@expo/metro-config 0.17.2 → 0.17.4

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.
Files changed (85) hide show
  1. package/build/ExpoMetroConfig.js +239 -366
  2. package/build/ExpoMetroConfig.js.map +1 -1
  3. package/build/babel-core.js +6 -23
  4. package/build/babel-core.js.map +1 -1
  5. package/build/babel-transformer.js +117 -162
  6. package/build/babel-transformer.js.map +1 -1
  7. package/build/customizeFrame.js +84 -78
  8. package/build/customizeFrame.js.map +1 -1
  9. package/build/env.js +23 -37
  10. package/build/env.js.map +1 -1
  11. package/build/file-store.js +13 -21
  12. package/build/file-store.js.map +1 -1
  13. package/build/getModulesPaths.js +31 -48
  14. package/build/getModulesPaths.js.map +1 -1
  15. package/build/getWatchFolders.js +70 -98
  16. package/build/getWatchFolders.js.map +1 -1
  17. package/build/loadBabelConfig.js +30 -49
  18. package/build/loadBabelConfig.js.map +1 -1
  19. package/build/rewriteRequestUrl.js +82 -142
  20. package/build/rewriteRequestUrl.js.map +1 -1
  21. package/build/serializer/debugId.js +23 -22
  22. package/build/serializer/debugId.js.map +1 -1
  23. package/build/serializer/environmentVariableSerializerPlugin.js +90 -101
  24. package/build/serializer/environmentVariableSerializerPlugin.js.map +1 -1
  25. package/build/serializer/exportHermes.js +96 -133
  26. package/build/serializer/exportHermes.js.map +1 -1
  27. package/build/serializer/exportPath.js +18 -35
  28. package/build/serializer/exportPath.js.map +1 -1
  29. package/build/serializer/fork/baseJSBundle.js +124 -147
  30. package/build/serializer/fork/baseJSBundle.js.map +1 -1
  31. package/build/serializer/fork/js.js +81 -116
  32. package/build/serializer/fork/js.js.map +1 -1
  33. package/build/serializer/fork/processModules.js +22 -36
  34. package/build/serializer/fork/processModules.js.map +1 -1
  35. package/build/serializer/getCssDeps.js +64 -95
  36. package/build/serializer/getCssDeps.js.map +1 -1
  37. package/build/serializer/jsOutput.js +6 -16
  38. package/build/serializer/jsOutput.js.map +1 -1
  39. package/build/serializer/serializeChunks.js +406 -483
  40. package/build/serializer/serializeChunks.js.map +1 -1
  41. package/build/serializer/serializerAssets.js +1 -0
  42. package/build/serializer/serializerAssets.js.map +1 -1
  43. package/build/serializer/withExpoSerializers.js +165 -236
  44. package/build/serializer/withExpoSerializers.js.map +1 -1
  45. package/build/transform-worker/asset-transformer.js +21 -44
  46. package/build/transform-worker/asset-transformer.js.map +1 -1
  47. package/build/transform-worker/css-modules.js +57 -84
  48. package/build/transform-worker/css-modules.js.map +1 -1
  49. package/build/transform-worker/css.js +21 -20
  50. package/build/transform-worker/css.js.map +1 -1
  51. package/build/transform-worker/getAssets.js +38 -75
  52. package/build/transform-worker/getAssets.js.map +1 -1
  53. package/build/transform-worker/metro-transform-worker.js +384 -489
  54. package/build/transform-worker/metro-transform-worker.js.map +1 -1
  55. package/build/transform-worker/postcss.js +176 -233
  56. package/build/transform-worker/postcss.js.map +1 -1
  57. package/build/transform-worker/sass.js +30 -38
  58. package/build/transform-worker/sass.js.map +1 -1
  59. package/build/transform-worker/transform-worker.js +156 -188
  60. package/build/transform-worker/transform-worker.js.map +1 -1
  61. package/build/transform-worker/utils/require.js +30 -28
  62. package/build/transform-worker/utils/require.js.map +1 -1
  63. package/build/transformSync.js +40 -28
  64. package/build/transformSync.js.map +1 -1
  65. package/build/transformer/createExoticTransformer.js +96 -129
  66. package/build/transformer/createExoticTransformer.js.map +1 -1
  67. package/build/transformer/createMatcher.js +37 -46
  68. package/build/transformer/createMatcher.js.map +1 -1
  69. package/build/transformer/createMultiRuleTransformer.js +170 -240
  70. package/build/transformer/createMultiRuleTransformer.js.map +1 -1
  71. package/build/transformer/generateFunctionMap.js +20 -23
  72. package/build/transformer/generateFunctionMap.js.map +1 -1
  73. package/build/transformer/getBabelConfig.js +94 -127
  74. package/build/transformer/getBabelConfig.js.map +1 -1
  75. package/build/transformer/getCacheKey.js +17 -31
  76. package/build/transformer/getCacheKey.js.map +1 -1
  77. package/build/transformer/index.js +11 -62
  78. package/build/transformer/index.js.map +1 -1
  79. package/build/transformer/metro-expo-exotic-babel-transformer.js +3 -12
  80. package/build/transformer/metro-expo-exotic-babel-transformer.js.map +1 -1
  81. package/build/traveling/metro-config.js +12 -19
  82. package/build/traveling/metro-config.js.map +1 -1
  83. package/build/utils/hash.js +8 -14
  84. package/build/utils/hash.js.map +1 -1
  85. package/package.json +6 -6
@@ -1,527 +1,450 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Chunk = void 0;
7
- exports.getSortedModules = getSortedModules;
8
- exports.graphToSerialAssetsAsync = graphToSerialAssetsAsync;
9
- function _assert() {
10
- const data = _interopRequireDefault(require("assert"));
11
- _assert = function () {
12
- return data;
13
- };
14
- return data;
15
- }
16
- function _sourceMapString() {
17
- const data = _interopRequireDefault(require("metro/src/DeltaBundler/Serializers/sourceMapString"));
18
- _sourceMapString = function () {
19
- return data;
20
- };
21
- return data;
22
- }
23
- function _bundleToString() {
24
- const data = _interopRequireDefault(require("metro/src/lib/bundleToString"));
25
- _bundleToString = function () {
26
- return data;
27
- };
28
- return data;
29
- }
30
- function _path() {
31
- const data = _interopRequireDefault(require("path"));
32
- _path = function () {
33
- return data;
34
- };
35
- return data;
36
- }
37
- function _debugId() {
38
- const data = require("./debugId");
39
- _debugId = function () {
40
- return data;
41
- };
42
- return data;
43
- }
44
- function _exportHermes() {
45
- const data = require("./exportHermes");
46
- _exportHermes = function () {
47
- return data;
48
- };
49
- return data;
50
- }
51
- function _exportPath() {
52
- const data = require("./exportPath");
53
- _exportPath = function () {
54
- return data;
55
- };
56
- return data;
57
- }
58
- function _baseJSBundle() {
59
- const data = require("./fork/baseJSBundle");
60
- _baseJSBundle = function () {
61
- return data;
62
- };
63
- return data;
64
- }
65
- function _getCssDeps() {
66
- const data = require("./getCssDeps");
67
- _getCssDeps = function () {
68
- return data;
69
- };
70
- return data;
71
- }
72
- function _getAssets() {
73
- const data = _interopRequireDefault(require("../transform-worker/getAssets"));
74
- _getAssets = function () {
75
- return data;
76
- };
77
- return data;
78
- }
79
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSortedModules = exports.Chunk = exports.graphToSerialAssetsAsync = void 0;
80
7
  /**
81
8
  * Copyright © 2023 650 Industries.
82
9
  *
83
10
  * This source code is licensed under the MIT license found in the
84
11
  * LICENSE file in the root directory of this source tree.
85
12
  */
86
-
13
+ const assert_1 = __importDefault(require("assert"));
14
+ const sourceMapString_1 = __importDefault(require("metro/src/DeltaBundler/Serializers/sourceMapString"));
15
+ const bundleToString_1 = __importDefault(require("metro/src/lib/bundleToString"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const debugId_1 = require("./debugId");
18
+ const exportHermes_1 = require("./exportHermes");
19
+ const exportPath_1 = require("./exportPath");
20
+ const baseJSBundle_1 = require("./fork/baseJSBundle");
21
+ const getCssDeps_1 = require("./getCssDeps");
22
+ const getAssets_1 = __importDefault(require("../transform-worker/getAssets"));
87
23
  // Convert file paths to regex matchers.
88
24
  function pathToRegex(path) {
89
- // Escape regex special characters, except for '*'
90
- let regexSafePath = path.replace(/[-[\]{}()+?.,\\^$|#\s]/g, '\\$&');
91
-
92
- // Replace '*' with '.*' to act as a wildcard in regex
93
- regexSafePath = regexSafePath.replace(/\*/g, '.*');
94
-
95
- // Create a RegExp object with the modified string
96
- return new RegExp('^' + regexSafePath + '$');
25
+ // Escape regex special characters, except for '*'
26
+ let regexSafePath = path.replace(/[-[\]{}()+?.,\\^$|#\s]/g, '\\$&');
27
+ // Replace '*' with '.*' to act as a wildcard in regex
28
+ regexSafePath = regexSafePath.replace(/\*/g, '.*');
29
+ // Create a RegExp object with the modified string
30
+ return new RegExp('^' + regexSafePath + '$');
97
31
  }
98
32
  async function graphToSerialAssetsAsync(config, serializeChunkOptions, ...props) {
99
- var _config$serializer, _baseUrl$replace, _config$transformer$a, _config$transformer, _getPlatformOption;
100
- const [entryFile, preModules, graph, options] = props;
101
- const cssDeps = (0, _getCssDeps().getCssSerialAssets)(graph.dependencies, {
102
- projectRoot: options.projectRoot,
103
- processModuleFilter: options.processModuleFilter
104
- });
105
-
106
- // Create chunks for splitting.
107
- const chunks = new Set();
108
- [{
109
- test: pathToRegex(entryFile)
110
- }].map(chunkSettings => gatherChunks(chunks, chunkSettings, preModules, graph, options, false));
111
-
112
- // Get the common modules and extract them into a separate chunk.
113
- const entryChunk = [...chunks.values()].find(chunk => !chunk.isAsync && chunk.hasAbsolutePath(entryFile));
114
- if (entryChunk) {
115
- for (const chunk of chunks.values()) {
116
- if (chunk !== entryChunk && chunk.isAsync) {
117
- for (const dep of chunk.deps.values()) {
118
- if (entryChunk.deps.has(dep)) {
119
- // Remove the dependency from the async chunk since it will be loaded in the main chunk.
120
- chunk.deps.delete(dep);
121
- }
33
+ const [entryFile, preModules, graph, options] = props;
34
+ const cssDeps = (0, getCssDeps_1.getCssSerialAssets)(graph.dependencies, {
35
+ projectRoot: options.projectRoot,
36
+ processModuleFilter: options.processModuleFilter,
37
+ });
38
+ // Create chunks for splitting.
39
+ const chunks = new Set();
40
+ [
41
+ {
42
+ test: pathToRegex(entryFile),
43
+ },
44
+ ].map((chunkSettings) => gatherChunks(chunks, chunkSettings, preModules, graph, options, false));
45
+ // Get the common modules and extract them into a separate chunk.
46
+ const entryChunk = [...chunks.values()].find((chunk) => !chunk.isAsync && chunk.hasAbsolutePath(entryFile));
47
+ if (entryChunk) {
48
+ for (const chunk of chunks.values()) {
49
+ if (chunk !== entryChunk && chunk.isAsync) {
50
+ for (const dep of chunk.deps.values()) {
51
+ if (entryChunk.deps.has(dep)) {
52
+ // Remove the dependency from the async chunk since it will be loaded in the main chunk.
53
+ chunk.deps.delete(dep);
54
+ }
55
+ }
56
+ }
122
57
  }
123
- }
124
- }
125
- const toCompare = [...chunks.values()];
126
- const commonDependencies = [];
127
- while (toCompare.length) {
128
- const chunk = toCompare.shift();
129
- for (const chunk2 of toCompare) {
130
- if (chunk !== chunk2 && chunk.isAsync && chunk2.isAsync) {
131
- const commonDeps = [...chunk.deps].filter(dep => chunk2.deps.has(dep));
132
- for (const dep of commonDeps) {
133
- chunk.deps.delete(dep);
134
- chunk2.deps.delete(dep);
135
- }
136
- commonDependencies.push(...commonDeps);
58
+ const toCompare = [...chunks.values()];
59
+ const commonDependencies = [];
60
+ while (toCompare.length) {
61
+ const chunk = toCompare.shift();
62
+ for (const chunk2 of toCompare) {
63
+ if (chunk !== chunk2 && chunk.isAsync && chunk2.isAsync) {
64
+ const commonDeps = [...chunk.deps].filter((dep) => chunk2.deps.has(dep));
65
+ for (const dep of commonDeps) {
66
+ chunk.deps.delete(dep);
67
+ chunk2.deps.delete(dep);
68
+ }
69
+ commonDependencies.push(...commonDeps);
70
+ }
71
+ }
137
72
  }
138
- }
139
- }
140
-
141
- // If common dependencies were found, extract them to the entry chunk.
142
- // TODO: Extract the metro-runtime to a common chunk apart from the entry chunk then load the common dependencies before the entry chunk.
143
- if (commonDependencies.length) {
144
- for (const dep of commonDependencies) {
145
- entryChunk.deps.add(dep);
146
- }
147
- // const commonDependenciesUnique = [...new Set(commonDependencies)];
148
- // const commonChunk = new Chunk(
149
- // chunkIdForModules(commonDependenciesUnique),
150
- // commonDependenciesUnique,
151
- // graph,
152
- // options,
153
- // false,
154
- // true
155
- // );
156
- // entryChunk.requiredChunks.add(commonChunk);
157
- // chunks.add(commonChunk);
158
- }
159
-
160
- // TODO: Optimize this pass more.
161
- // Remove all dependencies from async chunks that are already in the common chunk.
162
- for (const chunk of [...chunks.values()]) {
163
- if (chunk !== entryChunk) {
164
- for (const dep of chunk.deps) {
165
- if (entryChunk.deps.has(dep)) {
166
- chunk.deps.delete(dep);
167
- }
73
+ // If common dependencies were found, extract them to the entry chunk.
74
+ // TODO: Extract the metro-runtime to a common chunk apart from the entry chunk then load the common dependencies before the entry chunk.
75
+ if (commonDependencies.length) {
76
+ for (const dep of commonDependencies) {
77
+ entryChunk.deps.add(dep);
78
+ }
79
+ // const commonDependenciesUnique = [...new Set(commonDependencies)];
80
+ // const commonChunk = new Chunk(
81
+ // chunkIdForModules(commonDependenciesUnique),
82
+ // commonDependenciesUnique,
83
+ // graph,
84
+ // options,
85
+ // false,
86
+ // true
87
+ // );
88
+ // entryChunk.requiredChunks.add(commonChunk);
89
+ // chunks.add(commonChunk);
90
+ }
91
+ // TODO: Optimize this pass more.
92
+ // Remove all dependencies from async chunks that are already in the common chunk.
93
+ for (const chunk of [...chunks.values()]) {
94
+ if (chunk !== entryChunk) {
95
+ for (const dep of chunk.deps) {
96
+ if (entryChunk.deps.has(dep)) {
97
+ chunk.deps.delete(dep);
98
+ }
99
+ }
100
+ }
168
101
  }
169
- }
170
102
  }
171
- }
172
- const jsAssets = await serializeChunksAsync(chunks, (_config$serializer = config.serializer) !== null && _config$serializer !== void 0 ? _config$serializer : {}, serializeChunkOptions);
173
-
174
- // TODO: Can this be anything besides true?
175
- const isExporting = true;
176
- const baseUrl = (0, _baseJSBundle().getBaseUrlOption)(graph, {
177
- serializerOptions: serializeChunkOptions
178
- });
179
- const assetPublicUrl = ((_baseUrl$replace = baseUrl.replace(/\/+$/, '')) !== null && _baseUrl$replace !== void 0 ? _baseUrl$replace : '') + '/assets';
180
- const publicPath = isExporting ? graph.transformOptions.platform === 'web' ? `/assets?export_path=${assetPublicUrl}` : assetPublicUrl : '/assets/?unstable_path=.';
181
-
182
- // TODO: Convert to serial assets
183
- // TODO: Disable this call dynamically in development since assets are fetched differently.
184
- const metroAssets = await (0, _getAssets().default)(graph.dependencies, {
185
- processModuleFilter: options.processModuleFilter,
186
- assetPlugins: (_config$transformer$a = (_config$transformer = config.transformer) === null || _config$transformer === void 0 ? void 0 : _config$transformer.assetPlugins) !== null && _config$transformer$a !== void 0 ? _config$transformer$a : [],
187
- platform: (_getPlatformOption = (0, _baseJSBundle().getPlatformOption)(graph, options)) !== null && _getPlatformOption !== void 0 ? _getPlatformOption : 'web',
188
- projectRoot: options.projectRoot,
189
- // this._getServerRootDir(),
190
- publicPath
191
- });
192
- return {
193
- artifacts: [...jsAssets, ...cssDeps],
194
- assets: metroAssets
195
- };
103
+ const jsAssets = await serializeChunksAsync(chunks, config.serializer ?? {}, serializeChunkOptions);
104
+ // TODO: Can this be anything besides true?
105
+ const isExporting = true;
106
+ const baseUrl = (0, baseJSBundle_1.getBaseUrlOption)(graph, { serializerOptions: serializeChunkOptions });
107
+ const assetPublicUrl = (baseUrl.replace(/\/+$/, '') ?? '') + '/assets';
108
+ const publicPath = isExporting
109
+ ? graph.transformOptions.platform === 'web'
110
+ ? `/assets?export_path=${assetPublicUrl}`
111
+ : assetPublicUrl
112
+ : '/assets/?unstable_path=.';
113
+ // TODO: Convert to serial assets
114
+ // TODO: Disable this call dynamically in development since assets are fetched differently.
115
+ const metroAssets = (await (0, getAssets_1.default)(graph.dependencies, {
116
+ processModuleFilter: options.processModuleFilter,
117
+ assetPlugins: config.transformer?.assetPlugins ?? [],
118
+ platform: (0, baseJSBundle_1.getPlatformOption)(graph, options) ?? 'web',
119
+ projectRoot: options.projectRoot,
120
+ publicPath,
121
+ }));
122
+ return { artifacts: [...jsAssets, ...cssDeps], assets: metroAssets };
196
123
  }
124
+ exports.graphToSerialAssetsAsync = graphToSerialAssetsAsync;
197
125
  class Chunk {
198
- deps = new Set();
199
- preModules = new Set();
200
-
201
- // Chunks that are required to be loaded synchronously before this chunk.
202
- // These are included in the HTML as <script> tags.
203
- requiredChunks = new Set();
204
- constructor(name, entries, graph, options, isAsync = false, isVendor = false) {
205
- this.name = name;
206
- this.entries = entries;
207
- this.graph = graph;
208
- this.options = options;
209
- this.isAsync = isAsync;
210
- this.isVendor = isVendor;
211
- this.deps = new Set(entries);
212
- }
213
- getPlatform() {
214
- (0, _assert().default)(this.graph.transformOptions.platform, "platform is required to be in graph's transformOptions");
215
- return this.graph.transformOptions.platform;
216
- }
217
- getFilename(src) {
218
- return this.options.dev ? this.name : (0, _exportPath().getExportPathForDependencyWithOptions)(this.name, {
219
- platform: this.getPlatform(),
220
- src,
221
- serverRoot: this.options.serverRoot
222
- });
223
- }
224
- getStableChunkSource(serializerConfig) {
225
- return this.options.dev ? '' : this.serializeToCodeWithTemplates(serializerConfig, {
226
- // Disable source maps when creating a sha to reduce the number of possible changes that could
227
- // influence the cache hit.
228
- serializerOptions: {
229
- includeSourceMaps: false
230
- },
231
- sourceMapUrl: undefined,
232
- debugId: undefined
233
- });
234
- }
235
- getFilenameForConfig(serializerConfig) {
236
- return this.getFilename(this.getStableChunkSource(serializerConfig));
237
- }
238
- serializeToCodeWithTemplates(serializerConfig, options = {}) {
239
- var _serializerConfig$get, _serializerConfig$get2;
240
- const entryFile = this.name;
241
-
242
- // TODO: Disable all debugId steps when a dev server is enabled. This is an export-only feature.
243
-
244
- const preModules = [...this.preModules.values()];
245
- const dependencies = [...this.deps];
246
- const jsSplitBundle = (0, _baseJSBundle().baseJSBundleWithDependencies)(entryFile, preModules, dependencies, {
247
- ...this.options,
248
- runBeforeMainModule: (_serializerConfig$get = serializerConfig === null || serializerConfig === void 0 ? void 0 : (_serializerConfig$get2 = serializerConfig.getModulesRunBeforeMainModule) === null || _serializerConfig$get2 === void 0 ? void 0 : _serializerConfig$get2.call(serializerConfig, _path().default.relative(this.options.projectRoot, entryFile))) !== null && _serializerConfig$get !== void 0 ? _serializerConfig$get : [],
249
- runModule: !this.isVendor && !this.isAsync,
250
- modulesOnly: this.preModules.size === 0,
251
- platform: this.getPlatform(),
252
- baseUrl: (0, _baseJSBundle().getBaseUrlOption)(this.graph, this.options),
253
- splitChunks: (0, _baseJSBundle().getSplitChunksOption)(this.graph, this.options),
254
- skipWrapping: true,
255
- computedAsyncModulePaths: null,
256
- ...options
257
- });
258
- return (0, _bundleToString().default)(jsSplitBundle).code;
259
- }
260
- hasAbsolutePath(absolutePath) {
261
- return [...this.deps].some(module => module.path === absolutePath);
262
- }
263
- getComputedPathsForAsyncDependencies(serializerConfig, chunks) {
264
- const baseUrl = (0, _baseJSBundle().getBaseUrlOption)(this.graph, this.options);
265
- // Only calculate production paths when all chunks are being exported.
266
- if (this.options.includeAsyncPaths) {
267
- return null;
126
+ name;
127
+ entries;
128
+ graph;
129
+ options;
130
+ isAsync;
131
+ isVendor;
132
+ deps = new Set();
133
+ preModules = new Set();
134
+ // Chunks that are required to be loaded synchronously before this chunk.
135
+ // These are included in the HTML as <script> tags.
136
+ requiredChunks = new Set();
137
+ constructor(name, entries, graph, options, isAsync = false, isVendor = false) {
138
+ this.name = name;
139
+ this.entries = entries;
140
+ this.graph = graph;
141
+ this.options = options;
142
+ this.isAsync = isAsync;
143
+ this.isVendor = isVendor;
144
+ this.deps = new Set(entries);
268
145
  }
269
- const computedAsyncModulePaths = {};
270
- this.deps.forEach(module => {
271
- module.dependencies.forEach(dependency => {
272
- if (dependency.data.data.asyncType === 'async') {
273
- const chunkContainingModule = chunks.find(chunk => chunk.hasAbsolutePath(dependency.absolutePath));
274
- (0, _assert().default)(chunkContainingModule, 'Chunk containing module not found: ' + dependency.absolutePath);
275
- const moduleIdName = chunkContainingModule.getFilenameForConfig(serializerConfig);
276
- computedAsyncModulePaths[dependency.absolutePath] = (baseUrl !== null && baseUrl !== void 0 ? baseUrl : '/') + moduleIdName;
277
- }
278
- });
279
- });
280
- return computedAsyncModulePaths;
281
- }
282
- getAdjustedSourceMapUrl(serializerConfig) {
283
- var _this$options$seriali;
284
- // Metro really only accounts for development, so we'll use the defaults here.
285
- if (this.options.dev) {
286
- var _this$options$sourceM;
287
- return (_this$options$sourceM = this.options.sourceMapUrl) !== null && _this$options$sourceM !== void 0 ? _this$options$sourceM : null;
146
+ getPlatform() {
147
+ (0, assert_1.default)(this.graph.transformOptions.platform, "platform is required to be in graph's transformOptions");
148
+ return this.graph.transformOptions.platform;
288
149
  }
289
- if (((_this$options$seriali = this.options.serializerOptions) === null || _this$options$seriali === void 0 ? void 0 : _this$options$seriali.includeSourceMaps) !== true) {
290
- return null;
150
+ getFilename(src) {
151
+ return this.options.dev
152
+ ? this.name
153
+ : (0, exportPath_1.getExportPathForDependencyWithOptions)(this.name, {
154
+ platform: this.getPlatform(),
155
+ src,
156
+ serverRoot: this.options.serverRoot,
157
+ });
291
158
  }
292
- if (this.options.inlineSourceMap || !this.options.sourceMapUrl) {
293
- var _this$options$sourceM2;
294
- return (_this$options$sourceM2 = this.options.sourceMapUrl) !== null && _this$options$sourceM2 !== void 0 ? _this$options$sourceM2 : null;
159
+ getStableChunkSource(serializerConfig) {
160
+ return this.options.dev
161
+ ? ''
162
+ : this.serializeToCodeWithTemplates(serializerConfig, {
163
+ // Disable source maps when creating a sha to reduce the number of possible changes that could
164
+ // influence the cache hit.
165
+ serializerOptions: {
166
+ includeSourceMaps: false,
167
+ },
168
+ sourceMapUrl: undefined,
169
+ debugId: undefined,
170
+ });
295
171
  }
296
- const isAbsolute = this.getPlatform() !== 'web';
297
- const baseUrl = (0, _baseJSBundle().getBaseUrlOption)(this.graph, this.options);
298
- const filename = this.getFilenameForConfig(serializerConfig);
299
- const isAbsoluteBaseUrl = !!(baseUrl !== null && baseUrl !== void 0 && baseUrl.match(/https?:\/\//));
300
- const pathname = (isAbsoluteBaseUrl ? '' : baseUrl.replace(/\/+$/, '')) + '/' + filename.replace(/^\/+$/, '') + '.map';
301
- let adjustedSourceMapUrl = this.options.sourceMapUrl;
302
- // Metro has lots of issues...
303
- if (this.options.sourceMapUrl.startsWith('//localhost')) {
304
- adjustedSourceMapUrl = 'http:' + this.options.sourceMapUrl;
172
+ getFilenameForConfig(serializerConfig) {
173
+ return this.getFilename(this.getStableChunkSource(serializerConfig));
305
174
  }
306
- try {
307
- const parsed = new URL(pathname, isAbsoluteBaseUrl ? baseUrl : adjustedSourceMapUrl);
308
- if (isAbsoluteBaseUrl || isAbsolute) {
309
- return parsed.href;
310
- }
311
- return parsed.pathname;
312
- } catch (error) {
313
- console.error(`Failed to link source maps because the source map URL "${this.options.sourceMapUrl}" is corrupt:`, error);
314
- return null;
175
+ serializeToCodeWithTemplates(serializerConfig, options = {}) {
176
+ const entryFile = this.name;
177
+ // TODO: Disable all debugId steps when a dev server is enabled. This is an export-only feature.
178
+ const preModules = [...this.preModules.values()];
179
+ const dependencies = [...this.deps];
180
+ const jsSplitBundle = (0, baseJSBundle_1.baseJSBundleWithDependencies)(entryFile, preModules, dependencies, {
181
+ ...this.options,
182
+ runBeforeMainModule: serializerConfig?.getModulesRunBeforeMainModule?.(path_1.default.relative(this.options.projectRoot, entryFile)) ?? [],
183
+ runModule: !this.isVendor && !this.isAsync,
184
+ modulesOnly: this.preModules.size === 0,
185
+ platform: this.getPlatform(),
186
+ baseUrl: (0, baseJSBundle_1.getBaseUrlOption)(this.graph, this.options),
187
+ splitChunks: (0, baseJSBundle_1.getSplitChunksOption)(this.graph, this.options),
188
+ skipWrapping: true,
189
+ computedAsyncModulePaths: null,
190
+ ...options,
191
+ });
192
+ return (0, bundleToString_1.default)(jsSplitBundle).code;
315
193
  }
316
- }
317
- serializeToCode(serializerConfig, {
318
- debugId,
319
- chunks
320
- }) {
321
- var _this$getAdjustedSour;
322
- return this.serializeToCodeWithTemplates(serializerConfig, {
323
- skipWrapping: false,
324
- sourceMapUrl: (_this$getAdjustedSour = this.getAdjustedSourceMapUrl(serializerConfig)) !== null && _this$getAdjustedSour !== void 0 ? _this$getAdjustedSour : undefined,
325
- computedAsyncModulePaths: this.getComputedPathsForAsyncDependencies(serializerConfig, chunks),
326
- debugId
327
- });
328
- }
329
- async serializeToAssetsAsync(serializerConfig, chunks, {
330
- includeSourceMaps,
331
- includeBytecode,
332
- unstable_beforeAssetSerializationPlugins
333
- }) {
334
- // Create hash without wrapping to prevent it changing when the wrapping changes.
335
- const outputFile = this.getFilenameForConfig(serializerConfig);
336
- // We already use a stable hash for the output filename, so we'll reuse that for the debugId.
337
- const debugId = (0, _debugId().stringToUUID)(_path().default.basename(outputFile, _path().default.extname(outputFile)));
338
- let premodules = [...this.preModules];
339
- if (unstable_beforeAssetSerializationPlugins) {
340
- for (const plugin of unstable_beforeAssetSerializationPlugins) {
341
- premodules = plugin({
342
- graph: this.graph,
343
- premodules,
344
- debugId
194
+ hasAbsolutePath(absolutePath) {
195
+ return [...this.deps].some((module) => module.path === absolutePath);
196
+ }
197
+ getComputedPathsForAsyncDependencies(serializerConfig, chunks) {
198
+ const baseUrl = (0, baseJSBundle_1.getBaseUrlOption)(this.graph, this.options);
199
+ // Only calculate production paths when all chunks are being exported.
200
+ if (this.options.includeAsyncPaths) {
201
+ return null;
202
+ }
203
+ const computedAsyncModulePaths = {};
204
+ this.deps.forEach((module) => {
205
+ module.dependencies.forEach((dependency) => {
206
+ if (dependency.data.data.asyncType === 'async') {
207
+ const chunkContainingModule = chunks.find((chunk) => chunk.hasAbsolutePath(dependency.absolutePath));
208
+ (0, assert_1.default)(chunkContainingModule, 'Chunk containing module not found: ' + dependency.absolutePath);
209
+ const moduleIdName = chunkContainingModule.getFilenameForConfig(serializerConfig);
210
+ computedAsyncModulePaths[dependency.absolutePath] = (baseUrl ?? '/') + moduleIdName;
211
+ }
212
+ });
345
213
  });
346
- }
347
- this.preModules = new Set(premodules);
214
+ return computedAsyncModulePaths;
348
215
  }
349
- const jsCode = this.serializeToCode(serializerConfig, {
350
- chunks,
351
- debugId
352
- });
353
- const relativeEntry = _path().default.relative(this.options.projectRoot, this.name);
354
- const jsAsset = {
355
- filename: outputFile,
356
- originFilename: relativeEntry,
357
- type: 'js',
358
- metadata: {
359
- isAsync: this.isAsync,
360
- requires: [...this.requiredChunks.values()].map(chunk => chunk.getFilenameForConfig(serializerConfig)),
361
- // Provide a list of module paths that can be used for matching chunks to routes.
362
- // TODO: Move HTML serializing closer to this code so we can reduce passing this much data around.
363
- modulePaths: [...this.deps].map(module => module.path)
364
- },
365
- source: jsCode
366
- };
367
- const assets = [jsAsset];
368
- const mutateSourceMapWithDebugId = sourceMap => {
369
- // TODO: Upstream this so we don't have to parse the source map back and forth.
370
- if (!debugId) {
371
- return sourceMap;
372
- }
373
- // NOTE: debugId isn't required for inline source maps because the source map is included in the same file, therefore
374
- // we don't need to disambiguate between multiple source maps.
375
- const sourceMapObject = JSON.parse(sourceMap);
376
- sourceMapObject.debugId = debugId;
377
- // NOTE: Sentry does this, but bun does not.
378
- // sourceMapObject.debug_id = debugId;
379
- return JSON.stringify(sourceMapObject);
380
- };
381
- if (
382
- // Only include the source map if the `options.sourceMapUrl` option is provided and we are exporting a static build.
383
- includeSourceMaps && !this.options.inlineSourceMap && this.options.sourceMapUrl) {
384
- const modules = [...this.preModules, ...getSortedModules([...this.deps], {
385
- createModuleId: this.options.createModuleId
386
- })].map(module => {
387
- // TODO: Make this user-configurable.
388
-
389
- // Make all paths relative to the server root to prevent the entire user filesystem from being exposed.
390
- if (module.path.startsWith('/')) {
391
- var _this$options$serverR;
392
- return {
393
- ...module,
394
- path: '/' + _path().default.relative((_this$options$serverR = this.options.serverRoot) !== null && _this$options$serverR !== void 0 ? _this$options$serverR : this.options.projectRoot, module.path)
395
- };
216
+ getAdjustedSourceMapUrl(serializerConfig) {
217
+ // Metro really only accounts for development, so we'll use the defaults here.
218
+ if (this.options.dev) {
219
+ return this.options.sourceMapUrl ?? null;
220
+ }
221
+ if (this.options.serializerOptions?.includeSourceMaps !== true) {
222
+ return null;
223
+ }
224
+ if (this.options.inlineSourceMap || !this.options.sourceMapUrl) {
225
+ return this.options.sourceMapUrl ?? null;
226
+ }
227
+ const isAbsolute = this.getPlatform() !== 'web';
228
+ const baseUrl = (0, baseJSBundle_1.getBaseUrlOption)(this.graph, this.options);
229
+ const filename = this.getFilenameForConfig(serializerConfig);
230
+ const isAbsoluteBaseUrl = !!baseUrl?.match(/https?:\/\//);
231
+ const pathname = (isAbsoluteBaseUrl ? '' : baseUrl.replace(/\/+$/, '')) +
232
+ '/' +
233
+ filename.replace(/^\/+$/, '') +
234
+ '.map';
235
+ let adjustedSourceMapUrl = this.options.sourceMapUrl;
236
+ // Metro has lots of issues...
237
+ if (this.options.sourceMapUrl.startsWith('//localhost')) {
238
+ adjustedSourceMapUrl = 'http:' + this.options.sourceMapUrl;
239
+ }
240
+ try {
241
+ const parsed = new URL(pathname, isAbsoluteBaseUrl ? baseUrl : adjustedSourceMapUrl);
242
+ if (isAbsoluteBaseUrl || isAbsolute) {
243
+ return parsed.href;
244
+ }
245
+ return parsed.pathname;
246
+ }
247
+ catch (error) {
248
+ console.error(`Failed to link source maps because the source map URL "${this.options.sourceMapUrl}" is corrupt:`, error);
249
+ return null;
396
250
  }
397
- return module;
398
- });
399
-
400
- // TODO: We may not need to mutate the original source map with a `debugId` when hermes is enabled since we'll have different source maps.
401
- const sourceMap = mutateSourceMapWithDebugId((0, _sourceMapString().default)(modules, {
402
- excludeSource: false,
403
- ...this.options
404
- }));
405
- assets.push({
406
- filename: this.options.dev ? jsAsset.filename + '.map' : outputFile + '.map',
407
- originFilename: jsAsset.originFilename,
408
- type: 'map',
409
- metadata: {},
410
- source: sourceMap
411
- });
412
251
  }
413
- if (includeBytecode && this.isHermesEnabled()) {
414
- const adjustedSource = jsAsset.source.replace(/^\/\/# (sourceMappingURL)=(.*)$/gm, (...props) => {
415
- if (props[1] === 'sourceMappingURL') {
416
- const mapName = props[2].replace(/\.js\.map$/, '.hbc.map');
417
- return `//# ${props[1]}=` + mapName;
252
+ serializeToCode(serializerConfig, { debugId, chunks }) {
253
+ return this.serializeToCodeWithTemplates(serializerConfig, {
254
+ skipWrapping: false,
255
+ sourceMapUrl: this.getAdjustedSourceMapUrl(serializerConfig) ?? undefined,
256
+ computedAsyncModulePaths: this.getComputedPathsForAsyncDependencies(serializerConfig, chunks),
257
+ debugId,
258
+ });
259
+ }
260
+ async serializeToAssetsAsync(serializerConfig, chunks, { includeSourceMaps, includeBytecode, unstable_beforeAssetSerializationPlugins, }) {
261
+ // Create hash without wrapping to prevent it changing when the wrapping changes.
262
+ const outputFile = this.getFilenameForConfig(serializerConfig);
263
+ // We already use a stable hash for the output filename, so we'll reuse that for the debugId.
264
+ const debugId = (0, debugId_1.stringToUUID)(path_1.default.basename(outputFile, path_1.default.extname(outputFile)));
265
+ let premodules = [...this.preModules];
266
+ if (unstable_beforeAssetSerializationPlugins) {
267
+ for (const plugin of unstable_beforeAssetSerializationPlugins) {
268
+ premodules = plugin({ graph: this.graph, premodules, debugId });
269
+ }
270
+ this.preModules = new Set(premodules);
271
+ }
272
+ const jsCode = this.serializeToCode(serializerConfig, { chunks, debugId });
273
+ const relativeEntry = path_1.default.relative(this.options.projectRoot, this.name);
274
+ const jsAsset = {
275
+ filename: outputFile,
276
+ originFilename: relativeEntry,
277
+ type: 'js',
278
+ metadata: {
279
+ isAsync: this.isAsync,
280
+ requires: [...this.requiredChunks.values()].map((chunk) => chunk.getFilenameForConfig(serializerConfig)),
281
+ // Provide a list of module paths that can be used for matching chunks to routes.
282
+ // TODO: Move HTML serializing closer to this code so we can reduce passing this much data around.
283
+ modulePaths: [...this.deps].map((module) => module.path),
284
+ },
285
+ source: jsCode,
286
+ };
287
+ const assets = [jsAsset];
288
+ const mutateSourceMapWithDebugId = (sourceMap) => {
289
+ // TODO: Upstream this so we don't have to parse the source map back and forth.
290
+ if (!debugId) {
291
+ return sourceMap;
292
+ }
293
+ // NOTE: debugId isn't required for inline source maps because the source map is included in the same file, therefore
294
+ // we don't need to disambiguate between multiple source maps.
295
+ const sourceMapObject = JSON.parse(sourceMap);
296
+ sourceMapObject.debugId = debugId;
297
+ // NOTE: Sentry does this, but bun does not.
298
+ // sourceMapObject.debug_id = debugId;
299
+ return JSON.stringify(sourceMapObject);
300
+ };
301
+ if (
302
+ // Only include the source map if the `options.sourceMapUrl` option is provided and we are exporting a static build.
303
+ includeSourceMaps &&
304
+ !this.options.inlineSourceMap &&
305
+ this.options.sourceMapUrl) {
306
+ const modules = [
307
+ ...this.preModules,
308
+ ...getSortedModules([...this.deps], {
309
+ createModuleId: this.options.createModuleId,
310
+ }),
311
+ ].map((module) => {
312
+ // TODO: Make this user-configurable.
313
+ // Make all paths relative to the server root to prevent the entire user filesystem from being exposed.
314
+ if (module.path.startsWith('/')) {
315
+ return {
316
+ ...module,
317
+ path: '/' + path_1.default.relative(this.options.serverRoot ?? this.options.projectRoot, module.path),
318
+ };
319
+ }
320
+ return module;
321
+ });
322
+ // TODO: We may not need to mutate the original source map with a `debugId` when hermes is enabled since we'll have different source maps.
323
+ const sourceMap = mutateSourceMapWithDebugId((0, sourceMapString_1.default)(modules, {
324
+ excludeSource: false,
325
+ ...this.options,
326
+ }));
327
+ assets.push({
328
+ filename: this.options.dev ? jsAsset.filename + '.map' : outputFile + '.map',
329
+ originFilename: jsAsset.originFilename,
330
+ type: 'map',
331
+ metadata: {},
332
+ source: sourceMap,
333
+ });
418
334
  }
419
- return '';
420
- });
421
-
422
- // TODO: Generate hbc for each chunk
423
- const hermesBundleOutput = await (0, _exportHermes().buildHermesBundleAsync)({
424
- filename: this.name,
425
- code: adjustedSource,
426
- map: assets[1] ? assets[1].source : null,
427
- // TODO: Maybe allow prod + no minify.
428
- minify: true //!this.options.dev,
429
- });
430
- if (hermesBundleOutput.hbc) {
431
- // TODO: Unclear if we should add multiple assets, link the assets, or mutate the first asset.
432
- // jsAsset.metadata.hbc = hermesBundleOutput.hbc;
433
- // @ts-expect-error: TODO
434
- jsAsset.source = hermesBundleOutput.hbc;
435
- jsAsset.filename = jsAsset.filename.replace(/\.js$/, '.hbc');
436
- }
437
- if (assets[1] && hermesBundleOutput.sourcemap) {
438
- assets[1].source = mutateSourceMapWithDebugId(hermesBundleOutput.sourcemap);
439
- assets[1].filename = assets[1].filename.replace(/\.js\.map$/, '.hbc.map');
440
- }
335
+ if (includeBytecode && this.isHermesEnabled()) {
336
+ const adjustedSource = jsAsset.source.replace(/^\/\/# (sourceMappingURL)=(.*)$/gm, (...props) => {
337
+ if (props[1] === 'sourceMappingURL') {
338
+ const mapName = props[2].replace(/\.js\.map$/, '.hbc.map');
339
+ return `//# ${props[1]}=` + mapName;
340
+ }
341
+ return '';
342
+ });
343
+ // TODO: Generate hbc for each chunk
344
+ const hermesBundleOutput = await (0, exportHermes_1.buildHermesBundleAsync)({
345
+ filename: this.name,
346
+ code: adjustedSource,
347
+ map: assets[1] ? assets[1].source : null,
348
+ // TODO: Maybe allow prod + no minify.
349
+ minify: true, //!this.options.dev,
350
+ });
351
+ if (hermesBundleOutput.hbc) {
352
+ // TODO: Unclear if we should add multiple assets, link the assets, or mutate the first asset.
353
+ // jsAsset.metadata.hbc = hermesBundleOutput.hbc;
354
+ // @ts-expect-error: TODO
355
+ jsAsset.source = hermesBundleOutput.hbc;
356
+ jsAsset.filename = jsAsset.filename.replace(/\.js$/, '.hbc');
357
+ }
358
+ if (assets[1] && hermesBundleOutput.sourcemap) {
359
+ assets[1].source = mutateSourceMapWithDebugId(hermesBundleOutput.sourcemap);
360
+ assets[1].filename = assets[1].filename.replace(/\.js\.map$/, '.hbc.map');
361
+ }
362
+ }
363
+ return assets;
364
+ }
365
+ supportsBytecode() {
366
+ return this.getPlatform() !== 'web';
367
+ }
368
+ isHermesEnabled() {
369
+ // TODO: Revisit.
370
+ // TODO: There could be an issue with having the serializer for export:embed output hermes since the native scripts will
371
+ // also create hermes bytecode. We may need to disable in one of the two places.
372
+ return (!this.options.dev &&
373
+ this.supportsBytecode() &&
374
+ this.graph.transformOptions.customTransformOptions?.engine === 'hermes');
441
375
  }
442
- return assets;
443
- }
444
- supportsBytecode() {
445
- return this.getPlatform() !== 'web';
446
- }
447
- isHermesEnabled() {
448
- var _this$graph$transform;
449
- // TODO: Revisit.
450
- // TODO: There could be an issue with having the serializer for export:embed output hermes since the native scripts will
451
- // also create hermes bytecode. We may need to disable in one of the two places.
452
- return !this.options.dev && this.supportsBytecode() && ((_this$graph$transform = this.graph.transformOptions.customTransformOptions) === null || _this$graph$transform === void 0 ? void 0 : _this$graph$transform.engine) === 'hermes';
453
- }
454
376
  }
455
377
  exports.Chunk = Chunk;
456
378
  function getEntryModulesForChunkSettings(graph, settings) {
457
- return [...graph.dependencies.entries()].filter(([path]) => settings.test.test(path)).map(([, module]) => module);
379
+ return [...graph.dependencies.entries()]
380
+ .filter(([path]) => settings.test.test(path))
381
+ .map(([, module]) => module);
458
382
  }
459
383
  function chunkIdForModules(modules) {
460
- return modules.map(module => module.path).sort().join('=>');
384
+ return modules
385
+ .map((module) => module.path)
386
+ .sort()
387
+ .join('=>');
461
388
  }
462
389
  function gatherChunks(chunks, settings, preModules, graph, options, isAsync = false) {
463
- let entryModules = getEntryModulesForChunkSettings(graph, settings);
464
- const existingChunks = [...chunks.values()];
465
- entryModules = entryModules.filter(module => {
466
- return !existingChunks.find(chunk => chunk.entries.includes(module));
467
- });
468
-
469
- // Prevent processing the same entry file twice.
470
- if (!entryModules.length) {
471
- return chunks;
472
- }
473
- const entryChunk = new Chunk(chunkIdForModules(entryModules), entryModules, graph, options, isAsync);
474
-
475
- // Add all the pre-modules to the first chunk.
476
- if (preModules.length) {
477
- // On native, use the preModules in insert code in the entry chunk.
478
- for (const module of preModules.values()) {
479
- entryChunk.preModules.add(module);
390
+ let entryModules = getEntryModulesForChunkSettings(graph, settings);
391
+ const existingChunks = [...chunks.values()];
392
+ entryModules = entryModules.filter((module) => {
393
+ return !existingChunks.find((chunk) => chunk.entries.includes(module));
394
+ });
395
+ // Prevent processing the same entry file twice.
396
+ if (!entryModules.length) {
397
+ return chunks;
480
398
  }
481
- }
482
- chunks.add(entryChunk);
483
- const splitChunks = (0, _baseJSBundle().getSplitChunksOption)(graph, options);
484
- function includeModule(entryModule) {
485
- for (const dependency of entryModule.dependencies.values()) {
486
- if (dependency.data.data.asyncType === 'async' &&
487
- // Support disabling multiple chunks.
488
- splitChunks) {
489
- gatherChunks(chunks, {
490
- test: pathToRegex(dependency.absolutePath)
491
- }, [], graph, options, true);
492
- } else {
493
- const module = graph.dependencies.get(dependency.absolutePath);
494
- if (module) {
495
- // Prevent circular dependencies from creating infinite loops.
496
- if (!entryChunk.deps.has(module)) {
497
- entryChunk.deps.add(module);
498
- includeModule(module);
499
- }
399
+ const entryChunk = new Chunk(chunkIdForModules(entryModules), entryModules, graph, options, isAsync);
400
+ // Add all the pre-modules to the first chunk.
401
+ if (preModules.length) {
402
+ // On native, use the preModules in insert code in the entry chunk.
403
+ for (const module of preModules.values()) {
404
+ entryChunk.preModules.add(module);
500
405
  }
501
- }
502
406
  }
503
- }
504
- for (const entryModule of entryModules) {
505
- includeModule(entryModule);
506
- }
507
- return chunks;
407
+ chunks.add(entryChunk);
408
+ const splitChunks = (0, baseJSBundle_1.getSplitChunksOption)(graph, options);
409
+ function includeModule(entryModule) {
410
+ for (const dependency of entryModule.dependencies.values()) {
411
+ if (dependency.data.data.asyncType === 'async' &&
412
+ // Support disabling multiple chunks.
413
+ splitChunks) {
414
+ gatherChunks(chunks, { test: pathToRegex(dependency.absolutePath) }, [], graph, options, true);
415
+ }
416
+ else {
417
+ const module = graph.dependencies.get(dependency.absolutePath);
418
+ if (module) {
419
+ // Prevent circular dependencies from creating infinite loops.
420
+ if (!entryChunk.deps.has(module)) {
421
+ entryChunk.deps.add(module);
422
+ includeModule(module);
423
+ }
424
+ }
425
+ }
426
+ }
427
+ }
428
+ for (const entryModule of entryModules) {
429
+ includeModule(entryModule);
430
+ }
431
+ return chunks;
508
432
  }
509
433
  async function serializeChunksAsync(chunks, serializerConfig, options) {
510
- const jsAssets = [];
511
- const chunksArray = [...chunks.values()];
512
- await Promise.all(chunksArray.map(async chunk => {
513
- jsAssets.push(...(await chunk.serializeToAssetsAsync(serializerConfig, chunksArray, options)));
514
- }));
515
- return jsAssets;
434
+ const jsAssets = [];
435
+ const chunksArray = [...chunks.values()];
436
+ await Promise.all(chunksArray.map(async (chunk) => {
437
+ jsAssets.push(...(await chunk.serializeToAssetsAsync(serializerConfig, chunksArray, options)));
438
+ }));
439
+ return jsAssets;
516
440
  }
517
- function getSortedModules(modules, {
518
- createModuleId
519
- }) {
520
- // Assign IDs to modules in a consistent order
521
- for (const module of modules) {
522
- createModuleId(module.path);
523
- }
524
- // Sort by IDs
525
- return modules.sort((a, b) => createModuleId(a.path) - createModuleId(b.path));
441
+ function getSortedModules(modules, { createModuleId, }) {
442
+ // Assign IDs to modules in a consistent order
443
+ for (const module of modules) {
444
+ createModuleId(module.path);
445
+ }
446
+ // Sort by IDs
447
+ return modules.sort((a, b) => createModuleId(a.path) - createModuleId(b.path));
526
448
  }
449
+ exports.getSortedModules = getSortedModules;
527
450
  //# sourceMappingURL=serializeChunks.js.map