metro 0.71.0 → 0.71.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 +23 -22
- package/src/Bundler.js +0 -2
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.js +2 -0
- package/src/DeltaBundler/DeltaCalculator.js.flow +2 -0
- package/src/DeltaBundler/Worker.flow.js +78 -0
- package/src/DeltaBundler/Worker.flow.js.flow +121 -0
- package/src/DeltaBundler/Worker.js +8 -66
- package/src/DeltaBundler/Worker.js.flow +8 -107
- package/src/DeltaBundler/WorkerFarm.js.flow +2 -2
- package/src/DeltaBundler/__fixtures__/hasteImpl.js +4 -0
- package/src/DeltaBundler/graphOperations.js +382 -222
- package/src/DeltaBundler/graphOperations.js.flow +404 -232
- package/src/DeltaBundler/types.flow.js +6 -0
- package/src/DeltaBundler/types.flow.js.flow +7 -1
- package/src/DeltaBundler.js +0 -2
- package/src/DeltaBundler.js.flow +1 -1
- package/src/HmrServer.js +0 -2
- package/src/HmrServer.js.flow +1 -2
- package/src/ModuleGraph/node-haste/node-haste.flow.js +0 -1
- package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +1 -2
- package/src/ModuleGraph/node-haste/node-haste.js.flow +7 -2
- package/src/ModuleGraph/output/util.js.flow +2 -2
- package/src/ModuleGraph/silent-console.js +5 -4
- package/src/ModuleGraph/silent-console.js.flow +8 -4
- package/src/ModuleGraph/worker/collectDependencies.js +215 -8
- package/src/ModuleGraph/worker/collectDependencies.js.flow +233 -13
- package/src/Server.js +2 -0
- package/src/Server.js.flow +9 -2
- package/src/cli.js +5 -0
- package/src/cli.js.flow +5 -0
- package/src/commands/build.js +4 -3
- package/src/commands/build.js.flow +3 -1
- package/src/commands/serve.js +3 -3
- package/src/commands/serve.js.flow +3 -1
- package/src/index.flow.js +392 -0
- package/src/index.flow.js.flow +480 -0
- package/src/index.js +8 -380
- package/src/index.js.flow +8 -466
- package/src/lib/CountingSet.js +116 -0
- package/src/lib/CountingSet.js.flow +126 -0
- package/src/lib/JsonReporter.js +0 -2
- package/src/lib/JsonReporter.js.flow +1 -1
- package/src/lib/getAppendScripts.js +10 -4
- package/src/lib/getAppendScripts.js.flow +6 -4
- package/src/lib/getPreludeCode.js +19 -1
- package/src/lib/getPreludeCode.js.flow +15 -0
- package/src/lib/getPrependedScripts.js +10 -2
- package/src/lib/getPrependedScripts.js.flow +11 -2
- package/src/lib/reporting.js +0 -2
- package/src/lib/reporting.js.flow +2 -1
- package/src/node-haste/DependencyGraph/ModuleResolution.js +15 -3
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +15 -0
- package/src/node-haste/DependencyGraph/createHasteMap.js +78 -19
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +14 -9
- package/src/node-haste/DependencyGraph.js +2 -2
- package/src/node-haste/DependencyGraph.js.flow +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.71.
|
|
3
|
+
"version": "0.71.3",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -31,27 +31,27 @@
|
|
|
31
31
|
"error-stack-parser": "^2.0.6",
|
|
32
32
|
"fs-extra": "^1.0.0",
|
|
33
33
|
"graceful-fs": "^4.2.4",
|
|
34
|
-
"hermes-parser": "0.
|
|
34
|
+
"hermes-parser": "0.8.0",
|
|
35
35
|
"image-size": "^0.6.0",
|
|
36
36
|
"invariant": "^2.2.4",
|
|
37
37
|
"jest-worker": "^27.2.0",
|
|
38
38
|
"lodash.throttle": "^4.1.1",
|
|
39
|
-
"metro-babel-transformer": "0.71.
|
|
40
|
-
"metro-cache": "0.71.
|
|
41
|
-
"metro-cache-key": "0.71.
|
|
42
|
-
"metro-config": "0.71.
|
|
43
|
-
"metro-core": "0.71.
|
|
44
|
-
"metro-file-map": "0.71.
|
|
45
|
-
"metro-hermes-compiler": "0.71.
|
|
46
|
-
"metro-inspector-proxy": "0.71.
|
|
47
|
-
"metro-minify-uglify": "0.71.
|
|
48
|
-
"metro-react-native-babel-preset": "0.71.
|
|
49
|
-
"metro-resolver": "0.71.
|
|
50
|
-
"metro-runtime": "0.71.
|
|
51
|
-
"metro-source-map": "0.71.
|
|
52
|
-
"metro-symbolicate": "0.71.
|
|
53
|
-
"metro-transform-plugins": "0.71.
|
|
54
|
-
"metro-transform-worker": "0.71.
|
|
39
|
+
"metro-babel-transformer": "0.71.3",
|
|
40
|
+
"metro-cache": "0.71.3",
|
|
41
|
+
"metro-cache-key": "0.71.3",
|
|
42
|
+
"metro-config": "0.71.3",
|
|
43
|
+
"metro-core": "0.71.3",
|
|
44
|
+
"metro-file-map": "0.71.3",
|
|
45
|
+
"metro-hermes-compiler": "0.71.3",
|
|
46
|
+
"metro-inspector-proxy": "0.71.3",
|
|
47
|
+
"metro-minify-uglify": "0.71.3",
|
|
48
|
+
"metro-react-native-babel-preset": "0.71.3",
|
|
49
|
+
"metro-resolver": "0.71.3",
|
|
50
|
+
"metro-runtime": "0.71.3",
|
|
51
|
+
"metro-source-map": "0.71.3",
|
|
52
|
+
"metro-symbolicate": "0.71.3",
|
|
53
|
+
"metro-transform-plugins": "0.71.3",
|
|
54
|
+
"metro-transform-worker": "0.71.3",
|
|
55
55
|
"mime-types": "^2.1.27",
|
|
56
56
|
"node-fetch": "^2.2.0",
|
|
57
57
|
"nullthrows": "^1.1.1",
|
|
@@ -66,13 +66,14 @@
|
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
|
|
69
|
-
"acorn": "^
|
|
69
|
+
"acorn": "^8.7.1",
|
|
70
70
|
"babel-jest": "^26.6.3",
|
|
71
71
|
"dedent": "^0.7.0",
|
|
72
72
|
"jest-snapshot": "^26.5.2",
|
|
73
|
-
"metro-
|
|
74
|
-
"metro-
|
|
75
|
-
"metro-react-native-babel-
|
|
73
|
+
"metro-babel-register": "0.71.3",
|
|
74
|
+
"metro-memory-fs": "0.71.3",
|
|
75
|
+
"metro-react-native-babel-preset": "0.71.3",
|
|
76
|
+
"metro-react-native-babel-transformer": "0.71.3",
|
|
76
77
|
"stack-trace": "^0.0.10"
|
|
77
78
|
},
|
|
78
79
|
"license": "MIT"
|
package/src/Bundler.js
CHANGED
|
@@ -13,8 +13,6 @@ const Transformer = require("./DeltaBundler/Transformer");
|
|
|
13
13
|
|
|
14
14
|
const DependencyGraph = require("./node-haste/DependencyGraph");
|
|
15
15
|
|
|
16
|
-
const { EventEmitter } = require("events");
|
|
17
|
-
|
|
18
16
|
class Bundler {
|
|
19
17
|
constructor(config, options) {
|
|
20
18
|
this._depGraph = new DependencyGraph(config, options);
|
package/src/Bundler.js.flow
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
import type {TransformResultWithSource} from './DeltaBundler';
|
|
14
14
|
import type {TransformOptions} from './DeltaBundler/Worker';
|
|
15
15
|
import type {ConfigT} from 'metro-config/src/configTypes.flow';
|
|
16
|
+
import type EventEmitter from 'events';
|
|
16
17
|
|
|
17
18
|
const Transformer = require('./DeltaBundler/Transformer');
|
|
18
19
|
const DependencyGraph = require('./node-haste/DependencyGraph');
|
|
19
|
-
const {EventEmitter} = require('events');
|
|
20
20
|
|
|
21
21
|
export type BundlerOptions = $ReadOnly<{
|
|
22
22
|
hasReducedPerformance?: boolean,
|
|
@@ -130,6 +130,8 @@ class DeltaCalculator extends EventEmitter {
|
|
|
130
130
|
getGraph() {
|
|
131
131
|
return this._graph;
|
|
132
132
|
}
|
|
133
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
134
|
+
* LTI update could not be added via codemod */
|
|
133
135
|
|
|
134
136
|
_handleMultipleFileChanges = ({ eventsQueue }) => {
|
|
135
137
|
eventsQueue.forEach(this._handleFileChange);
|
|
@@ -158,6 +158,8 @@ class DeltaCalculator<T> extends EventEmitter {
|
|
|
158
158
|
return this._graph;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
162
|
+
* LTI update could not be added via codemod */
|
|
161
163
|
_handleMultipleFileChanges = ({eventsQueue}) => {
|
|
162
164
|
eventsQueue.forEach(this._handleFileChange);
|
|
163
165
|
};
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
*/
|
|
10
|
+
"use strict";
|
|
11
|
+
|
|
12
|
+
const traverse = require("@babel/traverse").default;
|
|
13
|
+
|
|
14
|
+
const crypto = require("crypto");
|
|
15
|
+
|
|
16
|
+
const fs = require("fs");
|
|
17
|
+
|
|
18
|
+
const path = require("path");
|
|
19
|
+
|
|
20
|
+
async function transform(
|
|
21
|
+
filename,
|
|
22
|
+
transformOptions,
|
|
23
|
+
projectRoot,
|
|
24
|
+
transformerConfig
|
|
25
|
+
) {
|
|
26
|
+
// eslint-disable-next-line no-useless-call
|
|
27
|
+
const Transformer = require.call(null, transformerConfig.transformerPath);
|
|
28
|
+
|
|
29
|
+
const transformFileStartLogEntry = {
|
|
30
|
+
action_name: "Transforming file",
|
|
31
|
+
action_phase: "start",
|
|
32
|
+
file_name: filename,
|
|
33
|
+
log_entry_label: "Transforming file",
|
|
34
|
+
start_timestamp: process.hrtime(),
|
|
35
|
+
};
|
|
36
|
+
const data = fs.readFileSync(path.resolve(projectRoot, filename));
|
|
37
|
+
const sha1 = crypto.createHash("sha1").update(data).digest("hex");
|
|
38
|
+
const result = await Transformer.transform(
|
|
39
|
+
transformerConfig.transformerConfig,
|
|
40
|
+
projectRoot,
|
|
41
|
+
filename,
|
|
42
|
+
data,
|
|
43
|
+
transformOptions
|
|
44
|
+
); // The babel cache caches scopes and pathes for already traversed AST nodes.
|
|
45
|
+
// Clearing the cache here since the nodes of the transformed file are no longer referenced.
|
|
46
|
+
// This isn't stritcly necessary since the cache uses a WeakMap. However, WeakMap only permit
|
|
47
|
+
// that unreferenced keys are collected but the values still hold references to the Scope and NodePaths.
|
|
48
|
+
// Manually clearing the cache allows the GC to collect the Scope and NodePaths without checking if there
|
|
49
|
+
// exist any other references to the keys.
|
|
50
|
+
|
|
51
|
+
traverse.cache.clear();
|
|
52
|
+
const transformFileEndLogEntry = getEndLogEntry(
|
|
53
|
+
transformFileStartLogEntry,
|
|
54
|
+
filename
|
|
55
|
+
);
|
|
56
|
+
return {
|
|
57
|
+
result,
|
|
58
|
+
sha1,
|
|
59
|
+
transformFileStartLogEntry,
|
|
60
|
+
transformFileEndLogEntry,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getEndLogEntry(startLogEntry, filename) {
|
|
65
|
+
const timeDelta = process.hrtime(startLogEntry.start_timestamp);
|
|
66
|
+
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
|
|
67
|
+
return {
|
|
68
|
+
action_name: "Transforming file",
|
|
69
|
+
action_phase: "end",
|
|
70
|
+
file_name: filename,
|
|
71
|
+
duration_ms,
|
|
72
|
+
log_entry_label: "Transforming file",
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
transform,
|
|
78
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
import type {TransformResult} from './types.flow';
|
|
14
|
+
import type {LogEntry} from 'metro-core/src/Logger';
|
|
15
|
+
import type {
|
|
16
|
+
JsTransformerConfig,
|
|
17
|
+
JsTransformOptions,
|
|
18
|
+
} from 'metro-transform-worker';
|
|
19
|
+
|
|
20
|
+
const traverse = require('@babel/traverse').default;
|
|
21
|
+
const crypto = require('crypto');
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const path = require('path');
|
|
24
|
+
|
|
25
|
+
export type {JsTransformOptions as TransformOptions} from 'metro-transform-worker';
|
|
26
|
+
|
|
27
|
+
export type Worker = {
|
|
28
|
+
+transform: typeof transform,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type TransformerInterface = {
|
|
32
|
+
transform(
|
|
33
|
+
JsTransformerConfig,
|
|
34
|
+
string,
|
|
35
|
+
string,
|
|
36
|
+
Buffer,
|
|
37
|
+
JsTransformOptions,
|
|
38
|
+
): Promise<TransformResult<>>,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type TransformerConfig = {
|
|
42
|
+
transformerPath: string,
|
|
43
|
+
transformerConfig: JsTransformerConfig,
|
|
44
|
+
...
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type Data = $ReadOnly<{
|
|
48
|
+
result: TransformResult<>,
|
|
49
|
+
sha1: string,
|
|
50
|
+
transformFileStartLogEntry: LogEntry,
|
|
51
|
+
transformFileEndLogEntry: LogEntry,
|
|
52
|
+
}>;
|
|
53
|
+
|
|
54
|
+
async function transform(
|
|
55
|
+
filename: string,
|
|
56
|
+
transformOptions: JsTransformOptions,
|
|
57
|
+
projectRoot: string,
|
|
58
|
+
transformerConfig: TransformerConfig,
|
|
59
|
+
): Promise<Data> {
|
|
60
|
+
// eslint-disable-next-line no-useless-call
|
|
61
|
+
const Transformer = (require.call(
|
|
62
|
+
null,
|
|
63
|
+
transformerConfig.transformerPath,
|
|
64
|
+
): TransformerInterface);
|
|
65
|
+
|
|
66
|
+
const transformFileStartLogEntry = {
|
|
67
|
+
action_name: 'Transforming file',
|
|
68
|
+
action_phase: 'start',
|
|
69
|
+
file_name: filename,
|
|
70
|
+
log_entry_label: 'Transforming file',
|
|
71
|
+
start_timestamp: process.hrtime(),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const data = fs.readFileSync(path.resolve(projectRoot, filename));
|
|
75
|
+
const sha1 = crypto.createHash('sha1').update(data).digest('hex');
|
|
76
|
+
|
|
77
|
+
const result = await Transformer.transform(
|
|
78
|
+
transformerConfig.transformerConfig,
|
|
79
|
+
projectRoot,
|
|
80
|
+
filename,
|
|
81
|
+
data,
|
|
82
|
+
transformOptions,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// The babel cache caches scopes and pathes for already traversed AST nodes.
|
|
86
|
+
// Clearing the cache here since the nodes of the transformed file are no longer referenced.
|
|
87
|
+
// This isn't stritcly necessary since the cache uses a WeakMap. However, WeakMap only permit
|
|
88
|
+
// that unreferenced keys are collected but the values still hold references to the Scope and NodePaths.
|
|
89
|
+
// Manually clearing the cache allows the GC to collect the Scope and NodePaths without checking if there
|
|
90
|
+
// exist any other references to the keys.
|
|
91
|
+
traverse.cache.clear();
|
|
92
|
+
|
|
93
|
+
const transformFileEndLogEntry = getEndLogEntry(
|
|
94
|
+
transformFileStartLogEntry,
|
|
95
|
+
filename,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
result,
|
|
100
|
+
sha1,
|
|
101
|
+
transformFileStartLogEntry,
|
|
102
|
+
transformFileEndLogEntry,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getEndLogEntry(startLogEntry: LogEntry, filename: string): LogEntry {
|
|
107
|
+
const timeDelta = process.hrtime(startLogEntry.start_timestamp);
|
|
108
|
+
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
action_name: 'Transforming file',
|
|
112
|
+
action_phase: 'end',
|
|
113
|
+
file_name: filename,
|
|
114
|
+
duration_ms,
|
|
115
|
+
log_entry_label: 'Transforming file',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = ({
|
|
120
|
+
transform,
|
|
121
|
+
}: Worker);
|
|
@@ -8,71 +8,13 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
|
+
/*::
|
|
12
|
+
export type * from './Worker.flow';
|
|
13
|
+
*/
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
try {
|
|
16
|
+
// $FlowFixMe[untyped-import]
|
|
17
|
+
require("metro-babel-register").unstable_registerForMetroMonorepo();
|
|
18
|
+
} catch {}
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const fs = require("fs");
|
|
17
|
-
|
|
18
|
-
const path = require("path");
|
|
19
|
-
|
|
20
|
-
async function transform(
|
|
21
|
-
filename,
|
|
22
|
-
transformOptions,
|
|
23
|
-
projectRoot,
|
|
24
|
-
transformerConfig
|
|
25
|
-
) {
|
|
26
|
-
// eslint-disable-next-line no-useless-call
|
|
27
|
-
const Transformer = require.call(null, transformerConfig.transformerPath);
|
|
28
|
-
|
|
29
|
-
const transformFileStartLogEntry = {
|
|
30
|
-
action_name: "Transforming file",
|
|
31
|
-
action_phase: "start",
|
|
32
|
-
file_name: filename,
|
|
33
|
-
log_entry_label: "Transforming file",
|
|
34
|
-
start_timestamp: process.hrtime(),
|
|
35
|
-
};
|
|
36
|
-
const data = fs.readFileSync(path.resolve(projectRoot, filename));
|
|
37
|
-
const sha1 = crypto.createHash("sha1").update(data).digest("hex");
|
|
38
|
-
const result = await Transformer.transform(
|
|
39
|
-
transformerConfig.transformerConfig,
|
|
40
|
-
projectRoot,
|
|
41
|
-
filename,
|
|
42
|
-
data,
|
|
43
|
-
transformOptions
|
|
44
|
-
); // The babel cache caches scopes and pathes for already traversed AST nodes.
|
|
45
|
-
// Clearing the cache here since the nodes of the transformed file are no longer referenced.
|
|
46
|
-
// This isn't stritcly necessary since the cache uses a WeakMap. However, WeakMap only permit
|
|
47
|
-
// that unreferenced keys are collected but the values still hold references to the Scope and NodePaths.
|
|
48
|
-
// Manually clearing the cache allows the GC to collect the Scope and NodePaths without checking if there
|
|
49
|
-
// exist any other references to the keys.
|
|
50
|
-
|
|
51
|
-
traverse.cache.clear();
|
|
52
|
-
const transformFileEndLogEntry = getEndLogEntry(
|
|
53
|
-
transformFileStartLogEntry,
|
|
54
|
-
filename
|
|
55
|
-
);
|
|
56
|
-
return {
|
|
57
|
-
result,
|
|
58
|
-
sha1,
|
|
59
|
-
transformFileStartLogEntry,
|
|
60
|
-
transformFileEndLogEntry,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getEndLogEntry(startLogEntry, filename) {
|
|
65
|
-
const timeDelta = process.hrtime(startLogEntry.start_timestamp);
|
|
66
|
-
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
|
|
67
|
-
return {
|
|
68
|
-
action_name: "Transforming file",
|
|
69
|
-
action_phase: "end",
|
|
70
|
-
file_name: filename,
|
|
71
|
-
duration_ms,
|
|
72
|
-
log_entry_label: "Transforming file",
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
module.exports = {
|
|
77
|
-
transform,
|
|
78
|
-
};
|
|
20
|
+
module.exports = require("./Worker.flow");
|
|
@@ -10,112 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
JsTransformerConfig,
|
|
17
|
-
JsTransformOptions,
|
|
18
|
-
} from 'metro-transform-worker';
|
|
13
|
+
/*::
|
|
14
|
+
export type * from './Worker.flow';
|
|
15
|
+
*/
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
try {
|
|
18
|
+
// $FlowFixMe[untyped-import]
|
|
19
|
+
require('metro-babel-register').unstable_registerForMetroMonorepo();
|
|
20
|
+
} catch {}
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export type Worker = {
|
|
28
|
-
+transform: typeof transform,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
type TransformerInterface = {
|
|
32
|
-
transform(
|
|
33
|
-
JsTransformerConfig,
|
|
34
|
-
string,
|
|
35
|
-
string,
|
|
36
|
-
Buffer,
|
|
37
|
-
JsTransformOptions,
|
|
38
|
-
): Promise<TransformResult<>>,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type TransformerConfig = {
|
|
42
|
-
transformerPath: string,
|
|
43
|
-
transformerConfig: JsTransformerConfig,
|
|
44
|
-
...
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type Data = $ReadOnly<{
|
|
48
|
-
result: TransformResult<>,
|
|
49
|
-
sha1: string,
|
|
50
|
-
transformFileStartLogEntry: LogEntry,
|
|
51
|
-
transformFileEndLogEntry: LogEntry,
|
|
52
|
-
}>;
|
|
53
|
-
|
|
54
|
-
async function transform(
|
|
55
|
-
filename: string,
|
|
56
|
-
transformOptions: JsTransformOptions,
|
|
57
|
-
projectRoot: string,
|
|
58
|
-
transformerConfig: TransformerConfig,
|
|
59
|
-
): Promise<Data> {
|
|
60
|
-
// eslint-disable-next-line no-useless-call
|
|
61
|
-
const Transformer = (require.call(
|
|
62
|
-
null,
|
|
63
|
-
transformerConfig.transformerPath,
|
|
64
|
-
): TransformerInterface);
|
|
65
|
-
|
|
66
|
-
const transformFileStartLogEntry = {
|
|
67
|
-
action_name: 'Transforming file',
|
|
68
|
-
action_phase: 'start',
|
|
69
|
-
file_name: filename,
|
|
70
|
-
log_entry_label: 'Transforming file',
|
|
71
|
-
start_timestamp: process.hrtime(),
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const data = fs.readFileSync(path.resolve(projectRoot, filename));
|
|
75
|
-
const sha1 = crypto.createHash('sha1').update(data).digest('hex');
|
|
76
|
-
|
|
77
|
-
const result = await Transformer.transform(
|
|
78
|
-
transformerConfig.transformerConfig,
|
|
79
|
-
projectRoot,
|
|
80
|
-
filename,
|
|
81
|
-
data,
|
|
82
|
-
transformOptions,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
// The babel cache caches scopes and pathes for already traversed AST nodes.
|
|
86
|
-
// Clearing the cache here since the nodes of the transformed file are no longer referenced.
|
|
87
|
-
// This isn't stritcly necessary since the cache uses a WeakMap. However, WeakMap only permit
|
|
88
|
-
// that unreferenced keys are collected but the values still hold references to the Scope and NodePaths.
|
|
89
|
-
// Manually clearing the cache allows the GC to collect the Scope and NodePaths without checking if there
|
|
90
|
-
// exist any other references to the keys.
|
|
91
|
-
traverse.cache.clear();
|
|
92
|
-
|
|
93
|
-
const transformFileEndLogEntry = getEndLogEntry(
|
|
94
|
-
transformFileStartLogEntry,
|
|
95
|
-
filename,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
result,
|
|
100
|
-
sha1,
|
|
101
|
-
transformFileStartLogEntry,
|
|
102
|
-
transformFileEndLogEntry,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function getEndLogEntry(startLogEntry: LogEntry, filename: string): LogEntry {
|
|
107
|
-
const timeDelta = process.hrtime(startLogEntry.start_timestamp);
|
|
108
|
-
const duration_ms = Math.round((timeDelta[0] * 1e9 + timeDelta[1]) / 1e6);
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
action_name: 'Transforming file',
|
|
112
|
-
action_phase: 'end',
|
|
113
|
-
file_name: filename,
|
|
114
|
-
duration_ms,
|
|
115
|
-
log_entry_label: 'Transforming file',
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
module.exports = ({
|
|
120
|
-
transform,
|
|
121
|
-
}: Worker);
|
|
22
|
+
module.exports = require('./Worker.flow');
|
|
@@ -136,7 +136,7 @@ class WorkerFarm {
|
|
|
136
136
|
return null;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
_formatGenericError(err, filename: string): TransformError {
|
|
139
|
+
_formatGenericError(err: any, filename: string): TransformError {
|
|
140
140
|
const error = new TransformError(`${filename}: ${err.message}`);
|
|
141
141
|
|
|
142
142
|
return Object.assign(error, {
|
|
@@ -145,7 +145,7 @@ class WorkerFarm {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
_formatBabelError(err, filename: string): TransformError {
|
|
148
|
+
_formatBabelError(err: any, filename: string): TransformError {
|
|
149
149
|
const error = new TransformError(
|
|
150
150
|
`${err.type || 'Error'}${
|
|
151
151
|
err.message.includes(filename) ? '' : ' in ' + filename
|