metro-transform-worker 0.83.3 → 0.83.5

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.83.3",
3
+ "version": "0.83.5",
4
4
  "description": "🚇 Transform worker for Metro.",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -10,7 +10,8 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git@github.com:facebook/metro.git"
13
+ "url": "git+https://github.com/facebook/metro.git",
14
+ "directory": "packages/metro-transform-worker"
14
15
  },
15
16
  "scripts": {
16
17
  "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
@@ -19,17 +20,17 @@
19
20
  "license": "MIT",
20
21
  "dependencies": {
21
22
  "@babel/core": "^7.25.2",
22
- "@babel/generator": "^7.25.0",
23
- "@babel/parser": "^7.25.3",
24
- "@babel/types": "^7.25.2",
23
+ "@babel/generator": "^7.29.1",
24
+ "@babel/parser": "^7.29.0",
25
+ "@babel/types": "^7.29.0",
25
26
  "flow-enums-runtime": "^0.0.6",
26
- "metro": "0.83.3",
27
- "metro-babel-transformer": "0.83.3",
28
- "metro-cache": "0.83.3",
29
- "metro-cache-key": "0.83.3",
30
- "metro-minify-terser": "0.83.3",
31
- "metro-source-map": "0.83.3",
32
- "metro-transform-plugins": "0.83.3",
27
+ "metro": "0.83.5",
28
+ "metro-babel-transformer": "0.83.5",
29
+ "metro-cache": "0.83.5",
30
+ "metro-cache-key": "0.83.5",
31
+ "metro-minify-terser": "0.83.5",
32
+ "metro-source-map": "0.83.5",
33
+ "metro-transform-plugins": "0.83.5",
33
34
  "nullthrows": "^1.1.1"
34
35
  },
35
36
  "devDependencies": {
package/src/index.d.ts CHANGED
@@ -8,7 +8,6 @@
8
8
  * @oncall react_native
9
9
  */
10
10
 
11
- import type {DynamicRequiresBehavior} from 'metro';
12
11
  import type {
13
12
  CustomTransformOptions,
14
13
  TransformProfile,
@@ -20,28 +19,21 @@ import type {
20
19
  } from 'metro-source-map';
21
20
  import type {TransformResultDependency} from 'metro/private/DeltaBundler';
22
21
  import type {AllowOptionalDependencies} from 'metro/private/DeltaBundler/types';
22
+ import type {DynamicRequiresBehavior} from 'metro/private/ModuleGraph/worker/collectDependencies';
23
23
 
24
- export type MinifierConfig = Readonly<Record<string, unknown>>;
25
-
26
- export interface MinifierOptions {
24
+ type MinifierConfig = Readonly<{[$$Key$$: string]: unknown}>;
25
+ export type MinifierOptions = {
27
26
  code: string;
28
- map?: BasicSourceMap;
27
+ map: null | undefined | BasicSourceMap;
29
28
  filename: string;
30
29
  reserved: ReadonlyArray<string>;
31
30
  config: MinifierConfig;
32
- }
33
-
34
- export interface MinifierResult {
35
- code: string;
36
- map?: BasicSourceMap;
37
- }
38
-
31
+ };
32
+ export type MinifierResult = {code: string; map?: BasicSourceMap};
39
33
  export type Minifier = (
40
- options: MinifierOptions,
34
+ $$PARAM_0$$: MinifierOptions,
41
35
  ) => MinifierResult | Promise<MinifierResult>;
42
-
43
36
  export type Type = 'script' | 'module' | 'asset';
44
-
45
37
  export type JsTransformerConfig = Readonly<{
46
38
  assetPlugins: ReadonlyArray<string>;
47
39
  assetRegistryPath: string;
@@ -49,7 +41,7 @@ export type JsTransformerConfig = Readonly<{
49
41
  babelTransformerPath: string;
50
42
  dynamicDepsInPackages: DynamicRequiresBehavior;
51
43
  enableBabelRCLookup: boolean;
52
- enableBabelRuntime: boolean;
44
+ enableBabelRuntime: boolean | string;
53
45
  globalPrefix: string;
54
46
  hermesParser: boolean;
55
47
  minifierConfig: MinifierConfig;
@@ -57,8 +49,7 @@ export type JsTransformerConfig = Readonly<{
57
49
  optimizationSizeLimit: number;
58
50
  publicPath: string;
59
51
  allowOptionalDependencies: AllowOptionalDependencies;
60
- unstable_collectDependenciesPath: string;
61
- unstable_dependencyMapReservedName?: string;
52
+ unstable_dependencyMapReservedName: null | undefined | string;
62
53
  unstable_disableModuleWrapping: boolean;
63
54
  unstable_disableNormalizePseudoGlobals: boolean;
64
55
  unstable_compactOutput: boolean;
@@ -71,9 +62,7 @@ export type JsTransformerConfig = Readonly<{
71
62
  /** Whether to rename scoped `require` functions to `_$$_REQUIRE`, usually an extraneous operation when serializing to iife (default). */
72
63
  unstable_renameRequire?: boolean;
73
64
  }>;
74
-
75
- export {CustomTransformOptions} from 'metro-babel-transformer';
76
-
65
+ export type {CustomTransformOptions} from 'metro-babel-transformer';
77
66
  export type JsTransformOptions = Readonly<{
78
67
  customTransformOptions?: CustomTransformOptions;
79
68
  dev: boolean;
@@ -82,47 +71,37 @@ export type JsTransformOptions = Readonly<{
82
71
  inlineRequires: boolean;
83
72
  minify: boolean;
84
73
  nonInlinedRequires?: ReadonlyArray<string>;
85
- platform?: string;
86
- runtimeBytecodeVersion?: number;
74
+ platform: null | undefined | string;
87
75
  type: Type;
76
+ unstable_memoizeInlineRequires?: boolean;
77
+ unstable_nonMemoizedInlineRequires?: ReadonlyArray<string>;
78
+ unstable_staticHermesOptimizedRequire?: boolean;
88
79
  unstable_transformProfile: TransformProfile;
89
80
  }>;
90
-
91
- export type BytecodeFileType =
92
- | 'bytecode/module'
93
- | 'bytecode/module/asset'
94
- | 'bytecode/script';
95
-
96
- export type JSFileType = 'js/script' | 'js/module' | 'js/module/asset';
97
-
81
+ type JSFileType = 'js/script' | 'js/module' | 'js/module/asset';
98
82
  export type JsOutput = Readonly<{
99
83
  data: Readonly<{
100
84
  code: string;
101
85
  lineCount: number;
102
- map: MetroSourceMapSegmentTuple[];
103
- functionMap: FBSourceFunctionMap | null;
86
+ map: Array<MetroSourceMapSegmentTuple>;
87
+ functionMap: null | undefined | FBSourceFunctionMap;
104
88
  }>;
105
89
  type: JSFileType;
106
90
  }>;
107
-
108
- // Hermes byte-code output type
109
- export type BytecodeOutput = unknown;
110
-
111
- export type TransformResponse = Readonly<{
91
+ type TransformResponse = Readonly<{
112
92
  dependencies: ReadonlyArray<TransformResultDependency>;
113
- output: ReadonlyArray<JsOutput | BytecodeOutput>;
93
+ output: ReadonlyArray<JsOutput>;
114
94
  }>;
115
-
116
- export function transform(
95
+ export declare const transform: (
117
96
  config: JsTransformerConfig,
118
97
  projectRoot: string,
119
98
  filename: string,
120
99
  data: Buffer,
121
100
  options: JsTransformOptions,
122
- ): Promise<TransformResponse>;
123
-
124
- export function getCacheKey(config: JsTransformerConfig): string;
125
-
101
+ ) => Promise<TransformResponse>;
102
+ export declare type transform = typeof transform;
103
+ export declare const getCacheKey: (config: JsTransformerConfig) => string;
104
+ export declare type getCacheKey = typeof getCacheKey;
126
105
  /**
127
106
  * Backwards-compatibility with CommonJS consumers using interopRequireDefault.
128
107
  * Do not add to this list.
package/src/index.js CHANGED
@@ -32,28 +32,32 @@ var _nullthrows = _interopRequireDefault(require("nullthrows"));
32
32
  function _interopRequireDefault(e) {
33
33
  return e && e.__esModule ? e : { default: e };
34
34
  }
35
- function _getRequireWildcardCache(e) {
36
- if ("function" != typeof WeakMap) return null;
37
- var r = new WeakMap(),
38
- t = new WeakMap();
39
- return (_getRequireWildcardCache = function (e) {
40
- return e ? t : r;
41
- })(e);
42
- }
43
- function _interopRequireWildcard(e, r) {
44
- if (!r && e && e.__esModule) return e;
45
- if (null === e || ("object" != typeof e && "function" != typeof e))
46
- return { default: e };
47
- var t = _getRequireWildcardCache(r);
48
- if (t && t.has(e)) return t.get(e);
49
- var n = { __proto__: null },
50
- a = Object.defineProperty && Object.getOwnPropertyDescriptor;
51
- for (var u in e)
52
- if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
53
- var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
54
- i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
35
+ function _interopRequireWildcard(e, t) {
36
+ if ("function" == typeof WeakMap)
37
+ var r = new WeakMap(),
38
+ n = new WeakMap();
39
+ return (_interopRequireWildcard = function (e, t) {
40
+ if (!t && e && e.__esModule) return e;
41
+ var o,
42
+ i,
43
+ f = { __proto__: null, default: e };
44
+ if (null === e || ("object" != typeof e && "function" != typeof e))
45
+ return f;
46
+ if ((o = t ? n : r)) {
47
+ if (o.has(e)) return o.get(e);
48
+ o.set(e, f);
55
49
  }
56
- return ((n.default = e), t && t.set(e, n), n);
50
+ for (const t in e)
51
+ "default" !== t &&
52
+ {}.hasOwnProperty.call(e, t) &&
53
+ ((i =
54
+ (o = Object.defineProperty) &&
55
+ Object.getOwnPropertyDescriptor(e, t)) &&
56
+ (i.get || i.set)
57
+ ? o(f, t, i)
58
+ : (f[t] = e[t]));
59
+ return f;
60
+ })(e, t);
57
61
  }
58
62
  const InternalInvalidRequireCallError =
59
63
  _collectDependencies.default.InvalidRequireCallError;
@@ -83,21 +87,21 @@ const minifyCode = async (
83
87
  const sourceMap = (0, _metroSourceMap.fromRawMappings)([
84
88
  {
85
89
  code,
86
- source,
87
- map,
88
90
  functionMap: null,
89
- path: filename,
90
91
  isIgnored: false,
92
+ map,
93
+ path: filename,
94
+ source,
91
95
  },
92
96
  ]).toMap(undefined, {});
93
97
  const minify = (0, _getMinifier.default)(config.minifierPath);
94
98
  try {
95
99
  const minified = await minify({
96
100
  code,
97
- map: sourceMap,
101
+ config: config.minifierConfig,
98
102
  filename,
103
+ map: sourceMap,
99
104
  reserved,
100
- config: config.minifierConfig,
101
105
  });
102
106
  return {
103
107
  code: minified.code,
@@ -117,11 +121,11 @@ const minifyCode = async (
117
121
  }
118
122
  };
119
123
  const disabledDependencyTransformer = {
120
- transformSyncRequire: () => void 0,
124
+ transformIllegalDynamicRequire: () => void 0,
121
125
  transformImportCall: () => void 0,
122
126
  transformImportMaybeSyncCall: () => void 0,
123
127
  transformPrefetch: () => void 0,
124
- transformIllegalDynamicRequire: () => void 0,
128
+ transformSyncRequire: () => void 0,
125
129
  };
126
130
  class InvalidRequireCallError extends Error {
127
131
  constructor(innerError, filename) {
@@ -182,13 +186,13 @@ async function transformJS(file, { config, options, projectRoot }) {
182
186
  (0, _core.transformFromAstSync)(ast, "", {
183
187
  ast: true,
184
188
  babelrc: false,
189
+ cloneInputAst: true,
185
190
  code: false,
186
- configFile: false,
187
191
  comments: true,
192
+ configFile: false,
188
193
  filename: file.filename,
189
194
  plugins,
190
195
  sourceMaps: false,
191
- cloneInputAst: true,
192
196
  }).ast,
193
197
  );
194
198
  if (!options.dev) {
@@ -196,13 +200,13 @@ async function transformJS(file, { config, options, projectRoot }) {
196
200
  (0, _core.transformFromAstSync)(ast, "", {
197
201
  ast: true,
198
202
  babelrc: false,
203
+ cloneInputAst: false,
199
204
  code: false,
200
- configFile: false,
201
205
  comments: true,
206
+ configFile: false,
202
207
  filename: file.filename,
203
208
  plugins: [_metroTransformPlugins.default.constantFoldingPlugin],
204
209
  sourceMaps: false,
205
- cloneInputAst: false,
206
210
  }).ast,
207
211
  );
208
212
  }
@@ -216,7 +220,9 @@ async function transformJS(file, { config, options, projectRoot }) {
216
220
  try {
217
221
  const importDeclarationLocs = file.unstable_importDeclarationLocs ?? null;
218
222
  const opts = {
223
+ allowOptionalDependencies: config.allowOptionalDependencies,
219
224
  asyncRequireModulePath: config.asyncRequireModulePath,
225
+ dependencyMapName: config.unstable_dependencyMapReservedName,
220
226
  dependencyTransformer:
221
227
  config.unstable_disableModuleWrapping === true
222
228
  ? disabledDependencyTransformer
@@ -227,8 +233,6 @@ async function transformJS(file, { config, options, projectRoot }) {
227
233
  ),
228
234
  inlineableCalls: [importDefault, importAll],
229
235
  keepRequireNames: options.dev,
230
- allowOptionalDependencies: config.allowOptionalDependencies,
231
- dependencyMapName: config.unstable_dependencyMapReservedName,
232
236
  unstable_allowRequireContext: config.unstable_allowRequireContext,
233
237
  unstable_isESMImportAtSource:
234
238
  importDeclarationLocs != null
@@ -317,9 +321,9 @@ async function transformJS(file, { config, options, projectRoot }) {
317
321
  {
318
322
  data: {
319
323
  code,
324
+ functionMap: file.functionMap,
320
325
  lineCount,
321
326
  map,
322
- functionMap: file.functionMap,
323
327
  },
324
328
  type: file.type,
325
329
  },
@@ -338,9 +342,9 @@ async function transformAsset(file, context) {
338
342
  );
339
343
  const jsFile = {
340
344
  ...file,
341
- type: "js/module/asset",
342
345
  ast: result.ast,
343
346
  functionMap: null,
347
+ type: "js/module/asset",
344
348
  };
345
349
  return transformJS(jsFile, context);
346
350
  }
@@ -406,9 +410,9 @@ async function transformJSON(file, { options, config, projectRoot }) {
406
410
  {
407
411
  data: {
408
412
  code,
413
+ functionMap: null,
409
414
  lineCount,
410
415
  map,
411
- functionMap: null,
412
416
  },
413
417
  type: jsType,
414
418
  },
@@ -442,8 +446,8 @@ function getBabelTransformArgs(
442
446
  const transform = async (config, projectRoot, filename, data, options) => {
443
447
  const context = {
444
448
  config,
445
- projectRoot,
446
449
  options,
450
+ projectRoot,
447
451
  };
448
452
  const sourceCode = data.toString("utf8");
449
453
  const reservedStrings = [];
@@ -469,28 +473,28 @@ const transform = async (config, projectRoot, filename, data, options) => {
469
473
  }
470
474
  if (filename.endsWith(".json")) {
471
475
  const jsonFile = {
476
+ code: sourceCode,
472
477
  filename,
473
478
  inputFileSize: data.length,
474
- code: sourceCode,
475
479
  type: options.type,
476
480
  };
477
481
  return await transformJSON(jsonFile, context);
478
482
  }
479
483
  if (options.type === "asset") {
480
484
  const file = {
485
+ code: sourceCode,
481
486
  filename,
482
487
  inputFileSize: data.length,
483
- code: sourceCode,
484
488
  type: options.type,
485
489
  };
486
490
  return await transformAsset(file, context);
487
491
  }
488
492
  const file = {
493
+ code: sourceCode,
489
494
  filename,
495
+ functionMap: null,
490
496
  inputFileSize: data.length,
491
- code: sourceCode,
492
497
  type: options.type === "script" ? "js/script" : "js/module",
493
- functionMap: null,
494
498
  };
495
499
  return await transformJSWithBabel(file, context);
496
500
  };
package/src/index.js.flow CHANGED
@@ -60,13 +60,13 @@ import nullthrows from 'nullthrows';
60
60
  const InternalInvalidRequireCallError =
61
61
  collectDependencies.InvalidRequireCallError;
62
62
 
63
- type MinifierConfig = $ReadOnly<{[string]: mixed, ...}>;
63
+ type MinifierConfig = Readonly<{[string]: unknown, ...}>;
64
64
 
65
65
  export type MinifierOptions = {
66
66
  code: string,
67
67
  map: ?BasicSourceMap,
68
68
  filename: string,
69
- reserved: $ReadOnlyArray<string>,
69
+ reserved: ReadonlyArray<string>,
70
70
  config: MinifierConfig,
71
71
  ...
72
72
  };
@@ -83,8 +83,8 @@ export type Minifier = MinifierOptions =>
83
83
 
84
84
  export type Type = 'script' | 'module' | 'asset';
85
85
 
86
- export type JsTransformerConfig = $ReadOnly<{
87
- assetPlugins: $ReadOnlyArray<string>,
86
+ export type JsTransformerConfig = Readonly<{
87
+ assetPlugins: ReadonlyArray<string>,
88
88
  assetRegistryPath: string,
89
89
  asyncRequireModulePath: string,
90
90
  babelTransformerPath: string,
@@ -107,50 +107,50 @@ export type JsTransformerConfig = $ReadOnly<{
107
107
  /** With inlineRequires, enable a module-scope memo var and inline as (v || v=require('foo')) */
108
108
  unstable_memoizeInlineRequires?: boolean,
109
109
  /** With inlineRequires, do not memoize these module specifiers */
110
- unstable_nonMemoizedInlineRequires?: $ReadOnlyArray<string>,
110
+ unstable_nonMemoizedInlineRequires?: ReadonlyArray<string>,
111
111
  /** Whether to rename scoped `require` functions to `_$$_REQUIRE`, usually an extraneous operation when serializing to iife (default). */
112
112
  unstable_renameRequire?: boolean,
113
113
  }>;
114
114
 
115
115
  export type {CustomTransformOptions} from 'metro-babel-transformer';
116
116
 
117
- export type JsTransformOptions = $ReadOnly<{
117
+ export type JsTransformOptions = Readonly<{
118
118
  customTransformOptions?: CustomTransformOptions,
119
119
  dev: boolean,
120
120
  experimentalImportSupport?: boolean,
121
121
  inlinePlatform: boolean,
122
122
  inlineRequires: boolean,
123
123
  minify: boolean,
124
- nonInlinedRequires?: $ReadOnlyArray<string>,
124
+ nonInlinedRequires?: ReadonlyArray<string>,
125
125
  platform: ?string,
126
126
  type: Type,
127
127
  unstable_memoizeInlineRequires?: boolean,
128
- unstable_nonMemoizedInlineRequires?: $ReadOnlyArray<string>,
128
+ unstable_nonMemoizedInlineRequires?: ReadonlyArray<string>,
129
129
  unstable_staticHermesOptimizedRequire?: boolean,
130
130
  unstable_transformProfile: TransformProfile,
131
131
  }>;
132
132
 
133
133
  opaque type Path = string;
134
134
 
135
- type BaseFile = $ReadOnly<{
135
+ type BaseFile = Readonly<{
136
136
  code: string,
137
137
  filename: Path,
138
138
  inputFileSize: number,
139
139
  }>;
140
140
 
141
- type AssetFile = $ReadOnly<{
141
+ type AssetFile = Readonly<{
142
142
  ...BaseFile,
143
143
  type: 'asset',
144
144
  }>;
145
145
 
146
146
  type JSFileType = 'js/script' | 'js/module' | 'js/module/asset';
147
147
 
148
- type JSFile = $ReadOnly<{
148
+ type JSFile = Readonly<{
149
149
  ...BaseFile,
150
150
  ast?: ?BabelNodeFile,
151
151
  type: JSFileType,
152
152
  functionMap: FBSourceFunctionMap | null,
153
- unstable_importDeclarationLocs?: ?$ReadOnlySet<string>,
153
+ unstable_importDeclarationLocs?: ?ReadonlySet<string>,
154
154
  }>;
155
155
 
156
156
  type JSONFile = {
@@ -158,14 +158,14 @@ type JSONFile = {
158
158
  type: Type,
159
159
  };
160
160
 
161
- type TransformationContext = $ReadOnly<{
161
+ type TransformationContext = Readonly<{
162
162
  config: JsTransformerConfig,
163
163
  projectRoot: Path,
164
164
  options: JsTransformOptions,
165
165
  }>;
166
166
 
167
- export type JsOutput = $ReadOnly<{
168
- data: $ReadOnly<{
167
+ export type JsOutput = Readonly<{
168
+ data: Readonly<{
169
169
  code: string,
170
170
  lineCount: number,
171
171
  map: Array<MetroSourceMapSegmentTuple>,
@@ -174,9 +174,9 @@ export type JsOutput = $ReadOnly<{
174
174
  type: JSFileType,
175
175
  }>;
176
176
 
177
- type TransformResponse = $ReadOnly<{
178
- dependencies: $ReadOnlyArray<TransformResultDependency>,
179
- output: $ReadOnlyArray<JsOutput>,
177
+ type TransformResponse = Readonly<{
178
+ dependencies: ReadonlyArray<TransformResultDependency>,
179
+ output: ReadonlyArray<JsOutput>,
180
180
  }>;
181
181
 
182
182
  function getDynamicDepsBehavior(
@@ -190,7 +190,7 @@ function getDynamicDepsBehavior(
190
190
  const isPackage = /(?:^|[/\\])node_modules[/\\]/.test(filename);
191
191
  return isPackage ? inPackages : 'reject';
192
192
  default:
193
- (inPackages: empty);
193
+ inPackages as empty;
194
194
  throw new Error(
195
195
  `invalid value for dynamic deps behavior: \`${inPackages}\``,
196
196
  );
@@ -204,7 +204,7 @@ const minifyCode = async (
204
204
  code: string,
205
205
  source: string,
206
206
  map: Array<MetroSourceMapSegmentTuple>,
207
- reserved?: $ReadOnlyArray<string> = [],
207
+ reserved?: ReadonlyArray<string> = [],
208
208
  ): Promise<{
209
209
  code: string,
210
210
  map: Array<MetroSourceMapSegmentTuple>,
@@ -213,13 +213,13 @@ const minifyCode = async (
213
213
  const sourceMap = fromRawMappings([
214
214
  {
215
215
  code,
216
- source,
217
- map,
218
216
  // functionMap is overridden by the serializer
219
217
  functionMap: null,
220
- path: filename,
221
218
  // isIgnored is overriden by the serializer
222
219
  isIgnored: false,
220
+ map,
221
+ path: filename,
222
+ source,
223
223
  },
224
224
  ]).toMap(undefined, {});
225
225
 
@@ -228,10 +228,10 @@ const minifyCode = async (
228
228
  try {
229
229
  const minified = await minify({
230
230
  code,
231
- map: sourceMap,
231
+ config: config.minifierConfig,
232
232
  filename,
233
+ map: sourceMap,
233
234
  reserved,
234
- config: config.minifierConfig,
235
235
  });
236
236
 
237
237
  return {
@@ -252,11 +252,11 @@ const minifyCode = async (
252
252
  };
253
253
 
254
254
  const disabledDependencyTransformer: DependencyTransformer = {
255
- transformSyncRequire: () => void 0,
255
+ transformIllegalDynamicRequire: () => void 0,
256
256
  transformImportCall: () => void 0,
257
257
  transformImportMaybeSyncCall: () => void 0,
258
258
  transformPrefetch: () => void 0,
259
- transformIllegalDynamicRequire: () => void 0,
259
+ transformSyncRequire: () => void 0,
260
260
  };
261
261
 
262
262
  class InvalidRequireCallError extends Error {
@@ -337,18 +337,18 @@ async function transformJS(
337
337
  transformFromAstSync(ast, '', {
338
338
  ast: true,
339
339
  babelrc: false,
340
- code: false,
341
- configFile: false,
342
- comments: true,
343
- filename: file.filename,
344
- plugins,
345
- sourceMaps: false,
346
340
  // Not-Cloning the input AST here should be safe because other code paths above this call
347
341
  // are mutating the AST as well and no code is depending on the original AST.
348
342
  // However, switching the flag to false caused issues with ES Modules if `experimentalImportSupport` isn't used https://github.com/facebook/metro/issues/641
349
343
  // either because one of the plugins is doing something funky or Babel messes up some caches.
350
344
  // Make sure to test the above mentioned case before flipping the flag back to false.
351
345
  cloneInputAst: true,
346
+ code: false,
347
+ comments: true,
348
+ configFile: false,
349
+ filename: file.filename,
350
+ plugins,
351
+ sourceMaps: false,
352
352
  }).ast,
353
353
  );
354
354
 
@@ -360,13 +360,13 @@ async function transformJS(
360
360
  transformFromAstSync(ast, '', {
361
361
  ast: true,
362
362
  babelrc: false,
363
+ cloneInputAst: false,
363
364
  code: false,
364
- configFile: false,
365
365
  comments: true,
366
+ configFile: false,
366
367
  filename: file.filename,
367
368
  plugins: [metroTransformPlugins.constantFoldingPlugin],
368
369
  sourceMaps: false,
369
- cloneInputAst: false,
370
370
  }).ast,
371
371
  );
372
372
  }
@@ -386,7 +386,9 @@ async function transformJS(
386
386
  try {
387
387
  const importDeclarationLocs = file.unstable_importDeclarationLocs ?? null;
388
388
  const opts = {
389
+ allowOptionalDependencies: config.allowOptionalDependencies,
389
390
  asyncRequireModulePath: config.asyncRequireModulePath,
391
+ dependencyMapName: config.unstable_dependencyMapReservedName,
390
392
  dependencyTransformer:
391
393
  config.unstable_disableModuleWrapping === true
392
394
  ? disabledDependencyTransformer
@@ -397,8 +399,6 @@ async function transformJS(
397
399
  ),
398
400
  inlineableCalls: [importDefault, importAll],
399
401
  keepRequireNames: options.dev,
400
- allowOptionalDependencies: config.allowOptionalDependencies,
401
- dependencyMapName: config.unstable_dependencyMapReservedName,
402
402
  unstable_allowRequireContext: config.unstable_allowRequireContext,
403
403
  unstable_isESMImportAtSource:
404
404
  importDeclarationLocs != null
@@ -493,9 +493,9 @@ async function transformJS(
493
493
  {
494
494
  data: {
495
495
  code,
496
+ functionMap: file.functionMap,
496
497
  lineCount,
497
498
  map,
498
- functionMap: file.functionMap,
499
499
  },
500
500
  type: file.type,
501
501
  },
@@ -524,9 +524,9 @@ async function transformAsset(
524
524
 
525
525
  const jsFile = {
526
526
  ...file,
527
- type: 'js/module/asset' as const,
528
527
  ast: result.ast,
529
528
  functionMap: null,
529
+ type: 'js/module/asset' as const,
530
530
  };
531
531
 
532
532
  return transformJS(jsFile, context);
@@ -616,7 +616,7 @@ async function transformJSON(
616
616
  ({lineCount, map} = countLinesAndTerminateMap(code, map));
617
617
  const output: Array<JsOutput> = [
618
618
  {
619
- data: {code, lineCount, map, functionMap: null},
619
+ data: {code, functionMap: null, lineCount, map},
620
620
  type: jsType,
621
621
  },
622
622
  ];
@@ -628,7 +628,7 @@ async function transformJSON(
628
628
  }
629
629
 
630
630
  function getBabelTransformArgs(
631
- file: $ReadOnly<{filename: Path, code: string, ...}>,
631
+ file: Readonly<{filename: Path, code: string, ...}>,
632
632
  {options, config, projectRoot}: TransformationContext,
633
633
  plugins?: Plugins = [],
634
634
  ): BabelTransformerArgs {
@@ -658,8 +658,8 @@ export const transform = async (
658
658
  ): Promise<TransformResponse> => {
659
659
  const context: TransformationContext = {
660
660
  config,
661
- projectRoot,
662
661
  options,
662
+ projectRoot,
663
663
  };
664
664
  const sourceCode = data.toString('utf8');
665
665
 
@@ -687,9 +687,9 @@ export const transform = async (
687
687
 
688
688
  if (filename.endsWith('.json')) {
689
689
  const jsonFile: JSONFile = {
690
+ code: sourceCode,
690
691
  filename,
691
692
  inputFileSize: data.length,
692
- code: sourceCode,
693
693
  type: options.type,
694
694
  };
695
695
 
@@ -698,9 +698,9 @@ export const transform = async (
698
698
 
699
699
  if (options.type === 'asset') {
700
700
  const file: AssetFile = {
701
+ code: sourceCode,
701
702
  filename,
702
703
  inputFileSize: data.length,
703
- code: sourceCode,
704
704
  type: options.type,
705
705
  };
706
706
 
@@ -708,11 +708,11 @@ export const transform = async (
708
708
  }
709
709
 
710
710
  const file: JSFile = {
711
+ code: sourceCode,
711
712
  filename,
713
+ functionMap: null,
712
714
  inputFileSize: data.length,
713
- code: sourceCode,
714
715
  type: options.type === 'script' ? 'js/script' : 'js/module',
715
- functionMap: null,
716
716
  };
717
717
 
718
718
  return await transformJSWithBabel(file, context);
@@ -743,7 +743,7 @@ export const getCacheKey = (config: JsTransformerConfig): string => {
743
743
 
744
744
  function countLinesAndTerminateMap(
745
745
  code: string,
746
- map: $ReadOnlyArray<MetroSourceMapSegmentTuple>,
746
+ map: ReadonlyArray<MetroSourceMapSegmentTuple>,
747
747
  ): {
748
748
  lineCount: number,
749
749
  map: Array<MetroSourceMapSegmentTuple>,
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {File} from '@babel/types';
12
+ import type {BabelTransformerArgs} from 'metro-babel-transformer';
13
+
14
+ export declare function transform(
15
+ $$PARAM_0$$: BabelTransformerArgs,
16
+ assetRegistryPath: string,
17
+ assetDataPlugins: ReadonlyArray<string>,
18
+ ): Promise<{ast: File}>;
@@ -19,7 +19,7 @@ import path from 'path';
19
19
  export async function transform(
20
20
  {filename, options, src}: BabelTransformerArgs,
21
21
  assetRegistryPath: string,
22
- assetDataPlugins: $ReadOnlyArray<string>,
22
+ assetDataPlugins: ReadonlyArray<string>,
23
23
  ): Promise<{ast: File, ...}> {
24
24
  options = options || {
25
25
  platform: '',
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ import type {Minifier} from '../index.js';
12
+
13
+ declare function getMinifier(minifierPath: string): Minifier;
14
+ export default getMinifier;