@atlaspack/core 2.16.2-canary.46 → 2.16.2-canary.460
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 +1280 -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 +1905 -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 +620 -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 +384 -37
- 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 +44 -21
- 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} +570 -142
- 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} +165 -57
- 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
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
GraphVisitor,
|
|
5
3
|
FilePath,
|
|
6
|
-
Symbol,
|
|
7
4
|
TraversalActions,
|
|
8
5
|
BundleBehavior as IBundleBehavior,
|
|
9
6
|
ConditionMeta,
|
|
7
|
+
Symbol,
|
|
10
8
|
} from '@atlaspack/types';
|
|
11
9
|
import type {
|
|
12
10
|
ContentKey,
|
|
@@ -49,6 +47,9 @@ import {ISOLATED_ENVS} from './public/Environment';
|
|
|
49
47
|
import {fromProjectPath, fromProjectPathRelative} from './projectPath';
|
|
50
48
|
import {HASH_REF_PREFIX} from './constants';
|
|
51
49
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
50
|
+
import logger from '@atlaspack/logger';
|
|
51
|
+
import {fromEnvironmentId} from './EnvironmentManager';
|
|
52
|
+
import type {EnvironmentRef} from './EnvironmentManager';
|
|
52
53
|
|
|
53
54
|
export const bundleGraphEdgeTypes = {
|
|
54
55
|
// A lack of an edge type indicates to follow the edge while traversing
|
|
@@ -75,47 +76,47 @@ export const bundleGraphEdgeTypes = {
|
|
|
75
76
|
internal_async: 5,
|
|
76
77
|
// This type is used to mark an edge between a bundle and a conditional bundle.
|
|
77
78
|
// This allows efficient discovery of conditional bundles in packaging
|
|
78
|
-
conditional:
|
|
79
|
+
conditional: 6,
|
|
80
|
+
} as const;
|
|
81
|
+
|
|
82
|
+
export type BundleGraphEdgeType =
|
|
83
|
+
(typeof bundleGraphEdgeTypes)[keyof typeof bundleGraphEdgeTypes];
|
|
84
|
+
|
|
85
|
+
type InternalSymbolResolution = {
|
|
86
|
+
asset: Asset;
|
|
87
|
+
exportSymbol: string;
|
|
88
|
+
symbol: Symbol | null | undefined | false;
|
|
89
|
+
loc: InternalSourceLocation | null | undefined;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
type InternalExportSymbolResolution = InternalSymbolResolution & {
|
|
93
|
+
readonly exportAs: Symbol | string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
type BundleGraphOpts = {
|
|
97
|
+
graph: ContentGraphOpts<BundleGraphNode, BundleGraphEdgeType>;
|
|
98
|
+
bundleContentHashes: Map<string, string>;
|
|
99
|
+
assetPublicIds: Set<string>;
|
|
100
|
+
publicIdByAssetId: Map<string, string>;
|
|
101
|
+
conditions: Map<string, Condition>;
|
|
79
102
|
};
|
|
80
103
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
...InternalSymbolResolution,
|
|
92
|
-
+exportAs: Symbol | string,
|
|
93
|
-
|};
|
|
94
|
-
|
|
95
|
-
type BundleGraphOpts = {|
|
|
96
|
-
graph: ContentGraphOpts<BundleGraphNode, BundleGraphEdgeType>,
|
|
97
|
-
bundleContentHashes: Map<string, string>,
|
|
98
|
-
assetPublicIds: Set<string>,
|
|
99
|
-
publicIdByAssetId: Map<string, string>,
|
|
100
|
-
conditions: Map<string, Condition>,
|
|
101
|
-
|};
|
|
102
|
-
|
|
103
|
-
type SerializedBundleGraph = {|
|
|
104
|
-
$$raw: true,
|
|
105
|
-
graph: SerializedContentGraph<BundleGraphNode, BundleGraphEdgeType>,
|
|
106
|
-
bundleContentHashes: Map<string, string>,
|
|
107
|
-
assetPublicIds: Set<string>,
|
|
108
|
-
publicIdByAssetId: Map<string, string>,
|
|
109
|
-
conditions: Map<string, Condition>,
|
|
110
|
-
|};
|
|
111
|
-
|
|
112
|
-
function makeReadOnlySet<T>(set: Set<T>): $ReadOnlySet<T> {
|
|
104
|
+
type SerializedBundleGraph = {
|
|
105
|
+
$$raw: true;
|
|
106
|
+
graph: SerializedContentGraph<BundleGraphNode, BundleGraphEdgeType>;
|
|
107
|
+
bundleContentHashes: Map<string, string>;
|
|
108
|
+
assetPublicIds: Set<string>;
|
|
109
|
+
publicIdByAssetId: Map<string, string>;
|
|
110
|
+
conditions: Map<string, Condition>;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
function makeReadOnlySet<T>(set: Set<T>): ReadonlySet<T> {
|
|
113
114
|
return new Proxy(set, {
|
|
114
|
-
get(target
|
|
115
|
+
get(target: Set<T>, property: string) {
|
|
115
116
|
if (property === 'delete' || property === 'add' || property === 'clear') {
|
|
116
117
|
return undefined;
|
|
117
118
|
} else {
|
|
118
|
-
//
|
|
119
|
+
// @ts-expect-error TS7053
|
|
119
120
|
let value = target[property];
|
|
120
121
|
return typeof value === 'function' ? value.bind(target) : value;
|
|
121
122
|
}
|
|
@@ -155,13 +156,13 @@ export default class BundleGraph {
|
|
|
155
156
|
assetPublicIds,
|
|
156
157
|
bundleContentHashes,
|
|
157
158
|
conditions,
|
|
158
|
-
}: {
|
|
159
|
-
graph: ContentGraph<BundleGraphNode, BundleGraphEdgeType
|
|
160
|
-
publicIdByAssetId: Map<string, string
|
|
161
|
-
assetPublicIds: Set<string
|
|
162
|
-
bundleContentHashes: Map<string, string
|
|
163
|
-
conditions: Map<string, Condition
|
|
164
|
-
|
|
159
|
+
}: {
|
|
160
|
+
graph: ContentGraph<BundleGraphNode, BundleGraphEdgeType>;
|
|
161
|
+
publicIdByAssetId: Map<string, string>;
|
|
162
|
+
assetPublicIds: Set<string>;
|
|
163
|
+
bundleContentHashes: Map<string, string>;
|
|
164
|
+
conditions: Map<string, Condition>;
|
|
165
|
+
}) {
|
|
165
166
|
this._graph = graph;
|
|
166
167
|
this._assetPublicIds = assetPublicIds;
|
|
167
168
|
this._publicIdByAssetId = publicIdByAssetId;
|
|
@@ -219,8 +220,8 @@ export default class BundleGraph {
|
|
|
219
220
|
// code need to be mapped to the "real" dependencies, so we need access to a map of placeholders
|
|
220
221
|
// to dependencies
|
|
221
222
|
const dep = node.value;
|
|
222
|
-
//
|
|
223
|
-
const placeholder: string |
|
|
223
|
+
// @ts-expect-error TS2322
|
|
224
|
+
const placeholder: string | undefined = dep.meta?.placeholder;
|
|
224
225
|
if (placeholder != null) {
|
|
225
226
|
placeholderToDependency.set(placeholder, dep);
|
|
226
227
|
}
|
|
@@ -228,7 +229,7 @@ export default class BundleGraph {
|
|
|
228
229
|
});
|
|
229
230
|
|
|
230
231
|
let walkVisited = new Set();
|
|
231
|
-
function walk(nodeId) {
|
|
232
|
+
function walk(nodeId: NodeId) {
|
|
232
233
|
if (walkVisited.has(nodeId)) return;
|
|
233
234
|
walkVisited.add(nodeId);
|
|
234
235
|
|
|
@@ -237,8 +238,7 @@ export default class BundleGraph {
|
|
|
237
238
|
if (getFeatureFlag('conditionalBundlingApi') && node.type === 'asset') {
|
|
238
239
|
const asset = node.value;
|
|
239
240
|
if (Array.isArray(asset.meta.conditions)) {
|
|
240
|
-
|
|
241
|
-
for (const condition of (asset.meta.conditions: ConditionMeta[])) {
|
|
241
|
+
for (const condition of asset.meta.conditions as ConditionMeta[]) {
|
|
242
242
|
// Resolve the placeholders that were attached to the asset in JSTransformer to dependencies,
|
|
243
243
|
// as well as create a public id for the condition.
|
|
244
244
|
const {
|
|
@@ -246,10 +246,9 @@ export default class BundleGraph {
|
|
|
246
246
|
ifTruePlaceholder,
|
|
247
247
|
ifFalsePlaceholder,
|
|
248
248
|
}: {
|
|
249
|
-
key: string
|
|
250
|
-
ifTruePlaceholder: string
|
|
251
|
-
ifFalsePlaceholder: string
|
|
252
|
-
...
|
|
249
|
+
key: string;
|
|
250
|
+
ifTruePlaceholder: string;
|
|
251
|
+
ifFalsePlaceholder: string;
|
|
253
252
|
} = condition;
|
|
254
253
|
|
|
255
254
|
const condHash = hashString(
|
|
@@ -283,7 +282,7 @@ export default class BundleGraph {
|
|
|
283
282
|
if (
|
|
284
283
|
node.type === 'dependency' &&
|
|
285
284
|
node.value.symbols != null &&
|
|
286
|
-
node.value.env.shouldScopeHoist &&
|
|
285
|
+
fromEnvironmentId(node.value.env).shouldScopeHoist &&
|
|
287
286
|
// Disable in dev mode because this feature is at odds with safeToIncrementallyBundle
|
|
288
287
|
isProduction
|
|
289
288
|
) {
|
|
@@ -333,7 +332,7 @@ export default class BundleGraph {
|
|
|
333
332
|
// Don't retarget because this cannot be resolved without also changing the asset symbols
|
|
334
333
|
// (and the asset content itself).
|
|
335
334
|
[...targets].every(
|
|
336
|
-
([, t]) => new Set([...t.values()]).size === t.size,
|
|
335
|
+
([, t]: [any, any]) => new Set([...t.values()]).size === t.size,
|
|
337
336
|
)
|
|
338
337
|
) {
|
|
339
338
|
let isReexportAll = nodeValueSymbols.get('*')?.local === '*';
|
|
@@ -351,13 +350,15 @@ export default class BundleGraph {
|
|
|
351
350
|
value: {
|
|
352
351
|
...node.value,
|
|
353
352
|
symbols: new Map(
|
|
354
|
-
|
|
353
|
+
// @ts-expect-error TS2769
|
|
354
|
+
[...nodeValueSymbols].filter(([k]: [any]) =>
|
|
355
355
|
externalSymbols.has(k),
|
|
356
356
|
),
|
|
357
357
|
),
|
|
358
358
|
},
|
|
359
359
|
usedSymbolsUp: new Map(
|
|
360
|
-
|
|
360
|
+
// @ts-expect-error TS2769
|
|
361
|
+
[...node.usedSymbolsUp].filter(([k]: [any]) =>
|
|
361
362
|
externalSymbols.has(k),
|
|
362
363
|
),
|
|
363
364
|
),
|
|
@@ -365,7 +366,7 @@ export default class BundleGraph {
|
|
|
365
366
|
excluded: externalSymbols.size === 0,
|
|
366
367
|
}),
|
|
367
368
|
},
|
|
368
|
-
...[...targets].map(([asset, target]) => {
|
|
369
|
+
...[...targets].map(([asset, target]: [any, any]) => {
|
|
369
370
|
let newNodeId = hashString(
|
|
370
371
|
node.id + [...target.keys()].join(','),
|
|
371
372
|
);
|
|
@@ -392,17 +393,28 @@ export default class BundleGraph {
|
|
|
392
393
|
local,
|
|
393
394
|
loc: reexportAllLoc,
|
|
394
395
|
});
|
|
396
|
+
|
|
395
397
|
if (node.value.sourceAssetId != null) {
|
|
396
|
-
let sourceAssetId
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
398
|
+
let sourceAssetId: NodeId;
|
|
399
|
+
|
|
400
|
+
if (getFeatureFlag('sourceAssetIdBundleGraphFix')) {
|
|
401
|
+
[sourceAssetId] =
|
|
402
|
+
assetGraph.getNodeIdsConnectedTo(nodeId);
|
|
403
|
+
} else {
|
|
404
|
+
sourceAssetId = assetGraph.getNodeIdByContentKey(
|
|
405
|
+
node.value.sourceAssetId,
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
let sourceAsset = nullthrows(
|
|
410
|
+
graph.getNode(
|
|
411
|
+
nullthrows(
|
|
412
|
+
assetGraphNodeIdToBundleGraphNodeId.get(
|
|
413
|
+
sourceAssetId,
|
|
414
|
+
),
|
|
400
415
|
),
|
|
401
416
|
),
|
|
402
417
|
);
|
|
403
|
-
let sourceAsset = nullthrows(
|
|
404
|
-
graph.getNode(sourceAssetId),
|
|
405
|
-
);
|
|
406
418
|
invariant(sourceAsset.type === 'asset');
|
|
407
419
|
let sourceAssetSymbols = sourceAsset.value.symbols;
|
|
408
420
|
if (sourceAssetSymbols) {
|
|
@@ -421,8 +433,9 @@ export default class BundleGraph {
|
|
|
421
433
|
}
|
|
422
434
|
let usedSymbolsUp = new Map(
|
|
423
435
|
[...node.usedSymbolsUp]
|
|
424
|
-
|
|
425
|
-
.
|
|
436
|
+
// @ts-expect-error TS2769
|
|
437
|
+
.filter(([k]: [any]) => target.has(k) || k === '*')
|
|
438
|
+
.map(([k, v]: [any, any]) => [target.get(k) ?? k, v]),
|
|
426
439
|
);
|
|
427
440
|
return {
|
|
428
441
|
asset,
|
|
@@ -478,6 +491,7 @@ export default class BundleGraph {
|
|
|
478
491
|
}
|
|
479
492
|
walk(nullthrows(assetGraph.rootNodeId));
|
|
480
493
|
|
|
494
|
+
// @ts-expect-error TS2488
|
|
481
495
|
for (let edge of assetGraph.getAllEdges()) {
|
|
482
496
|
if (assetGroupIds.has(edge.from)) {
|
|
483
497
|
continue;
|
|
@@ -502,10 +516,22 @@ export default class BundleGraph {
|
|
|
502
516
|
continue;
|
|
503
517
|
}
|
|
504
518
|
|
|
505
|
-
let to: Array<NodeId> = dependencies.get(edge.to)?.map(
|
|
519
|
+
let to: Array<NodeId> = dependencies.get(edge.to)?.map(
|
|
520
|
+
(
|
|
521
|
+
v:
|
|
522
|
+
| {
|
|
523
|
+
asset: null;
|
|
524
|
+
dep: NodeId;
|
|
525
|
+
}
|
|
526
|
+
| {
|
|
527
|
+
asset: ContentKey;
|
|
528
|
+
dep: NodeId;
|
|
529
|
+
},
|
|
530
|
+
) => v.dep,
|
|
531
|
+
) ??
|
|
506
532
|
assetGroupIds
|
|
507
533
|
.get(edge.to)
|
|
508
|
-
?.map((id) =>
|
|
534
|
+
?.map((id: NodeId) =>
|
|
509
535
|
nullthrows(assetGraphNodeIdToBundleGraphNodeId.get(id)),
|
|
510
536
|
) ?? [nullthrows(assetGraphNodeIdToBundleGraphNodeId.get(edge.to))];
|
|
511
537
|
|
|
@@ -547,31 +573,189 @@ export default class BundleGraph {
|
|
|
547
573
|
});
|
|
548
574
|
}
|
|
549
575
|
|
|
576
|
+
/**
|
|
577
|
+
* Serialize the bundle graph for efficient transfer to native Rust code.
|
|
578
|
+
* Returns a JSON string of nodes, an array of edges, and a map of asset IDs to public IDs.
|
|
579
|
+
*/
|
|
580
|
+
serializeForNative(): {
|
|
581
|
+
nodesJson: string;
|
|
582
|
+
edges: [number, number, BundleGraphEdgeType][];
|
|
583
|
+
publicIdByAssetId: Record<string, string>;
|
|
584
|
+
environmentsJson: string;
|
|
585
|
+
} {
|
|
586
|
+
const start = performance.now();
|
|
587
|
+
|
|
588
|
+
const nodes = this._graph.nodes as BundleGraphNode[];
|
|
589
|
+
const edges: [number, number, BundleGraphEdgeType][] = [];
|
|
590
|
+
|
|
591
|
+
const edgeIterator = this._graph.getAllEdges();
|
|
592
|
+
let next = edgeIterator.next();
|
|
593
|
+
while (!next.done) {
|
|
594
|
+
const edge = next.value;
|
|
595
|
+
edges.push([edge.from, edge.to, edge.type]);
|
|
596
|
+
next = edgeIterator.next();
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// Extract and deduplicate environments
|
|
600
|
+
const environmentMap = new Map<string, Environment>();
|
|
601
|
+
const extractEnvironment = (envRef: EnvironmentRef): string => {
|
|
602
|
+
const env = fromEnvironmentId(envRef);
|
|
603
|
+
const envId = env.id;
|
|
604
|
+
if (!environmentMap.has(envId)) {
|
|
605
|
+
environmentMap.set(envId, env);
|
|
606
|
+
}
|
|
607
|
+
return envId;
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
// Replace env objects with env IDs in nodes
|
|
611
|
+
const processedNodes = nodes.map((node) => {
|
|
612
|
+
const processedNode = {...node};
|
|
613
|
+
if (node.type === 'asset' && node.value?.env) {
|
|
614
|
+
processedNode.value = {
|
|
615
|
+
...node.value,
|
|
616
|
+
env: extractEnvironment(node.value.env),
|
|
617
|
+
};
|
|
618
|
+
} else if (node.type === 'dependency' && node.value?.env) {
|
|
619
|
+
processedNode.value = {
|
|
620
|
+
...node.value,
|
|
621
|
+
env: extractEnvironment(node.value.env),
|
|
622
|
+
};
|
|
623
|
+
} else if (node.type === 'bundle' && node.value?.env) {
|
|
624
|
+
processedNode.value = {
|
|
625
|
+
...node.value,
|
|
626
|
+
env: extractEnvironment(node.value.env),
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
return processedNode;
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// Optimize nodes by omitting null/undefined values to reduce JSON size
|
|
633
|
+
const optimizedNodes = processedNodes.map((node) => this._omitNulls(node));
|
|
634
|
+
const nodesJson = JSON.stringify(optimizedNodes);
|
|
635
|
+
|
|
636
|
+
// Serialize environments as array
|
|
637
|
+
const environments = Array.from(environmentMap.values());
|
|
638
|
+
const environmentsJson = JSON.stringify(environments);
|
|
639
|
+
|
|
640
|
+
// Convert Map to plain object for serialization
|
|
641
|
+
const publicIdByAssetId: Record<string, string> = {};
|
|
642
|
+
for (const [assetId, publicId] of this._publicIdByAssetId) {
|
|
643
|
+
publicIdByAssetId[assetId] = publicId;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
const duration = performance.now() - start;
|
|
647
|
+
const nodesSizeMB = (nodesJson.length / (1024 * 1024)).toFixed(2);
|
|
648
|
+
const envsSizeMB = (environmentsJson.length / (1024 * 1024)).toFixed(2);
|
|
649
|
+
logger.verbose({
|
|
650
|
+
origin: '@atlaspack/core',
|
|
651
|
+
message: `serializeForNative: ${duration.toFixed(1)}ms, ${nodesSizeMB}MB nodes, ${envsSizeMB}MB envs (${environmentMap.size} unique), ${nodes.length} nodes, ${edges.length} edges`,
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
return {nodesJson, edges, publicIdByAssetId, environmentsJson};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Serialize only the given asset nodes for native incremental update.
|
|
659
|
+
* Same node shape and env/omit logic as serializeForNative.
|
|
660
|
+
*/
|
|
661
|
+
serializeAssetNodesForNative(assetIds: Array<string>): string {
|
|
662
|
+
const start = performance.now();
|
|
663
|
+
|
|
664
|
+
if (assetIds.length === 0) {
|
|
665
|
+
return '[]';
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const nodes: Array<BundleGraphNode> = [];
|
|
669
|
+
for (const assetId of assetIds) {
|
|
670
|
+
const node = this._graph.getNodeByContentKey(assetId);
|
|
671
|
+
if (node?.type !== 'asset') {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
const processedNode = {...node};
|
|
675
|
+
if (node.value?.env) {
|
|
676
|
+
processedNode.value = {
|
|
677
|
+
...node.value,
|
|
678
|
+
env: fromEnvironmentId(node.value.env).id,
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
nodes.push(processedNode);
|
|
682
|
+
}
|
|
683
|
+
const optimizedNodes = nodes.map((node) => this._omitNulls(node));
|
|
684
|
+
const nodesJson = JSON.stringify(optimizedNodes);
|
|
685
|
+
|
|
686
|
+
const duration = performance.now() - start;
|
|
687
|
+
const nodesSizeMB = (nodesJson.length / (1024 * 1024)).toFixed(2);
|
|
688
|
+
|
|
689
|
+
logger.verbose({
|
|
690
|
+
origin: '@atlaspack/core',
|
|
691
|
+
message: `serializeAssetNodesForNative: ${duration.toFixed(1)}ms, ${nodesSizeMB}MB nodes, ${nodes.length} nodes`,
|
|
692
|
+
});
|
|
693
|
+
return nodesJson;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Remove null and undefined values from an object to reduce JSON size.
|
|
698
|
+
* Preserves false, 0, empty strings, and arrays.
|
|
699
|
+
*/
|
|
700
|
+
private _omitNulls(obj: unknown): unknown {
|
|
701
|
+
if (obj === null || obj === undefined) return obj;
|
|
702
|
+
if (typeof obj !== 'object') return obj;
|
|
703
|
+
if (Array.isArray(obj)) {
|
|
704
|
+
return obj.map((item) => this._omitNulls(item));
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const result: Record<string, unknown> = {};
|
|
708
|
+
for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {
|
|
709
|
+
if (value === null || value === undefined) {
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
if (
|
|
713
|
+
typeof value === 'object' &&
|
|
714
|
+
!Array.isArray(value) &&
|
|
715
|
+
Object.keys(value as object).length === 0
|
|
716
|
+
) {
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
if (typeof value === 'object') {
|
|
720
|
+
const processed = this._omitNulls(value);
|
|
721
|
+
if (processed !== undefined) {
|
|
722
|
+
result[key] = processed;
|
|
723
|
+
}
|
|
724
|
+
} else {
|
|
725
|
+
result[key] = value;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return result;
|
|
729
|
+
}
|
|
730
|
+
|
|
550
731
|
createBundle(
|
|
551
732
|
opts:
|
|
552
|
-
| {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
733
|
+
| {
|
|
734
|
+
readonly entryAsset: Asset;
|
|
735
|
+
readonly bundleRoots?: Array<Asset>;
|
|
736
|
+
readonly target: Target;
|
|
737
|
+
readonly needsStableName?: boolean | null | undefined;
|
|
738
|
+
readonly bundleBehavior?: IBundleBehavior | null | undefined;
|
|
739
|
+
readonly shouldContentHash: boolean;
|
|
740
|
+
readonly env: EnvironmentRef;
|
|
741
|
+
}
|
|
742
|
+
| {
|
|
743
|
+
readonly type: string;
|
|
744
|
+
readonly env: EnvironmentRef;
|
|
745
|
+
readonly uniqueKey: string;
|
|
746
|
+
readonly target: Target;
|
|
747
|
+
readonly needsStableName?: boolean | null | undefined;
|
|
748
|
+
readonly bundleBehavior?: IBundleBehavior | null | undefined;
|
|
749
|
+
readonly isSplittable?: boolean | null | undefined;
|
|
750
|
+
readonly pipeline?: string | null | undefined;
|
|
751
|
+
readonly shouldContentHash: boolean;
|
|
752
|
+
},
|
|
571
753
|
): Bundle {
|
|
754
|
+
// @ts-expect-error TS2339
|
|
572
755
|
let {entryAsset, target} = opts;
|
|
573
756
|
let bundleId = hashString(
|
|
574
757
|
'bundle:' +
|
|
758
|
+
// @ts-expect-error TS2339
|
|
575
759
|
(opts.entryAsset ? opts.entryAsset.id : opts.uniqueKey) +
|
|
576
760
|
fromProjectPathRelative(target.distDir) +
|
|
577
761
|
(opts.bundleBehavior ?? ''),
|
|
@@ -603,19 +787,24 @@ export default class BundleGraph {
|
|
|
603
787
|
hashReference: opts.shouldContentHash
|
|
604
788
|
? HASH_REF_PREFIX + bundleId
|
|
605
789
|
: bundleId.slice(-8),
|
|
790
|
+
// @ts-expect-error TS2339
|
|
606
791
|
type: opts.entryAsset ? opts.entryAsset.type : opts.type,
|
|
607
792
|
env: opts.env,
|
|
608
793
|
entryAssetIds: entryAsset ? [entryAsset.id] : [],
|
|
609
794
|
mainEntryId: entryAsset?.id,
|
|
795
|
+
// @ts-expect-error TS2339
|
|
610
796
|
pipeline: opts.entryAsset ? opts.entryAsset.pipeline : opts.pipeline,
|
|
611
797
|
needsStableName: opts.needsStableName,
|
|
612
798
|
bundleBehavior:
|
|
613
799
|
opts.bundleBehavior != null
|
|
614
800
|
? BundleBehavior[opts.bundleBehavior]
|
|
615
801
|
: null,
|
|
802
|
+
// @ts-expect-error TS2339
|
|
616
803
|
isSplittable: opts.entryAsset
|
|
617
|
-
?
|
|
618
|
-
|
|
804
|
+
? // @ts-expect-error TS2339
|
|
805
|
+
opts.entryAsset.isBundleSplittable
|
|
806
|
+
: // @ts-expect-error TS2339
|
|
807
|
+
opts.isSplittable,
|
|
619
808
|
isPlaceholder,
|
|
620
809
|
target,
|
|
621
810
|
name: null,
|
|
@@ -626,9 +815,11 @@ export default class BundleGraph {
|
|
|
626
815
|
|
|
627
816
|
let bundleNodeId = this._graph.addNodeByContentKey(bundleId, bundleNode);
|
|
628
817
|
|
|
818
|
+
// @ts-expect-error TS2339
|
|
629
819
|
if (opts.entryAsset) {
|
|
630
820
|
this._graph.addEdge(
|
|
631
821
|
bundleNodeId,
|
|
822
|
+
// @ts-expect-error TS2339
|
|
632
823
|
this._graph.getNodeIdByContentKey(opts.entryAsset.id),
|
|
633
824
|
);
|
|
634
825
|
}
|
|
@@ -661,10 +852,13 @@ export default class BundleGraph {
|
|
|
661
852
|
for (let [bundleGroupNodeId, bundleGroupNode] of this._graph
|
|
662
853
|
.getNodeIdsConnectedFrom(dependencyNodeId)
|
|
663
854
|
.map((id) => [id, nullthrows(this._graph.getNode(id))])
|
|
664
|
-
|
|
855
|
+
// @ts-expect-error TS2769
|
|
856
|
+
.filter(([, node]: [any, any]) => node.type === 'bundle_group')) {
|
|
857
|
+
// @ts-expect-error TS2339
|
|
665
858
|
invariant(bundleGroupNode.type === 'bundle_group');
|
|
666
859
|
this._graph.addEdge(
|
|
667
860
|
bundleNodeId,
|
|
861
|
+
// @ts-expect-error TS2345
|
|
668
862
|
bundleGroupNodeId,
|
|
669
863
|
bundleGraphEdgeTypes.bundle,
|
|
670
864
|
);
|
|
@@ -693,7 +887,7 @@ export default class BundleGraph {
|
|
|
693
887
|
addAssetGraphToBundle(
|
|
694
888
|
asset: Asset,
|
|
695
889
|
bundle: Bundle,
|
|
696
|
-
shouldSkipDependency: (Dependency) => boolean = (d) =>
|
|
890
|
+
shouldSkipDependency: (arg1: Dependency) => boolean = (d: Dependency) =>
|
|
697
891
|
this.isDependencySkipped(d),
|
|
698
892
|
) {
|
|
699
893
|
let assetNodeId = this._graph.getNodeIdByContentKey(asset.id);
|
|
@@ -726,10 +920,13 @@ export default class BundleGraph {
|
|
|
726
920
|
for (let [bundleGroupNodeId, bundleGroupNode] of this._graph
|
|
727
921
|
.getNodeIdsConnectedFrom(nodeId)
|
|
728
922
|
.map((id) => [id, nullthrows(this._graph.getNode(id))])
|
|
729
|
-
|
|
923
|
+
// @ts-expect-error TS2769
|
|
924
|
+
.filter(([, node]: [any, any]) => node.type === 'bundle_group')) {
|
|
925
|
+
// @ts-expect-error TS2339
|
|
730
926
|
invariant(bundleGroupNode.type === 'bundle_group');
|
|
731
927
|
this._graph.addEdge(
|
|
732
928
|
bundleNodeId,
|
|
929
|
+
// @ts-expect-error TS2345
|
|
733
930
|
bundleGroupNodeId,
|
|
734
931
|
bundleGraphEdgeTypes.bundle,
|
|
735
932
|
);
|
|
@@ -769,7 +966,7 @@ export default class BundleGraph {
|
|
|
769
966
|
addEntryToBundle(
|
|
770
967
|
asset: Asset,
|
|
771
968
|
bundle: Bundle,
|
|
772
|
-
shouldSkipDependency?: (Dependency) => boolean,
|
|
969
|
+
shouldSkipDependency?: (arg1: Dependency) => boolean,
|
|
773
970
|
) {
|
|
774
971
|
this.addAssetGraphToBundle(asset, bundle, shouldSkipDependency);
|
|
775
972
|
if (!bundle.entryAssetIds.includes(asset.id)) {
|
|
@@ -836,11 +1033,18 @@ export default class BundleGraph {
|
|
|
836
1033
|
|
|
837
1034
|
resolveAsyncDependency(
|
|
838
1035
|
dependency: Dependency,
|
|
839
|
-
bundle
|
|
840
|
-
):
|
|
841
|
-
| {
|
|
842
|
-
|
|
843
|
-
|
|
1036
|
+
bundle?: Bundle | null,
|
|
1037
|
+
):
|
|
1038
|
+
| {
|
|
1039
|
+
type: 'bundle_group';
|
|
1040
|
+
value: BundleGroup;
|
|
1041
|
+
}
|
|
1042
|
+
| {
|
|
1043
|
+
type: 'asset';
|
|
1044
|
+
value: Asset;
|
|
1045
|
+
}
|
|
1046
|
+
| null
|
|
1047
|
+
| undefined {
|
|
844
1048
|
let depNodeId = this._graph.getNodeIdByContentKey(dependency.id);
|
|
845
1049
|
let bundleNodeId =
|
|
846
1050
|
bundle != null ? this._graph.getNodeIdByContentKey(bundle.id) : null;
|
|
@@ -899,7 +1103,10 @@ export default class BundleGraph {
|
|
|
899
1103
|
}
|
|
900
1104
|
|
|
901
1105
|
// eslint-disable-next-line no-unused-vars
|
|
902
|
-
getReferencedBundle(
|
|
1106
|
+
getReferencedBundle(
|
|
1107
|
+
dependency: Dependency,
|
|
1108
|
+
fromBundle: Bundle,
|
|
1109
|
+
): Bundle | null | undefined {
|
|
903
1110
|
let dependencyNodeId = this._graph.getNodeIdByContentKey(dependency.id);
|
|
904
1111
|
|
|
905
1112
|
// Find an attached bundle via a reference edge (e.g. from createAssetReference).
|
|
@@ -931,8 +1138,12 @@ export default class BundleGraph {
|
|
|
931
1138
|
return this.getBundlesInBundleGroup(node.value, {
|
|
932
1139
|
includeInline: true,
|
|
933
1140
|
}).find((b) => {
|
|
934
|
-
|
|
935
|
-
|
|
1141
|
+
if (getFeatureFlag('supportWebpackChunkName')) {
|
|
1142
|
+
return b.entryAssetIds.some((id) => id === node.value.entryAssetId);
|
|
1143
|
+
} else {
|
|
1144
|
+
let mainEntryId = b.entryAssetIds[b.entryAssetIds.length - 1];
|
|
1145
|
+
return mainEntryId != null && node.value.entryAssetId === mainEntryId;
|
|
1146
|
+
}
|
|
936
1147
|
});
|
|
937
1148
|
}
|
|
938
1149
|
}
|
|
@@ -1226,7 +1437,10 @@ export default class BundleGraph {
|
|
|
1226
1437
|
});
|
|
1227
1438
|
}
|
|
1228
1439
|
|
|
1229
|
-
getResolvedAsset(
|
|
1440
|
+
getResolvedAsset(
|
|
1441
|
+
dep: Dependency,
|
|
1442
|
+
bundle?: Bundle | null,
|
|
1443
|
+
): Asset | null | undefined {
|
|
1230
1444
|
let assets = this.getDependencyAssets(dep);
|
|
1231
1445
|
let firstAsset = assets[0];
|
|
1232
1446
|
let resolved =
|
|
@@ -1240,7 +1454,7 @@ export default class BundleGraph {
|
|
|
1240
1454
|
|
|
1241
1455
|
// If a resolution still hasn't been found, return the first referenced asset.
|
|
1242
1456
|
if (resolved == null) {
|
|
1243
|
-
let potential = [];
|
|
1457
|
+
let potential: Array<Asset> = [];
|
|
1244
1458
|
this._graph.traverse(
|
|
1245
1459
|
(nodeId, _, traversal) => {
|
|
1246
1460
|
let node = nullthrows(this._graph.getNode(nodeId));
|
|
@@ -1255,6 +1469,7 @@ export default class BundleGraph {
|
|
|
1255
1469
|
);
|
|
1256
1470
|
|
|
1257
1471
|
if (bundle) {
|
|
1472
|
+
// @ts-expect-error TS2322
|
|
1258
1473
|
resolved = potential.find((a) => a.type === bundle.type);
|
|
1259
1474
|
}
|
|
1260
1475
|
resolved ||= potential[0];
|
|
@@ -1276,7 +1491,7 @@ export default class BundleGraph {
|
|
|
1276
1491
|
bundle: Bundle,
|
|
1277
1492
|
visit: GraphVisitor<Asset, TContext>,
|
|
1278
1493
|
startAsset?: Asset,
|
|
1279
|
-
):
|
|
1494
|
+
): TContext | null | undefined {
|
|
1280
1495
|
return this.traverseBundle(
|
|
1281
1496
|
bundle,
|
|
1282
1497
|
mapVisitor((node) => (node.type === 'asset' ? node.value : null), visit),
|
|
@@ -1359,7 +1574,8 @@ export default class BundleGraph {
|
|
|
1359
1574
|
|
|
1360
1575
|
if (
|
|
1361
1576
|
descendant.type !== bundle.type ||
|
|
1362
|
-
descendant.env.context !==
|
|
1577
|
+
fromEnvironmentId(descendant.env).context !==
|
|
1578
|
+
fromEnvironmentId(bundle.env).context
|
|
1363
1579
|
) {
|
|
1364
1580
|
actions.skipChildren();
|
|
1365
1581
|
return;
|
|
@@ -1376,6 +1592,158 @@ export default class BundleGraph {
|
|
|
1376
1592
|
});
|
|
1377
1593
|
}
|
|
1378
1594
|
|
|
1595
|
+
// New method: Fast checks only (no caching of results)
|
|
1596
|
+
isAssetReferencedFastCheck(bundle: Bundle, asset: Asset): boolean | null {
|
|
1597
|
+
// Fast Check #1: If asset is in multiple bundles in same target, it's referenced
|
|
1598
|
+
let bundlesWithAsset = this.getBundlesWithAsset(asset).filter(
|
|
1599
|
+
(b) =>
|
|
1600
|
+
b.target.name === bundle.target.name &&
|
|
1601
|
+
b.target.distDir === bundle.target.distDir,
|
|
1602
|
+
);
|
|
1603
|
+
|
|
1604
|
+
if (bundlesWithAsset.length > 1) {
|
|
1605
|
+
return true;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
// Fast Check #2: If asset is referenced by any async/conditional dependency, it's referenced
|
|
1609
|
+
let assetNodeId = nullthrows(this._graph.getNodeIdByContentKey(asset.id));
|
|
1610
|
+
|
|
1611
|
+
if (
|
|
1612
|
+
this._graph
|
|
1613
|
+
.getNodeIdsConnectedTo(assetNodeId, bundleGraphEdgeTypes.references)
|
|
1614
|
+
.map((id) => this._graph.getNode(id))
|
|
1615
|
+
.some(
|
|
1616
|
+
(node) =>
|
|
1617
|
+
node?.type === 'dependency' &&
|
|
1618
|
+
(node.value.priority === Priority.lazy ||
|
|
1619
|
+
node.value.priority === Priority.conditional) &&
|
|
1620
|
+
node.value.specifierType !== SpecifierType.url,
|
|
1621
|
+
)
|
|
1622
|
+
) {
|
|
1623
|
+
return true;
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// Fast checks failed - return null to indicate expensive computation needed
|
|
1627
|
+
return null;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
getReferencedAssets(bundle: Bundle): Set<Asset> {
|
|
1631
|
+
let referencedAssets = new Set<Asset>();
|
|
1632
|
+
|
|
1633
|
+
// Build a map of all assets in this bundle with their dependencies
|
|
1634
|
+
// This allows us to check all assets in a single traversal
|
|
1635
|
+
let assetDependenciesMap = new Map<Asset, Array<Dependency>>();
|
|
1636
|
+
|
|
1637
|
+
this.traverseAssets(bundle, (asset) => {
|
|
1638
|
+
// Always do fast checks (no caching)
|
|
1639
|
+
let fastCheckResult = this.isAssetReferencedFastCheck(bundle, asset);
|
|
1640
|
+
|
|
1641
|
+
if (fastCheckResult === true) {
|
|
1642
|
+
referencedAssets.add(asset);
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
// Fast checks failed (fastCheckResult === null), need expensive computation
|
|
1647
|
+
// Check if it's actually referenced via traversal
|
|
1648
|
+
|
|
1649
|
+
// Store dependencies for later batch checking
|
|
1650
|
+
let dependencies = this._graph
|
|
1651
|
+
.getNodeIdsConnectedTo(
|
|
1652
|
+
nullthrows(this._graph.getNodeIdByContentKey(asset.id)),
|
|
1653
|
+
)
|
|
1654
|
+
.map((id) => nullthrows(this._graph.getNode(id)))
|
|
1655
|
+
.filter((node) => node.type === 'dependency')
|
|
1656
|
+
.map((node) => {
|
|
1657
|
+
invariant(node.type === 'dependency');
|
|
1658
|
+
return node.value;
|
|
1659
|
+
});
|
|
1660
|
+
|
|
1661
|
+
if (dependencies.length > 0) {
|
|
1662
|
+
assetDependenciesMap.set(asset, dependencies);
|
|
1663
|
+
}
|
|
1664
|
+
});
|
|
1665
|
+
|
|
1666
|
+
// If no assets need the expensive check, return early
|
|
1667
|
+
if (assetDependenciesMap.size === 0) {
|
|
1668
|
+
return referencedAssets;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// Get the assets we need to check once
|
|
1672
|
+
let assetsToCheck = Array.from(assetDependenciesMap.keys());
|
|
1673
|
+
|
|
1674
|
+
// Helper function to check if all assets from assetDependenciesMap are in referencedAssets
|
|
1675
|
+
const allAssetsReferenced = (): boolean =>
|
|
1676
|
+
assetsToCheck.length <= referencedAssets.size &&
|
|
1677
|
+
assetsToCheck.every((asset) => referencedAssets.has(asset));
|
|
1678
|
+
|
|
1679
|
+
// Do ONE traversal to check all remaining assets
|
|
1680
|
+
// We can share visitedBundles across all assets because we check every asset
|
|
1681
|
+
// against every visited bundle, which matches the original per-asset behavior
|
|
1682
|
+
let siblingBundles = new Set(
|
|
1683
|
+
this.getBundleGroupsContainingBundle(bundle).flatMap((bundleGroup) =>
|
|
1684
|
+
this.getBundlesInBundleGroup(bundleGroup, {includeInline: true}),
|
|
1685
|
+
),
|
|
1686
|
+
);
|
|
1687
|
+
|
|
1688
|
+
let visitedBundles: Set<Bundle> = new Set();
|
|
1689
|
+
|
|
1690
|
+
// Single traversal from all referencers
|
|
1691
|
+
for (let referencer of siblingBundles) {
|
|
1692
|
+
this.traverseBundles((descendant, _, actions) => {
|
|
1693
|
+
if (descendant.id === bundle.id) {
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
if (visitedBundles.has(descendant)) {
|
|
1698
|
+
actions.skipChildren();
|
|
1699
|
+
return;
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
visitedBundles.add(descendant);
|
|
1703
|
+
|
|
1704
|
+
if (
|
|
1705
|
+
descendant.type !== bundle.type ||
|
|
1706
|
+
fromEnvironmentId(descendant.env).context !==
|
|
1707
|
+
fromEnvironmentId(bundle.env).context
|
|
1708
|
+
) {
|
|
1709
|
+
// Don't skip children - they might be the right type!
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
// Check ALL assets at once in this descendant bundle
|
|
1714
|
+
for (let [asset, dependencies] of assetDependenciesMap) {
|
|
1715
|
+
// Skip if already marked as referenced
|
|
1716
|
+
if (referencedAssets.has(asset)) {
|
|
1717
|
+
continue;
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
// Check if this descendant bundle references the asset
|
|
1721
|
+
if (
|
|
1722
|
+
!this.bundleHasAsset(descendant, asset) &&
|
|
1723
|
+
dependencies.some((dependency) =>
|
|
1724
|
+
this.bundleHasDependency(descendant, dependency),
|
|
1725
|
+
)
|
|
1726
|
+
) {
|
|
1727
|
+
referencedAssets.add(asset);
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
// If all assets from assetDependenciesMap are now marked as referenced, we can stop early
|
|
1732
|
+
if (allAssetsReferenced()) {
|
|
1733
|
+
actions.stop();
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
1736
|
+
}, referencer);
|
|
1737
|
+
|
|
1738
|
+
// If all assets from assetDependenciesMap are referenced, no need to check more sibling bundles
|
|
1739
|
+
if (allAssetsReferenced()) {
|
|
1740
|
+
break;
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
return referencedAssets;
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1379
1747
|
hasParentBundleOfType(bundle: Bundle, type: string): boolean {
|
|
1380
1748
|
let parents = this.getParentBundles(bundle);
|
|
1381
1749
|
return (
|
|
@@ -1400,10 +1768,11 @@ export default class BundleGraph {
|
|
|
1400
1768
|
// If a bundle's environment is isolated, it can't access assets present
|
|
1401
1769
|
// in any ancestor bundles. Don't consider any assets reachable.
|
|
1402
1770
|
if (
|
|
1403
|
-
ISOLATED_ENVS.has(bundle.env.context) ||
|
|
1771
|
+
ISOLATED_ENVS.has(fromEnvironmentId(bundle.env).context) ||
|
|
1404
1772
|
!bundle.isSplittable ||
|
|
1405
1773
|
bundle.bundleBehavior === BundleBehavior.isolated ||
|
|
1406
|
-
bundle.bundleBehavior === BundleBehavior.inline
|
|
1774
|
+
bundle.bundleBehavior === BundleBehavior.inline ||
|
|
1775
|
+
bundle.bundleBehavior === BundleBehavior.inlineIsolated
|
|
1407
1776
|
) {
|
|
1408
1777
|
return false;
|
|
1409
1778
|
}
|
|
@@ -1420,6 +1789,7 @@ export default class BundleGraph {
|
|
|
1420
1789
|
b.id !== bundle.id &&
|
|
1421
1790
|
b.bundleBehavior !== BundleBehavior.isolated &&
|
|
1422
1791
|
b.bundleBehavior !== BundleBehavior.inline &&
|
|
1792
|
+
b.bundleBehavior !== BundleBehavior.inlineIsolated &&
|
|
1423
1793
|
this.bundleHasAsset(b, asset),
|
|
1424
1794
|
)
|
|
1425
1795
|
) {
|
|
@@ -1438,7 +1808,8 @@ export default class BundleGraph {
|
|
|
1438
1808
|
if (
|
|
1439
1809
|
bundleNode.type !== 'bundle' ||
|
|
1440
1810
|
bundleNode.value.bundleBehavior === BundleBehavior.isolated ||
|
|
1441
|
-
bundleNode.value.bundleBehavior === BundleBehavior.inline
|
|
1811
|
+
bundleNode.value.bundleBehavior === BundleBehavior.inline ||
|
|
1812
|
+
bundleNode.value.bundleBehavior === BundleBehavior.inlineIsolated
|
|
1442
1813
|
) {
|
|
1443
1814
|
return false;
|
|
1444
1815
|
}
|
|
@@ -1454,7 +1825,8 @@ export default class BundleGraph {
|
|
|
1454
1825
|
node.type === 'root' ||
|
|
1455
1826
|
(node.type === 'bundle' &&
|
|
1456
1827
|
(node.value.id === bundle.id ||
|
|
1457
|
-
node.value.env.context !==
|
|
1828
|
+
fromEnvironmentId(node.value.env).context !==
|
|
1829
|
+
fromEnvironmentId(bundle.env).context))
|
|
1458
1830
|
) {
|
|
1459
1831
|
isReachable = false;
|
|
1460
1832
|
actions.stop();
|
|
@@ -1469,6 +1841,7 @@ export default class BundleGraph {
|
|
|
1469
1841
|
b.id !== bundle.id &&
|
|
1470
1842
|
b.bundleBehavior !== BundleBehavior.isolated &&
|
|
1471
1843
|
b.bundleBehavior !== BundleBehavior.inline &&
|
|
1844
|
+
b.bundleBehavior !== BundleBehavior.inlineIsolated &&
|
|
1472
1845
|
this.bundleHasAsset(b, asset),
|
|
1473
1846
|
)
|
|
1474
1847
|
) {
|
|
@@ -1486,14 +1859,42 @@ export default class BundleGraph {
|
|
|
1486
1859
|
}
|
|
1487
1860
|
|
|
1488
1861
|
/**
|
|
1489
|
-
*
|
|
1490
|
-
*
|
|
1862
|
+
* Performs a depth-first traversal of all assets and dependencies contained
|
|
1863
|
+
* within a bundle. Only visits nodes that are directly contained in the bundle
|
|
1864
|
+
* (connected via a `contains` edge).
|
|
1865
|
+
*
|
|
1866
|
+
* Entry Asset Ordering:
|
|
1867
|
+
* The traversal guarantees that entry assets are visited in the exact order they
|
|
1868
|
+
* appear in `bundle.entryAssetIds`. This ordering is critical for several reasons:
|
|
1869
|
+
*
|
|
1870
|
+
* 1. **Code Execution Order in Packagers**: Packagers (ScopeHoistingPackager,
|
|
1871
|
+
* DevPackager) use this traversal to concatenate assets into the final bundle.
|
|
1872
|
+
* The traversal order determines the execution order of code in the output.
|
|
1873
|
+
* Entry assets must be processed in their defined order to ensure correct
|
|
1874
|
+
* initialization sequences.
|
|
1875
|
+
*
|
|
1876
|
+
* 2. **Runtime Injection**: Runtime assets (HMR, bundle manifests) are prepended
|
|
1877
|
+
* to `entryAssetIds` via `unshift()` in `applyRuntimes.ts`. By honoring the
|
|
1878
|
+
* array order, runtimes are guaranteed to be visited (and thus output) before
|
|
1879
|
+
* application entry points, ensuring the runtime infrastructure is available
|
|
1880
|
+
* when application code executes.
|
|
1881
|
+
*
|
|
1882
|
+
* 3. **Deterministic Builds**: Consistent traversal order ensures reproducible
|
|
1883
|
+
* bundle output, which is essential for caching and build verification.
|
|
1884
|
+
*
|
|
1885
|
+
* The sorting only applies at the first traversal level (direct children of the
|
|
1886
|
+
* start node). Subsequent levels follow standard DFS order based on the graph's
|
|
1887
|
+
* edge structure.
|
|
1888
|
+
*
|
|
1889
|
+
* @param bundle - The bundle to traverse
|
|
1890
|
+
* @param visit - Visitor callback receiving asset or dependency nodes
|
|
1891
|
+
* @param startAsset - Optional asset to start traversal from (defaults to bundle root)
|
|
1491
1892
|
*/
|
|
1492
1893
|
traverseBundle<TContext>(
|
|
1493
1894
|
bundle: Bundle,
|
|
1494
1895
|
visit: GraphVisitor<AssetNode | DependencyNode, TContext>,
|
|
1495
1896
|
startAsset?: Asset,
|
|
1496
|
-
):
|
|
1897
|
+
): TContext | null | undefined {
|
|
1497
1898
|
let entries = !startAsset;
|
|
1498
1899
|
let bundleNodeId = this._graph.getNodeIdByContentKey(bundle.id);
|
|
1499
1900
|
|
|
@@ -1531,7 +1932,8 @@ export default class BundleGraph {
|
|
|
1531
1932
|
|
|
1532
1933
|
let sorted =
|
|
1533
1934
|
entries && bundle.entryAssetIds.length > 0
|
|
1534
|
-
?
|
|
1935
|
+
? // @ts-expect-error TS2345
|
|
1936
|
+
children.sort(([, a]: [any, any], [, b]: [any, any]) => {
|
|
1535
1937
|
let aIndex = bundle.entryAssetIds.indexOf(a.id);
|
|
1536
1938
|
let bIndex = bundle.entryAssetIds.indexOf(b.id);
|
|
1537
1939
|
|
|
@@ -1550,7 +1952,8 @@ export default class BundleGraph {
|
|
|
1550
1952
|
: children;
|
|
1551
1953
|
|
|
1552
1954
|
entries = false;
|
|
1553
|
-
|
|
1955
|
+
// @ts-expect-error TS2345
|
|
1956
|
+
return sorted.map(([id]: [any]) => id);
|
|
1554
1957
|
},
|
|
1555
1958
|
});
|
|
1556
1959
|
}
|
|
@@ -1558,7 +1961,7 @@ export default class BundleGraph {
|
|
|
1558
1961
|
traverse<TContext>(
|
|
1559
1962
|
visit: GraphVisitor<AssetNode | DependencyNode, TContext>,
|
|
1560
1963
|
start?: Asset,
|
|
1561
|
-
):
|
|
1964
|
+
): TContext | null | undefined {
|
|
1562
1965
|
return this._graph.filteredTraverse(
|
|
1563
1966
|
(nodeId) => {
|
|
1564
1967
|
let node = nullthrows(this._graph.getNode(nodeId));
|
|
@@ -1574,7 +1977,7 @@ export default class BundleGraph {
|
|
|
1574
1977
|
|
|
1575
1978
|
getChildBundles(bundle: Bundle): Array<Bundle> {
|
|
1576
1979
|
let siblings = new Set(this.getReferencedBundles(bundle));
|
|
1577
|
-
let bundles = [];
|
|
1980
|
+
let bundles: Array<Bundle> = [];
|
|
1578
1981
|
this.traverseBundles((b, _, actions) => {
|
|
1579
1982
|
if (bundle.id === b.id) {
|
|
1580
1983
|
return;
|
|
@@ -1591,8 +1994,8 @@ export default class BundleGraph {
|
|
|
1591
1994
|
|
|
1592
1995
|
traverseBundles<TContext>(
|
|
1593
1996
|
visit: GraphVisitor<Bundle, TContext>,
|
|
1594
|
-
startBundle
|
|
1595
|
-
):
|
|
1997
|
+
startBundle?: Bundle | null,
|
|
1998
|
+
): TContext | null | undefined {
|
|
1596
1999
|
return this._graph.filteredTraverse(
|
|
1597
2000
|
(nodeId) => {
|
|
1598
2001
|
let node = nullthrows(this._graph.getNode(nodeId));
|
|
@@ -1604,12 +2007,13 @@ export default class BundleGraph {
|
|
|
1604
2007
|
);
|
|
1605
2008
|
}
|
|
1606
2009
|
|
|
1607
|
-
getBundles(opts?: {
|
|
1608
|
-
let bundles = [];
|
|
2010
|
+
getBundles(opts?: {includeInline: boolean}): Array<Bundle> {
|
|
2011
|
+
let bundles: Array<Bundle> = [];
|
|
1609
2012
|
this.traverseBundles((bundle) => {
|
|
1610
2013
|
if (
|
|
1611
2014
|
opts?.includeInline ||
|
|
1612
|
-
bundle.bundleBehavior !== BundleBehavior.inline
|
|
2015
|
+
(bundle.bundleBehavior !== BundleBehavior.inline &&
|
|
2016
|
+
bundle.bundleBehavior !== BundleBehavior.inlineIsolated)
|
|
1613
2017
|
) {
|
|
1614
2018
|
bundles.push(bundle);
|
|
1615
2019
|
}
|
|
@@ -1679,7 +2083,9 @@ export default class BundleGraph {
|
|
|
1679
2083
|
|
|
1680
2084
|
getBundlesInBundleGroup(
|
|
1681
2085
|
bundleGroup: BundleGroup,
|
|
1682
|
-
opts?: {
|
|
2086
|
+
opts?: {
|
|
2087
|
+
includeInline: boolean;
|
|
2088
|
+
},
|
|
1683
2089
|
): Array<Bundle> {
|
|
1684
2090
|
let bundles: Set<Bundle> = new Set();
|
|
1685
2091
|
for (let bundleNodeId of this._graph.getNodeIdsConnectedFrom(
|
|
@@ -1691,7 +2097,8 @@ export default class BundleGraph {
|
|
|
1691
2097
|
let bundle = bundleNode.value;
|
|
1692
2098
|
if (
|
|
1693
2099
|
opts?.includeInline ||
|
|
1694
|
-
bundle.bundleBehavior !== BundleBehavior.inline
|
|
2100
|
+
(bundle.bundleBehavior !== BundleBehavior.inline &&
|
|
2101
|
+
bundle.bundleBehavior !== BundleBehavior.inlineIsolated)
|
|
1695
2102
|
) {
|
|
1696
2103
|
bundles.add(bundle);
|
|
1697
2104
|
}
|
|
@@ -1708,7 +2115,10 @@ export default class BundleGraph {
|
|
|
1708
2115
|
|
|
1709
2116
|
getReferencedBundles(
|
|
1710
2117
|
bundle: Bundle,
|
|
1711
|
-
opts?: {
|
|
2118
|
+
opts?: {
|
|
2119
|
+
recursive?: boolean;
|
|
2120
|
+
includeInline?: boolean;
|
|
2121
|
+
},
|
|
1712
2122
|
): Array<Bundle> {
|
|
1713
2123
|
let recursive = opts?.recursive ?? true;
|
|
1714
2124
|
let includeInline = opts?.includeInline ?? false;
|
|
@@ -1726,7 +2136,8 @@ export default class BundleGraph {
|
|
|
1726
2136
|
|
|
1727
2137
|
if (
|
|
1728
2138
|
includeInline ||
|
|
1729
|
-
node.value.bundleBehavior !== BundleBehavior.inline
|
|
2139
|
+
(node.value.bundleBehavior !== BundleBehavior.inline &&
|
|
2140
|
+
node.value.bundleBehavior !== BundleBehavior.inlineIsolated)
|
|
1730
2141
|
) {
|
|
1731
2142
|
referencedBundles.add(node.value);
|
|
1732
2143
|
}
|
|
@@ -1746,6 +2157,7 @@ export default class BundleGraph {
|
|
|
1746
2157
|
),
|
|
1747
2158
|
});
|
|
1748
2159
|
|
|
2160
|
+
// @ts-expect-error TS2322
|
|
1749
2161
|
return [...referencedBundles];
|
|
1750
2162
|
}
|
|
1751
2163
|
|
|
@@ -1768,7 +2180,7 @@ export default class BundleGraph {
|
|
|
1768
2180
|
});
|
|
1769
2181
|
}
|
|
1770
2182
|
|
|
1771
|
-
getAssetWithDependency(dep: Dependency):
|
|
2183
|
+
getAssetWithDependency(dep: Dependency): Asset | null | undefined {
|
|
1772
2184
|
if (!this._graph.hasContentKey(dep.id)) {
|
|
1773
2185
|
return null;
|
|
1774
2186
|
}
|
|
@@ -1777,6 +2189,7 @@ export default class BundleGraph {
|
|
|
1777
2189
|
let count = 0;
|
|
1778
2190
|
this._graph.forEachNodeIdConnectedTo(
|
|
1779
2191
|
this._graph.getNodeIdByContentKey(dep.id),
|
|
2192
|
+
// @ts-expect-error TS2345
|
|
1780
2193
|
(node) => {
|
|
1781
2194
|
res = node;
|
|
1782
2195
|
count += 1;
|
|
@@ -1817,16 +2230,16 @@ export default class BundleGraph {
|
|
|
1817
2230
|
|
|
1818
2231
|
filteredTraverse<TValue, TContext>(
|
|
1819
2232
|
bundleNodeId: NodeId,
|
|
1820
|
-
filter: (NodeId, TraversalActions) =>
|
|
2233
|
+
filter: (arg1: NodeId, arg2: TraversalActions) => TValue | null | undefined,
|
|
1821
2234
|
visit: GraphVisitor<TValue, TContext>,
|
|
1822
|
-
):
|
|
2235
|
+
): TContext | null | undefined {
|
|
1823
2236
|
return this._graph.filteredTraverse(filter, visit, bundleNodeId);
|
|
1824
2237
|
}
|
|
1825
2238
|
|
|
1826
2239
|
getSymbolResolution(
|
|
1827
2240
|
asset: Asset,
|
|
1828
2241
|
symbol: Symbol,
|
|
1829
|
-
boundary
|
|
2242
|
+
boundary?: Bundle | null,
|
|
1830
2243
|
): InternalSymbolResolution {
|
|
1831
2244
|
let assetOutside = boundary && !this.bundleHasAsset(boundary, asset);
|
|
1832
2245
|
|
|
@@ -1853,7 +2266,7 @@ export default class BundleGraph {
|
|
|
1853
2266
|
}
|
|
1854
2267
|
// If this is a re-export, find the original module.
|
|
1855
2268
|
let symbolLookup = new Map(
|
|
1856
|
-
[...depSymbols].map(([key, val]) => [val.local, key]),
|
|
2269
|
+
[...depSymbols].map(([key, val]: [any, any]) => [val.local, key]),
|
|
1857
2270
|
);
|
|
1858
2271
|
let depSymbol = symbolLookup.get(identifier);
|
|
1859
2272
|
if (depSymbol != null) {
|
|
@@ -1971,17 +2384,20 @@ export default class BundleGraph {
|
|
|
1971
2384
|
let result = identifier;
|
|
1972
2385
|
if (skipped) {
|
|
1973
2386
|
// ... and it was excluded (by symbol propagation) or deferred.
|
|
2387
|
+
// @ts-expect-error TS2322
|
|
1974
2388
|
result = false;
|
|
1975
2389
|
} else {
|
|
1976
2390
|
// ... and there is no single reexport, but it might still be exported:
|
|
1977
2391
|
if (found) {
|
|
1978
2392
|
// Fallback to namespace access, because of a bundle boundary.
|
|
2393
|
+
// @ts-expect-error TS2322
|
|
1979
2394
|
result = null;
|
|
1980
2395
|
} else if (result === undefined) {
|
|
1981
2396
|
// If not exported explicitly by the asset (= would have to be in * or a reexport-all) ...
|
|
1982
2397
|
if (nonStaticDependency || asset.symbols?.has('*')) {
|
|
1983
2398
|
// ... and if there are non-statically analyzable dependencies or it's a CJS asset,
|
|
1984
2399
|
// fallback to namespace access.
|
|
2400
|
+
// @ts-expect-error TS2322
|
|
1985
2401
|
result = null;
|
|
1986
2402
|
}
|
|
1987
2403
|
// (It shouldn't be possible for the symbol to be in a reexport-all and to end up here).
|
|
@@ -2019,13 +2435,13 @@ export default class BundleGraph {
|
|
|
2019
2435
|
|
|
2020
2436
|
getExportedSymbols(
|
|
2021
2437
|
asset: Asset,
|
|
2022
|
-
boundary
|
|
2438
|
+
boundary?: Bundle | null,
|
|
2023
2439
|
): Array<InternalExportSymbolResolution> {
|
|
2024
2440
|
if (!asset.symbols) {
|
|
2025
2441
|
return [];
|
|
2026
2442
|
}
|
|
2027
2443
|
|
|
2028
|
-
let symbols = [];
|
|
2444
|
+
let symbols: Array<InternalExportSymbolResolution> = [];
|
|
2029
2445
|
|
|
2030
2446
|
for (let symbol of asset.symbols.keys()) {
|
|
2031
2447
|
symbols.push({
|
|
@@ -2076,9 +2492,9 @@ export default class BundleGraph {
|
|
|
2076
2492
|
}
|
|
2077
2493
|
|
|
2078
2494
|
getInlineBundles(bundle: Bundle): Array<Bundle> {
|
|
2079
|
-
let bundles = [];
|
|
2495
|
+
let bundles: Array<Bundle> = [];
|
|
2080
2496
|
let seen = new Set();
|
|
2081
|
-
let addReferencedBundles = (bundle) => {
|
|
2497
|
+
let addReferencedBundles = (bundle: Bundle) => {
|
|
2082
2498
|
if (seen.has(bundle.id)) {
|
|
2083
2499
|
return;
|
|
2084
2500
|
}
|
|
@@ -2089,7 +2505,10 @@ export default class BundleGraph {
|
|
|
2089
2505
|
includeInline: true,
|
|
2090
2506
|
});
|
|
2091
2507
|
for (let referenced of referencedBundles) {
|
|
2092
|
-
if (
|
|
2508
|
+
if (
|
|
2509
|
+
referenced.bundleBehavior === BundleBehavior.inline ||
|
|
2510
|
+
referenced.bundleBehavior === BundleBehavior.inlineIsolated
|
|
2511
|
+
) {
|
|
2093
2512
|
bundles.push(referenced);
|
|
2094
2513
|
addReferencedBundles(referenced);
|
|
2095
2514
|
}
|
|
@@ -2099,7 +2518,10 @@ export default class BundleGraph {
|
|
|
2099
2518
|
addReferencedBundles(bundle);
|
|
2100
2519
|
|
|
2101
2520
|
this.traverseBundles((childBundle, _, traversal) => {
|
|
2102
|
-
if (
|
|
2521
|
+
if (
|
|
2522
|
+
childBundle.bundleBehavior === BundleBehavior.inline ||
|
|
2523
|
+
childBundle.bundleBehavior === BundleBehavior.inlineIsolated
|
|
2524
|
+
) {
|
|
2103
2525
|
bundles.push(childBundle);
|
|
2104
2526
|
} else if (childBundle.id !== bundle.id) {
|
|
2105
2527
|
traversal.skipChildren();
|
|
@@ -2128,7 +2550,9 @@ export default class BundleGraph {
|
|
|
2128
2550
|
hash.writeString(referencedBundle.id);
|
|
2129
2551
|
}
|
|
2130
2552
|
|
|
2131
|
-
hash.writeString(
|
|
2553
|
+
hash.writeString(
|
|
2554
|
+
JSON.stringify(objectSortedEntriesDeep(fromEnvironmentId(bundle.env))),
|
|
2555
|
+
);
|
|
2132
2556
|
return hash.finish();
|
|
2133
2557
|
}
|
|
2134
2558
|
|
|
@@ -2172,7 +2596,7 @@ export default class BundleGraph {
|
|
|
2172
2596
|
}
|
|
2173
2597
|
}
|
|
2174
2598
|
|
|
2175
|
-
getUsedSymbolsAsset(asset: Asset):
|
|
2599
|
+
getUsedSymbolsAsset(asset: Asset): ReadonlySet<Symbol> | null | undefined {
|
|
2176
2600
|
let node = this._graph.getNodeByContentKey(asset.id);
|
|
2177
2601
|
invariant(node && node.type === 'asset');
|
|
2178
2602
|
return node.value.symbols
|
|
@@ -2180,7 +2604,9 @@ export default class BundleGraph {
|
|
|
2180
2604
|
: null;
|
|
2181
2605
|
}
|
|
2182
2606
|
|
|
2183
|
-
getUsedSymbolsDependency(
|
|
2607
|
+
getUsedSymbolsDependency(
|
|
2608
|
+
dep: Dependency,
|
|
2609
|
+
): ReadonlySet<Symbol> | null | undefined {
|
|
2184
2610
|
let node = this._graph.getNodeByContentKey(dep.id);
|
|
2185
2611
|
invariant(node && node.type === 'dependency');
|
|
2186
2612
|
return node.value.symbols
|
|
@@ -2228,6 +2654,7 @@ export default class BundleGraph {
|
|
|
2228
2654
|
}
|
|
2229
2655
|
}
|
|
2230
2656
|
|
|
2657
|
+
// @ts-expect-error TS2488
|
|
2231
2658
|
for (let edge of other._graph.getAllEdges()) {
|
|
2232
2659
|
this._graph.addEdge(
|
|
2233
2660
|
nullthrows(otherGraphIdToThisNodeId.get(edge.from)),
|
|
@@ -2272,7 +2699,7 @@ export default class BundleGraph {
|
|
|
2272
2699
|
bundleGraphEdgeTypes.bundle,
|
|
2273
2700
|
);
|
|
2274
2701
|
|
|
2275
|
-
let entries = [];
|
|
2702
|
+
let entries: Array<FilePath> = [];
|
|
2276
2703
|
for (let bundleGroupId of entryBundleGroupIds) {
|
|
2277
2704
|
let bundleGroupNode = this._graph.getNode(bundleGroupId);
|
|
2278
2705
|
invariant(bundleGroupNode?.type === 'bundle_group');
|
|
@@ -2312,6 +2739,7 @@ export default class BundleGraph {
|
|
|
2312
2739
|
),
|
|
2313
2740
|
});
|
|
2314
2741
|
|
|
2742
|
+
// @ts-expect-error TS2322
|
|
2315
2743
|
return [...referencedBundles];
|
|
2316
2744
|
}
|
|
2317
2745
|
}
|