@zenithbuild/cli 0.7.5 → 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/dist/adapters/adapter-netlify.js +0 -8
- package/dist/adapters/adapter-vercel.js +6 -14
- package/dist/adapters/copy-hosted-page-runtime.js +2 -1
- 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.js +46 -2
- 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 +123 -924
- package/dist/images/payload.js +4 -0
- package/dist/manifest.js +46 -1
- 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 -112
- package/dist/preview.js +7 -1119
- package/dist/resource-response.d.ts +15 -0
- package/dist/resource-response.js +91 -2
- 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 -62
- package/dist/server-contract.js +9 -493
- package/dist/server-middleware.d.ts +10 -0
- package/dist/server-middleware.js +30 -0
- package/dist/server-output.js +13 -1
- package/dist/server-runtime/node-server.js +25 -3
- package/package.json +3 -3
|
@@ -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";
|