react / react/metro

Providing a cache key when custom transformers use external inputs

Open
#918 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Feature Request
Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Description

Raised by @cancit in a Tweet.

Do you want to request a feature or report a bug?
Feature/docs

What is the current behavior?
When using custom plugins (like babel-plugin-transform-inline-environment-variables) outside factors may influence the build, which breaks transform cache invalidation.

What is the expected behavior?
We probably can't do anything automatically for arbitrary plugins, but at the very least there should be a documented way to tell the transform cache about outside factors. We have cacheVersion, but it's not well documented ("There is generally no need to set this explicitly") and feels surprising.

A way to explicitly specify/allowlist environment variables in particular (like we do with Buck) might be worthwhile, since that's likely to be the most common outside factor.

Workaround

// metro.config.js
module.exports = {
  cacheVersion: [process.env.VAR_ONE, process.env.VAR_TWO].join('-') // Hash this if the values aren't safe for a file name
  // ...
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Metro's cacheVersion configuration and transform-cache documentation, then trace how custom transformer inputs and environment variables affect invalidation. Define the supported way to provide external inputs, including whether an environment-variable allowlist is in scope; done means the behavior and configuration are documented and covered by relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.