metro 0.83.0 → 0.83.2
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 +16 -16
- package/src/Assets.js +68 -42
- package/src/Assets.js.flow +13 -24
- package/src/Bundler/util.js +40 -17
- package/src/Bundler/util.js.flow +6 -13
- package/src/Bundler.js +17 -6
- package/src/Bundler.js.flow +3 -7
- package/src/DeltaBundler/DeltaCalculator.js +15 -15
- package/src/DeltaBundler/DeltaCalculator.js.flow +4 -7
- package/src/DeltaBundler/Graph.js +45 -40
- package/src/DeltaBundler/Graph.js.flow +3 -4
- package/src/DeltaBundler/Serializers/baseJSBundle.js +24 -10
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +6 -9
- package/src/DeltaBundler/Serializers/getAllFiles.js +9 -6
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +4 -8
- package/src/DeltaBundler/Serializers/getAssets.js +18 -11
- package/src/DeltaBundler/Serializers/getAssets.js.flow +5 -9
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +26 -0
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +7 -6
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +3 -9
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +40 -23
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +11 -18
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +4 -1
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -5
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +7 -4
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +3 -7
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +4 -1
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +2 -6
- package/src/DeltaBundler/Serializers/helpers/js.js +65 -31
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +21 -21
- package/src/DeltaBundler/Serializers/helpers/processModules.js +8 -5
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -7
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +70 -25
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +43 -33
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +19 -16
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -14
- package/src/DeltaBundler/Serializers/sourceMapObject.js +12 -10
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -9
- package/src/DeltaBundler/Serializers/sourceMapString.js +14 -12
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +4 -9
- package/src/DeltaBundler/Transformer.js +32 -27
- package/src/DeltaBundler/Transformer.js.flow +10 -17
- package/src/DeltaBundler/Worker.flow.js +25 -18
- package/src/DeltaBundler/Worker.flow.js.flow +12 -18
- package/src/DeltaBundler/Worker.js.flow +2 -0
- package/src/DeltaBundler/WorkerFarm.js +13 -11
- package/src/DeltaBundler/WorkerFarm.js.flow +7 -9
- package/src/DeltaBundler/buildSubgraph.js +13 -17
- package/src/DeltaBundler/buildSubgraph.js.flow +1 -1
- package/src/DeltaBundler/getTransformCacheKey.js +12 -6
- package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -7
- package/src/DeltaBundler/mergeDeltas.js +4 -1
- package/src/DeltaBundler/mergeDeltas.js.flow +5 -6
- package/src/DeltaBundler/types.d.ts +4 -1
- package/src/DeltaBundler/{types.flow.js → types.js} +1 -5
- package/src/DeltaBundler/{types.flow.js.flow → types.js.flow} +5 -3
- package/src/DeltaBundler.js +15 -6
- package/src/DeltaBundler.js.flow +4 -8
- package/src/HmrServer.js +116 -68
- package/src/HmrServer.js.flow +41 -52
- package/src/IncrementalBundler/GraphNotFoundError.js +5 -1
- package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler/ResourceNotFoundError.js +5 -1
- package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler/RevisionNotFoundError.js +5 -1
- package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -5
- package/src/IncrementalBundler.js +71 -35
- package/src/IncrementalBundler.js.flow +12 -16
- package/src/ModuleGraph/test-helpers.js +19 -14
- package/src/ModuleGraph/worker/JsFileWrapping.js +22 -29
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +1 -10
- package/src/ModuleGraph/worker/collectDependencies.js +81 -52
- package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -22
- package/src/ModuleGraph/worker/generateImportNames.js +12 -6
- package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -7
- package/src/ModuleGraph/worker/importLocationsPlugin.js +5 -4
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +2 -4
- package/src/Server/MultipartResponse.js +11 -4
- package/src/Server/MultipartResponse.js.flow +2 -5
- package/src/Server/symbolicate.d.ts +31 -0
- package/src/Server/symbolicate.js +15 -16
- package/src/Server/symbolicate.js.flow +6 -16
- package/src/Server.d.ts +0 -1
- package/src/Server.js +298 -191
- package/src/Server.js.flow +136 -99
- package/src/cli-utils.js +13 -4
- package/src/cli-utils.js.flow +3 -5
- package/src/cli.js.flow +2 -0
- package/src/commands/build.js +18 -15
- package/src/commands/build.js.flow +6 -6
- package/src/commands/dependencies.js +26 -16
- package/src/commands/dependencies.js.flow +7 -9
- package/src/commands/serve.js +16 -11
- package/src/commands/serve.js.flow +5 -6
- package/src/index.d.ts +26 -3
- package/src/index.flow.js +162 -72
- package/src/index.flow.js.flow +60 -47
- package/src/index.js.flow +2 -0
- package/src/integration_tests/basic_bundle/TestBundle.js.flow +2 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +1 -5
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +1 -5
- package/src/integration_tests/basic_bundle/import-export/index.js +5 -13
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +2 -2
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js +1 -1
- package/src/integration_tests/basic_bundle/require-context/utils.js +1 -1
- package/src/integration_tests/execBundle.js +7 -4
- package/src/integration_tests/execBundle.js.flow +1 -3
- package/src/integration_tests/metro.config.js +3 -3
- package/src/lib/BatchProcessor.js +15 -5
- package/src/lib/BatchProcessor.js.flow +2 -6
- package/src/lib/CountingSet.js.flow +2 -2
- package/src/lib/JsonReporter.js +6 -2
- package/src/lib/JsonReporter.js.flow +1 -5
- package/src/lib/RamBundleParser.js +12 -3
- package/src/lib/RamBundleParser.js.flow +2 -6
- package/src/lib/TerminalReporter.js +95 -56
- package/src/lib/TerminalReporter.js.flow +9 -12
- package/src/lib/bundleToString.js +4 -1
- package/src/lib/bundleToString.js.flow +2 -9
- package/src/lib/contextModule.js +3 -7
- package/src/lib/contextModuleTemplates.js +9 -19
- package/src/lib/countLines.js +5 -1
- package/src/lib/countLines.js.flow +1 -3
- package/src/lib/createWebsocketServer.js +7 -7
- package/src/lib/createWebsocketServer.js.flow +4 -4
- package/src/lib/debounceAsyncQueue.js +4 -1
- package/src/lib/debounceAsyncQueue.js.flow +1 -5
- package/src/lib/formatBundlingError.js +32 -22
- package/src/lib/formatBundlingError.js.flow +18 -20
- package/src/lib/getAppendScripts.js +20 -20
- package/src/lib/getAppendScripts.js.flow +9 -13
- package/src/lib/getGraphId.js +12 -6
- package/src/lib/getGraphId.js.flow +4 -10
- package/src/lib/getPreludeCode.js +7 -10
- package/src/lib/getPreludeCode.js.flow +2 -6
- package/src/lib/getPrependedScripts.js +40 -16
- package/src/lib/getPrependedScripts.js.flow +8 -13
- package/src/lib/isResolvedDependency.js.flow +1 -1
- package/src/lib/logToConsole.js +18 -12
- package/src/lib/logToConsole.js.flow +5 -14
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +144 -0
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js.flow +146 -0
- package/src/lib/parseCustomResolverOptions.js +8 -6
- package/src/lib/parseCustomResolverOptions.js.flow +6 -12
- package/src/lib/parseCustomTransformOptions.js +8 -6
- package/src/lib/parseCustomTransformOptions.js.flow +11 -14
- package/src/lib/parseJsonBody.js +4 -1
- package/src/lib/parseJsonBody.js.flow +1 -3
- package/src/lib/pathUtils.js +34 -0
- package/src/lib/pathUtils.js.flow +16 -0
- package/src/lib/relativizeSourceMap.js +12 -3
- package/src/lib/relativizeSourceMap.js.flow +2 -6
- package/src/lib/reporting.js +25 -19
- package/src/lib/reporting.js.flow +6 -16
- package/src/lib/splitBundleOptions.js +4 -2
- package/src/lib/splitBundleOptions.js.flow +4 -7
- package/src/lib/transformHelpers.js +19 -25
- package/src/lib/transformHelpers.js.flow +5 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.js +75 -57
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +28 -44
- package/src/node-haste/DependencyGraph/createFileMap.js +15 -13
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +2 -5
- package/src/node-haste/DependencyGraph.js +61 -45
- package/src/node-haste/DependencyGraph.js.flow +34 -31
- package/src/node-haste/Package.js +13 -6
- package/src/node-haste/Package.js.flow +3 -7
- package/src/node-haste/{ModuleCache.js → PackageCache.js} +11 -19
- package/src/node-haste/{ModuleCache.js.flow → PackageCache.js.flow} +2 -30
- package/src/node-haste/lib/AssetPaths.js +14 -8
- package/src/node-haste/lib/AssetPaths.js.flow +7 -8
- package/src/node-haste/lib/parsePlatformFilePath.js +10 -4
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -6
- package/src/shared/output/RamBundle/as-assets.js +42 -22
- package/src/shared/output/RamBundle/as-assets.js.flow +12 -15
- package/src/shared/output/RamBundle/as-indexed-file.js +33 -23
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +10 -16
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +11 -10
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -6
- package/src/shared/output/RamBundle/magic-number.js +5 -1
- package/src/shared/output/RamBundle/magic-number.js.flow +1 -3
- package/src/shared/output/RamBundle/util.js +21 -18
- package/src/shared/output/RamBundle/util.js.flow +4 -6
- package/src/shared/output/RamBundle/write-sourcemap.js +9 -3
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +2 -6
- package/src/shared/output/RamBundle.js +16 -9
- package/src/shared/output/RamBundle.js.flow +8 -12
- package/src/shared/output/bundle.flow.js +37 -13
- package/src/shared/output/bundle.flow.js.flow +24 -12
- package/src/shared/output/bundle.js.flow +2 -0
- package/src/shared/output/meta.js +16 -9
- package/src/shared/output/meta.js.flow +3 -5
- package/src/shared/output/unbundle.js +14 -1
- package/src/shared/output/unbundle.js.flow +1 -3
- package/src/shared/output/writeFile.js +11 -4
- package/src/shared/output/writeFile.js.flow +3 -5
- package/src/shared/types.d.ts +0 -1
- package/src/shared/{types.flow.js.flow → types.js.flow} +16 -17
- package/src/lib/createModuleIdFactory.js +0 -15
- package/src/lib/createModuleIdFactory.js.flow +0 -27
- package/src/lib/getMaxWorkers.js +0 -9
- package/src/lib/getMaxWorkers.js.flow +0 -22
- package/src/lib/parseOptionsFromUrl.js +0 -62
- package/src/lib/parseOptionsFromUrl.js.flow +0 -97
- package/src/node-haste/Module.js +0 -24
- package/src/node-haste/Module.js.flow +0 -41
- /package/src/shared/{types.flow.js → types.js} +0 -0
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
import type {
|
|
13
13
|
BundlerResolution,
|
|
14
14
|
TransformResultDependency,
|
|
15
|
-
} from '../DeltaBundler/types
|
|
16
|
-
import type {ResolverInputOptions} from '../shared/types
|
|
15
|
+
} from '../DeltaBundler/types';
|
|
16
|
+
import type {ResolverInputOptions} from '../shared/types';
|
|
17
17
|
import type Package from './Package';
|
|
18
18
|
import type {ConfigT} from 'metro-config';
|
|
19
19
|
import type MetroFileMap, {
|
|
@@ -25,22 +25,23 @@ import type MetroFileMap, {
|
|
|
25
25
|
} from 'metro-file-map';
|
|
26
26
|
import type {FileSystemLookup} from 'metro-resolver';
|
|
27
27
|
|
|
28
|
-
import
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const fs = require('fs');
|
|
35
|
-
const {
|
|
28
|
+
import createFileMap from './DependencyGraph/createFileMap';
|
|
29
|
+
import {ModuleResolver} from './DependencyGraph/ModuleResolution';
|
|
30
|
+
import {PackageCache} from './PackageCache';
|
|
31
|
+
import EventEmitter from 'events';
|
|
32
|
+
import fs from 'fs';
|
|
33
|
+
import {
|
|
36
34
|
AmbiguousModuleResolutionError,
|
|
37
|
-
Logger
|
|
35
|
+
Logger,
|
|
38
36
|
PackageResolutionError,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
} from 'metro-core';
|
|
38
|
+
import canonicalize from 'metro-core/private/canonicalize';
|
|
39
|
+
import {DuplicateHasteCandidatesError} from 'metro-file-map';
|
|
40
|
+
import {InvalidPackageError} from 'metro-resolver';
|
|
41
|
+
import nullthrows from 'nullthrows';
|
|
42
|
+
import path from 'path';
|
|
43
|
+
|
|
44
|
+
const {createActionStartEntry, createActionEndEntry, log} = Logger;
|
|
44
45
|
|
|
45
46
|
const NULL_PLATFORM = Symbol();
|
|
46
47
|
|
|
@@ -56,11 +57,11 @@ function getOrCreateMap<T>(
|
|
|
56
57
|
return subMap;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
class DependencyGraph extends EventEmitter {
|
|
60
|
+
export default class DependencyGraph extends EventEmitter {
|
|
60
61
|
_config: ConfigT;
|
|
61
62
|
_haste: MetroFileMap;
|
|
62
63
|
_fileSystem: FileSystem;
|
|
63
|
-
|
|
64
|
+
#packageCache: PackageCache;
|
|
64
65
|
_hasteMap: HasteMap;
|
|
65
66
|
_moduleResolver: ModuleResolver<Package>;
|
|
66
67
|
_resolutionCache: Map<
|
|
@@ -130,7 +131,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
130
131
|
this._onWatcherHealthCheck(result),
|
|
131
132
|
);
|
|
132
133
|
this._resolutionCache = new Map();
|
|
133
|
-
this
|
|
134
|
+
this.#packageCache = this._createPackageCache();
|
|
134
135
|
this._createModuleResolver();
|
|
135
136
|
});
|
|
136
137
|
}
|
|
@@ -162,7 +163,9 @@ class DependencyGraph extends EventEmitter {
|
|
|
162
163
|
|
|
163
164
|
_onHasteChange({eventsQueue}: ChangeEvent) {
|
|
164
165
|
this._resolutionCache = new Map();
|
|
165
|
-
eventsQueue.forEach(({filePath}) =>
|
|
166
|
+
eventsQueue.forEach(({filePath}) =>
|
|
167
|
+
this.#packageCache.invalidate(filePath),
|
|
168
|
+
);
|
|
166
169
|
this._createModuleResolver();
|
|
167
170
|
this.emit('change');
|
|
168
171
|
}
|
|
@@ -199,8 +202,8 @@ class DependencyGraph extends EventEmitter {
|
|
|
199
202
|
getHastePackagePath: (name, platform) =>
|
|
200
203
|
this._hasteMap.getPackage(name, platform, true),
|
|
201
204
|
mainFields: this._config.resolver.resolverMainFields,
|
|
202
|
-
moduleCache: this._moduleCache,
|
|
203
205
|
nodeModulesPaths: this._config.resolver.nodeModulesPaths,
|
|
206
|
+
packageCache: this.#packageCache,
|
|
204
207
|
preferNativePlatform: true,
|
|
205
208
|
projectRoot: this._config.projectRoot,
|
|
206
209
|
reporter: this._config.reporter,
|
|
@@ -247,8 +250,8 @@ class DependencyGraph extends EventEmitter {
|
|
|
247
250
|
: null;
|
|
248
251
|
}
|
|
249
252
|
|
|
250
|
-
|
|
251
|
-
return new
|
|
253
|
+
_createPackageCache(): PackageCache {
|
|
254
|
+
return new PackageCache({
|
|
252
255
|
getClosestPackage: absolutePath => this._getClosestPackage(absolutePath),
|
|
253
256
|
});
|
|
254
257
|
}
|
|
@@ -304,7 +307,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
304
307
|
}
|
|
305
308
|
|
|
306
309
|
resolveDependency(
|
|
307
|
-
|
|
310
|
+
originModulePath: string,
|
|
308
311
|
dependency: TransformResultDependency,
|
|
309
312
|
platform: string | null,
|
|
310
313
|
resolverOptions: ResolverInputOptions,
|
|
@@ -323,12 +326,14 @@ class DependencyGraph extends EventEmitter {
|
|
|
323
326
|
to === '.' ||
|
|
324
327
|
to === '..' ||
|
|
325
328
|
// Preserve standard assumptions under node_modules
|
|
326
|
-
|
|
329
|
+
originModulePath.includes(path.sep + 'node_modules' + path.sep);
|
|
327
330
|
|
|
328
331
|
// Compound key for the resolver cache
|
|
329
332
|
const resolverOptionsKey =
|
|
330
333
|
JSON.stringify(resolverOptions ?? {}, canonicalize) ?? '';
|
|
331
|
-
const originKey = isSensitiveToOriginFolder
|
|
334
|
+
const originKey = isSensitiveToOriginFolder
|
|
335
|
+
? path.dirname(originModulePath)
|
|
336
|
+
: '';
|
|
332
337
|
const targetKey =
|
|
333
338
|
to + (dependency.data.isESMImport === true ? '\0esm' : '\0cjs');
|
|
334
339
|
const platformKey = platform ?? NULL_PLATFORM;
|
|
@@ -346,7 +351,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
346
351
|
if (!resolution) {
|
|
347
352
|
try {
|
|
348
353
|
resolution = this._moduleResolver.resolveDependency(
|
|
349
|
-
|
|
354
|
+
originModulePath,
|
|
350
355
|
dependency,
|
|
351
356
|
true,
|
|
352
357
|
platform,
|
|
@@ -354,12 +359,12 @@ class DependencyGraph extends EventEmitter {
|
|
|
354
359
|
);
|
|
355
360
|
} catch (error) {
|
|
356
361
|
if (error instanceof DuplicateHasteCandidatesError) {
|
|
357
|
-
throw new AmbiguousModuleResolutionError(
|
|
362
|
+
throw new AmbiguousModuleResolutionError(originModulePath, error);
|
|
358
363
|
}
|
|
359
364
|
if (error instanceof InvalidPackageError) {
|
|
360
365
|
throw new PackageResolutionError({
|
|
361
366
|
packageError: error,
|
|
362
|
-
originModulePath
|
|
367
|
+
originModulePath,
|
|
363
368
|
targetModuleName: to,
|
|
364
369
|
});
|
|
365
370
|
}
|
|
@@ -389,5 +394,3 @@ class DependencyGraph extends EventEmitter {
|
|
|
389
394
|
return nullthrows(this._fileSystem.getDependencies(filePath));
|
|
390
395
|
}
|
|
391
396
|
}
|
|
392
|
-
|
|
393
|
-
module.exports = DependencyGraph;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
function _interopRequireDefault(e) {
|
|
10
|
+
return e && e.__esModule ? e : { default: e };
|
|
11
|
+
}
|
|
5
12
|
class Package {
|
|
6
13
|
constructor({ file }) {
|
|
7
|
-
this.path =
|
|
8
|
-
this._root =
|
|
14
|
+
this.path = _path.default.resolve(file);
|
|
15
|
+
this._root = _path.default.dirname(this.path);
|
|
9
16
|
this._content = null;
|
|
10
17
|
}
|
|
11
18
|
invalidate() {
|
|
@@ -13,9 +20,9 @@ class Package {
|
|
|
13
20
|
}
|
|
14
21
|
read() {
|
|
15
22
|
if (this._content == null) {
|
|
16
|
-
this._content = JSON.parse(
|
|
23
|
+
this._content = JSON.parse(_fs.default.readFileSync(this.path, "utf8"));
|
|
17
24
|
}
|
|
18
25
|
return this._content;
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
|
-
|
|
28
|
+
exports.default = Package;
|
|
@@ -9,14 +9,12 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
12
|
import type {PackageJson} from 'metro-resolver/private/types';
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
import fs from 'fs';
|
|
15
|
+
import path from 'path';
|
|
18
16
|
|
|
19
|
-
class Package {
|
|
17
|
+
export default class Package {
|
|
20
18
|
path: string;
|
|
21
19
|
|
|
22
20
|
_root: string;
|
|
@@ -39,5 +37,3 @@ class Package {
|
|
|
39
37
|
return this._content;
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
module.exports = Package;
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.PackageCache = void 0;
|
|
7
|
+
var _Package = _interopRequireDefault(require("./Package"));
|
|
8
|
+
function _interopRequireDefault(e) {
|
|
9
|
+
return e && e.__esModule ? e : { default: e };
|
|
10
|
+
}
|
|
11
|
+
class PackageCache {
|
|
6
12
|
constructor(options) {
|
|
7
13
|
this._getClosestPackage = options.getClosestPackage;
|
|
8
|
-
this._moduleCache = Object.create(null);
|
|
9
14
|
this._packageCache = Object.create(null);
|
|
10
15
|
this._packagePathAndSubpathByModulePath = Object.create(null);
|
|
11
16
|
this._modulePathsByPackagePath = Object.create(null);
|
|
12
17
|
}
|
|
13
|
-
getModule(filePath) {
|
|
14
|
-
if (!this._moduleCache[filePath]) {
|
|
15
|
-
this._moduleCache[filePath] = new Module(filePath, this);
|
|
16
|
-
}
|
|
17
|
-
return this._moduleCache[filePath];
|
|
18
|
-
}
|
|
19
18
|
getPackage(filePath) {
|
|
20
19
|
if (!this._packageCache[filePath]) {
|
|
21
|
-
this._packageCache[filePath] = new
|
|
20
|
+
this._packageCache[filePath] = new _Package.default({
|
|
22
21
|
file: filePath,
|
|
23
22
|
});
|
|
24
23
|
}
|
|
25
24
|
return this._packageCache[filePath];
|
|
26
25
|
}
|
|
27
|
-
getPackageForModule(module) {
|
|
28
|
-
return this.getPackageOf(module.path);
|
|
29
|
-
}
|
|
30
26
|
getPackageOf(absoluteModulePath) {
|
|
31
27
|
let packagePathAndSubpath =
|
|
32
28
|
this._packagePathAndSubpathByModulePath[absoluteModulePath];
|
|
@@ -56,10 +52,6 @@ class ModuleCache {
|
|
|
56
52
|
};
|
|
57
53
|
}
|
|
58
54
|
invalidate(filePath) {
|
|
59
|
-
if (this._moduleCache[filePath]) {
|
|
60
|
-
this._moduleCache[filePath].invalidate();
|
|
61
|
-
delete this._moduleCache[filePath];
|
|
62
|
-
}
|
|
63
55
|
if (this._packageCache[filePath]) {
|
|
64
56
|
this._packageCache[filePath].invalidate();
|
|
65
57
|
delete this._packageCache[filePath];
|
|
@@ -87,4 +79,4 @@ class ModuleCache {
|
|
|
87
79
|
}
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
|
-
|
|
82
|
+
exports.PackageCache = PackageCache;
|
|
@@ -9,23 +9,15 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const Module = require('./Module');
|
|
15
|
-
const Package = require('./Package');
|
|
12
|
+
import Package from './Package';
|
|
16
13
|
|
|
17
14
|
type GetClosestPackageFn = (absoluteFilePath: string) => ?{
|
|
18
15
|
packageJsonPath: string,
|
|
19
16
|
packageRelativePath: string,
|
|
20
17
|
};
|
|
21
18
|
|
|
22
|
-
class
|
|
19
|
+
export class PackageCache {
|
|
23
20
|
_getClosestPackage: GetClosestPackageFn;
|
|
24
|
-
_moduleCache: {
|
|
25
|
-
[filePath: string]: Module,
|
|
26
|
-
__proto__: null,
|
|
27
|
-
...
|
|
28
|
-
};
|
|
29
21
|
_packageCache: {
|
|
30
22
|
[filePath: string]: Package,
|
|
31
23
|
__proto__: null,
|
|
@@ -49,19 +41,11 @@ class ModuleCache {
|
|
|
49
41
|
|
|
50
42
|
constructor(options: {getClosestPackage: GetClosestPackageFn, ...}) {
|
|
51
43
|
this._getClosestPackage = options.getClosestPackage;
|
|
52
|
-
this._moduleCache = Object.create(null);
|
|
53
44
|
this._packageCache = Object.create(null);
|
|
54
45
|
this._packagePathAndSubpathByModulePath = Object.create(null);
|
|
55
46
|
this._modulePathsByPackagePath = Object.create(null);
|
|
56
47
|
}
|
|
57
48
|
|
|
58
|
-
getModule(filePath: string): Module {
|
|
59
|
-
if (!this._moduleCache[filePath]) {
|
|
60
|
-
this._moduleCache[filePath] = new Module(filePath, this);
|
|
61
|
-
}
|
|
62
|
-
return this._moduleCache[filePath];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
49
|
getPackage(filePath: string): Package {
|
|
66
50
|
if (!this._packageCache[filePath]) {
|
|
67
51
|
this._packageCache[filePath] = new Package({
|
|
@@ -71,12 +55,6 @@ class ModuleCache {
|
|
|
71
55
|
return this._packageCache[filePath];
|
|
72
56
|
}
|
|
73
57
|
|
|
74
|
-
getPackageForModule(
|
|
75
|
-
module: Module,
|
|
76
|
-
): ?{pkg: Package, packageRelativePath: string} {
|
|
77
|
-
return this.getPackageOf(module.path);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
58
|
getPackageOf(
|
|
81
59
|
absoluteModulePath: string,
|
|
82
60
|
): ?{pkg: Package, packageRelativePath: string} {
|
|
@@ -113,10 +91,6 @@ class ModuleCache {
|
|
|
113
91
|
}
|
|
114
92
|
|
|
115
93
|
invalidate(filePath: string) {
|
|
116
|
-
if (this._moduleCache[filePath]) {
|
|
117
|
-
this._moduleCache[filePath].invalidate();
|
|
118
|
-
delete this._moduleCache[filePath];
|
|
119
|
-
}
|
|
120
94
|
if (this._packageCache[filePath]) {
|
|
121
95
|
this._packageCache[filePath].invalidate();
|
|
122
96
|
delete this._packageCache[filePath];
|
|
@@ -149,5 +123,3 @@ class ModuleCache {
|
|
|
149
123
|
}
|
|
150
124
|
}
|
|
151
125
|
}
|
|
152
|
-
|
|
153
|
-
module.exports = ModuleCache;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.parse = parse;
|
|
7
|
+
exports.tryParse = tryParse;
|
|
8
|
+
var _parsePlatformFilePath = _interopRequireDefault(
|
|
9
|
+
require("./parsePlatformFilePath"),
|
|
10
|
+
);
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
function _interopRequireDefault(e) {
|
|
13
|
+
return e && e.__esModule ? e : { default: e };
|
|
14
|
+
}
|
|
5
15
|
const ASSET_BASE_NAME_RE = /(.+?)(@([\d.]+)x)?$/;
|
|
6
16
|
function parseBaseName(baseName) {
|
|
7
17
|
const match = baseName.match(ASSET_BASE_NAME_RE);
|
|
@@ -24,14 +34,14 @@ function parseBaseName(baseName) {
|
|
|
24
34
|
};
|
|
25
35
|
}
|
|
26
36
|
function tryParse(filePath, platforms) {
|
|
27
|
-
const result =
|
|
37
|
+
const result = (0, _parsePlatformFilePath.default)(filePath, platforms);
|
|
28
38
|
const { dirPath, baseName, platform, extension } = result;
|
|
29
39
|
if (extension == null) {
|
|
30
40
|
return null;
|
|
31
41
|
}
|
|
32
42
|
const { rootName, resolution } = parseBaseName(baseName);
|
|
33
43
|
return {
|
|
34
|
-
assetName:
|
|
44
|
+
assetName: _path.default.join(dirPath, `${rootName}.${extension}`),
|
|
35
45
|
name: rootName,
|
|
36
46
|
platform,
|
|
37
47
|
resolution,
|
|
@@ -45,7 +55,3 @@ function parse(filePath, platforms) {
|
|
|
45
55
|
}
|
|
46
56
|
return result;
|
|
47
57
|
}
|
|
48
|
-
module.exports = {
|
|
49
|
-
parse,
|
|
50
|
-
tryParse,
|
|
51
|
-
};
|
|
@@ -9,10 +9,8 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const parsePlatformFilePath = require('./parsePlatformFilePath');
|
|
15
|
-
const path = require('path');
|
|
12
|
+
import parsePlatformFilePath from './parsePlatformFilePath';
|
|
13
|
+
import path from 'path';
|
|
16
14
|
|
|
17
15
|
export type AssetPath = {
|
|
18
16
|
assetName: string,
|
|
@@ -47,7 +45,7 @@ function parseBaseName(baseName: string): {
|
|
|
47
45
|
* Return `null` if the `filePath` doesn't have a valid extension, required
|
|
48
46
|
* to describe the type of an asset.
|
|
49
47
|
*/
|
|
50
|
-
function tryParse(
|
|
48
|
+
export function tryParse(
|
|
51
49
|
filePath: string,
|
|
52
50
|
platforms: $ReadOnlySet<string>,
|
|
53
51
|
): ?AssetPath {
|
|
@@ -66,12 +64,13 @@ function tryParse(
|
|
|
66
64
|
};
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
function parse(
|
|
67
|
+
export function parse(
|
|
68
|
+
filePath: string,
|
|
69
|
+
platforms: $ReadOnlySet<string>,
|
|
70
|
+
): AssetPath {
|
|
70
71
|
const result = tryParse(filePath, platforms);
|
|
71
72
|
if (result == null) {
|
|
72
73
|
throw new Error(`invalid asset file path: ${filePath}`);
|
|
73
74
|
}
|
|
74
75
|
return result;
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
-
module.exports = {parse, tryParse};
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = parsePlatformFilePath;
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
function _interopRequireDefault(e) {
|
|
9
|
+
return e && e.__esModule ? e : { default: e };
|
|
10
|
+
}
|
|
4
11
|
const PATH_RE = /^(.+?)(\.([^.]+))?\.([^.]+)$/;
|
|
5
12
|
function parsePlatformFilePath(filePath, platforms) {
|
|
6
|
-
const dirPath =
|
|
7
|
-
const fileName =
|
|
13
|
+
const dirPath = _path.default.dirname(filePath);
|
|
14
|
+
const fileName = _path.default.basename(filePath);
|
|
8
15
|
const match = fileName.match(PATH_RE);
|
|
9
16
|
if (!match) {
|
|
10
17
|
return {
|
|
@@ -32,4 +39,3 @@ function parsePlatformFilePath(filePath, platforms) {
|
|
|
32
39
|
extension,
|
|
33
40
|
};
|
|
34
41
|
}
|
|
35
|
-
module.exports = parsePlatformFilePath;
|
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const path = require('path');
|
|
12
|
+
import path from 'path';
|
|
15
13
|
|
|
16
14
|
type PlatformFilePathParts = {
|
|
17
15
|
dirPath: string,
|
|
@@ -26,7 +24,7 @@ const PATH_RE = /^(.+?)(\.([^.]+))?\.([^.]+)$/;
|
|
|
26
24
|
* Extract the components of a file path that can have a platform specifier: Ex.
|
|
27
25
|
* `index.ios.js` is specific to the `ios` platform and has the extension `js`.
|
|
28
26
|
*/
|
|
29
|
-
function parsePlatformFilePath(
|
|
27
|
+
export default function parsePlatformFilePath(
|
|
30
28
|
filePath: string,
|
|
31
29
|
platforms: $ReadOnlySet<string>,
|
|
32
30
|
): PlatformFilePathParts {
|
|
@@ -44,5 +42,3 @@ function parsePlatformFilePath(
|
|
|
44
42
|
const baseName = `${match[1]}.${platform}`;
|
|
45
43
|
return {dirPath, baseName, platform: null, extension};
|
|
46
44
|
}
|
|
47
|
-
|
|
48
|
-
module.exports = parsePlatformFilePath;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = saveAsAssets;
|
|
7
|
+
var _relativizeSourceMap = _interopRequireDefault(
|
|
8
|
+
require("../../../lib/relativizeSourceMap"),
|
|
9
|
+
);
|
|
10
|
+
var _writeFile = _interopRequireDefault(require("../writeFile"));
|
|
11
|
+
var _buildSourcemapWithMetadata = _interopRequireDefault(
|
|
12
|
+
require("./buildSourcemapWithMetadata"),
|
|
13
|
+
);
|
|
14
|
+
var _magicNumber = _interopRequireDefault(require("./magic-number"));
|
|
15
|
+
var _util = require("./util");
|
|
16
|
+
var _writeSourcemap = _interopRequireDefault(require("./write-sourcemap"));
|
|
17
|
+
var _fs = require("fs");
|
|
18
|
+
var _path = _interopRequireDefault(require("path"));
|
|
19
|
+
function _interopRequireDefault(e) {
|
|
20
|
+
return e && e.__esModule ? e : { default: e };
|
|
21
|
+
}
|
|
11
22
|
const MAGIC_RAM_BUNDLE_FILENAME = "UNBUNDLE";
|
|
12
23
|
const MODULES_DIR = "js-modules";
|
|
13
24
|
function saveAsAssets(bundle, options, log) {
|
|
@@ -20,31 +31,34 @@ function saveAsAssets(bundle, options, log) {
|
|
|
20
31
|
log("start");
|
|
21
32
|
const { startupModules, lazyModules } = bundle;
|
|
22
33
|
log("finish");
|
|
23
|
-
const startupCode = joinModules(startupModules);
|
|
34
|
+
const startupCode = (0, _util.joinModules)(startupModules);
|
|
24
35
|
log("Writing bundle output to:", bundleOutput);
|
|
25
|
-
const modulesDir =
|
|
36
|
+
const modulesDir = _path.default.join(
|
|
37
|
+
_path.default.dirname(bundleOutput),
|
|
38
|
+
MODULES_DIR,
|
|
39
|
+
);
|
|
26
40
|
const writeUnbundle = createDir(modulesDir).then(() =>
|
|
27
41
|
Promise.all([
|
|
28
42
|
writeModules(lazyModules, modulesDir, encoding),
|
|
29
|
-
|
|
43
|
+
(0, _writeFile.default)(bundleOutput, startupCode, encoding),
|
|
30
44
|
writeMagicFlagFile(modulesDir),
|
|
31
|
-
])
|
|
45
|
+
]),
|
|
32
46
|
);
|
|
33
47
|
writeUnbundle.then(() => log("Done writing unbundle output"));
|
|
34
48
|
if (sourcemapOutput) {
|
|
35
|
-
const sourceMap =
|
|
49
|
+
const sourceMap = (0, _buildSourcemapWithMetadata.default)({
|
|
36
50
|
fixWrapperOffset: true,
|
|
37
51
|
lazyModules: lazyModules.concat(),
|
|
38
52
|
moduleGroups: null,
|
|
39
53
|
startupModules: startupModules.concat(),
|
|
40
54
|
});
|
|
41
55
|
if (sourcemapSourcesRoot != null) {
|
|
42
|
-
|
|
56
|
+
(0, _relativizeSourceMap.default)(sourceMap, sourcemapSourcesRoot);
|
|
43
57
|
}
|
|
44
|
-
const wroteSourceMap =
|
|
58
|
+
const wroteSourceMap = (0, _writeSourcemap.default)(
|
|
45
59
|
sourcemapOutput,
|
|
46
60
|
JSON.stringify(sourceMap),
|
|
47
|
-
log
|
|
61
|
+
log,
|
|
48
62
|
);
|
|
49
63
|
return Promise.all([writeUnbundle, wroteSourceMap]);
|
|
50
64
|
} else {
|
|
@@ -52,23 +66,29 @@ function saveAsAssets(bundle, options, log) {
|
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
function createDir(dirName) {
|
|
55
|
-
return
|
|
69
|
+
return _fs.promises.mkdir(dirName, {
|
|
56
70
|
recursive: true,
|
|
57
71
|
});
|
|
58
72
|
}
|
|
59
73
|
function writeModuleFile(module, modulesDir, encoding) {
|
|
60
74
|
const { code, id } = module;
|
|
61
|
-
return
|
|
75
|
+
return (0, _writeFile.default)(
|
|
76
|
+
_path.default.join(modulesDir, id + ".js"),
|
|
77
|
+
code,
|
|
78
|
+
encoding,
|
|
79
|
+
);
|
|
62
80
|
}
|
|
63
81
|
function writeModules(modules, modulesDir, encoding) {
|
|
64
82
|
const writeFiles = modules.map((module) =>
|
|
65
|
-
writeModuleFile(module, modulesDir, encoding)
|
|
83
|
+
writeModuleFile(module, modulesDir, encoding),
|
|
66
84
|
);
|
|
67
85
|
return Promise.all(writeFiles);
|
|
68
86
|
}
|
|
69
87
|
function writeMagicFlagFile(outputDir) {
|
|
70
88
|
const buffer = Buffer.alloc(4);
|
|
71
|
-
buffer.writeUInt32LE(
|
|
72
|
-
return
|
|
89
|
+
buffer.writeUInt32LE(_magicNumber.default, 0);
|
|
90
|
+
return (0, _writeFile.default)(
|
|
91
|
+
_path.default.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME),
|
|
92
|
+
buffer,
|
|
93
|
+
);
|
|
73
94
|
}
|
|
74
|
-
module.exports = saveAsAssets;
|
|
@@ -9,20 +9,19 @@
|
|
|
9
9
|
* @oncall react_native
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
'use strict';
|
|
13
|
-
|
|
14
12
|
import type {RamBundleInfo} from '../../../DeltaBundler/Serializers/getRamBundleInfo';
|
|
15
|
-
import type {ModuleTransportLike} from '../../../shared/types
|
|
16
|
-
import type {OutputOptions} from '../../types
|
|
13
|
+
import type {ModuleTransportLike} from '../../../shared/types';
|
|
14
|
+
import type {OutputOptions} from '../../types';
|
|
15
|
+
|
|
16
|
+
import relativizeSourceMapInline from '../../../lib/relativizeSourceMap';
|
|
17
|
+
import writeFile from '../writeFile';
|
|
18
|
+
import buildSourcemapWithMetadata from './buildSourcemapWithMetadata';
|
|
19
|
+
import MAGIC_RAM_BUNDLE_NUMBER from './magic-number';
|
|
20
|
+
import {joinModules} from './util';
|
|
21
|
+
import writeSourceMap from './write-sourcemap';
|
|
22
|
+
import {promises as fsPromises} from 'fs';
|
|
23
|
+
import path from 'path';
|
|
17
24
|
|
|
18
|
-
const relativizeSourceMapInline = require('../../../lib/relativizeSourceMap');
|
|
19
|
-
const writeFile = require('../writeFile');
|
|
20
|
-
const buildSourcemapWithMetadata = require('./buildSourcemapWithMetadata');
|
|
21
|
-
const MAGIC_RAM_BUNDLE_NUMBER = require('./magic-number');
|
|
22
|
-
const {joinModules} = require('./util');
|
|
23
|
-
const writeSourceMap = require('./write-sourcemap');
|
|
24
|
-
const fsPromises = require('fs').promises;
|
|
25
|
-
const path = require('path');
|
|
26
25
|
// must not start with a dot, as that won't go into the apk
|
|
27
26
|
const MAGIC_RAM_BUNDLE_FILENAME = 'UNBUNDLE';
|
|
28
27
|
const MODULES_DIR = 'js-modules';
|
|
@@ -34,7 +33,7 @@ const MODULES_DIR = 'js-modules';
|
|
|
34
33
|
* All other modules go into a 'js-modules' folder that in the same parent
|
|
35
34
|
* directory as the startup file.
|
|
36
35
|
*/
|
|
37
|
-
function saveAsAssets(
|
|
36
|
+
export default function saveAsAssets(
|
|
38
37
|
bundle: RamBundleInfo,
|
|
39
38
|
options: OutputOptions,
|
|
40
39
|
log: (...args: Array<string>) => void,
|
|
@@ -123,5 +122,3 @@ function writeMagicFlagFile(outputDir: string): Promise<mixed> {
|
|
|
123
122
|
buffer.writeUInt32LE(MAGIC_RAM_BUNDLE_NUMBER, 0);
|
|
124
123
|
return writeFile(path.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME), buffer);
|
|
125
124
|
}
|
|
126
|
-
|
|
127
|
-
module.exports = saveAsAssets;
|