metro-transform-worker 0.76.0 → 0.76.1
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 +10 -11
- package/src/index.d.ts +120 -0
- package/src/index.js +2 -70
- package/src/index.js.flow +5 -97
- package/types/index.d.ts +120 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro-transform-worker",
|
|
3
|
-
"version": "0.76.
|
|
3
|
+
"version": "0.76.1",
|
|
4
4
|
"description": "🚇 Transform worker for Metro.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -18,19 +18,18 @@
|
|
|
18
18
|
"@babel/parser": "^7.20.0",
|
|
19
19
|
"@babel/types": "^7.20.0",
|
|
20
20
|
"babel-preset-fbjs": "^3.4.0",
|
|
21
|
-
"metro": "0.76.
|
|
22
|
-
"metro-babel-transformer": "0.76.
|
|
23
|
-
"metro-cache": "0.76.
|
|
24
|
-
"metro-cache-key": "0.76.
|
|
25
|
-
"metro-
|
|
26
|
-
"metro-
|
|
27
|
-
"metro-transform-plugins": "0.76.0",
|
|
21
|
+
"metro": "0.76.1",
|
|
22
|
+
"metro-babel-transformer": "0.76.1",
|
|
23
|
+
"metro-cache": "0.76.1",
|
|
24
|
+
"metro-cache-key": "0.76.1",
|
|
25
|
+
"metro-source-map": "0.76.1",
|
|
26
|
+
"metro-transform-plugins": "0.76.1",
|
|
28
27
|
"nullthrows": "^1.1.1"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"metro-memory-fs": "0.76.
|
|
32
|
-
"metro-minify-terser": "0.76.
|
|
33
|
-
"metro-react-native-babel-transformer": "0.76.
|
|
30
|
+
"metro-memory-fs": "0.76.1",
|
|
31
|
+
"metro-minify-terser": "0.76.1",
|
|
32
|
+
"metro-react-native-babel-transformer": "0.76.1"
|
|
34
33
|
},
|
|
35
34
|
"engines": {
|
|
36
35
|
"node": ">=16"
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
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 {DynamicRequiresBehavior} from 'metro';
|
|
12
|
+
import type {TransformResultDependency} from 'metro/DeltaBundler';
|
|
13
|
+
import type {AllowOptionalDependencies} from 'metro/DeltaBundler/types';
|
|
14
|
+
import type {
|
|
15
|
+
CustomTransformOptions,
|
|
16
|
+
TransformProfile,
|
|
17
|
+
} from 'metro-babel-transformer';
|
|
18
|
+
import type {
|
|
19
|
+
BasicSourceMap,
|
|
20
|
+
FBSourceFunctionMap,
|
|
21
|
+
MetroSourceMapSegmentTuple,
|
|
22
|
+
} from 'metro-source-map';
|
|
23
|
+
|
|
24
|
+
export type MinifierConfig = Readonly<Record<string, unknown>>;
|
|
25
|
+
|
|
26
|
+
export interface MinifierOptions {
|
|
27
|
+
code: string;
|
|
28
|
+
map?: BasicSourceMap;
|
|
29
|
+
filename: string;
|
|
30
|
+
reserved: ReadonlyArray<string>;
|
|
31
|
+
config: MinifierConfig;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface MinifierResult {
|
|
35
|
+
code: string;
|
|
36
|
+
map?: BasicSourceMap;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Minifier = (
|
|
40
|
+
options: MinifierOptions,
|
|
41
|
+
) => MinifierResult | Promise<MinifierResult>;
|
|
42
|
+
|
|
43
|
+
export type Type = 'script' | 'module' | 'asset';
|
|
44
|
+
|
|
45
|
+
export type JsTransformerConfig = Readonly<{
|
|
46
|
+
assetPlugins: ReadonlyArray<string>;
|
|
47
|
+
assetRegistryPath: string;
|
|
48
|
+
asyncRequireModulePath: string;
|
|
49
|
+
babelTransformerPath: string;
|
|
50
|
+
dynamicDepsInPackages: DynamicRequiresBehavior;
|
|
51
|
+
enableBabelRCLookup: boolean;
|
|
52
|
+
enableBabelRuntime: boolean;
|
|
53
|
+
globalPrefix: string;
|
|
54
|
+
hermesParser: boolean;
|
|
55
|
+
minifierConfig: MinifierConfig;
|
|
56
|
+
minifierPath: string;
|
|
57
|
+
optimizationSizeLimit: number;
|
|
58
|
+
publicPath: string;
|
|
59
|
+
allowOptionalDependencies: AllowOptionalDependencies;
|
|
60
|
+
unstable_collectDependenciesPath: string;
|
|
61
|
+
unstable_dependencyMapReservedName?: string;
|
|
62
|
+
unstable_disableModuleWrapping: boolean;
|
|
63
|
+
unstable_disableNormalizePseudoGlobals: boolean;
|
|
64
|
+
unstable_compactOutput: boolean;
|
|
65
|
+
/** Enable `require.context` statements which can be used to import multiple files in a directory. */
|
|
66
|
+
unstable_allowRequireContext: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
|
|
69
|
+
export {CustomTransformOptions} from 'metro-babel-transformer';
|
|
70
|
+
|
|
71
|
+
export type JsTransformOptions = Readonly<{
|
|
72
|
+
customTransformOptions?: CustomTransformOptions;
|
|
73
|
+
dev: boolean;
|
|
74
|
+
experimentalImportSupport?: boolean;
|
|
75
|
+
hot: boolean;
|
|
76
|
+
inlinePlatform: boolean;
|
|
77
|
+
inlineRequires: boolean;
|
|
78
|
+
minify: boolean;
|
|
79
|
+
nonInlinedRequires?: ReadonlyArray<string>;
|
|
80
|
+
platform?: string;
|
|
81
|
+
runtimeBytecodeVersion?: number;
|
|
82
|
+
type: Type;
|
|
83
|
+
unstable_disableES6Transforms?: boolean;
|
|
84
|
+
unstable_transformProfile: TransformProfile;
|
|
85
|
+
}>;
|
|
86
|
+
|
|
87
|
+
export type BytecodeFileType =
|
|
88
|
+
| 'bytecode/module'
|
|
89
|
+
| 'bytecode/module/asset'
|
|
90
|
+
| 'bytecode/script';
|
|
91
|
+
|
|
92
|
+
export type JSFileType = 'js/script' | 'js/module' | 'js/module/asset';
|
|
93
|
+
|
|
94
|
+
export type JsOutput = Readonly<{
|
|
95
|
+
data: Readonly<{
|
|
96
|
+
code: string;
|
|
97
|
+
lineCount: number;
|
|
98
|
+
map: MetroSourceMapSegmentTuple[];
|
|
99
|
+
functionMap: FBSourceFunctionMap | null;
|
|
100
|
+
}>;
|
|
101
|
+
type: JSFileType;
|
|
102
|
+
}>;
|
|
103
|
+
|
|
104
|
+
// Hermes byte-code output type
|
|
105
|
+
export type BytecodeOutput = unknown;
|
|
106
|
+
|
|
107
|
+
export type TransformResponse = Readonly<{
|
|
108
|
+
dependencies: ReadonlyArray<TransformResultDependency>;
|
|
109
|
+
output: ReadonlyArray<JsOutput | BytecodeOutput>;
|
|
110
|
+
}>;
|
|
111
|
+
|
|
112
|
+
export function transform(
|
|
113
|
+
config: JsTransformerConfig,
|
|
114
|
+
projectRoot: string,
|
|
115
|
+
filename: string,
|
|
116
|
+
data: Buffer,
|
|
117
|
+
options: JsTransformOptions,
|
|
118
|
+
): Promise<TransformResponse>;
|
|
119
|
+
|
|
120
|
+
export function getCacheKey(config: JsTransformerConfig): string;
|
package/src/index.js
CHANGED
|
@@ -28,6 +28,7 @@ const countLines = require("metro/src/lib/countLines");
|
|
|
28
28
|
const {
|
|
29
29
|
InvalidRequireCallError: InternalInvalidRequireCallError,
|
|
30
30
|
} = require("metro/src/ModuleGraph/worker/collectDependencies");
|
|
31
|
+
const collectDependencies = require("metro/src/ModuleGraph/worker/collectDependencies");
|
|
31
32
|
const generateImportNames = require("metro/src/ModuleGraph/worker/generateImportNames");
|
|
32
33
|
const JsFileWrapping = require("metro/src/ModuleGraph/worker/JsFileWrapping");
|
|
33
34
|
const nullthrows = require("nullthrows");
|
|
@@ -87,18 +88,6 @@ const minifyCode = async (
|
|
|
87
88
|
throw error;
|
|
88
89
|
}
|
|
89
90
|
};
|
|
90
|
-
const compileToBytecode = (rawCode, type, options) => {
|
|
91
|
-
let code = rawCode;
|
|
92
|
-
if (type.startsWith("js/module")) {
|
|
93
|
-
const index = code.lastIndexOf(")");
|
|
94
|
-
code =
|
|
95
|
-
code.slice(0, index) +
|
|
96
|
-
",$$METRO_D[0],$$METRO_D[1],$$METRO_D[2]" +
|
|
97
|
-
code.slice(index);
|
|
98
|
-
}
|
|
99
|
-
const HermesCompiler = require("metro-hermes-compiler");
|
|
100
|
-
return HermesCompiler.compile(code, options);
|
|
101
|
-
};
|
|
102
91
|
const disabledDependencyTransformer = {
|
|
103
92
|
transformSyncRequire: () => void 0,
|
|
104
93
|
transformImportCall: () => void 0,
|
|
@@ -223,8 +212,6 @@ async function transformJS(file, { config, options, projectRoot }) {
|
|
|
223
212
|
dependencyMapName: config.unstable_dependencyMapReservedName,
|
|
224
213
|
unstable_allowRequireContext: config.unstable_allowRequireContext,
|
|
225
214
|
};
|
|
226
|
-
// $FlowFixMe[unsupported-syntax] dynamic require
|
|
227
|
-
const collectDependencies = require(config.unstable_collectDependenciesPath);
|
|
228
215
|
({ ast, dependencies, dependencyMapName } = collectDependencies(
|
|
229
216
|
ast,
|
|
230
217
|
opts
|
|
@@ -302,23 +289,6 @@ async function transformJS(file, { config, options, projectRoot }) {
|
|
|
302
289
|
type: file.type,
|
|
303
290
|
},
|
|
304
291
|
];
|
|
305
|
-
if (options.runtimeBytecodeVersion != null) {
|
|
306
|
-
output.push({
|
|
307
|
-
data: compileToBytecode(code, file.type, {
|
|
308
|
-
sourceURL: file.filename,
|
|
309
|
-
sourceMap: fromRawMappings([
|
|
310
|
-
{
|
|
311
|
-
code,
|
|
312
|
-
source: file.code,
|
|
313
|
-
map,
|
|
314
|
-
functionMap: null,
|
|
315
|
-
path: file.filename,
|
|
316
|
-
},
|
|
317
|
-
]).toString(),
|
|
318
|
-
}),
|
|
319
|
-
type: getBytecodeFileType(file.type),
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
292
|
return {
|
|
323
293
|
dependencies,
|
|
324
294
|
output,
|
|
@@ -404,43 +374,11 @@ async function transformJSON(file, { options, config, projectRoot }) {
|
|
|
404
374
|
type: jsType,
|
|
405
375
|
},
|
|
406
376
|
];
|
|
407
|
-
if (options.runtimeBytecodeVersion != null) {
|
|
408
|
-
output.push({
|
|
409
|
-
data: compileToBytecode(code, jsType, {
|
|
410
|
-
sourceURL: file.filename,
|
|
411
|
-
sourceMap: fromRawMappings([
|
|
412
|
-
{
|
|
413
|
-
code,
|
|
414
|
-
source: file.code,
|
|
415
|
-
map,
|
|
416
|
-
functionMap: null,
|
|
417
|
-
path: file.filename,
|
|
418
|
-
},
|
|
419
|
-
]).toString(),
|
|
420
|
-
}),
|
|
421
|
-
type: getBytecodeFileType(jsType),
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
377
|
return {
|
|
425
378
|
dependencies: [],
|
|
426
379
|
output,
|
|
427
380
|
};
|
|
428
381
|
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Returns the bytecode type for a file type
|
|
432
|
-
*/
|
|
433
|
-
function getBytecodeFileType(type) {
|
|
434
|
-
switch (type) {
|
|
435
|
-
case "js/module/asset":
|
|
436
|
-
return "bytecode/module/asset";
|
|
437
|
-
case "js/script":
|
|
438
|
-
return "bytecode/script";
|
|
439
|
-
default:
|
|
440
|
-
type;
|
|
441
|
-
return "bytecode/module";
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
382
|
function getBabelTransformArgs(file, { options, config, projectRoot }) {
|
|
445
383
|
return {
|
|
446
384
|
filename: file.filename,
|
|
@@ -510,18 +448,12 @@ module.exports = {
|
|
|
510
448
|
return await transformJSWithBabel(file, context);
|
|
511
449
|
},
|
|
512
450
|
getCacheKey: (config) => {
|
|
513
|
-
const {
|
|
514
|
-
babelTransformerPath,
|
|
515
|
-
minifierPath,
|
|
516
|
-
unstable_collectDependenciesPath,
|
|
517
|
-
...remainingConfig
|
|
518
|
-
} = config;
|
|
451
|
+
const { babelTransformerPath, minifierPath, ...remainingConfig } = config;
|
|
519
452
|
const filesKey = getCacheKey([
|
|
520
453
|
require.resolve(babelTransformerPath),
|
|
521
454
|
require.resolve(minifierPath),
|
|
522
455
|
require.resolve("./utils/getMinifier"),
|
|
523
456
|
require.resolve("./utils/assetTransformer"),
|
|
524
|
-
require.resolve(unstable_collectDependenciesPath),
|
|
525
457
|
require.resolve("metro/src/ModuleGraph/worker/generateImportNames"),
|
|
526
458
|
require.resolve("metro/src/ModuleGraph/worker/JsFileWrapping"),
|
|
527
459
|
...metroTransformPlugins.getTransformPluginCacheKeyFiles(),
|
package/src/index.js.flow
CHANGED
|
@@ -18,10 +18,6 @@ import type {
|
|
|
18
18
|
CustomTransformOptions,
|
|
19
19
|
TransformProfile,
|
|
20
20
|
} from 'metro-babel-transformer';
|
|
21
|
-
import type {
|
|
22
|
-
HermesCompilerResult,
|
|
23
|
-
Options as HermesCompilerOptions,
|
|
24
|
-
} from 'metro-hermes-compiler';
|
|
25
21
|
import type {
|
|
26
22
|
BasicSourceMap,
|
|
27
23
|
FBSourceFunctionMap,
|
|
@@ -33,7 +29,6 @@ import type {
|
|
|
33
29
|
DependencyTransformer,
|
|
34
30
|
DynamicRequiresBehavior,
|
|
35
31
|
} from 'metro/src/ModuleGraph/worker/collectDependencies';
|
|
36
|
-
import typeof CollectDependenciesFn from 'metro/src/ModuleGraph/worker/collectDependencies';
|
|
37
32
|
|
|
38
33
|
const getMinifier = require('./utils/getMinifier');
|
|
39
34
|
const {transformFromAstSync} = require('@babel/core');
|
|
@@ -52,6 +47,7 @@ const countLines = require('metro/src/lib/countLines');
|
|
|
52
47
|
const {
|
|
53
48
|
InvalidRequireCallError: InternalInvalidRequireCallError,
|
|
54
49
|
} = require('metro/src/ModuleGraph/worker/collectDependencies');
|
|
50
|
+
const collectDependencies = require('metro/src/ModuleGraph/worker/collectDependencies');
|
|
55
51
|
const generateImportNames = require('metro/src/ModuleGraph/worker/generateImportNames');
|
|
56
52
|
const JsFileWrapping = require('metro/src/ModuleGraph/worker/JsFileWrapping');
|
|
57
53
|
const nullthrows = require('nullthrows');
|
|
@@ -94,7 +90,6 @@ export type JsTransformerConfig = $ReadOnly<{
|
|
|
94
90
|
optimizationSizeLimit: number,
|
|
95
91
|
publicPath: string,
|
|
96
92
|
allowOptionalDependencies: AllowOptionalDependencies,
|
|
97
|
-
unstable_collectDependenciesPath: string,
|
|
98
93
|
unstable_dependencyMapReservedName: ?string,
|
|
99
94
|
unstable_disableModuleWrapping: boolean,
|
|
100
95
|
unstable_disableNormalizePseudoGlobals: boolean,
|
|
@@ -115,17 +110,11 @@ export type JsTransformOptions = $ReadOnly<{
|
|
|
115
110
|
minify: boolean,
|
|
116
111
|
nonInlinedRequires?: $ReadOnlyArray<string>,
|
|
117
112
|
platform: ?string,
|
|
118
|
-
runtimeBytecodeVersion: ?number,
|
|
119
113
|
type: Type,
|
|
120
114
|
unstable_disableES6Transforms?: boolean,
|
|
121
115
|
unstable_transformProfile: TransformProfile,
|
|
122
116
|
}>;
|
|
123
117
|
|
|
124
|
-
export type BytecodeFileType =
|
|
125
|
-
| 'bytecode/module'
|
|
126
|
-
| 'bytecode/module/asset'
|
|
127
|
-
| 'bytecode/script';
|
|
128
|
-
|
|
129
118
|
opaque type Path = string;
|
|
130
119
|
|
|
131
120
|
type BaseFile = $ReadOnly<{
|
|
@@ -169,14 +158,9 @@ export type JsOutput = $ReadOnly<{
|
|
|
169
158
|
type: JSFileType,
|
|
170
159
|
}>;
|
|
171
160
|
|
|
172
|
-
export type BytecodeOutput = $ReadOnly<{
|
|
173
|
-
data: HermesCompilerResult,
|
|
174
|
-
type: BytecodeFileType,
|
|
175
|
-
}>;
|
|
176
|
-
|
|
177
161
|
type TransformResponse = $ReadOnly<{
|
|
178
162
|
dependencies: $ReadOnlyArray<TransformResultDependency>,
|
|
179
|
-
output: $ReadOnlyArray<JsOutput
|
|
163
|
+
output: $ReadOnlyArray<JsOutput>,
|
|
180
164
|
}>;
|
|
181
165
|
|
|
182
166
|
function getDynamicDepsBehavior(
|
|
@@ -242,23 +226,6 @@ const minifyCode = async (
|
|
|
242
226
|
}
|
|
243
227
|
};
|
|
244
228
|
|
|
245
|
-
const compileToBytecode = (
|
|
246
|
-
rawCode: string,
|
|
247
|
-
type: string,
|
|
248
|
-
options: HermesCompilerOptions,
|
|
249
|
-
): HermesCompilerResult => {
|
|
250
|
-
let code = rawCode;
|
|
251
|
-
if (type.startsWith('js/module')) {
|
|
252
|
-
const index = code.lastIndexOf(')');
|
|
253
|
-
code =
|
|
254
|
-
code.slice(0, index) +
|
|
255
|
-
',$$METRO_D[0],$$METRO_D[1],$$METRO_D[2]' +
|
|
256
|
-
code.slice(index);
|
|
257
|
-
}
|
|
258
|
-
const HermesCompiler = require('metro-hermes-compiler');
|
|
259
|
-
return HermesCompiler.compile(code, options);
|
|
260
|
-
};
|
|
261
|
-
|
|
262
229
|
const disabledDependencyTransformer: DependencyTransformer = {
|
|
263
230
|
transformSyncRequire: () => void 0,
|
|
264
231
|
transformImportCall: () => void 0,
|
|
@@ -395,8 +362,6 @@ async function transformJS(
|
|
|
395
362
|
dependencyMapName: config.unstable_dependencyMapReservedName,
|
|
396
363
|
unstable_allowRequireContext: config.unstable_allowRequireContext,
|
|
397
364
|
};
|
|
398
|
-
// $FlowFixMe[unsupported-syntax] dynamic require
|
|
399
|
-
const collectDependencies: CollectDependenciesFn = require(config.unstable_collectDependenciesPath);
|
|
400
365
|
({ast, dependencies, dependencyMapName} = collectDependencies(ast, opts));
|
|
401
366
|
} catch (error) {
|
|
402
367
|
if (error instanceof InternalInvalidRequireCallError) {
|
|
@@ -467,7 +432,7 @@ async function transformJS(
|
|
|
467
432
|
));
|
|
468
433
|
}
|
|
469
434
|
|
|
470
|
-
const output: Array<JsOutput
|
|
435
|
+
const output: Array<JsOutput> = [
|
|
471
436
|
{
|
|
472
437
|
data: {
|
|
473
438
|
code,
|
|
@@ -479,24 +444,6 @@ async function transformJS(
|
|
|
479
444
|
},
|
|
480
445
|
];
|
|
481
446
|
|
|
482
|
-
if (options.runtimeBytecodeVersion != null) {
|
|
483
|
-
output.push({
|
|
484
|
-
data: (compileToBytecode(code, file.type, {
|
|
485
|
-
sourceURL: file.filename,
|
|
486
|
-
sourceMap: fromRawMappings([
|
|
487
|
-
{
|
|
488
|
-
code,
|
|
489
|
-
source: file.code,
|
|
490
|
-
map,
|
|
491
|
-
functionMap: null,
|
|
492
|
-
path: file.filename,
|
|
493
|
-
},
|
|
494
|
-
]).toString(),
|
|
495
|
-
}): HermesCompilerResult),
|
|
496
|
-
type: getBytecodeFileType(file.type),
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
|
|
500
447
|
return {
|
|
501
448
|
dependencies,
|
|
502
449
|
output,
|
|
@@ -591,52 +538,19 @@ async function transformJSON(
|
|
|
591
538
|
jsType = 'js/module';
|
|
592
539
|
}
|
|
593
540
|
|
|
594
|
-
const output: Array<JsOutput
|
|
541
|
+
const output: Array<JsOutput> = [
|
|
595
542
|
{
|
|
596
543
|
data: {code, lineCount: countLines(code), map, functionMap: null},
|
|
597
544
|
type: jsType,
|
|
598
545
|
},
|
|
599
546
|
];
|
|
600
547
|
|
|
601
|
-
if (options.runtimeBytecodeVersion != null) {
|
|
602
|
-
output.push({
|
|
603
|
-
data: (compileToBytecode(code, jsType, {
|
|
604
|
-
sourceURL: file.filename,
|
|
605
|
-
sourceMap: fromRawMappings([
|
|
606
|
-
{
|
|
607
|
-
code,
|
|
608
|
-
source: file.code,
|
|
609
|
-
map,
|
|
610
|
-
functionMap: null,
|
|
611
|
-
path: file.filename,
|
|
612
|
-
},
|
|
613
|
-
]).toString(),
|
|
614
|
-
}): HermesCompilerResult),
|
|
615
|
-
type: getBytecodeFileType(jsType),
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
|
|
619
548
|
return {
|
|
620
549
|
dependencies: [],
|
|
621
550
|
output,
|
|
622
551
|
};
|
|
623
552
|
}
|
|
624
553
|
|
|
625
|
-
/**
|
|
626
|
-
* Returns the bytecode type for a file type
|
|
627
|
-
*/
|
|
628
|
-
function getBytecodeFileType(type: JSFileType): BytecodeFileType {
|
|
629
|
-
switch (type) {
|
|
630
|
-
case 'js/module/asset':
|
|
631
|
-
return 'bytecode/module/asset';
|
|
632
|
-
case 'js/script':
|
|
633
|
-
return 'bytecode/script';
|
|
634
|
-
default:
|
|
635
|
-
(type: 'js/module');
|
|
636
|
-
return 'bytecode/module';
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
|
|
640
554
|
function getBabelTransformArgs(
|
|
641
555
|
file: $ReadOnly<{filename: Path, code: string, ...}>,
|
|
642
556
|
{options, config, projectRoot}: TransformationContext,
|
|
@@ -724,19 +638,13 @@ module.exports = {
|
|
|
724
638
|
},
|
|
725
639
|
|
|
726
640
|
getCacheKey: (config: JsTransformerConfig): string => {
|
|
727
|
-
const {
|
|
728
|
-
babelTransformerPath,
|
|
729
|
-
minifierPath,
|
|
730
|
-
unstable_collectDependenciesPath,
|
|
731
|
-
...remainingConfig
|
|
732
|
-
} = config;
|
|
641
|
+
const {babelTransformerPath, minifierPath, ...remainingConfig} = config;
|
|
733
642
|
|
|
734
643
|
const filesKey = getCacheKey([
|
|
735
644
|
require.resolve(babelTransformerPath),
|
|
736
645
|
require.resolve(minifierPath),
|
|
737
646
|
require.resolve('./utils/getMinifier'),
|
|
738
647
|
require.resolve('./utils/assetTransformer'),
|
|
739
|
-
require.resolve(unstable_collectDependenciesPath),
|
|
740
648
|
require.resolve('metro/src/ModuleGraph/worker/generateImportNames'),
|
|
741
649
|
require.resolve('metro/src/ModuleGraph/worker/JsFileWrapping'),
|
|
742
650
|
...metroTransformPlugins.getTransformPluginCacheKeyFiles(),
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
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 {DynamicRequiresBehavior} from 'metro';
|
|
12
|
+
import type {TransformResultDependency} from 'metro/DeltaBundler';
|
|
13
|
+
import type {AllowOptionalDependencies} from 'metro/DeltaBundler/types';
|
|
14
|
+
import type {
|
|
15
|
+
CustomTransformOptions,
|
|
16
|
+
TransformProfile,
|
|
17
|
+
} from 'metro-babel-transformer';
|
|
18
|
+
import type {
|
|
19
|
+
BasicSourceMap,
|
|
20
|
+
FBSourceFunctionMap,
|
|
21
|
+
MetroSourceMapSegmentTuple,
|
|
22
|
+
} from 'metro-source-map';
|
|
23
|
+
|
|
24
|
+
export type MinifierConfig = Readonly<Record<string, unknown>>;
|
|
25
|
+
|
|
26
|
+
export interface MinifierOptions {
|
|
27
|
+
code: string;
|
|
28
|
+
map?: BasicSourceMap;
|
|
29
|
+
filename: string;
|
|
30
|
+
reserved: ReadonlyArray<string>;
|
|
31
|
+
config: MinifierConfig;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface MinifierResult {
|
|
35
|
+
code: string;
|
|
36
|
+
map?: BasicSourceMap;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Minifier = (
|
|
40
|
+
options: MinifierOptions,
|
|
41
|
+
) => MinifierResult | Promise<MinifierResult>;
|
|
42
|
+
|
|
43
|
+
export type Type = 'script' | 'module' | 'asset';
|
|
44
|
+
|
|
45
|
+
export type JsTransformerConfig = Readonly<{
|
|
46
|
+
assetPlugins: ReadonlyArray<string>;
|
|
47
|
+
assetRegistryPath: string;
|
|
48
|
+
asyncRequireModulePath: string;
|
|
49
|
+
babelTransformerPath: string;
|
|
50
|
+
dynamicDepsInPackages: DynamicRequiresBehavior;
|
|
51
|
+
enableBabelRCLookup: boolean;
|
|
52
|
+
enableBabelRuntime: boolean;
|
|
53
|
+
globalPrefix: string;
|
|
54
|
+
hermesParser: boolean;
|
|
55
|
+
minifierConfig: MinifierConfig;
|
|
56
|
+
minifierPath: string;
|
|
57
|
+
optimizationSizeLimit: number;
|
|
58
|
+
publicPath: string;
|
|
59
|
+
allowOptionalDependencies: AllowOptionalDependencies;
|
|
60
|
+
unstable_collectDependenciesPath: string;
|
|
61
|
+
unstable_dependencyMapReservedName?: string;
|
|
62
|
+
unstable_disableModuleWrapping: boolean;
|
|
63
|
+
unstable_disableNormalizePseudoGlobals: boolean;
|
|
64
|
+
unstable_compactOutput: boolean;
|
|
65
|
+
/** Enable `require.context` statements which can be used to import multiple files in a directory. */
|
|
66
|
+
unstable_allowRequireContext: boolean;
|
|
67
|
+
}>;
|
|
68
|
+
|
|
69
|
+
export {CustomTransformOptions} from 'metro-babel-transformer';
|
|
70
|
+
|
|
71
|
+
export type JsTransformOptions = Readonly<{
|
|
72
|
+
customTransformOptions?: CustomTransformOptions;
|
|
73
|
+
dev: boolean;
|
|
74
|
+
experimentalImportSupport?: boolean;
|
|
75
|
+
hot: boolean;
|
|
76
|
+
inlinePlatform: boolean;
|
|
77
|
+
inlineRequires: boolean;
|
|
78
|
+
minify: boolean;
|
|
79
|
+
nonInlinedRequires?: ReadonlyArray<string>;
|
|
80
|
+
platform?: string;
|
|
81
|
+
runtimeBytecodeVersion?: number;
|
|
82
|
+
type: Type;
|
|
83
|
+
unstable_disableES6Transforms?: boolean;
|
|
84
|
+
unstable_transformProfile: TransformProfile;
|
|
85
|
+
}>;
|
|
86
|
+
|
|
87
|
+
export type BytecodeFileType =
|
|
88
|
+
| 'bytecode/module'
|
|
89
|
+
| 'bytecode/module/asset'
|
|
90
|
+
| 'bytecode/script';
|
|
91
|
+
|
|
92
|
+
export type JSFileType = 'js/script' | 'js/module' | 'js/module/asset';
|
|
93
|
+
|
|
94
|
+
export type JsOutput = Readonly<{
|
|
95
|
+
data: Readonly<{
|
|
96
|
+
code: string;
|
|
97
|
+
lineCount: number;
|
|
98
|
+
map: MetroSourceMapSegmentTuple[];
|
|
99
|
+
functionMap: FBSourceFunctionMap | null;
|
|
100
|
+
}>;
|
|
101
|
+
type: JSFileType;
|
|
102
|
+
}>;
|
|
103
|
+
|
|
104
|
+
// Hermes byte-code output type
|
|
105
|
+
export type BytecodeOutput = unknown;
|
|
106
|
+
|
|
107
|
+
export type TransformResponse = Readonly<{
|
|
108
|
+
dependencies: ReadonlyArray<TransformResultDependency>;
|
|
109
|
+
output: ReadonlyArray<JsOutput | BytecodeOutput>;
|
|
110
|
+
}>;
|
|
111
|
+
|
|
112
|
+
export function transform(
|
|
113
|
+
config: JsTransformerConfig,
|
|
114
|
+
projectRoot: string,
|
|
115
|
+
filename: string,
|
|
116
|
+
data: Buffer,
|
|
117
|
+
options: JsTransformOptions,
|
|
118
|
+
): Promise<TransformResponse>;
|
|
119
|
+
|
|
120
|
+
export function getCacheKey(config: JsTransformerConfig): string;
|