@riebeckite/honox 0.0.49 → 0.0.51
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 +111 -20
- package/dist/src/content_assets.d.ts +12 -1
- package/dist/src/vite_plugin.d.ts +3 -1
- package/package.json +14 -9
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,32 @@ function riebeckiteContentAssets(options) {
|
|
|
1912
1913
|
const base = server.config.base;
|
|
1913
1914
|
const publicDir = server.config.publicDir;
|
|
1914
1915
|
let cachedManifest;
|
|
1915
|
-
let
|
|
1916
|
-
|
|
1916
|
+
let cachedAssets = {
|
|
1917
|
+
paths: /* @__PURE__ */ new Set(),
|
|
1918
|
+
generated: /* @__PURE__ */ new Map(),
|
|
1919
|
+
deferred: /* @__PURE__ */ new Map()
|
|
1920
|
+
};
|
|
1921
|
+
const deferredContents = /* @__PURE__ */ new Map();
|
|
1922
|
+
const resolvePublicAssets = async () => {
|
|
1917
1923
|
const module = await loadContentModule(server, options.appRoot());
|
|
1918
1924
|
const manifest = await module.content?.getManifest?.();
|
|
1919
|
-
if (!manifest)
|
|
1925
|
+
if (!manifest) {
|
|
1926
|
+
return {
|
|
1927
|
+
paths: /* @__PURE__ */ new Set(),
|
|
1928
|
+
generated: /* @__PURE__ */ new Map(),
|
|
1929
|
+
deferred: /* @__PURE__ */ new Map()
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1920
1932
|
if (manifest !== cachedManifest) {
|
|
1921
1933
|
cachedManifest = manifest;
|
|
1922
|
-
|
|
1934
|
+
deferredContents.clear();
|
|
1935
|
+
cachedAssets = {
|
|
1936
|
+
paths: collectPublicImagePaths(manifest),
|
|
1937
|
+
generated: collectGeneratedImageContents(manifest),
|
|
1938
|
+
deferred: collectDeferredGeneratedImages(manifest)
|
|
1939
|
+
};
|
|
1923
1940
|
}
|
|
1924
|
-
return
|
|
1941
|
+
return cachedAssets;
|
|
1925
1942
|
};
|
|
1926
1943
|
const middleware = async (request, response, next) => {
|
|
1927
1944
|
try {
|
|
@@ -1930,7 +1947,7 @@ function riebeckiteContentAssets(options) {
|
|
|
1930
1947
|
return;
|
|
1931
1948
|
}
|
|
1932
1949
|
const logicalPath = toContentPath(request.url, base);
|
|
1933
|
-
if (!logicalPath
|
|
1950
|
+
if (!logicalPath) {
|
|
1934
1951
|
next();
|
|
1935
1952
|
return;
|
|
1936
1953
|
}
|
|
@@ -1943,30 +1960,37 @@ function riebeckiteContentAssets(options) {
|
|
|
1943
1960
|
next();
|
|
1944
1961
|
return;
|
|
1945
1962
|
}
|
|
1946
|
-
const available = await
|
|
1947
|
-
|
|
1963
|
+
const available = await resolvePublicAssets();
|
|
1964
|
+
const generated = available.generated.get(logicalPath);
|
|
1965
|
+
const deferred = available.deferred.get(logicalPath);
|
|
1966
|
+
if (generated === void 0 && deferred === void 0 && !available.paths.has(logicalPath)) {
|
|
1948
1967
|
next();
|
|
1949
1968
|
return;
|
|
1950
1969
|
}
|
|
1951
|
-
|
|
1952
|
-
if (!isPathInsideDirectory(contentRoot, file)) {
|
|
1970
|
+
if (await hasSiteOwnedFile(publicDir, logicalPath)) {
|
|
1953
1971
|
next();
|
|
1954
1972
|
return;
|
|
1955
1973
|
}
|
|
1956
|
-
if (
|
|
1957
|
-
|
|
1974
|
+
if (generated !== void 0) {
|
|
1975
|
+
sendImage(request, response, contentType, generated);
|
|
1958
1976
|
return;
|
|
1959
1977
|
}
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
response
|
|
1978
|
+
if (deferred !== void 0) {
|
|
1979
|
+
const content2 = await resolveDeferredImage(
|
|
1980
|
+
deferredContents,
|
|
1981
|
+
logicalPath,
|
|
1982
|
+
deferred
|
|
1983
|
+
);
|
|
1984
|
+
sendImage(request, response, contentType, content2);
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1987
|
+
const file = path7.join(contentRoot, logicalPath);
|
|
1988
|
+
if (!isPathInsideDirectory(contentRoot, file)) {
|
|
1989
|
+
next();
|
|
1967
1990
|
return;
|
|
1968
1991
|
}
|
|
1969
|
-
|
|
1992
|
+
const content = await fs5.readFile(file);
|
|
1993
|
+
sendImage(request, response, contentType, content);
|
|
1970
1994
|
return;
|
|
1971
1995
|
} catch {
|
|
1972
1996
|
next();
|
|
@@ -1988,6 +2012,38 @@ function collectPublicImagePaths(manifest) {
|
|
|
1988
2012
|
}
|
|
1989
2013
|
return paths;
|
|
1990
2014
|
}
|
|
2015
|
+
function collectGeneratedImageContents(manifest) {
|
|
2016
|
+
const contents = /* @__PURE__ */ new Map();
|
|
2017
|
+
for (const output of manifest.generatedOutputs ?? []) {
|
|
2018
|
+
if (output.content === void 0) continue;
|
|
2019
|
+
const normalized = normalizeContentPath(output.path);
|
|
2020
|
+
if (!imageContentType(normalized)) continue;
|
|
2021
|
+
contents.set(normalized, output.content);
|
|
2022
|
+
}
|
|
2023
|
+
return contents;
|
|
2024
|
+
}
|
|
2025
|
+
function collectDeferredGeneratedImages(manifest) {
|
|
2026
|
+
const outputs = /* @__PURE__ */ new Map();
|
|
2027
|
+
for (const output of manifest.generatedOutputs ?? []) {
|
|
2028
|
+
if (!output.generate) continue;
|
|
2029
|
+
const normalized = normalizeContentPath(output.path);
|
|
2030
|
+
if (!imageContentType(normalized)) continue;
|
|
2031
|
+
outputs.set(normalized, { generate: output.generate });
|
|
2032
|
+
}
|
|
2033
|
+
return outputs;
|
|
2034
|
+
}
|
|
2035
|
+
async function resolveDeferredImage(cache, logicalPath, output) {
|
|
2036
|
+
const cached = cache.get(logicalPath);
|
|
2037
|
+
if (cached) return await cached;
|
|
2038
|
+
const content = Promise.resolve().then(output.generate);
|
|
2039
|
+
cache.set(logicalPath, content);
|
|
2040
|
+
try {
|
|
2041
|
+
return await content;
|
|
2042
|
+
} catch (error) {
|
|
2043
|
+
cache.delete(logicalPath);
|
|
2044
|
+
throw error;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
1991
2047
|
async function collectSiteOwnedOutputPaths(publicDir) {
|
|
1992
2048
|
const paths = /* @__PURE__ */ new Set();
|
|
1993
2049
|
if (!publicDir) return paths;
|
|
@@ -2033,6 +2089,18 @@ function imageContentType(logicalPath) {
|
|
|
2033
2089
|
if (!extension) return void 0;
|
|
2034
2090
|
return IMAGE_CONTENT_TYPES[extension.toLowerCase()];
|
|
2035
2091
|
}
|
|
2092
|
+
function sendImage(request, response, contentType, content) {
|
|
2093
|
+
const body = typeof content === "string" ? Buffer.from(content) : content;
|
|
2094
|
+
response.statusCode = 200;
|
|
2095
|
+
response.setHeader("Content-Type", contentType);
|
|
2096
|
+
response.setHeader("Content-Length", String(body.byteLength));
|
|
2097
|
+
response.setHeader("Cache-Control", "no-cache");
|
|
2098
|
+
if (request.method === "HEAD") {
|
|
2099
|
+
response.end();
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
response.end(body);
|
|
2103
|
+
}
|
|
2036
2104
|
async function hasSiteOwnedFile(publicDir, logicalPath) {
|
|
2037
2105
|
if (!publicDir) return false;
|
|
2038
2106
|
const file = path7.join(publicDir, logicalPath);
|
|
@@ -3778,6 +3846,10 @@ function riebeckite(options = {}, onApplicationResolved) {
|
|
|
3778
3846
|
contentBareImportResolver(() => requireApplication(application)),
|
|
3779
3847
|
riebeckiteClientModule(getConfig),
|
|
3780
3848
|
riebeckiteRuntimeModules(() => requireApplication(application)),
|
|
3849
|
+
riebeckiteContentWarmup(
|
|
3850
|
+
options.warmContent ?? false,
|
|
3851
|
+
() => requireApplication(application)
|
|
3852
|
+
),
|
|
3781
3853
|
riebeckiteContentAssets({
|
|
3782
3854
|
appRoot: () => requireApplication(application).appRoot,
|
|
3783
3855
|
contentRoot: () => requireApplication(application).contentRoot
|
|
@@ -3796,6 +3868,7 @@ function riebeckite(options = {}, onApplicationResolved) {
|
|
|
3796
3868
|
const { appRoot } = requireApplication(application);
|
|
3797
3869
|
if (!isContentModuleLoaded(server, appRoot)) return void 0;
|
|
3798
3870
|
const module = await loadContentModule(server, appRoot);
|
|
3871
|
+
await module.content?.getManifest?.();
|
|
3799
3872
|
return module.content?.getCompletedBuildSnapshot?.();
|
|
3800
3873
|
}
|
|
3801
3874
|
}),
|
|
@@ -3810,11 +3883,29 @@ function riebeckite(options = {}, onApplicationResolved) {
|
|
|
3810
3883
|
const { appRoot } = requireApplication(application);
|
|
3811
3884
|
if (!isContentModuleLoaded(server, appRoot)) return void 0;
|
|
3812
3885
|
const module = await loadContentModule(server, appRoot);
|
|
3886
|
+
await module.content?.getManifest?.();
|
|
3813
3887
|
return module.content?.getCompletedBuildSnapshot?.();
|
|
3814
3888
|
}
|
|
3815
3889
|
})
|
|
3816
3890
|
];
|
|
3817
3891
|
}
|
|
3892
|
+
function riebeckiteContentWarmup(enabled, getApplication) {
|
|
3893
|
+
return {
|
|
3894
|
+
name: "riebeckite-content-warmup",
|
|
3895
|
+
apply: "serve",
|
|
3896
|
+
configureServer(server) {
|
|
3897
|
+
if (!enabled || !server.httpServer) return;
|
|
3898
|
+
server.httpServer.once("listening", () => {
|
|
3899
|
+
const { appRoot } = getApplication();
|
|
3900
|
+
void loadContentModule(server, appRoot).then(async (module) => await module.content?.getManifest?.()).catch((error) => {
|
|
3901
|
+
server.config.logger.error("Riebeckite content warmup failed.", {
|
|
3902
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
3903
|
+
});
|
|
3904
|
+
});
|
|
3905
|
+
});
|
|
3906
|
+
}
|
|
3907
|
+
};
|
|
3908
|
+
}
|
|
3818
3909
|
function contentBareImportResolver(getApplication) {
|
|
3819
3910
|
return {
|
|
3820
3911
|
name: "riebeckite-content-bare-imports",
|
|
@@ -8,11 +8,22 @@ type ContentAssetEntry = {
|
|
|
8
8
|
path: string;
|
|
9
9
|
}>;
|
|
10
10
|
};
|
|
11
|
-
type
|
|
11
|
+
type GeneratedOutputEntry = {
|
|
12
|
+
path: string;
|
|
13
|
+
content?: Uint8Array | string;
|
|
14
|
+
generate?: () => Uint8Array | string | Promise<Uint8Array | string>;
|
|
15
|
+
};
|
|
16
|
+
type DeferredGeneratedImage = {
|
|
17
|
+
generate: () => Uint8Array | string | Promise<Uint8Array | string>;
|
|
18
|
+
};
|
|
19
|
+
export type PublicContentManifest = {
|
|
12
20
|
publicEntries?: ReadonlyArray<ContentAssetEntry>;
|
|
21
|
+
generatedOutputs?: ReadonlyArray<GeneratedOutputEntry>;
|
|
13
22
|
};
|
|
14
23
|
export declare function riebeckiteContentAssets(options: RiebeckiteContentAssetsOptions): Plugin;
|
|
15
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>;
|
|
16
27
|
export declare function collectSiteOwnedOutputPaths(publicDir: string | false | undefined): Promise<Set<string>>;
|
|
17
28
|
export declare function toContentPath(url: string | undefined, base: string): string | undefined;
|
|
18
29
|
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?:
|
|
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.
|
|
3
|
+
"version": "0.0.51",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,12 +44,16 @@
|
|
|
44
44
|
"hono": "^4.13.18",
|
|
45
45
|
"honox": "0.1.62",
|
|
46
46
|
"vite": "^8.3.5",
|
|
47
|
-
"@riebeckite/
|
|
48
|
-
"@riebeckite/
|
|
49
|
-
"@riebeckite/node": "0.0.
|
|
50
|
-
"@riebeckite/
|
|
51
|
-
"@riebeckite/
|
|
52
|
-
"@riebeckite/ui": "0.0.
|
|
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"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@riebeckite/core": "^0.0.51"
|
|
53
57
|
},
|
|
54
58
|
"devDependencies": {
|
|
55
59
|
"@d2lang/d2": "^0.1.34",
|
|
@@ -57,8 +61,9 @@
|
|
|
57
61
|
"@hono/vite-build": "^1.11.1",
|
|
58
62
|
"@marp-team/marp-core": "^4.4.0",
|
|
59
63
|
"tsx": "^4.22.4",
|
|
60
|
-
"@riebeckite/
|
|
61
|
-
"@riebeckite/plugin-bases": "0.0.
|
|
64
|
+
"@riebeckite/core": "0.0.51",
|
|
65
|
+
"@riebeckite/plugin-bases": "0.0.51",
|
|
66
|
+
"@riebeckite/test": "0.0.51"
|
|
62
67
|
},
|
|
63
68
|
"publishConfig": {
|
|
64
69
|
"access": "public"
|