@riebeckite/honox 0.0.51 → 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"
195
+ );
196
+ const packageJsonListDigest = digestPackageJsonList(
197
+ options.workspaceRoot ? workspacePackageJsonPaths(options.workspaceRoot) : [path4.join(options.configRoot, "package.json")]
182
198
  );
183
- const outputFile = path4.join(temporaryDirectory, "config.mjs");
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,6 +381,36 @@ function replaceHonoxIslandDependencyPlugin(plugins) {
224
381
  scopedIslandDependencyPlugin()
225
382
  ];
226
383
  }
384
+ function injectRiebeckiteClientBundle(getConfig, ensure = async () => {
385
+ }) {
386
+ let rendererPath = "";
387
+ return {
388
+ name: "riebeckite-inject-client-bundle",
389
+ enforce: "pre",
390
+ configResolved(config) {
391
+ rendererPath = path5.join(config.root, "app", "routes", "_renderer");
392
+ },
393
+ async transform(sourceCode, id) {
394
+ await ensure();
395
+ if (!requiresClientBundle(getConfig()) || !isRendererModule(toFilePath(id), rendererPath) || sourceCode.includes(`export const ${importingIslandsExport}`)) {
396
+ return;
397
+ }
398
+ return {
399
+ code: `${sourceCode}
400
+ export const ${importingIslandsExport} = true;
401
+ `,
402
+ map: null
403
+ };
404
+ }
405
+ };
406
+ }
407
+ function requiresClientBundle(config) {
408
+ return config.spa !== void 0 || config.plugins.some(
409
+ (plugin) => (plugin.clientEntries?.length ?? 0) > 0 || plugin.markdownComponents?.some(
410
+ (component) => component.client !== void 0
411
+ ) === true
412
+ );
413
+ }
227
414
  function disableHonoxIslandDependencyPlugin(plugin) {
228
415
  if (!plugin || typeof plugin === "boolean") return plugin;
229
416
  if (Array.isArray(plugin)) {
@@ -264,7 +451,7 @@ export const ${importingIslandsExport} = true;
264
451
  if (visited.has(currentModulePath)) return false;
265
452
  visited.add(currentModulePath);
266
453
  if (isInDirectory(currentModulePath, islandDirectory)) return true;
267
- const importSources = getStaticImportSources(currentSourceCode);
454
+ const importSources = await getStaticImportSources(currentSourceCode);
268
455
  for (const importSource of importSources) {
269
456
  const resolved = await pluginContext.resolve(
270
457
  importSource,
@@ -289,7 +476,8 @@ export const ${importingIslandsExport} = true;
289
476
  return visit(modulePath, sourceCode);
290
477
  }
291
478
  }
292
- function getStaticImportSources(sourceCode) {
479
+ async function getStaticImportSources(sourceCode) {
480
+ const { parse } = await import("@babel/parser");
293
481
  const ast = parse(sourceCode, {
294
482
  sourceType: "module",
295
483
  plugins: ["typescript", "jsx"]
@@ -311,9 +499,14 @@ function isInDirectory(filePath, directory) {
311
499
  function isJavaScriptModule(filePath) {
312
500
  return /\.[cm]?[jt]sx?$/.test(filePath);
313
501
  }
502
+ function isRendererModule(filePath, rendererPath) {
503
+ const resolvedFilePath = path5.resolve(filePath);
504
+ const resolvedRendererPath = path5.resolve(rendererPath);
505
+ return resolvedFilePath.startsWith(`${resolvedRendererPath}.`) && isJavaScriptModule(resolvedFilePath);
506
+ }
314
507
 
315
508
  // src/ssg/inventory.ts
316
- import { createHash } from "node:crypto";
509
+ import { createHash as createHash2 } from "node:crypto";
317
510
  import { readdir, readFile } from "node:fs/promises";
318
511
  import { dirname, join, relative as relative2 } from "node:path";
319
512
  import { performance } from "node:perf_hooks";
@@ -363,7 +556,7 @@ async function computeAppFingerprint(root, configFile) {
363
556
  files.push(join(root, name));
364
557
  }
365
558
  files.sort();
366
- const hash = createHash("sha256");
559
+ const hash = createHash2("sha256");
367
560
  for (const file of files) {
368
561
  let content;
369
562
  try {
@@ -379,7 +572,7 @@ async function computeAppFingerprint(root, configFile) {
379
572
  return hash.digest("hex");
380
573
  }
381
574
  async function computeBundleFingerprint(root, configFile) {
382
- const hash = createHash("sha256");
575
+ const hash = createHash2("sha256");
383
576
  hash.update(await computeAppFingerprint(root, configFile));
384
577
  const files = [
385
578
  ...await findBundleInputFiles(root),
@@ -403,7 +596,7 @@ async function fingerprintDirectory(directory) {
403
596
  );
404
597
  }
405
598
  function fingerprintOutputInventory(inventory) {
406
- const hash = createHash("sha256");
599
+ const hash = createHash2("sha256");
407
600
  for (const [path14, checksum] of Object.entries(inventory).sort(
408
601
  ([left], [right]) => left.localeCompare(right)
409
602
  )) {
@@ -412,7 +605,7 @@ function fingerprintOutputInventory(inventory) {
412
605
  return hash.digest("hex");
413
606
  }
414
607
  function fingerprintOutputContent(content) {
415
- return createHash("sha256").update(content).digest("hex");
608
+ return createHash2("sha256").update(content).digest("hex");
416
609
  }
417
610
  async function fingerprintOutputDirectory(directory, relativeDirectory = "", metrics, knownChecksums) {
418
611
  const entries = await readdir(directory, { withFileTypes: true }).catch(
@@ -585,12 +778,12 @@ async function collectPackageFiles(directory, files) {
585
778
 
586
779
  // src/ssg/standalone.ts
587
780
  import { mkdir } from "node:fs/promises";
588
- import { createRequire } from "node:module";
781
+ import { createRequire as createRequire2 } from "node:module";
589
782
  import { relative as relative3, resolve as resolve2 } from "node:path";
590
783
  import { pathToFileURL } from "node:url";
591
784
  import { build } from "vite";
592
785
  var standaloneSsgMode = "riebeckite-ssr";
593
- var frameworkRequire = createRequire(import.meta.url);
786
+ var frameworkRequire = createRequire2(import.meta.url);
594
787
  async function loadStandaloneSsgBundle(input) {
595
788
  const root = resolve2(input.root);
596
789
  const outputDirectory = resolve2(input.outputDirectory);
@@ -678,7 +871,7 @@ function createClientManifestPlugin(root, clientOutputDirectory) {
678
871
  import { rm as rm2 } from "node:fs/promises";
679
872
 
680
873
  // src/ssg/build_output.ts
681
- import { createHash as createHash2, randomUUID } from "node:crypto";
874
+ import { createHash as createHash3, randomUUID } from "node:crypto";
682
875
  import { mkdir as mkdir2, readdir as readdir2, readFile as readFile2, rename, rm, stat } from "node:fs/promises";
683
876
  import { dirname as dirname2, join as join2 } from "node:path";
684
877
  var CLOUDFLARE_WORKER_ASSET_LIMIT = 25 * 1024 * 1024;
@@ -747,7 +940,7 @@ async function preserveClientBuildArtifacts(outDir) {
747
940
  return {
748
941
  stagingDirectory,
749
942
  paths,
750
- manifestFingerprint: createHash2("sha256").update(manifestSource).digest("hex")
943
+ manifestFingerprint: createHash3("sha256").update(manifestSource).digest("hex")
751
944
  };
752
945
  }
753
946
  async function restoreClientBuildArtifacts(outDir, artifacts) {
@@ -809,7 +1002,7 @@ async function verifyClientBuildArtifacts(input) {
809
1002
  const expectedChecksum = input.expectedInventory[relativePath];
810
1003
  if (!expectedChecksum) return false;
811
1004
  try {
812
- const actualChecksum = createHash2("sha256").update(
1005
+ const actualChecksum = createHash3("sha256").update(
813
1006
  await readFile2(resolveBuildArtifactPath(input.outDir, relativePath))
814
1007
  ).digest("hex");
815
1008
  if (actualChecksum !== expectedChecksum) return false;
@@ -870,7 +1063,6 @@ async function cleanupSsgGeneration(ctx, state) {
870
1063
 
871
1064
  // src/ssg_plugin_close.ts
872
1065
  import { resolve as resolve3 } from "node:path";
873
- import { buildOutputPlan, compareOutputPlan } from "@riebeckite/core";
874
1066
 
875
1067
  // src/ssg/output_cache_decision.ts
876
1068
  import { join as join4 } from "node:path";
@@ -882,7 +1074,7 @@ import { lstat as lstat3, mkdir as mkdir4, readFile as readFile4, rm as rm4, wri
882
1074
  import { dirname as dirname3 } from "node:path";
883
1075
 
884
1076
  // src/ssg/output_cache_paths.ts
885
- import { createHash as createHash3 } from "node:crypto";
1077
+ import { createHash as createHash4 } from "node:crypto";
886
1078
  import { lstat, mkdir as mkdir3, readFile as readFile3 } from "node:fs/promises";
887
1079
  function outputCacheEntriesPath(outputCachePath) {
888
1080
  return outputCachePath.replace(/\.json$/, ".entries");
@@ -917,7 +1109,7 @@ function assertSafeLogicalOutputPath(path14) {
917
1109
  }
918
1110
  }
919
1111
  function outputCacheEntryName(outputPath) {
920
- return createHash3("sha256").update(outputPath).digest("hex");
1112
+ return createHash4("sha256").update(outputPath).digest("hex");
921
1113
  }
922
1114
  async function ensureOutputCacheEntriesDirectory(directory) {
923
1115
  await mkdir3(directory, { recursive: true });
@@ -953,7 +1145,7 @@ async function isRegularFile(path14) {
953
1145
  }
954
1146
 
955
1147
  // src/ssg/output_cache_replace.ts
956
- import { createHash as createHash4, randomUUID as randomUUID2 } from "node:crypto";
1148
+ import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
957
1149
  import { createReadStream } from "node:fs";
958
1150
  import {
959
1151
  copyFile,
@@ -995,7 +1187,7 @@ async function writeSsgOutputMetrics(metrics) {
995
1187
 
996
1188
  // src/ssg/output_cache_replace.ts
997
1189
  async function checksumFile(path14) {
998
- const hash = createHash4("sha256");
1190
+ const hash = createHash5("sha256");
999
1191
  try {
1000
1192
  for await (const chunk of createReadStream(path14)) hash.update(chunk);
1001
1193
  return hash.digest("hex");
@@ -1466,7 +1658,7 @@ async function validateOutputCache(cache, path14, timingsMs, log = () => {
1466
1658
  }
1467
1659
 
1468
1660
  // src/ssg/output_cache_save.ts
1469
- import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
1661
+ import { createHash as createHash6, randomUUID as randomUUID4 } from "node:crypto";
1470
1662
  import { mkdir as mkdir5, rm as rm5, writeFile as writeFile4 } from "node:fs/promises";
1471
1663
  import { dirname as dirname5 } from "node:path";
1472
1664
  async function saveOutputCache(path14, state, outputDirectory, timingsMs) {
@@ -1508,7 +1700,7 @@ async function saveOutputCache(path14, state, outputDirectory, timingsMs) {
1508
1700
  "outputCacheRename",
1509
1701
  () => replaceFile(temporaryPath, path14)
1510
1702
  );
1511
- const checksum = createHash5("sha256").update(serialized).digest("hex");
1703
+ const checksum = createHash6("sha256").update(serialized).digest("hex");
1512
1704
  if (state.finalOutputInventory && state.configFile) {
1513
1705
  await saveFastPathCache(
1514
1706
  fastPathCachePath(path14),
@@ -1531,12 +1723,6 @@ async function saveOutputCache(path14, state, outputDirectory, timingsMs) {
1531
1723
  // src/ssg_plugin_helpers.ts
1532
1724
  import { lstat as lstat5, mkdir as mkdir6, writeFile as writeFile5 } from "node:fs/promises";
1533
1725
  import { dirname as dirname6, join as join6 } from "node:path";
1534
- import {
1535
- BUILD_OUTPUT_MARKER_FILE,
1536
- createBuildOutputMarker,
1537
- isDeferredGeneratedOutput,
1538
- serializeBuildOutputMarker
1539
- } from "@riebeckite/core";
1540
1726
  async function isDirectory(path14) {
1541
1727
  try {
1542
1728
  return (await lstat5(path14)).isDirectory();
@@ -1568,6 +1754,7 @@ async function emitGeneratedOutputs(module, emit, affectedPaths, shadowedPaths,
1568
1754
  const content = module.content;
1569
1755
  if (!content) return 0;
1570
1756
  if (affectedPaths?.size === 0) return 0;
1757
+ const { isDeferredGeneratedOutput } = await import("@riebeckite/core");
1571
1758
  const manifest = await content.getManifest();
1572
1759
  let count = 0;
1573
1760
  for (const output of manifest.generatedOutputs ?? []) {
@@ -1594,6 +1781,11 @@ function removeVirtualEntryChunk(bundle, virtualEntryId) {
1594
1781
  }
1595
1782
  }
1596
1783
  async function writePublicationMarker(input) {
1784
+ const {
1785
+ BUILD_OUTPUT_MARKER_FILE,
1786
+ createBuildOutputMarker,
1787
+ serializeBuildOutputMarker
1788
+ } = await import("@riebeckite/core");
1597
1789
  const path14 = join6(input.root, ".riebeckite", BUILD_OUTPUT_MARKER_FILE);
1598
1790
  try {
1599
1791
  await mkdir6(dirname6(path14), { recursive: true });
@@ -1620,6 +1812,7 @@ async function writePublicationMarker(input) {
1620
1812
  async function closeSsgBundle(plugin, state) {
1621
1813
  if (!state.resolvedConfig) return;
1622
1814
  if (state.resolvedConfig.mode === "client") return;
1815
+ const { buildOutputPlan, compareOutputPlan } = await import("@riebeckite/core");
1623
1816
  const outputDirectory = state.publicationOutputDirectory;
1624
1817
  if (!outputDirectory) {
1625
1818
  throw new Error(
@@ -1736,14 +1929,6 @@ async function closeSsgBundle(plugin, state) {
1736
1929
  }
1737
1930
  }
1738
1931
 
1739
- // src/ssg_plugin_generate_finalize.ts
1740
- import {
1741
- publicationFingerprint as fingerprintPublication,
1742
- publicationEntriesFromManifest,
1743
- publicationOutputsFromManifest,
1744
- publicationRedirectsFromManifest
1745
- } from "@riebeckite/core";
1746
-
1747
1932
  // src/ssg/diagnostics.ts
1748
1933
  function formatSsrNoExternal() {
1749
1934
  return "/^honox(?:\\/.*)?$/";
@@ -1802,6 +1987,12 @@ function inspectGeneratedHtmlPages(module, pages, log) {
1802
1987
 
1803
1988
  // src/ssg_plugin_generate_finalize.ts
1804
1989
  async function finalizeSsgGeneration(plugin, ctx, state) {
1990
+ const {
1991
+ publicationFingerprint: fingerprintPublication,
1992
+ publicationEntriesFromManifest,
1993
+ publicationRedirectsFromManifest,
1994
+ publicationOutputsFromManifest
1995
+ } = await import("@riebeckite/core");
1805
1996
  ctx.metrics.shadowedOutputCount = ctx.shadowedOutputs.size;
1806
1997
  if (ctx.shadowedOutputs.size > 0) {
1807
1998
  plugin.warn(
@@ -1869,8 +2060,6 @@ import { join as join7, resolve as resolve4 } from "node:path";
1869
2060
  // src/content_assets.ts
1870
2061
  import fs5 from "node:fs/promises";
1871
2062
  import path7 from "node:path";
1872
- import { isImagePath, normalizeContentPath } from "@riebeckite/core";
1873
- import { isIgnoredContentPath, isPathInsideDirectory } from "@riebeckite/node";
1874
2063
 
1875
2064
  // src/content_module.ts
1876
2065
  import path6 from "node:path";
@@ -1909,7 +2098,6 @@ function riebeckiteContentAssets(options) {
1909
2098
  apply: "serve",
1910
2099
  enforce: "pre",
1911
2100
  configureServer(server) {
1912
- const contentRoot = options.contentRoot();
1913
2101
  const base = server.config.base;
1914
2102
  const publicDir = server.config.publicDir;
1915
2103
  let cachedManifest;
@@ -1920,7 +2108,7 @@ function riebeckiteContentAssets(options) {
1920
2108
  };
1921
2109
  const deferredContents = /* @__PURE__ */ new Map();
1922
2110
  const resolvePublicAssets = async () => {
1923
- const module = await loadContentModule(server, options.appRoot());
2111
+ const module = await loadContentModule(server, await options.appRoot());
1924
2112
  const manifest = await module.content?.getManifest?.();
1925
2113
  if (!manifest) {
1926
2114
  return {
@@ -1933,9 +2121,9 @@ function riebeckiteContentAssets(options) {
1933
2121
  cachedManifest = manifest;
1934
2122
  deferredContents.clear();
1935
2123
  cachedAssets = {
1936
- paths: collectPublicImagePaths(manifest),
1937
- generated: collectGeneratedImageContents(manifest),
1938
- deferred: collectDeferredGeneratedImages(manifest)
2124
+ paths: await collectPublicImagePaths(manifest),
2125
+ generated: await collectGeneratedImageContents(manifest),
2126
+ deferred: await collectDeferredGeneratedImages(manifest)
1939
2127
  };
1940
2128
  }
1941
2129
  return cachedAssets;
@@ -1946,7 +2134,8 @@ function riebeckiteContentAssets(options) {
1946
2134
  next();
1947
2135
  return;
1948
2136
  }
1949
- const logicalPath = toContentPath(request.url, base);
2137
+ const { isIgnoredContentPath, isPathInsideDirectory } = await import("@riebeckite/node");
2138
+ const logicalPath = await toContentPath(request.url, base);
1950
2139
  if (!logicalPath) {
1951
2140
  next();
1952
2141
  return;
@@ -1984,6 +2173,7 @@ function riebeckiteContentAssets(options) {
1984
2173
  sendImage(request, response, contentType, content2);
1985
2174
  return;
1986
2175
  }
2176
+ const contentRoot = await options.contentRoot();
1987
2177
  const file = path7.join(contentRoot, logicalPath);
1988
2178
  if (!isPathInsideDirectory(contentRoot, file)) {
1989
2179
  next();
@@ -2002,7 +2192,8 @@ function riebeckiteContentAssets(options) {
2002
2192
  }
2003
2193
  };
2004
2194
  }
2005
- function collectPublicImagePaths(manifest) {
2195
+ async function collectPublicImagePaths(manifest) {
2196
+ const { isImagePath, normalizeContentPath } = await import("@riebeckite/core");
2006
2197
  const paths = /* @__PURE__ */ new Set();
2007
2198
  for (const entry of manifest.publicEntries ?? []) {
2008
2199
  for (const asset of entry.assets ?? []) {
@@ -2012,7 +2203,8 @@ function collectPublicImagePaths(manifest) {
2012
2203
  }
2013
2204
  return paths;
2014
2205
  }
2015
- function collectGeneratedImageContents(manifest) {
2206
+ async function collectGeneratedImageContents(manifest) {
2207
+ const { normalizeContentPath } = await import("@riebeckite/core");
2016
2208
  const contents = /* @__PURE__ */ new Map();
2017
2209
  for (const output of manifest.generatedOutputs ?? []) {
2018
2210
  if (output.content === void 0) continue;
@@ -2022,7 +2214,8 @@ function collectGeneratedImageContents(manifest) {
2022
2214
  }
2023
2215
  return contents;
2024
2216
  }
2025
- function collectDeferredGeneratedImages(manifest) {
2217
+ async function collectDeferredGeneratedImages(manifest) {
2218
+ const { normalizeContentPath } = await import("@riebeckite/core");
2026
2219
  const outputs = /* @__PURE__ */ new Map();
2027
2220
  for (const output of manifest.generatedOutputs ?? []) {
2028
2221
  if (!output.generate) continue;
@@ -2063,8 +2256,9 @@ async function collectSiteOwnedOutputPaths(publicDir) {
2063
2256
  await walk(root);
2064
2257
  return paths;
2065
2258
  }
2066
- function toContentPath(url, base) {
2259
+ async function toContentPath(url, base) {
2067
2260
  if (!url) return void 0;
2261
+ const { normalizeContentPath } = await import("@riebeckite/core");
2068
2262
  const withoutQuery = url.split("?")[0]?.split("#")[0];
2069
2263
  if (!withoutQuery) return void 0;
2070
2264
  let decoded = withoutQuery;
@@ -2883,9 +3077,6 @@ function createRiebeckiteSsg(options = {}) {
2883
3077
 
2884
3078
  // src/vite_plugin.ts
2885
3079
  import path13 from "node:path";
2886
- import {
2887
- createContentFormatRegistry
2888
- } from "@riebeckite/core";
2889
3080
  import {
2890
3081
  invalidateDevelopmentInspector,
2891
3082
  invalidateRiebeckiteBridge,
@@ -2897,27 +3088,39 @@ import { mergeConfig } from "vite";
2897
3088
  // src/asset_entries.ts
2898
3089
  import fs6 from "node:fs";
2899
3090
  import path8 from "node:path";
2900
- import { uniqueStrings } from "@riebeckite/core";
2901
- function writeRiebeckiteAssetEntries(config, paths) {
2902
- writeGeneratedFile(paths.frameworkStyles, createFrameworkStylesEntry());
2903
- writeGeneratedFile(paths.pluginStyles, createPluginStylesEntry(config));
2904
- 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
+ );
2905
3105
  }
2906
- function createFrameworkStylesEntry() {
3106
+ function createFrameworkStylesEntry(uniqueStrings) {
2907
3107
  return createStylesheetEntry(
3108
+ uniqueStrings,
2908
3109
  ["@riebeckite/honox/style.css"],
2909
3110
  "Framework structural styles. Generated by @riebeckite/honox; do not edit. Import this before the plugin and theme stylesheets."
2910
3111
  );
2911
3112
  }
2912
- function createPluginStylesEntry(config) {
3113
+ function createPluginStylesEntry(config, uniqueStrings) {
2913
3114
  return createStylesheetEntry(
3115
+ uniqueStrings,
2914
3116
  collectPluginStyleSpecifiers(config),
2915
3117
  "Plugin default styles in the rb-plugins cascade layer, in resolved plugin order. Generated by @riebeckite/honox; do not edit.",
2916
3118
  "rb-plugins"
2917
3119
  );
2918
3120
  }
2919
- function createThemeStylesEntry(config) {
3121
+ function createThemeStylesEntry(config, uniqueStrings) {
2920
3122
  return createStylesheetEntry(
3123
+ uniqueStrings,
2921
3124
  config.theme.styles.map((style) => style.moduleSpecifier),
2922
3125
  "Theme styles in the rb-theme cascade layer. Generated by @riebeckite/honox; do not edit.",
2923
3126
  "rb-theme"
@@ -2928,7 +3131,7 @@ function collectPluginStyleSpecifiers(config) {
2928
3131
  (plugin) => (plugin.assets ?? []).filter((asset) => asset.kind === "style").map((asset) => asset.moduleSpecifier)
2929
3132
  );
2930
3133
  }
2931
- function createStylesheetEntry(moduleSpecifiers, banner, layer) {
3134
+ function createStylesheetEntry(uniqueStrings, moduleSpecifiers, banner, layer) {
2932
3135
  const imports = uniqueStrings(moduleSpecifiers).map(
2933
3136
  (specifier) => `@import ${JSON.stringify(specifier)}${layer ? ` layer(${layer})` : ""};`
2934
3137
  ).join("\n");
@@ -2957,10 +3160,8 @@ function isNotFoundError3(error) {
2957
3160
  }
2958
3161
 
2959
3162
  // src/client_module_part2.ts
2960
- import {
2961
- serializePublicClientConfig
2962
- } from "@riebeckite/core";
2963
- function createClientModule(config, development) {
3163
+ async function createClientModule(config, development) {
3164
+ const { serializePublicClientConfig } = await import("@riebeckite/core");
2964
3165
  const imports = [];
2965
3166
  const appInitializers = [];
2966
3167
  const appConditionalInitializers = [];
@@ -3198,7 +3399,8 @@ export async function disposeRiebeckiteClient() {
3198
3399
  // src/client_module_part1.ts
3199
3400
  var clientModuleId = "virtual:riebeckite/client";
3200
3401
  var resolvedClientModuleId = `\0${clientModuleId}`;
3201
- function riebeckiteClientModule(getConfig) {
3402
+ function riebeckiteClientModule(getConfig, ensure = async () => {
3403
+ }) {
3202
3404
  let development = false;
3203
3405
  return {
3204
3406
  name: "riebeckite-client-module",
@@ -3209,21 +3411,16 @@ function riebeckiteClientModule(getConfig) {
3209
3411
  if (id === clientModuleId) return resolvedClientModuleId;
3210
3412
  return null;
3211
3413
  },
3212
- load(id) {
3414
+ async load(id) {
3415
+ await ensure();
3213
3416
  if (id !== resolvedClientModuleId) return null;
3214
- return createClientModule(getConfig(), development);
3417
+ return await createClientModule(getConfig(), development);
3215
3418
  }
3216
3419
  };
3217
3420
  }
3218
3421
 
3219
3422
  // src/content_watch.ts
3220
3423
  import path9 from "node:path";
3221
- import { isAttachmentPath, isImagePath as isImagePath2 } from "@riebeckite/core";
3222
- import {
3223
- isIgnoredContentPath as isIgnoredContentPath2,
3224
- isPathInsideDirectory as isPathInsideDirectory2,
3225
- toLogicalPath
3226
- } from "@riebeckite/node";
3227
3424
 
3228
3425
  // src/runtime_modules.ts
3229
3426
  var riebeckiteConfigModuleId = "virtual:riebeckite/config";
@@ -3237,7 +3434,8 @@ var runtimeModuleIds = [
3237
3434
  var resolvedConfigModuleId = `\0${riebeckiteConfigModuleId}`;
3238
3435
  var resolvedContentModuleId = `\0${riebeckiteContentModuleId}`;
3239
3436
  var resolvedContentRenderersModuleId = `\0${riebeckiteContentRenderersModuleId}`;
3240
- function riebeckiteRuntimeModules(getApplication) {
3437
+ function riebeckiteRuntimeModules(getApplication, ensure = async () => {
3438
+ }) {
3241
3439
  let development = false;
3242
3440
  return {
3243
3441
  name: "riebeckite-runtime-modules",
@@ -3251,7 +3449,8 @@ function riebeckiteRuntimeModules(getApplication) {
3251
3449
  return resolvedContentRenderersModuleId;
3252
3450
  return null;
3253
3451
  },
3254
- load(id) {
3452
+ async load(id) {
3453
+ await ensure();
3255
3454
  if (id === resolvedConfigModuleId) {
3256
3455
  const { appRoot, configFile } = getApplication();
3257
3456
  return createConfigModule(appRoot, configFile);
@@ -3375,45 +3574,51 @@ function riebeckiteContentWatch(options) {
3375
3574
  configureServer(server) {
3376
3575
  if (configuredWatchers.has(server.watcher)) return;
3377
3576
  configuredWatchers.add(server.watcher);
3378
- const appRoot = options.appRoot();
3379
- const contentRoot = options.contentRoot();
3380
- const exclude = options.exclude();
3381
- const isContentFile = (file) => isPathInsideDirectory2(contentRoot, file);
3382
- server.watcher.add(contentRoot);
3383
- suppressRestartOnContentEvents(server, isContentFile);
3384
- let timer;
3385
- const invalidate = () => {
3386
- if (timer) clearTimeout(timer);
3387
- timer = setTimeout(() => {
3388
- timer = void 0;
3389
- invalidateApplicationRuntime(server, appRoot);
3390
- options.onInvalidate?.(server);
3391
- server.hot.send({ type: "full-reload" });
3392
- }, CONTENT_RELOAD_DEBOUNCE_MS);
3393
- };
3394
- server.httpServer?.once("close", () => {
3395
- 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(() => {
3396
3616
  });
3397
- const handle = (event) => (file) => {
3398
- if (!isContentFile(file)) return;
3399
- const logicalPath = toLogicalPath(contentRoot, file);
3400
- if (isIgnoredContentPath2(logicalPath, exclude)) return;
3401
- if (event === "change" && isSiteAssetPath(logicalPath)) {
3402
- server.hot.send({ type: "full-reload" });
3403
- return;
3404
- }
3405
- invalidate();
3406
- };
3407
- server.watcher.on("add", handle("add"));
3408
- server.watcher.on("change", handle("change"));
3409
- server.watcher.on("unlink", handle("unlink"));
3410
3617
  }
3411
3618
  };
3412
3619
  }
3413
- function isSiteAssetPath(logicalPath) {
3414
- return isImagePath2(logicalPath) || isAttachmentPath(logicalPath);
3415
- }
3416
- function invalidateApplicationRuntime(server, appRoot) {
3620
+ async function invalidateApplicationRuntime(server, appRoot) {
3621
+ const { isPathInsideDirectory } = await import("@riebeckite/node");
3417
3622
  const moduleGraph = server.environments?.ssr?.moduleGraph;
3418
3623
  if (!moduleGraph) return 0;
3419
3624
  const appDirectory = path9.join(appRoot, "app") + path9.sep;
@@ -3421,14 +3626,15 @@ function invalidateApplicationRuntime(server, appRoot) {
3421
3626
  const timestamp = Date.now();
3422
3627
  let invalidated = 0;
3423
3628
  for (const mod of moduleGraph.idToModuleMap.values()) {
3424
- if (!isApplicationRuntimeModule(mod, appDirectory)) continue;
3629
+ if (!isApplicationRuntimeModule(mod, appDirectory, isPathInsideDirectory))
3630
+ continue;
3425
3631
  moduleGraph.invalidateModule(mod, seen, timestamp);
3426
3632
  invalidated += 1;
3427
3633
  }
3428
3634
  return invalidated;
3429
3635
  }
3430
- function isApplicationRuntimeModule(mod, appDirectory) {
3431
- 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;
3432
3638
  return isRiebeckiteRuntimeModuleId(mod.id);
3433
3639
  }
3434
3640
  function suppressRestartOnContentEvents(server, isContentFile) {
@@ -3792,38 +3998,57 @@ function riebeckite(options = {}, onApplicationResolved) {
3792
3998
  }
3793
3999
  return resolvedConfig;
3794
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
+ })();
3795
4038
  return [
3796
4039
  {
3797
4040
  name: "riebeckite-host-integration",
3798
- async config(userConfig) {
4041
+ async config(userConfig, environment) {
3799
4042
  const root = userConfig.root ? path13.resolve(userConfig.root) : process.cwd();
3800
- const appRoot = options.appRoot ?? root;
3801
- const resolvedApplication = await resolveHonoxApplication({
3802
- configRoot: options.configRoot ?? appRoot,
3803
- configFile: options.configFile,
3804
- appRoot,
3805
- workspaceRoot: options.workspaceRoot
3806
- });
3807
- resolvedConfig = resolvedApplication.config;
3808
- const resolved = resolvedConfig;
3809
- contentVitePlugins = resolved.plugins.flatMap(
3810
- (plugin) => plugin.vitePlugins?.({
3811
- contentDirectory: resolved.content.directory
3812
- }) ?? []
3813
- );
3814
- application = resolvedApplication;
3815
- onApplicationResolved?.(resolvedApplication);
3816
- writeRiebeckiteAssetEntries(resolvedConfig, {
3817
- frameworkStyles: path13.join(
3818
- appRoot,
3819
- "app/.riebeckite/framework-styles.css"
3820
- ),
3821
- pluginStyles: path13.join(appRoot, "app/.riebeckite/plugin-styles.css"),
3822
- themeStyles: path13.join(appRoot, "app/.riebeckite/theme-styles.css")
4043
+ applicationAppRoot = options.appRoot ?? root;
4044
+ void ensureApplication().catch(() => {
3823
4045
  });
4046
+ if (environment.command === "build") {
4047
+ await ensureApplication();
4048
+ }
3824
4049
  return {
3825
4050
  define: {
3826
- "process.env.RIEBECKITE_APP_ROOT": JSON.stringify(appRoot)
4051
+ "process.env.RIEBECKITE_APP_ROOT": JSON.stringify(applicationAppRoot)
3827
4052
  },
3828
4053
  oxc: {
3829
4054
  jsx: { runtime: "automatic", importSource: "hono/jsx" }
@@ -3837,26 +4062,40 @@ function riebeckite(options = {}, onApplicationResolved) {
3837
4062
  }
3838
4063
  },
3839
4064
  resolve: {
3840
- alias: options.workspaceRoot ? createWorkspacePackageAliases(options.workspaceRoot) : []
4065
+ alias: options.workspaceRoot ? await createWorkspacePackageAliases(options.workspaceRoot) : []
3841
4066
  }
3842
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
+ });
3843
4078
  }
3844
4079
  },
3845
4080
  contentVitePluginBridge(() => contentVitePlugins),
3846
- contentBareImportResolver(() => requireApplication(application)),
3847
- riebeckiteClientModule(getConfig),
3848
- riebeckiteRuntimeModules(() => requireApplication(application)),
3849
- riebeckiteContentWarmup(
3850
- options.warmContent ?? false,
3851
- () => requireApplication(application)
4081
+ contentBareImportResolver(
4082
+ () => requireApplication(application),
4083
+ ensureApplication
4084
+ ),
4085
+ injectRiebeckiteClientBundle(getConfig, ensureApplication),
4086
+ riebeckiteClientModule(getConfig, ensureApplication),
4087
+ riebeckiteRuntimeModules(
4088
+ () => requireApplication(application),
4089
+ ensureApplication
3852
4090
  ),
4091
+ riebeckiteContentWarmup(options.warmContent ?? false, ensureApplication),
3853
4092
  riebeckiteContentAssets({
3854
- appRoot: () => requireApplication(application).appRoot,
3855
- contentRoot: () => requireApplication(application).contentRoot
4093
+ appRoot: async () => (await ensureApplication()).appRoot,
4094
+ contentRoot: async () => (await ensureApplication()).contentRoot
3856
4095
  }),
3857
4096
  riebeckiteContentWatch({
3858
- appRoot: () => requireApplication(application).appRoot,
3859
- contentRoot: () => requireApplication(application).contentRoot,
4097
+ appRoot: async () => (await ensureApplication()).appRoot,
4098
+ contentRoot: async () => (await ensureApplication()).contentRoot,
3860
4099
  exclude: () => getConfig().content.exclude ?? [],
3861
4100
  onInvalidate(server) {
3862
4101
  invalidateDevelopmentInspector(server);
@@ -3877,7 +4116,12 @@ function riebeckite(options = {}, onApplicationResolved) {
3877
4116
  mutationToken: process.env.RIEBECKITE_BRIDGE_MUTATION_TOKEN,
3878
4117
  mutationApprovalToken: process.env.RIEBECKITE_BRIDGE_MUTATION_APPROVAL_TOKEN,
3879
4118
  contentRoot: () => requireApplication(application).contentRoot,
3880
- 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
+ },
3881
4125
  publicOrigin: () => getConfig().site.baseUrl || void 0,
3882
4126
  async getSnapshot(server) {
3883
4127
  const { appRoot } = requireApplication(application);
@@ -3896,8 +4140,12 @@ function riebeckiteContentWarmup(enabled, getApplication) {
3896
4140
  configureServer(server) {
3897
4141
  if (!enabled || !server.httpServer) return;
3898
4142
  server.httpServer.once("listening", () => {
3899
- const { appRoot } = getApplication();
3900
- 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) => {
3901
4149
  server.config.logger.error("Riebeckite content warmup failed.", {
3902
4150
  error: error instanceof Error ? error : new Error(String(error))
3903
4151
  });
@@ -3906,11 +4154,12 @@ function riebeckiteContentWarmup(enabled, getApplication) {
3906
4154
  }
3907
4155
  };
3908
4156
  }
3909
- function contentBareImportResolver(getApplication) {
4157
+ function contentBareImportResolver(getApplication, ensure) {
3910
4158
  return {
3911
4159
  name: "riebeckite-content-bare-imports",
3912
4160
  async resolveId(source, importer) {
3913
4161
  if (!importer || !isBareImport(source)) return null;
4162
+ await ensure();
3914
4163
  const { appRoot, contentRoot } = getApplication();
3915
4164
  if (!isInDirectory2(importer, contentRoot)) return null;
3916
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 {};
@@ -1,4 +1,5 @@
1
- import type { PluginOption } from "vite";
1
+ import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ import type { Plugin, PluginOption } from "vite";
2
3
  /**
3
4
  * Replaces HonoX's dependency walker with one that remains inside the app
4
5
  * directory. Riebeckite configurations import plugins with large dependency
@@ -6,3 +7,4 @@ import type { PluginOption } from "vite";
6
7
  * imports an island.
7
8
  */
8
9
  export declare function replaceHonoxIslandDependencyPlugin(plugins: PluginOption[]): PluginOption[];
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.51",
3
+ "version": "0.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,17 +43,17 @@
43
43
  "esbuild": "^0.28.2",
44
44
  "hono": "^4.13.18",
45
45
  "honox": "0.1.62",
46
- "vite": "^8.3.5",
47
- "@riebeckite/dev-inspector": "0.0.51",
48
- "@riebeckite/plugin-color-mode": "0.0.51",
49
- "@riebeckite/node": "0.0.51",
50
- "@riebeckite/og-image": "0.0.51",
51
- "@riebeckite/runtime": "0.0.51",
52
- "@riebeckite/ui": "0.0.51",
53
- "@riebeckite/spa": "0.0.51"
46
+ "vite": "^8.3.7",
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.51"
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/core": "0.0.51",
65
- "@riebeckite/plugin-bases": "0.0.51",
66
- "@riebeckite/test": "0.0.51"
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"