metro-transform-worker 0.81.2 → 0.82.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro-transform-worker",
3
- "version": "0.81.2",
3
+ "version": "0.82.0",
4
4
  "description": "🚇 Transform worker for Metro.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -26,18 +26,18 @@
26
26
  "@babel/parser": "^7.25.3",
27
27
  "@babel/types": "^7.25.2",
28
28
  "flow-enums-runtime": "^0.0.6",
29
- "metro": "0.81.2",
30
- "metro-babel-transformer": "0.81.2",
31
- "metro-cache": "0.81.2",
32
- "metro-cache-key": "0.81.2",
33
- "metro-minify-terser": "0.81.2",
34
- "metro-source-map": "0.81.2",
35
- "metro-transform-plugins": "0.81.2",
29
+ "metro": "0.82.0",
30
+ "metro-babel-transformer": "0.82.0",
31
+ "metro-cache": "0.82.0",
32
+ "metro-cache-key": "0.82.0",
33
+ "metro-minify-terser": "0.82.0",
34
+ "metro-source-map": "0.82.0",
35
+ "metro-transform-plugins": "0.82.0",
36
36
  "nullthrows": "^1.1.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@react-native/metro-babel-transformer": "0.73.11",
40
- "metro-memory-fs": "0.81.2"
40
+ "metro-memory-fs": "0.82.0"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">=18.18"
package/src/index.js CHANGED
@@ -19,6 +19,10 @@ const {
19
19
  InvalidRequireCallError: InternalInvalidRequireCallError,
20
20
  } = require("metro/src/ModuleGraph/worker/collectDependencies");
21
21
  const generateImportNames = require("metro/src/ModuleGraph/worker/generateImportNames");
22
+ const {
23
+ importLocationsPlugin,
24
+ locToKey,
25
+ } = require("metro/src/ModuleGraph/worker/importLocationsPlugin");
22
26
  const JsFileWrapping = require("metro/src/ModuleGraph/worker/JsFileWrapping");
23
27
  const nullthrows = require("nullthrows");
24
28
  function getDynamicDepsBehavior(inPackages, filename) {
@@ -176,6 +180,7 @@ async function transformJS(file, { config, options, projectRoot }) {
176
180
  wrappedAst = JsFileWrapping.wrapPolyfill(ast);
177
181
  } else {
178
182
  try {
183
+ const importDeclarationLocs = file.unstable_importDeclarationLocs ?? null;
179
184
  const opts = {
180
185
  asyncRequireModulePath: config.asyncRequireModulePath,
181
186
  dependencyTransformer:
@@ -191,6 +196,10 @@ async function transformJS(file, { config, options, projectRoot }) {
191
196
  allowOptionalDependencies: config.allowOptionalDependencies,
192
197
  dependencyMapName: config.unstable_dependencyMapReservedName,
193
198
  unstable_allowRequireContext: config.unstable_allowRequireContext,
199
+ unstable_isESMImportAtSource:
200
+ importDeclarationLocs != null
201
+ ? (loc) => importDeclarationLocs.has(locToKey(loc))
202
+ : null,
194
203
  };
195
204
  ({ ast, dependencies, dependencyMapName } = collectDependencies(
196
205
  ast,
@@ -297,7 +306,10 @@ async function transformJSWithBabel(file, context) {
297
306
  const { babelTransformerPath } = context.config;
298
307
  const transformer = require(babelTransformerPath);
299
308
  const transformResult = await transformer.transform(
300
- getBabelTransformArgs(file, context, [functionMapBabelPlugin])
309
+ getBabelTransformArgs(file, context, [
310
+ functionMapBabelPlugin,
311
+ importLocationsPlugin,
312
+ ])
301
313
  );
302
314
  const jsFile = {
303
315
  ...file,
@@ -306,6 +318,8 @@ async function transformJSWithBabel(file, context) {
306
318
  transformResult.metadata?.metro?.functionMap ??
307
319
  transformResult.functionMap ??
308
320
  null,
321
+ unstable_importDeclarationLocs:
322
+ transformResult.metadata?.metro?.unstable_importDeclarationLocs,
309
323
  };
310
324
  return await transformJS(jsFile, context);
311
325
  }
package/src/index.js.flow CHANGED
@@ -54,6 +54,10 @@ const {
54
54
  InvalidRequireCallError: InternalInvalidRequireCallError,
55
55
  } = require('metro/src/ModuleGraph/worker/collectDependencies');
56
56
  const generateImportNames = require('metro/src/ModuleGraph/worker/generateImportNames');
57
+ const {
58
+ importLocationsPlugin,
59
+ locToKey,
60
+ } = require('metro/src/ModuleGraph/worker/importLocationsPlugin');
57
61
  const JsFileWrapping = require('metro/src/ModuleGraph/worker/JsFileWrapping');
58
62
  const nullthrows = require('nullthrows');
59
63
 
@@ -148,6 +152,7 @@ type JSFile = $ReadOnly<{
148
152
  ast?: ?BabelNodeFile,
149
153
  type: JSFileType,
150
154
  functionMap: FBSourceFunctionMap | null,
155
+ unstable_importDeclarationLocs?: ?$ReadOnlySet<string>,
151
156
  }>;
152
157
 
153
158
  type JSONFile = {
@@ -381,6 +386,7 @@ async function transformJS(
381
386
  wrappedAst = JsFileWrapping.wrapPolyfill(ast);
382
387
  } else {
383
388
  try {
389
+ const importDeclarationLocs = file.unstable_importDeclarationLocs ?? null;
384
390
  const opts = {
385
391
  asyncRequireModulePath: config.asyncRequireModulePath,
386
392
  dependencyTransformer:
@@ -396,6 +402,11 @@ async function transformJS(
396
402
  allowOptionalDependencies: config.allowOptionalDependencies,
397
403
  dependencyMapName: config.unstable_dependencyMapReservedName,
398
404
  unstable_allowRequireContext: config.unstable_allowRequireContext,
405
+ unstable_isESMImportAtSource:
406
+ importDeclarationLocs != null
407
+ ? (loc: BabelSourceLocation) =>
408
+ importDeclarationLocs.has(locToKey(loc))
409
+ : null,
399
410
  };
400
411
  ({ast, dependencies, dependencyMapName} = collectDependencies(ast, opts));
401
412
  } catch (error) {
@@ -531,8 +542,12 @@ async function transformJSWithBabel(
531
542
  const transformer: BabelTransformer = require(babelTransformerPath);
532
543
 
533
544
  const transformResult = await transformer.transform(
534
- // functionMapBabelPlugin populates metadata.metro.functionMap
535
- getBabelTransformArgs(file, context, [functionMapBabelPlugin]),
545
+ getBabelTransformArgs(file, context, [
546
+ // functionMapBabelPlugin populates metadata.metro.functionMap
547
+ functionMapBabelPlugin,
548
+ // importLocationsPlugin populates metadata.metro.unstable_importDeclarationLocs
549
+ importLocationsPlugin,
550
+ ]),
536
551
  );
537
552
 
538
553
  const jsFile: JSFile = {
@@ -543,6 +558,8 @@ async function transformJSWithBabel(
543
558
  // Fallback to deprecated explicitly-generated `functionMap`
544
559
  transformResult.functionMap ??
545
560
  null,
561
+ unstable_importDeclarationLocs:
562
+ transformResult.metadata?.metro?.unstable_importDeclarationLocs,
546
563
  };
547
564
 
548
565
  return await transformJS(jsFile, context);