metro 0.83.3 → 0.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -25
- package/src/Assets.js +42 -29
- package/src/Assets.js.flow +26 -15
- package/src/Bundler/util.js +25 -21
- package/src/Bundler/util.js.flow +2 -2
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.js +4 -4
- package/src/DeltaBundler/DeltaCalculator.js.flow +8 -8
- package/src/DeltaBundler/Graph.js +16 -16
- package/src/DeltaBundler/Graph.js.flow +30 -30
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +8 -8
- package/src/DeltaBundler/Serializers/helpers/js.js +25 -21
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +6 -6
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +25 -21
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +5 -5
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +2 -2
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
- package/src/DeltaBundler/Transformer.js.flow +3 -3
- package/src/DeltaBundler/Worker.flow.js.flow +1 -1
- package/src/DeltaBundler/WorkerFarm.js +1 -1
- package/src/DeltaBundler/WorkerFarm.js.flow +26 -13
- package/src/DeltaBundler/buildSubgraph.js +4 -4
- package/src/DeltaBundler/buildSubgraph.js.flow +8 -8
- package/src/DeltaBundler/types.js.flow +36 -34
- package/src/DeltaBundler.js.flow +2 -2
- package/src/HmrServer.js +34 -29
- package/src/HmrServer.js.flow +17 -12
- package/src/IncrementalBundler.js +29 -21
- package/src/IncrementalBundler.js.flow +13 -9
- package/src/ModuleGraph/worker/JsFileWrapping.js +25 -21
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +10 -5
- package/src/ModuleGraph/worker/collectDependencies.js +25 -21
- package/src/ModuleGraph/worker/collectDependencies.js.flow +27 -21
- package/src/ModuleGraph/worker/generateImportNames.js.flow +4 -2
- package/src/ModuleGraph/worker/importLocationsPlugin.js.flow +7 -3
- package/src/Server/MultipartResponse.js.flow +1 -1
- package/src/Server/symbolicate.js.flow +4 -4
- package/src/Server.js +139 -39
- package/src/Server.js.flow +158 -47
- package/src/cli/parseKeyValueParamArray.js.flow +1 -1
- package/src/cli-utils.js.flow +2 -2
- package/src/commands/build.js.flow +11 -10
- package/src/commands/dependencies.js.flow +8 -4
- package/src/commands/serve.js +2 -0
- package/src/commands/serve.js.flow +14 -9
- package/src/index.flow.js +30 -26
- package/src/index.flow.js.flow +25 -20
- package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
- package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js.flow +1 -1
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/index.js +25 -21
- package/src/integration_tests/basic_bundle/import-export/index.js.flow +3 -3
- package/src/integration_tests/basic_bundle/import-export/utils.js.flow +2 -2
- package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js.flow +1 -1
- package/src/integration_tests/basic_bundle/optional-dependencies/index.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/conflict.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/empty.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/matching.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js.flow +2 -2
- package/src/integration_tests/basic_bundle/require-context/utils.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js.flow +1 -1
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js.flow +1 -1
- package/src/integration_tests/execBundle.js.flow +1 -1
- package/src/lib/BatchProcessor.js +5 -2
- package/src/lib/BatchProcessor.js.flow +10 -7
- package/src/lib/CountingSet.js.flow +4 -4
- package/src/lib/JsonReporter.js +5 -3
- package/src/lib/JsonReporter.js.flow +19 -17
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.js +31 -27
- package/src/lib/TerminalReporter.js.flow +15 -15
- package/src/lib/contextModule.js.flow +1 -1
- package/src/lib/contextModuleTemplates.js +25 -21
- package/src/lib/countLines.js +4 -3
- package/src/lib/countLines.js.flow +3 -4
- package/src/lib/createWebsocketServer.js +9 -2
- package/src/lib/createWebsocketServer.js.flow +16 -9
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.js.flow +1 -1
- package/src/lib/getAppendScripts.js.flow +4 -4
- package/src/lib/getGraphId.js.flow +1 -1
- package/src/lib/getPreludeCode.js +4 -0
- package/src/lib/getPreludeCode.js.flow +10 -3
- package/src/lib/getPrependedScripts.js +36 -22
- package/src/lib/getPrependedScripts.js.flow +10 -3
- package/src/lib/logToConsole.js.flow +2 -2
- package/src/lib/parseBundleOptionsFromBundleRequestUrl.js +25 -21
- package/src/lib/parseCustomResolverOptions.js.flow +2 -2
- package/src/lib/parseCustomTransformOptions.js.flow +1 -1
- package/src/lib/parseJsonBody.js.flow +11 -1
- package/src/lib/pathUtils.js +25 -21
- package/src/lib/pathUtils.js.flow +1 -1
- package/src/lib/reporting.js.flow +4 -4
- package/src/lib/transformHelpers.js +11 -9
- package/src/lib/transformHelpers.js.flow +17 -15
- package/src/node-haste/DependencyGraph/ModuleResolution.js +48 -42
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +35 -32
- package/src/node-haste/DependencyGraph/createFileMap.js +56 -38
- package/src/node-haste/DependencyGraph/createFileMap.js.flow +44 -18
- package/src/node-haste/DependencyGraph.js +40 -31
- package/src/node-haste/DependencyGraph.js.flow +35 -37
- package/src/node-haste/lib/AssetPaths.js +2 -2
- package/src/node-haste/lib/AssetPaths.js.flow +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.js +6 -6
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +4 -4
- package/src/shared/output/RamBundle/as-assets.js.flow +6 -6
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +5 -5
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +5 -5
- package/src/shared/output/RamBundle/util.js.flow +5 -5
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.js.flow +1 -1
- package/src/shared/output/bundle.flow.js.flow +3 -3
- package/src/shared/output/meta.js +2 -2
- package/src/shared/output/meta.js.flow +1 -1
- package/src/shared/output/writeFile.js +8 -3
- package/src/shared/output/writeFile.js.flow +8 -2
- package/src/shared/types.js.flow +20 -5
- package/src/Asset.d.ts +0 -25
- package/src/Bundler.d.ts +0 -39
- package/src/DeltaBundler/Graph.d.ts +0 -40
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.d.ts +0 -26
- package/src/DeltaBundler/Serializers/getRamBundleInfo.d.ts +0 -18
- package/src/DeltaBundler/Worker.d.ts +0 -45
- package/src/DeltaBundler/types.d.ts +0 -166
- package/src/DeltaBundler.d.ts +0 -58
- package/src/IncrementalBundler.d.ts +0 -98
- package/src/ModuleGraph/test-helpers.js +0 -75
- package/src/ModuleGraph/worker/collectDependencies.d.ts +0 -27
- package/src/Server/MultipartResponse.d.ts +0 -31
- package/src/Server/symbolicate.d.ts +0 -31
- package/src/Server.d.ts +0 -118
- package/src/index.d.ts +0 -193
- package/src/lib/CountingSet.d.ts +0 -48
- package/src/lib/TerminalReporter.d.ts +0 -27
- package/src/lib/contextModule.d.ts +0 -22
- package/src/lib/getGraphId.d.ts +0 -11
- package/src/lib/reporting.d.ts +0 -144
- package/src/node-haste/DependencyGraph.d.ts +0 -62
- package/src/shared/output/bundle.d.ts +0 -35
- package/src/shared/types.d.ts +0 -130
|
@@ -34,6 +34,7 @@ function getOrCreateMap(map, field) {
|
|
|
34
34
|
}
|
|
35
35
|
class DependencyGraph extends _events.default {
|
|
36
36
|
#packageCache;
|
|
37
|
+
#dependencyPlugin;
|
|
37
38
|
constructor(config, options) {
|
|
38
39
|
super();
|
|
39
40
|
this._config = config;
|
|
@@ -45,32 +46,34 @@ class DependencyGraph extends _events.default {
|
|
|
45
46
|
type: "dep_graph_loading",
|
|
46
47
|
hasReducedPerformance: !!hasReducedPerformance,
|
|
47
48
|
});
|
|
48
|
-
const fileMap = (0, _createFileMap.default)(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const { fileMap, hasteMap, dependencyPlugin } = (0, _createFileMap.default)(
|
|
50
|
+
config,
|
|
51
|
+
{
|
|
52
|
+
throwOnModuleCollision: false,
|
|
53
|
+
watch,
|
|
54
|
+
},
|
|
55
|
+
);
|
|
52
56
|
fileMap.setMaxListeners(1000);
|
|
53
57
|
this._haste = fileMap;
|
|
54
58
|
this._haste.on("status", (status) => this._onWatcherStatus(status));
|
|
55
|
-
this._initializedPromise = fileMap
|
|
56
|
-
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
config.reporter.update({
|
|
60
|
-
type: "dep_graph_loaded",
|
|
61
|
-
});
|
|
62
|
-
this._fileSystem = fileSystem;
|
|
63
|
-
this._hasteMap = hasteMap;
|
|
64
|
-
this._haste.on("change", (changeEvent) =>
|
|
65
|
-
this._onHasteChange(changeEvent),
|
|
66
|
-
);
|
|
67
|
-
this._haste.on("healthCheck", (result) =>
|
|
68
|
-
this._onWatcherHealthCheck(result),
|
|
69
|
-
);
|
|
70
|
-
this._resolutionCache = new Map();
|
|
71
|
-
this.#packageCache = this._createPackageCache();
|
|
72
|
-
this._createModuleResolver();
|
|
59
|
+
this._initializedPromise = fileMap.build().then(({ fileSystem }) => {
|
|
60
|
+
log(createActionEndEntry(initializingMetroLogEntry));
|
|
61
|
+
config.reporter.update({
|
|
62
|
+
type: "dep_graph_loaded",
|
|
73
63
|
});
|
|
64
|
+
this._fileSystem = fileSystem;
|
|
65
|
+
this._hasteMap = hasteMap;
|
|
66
|
+
this.#dependencyPlugin = dependencyPlugin;
|
|
67
|
+
this._haste.on("change", (changeEvent) =>
|
|
68
|
+
this._onHasteChange(changeEvent),
|
|
69
|
+
);
|
|
70
|
+
this._haste.on("healthCheck", (result) =>
|
|
71
|
+
this._onWatcherHealthCheck(result),
|
|
72
|
+
);
|
|
73
|
+
this._resolutionCache = new Map();
|
|
74
|
+
this.#packageCache = this._createPackageCache();
|
|
75
|
+
this._createModuleResolver();
|
|
76
|
+
});
|
|
74
77
|
}
|
|
75
78
|
_onWatcherHealthCheck(result) {
|
|
76
79
|
this._config.reporter.update({
|
|
@@ -87,11 +90,6 @@ class DependencyGraph extends _events.default {
|
|
|
87
90
|
async ready() {
|
|
88
91
|
await this._initializedPromise;
|
|
89
92
|
}
|
|
90
|
-
static async load(config, options) {
|
|
91
|
-
const self = new DependencyGraph(config, options);
|
|
92
|
-
await self.ready();
|
|
93
|
-
return self;
|
|
94
|
-
}
|
|
95
93
|
_onHasteChange({ eventsQueue }) {
|
|
96
94
|
this._resolutionCache = new Map();
|
|
97
95
|
eventsQueue.forEach(({ filePath }) =>
|
|
@@ -124,7 +122,7 @@ class DependencyGraph extends _events.default {
|
|
|
124
122
|
},
|
|
125
123
|
disableHierarchicalLookup:
|
|
126
124
|
this._config.resolver.disableHierarchicalLookup,
|
|
127
|
-
doesFileExist: this.
|
|
125
|
+
doesFileExist: this.doesFileExist,
|
|
128
126
|
emptyModulePath: this._config.resolver.emptyModulePath,
|
|
129
127
|
extraNodeModules: this._config.resolver.extraNodeModules,
|
|
130
128
|
fileSystemLookup,
|
|
@@ -157,6 +155,8 @@ class DependencyGraph extends _events.default {
|
|
|
157
155
|
this._config.resolver.unstable_conditionsByPlatform,
|
|
158
156
|
unstable_enablePackageExports:
|
|
159
157
|
this._config.resolver.unstable_enablePackageExports,
|
|
158
|
+
unstable_incrementalResolution:
|
|
159
|
+
this._config.resolver.unstable_incrementalResolution,
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
_getClosestPackage(absoluteModulePath) {
|
|
@@ -276,18 +276,27 @@ class DependencyGraph extends _events.default {
|
|
|
276
276
|
mapByPlatform.set(platformKey, resolution);
|
|
277
277
|
return resolution;
|
|
278
278
|
}
|
|
279
|
-
|
|
279
|
+
doesFileExist = (filePath) => {
|
|
280
280
|
return this._fileSystem.exists(filePath);
|
|
281
281
|
};
|
|
282
282
|
getHasteName(filePath) {
|
|
283
|
-
const hasteName = this.
|
|
283
|
+
const hasteName = this._hasteMap.getModuleNameByPath(filePath);
|
|
284
284
|
if (hasteName) {
|
|
285
285
|
return hasteName;
|
|
286
286
|
}
|
|
287
287
|
return _path.default.relative(this._config.projectRoot, filePath);
|
|
288
288
|
}
|
|
289
289
|
getDependencies(filePath) {
|
|
290
|
-
|
|
290
|
+
if (!this.#dependencyPlugin) {
|
|
291
|
+
throw new Error(
|
|
292
|
+
"getDependencies called but extractDependencies is false",
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
return Array.from(
|
|
296
|
+
(0, _nullthrows.default)(
|
|
297
|
+
this.#dependencyPlugin.getDependencies(filePath),
|
|
298
|
+
),
|
|
299
|
+
);
|
|
291
300
|
}
|
|
292
301
|
}
|
|
293
302
|
exports.default = DependencyGraph;
|
|
@@ -16,12 +16,14 @@ import type {
|
|
|
16
16
|
import type {ResolverInputOptions} from '../shared/types';
|
|
17
17
|
import type Package from './Package';
|
|
18
18
|
import type {ConfigT} from 'metro-config';
|
|
19
|
-
import type
|
|
19
|
+
import type {
|
|
20
20
|
ChangeEvent,
|
|
21
|
+
DependencyPlugin,
|
|
21
22
|
FileSystem,
|
|
22
23
|
HasteMap,
|
|
23
24
|
HealthCheckResult,
|
|
24
25
|
WatcherStatus,
|
|
26
|
+
default as MetroFileMap,
|
|
25
27
|
} from 'metro-file-map';
|
|
26
28
|
import type {FileSystemLookup} from 'metro-resolver';
|
|
27
29
|
|
|
@@ -63,6 +65,7 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
63
65
|
_fileSystem: FileSystem;
|
|
64
66
|
#packageCache: PackageCache;
|
|
65
67
|
_hasteMap: HasteMap;
|
|
68
|
+
#dependencyPlugin: ?DependencyPlugin;
|
|
66
69
|
_moduleResolver: ModuleResolver<Package>;
|
|
67
70
|
_resolutionCache: Map<
|
|
68
71
|
// Custom resolver options
|
|
@@ -103,7 +106,7 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
103
106
|
type: 'dep_graph_loading',
|
|
104
107
|
hasReducedPerformance: !!hasReducedPerformance,
|
|
105
108
|
});
|
|
106
|
-
const fileMap = createFileMap(config, {
|
|
109
|
+
const {fileMap, hasteMap, dependencyPlugin} = createFileMap(config, {
|
|
107
110
|
throwOnModuleCollision: false,
|
|
108
111
|
watch,
|
|
109
112
|
});
|
|
@@ -115,25 +118,22 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
115
118
|
this._haste = fileMap;
|
|
116
119
|
this._haste.on('status', status => this._onWatcherStatus(status));
|
|
117
120
|
|
|
118
|
-
this._initializedPromise = fileMap
|
|
119
|
-
|
|
120
|
-
.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.#packageCache = this._createPackageCache();
|
|
135
|
-
this._createModuleResolver();
|
|
136
|
-
});
|
|
121
|
+
this._initializedPromise = fileMap.build().then(({fileSystem}) => {
|
|
122
|
+
log(createActionEndEntry(initializingMetroLogEntry));
|
|
123
|
+
config.reporter.update({type: 'dep_graph_loaded'});
|
|
124
|
+
|
|
125
|
+
this._fileSystem = fileSystem;
|
|
126
|
+
this._hasteMap = hasteMap;
|
|
127
|
+
this.#dependencyPlugin = dependencyPlugin;
|
|
128
|
+
|
|
129
|
+
this._haste.on('change', changeEvent => this._onHasteChange(changeEvent));
|
|
130
|
+
this._haste.on('healthCheck', result =>
|
|
131
|
+
this._onWatcherHealthCheck(result),
|
|
132
|
+
);
|
|
133
|
+
this._resolutionCache = new Map();
|
|
134
|
+
this.#packageCache = this._createPackageCache();
|
|
135
|
+
this._createModuleResolver();
|
|
136
|
+
});
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
_onWatcherHealthCheck(result: HealthCheckResult) {
|
|
@@ -150,17 +150,6 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
150
150
|
await this._initializedPromise;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
// Creates the dependency graph and waits for it to become ready.
|
|
154
|
-
// @deprecated Use the constructor + ready() directly.
|
|
155
|
-
static async load(
|
|
156
|
-
config: ConfigT,
|
|
157
|
-
options?: {+hasReducedPerformance?: boolean, +watch?: boolean},
|
|
158
|
-
): Promise<DependencyGraph> {
|
|
159
|
-
const self = new DependencyGraph(config, options);
|
|
160
|
-
await self.ready();
|
|
161
|
-
return self;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
153
|
_onHasteChange({eventsQueue}: ChangeEvent) {
|
|
165
154
|
this._resolutionCache = new Map();
|
|
166
155
|
eventsQueue.forEach(({filePath}) =>
|
|
@@ -193,7 +182,7 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
193
182
|
},
|
|
194
183
|
disableHierarchicalLookup:
|
|
195
184
|
this._config.resolver.disableHierarchicalLookup,
|
|
196
|
-
doesFileExist: this.
|
|
185
|
+
doesFileExist: this.doesFileExist,
|
|
197
186
|
emptyModulePath: this._config.resolver.emptyModulePath,
|
|
198
187
|
extraNodeModules: this._config.resolver.extraNodeModules,
|
|
199
188
|
fileSystemLookup,
|
|
@@ -227,6 +216,8 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
227
216
|
this._config.resolver.unstable_conditionsByPlatform,
|
|
228
217
|
unstable_enablePackageExports:
|
|
229
218
|
this._config.resolver.unstable_enablePackageExports,
|
|
219
|
+
unstable_incrementalResolution:
|
|
220
|
+
this._config.resolver.unstable_incrementalResolution,
|
|
230
221
|
});
|
|
231
222
|
}
|
|
232
223
|
|
|
@@ -290,7 +281,7 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
290
281
|
/** Given a search context, return a list of file paths matching the query. */
|
|
291
282
|
matchFilesWithContext(
|
|
292
283
|
from: string,
|
|
293
|
-
context:
|
|
284
|
+
context: Readonly<{
|
|
294
285
|
/* Should search for files recursively. */
|
|
295
286
|
recursive: boolean,
|
|
296
287
|
/* Filter relative paths against a pattern. */
|
|
@@ -376,12 +367,12 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
376
367
|
return resolution;
|
|
377
368
|
}
|
|
378
369
|
|
|
379
|
-
|
|
370
|
+
doesFileExist = (filePath: string): boolean => {
|
|
380
371
|
return this._fileSystem.exists(filePath);
|
|
381
372
|
};
|
|
382
373
|
|
|
383
374
|
getHasteName(filePath: string): string {
|
|
384
|
-
const hasteName = this.
|
|
375
|
+
const hasteName = this._hasteMap.getModuleNameByPath(filePath);
|
|
385
376
|
|
|
386
377
|
if (hasteName) {
|
|
387
378
|
return hasteName;
|
|
@@ -391,6 +382,13 @@ export default class DependencyGraph extends EventEmitter {
|
|
|
391
382
|
}
|
|
392
383
|
|
|
393
384
|
getDependencies(filePath: string): Array<string> {
|
|
394
|
-
|
|
385
|
+
if (!this.#dependencyPlugin) {
|
|
386
|
+
throw new Error(
|
|
387
|
+
'getDependencies called but extractDependencies is false',
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
return Array.from(
|
|
391
|
+
nullthrows(this.#dependencyPlugin.getDependencies(filePath)),
|
|
392
|
+
);
|
|
395
393
|
}
|
|
396
394
|
}
|
|
@@ -23,14 +23,14 @@ function parseBaseName(baseName) {
|
|
|
23
23
|
const resolution = parseFloat(match[3]);
|
|
24
24
|
if (!Number.isNaN(resolution)) {
|
|
25
25
|
return {
|
|
26
|
-
rootName,
|
|
27
26
|
resolution,
|
|
27
|
+
rootName,
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
return {
|
|
32
|
-
rootName,
|
|
33
32
|
resolution: 1,
|
|
33
|
+
rootName,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
function tryParse(filePath, platforms) {
|
|
@@ -35,10 +35,10 @@ function parseBaseName(baseName: string): {
|
|
|
35
35
|
if (match[3] != null) {
|
|
36
36
|
const resolution = parseFloat(match[3]);
|
|
37
37
|
if (!Number.isNaN(resolution)) {
|
|
38
|
-
return {
|
|
38
|
+
return {resolution, rootName};
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
return {
|
|
41
|
+
return {resolution: 1, rootName};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -47,7 +47,7 @@ function parseBaseName(baseName: string): {
|
|
|
47
47
|
*/
|
|
48
48
|
export function tryParse(
|
|
49
49
|
filePath: string,
|
|
50
|
-
platforms:
|
|
50
|
+
platforms: ReadonlySet<string>,
|
|
51
51
|
): ?AssetPath {
|
|
52
52
|
const result = parsePlatformFilePath(filePath, platforms);
|
|
53
53
|
const {dirPath, baseName, platform, extension} = result;
|
|
@@ -66,7 +66,7 @@ export function tryParse(
|
|
|
66
66
|
|
|
67
67
|
export function parse(
|
|
68
68
|
filePath: string,
|
|
69
|
-
platforms:
|
|
69
|
+
platforms: ReadonlySet<string>,
|
|
70
70
|
): AssetPath {
|
|
71
71
|
const result = tryParse(filePath, platforms);
|
|
72
72
|
if (result == null) {
|
|
@@ -15,27 +15,27 @@ function parsePlatformFilePath(filePath, platforms) {
|
|
|
15
15
|
const match = fileName.match(PATH_RE);
|
|
16
16
|
if (!match) {
|
|
17
17
|
return {
|
|
18
|
-
dirPath,
|
|
19
18
|
baseName: fileName,
|
|
20
|
-
|
|
19
|
+
dirPath,
|
|
21
20
|
extension: null,
|
|
21
|
+
platform: null,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
const extension = match[4] || null;
|
|
25
25
|
const platform = match[3] || null;
|
|
26
26
|
if (platform == null || platforms.has(platform)) {
|
|
27
27
|
return {
|
|
28
|
-
dirPath,
|
|
29
28
|
baseName: match[1],
|
|
30
|
-
|
|
29
|
+
dirPath,
|
|
31
30
|
extension,
|
|
31
|
+
platform,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
const baseName = `${match[1]}.${platform}`;
|
|
35
35
|
return {
|
|
36
|
-
dirPath,
|
|
37
36
|
baseName,
|
|
38
|
-
|
|
37
|
+
dirPath,
|
|
39
38
|
extension,
|
|
39
|
+
platform: null,
|
|
40
40
|
};
|
|
41
41
|
}
|
|
@@ -26,19 +26,19 @@ const PATH_RE = /^(.+?)(\.([^.]+))?\.([^.]+)$/;
|
|
|
26
26
|
*/
|
|
27
27
|
export default function parsePlatformFilePath(
|
|
28
28
|
filePath: string,
|
|
29
|
-
platforms:
|
|
29
|
+
platforms: ReadonlySet<string>,
|
|
30
30
|
): PlatformFilePathParts {
|
|
31
31
|
const dirPath = path.dirname(filePath);
|
|
32
32
|
const fileName = path.basename(filePath);
|
|
33
33
|
const match = fileName.match(PATH_RE);
|
|
34
34
|
if (!match) {
|
|
35
|
-
return {
|
|
35
|
+
return {baseName: fileName, dirPath, extension: null, platform: null};
|
|
36
36
|
}
|
|
37
37
|
const extension = match[4] || null;
|
|
38
38
|
const platform = match[3] || null;
|
|
39
39
|
if (platform == null || platforms.has(platform)) {
|
|
40
|
-
return {
|
|
40
|
+
return {baseName: match[1], dirPath, extension, platform};
|
|
41
41
|
}
|
|
42
42
|
const baseName = `${match[1]}.${platform}`;
|
|
43
|
-
return {dirPath,
|
|
43
|
+
return {baseName, dirPath, extension, platform: null};
|
|
44
44
|
}
|
|
@@ -37,7 +37,7 @@ export default function saveAsAssets(
|
|
|
37
37
|
bundle: RamBundleInfo,
|
|
38
38
|
options: OutputOptions,
|
|
39
39
|
log: (...args: Array<string>) => void,
|
|
40
|
-
): Promise<
|
|
40
|
+
): Promise<unknown> {
|
|
41
41
|
const {
|
|
42
42
|
bundleOutput,
|
|
43
43
|
bundleEncoding: encoding,
|
|
@@ -100,24 +100,24 @@ function writeModuleFile(
|
|
|
100
100
|
module: ModuleTransportLike,
|
|
101
101
|
modulesDir: string,
|
|
102
102
|
encoding: void | 'ascii' | 'utf16le' | 'utf8',
|
|
103
|
-
): Promise<
|
|
103
|
+
): Promise<unknown> {
|
|
104
104
|
const {code, id} = module;
|
|
105
105
|
return writeFile(path.join(modulesDir, id + '.js'), code, encoding);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
function writeModules(
|
|
109
|
-
modules:
|
|
109
|
+
modules: ReadonlyArray<ModuleTransportLike>,
|
|
110
110
|
modulesDir: string,
|
|
111
111
|
encoding: void | 'ascii' | 'utf16le' | 'utf8',
|
|
112
|
-
): Promise<Array<
|
|
112
|
+
): Promise<Array<unknown>> {
|
|
113
113
|
const writeFiles = modules.map(
|
|
114
|
-
(module: ModuleTransportLike): Promise<
|
|
114
|
+
(module: ModuleTransportLike): Promise<unknown> =>
|
|
115
115
|
writeModuleFile(module, modulesDir, encoding),
|
|
116
116
|
);
|
|
117
117
|
return Promise.all(writeFiles);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
function writeMagicFlagFile(outputDir: string): Promise<
|
|
120
|
+
function writeMagicFlagFile(outputDir: string): Promise<unknown> {
|
|
121
121
|
const buffer = Buffer.alloc(4);
|
|
122
122
|
buffer.writeUInt32LE(MAGIC_RAM_BUNDLE_NUMBER, 0);
|
|
123
123
|
return writeFile(path.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME), buffer);
|
|
@@ -37,7 +37,7 @@ export function save(
|
|
|
37
37
|
bundle: RamBundleInfo,
|
|
38
38
|
options: OutputOptions,
|
|
39
39
|
log: (...args: Array<string>) => void,
|
|
40
|
-
): Promise<
|
|
40
|
+
): Promise<unknown> {
|
|
41
41
|
const {
|
|
42
42
|
bundleOutput,
|
|
43
43
|
bundleEncoding: encoding,
|
|
@@ -96,7 +96,7 @@ function writeBuffers(
|
|
|
96
96
|
buffers: Array<Buffer>,
|
|
97
97
|
): Promise<void> {
|
|
98
98
|
buffers.forEach((buffer: Buffer) => stream.write(buffer));
|
|
99
|
-
return new Promise((resolve: () => void, reject:
|
|
99
|
+
return new Promise((resolve: () => void, reject: unknown => unknown) => {
|
|
100
100
|
stream.on('error', reject);
|
|
101
101
|
stream.on('finish', () => resolve());
|
|
102
102
|
stream.end();
|
|
@@ -196,7 +196,7 @@ function groupCode(
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
function buildModuleBuffers(
|
|
199
|
-
modules:
|
|
199
|
+
modules: ReadonlyArray<ModuleTransportLike>,
|
|
200
200
|
moduleGroups: ModuleGroups,
|
|
201
201
|
encoding: void | 'ascii' | 'utf16le' | 'utf8',
|
|
202
202
|
): Array<{
|
|
@@ -217,7 +217,7 @@ function buildModuleBuffers(
|
|
|
217
217
|
|
|
218
218
|
export function buildTableAndContents(
|
|
219
219
|
startupCode: string,
|
|
220
|
-
modules:
|
|
220
|
+
modules: ReadonlyArray<ModuleTransportLike>,
|
|
221
221
|
moduleGroups: ModuleGroups,
|
|
222
222
|
encoding?: 'utf8' | 'utf16le' | 'ascii',
|
|
223
223
|
): Array<Buffer> {
|
|
@@ -242,7 +242,7 @@ export function buildTableAndContents(
|
|
|
242
242
|
|
|
243
243
|
export function createModuleGroups(
|
|
244
244
|
groups: Map<number, Set<number>>,
|
|
245
|
-
modules:
|
|
245
|
+
modules: ReadonlyArray<ModuleTransportLike>,
|
|
246
246
|
): ModuleGroups {
|
|
247
247
|
return {
|
|
248
248
|
groups,
|
|
@@ -20,17 +20,17 @@ import {
|
|
|
20
20
|
|
|
21
21
|
type Params = {
|
|
22
22
|
fixWrapperOffset: boolean,
|
|
23
|
-
lazyModules:
|
|
23
|
+
lazyModules: ReadonlyArray<ModuleTransportLike>,
|
|
24
24
|
moduleGroups: ?ModuleGroups,
|
|
25
|
-
startupModules:
|
|
25
|
+
startupModules: ReadonlyArray<ModuleTransportLike>,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export default (
|
|
28
|
+
export default ({
|
|
29
29
|
fixWrapperOffset,
|
|
30
30
|
lazyModules,
|
|
31
31
|
moduleGroups,
|
|
32
32
|
startupModules,
|
|
33
|
-
}: Params) => {
|
|
33
|
+
}: Params): IndexMap => {
|
|
34
34
|
const options = fixWrapperOffset ? {fixWrapperOffset: true} : undefined;
|
|
35
35
|
const startupModule: ModuleTransportLike = {
|
|
36
36
|
code: joinModules(startupModules),
|
|
@@ -59,4 +59,4 @@ export default (({
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
return map;
|
|
62
|
-
}
|
|
62
|
+
};
|
|
@@ -50,7 +50,7 @@ const Section = (line: number, column: number, map: MixedSourceMap) => ({
|
|
|
50
50
|
type CombineOptions = {fixWrapperOffset: boolean, ...};
|
|
51
51
|
|
|
52
52
|
function combineSourceMaps(
|
|
53
|
-
modules:
|
|
53
|
+
modules: ReadonlyArray<ModuleTransportLike>,
|
|
54
54
|
moduleGroups?: ModuleGroups,
|
|
55
55
|
options?: ?CombineOptions,
|
|
56
56
|
): IndexMap {
|
|
@@ -59,7 +59,7 @@ function combineSourceMaps(
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function combineSourceMapsAddingOffsets(
|
|
62
|
-
modules:
|
|
62
|
+
modules: ReadonlyArray<ModuleTransportLike>,
|
|
63
63
|
x_metro_module_paths: Array<string>,
|
|
64
64
|
moduleGroups?: ?ModuleGroups,
|
|
65
65
|
options?: ?CombineOptions,
|
|
@@ -75,7 +75,7 @@ function combineSourceMapsAddingOffsets(
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
function combineMaps(
|
|
78
|
-
modules:
|
|
78
|
+
modules: ReadonlyArray<ModuleTransportLike>,
|
|
79
79
|
offsets: ?Array<number>,
|
|
80
80
|
moduleGroups: ?ModuleGroups,
|
|
81
81
|
options: ?CombineOptions,
|
|
@@ -99,7 +99,7 @@ function combineMaps(
|
|
|
99
99
|
group = moduleGroups && moduleGroups.groups.get(id);
|
|
100
100
|
if (group && moduleGroups) {
|
|
101
101
|
const {modulesById} = moduleGroups;
|
|
102
|
-
const otherModules:
|
|
102
|
+
const otherModules: ReadonlyArray<ModuleTransportLike> = Array.from(
|
|
103
103
|
group || [],
|
|
104
104
|
)
|
|
105
105
|
.map((moduleId: number) => modulesById.get(moduleId))
|
|
@@ -135,7 +135,7 @@ function combineMaps(
|
|
|
135
135
|
return sections;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
const joinModules = (modules:
|
|
138
|
+
const joinModules = (modules: ReadonlyArray<{+code: string, ...}>): string =>
|
|
139
139
|
modules.map((m: {+code: string, ...}) => m.code).join('\n');
|
|
140
140
|
|
|
141
141
|
export {
|
|
@@ -33,7 +33,7 @@ export function save(
|
|
|
33
33
|
bundle: RamBundleInfo,
|
|
34
34
|
options: OutputOptions,
|
|
35
35
|
log: (x: string) => void,
|
|
36
|
-
): Promise<
|
|
36
|
+
): Promise<unknown> {
|
|
37
37
|
// We fork here depending on the platform: while Android is pretty good at
|
|
38
38
|
// loading individual assets, iOS has a large overhead when reading hundreds
|
|
39
39
|
// of assets from disk.
|
|
@@ -26,7 +26,7 @@ export function build(
|
|
|
26
26
|
): Promise<{
|
|
27
27
|
code: string,
|
|
28
28
|
map: string,
|
|
29
|
-
assets?:
|
|
29
|
+
assets?: ReadonlyArray<AssetData>,
|
|
30
30
|
...
|
|
31
31
|
}> {
|
|
32
32
|
return packagerClient.build(
|
|
@@ -69,7 +69,7 @@ export async function save(
|
|
|
69
69
|
},
|
|
70
70
|
options: OutputOptions,
|
|
71
71
|
log: string => void,
|
|
72
|
-
): Promise<
|
|
72
|
+
): Promise<unknown> {
|
|
73
73
|
const {
|
|
74
74
|
bundleOutput,
|
|
75
75
|
bundleEncoding: encoding,
|
|
@@ -101,7 +101,7 @@ export async function save(
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
// Wait until everything is written to disk.
|
|
104
|
-
await Promise.all(writeFns.map((cb: void =>
|
|
104
|
+
await Promise.all(writeFns.map((cb: void => unknown) => cb()));
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
export const formatName = 'bundle';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = meta;
|
|
7
7
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
8
8
|
function _interopRequireDefault(e) {
|
|
9
9
|
return e && e.__esModule ? e : { default: e };
|
|
@@ -17,7 +17,7 @@ const constantFor = (encoding) =>
|
|
|
17
17
|
: /^(?:utf-?16(?:le)?|ucs-?2)$/.test(encoding)
|
|
18
18
|
? 3
|
|
19
19
|
: 0;
|
|
20
|
-
function
|
|
20
|
+
function meta(code, encoding = "utf8") {
|
|
21
21
|
const buffer = asBuffer(code, encoding);
|
|
22
22
|
const hash = _crypto.default.createHash("sha1");
|
|
23
23
|
hash.update(buffer);
|
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true,
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = writeFile;
|
|
7
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
8
8
|
var _throat = _interopRequireDefault(require("throat"));
|
|
9
9
|
function _interopRequireDefault(e) {
|
|
10
10
|
return e && e.__esModule ? e : { default: e };
|
|
11
11
|
}
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const writeFileWithThroat = (0, _throat.default)(
|
|
13
|
+
128,
|
|
14
|
+
_fs.default.promises.writeFile,
|
|
15
|
+
);
|
|
16
|
+
function writeFile(filePath, data, encoding) {
|
|
17
|
+
return writeFileWithThroat(filePath, data, encoding);
|
|
18
|
+
}
|
|
@@ -12,9 +12,15 @@
|
|
|
12
12
|
import fs from 'fs';
|
|
13
13
|
import throat from 'throat';
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const writeFileWithThroat: typeof fs.promises.writeFile = throat(
|
|
16
16
|
128,
|
|
17
17
|
fs.promises.writeFile,
|
|
18
18
|
);
|
|
19
19
|
|
|
20
|
-
export default writeFile
|
|
20
|
+
export default function writeFile(
|
|
21
|
+
filePath: string,
|
|
22
|
+
data: string | Buffer | Uint8Array,
|
|
23
|
+
encoding?: string,
|
|
24
|
+
): Promise<void> {
|
|
25
|
+
return writeFileWithThroat(filePath, data, encoding);
|
|
26
|
+
}
|