@ecopages/core 0.2.0-rc.0 → 0.2.0-rc.10

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 (184) hide show
  1. package/README.md +52 -33
  2. package/package.json +58 -4
  3. package/src/adapters/README.md +3 -1
  4. package/src/adapters/abstract/application-adapter.d.ts +28 -6
  5. package/src/adapters/abstract/application-adapter.js +58 -5
  6. package/src/adapters/abstract/segment-path-matcher.js +56 -38
  7. package/src/adapters/abstract/server-adapter.d.ts +14 -0
  8. package/src/adapters/abstract/server-adapter.js +10 -0
  9. package/src/adapters/bun/create-app.d.ts +10 -6
  10. package/src/adapters/bun/create-app.js +64 -37
  11. package/src/adapters/bun/server-adapter.d.ts +6 -2
  12. package/src/adapters/bun/server-adapter.js +14 -1
  13. package/src/adapters/create-app.d.ts +62 -7
  14. package/src/adapters/create-app.js +61 -5
  15. package/src/adapters/node/create-app.d.ts +5 -5
  16. package/src/adapters/node/create-app.js +18 -5
  17. package/src/adapters/node/runtime-host.js +9 -4
  18. package/src/adapters/node/server-adapter.d.ts +5 -1
  19. package/src/adapters/node/server-adapter.js +16 -1
  20. package/src/adapters/shared/http/define-api-handler.d.ts +7 -49
  21. package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
  22. package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -8
  23. package/src/adapters/shared/http/fs-server-response-factory.js +5 -30
  24. package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
  25. package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
  26. package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
  27. package/src/adapters/shared/runtime/application-adapter.js +12 -0
  28. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
  29. package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
  30. package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
  31. package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
  32. package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
  33. package/src/adapters/shared/runtime/port-manager.js +14 -45
  34. package/src/adapters/shared/runtime/server-adapter.d.ts +14 -5
  35. package/src/adapters/shared/runtime/server-adapter.js +22 -30
  36. package/src/adapters/shared/runtime/server-route-handler.js +11 -3
  37. package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
  38. package/src/adapters/shared/runtime/server-static-builder.js +59 -37
  39. package/src/build/README.md +5 -1
  40. package/src/build/cache/server-entry-build-cache.d.ts +24 -1
  41. package/src/build/cache/server-entry-build-cache.js +125 -8
  42. package/src/build/contracts/content-virtual-modules.d.ts +3 -1
  43. package/src/build/contracts/content-virtual-modules.js +8 -0
  44. package/src/build/rolldown/rolldown-adapter-helpers.js +56 -31
  45. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  46. package/src/build/rolldown/runtime-build-output-normalizer.js +3 -29
  47. package/src/build/runtime/build-request-policy.js +1 -1
  48. package/src/build/server-bundle-publication.d.ts +14 -0
  49. package/src/build/server-bundle-publication.js +49 -0
  50. package/src/config/README.md +17 -2
  51. package/src/config/apply-user-config.d.ts +6 -0
  52. package/src/config/apply-user-config.js +67 -0
  53. package/src/config/config-builder.d.ts +10 -1
  54. package/src/config/config-builder.js +51 -10
  55. package/src/config/constants.d.ts +4 -0
  56. package/src/config/constants.js +4 -0
  57. package/src/config/define-config.d.ts +9 -0
  58. package/src/config/define-config.js +10 -0
  59. package/src/config/index.d.ts +5 -0
  60. package/src/config/index.js +4 -0
  61. package/src/config/is-finalized-app-config.d.ts +6 -0
  62. package/src/config/is-finalized-app-config.js +11 -0
  63. package/src/config/load-eco-config.d.ts +21 -0
  64. package/src/config/load-eco-config.js +100 -0
  65. package/src/config/resolve-eco-config-path.d.ts +23 -0
  66. package/src/config/resolve-eco-config-path.js +47 -0
  67. package/src/config/server-config-bundle.d.ts +25 -0
  68. package/src/config/server-config-bundle.js +148 -0
  69. package/src/config/user-config-types.d.ts +164 -0
  70. package/src/config/user-config-types.js +1 -0
  71. package/src/css-imports.d.ts +4 -0
  72. package/src/declarations.d.ts +11 -5
  73. package/src/dev/README.md +6 -0
  74. package/src/dev/development-restart-watch-paths.d.ts +13 -0
  75. package/src/dev/development-restart-watch-paths.js +37 -0
  76. package/src/dev/development-restart.d.ts +13 -0
  77. package/src/dev/development-restart.js +21 -0
  78. package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
  79. package/src/dev/transform-server/dev-transform-server.js +16 -5
  80. package/src/eco/README.md +73 -5
  81. package/src/eco/component-identity.d.ts +3 -2
  82. package/src/eco/component-identity.js +5 -2
  83. package/src/eco/discovered-dependencies.d.ts +45 -0
  84. package/src/eco/discovered-dependencies.js +87 -0
  85. package/src/eco/eco.js +6 -0
  86. package/src/eco/eco.types.d.ts +18 -2
  87. package/src/eco/lazy-injector-map.js +57 -41
  88. package/src/eco/page-dependency-contributions.d.ts +19 -0
  89. package/src/eco/page-dependency-contributions.js +52 -0
  90. package/src/errors/http-error-page-contract.d.ts +77 -0
  91. package/src/errors/http-error-page-contract.js +106 -0
  92. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  93. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  94. package/src/index.browser.d.ts +3 -0
  95. package/src/index.browser.js +3 -0
  96. package/src/index.d.ts +4 -1
  97. package/src/index.js +4 -1
  98. package/src/islands/README.md +5 -1
  99. package/src/plugins/README.md +10 -2
  100. package/src/plugins/component-import-discovery.d.ts +19 -0
  101. package/src/plugins/component-import-discovery.js +241 -0
  102. package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
  103. package/src/plugins/eco-component-meta-plugin.js +118 -16
  104. package/src/plugins/integration-plugin.d.ts +4 -9
  105. package/src/plugins/processor.d.ts +23 -2
  106. package/src/plugins/processor.js +25 -0
  107. package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
  108. package/src/plugins/tsconfig-import-resolver.js +4 -2
  109. package/src/route-renderer/GRAPH.md +1 -1
  110. package/src/route-renderer/README.md +16 -3
  111. package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
  112. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  113. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  114. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  115. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
  116. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
  117. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
  118. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
  119. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  120. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  121. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
  122. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
  123. package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +13 -1
  124. package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +15 -0
  125. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
  126. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
  127. package/src/route-renderer/orchestration/integration-renderer.d.ts +11 -5
  128. package/src/route-renderer/orchestration/integration-renderer.js +42 -29
  129. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
  130. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
  131. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  132. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  133. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  134. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
  135. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
  136. package/src/route-renderer/orchestration/string-markup-renderer.js +10 -8
  137. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
  138. package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
  139. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  140. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
  141. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
  142. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  143. package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
  144. package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
  145. package/src/route-renderer/route-renderer.d.ts +9 -0
  146. package/src/route-renderer/route-renderer.js +18 -0
  147. package/src/router/README.md +7 -1
  148. package/src/router/server/route-registry.d.ts +13 -0
  149. package/src/router/server/route-registry.js +46 -32
  150. package/src/services/README.md +5 -0
  151. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
  152. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
  153. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
  154. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
  155. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  156. package/src/services/error-pages/README.md +9 -0
  157. package/src/services/error-pages/default-error-pages.d.ts +44 -0
  158. package/src/services/error-pages/default-error-pages.js +207 -0
  159. package/src/services/error-pages/error-page-renderer.d.ts +58 -0
  160. package/src/services/error-pages/error-page-renderer.js +146 -0
  161. package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
  162. package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
  163. package/src/services/invalidation/development-invalidation.service.d.ts +7 -1
  164. package/src/services/invalidation/development-invalidation.service.js +35 -3
  165. package/src/services/module-loading/README.md +16 -13
  166. package/src/services/module-loading/app-server-module-transpiler.service.js +2 -0
  167. package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -0
  168. package/src/services/module-loading/collection-server-module-build.service.js +5 -2
  169. package/src/services/module-loading/page-module-import.service.d.ts +8 -0
  170. package/src/services/module-loading/page-module-import.service.js +62 -28
  171. package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
  172. package/src/services/module-loading/view-module-loader.d.ts +10 -0
  173. package/src/services/module-loading/view-module-loader.js +46 -0
  174. package/src/services/validation/schema-validation-service.d.ts +1 -0
  175. package/src/services/validation/schema-validation-service.js +23 -36
  176. package/src/static-site-generator/README.md +6 -1
  177. package/src/static-site-generator/static-site-generator.d.ts +7 -2
  178. package/src/static-site-generator/static-site-generator.js +90 -49
  179. package/src/types/internal-types.d.ts +6 -1
  180. package/src/types/public-types.d.ts +34 -24
  181. package/src/utils/parse-cli-args.js +29 -22
  182. package/src/watchers/project-watcher.d.ts +14 -1
  183. package/src/watchers/project-watcher.js +85 -34
  184. /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
@@ -0,0 +1,6 @@
1
+ import { ConfigBuilder } from './config-builder.js';
2
+ import type { EcoPagesUserConfig } from './user-config-types.js';
3
+ /**
4
+ * Applies author-owned config fields onto a {@link ConfigBuilder} instance.
5
+ */
6
+ export declare function applyUserConfigToBuilder(builder: ConfigBuilder, userConfig: EcoPagesUserConfig): ConfigBuilder;
@@ -0,0 +1,67 @@
1
+ import { ConfigBuilder } from './config-builder.js';
2
+ function applyUserDirectoryConfig(builder, userConfig) {
3
+ if (userConfig.srcDir)
4
+ builder.setSrcDir(userConfig.srcDir);
5
+ if (userConfig.pagesDir)
6
+ builder.setPagesDir(userConfig.pagesDir);
7
+ if (userConfig.includesDir)
8
+ builder.setIncludesDir(userConfig.includesDir);
9
+ if (userConfig.componentsDir)
10
+ builder.setComponentsDir(userConfig.componentsDir);
11
+ if (userConfig.layoutsDir)
12
+ builder.setLayoutsDir(userConfig.layoutsDir);
13
+ if (userConfig.publicDir)
14
+ builder.setPublicDir(userConfig.publicDir);
15
+ if (userConfig.distDir)
16
+ builder.setDistDir(userConfig.distDir);
17
+ if (userConfig.workDir)
18
+ builder.setWorkDir(userConfig.workDir);
19
+ }
20
+ function applyUserPipelineConfig(builder, userConfig) {
21
+ if (userConfig.integrations)
22
+ builder.setIntegrations(userConfig.integrations);
23
+ if (userConfig.processors)
24
+ builder.setProcessors(userConfig.processors);
25
+ if (userConfig.loaders)
26
+ builder.setLoaders(userConfig.loaders);
27
+ if (userConfig.sourceTransforms)
28
+ builder.setSourceTransforms(userConfig.sourceTransforms);
29
+ if (userConfig.cache)
30
+ builder.setCacheConfig(userConfig.cache);
31
+ if (userConfig.buildOwnership)
32
+ builder.setBuildOwnership(userConfig.buildOwnership);
33
+ }
34
+ function applyUserMetadataConfig(builder, userConfig) {
35
+ if (userConfig.baseUrl !== undefined)
36
+ builder.setBaseUrl(userConfig.baseUrl);
37
+ if (userConfig.robotsTxt)
38
+ builder.setRobotsTxt(userConfig.robotsTxt);
39
+ if (userConfig.sitemap)
40
+ builder.setSitemap(userConfig.sitemap);
41
+ if (userConfig.defaultMetadata)
42
+ builder.setDefaultMetadata(userConfig.defaultMetadata);
43
+ }
44
+ function applyUserRuntimeConfig(builder, userConfig) {
45
+ if (userConfig.devToolbar)
46
+ builder.setDevToolbar(userConfig.devToolbar);
47
+ if (userConfig.additionalWatchPaths)
48
+ builder.setAdditionalWatchPaths(userConfig.additionalWatchPaths);
49
+ if (userConfig.devPrewarmPaths)
50
+ builder.setDevPrewarmPaths(userConfig.devPrewarmPaths);
51
+ if (userConfig.devPrewarmBeforeReadyPaths) {
52
+ builder.setDevPrewarmBeforeReadyPaths(userConfig.devPrewarmBeforeReadyPaths);
53
+ }
54
+ if (userConfig.experimental)
55
+ builder.setExperimental(userConfig.experimental);
56
+ }
57
+ /**
58
+ * Applies author-owned config fields onto a {@link ConfigBuilder} instance.
59
+ */
60
+ export function applyUserConfigToBuilder(builder, userConfig) {
61
+ builder.setRootDir(userConfig.rootDir);
62
+ applyUserDirectoryConfig(builder, userConfig);
63
+ applyUserPipelineConfig(builder, userConfig);
64
+ applyUserMetadataConfig(builder, userConfig);
65
+ applyUserRuntimeConfig(builder, userConfig);
66
+ return builder;
67
+ }
@@ -16,7 +16,7 @@ export declare const CONFIG_BUILDER_ERRORS: {
16
16
  readonly MIXED_JSX_ENGINES: "Both kitajs and react integrations are enabled. Use per-file JSX import source/pragma consistently (e.g. `/** @jsxImportSource react */` for React files and `/** @jsxImportSource @kitajs/html */` for Kita files).";
17
17
  readonly duplicateProcessorName: (name: string) => string;
18
18
  readonly duplicateLoaderName: (name: string) => string;
19
- readonly duplicateSemanticTemplate: (kind: "html" | "404" | "500", matches: string[]) => string;
19
+ readonly duplicateSemanticTemplate: (kind: string, matches: string[]) => string;
20
20
  readonly incompatibleRuntimeCapability: (kind: "integration" | "processor", name: string, runtime: RuntimeKind, reason: string) => string;
21
21
  readonly unsupportedRuntimeVersion: (kind: "integration" | "processor", name: string, runtime: RuntimeKind, current: string, min: string) => string;
22
22
  readonly invalidRuntimeVersion: (kind: "integration" | "processor", name: string, version: string) => string;
@@ -45,6 +45,7 @@ type RuntimeKind = 'node' | 'bun';
45
45
  */
46
46
  export declare class ConfigBuilder {
47
47
  private buildOwnership;
48
+ private configModulePath?;
48
49
  config: EcoPagesAppConfig;
49
50
  /**
50
51
  * Sets the base URL for the application.
@@ -80,6 +81,14 @@ export declare class ConfigBuilder {
80
81
  * without an explicit ownership.
81
82
  */
82
83
  setBuildOwnership(buildOwnership: BuildOwnership): this;
84
+ /**
85
+ * Sets the canonical path of the Ecopages config module on disk.
86
+ *
87
+ * @remarks
88
+ * Used by the config loader so {@link EcoPagesAppConfig.absolutePaths.config}
89
+ * reflects `--config` overrides and production-emitted config modules.
90
+ */
91
+ setConfigModulePath(configModulePath: string): this;
83
92
  /**
84
93
  * Sets the source directory relative to the root directory.
85
94
  * This directory contains all the source files for the application.
@@ -45,6 +45,7 @@ export const CONFIG_BUILDER_ERRORS = {
45
45
  */
46
46
  export class ConfigBuilder {
47
47
  buildOwnership = 'rolldown';
48
+ configModulePath;
48
49
  config = {
49
50
  baseUrl: '',
50
51
  rootDir: '.',
@@ -88,6 +89,14 @@ export class ConfigBuilder {
88
89
  publicDir: '',
89
90
  srcDir: '',
90
91
  htmlTemplatePath: '',
92
+ errorPageTemplatePaths: {
93
+ 400: '',
94
+ 401: '',
95
+ 403: '',
96
+ 404: '',
97
+ 409: '',
98
+ 500: '',
99
+ },
91
100
  error404TemplatePath: '',
92
101
  error500TemplatePath: '',
93
102
  },
@@ -139,6 +148,17 @@ export class ConfigBuilder {
139
148
  this.buildOwnership = buildOwnership;
140
149
  return this;
141
150
  }
151
+ /**
152
+ * Sets the canonical path of the Ecopages config module on disk.
153
+ *
154
+ * @remarks
155
+ * Used by the config loader so {@link EcoPagesAppConfig.absolutePaths.config}
156
+ * reflects `--config` overrides and production-emitted config modules.
157
+ */
158
+ setConfigModulePath(configModulePath) {
159
+ this.configModulePath = configModulePath;
160
+ return this;
161
+ }
142
162
  /**
143
163
  * Sets the source directory relative to the root directory.
144
164
  * This directory contains all the source files for the application.
@@ -437,8 +457,34 @@ export class ConfigBuilder {
437
457
  const absoluteWorkDir = path.resolve(projectDir, workDir);
438
458
  const absoluteIncludesDir = path.join(absoluteSrcDir, includesDir);
439
459
  const absolutePagesDir = path.join(absoluteSrcDir, pagesDir);
460
+ const errorPageTemplatePaths = {
461
+ 400: this.resolveSemanticTemplatePath({
462
+ dirPath: absolutePagesDir,
463
+ basename: '400',
464
+ }),
465
+ 401: this.resolveSemanticTemplatePath({
466
+ dirPath: absolutePagesDir,
467
+ basename: '401',
468
+ }),
469
+ 403: this.resolveSemanticTemplatePath({
470
+ dirPath: absolutePagesDir,
471
+ basename: '403',
472
+ }),
473
+ 404: this.resolveSemanticTemplatePath({
474
+ dirPath: absolutePagesDir,
475
+ basename: '404',
476
+ }),
477
+ 409: this.resolveSemanticTemplatePath({
478
+ dirPath: absolutePagesDir,
479
+ basename: '409',
480
+ }),
481
+ 500: this.resolveSemanticTemplatePath({
482
+ dirPath: absolutePagesDir,
483
+ basename: '500',
484
+ }),
485
+ };
440
486
  this.config.absolutePaths = {
441
- config: path.join(projectDir, 'eco.config.ts'),
487
+ config: this.configModulePath ?? path.join(projectDir, 'eco.config.ts'),
442
488
  projectDir: projectDir,
443
489
  srcDir: absoluteSrcDir,
444
490
  distDir: absoluteDistDir,
@@ -452,18 +498,13 @@ export class ConfigBuilder {
452
498
  dirPath: absoluteIncludesDir,
453
499
  basename: 'html',
454
500
  }),
455
- error404TemplatePath: this.resolveSemanticTemplatePath({
456
- dirPath: absolutePagesDir,
457
- basename: '404',
458
- }),
459
- error500TemplatePath: this.resolveSemanticTemplatePath({
460
- dirPath: absolutePagesDir,
461
- basename: '500',
462
- }),
501
+ errorPageTemplatePaths,
502
+ error404TemplatePath: errorPageTemplatePaths[404],
503
+ error500TemplatePath: errorPageTemplatePaths[500],
463
504
  };
464
505
  return this;
465
506
  }
466
- resolveSemanticTemplatePath({ dirPath, basename, }) {
507
+ resolveSemanticTemplatePath({ dirPath, basename }) {
467
508
  const extensions = this.config.templatesExt;
468
509
  if (extensions.length === 0) {
469
510
  return '';
@@ -6,7 +6,11 @@
6
6
  * Collection of status messages used in the application.
7
7
  */
8
8
  export declare const STATUS_MESSAGE: {
9
+ 400: string;
10
+ 401: string;
11
+ 403: string;
9
12
  404: string;
13
+ 409: string;
10
14
  500: string;
11
15
  };
12
16
  /**
@@ -6,7 +6,11 @@
6
6
  * Collection of status messages used in the application.
7
7
  */
8
8
  export const STATUS_MESSAGE = {
9
+ 400: 'Bad Request',
10
+ 401: 'Unauthorized',
11
+ 403: 'Forbidden',
9
12
  404: '404 Not Found',
13
+ 409: 'Conflict',
10
14
  500: 'Internal Server Error',
11
15
  };
12
16
  /**
@@ -0,0 +1,9 @@
1
+ import type { EcoPagesUserConfig } from './user-config-types.js';
2
+ /**
3
+ * Type helper for `eco.config.ts` authoring.
4
+ *
5
+ * @remarks
6
+ * Synchronous identity only. Loading and finalization happen through
7
+ * {@link loadEcoPagesConfig} or {@link createApp}.
8
+ */
9
+ export declare function defineConfig(config: EcoPagesUserConfig): EcoPagesUserConfig;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Type helper for `eco.config.ts` authoring.
3
+ *
4
+ * @remarks
5
+ * Synchronous identity only. Loading and finalization happen through
6
+ * {@link loadEcoPagesConfig} or {@link createApp}.
7
+ */
8
+ export function defineConfig(config) {
9
+ return config;
10
+ }
@@ -0,0 +1,5 @@
1
+ export { defineConfig } from './define-config.js';
2
+ export { loadEcoPagesConfig, loadEcoPagesUserConfig, finalizeEcoPagesConfig } from './load-eco-config.js';
3
+ export { resolveEcoConfigPath, resolveEmittedEcoConfigPath, DEFAULT_ECO_CONFIG_FILENAME, ECOPAGES_CONFIG_FILE_ENV, } from './resolve-eco-config-path.js';
4
+ export { assertProductionConfigIdentity } from '../build/cache/server-entry-build-cache.js';
5
+ export type { EcoPagesUserConfig, LoadedEcoPagesUserConfig, FinalizeEcoPagesConfigOptions, LoadEcoPagesConfigOptions, } from './user-config-types.js';
@@ -0,0 +1,4 @@
1
+ export { defineConfig } from './define-config.js';
2
+ export { loadEcoPagesConfig, loadEcoPagesUserConfig, finalizeEcoPagesConfig } from './load-eco-config.js';
3
+ export { resolveEcoConfigPath, resolveEmittedEcoConfigPath, DEFAULT_ECO_CONFIG_FILENAME, ECOPAGES_CONFIG_FILE_ENV, } from './resolve-eco-config-path.js';
4
+ export { assertProductionConfigIdentity } from '../build/cache/server-entry-build-cache.js';
@@ -0,0 +1,6 @@
1
+ import type { EcoPagesAppConfig } from '../types/internal-types.js';
2
+ /**
3
+ * @remarks
4
+ * Finalized configs use Maps for processors/loaders; user configs use arrays.
5
+ */
6
+ export declare function isFinalizedEcoPagesAppConfig(value: unknown): value is EcoPagesAppConfig;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @remarks
3
+ * Finalized configs use Maps for processors/loaders; user configs use arrays.
4
+ */
5
+ export function isFinalizedEcoPagesAppConfig(value) {
6
+ if (!value || typeof value !== 'object') {
7
+ return false;
8
+ }
9
+ const config = value;
10
+ return config.processors instanceof Map && Array.isArray(config.templatesExt);
11
+ }
@@ -0,0 +1,21 @@
1
+ import type { EcoPagesAppConfig } from '../types/internal-types.js';
2
+ import type { FinalizeEcoPagesConfigOptions, LoadEcoPagesConfigOptions, LoadedEcoPagesUserConfig } from './user-config-types.js';
3
+ /**
4
+ * Loads the user-owned config object from the resolved config module.
5
+ */
6
+ export declare function loadEcoPagesUserConfig(options?: LoadEcoPagesConfigOptions): Promise<LoadedEcoPagesUserConfig>;
7
+ /**
8
+ * Finalizes a loaded user config through {@link ConfigBuilder.build}.
9
+ */
10
+ export declare function finalizeEcoPagesConfig(loaded: LoadedEcoPagesUserConfig, options?: FinalizeEcoPagesConfigOptions): Promise<EcoPagesAppConfig>;
11
+ /**
12
+ * Loads and finalizes the Ecopages config for the current project.
13
+ *
14
+ * @remarks
15
+ * Coalesces concurrent loads and caches by `configFilePath` and `buildOwnership`.
16
+ * Files that still export a finalized {@link ConfigBuilder.build} result are returned as-is
17
+ * so workers and tests can load existing `eco.config.ts` modules.
18
+ */
19
+ export declare function loadEcoPagesConfig(options?: LoadEcoPagesConfigOptions): Promise<EcoPagesAppConfig>;
20
+ /** @internal */
21
+ export declare function clearEcoPagesConfigCachesForTests(): void;
@@ -0,0 +1,100 @@
1
+ import { pathToFileURL } from 'node:url';
2
+ import { applyUserConfigToBuilder } from './apply-user-config.js';
3
+ import { ConfigBuilder } from './config-builder.js';
4
+ import { isFinalizedEcoPagesAppConfig } from './is-finalized-app-config.js';
5
+ import { resolveEcoConfigPath } from './resolve-eco-config-path.js';
6
+ const moduleLoadCache = new Map();
7
+ const appConfigCache = new Map();
8
+ function createCacheKey(configFilePath, buildOwnership) {
9
+ const ownership = buildOwnership ?? 'rolldown';
10
+ return `${configFilePath}::${ownership}`;
11
+ }
12
+ async function importEcoConfigModule(configFilePath) {
13
+ const moduleUrl = pathToFileURL(configFilePath).href;
14
+ const configModule = await import(moduleUrl);
15
+ return configModule.default ?? configModule;
16
+ }
17
+ function loadConfigModule(configFilePath) {
18
+ const cached = moduleLoadCache.get(configFilePath);
19
+ if (cached) {
20
+ return cached;
21
+ }
22
+ const loadPromise = (async () => {
23
+ const exported = await importEcoConfigModule(configFilePath);
24
+ if (isFinalizedEcoPagesAppConfig(exported)) {
25
+ return { kind: 'finalized', appConfig: exported, configFilePath };
26
+ }
27
+ if (!exported || typeof exported !== 'object') {
28
+ throw new Error(`Ecopages config at ${configFilePath} must default-export an object from defineConfig(...).`);
29
+ }
30
+ const userConfig = exported;
31
+ if (typeof userConfig.rootDir !== 'string' || userConfig.rootDir.length === 0) {
32
+ throw new Error(`Ecopages config at ${configFilePath} must include a non-empty rootDir.`);
33
+ }
34
+ return { kind: 'user', userConfig, configFilePath };
35
+ })();
36
+ moduleLoadCache.set(configFilePath, loadPromise);
37
+ return loadPromise.catch((error) => {
38
+ moduleLoadCache.delete(configFilePath);
39
+ throw error;
40
+ });
41
+ }
42
+ /**
43
+ * Loads the user-owned config object from the resolved config module.
44
+ */
45
+ export async function loadEcoPagesUserConfig(options = {}) {
46
+ const configFilePath = resolveEcoConfigPath(options);
47
+ const loaded = await loadConfigModule(configFilePath);
48
+ if (loaded.kind === 'finalized') {
49
+ throw new Error(`Ecopages config at ${configFilePath} exported a finalized app config. Use defineConfig(...) and let createApp() finalize the config.`);
50
+ }
51
+ return {
52
+ config: loaded.userConfig,
53
+ configFilePath,
54
+ };
55
+ }
56
+ /**
57
+ * Finalizes a loaded user config through {@link ConfigBuilder.build}.
58
+ */
59
+ export async function finalizeEcoPagesConfig(loaded, options = {}) {
60
+ const buildOwnership = options.buildOwnership ?? loaded.config.buildOwnership ?? 'rolldown';
61
+ const builder = new ConfigBuilder();
62
+ applyUserConfigToBuilder(builder, loaded.config);
63
+ builder.setBuildOwnership(buildOwnership);
64
+ builder.setConfigModulePath(loaded.configFilePath);
65
+ return await builder.build();
66
+ }
67
+ /**
68
+ * Loads and finalizes the Ecopages config for the current project.
69
+ *
70
+ * @remarks
71
+ * Coalesces concurrent loads and caches by `configFilePath` and `buildOwnership`.
72
+ * Files that still export a finalized {@link ConfigBuilder.build} result are returned as-is
73
+ * so workers and tests can load existing `eco.config.ts` modules.
74
+ */
75
+ export async function loadEcoPagesConfig(options = {}) {
76
+ const configFilePath = resolveEcoConfigPath(options);
77
+ const buildOwnership = options.buildOwnership ?? 'rolldown';
78
+ const cacheKey = createCacheKey(configFilePath, buildOwnership);
79
+ const cached = appConfigCache.get(cacheKey);
80
+ if (cached) {
81
+ return cached;
82
+ }
83
+ const loadPromise = (async () => {
84
+ const loaded = await loadConfigModule(configFilePath);
85
+ if (loaded.kind === 'finalized') {
86
+ return loaded.appConfig;
87
+ }
88
+ return await finalizeEcoPagesConfig({ config: loaded.userConfig, configFilePath }, { buildOwnership: options.buildOwnership });
89
+ })();
90
+ appConfigCache.set(cacheKey, loadPromise);
91
+ return loadPromise.catch((error) => {
92
+ appConfigCache.delete(cacheKey);
93
+ throw error;
94
+ });
95
+ }
96
+ /** @internal */
97
+ export function clearEcoPagesConfigCachesForTests() {
98
+ moduleLoadCache.clear();
99
+ appConfigCache.clear();
100
+ }
@@ -0,0 +1,23 @@
1
+ export declare const DEFAULT_ECO_CONFIG_FILENAME = "eco.config.ts";
2
+ export declare const ECOPAGES_CONFIG_FILE_ENV = "ECOPAGES_CONFIG_FILE";
3
+ export type ResolveEcoConfigPathOptions = {
4
+ configFile?: string;
5
+ cwd?: string;
6
+ required?: boolean;
7
+ /** Prefer the emitted production config over the source config when both exist. */
8
+ preferEmitted?: boolean;
9
+ };
10
+ /** Resolves the emitted production config without consulting source overrides. */
11
+ export declare function resolveEmittedEcoConfigPath(cwd?: string): string | undefined;
12
+ /**
13
+ * Resolves the canonical absolute path to the Ecopages config module.
14
+ *
15
+ * @remarks
16
+ * Precedence: explicit `configFile`, then `ECOPAGES_CONFIG_FILE`, then
17
+ * `<cwd>/eco.config.ts`, then the emitted production config. When `preferEmitted`
18
+ * is enabled, the emitted config precedes the source config.
19
+ */
20
+ export declare function resolveEcoConfigPath(options: ResolveEcoConfigPathOptions & {
21
+ required: false;
22
+ }): string | undefined;
23
+ export declare function resolveEcoConfigPath(options?: ResolveEcoConfigPathOptions): string;
@@ -0,0 +1,47 @@
1
+ import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
+ import { SERVER_BUNDLE_DIR } from '../utils/resolve-entry-file.js';
4
+ import { EMITTED_ECO_CONFIG_FILENAME } from './server-config-bundle.js';
5
+ export const DEFAULT_ECO_CONFIG_FILENAME = 'eco.config.ts';
6
+ export const ECOPAGES_CONFIG_FILE_ENV = 'ECOPAGES_CONFIG_FILE';
7
+ /** Resolves the emitted production config without consulting source overrides. */
8
+ export function resolveEmittedEcoConfigPath(cwd = process.cwd()) {
9
+ const candidates = [
10
+ path.resolve(cwd, 'dist', SERVER_BUNDLE_DIR, EMITTED_ECO_CONFIG_FILENAME),
11
+ path.resolve(cwd, SERVER_BUNDLE_DIR, EMITTED_ECO_CONFIG_FILENAME),
12
+ ];
13
+ return candidates.find((candidate) => fileSystem.exists(candidate));
14
+ }
15
+ export function resolveEcoConfigPath(options = {}) {
16
+ const cwd = options.cwd ?? process.cwd();
17
+ const required = options.required ?? true;
18
+ if (options.configFile) {
19
+ const resolved = path.isAbsolute(options.configFile)
20
+ ? options.configFile
21
+ : path.resolve(cwd, options.configFile);
22
+ if (!fileSystem.exists(resolved)) {
23
+ throw new Error(`Ecopages config file not found: ${resolved}`);
24
+ }
25
+ return resolved;
26
+ }
27
+ const envPath = process.env[ECOPAGES_CONFIG_FILE_ENV];
28
+ if (envPath) {
29
+ const resolved = path.isAbsolute(envPath) ? envPath : path.resolve(cwd, envPath);
30
+ if (!fileSystem.exists(resolved)) {
31
+ throw new Error(`Ecopages config file not found: ${resolved}`);
32
+ }
33
+ return resolved;
34
+ }
35
+ const defaultPath = path.resolve(cwd, DEFAULT_ECO_CONFIG_FILENAME);
36
+ const emittedConfigPath = resolveEmittedEcoConfigPath(cwd);
37
+ if (options.preferEmitted && emittedConfigPath)
38
+ return emittedConfigPath;
39
+ if (fileSystem.exists(defaultPath))
40
+ return defaultPath;
41
+ if (emittedConfigPath)
42
+ return emittedConfigPath;
43
+ if (!required) {
44
+ return undefined;
45
+ }
46
+ throw new Error(`Ecopages config file not found: ${defaultPath}`);
47
+ }
@@ -0,0 +1,25 @@
1
+ import type { BuildResult } from '../build/contracts/build-contracts.js';
2
+ import type { EcoSourceTransform } from '../plugins/source-transform.js';
3
+ import type { EcoPagesAppConfig } from '../types/internal-types.js';
4
+ export declare const EMITTED_ECO_CONFIG_FILENAME = "eco.config.mjs";
5
+ export interface BundleEcoConfigModuleResult {
6
+ emittedConfigPath: string;
7
+ buildResult: BuildResult;
8
+ }
9
+ /**
10
+ * Creates a source transform that preserves source module directory semantics
11
+ * when `eco.config.ts` is relocated into `dist/.server/eco.config.mjs`.
12
+ */
13
+ export declare function createPreserveImportMetaTransform(serverOutdir: string): EcoSourceTransform;
14
+ /**
15
+ * Compiles the selected Ecopages config module for production server startup.
16
+ */
17
+ export declare function bundleEcoConfigModule(appConfig: EcoPagesAppConfig, options?: {
18
+ outputDir?: string;
19
+ runtimeDir?: string;
20
+ }): Promise<BundleEcoConfigModuleResult | undefined>;
21
+ /**
22
+ * @remarks
23
+ * Ensures build ownership allows app-owned bundling before emitting config artifacts.
24
+ */
25
+ export declare function assertCanBundleServerConfig(appConfig: EcoPagesAppConfig): void;
@@ -0,0 +1,148 @@
1
+ import path from 'node:path';
2
+ import { fileSystem } from '@ecopages/file-system';
3
+ import { build, getAppBuildAdapter } from '../build/build-adapter.js';
4
+ import { cachedParseSync } from '../cache/module-parse-cache.js';
5
+ import { createServerBuildRequest } from '../build/runtime/build-request-policy.js';
6
+ import { requireBuildRuntime } from '../build/runtime/build-runtime.js';
7
+ import { getServerBundleOutputPaths } from '../build/cache/server-entry-build-cache.js';
8
+ export const EMITTED_ECO_CONFIG_FILENAME = 'eco.config.mjs';
9
+ function isAstNode(value) {
10
+ return typeof value === 'object' && value !== null;
11
+ }
12
+ function walkAst(value, visit) {
13
+ if (Array.isArray(value)) {
14
+ for (const child of value)
15
+ walkAst(child, visit);
16
+ return;
17
+ }
18
+ if (!isAstNode(value))
19
+ return;
20
+ visit(value);
21
+ for (const child of Object.values(value))
22
+ walkAst(child, visit);
23
+ }
24
+ function isImportMeta(node) {
25
+ if (!isAstNode(node) || node.type !== 'MetaProperty')
26
+ return false;
27
+ return (isAstNode(node.meta) &&
28
+ node.meta.type === 'Identifier' &&
29
+ node.meta.name === 'import' &&
30
+ isAstNode(node.property) &&
31
+ node.property.type === 'Identifier' &&
32
+ node.property.name === 'meta');
33
+ }
34
+ function collectImportMetaEdits(code, id, serverOutdir) {
35
+ const program = cachedParseSync(id, code, { sourceType: 'module' }).program;
36
+ const fileDir = path.dirname(id);
37
+ const relativeDir = path.relative(serverOutdir, fileDir).replaceAll('\\', '/');
38
+ const relativeFile = relativeDir ? `${relativeDir}/${path.basename(id)}` : `./${path.basename(id)}`;
39
+ const edits = [];
40
+ let needsNodePath = false;
41
+ const identifiers = new Set();
42
+ walkAst(program, (node) => {
43
+ if (node.type === 'Identifier' && typeof node.name === 'string')
44
+ identifiers.add(node.name);
45
+ });
46
+ let pathBinding = '__ecoConfigPath';
47
+ while (identifiers.has(pathBinding))
48
+ pathBinding = `_${pathBinding}`;
49
+ walkAst(program, (node) => {
50
+ if (node.type !== 'MemberExpression' && node.type !== 'StaticMemberExpression')
51
+ return;
52
+ if (!isImportMeta(node.object) || !isAstNode(node.property) || node.property.type !== 'Identifier')
53
+ return;
54
+ if (typeof node.start !== 'number' || typeof node.end !== 'number')
55
+ return;
56
+ if (node.property.name === 'dirname' || node.property.name === 'dir') {
57
+ needsNodePath = true;
58
+ edits.push({
59
+ start: node.start,
60
+ end: node.end,
61
+ replacement: `${pathBinding}.resolve(import.meta.dirname, ${JSON.stringify(relativeDir || '.')})`,
62
+ });
63
+ return;
64
+ }
65
+ if (node.property.name === 'url') {
66
+ edits.push({
67
+ start: node.start,
68
+ end: node.end,
69
+ replacement: `new URL(${JSON.stringify(relativeFile)}, import.meta.url).href`,
70
+ });
71
+ }
72
+ });
73
+ return { edits, needsNodePath, pathBinding };
74
+ }
75
+ function applySourceEdits(code, edits) {
76
+ let transformed = code;
77
+ for (const edit of edits.sort((left, right) => right.start - left.start)) {
78
+ transformed = `${transformed.slice(0, edit.start)}${edit.replacement}${transformed.slice(edit.end)}`;
79
+ }
80
+ return transformed;
81
+ }
82
+ /**
83
+ * Creates a source transform that preserves source module directory semantics
84
+ * when `eco.config.ts` is relocated into `dist/.server/eco.config.mjs`.
85
+ */
86
+ export function createPreserveImportMetaTransform(serverOutdir) {
87
+ return {
88
+ name: 'preserve-import-meta-for-server-config',
89
+ filter: /\.[cm]?[jt]sx?$/,
90
+ transform(code, id) {
91
+ if (!code.includes('import.meta')) {
92
+ return undefined;
93
+ }
94
+ const { edits, needsNodePath, pathBinding } = collectImportMetaEdits(code, id, serverOutdir);
95
+ if (edits.length === 0)
96
+ return undefined;
97
+ const transformed = applySourceEdits(code, edits);
98
+ return {
99
+ code: needsNodePath ? `import * as ${pathBinding} from 'node:path';\n${transformed}` : transformed,
100
+ };
101
+ },
102
+ };
103
+ }
104
+ /**
105
+ * Compiles the selected Ecopages config module for production server startup.
106
+ */
107
+ export async function bundleEcoConfigModule(appConfig, options = {}) {
108
+ const configSourcePath = appConfig.absolutePaths?.config;
109
+ if (!configSourcePath || !fileSystem.exists(configSourcePath)) {
110
+ return undefined;
111
+ }
112
+ const { serverOutdir } = getServerBundleOutputPaths(appConfig);
113
+ const outputDir = options.outputDir ?? serverOutdir;
114
+ const runtimeDir = options.runtimeDir ?? serverOutdir;
115
+ const emittedConfigPath = path.join(outputDir, EMITTED_ECO_CONFIG_FILENAME);
116
+ fileSystem.ensureDir(outputDir);
117
+ const buildOptions = createServerBuildRequest(appConfig, {
118
+ profile: 'server-entry',
119
+ entrypoints: [configSourcePath],
120
+ outdir: outputDir,
121
+ naming: EMITTED_ECO_CONFIG_FILENAME,
122
+ sourcemap: 'hidden',
123
+ sourceTransforms: [createPreserveImportMetaTransform(runtimeDir)],
124
+ });
125
+ const result = await build(buildOptions, requireBuildRuntime(appConfig).getProfile('server-entry'));
126
+ if (!result.success) {
127
+ const errorMessages = result.logs.map((log) => log.message).join('\n');
128
+ throw new Error(`Failed to bundle Ecopages config module:\n${errorMessages}`);
129
+ }
130
+ if (!fileSystem.exists(emittedConfigPath)) {
131
+ throw new Error(`Ecopages config bundle missing at ${emittedConfigPath}`);
132
+ }
133
+ return {
134
+ emittedConfigPath,
135
+ buildResult: result,
136
+ };
137
+ }
138
+ /**
139
+ * @remarks
140
+ * Ensures build ownership allows app-owned bundling before emitting config artifacts.
141
+ */
142
+ export function assertCanBundleServerConfig(appConfig) {
143
+ const buildAdapter = getAppBuildAdapter(appConfig);
144
+ if (buildAdapter.ownership === 'vite-host') {
145
+ throw new Error('Cannot bundle the server config: build ownership is "vite-host". ' +
146
+ 'The host runtime is expected to produce its own server bundle.');
147
+ }
148
+ }