@ecopages/core 0.2.0-rc.7 → 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.
- package/package.json +27 -3
- package/src/adapters/abstract/segment-path-matcher.js +56 -38
- package/src/adapters/bun/create-app.d.ts +4 -0
- package/src/adapters/bun/create-app.js +46 -31
- package/src/adapters/shared/runtime/server-adapter.d.ts +1 -0
- package/src/adapters/shared/runtime/server-adapter.js +9 -22
- package/src/build/rolldown/rolldown-adapter-helpers.js +41 -25
- package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
- package/src/eco/README.md +3 -1
- package/src/eco/lazy-injector-map.js +57 -41
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
- package/src/hmr/strategies/js-hmr-strategy.js +24 -16
- package/src/plugins/component-import-discovery.js +115 -77
- package/src/plugins/eco-component-meta-plugin.js +47 -30
- package/src/route-renderer/README.md +1 -0
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +9 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.d.ts +16 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preload-invalidation.js +34 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +68 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +183 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +9 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +22 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.d.ts +10 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-ssr-preload-entrypoint.js +46 -0
- package/src/route-renderer/orchestration/integration-renderer.d.ts +3 -0
- package/src/route-renderer/orchestration/integration-renderer.js +31 -17
- package/src/route-renderer/orchestration/ownership-graph/component-graph.js +55 -39
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.d.ts +6 -0
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +59 -36
- package/src/route-renderer/page-loading/component-dependency-collection.js +95 -74
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
- package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +0 -3
- package/src/route-renderer/page-loading/file-scoped-dependency-components.js +37 -34
- package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
- package/src/router/README.md +2 -0
- package/src/services/assets/asset-processing-service/page-package.js +42 -39
- package/src/services/module-loading/page-module-import.service.d.ts +6 -0
- package/src/services/module-loading/page-module-import.service.js +60 -27
- package/src/services/validation/schema-validation-service.d.ts +1 -0
- package/src/services/validation/schema-validation-service.js +23 -36
- package/src/static-site-generator/static-site-generator.d.ts +4 -0
- package/src/static-site-generator/static-site-generator.js +75 -48
- package/src/utils/parse-cli-args.js +29 -22
- package/src/watchers/project-watcher.d.ts +5 -0
- package/src/watchers/project-watcher.js +46 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/core",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
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.
|
|
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.
|
|
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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
pathIndex++;
|
|
30
|
-
continue;
|
|
58
|
+
const catchAllMatch = tryMatchCatchAllSegment(patternSegment, state);
|
|
59
|
+
if (catchAllMatch) {
|
|
60
|
+
return catchAllMatch;
|
|
31
61
|
}
|
|
32
|
-
if (patternSegment
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
318
|
+
return [
|
|
323
319
|
...(rolldownPlatform === 'node' ? [createNodeBuiltinExternalPlugin()] : []),
|
|
324
320
|
...(rolldownPlatform === 'browser' ? [createBrowserNodeBuiltinGuardPlugin()] : []),
|
|
325
321
|
...(options.target !== 'browser' ? [createServerSideCssShimPlugin()] : []),
|
|
326
322
|
...appPlugins,
|
|
327
323
|
];
|
|
328
|
-
|
|
324
|
+
}
|
|
325
|
+
function buildRolldownInputOptions(options, contextRoot, external, rolldownPlatform) {
|
|
326
|
+
return {
|
|
329
327
|
input: options.entrypoints,
|
|
330
328
|
cwd: contextRoot,
|
|
331
329
|
external,
|
|
332
|
-
platform:
|
|
333
|
-
transform:
|
|
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:
|
|
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
|
-
|
|
351
|
-
? jsExtension
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
361
|
-
|
|
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:
|
|
369
|
+
entryFileNames: resolveRolldownEntryFileNames(options),
|
|
366
370
|
chunkFileNames: '[name]-[hash].js',
|
|
367
371
|
assetFileNames: '[name]-[hash][extname]',
|
|
368
372
|
sourcemap: mapRolldownSourcemap(options.sourcemap),
|
|
369
|
-
...(
|
|
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
|
-
|
|
78
|
-
|
|
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') {
|
package/src/eco/README.md
CHANGED
|
@@ -67,7 +67,9 @@ scripts: [
|
|
|
67
67
|
];
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
For Lit,
|
|
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
|
|
|
@@ -35,48 +35,51 @@ function dedupeCsvValues(values) {
|
|
|
35
35
|
}
|
|
36
36
|
return Array.from(seen).join(',');
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
38
|
+
function mergeInjectorScripts(map, key, scripts) {
|
|
39
|
+
const entry = map[key];
|
|
40
|
+
map[key] = {
|
|
41
|
+
...entry,
|
|
42
|
+
scripts: [...(entry?.scripts ?? []), ...scripts],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function applyIdleLazyTrigger(map, scripts) {
|
|
46
|
+
mergeInjectorScripts(map, 'on:idle', scripts);
|
|
47
|
+
}
|
|
48
|
+
function applyInteractionLazyTrigger(map, lazy, scripts) {
|
|
49
|
+
const currentValue = map['on:interaction']?.value;
|
|
50
|
+
const nextValue = lazy['on:interaction'];
|
|
51
|
+
map['on:interaction'] = {
|
|
52
|
+
value: typeof currentValue === 'string' ? dedupeCsvValues([currentValue, nextValue]) : nextValue,
|
|
53
|
+
scripts: [...(map['on:interaction']?.scripts ?? []), ...scripts],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function applyVisibleLazyTrigger(map, lazy, scripts) {
|
|
57
|
+
const currentValue = map['on:visible']?.value;
|
|
58
|
+
const currentThreshold = typeof currentValue === 'string' ? currentValue : undefined;
|
|
59
|
+
const nextValue = lazy['on:visible'];
|
|
60
|
+
map['on:visible'] = {
|
|
61
|
+
...(nextValue === true ? (currentThreshold ? { value: currentThreshold } : {}) : { value: String(nextValue) }),
|
|
62
|
+
scripts: [...(map['on:visible']?.scripts ?? []), ...scripts],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function applyLazyGroupToInjectorMap(map, group) {
|
|
66
|
+
const scripts = normalizeScripts(group.scripts);
|
|
67
|
+
const lazy = group.lazy;
|
|
68
|
+
if ('on:idle' in lazy) {
|
|
69
|
+
applyIdleLazyTrigger(map, scripts);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if ('on:interaction' in lazy) {
|
|
73
|
+
applyInteractionLazyTrigger(map, lazy, scripts);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if ('on:visible' in lazy) {
|
|
77
|
+
applyVisibleLazyTrigger(map, lazy, scripts);
|
|
78
|
+
return;
|
|
79
79
|
}
|
|
80
|
+
throw new Error(`Invalid lazy options: must specify on:idle, on:interaction, or on:visible. Received: ${JSON.stringify(lazy)}`);
|
|
81
|
+
}
|
|
82
|
+
function dedupeInjectorMapScripts(map) {
|
|
80
83
|
for (const key of Object.keys(map)) {
|
|
81
84
|
const scripts = map[key]?.scripts;
|
|
82
85
|
if (scripts) {
|
|
@@ -86,6 +89,19 @@ function buildInjectorMap(lazyGroups) {
|
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
91
|
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Builds a scripts-injector map config from resolved lazy script groups.
|
|
95
|
+
*
|
|
96
|
+
* @param lazyGroups Lazy script groups resolved during dependency processing.
|
|
97
|
+
* @returns Injector map config keyed by lazy trigger.
|
|
98
|
+
*/
|
|
99
|
+
function buildInjectorMap(lazyGroups) {
|
|
100
|
+
const map = {};
|
|
101
|
+
for (const group of lazyGroups) {
|
|
102
|
+
applyLazyGroupToInjectorMap(map, group);
|
|
103
|
+
}
|
|
104
|
+
dedupeInjectorMapScripts(map);
|
|
89
105
|
return map;
|
|
90
106
|
}
|
|
91
107
|
/**
|