metro-transform-worker 0.84.1 → 0.84.3
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 +8 -8
- package/src/index.d.ts +127 -0
- package/src/index.js +8 -2
- package/src/index.js.flow +17 -5
- package/src/utils/assetTransformer.d.ts +25 -0
- package/src/utils/getMinifier.d.ts +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro-transform-worker",
|
|
3
|
-
"version": "0.84.
|
|
3
|
+
"version": "0.84.3",
|
|
4
4
|
"description": "🚇 Transform worker for Metro.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"@babel/parser": "^7.29.0",
|
|
25
25
|
"@babel/types": "^7.29.0",
|
|
26
26
|
"flow-enums-runtime": "^0.0.6",
|
|
27
|
-
"metro": "0.84.
|
|
28
|
-
"metro-babel-transformer": "0.84.
|
|
29
|
-
"metro-cache": "0.84.
|
|
30
|
-
"metro-cache-key": "0.84.
|
|
31
|
-
"metro-minify-terser": "0.84.
|
|
32
|
-
"metro-source-map": "0.84.
|
|
33
|
-
"metro-transform-plugins": "0.84.
|
|
27
|
+
"metro": "0.84.3",
|
|
28
|
+
"metro-babel-transformer": "0.84.3",
|
|
29
|
+
"metro-cache": "0.84.3",
|
|
30
|
+
"metro-cache-key": "0.84.3",
|
|
31
|
+
"metro-minify-terser": "0.84.3",
|
|
32
|
+
"metro-source-map": "0.84.3",
|
|
33
|
+
"metro-transform-plugins": "0.84.3",
|
|
34
34
|
"nullthrows": "^1.1.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<165882da0b131608da36b1cbd00ecf28>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro-transform-worker/src/index.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {
|
|
19
|
+
CustomTransformOptions,
|
|
20
|
+
TransformProfile,
|
|
21
|
+
} from 'metro-babel-transformer';
|
|
22
|
+
import type {
|
|
23
|
+
BasicSourceMap,
|
|
24
|
+
FBSourceFunctionMap,
|
|
25
|
+
MetroSourceMapSegmentTuple,
|
|
26
|
+
} from 'metro-source-map';
|
|
27
|
+
import type {TransformResultDependency} from 'metro/private/DeltaBundler';
|
|
28
|
+
import type {AllowOptionalDependencies} from 'metro/private/DeltaBundler/types';
|
|
29
|
+
import type {DynamicRequiresBehavior} from 'metro/private/ModuleGraph/worker/collectDependencies';
|
|
30
|
+
|
|
31
|
+
type MinifierConfig = Readonly<{[$$Key$$: string]: unknown}>;
|
|
32
|
+
export type MinifierOptions = {
|
|
33
|
+
code: string;
|
|
34
|
+
map: null | undefined | BasicSourceMap;
|
|
35
|
+
filename: string;
|
|
36
|
+
reserved: ReadonlyArray<string>;
|
|
37
|
+
config: MinifierConfig;
|
|
38
|
+
};
|
|
39
|
+
export type MinifierResult = {code: string; map?: BasicSourceMap};
|
|
40
|
+
export type Minifier = (
|
|
41
|
+
$$PARAM_0$$: MinifierOptions,
|
|
42
|
+
) => MinifierResult | Promise<MinifierResult>;
|
|
43
|
+
export type Type = 'script' | 'module' | 'asset';
|
|
44
|
+
export type JsTransformerConfig = Readonly<{
|
|
45
|
+
assetPlugins: ReadonlyArray<string>;
|
|
46
|
+
assetRegistryPath: string;
|
|
47
|
+
asyncRequireModulePath: string;
|
|
48
|
+
babelTransformerPath: string;
|
|
49
|
+
dynamicDepsInPackages: DynamicRequiresBehavior;
|
|
50
|
+
enableBabelRCLookup: boolean;
|
|
51
|
+
enableBabelRuntime: boolean | string;
|
|
52
|
+
globalPrefix: string;
|
|
53
|
+
hermesParser: boolean;
|
|
54
|
+
minifierConfig: MinifierConfig;
|
|
55
|
+
minifierPath: string;
|
|
56
|
+
optimizationSizeLimit: number;
|
|
57
|
+
publicPath: string;
|
|
58
|
+
allowOptionalDependencies: AllowOptionalDependencies;
|
|
59
|
+
unstable_dependencyMapReservedName: null | undefined | string;
|
|
60
|
+
unstable_disableModuleWrapping: boolean;
|
|
61
|
+
unstable_disableNormalizePseudoGlobals: boolean;
|
|
62
|
+
unstable_compactOutput: boolean;
|
|
63
|
+
/** Enable `require.context` statements which can be used to import multiple files in a directory. */
|
|
64
|
+
unstable_allowRequireContext: boolean;
|
|
65
|
+
/** With inlineRequires, enable a module-scope memo var and inline as (v || v=require('foo')) */
|
|
66
|
+
unstable_memoizeInlineRequires?: boolean;
|
|
67
|
+
/** With inlineRequires, do not memoize these module specifiers */
|
|
68
|
+
unstable_nonMemoizedInlineRequires?: ReadonlyArray<string>;
|
|
69
|
+
/** Whether to rename scoped `require` functions to `_$$_REQUIRE`, usually an extraneous operation when serializing to iife (default). */
|
|
70
|
+
unstable_renameRequire?: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
export type {CustomTransformOptions} from 'metro-babel-transformer';
|
|
73
|
+
export type JsTransformOptions = Readonly<{
|
|
74
|
+
customTransformOptions?: CustomTransformOptions;
|
|
75
|
+
dev: boolean;
|
|
76
|
+
experimentalImportSupport?: boolean;
|
|
77
|
+
inlinePlatform: boolean;
|
|
78
|
+
inlineRequires: boolean;
|
|
79
|
+
minify: boolean;
|
|
80
|
+
nonInlinedRequires?: ReadonlyArray<string>;
|
|
81
|
+
platform: null | undefined | string;
|
|
82
|
+
type: Type;
|
|
83
|
+
unstable_memoizeInlineRequires?: boolean;
|
|
84
|
+
unstable_nonMemoizedInlineRequires?: ReadonlyArray<string>;
|
|
85
|
+
unstable_staticHermesOptimizedRequire?: boolean;
|
|
86
|
+
unstable_transformProfile: TransformProfile;
|
|
87
|
+
}>;
|
|
88
|
+
type JSFileType = 'js/script' | 'js/module' | 'js/module/asset';
|
|
89
|
+
export type JsOutput = Readonly<{
|
|
90
|
+
data: Readonly<{
|
|
91
|
+
code: string;
|
|
92
|
+
lineCount: number;
|
|
93
|
+
map: Array<MetroSourceMapSegmentTuple>;
|
|
94
|
+
functionMap: null | undefined | FBSourceFunctionMap;
|
|
95
|
+
}>;
|
|
96
|
+
type: JSFileType;
|
|
97
|
+
}>;
|
|
98
|
+
type TransformResponse = Readonly<{
|
|
99
|
+
dependencies: ReadonlyArray<TransformResultDependency>;
|
|
100
|
+
output: ReadonlyArray<JsOutput>;
|
|
101
|
+
}>;
|
|
102
|
+
export declare const transform: (
|
|
103
|
+
config: JsTransformerConfig,
|
|
104
|
+
projectRoot: string,
|
|
105
|
+
filename: string,
|
|
106
|
+
data: Buffer,
|
|
107
|
+
options: JsTransformOptions,
|
|
108
|
+
) => Promise<TransformResponse>;
|
|
109
|
+
export declare type transform = typeof transform;
|
|
110
|
+
export declare const getCacheKey: (
|
|
111
|
+
config: JsTransformerConfig,
|
|
112
|
+
opts?: Readonly<{projectRoot: string}>,
|
|
113
|
+
) => string;
|
|
114
|
+
export declare type getCacheKey = typeof getCacheKey;
|
|
115
|
+
/**
|
|
116
|
+
* Backwards-compatibility with CommonJS consumers using interopRequireDefault.
|
|
117
|
+
* Do not add to this list.
|
|
118
|
+
*
|
|
119
|
+
* @deprecated Default import from 'metro-transform-worker' is deprecated, use named exports.
|
|
120
|
+
*/
|
|
121
|
+
declare const $$EXPORT_DEFAULT_DECLARATION$$: {
|
|
122
|
+
getCacheKey: typeof getCacheKey;
|
|
123
|
+
transform: typeof transform;
|
|
124
|
+
};
|
|
125
|
+
declare type $$EXPORT_DEFAULT_DECLARATION$$ =
|
|
126
|
+
typeof $$EXPORT_DEFAULT_DECLARATION$$;
|
|
127
|
+
export default $$EXPORT_DEFAULT_DECLARATION$$;
|
package/src/index.js
CHANGED
|
@@ -499,7 +499,7 @@ const transform = async (config, projectRoot, filename, data, options) => {
|
|
|
499
499
|
return await transformJSWithBabel(file, context);
|
|
500
500
|
};
|
|
501
501
|
exports.transform = transform;
|
|
502
|
-
const getCacheKey = (config) => {
|
|
502
|
+
const getCacheKey = (config, opts) => {
|
|
503
503
|
const { babelTransformerPath, minifierPath, ...remainingConfig } = config;
|
|
504
504
|
const filesKey = (0, _metroCacheKey.getCacheKey)([
|
|
505
505
|
__filename,
|
|
@@ -512,10 +512,16 @@ const getCacheKey = (config) => {
|
|
|
512
512
|
..._metroTransformPlugins.default.getTransformPluginCacheKeyFiles(),
|
|
513
513
|
]);
|
|
514
514
|
const babelTransformer = require(babelTransformerPath);
|
|
515
|
+
const babelTransformerCacheKey = babelTransformer.getCacheKey
|
|
516
|
+
? babelTransformer.getCacheKey({
|
|
517
|
+
projectRoot: opts?.projectRoot,
|
|
518
|
+
enableBabelRCLookup: config.enableBabelRCLookup,
|
|
519
|
+
})
|
|
520
|
+
: "";
|
|
515
521
|
return [
|
|
516
522
|
filesKey,
|
|
517
523
|
(0, _metroCache.stableHash)(remainingConfig).toString("hex"),
|
|
518
|
-
|
|
524
|
+
babelTransformerCacheKey,
|
|
519
525
|
].join("$");
|
|
520
526
|
};
|
|
521
527
|
exports.getCacheKey = getCacheKey;
|
package/src/index.js.flow
CHANGED
|
@@ -215,7 +215,7 @@ const minifyCode = async (
|
|
|
215
215
|
code,
|
|
216
216
|
// functionMap is overridden by the serializer
|
|
217
217
|
functionMap: null,
|
|
218
|
-
// isIgnored is
|
|
218
|
+
// isIgnored is overridden by the serializer
|
|
219
219
|
isIgnored: false,
|
|
220
220
|
map,
|
|
221
221
|
path: filename,
|
|
@@ -376,7 +376,7 @@ async function transformJS(
|
|
|
376
376
|
let wrappedAst;
|
|
377
377
|
|
|
378
378
|
// If the module to transform is a script (meaning that is not part of the
|
|
379
|
-
// dependency graph and
|
|
379
|
+
// dependency graph and its code will just be prepended to the bundle modules),
|
|
380
380
|
// we need to wrap it differently than a commonJS module (also, scripts do
|
|
381
381
|
// not have dependencies).
|
|
382
382
|
if (file.type === 'js/script') {
|
|
@@ -718,7 +718,10 @@ export const transform = async (
|
|
|
718
718
|
return await transformJSWithBabel(file, context);
|
|
719
719
|
};
|
|
720
720
|
|
|
721
|
-
export const getCacheKey = (
|
|
721
|
+
export const getCacheKey = (
|
|
722
|
+
config: JsTransformerConfig,
|
|
723
|
+
opts?: Readonly<{projectRoot: string, ...}>,
|
|
724
|
+
): string => {
|
|
722
725
|
const {babelTransformerPath, minifierPath, ...remainingConfig} = config;
|
|
723
726
|
|
|
724
727
|
const filesKey = metroGetCacheKey([
|
|
@@ -733,11 +736,20 @@ export const getCacheKey = (config: JsTransformerConfig): string => {
|
|
|
733
736
|
]);
|
|
734
737
|
|
|
735
738
|
// $FlowFixMe[unsupported-syntax]
|
|
736
|
-
const babelTransformer = require(babelTransformerPath);
|
|
739
|
+
const babelTransformer = require(babelTransformerPath) as BabelTransformer;
|
|
740
|
+
|
|
741
|
+
// Get cache key from babel transformer, which may include user's babel config files
|
|
742
|
+
const babelTransformerCacheKey = babelTransformer.getCacheKey
|
|
743
|
+
? babelTransformer.getCacheKey({
|
|
744
|
+
projectRoot: opts?.projectRoot,
|
|
745
|
+
enableBabelRCLookup: config.enableBabelRCLookup,
|
|
746
|
+
})
|
|
747
|
+
: '';
|
|
748
|
+
|
|
737
749
|
return [
|
|
738
750
|
filesKey,
|
|
739
751
|
stableHash(remainingConfig).toString('hex'),
|
|
740
|
-
|
|
752
|
+
babelTransformerCacheKey,
|
|
741
753
|
].join('$');
|
|
742
754
|
};
|
|
743
755
|
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<b122890ad90539195b3a9805a1a7e02f>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro-transform-worker/src/utils/assetTransformer.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {File} from '@babel/types';
|
|
19
|
+
import type {BabelTransformerArgs} from 'metro-babel-transformer';
|
|
20
|
+
|
|
21
|
+
export declare function transform(
|
|
22
|
+
$$PARAM_0$$: BabelTransformerArgs,
|
|
23
|
+
assetRegistryPath: string,
|
|
24
|
+
assetDataPlugins: ReadonlyArray<string>,
|
|
25
|
+
): Promise<{ast: File}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
* @noformat
|
|
8
|
+
* @oncall react_native
|
|
9
|
+
* @generated SignedSource<<410ba17e82af72676f3993ebd1d0f60f>>
|
|
10
|
+
*
|
|
11
|
+
* This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
|
|
12
|
+
* Original file: packages/metro-transform-worker/src/utils/getMinifier.js
|
|
13
|
+
* To regenerate, run:
|
|
14
|
+
* js1 build metro-ts-defs (internal) OR
|
|
15
|
+
* yarn run build-ts-defs (OSS)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type {Minifier} from '../index.js';
|
|
19
|
+
|
|
20
|
+
declare function getMinifier(minifierPath: string): Minifier;
|
|
21
|
+
export default getMinifier;
|