metro 0.76.7 → 0.77.0

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.76.7",
3
+ "version": "0.77.0",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
@@ -29,28 +29,26 @@
29
29
  "denodeify": "^1.2.1",
30
30
  "error-stack-parser": "^2.0.6",
31
31
  "graceful-fs": "^4.2.4",
32
- "hermes-parser": "0.12.0",
32
+ "hermes-parser": "0.14.0",
33
33
  "image-size": "^1.0.2",
34
34
  "invariant": "^2.2.4",
35
35
  "jest-worker": "^27.2.0",
36
36
  "jsc-safe-url": "^0.2.2",
37
37
  "lodash.throttle": "^4.1.1",
38
- "metro-babel-transformer": "0.76.7",
39
- "metro-cache": "0.76.7",
40
- "metro-cache-key": "0.76.7",
41
- "metro-config": "0.76.7",
42
- "metro-core": "0.76.7",
43
- "metro-file-map": "0.76.7",
44
- "metro-inspector-proxy": "0.76.7",
45
- "metro-minify-terser": "0.76.7",
46
- "metro-minify-uglify": "0.76.7",
47
- "metro-react-native-babel-preset": "0.76.7",
48
- "metro-resolver": "0.76.7",
49
- "metro-runtime": "0.76.7",
50
- "metro-source-map": "0.76.7",
51
- "metro-symbolicate": "0.76.7",
52
- "metro-transform-plugins": "0.76.7",
53
- "metro-transform-worker": "0.76.7",
38
+ "metro-babel-transformer": "0.77.0",
39
+ "metro-cache": "0.77.0",
40
+ "metro-cache-key": "0.77.0",
41
+ "metro-config": "0.77.0",
42
+ "metro-core": "0.77.0",
43
+ "metro-file-map": "0.77.0",
44
+ "metro-inspector-proxy": "0.77.0",
45
+ "metro-minify-terser": "0.77.0",
46
+ "metro-resolver": "0.77.0",
47
+ "metro-runtime": "0.77.0",
48
+ "metro-source-map": "0.77.0",
49
+ "metro-symbolicate": "0.77.0",
50
+ "metro-transform-plugins": "0.77.0",
51
+ "metro-transform-worker": "0.77.0",
54
52
  "mime-types": "^2.1.27",
55
53
  "node-fetch": "^2.2.0",
56
54
  "nullthrows": "^1.1.1",
@@ -68,16 +66,16 @@
68
66
  "dedent": "^0.7.0",
69
67
  "jest-snapshot": "^26.5.2",
70
68
  "jest-snapshot-serializer-raw": "^1.2.0",
71
- "metro-babel-register": "0.76.7",
72
- "metro-memory-fs": "0.76.7",
73
- "metro-react-native-babel-preset": "0.76.7",
74
- "metro-react-native-babel-transformer": "0.76.7",
69
+ "metro-babel-register": "0.77.0",
70
+ "metro-memory-fs": "0.77.0",
71
+ "metro-react-native-babel-preset": "0.77.0",
72
+ "metro-react-native-babel-transformer": "0.77.0",
75
73
  "mock-req": "^0.2.0",
76
74
  "mock-res": "^0.6.0",
77
75
  "stack-trace": "^0.0.10"
78
76
  },
79
77
  "license": "MIT",
80
78
  "engines": {
81
- "node": ">=16"
79
+ "node": ">=18"
82
80
  }
83
81
  }
@@ -26,8 +26,6 @@ const {
26
26
  fromRawMappingsNonBlocking,
27
27
  } = require('metro-source-map');
28
28
 
29
- type ReturnType<F> = $Call<<A, R>((...A) => R) => R, F>;
30
-
31
29
  function getSourceMapInfosImpl(
32
30
  isBlocking: boolean,
33
31
  onDone: ($ReadOnlyArray<ReturnType<typeof getSourceMapInfo>>) => void,
@@ -17,9 +17,10 @@ class WorkerFarm {
17
17
  constructor(config, transformerConfig) {
18
18
  this._config = config;
19
19
  this._transformerConfig = transformerConfig;
20
+ const absoluteWorkerPath = require.resolve(config.transformer.workerPath);
20
21
  if (this._config.maxWorkers > 1) {
21
22
  const worker = this._makeFarm(
22
- this._config.transformer.workerPath,
23
+ absoluteWorkerPath,
23
24
  ["transform"],
24
25
  this._config.maxWorkers
25
26
  );
@@ -69,13 +70,13 @@ class WorkerFarm {
69
70
  }
70
71
  }
71
72
  }
72
- _makeFarm(workerPath, exposedMethods, numWorkers) {
73
+ _makeFarm(absoluteWorkerPath, exposedMethods, numWorkers) {
73
74
  const env = {
74
75
  ...process.env,
75
76
  // Force color to print syntax highlighted code frames.
76
77
  FORCE_COLOR: 1,
77
78
  };
78
- return new JestWorker(workerPath, {
79
+ return new JestWorker(absoluteWorkerPath, {
79
80
  computeWorkerKey: this._config.stickyWorkers
80
81
  ? // $FlowFixMe[method-unbinding] added when improving typing for this parameters
81
82
  // $FlowFixMe[incompatible-call]
@@ -39,10 +39,11 @@ class WorkerFarm {
39
39
  constructor(config: ConfigT, transformerConfig: TransformerConfig) {
40
40
  this._config = config;
41
41
  this._transformerConfig = transformerConfig;
42
+ const absoluteWorkerPath = require.resolve(config.transformer.workerPath);
42
43
 
43
44
  if (this._config.maxWorkers > 1) {
44
45
  const worker = this._makeFarm(
45
- this._config.transformer.workerPath,
46
+ absoluteWorkerPath,
46
47
  ['transform'],
47
48
  this._config.maxWorkers,
48
49
  );
@@ -107,7 +108,7 @@ class WorkerFarm {
107
108
  }
108
109
 
109
110
  _makeFarm(
110
- workerPath: string,
111
+ absoluteWorkerPath: string,
111
112
  exposedMethods: $ReadOnlyArray<string>,
112
113
  numWorkers: number,
113
114
  ): any {
@@ -117,7 +118,7 @@ class WorkerFarm {
117
118
  FORCE_COLOR: 1,
118
119
  };
119
120
 
120
- return new JestWorker(workerPath, {
121
+ return new JestWorker(absoluteWorkerPath, {
121
122
  computeWorkerKey: this._config.stickyWorkers
122
123
  ? // $FlowFixMe[method-unbinding] added when improving typing for this parameters
123
124
  // $FlowFixMe[incompatible-call]
@@ -51,7 +51,7 @@ function deriveAbsolutePathFromContext(from, context) {
51
51
  /** Match a file against a require context. */
52
52
  function fileMatchesContext(testPath, context) {
53
53
  // NOTE(EvanBacon): Ensure this logic is synchronized with the similar
54
- // functionality in `metro-file-map/src/HasteFS.js` (`matchFilesWithContext()`)
54
+ // functionality in `metro-file-map/src/lib/TreeFS.js` (`matchFiles()`)
55
55
 
56
56
  const filePath = _path.default.relative(
57
57
  (0, _nullthrows.default)(context.from),
@@ -63,7 +63,7 @@ export function fileMatchesContext(
63
63
  context: RequireContext,
64
64
  ): boolean {
65
65
  // NOTE(EvanBacon): Ensure this logic is synchronized with the similar
66
- // functionality in `metro-file-map/src/HasteFS.js` (`matchFilesWithContext()`)
66
+ // functionality in `metro-file-map/src/lib/TreeFS.js` (`matchFiles()`)
67
67
 
68
68
  const filePath = path.relative(nullthrows(context.from), testPath);
69
69
  const filter = context.filter;
@@ -127,12 +127,13 @@ async function getTransformFn(
127
127
  // TODO: Check delta changes to avoid having to look over all files each time
128
128
  // this is a massive performance boost.
129
129
 
130
- // Search against all files, this is very expensive.
131
- // TODO: Maybe we could let the user specify which root to check against.
132
- const files = graph.matchFilesWithContext(requireContext.from, {
133
- filter: requireContext.filter,
134
- recursive: requireContext.recursive,
135
- });
130
+ // Search against all files in a subtree.
131
+ const files = Array.from(
132
+ graph.matchFilesWithContext(requireContext.from, {
133
+ filter: requireContext.filter,
134
+ recursive: requireContext.recursive,
135
+ })
136
+ );
136
137
  const template = (0, _contextModuleTemplates.getContextModuleTemplate)(
137
138
  requireContext.mode,
138
139
  requireContext.from,
@@ -152,12 +152,13 @@ async function getTransformFn(
152
152
  // TODO: Check delta changes to avoid having to look over all files each time
153
153
  // this is a massive performance boost.
154
154
 
155
- // Search against all files, this is very expensive.
156
- // TODO: Maybe we could let the user specify which root to check against.
157
- const files = graph.matchFilesWithContext(requireContext.from, {
158
- filter: requireContext.filter,
159
- recursive: requireContext.recursive,
160
- });
155
+ // Search against all files in a subtree.
156
+ const files = Array.from(
157
+ graph.matchFilesWithContext(requireContext.from, {
158
+ filter: requireContext.filter,
159
+ recursive: requireContext.recursive,
160
+ }),
161
+ );
161
162
 
162
163
  const template = getContextModuleTemplate(
163
164
  requireContext.mode,
@@ -53,7 +53,6 @@ function _interopRequireWildcard(obj, nodeInterop) {
53
53
  */
54
54
 
55
55
  const ci = require("ci-info");
56
- const path = require("path");
57
56
  function getIgnorePattern(config) {
58
57
  // For now we support both options
59
58
  const { blockList, blacklistRE } = config.resolver;
@@ -66,8 +65,21 @@ function getIgnorePattern(config) {
66
65
  const combine = (regexes) =>
67
66
  new RegExp(
68
67
  regexes
69
- .map((regex) => "(" + regex.source.replaceAll("/", path.sep) + ")")
70
- .join("|")
68
+ .map((regex, index) => {
69
+ if (regex.flags !== regexes[0].flags) {
70
+ throw new Error(
71
+ "Cannot combine blockList patterns, because they have different flags:\n" +
72
+ " - Pattern 0: " +
73
+ regexes[0].toString() +
74
+ "\n" +
75
+ ` - Pattern ${index}: ` +
76
+ regexes[index].toString()
77
+ );
78
+ }
79
+ return "(" + regex.source + ")";
80
+ })
81
+ .join("|"),
82
+ regexes[0]?.flags ?? ""
71
83
  );
72
84
 
73
85
  // If ignorePattern is an array, merge it into one
@@ -76,7 +88,7 @@ function getIgnorePattern(config) {
76
88
  }
77
89
  return ignorePattern;
78
90
  }
79
- function createHasteMap(config, options) {
91
+ function createFileMap(config, options) {
80
92
  const dependencyExtractor =
81
93
  options?.extractDependencies === false
82
94
  ? null
@@ -110,7 +122,10 @@ function createHasteMap(config, options) {
110
122
  ignorePattern: getIgnorePattern(config),
111
123
  maxWorkers: config.maxWorkers,
112
124
  mocksPattern: "",
113
- platforms: config.resolver.platforms,
125
+ platforms: [
126
+ ...config.resolver.platforms,
127
+ _metroFileMap.default.H.NATIVE_PLATFORM,
128
+ ],
114
129
  retainAllFiles: true,
115
130
  resetCache: config.resetCache,
116
131
  rootDir: config.projectRoot,
@@ -121,4 +136,4 @@ function createHasteMap(config, options) {
121
136
  watchmanDeferStates: config.watcher.watchman.deferStates,
122
137
  });
123
138
  }
124
- module.exports = createHasteMap;
139
+ module.exports = createFileMap;
@@ -14,7 +14,6 @@ import type {ConfigT} from 'metro-config/src/configTypes.flow';
14
14
  import MetroFileMap, {DiskCacheManager} from 'metro-file-map';
15
15
 
16
16
  const ci = require('ci-info');
17
- const path = require('path');
18
17
 
19
18
  function getIgnorePattern(config: ConfigT): RegExp {
20
19
  // For now we support both options
@@ -29,8 +28,21 @@ function getIgnorePattern(config: ConfigT): RegExp {
29
28
  const combine = (regexes: Array<RegExp>) =>
30
29
  new RegExp(
31
30
  regexes
32
- .map(regex => '(' + regex.source.replaceAll('/', path.sep) + ')')
31
+ .map((regex, index) => {
32
+ if (regex.flags !== regexes[0].flags) {
33
+ throw new Error(
34
+ 'Cannot combine blockList patterns, because they have different flags:\n' +
35
+ ' - Pattern 0: ' +
36
+ regexes[0].toString() +
37
+ '\n' +
38
+ ` - Pattern ${index}: ` +
39
+ regexes[index].toString(),
40
+ );
41
+ }
42
+ return '(' + regex.source + ')';
43
+ })
33
44
  .join('|'),
45
+ regexes[0]?.flags ?? '',
34
46
  );
35
47
 
36
48
  // If ignorePattern is an array, merge it into one
@@ -41,7 +53,7 @@ function getIgnorePattern(config: ConfigT): RegExp {
41
53
  return ignorePattern;
42
54
  }
43
55
 
44
- function createHasteMap(
56
+ function createFileMap(
45
57
  config: ConfigT,
46
58
  options?: $ReadOnly<{
47
59
  extractDependencies?: boolean,
@@ -84,7 +96,7 @@ function createHasteMap(
84
96
  ignorePattern: getIgnorePattern(config),
85
97
  maxWorkers: config.maxWorkers,
86
98
  mocksPattern: '',
87
- platforms: config.resolver.platforms,
99
+ platforms: [...config.resolver.platforms, MetroFileMap.H.NATIVE_PLATFORM],
88
100
  retainAllFiles: true,
89
101
  resetCache: config.resetCache,
90
102
  rootDir: config.projectRoot,
@@ -96,4 +108,4 @@ function createHasteMap(
96
108
  });
97
109
  }
98
110
 
99
- module.exports = createHasteMap;
111
+ module.exports = createFileMap;
@@ -13,7 +13,7 @@ var _metroFileMap = require("metro-file-map");
13
13
  */
14
14
 
15
15
  const canonicalize = require("metro-core/src/canonicalize");
16
- const createHasteMap = require("./DependencyGraph/createHasteMap");
16
+ const createFileMap = require("./DependencyGraph/createFileMap");
17
17
  const { ModuleResolver } = require("./DependencyGraph/ModuleResolution");
18
18
  const ModuleCache = require("./ModuleCache");
19
19
  const { EventEmitter } = require("events");
@@ -47,34 +47,32 @@ class DependencyGraph extends EventEmitter {
47
47
  type: "dep_graph_loading",
48
48
  hasReducedPerformance: !!hasReducedPerformance,
49
49
  });
50
- const haste = createHasteMap(config, {
50
+ const fileMap = createFileMap(config, {
51
51
  watch,
52
52
  });
53
53
 
54
54
  // We can have a lot of graphs listening to Haste for changes.
55
55
  // Bump this up to silence the max listeners EventEmitter warning.
56
- haste.setMaxListeners(1000);
57
- this._haste = haste;
56
+ fileMap.setMaxListeners(1000);
57
+ this._haste = fileMap;
58
58
  this._haste.on("status", (status) => this._onWatcherStatus(status));
59
- this._readyPromise = haste
60
- .build()
61
- .then(({ fileSystem, hasteModuleMap }) => {
62
- log(createActionEndEntry(initializingMetroLogEntry));
63
- config.reporter.update({
64
- type: "dep_graph_loaded",
65
- });
66
- this._fileSystem = fileSystem;
67
- this._hasteModuleMap = hasteModuleMap;
68
- this._haste.on("change", (changeEvent) =>
69
- this._onHasteChange(changeEvent)
70
- );
71
- this._haste.on("healthCheck", (result) =>
72
- this._onWatcherHealthCheck(result)
73
- );
74
- this._resolutionCache = new Map();
75
- this._moduleCache = this._createModuleCache();
76
- this._createModuleResolver();
59
+ this._readyPromise = fileMap.build().then(({ fileSystem, hasteMap }) => {
60
+ log(createActionEndEntry(initializingMetroLogEntry));
61
+ config.reporter.update({
62
+ type: "dep_graph_loaded",
77
63
  });
64
+ this._fileSystem = fileSystem;
65
+ this._hasteMap = hasteMap;
66
+ this._haste.on("change", (changeEvent) =>
67
+ this._onHasteChange(changeEvent)
68
+ );
69
+ this._haste.on("healthCheck", (result) =>
70
+ this._onWatcherHealthCheck(result)
71
+ );
72
+ this._resolutionCache = new Map();
73
+ this._moduleCache = this._createModuleCache();
74
+ this._createModuleResolver();
75
+ });
78
76
  }
79
77
  _onWatcherHealthCheck(result) {
80
78
  this._config.reporter.update({
@@ -143,9 +141,9 @@ class DependencyGraph extends EventEmitter {
143
141
  emptyModulePath: this._config.resolver.emptyModulePath,
144
142
  extraNodeModules: this._config.resolver.extraNodeModules,
145
143
  getHasteModulePath: (name, platform) =>
146
- this._hasteModuleMap.getModule(name, platform, true),
144
+ this._hasteMap.getModule(name, platform, true),
147
145
  getHastePackagePath: (name, platform) =>
148
- this._hasteModuleMap.getPackage(name, platform, true),
146
+ this._hasteMap.getPackage(name, platform, true),
149
147
  mainFields: this._config.resolver.resolverMainFields,
150
148
  moduleCache: this._moduleCache,
151
149
  nodeModulesPaths: this._config.resolver.nodeModulesPaths,
@@ -231,7 +229,13 @@ class DependencyGraph extends EventEmitter {
231
229
 
232
230
  /** Given a search context, return a list of file paths matching the query. */
233
231
  matchFilesWithContext(from, context) {
234
- return this._fileSystem.matchFilesWithContext(from, context);
232
+ return this._fileSystem.matchFiles({
233
+ rootDir: from,
234
+ recursive: context.recursive,
235
+ filter: context.filter,
236
+ filterComparePosix: true,
237
+ follow: true,
238
+ });
235
239
  }
236
240
  resolveDependency(
237
241
  from,
@@ -14,7 +14,7 @@ import type {ConfigT} from 'metro-config/src/configTypes.flow';
14
14
  import type MetroFileMap, {
15
15
  ChangeEvent,
16
16
  FileSystem,
17
- IModuleMap,
17
+ HasteMap,
18
18
  HealthCheckResult,
19
19
  WatcherStatus,
20
20
  } from 'metro-file-map';
@@ -22,7 +22,7 @@ import type MetroFileMap, {
22
22
  import {DuplicateHasteCandidatesError} from 'metro-file-map';
23
23
 
24
24
  const canonicalize = require('metro-core/src/canonicalize');
25
- const createHasteMap = require('./DependencyGraph/createHasteMap');
25
+ const createFileMap = require('./DependencyGraph/createFileMap');
26
26
  const {ModuleResolver} = require('./DependencyGraph/ModuleResolution');
27
27
  const ModuleCache = require('./ModuleCache');
28
28
  const {EventEmitter} = require('events');
@@ -57,7 +57,7 @@ class DependencyGraph extends EventEmitter {
57
57
  _haste: MetroFileMap;
58
58
  _fileSystem: FileSystem;
59
59
  _moduleCache: ModuleCache;
60
- _hasteModuleMap: IModuleMap;
60
+ _hasteMap: HasteMap;
61
61
  _moduleResolver: ModuleResolver<Package>;
62
62
  _resolutionCache: Map<
63
63
  // Custom resolver options
@@ -98,21 +98,21 @@ class DependencyGraph extends EventEmitter {
98
98
  type: 'dep_graph_loading',
99
99
  hasReducedPerformance: !!hasReducedPerformance,
100
100
  });
101
- const haste = createHasteMap(config, {watch});
101
+ const fileMap = createFileMap(config, {watch});
102
102
 
103
103
  // We can have a lot of graphs listening to Haste for changes.
104
104
  // Bump this up to silence the max listeners EventEmitter warning.
105
- haste.setMaxListeners(1000);
105
+ fileMap.setMaxListeners(1000);
106
106
 
107
- this._haste = haste;
107
+ this._haste = fileMap;
108
108
  this._haste.on('status', status => this._onWatcherStatus(status));
109
109
 
110
- this._readyPromise = haste.build().then(({fileSystem, hasteModuleMap}) => {
110
+ this._readyPromise = fileMap.build().then(({fileSystem, hasteMap}) => {
111
111
  log(createActionEndEntry(initializingMetroLogEntry));
112
112
  config.reporter.update({type: 'dep_graph_loaded'});
113
113
 
114
114
  this._fileSystem = fileSystem;
115
- this._hasteModuleMap = hasteModuleMap;
115
+ this._hasteMap = hasteMap;
116
116
 
117
117
  this._haste.on('change', changeEvent => this._onHasteChange(changeEvent));
118
118
  this._haste.on('healthCheck', result =>
@@ -191,9 +191,9 @@ class DependencyGraph extends EventEmitter {
191
191
  emptyModulePath: this._config.resolver.emptyModulePath,
192
192
  extraNodeModules: this._config.resolver.extraNodeModules,
193
193
  getHasteModulePath: (name, platform) =>
194
- this._hasteModuleMap.getModule(name, platform, true),
194
+ this._hasteMap.getModule(name, platform, true),
195
195
  getHastePackagePath: (name, platform) =>
196
- this._hasteModuleMap.getPackage(name, platform, true),
196
+ this._hasteMap.getPackage(name, platform, true),
197
197
  mainFields: this._config.resolver.resolverMainFields,
198
198
  moduleCache: this._moduleCache,
199
199
  nodeModulesPaths: this._config.resolver.nodeModulesPaths,
@@ -298,8 +298,14 @@ class DependencyGraph extends EventEmitter {
298
298
  /* Filter relative paths against a pattern. */
299
299
  filter: RegExp,
300
300
  }>,
301
- ): string[] {
302
- return this._fileSystem.matchFilesWithContext(from, context);
301
+ ): Iterable<string> {
302
+ return this._fileSystem.matchFiles({
303
+ rootDir: from,
304
+ recursive: context.recursive,
305
+ filter: context.filter,
306
+ filterComparePosix: true,
307
+ follow: true,
308
+ });
303
309
  }
304
310
 
305
311
  resolveDependency(