@ecopages/core 0.4.0 → 0.5.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 +3 -3
- package/package.json +3 -3
- package/src/adapters/shared/http/api-request-pipeline.js +2 -2
- package/src/adapters/shared/runtime/server-request-pipeline.js +1 -0
- package/src/adapters/shared/runtime/server-route-handler.js +4 -4
- package/src/assets/app-browser-client-build.js +8 -21
- package/src/assets/app-browser-client-manifest.d.ts +0 -1
- package/src/assets/app-browser-client-manifest.js +1 -20
- package/src/build/contracts/content-virtual-modules.d.ts +9 -3
- package/src/build/contracts/content-virtual-modules.js +11 -5
- package/src/build/contracts.d.ts +1 -1
- package/src/build/contracts.js +1 -1
- package/src/build/rolldown/rolldown-plugin-bridge.js +2 -2
- package/src/build.d.ts +1 -1
- package/src/build.js +1 -1
- package/src/dev/transform-server/dev-transform-server.js +1 -1
- package/src/dev/transform-server/dev-transform-vendor-registry.d.ts +29 -6
- package/src/dev/transform-server/dev-transform-vendor-registry.js +101 -53
- package/src/errors/http-error.d.ts +9 -0
- package/src/errors/http-error.js +11 -0
- package/src/html/html-transformer.service.d.ts +0 -21
- package/src/html/html-transformer.service.js +0 -32
- package/src/html-pages/html-page-renderer.d.ts +2 -1
- package/src/html-pages/html-page-renderer.js +5 -3
- package/src/integration.d.ts +1 -2
- package/src/integration.js +0 -1
- package/src/islands/island-host.d.ts +1 -2
- package/src/islands/island-host.js +1 -2
- package/src/plugins/integration-plugin.d.ts +1 -1
- package/src/plugins/processor.d.ts +1 -1
- package/src/plugins/tsconfig-import-resolver.d.ts +3 -1
- package/src/plugins/tsconfig-import-resolver.js +4 -2
- package/src/processor.d.ts +1 -1
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.d.ts +2 -44
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +14 -89
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +4 -16
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +2 -10
- package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +3 -5
- package/src/route-renderer/orchestration/integration-renderer.d.ts +20 -44
- package/src/route-renderer/orchestration/integration-renderer.js +52 -115
- package/src/route-renderer/orchestration/ownership-graph/page-client-browser-assets.d.ts +3 -4
- package/src/route-renderer/orchestration/ownership-graph/page-client-browser-assets.js +4 -15
- package/src/route-renderer/orchestration/ownership-graph/prepared-graph-membership.d.ts +22 -0
- package/src/route-renderer/orchestration/ownership-graph/prepared-graph-membership.js +45 -0
- package/src/route-renderer/orchestration/page-browser-graph/grouped-graph-build-plan.d.ts +0 -1
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +4 -3
- package/src/router/server/route-registry.d.ts +2 -0
- package/src/router/server/route-registry.js +3 -0
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +0 -4
- package/src/types/build-types.d.ts +6 -0
- package/src/types/contracts.d.ts +6 -4
- package/src/types/eco-api-types.d.ts +1 -1
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.d.ts +0 -12
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-merge.utils.js +0 -32
package/README.md
CHANGED
|
@@ -26,8 +26,8 @@ The important ownership rules are:
|
|
|
26
26
|
- Component identity attribution is one build plugin, shared by server, browser, and HMR compilation paths: after a lexical `eco.` gate, it uses Oxc to wrap supported factory options with `bindComponentIdentity()`, which factories retain as `config.identity`.
|
|
27
27
|
- Component ownership follows `config.integration`, then `config.identity.integration`, then the inherited owner through the exported `getComponentOwner()` helper. Integration plugins opt into page-owned asset bundling with `bundlesPageDependencies`; React and Ecopages JSX enable it. Bundling only combines consecutive eligible assets so custom-attribute files keep their declared order.
|
|
28
28
|
- Direct local Eco Component imports (including named `export { X } from` barrels) and relative side-effect CSS imports supply Dependencies by default through the shared transform and existing collector; explicit asset declarations override inference, and inferred styles stay keyed by identity until collection. Eco owns the component render context used by its factories. See [eco](src/eco/README.md) and [Plugin Contracts](src/plugins/README.md).
|
|
29
|
-
- Every Integration shares one renderer and the app-owned `AssetProcessingService` across route renders, explicit views, and foreign-child handoffs. Integration-owned asset processing calls pass their owning Integration so its optional dependency-preparation hook can run; one service cache covers grouped and ungrouped processor results. Route preparation records one component graph for ownership validation, dependencies, client assets, and dev cache paths. Dependency collection uses the service to turn declared assets into runtime-ready output instead of treating a missing service as an empty asset set. Route renders
|
|
30
|
-
- Custom Integrations can create a renderer with `createIntegrationRenderer()` and opt into component, page-graph, document-shell props and composition, foreign-child, route lifecycle, grouped island assets, and finalization hooks without rebuilding the route pipeline. Hook factories receive app-owned renderer options plus helpers for Integration-wide dependencies,
|
|
29
|
+
- Every Integration shares one renderer and the app-owned `AssetProcessingService` across route renders, explicit views, and foreign-child handoffs. Integration-owned asset processing calls pass their owning Integration so its optional dependency-preparation hook can run; one service cache covers grouped and ungrouped processor results. Route preparation records one component graph for ownership validation, dependencies, client assets, and dev cache paths; a development render fails on a component outside it. Dependency collection uses the service to turn declared assets into runtime-ready output instead of treating a missing service as an empty asset set. Route preparation builds each Page Package once; component renders return HTML and attributes only and add no assets. Route renders keep Integration dependencies and foreign-renderer caches in per-render sessions, with async context storage isolating concurrent renders. See [Route Renderer](src/route-renderer/README.md).
|
|
30
|
+
- Custom Integrations can create a renderer with `createIntegrationRenderer()` and opt into component, page-graph, document-shell props and composition, foreign-child, route lifecycle, grouped island assets, and finalization hooks without rebuilding the route pipeline. Hook factories receive app-owned renderer options plus helpers for Integration-wide dependencies, dependency paths, and pending lazy triggers. Core handles queued-child resolution and island-host finalization around component hooks. See [Custom Integration](../../apps/docs/src/content/docs/plugins/custom-integration.mdx).
|
|
31
31
|
- Browser bundling and server module loading are separate paths. SSR-enabled lazy scripts execute on the server before rendering and in the browser only on their configured trigger.
|
|
32
32
|
- The Project Watcher batches file and directory events, sends matching Processors one `onChanges` notification for each non-restart file batch, and dispatches every HMR-eligible path once per debounce window. Directory-only Pages batches refresh routes without Processor or HMR notifications. Sustained edits are scheduled no later than one second after the first; processing is serialized and startup fails if the filesystem subscription is not ready within 30 seconds. See [Project Watcher](src/watchers/README.md).
|
|
33
33
|
- Development Page prewarm renders run in the background without delaying server readiness. App configuration declares `devPrewarmPaths`; Processors append the pathnames they own to that list from `setup()`, which finishes before the server reports that it is listening. A path that fails to render is skipped and logged at debug level. See [Runtime Adapters](src/adapters/README.md) and [Plugin Contracts](src/plugins/README.md).
|
|
@@ -295,7 +295,7 @@ export const GET = defineGet({
|
|
|
295
295
|
});
|
|
296
296
|
```
|
|
297
297
|
|
|
298
|
-
The file's rules (405 and `Allow`, load errors, `app.ts` routes on the same URL) are in the [
|
|
298
|
+
The file's rules (405 and `Allow`, load errors, `app.ts` routes on the same URL) are in the [Endpoint Files docs](https://ecopages.app/docs/server/endpoint-files); the contracts are in `src/router/README.md` and `src/adapters/README.md`. A build of an app with an endpoint file checks each file's exports, then emits the server bundle (`dist/.server/`) even when nothing else registers a handler, so `ecopages start` serves it.
|
|
299
299
|
|
|
300
300
|
### 6. Error pages
|
|
301
301
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Core package for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@clack/prompts": "^1.7.0",
|
|
24
|
-
"@ecopages/file-system": "0.
|
|
24
|
+
"@ecopages/file-system": "0.5.0",
|
|
25
25
|
"@ecopages/logger": "^0.2.3",
|
|
26
26
|
"@ecopages/scripts-injector": "^0.1.5",
|
|
27
27
|
"@jridgewell/remapping": "^2.3.5",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"ws": "^8.20.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@ecopages/dev-toolbar": "0.
|
|
38
|
+
"@ecopages/dev-toolbar": "0.5.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@ecopages/dev-toolbar": {
|
|
@@ -85,8 +85,8 @@ export class ApiRequestPipeline {
|
|
|
85
85
|
appLogger.error('[ecopages] Error in custom error handler', handlerError);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
if (error
|
|
89
|
-
return
|
|
88
|
+
if (HttpError.isHttpError(error))
|
|
89
|
+
return HttpError.responseFor(error);
|
|
90
90
|
appLogger.error('[ecopages] Error handling request', error);
|
|
91
91
|
return new Response('Internal Server Error', { status: 500 });
|
|
92
92
|
}
|
|
@@ -65,8 +65,8 @@ export class ServerRouteHandler {
|
|
|
65
65
|
: this.fileSystemResponseMatcher.handleMatch(fsMatch, request));
|
|
66
66
|
}
|
|
67
67
|
catch (error) {
|
|
68
|
-
if (error
|
|
69
|
-
return
|
|
68
|
+
if (HttpError.isHttpError(error)) {
|
|
69
|
+
return HttpError.responseFor(error);
|
|
70
70
|
}
|
|
71
71
|
throw error;
|
|
72
72
|
}
|
|
@@ -88,8 +88,8 @@ export class ServerRouteHandler {
|
|
|
88
88
|
return await this.fileSystemResponseMatcher.handleNoMatch(pathname, request);
|
|
89
89
|
}
|
|
90
90
|
catch (error) {
|
|
91
|
-
if (error
|
|
92
|
-
return
|
|
91
|
+
if (HttpError.isHttpError(error)) {
|
|
92
|
+
return HttpError.responseFor(error);
|
|
93
93
|
}
|
|
94
94
|
if (error instanceof Error) {
|
|
95
95
|
this.router.appConfig?.appRuntime?.hmr?.broadcast({ type: 'error', message: error.message });
|
|
@@ -278,7 +278,6 @@ function registerPageClientEntry(appConfig, entriesByKey, cleanupEntries, instan
|
|
|
278
278
|
if (!canBundle(dependency)) {
|
|
279
279
|
instance.prebuiltPageClientBrowserAssets ??= {
|
|
280
280
|
processedAssets: [],
|
|
281
|
-
islandRenderAssetsByFile: new Map(),
|
|
282
281
|
fallbackDependencies: [],
|
|
283
282
|
};
|
|
284
283
|
instance.prebuiltPageClientBrowserAssets.fallbackDependencies.push({
|
|
@@ -292,12 +291,9 @@ function registerPageClientEntry(appConfig, entriesByKey, cleanupEntries, instan
|
|
|
292
291
|
if (!entry.dependencies.some((entryDependency) => dependencyAssociationKey(entryDependency) === identity)) {
|
|
293
292
|
entry.dependencies.push(dependency);
|
|
294
293
|
}
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
};
|
|
299
|
-
association.routes.set(routeKey, clientEntry.islandFile);
|
|
300
|
-
entry.pageClientRoutes.set(identity, association);
|
|
294
|
+
const routes = entry.pageClientRoutes.get(identity) ?? new Set();
|
|
295
|
+
routes.add(routeKey);
|
|
296
|
+
entry.pageClientRoutes.set(identity, routes);
|
|
301
297
|
return { ...clientEntry, dependency };
|
|
302
298
|
}
|
|
303
299
|
function prepareRouteBuildPlan(appConfig, plan, entriesByKey, cleanupEntries) {
|
|
@@ -335,29 +331,20 @@ function prepareRouteBuildPlans(appConfig, plans, cleanupEntries) {
|
|
|
335
331
|
const routePlans = plans.map((plan) => prepareRouteBuildPlan(appConfig, plan, entriesByKey, cleanupEntries));
|
|
336
332
|
return { routePlans, entries: [...entriesByKey.values()] };
|
|
337
333
|
}
|
|
338
|
-
function attachPageClientAsset(instance, asset
|
|
339
|
-
const prebuilt = instance.prebuiltPageClientBrowserAssets ?? {
|
|
340
|
-
processedAssets: [],
|
|
341
|
-
islandRenderAssetsByFile: new Map(),
|
|
342
|
-
fallbackDependencies: [],
|
|
343
|
-
};
|
|
334
|
+
function attachPageClientAsset(instance, asset) {
|
|
335
|
+
const prebuilt = instance.prebuiltPageClientBrowserAssets ?? { processedAssets: [], fallbackDependencies: [] };
|
|
344
336
|
prebuilt.processedAssets.push(asset);
|
|
345
|
-
if (islandFile) {
|
|
346
|
-
const islandAssets = prebuilt.islandRenderAssetsByFile.get(islandFile) ?? [];
|
|
347
|
-
islandAssets.push(asset);
|
|
348
|
-
prebuilt.islandRenderAssetsByFile.set(islandFile, islandAssets);
|
|
349
|
-
}
|
|
350
337
|
instance.prebuiltPageClientBrowserAssets = prebuilt;
|
|
351
338
|
}
|
|
352
339
|
function attachEntryAssetToRoutes(entry, dependency, asset, routePlans) {
|
|
353
|
-
const
|
|
340
|
+
const pageClientRoutes = entry.pageClientRoutes.get(dependencyAssociationKey(dependency));
|
|
354
341
|
for (const routePlan of routePlans) {
|
|
355
342
|
for (const { instance, routeKey } of routePlan.instances) {
|
|
356
343
|
if (entry.dependencyRoutes.get(dependency)?.has(routeKey)) {
|
|
357
344
|
instance.prebuiltGroupedAssets = [...(instance.prebuiltGroupedAssets ?? []), asset];
|
|
358
345
|
}
|
|
359
|
-
if (
|
|
360
|
-
attachPageClientAsset(instance, asset
|
|
346
|
+
if (pageClientRoutes?.has(routeKey)) {
|
|
347
|
+
attachPageClientAsset(instance, asset);
|
|
361
348
|
}
|
|
362
349
|
}
|
|
363
350
|
}
|
|
@@ -27,7 +27,6 @@ export type AppBrowserClientManifestEntry = {
|
|
|
27
27
|
groupedAssets: SerializedProcessedAsset[];
|
|
28
28
|
pageClientAssets: {
|
|
29
29
|
processedAssets: SerializedProcessedAsset[];
|
|
30
|
-
islandRenderAssetsByFile: Array<[string, SerializedProcessedAsset[]]>;
|
|
31
30
|
fallbackPageClientBuildEntryKeys: string[];
|
|
32
31
|
};
|
|
33
32
|
};
|
|
@@ -78,13 +78,6 @@ function isStringArray(value) {
|
|
|
78
78
|
function isProcessedAssetArray(value) {
|
|
79
79
|
return Array.isArray(value) && value.every(isProcessedAsset);
|
|
80
80
|
}
|
|
81
|
-
function isIslandRenderAssetEntries(value) {
|
|
82
|
-
return (Array.isArray(value) &&
|
|
83
|
-
value.every((entry) => Array.isArray(entry) &&
|
|
84
|
-
entry.length === 2 &&
|
|
85
|
-
typeof entry[0] === 'string' &&
|
|
86
|
-
isProcessedAssetArray(entry[1])));
|
|
87
|
-
}
|
|
88
81
|
function isManifestEntry(value) {
|
|
89
82
|
if (!isRecord(value) || !isRecord(value.pageClientAssets))
|
|
90
83
|
return false;
|
|
@@ -99,8 +92,7 @@ function isManifestEntry(value) {
|
|
|
99
92
|
isStringArray(value.pageClientBuildEntryKeys) &&
|
|
100
93
|
isProcessedAssetArray(value.groupedAssets) &&
|
|
101
94
|
isProcessedAssetArray(pageClientAssets.processedAssets) &&
|
|
102
|
-
isStringArray(pageClientAssets.fallbackPageClientBuildEntryKeys)
|
|
103
|
-
isIslandRenderAssetEntries(pageClientAssets.islandRenderAssetsByFile));
|
|
95
|
+
isStringArray(pageClientAssets.fallbackPageClientBuildEntryKeys));
|
|
104
96
|
}
|
|
105
97
|
function isManifest(value) {
|
|
106
98
|
return (isRecord(value) &&
|
|
@@ -137,10 +129,6 @@ function serializeEntry(rootDir, plan, instance, params) {
|
|
|
137
129
|
groupedAssets: (instance.prebuiltGroupedAssets ?? []).map((asset) => serializeProcessedAsset(rootDir, asset)),
|
|
138
130
|
pageClientAssets: {
|
|
139
131
|
processedAssets: (pageClientAssets?.processedAssets ?? []).map((asset) => serializeProcessedAsset(rootDir, asset)),
|
|
140
|
-
islandRenderAssetsByFile: [...(pageClientAssets?.islandRenderAssetsByFile ?? [])].map(([filePath, assets]) => [
|
|
141
|
-
toProjectPath(rootDir, filePath),
|
|
142
|
-
assets.map((asset) => serializeProcessedAsset(rootDir, asset)),
|
|
143
|
-
]),
|
|
144
132
|
fallbackPageClientBuildEntryKeys,
|
|
145
133
|
},
|
|
146
134
|
};
|
|
@@ -168,10 +156,6 @@ function collectInstanceSourceFilepaths(filepaths, instance) {
|
|
|
168
156
|
for (const asset of instance.prebuiltPageClientBrowserAssets?.processedAssets ?? []) {
|
|
169
157
|
addAssetSourceFilepaths(filepaths, asset);
|
|
170
158
|
}
|
|
171
|
-
for (const assets of instance.prebuiltPageClientBrowserAssets?.islandRenderAssetsByFile.values() ?? []) {
|
|
172
|
-
for (const asset of assets)
|
|
173
|
-
addAssetSourceFilepaths(filepaths, asset);
|
|
174
|
-
}
|
|
175
159
|
}
|
|
176
160
|
function collectSourceFilepaths(plans) {
|
|
177
161
|
const filepaths = new Set();
|
|
@@ -190,9 +174,6 @@ function addAssetOutputFilepaths(filepaths, assets = []) {
|
|
|
190
174
|
function collectInstanceOutputFilepaths(filepaths, instance) {
|
|
191
175
|
addAssetOutputFilepaths(filepaths, instance.prebuiltGroupedAssets);
|
|
192
176
|
addAssetOutputFilepaths(filepaths, instance.prebuiltPageClientBrowserAssets?.processedAssets);
|
|
193
|
-
for (const assets of instance.prebuiltPageClientBrowserAssets?.islandRenderAssetsByFile.values() ?? []) {
|
|
194
|
-
addAssetOutputFilepaths(filepaths, assets);
|
|
195
|
-
}
|
|
196
177
|
}
|
|
197
178
|
function addHtmlScriptOutputFilepaths(filepaths, distDir, htmlPageModuleScriptUrls) {
|
|
198
179
|
for (const url of Object.values(htmlPageModuleScriptUrls)) {
|
|
@@ -4,11 +4,17 @@ export declare const CONTENT_VIRTUAL_MODULE_PREFIX = "ecopages:content";
|
|
|
4
4
|
export declare const CONTENT_VIRTUAL_MODULE_PATTERN: RegExp;
|
|
5
5
|
/** Matches `ecopages:content/<collection>/server` component resolver specifiers. */
|
|
6
6
|
export declare const CONTENT_SERVER_VIRTUAL_MODULE_PATTERN: RegExp;
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Matches `ecopages:content/<collection>/component` loader specifiers.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* The server graph resolves this specifier to the `/server` module and the Page Browser Graph
|
|
12
|
+
* resolves it to the browser-safe loader, so one import serves both sides.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN: RegExp;
|
|
9
15
|
export type ParsedCollectionSpecifier = {
|
|
10
16
|
collectionName: string;
|
|
11
|
-
variant: 'entries' | 'server' | '
|
|
17
|
+
variant: 'entries' | 'server' | 'component';
|
|
12
18
|
};
|
|
13
19
|
export declare function parseCollectionSpecifier(specifier: string): ParsedCollectionSpecifier | null;
|
|
14
20
|
export declare function isContentServerVirtualModule(specifier: string): boolean;
|
|
@@ -4,8 +4,14 @@ export const CONTENT_VIRTUAL_MODULE_PREFIX = 'ecopages:content';
|
|
|
4
4
|
export const CONTENT_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]*$/;
|
|
5
5
|
/** Matches `ecopages:content/<collection>/server` component resolver specifiers. */
|
|
6
6
|
export const CONTENT_SERVER_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]+\/server$/;
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Matches `ecopages:content/<collection>/component` loader specifiers.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* The server graph resolves this specifier to the `/server` module and the Page Browser Graph
|
|
12
|
+
* resolves it to the browser-safe loader, so one import serves both sides.
|
|
13
|
+
*/
|
|
14
|
+
export const CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN = /^ecopages:content\/[a-z][a-z0-9-]+\/component$/;
|
|
9
15
|
export function parseCollectionSpecifier(specifier) {
|
|
10
16
|
const normalized = specifier.startsWith(`${CONTENT_VIRTUAL_MODULE_PREFIX}/`)
|
|
11
17
|
? specifier.slice(`${CONTENT_VIRTUAL_MODULE_PREFIX}/`.length)
|
|
@@ -21,10 +27,10 @@ export function parseCollectionSpecifier(specifier) {
|
|
|
21
27
|
variant: 'server',
|
|
22
28
|
};
|
|
23
29
|
}
|
|
24
|
-
if (normalized.endsWith('/
|
|
30
|
+
if (normalized.endsWith('/component')) {
|
|
25
31
|
return {
|
|
26
|
-
collectionName: normalized.slice(0, -'/
|
|
27
|
-
variant: '
|
|
32
|
+
collectionName: normalized.slice(0, -'/component'.length),
|
|
33
|
+
variant: 'component',
|
|
28
34
|
};
|
|
29
35
|
}
|
|
30
36
|
return {
|
package/src/build/contracts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type * from './contracts/build-contracts.js';
|
|
2
2
|
export type * from './contracts/build-types.js';
|
|
3
|
-
export {
|
|
3
|
+
export { CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, isContentServerVirtualModule, parseCollectionSpecifier, type ParsedCollectionSpecifier, } from './contracts/content-virtual-modules.js';
|
|
4
4
|
export { isServerOnlyModuleSpecifier } from './contracts/server-only-specifier.js';
|
package/src/build/contracts.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, isContentServerVirtualModule, parseCollectionSpecifier, } from './contracts/content-virtual-modules.js';
|
|
2
2
|
export { isServerOnlyModuleSpecifier } from './contracts/server-only-specifier.js';
|
|
@@ -338,7 +338,7 @@ export async function createRolldownPluginBridge(plugins, contextRoot, recordBui
|
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
registrationClosed = true;
|
|
341
|
-
const resolveIdHandler = async (source, importer) => {
|
|
341
|
+
const resolveIdHandler = async (source, importer, extraOptions) => {
|
|
342
342
|
for (const { matches, callback, pluginName } of resolveRegistrations) {
|
|
343
343
|
if (!matches(source)) {
|
|
344
344
|
continue;
|
|
@@ -346,7 +346,7 @@ export async function createRolldownPluginBridge(plugins, contextRoot, recordBui
|
|
|
346
346
|
const { namespace, path: sourcePath } = splitNamespace(source);
|
|
347
347
|
let result;
|
|
348
348
|
try {
|
|
349
|
-
result = await callback({ path: sourcePath, importer, namespace });
|
|
349
|
+
result = await callback({ path: sourcePath, importer, namespace, kind: extraOptions?.kind });
|
|
350
350
|
}
|
|
351
351
|
catch (error) {
|
|
352
352
|
throw new EcoBuildPluginError(error, pluginName, importer);
|
package/src/build.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { createBrowserRuntimePlugin, DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME, getBro
|
|
|
3
3
|
export { getHostScopedJsxOwnershipPlugins } from './build/browser/jsx-ownership-plugins.js';
|
|
4
4
|
export { isLitStaticRenderWorkerThread } from './build/browser/lit-static-render-worker-context.js';
|
|
5
5
|
export { type BuildAdapter, type BuildExecutor, type BuildOptions, type BuildResult, setupAppRuntimeIntegrations, setupAppRuntimePlugins, teardownAppRuntimeIntegrations, } from './build/build-adapter.js';
|
|
6
|
-
export {
|
|
6
|
+
export { CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, isContentServerVirtualModule, parseCollectionSpecifier, type ParsedCollectionSpecifier, } from './build/contracts/content-virtual-modules.js';
|
|
7
7
|
export { isServerOnlyModuleSpecifier } from './build/contracts/server-only-specifier.js';
|
|
8
8
|
export { BuildQueue } from './build/runtime/build-queue.js';
|
|
9
9
|
export { buildServerModule } from './build/server-module.js';
|
package/src/build.js
CHANGED
|
@@ -3,7 +3,7 @@ export { createBrowserRuntimePlugin, DEFAULT_BROWSER_RUNTIME_PLUGIN_NAME, getBro
|
|
|
3
3
|
export { getHostScopedJsxOwnershipPlugins } from './build/browser/jsx-ownership-plugins.js';
|
|
4
4
|
export { isLitStaticRenderWorkerThread } from './build/browser/lit-static-render-worker-context.js';
|
|
5
5
|
export { setupAppRuntimeIntegrations, setupAppRuntimePlugins, teardownAppRuntimeIntegrations, } from './build/build-adapter.js';
|
|
6
|
-
export {
|
|
6
|
+
export { CONTENT_COMPONENT_VIRTUAL_MODULE_PATTERN, CONTENT_SERVER_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PATTERN, CONTENT_VIRTUAL_MODULE_PREFIX, isContentServerVirtualModule, parseCollectionSpecifier, } from './build/contracts/content-virtual-modules.js';
|
|
7
7
|
export { isServerOnlyModuleSpecifier } from './build/contracts/server-only-specifier.js';
|
|
8
8
|
export { BuildQueue } from './build/runtime/build-queue.js';
|
|
9
9
|
export { buildServerModule } from './build/server-module.js';
|
|
@@ -126,7 +126,7 @@ export class DevTransformServer {
|
|
|
126
126
|
}
|
|
127
127
|
async tryHandleRequest(request) {
|
|
128
128
|
const url = new URL(request.url);
|
|
129
|
-
const vendorResponse = this.vendorRegistry.tryHandleVendorRequest(url.pathname, request.headers.get('If-None-Match'));
|
|
129
|
+
const vendorResponse = await this.vendorRegistry.tryHandleVendorRequest(url.pathname, request.headers.get('If-None-Match'));
|
|
130
130
|
if (vendorResponse) {
|
|
131
131
|
return vendorResponse;
|
|
132
132
|
}
|
|
@@ -6,23 +6,46 @@ export type DevTransformVendorRegistryOptions = {
|
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Lazily prebundles bare npm imports into process-local `/assets/vendors/*` chunks.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* A vendor bundle keeps the ESM imports of other packages external and points them at those packages' own
|
|
12
|
+
* vendor URLs, so a package shared by several vendors, such as a framework core, loads once in the browser
|
|
13
|
+
* and keeps one module identity. `require()` calls stay bundled, since a vendor URL is an ES module that
|
|
14
|
+
* `require()` cannot load.
|
|
9
15
|
*/
|
|
10
16
|
export declare class DevTransformVendorRegistry {
|
|
11
17
|
private readonly appConfig;
|
|
12
18
|
private readonly browserBundleService;
|
|
13
19
|
private readonly resolveVendorBundlePlugins?;
|
|
14
|
-
private
|
|
15
|
-
private
|
|
20
|
+
private records;
|
|
21
|
+
private recordsByUrl;
|
|
16
22
|
constructor(options: DevTransformVendorRegistryOptions);
|
|
17
23
|
resolveVendorUrl(specifier: string): Promise<string>;
|
|
18
24
|
/**
|
|
19
25
|
* @remarks
|
|
20
|
-
*
|
|
21
|
-
*
|
|
26
|
+
* A vendor that another vendor references may still be building when the browser asks for it, so the
|
|
27
|
+
* request waits for that build. Responses carry `no-cache` and a content `ETag`, so browsers revalidate
|
|
28
|
+
* each load and get `304` while `ifNoneMatch` still matches the in-memory bundle.
|
|
22
29
|
*/
|
|
23
|
-
tryHandleVendorRequest(pathname: string, ifNoneMatch?: string | null): Response | null
|
|
30
|
+
tryHandleVendorRequest(pathname: string, ifNoneMatch?: string | null): Promise<Response | null>;
|
|
24
31
|
invalidateAll(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the record for a package entry, starting its build when no build exists yet.
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* The build is not awaited here: two vendors that import each other would otherwise wait on each other.
|
|
37
|
+
* Failures are kept on the record and reported to whoever awaits the build or requests the URL.
|
|
38
|
+
*/
|
|
39
|
+
private ensureVendor;
|
|
25
40
|
private createVendorResponse;
|
|
26
|
-
private
|
|
41
|
+
private prebundle;
|
|
42
|
+
/**
|
|
43
|
+
* Points the ESM imports of other packages inside one vendor bundle at those packages' vendor URLs.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* It runs after the vendor plugins, so a specifier the browser runtime manifest owns keeps the manifest's
|
|
47
|
+
* URL. Each dependency resolves from its importer, where a strict install places it.
|
|
48
|
+
*/
|
|
49
|
+
private createSharedPackagePlugin;
|
|
27
50
|
private resolvePackageEntry;
|
|
28
51
|
}
|
|
@@ -2,7 +2,7 @@ import { contentHash } from '../../utils/content-hash.js';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { RESOLVED_ASSETS_VENDORS_DIR } from '../../constants.js';
|
|
4
4
|
import { resolveAppBuildPlugins } from '../../build/runtime/build-request-policy.js';
|
|
5
|
-
import { resolveBarePackageBrowserEntry } from '../../plugins/tsconfig-import-resolver.js';
|
|
5
|
+
import { isBarePackageImportSpecifier, resolveBarePackageBrowserEntry, } from '../../plugins/tsconfig-import-resolver.js';
|
|
6
6
|
import { toPackageRootSpecifier } from '../../plugins/package-specifier.js';
|
|
7
7
|
import { BrowserBundleService } from '../../assets/browser-bundle.service.js';
|
|
8
8
|
import { assertBuildSucceeded } from '../../build/build-log.js';
|
|
@@ -16,62 +16,89 @@ function getVendorBundleConditions(specifier) {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Lazily prebundles bare npm imports into process-local `/assets/vendors/*` chunks.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* A vendor bundle keeps the ESM imports of other packages external and points them at those packages' own
|
|
22
|
+
* vendor URLs, so a package shared by several vendors, such as a framework core, loads once in the browser
|
|
23
|
+
* and keeps one module identity. `require()` calls stay bundled, since a vendor URL is an ES module that
|
|
24
|
+
* `require()` cannot load.
|
|
19
25
|
*/
|
|
20
26
|
export class DevTransformVendorRegistry {
|
|
21
27
|
appConfig;
|
|
22
28
|
browserBundleService;
|
|
23
29
|
resolveVendorBundlePlugins;
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
records = new Map();
|
|
31
|
+
recordsByUrl = new Map();
|
|
26
32
|
constructor(options) {
|
|
27
33
|
this.appConfig = options.appConfig;
|
|
28
34
|
this.browserBundleService = new BrowserBundleService(options.appConfig);
|
|
29
35
|
this.resolveVendorBundlePlugins = options.resolveVendorBundlePlugins;
|
|
30
36
|
}
|
|
31
37
|
async resolveVendorUrl(specifier) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const pending = this.inFlight.get(specifier);
|
|
37
|
-
if (pending) {
|
|
38
|
-
return (await pending).url;
|
|
39
|
-
}
|
|
40
|
-
const promise = this.prebundleSpecifier(specifier)
|
|
41
|
-
.then((entry) => {
|
|
42
|
-
if (this.inFlight.get(specifier) === promise) {
|
|
43
|
-
this.cache.set(specifier, entry);
|
|
44
|
-
}
|
|
45
|
-
return entry;
|
|
46
|
-
})
|
|
47
|
-
.finally(() => {
|
|
48
|
-
if (this.inFlight.get(specifier) === promise) {
|
|
49
|
-
this.inFlight.delete(specifier);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
this.inFlight.set(specifier, promise);
|
|
53
|
-
return (await promise).url;
|
|
38
|
+
const entryPath = this.resolvePackageEntry(specifier, this.appConfig.rootDir);
|
|
39
|
+
const record = this.ensureVendor(specifier, entryPath);
|
|
40
|
+
await record.build;
|
|
41
|
+
return record.url;
|
|
54
42
|
}
|
|
55
43
|
/**
|
|
56
44
|
* @remarks
|
|
57
|
-
*
|
|
58
|
-
*
|
|
45
|
+
* A vendor that another vendor references may still be building when the browser asks for it, so the
|
|
46
|
+
* request waits for that build. Responses carry `no-cache` and a content `ETag`, so browsers revalidate
|
|
47
|
+
* each load and get `304` while `ifNoneMatch` still matches the in-memory bundle.
|
|
59
48
|
*/
|
|
60
|
-
tryHandleVendorRequest(pathname, ifNoneMatch) {
|
|
61
|
-
|
|
62
|
-
if (!pathname.startsWith(prefix)) {
|
|
49
|
+
async tryHandleVendorRequest(pathname, ifNoneMatch) {
|
|
50
|
+
if (!pathname.startsWith(`/${RESOLVED_ASSETS_VENDORS_DIR}/`)) {
|
|
63
51
|
return null;
|
|
64
52
|
}
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
53
|
+
const record = this.recordsByUrl.get(pathname);
|
|
54
|
+
if (!record) {
|
|
67
55
|
return null;
|
|
68
56
|
}
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
try {
|
|
58
|
+
return this.createVendorResponse(await record.build, ifNoneMatch);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return new Response(error instanceof Error ? error.message : String(error), {
|
|
62
|
+
status: 500,
|
|
63
|
+
headers: { 'Content-Type': 'text/plain', 'Cache-Control': 'no-store' },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
71
66
|
}
|
|
72
67
|
invalidateAll() {
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
68
|
+
this.records = new Map();
|
|
69
|
+
this.recordsByUrl = new Map();
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns the record for a package entry, starting its build when no build exists yet.
|
|
73
|
+
*
|
|
74
|
+
* @remarks
|
|
75
|
+
* The build is not awaited here: two vendors that import each other would otherwise wait on each other.
|
|
76
|
+
* Failures are kept on the record and reported to whoever awaits the build or requests the URL.
|
|
77
|
+
*/
|
|
78
|
+
ensureVendor(specifier, entryPath) {
|
|
79
|
+
const existing = this.records.get(entryPath);
|
|
80
|
+
if (existing) {
|
|
81
|
+
return existing;
|
|
82
|
+
}
|
|
83
|
+
const records = this.records;
|
|
84
|
+
const record = {
|
|
85
|
+
specifier,
|
|
86
|
+
entryPath,
|
|
87
|
+
url: `/${RESOLVED_ASSETS_VENDORS_DIR}/${sanitizeSpecifierForFileName(specifier)}.${contentHash(entryPath, 8)}.js`,
|
|
88
|
+
build: Promise.resolve(undefined),
|
|
89
|
+
};
|
|
90
|
+
record.build = this.prebundle(record).then((entry) => {
|
|
91
|
+
if (this.records === records)
|
|
92
|
+
record.entry = entry;
|
|
93
|
+
return entry;
|
|
94
|
+
}, (error) => {
|
|
95
|
+
record.error = error;
|
|
96
|
+
throw error;
|
|
97
|
+
});
|
|
98
|
+
record.build.catch(() => { });
|
|
99
|
+
this.records.set(entryPath, record);
|
|
100
|
+
this.recordsByUrl.set(record.url, record);
|
|
101
|
+
return record;
|
|
75
102
|
}
|
|
76
103
|
createVendorResponse(entry, ifNoneMatch) {
|
|
77
104
|
const etag = `"${contentHash(entry.content, 16)}"`;
|
|
@@ -83,38 +110,62 @@ export class DevTransformVendorRegistry {
|
|
|
83
110
|
headers: { ...headers, 'Content-Type': 'application/javascript' },
|
|
84
111
|
});
|
|
85
112
|
}
|
|
86
|
-
async
|
|
87
|
-
const resolvedEntry = this.resolvePackageEntry(specifier);
|
|
88
|
-
const fileName = `${sanitizeSpecifierForFileName(specifier)}.${hashVendorSpecifier(specifier)}.js`;
|
|
89
|
-
const url = `/${RESOLVED_ASSETS_VENDORS_DIR}/${fileName}`;
|
|
113
|
+
async prebundle(record) {
|
|
90
114
|
const vendorPlugins = this.resolveVendorBundlePlugins ? await this.resolveVendorBundlePlugins() : [];
|
|
91
115
|
const result = await this.browserBundleService.bundle({
|
|
92
116
|
lane: 'build',
|
|
93
|
-
entrypoints: [
|
|
117
|
+
entrypoints: [record.entryPath],
|
|
94
118
|
outdir: path.join(this.appConfig.absolutePaths.workDir, 'vendor-memory'),
|
|
95
|
-
naming:
|
|
119
|
+
naming: path.basename(record.url),
|
|
96
120
|
writeToDisk: false,
|
|
97
121
|
minify: false,
|
|
98
122
|
externalPackages: false,
|
|
99
123
|
treeshaking: true,
|
|
100
124
|
splitting: false,
|
|
101
|
-
conditions: [...getVendorBundleConditions(specifier)],
|
|
125
|
+
conditions: [...getVendorBundleConditions(record.specifier)],
|
|
102
126
|
excludeAppBuildPlugins: resolveAppBuildPlugins(this.appConfig, 'browser').map((plugin) => plugin.name),
|
|
103
|
-
plugins: [...vendorPlugins],
|
|
127
|
+
plugins: [...vendorPlugins, this.createSharedPackagePlugin(record)],
|
|
104
128
|
});
|
|
105
|
-
assertBuildSucceeded(result, (details) => formatVendorPrebundleError(specifier, details));
|
|
129
|
+
assertBuildSucceeded(result, (details) => formatVendorPrebundleError(record.specifier, details));
|
|
106
130
|
const output = result.outputs.find((candidate) => typeof candidate.content === 'string');
|
|
107
131
|
if (!output || typeof output.content !== 'string') {
|
|
108
|
-
throw new Error(`[dev-transform] Vendor prebundle produced no in-memory JavaScript for ${specifier}`);
|
|
132
|
+
throw new Error(`[dev-transform] Vendor prebundle produced no in-memory JavaScript for ${record.specifier}`);
|
|
109
133
|
}
|
|
110
|
-
return { url, content: output.content };
|
|
134
|
+
return { url: record.url, content: output.content };
|
|
111
135
|
}
|
|
112
|
-
|
|
113
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Points the ESM imports of other packages inside one vendor bundle at those packages' vendor URLs.
|
|
138
|
+
*
|
|
139
|
+
* @remarks
|
|
140
|
+
* It runs after the vendor plugins, so a specifier the browser runtime manifest owns keeps the manifest's
|
|
141
|
+
* URL. Each dependency resolves from its importer, where a strict install places it.
|
|
142
|
+
*/
|
|
143
|
+
createSharedPackagePlugin(record) {
|
|
144
|
+
return {
|
|
145
|
+
name: 'ecopages-dev-vendor-shared-packages',
|
|
146
|
+
environments: ['browser'],
|
|
147
|
+
setup: (build) => {
|
|
148
|
+
build.onResolve({ filter: /.*/u }, (args) => {
|
|
149
|
+
if (!args.importer || args.namespace)
|
|
150
|
+
return undefined;
|
|
151
|
+
if (args.kind !== 'import-statement' && args.kind !== 'dynamic-import')
|
|
152
|
+
return undefined;
|
|
153
|
+
if (!isBarePackageImportSpecifier(args.path))
|
|
154
|
+
return undefined;
|
|
155
|
+
const dependency = resolveBarePackageBrowserEntry(this.appConfig.rootDir, args.path, path.dirname(args.importer));
|
|
156
|
+
if (!dependency || dependency.path === record.entryPath)
|
|
157
|
+
return undefined;
|
|
158
|
+
return { path: this.ensureVendor(args.path, dependency.path).url, external: true };
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
resolvePackageEntry(specifier, fromDirectory) {
|
|
164
|
+
const resolved = resolveBarePackageBrowserEntry(this.appConfig.rootDir, specifier, fromDirectory);
|
|
114
165
|
if (!resolved) {
|
|
115
166
|
throw new Error(`[dev-transform] Unable to resolve bare import "${specifier}" for vendor prebundle`);
|
|
116
167
|
}
|
|
117
|
-
return
|
|
168
|
+
return resolved.path;
|
|
118
169
|
}
|
|
119
170
|
}
|
|
120
171
|
function formatVendorPrebundleError(specifier, details) {
|
|
@@ -130,9 +181,6 @@ function formatVendorPrebundleError(specifier, details) {
|
|
|
130
181
|
function sanitizeSpecifierForFileName(specifier) {
|
|
131
182
|
return specifier.replaceAll(/^@/gu, '').replaceAll(/[/:@]/gu, '-');
|
|
132
183
|
}
|
|
133
|
-
function hashVendorSpecifier(specifier) {
|
|
134
|
-
return contentHash(specifier, 8);
|
|
135
|
-
}
|
|
136
184
|
/**
|
|
137
185
|
* Whether an `If-None-Match` header matches `etag` under the weak comparison of
|
|
138
186
|
* RFC 9110: any listed tag equal to it once `W/` is stripped, or `*`.
|
|
@@ -22,6 +22,15 @@ export declare class HttpError extends Error {
|
|
|
22
22
|
* Prefer this over `instanceof` when catching errors from app page bundles.
|
|
23
23
|
*/
|
|
24
24
|
static isHttpError(error: unknown): error is HttpError;
|
|
25
|
+
/**
|
|
26
|
+
* Answers with an error's status and JSON body, whichever `HttpError` class threw it.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* An error that passed {@link HttpError.isHttpError} may come from an app bundle's own copy of
|
|
30
|
+
* this class, or be a duck-typed object without `toResponse()`, so the response is rebuilt from
|
|
31
|
+
* its fields.
|
|
32
|
+
*/
|
|
33
|
+
static responseFor(error: HttpError): Response;
|
|
25
34
|
/**
|
|
26
35
|
* Serialize error to JSON for API responses.
|
|
27
36
|
*/
|