@riebeckite/honox 0.0.52 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  // src/config_loader.ts
2
+ import { createHash } from "node:crypto";
2
3
  import fs3 from "node:fs/promises";
4
+ import { createRequire } from "node:module";
5
+ import { tmpdir } from "node:os";
3
6
  import path4 from "node:path";
4
- import { build as buildWithEsbuild } from "esbuild";
5
7
 
6
8
  // src/site_externals.ts
7
9
  import fs from "node:fs";
@@ -30,8 +32,8 @@ function siteRiebeckiteExternals(siteRoot) {
30
32
  // src/workspace_packages.ts
31
33
  import fs2 from "node:fs";
32
34
  import path2 from "node:path";
33
- import { escapeRegExp } from "@riebeckite/core";
34
- function createWorkspacePackageAliases(workspaceRoot) {
35
+ async function createWorkspacePackageAliases(workspaceRoot) {
36
+ const { escapeRegExp } = await import("@riebeckite/core");
35
37
  const packagesRoot = path2.join(workspaceRoot, "packages");
36
38
  if (!fs2.existsSync(packagesRoot)) return [];
37
39
  return findWorkspacePackageDirectories(packagesRoot).flatMap(
@@ -42,13 +44,21 @@ function createWorkspacePackageAliases(workspaceRoot) {
42
44
  return createPackageAliases(
43
45
  packageJson.name,
44
46
  packageDirectory,
45
- packageJson
47
+ packageJson,
48
+ escapeRegExp
46
49
  );
47
50
  }
48
51
  );
49
52
  }
50
- function workspacePackageResolver(workspaceRoot) {
51
- const aliases = createWorkspacePackageAliases(workspaceRoot);
53
+ function workspacePackageJsonPaths(workspaceRoot) {
54
+ const packagesRoot = path2.join(workspaceRoot, "packages");
55
+ if (!fs2.existsSync(packagesRoot)) return [];
56
+ return findWorkspacePackageDirectories(packagesRoot).map(
57
+ (packageDirectory) => path2.join(packageDirectory, "package.json")
58
+ );
59
+ }
60
+ async function workspacePackageResolver(workspaceRoot) {
61
+ const aliases = await createWorkspacePackageAliases(workspaceRoot);
52
62
  return {
53
63
  name: "workspace-package-resolver",
54
64
  setup(buildApi) {
@@ -68,7 +78,7 @@ function findWorkspacePackageDirectories(rootDirectory) {
68
78
  (entry) => findWorkspacePackageDirectories(path2.join(rootDirectory, entry.name))
69
79
  );
70
80
  }
71
- function createPackageAliases(packageName, packageDirectory, packageJson) {
81
+ function createPackageAliases(packageName, packageDirectory, packageJson, escapeRegExp) {
72
82
  const aliases = [];
73
83
  const mainEntry = resolveExportsEntry(packageJson.exports) ?? packageJson.main;
74
84
  if (mainEntry) {
@@ -133,9 +143,6 @@ function resolveExportTarget(target) {
133
143
  import path3 from "node:path";
134
144
 
135
145
  // src/spa_diagnostics.ts
136
- import {
137
- definePlugin
138
- } from "@riebeckite/core";
139
146
  var SPA_DIAGNOSTICS_PLUGIN_NAME = "riebeckite:spa-diagnostics";
140
147
  var MAIN_CONTENT_PATTERN = /<main\b[^>]*\bid=["']main-content["']/iu;
141
148
  var REDIRECT_PATTERN = /<meta\b[^>]*\bhttp-equiv=["']refresh["'][^>]*\bcontent=["'][^"']*\burl=/iu;
@@ -153,10 +160,10 @@ function inspectSpaPage(page) {
153
160
  ];
154
161
  }
155
162
  function spaDiagnostics() {
156
- return definePlugin({
163
+ return {
157
164
  name: SPA_DIAGNOSTICS_PLUGIN_NAME,
158
165
  inspectGeneratedHtml: inspectSpaPage
159
- });
166
+ };
160
167
  }
161
168
 
162
169
  // src/resolved_config.ts
@@ -175,39 +182,190 @@ function resolveHonoxConfig(config, appRoot) {
175
182
 
176
183
  // src/config_loader.ts
177
184
  var riebeckiteConfigTemporaryDirectory = ".riebeckite-config-";
185
+ var cacheFormatVersion = 2;
186
+ var cacheDirectoryName = path4.join(".riebeckite", "config-bundle");
187
+ var outputNamePattern = /^config-[0-9a-f]{16}\.mjs$/;
188
+ var failedCacheImports = /* @__PURE__ */ new Set();
178
189
  async function loadRiebeckiteConfig(options) {
179
- const configFile = options.configFile ?? "riebeckite.config.ts";
180
- const temporaryDirectory = await fs3.mkdtemp(
181
- path4.join(options.configRoot, riebeckiteConfigTemporaryDirectory)
190
+ const mode = options.workspaceRoot ? "workspace" : "site";
191
+ const cacheDirectory = path4.join(options.configRoot, cacheDirectoryName);
192
+ const configFilePath = path4.resolve(
193
+ options.configRoot,
194
+ options.configFile ?? "riebeckite.config.ts"
182
195
  );
183
- const outputFile = path4.join(temporaryDirectory, "config.mjs");
196
+ const packageJsonListDigest = digestPackageJsonList(
197
+ options.workspaceRoot ? workspacePackageJsonPaths(options.workspaceRoot) : [path4.join(options.configRoot, "package.json")]
198
+ );
199
+ const cached = await loadCachedConfig({
200
+ cacheDirectory,
201
+ mode,
202
+ workspaceRoot: options.workspaceRoot ?? null,
203
+ configFile: configFilePath,
204
+ packageJsonListDigest
205
+ });
206
+ if (cached) return cached;
207
+ const esbuild = await import("esbuild");
208
+ const resolverPackageJsonPaths = options.workspaceRoot ? workspacePackageJsonPaths(options.workspaceRoot) : [path4.join(options.configRoot, "package.json")];
209
+ const result = await esbuild.build({
210
+ stdin: {
211
+ contents: `
212
+ import rawConfig from ${JSON.stringify(
213
+ path4.resolve(
214
+ options.configRoot,
215
+ options.configFile ?? "riebeckite.config.ts"
216
+ )
217
+ )};
218
+ import { resolveConfigModule } from "@riebeckite/core";
219
+ export default resolveConfigModule(rawConfig);
220
+ `,
221
+ resolveDir: options.configRoot,
222
+ loader: "ts"
223
+ },
224
+ bundle: true,
225
+ write: false,
226
+ metafile: true,
227
+ platform: "node",
228
+ format: "esm",
229
+ external: options.workspaceRoot ? ["@riebeckite/og-image"] : ["@riebeckite/core", ...siteRiebeckiteExternals(options.configRoot)],
230
+ banner: {
231
+ js: 'import { createRequire as __riebeckiteCreateRequire } from "node:module"; const require = __riebeckiteCreateRequire(import.meta.url);'
232
+ },
233
+ plugins: options.workspaceRoot ? [await workspacePackageResolver(options.workspaceRoot)] : []
234
+ });
235
+ const metafile = result.metafile;
236
+ if (!metafile) throw new Error("esbuild returned no config bundle metadata.");
237
+ const inputMap = /* @__PURE__ */ new Map();
238
+ for (const input of Object.keys(metafile.inputs)) {
239
+ if (input === "<stdin>") continue;
240
+ const inputPath = path4.isAbsolute(input) ? input : path4.resolve(process.cwd(), input);
241
+ if (!inputMap.has(inputPath)) {
242
+ inputMap.set(inputPath, await digestFile(inputPath));
243
+ }
244
+ }
245
+ for (const packageJsonPath of resolverPackageJsonPaths) {
246
+ if (!inputMap.has(packageJsonPath)) {
247
+ inputMap.set(packageJsonPath, await digestFile(packageJsonPath));
248
+ }
249
+ }
250
+ const inputs = [...inputMap.entries()].map(([inputPath, digest]) => ({ path: inputPath, digest })).sort(
251
+ (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0
252
+ );
253
+ const fingerprint = createHash("sha256").update(
254
+ JSON.stringify({
255
+ version: cacheFormatVersion,
256
+ esbuildVersion: esbuild.version,
257
+ mode,
258
+ configFile: configFilePath,
259
+ packageJsonListDigest,
260
+ inputs
261
+ })
262
+ ).digest("hex").slice(0, 16);
263
+ const bundle = result.outputFiles?.[0]?.contents;
264
+ if (!bundle) throw new Error("esbuild returned no config bundle output.");
265
+ const output = `config-${fingerprint}.mjs`;
266
+ const outputPath = path4.join(cacheDirectory, output);
267
+ let outputUrl = pathToFileUrl(outputPath);
268
+ if (failedCacheImports.has(outputUrl)) outputUrl += `?retry=${Date.now()}`;
269
+ let wroteToCache = true;
184
270
  try {
185
- await buildWithEsbuild({
186
- stdin: {
187
- contents: `
188
- import rawConfig from ${JSON.stringify(path4.resolve(options.configRoot, configFile))};
189
- import { resolveConfigModule } from "@riebeckite/core";
190
- export default resolveConfigModule(rawConfig);
191
- `,
192
- resolveDir: options.configRoot,
193
- loader: "ts"
194
- },
195
- outfile: outputFile,
196
- bundle: true,
197
- platform: "node",
198
- format: "esm",
199
- external: options.workspaceRoot ? ["@riebeckite/og-image"] : ["@riebeckite/core", ...siteRiebeckiteExternals(options.configRoot)],
200
- banner: {
201
- js: 'import { createRequire as __riebeckiteCreateRequire } from "node:module"; const require = __riebeckiteCreateRequire(import.meta.url);'
202
- },
203
- plugins: options.workspaceRoot ? [workspacePackageResolver(options.workspaceRoot)] : []
271
+ await fs3.mkdir(cacheDirectory, { recursive: true });
272
+ await fs3.writeFile(outputPath, bundle);
273
+ } catch {
274
+ wroteToCache = false;
275
+ outputUrl = await writeFallbackBundle(bundle, output);
276
+ }
277
+ const module = await import(outputUrl);
278
+ if (wroteToCache) {
279
+ await fs3.writeFile(
280
+ path4.join(cacheDirectory, "manifest.json"),
281
+ `${JSON.stringify({
282
+ version: cacheFormatVersion,
283
+ esbuildVersion: esbuild.version,
284
+ mode,
285
+ workspaceRoot: options.workspaceRoot ?? null,
286
+ configFile: configFilePath,
287
+ packageJsonListDigest,
288
+ output,
289
+ inputs
290
+ })}
291
+ `,
292
+ "utf8"
293
+ ).catch(() => {
204
294
  });
205
- const module = await import(`${pathToFileUrl(outputFile)}?t=${Date.now()}`);
295
+ }
296
+ failedCacheImports.delete(pathToFileUrl(outputPath));
297
+ return module.default;
298
+ }
299
+ async function writeFallbackBundle(bundle, name) {
300
+ const fallbackDirectory = await fs3.mkdtemp(
301
+ path4.join(tmpdir(), "riebeckite-config-")
302
+ );
303
+ const fallbackPath = path4.join(fallbackDirectory, name);
304
+ await fs3.writeFile(fallbackPath, bundle);
305
+ return pathToFileUrl(fallbackPath);
306
+ }
307
+ async function loadCachedConfig(cache) {
308
+ let manifest;
309
+ try {
310
+ manifest = JSON.parse(
311
+ await fs3.readFile(
312
+ path4.join(cache.cacheDirectory, "manifest.json"),
313
+ "utf8"
314
+ )
315
+ );
316
+ } catch {
317
+ return null;
318
+ }
319
+ if (typeof manifest !== "object" || manifest === null || typeof manifest.output !== "string" || !outputNamePattern.test(manifest.output) || !Array.isArray(manifest.inputs) || !manifest.inputs.every(
320
+ (input) => typeof input?.path === "string" && typeof input?.digest !== "undefined"
321
+ )) {
322
+ return null;
323
+ }
324
+ if (manifest.version !== cacheFormatVersion || manifest.mode !== cache.mode || manifest.workspaceRoot !== cache.workspaceRoot || manifest.configFile !== cache.configFile || manifest.packageJsonListDigest !== cache.packageJsonListDigest || manifest.esbuildVersion !== await readEsbuildVersion()) {
325
+ return null;
326
+ }
327
+ const currentDigests = await Promise.all(
328
+ manifest.inputs.map((input) => digestFile(input.path))
329
+ );
330
+ if (manifest.inputs.some(
331
+ (input, index) => input.digest !== currentDigests[index]
332
+ )) {
333
+ return null;
334
+ }
335
+ const outputUrl = pathToFileUrl(
336
+ path4.join(cache.cacheDirectory, manifest.output)
337
+ );
338
+ try {
339
+ const module = await import(outputUrl);
206
340
  return module.default;
207
- } finally {
208
- await fs3.rm(temporaryDirectory, { recursive: true, force: true });
341
+ } catch {
342
+ failedCacheImports.add(outputUrl);
343
+ return null;
344
+ }
345
+ }
346
+ async function readEsbuildVersion() {
347
+ try {
348
+ const require2 = createRequire(import.meta.url);
349
+ const packageJsonPath = require2.resolve("esbuild/package.json");
350
+ const packageJson = JSON.parse(
351
+ await fs3.readFile(packageJsonPath, "utf8")
352
+ );
353
+ return packageJson.version ?? null;
354
+ } catch {
355
+ return null;
209
356
  }
210
357
  }
358
+ async function digestFile(filePath) {
359
+ try {
360
+ return createHash("sha256").update(await fs3.readFile(filePath)).digest("hex");
361
+ } catch {
362
+ return null;
363
+ }
364
+ }
365
+ function digestPackageJsonList(paths) {
366
+ const sorted = [...paths].sort();
367
+ return createHash("sha256").update(JSON.stringify(sorted)).digest("hex");
368
+ }
211
369
  function pathToFileUrl(filePath) {
212
370
  return `file:///${filePath.replace(/\\/g, "/").replace(/^([A-Za-z]):/, "$1:")}`;
213
371
  }
@@ -215,7 +373,6 @@ function pathToFileUrl(filePath) {
215
373
  // src/honox_islands.ts
216
374
  import fs4 from "node:fs/promises";
217
375
  import path5 from "node:path";
218
- import { parse } from "@babel/parser";
219
376
  var honoxIslandDependencyPluginName = "inject-importing-islands";
220
377
  var importingIslandsExport = "__importing_islands";
221
378
  function replaceHonoxIslandDependencyPlugin(plugins) {
@@ -224,7 +381,8 @@ function replaceHonoxIslandDependencyPlugin(plugins) {
224
381
  scopedIslandDependencyPlugin()
225
382
  ];
226
383
  }
227
- function injectRiebeckiteClientBundle(getConfig) {
384
+ function injectRiebeckiteClientBundle(getConfig, ensure = async () => {
385
+ }) {
228
386
  let rendererPath = "";
229
387
  return {
230
388
  name: "riebeckite-inject-client-bundle",
@@ -232,7 +390,8 @@ function injectRiebeckiteClientBundle(getConfig) {
232
390
  configResolved(config) {
233
391
  rendererPath = path5.join(config.root, "app", "routes", "_renderer");
234
392
  },
235
- transform(sourceCode, id) {
393
+ async transform(sourceCode, id) {
394
+ await ensure();
236
395
  if (!requiresClientBundle(getConfig()) || !isRendererModule(toFilePath(id), rendererPath) || sourceCode.includes(`export const ${importingIslandsExport}`)) {
237
396
  return;
238
397
  }
@@ -292,7 +451,7 @@ export const ${importingIslandsExport} = true;
292
451
  if (visited.has(currentModulePath)) return false;
293
452
  visited.add(currentModulePath);
294
453
  if (isInDirectory(currentModulePath, islandDirectory)) return true;
295
- const importSources = getStaticImportSources(currentSourceCode);
454
+ const importSources = await getStaticImportSources(currentSourceCode);
296
455
  for (const importSource of importSources) {
297
456
  const resolved = await pluginContext.resolve(
298
457
  importSource,
@@ -317,7 +476,8 @@ export const ${importingIslandsExport} = true;
317
476
  return visit(modulePath, sourceCode);
318
477
  }
319
478
  }
320
- function getStaticImportSources(sourceCode) {
479
+ async function getStaticImportSources(sourceCode) {
480
+ const { parse } = await import("@babel/parser");
321
481
  const ast = parse(sourceCode, {
322
482
  sourceType: "module",
323
483
  plugins: ["typescript", "jsx"]
@@ -346,7 +506,7 @@ function isRendererModule(filePath, rendererPath) {
346
506
  }
347
507
 
348
508
  // src/ssg/inventory.ts
349
- import { createHash } from "node:crypto";
509
+ import { createHash as createHash2 } from "node:crypto";
350
510
  import { readdir, readFile } from "node:fs/promises";
351
511
  import { dirname, join, relative as relative2 } from "node:path";
352
512
  import { performance } from "node:perf_hooks";
@@ -396,7 +556,7 @@ async function computeAppFingerprint(root, configFile) {
396
556
  files.push(join(root, name));
397
557
  }
398
558
  files.sort();
399
- const hash = createHash("sha256");
559
+ const hash = createHash2("sha256");
400
560
  for (const file of files) {
401
561
  let content;
402
562
  try {
@@ -412,7 +572,7 @@ async function computeAppFingerprint(root, configFile) {
412
572
  return hash.digest("hex");
413
573
  }
414
574
  async function computeBundleFingerprint(root, configFile) {
415
- const hash = createHash("sha256");
575
+ const hash = createHash2("sha256");
416
576
  hash.update(await computeAppFingerprint(root, configFile));
417
577
  const files = [
418
578
  ...await findBundleInputFiles(root),
@@ -436,7 +596,7 @@ async function fingerprintDirectory(directory) {
436
596
  );
437
597
  }
438
598
  function fingerprintOutputInventory(inventory) {
439
- const hash = createHash("sha256");
599
+ const hash = createHash2("sha256");
440
600
  for (const [path14, checksum] of Object.entries(inventory).sort(
441
601
  ([left], [right]) => left.localeCompare(right)
442
602
  )) {
@@ -445,7 +605,7 @@ function fingerprintOutputInventory(inventory) {
445
605
  return hash.digest("hex");
446
606
  }
447
607
  function fingerprintOutputContent(content) {
448
- return createHash("sha256").update(content).digest("hex");
608
+ return createHash2("sha256").update(content).digest("hex");
449
609
  }
450
610
  async function fingerprintOutputDirectory(directory, relativeDirectory = "", metrics, knownChecksums) {
451
611
  const entries = await readdir(directory, { withFileTypes: true }).catch(
@@ -618,12 +778,12 @@ async function collectPackageFiles(directory, files) {
618
778
 
619
779
  // src/ssg/standalone.ts
620
780
  import { mkdir } from "node:fs/promises";
621
- import { createRequire } from "node:module";
781
+ import { createRequire as createRequire2 } from "node:module";
622
782
  import { relative as relative3, resolve as resolve2 } from "node:path";
623
783
  import { pathToFileURL } from "node:url";
624
784
  import { build } from "vite";
625
785
  var standaloneSsgMode = "riebeckite-ssr";
626
- var frameworkRequire = createRequire(import.meta.url);
786
+ var frameworkRequire = createRequire2(import.meta.url);
627
787
  async function loadStandaloneSsgBundle(input) {
628
788
  const root = resolve2(input.root);
629
789
  const outputDirectory = resolve2(input.outputDirectory);
@@ -711,7 +871,7 @@ function createClientManifestPlugin(root, clientOutputDirectory) {
711
871
  import { rm as rm2 } from "node:fs/promises";
712
872
 
713
873
  // src/ssg/build_output.ts
714
- import { createHash as createHash2, randomUUID } from "node:crypto";
874
+ import { createHash as createHash3, randomUUID } from "node:crypto";
715
875
  import { mkdir as mkdir2, readdir as readdir2, readFile as readFile2, rename, rm, stat } from "node:fs/promises";
716
876
  import { dirname as dirname2, join as join2 } from "node:path";
717
877
  var CLOUDFLARE_WORKER_ASSET_LIMIT = 25 * 1024 * 1024;
@@ -780,7 +940,7 @@ async function preserveClientBuildArtifacts(outDir) {
780
940
  return {
781
941
  stagingDirectory,
782
942
  paths,
783
- manifestFingerprint: createHash2("sha256").update(manifestSource).digest("hex")
943
+ manifestFingerprint: createHash3("sha256").update(manifestSource).digest("hex")
784
944
  };
785
945
  }
786
946
  async function restoreClientBuildArtifacts(outDir, artifacts) {
@@ -842,7 +1002,7 @@ async function verifyClientBuildArtifacts(input) {
842
1002
  const expectedChecksum = input.expectedInventory[relativePath];
843
1003
  if (!expectedChecksum) return false;
844
1004
  try {
845
- const actualChecksum = createHash2("sha256").update(
1005
+ const actualChecksum = createHash3("sha256").update(
846
1006
  await readFile2(resolveBuildArtifactPath(input.outDir, relativePath))
847
1007
  ).digest("hex");
848
1008
  if (actualChecksum !== expectedChecksum) return false;
@@ -903,7 +1063,6 @@ async function cleanupSsgGeneration(ctx, state) {
903
1063
 
904
1064
  // src/ssg_plugin_close.ts
905
1065
  import { resolve as resolve3 } from "node:path";
906
- import { buildOutputPlan, compareOutputPlan } from "@riebeckite/core";
907
1066
 
908
1067
  // src/ssg/output_cache_decision.ts
909
1068
  import { join as join4 } from "node:path";
@@ -915,7 +1074,7 @@ import { lstat as lstat3, mkdir as mkdir4, readFile as readFile4, rm as rm4, wri
915
1074
  import { dirname as dirname3 } from "node:path";
916
1075
 
917
1076
  // src/ssg/output_cache_paths.ts
918
- import { createHash as createHash3 } from "node:crypto";
1077
+ import { createHash as createHash4 } from "node:crypto";
919
1078
  import { lstat, mkdir as mkdir3, readFile as readFile3 } from "node:fs/promises";
920
1079
  function outputCacheEntriesPath(outputCachePath) {
921
1080
  return outputCachePath.replace(/\.json$/, ".entries");
@@ -950,7 +1109,7 @@ function assertSafeLogicalOutputPath(path14) {
950
1109
  }
951
1110
  }
952
1111
  function outputCacheEntryName(outputPath) {
953
- return createHash3("sha256").update(outputPath).digest("hex");
1112
+ return createHash4("sha256").update(outputPath).digest("hex");
954
1113
  }
955
1114
  async function ensureOutputCacheEntriesDirectory(directory) {
956
1115
  await mkdir3(directory, { recursive: true });
@@ -986,7 +1145,7 @@ async function isRegularFile(path14) {
986
1145
  }
987
1146
 
988
1147
  // src/ssg/output_cache_replace.ts
989
- import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypto";
1148
+ import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
990
1149
  import { createReadStream } from "node:fs";
991
1150
  import {
992
1151
  copyFile,
@@ -1028,7 +1187,7 @@ async function writeSsgOutputMetrics(metrics) {
1028
1187
 
1029
1188
  // src/ssg/output_cache_replace.ts
1030
1189
  async function checksumFile(path14) {
1031
- const hash = createHash4("sha256");
1190
+ const hash = createHash5("sha256");
1032
1191
  try {
1033
1192
  for await (const chunk of createReadStream(path14)) hash.update(chunk);
1034
1193
  return hash.digest("hex");
@@ -1499,7 +1658,7 @@ async function validateOutputCache(cache, path14, timingsMs, log = () => {
1499
1658
  }
1500
1659
 
1501
1660
  // src/ssg/output_cache_save.ts
1502
- import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
1661
+ import { createHash as createHash6, randomUUID as randomUUID4 } from "node:crypto";
1503
1662
  import { mkdir as mkdir5, rm as rm5, writeFile as writeFile4 } from "node:fs/promises";
1504
1663
  import { dirname as dirname5 } from "node:path";
1505
1664
  async function saveOutputCache(path14, state, outputDirectory, timingsMs) {
@@ -1541,7 +1700,7 @@ async function saveOutputCache(path14, state, outputDirectory, timingsMs) {
1541
1700
  "outputCacheRename",
1542
1701
  () => replaceFile(temporaryPath, path14)
1543
1702
  );
1544
- const checksum = createHash5("sha256").update(serialized).digest("hex");
1703
+ const checksum = createHash6("sha256").update(serialized).digest("hex");
1545
1704
  if (state.finalOutputInventory && state.configFile) {
1546
1705
  await saveFastPathCache(
1547
1706
  fastPathCachePath(path14),
@@ -1564,12 +1723,6 @@ async function saveOutputCache(path14, state, outputDirectory, timingsMs) {
1564
1723
  // src/ssg_plugin_helpers.ts
1565
1724
  import { lstat as lstat5, mkdir as mkdir6, writeFile as writeFile5 } from "node:fs/promises";
1566
1725
  import { dirname as dirname6, join as join6 } from "node:path";
1567
- import {
1568
- BUILD_OUTPUT_MARKER_FILE,
1569
- createBuildOutputMarker,
1570
- isDeferredGeneratedOutput,
1571
- serializeBuildOutputMarker
1572
- } from "@riebeckite/core";
1573
1726
  async function isDirectory(path14) {
1574
1727
  try {
1575
1728
  return (await lstat5(path14)).isDirectory();
@@ -1601,6 +1754,7 @@ async function emitGeneratedOutputs(module, emit, affectedPaths, shadowedPaths,
1601
1754
  const content = module.content;
1602
1755
  if (!content) return 0;
1603
1756
  if (affectedPaths?.size === 0) return 0;
1757
+ const { isDeferredGeneratedOutput } = await import("@riebeckite/core");
1604
1758
  const manifest = await content.getManifest();
1605
1759
  let count = 0;
1606
1760
  for (const output of manifest.generatedOutputs ?? []) {
@@ -1627,6 +1781,11 @@ function removeVirtualEntryChunk(bundle, virtualEntryId) {
1627
1781
  }
1628
1782
  }
1629
1783
  async function writePublicationMarker(input) {
1784
+ const {
1785
+ BUILD_OUTPUT_MARKER_FILE,
1786
+ createBuildOutputMarker,
1787
+ serializeBuildOutputMarker
1788
+ } = await import("@riebeckite/core");
1630
1789
  const path14 = join6(input.root, ".riebeckite", BUILD_OUTPUT_MARKER_FILE);
1631
1790
  try {
1632
1791
  await mkdir6(dirname6(path14), { recursive: true });
@@ -1653,6 +1812,7 @@ async function writePublicationMarker(input) {
1653
1812
  async function closeSsgBundle(plugin, state) {
1654
1813
  if (!state.resolvedConfig) return;
1655
1814
  if (state.resolvedConfig.mode === "client") return;
1815
+ const { buildOutputPlan, compareOutputPlan } = await import("@riebeckite/core");
1656
1816
  const outputDirectory = state.publicationOutputDirectory;
1657
1817
  if (!outputDirectory) {
1658
1818
  throw new Error(
@@ -1769,14 +1929,6 @@ async function closeSsgBundle(plugin, state) {
1769
1929
  }
1770
1930
  }
1771
1931
 
1772
- // src/ssg_plugin_generate_finalize.ts
1773
- import {
1774
- publicationFingerprint as fingerprintPublication,
1775
- publicationEntriesFromManifest,
1776
- publicationOutputsFromManifest,
1777
- publicationRedirectsFromManifest
1778
- } from "@riebeckite/core";
1779
-
1780
1932
  // src/ssg/diagnostics.ts
1781
1933
  function formatSsrNoExternal() {
1782
1934
  return "/^honox(?:\\/.*)?$/";
@@ -1835,6 +1987,12 @@ function inspectGeneratedHtmlPages(module, pages, log) {
1835
1987
 
1836
1988
  // src/ssg_plugin_generate_finalize.ts
1837
1989
  async function finalizeSsgGeneration(plugin, ctx, state) {
1990
+ const {
1991
+ publicationFingerprint: fingerprintPublication,
1992
+ publicationEntriesFromManifest,
1993
+ publicationRedirectsFromManifest,
1994
+ publicationOutputsFromManifest
1995
+ } = await import("@riebeckite/core");
1838
1996
  ctx.metrics.shadowedOutputCount = ctx.shadowedOutputs.size;
1839
1997
  if (ctx.shadowedOutputs.size > 0) {
1840
1998
  plugin.warn(
@@ -1902,8 +2060,6 @@ import { join as join7, resolve as resolve4 } from "node:path";
1902
2060
  // src/content_assets.ts
1903
2061
  import fs5 from "node:fs/promises";
1904
2062
  import path7 from "node:path";
1905
- import { isImagePath, normalizeContentPath } from "@riebeckite/core";
1906
- import { isIgnoredContentPath, isPathInsideDirectory } from "@riebeckite/node";
1907
2063
 
1908
2064
  // src/content_module.ts
1909
2065
  import path6 from "node:path";
@@ -1942,7 +2098,6 @@ function riebeckiteContentAssets(options) {
1942
2098
  apply: "serve",
1943
2099
  enforce: "pre",
1944
2100
  configureServer(server) {
1945
- const contentRoot = options.contentRoot();
1946
2101
  const base = server.config.base;
1947
2102
  const publicDir = server.config.publicDir;
1948
2103
  let cachedManifest;
@@ -1953,7 +2108,7 @@ function riebeckiteContentAssets(options) {
1953
2108
  };
1954
2109
  const deferredContents = /* @__PURE__ */ new Map();
1955
2110
  const resolvePublicAssets = async () => {
1956
- const module = await loadContentModule(server, options.appRoot());
2111
+ const module = await loadContentModule(server, await options.appRoot());
1957
2112
  const manifest = await module.content?.getManifest?.();
1958
2113
  if (!manifest) {
1959
2114
  return {
@@ -1966,9 +2121,9 @@ function riebeckiteContentAssets(options) {
1966
2121
  cachedManifest = manifest;
1967
2122
  deferredContents.clear();
1968
2123
  cachedAssets = {
1969
- paths: collectPublicImagePaths(manifest),
1970
- generated: collectGeneratedImageContents(manifest),
1971
- deferred: collectDeferredGeneratedImages(manifest)
2124
+ paths: await collectPublicImagePaths(manifest),
2125
+ generated: await collectGeneratedImageContents(manifest),
2126
+ deferred: await collectDeferredGeneratedImages(manifest)
1972
2127
  };
1973
2128
  }
1974
2129
  return cachedAssets;
@@ -1979,7 +2134,8 @@ function riebeckiteContentAssets(options) {
1979
2134
  next();
1980
2135
  return;
1981
2136
  }
1982
- const logicalPath = toContentPath(request.url, base);
2137
+ const { isIgnoredContentPath, isPathInsideDirectory } = await import("@riebeckite/node");
2138
+ const logicalPath = await toContentPath(request.url, base);
1983
2139
  if (!logicalPath) {
1984
2140
  next();
1985
2141
  return;
@@ -2017,6 +2173,7 @@ function riebeckiteContentAssets(options) {
2017
2173
  sendImage(request, response, contentType, content2);
2018
2174
  return;
2019
2175
  }
2176
+ const contentRoot = await options.contentRoot();
2020
2177
  const file = path7.join(contentRoot, logicalPath);
2021
2178
  if (!isPathInsideDirectory(contentRoot, file)) {
2022
2179
  next();
@@ -2035,7 +2192,8 @@ function riebeckiteContentAssets(options) {
2035
2192
  }
2036
2193
  };
2037
2194
  }
2038
- function collectPublicImagePaths(manifest) {
2195
+ async function collectPublicImagePaths(manifest) {
2196
+ const { isImagePath, normalizeContentPath } = await import("@riebeckite/core");
2039
2197
  const paths = /* @__PURE__ */ new Set();
2040
2198
  for (const entry of manifest.publicEntries ?? []) {
2041
2199
  for (const asset of entry.assets ?? []) {
@@ -2045,7 +2203,8 @@ function collectPublicImagePaths(manifest) {
2045
2203
  }
2046
2204
  return paths;
2047
2205
  }
2048
- function collectGeneratedImageContents(manifest) {
2206
+ async function collectGeneratedImageContents(manifest) {
2207
+ const { normalizeContentPath } = await import("@riebeckite/core");
2049
2208
  const contents = /* @__PURE__ */ new Map();
2050
2209
  for (const output of manifest.generatedOutputs ?? []) {
2051
2210
  if (output.content === void 0) continue;
@@ -2055,7 +2214,8 @@ function collectGeneratedImageContents(manifest) {
2055
2214
  }
2056
2215
  return contents;
2057
2216
  }
2058
- function collectDeferredGeneratedImages(manifest) {
2217
+ async function collectDeferredGeneratedImages(manifest) {
2218
+ const { normalizeContentPath } = await import("@riebeckite/core");
2059
2219
  const outputs = /* @__PURE__ */ new Map();
2060
2220
  for (const output of manifest.generatedOutputs ?? []) {
2061
2221
  if (!output.generate) continue;
@@ -2096,8 +2256,9 @@ async function collectSiteOwnedOutputPaths(publicDir) {
2096
2256
  await walk(root);
2097
2257
  return paths;
2098
2258
  }
2099
- function toContentPath(url, base) {
2259
+ async function toContentPath(url, base) {
2100
2260
  if (!url) return void 0;
2261
+ const { normalizeContentPath } = await import("@riebeckite/core");
2101
2262
  const withoutQuery = url.split("?")[0]?.split("#")[0];
2102
2263
  if (!withoutQuery) return void 0;
2103
2264
  let decoded = withoutQuery;
@@ -2916,9 +3077,6 @@ function createRiebeckiteSsg(options = {}) {
2916
3077
 
2917
3078
  // src/vite_plugin.ts
2918
3079
  import path13 from "node:path";
2919
- import {
2920
- createContentFormatRegistry
2921
- } from "@riebeckite/core";
2922
3080
  import {
2923
3081
  invalidateDevelopmentInspector,
2924
3082
  invalidateRiebeckiteBridge,
@@ -2930,27 +3088,39 @@ import { mergeConfig } from "vite";
2930
3088
  // src/asset_entries.ts
2931
3089
  import fs6 from "node:fs";
2932
3090
  import path8 from "node:path";
2933
- import { uniqueStrings } from "@riebeckite/core";
2934
- function writeRiebeckiteAssetEntries(config, paths) {
2935
- writeGeneratedFile(paths.frameworkStyles, createFrameworkStylesEntry());
2936
- writeGeneratedFile(paths.pluginStyles, createPluginStylesEntry(config));
2937
- writeGeneratedFile(paths.themeStyles, createThemeStylesEntry(config));
3091
+ async function writeRiebeckiteAssetEntries(config, paths) {
3092
+ const { uniqueStrings } = await import("@riebeckite/core");
3093
+ writeGeneratedFile(
3094
+ paths.frameworkStyles,
3095
+ createFrameworkStylesEntry(uniqueStrings)
3096
+ );
3097
+ writeGeneratedFile(
3098
+ paths.pluginStyles,
3099
+ createPluginStylesEntry(config, uniqueStrings)
3100
+ );
3101
+ writeGeneratedFile(
3102
+ paths.themeStyles,
3103
+ createThemeStylesEntry(config, uniqueStrings)
3104
+ );
2938
3105
  }
2939
- function createFrameworkStylesEntry() {
3106
+ function createFrameworkStylesEntry(uniqueStrings) {
2940
3107
  return createStylesheetEntry(
3108
+ uniqueStrings,
2941
3109
  ["@riebeckite/honox/style.css"],
2942
3110
  "Framework structural styles. Generated by @riebeckite/honox; do not edit. Import this before the plugin and theme stylesheets."
2943
3111
  );
2944
3112
  }
2945
- function createPluginStylesEntry(config) {
3113
+ function createPluginStylesEntry(config, uniqueStrings) {
2946
3114
  return createStylesheetEntry(
3115
+ uniqueStrings,
2947
3116
  collectPluginStyleSpecifiers(config),
2948
3117
  "Plugin default styles in the rb-plugins cascade layer, in resolved plugin order. Generated by @riebeckite/honox; do not edit.",
2949
3118
  "rb-plugins"
2950
3119
  );
2951
3120
  }
2952
- function createThemeStylesEntry(config) {
3121
+ function createThemeStylesEntry(config, uniqueStrings) {
2953
3122
  return createStylesheetEntry(
3123
+ uniqueStrings,
2954
3124
  config.theme.styles.map((style) => style.moduleSpecifier),
2955
3125
  "Theme styles in the rb-theme cascade layer. Generated by @riebeckite/honox; do not edit.",
2956
3126
  "rb-theme"
@@ -2961,7 +3131,7 @@ function collectPluginStyleSpecifiers(config) {
2961
3131
  (plugin) => (plugin.assets ?? []).filter((asset) => asset.kind === "style").map((asset) => asset.moduleSpecifier)
2962
3132
  );
2963
3133
  }
2964
- function createStylesheetEntry(moduleSpecifiers, banner, layer) {
3134
+ function createStylesheetEntry(uniqueStrings, moduleSpecifiers, banner, layer) {
2965
3135
  const imports = uniqueStrings(moduleSpecifiers).map(
2966
3136
  (specifier) => `@import ${JSON.stringify(specifier)}${layer ? ` layer(${layer})` : ""};`
2967
3137
  ).join("\n");
@@ -2990,10 +3160,8 @@ function isNotFoundError3(error) {
2990
3160
  }
2991
3161
 
2992
3162
  // src/client_module_part2.ts
2993
- import {
2994
- serializePublicClientConfig
2995
- } from "@riebeckite/core";
2996
- function createClientModule(config, development) {
3163
+ async function createClientModule(config, development) {
3164
+ const { serializePublicClientConfig } = await import("@riebeckite/core");
2997
3165
  const imports = [];
2998
3166
  const appInitializers = [];
2999
3167
  const appConditionalInitializers = [];
@@ -3231,7 +3399,8 @@ export async function disposeRiebeckiteClient() {
3231
3399
  // src/client_module_part1.ts
3232
3400
  var clientModuleId = "virtual:riebeckite/client";
3233
3401
  var resolvedClientModuleId = `\0${clientModuleId}`;
3234
- function riebeckiteClientModule(getConfig) {
3402
+ function riebeckiteClientModule(getConfig, ensure = async () => {
3403
+ }) {
3235
3404
  let development = false;
3236
3405
  return {
3237
3406
  name: "riebeckite-client-module",
@@ -3242,21 +3411,16 @@ function riebeckiteClientModule(getConfig) {
3242
3411
  if (id === clientModuleId) return resolvedClientModuleId;
3243
3412
  return null;
3244
3413
  },
3245
- load(id) {
3414
+ async load(id) {
3415
+ await ensure();
3246
3416
  if (id !== resolvedClientModuleId) return null;
3247
- return createClientModule(getConfig(), development);
3417
+ return await createClientModule(getConfig(), development);
3248
3418
  }
3249
3419
  };
3250
3420
  }
3251
3421
 
3252
3422
  // src/content_watch.ts
3253
3423
  import path9 from "node:path";
3254
- import { isAttachmentPath, isImagePath as isImagePath2 } from "@riebeckite/core";
3255
- import {
3256
- isIgnoredContentPath as isIgnoredContentPath2,
3257
- isPathInsideDirectory as isPathInsideDirectory2,
3258
- toLogicalPath
3259
- } from "@riebeckite/node";
3260
3424
 
3261
3425
  // src/runtime_modules.ts
3262
3426
  var riebeckiteConfigModuleId = "virtual:riebeckite/config";
@@ -3270,7 +3434,8 @@ var runtimeModuleIds = [
3270
3434
  var resolvedConfigModuleId = `\0${riebeckiteConfigModuleId}`;
3271
3435
  var resolvedContentModuleId = `\0${riebeckiteContentModuleId}`;
3272
3436
  var resolvedContentRenderersModuleId = `\0${riebeckiteContentRenderersModuleId}`;
3273
- function riebeckiteRuntimeModules(getApplication) {
3437
+ function riebeckiteRuntimeModules(getApplication, ensure = async () => {
3438
+ }) {
3274
3439
  let development = false;
3275
3440
  return {
3276
3441
  name: "riebeckite-runtime-modules",
@@ -3284,7 +3449,8 @@ function riebeckiteRuntimeModules(getApplication) {
3284
3449
  return resolvedContentRenderersModuleId;
3285
3450
  return null;
3286
3451
  },
3287
- load(id) {
3452
+ async load(id) {
3453
+ await ensure();
3288
3454
  if (id === resolvedConfigModuleId) {
3289
3455
  const { appRoot, configFile } = getApplication();
3290
3456
  return createConfigModule(appRoot, configFile);
@@ -3408,45 +3574,51 @@ function riebeckiteContentWatch(options) {
3408
3574
  configureServer(server) {
3409
3575
  if (configuredWatchers.has(server.watcher)) return;
3410
3576
  configuredWatchers.add(server.watcher);
3411
- const appRoot = options.appRoot();
3412
- const contentRoot = options.contentRoot();
3413
- const exclude = options.exclude();
3414
- const isContentFile = (file) => isPathInsideDirectory2(contentRoot, file);
3415
- server.watcher.add(contentRoot);
3416
- suppressRestartOnContentEvents(server, isContentFile);
3417
- let timer;
3418
- const invalidate = () => {
3419
- if (timer) clearTimeout(timer);
3420
- timer = setTimeout(() => {
3421
- timer = void 0;
3422
- invalidateApplicationRuntime(server, appRoot);
3423
- options.onInvalidate?.(server);
3424
- server.hot.send({ type: "full-reload" });
3425
- }, CONTENT_RELOAD_DEBOUNCE_MS);
3426
- };
3427
- server.httpServer?.once("close", () => {
3428
- if (timer) clearTimeout(timer);
3577
+ void Promise.all([
3578
+ options.appRoot(),
3579
+ options.contentRoot(),
3580
+ import("@riebeckite/core"),
3581
+ import("@riebeckite/node")
3582
+ ]).then(([appRoot, contentRoot, core, nodeUtils]) => {
3583
+ const { isAttachmentPath, isImagePath } = core;
3584
+ const { isIgnoredContentPath, isPathInsideDirectory, toLogicalPath } = nodeUtils;
3585
+ const exclude = options.exclude();
3586
+ const isContentFile = (file) => isPathInsideDirectory(contentRoot, file);
3587
+ server.watcher.add(contentRoot);
3588
+ suppressRestartOnContentEvents(server, isContentFile);
3589
+ let timer;
3590
+ const invalidate = () => {
3591
+ if (timer) clearTimeout(timer);
3592
+ timer = setTimeout(() => {
3593
+ timer = void 0;
3594
+ void invalidateApplicationRuntime(server, appRoot);
3595
+ options.onInvalidate?.(server);
3596
+ server.hot.send({ type: "full-reload" });
3597
+ }, CONTENT_RELOAD_DEBOUNCE_MS);
3598
+ };
3599
+ server.httpServer?.once("close", () => {
3600
+ if (timer) clearTimeout(timer);
3601
+ });
3602
+ const handle = (event) => (file) => {
3603
+ if (!isContentFile(file)) return;
3604
+ const logicalPath = toLogicalPath(contentRoot, file);
3605
+ if (isIgnoredContentPath(logicalPath, exclude)) return;
3606
+ if (event === "change" && (isImagePath(logicalPath) || isAttachmentPath(logicalPath))) {
3607
+ server.hot.send({ type: "full-reload" });
3608
+ return;
3609
+ }
3610
+ invalidate();
3611
+ };
3612
+ server.watcher.on("add", handle("add"));
3613
+ server.watcher.on("change", handle("change"));
3614
+ server.watcher.on("unlink", handle("unlink"));
3615
+ }).catch(() => {
3429
3616
  });
3430
- const handle = (event) => (file) => {
3431
- if (!isContentFile(file)) return;
3432
- const logicalPath = toLogicalPath(contentRoot, file);
3433
- if (isIgnoredContentPath2(logicalPath, exclude)) return;
3434
- if (event === "change" && isSiteAssetPath(logicalPath)) {
3435
- server.hot.send({ type: "full-reload" });
3436
- return;
3437
- }
3438
- invalidate();
3439
- };
3440
- server.watcher.on("add", handle("add"));
3441
- server.watcher.on("change", handle("change"));
3442
- server.watcher.on("unlink", handle("unlink"));
3443
3617
  }
3444
3618
  };
3445
3619
  }
3446
- function isSiteAssetPath(logicalPath) {
3447
- return isImagePath2(logicalPath) || isAttachmentPath(logicalPath);
3448
- }
3449
- function invalidateApplicationRuntime(server, appRoot) {
3620
+ async function invalidateApplicationRuntime(server, appRoot) {
3621
+ const { isPathInsideDirectory } = await import("@riebeckite/node");
3450
3622
  const moduleGraph = server.environments?.ssr?.moduleGraph;
3451
3623
  if (!moduleGraph) return 0;
3452
3624
  const appDirectory = path9.join(appRoot, "app") + path9.sep;
@@ -3454,14 +3626,15 @@ function invalidateApplicationRuntime(server, appRoot) {
3454
3626
  const timestamp = Date.now();
3455
3627
  let invalidated = 0;
3456
3628
  for (const mod of moduleGraph.idToModuleMap.values()) {
3457
- if (!isApplicationRuntimeModule(mod, appDirectory)) continue;
3629
+ if (!isApplicationRuntimeModule(mod, appDirectory, isPathInsideDirectory))
3630
+ continue;
3458
3631
  moduleGraph.invalidateModule(mod, seen, timestamp);
3459
3632
  invalidated += 1;
3460
3633
  }
3461
3634
  return invalidated;
3462
3635
  }
3463
- function isApplicationRuntimeModule(mod, appDirectory) {
3464
- if (mod.file && isPathInsideDirectory2(appDirectory, mod.file)) return true;
3636
+ function isApplicationRuntimeModule(mod, appDirectory, isPathInsideDirectory) {
3637
+ if (mod.file && isPathInsideDirectory(appDirectory, mod.file)) return true;
3465
3638
  return isRiebeckiteRuntimeModuleId(mod.id);
3466
3639
  }
3467
3640
  function suppressRestartOnContentEvents(server, isContentFile) {
@@ -3825,38 +3998,57 @@ function riebeckite(options = {}, onApplicationResolved) {
3825
3998
  }
3826
3999
  return resolvedConfig;
3827
4000
  };
4001
+ let applicationPromise;
4002
+ let applicationAppRoot = "";
4003
+ let contentFormatRegistryFactory;
4004
+ const ensureApplication = () => applicationPromise ??= (async () => {
4005
+ const core = await import("@riebeckite/core");
4006
+ contentFormatRegistryFactory = core.createContentFormatRegistry;
4007
+ const resolvedApplication = await resolveHonoxApplication({
4008
+ configRoot: options.configRoot ?? applicationAppRoot,
4009
+ configFile: options.configFile,
4010
+ appRoot: applicationAppRoot,
4011
+ workspaceRoot: options.workspaceRoot
4012
+ });
4013
+ resolvedConfig = resolvedApplication.config;
4014
+ const resolved = resolvedConfig;
4015
+ contentVitePlugins = resolved.plugins.flatMap(
4016
+ (plugin) => plugin.vitePlugins?.({
4017
+ contentDirectory: resolved.content.directory
4018
+ }) ?? []
4019
+ );
4020
+ application = resolvedApplication;
4021
+ onApplicationResolved?.(resolvedApplication);
4022
+ await writeRiebeckiteAssetEntries(resolvedConfig, {
4023
+ frameworkStyles: path13.join(
4024
+ applicationAppRoot,
4025
+ "app/.riebeckite/framework-styles.css"
4026
+ ),
4027
+ pluginStyles: path13.join(
4028
+ applicationAppRoot,
4029
+ "app/.riebeckite/plugin-styles.css"
4030
+ ),
4031
+ themeStyles: path13.join(
4032
+ applicationAppRoot,
4033
+ "app/.riebeckite/theme-styles.css"
4034
+ )
4035
+ });
4036
+ return resolvedApplication;
4037
+ })();
3828
4038
  return [
3829
4039
  {
3830
4040
  name: "riebeckite-host-integration",
3831
- async config(userConfig) {
4041
+ async config(userConfig, environment) {
3832
4042
  const root = userConfig.root ? path13.resolve(userConfig.root) : process.cwd();
3833
- const appRoot = options.appRoot ?? root;
3834
- const resolvedApplication = await resolveHonoxApplication({
3835
- configRoot: options.configRoot ?? appRoot,
3836
- configFile: options.configFile,
3837
- appRoot,
3838
- workspaceRoot: options.workspaceRoot
3839
- });
3840
- resolvedConfig = resolvedApplication.config;
3841
- const resolved = resolvedConfig;
3842
- contentVitePlugins = resolved.plugins.flatMap(
3843
- (plugin) => plugin.vitePlugins?.({
3844
- contentDirectory: resolved.content.directory
3845
- }) ?? []
3846
- );
3847
- application = resolvedApplication;
3848
- onApplicationResolved?.(resolvedApplication);
3849
- writeRiebeckiteAssetEntries(resolvedConfig, {
3850
- frameworkStyles: path13.join(
3851
- appRoot,
3852
- "app/.riebeckite/framework-styles.css"
3853
- ),
3854
- pluginStyles: path13.join(appRoot, "app/.riebeckite/plugin-styles.css"),
3855
- themeStyles: path13.join(appRoot, "app/.riebeckite/theme-styles.css")
4043
+ applicationAppRoot = options.appRoot ?? root;
4044
+ void ensureApplication().catch(() => {
3856
4045
  });
4046
+ if (environment.command === "build") {
4047
+ await ensureApplication();
4048
+ }
3857
4049
  return {
3858
4050
  define: {
3859
- "process.env.RIEBECKITE_APP_ROOT": JSON.stringify(appRoot)
4051
+ "process.env.RIEBECKITE_APP_ROOT": JSON.stringify(applicationAppRoot)
3860
4052
  },
3861
4053
  oxc: {
3862
4054
  jsx: { runtime: "automatic", importSource: "hono/jsx" }
@@ -3870,27 +4062,40 @@ function riebeckite(options = {}, onApplicationResolved) {
3870
4062
  }
3871
4063
  },
3872
4064
  resolve: {
3873
- alias: options.workspaceRoot ? createWorkspacePackageAliases(options.workspaceRoot) : []
4065
+ alias: options.workspaceRoot ? await createWorkspacePackageAliases(options.workspaceRoot) : []
3874
4066
  }
3875
4067
  };
4068
+ },
4069
+ configureServer(server) {
4070
+ applicationPromise?.catch((error) => {
4071
+ server.config.logger.error(
4072
+ "Failed to resolve Riebeckite application.",
4073
+ {
4074
+ error: error instanceof Error ? error : new Error(String(error))
4075
+ }
4076
+ );
4077
+ });
3876
4078
  }
3877
4079
  },
3878
4080
  contentVitePluginBridge(() => contentVitePlugins),
3879
- contentBareImportResolver(() => requireApplication(application)),
3880
- injectRiebeckiteClientBundle(getConfig),
3881
- riebeckiteClientModule(getConfig),
3882
- riebeckiteRuntimeModules(() => requireApplication(application)),
3883
- riebeckiteContentWarmup(
3884
- options.warmContent ?? false,
3885
- () => requireApplication(application)
4081
+ contentBareImportResolver(
4082
+ () => requireApplication(application),
4083
+ ensureApplication
3886
4084
  ),
4085
+ injectRiebeckiteClientBundle(getConfig, ensureApplication),
4086
+ riebeckiteClientModule(getConfig, ensureApplication),
4087
+ riebeckiteRuntimeModules(
4088
+ () => requireApplication(application),
4089
+ ensureApplication
4090
+ ),
4091
+ riebeckiteContentWarmup(options.warmContent ?? false, ensureApplication),
3887
4092
  riebeckiteContentAssets({
3888
- appRoot: () => requireApplication(application).appRoot,
3889
- contentRoot: () => requireApplication(application).contentRoot
4093
+ appRoot: async () => (await ensureApplication()).appRoot,
4094
+ contentRoot: async () => (await ensureApplication()).contentRoot
3890
4095
  }),
3891
4096
  riebeckiteContentWatch({
3892
- appRoot: () => requireApplication(application).appRoot,
3893
- contentRoot: () => requireApplication(application).contentRoot,
4097
+ appRoot: async () => (await ensureApplication()).appRoot,
4098
+ contentRoot: async () => (await ensureApplication()).contentRoot,
3894
4099
  exclude: () => getConfig().content.exclude ?? [],
3895
4100
  onInvalidate(server) {
3896
4101
  invalidateDevelopmentInspector(server);
@@ -3911,7 +4116,12 @@ function riebeckite(options = {}, onApplicationResolved) {
3911
4116
  mutationToken: process.env.RIEBECKITE_BRIDGE_MUTATION_TOKEN,
3912
4117
  mutationApprovalToken: process.env.RIEBECKITE_BRIDGE_MUTATION_APPROVAL_TOKEN,
3913
4118
  contentRoot: () => requireApplication(application).contentRoot,
3914
- contentFormats: () => createContentFormatRegistry(getConfig().plugins),
4119
+ contentFormats: () => {
4120
+ if (!contentFormatRegistryFactory) {
4121
+ throw new Error("Riebeckite config has not been loaded yet.");
4122
+ }
4123
+ return contentFormatRegistryFactory(getConfig().plugins);
4124
+ },
3915
4125
  publicOrigin: () => getConfig().site.baseUrl || void 0,
3916
4126
  async getSnapshot(server) {
3917
4127
  const { appRoot } = requireApplication(application);
@@ -3930,8 +4140,12 @@ function riebeckiteContentWarmup(enabled, getApplication) {
3930
4140
  configureServer(server) {
3931
4141
  if (!enabled || !server.httpServer) return;
3932
4142
  server.httpServer.once("listening", () => {
3933
- const { appRoot } = getApplication();
3934
- void loadContentModule(server, appRoot).then(async (module) => await module.content?.getManifest?.()).catch((error) => {
4143
+ void (async () => {
4144
+ const { appRoot } = await getApplication();
4145
+ await loadContentModule(server, appRoot).then(
4146
+ async (module) => await module.content?.getManifest?.()
4147
+ );
4148
+ })().catch((error) => {
3935
4149
  server.config.logger.error("Riebeckite content warmup failed.", {
3936
4150
  error: error instanceof Error ? error : new Error(String(error))
3937
4151
  });
@@ -3940,11 +4154,12 @@ function riebeckiteContentWarmup(enabled, getApplication) {
3940
4154
  }
3941
4155
  };
3942
4156
  }
3943
- function contentBareImportResolver(getApplication) {
4157
+ function contentBareImportResolver(getApplication, ensure) {
3944
4158
  return {
3945
4159
  name: "riebeckite-content-bare-imports",
3946
4160
  async resolveId(source, importer) {
3947
4161
  if (!importer || !isBareImport(source)) return null;
4162
+ await ensure();
3948
4163
  const { appRoot, contentRoot } = getApplication();
3949
4164
  if (!isInDirectory2(importer, contentRoot)) return null;
3950
4165
  return await this.resolve(source, path13.join(appRoot, "package.json"), {
package/dist/runtime.js CHANGED
@@ -7,9 +7,6 @@ import {
7
7
  import path from "node:path";
8
8
 
9
9
  // src/spa_diagnostics.ts
10
- import {
11
- definePlugin
12
- } from "@riebeckite/core";
13
10
  var SPA_DIAGNOSTICS_PLUGIN_NAME = "riebeckite:spa-diagnostics";
14
11
  var MAIN_CONTENT_PATTERN = /<main\b[^>]*\bid=["']main-content["']/iu;
15
12
  var REDIRECT_PATTERN = /<meta\b[^>]*\bhttp-equiv=["']refresh["'][^>]*\bcontent=["'][^"']*\burl=/iu;
@@ -27,10 +24,10 @@ function inspectSpaPage(page) {
27
24
  ];
28
25
  }
29
26
  function spaDiagnostics() {
30
- return definePlugin({
27
+ return {
31
28
  name: SPA_DIAGNOSTICS_PLUGIN_NAME,
32
29
  inspectGeneratedHtml: inspectSpaPage
33
- });
30
+ };
34
31
  }
35
32
 
36
33
  // src/resolved_config.ts
@@ -1,8 +1,8 @@
1
- import { type ResolvedRiebeckiteConfig } from "@riebeckite/core";
1
+ import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
2
  type GeneratedAssetPaths = {
3
3
  frameworkStyles: string;
4
4
  pluginStyles: string;
5
5
  themeStyles: string;
6
6
  };
7
- export declare function writeRiebeckiteAssetEntries(config: ResolvedRiebeckiteConfig, paths: GeneratedAssetPaths): void;
7
+ export declare function writeRiebeckiteAssetEntries(config: ResolvedRiebeckiteConfig, paths: GeneratedAssetPaths): Promise<void>;
8
8
  export {};
@@ -2,4 +2,4 @@ import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
2
  import type { Plugin } from "vite";
3
3
  export declare const clientModuleId = "virtual:riebeckite/client";
4
4
  export declare const resolvedClientModuleId = "\0virtual:riebeckite/client";
5
- export declare function riebeckiteClientModule(getConfig: () => Pick<ResolvedRiebeckiteConfig, "plugins" | "spa">): Plugin;
5
+ export declare function riebeckiteClientModule(getConfig: () => Pick<ResolvedRiebeckiteConfig, "plugins" | "spa">, ensure?: () => Promise<unknown>): Plugin;
@@ -1,2 +1,2 @@
1
- import { type ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
- export declare function createClientModule(config: Pick<ResolvedRiebeckiteConfig, "plugins" | "spa">, development: boolean): string;
1
+ import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ export declare function createClientModule(config: Pick<ResolvedRiebeckiteConfig, "plugins" | "spa">, development: boolean): Promise<string>;
@@ -1,7 +1,7 @@
1
1
  import type { Plugin } from "vite";
2
2
  type RiebeckiteContentAssetsOptions = {
3
- appRoot: () => string;
4
- contentRoot: () => string;
3
+ appRoot: () => Promise<string>;
4
+ contentRoot: () => Promise<string>;
5
5
  };
6
6
  type ContentAssetEntry = {
7
7
  assets?: ReadonlyArray<{
@@ -21,10 +21,10 @@ export type PublicContentManifest = {
21
21
  generatedOutputs?: ReadonlyArray<GeneratedOutputEntry>;
22
22
  };
23
23
  export declare function riebeckiteContentAssets(options: RiebeckiteContentAssetsOptions): Plugin;
24
- export declare function collectPublicImagePaths(manifest: PublicContentManifest): Set<string>;
25
- export declare function collectGeneratedImageContents(manifest: PublicContentManifest): Map<string, Uint8Array | string>;
26
- export declare function collectDeferredGeneratedImages(manifest: PublicContentManifest): Map<string, DeferredGeneratedImage>;
24
+ export declare function collectPublicImagePaths(manifest: PublicContentManifest): Promise<Set<string>>;
25
+ export declare function collectGeneratedImageContents(manifest: PublicContentManifest): Promise<Map<string, Uint8Array | string>>;
26
+ export declare function collectDeferredGeneratedImages(manifest: PublicContentManifest): Promise<Map<string, DeferredGeneratedImage>>;
27
27
  export declare function collectSiteOwnedOutputPaths(publicDir: string | false | undefined): Promise<Set<string>>;
28
- export declare function toContentPath(url: string | undefined, base: string): string | undefined;
28
+ export declare function toContentPath(url: string | undefined, base: string): Promise<string | undefined>;
29
29
  export declare function imageContentType(logicalPath: string): string | undefined;
30
30
  export {};
@@ -1,11 +1,11 @@
1
1
  import type { Plugin, ViteDevServer } from "vite";
2
2
  type RiebeckiteContentWatchOptions = {
3
- appRoot: () => string;
4
- contentRoot: () => string;
3
+ appRoot: () => Promise<string>;
4
+ contentRoot: () => Promise<string>;
5
5
  exclude: () => readonly string[];
6
6
  onInvalidate?: (server: ViteDevServer) => void;
7
7
  };
8
8
  export declare function riebeckiteContentWatch(options: RiebeckiteContentWatchOptions): Plugin;
9
- export declare function isSiteAssetPath(logicalPath: string): boolean;
10
- export declare function invalidateApplicationRuntime(server: Pick<ViteDevServer, "environments">, appRoot: string): number;
9
+ export declare function isSiteAssetPath(logicalPath: string): Promise<boolean>;
10
+ export declare function invalidateApplicationRuntime(server: Pick<ViteDevServer, "environments">, appRoot: string): Promise<number>;
11
11
  export {};
@@ -7,4 +7,4 @@ import type { Plugin, PluginOption } from "vite";
7
7
  * imports an island.
8
8
  */
9
9
  export declare function replaceHonoxIslandDependencyPlugin(plugins: PluginOption[]): PluginOption[];
10
- export declare function injectRiebeckiteClientBundle(getConfig: () => Pick<ResolvedRiebeckiteConfig, "plugins" | "spa">): Plugin;
10
+ export declare function injectRiebeckiteClientBundle(getConfig: () => Pick<ResolvedRiebeckiteConfig, "plugins" | "spa">, ensure?: () => Promise<unknown>): Plugin;
@@ -8,5 +8,5 @@ export declare const riebeckiteContentRenderersModuleId = "virtual:riebeckite/co
8
8
  * instead of keeping resolved-config and content-manager ceremony in
9
9
  * `app/config.ts` and `app/content.ts`.
10
10
  */
11
- export declare function riebeckiteRuntimeModules(getApplication: () => ResolvedHonoxApplication): Plugin;
11
+ export declare function riebeckiteRuntimeModules(getApplication: () => ResolvedHonoxApplication, ensure?: () => Promise<unknown>): Plugin;
12
12
  export declare function isRiebeckiteRuntimeModuleId(id: string | null | undefined): boolean;
@@ -1,4 +1,4 @@
1
- import { type Diagnostic, type PluginGeneratedHtml, type RiebeckitePlugin } from "@riebeckite/core";
1
+ import type { Diagnostic, PluginGeneratedHtml, RiebeckitePlugin } from "@riebeckite/core";
2
2
  export declare const SPA_DIAGNOSTICS_PLUGIN_NAME = "riebeckite:spa-diagnostics";
3
3
  export declare function inspectSpaPage(page: PluginGeneratedHtml): Diagnostic[];
4
4
  export declare function spaDiagnostics(): RiebeckitePlugin;
@@ -15,7 +15,7 @@ export type RiebeckiteViteOptions = RiebeckiteIntegrationOptions & {
15
15
  ssg?: RiebeckiteSsgOptions;
16
16
  };
17
17
  export declare function riebeckite(options?: RiebeckiteViteOptions, onApplicationResolved?: (application: ResolvedHonoxApplication) => void): Plugin[];
18
- export declare function riebeckiteContentWarmup(enabled: boolean, getApplication: () => ResolvedHonoxApplication): Plugin;
18
+ export declare function riebeckiteContentWarmup(enabled: boolean, getApplication: () => Promise<ResolvedHonoxApplication>): Plugin;
19
19
  /**
20
20
  * Higher-level helper that registers the complete Riebeckite Vite integration
21
21
  * without exposing internal Vite/HonoX/SSR details. A site only needs to add
@@ -1,8 +1,9 @@
1
- export declare function createWorkspacePackageAliases(workspaceRoot: string): {
1
+ export declare function createWorkspacePackageAliases(workspaceRoot: string): Promise<{
2
2
  find: RegExp;
3
3
  replacement: string;
4
- }[];
5
- export declare function workspacePackageResolver(workspaceRoot: string): {
4
+ }[]>;
5
+ export declare function workspacePackageJsonPaths(workspaceRoot: string): string[];
6
+ export declare function workspacePackageResolver(workspaceRoot: string): Promise<{
6
7
  name: string;
7
8
  setup(buildApi: {
8
9
  onResolve: (options: {
@@ -13,4 +14,4 @@ export declare function workspacePackageResolver(workspaceRoot: string): {
13
14
  path: string;
14
15
  } | null) => void;
15
16
  }): void;
16
- };
17
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/honox",
3
- "version": "0.0.52",
3
+ "version": "0.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,16 +44,16 @@
44
44
  "hono": "^4.13.18",
45
45
  "honox": "0.1.62",
46
46
  "vite": "^8.3.7",
47
- "@riebeckite/og-image": "0.0.52",
48
- "@riebeckite/runtime": "0.0.52",
49
- "@riebeckite/plugin-color-mode": "0.0.52",
50
- "@riebeckite/dev-inspector": "0.0.52",
51
- "@riebeckite/node": "0.0.52",
52
- "@riebeckite/ui": "0.0.52",
53
- "@riebeckite/spa": "0.0.52"
47
+ "@riebeckite/dev-inspector": "0.1.0",
48
+ "@riebeckite/node": "0.1.0",
49
+ "@riebeckite/runtime": "0.1.0",
50
+ "@riebeckite/og-image": "0.1.0",
51
+ "@riebeckite/plugin-color-mode": "0.1.0",
52
+ "@riebeckite/spa": "0.1.0",
53
+ "@riebeckite/ui": "0.1.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "@riebeckite/core": "^0.0.52"
56
+ "@riebeckite/core": "^0.1.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@d2lang/d2": "^0.1.34",
@@ -61,9 +61,9 @@
61
61
  "@hono/vite-build": "^1.11.1",
62
62
  "@marp-team/marp-core": "^4.4.0",
63
63
  "tsx": "^4.22.4",
64
- "@riebeckite/test": "0.0.52",
65
- "@riebeckite/plugin-bases": "0.0.52",
66
- "@riebeckite/core": "0.0.52"
64
+ "@riebeckite/test": "0.1.0",
65
+ "@riebeckite/plugin-bases": "0.1.0",
66
+ "@riebeckite/core": "0.1.0"
67
67
  },
68
68
  "publishConfig": {
69
69
  "access": "public"