metro 0.71.0 → 0.71.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.71.0",
3
+ "version": "0.71.1",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
@@ -36,22 +36,22 @@
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.0",
40
- "metro-cache": "0.71.0",
41
- "metro-cache-key": "0.71.0",
42
- "metro-config": "0.71.0",
43
- "metro-core": "0.71.0",
44
- "metro-file-map": "0.71.0",
45
- "metro-hermes-compiler": "0.71.0",
46
- "metro-inspector-proxy": "0.71.0",
47
- "metro-minify-uglify": "0.71.0",
48
- "metro-react-native-babel-preset": "0.71.0",
49
- "metro-resolver": "0.71.0",
50
- "metro-runtime": "0.71.0",
51
- "metro-source-map": "0.71.0",
52
- "metro-symbolicate": "0.71.0",
53
- "metro-transform-plugins": "0.71.0",
54
- "metro-transform-worker": "0.71.0",
39
+ "metro-babel-transformer": "0.71.1",
40
+ "metro-cache": "0.71.1",
41
+ "metro-cache-key": "0.71.1",
42
+ "metro-config": "0.71.1",
43
+ "metro-core": "0.71.1",
44
+ "metro-file-map": "0.71.1",
45
+ "metro-hermes-compiler": "0.71.1",
46
+ "metro-inspector-proxy": "0.71.1",
47
+ "metro-minify-uglify": "0.71.1",
48
+ "metro-react-native-babel-preset": "0.71.1",
49
+ "metro-resolver": "0.71.1",
50
+ "metro-runtime": "0.71.1",
51
+ "metro-source-map": "0.71.1",
52
+ "metro-symbolicate": "0.71.1",
53
+ "metro-transform-plugins": "0.71.1",
54
+ "metro-transform-worker": "0.71.1",
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": "^5.1.2",
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-memory-fs": "0.71.0",
74
- "metro-react-native-babel-preset": "0.71.0",
75
- "metro-react-native-babel-transformer": "0.71.0",
73
+ "metro-babel-register": "0.71.1",
74
+ "metro-memory-fs": "0.71.1",
75
+ "metro-react-native-babel-preset": "0.71.1",
76
+ "metro-react-native-babel-transformer": "0.71.1",
76
77
  "stack-trace": "^0.0.10"
77
78
  },
78
79
  "license": "MIT"
@@ -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
- const traverse = require("@babel/traverse").default;
15
+ try {
16
+ // $FlowFixMe[untyped-import]
17
+ require("metro-babel-register").unstable_registerForMetroMonorepo();
18
+ } catch {}
13
19
 
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
- };
20
+ module.exports = require("./Worker.flow");
@@ -10,112 +10,13 @@
10
10
 
11
11
  'use strict';
12
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';
13
+ /*::
14
+ export type * from './Worker.flow';
15
+ */
19
16
 
20
- const traverse = require('@babel/traverse').default;
21
- const crypto = require('crypto');
22
- const fs = require('fs');
23
- const path = require('path');
17
+ try {
18
+ // $FlowFixMe[untyped-import]
19
+ require('metro-babel-register').unstable_registerForMetroMonorepo();
20
+ } catch {}
24
21
 
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);
22
+ module.exports = require('./Worker.flow');
@@ -26,4 +26,8 @@ module.exports = {
26
26
 
27
27
  return matches[1];
28
28
  },
29
+
30
+ getCacheKey() {
31
+ return "hasteImplFixture";
32
+ },
29
33
  };