@ecopages/core 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +14 -4
- package/src/adapters/node/create-app.d.ts +5 -5
- package/src/adapters/node/create-app.js +1 -1
- package/src/adapters/node/server-adapter.d.ts +1 -0
- package/src/adapters/node/server-adapter.js +4 -1
- package/src/adapters/shared/hmr/hmr-manager.d.ts +2 -0
- package/src/adapters/shared/hmr/hmr-manager.js +8 -4
- package/src/adapters/shared/http/api-request-pipeline.d.ts +16 -3
- package/src/adapters/shared/http/api-request-pipeline.js +23 -16
- package/src/adapters/shared/http/define-api-handler.d.ts +8 -8
- package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
- package/src/adapters/shared/http/file-route-middleware-pipeline.d.ts +10 -11
- package/src/adapters/shared/http/file-route-middleware-pipeline.js +5 -6
- package/src/adapters/shared/http/fs-server-response-matcher.js +12 -4
- package/src/adapters/shared/http/run-middleware-chain.d.ts +29 -2
- package/src/adapters/shared/http/run-middleware-chain.js +108 -10
- package/src/adapters/shared/runtime/render-context.d.ts +2 -0
- package/src/adapters/shared/runtime/render-context.js +6 -21
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +2 -2
- package/src/adapters/shared/runtime/server-request-pipeline.js +4 -3
- package/src/adapters/shared/runtime/server-static-builder.js +4 -1
- package/src/adapters/shared/runtime/unattached-scripts.d.ts +17 -0
- package/src/adapters/shared/runtime/unattached-scripts.js +57 -0
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +3 -2
- package/src/adapters/shared/ws/ws-pattern-matcher.d.ts +14 -1
- package/src/adapters/shared/ws/ws-pattern-matcher.js +14 -13
- package/src/assets/app-browser-client-build.js +3 -0
- package/src/assets/asset-processing-service/asset-processing.service.d.ts +9 -0
- package/src/assets/asset-processing-service/asset-processing.service.js +19 -0
- package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +16 -2
- package/src/assets/asset-processing-service/processed-asset-ledger.js +31 -3
- package/src/build/build-graph.d.ts +19 -2
- package/src/build/build-graph.js +19 -18
- package/src/build/cache/pages-unified-graph-build.d.ts +4 -6
- package/src/build/cache/pages-unified-graph-build.js +14 -51
- package/src/build/cache/server-module-entries.d.ts +5 -9
- package/src/build/cache/server-module-entries.js +5 -58
- package/src/build/contracts/build-contracts.d.ts +15 -0
- package/src/build/contracts.d.ts +1 -1
- package/src/build/contracts.js +1 -1
- package/src/build/production-asset-ledger.d.ts +1 -1
- package/src/build/production-asset-ledger.js +4 -2
- package/src/build/rolldown/file-role-grammar-plugin.d.ts +11 -0
- package/src/build/rolldown/file-role-grammar-plugin.js +32 -0
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +11 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +79 -10
- package/src/build/rolldown/ssr-script-entries-plugin.d.ts +31 -0
- package/src/build/rolldown/ssr-script-entries-plugin.js +104 -0
- package/src/build/runtime/build-request-policy.js +4 -1
- package/src/build/server/server-modules-manifest.d.ts +6 -1
- package/src/build/server/server-modules-manifest.js +10 -1
- package/src/build/server/view-reference.d.ts +9 -0
- package/src/build/server/view-reference.js +11 -0
- package/src/build.d.ts +3 -1
- package/src/build.js +3 -1
- package/src/cli.d.ts +14 -0
- package/src/cli.js +14 -0
- package/src/config/assembly/app-runtime.d.ts +13 -0
- package/src/config/assembly/app-runtime.js +2 -0
- package/src/config/assembly/finalize-config.js +13 -8
- package/src/config/internal-types.d.ts +0 -12
- package/src/config/resolve-eco-config-path.d.ts +2 -0
- package/src/config/resolve-eco-config-path.js +2 -1
- package/src/config/server-config-bundle.d.ts +0 -1
- package/src/config/server-config-bundle.js +1 -1
- package/src/config/user-config-types.d.ts +0 -12
- package/src/declarations.d.ts +2 -0
- package/src/dev/invalidation/development-invalidation.service.d.ts +0 -2
- package/src/dev/invalidation/development-invalidation.service.js +1 -11
- package/src/dev/transform-server/dev-transform-vendor-registry.js +33 -19
- package/src/eco/discovered-dependencies.d.ts +5 -0
- package/src/eco/discovered-dependencies.js +9 -0
- package/src/eco/eco.browser.js +6 -26
- package/src/eco/eco.js +24 -16
- package/src/eco/migration-docs.d.ts +7 -0
- package/src/eco/migration-docs.js +7 -0
- package/src/eco/page-data-hooks.d.ts +27 -0
- package/src/eco/page-data-hooks.js +64 -0
- package/src/eco/page-layout-normalization.d.ts +2 -2
- package/src/hmr/client/hmr-runtime.js +1 -1
- package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -2
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +2 -1
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +4 -3
- package/src/html/html-rewriter.d.ts +9 -7
- package/src/html/html-rewriter.js +26 -41
- package/src/html/html-transformer.service.d.ts +2 -2
- package/src/html/html-transformer.service.js +21 -15
- package/src/html-pages/html-page-module-scripts.js +2 -1
- package/src/html-pages/html-pages.plugin.d.ts +1 -1
- package/src/html-pages/html-pages.plugin.js +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/integration.d.ts +2 -2
- package/src/integration.js +2 -2
- package/src/islands/island-host.d.ts +16 -5
- package/src/islands/island-host.js +8 -1
- package/src/middleware/create-middleware.d.ts +41 -0
- package/src/middleware/create-middleware.js +72 -0
- package/src/plugins/component-import-discovery.d.ts +14 -1
- package/src/plugins/component-import-discovery.js +36 -16
- package/src/plugins/eco-component-meta-plugin.d.ts +38 -0
- package/src/plugins/eco-component-meta-plugin.js +208 -44
- package/src/plugins/ecopages-virtual-imports.d.ts +15 -0
- package/src/plugins/ecopages-virtual-imports.js +25 -0
- package/src/plugins/integration-plugin.d.ts +1 -1
- package/src/plugins/integration-plugin.js +1 -1
- package/src/plugins/tsconfig-import-resolver.d.ts +2 -0
- package/src/plugins/tsconfig-import-resolver.js +7 -5
- package/src/route-renderer/error-pages/error-page-renderer.js +32 -3
- package/src/route-renderer/explicit-view-render-preparation.d.ts +28 -3
- package/src/route-renderer/explicit-view-render-preparation.js +63 -11
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +15 -5
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +27 -15
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +24 -9
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +73 -50
- package/src/route-renderer/orchestration/integration-renderer.d.ts +42 -11
- package/src/route-renderer/orchestration/integration-renderer.js +83 -43
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.builder.js +0 -3
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +36 -11
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +74 -62
- package/src/route-renderer/page-declaration.d.ts +25 -0
- package/src/route-renderer/page-declaration.js +39 -0
- package/src/route-renderer/page-loading/component-declarations.d.ts +65 -0
- package/src/route-renderer/page-loading/component-declarations.js +77 -0
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -16
- package/src/route-renderer/page-loading/component-dependency-collection.js +36 -105
- package/src/route-renderer/page-loading/declared-asset-collection.d.ts +19 -14
- package/src/route-renderer/page-loading/declared-asset-collection.js +66 -67
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +18 -10
- package/src/route-renderer/page-loading/dependency-resolver.js +58 -99
- package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +19 -26
- package/src/route-renderer/page-loading/lazy-entry-collection.js +53 -64
- package/src/route-renderer/page-loading/module-declaration-aggregation.d.ts +17 -3
- package/src/route-renderer/page-loading/module-declaration-aggregation.js +14 -13
- package/src/route-renderer/page-loading/page-module-loader.d.ts +31 -12
- package/src/route-renderer/page-loading/page-module-loader.js +66 -35
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +14 -9
- package/src/router/server/pages-dir.d.ts +7 -0
- package/src/router/server/pages-dir.js +7 -0
- package/src/router/server/route-registry.d.ts +22 -10
- package/src/router/server/route-registry.js +54 -23
- package/src/router/server/segment-path-matcher.d.ts +29 -5
- package/src/router/server/segment-path-matcher.js +22 -19
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +2 -2
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +5 -5
- package/src/static-site-generator/static-site-generator.d.ts +17 -2
- package/src/static-site-generator/static-site-generator.js +52 -18
- package/src/types/contracts.d.ts +216 -160
- package/src/types/eco-api-types.d.ts +86 -51
- package/src/types/locals-brand.d.ts +9 -0
- package/src/types/locals-brand.js +9 -0
- package/src/types/middleware-types.d.ts +143 -0
- package/src/types/middleware-types.js +1 -0
- package/src/types/public-types.d.ts +3 -2
- package/src/utils/file-roles.d.ts +48 -0
- package/src/utils/file-roles.js +85 -0
- package/src/utils/node-builtin.d.ts +10 -0
- package/src/utils/node-builtin.js +13 -0
- package/src/watchers/project-watcher.js +2 -2
- package/src/build/contracts/server-only-specifier.d.ts +0 -8
- package/src/build/contracts/server-only-specifier.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.d.ts +0 -5
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.d.ts +0 -4
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.js +0 -30
- package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +0 -12
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +0 -100
- package/src/utils/endpoint-file-extensions.d.ts +0 -11
- package/src/utils/endpoint-file-extensions.js +0 -13
- package/src/utils/locals-utils.d.ts +0 -15
- package/src/utils/locals-utils.js +0 -34
package/src/build/build-graph.js
CHANGED
|
@@ -14,23 +14,24 @@ function tryRealpath(filePath) {
|
|
|
14
14
|
export function resolveBuildEntryPath(entry, root) {
|
|
15
15
|
return path.resolve(root, entry);
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Resolves every requested entry and its real paths once, for repeated {@link recordBuildEntryOutput} calls.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Real-path lookups touch the filesystem, so recording one build's chunks against freshly resolved entries
|
|
22
|
+
* would repeat them for every chunk and entry.
|
|
23
|
+
*/
|
|
24
|
+
export function resolveRequestedBuildEntries(entrypoints, root) {
|
|
18
25
|
const pairs = Array.isArray(entrypoints)
|
|
19
26
|
? entrypoints.map((entry) => [entry, entry])
|
|
20
27
|
: Object.entries(entrypoints);
|
|
21
|
-
return pairs.map(([name, entry]) =>
|
|
22
|
-
|
|
23
|
-
entry,
|
|
24
|
-
|
|
25
|
-
}));
|
|
28
|
+
return pairs.map(([name, entry]) => {
|
|
29
|
+
const resolved = resolveBuildEntryPath(entry, root);
|
|
30
|
+
return { name, entry, resolved, entryReal: tryRealpath(entry), resolvedReal: tryRealpath(resolved) };
|
|
31
|
+
});
|
|
26
32
|
}
|
|
27
|
-
function isSameBuildEntry(left, right) {
|
|
28
|
-
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
const leftReal = tryRealpath(left);
|
|
32
|
-
const rightReal = tryRealpath(right);
|
|
33
|
-
return Boolean(leftReal && rightReal && leftReal === rightReal);
|
|
33
|
+
function isSameBuildEntry(left, leftReal, right, rightReal) {
|
|
34
|
+
return left === right || Boolean(leftReal && rightReal && leftReal === rightReal);
|
|
34
35
|
}
|
|
35
36
|
/**
|
|
36
37
|
* Records every spelling a caller may use to look up one entry's output.
|
|
@@ -47,8 +48,9 @@ export function recordBuildEntryOutput(entryOutputs, outputPath, options) {
|
|
|
47
48
|
if (facadeReal) {
|
|
48
49
|
keys.add(facadeReal);
|
|
49
50
|
}
|
|
50
|
-
for (const requested of
|
|
51
|
-
const matchesFacade = isSameBuildEntry(facadeModuleId, requested.resolved
|
|
51
|
+
for (const requested of options.requestedEntries) {
|
|
52
|
+
const matchesFacade = isSameBuildEntry(facadeModuleId, facadeReal, requested.resolved, requested.resolvedReal) ||
|
|
53
|
+
isSameBuildEntry(facadeModuleId, facadeReal, requested.entry, requested.entryReal);
|
|
52
54
|
const matchesName = options.chunkName !== undefined && options.chunkName === requested.name;
|
|
53
55
|
if (!matchesFacade && !matchesName) {
|
|
54
56
|
continue;
|
|
@@ -56,9 +58,8 @@ export function recordBuildEntryOutput(entryOutputs, outputPath, options) {
|
|
|
56
58
|
keys.add(requested.entry);
|
|
57
59
|
keys.add(requested.resolved);
|
|
58
60
|
keys.add(requested.name);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
keys.add(requestedReal);
|
|
61
|
+
if (requested.resolvedReal) {
|
|
62
|
+
keys.add(requested.resolvedReal);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
for (const key of keys) {
|
|
@@ -28,12 +28,8 @@ export declare function importEmittedServerModule<T>(appConfig: EcoPagesAppConfi
|
|
|
28
28
|
* Emits every production server entry into `outdir` and writes `server-modules.json`.
|
|
29
29
|
*
|
|
30
30
|
* @remarks
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* before their `setup()`. A discovered script already bundled into the first
|
|
34
|
-
* emit maps to that output. Otherwise a second emit adds the scripts; preserved
|
|
35
|
-
* modules keep their output path across both emits, so a module imported after
|
|
36
|
-
* the first emit is not evaluated again from a second copy.
|
|
31
|
+
* The `ssr: true` scripts that declarations list are entries of the same build (see
|
|
32
|
+
* `createSsrScriptEntriesPlugin`), so every module is bundled once and none is evaluated from two copies.
|
|
37
33
|
*/
|
|
38
34
|
export declare function emitProductionServerModules(options: {
|
|
39
35
|
appConfig: EcoPagesAppConfig;
|
|
@@ -41,6 +37,8 @@ export declare function emitProductionServerModules(options: {
|
|
|
41
37
|
staticRoutes?: readonly StaticRoute[];
|
|
42
38
|
errorPageLoaders?: ErrorPageLoaders;
|
|
43
39
|
outdir?: string;
|
|
40
|
+
/** Receives the project and package source files the server build bundled, after it succeeds. */
|
|
41
|
+
onServerSources?: (sources: readonly string[]) => void | Promise<void>;
|
|
44
42
|
}): Promise<ProductionServerModulesManifest>;
|
|
45
43
|
/**
|
|
46
44
|
* Imports the emitted module for `filePath` from the production server-modules map.
|
|
@@ -20,7 +20,7 @@ import { toRootRelativePath } from '../../utils/root-relative-path.js';
|
|
|
20
20
|
import { loadProductionServerModules, writeProductionServerModulesManifest, } from '../server/server-modules-manifest.js';
|
|
21
21
|
import { getServerBundleOutputPaths } from '../server-bundle-deploy-manifest.js';
|
|
22
22
|
import { ensureProductionBuildId } from '../production-build-id.js';
|
|
23
|
-
import { collectServerModuleEntries,
|
|
23
|
+
import { collectServerModuleEntries, isRolldownServerModuleEntry, } from './server-module-entries.js';
|
|
24
24
|
/**
|
|
25
25
|
* True when a production build should emit the server-modules map.
|
|
26
26
|
*
|
|
@@ -93,7 +93,7 @@ export async function importEmittedServerModule(appConfig, filePath, outputPath)
|
|
|
93
93
|
}
|
|
94
94
|
async function emitRolldownServerModules(appConfig, entryPaths, outdir) {
|
|
95
95
|
if (entryPaths.length === 0) {
|
|
96
|
-
return { modules: {},
|
|
96
|
+
return { modules: {}, sources: [] };
|
|
97
97
|
}
|
|
98
98
|
const entryRecord = {};
|
|
99
99
|
for (const entryPath of entryPaths) {
|
|
@@ -107,6 +107,7 @@ async function emitRolldownServerModules(appConfig, entryPaths, outdir) {
|
|
|
107
107
|
preserveModules: true,
|
|
108
108
|
preserveModulesRoot: appConfig.rootDir,
|
|
109
109
|
naming: '[name]-[hash].[ext]',
|
|
110
|
+
ssrScriptEntries: true,
|
|
110
111
|
});
|
|
111
112
|
const buildResult = await buildOrThrow(appConfig, buildOptions, 'Pages unified graph build failed').finally(() => appLogger.debugTimeEnd('pagesUnifiedGraphBuild'));
|
|
112
113
|
const modules = {};
|
|
@@ -117,27 +118,13 @@ async function emitRolldownServerModules(appConfig, entryPaths, outdir) {
|
|
|
117
118
|
}
|
|
118
119
|
modules[toRootRelativePath(appConfig.rootDir, entryPath)] = toRootRelativePath(outdir, compiledOutput);
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const resolvedSource = path.resolve(sourcePath);
|
|
124
|
-
for (const [outputPath, chunk] of Object.entries(outputGraph)) {
|
|
125
|
-
if (chunk.modules.includes(resolvedSource)) {
|
|
126
|
-
return outputPath;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
|
-
async function importEmittedModules(manifest, sourceKeys) {
|
|
132
|
-
const modules = [];
|
|
133
|
-
for (const sourceKey of sourceKeys) {
|
|
134
|
-
const relativePath = manifest.modules[sourceKey];
|
|
135
|
-
if (!relativePath) {
|
|
136
|
-
continue;
|
|
121
|
+
for (const [outputPath, chunk] of Object.entries(buildResult.outputGraph)) {
|
|
122
|
+
if (chunk.isEntry && chunk.facadeModuleId) {
|
|
123
|
+
modules[toRootRelativePath(appConfig.rootDir, chunk.facadeModuleId)] ??= toRootRelativePath(outdir, outputPath);
|
|
137
124
|
}
|
|
138
|
-
modules.push(await import(/* @vite-ignore */ path.toFileUrl(path.join(manifest.outdir, relativePath)).href));
|
|
139
125
|
}
|
|
140
|
-
|
|
126
|
+
const sources = [...new Set(Object.values(buildResult.dependencyGraph.entrypoints).flat())];
|
|
127
|
+
return { modules, sources };
|
|
141
128
|
}
|
|
142
129
|
function assignProductionServerModules(appConfig, manifest) {
|
|
143
130
|
const runtime = requireAppRuntime(appConfig);
|
|
@@ -147,12 +134,8 @@ function assignProductionServerModules(appConfig, manifest) {
|
|
|
147
134
|
* Emits every production server entry into `outdir` and writes `server-modules.json`.
|
|
148
135
|
*
|
|
149
136
|
* @remarks
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* before their `setup()`. A discovered script already bundled into the first
|
|
153
|
-
* emit maps to that output. Otherwise a second emit adds the scripts; preserved
|
|
154
|
-
* modules keep their output path across both emits, so a module imported after
|
|
155
|
-
* the first emit is not evaluated again from a second copy.
|
|
137
|
+
* The `ssr: true` scripts that declarations list are entries of the same build (see
|
|
138
|
+
* `createSsrScriptEntriesPlugin`), so every module is bundled once and none is evaluated from two copies.
|
|
156
139
|
*/
|
|
157
140
|
export async function emitProductionServerModules(options) {
|
|
158
141
|
const appConfig = options.appConfig;
|
|
@@ -160,7 +143,7 @@ export async function emitProductionServerModules(options) {
|
|
|
160
143
|
await setupAppRuntimeIntegrations({ appConfig });
|
|
161
144
|
const outdir = path.resolve(options.outdir ?? getServerBundleOutputPaths(appConfig).serverOutdir);
|
|
162
145
|
fileSystem.ensureDir(outdir);
|
|
163
|
-
const collected =
|
|
146
|
+
const collected = collectServerModuleEntries({
|
|
164
147
|
appConfig,
|
|
165
148
|
router: options.router,
|
|
166
149
|
staticRoutes: options.staticRoutes,
|
|
@@ -168,38 +151,18 @@ export async function emitProductionServerModules(options) {
|
|
|
168
151
|
});
|
|
169
152
|
const rolldownEntries = collected.filter((entryPath) => isRolldownServerModuleEntry(entryPath, appConfig));
|
|
170
153
|
const htmlEntries = collected.filter((entryPath) => !isRolldownServerModuleEntry(entryPath, appConfig));
|
|
171
|
-
const modules =
|
|
172
|
-
|
|
173
|
-
Object.assign(modules, initialEmit.modules);
|
|
154
|
+
const { modules, sources } = await emitRolldownServerModules(appConfig, uniqueEntryPaths(rolldownEntries), outdir);
|
|
155
|
+
await options.onServerSources?.(sources);
|
|
174
156
|
for (const htmlEntry of uniqueEntryPaths(htmlEntries)) {
|
|
175
157
|
const emitted = await emitCompiledPageModule(appConfig, htmlEntry, outdir);
|
|
176
158
|
modules[emitted.sourceKey] = emitted.relativePath;
|
|
177
159
|
}
|
|
178
|
-
|
|
160
|
+
const manifest = {
|
|
179
161
|
outdir,
|
|
180
162
|
buildId: ensureProductionBuildId(appConfig),
|
|
181
163
|
modules,
|
|
182
164
|
};
|
|
183
165
|
assignProductionServerModules(appConfig, manifest);
|
|
184
|
-
const discoveredScripts = collectSsrScriptPaths(await importEmittedModules(manifest, rolldownEntries.map((entryPath) => toRootRelativePath(appConfig.rootDir, entryPath))), appConfig.rootDir).filter((scriptPath) => fileSystem.exists(scriptPath) && !(toRootRelativePath(appConfig.rootDir, scriptPath) in modules));
|
|
185
|
-
if (discoveredScripts.length > 0) {
|
|
186
|
-
const scriptsToEmit = [];
|
|
187
|
-
for (const scriptPath of discoveredScripts) {
|
|
188
|
-
const existingOutput = findEmittedModulePath(initialEmit.outputGraph, scriptPath);
|
|
189
|
-
if (existingOutput) {
|
|
190
|
-
modules[toRootRelativePath(appConfig.rootDir, scriptPath)] = toRootRelativePath(outdir, existingOutput);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
scriptsToEmit.push(scriptPath);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (scriptsToEmit.length > 0) {
|
|
197
|
-
const emittedModules = await emitRolldownServerModules(appConfig, uniqueEntryPaths([...rolldownEntries, ...scriptsToEmit]), outdir);
|
|
198
|
-
Object.assign(modules, emittedModules.modules);
|
|
199
|
-
}
|
|
200
|
-
manifest = { outdir, buildId: ensureProductionBuildId(appConfig), modules };
|
|
201
|
-
assignProductionServerModules(appConfig, manifest);
|
|
202
|
-
}
|
|
203
166
|
writeProductionServerModulesManifest(manifest);
|
|
204
167
|
appLogger.debug(`Emitted ${Object.keys(modules).length} production server modules`);
|
|
205
168
|
return manifest;
|
|
@@ -14,22 +14,18 @@ export type ServerModuleEntryRouteSource = {
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function isRolldownServerModuleEntry(filePath: string, appConfig: EcoPagesAppConfig): boolean;
|
|
16
16
|
/**
|
|
17
|
-
* Collects every production server entry except `ssr: true` scripts, which
|
|
18
|
-
*
|
|
17
|
+
* Collects every production server entry except `ssr: true` scripts, which the server build
|
|
18
|
+
* adds from each declaration (`createSsrScriptEntriesPlugin`).
|
|
19
19
|
*
|
|
20
20
|
* @remarks
|
|
21
21
|
* Processor `listProductionServerModuleEntries()` files, such as generated content
|
|
22
22
|
* collection modules, join the same map so production start can import them without
|
|
23
|
-
* calling Processor `setup()`.
|
|
24
|
-
* `ctx.renderPartial`) are recorded by the imported-view plugin during that bundle.
|
|
23
|
+
* calling Processor `setup()`. A Layout is not an entry: the Page that passes it as `eco.page({ layout })` uses
|
|
24
|
+
* it, so it is bundled once with that Page and keeps its exports. Views imported into the server entry (`ctx.render`, `ctx.renderPartial`) are recorded by the imported-view plugin during that bundle.
|
|
25
25
|
*/
|
|
26
26
|
export declare function collectServerModuleEntries(options: {
|
|
27
27
|
appConfig: EcoPagesAppConfig;
|
|
28
28
|
router: ServerModuleEntryRouteSource;
|
|
29
29
|
staticRoutes?: readonly StaticRoute[];
|
|
30
30
|
errorPageLoaders?: ErrorPageLoaders;
|
|
31
|
-
}):
|
|
32
|
-
/**
|
|
33
|
-
* Walks compiled Page, Layout, and view modules for `ssr: true` script paths.
|
|
34
|
-
*/
|
|
35
|
-
export declare function collectSsrScriptPaths(modules: readonly unknown[], rootDir: string): string[];
|
|
31
|
+
}): string[];
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { path } from '@ecopages/file-system/path';
|
|
2
2
|
import { fileSystem } from '@ecopages/file-system';
|
|
3
|
-
import { getComponentIdentity } from '../../eco/component-identity.js';
|
|
4
|
-
import { isEcoDeclaredComponent } from '../../eco/eco-declared-component.js';
|
|
5
3
|
import { findIntegrationForFile } from '../../plugins/find-integration-for-file.js';
|
|
6
4
|
import { getImportedViewPaths } from '../server/imported-view-plugin.js';
|
|
7
5
|
/**
|
|
@@ -23,34 +21,23 @@ function addExistingPath(entries, filePath) {
|
|
|
23
21
|
function addViewLoader(entries, loader) {
|
|
24
22
|
addExistingPath(entries, loader?.filePath);
|
|
25
23
|
}
|
|
26
|
-
async function collectLayoutFiles(appConfig, entries) {
|
|
27
|
-
const layoutsDir = appConfig.absolutePaths.layoutsDir;
|
|
28
|
-
if (!layoutsDir || !fileSystem.exists(layoutsDir)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const files = await fileSystem.glob(appConfig.templatesExt.map((extension) => `**/*${extension}`), { cwd: layoutsDir });
|
|
32
|
-
for (const file of files) {
|
|
33
|
-
entries.add(path.resolve(layoutsDir, file));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
24
|
/**
|
|
37
|
-
* Collects every production server entry except `ssr: true` scripts, which
|
|
38
|
-
*
|
|
25
|
+
* Collects every production server entry except `ssr: true` scripts, which the server build
|
|
26
|
+
* adds from each declaration (`createSsrScriptEntriesPlugin`).
|
|
39
27
|
*
|
|
40
28
|
* @remarks
|
|
41
29
|
* Processor `listProductionServerModuleEntries()` files, such as generated content
|
|
42
30
|
* collection modules, join the same map so production start can import them without
|
|
43
|
-
* calling Processor `setup()`.
|
|
44
|
-
* `ctx.renderPartial`) are recorded by the imported-view plugin during that bundle.
|
|
31
|
+
* calling Processor `setup()`. A Layout is not an entry: the Page that passes it as `eco.page({ layout })` uses
|
|
32
|
+
* it, so it is bundled once with that Page and keeps its exports. Views imported into the server entry (`ctx.render`, `ctx.renderPartial`) are recorded by the imported-view plugin during that bundle.
|
|
45
33
|
*/
|
|
46
|
-
export
|
|
34
|
+
export function collectServerModuleEntries(options) {
|
|
47
35
|
const entries = new Set();
|
|
48
36
|
const { appConfig } = options;
|
|
49
37
|
for (const route of options.router.templateRoutes) {
|
|
50
38
|
addExistingPath(entries, route.filePath);
|
|
51
39
|
}
|
|
52
40
|
addExistingPath(entries, appConfig.absolutePaths.htmlTemplatePath);
|
|
53
|
-
await collectLayoutFiles(appConfig, entries);
|
|
54
41
|
for (const route of options.staticRoutes ?? []) {
|
|
55
42
|
addViewLoader(entries, route.loader);
|
|
56
43
|
}
|
|
@@ -67,43 +54,3 @@ export async function collectServerModuleEntries(options) {
|
|
|
67
54
|
}
|
|
68
55
|
return [...entries];
|
|
69
56
|
}
|
|
70
|
-
function addSsrScripts(component, rootDir, scripts) {
|
|
71
|
-
const identity = getComponentIdentity(component);
|
|
72
|
-
const ownerDir = identity?.file ? path.dirname(path.resolve(rootDir, identity.file)) : undefined;
|
|
73
|
-
if (!ownerDir) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
for (const script of component.config?.dependencies?.scripts ?? []) {
|
|
77
|
-
if (typeof script === 'object' && script.ssr && script.src) {
|
|
78
|
-
scripts.add(path.resolve(ownerDir, script.src));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function collectSsrScriptsFromComponent(component, rootDir, seen, scripts) {
|
|
83
|
-
if (!component || seen.has(component) || !isEcoDeclaredComponent(component)) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
seen.add(component);
|
|
87
|
-
const ecoComponent = component;
|
|
88
|
-
addSsrScripts(ecoComponent, rootDir, scripts);
|
|
89
|
-
for (const related of ecoComponent.config?.layouts ?? []) {
|
|
90
|
-
collectSsrScriptsFromComponent(related, rootDir, seen, scripts);
|
|
91
|
-
}
|
|
92
|
-
for (const related of ecoComponent.config?.dependencies?.components ?? []) {
|
|
93
|
-
collectSsrScriptsFromComponent(related, rootDir, seen, scripts);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Walks compiled Page, Layout, and view modules for `ssr: true` script paths.
|
|
98
|
-
*/
|
|
99
|
-
export function collectSsrScriptPaths(modules, rootDir) {
|
|
100
|
-
const scripts = new Set();
|
|
101
|
-
const seen = new Set();
|
|
102
|
-
for (const module of modules) {
|
|
103
|
-
if (!module || typeof module !== 'object') {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
collectSsrScriptsFromComponent(module.default, rootDir, seen, scripts);
|
|
107
|
-
}
|
|
108
|
-
return [...scripts];
|
|
109
|
-
}
|
|
@@ -153,6 +153,21 @@ export interface BuildOptions {
|
|
|
153
153
|
* The dev transform server sets `false`: it compiles one module at a time and points the URL at its own module URL.
|
|
154
154
|
*/
|
|
155
155
|
workerEntries?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Builds each `ssr: true` script a declaration lists as an entry of the same build. Server builds only; defaults to `false`.
|
|
158
|
+
*/
|
|
159
|
+
ssrScriptEntries?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Gives each installed package with at least `minSize` bytes of source in the build a chunk of its own, named
|
|
162
|
+
* `vendor-<package>-[hash]`. Browser builds with code splitting only; off when unset.
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
* A package's chunk holds that package's modules and their own dependencies, so its name and bytes do not change when app code does. A
|
|
166
|
+
* smaller package stays with whatever shares it, as the bundler would place it.
|
|
167
|
+
*/
|
|
168
|
+
packageChunks?: {
|
|
169
|
+
minSize: number;
|
|
170
|
+
};
|
|
156
171
|
}
|
|
157
172
|
/**
|
|
158
173
|
* The stylesheets of one build request and the compiler of the module a binding import of one receives.
|
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
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
|
-
export { isServerOnlyModuleSpecifier } from '
|
|
4
|
+
export { isServerOnlyModuleSpecifier } from '../utils/file-roles.js';
|
package/src/build/contracts.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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
|
-
export { isServerOnlyModuleSpecifier } from '
|
|
2
|
+
export { isServerOnlyModuleSpecifier } from '../utils/file-roles.js';
|
|
@@ -9,7 +9,7 @@ export declare const PRODUCTION_ASSET_LEDGER_FILENAME = "processed-assets.json";
|
|
|
9
9
|
* root-relative source, so the file serves a build moved to another folder or platform.
|
|
10
10
|
*/
|
|
11
11
|
export type ProductionAssetLedgerFile = SerializedProcessedAssetLedger & {
|
|
12
|
-
version:
|
|
12
|
+
version: 5;
|
|
13
13
|
buildId: string;
|
|
14
14
|
htmlPageModuleScriptUrls: Record<string, string>;
|
|
15
15
|
};
|
|
@@ -22,7 +22,7 @@ function getLedgerPath(appConfig) {
|
|
|
22
22
|
export function writeProductionAssetLedger(appConfig, htmlPageModuleScriptUrls) {
|
|
23
23
|
const runtime = requireAppRuntime(appConfig);
|
|
24
24
|
const payload = {
|
|
25
|
-
version:
|
|
25
|
+
version: 5,
|
|
26
26
|
buildId: ensureProductionBuildId(appConfig),
|
|
27
27
|
...runtime.processedAssets.serialize(),
|
|
28
28
|
htmlPageModuleScriptUrls: Object.fromEntries([...htmlPageModuleScriptUrls]
|
|
@@ -45,11 +45,13 @@ function isStringArray(value) {
|
|
|
45
45
|
}
|
|
46
46
|
function isLedgerFile(value) {
|
|
47
47
|
return (isRecord(value) &&
|
|
48
|
-
value.version ===
|
|
48
|
+
value.version === 5 &&
|
|
49
49
|
typeof value.buildId === 'string' &&
|
|
50
50
|
Array.isArray(value.entries) &&
|
|
51
51
|
value.entries.every((entry) => isRecord(entry) && typeof entry.key === 'string' && isRecord(entry.asset)) &&
|
|
52
52
|
(value.browserOutputs === undefined || isStringArray(value.browserOutputs)) &&
|
|
53
|
+
(value.shells === undefined ||
|
|
54
|
+
(isRecord(value.shells) && Object.values(value.shells).every((assets) => Array.isArray(assets)))) &&
|
|
53
55
|
isRecord(value.htmlPageModuleScriptUrls) &&
|
|
54
56
|
Object.values(value.htmlPageModuleScriptUrls).every((url) => typeof url === 'string'));
|
|
55
57
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RolldownPlugin } from 'rolldown';
|
|
2
|
+
/**
|
|
3
|
+
* Fails a build that compiles an app module whose name puts a role segment anywhere but directly before a script
|
|
4
|
+
* extension, such as `card.server.kita.tsx`.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Role suffixes follow `<name>.<role>.<ts|tsx|js|jsx>`. The router enforces that for route files; this plugin
|
|
8
|
+
* covers every other module the build compiles, wherever it lives, so a misplaced segment never reads two ways.
|
|
9
|
+
* Modules under `node_modules` are installed packages and are not checked.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createFileRoleGrammarPlugin(): RolldownPlugin;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describeRoleForms, findMisplacedRole } from '../../utils/file-roles.js';
|
|
2
|
+
import { fromRolldownModuleId } from './rolldown-module-id.js';
|
|
3
|
+
const ROLE_FILE_PATTERN = /\.(?:api|server|script)\.[^/\\]*\.(?:[cm]?[jt]sx?)$/u;
|
|
4
|
+
/**
|
|
5
|
+
* Fails a build that compiles an app module whose name puts a role segment anywhere but directly before a script
|
|
6
|
+
* extension, such as `card.server.kita.tsx`.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Role suffixes follow `<name>.<role>.<ts|tsx|js|jsx>`. The router enforces that for route files; this plugin
|
|
10
|
+
* covers every other module the build compiles, wherever it lives, so a misplaced segment never reads two ways.
|
|
11
|
+
* Modules under `node_modules` are installed packages and are not checked.
|
|
12
|
+
*/
|
|
13
|
+
export function createFileRoleGrammarPlugin() {
|
|
14
|
+
return {
|
|
15
|
+
name: 'ecopages:file-role-grammar',
|
|
16
|
+
transform: {
|
|
17
|
+
filter: { id: ROLE_FILE_PATTERN },
|
|
18
|
+
handler(_code, id) {
|
|
19
|
+
if (id.startsWith('\0'))
|
|
20
|
+
return null;
|
|
21
|
+
const file = fromRolldownModuleId(id);
|
|
22
|
+
if (file.split('/').includes('node_modules'))
|
|
23
|
+
return null;
|
|
24
|
+
const misplaced = findMisplacedRole(file);
|
|
25
|
+
if (misplaced) {
|
|
26
|
+
this.error(`${file}: the "${misplaced}" role segment must come directly before a script extension, as in ${describeRoleForms()}. Rename the file.`);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -69,6 +69,9 @@ export declare function createInstalledPackageExternalPlugin(contextRoot: string
|
|
|
69
69
|
* bare specifiers. This plugin fails the build instead so server-only graphs
|
|
70
70
|
* cannot reach the browser as silent CORS errors.
|
|
71
71
|
*
|
|
72
|
+
* A built-in is recorded where it resolves and reported at `buildEnd`, because the importer chain through
|
|
73
|
+
* `node_modules` to the app module is only known once every module is parsed.
|
|
74
|
+
*
|
|
72
75
|
* The `.server` check reads the resolved ids a module imports once it is parsed,
|
|
73
76
|
* not the specifiers as written, so an alias such as a `package.json` `imports`
|
|
74
77
|
* entry or a tsconfig path is rejected like a relative import. Rolldown has no
|
|
@@ -97,6 +100,14 @@ export interface ResolvedRolldownOptions {
|
|
|
97
100
|
inputOptions: InputOptions;
|
|
98
101
|
outputOptions: OutputOptions;
|
|
99
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Names the chunk of the installed package a module belongs to, or nothing for app code.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* The package is the one at the last `node_modules` segment, so a pnpm store path and a nested install both resolve to
|
|
108
|
+
* the package that owns the module.
|
|
109
|
+
*/
|
|
110
|
+
export declare function getInstalledPackageChunkName(moduleId: string): string | null;
|
|
100
111
|
/**
|
|
101
112
|
* Translates a {@link BuildOptions} into Rolldown's `InputOptions` and
|
|
102
113
|
* `OutputOptions`. Always sets `experimental.nativeMagicString: true`
|
|
@@ -10,18 +10,21 @@
|
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
12
12
|
import { createHash } from 'node:crypto';
|
|
13
|
-
import {
|
|
13
|
+
import { createRequire } from 'node:module';
|
|
14
14
|
import { path } from '@ecopages/file-system/path';
|
|
15
15
|
import { fileSystem } from '@ecopages/file-system';
|
|
16
16
|
import { stripVTControlCharacters } from 'node:util';
|
|
17
|
-
import { recordBuildEntryOutput, resolveBuildEntryPath } from '../build-graph.js';
|
|
17
|
+
import { recordBuildEntryOutput, resolveBuildEntryPath, resolveRequestedBuildEntries } from '../build-graph.js';
|
|
18
18
|
import { id as idFilter, include } from 'rolldown/filter';
|
|
19
19
|
import { escapeRegExp } from '../../utils/regex-escaping.js';
|
|
20
20
|
import { isPathInside } from '../../utils/path-containment.js';
|
|
21
21
|
import { isEcopagesEnvEnabled } from '../../env.js';
|
|
22
22
|
import { isBarePackageImportSpecifier } from '../../plugins/tsconfig-import-resolver.js';
|
|
23
23
|
import { toPackageRootSpecifier } from '../../plugins/package-specifier.js';
|
|
24
|
-
import { isServerOnlyModuleSpecifier } from '
|
|
24
|
+
import { isServerOnlyModuleSpecifier } from '../../utils/file-roles.js';
|
|
25
|
+
import { isNodeBuiltinSpecifier, nodeBuiltinSpecifiers } from '../../utils/node-builtin.js';
|
|
26
|
+
import { createFileRoleGrammarPlugin } from './file-role-grammar-plugin.js';
|
|
27
|
+
import { createSsrScriptEntriesPlugin } from './ssr-script-entries-plugin.js';
|
|
25
28
|
import { createWorkerEntriesPlugin } from './worker-entries-plugin.js';
|
|
26
29
|
import { createStylesheetModulePlugin } from './stylesheet-module-plugin.js';
|
|
27
30
|
import { appLogger } from '../../global/app-logger.js';
|
|
@@ -30,7 +33,6 @@ import { fromRolldownModuleId } from './rolldown-module-id.js';
|
|
|
30
33
|
import { createRolldownPluginBridge } from './rolldown-plugin-bridge.js';
|
|
31
34
|
import { isDeclaredAppPackageImport, isWorkspacePackageImport } from './app-package-declarations.js';
|
|
32
35
|
const coreSourceFile = path.fromFileUrl(import.meta.url);
|
|
33
|
-
const nodeBuiltinSpecifiers = new Set(builtinModules);
|
|
34
36
|
const MAX_FLATTENED_PRESERVED_MODULE_NAME_BYTES = 120;
|
|
35
37
|
const PRESERVED_MODULE_NAME_HASH_LENGTH = 16;
|
|
36
38
|
let corePackageNames;
|
|
@@ -269,8 +271,28 @@ export function createInstalledPackageExternalPlugin(contextRoot, outdir, report
|
|
|
269
271
|
},
|
|
270
272
|
};
|
|
271
273
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
+
/**
|
|
275
|
+
* Names the import chain from the nearest app module to `specifier`, as ` (imported from <app module> > <package module> > ...)`.
|
|
276
|
+
*
|
|
277
|
+
* @remarks
|
|
278
|
+
* A package's own modules are not what the author wrote: when a bare `import 'pg'` reaches a built-in, the useful
|
|
279
|
+
* answer is the app module that imported the package. The walk follows each module's first importer until it
|
|
280
|
+
* leaves `node_modules` or reaches an entry, so the chain is the first path the bundler found. Rolldown ids are
|
|
281
|
+
* native paths, so each is converted to forward slashes before the `node_modules` test and kept native for
|
|
282
|
+
* `getModuleInfo`.
|
|
283
|
+
*/
|
|
284
|
+
function describeImportChain(context, importer, specifier) {
|
|
285
|
+
const chain = [];
|
|
286
|
+
const seen = new Set();
|
|
287
|
+
for (let current = importer; current && !seen.has(current);) {
|
|
288
|
+
seen.add(current);
|
|
289
|
+
const id = fromRolldownModuleId(current);
|
|
290
|
+
chain.unshift(id);
|
|
291
|
+
if (!id.split('/').includes('node_modules'))
|
|
292
|
+
break;
|
|
293
|
+
current = context.getModuleInfo(current)?.importers[0];
|
|
294
|
+
}
|
|
295
|
+
return ` (imported from ${[...chain, specifier].join(' > ')})`;
|
|
274
296
|
}
|
|
275
297
|
const nodeBuiltinFilter = new RegExp(`^(?:node:.*|${[...nodeBuiltinSpecifiers].map((specifier) => escapeRegExp(specifier)).join('|')})$`);
|
|
276
298
|
/**
|
|
@@ -281,6 +303,9 @@ const nodeBuiltinFilter = new RegExp(`^(?:node:.*|${[...nodeBuiltinSpecifiers].m
|
|
|
281
303
|
* bare specifiers. This plugin fails the build instead so server-only graphs
|
|
282
304
|
* cannot reach the browser as silent CORS errors.
|
|
283
305
|
*
|
|
306
|
+
* A built-in is recorded where it resolves and reported at `buildEnd`, because the importer chain through
|
|
307
|
+
* `node_modules` to the app module is only known once every module is parsed.
|
|
308
|
+
*
|
|
284
309
|
* The `.server` check reads the resolved ids a module imports once it is parsed,
|
|
285
310
|
* not the specifiers as written, so an alias such as a `package.json` `imports`
|
|
286
311
|
* entry or a tsconfig path is rejected like a relative import. Rolldown has no
|
|
@@ -291,6 +316,7 @@ export function createBrowserServerOnlyGuardPlugin() {
|
|
|
291
316
|
const from = importer ? ` (imported from ${fromRolldownModuleId(importer)})` : '';
|
|
292
317
|
throw new Error(`[browser-build] server-only module "${fromRolldownModuleId(id)}" cannot be bundled for the browser${from}. Check the browser graph boundary for the importer.`);
|
|
293
318
|
};
|
|
319
|
+
const builtinImports = [];
|
|
294
320
|
return {
|
|
295
321
|
name: 'ecopages-browser-server-only-guard',
|
|
296
322
|
resolveId: {
|
|
@@ -299,10 +325,20 @@ export function createBrowserServerOnlyGuardPlugin() {
|
|
|
299
325
|
if (!isNodeBuiltinSpecifier(id)) {
|
|
300
326
|
return null;
|
|
301
327
|
}
|
|
302
|
-
|
|
303
|
-
|
|
328
|
+
builtinImports.push({ id, importer });
|
|
329
|
+
return { id, external: true };
|
|
304
330
|
},
|
|
305
331
|
},
|
|
332
|
+
buildStart() {
|
|
333
|
+
builtinImports.length = 0;
|
|
334
|
+
},
|
|
335
|
+
buildEnd() {
|
|
336
|
+
const first = builtinImports[0];
|
|
337
|
+
if (!first)
|
|
338
|
+
return;
|
|
339
|
+
const chain = first.importer ? describeImportChain(this, first.importer, first.id) : '';
|
|
340
|
+
throw new Error(`[browser-build] Node builtin "${first.id}" cannot be bundled for the browser${chain}. Keep server-only code in a ".server" module that only server-side hooks such as props import, or check package "browser" exports and the client-graph boundary.`);
|
|
341
|
+
},
|
|
306
342
|
moduleParsed(info) {
|
|
307
343
|
if (info.isEntry && isServerOnlyModuleSpecifier(info.id)) {
|
|
308
344
|
rejectServerOnly(info.id, undefined);
|
|
@@ -446,10 +482,12 @@ async function buildRolldownInputPlugins(options, contextRoot, outdir, rolldownP
|
|
|
446
482
|
createInstalledPackageExternalPlugin(contextRoot, outdir, options.reportPackagesOutsideRoot === true ? (options.runtimeOutdir ?? outdir) : undefined),
|
|
447
483
|
]
|
|
448
484
|
: []),
|
|
485
|
+
createFileRoleGrammarPlugin(),
|
|
449
486
|
...(rolldownPlatform === 'browser' ? [createBrowserServerOnlyGuardPlugin()] : []),
|
|
450
487
|
createStylesheetModulePlugin({ environment: options.environment, root: contextRoot }, options.stylesheets, watchFiles),
|
|
451
488
|
...appPlugins,
|
|
452
489
|
...(options.environment === 'browser' && options.workerEntries !== false ? [createWorkerEntriesPlugin()] : []),
|
|
490
|
+
...(options.ssrScriptEntries === true ? [createSsrScriptEntriesPlugin()] : []),
|
|
453
491
|
];
|
|
454
492
|
}
|
|
455
493
|
async function buildRolldownInputOptions(options, contextRoot, outdir, external, rolldownPlatform, watchFiles) {
|
|
@@ -539,6 +577,25 @@ function flattenPreservedModuleFileNames(pattern) {
|
|
|
539
577
|
function sanitizePreservedModuleName(name) {
|
|
540
578
|
return name.replace(/^(?:\.\.?\/)+/u, '').replaceAll(/[\0?*:]/gu, '_');
|
|
541
579
|
}
|
|
580
|
+
/**
|
|
581
|
+
* Names the chunk of the installed package a module belongs to, or nothing for app code.
|
|
582
|
+
*
|
|
583
|
+
* @remarks
|
|
584
|
+
* The package is the one at the last `node_modules` segment, so a pnpm store path and a nested install both resolve to
|
|
585
|
+
* the package that owns the module.
|
|
586
|
+
*/
|
|
587
|
+
export function getInstalledPackageChunkName(moduleId) {
|
|
588
|
+
const marker = 'node_modules/';
|
|
589
|
+
const normalized = moduleId.replaceAll('\\', '/');
|
|
590
|
+
const index = normalized.lastIndexOf(marker);
|
|
591
|
+
if (index === -1)
|
|
592
|
+
return null;
|
|
593
|
+
const [first, second] = normalized.slice(index + marker.length).split('/');
|
|
594
|
+
if (!first)
|
|
595
|
+
return null;
|
|
596
|
+
const packageName = first.startsWith('@') && second ? `${first.slice(1)}-${second}` : first;
|
|
597
|
+
return `vendor-${packageName}`;
|
|
598
|
+
}
|
|
542
599
|
function buildRolldownOutputOptions(options, outdir) {
|
|
543
600
|
const entryFileNames = resolveRolldownEntryFileNames(options);
|
|
544
601
|
return {
|
|
@@ -559,6 +616,18 @@ function buildRolldownOutputOptions(options, outdir) {
|
|
|
559
616
|
: {}),
|
|
560
617
|
sourcemap: mapRolldownSourcemap(options.sourcemap),
|
|
561
618
|
...(shouldDisableRolldownCodeSplitting(options) ? { codeSplitting: false } : {}),
|
|
619
|
+
...(options.packageChunks && options.splitting !== false
|
|
620
|
+
? {
|
|
621
|
+
codeSplitting: {
|
|
622
|
+
groups: [
|
|
623
|
+
{
|
|
624
|
+
name: getInstalledPackageChunkName,
|
|
625
|
+
minSize: options.packageChunks.minSize,
|
|
626
|
+
},
|
|
627
|
+
],
|
|
628
|
+
},
|
|
629
|
+
}
|
|
630
|
+
: {}),
|
|
562
631
|
};
|
|
563
632
|
}
|
|
564
633
|
/**
|
|
@@ -638,6 +707,7 @@ export function buildResultFromRolldownOutput(output, outdir, contextRoot, depen
|
|
|
638
707
|
},
|
|
639
708
|
]));
|
|
640
709
|
const entryOutputs = {};
|
|
710
|
+
const requestedEntries = resolveRequestedBuildEntries(entrypoints, contextRoot);
|
|
641
711
|
for (const chunk of chunks) {
|
|
642
712
|
if (!chunk.isEntry || !chunk.facadeModuleId) {
|
|
643
713
|
continue;
|
|
@@ -645,8 +715,7 @@ export function buildResultFromRolldownOutput(output, outdir, contextRoot, depen
|
|
|
645
715
|
recordBuildEntryOutput(entryOutputs, normalizeOutputPath(chunk.fileName, outdir), {
|
|
646
716
|
facadeModuleId: resolveBuildEntryPath(chunk.facadeModuleId, contextRoot),
|
|
647
717
|
chunkName: chunk.name,
|
|
648
|
-
|
|
649
|
-
root: contextRoot,
|
|
718
|
+
requestedEntries,
|
|
650
719
|
});
|
|
651
720
|
}
|
|
652
721
|
return {
|