@ecopages/core 0.4.0 → 0.6.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.
Files changed (163) hide show
  1. package/README.md +19 -15
  2. package/package.json +13 -4
  3. package/src/adapters/create-app.js +9 -5
  4. package/src/adapters/node/create-app.d.ts +18 -16
  5. package/src/adapters/node/create-app.js +26 -30
  6. package/src/adapters/node/server-adapter.d.ts +26 -9
  7. package/src/adapters/node/server-adapter.js +38 -8
  8. package/src/adapters/shared/hmr/hmr-manager.js +3 -2
  9. package/src/adapters/shared/http/api-request-pipeline.js +2 -2
  10. package/src/adapters/shared/http/dist-file-handler.js +25 -7
  11. package/src/adapters/shared/runtime/render-context.d.ts +2 -1
  12. package/src/adapters/shared/runtime/render-context.js +18 -21
  13. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +4 -3
  14. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +6 -4
  15. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +6 -1
  16. package/src/adapters/shared/runtime/server-request-pipeline.js +11 -10
  17. package/src/adapters/shared/runtime/server-route-handler.js +4 -4
  18. package/src/adapters/shared/runtime/server-static-builder.d.ts +11 -11
  19. package/src/adapters/shared/runtime/server-static-builder.js +37 -18
  20. package/src/assets/app-browser-client-build.js +8 -21
  21. package/src/assets/app-browser-client-manifest.d.ts +1 -4
  22. package/src/assets/app-browser-client-manifest.js +6 -78
  23. package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +2 -2
  24. package/src/assets/asset-processing-service/processors/script/file-script.processor.js +2 -2
  25. package/src/assets/browser-asset-output.d.ts +1 -1
  26. package/src/assets/browser-asset-output.js +1 -1
  27. package/src/build/app-build-manifest-runtime.d.ts +11 -1
  28. package/src/build/app-build-manifest-runtime.js +17 -3
  29. package/src/build/cache/pages-unified-graph-build.d.ts +32 -35
  30. package/src/build/cache/pages-unified-graph-build.js +206 -124
  31. package/src/build/cache/server-module-entries.d.ts +35 -0
  32. package/src/build/cache/server-module-entries.js +109 -0
  33. package/src/build/contracts/build-contracts.d.ts +5 -0
  34. package/src/build/contracts/content-virtual-modules.d.ts +9 -3
  35. package/src/build/contracts/content-virtual-modules.js +11 -5
  36. package/src/build/contracts.d.ts +1 -1
  37. package/src/build/contracts.js +1 -1
  38. package/src/build/copy-server-files.d.ts +10 -0
  39. package/src/build/copy-server-files.js +37 -0
  40. package/src/build/preserve-import-meta-transform.d.ts +1 -1
  41. package/src/build/preserve-import-meta-transform.js +1 -1
  42. package/src/build/production-build-id.d.ts +9 -0
  43. package/src/build/production-build-id.js +19 -0
  44. package/src/build/production-dist-complete.d.ts +5 -0
  45. package/src/build/production-dist-complete.js +101 -0
  46. package/src/build/production-route-list.d.ts +26 -0
  47. package/src/build/production-route-list.js +78 -0
  48. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +2 -2
  49. package/src/build/rolldown/rolldown-adapter-helpers.js +56 -4
  50. package/src/build/rolldown/rolldown-build-adapter.js +1 -1
  51. package/src/build/rolldown/rolldown-plugin-bridge.js +2 -2
  52. package/src/build/runtime/build-request-identity.js +2 -1
  53. package/src/build/runtime/build-request-policy.d.ts +3 -2
  54. package/src/build/runtime/build-request-policy.js +5 -3
  55. package/src/build/server/import-view-module.d.ts +11 -0
  56. package/src/build/server/import-view-module.js +21 -0
  57. package/src/build/server/imported-view-plugin.d.ts +16 -0
  58. package/src/build/server/imported-view-plugin.js +59 -0
  59. package/src/build/server/page-module-import.service.d.ts +19 -20
  60. package/src/build/server/page-module-import.service.js +65 -36
  61. package/src/build/server/resolve-static-view.d.ts +9 -0
  62. package/src/build/server/resolve-static-view.js +28 -0
  63. package/src/build/server/route-module-build-cache-registry.d.ts +5 -3
  64. package/src/build/server/route-module-build-cache-registry.js +5 -3
  65. package/src/build/server/server-modules-manifest.d.ts +51 -0
  66. package/src/build/server/server-modules-manifest.js +129 -0
  67. package/src/build/server/view-reference.d.ts +38 -0
  68. package/src/build/server/view-reference.js +112 -0
  69. package/src/build/server-bundle-deploy-manifest.d.ts +9 -9
  70. package/src/build/server-bundle-deploy-manifest.js +24 -28
  71. package/src/build.d.ts +4 -2
  72. package/src/build.js +4 -2
  73. package/src/config/assembly/app-runtime.d.ts +15 -2
  74. package/src/config/assembly/app-runtime.js +3 -1
  75. package/src/config/assembly/finalize-config.js +64 -13
  76. package/src/config/index.d.ts +1 -0
  77. package/src/config/index.js +1 -0
  78. package/src/config/internal-types.d.ts +6 -0
  79. package/src/config/load-eco-config.d.ts +1 -0
  80. package/src/config/load-eco-config.js +11 -2
  81. package/src/config/resolve-eco-config-path.d.ts +2 -1
  82. package/src/config/resolve-eco-config-path.js +21 -15
  83. package/src/config/user-config-types.d.ts +9 -2
  84. package/src/dev/transform-server/dev-transform-server.js +1 -1
  85. package/src/dev/transform-server/dev-transform-vendor-registry.d.ts +29 -6
  86. package/src/dev/transform-server/dev-transform-vendor-registry.js +101 -53
  87. package/src/errors/http-error.d.ts +9 -0
  88. package/src/errors/http-error.js +11 -0
  89. package/src/html/html-transformer.service.d.ts +0 -21
  90. package/src/html/html-transformer.service.js +0 -32
  91. package/src/html-pages/html-page-module.d.ts +19 -0
  92. package/src/html-pages/html-page-module.js +66 -13
  93. package/src/html-pages/html-page-renderer.d.ts +6 -1
  94. package/src/html-pages/html-page-renderer.js +14 -6
  95. package/src/html-pages/html-pages.plugin.d.ts +10 -0
  96. package/src/html-pages/html-pages.plugin.js +7 -1
  97. package/src/index.d.ts +2 -0
  98. package/src/index.js +2 -0
  99. package/src/integration.d.ts +2 -2
  100. package/src/integration.js +1 -1
  101. package/src/islands/island-host.d.ts +1 -2
  102. package/src/islands/island-host.js +1 -2
  103. package/src/page-cache/page-cache-service.d.ts +8 -0
  104. package/src/page-cache/page-cache-service.js +12 -0
  105. package/src/plugins/integration-plugin.d.ts +34 -7
  106. package/src/plugins/integration-plugin.js +14 -2
  107. package/src/plugins/processor.d.ts +18 -1
  108. package/src/plugins/processor.js +20 -1
  109. package/src/plugins/server-dom.d.ts +29 -0
  110. package/src/plugins/server-dom.js +36 -0
  111. package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
  112. package/src/plugins/tsconfig-import-resolver.js +4 -2
  113. package/src/processor.d.ts +1 -1
  114. package/src/route-renderer/error-pages/error-page-renderer.d.ts +6 -4
  115. package/src/route-renderer/error-pages/error-page-renderer.js +9 -5
  116. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +2 -44
  117. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +14 -89
  118. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +4 -16
  119. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +2 -10
  120. package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +3 -5
  121. package/src/route-renderer/orchestration/integration-renderer.d.ts +21 -44
  122. package/src/route-renderer/orchestration/integration-renderer.js +69 -117
  123. package/src/route-renderer/orchestration/ownership-graph/page-client-browser-assets.d.ts +3 -4
  124. package/src/route-renderer/orchestration/ownership-graph/page-client-browser-assets.js +4 -15
  125. package/src/route-renderer/orchestration/ownership-graph/prepared-graph-membership.d.ts +22 -0
  126. package/src/route-renderer/orchestration/ownership-graph/prepared-graph-membership.js +45 -0
  127. package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.d.ts +0 -1
  128. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +21 -0
  129. package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +31 -0
  130. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +58 -24
  131. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +12 -0
  132. package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +55 -0
  133. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +4 -3
  134. package/src/router/server/route-registry.d.ts +23 -1
  135. package/src/router/server/route-registry.js +41 -14
  136. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +8 -2
  137. package/src/static-site-generator/production-page-browser-graph-prebuild.js +14 -13
  138. package/src/static-site-generator/static-site-generator.d.ts +19 -3
  139. package/src/static-site-generator/static-site-generator.js +78 -40
  140. package/src/types/build-types.d.ts +6 -0
  141. package/src/types/contracts.d.ts +26 -35
  142. package/src/types/eco-api-types.d.ts +1 -1
  143. package/src/types/public-types.d.ts +1 -0
  144. package/src/types/view-reference.d.ts +31 -0
  145. package/src/types/view-reference.js +15 -0
  146. package/src/utils/additional-watch-paths.d.ts +3 -3
  147. package/src/utils/additional-watch-paths.js +3 -1
  148. package/src/utils/resolve-entry-file.d.ts +4 -2
  149. package/src/utils/resolve-entry-file.js +4 -2
  150. package/src/utils/root-relative-path.d.ts +4 -0
  151. package/src/utils/root-relative-path.js +8 -0
  152. package/src/utils/server-bundle-context.d.ts +14 -0
  153. package/src/utils/server-bundle-context.js +45 -0
  154. package/src/watchers/project-watcher-ignore.d.ts +2 -5
  155. package/src/watchers/project-watcher-ignore.js +2 -5
  156. package/src/watchers/project-watcher.d.ts +9 -7
  157. package/src/watchers/project-watcher.js +100 -52
  158. package/src/watchers/workspace-package-watch-roots.d.ts +4 -4
  159. package/src/watchers/workspace-package-watch-roots.js +41 -25
  160. package/src/build/server/view-module-loader.d.ts +0 -10
  161. package/src/build/server/view-module-loader.js +0 -46
  162. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.d.ts +0 -12
  163. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.js +0 -32
package/src/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export { eco } from './eco/eco.js';
2
2
  export { defineApiHandler, defineGroupHandler, defineGet, definePost, definePut, defineDelete, definePatch, defineOptions, defineHead, defineQuery, json, html, redirect, } from './adapters/shared/http/define-api-handler.js';
3
+ export { createViewReference } from './build/server/view-reference.js';
4
+ export { VIEW_REFERENCE, isViewReference } from './types/view-reference.js';
3
5
  export { attributeMdxComponentIdentity } from './plugins/eco-component-meta-plugin.js';
4
6
  export { bindComponentIdentity, getComponentIdentity, getComponentOwner, } from './eco/component-identity.js';
5
7
  export { attachDiscoveredDependencies } from './eco/discovered-dependencies.js';
@@ -6,12 +6,12 @@ export { type ForeignChildInterceptionInput, type ForeignChildInterceptionResult
6
6
  export { ensurePageConfigLayouts } from './eco/page-layout-normalization.js';
7
7
  export { collectJsxExtensions, createJsxImportSourcePragma, filterJsxSourceExtensions, isJsxSourceExtension, } from './plugins/jsx-import-source.utils.js';
8
8
  export { resolveDocumentShellLayouts, resolveInnermostPageLayout, resolveLayoutEntryProps, resolveLayoutShellProps, resolvePageLayoutComponents, type DocumentShellLayoutResolutionInput, type LayoutShellPropsContext, } from './route-renderer/orchestration/document-shell/layout-shell-props.service.js';
9
- export { mergePageBrowserGraph } from './route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.js';
10
9
  export { isRegisteredDevTransformEntrypoint, isRegisteredScriptEntrypoint } from './hmr/hmr-entrypoint-output.js';
11
10
  export { type HmrRegisteredEntrypointsContext } from './hmr/hmr-registered-entrypoints-context.js';
12
11
  export { HmrStrategy, HmrStrategyType } from './hmr/hmr-strategy.js';
13
12
  export { type DefinedIntegration, defineIntegration } from './plugins/define-integration.js';
14
- export { type AnyIntegrationPlugin, type EcoBuildOnLoadArgs, type EcoBuildOnLoadResult, type EcoBuildOnResolveArgs, type EcoBuildOnResolveResult, type EcoBuildPlugin, type EcoBuildPluginBuilder, IntegrationPlugin, type IntegrationPluginConfig, type IntegrationRendererBase, type IntegrationRuntimeContext, mergeIntegrationOptions, type StaticExportContext, type StaticExportRelease, } from './plugins/integration-plugin.js';
13
+ export { type AnyIntegrationPlugin, type EcoBuildOnLoadArgs, type EcoBuildOnLoadResult, type EcoBuildImportKind, type EcoBuildOnResolveArgs, type EcoBuildOnResolveResult, type EcoBuildPlugin, type EcoBuildPluginBuilder, IntegrationPlugin, type IntegrationPluginConfig, type IntegrationRendererBase, type IntegrationRuntimeContext, mergeIntegrationOptions, type ServerDomInstaller, type ServerDomSurfaceKind, type StaticExportContext, type StaticExportRelease, } from './plugins/integration-plugin.js';
14
+ export { installConfiguredServerDom } from './plugins/server-dom.js';
15
15
  export { CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES, CustomElementScriptPreloader, type CustomElementScriptPreloadScopeState, type CustomElementSsrPreloadComponent, invalidateCustomElementScriptPreload, } from './route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js';
16
16
  export { createCustomElementServerModuleImporter, createSharedServerModuleImporter, } from './route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js';
17
17
  export { createCustomElementSsrPipelineImporter } from './route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js';
@@ -5,12 +5,12 @@ export { getComponentRenderContext, runWithComponentRenderContext, } from './eco
5
5
  export { ensurePageConfigLayouts } from './eco/page-layout-normalization.js';
6
6
  export { collectJsxExtensions, createJsxImportSourcePragma, filterJsxSourceExtensions, isJsxSourceExtension, } from './plugins/jsx-import-source.utils.js';
7
7
  export { resolveDocumentShellLayouts, resolveInnermostPageLayout, resolveLayoutEntryProps, resolveLayoutShellProps, resolvePageLayoutComponents, } from './route-renderer/orchestration/document-shell/layout-shell-props.service.js';
8
- export { mergePageBrowserGraph } from './route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.js';
9
8
  export { isRegisteredDevTransformEntrypoint, isRegisteredScriptEntrypoint } from './hmr/hmr-entrypoint-output.js';
10
9
  export {} from './hmr/hmr-registered-entrypoints-context.js';
11
10
  export { HmrStrategy, HmrStrategyType } from './hmr/hmr-strategy.js';
12
11
  export { defineIntegration } from './plugins/define-integration.js';
13
12
  export { IntegrationPlugin, mergeIntegrationOptions, } from './plugins/integration-plugin.js';
13
+ export { installConfiguredServerDom } from './plugins/server-dom.js';
14
14
  export { CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES, CustomElementScriptPreloader, invalidateCustomElementScriptPreload, } from './route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js';
15
15
  export { createCustomElementServerModuleImporter, createSharedServerModuleImporter, } from './route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js';
16
16
  export { createCustomElementSsrPipelineImporter } from './route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js';
@@ -27,8 +27,7 @@ export declare function componentRenderHasIslandBootstrap(assets: Array<{
27
27
  *
28
28
  * @param ownAssets - Assets of the component and its same-Integration nested components, excluding Foreign Children
29
29
  * and the Foreign Subtrees rendered inside it.
30
- * @remarks The decision ignores `result.assets`, which usually also carries Foreign Subtree assets: a component
31
- * without scripts that wraps an island is not an island itself.
30
+ * @remarks A component without scripts that wraps an island is not an island itself.
32
31
  */
33
32
  export declare function finalizeIslandComponentRender<T extends {
34
33
  canAttachAttributes: boolean;
@@ -46,8 +46,7 @@ export function componentRenderHasIslandBootstrap(assets) {
46
46
  *
47
47
  * @param ownAssets - Assets of the component and its same-Integration nested components, excluding Foreign Children
48
48
  * and the Foreign Subtrees rendered inside it.
49
- * @remarks The decision ignores `result.assets`, which usually also carries Foreign Subtree assets: a component
50
- * without scripts that wraps an island is not an island itself.
49
+ * @remarks A component without scripts that wraps an island is not an island itself.
51
50
  */
52
51
  export function finalizeIslandComponentRender(input, result, ownAssets) {
53
52
  const componentInstanceId = input.integrationContext?.componentInstanceId;
@@ -46,6 +46,14 @@ export declare class PageCacheService {
46
46
  * Uses promise deduplication to prevent multiple concurrent regenerations.
47
47
  */
48
48
  private regenerateInBackground;
49
+ /**
50
+ * @remarks
51
+ * Shutdown awaits this before Integration teardown so a revalidating cache
52
+ * regeneration cannot render against a torn-down Integration. Regeneration
53
+ * failures are already logged and do not reject shutdown. The mutation gate
54
+ * still drops a write whose generation is older than a later invalidation.
55
+ */
56
+ waitForInFlightRegenerations(): Promise<void>;
49
57
  /**
50
58
  * Invalidate cache entries by tags.
51
59
  */
@@ -278,6 +278,18 @@ export class PageCacheService {
278
278
  });
279
279
  });
280
280
  }
281
+ /**
282
+ * @remarks
283
+ * Shutdown awaits this before Integration teardown so a revalidating cache
284
+ * regeneration cannot render against a torn-down Integration. Regeneration
285
+ * failures are already logged and do not reject shutdown. The mutation gate
286
+ * still drops a write whose generation is older than a later invalidation.
287
+ */
288
+ async waitForInFlightRegenerations() {
289
+ while (this.regenerationPromises.size > 0) {
290
+ await Promise.allSettled([...this.regenerationPromises.values()]);
291
+ }
292
+ }
281
293
  /**
282
294
  * Invalidate cache entries by tags.
283
295
  */
@@ -7,7 +7,9 @@ import type { IntegrationRenderer, IntegrationRendererOptions } from '../route-r
7
7
  import { AssetProcessingService } from '../assets/asset-processing-service/asset-processing.service.js';
8
8
  import type { AssetDefinition, ProcessedAsset } from '../assets/asset-processing-service/assets.types.js';
9
9
  import type { StaticExportContext, StaticExportRelease } from '../static-site-generator/static-export-context.js';
10
- export type { EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, } from '../build/contracts/build-types.js';
10
+ import { type ServerDomInstaller } from './server-dom.js';
11
+ export type { ServerDomInstaller, ServerDomSurfaceKind } from './server-dom.js';
12
+ export type { EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildImportKind, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, } from '../build/contracts/build-types.js';
11
13
  export type { PageBrowserGraphContribution, PageBrowserGraphContributionContext } from '../types/contracts.js';
12
14
  export type { StaticExportContext, StaticExportRelease } from '../static-site-generator/static-export-context.js';
13
15
  export type { HtmlDocumentContribution, HtmlDocumentContributionContext, } from '../route-renderer/orchestration/integration-renderer.js';
@@ -107,6 +109,15 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
107
109
  readonly acceptsParams: boolean;
108
110
  /** Whether core may collapse this Integration's eligible Page assets into page-owned bundles. */
109
111
  readonly bundlesPageDependencies: boolean;
112
+ /**
113
+ * Server DOM installer this Integration contributes, if any.
114
+ *
115
+ * @remarks
116
+ * Core runs every configured `complete` installer, then every `repair`, before
117
+ * Integration `setup()` continues. Config order does not change the result.
118
+ * Omit this when the Integration does not install DOM globals.
119
+ */
120
+ readonly serverDom?: ServerDomInstaller;
110
121
  protected integrationDependencies: AssetDefinition[];
111
122
  protected resolvedIntegrationDependencies: ProcessedAsset[];
112
123
  protected appConfig?: EcoPagesAppConfig;
@@ -142,12 +153,27 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
142
153
  * calls it for every file of the Integration that it loads as a module, and never bundles
143
154
  * those files itself.
144
155
  *
145
- * - Every Page of an Integration that implements this stays out of the production pages
146
- * graph, so each one builds on first load.
147
- * - The result is cached by the file's content hash, so editing another file it reads does
148
- * not invalidate it.
156
+ * Production emit records the compiled module through {@link serializeCompiledPageModule}.
157
+ * Development caches the result by the file's content hash, so editing another file it
158
+ * reads does not invalidate it.
149
159
  */
150
160
  compilePageModule?(filePath: string, appConfig: EcoPagesAppConfig): EcoPageFile | Promise<EcoPageFile>;
161
+ /**
162
+ * Records a {@link compilePageModule} result so production can import it without compiling.
163
+ */
164
+ serializeCompiledPageModule?(module: EcoPageFile, context: {
165
+ rootDir: string;
166
+ filePath: string;
167
+ }): {
168
+ contents: string;
169
+ };
170
+ /**
171
+ * Restores a {@link serializeCompiledPageModule} record for production import.
172
+ */
173
+ reviveCompiledPageModule?(contents: string, context: {
174
+ rootDir: string;
175
+ filePath: string;
176
+ }): EcoPageFile;
151
177
  /**
152
178
  * Returns processed global assets resolved during `setup()`.
153
179
  */
@@ -197,8 +223,9 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
197
223
  *
198
224
  * @remarks
199
225
  * Core calls this after static-export releases and when the app stops or restarts,
200
- * after in-flight `setup()` calls and active prewarm renders finish. It then clears
201
- * activation state so the next runtime activation runs `setup()` again.
226
+ * after in-flight `setup()` calls finish. On stop or restart it also waits for
227
+ * active prewarm renders and page-cache regenerations. It then clears activation
228
+ * state so the next runtime activation runs `setup()` again.
202
229
  * Most integrations do not need custom teardown. Override this only for
203
230
  * explicit cleanup such as watchers, compiler handles, or runtime registries
204
231
  * that outlive individual requests.
@@ -1,6 +1,7 @@
1
1
  import { createBrowserRuntimeManifest, } from '../build/browser/browser-runtime-manifest.js';
2
2
  import { AssetProcessingService } from '../assets/asset-processing-service/asset-processing.service.js';
3
3
  import { deepMerge } from '../utils/deep-merge.js';
4
+ import { installConfiguredServerDom } from './server-dom.js';
4
5
  export const INTEGRATION_PLUGIN_ERRORS = {
5
6
  NOT_INITIALIZED_WITH_APP_CONFIG: 'Plugin not initialized with app config',
6
7
  };
@@ -42,6 +43,15 @@ export class IntegrationPlugin {
42
43
  acceptsParams = true;
43
44
  /** Whether core may collapse this Integration's eligible Page assets into page-owned bundles. */
44
45
  bundlesPageDependencies = false;
46
+ /**
47
+ * Server DOM installer this Integration contributes, if any.
48
+ *
49
+ * @remarks
50
+ * Core runs every configured `complete` installer, then every `repair`, before
51
+ * Integration `setup()` continues. Config order does not change the result.
52
+ * Omit this when the Integration does not install DOM globals.
53
+ */
54
+ serverDom;
45
55
  integrationDependencies;
46
56
  resolvedIntegrationDependencies = [];
47
57
  appConfig;
@@ -126,6 +136,7 @@ export class IntegrationPlugin {
126
136
  * Performs runtime integration setup, after config finalization has sealed the build manifest.
127
137
  */
128
138
  async setup(context) {
139
+ await installConfiguredServerDom(context.appConfig.integrations);
129
140
  this.appConfig = context.appConfig;
130
141
  this.runtime = context.runtime;
131
142
  this.rendererInstance = undefined;
@@ -148,8 +159,9 @@ export class IntegrationPlugin {
148
159
  *
149
160
  * @remarks
150
161
  * Core calls this after static-export releases and when the app stops or restarts,
151
- * after in-flight `setup()` calls and active prewarm renders finish. It then clears
152
- * activation state so the next runtime activation runs `setup()` again.
162
+ * after in-flight `setup()` calls finish. On stop or restart it also waits for
163
+ * active prewarm renders and page-cache regenerations. It then clears activation
164
+ * state so the next runtime activation runs `setup()` again.
153
165
  * Most integrations do not need custom teardown. Override this only for
154
166
  * explicit cleanup such as watchers, compiler handles, or runtime registries
155
167
  * that outlive individual requests.
@@ -1,7 +1,7 @@
1
1
  import type { EcoBuildPlugin } from '../build/contracts/build-types.js';
2
2
  import type { EcoPagesAppConfig, IClientBridge } from '../config/internal-types.js';
3
3
  import { GENERATED_BASE_PATHS } from '../constants.js';
4
- export type { EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, } from '../build/contracts/build-types.js';
4
+ export type { EcoBuildLoader, EcoBuildOnLoadArgs, EcoBuildOnLoadResult, EcoBuildImportKind, EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin, EcoBuildPluginBuilder, } from '../build/contracts/build-types.js';
5
5
  export declare const PROCESSOR_ERRORS: {
6
6
  readonly CACHE_DIRECTORY_NOT_SET: "Cache directory not set in context";
7
7
  };
@@ -86,6 +86,7 @@ export interface ProcessorContext {
86
86
  config: EcoPagesAppConfig;
87
87
  rootDir: string;
88
88
  srcDir: string;
89
+ /** Public output directory (`client/` beneath the configured build output root). */
89
90
  distDir: string;
90
91
  cache?: string;
91
92
  }
@@ -121,6 +122,22 @@ export declare abstract class Processor<TOptions = unknown> {
121
122
  constructor(config: ProcessorConfig<TOptions>);
122
123
  setContext(appConfig: EcoPagesAppConfig): void;
123
124
  abstract setup(): Promise<void>;
125
+ /**
126
+ * Source files this Processor needs in the production server-modules map.
127
+ *
128
+ * @remarks
129
+ * Core includes them in the unified graph after `setup()`. Production `ecopages start`
130
+ * imports the emitted modules and does not call `setup()`. Development never reads this list.
131
+ */
132
+ listProductionServerModuleEntries(): string[];
133
+ /**
134
+ * Restores in-memory state from the production server-modules map.
135
+ *
136
+ * @remarks
137
+ * Called instead of `setup()` on production `ecopages start`, and in the Lit static-render
138
+ * worker. Must not scan sources or write under the work directory.
139
+ */
140
+ restoreProductionRuntime(): Promise<void>;
124
141
  /**
125
142
  * Transforms one stylesheet before core writes or inlines it.
126
143
  *
@@ -80,7 +80,6 @@ export class Processor {
80
80
  root: workDir,
81
81
  module: this.name,
82
82
  });
83
- fileSystem.ensureDir(cachePath);
84
83
  this.context = {
85
84
  config: appConfig,
86
85
  rootDir: appConfig.rootDir,
@@ -89,6 +88,26 @@ export class Processor {
89
88
  cache: cachePath,
90
89
  };
91
90
  }
91
+ /**
92
+ * Source files this Processor needs in the production server-modules map.
93
+ *
94
+ * @remarks
95
+ * Core includes them in the unified graph after `setup()`. Production `ecopages start`
96
+ * imports the emitted modules and does not call `setup()`. Development never reads this list.
97
+ */
98
+ listProductionServerModuleEntries() {
99
+ return [];
100
+ }
101
+ /**
102
+ * Restores in-memory state from the production server-modules map.
103
+ *
104
+ * @remarks
105
+ * Called instead of `setup()` on production `ecopages start`, and in the Lit static-render
106
+ * worker. Must not scan sources or write under the work directory.
107
+ */
108
+ restoreProductionRuntime() {
109
+ return Promise.resolve();
110
+ }
92
111
  getCachePath(key) {
93
112
  return `${this.context?.cache}/${key}`;
94
113
  }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Process-wide server DOM installation for Integrations that render custom elements.
3
+ *
4
+ * @remarks
5
+ * Lit and Radiant each need constructors on `globalThis`. Installing a complete
6
+ * surface after an incomplete one replaces `customElements` and drops defined
7
+ * elements. Core therefore runs every configured `complete` installer, then
8
+ * every `repair`, before Integration `setup()` continues. Config order does not
9
+ * change the result. Installers must be idempotent and must not replace an
10
+ * existing custom element registry.
11
+ */
12
+ export type ServerDomSurfaceKind = 'complete' | 'repair';
13
+ export type ServerDomInstaller = {
14
+ kind: ServerDomSurfaceKind;
15
+ install: () => void | Promise<void>;
16
+ };
17
+ export type ServerDomContributor = {
18
+ serverDom?: ServerDomInstaller;
19
+ };
20
+ /**
21
+ * Installs the configured server DOM surfaces, serializing concurrent callers.
22
+ *
23
+ * @remarks
24
+ * Complete surfaces run first, then repairs, regardless of Integration order.
25
+ * Each caller runs its own installers after the previous pass, so a second app
26
+ * that starts while the first is still installing is not skipped. Installers
27
+ * must be idempotent and must not replace an existing custom element registry.
28
+ */
29
+ export declare function installConfiguredServerDom(integrations: ReadonlyArray<ServerDomContributor>): Promise<void>;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Process-wide server DOM installation for Integrations that render custom elements.
3
+ *
4
+ * @remarks
5
+ * Lit and Radiant each need constructors on `globalThis`. Installing a complete
6
+ * surface after an incomplete one replaces `customElements` and drops defined
7
+ * elements. Core therefore runs every configured `complete` installer, then
8
+ * every `repair`, before Integration `setup()` continues. Config order does not
9
+ * change the result. Installers must be idempotent and must not replace an
10
+ * existing custom element registry.
11
+ */
12
+ let tail = Promise.resolve();
13
+ /**
14
+ * Installs the configured server DOM surfaces, serializing concurrent callers.
15
+ *
16
+ * @remarks
17
+ * Complete surfaces run first, then repairs, regardless of Integration order.
18
+ * Each caller runs its own installers after the previous pass, so a second app
19
+ * that starts while the first is still installing is not skipped. Installers
20
+ * must be idempotent and must not replace an existing custom element registry.
21
+ */
22
+ export async function installConfiguredServerDom(integrations) {
23
+ const run = tail.then(() => runInstallers(integrations));
24
+ tail = run.then(() => undefined, () => undefined);
25
+ await run;
26
+ }
27
+ async function runInstallers(integrations) {
28
+ const installers = integrations
29
+ .map((integration) => integration.serverDom)
30
+ .filter((installer) => installer !== undefined);
31
+ const complete = installers.filter((installer) => installer.kind === 'complete');
32
+ const repair = installers.filter((installer) => installer.kind !== 'complete');
33
+ for (const installer of [...complete, ...repair]) {
34
+ await installer.install();
35
+ }
36
+ }
@@ -11,6 +11,8 @@ export declare function isBarePackageImportSpecifier(specifier: string, projectR
11
11
  /**
12
12
  * Resolves a bare npm package entry for browser vendor prebundles.
13
13
  *
14
+ * @param fromDirectory - Where resolution starts. Defaults to `projectRoot`; a vendor's own dependency
15
+ * resolves from the importing file's directory, since strict installs do not expose it at the root.
14
16
  * @returns The entry `path` and the installed package's root `package.json`
15
17
  * (`packageJsonPath`), which stays the root manifest when the entry sits below a
16
18
  * nested one such as `cjs/package.json`.
@@ -22,7 +24,7 @@ export declare function isBarePackageImportSpecifier(specifier: string, projectR
22
24
  * export condition so legacy UMD `exports.browser` entries cannot win during
23
25
  * Rolldown bundling.
24
26
  */
25
- export declare function resolveBarePackageBrowserEntry(projectRoot: string, specifier: string): {
27
+ export declare function resolveBarePackageBrowserEntry(projectRoot: string, specifier: string, fromDirectory?: string): {
26
28
  path: string;
27
29
  packageJsonPath?: string;
28
30
  } | undefined;
@@ -153,6 +153,8 @@ function getBrowserPackageResolver(projectRoot, mainFields, conditionNames) {
153
153
  /**
154
154
  * Resolves a bare npm package entry for browser vendor prebundles.
155
155
  *
156
+ * @param fromDirectory - Where resolution starts. Defaults to `projectRoot`; a vendor's own dependency
157
+ * resolves from the importing file's directory, since strict installs do not expose it at the root.
156
158
  * @returns The entry `path` and the installed package's root `package.json`
157
159
  * (`packageJsonPath`), which stays the root manifest when the entry sits below a
158
160
  * nested one such as `cjs/package.json`.
@@ -164,11 +166,11 @@ function getBrowserPackageResolver(projectRoot, mainFields, conditionNames) {
164
166
  * export condition so legacy UMD `exports.browser` entries cannot win during
165
167
  * Rolldown bundling.
166
168
  */
167
- export function resolveBarePackageBrowserEntry(projectRoot, specifier) {
169
+ export function resolveBarePackageBrowserEntry(projectRoot, specifier, fromDirectory = projectRoot) {
168
170
  const browserFirst = usesBrowserFirstPackageResolution(specifier);
169
171
  const mainFields = browserFirst ? BROWSER_FIRST_MAIN_FIELDS : MODULE_FIRST_MAIN_FIELDS;
170
172
  const conditionNames = browserFirst ? BROWSER_FIRST_CONDITION_NAMES : MODULE_FIRST_CONDITION_NAMES;
171
- const result = getBrowserPackageResolver(projectRoot, mainFields, conditionNames).sync(projectRoot, specifier);
173
+ const result = getBrowserPackageResolver(projectRoot, mainFields, conditionNames).sync(fromDirectory, specifier);
172
174
  if (result.error || !result.path) {
173
175
  return undefined;
174
176
  }
@@ -1,4 +1,4 @@
1
1
  export { writeHashedBrowserAsset } from './assets/hashed-browser-asset.js';
2
2
  export type { AssetDefinition, ProcessedAsset } from './types/asset-types.js';
3
- export { type EcoBuildOnLoadResult, type EcoBuildOnResolveArgs, type EcoBuildPlugin, type EcoBuildPluginBuilder, mergeProcessorOptions, Processor, type ProcessorConfig, type ProcessorContext, type ProcessorWatchChanges, type ProcessorWatchConfig, resolveGeneratedPath, writeGeneratedTypesPackage, } from './plugins/processor.js';
3
+ export { type EcoBuildOnLoadResult, type EcoBuildImportKind, type EcoBuildOnResolveArgs, type EcoBuildPlugin, type EcoBuildPluginBuilder, mergeProcessorOptions, Processor, type ProcessorConfig, type ProcessorContext, type ProcessorWatchChanges, type ProcessorWatchConfig, resolveGeneratedPath, writeGeneratedTypesPackage, } from './plugins/processor.js';
4
4
  export { getEcopagesEnv, isDevelopmentRuntime, isEcopagesEnvDisabled, isEcopagesEnvEnabled, isProductionRuntime, type EcopagesBooleanEnvironmentVariable, type EcopagesEnvironmentVariable, } from './env.js';
@@ -15,10 +15,12 @@ export type ErrorPageRenderInput = {
15
15
  * Owns error-page source precedence and rendering for runtime and static paths.
16
16
  *
17
17
  * @remarks
18
- * Filesystem semantic pages win over explicitly registered views. A missing
19
- * custom source is the only case that uses a framework default; rendering
20
- * failures are intentionally propagated so callers can apply their own retry
21
- * or fallback policy without hiding the original failure.
18
+ * Filesystem semantic pages win over explicitly registered views. A recorded
19
+ * production server-modules entry counts as a filesystem source when the
20
+ * original file is gone. A missing custom source is the only case that uses a
21
+ * framework default; rendering failures are intentionally propagated so
22
+ * callers can apply their own retry or fallback policy without hiding the
23
+ * original failure.
22
24
  */
23
25
  export declare class ErrorPageRenderer {
24
26
  private readonly appConfig;
@@ -1,6 +1,7 @@
1
1
  import { fileSystem } from '@ecopages/file-system';
2
2
  import { appLogger } from '../../global/app-logger.js';
3
3
  import { ensureIntegrationRuntimeReady } from '../../build/app-build-manifest-runtime.js';
4
+ import { hasProductionServerModule } from '../../build/server/server-modules-manifest.js';
4
5
  import { findIntegrationForFile } from '../../plugins/find-integration-for-file.js';
5
6
  import { prepareExplicitStaticRender } from '../explicit-view-render-preparation.js';
6
7
  import { ERROR_PAGE_STATUS_BY_KIND, kindForStatus } from '../../errors/http-error-page-contract.js';
@@ -20,10 +21,12 @@ function resolveRenderTarget(input) {
20
21
  * Owns error-page source precedence and rendering for runtime and static paths.
21
22
  *
22
23
  * @remarks
23
- * Filesystem semantic pages win over explicitly registered views. A missing
24
- * custom source is the only case that uses a framework default; rendering
25
- * failures are intentionally propagated so callers can apply their own retry
26
- * or fallback policy without hiding the original failure.
24
+ * Filesystem semantic pages win over explicitly registered views. A recorded
25
+ * production server-modules entry counts as a filesystem source when the
26
+ * original file is gone. A missing custom source is the only case that uses a
27
+ * framework default; rendering failures are intentionally propagated so
28
+ * callers can apply their own retry or fallback policy without hiding the
29
+ * original failure.
27
30
  */
28
31
  export class ErrorPageRenderer {
29
32
  appConfig;
@@ -62,7 +65,8 @@ export class ErrorPageRenderer {
62
65
  }
63
66
  resolveCustomSource(kind) {
64
67
  const templatePath = this.getTemplatePath(kind);
65
- if (templatePath && fileSystem.exists(templatePath)) {
68
+ if (templatePath &&
69
+ (fileSystem.exists(templatePath) || hasProductionServerModule(this.appConfig, templatePath))) {
66
70
  return { kind: 'filesystem', templatePath };
67
71
  }
68
72
  const loader = this.loaders[kind];
@@ -1,7 +1,5 @@
1
1
  import type { BaseIntegrationContext, ComponentRenderResult, EcoComponent, PageMetadataProps } from '../../../types/contracts.js';
2
2
  import type { InternalComponentRenderInput } from '../../../config/internal-types.js';
3
- import type { ProcessedAsset } from '../../../assets/asset-processing-service/index.js';
4
- import { HtmlTransformerService, type HtmlDocumentContribution } from '../../../html/html-transformer.service.js';
5
3
  export type DocumentShellLayoutInput = {
6
4
  component: EcoComponent;
7
5
  props?: Record<string, unknown>;
@@ -9,7 +7,6 @@ export type DocumentShellLayoutInput = {
9
7
  export type DocumentShellComposeChildrenContext = {
10
8
  primaryComponent: EcoComponent;
11
9
  primaryProps: Record<string, unknown>;
12
- primaryRender?: ComponentRenderResult;
13
10
  layouts: DocumentShellLayoutInput[];
14
11
  rendererCache: BaseIntegrationContext['rendererCache'];
15
12
  renderComponentWithForeignChildren: DocumentShellRenderDependencies['renderComponentWithForeignChildren'];
@@ -17,25 +14,16 @@ export type DocumentShellComposeChildrenContext = {
17
14
  export type DocumentShellComposeChildrenResult = {
18
15
  /** Serialized or element children passed to the HTML template shell. */
19
16
  children: unknown;
20
- layoutRenders: ComponentRenderResult[];
21
- /**
22
- * Primary/page render assets when the hook performs unified composition.
23
- *
24
- * @remarks
25
- * Omit only when the default sequential string path runs (core renders primary first).
26
- */
27
- primaryRender?: ComponentRenderResult;
28
17
  };
29
18
  /**
30
19
  * Optional hook that replaces default sequential string layout wrapping.
31
20
  *
32
21
  * @remarks
33
22
  * When provided, core skips the initial primary render and expects the hook to return
34
- * `children` for the HTML template. Supply `primaryRender` so dependency assets still merge.
23
+ * `children` for the HTML template.
35
24
  */
36
25
  export type DocumentShellComposeChildrenHook = (context: DocumentShellComposeChildrenContext) => Promise<DocumentShellComposeChildrenResult>;
37
26
  export type DocumentShellComposeInput = {
38
- inheritedOwner: string;
39
27
  primaryComponent: EcoComponent;
40
28
  primaryProps: Record<string, unknown>;
41
29
  /** Components whose ownership graphs must join the foreign-child decision. */
@@ -47,7 +35,6 @@ export type DocumentShellComposeInput = {
47
35
  documentProps: Record<string, unknown>;
48
36
  };
49
37
  export type DocumentShellPageRenderInput = {
50
- inheritedOwner: string;
51
38
  page: {
52
39
  component: EcoComponent;
53
40
  props: Record<string, unknown>;
@@ -65,16 +52,11 @@ export type DocumentShellPageRenderInput = {
65
52
  };
66
53
  export type DocumentShellRenderDependencies = {
67
54
  renderComponentWithForeignChildren(input: InternalComponentRenderInput): Promise<ComponentRenderResult>;
68
- appendProcessedDependencies(...assetGroups: Array<readonly ProcessedAsset[] | undefined>): ProcessedAsset[];
69
- };
70
- export type DocumentShellAttributeStamping = {
71
- applyAttributesToFirstBodyElement(html: string, attributes: Record<string, string>): string;
72
- applyAttributesToHtmlElement(html: string, attributes: Record<string, string>): string;
73
55
  };
74
56
  /**
75
57
  * Default sequential string-child composition for document shell layers.
76
58
  */
77
- export declare function composeSequentialLayoutChildren(context: DocumentShellComposeChildrenContext): Promise<DocumentShellComposeChildrenResult>;
59
+ export declare function composeSequentialLayoutChildren(context: DocumentShellComposeChildrenContext, primaryHtml: string): Promise<DocumentShellComposeChildrenResult>;
78
60
  /**
79
61
  * Composes page or view content through optional layout and document shells.
80
62
  *
@@ -84,31 +66,7 @@ export declare function composeSequentialLayoutChildren(context: DocumentShellCo
84
66
  export declare function composeDocumentShell(dependencies: DocumentShellRenderDependencies, input: DocumentShellComposeInput): Promise<{
85
67
  documentHtml: string;
86
68
  }>;
87
- /**
88
- * Applies optional component-root and document-root attribute stamping before HTML
89
- * transformation runs on explicit renderer-owned paths.
90
- */
91
- export declare function applyDocumentShellAttributeStamping(html: string, stamping: DocumentShellAttributeStamping, options: {
92
- componentRootAttributes?: Record<string, string>;
93
- documentAttributes?: Record<string, string>;
94
- }): string;
95
69
  /**
96
70
  * Builds the final serialized document HTML for one route page render.
97
71
  */
98
72
  export declare function renderPageDocumentShell(dependencies: DocumentShellRenderDependencies, input: DocumentShellPageRenderInput, docType: string): Promise<string>;
99
- /**
100
- * Finalizes already-resolved HTML for explicit renderer-owned paths.
101
- *
102
- * @remarks
103
- * Callers append renderer bootstrap dependencies before invoking this helper.
104
- * Stamps document/root attributes and runs HTML transformation after nested
105
- * foreign-subtree resolution without routing back through shared route execution.
106
- */
107
- export declare function finalizeDocumentShellHtml(htmlTransformer: HtmlTransformerService, options: {
108
- html: string;
109
- partial?: boolean;
110
- componentRootAttributes?: Record<string, string>;
111
- documentAttributes?: Record<string, string>;
112
- transformHtml?: boolean;
113
- htmlContributions?: HtmlDocumentContribution[];
114
- }): Promise<string>;