@riebeckite/honox 0.0.48 → 0.0.50

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
@@ -1900,6 +1900,7 @@ var IMAGE_CONTENT_TYPES = {
1900
1900
  gif: "image/gif",
1901
1901
  svg: "image/svg+xml",
1902
1902
  webp: "image/webp",
1903
+ avif: "image/avif",
1903
1904
  bmp: "image/bmp"
1904
1905
  };
1905
1906
  function riebeckiteContentAssets(options) {
@@ -1912,16 +1913,22 @@ function riebeckiteContentAssets(options) {
1912
1913
  const base = server.config.base;
1913
1914
  const publicDir = server.config.publicDir;
1914
1915
  let cachedManifest;
1915
- let cachedPaths = /* @__PURE__ */ new Set();
1916
- const resolvePublicImagePaths = async () => {
1916
+ let cachedAssets = {
1917
+ paths: /* @__PURE__ */ new Set(),
1918
+ generated: /* @__PURE__ */ new Map()
1919
+ };
1920
+ const resolvePublicAssets = async () => {
1917
1921
  const module = await loadContentModule(server, options.appRoot());
1918
1922
  const manifest = await module.content?.getManifest?.();
1919
- if (!manifest) return /* @__PURE__ */ new Set();
1923
+ if (!manifest) return { paths: /* @__PURE__ */ new Set(), generated: /* @__PURE__ */ new Map() };
1920
1924
  if (manifest !== cachedManifest) {
1921
1925
  cachedManifest = manifest;
1922
- cachedPaths = collectPublicImagePaths(manifest);
1926
+ cachedAssets = {
1927
+ paths: collectPublicImagePaths(manifest),
1928
+ generated: collectGeneratedImageContents(manifest)
1929
+ };
1923
1930
  }
1924
- return cachedPaths;
1931
+ return cachedAssets;
1925
1932
  };
1926
1933
  const middleware = async (request, response, next) => {
1927
1934
  try {
@@ -1930,7 +1937,7 @@ function riebeckiteContentAssets(options) {
1930
1937
  return;
1931
1938
  }
1932
1939
  const logicalPath = toContentPath(request.url, base);
1933
- if (!logicalPath || !isImagePath(logicalPath)) {
1940
+ if (!logicalPath) {
1934
1941
  next();
1935
1942
  return;
1936
1943
  }
@@ -1943,30 +1950,27 @@ function riebeckiteContentAssets(options) {
1943
1950
  next();
1944
1951
  return;
1945
1952
  }
1946
- const available = await resolvePublicImagePaths();
1947
- if (!available.has(logicalPath)) {
1953
+ const available = await resolvePublicAssets();
1954
+ const generated = available.generated.get(logicalPath);
1955
+ if (generated === void 0 && !available.paths.has(logicalPath)) {
1948
1956
  next();
1949
1957
  return;
1950
1958
  }
1951
- const file = path7.join(contentRoot, logicalPath);
1952
- if (!isPathInsideDirectory(contentRoot, file)) {
1959
+ if (await hasSiteOwnedFile(publicDir, logicalPath)) {
1953
1960
  next();
1954
1961
  return;
1955
1962
  }
1956
- if (await hasSiteOwnedFile(publicDir, logicalPath)) {
1957
- next();
1963
+ if (generated !== void 0) {
1964
+ sendImage(request, response, contentType, generated);
1958
1965
  return;
1959
1966
  }
1960
- const content = await fs5.readFile(file);
1961
- response.statusCode = 200;
1962
- response.setHeader("Content-Type", contentType);
1963
- response.setHeader("Content-Length", String(content.byteLength));
1964
- response.setHeader("Cache-Control", "no-cache");
1965
- if (request.method === "HEAD") {
1966
- response.end();
1967
+ const file = path7.join(contentRoot, logicalPath);
1968
+ if (!isPathInsideDirectory(contentRoot, file)) {
1969
+ next();
1967
1970
  return;
1968
1971
  }
1969
- response.end(content);
1972
+ const content = await fs5.readFile(file);
1973
+ sendImage(request, response, contentType, content);
1970
1974
  return;
1971
1975
  } catch {
1972
1976
  next();
@@ -1988,6 +1992,16 @@ function collectPublicImagePaths(manifest) {
1988
1992
  }
1989
1993
  return paths;
1990
1994
  }
1995
+ function collectGeneratedImageContents(manifest) {
1996
+ const contents = /* @__PURE__ */ new Map();
1997
+ for (const output of manifest.generatedOutputs ?? []) {
1998
+ if (output.content === void 0) continue;
1999
+ const normalized = normalizeContentPath(output.path);
2000
+ if (!imageContentType(normalized)) continue;
2001
+ contents.set(normalized, output.content);
2002
+ }
2003
+ return contents;
2004
+ }
1991
2005
  async function collectSiteOwnedOutputPaths(publicDir) {
1992
2006
  const paths = /* @__PURE__ */ new Set();
1993
2007
  if (!publicDir) return paths;
@@ -2033,6 +2047,18 @@ function imageContentType(logicalPath) {
2033
2047
  if (!extension) return void 0;
2034
2048
  return IMAGE_CONTENT_TYPES[extension.toLowerCase()];
2035
2049
  }
2050
+ function sendImage(request, response, contentType, content) {
2051
+ const body = typeof content === "string" ? Buffer.from(content) : content;
2052
+ response.statusCode = 200;
2053
+ response.setHeader("Content-Type", contentType);
2054
+ response.setHeader("Content-Length", String(body.byteLength));
2055
+ response.setHeader("Cache-Control", "no-cache");
2056
+ if (request.method === "HEAD") {
2057
+ response.end();
2058
+ return;
2059
+ }
2060
+ response.end(body);
2061
+ }
2036
2062
  async function hasSiteOwnedFile(publicDir, logicalPath) {
2037
2063
  if (!publicDir) return false;
2038
2064
  const file = path7.join(publicDir, logicalPath);
@@ -3778,6 +3804,10 @@ function riebeckite(options = {}, onApplicationResolved) {
3778
3804
  contentBareImportResolver(() => requireApplication(application)),
3779
3805
  riebeckiteClientModule(getConfig),
3780
3806
  riebeckiteRuntimeModules(() => requireApplication(application)),
3807
+ riebeckiteContentWarmup(
3808
+ options.warmContent ?? false,
3809
+ () => requireApplication(application)
3810
+ ),
3781
3811
  riebeckiteContentAssets({
3782
3812
  appRoot: () => requireApplication(application).appRoot,
3783
3813
  contentRoot: () => requireApplication(application).contentRoot
@@ -3815,6 +3845,26 @@ function riebeckite(options = {}, onApplicationResolved) {
3815
3845
  })
3816
3846
  ];
3817
3847
  }
3848
+ function riebeckiteContentWarmup(enabled, getApplication) {
3849
+ return {
3850
+ name: "riebeckite-content-warmup",
3851
+ apply: "serve",
3852
+ configureServer(server) {
3853
+ if (!enabled || !server.httpServer) return;
3854
+ server.httpServer.once("listening", () => {
3855
+ const { appRoot } = getApplication();
3856
+ void loadContentModule(server, appRoot).then(async (module) => await module.content?.getManifest?.()).catch((error) => {
3857
+ server.config.logger.error(
3858
+ "Riebeckite content warmup failed.",
3859
+ {
3860
+ error: error instanceof Error ? error : new Error(String(error))
3861
+ }
3862
+ );
3863
+ });
3864
+ });
3865
+ }
3866
+ };
3867
+ }
3818
3868
  function contentBareImportResolver(getApplication) {
3819
3869
  return {
3820
3870
  name: "riebeckite-content-bare-imports",
@@ -8,11 +8,17 @@ type ContentAssetEntry = {
8
8
  path: string;
9
9
  }>;
10
10
  };
11
- type PublicContentManifest = {
11
+ type GeneratedOutputEntry = {
12
+ path: string;
13
+ content?: Uint8Array | string;
14
+ };
15
+ export type PublicContentManifest = {
12
16
  publicEntries?: ReadonlyArray<ContentAssetEntry>;
17
+ generatedOutputs?: ReadonlyArray<GeneratedOutputEntry>;
13
18
  };
14
19
  export declare function riebeckiteContentAssets(options: RiebeckiteContentAssetsOptions): Plugin;
15
20
  export declare function collectPublicImagePaths(manifest: PublicContentManifest): Set<string>;
21
+ export declare function collectGeneratedImageContents(manifest: PublicContentManifest): Map<string, Uint8Array | string>;
16
22
  export declare function collectSiteOwnedOutputPaths(publicDir: string | false | undefined): Promise<Set<string>>;
17
23
  export declare function toContentPath(url: string | undefined, base: string): string | undefined;
18
24
  export declare function imageContentType(logicalPath: string): string | undefined;
@@ -8,12 +8,14 @@ import { type ResolvedHonoxApplication } from "./vite_runner.js";
8
8
  * restate the Vite `environments.ssr.resolve.external` list.
9
9
  */
10
10
  export type RiebeckiteViteOptions = RiebeckiteIntegrationOptions & {
11
+ warmContent?: boolean;
11
12
  /** Extra SSR externals appended after Riebeckite's defaults. */
12
13
  ssrExternals?: readonly string[];
13
14
  /** SSG overrides. A normal site does not need them. */
14
15
  ssg?: RiebeckiteSsgOptions;
15
16
  };
16
- export declare function riebeckite(options?: RiebeckiteIntegrationOptions, onApplicationResolved?: (application: ResolvedHonoxApplication) => void): Plugin[];
17
+ export declare function riebeckite(options?: RiebeckiteViteOptions, onApplicationResolved?: (application: ResolvedHonoxApplication) => void): Plugin[];
18
+ export declare function riebeckiteContentWarmup(enabled: boolean, getApplication: () => ResolvedHonoxApplication): Plugin;
17
19
  /**
18
20
  * Higher-level helper that registers the complete Riebeckite Vite integration
19
21
  * without exposing internal Vite/HonoX/SSR details. A site only needs to add
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/honox",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -44,12 +44,12 @@
44
44
  "hono": "^4.13.18",
45
45
  "honox": "0.1.62",
46
46
  "vite": "^8.3.5",
47
- "@riebeckite/plugin-color-mode": "0.0.48",
48
- "@riebeckite/dev-inspector": "0.0.48",
49
- "@riebeckite/core": "0.0.48",
50
- "@riebeckite/spa": "0.0.48",
51
- "@riebeckite/node": "0.0.48",
52
- "@riebeckite/ui": "0.0.48"
47
+ "@riebeckite/dev-inspector": "0.0.50",
48
+ "@riebeckite/core": "0.0.50",
49
+ "@riebeckite/ui": "0.0.50",
50
+ "@riebeckite/spa": "0.0.50",
51
+ "@riebeckite/node": "0.0.50",
52
+ "@riebeckite/plugin-color-mode": "0.0.50"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@d2lang/d2": "^0.1.34",
@@ -57,8 +57,8 @@
57
57
  "@hono/vite-build": "^1.11.1",
58
58
  "@marp-team/marp-core": "^4.4.0",
59
59
  "tsx": "^4.22.4",
60
- "@riebeckite/plugin-bases": "0.0.48",
61
- "@riebeckite/test": "0.0.48"
60
+ "@riebeckite/test": "0.0.50",
61
+ "@riebeckite/plugin-bases": "0.0.50"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public"