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
|
@@ -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,29 +9,30 @@
|
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
|
+
const virtualModule = require("../module").virtual;
|
|
13
|
+
|
|
12
14
|
const generate = require("../worker/generate");
|
|
13
15
|
|
|
14
16
|
const mergeSourceMaps = require("../worker/mergeSourceMaps");
|
|
15
17
|
|
|
16
|
-
const nullthrows = require("nullthrows");
|
|
17
|
-
|
|
18
18
|
const reverseDependencyMapReferences = require("./reverse-dependency-map-references");
|
|
19
19
|
|
|
20
|
-
const {
|
|
20
|
+
const { parseSync, transformFromAstSync } = require("@babel/core");
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const HermesParser = require("hermes-parser"); // flowlint-next-line untyped-import:off
|
|
23
23
|
|
|
24
24
|
const { passthroughSyntaxPlugins } = require("metro-react-native-babel-preset");
|
|
25
25
|
|
|
26
|
-
const {
|
|
26
|
+
const { addParamsToDefineCall } = require("metro-transform-plugins");
|
|
27
27
|
|
|
28
|
-
// Transformed modules have the form
|
|
28
|
+
const nullthrows = require("nullthrows"); // Transformed modules have the form
|
|
29
29
|
// __d(function(require, module, global, exports, dependencyMap) {
|
|
30
30
|
// /* code */
|
|
31
31
|
// });
|
|
32
32
|
//
|
|
33
33
|
// This function adds the numeric module ID, and an array with dependencies of
|
|
34
34
|
// the dependencies of the module before the closing parenthesis.
|
|
35
|
+
|
|
35
36
|
function addModuleIdsToModuleWrapper(module, idForPath) {
|
|
36
37
|
const { dependencies, file } = module;
|
|
37
38
|
const { code } = file; // calling `idForPath` on the module itself first gives us a lower module id
|
|
@@ -50,14 +51,23 @@ function addModuleIdsToModuleWrapper(module, idForPath) {
|
|
|
50
51
|
|
|
51
52
|
exports.addModuleIdsToModuleWrapper = addModuleIdsToModuleWrapper;
|
|
52
53
|
|
|
54
|
+
// TS detection conditions copied from metro-react-native-babel-preset
|
|
55
|
+
function isTypeScriptSource(fileName) {
|
|
56
|
+
return !!fileName && fileName.endsWith(".ts");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isTSXSource(fileName) {
|
|
60
|
+
return !!fileName && fileName.endsWith(".tsx");
|
|
61
|
+
}
|
|
62
|
+
|
|
53
63
|
function inlineModuleIds(
|
|
54
64
|
module,
|
|
55
65
|
idForPath,
|
|
56
66
|
{
|
|
57
|
-
|
|
58
|
-
dependencyMapReservedName = undefined,
|
|
67
|
+
dependencyMapReservedName,
|
|
59
68
|
globalPrefix,
|
|
60
|
-
ignoreMissingDependencyMapReference = false
|
|
69
|
+
ignoreMissingDependencyMapReference = false,
|
|
70
|
+
hermesParser = false,
|
|
61
71
|
}
|
|
62
72
|
) {
|
|
63
73
|
const { dependencies, file } = module;
|
|
@@ -73,7 +83,7 @@ function inlineModuleIds(
|
|
|
73
83
|
return {
|
|
74
84
|
fileId,
|
|
75
85
|
moduleCode: code,
|
|
76
|
-
moduleMap: map
|
|
86
|
+
moduleMap: map,
|
|
77
87
|
};
|
|
78
88
|
}
|
|
79
89
|
|
|
@@ -108,7 +118,7 @@ function inlineModuleIds(
|
|
|
108
118
|
return {
|
|
109
119
|
fileId,
|
|
110
120
|
moduleCode: code,
|
|
111
|
-
moduleMap: map
|
|
121
|
+
moduleMap: map,
|
|
112
122
|
};
|
|
113
123
|
} // If we're here, the module was probably generated by some code that
|
|
114
124
|
// doesn't make the dependency map name externally configurable, or a
|
|
@@ -133,8 +143,9 @@ function inlineModuleIds(
|
|
|
133
143
|
if (idStr.length > match.length) {
|
|
134
144
|
// Stop the build rather than silently emit an incorrect source map.
|
|
135
145
|
throw new Error(
|
|
136
|
-
`Module ID doesn't fit in available space; add ${
|
|
137
|
-
|
|
146
|
+
`Module ID doesn't fit in available space; add ${
|
|
147
|
+
idStr.length - match.length
|
|
148
|
+
} more characters to 'dependencyMapReservedName'.`
|
|
138
149
|
);
|
|
139
150
|
}
|
|
140
151
|
|
|
@@ -144,33 +155,42 @@ function inlineModuleIds(
|
|
|
144
155
|
return {
|
|
145
156
|
fileId,
|
|
146
157
|
moduleCode: inlinedCode,
|
|
147
|
-
moduleMap: map
|
|
158
|
+
moduleMap: map,
|
|
148
159
|
};
|
|
149
160
|
}
|
|
150
161
|
|
|
162
|
+
const babelConfig = {
|
|
163
|
+
ast: true,
|
|
164
|
+
babelrc: false,
|
|
165
|
+
browserslistConfigFile: false,
|
|
166
|
+
code: false,
|
|
167
|
+
configFile: false,
|
|
168
|
+
plugins: [
|
|
169
|
+
...passthroughSyntaxPlugins,
|
|
170
|
+
[
|
|
171
|
+
reverseDependencyMapReferences,
|
|
172
|
+
{
|
|
173
|
+
dependencyIds,
|
|
174
|
+
globalPrefix,
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
const sourceAst =
|
|
180
|
+
isTypeScriptSource(path) || isTSXSource(path) || !hermesParser
|
|
181
|
+
? parseSync(code, babelConfig)
|
|
182
|
+
: HermesParser.parse(code, {
|
|
183
|
+
babel: true,
|
|
184
|
+
sourceType: babelConfig.sourceType,
|
|
185
|
+
});
|
|
151
186
|
const ast = nullthrows(
|
|
152
|
-
|
|
153
|
-
ast: true,
|
|
154
|
-
babelrc: false,
|
|
155
|
-
code: false,
|
|
156
|
-
configFile: false,
|
|
157
|
-
plugins: [
|
|
158
|
-
...passthroughSyntaxPlugins,
|
|
159
|
-
[
|
|
160
|
-
reverseDependencyMapReferences,
|
|
161
|
-
{
|
|
162
|
-
dependencyIds,
|
|
163
|
-
globalPrefix
|
|
164
|
-
}
|
|
165
|
-
]
|
|
166
|
-
]
|
|
167
|
-
}).ast
|
|
187
|
+
transformFromAstSync(sourceAst, code, babelConfig).ast
|
|
168
188
|
);
|
|
169
189
|
const { code: generatedCode, map: generatedMap } = generate(ast, path, "");
|
|
170
190
|
return {
|
|
171
191
|
fileId,
|
|
172
192
|
moduleCode: generatedCode,
|
|
173
|
-
moduleMap: map && generatedMap && mergeSourceMaps(path, map, generatedMap)
|
|
193
|
+
moduleMap: map && generatedMap && mergeSourceMaps(path, map, generatedMap),
|
|
174
194
|
};
|
|
175
195
|
}
|
|
176
196
|
|
|
@@ -182,12 +202,13 @@ function inlineModuleIdsAndAddParamsToDefineCall(module, idForPath, options) {
|
|
|
182
202
|
);
|
|
183
203
|
return {
|
|
184
204
|
moduleCode: addParamsToDefineCall(moduleCode, fileId),
|
|
185
|
-
moduleMap
|
|
205
|
+
moduleMap,
|
|
186
206
|
};
|
|
187
207
|
}
|
|
188
208
|
|
|
189
209
|
exports.inlineModuleIds = inlineModuleIds;
|
|
190
|
-
exports.inlineModuleIdsAndAddParamsToDefineCall =
|
|
210
|
+
exports.inlineModuleIdsAndAddParamsToDefineCall =
|
|
211
|
+
inlineModuleIdsAndAddParamsToDefineCall;
|
|
191
212
|
|
|
192
213
|
function escapeRegex(str) {
|
|
193
214
|
// From http://stackoverflow.com/questions/14076210/
|
|
@@ -215,7 +236,7 @@ function getModuleCodeAndMap(module, idForPath, options) {
|
|
|
215
236
|
idForPath,
|
|
216
237
|
{
|
|
217
238
|
dependencyMapReservedName: options.dependencyMapReservedName,
|
|
218
|
-
globalPrefix: options.globalPrefix
|
|
239
|
+
globalPrefix: options.globalPrefix,
|
|
219
240
|
}
|
|
220
241
|
));
|
|
221
242
|
}
|
|
@@ -232,7 +253,7 @@ function getModuleCodeAndMap(module, idForPath, options) {
|
|
|
232
253
|
|
|
233
254
|
return {
|
|
234
255
|
moduleCode,
|
|
235
|
-
moduleMap
|
|
256
|
+
moduleMap,
|
|
236
257
|
};
|
|
237
258
|
}
|
|
238
259
|
|
|
@@ -261,7 +282,7 @@ exports.createIdForPathFn = () => {
|
|
|
261
282
|
}; // creates a series of virtual modules with require calls to the passed-in
|
|
262
283
|
// modules.
|
|
263
284
|
|
|
264
|
-
exports.requireCallsTo = function*(modules, idForPath, getRunModuleStatement) {
|
|
285
|
+
exports.requireCallsTo = function* (modules, idForPath, getRunModuleStatement) {
|
|
265
286
|
for (const module of modules) {
|
|
266
287
|
const id = idForPath(module.file);
|
|
267
288
|
yield virtualModule(
|
|
@@ -293,11 +314,11 @@ function toModuleTransport(
|
|
|
293
314
|
const { dependencies, file } = module;
|
|
294
315
|
const { moduleCode, moduleMap } = getModuleCodeAndMap(
|
|
295
316
|
module,
|
|
296
|
-
x => idsForPath(x).moduleId,
|
|
317
|
+
(x) => idsForPath(x).moduleId,
|
|
297
318
|
{
|
|
298
319
|
dependencyMapReservedName,
|
|
299
320
|
enableIDInlining: true,
|
|
300
|
-
globalPrefix
|
|
321
|
+
globalPrefix,
|
|
301
322
|
}
|
|
302
323
|
);
|
|
303
324
|
return {
|
|
@@ -307,7 +328,7 @@ function toModuleTransport(
|
|
|
307
328
|
id: file.type === "module" ? nullthrows(idsForPath(file).localId) : -1,
|
|
308
329
|
map: moduleMap,
|
|
309
330
|
name: file.path,
|
|
310
|
-
sourcePath: file.path
|
|
331
|
+
sourcePath: file.path,
|
|
311
332
|
};
|
|
312
333
|
}
|
|
313
334
|
|
|
@@ -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,20 +10,19 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
import type {Dependency, IdsForPathFn, Module} from '../types.flow';
|
|
14
|
+
import type {BasicSourceMap} from 'metro-source-map';
|
|
15
|
+
|
|
16
|
+
const virtualModule = require('../module').virtual;
|
|
13
17
|
const generate = require('../worker/generate');
|
|
14
18
|
const mergeSourceMaps = require('../worker/mergeSourceMaps');
|
|
15
|
-
const nullthrows = require('nullthrows');
|
|
16
19
|
const reverseDependencyMapReferences = require('./reverse-dependency-map-references');
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const virtualModule = require('../module').virtual;
|
|
20
|
-
|
|
20
|
+
const {parseSync, transformFromAstSync} = require('@babel/core');
|
|
21
|
+
const HermesParser = require('hermes-parser');
|
|
21
22
|
// flowlint-next-line untyped-import:off
|
|
22
23
|
const {passthroughSyntaxPlugins} = require('metro-react-native-babel-preset');
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
import type {Dependency, IdsForPathFn, Module} from '../types.flow';
|
|
26
|
-
import type {BasicSourceMap} from 'metro-source-map';
|
|
24
|
+
const {addParamsToDefineCall} = require('metro-transform-plugins');
|
|
25
|
+
const nullthrows = require('nullthrows');
|
|
27
26
|
|
|
28
27
|
// Transformed modules have the form
|
|
29
28
|
// __d(function(require, module, global, exports, dependencyMap) {
|
|
@@ -55,20 +54,30 @@ function addModuleIdsToModuleWrapper(
|
|
|
55
54
|
|
|
56
55
|
exports.addModuleIdsToModuleWrapper = addModuleIdsToModuleWrapper;
|
|
57
56
|
|
|
58
|
-
type InlineModuleIdsOptions = {
|
|
57
|
+
type InlineModuleIdsOptions = $ReadOnly<{
|
|
59
58
|
dependencyMapReservedName: ?string,
|
|
60
59
|
globalPrefix: string,
|
|
61
60
|
ignoreMissingDependencyMapReference?: boolean,
|
|
62
|
-
|
|
61
|
+
hermesParser?: boolean,
|
|
62
|
+
}>;
|
|
63
|
+
|
|
64
|
+
// TS detection conditions copied from metro-react-native-babel-preset
|
|
65
|
+
function isTypeScriptSource(fileName) {
|
|
66
|
+
return !!fileName && fileName.endsWith('.ts');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isTSXSource(fileName) {
|
|
70
|
+
return !!fileName && fileName.endsWith('.tsx');
|
|
71
|
+
}
|
|
63
72
|
|
|
64
73
|
function inlineModuleIds(
|
|
65
74
|
module: Module,
|
|
66
75
|
idForPath: ({path: string, ...}) => number,
|
|
67
76
|
{
|
|
68
|
-
|
|
69
|
-
dependencyMapReservedName = undefined,
|
|
77
|
+
dependencyMapReservedName,
|
|
70
78
|
globalPrefix,
|
|
71
79
|
ignoreMissingDependencyMapReference = false,
|
|
80
|
+
hermesParser = false,
|
|
72
81
|
}: InlineModuleIdsOptions,
|
|
73
82
|
): {
|
|
74
83
|
moduleCode: string,
|
|
@@ -140,8 +149,9 @@ function inlineModuleIds(
|
|
|
140
149
|
if (idStr.length > match.length) {
|
|
141
150
|
// Stop the build rather than silently emit an incorrect source map.
|
|
142
151
|
throw new Error(
|
|
143
|
-
`Module ID doesn't fit in available space; add ${
|
|
144
|
-
|
|
152
|
+
`Module ID doesn't fit in available space; add ${
|
|
153
|
+
idStr.length - match.length
|
|
154
|
+
} more characters to 'dependencyMapReservedName'.`,
|
|
145
155
|
);
|
|
146
156
|
}
|
|
147
157
|
return idStr.padEnd(match.length);
|
|
@@ -153,17 +163,29 @@ function inlineModuleIds(
|
|
|
153
163
|
moduleMap: map,
|
|
154
164
|
};
|
|
155
165
|
}
|
|
166
|
+
|
|
167
|
+
const babelConfig = {
|
|
168
|
+
ast: true,
|
|
169
|
+
babelrc: false,
|
|
170
|
+
browserslistConfigFile: false,
|
|
171
|
+
code: false,
|
|
172
|
+
configFile: false,
|
|
173
|
+
plugins: [
|
|
174
|
+
...passthroughSyntaxPlugins,
|
|
175
|
+
[reverseDependencyMapReferences, {dependencyIds, globalPrefix}],
|
|
176
|
+
],
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const sourceAst =
|
|
180
|
+
isTypeScriptSource(path) || isTSXSource(path) || !hermesParser
|
|
181
|
+
? parseSync(code, babelConfig)
|
|
182
|
+
: HermesParser.parse(code, {
|
|
183
|
+
babel: true,
|
|
184
|
+
sourceType: babelConfig.sourceType,
|
|
185
|
+
});
|
|
186
|
+
|
|
156
187
|
const ast = nullthrows(
|
|
157
|
-
|
|
158
|
-
ast: true,
|
|
159
|
-
babelrc: false,
|
|
160
|
-
code: false,
|
|
161
|
-
configFile: false,
|
|
162
|
-
plugins: [
|
|
163
|
-
...passthroughSyntaxPlugins,
|
|
164
|
-
[reverseDependencyMapReferences, {dependencyIds, globalPrefix}],
|
|
165
|
-
],
|
|
166
|
-
}).ast,
|
|
188
|
+
transformFromAstSync(sourceAst, code, babelConfig).ast,
|
|
167
189
|
);
|
|
168
190
|
|
|
169
191
|
const {code: generatedCode, map: generatedMap} = generate(ast, path, '');
|
|
@@ -193,7 +215,8 @@ function inlineModuleIdsAndAddParamsToDefineCall(
|
|
|
193
215
|
}
|
|
194
216
|
|
|
195
217
|
exports.inlineModuleIds = inlineModuleIds;
|
|
196
|
-
exports.inlineModuleIdsAndAddParamsToDefineCall =
|
|
218
|
+
exports.inlineModuleIdsAndAddParamsToDefineCall =
|
|
219
|
+
inlineModuleIdsAndAddParamsToDefineCall;
|
|
197
220
|
|
|
198
221
|
function escapeRegex(str: string): string {
|
|
199
222
|
// From http://stackoverflow.com/questions/14076210/
|
|
@@ -276,7 +299,7 @@ exports.createIdForPathFn = (): (({path: string, ...}) => number) => {
|
|
|
276
299
|
|
|
277
300
|
// creates a series of virtual modules with require calls to the passed-in
|
|
278
301
|
// modules.
|
|
279
|
-
exports.requireCallsTo = function*(
|
|
302
|
+
exports.requireCallsTo = function* (
|
|
280
303
|
modules: Iterable<Module>,
|
|
281
304
|
idForPath: IdForPathFn,
|
|
282
305
|
getRunModuleStatement: (id: number | string) => string,
|
|
@@ -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.
|
|
@@ -21,6 +21,6 @@ const write = (_, __, callback) => callback();
|
|
|
21
21
|
module.exports = new Console(
|
|
22
22
|
new Writable({
|
|
23
23
|
write,
|
|
24
|
-
writev: write
|
|
24
|
+
writev: write,
|
|
25
25
|
})
|
|
26
26
|
);
|
|
@@ -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.
|
|
@@ -14,19 +14,19 @@ const { toMatchSnapshot } = require("jest-snapshot");
|
|
|
14
14
|
|
|
15
15
|
const generateOptions = {
|
|
16
16
|
concise: true,
|
|
17
|
-
sourceType: "module"
|
|
17
|
+
sourceType: "module",
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const codeFromAst = ast => generate(ast, generateOptions).code;
|
|
20
|
+
const codeFromAst = (ast) => generate(ast, generateOptions).code;
|
|
21
21
|
|
|
22
|
-
const comparableCode = code => code.trim().replace(/\s+/g, " ");
|
|
22
|
+
const comparableCode = (code) => code.trim().replace(/\s+/g, " ");
|
|
23
23
|
|
|
24
24
|
function toEqualComparableCode(received, expected) {
|
|
25
25
|
const comparableExpected = comparableCode(expected);
|
|
26
26
|
const pass = received === comparableExpected;
|
|
27
27
|
const options = {
|
|
28
28
|
isNot: this.isNot,
|
|
29
|
-
promise: this.promise
|
|
29
|
+
promise: this.promise,
|
|
30
30
|
};
|
|
31
31
|
const message = pass
|
|
32
32
|
? () =>
|
|
@@ -61,7 +61,7 @@ function toEqualComparableCode(received, expected) {
|
|
|
61
61
|
return {
|
|
62
62
|
actual: received,
|
|
63
63
|
message,
|
|
64
|
-
pass
|
|
64
|
+
pass,
|
|
65
65
|
};
|
|
66
66
|
} // See https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream
|
|
67
67
|
|
|
@@ -87,5 +87,5 @@ module.exports = {
|
|
|
87
87
|
codeFromAst,
|
|
88
88
|
comparableCode,
|
|
89
89
|
toEqualComparableCode,
|
|
90
|
-
toMatchCodeFrameSnapshot
|
|
90
|
+
toMatchCodeFrameSnapshot,
|
|
91
91
|
};
|
|
@@ -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,9 +11,9 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
import type {
|
|
14
|
-
MixedSourceMap,
|
|
15
|
-
FBSourceFunctionMap,
|
|
16
14
|
BasicSourceMap,
|
|
15
|
+
FBSourceFunctionMap,
|
|
16
|
+
MixedSourceMap,
|
|
17
17
|
} from 'metro-source-map';
|
|
18
18
|
import type {TransformResultDependency} from 'metro/src/DeltaBundler';
|
|
19
19
|
|
|
@@ -98,7 +98,7 @@ export type PostProcessModules = (
|
|
|
98
98
|
) => $ReadOnlyArray<Module>;
|
|
99
99
|
|
|
100
100
|
export type OutputFnArg = {|
|
|
101
|
-
dependencyMapReservedName?: string,
|
|
101
|
+
dependencyMapReservedName?: ?string,
|
|
102
102
|
filename: string,
|
|
103
103
|
globalPrefix: string,
|
|
104
104
|
idsForPath: IdsForPathFn,
|
|
@@ -108,9 +108,8 @@ export type OutputFnArg = {|
|
|
|
108
108
|
enableIDInlining: boolean,
|
|
109
109
|
segmentID: number,
|
|
110
110
|
|};
|
|
111
|
-
export type OutputFn<
|
|
112
|
-
|
|
113
|
-
> = OutputFnArg => OutputResult<M>;
|
|
111
|
+
export type OutputFn<M: MixedSourceMap = MixedSourceMap> =
|
|
112
|
+
OutputFnArg => OutputResult<M>;
|
|
114
113
|
|
|
115
114
|
export type OutputResult<M: MixedSourceMap> = {|
|
|
116
115
|
code: string | Buffer,
|
|
@@ -138,12 +137,15 @@ export type ConcreteTransformResult = {
|
|
|
138
137
|
type: 'concrete',
|
|
139
138
|
code: string,
|
|
140
139
|
dependencies: $ReadOnlyArray<TransformResultDependency>,
|
|
141
|
-
dependencyMapName?: string,
|
|
142
140
|
map: ?BasicSourceMap,
|
|
143
|
-
requireName: string,
|
|
144
141
|
soundResources?: ?Array<string>,
|
|
142
|
+
|
|
143
|
+
// NOTE: requireName, importNames and dependencyMapName are only used by the
|
|
144
|
+
// optimizer. They are deleted when the transform result is serialized to
|
|
145
|
+
// JSON.
|
|
146
|
+
dependencyMapName?: string,
|
|
147
|
+
requireName?: string,
|
|
145
148
|
importNames?: ImportNames,
|
|
146
|
-
isESModule?: true,
|
|
147
149
|
};
|
|
148
150
|
|
|
149
151
|
export type LinkedTransformResult = $ReadOnly<{
|
|
@@ -161,56 +163,69 @@ export type TransformedCodeFile = {|
|
|
|
161
163
|
+file: string,
|
|
162
164
|
+functionMap: ?FBSourceFunctionMap,
|
|
163
165
|
+hasteID: ?string,
|
|
164
|
-
package?: PackageData,
|
|
166
|
+
+package?: PackageData,
|
|
165
167
|
+transformed: TransformResults,
|
|
166
168
|
+type: CodeFileTypes,
|
|
167
169
|
|};
|
|
168
170
|
|
|
169
171
|
export type ImageSize = {|+width: number, +height: number|};
|
|
170
172
|
|
|
171
|
-
export type
|
|
172
|
-
/**
|
|
173
|
-
* The path of the asset that is shared by all potential variants
|
|
174
|
-
* of this asset. For example `foo/bar@3x.png` would have the
|
|
175
|
-
* asset path `foo/bar.png`.
|
|
176
|
-
*/
|
|
177
|
-
+assetPath: string,
|
|
173
|
+
export type AssetFileVariant = $ReadOnly<{
|
|
178
174
|
/**
|
|
179
175
|
* The content is encoded in Base64 so that it can be stored in JSON files,
|
|
180
176
|
* that are used to communicate between different commands of a Buck
|
|
181
177
|
* build worker, for example.
|
|
182
178
|
*/
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Guessed from the file extension, for example `png` or `html`.
|
|
186
|
-
*/
|
|
187
|
-
+contentType: string,
|
|
179
|
+
contentBase64: string,
|
|
188
180
|
/**
|
|
189
181
|
* Hash of the asset file content.
|
|
190
182
|
*/
|
|
191
|
-
|
|
183
|
+
hash: string,
|
|
192
184
|
/**
|
|
193
185
|
* The path of the original file for this asset. For example
|
|
194
186
|
* `foo/bar@3x.ios.png`. This is most useful for reporting purposes, such as
|
|
195
187
|
* error messages.
|
|
196
188
|
*/
|
|
197
|
-
|
|
189
|
+
filePath: string,
|
|
198
190
|
/**
|
|
199
191
|
* If the asset is an image, this contain the size in physical pixels (ie.
|
|
200
|
-
*
|
|
192
|
+
* scale * logical pixels).
|
|
201
193
|
*/
|
|
202
|
-
|
|
194
|
+
physicalSize: ?ImageSize,
|
|
203
195
|
/**
|
|
204
196
|
* The platform this asset is designed for, for example `ios` if the file name
|
|
205
197
|
* is `foo.ios.js`. `null` if the asset is not platform-specific.
|
|
206
198
|
*/
|
|
207
|
-
|
|
199
|
+
platform: ?string,
|
|
208
200
|
/**
|
|
209
201
|
* The scale this asset is designed for, for example `2`
|
|
210
202
|
* if the file name is `foo@2x.png`.
|
|
211
203
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
204
|
+
scale: number,
|
|
205
|
+
}>;
|
|
206
|
+
|
|
207
|
+
// A *virtual* asset file ( = one generated JS module in the bundle)
|
|
208
|
+
// representing one or more asset variants ( = physical input files).
|
|
209
|
+
export type AssetFile = $ReadOnly<{
|
|
210
|
+
/**
|
|
211
|
+
* The path of the asset that is shared by all potential variants
|
|
212
|
+
* of this asset. For example `foo/bar@3x.png` would have the
|
|
213
|
+
* asset path `foo/bar.png`.
|
|
214
|
+
*/
|
|
215
|
+
assetPath: string,
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Guessed from the file extension, for example `png` or `html`.
|
|
219
|
+
*/
|
|
220
|
+
contentType: string,
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The source files for this asset.
|
|
224
|
+
* TODO(moti): Guarantee that an AssetFile has *all* the source files for a
|
|
225
|
+
* given asset.
|
|
226
|
+
*/
|
|
227
|
+
variants: $ReadOnlyArray<AssetFileVariant>,
|
|
228
|
+
}>;
|
|
214
229
|
|
|
215
230
|
export type TransformedSourceFile =
|
|
216
231
|
| {|
|
|
@@ -240,7 +255,7 @@ export type AssetContents = {
|
|
|
240
255
|
};
|
|
241
256
|
export type AssetContentsByPath = {
|
|
242
257
|
+[moduleFilePath: string]: $ReadOnlyArray<AssetContents>,
|
|
243
|
-
|
|
258
|
+
...
|
|
244
259
|
};
|
|
245
260
|
|
|
246
261
|
export type ResolvedCodeFile = {|
|
|
@@ -282,4 +297,5 @@ export type ResolvedLibrary = {|
|
|
|
282
297
|
+files: $ReadOnlyArray<ResolvedCodeFile>,
|
|
283
298
|
/* cannot be a Map because it's JSONified later on */
|
|
284
299
|
+assets: AssetContentsByPath,
|
|
300
|
+
+isPartiallyResolved?: boolean,
|
|
285
301
|
|};
|
|
@@ -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.
|
|
@@ -17,23 +17,23 @@ var t = _interopRequireWildcard(require("@babel/types"));
|
|
|
17
17
|
|
|
18
18
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
19
19
|
|
|
20
|
-
function _getRequireWildcardCache() {
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
21
21
|
if (typeof WeakMap !== "function") return null;
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
var cacheBabelInterop = new WeakMap();
|
|
23
|
+
var cacheNodeInterop = new WeakMap();
|
|
24
|
+
return (_getRequireWildcardCache = function (nodeInterop) {
|
|
25
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
26
|
+
})(nodeInterop);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function _interopRequireWildcard(obj) {
|
|
30
|
-
if (obj && obj.__esModule) {
|
|
29
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
30
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
31
31
|
return obj;
|
|
32
32
|
}
|
|
33
33
|
if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) {
|
|
34
34
|
return { default: obj };
|
|
35
35
|
}
|
|
36
|
-
var cache = _getRequireWildcardCache();
|
|
36
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
37
37
|
if (cache && cache.has(obj)) {
|
|
38
38
|
return cache.get(obj);
|
|
39
39
|
}
|
|
@@ -41,7 +41,7 @@ function _interopRequireWildcard(obj) {
|
|
|
41
41
|
var hasPropertyDescriptor =
|
|
42
42
|
Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
43
|
for (var key in obj) {
|
|
44
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
44
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
45
45
|
var desc = hasPropertyDescriptor
|
|
46
46
|
? Object.getOwnPropertyDescriptor(obj, key)
|
|
47
47
|
: null;
|
|
@@ -90,7 +90,7 @@ function wrapModule(
|
|
|
90
90
|
const requireName = renameRequires(ast);
|
|
91
91
|
return {
|
|
92
92
|
ast,
|
|
93
|
-
requireName
|
|
93
|
+
requireName,
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -114,7 +114,7 @@ function wrapJson(source, globalPrefix) {
|
|
|
114
114
|
return [
|
|
115
115
|
`${globalPrefix}__d(function(${moduleFactoryParameters.join(", ")}) {`,
|
|
116
116
|
` ${jsonToCommonJS(source)}`,
|
|
117
|
-
"});"
|
|
117
|
+
"});",
|
|
118
118
|
].join("\n");
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -138,7 +138,7 @@ function buildParameters(importDefaultName, importAllName, dependencyMapName) {
|
|
|
138
138
|
importAllName,
|
|
139
139
|
"module",
|
|
140
140
|
"exports",
|
|
141
|
-
dependencyMapName
|
|
141
|
+
dependencyMapName,
|
|
142
142
|
];
|
|
143
143
|
} // Renaming requires should ideally only be done when generating for the target
|
|
144
144
|
// that expects the custom require name in the optimize step.
|
|
@@ -157,7 +157,7 @@ function renameRequires(ast) {
|
|
|
157
157
|
);
|
|
158
158
|
newRequireName = body.scope.generateUid(WRAP_NAME);
|
|
159
159
|
body.scope.rename("require", newRequireName);
|
|
160
|
-
}
|
|
160
|
+
},
|
|
161
161
|
});
|
|
162
162
|
return newRequireName;
|
|
163
163
|
}
|
|
@@ -167,5 +167,5 @@ module.exports = {
|
|
|
167
167
|
wrapJson,
|
|
168
168
|
jsonToCommonJS,
|
|
169
169
|
wrapModule,
|
|
170
|
-
wrapPolyfill
|
|
170
|
+
wrapPolyfill,
|
|
171
171
|
};
|