@ecopages/core 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -143
- package/package.json +16 -3
- package/src/adapters/node/dev-session.js +2 -1
- package/src/adapters/node/node-client-bridge.d.ts +5 -7
- package/src/adapters/node/node-client-bridge.js +4 -14
- package/src/adapters/node/server-adapter.d.ts +4 -2
- package/src/adapters/node/server-adapter.js +13 -12
- package/src/adapters/shared/hmr/client-bridge.d.ts +25 -0
- package/src/adapters/shared/hmr/client-bridge.js +35 -0
- package/src/adapters/shared/hmr/dev-transform-entrypoint-registry.js +1 -1
- package/src/adapters/shared/hmr/hmr-manager.d.ts +9 -2
- package/src/adapters/shared/hmr/hmr-manager.js +36 -6
- package/src/adapters/shared/http/dist-file-handler.js +3 -7
- package/src/adapters/shared/http/response-headers.d.ts +29 -0
- package/src/adapters/shared/http/response-headers.js +89 -0
- package/src/adapters/shared/runtime/copy-runtime-public-dir.js +1 -1
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +3 -2
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +4 -3
- package/src/adapters/shared/runtime/server-request-pipeline.js +4 -4
- package/src/adapters/shared/runtime/server-static-builder.d.ts +19 -8
- package/src/adapters/shared/runtime/server-static-builder.js +23 -4
- package/src/adapters/shared/ws/node-http-websocket-upgrades.d.ts +1 -1
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +23 -16
- package/src/assets/app-browser-client-build.d.ts +5 -12
- package/src/assets/app-browser-client-build.js +121 -336
- package/src/assets/asset-processing-service/app-browser-client-bundle.d.ts +4 -0
- package/src/assets/asset-processing-service/app-browser-client-bundle.js +6 -0
- package/src/assets/asset-processing-service/asset-dependency-keys.d.ts +28 -8
- package/src/assets/asset-processing-service/asset-dependency-keys.js +104 -29
- package/src/assets/asset-processing-service/asset-processing.service.d.ts +60 -2
- package/src/assets/asset-processing-service/asset-processing.service.js +189 -58
- package/src/assets/asset-processing-service/bundleable-script.d.ts +3 -0
- package/src/assets/asset-processing-service/bundleable-script.js +4 -0
- package/src/assets/asset-processing-service/grouped-content-bundles.d.ts +2 -2
- package/src/assets/asset-processing-service/grouped-content-bundles.js +5 -10
- package/src/assets/asset-processing-service/index.d.ts +0 -3
- package/src/assets/asset-processing-service/index.js +0 -3
- package/src/assets/asset-processing-service/last-good-output.d.ts +21 -0
- package/src/assets/asset-processing-service/last-good-output.js +32 -0
- package/src/assets/asset-processing-service/page-package.js +1 -4
- package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +63 -0
- package/src/assets/asset-processing-service/processed-asset-ledger.js +101 -0
- package/src/assets/asset-processing-service/processors/base/base-processor.js +1 -1
- package/src/assets/asset-processing-service/processors/base/base-script-processor.js +1 -1
- package/src/assets/asset-processing-service/processors/script/content-script.processor.d.ts +24 -0
- package/src/assets/asset-processing-service/processors/script/content-script.processor.js +59 -4
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +8 -4
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +18 -6
- package/src/assets/asset-processing-service/processors/script/node-module-script.processor.js +2 -3
- package/src/assets/asset-processing-service/processors/stylesheet/app-stylesheet-imports.d.ts +34 -0
- package/src/assets/asset-processing-service/processors/stylesheet/app-stylesheet-imports.js +115 -0
- package/src/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +2 -2
- package/src/assets/asset-processing-service/processors/stylesheet/css-module-types.d.ts +39 -0
- package/src/assets/asset-processing-service/processors/stylesheet/css-module-types.js +150 -0
- package/src/assets/asset-processing-service/processors/stylesheet/css-scanner.d.ts +84 -0
- package/src/assets/asset-processing-service/processors/stylesheet/css-scanner.js +379 -0
- package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +16 -0
- package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +50 -24
- package/src/assets/asset-processing-service/processors/stylesheet/import-order.d.ts +33 -0
- package/src/assets/asset-processing-service/processors/stylesheet/import-order.js +67 -0
- package/src/assets/asset-processing-service/processors/stylesheet/package-stylesheet.d.ts +44 -0
- package/src/assets/asset-processing-service/processors/stylesheet/package-stylesheet.js +149 -0
- package/src/assets/asset-processing-service/processors/stylesheet/processed-stylesheet-cache.d.ts +31 -0
- package/src/assets/asset-processing-service/processors/stylesheet/processed-stylesheet-cache.js +59 -0
- package/src/assets/asset-processing-service/processors/stylesheet/source-relative-stylesheet.d.ts +20 -0
- package/src/assets/asset-processing-service/processors/stylesheet/source-relative-stylesheet.js +51 -0
- package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-failure.d.ts +2 -0
- package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-failure.js +5 -0
- package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-module.d.ts +37 -0
- package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-module.js +48 -0
- package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.d.ts +25 -1
- package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-processor-pipeline.js +56 -15
- package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-warnings.d.ts +9 -0
- package/src/assets/asset-processing-service/processors/stylesheet/stylesheet-warnings.js +21 -0
- package/src/assets/browser-asset-output.js +1 -1
- package/src/assets/hashed-browser-asset.js +1 -1
- package/src/assets/{browser-runtime-asset-page-cache.d.ts → page-script-page-cache.d.ts} +3 -3
- package/src/assets/{browser-runtime-asset-page-cache.js → page-script-page-cache.js} +3 -3
- package/src/build/app-build-manifest-runtime.d.ts +23 -11
- package/src/build/app-build-manifest-runtime.js +52 -13
- package/src/build/browser/jsx-ownership-plugins.d.ts +4 -1
- package/src/build/browser/jsx-ownership-plugins.js +6 -0
- package/src/build/build-adapter.d.ts +1 -1
- package/src/build/build-adapter.js +1 -1
- package/src/build/build-graph.d.ts +4 -2
- package/src/build/build-graph.js +12 -46
- package/src/build/cache/build-input-dependency-index.d.ts +0 -19
- package/src/build/cache/build-input-dependency-index.js +1 -34
- package/src/build/cache/pages-unified-graph-build.js +7 -43
- package/src/build/cache/server-module-entries.d.ts +1 -1
- package/src/build/cache/server-module-entries.js +9 -9
- package/src/build/contracts/build-contracts.d.ts +59 -12
- package/src/build/contracts/build-manifest.d.ts +3 -6
- package/src/build/contracts/build-manifest.js +2 -12
- package/src/build/contracts/content-virtual-modules.js +1 -3
- package/src/build/copy-server-files.js +1 -1
- package/src/build/preserve-import-meta-transform.d.ts +3 -1
- package/src/build/preserve-import-meta-transform.js +7 -4
- package/src/build/production-asset-ledger.d.ts +36 -0
- package/src/build/production-asset-ledger.js +104 -0
- package/src/build/production-dist-complete.js +12 -13
- package/src/build/production-route-list.js +1 -1
- package/src/build/rolldown/app-package-declarations.js +1 -1
- package/src/build/rolldown/entry-module-closures.d.ts +5 -1
- package/src/build/rolldown/entry-module-closures.js +21 -8
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +19 -8
- package/src/build/rolldown/rolldown-adapter-helpers.js +82 -45
- package/src/build/rolldown/rolldown-build-adapter.js +10 -13
- package/src/build/rolldown/rolldown-module-id.d.ts +18 -0
- package/src/build/rolldown/rolldown-module-id.js +29 -0
- package/src/build/rolldown/rolldown-plugin-bridge.d.ts +24 -60
- package/src/build/rolldown/rolldown-plugin-bridge.js +201 -373
- package/src/build/rolldown/stylesheet-module-plugin.d.ts +34 -0
- package/src/build/rolldown/stylesheet-module-plugin.js +160 -0
- package/src/build/rolldown/worker-entries-plugin.d.ts +13 -0
- package/src/build/rolldown/worker-entries-plugin.js +57 -0
- package/src/build/runtime/build-environment-options.js +13 -3
- package/src/build/runtime/build-request-identity.js +1 -1
- package/src/build/runtime/build-request-policy.d.ts +7 -12
- package/src/build/runtime/build-request-policy.js +63 -17
- package/src/build/server/imported-view-plugin.d.ts +1 -0
- package/src/build/server/imported-view-plugin.js +6 -4
- package/src/build/server/page-module-import.service.d.ts +1 -2
- package/src/build/server/page-module-import.service.js +4 -6
- package/src/build/server/resolve-static-view.js +3 -2
- package/src/build/server/route-module-build-cache-registry.js +1 -1
- package/src/build/server/route-module-build-cache.store.js +1 -1
- package/src/build/server/route-module-build-manifest.js +1 -1
- package/src/build/server/route-module-dependency-hasher.d.ts +1 -1
- package/src/build/server/route-module-dependency-hasher.js +2 -2
- package/src/build/server/server-modules-manifest.d.ts +3 -5
- package/src/build/server/server-modules-manifest.js +6 -21
- package/src/build/server/view-module.d.ts +12 -0
- package/src/build/server/view-module.js +23 -0
- package/src/build/server/view-reference.d.ts +16 -5
- package/src/build/server/view-reference.js +25 -14
- package/src/build/server-bundle-deploy-manifest.d.ts +1 -1
- package/src/build/server-bundle-deploy-manifest.js +2 -2
- package/src/build/server-bundle-publication.d.ts +7 -1
- package/src/build/server-bundle-publication.js +11 -4
- package/src/build/server-module.js +1 -1
- package/src/build/worker-urls.d.ts +60 -0
- package/src/build/worker-urls.js +197 -0
- package/src/build.d.ts +7 -5
- package/src/build.js +7 -5
- package/src/cache/module-parse-cache.js +2 -2
- package/src/client/navigation-attributes.d.ts +8 -0
- package/src/client/navigation-attributes.js +8 -0
- package/src/client/navigation-scripts/global-scripts.d.ts +14 -0
- package/src/client/navigation-scripts/global-scripts.js +65 -0
- package/src/client/navigation-scripts/index.d.ts +1 -0
- package/src/client/navigation-scripts/index.js +1 -0
- package/src/client.d.ts +2 -2
- package/src/client.js +2 -2
- package/src/config/assembly/app-runtime.d.ts +45 -5
- package/src/config/assembly/app-runtime.js +11 -2
- package/src/config/assembly/finalize-config.js +13 -5
- package/src/config/config-module-files.js +10 -6
- package/src/config/index.d.ts +2 -1
- package/src/config/internal-types.d.ts +3 -0
- package/src/config/load-eco-config.js +8 -5
- package/src/config/resolve-eco-config-path.js +3 -3
- package/src/config/server-config-bundle.js +1 -1
- package/src/config/user-config-types.d.ts +54 -1
- package/src/config/write-types.js +4 -1
- package/src/css-imports.d.ts +12 -0
- package/src/declarations.d.ts +2 -0
- package/src/dev/development-restart-watch-paths.js +1 -1
- package/src/dev/development-restart.js +1 -1
- package/src/dev/invalidation/development-invalidation.service.d.ts +6 -1
- package/src/dev/invalidation/development-invalidation.service.js +18 -2
- package/src/dev/stylesheets/development-stylesheet.service.d.ts +149 -0
- package/src/dev/stylesheets/development-stylesheet.service.js +350 -0
- package/src/dev/transform-server/dev-transform-bundler.d.ts +12 -3
- package/src/dev/transform-server/dev-transform-bundler.js +32 -21
- package/src/dev/transform-server/dev-transform-externalize-plugin.d.ts +3 -5
- package/src/dev/transform-server/dev-transform-externalize-plugin.js +8 -9
- package/src/dev/transform-server/dev-transform-import-rewriter.d.ts +15 -2
- package/src/dev/transform-server/dev-transform-import-rewriter.js +204 -35
- package/src/dev/transform-server/dev-transform-install-stamp.d.ts +17 -0
- package/src/dev/transform-server/dev-transform-install-stamp.js +79 -0
- package/src/dev/transform-server/dev-transform-server.d.ts +38 -2
- package/src/dev/transform-server/dev-transform-server.js +96 -33
- package/src/dev/transform-server/dev-transform-url.d.ts +4 -2
- package/src/dev/transform-server/dev-transform-url.js +13 -12
- package/src/dev/transform-server/dev-transform-vendor-registry.d.ts +178 -21
- package/src/dev/transform-server/dev-transform-vendor-registry.js +675 -99
- package/src/dev/transform-server/index.d.ts +1 -1
- package/src/dev-toolbar/dev-toolbar-package.js +4 -4
- package/src/eco/component-render-output.d.ts +6 -1
- package/src/eco/component-render-output.js +32 -7
- package/src/eco/discovered-dependencies.d.ts +30 -11
- package/src/eco/discovered-dependencies.js +25 -13
- package/src/eco/discovered-dependency-paths.d.ts +36 -0
- package/src/eco/discovered-dependency-paths.js +58 -0
- package/src/eco/eco.browser.js +8 -12
- package/src/eco/eco.js +0 -30
- package/src/eco/mdx-page-metadata.d.ts +14 -0
- package/src/eco/mdx-page-metadata.js +15 -0
- package/src/eco/page-layout-normalization.d.ts +6 -2
- package/src/eco/page-layout-normalization.js +9 -6
- package/src/env.js +17 -0
- package/src/hmr/client/hmr-runtime.js +14 -13
- package/src/hmr/dev-client-runtime.d.ts +5 -2
- package/src/hmr/dev-client-runtime.js +14 -4
- package/src/hmr/hmr-entrypoint-output.js +1 -1
- package/src/hmr/hmr-strategy.d.ts +2 -2
- package/src/hmr/hmr-strategy.js +2 -2
- package/src/hmr/strategies/js-hmr-strategy.d.ts +4 -1
- package/src/hmr/strategies/js-hmr-strategy.js +7 -6
- package/src/hmr/strategies/template-source-hmr-strategy.d.ts +25 -0
- package/src/hmr/strategies/template-source-hmr-strategy.js +36 -0
- package/src/html-pages/html-page-module-scripts.d.ts +2 -1
- package/src/html-pages/html-page-module-scripts.js +37 -14
- package/src/html-pages/html-page-module.js +1 -1
- package/src/html-pages/html-page-renderer.js +7 -6
- package/src/html-pages/html-page-template.d.ts +0 -5
- package/src/html-pages/html-page-template.js +3 -15
- package/src/html-pages/html-pages.plugin.js +2 -2
- package/src/integration.d.ts +8 -6
- package/src/integration.js +5 -3
- package/src/page-cache/html-page-cache-dependency-index.js +1 -1
- package/src/page-cache/page-cache-service.js +1 -1
- package/src/plugins/alias-resolver-plugin.d.ts +7 -0
- package/src/plugins/alias-resolver-plugin.js +16 -6
- package/src/plugins/component-import-discovery.d.ts +178 -7
- package/src/plugins/component-import-discovery.js +696 -112
- package/src/plugins/eco-component-meta-plugin.d.ts +47 -6
- package/src/plugins/eco-component-meta-plugin.js +227 -59
- package/src/plugins/foreign-jsx-override-plugin.d.ts +14 -1
- package/src/plugins/foreign-jsx-override-plugin.js +18 -8
- package/src/plugins/integration-plugin.d.ts +47 -11
- package/src/plugins/integration-plugin.js +57 -8
- package/src/plugins/processor.d.ts +72 -7
- package/src/plugins/processor.js +44 -9
- package/src/plugins/stylesheet-kinds.d.ts +57 -0
- package/src/plugins/stylesheet-kinds.js +114 -0
- package/src/plugins/tsconfig-import-resolver.d.ts +49 -3
- package/src/plugins/tsconfig-import-resolver.js +120 -6
- package/src/processor-contract.d.ts +66 -0
- package/src/processor-contract.js +389 -0
- package/src/processor.d.ts +6 -1
- package/src/processor.js +6 -1
- package/src/route-renderer/error-pages/default-error-pages.d.ts +1 -0
- package/src/route-renderer/error-pages/default-error-pages.js +27 -7
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +8 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +12 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +77 -24
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +97 -32
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +1 -1
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +9 -0
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +16 -2
- package/src/route-renderer/orchestration/document-shell/layout-children-not-rendered-error.d.ts +35 -0
- package/src/route-renderer/orchestration/document-shell/layout-children-not-rendered-error.js +53 -0
- package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +4 -8
- package/src/route-renderer/orchestration/foreign-child/render-session.js +2 -5
- package/src/route-renderer/orchestration/integration-renderer.d.ts +171 -64
- package/src/route-renderer/orchestration/integration-renderer.js +293 -332
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +8 -5
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +27 -25
- package/src/route-renderer/orchestration/ownership-graph/component-graph.d.ts +0 -6
- package/src/route-renderer/orchestration/page-browser-graph/global-injector-assets.service.js +3 -3
- package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.d.ts +12 -25
- package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.js +1 -14
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +0 -16
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -87
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +8 -16
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +25 -271
- package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +0 -24
- package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +0 -67
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +28 -15
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +63 -41
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -1
- package/src/route-renderer/page-loading/component-dependency-collection.js +51 -15
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +10 -0
- package/src/route-renderer/page-loading/dependency-resolver.js +27 -6
- package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +4 -2
- package/src/route-renderer/page-loading/file-scoped-dependency-components.js +22 -17
- package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +5 -0
- package/src/route-renderer/page-loading/lazy-entry-collection.js +6 -4
- package/src/route-renderer/page-loading/page-dependency-bundling.d.ts +5 -2
- package/src/route-renderer/page-loading/page-dependency-bundling.js +15 -31
- package/src/route-renderer/page-loading/page-module-loader.d.ts +13 -2
- package/src/route-renderer/page-loading/page-module-loader.js +23 -5
- package/src/route-renderer/route-renderer.d.ts +1 -1
- package/src/router/client/navigation-commit.d.ts +2 -0
- package/src/router/client/navigation-commit.js +20 -3
- package/src/router/client/navigation-coordinator.d.ts +18 -0
- package/src/router/client/navigation-coordinator.js +14 -0
- package/src/router/client/navigation-head-order.fixture.css +3 -0
- package/src/router/client/navigation-head.d.ts +2 -1
- package/src/router/client/navigation-head.fixture.css +3 -0
- package/src/router/client/navigation-head.js +222 -39
- package/src/router/client/navigation-lifecycle.d.ts +8 -1
- package/src/router/client/navigation-lifecycle.js +6 -3
- package/src/router/client/navigation-pipeline.d.ts +1 -0
- package/src/router/client/navigation-pipeline.js +1 -0
- package/src/router/server/route-registry.d.ts +3 -2
- package/src/router/server/route-registry.js +6 -5
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +30 -18
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +82 -143
- package/src/static-site-generator/static-site-generator.d.ts +37 -4
- package/src/static-site-generator/static-site-generator.js +99 -51
- package/src/types/asset-types.d.ts +19 -1
- package/src/types/build-types.d.ts +53 -35
- package/src/types/component-identity.d.ts +8 -0
- package/src/types/contracts.d.ts +69 -21
- package/src/types/dev-transform-types.d.ts +33 -6
- package/src/types/eco-api-types.d.ts +13 -18
- package/src/types/integration-types.d.ts +1 -1
- package/src/types/public-types.d.ts +1 -1
- package/src/utils/additional-watch-paths.js +3 -5
- package/src/utils/entry-command-flags.d.ts +23 -0
- package/src/utils/entry-command-flags.js +24 -0
- package/src/utils/package-path.d.ts +42 -0
- package/src/utils/package-path.js +114 -0
- package/src/utils/parse-cli-args.d.ts +18 -1
- package/src/utils/parse-cli-args.js +54 -37
- package/src/utils/path-containment.js +3 -10
- package/src/utils/resolve-work-dir.js +2 -2
- package/src/utils/root-relative-path.js +2 -2
- package/src/utils/server-bundle-context.d.ts +5 -0
- package/src/utils/server-bundle-context.js +7 -1
- package/src/utils/server-utils.module.js +1 -1
- package/src/watchers/project-watcher-ignore.js +3 -3
- package/src/watchers/project-watcher.d.ts +14 -2
- package/src/watchers/project-watcher.js +37 -6
- package/src/watchers/workspace-package-watch-roots.js +2 -2
- package/src/assets/app-browser-client-manifest.d.ts +0 -66
- package/src/assets/app-browser-client-manifest.js +0 -260
- package/src/assets/asset-processing-service/asset-package-role.d.ts +0 -2
- package/src/assets/asset-processing-service/asset-package-role.js +0 -3
- package/src/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +0 -58
- package/src/assets/asset-processing-service/browser-runtime-asset.factory.js +0 -61
- package/src/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +0 -79
- package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +0 -200
- package/src/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +0 -24
- package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +0 -67
- package/src/build/browser/browser-runtime-manifest.d.ts +0 -35
- package/src/build/browser/browser-runtime-manifest.js +0 -65
- package/src/build/browser/browser-runtime-plugin-helpers.d.ts +0 -14
- package/src/build/browser/browser-runtime-plugin-helpers.js +0 -21
- package/src/build/browser/browser-runtime-plugin.d.ts +0 -54
- package/src/build/browser/browser-runtime-plugin.js +0 -76
- package/src/build/rolldown/server-side-css-shim-plugin.d.ts +0 -28
- package/src/build/rolldown/server-side-css-shim-plugin.js +0 -59
- package/src/dev/transform-server/dev-transform-module-kind.d.ts +0 -13
- package/src/dev/transform-server/dev-transform-module-kind.js +0 -17
- package/src/dev/transform-server/dev-transform-runtime-specifiers.d.ts +0 -5
- package/src/dev/transform-server/dev-transform-runtime-specifiers.js +0 -16
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +0 -15
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +0 -65
- package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +0 -21
- package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +0 -31
|
@@ -1,183 +1,759 @@
|
|
|
1
1
|
import { contentHash } from '../../utils/content-hash.js';
|
|
2
|
-
import path from '
|
|
2
|
+
import { path } from '@ecopages/file-system/path';
|
|
3
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
3
4
|
import { RESOLVED_ASSETS_VENDORS_DIR } from '../../constants.js';
|
|
4
5
|
import { resolveAppBuildPlugins } from '../../build/runtime/build-request-policy.js';
|
|
5
|
-
import {
|
|
6
|
+
import { clearBarePackageResolverCaches, resolveBarePackageBrowserEntry, } from '../../plugins/tsconfig-import-resolver.js';
|
|
6
7
|
import { toPackageRootSpecifier } from '../../plugins/package-specifier.js';
|
|
7
8
|
import { BrowserBundleService } from '../../assets/browser-bundle.service.js';
|
|
8
|
-
import {
|
|
9
|
+
import { formatBuildLog } from '../../build/build-log.js';
|
|
10
|
+
import { appLogger } from '../../global/app-logger.js';
|
|
11
|
+
import { parseModuleSource } from '../../cache/module-parse-cache.js';
|
|
12
|
+
import { escapeRegExp } from '../../utils/regex-escaping.js';
|
|
9
13
|
const BROWSER_FIRST_VENDOR_CONDITIONS = ['browser', 'module', 'import', 'default'];
|
|
10
14
|
const MODULE_FIRST_VENDOR_CONDITIONS = ['module', 'import', 'default'];
|
|
11
15
|
const BROWSER_NODE_BUILTIN_GUARD_MARKER = '[browser-build] Node builtin';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
const VENDOR_GRAPH_QUIET_PERIOD_MS = 50;
|
|
17
|
+
const VENDOR_GRAPH_RETRY_BACKOFF_MS = 2_000;
|
|
18
|
+
const VENDOR_ENTRIES_FILE = 'dev-vendor-entries.json';
|
|
19
|
+
/** Whether a package file has an `import` or `export` statement, which makes it an ES module rather than CommonJS. */
|
|
20
|
+
function hasModuleSyntax(filePath) {
|
|
21
|
+
try {
|
|
22
|
+
return parseModuleSource(filePath, fileSystem.readFileSync(filePath)).module.hasModuleSyntax;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
16
27
|
}
|
|
28
|
+
const BROWSER_FIRST_PACKAGE = '@ecopages/core';
|
|
29
|
+
const BROWSER_FIRST_SPECIFIER = new RegExp(`^${escapeRegExp(BROWSER_FIRST_PACKAGE)}(?:/|$)`, 'u');
|
|
30
|
+
const PIN_ENTRY_NAME = '__eco_vendor_pin';
|
|
31
|
+
const PIN_SPECIFIER = 'ecopages:vendor-pin';
|
|
32
|
+
const PIN_MODULE_ID = '\0ecopages-vendor-pin';
|
|
17
33
|
/**
|
|
18
|
-
*
|
|
34
|
+
* Adds an entry to each vendor build that keeps the shape of the other entries the same from one build to the next.
|
|
19
35
|
*
|
|
20
36
|
* @remarks
|
|
21
|
-
* A vendor
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
37
|
+
* A browser that loaded a vendor file keeps its module, so a later build of the graph must not change a file it
|
|
38
|
+
* already served; when it does, the page reloads. Two things would change one as packages arrive. Rolldown puts the
|
|
39
|
+
* helpers its CommonJS interop needs in one shared runtime chunk, keeps only the ones the build uses and names the
|
|
40
|
+
* chunk after its content, so a package that needs one more helper renames it in every entry that imports it. And a
|
|
41
|
+
* CommonJS entry exports its module's `require` function only once another entry imports it, so a package that
|
|
42
|
+
* imports `react/jsx-runtime` adds an export to that entry. The pin re-exports every helper and the namespace of every
|
|
43
|
+
* entry whose file has no `import` or `export` statement, so each runtime helper and each CommonJS `require` export is
|
|
44
|
+
* there from the first build. It leaves ES module entries alone: importing one would move its code into a shared
|
|
45
|
+
* chunk behind the entry. Nothing requests the pin's own output.
|
|
46
|
+
*/
|
|
47
|
+
function exactly(value) {
|
|
48
|
+
return new RegExp(`^${escapeRegExp(value)}$`, 'u');
|
|
49
|
+
}
|
|
50
|
+
function createVendorPinPlugin(entries) {
|
|
51
|
+
const contents = [
|
|
52
|
+
'export * from "\\0rolldown/runtime.js";',
|
|
53
|
+
...entries
|
|
54
|
+
.filter((entry) => !hasModuleSyntax(entry.entryPath))
|
|
55
|
+
.map((entry, index) => `export * as __eco_pin_${index} from ${JSON.stringify(entry.entryPath)};`),
|
|
56
|
+
].join('\n');
|
|
57
|
+
return {
|
|
58
|
+
name: 'ecopages-dev-vendor-pin',
|
|
59
|
+
cacheKey: contents,
|
|
60
|
+
setup(build) {
|
|
61
|
+
build.onResolve({ filter: exactly(PIN_SPECIFIER) }, () => ({ path: PIN_MODULE_ID }));
|
|
62
|
+
build.onLoad({ filter: exactly(PIN_MODULE_ID) }, () => ({ contents, loader: 'js' }));
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function getVendorGraphKey(specifier) {
|
|
67
|
+
return toPackageRootSpecifier(specifier) === BROWSER_FIRST_PACKAGE ? 'browser-first' : 'module-first';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Prebundles bare npm imports into process-local `/assets/vendors/*` files, one code-split Rolldown build per
|
|
71
|
+
* vendor graph.
|
|
72
|
+
*
|
|
73
|
+
* @remarks
|
|
74
|
+
* Every known dependency entry is an entry of one build, so a file shared by two entries of a package, a package
|
|
75
|
+
* shared by two packages, and a CommonJS module required by two packages each become one shared chunk with one
|
|
76
|
+
* URL. Entry URLs are `<label>.<hash of the entry path>.js` and stay the same across rebuilds, so app modules
|
|
77
|
+
* that embed them stay valid; chunks are content-hashed and imported relatively from the same directory.
|
|
78
|
+
*
|
|
79
|
+
* A new entry rebuilds its graph after a short quiet period, which collects the bare imports of one page load
|
|
80
|
+
* into one build. The known entries are written to the app's `workDir` after each build and seed the next dev
|
|
81
|
+
* process, which then builds the full graph on its first request. Bundle contents stay in memory.
|
|
82
|
+
*
|
|
83
|
+
* A build that fails as a whole, rather than for some of its entries, keeps the previous build's outputs, so a
|
|
84
|
+
* transient failure such as one during a package install leaves working vendors serving.
|
|
25
85
|
*/
|
|
26
86
|
export class DevTransformVendorRegistry {
|
|
27
87
|
appConfig;
|
|
28
88
|
browserBundleService;
|
|
29
89
|
resolveVendorBundlePlugins;
|
|
30
|
-
|
|
31
|
-
|
|
90
|
+
onVendorGraphChange;
|
|
91
|
+
graphs = new Map();
|
|
92
|
+
entriesByUrl = new Map();
|
|
93
|
+
generation = 0;
|
|
94
|
+
warnedPackageCopies = new Set();
|
|
95
|
+
persistedContents;
|
|
32
96
|
constructor(options) {
|
|
33
97
|
this.appConfig = options.appConfig;
|
|
34
98
|
this.browserBundleService = new BrowserBundleService(options.appConfig);
|
|
35
99
|
this.resolveVendorBundlePlugins = options.resolveVendorBundlePlugins;
|
|
100
|
+
this.onVendorGraphChange = options.onVendorGraphChange;
|
|
101
|
+
this.graphs.set('browser-first', createVendorGraph('browser-first', BROWSER_FIRST_VENDOR_CONDITIONS));
|
|
102
|
+
this.graphs.set('module-first', createVendorGraph('module-first', MODULE_FIRST_VENDOR_CONDITIONS));
|
|
103
|
+
this.seedPersistedEntries();
|
|
36
104
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Returns the stable vendor URL of a bare specifier once a build of its graph that contains it finished.
|
|
107
|
+
*
|
|
108
|
+
* @param importer - The importing module's path; defaults to a module at the app root.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* Rejects with the prebundle error when the entry failed to build.
|
|
112
|
+
*/
|
|
113
|
+
async resolveVendorUrl(specifier, importer) {
|
|
114
|
+
const resolveDir = importer ? resolveImporterDir(importer) : this.rootResolveDir;
|
|
115
|
+
return (await this.resolveVendorEntry(specifier, resolveDir)).url;
|
|
42
116
|
}
|
|
43
117
|
/**
|
|
118
|
+
* Returns the vendor URL of a bare specifier imported by `importer`, and whether that build found its module to
|
|
119
|
+
* be CommonJS.
|
|
120
|
+
*
|
|
44
121
|
* @remarks
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
122
|
+
* The specifier resolves from the importer's directory, as Node and the production bundle resolve it, so a
|
|
123
|
+
* dependency that only the importing package declares resolves under a strict install, and two importers that
|
|
124
|
+
* reach two installed versions of one package get two entries. Importers that resolve it to the same file share
|
|
125
|
+
* one entry and one URL.
|
|
126
|
+
*
|
|
127
|
+
* A CommonJS entry is served with `module.exports` as its default export and no named exports, so the import
|
|
128
|
+
* rewriter reads named imports of it from the default export.
|
|
129
|
+
*/
|
|
130
|
+
resolveVendorImport(specifier, importer) {
|
|
131
|
+
return this.resolveVendorEntry(specifier, resolveImporterDir(importer));
|
|
132
|
+
}
|
|
133
|
+
async resolveVendorEntry(specifier, resolveDir) {
|
|
134
|
+
const entryPath = this.resolvePackageEntry(specifier, resolveDir);
|
|
135
|
+
const { graph, entry } = this.addEntry(specifier, resolveDir, entryPath);
|
|
136
|
+
const build = await this.waitForBuildContaining(graph, entry.entryPath);
|
|
137
|
+
const error = build.errors.get(entry.entryPath);
|
|
138
|
+
if (error) {
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
return { url: entry.url, commonJs: build.commonJsEntryPaths.has(entry.entryPath) };
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @remarks
|
|
145
|
+
* A request for a known entry whose graph is still building, or was invalidated, waits for a build that
|
|
146
|
+
* contains it. A chunk is only requested by a file that a finished build served, and a rebuild that changes a
|
|
147
|
+
* served file reports a graph change, so a chunk request does not wait. Responses carry `no-cache` and a
|
|
148
|
+
* content `ETag`, so browsers revalidate each load and get `304` while `ifNoneMatch` still matches the
|
|
149
|
+
* in-memory output.
|
|
48
150
|
*/
|
|
49
151
|
async tryHandleVendorRequest(pathname, ifNoneMatch) {
|
|
50
152
|
if (!pathname.startsWith(`/${RESOLVED_ASSETS_VENDORS_DIR}/`)) {
|
|
51
153
|
return null;
|
|
52
154
|
}
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
155
|
+
const found = await this.findOutput(pathname);
|
|
156
|
+
if (!found) {
|
|
55
157
|
return null;
|
|
56
158
|
}
|
|
57
|
-
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
return new Response(error instanceof Error ? error.message : String(error), {
|
|
159
|
+
if ('error' in found) {
|
|
160
|
+
return new Response(found.error.message, {
|
|
62
161
|
status: 500,
|
|
63
162
|
headers: { 'Content-Type': 'text/plain', 'Cache-Control': 'no-store' },
|
|
64
163
|
});
|
|
65
164
|
}
|
|
165
|
+
found.build.servedUrls.add(found.url);
|
|
166
|
+
return createVendorResponse(found.url, found.content, ifNoneMatch);
|
|
66
167
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Adds the entries of bare specifiers that modules are known to import, without building.
|
|
170
|
+
*
|
|
171
|
+
* @param resolveFrom - A directory inside the package that declares them, which they resolve from.
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
* Generated modules such as hydration bootstraps import their packages one request after another. Knowing
|
|
175
|
+
* them up front puts them all in the first build of their graph, so a later build does not move a module a
|
|
176
|
+
* browser already loaded into a new shared chunk and reload the page. A specifier that does not resolve is
|
|
177
|
+
* skipped.
|
|
178
|
+
*/
|
|
179
|
+
addKnownEntries({ resolveFrom, specifiers }) {
|
|
180
|
+
const resolveDir = resolveDirectory(resolveFrom);
|
|
181
|
+
for (const specifier of specifiers) {
|
|
182
|
+
const resolved = resolveBarePackageBrowserEntry(this.appConfig.rootDir, specifier, resolveDir);
|
|
183
|
+
if (resolved)
|
|
184
|
+
this.addEntry(specifier, resolveDir, resolved.path);
|
|
185
|
+
}
|
|
70
186
|
}
|
|
71
187
|
/**
|
|
72
|
-
*
|
|
188
|
+
* Rebuilds every graph on its next request and resolves each known specifier again, keeping the known
|
|
189
|
+
* entries.
|
|
73
190
|
*
|
|
74
191
|
* @remarks
|
|
75
|
-
*
|
|
76
|
-
*
|
|
192
|
+
* A build that started before this call still settles for its waiters but is not kept. The last build is kept
|
|
193
|
+
* only as the fallback of a rebuild that fails as a whole. Each specifier resolves again from every directory
|
|
194
|
+
* that reached its entry, so after a package upgrade each importer moves to the file it now reaches; an entry
|
|
195
|
+
* that no source resolves any more is kept as it was. A source whose directory no longer exists, such as a
|
|
196
|
+
* deleted workspace package, is dropped, and an entry left without sources goes with it.
|
|
197
|
+
*/
|
|
198
|
+
invalidateAll() {
|
|
199
|
+
this.generation += 1;
|
|
200
|
+
clearBarePackageResolverCaches();
|
|
201
|
+
for (const graph of this.graphs.values()) {
|
|
202
|
+
graph.failed.clear();
|
|
203
|
+
const previous = [...graph.entries.values()];
|
|
204
|
+
graph.entries.clear();
|
|
205
|
+
for (const entry of previous)
|
|
206
|
+
this.entriesByUrl.delete(entry.url);
|
|
207
|
+
for (const entry of previous) {
|
|
208
|
+
const sources = entry.sources.filter((source) => fileSystem.exists(source.resolveDir));
|
|
209
|
+
if (sources.length === 0)
|
|
210
|
+
continue;
|
|
211
|
+
let reached = false;
|
|
212
|
+
for (const source of sources) {
|
|
213
|
+
const resolved = resolveBarePackageBrowserEntry(this.appConfig.rootDir, source.specifier, source.resolveDir);
|
|
214
|
+
if (!resolved)
|
|
215
|
+
continue;
|
|
216
|
+
this.addEntry(source.specifier, source.resolveDir, resolved.path);
|
|
217
|
+
reached = true;
|
|
218
|
+
}
|
|
219
|
+
if (!reached && !graph.entries.has(entry.entryPath)) {
|
|
220
|
+
entry.sources = sources;
|
|
221
|
+
graph.entries.set(entry.entryPath, entry);
|
|
222
|
+
this.entriesByUrl.set(entry.url, { graph, entry });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* @remarks
|
|
229
|
+
* Entries are keyed by the resolved file, so importers that reach one file share its entry and URL; the first
|
|
230
|
+
* specifier names the URL, and every specifier and directory pair is kept as a source of the entry.
|
|
77
231
|
*/
|
|
78
|
-
|
|
79
|
-
const
|
|
232
|
+
addEntry(specifier, resolveDir, entryPath) {
|
|
233
|
+
const graph = this.requireGraph(getVendorGraphKey(specifier));
|
|
234
|
+
const existing = graph.entries.get(entryPath);
|
|
80
235
|
if (existing) {
|
|
81
|
-
|
|
236
|
+
if (!existing.sources.some((source) => source.specifier === specifier && source.resolveDir === resolveDir)) {
|
|
237
|
+
existing.sources.push({ specifier, resolveDir });
|
|
238
|
+
}
|
|
239
|
+
return { graph, entry: existing };
|
|
82
240
|
}
|
|
83
|
-
const
|
|
84
|
-
const record = {
|
|
241
|
+
const entry = {
|
|
85
242
|
specifier,
|
|
86
243
|
entryPath,
|
|
87
244
|
url: `/${RESOLVED_ASSETS_VENDORS_DIR}/${sanitizeSpecifierForFileName(specifier)}.${contentHash(entryPath, 8)}.js`,
|
|
88
|
-
|
|
245
|
+
sources: [{ specifier, resolveDir }],
|
|
89
246
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
247
|
+
graph.entries.set(entryPath, entry);
|
|
248
|
+
this.entriesByUrl.set(entry.url, { graph, entry });
|
|
249
|
+
this.warnOnDuplicatePackageCopies(specifier);
|
|
250
|
+
return { graph, entry };
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Warns when the package of `specifier` is reached in more than one installed copy.
|
|
254
|
+
*
|
|
255
|
+
* @remarks
|
|
256
|
+
* Each copy is its own vendor entry and loads as its own module, as in the production build. That is right for
|
|
257
|
+
* two versions an app means to have, but an accidental second copy of a package such as React, from a pnpm peer
|
|
258
|
+
* variant or a workspace package with its own install, otherwise surfaces only as a confusing runtime error.
|
|
259
|
+
* The warning names each copy's directory and the directories of the modules that import it, once per set of
|
|
260
|
+
* copies.
|
|
261
|
+
*/
|
|
262
|
+
warnOnDuplicatePackageCopies(specifier) {
|
|
263
|
+
const packageName = toPackageRootSpecifier(specifier);
|
|
264
|
+
const copies = new Map();
|
|
265
|
+
for (const graph of this.graphs.values()) {
|
|
266
|
+
for (const entry of graph.entries.values()) {
|
|
267
|
+
if (toPackageRootSpecifier(entry.specifier) !== packageName)
|
|
268
|
+
continue;
|
|
269
|
+
const packageDir = findPackageDir(entry.entryPath, packageName);
|
|
270
|
+
const importers = copies.get(packageDir) ?? new Set();
|
|
271
|
+
for (const source of entry.sources)
|
|
272
|
+
importers.add(source.resolveDir);
|
|
273
|
+
copies.set(packageDir, importers);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (copies.size < 2)
|
|
277
|
+
return;
|
|
278
|
+
const key = `${packageName}\0${[...copies.keys()].sort().join('\0')}`;
|
|
279
|
+
if (this.warnedPackageCopies.has(key))
|
|
280
|
+
return;
|
|
281
|
+
this.warnedPackageCopies.add(key);
|
|
282
|
+
const lines = [...copies].map(([packageDir, importers]) => ` ${packageDir}\n imported from ${[...importers].join(', ')}`);
|
|
283
|
+
appLogger.warn(`[dev-transform] Package "${packageName}" resolves to ${copies.size} installed copies, and each loads as its own module:\n${lines.join('\n')}`);
|
|
284
|
+
}
|
|
285
|
+
requireGraph(key) {
|
|
286
|
+
const graph = this.graphs.get(key);
|
|
287
|
+
if (!graph) {
|
|
288
|
+
throw new Error(`[dev-transform] Unknown vendor graph ${key}`);
|
|
289
|
+
}
|
|
290
|
+
return graph;
|
|
291
|
+
}
|
|
292
|
+
waitForBuildContaining(graph, entryPath) {
|
|
293
|
+
const current = this.currentBuild(graph);
|
|
294
|
+
if (current?.entryPaths.has(entryPath) && !isRetryDue(current, entryPath)) {
|
|
295
|
+
return Promise.resolve(current);
|
|
296
|
+
}
|
|
297
|
+
if (graph.running?.generation === this.generation && graph.running.entryPaths.has(entryPath)) {
|
|
298
|
+
return graph.running.promise;
|
|
299
|
+
}
|
|
300
|
+
return this.scheduleBuild(graph);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Schedules a build of every known entry of `graph` after a quiet period, restarting the period on each call.
|
|
304
|
+
*
|
|
305
|
+
* @remarks
|
|
306
|
+
* Builds of one graph run one at a time through its queue, and the entry list is read when a build starts, so
|
|
307
|
+
* an entry added while a build runs lands in the next one.
|
|
308
|
+
*/
|
|
309
|
+
scheduleBuild(graph) {
|
|
310
|
+
if (graph.scheduled) {
|
|
311
|
+
clearTimeout(graph.scheduled.timer);
|
|
312
|
+
graph.scheduled.timer = setTimeout(() => this.startBuild(graph), VENDOR_GRAPH_QUIET_PERIOD_MS);
|
|
313
|
+
return graph.scheduled.promise;
|
|
314
|
+
}
|
|
315
|
+
let resolve = () => { };
|
|
316
|
+
const promise = new Promise((resolvePromise) => {
|
|
317
|
+
resolve = resolvePromise;
|
|
97
318
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
319
|
+
graph.scheduled = {
|
|
320
|
+
promise,
|
|
321
|
+
resolve,
|
|
322
|
+
timer: setTimeout(() => this.startBuild(graph), VENDOR_GRAPH_QUIET_PERIOD_MS),
|
|
323
|
+
};
|
|
324
|
+
return promise;
|
|
325
|
+
}
|
|
326
|
+
startBuild(graph) {
|
|
327
|
+
const scheduled = graph.scheduled;
|
|
328
|
+
if (!scheduled) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
graph.scheduled = undefined;
|
|
332
|
+
graph.queue = graph.queue.then(() => this.runBuild(graph, scheduled));
|
|
333
|
+
}
|
|
334
|
+
async runBuild(graph, scheduled) {
|
|
335
|
+
const generation = this.generation;
|
|
336
|
+
const entries = [...graph.entries.values()];
|
|
337
|
+
const promise = this.buildGraph(graph, entries, new Map(graph.failed), generation);
|
|
338
|
+
const running = {
|
|
339
|
+
generation,
|
|
340
|
+
entryPaths: new Set(entries.map((entry) => entry.entryPath)),
|
|
341
|
+
promise,
|
|
342
|
+
};
|
|
343
|
+
graph.running = running;
|
|
344
|
+
const build = await promise;
|
|
345
|
+
if (graph.running === running) {
|
|
346
|
+
graph.running = undefined;
|
|
347
|
+
}
|
|
348
|
+
try {
|
|
349
|
+
if (generation === this.generation) {
|
|
350
|
+
this.commitBuild(graph, build);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
appLogger.error(`[dev-transform] Vendor graph update failed: ${String(error)}`);
|
|
355
|
+
}
|
|
356
|
+
finally {
|
|
357
|
+
scheduled.resolve(build);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* @remarks
|
|
362
|
+
* A file the previous build served and this build left unchanged counts as served by this one too, so a later
|
|
363
|
+
* build that changes it still reports the change.
|
|
364
|
+
*/
|
|
365
|
+
commitBuild(graph, build) {
|
|
366
|
+
const previous = graph.current;
|
|
367
|
+
graph.current = build;
|
|
368
|
+
for (const [entryPath, error] of build.failed) {
|
|
369
|
+
graph.failed.set(entryPath, error);
|
|
370
|
+
}
|
|
371
|
+
if (!previous) {
|
|
372
|
+
this.persistEntries();
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
let changed = false;
|
|
376
|
+
for (const url of previous.servedUrls) {
|
|
377
|
+
if (previous.outputs.get(url) === build.outputs.get(url))
|
|
378
|
+
build.servedUrls.add(url);
|
|
379
|
+
else
|
|
380
|
+
changed = true;
|
|
381
|
+
}
|
|
382
|
+
if (changed) {
|
|
383
|
+
this.onVendorGraphChange?.();
|
|
384
|
+
}
|
|
385
|
+
this.persistEntries();
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Builds `entries` as one graph, isolating the entries that fail.
|
|
389
|
+
*
|
|
390
|
+
* @remarks
|
|
391
|
+
* When the graph fails, each entry builds alone to find the failing ones, and the graph builds again without
|
|
392
|
+
* them, so one broken package does not take every vendor down. Entries in `failed` are left out and keep
|
|
393
|
+
* their error. When no entry is isolated, because every entry builds alone or none does, or when anything
|
|
394
|
+
* throws, the graph failed as a whole: see {@link DevTransformVendorRegistry.keepLastGoodBuild}.
|
|
395
|
+
*/
|
|
396
|
+
async buildGraph(graph, entries, knownFailed, generation) {
|
|
397
|
+
const failed = new Map(knownFailed);
|
|
398
|
+
const entryPaths = new Set(entries.map((entry) => entry.entryPath));
|
|
399
|
+
const finish = (result) => ({
|
|
400
|
+
generation,
|
|
401
|
+
entryPaths,
|
|
402
|
+
outputs: result ? this.collectOutputs(result) : new Map(),
|
|
403
|
+
commonJsEntryPaths: new Set((result?.dependencyGraph.commonJsEntrypoints ?? []).map((entryPath) => path.resolve(entryPath))),
|
|
404
|
+
errors: failed,
|
|
405
|
+
failed,
|
|
406
|
+
servedUrls: new Set(),
|
|
111
407
|
});
|
|
408
|
+
const failGraph = (error, entryErrors = new Map()) => this.keepLastGoodBuild(graph, { generation, entries, entryPaths, failed, error, entryErrors });
|
|
409
|
+
try {
|
|
410
|
+
const toBuild = entries.filter((entry) => !failed.has(entry.entryPath));
|
|
411
|
+
if (toBuild.length === 0) {
|
|
412
|
+
return finish();
|
|
413
|
+
}
|
|
414
|
+
const result = await this.bundleGraph(graph, toBuild);
|
|
415
|
+
if (result.success) {
|
|
416
|
+
return finish(result);
|
|
417
|
+
}
|
|
418
|
+
const graphError = createPrebundleError(describeEntries(toBuild), result);
|
|
419
|
+
if (toBuild.length === 1) {
|
|
420
|
+
return failGraph(graphError);
|
|
421
|
+
}
|
|
422
|
+
const isolated = await Promise.all(toBuild.map(async (entry) => ({ entry, result: await this.bundleGraph(graph, [entry]) })));
|
|
423
|
+
const isolatedErrors = new Map();
|
|
424
|
+
for (const { entry, result: entryResult } of isolated) {
|
|
425
|
+
if (!entryResult.success) {
|
|
426
|
+
isolatedErrors.set(entry.entryPath, createPrebundleError(entry.specifier, entryResult));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (isolatedErrors.size === 0 || isolatedErrors.size === toBuild.length) {
|
|
430
|
+
return failGraph(graphError, isolatedErrors);
|
|
431
|
+
}
|
|
432
|
+
for (const [entryPath, error] of isolatedErrors)
|
|
433
|
+
failed.set(entryPath, error);
|
|
434
|
+
const remaining = toBuild.filter((entry) => !failed.has(entry.entryPath));
|
|
435
|
+
const retried = await this.bundleGraph(graph, remaining);
|
|
436
|
+
if (!retried.success) {
|
|
437
|
+
return failGraph(createPrebundleError(describeEntries(remaining), retried));
|
|
438
|
+
}
|
|
439
|
+
return finish(retried);
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
return failGraph(error instanceof Error ? error : new Error(String(error)));
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* The build of a graph that failed as a whole: the outputs of the last build, with an error for each entry
|
|
447
|
+
* that has none.
|
|
448
|
+
*
|
|
449
|
+
* @remarks
|
|
450
|
+
* A whole-graph failure can be transient, such as one during a package install, so no entry is marked
|
|
451
|
+
* failed and the next build tries every entry again. An entry without a previous output gets its own error
|
|
452
|
+
* when it failed alone, otherwise the graph error. A request for such an entry made after a backoff schedules
|
|
453
|
+
* that next build, so the error does not stick; the backoff keeps a lasting failure from rebuilding the graph,
|
|
454
|
+
* with its per-entry isolation builds, on every request.
|
|
455
|
+
*/
|
|
456
|
+
keepLastGoodBuild(graph, failure) {
|
|
457
|
+
const lastGood = graph.current;
|
|
458
|
+
const outputs = lastGood?.outputs ?? new Map();
|
|
459
|
+
const errors = new Map();
|
|
460
|
+
for (const entry of failure.entries) {
|
|
461
|
+
if (outputs.has(entry.url))
|
|
462
|
+
continue;
|
|
463
|
+
errors.set(entry.entryPath, failure.failed.get(entry.entryPath) ?? failure.entryErrors.get(entry.entryPath) ?? failure.error);
|
|
464
|
+
}
|
|
465
|
+
appLogger.error(`[dev-transform] Vendor graph build failed; built vendors keep their last good output.\n${failure.error.message}`);
|
|
466
|
+
return {
|
|
467
|
+
generation: failure.generation,
|
|
468
|
+
entryPaths: failure.entryPaths,
|
|
469
|
+
outputs,
|
|
470
|
+
commonJsEntryPaths: lastGood?.commonJsEntryPaths ?? new Set(),
|
|
471
|
+
errors,
|
|
472
|
+
failed: failure.failed,
|
|
473
|
+
servedUrls: lastGood?.servedUrls ?? new Set(),
|
|
474
|
+
failedAt: Date.now(),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Keeps the `@ecopages/core` imports of module-first packages out of their graph, pointing each at its
|
|
479
|
+
* browser-first entry URL.
|
|
480
|
+
*
|
|
481
|
+
* @remarks
|
|
482
|
+
* A package such as a router imports core's browser modules. Bundled into the module-first graph, they would
|
|
483
|
+
* be a second copy next to the browser-first one that Pages import, and would move between that graph's chunks
|
|
484
|
+
* as other packages that import them arrive. The import becomes the entry's stable URL instead, which a browser
|
|
485
|
+
* request then builds like any other entry.
|
|
486
|
+
*/
|
|
487
|
+
createBrowserFirstImportsPlugin() {
|
|
488
|
+
return {
|
|
489
|
+
name: 'ecopages-dev-vendor-browser-first-imports',
|
|
490
|
+
setup: (build) => {
|
|
491
|
+
build.onResolve({ filter: BROWSER_FIRST_SPECIFIER }, (args) => {
|
|
492
|
+
const resolveDir = args.importer && path.isAbsolute(args.importer)
|
|
493
|
+
? resolveImporterDir(args.importer)
|
|
494
|
+
: this.rootResolveDir;
|
|
495
|
+
const resolved = resolveBarePackageBrowserEntry(this.appConfig.rootDir, args.path, resolveDir);
|
|
496
|
+
if (!resolved)
|
|
497
|
+
return undefined;
|
|
498
|
+
return { path: this.addEntry(args.path, resolveDir, resolved.path).entry.url, external: true };
|
|
499
|
+
});
|
|
500
|
+
},
|
|
501
|
+
};
|
|
112
502
|
}
|
|
113
|
-
async
|
|
503
|
+
async bundleGraph(graph, entries) {
|
|
114
504
|
const vendorPlugins = this.resolveVendorBundlePlugins ? await this.resolveVendorBundlePlugins() : [];
|
|
115
|
-
const
|
|
505
|
+
const graphPlugins = graph.key === 'module-first' ? [this.createBrowserFirstImportsPlugin()] : [];
|
|
506
|
+
return this.browserBundleService.bundle({
|
|
116
507
|
lane: 'build',
|
|
117
|
-
entrypoints:
|
|
118
|
-
|
|
119
|
-
|
|
508
|
+
entrypoints: {
|
|
509
|
+
...Object.fromEntries(entries.map((entry) => [path.basename(entry.url, '.js'), entry.entryPath])),
|
|
510
|
+
[PIN_ENTRY_NAME]: PIN_SPECIFIER,
|
|
511
|
+
},
|
|
512
|
+
outdir: this.resolveOutdir(),
|
|
513
|
+
naming: '[name]',
|
|
120
514
|
writeToDisk: false,
|
|
121
515
|
minify: false,
|
|
122
516
|
externalPackages: false,
|
|
123
517
|
treeshaking: true,
|
|
124
|
-
splitting:
|
|
125
|
-
conditions: [...
|
|
518
|
+
splitting: true,
|
|
519
|
+
conditions: [...graph.conditions],
|
|
126
520
|
excludeAppBuildPlugins: resolveAppBuildPlugins(this.appConfig, 'browser').map((plugin) => plugin.name),
|
|
127
|
-
plugins: [...
|
|
521
|
+
plugins: [createVendorPinPlugin(entries), ...graphPlugins, ...vendorPlugins],
|
|
128
522
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* @remarks
|
|
526
|
+
* Every output lands in one directory, so the relative imports between entries and chunks resolve under
|
|
527
|
+
* `/assets/vendors/` in the browser as they are.
|
|
528
|
+
*/
|
|
529
|
+
collectOutputs(result) {
|
|
530
|
+
const outdir = this.resolveOutdir();
|
|
531
|
+
const outputs = new Map();
|
|
532
|
+
for (const output of result.outputs) {
|
|
533
|
+
if (typeof output.content !== 'string')
|
|
534
|
+
continue;
|
|
535
|
+
const relative = path.relative(outdir, output.path);
|
|
536
|
+
outputs.set(`/${RESOLVED_ASSETS_VENDORS_DIR}/${relative}`, output.content);
|
|
133
537
|
}
|
|
134
|
-
return
|
|
538
|
+
return outputs;
|
|
539
|
+
}
|
|
540
|
+
async findOutput(url) {
|
|
541
|
+
const built = this.findBuiltOutput(url);
|
|
542
|
+
if (built) {
|
|
543
|
+
return built;
|
|
544
|
+
}
|
|
545
|
+
const known = this.entriesByUrl.get(url);
|
|
546
|
+
if (known) {
|
|
547
|
+
const build = await this.waitForBuildContaining(known.graph, known.entry.entryPath);
|
|
548
|
+
const error = build.errors.get(known.entry.entryPath);
|
|
549
|
+
if (error) {
|
|
550
|
+
return { error };
|
|
551
|
+
}
|
|
552
|
+
const content = build.outputs.get(url);
|
|
553
|
+
return content === undefined ? null : { build, url, content };
|
|
554
|
+
}
|
|
555
|
+
return null;
|
|
135
556
|
}
|
|
136
557
|
/**
|
|
137
|
-
*
|
|
558
|
+
* @remarks
|
|
559
|
+
* After {@link DevTransformVendorRegistry.invalidateAll} an entry URL waits for the rebuild, but a chunk or an
|
|
560
|
+
* entry URL that is no longer known is still served from the previous build until the rebuild commits, so an
|
|
561
|
+
* open page can load its lazy chunks; a rebuild that changes a served file then reloads the page.
|
|
562
|
+
*/
|
|
563
|
+
findBuiltOutput(url) {
|
|
564
|
+
const known = this.entriesByUrl.get(url);
|
|
565
|
+
for (const graph of this.graphs.values()) {
|
|
566
|
+
const build = graph.current;
|
|
567
|
+
if (!build || (known && build.generation !== this.generation))
|
|
568
|
+
continue;
|
|
569
|
+
const content = build.outputs.get(url);
|
|
570
|
+
if (content !== undefined) {
|
|
571
|
+
return { build, url, content };
|
|
572
|
+
}
|
|
573
|
+
const entryPath = known?.graph === graph ? known.entry.entryPath : undefined;
|
|
574
|
+
const error = entryPath && !isRetryDue(build, entryPath) ? build.errors.get(entryPath) : undefined;
|
|
575
|
+
if (error) {
|
|
576
|
+
return { error };
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
/** The graph's last build when it belongs to the current generation. */
|
|
582
|
+
currentBuild(graph) {
|
|
583
|
+
return graph.current?.generation === this.generation ? graph.current : undefined;
|
|
584
|
+
}
|
|
585
|
+
resolveOutdir() {
|
|
586
|
+
return path.join(this.appConfig.absolutePaths.workDir, 'vendor-memory');
|
|
587
|
+
}
|
|
588
|
+
resolveEntriesFile() {
|
|
589
|
+
return path.join(this.appConfig.absolutePaths.workDir, VENDOR_ENTRIES_FILE);
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Seeds the known entries from the previous dev process.
|
|
138
593
|
*
|
|
139
594
|
* @remarks
|
|
140
|
-
*
|
|
141
|
-
*
|
|
595
|
+
* A specifier that no longer resolves from its directory, or now belongs to another graph, is skipped without
|
|
596
|
+
* an error.
|
|
142
597
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
598
|
+
seedPersistedEntries() {
|
|
599
|
+
const file = this.resolveEntriesFile();
|
|
600
|
+
if (!fileSystem.exists(file)) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
let persisted;
|
|
604
|
+
try {
|
|
605
|
+
persisted = JSON.parse(fileSystem.readFileSync(file));
|
|
606
|
+
}
|
|
607
|
+
catch {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (!isPersistedVendorEntries(persisted)) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
for (const { specifier, resolveDir, conditions } of persisted.entries) {
|
|
614
|
+
if (getVendorGraphKey(specifier) !== conditions)
|
|
615
|
+
continue;
|
|
616
|
+
const resolved = resolveBarePackageBrowserEntry(this.appConfig.rootDir, specifier, resolveDir);
|
|
617
|
+
if (resolved)
|
|
618
|
+
this.addEntry(specifier, resolveDir, resolved.path);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* @remarks
|
|
623
|
+
* Every known entry is written, failing ones included, so a failure never costs the next process its seed.
|
|
624
|
+
* The write is synchronous so it finishes before the build's waiters resume; a failed write only costs the
|
|
625
|
+
* next process its seed, so it is logged at debug level.
|
|
626
|
+
*/
|
|
627
|
+
persistEntries() {
|
|
628
|
+
const persisted = {
|
|
629
|
+
entries: [...this.graphs.values()].flatMap((graph) => [...graph.entries.values()].flatMap((entry) => entry.sources.map((source) => ({ ...source, conditions: graph.key })))),
|
|
161
630
|
};
|
|
631
|
+
const contents = `${JSON.stringify(persisted, null, '\t')}\n`;
|
|
632
|
+
if (contents === this.persistedContents) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
const file = this.resolveEntriesFile();
|
|
636
|
+
try {
|
|
637
|
+
fileSystem.write(file, contents);
|
|
638
|
+
this.persistedContents = contents;
|
|
639
|
+
}
|
|
640
|
+
catch (error) {
|
|
641
|
+
appLogger.debug(`[dev-transform] Could not write ${file}: ${String(error)}`);
|
|
642
|
+
}
|
|
162
643
|
}
|
|
163
|
-
resolvePackageEntry(specifier,
|
|
164
|
-
const resolved = resolveBarePackageBrowserEntry(this.appConfig.rootDir, specifier,
|
|
644
|
+
resolvePackageEntry(specifier, resolveDir) {
|
|
645
|
+
const resolved = resolveBarePackageBrowserEntry(this.appConfig.rootDir, specifier, resolveDir);
|
|
165
646
|
if (!resolved) {
|
|
166
|
-
throw new Error(`[dev-transform] Unable to resolve bare import "${specifier}" for vendor prebundle`);
|
|
647
|
+
throw new Error(`[dev-transform] Unable to resolve bare import "${specifier}" from ${resolveDir} for vendor prebundle`);
|
|
167
648
|
}
|
|
168
649
|
return resolved.path;
|
|
169
650
|
}
|
|
651
|
+
/** Where a bare import that no module imports resolves from. */
|
|
652
|
+
get rootResolveDir() {
|
|
653
|
+
return resolveDirectory(this.appConfig.rootDir);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
/** The `name` of a `package.json`, or `undefined` when the file is missing or unreadable. */
|
|
657
|
+
function readPackageName(manifest) {
|
|
658
|
+
if (!fileSystem.exists(manifest))
|
|
659
|
+
return undefined;
|
|
660
|
+
try {
|
|
661
|
+
const parsed = JSON.parse(fileSystem.readFileSync(manifest));
|
|
662
|
+
return typeof parsed === 'object' && parsed !== null && 'name' in parsed && typeof parsed.name === 'string'
|
|
663
|
+
? parsed.name
|
|
664
|
+
: undefined;
|
|
665
|
+
}
|
|
666
|
+
catch {
|
|
667
|
+
return undefined;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
/** The installed directory of `packageName` that holds `entryPath`, or the entry's directory when none is found. */
|
|
671
|
+
function findPackageDir(entryPath, packageName) {
|
|
672
|
+
let directory = path.dirname(entryPath);
|
|
673
|
+
while (true) {
|
|
674
|
+
if (readPackageName(path.join(directory, 'package.json')) === packageName)
|
|
675
|
+
return directory;
|
|
676
|
+
const parent = path.dirname(directory);
|
|
677
|
+
if (parent === directory)
|
|
678
|
+
return path.dirname(entryPath);
|
|
679
|
+
directory = parent;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
/** A directory with its symlinks resolved, or as given when it does not exist. */
|
|
683
|
+
function resolveDirectory(directory) {
|
|
684
|
+
try {
|
|
685
|
+
return fileSystem.realpath(path.resolve(directory));
|
|
686
|
+
}
|
|
687
|
+
catch {
|
|
688
|
+
return path.resolve(directory);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* The directory a module's bare imports resolve from.
|
|
693
|
+
*
|
|
694
|
+
* @remarks
|
|
695
|
+
* Symlinks are resolved first, as Node and Rolldown do, so a package linked into the pnpm store finds its own
|
|
696
|
+
* dependencies beside it in the store rather than in the linking `node_modules`.
|
|
697
|
+
*/
|
|
698
|
+
function resolveImporterDir(importer) {
|
|
699
|
+
return resolveDirectory(path.dirname(path.resolve(importer)));
|
|
700
|
+
}
|
|
701
|
+
function createVendorGraph(key, conditions) {
|
|
702
|
+
return { key, conditions, entries: new Map(), failed: new Map(), queue: Promise.resolve() };
|
|
703
|
+
}
|
|
704
|
+
function isPersistedVendorEntries(value) {
|
|
705
|
+
if (typeof value !== 'object' || value === null || !('entries' in value) || !Array.isArray(value.entries)) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
return value.entries.every((entry) => typeof entry === 'object' &&
|
|
709
|
+
entry !== null &&
|
|
710
|
+
'specifier' in entry &&
|
|
711
|
+
typeof entry.specifier === 'string' &&
|
|
712
|
+
'resolveDir' in entry &&
|
|
713
|
+
typeof entry.resolveDir === 'string' &&
|
|
714
|
+
'conditions' in entry &&
|
|
715
|
+
(entry.conditions === 'browser-first' || entry.conditions === 'module-first'));
|
|
716
|
+
}
|
|
717
|
+
/** Whether a request for an entry with no output in a build that failed as a whole should build the graph again. */
|
|
718
|
+
function isRetryDue(build, entryPath) {
|
|
719
|
+
return (build.failedAt !== undefined &&
|
|
720
|
+
Date.now() - build.failedAt >= VENDOR_GRAPH_RETRY_BACKOFF_MS &&
|
|
721
|
+
build.errors.has(entryPath) &&
|
|
722
|
+
!build.failed.has(entryPath));
|
|
723
|
+
}
|
|
724
|
+
function describeEntries(entries) {
|
|
725
|
+
return entries.map((entry) => entry.specifier).join(', ');
|
|
726
|
+
}
|
|
727
|
+
function createPrebundleError(specifier, result) {
|
|
728
|
+
return new Error(formatVendorPrebundleError(specifier, result.logs.map(formatBuildLog).join('\n')));
|
|
170
729
|
}
|
|
171
730
|
function formatVendorPrebundleError(specifier, details) {
|
|
172
731
|
if (details.includes(BROWSER_NODE_BUILTIN_GUARD_MARKER)) {
|
|
173
732
|
return (`[dev-transform] Bare import "${specifier}" resolved to a server-only entry. ` +
|
|
174
|
-
`Import a browser subpath
|
|
733
|
+
`Import a browser subpath of the package.` +
|
|
175
734
|
(details ? `\n${details}` : ''));
|
|
176
735
|
}
|
|
177
736
|
return details
|
|
178
737
|
? `[dev-transform] Vendor prebundle failed for ${specifier}:\n${details}`
|
|
179
738
|
: `[dev-transform] Vendor prebundle failed for ${specifier}`;
|
|
180
739
|
}
|
|
740
|
+
function createVendorResponse(url, content, ifNoneMatch) {
|
|
741
|
+
const etag = `"${contentHash(content, 16)}"`;
|
|
742
|
+
const headers = { 'Cache-Control': 'no-cache', ETag: etag };
|
|
743
|
+
if (matchesIfNoneMatch(ifNoneMatch, etag)) {
|
|
744
|
+
return new Response(null, { status: 304, headers });
|
|
745
|
+
}
|
|
746
|
+
return new Response(content, {
|
|
747
|
+
headers: { ...headers, 'Content-Type': resolveVendorContentType(url) },
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
function resolveVendorContentType(url) {
|
|
751
|
+
if (url.endsWith('.css'))
|
|
752
|
+
return 'text/css';
|
|
753
|
+
if (url.endsWith('.map'))
|
|
754
|
+
return 'application/json';
|
|
755
|
+
return 'application/javascript';
|
|
756
|
+
}
|
|
181
757
|
function sanitizeSpecifierForFileName(specifier) {
|
|
182
758
|
return specifier.replaceAll(/^@/gu, '').replaceAll(/[/:@]/gu, '-');
|
|
183
759
|
}
|