metro-transform-worker 0.83.4 → 0.83.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 +10 -9
- package/src/index.d.ts +127 -0
- package/src/index.js +10 -11
- package/src/index.js.flow +17 -5
- package/src/utils/assetTransformer.d.ts +25 -0
- package/src/utils/assetTransformer.js +1 -5
- 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.83.
|
|
3
|
+
"version": "0.83.6",
|
|
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
|
|
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",
|
|
@@ -23,13 +24,13 @@
|
|
|
23
24
|
"@babel/parser": "^7.29.0",
|
|
24
25
|
"@babel/types": "^7.29.0",
|
|
25
26
|
"flow-enums-runtime": "^0.0.6",
|
|
26
|
-
"metro": "0.83.
|
|
27
|
-
"metro-babel-transformer": "0.83.
|
|
28
|
-
"metro-cache": "0.83.
|
|
29
|
-
"metro-cache-key": "0.83.
|
|
30
|
-
"metro-minify-terser": "0.83.
|
|
31
|
-
"metro-source-map": "0.83.
|
|
32
|
-
"metro-transform-plugins": "0.83.
|
|
27
|
+
"metro": "0.83.6",
|
|
28
|
+
"metro-babel-transformer": "0.83.6",
|
|
29
|
+
"metro-cache": "0.83.6",
|
|
30
|
+
"metro-cache-key": "0.83.6",
|
|
31
|
+
"metro-minify-terser": "0.83.6",
|
|
32
|
+
"metro-source-map": "0.83.6",
|
|
33
|
+
"metro-transform-plugins": "0.83.6",
|
|
33
34
|
"nullthrows": "^1.1.1"
|
|
34
35
|
},
|
|
35
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
|
@@ -30,11 +30,7 @@ var JsFileWrapping = _interopRequireWildcard(
|
|
|
30
30
|
);
|
|
31
31
|
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
32
32
|
function _interopRequireDefault(e) {
|
|
33
|
-
return e && e.__esModule
|
|
34
|
-
? e
|
|
35
|
-
: {
|
|
36
|
-
default: e,
|
|
37
|
-
};
|
|
33
|
+
return e && e.__esModule ? e : { default: e };
|
|
38
34
|
}
|
|
39
35
|
function _interopRequireWildcard(e, t) {
|
|
40
36
|
if ("function" == typeof WeakMap)
|
|
@@ -44,10 +40,7 @@ function _interopRequireWildcard(e, t) {
|
|
|
44
40
|
if (!t && e && e.__esModule) return e;
|
|
45
41
|
var o,
|
|
46
42
|
i,
|
|
47
|
-
f = {
|
|
48
|
-
__proto__: null,
|
|
49
|
-
default: e,
|
|
50
|
-
};
|
|
43
|
+
f = { __proto__: null, default: e };
|
|
51
44
|
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
52
45
|
return f;
|
|
53
46
|
if ((o = t ? n : r)) {
|
|
@@ -506,7 +499,7 @@ const transform = async (config, projectRoot, filename, data, options) => {
|
|
|
506
499
|
return await transformJSWithBabel(file, context);
|
|
507
500
|
};
|
|
508
501
|
exports.transform = transform;
|
|
509
|
-
const getCacheKey = (config) => {
|
|
502
|
+
const getCacheKey = (config, opts) => {
|
|
510
503
|
const { babelTransformerPath, minifierPath, ...remainingConfig } = config;
|
|
511
504
|
const filesKey = (0, _metroCacheKey.getCacheKey)([
|
|
512
505
|
__filename,
|
|
@@ -519,10 +512,16 @@ const getCacheKey = (config) => {
|
|
|
519
512
|
..._metroTransformPlugins.default.getTransformPluginCacheKeyFiles(),
|
|
520
513
|
]);
|
|
521
514
|
const babelTransformer = require(babelTransformerPath);
|
|
515
|
+
const babelTransformerCacheKey = babelTransformer.getCacheKey
|
|
516
|
+
? babelTransformer.getCacheKey({
|
|
517
|
+
projectRoot: opts?.projectRoot,
|
|
518
|
+
enableBabelRCLookup: config.enableBabelRCLookup,
|
|
519
|
+
})
|
|
520
|
+
: "";
|
|
522
521
|
return [
|
|
523
522
|
filesKey,
|
|
524
523
|
(0, _metroCache.stableHash)(remainingConfig).toString("hex"),
|
|
525
|
-
|
|
524
|
+
babelTransformerCacheKey,
|
|
526
525
|
].join("$");
|
|
527
526
|
};
|
|
528
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}>;
|
|
@@ -8,11 +8,7 @@ var _Assets = require("metro/private/Assets");
|
|
|
8
8
|
var _util = require("metro/private/Bundler/util");
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
function _interopRequireDefault(e) {
|
|
11
|
-
return e && e.__esModule
|
|
12
|
-
? e
|
|
13
|
-
: {
|
|
14
|
-
default: e,
|
|
15
|
-
};
|
|
11
|
+
return e && e.__esModule ? e : { default: e };
|
|
16
12
|
}
|
|
17
13
|
async function transform(
|
|
18
14
|
{ filename, options, src },
|
|
@@ -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;
|