metro 0.71.2 → 0.72.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 +21 -21
- package/src/Assets.js +3 -2
- package/src/Assets.js.flow +3 -2
- package/src/Bundler.js +11 -2
- package/src/Bundler.js.flow +7 -1
- package/src/DeltaBundler/DeltaCalculator.js +85 -21
- package/src/DeltaBundler/DeltaCalculator.js.flow +63 -8
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +1 -3
- package/src/DeltaBundler/Transformer.js +27 -4
- package/src/DeltaBundler/Transformer.js.flow +18 -2
- package/src/DeltaBundler/Worker.flow.js +45 -1
- package/src/DeltaBundler/Worker.flow.js.flow +42 -1
- package/src/DeltaBundler/WorkerFarm.js +3 -2
- package/src/DeltaBundler/WorkerFarm.js.flow +5 -3
- package/src/DeltaBundler/graphOperations.js +170 -63
- package/src/DeltaBundler/graphOperations.js.flow +144 -64
- package/src/DeltaBundler/types.flow.js.flow +11 -5
- package/src/HmrServer.js +2 -0
- package/src/HmrServer.js.flow +2 -0
- package/src/IncrementalBundler.js +6 -0
- package/src/IncrementalBundler.js.flow +6 -0
- package/src/ModuleGraph/node-haste/HasteFS.js.flow +1 -1
- package/src/ModuleGraph/node-haste/node-haste.js +14 -7
- package/src/ModuleGraph/node-haste/node-haste.js.flow +35 -10
- package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +5 -13
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +4 -14
- package/src/ModuleGraph/output/util.js +1 -0
- package/src/ModuleGraph/output/util.js.flow +4 -3
- package/src/ModuleGraph/silent-console.js +5 -4
- package/src/ModuleGraph/silent-console.js.flow +8 -4
- package/src/ModuleGraph/worker/collectDependencies.js +19 -30
- package/src/ModuleGraph/worker/collectDependencies.js.flow +28 -43
- package/src/Server.js +8 -0
- package/src/Server.js.flow +48 -12
- package/src/cli-utils.js.flow +1 -1
- package/src/commands/build.js +1 -2
- package/src/commands/build.js.flow +6 -9
- package/src/commands/dependencies.js +1 -1
- package/src/commands/serve.js +2 -1
- package/src/commands/serve.js.flow +7 -8
- package/src/index.flow.js +11 -8
- package/src/index.flow.js.flow +10 -7
- package/src/integration_tests/basic_bundle/require-context/conflict.js +25 -0
- package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +27 -0
- package/src/integration_tests/basic_bundle/require-context/empty.js +29 -0
- package/src/integration_tests/basic_bundle/require-context/empty.js.flow +26 -0
- package/src/integration_tests/basic_bundle/require-context/matching.js +26 -0
- package/src/integration_tests/basic_bundle/require-context/matching.js.flow +27 -0
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js +22 -0
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +24 -0
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +22 -0
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +24 -0
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +22 -0
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +24 -0
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js +20 -0
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +22 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/a.js +12 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/a.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/b.js +18 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/b.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/c.js +12 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/c.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js +12 -0
- package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js +12 -0
- package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js.flow +11 -0
- package/src/integration_tests/basic_bundle/require-context/utils.js +29 -0
- package/src/integration_tests/basic_bundle/require-context/utils.js.flow +44 -0
- package/src/lib/CountingSet.js +1 -0
- package/src/lib/CountingSet.js.flow +1 -0
- package/src/lib/contextModule.js +80 -0
- package/src/lib/contextModule.js.flow +86 -0
- package/src/lib/contextModuleTemplates.js +186 -0
- package/src/lib/contextModuleTemplates.js.flow +148 -0
- package/src/lib/getGraphId.js +2 -1
- package/src/lib/getGraphId.js.flow +3 -0
- package/src/lib/getPrependedScripts.js +2 -0
- package/src/lib/getPrependedScripts.js.flow +2 -0
- package/src/lib/parseOptionsFromUrl.js.flow +7 -18
- package/src/lib/transformHelpers.js +41 -9
- package/src/lib/transformHelpers.js.flow +46 -9
- package/src/node-haste/DependencyGraph/ModuleResolution.js +1 -0
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +3 -2
- package/src/node-haste/DependencyGraph/createHasteMap.js +7 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +8 -2
- package/src/node-haste/DependencyGraph.js +7 -0
- package/src/node-haste/DependencyGraph.js.flow +17 -2
- package/src/shared/output/bundle.flow.js +67 -0
- package/src/shared/output/bundle.flow.js.flow +89 -0
- package/src/shared/output/bundle.js +8 -55
- package/src/shared/output/bundle.js.flow +8 -75
|
@@ -16,6 +16,9 @@ import type {TransformInputOptions} from '../DeltaBundler/types.flow';
|
|
|
16
16
|
import type {TransformOptions} from '../DeltaBundler/Worker';
|
|
17
17
|
import type {ConfigT} from 'metro-config/src/configTypes.flow';
|
|
18
18
|
import type {Type} from 'metro-transform-worker';
|
|
19
|
+
import type {RequireContext} from './contextModule';
|
|
20
|
+
|
|
21
|
+
import {getContextModuleTemplate} from './contextModuleTemplates';
|
|
19
22
|
|
|
20
23
|
const path = require('path');
|
|
21
24
|
|
|
@@ -68,6 +71,8 @@ async function calcTransformerOptions(
|
|
|
68
71
|
onProgress: null,
|
|
69
72
|
experimentalImportBundleSupport:
|
|
70
73
|
config.transformer.experimentalImportBundleSupport,
|
|
74
|
+
unstable_allowRequireContext:
|
|
75
|
+
config.transformer.unstable_allowRequireContext,
|
|
71
76
|
shallow: false,
|
|
72
77
|
});
|
|
73
78
|
|
|
@@ -118,15 +123,47 @@ async function getTransformFn(
|
|
|
118
123
|
options,
|
|
119
124
|
);
|
|
120
125
|
|
|
121
|
-
return async (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
return async (modulePath: string, requireContext: ?RequireContext) => {
|
|
127
|
+
let templateBuffer: Buffer;
|
|
128
|
+
|
|
129
|
+
if (requireContext) {
|
|
130
|
+
const graph = await bundler.getDependencyGraph();
|
|
131
|
+
|
|
132
|
+
// TODO: Check delta changes to avoid having to look over all files each time
|
|
133
|
+
// this is a massive performance boost.
|
|
134
|
+
|
|
135
|
+
// Search against all files, this is very expensive.
|
|
136
|
+
// TODO: Maybe we could let the user specify which root to check against.
|
|
137
|
+
const files = graph.matchFilesWithContext(requireContext.from, {
|
|
138
|
+
filter: requireContext.filter,
|
|
139
|
+
recursive: requireContext.recursive,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const template = getContextModuleTemplate(
|
|
143
|
+
requireContext.mode,
|
|
144
|
+
requireContext.from,
|
|
145
|
+
files,
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
templateBuffer = Buffer.from(template);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return await bundler.transformFile(
|
|
152
|
+
modulePath,
|
|
153
|
+
{
|
|
154
|
+
...transformOptions,
|
|
155
|
+
type: getType(
|
|
156
|
+
transformOptions.type,
|
|
157
|
+
modulePath,
|
|
158
|
+
config.resolver.assetExts,
|
|
159
|
+
),
|
|
160
|
+
inlineRequires: removeInlineRequiresBlockListFromOptions(
|
|
161
|
+
modulePath,
|
|
162
|
+
inlineRequires,
|
|
163
|
+
),
|
|
164
|
+
},
|
|
165
|
+
templateBuffer,
|
|
166
|
+
);
|
|
130
167
|
};
|
|
131
168
|
}
|
|
132
169
|
|
|
@@ -94,7 +94,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
_getEmptyModule() {
|
|
97
|
+
_getEmptyModule(): TModule | Moduleish {
|
|
98
98
|
let emptyModule = this._cachedEmptyModule;
|
|
99
99
|
if (!emptyModule) {
|
|
100
100
|
emptyModule = this.resolveDependency(
|
|
@@ -252,6 +252,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
|
252
252
|
invariant(arbitrary != null, 'invalid asset resolution');
|
|
253
253
|
return this._options.moduleCache.getModule(arbitrary);
|
|
254
254
|
case 'empty':
|
|
255
|
+
// $FlowFixMe[incompatible-return]
|
|
255
256
|
return this._getEmptyModule();
|
|
256
257
|
default:
|
|
257
258
|
(resolution.type: empty);
|
|
@@ -259,7 +260,7 @@ class ModuleResolver<TModule: Moduleish, TPackage: Packageish> {
|
|
|
259
260
|
}
|
|
260
261
|
}
|
|
261
262
|
|
|
262
|
-
_removeRoot(candidates: FileCandidates) {
|
|
263
|
+
_removeRoot(candidates: FileCandidates): FileCandidates {
|
|
263
264
|
if (candidates.filePathPrefix) {
|
|
264
265
|
candidates.filePathPrefix = path.relative(
|
|
265
266
|
this._options.projectRoot,
|
|
@@ -129,7 +129,13 @@ function createHasteMap(config, options) {
|
|
|
129
129
|
computeDependencies,
|
|
130
130
|
computeSha1: true,
|
|
131
131
|
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
132
|
-
extensions:
|
|
132
|
+
extensions: Array.from(
|
|
133
|
+
new Set([
|
|
134
|
+
...config.resolver.sourceExts,
|
|
135
|
+
...config.resolver.assetExts,
|
|
136
|
+
...config.watcher.additionalExts,
|
|
137
|
+
])
|
|
138
|
+
),
|
|
133
139
|
forceNodeFilesystemAPI: !config.resolver.useWatchman,
|
|
134
140
|
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
135
141
|
ignorePattern: getIgnorePattern(config),
|
|
@@ -25,7 +25,7 @@ function getIgnorePattern(config: ConfigT): RegExp {
|
|
|
25
25
|
return / ^/;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const combine = regexes =>
|
|
28
|
+
const combine = (regexes: Array<RegExp>) =>
|
|
29
29
|
new RegExp(
|
|
30
30
|
regexes
|
|
31
31
|
.map(regex => '(' + regex.source.replace(/\//g, path.sep) + ')')
|
|
@@ -69,7 +69,13 @@ function createHasteMap(
|
|
|
69
69
|
computeDependencies,
|
|
70
70
|
computeSha1: true,
|
|
71
71
|
dependencyExtractor: config.resolver.dependencyExtractor,
|
|
72
|
-
extensions:
|
|
72
|
+
extensions: Array.from(
|
|
73
|
+
new Set([
|
|
74
|
+
...config.resolver.sourceExts,
|
|
75
|
+
...config.resolver.assetExts,
|
|
76
|
+
...config.watcher.additionalExts,
|
|
77
|
+
]),
|
|
78
|
+
),
|
|
73
79
|
forceNodeFilesystemAPI: !config.resolver.useWatchman,
|
|
74
80
|
hasteImplModulePath: config.resolver.hasteImplModulePath,
|
|
75
81
|
ignorePattern: getIgnorePattern(config),
|
|
@@ -115,6 +115,8 @@ class DependencyGraph extends EventEmitter {
|
|
|
115
115
|
|
|
116
116
|
return null;
|
|
117
117
|
}
|
|
118
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
119
|
+
* LTI update could not be added via codemod */
|
|
118
120
|
|
|
119
121
|
_onHasteChange({ eventsQueue, hasteFS, moduleMap }) {
|
|
120
122
|
this._hasteFS = hasteFS;
|
|
@@ -206,6 +208,11 @@ class DependencyGraph extends EventEmitter {
|
|
|
206
208
|
end() {
|
|
207
209
|
this._haste.end();
|
|
208
210
|
}
|
|
211
|
+
/** Given a search context, return a list of file paths matching the query. */
|
|
212
|
+
|
|
213
|
+
matchFilesWithContext(from, context) {
|
|
214
|
+
return this._hasteFS.matchFilesWithContext(from, context);
|
|
215
|
+
}
|
|
209
216
|
|
|
210
217
|
resolveDependency(
|
|
211
218
|
from,
|
|
@@ -33,7 +33,7 @@ const {DuplicateHasteCandidatesError} = MetroFileMapModuleMap;
|
|
|
33
33
|
|
|
34
34
|
function getOrCreate<T>(
|
|
35
35
|
map: Map<string, Map<string, T>>,
|
|
36
|
-
field,
|
|
36
|
+
field: string,
|
|
37
37
|
): Map<string, T> {
|
|
38
38
|
let subMap = map.get(field);
|
|
39
39
|
if (!subMap) {
|
|
@@ -131,6 +131,8 @@ class DependencyGraph extends EventEmitter {
|
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
135
|
+
* LTI update could not be added via codemod */
|
|
134
136
|
_onHasteChange({eventsQueue, hasteFS, moduleMap}) {
|
|
135
137
|
this._hasteFS = hasteFS;
|
|
136
138
|
this._resolutionCache = new Map();
|
|
@@ -177,7 +179,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
177
179
|
});
|
|
178
180
|
}
|
|
179
181
|
|
|
180
|
-
_createModuleCache() {
|
|
182
|
+
_createModuleCache(): ModuleCache {
|
|
181
183
|
return new ModuleCache({
|
|
182
184
|
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
183
185
|
getClosestPackage: this._getClosestPackage.bind(this),
|
|
@@ -223,6 +225,19 @@ class DependencyGraph extends EventEmitter {
|
|
|
223
225
|
this._haste.end();
|
|
224
226
|
}
|
|
225
227
|
|
|
228
|
+
/** Given a search context, return a list of file paths matching the query. */
|
|
229
|
+
matchFilesWithContext(
|
|
230
|
+
from: string,
|
|
231
|
+
context: $ReadOnly<{
|
|
232
|
+
/* Should search for files recursively. */
|
|
233
|
+
recursive: boolean,
|
|
234
|
+
/* Filter relative paths against a pattern. */
|
|
235
|
+
filter: RegExp,
|
|
236
|
+
}>,
|
|
237
|
+
): string[] {
|
|
238
|
+
return this._hasteFS.matchFilesWithContext(from, context);
|
|
239
|
+
}
|
|
240
|
+
|
|
226
241
|
resolveDependency(
|
|
227
242
|
from: string,
|
|
228
243
|
to: string,
|
|
@@ -0,0 +1,67 @@
|
|
|
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 relativizeSourceMapInline = require("../../lib/relativizeSourceMap");
|
|
13
|
+
|
|
14
|
+
const Server = require("../../Server");
|
|
15
|
+
|
|
16
|
+
const writeFile = require("./writeFile");
|
|
17
|
+
|
|
18
|
+
function buildBundle(packagerClient, requestOptions) {
|
|
19
|
+
return packagerClient.build({
|
|
20
|
+
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
21
|
+
...requestOptions,
|
|
22
|
+
bundleType: "bundle",
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function relativateSerializedMap(map, sourceMapSourcesRoot) {
|
|
27
|
+
const sourceMap = JSON.parse(map);
|
|
28
|
+
relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
|
|
29
|
+
return JSON.stringify(sourceMap);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function saveBundleAndMap(bundle, options, log) {
|
|
33
|
+
const {
|
|
34
|
+
bundleOutput,
|
|
35
|
+
bundleEncoding: encoding,
|
|
36
|
+
sourcemapOutput,
|
|
37
|
+
sourcemapSourcesRoot,
|
|
38
|
+
} = options;
|
|
39
|
+
const writeFns = [];
|
|
40
|
+
writeFns.push(async () => {
|
|
41
|
+
log("Writing bundle output to:", bundleOutput);
|
|
42
|
+
await writeFile(bundleOutput, bundle.code, encoding);
|
|
43
|
+
log("Done writing bundle output");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (sourcemapOutput) {
|
|
47
|
+
let { map } = bundle;
|
|
48
|
+
|
|
49
|
+
if (sourcemapSourcesRoot !== undefined) {
|
|
50
|
+
log("start relativating source map");
|
|
51
|
+
map = relativateSerializedMap(map, sourcemapSourcesRoot);
|
|
52
|
+
log("finished relativating");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
writeFns.push(async () => {
|
|
56
|
+
log("Writing sourcemap output to:", sourcemapOutput);
|
|
57
|
+
await writeFile(sourcemapOutput, map, null);
|
|
58
|
+
log("Done writing sourcemap output");
|
|
59
|
+
});
|
|
60
|
+
} // Wait until everything is written to disk.
|
|
61
|
+
|
|
62
|
+
await Promise.all(writeFns.map((cb) => cb()));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.build = buildBundle;
|
|
66
|
+
exports.save = saveBundleAndMap;
|
|
67
|
+
exports.formatName = "bundle";
|
|
@@ -0,0 +1,89 @@
|
|
|
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 {OutputOptions, RequestOptions} from '../types.flow';
|
|
14
|
+
import type {MixedSourceMap} from 'metro-source-map';
|
|
15
|
+
|
|
16
|
+
const relativizeSourceMapInline = require('../../lib/relativizeSourceMap');
|
|
17
|
+
const Server = require('../../Server');
|
|
18
|
+
const writeFile = require('./writeFile');
|
|
19
|
+
|
|
20
|
+
function buildBundle(
|
|
21
|
+
packagerClient: Server,
|
|
22
|
+
requestOptions: RequestOptions,
|
|
23
|
+
): Promise<{
|
|
24
|
+
code: string,
|
|
25
|
+
map: string,
|
|
26
|
+
...
|
|
27
|
+
}> {
|
|
28
|
+
return packagerClient.build({
|
|
29
|
+
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
30
|
+
...requestOptions,
|
|
31
|
+
bundleType: 'bundle',
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function relativateSerializedMap(
|
|
36
|
+
map: string,
|
|
37
|
+
sourceMapSourcesRoot: string,
|
|
38
|
+
): string {
|
|
39
|
+
const sourceMap = (JSON.parse(map): MixedSourceMap);
|
|
40
|
+
relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
|
|
41
|
+
return JSON.stringify(sourceMap);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function saveBundleAndMap(
|
|
45
|
+
bundle: {
|
|
46
|
+
code: string,
|
|
47
|
+
map: string,
|
|
48
|
+
...
|
|
49
|
+
},
|
|
50
|
+
options: OutputOptions,
|
|
51
|
+
log: (...args: Array<string>) => void,
|
|
52
|
+
): Promise<mixed> {
|
|
53
|
+
const {
|
|
54
|
+
bundleOutput,
|
|
55
|
+
bundleEncoding: encoding,
|
|
56
|
+
sourcemapOutput,
|
|
57
|
+
sourcemapSourcesRoot,
|
|
58
|
+
} = options;
|
|
59
|
+
|
|
60
|
+
const writeFns = [];
|
|
61
|
+
|
|
62
|
+
writeFns.push(async () => {
|
|
63
|
+
log('Writing bundle output to:', bundleOutput);
|
|
64
|
+
await writeFile(bundleOutput, bundle.code, encoding);
|
|
65
|
+
log('Done writing bundle output');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (sourcemapOutput) {
|
|
69
|
+
let {map} = bundle;
|
|
70
|
+
if (sourcemapSourcesRoot !== undefined) {
|
|
71
|
+
log('start relativating source map');
|
|
72
|
+
map = relativateSerializedMap(map, sourcemapSourcesRoot);
|
|
73
|
+
log('finished relativating');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
writeFns.push(async () => {
|
|
77
|
+
log('Writing sourcemap output to:', sourcemapOutput);
|
|
78
|
+
await writeFile(sourcemapOutput, map, null);
|
|
79
|
+
log('Done writing sourcemap output');
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Wait until everything is written to disk.
|
|
84
|
+
await Promise.all(writeFns.map((cb: void => mixed) => cb()));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.build = buildBundle;
|
|
88
|
+
exports.save = saveBundleAndMap;
|
|
89
|
+
exports.formatName = 'bundle';
|
|
@@ -8,60 +8,13 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
|
+
/*::
|
|
12
|
+
export type * from './bundle.flow';
|
|
13
|
+
*/
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
try {
|
|
16
|
+
// $FlowFixMe[untyped-import]
|
|
17
|
+
require("metro-babel-register").unstable_registerForMetroMonorepo();
|
|
18
|
+
} catch {}
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const writeFile = require("./writeFile");
|
|
17
|
-
|
|
18
|
-
function buildBundle(packagerClient, requestOptions) {
|
|
19
|
-
return packagerClient.build({
|
|
20
|
-
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
21
|
-
...requestOptions,
|
|
22
|
-
bundleType: "bundle",
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function relativateSerializedMap(map, sourceMapSourcesRoot) {
|
|
27
|
-
const sourceMap = JSON.parse(map);
|
|
28
|
-
relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
|
|
29
|
-
return JSON.stringify(sourceMap);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function saveBundleAndMap(bundle, options, log) {
|
|
33
|
-
const {
|
|
34
|
-
bundleOutput,
|
|
35
|
-
bundleEncoding: encoding,
|
|
36
|
-
sourcemapOutput,
|
|
37
|
-
sourcemapSourcesRoot,
|
|
38
|
-
} = options;
|
|
39
|
-
const writeFns = [];
|
|
40
|
-
writeFns.push(async () => {
|
|
41
|
-
log("Writing bundle output to:", bundleOutput);
|
|
42
|
-
await writeFile(bundleOutput, bundle.code, encoding);
|
|
43
|
-
log("Done writing bundle output");
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
if (sourcemapOutput) {
|
|
47
|
-
let { map } = bundle;
|
|
48
|
-
|
|
49
|
-
if (sourcemapSourcesRoot !== undefined) {
|
|
50
|
-
log("start relativating source map");
|
|
51
|
-
map = relativateSerializedMap(map, sourcemapSourcesRoot);
|
|
52
|
-
log("finished relativating");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
writeFns.push(async () => {
|
|
56
|
-
log("Writing sourcemap output to:", sourcemapOutput);
|
|
57
|
-
await writeFile(sourcemapOutput, map, null);
|
|
58
|
-
log("Done writing sourcemap output");
|
|
59
|
-
});
|
|
60
|
-
} // Wait until everything is written to disk.
|
|
61
|
-
|
|
62
|
-
await Promise.all(writeFns.map((cb) => cb()));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
exports.build = buildBundle;
|
|
66
|
-
exports.save = saveBundleAndMap;
|
|
67
|
-
exports.formatName = "bundle";
|
|
20
|
+
module.exports = require("./bundle.flow");
|
|
@@ -10,80 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/*::
|
|
14
|
+
export type * from './bundle.flow';
|
|
15
|
+
*/
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
try {
|
|
18
|
+
// $FlowFixMe[untyped-import]
|
|
19
|
+
require('metro-babel-register').unstable_registerForMetroMonorepo();
|
|
20
|
+
} catch {}
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
packagerClient: Server,
|
|
22
|
-
requestOptions: RequestOptions,
|
|
23
|
-
): Promise<{
|
|
24
|
-
code: string,
|
|
25
|
-
map: string,
|
|
26
|
-
...
|
|
27
|
-
}> {
|
|
28
|
-
return packagerClient.build({
|
|
29
|
-
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
30
|
-
...requestOptions,
|
|
31
|
-
bundleType: 'bundle',
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function relativateSerializedMap(
|
|
36
|
-
map: string,
|
|
37
|
-
sourceMapSourcesRoot: string,
|
|
38
|
-
): string {
|
|
39
|
-
const sourceMap = (JSON.parse(map): MixedSourceMap);
|
|
40
|
-
relativizeSourceMapInline(sourceMap, sourceMapSourcesRoot);
|
|
41
|
-
return JSON.stringify(sourceMap);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function saveBundleAndMap(
|
|
45
|
-
bundle: {
|
|
46
|
-
code: string,
|
|
47
|
-
map: string,
|
|
48
|
-
...
|
|
49
|
-
},
|
|
50
|
-
options: OutputOptions,
|
|
51
|
-
log: (...args: Array<string>) => void,
|
|
52
|
-
): Promise<mixed> {
|
|
53
|
-
const {
|
|
54
|
-
bundleOutput,
|
|
55
|
-
bundleEncoding: encoding,
|
|
56
|
-
sourcemapOutput,
|
|
57
|
-
sourcemapSourcesRoot,
|
|
58
|
-
} = options;
|
|
59
|
-
|
|
60
|
-
const writeFns = [];
|
|
61
|
-
|
|
62
|
-
writeFns.push(async () => {
|
|
63
|
-
log('Writing bundle output to:', bundleOutput);
|
|
64
|
-
await writeFile(bundleOutput, bundle.code, encoding);
|
|
65
|
-
log('Done writing bundle output');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
if (sourcemapOutput) {
|
|
69
|
-
let {map} = bundle;
|
|
70
|
-
if (sourcemapSourcesRoot !== undefined) {
|
|
71
|
-
log('start relativating source map');
|
|
72
|
-
map = relativateSerializedMap(map, sourcemapSourcesRoot);
|
|
73
|
-
log('finished relativating');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
writeFns.push(async () => {
|
|
77
|
-
log('Writing sourcemap output to:', sourcemapOutput);
|
|
78
|
-
await writeFile(sourcemapOutput, map, null);
|
|
79
|
-
log('Done writing sourcemap output');
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Wait until everything is written to disk.
|
|
84
|
-
await Promise.all(writeFns.map((cb: void => mixed) => cb()));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
exports.build = buildBundle;
|
|
88
|
-
exports.save = saveBundleAndMap;
|
|
89
|
-
exports.formatName = 'bundle';
|
|
22
|
+
module.exports = require('./bundle.flow');
|