@zenithbuild/cli 0.7.4 → 0.7.7
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 +5 -3
- package/dist/adapters/adapter-netlify.d.ts +1 -1
- package/dist/adapters/adapter-netlify.js +48 -14
- package/dist/adapters/adapter-static-export.d.ts +5 -0
- package/dist/adapters/adapter-static-export.js +115 -0
- package/dist/adapters/adapter-types.d.ts +3 -1
- package/dist/adapters/adapter-types.js +5 -2
- package/dist/adapters/adapter-vercel.d.ts +1 -1
- package/dist/adapters/adapter-vercel.js +67 -19
- package/dist/adapters/copy-hosted-page-runtime.d.ts +1 -0
- package/dist/adapters/copy-hosted-page-runtime.js +50 -0
- package/dist/adapters/resolve-adapter.js +4 -0
- package/dist/adapters/route-rules.d.ts +5 -0
- package/dist/adapters/route-rules.js +9 -0
- package/dist/adapters/validate-hosted-resource-routes.d.ts +1 -0
- package/dist/adapters/validate-hosted-resource-routes.js +13 -0
- package/dist/auth/route-auth.d.ts +6 -0
- package/dist/auth/route-auth.js +236 -0
- package/dist/build/compiler-runtime.d.ts +1 -1
- package/dist/build/compiler-runtime.js +8 -2
- package/dist/build/hoisted-code-transforms.d.ts +4 -1
- package/dist/build/hoisted-code-transforms.js +5 -3
- package/dist/build/page-ir-normalization.d.ts +1 -1
- package/dist/build/page-ir-normalization.js +33 -3
- package/dist/build/page-loop-state.js +1 -1
- package/dist/build/page-loop.js +46 -2
- package/dist/build/server-script.d.ts +2 -1
- package/dist/build/server-script.js +7 -3
- package/dist/build-output-manifest.d.ts +3 -2
- package/dist/build-output-manifest.js +3 -0
- package/dist/build.js +29 -17
- package/dist/dev-build-session/helpers.d.ts +29 -0
- package/dist/dev-build-session/helpers.js +223 -0
- package/dist/dev-build-session/session.d.ts +24 -0
- package/dist/dev-build-session/session.js +204 -0
- package/dist/dev-build-session/state.d.ts +37 -0
- package/dist/dev-build-session/state.js +17 -0
- package/dist/dev-build-session.d.ts +1 -24
- package/dist/dev-build-session.js +1 -434
- package/dist/dev-server/css-state.d.ts +7 -0
- package/dist/dev-server/css-state.js +92 -0
- package/dist/dev-server/not-found.d.ts +23 -0
- package/dist/dev-server/not-found.js +129 -0
- package/dist/dev-server/request-handler.d.ts +1 -0
- package/dist/dev-server/request-handler.js +376 -0
- package/dist/dev-server/route-check.d.ts +9 -0
- package/dist/dev-server/route-check.js +100 -0
- package/dist/dev-server/watcher.d.ts +5 -0
- package/dist/dev-server/watcher.js +216 -0
- package/dist/dev-server.js +136 -883
- package/dist/download-result.d.ts +14 -0
- package/dist/download-result.js +148 -0
- package/dist/images/payload.js +4 -0
- package/dist/images/service.d.ts +13 -1
- package/dist/images/service.js +45 -15
- package/dist/manifest.d.ts +15 -1
- package/dist/manifest.js +70 -6
- package/dist/preview/create-preview-server.d.ts +18 -0
- package/dist/preview/create-preview-server.js +71 -0
- package/dist/preview/manifest.d.ts +42 -0
- package/dist/preview/manifest.js +57 -0
- package/dist/preview/paths.d.ts +3 -0
- package/dist/preview/paths.js +38 -0
- package/dist/preview/payload.d.ts +6 -0
- package/dist/preview/payload.js +34 -0
- package/dist/preview/request-handler.d.ts +1 -0
- package/dist/preview/request-handler.js +300 -0
- package/dist/preview/server-runner.d.ts +49 -0
- package/dist/preview/server-runner.js +220 -0
- package/dist/preview/server-script-runner-template.d.ts +1 -0
- package/dist/preview/server-script-runner-template.js +425 -0
- package/dist/preview.d.ts +5 -104
- package/dist/preview.js +7 -993
- package/dist/request-body.d.ts +0 -1
- package/dist/request-body.js +0 -6
- package/dist/resource-manifest.d.ts +16 -0
- package/dist/resource-manifest.js +53 -0
- package/dist/resource-response.d.ts +49 -0
- package/dist/resource-response.js +160 -0
- package/dist/resource-route-module.d.ts +15 -0
- package/dist/resource-route-module.js +129 -0
- package/dist/route-check-support.js +1 -1
- package/dist/server-contract/constants.d.ts +5 -0
- package/dist/server-contract/constants.js +5 -0
- package/dist/server-contract/export-validation.d.ts +5 -0
- package/dist/server-contract/export-validation.js +59 -0
- package/dist/server-contract/json-serializable.d.ts +1 -0
- package/dist/server-contract/json-serializable.js +52 -0
- package/dist/server-contract/resolve.d.ts +15 -0
- package/dist/server-contract/resolve.js +271 -0
- package/dist/server-contract/result-helpers.d.ts +51 -0
- package/dist/server-contract/result-helpers.js +59 -0
- package/dist/server-contract/route-result-validation.d.ts +2 -0
- package/dist/server-contract/route-result-validation.js +73 -0
- package/dist/server-contract/stage.d.ts +6 -0
- package/dist/server-contract/stage.js +22 -0
- package/dist/server-contract.d.ts +6 -54
- package/dist/server-contract.js +9 -301
- package/dist/server-error.d.ts +1 -1
- package/dist/server-error.js +2 -0
- package/dist/server-middleware.d.ts +10 -0
- package/dist/server-middleware.js +30 -0
- package/dist/server-output.d.ts +2 -1
- package/dist/server-output.js +72 -12
- package/dist/server-runtime/node-server.js +59 -7
- package/dist/server-runtime/route-render.d.ts +25 -1
- package/dist/server-runtime/route-render.js +81 -29
- package/dist/server-script-composition.d.ts +4 -2
- package/dist/server-script-composition.js +6 -3
- package/dist/static-export-paths.d.ts +3 -0
- package/dist/static-export-paths.js +160 -0
- package/package.json +3 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function createCompilerTotals(): {
|
|
2
|
+
pageMs: number;
|
|
3
|
+
ownerMs: number;
|
|
4
|
+
componentMs: number;
|
|
5
|
+
pageCalls: number;
|
|
6
|
+
ownerCalls: number;
|
|
7
|
+
componentCalls: number;
|
|
8
|
+
componentCacheHits: number;
|
|
9
|
+
componentCacheMisses: number;
|
|
10
|
+
};
|
|
11
|
+
export function createExpressionRewriteMetrics(): {
|
|
12
|
+
calls: number;
|
|
13
|
+
compilerOwnedBindings: number;
|
|
14
|
+
ambiguousBindings: number;
|
|
15
|
+
};
|
|
16
|
+
export function toManifestEntryMap(manifest: any, pagesDir: any): Map<any, any>;
|
|
17
|
+
export function orderEnvelopes(manifest: any, pagesDir: any, envelopeByFile: any): any[] | null;
|
|
18
|
+
export function isCssOnlyChange(changedFiles: any): any;
|
|
19
|
+
export function buildPageOnlyFastPathSignature(envelope: any): any;
|
|
20
|
+
export function buildGlobalGraphHash(envelopes: any): string;
|
|
21
|
+
export function selectPageOnlyEntries(changedFiles: any, pagesDir: any, manifestEntryByPath: any): any[];
|
|
22
|
+
export function maybeRunVersionCheck({ state, startupProfile, projectRoot, logger, bundlerBin }: {
|
|
23
|
+
state: any;
|
|
24
|
+
startupProfile: any;
|
|
25
|
+
projectRoot: any;
|
|
26
|
+
logger: any;
|
|
27
|
+
bundlerBin: any;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
export function buildCompilerWarningEmitter(logger: any): (line: string) => void;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { createCompilerWarningEmitter } from '../build/compiler-runtime.js';
|
|
5
|
+
import { resolveBundlerBin } from '../toolchain-paths.js';
|
|
6
|
+
import { getActiveToolchainCandidate } from '../toolchain-runner.js';
|
|
7
|
+
import { maybeWarnAboutZenithVersionMismatch } from '../version-check.js';
|
|
8
|
+
export function createCompilerTotals() {
|
|
9
|
+
return {
|
|
10
|
+
pageMs: 0,
|
|
11
|
+
ownerMs: 0,
|
|
12
|
+
componentMs: 0,
|
|
13
|
+
pageCalls: 0,
|
|
14
|
+
ownerCalls: 0,
|
|
15
|
+
componentCalls: 0,
|
|
16
|
+
componentCacheHits: 0,
|
|
17
|
+
componentCacheMisses: 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function createExpressionRewriteMetrics() {
|
|
21
|
+
return {
|
|
22
|
+
calls: 0,
|
|
23
|
+
compilerOwnedBindings: 0,
|
|
24
|
+
ambiguousBindings: 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function toManifestEntryMap(manifest, pagesDir) {
|
|
28
|
+
const map = new Map();
|
|
29
|
+
for (const entry of manifest) {
|
|
30
|
+
map.set(resolve(pagesDir, entry.file), entry);
|
|
31
|
+
}
|
|
32
|
+
return map;
|
|
33
|
+
}
|
|
34
|
+
export function orderEnvelopes(manifest, pagesDir, envelopeByFile) {
|
|
35
|
+
const ordered = [];
|
|
36
|
+
for (const entry of manifest) {
|
|
37
|
+
const envelope = envelopeByFile.get(resolve(pagesDir, entry.file));
|
|
38
|
+
if (!envelope) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
ordered.push(envelope);
|
|
42
|
+
}
|
|
43
|
+
return ordered;
|
|
44
|
+
}
|
|
45
|
+
export function isCssOnlyChange(changedFiles) {
|
|
46
|
+
return changedFiles.length > 0 && changedFiles.every((filePath) => filePath.endsWith('.css'));
|
|
47
|
+
}
|
|
48
|
+
function stableJson(value) {
|
|
49
|
+
if (value === null || value === undefined) {
|
|
50
|
+
return 'null';
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
return `[${value.map((entry) => stableJson(entry)).join(',')}]`;
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === 'object') {
|
|
56
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(',')}}`;
|
|
57
|
+
}
|
|
58
|
+
return JSON.stringify(value);
|
|
59
|
+
}
|
|
60
|
+
function collectJsImportSpecifiers(source) {
|
|
61
|
+
const values = [];
|
|
62
|
+
const patterns = [
|
|
63
|
+
/\bimport\s+(?:[^'"\n;]*?\s+from\s+)?['"]([^'"]+)['"]/g,
|
|
64
|
+
/\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
65
|
+
/\bexport\s+[^'"\n;]*?\s+from\s+['"]([^'"]+)['"]/g
|
|
66
|
+
];
|
|
67
|
+
for (const pattern of patterns) {
|
|
68
|
+
pattern.lastIndex = 0;
|
|
69
|
+
for (const match of source.matchAll(pattern)) {
|
|
70
|
+
const value = String(match[1] || '').trim();
|
|
71
|
+
if (value.length > 0 && !values.includes(value)) {
|
|
72
|
+
values.push(value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return values.sort();
|
|
77
|
+
}
|
|
78
|
+
function isExternalRuntimeSpecifier(specifier) {
|
|
79
|
+
return !specifier.startsWith('.')
|
|
80
|
+
&& !specifier.startsWith('/')
|
|
81
|
+
&& !specifier.startsWith('@/')
|
|
82
|
+
&& !specifier.startsWith('\0zenith:')
|
|
83
|
+
&& !specifier.includes('zenith:');
|
|
84
|
+
}
|
|
85
|
+
function collectEnvelopeAssetContract(envelope) {
|
|
86
|
+
const cssImportSpecifiers = new Set();
|
|
87
|
+
const externalImportSpecifiers = new Set();
|
|
88
|
+
for (const entry of envelope.ir.hoisted?.imports || []) {
|
|
89
|
+
for (const specifier of collectJsImportSpecifiers(String(entry || ''))) {
|
|
90
|
+
if (specifier.endsWith('.css')) {
|
|
91
|
+
cssImportSpecifiers.add(specifier);
|
|
92
|
+
}
|
|
93
|
+
if (isExternalRuntimeSpecifier(specifier)) {
|
|
94
|
+
externalImportSpecifiers.add(specifier);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const moduleEntry of envelope.ir.modules || []) {
|
|
99
|
+
for (const specifier of collectJsImportSpecifiers(String(moduleEntry?.source || ''))) {
|
|
100
|
+
if (specifier.endsWith('.css')) {
|
|
101
|
+
cssImportSpecifiers.add(specifier);
|
|
102
|
+
}
|
|
103
|
+
if (isExternalRuntimeSpecifier(specifier)) {
|
|
104
|
+
externalImportSpecifiers.add(specifier);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const importEntry of envelope.ir.imports || []) {
|
|
109
|
+
const specifier = String(importEntry?.spec || '').trim();
|
|
110
|
+
if (!specifier) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (specifier.endsWith('.css')) {
|
|
114
|
+
cssImportSpecifiers.add(specifier);
|
|
115
|
+
}
|
|
116
|
+
if (isExternalRuntimeSpecifier(specifier)) {
|
|
117
|
+
externalImportSpecifiers.add(specifier);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
componentHoistIds: Object.keys(envelope.ir.components_scripts || {}).sort(),
|
|
122
|
+
cssImportSpecifiers: [...cssImportSpecifiers].sort(),
|
|
123
|
+
externalImportSpecifiers: [...externalImportSpecifiers].sort()
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function collectTemplateClassSignature(envelope) {
|
|
127
|
+
const html = typeof envelope?.ir?.html === 'string' ? envelope.ir.html : '';
|
|
128
|
+
if (!html) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
const classes = new Set();
|
|
132
|
+
const classAttrRe = /\bclass\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;
|
|
133
|
+
let match;
|
|
134
|
+
while ((match = classAttrRe.exec(html)) !== null) {
|
|
135
|
+
const rawValue = String(match[1] || match[2] || '');
|
|
136
|
+
for (const token of rawValue.split(/\s+/)) {
|
|
137
|
+
const value = token.trim();
|
|
138
|
+
if (value.length > 0) {
|
|
139
|
+
classes.add(value);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return [...classes].sort();
|
|
144
|
+
}
|
|
145
|
+
export function buildPageOnlyFastPathSignature(envelope) {
|
|
146
|
+
return stableJson({
|
|
147
|
+
route: envelope.route,
|
|
148
|
+
router: envelope.router === true,
|
|
149
|
+
assetContract: collectEnvelopeAssetContract(envelope),
|
|
150
|
+
templateClassSignature: collectTemplateClassSignature(envelope),
|
|
151
|
+
styleBlocks: envelope.ir.style_blocks || [],
|
|
152
|
+
serverScript: envelope.ir.server_script || null,
|
|
153
|
+
prerender: envelope.ir.prerender === true,
|
|
154
|
+
hasGuard: envelope.ir.has_guard === true,
|
|
155
|
+
hasLoad: envelope.ir.has_load === true,
|
|
156
|
+
guardModuleRef: envelope.ir.guard_module_ref || null,
|
|
157
|
+
loadModuleRef: envelope.ir.load_module_ref || null
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
export function buildGlobalGraphHash(envelopes) {
|
|
161
|
+
const nodesByHoistId = new Map();
|
|
162
|
+
const edgeSet = new Set();
|
|
163
|
+
for (const envelope of envelopes) {
|
|
164
|
+
for (const node of envelope.ir.graph_nodes || []) {
|
|
165
|
+
if (node && typeof node.hoist_id === 'string' && node.hoist_id.length > 0) {
|
|
166
|
+
nodesByHoistId.set(node.hoist_id, true);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
for (const edge of envelope.ir.graph_edges || []) {
|
|
170
|
+
if (typeof edge === 'string' && edge.length > 0) {
|
|
171
|
+
edgeSet.add(edge);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
let seed = '';
|
|
176
|
+
for (const hoistId of [...nodesByHoistId.keys()].sort()) {
|
|
177
|
+
seed += `node:${hoistId}\n`;
|
|
178
|
+
}
|
|
179
|
+
for (const edge of [...edgeSet].sort()) {
|
|
180
|
+
seed += `edge:${edge}\n`;
|
|
181
|
+
}
|
|
182
|
+
return createHash('sha256').update(seed).digest('hex');
|
|
183
|
+
}
|
|
184
|
+
export function selectPageOnlyEntries(changedFiles, pagesDir, manifestEntryByPath) {
|
|
185
|
+
if (changedFiles.length === 0) {
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
const selected = new Map();
|
|
189
|
+
for (const filePath of changedFiles) {
|
|
190
|
+
const resolvedPath = resolve(filePath);
|
|
191
|
+
if (!resolvedPath.startsWith(pagesDir) || !resolvedPath.endsWith('.zen') || !existsSync(resolvedPath)) {
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
const entry = manifestEntryByPath.get(resolvedPath);
|
|
195
|
+
if (!entry) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
selected.set(entry.file, entry);
|
|
199
|
+
}
|
|
200
|
+
return [...selected.values()];
|
|
201
|
+
}
|
|
202
|
+
export async function maybeRunVersionCheck({ state, startupProfile, projectRoot, logger, bundlerBin }) {
|
|
203
|
+
if (state.versionChecked) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const resolvedBundlerCandidate = getActiveToolchainCandidate(bundlerBin);
|
|
207
|
+
await startupProfile.measureAsync('version_mismatch_check', () => maybeWarnAboutZenithVersionMismatch({
|
|
208
|
+
projectRoot,
|
|
209
|
+
logger,
|
|
210
|
+
command: 'dev',
|
|
211
|
+
bundlerBinPath: resolvedBundlerCandidate?.path || resolveBundlerBin(projectRoot)
|
|
212
|
+
}));
|
|
213
|
+
state.versionChecked = true;
|
|
214
|
+
}
|
|
215
|
+
export function buildCompilerWarningEmitter(logger) {
|
|
216
|
+
return createCompilerWarningEmitter((line) => {
|
|
217
|
+
if (logger && typeof logger.warn === 'function') {
|
|
218
|
+
logger.warn(line, { onceKey: `compiler-warning:${line}` });
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
console.warn(line);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function createDevBuildSession(options: any): {
|
|
2
|
+
build(buildOptions?: {}): Promise<{
|
|
3
|
+
pages: number;
|
|
4
|
+
assets: any;
|
|
5
|
+
strategy: string;
|
|
6
|
+
}>;
|
|
7
|
+
getImageRuntimePayload(): {
|
|
8
|
+
mode: string;
|
|
9
|
+
basePath: string;
|
|
10
|
+
config: {
|
|
11
|
+
formats: string[];
|
|
12
|
+
deviceSizes: number[];
|
|
13
|
+
imageSizes: number[];
|
|
14
|
+
remotePatterns: any[];
|
|
15
|
+
quality: number;
|
|
16
|
+
allowSvg: boolean;
|
|
17
|
+
maxRemoteBytes: number;
|
|
18
|
+
maxPixels: number;
|
|
19
|
+
minimumCacheTTL: number;
|
|
20
|
+
dangerouslyAllowLocalNetwork: boolean;
|
|
21
|
+
};
|
|
22
|
+
localImages: any;
|
|
23
|
+
} | null;
|
|
24
|
+
};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { buildComponentRegistry } from '../resolve-components.js';
|
|
3
|
+
import { normalizeBasePath } from '../base-path.js';
|
|
4
|
+
import { collectAssets, runBundler } from '../build/compiler-runtime.js';
|
|
5
|
+
import { buildPageEnvelopes } from '../build/page-loop.js';
|
|
6
|
+
import { createPageLoopCaches } from '../build/page-loop-state.js';
|
|
7
|
+
import { deriveProjectRootFromPagesDir, ensureZenithTypeDeclarations } from '../build/type-declarations.js';
|
|
8
|
+
import { injectImageMaterializationIntoRouterManifest } from '../images/router-manifest.js';
|
|
9
|
+
import { buildImageArtifacts } from '../images/service.js';
|
|
10
|
+
import { materializeImageMarkupInHtmlFiles } from '../images/materialize.js';
|
|
11
|
+
import { createImageRuntimePayload, injectImageRuntimePayloadIntoHtmlFiles } from '../images/payload.js';
|
|
12
|
+
import { createStartupProfiler } from '../startup-profile.js';
|
|
13
|
+
import { resolveBuildAdapter } from '../adapters/resolve-adapter.js';
|
|
14
|
+
import { supportsTargetRouteCheck } from '../route-check-support.js';
|
|
15
|
+
import { createBundlerToolchain, createCompilerToolchain, ensureToolchainCompatibility } from '../toolchain-runner.js';
|
|
16
|
+
import { buildCompilerWarningEmitter, buildGlobalGraphHash, buildPageOnlyFastPathSignature, createCompilerTotals, createExpressionRewriteMetrics, isCssOnlyChange, maybeRunVersionCheck, orderEnvelopes, selectPageOnlyEntries, toManifestEntryMap } from './helpers.js';
|
|
17
|
+
import { createDevBuildState } from './state.js';
|
|
18
|
+
import { generateManifest } from '../manifest.js';
|
|
19
|
+
export function createDevBuildSession(options) {
|
|
20
|
+
const { pagesDir, outDir, config = {}, logger = null } = options;
|
|
21
|
+
const resolvedPagesDir = resolve(pagesDir);
|
|
22
|
+
const projectRoot = deriveProjectRootFromPagesDir(resolvedPagesDir);
|
|
23
|
+
const srcDir = resolve(resolvedPagesDir, '..');
|
|
24
|
+
const compilerBin = createCompilerToolchain({ projectRoot, logger });
|
|
25
|
+
const bundlerBin = createBundlerToolchain({ projectRoot, logger });
|
|
26
|
+
const routerEnabled = config.router === true;
|
|
27
|
+
const { target } = resolveBuildAdapter(config);
|
|
28
|
+
const basePath = normalizeBasePath(config.basePath || '/');
|
|
29
|
+
const routeCheckEnabled = supportsTargetRouteCheck(target);
|
|
30
|
+
const compilerOpts = {
|
|
31
|
+
typescriptDefault: config.typescriptDefault === true,
|
|
32
|
+
experimentalEmbeddedMarkup: config.embeddedMarkupExpressions === true,
|
|
33
|
+
strictDomLints: config.strictDomLints === true
|
|
34
|
+
};
|
|
35
|
+
ensureToolchainCompatibility(bundlerBin);
|
|
36
|
+
const state = createDevBuildState(config, basePath);
|
|
37
|
+
async function syncImageState(startupProfile) {
|
|
38
|
+
const { manifest } = await startupProfile.measureAsync('build_image_artifacts', () => buildImageArtifacts({
|
|
39
|
+
projectRoot,
|
|
40
|
+
outDir,
|
|
41
|
+
config: config.images
|
|
42
|
+
}));
|
|
43
|
+
state.imageManifest = manifest;
|
|
44
|
+
state.imageRuntimePayload = createImageRuntimePayload(config.images, manifest, 'passthrough', basePath);
|
|
45
|
+
await startupProfile.measureAsync('materialize_image_markup', () => materializeImageMarkupInHtmlFiles({
|
|
46
|
+
distDir: outDir,
|
|
47
|
+
payload: state.imageRuntimePayload
|
|
48
|
+
}));
|
|
49
|
+
await startupProfile.measureAsync('inject_image_runtime_payload', () => injectImageRuntimePayloadIntoHtmlFiles(outDir, state.imageRuntimePayload));
|
|
50
|
+
}
|
|
51
|
+
async function runBundlerWithCachedEnvelopes(startupProfile, activeLogger, showBundlerInfo, bundlerOptions = {}) {
|
|
52
|
+
const orderedEnvelopes = bundlerOptions.envelopesOverride
|
|
53
|
+
|| orderEnvelopes(state.manifest, resolvedPagesDir, state.envelopeByFile);
|
|
54
|
+
if (!orderedEnvelopes || orderedEnvelopes.length === 0) {
|
|
55
|
+
throw new Error('Dev rebuild cache is incomplete; full rebuild required.');
|
|
56
|
+
}
|
|
57
|
+
await startupProfile.measureAsync('run_bundler', () => runBundler(orderedEnvelopes, outDir, projectRoot, activeLogger, showBundlerInfo, bundlerBin, {
|
|
58
|
+
routeCheck: routeCheckEnabled,
|
|
59
|
+
devStableAssets: true,
|
|
60
|
+
rebuildStrategy: bundlerOptions.rebuildStrategy || 'full',
|
|
61
|
+
changedRoutes: bundlerOptions.changedRoutes || [],
|
|
62
|
+
fastPath: bundlerOptions.fastPath === true,
|
|
63
|
+
globalGraphHash: bundlerOptions.globalGraphHash || ''
|
|
64
|
+
}), { envelopes: orderedEnvelopes.length });
|
|
65
|
+
await startupProfile.measureAsync('inject_image_materialization_manifest', () => injectImageMaterializationIntoRouterManifest(outDir, orderedEnvelopes), { envelopes: orderedEnvelopes.length });
|
|
66
|
+
const assets = await startupProfile.measureAsync('collect_assets', () => collectAssets(outDir));
|
|
67
|
+
return { assets, envelopeCount: orderedEnvelopes.length };
|
|
68
|
+
}
|
|
69
|
+
async function runFullBuild(activeLogger, showBundlerInfo) {
|
|
70
|
+
const startupProfile = createStartupProfiler('cli-build');
|
|
71
|
+
const compilerTotals = createCompilerTotals();
|
|
72
|
+
await maybeRunVersionCheck({
|
|
73
|
+
state,
|
|
74
|
+
startupProfile,
|
|
75
|
+
projectRoot,
|
|
76
|
+
logger: activeLogger,
|
|
77
|
+
bundlerBin
|
|
78
|
+
});
|
|
79
|
+
state.registry = startupProfile.measureSync('build_component_registry', () => buildComponentRegistry(srcDir));
|
|
80
|
+
state.manifest = await startupProfile.measureAsync('generate_manifest', () => generateManifest(resolvedPagesDir));
|
|
81
|
+
await startupProfile.measureAsync('ensure_zenith_type_declarations', () => ensureZenithTypeDeclarations({
|
|
82
|
+
manifest: state.manifest,
|
|
83
|
+
pagesDir: resolvedPagesDir
|
|
84
|
+
}));
|
|
85
|
+
state.pageLoopCaches = createPageLoopCaches();
|
|
86
|
+
const emitCompilerWarning = buildCompilerWarningEmitter(activeLogger);
|
|
87
|
+
const { envelopes, expressionRewriteMetrics } = await buildPageEnvelopes({
|
|
88
|
+
manifest: state.manifest,
|
|
89
|
+
pagesDir: resolvedPagesDir,
|
|
90
|
+
srcDir,
|
|
91
|
+
registry: state.registry,
|
|
92
|
+
compilerOpts,
|
|
93
|
+
compilerBin,
|
|
94
|
+
routerEnabled,
|
|
95
|
+
startupProfile,
|
|
96
|
+
compilerTotals,
|
|
97
|
+
emitCompilerWarning,
|
|
98
|
+
pageLoopCaches: state.pageLoopCaches
|
|
99
|
+
});
|
|
100
|
+
state.envelopeByFile = new Map(envelopes.map((entry) => [entry.file, entry]));
|
|
101
|
+
state.manifestEntryByPath = toManifestEntryMap(state.manifest, resolvedPagesDir);
|
|
102
|
+
state.pageOnlyFastPathSignatureByFile = new Map(envelopes.map((entry) => [entry.file, buildPageOnlyFastPathSignature(entry)]));
|
|
103
|
+
state.globalGraphHash = buildGlobalGraphHash(envelopes);
|
|
104
|
+
const { assets } = await runBundlerWithCachedEnvelopes(startupProfile, activeLogger, showBundlerInfo);
|
|
105
|
+
await syncImageState(startupProfile);
|
|
106
|
+
startupProfile.emit('build_complete', {
|
|
107
|
+
pages: state.manifest.length,
|
|
108
|
+
assets: assets.length,
|
|
109
|
+
compilerTotals,
|
|
110
|
+
expressionRewriteMetrics,
|
|
111
|
+
strategy: 'full'
|
|
112
|
+
});
|
|
113
|
+
state.hasSuccessfulBuild = true;
|
|
114
|
+
return { pages: state.manifest.length, assets, strategy: 'full' };
|
|
115
|
+
}
|
|
116
|
+
async function runBundleOnlyBuild(activeLogger, showBundlerInfo) {
|
|
117
|
+
const startupProfile = createStartupProfiler('cli-build');
|
|
118
|
+
const compilerTotals = createCompilerTotals();
|
|
119
|
+
const expressionRewriteMetrics = createExpressionRewriteMetrics();
|
|
120
|
+
const { assets } = await runBundlerWithCachedEnvelopes(startupProfile, activeLogger, showBundlerInfo, { rebuildStrategy: 'bundle-only' });
|
|
121
|
+
await syncImageState(startupProfile);
|
|
122
|
+
startupProfile.emit('build_complete', {
|
|
123
|
+
pages: state.manifest.length,
|
|
124
|
+
assets: assets.length,
|
|
125
|
+
compilerTotals,
|
|
126
|
+
expressionRewriteMetrics,
|
|
127
|
+
strategy: 'bundle-only'
|
|
128
|
+
});
|
|
129
|
+
return { pages: state.manifest.length, assets, strategy: 'bundle-only' };
|
|
130
|
+
}
|
|
131
|
+
async function runPageOnlyBuild(entries, activeLogger, showBundlerInfo) {
|
|
132
|
+
const startupProfile = createStartupProfiler('cli-build');
|
|
133
|
+
const compilerTotals = createCompilerTotals();
|
|
134
|
+
const emitCompilerWarning = buildCompilerWarningEmitter(activeLogger);
|
|
135
|
+
const { envelopes, expressionRewriteMetrics } = await buildPageEnvelopes({
|
|
136
|
+
manifest: entries,
|
|
137
|
+
pagesDir: resolvedPagesDir,
|
|
138
|
+
srcDir,
|
|
139
|
+
registry: state.registry,
|
|
140
|
+
compilerOpts,
|
|
141
|
+
compilerBin,
|
|
142
|
+
routerEnabled,
|
|
143
|
+
startupProfile,
|
|
144
|
+
compilerTotals,
|
|
145
|
+
emitCompilerWarning,
|
|
146
|
+
pageLoopCaches: state.pageLoopCaches
|
|
147
|
+
});
|
|
148
|
+
const previousFastPathSignatures = new Map(state.pageOnlyFastPathSignatureByFile);
|
|
149
|
+
const canUseFastPath = entries.every((entry, index) => {
|
|
150
|
+
const previous = previousFastPathSignatures.get(resolve(resolvedPagesDir, entry.file));
|
|
151
|
+
const next = buildPageOnlyFastPathSignature(envelopes[index]);
|
|
152
|
+
return typeof previous === 'string' && previous === next;
|
|
153
|
+
});
|
|
154
|
+
for (const envelope of envelopes) {
|
|
155
|
+
state.envelopeByFile.set(envelope.file, envelope);
|
|
156
|
+
state.pageOnlyFastPathSignatureByFile.set(envelope.file, buildPageOnlyFastPathSignature(envelope));
|
|
157
|
+
}
|
|
158
|
+
const orderedEnvelopes = orderEnvelopes(state.manifest, resolvedPagesDir, state.envelopeByFile);
|
|
159
|
+
if (!orderedEnvelopes || orderedEnvelopes.length === 0) {
|
|
160
|
+
throw new Error('Dev rebuild cache is incomplete; full rebuild required.');
|
|
161
|
+
}
|
|
162
|
+
state.globalGraphHash = buildGlobalGraphHash(orderedEnvelopes);
|
|
163
|
+
const { assets } = await runBundlerWithCachedEnvelopes(startupProfile, activeLogger, showBundlerInfo, {
|
|
164
|
+
rebuildStrategy: 'page-only',
|
|
165
|
+
changedRoutes: entries.map((entry) => entry.path),
|
|
166
|
+
fastPath: canUseFastPath,
|
|
167
|
+
envelopesOverride: canUseFastPath ? envelopes : orderedEnvelopes,
|
|
168
|
+
globalGraphHash: canUseFastPath ? state.globalGraphHash : ''
|
|
169
|
+
});
|
|
170
|
+
await syncImageState(startupProfile);
|
|
171
|
+
startupProfile.emit('build_complete', {
|
|
172
|
+
pages: state.manifest.length,
|
|
173
|
+
assets: assets.length,
|
|
174
|
+
compilerTotals,
|
|
175
|
+
expressionRewriteMetrics,
|
|
176
|
+
strategy: 'page-only',
|
|
177
|
+
rebuiltPages: entries.length
|
|
178
|
+
});
|
|
179
|
+
return { pages: state.manifest.length, assets, strategy: 'page-only', rebuiltPages: entries.length };
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
async build(buildOptions = {}) {
|
|
183
|
+
const activeLogger = buildOptions.logger || logger;
|
|
184
|
+
const showBundlerInfo = buildOptions.showBundlerInfo !== false;
|
|
185
|
+
const changedFiles = Array.isArray(buildOptions.changedFiles)
|
|
186
|
+
? [...new Set(buildOptions.changedFiles.map((entry) => resolve(String(entry))))]
|
|
187
|
+
: [];
|
|
188
|
+
if (!state.hasSuccessfulBuild || changedFiles.length === 0) {
|
|
189
|
+
return runFullBuild(activeLogger, showBundlerInfo);
|
|
190
|
+
}
|
|
191
|
+
if (isCssOnlyChange(changedFiles)) {
|
|
192
|
+
return runBundleOnlyBuild(activeLogger, showBundlerInfo);
|
|
193
|
+
}
|
|
194
|
+
const pageOnlyEntries = selectPageOnlyEntries(changedFiles, resolvedPagesDir, state.manifestEntryByPath);
|
|
195
|
+
if (pageOnlyEntries.length > 0) {
|
|
196
|
+
return runPageOnlyBuild(pageOnlyEntries, activeLogger, showBundlerInfo);
|
|
197
|
+
}
|
|
198
|
+
return runFullBuild(activeLogger, showBundlerInfo);
|
|
199
|
+
},
|
|
200
|
+
getImageRuntimePayload() {
|
|
201
|
+
return state.imageRuntimePayload;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function createDevBuildState(config: any, basePath: any): {
|
|
2
|
+
versionChecked: boolean;
|
|
3
|
+
registry: Map<any, any>;
|
|
4
|
+
manifest: never[];
|
|
5
|
+
manifestEntryByPath: Map<any, any>;
|
|
6
|
+
envelopeByFile: Map<any, any>;
|
|
7
|
+
pageOnlyFastPathSignatureByFile: Map<any, any>;
|
|
8
|
+
globalGraphHash: string;
|
|
9
|
+
pageLoopCaches: {
|
|
10
|
+
componentIrCache: Map<any, any>;
|
|
11
|
+
componentDocumentModeCache: Map<any, any>;
|
|
12
|
+
componentExpressionRewriteCache: Map<any, any>;
|
|
13
|
+
hoistedCodeTransformCache: {
|
|
14
|
+
transpileToJs: Map<any, any>;
|
|
15
|
+
deferRuntime: Map<any, any>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
hasSuccessfulBuild: boolean;
|
|
19
|
+
imageManifest: {};
|
|
20
|
+
imageRuntimePayload: {
|
|
21
|
+
mode: string;
|
|
22
|
+
basePath: string;
|
|
23
|
+
config: {
|
|
24
|
+
formats: string[];
|
|
25
|
+
deviceSizes: number[];
|
|
26
|
+
imageSizes: number[];
|
|
27
|
+
remotePatterns: any[];
|
|
28
|
+
quality: number;
|
|
29
|
+
allowSvg: boolean;
|
|
30
|
+
maxRemoteBytes: number;
|
|
31
|
+
maxPixels: number;
|
|
32
|
+
minimumCacheTTL: number;
|
|
33
|
+
dangerouslyAllowLocalNetwork: boolean;
|
|
34
|
+
};
|
|
35
|
+
localImages: any;
|
|
36
|
+
} | null;
|
|
37
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createPageLoopCaches } from '../build/page-loop-state.js';
|
|
2
|
+
import { createImageRuntimePayload } from '../images/payload.js';
|
|
3
|
+
export function createDevBuildState(config, basePath) {
|
|
4
|
+
return {
|
|
5
|
+
versionChecked: false,
|
|
6
|
+
registry: new Map(),
|
|
7
|
+
manifest: [],
|
|
8
|
+
manifestEntryByPath: new Map(),
|
|
9
|
+
envelopeByFile: new Map(),
|
|
10
|
+
pageOnlyFastPathSignatureByFile: new Map(),
|
|
11
|
+
globalGraphHash: '',
|
|
12
|
+
pageLoopCaches: createPageLoopCaches(),
|
|
13
|
+
hasSuccessfulBuild: false,
|
|
14
|
+
imageManifest: {},
|
|
15
|
+
imageRuntimePayload: createImageRuntimePayload(config.images, {}, 'passthrough', basePath)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,24 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
build(buildOptions?: {}): Promise<{
|
|
3
|
-
pages: number;
|
|
4
|
-
assets: any;
|
|
5
|
-
strategy: string;
|
|
6
|
-
}>;
|
|
7
|
-
getImageRuntimePayload(): {
|
|
8
|
-
mode: string;
|
|
9
|
-
basePath: string;
|
|
10
|
-
config: {
|
|
11
|
-
formats: string[];
|
|
12
|
-
deviceSizes: number[];
|
|
13
|
-
imageSizes: number[];
|
|
14
|
-
remotePatterns: any[];
|
|
15
|
-
quality: number;
|
|
16
|
-
allowSvg: boolean;
|
|
17
|
-
maxRemoteBytes: number;
|
|
18
|
-
maxPixels: number;
|
|
19
|
-
minimumCacheTTL: number;
|
|
20
|
-
dangerouslyAllowLocalNetwork: boolean;
|
|
21
|
-
};
|
|
22
|
-
localImages: any;
|
|
23
|
-
} | null;
|
|
24
|
-
};
|
|
1
|
+
export { createDevBuildSession } from "./dev-build-session/session.js";
|