@ecopages/core 0.8.0 → 0.9.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 (145) hide show
  1. package/README.md +2 -2
  2. package/package.json +14 -4
  3. package/src/adapters/node/create-app.d.ts +1 -1
  4. package/src/adapters/node/create-app.js +1 -1
  5. package/src/adapters/node/server-adapter.d.ts +1 -0
  6. package/src/adapters/node/server-adapter.js +4 -1
  7. package/src/adapters/shared/hmr/hmr-manager.d.ts +2 -0
  8. package/src/adapters/shared/hmr/hmr-manager.js +8 -4
  9. package/src/adapters/shared/http/api-request-pipeline.d.ts +16 -3
  10. package/src/adapters/shared/http/api-request-pipeline.js +16 -11
  11. package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
  12. package/src/adapters/shared/runtime/render-context.d.ts +2 -0
  13. package/src/adapters/shared/runtime/render-context.js +4 -0
  14. package/src/adapters/shared/runtime/server-request-pipeline.d.ts +2 -2
  15. package/src/adapters/shared/runtime/server-request-pipeline.js +4 -3
  16. package/src/adapters/shared/runtime/server-static-builder.js +4 -1
  17. package/src/adapters/shared/runtime/unattached-scripts.d.ts +17 -0
  18. package/src/adapters/shared/runtime/unattached-scripts.js +57 -0
  19. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +3 -2
  20. package/src/adapters/shared/ws/ws-pattern-matcher.d.ts +14 -1
  21. package/src/adapters/shared/ws/ws-pattern-matcher.js +14 -13
  22. package/src/assets/app-browser-client-build.js +3 -0
  23. package/src/assets/asset-processing-service/asset-processing.service.d.ts +9 -0
  24. package/src/assets/asset-processing-service/asset-processing.service.js +19 -0
  25. package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +16 -2
  26. package/src/assets/asset-processing-service/processed-asset-ledger.js +31 -3
  27. package/src/build/build-graph.d.ts +19 -2
  28. package/src/build/build-graph.js +19 -18
  29. package/src/build/cache/pages-unified-graph-build.d.ts +4 -6
  30. package/src/build/cache/pages-unified-graph-build.js +14 -51
  31. package/src/build/cache/server-module-entries.d.ts +5 -9
  32. package/src/build/cache/server-module-entries.js +5 -58
  33. package/src/build/contracts/build-contracts.d.ts +15 -0
  34. package/src/build/contracts.d.ts +1 -1
  35. package/src/build/contracts.js +1 -1
  36. package/src/build/production-asset-ledger.d.ts +1 -1
  37. package/src/build/production-asset-ledger.js +4 -2
  38. package/src/build/rolldown/file-role-grammar-plugin.d.ts +11 -0
  39. package/src/build/rolldown/file-role-grammar-plugin.js +32 -0
  40. package/src/build/rolldown/rolldown-adapter-helpers.d.ts +11 -0
  41. package/src/build/rolldown/rolldown-adapter-helpers.js +79 -10
  42. package/src/build/rolldown/ssr-script-entries-plugin.d.ts +31 -0
  43. package/src/build/rolldown/ssr-script-entries-plugin.js +104 -0
  44. package/src/build/server/server-modules-manifest.d.ts +6 -1
  45. package/src/build/server/server-modules-manifest.js +10 -1
  46. package/src/build/server/view-reference.d.ts +9 -0
  47. package/src/build/server/view-reference.js +11 -0
  48. package/src/build.d.ts +2 -1
  49. package/src/build.js +2 -1
  50. package/src/cli.d.ts +14 -0
  51. package/src/cli.js +14 -0
  52. package/src/config/assembly/app-runtime.d.ts +13 -0
  53. package/src/config/assembly/app-runtime.js +2 -0
  54. package/src/config/assembly/finalize-config.js +13 -8
  55. package/src/config/internal-types.d.ts +0 -12
  56. package/src/config/resolve-eco-config-path.d.ts +2 -0
  57. package/src/config/resolve-eco-config-path.js +2 -1
  58. package/src/config/server-config-bundle.d.ts +0 -1
  59. package/src/config/server-config-bundle.js +1 -1
  60. package/src/config/user-config-types.d.ts +0 -12
  61. package/src/dev/invalidation/development-invalidation.service.d.ts +0 -2
  62. package/src/dev/invalidation/development-invalidation.service.js +1 -11
  63. package/src/dev/transform-server/dev-transform-vendor-registry.js +33 -19
  64. package/src/eco/discovered-dependencies.d.ts +5 -0
  65. package/src/eco/discovered-dependencies.js +9 -0
  66. package/src/eco/eco.browser.js +5 -5
  67. package/src/eco/eco.js +24 -5
  68. package/src/eco/migration-docs.d.ts +7 -0
  69. package/src/eco/migration-docs.js +7 -0
  70. package/src/hmr/client/hmr-runtime.js +1 -1
  71. package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -2
  72. package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +2 -1
  73. package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +4 -3
  74. package/src/html/html-rewriter.d.ts +9 -7
  75. package/src/html/html-rewriter.js +26 -41
  76. package/src/html/html-transformer.service.d.ts +2 -2
  77. package/src/html/html-transformer.service.js +21 -15
  78. package/src/html-pages/html-page-module-scripts.js +2 -1
  79. package/src/html-pages/html-pages.plugin.d.ts +1 -1
  80. package/src/html-pages/html-pages.plugin.js +1 -1
  81. package/src/integration.d.ts +1 -1
  82. package/src/integration.js +1 -1
  83. package/src/islands/island-host.d.ts +16 -5
  84. package/src/islands/island-host.js +8 -1
  85. package/src/plugins/component-import-discovery.d.ts +14 -1
  86. package/src/plugins/component-import-discovery.js +36 -16
  87. package/src/plugins/eco-component-meta-plugin.d.ts +5 -0
  88. package/src/plugins/eco-component-meta-plugin.js +39 -22
  89. package/src/plugins/ecopages-virtual-imports.d.ts +15 -0
  90. package/src/plugins/ecopages-virtual-imports.js +25 -0
  91. package/src/plugins/integration-plugin.d.ts +1 -1
  92. package/src/plugins/integration-plugin.js +1 -1
  93. package/src/plugins/tsconfig-import-resolver.d.ts +2 -0
  94. package/src/plugins/tsconfig-import-resolver.js +7 -5
  95. package/src/route-renderer/error-pages/error-page-renderer.js +3 -2
  96. package/src/route-renderer/explicit-view-render-preparation.d.ts +10 -3
  97. package/src/route-renderer/explicit-view-render-preparation.js +14 -8
  98. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +24 -9
  99. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +73 -50
  100. package/src/route-renderer/orchestration/integration-renderer.d.ts +39 -10
  101. package/src/route-renderer/orchestration/integration-renderer.js +74 -38
  102. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +32 -11
  103. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +68 -61
  104. package/src/route-renderer/page-declaration.d.ts +25 -0
  105. package/src/route-renderer/page-declaration.js +39 -0
  106. package/src/route-renderer/page-loading/component-declarations.d.ts +65 -0
  107. package/src/route-renderer/page-loading/component-declarations.js +77 -0
  108. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -16
  109. package/src/route-renderer/page-loading/component-dependency-collection.js +36 -105
  110. package/src/route-renderer/page-loading/declared-asset-collection.d.ts +19 -14
  111. package/src/route-renderer/page-loading/declared-asset-collection.js +66 -67
  112. package/src/route-renderer/page-loading/dependency-resolver.d.ts +18 -10
  113. package/src/route-renderer/page-loading/dependency-resolver.js +58 -99
  114. package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +19 -26
  115. package/src/route-renderer/page-loading/lazy-entry-collection.js +53 -64
  116. package/src/route-renderer/page-loading/module-declaration-aggregation.d.ts +17 -3
  117. package/src/route-renderer/page-loading/module-declaration-aggregation.js +14 -13
  118. package/src/route-renderer/page-loading/page-module-loader.d.ts +10 -11
  119. package/src/route-renderer/page-loading/page-module-loader.js +30 -30
  120. package/src/router/server/pages-dir.d.ts +7 -0
  121. package/src/router/server/pages-dir.js +7 -0
  122. package/src/router/server/route-registry.d.ts +22 -10
  123. package/src/router/server/route-registry.js +54 -23
  124. package/src/router/server/segment-path-matcher.d.ts +29 -5
  125. package/src/router/server/segment-path-matcher.js +22 -19
  126. package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +2 -2
  127. package/src/static-site-generator/production-page-browser-graph-prebuild.js +5 -5
  128. package/src/static-site-generator/static-site-generator.d.ts +17 -1
  129. package/src/static-site-generator/static-site-generator.js +46 -12
  130. package/src/types/contracts.d.ts +28 -28
  131. package/src/types/eco-api-types.d.ts +17 -12
  132. package/src/types/public-types.d.ts +1 -1
  133. package/src/utils/file-roles.d.ts +48 -0
  134. package/src/utils/file-roles.js +85 -0
  135. package/src/utils/node-builtin.d.ts +10 -0
  136. package/src/utils/node-builtin.js +13 -0
  137. package/src/watchers/project-watcher.js +2 -2
  138. package/src/build/contracts/server-only-specifier.d.ts +0 -8
  139. package/src/build/contracts/server-only-specifier.js +0 -11
  140. package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.d.ts +0 -5
  141. package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +0 -11
  142. package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +0 -12
  143. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +0 -100
  144. package/src/utils/endpoint-file-extensions.d.ts +0 -11
  145. package/src/utils/endpoint-file-extensions.js +0 -13
@@ -131,8 +131,6 @@ export declare class DevelopmentInvalidationService {
131
131
  matchesAdditionalWatchPaths(filePath: string): boolean;
132
132
  /** Returns whether a file is an include or template source. */
133
133
  isIncludeSourceFile(filePath: string): boolean;
134
- /** Returns whether a file is an explicit server-rendered view module. */
135
- isExplicitServerViewFile(filePath: string): boolean;
136
134
  /** Returns whether a file under the source directory has an integration template extension. */
137
135
  isTemplateSourceFile(filePath: string): boolean;
138
136
  /**
@@ -290,12 +290,6 @@ export class DevelopmentInvalidationService {
290
290
  const resolvedPath = path.resolve(filePath);
291
291
  return isPathInside(resolvedPath, this.appConfig.absolutePaths.includesDir) && this.isSourceFile(resolvedPath);
292
292
  }
293
- /** Returns whether a file is an explicit server-rendered view module. */
294
- isExplicitServerViewFile(filePath) {
295
- const resolvedPath = path.resolve(filePath);
296
- const viewsDir = path.join(this.appConfig.absolutePaths.srcDir, 'views');
297
- return isPathInside(resolvedPath, viewsDir) && this.isSourceFile(resolvedPath);
298
- }
299
293
  /** Returns whether a file under the source directory has an integration template extension. */
300
294
  isTemplateSourceFile(filePath) {
301
295
  const resolvedPath = path.resolve(filePath);
@@ -314,11 +308,7 @@ export class DevelopmentInvalidationService {
314
308
  */
315
309
  isServerModuleSourceFile(filePath) {
316
310
  const resolvedPath = path.resolve(filePath);
317
- const sourceRoots = [
318
- this.appConfig.absolutePaths.srcDir,
319
- this.appConfig.absolutePaths.includesDir,
320
- path.join(this.appConfig.absolutePaths.srcDir, 'views'),
321
- ];
311
+ const sourceRoots = [this.appConfig.absolutePaths.srcDir, this.appConfig.absolutePaths.includesDir];
322
312
  return sourceRoots.some((root) => isPathInside(resolvedPath, root)) && this.isSourceFile(resolvedPath);
323
313
  }
324
314
  isSourceFile(filePath) {
@@ -30,36 +30,49 @@ const BROWSER_FIRST_SPECIFIER = new RegExp(`^${escapeRegExp(BROWSER_FIRST_PACKAG
30
30
  const PIN_ENTRY_NAME = '__eco_vendor_pin';
31
31
  const PIN_SPECIFIER = 'ecopages:vendor-pin';
32
32
  const PIN_MODULE_ID = '\0ecopages-vendor-pin';
33
+ const RUNTIME_PIN_ENTRY_NAME = '__eco_vendor_runtime_pin';
34
+ const RUNTIME_PIN_SPECIFIER = 'ecopages:vendor-runtime-pin';
35
+ const RUNTIME_PIN_MODULE_ID = '\0ecopages-vendor-runtime-pin';
36
+ function exactly(value) {
37
+ return new RegExp(`^${escapeRegExp(value)}$`, 'u');
38
+ }
33
39
  /**
34
- * Adds an entry to each vendor build that keeps the shape of the other entries the same from one build to the next.
40
+ * Adds two entries to each vendor build that keep the shape of the other entries the same from one build to the next.
35
41
  *
36
42
  * @remarks
37
43
  * A browser that loaded a vendor file keeps its module, so a later build of the graph must not change a file it
38
- * already served; when it does, the page reloads. Two things would change one as packages arrive. Rolldown puts the
39
- * helpers its CommonJS interop needs in one shared runtime chunk, keeps only the ones the build uses and names the
40
- * chunk after its content, so a package that needs one more helper renames it in every entry that imports it. And a
41
- * CommonJS entry exports its module's `require` function only once another entry imports it, so a package that
42
- * imports `react/jsx-runtime` adds an export to that entry. The pin re-exports every helper and the namespace of every
43
- * entry whose file has no `import` or `export` statement, so each runtime helper and each CommonJS `require` export is
44
- * there from the first build. It leaves ES module entries alone: importing one would move its code into a shared
45
- * chunk behind the entry. Nothing requests the pin's own output.
44
+ * already served; when it does, the page reloads. Two things would change one as packages arrive.
45
+ *
46
+ * Rolldown puts the helpers its CommonJS interop needs in one runtime module. It merges that module into the one
47
+ * chunk that needs it, and splits it into a `rolldown-runtime-*` chunk once a second chunk needs it, so the first
48
+ * ES module that needs a helper moves the helpers out of every CommonJS package's chunk and changes that chunk and
49
+ * its entry. The runtime pin re-exports the module from an entry of its own, so the runtime is always a chunk of
50
+ * its own, with every helper kept, from the first build; its name and content no longer depend on the packages
51
+ * that use it.
52
+ *
53
+ * A CommonJS entry exports its module's `require` function only once another entry imports it, so a package that
54
+ * imports `react/jsx-runtime` adds an export to that entry. The pin re-exports the namespace of every entry whose
55
+ * file has no `import` or `export` statement, so each `require` export is there from the first build. It leaves ES
56
+ * module entries alone: importing one would move its code into a shared chunk behind the entry. Nothing requests
57
+ * the output of either pin.
46
58
  */
47
- function exactly(value) {
48
- return new RegExp(`^${escapeRegExp(value)}$`, 'u');
49
- }
50
59
  function createVendorPinPlugin(entries) {
51
- const contents = [
52
- 'export * from "\\0rolldown/runtime.js";',
53
- ...entries
54
- .filter((entry) => !hasModuleSyntax(entry.entryPath))
55
- .map((entry, index) => `export * as __eco_pin_${index} from ${JSON.stringify(entry.entryPath)};`),
56
- ].join('\n');
60
+ const contents = entries
61
+ .filter((entry) => !hasModuleSyntax(entry.entryPath))
62
+ .map((entry, index) => `export * as __eco_pin_${index} from ${JSON.stringify(entry.entryPath)};`)
63
+ .join('\n');
64
+ const runtimeContents = 'export * from "\\0rolldown/runtime.js";';
57
65
  return {
58
66
  name: 'ecopages-dev-vendor-pin',
59
- cacheKey: contents,
67
+ cacheKey: `${contents}\n${runtimeContents}`,
60
68
  setup(build) {
61
69
  build.onResolve({ filter: exactly(PIN_SPECIFIER) }, () => ({ path: PIN_MODULE_ID }));
62
70
  build.onLoad({ filter: exactly(PIN_MODULE_ID) }, () => ({ contents, loader: 'js' }));
71
+ build.onResolve({ filter: exactly(RUNTIME_PIN_SPECIFIER) }, () => ({ path: RUNTIME_PIN_MODULE_ID }));
72
+ build.onLoad({ filter: exactly(RUNTIME_PIN_MODULE_ID) }, () => ({
73
+ contents: runtimeContents,
74
+ loader: 'js',
75
+ }));
63
76
  },
64
77
  };
65
78
  }
@@ -508,6 +521,7 @@ export class DevTransformVendorRegistry {
508
521
  entrypoints: {
509
522
  ...Object.fromEntries(entries.map((entry) => [path.basename(entry.url, '.js'), entry.entryPath])),
510
523
  [PIN_ENTRY_NAME]: PIN_SPECIFIER,
524
+ [RUNTIME_PIN_ENTRY_NAME]: RUNTIME_PIN_SPECIFIER,
511
525
  },
512
526
  outdir: this.resolveOutdir(),
513
527
  naming: '[name]',
@@ -1,5 +1,6 @@
1
1
  import type { EcoComponentConfig } from '../types/contracts.js';
2
2
  import type { ComponentIdentity } from './component-identity.js';
3
+ import type { EcopagesVirtualImport } from '../plugins/ecopages-virtual-imports.js';
3
4
  /**
4
5
  * What the component meta transform discovered for one declaration.
5
6
  *
@@ -16,6 +17,8 @@ export type DiscoveredDependencies = {
16
17
  plainModuleStylesheets?: string[];
17
18
  /** The entries of `stylesheets` and `plainModuleStylesheets` whose import named a package: package paths. */
18
19
  packageStylesheets?: string[];
20
+ /** The `ecopages:` virtual modules the declaring module imports. */
21
+ virtualImports?: EcopagesVirtualImport[];
19
22
  watchFiles?: string[];
20
23
  };
21
24
  /**
@@ -52,6 +55,8 @@ export declare function getDiscoveredStylesheets(config: EcoComponentConfig | un
52
55
  * without editing the importing Page.
53
56
  */
54
57
  export declare function getDiscoveredWatchFiles(config: EcoComponentConfig | undefined): readonly string[];
58
+ /** The `ecopages:` virtual modules discovery recorded for this component identity. */
59
+ export declare function getDiscoveredVirtualImports(config: EcoComponentConfig | undefined): readonly EcopagesVirtualImport[];
55
60
  /**
56
61
  * Attaches deferred discovered Component references to `config.dependencies`.
57
62
  *
@@ -3,6 +3,7 @@ const INFERRED_STYLESHEETS = Symbol.for('ecopages.identity.inferredStylesheets')
3
3
  const PLAIN_MODULE_STYLESHEETS = Symbol.for('ecopages.identity.plainModuleStylesheets');
4
4
  const PACKAGE_STYLESHEETS = Symbol.for('ecopages.identity.packageStylesheets');
5
5
  const DISCOVERED_WATCH_FILES = Symbol.for('ecopages.identity.watchFiles');
6
+ const VIRTUAL_IMPORTS = Symbol.for('ecopages.identity.virtualImports');
6
7
  function discoveryRecord(identity) {
7
8
  return identity;
8
9
  }
@@ -21,6 +22,7 @@ export function registerDiscoveredDependencies(identity, discovered) {
21
22
  record[PLAIN_MODULE_STYLESHEETS] = discovered.plainModuleStylesheets;
22
23
  record[PACKAGE_STYLESHEETS] = discovered.packageStylesheets;
23
24
  record[DISCOVERED_WATCH_FILES] = discovered.watchFiles;
25
+ record[VIRTUAL_IMPORTS] = discovered.virtualImports;
24
26
  }
25
27
  /**
26
28
  * Inferred stylesheets registered for this component identity, split by where the import sits, as discovery
@@ -59,6 +61,13 @@ export function getDiscoveredWatchFiles(config) {
59
61
  return [];
60
62
  return discoveryRecord(identity)[DISCOVERED_WATCH_FILES] ?? discoveries.get(identity)?.watchFiles ?? [];
61
63
  }
64
+ /** The `ecopages:` virtual modules discovery recorded for this component identity. */
65
+ export function getDiscoveredVirtualImports(config) {
66
+ const identity = config?.identity;
67
+ if (!identity)
68
+ return [];
69
+ return discoveryRecord(identity)[VIRTUAL_IMPORTS] ?? discoveries.get(identity)?.virtualImports ?? [];
70
+ }
62
71
  function isDeclared(value) {
63
72
  return typeof value === 'function' && Boolean(value.config?.identity);
64
73
  }
@@ -30,7 +30,7 @@ function layout(options) {
30
30
  return createComponentFactory(options);
31
31
  }
32
32
  function page(options) {
33
- const { layout: pageLayout, dependencies: dependenciesInput, render, staticPaths, staticProps, metadata, cache, requires, middleware, } = options;
33
+ const { layout: pageLayout, dependencies: dependenciesInput, render, paths, props, metadata, cache, requires, middleware, } = options;
34
34
  const layoutEntries = normalizePageLayouts(pageLayout);
35
35
  const resolveDependencies = typeof dependenciesInput === 'function' ? dependenciesInput : undefined;
36
36
  const staticDependencies = typeof dependenciesInput === 'function'
@@ -45,11 +45,11 @@ function page(options) {
45
45
  if (pageComponent.config) {
46
46
  applyPageLayoutConfig(pageComponent.config, layoutEntries);
47
47
  }
48
- if (staticPaths) {
49
- pageComponent.staticPaths = staticPaths;
48
+ if (paths) {
49
+ pageComponent.paths = paths;
50
50
  }
51
- if (staticProps) {
52
- pageComponent.staticProps = staticProps;
51
+ if (props) {
52
+ pageComponent.props = props;
53
53
  }
54
54
  if (metadata) {
55
55
  pageComponent.metadata = metadata;
package/src/eco/eco.js CHANGED
@@ -7,6 +7,7 @@ import { isThenable } from './component-render-output.js';
7
7
  import { applyPageLayoutConfig, mergeLayoutDependencies, normalizePageLayouts } from './page-layout-normalization.js';
8
8
  import { getComponentIdentity, getComponentOwner } from './component-identity.js';
9
9
  import { attachDiscoveredDependencies } from './discovered-dependencies.js';
10
+ import { DATA_HOOKS_MIGRATION_URL } from './migration-docs.js';
10
11
  /**
11
12
  * Creates a component factory with lazy-trigger support and foreign-child-runtime
12
13
  * interception.
@@ -110,6 +111,23 @@ function html(options) {
110
111
  function layout(options) {
111
112
  return createComponentFactory(options);
112
113
  }
114
+ const RENAMED_PAGE_OPTIONS = { staticProps: 'props', staticPaths: 'paths' };
115
+ /**
116
+ * Fails a page that still declares a data hook under its pre-rename option name.
117
+ *
118
+ * @remarks
119
+ * `eco.page()` copies only the options it knows, so an old name would otherwise be dropped silently and the
120
+ * page would render without its data.
121
+ */
122
+ function assertNoRenamedPageOptions(options) {
123
+ const found = Object.keys(RENAMED_PAGE_OPTIONS).filter((name) => name in options);
124
+ if (found.length === 0)
125
+ return;
126
+ const renames = found
127
+ .map((name) => `${name} is now ${RENAMED_PAGE_OPTIONS[name]}`)
128
+ .join(', ');
129
+ throw new Error(`[ecopages] eco.page() no longer accepts ${found.join(', ')}: ${renames}, and the hook returns its value directly instead of a { props } or { paths } envelope. Migration steps: ${DATA_HOOKS_MIGRATION_URL}`);
130
+ }
113
131
  /**
114
132
  * Creates a page component and attaches optional static APIs.
115
133
  *
@@ -117,7 +135,8 @@ function layout(options) {
117
135
  * @returns Eco page component.
118
136
  */
119
137
  function page(options) {
120
- const { layout, dependencies: dependenciesInput, render, staticPaths, staticProps, metadata, cache, requires, middleware, } = options;
138
+ assertNoRenamedPageOptions(options);
139
+ const { layout, dependencies: dependenciesInput, render, paths, props, metadata, cache, requires, middleware, } = options;
121
140
  const layoutEntries = normalizePageLayouts(layout);
122
141
  const resolveDependencies = typeof dependenciesInput === 'function' ? dependenciesInput : undefined;
123
142
  const staticDependencies = typeof dependenciesInput === 'function'
@@ -133,10 +152,10 @@ function page(options) {
133
152
  if (pageComponent.config) {
134
153
  applyPageLayoutConfig(pageComponent.config, layoutEntries);
135
154
  }
136
- if (staticPaths)
137
- pageComponent.staticPaths = staticPaths;
138
- if (staticProps)
139
- pageComponent.staticProps = staticProps;
155
+ if (paths)
156
+ pageComponent.paths = paths;
157
+ if (props)
158
+ pageComponent.props = props;
140
159
  if (metadata)
141
160
  pageComponent.metadata = metadata;
142
161
  if (resolveDependencies)
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Where the docs explain how to migrate a page to the current data hooks.
3
+ *
4
+ * @remarks
5
+ * Errors link here instead of naming `@ecopages/codemod`, which is not published to npm.
6
+ */
7
+ export declare const DATA_HOOKS_MIGRATION_URL = "https://ecopages.app/docs/core/data-fetching#migrating-from-staticprops-and-staticpaths";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Where the docs explain how to migrate a page to the current data hooks.
3
+ *
4
+ * @remarks
5
+ * Errors link here instead of naming `@ecopages/codemod`, which is not published to npm.
6
+ */
7
+ export const DATA_HOOKS_MIGRATION_URL = 'https://ecopages.app/docs/core/data-fetching#migrating-from-staticprops-and-staticpaths';
@@ -75,7 +75,7 @@ import { resetBuildErrors, reportBuildError } from './build-error-presentation.j
75
75
  getHandlers: () => window.__ECO_PAGES__?.hmrHandlers,
76
76
  getActivePageModule: () => window.__ECO_PAGES__?.page?.module,
77
77
  reloadCurrentPage: async (request) => Boolean(await navigationRuntime.reloadCurrentPage(request)),
78
- importModule: (url) => import(url),
78
+ importModule: (url) => import(/* @vite-ignore */ url),
79
79
  waitForSettled: async () => waitForNavigationToSettle(navigationRuntime),
80
80
  reloadPage,
81
81
  }, timestamp);
@@ -19,8 +19,6 @@ export interface JsHmrContext extends HmrRegisteredEntrypointsContext {
19
19
  getDependencyEntrypoints(filePath: string): Set<string>;
20
20
  };
21
21
  getSrcDir(): string;
22
- getPagesDir(): string;
23
- getLayoutsDir(): string;
24
22
  getTemplateExtensions(): string[];
25
23
  /** Whether `filePath` is a stylesheet, which a served module can import as text. */
26
24
  isStylesheet(filePath: string): boolean;
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * HMR strategy for server-rendered include templates and explicit server views.
3
3
  *
4
- * These files affect SSR output (head, layout shell, explicit views) but are not
4
+ * An explicit view is a file the server entry imports as a View Reference, wherever it lives. These files affect
5
+ * SSR output (head, layout shell, explicit views) but are not
5
6
  * client HMR entrypoints. Broadcast a layout-update so the active navigation
6
7
  * runtime can refresh the current page without a full document reload.
7
8
  */
@@ -1,11 +1,13 @@
1
1
  /**
2
2
  * HMR strategy for server-rendered include templates and explicit server views.
3
3
  *
4
- * These files affect SSR output (head, layout shell, explicit views) but are not
4
+ * An explicit view is a file the server entry imports as a View Reference, wherever it lives. These files affect
5
+ * SSR output (head, layout shell, explicit views) but are not
5
6
  * client HMR entrypoints. Broadcast a layout-update so the active navigation
6
7
  * runtime can refresh the current page without a full document reload.
7
8
  */
8
9
  import { HmrStrategy, HmrStrategyType } from '../hmr-strategy.js';
10
+ import { isViewReferencePath } from '../../build/server/view-reference.js';
9
11
  /** Outranks integration-owned strategies that may also match shared dependencies. */
10
12
  const SERVER_RENDERED_TEMPLATE_PRIORITY_OFFSET = 50;
11
13
  export class ServerRenderedTemplateHmrStrategy extends HmrStrategy {
@@ -17,8 +19,7 @@ export class ServerRenderedTemplateHmrStrategy extends HmrStrategy {
17
19
  this.invalidationService = invalidationService;
18
20
  }
19
21
  matches(filePath) {
20
- return (this.invalidationService.isIncludeSourceFile(filePath) ||
21
- this.invalidationService.isExplicitServerViewFile(filePath));
22
+ return this.invalidationService.isIncludeSourceFile(filePath) || isViewReferencePath(filePath);
22
23
  }
23
24
  async process(filePath) {
24
25
  return {
@@ -55,7 +55,7 @@ export declare class HtmlRewriter {
55
55
  transform(input: string): string;
56
56
  transform(input: Response): Response;
57
57
  }
58
- /** Attribute access on the element passed to {@link rewriteFirstElement}. */
58
+ /** Attribute access on the element passed to {@link rewriteFirstElement} and {@link rewriteLeadingElement}. */
59
59
  export type HtmlRewriterAttributeTarget = Pick<HtmlRewriterElement, 'tagName' | 'attributes' | 'getAttribute' | 'hasAttribute' | 'setAttribute' | 'removeAttribute'>;
60
60
  /**
61
61
  * Rewrites the attributes of the first start tag that `isTarget` accepts and
@@ -67,11 +67,13 @@ export type HtmlRewriterAttributeTarget = Pick<HtmlRewriterElement, 'tagName' |
67
67
  * is rewritten, so the cost grows with the markup before the target rather than
68
68
  * with the whole document. Only attribute changes are offered: content placed
69
69
  * with `append` or `after` needs the element's end tag, which is never reached.
70
+ */
71
+ export declare function rewriteFirstElement(html: string, isTarget: (element: HtmlRewriterAttributeTarget) => boolean, rewrite: (element: HtmlRewriterAttributeTarget) => void): string;
72
+ /**
73
+ * Rewrites the attributes of the element `html` starts with, whitespace aside.
70
74
  *
71
- * With `leadingOnly`, the target must directly follow the previous start tag
72
- * (or the start of `html`), whitespace aside. When text, a comment or an end tag
73
- * comes first, scanning stops and nothing is rewritten.
75
+ * @remarks
76
+ * Only the leading start tag is read. When text, a comment or an end tag comes first, `html` is returned unchanged,
77
+ * so a Lit render that opens with `<!--lit-part-->` keeps its markup.
74
78
  */
75
- export declare function rewriteFirstElement(html: string, isTarget: (element: HtmlRewriterAttributeTarget) => boolean, rewrite: (element: HtmlRewriterAttributeTarget) => void, options?: {
76
- leadingOnly?: boolean;
77
- }): string;
79
+ export declare function rewriteLeadingElement(html: string, rewrite: (element: HtmlRewriterAttributeTarget) => void): string;
@@ -68,13 +68,8 @@ export class HtmlRewriter {
68
68
  * is rewritten, so the cost grows with the markup before the target rather than
69
69
  * with the whole document. Only attribute changes are offered: content placed
70
70
  * with `append` or `after` needs the element's end tag, which is never reached.
71
- *
72
- * With `leadingOnly`, the target must directly follow the previous start tag
73
- * (or the start of `html`), whitespace aside. When text, a comment or an end tag
74
- * comes first, scanning stops and nothing is rewritten.
75
71
  */
76
- export function rewriteFirstElement(html, isTarget, rewrite, options = {}) {
77
- const leadingOnly = options.leadingOnly ?? false;
72
+ export function rewriteFirstElement(html, isTarget, rewrite) {
78
73
  const session = new RewriteSession([
79
74
  {
80
75
  tagName: '*',
@@ -82,15 +77,35 @@ export function rewriteFirstElement(html, isTarget, rewrite, options = {}) {
82
77
  element(element) {
83
78
  if (!isTarget(element))
84
79
  return;
85
- if (!leadingOnly || !session.contentBeforeStartTag)
86
- rewrite(element);
80
+ rewrite(element);
87
81
  session.stop();
88
82
  },
89
83
  },
90
84
  },
91
- ], { trackLeadingText: leadingOnly });
85
+ ]);
92
86
  return `${session.write(html)}${session.end()}`;
93
87
  }
88
+ /**
89
+ * Rewrites the attributes of the element `html` starts with, whitespace aside.
90
+ *
91
+ * @remarks
92
+ * Only the leading start tag is read. When text, a comment or an end tag comes first, `html` is returned unchanged,
93
+ * so a Lit render that opens with `<!--lit-part-->` keeps its markup.
94
+ */
95
+ export function rewriteLeadingElement(html, rewrite) {
96
+ let index = 0;
97
+ while (index < html.length && isWhitespaceCode(html.charCodeAt(index)))
98
+ index += 1;
99
+ if (html[index] !== '<' || !isAsciiAlpha(html[index + 1] ?? ''))
100
+ return html;
101
+ const tag = scanTag(html, index);
102
+ if (!tag)
103
+ return html;
104
+ const end = tag.end + 1;
105
+ const element = new RewriterElement(html.slice(index, end), readTagName(html, index + 1).toLowerCase(), tag.selfClosing, false);
106
+ rewrite(element);
107
+ return `${html.slice(0, index)}${element.renderStart()}${html.slice(end)}`;
108
+ }
94
109
  /** SVG and MathML elements whose children are parsed as HTML again. */
95
110
  const HTML_INTEGRATION_POINTS = new Set(['foreignobject', 'desc', 'title', 'mi', 'mo', 'mn', 'ms', 'mtext']);
96
111
  /** HTML start tags that end foreign (SVG or MathML) content. */
@@ -158,29 +173,14 @@ class RewriteSession {
158
173
  rawTextTag = null;
159
174
  scriptState = 'data';
160
175
  stopped = false;
161
- markupSinceStartTag = false;
162
176
  openElements = [];
163
177
  handlers;
164
178
  handledTags;
165
179
  handlesAnyTag;
166
- trackLeadingText;
167
- /**
168
- * @param options.trackLeadingText Also count non-whitespace text in
169
- * {@link contentBeforeStartTag}. Off by default because it scans every text run.
170
- */
171
- constructor(handlers, options = {}) {
180
+ constructor(handlers) {
172
181
  this.handlers = handlers;
173
182
  this.handledTags = new Set(handlers.map((entry) => entry.tagName));
174
183
  this.handlesAnyTag = this.handledTags.has('*');
175
- this.trackLeadingText = options.trackLeadingText ?? false;
176
- }
177
- /**
178
- * Whether a comment, end tag or other non-start-tag markup (and, when tracked,
179
- * non-whitespace text) appeared between the previous start tag and the one
180
- * whose handlers are running.
181
- */
182
- get contentBeforeStartTag() {
183
- return this.markupSinceStartTag;
184
184
  }
185
185
  write(chunk) {
186
186
  this.buffer += chunk;
@@ -218,10 +218,6 @@ class RewriteSession {
218
218
  continue;
219
219
  }
220
220
  const lt = source.indexOf('<', index);
221
- const textEnd = lt === -1 ? source.length : lt;
222
- if (this.trackLeadingText && !this.markupSinceStartTag && hasNonWhitespace(source, index, textEnd)) {
223
- this.markupSinceStartTag = true;
224
- }
225
221
  if (lt === -1) {
226
222
  index = source.length;
227
223
  break;
@@ -256,10 +252,7 @@ class RewriteSession {
256
252
  return null;
257
253
  return { end: tag.end + 1, replacement: this.openElement(source, index, tag.end + 1, tag.selfClosing) };
258
254
  }
259
- const token = this.readNonStartTag(source, index, next, final);
260
- if (token)
261
- this.markupSinceStartTag = true;
262
- return token;
255
+ return this.readNonStartTag(source, index, next, final);
263
256
  }
264
257
  /** Reads a comment, declaration, processing instruction, end tag or a stray `<`. */
265
258
  readNonStartTag(source, index, next, final) {
@@ -330,7 +323,6 @@ class RewriteSession {
330
323
  if (isVoid)
331
324
  replacement += openElement.after;
332
325
  }
333
- this.markupSinceStartTag = false;
334
326
  if (!isVoid) {
335
327
  this.openElements.push(openElement);
336
328
  if (!foreign && RAW_TEXT_ELEMENTS.has(name)) {
@@ -581,10 +573,3 @@ function toMarkup(content, options) {
581
573
  return content;
582
574
  return content.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
583
575
  }
584
- function hasNonWhitespace(source, start, end) {
585
- for (let position = start; position < end; position++) {
586
- if (!isWhitespaceCode(source.charCodeAt(position)))
587
- return true;
588
- }
589
- return false;
590
- }
@@ -26,9 +26,9 @@ export declare class HtmlTransformerService {
26
26
  */
27
27
  applyAttributesToHtmlElement(html: string, attributes: Record<string, string>): string;
28
28
  /**
29
- * Injects page assets and document contributions into a streaming HTML response.
29
+ * Injects page assets and document contributions into rendered HTML.
30
30
  */
31
- transform(res: Response, input?: PageAssetInjection): Response;
31
+ transform(html: string, input?: PageAssetInjection): string;
32
32
  /**
33
33
  * @remarks
34
34
  * Each slot is inserted as one joined string, so contributions and assets keep
@@ -1,5 +1,5 @@
1
1
  import { escapeHtmlAttribute } from '../utils/html-escaping.js';
2
- import { HtmlRewriter, rewriteFirstElement } from './html-rewriter.js';
2
+ import { HtmlRewriter, rewriteFirstElement, rewriteLeadingElement } from './html-rewriter.js';
3
3
  import { buildProcessedAssetDedupeKey, dedupeProcessedAssets } from '../assets/processed-asset-dedupe.js';
4
4
  /**
5
5
  * Rewrites rendered HTML with processed assets and per-render document contributions.
@@ -41,13 +41,19 @@ export class HtmlTransformerService {
41
41
  * Sets attributes on the first `<html>` start tag.
42
42
  */
43
43
  applyAttributesToHtmlElement(html, attributes) {
44
- return stampAttributes(html, attributes, (element) => element.tagName === 'html');
44
+ const entries = stampableEntries(attributes);
45
+ if (entries.length === 0)
46
+ return html;
47
+ return rewriteFirstElement(html, (element) => element.tagName === 'html', (element) => {
48
+ for (const [name, value] of entries)
49
+ element.setAttribute(name, value);
50
+ });
45
51
  }
46
52
  /**
47
- * Injects page assets and document contributions into a streaming HTML response.
53
+ * Injects page assets and document contributions into rendered HTML.
48
54
  */
49
- transform(res, input = {}) {
50
- return this.createRewriter(input.contributions ?? [], input.pagePackage).transform(res);
55
+ transform(html, input = {}) {
56
+ return this.createRewriter(input.contributions ?? [], input.pagePackage).transform(html);
51
57
  }
52
58
  /**
53
59
  * @remarks
@@ -120,22 +126,22 @@ export class HtmlTransformerService {
120
126
  * so a Lit render that opens with `<!--lit-part-->` keeps its markup.
121
127
  */
122
128
  export function applyAttributesToFirstElement(html, attributes) {
123
- return stampAttributes(html, attributes, () => true, { leadingOnly: true });
129
+ const entries = stampableEntries(attributes);
130
+ if (entries.length === 0)
131
+ return html;
132
+ return rewriteLeadingElement(html, (element) => {
133
+ for (const [name, value] of entries)
134
+ element.setAttribute(name, value);
135
+ });
124
136
  }
125
137
  /**
126
- * Sets `attributes` on the first element that `isTarget` accepts.
138
+ * The attributes to stamp.
127
139
  *
128
140
  * @remarks
129
141
  * Entries with an empty name are skipped. An empty value is kept and rendered as
130
142
  * `name=""`, so presence markers such as `data-eco-island` survive. An attribute
131
143
  * the element already has is replaced rather than duplicated.
132
144
  */
133
- function stampAttributes(html, attributes, isTarget, options) {
134
- const entries = Object.entries(attributes).filter(([name]) => name.length > 0);
135
- if (entries.length === 0)
136
- return html;
137
- return rewriteFirstElement(html, isTarget, (element) => {
138
- for (const [name, value] of entries)
139
- element.setAttribute(name, value);
140
- }, options);
145
+ function stampableEntries(attributes) {
146
+ return Object.entries(attributes).filter(([name]) => name.length > 0);
141
147
  }
@@ -12,6 +12,7 @@ import { isCssImport, isDeliveredStylesheetImport } from '../plugins/component-i
12
12
  import { stripsSideEffectStylesheetImports } from '../plugins/eco-component-meta-plugin.js';
13
13
  import { isBarePackageImportSpecifier, loadTsconfigPathPrefixes, resolveProjectModulePath, } from '../plugins/tsconfig-import-resolver.js';
14
14
  import { BrowserBundleService } from '../assets/browser-bundle.service.js';
15
+ import { isPrivatePath } from '../utils/file-roles.js';
15
16
  import { isProductionRuntime } from '../utils/runtime.js';
16
17
  import { compileHtmlPage, compileHtmlShell } from './html-page-template.js';
17
18
  export function createHtmlPageModuleScriptState() {
@@ -225,7 +226,7 @@ function listHtmlFiles(appConfig) {
225
226
  ? fileSystem
226
227
  .readdir(pagesDir, { recursive: true })
227
228
  .map((entry) => entry.name)
228
- .filter((name) => name.endsWith('.html'))
229
+ .filter((name) => name.endsWith('.html') && !isPrivatePath(name))
229
230
  .map((name) => path.join(pagesDir, name))
230
231
  .sort()
231
232
  : [];
@@ -8,7 +8,7 @@ import { HtmlPageRenderer } from './html-page-renderer.js';
8
8
  * @remarks
9
9
  * `finalizeEcoPagesConfig()` appends it after user Integrations unless one of them
10
10
  * already owns `.html`, so apps never register it themselves. HTML Pages have no
11
- * `staticPaths`, so they receive no Params.
11
+ * `paths`, so they receive no Params.
12
12
  */
13
13
  export declare class HtmlPagesPlugin extends IntegrationPlugin {
14
14
  renderer: typeof HtmlPageRenderer;
@@ -8,7 +8,7 @@ import { HtmlPageRenderer } from './html-page-renderer.js';
8
8
  * @remarks
9
9
  * `finalizeEcoPagesConfig()` appends it after user Integrations unless one of them
10
10
  * already owns `.html`, so apps never register it themselves. HTML Pages have no
11
- * `staticPaths`, so they receive no Params.
11
+ * `paths`, so they receive no Params.
12
12
  */
13
13
  export class HtmlPagesPlugin extends IntegrationPlugin {
14
14
  renderer = HtmlPageRenderer;
@@ -18,7 +18,7 @@ export { installConfiguredServerDom } from './plugins/server-dom.js';
18
18
  export { CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES, CustomElementScriptPreloader, type CustomElementScriptPreloadScopeState, type CustomElementSsrPreloadComponent, invalidateCustomElementScriptPreload, type SsrScriptAssignment, type SsrScriptPreload, type SsrScriptPreloadDeclaration, type SsrScriptPreloaderInit, } from './route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js';
19
19
  export { createCustomElementServerModuleImporter, createSharedServerModuleImporter, } from './route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js';
20
20
  export { type DocumentShellComposeChildrenContext, type DocumentShellComposeChildrenResult, type DocumentShellLayoutInput, } from './route-renderer/orchestration/document-shell/document-shell-render.service.js';
21
- export { type QueuedForeignSubtreeResolutionContext, resolveQueuedTokens, } from './route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js';
21
+ export { type QueuedForeignSubtreeResolutionContext, type ResolveForeignSubtreeTokens, } from './route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js';
22
22
  export { createIntegrationRenderer, type HtmlDocumentContribution, type HtmlDocumentContributionContext, IntegrationRenderer, type IntegrationRendererHookFactory, type IntegrationRendererHookFactoryOptions, type IntegrationRendererHooks, type IntegrationRendererOptions, type PageBrowserGraphContribution, type PageBrowserGraphContributionContext, type PageBrowserGraphDeclaration, type PageClientBrowserAssets, type PageClientBuildEntry, type PageClientPlan, type RouteModuleLoadOptions, selectHydrationIslandEntries, } from './route-renderer/orchestration/integration-renderer.js';
23
23
  export { StringMarkupRenderer } from './route-renderer/orchestration/string-markup-renderer.js';
24
24
  export { attachEcoFileMetadataToConfig, collectComponentConfigFilePaths, } from './route-renderer/page-loading/file-scoped-dependency-components.js';
@@ -17,7 +17,7 @@ export { installConfiguredServerDom } from './plugins/server-dom.js';
17
17
  export { CUSTOM_ELEMENT_SSR_PRELOAD_CACHE_SCOPES, CustomElementScriptPreloader, invalidateCustomElementScriptPreload, } from './route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js';
18
18
  export { createCustomElementServerModuleImporter, createSharedServerModuleImporter, } from './route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js';
19
19
  export {} from './route-renderer/orchestration/document-shell/document-shell-render.service.js';
20
- export { resolveQueuedTokens, } from './route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js';
20
+ export {} from './route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js';
21
21
  export { createIntegrationRenderer, IntegrationRenderer, selectHydrationIslandEntries, } from './route-renderer/orchestration/integration-renderer.js';
22
22
  export { StringMarkupRenderer } from './route-renderer/orchestration/string-markup-renderer.js';
23
23
  export { attachEcoFileMetadataToConfig, collectComponentConfigFilePaths, } from './route-renderer/page-loading/file-scoped-dependency-components.js';