@ecopages/core 0.7.1 → 0.9.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 +1 -1
- 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 +16 -11
- package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
- package/src/adapters/shared/runtime/render-context.d.ts +2 -0
- package/src/adapters/shared/runtime/render-context.js +4 -0
- 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/assets/asset-processing-service/processors/stylesheet/import-order.js +5 -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/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 +2 -1
- package/src/build.js +2 -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/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 +5 -5
- package/src/eco/eco.js +24 -5
- package/src/eco/migration-docs.d.ts +7 -0
- package/src/eco/migration-docs.js +7 -0
- 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/integration.d.ts +1 -1
- package/src/integration.js +1 -1
- package/src/islands/island-host.d.ts +16 -5
- package/src/islands/island-host.js +8 -1
- 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 +5 -0
- package/src/plugins/eco-component-meta-plugin.js +39 -22
- 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 +3 -2
- package/src/route-renderer/explicit-view-render-preparation.d.ts +10 -3
- package/src/route-renderer/explicit-view-render-preparation.js +14 -8
- 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 +39 -10
- package/src/route-renderer/orchestration/integration-renderer.js +74 -38
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +32 -11
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +68 -61
- 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 +10 -11
- package/src/route-renderer/page-loading/page-module-loader.js +30 -30
- 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 -1
- package/src/static-site-generator/static-site-generator.js +46 -12
- package/src/types/contracts.d.ts +28 -28
- package/src/types/eco-api-types.d.ts +17 -12
- package/src/types/public-types.d.ts +1 -1
- 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/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
|
@@ -42,7 +42,7 @@ export const STATIC_SITE_GENERATOR_ERRORS = {
|
|
|
42
42
|
unsupportedBodyType: (bodyType) => `Unsupported body type for static generation: ${bodyType}`,
|
|
43
43
|
missingIntegration: (routePath) => `View at ${routePath} is missing component identity integration. Ensure it's defined with eco.page().`,
|
|
44
44
|
noRendererForIntegration: (integrationName) => `No renderer found for integration: ${integrationName}`,
|
|
45
|
-
|
|
45
|
+
dynamicRouteRequiresPaths: (routePath) => `Dynamic route ${routePath} requires paths to be defined on the view.`,
|
|
46
46
|
};
|
|
47
47
|
async function runWithConcurrency(items, concurrency, worker) {
|
|
48
48
|
if (items.length === 0) {
|
|
@@ -236,6 +236,13 @@ export class StaticSiteGenerator {
|
|
|
236
236
|
routes: input.routes,
|
|
237
237
|
};
|
|
238
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Starts every Integration's static export.
|
|
241
|
+
*
|
|
242
|
+
* @remarks
|
|
243
|
+
* The caller runs this concurrently with planning and the browser-graph prebuild and awaits it before the
|
|
244
|
+
* first page render, the earliest point an export's output (the Lit render worker) is consumed.
|
|
245
|
+
*/
|
|
239
246
|
async startStaticExports(context) {
|
|
240
247
|
const releases = [];
|
|
241
248
|
try {
|
|
@@ -330,10 +337,10 @@ export class StaticSiteGenerator {
|
|
|
330
337
|
]);
|
|
331
338
|
const dynamicRouteTemplates = (input.router.templateRoutes ?? [])
|
|
332
339
|
.filter((route) => route.kind !== 'exact' && route.role === 'page' && !expandedRouteFiles.has(route.filePath))
|
|
333
|
-
.map((route) => ({ routeFile: route.filePath,
|
|
340
|
+
.map((route) => ({ routeFile: route.filePath, skipPropsHook: true, isRouteTemplate: true }));
|
|
334
341
|
const importedViews = getImportedViewPaths(this.appConfig).map((routeFile) => ({
|
|
335
342
|
routeFile,
|
|
336
|
-
|
|
343
|
+
skipPropsHook: true,
|
|
337
344
|
isRouteTemplate: true,
|
|
338
345
|
}));
|
|
339
346
|
const exportedRouteKeys = new Set(input.routes.map((route) => getPlannedRouteKey({ routeFile: route.templateRoute.filePath, params: route.params })));
|
|
@@ -360,6 +367,7 @@ export class StaticSiteGenerator {
|
|
|
360
367
|
else {
|
|
361
368
|
await resolveIntegrationDependencies({ appConfig: this.appConfig });
|
|
362
369
|
}
|
|
370
|
+
await input.staticExportsReady;
|
|
363
371
|
this.generateRobotsTxt();
|
|
364
372
|
const semanticErrorPathnames = new Set(SEMANTIC_ERROR_PAGE_PATHNAMES);
|
|
365
373
|
const pageRoutes = input.routes.filter((route) => !semanticErrorPathnames.has(route.pathname));
|
|
@@ -422,7 +430,7 @@ export class StaticSiteGenerator {
|
|
|
422
430
|
requireBrowserBuildGlobalScriptResolution(this.appConfig);
|
|
423
431
|
this.resetStaticGenerationState(force);
|
|
424
432
|
requireAppRuntime(this.appConfig).staticGenerationActive = true;
|
|
425
|
-
let
|
|
433
|
+
let staticExportsStarted;
|
|
426
434
|
let generationFailed = false;
|
|
427
435
|
let generationError;
|
|
428
436
|
try {
|
|
@@ -443,7 +451,8 @@ export class StaticSiteGenerator {
|
|
|
443
451
|
force,
|
|
444
452
|
routes: exportRoutes,
|
|
445
453
|
});
|
|
446
|
-
|
|
454
|
+
staticExportsStarted = this.startStaticExports(staticExportContext);
|
|
455
|
+
staticExportsStarted.catch(() => undefined);
|
|
447
456
|
try {
|
|
448
457
|
await this.executeStaticGenerationBody({
|
|
449
458
|
router,
|
|
@@ -456,6 +465,7 @@ export class StaticSiteGenerator {
|
|
|
456
465
|
pageFailures,
|
|
457
466
|
activeStaticPathnames,
|
|
458
467
|
sitemapEligiblePathnames,
|
|
468
|
+
staticExportsReady: staticExportsStarted,
|
|
459
469
|
});
|
|
460
470
|
}
|
|
461
471
|
catch (error) {
|
|
@@ -476,7 +486,28 @@ export class StaticSiteGenerator {
|
|
|
476
486
|
}
|
|
477
487
|
requireAppRuntime(this.appConfig).staticGenerationActive = false;
|
|
478
488
|
clearProductionAssetLedgerOnFailure(this.appConfig, generationFailed);
|
|
489
|
+
await this.cleanUpStaticGeneration({ staticExportsStarted, generationFailed, generationError });
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Releases the static exports, tears down the Integrations, and throws whatever failed.
|
|
493
|
+
*
|
|
494
|
+
* @remarks
|
|
495
|
+
* Static exports start while the generation runs, so they are awaited here even when generation failed; their
|
|
496
|
+
* own failure is reported only when it is not the error generation already threw. Every cleanup step runs,
|
|
497
|
+
* and a generation error is thrown together with any cleanup errors.
|
|
498
|
+
*/
|
|
499
|
+
async cleanUpStaticGeneration(input) {
|
|
500
|
+
let releases = [];
|
|
479
501
|
const cleanupErrors = [];
|
|
502
|
+
try {
|
|
503
|
+
if (input.staticExportsStarted) {
|
|
504
|
+
releases = await input.staticExportsStarted;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
if (!input.generationFailed || error !== input.generationError)
|
|
509
|
+
cleanupErrors.push(error);
|
|
510
|
+
}
|
|
480
511
|
try {
|
|
481
512
|
await this.releaseStaticExports(releases);
|
|
482
513
|
}
|
|
@@ -489,13 +520,13 @@ export class StaticSiteGenerator {
|
|
|
489
520
|
catch (error) {
|
|
490
521
|
cleanupErrors.push(error);
|
|
491
522
|
}
|
|
492
|
-
if (generationFailed) {
|
|
523
|
+
if (input.generationFailed) {
|
|
493
524
|
if (cleanupErrors.length > 0) {
|
|
494
|
-
throw new AggregateError([generationError, ...cleanupErrors], 'Static generation and cleanup failed', {
|
|
495
|
-
cause: generationError,
|
|
525
|
+
throw new AggregateError([input.generationError, ...cleanupErrors], 'Static generation and cleanup failed', {
|
|
526
|
+
cause: input.generationError,
|
|
496
527
|
});
|
|
497
528
|
}
|
|
498
|
-
throw generationError;
|
|
529
|
+
throw input.generationError;
|
|
499
530
|
}
|
|
500
531
|
if (cleanupErrors.length === 1)
|
|
501
532
|
throw cleanupErrors[0];
|
|
@@ -522,6 +553,9 @@ export class StaticSiteGenerator {
|
|
|
522
553
|
const { renderer } = resolveExplicitViewRenderer({
|
|
523
554
|
routePath: route.path,
|
|
524
555
|
view,
|
|
556
|
+
declaredIn: route.loader.filePath
|
|
557
|
+
? { file: route.loader.filePath, rootDir: this.appConfig.rootDir }
|
|
558
|
+
: undefined,
|
|
525
559
|
routeRendererFactory: input.routeRendererFactory,
|
|
526
560
|
errors: STATIC_SITE_GENERATOR_ERRORS,
|
|
527
561
|
});
|
|
@@ -609,10 +643,10 @@ export class StaticSiteGenerator {
|
|
|
609
643
|
if (!isDynamic) {
|
|
610
644
|
return [{ pathname: routePath, params: {} }];
|
|
611
645
|
}
|
|
612
|
-
if (!view.
|
|
613
|
-
throw new Error(STATIC_SITE_GENERATOR_ERRORS.
|
|
646
|
+
if (!view.paths) {
|
|
647
|
+
throw new Error(STATIC_SITE_GENERATOR_ERRORS.dynamicRouteRequiresPaths(routePath));
|
|
614
648
|
}
|
|
615
|
-
const
|
|
649
|
+
const paths = await view.paths({
|
|
616
650
|
appConfig: this.appConfig,
|
|
617
651
|
runtimeOrigin: this.appConfig.baseUrl,
|
|
618
652
|
});
|
package/src/types/contracts.d.ts
CHANGED
|
@@ -190,15 +190,16 @@ export interface DefaultHmrContext {
|
|
|
190
190
|
*/
|
|
191
191
|
getSrcDir(): string;
|
|
192
192
|
/**
|
|
193
|
-
*
|
|
194
|
-
* Used to detect layout file changes that require full page reloads.
|
|
193
|
+
* True when the Route Registry holds `filePath` as a Page.
|
|
195
194
|
*/
|
|
196
|
-
|
|
195
|
+
isPageFile(filePath: string): boolean;
|
|
197
196
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
197
|
+
* True when a Page rendered in this session references `filePath` as a Layout.
|
|
198
|
+
*
|
|
199
|
+
* @remarks
|
|
200
|
+
* Layouts are known after route preparation, so a Layout no Page has rendered yet reports `false`.
|
|
200
201
|
*/
|
|
201
|
-
|
|
202
|
+
isLayoutFile(filePath: string): boolean;
|
|
202
203
|
/**
|
|
203
204
|
* Server-side module loader owned by the active app/runtime.
|
|
204
205
|
*/
|
|
@@ -763,9 +764,9 @@ export type WithLocals<P> = P & {
|
|
|
763
764
|
locals?: RequestLocals;
|
|
764
765
|
};
|
|
765
766
|
/**
|
|
766
|
-
*
|
|
767
|
+
* One page that `paths` lists at build.
|
|
767
768
|
*/
|
|
768
|
-
export type
|
|
769
|
+
export type PagePath = {
|
|
769
770
|
params: PageParams;
|
|
770
771
|
};
|
|
771
772
|
export type EcoPagesAppConfig = {
|
|
@@ -775,11 +776,9 @@ export type EcoPagesAppConfig = {
|
|
|
775
776
|
publicDir: string;
|
|
776
777
|
pagesDir: string;
|
|
777
778
|
includesDir: string;
|
|
778
|
-
layoutsDir: string;
|
|
779
779
|
distDir: string;
|
|
780
780
|
workDir: string;
|
|
781
781
|
templatesExt: string[];
|
|
782
|
-
componentsDir: string;
|
|
783
782
|
robotsTxt: {
|
|
784
783
|
preferences: Record<string, string[]>;
|
|
785
784
|
};
|
|
@@ -790,11 +789,9 @@ export type EcoPagesAppConfig = {
|
|
|
790
789
|
absolutePaths: {
|
|
791
790
|
config: string;
|
|
792
791
|
configModuleFiles: string[];
|
|
793
|
-
componentsDir: string;
|
|
794
792
|
distDir: string;
|
|
795
793
|
workDir: string;
|
|
796
794
|
includesDir: string;
|
|
797
|
-
layoutsDir: string;
|
|
798
795
|
pagesDir: string;
|
|
799
796
|
projectDir: string;
|
|
800
797
|
publicDir: string;
|
|
@@ -809,7 +806,7 @@ export type EcoPagesAppConfig = {
|
|
|
809
806
|
package?: string;
|
|
810
807
|
};
|
|
811
808
|
};
|
|
812
|
-
export type PagePropsFor<T> = T extends
|
|
809
|
+
export type PagePropsFor<T> = T extends GetProps<infer P> ? P & {
|
|
813
810
|
params?: PageParams;
|
|
814
811
|
query?: PageQuery;
|
|
815
812
|
} : T & {
|
|
@@ -817,8 +814,8 @@ export type PagePropsFor<T> = T extends GetStaticProps<infer P> ? P & {
|
|
|
817
814
|
query?: PageQuery;
|
|
818
815
|
};
|
|
819
816
|
export type EcoPageComponent<T> = EcoComponent<PagePropsFor<T> & Partial<RequestPageContext>> & {
|
|
820
|
-
|
|
821
|
-
|
|
817
|
+
paths?: GetPaths;
|
|
818
|
+
props?: GetProps<T>;
|
|
822
819
|
metadata?: GetMetadata<T>;
|
|
823
820
|
resolveDependencies?: GetPageDependencies<T>;
|
|
824
821
|
cache?: CacheStrategy;
|
|
@@ -826,14 +823,15 @@ export type EcoPageComponent<T> = EcoComponent<PagePropsFor<T> & Partial<Request
|
|
|
826
823
|
middleware?: FileRouteMiddleware[];
|
|
827
824
|
};
|
|
828
825
|
/**
|
|
829
|
-
* The function that
|
|
826
|
+
* The function that lists the Params a page is known for at build time.
|
|
827
|
+
*
|
|
828
|
+
* @remarks
|
|
829
|
+
* Returns `[{ params }]` directly. The Cache Strategy decides what the build does with each entry.
|
|
830
830
|
*/
|
|
831
|
-
export type
|
|
831
|
+
export type GetPaths = (context: {
|
|
832
832
|
appConfig: EcoPagesAppConfig;
|
|
833
833
|
runtimeOrigin: string;
|
|
834
|
-
}) => Promise<
|
|
835
|
-
paths: StaticPath[];
|
|
836
|
-
}>;
|
|
834
|
+
}) => Promise<PagePath[]>;
|
|
837
835
|
/**
|
|
838
836
|
* The context object for the getMetadata function.
|
|
839
837
|
*/
|
|
@@ -846,15 +844,17 @@ export type GetMetadataContext<T = Record<string, unknown>> = Required<StaticPag
|
|
|
846
844
|
*/
|
|
847
845
|
export type GetMetadata<T = Record<string, unknown>> = (context: GetMetadataContext<T>) => PageMetadataProps | Promise<PageMetadataProps>;
|
|
848
846
|
/**
|
|
849
|
-
* The function that returns the
|
|
847
|
+
* The function that returns the props for a page.
|
|
848
|
+
*
|
|
849
|
+
* @remarks
|
|
850
|
+
* Returns the props object directly. `paths` lists the Params known at build; `props` receives Params,
|
|
851
|
+
* from `paths` at build and from the request at run time.
|
|
850
852
|
*/
|
|
851
|
-
export type
|
|
852
|
-
|
|
853
|
+
export type GetProps<T> = (context: {
|
|
854
|
+
params: PageParams;
|
|
853
855
|
appConfig: EcoPagesAppConfig;
|
|
854
856
|
runtimeOrigin: string;
|
|
855
|
-
}) => Promise<
|
|
856
|
-
props: T;
|
|
857
|
-
}>;
|
|
857
|
+
}) => Promise<T>;
|
|
858
858
|
/**
|
|
859
859
|
* Represents a page file in EcoPages.
|
|
860
860
|
* @template T - The type of the page props.
|
|
@@ -886,12 +886,12 @@ export type RouteRendererOptions = {
|
|
|
886
886
|
*/
|
|
887
887
|
props?: Record<string, unknown>;
|
|
888
888
|
/**
|
|
889
|
-
* Skips the page's `
|
|
889
|
+
* Skips the page's `props` hook for this render.
|
|
890
890
|
* @remarks Set when the caller already holds the final props, as the caller of an
|
|
891
891
|
* explicit view does. `props` then replaces the hook's result instead of being
|
|
892
892
|
* merged into it, and metadata sees the same props.
|
|
893
893
|
*/
|
|
894
|
-
|
|
894
|
+
skipPropsHook?: boolean;
|
|
895
895
|
};
|
|
896
896
|
/**
|
|
897
897
|
* The body of the route renderer.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Type definitions for the eco namespace API
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import type { DependencyLazyTrigger, EcoComponent, EcoComponentDependencies, EcoHtmlComponent, EcoPageLayouts, EcoPagesElement, EcoPageComponent, FileRouteMiddleware, GetMetadata,
|
|
5
|
+
import type { DependencyLazyTrigger, EcoComponent, EcoComponentDependencies, EcoHtmlComponent, EcoPageLayouts, EcoPagesElement, EcoPageComponent, FileRouteMiddleware, GetMetadata, GetPaths, GetProps, HtmlTemplateProps, LayoutProps, RequestLocals, RequestPageContext, PagePropsFor, PageRequires, PageDependenciesInput } from './contracts.js';
|
|
6
6
|
import type { CacheStrategy } from './cache-types.js';
|
|
7
7
|
import type { ComponentIdentity } from './component-identity.js';
|
|
8
8
|
export type { EcoPageComponent, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, PageDependenciesInput, PageDependenciesResult, PagePropsFor, PageRequires, } from './contracts.js';
|
|
@@ -90,25 +90,30 @@ export interface PageOptionsBase<T, E = EcoPagesElement> {
|
|
|
90
90
|
integration?: string;
|
|
91
91
|
/**
|
|
92
92
|
* Declares browser dependencies for the page, or resolves them per render after
|
|
93
|
-
* `
|
|
93
|
+
* `props` are available.
|
|
94
94
|
*/
|
|
95
95
|
dependencies?: PageDependenciesInput<T>;
|
|
96
96
|
layout?: EcoPageLayouts<E>;
|
|
97
97
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
98
|
+
* Lists the Params a dynamic route (e.g. `[slug].tsx`) is known for at build time, as `[{ params }]`.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* The Cache Strategy decides what the build does with each entry: `'static'` and `{ revalidate }` Pages render
|
|
102
|
+
* and write HTML for it, `'dynamic'` Pages plan a Page Browser Graph for it.
|
|
100
103
|
*/
|
|
101
|
-
|
|
104
|
+
paths?: GetPaths;
|
|
102
105
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
106
|
+
* Returns the page's props object. Props are passed to both render() and metadata().
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* Receives Params from `paths` at build time and from the request at run time.
|
|
105
110
|
*/
|
|
106
|
-
|
|
111
|
+
props?: GetProps<T>;
|
|
107
112
|
/**
|
|
108
113
|
* Generate page metadata (title, description, etc.).
|
|
109
114
|
*
|
|
110
115
|
* @remarks
|
|
111
|
-
* Props come from `
|
|
116
|
+
* Props come from `props`. Props passed into the render are overlaid
|
|
112
117
|
* and win when both set the same key. `metadata` sees the merged props.
|
|
113
118
|
*/
|
|
114
119
|
metadata?: GetMetadata<T>;
|
|
@@ -151,7 +156,7 @@ interface PageOptionsWithMiddleware<T, E = EcoPagesElement> extends PageOptionsB
|
|
|
151
156
|
/**
|
|
152
157
|
* Options for creating a page with eco.page()
|
|
153
158
|
*
|
|
154
|
-
* Define
|
|
159
|
+
* Define paths, props, and metadata inline. When using
|
|
155
160
|
* `middleware`, `cache` must be set to `'dynamic'` because middleware
|
|
156
161
|
* runs on every request and caching would bypass middleware effects.
|
|
157
162
|
*
|
|
@@ -191,8 +196,8 @@ export interface Eco {
|
|
|
191
196
|
*/
|
|
192
197
|
layout: <E = EcoPagesElement, P extends LayoutProps<E> = LayoutProps<E>>(options: LayoutOptions<E, P>) => EcoComponent<P, E>;
|
|
193
198
|
/**
|
|
194
|
-
* Create a page component with type-safe props from `
|
|
195
|
-
* Returns an EcoPageComponent with attached
|
|
199
|
+
* Create a page component with type-safe props from `props`.
|
|
200
|
+
* Returns an EcoPageComponent with attached paths, props, and metadata.
|
|
196
201
|
*
|
|
197
202
|
* If `requires` is provided, the `render` callback receives `locals` as required and non-null for the required keys.
|
|
198
203
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ApiHandler, ApiHandlerContext, BrowserForeignChildHost, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutEntrySpec, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent, EcoMiddleware, ErrorHandler, ErrorPageTemplateProps, EcopagesRouteInfo, EcopagesSocket, EcopagesWebSocketHandler, FileRouteMiddleware, FileRouteMiddlewareContext, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, GetMetadata, GetMetadataContext,
|
|
1
|
+
export type { ApiHandler, ApiHandlerContext, BrowserForeignChildHost, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutEntrySpec, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent, EcoMiddleware, ErrorHandler, ErrorPageTemplateProps, EcopagesRouteInfo, EcopagesSocket, EcopagesWebSocketHandler, FileRouteMiddleware, FileRouteMiddlewareContext, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, GetMetadata, GetMetadataContext, GetPaths, GetProps, HtmlTemplateProps, LayoutProps, LayoutPropsContext, Middleware, MiddlewareList, MiddlewareNext, OutgoingWebSocketMessage, IncomingWebSocketMessage, PageHeadProps, PageMetadataProps, PageParams, PageQuery, PageDependenciesInput, PageDependenciesResult, PageProps, PagePropsFor, PageRequires, PageRobotsMetadata, RequestLocals, RequestPageContext, RenderContext, RenderOptions, RouteGroupBuilder, RouteHandlerContext, RouteMethod, RouteOptions, RouteSchema, SitemapConfig, StandardSchema, StandardSchemaFailureResult, StandardSchemaIssue, StandardSchemaResult, StandardSchemaSuccessResult, StandardSchemaV1, StaticPageContext, PagePath, WebSocketCloseInfo, WithLocals, } from './contracts.js';
|
|
2
2
|
export type { ViewReference } from './view-reference.js';
|
|
3
3
|
export type { CacheConfig, CacheStrategy } from './cache-types.js';
|
|
4
4
|
export type { CallableComponentOf, ChildrenOf, ComponentOptions, Eco, EcoEmbedProps, EmbedPropsOf, HtmlOptions, LayoutOptions, LazyTrigger, PageOptions, PageOptionsBase, PagePropsForWithLocals, PropsOf, ResultOf, } from './eco-api-types.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare const FILE_ROLES: readonly ["api", "server", "script"];
|
|
2
|
+
type FileRole = (typeof FILE_ROLES)[number];
|
|
3
|
+
/** Suffixes that mark a file under the pages directory as an endpoint: `.api.ts`, `.api.tsx`, `.api.js`, `.api.jsx`. */
|
|
4
|
+
export declare const ENDPOINT_FILE_EXTENSIONS: readonly string[];
|
|
5
|
+
/** Every role suffix: `<name>.<role>.<ts|tsx|js|jsx>` for `api`, `server` and `script`. */
|
|
6
|
+
export declare const FILE_ROLE_SUFFIXES: readonly string[];
|
|
7
|
+
/**
|
|
8
|
+
* Returns the role `file` declares by its name and the suffix that declares it, or `undefined` for a file with none.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* `api` is an endpoint, `server` a server-only module no browser module may reach, `script` a browser script.
|
|
12
|
+
* The last two are never Pages.
|
|
13
|
+
*/
|
|
14
|
+
export declare function matchRoleSuffix(file: string): {
|
|
15
|
+
role: FileRole;
|
|
16
|
+
suffix: string;
|
|
17
|
+
} | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the role segment of `file` when it sits anywhere but directly before a script extension, as in
|
|
20
|
+
* `card.server.kita.tsx` or `nav.script.lit.tsx`, or `undefined` when the name has none or a well-formed one.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* The name's first segment is never a role, so `server.tsx` and `api.ts` are ordinary names. A role segment
|
|
24
|
+
* followed by a template extension is ambiguous (a server-only file or a Page of that Integration), so it is
|
|
25
|
+
* rejected instead of read one way.
|
|
26
|
+
*/
|
|
27
|
+
export declare function findMisplacedRole(file: string): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Whether `relativePath`, relative to the pages directory, has a segment starting with `_`.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* A private file or folder is never a route: `_layout.tsx`, `_card.tsx`, `_test/page.tsx`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isPrivatePath(relativePath: string): boolean;
|
|
35
|
+
/** The forms a role file name takes, for error messages. */
|
|
36
|
+
export declare function describeRoleForms(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether `specifier` names a `.server` module: `<name>.server`, with or without a script extension.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Ignores the query and fragment suffixes module resolver plugins add, so import pruning and browser
|
|
42
|
+
* resolution enforce the same boundary. `.mjs` and `.cjs` stay on the list because a package's published
|
|
43
|
+
* output may use them. A template extension after `.server` (`card.server.kita.tsx`) does not make a file
|
|
44
|
+
* server-only: the router rejects that name. This module has no runtime dependencies and is safe to import
|
|
45
|
+
* in the browser.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isServerOnlyModuleSpecifier(specifier: string): boolean;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const FILE_ROLES = ['api', 'server', 'script'];
|
|
2
|
+
/**
|
|
3
|
+
* The script extensions a role suffix may end in.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Never a template extension: a role file has no Integration owner, Layout or Cache Strategy, so
|
|
7
|
+
* config assembly rejects an Integration whose extensions end in a role suffix.
|
|
8
|
+
*/
|
|
9
|
+
const FILE_ROLE_SCRIPT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];
|
|
10
|
+
function suffixesOf(role) {
|
|
11
|
+
return FILE_ROLE_SCRIPT_EXTENSIONS.map((extension) => `.${role}${extension}`);
|
|
12
|
+
}
|
|
13
|
+
/** Suffixes that mark a file under the pages directory as an endpoint: `.api.ts`, `.api.tsx`, `.api.js`, `.api.jsx`. */
|
|
14
|
+
export const ENDPOINT_FILE_EXTENSIONS = suffixesOf('api');
|
|
15
|
+
/** Every role suffix: `<name>.<role>.<ts|tsx|js|jsx>` for `api`, `server` and `script`. */
|
|
16
|
+
export const FILE_ROLE_SUFFIXES = FILE_ROLES.flatMap(suffixesOf);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the role `file` declares by its name and the suffix that declares it, or `undefined` for a file with none.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* `api` is an endpoint, `server` a server-only module no browser module may reach, `script` a browser script.
|
|
22
|
+
* The last two are never Pages.
|
|
23
|
+
*/
|
|
24
|
+
export function matchRoleSuffix(file) {
|
|
25
|
+
for (const role of FILE_ROLES) {
|
|
26
|
+
const suffix = suffixesOf(role).find((candidate) => file.endsWith(candidate));
|
|
27
|
+
if (suffix)
|
|
28
|
+
return { role, suffix };
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns the role segment of `file` when it sits anywhere but directly before a script extension, as in
|
|
34
|
+
* `card.server.kita.tsx` or `nav.script.lit.tsx`, or `undefined` when the name has none or a well-formed one.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* The name's first segment is never a role, so `server.tsx` and `api.ts` are ordinary names. A role segment
|
|
38
|
+
* followed by a template extension is ambiguous (a server-only file or a Page of that Integration), so it is
|
|
39
|
+
* rejected instead of read one way.
|
|
40
|
+
*/
|
|
41
|
+
export function findMisplacedRole(file) {
|
|
42
|
+
const parts = (file.split('/').pop() ?? file).split('.');
|
|
43
|
+
const wellFormedIndex = FILE_ROLE_SCRIPT_EXTENSIONS.includes(`.${parts[parts.length - 1]}`) ? parts.length - 2 : -1;
|
|
44
|
+
for (let index = 1; index < parts.length; index += 1) {
|
|
45
|
+
const segment = parts[index] ?? '';
|
|
46
|
+
if (FILE_ROLES.includes(segment) && index !== wellFormedIndex) {
|
|
47
|
+
return segment;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether `relativePath`, relative to the pages directory, has a segment starting with `_`.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* A private file or folder is never a route: `_layout.tsx`, `_card.tsx`, `_test/page.tsx`.
|
|
57
|
+
*/
|
|
58
|
+
export function isPrivatePath(relativePath) {
|
|
59
|
+
return relativePath.split('/').some((segment) => segment.startsWith('_'));
|
|
60
|
+
}
|
|
61
|
+
/** The forms a role file name takes, for error messages. */
|
|
62
|
+
export function describeRoleForms() {
|
|
63
|
+
return FILE_ROLES.map((role) => `<name>.${role}.<ts|tsx|js|jsx>`).join(', ');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Whether `specifier` names a `.server` module: `<name>.server`, with or without a script extension.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* Ignores the query and fragment suffixes module resolver plugins add, so import pruning and browser
|
|
70
|
+
* resolution enforce the same boundary. `.mjs` and `.cjs` stay on the list because a package's published
|
|
71
|
+
* output may use them. A template extension after `.server` (`card.server.kita.tsx`) does not make a file
|
|
72
|
+
* server-only: the router rejects that name. This module has no runtime dependencies and is safe to import
|
|
73
|
+
* in the browser.
|
|
74
|
+
*/
|
|
75
|
+
export function isServerOnlyModuleSpecifier(specifier) {
|
|
76
|
+
const queryStart = specifier.indexOf('?');
|
|
77
|
+
const fragmentStart = specifier.indexOf('#');
|
|
78
|
+
const suffixStart = Math.min(queryStart === -1 ? specifier.length : queryStart, fragmentStart === -1 ? specifier.length : fragmentStart);
|
|
79
|
+
const path = specifier.slice(0, suffixStart);
|
|
80
|
+
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
81
|
+
return [...FILE_ROLE_SCRIPT_EXTENSIONS, '.mjs', '.cjs', ''].some((extension) => {
|
|
82
|
+
const suffix = `.server${extension}`;
|
|
83
|
+
return name.length > suffix.length && name.endsWith(suffix);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Every specifier `node:module` lists as a built-in, without the `node:` prefix, subpaths such as `fs/promises` included. */
|
|
2
|
+
export declare const nodeBuiltinSpecifiers: ReadonlySet<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Whether `specifier` names a Node built-in, with or without the `node:` prefix.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* The one owner of this question: the browser guard and the React client graph both ask it. A package named like a
|
|
8
|
+
* subpath `builtinModules` does not list (`path-browserify`) is not a built-in.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isNodeBuiltinSpecifier(specifier: string): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { builtinModules } from 'node:module';
|
|
2
|
+
/** Every specifier `node:module` lists as a built-in, without the `node:` prefix, subpaths such as `fs/promises` included. */
|
|
3
|
+
export const nodeBuiltinSpecifiers = new Set(builtinModules);
|
|
4
|
+
/**
|
|
5
|
+
* Whether `specifier` names a Node built-in, with or without the `node:` prefix.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The one owner of this question: the browser guard and the React client graph both ask it. A package named like a
|
|
9
|
+
* subpath `builtinModules` does not list (`path-browserify`) is not a built-in.
|
|
10
|
+
*/
|
|
11
|
+
export function isNodeBuiltinSpecifier(specifier) {
|
|
12
|
+
return specifier.startsWith('node:') || nodeBuiltinSpecifiers.has(specifier);
|
|
13
|
+
}
|
|
@@ -402,8 +402,8 @@ export class ProjectWatcher {
|
|
|
402
402
|
const activeWorkspacePackageRoots = new Set(this.workspacePackageRoots.filter((root) => recordedWatchPaths.some((filePath) => isPathInside(filePath, root))));
|
|
403
403
|
const srcDir = this.appConfig.absolutePaths.srcDir;
|
|
404
404
|
const literalPaths = new Set([srcDir]);
|
|
405
|
-
const { pagesDir,
|
|
406
|
-
for (const sourceDir of [pagesDir,
|
|
405
|
+
const { pagesDir, includesDir, publicDir } = this.appConfig.absolutePaths;
|
|
406
|
+
for (const sourceDir of [pagesDir, includesDir, publicDir]) {
|
|
407
407
|
if (!isPathInside(sourceDir, srcDir) && fileSystem.exists(sourceDir)) {
|
|
408
408
|
literalPaths.add(sourceDir);
|
|
409
409
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @remarks
|
|
3
|
-
* Matches the `.server` naming convention with or without a file extension,
|
|
4
|
-
* ignoring query and fragment suffixes used by module resolver plugins,
|
|
5
|
-
* so import pruning and browser resolution enforce the same boundary.
|
|
6
|
-
* This module has no runtime dependencies and is safe to import in the browser.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isServerOnlyModuleSpecifier(specifier: string): boolean;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @remarks
|
|
3
|
-
* Matches the `.server` naming convention with or without a file extension,
|
|
4
|
-
* ignoring query and fragment suffixes used by module resolver plugins,
|
|
5
|
-
* so import pruning and browser resolution enforce the same boundary.
|
|
6
|
-
* This module has no runtime dependencies and is safe to import in the browser.
|
|
7
|
-
*/
|
|
8
|
-
export function isServerOnlyModuleSpecifier(specifier) {
|
|
9
|
-
const pathname = specifier.replace(/[?#].*$/, '');
|
|
10
|
-
return /(?:^|[/])[^/]+\.server(?:$|\.)/.test(pathname);
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { decodeHtmlEntitiesUntilStable } from '../../../utils/html-entities.js';
|
|
2
|
-
export function normalizeUnresolvedMarkerArtifactHtml(html) {
|
|
3
|
-
return html.replace(/&(?:amp;)?lt;eco-marker\b[\s\S]*?&(?:amp;)?gt;&(?:amp;)?lt;\/eco-marker&(?:amp;)?gt;/g, (marker) => decodeHtmlEntitiesUntilStable(marker));
|
|
4
|
-
}
|
|
5
|
-
export function inspectUnresolvedMarkerArtifactHtml(html) {
|
|
6
|
-
const normalizedHtml = normalizeUnresolvedMarkerArtifactHtml(html);
|
|
7
|
-
return {
|
|
8
|
-
normalizedHtml,
|
|
9
|
-
hasUnresolvedMarkerArtifacts: normalizedHtml.includes('<eco-marker'),
|
|
10
|
-
};
|
|
11
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type EcopagesVirtualImport = {
|
|
2
|
-
from: string;
|
|
3
|
-
imports: string[] | undefined;
|
|
4
|
-
};
|
|
5
|
-
export declare function isBrowserEcopagesVirtualImport(specifier: string): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Extracts runtime `ecopages:` virtual-module imports from a component source file.
|
|
8
|
-
*
|
|
9
|
-
* Type-only imports are skipped and bare namespace imports are represented by an
|
|
10
|
-
* `undefined` import list so downstream module generation can preserve that shape.
|
|
11
|
-
*/
|
|
12
|
-
export declare function extractEcopagesVirtualImports(file: string): EcopagesVirtualImport[];
|