@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.
- package/README.md +2 -0
- 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/declarations.d.ts +10 -1
- 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/islands/README.md +5 -1
- 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 +3 -2
- 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/document-shell/document-shell-render.service.d.ts +7 -2
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +2 -0
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +3 -2
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +1 -1
- package/src/route-renderer/orchestration/integration-renderer.d.ts +7 -3
- package/src/route-renderer/orchestration/integration-renderer.js +34 -20
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +1 -1
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -2
- 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/orchestration/route-pipeline/route-render-orchestrator.js +3 -2
- package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
- package/src/route-renderer/orchestration/string-markup-renderer.js +2 -1
- 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 +7 -1
- package/src/router/server/route-registry.d.ts +13 -0
- package/src/router/server/route-registry.js +46 -32
- package/src/services/README.md +2 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +6 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +24 -5
- 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/types/internal-types.d.ts +5 -1
- 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
|
@@ -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
|
/**
|
|
@@ -39,5 +39,7 @@ export declare class JsHmrStrategy extends HmrStrategy {
|
|
|
39
39
|
private context;
|
|
40
40
|
constructor(context: JsHmrContext);
|
|
41
41
|
matches(filePath: string): boolean;
|
|
42
|
+
private resolveImpactedEntrypoints;
|
|
43
|
+
private collectDevTransformHmrOutcome;
|
|
42
44
|
process(filePath: string): Promise<HmrAction>;
|
|
43
45
|
}
|
|
@@ -45,16 +45,7 @@ export class JsHmrStrategy extends HmrStrategy {
|
|
|
45
45
|
}
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
appLogger.debug(`[JsHmrStrategy] Processing ${filePath}`);
|
|
50
|
-
const watchedFiles = this.context.getWatchedFiles();
|
|
51
|
-
const resolvedChanged = path.resolve(filePath);
|
|
52
|
-
const registeredEntrypoints = this.context.getRegisteredEntrypoints();
|
|
53
|
-
const isRegisteredEntrypointEdit = isRegisteredDevTransformEntrypoint(registeredEntrypoints, resolvedChanged);
|
|
54
|
-
if (watchedFiles.size === 0) {
|
|
55
|
-
appLogger.debug(`[JsHmrStrategy] No watched files to rebuild`);
|
|
56
|
-
return { type: 'none' };
|
|
57
|
-
}
|
|
48
|
+
resolveImpactedEntrypoints(filePath, watchedFiles, resolvedChanged, isRegisteredEntrypointEdit) {
|
|
58
49
|
const dependencyHits = this.context.getEntrypointDependencyGraph().getDependencyEntrypoints(filePath);
|
|
59
50
|
const hasDependencyHit = dependencyHits.size > 0;
|
|
60
51
|
const impactedEntrypoints = isRegisteredEntrypointEdit
|
|
@@ -63,12 +54,9 @@ export class JsHmrStrategy extends HmrStrategy {
|
|
|
63
54
|
? Array.from(dependencyHits).filter((entrypoint) => watchedFiles.has(path.resolve(entrypoint)))
|
|
64
55
|
: Array.from(watchedFiles.keys());
|
|
65
56
|
const buildableEntrypoints = impactedEntrypoints.filter((entrypoint) => this.context.shouldProcessEntrypoint?.(entrypoint) ?? true);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (buildableEntrypoints.length === 0) {
|
|
70
|
-
return { type: 'none' };
|
|
71
|
-
}
|
|
57
|
+
return { buildableEntrypoints, hasDependencyHit };
|
|
58
|
+
}
|
|
59
|
+
collectDevTransformHmrOutcome(buildableEntrypoints, watchedFiles, registeredEntrypoints) {
|
|
72
60
|
const devTransformUpdates = [];
|
|
73
61
|
let devTransformReloadRequired = false;
|
|
74
62
|
for (const entrypoint of buildableEntrypoints) {
|
|
@@ -91,6 +79,26 @@ export class JsHmrStrategy extends HmrStrategy {
|
|
|
91
79
|
devTransformUpdates.push(outputUrl);
|
|
92
80
|
}
|
|
93
81
|
}
|
|
82
|
+
return { devTransformUpdates, devTransformReloadRequired };
|
|
83
|
+
}
|
|
84
|
+
async process(filePath) {
|
|
85
|
+
appLogger.debug(`[JsHmrStrategy] Processing ${filePath}`);
|
|
86
|
+
const watchedFiles = this.context.getWatchedFiles();
|
|
87
|
+
const resolvedChanged = path.resolve(filePath);
|
|
88
|
+
const registeredEntrypoints = this.context.getRegisteredEntrypoints();
|
|
89
|
+
const isRegisteredEntrypointEdit = isRegisteredDevTransformEntrypoint(registeredEntrypoints, resolvedChanged);
|
|
90
|
+
if (watchedFiles.size === 0) {
|
|
91
|
+
appLogger.debug(`[JsHmrStrategy] No watched files to rebuild`);
|
|
92
|
+
return { type: 'none' };
|
|
93
|
+
}
|
|
94
|
+
const { buildableEntrypoints, hasDependencyHit } = this.resolveImpactedEntrypoints(filePath, watchedFiles, resolvedChanged, isRegisteredEntrypointEdit);
|
|
95
|
+
if (!hasDependencyHit && !isRegisteredEntrypointEdit) {
|
|
96
|
+
appLogger.debug('[JsHmrStrategy] Dependency graph miss, rebuilding all watched entrypoints');
|
|
97
|
+
}
|
|
98
|
+
if (buildableEntrypoints.length === 0) {
|
|
99
|
+
return { type: 'none' };
|
|
100
|
+
}
|
|
101
|
+
const { devTransformUpdates, devTransformReloadRequired } = this.collectDevTransformHmrOutcome(buildableEntrypoints, watchedFiles, registeredEntrypoints);
|
|
94
102
|
if (devTransformReloadRequired) {
|
|
95
103
|
appLogger.debug(`[JsHmrStrategy] Full reload required (no HMR accept found)`);
|
|
96
104
|
return {
|
package/src/islands/README.md
CHANGED
|
@@ -12,7 +12,11 @@ Hydratable component instances stamp a small, integration-agnostic attribute set
|
|
|
12
12
|
| `data-eco-component-key` | Optional module key used by client hydration (React) |
|
|
13
13
|
| `data-eco-props` | Optional base64 JSON props snapshot for hydration |
|
|
14
14
|
|
|
15
|
-
React may
|
|
15
|
+
React integrations may emit `<eco-island>` as the SSR host. The host uses
|
|
16
|
+
`display: contents` so it does not introduce a layout box, while the host and
|
|
17
|
+
its children remain in place as the client calls `hydrateRoot()` on that host.
|
|
18
|
+
React island integrations may add `data-eco-hydrated` after the initial client
|
|
19
|
+
commit for development diagnostics.
|
|
16
20
|
|
|
17
21
|
## Where stamping happens
|
|
18
22
|
|
|
@@ -27,22 +27,9 @@ function isFactory(value) {
|
|
|
27
27
|
function isServerSpecifier(source) {
|
|
28
28
|
return /\.server(?:\.[cm]?[jt]sx?)?$/.test(source);
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
* Indexes local `eco.*()` factory exports and named `export { X } from` re-exports.
|
|
32
|
-
*
|
|
33
|
-
* @remarks
|
|
34
|
-
* `export *` is ignored so a barrel cannot pull an entire kit into the graph.
|
|
35
|
-
*/
|
|
36
|
-
function indexModuleExports(file, cache) {
|
|
37
|
-
const cached = cache.get(file);
|
|
38
|
-
if (cached)
|
|
39
|
-
return cached;
|
|
40
|
-
const source = readFileSync(file, 'utf8');
|
|
41
|
-
const parsed = cachedParseSync(file, source, { sourceType: 'module' });
|
|
42
|
-
const body = nodes(parsed.program.body);
|
|
30
|
+
function collectDeclaredFactoryBindings(body) {
|
|
43
31
|
const declared = new Set();
|
|
44
32
|
const factories = new Set();
|
|
45
|
-
const namedReexports = new Map();
|
|
46
33
|
for (const statement of body) {
|
|
47
34
|
const declaration = statement.type === 'ExportNamedDeclaration' ? node(statement.declaration) : statement;
|
|
48
35
|
for (const variable of nodes(declaration?.declarations)) {
|
|
@@ -56,32 +43,59 @@ function indexModuleExports(file, cache) {
|
|
|
56
43
|
if (statement.type === 'ExportDefaultDeclaration' && isFactory(statement.declaration))
|
|
57
44
|
factories.add('default');
|
|
58
45
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (statement.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type')
|
|
65
|
-
continue;
|
|
66
|
-
const from = node(statement.source)?.value;
|
|
67
|
-
if (typeof from === 'string') {
|
|
68
|
-
for (const specifier of nodes(statement.specifiers)) {
|
|
69
|
-
if (specifier.exportKind === 'type')
|
|
70
|
-
continue;
|
|
71
|
-
const exported = identifierName(specifier.exported);
|
|
72
|
-
const imported = identifierName(specifier.local) ?? exported;
|
|
73
|
-
if (exported && imported)
|
|
74
|
-
namedReexports.set(exported, { source: from, imported });
|
|
75
|
-
}
|
|
46
|
+
return { declared, factories };
|
|
47
|
+
}
|
|
48
|
+
function indexReexportFromSource(from, specifiers, namedReexports) {
|
|
49
|
+
for (const specifier of specifiers) {
|
|
50
|
+
if (specifier.exportKind === 'type')
|
|
76
51
|
continue;
|
|
52
|
+
const exported = identifierName(specifier.exported);
|
|
53
|
+
const imported = identifierName(specifier.local) ?? exported;
|
|
54
|
+
if (exported && imported)
|
|
55
|
+
namedReexports.set(exported, { source: from, imported });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function indexLocalNamedExportSpecifiers(specifiers, declared, factories) {
|
|
59
|
+
for (const specifier of specifiers) {
|
|
60
|
+
if (specifier.exportKind !== 'type' && declared.has(String(identifierName(specifier.local)))) {
|
|
61
|
+
const exported = identifierName(specifier.exported);
|
|
62
|
+
if (exported)
|
|
63
|
+
factories.add(exported);
|
|
77
64
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function indexNamedExportStatement(statement, declared, factories, namedReexports) {
|
|
68
|
+
if (statement.type === 'ExportDefaultDeclaration' && declared.has(String(identifierName(statement.declaration)))) {
|
|
69
|
+
factories.add('default');
|
|
70
|
+
}
|
|
71
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const from = node(statement.source)?.value;
|
|
75
|
+
const specifiers = nodes(statement.specifiers);
|
|
76
|
+
if (typeof from === 'string') {
|
|
77
|
+
indexReexportFromSource(from, specifiers, namedReexports);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
indexLocalNamedExportSpecifiers(specifiers, declared, factories);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Indexes local `eco.*()` factory exports and named `export { X } from` re-exports.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* `export *` is ignored so a barrel cannot pull an entire kit into the graph.
|
|
87
|
+
*/
|
|
88
|
+
function indexModuleExports(file, cache) {
|
|
89
|
+
const cached = cache.get(file);
|
|
90
|
+
if (cached)
|
|
91
|
+
return cached;
|
|
92
|
+
const source = readFileSync(file, 'utf8');
|
|
93
|
+
const parsed = cachedParseSync(file, source, { sourceType: 'module' });
|
|
94
|
+
const body = nodes(parsed.program.body);
|
|
95
|
+
const { declared, factories } = collectDeclaredFactoryBindings(body);
|
|
96
|
+
const namedReexports = new Map();
|
|
97
|
+
for (const statement of body) {
|
|
98
|
+
indexNamedExportStatement(statement, declared, factories, namedReexports);
|
|
85
99
|
}
|
|
86
100
|
const indexed = { factories, namedReexports };
|
|
87
101
|
cache.set(file, indexed);
|
|
@@ -132,6 +146,66 @@ function isFactoryExport(file, exportName, projectRoot, pathPrefixes, state) {
|
|
|
132
146
|
function isCssImport(source) {
|
|
133
147
|
return source.endsWith('.css') && !source.endsWith('.module.css');
|
|
134
148
|
}
|
|
149
|
+
function resolveStylesheetImportPath(source, ownerFile, projectRoot, pathPrefixes) {
|
|
150
|
+
const isRelative = source.startsWith('.');
|
|
151
|
+
const isAlias = matchesTsconfigPathPrefix(source, pathPrefixes);
|
|
152
|
+
if (!isRelative && !isAlias) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
if (isRelative) {
|
|
156
|
+
const candidate = path.resolve(path.dirname(ownerFile), source);
|
|
157
|
+
return existsSync(candidate) ? realpathSync(candidate) : undefined;
|
|
158
|
+
}
|
|
159
|
+
return resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
|
|
160
|
+
}
|
|
161
|
+
function tryRecordSideEffectStylesheetImport(statement, source, ownerFile, projectRoot, pathPrefixes, result) {
|
|
162
|
+
const specifiers = nodes(statement.specifiers);
|
|
163
|
+
if (!isCssImport(source) || specifiers.length > 0) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
const resolved = resolveStylesheetImportPath(source, ownerFile, projectRoot, pathPrefixes);
|
|
167
|
+
if (!resolved) {
|
|
168
|
+
if (source.startsWith('.') || matchesTsconfigPathPrefix(source, pathPrefixes)) {
|
|
169
|
+
throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(source)} from ${ownerFile}`);
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if (!existsSync(resolved)) {
|
|
174
|
+
throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(source)} from ${ownerFile}`);
|
|
175
|
+
}
|
|
176
|
+
result.stylesheets.push(resolved);
|
|
177
|
+
result.removals.push({ start: statement.start, end: statement.end, replacement: '' });
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
function collectFactoryComponentsFromImport(statement, source, ownerFile, projectRoot, pathPrefixes, factoryState, result) {
|
|
181
|
+
const specifiers = nodes(statement.specifiers);
|
|
182
|
+
const values = specifiers.filter((entry) => entry.importKind !== 'type' &&
|
|
183
|
+
(entry.type === 'ImportSpecifier' || entry.type === 'ImportDefaultSpecifier'));
|
|
184
|
+
if (!values.length || (!source.startsWith('.') && !matchesTsconfigPathPrefix(source, pathPrefixes))) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (isServerSpecifier(source)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const resolved = resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
|
|
191
|
+
if (!resolved)
|
|
192
|
+
throw new Error(`[ecopages] Cannot resolve import ${JSON.stringify(source)} from ${ownerFile}`);
|
|
193
|
+
if (!/\.[jt]sx?$/.test(resolved) || resolved.includes(`${path.sep}node_modules${path.sep}`)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
for (const specifier of values) {
|
|
197
|
+
const imported = specifier.type === 'ImportDefaultSpecifier' ? 'default' : identifierName(specifier.imported);
|
|
198
|
+
const local = identifierName(specifier.local);
|
|
199
|
+
if (typeof local === 'string' &&
|
|
200
|
+
imported &&
|
|
201
|
+
isFactoryExport(resolved, imported, projectRoot, pathPrefixes, {
|
|
202
|
+
...factoryState,
|
|
203
|
+
path: new Set(),
|
|
204
|
+
})) {
|
|
205
|
+
result.components.push(local);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
135
209
|
/**
|
|
136
210
|
* Discovers local Eco Component imports and relative or aliased side-effect CSS.
|
|
137
211
|
*
|
|
@@ -147,6 +221,7 @@ export function discoverComponentImports(program, ownerFile, projectRoot) {
|
|
|
147
221
|
moduleIndex: new Map(),
|
|
148
222
|
resolved: new Map(),
|
|
149
223
|
watchFiles: new Set(),
|
|
224
|
+
path: new Set(),
|
|
150
225
|
};
|
|
151
226
|
for (const statement of nodes(node(program)?.body)) {
|
|
152
227
|
if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type')
|
|
@@ -156,47 +231,10 @@ export function discoverComponentImports(program, ownerFile, projectRoot) {
|
|
|
156
231
|
const source = node(statement.source)?.value;
|
|
157
232
|
if (typeof source !== 'string')
|
|
158
233
|
continue;
|
|
159
|
-
|
|
160
|
-
if (isCssImport(source) && !specifiers.length) {
|
|
161
|
-
const isRelative = source.startsWith('.');
|
|
162
|
-
const isAlias = matchesTsconfigPathPrefix(source, pathPrefixes);
|
|
163
|
-
if (isRelative || isAlias) {
|
|
164
|
-
const resolved = isRelative
|
|
165
|
-
? existsSync(path.resolve(path.dirname(ownerFile), source))
|
|
166
|
-
? realpathSync(path.resolve(path.dirname(ownerFile), source))
|
|
167
|
-
: undefined
|
|
168
|
-
: resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
|
|
169
|
-
if (!resolved || !existsSync(resolved)) {
|
|
170
|
-
throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(source)} from ${ownerFile}`);
|
|
171
|
-
}
|
|
172
|
-
result.stylesheets.push(resolved);
|
|
173
|
-
result.removals.push({ start: statement.start, end: statement.end, replacement: '' });
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
const values = specifiers.filter((entry) => entry.importKind !== 'type' &&
|
|
178
|
-
(entry.type === 'ImportSpecifier' || entry.type === 'ImportDefaultSpecifier'));
|
|
179
|
-
if (!values.length || (!source.startsWith('.') && !matchesTsconfigPathPrefix(source, pathPrefixes)))
|
|
180
|
-
continue;
|
|
181
|
-
if (isServerSpecifier(source))
|
|
234
|
+
if (tryRecordSideEffectStylesheetImport(statement, source, ownerFile, projectRoot, pathPrefixes, result)) {
|
|
182
235
|
continue;
|
|
183
|
-
const resolved = resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
|
|
184
|
-
if (!resolved)
|
|
185
|
-
throw new Error(`[ecopages] Cannot resolve import ${JSON.stringify(source)} from ${ownerFile}`);
|
|
186
|
-
if (!/\.[jt]sx?$/.test(resolved) || resolved.includes(`${path.sep}node_modules${path.sep}`))
|
|
187
|
-
continue;
|
|
188
|
-
for (const specifier of values) {
|
|
189
|
-
const imported = specifier.type === 'ImportDefaultSpecifier' ? 'default' : identifierName(specifier.imported);
|
|
190
|
-
const local = identifierName(specifier.local);
|
|
191
|
-
if (typeof local === 'string' &&
|
|
192
|
-
imported &&
|
|
193
|
-
isFactoryExport(resolved, imported, projectRoot, pathPrefixes, {
|
|
194
|
-
...factoryState,
|
|
195
|
-
path: new Set(),
|
|
196
|
-
})) {
|
|
197
|
-
result.components.push(local);
|
|
198
|
-
}
|
|
199
236
|
}
|
|
237
|
+
collectFactoryComponentsFromImport(statement, source, ownerFile, projectRoot, pathPrefixes, factoryState, result);
|
|
200
238
|
}
|
|
201
239
|
result.watchFiles.push(...factoryState.watchFiles);
|
|
202
240
|
return result;
|
|
@@ -135,6 +135,44 @@ export function attributeComponentIdentity(contents, filePath, integration, proj
|
|
|
135
135
|
}
|
|
136
136
|
return addIdentityBindingImport(transformed, cachedParseSync(filePath, transformed, { sourceType: 'module' }).program);
|
|
137
137
|
}
|
|
138
|
+
function findMdxConfigDeclarator(program) {
|
|
139
|
+
for (const statement of nodes(program?.body)) {
|
|
140
|
+
if (statement.type !== 'ExportNamedDeclaration' || !statement.declaration) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const decl = node(statement.declaration);
|
|
144
|
+
if (decl?.type !== 'VariableDeclaration') {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
for (const declarator of nodes(decl.declarations)) {
|
|
148
|
+
if (node(declarator.id)?.name === 'config') {
|
|
149
|
+
return declarator;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
function buildMdxConfigIdentityEdits(options) {
|
|
156
|
+
const edits = [...options.removals];
|
|
157
|
+
const init = options.configDeclarator ? node(options.configDeclarator.init) : undefined;
|
|
158
|
+
if (!init || typeof init.start !== 'number' || typeof init.end !== 'number') {
|
|
159
|
+
return edits;
|
|
160
|
+
}
|
|
161
|
+
edits.push({
|
|
162
|
+
start: init.start,
|
|
163
|
+
end: init.end,
|
|
164
|
+
replacement: `bindComponentIdentity(${options.identityLiteral}, ${options.contents.slice(init.start, init.end)}${options.discoveryArgument})`,
|
|
165
|
+
});
|
|
166
|
+
return edits;
|
|
167
|
+
}
|
|
168
|
+
function buildMdxIdentityAppend(options) {
|
|
169
|
+
let appended = '';
|
|
170
|
+
if (!options.configDeclarator) {
|
|
171
|
+
appended += `\nexport const config = bindComponentIdentity(${options.identityLiteral}, {}${options.discoveryArgument});\n`;
|
|
172
|
+
}
|
|
173
|
+
appended += `attachDiscoveredDependencies(config);\nif (typeof MDXContent === 'function') MDXContent.config = config;\n`;
|
|
174
|
+
return appended;
|
|
175
|
+
}
|
|
138
176
|
/** Attributes compiled MDX module with canonical component identity and discovered dependencies. */
|
|
139
177
|
export function attributeMdxComponentIdentity(contents, filePath, integration, projectRoot) {
|
|
140
178
|
if (!projectRoot) {
|
|
@@ -148,42 +186,21 @@ export function attributeMdxComponentIdentity(contents, filePath, integration, p
|
|
|
148
186
|
catch {
|
|
149
187
|
return contents;
|
|
150
188
|
}
|
|
151
|
-
|
|
152
|
-
for (const statement of nodes(program?.body)) {
|
|
153
|
-
if (statement.type === 'ExportNamedDeclaration' && statement.declaration) {
|
|
154
|
-
const decl = node(statement.declaration);
|
|
155
|
-
if (decl?.type === 'VariableDeclaration') {
|
|
156
|
-
for (const declarator of nodes(decl.declarations)) {
|
|
157
|
-
if (node(declarator.id)?.name === 'config') {
|
|
158
|
-
configDeclarator = declarator;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
189
|
+
const configDeclarator = findMdxConfigDeclarator(program);
|
|
165
190
|
if (configDeclarator && isIdentityBinding(configDeclarator.init)) {
|
|
166
191
|
return contents;
|
|
167
192
|
}
|
|
168
193
|
const discovered = discoverComponentImports(program, filePath, projectRoot);
|
|
169
194
|
const identityLiteral = `{ id: ${JSON.stringify(rapidhash(filePath).toString(36))}, file: ${JSON.stringify(filePath)}, integration: ${JSON.stringify(integration)} }`;
|
|
170
195
|
const discoveryArgument = serializeDiscoveryArgument(discovered);
|
|
171
|
-
const edits =
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
let appended = '';
|
|
183
|
-
if (!configDeclarator) {
|
|
184
|
-
appended += `\nexport const config = bindComponentIdentity(${identityLiteral}, {}${discoveryArgument});\n`;
|
|
185
|
-
}
|
|
186
|
-
appended += `attachDiscoveredDependencies(config);\nif (typeof MDXContent === 'function') MDXContent.config = config;\n`;
|
|
196
|
+
const edits = buildMdxConfigIdentityEdits({
|
|
197
|
+
contents,
|
|
198
|
+
configDeclarator,
|
|
199
|
+
identityLiteral,
|
|
200
|
+
discoveryArgument,
|
|
201
|
+
removals: discovered.removals,
|
|
202
|
+
});
|
|
203
|
+
const appended = buildMdxIdentityAppend({ configDeclarator, identityLiteral, discoveryArgument });
|
|
187
204
|
let transformed = contents;
|
|
188
205
|
for (const edit of edits.sort((left, right) => right.start - left.start)) {
|
|
189
206
|
transformed = `${transformed.slice(0, edit.start)}${edit.replacement}${transformed.slice(edit.end)}`;
|
|
@@ -66,6 +66,7 @@ Domain folders:
|
|
|
66
66
|
- `document-shell/`: shared page/layout/html shell composition, layout prop resolution, and attribute stamping helpers
|
|
67
67
|
- `route-pipeline/`: route preparation, final HTML capture, marker-artifact enforcement
|
|
68
68
|
- `page-browser-graph/`: browser asset graph build, session cache, and injector assets
|
|
69
|
+
- `custom-element-scripts/`: shared `ssr: true` script collection and server preload for custom-element registration
|
|
69
70
|
|
|
70
71
|
**Page Browser Graph session behavior:**
|
|
71
72
|
|
|
@@ -95,12 +96,12 @@ Important:
|
|
|
95
96
|
|
|
96
97
|
- route-level fallback resolution is gone; unresolved artifacts are now a hard failure
|
|
97
98
|
- ownership is declared from canonical component identity, not inferred from final HTML
|
|
98
|
-
- declared page dependencies are resolved from final render inputs and carried to the owning integration;
|
|
99
|
+
- declared page dependencies are resolved from final render inputs and carried as dependency roots to the owning integration; those roots participate in asset, integration, ownership, and renderer-specific lifecycle collection
|
|
99
100
|
- same-integration children stay renderer-local and do not need to pass through a universal transport
|
|
100
101
|
|
|
101
102
|
## Declared Foreign Child Contract
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
Static mixed-integration component configs must declare every possible foreign child in `config.dependencies.components`. Page dependency resolvers can additionally provide request-time component roots when a route loads a component dynamically.
|
|
104
105
|
|
|
105
106
|
`OwnershipValidationService` surfaces missing metadata or unknown integrations during `prepareRenderOptions()` and throws before render execution starts.
|
|
106
107
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Custom element SSR script preload
|
|
2
|
+
|
|
3
|
+
Shared orchestration for `dependencies.scripts` entries marked `ssr: true`.
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
Server evaluation uses `appConfig.runtime.appModuleLoader` via {@link createCustomElementServerModuleImporter} when no {@link createCustomElementSsrPreloadEntrypointResolver} is configured. Lit's main-thread session and Ecopages JSX pass 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.
|
|
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`.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type ScopePreloadState = {
|
|
2
|
+
activeRegistry?: CustomElementRegistry;
|
|
3
|
+
preloadedScripts: Set<string>;
|
|
4
|
+
preloadFailedScripts: Set<string>;
|
|
5
|
+
inFlightImports: Map<string, Promise<void>>;
|
|
6
|
+
};
|
|
7
|
+
export declare function getCustomElementScriptPreloadScopeState(cacheScope: string): ScopePreloadState;
|
|
8
|
+
/**
|
|
9
|
+
* Clears all preload state for one integration scope.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Intended for tests; production invalidation should use {@link invalidateCustomElementScriptPreload}.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resetCustomElementScriptPreloadScope(cacheScope: string): void;
|
|
15
|
+
export declare function invalidateCustomElementScriptPreload(scriptPath: string, cacheScope?: string): void;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const scopeStates = new Map();
|
|
2
|
+
export function getCustomElementScriptPreloadScopeState(cacheScope) {
|
|
3
|
+
let state = scopeStates.get(cacheScope);
|
|
4
|
+
if (!state) {
|
|
5
|
+
state = {
|
|
6
|
+
preloadedScripts: new Set(),
|
|
7
|
+
preloadFailedScripts: new Set(),
|
|
8
|
+
inFlightImports: new Map(),
|
|
9
|
+
};
|
|
10
|
+
scopeStates.set(cacheScope, state);
|
|
11
|
+
}
|
|
12
|
+
return state;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Clears all preload state for one integration scope.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Intended for tests; production invalidation should use {@link invalidateCustomElementScriptPreload}.
|
|
19
|
+
*/
|
|
20
|
+
export function resetCustomElementScriptPreloadScope(cacheScope) {
|
|
21
|
+
scopeStates.delete(cacheScope);
|
|
22
|
+
}
|
|
23
|
+
export function invalidateCustomElementScriptPreload(scriptPath, cacheScope) {
|
|
24
|
+
const scopes = cacheScope ? [cacheScope] : [...scopeStates.keys()];
|
|
25
|
+
for (const scope of scopes) {
|
|
26
|
+
const state = scopeStates.get(scope);
|
|
27
|
+
if (!state) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
state.preloadedScripts.delete(scriptPath);
|
|
31
|
+
state.preloadFailedScripts.delete(scriptPath);
|
|
32
|
+
state.inFlightImports.delete(scriptPath);
|
|
33
|
+
}
|
|
34
|
+
}
|