@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
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
2
|
+
import { path } from '@ecopages/file-system/path';
|
|
3
|
+
import { appLogger } from '../../../../global/app-logger.js';
|
|
4
|
+
import { resolveGeneratedPath, writeGeneratedTypesPackage } from '../../../../plugins/processor.js';
|
|
5
|
+
import { findStylesheetProcessor, getStylesheetKinds } from '../../../../plugins/stylesheet-kinds.js';
|
|
6
|
+
import { loadTsconfigResolutionOptions } from '../../../../plugins/tsconfig-import-resolver.js';
|
|
7
|
+
import { isPathInside } from '../../../../utils/path-containment.js';
|
|
8
|
+
import { isCssModuleExportName } from './stylesheet-module.js';
|
|
9
|
+
import { applyStylesheetProcessors } from './stylesheet-processor-pipeline.js';
|
|
10
|
+
/** The module name of the generated `@types` package that holds the declarations of the app's CSS Modules. */
|
|
11
|
+
export const CSS_MODULE_TYPES_MODULE = 'ecopages-css-modules';
|
|
12
|
+
/**
|
|
13
|
+
* The declaration of a CSS Module whose class map is `exports`: the default export, typed with each class name as a
|
|
14
|
+
* literal key, and a named export for each name that is a valid identifier (see {@link isCssModuleExportName}).
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* The default export is bound to a local name that no class takes, so a class named `styles` stays a named export.
|
|
18
|
+
*/
|
|
19
|
+
export function toCssModuleDeclaration(exports) {
|
|
20
|
+
const names = Object.keys(exports);
|
|
21
|
+
const members = names.map((name) => `\treadonly ${JSON.stringify(name)}: string;\n`).join('');
|
|
22
|
+
const named = names
|
|
23
|
+
.filter(isCssModuleExportName)
|
|
24
|
+
.map((name) => `export declare const ${name}: string;\n`)
|
|
25
|
+
.join('');
|
|
26
|
+
let binding = 'styles';
|
|
27
|
+
while (names.includes(binding))
|
|
28
|
+
binding = `_${binding}`;
|
|
29
|
+
return `declare const ${binding}: {\n${members}};\nexport default ${binding};\n${named}`;
|
|
30
|
+
}
|
|
31
|
+
function writeGeneratedFile(filePath, content) {
|
|
32
|
+
if (fileSystem.exists(filePath) && fileSystem.readFileSync(filePath) === content)
|
|
33
|
+
return;
|
|
34
|
+
fileSystem.ensureDir(path.dirname(filePath));
|
|
35
|
+
fileSystem.write(filePath, content);
|
|
36
|
+
}
|
|
37
|
+
function typesRoot(appConfig) {
|
|
38
|
+
return resolveGeneratedPath('types', { root: appConfig.rootDir, module: CSS_MODULE_TYPES_MODULE });
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The file that declares the CSS Module `file`, mirroring its place under `srcDir`; `undefined` for a file outside
|
|
42
|
+
* `srcDir`.
|
|
43
|
+
*/
|
|
44
|
+
function declarationPath(appConfig, file) {
|
|
45
|
+
const { srcDir } = appConfig.absolutePaths;
|
|
46
|
+
if (!isPathInside(file, srcDir))
|
|
47
|
+
return undefined;
|
|
48
|
+
return path.join(typesRoot(appConfig), `${path.relative(srcDir, file)}.d.ts`);
|
|
49
|
+
}
|
|
50
|
+
/** Writes the manifest and the entry of the generated `@types` package, so TypeScript does not report it empty. */
|
|
51
|
+
function writeTypesPackage(appConfig) {
|
|
52
|
+
writeGeneratedTypesPackage({
|
|
53
|
+
root: appConfig.rootDir,
|
|
54
|
+
module: CSS_MODULE_TYPES_MODULE,
|
|
55
|
+
packageName: `@types/${CSS_MODULE_TYPES_MODULE}`,
|
|
56
|
+
writeFile: writeGeneratedFile,
|
|
57
|
+
});
|
|
58
|
+
writeGeneratedFile(path.join(typesRoot(appConfig), 'index.d.ts'), 'export {};\n');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Writes the declaration of the CSS Module `file` into the generated `@types` package, so a named import of its
|
|
62
|
+
* classes type-checks.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* The declaration sits at the path of the module under `srcDir`, which resolves for an app that lists the package
|
|
66
|
+
* folder in `rootDirs` (and, for an alias such as `@/*`, in `paths`; see the CSS Modules guide). Unchanged
|
|
67
|
+
* content is not rewritten, so a watcher on the folder stays quiet.
|
|
68
|
+
*/
|
|
69
|
+
export function writeCssModuleDeclaration(appConfig, file, exports) {
|
|
70
|
+
const target = declarationPath(appConfig, file);
|
|
71
|
+
if (!target)
|
|
72
|
+
return;
|
|
73
|
+
writeTypesPackage(appConfig);
|
|
74
|
+
writeGeneratedFile(target, toCssModuleDeclaration(exports));
|
|
75
|
+
}
|
|
76
|
+
/** Removes the declaration of the CSS Module `file`, as when the module is deleted. */
|
|
77
|
+
export function removeCssModuleDeclaration(appConfig, file) {
|
|
78
|
+
const target = declarationPath(appConfig, file);
|
|
79
|
+
if (target)
|
|
80
|
+
fileSystem.remove(target);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Writes the declarations of every CSS Module in `srcDir`, and drops the ones an earlier run left for modules that
|
|
84
|
+
* are gone. Writes nothing when no stylesheet Processor scopes CSS Modules.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* A module the Processor rejects is logged and skipped, so one broken file does not hide the types of the others.
|
|
88
|
+
*/
|
|
89
|
+
export async function writeCssModuleDeclarations(appConfig) {
|
|
90
|
+
const kinds = getStylesheetKinds(appConfig);
|
|
91
|
+
if (!kinds.scopesCssModules)
|
|
92
|
+
return;
|
|
93
|
+
const processor = findStylesheetProcessor(appConfig.processors.values());
|
|
94
|
+
const { srcDir, publicDir } = appConfig.absolutePaths;
|
|
95
|
+
fileSystem.remove(typesRoot(appConfig));
|
|
96
|
+
writeTypesPackage(appConfig);
|
|
97
|
+
const patterns = kinds.extensions.map((extension) => `**/*.module${extension}`);
|
|
98
|
+
for (const relativePath of await fileSystem.glob(patterns, { cwd: srcDir })) {
|
|
99
|
+
const file = path.join(srcDir, relativePath);
|
|
100
|
+
if (isPathInside(file, publicDir) || !processor?.canProcessAsset('stylesheet', file))
|
|
101
|
+
continue;
|
|
102
|
+
try {
|
|
103
|
+
const { exports } = await applyStylesheetProcessors(appConfig, await fileSystem.readFile(file), file);
|
|
104
|
+
if (exports)
|
|
105
|
+
writeCssModuleDeclaration(appConfig, file, exports);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
appLogger.error(`Could not declare the CSS Module ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
warnMissingCssModuleRootDirs(appConfig);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Warns when the app has CSS Module declarations but its tsconfig cannot find them, and prints the lines to add.
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* The caller runs it once, after the declarations are written. TypeScript resolves a declaration only through `rootDirs`, and an alias such as `@/*` also needs the package folder
|
|
118
|
+
* as a second `paths` target. Until they are listed, a named import of a CSS Module class fails type checking.
|
|
119
|
+
*/
|
|
120
|
+
export function warnMissingCssModuleRootDirs(appConfig) {
|
|
121
|
+
const root = typesRoot(appConfig);
|
|
122
|
+
if (!fileSystem.exists(root))
|
|
123
|
+
return;
|
|
124
|
+
const declared = fileSystem
|
|
125
|
+
.readdir(root, { recursive: true })
|
|
126
|
+
.some((entry) => entry.isFile && entry.name.endsWith('.d.ts') && entry.name !== 'index.d.ts');
|
|
127
|
+
if (!declared)
|
|
128
|
+
return;
|
|
129
|
+
const options = loadTsconfigResolutionOptions(appConfig.rootDir);
|
|
130
|
+
const { srcDir } = appConfig.absolutePaths;
|
|
131
|
+
const relative = (target) => {
|
|
132
|
+
const value = path.relative(appConfig.rootDir, target);
|
|
133
|
+
return value.startsWith('.') ? value : `./${value}`;
|
|
134
|
+
};
|
|
135
|
+
const lines = [];
|
|
136
|
+
if (!options?.rootDirs?.some((dir) => path.resolve(dir) === path.resolve(root))) {
|
|
137
|
+
lines.push(`"rootDirs": ["${relative(srcDir)}", "${relative(root)}"]`);
|
|
138
|
+
}
|
|
139
|
+
for (const [alias, targets] of Object.entries(options?.paths ?? {})) {
|
|
140
|
+
const source = targets.find((target) => path.resolve(target) === path.join(srcDir, '*'));
|
|
141
|
+
if (!alias.endsWith('/*') || !source)
|
|
142
|
+
continue;
|
|
143
|
+
if (targets.some((target) => path.resolve(target) === path.join(root, '*')))
|
|
144
|
+
continue;
|
|
145
|
+
lines.push(`"${alias}": ["${relative(srcDir)}/*", "${relative(root)}/*"]`);
|
|
146
|
+
}
|
|
147
|
+
if (lines.length === 0)
|
|
148
|
+
return;
|
|
149
|
+
appLogger.warn(`CSS Modules are declared in ${relative(root)}, but tsconfig.json does not list that folder, so importing a class by name fails type checking. Add to compilerOptions:\n ${lines.join(',\n ')}`);
|
|
150
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The core CSS scanner: finds and rewrites the references in a stylesheet.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Engine-free and pure: it reads no file and knows no Processor. It honours strings, comments and escapes, so
|
|
6
|
+
* `content: "url(x)"` and a commented-out `@import` are left alone. A caller decides what a reference becomes: a
|
|
7
|
+
* package stylesheet fails on a missing file, an app stylesheet warns, and the Processors' output is scanned the same way.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A reference that does not name a file: a fragment, a root-relative path, or any URL with a scheme (`data:`,
|
|
11
|
+
* `https:`). A Windows drive path names a file.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isExternalReference(reference: string): boolean;
|
|
14
|
+
/** Splits a reference into its file part, decoded where it can be, and its `?` or `#` suffix. */
|
|
15
|
+
export declare function splitReference(reference: string): {
|
|
16
|
+
filePart: string;
|
|
17
|
+
decoded: string;
|
|
18
|
+
suffix: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Wraps inlined CSS in the blocks an `@import`'s `layer`, `supports()` and media conditions stand for.
|
|
22
|
+
*
|
|
23
|
+
* @returns The wrapped CSS, or `undefined` when the conditions cannot be read.
|
|
24
|
+
*/
|
|
25
|
+
export declare function wrapInConditions(css: string, conditions: string): string | undefined;
|
|
26
|
+
/** An `@import` statement the scan found at the top level. */
|
|
27
|
+
export type CssImport = {
|
|
28
|
+
/** The statement as written, trimmed and ending in `;`, for a caller that hoists it. */
|
|
29
|
+
statement: string;
|
|
30
|
+
/** The imported URL, decoded. */
|
|
31
|
+
specifier: string;
|
|
32
|
+
/** What follows the URL: the `layer`, `supports()` and media conditions, trimmed. */
|
|
33
|
+
conditions: string;
|
|
34
|
+
};
|
|
35
|
+
/** What a scan asks of its caller; a missing handler leaves what it handles as written. */
|
|
36
|
+
export type CssScanHandlers = {
|
|
37
|
+
/**
|
|
38
|
+
* What a relative `url()` or `image-set()` string reference becomes, or `undefined` to leave it as written.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Fragments, root-relative paths and URLs with a scheme never reach it, since they name no file.
|
|
42
|
+
*/
|
|
43
|
+
reference?: (reference: string) => string | undefined;
|
|
44
|
+
/** What replaces a top-level `@import` the scan could read, or `undefined` to leave the statement as written. */
|
|
45
|
+
import?: (statement: CssImport) => string | undefined;
|
|
46
|
+
/** What replaces the top-level `@charset`; the statement is passed trimmed and ending in `;`. */
|
|
47
|
+
charset?: (statement: string) => string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Walks `css` once and returns it with each reference the handlers rewrite replaced.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Sees the `url()` and `image-set()` string references anywhere, and the `@import` and `@charset` rules outside any
|
|
54
|
+
* block. Everything else, including strings, comments and escapes, is copied as written.
|
|
55
|
+
*/
|
|
56
|
+
export declare function scanCss(css: string, handlers: CssScanHandlers): string;
|
|
57
|
+
/** The references of a stylesheet, as {@link listCssReferences} finds them. */
|
|
58
|
+
export type CssReferences = {
|
|
59
|
+
/** The relative `url()` and `image-set()` string references, without duplicates. */
|
|
60
|
+
references: string[];
|
|
61
|
+
/** Every top-level `@import`, relative or not. */
|
|
62
|
+
imports: CssImport[];
|
|
63
|
+
};
|
|
64
|
+
/** Lists the references of `css` without rewriting any. */
|
|
65
|
+
export declare function listCssReferences(css: string): CssReferences;
|
|
66
|
+
/** What a {@link CssToken} is. */
|
|
67
|
+
export type CssTokenType = 'comment' | 'string' | 'escape' | 'url' | 'word' | 'space'
|
|
68
|
+
/** Any other single character, such as `{`, `;`, `(` or `.`. */
|
|
69
|
+
| 'punct';
|
|
70
|
+
/** A token of a stylesheet: its type and the half-open range `[start, end)` it covers. */
|
|
71
|
+
export type CssToken = {
|
|
72
|
+
type: CssTokenType;
|
|
73
|
+
start: number;
|
|
74
|
+
end: number;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Splits `css` into tokens that cover it without gaps, so a caller finds the structure of a stylesheet without
|
|
78
|
+
* reading a `{` or a `;` inside a string, a comment, an escape or a `url()`.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* A `word` is a run of letters, digits, `_` and `-`; a `url()` with a literal argument is one `url` token. It is a
|
|
82
|
+
* lexer, not a parser: it keeps no brace or parenthesis depth, which is the caller's to track.
|
|
83
|
+
*/
|
|
84
|
+
export declare function tokenizeCss(css: string): CssToken[];
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The core CSS scanner: finds and rewrites the references in a stylesheet.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Engine-free and pure: it reads no file and knows no Processor. It honours strings, comments and escapes, so
|
|
6
|
+
* `content: "url(x)"` and a commented-out `@import` are left alone. A caller decides what a reference becomes: a
|
|
7
|
+
* package stylesheet fails on a missing file, an app stylesheet warns, and the Processors' output is scanned the same way.
|
|
8
|
+
*/
|
|
9
|
+
const IDENT_CHAR = /[\w-]/;
|
|
10
|
+
const IDENT = /[\w-]+/y;
|
|
11
|
+
/** A Windows path with a drive letter, as a rebased reference to a file on another drive is written. */
|
|
12
|
+
const DRIVE_PATH = /^[a-z]:[\\/]/i;
|
|
13
|
+
/**
|
|
14
|
+
* A reference that does not name a file: a fragment, a root-relative path, or any URL with a scheme (`data:`,
|
|
15
|
+
* `https:`). A Windows drive path names a file.
|
|
16
|
+
*/
|
|
17
|
+
export function isExternalReference(reference) {
|
|
18
|
+
return (reference === '' ||
|
|
19
|
+
reference.startsWith('#') ||
|
|
20
|
+
reference.startsWith('/') ||
|
|
21
|
+
(/^[a-z][a-z\d+.-]*:/i.test(reference) && !DRIVE_PATH.test(reference)));
|
|
22
|
+
}
|
|
23
|
+
/** Splits a reference into its file part, decoded where it can be, and its `?` or `#` suffix. */
|
|
24
|
+
export function splitReference(reference) {
|
|
25
|
+
const suffixStart = reference.search(/[?#]/);
|
|
26
|
+
const filePart = suffixStart === -1 ? reference : reference.slice(0, suffixStart);
|
|
27
|
+
const suffix = suffixStart === -1 ? '' : reference.slice(suffixStart);
|
|
28
|
+
let decoded = filePart;
|
|
29
|
+
try {
|
|
30
|
+
decoded = decodeURI(filePart);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
decoded = filePart;
|
|
34
|
+
}
|
|
35
|
+
return { filePart, decoded, suffix };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Reads a CSS escape starting at the backslash at `start`.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Follows CSS Syntax: up to six hex digits and one optional whitespace, an escaped newline that continues a
|
|
42
|
+
* string, or any other character taken literally.
|
|
43
|
+
*/
|
|
44
|
+
function readEscape(css, start) {
|
|
45
|
+
const hex = /^[\da-f]{1,6}/i.exec(css.slice(start + 1, start + 7))?.[0];
|
|
46
|
+
if (hex) {
|
|
47
|
+
let end = start + 1 + hex.length;
|
|
48
|
+
if (/\s/.test(css[end] ?? ''))
|
|
49
|
+
end += css[end] === '\r' && css[end + 1] === '\n' ? 2 : 1;
|
|
50
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
51
|
+
return { value: codePoint === 0 || codePoint > 0x10ffff ? '�' : String.fromCodePoint(codePoint), end };
|
|
52
|
+
}
|
|
53
|
+
if (css[start + 1] === '\n')
|
|
54
|
+
return { value: '', end: start + 2 };
|
|
55
|
+
return { value: css[start + 1] ?? '', end: Math.min(start + 2, css.length) };
|
|
56
|
+
}
|
|
57
|
+
/** Reads the quoted string starting at `start`, ending after its closing quote, at a newline, or at the end. */
|
|
58
|
+
function readString(css, start) {
|
|
59
|
+
const quote = css[start];
|
|
60
|
+
let value = '';
|
|
61
|
+
let index = start + 1;
|
|
62
|
+
while (index < css.length && css[index] !== quote && css[index] !== '\n') {
|
|
63
|
+
if (css[index] === '\\') {
|
|
64
|
+
const escape = readEscape(css, index);
|
|
65
|
+
value += escape.value;
|
|
66
|
+
index = escape.end;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
value += css[index];
|
|
70
|
+
index += 1;
|
|
71
|
+
}
|
|
72
|
+
return { value, end: css[index] === quote ? index + 1 : index };
|
|
73
|
+
}
|
|
74
|
+
function readComment(css, start) {
|
|
75
|
+
const end = css.indexOf('*/', start + 2);
|
|
76
|
+
return end === -1 ? css.length : end + 2;
|
|
77
|
+
}
|
|
78
|
+
function skipSpace(css, start) {
|
|
79
|
+
let index = start;
|
|
80
|
+
while (index < css.length) {
|
|
81
|
+
if (/\s/.test(css[index]))
|
|
82
|
+
index += 1;
|
|
83
|
+
else if (css.startsWith('/*', index))
|
|
84
|
+
index = readComment(css, index);
|
|
85
|
+
else
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
return index;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reads the argument of a `url(` whose opening parenthesis ends just before `start`, quoted or not.
|
|
92
|
+
*
|
|
93
|
+
* @returns The decoded reference and the index after the closing parenthesis, or `undefined` when it is malformed
|
|
94
|
+
* or is not a literal reference, such as `url(var(--x))`, which the scan then reads as nested functions.
|
|
95
|
+
*/
|
|
96
|
+
function readUrl(css, start) {
|
|
97
|
+
let index = skipSpace(css, start);
|
|
98
|
+
if (css[index] === '"' || css[index] === "'") {
|
|
99
|
+
const string = readString(css, index);
|
|
100
|
+
index = skipSpace(css, string.end);
|
|
101
|
+
return css[index] === ')' ? { value: string.value, end: index + 1 } : undefined;
|
|
102
|
+
}
|
|
103
|
+
let value = '';
|
|
104
|
+
while (index < css.length && css[index] !== ')') {
|
|
105
|
+
if (css[index] === '\\') {
|
|
106
|
+
const escape = readEscape(css, index);
|
|
107
|
+
value += escape.value;
|
|
108
|
+
index = escape.end;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (css[index] === '(')
|
|
112
|
+
return undefined;
|
|
113
|
+
value += css[index];
|
|
114
|
+
index += 1;
|
|
115
|
+
}
|
|
116
|
+
return css[index] === ')' ? { value: value.trim(), end: index + 1 } : undefined;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Walks `css` from `start`, skipping strings, comments and escapes, and stops where `stop` returns true for a
|
|
120
|
+
* character at parenthesis depth `depth`.
|
|
121
|
+
*/
|
|
122
|
+
function scanUntil(css, start, stop) {
|
|
123
|
+
let depth = 0;
|
|
124
|
+
let index = start;
|
|
125
|
+
while (index < css.length) {
|
|
126
|
+
const char = css[index];
|
|
127
|
+
if (char === '"' || char === "'") {
|
|
128
|
+
index = readString(css, index).end;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (css.startsWith('/*', index)) {
|
|
132
|
+
index = readComment(css, index);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (char === '\\') {
|
|
136
|
+
index = readEscape(css, index).end;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (char === '(')
|
|
140
|
+
depth += 1;
|
|
141
|
+
if (char === ')')
|
|
142
|
+
depth -= 1;
|
|
143
|
+
if (stop(char, depth))
|
|
144
|
+
return index;
|
|
145
|
+
index += 1;
|
|
146
|
+
}
|
|
147
|
+
return css.length;
|
|
148
|
+
}
|
|
149
|
+
/** Reads the contents of the parenthesized group whose opening parenthesis is at `start`. */
|
|
150
|
+
function readParenthesized(css, start) {
|
|
151
|
+
const close = scanUntil(css, start, (char, depth) => char === ')' && depth === 0);
|
|
152
|
+
return { value: css.slice(start + 1, close), end: Math.min(close + 1, css.length) };
|
|
153
|
+
}
|
|
154
|
+
/** The end of the at-rule prelude starting at `start`: its `;` outside parentheses, or the end of the file. */
|
|
155
|
+
function findStatementEnd(css, start) {
|
|
156
|
+
return scanUntil(css, start, (char, depth) => char === ';' && depth <= 0);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Wraps inlined CSS in the blocks an `@import`'s `layer`, `supports()` and media conditions stand for.
|
|
160
|
+
*
|
|
161
|
+
* @returns The wrapped CSS, or `undefined` when the conditions cannot be read.
|
|
162
|
+
*/
|
|
163
|
+
export function wrapInConditions(css, conditions) {
|
|
164
|
+
let rest = conditions.trim();
|
|
165
|
+
let layer;
|
|
166
|
+
let supports;
|
|
167
|
+
const layerMatch = /^layer\b/i.exec(rest);
|
|
168
|
+
if (layerMatch) {
|
|
169
|
+
rest = rest.slice(layerMatch[0].length);
|
|
170
|
+
if (rest.startsWith('(')) {
|
|
171
|
+
const group = readParenthesized(rest, 0);
|
|
172
|
+
layer = group.value.trim();
|
|
173
|
+
rest = rest.slice(group.end);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
layer = '';
|
|
177
|
+
}
|
|
178
|
+
rest = rest.trim();
|
|
179
|
+
}
|
|
180
|
+
const supportsMatch = /^supports\(/i.exec(rest);
|
|
181
|
+
if (supportsMatch) {
|
|
182
|
+
const group = readParenthesized(rest, supportsMatch[0].length - 1);
|
|
183
|
+
supports = group.value.trim();
|
|
184
|
+
rest = rest.slice(group.end).trim();
|
|
185
|
+
}
|
|
186
|
+
if (rest.includes('{') || rest.includes('}'))
|
|
187
|
+
return undefined;
|
|
188
|
+
let wrapped = css;
|
|
189
|
+
if (rest)
|
|
190
|
+
wrapped = `@media ${rest} {\n${wrapped}\n}`;
|
|
191
|
+
if (supports !== undefined)
|
|
192
|
+
wrapped = `@supports (${supports}) {\n${wrapped}\n}`;
|
|
193
|
+
if (layer !== undefined)
|
|
194
|
+
wrapped = `@layer${layer ? ` ${layer}` : ''} {\n${wrapped}\n}`;
|
|
195
|
+
return wrapped;
|
|
196
|
+
}
|
|
197
|
+
function rewriteReference(scan, reference) {
|
|
198
|
+
return isExternalReference(reference) ? undefined : scan.handlers.reference?.(reference);
|
|
199
|
+
}
|
|
200
|
+
/** A string is copied as written, unless it is an `image-set()` reference. */
|
|
201
|
+
function scanString(scan, index) {
|
|
202
|
+
const string = readString(scan.css, index);
|
|
203
|
+
const inImageSet = /^(?:-webkit-)?image-set$/i.test(scan.functions[scan.functions.length - 1] ?? '');
|
|
204
|
+
const rewritten = inImageSet ? rewriteReference(scan, string.value) : undefined;
|
|
205
|
+
return {
|
|
206
|
+
text: rewritten === undefined ? scan.css.slice(index, string.end) : JSON.stringify(rewritten),
|
|
207
|
+
end: string.end,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** The `@import` whose `@` is at `start`, or `undefined` when its URL cannot be read; the scan then leaves it. */
|
|
211
|
+
function readImport(css, start, statementEnd) {
|
|
212
|
+
let index = skipSpace(css, start + '@import'.length);
|
|
213
|
+
let target;
|
|
214
|
+
if (css[index] === '"' || css[index] === "'") {
|
|
215
|
+
target = readString(css, index);
|
|
216
|
+
}
|
|
217
|
+
else if (/^url\(/i.test(css.slice(index, index + 4))) {
|
|
218
|
+
target = readUrl(css, index + 4);
|
|
219
|
+
}
|
|
220
|
+
if (!target)
|
|
221
|
+
return undefined;
|
|
222
|
+
return {
|
|
223
|
+
statement: `${css.slice(start, statementEnd).trim()};`,
|
|
224
|
+
specifier: target.value,
|
|
225
|
+
conditions: css.slice(target.end, statementEnd).trim(),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/** Handles a top-level `@import` or `@charset`; any other at-rule is left to the scan. */
|
|
229
|
+
function scanAtRule(scan, index) {
|
|
230
|
+
IDENT.lastIndex = index + 1;
|
|
231
|
+
const keyword = IDENT.exec(scan.css)?.[0].toLowerCase();
|
|
232
|
+
if (keyword !== 'import' && keyword !== 'charset')
|
|
233
|
+
return undefined;
|
|
234
|
+
const statementEnd = findStatementEnd(scan.css, index);
|
|
235
|
+
const end = Math.min(statementEnd + 1, scan.css.length);
|
|
236
|
+
const written = { text: scan.css.slice(index, end), end };
|
|
237
|
+
if (keyword === 'charset') {
|
|
238
|
+
const statement = `${scan.css.slice(index, end).replace(/;?\s*$/, '')};`;
|
|
239
|
+
return scan.handlers.charset ? { text: scan.handlers.charset(statement), end } : written;
|
|
240
|
+
}
|
|
241
|
+
const statement = readImport(scan.css, index, statementEnd);
|
|
242
|
+
const replacement = statement && scan.handlers.import?.(statement);
|
|
243
|
+
return replacement === undefined ? written : { text: replacement, end };
|
|
244
|
+
}
|
|
245
|
+
/** Reads an identifier: a `url()` is rewritten, a function name opens a group. */
|
|
246
|
+
function scanIdentifier(scan, index) {
|
|
247
|
+
IDENT.lastIndex = index;
|
|
248
|
+
const name = IDENT.exec(scan.css)[0];
|
|
249
|
+
const open = index + name.length;
|
|
250
|
+
if (scan.css[open] !== '(')
|
|
251
|
+
return { text: name, end: open };
|
|
252
|
+
if (name.toLowerCase() === 'url') {
|
|
253
|
+
const url = readUrl(scan.css, open + 1);
|
|
254
|
+
if (url) {
|
|
255
|
+
const rewritten = rewriteReference(scan, url.value);
|
|
256
|
+
return {
|
|
257
|
+
text: rewritten === undefined ? scan.css.slice(index, url.end) : `url(${JSON.stringify(rewritten)})`,
|
|
258
|
+
end: url.end,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
scan.functions.push(name);
|
|
263
|
+
return { text: scan.css.slice(index, open + 1), end: open + 1 };
|
|
264
|
+
}
|
|
265
|
+
function scanPunctuation(scan, index) {
|
|
266
|
+
const char = scan.css[index];
|
|
267
|
+
if (char === '(')
|
|
268
|
+
scan.functions.push('');
|
|
269
|
+
if (char === ')')
|
|
270
|
+
scan.functions.pop();
|
|
271
|
+
if (char === '{')
|
|
272
|
+
scan.braces += 1;
|
|
273
|
+
if (char === '}')
|
|
274
|
+
scan.braces = Math.max(0, scan.braces - 1);
|
|
275
|
+
return { text: char, end: index + 1 };
|
|
276
|
+
}
|
|
277
|
+
function scanToken(scan, index) {
|
|
278
|
+
const { css } = scan;
|
|
279
|
+
const char = css[index];
|
|
280
|
+
if (css.startsWith('/*', index)) {
|
|
281
|
+
const end = readComment(css, index);
|
|
282
|
+
return { text: css.slice(index, end), end };
|
|
283
|
+
}
|
|
284
|
+
if (char === '"' || char === "'")
|
|
285
|
+
return scanString(scan, index);
|
|
286
|
+
if (char === '\\') {
|
|
287
|
+
const end = readEscape(css, index).end;
|
|
288
|
+
return { text: css.slice(index, end), end };
|
|
289
|
+
}
|
|
290
|
+
if (char === '@' && scan.braces === 0) {
|
|
291
|
+
const atRule = scanAtRule(scan, index);
|
|
292
|
+
if (atRule)
|
|
293
|
+
return atRule;
|
|
294
|
+
}
|
|
295
|
+
if (IDENT_CHAR.test(char) && !IDENT_CHAR.test(css[index - 1] ?? ''))
|
|
296
|
+
return scanIdentifier(scan, index);
|
|
297
|
+
return scanPunctuation(scan, index);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Walks `css` once and returns it with each reference the handlers rewrite replaced.
|
|
301
|
+
*
|
|
302
|
+
* @remarks
|
|
303
|
+
* Sees the `url()` and `image-set()` string references anywhere, and the `@import` and `@charset` rules outside any
|
|
304
|
+
* block. Everything else, including strings, comments and escapes, is copied as written.
|
|
305
|
+
*/
|
|
306
|
+
export function scanCss(css, handlers) {
|
|
307
|
+
const scan = { css, handlers, functions: [], braces: 0 };
|
|
308
|
+
let output = '';
|
|
309
|
+
let index = 0;
|
|
310
|
+
while (index < scan.css.length) {
|
|
311
|
+
const token = scanToken(scan, index);
|
|
312
|
+
output += token.text;
|
|
313
|
+
index = token.end;
|
|
314
|
+
}
|
|
315
|
+
return output;
|
|
316
|
+
}
|
|
317
|
+
/** Lists the references of `css` without rewriting any. */
|
|
318
|
+
export function listCssReferences(css) {
|
|
319
|
+
const references = new Set();
|
|
320
|
+
const imports = [];
|
|
321
|
+
scanCss(css, {
|
|
322
|
+
reference: (reference) => {
|
|
323
|
+
references.add(reference);
|
|
324
|
+
return undefined;
|
|
325
|
+
},
|
|
326
|
+
import: (statement) => {
|
|
327
|
+
imports.push(statement);
|
|
328
|
+
return undefined;
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
return { references: [...references], imports };
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Splits `css` into tokens that cover it without gaps, so a caller finds the structure of a stylesheet without
|
|
335
|
+
* reading a `{` or a `;` inside a string, a comment, an escape or a `url()`.
|
|
336
|
+
*
|
|
337
|
+
* @remarks
|
|
338
|
+
* A `word` is a run of letters, digits, `_` and `-`; a `url()` with a literal argument is one `url` token. It is a
|
|
339
|
+
* lexer, not a parser: it keeps no brace or parenthesis depth, which is the caller's to track.
|
|
340
|
+
*/
|
|
341
|
+
export function tokenizeCss(css) {
|
|
342
|
+
const tokens = [];
|
|
343
|
+
let index = 0;
|
|
344
|
+
while (index < css.length) {
|
|
345
|
+
const char = css[index];
|
|
346
|
+
let type = 'punct';
|
|
347
|
+
let end = index + 1;
|
|
348
|
+
if (css.startsWith('/*', index)) {
|
|
349
|
+
type = 'comment';
|
|
350
|
+
end = readComment(css, index);
|
|
351
|
+
}
|
|
352
|
+
else if (char === '"' || char === "'") {
|
|
353
|
+
type = 'string';
|
|
354
|
+
end = readString(css, index).end;
|
|
355
|
+
}
|
|
356
|
+
else if (char === '\\') {
|
|
357
|
+
type = 'escape';
|
|
358
|
+
end = readEscape(css, index).end;
|
|
359
|
+
}
|
|
360
|
+
else if (/\s/.test(char)) {
|
|
361
|
+
type = 'space';
|
|
362
|
+
while (end < css.length && /\s/.test(css[end]))
|
|
363
|
+
end += 1;
|
|
364
|
+
}
|
|
365
|
+
else if (IDENT_CHAR.test(char)) {
|
|
366
|
+
type = 'word';
|
|
367
|
+
IDENT.lastIndex = index;
|
|
368
|
+
end = index + IDENT.exec(css)[0].length;
|
|
369
|
+
const url = css[end] === '(' && css.slice(index, end).toLowerCase() === 'url' ? readUrl(css, end + 1) : undefined;
|
|
370
|
+
if (url) {
|
|
371
|
+
type = 'url';
|
|
372
|
+
end = url.end;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
tokens.push({ type, start: index, end });
|
|
376
|
+
index = end;
|
|
377
|
+
}
|
|
378
|
+
return tokens;
|
|
379
|
+
}
|
package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import type { FileStylesheetAsset, ProcessedAsset } from '../../assets.types.js';
|
|
2
2
|
import { BaseProcessor } from '../base/base-processor.js';
|
|
3
|
+
/**
|
|
4
|
+
* Processes a stylesheet file through the app's Processors and writes it under `dist/client/assets`.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A package stylesheet (`fromPackage`) skips Processors (see {@link preparePackageStylesheet}) and is always
|
|
8
|
+
* written under its content hash. A package CSS Module is the one exception: the Processor that scopes CSS Modules
|
|
9
|
+
* scopes it, and the files it references follow the package policy (see {@link emitPackageStylesheetReferences}). The files any stylesheet's relative `url()` references name are emitted to
|
|
10
|
+
* `dist/client/assets` under a content hash (see {@link emitStylesheetReferences}); a linked stylesheet names them
|
|
11
|
+
* relative to where it is written, and an inline one root-relative, since a `<style>` resolves against the Page. In
|
|
12
|
+
* development a stylesheet inside `srcDir` keeps its source-relative path (see {@link writeSourceRelativeStylesheet}).
|
|
13
|
+
* The stylesheets the Processor inlined join `bundledSourceFilepaths`, so an edit to an `@import` partial evicts the
|
|
14
|
+
* cached asset and the Pages that link it.
|
|
15
|
+
*/
|
|
3
16
|
export declare class FileStylesheetProcessor extends BaseProcessor<FileStylesheetAsset> {
|
|
4
17
|
getStyleContent: (srcUrl: string) => Buffer;
|
|
5
18
|
process(dep: FileStylesheetAsset): Promise<ProcessedAsset>;
|
|
19
|
+
private appDirs;
|
|
20
|
+
/** Writes `content` under its content hash unless the stylesheet is inline or already written at `filepath`. */
|
|
21
|
+
private toProcessedAsset;
|
|
6
22
|
}
|