@ecopages/core 0.3.1 → 0.4.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 +17 -1
- package/package.json +3 -3
- package/src/adapters/node/create-app.d.ts +31 -20
- package/src/adapters/node/create-app.js +44 -43
- package/src/adapters/node/dev-session.d.ts +3 -1
- package/src/adapters/node/dev-session.js +4 -1
- package/src/adapters/node/runtime-host.d.ts +5 -0
- package/src/adapters/node/runtime-host.js +8 -1
- package/src/adapters/node/server-adapter.js +5 -1
- package/src/adapters/shared/hmr/hmr-manager.d.ts +12 -2
- package/src/adapters/shared/hmr/hmr-manager.js +20 -16
- package/src/adapters/shared/http/define-api-handler.d.ts +41 -26
- package/src/adapters/shared/http/define-api-handler.js +15 -1
- package/src/adapters/shared/http/endpoint-route-handler.d.ts +46 -0
- package/src/adapters/shared/http/endpoint-route-handler.js +96 -0
- package/src/adapters/shared/runtime/bind-runtime-server.js +3 -1
- package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
- package/src/adapters/shared/runtime/port-manager.d.ts +6 -0
- package/src/adapters/shared/runtime/port-manager.js +16 -2
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +20 -3
- package/src/adapters/shared/runtime/server-request-pipeline.js +45 -12
- package/src/adapters/shared/runtime/server-route-handler.d.ts +8 -3
- package/src/adapters/shared/runtime/server-route-handler.js +12 -6
- package/src/adapters/shared/runtime/server-static-builder.d.ts +14 -1
- package/src/adapters/shared/runtime/server-static-builder.js +13 -2
- package/src/assets/app-browser-client-build.js +1 -2
- package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
- package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
- package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
- package/src/assets/browser-asset-output.d.ts +19 -0
- package/src/assets/browser-asset-output.js +30 -0
- package/src/assets/hashed-browser-asset.d.ts +8 -6
- package/src/assets/hashed-browser-asset.js +8 -6
- package/src/build/build-graph.js +2 -2
- package/src/build/preserve-import-meta-transform.js +2 -2
- package/src/build/rolldown/app-package-declarations.js +3 -3
- package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
- package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
- package/src/build/server-bundle-deploy-manifest.d.ts +1 -1
- package/src/build/server-bundle-deploy-manifest.js +1 -1
- package/src/build/server-bundle-publication.js +4 -5
- package/src/config/assembly/finalize-config.js +5 -0
- package/src/config/config-module-files.js +2 -3
- package/src/diagnostics/startup-trace.js +2 -5
- package/src/html-pages/html-page-module-scripts.js +4 -3
- package/src/html-pages/html-page-renderer.js +2 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/plugins/component-import-discovery.js +4 -4
- package/src/plugins/foreign-jsx-override-plugin.js +2 -2
- package/src/plugins/tsconfig-import-resolver.js +12 -12
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +0 -17
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -23
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
- package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
- package/src/router/server/route-registry.d.ts +18 -9
- package/src/router/server/route-registry.js +50 -32
- package/src/router/server/segment-path-matcher.d.ts +8 -0
- package/src/router/server/segment-path-matcher.js +15 -0
- package/src/static-site-generator/static-site-generator.js +1 -1
- package/src/types/contracts.d.ts +87 -61
- package/src/types/contracts.js +4 -1
- package/src/types/public-types.d.ts +1 -1
- package/src/utils/endpoint-file-extensions.d.ts +11 -0
- package/src/utils/endpoint-file-extensions.js +13 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { contentHash } from '../utils/content-hash.js';
|
|
2
|
-
import { readdirSync, realpathSync } from 'node:fs';
|
|
3
2
|
import { getBuildEntryOutput } from '../build/build-graph.js';
|
|
4
3
|
import { assertBuildSucceeded } from '../build/build-log.js';
|
|
5
4
|
import { createRequire } from 'node:module';
|
|
@@ -200,7 +199,9 @@ export function scanModuleScript(appConfig, script) {
|
|
|
200
199
|
function listHtmlFiles(appConfig) {
|
|
201
200
|
const { pagesDir, htmlTemplatePath } = appConfig.absolutePaths;
|
|
202
201
|
const pages = fileSystem.exists(pagesDir)
|
|
203
|
-
?
|
|
202
|
+
? fileSystem
|
|
203
|
+
.readdir(pagesDir, { recursive: true })
|
|
204
|
+
.map((entry) => entry.name)
|
|
204
205
|
.filter((name) => name.endsWith('.html'))
|
|
205
206
|
.map((name) => path.join(pagesDir, name))
|
|
206
207
|
.sort()
|
|
@@ -287,7 +288,7 @@ async function buildModuleScripts(appConfig, referencedScripts) {
|
|
|
287
288
|
for (const script of scripts) {
|
|
288
289
|
const output = getBuildEntryOutput(result, script, appConfig.rootDir);
|
|
289
290
|
if (output)
|
|
290
|
-
urls.set(
|
|
291
|
+
urls.set(fileSystem.realpath(script), `/${path.relative(distDir, output).split(path.sep).join('/')}`);
|
|
291
292
|
}
|
|
292
293
|
return urls;
|
|
293
294
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { realpathSync } from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { fileSystem } from '@ecopages/file-system';
|
|
4
3
|
import { AssetFactory } from '../assets/asset-processing-service/asset.factory.js';
|
|
@@ -237,7 +236,7 @@ export class HtmlPageRenderer extends StringMarkupRenderer {
|
|
|
237
236
|
if (asset.kind === 'module-script') {
|
|
238
237
|
const hmr = this.assetProcessingService.getHmrManager()?.isEnabled() === true;
|
|
239
238
|
if (!hmr) {
|
|
240
|
-
const url = (await getHtmlPageModuleScriptUrls(this.appConfig)).get(
|
|
239
|
+
const url = (await getHtmlPageModuleScriptUrls(this.appConfig)).get(fileSystem.realpath(asset.filepath));
|
|
241
240
|
if (url !== undefined)
|
|
242
241
|
return url;
|
|
243
242
|
}
|
|
@@ -265,7 +264,7 @@ export class HtmlPageRenderer extends StringMarkupRenderer {
|
|
|
265
264
|
const found = scanModuleScript(this.appConfig, script).stylesheetImport;
|
|
266
265
|
if (!found)
|
|
267
266
|
return;
|
|
268
|
-
const real = (target) => (fileSystem.exists(target) ?
|
|
267
|
+
const real = (target) => (fileSystem.exists(target) ? fileSystem.realpath(target) : target);
|
|
269
268
|
const rootDir = real(this.appConfig.rootDir);
|
|
270
269
|
const show = (target) => path.isAbsolute(target) ? path.relative(rootDir, real(target)).split(path.sep).join('/') : target;
|
|
271
270
|
const stylesheet = real(found.stylesheet);
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type * from './types/public-types.js';
|
|
2
2
|
export { eco } from './eco/eco.js';
|
|
3
|
-
export { defineApiHandler, defineGroupHandler, defineGet, definePost, definePut, defineDelete, definePatch, defineOptions, defineHead, json, html, redirect, type GroupHandler, } from './adapters/shared/http/define-api-handler.js';
|
|
3
|
+
export { defineApiHandler, defineGroupHandler, defineGet, definePost, definePut, defineDelete, definePatch, defineOptions, defineHead, defineQuery, json, html, redirect, type GroupHandler, } from './adapters/shared/http/define-api-handler.js';
|
|
4
4
|
export { attributeMdxComponentIdentity } from './plugins/eco-component-meta-plugin.js';
|
|
5
5
|
export { bindComponentIdentity, getComponentIdentity, getComponentOwner, type ComponentIdentity, } from './eco/component-identity.js';
|
|
6
6
|
export { attachDiscoveredDependencies } from './eco/discovered-dependencies.js';
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { eco } from './eco/eco.js';
|
|
2
|
-
export { defineApiHandler, defineGroupHandler, defineGet, definePost, definePut, defineDelete, definePatch, defineOptions, defineHead, json, html, redirect, } from './adapters/shared/http/define-api-handler.js';
|
|
2
|
+
export { defineApiHandler, defineGroupHandler, defineGet, definePost, definePut, defineDelete, definePatch, defineOptions, defineHead, defineQuery, json, html, redirect, } from './adapters/shared/http/define-api-handler.js';
|
|
3
3
|
export { attributeMdxComponentIdentity } from './plugins/eco-component-meta-plugin.js';
|
|
4
4
|
export { bindComponentIdentity, getComponentIdentity, getComponentOwner, } from './eco/component-identity.js';
|
|
5
5
|
export { attachDiscoveredDependencies } from './eco/discovered-dependencies.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
3
3
|
import { parseModuleSource } from '../cache/module-parse-cache.js';
|
|
4
4
|
import { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix, resolveProjectModulePath, } from './tsconfig-import-resolver.js';
|
|
5
5
|
function node(value) {
|
|
@@ -89,7 +89,7 @@ function indexModuleExports(file, cache) {
|
|
|
89
89
|
const cached = cache.get(file);
|
|
90
90
|
if (cached)
|
|
91
91
|
return cached;
|
|
92
|
-
const source = readFileSync(file
|
|
92
|
+
const source = fileSystem.readFileSync(file);
|
|
93
93
|
const parsed = parseModuleSource(file, source, { sourceType: 'module' });
|
|
94
94
|
const body = nodes(parsed.program.body);
|
|
95
95
|
const { declared, factories } = collectDeclaredFactoryBindings(body);
|
|
@@ -155,7 +155,7 @@ function resolveStylesheetImportPath(source, ownerFile, projectRoot, pathPrefixe
|
|
|
155
155
|
}
|
|
156
156
|
if (isRelative) {
|
|
157
157
|
const candidate = path.resolve(path.dirname(ownerFile), source);
|
|
158
|
-
return
|
|
158
|
+
return fileSystem.exists(candidate) ? fileSystem.realpath(candidate) : undefined;
|
|
159
159
|
}
|
|
160
160
|
return resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
|
|
161
161
|
}
|
|
@@ -171,7 +171,7 @@ function tryRecordSideEffectStylesheetImport(statement, source, ownerFile, proje
|
|
|
171
171
|
}
|
|
172
172
|
return false;
|
|
173
173
|
}
|
|
174
|
-
if (!
|
|
174
|
+
if (!fileSystem.exists(resolved)) {
|
|
175
175
|
throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(source)} from ${ownerFile}`);
|
|
176
176
|
}
|
|
177
177
|
result.stylesheets.push(resolved);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
2
2
|
import { escapeRegExp } from '../utils/regex-escaping.js';
|
|
3
3
|
import { createJsxImportSourcePragma, filterJsxSourceExtensions } from './jsx-import-source.utils.js';
|
|
4
4
|
/**
|
|
@@ -38,7 +38,7 @@ export function createForeignJsxOverridePlugin(options) {
|
|
|
38
38
|
if (excludedExtensions.some((extension) => args.path.endsWith(extension))) {
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
41
|
-
const source = readFileSync(args.path
|
|
41
|
+
const source = fileSystem.readFileSync(args.path);
|
|
42
42
|
const loader = args.path.endsWith('.jsx') ? 'jsx' : 'tsx';
|
|
43
43
|
if (source.includes('@jsxImportSource')) {
|
|
44
44
|
return undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
2
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
3
3
|
import { ResolverFactory } from 'oxc-resolver';
|
|
4
4
|
import { toPackageRootSpecifier } from './package-specifier.js';
|
|
5
5
|
const RESOLVABLE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.mdx'];
|
|
@@ -10,10 +10,10 @@ function stripJsonComments(source) {
|
|
|
10
10
|
}
|
|
11
11
|
function findTsconfigPath(projectRoot) {
|
|
12
12
|
const candidate = path.join(projectRoot, 'tsconfig.json');
|
|
13
|
-
return
|
|
13
|
+
return fileSystem.exists(candidate) ? candidate : undefined;
|
|
14
14
|
}
|
|
15
15
|
function readJsonFile(filePath) {
|
|
16
|
-
const source = readFileSync(filePath
|
|
16
|
+
const source = fileSystem.readFileSync(filePath);
|
|
17
17
|
try {
|
|
18
18
|
return JSON.parse(source);
|
|
19
19
|
}
|
|
@@ -173,7 +173,7 @@ export function resolveBarePackageBrowserEntry(projectRoot, specifier) {
|
|
|
173
173
|
return undefined;
|
|
174
174
|
}
|
|
175
175
|
try {
|
|
176
|
-
return { path:
|
|
176
|
+
return { path: fileSystem.realpath(result.path), packageJsonPath: result.packageJsonPath };
|
|
177
177
|
}
|
|
178
178
|
catch {
|
|
179
179
|
return { path: result.path, packageJsonPath: result.packageJsonPath };
|
|
@@ -183,7 +183,7 @@ function resolveAliasedBarrelTarget(resolvedPath) {
|
|
|
183
183
|
if (!path.basename(resolvedPath).startsWith('index.')) {
|
|
184
184
|
return resolvedPath;
|
|
185
185
|
}
|
|
186
|
-
const source = readFileSync(resolvedPath
|
|
186
|
+
const source = fileSystem.readFileSync(resolvedPath).trim();
|
|
187
187
|
const match = source.match(/^export\s+\*\s+from\s+['"]([^'"]+)['"]\s*;?$/);
|
|
188
188
|
if (!match?.[1]?.startsWith('.')) {
|
|
189
189
|
return resolvedPath;
|
|
@@ -192,13 +192,13 @@ function resolveAliasedBarrelTarget(resolvedPath) {
|
|
|
192
192
|
const targetBase = path.resolve(targetDir, match[1]);
|
|
193
193
|
for (const extension of RESOLVABLE_EXTENSIONS) {
|
|
194
194
|
const candidate = `${targetBase}${extension}`;
|
|
195
|
-
if (
|
|
195
|
+
if (fileSystem.exists(candidate)) {
|
|
196
196
|
return candidate;
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
for (const extension of RESOLVABLE_EXTENSIONS) {
|
|
200
200
|
const candidate = path.join(targetBase, `index${extension}`);
|
|
201
|
-
if (
|
|
201
|
+
if (fileSystem.exists(candidate)) {
|
|
202
202
|
return candidate;
|
|
203
203
|
}
|
|
204
204
|
}
|
|
@@ -216,18 +216,18 @@ export function resolveRelativeModulePath(fromFile, specifier) {
|
|
|
216
216
|
return undefined;
|
|
217
217
|
}
|
|
218
218
|
const targetBase = path.resolve(path.dirname(fromFile), specifier);
|
|
219
|
-
if (
|
|
219
|
+
if (fileSystem.exists(targetBase)) {
|
|
220
220
|
return path.resolve(targetBase);
|
|
221
221
|
}
|
|
222
222
|
for (const candidateExtension of RESOLVABLE_EXTENSIONS) {
|
|
223
223
|
const candidate = `${targetBase}${candidateExtension}`;
|
|
224
|
-
if (
|
|
224
|
+
if (fileSystem.exists(candidate)) {
|
|
225
225
|
return path.resolve(candidate);
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
for (const candidateExtension of RESOLVABLE_EXTENSIONS) {
|
|
229
229
|
const candidate = path.join(targetBase, `index${candidateExtension}`);
|
|
230
|
-
if (
|
|
230
|
+
if (fileSystem.exists(candidate)) {
|
|
231
231
|
return path.resolve(candidate);
|
|
232
232
|
}
|
|
233
233
|
}
|
|
@@ -248,8 +248,8 @@ export function resolveProjectModulePath(projectRoot, fromFile, specifier, optio
|
|
|
248
248
|
const result = resolver.sync(path.dirname(fromFile), specifier);
|
|
249
249
|
if (result.path) {
|
|
250
250
|
return options?.preserveBarrel
|
|
251
|
-
?
|
|
252
|
-
: resolveAliasedBarrelTarget(
|
|
251
|
+
? fileSystem.realpath(result.path)
|
|
252
|
+
: resolveAliasedBarrelTarget(fileSystem.realpath(result.path));
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
if (isRelative) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { GroupedGraphScope } from './route-instance-key.js';
|
|
2
|
-
import type { EcoPagesAppConfig } from '../../../config/internal-types.js';
|
|
3
2
|
import type { PageBrowserGraphContribution, PageBrowserGraphResult } from '../../../types/contracts.js';
|
|
4
3
|
import type { ProcessedAsset } from '../../../assets/asset-processing-service/assets.types.js';
|
|
5
4
|
import { BuildInputDependencyIndex } from '../../../build/cache/build-input-dependency-index.js';
|
|
@@ -32,13 +31,6 @@ type GroupedGraphRecord = {
|
|
|
32
31
|
dependencyPaths: ReadonlySet<string>;
|
|
33
32
|
generation: number;
|
|
34
33
|
};
|
|
35
|
-
export type AffectedGraphIdentity = {
|
|
36
|
-
integrationName: string;
|
|
37
|
-
routeFile: string;
|
|
38
|
-
dependencyInstanceKey: string;
|
|
39
|
-
policy: GraphPolicy;
|
|
40
|
-
entryFingerprint: string;
|
|
41
|
-
};
|
|
42
34
|
/**
|
|
43
35
|
* Session-local Page Browser Graph cache with precise dependency invalidation.
|
|
44
36
|
*/
|
|
@@ -63,7 +55,6 @@ export declare class SessionPageBrowserGraphCache {
|
|
|
63
55
|
getBuildCount(): number;
|
|
64
56
|
getGraphByRoute(integrationName: string, routeFile: string, policy: GraphPolicy, dependencyInstanceKey?: string): PageBrowserGraphResult | undefined;
|
|
65
57
|
getDependencyPathsByRoute(integrationName: string, routeFile: string, policy: GraphPolicy, dependencyInstanceKey?: string): ReadonlySet<string> | undefined;
|
|
66
|
-
getAffectedGraphIdentities(filePath: string): AffectedGraphIdentity[];
|
|
67
58
|
resolveGraph(key: GraphKey, provisionalDependencyPaths: ReadonlySet<string>, build: () => Promise<GraphBuildResult | undefined>, options?: {
|
|
68
59
|
reuseCachedResult?: boolean;
|
|
69
60
|
}): Promise<PageBrowserGraphResult | undefined>;
|
|
@@ -89,14 +80,6 @@ export declare class SessionPageBrowserGraphCache {
|
|
|
89
80
|
private clearInFlightBuild;
|
|
90
81
|
private releaseInFlightDependencyPaths;
|
|
91
82
|
}
|
|
92
|
-
/**
|
|
93
|
-
* Invalidates graph records that depend on the changed file path.
|
|
94
|
-
*/
|
|
95
|
-
export declare function invalidatePageBrowserGraphSession(appConfig: EcoPagesAppConfig, filePath: string): void;
|
|
96
|
-
/**
|
|
97
|
-
* Returns graph identities affected by a source file change.
|
|
98
|
-
*/
|
|
99
|
-
export declare function getAffectedPageBrowserGraphIdentities(appConfig: EcoPagesAppConfig, filePath: string): AffectedGraphIdentity[];
|
|
100
83
|
/**
|
|
101
84
|
* Builds a stable fingerprint from declared browser-entry dependencies and assets.
|
|
102
85
|
*/
|
|
@@ -3,7 +3,6 @@ import { serializeGroupedGraphCacheKey } from './route-instance-key.js';
|
|
|
3
3
|
import { contentHash } from '../../../utils/content-hash.js';
|
|
4
4
|
import { appLogger } from '../../../global/app-logger.js';
|
|
5
5
|
import { BuildInputDependencyIndex, } from '../../../build/cache/build-input-dependency-index.js';
|
|
6
|
-
import { requireAppRuntime } from '../../../utils/app-runtime.js';
|
|
7
6
|
function graphBinding(key) {
|
|
8
7
|
return { consumer: 'page-browser-graph', key };
|
|
9
8
|
}
|
|
@@ -106,16 +105,6 @@ export class SessionPageBrowserGraphCache {
|
|
|
106
105
|
}
|
|
107
106
|
return undefined;
|
|
108
107
|
}
|
|
109
|
-
getAffectedGraphIdentities(filePath) {
|
|
110
|
-
const identities = [];
|
|
111
|
-
for (const serializedKey of this.graphKeysFor(filePath)) {
|
|
112
|
-
const identity = parseSerializedGraphKey(serializedKey);
|
|
113
|
-
if (identity) {
|
|
114
|
-
identities.push(identity);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return identities;
|
|
118
|
-
}
|
|
119
108
|
resolveGraph(key, provisionalDependencyPaths, build, options = {}) {
|
|
120
109
|
if (options.reuseCachedResult === false) {
|
|
121
110
|
return this.buildGraphWithoutCaching(build);
|
|
@@ -396,18 +385,6 @@ export class SessionPageBrowserGraphCache {
|
|
|
396
385
|
this.inFlightDependencyPaths.delete(serializedKey);
|
|
397
386
|
}
|
|
398
387
|
}
|
|
399
|
-
/**
|
|
400
|
-
* Invalidates graph records that depend on the changed file path.
|
|
401
|
-
*/
|
|
402
|
-
export function invalidatePageBrowserGraphSession(appConfig, filePath) {
|
|
403
|
-
requireAppRuntime(appConfig).pageBrowserGraphSession.invalidateByFilePath(filePath);
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Returns graph identities affected by a source file change.
|
|
407
|
-
*/
|
|
408
|
-
export function getAffectedPageBrowserGraphIdentities(appConfig, filePath) {
|
|
409
|
-
return requireAppRuntime(appConfig).pageBrowserGraphSession.getAffectedGraphIdentities(filePath);
|
|
410
|
-
}
|
|
411
388
|
/**
|
|
412
389
|
* Builds a stable fingerprint from declared browser-entry dependencies and assets.
|
|
413
390
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
2
2
|
import { isContentServerVirtualModule } from '../../build/contracts/content-virtual-modules.js';
|
|
3
3
|
import { parseModuleSource } from '../../cache/module-parse-cache.js';
|
|
4
4
|
import { isProductionRuntime } from '../../utils/runtime.js';
|
|
@@ -70,7 +70,7 @@ const productionVirtualImportsByFile = new Map();
|
|
|
70
70
|
function readEcopagesVirtualImports(file) {
|
|
71
71
|
let source;
|
|
72
72
|
try {
|
|
73
|
-
source = readFileSync(file
|
|
73
|
+
source = fileSystem.readFileSync(file);
|
|
74
74
|
}
|
|
75
75
|
catch {
|
|
76
76
|
return [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
2
2
|
import { AssetFactory } from '../../assets/asset-processing-service/index.js';
|
|
3
3
|
import { contentHash } from '../../utils/content-hash.js';
|
|
4
4
|
import { isProductionRuntime } from '../../utils/runtime.js';
|
|
@@ -74,10 +74,10 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
|
|
|
74
74
|
if (dependency.source === 'content') {
|
|
75
75
|
return isSafeBundledStylesheetContent(dependency.content);
|
|
76
76
|
}
|
|
77
|
-
if (!
|
|
77
|
+
if (!fileSystem.exists(dependency.filepath)) {
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
|
-
return isSafeBundledStylesheetContent(readFileSync(dependency.filepath
|
|
80
|
+
return isSafeBundledStylesheetContent(fileSystem.readFileSync(dependency.filepath));
|
|
81
81
|
})
|
|
82
82
|
.filter(isBundleableFileStylesheetAsset);
|
|
83
83
|
const bundleableScripts = dependencies
|
|
@@ -93,7 +93,7 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
|
|
|
93
93
|
!dependency.packageRole &&
|
|
94
94
|
dependency.bundle !== false &&
|
|
95
95
|
hasOnlyExpectedAttributes(dependency.attributes, { type: 'module', defer: '' }) &&
|
|
96
|
-
|
|
96
|
+
fileSystem.exists(dependency.filepath));
|
|
97
97
|
})
|
|
98
98
|
.filter(isBundleableFileScriptAsset);
|
|
99
99
|
const eligibleStyles = new Set(bundleableStyles);
|
|
@@ -106,7 +106,7 @@ function createPageDependencyPackagingPlan(dependencies, integrationName) {
|
|
|
106
106
|
const bundledScriptMembers = new Set();
|
|
107
107
|
for (const run of collectContiguousEligibleRuns(dependencies, isEligibleStyle)) {
|
|
108
108
|
const bundledStylesheet = AssetFactory.createContentStylesheet({
|
|
109
|
-
content: run.assets.map((dependency) => readFileSync(dependency.filepath
|
|
109
|
+
content: run.assets.map((dependency) => fileSystem.readFileSync(dependency.filepath)).join('\n'),
|
|
110
110
|
position: 'head',
|
|
111
111
|
attributes: { rel: 'stylesheet' },
|
|
112
112
|
packageRole: 'page-style',
|
|
@@ -2,17 +2,23 @@ import type { EcoPagesAppConfig } from '../../config/internal-types.js';
|
|
|
2
2
|
import type { PageParams, PageQuery } from '../../types/contracts.js';
|
|
3
3
|
import { type ParsedSegmentPath } from './segment-path-matcher.js';
|
|
4
4
|
export type RouteKind = 'exact' | 'catch-all' | 'dynamic';
|
|
5
|
+
/**
|
|
6
|
+
* What a Template Route file declares: a Page rendered to HTML, or an endpoint file whose method
|
|
7
|
+
* handler exports answer its requests. Only `page` routes take part in static generation.
|
|
8
|
+
*/
|
|
9
|
+
export type RouteRole = 'page' | 'endpoint';
|
|
5
10
|
export type RouteParams = PageParams;
|
|
6
11
|
export type RouteQuery = PageQuery;
|
|
7
12
|
export type TemplateRoute = {
|
|
8
13
|
readonly pathname: string;
|
|
9
14
|
readonly kind: RouteKind;
|
|
15
|
+
readonly role: RouteRole;
|
|
10
16
|
readonly filePath: string;
|
|
11
17
|
readonly paramNames: readonly string[];
|
|
12
18
|
};
|
|
13
19
|
export type RouteMatch = {
|
|
14
20
|
readonly requestedPathname: string;
|
|
15
|
-
readonly templateRoute: Pick<TemplateRoute, 'pathname' | 'kind' | 'filePath'> & Partial<Pick<TemplateRoute, 'paramNames'>>;
|
|
21
|
+
readonly templateRoute: Pick<TemplateRoute, 'pathname' | 'kind' | 'role' | 'filePath'> & Partial<Pick<TemplateRoute, 'paramNames'>>;
|
|
16
22
|
readonly params: RouteParams;
|
|
17
23
|
readonly query: RouteQuery;
|
|
18
24
|
};
|
|
@@ -62,22 +68,23 @@ export declare class RouteRegistry {
|
|
|
62
68
|
constructor(options: RouteRegistryOptions);
|
|
63
69
|
get origin(): string;
|
|
64
70
|
get templateRoutes(): readonly TemplateRoute[];
|
|
71
|
+
private get pageRoutes();
|
|
65
72
|
init(): Promise<void>;
|
|
66
73
|
reload(): Promise<void>;
|
|
67
74
|
onReload(listener: () => void): () => void;
|
|
68
75
|
matchRequest(requestUrl: string, parsedPathSegments?: ParsedSegmentPath): RouteMatch | null;
|
|
69
76
|
/**
|
|
70
|
-
* Orders
|
|
77
|
+
* Orders two dynamic or two catch-all routes by the specificity of their
|
|
78
|
+
* pattern segments, the catch-all segment itself left out.
|
|
71
79
|
*
|
|
72
80
|
* @remarks
|
|
73
|
-
*
|
|
81
|
+
* Segments are compared from left to right because an earlier literal
|
|
74
82
|
* segment constrains a request more strongly than a later one. A longer
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* order.
|
|
83
|
+
* pattern wins only after the shared segments tie. The pathname tie breaker
|
|
84
|
+
* keeps equal patterns deterministic without depending on discovery order.
|
|
78
85
|
*/
|
|
79
|
-
private
|
|
80
|
-
private
|
|
86
|
+
private compareSpecificity;
|
|
87
|
+
private getSpecificitySegments;
|
|
81
88
|
private isDynamicRouteSegment;
|
|
82
89
|
listStaticPathExpansions(input: {
|
|
83
90
|
runtimeOrigin: string;
|
|
@@ -89,7 +96,9 @@ export declare class RouteRegistry {
|
|
|
89
96
|
/**
|
|
90
97
|
* @remarks
|
|
91
98
|
* Strips the longest template extension the file ends with, so `about.kita.tsx` keeps no
|
|
92
|
-
* `.kita` part when `.tsx` is also registered, and `my.html-tips.html` keeps its name.
|
|
99
|
+
* `.kita` part when `.tsx` is also registered, and `my.html-tips.html` keeps its name. An
|
|
100
|
+
* endpoint strips its whole marker, so `users.api.tsx` is `/users` even when `.tsx` is a
|
|
101
|
+
* template extension.
|
|
93
102
|
*/
|
|
94
103
|
private getRoutePath;
|
|
95
104
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
2
|
import { fileSystem } from '@ecopages/file-system';
|
|
4
3
|
import { appLogger } from '../../global/app-logger.js';
|
|
5
4
|
import { invariant } from '../../utils/invariant.js';
|
|
5
|
+
import { hasKnownStaticExtension } from '../../utils/static-file-extensions.js';
|
|
6
|
+
import { ENDPOINT_FILE_EXTENSIONS, findEndpointFileExtension } from '../../utils/endpoint-file-extensions.js';
|
|
6
7
|
import { normalizePathname } from '../../utils/path-pattern.js';
|
|
7
8
|
import { parseSearchParams } from './parse-search-params.js';
|
|
8
9
|
import { findIntegrationForFile, findLongestExtension } from '../../plugins/find-integration-for-file.js';
|
|
9
|
-
import { buildSegmentPath, matchParsedSegmentPath, parseSegmentPath, } from './segment-path-matcher.js';
|
|
10
|
+
import { buildSegmentPath, matchParsedSegmentPath, parseSegmentPath, segmentPathPatternKey, } from './segment-path-matcher.js';
|
|
10
11
|
const ROUTE_PRIORITY = {
|
|
11
12
|
exact: 0,
|
|
12
13
|
dynamic: 1,
|
|
@@ -35,6 +36,9 @@ export class RouteRegistry {
|
|
|
35
36
|
get templateRoutes() {
|
|
36
37
|
return this.templateRouteList;
|
|
37
38
|
}
|
|
39
|
+
get pageRoutes() {
|
|
40
|
+
return this.templateRouteList.filter((route) => route.role === 'page');
|
|
41
|
+
}
|
|
38
42
|
async init() {
|
|
39
43
|
this.templateRouteList = await this.scanTemplateRoutes();
|
|
40
44
|
appLogger.debug('RouteRegistry initialized', this.templateRouteList);
|
|
@@ -70,30 +74,30 @@ export class RouteRegistry {
|
|
|
70
74
|
return null;
|
|
71
75
|
}
|
|
72
76
|
/**
|
|
73
|
-
* Orders
|
|
77
|
+
* Orders two dynamic or two catch-all routes by the specificity of their
|
|
78
|
+
* pattern segments, the catch-all segment itself left out.
|
|
74
79
|
*
|
|
75
80
|
* @remarks
|
|
76
|
-
*
|
|
81
|
+
* Segments are compared from left to right because an earlier literal
|
|
77
82
|
* segment constrains a request more strongly than a later one. A longer
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* order.
|
|
83
|
+
* pattern wins only after the shared segments tie. The pathname tie breaker
|
|
84
|
+
* keeps equal patterns deterministic without depending on discovery order.
|
|
81
85
|
*/
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const sharedLength = Math.min(
|
|
86
|
+
compareSpecificity(left, right) {
|
|
87
|
+
const leftSegments = this.getSpecificitySegments(left.pathname);
|
|
88
|
+
const rightSegments = this.getSpecificitySegments(right.pathname);
|
|
89
|
+
const sharedLength = Math.min(leftSegments.length, rightSegments.length);
|
|
86
90
|
for (let index = 0; index < sharedLength; index += 1) {
|
|
87
|
-
const leftIsDynamic = this.isDynamicRouteSegment(
|
|
88
|
-
const rightIsDynamic = this.isDynamicRouteSegment(
|
|
91
|
+
const leftIsDynamic = this.isDynamicRouteSegment(leftSegments[index]);
|
|
92
|
+
const rightIsDynamic = this.isDynamicRouteSegment(rightSegments[index]);
|
|
89
93
|
if (leftIsDynamic !== rightIsDynamic) {
|
|
90
94
|
return leftIsDynamic ? 1 : -1;
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
|
-
const
|
|
94
|
-
return
|
|
97
|
+
const lengthDifference = rightSegments.length - leftSegments.length;
|
|
98
|
+
return lengthDifference !== 0 ? lengthDifference : left.pathname.localeCompare(right.pathname);
|
|
95
99
|
}
|
|
96
|
-
|
|
100
|
+
getSpecificitySegments(pathname) {
|
|
97
101
|
const segments = pathname.split('/').filter(Boolean);
|
|
98
102
|
const catchAllIndex = segments.findIndex((segment) => segment.startsWith('[...') && segment.endsWith(']'));
|
|
99
103
|
return catchAllIndex === -1 ? segments : segments.slice(0, catchAllIndex);
|
|
@@ -103,7 +107,7 @@ export class RouteRegistry {
|
|
|
103
107
|
}
|
|
104
108
|
async listStaticPathExpansions(input) {
|
|
105
109
|
const expansions = [];
|
|
106
|
-
for (const route of this.
|
|
110
|
+
for (const route of this.pageRoutes) {
|
|
107
111
|
if (route.kind === 'exact') {
|
|
108
112
|
continue;
|
|
109
113
|
}
|
|
@@ -133,7 +137,7 @@ export class RouteRegistry {
|
|
|
133
137
|
async listStaticGenerationRoutes(input) {
|
|
134
138
|
const staticPathExpansions = await this.listStaticPathExpansions(input);
|
|
135
139
|
return [
|
|
136
|
-
...this.
|
|
140
|
+
...this.pageRoutes
|
|
137
141
|
.filter((route) => route.kind === 'exact')
|
|
138
142
|
.map((route) => ({
|
|
139
143
|
requestUrl: `${input.runtimeOrigin}${route.pathname}`,
|
|
@@ -150,32 +154,44 @@ export class RouteRegistry {
|
|
|
150
154
|
];
|
|
151
155
|
}
|
|
152
156
|
async scanTemplateRoutes() {
|
|
153
|
-
if (!
|
|
157
|
+
if (!fileSystem.exists(this.pagesDir)) {
|
|
154
158
|
return [];
|
|
155
159
|
}
|
|
156
|
-
const scannedFiles = await fileSystem.glob(this.templatesExt.map((ext) => `**/*${ext}`), {
|
|
160
|
+
const scannedFiles = await fileSystem.glob([...this.templatesExt, ...ENDPOINT_FILE_EXTENSIONS].map((ext) => `**/*${ext}`), {
|
|
157
161
|
cwd: this.pagesDir,
|
|
158
162
|
});
|
|
159
163
|
const templateRoutes = [];
|
|
160
|
-
const
|
|
164
|
+
const routesByKey = new Map();
|
|
161
165
|
for await (const file of scannedFiles) {
|
|
162
166
|
if (file.includes('.ecopages-node.')) {
|
|
163
167
|
continue;
|
|
164
168
|
}
|
|
165
|
-
const
|
|
169
|
+
const endpointExtension = findEndpointFileExtension(file);
|
|
170
|
+
const role = endpointExtension ? 'endpoint' : 'page';
|
|
171
|
+
const routePathname = this.getRoutePath(file, endpointExtension);
|
|
166
172
|
const filePath = path.join(this.pagesDir, file);
|
|
167
173
|
const kind = this.classifyRouteKind(file);
|
|
168
|
-
const
|
|
169
|
-
|
|
174
|
+
const routeKey = segmentPathPatternKey(routePathname, 'filesystem');
|
|
175
|
+
const duplicate = routesByKey.get(routeKey);
|
|
176
|
+
if (duplicate?.filePath === filePath) {
|
|
170
177
|
continue;
|
|
171
178
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
if (duplicate) {
|
|
180
|
+
const route = duplicate.pathname === routePathname
|
|
181
|
+
? `the route "${routePathname}"`
|
|
182
|
+
: `the same route, "${duplicate.pathname}" and "${routePathname}"`;
|
|
183
|
+
invariant(false, `${duplicate.filePath} and ${filePath} both define ${route}. Keep one of them.`);
|
|
184
|
+
}
|
|
185
|
+
routesByKey.set(routeKey, { pathname: routePathname, filePath });
|
|
186
|
+
invariant(role === 'page' || !hasKnownStaticExtension(routePathname), `${filePath}: the endpoint "${routePathname}" ends in a static file extension, so no request reaches it. Register that URL in app.ts instead.`);
|
|
187
|
+
const owner = role === 'page' && kind !== 'exact'
|
|
188
|
+
? findIntegrationForFile(this.appConfig.integrations, filePath)
|
|
189
|
+
: undefined;
|
|
175
190
|
invariant(owner?.acceptsParams !== false, `${filePath}: ${findLongestExtension(owner?.extensions ?? [], filePath)} Pages cannot receive Params, so they cannot use dynamic route segments. Rename the file, or use an eco.page() Page from an Integration that supports staticPaths.`);
|
|
176
191
|
templateRoutes.push({
|
|
177
192
|
pathname: routePathname,
|
|
178
193
|
kind,
|
|
194
|
+
role,
|
|
179
195
|
filePath,
|
|
180
196
|
paramNames: this.getParamNames(routePathname),
|
|
181
197
|
});
|
|
@@ -185,8 +201,8 @@ export class RouteRegistry {
|
|
|
185
201
|
if (priorityDifference !== 0) {
|
|
186
202
|
return priorityDifference;
|
|
187
203
|
}
|
|
188
|
-
if (left.kind
|
|
189
|
-
return this.
|
|
204
|
+
if (left.kind !== 'exact') {
|
|
205
|
+
return this.compareSpecificity(left, right);
|
|
190
206
|
}
|
|
191
207
|
if (left.pathname === '/') {
|
|
192
208
|
return -1;
|
|
@@ -200,10 +216,12 @@ export class RouteRegistry {
|
|
|
200
216
|
/**
|
|
201
217
|
* @remarks
|
|
202
218
|
* Strips the longest template extension the file ends with, so `about.kita.tsx` keeps no
|
|
203
|
-
* `.kita` part when `.tsx` is also registered, and `my.html-tips.html` keeps its name.
|
|
219
|
+
* `.kita` part when `.tsx` is also registered, and `my.html-tips.html` keeps its name. An
|
|
220
|
+
* endpoint strips its whole marker, so `users.api.tsx` is `/users` even when `.tsx` is a
|
|
221
|
+
* template extension.
|
|
204
222
|
*/
|
|
205
|
-
getRoutePath(file) {
|
|
206
|
-
const extension = findLongestExtension(this.templatesExt, file) ?? '';
|
|
223
|
+
getRoutePath(file, endpointExtension) {
|
|
224
|
+
const extension = endpointExtension ?? findLongestExtension(this.templatesExt, file) ?? '';
|
|
207
225
|
const cleanedRoute = file.slice(0, file.length - extension.length).replace(/\/?index$/, '');
|
|
208
226
|
return normalizePathname(`/${cleanedRoute}`);
|
|
209
227
|
}
|
|
@@ -35,5 +35,13 @@ export declare function matchSegmentPath(pattern: string, pathname: string, synt
|
|
|
35
35
|
* catch-all with no values disappears from the pathname.
|
|
36
36
|
*/
|
|
37
37
|
export declare function buildSegmentPath(pattern: string, params: SegmentPathParams, syntax: SegmentPathSyntax): string;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a key that two patterns share when they match the same pathnames.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Parameter names and syntax are dropped, so `/blog/:slug` and `/blog/[id]` share a key, and a
|
|
43
|
+
* catch-all shares one with a wildcard, since both take every remaining segment.
|
|
44
|
+
*/
|
|
45
|
+
export declare function segmentPathPatternKey(pattern: string, syntax: SegmentPathSyntax): string;
|
|
38
46
|
export declare function scoreSegmentPathPattern(pattern: string, syntax: 'api'): number;
|
|
39
47
|
export declare function scoreSegmentPathPattern(pattern: string, syntax: 'websocket'): number;
|
|
@@ -162,6 +162,21 @@ export function buildSegmentPath(pattern, params, syntax) {
|
|
|
162
162
|
.filter((segment) => segment !== '');
|
|
163
163
|
return normalizePathname(segments.join('/'));
|
|
164
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns a key that two patterns share when they match the same pathnames.
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* Parameter names and syntax are dropped, so `/blog/:slug` and `/blog/[id]` share a key, and a
|
|
170
|
+
* catch-all shares one with a wildcard, since both take every remaining segment.
|
|
171
|
+
*/
|
|
172
|
+
export function segmentPathPatternKey(pattern, syntax) {
|
|
173
|
+
const segments = parsePattern(pattern, syntax).map((segment) => {
|
|
174
|
+
if (segment.kind === 'literal')
|
|
175
|
+
return encodeURIComponent(segment.value);
|
|
176
|
+
return segment.kind === 'parameter' ? '[]' : '[...]';
|
|
177
|
+
});
|
|
178
|
+
return `/${segments.join('/')}`;
|
|
179
|
+
}
|
|
165
180
|
export function scoreSegmentPathPattern(pattern, syntax) {
|
|
166
181
|
const segments = parsePattern(pattern, syntax);
|
|
167
182
|
if (syntax === 'websocket') {
|
|
@@ -293,7 +293,7 @@ export class StaticSiteGenerator {
|
|
|
293
293
|
async executeStaticGenerationBody(input) {
|
|
294
294
|
if (shouldPrebuildProductionPageBrowserGraphs() && input.routeRendererFactory) {
|
|
295
295
|
const dynamicRouteTemplates = (input.router.templateRoutes ?? [])
|
|
296
|
-
.filter((route) => route.kind !== 'exact')
|
|
296
|
+
.filter((route) => route.kind !== 'exact' && route.role === 'page')
|
|
297
297
|
.map((route) => ({ routeFile: route.filePath, skipStaticProps: true, isRouteTemplate: true }));
|
|
298
298
|
await prebuildProductionPageBrowserGraphs(this.appConfig, [
|
|
299
299
|
...input.routes.map((route) => ({
|