@ecopages/core 0.2.0-alpha.26 → 0.2.0-alpha.28
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/CHANGELOG.md +25 -0
- package/README.md +63 -7
- package/package.json +8 -94
- package/src/adapters/bun/create-app.d.ts +1 -0
- package/src/adapters/bun/create-app.js +39 -2
- package/src/adapters/bun/hmr-manager.d.ts +1 -13
- package/src/adapters/bun/hmr-manager.js +1 -22
- package/src/adapters/bun/server-adapter.js +23 -4
- package/src/adapters/node/node-hmr-manager.d.ts +2 -14
- package/src/adapters/node/node-hmr-manager.js +2 -23
- package/src/adapters/shared/explicit-static-render-preparation.d.ts +25 -0
- package/src/adapters/shared/explicit-static-render-preparation.js +26 -0
- package/src/adapters/shared/explicit-static-route-matcher.d.ts +5 -2
- package/src/adapters/shared/explicit-static-route-matcher.js +14 -16
- package/src/adapters/shared/file-route-middleware-pipeline.d.ts +7 -10
- package/src/adapters/shared/file-route-middleware-pipeline.js +2 -11
- package/src/adapters/shared/fs-server-response-factory.d.ts +13 -9
- package/src/adapters/shared/fs-server-response-factory.js +10 -26
- package/src/adapters/shared/fs-server-response-matcher.d.ts +14 -6
- package/src/adapters/shared/fs-server-response-matcher.js +67 -28
- package/src/adapters/shared/render-context.d.ts +2 -2
- package/src/adapters/shared/server-adapter.d.ts +21 -10
- package/src/adapters/shared/server-adapter.js +171 -132
- package/src/adapters/shared/server-route-handler.d.ts +2 -2
- package/src/adapters/shared/server-route-handler.js +1 -1
- package/src/adapters/shared/server-static-builder.d.ts +4 -4
- package/src/config/README.md +1 -1
- package/src/config/config-builder.d.ts +2 -2
- package/src/config/config-builder.js +0 -5
- package/src/dev/host-runtime.d.ts +10 -0
- package/src/dev/host-runtime.js +24 -0
- package/src/eco/eco.js +7 -7
- package/src/eco/eco.types.d.ts +3 -3
- package/src/errors/index.d.ts +1 -0
- package/src/errors/index.js +3 -1
- package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -5
- package/src/integrations/ghtml/ghtml-renderer.d.ts +0 -4
- package/src/integrations/ghtml/ghtml-renderer.js +1 -7
- package/src/plugins/eco-component-meta-plugin.js +0 -1
- package/src/plugins/integration-plugin.d.ts +14 -18
- package/src/plugins/integration-plugin.js +14 -21
- package/src/plugins/processor.d.ts +2 -0
- package/src/plugins/processor.js +6 -1
- package/src/route-renderer/GRAPH.md +81 -289
- package/src/route-renderer/README.md +67 -105
- package/src/route-renderer/orchestration/component-render-context.d.ts +24 -18
- package/src/route-renderer/orchestration/component-render-context.js +14 -14
- package/src/route-renderer/orchestration/declared-ownership-graph.d.ts +18 -0
- package/src/route-renderer/orchestration/declared-ownership-graph.js +34 -0
- package/src/route-renderer/orchestration/foreign-subtree-execution.service.d.ts +108 -0
- package/src/route-renderer/orchestration/foreign-subtree-execution.service.js +206 -0
- package/src/route-renderer/orchestration/integration-renderer.d.ts +96 -136
- package/src/route-renderer/orchestration/integration-renderer.js +280 -303
- package/src/route-renderer/orchestration/ownership-planning.service.d.ts +24 -0
- package/src/route-renderer/orchestration/ownership-planning.service.js +63 -0
- package/src/route-renderer/orchestration/ownership-validation.service.d.ts +29 -0
- package/src/route-renderer/orchestration/ownership-validation.service.js +53 -0
- package/src/route-renderer/orchestration/queued-foreign-subtree-resolution.service.d.ts +90 -0
- package/src/route-renderer/orchestration/{queued-boundary-runtime.service.js → queued-foreign-subtree-resolution.service.js} +28 -25
- package/src/route-renderer/orchestration/render-output.utils.d.ts +3 -3
- package/src/route-renderer/orchestration/render-output.utils.js +6 -6
- package/src/route-renderer/orchestration/route-render-orchestrator.d.ts +120 -0
- package/src/route-renderer/orchestration/{render-preparation.service.js → route-render-orchestrator.js} +132 -108
- package/src/route-renderer/page-loading/component-dependency-collection.js +8 -1
- package/src/route-renderer/page-loading/dependency-resolver.js +5 -7
- package/src/route-renderer/page-loading/page-dependency-bundling.d.ts +1 -1
- package/src/route-renderer/page-loading/page-dependency-bundling.js +41 -19
- package/src/route-renderer/route-renderer.d.ts +28 -26
- package/src/route-renderer/route-renderer.js +4 -27
- package/src/router/README.md +16 -19
- package/src/router/server/route-registry.d.ts +78 -0
- package/src/router/server/route-registry.js +262 -0
- package/src/services/README.md +1 -2
- package/src/services/assets/asset-processing-service/assets.types.d.ts +3 -0
- package/src/services/assets/asset-processing-service/index.d.ts +1 -0
- package/src/services/assets/asset-processing-service/index.js +1 -0
- package/src/services/assets/asset-processing-service/page-package.d.ts +3 -0
- package/src/services/assets/asset-processing-service/page-package.js +74 -0
- package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +4 -4
- package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +6 -3
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +9 -3
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +4 -2
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +2 -1
- package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +3 -1
- package/src/services/module-loading/node-bootstrap-plugin.js +15 -3
- package/src/static-site-generator/static-site-generator.d.ts +20 -21
- package/src/static-site-generator/static-site-generator.js +107 -140
- package/src/types/internal-types.d.ts +13 -12
- package/src/types/public-types.d.ts +46 -36
- package/src/watchers/project-watcher.test-helpers.js +5 -5
- package/src/route-renderer/orchestration/boundary-planning.service.d.ts +0 -25
- package/src/route-renderer/orchestration/boundary-planning.service.js +0 -97
- package/src/route-renderer/orchestration/page-packaging.service.d.ts +0 -16
- package/src/route-renderer/orchestration/page-packaging.service.js +0 -66
- package/src/route-renderer/orchestration/queued-boundary-runtime.service.d.ts +0 -89
- package/src/route-renderer/orchestration/render-execution.service.d.ts +0 -43
- package/src/route-renderer/orchestration/render-execution.service.js +0 -106
- package/src/route-renderer/orchestration/render-preparation.service.d.ts +0 -120
- package/src/route-renderer/orchestration/route-shell-composer.service.d.ts +0 -50
- package/src/route-renderer/orchestration/route-shell-composer.service.js +0 -81
- package/src/router/server/fs-router-scanner.d.ts +0 -41
- package/src/router/server/fs-router-scanner.js +0 -161
- package/src/router/server/fs-router.d.ts +0 -26
- package/src/router/server/fs-router.js +0 -100
- package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +0 -69
- package/src/services/runtime-state/runtime-specifier-registry.service.js +0 -37
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import type { EcoPagesAppConfig } from '../../types/internal-types.js';
|
|
2
|
-
import type { ComponentRenderResult, EcoComponent, EcoPageComponent, EcoPageFile, EcoPagesElement, GetMetadata, GetStaticProps, HtmlTemplateProps, IntegrationRendererRenderOptions, PageMetadataProps, RouteRendererOptions } from '../../types/public-types.js';
|
|
3
|
-
import { type AssetProcessingService, type ProcessedAsset } from '../../services/assets/asset-processing-service/index.js';
|
|
4
|
-
import { BoundaryPlanningService } from './boundary-planning.service.js';
|
|
5
|
-
import { PagePackagingService } from './page-packaging.service.js';
|
|
6
|
-
type ResolvedPageModule = {
|
|
7
|
-
Page: EcoPageFile['default'] | EcoPageComponent<any>;
|
|
8
|
-
getStaticProps?: GetStaticProps<Record<string, unknown>>;
|
|
9
|
-
getMetadata?: GetMetadata;
|
|
10
|
-
integrationSpecificProps: Record<string, unknown>;
|
|
11
|
-
};
|
|
12
|
-
export interface RenderPreparationCallbacks {
|
|
13
|
-
resolvePageModule(file: string): Promise<ResolvedPageModule>;
|
|
14
|
-
getHtmlTemplate(): Promise<EcoComponent<HtmlTemplateProps>>;
|
|
15
|
-
resolvePageData(pageModule: {
|
|
16
|
-
getStaticProps?: GetStaticProps<Record<string, unknown>>;
|
|
17
|
-
getMetadata?: GetMetadata;
|
|
18
|
-
}, routeOptions: RouteRendererOptions): Promise<{
|
|
19
|
-
props: Record<string, unknown>;
|
|
20
|
-
metadata: PageMetadataProps;
|
|
21
|
-
}>;
|
|
22
|
-
resolveDependencies(components: (EcoComponent | Partial<EcoComponent>)[]): Promise<ProcessedAsset[]>;
|
|
23
|
-
buildRouteRenderAssets(file: string): Promise<ProcessedAsset[]> | undefined;
|
|
24
|
-
shouldRenderPageComponent(input: {
|
|
25
|
-
Page: EcoComponent;
|
|
26
|
-
Layout?: EcoComponent;
|
|
27
|
-
options: RouteRendererOptions;
|
|
28
|
-
}): boolean;
|
|
29
|
-
renderPageComponent(input: {
|
|
30
|
-
component: EcoComponent;
|
|
31
|
-
props: Record<string, unknown>;
|
|
32
|
-
}): Promise<ComponentRenderResult>;
|
|
33
|
-
}
|
|
34
|
-
export interface RenderPreparationServiceDependencies {
|
|
35
|
-
boundaryPlanningService?: BoundaryPlanningService;
|
|
36
|
-
pagePackagingService?: PagePackagingService;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Prepares the normalized render inputs consumed by `IntegrationRenderer.execute()`.
|
|
40
|
-
*
|
|
41
|
-
* This service owns the orchestration that happens before the main HTML render:
|
|
42
|
-
* page module resolution, data loading, dependency aggregation, page-root
|
|
43
|
-
* component artifact capture, lazy trigger bootstrap generation, and request
|
|
44
|
-
* locals policy.
|
|
45
|
-
*/
|
|
46
|
-
export declare class RenderPreparationService {
|
|
47
|
-
private appConfig;
|
|
48
|
-
private assetProcessingService;
|
|
49
|
-
private readonly boundaryPlanningService;
|
|
50
|
-
private readonly pagePackagingService;
|
|
51
|
-
/**
|
|
52
|
-
* Creates the render-preparation orchestrator for one app instance.
|
|
53
|
-
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* The service is app-scoped because it depends on finalized config defaults and
|
|
56
|
-
* the app-owned asset-processing pipeline while remaining renderer-agnostic.
|
|
57
|
-
*/
|
|
58
|
-
constructor(appConfig: EcoPagesAppConfig, assetProcessingService: AssetProcessingService, dependencies?: RenderPreparationServiceDependencies);
|
|
59
|
-
/**
|
|
60
|
-
* Builds the final render options object used by the integration-specific
|
|
61
|
-
* renderer.
|
|
62
|
-
*
|
|
63
|
-
* The returned object contains normalized page data, processed dependency
|
|
64
|
-
* state, component render artifacts, and the locals contract expected by the
|
|
65
|
-
* rest of the pipeline.
|
|
66
|
-
*
|
|
67
|
-
* @typeParam C Integration render output element type.
|
|
68
|
-
* @param routeOptions Route-level render inputs.
|
|
69
|
-
* @param currentIntegrationName Active integration name for this preparation pass.
|
|
70
|
-
* @param callbacks Renderer-specific hooks used during preparation.
|
|
71
|
-
* @returns Normalized render options.
|
|
72
|
-
*/
|
|
73
|
-
prepare<C = EcoPagesElement>(routeOptions: RouteRendererOptions, currentIntegrationName: string, callbacks: RenderPreparationCallbacks): Promise<IntegrationRendererRenderOptions<C>>;
|
|
74
|
-
/**
|
|
75
|
-
* Collects resolved lazy trigger metadata from the component tree.
|
|
76
|
-
*
|
|
77
|
-
* Traversal is depth-first and deduplicated by component identity so shared
|
|
78
|
-
* component dependencies do not emit duplicate trigger sets.
|
|
79
|
-
*
|
|
80
|
-
* @param components Root component set.
|
|
81
|
-
* @param seen Internal visited set for shared graphs.
|
|
82
|
-
* @returns All resolved lazy triggers reachable from the root set.
|
|
83
|
-
*/
|
|
84
|
-
private collectResolvedTriggers;
|
|
85
|
-
/**
|
|
86
|
-
* Collects global integration dependencies used by nested components belonging
|
|
87
|
-
* to integrations other than the current renderer.
|
|
88
|
-
*
|
|
89
|
-
* @param components Root component set.
|
|
90
|
-
* @returns Processed integration dependencies contributed by nested integrations.
|
|
91
|
-
*/
|
|
92
|
-
private collectUsedIntegrationDependencies;
|
|
93
|
-
/**
|
|
94
|
-
* Discovers integration names referenced by the component dependency graph.
|
|
95
|
-
*
|
|
96
|
-
* @param components Root component set.
|
|
97
|
-
* @param seen Internal visited set for shared graphs.
|
|
98
|
-
* @returns Set of integration names found in the graph.
|
|
99
|
-
*/
|
|
100
|
-
private collectIntegrationNames;
|
|
101
|
-
/**
|
|
102
|
-
* Renders the page root through the component-level render contract so any
|
|
103
|
-
* integration-specific assets and root attributes are available before the main
|
|
104
|
-
* document render.
|
|
105
|
-
*
|
|
106
|
-
* @param input Page root render inputs.
|
|
107
|
-
* @returns Structured component render result.
|
|
108
|
-
*/
|
|
109
|
-
private renderPageRoot;
|
|
110
|
-
/**
|
|
111
|
-
* Builds the runtime assets needed to bootstrap global lazy trigger execution.
|
|
112
|
-
*
|
|
113
|
-
* @param triggers Fully resolved lazy trigger definitions.
|
|
114
|
-
* @returns Processed assets that should be merged into the final dependency set.
|
|
115
|
-
*/
|
|
116
|
-
private buildGlobalInjectorAssets;
|
|
117
|
-
private buildEagerSsrLazyAssets;
|
|
118
|
-
private collectEagerSsrLazyDependencies;
|
|
119
|
-
}
|
|
120
|
-
export {};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { ComponentRenderInput, ComponentRenderResult, EcoComponent, HtmlTemplateProps, PageMetadataProps } from '../../types/public-types.js';
|
|
2
|
-
import type { ProcessedAsset } from '../../services/assets/asset-processing-service/index.js';
|
|
3
|
-
import type { RenderToResponseContext } from './integration-renderer.js';
|
|
4
|
-
export interface RouteShellComposerCallbacks {
|
|
5
|
-
hasForeignBoundaryDescendants(component: EcoComponent): boolean;
|
|
6
|
-
createHtmlResponse(body: BodyInit, ctx: RenderToResponseContext): Response;
|
|
7
|
-
renderComponentBoundary(input: ComponentRenderInput): Promise<ComponentRenderResult>;
|
|
8
|
-
prepareViewDependencies(view: EcoComponent, layout?: EcoComponent): Promise<ProcessedAsset[]>;
|
|
9
|
-
getHtmlTemplate(): Promise<EcoComponent<HtmlTemplateProps>>;
|
|
10
|
-
resolveViewMetadata<P>(view: EcoComponent<P>, props: P): Promise<PageMetadataProps>;
|
|
11
|
-
appendProcessedDependencies(...assetGroups: Array<readonly ProcessedAsset[] | undefined>): ProcessedAsset[];
|
|
12
|
-
finalizeResolvedHtml(options: {
|
|
13
|
-
html: string;
|
|
14
|
-
partial?: boolean;
|
|
15
|
-
componentRootAttributes?: Record<string, string>;
|
|
16
|
-
documentAttributes?: Record<string, string>;
|
|
17
|
-
transformHtml?: boolean;
|
|
18
|
-
}): Promise<string>;
|
|
19
|
-
docType: string;
|
|
20
|
-
}
|
|
21
|
-
export declare class RouteShellComposer {
|
|
22
|
-
renderPartialViewResponse<P>(input: {
|
|
23
|
-
view: EcoComponent<P>;
|
|
24
|
-
props: P;
|
|
25
|
-
ctx: RenderToResponseContext;
|
|
26
|
-
renderInline?: () => Promise<BodyInit>;
|
|
27
|
-
transformHtml?: (html: string) => string;
|
|
28
|
-
}, callbacks: RouteShellComposerCallbacks): Promise<Response>;
|
|
29
|
-
renderViewWithDocumentShell<P>(input: {
|
|
30
|
-
view: EcoComponent<P>;
|
|
31
|
-
props: P;
|
|
32
|
-
ctx: RenderToResponseContext;
|
|
33
|
-
layout?: EcoComponent;
|
|
34
|
-
}, callbacks: RouteShellComposerCallbacks): Promise<Response>;
|
|
35
|
-
renderPageWithDocumentShell(input: {
|
|
36
|
-
page: {
|
|
37
|
-
component: EcoComponent;
|
|
38
|
-
props: Record<string, unknown>;
|
|
39
|
-
};
|
|
40
|
-
layout?: {
|
|
41
|
-
component: EcoComponent;
|
|
42
|
-
props?: Record<string, unknown>;
|
|
43
|
-
};
|
|
44
|
-
htmlTemplate: EcoComponent;
|
|
45
|
-
metadata: PageMetadataProps;
|
|
46
|
-
pageProps: Record<string, unknown>;
|
|
47
|
-
documentProps?: Record<string, unknown>;
|
|
48
|
-
transformDocumentHtml?: (html: string) => string;
|
|
49
|
-
}, callbacks: RouteShellComposerCallbacks): Promise<string>;
|
|
50
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
class RouteShellComposer {
|
|
2
|
-
async renderPartialViewResponse(input, callbacks) {
|
|
3
|
-
if (input.renderInline && !callbacks.hasForeignBoundaryDescendants(input.view)) {
|
|
4
|
-
return callbacks.createHtmlResponse(await input.renderInline(), input.ctx);
|
|
5
|
-
}
|
|
6
|
-
const rendererCache = /* @__PURE__ */ new Map();
|
|
7
|
-
const viewRender = await callbacks.renderComponentBoundary({
|
|
8
|
-
component: input.view,
|
|
9
|
-
props: input.props ?? {},
|
|
10
|
-
integrationContext: { rendererCache }
|
|
11
|
-
});
|
|
12
|
-
const html = input.transformHtml ? input.transformHtml(viewRender.html) : viewRender.html;
|
|
13
|
-
return callbacks.createHtmlResponse(html, input.ctx);
|
|
14
|
-
}
|
|
15
|
-
async renderViewWithDocumentShell(input, callbacks) {
|
|
16
|
-
const normalizedProps = input.props ?? {};
|
|
17
|
-
if (input.ctx.partial) {
|
|
18
|
-
return this.renderPartialViewResponse(input, callbacks);
|
|
19
|
-
}
|
|
20
|
-
await callbacks.prepareViewDependencies(input.view, input.layout);
|
|
21
|
-
const HtmlTemplate = await callbacks.getHtmlTemplate();
|
|
22
|
-
const metadata = await callbacks.resolveViewMetadata(input.view, input.props);
|
|
23
|
-
const rendererCache = /* @__PURE__ */ new Map();
|
|
24
|
-
const viewRender = await callbacks.renderComponentBoundary({
|
|
25
|
-
component: input.view,
|
|
26
|
-
props: normalizedProps,
|
|
27
|
-
integrationContext: { rendererCache }
|
|
28
|
-
});
|
|
29
|
-
const layoutRender = input.layout ? await callbacks.renderComponentBoundary({
|
|
30
|
-
component: input.layout,
|
|
31
|
-
props: {},
|
|
32
|
-
children: viewRender.html,
|
|
33
|
-
integrationContext: { rendererCache }
|
|
34
|
-
}) : void 0;
|
|
35
|
-
const documentRender = await callbacks.renderComponentBoundary({
|
|
36
|
-
component: HtmlTemplate,
|
|
37
|
-
props: {
|
|
38
|
-
metadata,
|
|
39
|
-
pageProps: normalizedProps
|
|
40
|
-
},
|
|
41
|
-
children: layoutRender?.html ?? viewRender.html,
|
|
42
|
-
integrationContext: { rendererCache }
|
|
43
|
-
});
|
|
44
|
-
callbacks.appendProcessedDependencies(viewRender.assets, layoutRender?.assets, documentRender.assets);
|
|
45
|
-
const html = await callbacks.finalizeResolvedHtml({
|
|
46
|
-
html: `${callbacks.docType}${documentRender.html}`,
|
|
47
|
-
partial: false
|
|
48
|
-
});
|
|
49
|
-
return callbacks.createHtmlResponse(html, input.ctx);
|
|
50
|
-
}
|
|
51
|
-
async renderPageWithDocumentShell(input, callbacks) {
|
|
52
|
-
const rendererCache = /* @__PURE__ */ new Map();
|
|
53
|
-
const pageRender = await callbacks.renderComponentBoundary({
|
|
54
|
-
component: input.page.component,
|
|
55
|
-
props: input.page.props,
|
|
56
|
-
integrationContext: { rendererCache }
|
|
57
|
-
});
|
|
58
|
-
const layoutRender = input.layout ? await callbacks.renderComponentBoundary({
|
|
59
|
-
component: input.layout.component,
|
|
60
|
-
props: input.layout.props ?? {},
|
|
61
|
-
children: pageRender.html,
|
|
62
|
-
integrationContext: { rendererCache }
|
|
63
|
-
}) : void 0;
|
|
64
|
-
const documentRender = await callbacks.renderComponentBoundary({
|
|
65
|
-
component: input.htmlTemplate,
|
|
66
|
-
props: {
|
|
67
|
-
metadata: input.metadata,
|
|
68
|
-
pageProps: input.pageProps,
|
|
69
|
-
...input.documentProps ?? {}
|
|
70
|
-
},
|
|
71
|
-
children: layoutRender?.html ?? pageRender.html,
|
|
72
|
-
integrationContext: { rendererCache }
|
|
73
|
-
});
|
|
74
|
-
callbacks.appendProcessedDependencies(pageRender.assets, layoutRender?.assets, documentRender.assets);
|
|
75
|
-
const documentHtml = input.transformDocumentHtml ? input.transformDocumentHtml(documentRender.html) : documentRender.html;
|
|
76
|
-
return `${callbacks.docType}${documentHtml}`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export {
|
|
80
|
-
RouteShellComposer
|
|
81
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { EcoPagesAppConfig, Routes } from '../../types/internal-types.js';
|
|
2
|
-
type FSRouterScannerOptions = {
|
|
3
|
-
buildMode: boolean;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* @class FSRouterScanner
|
|
7
|
-
* @description
|
|
8
|
-
* This class is responsible for scanning the file system for routes.
|
|
9
|
-
* It uses the glob package to scan the file system for files with the specified file extensions.
|
|
10
|
-
* It then creates a map of the routes with the pathname as the key.
|
|
11
|
-
* The pathname is the route without the file extension.
|
|
12
|
-
* For example, if the file is "index.tsx", the pathname will be "/index".
|
|
13
|
-
* If the file is "blog/[slug].tsx", the pathname will be "/blog/[slug]".
|
|
14
|
-
* If the file is "blog/[...slug].tsx", the pathname will be "/blog/[...slug]".
|
|
15
|
-
*/
|
|
16
|
-
export declare class FSRouterScanner {
|
|
17
|
-
private dir;
|
|
18
|
-
private origin;
|
|
19
|
-
private templatesExt;
|
|
20
|
-
private options;
|
|
21
|
-
readonly appConfig: EcoPagesAppConfig;
|
|
22
|
-
routes: Routes;
|
|
23
|
-
private serverModuleTranspiler;
|
|
24
|
-
constructor({ dir, origin, templatesExt, options, appConfig, }: {
|
|
25
|
-
dir: string;
|
|
26
|
-
origin: string;
|
|
27
|
-
templatesExt: string[];
|
|
28
|
-
options: FSRouterScannerOptions;
|
|
29
|
-
appConfig: EcoPagesAppConfig;
|
|
30
|
-
});
|
|
31
|
-
private getRoutePath;
|
|
32
|
-
private getDynamicParamsNames;
|
|
33
|
-
private getStaticPathsFromDynamicRoute;
|
|
34
|
-
private createStaticRoutes;
|
|
35
|
-
private handleDynamicRouteCreation;
|
|
36
|
-
private importPageModule;
|
|
37
|
-
private createRoute;
|
|
38
|
-
private getRouteData;
|
|
39
|
-
scan(): Promise<Routes>;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { appLogger } from "../../global/app-logger.js";
|
|
3
|
-
import { fileSystem } from "@ecopages/file-system";
|
|
4
|
-
import { invariant } from "../../utils/invariant.js";
|
|
5
|
-
import { existsSync } from "node:fs";
|
|
6
|
-
import { getAppServerModuleTranspiler } from "../../services/module-loading/app-server-module-transpiler.service.js";
|
|
7
|
-
import { resolveInternalExecutionDir } from "../../utils/resolve-work-dir.js";
|
|
8
|
-
class FSRouterScanner {
|
|
9
|
-
dir;
|
|
10
|
-
origin = "";
|
|
11
|
-
templatesExt;
|
|
12
|
-
options;
|
|
13
|
-
appConfig;
|
|
14
|
-
routes = {};
|
|
15
|
-
serverModuleTranspiler;
|
|
16
|
-
constructor({
|
|
17
|
-
dir,
|
|
18
|
-
origin,
|
|
19
|
-
templatesExt,
|
|
20
|
-
options,
|
|
21
|
-
appConfig
|
|
22
|
-
}) {
|
|
23
|
-
this.dir = dir;
|
|
24
|
-
this.origin = origin;
|
|
25
|
-
this.templatesExt = templatesExt;
|
|
26
|
-
this.options = options;
|
|
27
|
-
this.appConfig = appConfig;
|
|
28
|
-
this.serverModuleTranspiler = getAppServerModuleTranspiler(appConfig);
|
|
29
|
-
}
|
|
30
|
-
getRoutePath(path2) {
|
|
31
|
-
const cleanedRoute = this.templatesExt.reduce((route, ext) => route.replace(ext, ""), path2).replace(/\/?index$/, "");
|
|
32
|
-
return `/${cleanedRoute}`;
|
|
33
|
-
}
|
|
34
|
-
getDynamicParamsNames(route) {
|
|
35
|
-
const matches = route.match(/\[.*?\]/g);
|
|
36
|
-
return matches ? matches.map((match) => match.slice(1, -1)) : [];
|
|
37
|
-
}
|
|
38
|
-
async getStaticPathsFromDynamicRoute({
|
|
39
|
-
route,
|
|
40
|
-
filePath,
|
|
41
|
-
getStaticPaths
|
|
42
|
-
}) {
|
|
43
|
-
const staticPaths = await getStaticPaths({
|
|
44
|
-
appConfig: this.appConfig,
|
|
45
|
-
runtimeOrigin: this.origin
|
|
46
|
-
});
|
|
47
|
-
return staticPaths.paths.map((path2) => {
|
|
48
|
-
const dynamicParamsNames = this.getDynamicParamsNames(filePath);
|
|
49
|
-
let routeWithParams = route;
|
|
50
|
-
for (const param of dynamicParamsNames) {
|
|
51
|
-
routeWithParams = routeWithParams.replace(`[${param}]`, path2.params[param]);
|
|
52
|
-
}
|
|
53
|
-
return routeWithParams;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
async createStaticRoutes({
|
|
57
|
-
filePath,
|
|
58
|
-
route,
|
|
59
|
-
routePath,
|
|
60
|
-
getStaticPaths
|
|
61
|
-
}) {
|
|
62
|
-
try {
|
|
63
|
-
const routesWithParams = await this.getStaticPathsFromDynamicRoute({
|
|
64
|
-
route,
|
|
65
|
-
filePath,
|
|
66
|
-
getStaticPaths
|
|
67
|
-
});
|
|
68
|
-
for (const routeWithParams of routesWithParams) {
|
|
69
|
-
this.createRoute("dynamic", { filePath, route: routeWithParams, routePath });
|
|
70
|
-
}
|
|
71
|
-
} catch (error) {
|
|
72
|
-
appLogger.error(`[ecopages] Error creating static routes for ${filePath}: ${error}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async handleDynamicRouteCreation({ filePath, route, routePath }) {
|
|
76
|
-
const module = await this.importPageModule(filePath);
|
|
77
|
-
const Page = module.default;
|
|
78
|
-
const getStaticPaths = Page?.staticPaths ?? module.getStaticPaths;
|
|
79
|
-
const getStaticProps = Page?.staticProps ?? module.getStaticProps;
|
|
80
|
-
if (this.options.buildMode) {
|
|
81
|
-
invariant(getStaticProps !== void 0, `[ecopages] Missing getStaticProps in ${filePath}`);
|
|
82
|
-
invariant(getStaticPaths !== void 0, `[ecopages] Missing getStaticPaths in ${filePath}`);
|
|
83
|
-
}
|
|
84
|
-
if (getStaticPaths) {
|
|
85
|
-
return this.createStaticRoutes({
|
|
86
|
-
filePath,
|
|
87
|
-
route,
|
|
88
|
-
routePath,
|
|
89
|
-
getStaticPaths
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
return this.createRoute("dynamic", { filePath, route, routePath });
|
|
93
|
-
}
|
|
94
|
-
async importPageModule(filePath) {
|
|
95
|
-
return this.serverModuleTranspiler.importModule({
|
|
96
|
-
filePath,
|
|
97
|
-
outdir: path.join(resolveInternalExecutionDir(this.appConfig), ".server-route-modules"),
|
|
98
|
-
externalPackages: false,
|
|
99
|
-
transpileErrorMessage: (details) => `Error transpiling route module: ${details}`,
|
|
100
|
-
noOutputMessage: (targetFilePath) => `No transpiled output generated for route module: ${targetFilePath}`
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
createRoute(kind, { filePath, route, routePath }) {
|
|
104
|
-
this.routes[route] = {
|
|
105
|
-
kind,
|
|
106
|
-
pathname: routePath,
|
|
107
|
-
filePath
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
getRouteData(file) {
|
|
111
|
-
const routePath = this.getRoutePath(file);
|
|
112
|
-
const route = `${this.origin}${routePath}`;
|
|
113
|
-
const filePath = path.join(this.dir, file);
|
|
114
|
-
const isCatchAll = filePath.includes("[...");
|
|
115
|
-
const isDynamic = !isCatchAll && filePath.includes("[") && filePath.includes("]");
|
|
116
|
-
let kind = "exact";
|
|
117
|
-
if (isCatchAll) {
|
|
118
|
-
kind = "catch-all";
|
|
119
|
-
} else if (isDynamic) {
|
|
120
|
-
kind = "dynamic";
|
|
121
|
-
}
|
|
122
|
-
return { route, routePath, filePath, kind };
|
|
123
|
-
}
|
|
124
|
-
async scan() {
|
|
125
|
-
this.routes = {};
|
|
126
|
-
if (!existsSync(this.dir)) {
|
|
127
|
-
return this.routes;
|
|
128
|
-
}
|
|
129
|
-
const scannedFiles = await fileSystem.glob(
|
|
130
|
-
this.templatesExt.map((ext) => `**/*${ext}`),
|
|
131
|
-
{ cwd: this.dir }
|
|
132
|
-
);
|
|
133
|
-
for await (const file of scannedFiles) {
|
|
134
|
-
if (file.includes(".ecopages-node.")) {
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
const { kind, ...routeData } = this.getRouteData(file);
|
|
138
|
-
switch (kind) {
|
|
139
|
-
case "dynamic":
|
|
140
|
-
await this.handleDynamicRouteCreation(routeData);
|
|
141
|
-
break;
|
|
142
|
-
case "catch-all":
|
|
143
|
-
if (this.options.buildMode) {
|
|
144
|
-
appLogger.warn(
|
|
145
|
-
"Catch-all routes are not supported in static generation, they will not be included in the bundle\n",
|
|
146
|
-
`\u27A4 ${routeData.filePath}`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
this.createRoute(kind, routeData);
|
|
150
|
-
break;
|
|
151
|
-
default:
|
|
152
|
-
this.createRoute(kind, routeData);
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return this.routes;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
export {
|
|
160
|
-
FSRouterScanner
|
|
161
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { MatchResult, Route, Routes } from '../../types/internal-types.js';
|
|
2
|
-
import type { FSRouterScanner } from './fs-router-scanner.js';
|
|
3
|
-
/**
|
|
4
|
-
* A class that manages the routes of the file system.
|
|
5
|
-
* It scans the file system for files with the specified extensions and creates a map of routes.
|
|
6
|
-
* It also provides a method to match a request to a route.
|
|
7
|
-
* It can be used to reload the routes when the file system changes.
|
|
8
|
-
*/
|
|
9
|
-
export declare class FSRouter {
|
|
10
|
-
origin: string;
|
|
11
|
-
assetPrefix: string;
|
|
12
|
-
routes: Routes;
|
|
13
|
-
scanner: FSRouterScanner;
|
|
14
|
-
onReload?: () => void;
|
|
15
|
-
constructor({ origin, assetPrefix, scanner }: {
|
|
16
|
-
origin: string;
|
|
17
|
-
assetPrefix: string;
|
|
18
|
-
scanner: FSRouterScanner;
|
|
19
|
-
});
|
|
20
|
-
init(): Promise<void>;
|
|
21
|
-
getDynamicParams(route: Route, pathname: string): Record<string, string | string[]>;
|
|
22
|
-
getSearchParams(url: URL): Record<string, string>;
|
|
23
|
-
match(requestUrl: string): MatchResult | null;
|
|
24
|
-
setOnReload(cb: () => void): void;
|
|
25
|
-
reload(): void;
|
|
26
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { appLogger } from "../../global/app-logger.js";
|
|
2
|
-
class FSRouter {
|
|
3
|
-
origin;
|
|
4
|
-
assetPrefix;
|
|
5
|
-
routes = {};
|
|
6
|
-
scanner;
|
|
7
|
-
onReload;
|
|
8
|
-
constructor({ origin, assetPrefix, scanner }) {
|
|
9
|
-
this.origin = origin;
|
|
10
|
-
this.assetPrefix = assetPrefix;
|
|
11
|
-
this.scanner = scanner;
|
|
12
|
-
}
|
|
13
|
-
async init() {
|
|
14
|
-
this.routes = await this.scanner.scan();
|
|
15
|
-
appLogger.debug("FSRouter initialized", this.routes);
|
|
16
|
-
}
|
|
17
|
-
getDynamicParams(route, pathname) {
|
|
18
|
-
const params = {};
|
|
19
|
-
const routeParts = route.pathname.split("/");
|
|
20
|
-
const pathnameParts = pathname.split("/");
|
|
21
|
-
for (let i = 0; i < routeParts.length; i++) {
|
|
22
|
-
const part = routeParts[i];
|
|
23
|
-
if (part.startsWith("[") && part.endsWith("]")) {
|
|
24
|
-
if (part.startsWith("[...")) {
|
|
25
|
-
const param2 = part.slice(4, -1);
|
|
26
|
-
params[param2] = pathnameParts.slice(i);
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
const param = part.slice(1, -1);
|
|
30
|
-
params[param] = pathnameParts[i];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return params;
|
|
34
|
-
}
|
|
35
|
-
getSearchParams(url) {
|
|
36
|
-
const query = {};
|
|
37
|
-
for (const [key, value] of url.searchParams) {
|
|
38
|
-
query[key] = value;
|
|
39
|
-
}
|
|
40
|
-
return query;
|
|
41
|
-
}
|
|
42
|
-
match(requestUrl) {
|
|
43
|
-
const url = new URL(requestUrl);
|
|
44
|
-
const pathname = url.pathname.replace(this.origin, "");
|
|
45
|
-
const routeValues = Object.values(this.routes);
|
|
46
|
-
for (const route of routeValues) {
|
|
47
|
-
if (route.kind === "exact" && (pathname === route.pathname || pathname === `${route.pathname}/`)) {
|
|
48
|
-
return {
|
|
49
|
-
filePath: route.filePath,
|
|
50
|
-
kind: "exact",
|
|
51
|
-
pathname: route.pathname,
|
|
52
|
-
query: this.getSearchParams(url)
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
for (const route of routeValues) {
|
|
57
|
-
const cleanPathname = route.pathname.replace(/\[.*?\]/g, "");
|
|
58
|
-
const isValidDynamicRoute = pathname.includes(cleanPathname);
|
|
59
|
-
if (route.kind === "dynamic" && isValidDynamicRoute) {
|
|
60
|
-
const routeParts = route.pathname.split("/");
|
|
61
|
-
const pathnameParts = pathname.split("/");
|
|
62
|
-
if (routeParts.length === pathnameParts.length) {
|
|
63
|
-
return {
|
|
64
|
-
filePath: route.filePath,
|
|
65
|
-
kind: "dynamic",
|
|
66
|
-
pathname,
|
|
67
|
-
query: this.getSearchParams(url),
|
|
68
|
-
params: this.getDynamicParams(route, pathname)
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
for (const route of routeValues) {
|
|
74
|
-
const cleanPathname = route.pathname.replace(/\[.*?\]/g, "");
|
|
75
|
-
const isValidCatchAllRoute = pathname.includes(cleanPathname);
|
|
76
|
-
if (route.kind === "catch-all" && isValidCatchAllRoute) {
|
|
77
|
-
return {
|
|
78
|
-
filePath: route.filePath,
|
|
79
|
-
kind: "catch-all",
|
|
80
|
-
pathname,
|
|
81
|
-
query: this.getSearchParams(url),
|
|
82
|
-
params: this.getDynamicParams(route, pathname)
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
setOnReload(cb) {
|
|
89
|
-
this.onReload = cb;
|
|
90
|
-
}
|
|
91
|
-
reload() {
|
|
92
|
-
this.init();
|
|
93
|
-
if (this.onReload) {
|
|
94
|
-
this.onReload();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
export {
|
|
99
|
-
FSRouter
|
|
100
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { EcoPagesAppConfig } from '../../types/internal-types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Stores runtime-visible bare-specifier mappings for one app instance.
|
|
4
|
-
*
|
|
5
|
-
* @remarks
|
|
6
|
-
* Integrations populate this registry during runtime setup when they expose
|
|
7
|
-
* browser runtime modules through stable bare imports. Build and HMR code later
|
|
8
|
-
* consume the collected map to create aliasing and bootstrap behavior without
|
|
9
|
-
* forcing integrations to own global registry state.
|
|
10
|
-
*/
|
|
11
|
-
export interface RuntimeSpecifierRegistry {
|
|
12
|
-
/**
|
|
13
|
-
* Merges a new batch of specifier mappings into the registry.
|
|
14
|
-
*
|
|
15
|
-
* @remarks
|
|
16
|
-
* Later registrations replace earlier URLs for the same specifier. This keeps
|
|
17
|
-
* runtime setup deterministic while still allowing an integration to refresh
|
|
18
|
-
* its own declarations during one app session.
|
|
19
|
-
*/
|
|
20
|
-
register(map: Record<string, string>): void;
|
|
21
|
-
/**
|
|
22
|
-
* Returns the current registry contents.
|
|
23
|
-
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* The returned map is the live backing map for the registry implementation, so
|
|
26
|
-
* callers should treat it as read-only unless they intentionally own registry
|
|
27
|
-
* mutation semantics.
|
|
28
|
-
*/
|
|
29
|
-
getAll(): Map<string, string>;
|
|
30
|
-
/**
|
|
31
|
-
* Removes all registered specifiers for the current app/runtime instance.
|
|
32
|
-
*/
|
|
33
|
-
clear(): void;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Default in-memory runtime specifier registry used by core.
|
|
37
|
-
*
|
|
38
|
-
* @remarks
|
|
39
|
-
* Runtime specifier maps are app-local bootstrap metadata, not durable build
|
|
40
|
-
* artifacts, so the default implementation stays intentionally small.
|
|
41
|
-
*/
|
|
42
|
-
export declare class InMemoryRuntimeSpecifierRegistry implements RuntimeSpecifierRegistry {
|
|
43
|
-
private readonly specifierMap;
|
|
44
|
-
/**
|
|
45
|
-
* Merges one integration-provided mapping set into the app registry.
|
|
46
|
-
*/
|
|
47
|
-
register(map: Record<string, string>): void;
|
|
48
|
-
/**
|
|
49
|
-
* Returns the live app-owned mapping table.
|
|
50
|
-
*/
|
|
51
|
-
getAll(): Map<string, string>;
|
|
52
|
-
/**
|
|
53
|
-
* Clears all mappings for the current runtime session.
|
|
54
|
-
*/
|
|
55
|
-
clear(): void;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns the runtime specifier registry owned by one app instance.
|
|
59
|
-
*
|
|
60
|
-
* @remarks
|
|
61
|
-
* Older tests and helpers may not seed runtime state explicitly yet, so this
|
|
62
|
-
* helper still provides an in-memory fallback when the app runtime has not been
|
|
63
|
-
* initialized.
|
|
64
|
-
*/
|
|
65
|
-
export declare function getAppRuntimeSpecifierRegistry(appConfig: EcoPagesAppConfig): RuntimeSpecifierRegistry;
|
|
66
|
-
/**
|
|
67
|
-
* Installs the runtime specifier registry that should back one app instance.
|
|
68
|
-
*/
|
|
69
|
-
export declare function setAppRuntimeSpecifierRegistry(appConfig: EcoPagesAppConfig, runtimeSpecifierRegistry: RuntimeSpecifierRegistry): void;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
class InMemoryRuntimeSpecifierRegistry {
|
|
2
|
-
specifierMap = /* @__PURE__ */ new Map();
|
|
3
|
-
/**
|
|
4
|
-
* Merges one integration-provided mapping set into the app registry.
|
|
5
|
-
*/
|
|
6
|
-
register(map) {
|
|
7
|
-
for (const [specifier, url] of Object.entries(map)) {
|
|
8
|
-
this.specifierMap.set(specifier, url);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns the live app-owned mapping table.
|
|
13
|
-
*/
|
|
14
|
-
getAll() {
|
|
15
|
-
return this.specifierMap;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Clears all mappings for the current runtime session.
|
|
19
|
-
*/
|
|
20
|
-
clear() {
|
|
21
|
-
this.specifierMap.clear();
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function getAppRuntimeSpecifierRegistry(appConfig) {
|
|
25
|
-
return appConfig.runtime?.runtimeSpecifierRegistry ?? new InMemoryRuntimeSpecifierRegistry();
|
|
26
|
-
}
|
|
27
|
-
function setAppRuntimeSpecifierRegistry(appConfig, runtimeSpecifierRegistry) {
|
|
28
|
-
appConfig.runtime = {
|
|
29
|
-
...appConfig.runtime ?? {},
|
|
30
|
-
runtimeSpecifierRegistry
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
InMemoryRuntimeSpecifierRegistry,
|
|
35
|
-
getAppRuntimeSpecifierRegistry,
|
|
36
|
-
setAppRuntimeSpecifierRegistry
|
|
37
|
-
};
|