metro 0.65.2 → 0.67.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 +27 -27
- package/src/Assets.js +9 -9
- package/src/Assets.js.flow +5 -7
- package/src/Bundler/util.js +17 -15
- package/src/Bundler/util.js.flow +12 -10
- package/src/Bundler.js +22 -9
- package/src/Bundler.js.flow +20 -7
- package/src/DeltaBundler/DeltaCalculator.js +17 -15
- package/src/DeltaBundler/DeltaCalculator.js.flow +9 -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 +18 -8
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +19 -10
- 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 +16 -14
- package/src/DeltaBundler/Transformer.js.flow +15 -15
- package/src/DeltaBundler/Worker.js +8 -11
- package/src/DeltaBundler/Worker.js.flow +8 -11
- package/src/DeltaBundler/WorkerFarm.js +15 -18
- package/src/DeltaBundler/WorkerFarm.js.flow +9 -11
- 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 +15 -1
- package/src/DeltaBundler.js +5 -5
- package/src/DeltaBundler.js.flow +4 -4
- package/src/HmrServer.js +73 -55
- package/src/HmrServer.js.flow +42 -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 +46 -32
- package/src/IncrementalBundler.js.flow +32 -24
- package/src/ModuleGraph/module.js +3 -3
- package/src/ModuleGraph/module.js.flow +1 -1
- package/src/ModuleGraph/node-haste/HasteFS.js +5 -3
- package/src/ModuleGraph/node-haste/HasteFS.js.flow +3 -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 +41 -31
- package/src/ModuleGraph/node-haste/node-haste.js.flow +28 -22
- 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 +61 -40
- package/src/ModuleGraph/output/util.js.flow +51 -28
- 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 +47 -31
- package/src/ModuleGraph/worker/JsFileWrapping.js +16 -16
- 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 +16 -18
- 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 +204 -150
- package/src/Server.js.flow +131 -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 +19 -19
- package/src/commands/serve.js.flow +7 -9
- package/src/index.js +117 -50
- package/src/index.js.flow +108 -40
- 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 +2 -2
- package/src/integration_tests/basic_bundle/TestBundle.js.flow +1 -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 +17 -17
- 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 +10 -6
- package/src/lib/BatchProcessor.js.flow +6 -1
- package/src/lib/JsonReporter.js +3 -2
- package/src/lib/JsonReporter.js.flow +2 -1
- package/src/lib/RamBundleParser.js +1 -1
- package/src/lib/RamBundleParser.js.flow +1 -1
- package/src/lib/TerminalReporter.js +15 -15
- package/src/lib/TerminalReporter.js.flow +15 -16
- 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} +13 -23
- 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 +18 -20
- 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 +16 -15
- package/src/lib/getPrependedScripts.js.flow +8 -8
- package/src/lib/logToConsole.js +12 -5
- package/src/lib/logToConsole.js.flow +19 -6
- 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 +18 -4
- package/src/lib/splitBundleOptions.js +5 -5
- package/src/lib/splitBundleOptions.js.flow +1 -1
- package/src/lib/transformHelpers.js +11 -10
- package/src/lib/transformHelpers.js.flow +6 -13
- package/src/node-haste/DependencyGraph/ModuleResolution.js +51 -30
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +49 -48
- 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 +51 -118
- package/src/node-haste/DependencyGraph.js.flow +38 -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 +2 -2
- package/src/node-haste/Package.js.flow +1 -1
- package/src/node-haste/lib/AssetPaths.js +5 -5
- package/src/node-haste/lib/AssetPaths.js.flow +7 -6
- package/src/node-haste/lib/parsePlatformFilePath.js +4 -4
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -2
- package/src/shared/output/RamBundle/as-assets.js +14 -15
- package/src/shared/output/RamBundle/as-assets.js.flow +9 -11
- 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 +6 -4
- 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.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.
|
|
@@ -9,47 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
|
-
const IncrementalBundler = require('./IncrementalBundler');
|
|
13
|
-
const MultipartResponse = require('./Server/MultipartResponse');
|
|
14
|
-
const ResourceNotFoundError = require('./IncrementalBundler/ResourceNotFoundError');
|
|
15
|
-
|
|
16
|
-
const baseBytecodeBundle = require('./DeltaBundler/Serializers/baseBytecodeBundle');
|
|
17
|
-
const baseJSBundle = require('./DeltaBundler/Serializers/baseJSBundle');
|
|
18
|
-
const bundleToBytecode = require('./lib/bundleToBytecode');
|
|
19
|
-
const bundleToString = require('./lib/bundleToString');
|
|
20
|
-
|
|
21
|
-
const {codeFrameColumns} = require('@babel/code-frame');
|
|
22
|
-
const debug = require('debug')('Metro:Server');
|
|
23
|
-
const formatBundlingError = require('./lib/formatBundlingError');
|
|
24
|
-
const fs = require('graceful-fs');
|
|
25
|
-
const getAllFiles = require('./DeltaBundler/Serializers/getAllFiles');
|
|
26
|
-
const getAssets = require('./DeltaBundler/Serializers/getAssets');
|
|
27
|
-
const getGraphId = require('./lib/getGraphId');
|
|
28
|
-
const getRamBundleInfo = require('./DeltaBundler/Serializers/getRamBundleInfo');
|
|
29
|
-
const mime = require('mime-types');
|
|
30
|
-
const parseOptionsFromUrl = require('./lib/parseOptionsFromUrl');
|
|
31
|
-
const parsePlatformFilePath = require('./node-haste/lib/parsePlatformFilePath');
|
|
32
|
-
const path = require('path');
|
|
33
|
-
const sourceMapString = require('./DeltaBundler/Serializers/sourceMapString');
|
|
34
|
-
const splitBundleOptions = require('./lib/splitBundleOptions');
|
|
35
|
-
const symbolicate = require('./Server/symbolicate');
|
|
36
|
-
const transformHelpers = require('./lib/transformHelpers');
|
|
37
|
-
const url = require('url');
|
|
38
|
-
|
|
39
|
-
const {VERSION: BYTECODE_VERSION} = require('metro-hermes-compiler');
|
|
40
|
-
const {getAsset} = require('./Assets');
|
|
41
|
-
const {
|
|
42
|
-
getExplodedSourceMap,
|
|
43
|
-
} = require('./DeltaBundler/Serializers/getExplodedSourceMap');
|
|
44
|
-
const {
|
|
45
|
-
Logger,
|
|
46
|
-
Logger: {createActionStartEntry, createActionEndEntry, log},
|
|
47
|
-
} = require('metro-core');
|
|
48
|
-
|
|
49
12
|
import type {AssetData} from './Assets';
|
|
50
13
|
import type {ExplodedSourceMap} from './DeltaBundler/Serializers/getExplodedSourceMap';
|
|
51
14
|
import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo';
|
|
52
|
-
import type {
|
|
15
|
+
import type {
|
|
16
|
+
Graph,
|
|
17
|
+
Module,
|
|
18
|
+
TransformInputOptions,
|
|
19
|
+
} from './DeltaBundler/types.flow';
|
|
53
20
|
import type {MixedOutput, TransformResult} from './DeltaBundler/types.flow';
|
|
54
21
|
import type {RevisionId} from './IncrementalBundler';
|
|
55
22
|
import type {GraphId} from './lib/getGraphId';
|
|
@@ -68,6 +35,42 @@ import type {
|
|
|
68
35
|
LogEntry,
|
|
69
36
|
} from 'metro-core/src/Logger';
|
|
70
37
|
|
|
38
|
+
const {getAsset} = require('./Assets');
|
|
39
|
+
const baseBytecodeBundle = require('./DeltaBundler/Serializers/baseBytecodeBundle');
|
|
40
|
+
const baseJSBundle = require('./DeltaBundler/Serializers/baseJSBundle');
|
|
41
|
+
const getAllFiles = require('./DeltaBundler/Serializers/getAllFiles');
|
|
42
|
+
const getAssets = require('./DeltaBundler/Serializers/getAssets');
|
|
43
|
+
const {
|
|
44
|
+
getExplodedSourceMap,
|
|
45
|
+
} = require('./DeltaBundler/Serializers/getExplodedSourceMap');
|
|
46
|
+
const getRamBundleInfo = require('./DeltaBundler/Serializers/getRamBundleInfo');
|
|
47
|
+
const sourceMapString = require('./DeltaBundler/Serializers/sourceMapString');
|
|
48
|
+
const IncrementalBundler = require('./IncrementalBundler');
|
|
49
|
+
const ResourceNotFoundError = require('./IncrementalBundler/ResourceNotFoundError');
|
|
50
|
+
const bundleToBytecode = require('./lib/bundleToBytecode');
|
|
51
|
+
const bundleToString = require('./lib/bundleToString');
|
|
52
|
+
const formatBundlingError = require('./lib/formatBundlingError');
|
|
53
|
+
const getGraphId = require('./lib/getGraphId');
|
|
54
|
+
const parseOptionsFromUrl = require('./lib/parseOptionsFromUrl');
|
|
55
|
+
const splitBundleOptions = require('./lib/splitBundleOptions');
|
|
56
|
+
const transformHelpers = require('./lib/transformHelpers');
|
|
57
|
+
const parsePlatformFilePath = require('./node-haste/lib/parsePlatformFilePath');
|
|
58
|
+
const MultipartResponse = require('./Server/MultipartResponse');
|
|
59
|
+
const symbolicate = require('./Server/symbolicate');
|
|
60
|
+
const {codeFrameColumns} = require('@babel/code-frame');
|
|
61
|
+
const debug = require('debug')('Metro:Server');
|
|
62
|
+
const fs = require('graceful-fs');
|
|
63
|
+
const {
|
|
64
|
+
Logger,
|
|
65
|
+
Logger: {createActionStartEntry, createActionEndEntry, log},
|
|
66
|
+
} = require('metro-core');
|
|
67
|
+
const {VERSION: BYTECODE_VERSION} = require('metro-hermes-compiler');
|
|
68
|
+
const mime = require('mime-types');
|
|
69
|
+
const nullthrows = require('nullthrows');
|
|
70
|
+
const path = require('path');
|
|
71
|
+
const querystring = require('querystring');
|
|
72
|
+
const url = require('url');
|
|
73
|
+
|
|
71
74
|
export type SegmentLoadData = {[number]: [Array<number>, ?number], ...};
|
|
72
75
|
export type BundleMetadata = {
|
|
73
76
|
hash: string,
|
|
@@ -164,9 +167,7 @@ class Server {
|
|
|
164
167
|
return this._createModuleId;
|
|
165
168
|
}
|
|
166
169
|
|
|
167
|
-
async build(
|
|
168
|
-
options: BundleOptions,
|
|
169
|
-
): Promise<{
|
|
170
|
+
async build(options: BundleOptions): Promise<{
|
|
170
171
|
code: string,
|
|
171
172
|
map: string,
|
|
172
173
|
...
|
|
@@ -188,12 +189,12 @@ class Server {
|
|
|
188
189
|
},
|
|
189
190
|
);
|
|
190
191
|
|
|
191
|
-
const entryPoint =
|
|
192
|
+
const entryPoint = this._getEntryPointAbsolutePath(entryFile);
|
|
192
193
|
|
|
193
194
|
const bundleOptions = {
|
|
194
195
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
195
196
|
this._config.transformer.asyncRequireModulePath,
|
|
196
|
-
{transformOptions},
|
|
197
|
+
{transformOptions, relativeTo: 'project'},
|
|
197
198
|
),
|
|
198
199
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
199
200
|
createModuleId: this._createModuleId,
|
|
@@ -201,9 +202,10 @@ class Server {
|
|
|
201
202
|
dev: transformOptions.dev,
|
|
202
203
|
projectRoot: this._config.projectRoot,
|
|
203
204
|
modulesOnly: serializerOptions.modulesOnly,
|
|
204
|
-
runBeforeMainModule:
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
runBeforeMainModule:
|
|
206
|
+
this._config.serializer.getModulesRunBeforeMainModule(
|
|
207
|
+
path.relative(this._config.projectRoot, entryPoint),
|
|
208
|
+
),
|
|
207
209
|
runModule: serializerOptions.runModule,
|
|
208
210
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
209
211
|
sourceUrl: serializerOptions.sourceUrl,
|
|
@@ -259,12 +261,12 @@ class Server {
|
|
|
259
261
|
{onProgress, shallow: graphOptions.shallow},
|
|
260
262
|
);
|
|
261
263
|
|
|
262
|
-
const entryPoint =
|
|
264
|
+
const entryPoint = this._getEntryPointAbsolutePath(entryFile);
|
|
263
265
|
|
|
264
266
|
return await getRamBundleInfo(entryPoint, prepend, graph, {
|
|
265
267
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
266
268
|
this._config.transformer.asyncRequireModulePath,
|
|
267
|
-
{transformOptions},
|
|
269
|
+
{transformOptions, relativeTo: 'project'},
|
|
268
270
|
),
|
|
269
271
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
270
272
|
createModuleId: this._createModuleId,
|
|
@@ -275,9 +277,10 @@ class Server {
|
|
|
275
277
|
platform: transformOptions.platform,
|
|
276
278
|
projectRoot: this._config.projectRoot,
|
|
277
279
|
modulesOnly: serializerOptions.modulesOnly,
|
|
278
|
-
runBeforeMainModule:
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
runBeforeMainModule:
|
|
281
|
+
this._config.serializer.getModulesRunBeforeMainModule(
|
|
282
|
+
path.relative(this._config.projectRoot, entryPoint),
|
|
283
|
+
),
|
|
281
284
|
runModule: serializerOptions.runModule,
|
|
282
285
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
283
286
|
sourceUrl: serializerOptions.sourceUrl,
|
|
@@ -286,9 +289,8 @@ class Server {
|
|
|
286
289
|
}
|
|
287
290
|
|
|
288
291
|
async getAssets(options: BundleOptions): Promise<$ReadOnlyArray<AssetData>> {
|
|
289
|
-
const {entryFile, transformOptions, onProgress} =
|
|
290
|
-
options
|
|
291
|
-
);
|
|
292
|
+
const {entryFile, transformOptions, onProgress} =
|
|
293
|
+
splitBundleOptions(options);
|
|
292
294
|
|
|
293
295
|
const dependencies = await this._bundler.getDependencies(
|
|
294
296
|
[entryFile],
|
|
@@ -300,7 +302,7 @@ class Server {
|
|
|
300
302
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
301
303
|
assetPlugins: this._config.transformer.assetPlugins,
|
|
302
304
|
platform: transformOptions.platform,
|
|
303
|
-
projectRoot: this.
|
|
305
|
+
projectRoot: this._getServerRootDir(),
|
|
304
306
|
publicPath: this._config.transformer.publicPath,
|
|
305
307
|
});
|
|
306
308
|
}
|
|
@@ -367,8 +369,21 @@ class Server {
|
|
|
367
369
|
|
|
368
370
|
async _processSingleAssetRequest(req: IncomingMessage, res: ServerResponse) {
|
|
369
371
|
const urlObj = url.parse(decodeURI(req.url), true);
|
|
370
|
-
|
|
371
|
-
urlObj &&
|
|
372
|
+
let [, assetPath] =
|
|
373
|
+
(urlObj &&
|
|
374
|
+
urlObj.pathname &&
|
|
375
|
+
urlObj.pathname.match(/^\/assets\/(.+)$/)) ||
|
|
376
|
+
[];
|
|
377
|
+
|
|
378
|
+
if (!assetPath && urlObj && urlObj.query && urlObj.query.unstable_path) {
|
|
379
|
+
const [, actualPath, secondaryQuery] = nullthrows(
|
|
380
|
+
urlObj.query.unstable_path.match(/^([^?]*)\??(.*)$/),
|
|
381
|
+
);
|
|
382
|
+
if (secondaryQuery) {
|
|
383
|
+
Object.assign(urlObj.query, querystring.parse(secondaryQuery));
|
|
384
|
+
}
|
|
385
|
+
assetPath = actualPath;
|
|
386
|
+
}
|
|
372
387
|
|
|
373
388
|
if (!assetPath) {
|
|
374
389
|
throw new Error('Could not extract asset path from URL');
|
|
@@ -383,7 +398,7 @@ class Server {
|
|
|
383
398
|
|
|
384
399
|
try {
|
|
385
400
|
const data = await getAsset(
|
|
386
|
-
assetPath
|
|
401
|
+
assetPath,
|
|
387
402
|
this._config.projectRoot,
|
|
388
403
|
this._config.watchFolders,
|
|
389
404
|
urlObj.query.platform,
|
|
@@ -394,7 +409,7 @@ class Server {
|
|
|
394
409
|
if (process.env.REACT_NATIVE_ENABLE_ASSET_CACHING === true) {
|
|
395
410
|
res.setHeader('Cache-Control', 'max-age=31536000');
|
|
396
411
|
}
|
|
397
|
-
res.end(this._rangeRequestMiddleware(req, res, data, assetPath
|
|
412
|
+
res.end(this._rangeRequestMiddleware(req, res, data, assetPath));
|
|
398
413
|
process.nextTick(() => {
|
|
399
414
|
log(createActionEndEntry(processingAssetRequestLogEntry));
|
|
400
415
|
});
|
|
@@ -408,7 +423,7 @@ class Server {
|
|
|
408
423
|
processRequest: (
|
|
409
424
|
IncomingMessage,
|
|
410
425
|
ServerResponse,
|
|
411
|
-
(e: ?Error) => mixed,
|
|
426
|
+
((e: ?Error) => mixed),
|
|
412
427
|
) => void = (
|
|
413
428
|
req: IncomingMessage,
|
|
414
429
|
res: ServerResponse,
|
|
@@ -470,7 +485,7 @@ class Server {
|
|
|
470
485
|
res,
|
|
471
486
|
this._parseOptions(formattedUrl),
|
|
472
487
|
);
|
|
473
|
-
} else if (pathname.startsWith('/assets/')) {
|
|
488
|
+
} else if (pathname.startsWith('/assets/') || pathname === '/assets') {
|
|
474
489
|
await this._processSingleAssetRequest(req, res);
|
|
475
490
|
} else if (pathname === '/symbolicate') {
|
|
476
491
|
await this._symbolicate(req, res);
|
|
@@ -499,12 +514,8 @@ class Server {
|
|
|
499
514
|
res: ServerResponse,
|
|
500
515
|
bundleOptions: BundleOptions,
|
|
501
516
|
): Promise<void> {
|
|
502
|
-
const {
|
|
503
|
-
|
|
504
|
-
graphOptions,
|
|
505
|
-
transformOptions,
|
|
506
|
-
serializerOptions,
|
|
507
|
-
} = splitBundleOptions(bundleOptions);
|
|
517
|
+
const {entryFile, graphOptions, transformOptions, serializerOptions} =
|
|
518
|
+
splitBundleOptions(bundleOptions);
|
|
508
519
|
|
|
509
520
|
/**
|
|
510
521
|
* `entryFile` is relative to projectRoot, we need to use resolution function
|
|
@@ -512,11 +523,12 @@ class Server {
|
|
|
512
523
|
*/
|
|
513
524
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
514
525
|
transformOptions,
|
|
526
|
+
relativeTo: 'server',
|
|
515
527
|
});
|
|
516
528
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
517
529
|
shallow: graphOptions.shallow,
|
|
518
|
-
experimentalImportBundleSupport:
|
|
519
|
-
.experimentalImportBundleSupport,
|
|
530
|
+
experimentalImportBundleSupport:
|
|
531
|
+
this._config.transformer.experimentalImportBundleSupport,
|
|
520
532
|
});
|
|
521
533
|
|
|
522
534
|
// For resources that support deletion, handle the DELETE method.
|
|
@@ -571,6 +583,7 @@ class Server {
|
|
|
571
583
|
// is not actually sent in the response until after bundling is complete. This
|
|
572
584
|
// would defeat the purpose of sending progress, so we `uncork` the stream now
|
|
573
585
|
// which will force the response to flush to the client immediately.
|
|
586
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
574
587
|
if (res.socket != null && res.socket.uncork != null) {
|
|
575
588
|
res.socket.uncork();
|
|
576
589
|
}
|
|
@@ -645,6 +658,8 @@ class Server {
|
|
|
645
658
|
stack: formattedError.message,
|
|
646
659
|
});
|
|
647
660
|
|
|
661
|
+
debug('Bundling error', error);
|
|
662
|
+
|
|
648
663
|
return;
|
|
649
664
|
}
|
|
650
665
|
|
|
@@ -723,7 +738,7 @@ class Server {
|
|
|
723
738
|
{
|
|
724
739
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
725
740
|
this._config.transformer.asyncRequireModulePath,
|
|
726
|
-
{transformOptions},
|
|
741
|
+
{transformOptions, relativeTo: 'project'},
|
|
727
742
|
),
|
|
728
743
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
729
744
|
createModuleId: this._createModuleId,
|
|
@@ -731,9 +746,10 @@ class Server {
|
|
|
731
746
|
dev: transformOptions.dev,
|
|
732
747
|
projectRoot: this._config.projectRoot,
|
|
733
748
|
modulesOnly: serializerOptions.modulesOnly,
|
|
734
|
-
runBeforeMainModule:
|
|
735
|
-
|
|
736
|
-
|
|
749
|
+
runBeforeMainModule:
|
|
750
|
+
this._config.serializer.getModulesRunBeforeMainModule(
|
|
751
|
+
path.relative(this._config.projectRoot, entryFile),
|
|
752
|
+
),
|
|
737
753
|
runModule: serializerOptions.runModule,
|
|
738
754
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
739
755
|
sourceUrl: serializerOptions.sourceUrl,
|
|
@@ -769,7 +785,7 @@ class Server {
|
|
|
769
785
|
String(result.numModifiedFiles),
|
|
770
786
|
);
|
|
771
787
|
mres.setHeader(DELTA_ID_HEADER, String(result.nextRevId));
|
|
772
|
-
mres.setHeader('Content-Type', 'application/javascript');
|
|
788
|
+
mres.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
|
773
789
|
mres.setHeader('Last-Modified', result.lastModifiedDate.toUTCString());
|
|
774
790
|
mres.setHeader(
|
|
775
791
|
'Content-Length',
|
|
@@ -830,7 +846,7 @@ class Server {
|
|
|
830
846
|
baseBytecodeBundle(entryFile, revision.prepend, revision.graph, {
|
|
831
847
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
832
848
|
this._config.transformer.asyncRequireModulePath,
|
|
833
|
-
{transformOptions},
|
|
849
|
+
{transformOptions, relativeTo: 'project'},
|
|
834
850
|
),
|
|
835
851
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
836
852
|
createModuleId: this._createModuleId,
|
|
@@ -838,9 +854,10 @@ class Server {
|
|
|
838
854
|
dev: transformOptions.dev,
|
|
839
855
|
projectRoot: this._config.projectRoot,
|
|
840
856
|
modulesOnly: serializerOptions.modulesOnly,
|
|
841
|
-
runBeforeMainModule:
|
|
842
|
-
|
|
843
|
-
|
|
857
|
+
runBeforeMainModule:
|
|
858
|
+
this._config.serializer.getModulesRunBeforeMainModule(
|
|
859
|
+
path.relative(this._config.projectRoot, entryFile),
|
|
860
|
+
),
|
|
844
861
|
runModule: serializerOptions.runModule,
|
|
845
862
|
sourceMapUrl: serializerOptions.sourceMapUrl,
|
|
846
863
|
sourceUrl: serializerOptions.sourceUrl,
|
|
@@ -989,16 +1006,15 @@ class Server {
|
|
|
989
1006
|
const getCodeFrame = (urls, symbolicatedStack) => {
|
|
990
1007
|
for (let i = 0; i < symbolicatedStack.length; i++) {
|
|
991
1008
|
const {collapse, column, file, lineNumber} = symbolicatedStack[i];
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
if (collapse || lineNumber == null || urls.has(entryPoint)) {
|
|
1009
|
+
const fileAbsolute = path.resolve(this._config.projectRoot, file ?? '');
|
|
1010
|
+
if (collapse || lineNumber == null || urls.has(fileAbsolute)) {
|
|
995
1011
|
continue;
|
|
996
1012
|
}
|
|
997
1013
|
|
|
998
1014
|
try {
|
|
999
1015
|
return {
|
|
1000
1016
|
content: codeFrameColumns(
|
|
1001
|
-
fs.readFileSync(
|
|
1017
|
+
fs.readFileSync(fileAbsolute, 'utf8'),
|
|
1002
1018
|
{
|
|
1003
1019
|
// Metro returns 0 based columns but codeFrameColumns expects 1-based columns
|
|
1004
1020
|
// $FlowFixMe[unsafe-addition]
|
|
@@ -1054,6 +1070,7 @@ class Server {
|
|
|
1054
1070
|
|
|
1055
1071
|
debug('Getting source maps for symbolication');
|
|
1056
1072
|
const sourceMaps = await Promise.all(
|
|
1073
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
1057
1074
|
Array.from(urls.values()).map(this._explodedSourceMapForURL, this),
|
|
1058
1075
|
);
|
|
1059
1076
|
|
|
@@ -1102,12 +1119,13 @@ class Server {
|
|
|
1102
1119
|
*/
|
|
1103
1120
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
1104
1121
|
transformOptions,
|
|
1122
|
+
relativeTo: 'server',
|
|
1105
1123
|
});
|
|
1106
1124
|
|
|
1107
1125
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
1108
1126
|
shallow: graphOptions.shallow,
|
|
1109
|
-
experimentalImportBundleSupport:
|
|
1110
|
-
.experimentalImportBundleSupport,
|
|
1127
|
+
experimentalImportBundleSupport:
|
|
1128
|
+
this._config.transformer.experimentalImportBundleSupport,
|
|
1111
1129
|
});
|
|
1112
1130
|
let revision;
|
|
1113
1131
|
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
@@ -1134,12 +1152,25 @@ class Server {
|
|
|
1134
1152
|
);
|
|
1135
1153
|
}
|
|
1136
1154
|
|
|
1137
|
-
async _resolveRelativePath(
|
|
1155
|
+
async _resolveRelativePath(
|
|
1156
|
+
filePath,
|
|
1157
|
+
{
|
|
1158
|
+
transformOptions,
|
|
1159
|
+
relativeTo,
|
|
1160
|
+
}: $ReadOnly<{
|
|
1161
|
+
transformOptions: TransformInputOptions,
|
|
1162
|
+
relativeTo: 'project' | 'server',
|
|
1163
|
+
}>,
|
|
1164
|
+
) {
|
|
1138
1165
|
const resolutionFn = await transformHelpers.getResolveDependencyFn(
|
|
1139
1166
|
this._bundler.getBundler(),
|
|
1140
1167
|
transformOptions.platform,
|
|
1141
1168
|
);
|
|
1142
|
-
|
|
1169
|
+
const rootDir =
|
|
1170
|
+
relativeTo === 'server'
|
|
1171
|
+
? this._getServerRootDir()
|
|
1172
|
+
: this._config.projectRoot;
|
|
1173
|
+
return resolutionFn(`${rootDir}/.`, filePath);
|
|
1143
1174
|
}
|
|
1144
1175
|
|
|
1145
1176
|
getNewBuildID(): string {
|
|
@@ -1191,6 +1222,19 @@ class Server {
|
|
|
1191
1222
|
sourceMapUrl: null,
|
|
1192
1223
|
sourceUrl: null,
|
|
1193
1224
|
};
|
|
1225
|
+
|
|
1226
|
+
_getServerRootDir() {
|
|
1227
|
+
return this._config.server.unstable_serverRoot ?? this._config.projectRoot;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
_getEntryPointAbsolutePath(entryFile: string) {
|
|
1231
|
+
return path.resolve(this._getServerRootDir(), entryFile);
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
// Wait for the server to finish initializing.
|
|
1235
|
+
async ready(): Promise<void> {
|
|
1236
|
+
await this._bundler.ready();
|
|
1237
|
+
}
|
|
1194
1238
|
}
|
|
1195
1239
|
|
|
1196
1240
|
function* zip<X, Y>(xs: Iterable<X>, ys: Iterable<Y>): Iterable<[X, Y]> {
|
package/src/cli-utils.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.
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
|
|
12
12
|
const fs = require("fs-extra");
|
|
13
13
|
|
|
14
|
-
exports.watchFile = async function(filename, callback) {
|
|
14
|
+
exports.watchFile = async function (filename, callback) {
|
|
15
15
|
fs.watchFile(filename, () => {
|
|
16
16
|
callback();
|
|
17
17
|
});
|
|
18
18
|
await callback();
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
exports.makeAsyncCommand = command => argv => {
|
|
22
|
-
Promise.resolve(command(argv)).catch(error => {
|
|
21
|
+
exports.makeAsyncCommand = (command) => (argv) => {
|
|
22
|
+
Promise.resolve(command(argv)).catch((error) => {
|
|
23
23
|
console.error(error.stack);
|
|
24
24
|
process.exitCode = 1;
|
|
25
25
|
});
|
package/src/cli-utils.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,13 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
const fs = require('fs-extra');
|
|
14
|
-
|
|
15
13
|
import type {YargArguments} from 'metro-config/src/configTypes.flow';
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
const fs = require('fs-extra');
|
|
16
|
+
|
|
17
|
+
exports.watchFile = async function (
|
|
18
18
|
filename: string,
|
|
19
|
-
callback: () =>
|
|
19
|
+
callback: () => any,
|
|
20
20
|
): Promise<void> {
|
|
21
21
|
fs.watchFile(filename, () => {
|
|
22
22
|
callback();
|
|
@@ -25,11 +25,13 @@ exports.watchFile = async function(
|
|
|
25
25
|
await callback();
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
exports.makeAsyncCommand =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
exports.makeAsyncCommand =
|
|
29
|
+
(
|
|
30
|
+
command: (argv: YargArguments) => Promise<mixed>,
|
|
31
|
+
): ((argv: YargArguments) => void) =>
|
|
32
|
+
(argv: YargArguments) => {
|
|
33
|
+
Promise.resolve(command(argv)).catch(error => {
|
|
34
|
+
console.error(error.stack);
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
});
|
|
37
|
+
};
|
package/src/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
5
|
*
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @format
|
|
11
11
|
*/
|
|
12
|
-
"use strict";
|
|
13
|
-
|
|
14
|
-
const yargs = require("yargs");
|
|
12
|
+
"use strict";
|
|
15
13
|
|
|
16
14
|
const { attachMetroCli } = require("./index");
|
|
17
15
|
|
|
16
|
+
const yargs = require("yargs");
|
|
17
|
+
|
|
18
18
|
attachMetroCli(yargs.demandCommand(1)).argv;
|
package/src/cli.js.flow
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -11,9 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
// flowlint-next-line untyped-import:off
|
|
15
|
-
const yargs = require('yargs');
|
|
16
|
-
|
|
17
14
|
const {attachMetroCli} = require('./index');
|
|
15
|
+
const yargs = require('yargs');
|
|
18
16
|
|
|
19
17
|
attachMetroCli(yargs.demandCommand(1)).argv;
|
package/src/commands/build.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,12 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
|
+
const { makeAsyncCommand } = require("../cli-utils");
|
|
13
|
+
|
|
12
14
|
const MetroApi = require("../index");
|
|
13
15
|
|
|
14
16
|
const TerminalReporter = require("../lib/TerminalReporter");
|
|
15
17
|
|
|
16
|
-
const { makeAsyncCommand } = require("../cli-utils");
|
|
17
|
-
|
|
18
18
|
const { loadConfig } = require("metro-config");
|
|
19
19
|
|
|
20
20
|
const { Terminal } = require("metro-core");
|
|
@@ -26,57 +26,56 @@ module.exports = () => ({
|
|
|
26
26
|
command: "build <entry>",
|
|
27
27
|
description:
|
|
28
28
|
"Generates a JavaScript bundle containing the specified entrypoint and its descendants",
|
|
29
|
-
|
|
30
|
-
builder: yargs => {
|
|
29
|
+
builder: (yargs) => {
|
|
31
30
|
yargs.option("project-roots", {
|
|
32
31
|
alias: "P",
|
|
33
32
|
type: "string",
|
|
34
|
-
array: true
|
|
33
|
+
array: true,
|
|
35
34
|
});
|
|
36
35
|
yargs.option("out", {
|
|
37
36
|
alias: "O",
|
|
38
37
|
type: "string",
|
|
39
|
-
demandOption: true
|
|
38
|
+
demandOption: true,
|
|
40
39
|
});
|
|
41
40
|
yargs.option("platform", {
|
|
42
41
|
alias: "p",
|
|
43
|
-
type: "string"
|
|
42
|
+
type: "string",
|
|
44
43
|
});
|
|
45
44
|
yargs.option("output-type", {
|
|
46
45
|
alias: "t",
|
|
47
|
-
type: "string"
|
|
46
|
+
type: "string",
|
|
48
47
|
});
|
|
49
48
|
yargs.option("max-workers", {
|
|
50
49
|
alias: "j",
|
|
51
|
-
type: "number"
|
|
50
|
+
type: "number",
|
|
52
51
|
});
|
|
53
52
|
yargs.option("minify", {
|
|
54
53
|
alias: "z",
|
|
55
|
-
type: "boolean"
|
|
54
|
+
type: "boolean",
|
|
56
55
|
});
|
|
57
56
|
yargs.option("dev", {
|
|
58
57
|
alias: "g",
|
|
59
|
-
type: "boolean"
|
|
58
|
+
type: "boolean",
|
|
60
59
|
});
|
|
61
60
|
yargs.option("source-map", {
|
|
62
|
-
type: "boolean"
|
|
61
|
+
type: "boolean",
|
|
63
62
|
});
|
|
64
63
|
yargs.option("source-map-url", {
|
|
65
|
-
type: "string"
|
|
64
|
+
type: "string",
|
|
66
65
|
});
|
|
67
66
|
yargs.option("legacy-bundler", {
|
|
68
|
-
type: "boolean"
|
|
67
|
+
type: "boolean",
|
|
69
68
|
});
|
|
70
69
|
yargs.option("config", {
|
|
71
70
|
alias: "c",
|
|
72
|
-
type: "string"
|
|
71
|
+
type: "string",
|
|
73
72
|
}); // Deprecated
|
|
74
73
|
|
|
75
74
|
yargs.option("reset-cache", {
|
|
76
|
-
type: "boolean"
|
|
75
|
+
type: "boolean",
|
|
77
76
|
});
|
|
78
77
|
},
|
|
79
|
-
handler: makeAsyncCommand(async argv => {
|
|
78
|
+
handler: makeAsyncCommand(async (argv) => {
|
|
80
79
|
const config = await loadConfig(argv); // $FlowExpectedError YargArguments and RunBuildOptions are used interchangeable but their types are not yet compatible
|
|
81
80
|
|
|
82
81
|
const options = argv;
|
|
@@ -94,8 +93,8 @@ module.exports = () => ({
|
|
|
94
93
|
platform: options.platform,
|
|
95
94
|
// Bytecode bundles in Metro are not meant for production use. Instead,
|
|
96
95
|
// the Hermes Bytecode Compiler should be invoked on the resulting JS bundle from Metro.
|
|
97
|
-
runtimeBytecodeVersion: null
|
|
98
|
-
}
|
|
96
|
+
runtimeBytecodeVersion: null,
|
|
97
|
+
},
|
|
99
98
|
});
|
|
100
99
|
},
|
|
101
100
|
onProgress: (transformedFileCount, totalFileCount) => {
|
|
@@ -103,15 +102,15 @@ module.exports = () => ({
|
|
|
103
102
|
buildID: "$",
|
|
104
103
|
type: "bundle_transform_progressed",
|
|
105
104
|
transformedFileCount,
|
|
106
|
-
totalFileCount
|
|
105
|
+
totalFileCount,
|
|
107
106
|
});
|
|
108
107
|
},
|
|
109
108
|
onComplete: () => {
|
|
110
109
|
updateReporter.update({
|
|
111
110
|
buildID: "$",
|
|
112
|
-
type: "bundle_build_done"
|
|
111
|
+
type: "bundle_build_done",
|
|
113
112
|
});
|
|
114
|
-
}
|
|
113
|
+
},
|
|
115
114
|
});
|
|
116
|
-
})
|
|
115
|
+
}),
|
|
117
116
|
});
|