@ecopages/core 0.5.0 → 0.6.1
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 +18 -14
- package/package.json +13 -4
- package/src/adapters/create-app.js +9 -5
- package/src/adapters/node/create-app.d.ts +18 -16
- package/src/adapters/node/create-app.js +26 -30
- package/src/adapters/node/server-adapter.d.ts +26 -9
- package/src/adapters/node/server-adapter.js +38 -8
- package/src/adapters/shared/hmr/hmr-manager.js +3 -2
- package/src/adapters/shared/http/dist-file-handler.js +25 -7
- package/src/adapters/shared/runtime/render-context.d.ts +2 -1
- package/src/adapters/shared/runtime/render-context.js +18 -21
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +4 -3
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +6 -4
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +6 -1
- package/src/adapters/shared/runtime/server-request-pipeline.js +10 -10
- package/src/adapters/shared/runtime/server-static-builder.d.ts +11 -11
- package/src/adapters/shared/runtime/server-static-builder.js +37 -18
- package/src/assets/app-browser-client-manifest.d.ts +1 -3
- package/src/assets/app-browser-client-manifest.js +5 -58
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +2 -2
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +2 -2
- package/src/assets/browser-asset-output.d.ts +1 -1
- package/src/assets/browser-asset-output.js +1 -1
- package/src/build/app-build-manifest-runtime.d.ts +11 -1
- package/src/build/app-build-manifest-runtime.js +17 -3
- package/src/build/cache/pages-unified-graph-build.d.ts +32 -35
- package/src/build/cache/pages-unified-graph-build.js +206 -124
- package/src/build/cache/server-module-entries.d.ts +35 -0
- package/src/build/cache/server-module-entries.js +109 -0
- package/src/build/contracts/build-contracts.d.ts +5 -0
- package/src/build/copy-server-files.d.ts +10 -0
- package/src/build/copy-server-files.js +37 -0
- package/src/build/preserve-import-meta-transform.d.ts +1 -1
- package/src/build/preserve-import-meta-transform.js +1 -1
- package/src/build/production-build-id.d.ts +9 -0
- package/src/build/production-build-id.js +19 -0
- package/src/build/production-dist-complete.d.ts +5 -0
- package/src/build/production-dist-complete.js +101 -0
- package/src/build/production-route-list.d.ts +26 -0
- package/src/build/production-route-list.js +78 -0
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +2 -2
- package/src/build/rolldown/rolldown-adapter-helpers.js +56 -4
- package/src/build/rolldown/rolldown-build-adapter.js +1 -1
- package/src/build/runtime/build-request-identity.js +2 -1
- package/src/build/runtime/build-request-policy.d.ts +3 -2
- package/src/build/runtime/build-request-policy.js +5 -3
- package/src/build/server/import-view-module.d.ts +11 -0
- package/src/build/server/import-view-module.js +21 -0
- package/src/build/server/imported-view-plugin.d.ts +16 -0
- package/src/build/server/imported-view-plugin.js +59 -0
- package/src/build/server/page-module-import.service.d.ts +19 -20
- package/src/build/server/page-module-import.service.js +65 -36
- package/src/build/server/resolve-static-view.d.ts +9 -0
- package/src/build/server/resolve-static-view.js +28 -0
- package/src/build/server/route-module-build-cache-registry.d.ts +5 -3
- package/src/build/server/route-module-build-cache-registry.js +5 -3
- package/src/build/server/server-modules-manifest.d.ts +51 -0
- package/src/build/server/server-modules-manifest.js +129 -0
- package/src/build/server/view-reference.d.ts +38 -0
- package/src/build/server/view-reference.js +112 -0
- package/src/build/server-bundle-deploy-manifest.d.ts +9 -9
- package/src/build/server-bundle-deploy-manifest.js +24 -28
- package/src/build.d.ts +3 -1
- package/src/build.js +3 -1
- package/src/config/assembly/app-runtime.d.ts +15 -2
- package/src/config/assembly/app-runtime.js +3 -1
- package/src/config/assembly/finalize-config.js +64 -13
- package/src/config/index.d.ts +1 -0
- package/src/config/index.js +1 -0
- package/src/config/internal-types.d.ts +6 -0
- package/src/config/load-eco-config.d.ts +1 -0
- package/src/config/load-eco-config.js +11 -2
- package/src/config/resolve-eco-config-path.d.ts +2 -1
- package/src/config/resolve-eco-config-path.js +21 -15
- package/src/config/user-config-types.d.ts +9 -2
- package/src/html-pages/html-page-module.d.ts +19 -0
- package/src/html-pages/html-page-module.js +66 -13
- package/src/html-pages/html-page-renderer.d.ts +4 -0
- package/src/html-pages/html-page-renderer.js +9 -3
- package/src/html-pages/html-pages.plugin.d.ts +10 -0
- package/src/html-pages/html-pages.plugin.js +7 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/integration.d.ts +2 -1
- package/src/integration.js +1 -0
- package/src/page-cache/page-cache-service.d.ts +8 -0
- package/src/page-cache/page-cache-service.js +12 -0
- package/src/plugins/integration-plugin.d.ts +33 -6
- package/src/plugins/integration-plugin.js +14 -2
- package/src/plugins/processor.d.ts +17 -0
- package/src/plugins/processor.js +20 -1
- package/src/plugins/server-dom.d.ts +29 -0
- package/src/plugins/server-dom.js +36 -0
- package/src/route-renderer/error-pages/error-page-renderer.d.ts +6 -4
- package/src/route-renderer/error-pages/error-page-renderer.js +9 -5
- package/src/route-renderer/orchestration/integration-renderer.d.ts +1 -0
- package/src/route-renderer/orchestration/integration-renderer.js +17 -2
- package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.d.ts +21 -0
- package/src/route-renderer/orchestration/page-browser-graph/missing-production-browser-graph.js +31 -0
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +58 -24
- package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.d.ts +12 -0
- package/src/route-renderer/orchestration/page-browser-graph/route-instance-key.js +55 -0
- package/src/router/client/navigation-commit.js +16 -2
- package/src/router/client/navigation-head-order.fixture.css +3 -0
- package/src/router/client/navigation-head.d.ts +2 -1
- package/src/router/client/navigation-head.fixture.css +3 -0
- package/src/router/client/navigation-head.js +222 -39
- package/src/router/server/route-registry.d.ts +22 -2
- package/src/router/server/route-registry.js +39 -15
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +8 -2
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +14 -9
- package/src/static-site-generator/static-site-generator.d.ts +19 -3
- package/src/static-site-generator/static-site-generator.js +78 -40
- package/src/types/contracts.d.ts +20 -31
- package/src/types/public-types.d.ts +1 -0
- package/src/types/view-reference.d.ts +31 -0
- package/src/types/view-reference.js +15 -0
- package/src/utils/additional-watch-paths.d.ts +3 -3
- package/src/utils/additional-watch-paths.js +3 -1
- package/src/utils/resolve-entry-file.d.ts +4 -2
- package/src/utils/resolve-entry-file.js +4 -2
- package/src/utils/root-relative-path.d.ts +4 -0
- package/src/utils/root-relative-path.js +8 -0
- package/src/utils/server-bundle-context.d.ts +14 -0
- package/src/utils/server-bundle-context.js +45 -0
- package/src/watchers/project-watcher-ignore.d.ts +2 -5
- package/src/watchers/project-watcher-ignore.js +2 -5
- package/src/watchers/project-watcher.d.ts +9 -7
- package/src/watchers/project-watcher.js +100 -52
- package/src/watchers/workspace-package-watch-roots.d.ts +4 -4
- package/src/watchers/workspace-package-watch-roots.js +41 -25
- package/src/build/server/view-module-loader.d.ts +0 -10
- package/src/build/server/view-module-loader.js +0 -46
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { appLogger } from '../global/app-logger.js';
|
|
3
|
+
import { requireAppRuntime } from '../utils/app-runtime.js';
|
|
3
4
|
import { resolveBuildParallelism } from '../build/build-parallelism.js';
|
|
4
5
|
import { fileSystem } from '@ecopages/file-system';
|
|
6
|
+
import { CLIENT_OUTPUT_DIR } from '../utils/resolve-entry-file.js';
|
|
5
7
|
import { prepareExplicitStaticRender, resolveExplicitViewRenderer, } from '../route-renderer/explicit-view-render-preparation.js';
|
|
6
|
-
import { getServerModuleBuildCacheOutdir } from '../build/server/route-module-build-cache-registry.js';
|
|
7
8
|
import { ensureIntegrationRuntimeReady, setupAppRuntimeIntegrations, teardownAppRuntimeIntegrations, } from '../build/app-build-manifest-runtime.js';
|
|
8
|
-
import {
|
|
9
|
+
import { emitProductionServerModules, shouldBuildPagesUnifiedGraph } from '../build/cache/pages-unified-graph-build.js';
|
|
9
10
|
import { clearProductionPageBrowserGraphSession, prebuildProductionPageBrowserGraphs, shouldPrebuildProductionPageBrowserGraphs, } from './production-page-browser-graph-prebuild.js';
|
|
10
11
|
import { renderSitemap } from './sitemap.js';
|
|
11
12
|
import { resolveSitemapLocations } from './sitemap-routes.js';
|
|
@@ -68,7 +69,8 @@ export class StaticSiteGenerator {
|
|
|
68
69
|
this.appConfig = appConfig;
|
|
69
70
|
}
|
|
70
71
|
getExportDir() {
|
|
71
|
-
return this.appConfig.absolutePaths?.distDir ??
|
|
72
|
+
return (this.appConfig.absolutePaths?.distDir ??
|
|
73
|
+
path.join(this.appConfig.rootDir, this.appConfig.distDir, CLIENT_OUTPUT_DIR));
|
|
72
74
|
}
|
|
73
75
|
async shouldSkipStaticPageFile(filePath, params, routeRendererFactory) {
|
|
74
76
|
const renderer = routeRendererFactory.getPageRenderer(filePath);
|
|
@@ -279,28 +281,50 @@ export class StaticSiteGenerator {
|
|
|
279
281
|
clearProductionPageBrowserGraphSession(this.appConfig);
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
+
/**
|
|
285
|
+
* @remarks
|
|
286
|
+
* An empty `templateRoutes` array still emits explicit views, the Html shell,
|
|
287
|
+
* Layouts, and error pages. When the route source omits `templateRoutes`,
|
|
288
|
+
* listed Pages are used instead.
|
|
289
|
+
*/
|
|
290
|
+
async emitProductionServerModulesForStaticGeneration(input) {
|
|
291
|
+
if (requireAppRuntime(this.appConfig).productionServerModules || !shouldBuildPagesUnifiedGraph()) {
|
|
284
292
|
return;
|
|
285
293
|
}
|
|
286
|
-
await
|
|
294
|
+
await emitProductionServerModules({
|
|
287
295
|
appConfig: this.appConfig,
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
296
|
+
router: { templateRoutes: input.router.templateRoutes ?? input.listedTemplateRoutes },
|
|
297
|
+
staticRoutes: input.staticRoutes,
|
|
298
|
+
errorPageLoaders: input.errorPageLoaders,
|
|
291
299
|
});
|
|
292
300
|
}
|
|
293
301
|
async executeStaticGenerationBody(input) {
|
|
302
|
+
const explicitStaticRoutes = input.staticRoutes && input.routeRendererFactory
|
|
303
|
+
? await this.prepareExplicitStaticRoutes({
|
|
304
|
+
staticRoutes: input.staticRoutes,
|
|
305
|
+
routeRendererFactory: input.routeRendererFactory,
|
|
306
|
+
skipped: input.skippedDynamicPages,
|
|
307
|
+
failures: input.pageFailures,
|
|
308
|
+
})
|
|
309
|
+
: [];
|
|
294
310
|
if (shouldPrebuildProductionPageBrowserGraphs() && input.routeRendererFactory) {
|
|
295
311
|
const dynamicRouteTemplates = (input.router.templateRoutes ?? [])
|
|
296
312
|
.filter((route) => route.kind !== 'exact' && route.role === 'page')
|
|
297
313
|
.map((route) => ({ routeFile: route.filePath, skipStaticProps: true, isRouteTemplate: true }));
|
|
314
|
+
const dynamicPageEntries = (await input.router.listDynamicPagePathExpansions?.({
|
|
315
|
+
runtimeOrigin: input.baseUrl,
|
|
316
|
+
})) ?? [];
|
|
298
317
|
await prebuildProductionPageBrowserGraphs(this.appConfig, [
|
|
299
318
|
...input.routes.map((route) => ({
|
|
300
319
|
routeFile: route.templateRoute.filePath,
|
|
301
320
|
params: route.params,
|
|
302
321
|
})),
|
|
322
|
+
...dynamicPageEntries.map((route) => ({
|
|
323
|
+
routeFile: route.templateRoute.filePath,
|
|
324
|
+
params: route.params,
|
|
325
|
+
})),
|
|
303
326
|
...dynamicRouteTemplates,
|
|
327
|
+
...explicitStaticRoutes.flatMap(({ routeFile, routeEntries }) => routeFile ? routeEntries.map(({ params }) => ({ routeFile, params })) : []),
|
|
304
328
|
], input.routeRendererFactory);
|
|
305
329
|
}
|
|
306
330
|
this.generateRobotsTxt();
|
|
@@ -316,11 +340,10 @@ export class StaticSiteGenerator {
|
|
|
316
340
|
preloadedRoutes: pageRoutes,
|
|
317
341
|
sitemapEligiblePathnames: input.sitemapEligiblePathnames,
|
|
318
342
|
});
|
|
319
|
-
if (
|
|
343
|
+
if (explicitStaticRoutes.length > 0 && input.routeRendererFactory) {
|
|
320
344
|
await this.generateExplicitStaticPages({
|
|
321
|
-
staticRoutes:
|
|
345
|
+
staticRoutes: explicitStaticRoutes,
|
|
322
346
|
routeRendererFactory: input.routeRendererFactory,
|
|
323
|
-
skipped: input.skippedDynamicPages,
|
|
324
347
|
failures: input.pageFailures,
|
|
325
348
|
activeStaticPathnames: input.activeStaticPathnames,
|
|
326
349
|
sitemapEligiblePathnames: input.sitemapEligiblePathnames,
|
|
@@ -364,8 +387,13 @@ export class StaticSiteGenerator {
|
|
|
364
387
|
try {
|
|
365
388
|
await setupAppRuntimeIntegrations({ appConfig: this.appConfig });
|
|
366
389
|
const routes = await router.listStaticGenerationRoutes({ runtimeOrigin: baseUrl });
|
|
390
|
+
await this.emitProductionServerModulesForStaticGeneration({
|
|
391
|
+
router,
|
|
392
|
+
listedTemplateRoutes: routes.map((route) => route.templateRoute),
|
|
393
|
+
staticRoutes,
|
|
394
|
+
errorPageLoaders,
|
|
395
|
+
});
|
|
367
396
|
const exportRoutes = routes.map((route) => toEcopagesRouteInfo(route));
|
|
368
|
-
await this.ensureUnifiedGraphForStaticGeneration(routes, force);
|
|
369
397
|
const staticExportContext = this.createStaticExportContext({
|
|
370
398
|
router,
|
|
371
399
|
baseUrl,
|
|
@@ -434,37 +462,59 @@ export class StaticSiteGenerator {
|
|
|
434
462
|
throw new AggregateError(cleanupErrors, 'Failed to clean up static generation resources');
|
|
435
463
|
}
|
|
436
464
|
}
|
|
437
|
-
|
|
438
|
-
|
|
465
|
+
/**
|
|
466
|
+
* Loads each explicit static view, resolves its renderer and lists its pathnames.
|
|
467
|
+
*
|
|
468
|
+
* @remarks
|
|
469
|
+
* A view that fails here is recorded as a page failure and left out of both
|
|
470
|
+
* production browser-graph prebuild and generation.
|
|
471
|
+
*/
|
|
472
|
+
async prepareExplicitStaticRoutes(input) {
|
|
473
|
+
const prepared = [];
|
|
439
474
|
for (const route of input.staticRoutes) {
|
|
440
475
|
try {
|
|
441
|
-
const
|
|
442
|
-
const view = mod.default;
|
|
476
|
+
const view = (await route.loader()).default;
|
|
443
477
|
if (this.shouldSkipStaticView(route.path, view)) {
|
|
444
|
-
input.skipped
|
|
478
|
+
input.skipped.push(route.path);
|
|
445
479
|
continue;
|
|
446
480
|
}
|
|
447
|
-
|
|
481
|
+
const { renderer } = resolveExplicitViewRenderer({
|
|
448
482
|
routePath: route.path,
|
|
449
483
|
view,
|
|
450
484
|
routeRendererFactory: input.routeRendererFactory,
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
485
|
+
errors: STATIC_SITE_GENERATOR_ERRORS,
|
|
486
|
+
});
|
|
487
|
+
prepared.push({
|
|
488
|
+
routePath: route.path,
|
|
489
|
+
routeFile: route.loader.filePath,
|
|
490
|
+
view,
|
|
491
|
+
renderer,
|
|
492
|
+
routeEntries: await this.listExplicitStaticRouteEntries(route.path, view),
|
|
454
493
|
});
|
|
455
494
|
}
|
|
456
495
|
catch (error) {
|
|
457
496
|
input.failures.push(createStaticGenerationPageError(route.path, error, 'explicit static page'));
|
|
458
497
|
}
|
|
459
498
|
}
|
|
499
|
+
return prepared;
|
|
500
|
+
}
|
|
501
|
+
async generateExplicitStaticPages(input) {
|
|
502
|
+
appLogger.debug('Generating explicit static routes', input.staticRoutes.map((route) => route.routePath));
|
|
503
|
+
for (const route of input.staticRoutes) {
|
|
504
|
+
await this.generateExplicitStaticRoute({
|
|
505
|
+
routePath: route.routePath,
|
|
506
|
+
view: route.view,
|
|
507
|
+
renderer: route.renderer,
|
|
508
|
+
routeEntries: route.routeEntries,
|
|
509
|
+
routeRendererFactory: input.routeRendererFactory,
|
|
510
|
+
failures: input.failures,
|
|
511
|
+
activeStaticPathnames: input.activeStaticPathnames,
|
|
512
|
+
sitemapEligiblePathnames: input.sitemapEligiblePathnames,
|
|
513
|
+
});
|
|
514
|
+
}
|
|
460
515
|
}
|
|
461
516
|
async generateExplicitStaticRoute(input) {
|
|
462
|
-
const { routePath, view, routeRendererFactory, failures, activeStaticPathnames, sitemapEligiblePathnames } = input;
|
|
463
|
-
const { renderer, routeEntries } = await this.planExplicitStaticRoute({
|
|
464
|
-
routePath,
|
|
465
|
-
view,
|
|
466
|
-
routeRendererFactory,
|
|
467
|
-
});
|
|
517
|
+
const { routePath, view, renderer, routeEntries, routeRendererFactory, failures, activeStaticPathnames, sitemapEligiblePathnames, } = input;
|
|
468
518
|
for (const { pathname, params } of routeEntries) {
|
|
469
519
|
try {
|
|
470
520
|
let renderedMetadata;
|
|
@@ -500,18 +550,6 @@ export class StaticSiteGenerator {
|
|
|
500
550
|
}
|
|
501
551
|
}
|
|
502
552
|
}
|
|
503
|
-
async planExplicitStaticRoute(input) {
|
|
504
|
-
const { renderer } = resolveExplicitViewRenderer({
|
|
505
|
-
routePath: input.routePath,
|
|
506
|
-
view: input.view,
|
|
507
|
-
routeRendererFactory: input.routeRendererFactory,
|
|
508
|
-
errors: STATIC_SITE_GENERATOR_ERRORS,
|
|
509
|
-
});
|
|
510
|
-
return {
|
|
511
|
-
renderer,
|
|
512
|
-
routeEntries: await this.listExplicitStaticRouteEntries(input.routePath, input.view),
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
553
|
async createExplicitStaticContents(input) {
|
|
516
554
|
const { props, view: renderableView } = await prepareExplicitStaticRender({
|
|
517
555
|
routePath: input.routePath,
|
package/src/types/contracts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
2
|
import type { ComponentIdentity } from './component-identity.js';
|
|
3
|
+
import type { ViewReference } from './view-reference.js';
|
|
3
4
|
import type { ApiResponseBuilder } from './api-response.js';
|
|
4
5
|
import type { AssetDefinition, ProcessedAsset } from './asset-types.js';
|
|
5
6
|
import type { CacheStats, CacheStrategy } from './cache-types.js';
|
|
@@ -1066,38 +1067,22 @@ export interface RenderOptions {
|
|
|
1066
1067
|
* Provides methods to render eco.page views and return formatted responses.
|
|
1067
1068
|
*/
|
|
1068
1069
|
export interface RenderContext {
|
|
1069
|
-
/**
|
|
1070
|
-
* Import a server-executed module through the active Ecopages module loader.
|
|
1071
|
-
*
|
|
1072
|
-
* This applies the runtime's cache-busting and source-transpilation rules so
|
|
1073
|
-
* request-time lazy imports participate in development invalidation.
|
|
1074
|
-
*
|
|
1075
|
-
* @param filePath - Absolute filesystem path or file URL for the server module
|
|
1076
|
-
*/
|
|
1077
|
-
importServerModule<T = unknown>(filePath: string | URL): Promise<T>;
|
|
1078
|
-
/**
|
|
1079
|
-
* Import a server module through the active Ecopages module loader and render
|
|
1080
|
-
* its default-exported eco.page view.
|
|
1081
|
-
*
|
|
1082
|
-
* @param filePath - Absolute filesystem path or file URL for the server module
|
|
1083
|
-
* @param props - Props to pass to the default-exported view
|
|
1084
|
-
* @param options - Optional status code and headers
|
|
1085
|
-
*/
|
|
1086
|
-
renderServerModule<P = Record<string, unknown>>(filePath: string | URL, props?: P, options?: RenderOptions): Promise<Response>;
|
|
1087
1070
|
/**
|
|
1088
1071
|
* Render an eco.page view with full layout and includes.
|
|
1089
|
-
*
|
|
1090
|
-
* @
|
|
1091
|
-
*
|
|
1072
|
+
*
|
|
1073
|
+
* @remarks
|
|
1074
|
+
* Pass an imported view. Core resolves Integration-owned imports at render
|
|
1075
|
+
* time so a save reloads in development and production reads the built module.
|
|
1092
1076
|
*/
|
|
1093
|
-
render<P = Record<string, unknown>>(view: EcoComponent<P>, props?: P, options?: RenderOptions): Promise<Response>;
|
|
1077
|
+
render<P = Record<string, unknown>>(view: EcoComponent<P> | ViewReference<P>, props?: P, options?: RenderOptions): Promise<Response>;
|
|
1094
1078
|
/**
|
|
1095
1079
|
* Render an eco.page view without layout (for partials/fragments).
|
|
1096
|
-
*
|
|
1097
|
-
* @
|
|
1098
|
-
*
|
|
1080
|
+
*
|
|
1081
|
+
* @remarks
|
|
1082
|
+
* Pass an imported view. Core resolves Integration-owned imports at render
|
|
1083
|
+
* time so a save reloads in development and production reads the built module.
|
|
1099
1084
|
*/
|
|
1100
|
-
renderPartial<P = Record<string, unknown>>(view: EcoComponent<P>, props: P, options?: RenderOptions): Promise<Response>;
|
|
1085
|
+
renderPartial<P = Record<string, unknown>>(view: EcoComponent<P> | ViewReference<P>, props: P, options?: RenderOptions): Promise<Response>;
|
|
1101
1086
|
/**
|
|
1102
1087
|
* Return a JSON response.
|
|
1103
1088
|
* @param data - Data to serialize as JSON
|
|
@@ -1274,7 +1259,7 @@ export interface ApiHandlerContext<TRequest extends Request = Request, TServer =
|
|
|
1274
1259
|
* response helpers, but final document rendering stays owned by the page route
|
|
1275
1260
|
* execution path. The query string is not parsed for page middleware; read it from `request.url`.
|
|
1276
1261
|
*/
|
|
1277
|
-
export interface FileRouteMiddlewareContext<TRequest extends Request = Request, TServer = any> extends Omit<ApiHandlerContext<TRequest, TServer>, 'render' | 'renderPartial' | '
|
|
1262
|
+
export interface FileRouteMiddlewareContext<TRequest extends Request = Request, TServer = any> extends Omit<ApiHandlerContext<TRequest, TServer>, 'render' | 'renderPartial' | 'query'> {
|
|
1278
1263
|
}
|
|
1279
1264
|
/**
|
|
1280
1265
|
* Next function for middleware chain.
|
|
@@ -1512,12 +1497,16 @@ export type RouteGroupBuilder<TRequest extends Request = Request, TServer = any,
|
|
|
1512
1497
|
/**
|
|
1513
1498
|
* A function that dynamically imports a view module.
|
|
1514
1499
|
* Used by `app.static()` and the HTML error-page helpers (`app.notFound()`,
|
|
1515
|
-
* `app.forbidden()`, `app.serverError()`, `app.errorPage()`, …)
|
|
1516
|
-
*
|
|
1500
|
+
* `app.forbidden()`, `app.serverError()`, `app.errorPage()`, …). Production emit
|
|
1501
|
+
* reads `filePath` so the view joins `dist/server/`. Development compiles from
|
|
1502
|
+
* source so an edit reloads it.
|
|
1517
1503
|
*/
|
|
1518
|
-
export type ViewLoader<P = any> = () => Promise<{
|
|
1504
|
+
export type ViewLoader<P = any> = (() => Promise<{
|
|
1519
1505
|
default: EcoPageComponent<P>;
|
|
1520
|
-
}
|
|
1506
|
+
}>) & {
|
|
1507
|
+
/** Absolute source path of the imported view. */
|
|
1508
|
+
filePath?: string;
|
|
1509
|
+
};
|
|
1521
1510
|
/**
|
|
1522
1511
|
* Represents a static route registered via app.static().
|
|
1523
1512
|
* Uses a loader function to enable HMR in development mode.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export type { ApiHandler, ApiHandlerContext, EcoComponent, EcoComponentConfig, EcoComponentDependencies, DependencyAttributes, EcoChildren, EcoFunctionComponent, EcoPageComponent, EcoPageFile, EcoPagesAppConfig, EcoPagesElement, EcoPageLayoutEntry, EcoPageLayoutSpec, EcoPageLayouts, EcoHtmlComponent, EcoLayoutComponent, EcoMiddleware, ErrorHandler, ErrorPageTemplateProps, EcopagesRouteInfo, EcopagesSocket, EcopagesWebSocketHandler, FileRouteMiddleware, FileRouteMiddlewareContext, FileOwnedDependencyContribution, GetPageDependencies, GetPageDependenciesContext, GetMetadata, GetMetadataContext, GetStaticPaths, GetStaticProps, 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, StaticPath, WebSocketCloseInfo, WithLocals, } from './contracts.js';
|
|
2
|
+
export type { ViewReference } from './view-reference.js';
|
|
2
3
|
export type { CacheConfig, CacheStrategy } from './cache-types.js';
|
|
3
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,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brand on a view reference created from an import of an Integration-owned file.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Shared across the CLI preload, the server-entry plugin, and render-time
|
|
6
|
+
* resolution so two imports of one file compare as the same object.
|
|
7
|
+
*/
|
|
8
|
+
export declare const VIEW_REFERENCE: unique symbol;
|
|
9
|
+
/**
|
|
10
|
+
* Handle for an Integration-owned view imported from the server entry.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Core resolves the file at render time: development through the app module
|
|
14
|
+
* loader, production from the server-modules map. The identity fields match the
|
|
15
|
+
* module so Integration ownership is available before that load.
|
|
16
|
+
*/
|
|
17
|
+
export interface ViewReference<P = Record<string, unknown>> {
|
|
18
|
+
readonly [VIEW_REFERENCE]: true;
|
|
19
|
+
readonly filePath: string;
|
|
20
|
+
readonly config: {
|
|
21
|
+
identity: {
|
|
22
|
+
id: string;
|
|
23
|
+
file: string;
|
|
24
|
+
integration?: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/** Phantom props parameter so `ctx.render(view, props)` stays typed. */
|
|
28
|
+
readonly __props?: P;
|
|
29
|
+
}
|
|
30
|
+
/** True when `value` is a view reference, not a loaded component. */
|
|
31
|
+
export declare function isViewReference<P = Record<string, unknown>>(value: unknown): value is ViewReference<P>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brand on a view reference created from an import of an Integration-owned file.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Shared across the CLI preload, the server-entry plugin, and render-time
|
|
6
|
+
* resolution so two imports of one file compare as the same object.
|
|
7
|
+
*/
|
|
8
|
+
export const VIEW_REFERENCE = Symbol.for('ecopages.view-reference');
|
|
9
|
+
/** True when `value` is a view reference, not a loaded component. */
|
|
10
|
+
export function isViewReference(value) {
|
|
11
|
+
return (typeof value === 'object' &&
|
|
12
|
+
value !== null &&
|
|
13
|
+
value[VIEW_REFERENCE] === true &&
|
|
14
|
+
typeof value.filePath === 'string');
|
|
15
|
+
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* One `additionalWatchPaths` entry resolved against the project root.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
* `base` is the absolute
|
|
6
|
-
*
|
|
5
|
+
* `base` is the absolute directory the filesystem watcher subscribes to. For
|
|
6
|
+
* a glob, `base` is built from the
|
|
7
7
|
* pattern's segments before the first one with a glob character, and `glob`
|
|
8
8
|
* is the rest of the pattern, matched against paths relative to `base`. Glob
|
|
9
9
|
* characters in the root directory itself therefore never reach the matcher.
|
|
@@ -21,5 +21,5 @@ export type AdditionalWatchPath = {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function resolveAdditionalWatchPath(pattern: string, rootDir: string): AdditionalWatchPath;
|
|
23
23
|
export declare function matchesAdditionalWatchPath(filePath: string, watchPath: AdditionalWatchPath): boolean;
|
|
24
|
-
/** Returns whether a directory
|
|
24
|
+
/** Returns whether a directory can lead to or contain files matched by a glob. */
|
|
25
25
|
export declare function mayContainAdditionalWatchMatches(directory: string, watchPath: AdditionalWatchPath): boolean;
|
|
@@ -42,8 +42,10 @@ export function matchesAdditionalWatchPath(filePath, watchPath) {
|
|
|
42
42
|
allowsDotSegments(relativePath, watchPath.glob) &&
|
|
43
43
|
path.matchesGlob(relativePath, watchPath.glob));
|
|
44
44
|
}
|
|
45
|
-
/** Returns whether a directory
|
|
45
|
+
/** Returns whether a directory can lead to or contain files matched by a glob. */
|
|
46
46
|
export function mayContainAdditionalWatchMatches(directory, watchPath) {
|
|
47
|
+
if (isPathInside(watchPath.base, directory))
|
|
48
|
+
return true;
|
|
47
49
|
const relativePath = relativeToBase(directory, watchPath.base);
|
|
48
50
|
return relativePath !== undefined && (!watchPath.glob || allowsDotSegments(relativePath, watchPath.glob));
|
|
49
51
|
}
|
|
@@ -63,9 +63,11 @@ export declare function resolveEntryFile({ entryFile, env, argv, }?: ResolveEntr
|
|
|
63
63
|
*/
|
|
64
64
|
export declare function readEntryFileFlag(argv?: string[]): string | undefined;
|
|
65
65
|
/**
|
|
66
|
-
* The subdirectory inside
|
|
66
|
+
* The subdirectory inside the configured output directory where the private server bundle is placed.
|
|
67
67
|
*/
|
|
68
|
-
export declare const SERVER_BUNDLE_DIR = "
|
|
68
|
+
export declare const SERVER_BUNDLE_DIR = "server";
|
|
69
|
+
/** The public files inside the configured output directory. */
|
|
70
|
+
export declare const CLIENT_OUTPUT_DIR = "client";
|
|
69
71
|
/**
|
|
70
72
|
* The filename of the bundled server entry.
|
|
71
73
|
*/
|
|
@@ -65,9 +65,11 @@ export function readEntryFileFlag(argv = getRuntimeArgv()) {
|
|
|
65
65
|
return typeof raw === 'string' && raw.length > 0 ? raw : undefined;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* The subdirectory inside
|
|
68
|
+
* The subdirectory inside the configured output directory where the private server bundle is placed.
|
|
69
69
|
*/
|
|
70
|
-
export const SERVER_BUNDLE_DIR = '
|
|
70
|
+
export const SERVER_BUNDLE_DIR = 'server';
|
|
71
|
+
/** The public files inside the configured output directory. */
|
|
72
|
+
export const CLIENT_OUTPUT_DIR = 'client';
|
|
71
73
|
/**
|
|
72
74
|
* The filename of the bundled server entry.
|
|
73
75
|
*/
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Returns `filePath` relative to `rootDir` with POSIX separators.
|
|
4
|
+
*/
|
|
5
|
+
export function toRootRelativePath(rootDir, filePath) {
|
|
6
|
+
const absolute = path.isAbsolute(filePath) ? path.resolve(filePath) : path.resolve(rootDir, filePath);
|
|
7
|
+
return path.relative(rootDir, absolute).split(path.sep).join('/');
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const SERVER_BUNDLE_CONTEXT_KEY = "@ecopages/server-bundle-context";
|
|
2
|
+
export declare const SERVER_BUNDLE_IMPLEMENTATION_FILENAME = "app.bundle.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the folder of the production server bundle running this application.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Node scopes the folder to the bundle's async import, so two bundles loaded in one process each see their own.
|
|
8
|
+
* Bun does not carry `AsyncLocalStorage` into a module loaded through `import()`, so the loader also records the
|
|
9
|
+
* folder of the last bundle it started on `globalThis`, and that value is the fallback.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getProductionServerBundleDir(): string | undefined;
|
|
12
|
+
export declare function runWithProductionServerBundleDir<T>(serverBundleDir: string, callback: () => T): T;
|
|
13
|
+
/** Emits a loader that scopes the bundle directory to that application's async import. */
|
|
14
|
+
export declare function createServerBundleLoaderSource(): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
export const SERVER_BUNDLE_CONTEXT_KEY = '@ecopages/server-bundle-context';
|
|
3
|
+
export const SERVER_BUNDLE_IMPLEMENTATION_FILENAME = 'app.bundle.mjs';
|
|
4
|
+
const SERVER_BUNDLE_DIR_KEY = `${SERVER_BUNDLE_CONTEXT_KEY}/dir`;
|
|
5
|
+
function getServerBundleStorage() {
|
|
6
|
+
const storageKey = Symbol.for(SERVER_BUNDLE_CONTEXT_KEY);
|
|
7
|
+
const existingStorage = Reflect.get(globalThis, storageKey);
|
|
8
|
+
if (existingStorage instanceof AsyncLocalStorage)
|
|
9
|
+
return existingStorage;
|
|
10
|
+
const storage = new AsyncLocalStorage();
|
|
11
|
+
Object.defineProperty(globalThis, storageKey, { value: storage, configurable: true });
|
|
12
|
+
return storage;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns the folder of the production server bundle running this application.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Node scopes the folder to the bundle's async import, so two bundles loaded in one process each see their own.
|
|
19
|
+
* Bun does not carry `AsyncLocalStorage` into a module loaded through `import()`, so the loader also records the
|
|
20
|
+
* folder of the last bundle it started on `globalThis`, and that value is the fallback.
|
|
21
|
+
*/
|
|
22
|
+
export function getProductionServerBundleDir() {
|
|
23
|
+
const bundleDir = getServerBundleStorage().getStore() ?? Reflect.get(globalThis, Symbol.for(SERVER_BUNDLE_DIR_KEY));
|
|
24
|
+
return typeof bundleDir === 'string' ? bundleDir : undefined;
|
|
25
|
+
}
|
|
26
|
+
export function runWithProductionServerBundleDir(serverBundleDir, callback) {
|
|
27
|
+
return getServerBundleStorage().run(serverBundleDir, callback);
|
|
28
|
+
}
|
|
29
|
+
/** Emits a loader that scopes the bundle directory to that application's async import. */
|
|
30
|
+
export function createServerBundleLoaderSource() {
|
|
31
|
+
return [
|
|
32
|
+
"import { AsyncLocalStorage } from 'node:async_hooks';",
|
|
33
|
+
"import { fileURLToPath } from 'node:url';",
|
|
34
|
+
"const serverBundleDir = fileURLToPath(new URL('.', import.meta.url));",
|
|
35
|
+
`const storageKey = Symbol.for(${JSON.stringify(SERVER_BUNDLE_CONTEXT_KEY)});`,
|
|
36
|
+
'let storage = Reflect.get(globalThis, storageKey);',
|
|
37
|
+
'if (!(storage instanceof AsyncLocalStorage)) {',
|
|
38
|
+
'\tstorage = new AsyncLocalStorage();',
|
|
39
|
+
'\tObject.defineProperty(globalThis, storageKey, { value: storage, configurable: true });',
|
|
40
|
+
'}',
|
|
41
|
+
`Object.defineProperty(globalThis, Symbol.for(${JSON.stringify(SERVER_BUNDLE_DIR_KEY)}), { value: serverBundleDir, configurable: true });`,
|
|
42
|
+
`await storage.run(serverBundleDir, () => import('./${SERVER_BUNDLE_IMPLEMENTATION_FILENAME}'));`,
|
|
43
|
+
'',
|
|
44
|
+
].join('\n');
|
|
45
|
+
}
|
|
@@ -4,10 +4,7 @@ export type ProjectWatcherIgnorePaths = {
|
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
6
|
* @remarks
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* the watch tree without descending into symlinked monorepo node_modules.
|
|
10
|
-
* chokidar hands the predicate forward-slash paths on Windows too, so the
|
|
11
|
-
* path is normalised before its segments are compared.
|
|
7
|
+
* A path predicate filters node_modules, VCS metadata, and scoped artifact dirs
|
|
8
|
+
* from indexing and reported changes without traversing symlinked monorepo node_modules.
|
|
12
9
|
*/
|
|
13
10
|
export declare function createProjectWatcherIgnorePredicate(absolutePaths: ProjectWatcherIgnorePaths, workspacePackageRoots?: readonly string[]): (watchedPath: string) => boolean;
|
|
@@ -3,11 +3,8 @@ import { isPathInside } from '../utils/path-containment.js';
|
|
|
3
3
|
import { isWorkspacePackageFile } from './workspace-package-watch-roots.js';
|
|
4
4
|
/**
|
|
5
5
|
* @remarks
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* the watch tree without descending into symlinked monorepo node_modules.
|
|
9
|
-
* chokidar hands the predicate forward-slash paths on Windows too, so the
|
|
10
|
-
* path is normalised before its segments are compared.
|
|
6
|
+
* A path predicate filters node_modules, VCS metadata, and scoped artifact dirs
|
|
7
|
+
* from indexing and reported changes without traversing symlinked monorepo node_modules.
|
|
11
8
|
*/
|
|
12
9
|
export function createProjectWatcherIgnorePredicate(absolutePaths, workspacePackageRoots = []) {
|
|
13
10
|
const ignoredDirectories = [absolutePaths.workDir, absolutePaths.distDir];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type FileWatcher } from '@ecopages/file-system';
|
|
2
2
|
import type { EcoPagesAppConfig, IHmrManager, IClientBridge } from '../config/internal-types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Configuration options for the ProjectWatcher
|
|
@@ -51,6 +51,7 @@ export declare class ProjectWatcher {
|
|
|
51
51
|
private restartRequestScheduled;
|
|
52
52
|
private workspacePackageRoots;
|
|
53
53
|
private watcher;
|
|
54
|
+
private readonly watchedPaths;
|
|
54
55
|
private watcherReady?;
|
|
55
56
|
private watcherReadyTimeout;
|
|
56
57
|
private rejectWatcherReady;
|
|
@@ -82,7 +83,7 @@ export declare class ProjectWatcher {
|
|
|
82
83
|
*/
|
|
83
84
|
private syncPublicDirFile;
|
|
84
85
|
/**
|
|
85
|
-
* Serializes file change handling so that concurrent
|
|
86
|
+
* Serializes file change handling so that concurrent filesystem events are
|
|
86
87
|
* processed one at a time, preventing overlapping builds and race conditions.
|
|
87
88
|
*/
|
|
88
89
|
private enqueueChange;
|
|
@@ -127,18 +128,19 @@ export declare class ProjectWatcher {
|
|
|
127
128
|
/**
|
|
128
129
|
* @remarks
|
|
129
130
|
* The subscription watches `srcDir` recursively alongside external recorded
|
|
130
|
-
* inputs, restart files, workspace roots, and additional watch paths. Processor
|
|
131
|
-
* notifications share the same file-change pipeline.
|
|
132
|
-
* for
|
|
131
|
+
* inputs, restart files, workspace roots used by recorded inputs, and additional watch paths. Processor
|
|
132
|
+
* notifications share the same file-change pipeline. The filesystem adapter
|
|
133
|
+
* coalesces native events for one path across a 50 ms window.
|
|
133
134
|
*
|
|
134
135
|
* A glob in `additionalWatchPaths` is watched through its static base
|
|
135
136
|
* directory, which can be the project root for `**` patterns. Files reached
|
|
136
137
|
* only through such a base are ignored unless they match a pattern, and so
|
|
137
138
|
* are dot-directories the pattern does not name, so a broad base does not
|
|
138
139
|
* feed unrelated files into the change pipeline. Readiness rejects and closes
|
|
139
|
-
* the subscription if
|
|
140
|
+
* the subscription if the filesystem adapter does not become ready within 30 seconds.
|
|
140
141
|
*/
|
|
141
|
-
createWatcherSubscription(): Promise<
|
|
142
|
+
createWatcherSubscription(): Promise<FileWatcher>;
|
|
143
|
+
private handleWatchChange;
|
|
142
144
|
/**
|
|
143
145
|
* Closes the active filesystem watcher subscription.
|
|
144
146
|
*
|