@atlaspack/core 2.16.2-canary.48 → 2.16.2-canary.481
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/CHANGELOG.md +1324 -0
- package/dist/AssetGraph.js +523 -0
- package/dist/Atlaspack.js +701 -0
- package/dist/AtlaspackConfig.js +324 -0
- package/dist/AtlaspackConfig.schema.js +117 -0
- package/dist/BundleGraph.js +1906 -0
- package/dist/CommittedAsset.js +142 -0
- package/dist/Dependency.js +125 -0
- package/dist/Environment.js +132 -0
- package/dist/EnvironmentManager.js +108 -0
- package/dist/IdentifierRegistry.js +38 -0
- package/dist/InternalConfig.js +37 -0
- package/dist/PackagerRunner.js +470 -0
- package/dist/ReporterRunner.js +151 -0
- package/dist/RequestTracker.js +1297 -0
- package/dist/SymbolPropagation.js +624 -0
- package/dist/TargetDescriptor.schema.js +146 -0
- package/dist/Transformation.js +514 -0
- package/dist/UncommittedAsset.js +310 -0
- package/dist/Validation.js +196 -0
- package/dist/applyRuntimes.js +384 -0
- package/dist/assetUtils.js +169 -0
- package/dist/atlaspack-v3/AtlaspackV3.js +83 -0
- package/dist/atlaspack-v3/NapiWorkerPool.js +114 -0
- package/dist/atlaspack-v3/fs.js +53 -0
- package/dist/atlaspack-v3/index.js +25 -0
- package/dist/atlaspack-v3/jsCallable.js +16 -0
- package/dist/atlaspack-v3/worker/compat/asset-symbols.js +190 -0
- package/dist/atlaspack-v3/worker/compat/bitflags.js +98 -0
- package/dist/atlaspack-v3/worker/compat/dependency.js +43 -0
- package/dist/atlaspack-v3/worker/compat/environment.js +57 -0
- package/dist/atlaspack-v3/worker/compat/index.js +24 -0
- package/dist/atlaspack-v3/worker/compat/mutable-asset.js +152 -0
- package/dist/atlaspack-v3/worker/compat/plugin-config.js +64 -0
- package/dist/atlaspack-v3/worker/compat/plugin-options.js +137 -0
- package/dist/atlaspack-v3/worker/compat/plugin-tracer.js +10 -0
- package/dist/atlaspack-v3/worker/compat/target.js +14 -0
- package/dist/atlaspack-v3/worker/side-effect-detector.js +243 -0
- package/dist/atlaspack-v3/worker/worker.js +398 -0
- package/dist/constants.js +17 -0
- package/dist/dumpGraphToGraphViz.js +281 -0
- package/dist/index.js +62 -0
- package/dist/loadAtlaspackPlugin.js +128 -0
- package/dist/loadDotEnv.js +41 -0
- package/dist/projectPath.js +83 -0
- package/dist/public/Asset.js +279 -0
- package/dist/public/Bundle.js +224 -0
- package/dist/public/BundleGraph.js +371 -0
- package/dist/public/BundleGroup.js +53 -0
- package/dist/public/Config.js +286 -0
- package/dist/public/Dependency.js +138 -0
- package/dist/public/Environment.js +278 -0
- package/dist/public/MutableBundleGraph.js +277 -0
- package/dist/public/PluginOptions.js +80 -0
- package/dist/public/Symbols.js +248 -0
- package/dist/public/Target.js +69 -0
- package/dist/registerCoreWithSerializer.js +38 -0
- package/dist/requests/AssetGraphRequest.js +430 -0
- package/dist/requests/AssetGraphRequestRust.js +471 -0
- package/dist/requests/AssetRequest.js +130 -0
- package/dist/requests/AtlaspackBuildRequest.js +98 -0
- package/dist/requests/AtlaspackConfigRequest.js +493 -0
- package/dist/requests/BundleGraphRequest.js +381 -0
- package/dist/requests/BundleGraphRequestRust.js +324 -0
- package/dist/requests/BundleGraphRequestUtils.js +262 -0
- package/dist/requests/ConfigRequest.js +246 -0
- package/dist/requests/DevDepRequest.js +204 -0
- package/dist/requests/EntryRequest.js +314 -0
- package/dist/requests/PackageRequest.js +89 -0
- package/dist/requests/PathRequest.js +349 -0
- package/dist/requests/TargetRequest.js +1316 -0
- package/dist/requests/ValidationRequest.js +49 -0
- package/dist/requests/WriteBundleRequest.js +522 -0
- package/dist/requests/WriteBundlesRequest.js +190 -0
- package/dist/requests/asset-graph-diff.js +128 -0
- package/dist/requests/asset-graph-dot.js +131 -0
- package/dist/resolveOptions.js +267 -0
- package/dist/rustWorkerThreadDylibHack.js +19 -0
- package/dist/serializerCore.browser.js +43 -0
- package/dist/summarizeRequest.js +39 -0
- package/dist/types.js +31 -0
- package/dist/utils.js +172 -0
- package/dist/worker.js +123 -0
- package/lib/AssetGraph.js +53 -15
- package/lib/Atlaspack.js +140 -56
- package/lib/AtlaspackConfig.js +17 -6
- package/lib/AtlaspackConfig.schema.js +16 -5
- package/lib/BundleGraph.js +390 -43
- package/lib/CommittedAsset.js +8 -2
- package/lib/Dependency.js +9 -3
- package/lib/Environment.js +16 -10
- package/lib/EnvironmentManager.js +143 -0
- package/lib/IdentifierRegistry.js +2 -4
- package/lib/InternalConfig.js +3 -2
- package/lib/PackagerRunner.js +46 -82
- package/lib/ReporterRunner.js +8 -12
- package/lib/RequestTracker.js +191 -152
- package/lib/SymbolPropagation.js +52 -29
- package/lib/TargetDescriptor.schema.js +10 -1
- package/lib/Transformation.js +68 -19
- package/lib/UncommittedAsset.js +17 -24
- package/lib/Validation.js +20 -5
- package/lib/applyRuntimes.js +98 -7
- package/lib/assetUtils.js +16 -6
- package/lib/atlaspack-v3/AtlaspackV3.js +58 -15
- package/lib/atlaspack-v3/NapiWorkerPool.js +63 -2
- package/lib/atlaspack-v3/fs.js +4 -1
- package/lib/atlaspack-v3/index.js +28 -1
- package/lib/atlaspack-v3/jsCallable.js +0 -2
- package/lib/atlaspack-v3/worker/compat/asset-symbols.js +7 -4
- package/lib/atlaspack-v3/worker/compat/bitflags.js +31 -25
- package/lib/atlaspack-v3/worker/compat/dependency.js +4 -1
- package/lib/atlaspack-v3/worker/compat/environment.js +10 -7
- package/lib/atlaspack-v3/worker/compat/index.js +0 -11
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +16 -11
- package/lib/atlaspack-v3/worker/compat/plugin-config.js +14 -35
- package/lib/atlaspack-v3/worker/compat/plugin-options.js +16 -2
- package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +3 -0
- package/lib/atlaspack-v3/worker/compat/target.js +2 -0
- package/lib/atlaspack-v3/worker/index.js +3 -0
- package/lib/atlaspack-v3/worker/side-effect-detector.js +214 -0
- package/lib/atlaspack-v3/worker/worker.js +231 -79
- package/lib/constants.js +0 -1
- package/lib/dumpGraphToGraphViz.js +72 -17
- package/lib/index.js +46 -3
- package/lib/loadAtlaspackPlugin.js +2 -3
- package/lib/loadDotEnv.js +5 -2
- package/lib/projectPath.js +6 -1
- package/lib/public/Asset.js +22 -12
- package/lib/public/Bundle.js +16 -18
- package/lib/public/BundleGraph.js +27 -25
- package/lib/public/BundleGroup.js +5 -6
- package/lib/public/Config.js +118 -18
- package/lib/public/Dependency.js +9 -7
- package/lib/public/Environment.js +13 -8
- package/lib/public/MutableBundleGraph.js +56 -15
- package/lib/public/PluginOptions.js +2 -2
- package/lib/public/Symbols.js +12 -12
- package/lib/public/Target.js +8 -7
- package/lib/registerCoreWithSerializer.js +7 -4
- package/lib/requests/AssetGraphRequest.js +61 -40
- package/lib/requests/AssetGraphRequestRust.js +314 -82
- package/lib/requests/AssetRequest.js +24 -7
- package/lib/requests/AtlaspackBuildRequest.js +53 -7
- package/lib/requests/AtlaspackConfigRequest.js +29 -19
- package/lib/requests/BundleGraphRequest.js +61 -130
- package/lib/requests/BundleGraphRequestRust.js +381 -0
- package/lib/requests/BundleGraphRequestUtils.js +280 -0
- package/lib/requests/ConfigRequest.js +55 -7
- package/lib/requests/DevDepRequest.js +32 -6
- package/lib/requests/EntryRequest.js +4 -3
- package/lib/requests/PackageRequest.js +56 -12
- package/lib/requests/PathRequest.js +26 -6
- package/lib/requests/TargetRequest.js +129 -60
- package/lib/requests/ValidationRequest.js +6 -2
- package/lib/requests/WriteBundleRequest.js +329 -20
- package/lib/requests/WriteBundlesRequest.js +64 -10
- package/lib/requests/asset-graph-diff.js +13 -8
- package/lib/requests/asset-graph-dot.js +2 -8
- package/lib/resolveOptions.js +37 -14
- package/lib/rustWorkerThreadDylibHack.js +0 -1
- package/lib/serializerCore.browser.js +1 -2
- package/lib/summarizeRequest.js +1 -1
- package/lib/types/AssetGraph.d.ts +55 -0
- package/lib/types/Atlaspack.d.ts +52 -0
- package/lib/types/AtlaspackConfig.d.ts +65 -0
- package/lib/types/AtlaspackConfig.schema.d.ts +53 -0
- package/lib/types/BundleGraph.d.ts +232 -0
- package/lib/types/CommittedAsset.d.ts +23 -0
- package/lib/types/Dependency.d.ts +44 -0
- package/lib/types/Environment.d.ts +11 -0
- package/lib/types/EnvironmentManager.d.ts +37 -0
- package/lib/types/IdentifierRegistry.d.ts +6 -0
- package/lib/types/InternalConfig.d.ts +23 -0
- package/lib/types/PackagerRunner.d.ts +85 -0
- package/lib/types/ReporterRunner.d.ts +25 -0
- package/lib/types/RequestTracker.d.ts +385 -0
- package/lib/types/SymbolPropagation.d.ts +11 -0
- package/lib/types/TargetDescriptor.schema.d.ts +5 -0
- package/lib/types/Transformation.d.ts +72 -0
- package/lib/types/UncommittedAsset.d.ts +61 -0
- package/lib/types/Validation.d.ts +37 -0
- package/lib/types/applyRuntimes.d.ts +25 -0
- package/lib/types/assetUtils.d.ts +42 -0
- package/lib/types/atlaspack-v3/AtlaspackV3.d.ts +35 -0
- package/lib/types/atlaspack-v3/NapiWorkerPool.d.ts +13 -0
- package/lib/types/atlaspack-v3/fs.d.ts +13 -0
- package/lib/types/atlaspack-v3/index.d.ts +6 -0
- package/lib/types/atlaspack-v3/jsCallable.d.ts +1 -0
- package/lib/types/atlaspack-v3/worker/compat/asset-symbols.d.ts +51 -0
- package/lib/types/atlaspack-v3/worker/compat/bitflags.d.ts +14 -0
- package/lib/types/atlaspack-v3/worker/compat/dependency.d.ts +25 -0
- package/lib/types/atlaspack-v3/worker/compat/environment.d.ts +27 -0
- package/{src/atlaspack-v3/worker/compat/index.js → lib/types/atlaspack-v3/worker/compat/index.d.ts} +0 -2
- package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +49 -0
- package/lib/types/atlaspack-v3/worker/compat/plugin-config.d.ts +29 -0
- package/lib/types/atlaspack-v3/worker/compat/plugin-options.d.ts +23 -0
- package/lib/types/atlaspack-v3/worker/compat/plugin-tracer.d.ts +5 -0
- package/lib/types/atlaspack-v3/worker/compat/target.d.ts +11 -0
- package/lib/types/atlaspack-v3/worker/side-effect-detector.d.ts +76 -0
- package/lib/types/atlaspack-v3/worker/worker.d.ts +81 -0
- package/lib/types/constants.d.ts +13 -0
- package/lib/types/dumpGraphToGraphViz.d.ts +10 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/loadAtlaspackPlugin.d.ts +8 -0
- package/lib/types/loadDotEnv.d.ts +3 -0
- package/lib/types/projectPath.d.ts +19 -0
- package/lib/types/public/Asset.d.ts +74 -0
- package/lib/types/public/Bundle.d.ts +45 -0
- package/lib/types/public/BundleGraph.d.ts +72 -0
- package/lib/types/public/BundleGroup.d.ts +12 -0
- package/lib/types/public/Config.d.ts +75 -0
- package/lib/types/public/Dependency.d.ts +32 -0
- package/lib/types/public/Environment.d.ts +34 -0
- package/lib/types/public/MutableBundleGraph.d.ts +26 -0
- package/lib/types/public/PluginOptions.d.ts +25 -0
- package/lib/types/public/Symbols.d.ts +81 -0
- package/lib/types/public/Target.d.ts +16 -0
- package/lib/types/registerCoreWithSerializer.d.ts +2 -0
- package/lib/types/requests/AssetGraphRequest.d.ts +76 -0
- package/lib/types/requests/AssetGraphRequestRust.d.ts +21 -0
- package/lib/types/requests/AssetRequest.d.ts +16 -0
- package/lib/types/requests/AtlaspackBuildRequest.d.ts +33 -0
- package/lib/types/requests/AtlaspackConfigRequest.d.ts +45 -0
- package/lib/types/requests/BundleGraphRequest.d.ts +28 -0
- package/lib/types/requests/BundleGraphRequestRust.d.ts +34 -0
- package/lib/types/requests/BundleGraphRequestUtils.d.ts +38 -0
- package/lib/types/requests/ConfigRequest.d.ts +67 -0
- package/lib/types/requests/DevDepRequest.d.ts +30 -0
- package/lib/types/requests/EntryRequest.d.ts +36 -0
- package/lib/types/requests/PackageRequest.d.ts +27 -0
- package/lib/types/requests/PathRequest.d.ts +48 -0
- package/lib/types/requests/TargetRequest.d.ts +48 -0
- package/lib/types/requests/ValidationRequest.d.ts +20 -0
- package/lib/types/requests/WriteBundleRequest.d.ts +80 -0
- package/lib/types/requests/WriteBundlesRequest.d.ts +32 -0
- package/lib/types/requests/asset-graph-diff.d.ts +1 -0
- package/lib/types/requests/asset-graph-dot.d.ts +9 -0
- package/lib/types/resolveOptions.d.ts +3 -0
- package/lib/types/rustWorkerThreadDylibHack.d.ts +9 -0
- package/lib/types/serializerCore.browser.d.ts +3 -0
- package/lib/types/summarizeRequest.d.ts +10 -0
- package/lib/types/types.d.ts +496 -0
- package/lib/types/utils.d.ts +23 -0
- package/lib/types/worker.d.ts +44 -0
- package/lib/types.js +8 -1
- package/lib/utils.js +18 -3
- package/lib/worker.js +32 -15
- package/package.json +26 -36
- package/src/{AssetGraph.js → AssetGraph.ts} +87 -51
- package/src/{Atlaspack.js → Atlaspack.ts} +181 -72
- package/src/{AtlaspackConfig.schema.js → AtlaspackConfig.schema.ts} +25 -19
- package/src/{AtlaspackConfig.js → AtlaspackConfig.ts} +78 -54
- package/src/{BundleGraph.js → BundleGraph.ts} +575 -145
- package/src/{CommittedAsset.js → CommittedAsset.ts} +15 -13
- package/src/{Dependency.js → Dependency.ts} +59 -42
- package/src/{Environment.js → Environment.ts} +24 -15
- package/src/EnvironmentManager.ts +154 -0
- package/src/{IdentifierRegistry.js → IdentifierRegistry.ts} +1 -4
- package/src/{InternalConfig.js → InternalConfig.ts} +22 -23
- package/src/{PackagerRunner.js → PackagerRunner.ts} +114 -159
- package/src/{ReporterRunner.js → ReporterRunner.ts} +13 -18
- package/src/{RequestTracker.js → RequestTracker.ts} +444 -355
- package/src/{SymbolPropagation.js → SymbolPropagation.ts} +178 -61
- package/src/{TargetDescriptor.schema.js → TargetDescriptor.schema.ts} +10 -1
- package/src/{Transformation.js → Transformation.ts} +110 -65
- package/src/{UncommittedAsset.js → UncommittedAsset.ts} +45 -49
- package/src/{Validation.js → Validation.ts} +32 -17
- package/src/{applyRuntimes.js → applyRuntimes.ts} +135 -26
- package/src/{assetUtils.js → assetUtils.ts} +49 -36
- package/src/atlaspack-v3/AtlaspackV3.ts +183 -0
- package/src/atlaspack-v3/NapiWorkerPool.ts +129 -0
- package/src/atlaspack-v3/{fs.js → fs.ts} +8 -4
- package/src/atlaspack-v3/{index.js → index.ts} +3 -4
- package/src/atlaspack-v3/jsCallable.ts +14 -0
- package/src/atlaspack-v3/worker/compat/{asset-symbols.js → asset-symbols.ts} +40 -30
- package/src/atlaspack-v3/worker/compat/bitflags.ts +102 -0
- package/src/atlaspack-v3/worker/compat/{dependency.js → dependency.ts} +13 -13
- package/src/atlaspack-v3/worker/compat/{environment.js → environment.ts} +13 -9
- package/src/atlaspack-v3/worker/compat/index.ts +8 -0
- package/src/atlaspack-v3/worker/compat/{mutable-asset.js → mutable-asset.ts} +21 -20
- package/src/atlaspack-v3/worker/compat/{plugin-config.js → plugin-config.ts} +25 -56
- package/src/atlaspack-v3/worker/compat/{plugin-options.js → plugin-options.ts} +19 -5
- package/src/atlaspack-v3/worker/compat/{plugin-tracer.js → plugin-tracer.ts} +2 -2
- package/src/atlaspack-v3/worker/compat/{target.js → target.ts} +3 -4
- package/src/atlaspack-v3/worker/index.js +2 -1
- package/src/atlaspack-v3/worker/side-effect-detector.ts +298 -0
- package/src/atlaspack-v3/worker/worker.ts +548 -0
- package/src/{constants.js → constants.ts} +0 -3
- package/src/{dumpGraphToGraphViz.js → dumpGraphToGraphViz.ts} +73 -28
- package/src/index.ts +18 -0
- package/src/{loadAtlaspackPlugin.js → loadAtlaspackPlugin.ts} +8 -9
- package/src/{loadDotEnv.js → loadDotEnv.ts} +2 -2
- package/src/{projectPath.js → projectPath.ts} +20 -9
- package/src/public/{Asset.js → Asset.ts} +41 -28
- package/src/public/{Bundle.js → Bundle.ts} +28 -29
- package/src/public/{BundleGraph.js → BundleGraph.ts} +103 -68
- package/src/public/{BundleGroup.js → BundleGroup.ts} +7 -10
- package/src/public/{Config.js → Config.ts} +171 -33
- package/src/public/{Dependency.js → Dependency.ts} +20 -17
- package/src/public/{Environment.js → Environment.ts} +28 -17
- package/src/public/{MutableBundleGraph.js → MutableBundleGraph.ts} +55 -24
- package/src/public/{PluginOptions.js → PluginOptions.ts} +6 -6
- package/src/public/{Symbols.js → Symbols.ts} +75 -36
- package/src/public/{Target.js → Target.ts} +10 -8
- package/src/{registerCoreWithSerializer.js → registerCoreWithSerializer.ts} +9 -7
- package/src/requests/{AssetGraphRequest.js → AssetGraphRequest.ts} +117 -90
- package/src/requests/AssetGraphRequestRust.ts +557 -0
- package/src/requests/{AssetRequest.js → AssetRequest.ts} +24 -18
- package/src/requests/AtlaspackBuildRequest.ts +168 -0
- package/src/requests/{AtlaspackConfigRequest.js → AtlaspackConfigRequest.ts} +72 -58
- package/src/requests/{BundleGraphRequest.js → BundleGraphRequest.ts} +119 -199
- package/src/requests/BundleGraphRequestRust.ts +470 -0
- package/src/requests/BundleGraphRequestUtils.ts +323 -0
- package/src/requests/{ConfigRequest.js → ConfigRequest.ts} +110 -50
- package/src/requests/{DevDepRequest.js → DevDepRequest.ts} +60 -35
- package/src/requests/{EntryRequest.js → EntryRequest.ts} +36 -31
- package/src/requests/{PackageRequest.js → PackageRequest.ts} +52 -25
- package/src/requests/{PathRequest.js → PathRequest.ts} +47 -37
- package/src/requests/{TargetRequest.js → TargetRequest.ts} +265 -179
- package/src/requests/{ValidationRequest.js → ValidationRequest.ts} +18 -17
- package/src/requests/WriteBundleRequest.ts +734 -0
- package/src/requests/{WriteBundlesRequest.js → WriteBundlesRequest.ts} +134 -50
- package/src/requests/{asset-graph-diff.js → asset-graph-diff.ts} +25 -21
- package/src/requests/{asset-graph-dot.js → asset-graph-dot.ts} +8 -12
- package/src/{resolveOptions.js → resolveOptions.ts} +57 -27
- package/src/{rustWorkerThreadDylibHack.js → rustWorkerThreadDylibHack.ts} +1 -4
- package/src/{serializerCore.browser.js → serializerCore.browser.ts} +2 -3
- package/src/{summarizeRequest.js → summarizeRequest.ts} +17 -5
- package/src/types.ts +651 -0
- package/src/{utils.js → utils.ts} +52 -21
- package/src/{worker.js → worker.ts} +50 -42
- package/test/{AssetGraph.test.js → AssetGraph.test.ts} +5 -8
- package/test/{Atlaspack.test.js → Atlaspack.test.ts} +5 -10
- package/test/{AtlaspackConfig.test.js → AtlaspackConfig.test.ts} +0 -5
- package/test/{AtlaspackConfigRequest.test.js → AtlaspackConfigRequest.test.ts} +76 -16
- package/test/{BundleGraph.test.js → BundleGraph.test.ts} +8 -13
- package/test/{Dependency.test.js → Dependency.test.ts} +2 -3
- package/test/{EntryRequest.test.js → EntryRequest.test.ts} +1 -6
- package/test/Environment.test.ts +153 -0
- package/test/EnvironmentManager.test.ts +188 -0
- package/test/{IdentifierRegistry.test.js → IdentifierRegistry.test.ts} +2 -4
- package/test/{InternalAsset.test.js → InternalAsset.test.ts} +2 -7
- package/test/PackagerRunner.test.ts +0 -0
- package/test/{PublicAsset.test.js → PublicAsset.test.ts} +2 -7
- package/test/{PublicBundle.test.js → PublicBundle.test.ts} +1 -2
- package/test/{PublicDependency.test.js → PublicDependency.test.ts} +0 -2
- package/test/PublicEnvironment.test.ts +49 -0
- package/test/{PublicMutableBundleGraph.test.js → PublicMutableBundleGraph.test.ts} +6 -11
- package/test/{RequestTracker.test.js → RequestTracker.test.ts} +136 -58
- package/test/{SymbolPropagation.test.js → SymbolPropagation.test.ts} +124 -74
- package/test/{TargetRequest.test.js → TargetRequest.test.ts} +91 -92
- package/test/fixtures/config-with-reporters/.parcelrc +7 -0
- package/test/fixtures/custom-targets/package.json +6 -0
- package/test/public/Config.test.ts +104 -0
- package/test/requests/AssetGraphRequestRust.test.ts +443 -0
- package/test/requests/{ConfigRequest.test.js → ConfigRequest.test.ts} +202 -13
- package/test/requests/{DevDepRequest.test.js → DevDepRequest.test.ts} +0 -2
- package/test/requests/WriteBundleRequest.test.ts +602 -0
- package/test/{test-utils.js → test-utils.ts} +3 -4
- package/test/{utils.test.js → utils.test.ts} +1 -3
- package/tsconfig.json +60 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/index.d.ts +0 -30
- package/lib/atlaspack-v3/worker/compat/plugin-logger.js +0 -29
- package/src/atlaspack-v3/AtlaspackV3.js +0 -87
- package/src/atlaspack-v3/NapiWorkerPool.js +0 -53
- package/src/atlaspack-v3/jsCallable.js +0 -18
- package/src/atlaspack-v3/worker/compat/bitflags.js +0 -100
- package/src/atlaspack-v3/worker/compat/plugin-logger.js +0 -47
- package/src/atlaspack-v3/worker/worker.js +0 -369
- package/src/index.js +0 -13
- package/src/requests/AssetGraphRequestRust.js +0 -263
- package/src/requests/AtlaspackBuildRequest.js +0 -111
- package/src/requests/WriteBundleRequest.js +0 -369
- package/src/types.js +0 -600
- package/test/Environment.test.js +0 -119
- package/test/PackagerRunner.test.js +0 -27
- package/test/PublicEnvironment.test.js +0 -27
- package/test/requests/AssetGraphRequestRust.test.js +0 -411
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = createValidationRequest;
|
|
7
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
8
|
+
const AtlaspackConfig_1 = require("../AtlaspackConfig");
|
|
9
|
+
const ReporterRunner_1 = require("../ReporterRunner");
|
|
10
|
+
const Validation_1 = __importDefault(require("../Validation"));
|
|
11
|
+
const AtlaspackConfigRequest_1 = __importDefault(require("./AtlaspackConfigRequest"));
|
|
12
|
+
const RequestTracker_1 = require("../RequestTracker");
|
|
13
|
+
function createValidationRequest(input) {
|
|
14
|
+
return {
|
|
15
|
+
id: 'validation',
|
|
16
|
+
type: RequestTracker_1.requestTypes.validation_request,
|
|
17
|
+
run: async ({ input: { assetRequests, optionsRef }, api, options, farm }) => {
|
|
18
|
+
let { config: processedConfig, cachePath } = (0, nullthrows_1.default)(await api.runRequest((0, AtlaspackConfigRequest_1.default)()));
|
|
19
|
+
let config = new AtlaspackConfig_1.AtlaspackConfig(processedConfig, options);
|
|
20
|
+
let trackedRequestsDesc = assetRequests.filter((request) => {
|
|
21
|
+
// @ts-expect-error TS2345
|
|
22
|
+
return config.getValidatorNames(request.filePath).length > 0;
|
|
23
|
+
});
|
|
24
|
+
// Schedule validations on workers for all plugins that implement the one-asset-at-a-time "validate" method.
|
|
25
|
+
let promises = trackedRequestsDesc.map(async (request) => (await farm.createHandle('runValidate'))({
|
|
26
|
+
requests: [request],
|
|
27
|
+
optionsRef: optionsRef,
|
|
28
|
+
configCachePath: cachePath,
|
|
29
|
+
}));
|
|
30
|
+
// Skip sending validation requests if no validators were configured
|
|
31
|
+
if (trackedRequestsDesc.length === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Schedule validations on the main thread for all validation plugins that implement "validateAll".
|
|
35
|
+
promises.push(
|
|
36
|
+
// @ts-expect-error TS2345
|
|
37
|
+
new Validation_1.default({
|
|
38
|
+
requests: trackedRequestsDesc,
|
|
39
|
+
options,
|
|
40
|
+
config,
|
|
41
|
+
// @ts-expect-error TS2322
|
|
42
|
+
report: ReporterRunner_1.report,
|
|
43
|
+
dedicatedThread: true,
|
|
44
|
+
}).run());
|
|
45
|
+
await Promise.all(promises);
|
|
46
|
+
},
|
|
47
|
+
input,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.SourceMapHashRefRewriteStream = void 0;
|
|
40
|
+
exports.default = createWriteBundleRequest;
|
|
41
|
+
exports.applyReplacementsToSourceMap = applyReplacementsToSourceMap;
|
|
42
|
+
exports.applyReplacementsToVLQMappings = applyReplacementsToVLQMappings;
|
|
43
|
+
exports.computeSourceMapRoot = computeSourceMapRoot;
|
|
44
|
+
const constants_1 = require("../constants");
|
|
45
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
46
|
+
const path_1 = __importDefault(require("path"));
|
|
47
|
+
const url_1 = __importDefault(require("url"));
|
|
48
|
+
const Bundle_1 = require("../public/Bundle");
|
|
49
|
+
const utils_1 = require("@atlaspack/utils");
|
|
50
|
+
const stream_1 = require("stream");
|
|
51
|
+
const projectPath_1 = require("../projectPath");
|
|
52
|
+
const AtlaspackConfigRequest_1 = __importStar(require("./AtlaspackConfigRequest"));
|
|
53
|
+
const PluginOptions_1 = __importDefault(require("../public/PluginOptions"));
|
|
54
|
+
const logger_1 = require("@atlaspack/logger");
|
|
55
|
+
const DevDepRequest_1 = require("./DevDepRequest");
|
|
56
|
+
const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
|
|
57
|
+
const profiler_1 = require("@atlaspack/profiler");
|
|
58
|
+
const RequestTracker_1 = require("../RequestTracker");
|
|
59
|
+
const feature_flags_1 = require("@atlaspack/feature-flags");
|
|
60
|
+
const EnvironmentManager_1 = require("../EnvironmentManager");
|
|
61
|
+
const source_map_1 = require("@atlaspack/source-map");
|
|
62
|
+
const HASH_REF_PREFIX_LEN = constants_1.HASH_REF_PREFIX.length;
|
|
63
|
+
const BOUNDARY_LENGTH = constants_1.HASH_REF_PREFIX.length + 32 - 1;
|
|
64
|
+
const HASH_REF_PLACEHOLDER_LEN = HASH_REF_PREFIX_LEN + constants_1.HASH_REF_HASH_LEN;
|
|
65
|
+
// The JSON key prefix we scan for in the source map stream.
|
|
66
|
+
const MAPPINGS_KEY_BUF = Buffer.from('"mappings":"');
|
|
67
|
+
/**
|
|
68
|
+
* Writes a bundle to the dist directory, replacing hash references with the final content hashes.
|
|
69
|
+
*/
|
|
70
|
+
function createWriteBundleRequest(input) {
|
|
71
|
+
let name = (0, nullthrows_1.default)(input.bundle.name);
|
|
72
|
+
let nameHash = (0, nullthrows_1.default)(input.hashRefToNameHash.get(input.bundle.hashReference));
|
|
73
|
+
return {
|
|
74
|
+
id: `${input.bundle.id}:${input.info.hash}:${nameHash}:${name}`,
|
|
75
|
+
type: RequestTracker_1.requestTypes.write_bundle_request,
|
|
76
|
+
run,
|
|
77
|
+
input,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// @ts-expect-error TS7031
|
|
81
|
+
async function run({ input, options, api }) {
|
|
82
|
+
let { bundleGraph, bundle, info, hashRefToNameHash } = input;
|
|
83
|
+
let { inputFS, outputFS } = options;
|
|
84
|
+
let name = (0, nullthrows_1.default)(bundle.name);
|
|
85
|
+
let thisHashReference = bundle.hashReference;
|
|
86
|
+
if (info.type !== bundle.type) {
|
|
87
|
+
name = name.slice(0, -path_1.default.extname(name).length) + '.' + info.type;
|
|
88
|
+
}
|
|
89
|
+
if (name.includes(thisHashReference)) {
|
|
90
|
+
let thisNameHash = (0, nullthrows_1.default)(hashRefToNameHash.get(thisHashReference));
|
|
91
|
+
name = name.replace(thisHashReference, thisNameHash);
|
|
92
|
+
}
|
|
93
|
+
let filePath = (0, projectPath_1.joinProjectPath)(bundle.target.distDir, name);
|
|
94
|
+
// Watch the bundle and source map for deletion.
|
|
95
|
+
// Also watch the dist dir because invalidateOnFileDelete does not currently
|
|
96
|
+
// invalidate when a parent directory is deleted.
|
|
97
|
+
// TODO: do we want to also watch for file edits?
|
|
98
|
+
api.invalidateOnFileDelete(bundle.target.distDir);
|
|
99
|
+
api.invalidateOnFileDelete(filePath);
|
|
100
|
+
let cacheKeys = info.cacheKeys;
|
|
101
|
+
let mapKey = cacheKeys.map;
|
|
102
|
+
let fullPath = (0, projectPath_1.fromProjectPath)(options.projectRoot, filePath);
|
|
103
|
+
const env = (0, EnvironmentManager_1.fromEnvironmentId)(bundle.env);
|
|
104
|
+
if (mapKey && env.sourceMap && !env.sourceMap.inline) {
|
|
105
|
+
api.invalidateOnFileDelete((0, projectPath_1.toProjectPath)(options.projectRoot, fullPath + '.map'));
|
|
106
|
+
}
|
|
107
|
+
let dir = path_1.default.dirname(fullPath);
|
|
108
|
+
await outputFS.mkdirp(dir); // ? Got rid of dist exists, is this an expensive operation
|
|
109
|
+
// Use the file mode from the entry asset as the file mode for the bundle.
|
|
110
|
+
// Don't do this for browser builds, as the executable bit in particular is unnecessary.
|
|
111
|
+
let publicBundle = Bundle_1.NamedBundle.get(bundle, bundleGraph, options);
|
|
112
|
+
let mainEntry = publicBundle.getMainEntry();
|
|
113
|
+
let writeOptions = publicBundle.env.isBrowser() || !mainEntry
|
|
114
|
+
? undefined
|
|
115
|
+
: {
|
|
116
|
+
mode: (await inputFS.stat(mainEntry.filePath)).mode,
|
|
117
|
+
};
|
|
118
|
+
let contentStream;
|
|
119
|
+
if (info.isLargeBlob) {
|
|
120
|
+
contentStream = options.cache.getStream(cacheKeys.content);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
contentStream = (0, utils_1.blobToStream)(await options.cache.getBlob(cacheKeys.content));
|
|
124
|
+
}
|
|
125
|
+
let size = 0;
|
|
126
|
+
contentStream = contentStream.pipe(
|
|
127
|
+
// @ts-expect-error TS2554
|
|
128
|
+
new utils_1.TapStream((buf) => {
|
|
129
|
+
size += buf.length;
|
|
130
|
+
}));
|
|
131
|
+
let configResult = (0, nullthrows_1.default)(
|
|
132
|
+
// @ts-expect-error TS2347
|
|
133
|
+
await api.runRequest((0, AtlaspackConfigRequest_1.default)()));
|
|
134
|
+
let config = (0, AtlaspackConfigRequest_1.getCachedAtlaspackConfig)(configResult, options);
|
|
135
|
+
let { devDeps, invalidDevDeps } = await (0, DevDepRequest_1.getDevDepRequests)(api);
|
|
136
|
+
(0, DevDepRequest_1.invalidateDevDeps)(invalidDevDeps, options, config);
|
|
137
|
+
const bundleReplacements = (0, feature_flags_1.getFeatureFlag)('fixSourceMapHashRefs')
|
|
138
|
+
? []
|
|
139
|
+
: undefined;
|
|
140
|
+
await writeFiles(contentStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements);
|
|
141
|
+
const hasSourceMap = await options.cache.has(mapKey);
|
|
142
|
+
if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
|
|
143
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
144
|
+
let mapStream;
|
|
145
|
+
if ((0, feature_flags_1.getFeatureFlag)('fixSourceMapHashRefs') &&
|
|
146
|
+
bundleReplacements &&
|
|
147
|
+
bundleReplacements.length > 0) {
|
|
148
|
+
mapStream = (0, utils_1.blobToStream)(mapEntry).pipe(new SourceMapHashRefRewriteStream(bundleReplacements));
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
mapStream = (0, utils_1.blobToStream)(mapEntry);
|
|
152
|
+
}
|
|
153
|
+
await writeFiles(mapStream, info, hashRefToNameHash, options, config, outputFS, (0, projectPath_1.toProjectPathUnsafe)((0, projectPath_1.fromProjectPathRelative)(filePath) + '.map'), writeOptions, devDeps, api);
|
|
154
|
+
}
|
|
155
|
+
let res = {
|
|
156
|
+
filePath,
|
|
157
|
+
bundleId: bundle.id,
|
|
158
|
+
type: info.type,
|
|
159
|
+
stats: {
|
|
160
|
+
size,
|
|
161
|
+
time: info.time ?? 0,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
api.storeResult(res);
|
|
165
|
+
return res;
|
|
166
|
+
}
|
|
167
|
+
function applyReplacementsToSourceMap(sourceMap, replacements) {
|
|
168
|
+
if (replacements.length === 0)
|
|
169
|
+
return;
|
|
170
|
+
const sorted = [...replacements].sort((a, b) => a.line - b.line || a.column - b.column);
|
|
171
|
+
for (const r of sorted) {
|
|
172
|
+
const delta = r.newLength - r.originalLength;
|
|
173
|
+
if (delta !== 0) {
|
|
174
|
+
// r.column is in post-replacement coordinates (matching the already-shifted
|
|
175
|
+
// source map state after previous offsetColumns calls). The end of the
|
|
176
|
+
// placeholder in these coordinates is simply r.column + r.originalLength.
|
|
177
|
+
const offsetStartColumn = r.column + r.originalLength;
|
|
178
|
+
const line1Based = r.line + 1;
|
|
179
|
+
if (line1Based >= 1 && offsetStartColumn + delta >= 0) {
|
|
180
|
+
sourceMap.offsetColumns(line1Based, offsetStartColumn, delta);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Applies hash-ref replacement column offsets directly to a VLQ mappings
|
|
187
|
+
* string without deserializing the full source map into a native struct.
|
|
188
|
+
*
|
|
189
|
+
* Each replacement r describes a hash-ref that was substituted in the output
|
|
190
|
+
* file. r.column is in the progressively-shifted post-replacement coordinate
|
|
191
|
+
* space (matching the already-shifted source map state after all previous
|
|
192
|
+
* offsetColumns calls), so thresholds are applied sequentially against the
|
|
193
|
+
* running absCol values exactly as the native offsetColumns implementation does.
|
|
194
|
+
*/
|
|
195
|
+
function applyReplacementsToVLQMappings(mappings, replacements) {
|
|
196
|
+
if (replacements.length === 0)
|
|
197
|
+
return mappings;
|
|
198
|
+
// Group replacements by line (0-indexed), sorted by column ascending.
|
|
199
|
+
const byLine = new Map();
|
|
200
|
+
for (const r of replacements) {
|
|
201
|
+
let arr = byLine.get(r.line);
|
|
202
|
+
if (!arr) {
|
|
203
|
+
arr = [];
|
|
204
|
+
byLine.set(r.line, arr);
|
|
205
|
+
}
|
|
206
|
+
arr.push(r);
|
|
207
|
+
}
|
|
208
|
+
for (const arr of byLine.values()) {
|
|
209
|
+
arr.sort((a, b) => a.column - b.column);
|
|
210
|
+
}
|
|
211
|
+
const lines = mappings.split(';');
|
|
212
|
+
const resultLines = [];
|
|
213
|
+
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
214
|
+
const lineReps = byLine.get(lineIdx);
|
|
215
|
+
if (!lineReps || lineReps.length === 0) {
|
|
216
|
+
resultLines.push(lines[lineIdx]);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const line = lines[lineIdx];
|
|
220
|
+
if (!line) {
|
|
221
|
+
resultLines.push('');
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
// Decode segment column deltas to absolute columns.
|
|
225
|
+
const segments = line.split(',');
|
|
226
|
+
const colVlqEnds = [];
|
|
227
|
+
const absCols = [];
|
|
228
|
+
let absCol = 0;
|
|
229
|
+
for (const seg of segments) {
|
|
230
|
+
const { value: colDelta, nextPos } = (0, source_map_1.decodeVLQ)(seg, 0);
|
|
231
|
+
absCol += colDelta;
|
|
232
|
+
colVlqEnds.push(nextPos);
|
|
233
|
+
absCols.push(absCol);
|
|
234
|
+
}
|
|
235
|
+
// Apply each replacement's column shift sequentially against the
|
|
236
|
+
// current absCol values (which have already been adjusted by previous
|
|
237
|
+
// replacements on this line), mirroring the sequential offsetColumns calls.
|
|
238
|
+
for (const r of lineReps) {
|
|
239
|
+
const delta = r.newLength - r.originalLength;
|
|
240
|
+
if (delta === 0)
|
|
241
|
+
continue;
|
|
242
|
+
const threshold = r.column + r.originalLength;
|
|
243
|
+
for (let i = 0; i < absCols.length; i++) {
|
|
244
|
+
if (absCols[i] >= threshold) {
|
|
245
|
+
absCols[i] += delta;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// Re-encode with updated absolute columns; only the leading column VLQ
|
|
250
|
+
// field of each segment changes – the tail bytes are sliced unchanged.
|
|
251
|
+
const resultSegments = [];
|
|
252
|
+
let prevAbsCol = 0;
|
|
253
|
+
for (let i = 0; i < segments.length; i++) {
|
|
254
|
+
const newDelta = absCols[i] - prevAbsCol;
|
|
255
|
+
prevAbsCol = absCols[i];
|
|
256
|
+
resultSegments.push((0, source_map_1.encodeVLQ)(newDelta) + segments[i].slice(colVlqEnds[i]));
|
|
257
|
+
}
|
|
258
|
+
resultLines.push(resultSegments.join(','));
|
|
259
|
+
}
|
|
260
|
+
return resultLines.join(';');
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* A Transform stream that rewrites the "mappings" VLQ field of a source map
|
|
264
|
+
* JSON to account for hash-ref replacements, without ever loading the full
|
|
265
|
+
* JSON object or the native Rust SourceMapInner into memory.
|
|
266
|
+
*
|
|
267
|
+
* Field order in cached source maps (from partialVlqMapToSourceMap / toVLQ):
|
|
268
|
+
* mappings → sources → sourcesContent → names → version → file → sourceRoot
|
|
269
|
+
*
|
|
270
|
+
* "mappings" is the very first field, so we scan only a tiny header before
|
|
271
|
+
* switching to zero-copy passthrough for the bulk sourcesContent bytes.
|
|
272
|
+
*/
|
|
273
|
+
class SourceMapHashRefRewriteStream extends stream_1.Transform {
|
|
274
|
+
constructor(replacements) {
|
|
275
|
+
super();
|
|
276
|
+
this.replacements = replacements;
|
|
277
|
+
this.state = 'scanning';
|
|
278
|
+
this.scanBuf = Buffer.alloc(0);
|
|
279
|
+
this.mappingsBufs = [];
|
|
280
|
+
}
|
|
281
|
+
// @ts-expect-error TS7006
|
|
282
|
+
_transform(chunk, _encoding, cb) {
|
|
283
|
+
if (this.state === 'passthrough') {
|
|
284
|
+
this.push(chunk);
|
|
285
|
+
cb();
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (this.state === 'scanning') {
|
|
289
|
+
const combined = Buffer.concat([this.scanBuf, chunk]);
|
|
290
|
+
const idx = combined.indexOf(MAPPINGS_KEY_BUF);
|
|
291
|
+
if (idx === -1) {
|
|
292
|
+
// Key not yet found – hold back enough bytes to handle a split key.
|
|
293
|
+
const keepLen = Math.min(combined.length, MAPPINGS_KEY_BUF.length - 1);
|
|
294
|
+
if (combined.length > keepLen) {
|
|
295
|
+
this.push(combined.slice(0, combined.length - keepLen));
|
|
296
|
+
}
|
|
297
|
+
this.scanBuf = combined.slice(combined.length - keepLen);
|
|
298
|
+
cb();
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
// Emit everything up to and including the key.
|
|
302
|
+
const keyEnd = idx + MAPPINGS_KEY_BUF.length;
|
|
303
|
+
this.push(combined.slice(0, keyEnd));
|
|
304
|
+
this.scanBuf = Buffer.alloc(0);
|
|
305
|
+
this.state = 'buffering';
|
|
306
|
+
this._bufferingTransform(combined.slice(keyEnd), cb);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
// state === 'buffering'
|
|
310
|
+
this._bufferingTransform(chunk, cb);
|
|
311
|
+
}
|
|
312
|
+
// @ts-expect-error TS7006
|
|
313
|
+
_bufferingTransform(chunk, cb) {
|
|
314
|
+
// Mappings values contain only base64 chars, ';', and ',' – no escaping –
|
|
315
|
+
// so scanning for the closing '"' (0x22) is safe.
|
|
316
|
+
const closeIdx = chunk.indexOf(0x22);
|
|
317
|
+
if (closeIdx === -1) {
|
|
318
|
+
this.mappingsBufs.push(chunk);
|
|
319
|
+
cb();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
this.mappingsBufs.push(chunk.slice(0, closeIdx));
|
|
323
|
+
// VLQ chars are all ASCII (<128), so latin1 round-trips without loss.
|
|
324
|
+
const mappingsStr = Buffer.concat(this.mappingsBufs).toString('latin1');
|
|
325
|
+
const rewritten = applyReplacementsToVLQMappings(mappingsStr, this.replacements);
|
|
326
|
+
this.push(Buffer.from(rewritten, 'latin1'));
|
|
327
|
+
// Emit the closing '"' and everything remaining in one push.
|
|
328
|
+
this.push(chunk.slice(closeIdx));
|
|
329
|
+
this.state = 'passthrough';
|
|
330
|
+
this.mappingsBufs = [];
|
|
331
|
+
cb();
|
|
332
|
+
}
|
|
333
|
+
// @ts-expect-error TS7006
|
|
334
|
+
_flush(cb) {
|
|
335
|
+
if (this.state === 'scanning' && this.scanBuf.length > 0) {
|
|
336
|
+
this.push(this.scanBuf);
|
|
337
|
+
}
|
|
338
|
+
else if (this.state === 'buffering') {
|
|
339
|
+
// Malformed JSON – flush whatever we buffered as-is.
|
|
340
|
+
this.push(Buffer.concat(this.mappingsBufs));
|
|
341
|
+
}
|
|
342
|
+
cb();
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
exports.SourceMapHashRefRewriteStream = SourceMapHashRefRewriteStream;
|
|
346
|
+
/**
|
|
347
|
+
* Computes the sourceRoot for a source map file. This is the relative path from
|
|
348
|
+
* the output directory back to the project root, so that source paths (stored
|
|
349
|
+
* relative to projectRoot) resolve correctly from the .map file location.
|
|
350
|
+
*
|
|
351
|
+
* Returns undefined when sources are inlined (inlineSources), since the browser
|
|
352
|
+
* doesn't need to fetch them and sourceRoot would be unnecessary.
|
|
353
|
+
*
|
|
354
|
+
* This logic must stay in sync with PackagerRunner.generateSourceMap.
|
|
355
|
+
*/
|
|
356
|
+
function computeSourceMapRoot(bundle, options) {
|
|
357
|
+
let name = (0, nullthrows_1.default)(bundle.name);
|
|
358
|
+
let filePath = (0, projectPath_1.joinProjectPath)(bundle.target.distDir, name);
|
|
359
|
+
let fullPath = (0, projectPath_1.fromProjectPath)(options.projectRoot, filePath);
|
|
360
|
+
let sourceRoot = path_1.default.relative(path_1.default.dirname(fullPath), options.projectRoot);
|
|
361
|
+
let inlineSources = false;
|
|
362
|
+
const bundleEnv = (0, EnvironmentManager_1.fromEnvironmentId)(bundle.env);
|
|
363
|
+
if (bundle.target) {
|
|
364
|
+
const bundleTargetEnv = (0, EnvironmentManager_1.fromEnvironmentId)(bundle.target.env);
|
|
365
|
+
if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
|
|
366
|
+
sourceRoot = bundleEnv.sourceMap.sourceRoot;
|
|
367
|
+
}
|
|
368
|
+
else if (options.serveOptions && bundleTargetEnv.context === 'browser') {
|
|
369
|
+
sourceRoot = '/__parcel_source_root';
|
|
370
|
+
}
|
|
371
|
+
if (bundleEnv.sourceMap &&
|
|
372
|
+
bundleEnv.sourceMap.inlineSources !== undefined) {
|
|
373
|
+
inlineSources = bundleEnv.sourceMap.inlineSources;
|
|
374
|
+
}
|
|
375
|
+
else if (bundleTargetEnv.context !== 'node') {
|
|
376
|
+
inlineSources = options.mode === 'production';
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
|
|
380
|
+
if ((0, feature_flags_1.getFeatureFlag)('omitSourcesContentInMemory') && !isInlineMap) {
|
|
381
|
+
if (!(bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources === false)) {
|
|
382
|
+
inlineSources = true;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (inlineSources) {
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
return url_1.default.format(url_1.default.parse(sourceRoot + '/'));
|
|
389
|
+
}
|
|
390
|
+
async function writeFiles(
|
|
391
|
+
// @ts-expect-error TS2503
|
|
392
|
+
inputStream, info, hashRefToNameHash, options, config, outputFS, filePath, writeOptions, devDeps, api, bundleReplacements) {
|
|
393
|
+
let compressors = await config.getCompressors((0, projectPath_1.fromProjectPathRelative)(filePath));
|
|
394
|
+
let fullPath = (0, projectPath_1.fromProjectPath)(options.projectRoot, filePath);
|
|
395
|
+
let stream = info.hashReferences.length
|
|
396
|
+
? inputStream.pipe(replaceStream(hashRefToNameHash, bundleReplacements))
|
|
397
|
+
: inputStream;
|
|
398
|
+
let promises = [];
|
|
399
|
+
for (let compressor of compressors) {
|
|
400
|
+
promises.push(
|
|
401
|
+
// @ts-expect-error TS2345
|
|
402
|
+
runCompressor(compressor, cloneStream(stream), options, outputFS, fullPath, writeOptions, devDeps, api));
|
|
403
|
+
}
|
|
404
|
+
await Promise.all(promises);
|
|
405
|
+
}
|
|
406
|
+
async function runCompressor(compressor,
|
|
407
|
+
// @ts-expect-error TS2503
|
|
408
|
+
stream, options, outputFS, filePath, writeOptions, devDeps, api) {
|
|
409
|
+
let measurement;
|
|
410
|
+
try {
|
|
411
|
+
measurement = profiler_1.tracer.createMeasurement(compressor.name, 'compress', path_1.default.relative(options.projectRoot, filePath));
|
|
412
|
+
let res = await compressor.plugin.compress({
|
|
413
|
+
stream,
|
|
414
|
+
options: new PluginOptions_1.default(options),
|
|
415
|
+
logger: new logger_1.PluginLogger({ origin: compressor.name }),
|
|
416
|
+
tracer: new profiler_1.PluginTracer({ origin: compressor.name, category: 'compress' }),
|
|
417
|
+
});
|
|
418
|
+
if (res != null) {
|
|
419
|
+
await new Promise((resolve, reject) => (0, stream_1.pipeline)(res.stream, outputFS.createWriteStream(filePath + (res.type != null ? '.' + res.type : ''), writeOptions), (err) => {
|
|
420
|
+
if (err)
|
|
421
|
+
reject(err);
|
|
422
|
+
// @ts-expect-error TS2794
|
|
423
|
+
else
|
|
424
|
+
resolve();
|
|
425
|
+
}));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
catch (err) {
|
|
429
|
+
throw new diagnostic_1.default({
|
|
430
|
+
diagnostic: (0, diagnostic_1.errorToDiagnostic)(err, {
|
|
431
|
+
origin: compressor.name,
|
|
432
|
+
}),
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
finally {
|
|
436
|
+
measurement && measurement.end();
|
|
437
|
+
// Add dev deps for compressor plugins AFTER running them, to account for lazy require().
|
|
438
|
+
let devDepRequest = await (0, DevDepRequest_1.createDevDependency)({
|
|
439
|
+
specifier: compressor.name,
|
|
440
|
+
resolveFrom: compressor.resolveFrom,
|
|
441
|
+
}, devDeps, options);
|
|
442
|
+
await (0, DevDepRequest_1.runDevDepRequest)(api, devDepRequest);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function advanceLineColumn(line, column, buf) {
|
|
446
|
+
for (let i = 0; i < buf.length; i++) {
|
|
447
|
+
if (buf[i] === 0x0a) {
|
|
448
|
+
line++;
|
|
449
|
+
column = 0;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
column++;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return { line, column };
|
|
456
|
+
}
|
|
457
|
+
function replaceStream(hashRefToNameHash, replacements) {
|
|
458
|
+
let boundaryStr = Buffer.alloc(0);
|
|
459
|
+
let replaced = Buffer.alloc(0);
|
|
460
|
+
let outputLine = 0;
|
|
461
|
+
let outputColumn = 0;
|
|
462
|
+
return new stream_1.Transform({
|
|
463
|
+
transform(chunk, encoding, cb) {
|
|
464
|
+
let str = Buffer.concat([boundaryStr, Buffer.from(chunk)]);
|
|
465
|
+
let lastMatchI = 0;
|
|
466
|
+
if (replaced.length < str.byteLength) {
|
|
467
|
+
replaced = Buffer.alloc(str.byteLength);
|
|
468
|
+
}
|
|
469
|
+
let replacedLength = 0;
|
|
470
|
+
while (lastMatchI < str.byteLength) {
|
|
471
|
+
let matchI = str.indexOf(constants_1.HASH_REF_PREFIX, lastMatchI);
|
|
472
|
+
if (matchI === -1) {
|
|
473
|
+
replaced.set(str.subarray(lastMatchI, str.byteLength), replacedLength);
|
|
474
|
+
replacedLength += str.byteLength - lastMatchI;
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
let match = str
|
|
479
|
+
.subarray(matchI, matchI + HASH_REF_PREFIX_LEN + constants_1.HASH_REF_HASH_LEN)
|
|
480
|
+
.toString();
|
|
481
|
+
let replacement = Buffer.from(hashRefToNameHash.get(match) ?? match);
|
|
482
|
+
// Copy pre-match content FIRST so position calculation includes it
|
|
483
|
+
replaced.set(str.subarray(lastMatchI, matchI), replacedLength);
|
|
484
|
+
replacedLength += matchI - lastMatchI;
|
|
485
|
+
if (replacements) {
|
|
486
|
+
const pos = advanceLineColumn(outputLine, outputColumn, replaced.subarray(0, replacedLength));
|
|
487
|
+
replacements.push({
|
|
488
|
+
line: pos.line,
|
|
489
|
+
column: pos.column,
|
|
490
|
+
originalLength: HASH_REF_PLACEHOLDER_LEN,
|
|
491
|
+
newLength: replacement.byteLength,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
replaced.set(replacement, replacedLength);
|
|
495
|
+
replacedLength += replacement.byteLength;
|
|
496
|
+
lastMatchI = matchI + HASH_REF_PREFIX_LEN + constants_1.HASH_REF_HASH_LEN;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const pushLen = replacedLength - BOUNDARY_LENGTH;
|
|
500
|
+
const pushed = advanceLineColumn(outputLine, outputColumn, replaced.subarray(0, pushLen));
|
|
501
|
+
outputLine = pushed.line;
|
|
502
|
+
outputColumn = pushed.column;
|
|
503
|
+
boundaryStr = replaced.subarray(replacedLength - BOUNDARY_LENGTH, replacedLength);
|
|
504
|
+
let strUpToBoundary = replaced.subarray(0, pushLen);
|
|
505
|
+
cb(null, strUpToBoundary);
|
|
506
|
+
},
|
|
507
|
+
flush(cb) {
|
|
508
|
+
cb(null, boundaryStr);
|
|
509
|
+
},
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
// @ts-expect-error TS2503
|
|
513
|
+
function cloneStream(readable) {
|
|
514
|
+
let res = new stream_1.Readable();
|
|
515
|
+
res._read = () => { };
|
|
516
|
+
// @ts-expect-error TS7006
|
|
517
|
+
readable.on('data', (chunk) => res.push(chunk));
|
|
518
|
+
readable.on('end', () => res.push(null));
|
|
519
|
+
// @ts-expect-error TS7006
|
|
520
|
+
readable.on('error', (err) => res.emit('error', err));
|
|
521
|
+
return res;
|
|
522
|
+
}
|