@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,734 @@
|
|
|
1
|
+
import type {FileSystem, FileOptions} from '@atlaspack/fs';
|
|
2
|
+
import type {ContentKey} from '@atlaspack/graph';
|
|
3
|
+
import type {Async, FilePath, Compressor} from '@atlaspack/types';
|
|
4
|
+
|
|
5
|
+
import type {RunAPI, StaticRunOpts} from '../RequestTracker';
|
|
6
|
+
import type {Bundle, PackagedBundleInfo, AtlaspackOptions} from '../types';
|
|
7
|
+
import type BundleGraph from '../BundleGraph';
|
|
8
|
+
import type {BundleInfo} from '../PackagerRunner';
|
|
9
|
+
import type {ConfigAndCachePath} from './AtlaspackConfigRequest';
|
|
10
|
+
import type {LoadedPlugin} from '../AtlaspackConfig';
|
|
11
|
+
import type {ProjectPath} from '../projectPath';
|
|
12
|
+
|
|
13
|
+
import {HASH_REF_HASH_LEN, HASH_REF_PREFIX} from '../constants';
|
|
14
|
+
import nullthrows from 'nullthrows';
|
|
15
|
+
import path from 'path';
|
|
16
|
+
import url from 'url';
|
|
17
|
+
import {NamedBundle} from '../public/Bundle';
|
|
18
|
+
import {blobToStream, TapStream} from '@atlaspack/utils';
|
|
19
|
+
import {Readable, Transform, pipeline} from 'stream';
|
|
20
|
+
import {
|
|
21
|
+
fromProjectPath,
|
|
22
|
+
fromProjectPathRelative,
|
|
23
|
+
toProjectPath,
|
|
24
|
+
joinProjectPath,
|
|
25
|
+
toProjectPathUnsafe,
|
|
26
|
+
} from '../projectPath';
|
|
27
|
+
import createAtlaspackConfigRequest, {
|
|
28
|
+
getCachedAtlaspackConfig,
|
|
29
|
+
} from './AtlaspackConfigRequest';
|
|
30
|
+
import PluginOptions from '../public/PluginOptions';
|
|
31
|
+
import {PluginLogger} from '@atlaspack/logger';
|
|
32
|
+
import {
|
|
33
|
+
getDevDepRequests,
|
|
34
|
+
invalidateDevDeps,
|
|
35
|
+
createDevDependency,
|
|
36
|
+
runDevDepRequest,
|
|
37
|
+
} from './DevDepRequest';
|
|
38
|
+
import {AtlaspackConfig} from '../AtlaspackConfig';
|
|
39
|
+
import ThrowableDiagnostic, {errorToDiagnostic} from '@atlaspack/diagnostic';
|
|
40
|
+
import {PluginTracer, tracer} from '@atlaspack/profiler';
|
|
41
|
+
import {requestTypes} from '../RequestTracker';
|
|
42
|
+
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
43
|
+
import {fromEnvironmentId} from '../EnvironmentManager';
|
|
44
|
+
import SourceMap, {decodeVLQ, encodeVLQ} from '@atlaspack/source-map';
|
|
45
|
+
|
|
46
|
+
const HASH_REF_PREFIX_LEN = HASH_REF_PREFIX.length;
|
|
47
|
+
const BOUNDARY_LENGTH = HASH_REF_PREFIX.length + 32 - 1;
|
|
48
|
+
const HASH_REF_PLACEHOLDER_LEN = HASH_REF_PREFIX_LEN + HASH_REF_HASH_LEN;
|
|
49
|
+
|
|
50
|
+
// The JSON key prefix we scan for in the source map stream.
|
|
51
|
+
const MAPPINGS_KEY_BUF = Buffer.from('"mappings":"');
|
|
52
|
+
|
|
53
|
+
export type HashRefReplacement = {
|
|
54
|
+
line: number;
|
|
55
|
+
column: number;
|
|
56
|
+
originalLength: number;
|
|
57
|
+
newLength: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type WriteBundleRequestInput = {
|
|
61
|
+
bundleGraph: BundleGraph;
|
|
62
|
+
bundle: Bundle;
|
|
63
|
+
info: BundleInfo;
|
|
64
|
+
hashRefToNameHash: Map<string, string>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type WriteBundleRequestResult = PackagedBundleInfo;
|
|
68
|
+
|
|
69
|
+
type RunInput<TResult> = {
|
|
70
|
+
input: WriteBundleRequestInput;
|
|
71
|
+
} & StaticRunOpts<TResult>;
|
|
72
|
+
|
|
73
|
+
export type WriteBundleRequest = {
|
|
74
|
+
id: ContentKey;
|
|
75
|
+
readonly type: typeof requestTypes.write_bundle_request;
|
|
76
|
+
run: (arg1: RunInput<PackagedBundleInfo>) => Async<PackagedBundleInfo>;
|
|
77
|
+
input: WriteBundleRequestInput;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Writes a bundle to the dist directory, replacing hash references with the final content hashes.
|
|
82
|
+
*/
|
|
83
|
+
export default function createWriteBundleRequest(
|
|
84
|
+
input: WriteBundleRequestInput,
|
|
85
|
+
): WriteBundleRequest {
|
|
86
|
+
let name = nullthrows(input.bundle.name);
|
|
87
|
+
let nameHash = nullthrows(
|
|
88
|
+
input.hashRefToNameHash.get(input.bundle.hashReference),
|
|
89
|
+
);
|
|
90
|
+
return {
|
|
91
|
+
id: `${input.bundle.id}:${input.info.hash}:${nameHash}:${name}`,
|
|
92
|
+
type: requestTypes.write_bundle_request,
|
|
93
|
+
run,
|
|
94
|
+
input,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// @ts-expect-error TS7031
|
|
99
|
+
async function run({input, options, api}) {
|
|
100
|
+
let {bundleGraph, bundle, info, hashRefToNameHash} = input;
|
|
101
|
+
let {inputFS, outputFS} = options;
|
|
102
|
+
let name = nullthrows(bundle.name);
|
|
103
|
+
let thisHashReference = bundle.hashReference;
|
|
104
|
+
|
|
105
|
+
if (info.type !== bundle.type) {
|
|
106
|
+
name = name.slice(0, -path.extname(name).length) + '.' + info.type;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (name.includes(thisHashReference)) {
|
|
110
|
+
let thisNameHash = nullthrows(hashRefToNameHash.get(thisHashReference));
|
|
111
|
+
name = name.replace(thisHashReference, thisNameHash);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let filePath = joinProjectPath(bundle.target.distDir, name);
|
|
115
|
+
|
|
116
|
+
// Watch the bundle and source map for deletion.
|
|
117
|
+
// Also watch the dist dir because invalidateOnFileDelete does not currently
|
|
118
|
+
// invalidate when a parent directory is deleted.
|
|
119
|
+
// TODO: do we want to also watch for file edits?
|
|
120
|
+
api.invalidateOnFileDelete(bundle.target.distDir);
|
|
121
|
+
api.invalidateOnFileDelete(filePath);
|
|
122
|
+
|
|
123
|
+
let cacheKeys = info.cacheKeys;
|
|
124
|
+
let mapKey = cacheKeys.map;
|
|
125
|
+
let fullPath = fromProjectPath(options.projectRoot, filePath);
|
|
126
|
+
const env = fromEnvironmentId(bundle.env);
|
|
127
|
+
|
|
128
|
+
if (mapKey && env.sourceMap && !env.sourceMap.inline) {
|
|
129
|
+
api.invalidateOnFileDelete(
|
|
130
|
+
toProjectPath(options.projectRoot, fullPath + '.map'),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let dir = path.dirname(fullPath);
|
|
135
|
+
await outputFS.mkdirp(dir); // ? Got rid of dist exists, is this an expensive operation
|
|
136
|
+
|
|
137
|
+
// Use the file mode from the entry asset as the file mode for the bundle.
|
|
138
|
+
// Don't do this for browser builds, as the executable bit in particular is unnecessary.
|
|
139
|
+
let publicBundle = NamedBundle.get(bundle, bundleGraph, options);
|
|
140
|
+
let mainEntry = publicBundle.getMainEntry();
|
|
141
|
+
let writeOptions =
|
|
142
|
+
publicBundle.env.isBrowser() || !mainEntry
|
|
143
|
+
? undefined
|
|
144
|
+
: {
|
|
145
|
+
mode: (await inputFS.stat(mainEntry.filePath)).mode,
|
|
146
|
+
};
|
|
147
|
+
let contentStream: Readable;
|
|
148
|
+
if (info.isLargeBlob) {
|
|
149
|
+
contentStream = options.cache.getStream(cacheKeys.content);
|
|
150
|
+
} else {
|
|
151
|
+
contentStream = blobToStream(
|
|
152
|
+
await options.cache.getBlob(cacheKeys.content),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
let size = 0;
|
|
156
|
+
contentStream = contentStream.pipe(
|
|
157
|
+
// @ts-expect-error TS2554
|
|
158
|
+
new TapStream((buf: Buffer) => {
|
|
159
|
+
size += buf.length;
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
let configResult = nullthrows(
|
|
164
|
+
// @ts-expect-error TS2347
|
|
165
|
+
await api.runRequest<null, ConfigAndCachePath>(
|
|
166
|
+
createAtlaspackConfigRequest(),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
let config = getCachedAtlaspackConfig(configResult, options);
|
|
170
|
+
|
|
171
|
+
let {devDeps, invalidDevDeps} = await getDevDepRequests(api);
|
|
172
|
+
invalidateDevDeps(invalidDevDeps, options, config);
|
|
173
|
+
|
|
174
|
+
const bundleReplacements = getFeatureFlag('fixSourceMapHashRefs')
|
|
175
|
+
? []
|
|
176
|
+
: undefined;
|
|
177
|
+
await writeFiles(
|
|
178
|
+
contentStream,
|
|
179
|
+
info,
|
|
180
|
+
hashRefToNameHash,
|
|
181
|
+
options,
|
|
182
|
+
config,
|
|
183
|
+
outputFS,
|
|
184
|
+
filePath,
|
|
185
|
+
writeOptions,
|
|
186
|
+
devDeps,
|
|
187
|
+
api,
|
|
188
|
+
bundleReplacements,
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const hasSourceMap = await options.cache.has(mapKey);
|
|
192
|
+
if (mapKey && env.sourceMap && !env.sourceMap.inline && hasSourceMap) {
|
|
193
|
+
const mapEntry = await options.cache.getBlob(mapKey);
|
|
194
|
+
let mapStream: Readable;
|
|
195
|
+
if (
|
|
196
|
+
getFeatureFlag('fixSourceMapHashRefs') &&
|
|
197
|
+
bundleReplacements &&
|
|
198
|
+
bundleReplacements.length > 0
|
|
199
|
+
) {
|
|
200
|
+
mapStream = blobToStream(mapEntry).pipe(
|
|
201
|
+
new SourceMapHashRefRewriteStream(bundleReplacements),
|
|
202
|
+
);
|
|
203
|
+
} else {
|
|
204
|
+
mapStream = blobToStream(mapEntry);
|
|
205
|
+
}
|
|
206
|
+
await writeFiles(
|
|
207
|
+
mapStream,
|
|
208
|
+
info,
|
|
209
|
+
hashRefToNameHash,
|
|
210
|
+
options,
|
|
211
|
+
config,
|
|
212
|
+
outputFS,
|
|
213
|
+
toProjectPathUnsafe(fromProjectPathRelative(filePath) + '.map'),
|
|
214
|
+
writeOptions,
|
|
215
|
+
devDeps,
|
|
216
|
+
api,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let res = {
|
|
221
|
+
filePath,
|
|
222
|
+
bundleId: bundle.id,
|
|
223
|
+
type: info.type,
|
|
224
|
+
stats: {
|
|
225
|
+
size,
|
|
226
|
+
time: info.time ?? 0,
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
api.storeResult(res);
|
|
231
|
+
return res;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function applyReplacementsToSourceMap(
|
|
235
|
+
sourceMap: SourceMap,
|
|
236
|
+
replacements: HashRefReplacement[],
|
|
237
|
+
): void {
|
|
238
|
+
if (replacements.length === 0) return;
|
|
239
|
+
const sorted = [...replacements].sort(
|
|
240
|
+
(a, b) => a.line - b.line || a.column - b.column,
|
|
241
|
+
);
|
|
242
|
+
for (const r of sorted) {
|
|
243
|
+
const delta = r.newLength - r.originalLength;
|
|
244
|
+
if (delta !== 0) {
|
|
245
|
+
// r.column is in post-replacement coordinates (matching the already-shifted
|
|
246
|
+
// source map state after previous offsetColumns calls). The end of the
|
|
247
|
+
// placeholder in these coordinates is simply r.column + r.originalLength.
|
|
248
|
+
const offsetStartColumn = r.column + r.originalLength;
|
|
249
|
+
const line1Based = r.line + 1;
|
|
250
|
+
if (line1Based >= 1 && offsetStartColumn + delta >= 0) {
|
|
251
|
+
sourceMap.offsetColumns(line1Based, offsetStartColumn, delta);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Applies hash-ref replacement column offsets directly to a VLQ mappings
|
|
259
|
+
* string without deserializing the full source map into a native struct.
|
|
260
|
+
*
|
|
261
|
+
* Each replacement r describes a hash-ref that was substituted in the output
|
|
262
|
+
* file. r.column is in the progressively-shifted post-replacement coordinate
|
|
263
|
+
* space (matching the already-shifted source map state after all previous
|
|
264
|
+
* offsetColumns calls), so thresholds are applied sequentially against the
|
|
265
|
+
* running absCol values exactly as the native offsetColumns implementation does.
|
|
266
|
+
*/
|
|
267
|
+
export function applyReplacementsToVLQMappings(
|
|
268
|
+
mappings: string,
|
|
269
|
+
replacements: HashRefReplacement[],
|
|
270
|
+
): string {
|
|
271
|
+
if (replacements.length === 0) return mappings;
|
|
272
|
+
|
|
273
|
+
// Group replacements by line (0-indexed), sorted by column ascending.
|
|
274
|
+
const byLine = new Map<number, HashRefReplacement[]>();
|
|
275
|
+
for (const r of replacements) {
|
|
276
|
+
let arr = byLine.get(r.line);
|
|
277
|
+
if (!arr) {
|
|
278
|
+
arr = [];
|
|
279
|
+
byLine.set(r.line, arr);
|
|
280
|
+
}
|
|
281
|
+
arr.push(r);
|
|
282
|
+
}
|
|
283
|
+
for (const arr of byLine.values()) {
|
|
284
|
+
arr.sort((a, b) => a.column - b.column);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const lines = mappings.split(';');
|
|
288
|
+
const resultLines: string[] = [];
|
|
289
|
+
|
|
290
|
+
for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
|
|
291
|
+
const lineReps = byLine.get(lineIdx);
|
|
292
|
+
if (!lineReps || lineReps.length === 0) {
|
|
293
|
+
resultLines.push(lines[lineIdx]);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const line = lines[lineIdx];
|
|
298
|
+
if (!line) {
|
|
299
|
+
resultLines.push('');
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Decode segment column deltas to absolute columns.
|
|
304
|
+
const segments = line.split(',');
|
|
305
|
+
const colVlqEnds: number[] = [];
|
|
306
|
+
const absCols: number[] = [];
|
|
307
|
+
let absCol = 0;
|
|
308
|
+
for (const seg of segments) {
|
|
309
|
+
const {value: colDelta, nextPos} = decodeVLQ(seg, 0);
|
|
310
|
+
absCol += colDelta;
|
|
311
|
+
colVlqEnds.push(nextPos);
|
|
312
|
+
absCols.push(absCol);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Apply each replacement's column shift sequentially against the
|
|
316
|
+
// current absCol values (which have already been adjusted by previous
|
|
317
|
+
// replacements on this line), mirroring the sequential offsetColumns calls.
|
|
318
|
+
for (const r of lineReps) {
|
|
319
|
+
const delta = r.newLength - r.originalLength;
|
|
320
|
+
if (delta === 0) continue;
|
|
321
|
+
const threshold = r.column + r.originalLength;
|
|
322
|
+
for (let i = 0; i < absCols.length; i++) {
|
|
323
|
+
if (absCols[i] >= threshold) {
|
|
324
|
+
absCols[i] += delta;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Re-encode with updated absolute columns; only the leading column VLQ
|
|
330
|
+
// field of each segment changes – the tail bytes are sliced unchanged.
|
|
331
|
+
const resultSegments: string[] = [];
|
|
332
|
+
let prevAbsCol = 0;
|
|
333
|
+
for (let i = 0; i < segments.length; i++) {
|
|
334
|
+
const newDelta = absCols[i] - prevAbsCol;
|
|
335
|
+
prevAbsCol = absCols[i];
|
|
336
|
+
resultSegments.push(
|
|
337
|
+
encodeVLQ(newDelta) + segments[i].slice(colVlqEnds[i]),
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
resultLines.push(resultSegments.join(','));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return resultLines.join(';');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
type StreamState = 'scanning' | 'buffering' | 'passthrough';
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* A Transform stream that rewrites the "mappings" VLQ field of a source map
|
|
351
|
+
* JSON to account for hash-ref replacements, without ever loading the full
|
|
352
|
+
* JSON object or the native Rust SourceMapInner into memory.
|
|
353
|
+
*
|
|
354
|
+
* Field order in cached source maps (from partialVlqMapToSourceMap / toVLQ):
|
|
355
|
+
* mappings → sources → sourcesContent → names → version → file → sourceRoot
|
|
356
|
+
*
|
|
357
|
+
* "mappings" is the very first field, so we scan only a tiny header before
|
|
358
|
+
* switching to zero-copy passthrough for the bulk sourcesContent bytes.
|
|
359
|
+
*/
|
|
360
|
+
export class SourceMapHashRefRewriteStream extends Transform {
|
|
361
|
+
private replacements: HashRefReplacement[];
|
|
362
|
+
private state: StreamState;
|
|
363
|
+
private scanBuf: Buffer;
|
|
364
|
+
private mappingsBufs: Buffer[];
|
|
365
|
+
|
|
366
|
+
constructor(replacements: HashRefReplacement[]) {
|
|
367
|
+
super();
|
|
368
|
+
this.replacements = replacements;
|
|
369
|
+
this.state = 'scanning';
|
|
370
|
+
this.scanBuf = Buffer.alloc(0);
|
|
371
|
+
this.mappingsBufs = [];
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// @ts-expect-error TS7006
|
|
375
|
+
_transform(chunk: Buffer, _encoding: string, cb): void {
|
|
376
|
+
if (this.state === 'passthrough') {
|
|
377
|
+
this.push(chunk);
|
|
378
|
+
cb();
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (this.state === 'scanning') {
|
|
383
|
+
const combined = Buffer.concat([this.scanBuf, chunk]);
|
|
384
|
+
const idx = combined.indexOf(MAPPINGS_KEY_BUF);
|
|
385
|
+
|
|
386
|
+
if (idx === -1) {
|
|
387
|
+
// Key not yet found – hold back enough bytes to handle a split key.
|
|
388
|
+
const keepLen = Math.min(combined.length, MAPPINGS_KEY_BUF.length - 1);
|
|
389
|
+
if (combined.length > keepLen) {
|
|
390
|
+
this.push(combined.slice(0, combined.length - keepLen));
|
|
391
|
+
}
|
|
392
|
+
this.scanBuf = combined.slice(combined.length - keepLen);
|
|
393
|
+
cb();
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Emit everything up to and including the key.
|
|
398
|
+
const keyEnd = idx + MAPPINGS_KEY_BUF.length;
|
|
399
|
+
this.push(combined.slice(0, keyEnd));
|
|
400
|
+
this.scanBuf = Buffer.alloc(0);
|
|
401
|
+
this.state = 'buffering';
|
|
402
|
+
this._bufferingTransform(combined.slice(keyEnd), cb);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// state === 'buffering'
|
|
407
|
+
this._bufferingTransform(chunk, cb);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// @ts-expect-error TS7006
|
|
411
|
+
private _bufferingTransform(chunk: Buffer, cb): void {
|
|
412
|
+
// Mappings values contain only base64 chars, ';', and ',' – no escaping –
|
|
413
|
+
// so scanning for the closing '"' (0x22) is safe.
|
|
414
|
+
const closeIdx = chunk.indexOf(0x22);
|
|
415
|
+
|
|
416
|
+
if (closeIdx === -1) {
|
|
417
|
+
this.mappingsBufs.push(chunk);
|
|
418
|
+
cb();
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
this.mappingsBufs.push(chunk.slice(0, closeIdx));
|
|
423
|
+
|
|
424
|
+
// VLQ chars are all ASCII (<128), so latin1 round-trips without loss.
|
|
425
|
+
const mappingsStr = Buffer.concat(this.mappingsBufs).toString('latin1');
|
|
426
|
+
const rewritten = applyReplacementsToVLQMappings(
|
|
427
|
+
mappingsStr,
|
|
428
|
+
this.replacements,
|
|
429
|
+
);
|
|
430
|
+
this.push(Buffer.from(rewritten, 'latin1'));
|
|
431
|
+
|
|
432
|
+
// Emit the closing '"' and everything remaining in one push.
|
|
433
|
+
this.push(chunk.slice(closeIdx));
|
|
434
|
+
|
|
435
|
+
this.state = 'passthrough';
|
|
436
|
+
this.mappingsBufs = [];
|
|
437
|
+
cb();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// @ts-expect-error TS7006
|
|
441
|
+
_flush(cb): void {
|
|
442
|
+
if (this.state === 'scanning' && this.scanBuf.length > 0) {
|
|
443
|
+
this.push(this.scanBuf);
|
|
444
|
+
} else if (this.state === 'buffering') {
|
|
445
|
+
// Malformed JSON – flush whatever we buffered as-is.
|
|
446
|
+
this.push(Buffer.concat(this.mappingsBufs));
|
|
447
|
+
}
|
|
448
|
+
cb();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Computes the sourceRoot for a source map file. This is the relative path from
|
|
454
|
+
* the output directory back to the project root, so that source paths (stored
|
|
455
|
+
* relative to projectRoot) resolve correctly from the .map file location.
|
|
456
|
+
*
|
|
457
|
+
* Returns undefined when sources are inlined (inlineSources), since the browser
|
|
458
|
+
* doesn't need to fetch them and sourceRoot would be unnecessary.
|
|
459
|
+
*
|
|
460
|
+
* This logic must stay in sync with PackagerRunner.generateSourceMap.
|
|
461
|
+
*/
|
|
462
|
+
export function computeSourceMapRoot(
|
|
463
|
+
bundle: Bundle,
|
|
464
|
+
options: AtlaspackOptions,
|
|
465
|
+
): string | undefined {
|
|
466
|
+
let name = nullthrows(bundle.name);
|
|
467
|
+
let filePath = joinProjectPath(bundle.target.distDir, name);
|
|
468
|
+
let fullPath = fromProjectPath(options.projectRoot, filePath);
|
|
469
|
+
let sourceRoot: string = path.relative(
|
|
470
|
+
path.dirname(fullPath),
|
|
471
|
+
options.projectRoot,
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
let inlineSources = false;
|
|
475
|
+
|
|
476
|
+
const bundleEnv = fromEnvironmentId(bundle.env);
|
|
477
|
+
if (bundle.target) {
|
|
478
|
+
const bundleTargetEnv = fromEnvironmentId(bundle.target.env);
|
|
479
|
+
|
|
480
|
+
if (bundleEnv.sourceMap && bundleEnv.sourceMap.sourceRoot !== undefined) {
|
|
481
|
+
sourceRoot = bundleEnv.sourceMap.sourceRoot;
|
|
482
|
+
} else if (options.serveOptions && bundleTargetEnv.context === 'browser') {
|
|
483
|
+
sourceRoot = '/__parcel_source_root';
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (
|
|
487
|
+
bundleEnv.sourceMap &&
|
|
488
|
+
bundleEnv.sourceMap.inlineSources !== undefined
|
|
489
|
+
) {
|
|
490
|
+
inlineSources = bundleEnv.sourceMap.inlineSources;
|
|
491
|
+
} else if (bundleTargetEnv.context !== 'node') {
|
|
492
|
+
inlineSources = options.mode === 'production';
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
let isInlineMap = bundleEnv.sourceMap && bundleEnv.sourceMap.inline;
|
|
497
|
+
|
|
498
|
+
if (getFeatureFlag('omitSourcesContentInMemory') && !isInlineMap) {
|
|
499
|
+
if (!(bundleEnv.sourceMap && bundleEnv.sourceMap.inlineSources === false)) {
|
|
500
|
+
inlineSources = true;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (inlineSources) {
|
|
505
|
+
return undefined;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return url.format(url.parse(sourceRoot + '/'));
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
async function writeFiles(
|
|
512
|
+
// @ts-expect-error TS2503
|
|
513
|
+
inputStream: stream.Readable,
|
|
514
|
+
info: BundleInfo,
|
|
515
|
+
hashRefToNameHash: Map<string, string>,
|
|
516
|
+
options: AtlaspackOptions,
|
|
517
|
+
config: AtlaspackConfig,
|
|
518
|
+
outputFS: FileSystem,
|
|
519
|
+
filePath: ProjectPath,
|
|
520
|
+
writeOptions: FileOptions | null | undefined,
|
|
521
|
+
devDeps: Map<string, string>,
|
|
522
|
+
api: RunAPI<PackagedBundleInfo>,
|
|
523
|
+
bundleReplacements?: HashRefReplacement[],
|
|
524
|
+
) {
|
|
525
|
+
let compressors = await config.getCompressors(
|
|
526
|
+
fromProjectPathRelative(filePath),
|
|
527
|
+
);
|
|
528
|
+
let fullPath = fromProjectPath(options.projectRoot, filePath);
|
|
529
|
+
|
|
530
|
+
let stream = info.hashReferences.length
|
|
531
|
+
? inputStream.pipe(replaceStream(hashRefToNameHash, bundleReplacements))
|
|
532
|
+
: inputStream;
|
|
533
|
+
|
|
534
|
+
let promises: Array<Promise<undefined>> = [];
|
|
535
|
+
for (let compressor of compressors) {
|
|
536
|
+
promises.push(
|
|
537
|
+
// @ts-expect-error TS2345
|
|
538
|
+
runCompressor(
|
|
539
|
+
compressor,
|
|
540
|
+
cloneStream(stream),
|
|
541
|
+
options,
|
|
542
|
+
outputFS,
|
|
543
|
+
fullPath,
|
|
544
|
+
writeOptions,
|
|
545
|
+
devDeps,
|
|
546
|
+
api,
|
|
547
|
+
),
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
await Promise.all(promises);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
async function runCompressor(
|
|
555
|
+
compressor: LoadedPlugin<Compressor>,
|
|
556
|
+
// @ts-expect-error TS2503
|
|
557
|
+
stream: stream.Readable,
|
|
558
|
+
options: AtlaspackOptions,
|
|
559
|
+
outputFS: FileSystem,
|
|
560
|
+
filePath: FilePath,
|
|
561
|
+
writeOptions: FileOptions | null | undefined,
|
|
562
|
+
devDeps: Map<string, string>,
|
|
563
|
+
api: RunAPI<PackagedBundleInfo>,
|
|
564
|
+
) {
|
|
565
|
+
let measurement;
|
|
566
|
+
try {
|
|
567
|
+
measurement = tracer.createMeasurement(
|
|
568
|
+
compressor.name,
|
|
569
|
+
'compress',
|
|
570
|
+
path.relative(options.projectRoot, filePath),
|
|
571
|
+
);
|
|
572
|
+
let res = await compressor.plugin.compress({
|
|
573
|
+
stream,
|
|
574
|
+
options: new PluginOptions(options),
|
|
575
|
+
logger: new PluginLogger({origin: compressor.name}),
|
|
576
|
+
tracer: new PluginTracer({origin: compressor.name, category: 'compress'}),
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
if (res != null) {
|
|
580
|
+
await new Promise(
|
|
581
|
+
(
|
|
582
|
+
resolve: (result: Promise<undefined> | undefined) => void,
|
|
583
|
+
reject: (error?: any) => void,
|
|
584
|
+
) =>
|
|
585
|
+
pipeline(
|
|
586
|
+
res.stream,
|
|
587
|
+
outputFS.createWriteStream(
|
|
588
|
+
filePath + (res.type != null ? '.' + res.type : ''),
|
|
589
|
+
writeOptions,
|
|
590
|
+
),
|
|
591
|
+
(err) => {
|
|
592
|
+
if (err) reject(err);
|
|
593
|
+
// @ts-expect-error TS2794
|
|
594
|
+
else resolve();
|
|
595
|
+
},
|
|
596
|
+
),
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
} catch (err: any) {
|
|
600
|
+
throw new ThrowableDiagnostic({
|
|
601
|
+
diagnostic: errorToDiagnostic(err, {
|
|
602
|
+
origin: compressor.name,
|
|
603
|
+
}),
|
|
604
|
+
});
|
|
605
|
+
} finally {
|
|
606
|
+
measurement && measurement.end();
|
|
607
|
+
// Add dev deps for compressor plugins AFTER running them, to account for lazy require().
|
|
608
|
+
let devDepRequest = await createDevDependency(
|
|
609
|
+
{
|
|
610
|
+
specifier: compressor.name,
|
|
611
|
+
resolveFrom: compressor.resolveFrom,
|
|
612
|
+
},
|
|
613
|
+
devDeps,
|
|
614
|
+
options,
|
|
615
|
+
);
|
|
616
|
+
await runDevDepRequest(api, devDepRequest);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function advanceLineColumn(
|
|
621
|
+
line: number,
|
|
622
|
+
column: number,
|
|
623
|
+
buf: Buffer,
|
|
624
|
+
): {line: number; column: number} {
|
|
625
|
+
for (let i = 0; i < buf.length; i++) {
|
|
626
|
+
if (buf[i] === 0x0a) {
|
|
627
|
+
line++;
|
|
628
|
+
column = 0;
|
|
629
|
+
} else {
|
|
630
|
+
column++;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return {line, column};
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function replaceStream(
|
|
637
|
+
hashRefToNameHash: Map<string, string>,
|
|
638
|
+
replacements?: HashRefReplacement[],
|
|
639
|
+
) {
|
|
640
|
+
let boundaryStr = Buffer.alloc(0);
|
|
641
|
+
let replaced = Buffer.alloc(0);
|
|
642
|
+
let outputLine = 0;
|
|
643
|
+
let outputColumn = 0;
|
|
644
|
+
return new Transform({
|
|
645
|
+
transform(
|
|
646
|
+
chunk: Buffer | string,
|
|
647
|
+
encoding: string,
|
|
648
|
+
cb: (
|
|
649
|
+
error?: Error | null | undefined,
|
|
650
|
+
data?: Buffer | string | null | undefined,
|
|
651
|
+
) => void,
|
|
652
|
+
) {
|
|
653
|
+
let str = Buffer.concat([boundaryStr, Buffer.from(chunk)]);
|
|
654
|
+
let lastMatchI = 0;
|
|
655
|
+
if (replaced.length < str.byteLength) {
|
|
656
|
+
replaced = Buffer.alloc(str.byteLength);
|
|
657
|
+
}
|
|
658
|
+
let replacedLength = 0;
|
|
659
|
+
|
|
660
|
+
while (lastMatchI < str.byteLength) {
|
|
661
|
+
let matchI = str.indexOf(HASH_REF_PREFIX, lastMatchI);
|
|
662
|
+
if (matchI === -1) {
|
|
663
|
+
replaced.set(
|
|
664
|
+
str.subarray(lastMatchI, str.byteLength),
|
|
665
|
+
replacedLength,
|
|
666
|
+
);
|
|
667
|
+
replacedLength += str.byteLength - lastMatchI;
|
|
668
|
+
break;
|
|
669
|
+
} else {
|
|
670
|
+
let match = str
|
|
671
|
+
.subarray(matchI, matchI + HASH_REF_PREFIX_LEN + HASH_REF_HASH_LEN)
|
|
672
|
+
.toString();
|
|
673
|
+
let replacement = Buffer.from(hashRefToNameHash.get(match) ?? match);
|
|
674
|
+
// Copy pre-match content FIRST so position calculation includes it
|
|
675
|
+
replaced.set(str.subarray(lastMatchI, matchI), replacedLength);
|
|
676
|
+
replacedLength += matchI - lastMatchI;
|
|
677
|
+
if (replacements) {
|
|
678
|
+
const pos = advanceLineColumn(
|
|
679
|
+
outputLine,
|
|
680
|
+
outputColumn,
|
|
681
|
+
replaced.subarray(0, replacedLength),
|
|
682
|
+
);
|
|
683
|
+
replacements.push({
|
|
684
|
+
line: pos.line,
|
|
685
|
+
column: pos.column,
|
|
686
|
+
originalLength: HASH_REF_PLACEHOLDER_LEN,
|
|
687
|
+
newLength: replacement.byteLength,
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
replaced.set(replacement, replacedLength);
|
|
691
|
+
replacedLength += replacement.byteLength;
|
|
692
|
+
lastMatchI = matchI + HASH_REF_PREFIX_LEN + HASH_REF_HASH_LEN;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const pushLen = replacedLength - BOUNDARY_LENGTH;
|
|
697
|
+
const pushed = advanceLineColumn(
|
|
698
|
+
outputLine,
|
|
699
|
+
outputColumn,
|
|
700
|
+
replaced.subarray(0, pushLen),
|
|
701
|
+
);
|
|
702
|
+
outputLine = pushed.line;
|
|
703
|
+
outputColumn = pushed.column;
|
|
704
|
+
|
|
705
|
+
boundaryStr = replaced.subarray(
|
|
706
|
+
replacedLength - BOUNDARY_LENGTH,
|
|
707
|
+
replacedLength,
|
|
708
|
+
);
|
|
709
|
+
let strUpToBoundary = replaced.subarray(0, pushLen);
|
|
710
|
+
cb(null, strUpToBoundary);
|
|
711
|
+
},
|
|
712
|
+
|
|
713
|
+
flush(
|
|
714
|
+
cb: (
|
|
715
|
+
error?: Error | null | undefined,
|
|
716
|
+
data?: Buffer | string | null | undefined,
|
|
717
|
+
) => void,
|
|
718
|
+
) {
|
|
719
|
+
cb(null, boundaryStr);
|
|
720
|
+
},
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// @ts-expect-error TS2503
|
|
725
|
+
function cloneStream(readable: stream.Readable | stream.Transform) {
|
|
726
|
+
let res = new Readable();
|
|
727
|
+
res._read = () => {};
|
|
728
|
+
// @ts-expect-error TS7006
|
|
729
|
+
readable.on('data', (chunk) => res.push(chunk));
|
|
730
|
+
readable.on('end', () => res.push(null));
|
|
731
|
+
// @ts-expect-error TS7006
|
|
732
|
+
readable.on('error', (err) => res.emit('error', err));
|
|
733
|
+
return res;
|
|
734
|
+
}
|