@ecopages/core 0.2.0-rc.6 → 0.2.0-rc.8

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 (63) hide show
  1. package/README.md +2 -0
  2. package/package.json +27 -3
  3. package/src/adapters/abstract/segment-path-matcher.js +56 -38
  4. package/src/adapters/bun/create-app.d.ts +4 -0
  5. package/src/adapters/bun/create-app.js +46 -31
  6. package/src/adapters/shared/runtime/server-adapter.d.ts +1 -0
  7. package/src/adapters/shared/runtime/server-adapter.js +9 -22
  8. package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
  9. package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
  10. package/src/declarations.d.ts +10 -1
  11. package/src/eco/README.md +3 -1
  12. package/src/eco/lazy-injector-map.js +57 -41
  13. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
  14. package/src/hmr/strategies/js-hmr-strategy.js +24 -16
  15. package/src/islands/README.md +5 -1
  16. package/src/plugins/component-import-discovery.js +115 -77
  17. package/src/plugins/eco-component-meta-plugin.js +47 -30
  18. package/src/route-renderer/README.md +3 -2
  19. package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
  20. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
  21. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
  22. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +68 -0
  23. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +183 -0
  24. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +9 -0
  25. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +22 -0
  26. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
  27. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
  28. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +7 -2
  29. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
  30. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +3 -2
  31. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +1 -1
  32. package/src/route-renderer/orchestration/integration-renderer.d.ts +7 -3
  33. package/src/route-renderer/orchestration/integration-renderer.js +34 -20
  34. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +1 -1
  35. package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -2
  36. package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
  37. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
  38. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
  39. package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +3 -2
  40. package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
  41. package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
  42. package/src/route-renderer/page-loading/component-dependency-collection.js +95 -74
  43. package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
  44. package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +0 -3
  45. package/src/route-renderer/page-loading/file-scoped-dependency-components.js +37 -34
  46. package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
  47. package/src/router/README.md +7 -1
  48. package/src/router/server/route-registry.d.ts +13 -0
  49. package/src/router/server/route-registry.js +46 -32
  50. package/src/services/README.md +2 -0
  51. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +6 -0
  52. package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +24 -5
  53. package/src/services/assets/asset-processing-service/page-package.js +42 -39
  54. package/src/services/module-loading/page-module-import.service.d.ts +6 -0
  55. package/src/services/module-loading/page-module-import.service.js +60 -27
  56. package/src/services/validation/schema-validation-service.d.ts +1 -0
  57. package/src/services/validation/schema-validation-service.js +23 -36
  58. package/src/static-site-generator/static-site-generator.d.ts +4 -0
  59. package/src/static-site-generator/static-site-generator.js +75 -48
  60. package/src/types/internal-types.d.ts +5 -1
  61. package/src/utils/parse-cli-args.js +29 -22
  62. package/src/watchers/project-watcher.d.ts +5 -0
  63. package/src/watchers/project-watcher.js +46 -32
package/README.md CHANGED
@@ -77,6 +77,8 @@ The manager/orchestration layer is core-owned, but framework-specific strategies
77
77
  - `ConfigBuilder` seeds one app-owned build ownership path, adapter, manifest, executor, dev graph, and runtime registry.
78
78
  - `BrowserBundleService` is the shared browser build seam used by HMR and asset-oriented browser output paths.
79
79
  - `ServerModuleTranspiler` is the shared server-side source loading seam used by runtime bootstrap and HMR metadata loading.
80
+ - `RouteRegistry` gives exact and dynamic Pages priority over catch-alls, then selects the most specific matching catch-all prefix.
81
+ - Browser runtime package entries resolve from the application root with ESM import conditions, so framework-local packages cannot shadow app dependencies.
80
82
  - `createApp()` stays the universal runtime entrypoint, while Vite and Nitro hosts own their advanced dev and build workflows.
81
83
  - One bundled adapter is the default bundler. Vite-based apps route through the `ViteHostBuildAdapter` boundary marker instead.
82
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/core",
3
- "version": "0.2.0-rc.6",
3
+ "version": "0.2.0-rc.8",
4
4
  "description": "Core package for Ecopages",
5
5
  "keywords": [
6
6
  "ecopages",
@@ -20,7 +20,7 @@
20
20
  "directory": "packages/core"
21
21
  },
22
22
  "dependencies": {
23
- "@ecopages/file-system": "0.2.0-rc.6",
23
+ "@ecopages/file-system": "0.2.0-rc.8",
24
24
  "@ecopages/logger": "^0.2.3",
25
25
  "@ecopages/scripts-injector": "^0.1.5",
26
26
  "@oxc-project/runtime": "0.141.0",
@@ -34,7 +34,7 @@
34
34
  "@standard-schema/utils": "^0.3.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "@ecopages/dev-toolbar": "0.2.0-rc.6"
37
+ "@ecopages/dev-toolbar": "0.2.0-rc.8"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@ecopages/dev-toolbar": {
@@ -57,6 +57,18 @@
57
57
  "types": "./src/route-renderer/orchestration/integration-renderer.d.ts",
58
58
  "default": "./src/route-renderer/orchestration/integration-renderer.js"
59
59
  },
60
+ "./route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader": {
61
+ "types": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts",
62
+ "default": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js"
63
+ },
64
+ "./route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer": {
65
+ "types": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts",
66
+ "default": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js"
67
+ },
68
+ "./route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint": {
69
+ "types": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts",
70
+ "default": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js"
71
+ },
60
72
  "./route-renderer/orchestration/string-markup-renderer": {
61
73
  "types": "./src/route-renderer/orchestration/string-markup-renderer.d.ts",
62
74
  "default": "./src/route-renderer/orchestration/string-markup-renderer.js"
@@ -349,6 +361,18 @@
349
361
  "types": "./src/route-renderer/orchestration/integration-renderer.d.ts",
350
362
  "default": "./src/route-renderer/orchestration/integration-renderer.js"
351
363
  },
364
+ "./route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.ts": {
365
+ "types": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts",
366
+ "default": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js"
367
+ },
368
+ "./route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.ts": {
369
+ "types": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts",
370
+ "default": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js"
371
+ },
372
+ "./route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.ts": {
373
+ "types": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts",
374
+ "default": "./src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js"
375
+ },
352
376
  "./route-renderer/orchestration/string-markup-renderer.ts": {
353
377
  "types": "./src/route-renderer/orchestration/string-markup-renderer.d.ts",
354
378
  "default": "./src/route-renderer/orchestration/string-markup-renderer.js"
@@ -4,59 +4,77 @@ export function normalizeSegmentPath(pathname) {
4
4
  }
5
5
  return pathname;
6
6
  }
7
+ function tryMatchCatchAllSegment(patternSegment, state) {
8
+ if (!patternSegment.startsWith('[...') || !patternSegment.endsWith(']')) {
9
+ return null;
10
+ }
11
+ const paramName = patternSegment.slice(4, -1);
12
+ state.params[paramName] = state.pathSegments.slice(state.pathIndex);
13
+ return state.params;
14
+ }
15
+ function tryMatchDynamicSegment(patternSegment, pathSegment, state) {
16
+ if (patternSegment.startsWith(':')) {
17
+ state.params[patternSegment.slice(1)] = pathSegment;
18
+ state.patternIndex++;
19
+ state.pathIndex++;
20
+ return true;
21
+ }
22
+ if (patternSegment.startsWith('[') && patternSegment.endsWith(']')) {
23
+ state.params[patternSegment.slice(1, -1)] = pathSegment;
24
+ state.patternIndex++;
25
+ state.pathIndex++;
26
+ return true;
27
+ }
28
+ return false;
29
+ }
30
+ function matchTrailingCatchAll(state) {
31
+ const remaining = state.patternSegments.slice(state.patternIndex);
32
+ const catchAll = remaining[0];
33
+ if (remaining.length !== 1 || (catchAll !== '*' && !(catchAll.startsWith('[...') && catchAll.endsWith(']')))) {
34
+ return null;
35
+ }
36
+ if (catchAll.startsWith('[...')) {
37
+ const paramName = catchAll.slice(4, -1);
38
+ state.params[paramName] = [];
39
+ }
40
+ return state.params;
41
+ }
7
42
  export function matchApiPathPattern(pattern, pathname) {
8
43
  const normalizedPattern = normalizeSegmentPath(pattern);
9
44
  const normalizedPathname = normalizeSegmentPath(pathname);
10
- const patternSegments = normalizedPattern.split('/').filter(Boolean);
11
- const pathSegments = normalizedPathname.split('/').filter(Boolean);
12
- const params = {};
13
- let patternIndex = 0;
14
- let pathIndex = 0;
15
- while (patternIndex < patternSegments.length && pathIndex < pathSegments.length) {
16
- const patternSegment = patternSegments[patternIndex];
17
- const pathSegment = pathSegments[pathIndex];
45
+ const state = {
46
+ patternSegments: normalizedPattern.split('/').filter(Boolean),
47
+ pathSegments: normalizedPathname.split('/').filter(Boolean),
48
+ params: {},
49
+ patternIndex: 0,
50
+ pathIndex: 0,
51
+ };
52
+ while (state.patternIndex < state.patternSegments.length && state.pathIndex < state.pathSegments.length) {
53
+ const patternSegment = state.patternSegments[state.patternIndex];
54
+ const pathSegment = state.pathSegments[state.pathIndex];
18
55
  if (patternSegment === '*') {
19
- return params;
20
- }
21
- if (patternSegment.startsWith('[...') && patternSegment.endsWith(']')) {
22
- const paramName = patternSegment.slice(4, -1);
23
- params[paramName] = pathSegments.slice(pathIndex);
24
- return params;
56
+ return state.params;
25
57
  }
26
- if (patternSegment.startsWith(':')) {
27
- params[patternSegment.slice(1)] = pathSegment;
28
- patternIndex++;
29
- pathIndex++;
30
- continue;
58
+ const catchAllMatch = tryMatchCatchAllSegment(patternSegment, state);
59
+ if (catchAllMatch) {
60
+ return catchAllMatch;
31
61
  }
32
- if (patternSegment.startsWith('[') && patternSegment.endsWith(']')) {
33
- params[patternSegment.slice(1, -1)] = pathSegment;
34
- patternIndex++;
35
- pathIndex++;
62
+ if (tryMatchDynamicSegment(patternSegment, pathSegment, state)) {
36
63
  continue;
37
64
  }
38
65
  if (patternSegment !== pathSegment) {
39
66
  return null;
40
67
  }
41
- patternIndex++;
42
- pathIndex++;
68
+ state.patternIndex++;
69
+ state.pathIndex++;
43
70
  }
44
- if (patternIndex < patternSegments.length) {
45
- const remaining = patternSegments.slice(patternIndex);
46
- const catchAll = remaining[0];
47
- if (remaining.length === 1 && (catchAll === '*' || (catchAll.startsWith('[...') && catchAll.endsWith(']')))) {
48
- if (catchAll.startsWith('[...')) {
49
- const paramName = catchAll.slice(4, -1);
50
- params[paramName] = [];
51
- }
52
- return params;
53
- }
54
- return null;
71
+ if (state.patternIndex < state.patternSegments.length) {
72
+ return matchTrailingCatchAll(state);
55
73
  }
56
- if (pathIndex < pathSegments.length) {
74
+ if (state.pathIndex < state.pathSegments.length) {
57
75
  return null;
58
76
  }
59
- return params;
77
+ return state.params;
60
78
  }
61
79
  export function scoreApiPathPattern(pattern) {
62
80
  const segments = normalizeSegmentPath(pattern).split('/').filter(Boolean);
@@ -48,6 +48,10 @@ export declare class BunEcopagesApp<WebSocketData = undefined> extends SharedApp
48
48
  * Initialize the Bun server adapter
49
49
  */
50
50
  protected initializeServerAdapter(): Promise<BunServerAdapterResult>;
51
+ private ensureServerAdapterReady;
52
+ private bootPreviewServeOnly;
53
+ private bootStaticWithoutRuntimeServer;
54
+ private runStaticBuildOnRuntimeServer;
51
55
  /**
52
56
  * Start the Bun application server
53
57
  * @param options Optional settings
@@ -77,12 +77,7 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
77
77
  allowPortFallback: binding.allowPortFallback,
78
78
  });
79
79
  }
80
- /**
81
- * Start the Bun application server
82
- * @param options Optional settings
83
- * @param options.autoCompleteInitialization Whether to automatically complete initialization with dynamic routes after server start (defaults to true)
84
- */
85
- async bootServer() {
80
+ async ensureServerAdapterReady() {
86
81
  if (this.stopped) {
87
82
  this.serverAdapter = undefined;
88
83
  this.stopped = false;
@@ -90,40 +85,68 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
90
85
  if (!this.serverAdapter) {
91
86
  this.serverAdapter = await this.initializeServerAdapter();
92
87
  }
88
+ return this.serverAdapter;
89
+ }
90
+ async bootPreviewServeOnly(serverAdapter) {
91
+ const previewOrigin = await serverAdapter.servePreviewOnly();
92
+ if (previewOrigin) {
93
+ await this.notifyListening(previewOrigin);
94
+ }
95
+ }
96
+ async bootStaticWithoutRuntimeServer(serverAdapter, preview, build, force) {
97
+ appLogger.debugTime('Building static pages');
98
+ const previewOrigin = await serverAdapter.buildStatic({ preview, force });
99
+ appLogger.debugTimeEnd('Building static pages');
100
+ if (preview && previewOrigin) {
101
+ await this.notifyListening(previewOrigin);
102
+ }
103
+ if (build) {
104
+ process.exit(0);
105
+ }
106
+ }
107
+ async runStaticBuildOnRuntimeServer(serverAdapter, preview, build, force) {
108
+ appLogger.debugTime('Building static pages');
109
+ const previewOrigin = await serverAdapter.buildStatic({ preview, force });
110
+ const buildRuntimeServer = this.server;
111
+ this.server = null;
112
+ if (buildRuntimeServer) {
113
+ await this.runtimeHost.stop(buildRuntimeServer, { force: true });
114
+ }
115
+ appLogger.debugTimeEnd('Building static pages');
116
+ if (build) {
117
+ process.exit(0);
118
+ }
119
+ return previewOrigin;
120
+ }
121
+ /**
122
+ * Start the Bun application server
123
+ * @param options Optional settings
124
+ * @param options.autoCompleteInitialization Whether to automatically complete initialization with dynamic routes after server start (defaults to true)
125
+ */
126
+ async bootServer() {
127
+ const serverAdapter = await this.ensureServerAdapterReady();
93
128
  const { dev, preview, build, force, serveOnly } = this.cliArgs;
94
129
  const staticRuntimeMode = resolveStaticRuntimeMode({
95
130
  appConfig: this.appConfig,
96
131
  cliArgs: this.cliArgs,
97
132
  });
98
133
  if (preview && serveOnly) {
99
- const previewOrigin = await this.serverAdapter.servePreviewOnly();
100
- if (previewOrigin) {
101
- await this.notifyListening(previewOrigin);
102
- }
134
+ await this.bootPreviewServeOnly(serverAdapter);
103
135
  return;
104
136
  }
105
137
  if (staticRuntimeMode.canBuildWithoutRuntimeServer) {
106
- appLogger.debugTime('Building static pages');
107
- const previewOrigin = await this.serverAdapter.buildStatic({ preview, force });
108
- appLogger.debugTimeEnd('Building static pages');
109
- if (preview && previewOrigin) {
110
- await this.notifyListening(previewOrigin);
111
- }
112
- if (build) {
113
- process.exit(0);
114
- }
138
+ await this.bootStaticWithoutRuntimeServer(serverAdapter, preview, build, force);
115
139
  return;
116
140
  }
117
141
  const enableHmr = dev || (!preview && !build);
118
- const serverOptions = this.serverAdapter.getServerOptions({ enableHmr });
119
- const runtimeServerOptions = serverOptions;
142
+ const runtimeServerOptions = serverAdapter.getServerOptions({ enableHmr });
120
143
  startupTrace.beginServerListen();
121
144
  this.server = await this.runtimeHost.start({
122
145
  serveOptions: runtimeServerOptions,
123
146
  handleRequest: async () => new Response(null, { status: 500 }),
124
147
  onError: async () => { },
125
148
  });
126
- await this.serverAdapter.completeInitialization(this.server).catch((error) => {
149
+ await serverAdapter.completeInitialization(this.server).catch((error) => {
127
150
  appLogger.error(`Failed to complete initialization: ${error}`);
128
151
  });
129
152
  if (!this.server) {
@@ -132,15 +155,7 @@ export class BunEcopagesApp extends SharedApplicationAdapter {
132
155
  const runtimeOrigin = this.runtimeHost.getOrigin(this.server, runtimeServerOptions);
133
156
  let previewOrigin;
134
157
  if (build || preview) {
135
- appLogger.debugTime('Building static pages');
136
- previewOrigin = await this.serverAdapter.buildStatic({ preview, force });
137
- const buildRuntimeServer = this.server;
138
- this.server = null;
139
- await this.runtimeHost.stop(buildRuntimeServer, { force: true });
140
- appLogger.debugTimeEnd('Building static pages');
141
- if (build) {
142
- process.exit(0);
143
- }
158
+ previewOrigin = await this.runStaticBuildOnRuntimeServer(serverAdapter, preview, build, force);
144
159
  }
145
160
  else {
146
161
  await this.notifyListening(runtimeOrigin);
@@ -66,6 +66,7 @@ export declare abstract class SharedServerAdapter<TOptions extends ServerAdapter
66
66
  */
67
67
  protected configureSharedResponseHandlers(staticRoutes: StaticRoute[], hmrManager?: IHmrManager): void;
68
68
  private createSharedResponseHandlerDependencies;
69
+ private createSharedPageCacheServiceFromConfig;
69
70
  private getOrCreateSharedPageCacheService;
70
71
  protected getCacheService(): CacheInvalidator | null;
71
72
  protected getRenderContext(): RenderContext;
@@ -190,36 +190,23 @@ export class SharedServerAdapter extends AbstractServerAdapter {
190
190
  : undefined,
191
191
  };
192
192
  }
193
- getOrCreateSharedPageCacheService() {
194
- if (this.sharedPageCacheService !== undefined) {
195
- return this.sharedPageCacheService;
196
- }
193
+ createSharedPageCacheServiceFromConfig() {
197
194
  const cacheConfig = this.appConfig.cache;
198
195
  const watch = Boolean(this.options?.watch);
199
- if (watch) {
200
- if (cacheConfig?.enabled === false) {
201
- this.sharedPageCacheService = null;
202
- registerAppPageCacheService(this.appConfig, null);
203
- return null;
204
- }
205
- const store = cacheConfig?.store === 'memory' || !cacheConfig?.store
206
- ? new MemoryCacheStore({ maxEntries: cacheConfig?.maxEntries })
207
- : cacheConfig.store;
208
- const service = new PageCacheService({ store, enabled: true });
209
- this.sharedPageCacheService = service;
210
- registerAppPageCacheService(this.appConfig, service);
211
- return service;
212
- }
213
- const isCacheEnabled = cacheConfig?.enabled ?? true;
196
+ const isCacheEnabled = watch ? cacheConfig?.enabled !== false : (cacheConfig?.enabled ?? true);
214
197
  if (!isCacheEnabled) {
215
- this.sharedPageCacheService = null;
216
- registerAppPageCacheService(this.appConfig, null);
217
198
  return null;
218
199
  }
219
200
  const store = cacheConfig?.store === 'memory' || !cacheConfig?.store
220
201
  ? new MemoryCacheStore({ maxEntries: cacheConfig?.maxEntries })
221
202
  : cacheConfig.store;
222
- const service = new PageCacheService({ store, enabled: true });
203
+ return new PageCacheService({ store, enabled: true });
204
+ }
205
+ getOrCreateSharedPageCacheService() {
206
+ if (this.sharedPageCacheService !== undefined) {
207
+ return this.sharedPageCacheService;
208
+ }
209
+ const service = this.createSharedPageCacheServiceFromConfig();
223
210
  this.sharedPageCacheService = service;
224
211
  registerAppPageCacheService(this.appConfig, service);
225
212
  return service;
@@ -298,14 +298,7 @@ export function toBuildLogs(error) {
298
298
  }
299
299
  return [{ message: 'Unknown build error' }];
300
300
  }
301
- /**
302
- * Translates a {@link BuildOptions} into Rolldown's `InputOptions` and
303
- * `OutputOptions`. Always sets `experimental.nativeMagicString: true`
304
- * and always consolidates eco plugins via the bridge.
305
- */
306
- export function resolveRolldownOptions(options, contextRoot, outdir, appRootRequireCache) {
307
- const rolldownPlatform = mapRolldownPlatform(options.target);
308
- const external = createExternalMatcher(options, appRootRequireCache);
301
+ function buildRolldownTransformOptions(options) {
309
302
  const transformOptions = {};
310
303
  if (options.define) {
311
304
  transformOptions.define = options.define;
@@ -316,21 +309,26 @@ export function resolveRolldownOptions(options, contextRoot, outdir, appRootRequ
316
309
  if (options.target && /^(?:es|chrome|edge|firefox|safari|hermes|deno|ios)/.test(options.target)) {
317
310
  transformOptions.target = options.target;
318
311
  }
312
+ return Object.keys(transformOptions).length > 0 ? transformOptions : undefined;
313
+ }
314
+ function buildRolldownInputPlugins(options, contextRoot, rolldownPlatform) {
319
315
  const bundlePlugins = options.plugins ?? [];
320
316
  const sourceTransforms = options.sourceTransforms ?? [];
321
317
  const appPlugins = createRolldownPluginBridge(bundlePlugins, contextRoot, sourceTransforms);
322
- const allPlugins = [
318
+ return [
323
319
  ...(rolldownPlatform === 'node' ? [createNodeBuiltinExternalPlugin()] : []),
324
320
  ...(rolldownPlatform === 'browser' ? [createBrowserNodeBuiltinGuardPlugin()] : []),
325
321
  ...(options.target !== 'browser' ? [createServerSideCssShimPlugin()] : []),
326
322
  ...appPlugins,
327
323
  ];
328
- const inputOptions = {
324
+ }
325
+ function buildRolldownInputOptions(options, contextRoot, external, rolldownPlatform) {
326
+ return {
329
327
  input: options.entrypoints,
330
328
  cwd: contextRoot,
331
329
  external,
332
- platform: mapRolldownPlatform(options.target),
333
- transform: Object.keys(transformOptions).length > 0 ? transformOptions : undefined,
330
+ platform: rolldownPlatform,
331
+ transform: buildRolldownTransformOptions(options),
334
332
  resolve: options.conditions ? { conditionNames: options.conditions } : undefined,
335
333
  treeshake: typeof options.treeshaking === 'boolean' ? options.treeshaking : true,
336
334
  ...(process.env.ECOPAGES_PROFILE_BUILD === '1'
@@ -343,32 +341,50 @@ export function resolveRolldownOptions(options, contextRoot, outdir, appRootRequ
343
341
  experimental: {
344
342
  nativeMagicString: true,
345
343
  },
346
- plugins: allPlugins,
344
+ plugins: buildRolldownInputPlugins(options, contextRoot, rolldownPlatform),
347
345
  };
346
+ }
347
+ function resolveRolldownEntryFileNames(options) {
348
348
  const entryFileNames = toEntryFileNamesPattern(options.naming);
349
349
  const jsExtension = getJavaScriptOutExtension(options, entryFileNames?.literal ?? false);
350
- const finalEntryFileNames = entryFileNames
351
- ? jsExtension
352
- ? `${entryFileNames.pattern}${jsExtension}`
353
- : entryFileNames.pattern
354
- : jsExtension
355
- ? `[name]${jsExtension}`
356
- : '[name]';
350
+ if (entryFileNames) {
351
+ return jsExtension ? `${entryFileNames.pattern}${jsExtension}` : entryFileNames.pattern;
352
+ }
353
+ return jsExtension ? `[name]${jsExtension}` : '[name]';
354
+ }
355
+ function shouldDisableRolldownCodeSplitting(options) {
356
+ if (options.splitting !== false) {
357
+ return false;
358
+ }
357
359
  const entrypointCount = Array.isArray(options.entrypoints)
358
360
  ? options.entrypoints.length
359
361
  : Object.keys(options.entrypoints).length;
360
- const disableCodeSplitting = options.splitting === false && entrypointCount === 1;
361
- const outputOptions = {
362
+ return entrypointCount === 1;
363
+ }
364
+ function buildRolldownOutputOptions(options, outdir) {
365
+ return {
362
366
  dir: outdir,
363
367
  format: mapRolldownFormat(options.format),
364
368
  minify: !!options.minify,
365
- entryFileNames: finalEntryFileNames,
369
+ entryFileNames: resolveRolldownEntryFileNames(options),
366
370
  chunkFileNames: '[name]-[hash].js',
367
371
  assetFileNames: '[name]-[hash][extname]',
368
372
  sourcemap: mapRolldownSourcemap(options.sourcemap),
369
- ...(disableCodeSplitting ? { codeSplitting: false } : {}),
373
+ ...(shouldDisableRolldownCodeSplitting(options) ? { codeSplitting: false } : {}),
374
+ };
375
+ }
376
+ /**
377
+ * Translates a {@link BuildOptions} into Rolldown's `InputOptions` and
378
+ * `OutputOptions`. Always sets `experimental.nativeMagicString: true`
379
+ * and always consolidates eco plugins via the bridge.
380
+ */
381
+ export function resolveRolldownOptions(options, contextRoot, outdir, appRootRequireCache) {
382
+ const rolldownPlatform = mapRolldownPlatform(options.target);
383
+ const external = createExternalMatcher(options, appRootRequireCache);
384
+ return {
385
+ inputOptions: buildRolldownInputOptions(options, contextRoot, external, rolldownPlatform),
386
+ outputOptions: buildRolldownOutputOptions(options, outdir),
370
387
  };
371
- return { inputOptions, outputOptions };
372
388
  }
373
389
  /**
374
390
  * Rewrites manifest-owned runtime specifiers in emitted JS output
@@ -73,29 +73,33 @@ function inferRolldownModuleTypeFromPath(filePath) {
73
73
  return 'js';
74
74
  }
75
75
  }
76
+ const DIRECT_ROLLDOWN_MODULE_LOADERS = new Set([
77
+ 'js',
78
+ 'jsx',
79
+ 'ts',
80
+ 'tsx',
81
+ 'json',
82
+ 'css',
83
+ 'text',
84
+ 'base64',
85
+ 'dataurl',
86
+ 'binary',
87
+ 'empty',
88
+ ]);
89
+ const ROLLDOWN_LOADER_ALIASES = {
90
+ 'global-css': 'css',
91
+ 'local-css': 'css',
92
+ file: 'asset',
93
+ copy: 'asset',
94
+ };
76
95
  function normalizeRolldownModuleType(loader) {
77
- switch (loader) {
78
- case 'js':
79
- case 'jsx':
80
- case 'ts':
81
- case 'tsx':
82
- case 'json':
83
- case 'css':
84
- case 'text':
85
- case 'base64':
86
- case 'dataurl':
87
- case 'binary':
88
- case 'empty':
89
- return loader;
90
- case 'global-css':
91
- case 'local-css':
92
- return 'css';
93
- case 'file':
94
- case 'copy':
95
- return 'asset';
96
- default:
97
- return undefined;
96
+ if (typeof loader === 'string' && DIRECT_ROLLDOWN_MODULE_LOADERS.has(loader)) {
97
+ return loader;
98
98
  }
99
+ if (typeof loader === 'string' && Object.prototype.hasOwnProperty.call(ROLLDOWN_LOADER_ALIASES, loader)) {
100
+ return ROLLDOWN_LOADER_ALIASES[loader];
101
+ }
102
+ return undefined;
99
103
  }
100
104
  function convertLoadResultToModuleSource(result) {
101
105
  if (result.loader === 'object' && result.exports && typeof result.exports === 'object') {
@@ -1,4 +1,4 @@
1
- /// <reference path="./css-imports.d.js" />
1
+ import './css-imports.d.js';
2
2
 
3
3
  import type { EcoPagesAppConfig } from './types/internal-types';
4
4
  import type { EcoNavigationRuntime } from './router/client/navigation-coordinator';
@@ -6,6 +6,12 @@ import type { EcoNavigationRuntime } from './router/client/navigation-coordinato
6
6
  type HMRHandler = (url: string) => Promise<void>;
7
7
  type CleanupPageRootFunction = () => void;
8
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
+ };
9
15
  type EcoPageData = {
10
16
  module: string;
11
17
  props: Record<string, unknown>;
@@ -17,7 +23,10 @@ type EcoPagesWindowRuntime = {
17
23
  cleanupPageRoot?: CleanupPageRootFunction;
18
24
  pageRoot?: EcoPageRoot | null;
19
25
  };
26
+ /** Roots keyed by SSR instance ID; component keys are never used for lookup. */
20
27
  islandRoots?: Record<string, EcoPageRoot>;
28
+ islandComponents?: Record<string, EcoIslandComponent>;
29
+ __ecoIslandRuntime?: EcoIslandRuntime;
21
30
  page?: EcoPageData;
22
31
  };
23
32
 
package/src/eco/README.md CHANGED
@@ -67,7 +67,9 @@ scripts: [
67
67
  ];
68
68
  ```
69
69
 
70
- For Lit, this registers the custom element before server rendering while delaying browser execution until visibility. `ssr: true` does not force eager browser loading. To load eagerly, omit `lazy`. This corrects the previous behavior that emitted an extra eager script for SSR-enabled lazy entries.
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.
71
73
 
72
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.
73
75