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
package/src/Server.js
CHANGED
|
@@ -1,47 +1,92 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _Assets = require("./Assets");
|
|
8
|
+
var _baseJSBundle = _interopRequireDefault(
|
|
9
|
+
require("./DeltaBundler/Serializers/baseJSBundle"),
|
|
10
|
+
);
|
|
11
|
+
var _getAllFiles = _interopRequireDefault(
|
|
12
|
+
require("./DeltaBundler/Serializers/getAllFiles"),
|
|
13
|
+
);
|
|
14
|
+
var _getAssets = _interopRequireDefault(
|
|
15
|
+
require("./DeltaBundler/Serializers/getAssets"),
|
|
16
|
+
);
|
|
17
|
+
var _getExplodedSourceMap = require("./DeltaBundler/Serializers/getExplodedSourceMap");
|
|
18
|
+
var _getRamBundleInfo = _interopRequireDefault(
|
|
19
|
+
require("./DeltaBundler/Serializers/getRamBundleInfo"),
|
|
20
|
+
);
|
|
21
|
+
var _sourceMapString = require("./DeltaBundler/Serializers/sourceMapString");
|
|
22
|
+
var _IncrementalBundler = _interopRequireDefault(
|
|
23
|
+
require("./IncrementalBundler"),
|
|
24
|
+
);
|
|
25
|
+
var _ResourceNotFoundError = _interopRequireDefault(
|
|
26
|
+
require("./IncrementalBundler/ResourceNotFoundError"),
|
|
27
|
+
);
|
|
28
|
+
var _bundleToString = _interopRequireDefault(require("./lib/bundleToString"));
|
|
29
|
+
var _formatBundlingError = _interopRequireDefault(
|
|
30
|
+
require("./lib/formatBundlingError"),
|
|
31
|
+
);
|
|
32
|
+
var _getGraphId = _interopRequireDefault(require("./lib/getGraphId"));
|
|
33
|
+
var _parseBundleOptionsFromBundleRequestUrl = _interopRequireDefault(
|
|
34
|
+
require("./lib/parseBundleOptionsFromBundleRequestUrl"),
|
|
35
|
+
);
|
|
36
|
+
var _parseJsonBody = _interopRequireDefault(require("./lib/parseJsonBody"));
|
|
37
|
+
var _splitBundleOptions = _interopRequireDefault(
|
|
38
|
+
require("./lib/splitBundleOptions"),
|
|
39
|
+
);
|
|
40
|
+
var transformHelpers = _interopRequireWildcard(
|
|
41
|
+
require("./lib/transformHelpers"),
|
|
42
|
+
);
|
|
43
|
+
var _ModuleResolution = require("./node-haste/DependencyGraph/ModuleResolution");
|
|
44
|
+
var _parsePlatformFilePath = _interopRequireDefault(
|
|
45
|
+
require("./node-haste/lib/parsePlatformFilePath"),
|
|
46
|
+
);
|
|
47
|
+
var _MultipartResponse = _interopRequireDefault(
|
|
48
|
+
require("./Server/MultipartResponse"),
|
|
49
|
+
);
|
|
50
|
+
var _symbolicate = _interopRequireDefault(require("./Server/symbolicate"));
|
|
51
|
+
var _types = require("./shared/types");
|
|
52
|
+
var _codeFrame = require("@babel/code-frame");
|
|
53
|
+
var fs = _interopRequireWildcard(require("graceful-fs"));
|
|
54
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
55
|
+
var jscSafeUrl = _interopRequireWildcard(require("jsc-safe-url"));
|
|
56
|
+
var _metroCore = require("metro-core");
|
|
57
|
+
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
58
|
+
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
59
|
+
var _path = _interopRequireDefault(require("path"));
|
|
60
|
+
var _perf_hooks = require("perf_hooks");
|
|
61
|
+
var _querystring = _interopRequireDefault(require("querystring"));
|
|
62
|
+
function _getRequireWildcardCache(e) {
|
|
63
|
+
if ("function" != typeof WeakMap) return null;
|
|
64
|
+
var r = new WeakMap(),
|
|
65
|
+
t = new WeakMap();
|
|
66
|
+
return (_getRequireWildcardCache = function (e) {
|
|
67
|
+
return e ? t : r;
|
|
68
|
+
})(e);
|
|
69
|
+
}
|
|
70
|
+
function _interopRequireWildcard(e, r) {
|
|
71
|
+
if (!r && e && e.__esModule) return e;
|
|
72
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
73
|
+
return { default: e };
|
|
74
|
+
var t = _getRequireWildcardCache(r);
|
|
75
|
+
if (t && t.has(e)) return t.get(e);
|
|
76
|
+
var n = { __proto__: null },
|
|
77
|
+
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
78
|
+
for (var u in e)
|
|
79
|
+
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
80
|
+
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
81
|
+
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
82
|
+
}
|
|
83
|
+
return ((n.default = e), t && t.set(e, n), n);
|
|
84
|
+
}
|
|
85
|
+
function _interopRequireDefault(e) {
|
|
86
|
+
return e && e.__esModule ? e : { default: e };
|
|
87
|
+
}
|
|
31
88
|
const debug = require("debug")("Metro:Server");
|
|
32
|
-
const
|
|
33
|
-
const invariant = require("invariant");
|
|
34
|
-
const jscSafeUrl = require("jsc-safe-url");
|
|
35
|
-
const {
|
|
36
|
-
Logger,
|
|
37
|
-
Logger: { createActionStartEntry, createActionEndEntry, log },
|
|
38
|
-
} = require("metro-core");
|
|
39
|
-
const mime = require("mime-types");
|
|
40
|
-
const nullthrows = require("nullthrows");
|
|
41
|
-
const path = require("path");
|
|
42
|
-
const { performance } = require("perf_hooks");
|
|
43
|
-
const querystring = require("querystring");
|
|
44
|
-
const url = require("url");
|
|
89
|
+
const { createActionStartEntry, createActionEndEntry, log } = _metroCore.Logger;
|
|
45
90
|
const noopLogger = {
|
|
46
91
|
start: () => {},
|
|
47
92
|
point: () => {},
|
|
@@ -62,7 +107,7 @@ class Server {
|
|
|
62
107
|
});
|
|
63
108
|
}
|
|
64
109
|
this._reporter = config.reporter;
|
|
65
|
-
this._logger = Logger;
|
|
110
|
+
this._logger = _metroCore.Logger;
|
|
66
111
|
this._platforms = new Set(this._config.resolver.platforms);
|
|
67
112
|
this._allowedSuffixesForSourceRequests = [
|
|
68
113
|
...new Set(
|
|
@@ -70,19 +115,19 @@ class Server {
|
|
|
70
115
|
...this._config.resolver.sourceExts,
|
|
71
116
|
...this._config.watcher.additionalExts,
|
|
72
117
|
...this._config.resolver.assetExts,
|
|
73
|
-
].map((ext) => "." + ext)
|
|
118
|
+
].map((ext) => "." + ext),
|
|
74
119
|
),
|
|
75
120
|
];
|
|
76
121
|
this._sourceRequestRoutingMap = [
|
|
77
|
-
["/[metro-project]/",
|
|
122
|
+
["/[metro-project]/", _path.default.resolve(this._config.projectRoot)],
|
|
78
123
|
...this._config.watchFolders.map((watchFolder, index) => [
|
|
79
124
|
`/[metro-watchFolders]/${index}/`,
|
|
80
|
-
|
|
125
|
+
_path.default.resolve(watchFolder),
|
|
81
126
|
]),
|
|
82
127
|
];
|
|
83
128
|
this._isEnded = false;
|
|
84
129
|
this._createModuleId = config.serializer.createModuleIdFactory();
|
|
85
|
-
this._bundler = new
|
|
130
|
+
this._bundler = new _IncrementalBundler.default(config, {
|
|
86
131
|
hasReducedPerformance: options && options.hasReducedPerformance,
|
|
87
132
|
watch: options ? options.watch : undefined,
|
|
88
133
|
});
|
|
@@ -116,18 +161,19 @@ class Server {
|
|
|
116
161
|
relativeTo: "project",
|
|
117
162
|
resolverOptions,
|
|
118
163
|
transformOptions,
|
|
119
|
-
}
|
|
164
|
+
},
|
|
120
165
|
),
|
|
121
166
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
122
167
|
createModuleId: this._createModuleId,
|
|
123
168
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
169
|
+
globalPrefix: this._config.transformer.globalPrefix,
|
|
124
170
|
dev: transformOptions.dev,
|
|
125
171
|
includeAsyncPaths: graphOptions.lazy,
|
|
126
172
|
projectRoot: this._config.projectRoot,
|
|
127
173
|
modulesOnly: serializerOptions.modulesOnly,
|
|
128
174
|
runBeforeMainModule:
|
|
129
175
|
this._config.serializer.getModulesRunBeforeMainModule(
|
|
130
|
-
|
|
176
|
+
_path.default.relative(this._config.projectRoot, entryPoint),
|
|
131
177
|
),
|
|
132
178
|
runModule: serializerOptions.runModule,
|
|
133
179
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
@@ -147,7 +193,7 @@ class Server {
|
|
|
147
193
|
entryPoint,
|
|
148
194
|
prepend,
|
|
149
195
|
graph,
|
|
150
|
-
bundleOptions
|
|
196
|
+
bundleOptions,
|
|
151
197
|
);
|
|
152
198
|
if (typeof bundle === "string") {
|
|
153
199
|
bundleCode = bundle;
|
|
@@ -156,12 +202,12 @@ class Server {
|
|
|
156
202
|
bundleMap = bundle.map;
|
|
157
203
|
}
|
|
158
204
|
} else {
|
|
159
|
-
bundleCode =
|
|
160
|
-
|
|
205
|
+
bundleCode = (0, _bundleToString.default)(
|
|
206
|
+
(0, _baseJSBundle.default)(entryPoint, prepend, graph, bundleOptions),
|
|
161
207
|
).code;
|
|
162
208
|
}
|
|
163
209
|
if (!bundleMap) {
|
|
164
|
-
bundleMap = await sourceMapStringNonBlocking(
|
|
210
|
+
bundleMap = await (0, _sourceMapString.sourceMapStringNonBlocking)(
|
|
165
211
|
[...prepend, ...this._getSortedModules(graph)],
|
|
166
212
|
{
|
|
167
213
|
excludeSource: serializerOptions.excludeSource,
|
|
@@ -169,7 +215,7 @@ class Server {
|
|
|
169
215
|
shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList,
|
|
170
216
|
getSourceUrl: (module) =>
|
|
171
217
|
this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
|
|
172
|
-
}
|
|
218
|
+
},
|
|
173
219
|
);
|
|
174
220
|
}
|
|
175
221
|
return {
|
|
@@ -178,7 +224,7 @@ class Server {
|
|
|
178
224
|
};
|
|
179
225
|
}
|
|
180
226
|
async build(bundleOptions, { withAssets } = {}) {
|
|
181
|
-
const splitOptions =
|
|
227
|
+
const splitOptions = (0, _splitBundleOptions.default)(bundleOptions);
|
|
182
228
|
const {
|
|
183
229
|
entryFile,
|
|
184
230
|
graphOptions,
|
|
@@ -194,7 +240,7 @@ class Server {
|
|
|
194
240
|
onProgress,
|
|
195
241
|
shallow: graphOptions.shallow,
|
|
196
242
|
lazy: graphOptions.lazy,
|
|
197
|
-
}
|
|
243
|
+
},
|
|
198
244
|
);
|
|
199
245
|
const [{ code, map }, assets] = await Promise.all([
|
|
200
246
|
this._serializeGraph({
|
|
@@ -205,7 +251,7 @@ class Server {
|
|
|
205
251
|
withAssets
|
|
206
252
|
? this._getAssetsFromDependencies(
|
|
207
253
|
graph.dependencies,
|
|
208
|
-
bundleOptions.platform
|
|
254
|
+
bundleOptions.platform,
|
|
209
255
|
)
|
|
210
256
|
: null,
|
|
211
257
|
]);
|
|
@@ -214,7 +260,7 @@ class Server {
|
|
|
214
260
|
map,
|
|
215
261
|
...(withAssets
|
|
216
262
|
? {
|
|
217
|
-
assets:
|
|
263
|
+
assets: (0, _nullthrows.default)(assets),
|
|
218
264
|
}
|
|
219
265
|
: null),
|
|
220
266
|
};
|
|
@@ -227,7 +273,7 @@ class Server {
|
|
|
227
273
|
resolverOptions,
|
|
228
274
|
serializerOptions,
|
|
229
275
|
transformOptions,
|
|
230
|
-
} =
|
|
276
|
+
} = (0, _splitBundleOptions.default)(options);
|
|
231
277
|
const { prepend, graph } = await this._bundler.buildGraph(
|
|
232
278
|
entryFile,
|
|
233
279
|
transformOptions,
|
|
@@ -236,17 +282,17 @@ class Server {
|
|
|
236
282
|
onProgress,
|
|
237
283
|
shallow: graphOptions.shallow,
|
|
238
284
|
lazy: graphOptions.lazy,
|
|
239
|
-
}
|
|
285
|
+
},
|
|
240
286
|
);
|
|
241
287
|
const entryPoint = this._getEntryPointAbsolutePath(entryFile);
|
|
242
|
-
return await
|
|
288
|
+
return await (0, _getRamBundleInfo.default)(entryPoint, prepend, graph, {
|
|
243
289
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
244
290
|
this._config.transformer.asyncRequireModulePath,
|
|
245
291
|
{
|
|
246
292
|
relativeTo: "project",
|
|
247
293
|
resolverOptions,
|
|
248
294
|
transformOptions,
|
|
249
|
-
}
|
|
295
|
+
},
|
|
250
296
|
),
|
|
251
297
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
252
298
|
createModuleId: this._createModuleId,
|
|
@@ -254,13 +300,14 @@ class Server {
|
|
|
254
300
|
excludeSource: serializerOptions.excludeSource,
|
|
255
301
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
256
302
|
getTransformOptions: this._config.transformer.getTransformOptions,
|
|
303
|
+
globalPrefix: this._config.transformer.globalPrefix,
|
|
257
304
|
includeAsyncPaths: graphOptions.lazy,
|
|
258
305
|
platform: transformOptions.platform,
|
|
259
306
|
projectRoot: this._config.projectRoot,
|
|
260
307
|
modulesOnly: serializerOptions.modulesOnly,
|
|
261
308
|
runBeforeMainModule:
|
|
262
309
|
this._config.serializer.getModulesRunBeforeMainModule(
|
|
263
|
-
|
|
310
|
+
_path.default.relative(this._config.projectRoot, entryPoint),
|
|
264
311
|
),
|
|
265
312
|
runModule: serializerOptions.runModule,
|
|
266
313
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
@@ -275,8 +322,8 @@ class Server {
|
|
|
275
322
|
});
|
|
276
323
|
}
|
|
277
324
|
async getAssets(options) {
|
|
278
|
-
const { entryFile, onProgress, resolverOptions, transformOptions } =
|
|
279
|
-
|
|
325
|
+
const { entryFile, onProgress, resolverOptions, transformOptions } = (0,
|
|
326
|
+
_splitBundleOptions.default)(options);
|
|
280
327
|
const dependencies = await this._bundler.getDependencies(
|
|
281
328
|
[entryFile],
|
|
282
329
|
transformOptions,
|
|
@@ -285,15 +332,15 @@ class Server {
|
|
|
285
332
|
onProgress,
|
|
286
333
|
shallow: false,
|
|
287
334
|
lazy: false,
|
|
288
|
-
}
|
|
335
|
+
},
|
|
289
336
|
);
|
|
290
337
|
return this._getAssetsFromDependencies(
|
|
291
338
|
dependencies,
|
|
292
|
-
transformOptions.platform
|
|
339
|
+
transformOptions.platform,
|
|
293
340
|
);
|
|
294
341
|
}
|
|
295
342
|
async _getAssetsFromDependencies(dependencies, platform) {
|
|
296
|
-
return await
|
|
343
|
+
return await (0, _getAssets.default)(dependencies, {
|
|
297
344
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
298
345
|
assetPlugins: this._config.transformer.assetPlugins,
|
|
299
346
|
platform,
|
|
@@ -302,11 +349,11 @@ class Server {
|
|
|
302
349
|
});
|
|
303
350
|
}
|
|
304
351
|
async getOrderedDependencyPaths(options) {
|
|
305
|
-
const { entryFile, onProgress, resolverOptions, transformOptions } =
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
352
|
+
const { entryFile, onProgress, resolverOptions, transformOptions } = (0,
|
|
353
|
+
_splitBundleOptions.default)({
|
|
354
|
+
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
355
|
+
...options,
|
|
356
|
+
});
|
|
310
357
|
const { prepend, graph } = await this._bundler.buildGraph(
|
|
311
358
|
entryFile,
|
|
312
359
|
transformOptions,
|
|
@@ -315,12 +362,12 @@ class Server {
|
|
|
315
362
|
onProgress,
|
|
316
363
|
shallow: false,
|
|
317
364
|
lazy: false,
|
|
318
|
-
}
|
|
365
|
+
},
|
|
319
366
|
);
|
|
320
367
|
const platform =
|
|
321
368
|
transformOptions.platform ||
|
|
322
|
-
|
|
323
|
-
return await
|
|
369
|
+
(0, _parsePlatformFilePath.default)(entryFile, this._platforms).platform;
|
|
370
|
+
return await (0, _getAllFiles.default)(prepend, graph, {
|
|
324
371
|
platform,
|
|
325
372
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
326
373
|
});
|
|
@@ -344,18 +391,35 @@ class Server {
|
|
|
344
391
|
return data;
|
|
345
392
|
}
|
|
346
393
|
async _processSingleAssetRequest(req, res) {
|
|
347
|
-
|
|
394
|
+
debug("Processing single asset request: %s", req.url);
|
|
395
|
+
if (!URL.canParse(req.url, "resolve://")) {
|
|
396
|
+
throw new Error("Could not parse URL", {
|
|
397
|
+
cause: req.url,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const urlObj = new URL(req.url, "resolve://");
|
|
401
|
+
const formattedUrl = urlObj.toString();
|
|
402
|
+
if (req.url !== formattedUrl) {
|
|
403
|
+
debug("Formatted as: %s", formattedUrl);
|
|
404
|
+
}
|
|
348
405
|
let [, assetPath] =
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
406
|
+
urlObj.pathname
|
|
407
|
+
.split("/")
|
|
408
|
+
.map((segment) => decodeURIComponent(segment))
|
|
409
|
+
.join("/")
|
|
410
|
+
.match(/^\/assets\/(.+)$/) || [];
|
|
411
|
+
if (!assetPath && urlObj.searchParams.get("unstable_path")) {
|
|
412
|
+
const [, actualPath, secondaryQuery] = (0, _nullthrows.default)(
|
|
413
|
+
(urlObj.searchParams.get("unstable_path") || "").match(
|
|
414
|
+
/^([^?]*)\??(.*)$/,
|
|
415
|
+
),
|
|
356
416
|
);
|
|
357
417
|
if (secondaryQuery) {
|
|
358
|
-
Object.
|
|
418
|
+
Object.entries(_querystring.default.parse(secondaryQuery)).forEach(
|
|
419
|
+
([key, value]) => {
|
|
420
|
+
urlObj.searchParams.set(key, value);
|
|
421
|
+
},
|
|
422
|
+
);
|
|
359
423
|
}
|
|
360
424
|
assetPath = actualPath;
|
|
361
425
|
}
|
|
@@ -366,20 +430,23 @@ class Server {
|
|
|
366
430
|
createActionStartEntry({
|
|
367
431
|
action_name: "Processing asset request",
|
|
368
432
|
asset: assetPath[1],
|
|
369
|
-
})
|
|
433
|
+
}),
|
|
370
434
|
);
|
|
371
435
|
try {
|
|
372
|
-
const data = await getAsset(
|
|
436
|
+
const data = await (0, _Assets.getAsset)(
|
|
373
437
|
assetPath,
|
|
374
438
|
this._config.projectRoot,
|
|
375
439
|
this._config.watchFolders,
|
|
376
|
-
urlObj.
|
|
377
|
-
this._config.resolver.assetExts
|
|
440
|
+
urlObj.searchParams.get("platform"),
|
|
441
|
+
this._config.resolver.assetExts,
|
|
378
442
|
);
|
|
379
443
|
if (process.env.REACT_NATIVE_ENABLE_ASSET_CACHING === true) {
|
|
380
444
|
res.setHeader("Cache-Control", "max-age=31536000");
|
|
381
445
|
}
|
|
382
|
-
res.setHeader(
|
|
446
|
+
res.setHeader(
|
|
447
|
+
"Content-Type",
|
|
448
|
+
_mimeTypes.default.lookup(_path.default.basename(assetPath)),
|
|
449
|
+
);
|
|
383
450
|
res.end(this._rangeRequestMiddleware(req, res, data, assetPath));
|
|
384
451
|
process.nextTick(() => {
|
|
385
452
|
log(createActionEndEntry(processingAssetRequestLogEntry));
|
|
@@ -394,32 +461,42 @@ class Server {
|
|
|
394
461
|
this._processRequest(req, res, next).catch(next);
|
|
395
462
|
};
|
|
396
463
|
_parseOptions(url) {
|
|
397
|
-
const { bundleType: _bundleType, ...bundleOptions } =
|
|
464
|
+
const { bundleType: _bundleType, ...bundleOptions } = (0,
|
|
465
|
+
_parseBundleOptionsFromBundleRequestUrl.default)(
|
|
398
466
|
url,
|
|
399
|
-
new Set(this._config.resolver.platforms)
|
|
467
|
+
new Set(this._config.resolver.platforms),
|
|
400
468
|
);
|
|
401
469
|
return bundleOptions;
|
|
402
470
|
}
|
|
403
471
|
_rewriteAndNormalizeUrl(requestUrl) {
|
|
404
472
|
return jscSafeUrl.toNormalUrl(
|
|
405
|
-
this._config.server.rewriteRequestUrl(jscSafeUrl.toNormalUrl(requestUrl))
|
|
473
|
+
this._config.server.rewriteRequestUrl(jscSafeUrl.toNormalUrl(requestUrl)),
|
|
406
474
|
);
|
|
407
475
|
}
|
|
408
476
|
async _processRequest(req, res, next) {
|
|
409
477
|
const originalUrl = req.url;
|
|
478
|
+
debug("Handling request: %s", originalUrl);
|
|
410
479
|
req.url = this._rewriteAndNormalizeUrl(req.url);
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
480
|
+
if (req.url !== originalUrl) {
|
|
481
|
+
debug("Rewritten to: %s", req.url);
|
|
482
|
+
}
|
|
483
|
+
const reqHost = req.headers["x-forwarded-host"] || req.headers["host"];
|
|
484
|
+
if (!reqHost) {
|
|
485
|
+
throw new Error("No host header was found.");
|
|
486
|
+
}
|
|
487
|
+
const reqProtocol =
|
|
488
|
+
req.headers["x-forwarded-proto"] ||
|
|
489
|
+
(req.socket?.encrypted === true ? "https" : "http");
|
|
490
|
+
const urlObj = new URL(req.url, reqProtocol + "://" + reqHost);
|
|
491
|
+
const formattedUrl = urlObj.toString();
|
|
492
|
+
if (req.url !== formattedUrl) {
|
|
493
|
+
debug("Formatted as: %s", formattedUrl);
|
|
494
|
+
}
|
|
422
495
|
const pathname = urlObj.pathname || "";
|
|
496
|
+
const filePathname = pathname
|
|
497
|
+
.split("/")
|
|
498
|
+
.map((segment) => decodeURIComponent(segment))
|
|
499
|
+
.join("/");
|
|
423
500
|
const buildNumber = this.getNewBuildNumber();
|
|
424
501
|
if (pathname.endsWith(".bundle")) {
|
|
425
502
|
const options = this._parseOptions(formattedUrl);
|
|
@@ -431,7 +508,7 @@ class Server {
|
|
|
431
508
|
}) ?? noopLogger,
|
|
432
509
|
});
|
|
433
510
|
if (this._serverOptions && this._serverOptions.onBundleBuilt) {
|
|
434
|
-
this._serverOptions.onBundleBuilt(
|
|
511
|
+
this._serverOptions.onBundleBuilt(filePathname);
|
|
435
512
|
}
|
|
436
513
|
} else if (pathname.endsWith(".map")) {
|
|
437
514
|
res.setHeader("Access-Control-Allow-Origin", "devtools://devtools");
|
|
@@ -442,7 +519,7 @@ class Server {
|
|
|
442
519
|
{
|
|
443
520
|
buildNumber,
|
|
444
521
|
bundlePerfLogger: noopLogger,
|
|
445
|
-
}
|
|
522
|
+
},
|
|
446
523
|
);
|
|
447
524
|
} else if (pathname.endsWith(".assets")) {
|
|
448
525
|
await this._processAssetsRequest(
|
|
@@ -452,7 +529,7 @@ class Server {
|
|
|
452
529
|
{
|
|
453
530
|
buildNumber,
|
|
454
531
|
bundlePerfLogger: noopLogger,
|
|
455
|
-
}
|
|
532
|
+
},
|
|
456
533
|
);
|
|
457
534
|
} else if (pathname.startsWith("/assets/") || pathname === "/assets") {
|
|
458
535
|
await this._processSingleAssetRequest(req, res);
|
|
@@ -462,12 +539,14 @@ class Server {
|
|
|
462
539
|
let handled = false;
|
|
463
540
|
for (const [pathnamePrefix, normalizedRootDir] of this
|
|
464
541
|
._sourceRequestRoutingMap) {
|
|
465
|
-
if (
|
|
466
|
-
const
|
|
542
|
+
if (filePathname.startsWith(pathnamePrefix)) {
|
|
543
|
+
const relativeFilePathname = filePathname.substr(
|
|
544
|
+
pathnamePrefix.length,
|
|
545
|
+
);
|
|
467
546
|
await this._processSourceRequest(
|
|
468
|
-
|
|
547
|
+
relativeFilePathname,
|
|
469
548
|
normalizedRootDir,
|
|
470
|
-
res
|
|
549
|
+
res,
|
|
471
550
|
);
|
|
472
551
|
handled = true;
|
|
473
552
|
break;
|
|
@@ -478,10 +557,10 @@ class Server {
|
|
|
478
557
|
}
|
|
479
558
|
}
|
|
480
559
|
}
|
|
481
|
-
async _processSourceRequest(
|
|
560
|
+
async _processSourceRequest(relativeFilePathname, rootDir, res) {
|
|
482
561
|
if (
|
|
483
562
|
!this._allowedSuffixesForSourceRequests.some((suffix) =>
|
|
484
|
-
|
|
563
|
+
relativeFilePathname.endsWith(suffix),
|
|
485
564
|
)
|
|
486
565
|
) {
|
|
487
566
|
res.writeHead(404);
|
|
@@ -489,7 +568,7 @@ class Server {
|
|
|
489
568
|
return;
|
|
490
569
|
}
|
|
491
570
|
const depGraph = await this._bundler.getBundler().getDependencyGraph();
|
|
492
|
-
const filePath =
|
|
571
|
+
const filePath = _path.default.join(rootDir, relativeFilePathname);
|
|
493
572
|
try {
|
|
494
573
|
await depGraph.getOrComputeSha1(filePath);
|
|
495
574
|
} catch {
|
|
@@ -497,7 +576,9 @@ class Server {
|
|
|
497
576
|
res.end();
|
|
498
577
|
return;
|
|
499
578
|
}
|
|
500
|
-
const mimeType =
|
|
579
|
+
const mimeType = _mimeTypes.default.lookup(
|
|
580
|
+
_path.default.basename(relativeFilePathname),
|
|
581
|
+
);
|
|
501
582
|
res.setHeader("Content-Type", mimeType);
|
|
502
583
|
const stream = fs.createReadStream(filePath);
|
|
503
584
|
stream.pipe(res);
|
|
@@ -523,9 +604,10 @@ class Server {
|
|
|
523
604
|
req,
|
|
524
605
|
res,
|
|
525
606
|
bundleOptions,
|
|
526
|
-
buildContext
|
|
607
|
+
buildContext,
|
|
527
608
|
) {
|
|
528
|
-
const requestStartTimestamp =
|
|
609
|
+
const requestStartTimestamp =
|
|
610
|
+
_perf_hooks.performance.timeOrigin + _perf_hooks.performance.now();
|
|
529
611
|
const { buildNumber } = buildContext;
|
|
530
612
|
const {
|
|
531
613
|
entryFile,
|
|
@@ -533,7 +615,7 @@ class Server {
|
|
|
533
615
|
resolverOptions,
|
|
534
616
|
serializerOptions,
|
|
535
617
|
transformOptions,
|
|
536
|
-
} =
|
|
618
|
+
} = (0, _splitBundleOptions.default)(bundleOptions);
|
|
537
619
|
let resolvedEntryFilePath;
|
|
538
620
|
try {
|
|
539
621
|
resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
@@ -542,21 +624,26 @@ class Server {
|
|
|
542
624
|
transformOptions,
|
|
543
625
|
});
|
|
544
626
|
} catch (error) {
|
|
545
|
-
const formattedError =
|
|
546
|
-
const status =
|
|
627
|
+
const formattedError = (0, _formatBundlingError.default)(error);
|
|
628
|
+
const status =
|
|
629
|
+
error instanceof _ModuleResolution.UnableToResolveError ? 404 : 500;
|
|
547
630
|
res.writeHead(status, {
|
|
548
631
|
"Content-Type": "application/json; charset=UTF-8",
|
|
549
632
|
});
|
|
550
633
|
res.end(JSON.stringify(formattedError));
|
|
551
634
|
return;
|
|
552
635
|
}
|
|
553
|
-
const graphId =
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
636
|
+
const graphId = (0, _getGraphId.default)(
|
|
637
|
+
resolvedEntryFilePath,
|
|
638
|
+
transformOptions,
|
|
639
|
+
{
|
|
640
|
+
unstable_allowRequireContext:
|
|
641
|
+
this._config.transformer.unstable_allowRequireContext,
|
|
642
|
+
resolverOptions,
|
|
643
|
+
shallow: graphOptions.shallow,
|
|
644
|
+
lazy: graphOptions.lazy,
|
|
645
|
+
},
|
|
646
|
+
);
|
|
560
647
|
if (deleteFn && req.method === "DELETE") {
|
|
561
648
|
const deleteContext = {
|
|
562
649
|
graphId,
|
|
@@ -566,8 +653,9 @@ class Server {
|
|
|
566
653
|
try {
|
|
567
654
|
await deleteFn(deleteContext);
|
|
568
655
|
} catch (error) {
|
|
569
|
-
const formattedError =
|
|
570
|
-
const status =
|
|
656
|
+
const formattedError = (0, _formatBundlingError.default)(error);
|
|
657
|
+
const status =
|
|
658
|
+
error instanceof _ResourceNotFoundError.default ? 404 : 500;
|
|
571
659
|
res.writeHead(status, {
|
|
572
660
|
"Content-Type": "application/json; charset=UTF-8",
|
|
573
661
|
});
|
|
@@ -575,17 +663,17 @@ class Server {
|
|
|
575
663
|
}
|
|
576
664
|
return;
|
|
577
665
|
}
|
|
578
|
-
const mres =
|
|
666
|
+
const mres = _MultipartResponse.default.wrapIfSupported(req, res);
|
|
579
667
|
let onProgress = null;
|
|
580
668
|
let lastProgress = -1;
|
|
581
669
|
if (this._config.reporter) {
|
|
582
670
|
onProgress = (transformedFileCount, totalFileCount) => {
|
|
583
671
|
const currentProgress = parseInt(
|
|
584
672
|
(transformedFileCount / totalFileCount) * 100,
|
|
585
|
-
10
|
|
673
|
+
10,
|
|
586
674
|
);
|
|
587
675
|
if (currentProgress > lastProgress || totalFileCount < 10) {
|
|
588
|
-
if (mres instanceof
|
|
676
|
+
if (mres instanceof _MultipartResponse.default) {
|
|
589
677
|
mres.writeChunk(
|
|
590
678
|
{
|
|
591
679
|
"Content-Type": "application/json",
|
|
@@ -593,7 +681,7 @@ class Server {
|
|
|
593
681
|
JSON.stringify({
|
|
594
682
|
done: transformedFileCount,
|
|
595
683
|
total: totalFileCount,
|
|
596
|
-
})
|
|
684
|
+
}),
|
|
597
685
|
);
|
|
598
686
|
}
|
|
599
687
|
if (res.socket != null && res.socket.uncork != null) {
|
|
@@ -639,14 +727,15 @@ class Server {
|
|
|
639
727
|
requestStartTimestamp,
|
|
640
728
|
};
|
|
641
729
|
const logEntry = log(
|
|
642
|
-
createActionStartEntry(createStartEntry(startContext))
|
|
730
|
+
createActionStartEntry(createStartEntry(startContext)),
|
|
643
731
|
);
|
|
644
732
|
let result;
|
|
645
733
|
try {
|
|
646
734
|
result = await build(startContext);
|
|
647
735
|
} catch (error) {
|
|
648
|
-
const formattedError =
|
|
649
|
-
const status =
|
|
736
|
+
const formattedError = (0, _formatBundlingError.default)(error);
|
|
737
|
+
const status =
|
|
738
|
+
error instanceof _ResourceNotFoundError.default ? 404 : 500;
|
|
650
739
|
mres.writeHead(status, {
|
|
651
740
|
"Content-Type": "application/json; charset=UTF-8",
|
|
652
741
|
});
|
|
@@ -685,7 +774,7 @@ class Server {
|
|
|
685
774
|
createActionEndEntry({
|
|
686
775
|
...logEntry,
|
|
687
776
|
...createEndEntry(endContext),
|
|
688
|
-
})
|
|
777
|
+
}),
|
|
689
778
|
);
|
|
690
779
|
};
|
|
691
780
|
}
|
|
@@ -744,7 +833,7 @@ class Server {
|
|
|
744
833
|
onProgress,
|
|
745
834
|
shallow: graphOptions.shallow,
|
|
746
835
|
lazy: graphOptions.lazy,
|
|
747
|
-
}
|
|
836
|
+
},
|
|
748
837
|
));
|
|
749
838
|
bundlePerfLogger.annotate({
|
|
750
839
|
int: {
|
|
@@ -756,8 +845,9 @@ class Server {
|
|
|
756
845
|
const serializer =
|
|
757
846
|
this._config.serializer.customSerializer ||
|
|
758
847
|
((entryPoint, preModules, graph, options) =>
|
|
759
|
-
|
|
760
|
-
.
|
|
848
|
+
(0, _bundleToString.default)(
|
|
849
|
+
(0, _baseJSBundle.default)(entryPoint, preModules, graph, options),
|
|
850
|
+
).code);
|
|
761
851
|
const bundle = await serializer(
|
|
762
852
|
entryFile,
|
|
763
853
|
revision.prepend,
|
|
@@ -769,18 +859,19 @@ class Server {
|
|
|
769
859
|
relativeTo: "project",
|
|
770
860
|
resolverOptions,
|
|
771
861
|
transformOptions,
|
|
772
|
-
}
|
|
862
|
+
},
|
|
773
863
|
),
|
|
774
864
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
775
865
|
createModuleId: this._createModuleId,
|
|
776
866
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
867
|
+
globalPrefix: this._config.transformer.globalPrefix,
|
|
777
868
|
includeAsyncPaths: graphOptions.lazy,
|
|
778
869
|
dev: transformOptions.dev,
|
|
779
870
|
projectRoot: this._config.projectRoot,
|
|
780
871
|
modulesOnly: serializerOptions.modulesOnly,
|
|
781
872
|
runBeforeMainModule:
|
|
782
873
|
this._config.serializer.getModulesRunBeforeMainModule(
|
|
783
|
-
|
|
874
|
+
_path.default.relative(this._config.projectRoot, entryFile),
|
|
784
875
|
),
|
|
785
876
|
runModule: serializerOptions.runModule,
|
|
786
877
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
@@ -792,7 +883,7 @@ class Server {
|
|
|
792
883
|
this._shouldAddModuleToIgnoreList(module),
|
|
793
884
|
getSourceUrl: (module) =>
|
|
794
885
|
this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
|
|
795
|
-
}
|
|
886
|
+
},
|
|
796
887
|
);
|
|
797
888
|
bundlePerfLogger.point("serializingBundle_end");
|
|
798
889
|
const bundleCode = typeof bundle === "string" ? bundle : bundle.code;
|
|
@@ -838,7 +929,7 @@ class Server {
|
|
|
838
929
|
});
|
|
839
930
|
mres.setHeader(
|
|
840
931
|
FILES_CHANGED_COUNT_HEADER,
|
|
841
|
-
String(result.numModifiedFiles)
|
|
932
|
+
String(result.numModifiedFiles),
|
|
842
933
|
);
|
|
843
934
|
mres.setHeader(DELTA_ID_HEADER, String(result.nextRevId));
|
|
844
935
|
if (serializerOptions?.sourceUrl != null) {
|
|
@@ -848,7 +939,7 @@ class Server {
|
|
|
848
939
|
mres.setHeader("Last-Modified", result.lastModifiedDate.toUTCString());
|
|
849
940
|
mres.setHeader(
|
|
850
941
|
"Content-Length",
|
|
851
|
-
String(Buffer.byteLength(result.bundle))
|
|
942
|
+
String(Buffer.byteLength(result.bundle)),
|
|
852
943
|
);
|
|
853
944
|
mres.end(result.bundle);
|
|
854
945
|
}
|
|
@@ -865,7 +956,7 @@ class Server {
|
|
|
865
956
|
this._createModuleId(module.path);
|
|
866
957
|
}
|
|
867
958
|
return modules.sort(
|
|
868
|
-
(a, b) => this._createModuleId(a.path) - this._createModuleId(b.path)
|
|
959
|
+
(a, b) => this._createModuleId(a.path) - this._createModuleId(b.path),
|
|
869
960
|
);
|
|
870
961
|
}
|
|
871
962
|
_processSourceMapRequest = this._createRequestProcessor({
|
|
@@ -903,19 +994,19 @@ class Server {
|
|
|
903
994
|
onProgress,
|
|
904
995
|
shallow: graphOptions.shallow,
|
|
905
996
|
lazy: graphOptions.lazy,
|
|
906
|
-
}
|
|
997
|
+
},
|
|
907
998
|
));
|
|
908
999
|
} else {
|
|
909
1000
|
({ revision } = await this._bundler.updateGraph(
|
|
910
1001
|
await revPromise,
|
|
911
|
-
false
|
|
1002
|
+
false,
|
|
912
1003
|
));
|
|
913
1004
|
}
|
|
914
1005
|
let { prepend, graph } = revision;
|
|
915
1006
|
if (serializerOptions.modulesOnly) {
|
|
916
1007
|
prepend = [];
|
|
917
1008
|
}
|
|
918
|
-
return await sourceMapStringNonBlocking(
|
|
1009
|
+
return await (0, _sourceMapString.sourceMapStringNonBlocking)(
|
|
919
1010
|
[...prepend, ...this._getSortedModules(graph)],
|
|
920
1011
|
{
|
|
921
1012
|
excludeSource: serializerOptions.excludeSource,
|
|
@@ -924,7 +1015,7 @@ class Server {
|
|
|
924
1015
|
this._shouldAddModuleToIgnoreList(module),
|
|
925
1016
|
getSourceUrl: (module) =>
|
|
926
1017
|
this._getModuleSourceUrl(module, serializerOptions.sourcePaths),
|
|
927
|
-
}
|
|
1018
|
+
},
|
|
928
1019
|
);
|
|
929
1020
|
},
|
|
930
1021
|
finish({ mres, result }) {
|
|
@@ -961,9 +1052,9 @@ class Server {
|
|
|
961
1052
|
onProgress,
|
|
962
1053
|
shallow: false,
|
|
963
1054
|
lazy: false,
|
|
964
|
-
}
|
|
1055
|
+
},
|
|
965
1056
|
);
|
|
966
|
-
return await
|
|
1057
|
+
return await (0, _getAssets.default)(dependencies, {
|
|
967
1058
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
968
1059
|
assetPlugins: this._config.transformer.assetPlugins,
|
|
969
1060
|
platform: transformOptions.platform,
|
|
@@ -979,7 +1070,7 @@ class Server {
|
|
|
979
1070
|
async _symbolicate(req, res) {
|
|
980
1071
|
const getCodeFrame = (urls, symbolicatedStack) => {
|
|
981
1072
|
const allFramesCollapsed = symbolicatedStack.every(
|
|
982
|
-
({ collapse }) => collapse
|
|
1073
|
+
({ collapse }) => collapse,
|
|
983
1074
|
);
|
|
984
1075
|
for (let i = 0; i < symbolicatedStack.length; i++) {
|
|
985
1076
|
const { collapse, column, file, lineNumber } = symbolicatedStack[i];
|
|
@@ -990,10 +1081,13 @@ class Server {
|
|
|
990
1081
|
) {
|
|
991
1082
|
continue;
|
|
992
1083
|
}
|
|
993
|
-
const fileAbsolute =
|
|
1084
|
+
const fileAbsolute = _path.default.resolve(
|
|
1085
|
+
this._config.projectRoot,
|
|
1086
|
+
file ?? "",
|
|
1087
|
+
);
|
|
994
1088
|
try {
|
|
995
1089
|
return {
|
|
996
|
-
content: codeFrameColumns(
|
|
1090
|
+
content: (0, _codeFrame.codeFrameColumns)(
|
|
997
1091
|
fs.readFileSync(fileAbsolute, "utf8"),
|
|
998
1092
|
{
|
|
999
1093
|
start: {
|
|
@@ -1003,7 +1097,7 @@ class Server {
|
|
|
1003
1097
|
},
|
|
1004
1098
|
{
|
|
1005
1099
|
forceColor: true,
|
|
1006
|
-
}
|
|
1100
|
+
},
|
|
1007
1101
|
),
|
|
1008
1102
|
location: {
|
|
1009
1103
|
row: lineNumber,
|
|
@@ -1012,14 +1106,18 @@ class Server {
|
|
|
1012
1106
|
fileName: file,
|
|
1013
1107
|
};
|
|
1014
1108
|
} catch (error) {
|
|
1015
|
-
|
|
1109
|
+
debug(
|
|
1110
|
+
"Generating code frame failed on file read.",
|
|
1111
|
+
fileAbsolute,
|
|
1112
|
+
error,
|
|
1113
|
+
);
|
|
1016
1114
|
}
|
|
1017
1115
|
}
|
|
1018
1116
|
return null;
|
|
1019
1117
|
};
|
|
1020
1118
|
try {
|
|
1021
1119
|
const symbolicatingLogEntry = log(
|
|
1022
|
-
createActionStartEntry("Symbolicating")
|
|
1120
|
+
createActionStartEntry("Symbolicating"),
|
|
1023
1121
|
);
|
|
1024
1122
|
debug("Start symbolication");
|
|
1025
1123
|
let parsedBody;
|
|
@@ -1027,14 +1125,14 @@ class Server {
|
|
|
1027
1125
|
const body = await req.rawBody;
|
|
1028
1126
|
parsedBody = JSON.parse(body);
|
|
1029
1127
|
} else {
|
|
1030
|
-
parsedBody = await
|
|
1128
|
+
parsedBody = await (0, _parseJsonBody.default)(req);
|
|
1031
1129
|
}
|
|
1032
1130
|
const rewriteAndNormalizeStackFrame = (frame, lineNumber) => {
|
|
1033
|
-
|
|
1131
|
+
(0, _invariant.default)(
|
|
1034
1132
|
frame != null && typeof frame === "object",
|
|
1035
1133
|
"Bad stack frame at line %d, expected object, received: %s",
|
|
1036
1134
|
lineNumber,
|
|
1037
|
-
typeof frame
|
|
1135
|
+
typeof frame,
|
|
1038
1136
|
);
|
|
1039
1137
|
const frameFile = frame.file;
|
|
1040
1138
|
if (typeof frameFile === "string" && frameFile.includes("://")) {
|
|
@@ -1062,34 +1160,34 @@ class Server {
|
|
|
1062
1160
|
const sourceMaps = await Promise.all(
|
|
1063
1161
|
Array.from(urls.values()).map((normalizedUrl) =>
|
|
1064
1162
|
this._explodedSourceMapForBundleOptions(
|
|
1065
|
-
this._parseOptions(normalizedUrl)
|
|
1066
|
-
)
|
|
1067
|
-
)
|
|
1163
|
+
this._parseOptions(normalizedUrl),
|
|
1164
|
+
),
|
|
1165
|
+
),
|
|
1068
1166
|
);
|
|
1069
1167
|
debug("Performing fast symbolication");
|
|
1070
|
-
const symbolicatedStack = await
|
|
1168
|
+
const symbolicatedStack = await (0, _symbolicate.default)(
|
|
1071
1169
|
stack,
|
|
1072
1170
|
zip(urls.values(), sourceMaps),
|
|
1073
1171
|
this._config,
|
|
1074
|
-
parsedBody.extraData ?? {}
|
|
1172
|
+
parsedBody.extraData ?? {},
|
|
1075
1173
|
);
|
|
1076
1174
|
debug("Symbolication done");
|
|
1077
1175
|
res.end(
|
|
1078
1176
|
JSON.stringify({
|
|
1079
1177
|
codeFrame: getCodeFrame(urls, symbolicatedStack),
|
|
1080
1178
|
stack: symbolicatedStack,
|
|
1081
|
-
})
|
|
1179
|
+
}),
|
|
1082
1180
|
);
|
|
1083
1181
|
process.nextTick(() => {
|
|
1084
1182
|
log(createActionEndEntry(symbolicatingLogEntry));
|
|
1085
1183
|
});
|
|
1086
1184
|
} catch (error) {
|
|
1087
|
-
|
|
1185
|
+
debug("Symbolication failed", error.stack || error);
|
|
1088
1186
|
res.statusCode = 500;
|
|
1089
1187
|
res.end(
|
|
1090
1188
|
JSON.stringify({
|
|
1091
1189
|
error: error.message,
|
|
1092
|
-
})
|
|
1190
|
+
}),
|
|
1093
1191
|
);
|
|
1094
1192
|
}
|
|
1095
1193
|
}
|
|
@@ -1101,19 +1199,23 @@ class Server {
|
|
|
1101
1199
|
resolverOptions,
|
|
1102
1200
|
serializerOptions,
|
|
1103
1201
|
transformOptions,
|
|
1104
|
-
} =
|
|
1202
|
+
} = (0, _splitBundleOptions.default)(bundleOptions);
|
|
1105
1203
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
1106
1204
|
relativeTo: "server",
|
|
1107
1205
|
resolverOptions,
|
|
1108
1206
|
transformOptions,
|
|
1109
1207
|
});
|
|
1110
|
-
const graphId =
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1208
|
+
const graphId = (0, _getGraphId.default)(
|
|
1209
|
+
resolvedEntryFilePath,
|
|
1210
|
+
transformOptions,
|
|
1211
|
+
{
|
|
1212
|
+
unstable_allowRequireContext:
|
|
1213
|
+
this._config.transformer.unstable_allowRequireContext,
|
|
1214
|
+
resolverOptions,
|
|
1215
|
+
shallow: graphOptions.shallow,
|
|
1216
|
+
lazy: graphOptions.lazy,
|
|
1217
|
+
},
|
|
1218
|
+
);
|
|
1117
1219
|
let revision;
|
|
1118
1220
|
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
1119
1221
|
if (revPromise == null) {
|
|
@@ -1125,7 +1227,7 @@ class Server {
|
|
|
1125
1227
|
onProgress,
|
|
1126
1228
|
shallow: graphOptions.shallow,
|
|
1127
1229
|
lazy: graphOptions.lazy,
|
|
1128
|
-
}
|
|
1230
|
+
},
|
|
1129
1231
|
));
|
|
1130
1232
|
} else {
|
|
1131
1233
|
({ revision } = await this._bundler.updateGraph(await revPromise, false));
|
|
@@ -1134,21 +1236,21 @@ class Server {
|
|
|
1134
1236
|
if (serializerOptions.modulesOnly) {
|
|
1135
1237
|
prepend = [];
|
|
1136
1238
|
}
|
|
1137
|
-
return getExplodedSourceMap(
|
|
1239
|
+
return (0, _getExplodedSourceMap.getExplodedSourceMap)(
|
|
1138
1240
|
[...prepend, ...this._getSortedModules(graph)],
|
|
1139
1241
|
{
|
|
1140
1242
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
1141
|
-
}
|
|
1243
|
+
},
|
|
1142
1244
|
);
|
|
1143
1245
|
}
|
|
1144
1246
|
async _resolveRelativePath(
|
|
1145
1247
|
filePath,
|
|
1146
|
-
{ relativeTo, resolverOptions, transformOptions }
|
|
1248
|
+
{ relativeTo, resolverOptions, transformOptions },
|
|
1147
1249
|
) {
|
|
1148
1250
|
const resolutionFn = await transformHelpers.getResolveDependencyFn(
|
|
1149
1251
|
this._bundler.getBundler(),
|
|
1150
1252
|
transformOptions.platform,
|
|
1151
|
-
resolverOptions
|
|
1253
|
+
resolverOptions,
|
|
1152
1254
|
);
|
|
1153
1255
|
const rootDir =
|
|
1154
1256
|
relativeTo === "server"
|
|
@@ -1177,7 +1279,6 @@ class Server {
|
|
|
1177
1279
|
customResolverOptions: Object.create(null),
|
|
1178
1280
|
customTransformOptions: Object.create(null),
|
|
1179
1281
|
dev: true,
|
|
1180
|
-
hot: false,
|
|
1181
1282
|
minify: false,
|
|
1182
1283
|
unstable_transformProfile: "default",
|
|
1183
1284
|
};
|
|
@@ -1198,7 +1299,7 @@ class Server {
|
|
|
1198
1299
|
return this._config.server.unstable_serverRoot ?? this._config.projectRoot;
|
|
1199
1300
|
}
|
|
1200
1301
|
_getEntryPointAbsolutePath(entryFile) {
|
|
1201
|
-
return
|
|
1302
|
+
return _path.default.resolve(this._getServerRootDir(), entryFile);
|
|
1202
1303
|
}
|
|
1203
1304
|
async ready() {
|
|
1204
1305
|
await this._bundler.ready();
|
|
@@ -1215,23 +1316,30 @@ class Server {
|
|
|
1215
1316
|
case _types.SourcePathsMode.ServerUrl:
|
|
1216
1317
|
for (const [pathnamePrefix, normalizedRootDir] of this
|
|
1217
1318
|
._sourceRequestRoutingMap) {
|
|
1218
|
-
if (module.path.startsWith(normalizedRootDir +
|
|
1319
|
+
if (module.path.startsWith(normalizedRootDir + _path.default.sep)) {
|
|
1219
1320
|
const relativePath = module.path.slice(
|
|
1220
|
-
normalizedRootDir.length + 1
|
|
1321
|
+
normalizedRootDir.length + 1,
|
|
1221
1322
|
);
|
|
1222
|
-
const relativePathPosix = relativePath
|
|
1223
|
-
|
|
1323
|
+
const relativePathPosix = relativePath
|
|
1324
|
+
.split(_path.default.sep)
|
|
1325
|
+
.map((segment) => encodeURIComponent(segment))
|
|
1326
|
+
.join("/");
|
|
1327
|
+
return pathnamePrefix + relativePathPosix;
|
|
1224
1328
|
}
|
|
1225
1329
|
}
|
|
1226
|
-
const modulePathPosix = module.path
|
|
1330
|
+
const modulePathPosix = module.path
|
|
1331
|
+
.split(_path.default.sep)
|
|
1332
|
+
.map((segment) => encodeURIComponent(segment))
|
|
1333
|
+
.join("/");
|
|
1227
1334
|
return modulePathPosix.startsWith("/")
|
|
1228
|
-
?
|
|
1229
|
-
: "/" +
|
|
1335
|
+
? modulePathPosix
|
|
1336
|
+
: "/" + modulePathPosix;
|
|
1230
1337
|
case _types.SourcePathsMode.Absolute:
|
|
1231
1338
|
return module.path;
|
|
1232
1339
|
}
|
|
1233
1340
|
}
|
|
1234
1341
|
}
|
|
1342
|
+
exports.default = Server;
|
|
1235
1343
|
function* zip(xs, ys) {
|
|
1236
1344
|
const ysIter = ys[Symbol.iterator]();
|
|
1237
1345
|
for (const x of xs) {
|
|
@@ -1245,4 +1353,3 @@ function* zip(xs, ys) {
|
|
|
1245
1353
|
function getBuildID(buildNumber) {
|
|
1246
1354
|
return buildNumber.toString(36);
|
|
1247
1355
|
}
|
|
1248
|
-
module.exports = Server;
|