metro 0.66.2 → 0.69.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 +22 -24
- package/src/Assets.js +9 -9
- package/src/Assets.js.flow +5 -7
- package/src/Bundler/util.js +16 -15
- package/src/Bundler/util.js.flow +11 -10
- package/src/Bundler.js +21 -8
- package/src/Bundler.js.flow +19 -7
- package/src/DeltaBundler/DeltaCalculator.js +15 -15
- package/src/DeltaBundler/DeltaCalculator.js.flow +7 -7
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +13 -13
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +6 -7
- package/src/DeltaBundler/Serializers/baseJSBundle.js +4 -4
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +4 -4
- package/src/DeltaBundler/Serializers/getAllFiles.js +1 -1
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +3 -3
- package/src/DeltaBundler/Serializers/getAssets.js +3 -3
- package/src/DeltaBundler/Serializers/getAssets.js.flow +4 -5
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +4 -4
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +4 -4
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +20 -20
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +9 -10
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +11 -11
- package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +5 -6
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +1 -1
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js.flow +1 -1
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +2 -2
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +4 -4
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +1 -1
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js.flow +1 -1
- package/src/DeltaBundler/Serializers/helpers/js.js +6 -6
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +11 -12
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +4 -4
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/helpers/processModules.js +4 -4
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -3
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +9 -9
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +9 -8
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +6 -6
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +3 -4
- package/src/DeltaBundler/Serializers/sourceMapObject.js +5 -5
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -4
- package/src/DeltaBundler/Serializers/sourceMapString.js +2 -2
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +3 -3
- package/src/DeltaBundler/Transformer.js +9 -9
- package/src/DeltaBundler/Transformer.js.flow +7 -9
- package/src/DeltaBundler/Worker.js +8 -11
- package/src/DeltaBundler/Worker.js.flow +8 -11
- package/src/DeltaBundler/WorkerFarm.js +14 -17
- package/src/DeltaBundler/WorkerFarm.js.flow +7 -10
- package/src/DeltaBundler/__fixtures__/hasteImpl.js +2 -2
- package/src/DeltaBundler/computeDelta.js +2 -2
- package/src/DeltaBundler/computeDelta.js.flow +2 -2
- package/src/DeltaBundler/getTransformCacheKey.js +4 -4
- package/src/DeltaBundler/getTransformCacheKey.js.flow +5 -6
- package/src/DeltaBundler/mergeDeltas.js +2 -2
- package/src/DeltaBundler/mergeDeltas.js.flow +1 -1
- package/src/DeltaBundler/traverseDependencies.js +22 -22
- package/src/DeltaBundler/traverseDependencies.js.flow +3 -3
- package/src/DeltaBundler/types.flow.js +1 -1
- package/src/DeltaBundler/types.flow.js.flow +1 -1
- package/src/DeltaBundler.js +5 -5
- package/src/DeltaBundler.js.flow +4 -4
- package/src/HmrServer.js +71 -55
- package/src/HmrServer.js.flow +40 -37
- package/src/IncrementalBundler/GraphNotFoundError.js +1 -1
- package/src/IncrementalBundler/GraphNotFoundError.js.flow +1 -1
- package/src/IncrementalBundler/ResourceNotFoundError.js +1 -1
- package/src/IncrementalBundler/ResourceNotFoundError.js.flow +1 -1
- package/src/IncrementalBundler/RevisionNotFoundError.js +1 -1
- package/src/IncrementalBundler/RevisionNotFoundError.js.flow +1 -1
- package/src/IncrementalBundler.js +44 -32
- package/src/IncrementalBundler.js.flow +30 -24
- package/src/ModuleGraph/module.js +3 -3
- package/src/ModuleGraph/module.js.flow +1 -1
- package/src/ModuleGraph/node-haste/HasteFS.js +2 -2
- package/src/ModuleGraph/node-haste/HasteFS.js.flow +1 -1
- package/src/ModuleGraph/node-haste/Module.js +1 -1
- package/src/ModuleGraph/node-haste/Module.js.flow +1 -1
- package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
- package/src/ModuleGraph/node-haste/ModuleCache.js.flow +3 -3
- package/src/ModuleGraph/node-haste/Package.js +3 -3
- package/src/ModuleGraph/node-haste/Package.js.flow +3 -3
- package/src/ModuleGraph/node-haste/node-haste.flow.js +1 -1
- package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +1 -1
- package/src/ModuleGraph/node-haste/node-haste.js +42 -32
- package/src/ModuleGraph/node-haste/node-haste.js.flow +28 -23
- package/src/ModuleGraph/output/indexed-ram-bundle.js +17 -17
- package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +41 -9
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js +18 -18
- package/src/ModuleGraph/output/multiple-files-ram-bundle.js.flow +21 -9
- package/src/ModuleGraph/output/plain-bundle.js +6 -6
- package/src/ModuleGraph/output/plain-bundle.js.flow +7 -7
- package/src/ModuleGraph/output/reverse-dependency-map-references.js +3 -3
- package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +4 -8
- package/src/ModuleGraph/output/util.js +31 -30
- package/src/ModuleGraph/output/util.js.flow +15 -16
- package/src/ModuleGraph/silent-console.js +2 -2
- package/src/ModuleGraph/silent-console.js.flow +1 -1
- package/src/ModuleGraph/test-helpers.js +7 -7
- package/src/ModuleGraph/types.flow.js +1 -1
- package/src/ModuleGraph/types.flow.js.flow +7 -7
- package/src/ModuleGraph/worker/JsFileWrapping.js +7 -7
- package/src/ModuleGraph/worker/JsFileWrapping.js.flow +3 -2
- package/src/ModuleGraph/worker/Platforms.js +2 -2
- package/src/ModuleGraph/worker/Platforms.js.flow +1 -1
- package/src/ModuleGraph/worker/collectDependencies.js +24 -25
- package/src/ModuleGraph/worker/collectDependencies.js.flow +15 -17
- package/src/ModuleGraph/worker/generate.js +2 -2
- package/src/ModuleGraph/worker/generate.js.flow +3 -3
- package/src/ModuleGraph/worker/generateImportNames.js +5 -5
- package/src/ModuleGraph/worker/generateImportNames.js.flow +3 -5
- package/src/ModuleGraph/worker/mergeSourceMaps.js +8 -7
- package/src/ModuleGraph/worker/mergeSourceMaps.js.flow +3 -3
- package/src/Server/MultipartResponse.js +4 -8
- package/src/Server/symbolicate.js +8 -8
- package/src/Server/symbolicate.js.flow +17 -5
- package/src/Server.js +202 -150
- package/src/Server.js.flow +129 -87
- package/src/cli-utils.js +4 -4
- package/src/cli-utils.js.flow +15 -13
- package/src/cli.js +4 -4
- package/src/cli.js.flow +2 -4
- package/src/commands/build.js +23 -24
- package/src/commands/build.js.flow +6 -9
- package/src/commands/dependencies.js +25 -19
- package/src/commands/serve.js +17 -18
- package/src/commands/serve.js.flow +6 -9
- package/src/index.js +116 -51
- package/src/index.js.flow +107 -41
- package/src/integration_tests/basic_bundle/AssetRegistry.js +2 -2
- package/src/integration_tests/basic_bundle/AssetRegistry.js.flow +1 -1
- package/src/integration_tests/basic_bundle/Bar.js +2 -2
- package/src/integration_tests/basic_bundle/Bar.js.flow +1 -1
- package/src/integration_tests/basic_bundle/ErrorBundle.js +2 -2
- package/src/integration_tests/basic_bundle/ErrorBundle.js.flow +1 -1
- package/src/integration_tests/basic_bundle/Foo.js +2 -2
- package/src/integration_tests/basic_bundle/Foo.js.flow +1 -1
- package/src/integration_tests/basic_bundle/TestBundle.js +3 -2
- package/src/integration_tests/basic_bundle/TestBundle.js.flow +3 -1
- package/src/integration_tests/basic_bundle/TestPolyfill.js +1 -1
- package/src/integration_tests/basic_bundle/TestPolyfill.js.flow +1 -1
- package/src/integration_tests/basic_bundle/TypeScript.ts +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-1.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-1.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-2.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-2.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-3.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-3.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-4.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-4.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-5.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-5.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-6.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-6.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-null.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-null.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js +2 -2
- package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js.flow +1 -1
- package/src/integration_tests/basic_bundle/import-export/index.js +8 -8
- package/src/integration_tests/basic_bundle/import-export/index.js.flow +1 -1
- package/src/integration_tests/basic_bundle/polyfill.js +1 -1
- package/src/integration_tests/execBundle.js +2 -2
- package/src/integration_tests/execBundle.js.flow +1 -1
- package/src/integration_tests/metro.config.js +8 -8
- package/src/lib/BatchProcessor.js +3 -3
- package/src/lib/BatchProcessor.js.flow +1 -1
- package/src/lib/JsonReporter.js +2 -2
- package/src/lib/JsonReporter.js.flow +1 -1
- package/src/lib/RamBundleParser.js +1 -1
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.js +14 -14
- package/src/lib/TerminalReporter.js.flow +9 -10
- package/src/lib/bundleToBytecode.js +6 -7
- package/src/lib/bundleToBytecode.js.flow +8 -7
- package/src/lib/bundleToString.js +3 -3
- package/src/lib/bundleToString.js.flow +5 -4
- package/src/lib/countLines.js +3 -7
- package/src/lib/countLines.js.flow +4 -7
- package/src/lib/createModuleIdFactory.js +2 -2
- package/src/lib/createModuleIdFactory.js.flow +1 -1
- package/src/lib/{attachWebsocketServer.js → createWebsocketServer.js} +18 -17
- package/src/lib/{attachWebsocketServer.js.flow → createWebsocketServer.js.flow} +12 -21
- package/src/lib/debounceAsyncQueue.js +2 -2
- package/src/lib/debounceAsyncQueue.js.flow +1 -1
- package/src/lib/formatBundlingError.js +21 -21
- package/src/lib/formatBundlingError.js.flow +6 -8
- package/src/lib/getAppendScripts.js +26 -27
- package/src/lib/getAppendScripts.js.flow +7 -8
- package/src/lib/getGraphId.js +3 -3
- package/src/lib/getGraphId.js.flow +3 -3
- package/src/lib/getMaxWorkers.js +2 -2
- package/src/lib/getMaxWorkers.js.flow +1 -1
- package/src/lib/getPreludeCode.js +2 -2
- package/src/lib/getPreludeCode.js.flow +1 -1
- package/src/lib/getPrependedScripts.js +15 -15
- package/src/lib/getPrependedScripts.js.flow +7 -8
- package/src/lib/logToConsole.js +1 -1
- package/src/lib/logToConsole.js.flow +3 -3
- package/src/lib/parseCustomTransformOptions.js +2 -2
- package/src/lib/parseCustomTransformOptions.js.flow +3 -3
- package/src/lib/parseOptionsFromUrl.js +7 -7
- package/src/lib/parseOptionsFromUrl.js.flow +29 -9
- package/src/lib/relativizeSourceMap.js +1 -1
- package/src/lib/relativizeSourceMap.js.flow +3 -3
- package/src/lib/reporting.js +5 -5
- package/src/lib/reporting.js.flow +16 -3
- package/src/lib/splitBundleOptions.js +5 -5
- package/src/lib/splitBundleOptions.js.flow +1 -1
- package/src/lib/transformHelpers.js +10 -10
- package/src/lib/transformHelpers.js.flow +5 -5
- package/src/node-haste/DependencyGraph/ModuleResolution.js +51 -30
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +46 -42
- package/src/node-haste/DependencyGraph/createHasteMap.js +99 -0
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +88 -0
- package/src/node-haste/DependencyGraph/{assets/empty-module.js → types.js} +2 -2
- package/src/node-haste/DependencyGraph/types.js.flow +88 -0
- package/src/node-haste/DependencyGraph.js +49 -117
- package/src/node-haste/DependencyGraph.js.flow +36 -111
- package/src/node-haste/Module.js +1 -1
- package/src/node-haste/Module.js.flow +3 -3
- package/src/node-haste/ModuleCache.js +54 -13
- package/src/node-haste/ModuleCache.js.flow +53 -12
- package/src/node-haste/Package.js +7 -9
- package/src/node-haste/Package.js.flow +1 -8
- package/src/node-haste/lib/AssetPaths.js +5 -5
- package/src/node-haste/lib/AssetPaths.js.flow +2 -4
- package/src/node-haste/lib/parsePlatformFilePath.js +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +1 -1
- package/src/shared/output/RamBundle/as-assets.js +16 -17
- package/src/shared/output/RamBundle/as-assets.js.flow +11 -15
- package/src/shared/output/RamBundle/as-indexed-file.js +14 -15
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +8 -12
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +7 -7
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +4 -4
- package/src/shared/output/RamBundle/magic-number.js +1 -1
- package/src/shared/output/RamBundle/magic-number.js.flow +1 -1
- package/src/shared/output/RamBundle/util.js +21 -19
- package/src/shared/output/RamBundle/util.js.flow +5 -8
- package/src/shared/output/RamBundle/write-sourcemap.js +1 -1
- package/src/shared/output/RamBundle/write-sourcemap.js.flow +1 -1
- package/src/shared/output/RamBundle.js +2 -2
- package/src/shared/output/RamBundle.js.flow +4 -5
- package/src/shared/output/bundle.js +6 -6
- package/src/shared/output/bundle.js.flow +4 -5
- package/src/shared/output/meta.js +4 -5
- package/src/shared/output/meta.js.flow +2 -4
- package/src/shared/output/unbundle.js +1 -1
- package/src/shared/output/unbundle.js.flow +1 -1
- package/src/shared/output/writeFile.js +1 -1
- package/src/shared/output/writeFile.js.flow +1 -1
- package/src/shared/types.flow.js +1 -1
- package/src/shared/types.flow.js.flow +2 -2
- package/src/node-haste/DependencyGraph/assets/empty-module.js.flow +0 -9
- package/src/node-haste/types.js +0 -10
- package/src/node-haste/types.js.flow +0 -23
package/src/Server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -9,67 +9,71 @@
|
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const MultipartResponse = require("./Server/MultipartResponse");
|
|
15
|
-
|
|
16
|
-
const ResourceNotFoundError = require("./IncrementalBundler/ResourceNotFoundError");
|
|
12
|
+
const { getAsset } = require("./Assets");
|
|
17
13
|
|
|
18
14
|
const baseBytecodeBundle = require("./DeltaBundler/Serializers/baseBytecodeBundle");
|
|
19
15
|
|
|
20
16
|
const baseJSBundle = require("./DeltaBundler/Serializers/baseJSBundle");
|
|
21
17
|
|
|
22
|
-
const
|
|
18
|
+
const getAllFiles = require("./DeltaBundler/Serializers/getAllFiles");
|
|
23
19
|
|
|
24
|
-
const
|
|
20
|
+
const getAssets = require("./DeltaBundler/Serializers/getAssets");
|
|
25
21
|
|
|
26
|
-
const {
|
|
22
|
+
const {
|
|
23
|
+
getExplodedSourceMap,
|
|
24
|
+
} = require("./DeltaBundler/Serializers/getExplodedSourceMap");
|
|
27
25
|
|
|
28
|
-
const
|
|
26
|
+
const getRamBundleInfo = require("./DeltaBundler/Serializers/getRamBundleInfo");
|
|
29
27
|
|
|
30
|
-
const
|
|
28
|
+
const sourceMapString = require("./DeltaBundler/Serializers/sourceMapString");
|
|
31
29
|
|
|
32
|
-
const
|
|
30
|
+
const IncrementalBundler = require("./IncrementalBundler");
|
|
33
31
|
|
|
34
|
-
const
|
|
32
|
+
const ResourceNotFoundError = require("./IncrementalBundler/ResourceNotFoundError");
|
|
35
33
|
|
|
36
|
-
const
|
|
34
|
+
const bundleToBytecode = require("./lib/bundleToBytecode");
|
|
37
35
|
|
|
38
|
-
const
|
|
36
|
+
const bundleToString = require("./lib/bundleToString");
|
|
39
37
|
|
|
40
|
-
const
|
|
38
|
+
const formatBundlingError = require("./lib/formatBundlingError");
|
|
41
39
|
|
|
42
|
-
const
|
|
40
|
+
const getGraphId = require("./lib/getGraphId");
|
|
43
41
|
|
|
44
42
|
const parseOptionsFromUrl = require("./lib/parseOptionsFromUrl");
|
|
45
43
|
|
|
46
|
-
const
|
|
44
|
+
const splitBundleOptions = require("./lib/splitBundleOptions");
|
|
47
45
|
|
|
48
|
-
const
|
|
46
|
+
const transformHelpers = require("./lib/transformHelpers");
|
|
49
47
|
|
|
50
|
-
const
|
|
48
|
+
const parsePlatformFilePath = require("./node-haste/lib/parsePlatformFilePath");
|
|
51
49
|
|
|
52
|
-
const
|
|
50
|
+
const MultipartResponse = require("./Server/MultipartResponse");
|
|
53
51
|
|
|
54
52
|
const symbolicate = require("./Server/symbolicate");
|
|
55
53
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const url = require("url");
|
|
59
|
-
|
|
60
|
-
const { VERSION: BYTECODE_VERSION } = require("metro-hermes-compiler");
|
|
54
|
+
const { codeFrameColumns } = require("@babel/code-frame");
|
|
61
55
|
|
|
62
|
-
const
|
|
56
|
+
const debug = require("debug")("Metro:Server");
|
|
63
57
|
|
|
64
|
-
const
|
|
65
|
-
getExplodedSourceMap
|
|
66
|
-
} = require("./DeltaBundler/Serializers/getExplodedSourceMap");
|
|
58
|
+
const fs = require("graceful-fs");
|
|
67
59
|
|
|
68
60
|
const {
|
|
69
61
|
Logger,
|
|
70
|
-
Logger: { createActionStartEntry, createActionEndEntry, log }
|
|
62
|
+
Logger: { createActionStartEntry, createActionEndEntry, log },
|
|
71
63
|
} = require("metro-core");
|
|
72
64
|
|
|
65
|
+
const { VERSION: BYTECODE_VERSION } = require("metro-hermes-compiler");
|
|
66
|
+
|
|
67
|
+
const mime = require("mime-types");
|
|
68
|
+
|
|
69
|
+
const nullthrows = require("nullthrows");
|
|
70
|
+
|
|
71
|
+
const path = require("path");
|
|
72
|
+
|
|
73
|
+
const querystring = require("querystring");
|
|
74
|
+
|
|
75
|
+
const url = require("url");
|
|
76
|
+
|
|
73
77
|
const DELTA_ID_HEADER = "X-Metro-Delta-ID";
|
|
74
78
|
const FILES_CHANGED_COUNT_HEADER = "X-Metro-Files-Changed-Count";
|
|
75
79
|
|
|
@@ -79,10 +83,10 @@ class Server {
|
|
|
79
83
|
this._serverOptions = options;
|
|
80
84
|
|
|
81
85
|
if (this._config.resetCache) {
|
|
82
|
-
this._config.cacheStores.forEach(store => store.clear());
|
|
86
|
+
this._config.cacheStores.forEach((store) => store.clear());
|
|
83
87
|
|
|
84
88
|
this._config.reporter.update({
|
|
85
|
-
type: "transform_cache_reset"
|
|
89
|
+
type: "transform_cache_reset",
|
|
86
90
|
});
|
|
87
91
|
}
|
|
88
92
|
|
|
@@ -97,7 +101,7 @@ class Server {
|
|
|
97
101
|
this._createModuleId = config.serializer.createModuleIdFactory();
|
|
98
102
|
this._bundler = new IncrementalBundler(config, {
|
|
99
103
|
hasReducedPerformance: options && options.hasReducedPerformance,
|
|
100
|
-
watch: options ? options.watch : undefined
|
|
104
|
+
watch: options ? options.watch : undefined,
|
|
101
105
|
});
|
|
102
106
|
this._nextBundleBuildID = 1;
|
|
103
107
|
}
|
|
@@ -124,22 +128,25 @@ class Server {
|
|
|
124
128
|
graphOptions,
|
|
125
129
|
onProgress,
|
|
126
130
|
serializerOptions,
|
|
127
|
-
transformOptions
|
|
131
|
+
transformOptions,
|
|
128
132
|
} = splitBundleOptions(options);
|
|
129
133
|
const { prepend, graph } = await this._bundler.buildGraph(
|
|
130
134
|
entryFile,
|
|
131
135
|
transformOptions,
|
|
132
136
|
{
|
|
133
137
|
onProgress,
|
|
134
|
-
shallow: graphOptions.shallow
|
|
138
|
+
shallow: graphOptions.shallow,
|
|
135
139
|
}
|
|
136
140
|
);
|
|
137
|
-
|
|
141
|
+
|
|
142
|
+
const entryPoint = this._getEntryPointAbsolutePath(entryFile);
|
|
143
|
+
|
|
138
144
|
const bundleOptions = {
|
|
139
145
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
140
146
|
this._config.transformer.asyncRequireModulePath,
|
|
141
147
|
{
|
|
142
|
-
transformOptions
|
|
148
|
+
transformOptions,
|
|
149
|
+
relativeTo: "project",
|
|
143
150
|
}
|
|
144
151
|
),
|
|
145
152
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
@@ -148,13 +155,14 @@ class Server {
|
|
|
148
155
|
dev: transformOptions.dev,
|
|
149
156
|
projectRoot: this._config.projectRoot,
|
|
150
157
|
modulesOnly: serializerOptions.modulesOnly,
|
|
151
|
-
runBeforeMainModule:
|
|
152
|
-
|
|
153
|
-
|
|
158
|
+
runBeforeMainModule:
|
|
159
|
+
this._config.serializer.getModulesRunBeforeMainModule(
|
|
160
|
+
path.relative(this._config.projectRoot, entryPoint)
|
|
161
|
+
),
|
|
154
162
|
runModule: serializerOptions.runModule,
|
|
155
163
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
156
164
|
sourceUrl: serializerOptions.sourceUrl,
|
|
157
|
-
inlineSourceMap: serializerOptions.inlineSourceMap
|
|
165
|
+
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
158
166
|
};
|
|
159
167
|
let bundleCode = null;
|
|
160
168
|
let bundleMap = null;
|
|
@@ -184,14 +192,14 @@ class Server {
|
|
|
184
192
|
[...prepend, ...this._getSortedModules(graph)],
|
|
185
193
|
{
|
|
186
194
|
excludeSource: serializerOptions.excludeSource,
|
|
187
|
-
processModuleFilter: this._config.serializer.processModuleFilter
|
|
195
|
+
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
188
196
|
}
|
|
189
197
|
);
|
|
190
198
|
}
|
|
191
199
|
|
|
192
200
|
return {
|
|
193
201
|
code: bundleCode,
|
|
194
|
-
map: bundleMap
|
|
202
|
+
map: bundleMap,
|
|
195
203
|
};
|
|
196
204
|
}
|
|
197
205
|
|
|
@@ -201,22 +209,25 @@ class Server {
|
|
|
201
209
|
graphOptions,
|
|
202
210
|
onProgress,
|
|
203
211
|
serializerOptions,
|
|
204
|
-
transformOptions
|
|
212
|
+
transformOptions,
|
|
205
213
|
} = splitBundleOptions(options);
|
|
206
214
|
const { prepend, graph } = await this._bundler.buildGraph(
|
|
207
215
|
entryFile,
|
|
208
216
|
transformOptions,
|
|
209
217
|
{
|
|
210
218
|
onProgress,
|
|
211
|
-
shallow: graphOptions.shallow
|
|
219
|
+
shallow: graphOptions.shallow,
|
|
212
220
|
}
|
|
213
221
|
);
|
|
214
|
-
|
|
222
|
+
|
|
223
|
+
const entryPoint = this._getEntryPointAbsolutePath(entryFile);
|
|
224
|
+
|
|
215
225
|
return await getRamBundleInfo(entryPoint, prepend, graph, {
|
|
216
226
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
217
227
|
this._config.transformer.asyncRequireModulePath,
|
|
218
228
|
{
|
|
219
|
-
transformOptions
|
|
229
|
+
transformOptions,
|
|
230
|
+
relativeTo: "project",
|
|
220
231
|
}
|
|
221
232
|
),
|
|
222
233
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
@@ -228,34 +239,34 @@ class Server {
|
|
|
228
239
|
platform: transformOptions.platform,
|
|
229
240
|
projectRoot: this._config.projectRoot,
|
|
230
241
|
modulesOnly: serializerOptions.modulesOnly,
|
|
231
|
-
runBeforeMainModule:
|
|
232
|
-
|
|
233
|
-
|
|
242
|
+
runBeforeMainModule:
|
|
243
|
+
this._config.serializer.getModulesRunBeforeMainModule(
|
|
244
|
+
path.relative(this._config.projectRoot, entryPoint)
|
|
245
|
+
),
|
|
234
246
|
runModule: serializerOptions.runModule,
|
|
235
247
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
236
248
|
sourceUrl: serializerOptions.sourceUrl,
|
|
237
|
-
inlineSourceMap: serializerOptions.inlineSourceMap
|
|
249
|
+
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
238
250
|
});
|
|
239
251
|
}
|
|
240
252
|
|
|
241
253
|
async getAssets(options) {
|
|
242
|
-
const { entryFile, transformOptions, onProgress } =
|
|
243
|
-
options
|
|
244
|
-
);
|
|
254
|
+
const { entryFile, transformOptions, onProgress } =
|
|
255
|
+
splitBundleOptions(options);
|
|
245
256
|
const dependencies = await this._bundler.getDependencies(
|
|
246
257
|
[entryFile],
|
|
247
258
|
transformOptions,
|
|
248
259
|
{
|
|
249
260
|
onProgress,
|
|
250
|
-
shallow: false
|
|
261
|
+
shallow: false,
|
|
251
262
|
}
|
|
252
263
|
);
|
|
253
264
|
return await getAssets(dependencies, {
|
|
254
265
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
255
266
|
assetPlugins: this._config.transformer.assetPlugins,
|
|
256
267
|
platform: transformOptions.platform,
|
|
257
|
-
projectRoot: this.
|
|
258
|
-
publicPath: this._config.transformer.publicPath
|
|
268
|
+
projectRoot: this._getServerRootDir(),
|
|
269
|
+
publicPath: this._config.transformer.publicPath,
|
|
259
270
|
});
|
|
260
271
|
}
|
|
261
272
|
|
|
@@ -266,14 +277,14 @@ class Server {
|
|
|
266
277
|
const { entryFile, transformOptions, onProgress } = splitBundleOptions({
|
|
267
278
|
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
268
279
|
...options,
|
|
269
|
-
bundleType: "bundle"
|
|
280
|
+
bundleType: "bundle",
|
|
270
281
|
});
|
|
271
282
|
const { prepend, graph } = await this._bundler.buildGraph(
|
|
272
283
|
entryFile,
|
|
273
284
|
transformOptions,
|
|
274
285
|
{
|
|
275
286
|
onProgress,
|
|
276
|
-
shallow: false
|
|
287
|
+
shallow: false,
|
|
277
288
|
}
|
|
278
289
|
);
|
|
279
290
|
const platform =
|
|
@@ -282,7 +293,7 @@ class Server {
|
|
|
282
293
|
|
|
283
294
|
return await getAllFiles(prepend, graph, {
|
|
284
295
|
platform,
|
|
285
|
-
processModuleFilter: this._config.serializer.processModuleFilter
|
|
296
|
+
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
286
297
|
});
|
|
287
298
|
}
|
|
288
299
|
|
|
@@ -298,7 +309,7 @@ class Server {
|
|
|
298
309
|
"Accept-Ranges": "bytes",
|
|
299
310
|
"Content-Length": chunksize.toString(),
|
|
300
311
|
"Content-Range": `bytes ${dataStart}-${dataEnd}/${data.length}`,
|
|
301
|
-
"Content-Type": mime.lookup(path.basename(assetPath))
|
|
312
|
+
"Content-Type": mime.lookup(path.basename(assetPath)),
|
|
302
313
|
});
|
|
303
314
|
return data.slice(dataStart, dataEnd + 1);
|
|
304
315
|
}
|
|
@@ -308,8 +319,23 @@ class Server {
|
|
|
308
319
|
|
|
309
320
|
async _processSingleAssetRequest(req, res) {
|
|
310
321
|
const urlObj = url.parse(decodeURI(req.url), true);
|
|
311
|
-
|
|
312
|
-
urlObj &&
|
|
322
|
+
let [, assetPath] =
|
|
323
|
+
(urlObj &&
|
|
324
|
+
urlObj.pathname &&
|
|
325
|
+
urlObj.pathname.match(/^\/assets\/(.+)$/)) ||
|
|
326
|
+
[];
|
|
327
|
+
|
|
328
|
+
if (!assetPath && urlObj && urlObj.query && urlObj.query.unstable_path) {
|
|
329
|
+
const [, actualPath, secondaryQuery] = nullthrows(
|
|
330
|
+
urlObj.query.unstable_path.match(/^([^?]*)\??(.*)$/)
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
if (secondaryQuery) {
|
|
334
|
+
Object.assign(urlObj.query, querystring.parse(secondaryQuery));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
assetPath = actualPath;
|
|
338
|
+
}
|
|
313
339
|
|
|
314
340
|
if (!assetPath) {
|
|
315
341
|
throw new Error("Could not extract asset path from URL");
|
|
@@ -318,13 +344,13 @@ class Server {
|
|
|
318
344
|
const processingAssetRequestLogEntry = log(
|
|
319
345
|
createActionStartEntry({
|
|
320
346
|
action_name: "Processing asset request",
|
|
321
|
-
asset: assetPath[1]
|
|
347
|
+
asset: assetPath[1],
|
|
322
348
|
})
|
|
323
349
|
);
|
|
324
350
|
|
|
325
351
|
try {
|
|
326
352
|
const data = await getAsset(
|
|
327
|
-
assetPath
|
|
353
|
+
assetPath,
|
|
328
354
|
this._config.projectRoot,
|
|
329
355
|
this._config.watchFolders,
|
|
330
356
|
urlObj.query.platform,
|
|
@@ -336,7 +362,7 @@ class Server {
|
|
|
336
362
|
res.setHeader("Cache-Control", "max-age=31536000");
|
|
337
363
|
}
|
|
338
364
|
|
|
339
|
-
res.end(this._rangeRequestMiddleware(req, res, data, assetPath
|
|
365
|
+
res.end(this._rangeRequestMiddleware(req, res, data, assetPath));
|
|
340
366
|
process.nextTick(() => {
|
|
341
367
|
log(createActionEndEntry(processingAssetRequestLogEntry));
|
|
342
368
|
});
|
|
@@ -397,7 +423,7 @@ class Server {
|
|
|
397
423
|
res,
|
|
398
424
|
this._parseOptions(formattedUrl)
|
|
399
425
|
);
|
|
400
|
-
} else if (pathname.startsWith("/assets/")) {
|
|
426
|
+
} else if (pathname.startsWith("/assets/") || pathname === "/assets") {
|
|
401
427
|
await this._processSingleAssetRequest(req, res);
|
|
402
428
|
} else if (pathname === "/symbolicate") {
|
|
403
429
|
await this._symbolicate(req, res);
|
|
@@ -411,34 +437,31 @@ class Server {
|
|
|
411
437
|
createEndEntry,
|
|
412
438
|
build,
|
|
413
439
|
delete: deleteFn,
|
|
414
|
-
finish
|
|
440
|
+
finish,
|
|
415
441
|
}) {
|
|
416
442
|
return async function requestProcessor(req, res, bundleOptions) {
|
|
417
|
-
const {
|
|
418
|
-
|
|
419
|
-
graphOptions,
|
|
420
|
-
transformOptions,
|
|
421
|
-
serializerOptions
|
|
422
|
-
} = splitBundleOptions(bundleOptions);
|
|
443
|
+
const { entryFile, graphOptions, transformOptions, serializerOptions } =
|
|
444
|
+
splitBundleOptions(bundleOptions);
|
|
423
445
|
/**
|
|
424
446
|
* `entryFile` is relative to projectRoot, we need to use resolution function
|
|
425
447
|
* to find the appropriate file with supported extensions.
|
|
426
448
|
*/
|
|
427
449
|
|
|
428
450
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
429
|
-
transformOptions
|
|
451
|
+
transformOptions,
|
|
452
|
+
relativeTo: "server",
|
|
430
453
|
});
|
|
431
454
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
432
455
|
shallow: graphOptions.shallow,
|
|
433
|
-
experimentalImportBundleSupport:
|
|
434
|
-
.experimentalImportBundleSupport
|
|
456
|
+
experimentalImportBundleSupport:
|
|
457
|
+
this._config.transformer.experimentalImportBundleSupport,
|
|
435
458
|
}); // For resources that support deletion, handle the DELETE method.
|
|
436
459
|
|
|
437
460
|
if (deleteFn && req.method === "DELETE") {
|
|
438
461
|
const deleteContext = {
|
|
439
462
|
graphId,
|
|
440
463
|
req,
|
|
441
|
-
res
|
|
464
|
+
res,
|
|
442
465
|
};
|
|
443
466
|
|
|
444
467
|
try {
|
|
@@ -447,7 +470,7 @@ class Server {
|
|
|
447
470
|
const formattedError = formatBundlingError(error);
|
|
448
471
|
const status = error instanceof ResourceNotFoundError ? 404 : 500;
|
|
449
472
|
res.writeHead(status, {
|
|
450
|
-
"Content-Type": "application/json; charset=UTF-8"
|
|
473
|
+
"Content-Type": "application/json; charset=UTF-8",
|
|
451
474
|
});
|
|
452
475
|
res.end(JSON.stringify(formattedError));
|
|
453
476
|
}
|
|
@@ -473,11 +496,11 @@ class Server {
|
|
|
473
496
|
if (currentProgress > lastProgress || totalFileCount < 10) {
|
|
474
497
|
mres.writeChunk(
|
|
475
498
|
{
|
|
476
|
-
"Content-Type": "application/json"
|
|
499
|
+
"Content-Type": "application/json",
|
|
477
500
|
},
|
|
478
501
|
JSON.stringify({
|
|
479
502
|
done: transformedFileCount,
|
|
480
|
-
total: totalFileCount
|
|
503
|
+
total: totalFileCount,
|
|
481
504
|
})
|
|
482
505
|
); // The `uncork` called internally in Node via `promise.nextTick()` may not fire
|
|
483
506
|
// until all of the Promises are resolved because the microtask queue we're
|
|
@@ -498,7 +521,7 @@ class Server {
|
|
|
498
521
|
buildID,
|
|
499
522
|
type: "bundle_transform_progressed",
|
|
500
523
|
transformedFileCount,
|
|
501
|
-
totalFileCount
|
|
524
|
+
totalFileCount,
|
|
502
525
|
});
|
|
503
526
|
};
|
|
504
527
|
}
|
|
@@ -511,9 +534,9 @@ class Server {
|
|
|
511
534
|
entryFile: resolvedEntryFilePath,
|
|
512
535
|
minify: transformOptions.minify,
|
|
513
536
|
platform: transformOptions.platform,
|
|
514
|
-
runtimeBytecodeVersion: transformOptions.runtimeBytecodeVersion
|
|
537
|
+
runtimeBytecodeVersion: transformOptions.runtimeBytecodeVersion,
|
|
515
538
|
},
|
|
516
|
-
type: "bundle_build_started"
|
|
539
|
+
type: "bundle_build_started",
|
|
517
540
|
});
|
|
518
541
|
|
|
519
542
|
const startContext = {
|
|
@@ -526,7 +549,7 @@ class Server {
|
|
|
526
549
|
onProgress,
|
|
527
550
|
req,
|
|
528
551
|
serializerOptions,
|
|
529
|
-
transformOptions
|
|
552
|
+
transformOptions,
|
|
530
553
|
};
|
|
531
554
|
const logEntry = log(
|
|
532
555
|
createActionStartEntry(createStartEntry(startContext))
|
|
@@ -539,19 +562,19 @@ class Server {
|
|
|
539
562
|
const formattedError = formatBundlingError(error);
|
|
540
563
|
const status = error instanceof ResourceNotFoundError ? 404 : 500;
|
|
541
564
|
mres.writeHead(status, {
|
|
542
|
-
"Content-Type": "application/json; charset=UTF-8"
|
|
565
|
+
"Content-Type": "application/json; charset=UTF-8",
|
|
543
566
|
});
|
|
544
567
|
mres.end(JSON.stringify(formattedError));
|
|
545
568
|
|
|
546
569
|
this._reporter.update({
|
|
547
570
|
buildID,
|
|
548
571
|
type: "bundle_build_failed",
|
|
549
|
-
bundleOptions
|
|
572
|
+
bundleOptions,
|
|
550
573
|
});
|
|
551
574
|
|
|
552
575
|
this._reporter.update({
|
|
553
576
|
error,
|
|
554
|
-
type: "bundling_error"
|
|
577
|
+
type: "bundling_error",
|
|
555
578
|
});
|
|
556
579
|
|
|
557
580
|
log({
|
|
@@ -560,8 +583,9 @@ class Server {
|
|
|
560
583
|
log_entry_label: "bundling_error",
|
|
561
584
|
bundle_id: graphId,
|
|
562
585
|
build_id: buildID,
|
|
563
|
-
stack: formattedError.message
|
|
586
|
+
stack: formattedError.message,
|
|
564
587
|
});
|
|
588
|
+
debug("Bundling error", error);
|
|
565
589
|
return;
|
|
566
590
|
}
|
|
567
591
|
|
|
@@ -570,7 +594,7 @@ class Server {
|
|
|
570
594
|
|
|
571
595
|
this._reporter.update({
|
|
572
596
|
buildID,
|
|
573
|
-
type: "bundle_build_done"
|
|
597
|
+
type: "bundle_build_done",
|
|
574
598
|
});
|
|
575
599
|
|
|
576
600
|
log(
|
|
@@ -591,13 +615,13 @@ class Server {
|
|
|
591
615
|
bundler: "delta",
|
|
592
616
|
build_id: context.buildID,
|
|
593
617
|
bundle_options: context.bundleOptions,
|
|
594
|
-
bundle_hash: context.graphId
|
|
618
|
+
bundle_hash: context.graphId,
|
|
595
619
|
};
|
|
596
620
|
},
|
|
597
621
|
|
|
598
622
|
createEndEntry(context) {
|
|
599
623
|
return {
|
|
600
|
-
outdated_modules: context.result.numModifiedFiles
|
|
624
|
+
outdated_modules: context.result.numModifiedFiles,
|
|
601
625
|
};
|
|
602
626
|
},
|
|
603
627
|
|
|
@@ -607,7 +631,7 @@ class Server {
|
|
|
607
631
|
graphOptions,
|
|
608
632
|
onProgress,
|
|
609
633
|
serializerOptions,
|
|
610
|
-
transformOptions
|
|
634
|
+
transformOptions,
|
|
611
635
|
}) => {
|
|
612
636
|
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
613
637
|
|
|
@@ -615,7 +639,7 @@ class Server {
|
|
|
615
639
|
? this._bundler.updateGraph(await revPromise, false)
|
|
616
640
|
: this._bundler.initializeGraph(entryFile, transformOptions, {
|
|
617
641
|
onProgress,
|
|
618
|
-
shallow: graphOptions.shallow
|
|
642
|
+
shallow: graphOptions.shallow,
|
|
619
643
|
}));
|
|
620
644
|
|
|
621
645
|
const serializer =
|
|
@@ -630,7 +654,8 @@ class Server {
|
|
|
630
654
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
631
655
|
this._config.transformer.asyncRequireModulePath,
|
|
632
656
|
{
|
|
633
|
-
transformOptions
|
|
657
|
+
transformOptions,
|
|
658
|
+
relativeTo: "project",
|
|
634
659
|
}
|
|
635
660
|
),
|
|
636
661
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
@@ -639,13 +664,14 @@ class Server {
|
|
|
639
664
|
dev: transformOptions.dev,
|
|
640
665
|
projectRoot: this._config.projectRoot,
|
|
641
666
|
modulesOnly: serializerOptions.modulesOnly,
|
|
642
|
-
runBeforeMainModule:
|
|
643
|
-
|
|
644
|
-
|
|
667
|
+
runBeforeMainModule:
|
|
668
|
+
this._config.serializer.getModulesRunBeforeMainModule(
|
|
669
|
+
path.relative(this._config.projectRoot, entryFile)
|
|
670
|
+
),
|
|
645
671
|
runModule: serializerOptions.runModule,
|
|
646
672
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
647
673
|
sourceUrl: serializerOptions.sourceUrl,
|
|
648
|
-
inlineSourceMap: serializerOptions.inlineSourceMap
|
|
674
|
+
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
649
675
|
}
|
|
650
676
|
);
|
|
651
677
|
const bundleCode = typeof bundle === "string" ? bundle : bundle.code;
|
|
@@ -655,7 +681,7 @@ class Server {
|
|
|
655
681
|
: delta.added.size + delta.modified.size + delta.deleted.size,
|
|
656
682
|
lastModifiedDate: revision.date,
|
|
657
683
|
nextRevId: revision.id,
|
|
658
|
-
bundle: bundleCode
|
|
684
|
+
bundle: bundleCode,
|
|
659
685
|
};
|
|
660
686
|
},
|
|
661
687
|
|
|
@@ -676,7 +702,7 @@ class Server {
|
|
|
676
702
|
String(result.numModifiedFiles)
|
|
677
703
|
);
|
|
678
704
|
mres.setHeader(DELTA_ID_HEADER, String(result.nextRevId));
|
|
679
|
-
mres.setHeader("Content-Type", "application/javascript");
|
|
705
|
+
mres.setHeader("Content-Type", "application/javascript; charset=UTF-8");
|
|
680
706
|
mres.setHeader("Last-Modified", result.lastModifiedDate.toUTCString());
|
|
681
707
|
mres.setHeader(
|
|
682
708
|
"Content-Length",
|
|
@@ -690,7 +716,7 @@ class Server {
|
|
|
690
716
|
await this._bundler.endGraph(graphId);
|
|
691
717
|
res.statusCode = 204;
|
|
692
718
|
res.end();
|
|
693
|
-
}
|
|
719
|
+
},
|
|
694
720
|
});
|
|
695
721
|
_processBytecodeBundleRequest = this._createRequestProcessor({
|
|
696
722
|
createStartEntry(context) {
|
|
@@ -701,13 +727,13 @@ class Server {
|
|
|
701
727
|
bundler: "delta",
|
|
702
728
|
build_id: context.buildID,
|
|
703
729
|
bundle_options: context.bundleOptions,
|
|
704
|
-
bundle_hash: context.graphId
|
|
730
|
+
bundle_hash: context.graphId,
|
|
705
731
|
};
|
|
706
732
|
},
|
|
707
733
|
|
|
708
734
|
createEndEntry(context) {
|
|
709
735
|
return {
|
|
710
|
-
outdated_modules: context.result.numModifiedFiles
|
|
736
|
+
outdated_modules: context.result.numModifiedFiles,
|
|
711
737
|
};
|
|
712
738
|
},
|
|
713
739
|
|
|
@@ -717,7 +743,7 @@ class Server {
|
|
|
717
743
|
graphOptions,
|
|
718
744
|
onProgress,
|
|
719
745
|
serializerOptions,
|
|
720
|
-
transformOptions
|
|
746
|
+
transformOptions,
|
|
721
747
|
}) => {
|
|
722
748
|
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
723
749
|
|
|
@@ -725,14 +751,15 @@ class Server {
|
|
|
725
751
|
? this._bundler.updateGraph(await revPromise, false)
|
|
726
752
|
: this._bundler.initializeGraph(entryFile, transformOptions, {
|
|
727
753
|
onProgress,
|
|
728
|
-
shallow: graphOptions.shallow
|
|
754
|
+
shallow: graphOptions.shallow,
|
|
729
755
|
}));
|
|
730
756
|
const bundle = bundleToBytecode(
|
|
731
757
|
baseBytecodeBundle(entryFile, revision.prepend, revision.graph, {
|
|
732
758
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
733
759
|
this._config.transformer.asyncRequireModulePath,
|
|
734
760
|
{
|
|
735
|
-
transformOptions
|
|
761
|
+
transformOptions,
|
|
762
|
+
relativeTo: "project",
|
|
736
763
|
}
|
|
737
764
|
),
|
|
738
765
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
@@ -741,13 +768,14 @@ class Server {
|
|
|
741
768
|
dev: transformOptions.dev,
|
|
742
769
|
projectRoot: this._config.projectRoot,
|
|
743
770
|
modulesOnly: serializerOptions.modulesOnly,
|
|
744
|
-
runBeforeMainModule:
|
|
745
|
-
|
|
746
|
-
|
|
771
|
+
runBeforeMainModule:
|
|
772
|
+
this._config.serializer.getModulesRunBeforeMainModule(
|
|
773
|
+
path.relative(this._config.projectRoot, entryFile)
|
|
774
|
+
),
|
|
747
775
|
runModule: serializerOptions.runModule,
|
|
748
776
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
749
777
|
sourceUrl: serializerOptions.sourceUrl,
|
|
750
|
-
inlineSourceMap: serializerOptions.inlineSourceMap
|
|
778
|
+
inlineSourceMap: serializerOptions.inlineSourceMap,
|
|
751
779
|
})
|
|
752
780
|
);
|
|
753
781
|
return {
|
|
@@ -756,7 +784,7 @@ class Server {
|
|
|
756
784
|
: delta.added.size + delta.modified.size + delta.deleted.size,
|
|
757
785
|
lastModifiedDate: revision.date,
|
|
758
786
|
nextRevId: revision.id,
|
|
759
|
-
bytecode: bundle.bytecode
|
|
787
|
+
bytecode: bundle.bytecode,
|
|
760
788
|
};
|
|
761
789
|
},
|
|
762
790
|
|
|
@@ -785,7 +813,7 @@ class Server {
|
|
|
785
813
|
);
|
|
786
814
|
mres.end(result.bytecode);
|
|
787
815
|
}
|
|
788
|
-
}
|
|
816
|
+
},
|
|
789
817
|
}); // This function ensures that modules in source maps are sorted in the same
|
|
790
818
|
// order as in a plain JS bundle.
|
|
791
819
|
|
|
@@ -807,13 +835,13 @@ class Server {
|
|
|
807
835
|
action_name: "Requesting sourcemap",
|
|
808
836
|
bundle_url: context.req.url,
|
|
809
837
|
entry_point: context.entryFile,
|
|
810
|
-
bundler: "delta"
|
|
838
|
+
bundler: "delta",
|
|
811
839
|
};
|
|
812
840
|
},
|
|
813
841
|
|
|
814
842
|
createEndEntry(context) {
|
|
815
843
|
return {
|
|
816
|
-
bundler: "delta"
|
|
844
|
+
bundler: "delta",
|
|
817
845
|
};
|
|
818
846
|
},
|
|
819
847
|
|
|
@@ -823,7 +851,7 @@ class Server {
|
|
|
823
851
|
graphOptions,
|
|
824
852
|
onProgress,
|
|
825
853
|
serializerOptions,
|
|
826
|
-
transformOptions
|
|
854
|
+
transformOptions,
|
|
827
855
|
}) => {
|
|
828
856
|
let revision;
|
|
829
857
|
|
|
@@ -835,7 +863,7 @@ class Server {
|
|
|
835
863
|
transformOptions,
|
|
836
864
|
{
|
|
837
865
|
onProgress,
|
|
838
|
-
shallow: graphOptions.shallow
|
|
866
|
+
shallow: graphOptions.shallow,
|
|
839
867
|
}
|
|
840
868
|
));
|
|
841
869
|
} else {
|
|
@@ -853,14 +881,14 @@ class Server {
|
|
|
853
881
|
|
|
854
882
|
return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
|
|
855
883
|
excludeSource: serializerOptions.excludeSource,
|
|
856
|
-
processModuleFilter: this._config.serializer.processModuleFilter
|
|
884
|
+
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
857
885
|
});
|
|
858
886
|
},
|
|
859
887
|
|
|
860
888
|
finish({ mres, result }) {
|
|
861
889
|
mres.setHeader("Content-Type", "application/json");
|
|
862
890
|
mres.end(result.toString());
|
|
863
|
-
}
|
|
891
|
+
},
|
|
864
892
|
});
|
|
865
893
|
_processAssetsRequest = this._createRequestProcessor({
|
|
866
894
|
createStartEntry(context) {
|
|
@@ -868,13 +896,13 @@ class Server {
|
|
|
868
896
|
action_name: "Requesting assets",
|
|
869
897
|
bundle_url: context.req.url,
|
|
870
898
|
entry_point: context.entryFile,
|
|
871
|
-
bundler: "delta"
|
|
899
|
+
bundler: "delta",
|
|
872
900
|
};
|
|
873
901
|
},
|
|
874
902
|
|
|
875
903
|
createEndEntry(context) {
|
|
876
904
|
return {
|
|
877
|
-
bundler: "delta"
|
|
905
|
+
bundler: "delta",
|
|
878
906
|
};
|
|
879
907
|
},
|
|
880
908
|
|
|
@@ -884,7 +912,7 @@ class Server {
|
|
|
884
912
|
transformOptions,
|
|
885
913
|
{
|
|
886
914
|
onProgress,
|
|
887
|
-
shallow: false
|
|
915
|
+
shallow: false,
|
|
888
916
|
}
|
|
889
917
|
);
|
|
890
918
|
return await getAssets(dependencies, {
|
|
@@ -892,48 +920,50 @@ class Server {
|
|
|
892
920
|
assetPlugins: this._config.transformer.assetPlugins,
|
|
893
921
|
platform: transformOptions.platform,
|
|
894
922
|
publicPath: this._config.transformer.publicPath,
|
|
895
|
-
projectRoot: this._config.projectRoot
|
|
923
|
+
projectRoot: this._config.projectRoot,
|
|
896
924
|
});
|
|
897
925
|
},
|
|
898
926
|
|
|
899
927
|
finish({ mres, result }) {
|
|
900
928
|
mres.setHeader("Content-Type", "application/json");
|
|
901
929
|
mres.end(JSON.stringify(result));
|
|
902
|
-
}
|
|
930
|
+
},
|
|
903
931
|
});
|
|
904
932
|
|
|
905
933
|
async _symbolicate(req, res) {
|
|
906
934
|
const getCodeFrame = (urls, symbolicatedStack) => {
|
|
907
935
|
for (let i = 0; i < symbolicatedStack.length; i++) {
|
|
908
|
-
const { collapse, column, file, lineNumber } = symbolicatedStack[i];
|
|
909
|
-
|
|
910
|
-
|
|
936
|
+
const { collapse, column, file, lineNumber } = symbolicatedStack[i];
|
|
937
|
+
const fileAbsolute = path.resolve(
|
|
938
|
+
this._config.projectRoot,
|
|
939
|
+
file !== null && file !== void 0 ? file : ""
|
|
940
|
+
);
|
|
911
941
|
|
|
912
|
-
if (collapse || lineNumber == null || urls.has(
|
|
942
|
+
if (collapse || lineNumber == null || urls.has(fileAbsolute)) {
|
|
913
943
|
continue;
|
|
914
944
|
}
|
|
915
945
|
|
|
916
946
|
try {
|
|
917
947
|
return {
|
|
918
948
|
content: codeFrameColumns(
|
|
919
|
-
fs.readFileSync(
|
|
949
|
+
fs.readFileSync(fileAbsolute, "utf8"),
|
|
920
950
|
{
|
|
921
951
|
// Metro returns 0 based columns but codeFrameColumns expects 1-based columns
|
|
922
952
|
// $FlowFixMe[unsafe-addition]
|
|
923
953
|
start: {
|
|
924
954
|
column: column + 1,
|
|
925
|
-
line: lineNumber
|
|
926
|
-
}
|
|
955
|
+
line: lineNumber,
|
|
956
|
+
},
|
|
927
957
|
},
|
|
928
958
|
{
|
|
929
|
-
forceColor: true
|
|
959
|
+
forceColor: true,
|
|
930
960
|
}
|
|
931
961
|
),
|
|
932
962
|
location: {
|
|
933
963
|
row: lineNumber,
|
|
934
|
-
column
|
|
964
|
+
column,
|
|
935
965
|
},
|
|
936
|
-
fileName: file
|
|
966
|
+
fileName: file,
|
|
937
967
|
};
|
|
938
968
|
} catch (error) {
|
|
939
969
|
console.error(error);
|
|
@@ -951,11 +981,11 @@ class Server {
|
|
|
951
981
|
/* $FlowFixMe: where is `rawBody` defined? Is it added by the `connect` framework? */
|
|
952
982
|
|
|
953
983
|
const body = await req.rawBody;
|
|
954
|
-
const stack = JSON.parse(body).stack.map(frame => {
|
|
984
|
+
const stack = JSON.parse(body).stack.map((frame) => {
|
|
955
985
|
if (frame.file && frame.file.includes("://")) {
|
|
956
986
|
return {
|
|
957
987
|
...frame,
|
|
958
|
-
file: this._config.server.rewriteRequestUrl(frame.file)
|
|
988
|
+
file: this._config.server.rewriteRequestUrl(frame.file),
|
|
959
989
|
};
|
|
960
990
|
}
|
|
961
991
|
|
|
@@ -963,7 +993,7 @@ class Server {
|
|
|
963
993
|
}); // In case of multiple bundles / HMR, some stack frames can have different URLs from others
|
|
964
994
|
|
|
965
995
|
const urls = new Set();
|
|
966
|
-
stack.forEach(frame => {
|
|
996
|
+
stack.forEach((frame) => {
|
|
967
997
|
const sourceUrl = frame.file; // Skip `/debuggerWorker.js` which does not need symbolication.
|
|
968
998
|
|
|
969
999
|
if (
|
|
@@ -990,7 +1020,7 @@ class Server {
|
|
|
990
1020
|
res.end(
|
|
991
1021
|
JSON.stringify({
|
|
992
1022
|
codeFrame: getCodeFrame(urls, symbolicatedStack),
|
|
993
|
-
stack: symbolicatedStack
|
|
1023
|
+
stack: symbolicatedStack,
|
|
994
1024
|
})
|
|
995
1025
|
);
|
|
996
1026
|
process.nextTick(() => {
|
|
@@ -1001,7 +1031,7 @@ class Server {
|
|
|
1001
1031
|
res.statusCode = 500;
|
|
1002
1032
|
res.end(
|
|
1003
1033
|
JSON.stringify({
|
|
1004
|
-
error: error.message
|
|
1034
|
+
error: error.message,
|
|
1005
1035
|
})
|
|
1006
1036
|
);
|
|
1007
1037
|
}
|
|
@@ -1018,7 +1048,7 @@ class Server {
|
|
|
1018
1048
|
transformOptions,
|
|
1019
1049
|
serializerOptions,
|
|
1020
1050
|
graphOptions,
|
|
1021
|
-
onProgress
|
|
1051
|
+
onProgress,
|
|
1022
1052
|
} = splitBundleOptions(options);
|
|
1023
1053
|
/**
|
|
1024
1054
|
* `entryFile` is relative to projectRoot, we need to use resolution function
|
|
@@ -1026,12 +1056,13 @@ class Server {
|
|
|
1026
1056
|
*/
|
|
1027
1057
|
|
|
1028
1058
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
1029
|
-
transformOptions
|
|
1059
|
+
transformOptions,
|
|
1060
|
+
relativeTo: "server",
|
|
1030
1061
|
});
|
|
1031
1062
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
1032
1063
|
shallow: graphOptions.shallow,
|
|
1033
|
-
experimentalImportBundleSupport:
|
|
1034
|
-
.experimentalImportBundleSupport
|
|
1064
|
+
experimentalImportBundleSupport:
|
|
1065
|
+
this._config.transformer.experimentalImportBundleSupport,
|
|
1035
1066
|
});
|
|
1036
1067
|
let revision;
|
|
1037
1068
|
|
|
@@ -1043,7 +1074,7 @@ class Server {
|
|
|
1043
1074
|
transformOptions,
|
|
1044
1075
|
{
|
|
1045
1076
|
onProgress,
|
|
1046
|
-
shallow: graphOptions.shallow
|
|
1077
|
+
shallow: graphOptions.shallow,
|
|
1047
1078
|
}
|
|
1048
1079
|
));
|
|
1049
1080
|
} else {
|
|
@@ -1059,17 +1090,21 @@ class Server {
|
|
|
1059
1090
|
return getExplodedSourceMap(
|
|
1060
1091
|
[...prepend, ...this._getSortedModules(graph)],
|
|
1061
1092
|
{
|
|
1062
|
-
processModuleFilter: this._config.serializer.processModuleFilter
|
|
1093
|
+
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
1063
1094
|
}
|
|
1064
1095
|
);
|
|
1065
1096
|
}
|
|
1066
1097
|
|
|
1067
|
-
async _resolveRelativePath(filePath, { transformOptions }) {
|
|
1098
|
+
async _resolveRelativePath(filePath, { transformOptions, relativeTo }) {
|
|
1068
1099
|
const resolutionFn = await transformHelpers.getResolveDependencyFn(
|
|
1069
1100
|
this._bundler.getBundler(),
|
|
1070
1101
|
transformOptions.platform
|
|
1071
1102
|
);
|
|
1072
|
-
|
|
1103
|
+
const rootDir =
|
|
1104
|
+
relativeTo === "server"
|
|
1105
|
+
? this._getServerRootDir()
|
|
1106
|
+
: this._config.projectRoot;
|
|
1107
|
+
return resolutionFn(`${rootDir}/.`, filePath);
|
|
1073
1108
|
}
|
|
1074
1109
|
|
|
1075
1110
|
getNewBuildID() {
|
|
@@ -1090,7 +1125,7 @@ class Server {
|
|
|
1090
1125
|
hot: false,
|
|
1091
1126
|
minify: false,
|
|
1092
1127
|
runtimeBytecodeVersion: null,
|
|
1093
|
-
unstable_transformProfile: "default"
|
|
1128
|
+
unstable_transformProfile: "default",
|
|
1094
1129
|
};
|
|
1095
1130
|
static DEFAULT_BUNDLE_OPTIONS = {
|
|
1096
1131
|
...Server.DEFAULT_GRAPH_OPTIONS,
|
|
@@ -1101,8 +1136,25 @@ class Server {
|
|
|
1101
1136
|
runModule: true,
|
|
1102
1137
|
shallow: false,
|
|
1103
1138
|
sourceMapUrl: null,
|
|
1104
|
-
sourceUrl: null
|
|
1139
|
+
sourceUrl: null,
|
|
1105
1140
|
};
|
|
1141
|
+
|
|
1142
|
+
_getServerRootDir() {
|
|
1143
|
+
var _this$_config$server$;
|
|
1144
|
+
|
|
1145
|
+
return (_this$_config$server$ = this._config.server.unstable_serverRoot) !==
|
|
1146
|
+
null && _this$_config$server$ !== void 0
|
|
1147
|
+
? _this$_config$server$
|
|
1148
|
+
: this._config.projectRoot;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
_getEntryPointAbsolutePath(entryFile) {
|
|
1152
|
+
return path.resolve(this._getServerRootDir(), entryFile);
|
|
1153
|
+
} // Wait for the server to finish initializing.
|
|
1154
|
+
|
|
1155
|
+
async ready() {
|
|
1156
|
+
await this._bundler.ready();
|
|
1157
|
+
}
|
|
1106
1158
|
}
|
|
1107
1159
|
|
|
1108
1160
|
function* zip(xs, ys) {
|