metro-transform-worker 0.80.4 → 0.80.6
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 +9 -9
- package/src/index.js +0 -50
- package/src/utils/assetTransformer.js +0 -11
- package/src/utils/getMinifier.js +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro-transform-worker",
|
|
3
|
-
"version": "0.80.
|
|
3
|
+
"version": "0.80.6",
|
|
4
4
|
"description": "🚇 Transform worker for Metro.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"@babel/generator": "^7.20.0",
|
|
18
18
|
"@babel/parser": "^7.20.0",
|
|
19
19
|
"@babel/types": "^7.20.0",
|
|
20
|
-
"metro": "0.80.
|
|
21
|
-
"metro-babel-transformer": "0.80.
|
|
22
|
-
"metro-cache": "0.80.
|
|
23
|
-
"metro-cache-key": "0.80.
|
|
24
|
-
"metro-
|
|
25
|
-
"metro-
|
|
20
|
+
"metro": "0.80.6",
|
|
21
|
+
"metro-babel-transformer": "0.80.6",
|
|
22
|
+
"metro-cache": "0.80.6",
|
|
23
|
+
"metro-cache-key": "0.80.6",
|
|
24
|
+
"metro-minify-terser": "0.80.6",
|
|
25
|
+
"metro-source-map": "0.80.6",
|
|
26
|
+
"metro-transform-plugins": "0.80.6",
|
|
26
27
|
"nullthrows": "^1.1.1"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"metro-memory-fs": "0.80.
|
|
30
|
-
"metro-minify-terser": "0.80.4",
|
|
30
|
+
"metro-memory-fs": "0.80.6",
|
|
31
31
|
"@react-native/metro-babel-transformer": "0.73.11"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
package/src/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const getMinifier = require("./utils/getMinifier");
|
|
@@ -61,10 +50,8 @@ const minifyCode = async (
|
|
|
61
50
|
code,
|
|
62
51
|
source,
|
|
63
52
|
map,
|
|
64
|
-
// functionMap is overridden by the serializer
|
|
65
53
|
functionMap: null,
|
|
66
54
|
path: filename,
|
|
67
|
-
// isIgnored is overriden by the serializer
|
|
68
55
|
isIgnored: false,
|
|
69
56
|
},
|
|
70
57
|
]).toMap(undefined, {});
|
|
@@ -106,17 +93,12 @@ class InvalidRequireCallError extends Error {
|
|
|
106
93
|
}
|
|
107
94
|
}
|
|
108
95
|
async function transformJS(file, { config, options, projectRoot }) {
|
|
109
|
-
// Transformers can output null ASTs (if they ignore the file). In that case
|
|
110
|
-
// we need to parse the module source code to get their AST.
|
|
111
96
|
let ast =
|
|
112
97
|
file.ast ??
|
|
113
98
|
babylon.parse(file.code, {
|
|
114
99
|
sourceType: "unambiguous",
|
|
115
100
|
});
|
|
116
101
|
const { importDefault, importAll } = generateImportNames(ast);
|
|
117
|
-
|
|
118
|
-
// Add "use strict" if the file was parsed as a module, and the directive did
|
|
119
|
-
// not exist yet.
|
|
120
102
|
const { directives } = ast.program;
|
|
121
103
|
if (
|
|
122
104
|
ast.program.sourceType === "module" &&
|
|
@@ -125,9 +107,6 @@ async function transformJS(file, { config, options, projectRoot }) {
|
|
|
125
107
|
) {
|
|
126
108
|
directives.push(types.directive(types.directiveLiteral("use strict")));
|
|
127
109
|
}
|
|
128
|
-
|
|
129
|
-
// Perform the import-export transform (in case it's still needed), then
|
|
130
|
-
// fold requires and perform constant folding (if in dev).
|
|
131
110
|
const plugins = [];
|
|
132
111
|
const babelPluginOpts = {
|
|
133
112
|
...options,
|
|
@@ -158,18 +137,10 @@ async function transformJS(file, { config, options, projectRoot }) {
|
|
|
158
137
|
filename: file.filename,
|
|
159
138
|
plugins,
|
|
160
139
|
sourceMaps: false,
|
|
161
|
-
// Not-Cloning the input AST here should be safe because other code paths above this call
|
|
162
|
-
// are mutating the AST as well and no code is depending on the original AST.
|
|
163
|
-
// However, switching the flag to false caused issues with ES Modules if `experimentalImportSupport` isn't used https://github.com/facebook/metro/issues/641
|
|
164
|
-
// either because one of the plugins is doing something funky or Babel messes up some caches.
|
|
165
|
-
// Make sure to test the above mentioned case before flipping the flag back to false.
|
|
166
140
|
cloneInputAst: true,
|
|
167
141
|
}).ast
|
|
168
142
|
);
|
|
169
143
|
if (!options.dev) {
|
|
170
|
-
// Run the constant folding plugin in its own pass, avoiding race conditions
|
|
171
|
-
// with other plugins that have exit() visitors on Program (e.g. the ESM
|
|
172
|
-
// transform).
|
|
173
144
|
ast = nullthrows(
|
|
174
145
|
transformFromAstSync(ast, "", {
|
|
175
146
|
ast: true,
|
|
@@ -189,11 +160,6 @@ async function transformJS(file, { config, options, projectRoot }) {
|
|
|
189
160
|
let dependencyMapName = "";
|
|
190
161
|
let dependencies;
|
|
191
162
|
let wrappedAst;
|
|
192
|
-
|
|
193
|
-
// If the module to transform is a script (meaning that is not part of the
|
|
194
|
-
// dependency graph and it code will just be prepended to the bundle modules),
|
|
195
|
-
// we need to wrap it differently than a commonJS module (also, scripts do
|
|
196
|
-
// not have dependencies).
|
|
197
163
|
if (file.type === "js/script") {
|
|
198
164
|
dependencies = [];
|
|
199
165
|
wrappedAst = JsFileWrapping.wrapPolyfill(ast);
|
|
@@ -297,10 +263,6 @@ async function transformJS(file, { config, options, projectRoot }) {
|
|
|
297
263
|
output,
|
|
298
264
|
};
|
|
299
265
|
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Transforms an asset file
|
|
303
|
-
*/
|
|
304
266
|
async function transformAsset(file, context) {
|
|
305
267
|
const assetTransformer = require("./utils/assetTransformer");
|
|
306
268
|
const { assetRegistryPath, assetPlugins } = context.config;
|
|
@@ -317,17 +279,10 @@ async function transformAsset(file, context) {
|
|
|
317
279
|
};
|
|
318
280
|
return transformJS(jsFile, context);
|
|
319
281
|
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Transforms a JavaScript file with Babel before processing the file with
|
|
323
|
-
* the generic JavaScript transformation.
|
|
324
|
-
*/
|
|
325
282
|
async function transformJSWithBabel(file, context) {
|
|
326
283
|
const { babelTransformerPath } = context.config;
|
|
327
|
-
// $FlowFixMe[unsupported-syntax] dynamic require
|
|
328
284
|
const transformer = require(babelTransformerPath);
|
|
329
285
|
const transformResult = await transformer.transform(
|
|
330
|
-
// functionMapBabelPlugin populates metadata.metro.functionMap
|
|
331
286
|
getBabelTransformArgs(file, context, [functionMapBabelPlugin])
|
|
332
287
|
);
|
|
333
288
|
const jsFile = {
|
|
@@ -335,7 +290,6 @@ async function transformJSWithBabel(file, context) {
|
|
|
335
290
|
ast: transformResult.ast,
|
|
336
291
|
functionMap:
|
|
337
292
|
transformResult.metadata?.metro?.functionMap ??
|
|
338
|
-
// Fallback to deprecated explicitly-generated `functionMap`
|
|
339
293
|
transformResult.functionMap ??
|
|
340
294
|
null,
|
|
341
295
|
};
|
|
@@ -347,8 +301,6 @@ async function transformJSON(file, { options, config, projectRoot }) {
|
|
|
347
301
|
? JsFileWrapping.jsonToCommonJS(file.code)
|
|
348
302
|
: JsFileWrapping.wrapJson(file.code, config.globalPrefix);
|
|
349
303
|
let map = [];
|
|
350
|
-
|
|
351
|
-
// TODO: When we can reuse transformJS for JSON, we should not derive `minify` separately.
|
|
352
304
|
const minify =
|
|
353
305
|
options.minify &&
|
|
354
306
|
options.unstable_transformProfile !== "hermes-canary" &&
|
|
@@ -466,8 +418,6 @@ module.exports = {
|
|
|
466
418
|
require.resolve("metro/src/ModuleGraph/worker/JsFileWrapping"),
|
|
467
419
|
...metroTransformPlugins.getTransformPluginCacheKeyFiles(),
|
|
468
420
|
]);
|
|
469
|
-
|
|
470
|
-
// $FlowFixMe[unsupported-syntax]
|
|
471
421
|
const babelTransformer = require(babelTransformerPath);
|
|
472
422
|
return [
|
|
473
423
|
filesKey,
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const { getAssetData } = require("metro/src/Assets");
|
package/src/utils/getMinifier.js
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
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
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
function getMinifier(minifierPath) {
|
|
15
|
-
// Note: minifierPath should be an absolute path OR a module name here!
|
|
16
|
-
// The options allow relative paths but they HAVE to be normalized at
|
|
17
|
-
// any entry point that accepts them...
|
|
18
4
|
try {
|
|
19
|
-
// $FlowFixMe TODO t0 cannot do require with literal
|
|
20
5
|
return require(minifierPath);
|
|
21
6
|
} catch (e) {
|
|
22
7
|
throw new Error(
|