@ecopages/core 0.2.0-rc.0 → 0.2.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -33
- package/package.json +58 -4
- package/src/adapters/README.md +3 -1
- package/src/adapters/abstract/application-adapter.d.ts +28 -6
- package/src/adapters/abstract/application-adapter.js +58 -5
- package/src/adapters/abstract/segment-path-matcher.js +56 -38
- package/src/adapters/abstract/server-adapter.d.ts +14 -0
- package/src/adapters/abstract/server-adapter.js +10 -0
- package/src/adapters/bun/create-app.d.ts +10 -6
- package/src/adapters/bun/create-app.js +64 -37
- package/src/adapters/bun/server-adapter.d.ts +6 -2
- package/src/adapters/bun/server-adapter.js +14 -1
- package/src/adapters/create-app.d.ts +62 -7
- package/src/adapters/create-app.js +61 -5
- package/src/adapters/node/create-app.d.ts +5 -5
- package/src/adapters/node/create-app.js +18 -5
- package/src/adapters/node/runtime-host.js +9 -4
- package/src/adapters/node/server-adapter.d.ts +5 -1
- package/src/adapters/node/server-adapter.js +16 -1
- package/src/adapters/shared/http/define-api-handler.d.ts +7 -49
- package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
- package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -8
- package/src/adapters/shared/http/fs-server-response-factory.js +5 -30
- package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
- package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
- package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
- package/src/adapters/shared/runtime/application-adapter.js +12 -0
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
- package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
- package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
- package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
- package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
- package/src/adapters/shared/runtime/port-manager.js +14 -45
- package/src/adapters/shared/runtime/server-adapter.d.ts +14 -5
- package/src/adapters/shared/runtime/server-adapter.js +22 -30
- package/src/adapters/shared/runtime/server-route-handler.js +11 -3
- package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
- package/src/adapters/shared/runtime/server-static-builder.js +59 -37
- package/src/build/README.md +5 -1
- package/src/build/cache/server-entry-build-cache.d.ts +24 -1
- package/src/build/cache/server-entry-build-cache.js +125 -8
- package/src/build/contracts/content-virtual-modules.d.ts +3 -1
- package/src/build/contracts/content-virtual-modules.js +8 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +56 -31
- package/src/build/rolldown/rolldown-plugin-bridge.js +25 -21
- package/src/build/rolldown/runtime-build-output-normalizer.js +3 -29
- package/src/build/runtime/build-request-policy.js +1 -1
- package/src/build/server-bundle-publication.d.ts +14 -0
- package/src/build/server-bundle-publication.js +49 -0
- package/src/config/README.md +17 -2
- package/src/config/apply-user-config.d.ts +6 -0
- package/src/config/apply-user-config.js +67 -0
- package/src/config/config-builder.d.ts +10 -1
- package/src/config/config-builder.js +51 -10
- package/src/config/constants.d.ts +4 -0
- package/src/config/constants.js +4 -0
- package/src/config/define-config.d.ts +9 -0
- package/src/config/define-config.js +10 -0
- package/src/config/index.d.ts +5 -0
- package/src/config/index.js +4 -0
- package/src/config/is-finalized-app-config.d.ts +6 -0
- package/src/config/is-finalized-app-config.js +11 -0
- package/src/config/load-eco-config.d.ts +21 -0
- package/src/config/load-eco-config.js +100 -0
- package/src/config/resolve-eco-config-path.d.ts +23 -0
- package/src/config/resolve-eco-config-path.js +47 -0
- package/src/config/server-config-bundle.d.ts +25 -0
- package/src/config/server-config-bundle.js +148 -0
- package/src/config/user-config-types.d.ts +164 -0
- package/src/config/user-config-types.js +1 -0
- package/src/css-imports.d.ts +4 -0
- package/src/declarations.d.ts +11 -5
- package/src/dev/README.md +6 -0
- package/src/dev/development-restart-watch-paths.d.ts +13 -0
- package/src/dev/development-restart-watch-paths.js +37 -0
- package/src/dev/development-restart.d.ts +13 -0
- package/src/dev/development-restart.js +21 -0
- package/src/dev/transform-server/dev-transform-server.d.ts +6 -0
- package/src/dev/transform-server/dev-transform-server.js +16 -5
- package/src/eco/README.md +73 -5
- package/src/eco/component-identity.d.ts +3 -2
- package/src/eco/component-identity.js +5 -2
- package/src/eco/discovered-dependencies.d.ts +45 -0
- package/src/eco/discovered-dependencies.js +87 -0
- package/src/eco/eco.js +6 -0
- package/src/eco/eco.types.d.ts +18 -2
- package/src/eco/lazy-injector-map.js +57 -41
- package/src/eco/page-dependency-contributions.d.ts +19 -0
- package/src/eco/page-dependency-contributions.js +52 -0
- package/src/errors/http-error-page-contract.d.ts +77 -0
- package/src/errors/http-error-page-contract.js +106 -0
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -0
- package/src/hmr/strategies/js-hmr-strategy.js +24 -16
- package/src/index.browser.d.ts +3 -0
- package/src/index.browser.js +3 -0
- package/src/index.d.ts +4 -1
- package/src/index.js +4 -1
- package/src/islands/README.md +5 -1
- package/src/plugins/README.md +10 -2
- package/src/plugins/component-import-discovery.d.ts +19 -0
- package/src/plugins/component-import-discovery.js +241 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +3 -1
- package/src/plugins/eco-component-meta-plugin.js +118 -16
- package/src/plugins/integration-plugin.d.ts +4 -9
- package/src/plugins/processor.d.ts +23 -2
- package/src/plugins/processor.js +25 -0
- package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
- package/src/plugins/tsconfig-import-resolver.js +4 -2
- package/src/route-renderer/GRAPH.md +1 -1
- package/src/route-renderer/README.md +16 -3
- package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
- 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 +80 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +190 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +17 -0
- package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +41 -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/document-shell/layout-shell-props.service.d.ts +13 -1
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +15 -0
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +11 -2
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +10 -2
- package/src/route-renderer/orchestration/integration-renderer.d.ts +11 -5
- package/src/route-renderer/orchestration/integration-renderer.js +42 -29
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.d.ts +2 -5
- package/src/route-renderer/orchestration/ownership-graph/component-graph-collectors.js +2 -68
- 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 +8 -10
- package/src/route-renderer/orchestration/string-markup-renderer.d.ts +1 -1
- package/src/route-renderer/orchestration/string-markup-renderer.js +10 -8
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +6 -2
- package/src/route-renderer/page-loading/component-dependency-collection.js +113 -68
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +41 -28
- package/src/route-renderer/page-loading/file-scoped-dependency-components.d.ts +10 -3
- package/src/route-renderer/page-loading/file-scoped-dependency-components.js +62 -25
- package/src/route-renderer/page-loading/page-dependency-bundling.js +14 -8
- package/src/route-renderer/page-loading/resolved-page-dependencies.d.ts +1 -2
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +8 -7
- package/src/route-renderer/route-renderer.d.ts +9 -0
- package/src/route-renderer/route-renderer.js +18 -0
- 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 +5 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.d.ts +36 -9
- package/src/services/assets/asset-processing-service/browser-runtime-entry-resolution.js +122 -37
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +2 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +13 -2
- package/src/services/assets/asset-processing-service/page-package.js +42 -39
- package/src/services/error-pages/README.md +9 -0
- package/src/services/error-pages/default-error-pages.d.ts +44 -0
- package/src/services/error-pages/default-error-pages.js +207 -0
- package/src/services/error-pages/error-page-renderer.d.ts +58 -0
- package/src/services/error-pages/error-page-renderer.js +146 -0
- package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
- package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
- package/src/services/invalidation/development-invalidation.service.d.ts +7 -1
- package/src/services/invalidation/development-invalidation.service.js +35 -3
- package/src/services/module-loading/README.md +16 -13
- package/src/services/module-loading/app-server-module-transpiler.service.js +2 -0
- package/src/services/module-loading/collection-server-module-build.service.d.ts +1 -0
- package/src/services/module-loading/collection-server-module-build.service.js +5 -2
- package/src/services/module-loading/page-module-import.service.d.ts +8 -0
- package/src/services/module-loading/page-module-import.service.js +62 -28
- package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
- package/src/services/module-loading/view-module-loader.d.ts +10 -0
- package/src/services/module-loading/view-module-loader.js +46 -0
- 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/README.md +6 -1
- package/src/static-site-generator/static-site-generator.d.ts +7 -2
- package/src/static-site-generator/static-site-generator.js +90 -49
- package/src/types/internal-types.d.ts +6 -1
- package/src/types/public-types.d.ts +34 -24
- package/src/utils/parse-cli-args.js +29 -22
- package/src/watchers/project-watcher.d.ts +14 -1
- package/src/watchers/project-watcher.js +85 -34
- /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
package/src/plugins/README.md
CHANGED
|
@@ -16,10 +16,12 @@ These contracts are responsible for:
|
|
|
16
16
|
## Main Files
|
|
17
17
|
|
|
18
18
|
- `integration-plugin.ts`: framework-semantics contract for render integrations
|
|
19
|
-
- `
|
|
19
|
+
- `define-integration.ts`: typed factory for integrations that only need declarative config and a renderer class
|
|
20
|
+
- `processor.ts`: asset-transformation contract for processors, including generated `@types` package helpers for virtual modules
|
|
20
21
|
- `runtime-capability.ts`: runtime compatibility declaration types
|
|
21
22
|
- `source-transform.ts`: bundler-neutral source-transform primitive with Ecopages adapters plus app-level Vite plugin composition helpers
|
|
22
|
-
- `
|
|
23
|
+
- `component-import-discovery.ts`: resolves direct local factory exports, named `export { X } from` barrels (imported binding only), relative CSS imports, and aliased CSS imports; records successful named re-export hops as watch files; excludes `export *`, type imports, package imports, and ordinary helpers.
|
|
24
|
+
- `eco-component-meta-plugin.ts`: component-identity attribution transform for `eco.*()` factories and `attributeMdxComponentIdentity` for compiled MDX modules
|
|
23
25
|
|
|
24
26
|
## Ownership Rules
|
|
25
27
|
|
|
@@ -27,6 +29,7 @@ These contracts are responsible for:
|
|
|
27
29
|
- Processors own asset semantics, cache ownership, and processor-specific watch behavior.
|
|
28
30
|
- Core owns lifecycle ordering, startup orchestration, and manifest assembly.
|
|
29
31
|
- The transform wraps native `eco.page()`, `eco.component()`, `eco.layout()`, and `eco.html()` factory options with `bindComponentIdentity()`. Factories retain the resulting `options.identity` on `config`, and runtime consumers read it through `getComponentIdentity()`. Browser, HMR, and server builds use the same source transform, so ownership and dependency diagnostics retain stable file attribution without a loader duplicate.
|
|
32
|
+
- MDX modules compiled by `@ecopages/mdx/core` use `attributeMdxComponentIdentity()` to strip bare CSS imports, attach live component accessors to `config.dependencies`, keep inferred stylesheets on identity, and assign `MDXContent.config = config`. The loader requires `projectRoot` from app config. Markdown code blocks and dynamic imports within functions are distinguished and left unaffected.
|
|
30
33
|
|
|
31
34
|
## Lifecycle Summary
|
|
32
35
|
|
|
@@ -34,3 +37,8 @@ These contracts are responsible for:
|
|
|
34
37
|
2. Core seals the app-owned build manifest.
|
|
35
38
|
3. Runtime startup calls runtime-only setup hooks.
|
|
36
39
|
4. Request-time rendering and development invalidation reuse those finalized contracts.
|
|
40
|
+
5. `DevelopmentInvalidationService.invalidateServerModules()` calls `Processor.invalidateServerArtifacts()` so processors can discard compiled server artifacts that are not part of the route-module graph.
|
|
41
|
+
|
|
42
|
+
## Discovered dependency metadata
|
|
43
|
+
|
|
44
|
+
The identity transform passes a deferred Component accessor and resolved stylesheet paths to `bindComponentIdentity`. Factories attach the deferred Component accessor to `config.dependencies`; inferred stylesheets stay keyed by identity for the collector. Import bindings are read during graph traversal, after module initialization. Supported relative and aliased CSS imports are removed from all transformed outputs so the asset pipeline owns CSS delivery. Explicit styles override discovery. Discovery follows named `export { X } from` barrels for the imported binding only. Successful named re-export hops are recorded as watch files on the discovering identity so a barrel retarget invalidates HTML and Page Browser Graph caches without editing the importing Page. It does not follow `export *`, dynamic imports, namespace imports, package Components/CSS, CSS Modules, or custom import attributes. The transform uses the same discovery rules in Bun and Vite/Rolldown. Imported source changes are reparsed through the content-keyed parser cache.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type DiscoveredImports = {
|
|
2
|
+
components: string[];
|
|
3
|
+
stylesheets: string[];
|
|
4
|
+
watchFiles: string[];
|
|
5
|
+
removals: Array<{
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
replacement: string;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Discovers local Eco Component imports and relative or aliased side-effect CSS.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Named `export { X } from` barrels are followed for the imported binding only.
|
|
16
|
+
* Successful re-export hops are recorded in `watchFiles` so barrel edits invalidate caches.
|
|
17
|
+
* `export *`, dynamic imports, namespace imports, packages, and `.server` modules are not.
|
|
18
|
+
*/
|
|
19
|
+
export declare function discoverComponentImports(program: unknown, ownerFile: string, projectRoot: string): DiscoveredImports;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { cachedParseSync } from '../cache/module-parse-cache.js';
|
|
4
|
+
import { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix, resolveProjectModulePath, } from './tsconfig-import-resolver.js';
|
|
5
|
+
function node(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null ? value : undefined;
|
|
7
|
+
}
|
|
8
|
+
function nodes(value) {
|
|
9
|
+
return Array.isArray(value) ? value.map(node).filter((value) => value !== undefined) : [];
|
|
10
|
+
}
|
|
11
|
+
function identifierName(value) {
|
|
12
|
+
const named = node(value);
|
|
13
|
+
if (typeof named?.name === 'string')
|
|
14
|
+
return named.name;
|
|
15
|
+
if (typeof named?.value === 'string')
|
|
16
|
+
return named.value;
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
function isFactory(value) {
|
|
20
|
+
const call = node(value);
|
|
21
|
+
const callee = node(call?.callee);
|
|
22
|
+
return (call?.type === 'CallExpression' &&
|
|
23
|
+
callee?.type === 'MemberExpression' &&
|
|
24
|
+
node(callee.object)?.name === 'eco' &&
|
|
25
|
+
['component', 'layout', 'html'].includes(String(node(callee.property)?.name)));
|
|
26
|
+
}
|
|
27
|
+
function isServerSpecifier(source) {
|
|
28
|
+
return /\.server(?:\.[cm]?[jt]sx?)?$/.test(source);
|
|
29
|
+
}
|
|
30
|
+
function collectDeclaredFactoryBindings(body) {
|
|
31
|
+
const declared = new Set();
|
|
32
|
+
const factories = new Set();
|
|
33
|
+
for (const statement of body) {
|
|
34
|
+
const declaration = statement.type === 'ExportNamedDeclaration' ? node(statement.declaration) : statement;
|
|
35
|
+
for (const variable of nodes(declaration?.declarations)) {
|
|
36
|
+
const name = identifierName(variable.id);
|
|
37
|
+
if (typeof name === 'string' && isFactory(variable.init)) {
|
|
38
|
+
declared.add(name);
|
|
39
|
+
if (statement.type === 'ExportNamedDeclaration')
|
|
40
|
+
factories.add(name);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (statement.type === 'ExportDefaultDeclaration' && isFactory(statement.declaration))
|
|
44
|
+
factories.add('default');
|
|
45
|
+
}
|
|
46
|
+
return { declared, factories };
|
|
47
|
+
}
|
|
48
|
+
function indexReexportFromSource(from, specifiers, namedReexports) {
|
|
49
|
+
for (const specifier of specifiers) {
|
|
50
|
+
if (specifier.exportKind === 'type')
|
|
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);
|
|
64
|
+
}
|
|
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);
|
|
99
|
+
}
|
|
100
|
+
const indexed = { factories, namedReexports };
|
|
101
|
+
cache.set(file, indexed);
|
|
102
|
+
return indexed;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* True when `exportName` is an `eco.*()` factory, including through named barrel re-exports.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* Completed answers are memoized on `resolved`. `path` is only the current walk, so a
|
|
109
|
+
* second alias of the same Component is not treated as a cycle miss.
|
|
110
|
+
*/
|
|
111
|
+
function isFactoryExport(file, exportName, projectRoot, pathPrefixes, state) {
|
|
112
|
+
const visitKey = `${file}\0${exportName}`;
|
|
113
|
+
const known = state.resolved.get(visitKey);
|
|
114
|
+
if (known !== undefined)
|
|
115
|
+
return known;
|
|
116
|
+
if (state.path.has(visitKey))
|
|
117
|
+
return false;
|
|
118
|
+
state.path.add(visitKey);
|
|
119
|
+
let result = false;
|
|
120
|
+
if (!file.includes(`${path.sep}node_modules${path.sep}`) && !isServerSpecifier(file)) {
|
|
121
|
+
const { factories, namedReexports } = indexModuleExports(file, state.moduleIndex);
|
|
122
|
+
if (factories.has(exportName)) {
|
|
123
|
+
result = true;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const reexport = namedReexports.get(exportName);
|
|
127
|
+
if (reexport &&
|
|
128
|
+
!isServerSpecifier(reexport.source) &&
|
|
129
|
+
(reexport.source.startsWith('.') || matchesTsconfigPathPrefix(reexport.source, pathPrefixes))) {
|
|
130
|
+
const resolved = resolveProjectModulePath(projectRoot, file, reexport.source, { preserveBarrel: true });
|
|
131
|
+
if (!resolved) {
|
|
132
|
+
throw new Error(`[ecopages] Cannot resolve import ${JSON.stringify(reexport.source)} from ${file}`);
|
|
133
|
+
}
|
|
134
|
+
if (/\.[jt]sx?$/.test(resolved) && !resolved.includes(`${path.sep}node_modules${path.sep}`)) {
|
|
135
|
+
result = isFactoryExport(resolved, reexport.imported, projectRoot, pathPrefixes, state);
|
|
136
|
+
if (result)
|
|
137
|
+
state.watchFiles.add(file);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
state.path.delete(visitKey);
|
|
143
|
+
state.resolved.set(visitKey, result);
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
function isCssImport(source) {
|
|
147
|
+
return source.endsWith('.css') && !source.endsWith('.module.css');
|
|
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
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Discovers local Eco Component imports and relative or aliased side-effect CSS.
|
|
211
|
+
*
|
|
212
|
+
* @remarks
|
|
213
|
+
* Named `export { X } from` barrels are followed for the imported binding only.
|
|
214
|
+
* Successful re-export hops are recorded in `watchFiles` so barrel edits invalidate caches.
|
|
215
|
+
* `export *`, dynamic imports, namespace imports, packages, and `.server` modules are not.
|
|
216
|
+
*/
|
|
217
|
+
export function discoverComponentImports(program, ownerFile, projectRoot) {
|
|
218
|
+
const result = { components: [], stylesheets: [], watchFiles: [], removals: [] };
|
|
219
|
+
const pathPrefixes = loadTsconfigPathPrefixes(projectRoot);
|
|
220
|
+
const factoryState = {
|
|
221
|
+
moduleIndex: new Map(),
|
|
222
|
+
resolved: new Map(),
|
|
223
|
+
watchFiles: new Set(),
|
|
224
|
+
path: new Set(),
|
|
225
|
+
};
|
|
226
|
+
for (const statement of nodes(node(program)?.body)) {
|
|
227
|
+
if (statement.type !== 'ImportDeclaration' || statement.importKind === 'type')
|
|
228
|
+
continue;
|
|
229
|
+
if (nodes(statement.attributes).length || nodes(statement.assertions).length)
|
|
230
|
+
continue;
|
|
231
|
+
const source = node(statement.source)?.value;
|
|
232
|
+
if (typeof source !== 'string')
|
|
233
|
+
continue;
|
|
234
|
+
if (tryRecordSideEffectStylesheetImport(statement, source, ownerFile, projectRoot, pathPrefixes, result)) {
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
collectFactoryComponentsFromImport(statement, source, ownerFile, projectRoot, pathPrefixes, factoryState, result);
|
|
238
|
+
}
|
|
239
|
+
result.watchFiles.push(...factoryState.watchFiles);
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
@@ -5,7 +5,9 @@ export interface EcoComponentDirPluginOptions {
|
|
|
5
5
|
config: EcoPagesAppConfig;
|
|
6
6
|
}
|
|
7
7
|
/** Attributes real `eco.*()` factory calls with canonical component identity. */
|
|
8
|
-
export declare function attributeComponentIdentity(contents: string, filePath: string, integration: string): string;
|
|
8
|
+
export declare function attributeComponentIdentity(contents: string, filePath: string, integration: string, projectRoot?: string): string;
|
|
9
|
+
/** Attributes compiled MDX module with canonical component identity and discovered dependencies. */
|
|
10
|
+
export declare function attributeMdxComponentIdentity(contents: string, filePath: string, integration: string, projectRoot: string): string;
|
|
9
11
|
export declare function createEcoComponentMetaTransform(options: EcoComponentDirPluginOptions): EcoSourceTransform;
|
|
10
12
|
export declare function createEcoComponentMetaVitePlugin(options: EcoComponentDirPluginOptions): EcoViteCompatiblePlugin;
|
|
11
13
|
export declare function createEcoComponentMetaPlugin(options: EcoComponentDirPluginOptions): EcoBuildPlugin;
|
|
@@ -2,6 +2,7 @@ import { prependJsxImportSourceIfMissing } from './jsx-import-source.utils.js';
|
|
|
2
2
|
import { createEcoBuildPluginFromSourceTransform, createVitePluginFromSourceTransform } from './source-transform.js';
|
|
3
3
|
import { cachedParseSync } from '../cache/module-parse-cache.js';
|
|
4
4
|
import { rapidhash } from '../utils/hash.js';
|
|
5
|
+
import { discoverComponentImports } from './component-import-discovery.js';
|
|
5
6
|
function integrationForFile(filePath, config) {
|
|
6
7
|
const candidates = config.integrations
|
|
7
8
|
.flatMap((integration) => integration.extensions.map((extension) => [extension, integration]))
|
|
@@ -12,6 +13,12 @@ function integrationForFile(filePath, config) {
|
|
|
12
13
|
function isAstNode(value) {
|
|
13
14
|
return typeof value === 'object' && value !== null;
|
|
14
15
|
}
|
|
16
|
+
function node(value) {
|
|
17
|
+
return typeof value === 'object' && value !== null ? value : undefined;
|
|
18
|
+
}
|
|
19
|
+
function nodes(value) {
|
|
20
|
+
return Array.isArray(value) ? value.map(node).filter((value) => value !== undefined) : [];
|
|
21
|
+
}
|
|
15
22
|
function isEcoFactoryCall(node) {
|
|
16
23
|
if (node.type !== 'CallExpression' || !isAstNode(node.callee))
|
|
17
24
|
return false;
|
|
@@ -41,36 +48,52 @@ function walkAst(node, visit) {
|
|
|
41
48
|
for (const value of Object.values(node))
|
|
42
49
|
walkAst(value, visit);
|
|
43
50
|
}
|
|
44
|
-
function
|
|
51
|
+
function addNamedImport(contents, program, sourceModule, importedName) {
|
|
52
|
+
const importedNames = typeof importedName === 'string' ? [importedName] : [...importedName];
|
|
45
53
|
const imports = program.body.filter((node) => isAstNode(node) &&
|
|
46
54
|
node.type === 'ImportDeclaration' &&
|
|
47
55
|
isAstNode(node.source) &&
|
|
48
|
-
node.source.value ===
|
|
56
|
+
node.source.value === sourceModule);
|
|
49
57
|
const valueImport = imports.find((node) => node.importKind !== 'type');
|
|
50
58
|
if (!valueImport)
|
|
51
|
-
return `import {
|
|
59
|
+
return `import { ${importedNames.join(', ')} } from '${sourceModule}';\n${contents}`;
|
|
52
60
|
const specifiers = Array.isArray(valueImport.specifiers) ? valueImport.specifiers.filter(isAstNode) : [];
|
|
53
|
-
|
|
54
|
-
isAstNode(specifier.imported)
|
|
55
|
-
|
|
61
|
+
const existingNames = new Set(specifiers.flatMap((specifier) => {
|
|
62
|
+
if (specifier.type !== 'ImportSpecifier' || !isAstNode(specifier.imported))
|
|
63
|
+
return [];
|
|
64
|
+
const name = specifier.imported.name ?? specifier.imported.value;
|
|
65
|
+
return typeof name === 'string' ? [name] : [];
|
|
66
|
+
}));
|
|
67
|
+
const missing = importedNames.filter((name) => !existingNames.has(name));
|
|
68
|
+
if (missing.length === 0) {
|
|
56
69
|
return contents;
|
|
57
70
|
}
|
|
58
71
|
const namedSpecifiers = specifiers.filter((specifier) => specifier.type === 'ImportSpecifier');
|
|
59
72
|
if (namedSpecifiers.length > 0) {
|
|
60
73
|
const lastSpecifier = namedSpecifiers[namedSpecifiers.length - 1];
|
|
61
|
-
return `${contents.slice(0, lastSpecifier.end)},
|
|
74
|
+
return `${contents.slice(0, lastSpecifier.end)}, ${missing.join(', ')}${contents.slice(lastSpecifier.end)}`;
|
|
62
75
|
}
|
|
63
76
|
if (specifiers.some((specifier) => specifier.type === 'ImportNamespaceSpecifier')) {
|
|
64
|
-
return `import {
|
|
77
|
+
return `import { ${missing.join(', ')} } from '${sourceModule}';\n${contents}`;
|
|
65
78
|
}
|
|
66
79
|
const defaultSpecifier = specifiers.find((specifier) => specifier.type === 'ImportDefaultSpecifier');
|
|
67
80
|
if (defaultSpecifier) {
|
|
68
|
-
return `${contents.slice(0, defaultSpecifier.end)}, {
|
|
81
|
+
return `${contents.slice(0, defaultSpecifier.end)}, { ${missing.join(', ')} }${contents.slice(defaultSpecifier.end)}`;
|
|
69
82
|
}
|
|
70
|
-
return `import {
|
|
83
|
+
return `import { ${missing.join(', ')} } from '${sourceModule}';\n${contents}`;
|
|
84
|
+
}
|
|
85
|
+
function addIdentityBindingImport(contents, program) {
|
|
86
|
+
return addNamedImport(contents, program, '@ecopages/core', 'bindComponentIdentity');
|
|
87
|
+
}
|
|
88
|
+
function serializeDiscoveryArgument(discovered) {
|
|
89
|
+
if (!discovered || (discovered.components.length === 0 && discovered.stylesheets.length === 0)) {
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
const watchFiles = discovered.watchFiles.length > 0 ? `, watchFiles: ${JSON.stringify(discovered.watchFiles)}` : '';
|
|
93
|
+
return `, { components: () => [${discovered.components.join(', ')}], stylesheets: ${JSON.stringify(discovered.stylesheets)}${watchFiles} }`;
|
|
71
94
|
}
|
|
72
95
|
/** Attributes real `eco.*()` factory calls with canonical component identity. */
|
|
73
|
-
export function attributeComponentIdentity(contents, filePath, integration) {
|
|
96
|
+
export function attributeComponentIdentity(contents, filePath, integration, projectRoot) {
|
|
74
97
|
if (!contents.includes('eco.'))
|
|
75
98
|
return contents;
|
|
76
99
|
let program;
|
|
@@ -82,6 +105,13 @@ export function attributeComponentIdentity(contents, filePath, integration) {
|
|
|
82
105
|
}
|
|
83
106
|
const identityLiteral = `{ id: ${JSON.stringify(rapidhash(filePath).toString(36))}, file: ${JSON.stringify(filePath)}, integration: ${JSON.stringify(integration)} }`;
|
|
84
107
|
const edits = [];
|
|
108
|
+
let hasFactory = false;
|
|
109
|
+
walkAst(program, (node) => {
|
|
110
|
+
if (isEcoFactoryCall(node))
|
|
111
|
+
hasFactory = true;
|
|
112
|
+
});
|
|
113
|
+
const discovered = hasFactory && projectRoot ? discoverComponentImports(program, filePath, projectRoot) : undefined;
|
|
114
|
+
const discoveryArgument = serializeDiscoveryArgument(discovered);
|
|
85
115
|
walkAst(program, (node) => {
|
|
86
116
|
if (!isEcoFactoryCall(node) || !Array.isArray(node.arguments))
|
|
87
117
|
return;
|
|
@@ -93,16 +123,90 @@ export function attributeComponentIdentity(contents, filePath, integration) {
|
|
|
93
123
|
edits.push({
|
|
94
124
|
start: firstArgument.start,
|
|
95
125
|
end: firstArgument.end,
|
|
96
|
-
replacement: `bindComponentIdentity(${identityLiteral}, ${contents.slice(firstArgument.start, firstArgument.end)})`,
|
|
126
|
+
replacement: `bindComponentIdentity(${identityLiteral}, ${contents.slice(firstArgument.start, firstArgument.end)}${discoveryArgument})`,
|
|
97
127
|
});
|
|
98
128
|
});
|
|
99
129
|
if (edits.length === 0)
|
|
100
130
|
return contents;
|
|
131
|
+
edits.push(...(discovered?.removals ?? []));
|
|
132
|
+
let transformed = contents;
|
|
133
|
+
for (const edit of edits.sort((left, right) => right.start - left.start)) {
|
|
134
|
+
transformed = `${transformed.slice(0, edit.start)}${edit.replacement}${transformed.slice(edit.end)}`;
|
|
135
|
+
}
|
|
136
|
+
return addIdentityBindingImport(transformed, cachedParseSync(filePath, transformed, { sourceType: 'module' }).program);
|
|
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
|
+
}
|
|
176
|
+
/** Attributes compiled MDX module with canonical component identity and discovered dependencies. */
|
|
177
|
+
export function attributeMdxComponentIdentity(contents, filePath, integration, projectRoot) {
|
|
178
|
+
if (!projectRoot) {
|
|
179
|
+
throw new Error(`[ecopages] Cannot process MDX dependencies for "${filePath}": projectRoot is required.`);
|
|
180
|
+
}
|
|
181
|
+
let program;
|
|
182
|
+
try {
|
|
183
|
+
program = cachedParseSync(filePath, contents, { lang: 'jsx', sourceType: 'module' })
|
|
184
|
+
.program;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return contents;
|
|
188
|
+
}
|
|
189
|
+
const configDeclarator = findMdxConfigDeclarator(program);
|
|
190
|
+
if (configDeclarator && isIdentityBinding(configDeclarator.init)) {
|
|
191
|
+
return contents;
|
|
192
|
+
}
|
|
193
|
+
const discovered = discoverComponentImports(program, filePath, projectRoot);
|
|
194
|
+
const identityLiteral = `{ id: ${JSON.stringify(rapidhash(filePath).toString(36))}, file: ${JSON.stringify(filePath)}, integration: ${JSON.stringify(integration)} }`;
|
|
195
|
+
const discoveryArgument = serializeDiscoveryArgument(discovered);
|
|
196
|
+
const edits = buildMdxConfigIdentityEdits({
|
|
197
|
+
contents,
|
|
198
|
+
configDeclarator,
|
|
199
|
+
identityLiteral,
|
|
200
|
+
discoveryArgument,
|
|
201
|
+
removals: discovered.removals,
|
|
202
|
+
});
|
|
203
|
+
const appended = buildMdxIdentityAppend({ configDeclarator, identityLiteral, discoveryArgument });
|
|
101
204
|
let transformed = contents;
|
|
102
205
|
for (const edit of edits.sort((left, right) => right.start - left.start)) {
|
|
103
206
|
transformed = `${transformed.slice(0, edit.start)}${edit.replacement}${transformed.slice(edit.end)}`;
|
|
104
207
|
}
|
|
105
|
-
|
|
208
|
+
transformed = `${transformed}\n${appended}`;
|
|
209
|
+
return addNamedImport(transformed, cachedParseSync(filePath, transformed, { lang: 'jsx', sourceType: 'module' }).program, '@ecopages/core', ['bindComponentIdentity', 'attachDiscoveredDependencies']);
|
|
106
210
|
}
|
|
107
211
|
export function createEcoComponentMetaTransform(options) {
|
|
108
212
|
const extensions = options.config.integrations
|
|
@@ -115,14 +219,12 @@ export function createEcoComponentMetaTransform(options) {
|
|
|
115
219
|
enforce: 'pre',
|
|
116
220
|
filter,
|
|
117
221
|
transform(code, id) {
|
|
118
|
-
if (id.endsWith('.mdx'))
|
|
119
|
-
return { code };
|
|
120
222
|
const integration = integrationForFile(id, options.config);
|
|
121
223
|
if (!integration) {
|
|
122
224
|
return { code };
|
|
123
225
|
}
|
|
124
226
|
return {
|
|
125
|
-
code: prependJsxImportSourceIfMissing(attributeComponentIdentity(code, id, integration.name), integration.jsxImportSource),
|
|
227
|
+
code: prependJsxImportSourceIfMissing(attributeComponentIdentity(code, id, integration.name, options.config.rootDir), integration.jsxImportSource),
|
|
126
228
|
};
|
|
127
229
|
},
|
|
128
230
|
};
|
|
@@ -64,13 +64,14 @@ export interface IntegrationPluginConfig {
|
|
|
64
64
|
*/
|
|
65
65
|
jsxImportSource?: string;
|
|
66
66
|
}
|
|
67
|
-
type
|
|
67
|
+
type IntegrationRendererConstructorOptions = {
|
|
68
68
|
appConfig: EcoPagesAppConfig;
|
|
69
69
|
assetProcessingService: AssetProcessingService;
|
|
70
70
|
resolvedIntegrationDependencies: ProcessedAsset[];
|
|
71
71
|
rendererModules?: unknown;
|
|
72
72
|
runtimeOrigin: string;
|
|
73
|
-
}
|
|
73
|
+
};
|
|
74
|
+
type RendererClass<C> = new (options: IntegrationRendererConstructorOptions) => IntegrationRenderer<C>;
|
|
74
75
|
/**
|
|
75
76
|
* Base class for framework integrations.
|
|
76
77
|
*
|
|
@@ -186,13 +187,7 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
|
|
|
186
187
|
*/
|
|
187
188
|
protected createRendererOptions(options?: {
|
|
188
189
|
rendererModules?: unknown;
|
|
189
|
-
}):
|
|
190
|
-
appConfig: EcoPagesAppConfig;
|
|
191
|
-
assetProcessingService: AssetProcessingService;
|
|
192
|
-
resolvedIntegrationDependencies: ProcessedAsset[];
|
|
193
|
-
rendererModules: unknown;
|
|
194
|
-
runtimeOrigin: string;
|
|
195
|
-
};
|
|
190
|
+
}): IntegrationRendererConstructorOptions;
|
|
196
191
|
/**
|
|
197
192
|
* Attaches runtime-only services after a renderer instance has been created.
|
|
198
193
|
*/
|
|
@@ -13,6 +13,19 @@ export declare function resolveGeneratedPath(type: keyof typeof GENERATED_BASE_P
|
|
|
13
13
|
module: string;
|
|
14
14
|
subPath?: string;
|
|
15
15
|
}): string;
|
|
16
|
+
/**
|
|
17
|
+
* Serializes the TypeScript `@types` package manifest for generated virtual-module declarations.
|
|
18
|
+
*/
|
|
19
|
+
export declare function serializeGeneratedTypesPackage(packageName: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Writes the generated `@types` package manifest that TypeScript auto-loads from `node_modules`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function writeGeneratedTypesPackage(options: {
|
|
24
|
+
root: string;
|
|
25
|
+
module: string;
|
|
26
|
+
packageName: string;
|
|
27
|
+
writeFile: (filePath: string, content: string) => void;
|
|
28
|
+
}): void;
|
|
16
29
|
export interface ProcessorWatchContext {
|
|
17
30
|
path: string;
|
|
18
31
|
bridge: IClientBridge;
|
|
@@ -49,7 +62,7 @@ export interface ProcessorAssetCapability {
|
|
|
49
62
|
*/
|
|
50
63
|
extensions?: ProcessorExtensionPattern[];
|
|
51
64
|
}
|
|
52
|
-
export interface ProcessorConfig<TOptions =
|
|
65
|
+
export interface ProcessorConfig<TOptions = unknown> {
|
|
53
66
|
name: string;
|
|
54
67
|
description?: string;
|
|
55
68
|
options?: TOptions;
|
|
@@ -64,6 +77,10 @@ export interface ProcessorContext {
|
|
|
64
77
|
distDir: string;
|
|
65
78
|
cache?: string;
|
|
66
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Unconstrained processor type for heterogeneous processor collections.
|
|
82
|
+
*/
|
|
83
|
+
export type AnyProcessor = Processor<unknown>;
|
|
67
84
|
/**
|
|
68
85
|
* Base class for content and asset processors that contribute build plugins.
|
|
69
86
|
*
|
|
@@ -77,7 +94,7 @@ export interface ProcessorContext {
|
|
|
77
94
|
* Virtual modules that must resolve during route-module transpile belong in
|
|
78
95
|
* `plugins`. Browser-only bundler hooks belong in `buildPlugins`.
|
|
79
96
|
*/
|
|
80
|
-
export declare abstract class Processor<TOptions =
|
|
97
|
+
export declare abstract class Processor<TOptions = unknown> {
|
|
81
98
|
readonly name: string;
|
|
82
99
|
protected context?: ProcessorContext;
|
|
83
100
|
protected options?: TOptions;
|
|
@@ -134,6 +151,10 @@ export declare abstract class Processor<TOptions = Record<string, unknown>> {
|
|
|
134
151
|
didChange(): boolean;
|
|
135
152
|
abstract setup(): Promise<void>;
|
|
136
153
|
abstract process(input: unknown, filePath?: string): Promise<unknown>;
|
|
154
|
+
/**
|
|
155
|
+
* Discards cached server build artifacts when server modules are invalidated.
|
|
156
|
+
*/
|
|
157
|
+
invalidateServerArtifacts(): void;
|
|
137
158
|
/**
|
|
138
159
|
* Releases runtime resources owned by the processor.
|
|
139
160
|
*
|
package/src/plugins/processor.js
CHANGED
|
@@ -14,6 +14,27 @@ export function resolveGeneratedPath(type, options) {
|
|
|
14
14
|
const parts = [root, GENERATED_BASE_PATHS[type], module, subPath].filter(Boolean);
|
|
15
15
|
return path.join(...parts);
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Serializes the TypeScript `@types` package manifest for generated virtual-module declarations.
|
|
19
|
+
*/
|
|
20
|
+
export function serializeGeneratedTypesPackage(packageName) {
|
|
21
|
+
return `${JSON.stringify({
|
|
22
|
+
name: packageName,
|
|
23
|
+
version: '0.0.0',
|
|
24
|
+
types: './index.d.js',
|
|
25
|
+
}, null, 2)}\n`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Writes the generated `@types` package manifest that TypeScript auto-loads from `node_modules`.
|
|
29
|
+
*/
|
|
30
|
+
export function writeGeneratedTypesPackage(options) {
|
|
31
|
+
const packageManifestPath = resolveGeneratedPath('types', {
|
|
32
|
+
root: options.root,
|
|
33
|
+
module: options.module,
|
|
34
|
+
subPath: 'package.json',
|
|
35
|
+
});
|
|
36
|
+
options.writeFile(packageManifestPath, serializeGeneratedTypesPackage(options.packageName));
|
|
37
|
+
}
|
|
17
38
|
/**
|
|
18
39
|
* Base class for content and asset processors that contribute build plugins.
|
|
19
40
|
*
|
|
@@ -87,6 +108,10 @@ export class Processor {
|
|
|
87
108
|
didChange() {
|
|
88
109
|
return false;
|
|
89
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Discards cached server build artifacts when server modules are invalidated.
|
|
113
|
+
*/
|
|
114
|
+
invalidateServerArtifacts() { }
|
|
90
115
|
/**
|
|
91
116
|
* Releases runtime resources owned by the processor.
|
|
92
117
|
*
|
|
@@ -30,7 +30,9 @@ export declare function resolveRelativeModulePath(fromFile: string, specifier: s
|
|
|
30
30
|
/**
|
|
31
31
|
* Resolves a relative or tsconfig path alias import (via oxc-resolver).
|
|
32
32
|
*/
|
|
33
|
-
export declare function resolveProjectModulePath(projectRoot: string, fromFile: string, specifier: string
|
|
33
|
+
export declare function resolveProjectModulePath(projectRoot: string, fromFile: string, specifier: string, options?: {
|
|
34
|
+
preserveBarrel?: boolean;
|
|
35
|
+
}): string | undefined;
|
|
34
36
|
/**
|
|
35
37
|
* Resolves a TS path alias import using the app's tsconfig `paths` (via oxc-resolver).
|
|
36
38
|
*/
|