@ecopages/core 0.2.0-rc.1 → 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 (179) hide show
  1. package/README.md +50 -32
  2. package/package.json +50 -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 +8 -4
  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/explicit-static-route-matcher.js +5 -2
  21. package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -8
  22. package/src/adapters/shared/http/fs-server-response-factory.js +5 -30
  23. package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
  24. package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
  25. package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
  26. package/src/adapters/shared/runtime/application-adapter.js +12 -0
  27. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
  28. package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
  29. package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
  30. package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
  31. package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
  32. package/src/adapters/shared/runtime/port-manager.js +14 -45
  33. package/src/adapters/shared/runtime/server-adapter.d.ts +14 -5
  34. package/src/adapters/shared/runtime/server-adapter.js +22 -30
  35. package/src/adapters/shared/runtime/server-route-handler.js +11 -3
  36. package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
  37. package/src/adapters/shared/runtime/server-static-builder.js +59 -37
  38. package/src/build/README.md +4 -0
  39. package/src/build/cache/server-entry-build-cache.d.ts +24 -1
  40. package/src/build/cache/server-entry-build-cache.js +125 -8
  41. package/src/build/contracts/content-virtual-modules.d.ts +3 -1
  42. package/src/build/contracts/content-virtual-modules.js +8 -0
  43. package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
  44. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  45. package/src/build/runtime/build-request-policy.js +1 -1
  46. package/src/build/server-bundle-publication.d.ts +14 -0
  47. package/src/build/server-bundle-publication.js +49 -0
  48. package/src/config/README.md +17 -2
  49. package/src/config/apply-user-config.d.ts +6 -0
  50. package/src/config/apply-user-config.js +67 -0
  51. package/src/config/config-builder.d.ts +10 -1
  52. package/src/config/config-builder.js +51 -10
  53. package/src/config/constants.d.ts +4 -0
  54. package/src/config/constants.js +4 -0
  55. package/src/config/define-config.d.ts +9 -0
  56. package/src/config/define-config.js +10 -0
  57. package/src/config/index.d.ts +5 -0
  58. package/src/config/index.js +4 -0
  59. package/src/config/is-finalized-app-config.d.ts +6 -0
  60. package/src/config/is-finalized-app-config.js +11 -0
  61. package/src/config/load-eco-config.d.ts +21 -0
  62. package/src/config/load-eco-config.js +100 -0
  63. package/src/config/resolve-eco-config-path.d.ts +23 -0
  64. package/src/config/resolve-eco-config-path.js +47 -0
  65. package/src/config/server-config-bundle.d.ts +25 -0
  66. package/src/config/server-config-bundle.js +148 -0
  67. package/src/config/user-config-types.d.ts +164 -0
  68. package/src/config/user-config-types.js +1 -0
  69. package/src/css-imports.d.ts +4 -0
  70. package/src/declarations.d.ts +11 -5
  71. package/src/dev/README.md +6 -0
  72. package/src/dev/development-restart-watch-paths.d.ts +13 -0
  73. package/src/dev/development-restart-watch-paths.js +37 -0
  74. package/src/dev/development-restart.d.ts +13 -0
  75. package/src/dev/development-restart.js +21 -0
  76. package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
  77. package/src/dev/transform-server/dev-transform-server.js +16 -5
  78. package/src/eco/README.md +73 -5
  79. package/src/eco/component-identity.d.ts +3 -2
  80. package/src/eco/component-identity.js +5 -2
  81. package/src/eco/discovered-dependencies.d.ts +45 -0
  82. package/src/eco/discovered-dependencies.js +87 -0
  83. package/src/eco/eco.js +6 -0
  84. package/src/eco/eco.types.d.ts +18 -2
  85. package/src/eco/lazy-injector-map.js +57 -41
  86. package/src/eco/page-dependency-contributions.d.ts +19 -0
  87. package/src/eco/page-dependency-contributions.js +52 -0
  88. package/src/errors/http-error-page-contract.d.ts +77 -0
  89. package/src/errors/http-error-page-contract.js +106 -0
  90. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  91. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  92. package/src/index.browser.d.ts +3 -0
  93. package/src/index.browser.js +3 -0
  94. package/src/index.d.ts +4 -1
  95. package/src/index.js +4 -1
  96. package/src/islands/README.md +5 -1
  97. package/src/plugins/README.md +8 -1
  98. package/src/plugins/component-import-discovery.d.ts +19 -0
  99. package/src/plugins/component-import-discovery.js +241 -0
  100. package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
  101. package/src/plugins/eco-component-meta-plugin.js +118 -16
  102. package/src/plugins/processor.d.ts +10 -2
  103. package/src/plugins/processor.js +4 -0
  104. package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
  105. package/src/plugins/tsconfig-import-resolver.js +4 -2
  106. package/src/route-renderer/GRAPH.md +1 -1
  107. package/src/route-renderer/README.md +15 -2
  108. package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
  109. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  110. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  111. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  112. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +80 -0
  113. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
  114. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
  115. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -0
  116. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  117. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  118. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
  119. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
  120. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
  121. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
  122. package/src/route-renderer/orchestration/integration-renderer.d.ts +9 -5
  123. package/src/route-renderer/orchestration/integration-renderer.js +42 -29
  124. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
  125. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
  126. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  127. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  128. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  129. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +8 -10
  130. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
  131. package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
  132. package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
  133. package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
  134. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  135. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
  136. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
  137. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  138. package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
  139. package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
  140. package/src/route-renderer/route-renderer.d.ts +9 -0
  141. package/src/route-renderer/route-renderer.js +18 -0
  142. package/src/router/README.md +7 -1
  143. package/src/router/server/route-registry.d.ts +13 -0
  144. package/src/router/server/route-registry.js +46 -32
  145. package/src/services/README.md +5 -0
  146. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
  147. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
  148. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
  149. package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
  150. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  151. package/src/services/error-pages/README.md +9 -0
  152. package/src/services/error-pages/default-error-pages.d.ts +44 -0
  153. package/src/services/error-pages/default-error-pages.js +207 -0
  154. package/src/services/error-pages/error-page-renderer.d.ts +58 -0
  155. package/src/services/error-pages/error-page-renderer.js +146 -0
  156. package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
  157. package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
  158. package/src/services/invalidation/development-invalidation.service.d.ts +7 -1
  159. package/src/services/invalidation/development-invalidation.service.js +35 -3
  160. package/src/services/module-loading/README.md +16 -13
  161. package/src/services/module-loading/app-server-module-transpiler.service.js +2 -0
  162. package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -0
  163. package/src/services/module-loading/collection-server-module-build.service.js +5 -2
  164. package/src/services/module-loading/page-module-import.service.d.ts +8 -0
  165. package/src/services/module-loading/page-module-import.service.js +62 -28
  166. package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
  167. package/src/services/module-loading/view-module-loader.d.ts +10 -0
  168. package/src/services/module-loading/view-module-loader.js +46 -0
  169. package/src/services/validation/schema-validation-service.d.ts +1 -0
  170. package/src/services/validation/schema-validation-service.js +23 -36
  171. package/src/static-site-generator/README.md +6 -1
  172. package/src/static-site-generator/static-site-generator.d.ts +7 -2
  173. package/src/static-site-generator/static-site-generator.js +90 -49
  174. package/src/types/internal-types.d.ts +6 -1
  175. package/src/types/public-types.d.ts +32 -22
  176. package/src/utils/parse-cli-args.js +29 -22
  177. package/src/watchers/project-watcher.d.ts +14 -1
  178. package/src/watchers/project-watcher.js +85 -34
  179. /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
@@ -0,0 +1,164 @@
1
+ import type { BuildOwnership } from '../build/build-adapter.js';
2
+ import type { EcoBuildPlugin } from '../build/contracts/build-types.js';
3
+ import type { AnyIntegrationPlugin } from '../plugins/integration-plugin.js';
4
+ import type { AnyProcessor } from '../plugins/processor.js';
5
+ import type { EcoSourceTransform } from '../plugins/source-transform.js';
6
+ import type { CacheConfig } from '../services/cache/cache.types.js';
7
+ import type { EcoPagesAppConfig, RobotsPreference } from '../types/internal-types.js';
8
+ import type { PageMetadataProps, SitemapConfig } from '../types/public-types.js';
9
+ /**
10
+ * Author-owned Ecopages configuration declared in `eco.config.ts`.
11
+ *
12
+ * @remarks
13
+ * Author this object using `defineConfig({ ... })` in `eco.config.ts`.
14
+ * This type excludes resolved absolute paths, derived integration extensions, and runtime
15
+ * services attached during {@link ConfigBuilder.build}.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { defineConfig } from '@ecopages/core/config';
20
+ * import { ecopagesJsxPlugin } from '@ecopages/ecopages-jsx';
21
+ *
22
+ * export default defineConfig({
23
+ * rootDir: import.meta.dirname,
24
+ * baseUrl: process.env.ECOPAGES_BASE_URL ?? 'http://localhost:3000',
25
+ * integrations: [ecopagesJsxPlugin()],
26
+ * });
27
+ * ```
28
+ */
29
+ export type EcoPagesUserConfig = {
30
+ /**
31
+ * Absolute or relative path to the project root directory.
32
+ */
33
+ rootDir: string;
34
+ /**
35
+ * Canonical base URL for production deployment (e.g. `https://example.com`).
36
+ *
37
+ * @default 'http://localhost:3000'
38
+ */
39
+ baseUrl?: string;
40
+ /**
41
+ * Directory containing application source code, relative to `rootDir`.
42
+ *
43
+ * @default 'src'
44
+ */
45
+ srcDir?: string;
46
+ /**
47
+ * Directory for static public assets copied directly to `distDir`, relative to `rootDir`.
48
+ *
49
+ * @default 'public'
50
+ */
51
+ publicDir?: string;
52
+ /**
53
+ * Directory containing page route files and semantic HTML error pages (`400.ts` through `500.ts`), relative to `srcDir`.
54
+ *
55
+ * @default 'pages'
56
+ */
57
+ pagesDir?: string;
58
+ /**
59
+ * Directory containing reusable includes or the semantic `html.*` document shell, relative to `srcDir`.
60
+ *
61
+ * @default 'includes'
62
+ */
63
+ includesDir?: string;
64
+ /**
65
+ * Directory containing layout components, relative to `srcDir`.
66
+ *
67
+ * @default 'layouts'
68
+ */
69
+ layoutsDir?: string;
70
+ /**
71
+ * Output directory for the production build, relative to `rootDir`.
72
+ *
73
+ * @default 'dist'
74
+ */
75
+ distDir?: string;
76
+ /**
77
+ * Internal scratch and cache directory for build artifacts and virtual modules, relative to `rootDir`.
78
+ *
79
+ * @default '.eco'
80
+ */
81
+ workDir?: string;
82
+ /**
83
+ * Directory containing island and client components, relative to `srcDir`.
84
+ *
85
+ * @default 'components'
86
+ */
87
+ componentsDir?: string;
88
+ /**
89
+ * Configuration for automatic `robots.txt` generation.
90
+ */
91
+ robotsTxt?: {
92
+ preferences: RobotsPreference;
93
+ };
94
+ /**
95
+ * Configuration for automatic `sitemap.xml` generation.
96
+ */
97
+ sitemap?: SitemapConfig;
98
+ /**
99
+ * Additional file or directory paths to watch during development.
100
+ */
101
+ additionalWatchPaths?: string[];
102
+ /**
103
+ * URL route paths to prewarm in the background when the development server starts.
104
+ */
105
+ devPrewarmPaths?: string[];
106
+ /**
107
+ * URL route paths that must complete prewarming before the dev server reports ready.
108
+ */
109
+ devPrewarmBeforeReadyPaths?: string[];
110
+ /**
111
+ * Default fallback HTML `<head>` metadata (title, description, OpenGraph tags) applied across all pages.
112
+ */
113
+ defaultMetadata?: PageMetadataProps;
114
+ /**
115
+ * Integration plugins enabling template rendering (e.g. JSX, MDX, Lit, React).
116
+ */
117
+ integrations?: AnyIntegrationPlugin[];
118
+ /**
119
+ * PostCSS, Tailwind, or custom asset processors applied to imported styles and assets.
120
+ */
121
+ processors?: AnyProcessor[];
122
+ /**
123
+ * Custom Rolldown/Vite build loaders and asset transforms.
124
+ */
125
+ loaders?: EcoBuildPlugin[];
126
+ /**
127
+ * AST transforms applied to source files before compilation (e.g. island script extraction).
128
+ */
129
+ sourceTransforms?: EcoSourceTransform[];
130
+ /**
131
+ * Cache policy configuration for page and asset build outputs.
132
+ */
133
+ cache?: CacheConfig;
134
+ /**
135
+ * Development toolbar configuration and toggle options.
136
+ */
137
+ devToolbar?: EcoPagesAppConfig['devToolbar'];
138
+ /**
139
+ * Experimental runtime or compiler feature flags.
140
+ */
141
+ experimental?: EcoPagesAppConfig['experimental'];
142
+ /**
143
+ * Build pipeline ownership mode.
144
+ *
145
+ * @default 'rolldown'
146
+ *
147
+ * @remarks
148
+ * Set to `'vite-host'` when running inside Vite (`@ecopages/vite-plugin`), where Vite
149
+ * owns client and server module transforms.
150
+ */
151
+ buildOwnership?: BuildOwnership;
152
+ };
153
+ export type LoadedEcoPagesUserConfig = {
154
+ config: EcoPagesUserConfig;
155
+ configFilePath: string;
156
+ };
157
+ export type FinalizeEcoPagesConfigOptions = {
158
+ buildOwnership?: BuildOwnership;
159
+ };
160
+ export type LoadEcoPagesConfigOptions = {
161
+ configFile?: string;
162
+ cwd?: string;
163
+ buildOwnership?: BuildOwnership;
164
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ declare module '*.css' {
2
+ const styles: string;
3
+ export default styles;
4
+ }
@@ -1,9 +1,17 @@
1
+ import './css-imports.d.js';
2
+
1
3
  import type { EcoPagesAppConfig } from './types/internal-types';
2
4
  import type { EcoNavigationRuntime } from './router/client/navigation-coordinator';
3
5
 
4
6
  type HMRHandler = (url: string) => Promise<void>;
5
7
  type CleanupPageRootFunction = () => void;
6
8
  type EcoPageRoot = { render: (node: unknown) => void; unmount: () => void };
9
+ type EcoIslandComponent = (props: Record<string, unknown>) => unknown;
10
+ /** Shared React island diagnostics and root lookup state exposed to devtools. */
11
+ type EcoIslandRuntime = {
12
+ islandRoots: Record<string, EcoPageRoot>;
13
+ islandComponents: Record<string, EcoIslandComponent>;
14
+ };
7
15
  type EcoPageData = {
8
16
  module: string;
9
17
  props: Record<string, unknown>;
@@ -15,7 +23,10 @@ type EcoPagesWindowRuntime = {
15
23
  cleanupPageRoot?: CleanupPageRootFunction;
16
24
  pageRoot?: EcoPageRoot | null;
17
25
  };
26
+ /** Roots keyed by SSR instance ID; component keys are never used for lookup. */
18
27
  islandRoots?: Record<string, EcoPageRoot>;
28
+ islandComponents?: Record<string, EcoIslandComponent>;
29
+ __ecoIslandRuntime?: EcoIslandRuntime;
19
30
  page?: EcoPageData;
20
31
  };
21
32
 
@@ -25,8 +36,3 @@ declare global {
25
36
  __ECO_PAGES__?: EcoPagesWindowRuntime;
26
37
  }
27
38
  }
28
-
29
- declare module '*.css' {
30
- const styles: string;
31
- export default styles;
32
- }
package/src/dev/README.md CHANGED
@@ -22,3 +22,9 @@ Install the client package in the app project. Core resolves it from the applica
22
22
  Disable per project with `devToolbar: { enabled: false }`, or per process with `ECOPAGES_DEV_TOOLBAR=false`.
23
23
 
24
24
  Server wiring: [dev-toolbar/README.md](../dev-toolbar/README.md) (`DevToolbarHost`, manifest, runtime bundling, HTML injection). Bring-your-own toolbars export `src/bootstrap.ts` and use the same `devToolbar.package` config key.
25
+
26
+ Dev transform requests retry when their source changes or is invalidated during compilation. Concurrent requests share one in-flight compile per source, including across source and global invalidation; stale attempts release their slot before retrying. Only results for the current source snapshot enter the module cache, so rapid edits cannot label stale browser code with a newer source hash.
27
+
28
+ ## Process restarts
29
+
30
+ The Project Watcher classifies the resolved `eco.config` module and supported project dotenv paths separately from HMR. Under the CLI, those changes request a graceful runtime stop and a supervised child-process restart so config modules and environment values are loaded from scratch. Embedded hosts are warned without core terminating their process. Runtime entry watchers own config-module changes when `dev:watch` is active, while the Project Watcher continues to own dotenv changes.
@@ -0,0 +1,13 @@
1
+ import type { EcoPagesAppConfig } from '../types/internal-types.js';
2
+ /** Returns whether `filePath` is a supported project-level dotenv file. */
3
+ export declare function isDevEnvFilePath(filePath: string, rootDir?: string, nodeEnv?: string | undefined): boolean;
4
+ /**
5
+ * Absolute paths to project-level dotenv files under `rootDir`.
6
+ *
7
+ * @remarks
8
+ * The paths need not exist yet. Watching every supported name allows creating
9
+ * or removing a dotenv file to restart the development process too.
10
+ */
11
+ export declare function resolveDevEnvFilePaths(rootDir?: string, nodeEnv?: string | undefined): string[];
12
+ /** Absolute paths that should restart the development server when changed. */
13
+ export declare function resolveRuntimeRestartWatchPaths(appConfig: EcoPagesAppConfig): string[];
@@ -0,0 +1,37 @@
1
+ import path from 'node:path';
2
+ import { getDevEnvFileNames } from './development-restart.js';
3
+ /** Returns whether `filePath` is a supported project-level dotenv file. */
4
+ export function isDevEnvFilePath(filePath, rootDir, nodeEnv = process.env.NODE_ENV) {
5
+ if (!rootDir) {
6
+ return false;
7
+ }
8
+ const resolvedPath = path.resolve(filePath);
9
+ if (path.dirname(resolvedPath) !== path.resolve(rootDir)) {
10
+ return false;
11
+ }
12
+ return getDevEnvFileNames(nodeEnv).includes(path.basename(resolvedPath));
13
+ }
14
+ /**
15
+ * Absolute paths to project-level dotenv files under `rootDir`.
16
+ *
17
+ * @remarks
18
+ * The paths need not exist yet. Watching every supported name allows creating
19
+ * or removing a dotenv file to restart the development process too.
20
+ */
21
+ export function resolveDevEnvFilePaths(rootDir, nodeEnv = process.env.NODE_ENV) {
22
+ if (!rootDir) {
23
+ return [];
24
+ }
25
+ return getDevEnvFileNames(nodeEnv).map((envFile) => path.resolve(rootDir, envFile));
26
+ }
27
+ /** Absolute paths that should restart the development server when changed. */
28
+ export function resolveRuntimeRestartWatchPaths(appConfig) {
29
+ const paths = [];
30
+ if (appConfig.absolutePaths?.config) {
31
+ paths.push(appConfig.absolutePaths.config);
32
+ }
33
+ for (const envPath of resolveDevEnvFilePaths(appConfig.rootDir)) {
34
+ paths.push(envPath);
35
+ }
36
+ return paths;
37
+ }
@@ -0,0 +1,13 @@
1
+ /** Process exit code the CLI supervisor treats as a development restart request. */
2
+ export declare const ECOPAGES_DEV_RESTART_EXIT_CODE = 100;
3
+ /** Env var carrying a short restart reason for the next child process startup log. */
4
+ export declare const ECOPAGES_DEV_RESTART_REASON_ENV = "ECOPAGES_DEV_RESTART_REASON";
5
+ /**
6
+ * When set, the CLI entry watcher (`bun --watch` or `node --watch`) owns hard restarts;
7
+ * core skips a second config-file exit for the same change.
8
+ */
9
+ export declare const ECOPAGES_ENTRY_WATCH_ENV = "ECOPAGES_ENTRY_WATCH";
10
+ /** Returns whether the runtime's entry watcher owns config-module restarts. */
11
+ export declare function entryWatcherOwnsConfig(env?: NodeJS.ProcessEnv): boolean;
12
+ /** Relative dotenv filenames loaded by the CLI, in precedence order. */
13
+ export declare function getDevEnvFileNames(nodeEnv?: string | undefined): string[];
@@ -0,0 +1,21 @@
1
+ /** Process exit code the CLI supervisor treats as a development restart request. */
2
+ export const ECOPAGES_DEV_RESTART_EXIT_CODE = 100;
3
+ /** Env var carrying a short restart reason for the next child process startup log. */
4
+ export const ECOPAGES_DEV_RESTART_REASON_ENV = 'ECOPAGES_DEV_RESTART_REASON';
5
+ /**
6
+ * When set, the CLI entry watcher (`bun --watch` or `node --watch`) owns hard restarts;
7
+ * core skips a second config-file exit for the same change.
8
+ */
9
+ export const ECOPAGES_ENTRY_WATCH_ENV = 'ECOPAGES_ENTRY_WATCH';
10
+ /** Returns whether the runtime's entry watcher owns config-module restarts. */
11
+ export function entryWatcherOwnsConfig(env = process.env) {
12
+ return env[ECOPAGES_ENTRY_WATCH_ENV] === '1';
13
+ }
14
+ /** Relative dotenv filenames loaded by the CLI, in precedence order. */
15
+ export function getDevEnvFileNames(nodeEnv = process.env.NODE_ENV) {
16
+ const envFiles = ['.env', '.env.local'];
17
+ if (nodeEnv) {
18
+ envFiles.push(`.env.${nodeEnv}`, `.env.${nodeEnv}.local`);
19
+ }
20
+ return envFiles;
21
+ }
@@ -24,6 +24,7 @@ export declare class DevTransformServer {
24
24
  private readonly cache;
25
25
  private readonly inFlight;
26
26
  private cacheGeneration;
27
+ private readonly sourceGenerations;
27
28
  constructor(options: DevTransformServerOptions);
28
29
  registerModule(sourcePath: string): string;
29
30
  getRegisteredSourcePath(moduleUrl: string): string | undefined;
@@ -31,6 +32,11 @@ export declare class DevTransformServer {
31
32
  private rebuildRuntimeSpecifierMap;
32
33
  private resolveVendorBundlePlugins;
33
34
  getWatchedModules(): ReadonlyMap<string, string>;
35
+ /**
36
+ * @remarks
37
+ * Marks pending work stale while preserving one in-flight compile per source.
38
+ * Requests awaiting that work retry against the current source when it completes.
39
+ */
34
40
  invalidateSource(sourcePath: string): void;
35
41
  invalidateAll(): void;
36
42
  reset(): void;
@@ -26,6 +26,7 @@ export class DevTransformServer {
26
26
  cache = new Map();
27
27
  inFlight = new Map();
28
28
  cacheGeneration = 0;
29
+ sourceGenerations = new Map();
29
30
  constructor(options) {
30
31
  this.appConfig = options.appConfig;
31
32
  this.onModuleDependencies = options.onModuleDependencies;
@@ -81,14 +82,20 @@ export class DevTransformServer {
81
82
  getWatchedModules() {
82
83
  return this.urlToSource;
83
84
  }
85
+ /**
86
+ * @remarks
87
+ * Marks pending work stale while preserving one in-flight compile per source.
88
+ * Requests awaiting that work retry against the current source when it completes.
89
+ */
84
90
  invalidateSource(sourcePath) {
85
91
  const normalized = path.resolve(sourcePath);
86
92
  this.cache.delete(normalized);
93
+ this.sourceGenerations.set(normalized, (this.sourceGenerations.get(normalized) ?? 0) + 1);
87
94
  }
88
95
  invalidateAll() {
89
96
  this.cacheGeneration += 1;
90
97
  this.cache.clear();
91
- this.inFlight.clear();
98
+ this.sourceGenerations.clear();
92
99
  this.vendorRegistry.invalidateAll();
93
100
  }
94
101
  reset() {
@@ -169,22 +176,26 @@ export class DevTransformServer {
169
176
  return entry;
170
177
  }
171
178
  const generation = this.cacheGeneration;
179
+ const sourceGeneration = this.sourceGenerations.get(normalized) ?? 0;
172
180
  const promise = this.bundler
173
181
  .transpileModule(normalized)
174
182
  .then((result) => {
175
- if (generation !== this.cacheGeneration) {
176
- throw new Error(`[dev-transform] Stale transpile result for ${normalized}`);
183
+ if (generation !== this.cacheGeneration ||
184
+ sourceGeneration !== (this.sourceGenerations.get(normalized) ?? 0) ||
185
+ fileSystem.hash(normalized) !== sourceHash) {
186
+ return undefined;
177
187
  }
178
188
  if (result.dependencies) {
179
189
  this.onModuleDependencies?.(normalized, result.dependencies);
180
190
  }
181
- const entry = { code: result.code, sourceHash: fileSystem.hash(normalized) };
191
+ const entry = { code: result.code, sourceHash };
182
192
  this.cache.set(normalized, entry);
183
193
  return entry;
184
194
  })
185
195
  .finally(() => {
186
196
  this.inFlight.delete(normalized);
187
- });
197
+ })
198
+ .then((entry) => entry ?? this.materialize(normalized));
188
199
  this.inFlight.set(normalized, promise);
189
200
  return promise;
190
201
  }
package/src/eco/README.md CHANGED
@@ -20,6 +20,59 @@ Layouts are assigned explicitly on each `eco.page({ layout })` call — either o
20
20
 
21
21
  EcoPages does **not** infer layouts from `src/layouts/` file paths or route segment directories. A file under `src/layouts/` is only used when a page imports it and passes it to `layout`.
22
22
 
23
+ ## Dependency discovery
24
+
25
+ Discovery is enabled by default for modules declaring `eco.component()`, `eco.layout()`, `eco.html()`, or `eco.page()`, as well as MDX documents compiled through `@ecopages/mdx/core`.
26
+
27
+ ```tsx
28
+ import { eco } from '@ecopages/core';
29
+ import { Counter } from './counter';
30
+ import './page.css';
31
+
32
+ export default eco.page({
33
+ render: () => <Counter />,
34
+ });
35
+ ```
36
+
37
+ Direct static named/default imports of local Eco Components contribute their Dependencies transitively. Configured TypeScript path aliases and relative imports are supported for both Components and CSS stylesheets (e.g., `import '@/components/button'` or `import '@/styles/main.css'`). Side-effect CSS imports become stylesheet Dependencies; the shared transform removes the imports so the existing asset pipeline owns delivery in server and browser builds. In MDX documents, top-level component and CSS imports are discovered while markdown code blocks and dynamic imports within functions are safely ignored.
38
+
39
+ Discovery is conservative and module-scoped: every Eco declaration in a file shares its imported Components and styles, even when a render condition omits a Component. It does not infer which Components actually render. **Best practice:** author **one `eco.component()` per file**. Co-locating multiple components in a single file will cause all declared components in that file to share discovered dependencies.
40
+
41
+ Imported Layouts contribute assets; only the explicit `layout` option controls Layout composition.
42
+
43
+ Explicit `dependencies` remain supported. Explicit Components come first, followed by discovered Components in import order, with duplicate Components removed. Explicit stylesheet declarations take precedence over discovered references to the same resolved file, preserving their attributes and order. Discovered stylesheets are **not** written into `config.dependencies.stylesheets`; they stay on Component identity until collection. Inferred styles follow explicit styles and are emitted once per collection. Circular dependency traversal is guarded by Component config identity, so two Components in one file remain distinct.
44
+
45
+ When a Page combines its own relative assets with a content entry, use `mergePageDependencies()`. Do not object-spread the two bags: spread copies `ownerFile` onto the other side's relative paths.
46
+
47
+ ```ts
48
+ import { eco, mergePageDependencies } from '@ecopages/core';
49
+ import { getEntryDependencies } from 'ecopages:content/posts/server';
50
+
51
+ export default eco.page({
52
+ dependencies: async ({ props }) =>
53
+ mergePageDependencies({ stylesheets: ['./post.css'] }, await getEntryDependencies(props.slug)),
54
+ render: () => <article />,
55
+ });
56
+ ```
57
+
58
+ Browser scripts remain explicit:
59
+
60
+ ```ts
61
+ scripts: [
62
+ {
63
+ src: './counter.script.ts',
64
+ ssr: true,
65
+ lazy: { 'on:visible': true },
66
+ },
67
+ ];
68
+ ```
69
+
70
+ For Lit and Ecopages JSX (Radiant hosts), `ssr: true` imports the script on the server before rendering so `customElements.define` runs without a separate value import in the component file. `lazy` controls browser delivery only; it does not suppress server import. To load eagerly in the browser, omit `lazy`. String-form `scripts: ['./file.ts']` stays browser-only unless you opt in with `{ src, ssr: true }`.
71
+
72
+ Scripts listening to client navigation events (`eco:after-swap`, `eco:page-load`) should be registered as client scripts (e.g., using `scripts: ['./component.script.ts']`) or guarded by `isServer` from `@ecopages/radiant/is-server` when used in Radiant projects where `document` is defined during SSR.
73
+
74
+ Named barrel re-exports (`export { Counter } from './counter'`) are followed for the imported binding only. Successful named re-export hops are watch paths, so retargeting a barrel updates page assets without editing the importing Page. Discovery does not follow `export * from './components'`, dynamic imports, namespace imports (`import * as`), package Components/CSS, CSS Modules, or custom import attributes. `export *` would pull an entire kit into the page asset graph; keep that explicit with `dependencies.components`. Plain-function modules retain their existing behavior. Ordinary utility imports do not become browser script entries. Missing supported imports report the owner file and import specifier.
75
+
23
76
  ## Component Patterns
24
77
 
25
78
  EcoPages supports two approaches for creating components, each suited for different use cases:
@@ -546,9 +599,6 @@ import { Counter } from '@/components/counter';
546
599
 
547
600
  export default eco.page({
548
601
  layout: BaseLayout,
549
- dependencies: {
550
- components: [Counter],
551
- },
552
602
  metadata: () => ({
553
603
  title: 'Home',
554
604
  description: 'Welcome to EcoPages',
@@ -562,6 +612,8 @@ export default eco.page({
562
612
  });
563
613
  ```
564
614
 
615
+ The static `Counter` import is discovered automatically. You do not list it again in `dependencies.components`. Lazy scripts stay on the Component.
616
+
565
617
  ## Type Definitions
566
618
 
567
619
  ```typescript
@@ -578,9 +630,25 @@ type DependencyEntry = {
578
630
  interface EcoComponentDependencies {
579
631
  scripts?: Array<string | DependencyEntry>;
580
632
  stylesheets?: Array<string | DependencyEntry>;
581
- components?: EcoComponent[];
633
+ modules?: string[];
634
+ /** Declared eco components only — see `EcoDeclaredComponent`. */
635
+ components?: EcoDeclaredComponent[];
582
636
  }
583
637
 
638
+ type FileOwnedDependencyContribution = EcoComponentDependencies & {
639
+ ownerFile?: string;
640
+ };
641
+
642
+ type PageDependenciesResult = FileOwnedDependencyContribution & {
643
+ contributions?: FileOwnedDependencyContribution[];
644
+ };
645
+
646
+ type GetPageDependencies<T> = (context: {
647
+ props: PagePropsFor<T>;
648
+ params?: Record<string, string>;
649
+ query?: Record<string, string>;
650
+ }) => PageDependenciesResult | undefined | Promise<PageDependenciesResult | undefined>;
651
+
584
652
  // Shared base option shape used by component(), html(), and layout()
585
653
  interface ComponentOptions<P, E = EcoPagesElement> {
586
654
  componentDir?: string;
@@ -595,7 +663,7 @@ type LayoutOptions<E = EcoPagesElement> = ComponentOptions<{ children: E }, E>;
595
663
 
596
664
  interface PageOptions<T, E = EcoPagesElement> {
597
665
  componentDir?: string;
598
- dependencies?: EcoComponentDependencies;
666
+ dependencies?: EcoComponentDependencies | GetPageDependencies<T>;
599
667
  layout?: EcoComponent<{ children: E }>;
600
668
  staticPaths?: GetStaticPaths;
601
669
  staticProps?: GetStaticProps<T>;
@@ -1,4 +1,5 @@
1
1
  import type { EcoComponent, EcoComponentConfig } from '../types/public-types.js';
2
+ import { type DiscoveredDependencies } from './discovered-dependencies.js';
2
3
  /** Stable attribution for a Component created by an Integration-owned module. */
3
4
  export type ComponentIdentity = {
4
5
  id: string;
@@ -7,7 +8,7 @@ export type ComponentIdentity = {
7
8
  };
8
9
  /** Gets canonical component attribution. */
9
10
  export declare function getComponentIdentity(value: EcoComponent | EcoComponentConfig | undefined): ComponentIdentity | undefined;
10
- /** Merges attribution into factory options. */
11
- export declare function bindComponentIdentity<T extends object>(identity: ComponentIdentity, options: T): T & {
11
+ /** Merges attribution into factory options. Optional discovered stylesheets stay keyed by identity. */
12
+ export declare function bindComponentIdentity<T extends object>(identity: ComponentIdentity, options: T, discovered?: DiscoveredDependencies): T & {
12
13
  identity: ComponentIdentity;
13
14
  };
@@ -1,3 +1,4 @@
1
+ import { registerDiscoveredDependencies } from './discovered-dependencies.js';
1
2
  function asConfig(value) {
2
3
  if (!value)
3
4
  return undefined;
@@ -12,7 +13,9 @@ export function getComponentIdentity(value) {
12
13
  const config = asConfig(value);
13
14
  return config?.identity;
14
15
  }
15
- /** Merges attribution into factory options. */
16
- export function bindComponentIdentity(identity, options) {
16
+ /** Merges attribution into factory options. Optional discovered stylesheets stay keyed by identity. */
17
+ export function bindComponentIdentity(identity, options, discovered) {
18
+ if (discovered)
19
+ registerDiscoveredDependencies(identity, discovered);
17
20
  return { ...options, identity };
18
21
  }
@@ -0,0 +1,45 @@
1
+ import type { EcoComponentConfig } from '../types/public-types.js';
2
+ import type { ComponentIdentity } from './component-identity.js';
3
+ export type DiscoveredDependencies = {
4
+ components: () => unknown[];
5
+ stylesheets: string[];
6
+ watchFiles?: string[];
7
+ };
8
+ /**
9
+ * Records discovered Components, inferred styles, and barrel watch hops on identity.
10
+ *
11
+ * @remarks
12
+ * Styles and watch hops are stored on the identity object through interned symbols so
13
+ * a bundled copy of this module still sees them during collection. The component getter
14
+ * stays on a same-isolate WeakMap and is attached to `config.dependencies` at factory time.
15
+ */
16
+ export declare function registerDiscoveredDependencies(identity: ComponentIdentity, discovered: DiscoveredDependencies): void;
17
+ /**
18
+ * Inferred stylesheet paths registered for this component identity.
19
+ *
20
+ * @remarks
21
+ * Provenance stays on identity so copying or merging `config.dependencies` cannot
22
+ * turn inferred styles into explicit ones. Paths are stored on the identity object
23
+ * so collection still sees them when server modules bundle a separate copy of `eco`.
24
+ * The collector prefers explicit entries across the whole graph by resolved path.
25
+ */
26
+ export declare function getInferredStylesheets(config: EcoComponentConfig | undefined): readonly string[];
27
+ /**
28
+ * Named re-export hops recorded for this component identity.
29
+ *
30
+ * @remarks
31
+ * Barrel files are not Component identity files. Collecting them as watch paths
32
+ * lets a barrel retarget invalidate HTML and Page Browser Graph caches without
33
+ * editing the importing Page.
34
+ */
35
+ export declare function getDiscoveredWatchFiles(config: EcoComponentConfig | undefined): readonly string[];
36
+ /**
37
+ * Attaches deferred discovered Component references to `config.dependencies`.
38
+ *
39
+ * @remarks
40
+ * The component getter reads live import bindings only during graph traversal,
41
+ * after module initialization. Inferred stylesheets stay keyed by identity and are
42
+ * not copied into the public bag, so rendering, SSR preload, ownership, and watch
43
+ * collectors share the same graph without object-identity bookkeeping.
44
+ */
45
+ export declare function attachDiscoveredDependencies(config: EcoComponentConfig): void;