@riebeckite/honox 0.0.35 → 0.0.37
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/index.d.ts +2 -1
- package/dist/index.js +1326 -1099
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.js +6 -0
- package/dist/server.js +50 -7
- package/dist/src/content_module.d.ts +11 -0
- package/dist/src/content_route.d.ts +2 -2
- package/dist/src/content_watch.d.ts +1 -2
- package/dist/src/endpoints.d.ts +2 -0
- package/dist/src/routes.d.ts +1 -1
- package/dist/src/ssg/artifact_writer.d.ts +14 -0
- package/dist/src/ssg/build_output.d.ts +4 -0
- package/dist/src/ssg/diagnostics.d.ts +2 -1
- package/dist/src/ssg/inventory.d.ts +1 -0
- package/dist/src/ssg/output_cache.d.ts +6 -0
- package/dist/src/ssg/runner.d.ts +12 -0
- package/dist/src/ssg/standalone.d.ts +14 -0
- package/dist/src/ssg/types.d.ts +10 -4
- package/dist/src/ssg_plugin.d.ts +2 -2
- package/dist/src/vite_runner.d.ts +5 -0
- package/package.json +12 -10
- package/style.css +5 -1
- package/dist/src/development_inspector.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -281,183 +281,301 @@ function isJavaScriptModule(filePath) {
|
|
|
281
281
|
return /\.[cm]?[jt]sx?$/.test(filePath);
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
// src/
|
|
285
|
-
import {
|
|
286
|
-
import {
|
|
287
|
-
import {
|
|
288
|
-
import {
|
|
289
|
-
import {
|
|
290
|
-
createServer
|
|
291
|
-
} from "vite";
|
|
292
|
-
|
|
293
|
-
// src/content_assets.ts
|
|
294
|
-
import fs5 from "node:fs/promises";
|
|
295
|
-
import path7 from "node:path";
|
|
296
|
-
import { isImagePath as isImagePath2, normalizeContentPath as normalizeContentPath2 } from "@riebeckite/core";
|
|
297
|
-
import { isIgnoredContentPath as isIgnoredContentPath2 } from "@riebeckite/node";
|
|
298
|
-
|
|
299
|
-
// src/content_watch.ts
|
|
300
|
-
import path6 from "node:path";
|
|
301
|
-
import {
|
|
302
|
-
isAttachmentPath,
|
|
303
|
-
isImagePath,
|
|
304
|
-
normalizeContentPath
|
|
305
|
-
} from "@riebeckite/core";
|
|
306
|
-
import { isIgnoredContentPath } from "@riebeckite/node";
|
|
284
|
+
// src/ssg/inventory.ts
|
|
285
|
+
import { createHash } from "node:crypto";
|
|
286
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
287
|
+
import { dirname, join, relative as relative2 } from "node:path";
|
|
288
|
+
import { performance } from "node:perf_hooks";
|
|
307
289
|
|
|
308
|
-
// src/
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
riebeckiteConfigModuleId,
|
|
313
|
-
riebeckiteContentModuleId
|
|
314
|
-
];
|
|
315
|
-
var resolvedConfigModuleId = `\0${riebeckiteConfigModuleId}`;
|
|
316
|
-
var resolvedContentModuleId = `\0${riebeckiteContentModuleId}`;
|
|
317
|
-
function riebeckiteRuntimeModules(getApplication) {
|
|
318
|
-
return {
|
|
319
|
-
name: "riebeckite-runtime-modules",
|
|
320
|
-
resolveId(id) {
|
|
321
|
-
if (id === riebeckiteConfigModuleId) return resolvedConfigModuleId;
|
|
322
|
-
if (id === riebeckiteContentModuleId) return resolvedContentModuleId;
|
|
323
|
-
return null;
|
|
324
|
-
},
|
|
325
|
-
load(id) {
|
|
326
|
-
if (id === resolvedConfigModuleId) {
|
|
327
|
-
const { appRoot, configFile } = getApplication();
|
|
328
|
-
return createConfigModule(appRoot, configFile);
|
|
329
|
-
}
|
|
330
|
-
if (id === resolvedContentModuleId) return createContentModule();
|
|
331
|
-
return null;
|
|
332
|
-
}
|
|
333
|
-
};
|
|
290
|
+
// src/ssg/file_system.ts
|
|
291
|
+
import { relative, resolve } from "node:path";
|
|
292
|
+
function isMissingDirectoryError(error) {
|
|
293
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
334
294
|
}
|
|
335
|
-
function
|
|
336
|
-
|
|
337
|
-
return runtimeModuleIds.some(
|
|
338
|
-
(moduleId) => id === moduleId || id === `\0${moduleId}`
|
|
339
|
-
);
|
|
295
|
+
function isNotFoundError(error) {
|
|
296
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
340
297
|
}
|
|
341
|
-
function
|
|
342
|
-
|
|
343
|
-
return `import * as rawConfigModule from ${JSON.stringify(configSpecifier)};
|
|
344
|
-
import { resolveConfigModule } from "@riebeckite/core";
|
|
345
|
-
import { resolveHonoxConfig } from "@riebeckite/honox/runtime";
|
|
346
|
-
|
|
347
|
-
export const config = resolveHonoxConfig(
|
|
348
|
-
resolveConfigModule(rawConfigModule),
|
|
349
|
-
${JSON.stringify(appRoot)},
|
|
350
|
-
);
|
|
351
|
-
`;
|
|
298
|
+
function isAbsolutePath(path12) {
|
|
299
|
+
return /^([a-z]:)?[\\/]/iu.test(path12);
|
|
352
300
|
}
|
|
353
|
-
function
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
[],
|
|
364
|
-
{ config, plugins: config.plugins },
|
|
365
|
-
);
|
|
366
|
-
`;
|
|
301
|
+
function resolveWithinDirectory(directory, relativePath, label) {
|
|
302
|
+
if (!relativePath || relativePath.includes("\0") || isAbsolutePath(relativePath)) {
|
|
303
|
+
throw new Error(`Invalid ${label}: ${relativePath}`);
|
|
304
|
+
}
|
|
305
|
+
const file = resolve(directory, relativePath);
|
|
306
|
+
const relativePathFromDirectory = relative(directory, file);
|
|
307
|
+
if (relativePathFromDirectory.startsWith("..") || relativePathFromDirectory === "" || isAbsolutePath(relativePathFromDirectory)) {
|
|
308
|
+
throw new Error(`Unsafe ${label}: ${relativePath}`);
|
|
309
|
+
}
|
|
310
|
+
return file;
|
|
367
311
|
}
|
|
368
312
|
|
|
369
|
-
// src/
|
|
370
|
-
var
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
const handle = (event) => (file) => {
|
|
399
|
-
if (!isContentFile(file)) return;
|
|
400
|
-
const logicalPath = toLogicalPath(contentRoot, file);
|
|
401
|
-
if (isIgnoredContentPath(logicalPath, exclude)) return;
|
|
402
|
-
if (event === "change" && isSiteAssetPath(logicalPath)) {
|
|
403
|
-
server.hot.send({ type: "full-reload" });
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
invalidate();
|
|
407
|
-
};
|
|
408
|
-
server.watcher.on("add", handle("add"));
|
|
409
|
-
server.watcher.on("change", handle("change"));
|
|
410
|
-
server.watcher.on("unlink", handle("unlink"));
|
|
313
|
+
// src/ssg/inventory.ts
|
|
314
|
+
var APP_FINGERPRINT_IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
315
|
+
"node_modules",
|
|
316
|
+
".riebeckite",
|
|
317
|
+
"dist"
|
|
318
|
+
]);
|
|
319
|
+
var APP_FINGERPRINT_CONFIG_FILES = [
|
|
320
|
+
"riebeckite.config.ts",
|
|
321
|
+
"riebeckite.config.mts",
|
|
322
|
+
"riebeckite.config.cts",
|
|
323
|
+
"riebeckite.config.js",
|
|
324
|
+
"riebeckite.config.mjs",
|
|
325
|
+
"riebeckite.config.cjs"
|
|
326
|
+
];
|
|
327
|
+
async function computeAppFingerprint(root, configFile) {
|
|
328
|
+
const files = [];
|
|
329
|
+
await collectAppFiles(join(root, "app"), files);
|
|
330
|
+
if (configFile) files.push(configFile);
|
|
331
|
+
for (const name of APP_FINGERPRINT_CONFIG_FILES) {
|
|
332
|
+
files.push(join(root, name));
|
|
333
|
+
}
|
|
334
|
+
files.sort();
|
|
335
|
+
const hash = createHash("sha256");
|
|
336
|
+
for (const file of files) {
|
|
337
|
+
let content;
|
|
338
|
+
try {
|
|
339
|
+
content = await readFile(file);
|
|
340
|
+
} catch {
|
|
341
|
+
continue;
|
|
411
342
|
}
|
|
412
|
-
|
|
343
|
+
hash.update(relative2(root, file).replaceAll("\\", "/"));
|
|
344
|
+
hash.update("\0");
|
|
345
|
+
hash.update(content);
|
|
346
|
+
hash.update("\0");
|
|
347
|
+
}
|
|
348
|
+
return hash.digest("hex");
|
|
413
349
|
}
|
|
414
|
-
function
|
|
415
|
-
|
|
350
|
+
async function computeBundleFingerprint(root, configFile) {
|
|
351
|
+
const hash = createHash("sha256");
|
|
352
|
+
hash.update(await computeAppFingerprint(root, configFile));
|
|
353
|
+
const files = [
|
|
354
|
+
...await findBundleInputFiles(root),
|
|
355
|
+
...await findLocalPackageInputFiles(root)
|
|
356
|
+
].sort();
|
|
357
|
+
for (const file of files) {
|
|
358
|
+
try {
|
|
359
|
+
hash.update(file).update("\0").update(await readFile(file)).update("\0");
|
|
360
|
+
} catch {
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
for (const [name, value] of Object.entries(process.env).filter(([name2]) => name2 === "NODE_ENV" || name2.startsWith("VITE_")).sort(([left], [right]) => left.localeCompare(right))) {
|
|
364
|
+
if (value === void 0) continue;
|
|
365
|
+
hash.update(name).update("\0").update(value).update("\0");
|
|
366
|
+
}
|
|
367
|
+
return hash.digest("hex");
|
|
368
|
+
}
|
|
369
|
+
async function fingerprintDirectory(directory) {
|
|
370
|
+
const inventory = await fingerprintOutputDirectory(directory);
|
|
371
|
+
const hash = createHash("sha256");
|
|
372
|
+
for (const [path12, checksum] of Object.entries(inventory).sort(
|
|
373
|
+
([left], [right]) => left.localeCompare(right)
|
|
374
|
+
)) {
|
|
375
|
+
hash.update(path12).update("\0").update(checksum).update("\0");
|
|
376
|
+
}
|
|
377
|
+
return hash.digest("hex");
|
|
378
|
+
}
|
|
379
|
+
async function fingerprintOutputDirectory(directory, relativeDirectory = "", metrics) {
|
|
380
|
+
const entries = await readdir(directory, { withFileTypes: true }).catch(
|
|
381
|
+
(error) => {
|
|
382
|
+
if (isMissingDirectoryError(error)) return void 0;
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
);
|
|
386
|
+
if (!entries) return {};
|
|
387
|
+
const inventory = {};
|
|
388
|
+
for (const entry of entries) {
|
|
389
|
+
const file = join(directory, entry.name);
|
|
390
|
+
const relativePath = join(relativeDirectory, entry.name).replaceAll(
|
|
391
|
+
"\\",
|
|
392
|
+
"/"
|
|
393
|
+
);
|
|
394
|
+
if (entry.isDirectory()) {
|
|
395
|
+
Object.assign(
|
|
396
|
+
inventory,
|
|
397
|
+
await fingerprintOutputDirectory(file, relativePath, metrics)
|
|
398
|
+
);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
if (entry.isFile()) {
|
|
402
|
+
const hashedAt = performance.now();
|
|
403
|
+
const content = await readFile(file);
|
|
404
|
+
inventory[relativePath] = createHash("sha256").update(content).digest("hex");
|
|
405
|
+
if (metrics) {
|
|
406
|
+
metrics.outputHashValidationDurationMs += performance.now() - hashedAt;
|
|
407
|
+
metrics.outputFilesHashed += 1;
|
|
408
|
+
metrics.outputBytesHashed += content.length;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return inventory;
|
|
416
413
|
}
|
|
417
|
-
function
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
return target === root || target.startsWith(`${root}/`);
|
|
414
|
+
function inventoriesEqual(left, right) {
|
|
415
|
+
const leftPaths = Object.keys(left);
|
|
416
|
+
const rightPaths = Object.keys(right);
|
|
417
|
+
return leftPaths.length === rightPaths.length && leftPaths.every((path12) => left[path12] === right[path12]);
|
|
422
418
|
}
|
|
423
|
-
function
|
|
424
|
-
|
|
425
|
-
|
|
419
|
+
async function collectAppFiles(directory, files) {
|
|
420
|
+
const entries = await readdir(directory, { withFileTypes: true }).catch(
|
|
421
|
+
() => void 0
|
|
426
422
|
);
|
|
423
|
+
if (!entries) return;
|
|
424
|
+
for (const entry of entries) {
|
|
425
|
+
const full = join(directory, entry.name);
|
|
426
|
+
if (entry.isDirectory()) {
|
|
427
|
+
if (APP_FINGERPRINT_IGNORED_DIRECTORIES.has(entry.name)) continue;
|
|
428
|
+
await collectAppFiles(full, files);
|
|
429
|
+
} else if (entry.isFile()) {
|
|
430
|
+
files.push(full);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
427
433
|
}
|
|
428
|
-
function
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
434
|
+
async function findBundleInputFiles(root) {
|
|
435
|
+
const files = [];
|
|
436
|
+
for (let directory = root; ; directory = dirname(directory)) {
|
|
437
|
+
for (const name of [
|
|
438
|
+
"package.json",
|
|
439
|
+
"pnpm-lock.yaml",
|
|
440
|
+
"package-lock.json",
|
|
441
|
+
"yarn.lock"
|
|
442
|
+
]) {
|
|
443
|
+
files.push(join(directory, name));
|
|
444
|
+
}
|
|
445
|
+
const parent = dirname(directory);
|
|
446
|
+
if (parent === directory) return files;
|
|
439
447
|
}
|
|
440
|
-
return invalidated;
|
|
441
448
|
}
|
|
442
|
-
function
|
|
443
|
-
|
|
444
|
-
|
|
449
|
+
async function findLocalPackageInputFiles(root) {
|
|
450
|
+
const packageFile = join(root, "package.json");
|
|
451
|
+
let packageSource;
|
|
452
|
+
try {
|
|
453
|
+
packageSource = await readFile(packageFile, "utf8");
|
|
454
|
+
} catch {
|
|
455
|
+
return [];
|
|
456
|
+
}
|
|
457
|
+
let packageJson;
|
|
458
|
+
try {
|
|
459
|
+
packageJson = JSON.parse(packageSource);
|
|
460
|
+
} catch {
|
|
461
|
+
return [];
|
|
462
|
+
}
|
|
463
|
+
if (!packageJson || typeof packageJson !== "object") return [];
|
|
464
|
+
const files = [];
|
|
465
|
+
const workspaceDependencies = /* @__PURE__ */ new Set();
|
|
466
|
+
for (const dependencyGroup of [
|
|
467
|
+
"dependencies",
|
|
468
|
+
"devDependencies",
|
|
469
|
+
"optionalDependencies"
|
|
470
|
+
]) {
|
|
471
|
+
const dependencies = packageJson[dependencyGroup];
|
|
472
|
+
if (!dependencies || typeof dependencies !== "object") continue;
|
|
473
|
+
for (const [name, specifier] of Object.entries(dependencies)) {
|
|
474
|
+
if (typeof specifier !== "string") continue;
|
|
475
|
+
const directory = localPackageDirectory(root, specifier);
|
|
476
|
+
if (directory) {
|
|
477
|
+
await collectPackageFiles(directory, files);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (specifier.startsWith("workspace:")) workspaceDependencies.add(name);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const workspaceRoot = await findWorkspaceRoot(root);
|
|
484
|
+
if (workspaceRoot && workspaceDependencies.size > 0) {
|
|
485
|
+
for (const directory of await findWorkspacePackageDirectories2(
|
|
486
|
+
workspaceRoot,
|
|
487
|
+
workspaceDependencies
|
|
488
|
+
)) {
|
|
489
|
+
await collectPackageFiles(directory, files);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return files;
|
|
445
493
|
}
|
|
446
|
-
function
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
494
|
+
function localPackageDirectory(root, specifier) {
|
|
495
|
+
if (specifier.startsWith("file:")) return join(root, specifier.slice(5));
|
|
496
|
+
if (specifier.startsWith("link:")) return join(root, specifier.slice(5));
|
|
497
|
+
return void 0;
|
|
498
|
+
}
|
|
499
|
+
async function findWorkspaceRoot(root) {
|
|
500
|
+
for (let directory = root; ; directory = dirname(directory)) {
|
|
501
|
+
try {
|
|
502
|
+
await readFile(join(directory, "pnpm-workspace.yaml"));
|
|
503
|
+
return directory;
|
|
504
|
+
} catch {
|
|
505
|
+
}
|
|
506
|
+
const parent = dirname(directory);
|
|
507
|
+
if (parent === directory) return void 0;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
async function findWorkspacePackageDirectories2(directory, names) {
|
|
511
|
+
const entries = await readdir(directory, { withFileTypes: true }).catch(
|
|
512
|
+
() => []
|
|
513
|
+
);
|
|
514
|
+
const matches = [];
|
|
515
|
+
for (const entry of entries) {
|
|
516
|
+
if (!entry.isDirectory() || APP_FINGERPRINT_IGNORED_DIRECTORIES.has(entry.name))
|
|
517
|
+
continue;
|
|
518
|
+
const child = join(directory, entry.name);
|
|
519
|
+
try {
|
|
520
|
+
const packageJson = JSON.parse(
|
|
521
|
+
await readFile(join(child, "package.json"), "utf8")
|
|
522
|
+
);
|
|
523
|
+
if (typeof packageJson.name === "string" && names.has(packageJson.name)) {
|
|
524
|
+
matches.push(child);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
} catch {
|
|
455
528
|
}
|
|
529
|
+
matches.push(...await findWorkspacePackageDirectories2(child, names));
|
|
456
530
|
}
|
|
531
|
+
return matches;
|
|
532
|
+
}
|
|
533
|
+
async function collectPackageFiles(directory, files) {
|
|
534
|
+
files.push(join(directory, "package.json"));
|
|
535
|
+
await collectAppFiles(directory, files);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// src/ssg_plugin.ts
|
|
539
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
540
|
+
import { lstat as lstat3, mkdir as mkdir5, rm as rm4, writeFile as writeFile4 } from "node:fs/promises";
|
|
541
|
+
import { dirname as dirname5, join as join5, relative as relative4, resolve as resolve4 } from "node:path";
|
|
542
|
+
import {
|
|
543
|
+
BUILD_OUTPUT_MARKER_FILE,
|
|
544
|
+
buildOutputPlan,
|
|
545
|
+
compareOutputPlan,
|
|
546
|
+
createBuildOutputMarker,
|
|
547
|
+
publicationFingerprint as fingerprintPublication,
|
|
548
|
+
isDeferredGeneratedOutput,
|
|
549
|
+
publicationEntriesFromManifest,
|
|
550
|
+
publicationOutputsFromManifest,
|
|
551
|
+
publicationRedirectsFromManifest,
|
|
552
|
+
serializeBuildOutputMarker
|
|
553
|
+
} from "@riebeckite/core";
|
|
554
|
+
|
|
555
|
+
// src/content_assets.ts
|
|
556
|
+
import fs5 from "node:fs/promises";
|
|
557
|
+
import path7 from "node:path";
|
|
558
|
+
import { isImagePath, normalizeContentPath } from "@riebeckite/core";
|
|
559
|
+
import { isIgnoredContentPath, isPathInsideDirectory } from "@riebeckite/node";
|
|
560
|
+
|
|
561
|
+
// src/content_module.ts
|
|
562
|
+
import path6 from "node:path";
|
|
563
|
+
function contentModuleEntry(appRoot) {
|
|
564
|
+
return path6.join(appRoot, "app", "server.ts");
|
|
565
|
+
}
|
|
566
|
+
function isContentModuleLoaded(server, appRoot) {
|
|
567
|
+
const entry = contentModuleEntry(appRoot);
|
|
568
|
+
const moduleGraph = server.environments?.ssr?.moduleGraph;
|
|
569
|
+
return Boolean(
|
|
570
|
+
moduleGraph?.getModuleById(entry) ?? [...moduleGraph?.idToModuleMap?.values() ?? []].find(
|
|
571
|
+
(module) => module.file && path6.resolve(module.file) === path6.resolve(entry)
|
|
572
|
+
)
|
|
573
|
+
);
|
|
457
574
|
}
|
|
458
|
-
function
|
|
459
|
-
|
|
460
|
-
|
|
575
|
+
async function loadContentModule(server, appRoot) {
|
|
576
|
+
return await server.ssrLoadModule(
|
|
577
|
+
contentModuleEntry(appRoot)
|
|
578
|
+
);
|
|
461
579
|
}
|
|
462
580
|
|
|
463
581
|
// src/content_assets.ts
|
|
@@ -477,14 +595,13 @@ function riebeckiteContentAssets(options) {
|
|
|
477
595
|
enforce: "pre",
|
|
478
596
|
configureServer(server) {
|
|
479
597
|
const contentRoot = options.contentRoot();
|
|
480
|
-
const entry = path7.join(options.appRoot(), "app", "server.ts");
|
|
481
598
|
const base = server.config.base;
|
|
482
599
|
const publicDir = server.config.publicDir;
|
|
483
600
|
let cachedManifest;
|
|
484
601
|
let cachedPaths = /* @__PURE__ */ new Set();
|
|
485
602
|
const resolvePublicImagePaths = async () => {
|
|
486
|
-
const module = await server.
|
|
487
|
-
const manifest = await module.content?.getManifest();
|
|
603
|
+
const module = await loadContentModule(server, options.appRoot());
|
|
604
|
+
const manifest = await module.content?.getManifest?.();
|
|
488
605
|
if (!manifest) return /* @__PURE__ */ new Set();
|
|
489
606
|
if (manifest !== cachedManifest) {
|
|
490
607
|
cachedManifest = manifest;
|
|
@@ -499,11 +616,11 @@ function riebeckiteContentAssets(options) {
|
|
|
499
616
|
return;
|
|
500
617
|
}
|
|
501
618
|
const logicalPath = toContentPath(request.url, base);
|
|
502
|
-
if (!logicalPath || !
|
|
619
|
+
if (!logicalPath || !isImagePath(logicalPath)) {
|
|
503
620
|
next();
|
|
504
621
|
return;
|
|
505
622
|
}
|
|
506
|
-
if (
|
|
623
|
+
if (isIgnoredContentPath(logicalPath)) {
|
|
507
624
|
next();
|
|
508
625
|
return;
|
|
509
626
|
}
|
|
@@ -555,8 +672,8 @@ function collectPublicImagePaths(manifest) {
|
|
|
555
672
|
const paths = /* @__PURE__ */ new Set();
|
|
556
673
|
for (const entry of manifest.publicEntries ?? []) {
|
|
557
674
|
for (const asset of entry.assets ?? []) {
|
|
558
|
-
const normalized =
|
|
559
|
-
if (
|
|
675
|
+
const normalized = normalizeContentPath(asset.path);
|
|
676
|
+
if (isImagePath(normalized)) paths.add(normalized);
|
|
560
677
|
}
|
|
561
678
|
}
|
|
562
679
|
return paths;
|
|
@@ -590,9 +707,9 @@ function toContentPath(url, base) {
|
|
|
590
707
|
} catch {
|
|
591
708
|
return void 0;
|
|
592
709
|
}
|
|
593
|
-
let pathname =
|
|
710
|
+
let pathname = normalizeContentPath(decoded);
|
|
594
711
|
if (base && base !== "/" && pathname.startsWith(base)) {
|
|
595
|
-
pathname =
|
|
712
|
+
pathname = normalizeContentPath(pathname.slice(base.length));
|
|
596
713
|
}
|
|
597
714
|
const logicalPath = pathname.replace(/^\/+/, "");
|
|
598
715
|
if (!logicalPath) return void 0;
|
|
@@ -616,38 +733,195 @@ async function hasSiteOwnedFile(publicDir, logicalPath) {
|
|
|
616
733
|
}
|
|
617
734
|
}
|
|
618
735
|
|
|
619
|
-
// src/ssg/
|
|
620
|
-
import {
|
|
621
|
-
import {
|
|
622
|
-
import {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
736
|
+
// src/ssg/artifact_writer.ts
|
|
737
|
+
import { randomUUID } from "node:crypto";
|
|
738
|
+
import { constants } from "node:fs";
|
|
739
|
+
import {
|
|
740
|
+
copyFile,
|
|
741
|
+
cp,
|
|
742
|
+
lstat,
|
|
743
|
+
mkdir,
|
|
744
|
+
readFile as readFile2,
|
|
745
|
+
rename,
|
|
746
|
+
rm,
|
|
747
|
+
writeFile
|
|
748
|
+
} from "node:fs/promises";
|
|
749
|
+
import { dirname as dirname2, join as join2, resolve as resolve2 } from "node:path";
|
|
750
|
+
async function createBuildArtifactWriter(input) {
|
|
751
|
+
const outputDirectory = input.outputDirectory;
|
|
752
|
+
await recoverPendingPublication(outputDirectory);
|
|
753
|
+
const stagingDirectory = input.stagingDirectory ?? join2(
|
|
754
|
+
dirname2(outputDirectory),
|
|
755
|
+
".riebeckite",
|
|
756
|
+
`build-output-${randomUUID()}`
|
|
757
|
+
);
|
|
758
|
+
if (resolve2(stagingDirectory) === resolve2(outputDirectory)) {
|
|
759
|
+
throw new Error(
|
|
760
|
+
"Build artifact staging directory must differ from output."
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
if (input.clearStagingDirectory !== false) {
|
|
764
|
+
await rm(stagingDirectory, { force: true, recursive: true });
|
|
765
|
+
}
|
|
766
|
+
await mkdir(stagingDirectory, { recursive: true });
|
|
767
|
+
let completed = false;
|
|
768
|
+
return {
|
|
769
|
+
directory: stagingDirectory,
|
|
770
|
+
async copyFrom(source) {
|
|
771
|
+
ensureOpen(completed);
|
|
772
|
+
await cp(source, stagingDirectory, { recursive: true });
|
|
773
|
+
},
|
|
774
|
+
async remove(path12) {
|
|
775
|
+
ensureOpen(completed);
|
|
776
|
+
await rm(resolveArtifactPath(stagingDirectory, path12), {
|
|
777
|
+
force: true,
|
|
778
|
+
recursive: true
|
|
779
|
+
});
|
|
780
|
+
},
|
|
781
|
+
async write(path12, data) {
|
|
782
|
+
ensureOpen(completed);
|
|
783
|
+
const target = resolveArtifactPath(stagingDirectory, path12);
|
|
784
|
+
await mkdir(dirname2(target), { recursive: true });
|
|
785
|
+
await writeFile(target, data);
|
|
786
|
+
},
|
|
787
|
+
async copyFileFrom(source, path12) {
|
|
788
|
+
ensureOpen(completed);
|
|
789
|
+
const target = resolveArtifactPath(stagingDirectory, path12);
|
|
790
|
+
await mkdir(dirname2(target), { recursive: true });
|
|
791
|
+
await rm(target, { force: true });
|
|
792
|
+
await copyFile(source, target, constants.COPYFILE_FICLONE);
|
|
793
|
+
},
|
|
794
|
+
async publish() {
|
|
795
|
+
ensureOpen(completed);
|
|
796
|
+
await publishDirectory(stagingDirectory, outputDirectory);
|
|
797
|
+
completed = true;
|
|
798
|
+
},
|
|
799
|
+
async discard() {
|
|
800
|
+
if (completed) return;
|
|
801
|
+
completed = true;
|
|
802
|
+
await rm(stagingDirectory, { force: true, recursive: true });
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
function ensureOpen(completed) {
|
|
807
|
+
if (completed) throw new Error("Build artifact writer is already closed.");
|
|
808
|
+
}
|
|
809
|
+
function resolveArtifactPath(directory, path12) {
|
|
810
|
+
return resolveWithinDirectory(directory, path12, "Build artifact path");
|
|
811
|
+
}
|
|
812
|
+
async function publishDirectory(stagingDirectory, outputDirectory) {
|
|
813
|
+
const backupDirectory = join2(
|
|
814
|
+
dirname2(outputDirectory),
|
|
815
|
+
".riebeckite",
|
|
816
|
+
`build-output-backup-${randomUUID()}`
|
|
817
|
+
);
|
|
818
|
+
const previousOutputExists = await isDirectory(outputDirectory);
|
|
819
|
+
let previousOutputMoved = false;
|
|
820
|
+
const journalPath = publicationJournalPath(outputDirectory);
|
|
821
|
+
await writeJournal(journalPath, {
|
|
822
|
+
backupDirectory,
|
|
823
|
+
outputDirectory,
|
|
824
|
+
stagingDirectory,
|
|
825
|
+
state: "staged"
|
|
826
|
+
});
|
|
827
|
+
try {
|
|
828
|
+
if (previousOutputExists) {
|
|
829
|
+
await moveWithRetry(outputDirectory, backupDirectory);
|
|
830
|
+
previousOutputMoved = true;
|
|
831
|
+
await writeJournal(journalPath, {
|
|
832
|
+
backupDirectory,
|
|
833
|
+
outputDirectory,
|
|
834
|
+
stagingDirectory,
|
|
835
|
+
state: "previous-output-moved"
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
await moveWithRetry(stagingDirectory, outputDirectory);
|
|
839
|
+
await writeJournal(journalPath, {
|
|
840
|
+
backupDirectory,
|
|
841
|
+
outputDirectory,
|
|
842
|
+
stagingDirectory,
|
|
843
|
+
state: "published"
|
|
844
|
+
});
|
|
845
|
+
} catch (error) {
|
|
846
|
+
if (previousOutputMoved) {
|
|
847
|
+
await rm(outputDirectory, { force: true, recursive: true });
|
|
848
|
+
await moveWithRetry(backupDirectory, outputDirectory);
|
|
849
|
+
}
|
|
850
|
+
await rm(journalPath, { force: true });
|
|
851
|
+
throw error;
|
|
852
|
+
}
|
|
853
|
+
await rm(backupDirectory, { force: true, recursive: true });
|
|
854
|
+
await rm(journalPath, { force: true });
|
|
855
|
+
}
|
|
856
|
+
function publicationJournalPath(outputDirectory) {
|
|
857
|
+
return join2(dirname2(outputDirectory), ".riebeckite", "build-output.json");
|
|
858
|
+
}
|
|
859
|
+
async function writeJournal(path12, journal) {
|
|
860
|
+
await mkdir(dirname2(path12), { recursive: true });
|
|
861
|
+
await writeFile(path12, JSON.stringify(journal));
|
|
862
|
+
}
|
|
863
|
+
async function recoverPendingPublication(outputDirectory) {
|
|
864
|
+
const path12 = publicationJournalPath(outputDirectory);
|
|
865
|
+
let journal;
|
|
866
|
+
try {
|
|
867
|
+
journal = JSON.parse(await readFile2(path12, "utf8"));
|
|
868
|
+
} catch (error) {
|
|
869
|
+
if (isNotFoundError2(error)) return;
|
|
870
|
+
await rm(path12, { force: true });
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
if (journal.outputDirectory !== outputDirectory || !isPublicationJournalState(journal.state)) {
|
|
874
|
+
await rm(path12, { force: true });
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
if (journal.state === "previous-output-moved" && !await isDirectory(outputDirectory) && await isDirectory(journal.backupDirectory)) {
|
|
878
|
+
await moveWithRetry(journal.backupDirectory, outputDirectory);
|
|
879
|
+
}
|
|
880
|
+
await rm(journal.backupDirectory, { force: true, recursive: true });
|
|
881
|
+
await rm(journal.stagingDirectory, { force: true, recursive: true });
|
|
882
|
+
await rm(path12, { force: true });
|
|
883
|
+
}
|
|
884
|
+
function isPublicationJournalState(value) {
|
|
885
|
+
return value === "staged" || value === "previous-output-moved" || value === "published";
|
|
886
|
+
}
|
|
887
|
+
async function isDirectory(path12) {
|
|
888
|
+
try {
|
|
889
|
+
return (await lstat(path12)).isDirectory();
|
|
890
|
+
} catch (error) {
|
|
891
|
+
if (isNotFoundError2(error)) return false;
|
|
892
|
+
throw error;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
async function moveWithRetry(source, destination) {
|
|
896
|
+
let error;
|
|
897
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
898
|
+
try {
|
|
899
|
+
await rename(source, destination);
|
|
900
|
+
return;
|
|
901
|
+
} catch (nextError) {
|
|
902
|
+
error = nextError;
|
|
903
|
+
if (!isRetryableRenameError(nextError) || attempt === 2) break;
|
|
904
|
+
await new Promise((resolve5) => setTimeout(resolve5, (attempt + 1) * 25));
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
throw error;
|
|
628
908
|
}
|
|
629
|
-
function
|
|
909
|
+
function isNotFoundError2(error) {
|
|
630
910
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
631
911
|
}
|
|
632
|
-
function
|
|
633
|
-
return
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (!relativePath || relativePath.includes("\0") || isAbsolutePath(relativePath)) {
|
|
637
|
-
throw new Error(`Invalid ${label}: ${relativePath}`);
|
|
638
|
-
}
|
|
639
|
-
const file = resolve(directory, relativePath);
|
|
640
|
-
const relativePathFromDirectory = relative(directory, file);
|
|
641
|
-
if (relativePathFromDirectory.startsWith("..") || relativePathFromDirectory === "" || isAbsolutePath(relativePathFromDirectory)) {
|
|
642
|
-
throw new Error(`Unsafe ${label}: ${relativePath}`);
|
|
643
|
-
}
|
|
644
|
-
return file;
|
|
912
|
+
function isRetryableRenameError(error) {
|
|
913
|
+
return typeof error === "object" && error !== null && "code" in error && ["EBUSY", "EPERM", "EACCES"].includes(
|
|
914
|
+
error.code
|
|
915
|
+
);
|
|
645
916
|
}
|
|
646
917
|
|
|
647
918
|
// src/ssg/build_output.ts
|
|
919
|
+
import { createHash as createHash2, randomUUID as randomUUID2 } from "node:crypto";
|
|
920
|
+
import { mkdir as mkdir2, readdir as readdir2, readFile as readFile3, rename as rename2, rm as rm2, stat } from "node:fs/promises";
|
|
921
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
648
922
|
var CLOUDFLARE_WORKER_ASSET_LIMIT = 25 * 1024 * 1024;
|
|
649
923
|
async function findOversizedAssets(directory, relativeDirectory = "") {
|
|
650
|
-
const entries = await
|
|
924
|
+
const entries = await readdir2(directory, { withFileTypes: true }).catch(
|
|
651
925
|
(error) => {
|
|
652
926
|
if (isMissingDirectoryError(error)) return [];
|
|
653
927
|
throw error;
|
|
@@ -655,16 +929,16 @@ async function findOversizedAssets(directory, relativeDirectory = "") {
|
|
|
655
929
|
);
|
|
656
930
|
const nestedAssets = await Promise.all(
|
|
657
931
|
entries.map(async (entry) => {
|
|
658
|
-
const
|
|
659
|
-
const relativePath =
|
|
932
|
+
const path12 = join3(directory, entry.name);
|
|
933
|
+
const relativePath = join3(relativeDirectory, entry.name).replaceAll(
|
|
660
934
|
"\\",
|
|
661
935
|
"/"
|
|
662
936
|
);
|
|
663
937
|
if (entry.isDirectory()) {
|
|
664
|
-
return findOversizedAssets(
|
|
938
|
+
return findOversizedAssets(path12, relativePath);
|
|
665
939
|
}
|
|
666
940
|
if (!entry.isFile()) return [];
|
|
667
|
-
const size = (await stat(
|
|
941
|
+
const size = (await stat(path12)).size;
|
|
668
942
|
return size > CLOUDFLARE_WORKER_ASSET_LIMIT ? [{ path: relativePath, size }] : [];
|
|
669
943
|
})
|
|
670
944
|
);
|
|
@@ -674,30 +948,30 @@ function formatBytes(bytes) {
|
|
|
674
948
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
|
|
675
949
|
}
|
|
676
950
|
async function emptyBuildOutputDirectory(outDir) {
|
|
677
|
-
const entries = await
|
|
951
|
+
const entries = await readdir2(outDir, { withFileTypes: true }).catch(
|
|
678
952
|
(error) => {
|
|
679
953
|
if (isMissingDirectoryError(error)) return [];
|
|
680
954
|
throw error;
|
|
681
955
|
}
|
|
682
956
|
);
|
|
683
957
|
for (const entry of entries) {
|
|
684
|
-
await
|
|
958
|
+
await rm2(join3(outDir, entry.name), { recursive: true, force: true });
|
|
685
959
|
}
|
|
686
960
|
}
|
|
687
961
|
async function preserveClientBuildArtifacts(outDir) {
|
|
688
962
|
const manifestPath = ".vite/manifest.json";
|
|
689
963
|
let manifestSource;
|
|
690
964
|
try {
|
|
691
|
-
manifestSource = await
|
|
965
|
+
manifestSource = await readFile3(join3(outDir, manifestPath), "utf8");
|
|
692
966
|
} catch (error) {
|
|
693
967
|
if (isNotFoundError(error)) return void 0;
|
|
694
968
|
throw error;
|
|
695
969
|
}
|
|
696
970
|
const paths = [manifestPath, ...collectClientAssetPaths(manifestSource)];
|
|
697
|
-
const stagingDirectory =
|
|
698
|
-
|
|
971
|
+
const stagingDirectory = join3(
|
|
972
|
+
dirname3(outDir),
|
|
699
973
|
".riebeckite",
|
|
700
|
-
`client-build-${
|
|
974
|
+
`client-build-${randomUUID2()}`
|
|
701
975
|
);
|
|
702
976
|
for (const relativePath of paths) {
|
|
703
977
|
const source = resolveBuildArtifactPath(outDir, relativePath);
|
|
@@ -705,13 +979,13 @@ async function preserveClientBuildArtifacts(outDir) {
|
|
|
705
979
|
stagingDirectory,
|
|
706
980
|
relativePath
|
|
707
981
|
);
|
|
708
|
-
await
|
|
709
|
-
await
|
|
982
|
+
await mkdir2(dirname3(destination), { recursive: true });
|
|
983
|
+
await rename2(source, destination);
|
|
710
984
|
}
|
|
711
985
|
return {
|
|
712
986
|
stagingDirectory,
|
|
713
987
|
paths,
|
|
714
|
-
manifestFingerprint:
|
|
988
|
+
manifestFingerprint: createHash2("sha256").update(manifestSource).digest("hex")
|
|
715
989
|
};
|
|
716
990
|
}
|
|
717
991
|
async function restoreClientBuildArtifacts(outDir, artifacts) {
|
|
@@ -722,16 +996,16 @@ async function restoreClientBuildArtifacts(outDir, artifacts) {
|
|
|
722
996
|
relativePath
|
|
723
997
|
);
|
|
724
998
|
const destination = resolveBuildArtifactPath(outDir, relativePath);
|
|
725
|
-
await
|
|
726
|
-
await
|
|
999
|
+
await mkdir2(dirname3(destination), { recursive: true });
|
|
1000
|
+
await rename2(source, destination);
|
|
727
1001
|
}
|
|
728
1002
|
}
|
|
729
1003
|
async function discardClientBuildArtifacts(artifacts) {
|
|
730
1004
|
if (!artifacts) return;
|
|
731
|
-
await
|
|
1005
|
+
await rm2(artifacts.stagingDirectory, { recursive: true, force: true });
|
|
732
1006
|
}
|
|
733
1007
|
async function collectBuildOutputPaths(directory, relativeDirectory = "") {
|
|
734
|
-
const entries = await
|
|
1008
|
+
const entries = await readdir2(directory, { withFileTypes: true }).catch(
|
|
735
1009
|
(error) => {
|
|
736
1010
|
if (isMissingDirectoryError(error)) return void 0;
|
|
737
1011
|
throw error;
|
|
@@ -740,14 +1014,14 @@ async function collectBuildOutputPaths(directory, relativeDirectory = "") {
|
|
|
740
1014
|
if (!entries) return [];
|
|
741
1015
|
const paths = [];
|
|
742
1016
|
for (const entry of entries) {
|
|
743
|
-
const relativePath =
|
|
1017
|
+
const relativePath = join3(relativeDirectory, entry.name).replaceAll(
|
|
744
1018
|
"\\",
|
|
745
1019
|
"/"
|
|
746
1020
|
);
|
|
747
1021
|
if (entry.isDirectory()) {
|
|
748
1022
|
paths.push(
|
|
749
1023
|
...await collectBuildOutputPaths(
|
|
750
|
-
|
|
1024
|
+
join3(directory, entry.name),
|
|
751
1025
|
relativePath
|
|
752
1026
|
)
|
|
753
1027
|
);
|
|
@@ -757,6 +1031,32 @@ async function collectBuildOutputPaths(directory, relativeDirectory = "") {
|
|
|
757
1031
|
}
|
|
758
1032
|
return paths.sort();
|
|
759
1033
|
}
|
|
1034
|
+
async function verifyClientBuildArtifacts(input) {
|
|
1035
|
+
const manifestPath = ".vite/manifest.json";
|
|
1036
|
+
let manifestSource;
|
|
1037
|
+
try {
|
|
1038
|
+
manifestSource = await readFile3(
|
|
1039
|
+
resolveBuildArtifactPath(input.outDir, manifestPath),
|
|
1040
|
+
"utf8"
|
|
1041
|
+
);
|
|
1042
|
+
} catch {
|
|
1043
|
+
return false;
|
|
1044
|
+
}
|
|
1045
|
+
const paths = [manifestPath, ...collectClientAssetPaths(manifestSource)];
|
|
1046
|
+
for (const relativePath of paths) {
|
|
1047
|
+
const expectedChecksum = input.expectedInventory[relativePath];
|
|
1048
|
+
if (!expectedChecksum) return false;
|
|
1049
|
+
try {
|
|
1050
|
+
const actualChecksum = createHash2("sha256").update(
|
|
1051
|
+
await readFile3(resolveBuildArtifactPath(input.outDir, relativePath))
|
|
1052
|
+
).digest("hex");
|
|
1053
|
+
if (actualChecksum !== expectedChecksum) return false;
|
|
1054
|
+
} catch {
|
|
1055
|
+
return false;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return true;
|
|
1059
|
+
}
|
|
760
1060
|
function collectClientAssetPaths(manifestSource) {
|
|
761
1061
|
let manifest;
|
|
762
1062
|
try {
|
|
@@ -786,7 +1086,7 @@ function addClientAssetPath(paths, value) {
|
|
|
786
1086
|
}
|
|
787
1087
|
function addClientAssetPaths(paths, value) {
|
|
788
1088
|
if (!Array.isArray(value)) return;
|
|
789
|
-
for (const
|
|
1089
|
+
for (const path12 of value) addClientAssetPath(paths, path12);
|
|
790
1090
|
}
|
|
791
1091
|
function resolveBuildArtifactPath(directory, relativePath) {
|
|
792
1092
|
return resolveWithinDirectory(
|
|
@@ -829,6 +1129,7 @@ function logGeneratedHtmlAssetDiagnostics(logger, pages) {
|
|
|
829
1129
|
}
|
|
830
1130
|
}
|
|
831
1131
|
function inspectGeneratedHtmlPages(module, pages, log) {
|
|
1132
|
+
const diagnostics = [];
|
|
832
1133
|
const plugins = module.config?.plugins ?? [];
|
|
833
1134
|
for (const plugin of plugins) {
|
|
834
1135
|
const inspector = plugin.inspectGeneratedHtml;
|
|
@@ -838,136 +1139,37 @@ function inspectGeneratedHtmlPages(module, pages, log) {
|
|
|
838
1139
|
const label = `[${plugin.name ?? "plugin"}] ${page.path}: ${diagnostic.message}`;
|
|
839
1140
|
if (diagnostic.severity === "info") log.info(label);
|
|
840
1141
|
else log.warn(label);
|
|
1142
|
+
diagnostics.push({
|
|
1143
|
+
code: diagnostic.code ?? "generated-html",
|
|
1144
|
+
severity: diagnostic.severity,
|
|
1145
|
+
message: diagnostic.message,
|
|
1146
|
+
pluginName: plugin.name,
|
|
1147
|
+
filePath: diagnostic.filePath ?? page.path
|
|
1148
|
+
});
|
|
841
1149
|
}
|
|
842
1150
|
}
|
|
843
1151
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
// src/ssg/inventory.ts
|
|
847
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
848
|
-
import { readdir as readdir2, readFile as readFile2 } from "node:fs/promises";
|
|
849
|
-
import { join as join2, relative as relative2 } from "node:path";
|
|
850
|
-
import { performance } from "node:perf_hooks";
|
|
851
|
-
var APP_FINGERPRINT_IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
852
|
-
"node_modules",
|
|
853
|
-
".riebeckite",
|
|
854
|
-
"dist"
|
|
855
|
-
]);
|
|
856
|
-
var APP_FINGERPRINT_CONFIG_FILES = [
|
|
857
|
-
"riebeckite.config.ts",
|
|
858
|
-
"riebeckite.config.mts",
|
|
859
|
-
"riebeckite.config.cts",
|
|
860
|
-
"riebeckite.config.js",
|
|
861
|
-
"riebeckite.config.mjs",
|
|
862
|
-
"riebeckite.config.cjs"
|
|
863
|
-
];
|
|
864
|
-
async function computeAppFingerprint(root, configFile) {
|
|
865
|
-
const files = [];
|
|
866
|
-
await collectAppFiles(join2(root, "app"), files);
|
|
867
|
-
if (configFile) files.push(configFile);
|
|
868
|
-
for (const name of APP_FINGERPRINT_CONFIG_FILES) {
|
|
869
|
-
files.push(join2(root, name));
|
|
870
|
-
}
|
|
871
|
-
files.sort();
|
|
872
|
-
const hash = createHash2("sha256");
|
|
873
|
-
for (const file of files) {
|
|
874
|
-
let content;
|
|
875
|
-
try {
|
|
876
|
-
content = await readFile2(file);
|
|
877
|
-
} catch {
|
|
878
|
-
continue;
|
|
879
|
-
}
|
|
880
|
-
hash.update(relative2(root, file).replaceAll("\\", "/"));
|
|
881
|
-
hash.update("\0");
|
|
882
|
-
hash.update(content);
|
|
883
|
-
hash.update("\0");
|
|
884
|
-
}
|
|
885
|
-
return hash.digest("hex");
|
|
886
|
-
}
|
|
887
|
-
async function fingerprintDirectory(directory) {
|
|
888
|
-
const inventory = await fingerprintOutputDirectory(directory);
|
|
889
|
-
const hash = createHash2("sha256");
|
|
890
|
-
for (const [path11, checksum] of Object.entries(inventory).sort(
|
|
891
|
-
([left], [right]) => left.localeCompare(right)
|
|
892
|
-
)) {
|
|
893
|
-
hash.update(path11).update("\0").update(checksum).update("\0");
|
|
894
|
-
}
|
|
895
|
-
return hash.digest("hex");
|
|
896
|
-
}
|
|
897
|
-
async function fingerprintOutputDirectory(directory, relativeDirectory = "", metrics) {
|
|
898
|
-
const entries = await readdir2(directory, { withFileTypes: true }).catch(
|
|
899
|
-
(error) => {
|
|
900
|
-
if (isMissingDirectoryError(error)) return void 0;
|
|
901
|
-
throw error;
|
|
902
|
-
}
|
|
903
|
-
);
|
|
904
|
-
if (!entries) return {};
|
|
905
|
-
const inventory = {};
|
|
906
|
-
for (const entry of entries) {
|
|
907
|
-
const file = join2(directory, entry.name);
|
|
908
|
-
const relativePath = join2(relativeDirectory, entry.name).replaceAll(
|
|
909
|
-
"\\",
|
|
910
|
-
"/"
|
|
911
|
-
);
|
|
912
|
-
if (entry.isDirectory()) {
|
|
913
|
-
Object.assign(
|
|
914
|
-
inventory,
|
|
915
|
-
await fingerprintOutputDirectory(file, relativePath, metrics)
|
|
916
|
-
);
|
|
917
|
-
continue;
|
|
918
|
-
}
|
|
919
|
-
if (entry.isFile()) {
|
|
920
|
-
const hashedAt = performance.now();
|
|
921
|
-
const content = await readFile2(file);
|
|
922
|
-
inventory[relativePath] = createHash2("sha256").update(content).digest("hex");
|
|
923
|
-
if (metrics) {
|
|
924
|
-
metrics.outputHashValidationDurationMs += performance.now() - hashedAt;
|
|
925
|
-
metrics.outputFilesHashed += 1;
|
|
926
|
-
metrics.outputBytesHashed += content.length;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
return inventory;
|
|
931
|
-
}
|
|
932
|
-
function inventoriesEqual(left, right) {
|
|
933
|
-
const leftPaths = Object.keys(left);
|
|
934
|
-
const rightPaths = Object.keys(right);
|
|
935
|
-
return leftPaths.length === rightPaths.length && leftPaths.every((path11) => left[path11] === right[path11]);
|
|
936
|
-
}
|
|
937
|
-
async function collectAppFiles(directory, files) {
|
|
938
|
-
const entries = await readdir2(directory, { withFileTypes: true }).catch(
|
|
939
|
-
() => void 0
|
|
940
|
-
);
|
|
941
|
-
if (!entries) return;
|
|
942
|
-
for (const entry of entries) {
|
|
943
|
-
const full = join2(directory, entry.name);
|
|
944
|
-
if (entry.isDirectory()) {
|
|
945
|
-
if (APP_FINGERPRINT_IGNORED_DIRECTORIES.has(entry.name)) continue;
|
|
946
|
-
await collectAppFiles(full, files);
|
|
947
|
-
} else if (entry.isFile()) {
|
|
948
|
-
files.push(full);
|
|
949
|
-
}
|
|
950
|
-
}
|
|
1152
|
+
return diagnostics;
|
|
951
1153
|
}
|
|
952
1154
|
|
|
953
1155
|
// src/ssg/output_cache.ts
|
|
954
|
-
import { createHash as createHash3, randomUUID as
|
|
1156
|
+
import { createHash as createHash3, randomUUID as randomUUID3 } from "node:crypto";
|
|
955
1157
|
import { createReadStream } from "node:fs";
|
|
956
1158
|
import {
|
|
957
|
-
copyFile,
|
|
958
|
-
lstat,
|
|
959
|
-
mkdir as
|
|
1159
|
+
copyFile as copyFile2,
|
|
1160
|
+
lstat as lstat2,
|
|
1161
|
+
mkdir as mkdir3,
|
|
960
1162
|
readdir as readdir3,
|
|
961
|
-
readFile as
|
|
962
|
-
rename as
|
|
963
|
-
rm as
|
|
964
|
-
writeFile as
|
|
1163
|
+
readFile as readFile4,
|
|
1164
|
+
rename as rename3,
|
|
1165
|
+
rm as rm3,
|
|
1166
|
+
writeFile as writeFile3
|
|
965
1167
|
} from "node:fs/promises";
|
|
966
|
-
import { dirname as
|
|
1168
|
+
import { dirname as dirname4, join as join4 } from "node:path";
|
|
967
1169
|
import { performance as performance3 } from "node:perf_hooks";
|
|
968
1170
|
|
|
969
1171
|
// src/ssg/runtime_metrics.ts
|
|
970
|
-
import { writeFile } from "node:fs/promises";
|
|
1172
|
+
import { writeFile as writeFile2 } from "node:fs/promises";
|
|
971
1173
|
import { performance as performance2 } from "node:perf_hooks";
|
|
972
1174
|
async function measure(timingsMs, name, fn) {
|
|
973
1175
|
if (!timingsMs) return await fn();
|
|
@@ -992,7 +1194,7 @@ function measureSync(timingsMs, name, fn) {
|
|
|
992
1194
|
async function writeSsgOutputMetrics(metrics) {
|
|
993
1195
|
const file = process.env.RIEBECKITE_SSG_METRICS_FILE;
|
|
994
1196
|
if (!file) return;
|
|
995
|
-
await
|
|
1197
|
+
await writeFile2(file, `${JSON.stringify(metrics)}
|
|
996
1198
|
`, "utf8");
|
|
997
1199
|
}
|
|
998
1200
|
|
|
@@ -1019,7 +1221,7 @@ function createNoChangeFastPathOutputMetrics() {
|
|
|
1019
1221
|
};
|
|
1020
1222
|
}
|
|
1021
1223
|
async function verifyNoChangeFastPath(input) {
|
|
1022
|
-
const outputCachePath =
|
|
1224
|
+
const outputCachePath = join4(
|
|
1023
1225
|
input.root,
|
|
1024
1226
|
".riebeckite",
|
|
1025
1227
|
"ssg-output-cache.json"
|
|
@@ -1054,13 +1256,13 @@ async function verifyNoChangeFastPath(input) {
|
|
|
1054
1256
|
}
|
|
1055
1257
|
return { used: true };
|
|
1056
1258
|
}
|
|
1057
|
-
async function
|
|
1259
|
+
async function loadOutputCacheMetadata(path12, timingsMs, log = () => {
|
|
1058
1260
|
}) {
|
|
1059
|
-
if (!await isSafeOutputCacheDirectory(
|
|
1261
|
+
if (!await isSafeOutputCacheDirectory(dirname4(path12))) {
|
|
1060
1262
|
log("SSG output cache directory is unsafe and will be ignored.");
|
|
1061
1263
|
return void 0;
|
|
1062
1264
|
}
|
|
1063
|
-
if (!await isRegularFile(
|
|
1265
|
+
if (!await isRegularFile(path12)) {
|
|
1064
1266
|
return void 0;
|
|
1065
1267
|
}
|
|
1066
1268
|
let raw;
|
|
@@ -1068,7 +1270,7 @@ async function loadOutputCache(path11, timingsMs, log = () => {
|
|
|
1068
1270
|
raw = await measure(
|
|
1069
1271
|
timingsMs,
|
|
1070
1272
|
"outputCacheRead",
|
|
1071
|
-
() =>
|
|
1273
|
+
() => readFile4(path12, "utf8")
|
|
1072
1274
|
);
|
|
1073
1275
|
} catch (error) {
|
|
1074
1276
|
if (isNotFoundError(error)) return void 0;
|
|
@@ -1090,28 +1292,30 @@ async function loadOutputCache(path11, timingsMs, log = () => {
|
|
|
1090
1292
|
log("SSG output cache uses an unsupported format and will be rebuilt.");
|
|
1091
1293
|
return void 0;
|
|
1092
1294
|
}
|
|
1295
|
+
return timingsMs ? { ...parsed, fileSizeBytes: Buffer.byteLength(raw) } : parsed;
|
|
1296
|
+
}
|
|
1297
|
+
async function validateOutputCache(cache, path12, timingsMs, log = () => {
|
|
1298
|
+
}) {
|
|
1093
1299
|
const entriesAreValid = await measure(
|
|
1094
1300
|
timingsMs,
|
|
1095
1301
|
"outputCacheEntriesValidate",
|
|
1096
|
-
() => validateOutputCacheEntries(
|
|
1302
|
+
() => validateOutputCacheEntries(path12, cache.outputs, timingsMs)
|
|
1097
1303
|
);
|
|
1098
|
-
if (
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
}
|
|
1102
|
-
return timingsMs ? { ...parsed, fileSizeBytes: Buffer.byteLength(raw) } : parsed;
|
|
1304
|
+
if (entriesAreValid) return true;
|
|
1305
|
+
log("SSG output cache entries are corrupted and will be rebuilt.");
|
|
1306
|
+
return false;
|
|
1103
1307
|
}
|
|
1104
|
-
async function saveOutputCache(
|
|
1105
|
-
const directory =
|
|
1106
|
-
await
|
|
1308
|
+
async function saveOutputCache(path12, state, outputDirectory, timingsMs) {
|
|
1309
|
+
const directory = dirname4(path12);
|
|
1310
|
+
await mkdir3(directory, { recursive: true });
|
|
1107
1311
|
if (!await isSafeOutputCacheDirectory(directory)) {
|
|
1108
1312
|
throw new Error(`Unsafe SSG output cache directory: ${directory}`);
|
|
1109
1313
|
}
|
|
1110
|
-
if (!await isSafeCacheFileTarget(
|
|
1111
|
-
throw new Error(`Unsafe SSG output cache file: ${
|
|
1314
|
+
if (!await isSafeCacheFileTarget(path12)) {
|
|
1315
|
+
throw new Error(`Unsafe SSG output cache file: ${path12}`);
|
|
1112
1316
|
}
|
|
1113
|
-
const entriesPath = outputCacheEntriesPath(
|
|
1114
|
-
const temporaryPath = `${
|
|
1317
|
+
const entriesPath = outputCacheEntriesPath(path12);
|
|
1318
|
+
const temporaryPath = `${path12}.${randomUUID3()}.tmp`;
|
|
1115
1319
|
try {
|
|
1116
1320
|
const outputs = await measure(
|
|
1117
1321
|
timingsMs,
|
|
@@ -1133,40 +1337,40 @@ async function saveOutputCache(path11, state, outputDirectory, timingsMs) {
|
|
|
1133
1337
|
await measure(
|
|
1134
1338
|
timingsMs,
|
|
1135
1339
|
"outputCacheWrite",
|
|
1136
|
-
() =>
|
|
1340
|
+
() => writeFile3(temporaryPath, serialized, "utf8")
|
|
1137
1341
|
);
|
|
1138
1342
|
await measure(
|
|
1139
1343
|
timingsMs,
|
|
1140
1344
|
"outputCacheRename",
|
|
1141
|
-
() => replaceFile(temporaryPath,
|
|
1345
|
+
() => replaceFile(temporaryPath, path12)
|
|
1142
1346
|
);
|
|
1143
1347
|
const checksum = createHash3("sha256").update(serialized).digest("hex");
|
|
1144
1348
|
if (state.finalOutputInventory && state.configFile) {
|
|
1145
1349
|
await saveFastPathCache(
|
|
1146
|
-
fastPathCachePath(
|
|
1350
|
+
fastPathCachePath(path12),
|
|
1147
1351
|
createFastPathCacheState(state, checksum),
|
|
1148
1352
|
timingsMs
|
|
1149
1353
|
);
|
|
1150
1354
|
}
|
|
1151
1355
|
await collectUnreferencedOutputCacheEntries(
|
|
1152
|
-
outputCacheEntriesPath(
|
|
1356
|
+
outputCacheEntriesPath(path12),
|
|
1153
1357
|
outputs,
|
|
1154
1358
|
timingsMs
|
|
1155
1359
|
);
|
|
1156
1360
|
return checksum;
|
|
1157
1361
|
} catch (error) {
|
|
1158
|
-
await
|
|
1362
|
+
await rm3(temporaryPath, { force: true }).catch(() => void 0);
|
|
1159
1363
|
throw error;
|
|
1160
1364
|
}
|
|
1161
1365
|
}
|
|
1162
1366
|
function isOutputCacheState(value) {
|
|
1163
1367
|
if (typeof value !== "object" || value === null) return false;
|
|
1164
1368
|
const candidate = value;
|
|
1165
|
-
return candidate.version === 4 && (candidate.appFingerprint === void 0 || typeof candidate.appFingerprint === "string") && (candidate.clientManifestFingerprint === void 0 || typeof candidate.clientManifestFingerprint === "string") && isOutputCacheEntries(candidate.outputs) && (candidate.finalOutputInventory === void 0 || isOutputInventory(candidate.finalOutputInventory)) && (candidate.publicDirectory === void 0 || typeof candidate.publicDirectory === "string") && (candidate.publicFingerprint === void 0 || typeof candidate.publicFingerprint === "string") && (candidate.configFile === void 0 || typeof candidate.configFile === "string");
|
|
1369
|
+
return candidate.version === 4 && (candidate.appFingerprint === void 0 || typeof candidate.appFingerprint === "string") && (candidate.bundleFingerprint === void 0 || typeof candidate.bundleFingerprint === "string") && (candidate.clientManifestFingerprint === void 0 || typeof candidate.clientManifestFingerprint === "string") && isOutputCacheEntries(candidate.outputs) && (candidate.finalOutputInventory === void 0 || isOutputInventory(candidate.finalOutputInventory)) && (candidate.publicDirectory === void 0 || typeof candidate.publicDirectory === "string") && (candidate.publicFingerprint === void 0 || typeof candidate.publicFingerprint === "string") && (candidate.configFile === void 0 || typeof candidate.configFile === "string");
|
|
1166
1370
|
}
|
|
1167
1371
|
function isOutputInventory(value) {
|
|
1168
1372
|
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.entries(value).every(
|
|
1169
|
-
([
|
|
1373
|
+
([outputPath, checksum]) => isSafeLogicalOutputPath(outputPath) && isChecksum(checksum)
|
|
1170
1374
|
);
|
|
1171
1375
|
}
|
|
1172
1376
|
function isOutputCacheEntries(value) {
|
|
@@ -1174,7 +1378,7 @@ function isOutputCacheEntries(value) {
|
|
|
1174
1378
|
return false;
|
|
1175
1379
|
}
|
|
1176
1380
|
return Object.entries(value).every(
|
|
1177
|
-
([
|
|
1381
|
+
([outputPath, entry]) => isSafeLogicalOutputPath(outputPath) && typeof entry === "object" && entry !== null && typeof entry.cachePath === "string" && entry.cachePath === outputCacheEntryName(outputPath) && isChecksum(entry.checksum)
|
|
1178
1382
|
);
|
|
1179
1383
|
}
|
|
1180
1384
|
function outputCacheEntriesPath(outputCachePath) {
|
|
@@ -1183,30 +1387,30 @@ function outputCacheEntriesPath(outputCachePath) {
|
|
|
1183
1387
|
async function saveOutputCacheEntries(directory, outputDirectory, outputs, finalOutputInventory, timingsMs) {
|
|
1184
1388
|
await ensureOutputCacheEntriesDirectory(directory);
|
|
1185
1389
|
const entries = {};
|
|
1186
|
-
for (const
|
|
1187
|
-
assertSafeLogicalOutputPath(
|
|
1188
|
-
const existing = outputs[
|
|
1390
|
+
for (const outputPath of Object.keys(outputs).sort()) {
|
|
1391
|
+
assertSafeLogicalOutputPath(outputPath);
|
|
1392
|
+
const existing = outputs[outputPath];
|
|
1189
1393
|
if (existing.cachePath && existing.checksum) {
|
|
1190
|
-
if (existing.cachePath !== outputCacheEntryName(
|
|
1191
|
-
throw new Error(`Invalid SSG output cache entry: ${
|
|
1394
|
+
if (existing.cachePath !== outputCacheEntryName(outputPath) || !isChecksum(existing.checksum)) {
|
|
1395
|
+
throw new Error(`Invalid SSG output cache entry: ${outputPath}`);
|
|
1192
1396
|
}
|
|
1193
|
-
entries[
|
|
1397
|
+
entries[outputPath] = existing;
|
|
1194
1398
|
continue;
|
|
1195
1399
|
}
|
|
1196
|
-
const source = resolveOutputCacheFile(outputDirectory,
|
|
1197
|
-
const cachePath = outputCacheEntryName(
|
|
1198
|
-
const destination =
|
|
1400
|
+
const source = resolveOutputCacheFile(outputDirectory, outputPath);
|
|
1401
|
+
const cachePath = outputCacheEntryName(outputPath);
|
|
1402
|
+
const destination = join4(directory, cachePath);
|
|
1199
1403
|
await replaceOutputCacheEntry(source, destination, timingsMs);
|
|
1200
|
-
const checksum = finalOutputInventory?.[
|
|
1404
|
+
const checksum = finalOutputInventory?.[outputPath];
|
|
1201
1405
|
if (!checksum) {
|
|
1202
1406
|
const cachedChecksum = await checksumFile(destination);
|
|
1203
1407
|
if (!cachedChecksum) {
|
|
1204
|
-
throw new Error(`Could not checksum cached output: ${
|
|
1408
|
+
throw new Error(`Could not checksum cached output: ${outputPath}`);
|
|
1205
1409
|
}
|
|
1206
|
-
entries[
|
|
1410
|
+
entries[outputPath] = { cachePath, checksum: cachedChecksum };
|
|
1207
1411
|
continue;
|
|
1208
1412
|
}
|
|
1209
|
-
entries[
|
|
1413
|
+
entries[outputPath] = { cachePath, checksum };
|
|
1210
1414
|
}
|
|
1211
1415
|
return entries;
|
|
1212
1416
|
}
|
|
@@ -1221,20 +1425,20 @@ async function validateOutputCacheEntries(outputCachePath, entries, timingsMs) {
|
|
|
1221
1425
|
while (valid) {
|
|
1222
1426
|
const next = entriesToValidate[nextEntryIndex++];
|
|
1223
1427
|
if (!next) return;
|
|
1224
|
-
const [
|
|
1225
|
-
if (!isSafeLogicalOutputPath(
|
|
1428
|
+
const [outputPath, entry] = next;
|
|
1429
|
+
if (!isSafeLogicalOutputPath(outputPath) || entry.cachePath !== outputCacheEntryName(outputPath) || !isChecksum(entry.checksum)) {
|
|
1226
1430
|
valid = false;
|
|
1227
1431
|
return;
|
|
1228
1432
|
}
|
|
1229
|
-
const
|
|
1230
|
-
if (!await isRegularFile(
|
|
1433
|
+
const path12 = resolveOutputCacheFile(directory, entry.cachePath);
|
|
1434
|
+
if (!await isRegularFile(path12)) {
|
|
1231
1435
|
valid = false;
|
|
1232
1436
|
return;
|
|
1233
1437
|
}
|
|
1234
1438
|
if (await measure(
|
|
1235
1439
|
timingsMs,
|
|
1236
1440
|
"outputCacheEntryChecksum",
|
|
1237
|
-
() => checksumFile(
|
|
1441
|
+
() => checksumFile(path12)
|
|
1238
1442
|
) !== entry.checksum)
|
|
1239
1443
|
valid = false;
|
|
1240
1444
|
}
|
|
@@ -1273,38 +1477,38 @@ function createFastPathCacheState(state, outputCacheChecksum) {
|
|
|
1273
1477
|
outputPaths: Object.keys(state.outputs).sort()
|
|
1274
1478
|
};
|
|
1275
1479
|
}
|
|
1276
|
-
async function saveFastPathCache(
|
|
1277
|
-
const directory =
|
|
1278
|
-
await
|
|
1480
|
+
async function saveFastPathCache(path12, state, timingsMs) {
|
|
1481
|
+
const directory = dirname4(path12);
|
|
1482
|
+
await mkdir3(directory, { recursive: true });
|
|
1279
1483
|
if (!await isSafeOutputCacheDirectory(directory)) {
|
|
1280
1484
|
throw new Error(`Unsafe SSG fast-path cache directory: ${directory}`);
|
|
1281
1485
|
}
|
|
1282
|
-
if (!await isSafeCacheFileTarget(
|
|
1283
|
-
throw new Error(`Unsafe SSG fast-path cache file: ${
|
|
1486
|
+
if (!await isSafeCacheFileTarget(path12)) {
|
|
1487
|
+
throw new Error(`Unsafe SSG fast-path cache file: ${path12}`);
|
|
1284
1488
|
}
|
|
1285
|
-
const temporaryPath = `${
|
|
1489
|
+
const temporaryPath = `${path12}.${randomUUID3()}.tmp`;
|
|
1286
1490
|
try {
|
|
1287
1491
|
await measure(
|
|
1288
1492
|
timingsMs,
|
|
1289
1493
|
"sidecarWrite",
|
|
1290
|
-
() =>
|
|
1494
|
+
() => writeFile3(temporaryPath, `${JSON.stringify(state)}
|
|
1291
1495
|
`, "utf8")
|
|
1292
1496
|
);
|
|
1293
1497
|
await measure(
|
|
1294
1498
|
timingsMs,
|
|
1295
1499
|
"sidecarRename",
|
|
1296
|
-
() => replaceFile(temporaryPath,
|
|
1500
|
+
() => replaceFile(temporaryPath, path12)
|
|
1297
1501
|
);
|
|
1298
1502
|
} catch (error) {
|
|
1299
|
-
await
|
|
1503
|
+
await rm3(temporaryPath, { force: true }).catch(() => void 0);
|
|
1300
1504
|
throw error;
|
|
1301
1505
|
}
|
|
1302
1506
|
}
|
|
1303
|
-
async function loadFastPathCache(
|
|
1507
|
+
async function loadFastPathCache(path12) {
|
|
1304
1508
|
try {
|
|
1305
|
-
if (!await isSafeOutputCacheDirectory(
|
|
1306
|
-
if (!await isRegularFile(
|
|
1307
|
-
const candidate = JSON.parse(await
|
|
1509
|
+
if (!await isSafeOutputCacheDirectory(dirname4(path12))) return void 0;
|
|
1510
|
+
if (!await isRegularFile(path12)) return void 0;
|
|
1511
|
+
const candidate = JSON.parse(await readFile4(path12, "utf8"));
|
|
1308
1512
|
return isFastPathCacheState(candidate) ? candidate : void 0;
|
|
1309
1513
|
} catch {
|
|
1310
1514
|
return void 0;
|
|
@@ -1314,13 +1518,13 @@ function isFastPathCacheState(value) {
|
|
|
1314
1518
|
if (typeof value !== "object" || value === null) return false;
|
|
1315
1519
|
const candidate = value;
|
|
1316
1520
|
return candidate.version === 1 && typeof candidate.outputCacheChecksum === "string" && (candidate.appFingerprint === void 0 || typeof candidate.appFingerprint === "string") && isOutputInventory(candidate.finalOutputInventory) && (candidate.publicDirectory === void 0 || typeof candidate.publicDirectory === "string") && (candidate.publicFingerprint === void 0 || typeof candidate.publicFingerprint === "string") && typeof candidate.configFile === "string" && Array.isArray(candidate.outputPaths) && candidate.outputPaths.every(isSafeLogicalOutputPath) && candidate.outputPaths.every(
|
|
1317
|
-
(
|
|
1521
|
+
(path12, index, paths) => index === 0 || paths[index - 1] < path12
|
|
1318
1522
|
);
|
|
1319
1523
|
}
|
|
1320
|
-
async function checksumFile(
|
|
1524
|
+
async function checksumFile(path12) {
|
|
1321
1525
|
const hash = createHash3("sha256");
|
|
1322
1526
|
try {
|
|
1323
|
-
for await (const chunk of createReadStream(
|
|
1527
|
+
for await (const chunk of createReadStream(path12)) hash.update(chunk);
|
|
1324
1528
|
return hash.digest("hex");
|
|
1325
1529
|
} catch {
|
|
1326
1530
|
return void 0;
|
|
@@ -1328,11 +1532,11 @@ async function checksumFile(path11) {
|
|
|
1328
1532
|
}
|
|
1329
1533
|
async function replaceFile(temporaryPath, targetPath) {
|
|
1330
1534
|
try {
|
|
1331
|
-
await
|
|
1535
|
+
await rename3(temporaryPath, targetPath);
|
|
1332
1536
|
} catch (error) {
|
|
1333
1537
|
if (!isReplacementFailure(error)) throw error;
|
|
1334
|
-
await
|
|
1335
|
-
await
|
|
1538
|
+
await rm3(targetPath, { force: true });
|
|
1539
|
+
await rename3(temporaryPath, targetPath);
|
|
1336
1540
|
}
|
|
1337
1541
|
}
|
|
1338
1542
|
function isReplacementFailure(error) {
|
|
@@ -1342,17 +1546,11 @@ function isReplacementFailure(error) {
|
|
|
1342
1546
|
const code = String(error.code);
|
|
1343
1547
|
return code === "EPERM" || code === "EEXIST" || code === "EACCES";
|
|
1344
1548
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1549
|
+
function resolveOutputCacheEntryPath(outputCachePath, entry) {
|
|
1550
|
+
return resolveOutputCacheFile(
|
|
1347
1551
|
outputCacheEntriesPath(outputCachePath),
|
|
1348
1552
|
entry.cachePath
|
|
1349
1553
|
);
|
|
1350
|
-
const content = await readFile3(file);
|
|
1351
|
-
const checksum = createHash3("sha256").update(content).digest("hex");
|
|
1352
|
-
if (checksum !== entry.checksum) {
|
|
1353
|
-
throw new Error("SSG output cache entry checksum mismatch.");
|
|
1354
|
-
}
|
|
1355
|
-
return content;
|
|
1356
1554
|
}
|
|
1357
1555
|
function resolveOutputCacheFile(directory, relativePath) {
|
|
1358
1556
|
return resolveWithinDirectory(
|
|
@@ -1361,45 +1559,45 @@ function resolveOutputCacheFile(directory, relativePath) {
|
|
|
1361
1559
|
"SSG output cache path"
|
|
1362
1560
|
);
|
|
1363
1561
|
}
|
|
1364
|
-
function isSafeLogicalOutputPath(
|
|
1365
|
-
if (typeof
|
|
1562
|
+
function isSafeLogicalOutputPath(path12) {
|
|
1563
|
+
if (typeof path12 !== "string" || !path12 || path12.includes("\\") || path12.includes("\0") || isAbsolutePath(path12)) {
|
|
1366
1564
|
return false;
|
|
1367
1565
|
}
|
|
1368
1566
|
try {
|
|
1369
|
-
resolveOutputCacheFile("/riebeckite-output-root",
|
|
1567
|
+
resolveOutputCacheFile("/riebeckite-output-root", path12);
|
|
1370
1568
|
return true;
|
|
1371
1569
|
} catch {
|
|
1372
1570
|
return false;
|
|
1373
1571
|
}
|
|
1374
1572
|
}
|
|
1375
|
-
function assertSafeLogicalOutputPath(
|
|
1376
|
-
if (!isSafeLogicalOutputPath(
|
|
1377
|
-
throw new Error(`Invalid SSG output path: ${
|
|
1573
|
+
function assertSafeLogicalOutputPath(path12) {
|
|
1574
|
+
if (!isSafeLogicalOutputPath(path12)) {
|
|
1575
|
+
throw new Error(`Invalid SSG output path: ${path12}`);
|
|
1378
1576
|
}
|
|
1379
1577
|
}
|
|
1380
|
-
function outputCacheEntryName(
|
|
1381
|
-
return createHash3("sha256").update(
|
|
1578
|
+
function outputCacheEntryName(outputPath) {
|
|
1579
|
+
return createHash3("sha256").update(outputPath).digest("hex");
|
|
1382
1580
|
}
|
|
1383
1581
|
function isChecksum(value) {
|
|
1384
1582
|
return typeof value === "string" && /^[a-f0-9]{64}$/u.test(value);
|
|
1385
1583
|
}
|
|
1386
1584
|
async function ensureOutputCacheEntriesDirectory(directory) {
|
|
1387
|
-
await
|
|
1585
|
+
await mkdir3(directory, { recursive: true });
|
|
1388
1586
|
if (!await isSafeOutputCacheEntriesDirectory(directory)) {
|
|
1389
1587
|
throw new Error(`Unsafe SSG output cache entries directory: ${directory}`);
|
|
1390
1588
|
}
|
|
1391
1589
|
}
|
|
1392
1590
|
async function isSafeOutputCacheDirectory(directory) {
|
|
1393
1591
|
try {
|
|
1394
|
-
const info = await
|
|
1592
|
+
const info = await lstat2(directory);
|
|
1395
1593
|
return info.isDirectory() && !info.isSymbolicLink();
|
|
1396
1594
|
} catch {
|
|
1397
1595
|
return false;
|
|
1398
1596
|
}
|
|
1399
1597
|
}
|
|
1400
|
-
async function isSafeCacheFileTarget(
|
|
1598
|
+
async function isSafeCacheFileTarget(path12) {
|
|
1401
1599
|
try {
|
|
1402
|
-
return !(await
|
|
1600
|
+
return !(await lstat2(path12)).isSymbolicLink();
|
|
1403
1601
|
} catch (error) {
|
|
1404
1602
|
return isNotFoundError(error);
|
|
1405
1603
|
}
|
|
@@ -1407,29 +1605,29 @@ async function isSafeCacheFileTarget(path11) {
|
|
|
1407
1605
|
async function isSafeOutputCacheEntriesDirectory(directory) {
|
|
1408
1606
|
return isSafeOutputCacheDirectory(directory);
|
|
1409
1607
|
}
|
|
1410
|
-
async function isRegularFile(
|
|
1608
|
+
async function isRegularFile(path12) {
|
|
1411
1609
|
try {
|
|
1412
|
-
const info = await
|
|
1610
|
+
const info = await lstat2(path12);
|
|
1413
1611
|
return info.isFile() && !info.isSymbolicLink();
|
|
1414
1612
|
} catch {
|
|
1415
1613
|
return false;
|
|
1416
1614
|
}
|
|
1417
1615
|
}
|
|
1418
1616
|
async function replaceOutputCacheEntry(source, destination, timingsMs) {
|
|
1419
|
-
if ((await
|
|
1617
|
+
if ((await lstat2(destination).catch(() => void 0))?.isSymbolicLink()) {
|
|
1420
1618
|
throw new Error(`Unsafe SSG output cache entry: ${destination}`);
|
|
1421
1619
|
}
|
|
1422
|
-
const temporaryPath = `${destination}.${
|
|
1620
|
+
const temporaryPath = `${destination}.${randomUUID3()}.tmp`;
|
|
1423
1621
|
try {
|
|
1424
1622
|
await measure(
|
|
1425
1623
|
timingsMs,
|
|
1426
1624
|
"outputCacheEntryWrite",
|
|
1427
|
-
() =>
|
|
1625
|
+
() => writeFile3(temporaryPath, new Uint8Array())
|
|
1428
1626
|
);
|
|
1429
1627
|
await measure(
|
|
1430
1628
|
timingsMs,
|
|
1431
1629
|
"outputCacheEntryCopy",
|
|
1432
|
-
() =>
|
|
1630
|
+
() => copyFile2(source, temporaryPath)
|
|
1433
1631
|
);
|
|
1434
1632
|
await measure(
|
|
1435
1633
|
timingsMs,
|
|
@@ -1437,7 +1635,7 @@ async function replaceOutputCacheEntry(source, destination, timingsMs) {
|
|
|
1437
1635
|
() => replaceFile(temporaryPath, destination)
|
|
1438
1636
|
);
|
|
1439
1637
|
} catch (error) {
|
|
1440
|
-
await
|
|
1638
|
+
await rm3(temporaryPath, { force: true }).catch(() => void 0);
|
|
1441
1639
|
throw error;
|
|
1442
1640
|
}
|
|
1443
1641
|
}
|
|
@@ -1456,12 +1654,12 @@ async function collectUnreferencedOutputCacheEntries(directory, outputs, timings
|
|
|
1456
1654
|
if (!/^[a-f0-9]{64}$/u.test(entry.name) || referenced.has(entry.name)) {
|
|
1457
1655
|
continue;
|
|
1458
1656
|
}
|
|
1459
|
-
const
|
|
1460
|
-
if (await isRegularFile(
|
|
1657
|
+
const path12 = join4(directory, entry.name);
|
|
1658
|
+
if (await isRegularFile(path12)) {
|
|
1461
1659
|
await measure(
|
|
1462
1660
|
timingsMs,
|
|
1463
1661
|
"outputCacheGcDelete",
|
|
1464
|
-
() =>
|
|
1662
|
+
() => rm3(path12, { force: true })
|
|
1465
1663
|
);
|
|
1466
1664
|
}
|
|
1467
1665
|
}
|
|
@@ -1470,6 +1668,118 @@ async function collectUnreferencedOutputCacheEntries(directory, outputs, timings
|
|
|
1470
1668
|
}
|
|
1471
1669
|
}
|
|
1472
1670
|
|
|
1671
|
+
// src/ssg/runner.ts
|
|
1672
|
+
import { defaultExtensionMap, redirectPlugin, toSSG } from "hono/ssg";
|
|
1673
|
+
async function runSsg(options) {
|
|
1674
|
+
return await withSsgRenderEnvironment(
|
|
1675
|
+
options.incremental,
|
|
1676
|
+
() => toSSG(
|
|
1677
|
+
options.app,
|
|
1678
|
+
{
|
|
1679
|
+
writeFile: options.write,
|
|
1680
|
+
mkdir: async () => {
|
|
1681
|
+
}
|
|
1682
|
+
},
|
|
1683
|
+
{
|
|
1684
|
+
dir: options.outDir,
|
|
1685
|
+
plugins: [redirectPlugin(), ...options.plugins ?? []],
|
|
1686
|
+
extensionMap: options.extensionMap ?? defaultExtensionMap
|
|
1687
|
+
}
|
|
1688
|
+
)
|
|
1689
|
+
);
|
|
1690
|
+
}
|
|
1691
|
+
async function withSsgRenderEnvironment(incremental, operation) {
|
|
1692
|
+
const previousFullRegeneration = process.env.RIEBECKITE_SSG_FULL_REGENERATION;
|
|
1693
|
+
const previousSkipUnchanged = process.env.RIEBECKITE_SSG_SKIP_UNCHANGED;
|
|
1694
|
+
process.env.RIEBECKITE_SSG_FULL_REGENERATION = incremental ? "" : "1";
|
|
1695
|
+
process.env.RIEBECKITE_SSG_SKIP_UNCHANGED = incremental ? "1" : "";
|
|
1696
|
+
try {
|
|
1697
|
+
return await operation();
|
|
1698
|
+
} finally {
|
|
1699
|
+
restoreEnvironmentVariable(
|
|
1700
|
+
"RIEBECKITE_SSG_FULL_REGENERATION",
|
|
1701
|
+
previousFullRegeneration
|
|
1702
|
+
);
|
|
1703
|
+
restoreEnvironmentVariable(
|
|
1704
|
+
"RIEBECKITE_SSG_SKIP_UNCHANGED",
|
|
1705
|
+
previousSkipUnchanged
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
function restoreEnvironmentVariable(name, value) {
|
|
1710
|
+
if (value === void 0) delete process.env[name];
|
|
1711
|
+
else process.env[name] = value;
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
// src/ssg/standalone.ts
|
|
1715
|
+
import { mkdir as mkdir4 } from "node:fs/promises";
|
|
1716
|
+
import { relative as relative3, resolve as resolve3 } from "node:path";
|
|
1717
|
+
import { pathToFileURL } from "node:url";
|
|
1718
|
+
import { build } from "vite";
|
|
1719
|
+
var standaloneSsgMode = "riebeckite-ssr";
|
|
1720
|
+
async function loadStandaloneSsgBundle(input) {
|
|
1721
|
+
const root = resolve3(input.root);
|
|
1722
|
+
const outputDirectory = resolve3(input.outputDirectory);
|
|
1723
|
+
await mkdir4(outputDirectory, { recursive: true });
|
|
1724
|
+
await build({
|
|
1725
|
+
root,
|
|
1726
|
+
configFile: input.config ? false : void 0,
|
|
1727
|
+
mode: standaloneSsgMode,
|
|
1728
|
+
...input.config ? {
|
|
1729
|
+
define: input.config.define,
|
|
1730
|
+
oxc: input.config.oxc,
|
|
1731
|
+
plugins: [
|
|
1732
|
+
...input.config.plugins.filter(
|
|
1733
|
+
(plugin) => plugin.name !== "riebeckite-ssg" && plugin.name !== "riebeckite-ssr-externals" && !plugin.name.startsWith("@hono/vite-build/")
|
|
1734
|
+
),
|
|
1735
|
+
createRuntimeExternalPlugin(),
|
|
1736
|
+
...input.clientOutputDirectory ? [createClientManifestPlugin(root, input.clientOutputDirectory)] : []
|
|
1737
|
+
],
|
|
1738
|
+
resolve: {
|
|
1739
|
+
...input.config.resolve,
|
|
1740
|
+
external: []
|
|
1741
|
+
}
|
|
1742
|
+
} : {},
|
|
1743
|
+
build: {
|
|
1744
|
+
emptyOutDir: false,
|
|
1745
|
+
outDir: outputDirectory,
|
|
1746
|
+
ssr: true,
|
|
1747
|
+
rollupOptions: {
|
|
1748
|
+
input: input.entry,
|
|
1749
|
+
output: { entryFileNames: "ssg-server.mjs", format: "es" }
|
|
1750
|
+
}
|
|
1751
|
+
},
|
|
1752
|
+
environments: { ssr: { resolve: { noExternal: true } } }
|
|
1753
|
+
});
|
|
1754
|
+
const module = await import(`${pathToFileURL(resolve3(outputDirectory, "ssg-server.mjs")).href}?v=${Date.now()}`);
|
|
1755
|
+
if (!module.default) {
|
|
1756
|
+
throw new Error(`Failed to find a default export from ${input.entry}.`);
|
|
1757
|
+
}
|
|
1758
|
+
return { app: module.default, module };
|
|
1759
|
+
}
|
|
1760
|
+
var runtimeExternalPackages = /* @__PURE__ */ new Set(["@d2lang/d2", "@marp-team/marp-core"]);
|
|
1761
|
+
function createRuntimeExternalPlugin() {
|
|
1762
|
+
return {
|
|
1763
|
+
name: "riebeckite-ssg-runtime-externals",
|
|
1764
|
+
enforce: "pre",
|
|
1765
|
+
async resolveId(source, importer) {
|
|
1766
|
+
if (!runtimeExternalPackages.has(source)) return void 0;
|
|
1767
|
+
const resolved = await this.resolve(source, importer, { skipSelf: true });
|
|
1768
|
+
return resolved ? { id: pathToFileURL(resolved.id).href, external: true } : void 0;
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
function createClientManifestPlugin(root, clientOutputDirectory) {
|
|
1773
|
+
const manifestPath = `/${relative3(root, clientOutputDirectory).replaceAll("\\", "/")}/.vite/manifest.json`;
|
|
1774
|
+
return {
|
|
1775
|
+
name: "riebeckite-client-manifest",
|
|
1776
|
+
enforce: "pre",
|
|
1777
|
+
transform(code, id) {
|
|
1778
|
+
return id.includes("honox/dist/server/components/") ? code.replaceAll("/dist/.vite/manifest.json", manifestPath) : void 0;
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1473
1783
|
// src/ssg_plugin.ts
|
|
1474
1784
|
var defaultEntry = "./src/index.tsx";
|
|
1475
1785
|
function riebeckiteSsg(options = {}) {
|
|
@@ -1477,34 +1787,60 @@ function riebeckiteSsg(options = {}) {
|
|
|
1477
1787
|
const resolvedVirtualId = `\0${virtualId}`;
|
|
1478
1788
|
const entry = options.entry ?? defaultEntry;
|
|
1479
1789
|
let resolvedConfig;
|
|
1790
|
+
let publicationOutputDirectory;
|
|
1791
|
+
let clientOutputDirectory;
|
|
1792
|
+
let artifactWriter;
|
|
1480
1793
|
let pendingOutputCache;
|
|
1481
1794
|
let clientBuildArtifacts;
|
|
1482
1795
|
return {
|
|
1483
1796
|
name: "riebeckite-ssg",
|
|
1484
|
-
apply:
|
|
1797
|
+
apply: (_config, env) => env.command === "build",
|
|
1485
1798
|
enforce: "post",
|
|
1486
|
-
config() {
|
|
1799
|
+
config(config, env) {
|
|
1800
|
+
const root = resolve4(config.root ?? process.cwd());
|
|
1801
|
+
publicationOutputDirectory = resolve4(
|
|
1802
|
+
root,
|
|
1803
|
+
config.build?.outDir ?? "dist"
|
|
1804
|
+
);
|
|
1805
|
+
clientOutputDirectory = join5(root, ".riebeckite", "build-output-client");
|
|
1487
1806
|
return {
|
|
1488
1807
|
build: {
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
}
|
|
1808
|
+
outDir: env.mode === "client" ? clientOutputDirectory : join5(root, ".riebeckite", "build-output"),
|
|
1809
|
+
...env.mode === "client" ? {} : { rollupOptions: { input: [virtualId] } }
|
|
1492
1810
|
}
|
|
1493
1811
|
};
|
|
1494
1812
|
},
|
|
1495
1813
|
configResolved(config) {
|
|
1496
1814
|
resolvedConfig = config;
|
|
1815
|
+
if (config.mode === "client") {
|
|
1816
|
+
clientOutputDirectory = resolve4(config.root, config.build.outDir);
|
|
1817
|
+
}
|
|
1497
1818
|
},
|
|
1498
1819
|
async buildStart() {
|
|
1499
1820
|
const config = resolvedConfig;
|
|
1500
|
-
if (!config) return;
|
|
1501
|
-
if (!
|
|
1502
|
-
|
|
1503
|
-
|
|
1821
|
+
if (!config || config.mode === "client") return;
|
|
1822
|
+
if (!publicationOutputDirectory) {
|
|
1823
|
+
throw new Error(
|
|
1824
|
+
"Riebeckite SSG could not resolve the publication output directory."
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
artifactWriter = await createBuildArtifactWriter({
|
|
1828
|
+
outputDirectory: publicationOutputDirectory,
|
|
1829
|
+
stagingDirectory: resolve4(config.root, config.build.outDir)
|
|
1830
|
+
});
|
|
1831
|
+
const outDir = resolve4(config.root, config.build.outDir);
|
|
1832
|
+
clientBuildArtifacts = clientOutputDirectory ? await preserveClientBuildArtifacts(clientOutputDirectory) : void 0;
|
|
1833
|
+
if (!clientBuildArtifacts) {
|
|
1834
|
+
clientBuildArtifacts = await preserveClientBuildArtifacts(
|
|
1835
|
+
publicationOutputDirectory
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1838
|
+
if (!clientBuildArtifacts) {
|
|
1839
|
+
if (await isDirectory2(publicationOutputDirectory)) {
|
|
1840
|
+
await artifactWriter.copyFrom(publicationOutputDirectory);
|
|
1841
|
+
}
|
|
1504
1842
|
return;
|
|
1505
1843
|
}
|
|
1506
|
-
const outDir = resolve2(config.root, config.build.outDir);
|
|
1507
|
-
clientBuildArtifacts = await preserveClientBuildArtifacts(outDir);
|
|
1508
1844
|
logSsgDiagnostics(
|
|
1509
1845
|
this,
|
|
1510
1846
|
`client manifest ${clientBuildArtifacts ? `preserved (${clientBuildArtifacts.paths.length} files)` : "not found"}`
|
|
@@ -1519,42 +1855,20 @@ function riebeckiteSsg(options = {}) {
|
|
|
1519
1855
|
},
|
|
1520
1856
|
async generateBundle(_outputOptions, bundle) {
|
|
1521
1857
|
const config = resolvedConfig;
|
|
1858
|
+
if (config?.mode === "client") return;
|
|
1522
1859
|
if (!config) {
|
|
1523
1860
|
throw new Error(
|
|
1524
1861
|
"Riebeckite SSG could not resolve the Vite configuration."
|
|
1525
1862
|
);
|
|
1526
1863
|
}
|
|
1527
1864
|
const timingsMs = process.env.RIEBECKITE_SSG_METRICS_FILE ? {} : void 0;
|
|
1528
|
-
const outDir =
|
|
1865
|
+
const outDir = resolve4(config.root, config.build.outDir);
|
|
1529
1866
|
let viteClientAssetPaths = [];
|
|
1530
1867
|
removeVirtualEntryChunk(bundle, resolvedVirtualId);
|
|
1531
|
-
const
|
|
1532
|
-
|
|
1533
|
-
"
|
|
1534
|
-
()
|
|
1535
|
-
root: config.root,
|
|
1536
|
-
define: config.define,
|
|
1537
|
-
resolve: {
|
|
1538
|
-
...config.resolve,
|
|
1539
|
-
builtins: [...config.resolve.builtins, /^node:/]
|
|
1540
|
-
},
|
|
1541
|
-
plugins: [
|
|
1542
|
-
{
|
|
1543
|
-
name: "riebeckite-ssg-package-resolution",
|
|
1544
|
-
enforce: "post",
|
|
1545
|
-
configResolved(runtimeConfig) {
|
|
1546
|
-
runtimeConfig.resolve.alias = [];
|
|
1547
|
-
}
|
|
1548
|
-
}
|
|
1549
|
-
],
|
|
1550
|
-
build: { ssr: true },
|
|
1551
|
-
oxc: { jsx: { runtime: "automatic", importSource: "hono/jsx" } },
|
|
1552
|
-
environments: {
|
|
1553
|
-
ssr: { resolve: { noExternal: [/^honox(?:\/.*)?$/] } }
|
|
1554
|
-
},
|
|
1555
|
-
mode: config.mode,
|
|
1556
|
-
server: { watch: null }
|
|
1557
|
-
})
|
|
1868
|
+
const bundleDirectory = join5(
|
|
1869
|
+
config.root,
|
|
1870
|
+
".riebeckite",
|
|
1871
|
+
`ssg-bundle-${randomUUID4()}`
|
|
1558
1872
|
);
|
|
1559
1873
|
try {
|
|
1560
1874
|
await restoreClientBuildArtifacts(outDir, clientBuildArtifacts);
|
|
@@ -1563,15 +1877,17 @@ function riebeckiteSsg(options = {}) {
|
|
|
1563
1877
|
this,
|
|
1564
1878
|
`SSR noExternal=${formatSsrNoExternal()} · client manifest ${clientBuildArtifacts ? "restored" : "not found"}`
|
|
1565
1879
|
);
|
|
1566
|
-
const module = await measure(
|
|
1880
|
+
const { app, module } = await measure(
|
|
1567
1881
|
timingsMs,
|
|
1568
1882
|
"ssrModuleLoad",
|
|
1569
|
-
() =>
|
|
1883
|
+
() => loadStandaloneSsgBundle({
|
|
1884
|
+
root: config.root,
|
|
1885
|
+
entry,
|
|
1886
|
+
outputDirectory: bundleDirectory,
|
|
1887
|
+
clientOutputDirectory: outDir,
|
|
1888
|
+
config
|
|
1889
|
+
})
|
|
1570
1890
|
);
|
|
1571
|
-
const app = module.default;
|
|
1572
|
-
if (!app) {
|
|
1573
|
-
throw new Error(`Failed to find a default export from ${entry}.`);
|
|
1574
|
-
}
|
|
1575
1891
|
const outputChangeSet = await measure(
|
|
1576
1892
|
timingsMs,
|
|
1577
1893
|
"outputDependencyResolution",
|
|
@@ -1582,12 +1898,17 @@ function riebeckiteSsg(options = {}) {
|
|
|
1582
1898
|
"appFingerprint",
|
|
1583
1899
|
() => computeAppFingerprint(config.root, config.configFile)
|
|
1584
1900
|
);
|
|
1585
|
-
const
|
|
1901
|
+
const bundleFingerprint = await measure(
|
|
1902
|
+
timingsMs,
|
|
1903
|
+
"bundleFingerprint",
|
|
1904
|
+
() => computeBundleFingerprint(config.root, config.configFile)
|
|
1905
|
+
);
|
|
1906
|
+
const outputCachePath = join5(
|
|
1586
1907
|
config.root,
|
|
1587
1908
|
".riebeckite",
|
|
1588
1909
|
"ssg-output-cache.json"
|
|
1589
1910
|
);
|
|
1590
|
-
|
|
1911
|
+
let previousOutputCache = await loadOutputCacheMetadata(
|
|
1591
1912
|
outputCachePath,
|
|
1592
1913
|
timingsMs,
|
|
1593
1914
|
(message) => this.warn(message)
|
|
@@ -1599,7 +1920,7 @@ function riebeckiteSsg(options = {}) {
|
|
|
1599
1920
|
);
|
|
1600
1921
|
viteClientAssetPaths = [
|
|
1601
1922
|
.../* @__PURE__ */ new Set([...viteClientAssetPaths, ...Object.keys(bundle)])
|
|
1602
|
-
].filter((
|
|
1923
|
+
].filter((outputPath) => !siteOwnedOutputPaths.has(outputPath)).sort();
|
|
1603
1924
|
const siteOutputCollisions = findBuildOutputSiteCollisions(
|
|
1604
1925
|
Object.keys(bundle),
|
|
1605
1926
|
siteOwnedOutputPaths
|
|
@@ -1612,7 +1933,7 @@ function riebeckiteSsg(options = {}) {
|
|
|
1612
1933
|
const uncoveredUnchangedCount = outputChangeSet ? outputChangeSet.unchanged.filter(
|
|
1613
1934
|
(output) => !siteOwnedOutputPaths.has(output.path) && !previousOutputCache?.outputs[output.path]
|
|
1614
1935
|
).length : 0;
|
|
1615
|
-
|
|
1936
|
+
let outputCacheDecision = {
|
|
1616
1937
|
changeSetPresent: outputChangeSet !== void 0,
|
|
1617
1938
|
changeSetRequiresFullRegeneration: outputChangeSet?.fullRegenerationRequired ?? true,
|
|
1618
1939
|
outputCacheLoaded: previousOutputCache !== void 0,
|
|
@@ -1620,7 +1941,20 @@ function riebeckiteSsg(options = {}) {
|
|
|
1620
1941
|
clientManifestFingerprintMatch: previousOutputCache?.clientManifestFingerprint === clientBuildArtifacts?.manifestFingerprint,
|
|
1621
1942
|
uncoveredUnchangedCount
|
|
1622
1943
|
};
|
|
1623
|
-
|
|
1944
|
+
let outputCacheRejectionReason = decideOutputCacheRejection(outputCacheDecision);
|
|
1945
|
+
if (outputCacheRejectionReason === void 0 && previousOutputCache && !await validateOutputCache(
|
|
1946
|
+
previousOutputCache,
|
|
1947
|
+
outputCachePath,
|
|
1948
|
+
timingsMs,
|
|
1949
|
+
(message) => this.warn(message)
|
|
1950
|
+
)) {
|
|
1951
|
+
previousOutputCache = void 0;
|
|
1952
|
+
outputCacheDecision = {
|
|
1953
|
+
...outputCacheDecision,
|
|
1954
|
+
outputCacheLoaded: false
|
|
1955
|
+
};
|
|
1956
|
+
outputCacheRejectionReason = decideOutputCacheRejection(outputCacheDecision);
|
|
1957
|
+
}
|
|
1624
1958
|
const canUseIncremental = outputCacheRejectionReason === void 0;
|
|
1625
1959
|
const reusablePaths = new Set(
|
|
1626
1960
|
canUseIncremental ? (outputChangeSet?.unchanged ?? []).map((output) => output.path) : []
|
|
@@ -1643,6 +1977,7 @@ function riebeckiteSsg(options = {}) {
|
|
|
1643
1977
|
const nextOutputCache = {
|
|
1644
1978
|
version: 4,
|
|
1645
1979
|
appFingerprint,
|
|
1980
|
+
bundleFingerprint,
|
|
1646
1981
|
clientManifestFingerprint: clientBuildArtifacts?.manifestFingerprint,
|
|
1647
1982
|
outputs: {},
|
|
1648
1983
|
configFile: config.configFile
|
|
@@ -1691,64 +2026,54 @@ function riebeckiteSsg(options = {}) {
|
|
|
1691
2026
|
outputCacheRejectionReason: outputCacheRejectionReason ?? null,
|
|
1692
2027
|
timingsMs: timingsMs ?? {}
|
|
1693
2028
|
};
|
|
1694
|
-
process.env.RIEBECKITE_SSG_FULL_REGENERATION = canUseIncremental ? "" : "1";
|
|
1695
|
-
process.env.RIEBECKITE_SSG_SKIP_UNCHANGED = canUseIncremental ? "1" : "";
|
|
1696
2029
|
const result = await measure(
|
|
1697
2030
|
timingsMs,
|
|
1698
2031
|
"toSSG",
|
|
1699
|
-
() =>
|
|
2032
|
+
() => runSsg({
|
|
1700
2033
|
app,
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
"
|
|
1728
|
-
() => this.emitFile({
|
|
1729
|
-
type: "asset",
|
|
1730
|
-
fileName,
|
|
1731
|
-
source: data
|
|
1732
|
-
})
|
|
2034
|
+
outDir,
|
|
2035
|
+
incremental: canUseIncremental,
|
|
2036
|
+
plugins: options.plugins,
|
|
2037
|
+
extensionMap: options.extensionMap,
|
|
2038
|
+
write: async (filePath, data) => {
|
|
2039
|
+
const fileName = relative4(outDir, filePath).replaceAll("\\", "/");
|
|
2040
|
+
if (!inventoryPaths.has(fileName)) {
|
|
2041
|
+
honoStaticRoutePaths.add(fileName);
|
|
2042
|
+
}
|
|
2043
|
+
if (siteOwnedOutputPaths.has(fileName)) {
|
|
2044
|
+
shadowedOutputs.add(fileName);
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
if (canUseIncremental && reusablePaths.has(fileName)) {
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
if (fileName.endsWith(".html") && typeof data === "string") {
|
|
2051
|
+
metrics.renderedOutputCount += 1;
|
|
2052
|
+
metrics.renderedRouteCount += 1;
|
|
2053
|
+
metrics.htmlOutputCount += 1;
|
|
2054
|
+
generatedHtml.push({ path: fileName, html: data });
|
|
2055
|
+
} else {
|
|
2056
|
+
metrics.assetOutputCount += 1;
|
|
2057
|
+
}
|
|
2058
|
+
if (!artifactWriter) {
|
|
2059
|
+
throw new Error(
|
|
2060
|
+
"Riebeckite SSG artifact writer was not initialized."
|
|
1733
2061
|
);
|
|
1734
|
-
metrics.emittedOutputCount += 1;
|
|
1735
|
-
nextOutputCache.outputs[fileName] = {
|
|
1736
|
-
cachePath: "",
|
|
1737
|
-
checksum: ""
|
|
1738
|
-
};
|
|
1739
|
-
},
|
|
1740
|
-
async mkdir() {
|
|
1741
2062
|
}
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
2063
|
+
const writer = artifactWriter;
|
|
2064
|
+
await measure(
|
|
2065
|
+
timingsMs,
|
|
2066
|
+
"outputWrite",
|
|
2067
|
+
() => writer.write(fileName, data)
|
|
2068
|
+
);
|
|
2069
|
+
metrics.emittedOutputCount += 1;
|
|
2070
|
+
nextOutputCache.outputs[fileName] = {
|
|
2071
|
+
cachePath: "",
|
|
2072
|
+
checksum: ""
|
|
2073
|
+
};
|
|
1747
2074
|
}
|
|
1748
|
-
)
|
|
2075
|
+
})
|
|
1749
2076
|
);
|
|
1750
|
-
delete process.env.RIEBECKITE_SSG_FULL_REGENERATION;
|
|
1751
|
-
delete process.env.RIEBECKITE_SSG_SKIP_UNCHANGED;
|
|
1752
2077
|
metrics.enumeratedRouteCount = result.files.length;
|
|
1753
2078
|
if (!result.success) throw result.error;
|
|
1754
2079
|
metrics.processedContentCount = module.content?.getProcessedContentCount() ?? 0;
|
|
@@ -1765,11 +2090,17 @@ function riebeckiteSsg(options = {}) {
|
|
|
1765
2090
|
"generatedOutputs",
|
|
1766
2091
|
() => emitGeneratedOutputs(
|
|
1767
2092
|
module,
|
|
1768
|
-
(asset) => {
|
|
1769
|
-
|
|
2093
|
+
async (asset) => {
|
|
2094
|
+
if (!artifactWriter) {
|
|
2095
|
+
throw new Error(
|
|
2096
|
+
"Riebeckite SSG artifact writer was not initialized."
|
|
2097
|
+
);
|
|
2098
|
+
}
|
|
2099
|
+
const writer = artifactWriter;
|
|
2100
|
+
await measure(
|
|
1770
2101
|
timingsMs,
|
|
1771
2102
|
"outputWrite",
|
|
1772
|
-
() =>
|
|
2103
|
+
() => writer.write(asset.fileName, asset.source)
|
|
1773
2104
|
);
|
|
1774
2105
|
metrics.emittedOutputCount += 1;
|
|
1775
2106
|
nextOutputCache.outputs[asset.fileName] = {
|
|
@@ -1781,7 +2112,7 @@ function riebeckiteSsg(options = {}) {
|
|
|
1781
2112
|
(outputChangeSet?.affected ?? []).filter((output) => output.kind === "generated").map((output) => output.path)
|
|
1782
2113
|
) : void 0,
|
|
1783
2114
|
siteOwnedOutputPaths,
|
|
1784
|
-
(
|
|
2115
|
+
(path12) => shadowedOutputs.add(path12)
|
|
1785
2116
|
)
|
|
1786
2117
|
);
|
|
1787
2118
|
if (!outputChangeSet)
|
|
@@ -1789,30 +2120,42 @@ function riebeckiteSsg(options = {}) {
|
|
|
1789
2120
|
if (canUseIncremental && outputChangeSet && previousOutputCache) {
|
|
1790
2121
|
await measure(timingsMs, "unchangedOutputReuse", async () => {
|
|
1791
2122
|
for (const output of outputChangeSet.unchanged) {
|
|
1792
|
-
const
|
|
1793
|
-
if (siteOwnedOutputPaths.has(
|
|
1794
|
-
shadowedOutputs.add(
|
|
2123
|
+
const path12 = output.path;
|
|
2124
|
+
if (siteOwnedOutputPaths.has(path12)) {
|
|
2125
|
+
shadowedOutputs.add(path12);
|
|
1795
2126
|
continue;
|
|
1796
2127
|
}
|
|
1797
|
-
const cached = previousOutputCache.outputs[
|
|
2128
|
+
const cached = previousOutputCache.outputs[path12];
|
|
1798
2129
|
if (!cached) continue;
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
}
|
|
2130
|
+
if (!artifactWriter) {
|
|
2131
|
+
throw new Error(
|
|
2132
|
+
"Riebeckite SSG artifact writer was not initialized."
|
|
2133
|
+
);
|
|
2134
|
+
}
|
|
2135
|
+
const writer = artifactWriter;
|
|
2136
|
+
await measure(
|
|
2137
|
+
timingsMs,
|
|
2138
|
+
"outputWrite",
|
|
2139
|
+
() => writer.copyFileFrom(
|
|
2140
|
+
resolveOutputCacheEntryPath(outputCachePath, cached),
|
|
2141
|
+
path12
|
|
2142
|
+
)
|
|
2143
|
+
);
|
|
1804
2144
|
metrics.emittedOutputCount += 1;
|
|
1805
2145
|
metrics.reusedOutputCount += 1;
|
|
1806
|
-
nextOutputCache.outputs[
|
|
2146
|
+
nextOutputCache.outputs[path12] = cached;
|
|
1807
2147
|
}
|
|
1808
2148
|
});
|
|
1809
2149
|
}
|
|
1810
2150
|
if (outputChangeSet) {
|
|
1811
2151
|
for (const output of outputChangeSet.removed) {
|
|
1812
2152
|
if (siteOwnedOutputPaths.has(output.path)) continue;
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
2153
|
+
if (!artifactWriter) {
|
|
2154
|
+
throw new Error(
|
|
2155
|
+
"Riebeckite SSG artifact writer was not initialized."
|
|
2156
|
+
);
|
|
2157
|
+
}
|
|
2158
|
+
await artifactWriter.remove(output.path);
|
|
1816
2159
|
metrics.deletedOutputCount += 1;
|
|
1817
2160
|
}
|
|
1818
2161
|
}
|
|
@@ -1827,6 +2170,12 @@ function riebeckiteSsg(options = {}) {
|
|
|
1827
2170
|
metrics.cacheEntriesSerialized = Object.keys(
|
|
1828
2171
|
nextOutputCache.outputs
|
|
1829
2172
|
).length;
|
|
2173
|
+
const manifest = await module.content?.getManifest();
|
|
2174
|
+
const publicationFingerprint = manifest ? fingerprintPublication(
|
|
2175
|
+
publicationEntriesFromManifest(manifest),
|
|
2176
|
+
publicationRedirectsFromManifest(manifest),
|
|
2177
|
+
publicationOutputsFromManifest(manifest)
|
|
2178
|
+
) : void 0;
|
|
1830
2179
|
pendingOutputCache = {
|
|
1831
2180
|
path: outputCachePath,
|
|
1832
2181
|
state: nextOutputCache,
|
|
@@ -1835,6 +2184,7 @@ function riebeckiteSsg(options = {}) {
|
|
|
1835
2184
|
outDir,
|
|
1836
2185
|
publicDir: config.publicDir,
|
|
1837
2186
|
configFile: config.configFile,
|
|
2187
|
+
...publicationFingerprint === void 0 ? {} : { publicationFingerprint },
|
|
1838
2188
|
outputPlanInput: {
|
|
1839
2189
|
inventory,
|
|
1840
2190
|
affectedPaths: new Set(
|
|
@@ -1845,19 +2195,34 @@ function riebeckiteSsg(options = {}) {
|
|
|
1845
2195
|
honoStaticRoutePaths,
|
|
1846
2196
|
viteClientAssetPaths: new Set(viteClientAssetPaths),
|
|
1847
2197
|
sitePublicAssetPaths: siteOwnedOutputPaths
|
|
1848
|
-
}
|
|
2198
|
+
},
|
|
2199
|
+
provenance: module.content?.getProvenance(),
|
|
2200
|
+
content: module.content,
|
|
2201
|
+
reusablePaths: new Set(
|
|
2202
|
+
[...reusablePaths].filter(
|
|
2203
|
+
(path12) => !siteOwnedOutputPaths.has(path12)
|
|
2204
|
+
)
|
|
2205
|
+
)
|
|
1849
2206
|
};
|
|
1850
2207
|
this.info(
|
|
1851
2208
|
`SSG outputs: ${metrics.renderedOutputCount} rendered · ${metrics.reusedOutputCount} reused · ${metrics.deletedOutputCount} removed`
|
|
1852
2209
|
);
|
|
1853
|
-
inspectGeneratedHtmlPages(
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
2210
|
+
const generatedHtmlDiagnostics = inspectGeneratedHtmlPages(
|
|
2211
|
+
module,
|
|
2212
|
+
generatedHtml,
|
|
2213
|
+
{
|
|
2214
|
+
warn: (message) => this.warn(message),
|
|
2215
|
+
info: (message) => this.info(message)
|
|
2216
|
+
}
|
|
2217
|
+
);
|
|
2218
|
+
module.content?.recordFinalHtmlDiagnostics?.(generatedHtmlDiagnostics);
|
|
1857
2219
|
logGeneratedHtmlAssetDiagnostics(this, generatedHtml);
|
|
1858
2220
|
} finally {
|
|
1859
|
-
await
|
|
2221
|
+
await rm4(bundleDirectory, { recursive: true, force: true });
|
|
1860
2222
|
await discardClientBuildArtifacts(clientBuildArtifacts);
|
|
2223
|
+
if (clientOutputDirectory) {
|
|
2224
|
+
await rm4(clientOutputDirectory, { recursive: true, force: true });
|
|
2225
|
+
}
|
|
1861
2226
|
clientBuildArtifacts = void 0;
|
|
1862
2227
|
}
|
|
1863
2228
|
},
|
|
@@ -1865,7 +2230,14 @@ function riebeckiteSsg(options = {}) {
|
|
|
1865
2230
|
order: "post",
|
|
1866
2231
|
async handler() {
|
|
1867
2232
|
if (!resolvedConfig) return;
|
|
1868
|
-
|
|
2233
|
+
if (resolvedConfig.mode === "client") return;
|
|
2234
|
+
const outputDirectory = publicationOutputDirectory;
|
|
2235
|
+
if (!outputDirectory) {
|
|
2236
|
+
throw new Error(
|
|
2237
|
+
"Riebeckite SSG could not resolve the publication output directory."
|
|
2238
|
+
);
|
|
2239
|
+
}
|
|
2240
|
+
const outDir = resolve4(
|
|
1869
2241
|
resolvedConfig.root,
|
|
1870
2242
|
resolvedConfig.build.outDir
|
|
1871
2243
|
);
|
|
@@ -1877,13 +2249,26 @@ function riebeckiteSsg(options = {}) {
|
|
|
1877
2249
|
}
|
|
1878
2250
|
const outputCache = pendingOutputCache;
|
|
1879
2251
|
if (!outputCache) return;
|
|
2252
|
+
let published = false;
|
|
1880
2253
|
try {
|
|
2254
|
+
if (!artifactWriter) {
|
|
2255
|
+
throw new Error(
|
|
2256
|
+
"Riebeckite SSG artifact writer was not initialized."
|
|
2257
|
+
);
|
|
2258
|
+
}
|
|
1881
2259
|
outputCache.state.finalOutputInventory = await measure(
|
|
1882
2260
|
outputCache.timingsMs,
|
|
1883
2261
|
"outputInventory",
|
|
1884
2262
|
() => fingerprintOutputDirectory(outputCache.outDir)
|
|
1885
2263
|
);
|
|
1886
2264
|
const finalOutputInventory = outputCache.state.finalOutputInventory;
|
|
2265
|
+
if (outputCache.provenance && outputCache.content) {
|
|
2266
|
+
await outputCache.content.attachFinalOutputArtifacts(
|
|
2267
|
+
outputCache.provenance.buildId,
|
|
2268
|
+
finalOutputInventory,
|
|
2269
|
+
outputCache.reusablePaths
|
|
2270
|
+
);
|
|
2271
|
+
}
|
|
1887
2272
|
const outputPlanRssBefore = process.memoryUsage().rss;
|
|
1888
2273
|
const outputPlan = measureSync(
|
|
1889
2274
|
outputCache.timingsMs,
|
|
@@ -1922,37 +2307,62 @@ function riebeckiteSsg(options = {}) {
|
|
|
1922
2307
|
process.memoryUsage().rss - outputPlanRssBefore
|
|
1923
2308
|
);
|
|
1924
2309
|
const publicDir = outputCache.publicDir;
|
|
1925
|
-
outputCache.state.publicDirectory = publicDir ?
|
|
2310
|
+
outputCache.state.publicDirectory = publicDir ? resolve4(publicDir) : void 0;
|
|
1926
2311
|
outputCache.state.publicFingerprint = publicDir ? await measure(
|
|
1927
2312
|
outputCache.timingsMs,
|
|
1928
2313
|
"publicFingerprint",
|
|
1929
|
-
() => fingerprintDirectory(
|
|
2314
|
+
() => fingerprintDirectory(resolve4(publicDir))
|
|
1930
2315
|
) : void 0;
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2316
|
+
try {
|
|
2317
|
+
await saveOutputCache(
|
|
2318
|
+
outputCache.path,
|
|
2319
|
+
outputCache.state,
|
|
2320
|
+
outputCache.outDir,
|
|
2321
|
+
outputCache.timingsMs
|
|
2322
|
+
);
|
|
2323
|
+
} catch (error) {
|
|
2324
|
+
this.warn(
|
|
2325
|
+
`SSG output cache could not be saved; the next build regenerates every output. ${error instanceof Error ? error.message : String(error)}`
|
|
2326
|
+
);
|
|
2327
|
+
}
|
|
2328
|
+
await artifactWriter.publish();
|
|
2329
|
+
published = true;
|
|
2330
|
+
await writePublicationMarker({
|
|
2331
|
+
root: resolvedConfig.root,
|
|
2332
|
+
outputDirectory,
|
|
2333
|
+
publicationFingerprint: outputCache.publicationFingerprint,
|
|
2334
|
+
warn: (message) => this.warn(message)
|
|
2335
|
+
});
|
|
1941
2336
|
} finally {
|
|
2337
|
+
if (!published) await artifactWriter?.discard();
|
|
1942
2338
|
await writeSsgOutputMetrics(outputCache.metrics);
|
|
1943
2339
|
pendingOutputCache = void 0;
|
|
2340
|
+
artifactWriter = void 0;
|
|
1944
2341
|
}
|
|
1945
2342
|
}
|
|
2343
|
+
},
|
|
2344
|
+
async buildEnd(error) {
|
|
2345
|
+
if (!error || !artifactWriter) return;
|
|
2346
|
+
await artifactWriter.discard();
|
|
2347
|
+
artifactWriter = void 0;
|
|
2348
|
+
pendingOutputCache = void 0;
|
|
1946
2349
|
}
|
|
1947
2350
|
};
|
|
1948
2351
|
}
|
|
1949
|
-
function
|
|
1950
|
-
|
|
2352
|
+
async function isDirectory2(path12) {
|
|
2353
|
+
try {
|
|
2354
|
+
return (await lstat3(path12)).isDirectory();
|
|
2355
|
+
} catch (error) {
|
|
2356
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
2357
|
+
return false;
|
|
2358
|
+
}
|
|
2359
|
+
throw error;
|
|
2360
|
+
}
|
|
1951
2361
|
}
|
|
1952
2362
|
function findBuildOutputSiteCollisions(buildOutputPaths, siteOwnedOutputPaths) {
|
|
1953
2363
|
const collisions = /* @__PURE__ */ new Set();
|
|
1954
|
-
for (const
|
|
1955
|
-
if (siteOwnedOutputPaths.has(
|
|
2364
|
+
for (const path12 of buildOutputPaths) {
|
|
2365
|
+
if (siteOwnedOutputPaths.has(path12)) collisions.add(path12);
|
|
1956
2366
|
}
|
|
1957
2367
|
return [...collisions].sort();
|
|
1958
2368
|
}
|
|
@@ -1968,10 +2378,11 @@ async function emitGeneratedOutputs(module, emit, affectedPaths, shadowedPaths,
|
|
|
1968
2378
|
onShadowed?.(output.path);
|
|
1969
2379
|
continue;
|
|
1970
2380
|
}
|
|
1971
|
-
|
|
2381
|
+
const source = isDeferredGeneratedOutput(output) ? await output.generate() : output.content;
|
|
2382
|
+
await emit({
|
|
1972
2383
|
type: "asset",
|
|
1973
2384
|
fileName: output.path,
|
|
1974
|
-
source
|
|
2385
|
+
source
|
|
1975
2386
|
});
|
|
1976
2387
|
count += 1;
|
|
1977
2388
|
}
|
|
@@ -1984,6 +2395,27 @@ function removeVirtualEntryChunk(bundle, virtualEntryId) {
|
|
|
1984
2395
|
}
|
|
1985
2396
|
}
|
|
1986
2397
|
}
|
|
2398
|
+
async function writePublicationMarker(input) {
|
|
2399
|
+
const path12 = join5(input.root, ".riebeckite", BUILD_OUTPUT_MARKER_FILE);
|
|
2400
|
+
try {
|
|
2401
|
+
await mkdir5(dirname5(path12), { recursive: true });
|
|
2402
|
+
await writeFile4(
|
|
2403
|
+
path12,
|
|
2404
|
+
serializeBuildOutputMarker(
|
|
2405
|
+
createBuildOutputMarker({
|
|
2406
|
+
outputDirectory: input.outputDirectory,
|
|
2407
|
+
...input.publicationFingerprint === void 0 ? {} : { publicationFingerprint: input.publicationFingerprint },
|
|
2408
|
+
completedAt: /* @__PURE__ */ new Date()
|
|
2409
|
+
})
|
|
2410
|
+
),
|
|
2411
|
+
"utf8"
|
|
2412
|
+
);
|
|
2413
|
+
} catch (error) {
|
|
2414
|
+
input.warn(
|
|
2415
|
+
`Could not write the publication marker; publish will rebuild before deploying. ${error instanceof Error ? error.message : String(error)}`
|
|
2416
|
+
);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
1987
2419
|
|
|
1988
2420
|
// src/ssg.ts
|
|
1989
2421
|
var defaultSsgEntry = "./app/server.ts";
|
|
@@ -2010,7 +2442,11 @@ function createRiebeckiteSsg(options = {}) {
|
|
|
2010
2442
|
}
|
|
2011
2443
|
|
|
2012
2444
|
// src/vite_plugin.ts
|
|
2013
|
-
import
|
|
2445
|
+
import path11 from "node:path";
|
|
2446
|
+
import {
|
|
2447
|
+
invalidateDevelopmentInspector,
|
|
2448
|
+
riebeckiteDevelopmentInspector
|
|
2449
|
+
} from "@riebeckite/dev-inspector";
|
|
2014
2450
|
|
|
2015
2451
|
// src/asset_entries.ts
|
|
2016
2452
|
import fs6 from "node:fs";
|
|
@@ -2062,11 +2498,11 @@ function readGeneratedFile(filePath) {
|
|
|
2062
2498
|
try {
|
|
2063
2499
|
return fs6.readFileSync(filePath, "utf8");
|
|
2064
2500
|
} catch (error) {
|
|
2065
|
-
if (
|
|
2501
|
+
if (isNotFoundError3(error)) return void 0;
|
|
2066
2502
|
throw error;
|
|
2067
2503
|
}
|
|
2068
2504
|
}
|
|
2069
|
-
function
|
|
2505
|
+
function isNotFoundError3(error) {
|
|
2070
2506
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
2071
2507
|
}
|
|
2072
2508
|
|
|
@@ -2095,7 +2531,29 @@ function createClientModule(config, development) {
|
|
|
2095
2531
|
const imports = [];
|
|
2096
2532
|
const appInitializers = [];
|
|
2097
2533
|
const pageInitializers = [];
|
|
2534
|
+
const clientEntries = config.plugins.flatMap(
|
|
2535
|
+
(plugin) => plugin.clientEntries ?? []
|
|
2536
|
+
);
|
|
2537
|
+
const runtimeEntries = /* @__PURE__ */ new Map();
|
|
2538
|
+
for (const entry of clientEntries) {
|
|
2539
|
+
for (const runtime of entry.runtimeEntries ?? []) {
|
|
2540
|
+
if (runtimeEntries.has(runtime.id)) {
|
|
2541
|
+
throw new Error(`Duplicate plugin runtime id: ${runtime.id}`);
|
|
2542
|
+
}
|
|
2543
|
+
runtimeEntries.set(runtime.id, {
|
|
2544
|
+
moduleSpecifier: runtime.moduleSpecifier,
|
|
2545
|
+
exportName: runtime.exportName,
|
|
2546
|
+
options: runtime.options
|
|
2547
|
+
});
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
const hasRuntimes = runtimeEntries.size > 0;
|
|
2098
2551
|
imports.push('import { ClientLifecycle } from "@riebeckite/core/client";');
|
|
2552
|
+
if (hasRuntimes) {
|
|
2553
|
+
imports.push(
|
|
2554
|
+
'import { createClientRuntimeHost, InteractiveRuntimeRegistry } from "@riebeckite/runtime/client";'
|
|
2555
|
+
);
|
|
2556
|
+
}
|
|
2099
2557
|
if (config.spa !== void 0) {
|
|
2100
2558
|
imports.push('import { createClient } from "honox/client";');
|
|
2101
2559
|
imports.push('import { startSpaNavigation } from "@riebeckite/spa";');
|
|
@@ -2106,8 +2564,12 @@ function createClientModule(config, development) {
|
|
|
2106
2564
|
);
|
|
2107
2565
|
appInitializers.push("initDevelopmentInspector()");
|
|
2108
2566
|
}
|
|
2109
|
-
for (const [index, entry] of
|
|
2567
|
+
for (const [index, entry] of clientEntries.entries()) {
|
|
2110
2568
|
const localName = `pluginClientInitializer${index}`;
|
|
2569
|
+
const runtimeIds = (entry.runtimeEntries ?? []).map(
|
|
2570
|
+
(runtime) => runtime.id
|
|
2571
|
+
);
|
|
2572
|
+
const serializedRuntimeIds = serializePublicClientConfig(runtimeIds);
|
|
2111
2573
|
const importTarget = entry.exportName ? `{ ${entry.exportName} as ${localName} }` : localName;
|
|
2112
2574
|
if (entry.presenceSelector === void 0) {
|
|
2113
2575
|
imports.push(
|
|
@@ -2117,32 +2579,71 @@ function createClientModule(config, development) {
|
|
|
2117
2579
|
const publicConfig = entry.publicConfig;
|
|
2118
2580
|
const serializedConfig = publicConfig === void 0 ? "undefined" : serializePublicClientConfig(publicConfig);
|
|
2119
2581
|
const initializer = entry.initializerArguments === "context" ? `${localName}(context)` : entry.initializerArguments === "root" ? `${localName}(context.root)` : `${localName}(context.config)`;
|
|
2582
|
+
const ensureRuntimes = runtimeIds.length > 0 ? `await ensurePluginRuntimes(${serializedRuntimeIds}); ` : "";
|
|
2583
|
+
const initializerWrapper = runtimeIds.length > 0 ? `async (context) => { ${ensureRuntimes}return ${initializer}; }` : `(context) => ${initializer}`;
|
|
2584
|
+
const runtimeArguments = hasRuntimes ? `${serializedRuntimeIds}, ${initializerWrapper}` : initializerWrapper;
|
|
2120
2585
|
const initializers = entry.scope === "app" ? appInitializers : pageInitializers;
|
|
2121
2586
|
if (entry.presenceSelector === void 0) {
|
|
2122
2587
|
initializers.push(
|
|
2123
|
-
`mountPluginClientInitializer(${JSON.stringify(entry.scope ?? "page")}, ${JSON.stringify(entry.moduleSpecifier)}, root, ${serializedConfig},
|
|
2588
|
+
`mountPluginClientInitializer(${JSON.stringify(entry.scope ?? "page")}, ${JSON.stringify(entry.moduleSpecifier)}, root, ${serializedConfig}, ${runtimeArguments})`
|
|
2124
2589
|
);
|
|
2125
2590
|
continue;
|
|
2126
2591
|
}
|
|
2127
2592
|
const dynamicInitializer = entry.initializerArguments === "context" ? `initializer(context)` : entry.initializerArguments === "root" ? `initializer(context.root)` : `initializer(context.config)`;
|
|
2593
|
+
const dynamicWrapper = runtimeIds.length > 0 ? `async (context) => { ${ensureRuntimes}return ${dynamicInitializer}; }` : `(context) => ${dynamicInitializer}`;
|
|
2128
2594
|
initializers.push(
|
|
2129
|
-
`mountConditionalPluginClientInitializer(${JSON.stringify(entry.scope ?? "page")}, ${JSON.stringify(entry.moduleSpecifier)}, root, ${serializedConfig}, ${JSON.stringify(entry.presenceSelector)}, async () => { const { ${entry.exportName ?? "default"}: initializer } = await import(${JSON.stringify(entry.moduleSpecifier)}); return
|
|
2595
|
+
`mountConditionalPluginClientInitializer(${JSON.stringify(entry.scope ?? "page")}, ${JSON.stringify(entry.moduleSpecifier)}, root, ${serializedConfig}, ${JSON.stringify(entry.presenceSelector)}, ${hasRuntimes ? `${serializedRuntimeIds}, ` : ""}async () => { const { ${entry.exportName ?? "default"}: initializer } = await import(${JSON.stringify(entry.moduleSpecifier)}); return ${dynamicWrapper}; })`
|
|
2130
2596
|
);
|
|
2131
2597
|
}
|
|
2598
|
+
const runtimeSupport = hasRuntimes ? `const pluginRuntimeRegistry = new InteractiveRuntimeRegistry();
|
|
2599
|
+
const pluginRuntimeLoads = new Map();
|
|
2600
|
+
const pluginRuntimeEntries = {
|
|
2601
|
+
${[...runtimeEntries.entries()].map(
|
|
2602
|
+
([id, runtime]) => ` ${JSON.stringify(id)}: { moduleSpecifier: ${JSON.stringify(runtime.moduleSpecifier)}, exportName: ${JSON.stringify(runtime.exportName ?? "default")}, load: () => import(${JSON.stringify(runtime.moduleSpecifier)})${runtime.options === void 0 ? "" : `, options: ${serializePublicClientConfig(runtime.options)}`} }`
|
|
2603
|
+
).join(",\n")}
|
|
2604
|
+
};
|
|
2605
|
+
|
|
2606
|
+
async function ensurePluginRuntimes(ids) {
|
|
2607
|
+
await Promise.all(ids.map(async (id) => {
|
|
2608
|
+
let load = pluginRuntimeLoads.get(id);
|
|
2609
|
+
if (!load) {
|
|
2610
|
+
const entry = pluginRuntimeEntries[id];
|
|
2611
|
+
if (!entry) throw new Error("Unknown plugin runtime: " + id);
|
|
2612
|
+
load = entry.load().then((module) => {
|
|
2613
|
+
const factory = module[entry.exportName];
|
|
2614
|
+
if (typeof factory !== "function") throw new Error("Plugin runtime \\"" + id + "\\" did not export a factory.");
|
|
2615
|
+
const definition = factory(entry.options);
|
|
2616
|
+
if (!definition || definition.id !== id) throw new Error("Plugin runtime \\"" + id + "\\" returned a mismatched definition.");
|
|
2617
|
+
pluginRuntimeRegistry.register(definition);
|
|
2618
|
+
}).catch((error) => {
|
|
2619
|
+
pluginRuntimeLoads.delete(id);
|
|
2620
|
+
throw error;
|
|
2621
|
+
});
|
|
2622
|
+
pluginRuntimeLoads.set(id, load);
|
|
2623
|
+
}
|
|
2624
|
+
await load;
|
|
2625
|
+
}));
|
|
2626
|
+
}
|
|
2627
|
+
|
|
2628
|
+
function createPluginRuntimeHost(root, ids) {
|
|
2629
|
+
if (ids.length === 0) return undefined;
|
|
2630
|
+
return createClientRuntimeHost({ registry: pluginRuntimeRegistry, root });
|
|
2631
|
+
}
|
|
2632
|
+
` : "";
|
|
2132
2633
|
return `${imports.join("\n")}
|
|
2133
2634
|
|
|
2134
2635
|
const lifecycle = new ClientLifecycle();
|
|
2135
|
-
let stopSpaNavigation;
|
|
2636
|
+
${runtimeSupport}let stopSpaNavigation;
|
|
2136
2637
|
|
|
2137
|
-
function mountPluginClientInitializer(scope, name, root, config, initialize) {
|
|
2138
|
-
void lifecycle.mount({ scope, name, root, config, initialize });
|
|
2638
|
+
function mountPluginClientInitializer(scope, name, root, config, ${hasRuntimes ? "runtimeIds, " : ""}initialize) {
|
|
2639
|
+
void lifecycle.mount({ scope, name, root, config, ${hasRuntimes ? "runtimes: createPluginRuntimeHost(root, runtimeIds), " : ""}initialize }).catch((error) => console.error("[riebeckite] Client initializer failed: " + name, error));
|
|
2139
2640
|
}
|
|
2140
2641
|
|
|
2141
|
-
function mountConditionalPluginClientInitializer(scope, name, root, config, presenceSelector, load) {
|
|
2642
|
+
function mountConditionalPluginClientInitializer(scope, name, root, config, presenceSelector, ${hasRuntimes ? "runtimeIds, " : ""}load) {
|
|
2142
2643
|
if (!root.querySelector(presenceSelector)) return;
|
|
2143
2644
|
void load().then((initialize) => {
|
|
2144
2645
|
if ("isConnected" in root && !root.isConnected) return;
|
|
2145
|
-
void lifecycle.mount({ scope, name, root, config, initialize });
|
|
2646
|
+
void lifecycle.mount({ scope, name, root, config, ${hasRuntimes ? "runtimes: createPluginRuntimeHost(root, runtimeIds), " : ""}initialize }).catch((error) => console.error("[riebeckite] Client initializer failed: " + name, error));
|
|
2146
2647
|
}, (error) => console.error("[riebeckite] Client initializer module failed: " + name, error));
|
|
2147
2648
|
}
|
|
2148
2649
|
|
|
@@ -2182,522 +2683,183 @@ export async function disposeRiebeckiteClient() {
|
|
|
2182
2683
|
`;
|
|
2183
2684
|
}
|
|
2184
2685
|
|
|
2185
|
-
// src/
|
|
2186
|
-
import
|
|
2187
|
-
|
|
2188
|
-
ContentManager
|
|
2189
|
-
} from "@riebeckite/core";
|
|
2686
|
+
// src/content_watch.ts
|
|
2687
|
+
import path9 from "node:path";
|
|
2688
|
+
import { isAttachmentPath, isImagePath as isImagePath2 } from "@riebeckite/core";
|
|
2190
2689
|
import {
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
} from "@riebeckite/
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
var
|
|
2198
|
-
var
|
|
2199
|
-
var
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
}
|
|
2208
|
-
if (inspection) {
|
|
2209
|
-
const previous = inspection;
|
|
2210
|
-
const disposePrevious = () => {
|
|
2211
|
-
void previous.dispose().catch(() => {
|
|
2212
|
-
});
|
|
2213
|
-
};
|
|
2214
|
-
void Promise.allSettled([previous.report, previous.output]).then(
|
|
2215
|
-
disposePrevious
|
|
2216
|
-
);
|
|
2217
|
-
inspection = null;
|
|
2218
|
-
}
|
|
2219
|
-
const content = createInspectionContent(application);
|
|
2220
|
-
let disposed = false;
|
|
2221
|
-
const dispose = async () => {
|
|
2222
|
-
if (disposed) return;
|
|
2223
|
-
disposed = true;
|
|
2224
|
-
await content.dispose();
|
|
2225
|
-
};
|
|
2226
|
-
const report = collectDevelopmentDiagnostics({
|
|
2227
|
-
config: application.config,
|
|
2228
|
-
content,
|
|
2229
|
-
revision: currentRevision,
|
|
2230
|
-
includeOutput: false
|
|
2231
|
-
});
|
|
2232
|
-
const output = report.then(
|
|
2233
|
-
() => inspectContentOutputs(content),
|
|
2234
|
-
() => inspectContentOutputs(content)
|
|
2235
|
-
);
|
|
2236
|
-
const entry = {
|
|
2237
|
-
application,
|
|
2238
|
-
revision: currentRevision,
|
|
2239
|
-
report,
|
|
2240
|
-
output,
|
|
2241
|
-
dispose
|
|
2242
|
-
};
|
|
2243
|
-
inspection = entry;
|
|
2244
|
-
void report.catch(() => {
|
|
2245
|
-
if (inspection === entry) inspection = null;
|
|
2246
|
-
void output.then(dispose, dispose);
|
|
2247
|
-
});
|
|
2248
|
-
return entry;
|
|
2249
|
-
};
|
|
2690
|
+
isIgnoredContentPath as isIgnoredContentPath2,
|
|
2691
|
+
isPathInsideDirectory as isPathInsideDirectory2,
|
|
2692
|
+
toLogicalPath
|
|
2693
|
+
} from "@riebeckite/node";
|
|
2694
|
+
|
|
2695
|
+
// src/runtime_modules.ts
|
|
2696
|
+
var riebeckiteConfigModuleId = "virtual:riebeckite/config";
|
|
2697
|
+
var riebeckiteContentModuleId = "virtual:riebeckite/content";
|
|
2698
|
+
var runtimeModuleIds = [
|
|
2699
|
+
riebeckiteConfigModuleId,
|
|
2700
|
+
riebeckiteContentModuleId
|
|
2701
|
+
];
|
|
2702
|
+
var resolvedConfigModuleId = `\0${riebeckiteConfigModuleId}`;
|
|
2703
|
+
var resolvedContentModuleId = `\0${riebeckiteContentModuleId}`;
|
|
2704
|
+
function riebeckiteRuntimeModules(getApplication) {
|
|
2705
|
+
let development = false;
|
|
2250
2706
|
return {
|
|
2251
|
-
name: "riebeckite-
|
|
2252
|
-
|
|
2253
|
-
|
|
2707
|
+
name: "riebeckite-runtime-modules",
|
|
2708
|
+
configResolved(config) {
|
|
2709
|
+
development = config.command === "serve";
|
|
2710
|
+
},
|
|
2254
2711
|
resolveId(id) {
|
|
2255
|
-
|
|
2712
|
+
if (id === riebeckiteConfigModuleId) return resolvedConfigModuleId;
|
|
2713
|
+
if (id === riebeckiteContentModuleId) return resolvedContentModuleId;
|
|
2714
|
+
return null;
|
|
2256
2715
|
},
|
|
2257
2716
|
load(id) {
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
return;
|
|
2266
|
-
}
|
|
2267
|
-
try {
|
|
2268
|
-
const application = getApplication();
|
|
2269
|
-
const report = await inspectApplication(application, revision).report;
|
|
2270
|
-
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
2271
|
-
response.setHeader("cache-control", "no-store");
|
|
2272
|
-
response.end(
|
|
2273
|
-
JSON.stringify({
|
|
2274
|
-
...report,
|
|
2275
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2276
|
-
currentPage: currentPageFromRequest(request.url),
|
|
2277
|
-
theme: application.config.theme.name,
|
|
2278
|
-
plugins: application.config.plugins.map((plugin) => plugin.name)
|
|
2279
|
-
})
|
|
2280
|
-
);
|
|
2281
|
-
} catch {
|
|
2282
|
-
response.statusCode = 500;
|
|
2283
|
-
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
2284
|
-
response.end(JSON.stringify({ code: "INSPECTOR_REPORT_FAILED" }));
|
|
2285
|
-
}
|
|
2286
|
-
};
|
|
2287
|
-
const outputMiddleware = async (request, response) => {
|
|
2288
|
-
if (!isLocalRequest(request.headers.host, server)) {
|
|
2289
|
-
response.statusCode = 403;
|
|
2290
|
-
response.end();
|
|
2291
|
-
return;
|
|
2292
|
-
}
|
|
2293
|
-
try {
|
|
2294
|
-
const application = getApplication();
|
|
2295
|
-
const entry = inspectApplication(application, revision);
|
|
2296
|
-
const result = await entry.output;
|
|
2297
|
-
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
2298
|
-
response.setHeader("cache-control", "no-store");
|
|
2299
|
-
response.end(
|
|
2300
|
-
JSON.stringify({
|
|
2301
|
-
version: 1,
|
|
2302
|
-
revision: entry.revision,
|
|
2303
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2304
|
-
...result,
|
|
2305
|
-
diagnostics: sortDevelopmentDiagnostics(result.diagnostics)
|
|
2306
|
-
})
|
|
2307
|
-
);
|
|
2308
|
-
} catch {
|
|
2309
|
-
response.statusCode = 500;
|
|
2310
|
-
response.setHeader("content-type", "application/json; charset=utf-8");
|
|
2311
|
-
response.end(JSON.stringify({ code: "INSPECTOR_OUTPUT_FAILED" }));
|
|
2312
|
-
}
|
|
2313
|
-
};
|
|
2314
|
-
server.middlewares.use(reportPath, reportMiddleware);
|
|
2315
|
-
server.middlewares.use(outputPath, outputMiddleware);
|
|
2316
|
-
return () => {
|
|
2317
|
-
prioritizeMiddleware(server, outputMiddleware, outputPath);
|
|
2318
|
-
prioritizeMiddleware(server, reportMiddleware, reportPath);
|
|
2319
|
-
};
|
|
2320
|
-
},
|
|
2321
|
-
handleHotUpdate({ server }) {
|
|
2322
|
-
revision += 1;
|
|
2323
|
-
server.hot.send({ type: "custom", event: "riebeckite:inspector" });
|
|
2717
|
+
if (id === resolvedConfigModuleId) {
|
|
2718
|
+
const { appRoot, configFile } = getApplication();
|
|
2719
|
+
return createConfigModule(appRoot, configFile);
|
|
2720
|
+
}
|
|
2721
|
+
if (id === resolvedContentModuleId)
|
|
2722
|
+
return createContentModule(development);
|
|
2723
|
+
return null;
|
|
2324
2724
|
}
|
|
2325
2725
|
};
|
|
2326
2726
|
}
|
|
2327
|
-
function
|
|
2328
|
-
|
|
2329
|
-
return
|
|
2330
|
-
|
|
2331
|
-
config.content.exclude,
|
|
2332
|
-
{ config, commitBuildState: false }
|
|
2727
|
+
function isRiebeckiteRuntimeModuleId(id) {
|
|
2728
|
+
if (!id) return false;
|
|
2729
|
+
return runtimeModuleIds.some(
|
|
2730
|
+
(moduleId) => id === moduleId || id === `\0${moduleId}`
|
|
2333
2731
|
);
|
|
2334
2732
|
}
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
removed: changes.removed,
|
|
2341
|
-
affectedPaths: new Set(changes.affected.map((output) => output.path)),
|
|
2342
|
-
cacheAvailable: changes.unchanged.length > 0
|
|
2343
|
-
});
|
|
2344
|
-
return {
|
|
2345
|
-
output: inspectOutput(changes, plan),
|
|
2346
|
-
dependencies: inspectDependencies(changes),
|
|
2347
|
-
diagnostics: diagnoseOutputPlan(plan)
|
|
2348
|
-
};
|
|
2349
|
-
} catch {
|
|
2350
|
-
return {
|
|
2351
|
-
output: {
|
|
2352
|
-
status: "unavailable",
|
|
2353
|
-
reason: "output inspection failed"
|
|
2354
|
-
},
|
|
2355
|
-
dependencies: {
|
|
2356
|
-
status: "unavailable",
|
|
2357
|
-
reason: "dependency inspection failed"
|
|
2358
|
-
},
|
|
2359
|
-
diagnostics: []
|
|
2360
|
-
};
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
function inspectOutput(changes, plan) {
|
|
2364
|
-
return {
|
|
2365
|
-
status: "available",
|
|
2366
|
-
candidateOutputCount: changes.candidateOutputCount,
|
|
2367
|
-
affectedOutputCount: changes.affectedOutputCount,
|
|
2368
|
-
unchangedOutputCount: changes.unchangedOutputCount,
|
|
2369
|
-
removedOutputCount: changes.removedOutputCount,
|
|
2370
|
-
fullRegenerationRequired: changes.fullRegenerationRequired,
|
|
2371
|
-
conflicts: plan.conflicts.map((conflict) => ({
|
|
2372
|
-
path: conflict.path,
|
|
2373
|
-
owners: conflict.owners
|
|
2374
|
-
})),
|
|
2375
|
-
affected: changes.affected.slice(0, listedOutputLimit).map(listOutput),
|
|
2376
|
-
hiddenAffectedCount: Math.max(
|
|
2377
|
-
0,
|
|
2378
|
-
changes.affected.length - listedOutputLimit
|
|
2379
|
-
),
|
|
2380
|
-
removed: changes.removed.slice(0, listedOutputLimit).map(listOutput),
|
|
2381
|
-
hiddenRemovedCount: Math.max(0, changes.removed.length - listedOutputLimit)
|
|
2382
|
-
};
|
|
2383
|
-
}
|
|
2384
|
-
function inspectDependencies(changes) {
|
|
2385
|
-
const outputs = [...changes.affected, ...changes.unchanged];
|
|
2386
|
-
const kinds = /* @__PURE__ */ new Map();
|
|
2387
|
-
const listed = [];
|
|
2388
|
-
let dependencyCount = 0;
|
|
2389
|
-
let dependentOutputCount = 0;
|
|
2390
|
-
let unknownOutputCount = 0;
|
|
2391
|
-
let hiddenOutputCount = 0;
|
|
2392
|
-
for (const output of outputs) {
|
|
2393
|
-
for (const dependency of output.dependencies) {
|
|
2394
|
-
dependencyCount += 1;
|
|
2395
|
-
kinds.set(dependency.type, (kinds.get(dependency.type) ?? 0) + 1);
|
|
2396
|
-
}
|
|
2397
|
-
if (output.dependencies.some(({ type }) => type === "unknown")) {
|
|
2398
|
-
unknownOutputCount += 1;
|
|
2399
|
-
}
|
|
2400
|
-
if (output.dependencies.length === 0) continue;
|
|
2401
|
-
dependentOutputCount += 1;
|
|
2402
|
-
if (listed.length < listedOutputLimit) {
|
|
2403
|
-
listed.push({
|
|
2404
|
-
path: output.path,
|
|
2405
|
-
dependencies: output.dependencies.map(dependencyLabel)
|
|
2406
|
-
});
|
|
2407
|
-
} else {
|
|
2408
|
-
hiddenOutputCount += 1;
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
return {
|
|
2412
|
-
status: "available",
|
|
2413
|
-
outputCount: outputs.length,
|
|
2414
|
-
dependentOutputCount,
|
|
2415
|
-
dependencyCount,
|
|
2416
|
-
unknownOutputCount,
|
|
2417
|
-
kinds: [...kinds.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([kind, count]) => ({ kind, count })),
|
|
2418
|
-
outputs: listed,
|
|
2419
|
-
hiddenOutputCount
|
|
2420
|
-
};
|
|
2421
|
-
}
|
|
2422
|
-
function listOutput(output) {
|
|
2423
|
-
return {
|
|
2424
|
-
path: output.path,
|
|
2425
|
-
kind: output.kind,
|
|
2426
|
-
producer: output.producer
|
|
2427
|
-
};
|
|
2428
|
-
}
|
|
2429
|
-
function dependencyLabel(dependency) {
|
|
2430
|
-
switch (dependency.type) {
|
|
2431
|
-
case "content":
|
|
2432
|
-
return `content:${dependency.slug}`;
|
|
2433
|
-
case "tag":
|
|
2434
|
-
return `tag:${dependency.tag}`;
|
|
2435
|
-
case "folder":
|
|
2436
|
-
return `folder:${dependency.folder}`;
|
|
2437
|
-
case "file":
|
|
2438
|
-
return `file:${dependency.path}`;
|
|
2439
|
-
case "public-location":
|
|
2440
|
-
return `public-location:${dependency.pathname}`;
|
|
2441
|
-
case "projection":
|
|
2442
|
-
return `projection:${dependency.projection}`;
|
|
2443
|
-
case "external":
|
|
2444
|
-
return `external:${dependency.id}`;
|
|
2445
|
-
case "content-query":
|
|
2446
|
-
return `content-query:${dependency.properties.join(",")}${dependency.unknown ? "?" : ""}`;
|
|
2447
|
-
case "global":
|
|
2448
|
-
return "global";
|
|
2449
|
-
case "unknown":
|
|
2450
|
-
return "unknown";
|
|
2451
|
-
}
|
|
2452
|
-
}
|
|
2453
|
-
function currentPageFromRequest(url) {
|
|
2454
|
-
const value = new URL(url ?? reportPath, "http://localhost").searchParams.get(
|
|
2455
|
-
"path"
|
|
2456
|
-
);
|
|
2457
|
-
return value?.startsWith("/") && !value.startsWith("//") ? value : "/";
|
|
2458
|
-
}
|
|
2459
|
-
function prioritizeMiddleware(server, middleware, path11) {
|
|
2460
|
-
const stack = server.middlewares.stack;
|
|
2461
|
-
const index = stack?.findIndex(
|
|
2462
|
-
(layer) => layer.handle === middleware || layer.route === path11
|
|
2463
|
-
) ?? -1;
|
|
2464
|
-
if (index > 0 && stack) stack.unshift(...stack.splice(index, 1));
|
|
2465
|
-
}
|
|
2466
|
-
function isLocalRequest(host, server) {
|
|
2467
|
-
if (!host) return false;
|
|
2468
|
-
const hostname = host.replace(/:\d+$/, "").toLowerCase();
|
|
2469
|
-
if (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]")
|
|
2470
|
-
return true;
|
|
2471
|
-
const address = server.httpServer?.address();
|
|
2472
|
-
return typeof address === "object" && address?.address === hostname;
|
|
2473
|
-
}
|
|
2474
|
-
function inspectorClientModule() {
|
|
2475
|
-
return `
|
|
2476
|
-
const reportEndpoint = ${JSON.stringify(reportPath)};
|
|
2477
|
-
const outputEndpoint = ${JSON.stringify(outputPath)};
|
|
2478
|
-
const panelId = "riebeckite-development-inspector";
|
|
2733
|
+
function createConfigModule(appRoot, configFile) {
|
|
2734
|
+
const configSpecifier = configFile.replace(/\\/g, "/");
|
|
2735
|
+
return `import * as rawConfigModule from ${JSON.stringify(configSpecifier)};
|
|
2736
|
+
import { resolveConfigModule } from "@riebeckite/core";
|
|
2737
|
+
import { resolveHonoxConfig } from "@riebeckite/honox/runtime";
|
|
2479
2738
|
|
|
2480
|
-
export
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
const refresh = async () => {
|
|
2492
|
-
if (!panel?.isConnected) return;
|
|
2493
|
-
if (refreshing) {
|
|
2494
|
-
pendingRefresh = true;
|
|
2495
|
-
return;
|
|
2496
|
-
}
|
|
2497
|
-
refreshing = true;
|
|
2498
|
-
controller?.abort();
|
|
2499
|
-
controller = new AbortController();
|
|
2500
|
-
const current = ++generation;
|
|
2501
|
-
try {
|
|
2502
|
-
const response = await fetch(reportEndpoint + "?path=" + encodeURIComponent(location.pathname), { cache: "no-store", signal: controller.signal });
|
|
2503
|
-
if (!response.ok) throw new Error("Inspector report is unavailable.");
|
|
2504
|
-
const next = await response.json();
|
|
2505
|
-
if (current !== generation || !panel?.isConnected) return;
|
|
2506
|
-
report = next;
|
|
2507
|
-
render();
|
|
2508
|
-
void loadOutput(current);
|
|
2509
|
-
} catch (error) {
|
|
2510
|
-
if (error.name === "AbortError" || current !== generation) return;
|
|
2511
|
-
clearInterval(loadingTimer);
|
|
2512
|
-
renderFailure(panel.shadowRoot, error instanceof Error ? error.message : String(error));
|
|
2513
|
-
panel.shadowRoot.querySelector("[data-close]").addEventListener("click", close);
|
|
2514
|
-
} finally {
|
|
2515
|
-
refreshing = false;
|
|
2516
|
-
if (pendingRefresh) {
|
|
2517
|
-
pendingRefresh = false;
|
|
2518
|
-
void refresh();
|
|
2519
|
-
}
|
|
2520
|
-
}
|
|
2521
|
-
};
|
|
2522
|
-
const loadOutput = async (current) => {
|
|
2523
|
-
try {
|
|
2524
|
-
const response = await fetch(outputEndpoint, { cache: "no-store", signal: controller.signal });
|
|
2525
|
-
if (!response.ok) throw new Error("Inspector output is unavailable.");
|
|
2526
|
-
const next = await response.json();
|
|
2527
|
-
if (current !== generation || !panel?.isConnected) return;
|
|
2528
|
-
report.output = next.output;
|
|
2529
|
-
report.dependencies = next.dependencies;
|
|
2530
|
-
report.diagnostics = report.diagnostics.concat(next.diagnostics);
|
|
2531
|
-
report.summary = summarize(report.diagnostics);
|
|
2532
|
-
render();
|
|
2533
|
-
} catch (error) {
|
|
2534
|
-
if (error.name === "AbortError" || current !== generation) return;
|
|
2535
|
-
report.output = { status: "unavailable", reason: "output inspection failed" };
|
|
2536
|
-
report.dependencies = { status: "unavailable", reason: "dependency inspection failed" };
|
|
2537
|
-
render();
|
|
2538
|
-
}
|
|
2539
|
-
};
|
|
2540
|
-
const open = () => {
|
|
2541
|
-
if (!panel) {
|
|
2542
|
-
panel = document.createElement("div");
|
|
2543
|
-
panel.id = panelId;
|
|
2544
|
-
panel.attachShadow({ mode: "open" });
|
|
2545
|
-
}
|
|
2546
|
-
if (!panel.isConnected) document.body.append(panel);
|
|
2547
|
-
showLoading();
|
|
2548
|
-
void refresh();
|
|
2549
|
-
};
|
|
2550
|
-
const close = () => {
|
|
2551
|
-
generation += 1;
|
|
2552
|
-
pendingRefresh = false;
|
|
2553
|
-
controller?.abort();
|
|
2554
|
-
clearInterval(loadingTimer);
|
|
2555
|
-
panel?.remove();
|
|
2556
|
-
launcher?.focus();
|
|
2557
|
-
};
|
|
2558
|
-
const showLoading = () => {
|
|
2559
|
-
if (!panel) return;
|
|
2560
|
-
clearInterval(loadingTimer);
|
|
2561
|
-
panel.shadowRoot.innerHTML = '<style>' + styles + '</style><section role="dialog" aria-modal="false" aria-labelledby="rb-loading-title"><header><strong id="rb-loading-title">Riebeckite Inspector</strong><button type="button" data-close aria-label="Close inspector">Close</button></header><p class="status" aria-live="polite">Loading inspector report…</p></section>';
|
|
2562
|
-
const status = panel.shadowRoot.querySelector(".status");
|
|
2563
|
-
const started = Date.now();
|
|
2564
|
-
loadingTimer = setInterval(() => {
|
|
2565
|
-
if (status?.isConnected) status.textContent = 'Loading inspector report… ' + Math.round((Date.now() - started) / 1000) + 's';
|
|
2566
|
-
}, 1000);
|
|
2567
|
-
panel.shadowRoot.querySelector("[data-close]").addEventListener("click", close);
|
|
2568
|
-
};
|
|
2569
|
-
launcher = document.createElement("button");
|
|
2570
|
-
launcher.type = "button";
|
|
2571
|
-
launcher.textContent = "Inspector";
|
|
2572
|
-
launcher.setAttribute("aria-label", "Open Riebeckite Development Inspector");
|
|
2573
|
-
launcher.style.cssText = "position:fixed;right:16px;bottom:16px;z-index:2147483647;border:1px solid #434343;border-radius:4px;background:#171717;color:#fff;padding:8px 12px;font:600 12px system-ui;cursor:pointer";
|
|
2574
|
-
launcher.addEventListener("click", open);
|
|
2575
|
-
document.body.append(launcher);
|
|
2576
|
-
window.addEventListener("keydown", (event) => {
|
|
2577
|
-
const editable = event.target instanceof HTMLElement && (event.target.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(event.target.tagName));
|
|
2578
|
-
if (event.key === "Escape" && panel?.isConnected) {
|
|
2579
|
-
event.preventDefault();
|
|
2580
|
-
close();
|
|
2581
|
-
} else if (event.key.toLowerCase() === "r" && event.ctrlKey && event.altKey && !editable) {
|
|
2582
|
-
event.preventDefault();
|
|
2583
|
-
panel?.isConnected ? close() : open();
|
|
2584
|
-
}
|
|
2585
|
-
});
|
|
2586
|
-
import.meta.hot?.on("riebeckite:inspector", refresh);
|
|
2739
|
+
export const config = resolveHonoxConfig(
|
|
2740
|
+
resolveConfigModule(rawConfigModule),
|
|
2741
|
+
${JSON.stringify(appRoot)},
|
|
2742
|
+
);
|
|
2743
|
+
`;
|
|
2744
|
+
}
|
|
2745
|
+
function createContentModule(development) {
|
|
2746
|
+
if (!development) {
|
|
2747
|
+
return `import { ContentManager } from "@riebeckite/core";
|
|
2748
|
+
import { createContentSource } from "@riebeckite/node";
|
|
2749
|
+
import { config } from ${JSON.stringify(riebeckiteConfigModuleId)};
|
|
2587
2750
|
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
root.querySelector("[role=tablist]").addEventListener("keydown", (event) => {
|
|
2595
|
-
if (event.key === "Home") activeTab = 0;
|
|
2596
|
-
else if (event.key === "End") activeTab = tabs.length - 1;
|
|
2597
|
-
else if (event.key === "ArrowRight" || event.key === "ArrowDown") activeTab = (activeTab + 1) % tabs.length;
|
|
2598
|
-
else if (event.key === "ArrowLeft" || event.key === "ArrowUp") activeTab = (activeTab + tabs.length - 1) % tabs.length;
|
|
2599
|
-
else return;
|
|
2600
|
-
event.preventDefault(); render(); root.querySelector('[data-tab="' + activeTab + '"]').focus();
|
|
2601
|
-
});
|
|
2602
|
-
}
|
|
2603
|
-
function panelContent() {
|
|
2604
|
-
if (activeTab === 0) return '<dl><dt>Page</dt><dd>' + escapeHtml(report.currentPage) + '</dd><dt>Theme</dt><dd>' + escapeHtml(report.theme) + '</dd><dt>Revision</dt><dd>' + escapeHtml(report.revision) + '</dd></dl>';
|
|
2605
|
-
if (activeTab === 1) return diagnosticList(report.diagnostics);
|
|
2606
|
-
if (activeTab === 2) return dependencyReport(report.dependencies);
|
|
2607
|
-
if (activeTab === 3) return '<ul>' + (report.plugins.map((plugin) => '<li>' + escapeHtml(plugin) + '</li>').join("") || "<li>No plugins configured.</li>") + '</ul>';
|
|
2608
|
-
return outputReport(report.output);
|
|
2751
|
+
export const content = new ContentManager(
|
|
2752
|
+
createContentSource(config.content),
|
|
2753
|
+
[],
|
|
2754
|
+
{ config, plugins: config.plugins, isDevelopment: import.meta.env.DEV },
|
|
2755
|
+
);
|
|
2756
|
+
`;
|
|
2609
2757
|
}
|
|
2758
|
+
return `import { ContentManager } from "@riebeckite/core";
|
|
2759
|
+
import { createContentSource } from "@riebeckite/node";
|
|
2760
|
+
import { createDevelopmentTrace } from "@riebeckite/honox/runtime";
|
|
2761
|
+
import { config } from ${JSON.stringify(riebeckiteConfigModuleId)};
|
|
2762
|
+
|
|
2763
|
+
const trace = createDevelopmentTrace();
|
|
2764
|
+
export const content = new ContentManager(
|
|
2765
|
+
createContentSource(config.content),
|
|
2766
|
+
[],
|
|
2767
|
+
{
|
|
2768
|
+
config,
|
|
2769
|
+
plugins: config.plugins,
|
|
2770
|
+
isDevelopment: true,
|
|
2771
|
+
observability: trace.observability,
|
|
2772
|
+
traceRecorder: trace,
|
|
2773
|
+
},
|
|
2774
|
+
);
|
|
2775
|
+
`;
|
|
2610
2776
|
}
|
|
2611
2777
|
|
|
2612
|
-
|
|
2778
|
+
// src/content_watch.ts
|
|
2779
|
+
var CONTENT_RELOAD_DEBOUNCE_MS = 60;
|
|
2780
|
+
var configuredWatchers = /* @__PURE__ */ new WeakSet();
|
|
2781
|
+
function riebeckiteContentWatch(options) {
|
|
2613
2782
|
return {
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2783
|
+
name: "riebeckite-content-watch",
|
|
2784
|
+
apply: "serve",
|
|
2785
|
+
enforce: "post",
|
|
2786
|
+
configureServer(server) {
|
|
2787
|
+
if (configuredWatchers.has(server.watcher)) return;
|
|
2788
|
+
configuredWatchers.add(server.watcher);
|
|
2789
|
+
const appRoot = options.appRoot();
|
|
2790
|
+
const contentRoot = options.contentRoot();
|
|
2791
|
+
const exclude = options.exclude();
|
|
2792
|
+
const isContentFile = (file) => isPathInsideDirectory2(contentRoot, file);
|
|
2793
|
+
server.watcher.add(contentRoot);
|
|
2794
|
+
suppressRestartOnContentEvents(server, isContentFile);
|
|
2795
|
+
let timer;
|
|
2796
|
+
const invalidate = () => {
|
|
2797
|
+
if (timer) clearTimeout(timer);
|
|
2798
|
+
timer = setTimeout(() => {
|
|
2799
|
+
timer = void 0;
|
|
2800
|
+
invalidateApplicationRuntime(server, appRoot);
|
|
2801
|
+
options.onInvalidate?.(server);
|
|
2802
|
+
server.hot.send({ type: "full-reload" });
|
|
2803
|
+
}, CONTENT_RELOAD_DEBOUNCE_MS);
|
|
2804
|
+
};
|
|
2805
|
+
server.httpServer?.once("close", () => {
|
|
2806
|
+
if (timer) clearTimeout(timer);
|
|
2807
|
+
});
|
|
2808
|
+
const handle = (event) => (file) => {
|
|
2809
|
+
if (!isContentFile(file)) return;
|
|
2810
|
+
const logicalPath = toLogicalPath(contentRoot, file);
|
|
2811
|
+
if (isIgnoredContentPath2(logicalPath, exclude)) return;
|
|
2812
|
+
if (event === "change" && isSiteAssetPath(logicalPath)) {
|
|
2813
|
+
server.hot.send({ type: "full-reload" });
|
|
2814
|
+
return;
|
|
2815
|
+
}
|
|
2816
|
+
invalidate();
|
|
2817
|
+
};
|
|
2818
|
+
server.watcher.on("add", handle("add"));
|
|
2819
|
+
server.watcher.on("change", handle("change"));
|
|
2820
|
+
server.watcher.on("unlink", handle("unlink"));
|
|
2821
|
+
}
|
|
2617
2822
|
};
|
|
2618
2823
|
}
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
return '<ul>' + (diagnostics.map((diagnostic) =>
|
|
2622
|
-
'<li data-severity="' + escapeHtml(diagnostic.severity) + '"><b>' + escapeHtml(diagnostic.code) + '</b> ' + escapeHtml(diagnostic.message) + location(diagnostic) + '</li>'
|
|
2623
|
-
).join("") || "<li>No diagnostic findings.</li>") + '</ul>';
|
|
2624
|
-
}
|
|
2625
|
-
|
|
2626
|
-
function outputReport(output) {
|
|
2627
|
-
if (!output) return '<p class="status" aria-live="polite">Loading output plan…</p>';
|
|
2628
|
-
if (output.status !== "available") return unavailable("Output", output.reason);
|
|
2629
|
-
return '<dl>' +
|
|
2630
|
-
'<dt>Candidate</dt><dd>' + output.candidateOutputCount + '</dd>' +
|
|
2631
|
-
'<dt>Affected</dt><dd>' + output.affectedOutputCount + '</dd>' +
|
|
2632
|
-
'<dt>Unchanged</dt><dd>' + output.unchangedOutputCount + '</dd>' +
|
|
2633
|
-
'<dt>Removed</dt><dd>' + output.removedOutputCount + '</dd>' +
|
|
2634
|
-
'<dt>Full regeneration</dt><dd>' + (output.fullRegenerationRequired ? "required" : "not required") + '</dd>' +
|
|
2635
|
-
'<dt>Owner conflicts</dt><dd>' + output.conflicts.length + '</dd>' +
|
|
2636
|
-
'</dl>' +
|
|
2637
|
-
listedOutputs("Affected outputs", output.affected, output.hiddenAffectedCount) +
|
|
2638
|
-
listedOutputs("Removed outputs", output.removed, output.hiddenRemovedCount) +
|
|
2639
|
-
conflictList(output.conflicts);
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
function listedOutputs(title, outputs, hiddenCount) {
|
|
2643
|
-
if (outputs.length === 0) return "";
|
|
2644
|
-
return '<h3>' + escapeHtml(title) + '</h3><ul>' + outputs.map((output) =>
|
|
2645
|
-
'<li><code>' + escapeHtml(output.path) + '</code> <small>' + escapeHtml(output.kind) + ' · ' + escapeHtml(output.producer) + '</small></li>'
|
|
2646
|
-
).join("") + '</ul>' + (hiddenCount > 0 ? '<p class="more">' + hiddenCount + ' more not shown.</p>' : "");
|
|
2647
|
-
}
|
|
2648
|
-
|
|
2649
|
-
function conflictList(conflicts) {
|
|
2650
|
-
if (conflicts.length === 0) return "";
|
|
2651
|
-
return '<h3>Owner conflicts</h3><ul>' + conflicts.map((conflict) =>
|
|
2652
|
-
'<li><code>' + escapeHtml(conflict.path) + '</code> <small>' + escapeHtml(conflict.owners.join(", ")) + '</small></li>'
|
|
2653
|
-
).join("") + '</ul>';
|
|
2654
|
-
}
|
|
2655
|
-
|
|
2656
|
-
function dependencyReport(dependencies) {
|
|
2657
|
-
if (!dependencies) return '<p class="status" aria-live="polite">Loading dependencies…</p>';
|
|
2658
|
-
if (dependencies.status !== "available") return unavailable("Dependencies", dependencies.reason);
|
|
2659
|
-
return '<dl>' +
|
|
2660
|
-
'<dt>Outputs</dt><dd>' + dependencies.outputCount + '</dd>' +
|
|
2661
|
-
'<dt>With dependencies</dt><dd>' + dependencies.dependentOutputCount + '</dd>' +
|
|
2662
|
-
'<dt>Dependencies</dt><dd>' + dependencies.dependencyCount + '</dd>' +
|
|
2663
|
-
'<dt>Unknown outputs</dt><dd>' + dependencies.unknownOutputCount + '</dd>' +
|
|
2664
|
-
'</dl>' +
|
|
2665
|
-
(dependencies.kinds.length === 0 ? "<p>No output dependencies.</p>" :
|
|
2666
|
-
'<h3>Kinds</h3><ul>' + dependencies.kinds.map((kind) =>
|
|
2667
|
-
'<li>' + escapeHtml(kind.kind) + ' <small>' + kind.count + '</small></li>'
|
|
2668
|
-
).join("") + '</ul>') +
|
|
2669
|
-
(dependencies.outputs.length === 0 ? "" :
|
|
2670
|
-
'<h3>Outputs</h3><ul>' + dependencies.outputs.map((output) =>
|
|
2671
|
-
'<li><code>' + escapeHtml(output.path) + '</code><br><small>' + escapeHtml(output.dependencies.join(", ")) + '</small></li>'
|
|
2672
|
-
).join("") + '</ul>') +
|
|
2673
|
-
(dependencies.hiddenOutputCount > 0 ? '<p class="more">' + dependencies.hiddenOutputCount + ' more outputs not shown.</p>' : "");
|
|
2674
|
-
}
|
|
2675
|
-
|
|
2676
|
-
function unavailable(subject, capability) {
|
|
2677
|
-
return '<p class="partial">' + escapeHtml(subject) + ' unavailable: ' + escapeHtml(capability) + '.</p>';
|
|
2678
|
-
}
|
|
2679
|
-
|
|
2680
|
-
function renderFailure(root, message) {
|
|
2681
|
-
root.innerHTML = '<style>' + styles + '</style><section role="dialog" aria-modal="false" aria-labelledby="rb-failure-title"><header><strong id="rb-failure-title">Riebeckite Inspector</strong><button type="button" data-close aria-label="Close inspector">Close</button></header><p class="failure" aria-live="polite">' + escapeHtml(message) + '</p></section>';
|
|
2824
|
+
function isSiteAssetPath(logicalPath) {
|
|
2825
|
+
return isImagePath2(logicalPath) || isAttachmentPath(logicalPath);
|
|
2682
2826
|
}
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2827
|
+
function invalidateApplicationRuntime(server, appRoot) {
|
|
2828
|
+
const moduleGraph = server.environments?.ssr?.moduleGraph;
|
|
2829
|
+
if (!moduleGraph) return 0;
|
|
2830
|
+
const appDirectory = path9.join(appRoot, "app") + path9.sep;
|
|
2831
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2832
|
+
const timestamp = Date.now();
|
|
2833
|
+
let invalidated = 0;
|
|
2834
|
+
for (const mod of moduleGraph.idToModuleMap.values()) {
|
|
2835
|
+
if (!isApplicationRuntimeModule(mod, appDirectory)) continue;
|
|
2836
|
+
moduleGraph.invalidateModule(mod, seen, timestamp);
|
|
2837
|
+
invalidated += 1;
|
|
2838
|
+
}
|
|
2839
|
+
return invalidated;
|
|
2687
2840
|
}
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
return
|
|
2841
|
+
function isApplicationRuntimeModule(mod, appDirectory) {
|
|
2842
|
+
if (mod.file && isPathInsideDirectory2(appDirectory, mod.file)) return true;
|
|
2843
|
+
return isRiebeckiteRuntimeModuleId(mod.id);
|
|
2691
2844
|
}
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2845
|
+
function suppressRestartOnContentEvents(server, isContentFile) {
|
|
2846
|
+
for (const event of ["add", "unlink"]) {
|
|
2847
|
+
const listeners = server.watcher.rawListeners(event).slice();
|
|
2848
|
+
server.watcher.removeAllListeners(event);
|
|
2849
|
+
for (const listener of listeners) {
|
|
2850
|
+
server.watcher.on(event, (file) => {
|
|
2851
|
+
if (isContentFile(file)) return;
|
|
2852
|
+
listener(file);
|
|
2853
|
+
});
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2695
2856
|
}
|
|
2696
2857
|
|
|
2697
2858
|
// src/vite_runner.ts
|
|
2698
2859
|
import fs7 from "node:fs/promises";
|
|
2699
|
-
import
|
|
2700
|
-
import
|
|
2860
|
+
import os from "node:os";
|
|
2861
|
+
import path10 from "node:path";
|
|
2862
|
+
import { build as build2, createServer } from "vite";
|
|
2701
2863
|
var viteConfigFileNames = [
|
|
2702
2864
|
"vite.config.ts",
|
|
2703
2865
|
"vite.config.js",
|
|
@@ -2730,10 +2892,10 @@ var HonoxApplicationRootError = class extends Error {
|
|
|
2730
2892
|
}
|
|
2731
2893
|
};
|
|
2732
2894
|
async function resolveHonoxApplication(options) {
|
|
2733
|
-
const configRoot =
|
|
2734
|
-
const appRoot = options.appRoot ?
|
|
2735
|
-
const workspaceRoot = options.workspaceRoot ?? await
|
|
2736
|
-
const configFile =
|
|
2895
|
+
const configRoot = path10.resolve(options.configRoot);
|
|
2896
|
+
const appRoot = options.appRoot ? path10.resolve(options.appRoot) : await resolveHonoxApplicationRoot(configRoot, options.startDirectory);
|
|
2897
|
+
const workspaceRoot = options.workspaceRoot ?? await findWorkspaceRoot2(configRoot);
|
|
2898
|
+
const configFile = path10.resolve(
|
|
2737
2899
|
configRoot,
|
|
2738
2900
|
options.configFile ?? "riebeckite.config.ts"
|
|
2739
2901
|
);
|
|
@@ -2751,25 +2913,25 @@ async function resolveHonoxApplication(options) {
|
|
|
2751
2913
|
contentRoot: config.content.directory
|
|
2752
2914
|
};
|
|
2753
2915
|
}
|
|
2754
|
-
async function
|
|
2916
|
+
async function findWorkspaceRoot2(configRoot) {
|
|
2755
2917
|
try {
|
|
2756
|
-
const workspaceConfig =
|
|
2918
|
+
const workspaceConfig = path10.join(configRoot, "pnpm-workspace.yaml");
|
|
2757
2919
|
return (await fs7.stat(workspaceConfig)).isFile() ? configRoot : void 0;
|
|
2758
2920
|
} catch {
|
|
2759
2921
|
return void 0;
|
|
2760
2922
|
}
|
|
2761
2923
|
}
|
|
2762
2924
|
async function startHonoxDevServer(options) {
|
|
2763
|
-
const root =
|
|
2925
|
+
const root = path10.resolve(options.root);
|
|
2764
2926
|
await withWorkingDirectory(root, async () => {
|
|
2765
|
-
const server = await
|
|
2927
|
+
const server = await createServer({ root, server: options.server });
|
|
2766
2928
|
const restartFiles = new Set(
|
|
2767
|
-
options.restartOnChange?.map((file) =>
|
|
2929
|
+
options.restartOnChange?.map((file) => path10.resolve(file))
|
|
2768
2930
|
);
|
|
2769
2931
|
if (restartFiles.size > 0) {
|
|
2770
2932
|
server.watcher.add([...restartFiles]);
|
|
2771
2933
|
server.watcher.on("change", (file) => {
|
|
2772
|
-
if (restartFiles.has(
|
|
2934
|
+
if (restartFiles.has(path10.resolve(file))) void server.restart();
|
|
2773
2935
|
});
|
|
2774
2936
|
}
|
|
2775
2937
|
await server.listen(options.server?.port);
|
|
@@ -2794,20 +2956,74 @@ async function startHonoxDevServer(options) {
|
|
|
2794
2956
|
});
|
|
2795
2957
|
}
|
|
2796
2958
|
async function buildHonoxApplication(options) {
|
|
2797
|
-
const root =
|
|
2959
|
+
const root = path10.resolve(options.root);
|
|
2798
2960
|
await withWorkingDirectory(root, async () => {
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2961
|
+
if (!options.reuseClientBuild) {
|
|
2962
|
+
await runTraced(
|
|
2963
|
+
options.tracer,
|
|
2964
|
+
"integration.honox.client_build",
|
|
2965
|
+
() => build2({ root, mode: "client" })
|
|
2966
|
+
);
|
|
2967
|
+
}
|
|
2804
2968
|
await runTraced(
|
|
2805
2969
|
options.tracer,
|
|
2806
2970
|
"integration.honox.server_build",
|
|
2807
|
-
() =>
|
|
2971
|
+
() => buildServerWithMetrics(root, options.tracer)
|
|
2808
2972
|
);
|
|
2809
2973
|
});
|
|
2810
2974
|
}
|
|
2975
|
+
async function canReuseClientBuild(input) {
|
|
2976
|
+
const root = path10.resolve(input.root);
|
|
2977
|
+
const cache = await loadOutputCacheMetadata(
|
|
2978
|
+
path10.join(root, ".riebeckite", "ssg-output-cache.json")
|
|
2979
|
+
);
|
|
2980
|
+
if (!cache?.bundleFingerprint || !cache.configFile) return false;
|
|
2981
|
+
if (cache.bundleFingerprint !== await computeBundleFingerprint(root, cache.configFile)) {
|
|
2982
|
+
return false;
|
|
2983
|
+
}
|
|
2984
|
+
return await verifyClientBuildArtifacts({
|
|
2985
|
+
outDir: input.outputDirectory,
|
|
2986
|
+
expectedInventory: cache.finalOutputInventory ?? {}
|
|
2987
|
+
});
|
|
2988
|
+
}
|
|
2989
|
+
async function buildServerWithMetrics(root, tracer) {
|
|
2990
|
+
if (!tracer) {
|
|
2991
|
+
await build2({ root });
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
const previousMetricsFile = process.env.RIEBECKITE_SSG_METRICS_FILE;
|
|
2995
|
+
const metricsDirectory = previousMetricsFile ? void 0 : await fs7.mkdtemp(path10.join(os.tmpdir(), "riebeckite-ssg-metrics-"));
|
|
2996
|
+
const metricsFile = previousMetricsFile ?? path10.join(metricsDirectory, "metrics.json");
|
|
2997
|
+
if (!previousMetricsFile)
|
|
2998
|
+
process.env.RIEBECKITE_SSG_METRICS_FILE = metricsFile;
|
|
2999
|
+
try {
|
|
3000
|
+
await build2({ root });
|
|
3001
|
+
await reportSsgTimings(tracer, metricsFile);
|
|
3002
|
+
} finally {
|
|
3003
|
+
if (previousMetricsFile === void 0) {
|
|
3004
|
+
delete process.env.RIEBECKITE_SSG_METRICS_FILE;
|
|
3005
|
+
}
|
|
3006
|
+
if (metricsDirectory)
|
|
3007
|
+
await fs7.rm(metricsDirectory, { recursive: true, force: true });
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
async function reportSsgTimings(tracer, metricsFile) {
|
|
3011
|
+
try {
|
|
3012
|
+
const metrics = JSON.parse(await fs7.readFile(metricsFile, "utf8"));
|
|
3013
|
+
if (!metrics || typeof metrics !== "object") return;
|
|
3014
|
+
const timings = metrics.timingsMs;
|
|
3015
|
+
if (!timings || typeof timings !== "object") return;
|
|
3016
|
+
for (const [name, durationMs] of Object.entries(timings)) {
|
|
3017
|
+
if (typeof durationMs !== "number" || !Number.isFinite(durationMs))
|
|
3018
|
+
continue;
|
|
3019
|
+
tracer.event("integration.timing", {
|
|
3020
|
+
name: `integration.honox.server_build.ssg.${name}`,
|
|
3021
|
+
durationMs
|
|
3022
|
+
});
|
|
3023
|
+
}
|
|
3024
|
+
} catch {
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
2811
3027
|
async function withWorkingDirectory(root, task) {
|
|
2812
3028
|
const previousDirectory = process.cwd();
|
|
2813
3029
|
if (previousDirectory === root) return await task();
|
|
@@ -2822,16 +3038,16 @@ async function runTraced(tracer, name, buildTask) {
|
|
|
2822
3038
|
return tracer ? await tracer.span(name, {}, buildTask) : await buildTask();
|
|
2823
3039
|
}
|
|
2824
3040
|
function waitForShutdown(server) {
|
|
2825
|
-
let
|
|
3041
|
+
let resolve5 = () => {
|
|
2826
3042
|
};
|
|
2827
3043
|
let closing = false;
|
|
2828
3044
|
const close = () => {
|
|
2829
3045
|
if (closing) return;
|
|
2830
3046
|
closing = true;
|
|
2831
|
-
void server.close().finally(
|
|
3047
|
+
void server.close().finally(resolve5);
|
|
2832
3048
|
};
|
|
2833
3049
|
const promise = new Promise((resolvePromise) => {
|
|
2834
|
-
|
|
3050
|
+
resolve5 = resolvePromise;
|
|
2835
3051
|
});
|
|
2836
3052
|
process.once("SIGINT", close);
|
|
2837
3053
|
process.once("SIGTERM", close);
|
|
@@ -2858,29 +3074,29 @@ async function findViteApplicationRoots(root, startDirectory) {
|
|
|
2858
3074
|
if (!entry.isDirectory() || ignoredApplicationRootDirectoryNames.has(entry.name)) {
|
|
2859
3075
|
continue;
|
|
2860
3076
|
}
|
|
2861
|
-
directories.push(
|
|
3077
|
+
directories.push(path10.join(directory, entry.name));
|
|
2862
3078
|
}
|
|
2863
3079
|
}
|
|
2864
3080
|
return applicationRoots;
|
|
2865
3081
|
}
|
|
2866
3082
|
async function findViteApplicationRootFrom(startDirectory, configRoot) {
|
|
2867
|
-
let directory =
|
|
3083
|
+
let directory = path10.resolve(startDirectory);
|
|
2868
3084
|
while (isWithin(configRoot, directory)) {
|
|
2869
3085
|
if (await hasViteConfig(directory)) return directory;
|
|
2870
|
-
const parent =
|
|
3086
|
+
const parent = path10.dirname(directory);
|
|
2871
3087
|
if (parent === directory) return void 0;
|
|
2872
3088
|
directory = parent;
|
|
2873
3089
|
}
|
|
2874
3090
|
return void 0;
|
|
2875
3091
|
}
|
|
2876
3092
|
function isWithin(parent, target) {
|
|
2877
|
-
const
|
|
2878
|
-
return
|
|
3093
|
+
const relative5 = path10.relative(parent, target);
|
|
3094
|
+
return relative5 === "" || !relative5.startsWith("..") && !path10.isAbsolute(relative5);
|
|
2879
3095
|
}
|
|
2880
3096
|
async function hasViteConfig(directory) {
|
|
2881
3097
|
for (const fileName of viteConfigFileNames) {
|
|
2882
3098
|
try {
|
|
2883
|
-
if ((await fs7.stat(
|
|
3099
|
+
if ((await fs7.stat(path10.join(directory, fileName))).isFile()) return true;
|
|
2884
3100
|
} catch {
|
|
2885
3101
|
}
|
|
2886
3102
|
}
|
|
@@ -2915,7 +3131,7 @@ function riebeckite(options = {}, onApplicationResolved) {
|
|
|
2915
3131
|
{
|
|
2916
3132
|
name: "riebeckite-host-integration",
|
|
2917
3133
|
async config(userConfig) {
|
|
2918
|
-
const root = userConfig.root ?
|
|
3134
|
+
const root = userConfig.root ? path11.resolve(userConfig.root) : process.cwd();
|
|
2919
3135
|
const appRoot = options.appRoot ?? root;
|
|
2920
3136
|
const resolvedApplication = await resolveHonoxApplication({
|
|
2921
3137
|
configRoot: options.configRoot ?? appRoot,
|
|
@@ -2927,12 +3143,12 @@ function riebeckite(options = {}, onApplicationResolved) {
|
|
|
2927
3143
|
application = resolvedApplication;
|
|
2928
3144
|
onApplicationResolved?.(resolvedApplication);
|
|
2929
3145
|
writeRiebeckiteAssetEntries(resolvedConfig, {
|
|
2930
|
-
frameworkStyles:
|
|
3146
|
+
frameworkStyles: path11.join(
|
|
2931
3147
|
appRoot,
|
|
2932
3148
|
"app/.riebeckite/framework-styles.css"
|
|
2933
3149
|
),
|
|
2934
|
-
pluginStyles:
|
|
2935
|
-
themeStyles:
|
|
3150
|
+
pluginStyles: path11.join(appRoot, "app/.riebeckite/plugin-styles.css"),
|
|
3151
|
+
themeStyles: path11.join(appRoot, "app/.riebeckite/theme-styles.css")
|
|
2936
3152
|
});
|
|
2937
3153
|
return {
|
|
2938
3154
|
define: {
|
|
@@ -2961,9 +3177,17 @@ function riebeckite(options = {}, onApplicationResolved) {
|
|
|
2961
3177
|
riebeckiteContentWatch({
|
|
2962
3178
|
appRoot: () => requireApplication(application).appRoot,
|
|
2963
3179
|
contentRoot: () => requireApplication(application).contentRoot,
|
|
2964
|
-
exclude: () => getConfig().content.exclude ?? []
|
|
3180
|
+
exclude: () => getConfig().content.exclude ?? [],
|
|
3181
|
+
onInvalidate: invalidateDevelopmentInspector
|
|
2965
3182
|
}),
|
|
2966
|
-
riebeckiteDevelopmentInspector(() => requireApplication(application)
|
|
3183
|
+
riebeckiteDevelopmentInspector(() => requireApplication(application), {
|
|
3184
|
+
async getSnapshot(server) {
|
|
3185
|
+
const { appRoot } = requireApplication(application);
|
|
3186
|
+
if (!isContentModuleLoaded(server, appRoot)) return void 0;
|
|
3187
|
+
const module = await loadContentModule(server, appRoot);
|
|
3188
|
+
return module.content?.getCompletedBuildSnapshot?.();
|
|
3189
|
+
}
|
|
3190
|
+
})
|
|
2967
3191
|
];
|
|
2968
3192
|
}
|
|
2969
3193
|
function requireApplication(application) {
|
|
@@ -3009,10 +3233,13 @@ function riebeckiteSsrExternals(externals, siteExternals = () => []) {
|
|
|
3009
3233
|
}
|
|
3010
3234
|
export {
|
|
3011
3235
|
buildHonoxApplication,
|
|
3236
|
+
canReuseClientBuild,
|
|
3012
3237
|
createNoChangeFastPathOutputMetrics,
|
|
3013
3238
|
createRiebeckiteSsg,
|
|
3014
3239
|
defaultSsgEntry,
|
|
3015
3240
|
defaultSsrExternals,
|
|
3241
|
+
fingerprintDirectory,
|
|
3242
|
+
fingerprintOutputDirectory,
|
|
3016
3243
|
loadRiebeckiteConfig,
|
|
3017
3244
|
replaceHonoxIslandDependencyPlugin,
|
|
3018
3245
|
resolveHonoxApplication,
|