@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
@@ -1,6 +1,7 @@
1
1
  import { invariant } from '../../utils/invariant.js';
2
2
  import { requireAppRuntime } from '../../utils/app-runtime.js';
3
3
  import { resolveInternalExecutionDir } from '../../utils/resolve-work-dir.js';
4
+ import { DATA_HOOKS_MIGRATION_URL } from '../../eco/migration-docs.js';
4
5
  import { HttpError } from '../../errors/http-error.js';
5
6
  const LEGACY_PAGE_EXPORT_NAMES = ['getStaticPaths', 'getStaticProps', 'getMetadata'];
6
7
  /**
@@ -43,32 +44,32 @@ export class PageModuleLoaderService {
43
44
  }
44
45
  }
45
46
  /**
46
- * Executes the page's static-props hook with Ecopages runtime context.
47
+ * Executes the page's `props` hook with Ecopages runtime context.
47
48
  *
48
49
  * @remarks
49
- * Pages without a static-props hook still return a normalized empty props
50
+ * Pages without a `props` hook still return a normalized empty props
50
51
  * object so downstream render preparation does not branch on hook presence.
51
52
  */
52
- async getStaticPropsForPage(options) {
53
- const { getStaticProps, params } = options;
54
- return getStaticProps
55
- ? await getStaticProps({
56
- pathname: { params: params ?? {} },
53
+ async getPropsForPage(options) {
54
+ const { getProps, params } = options;
55
+ if (!getProps) {
56
+ return { props: {}, metadata: undefined };
57
+ }
58
+ try {
59
+ const props = await getProps({
60
+ params: params ?? {},
57
61
  appConfig: this.appConfig,
58
62
  runtimeOrigin: requireAppRuntime(this.appConfig).origin,
59
- })
60
- .then((data) => data)
61
- .catch((err) => {
62
- if (HttpError.isHttpError(err) || err instanceof Response) {
63
- throw err;
64
- }
65
- const message = err instanceof Error ? err.message : String(err);
66
- throw new Error(`Error fetching static props: ${message}`, { cause: err });
67
- })
68
- : {
69
- props: {},
70
- metadata: undefined,
71
- };
63
+ });
64
+ return { props };
65
+ }
66
+ catch (err) {
67
+ if (HttpError.isHttpError(err) || err instanceof Response) {
68
+ throw err;
69
+ }
70
+ const message = err instanceof Error ? err.message : String(err);
71
+ throw new Error(`Error fetching props: ${message}`, { cause: err });
72
+ }
72
73
  }
73
74
  /**
74
75
  * Builds the final page metadata object for one render request.
@@ -102,7 +103,7 @@ export class PageModuleLoaderService {
102
103
  const found = LEGACY_PAGE_EXPORT_NAMES.filter((name) => module[name] !== undefined);
103
104
  if (found.length === 0)
104
105
  return;
105
- throw new Error(`[ecopages] ${file} exports ${found.join(', ')}. Pages declare data through the staticPaths, staticProps and metadata options of eco.page({ ... }); module-level exports are no longer read. Run the migrate-to-eco-page codemod from @ecopages/codemod to migrate this file.`);
106
+ throw new Error(`[ecopages] ${file} exports ${found.join(', ')}. Pages declare data through the paths, props and metadata options of eco.page({ ... }); module-level exports are no longer read. Migration steps: ${DATA_HOOKS_MIGRATION_URL}`);
106
107
  }
107
108
  /**
108
109
  * Loads a page module and resolves the data hooks of its Page component.
@@ -120,7 +121,7 @@ export class PageModuleLoaderService {
120
121
  return {
121
122
  module,
122
123
  Page,
123
- getStaticProps: pageComponent.staticProps,
124
+ getProps: pageComponent.props,
124
125
  getMetadata: pageComponent.metadata,
125
126
  integrationSpecificProps,
126
127
  };
@@ -129,19 +130,18 @@ export class PageModuleLoaderService {
129
130
  * Resolves the page data needed by the render pipeline.
130
131
  *
131
132
  * @remarks
132
- * Static props are resolved first because page metadata may depend on those
133
- * props. This preserves the same ordering whether data hooks are declared as
134
- * component statics or module exports. Props passed with the render win over
135
- * static props and are visible to metadata; `skipStaticProps` drops the hook.
133
+ * The `props` hook runs first because page metadata may depend on its result.
134
+ * Props passed with the render win over the hook's props and are visible to
135
+ * metadata; `skipPropsHook` drops the hook.
136
136
  */
137
137
  async resolvePageData(options) {
138
- const staticProps = options.routeOptions.skipStaticProps
138
+ const hookProps = options.routeOptions.skipPropsHook
139
139
  ? {}
140
- : (await this.getStaticPropsForPage({
141
- getStaticProps: options.pageModule.getStaticProps,
140
+ : (await this.getPropsForPage({
141
+ getProps: options.pageModule.getProps,
142
142
  params: options.routeOptions.params,
143
143
  })).props;
144
- const props = { ...staticProps, ...(options.routeOptions.props ?? {}) };
144
+ const props = { ...hookProps, ...(options.routeOptions.props ?? {}) };
145
145
  const metadata = options.skipMetadata
146
146
  ? this.appConfig.defaultMetadata
147
147
  : await this.getMetadataPropsForPage({
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The folder, relative to `srcDir`, that the Route Registry scans for routes when `pagesDir` is not configured.
3
+ *
4
+ * @remarks
5
+ * `pagesDir` is the URL space of the app: the one folder name that carries meaning, owned by the router.
6
+ */
7
+ export declare const DEFAULT_PAGES_DIR = "pages";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The folder, relative to `srcDir`, that the Route Registry scans for routes when `pagesDir` is not configured.
3
+ *
4
+ * @remarks
5
+ * `pagesDir` is the URL space of the app: the one folder name that carries meaning, owned by the router.
6
+ */
7
+ export const DEFAULT_PAGES_DIR = 'pages';
@@ -34,23 +34,20 @@ export type StaticGenerationRoute = {
34
34
  readonly templateRoute: TemplateRoute;
35
35
  readonly params: RouteParams;
36
36
  };
37
- export type StaticPathsContext = {
37
+ export type PathsContext = {
38
38
  readonly appConfig: EcoPagesAppConfig;
39
39
  readonly runtimeOrigin: string;
40
40
  };
41
41
  export type RouteRegistryPageModule = {
42
- readonly staticPaths?: (context: StaticPathsContext) => Promise<{
43
- paths: Array<{
44
- params: RouteParams;
45
- }>;
46
- }>;
47
- readonly staticProps?: unknown;
42
+ readonly paths?: (context: PathsContext) => Promise<Array<{
43
+ params: RouteParams;
44
+ }>>;
48
45
  /**
49
46
  * The Page's Cache Strategy.
50
47
  *
51
48
  * @remarks
52
49
  * `'dynamic'` Pages are omitted from Static Path Expansions (no HTML at Build-Time Rendering).
53
- * When they declare `staticPaths`, those Params are still listed for Page Browser Graph planning.
50
+ * When they declare `paths`, those Params are still listed for Page Browser Graph planning.
54
51
  */
55
52
  readonly cache?: unknown;
56
53
  };
@@ -73,12 +70,19 @@ export declare class RouteRegistry {
73
70
  readonly buildMode: boolean;
74
71
  private readonly pageModuleAdapter;
75
72
  private templateRouteList;
73
+ private routeMatchers;
76
74
  private readonly reloadListeners;
77
75
  constructor(options: RouteRegistryOptions);
78
76
  get origin(): string;
79
77
  get templateRoutes(): readonly TemplateRoute[];
78
+ /**
79
+ * True when `filePath` is the source file of a Page route.
80
+ */
81
+ isPageFile(filePath: string): boolean;
80
82
  private get pageRoutes();
81
83
  init(): Promise<void>;
84
+ /** Sets the routes in match order, parsing each pattern once instead of per request. */
85
+ private useTemplateRoutes;
82
86
  reload(): Promise<void>;
83
87
  onReload(listener: () => void): () => void;
84
88
  matchRequest(requestUrl: string, parsedPathSegments?: ParsedSegmentPath): RouteMatch | null;
@@ -101,10 +105,10 @@ export declare class RouteRegistry {
101
105
  runtimeOrigin: string;
102
106
  }): Promise<readonly StaticPathExpansion[]>;
103
107
  /**
104
- * Params of Dynamic Pages that declare `staticPaths`, for Page Browser Graph planning.
108
+ * Params of Dynamic Pages that declare `paths`, for Page Browser Graph planning.
105
109
  *
106
110
  * @remarks
107
- * The return shape is {@link PathExpansion}, the same records `staticPaths` produces. They are
111
+ * The return shape is {@link PathExpansion}, the same records `paths` produces. They are
108
112
  * not Static Path Expansions: HTML still uses Request-Time Rendering. The build uses them so
109
113
  * each Params list's graph scripts are in the production asset ledger.
110
114
  */
@@ -114,6 +118,14 @@ export declare class RouteRegistry {
114
118
  listStaticGenerationRoutes(input: {
115
119
  runtimeOrigin: string;
116
120
  }): Promise<readonly StaticGenerationRoute[]>;
121
+ /**
122
+ * Classifies `file`, relative to the pages directory, as a Page or an endpoint file, or `undefined` when it is no route.
123
+ *
124
+ * @remarks
125
+ * Private files and `.server.*` and `.script.*` modules are not routes. Any other file with a role
126
+ * segment out of place fails the build, naming the file and the expected form.
127
+ */
128
+ private classifyRouteFile;
117
129
  private scanTemplateRoutes;
118
130
  /**
119
131
  * @remarks
@@ -5,11 +5,11 @@ import { loadProductionTemplateRoutes } from '../../build/production-route-list.
5
5
  import { invariant } from '../../utils/invariant.js';
6
6
  import { isProductionRuntime } from '../../env.js';
7
7
  import { hasKnownStaticExtension } from '../../utils/static-file-extensions.js';
8
- import { ENDPOINT_FILE_EXTENSIONS, findEndpointFileExtension } from '../../utils/endpoint-file-extensions.js';
8
+ import { describeRoleForms, ENDPOINT_FILE_EXTENSIONS, findMisplacedRole, matchRoleSuffix, isPrivatePath, } from '../../utils/file-roles.js';
9
9
  import { normalizePathname } from '../../utils/path-pattern.js';
10
10
  import { parseSearchParams } from './parse-search-params.js';
11
11
  import { findIntegrationForFile, findLongestExtension } from '../../plugins/find-integration-for-file.js';
12
- import { buildSegmentPath, matchParsedSegmentPath, parseSegmentPath, segmentPathPatternKey, } from './segment-path-matcher.js';
12
+ import { buildSegmentPath, compileSegmentPattern, matchParsedSegmentPath, parseSegmentPath, segmentPathPatternKey, } from './segment-path-matcher.js';
13
13
  const ROUTE_PRIORITY = {
14
14
  exact: 0,
15
15
  dynamic: 1,
@@ -23,6 +23,7 @@ export class RouteRegistry {
23
23
  buildMode;
24
24
  pageModuleAdapter;
25
25
  templateRouteList = [];
26
+ routeMatchers = [];
26
27
  reloadListeners = new Set();
27
28
  constructor(options) {
28
29
  this.fallbackOrigin = options.origin;
@@ -38,14 +39,29 @@ export class RouteRegistry {
38
39
  get templateRoutes() {
39
40
  return this.templateRouteList;
40
41
  }
42
+ /**
43
+ * True when `filePath` is the source file of a Page route.
44
+ */
45
+ isPageFile(filePath) {
46
+ const resolved = path.resolve(filePath);
47
+ return this.templateRouteList.some((route) => route.role === 'page' && path.resolve(route.filePath) === resolved);
48
+ }
41
49
  get pageRoutes() {
42
50
  return this.templateRouteList.filter((route) => route.role === 'page');
43
51
  }
44
52
  async init() {
45
53
  const productionRoutes = isProductionRuntime() ? loadProductionTemplateRoutes(this.appConfig) : undefined;
46
- this.templateRouteList = productionRoutes ?? (await this.scanTemplateRoutes());
54
+ this.useTemplateRoutes(productionRoutes ?? (await this.scanTemplateRoutes()));
47
55
  appLogger.debug('RouteRegistry initialized', this.templateRouteList);
48
56
  }
57
+ /** Sets the routes in match order, parsing each pattern once instead of per request. */
58
+ useTemplateRoutes(routes) {
59
+ this.templateRouteList = routes;
60
+ this.routeMatchers = routes.map((route) => ({
61
+ route,
62
+ pattern: compileSegmentPattern(route.pathname, 'filesystem'),
63
+ }));
64
+ }
49
65
  async reload() {
50
66
  await this.init();
51
67
  for (const listener of this.reloadListeners) {
@@ -63,8 +79,8 @@ export class RouteRegistry {
63
79
  const requestedPathname = normalizePathname(url.pathname);
64
80
  const pathSegments = parsedPathSegments ?? parseSegmentPath(requestedPathname);
65
81
  const query = this.getSearchParams(url);
66
- for (const route of this.templateRouteList) {
67
- const params = matchParsedSegmentPath(route.pathname, pathSegments, 'filesystem');
82
+ for (const { route, pattern } of this.routeMatchers) {
83
+ const params = matchParsedSegmentPath(pattern, pathSegments);
68
84
  if (params) {
69
85
  return {
70
86
  requestedPathname,
@@ -108,12 +124,12 @@ export class RouteRegistry {
108
124
  isDynamicRouteSegment(segment) {
109
125
  return segment.startsWith('[') && segment.endsWith(']');
110
126
  }
111
- async expandStaticPaths(route, staticPaths, runtimeOrigin) {
112
- const result = await staticPaths({
127
+ async expandStaticPaths(route, listParams, runtimeOrigin) {
128
+ const result = await listParams({
113
129
  appConfig: this.appConfig,
114
130
  runtimeOrigin,
115
131
  });
116
- return result.paths.map(({ params }) => ({
132
+ return result.map(({ params }) => ({
117
133
  pathname: buildSegmentPath(route.pathname, params, 'filesystem'),
118
134
  templateRoute: route,
119
135
  params,
@@ -129,36 +145,35 @@ export class RouteRegistry {
129
145
  if (!options.include(pageModule)) {
130
146
  continue;
131
147
  }
132
- const staticPaths = pageModule.staticPaths;
133
- if (options.requireStaticHooks && this.buildMode) {
134
- invariant(staticPaths !== undefined, `[ecopages] Missing staticPaths in ${route.filePath}`);
135
- invariant(pageModule.staticProps !== undefined, `[ecopages] Missing staticProps in ${route.filePath}`);
148
+ const listParams = pageModule.paths;
149
+ if (options.requirePaths && this.buildMode) {
150
+ invariant(listParams !== undefined, `[ecopages] Missing paths in ${route.filePath}`);
136
151
  }
137
- if (!staticPaths) {
152
+ if (!listParams) {
138
153
  continue;
139
154
  }
140
- expansions.push(...(await this.expandStaticPaths(route, staticPaths, input.runtimeOrigin)));
155
+ expansions.push(...(await this.expandStaticPaths(route, listParams, input.runtimeOrigin)));
141
156
  }
142
157
  return expansions;
143
158
  }
144
159
  async listStaticPathExpansions(input) {
145
160
  return this.listPathExpansions(input, {
146
161
  include: (pageModule) => pageModule.cache !== 'dynamic',
147
- requireStaticHooks: true,
162
+ requirePaths: true,
148
163
  });
149
164
  }
150
165
  /**
151
- * Params of Dynamic Pages that declare `staticPaths`, for Page Browser Graph planning.
166
+ * Params of Dynamic Pages that declare `paths`, for Page Browser Graph planning.
152
167
  *
153
168
  * @remarks
154
- * The return shape is {@link PathExpansion}, the same records `staticPaths` produces. They are
169
+ * The return shape is {@link PathExpansion}, the same records `paths` produces. They are
155
170
  * not Static Path Expansions: HTML still uses Request-Time Rendering. The build uses them so
156
171
  * each Params list's graph scripts are in the production asset ledger.
157
172
  */
158
173
  async listDynamicPagePathExpansions(input) {
159
174
  return this.listPathExpansions(input, {
160
- include: (pageModule) => pageModule.cache === 'dynamic' && pageModule.staticPaths !== undefined,
161
- requireStaticHooks: false,
175
+ include: (pageModule) => pageModule.cache === 'dynamic' && pageModule.paths !== undefined,
176
+ requirePaths: false,
162
177
  });
163
178
  }
164
179
  async listStaticGenerationRoutes(input) {
@@ -180,6 +195,22 @@ export class RouteRegistry {
180
195
  })),
181
196
  ];
182
197
  }
198
+ /**
199
+ * Classifies `file`, relative to the pages directory, as a Page or an endpoint file, or `undefined` when it is no route.
200
+ *
201
+ * @remarks
202
+ * Private files and `.server.*` and `.script.*` modules are not routes. Any other file with a role
203
+ * segment out of place fails the build, naming the file and the expected form.
204
+ */
205
+ classifyRouteFile(file) {
206
+ const match = matchRoleSuffix(file);
207
+ if (isPrivatePath(file) || match?.role === 'server' || match?.role === 'script') {
208
+ return undefined;
209
+ }
210
+ const misplacedRole = findMisplacedRole(file);
211
+ invariant(misplacedRole === undefined, `${path.join(this.pagesDir, file)}: the "${misplacedRole}" role segment must come directly before a script extension, as in ${describeRoleForms()}. Rename the file, or prefix it with "_" to keep it out of routing.`);
212
+ return match ? { role: 'endpoint', endpointExtension: match.suffix } : { role: 'page' };
213
+ }
183
214
  async scanTemplateRoutes() {
184
215
  if (!fileSystem.exists(this.pagesDir)) {
185
216
  return [];
@@ -190,11 +221,11 @@ export class RouteRegistry {
190
221
  const templateRoutes = [];
191
222
  const routesByKey = new Map();
192
223
  for await (const file of scannedFiles) {
193
- if (file.includes('.ecopages-node.')) {
224
+ const classified = this.classifyRouteFile(file);
225
+ if (!classified) {
194
226
  continue;
195
227
  }
196
- const endpointExtension = findEndpointFileExtension(file);
197
- const role = endpointExtension ? 'endpoint' : 'page';
228
+ const { role, endpointExtension } = classified;
198
229
  const routePathname = this.getRoutePath(file, endpointExtension);
199
230
  const filePath = path.join(this.pagesDir, file);
200
231
  const kind = this.classifyRouteKind(file);
@@ -214,7 +245,7 @@ export class RouteRegistry {
214
245
  const owner = role === 'page' && kind !== 'exact'
215
246
  ? findIntegrationForFile(this.appConfig.integrations, filePath)
216
247
  : undefined;
217
- invariant(owner?.acceptsParams !== false, `${filePath}: ${findLongestExtension(owner?.extensions ?? [], filePath)} Pages cannot receive Params, so they cannot use dynamic route segments. Rename the file, or use an eco.page() Page from an Integration that supports staticPaths.`);
248
+ invariant(owner?.acceptsParams !== false, `${filePath}: ${findLongestExtension(owner?.extensions ?? [], filePath)} Pages cannot receive Params, so they cannot use dynamic route segments. Rename the file, or use an eco.page() Page from an Integration that supports paths.`);
218
249
  templateRoutes.push({
219
250
  pathname: routePathname,
220
251
  kind,
@@ -2,6 +2,33 @@ import type { PageParams } from '../../types/contracts.js';
2
2
  export type SegmentPathSyntax = 'filesystem' | 'api' | 'explicit' | 'websocket';
3
3
  export type SegmentPathParams = PageParams;
4
4
  export type ParsedSegmentPath = readonly string[];
5
+ type PatternSegment = {
6
+ kind: 'literal';
7
+ value: string;
8
+ } | {
9
+ kind: 'parameter';
10
+ name: string;
11
+ } | {
12
+ kind: 'catch-all';
13
+ name: string;
14
+ } | {
15
+ kind: 'wildcard';
16
+ };
17
+ /** Joined catch-all values make `explicit` and `websocket` params plain strings. */
18
+ type MatchedParams<S extends SegmentPathSyntax> = S extends 'explicit' | 'websocket' ? Record<string, string> : SegmentPathParams;
19
+ /**
20
+ * A route pattern parsed once, with the specificity score that orders it against other patterns.
21
+ *
22
+ * @remarks
23
+ * Build one with {@link compileSegmentPattern} when the route is registered, so a request only compares
24
+ * path segments. The score is the `api` ordering for every syntax but `websocket`, which has its own.
25
+ */
26
+ export type SegmentPattern<S extends SegmentPathSyntax = SegmentPathSyntax> = {
27
+ readonly syntax: S;
28
+ readonly segments: readonly PatternSegment[];
29
+ readonly score: number;
30
+ };
31
+ export declare function compileSegmentPattern<S extends SegmentPathSyntax>(pattern: string, syntax: S): SegmentPattern<S>;
5
32
  /**
6
33
  * Normalizes and decodes a request pathname once for matching multiple routes.
7
34
  *
@@ -10,9 +37,7 @@ export type ParsedSegmentPath = readonly string[];
10
37
  * original segment. Malformed escapes throw an HTTP 400 {@link HttpError}.
11
38
  */
12
39
  export declare function parseSegmentPath(pathname: string): ParsedSegmentPath;
13
- export declare function matchParsedSegmentPath(pattern: string, pathSegments: ParsedSegmentPath, syntax: 'filesystem' | 'api'): SegmentPathParams | null;
14
- export declare function matchParsedSegmentPath(pattern: string, pathSegments: ParsedSegmentPath, syntax: 'explicit' | 'websocket'): Record<string, string> | null;
15
- export declare function matchParsedSegmentPath(pattern: string, pathSegments: ParsedSegmentPath, syntax: SegmentPathSyntax): SegmentPathParams | null;
40
+ export declare function matchParsedSegmentPath<S extends SegmentPathSyntax>(pattern: SegmentPattern<S>, pathSegments: ParsedSegmentPath): MatchedParams<S> | null;
16
41
  /**
17
42
  * Matches one route syntax against a pathname and returns its captured parameters.
18
43
  *
@@ -43,5 +68,4 @@ export declare function buildSegmentPath(pattern: string, params: SegmentPathPar
43
68
  * catch-all shares one with a wildcard, since both take every remaining segment.
44
69
  */
45
70
  export declare function segmentPathPatternKey(pattern: string, syntax: SegmentPathSyntax): string;
46
- export declare function scoreSegmentPathPattern(pattern: string, syntax: 'api'): number;
47
- export declare function scoreSegmentPathPattern(pattern: string, syntax: 'websocket'): number;
71
+ export {};
@@ -82,6 +82,24 @@ function parsePattern(pattern, syntax) {
82
82
  .filter(Boolean)
83
83
  .map((segment) => parsePatternSegment(segment, options));
84
84
  }
85
+ function scorePatternSegments(segments, syntax) {
86
+ if (syntax === 'websocket') {
87
+ const literals = segments.filter((segment) => segment.kind === 'literal').length;
88
+ const params = segments.length - literals;
89
+ return literals * 100 - params * 10 + segments.length;
90
+ }
91
+ return segments.reduce((score, segment) => {
92
+ if (segment.kind === 'literal')
93
+ return score + 100;
94
+ if (segment.kind === 'parameter')
95
+ return score + 50;
96
+ return score + 10;
97
+ }, 0);
98
+ }
99
+ export function compileSegmentPattern(pattern, syntax) {
100
+ const segments = parsePattern(pattern, syntax);
101
+ return { syntax, segments, score: scorePatternSegments(segments, syntax) };
102
+ }
85
103
  /**
86
104
  * Normalizes and decodes a request pathname once for matching multiple routes.
87
105
  *
@@ -102,10 +120,10 @@ export function parseSegmentPath(pathname) {
102
120
  }
103
121
  });
104
122
  }
105
- export function matchParsedSegmentPath(pattern, pathSegments, syntax) {
106
- const patternSegments = parsePattern(pattern, syntax);
123
+ export function matchParsedSegmentPath(pattern, pathSegments) {
124
+ const patternSegments = pattern.segments;
107
125
  const params = {};
108
- const { catchAllValue } = syntaxOptions[syntax];
126
+ const { catchAllValue } = syntaxOptions[pattern.syntax];
109
127
  for (const [index, patternSegment] of patternSegments.entries()) {
110
128
  if (patternSegment.kind === 'wildcard') {
111
129
  return params;
@@ -130,7 +148,7 @@ export function matchParsedSegmentPath(pattern, pathSegments, syntax) {
130
148
  return pathSegments.length === patternSegments.length ? params : null;
131
149
  }
132
150
  export function matchSegmentPath(pattern, pathname, syntax) {
133
- return matchParsedSegmentPath(pattern, parseSegmentPath(pathname), syntax);
151
+ return matchParsedSegmentPath(compileSegmentPattern(pattern, syntax), parseSegmentPath(pathname));
134
152
  }
135
153
  /**
136
154
  * Builds a concrete pathname from a route pattern and its params.
@@ -177,18 +195,3 @@ export function segmentPathPatternKey(pattern, syntax) {
177
195
  });
178
196
  return `/${segments.join('/')}`;
179
197
  }
180
- export function scoreSegmentPathPattern(pattern, syntax) {
181
- const segments = parsePattern(pattern, syntax);
182
- if (syntax === 'websocket') {
183
- const literals = segments.filter((segment) => segment.kind === 'literal').length;
184
- const params = segments.length - literals;
185
- return literals * 100 - params * 10 + segments.length;
186
- }
187
- return segments.reduce((score, segment) => {
188
- if (segment.kind === 'literal')
189
- return score + 100;
190
- if (segment.kind === 'parameter')
191
- return score + 50;
192
- return score + 10;
193
- }, 0);
194
- }
@@ -19,7 +19,7 @@ export declare function shouldPrebuildProductionPageBrowserGraphs(): boolean;
19
19
  * file a previous build wrote. Development session records are left intact.
20
20
  */
21
21
  export declare function clearProductionPageBrowserGraphSession(appConfig: EcoPagesAppConfig): void;
22
- /** Identifies one planned route instance: its file, Params and whether it is a template without static props. */
22
+ /** Identifies one planned route instance: its file, Params and whether it is a template without a `props` run. */
23
23
  export declare function getPlannedRouteKey(instance: PlannedRouteInstance): string;
24
24
  /**
25
25
  * Builds the production browser client for the supplied route instances and prepares each of them.
@@ -32,7 +32,7 @@ export declare function getPlannedRouteKey(instance: PlannedRouteInstance): stri
32
32
  * worker restores it during the export. A route that fails to plan is left out and reported to `onRouteFailure`.
33
33
  * Each Integration's global scripts are resolved once, after that build, or on their own when no route is planned.
34
34
  *
35
- * Returns the preparation of every planned instance that runs its static props, by {@link getPlannedRouteKey}, so
35
+ * Returns the preparation of every planned instance that runs its `props` hook, by {@link getPlannedRouteKey}, so
36
36
  * static export renders it without running its data hooks again. The caller owns the map for the build; no
37
37
  * renderer keeps it.
38
38
  */
@@ -29,17 +29,17 @@ export function shouldPrebuildProductionPageBrowserGraphs() {
29
29
  export function clearProductionPageBrowserGraphSession(appConfig) {
30
30
  const runtime = requireAppRuntime(appConfig);
31
31
  runtime.pageBrowserGraphSession.clearPolicyRecords('production');
32
- runtime.processedAssets.clearBrowserOutputs();
32
+ runtime.processedAssets.clearBuildOutputs();
33
33
  clearProductionAssetLedger(appConfig);
34
34
  }
35
- /** Identifies one planned route instance: its file, Params and whether it is a template without static props. */
35
+ /** Identifies one planned route instance: its file, Params and whether it is a template without a `props` run. */
36
36
  export function getPlannedRouteKey(instance) {
37
37
  const routeFile = path.resolve(instance.routeFile);
38
38
  const dependencyInstanceKey = createPageDependencyInstanceKey({ params: instance.params });
39
39
  return JSON.stringify([
40
40
  routeFile,
41
41
  dependencyInstanceKey,
42
- instance.skipStaticProps ?? false,
42
+ instance.skipPropsHook ?? false,
43
43
  instance.isRouteTemplate ?? false,
44
44
  ]);
45
45
  }
@@ -64,7 +64,7 @@ function groupRouteInstancesByRenderer(routeInstances, routeRendererFactory) {
64
64
  * worker restores it during the export. A route that fails to plan is left out and reported to `onRouteFailure`.
65
65
  * Each Integration's global scripts are resolved once, after that build, or on their own when no route is planned.
66
66
  *
67
- * Returns the preparation of every planned instance that runs its static props, by {@link getPlannedRouteKey}, so
67
+ * Returns the preparation of every planned instance that runs its `props` hook, by {@link getPlannedRouteKey}, so
68
68
  * static export renders it without running its data hooks again. The caller owns the map for the build; no
69
69
  * renderer keeps it.
70
70
  */
@@ -95,7 +95,7 @@ export async function prebuildProductionPageBrowserGraphs(appConfig, routeInstan
95
95
  }
96
96
  writeProductionAssetLedger(appConfig, await getPrebuiltHtmlPageModuleScriptUrls(appConfig));
97
97
  for (const { instance, preparation } of routePlans.flatMap((routePlan) => routePlan.preparations)) {
98
- if (!instance.skipStaticProps)
98
+ if (!instance.skipPropsHook)
99
99
  preparations.set(getPlannedRouteKey(instance), preparation);
100
100
  }
101
101
  return preparations;
@@ -31,7 +31,7 @@ export declare const STATIC_SITE_GENERATOR_ERRORS: {
31
31
  readonly unsupportedBodyType: (bodyType: string) => string;
32
32
  readonly missingIntegration: (routePath: string) => string;
33
33
  readonly noRendererForIntegration: (integrationName: string) => string;
34
- readonly dynamicRouteRequiresStaticPaths: (routePath: string) => string;
34
+ readonly dynamicRouteRequiresPaths: (routePath: string) => string;
35
35
  };
36
36
  /**
37
37
  * Generates static output files from the finalized app config and route graph.
@@ -91,6 +91,13 @@ export declare class StaticSiteGenerator {
91
91
  routePlans?: StaticExportRoutePlans;
92
92
  }): Promise<void>;
93
93
  private createStaticExportContext;
94
+ /**
95
+ * Starts every Integration's static export.
96
+ *
97
+ * @remarks
98
+ * The caller runs this concurrently with planning and the browser-graph prebuild and awaits it before the
99
+ * first page render, the earliest point an export's output (the Lit render worker) is consumed.
100
+ */
94
101
  private startStaticExports;
95
102
  private releaseStaticExports;
96
103
  private resetStaticGenerationState;
@@ -131,6 +138,15 @@ export declare class StaticSiteGenerator {
131
138
  force?: boolean;
132
139
  keepGoing?: boolean;
133
140
  }): Promise<void>;
141
+ /**
142
+ * Releases the static exports, tears down the Integrations, and throws whatever failed.
143
+ *
144
+ * @remarks
145
+ * Static exports start while the generation runs, so they are awaited here even when generation failed; their
146
+ * own failure is reported only when it is not the error generation already threw. Every cleanup step runs,
147
+ * and a generation error is thrown together with any cleanup errors.
148
+ */
149
+ private cleanUpStaticGeneration;
134
150
  /**
135
151
  * Loads each explicit static view, resolves its renderer and lists its pathnames.
136
152
  *