@ecopages/core 0.8.0 → 0.10.0
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 -2
- package/package.json +14 -4
- package/src/adapters/node/create-app.d.ts +5 -5
- package/src/adapters/node/create-app.js +1 -1
- package/src/adapters/node/server-adapter.d.ts +1 -0
- package/src/adapters/node/server-adapter.js +4 -1
- package/src/adapters/shared/hmr/hmr-manager.d.ts +2 -0
- package/src/adapters/shared/hmr/hmr-manager.js +8 -4
- package/src/adapters/shared/http/api-request-pipeline.d.ts +16 -3
- package/src/adapters/shared/http/api-request-pipeline.js +23 -16
- package/src/adapters/shared/http/define-api-handler.d.ts +8 -8
- package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
- package/src/adapters/shared/http/file-route-middleware-pipeline.d.ts +10 -11
- package/src/adapters/shared/http/file-route-middleware-pipeline.js +5 -6
- package/src/adapters/shared/http/fs-server-response-matcher.js +12 -4
- package/src/adapters/shared/http/run-middleware-chain.d.ts +29 -2
- package/src/adapters/shared/http/run-middleware-chain.js +108 -10
- package/src/adapters/shared/runtime/render-context.d.ts +2 -0
- package/src/adapters/shared/runtime/render-context.js +6 -21
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +2 -2
- package/src/adapters/shared/runtime/server-request-pipeline.js +4 -3
- package/src/adapters/shared/runtime/server-static-builder.js +4 -1
- package/src/adapters/shared/runtime/unattached-scripts.d.ts +17 -0
- package/src/adapters/shared/runtime/unattached-scripts.js +57 -0
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +3 -2
- package/src/adapters/shared/ws/ws-pattern-matcher.d.ts +14 -1
- package/src/adapters/shared/ws/ws-pattern-matcher.js +14 -13
- package/src/assets/app-browser-client-build.js +3 -0
- package/src/assets/asset-processing-service/asset-processing.service.d.ts +9 -0
- package/src/assets/asset-processing-service/asset-processing.service.js +19 -0
- package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +16 -2
- package/src/assets/asset-processing-service/processed-asset-ledger.js +31 -3
- package/src/build/build-graph.d.ts +19 -2
- package/src/build/build-graph.js +19 -18
- package/src/build/cache/pages-unified-graph-build.d.ts +4 -6
- package/src/build/cache/pages-unified-graph-build.js +14 -51
- package/src/build/cache/server-module-entries.d.ts +5 -9
- package/src/build/cache/server-module-entries.js +5 -58
- package/src/build/contracts/build-contracts.d.ts +15 -0
- package/src/build/contracts.d.ts +1 -1
- package/src/build/contracts.js +1 -1
- package/src/build/production-asset-ledger.d.ts +1 -1
- package/src/build/production-asset-ledger.js +4 -2
- package/src/build/rolldown/file-role-grammar-plugin.d.ts +11 -0
- package/src/build/rolldown/file-role-grammar-plugin.js +32 -0
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +11 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +79 -10
- package/src/build/rolldown/ssr-script-entries-plugin.d.ts +31 -0
- package/src/build/rolldown/ssr-script-entries-plugin.js +104 -0
- package/src/build/runtime/build-request-policy.js +4 -1
- package/src/build/server/server-modules-manifest.d.ts +6 -1
- package/src/build/server/server-modules-manifest.js +10 -1
- package/src/build/server/view-reference.d.ts +9 -0
- package/src/build/server/view-reference.js +11 -0
- package/src/build.d.ts +3 -1
- package/src/build.js +3 -1
- package/src/cli.d.ts +14 -0
- package/src/cli.js +14 -0
- package/src/config/assembly/app-runtime.d.ts +13 -0
- package/src/config/assembly/app-runtime.js +2 -0
- package/src/config/assembly/finalize-config.js +13 -8
- package/src/config/internal-types.d.ts +0 -12
- package/src/config/resolve-eco-config-path.d.ts +2 -0
- package/src/config/resolve-eco-config-path.js +2 -1
- package/src/config/server-config-bundle.d.ts +0 -1
- package/src/config/server-config-bundle.js +1 -1
- package/src/config/user-config-types.d.ts +0 -12
- package/src/declarations.d.ts +2 -0
- package/src/dev/invalidation/development-invalidation.service.d.ts +0 -2
- package/src/dev/invalidation/development-invalidation.service.js +1 -11
- package/src/dev/transform-server/dev-transform-vendor-registry.js +33 -19
- package/src/eco/discovered-dependencies.d.ts +5 -0
- package/src/eco/discovered-dependencies.js +9 -0
- package/src/eco/eco.browser.js +6 -26
- package/src/eco/eco.js +24 -16
- package/src/eco/migration-docs.d.ts +7 -0
- package/src/eco/migration-docs.js +7 -0
- package/src/eco/page-data-hooks.d.ts +27 -0
- package/src/eco/page-data-hooks.js +64 -0
- package/src/eco/page-layout-normalization.d.ts +2 -2
- package/src/hmr/client/hmr-runtime.js +1 -1
- package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -2
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +2 -1
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +4 -3
- package/src/html/html-rewriter.d.ts +9 -7
- package/src/html/html-rewriter.js +26 -41
- package/src/html/html-transformer.service.d.ts +2 -2
- package/src/html/html-transformer.service.js +21 -15
- package/src/html-pages/html-page-module-scripts.js +2 -1
- package/src/html-pages/html-pages.plugin.d.ts +1 -1
- package/src/html-pages/html-pages.plugin.js +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/integration.d.ts +2 -2
- package/src/integration.js +2 -2
- package/src/islands/island-host.d.ts +16 -5
- package/src/islands/island-host.js +8 -1
- package/src/middleware/create-middleware.d.ts +41 -0
- package/src/middleware/create-middleware.js +72 -0
- package/src/plugins/component-import-discovery.d.ts +14 -1
- package/src/plugins/component-import-discovery.js +36 -16
- package/src/plugins/eco-component-meta-plugin.d.ts +38 -0
- package/src/plugins/eco-component-meta-plugin.js +208 -44
- package/src/plugins/ecopages-virtual-imports.d.ts +15 -0
- package/src/plugins/ecopages-virtual-imports.js +25 -0
- package/src/plugins/integration-plugin.d.ts +1 -1
- package/src/plugins/integration-plugin.js +1 -1
- package/src/plugins/tsconfig-import-resolver.d.ts +2 -0
- package/src/plugins/tsconfig-import-resolver.js +7 -5
- package/src/route-renderer/error-pages/error-page-renderer.js +32 -3
- package/src/route-renderer/explicit-view-render-preparation.d.ts +28 -3
- package/src/route-renderer/explicit-view-render-preparation.js +63 -11
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +15 -5
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +27 -15
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +24 -9
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +73 -50
- package/src/route-renderer/orchestration/integration-renderer.d.ts +42 -11
- package/src/route-renderer/orchestration/integration-renderer.js +83 -43
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.builder.js +0 -3
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +36 -11
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +74 -62
- package/src/route-renderer/page-declaration.d.ts +25 -0
- package/src/route-renderer/page-declaration.js +39 -0
- package/src/route-renderer/page-loading/component-declarations.d.ts +65 -0
- package/src/route-renderer/page-loading/component-declarations.js +77 -0
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -16
- package/src/route-renderer/page-loading/component-dependency-collection.js +36 -105
- package/src/route-renderer/page-loading/declared-asset-collection.d.ts +19 -14
- package/src/route-renderer/page-loading/declared-asset-collection.js +66 -67
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +18 -10
- package/src/route-renderer/page-loading/dependency-resolver.js +58 -99
- package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +19 -26
- package/src/route-renderer/page-loading/lazy-entry-collection.js +53 -64
- package/src/route-renderer/page-loading/module-declaration-aggregation.d.ts +17 -3
- package/src/route-renderer/page-loading/module-declaration-aggregation.js +14 -13
- package/src/route-renderer/page-loading/page-module-loader.d.ts +31 -12
- package/src/route-renderer/page-loading/page-module-loader.js +66 -35
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +14 -9
- package/src/router/server/pages-dir.d.ts +7 -0
- package/src/router/server/pages-dir.js +7 -0
- package/src/router/server/route-registry.d.ts +22 -10
- package/src/router/server/route-registry.js +54 -23
- package/src/router/server/segment-path-matcher.d.ts +29 -5
- package/src/router/server/segment-path-matcher.js +22 -19
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +2 -2
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +5 -5
- package/src/static-site-generator/static-site-generator.d.ts +17 -2
- package/src/static-site-generator/static-site-generator.js +52 -18
- package/src/types/contracts.d.ts +216 -160
- package/src/types/eco-api-types.d.ts +86 -51
- package/src/types/locals-brand.d.ts +9 -0
- package/src/types/locals-brand.js +9 -0
- package/src/types/middleware-types.d.ts +143 -0
- package/src/types/middleware-types.js +1 -0
- package/src/types/public-types.d.ts +3 -2
- package/src/utils/file-roles.d.ts +48 -0
- package/src/utils/file-roles.js +85 -0
- package/src/utils/node-builtin.d.ts +10 -0
- package/src/utils/node-builtin.js +13 -0
- package/src/watchers/project-watcher.js +2 -2
- package/src/build/contracts/server-only-specifier.d.ts +0 -8
- package/src/build/contracts/server-only-specifier.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.d.ts +0 -5
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.d.ts +0 -4
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.js +0 -30
- package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +0 -12
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +0 -100
- package/src/utils/endpoint-file-extensions.d.ts +0 -11
- package/src/utils/endpoint-file-extensions.js +0 -13
- package/src/utils/locals-utils.d.ts +0 -15
- package/src/utils/locals-utils.js +0 -34
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { path } from '@ecopages/file-system/path';
|
|
2
|
+
import { getComponentIdentity } from '../eco/component-identity.js';
|
|
3
|
+
import { isEcoDeclaredComponent } from '../eco/eco-declared-component.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether `page` is a declared component whose build-time identity names `file`, absolute or relative to `rootDir`.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The identity transform stamps the file that holds the literal `eco.page(...)` call, so a Page made by a
|
|
9
|
+
* wrapper in another file, or re-exported from one, names that other file.
|
|
10
|
+
*/
|
|
11
|
+
export function isPageDeclaredIn(file, page, rootDir) {
|
|
12
|
+
const identityFile = isEcoDeclaredComponent(page) ? getComponentIdentity(page)?.file : undefined;
|
|
13
|
+
return identityFile !== undefined && path.resolve(rootDir, identityFile) === path.resolve(rootDir, file);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether `page` is a function carrying a `config`, which is what a wrapped or re-exported `eco.page()` result
|
|
17
|
+
* looks like when {@link isPageDeclaredIn} fails.
|
|
18
|
+
*/
|
|
19
|
+
export function isUnattributedPage(page) {
|
|
20
|
+
return typeof page === 'function' && typeof page.config === 'object';
|
|
21
|
+
}
|
|
22
|
+
/** The error for a view or route file whose Page the build did not attribute to it. */
|
|
23
|
+
export function createLiteralPageDeclarationError(file) {
|
|
24
|
+
return new Error(`[ecopages] ${file} default-exports an eco.page() result that the build did not attribute to this file. A route file declares its Page with a literal \`eco.page(...)\` call in that file. The build finds eco.page, eco.layout, eco.component and eco.html by their literal call, so a wrapper function, an alias such as \`const page = eco.page\`, a renamed import, or a Page declared in another file and re-exported gives the Page no identity or another file's, and server options such as props and metadata stay in the browser bundle. Call eco.page(...) directly in ${file}.`);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Fails when a view loaded from `file` is not a Page that file declares with a literal `eco.page(...)` call.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Applies the route-file check to views passed to `app.static()`, `app.errorPage()` and `ctx.render()`, so a view
|
|
31
|
+
* behaves the same however it is routed. A value that is not a declared component at all is left to the
|
|
32
|
+
* renderer lookup, which reports a missing integration.
|
|
33
|
+
* @throws When `view` carries a config that the build did not attribute to `file`.
|
|
34
|
+
*/
|
|
35
|
+
export function assertViewDeclaredIn(file, view, rootDir) {
|
|
36
|
+
if (isUnattributedPage(view) && !isPageDeclaredIn(file, view, rootDir)) {
|
|
37
|
+
throw createLiteralPageDeclarationError(file);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { EcoComponentConfig } from '../../types/contracts.js';
|
|
2
|
+
import { type DeclaredAsset } from './declared-asset-collection.js';
|
|
3
|
+
import { type DeclaredLazyScript } from './lazy-entry-collection.js';
|
|
4
|
+
import { type ModuleDeclaration } from './module-declaration-aggregation.js';
|
|
5
|
+
/** An inferred stylesheet and whether only a plain module imports it. */
|
|
6
|
+
export type InferredStyle = {
|
|
7
|
+
filepath: string;
|
|
8
|
+
plainModule: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The assets one component config declares, resolved against the app root.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* It covers the config alone, not its nested Components, so collection walks the graph and merges the
|
|
15
|
+
* declarations of each config it reaches.
|
|
16
|
+
*/
|
|
17
|
+
export type ComponentDeclarations = {
|
|
18
|
+
/** The identity file, absolute. */
|
|
19
|
+
file: string;
|
|
20
|
+
/** Stylesheets, then eager scripts, in declaration order. */
|
|
21
|
+
assets: ReadonlyArray<DeclaredAsset>;
|
|
22
|
+
lazyScripts: ReadonlyArray<DeclaredLazyScript>;
|
|
23
|
+
/** Declared `modules` and the `ecopages:` virtual modules the declaring module imports, in merge order. */
|
|
24
|
+
modules: ReadonlyArray<ModuleDeclaration>;
|
|
25
|
+
explicitStylePaths: ReadonlyArray<string>;
|
|
26
|
+
inferredStyles: ReadonlyArray<InferredStyle>;
|
|
27
|
+
packageStylePaths: ReadonlyMap<string, string>;
|
|
28
|
+
/** Whether the config itself ships a browser script: an eager or lazy script, or a module. */
|
|
29
|
+
declaresScript: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type ComponentDeclarationErrors = {
|
|
32
|
+
invalidStylesheetEntry: string;
|
|
33
|
+
invalidScriptEntry: string;
|
|
34
|
+
lazyScriptMissingSrc: string;
|
|
35
|
+
};
|
|
36
|
+
export type ComponentDeclarationStoreOptions = {
|
|
37
|
+
/** The app root that root-relative identity files and discovered stylesheets resolve against. */
|
|
38
|
+
rootDir: string;
|
|
39
|
+
/** Maps lazy script sources to the public URLs used when no build output URL exists. */
|
|
40
|
+
resolveLazyScripts: (componentDir: string, scripts: string[]) => string;
|
|
41
|
+
errors: ComponentDeclarationErrors;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Names the app browser client entry of a lazy script for the Integration that owns its component.
|
|
45
|
+
*
|
|
46
|
+
* @remarks `entryHash` is {@link DeclaredLazyScript.entryHash}; only the owner varies between renders.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createLazyEntryName(integrationName: string, entryHash: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the declarations of each component config once per app.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* A config is a value of the module that declares it, so its declarations are fixed for the life of that module
|
|
54
|
+
* instance: the file paths, the virtual imports discovery recorded and the lazy entry keys never change while the config
|
|
55
|
+
* exists. A development edit re-imports the module, and the new config is resolved afresh. Configs are held
|
|
56
|
+
* weakly, so a dropped module instance takes its declarations with it.
|
|
57
|
+
*/
|
|
58
|
+
export declare class ComponentDeclarationStore {
|
|
59
|
+
private readonly declarationsByConfig;
|
|
60
|
+
private readonly options;
|
|
61
|
+
constructor(options: ComponentDeclarationStoreOptions);
|
|
62
|
+
/** Returns the declarations of `config`, or `undefined` when it has no identity file and so takes no part. */
|
|
63
|
+
get(config: EcoComponentConfig): ComponentDeclarations | undefined;
|
|
64
|
+
private resolve;
|
|
65
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { path } from '@ecopages/file-system/path';
|
|
2
|
+
import { getComponentIdentity } from '../../eco/component-identity.js';
|
|
3
|
+
import { resolveDiscoveredStylesheets } from '../../eco/discovered-dependency-paths.js';
|
|
4
|
+
import { declareAssetEntries, resolveDeclaredPath } from './declared-asset-collection.js';
|
|
5
|
+
import { declareLazyScriptEntries } from './lazy-entry-collection.js';
|
|
6
|
+
import { declareModules } from './module-declaration-aggregation.js';
|
|
7
|
+
import { getDiscoveredVirtualImports } from '../../eco/discovered-dependencies.js';
|
|
8
|
+
/**
|
|
9
|
+
* Names the app browser client entry of a lazy script for the Integration that owns its component.
|
|
10
|
+
*
|
|
11
|
+
* @remarks `entryHash` is {@link DeclaredLazyScript.entryHash}; only the owner varies between renders.
|
|
12
|
+
*/
|
|
13
|
+
export function createLazyEntryName(integrationName, entryHash) {
|
|
14
|
+
return `ecopages-${integrationName}-lazy-${entryHash}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the declarations of each component config once per app.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* A config is a value of the module that declares it, so its declarations are fixed for the life of that module
|
|
21
|
+
* instance: the file paths, the virtual imports discovery recorded and the lazy entry keys never change while the config
|
|
22
|
+
* exists. A development edit re-imports the module, and the new config is resolved afresh. Configs are held
|
|
23
|
+
* weakly, so a dropped module instance takes its declarations with it.
|
|
24
|
+
*/
|
|
25
|
+
export class ComponentDeclarationStore {
|
|
26
|
+
declarationsByConfig = new WeakMap();
|
|
27
|
+
options;
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.options = options;
|
|
30
|
+
}
|
|
31
|
+
/** Returns the declarations of `config`, or `undefined` when it has no identity file and so takes no part. */
|
|
32
|
+
get(config) {
|
|
33
|
+
let declarations = this.declarationsByConfig.get(config);
|
|
34
|
+
if (declarations === undefined) {
|
|
35
|
+
declarations = this.resolve(config);
|
|
36
|
+
this.declarationsByConfig.set(config, declarations);
|
|
37
|
+
}
|
|
38
|
+
return declarations ?? undefined;
|
|
39
|
+
}
|
|
40
|
+
resolve(config) {
|
|
41
|
+
const identityFile = getComponentIdentity(config)?.file;
|
|
42
|
+
if (!identityFile)
|
|
43
|
+
return null;
|
|
44
|
+
const { rootDir, errors } = this.options;
|
|
45
|
+
const file = path.resolve(rootDir, identityFile);
|
|
46
|
+
const dir = path.dirname(file);
|
|
47
|
+
const stylesheetEntries = config.dependencies?.stylesheets ?? [];
|
|
48
|
+
const scriptEntries = config.dependencies?.scripts ?? [];
|
|
49
|
+
const discovered = resolveDiscoveredStylesheets(config, rootDir);
|
|
50
|
+
const assets = declareAssetEntries({ stylesheetEntries, scriptEntries, componentDir: dir, errors });
|
|
51
|
+
const lazyScripts = declareLazyScriptEntries({
|
|
52
|
+
scriptEntries,
|
|
53
|
+
rootDir,
|
|
54
|
+
componentFile: file,
|
|
55
|
+
componentDir: dir,
|
|
56
|
+
resolveLazyScripts: this.options.resolveLazyScripts,
|
|
57
|
+
lazyScriptMissingSrcMessage: errors.lazyScriptMissingSrc,
|
|
58
|
+
});
|
|
59
|
+
const modules = declareModules(config.dependencies?.modules, getDiscoveredVirtualImports(config));
|
|
60
|
+
return {
|
|
61
|
+
file,
|
|
62
|
+
assets,
|
|
63
|
+
lazyScripts,
|
|
64
|
+
modules,
|
|
65
|
+
explicitStylePaths: stylesheetEntries
|
|
66
|
+
.map((style) => (typeof style === 'string' ? style : style.src))
|
|
67
|
+
.filter((src) => Boolean(src))
|
|
68
|
+
.map((src) => resolveDeclaredPath(dir, src)),
|
|
69
|
+
inferredStyles: [
|
|
70
|
+
...discovered.imported.map((filepath) => ({ filepath, plainModule: false })),
|
|
71
|
+
...discovered.plainModules.map((filepath) => ({ filepath, plainModule: true })),
|
|
72
|
+
],
|
|
73
|
+
packageStylePaths: discovered.packagePaths,
|
|
74
|
+
declaresScript: modules.length > 0 || lazyScripts.length > 0 || assets.some((asset) => asset.kind === 'script'),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EcoComponent } from '../../types/contracts.js';
|
|
2
2
|
import type { AssetDefinition } from '../../assets/asset-processing-service/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { LazyGroup } from './lazy-entry-collection.js';
|
|
4
|
+
import { type ComponentDeclarationStore } from './component-declarations.js';
|
|
4
5
|
/**
|
|
5
6
|
* Aggregated dependency output for one dependency-collection pass.
|
|
6
7
|
*/
|
|
@@ -17,25 +18,12 @@ export type CollectedComponentDependencies = {
|
|
|
17
18
|
type CollectComponentDependenciesOptions = {
|
|
18
19
|
components: Array<EcoComponent | Partial<EcoComponent> | undefined | null>;
|
|
19
20
|
integrationName: string;
|
|
20
|
-
/** The
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Skips nested components owned by another Integration, and their descendants.
|
|
24
|
-
*
|
|
25
|
-
* @remarks Those are Foreign Children: their owning Integration renders them and emits their assets.
|
|
26
|
-
*/
|
|
27
|
-
excludeForeignChildren?: boolean;
|
|
21
|
+
/** The declarations of each component config the walk reaches. */
|
|
22
|
+
declarations: ComponentDeclarationStore;
|
|
28
23
|
/**
|
|
29
24
|
* Treats each supplied component as an already flattened graph node.
|
|
30
25
|
*/
|
|
31
26
|
skipNestedComponents?: boolean;
|
|
32
|
-
resolveLazyScripts: (componentDir: string, scripts: string[]) => string;
|
|
33
|
-
createEcopagesJsxLazyEntryName: (integrationName: string, key: string) => string;
|
|
34
|
-
errors: {
|
|
35
|
-
invalidStylesheetEntry: string;
|
|
36
|
-
invalidScriptEntry: string;
|
|
37
|
-
lazyScriptMissingSrc: string;
|
|
38
|
-
};
|
|
39
27
|
};
|
|
40
28
|
/**
|
|
41
29
|
* Walks component dependency trees and collects declared assets, module declarations,
|
|
@@ -1,67 +1,45 @@
|
|
|
1
|
-
import { path } from '@ecopages/file-system/path';
|
|
2
1
|
import { assertEcoDeclaredComponent } from '../../eco/eco-declared-component.js';
|
|
3
2
|
import { getComponentIdentity, getComponentOwner } from '../../eco/component-identity.js';
|
|
4
|
-
import { resolveDiscoveredStylesheets } from '../../eco/discovered-dependency-paths.js';
|
|
5
3
|
import { AssetFactory } from '../../assets/asset-processing-service/index.js';
|
|
6
|
-
import { extractEcopagesVirtualImports } from './ecopages-virtual-imports.js';
|
|
7
|
-
import { collectDeclaredAssetEntries } from './declared-asset-collection.js';
|
|
8
4
|
import { getLazyTriggerKey } from './lazy-trigger-planning.js';
|
|
9
|
-
import { collectLazyScriptEntries } from './lazy-entry-collection.js';
|
|
10
5
|
import { createModuleScriptName, createNamedImportModuleSource, createNamespaceImportModuleSource, } from './module-declaration-scripts.js';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
defer: '',
|
|
15
|
-
};
|
|
16
|
-
function createModuleScriptAttributes(attributes) {
|
|
17
|
-
return {
|
|
18
|
-
...MODULE_SCRIPT_ATTRIBUTES,
|
|
19
|
-
...attributes,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
6
|
+
import { mergeModuleDeclaration } from './module-declaration-aggregation.js';
|
|
7
|
+
import { createModuleScriptAttributes } from './declared-asset-collection.js';
|
|
8
|
+
import { createLazyEntryName, } from './component-declarations.js';
|
|
22
9
|
function pushUniqueDependency(keys, key, dependencies, dependency) {
|
|
23
|
-
if (keys.has(key))
|
|
24
|
-
return
|
|
25
|
-
}
|
|
10
|
+
if (keys.has(key))
|
|
11
|
+
return;
|
|
26
12
|
keys.add(key);
|
|
27
13
|
dependencies.push(dependency);
|
|
28
|
-
return true;
|
|
29
14
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const triggerKey = getLazyTriggerKey(lazy);
|
|
41
|
-
const existing = grouped.get(triggerKey) ?? { lazy, scripts: [] };
|
|
42
|
-
existing.scripts.push({ lazyKey, fallbackUrl });
|
|
43
|
-
grouped.set(triggerKey, existing);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function recordExplicitAndInferredStyles(config, dir, context) {
|
|
47
|
-
const dependenciesConfig = config.dependencies;
|
|
48
|
-
const explicitStyles = dependenciesConfig?.stylesheets ?? [];
|
|
49
|
-
for (const style of explicitStyles) {
|
|
50
|
-
const src = typeof style === 'string' ? style : style.src;
|
|
51
|
-
if (src)
|
|
52
|
-
context.explicitStylePaths.add(resolveDependencyPath(dir, src));
|
|
53
|
-
}
|
|
54
|
-
const discovered = resolveDiscoveredStylesheets(config, context.rootDir);
|
|
55
|
-
for (const filepath of discovered.imported) {
|
|
56
|
-
context.inferredStyles.push({ filepath, plainModule: false });
|
|
15
|
+
/** Adds one config's declarations to the pass, skipping assets an earlier config already added. */
|
|
16
|
+
function mergeComponentDeclarations(config, declarations, context) {
|
|
17
|
+
for (const filepath of declarations.explicitStylePaths)
|
|
18
|
+
context.explicitStylePaths.add(filepath);
|
|
19
|
+
context.inferredStyles.push(...declarations.inferredStyles);
|
|
20
|
+
for (const [filepath, packagePath] of declarations.packageStylePaths)
|
|
21
|
+
context.packageStylePaths.set(filepath, packagePath);
|
|
22
|
+
for (const { kind, key, asset } of declarations.assets) {
|
|
23
|
+
const keys = kind === 'stylesheet' ? context.stylesheetDependencyKeys : context.scriptDependencyKeys;
|
|
24
|
+
pushUniqueDependency(keys, key, context.dependencies, asset);
|
|
57
25
|
}
|
|
58
|
-
for (const
|
|
59
|
-
context.
|
|
26
|
+
for (const declaration of declarations.modules)
|
|
27
|
+
mergeModuleDeclaration(context.modulesMap, declaration);
|
|
28
|
+
if (declarations.lazyScripts.length === 0)
|
|
29
|
+
return;
|
|
30
|
+
const owner = getComponentOwner(config, context.integrationName);
|
|
31
|
+
let groups = context.lazyScriptsByConfig.get(config);
|
|
32
|
+
if (!groups) {
|
|
33
|
+
groups = new Map();
|
|
34
|
+
context.lazyScriptsByConfig.set(config, groups);
|
|
60
35
|
}
|
|
61
|
-
for (const
|
|
62
|
-
context.
|
|
36
|
+
for (const script of declarations.lazyScripts) {
|
|
37
|
+
pushUniqueDependency(context.lazyDependencyKeys, script.key, context.dependencies, script.createAsset(createLazyEntryName(owner, script.entryHash)));
|
|
38
|
+
const triggerKey = getLazyTriggerKey(script.lazy);
|
|
39
|
+
const group = groups.get(triggerKey) ?? { lazy: script.lazy, scripts: [] };
|
|
40
|
+
group.scripts.push({ lazyKey: script.lazyKey, fallbackUrl: script.fallbackUrl });
|
|
41
|
+
groups.set(triggerKey, group);
|
|
63
42
|
}
|
|
64
|
-
return explicitStyles;
|
|
65
43
|
}
|
|
66
44
|
/**
|
|
67
45
|
* Orders inferred stylesheets once each, leaving out paths with an explicit entry.
|
|
@@ -85,12 +63,6 @@ function orderInferredStylesheets(styles, explicitStylePaths) {
|
|
|
85
63
|
});
|
|
86
64
|
return [...positions].sort(([, left], [, right]) => left.index - right.index).map(([filepath]) => filepath);
|
|
87
65
|
}
|
|
88
|
-
/**
|
|
89
|
-
* @remarks A nested component without an Integration inherits its parent's, so it is not a Foreign Child.
|
|
90
|
-
*/
|
|
91
|
-
function isForeignChild(component, integrationName) {
|
|
92
|
-
return getComponentOwner(component, integrationName) !== integrationName;
|
|
93
|
-
}
|
|
94
66
|
/**
|
|
95
67
|
* Recursively visits one component config and its declared child dependencies.
|
|
96
68
|
*/
|
|
@@ -98,45 +70,11 @@ function collectComponentConfigDependencies(config, context) {
|
|
|
98
70
|
if (!config || context.visited.has(config))
|
|
99
71
|
return;
|
|
100
72
|
context.visited.add(config);
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
73
|
+
const declarations = context.declarations.get(config);
|
|
74
|
+
if (!declarations)
|
|
103
75
|
return;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const explicitStyles = recordExplicitAndInferredStyles(config, dir, context);
|
|
107
|
-
const dependenciesConfig = config.dependencies;
|
|
108
|
-
const registerLazyScript = createLazyScriptRegistrar(config, context.lazyScriptsByConfig);
|
|
109
|
-
collectDeclaredAssetEntries({
|
|
110
|
-
stylesheetEntries: explicitStyles,
|
|
111
|
-
scriptEntries: dependenciesConfig?.scripts ?? [],
|
|
112
|
-
componentDir: dir,
|
|
113
|
-
dependencies: context.dependencies,
|
|
114
|
-
stylesheetDependencyKeys: context.stylesheetDependencyKeys,
|
|
115
|
-
scriptDependencyKeys: context.scriptDependencyKeys,
|
|
116
|
-
resolveDependencyPath,
|
|
117
|
-
createModuleScriptAttributes,
|
|
118
|
-
pushUniqueDependency,
|
|
119
|
-
getInvalidStylesheetEntryMessage: () => context.errors.invalidStylesheetEntry,
|
|
120
|
-
getInvalidScriptEntryMessage: () => context.errors.invalidScriptEntry,
|
|
121
|
-
});
|
|
122
|
-
collectModuleDeclarations(context.modulesMap, dependenciesConfig?.modules, extractEcopagesVirtualImports(file));
|
|
123
|
-
collectLazyScriptEntries({
|
|
124
|
-
scriptEntries: dependenciesConfig?.scripts ?? [],
|
|
125
|
-
rootDir: context.rootDir,
|
|
126
|
-
componentFile: file,
|
|
127
|
-
componentDir: dir,
|
|
128
|
-
integrationName: getComponentOwner(config, context.integrationName),
|
|
129
|
-
dependencies: context.dependencies,
|
|
130
|
-
lazyDependencyKeys: context.lazyDependencyKeys,
|
|
131
|
-
registerLazyScript,
|
|
132
|
-
resolveDependencyPath,
|
|
133
|
-
resolveLazyScripts: context.resolveLazyScripts,
|
|
134
|
-
createModuleScriptAttributes,
|
|
135
|
-
createEcopagesJsxLazyEntryName: context.createEcopagesJsxLazyEntryName,
|
|
136
|
-
pushUniqueDependency,
|
|
137
|
-
getLazyScriptMissingSrcMessage: () => context.errors.lazyScriptMissingSrc,
|
|
138
|
-
});
|
|
139
|
-
collectNestedComponentDependencies(dependenciesConfig?.components ?? [], file, context);
|
|
76
|
+
mergeComponentDeclarations(config, declarations, context);
|
|
77
|
+
collectNestedComponentDependencies(config.dependencies?.components ?? [], declarations.file, context);
|
|
140
78
|
}
|
|
141
79
|
function collectNestedComponentDependencies(nestedComponents, parentComponentFile, context) {
|
|
142
80
|
for (const nestedComponent of nestedComponents) {
|
|
@@ -147,9 +85,6 @@ function collectNestedComponentDependencies(nestedComponents, parentComponentFil
|
|
|
147
85
|
if (context.skipNestedComponents) {
|
|
148
86
|
continue;
|
|
149
87
|
}
|
|
150
|
-
if (context.excludeForeignChildren && isForeignChild(nestedComponent, context.integrationName)) {
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
88
|
collectComponentConfigDependencies(nestedComponent.config, context);
|
|
154
89
|
}
|
|
155
90
|
}
|
|
@@ -166,7 +101,7 @@ function collectNestedComponentDependencies(nestedComponents, parentComponentFil
|
|
|
166
101
|
* later during render output.
|
|
167
102
|
*/
|
|
168
103
|
export function collectComponentDependencies(options) {
|
|
169
|
-
const { components, integrationName,
|
|
104
|
+
const { components, integrationName, declarations, skipNestedComponents = false } = options;
|
|
170
105
|
const dependencies = [];
|
|
171
106
|
const lazyScriptsByConfig = new Map();
|
|
172
107
|
const lazyDependencyKeys = new Set();
|
|
@@ -185,12 +120,8 @@ export function collectComponentDependencies(options) {
|
|
|
185
120
|
continue;
|
|
186
121
|
const collectionContext = {
|
|
187
122
|
integrationName,
|
|
188
|
-
|
|
189
|
-
excludeForeignChildren,
|
|
123
|
+
declarations,
|
|
190
124
|
skipNestedComponents,
|
|
191
|
-
resolveLazyScripts,
|
|
192
|
-
createEcopagesJsxLazyEntryName,
|
|
193
|
-
errors,
|
|
194
125
|
dependencies,
|
|
195
126
|
lazyScriptsByConfig,
|
|
196
127
|
lazyDependencyKeys,
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import type { EcoComponentScriptEntry, EcoComponentStylesheetEntry } from '../../types/contracts.js';
|
|
2
2
|
import type { AssetDefinition } from '../../assets/asset-processing-service/index.js';
|
|
3
|
-
|
|
3
|
+
/** One declared stylesheet or eager script, with the key that dedupes it within a collection pass. */
|
|
4
|
+
export type DeclaredAsset = {
|
|
5
|
+
kind: 'stylesheet' | 'script';
|
|
6
|
+
key: string;
|
|
7
|
+
asset: AssetDefinition;
|
|
8
|
+
};
|
|
9
|
+
type DeclareAssetEntriesOptions = {
|
|
4
10
|
stylesheetEntries: Array<string | EcoComponentStylesheetEntry>;
|
|
5
11
|
scriptEntries: Array<string | EcoComponentScriptEntry>;
|
|
6
12
|
componentDir: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
createModuleScriptAttributes: (attributes?: Record<string, string>) => Record<string, string>;
|
|
12
|
-
pushUniqueDependency: (keys: Set<string>, key: string, dependencies: AssetDefinition[], dependency: AssetDefinition) => boolean;
|
|
13
|
-
getInvalidStylesheetEntryMessage: () => string;
|
|
14
|
-
getInvalidScriptEntryMessage: () => string;
|
|
13
|
+
errors: {
|
|
14
|
+
invalidStylesheetEntry: string;
|
|
15
|
+
invalidScriptEntry: string;
|
|
16
|
+
};
|
|
15
17
|
};
|
|
18
|
+
/** Resolves a declared asset path against the directory of the component that declares it. */
|
|
19
|
+
export declare function resolveDeclaredPath(componentDir: string, pathUrl: string): string;
|
|
20
|
+
/** Script attributes a declared module script gets unless it overrides them. */
|
|
21
|
+
export declare function createModuleScriptAttributes(attributes?: Record<string, string>): Record<string, string>;
|
|
16
22
|
/**
|
|
17
|
-
* Normalizes
|
|
23
|
+
* Normalizes a component's stylesheet and non-lazy script declarations into asset definitions, stylesheets first.
|
|
18
24
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* the same asset multiple times.
|
|
25
|
+
* @remarks
|
|
26
|
+
* Each carries the key collection dedupes it by, so the same declaration from two components is emitted once.
|
|
22
27
|
*/
|
|
23
|
-
export declare function
|
|
28
|
+
export declare function declareAssetEntries(options: DeclareAssetEntriesOptions): DeclaredAsset[];
|
|
24
29
|
export {};
|
|
@@ -1,78 +1,77 @@
|
|
|
1
1
|
import { AssetFactory } from '../../assets/asset-processing-service/index.js';
|
|
2
|
+
import { path } from '@ecopages/file-system/path';
|
|
3
|
+
/** Resolves a declared asset path against the directory of the component that declares it. */
|
|
4
|
+
export function resolveDeclaredPath(componentDir, pathUrl) {
|
|
5
|
+
return path.isAbsolute(pathUrl) ? pathUrl : path.join(componentDir, pathUrl);
|
|
6
|
+
}
|
|
7
|
+
/** Script attributes a declared module script gets unless it overrides them. */
|
|
8
|
+
export function createModuleScriptAttributes(attributes) {
|
|
9
|
+
return { type: 'module', defer: '', ...attributes };
|
|
10
|
+
}
|
|
2
11
|
function isDependencyEntryObject(entry) {
|
|
3
12
|
return typeof entry === 'object' && entry !== null;
|
|
4
13
|
}
|
|
5
|
-
function
|
|
6
|
-
return isDependencyEntryObject(entry)
|
|
14
|
+
function readEntry(entry) {
|
|
15
|
+
return isDependencyEntryObject(entry)
|
|
16
|
+
? { src: entry.src, content: entry.content, attributes: entry.attributes }
|
|
17
|
+
: { src: entry };
|
|
7
18
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
19
|
+
function declareStylesheet(style, componentDir, invalidEntry) {
|
|
20
|
+
const { src, content, attributes } = readEntry(style);
|
|
21
|
+
if (content) {
|
|
22
|
+
return {
|
|
23
|
+
kind: 'stylesheet',
|
|
24
|
+
key: `style:content:${content}:${JSON.stringify(attributes ?? {})}`,
|
|
25
|
+
asset: AssetFactory.createContentStylesheet({ content, position: 'head', attributes }),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
if (!src)
|
|
29
|
+
throw new Error(invalidEntry);
|
|
30
|
+
const filepath = resolveDeclaredPath(componentDir, src);
|
|
31
|
+
return {
|
|
32
|
+
kind: 'stylesheet',
|
|
33
|
+
key: `style:file:${filepath}:${JSON.stringify(attributes ?? {})}`,
|
|
34
|
+
asset: AssetFactory.createFileStylesheet({
|
|
35
|
+
filepath,
|
|
36
|
+
position: 'head',
|
|
37
|
+
attributes: { rel: 'stylesheet', ...attributes },
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
10
40
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
41
|
+
function declareScript(script, componentDir, invalidEntry) {
|
|
42
|
+
const { src, content, attributes } = readEntry(script);
|
|
43
|
+
if (content) {
|
|
44
|
+
return {
|
|
45
|
+
kind: 'script',
|
|
46
|
+
key: `script:content:${content}:${JSON.stringify(attributes ?? {})}`,
|
|
47
|
+
asset: AssetFactory.createInlineContentScript({ position: 'head', content, bundle: false, attributes }),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (!src)
|
|
51
|
+
throw new Error(invalidEntry);
|
|
52
|
+
const filepath = resolveDeclaredPath(componentDir, src);
|
|
53
|
+
return {
|
|
54
|
+
kind: 'script',
|
|
55
|
+
key: `script:file:${filepath}:${JSON.stringify(attributes ?? {})}`,
|
|
56
|
+
asset: AssetFactory.createFileScript({
|
|
57
|
+
filepath,
|
|
58
|
+
position: 'head',
|
|
59
|
+
attributes: createModuleScriptAttributes(attributes),
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
13
62
|
}
|
|
14
63
|
/**
|
|
15
|
-
* Normalizes
|
|
64
|
+
* Normalizes a component's stylesheet and non-lazy script declarations into asset definitions, stylesheets first.
|
|
16
65
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* the same asset multiple times.
|
|
66
|
+
* @remarks
|
|
67
|
+
* Each carries the key collection dedupes it by, so the same declaration from two components is emitted once.
|
|
20
68
|
*/
|
|
21
|
-
export function
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
pushUniqueDependency(stylesheetDependencyKeys, depKey, dependencies, AssetFactory.createContentStylesheet({
|
|
30
|
-
content,
|
|
31
|
-
position: 'head',
|
|
32
|
-
attributes,
|
|
33
|
-
}));
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (!src) {
|
|
37
|
-
throw new Error(getInvalidStylesheetEntryMessage());
|
|
38
|
-
}
|
|
39
|
-
const resolvedPath = resolveDependencyPath(componentDir, src);
|
|
40
|
-
const depKey = `style:file:${resolvedPath}:${JSON.stringify(attributes ?? {})}`;
|
|
41
|
-
pushUniqueDependency(stylesheetDependencyKeys, depKey, dependencies, AssetFactory.createFileStylesheet({
|
|
42
|
-
filepath: resolvedPath,
|
|
43
|
-
position: 'head',
|
|
44
|
-
attributes: {
|
|
45
|
-
rel: 'stylesheet',
|
|
46
|
-
...attributes,
|
|
47
|
-
},
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
for (const script of scriptEntries) {
|
|
51
|
-
if (isDependencyEntryObject(script) && 'lazy' in script && script.lazy) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const content = getDependencyEntryContent(script);
|
|
55
|
-
const src = getDependencyEntrySrc(script);
|
|
56
|
-
const attributes = getDependencyEntryAttributes(script);
|
|
57
|
-
if (content) {
|
|
58
|
-
const depKey = `script:content:${content}:${JSON.stringify(attributes ?? {})}`;
|
|
59
|
-
pushUniqueDependency(scriptDependencyKeys, depKey, dependencies, AssetFactory.createInlineContentScript({
|
|
60
|
-
position: 'head',
|
|
61
|
-
content,
|
|
62
|
-
bundle: false,
|
|
63
|
-
attributes,
|
|
64
|
-
}));
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (!src) {
|
|
68
|
-
throw new Error(getInvalidScriptEntryMessage());
|
|
69
|
-
}
|
|
70
|
-
const resolvedPath = resolveDependencyPath(componentDir, src);
|
|
71
|
-
const depKey = `script:file:${resolvedPath}:${JSON.stringify(attributes ?? {})}`;
|
|
72
|
-
pushUniqueDependency(scriptDependencyKeys, depKey, dependencies, AssetFactory.createFileScript({
|
|
73
|
-
filepath: resolvedPath,
|
|
74
|
-
position: 'head',
|
|
75
|
-
attributes: createModuleScriptAttributes(attributes),
|
|
76
|
-
}));
|
|
77
|
-
}
|
|
69
|
+
export function declareAssetEntries(options) {
|
|
70
|
+
const { componentDir, errors } = options;
|
|
71
|
+
return [
|
|
72
|
+
...options.stylesheetEntries.map((style) => declareStylesheet(style, componentDir, errors.invalidStylesheetEntry)),
|
|
73
|
+
...options.scriptEntries
|
|
74
|
+
.filter((script) => !(isDependencyEntryObject(script) && 'lazy' in script && script.lazy))
|
|
75
|
+
.map((script) => declareScript(script, componentDir, errors.invalidScriptEntry)),
|
|
76
|
+
];
|
|
78
77
|
}
|