@granite-js/mpack 0.0.0-dev-20250725013859
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/LICENSE +202 -0
- package/README.md +24 -0
- package/dist/bundler/Bundler.d.ts +24 -0
- package/dist/bundler/Bundler.js +180 -0
- package/dist/bundler/PluginDriver.d.ts +9 -0
- package/dist/bundler/PluginDriver.js +47 -0
- package/dist/bundler/index.d.ts +1 -0
- package/dist/bundler/index.js +22 -0
- package/dist/bundler/internal/presets.d.ts +18 -0
- package/dist/bundler/internal/presets.js +103 -0
- package/dist/bundler/plugins/buildStatusPlugin/buildStatusPlugin.d.ts +12 -0
- package/dist/bundler/plugins/buildStatusPlugin/buildStatusPlugin.js +74 -0
- package/dist/bundler/plugins/buildStatusPlugin/index.d.ts +1 -0
- package/dist/bundler/plugins/buildStatusPlugin/index.js +28 -0
- package/dist/bundler/plugins/dependencyAliasPlugin/aliasResolver.d.ts +3 -0
- package/dist/bundler/plugins/dependencyAliasPlugin/aliasResolver.js +89 -0
- package/dist/bundler/plugins/dependencyAliasPlugin/dependencyAliasPlugin.d.ts +3 -0
- package/dist/bundler/plugins/dependencyAliasPlugin/dependencyAliasPlugin.js +43 -0
- package/dist/bundler/plugins/dependencyAliasPlugin/index.d.ts +1 -0
- package/dist/bundler/plugins/dependencyAliasPlugin/index.js +28 -0
- package/dist/bundler/plugins/dependencyAliasPlugin/protocolResolver.d.ts +3 -0
- package/dist/bundler/plugins/dependencyAliasPlugin/protocolResolver.js +53 -0
- package/dist/bundler/plugins/index.d.ts +4 -0
- package/dist/bundler/plugins/index.js +28 -0
- package/dist/bundler/plugins/requireContextPlugin/index.d.ts +1 -0
- package/dist/bundler/plugins/requireContextPlugin/index.js +28 -0
- package/dist/bundler/plugins/requireContextPlugin/requireContextPlugin.d.ts +6 -0
- package/dist/bundler/plugins/requireContextPlugin/requireContextPlugin.js +101 -0
- package/dist/bundler/plugins/requireContextPlugin/scripts.d.ts +56 -0
- package/dist/bundler/plugins/requireContextPlugin/scripts.js +65 -0
- package/dist/bundler/plugins/shared/swc.d.ts +11 -0
- package/dist/bundler/plugins/shared/swc.js +70 -0
- package/dist/bundler/plugins/transformPlugin/helpers/preludeScript.d.ts +23 -0
- package/dist/bundler/plugins/transformPlugin/helpers/preludeScript.js +79 -0
- package/dist/bundler/plugins/transformPlugin/index.d.ts +1 -0
- package/dist/bundler/plugins/transformPlugin/index.js +28 -0
- package/dist/bundler/plugins/transformPlugin/steps/createCacheSteps.d.ts +10 -0
- package/dist/bundler/plugins/transformPlugin/steps/createCacheSteps.js +56 -0
- package/dist/bundler/plugins/transformPlugin/steps/createFullyTransformStep.d.ts +8 -0
- package/dist/bundler/plugins/transformPlugin/steps/createFullyTransformStep.js +120 -0
- package/dist/bundler/plugins/transformPlugin/steps/createStripFlowStep.d.ts +6 -0
- package/dist/bundler/plugins/transformPlugin/steps/createStripFlowStep.js +91 -0
- package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.d.ts +8 -0
- package/dist/bundler/plugins/transformPlugin/steps/createTransformToHermesSyntaxStep.js +100 -0
- package/dist/bundler/plugins/transformPlugin/transformPlugin.d.ts +8 -0
- package/dist/bundler/plugins/transformPlugin/transformPlugin.js +88 -0
- package/dist/bundler/plugins/types.d.ts +7 -0
- package/dist/bundler/plugins/types.js +16 -0
- package/dist/bundler/types.d.ts +16 -0
- package/dist/bundler/types.js +16 -0
- package/dist/cache/Cache.d.ts +25 -0
- package/dist/cache/Cache.js +87 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cache/index.js +22 -0
- package/dist/constants/index.d.ts +20 -0
- package/dist/constants/index.js +91 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +56 -0
- package/dist/logger/Logger.d.ts +17 -0
- package/dist/logger/Logger.js +115 -0
- package/dist/logger/clientLogger.d.ts +2 -0
- package/dist/logger/clientLogger.js +49 -0
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.js +31 -0
- package/dist/metro/assetRegistry.d.ts +12 -0
- package/dist/metro/assetRegistry.js +57 -0
- package/dist/metro/enhancedResolver.d.ts +7 -0
- package/dist/metro/enhancedResolver.js +127 -0
- package/dist/metro/getMetroConfig.d.ts +27 -0
- package/dist/metro/getMetroConfig.js +137 -0
- package/dist/metro/getMonorepoRoot.d.ts +4 -0
- package/dist/metro/getMonorepoRoot.js +80 -0
- package/dist/metro/index.d.ts +3 -0
- package/dist/metro/index.js +24 -0
- package/dist/metro/pnpapi.d.ts +6 -0
- package/dist/metro/pnpapi.js +32 -0
- package/dist/metro/runBuild.d.ts +10 -0
- package/dist/metro/runBuild.js +57 -0
- package/dist/metro/types.d.ts +92 -0
- package/dist/metro/types.js +16 -0
- package/dist/operations/constants.d.ts +3 -0
- package/dist/operations/constants.js +34 -0
- package/dist/operations/createDebuggerMiddleware.d.ts +11 -0
- package/dist/operations/createDebuggerMiddleware.js +128 -0
- package/dist/operations/experimental/StartMenuHandler.d.ts +13 -0
- package/dist/operations/experimental/StartMenuHandler.js +86 -0
- package/dist/operations/experimental/runServer.d.ts +13 -0
- package/dist/operations/experimental/runServer.js +130 -0
- package/dist/operations/index.d.ts +3 -0
- package/dist/operations/index.js +26 -0
- package/dist/operations/openDebugger.d.ts +1 -0
- package/dist/operations/openDebugger.js +73 -0
- package/dist/operations/runBundle.d.ts +6 -0
- package/dist/operations/runBundle.js +60 -0
- package/dist/operations/runServer.d.ts +13 -0
- package/dist/operations/runServer.js +131 -0
- package/dist/performance/Performance.d.ts +23 -0
- package/dist/performance/Performance.js +121 -0
- package/dist/performance/index.d.ts +2 -0
- package/dist/performance/index.js +31 -0
- package/dist/performance/printSummary.d.ts +5 -0
- package/dist/performance/printSummary.js +58 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +22 -0
- package/dist/plugins/statusPlugin.d.ts +2 -0
- package/dist/plugins/statusPlugin.js +64 -0
- package/dist/server/DevServer.d.ts +26 -0
- package/dist/server/DevServer.js +215 -0
- package/dist/server/constants.d.ts +1 -0
- package/dist/server/constants.js +28 -0
- package/dist/server/debugger/DebuggerEventHandler.d.ts +41 -0
- package/dist/server/debugger/DebuggerEventHandler.js +169 -0
- package/dist/server/debugger/parseDomain.d.ts +1 -0
- package/dist/server/debugger/parseDomain.js +30 -0
- package/dist/server/helpers/createBundlerForDevServer.d.ts +8 -0
- package/dist/server/helpers/createBundlerForDevServer.js +48 -0
- package/dist/server/helpers/mergeBundles.d.ts +7 -0
- package/dist/server/helpers/mergeBundles.js +129 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +22 -0
- package/dist/server/middlewares/createLiveReloadMiddleware.d.ts +10 -0
- package/dist/server/middlewares/createLiveReloadMiddleware.js +129 -0
- package/dist/server/middlewares/index.d.ts +1 -0
- package/dist/server/middlewares/index.js +22 -0
- package/dist/server/plugins/debuggerPlugin.d.ts +7 -0
- package/dist/server/plugins/debuggerPlugin.js +68 -0
- package/dist/server/plugins/index.d.ts +5 -0
- package/dist/server/plugins/index.js +30 -0
- package/dist/server/plugins/indexPagePlugin.d.ts +4 -0
- package/dist/server/plugins/indexPagePlugin.js +52 -0
- package/dist/server/plugins/reply.d.ts +3 -0
- package/dist/server/plugins/reply.js +38 -0
- package/dist/server/plugins/serveBundlePlugin.d.ts +8 -0
- package/dist/server/plugins/serveBundlePlugin.js +118 -0
- package/dist/server/plugins/statusPlugin.d.ts +7 -0
- package/dist/server/plugins/statusPlugin.js +50 -0
- package/dist/server/plugins/symbolicatePlugin/index.d.ts +1 -0
- package/dist/server/plugins/symbolicatePlugin/index.js +28 -0
- package/dist/server/plugins/symbolicatePlugin/parseStackFrame.d.ts +25 -0
- package/dist/server/plugins/symbolicatePlugin/parseStackFrame.js +51 -0
- package/dist/server/plugins/symbolicatePlugin/symbolicate.d.ts +25 -0
- package/dist/server/plugins/symbolicatePlugin/symbolicate.js +84 -0
- package/dist/server/plugins/symbolicatePlugin/symbolicatePlugin.d.ts +8 -0
- package/dist/server/plugins/symbolicatePlugin/symbolicatePlugin.js +77 -0
- package/dist/server/types.d.ts +92 -0
- package/dist/server/types.js +16 -0
- package/dist/server/wss/WebSocketServerDelegate.d.ts +23 -0
- package/dist/server/wss/WebSocketServerDelegate.js +50 -0
- package/dist/server/wss/WebSocketServerRouter.d.ts +8 -0
- package/dist/server/wss/WebSocketServerRouter.js +66 -0
- package/dist/server/wss/index.d.ts +2 -0
- package/dist/server/wss/index.js +24 -0
- package/dist/shared/PersistentStorage.d.ts +21 -0
- package/dist/shared/PersistentStorage.js +68 -0
- package/dist/transformer/AsyncTransformPipeline.d.ts +4 -0
- package/dist/transformer/AsyncTransformPipeline.js +58 -0
- package/dist/transformer/TransformPipeline.d.ts +37 -0
- package/dist/transformer/TransformPipeline.js +64 -0
- package/dist/transformer/index.d.ts +1 -0
- package/dist/transformer/index.js +28 -0
- package/dist/types/BuildConfig.d.ts +187 -0
- package/dist/types/BuildConfig.js +16 -0
- package/dist/types/BundlerConfig.d.ts +23 -0
- package/dist/types/BundlerConfig.js +16 -0
- package/dist/types/DevServer.d.ts +10 -0
- package/dist/types/DevServer.js +16 -0
- package/dist/types/Id.d.ts +3 -0
- package/dist/types/Id.js +16 -0
- package/dist/types/Plugin.d.ts +28 -0
- package/dist/types/Plugin.js +16 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +30 -0
- package/dist/types/schemas/buildConfigSchema.d.ts +131 -0
- package/dist/types/schemas/buildConfigSchema.js +70 -0
- package/dist/types/schemas/index.d.ts +1 -0
- package/dist/types/schemas/index.js +22 -0
- package/dist/utils/cleanupOutputDirectory.d.ts +1 -0
- package/dist/utils/cleanupOutputDirectory.js +53 -0
- package/dist/utils/defineStepName.d.ts +2 -0
- package/dist/utils/defineStepName.js +30 -0
- package/dist/utils/esbuildUtils.d.ts +1 -0
- package/dist/utils/esbuildUtils.js +45 -0
- package/dist/utils/getBundleName.d.ts +1 -0
- package/dist/utils/getBundleName.js +30 -0
- package/dist/utils/getBundleOutputs.d.ts +5 -0
- package/dist/utils/getBundleOutputs.js +49 -0
- package/dist/utils/getId.d.ts +2 -0
- package/dist/utils/getId.js +34 -0
- package/dist/utils/getSourcemapName.d.ts +1 -0
- package/dist/utils/getSourcemapName.js +30 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +34 -0
- package/dist/utils/isDebugMode.d.ts +1 -0
- package/dist/utils/isDebugMode.js +30 -0
- package/dist/utils/md5.d.ts +1 -0
- package/dist/utils/md5.js +41 -0
- package/dist/utils/mergeBabel.d.ts +2 -0
- package/dist/utils/mergeBabel.js +45 -0
- package/dist/utils/mergeBuildConfigs.d.ts +2 -0
- package/dist/utils/mergeBuildConfigs.js +50 -0
- package/dist/utils/mergeEsbuild.d.ts +2 -0
- package/dist/utils/mergeEsbuild.js +54 -0
- package/dist/utils/mergeExtra.d.ts +1 -0
- package/dist/utils/mergeExtra.js +39 -0
- package/dist/utils/mergeResolver.d.ts +2 -0
- package/dist/utils/mergeResolver.js +45 -0
- package/dist/utils/mergeSwc.d.ts +2 -0
- package/dist/utils/mergeSwc.js +43 -0
- package/dist/utils/mergeTransformer.d.ts +2 -0
- package/dist/utils/mergeTransformer.js +69 -0
- package/dist/utils/printLogo.d.ts +1 -0
- package/dist/utils/printLogo.js +56 -0
- package/dist/utils/printSummary.d.ts +7 -0
- package/dist/utils/printSummary.js +55 -0
- package/dist/utils/progressBar.d.ts +9 -0
- package/dist/utils/progressBar.js +97 -0
- package/dist/utils/promiseHandler.d.ts +12 -0
- package/dist/utils/promiseHandler.js +54 -0
- package/dist/utils/replaceModulePath.d.ts +1 -0
- package/dist/utils/replaceModulePath.js +31 -0
- package/dist/utils/replacePlaceholders.d.ts +1 -0
- package/dist/utils/replacePlaceholders.js +33 -0
- package/dist/utils/stripExtension.d.ts +1 -0
- package/dist/utils/stripExtension.js +41 -0
- package/dist/utils/writeBundle.d.ts +2 -0
- package/dist/utils/writeBundle.js +52 -0
- package/dist/vendors/@react-native/dev-middleware/Device.d.ts +5 -0
- package/dist/vendors/@react-native/dev-middleware/Device.js +33 -0
- package/dist/vendors/@react-native/dev-middleware/InspectorProxy.d.ts +31 -0
- package/dist/vendors/@react-native/dev-middleware/InspectorProxy.js +169 -0
- package/dist/vendors/@react-native/dev-middleware/index.d.ts +3 -0
- package/dist/vendors/@react-native/dev-middleware/index.js +26 -0
- package/dist/vendors/@react-native/dev-middleware/types.d.ts +54 -0
- package/dist/vendors/@react-native/dev-middleware/types.js +16 -0
- package/dist/vendors/@react-native-community/cli-server-api/createWebSocketEndpoints.d.ts +23 -0
- package/dist/vendors/@react-native-community/cli-server-api/createWebSocketEndpoints.js +47 -0
- package/dist/vendors/@react-native-community/cli-server-api/index.d.ts +1 -0
- package/dist/vendors/@react-native-community/cli-server-api/index.js +22 -0
- package/dist/vendors/index.d.ts +27 -0
- package/dist/vendors/index.js +63 -0
- package/dist/vendors/metro/src/Assets.js +159 -0
- package/dist/vendors/metro/src/Bundler/util.js +131 -0
- package/dist/vendors/metro/src/Bundler.js +43 -0
- package/dist/vendors/metro/src/DeltaBundler/DeltaCalculator.js +176 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/baseBytecodeBundle.js +61 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/baseJSBundle.js +45 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/getAllFiles.js +30 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/getAssets.js +23 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/getExplodedSourceMap.js +17 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/getRamBundleInfo.js +87 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/bytecode.js +51 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +6 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +16 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +21 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/js.js +43 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js +13 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/helpers/processModules.js +13 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/hmrJSBundle.js +66 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js +63 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/sourceMapObject.js +18 -0
- package/dist/vendors/metro/src/DeltaBundler/Serializers/sourceMapString.js +8 -0
- package/dist/vendors/metro/src/DeltaBundler/Transformer.js +133 -0
- package/dist/vendors/metro/src/DeltaBundler/Worker.flow.js +64 -0
- package/dist/vendors/metro/src/DeltaBundler/Worker.js +6 -0
- package/dist/vendors/metro/src/DeltaBundler/WorkerFarm.js +128 -0
- package/dist/vendors/metro/src/DeltaBundler/getTransformCacheKey.js +20 -0
- package/dist/vendors/metro/src/DeltaBundler/graphOperations.js +420 -0
- package/dist/vendors/metro/src/DeltaBundler/mergeDeltas.js +52 -0
- package/dist/vendors/metro/src/DeltaBundler/types.flow.js +24 -0
- package/dist/vendors/metro/src/DeltaBundler.js +56 -0
- package/dist/vendors/metro/src/HmrServer.js +224 -0
- package/dist/vendors/metro/src/IncrementalBundler/GraphNotFoundError.js +9 -0
- package/dist/vendors/metro/src/IncrementalBundler/ResourceNotFoundError.js +9 -0
- package/dist/vendors/metro/src/IncrementalBundler/RevisionNotFoundError.js +9 -0
- package/dist/vendors/metro/src/IncrementalBundler.js +213 -0
- package/dist/vendors/metro/src/ModuleGraph/module.js +14 -0
- package/dist/vendors/metro/src/ModuleGraph/node-haste/HasteFS.js +66 -0
- package/dist/vendors/metro/src/ModuleGraph/node-haste/Module.js +22 -0
- package/dist/vendors/metro/src/ModuleGraph/node-haste/ModuleCache.js +43 -0
- package/dist/vendors/metro/src/ModuleGraph/node-haste/Package.js +81 -0
- package/dist/vendors/metro/src/ModuleGraph/node-haste/node-haste.flow.js +1 -0
- package/dist/vendors/metro/src/ModuleGraph/node-haste/node-haste.js +127 -0
- package/dist/vendors/metro/src/ModuleGraph/output/indexed-ram-bundle.js +71 -0
- package/dist/vendors/metro/src/ModuleGraph/output/multiple-files-ram-bundle.js +53 -0
- package/dist/vendors/metro/src/ModuleGraph/output/plain-bundle.js +36 -0
- package/dist/vendors/metro/src/ModuleGraph/output/reverse-dependency-map-references.js +53 -0
- package/dist/vendors/metro/src/ModuleGraph/output/util.js +168 -0
- package/dist/vendors/metro/src/ModuleGraph/silent-console.js +5 -0
- package/dist/vendors/metro/src/ModuleGraph/types.flow.js +1 -0
- package/dist/vendors/metro/src/ModuleGraph/worker/JsFileWrapping.js +87 -0
- package/dist/vendors/metro/src/ModuleGraph/worker/Platforms.js +3 -0
- package/dist/vendors/metro/src/ModuleGraph/worker/collectDependencies.js +440 -0
- package/dist/vendors/metro/src/ModuleGraph/worker/generate.js +21 -0
- package/dist/vendors/metro/src/ModuleGraph/worker/generateImportNames.js +19 -0
- package/dist/vendors/metro/src/ModuleGraph/worker/mergeSourceMaps.js +29 -0
- package/dist/vendors/metro/src/Server/MultipartResponse.js +57 -0
- package/dist/vendors/metro/src/Server/symbolicate.js +109 -0
- package/dist/vendors/metro/src/Server.js +855 -0
- package/dist/vendors/metro/src/cli-utils.js +14 -0
- package/dist/vendors/metro/src/cli.js +9 -0
- package/dist/vendors/metro/src/commands/build.js +67 -0
- package/dist/vendors/metro/src/commands/dependencies.js +75 -0
- package/dist/vendors/metro/src/commands/serve.js +56 -0
- package/dist/vendors/metro/src/index.d.ts +8 -0
- package/dist/vendors/metro/src/index.flow.js +279 -0
- package/dist/vendors/metro/src/index.js +6 -0
- package/dist/vendors/metro/src/isPnP.js +13 -0
- package/dist/vendors/metro/src/lib/BatchProcessor.js +69 -0
- package/dist/vendors/metro/src/lib/CountingSet.js +98 -0
- package/dist/vendors/metro/src/lib/JsonReporter.js +21 -0
- package/dist/vendors/metro/src/lib/RamBundleParser.js +36 -0
- package/dist/vendors/metro/src/lib/ReportableEvent.d.ts +152 -0
- package/dist/vendors/metro/src/lib/TerminalReporter.d.ts +18 -0
- package/dist/vendors/metro/src/lib/TerminalReporter.js +258 -0
- package/dist/vendors/metro/src/lib/bundleToBytecode.js +40 -0
- package/dist/vendors/metro/src/lib/bundleToString.js +22 -0
- package/dist/vendors/metro/src/lib/contextModule.js +73 -0
- package/dist/vendors/metro/src/lib/contextModuleTemplates.js +116 -0
- package/dist/vendors/metro/src/lib/countLines.js +4 -0
- package/dist/vendors/metro/src/lib/createModuleIdFactory.js +14 -0
- package/dist/vendors/metro/src/lib/createWebsocketServer.js +54 -0
- package/dist/vendors/metro/src/lib/debounceAsyncQueue.js +33 -0
- package/dist/vendors/metro/src/lib/formatBundlingError.js +76 -0
- package/dist/vendors/metro/src/lib/getAppendScripts.js +131 -0
- package/dist/vendors/metro/src/lib/getGraphId.js +27 -0
- package/dist/vendors/metro/src/lib/getMaxWorkers.js +6 -0
- package/dist/vendors/metro/src/lib/getPreludeCode.js +32 -0
- package/dist/vendors/metro/src/lib/getPrependedScripts.js +93 -0
- package/dist/vendors/metro/src/lib/logToConsole.js +46 -0
- package/dist/vendors/metro/src/lib/parseCustomResolverOptions.js +13 -0
- package/dist/vendors/metro/src/lib/parseCustomTransformOptions.js +13 -0
- package/dist/vendors/metro/src/lib/parseOptionsFromUrl.js +50 -0
- package/dist/vendors/metro/src/lib/relativizeSourceMap.js +14 -0
- package/dist/vendors/metro/src/lib/reporting.js +26 -0
- package/dist/vendors/metro/src/lib/splitBundleOptions.js +32 -0
- package/dist/vendors/metro/src/lib/transformHelpers.js +112 -0
- package/dist/vendors/metro/src/node-haste/DependencyGraph/ModuleResolution.js +221 -0
- package/dist/vendors/metro/src/node-haste/DependencyGraph/createHasteMap.js +71 -0
- package/dist/vendors/metro/src/node-haste/DependencyGraph.js +223 -0
- package/dist/vendors/metro/src/node-haste/Module.js +21 -0
- package/dist/vendors/metro/src/node-haste/ModuleCache.js +81 -0
- package/dist/vendors/metro/src/node-haste/Package.js +98 -0
- package/dist/vendors/metro/src/node-haste/lib/AssetPaths.js +41 -0
- package/dist/vendors/metro/src/node-haste/lib/parsePlatformFilePath.js +19 -0
- package/dist/vendors/metro/src/shared/output/RamBundle/as-assets.js +61 -0
- package/dist/vendors/metro/src/shared/output/RamBundle/as-indexed-file.js +115 -0
- package/dist/vendors/metro/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +23 -0
- package/dist/vendors/metro/src/shared/output/RamBundle/magic-number.js +2 -0
- package/dist/vendors/metro/src/shared/output/RamBundle/util.js +94 -0
- package/dist/vendors/metro/src/shared/output/RamBundle/write-sourcemap.js +12 -0
- package/dist/vendors/metro/src/shared/output/RamBundle.js +18 -0
- package/dist/vendors/metro/src/shared/output/bundle.flow.js +42 -0
- package/dist/vendors/metro/src/shared/output/bundle.js +6 -0
- package/dist/vendors/metro/src/shared/output/meta.js +31 -0
- package/dist/vendors/metro/src/shared/output/unbundle.js +2 -0
- package/dist/vendors/metro/src/shared/output/writeFile.js +6 -0
- package/dist/vendors/metro/src/shared/types.flow.js +1 -0
- package/dist/vendors/metro-config/src/configTypes.flow.js +1 -0
- package/dist/vendors/metro-config/src/defaults/defaults.js +66 -0
- package/dist/vendors/metro-config/src/defaults/exclusionList.d.ts +3 -0
- package/dist/vendors/metro-config/src/defaults/exclusionList.js +17 -0
- package/dist/vendors/metro-config/src/defaults/index.d.ts +5 -0
- package/dist/vendors/metro-config/src/defaults/index.js +161 -0
- package/dist/vendors/metro-config/src/defaults/validConfig.js +28 -0
- package/dist/vendors/metro-config/src/index.js +9 -0
- package/dist/vendors/metro-config/src/loadConfig.d.ts +4 -0
- package/dist/vendors/metro-config/src/loadConfig.js +188 -0
- package/dist/vendors/metro-core/src/Logger.js +62 -0
- package/dist/vendors/metro-core/src/Terminal.d.ts +30 -0
- package/dist/vendors/metro-core/src/Terminal.js +100 -0
- package/dist/vendors/metro-core/src/canonicalize.js +17 -0
- package/dist/vendors/metro-core/src/errors/AmbiguousModuleResolutionError.js +11 -0
- package/dist/vendors/metro-core/src/errors/PackageResolutionError.js +18 -0
- package/dist/vendors/metro-core/src/errors.js +7 -0
- package/dist/vendors/metro-core/src/index.js +11 -0
- package/dist/vendors/metro-inspector-proxy/src/Device.js +398 -0
- package/dist/vendors/metro-inspector-proxy/src/InspectorProxy.d.ts +21 -0
- package/dist/vendors/metro-inspector-proxy/src/InspectorProxy.js +153 -0
- package/dist/vendors/metro-inspector-proxy/src/cli.js +15 -0
- package/dist/vendors/metro-inspector-proxy/src/index.js +23 -0
- package/dist/vendors/metro-inspector-proxy/src/types.js +1 -0
- package/dist/vendors/metro-transform-worker/src/index.js +429 -0
- package/dist/vendors/metro-transform-worker/src/utils/assetTransformer.js +20 -0
- package/dist/vendors/metro-transform-worker/src/utils/getMinifier.js +11 -0
- package/package.json +163 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var import_metro_file_map = require("metro-file-map");
|
|
3
|
+
const canonicalize = require("../../../metro-core/src/canonicalize");
|
|
4
|
+
const createHasteMap = require("./DependencyGraph/createHasteMap");
|
|
5
|
+
const { ModuleResolver } = require("./DependencyGraph/ModuleResolution");
|
|
6
|
+
const ModuleCache = require("./ModuleCache");
|
|
7
|
+
const { EventEmitter } = require("events");
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const {
|
|
10
|
+
AmbiguousModuleResolutionError,
|
|
11
|
+
Logger: { createActionStartEntry, createActionEndEntry, log },
|
|
12
|
+
PackageResolutionError
|
|
13
|
+
} = require("../../../metro-core/src");
|
|
14
|
+
const { InvalidPackageError } = require("metro-resolver");
|
|
15
|
+
const nullthrows = require("nullthrows");
|
|
16
|
+
const path = require("path");
|
|
17
|
+
const isPnP = require("../isPnP");
|
|
18
|
+
let pnpapi;
|
|
19
|
+
if (isPnP()) {
|
|
20
|
+
pnpapi = require("pnpapi");
|
|
21
|
+
}
|
|
22
|
+
const { DuplicateHasteCandidatesError } = import_metro_file_map.ModuleMap;
|
|
23
|
+
const NULL_PLATFORM = Symbol();
|
|
24
|
+
function getOrCreateMap(map, field) {
|
|
25
|
+
let subMap = map.get(field);
|
|
26
|
+
if (!subMap) {
|
|
27
|
+
subMap = /* @__PURE__ */ new Map();
|
|
28
|
+
map.set(field, subMap);
|
|
29
|
+
}
|
|
30
|
+
return subMap;
|
|
31
|
+
}
|
|
32
|
+
class DependencyGraph extends EventEmitter {
|
|
33
|
+
_assetExtensions;
|
|
34
|
+
_config;
|
|
35
|
+
_haste;
|
|
36
|
+
_hasteFS;
|
|
37
|
+
_moduleCache;
|
|
38
|
+
_moduleMap;
|
|
39
|
+
_moduleResolver;
|
|
40
|
+
_resolutionCache;
|
|
41
|
+
_readyPromise;
|
|
42
|
+
constructor(config, options) {
|
|
43
|
+
super();
|
|
44
|
+
this._config = config;
|
|
45
|
+
this._assetExtensions = new Set(config.resolver.assetExts.map((asset) => "." + asset));
|
|
46
|
+
const { hasReducedPerformance, watch } = options ?? {};
|
|
47
|
+
const initializingMetroLogEntry = log(createActionStartEntry("Initializing Metro"));
|
|
48
|
+
config.reporter.update({
|
|
49
|
+
type: "dep_graph_loading",
|
|
50
|
+
hasReducedPerformance: !!hasReducedPerformance
|
|
51
|
+
});
|
|
52
|
+
const haste = createHasteMap(config, { watch });
|
|
53
|
+
haste.setMaxListeners(1e3);
|
|
54
|
+
this._haste = haste;
|
|
55
|
+
this._readyPromise = haste.build().then(({ hasteFS, moduleMap }) => {
|
|
56
|
+
log(createActionEndEntry(initializingMetroLogEntry));
|
|
57
|
+
config.reporter.update({ type: "dep_graph_loaded" });
|
|
58
|
+
this._hasteFS = hasteFS;
|
|
59
|
+
this._moduleMap = moduleMap;
|
|
60
|
+
this._haste.on("change", this._onHasteChange.bind(this));
|
|
61
|
+
this._resolutionCache = /* @__PURE__ */ new Map();
|
|
62
|
+
this._moduleCache = this._createModuleCache();
|
|
63
|
+
this._createModuleResolver();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Waits for the dependency graph to become ready after initialisation.
|
|
67
|
+
// Don't read anything from the graph until this resolves.
|
|
68
|
+
async ready() {
|
|
69
|
+
await this._readyPromise;
|
|
70
|
+
}
|
|
71
|
+
// Creates the dependency graph and waits for it to become ready.
|
|
72
|
+
// @deprecated Use the constructor + ready() directly.
|
|
73
|
+
static async load(config, options) {
|
|
74
|
+
const self = new DependencyGraph(config, options);
|
|
75
|
+
await self.ready();
|
|
76
|
+
return self;
|
|
77
|
+
}
|
|
78
|
+
_getClosestPackage(filePath) {
|
|
79
|
+
const parsedPath = path.parse(filePath);
|
|
80
|
+
const root = parsedPath.root;
|
|
81
|
+
let dir = parsedPath.dir;
|
|
82
|
+
do {
|
|
83
|
+
const candidate = path.join(dir, "package.json");
|
|
84
|
+
if (this._hasteFS.exists(candidate)) {
|
|
85
|
+
return candidate;
|
|
86
|
+
}
|
|
87
|
+
dir = path.dirname(dir);
|
|
88
|
+
} while (dir !== "." && dir !== root);
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
92
|
+
* LTI update could not be added via codemod */
|
|
93
|
+
_onHasteChange({ eventsQueue, hasteFS, moduleMap }) {
|
|
94
|
+
this._hasteFS = hasteFS;
|
|
95
|
+
this._resolutionCache = /* @__PURE__ */ new Map();
|
|
96
|
+
this._moduleMap = moduleMap;
|
|
97
|
+
eventsQueue.forEach(({ type, filePath }) => this._moduleCache.processFileChange(type, filePath));
|
|
98
|
+
this._createModuleResolver();
|
|
99
|
+
this.emit("change");
|
|
100
|
+
}
|
|
101
|
+
_createModuleResolver() {
|
|
102
|
+
this._moduleResolver = new ModuleResolver({
|
|
103
|
+
dirExists: (filePath) => {
|
|
104
|
+
try {
|
|
105
|
+
return fs.lstatSync(filePath).isDirectory();
|
|
106
|
+
} catch (e) {
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
},
|
|
110
|
+
disableHierarchicalLookup: this._config.resolver.disableHierarchicalLookup,
|
|
111
|
+
doesFileExist: this._doesFileExist,
|
|
112
|
+
emptyModulePath: this._config.resolver.emptyModulePath,
|
|
113
|
+
extraNodeModules: this._config.resolver.extraNodeModules,
|
|
114
|
+
isAssetFile: (file) => this._assetExtensions.has(path.extname(file)),
|
|
115
|
+
mainFields: this._config.resolver.resolverMainFields,
|
|
116
|
+
moduleCache: this._moduleCache,
|
|
117
|
+
moduleMap: this._moduleMap,
|
|
118
|
+
nodeModulesPaths: this._config.resolver.nodeModulesPaths,
|
|
119
|
+
preferNativePlatform: true,
|
|
120
|
+
projectRoot: this._config.projectRoot,
|
|
121
|
+
resolveAsset: (dirPath, assetName, extension) => {
|
|
122
|
+
const basePath = dirPath + path.sep + assetName;
|
|
123
|
+
const assets = [
|
|
124
|
+
basePath + extension,
|
|
125
|
+
...this._config.resolver.assetResolutions.map((resolution) => basePath + "@" + resolution + "x" + extension)
|
|
126
|
+
].filter((candidate) => this._hasteFS.exists(candidate));
|
|
127
|
+
return assets.length ? assets : null;
|
|
128
|
+
},
|
|
129
|
+
resolveRequest: this._config.resolver.resolveRequest,
|
|
130
|
+
sourceExts: this._config.resolver.sourceExts
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
_createModuleCache() {
|
|
134
|
+
return new ModuleCache({
|
|
135
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
136
|
+
getClosestPackage: this._getClosestPackage.bind(this)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
getSha1(filename) {
|
|
140
|
+
const splitIndex = filename.indexOf(".zip/");
|
|
141
|
+
const containerName = splitIndex !== -1 ? filename.slice(0, splitIndex + 4) : filename;
|
|
142
|
+
const realpath = fs.realpathSync(containerName);
|
|
143
|
+
const resolvedPath = (pnpapi ? pnpapi.resolveVirtual(realpath) : realpath) ?? realpath;
|
|
144
|
+
const sha1 = this._hasteFS.getSha1(resolvedPath);
|
|
145
|
+
if (!sha1) {
|
|
146
|
+
throw new ReferenceError(
|
|
147
|
+
`SHA-1 for file ${filename} (${resolvedPath}) is not computed.
|
|
148
|
+
Potential causes:
|
|
149
|
+
1) You have symlinks in your project - watchman does not follow symlinks.
|
|
150
|
+
2) Check \`blockList\` in your metro.config.js and make sure it isn't excluding the file path.`
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return sha1;
|
|
154
|
+
}
|
|
155
|
+
getWatcher() {
|
|
156
|
+
return this._haste;
|
|
157
|
+
}
|
|
158
|
+
end() {
|
|
159
|
+
this._haste.end();
|
|
160
|
+
}
|
|
161
|
+
/** Given a search context, return a list of file paths matching the query. */
|
|
162
|
+
matchFilesWithContext(from, context) {
|
|
163
|
+
return this._hasteFS.matchFilesWithContext(from, context);
|
|
164
|
+
}
|
|
165
|
+
resolveDependency(from, to, platform, resolverOptions, { assumeFlatNodeModules } = {
|
|
166
|
+
assumeFlatNodeModules: false
|
|
167
|
+
}) {
|
|
168
|
+
const isSensitiveToOriginFolder = (
|
|
169
|
+
// Resolution is always relative to the origin folder unless we assume a flat node_modules
|
|
170
|
+
!assumeFlatNodeModules || // Path requests are resolved relative to the origin folder
|
|
171
|
+
to.includes("/") || to === "." || to === ".." || // Preserve standard assumptions under node_modules
|
|
172
|
+
from.includes(path.sep + "node_modules" + path.sep)
|
|
173
|
+
);
|
|
174
|
+
const resolverOptionsKey = JSON.stringify(resolverOptions.customResolverOptions ?? {}, canonicalize) ?? "";
|
|
175
|
+
const originKey = isSensitiveToOriginFolder ? path.dirname(from) : "";
|
|
176
|
+
const targetKey = to;
|
|
177
|
+
const platformKey = platform ?? NULL_PLATFORM;
|
|
178
|
+
const mapByResolverOptions = this._resolutionCache;
|
|
179
|
+
const mapByOrigin = getOrCreateMap(mapByResolverOptions, resolverOptionsKey);
|
|
180
|
+
const mapByTarget = getOrCreateMap(mapByOrigin, originKey);
|
|
181
|
+
const mapByPlatform = getOrCreateMap(mapByTarget, targetKey);
|
|
182
|
+
let modulePath = mapByPlatform.get(platformKey);
|
|
183
|
+
if (!modulePath) {
|
|
184
|
+
try {
|
|
185
|
+
modulePath = this._moduleResolver.resolveDependency(
|
|
186
|
+
this._moduleCache.getModule(from),
|
|
187
|
+
to,
|
|
188
|
+
true,
|
|
189
|
+
platform,
|
|
190
|
+
resolverOptions
|
|
191
|
+
).path;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if (error instanceof DuplicateHasteCandidatesError) {
|
|
194
|
+
throw new AmbiguousModuleResolutionError(from, error);
|
|
195
|
+
}
|
|
196
|
+
if (error instanceof InvalidPackageError) {
|
|
197
|
+
throw new PackageResolutionError({
|
|
198
|
+
packageError: error,
|
|
199
|
+
originModulePath: from,
|
|
200
|
+
targetModuleName: to
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
mapByPlatform.set(platformKey, modulePath);
|
|
207
|
+
return modulePath;
|
|
208
|
+
}
|
|
209
|
+
_doesFileExist = (filePath) => {
|
|
210
|
+
return this._hasteFS.exists(filePath);
|
|
211
|
+
};
|
|
212
|
+
getHasteName(filePath) {
|
|
213
|
+
const hasteName = this._hasteFS.getModuleName(filePath);
|
|
214
|
+
if (hasteName) {
|
|
215
|
+
return hasteName;
|
|
216
|
+
}
|
|
217
|
+
return path.relative(this._config.projectRoot, filePath);
|
|
218
|
+
}
|
|
219
|
+
getDependencies(filePath) {
|
|
220
|
+
return nullthrows(this._hasteFS.getDependencies(filePath));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
module.exports = DependencyGraph;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const isAbsolutePath = require("absolute-path");
|
|
3
|
+
class Module {
|
|
4
|
+
path;
|
|
5
|
+
_moduleCache;
|
|
6
|
+
_sourceCode;
|
|
7
|
+
// $FlowFixMe[missing-local-annot]
|
|
8
|
+
constructor(file, moduleCache) {
|
|
9
|
+
if (!isAbsolutePath(file)) {
|
|
10
|
+
throw new Error("Expected file to be absolute path but got " + file);
|
|
11
|
+
}
|
|
12
|
+
this.path = file;
|
|
13
|
+
this._moduleCache = moduleCache;
|
|
14
|
+
}
|
|
15
|
+
getPackage() {
|
|
16
|
+
return this._moduleCache.getPackageForModule(this);
|
|
17
|
+
}
|
|
18
|
+
invalidate() {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
module.exports = Module;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const Module = require("./Module");
|
|
3
|
+
const Package = require("./Package");
|
|
4
|
+
class ModuleCache {
|
|
5
|
+
_getClosestPackage;
|
|
6
|
+
_moduleCache;
|
|
7
|
+
_packageCache;
|
|
8
|
+
// Cache for "closest package.json" queries by module path.
|
|
9
|
+
_packagePathByModulePath;
|
|
10
|
+
// The inverse of _packagePathByModulePath.
|
|
11
|
+
_modulePathsByPackagePath;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this._getClosestPackage = options.getClosestPackage;
|
|
14
|
+
this._moduleCache = /* @__PURE__ */ Object.create(null);
|
|
15
|
+
this._packageCache = /* @__PURE__ */ Object.create(null);
|
|
16
|
+
this._packagePathByModulePath = /* @__PURE__ */ Object.create(null);
|
|
17
|
+
this._modulePathsByPackagePath = /* @__PURE__ */ Object.create(null);
|
|
18
|
+
}
|
|
19
|
+
getModule(filePath) {
|
|
20
|
+
if (!this._moduleCache[filePath]) {
|
|
21
|
+
this._moduleCache[filePath] = new Module(filePath, this);
|
|
22
|
+
}
|
|
23
|
+
return this._moduleCache[filePath];
|
|
24
|
+
}
|
|
25
|
+
getPackage(filePath) {
|
|
26
|
+
if (!this._packageCache[filePath]) {
|
|
27
|
+
this._packageCache[filePath] = new Package({
|
|
28
|
+
file: filePath
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return this._packageCache[filePath];
|
|
32
|
+
}
|
|
33
|
+
getPackageForModule(module2) {
|
|
34
|
+
return this.getPackageOf(module2.path);
|
|
35
|
+
}
|
|
36
|
+
getPackageOf(modulePath) {
|
|
37
|
+
let packagePath = this._packagePathByModulePath[modulePath];
|
|
38
|
+
if (packagePath && this._packageCache[packagePath]) {
|
|
39
|
+
return this._packageCache[packagePath];
|
|
40
|
+
}
|
|
41
|
+
packagePath = this._getClosestPackage(modulePath);
|
|
42
|
+
if (!packagePath) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
this._packagePathByModulePath[modulePath] = packagePath;
|
|
46
|
+
const modulePaths = this._modulePathsByPackagePath[packagePath] ?? /* @__PURE__ */ new Set();
|
|
47
|
+
modulePaths.add(modulePath);
|
|
48
|
+
this._modulePathsByPackagePath[packagePath] = modulePaths;
|
|
49
|
+
return this.getPackage(packagePath);
|
|
50
|
+
}
|
|
51
|
+
processFileChange(type, filePath) {
|
|
52
|
+
if (this._moduleCache[filePath]) {
|
|
53
|
+
this._moduleCache[filePath].invalidate();
|
|
54
|
+
delete this._moduleCache[filePath];
|
|
55
|
+
}
|
|
56
|
+
if (this._packageCache[filePath]) {
|
|
57
|
+
this._packageCache[filePath].invalidate();
|
|
58
|
+
delete this._packageCache[filePath];
|
|
59
|
+
}
|
|
60
|
+
if (this._packagePathByModulePath[filePath]) {
|
|
61
|
+
const packagePath = this._packagePathByModulePath[filePath];
|
|
62
|
+
delete this._packagePathByModulePath[filePath];
|
|
63
|
+
const modulePaths = this._modulePathsByPackagePath[packagePath];
|
|
64
|
+
if (modulePaths) {
|
|
65
|
+
modulePaths.delete(filePath);
|
|
66
|
+
if (modulePaths.size === 0) {
|
|
67
|
+
delete this._modulePathsByPackagePath[packagePath];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (this._modulePathsByPackagePath[filePath]) {
|
|
72
|
+
const modulePaths = this._modulePathsByPackagePath[filePath];
|
|
73
|
+
for (const modulePath of modulePaths) {
|
|
74
|
+
delete this._packagePathByModulePath[modulePath];
|
|
75
|
+
}
|
|
76
|
+
modulePaths.clear();
|
|
77
|
+
delete this._modulePathsByPackagePath[filePath];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
module.exports = ModuleCache;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
class Package {
|
|
5
|
+
path;
|
|
6
|
+
_root;
|
|
7
|
+
_content;
|
|
8
|
+
constructor({ file }) {
|
|
9
|
+
this.path = path.resolve(file);
|
|
10
|
+
this._root = path.dirname(this.path);
|
|
11
|
+
this._content = null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The `browser` field and replacement behavior is specified in
|
|
15
|
+
* https://github.com/defunctzombie/package-browser-field-spec.
|
|
16
|
+
*/
|
|
17
|
+
getMain(mainFields) {
|
|
18
|
+
const json = this.read();
|
|
19
|
+
let main;
|
|
20
|
+
for (const name of mainFields) {
|
|
21
|
+
if (typeof json[name] === "string") {
|
|
22
|
+
main = json[name];
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!main) {
|
|
27
|
+
main = "index";
|
|
28
|
+
}
|
|
29
|
+
const replacements = getReplacements(json, mainFields);
|
|
30
|
+
if (replacements) {
|
|
31
|
+
const variants = [main];
|
|
32
|
+
if (main.slice(0, 2) === "./") {
|
|
33
|
+
variants.push(main.slice(2));
|
|
34
|
+
} else {
|
|
35
|
+
variants.push("./" + main);
|
|
36
|
+
}
|
|
37
|
+
for (const variant of variants) {
|
|
38
|
+
const winner = replacements[variant] || replacements[variant + ".js"] || replacements[variant + ".json"] || replacements[variant.replace(/(\.js|\.json)$/, "")];
|
|
39
|
+
if (winner) {
|
|
40
|
+
main = winner;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return path.join(this._root, main);
|
|
46
|
+
}
|
|
47
|
+
invalidate() {
|
|
48
|
+
this._content = null;
|
|
49
|
+
}
|
|
50
|
+
redirectRequire(name, mainFields) {
|
|
51
|
+
const json = this.read();
|
|
52
|
+
const replacements = getReplacements(json, mainFields);
|
|
53
|
+
if (!replacements) {
|
|
54
|
+
return name;
|
|
55
|
+
}
|
|
56
|
+
if (!name.startsWith(".") && !path.isAbsolute(name)) {
|
|
57
|
+
const replacement = replacements[name];
|
|
58
|
+
return replacement === false ? false : replacement || name;
|
|
59
|
+
}
|
|
60
|
+
let relPath = "./" + path.relative(this._root, path.resolve(this._root, name));
|
|
61
|
+
if (path.sep !== "/") {
|
|
62
|
+
relPath = relPath.replace(new RegExp("\\" + path.sep, "g"), "/");
|
|
63
|
+
}
|
|
64
|
+
let redirect = replacements[relPath];
|
|
65
|
+
if (redirect == null) {
|
|
66
|
+
redirect = replacements[relPath + ".js"];
|
|
67
|
+
if (redirect == null) {
|
|
68
|
+
redirect = replacements[relPath + ".json"];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (redirect === false) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (redirect) {
|
|
75
|
+
return path.join(this._root, redirect);
|
|
76
|
+
}
|
|
77
|
+
return name;
|
|
78
|
+
}
|
|
79
|
+
read() {
|
|
80
|
+
if (this._content == null) {
|
|
81
|
+
this._content = JSON.parse(fs.readFileSync(this.path, "utf8"));
|
|
82
|
+
}
|
|
83
|
+
return this._content;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function getReplacements(pkg, mainFields) {
|
|
87
|
+
const replacements = mainFields.map((name) => {
|
|
88
|
+
if (!pkg[name] || typeof pkg[name] === "string") {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return pkg[name];
|
|
92
|
+
}).filter(Boolean);
|
|
93
|
+
if (!replacements.length) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return Object.assign({}, ...replacements.reverse());
|
|
97
|
+
}
|
|
98
|
+
module.exports = Package;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const parsePlatformFilePath = require("./parsePlatformFilePath");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const ASSET_BASE_NAME_RE = /(.+?)(@([\d.]+)x)?$/;
|
|
5
|
+
function parseBaseName(baseName) {
|
|
6
|
+
const match = baseName.match(ASSET_BASE_NAME_RE);
|
|
7
|
+
if (!match) {
|
|
8
|
+
throw new Error(`invalid asset name: \`${baseName}'`);
|
|
9
|
+
}
|
|
10
|
+
const rootName = match[1];
|
|
11
|
+
if (match[3] != null) {
|
|
12
|
+
const resolution = parseFloat(match[3]);
|
|
13
|
+
if (!Number.isNaN(resolution)) {
|
|
14
|
+
return { rootName, resolution };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return { rootName, resolution: 1 };
|
|
18
|
+
}
|
|
19
|
+
function tryParse(filePath, platforms) {
|
|
20
|
+
const result = parsePlatformFilePath(filePath, platforms);
|
|
21
|
+
const { dirPath, baseName, platform, extension } = result;
|
|
22
|
+
if (extension == null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const { rootName, resolution } = parseBaseName(baseName);
|
|
26
|
+
return {
|
|
27
|
+
assetName: path.join(dirPath, `${rootName}.${extension}`),
|
|
28
|
+
name: rootName,
|
|
29
|
+
platform,
|
|
30
|
+
resolution,
|
|
31
|
+
type: extension
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function parse(filePath, platforms) {
|
|
35
|
+
const result = tryParse(filePath, platforms);
|
|
36
|
+
if (result == null) {
|
|
37
|
+
throw new Error("invalid asset file path: `${filePath}");
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
module.exports = { parse, tryParse };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const PATH_RE = /^(.+?)(\.([^.]+))?\.([^.]+)$/;
|
|
4
|
+
function parsePlatformFilePath(filePath, platforms) {
|
|
5
|
+
const dirPath = path.dirname(filePath);
|
|
6
|
+
const fileName = path.basename(filePath);
|
|
7
|
+
const match = fileName.match(PATH_RE);
|
|
8
|
+
if (!match) {
|
|
9
|
+
return { dirPath, baseName: fileName, platform: null, extension: null };
|
|
10
|
+
}
|
|
11
|
+
const extension = match[4] || null;
|
|
12
|
+
const platform = match[3] || null;
|
|
13
|
+
if (platform == null || platforms.has(platform)) {
|
|
14
|
+
return { dirPath, baseName: match[1], platform, extension };
|
|
15
|
+
}
|
|
16
|
+
const baseName = `${match[1]}.${platform}`;
|
|
17
|
+
return { dirPath, baseName, platform: null, extension };
|
|
18
|
+
}
|
|
19
|
+
module.exports = parsePlatformFilePath;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const relativizeSourceMapInline = require("../../../lib/relativizeSourceMap");
|
|
3
|
+
const writeFile = require("../writeFile");
|
|
4
|
+
const buildSourcemapWithMetadata = require("./buildSourcemapWithMetadata");
|
|
5
|
+
const MAGIC_RAM_BUNDLE_NUMBER = require("./magic-number");
|
|
6
|
+
const { joinModules } = require("./util");
|
|
7
|
+
const writeSourceMap = require("./write-sourcemap");
|
|
8
|
+
const fsPromises = require("fs").promises;
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const MAGIC_RAM_BUNDLE_FILENAME = "UNBUNDLE";
|
|
11
|
+
const MODULES_DIR = "js-modules";
|
|
12
|
+
function saveAsAssets(bundle, options, log) {
|
|
13
|
+
const { bundleOutput, bundleEncoding: encoding, sourcemapOutput, sourcemapSourcesRoot } = options;
|
|
14
|
+
log("start");
|
|
15
|
+
const { startupModules, lazyModules } = bundle;
|
|
16
|
+
log("finish");
|
|
17
|
+
const startupCode = joinModules(startupModules);
|
|
18
|
+
log("Writing bundle output to:", bundleOutput);
|
|
19
|
+
const modulesDir = path.join(path.dirname(bundleOutput), MODULES_DIR);
|
|
20
|
+
const writeUnbundle = createDir(modulesDir).then(
|
|
21
|
+
// create the modules directory first
|
|
22
|
+
() => Promise.all([
|
|
23
|
+
writeModules(lazyModules, modulesDir, encoding),
|
|
24
|
+
writeFile(bundleOutput, startupCode, encoding),
|
|
25
|
+
writeMagicFlagFile(modulesDir)
|
|
26
|
+
])
|
|
27
|
+
);
|
|
28
|
+
writeUnbundle.then(() => log("Done writing unbundle output"));
|
|
29
|
+
if (sourcemapOutput) {
|
|
30
|
+
const sourceMap = buildSourcemapWithMetadata({
|
|
31
|
+
fixWrapperOffset: true,
|
|
32
|
+
lazyModules: lazyModules.concat(),
|
|
33
|
+
moduleGroups: null,
|
|
34
|
+
startupModules: startupModules.concat()
|
|
35
|
+
});
|
|
36
|
+
if (sourcemapSourcesRoot !== void 0) {
|
|
37
|
+
relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
|
|
38
|
+
}
|
|
39
|
+
const wroteSourceMap = writeSourceMap(sourcemapOutput, JSON.stringify(sourceMap), log);
|
|
40
|
+
return Promise.all([writeUnbundle, wroteSourceMap]);
|
|
41
|
+
} else {
|
|
42
|
+
return writeUnbundle;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function createDir(dirName) {
|
|
46
|
+
return fsPromises.mkdir(dirName, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
function writeModuleFile(module2, modulesDir, encoding) {
|
|
49
|
+
const { code, id } = module2;
|
|
50
|
+
return writeFile(path.join(modulesDir, id + ".js"), code, encoding);
|
|
51
|
+
}
|
|
52
|
+
function writeModules(modules, modulesDir, encoding) {
|
|
53
|
+
const writeFiles = modules.map((module2) => writeModuleFile(module2, modulesDir, encoding));
|
|
54
|
+
return Promise.all(writeFiles);
|
|
55
|
+
}
|
|
56
|
+
function writeMagicFlagFile(outputDir) {
|
|
57
|
+
const buffer = Buffer.alloc(4);
|
|
58
|
+
buffer.writeUInt32LE(MAGIC_RAM_BUNDLE_NUMBER, 0);
|
|
59
|
+
return writeFile(path.join(outputDir, MAGIC_RAM_BUNDLE_FILENAME), buffer);
|
|
60
|
+
}
|
|
61
|
+
module.exports = saveAsAssets;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const relativizeSourceMapInline = require("../../../lib/relativizeSourceMap");
|
|
3
|
+
const buildSourcemapWithMetadata = require("./buildSourcemapWithMetadata");
|
|
4
|
+
const MAGIC_UNBUNDLE_FILE_HEADER = require("./magic-number");
|
|
5
|
+
const { joinModules } = require("./util");
|
|
6
|
+
const writeSourceMap = require("./write-sourcemap");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const SIZEOF_UINT32 = 4;
|
|
9
|
+
function saveAsIndexedFile(bundle, options, log) {
|
|
10
|
+
const { bundleOutput, bundleEncoding: encoding, sourcemapOutput, sourcemapSourcesRoot } = options;
|
|
11
|
+
log("start");
|
|
12
|
+
const { startupModules, lazyModules, groups } = bundle;
|
|
13
|
+
log("finish");
|
|
14
|
+
const moduleGroups = createModuleGroups(groups, lazyModules);
|
|
15
|
+
const startupCode = joinModules(startupModules);
|
|
16
|
+
log("Writing unbundle output to:", bundleOutput);
|
|
17
|
+
const writeUnbundle = writeBuffers(
|
|
18
|
+
fs.createWriteStream(bundleOutput),
|
|
19
|
+
buildTableAndContents(startupCode, lazyModules, moduleGroups, encoding)
|
|
20
|
+
).then(() => log("Done writing unbundle output"));
|
|
21
|
+
if (sourcemapOutput) {
|
|
22
|
+
const sourceMap = buildSourcemapWithMetadata({
|
|
23
|
+
startupModules: startupModules.concat(),
|
|
24
|
+
lazyModules: lazyModules.concat(),
|
|
25
|
+
moduleGroups,
|
|
26
|
+
fixWrapperOffset: true
|
|
27
|
+
});
|
|
28
|
+
if (sourcemapSourcesRoot !== void 0) {
|
|
29
|
+
relativizeSourceMapInline(sourceMap, sourcemapSourcesRoot);
|
|
30
|
+
}
|
|
31
|
+
const wroteSourceMap = writeSourceMap(sourcemapOutput, JSON.stringify(sourceMap), log);
|
|
32
|
+
return Promise.all([writeUnbundle, wroteSourceMap]);
|
|
33
|
+
} else {
|
|
34
|
+
return writeUnbundle;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const fileHeader = Buffer.alloc(4);
|
|
38
|
+
fileHeader.writeUInt32LE(MAGIC_UNBUNDLE_FILE_HEADER, 0);
|
|
39
|
+
const nullByteBuffer = Buffer.alloc(1).fill(0);
|
|
40
|
+
function writeBuffers(stream, buffers) {
|
|
41
|
+
buffers.forEach((buffer) => stream.write(buffer));
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
stream.on("error", reject);
|
|
44
|
+
stream.on("finish", () => resolve());
|
|
45
|
+
stream.end();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function nullTerminatedBuffer(contents, encoding) {
|
|
49
|
+
return Buffer.concat([Buffer.from(contents, encoding), nullByteBuffer]);
|
|
50
|
+
}
|
|
51
|
+
function moduleToBuffer(id, code, encoding) {
|
|
52
|
+
return {
|
|
53
|
+
id,
|
|
54
|
+
buffer: nullTerminatedBuffer(code, encoding)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function entryOffset(n) {
|
|
58
|
+
return (2 + n * 2) * SIZEOF_UINT32;
|
|
59
|
+
}
|
|
60
|
+
function buildModuleTable(startupCode, moduleBuffers, moduleGroups) {
|
|
61
|
+
const moduleIds = [...moduleGroups.modulesById.keys()];
|
|
62
|
+
const maxId = moduleIds.reduce((max, id) => Math.max(max, id));
|
|
63
|
+
const numEntries = maxId + 1;
|
|
64
|
+
const table = Buffer.alloc(entryOffset(numEntries)).fill(0);
|
|
65
|
+
table.writeUInt32LE(numEntries, 0);
|
|
66
|
+
table.writeUInt32LE(startupCode.length, SIZEOF_UINT32);
|
|
67
|
+
let codeOffset = startupCode.length;
|
|
68
|
+
moduleBuffers.forEach(({ id, buffer }) => {
|
|
69
|
+
const group = moduleGroups.groups.get(id);
|
|
70
|
+
const idsInGroup = group ? [id].concat(Array.from(group)) : [id];
|
|
71
|
+
idsInGroup.forEach((moduleId) => {
|
|
72
|
+
const offset = entryOffset(moduleId);
|
|
73
|
+
table.writeUInt32LE(codeOffset, offset);
|
|
74
|
+
table.writeUInt32LE(buffer.length, offset + SIZEOF_UINT32);
|
|
75
|
+
});
|
|
76
|
+
codeOffset += buffer.length;
|
|
77
|
+
});
|
|
78
|
+
return table;
|
|
79
|
+
}
|
|
80
|
+
function groupCode(rootCode, moduleGroup, modulesById) {
|
|
81
|
+
if (!moduleGroup || !moduleGroup.size) {
|
|
82
|
+
return rootCode;
|
|
83
|
+
}
|
|
84
|
+
const code = [rootCode];
|
|
85
|
+
for (const id of moduleGroup) {
|
|
86
|
+
code.push((modulesById.get(id) || { code: "" }).code);
|
|
87
|
+
}
|
|
88
|
+
return code.join("\n");
|
|
89
|
+
}
|
|
90
|
+
function buildModuleBuffers(modules, moduleGroups, encoding) {
|
|
91
|
+
return modules.filter((m) => !moduleGroups.modulesInGroups.has(m.id)).map(
|
|
92
|
+
({ id, code }) => moduleToBuffer(id, groupCode(code, moduleGroups.groups.get(id), moduleGroups.modulesById), encoding)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
function buildTableAndContents(startupCode, modules, moduleGroups, encoding) {
|
|
96
|
+
const startupCodeBuffer = nullTerminatedBuffer(startupCode, encoding);
|
|
97
|
+
const moduleBuffers = buildModuleBuffers(modules, moduleGroups, encoding);
|
|
98
|
+
const table = buildModuleTable(startupCodeBuffer, moduleBuffers, moduleGroups);
|
|
99
|
+
return [fileHeader, table, startupCodeBuffer].concat(moduleBuffers.map(({ buffer }) => buffer));
|
|
100
|
+
}
|
|
101
|
+
function createModuleGroups(groups, modules) {
|
|
102
|
+
return {
|
|
103
|
+
groups,
|
|
104
|
+
modulesById: new Map(modules.map((m) => [m.id, m])),
|
|
105
|
+
modulesInGroups: new Set(concat(groups.values()))
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function* concat(iterators) {
|
|
109
|
+
for (const it of iterators) {
|
|
110
|
+
yield* it;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.save = saveAsIndexedFile;
|
|
114
|
+
exports.buildTableAndContents = buildTableAndContents;
|
|
115
|
+
exports.createModuleGroups = createModuleGroups;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { combineSourceMaps, combineSourceMapsAddingOffsets, joinModules } = require("./util");
|
|
3
|
+
module.exports = ({ fixWrapperOffset, lazyModules, moduleGroups, startupModules }) => {
|
|
4
|
+
const options = fixWrapperOffset ? { fixWrapperOffset: true } : void 0;
|
|
5
|
+
const startupModule = {
|
|
6
|
+
code: joinModules(startupModules),
|
|
7
|
+
id: Number.MIN_SAFE_INTEGER,
|
|
8
|
+
map: combineSourceMaps(startupModules, void 0, options),
|
|
9
|
+
sourcePath: ""
|
|
10
|
+
};
|
|
11
|
+
const module_paths = [];
|
|
12
|
+
startupModules.forEach((m) => {
|
|
13
|
+
module_paths[m.id] = m.sourcePath;
|
|
14
|
+
});
|
|
15
|
+
lazyModules.forEach((m) => {
|
|
16
|
+
module_paths[m.id] = m.sourcePath;
|
|
17
|
+
});
|
|
18
|
+
const map = combineSourceMapsAddingOffsets([startupModule].concat(lazyModules), module_paths, moduleGroups, options);
|
|
19
|
+
if (map.x_facebook_offsets != null) {
|
|
20
|
+
delete map.x_facebook_offsets[Number.MIN_SAFE_INTEGER];
|
|
21
|
+
}
|
|
22
|
+
return map;
|
|
23
|
+
};
|