@ecopages/core 0.2.0-rc.8 → 0.2.0-rc.9
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 +3 -3
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +2 -2
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +14 -2
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +12 -5
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +8 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +19 -0
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.9",
|
|
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.9",
|
|
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.9"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@ecopages/dev-toolbar": {
|
|
@@ -4,6 +4,6 @@ Shared orchestration for `dependencies.scripts` entries marked `ssr: true`.
|
|
|
4
4
|
|
|
5
5
|
Lit and Ecopages JSX construct a {@link CustomElementScriptPreloader} with a stable `cacheScope` so imports are deduplicated across concurrent renders and dev invalidation can clear preload state without per-renderer registries.
|
|
6
6
|
|
|
7
|
-
Server evaluation uses `appConfig.runtime.appModuleLoader` via {@link createCustomElementServerModuleImporter} when no {@link createCustomElementSsrPreloadEntrypointResolver} is configured. Lit
|
|
7
|
+
Server evaluation uses `appConfig.runtime.appModuleLoader` via {@link createCustomElementServerModuleImporter} when no {@link createCustomElementSsrPreloadEntrypointResolver} is configured. Lit passes a resolver so Node preloads through the asset pipeline and Bun can import source. The resolver skips {@link importServerModule}; Lit's static-render worker therefore omits it and uses the app module loader so `@lit-labs/ssr` sees registered custom elements. Ecopages JSX does not pass a resolver. On Bun, `preferSourceImports` imports the script source directly. On Node it imports through the page server-module loader with external packages, because the dev asset pipeline still points at `.tsx` source and a browser bundle would register a second Radiant graph.
|
|
8
8
|
|
|
9
|
-
Lit only preloads lazy `ssr: true` script entries (`requireLazyScriptEntry`) so eager registrations are not evaluated in an isolated graph that would break `@lit-labs/ssr`.
|
|
9
|
+
Lit only preloads lazy `ssr: true` script entries (`requireLazyScriptEntry`) so eager registrations are not evaluated in an isolated graph that would break `@lit-labs/ssr`. Ecopages JSX sets `collectForIntegration` so foreign integration scripts in shared dependency trees are not preloaded here; Lit and other hosts keep owning their registrations.
|
package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare function isExpectedCustomElementSsrPreloadError(error: unknown):
|
|
|
13
13
|
/**
|
|
14
14
|
* Collects `dependencies.scripts` paths marked `ssr: true` from a component tree.
|
|
15
15
|
*/
|
|
16
|
-
export declare function collectCustomElementSsrPreloadScripts(components: Array<CustomElementSsrPreloadComponent | undefined>, resolveDependencyPath: (componentDir: string, sourcePath: string) => string, requireLazyScriptEntry?: boolean): string[];
|
|
16
|
+
export declare function collectCustomElementSsrPreloadScripts(components: Array<CustomElementSsrPreloadComponent | undefined>, resolveDependencyPath: (componentDir: string, sourcePath: string) => string, requireLazyScriptEntry?: boolean, collectForIntegration?: string): string[];
|
|
17
17
|
export interface CustomElementScriptPreloaderOptions {
|
|
18
18
|
cacheScope: string;
|
|
19
19
|
enabled?: boolean;
|
|
@@ -36,6 +36,17 @@ export interface CustomElementScriptPreloaderOptions {
|
|
|
36
36
|
*/
|
|
37
37
|
resolvePreloadEntrypoint?: (scriptPath: string) => Promise<string>;
|
|
38
38
|
importServerModule?: (scriptPath: string, registryKey: string) => Promise<unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Limits script collection to components owned by one integration.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Dependency trees may include foreign integrations whose `ssr: true` scripts
|
|
44
|
+
* are preloaded by their own renderer. Ownership uses
|
|
45
|
+
* `config.integration ?? identity.integration`, matching render routing.
|
|
46
|
+
* Ecopages JSX still walks nested components so it can find owned Radiant
|
|
47
|
+
* hosts deeper in the graph.
|
|
48
|
+
*/
|
|
49
|
+
collectForIntegration?: string;
|
|
39
50
|
logLabel?: string;
|
|
40
51
|
}
|
|
41
52
|
/**
|
|
@@ -54,8 +65,9 @@ export declare class CustomElementScriptPreloader {
|
|
|
54
65
|
private readonly preferSourceImports;
|
|
55
66
|
private readonly resolvePreloadEntrypoint?;
|
|
56
67
|
private readonly importServerModule?;
|
|
68
|
+
private readonly collectForIntegration?;
|
|
57
69
|
private readonly logLabel;
|
|
58
|
-
constructor({ cacheScope, enabled, requireLazyScriptEntry, resolveDependencyPath, preferSourceImports, resolvePreloadEntrypoint, importServerModule, logLabel, }: CustomElementScriptPreloaderOptions);
|
|
70
|
+
constructor({ cacheScope, enabled, requireLazyScriptEntry, resolveDependencyPath, preferSourceImports, resolvePreloadEntrypoint, importServerModule, collectForIntegration, logLabel, }: CustomElementScriptPreloaderOptions);
|
|
59
71
|
invalidateScript(scriptPath: string): void;
|
|
60
72
|
isExpectedSsrPreloadError(error: unknown): boolean;
|
|
61
73
|
collectSsrPreloadScripts(components: Array<CustomElementSsrPreloadComponent | undefined>): string[];
|
package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js
CHANGED
|
@@ -45,7 +45,7 @@ function collectSsrScriptsFromConfig(config, scriptPaths, resolveDependencyPath,
|
|
|
45
45
|
/**
|
|
46
46
|
* Collects `dependencies.scripts` paths marked `ssr: true` from a component tree.
|
|
47
47
|
*/
|
|
48
|
-
export function collectCustomElementSsrPreloadScripts(components, resolveDependencyPath, requireLazyScriptEntry = false) {
|
|
48
|
+
export function collectCustomElementSsrPreloadScripts(components, resolveDependencyPath, requireLazyScriptEntry = false, collectForIntegration) {
|
|
49
49
|
const scriptPaths = new Set();
|
|
50
50
|
const visitedConfigs = new Set();
|
|
51
51
|
const collect = (component) => {
|
|
@@ -54,8 +54,13 @@ export function collectCustomElementSsrPreloadScripts(components, resolveDepende
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
visitedConfigs.add(config);
|
|
57
|
-
const
|
|
58
|
-
|
|
57
|
+
const identity = getComponentIdentity(config);
|
|
58
|
+
const integration = config.integration ?? identity?.integration;
|
|
59
|
+
const ownsScripts = !collectForIntegration || integration === collectForIntegration;
|
|
60
|
+
const componentFile = ownsScripts ? identity?.file : undefined;
|
|
61
|
+
if (ownsScripts) {
|
|
62
|
+
collectSsrScriptsFromConfig(config, scriptPaths, resolveDependencyPath, componentFile, requireLazyScriptEntry);
|
|
63
|
+
}
|
|
59
64
|
for (const layout of config.layouts ?? []) {
|
|
60
65
|
collect(layout);
|
|
61
66
|
}
|
|
@@ -84,8 +89,9 @@ export class CustomElementScriptPreloader {
|
|
|
84
89
|
preferSourceImports;
|
|
85
90
|
resolvePreloadEntrypoint;
|
|
86
91
|
importServerModule;
|
|
92
|
+
collectForIntegration;
|
|
87
93
|
logLabel;
|
|
88
|
-
constructor({ cacheScope, enabled = true, requireLazyScriptEntry = false, resolveDependencyPath, preferSourceImports, resolvePreloadEntrypoint, importServerModule, logLabel = 'ecopages', }) {
|
|
94
|
+
constructor({ cacheScope, enabled = true, requireLazyScriptEntry = false, resolveDependencyPath, preferSourceImports, resolvePreloadEntrypoint, importServerModule, collectForIntegration, logLabel = 'ecopages', }) {
|
|
89
95
|
this.cacheScope = cacheScope;
|
|
90
96
|
this.enabled = enabled;
|
|
91
97
|
this.requireLazyScriptEntry = requireLazyScriptEntry;
|
|
@@ -93,6 +99,7 @@ export class CustomElementScriptPreloader {
|
|
|
93
99
|
this.preferSourceImports = preferSourceImports ?? typeof Bun !== 'undefined';
|
|
94
100
|
this.resolvePreloadEntrypoint = resolvePreloadEntrypoint;
|
|
95
101
|
this.importServerModule = importServerModule;
|
|
102
|
+
this.collectForIntegration = collectForIntegration;
|
|
96
103
|
this.logLabel = logLabel;
|
|
97
104
|
}
|
|
98
105
|
invalidateScript(scriptPath) {
|
|
@@ -102,7 +109,7 @@ export class CustomElementScriptPreloader {
|
|
|
102
109
|
return isExpectedCustomElementSsrPreloadError(error);
|
|
103
110
|
}
|
|
104
111
|
collectSsrPreloadScripts(components) {
|
|
105
|
-
return collectCustomElementSsrPreloadScripts(components, this.resolveDependencyPath, this.requireLazyScriptEntry);
|
|
112
|
+
return collectCustomElementSsrPreloadScripts(components, this.resolveDependencyPath, this.requireLazyScriptEntry, this.collectForIntegration);
|
|
106
113
|
}
|
|
107
114
|
/**
|
|
108
115
|
* Preloads SSR-eligible scripts to register custom elements before render.
|
|
@@ -7,3 +7,11 @@ import type { EcoPagesAppConfig } from '../../../types/internal-types.js';
|
|
|
7
7
|
* not share mutable module evaluation state.
|
|
8
8
|
*/
|
|
9
9
|
export declare function createCustomElementServerModuleImporter(appConfig: EcoPagesAppConfig, outdirSegment: string): (filePath: string, registryKey: string) => Promise<unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Imports an `ssr: true` script through the same server-module graph as pages.
|
|
12
|
+
*
|
|
13
|
+
* @remarks A per-registry outdir with `forceBuild` compiles a second copy of
|
|
14
|
+
* Radiant and breaks host SSR. This outdir matches page imports and keeps
|
|
15
|
+
* package specifiers external.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSharedServerModuleImporter(appConfig: EcoPagesAppConfig): (filePath: string) => Promise<unknown>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { getAppModuleLoader } from '../../../services/module-loading/app-server-module-transpiler.service.js';
|
|
3
|
+
import { resolveInternalExecutionDir } from '../../../utils/resolve-work-dir.js';
|
|
2
4
|
/**
|
|
3
5
|
* Imports one registered script through the app server module loader for SSR.
|
|
4
6
|
*
|
|
@@ -20,3 +22,20 @@ export function createCustomElementServerModuleImporter(appConfig, outdirSegment
|
|
|
20
22
|
});
|
|
21
23
|
};
|
|
22
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Imports an `ssr: true` script through the same server-module graph as pages.
|
|
27
|
+
*
|
|
28
|
+
* @remarks A per-registry outdir with `forceBuild` compiles a second copy of
|
|
29
|
+
* Radiant and breaks host SSR. This outdir matches page imports and keeps
|
|
30
|
+
* package specifiers external.
|
|
31
|
+
*/
|
|
32
|
+
export function createSharedServerModuleImporter(appConfig) {
|
|
33
|
+
return async (filePath) => {
|
|
34
|
+
return getAppModuleLoader(appConfig).importModule({
|
|
35
|
+
filePath,
|
|
36
|
+
rootDir: appConfig.rootDir,
|
|
37
|
+
outdir: `${resolveInternalExecutionDir(appConfig)}/.server-modules`,
|
|
38
|
+
externalPackages: true,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|