metro 0.76.0 → 0.76.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.
Files changed (94) hide show
  1. package/package.json +24 -24
  2. package/src/Asset.d.ts +25 -0
  3. package/src/Bundler.d.ts +39 -0
  4. package/src/DeltaBundler/Graph.d.ts +40 -0
  5. package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
  6. package/src/DeltaBundler/Transformer.js +1 -2
  7. package/src/DeltaBundler/Transformer.js.flow +1 -2
  8. package/src/DeltaBundler/Worker.d.ts +47 -0
  9. package/src/DeltaBundler/types.d.ts +167 -0
  10. package/src/DeltaBundler.d.ts +58 -0
  11. package/src/HmrServer.js +1 -5
  12. package/src/HmrServer.js.flow +0 -5
  13. package/src/IncrementalBundler.d.ts +97 -0
  14. package/src/IncrementalBundler.js +1 -0
  15. package/src/IncrementalBundler.js.flow +1 -0
  16. package/src/ModuleGraph/worker/collectDependencies.d.ts +27 -0
  17. package/src/ModuleGraph/worker/collectDependencies.js +42 -25
  18. package/src/ModuleGraph/worker/collectDependencies.js.flow +41 -36
  19. package/src/Server/MultipartResponse.d.ts +31 -0
  20. package/src/Server.d.ts +113 -0
  21. package/src/Server.js +11 -133
  22. package/src/Server.js.flow +12 -154
  23. package/src/cli/parseKeyValueParamArray.js +34 -0
  24. package/src/cli/parseKeyValueParamArray.js.flow +31 -0
  25. package/src/cli-utils.js.flow +2 -6
  26. package/src/cli.js +2 -0
  27. package/src/cli.js.flow +1 -0
  28. package/src/commands/build.js +34 -7
  29. package/src/commands/build.js.flow +50 -8
  30. package/src/commands/dependencies.js +11 -9
  31. package/src/commands/dependencies.js.flow +128 -0
  32. package/src/commands/serve.js +11 -4
  33. package/src/commands/serve.js.flow +26 -6
  34. package/src/index.d.ts +151 -0
  35. package/src/index.flow.js +8 -2
  36. package/src/index.flow.js.flow +18 -6
  37. package/src/lib/CountingSet.d.ts +48 -0
  38. package/src/lib/TerminalReporter.d.ts +27 -0
  39. package/src/lib/TerminalReporter.js +1 -4
  40. package/src/lib/TerminalReporter.js.flow +1 -5
  41. package/src/lib/contextModule.d.ts +22 -0
  42. package/src/lib/getGraphId.d.ts +11 -0
  43. package/src/lib/getGraphId.js +0 -1
  44. package/src/lib/getGraphId.js.flow +0 -1
  45. package/src/lib/getPrependedScripts.js +0 -9
  46. package/src/lib/getPrependedScripts.js.flow +0 -9
  47. package/src/lib/parseOptionsFromUrl.js +1 -16
  48. package/src/lib/parseOptionsFromUrl.js.flow +0 -17
  49. package/src/lib/reporting.d.ts +140 -0
  50. package/src/lib/reporting.js.flow +0 -1
  51. package/src/lib/splitBundleOptions.js +0 -1
  52. package/src/lib/splitBundleOptions.js.flow +0 -1
  53. package/src/lib/transformHelpers.js +0 -1
  54. package/src/lib/transformHelpers.js.flow +0 -1
  55. package/src/node-haste/DependencyGraph/createHasteMap.js +0 -1
  56. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +0 -1
  57. package/src/node-haste/DependencyGraph.d.ts +59 -0
  58. package/src/node-haste/DependencyGraph.js +1 -0
  59. package/src/node-haste/DependencyGraph.js.flow +1 -0
  60. package/src/shared/output/RamBundle/as-assets.js +1 -0
  61. package/src/shared/output/RamBundle/as-assets.js.flow +1 -0
  62. package/src/shared/output/RamBundle/write-sourcemap.js +1 -0
  63. package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -0
  64. package/src/shared/output/bundle.d.ts +31 -0
  65. package/src/shared/types.d.ts +138 -0
  66. package/src/shared/types.flow.js.flow +2 -1
  67. package/types/Asset.d.ts +25 -0
  68. package/types/Bundler.d.ts +39 -0
  69. package/types/DeltaBundler/Graph.d.ts +40 -0
  70. package/types/DeltaBundler/Serializers/getRamBundleInfo.d.ts +18 -0
  71. package/types/DeltaBundler/Worker.d.ts +47 -0
  72. package/types/DeltaBundler/types.d.ts +167 -0
  73. package/types/DeltaBundler.d.ts +58 -0
  74. package/types/IncrementalBundler.d.ts +97 -0
  75. package/types/ModuleGraph/worker/collectDependencies.d.ts +27 -0
  76. package/types/Server/MultipartResponse.d.ts +31 -0
  77. package/types/Server.d.ts +113 -0
  78. package/types/index.d.ts +151 -0
  79. package/types/lib/CountingSet.d.ts +48 -0
  80. package/types/lib/TerminalReporter.d.ts +27 -0
  81. package/types/lib/contextModule.d.ts +22 -0
  82. package/types/lib/getGraphId.d.ts +11 -0
  83. package/types/lib/reporting.d.ts +140 -0
  84. package/types/node-haste/DependencyGraph.d.ts +59 -0
  85. package/types/shared/output/bundle.d.ts +31 -0
  86. package/types/shared/types.d.ts +138 -0
  87. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +0 -81
  88. package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +0 -103
  89. package/src/DeltaBundler/Serializers/helpers/bytecode.js +0 -61
  90. package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +0 -75
  91. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +0 -40
  92. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +0 -51
  93. package/src/lib/bundleToBytecode.js +0 -79
  94. package/src/lib/bundleToBytecode.js.flow +0 -97
@@ -1,81 +0,0 @@
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
- * @oncall react_native
10
- */
11
-
12
- "use strict";
13
-
14
- const getAppendScripts = require("../../lib/getAppendScripts");
15
- const { getJsOutput } = require("./helpers/js");
16
- const processBytecodeModules = require("./helpers/processBytecodeModules");
17
- function baseBytecodeBundle(entryPoint, preModules, graph, options) {
18
- for (const module of graph.dependencies.values()) {
19
- options.createModuleId(module.path);
20
- }
21
- const processModulesOptions = {
22
- filter: options.processModuleFilter,
23
- createModuleId: options.createModuleId,
24
- dev: options.dev,
25
- includeAsyncPaths: options.includeAsyncPaths,
26
- projectRoot: options.projectRoot,
27
- serverRoot: options.serverRoot,
28
- };
29
-
30
- // Do not prepend polyfills or the require runtime when only modules are requested
31
- if (options.modulesOnly) {
32
- preModules = [];
33
- }
34
- const modules = [...graph.dependencies.values()].sort(
35
- (a, b) => options.createModuleId(a.path) - options.createModuleId(b.path)
36
- );
37
- const { compile } = require("metro-hermes-compiler");
38
- const post = processBytecodeModules(
39
- getAppendScripts(entryPoint, [...preModules, ...modules], {
40
- asyncRequireModulePath: options.asyncRequireModulePath,
41
- createModuleId: options.createModuleId,
42
- getRunModuleStatement: options.getRunModuleStatement,
43
- inlineSourceMap: options.inlineSourceMap,
44
- runBeforeMainModule: options.runBeforeMainModule,
45
- runModule: options.runModule,
46
- sourceMapUrl: options.sourceMapUrl,
47
- sourceUrl: options.sourceUrl,
48
- }).map((module) => {
49
- return {
50
- ...module,
51
- output: [
52
- ...module.output,
53
- {
54
- type: "bytecode/script/virtual",
55
- data: {
56
- bytecode: compile(getJsOutput(module).data.code, {
57
- sourceURL: module.path,
58
- }).bytecode,
59
- },
60
- },
61
- ],
62
- };
63
- }),
64
- processModulesOptions
65
- ).flatMap(([module, bytecodeBundle]) => bytecodeBundle);
66
- const processedModules = processBytecodeModules(
67
- [...graph.dependencies.values()],
68
- processModulesOptions
69
- ).map(([module, bytecodeBundle]) => [
70
- options.createModuleId(module.path),
71
- bytecodeBundle,
72
- ]);
73
- return {
74
- pre: processBytecodeModules(preModules, processModulesOptions).flatMap(
75
- ([_, bytecodeBundle]) => bytecodeBundle
76
- ),
77
- post,
78
- modules: processedModules,
79
- };
80
- }
81
- module.exports = baseBytecodeBundle;
@@ -1,103 +0,0 @@
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
- * @oncall react_native
10
- */
11
-
12
- 'use strict';
13
-
14
- import type {
15
- MixedOutput,
16
- Module,
17
- ReadOnlyGraph,
18
- SerializerOptions,
19
- } from '../types.flow';
20
- import type {BytecodeBundle} from 'metro-runtime/src/modules/types.flow';
21
-
22
- const getAppendScripts = require('../../lib/getAppendScripts');
23
- const {getJsOutput} = require('./helpers/js');
24
- const processBytecodeModules = require('./helpers/processBytecodeModules');
25
-
26
- function baseBytecodeBundle(
27
- entryPoint: string,
28
- preModules: $ReadOnlyArray<Module<>>,
29
- graph: ReadOnlyGraph<>,
30
- options: SerializerOptions,
31
- ): BytecodeBundle {
32
- for (const module of graph.dependencies.values()) {
33
- options.createModuleId(module.path);
34
- }
35
-
36
- const processModulesOptions = {
37
- filter: options.processModuleFilter,
38
- createModuleId: options.createModuleId,
39
- dev: options.dev,
40
- includeAsyncPaths: options.includeAsyncPaths,
41
- projectRoot: options.projectRoot,
42
- serverRoot: options.serverRoot,
43
- };
44
-
45
- // Do not prepend polyfills or the require runtime when only modules are requested
46
- if (options.modulesOnly) {
47
- preModules = [];
48
- }
49
-
50
- const modules = [...graph.dependencies.values()].sort(
51
- (a: Module<MixedOutput>, b: Module<MixedOutput>) =>
52
- options.createModuleId(a.path) - options.createModuleId(b.path),
53
- );
54
-
55
- const {compile} = require('metro-hermes-compiler');
56
-
57
- const post = processBytecodeModules(
58
- getAppendScripts(entryPoint, [...preModules, ...modules], {
59
- asyncRequireModulePath: options.asyncRequireModulePath,
60
- createModuleId: options.createModuleId,
61
- getRunModuleStatement: options.getRunModuleStatement,
62
- inlineSourceMap: options.inlineSourceMap,
63
- runBeforeMainModule: options.runBeforeMainModule,
64
- runModule: options.runModule,
65
- sourceMapUrl: options.sourceMapUrl,
66
- sourceUrl: options.sourceUrl,
67
- }).map(module => {
68
- return {
69
- ...module,
70
- output: [
71
- ...module.output,
72
- {
73
- type: 'bytecode/script/virtual',
74
- data: {
75
- bytecode: compile(getJsOutput(module).data.code, {
76
- sourceURL: module.path,
77
- }).bytecode,
78
- },
79
- },
80
- ],
81
- };
82
- }),
83
- processModulesOptions,
84
- ).flatMap(([module, bytecodeBundle]) => bytecodeBundle);
85
-
86
- const processedModules = processBytecodeModules(
87
- [...graph.dependencies.values()],
88
- processModulesOptions,
89
- ).map(([module, bytecodeBundle]) => [
90
- options.createModuleId(module.path),
91
- bytecodeBundle,
92
- ]);
93
-
94
- return {
95
- pre: processBytecodeModules(preModules, processModulesOptions).flatMap(
96
- ([_, bytecodeBundle]) => bytecodeBundle,
97
- ),
98
- post,
99
- modules: processedModules,
100
- };
101
- }
102
-
103
- module.exports = baseBytecodeBundle;
@@ -1,61 +0,0 @@
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
- * @oncall react_native
10
- */
11
-
12
- "use strict";
13
-
14
- const { getModuleParams } = require("./js");
15
- const invariant = require("invariant");
16
- function wrapModule(module, options) {
17
- const output = getBytecodeOutput(module);
18
- if (output.type.startsWith("bytecode/script")) {
19
- return [output.data.bytecode];
20
- }
21
- const params = getModuleParams(module, options);
22
- const { compile } = require("metro-hermes-compiler");
23
- const headerCode = `globalThis.$$METRO_D=[${JSON.stringify(params)}];`;
24
- return [
25
- compile(headerCode, {
26
- sourceURL: module.path + "-virtual.js",
27
- }).bytecode,
28
- output.data.bytecode,
29
- ];
30
- }
31
- function getBytecodeOutput(module) {
32
- const output = module.output
33
- .filter(({ type }) => type.startsWith("bytecode/"))
34
- .map((output) =>
35
- output.data.bytecode instanceof Buffer
36
- ? output
37
- : // Re-create buffers after losing the Buffer instance when sending data over workers.
38
- {
39
- ...output,
40
- data: {
41
- ...output.data,
42
- bytecode: Buffer.from(output.data.bytecode.data),
43
- },
44
- }
45
- );
46
- invariant(
47
- output.length === 1,
48
- `Modules must have exactly one bytecode output, but ${module.path} has ${output.length} bytecode outputs.`
49
- );
50
- return output[0];
51
- }
52
- function isBytecodeModule(module) {
53
- return (
54
- module.output.filter(({ type }) => type.startsWith("bytecode/")).length > 0
55
- );
56
- }
57
- module.exports = {
58
- getBytecodeOutput,
59
- isBytecodeModule,
60
- wrapModule,
61
- };
@@ -1,75 +0,0 @@
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
- * @oncall react_native
10
- */
11
-
12
- 'use strict';
13
-
14
- import type {Module} from '../../types.flow';
15
- import type {BytecodeOutput} from 'metro-transform-worker';
16
-
17
- import type {Options} from './js';
18
- const {getModuleParams} = require('./js');
19
-
20
- const invariant = require('invariant');
21
-
22
- function wrapModule(module: Module<>, options: Options): Array<Buffer> {
23
- const output = getBytecodeOutput(module);
24
-
25
- if (output.type.startsWith('bytecode/script')) {
26
- return [output.data.bytecode];
27
- }
28
-
29
- const params = getModuleParams(module, options);
30
- const {compile} = require('metro-hermes-compiler');
31
-
32
- const headerCode = `globalThis.$$METRO_D=[${JSON.stringify(params)}];`;
33
- return [
34
- compile(headerCode, {
35
- sourceURL: module.path + '-virtual.js',
36
- }).bytecode,
37
- output.data.bytecode,
38
- ];
39
- }
40
-
41
- function getBytecodeOutput(module: Module<>): BytecodeOutput {
42
- const output = module.output
43
- .filter(({type}) => type.startsWith('bytecode/'))
44
- .map((output: any) =>
45
- output.data.bytecode instanceof Buffer
46
- ? output
47
- : // Re-create buffers after losing the Buffer instance when sending data over workers.
48
- {
49
- ...output,
50
- data: {
51
- ...output.data,
52
- bytecode: Buffer.from(output.data.bytecode.data),
53
- },
54
- },
55
- );
56
-
57
- invariant(
58
- output.length === 1,
59
- `Modules must have exactly one bytecode output, but ${module.path} has ${output.length} bytecode outputs.`,
60
- );
61
-
62
- return (output[0]: any);
63
- }
64
-
65
- function isBytecodeModule(module: Module<>): boolean {
66
- return (
67
- module.output.filter(({type}) => type.startsWith('bytecode/')).length > 0
68
- );
69
- }
70
-
71
- module.exports = {
72
- getBytecodeOutput,
73
- isBytecodeModule,
74
- wrapModule,
75
- };
@@ -1,40 +0,0 @@
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
- * @oncall react_native
10
- */
11
-
12
- "use strict";
13
-
14
- const { isBytecodeModule, wrapModule } = require("./bytecode");
15
- function processBytecodeModules(
16
- modules,
17
- {
18
- filter = () => true,
19
- createModuleId,
20
- dev,
21
- includeAsyncPaths,
22
- projectRoot,
23
- serverRoot,
24
- }
25
- ) {
26
- return [...modules]
27
- .filter(isBytecodeModule)
28
- .filter(filter)
29
- .map((module) => [
30
- module,
31
- wrapModule(module, {
32
- createModuleId,
33
- dev,
34
- includeAsyncPaths,
35
- projectRoot,
36
- serverRoot,
37
- }),
38
- ]);
39
- }
40
- module.exports = processBytecodeModules;
@@ -1,51 +0,0 @@
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
- * @oncall react_native
10
- */
11
-
12
- 'use strict';
13
-
14
- import type {Module} from '../../types.flow';
15
-
16
- const {isBytecodeModule, wrapModule} = require('./bytecode');
17
-
18
- function processBytecodeModules(
19
- modules: $ReadOnlyArray<Module<>>,
20
- {
21
- filter = () => true,
22
- createModuleId,
23
- dev,
24
- includeAsyncPaths,
25
- projectRoot,
26
- serverRoot,
27
- }: $ReadOnly<{
28
- filter?: (module: Module<>) => boolean,
29
- createModuleId: string => number,
30
- dev: boolean,
31
- includeAsyncPaths: boolean,
32
- projectRoot: string,
33
- serverRoot: string,
34
- }>,
35
- ): $ReadOnlyArray<[Module<>, Array<Buffer>]> {
36
- return [...modules]
37
- .filter(isBytecodeModule)
38
- .filter(filter)
39
- .map((module: Module<>) => [
40
- module,
41
- wrapModule(module, {
42
- createModuleId,
43
- dev,
44
- includeAsyncPaths,
45
- projectRoot,
46
- serverRoot,
47
- }),
48
- ]);
49
- }
50
-
51
- module.exports = processBytecodeModules;
@@ -1,79 +0,0 @@
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
- * @oncall react_native
10
- */
11
-
12
- "use strict";
13
-
14
- // The magic number is used as a header for bytecode.
15
- // It represents a Metro tunnel in binary.
16
- //
17
- // 11111111
18
- // 11100111
19
- // 11000011
20
- // 11000011
21
- const MAGIC_NUMBER = 0xffe7c3c3;
22
- function getFileHeader(moduleCount) {
23
- const buffer = Buffer.alloc(8);
24
- buffer.writeUInt32LE(MAGIC_NUMBER, 0);
25
- buffer.writeUInt32LE(moduleCount, 4);
26
- return buffer;
27
- }
28
- function addModuleHeader(buffer) {
29
- const { getFileLength } = require("metro-hermes-compiler");
30
- const fileLength = getFileLength(buffer, 0);
31
- const header = Buffer.alloc(4);
32
- header.writeUInt32LE(fileLength, 0);
33
- return [header, buffer];
34
- }
35
-
36
- /**
37
- * A bytecode bundle has the following format:
38
- *
39
- * 4 bytes MAGIC_NUMBER
40
- * 4 bytes Module count
41
- * 4 bytes Module length N + N bytes
42
- * ...
43
- *
44
- */
45
- function bundleToBytecode(bundle) {
46
- const buffers = [];
47
- if (bundle.pre.length) {
48
- buffers.push(...bundle.pre);
49
- }
50
- const modules = [];
51
- const sortedModules = bundle.modules
52
- .slice()
53
- // In a JS bundle, the order of modules needs to be deterministic for source
54
- // maps to work. This constraint is not necessary for bytecode bundles but
55
- // is kept for consistency.
56
- .sort((a, b) => a[0] - b[0]);
57
- for (const [id, bytecodeBundle] of sortedModules) {
58
- buffers.push(...bytecodeBundle);
59
- // Use the size of the last item in `bytecodeBundle` which is always
60
- // the actual module without headers.
61
- modules.push([id, bytecodeBundle[bytecodeBundle.length - 1].length]);
62
- }
63
- if (bundle.post.length) {
64
- buffers.push(...bundle.post);
65
- }
66
- return {
67
- bytecode: Buffer.concat([
68
- getFileHeader(buffers.length),
69
- ...buffers.flatMap(addModuleHeader),
70
- ]),
71
- metadata: {
72
- pre: bundle.pre ? bundle.pre.length : 0,
73
- post: bundle.post.length,
74
- modules,
75
- },
76
- };
77
- }
78
- bundleToBytecode.MAGIC_NUMBER = MAGIC_NUMBER;
79
- module.exports = bundleToBytecode;
@@ -1,97 +0,0 @@
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 strict-local
8
- * @format
9
- * @oncall react_native
10
- */
11
-
12
- 'use strict';
13
-
14
- import type {
15
- BundleMetadata,
16
- BytecodeBundle,
17
- } from 'metro-runtime/src/modules/types.flow';
18
-
19
- // The magic number is used as a header for bytecode.
20
- // It represents a Metro tunnel in binary.
21
- //
22
- // 11111111
23
- // 11100111
24
- // 11000011
25
- // 11000011
26
- const MAGIC_NUMBER = 0xffe7c3c3;
27
-
28
- function getFileHeader(moduleCount: number): Buffer {
29
- const buffer = Buffer.alloc(8);
30
- buffer.writeUInt32LE(MAGIC_NUMBER, 0);
31
- buffer.writeUInt32LE(moduleCount, 4);
32
- return buffer;
33
- }
34
-
35
- function addModuleHeader(buffer: Buffer): [Buffer, Buffer] {
36
- const {getFileLength} = require('metro-hermes-compiler');
37
-
38
- const fileLength = getFileLength(buffer, 0);
39
- const header = Buffer.alloc(4);
40
- header.writeUInt32LE(fileLength, 0);
41
- return [header, buffer];
42
- }
43
-
44
- /**
45
- * A bytecode bundle has the following format:
46
- *
47
- * 4 bytes MAGIC_NUMBER
48
- * 4 bytes Module count
49
- * 4 bytes Module length N + N bytes
50
- * ...
51
- *
52
- */
53
- function bundleToBytecode(bundle: BytecodeBundle): {
54
- +bytecode: Buffer,
55
- +metadata: BundleMetadata,
56
- } {
57
- const buffers: Array<Buffer> = [];
58
-
59
- if (bundle.pre.length) {
60
- buffers.push(...bundle.pre);
61
- }
62
-
63
- const modules = [];
64
-
65
- const sortedModules = bundle.modules
66
- .slice()
67
- // In a JS bundle, the order of modules needs to be deterministic for source
68
- // maps to work. This constraint is not necessary for bytecode bundles but
69
- // is kept for consistency.
70
- .sort((a, b) => a[0] - b[0]);
71
-
72
- for (const [id, bytecodeBundle] of sortedModules) {
73
- buffers.push(...bytecodeBundle);
74
- // Use the size of the last item in `bytecodeBundle` which is always
75
- // the actual module without headers.
76
- modules.push([id, bytecodeBundle[bytecodeBundle.length - 1].length]);
77
- }
78
-
79
- if (bundle.post.length) {
80
- buffers.push(...bundle.post);
81
- }
82
-
83
- return {
84
- bytecode: Buffer.concat([
85
- getFileHeader(buffers.length),
86
- ...buffers.flatMap(addModuleHeader),
87
- ]),
88
- metadata: {
89
- pre: bundle.pre ? bundle.pre.length : 0,
90
- post: bundle.post.length,
91
- modules,
92
- },
93
- };
94
- }
95
-
96
- bundleToBytecode.MAGIC_NUMBER = MAGIC_NUMBER;
97
- module.exports = bundleToBytecode;