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/index.js.flow
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.
|
|
@@ -10,26 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
const IncrementalBundler = require('./IncrementalBundler');
|
|
14
|
-
const MetroHmrServer = require('./HmrServer');
|
|
15
|
-
const MetroServer = require('./Server');
|
|
16
|
-
|
|
17
|
-
const attachWebsocketServer = require('./lib/attachWebsocketServer');
|
|
18
|
-
const chalk = require('chalk');
|
|
19
|
-
const fs = require('fs');
|
|
20
|
-
const http = require('http');
|
|
21
|
-
const https = require('https');
|
|
22
|
-
const makeBuildCommand = require('./commands/build');
|
|
23
|
-
const makeDependenciesCommand = require('./commands/dependencies');
|
|
24
|
-
const makeServeCommand = require('./commands/serve');
|
|
25
|
-
const outputBundle = require('./shared/output/bundle');
|
|
26
|
-
|
|
27
|
-
const {loadConfig, mergeConfig, getDefaultConfig} = require('metro-config');
|
|
28
|
-
const {InspectorProxy} = require('metro-inspector-proxy');
|
|
29
|
-
|
|
30
13
|
import type {Graph} from './DeltaBundler';
|
|
31
14
|
import type {ServerOptions} from './Server';
|
|
32
|
-
import type {
|
|
15
|
+
import type {OutputOptions, RequestOptions} from './shared/types.flow.js';
|
|
33
16
|
import type {Server as HttpServer} from 'http';
|
|
34
17
|
import type {Server as HttpsServer} from 'https';
|
|
35
18
|
import type {
|
|
@@ -40,6 +23,23 @@ import type {
|
|
|
40
23
|
import type {CustomTransformOptions} from 'metro-transform-worker';
|
|
41
24
|
import typeof Yargs from 'yargs';
|
|
42
25
|
|
|
26
|
+
const makeBuildCommand = require('./commands/build');
|
|
27
|
+
const makeDependenciesCommand = require('./commands/dependencies');
|
|
28
|
+
const makeServeCommand = require('./commands/serve');
|
|
29
|
+
const MetroHmrServer = require('./HmrServer');
|
|
30
|
+
const IncrementalBundler = require('./IncrementalBundler');
|
|
31
|
+
const createWebsocketServer = require('./lib/createWebsocketServer');
|
|
32
|
+
const MetroServer = require('./Server');
|
|
33
|
+
const outputBundle = require('./shared/output/bundle');
|
|
34
|
+
const chalk = require('chalk');
|
|
35
|
+
const fs = require('fs');
|
|
36
|
+
const http = require('http');
|
|
37
|
+
const https = require('https');
|
|
38
|
+
const {getDefaultConfig, loadConfig, mergeConfig} = require('metro-config');
|
|
39
|
+
const {InspectorProxy} = require('metro-inspector-proxy');
|
|
40
|
+
const {parse} = require('url');
|
|
41
|
+
const ws = require('ws');
|
|
42
|
+
|
|
43
43
|
type MetroMiddleWare = {|
|
|
44
44
|
attachHmrServer: (httpServer: HttpServer | HttpsServer) => void,
|
|
45
45
|
end: () => void,
|
|
@@ -47,6 +47,11 @@ type MetroMiddleWare = {|
|
|
|
47
47
|
middleware: Middleware,
|
|
48
48
|
|};
|
|
49
49
|
|
|
50
|
+
export type RunMetroOptions = {
|
|
51
|
+
...ServerOptions,
|
|
52
|
+
waitForBundler?: boolean,
|
|
53
|
+
};
|
|
54
|
+
|
|
50
55
|
export type RunServerOptions = {|
|
|
51
56
|
hasReducedPerformance?: boolean,
|
|
52
57
|
host?: string,
|
|
@@ -57,6 +62,10 @@ export type RunServerOptions = {|
|
|
|
57
62
|
secure?: boolean, // deprecated
|
|
58
63
|
secureCert?: string, // deprecated
|
|
59
64
|
secureKey?: string, // deprecated
|
|
65
|
+
waitForBundler?: boolean,
|
|
66
|
+
websocketEndpoints?: {
|
|
67
|
+
[path: string]: typeof ws.Server,
|
|
68
|
+
},
|
|
60
69
|
|};
|
|
61
70
|
|
|
62
71
|
type BuildGraphOptions = {|
|
|
@@ -112,27 +121,53 @@ async function getConfig(config: InputConfigT): Promise<ConfigT> {
|
|
|
112
121
|
|
|
113
122
|
async function runMetro(
|
|
114
123
|
config: InputConfigT,
|
|
115
|
-
options?:
|
|
124
|
+
options?: RunMetroOptions,
|
|
116
125
|
): Promise<MetroServer> {
|
|
117
126
|
const mergedConfig = await getConfig(config);
|
|
127
|
+
const {
|
|
128
|
+
reporter,
|
|
129
|
+
server: {port},
|
|
130
|
+
} = mergedConfig;
|
|
118
131
|
|
|
119
|
-
|
|
132
|
+
reporter.update({
|
|
120
133
|
hasReducedPerformance: options
|
|
121
134
|
? Boolean(options.hasReducedPerformance)
|
|
122
135
|
: false,
|
|
123
|
-
port
|
|
136
|
+
port,
|
|
124
137
|
type: 'initialize_started',
|
|
125
138
|
});
|
|
126
139
|
|
|
127
|
-
|
|
140
|
+
const {waitForBundler = false, ...serverOptions} = options ?? {};
|
|
141
|
+
const server = new MetroServer(mergedConfig, serverOptions);
|
|
142
|
+
|
|
143
|
+
const readyPromise = server
|
|
144
|
+
.ready()
|
|
145
|
+
.then(() => {
|
|
146
|
+
reporter.update({
|
|
147
|
+
type: 'initialize_done',
|
|
148
|
+
port,
|
|
149
|
+
});
|
|
150
|
+
})
|
|
151
|
+
.catch(error => {
|
|
152
|
+
reporter.update({
|
|
153
|
+
type: 'initialize_failed',
|
|
154
|
+
port,
|
|
155
|
+
error,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
if (waitForBundler) {
|
|
159
|
+
await readyPromise;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return server;
|
|
128
163
|
}
|
|
129
164
|
|
|
130
165
|
exports.runMetro = runMetro;
|
|
131
166
|
exports.loadConfig = loadConfig;
|
|
132
167
|
|
|
133
|
-
|
|
168
|
+
const createConnectMiddleware = async function (
|
|
134
169
|
config: ConfigT,
|
|
135
|
-
options?:
|
|
170
|
+
options?: RunMetroOptions,
|
|
136
171
|
): Promise<MetroMiddleWare> {
|
|
137
172
|
const metroServer = await runMetro(config, options);
|
|
138
173
|
|
|
@@ -148,16 +183,23 @@ exports.createConnectMiddleware = async function(
|
|
|
148
183
|
|
|
149
184
|
return {
|
|
150
185
|
attachHmrServer(httpServer: HttpServer | HttpsServer): void {
|
|
151
|
-
|
|
152
|
-
httpServer,
|
|
153
|
-
path: '/hot',
|
|
154
|
-
// $FlowFixMe[method-unbinding]
|
|
186
|
+
const wss = createWebsocketServer({
|
|
155
187
|
websocketServer: new MetroHmrServer(
|
|
156
188
|
metroServer.getBundler(),
|
|
157
189
|
metroServer.getCreateModuleId(),
|
|
158
190
|
config,
|
|
159
191
|
),
|
|
160
192
|
});
|
|
193
|
+
httpServer.on('upgrade', (request, socket, head) => {
|
|
194
|
+
const {pathname} = parse(request.url);
|
|
195
|
+
if (pathname === '/hot') {
|
|
196
|
+
wss.handleUpgrade(request, socket, head, ws => {
|
|
197
|
+
wss.emit('connection', ws, request);
|
|
198
|
+
});
|
|
199
|
+
} else {
|
|
200
|
+
socket.destroy();
|
|
201
|
+
}
|
|
202
|
+
});
|
|
161
203
|
},
|
|
162
204
|
metroServer,
|
|
163
205
|
middleware: enhancedMiddleware,
|
|
@@ -166,6 +208,7 @@ exports.createConnectMiddleware = async function(
|
|
|
166
208
|
},
|
|
167
209
|
};
|
|
168
210
|
};
|
|
211
|
+
exports.createConnectMiddleware = createConnectMiddleware;
|
|
169
212
|
|
|
170
213
|
exports.runServer = async (
|
|
171
214
|
config: ConfigT,
|
|
@@ -178,6 +221,8 @@ exports.runServer = async (
|
|
|
178
221
|
secure, //deprecated
|
|
179
222
|
secureCert, // deprecated
|
|
180
223
|
secureKey, // deprecated
|
|
224
|
+
waitForBundler = false,
|
|
225
|
+
websocketEndpoints = {},
|
|
181
226
|
}: RunServerOptions,
|
|
182
227
|
): Promise<HttpServer | HttpsServer> => {
|
|
183
228
|
if (secure != null || secureCert != null || secureKey != null) {
|
|
@@ -194,12 +239,9 @@ exports.runServer = async (
|
|
|
194
239
|
|
|
195
240
|
const serverApp = connect();
|
|
196
241
|
|
|
197
|
-
const {
|
|
198
|
-
attachHmrServer,
|
|
199
|
-
middleware,
|
|
200
|
-
end,
|
|
201
|
-
} = await exports.createConnectMiddleware(config, {
|
|
242
|
+
const {middleware, end, metroServer} = await createConnectMiddleware(config, {
|
|
202
243
|
hasReducedPerformance,
|
|
244
|
+
waitForBundler,
|
|
203
245
|
});
|
|
204
246
|
|
|
205
247
|
serverApp.use(middleware);
|
|
@@ -244,10 +286,36 @@ exports.runServer = async (
|
|
|
244
286
|
onReady(httpServer);
|
|
245
287
|
}
|
|
246
288
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
289
|
+
Object.assign(websocketEndpoints, {
|
|
290
|
+
...(inspectorProxy
|
|
291
|
+
? {...inspectorProxy.createWebSocketListeners(httpServer)}
|
|
292
|
+
: {}),
|
|
293
|
+
'/hot': createWebsocketServer({
|
|
294
|
+
websocketServer: new MetroHmrServer(
|
|
295
|
+
metroServer.getBundler(),
|
|
296
|
+
metroServer.getCreateModuleId(),
|
|
297
|
+
config,
|
|
298
|
+
),
|
|
299
|
+
}),
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
httpServer.on('upgrade', (request, socket, head) => {
|
|
303
|
+
const {pathname} = parse(request.url);
|
|
304
|
+
if (pathname != null && websocketEndpoints[pathname]) {
|
|
305
|
+
websocketEndpoints[pathname].handleUpgrade(
|
|
306
|
+
request,
|
|
307
|
+
socket,
|
|
308
|
+
head,
|
|
309
|
+
ws => {
|
|
310
|
+
websocketEndpoints[pathname].emit('connection', ws, request);
|
|
311
|
+
},
|
|
312
|
+
);
|
|
313
|
+
} else {
|
|
314
|
+
socket.destroy();
|
|
315
|
+
}
|
|
316
|
+
});
|
|
250
317
|
|
|
318
|
+
if (inspectorProxy) {
|
|
251
319
|
// TODO(hypuk): Refactor inspectorProxy.processRequest into separate request handlers
|
|
252
320
|
// so that we could provide routes (/json/list and /json/version) here.
|
|
253
321
|
// Currently this causes Metro to give warning about T31407894.
|
|
@@ -343,7 +411,7 @@ exports.runBuild = async (
|
|
|
343
411
|
}
|
|
344
412
|
};
|
|
345
413
|
|
|
346
|
-
exports.buildGraph = async function(
|
|
414
|
+
exports.buildGraph = async function (
|
|
347
415
|
config: InputConfigT,
|
|
348
416
|
{
|
|
349
417
|
customTransformOptions = Object.create(null),
|
|
@@ -373,8 +441,7 @@ exports.buildGraph = async function(
|
|
|
373
441
|
}
|
|
374
442
|
};
|
|
375
443
|
|
|
376
|
-
exports.attachMetroCli = function(
|
|
377
|
-
// $FlowFixMe[value-as-type]
|
|
444
|
+
exports.attachMetroCli = function (
|
|
378
445
|
yargs: Yargs,
|
|
379
446
|
{
|
|
380
447
|
build = {},
|
|
@@ -386,7 +453,6 @@ exports.attachMetroCli = function(
|
|
|
386
453
|
dependencies: any,
|
|
387
454
|
...
|
|
388
455
|
} = {},
|
|
389
|
-
// $FlowFixMe[value-as-type]
|
|
390
456
|
): Yargs {
|
|
391
457
|
if (build) {
|
|
392
458
|
const {command, description, builder, handler} = makeBuildCommand();
|
|
@@ -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.
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
module.exports = {
|
|
13
13
|
registerAsset(data) {
|
|
14
14
|
return data;
|
|
15
|
-
}
|
|
15
|
+
},
|
|
16
16
|
};
|
|
@@ -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.
|
|
@@ -13,5 +13,5 @@ const Foo = require("./Foo");
|
|
|
13
13
|
|
|
14
14
|
module.exports = {
|
|
15
15
|
type: "bar",
|
|
16
|
-
foo: Foo.type
|
|
16
|
+
foo: Foo.type,
|
|
17
17
|
};
|
|
@@ -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.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
require("./AssetRegistry");
|
|
13
13
|
|
|
14
|
-
const calcSum = value => {
|
|
14
|
+
const calcSum = (value) => {
|
|
15
15
|
// some random function
|
|
16
16
|
const error = new Error("SOURCEMAP: value: " + value);
|
|
17
17
|
return error;
|
|
@@ -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.
|
|
@@ -13,5 +13,5 @@ const asset = require("./test.png");
|
|
|
13
13
|
|
|
14
14
|
module.exports = {
|
|
15
15
|
type: "foo",
|
|
16
|
-
asset
|
|
16
|
+
asset,
|
|
17
17
|
};
|
|
@@ -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.
|
|
@@ -15,8 +15,9 @@ const Foo = require("./Foo"); // $FlowFixMe: Flow doesn't understand TypeScript
|
|
|
15
15
|
|
|
16
16
|
const TypeScript = require("./TypeScript");
|
|
17
17
|
|
|
18
|
+
Object.keys({ ...Bar });
|
|
18
19
|
module.exports = {
|
|
19
20
|
Foo,
|
|
20
21
|
Bar,
|
|
21
|
-
TypeScript
|
|
22
|
+
TypeScript,
|
|
22
23
|
};
|
|
@@ -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.
|
|
@@ -15,4 +15,6 @@ const Foo = require('./Foo');
|
|
|
15
15
|
// $FlowFixMe: Flow doesn't understand TypeScript
|
|
16
16
|
const TypeScript = require('./TypeScript');
|
|
17
17
|
|
|
18
|
+
Object.keys({...Bar});
|
|
19
|
+
|
|
18
20
|
module.exports = {Foo, Bar, TypeScript};
|
|
@@ -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.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
13
|
+
value: true,
|
|
14
14
|
});
|
|
15
15
|
exports.myFunction = myFunction;
|
|
16
16
|
exports.foo = exports.default = void 0;
|
|
@@ -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.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
13
|
+
value: true,
|
|
14
14
|
});
|
|
15
15
|
exports.myFunction = myFunction;
|
|
16
16
|
exports.foo = exports.default = void 0;
|
|
@@ -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.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
13
|
+
value: true,
|
|
14
14
|
});
|
|
15
15
|
exports.myFunction = myFunction;
|
|
16
16
|
exports.foo = exports.default = void 0;
|
|
@@ -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.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
13
|
+
value: true,
|
|
14
14
|
});
|
|
15
15
|
exports.myFunction = myFunction;
|
|
16
16
|
exports.foo = exports.default = void 0;
|
|
@@ -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.
|
|
@@ -10,5 +10,5 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
module.exports = {
|
|
13
|
-
foo: "export-5: FOO"
|
|
13
|
+
foo: "export-5: FOO",
|
|
14
14
|
};
|
|
@@ -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.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
13
|
+
value: true,
|
|
14
14
|
});
|
|
15
15
|
exports.foo = exports.default = void 0;
|
|
16
16
|
var _default = "export-6: DEFAULT";
|
|
@@ -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.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
13
|
+
value: true,
|
|
14
14
|
});
|
|
15
15
|
exports.foo = exports.default = void 0;
|
|
16
16
|
var _default = null;
|
|
@@ -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.
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
13
|
+
value: true,
|
|
14
14
|
});
|
|
15
15
|
exports.foo = exports.default = void 0;
|
|
16
16
|
var _default = "export-primitive-default: DEFAULT";
|
|
@@ -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.
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
13
|
+
value: true,
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "namedDefaultExported", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function() {
|
|
17
|
+
get: function () {
|
|
18
18
|
return _export3.default;
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
20
|
});
|
|
21
21
|
Object.defineProperty(exports, "default", {
|
|
22
22
|
enumerable: true,
|
|
23
|
-
get: function() {
|
|
23
|
+
get: function () {
|
|
24
24
|
return _export4.foo;
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
26
|
});
|
|
27
27
|
exports.asyncImportESM = exports.asyncImportCJS = exports.extraData = void 0;
|
|
28
28
|
|
|
@@ -48,7 +48,7 @@ function _getRequireWildcardCache(nodeInterop) {
|
|
|
48
48
|
if (typeof WeakMap !== "function") return null;
|
|
49
49
|
var cacheBabelInterop = new WeakMap();
|
|
50
50
|
var cacheNodeInterop = new WeakMap();
|
|
51
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
51
|
+
return (_getRequireWildcardCache = function (nodeInterop) {
|
|
52
52
|
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
53
53
|
})(nodeInterop);
|
|
54
54
|
}
|
|
@@ -93,7 +93,7 @@ const extraData = {
|
|
|
93
93
|
myFoo: _export.foo,
|
|
94
94
|
myFunction: (0, _export.myFunction)(),
|
|
95
95
|
primitiveDefault: _exportPrimitiveDefault.default,
|
|
96
|
-
primitiveFoo: _exportPrimitiveDefault.foo
|
|
96
|
+
primitiveFoo: _exportPrimitiveDefault.foo,
|
|
97
97
|
};
|
|
98
98
|
exports.extraData = extraData;
|
|
99
99
|
const asyncImportCJS = import("./export-5");
|