@lupinum/ginko-content 0.3.2 → 0.3.3
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/module.json +1 -1
- package/dist/module.mjs +43 -10
- package/dist/runtime/app/plugins/hot-reload.d.ts +4 -0
- package/dist/runtime/app/plugins/hot-reload.js +12 -4
- package/dist/web-types.json +1 -1
- package/package.json +1 -1
- package/dist/runtime/app/composables/hot-reload.d.ts +0 -5
- package/dist/runtime/app/composables/hot-reload.js +0 -15
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import { readFile, readdir, rm } from 'node:fs/promises';
|
|
|
4
4
|
import { join as join$1, basename, resolve as resolve$1, dirname, isAbsolute as isAbsolute$1 } from 'node:path';
|
|
5
5
|
import { buildResolvedContentContract } from '../dist/cms-contract/index.js';
|
|
6
6
|
import fs, { existsSync } from 'fs';
|
|
7
|
-
import {
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import { join, relative, isAbsolute, resolve } from 'pathe';
|
|
8
9
|
import jiti from 'jiti';
|
|
9
10
|
import { genSafeVariableName, genImport } from 'knitwork';
|
|
10
11
|
import { hash } from 'ohash';
|
|
@@ -29,7 +30,7 @@ import { createRouterMatcher } from 'vue-router';
|
|
|
29
30
|
import { globby } from 'globby';
|
|
30
31
|
|
|
31
32
|
const name = "@lupinum/ginko-content";
|
|
32
|
-
const version = "0.3.
|
|
33
|
+
const version = "0.3.3";
|
|
33
34
|
const peerDependencies = {
|
|
34
35
|
nuxt: ">=4.4.7 <5"};
|
|
35
36
|
|
|
@@ -40,6 +41,17 @@ const CONFIG_FILES = [
|
|
|
40
41
|
"content.config.mjs",
|
|
41
42
|
"content.config.cjs"
|
|
42
43
|
];
|
|
44
|
+
const isLocalModule = (filename, rootDir) => {
|
|
45
|
+
const localPath = relative(rootDir, filename);
|
|
46
|
+
return Boolean(localPath) && !localPath.startsWith("../") && !isAbsolute(localPath) && !localPath.split("/").includes("node_modules");
|
|
47
|
+
};
|
|
48
|
+
const clearLocalNativeModules = (cache, rootDir) => {
|
|
49
|
+
for (const [id, entry] of Object.entries(cache)) {
|
|
50
|
+
if (entry && isLocalModule(entry.filename, rootDir)) {
|
|
51
|
+
Reflect.deleteProperty(cache, id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
43
55
|
function resolveContentConfigPath(nuxt) {
|
|
44
56
|
return CONFIG_FILES.map((name) => join(nuxt.options.rootDir, name)).find((path) => existsSync(path));
|
|
45
57
|
}
|
|
@@ -48,8 +60,21 @@ async function loadContentConfig(nuxt) {
|
|
|
48
60
|
if (!configPath) {
|
|
49
61
|
return {};
|
|
50
62
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
63
|
+
const nativeRequire = createRequire(configPath);
|
|
64
|
+
clearLocalNativeModules(nativeRequire.cache, nuxt.options.rootDir);
|
|
65
|
+
const importer = jiti(nuxt.options.rootDir, {
|
|
66
|
+
interopDefault: true,
|
|
67
|
+
// Nuxt reloads module setup in the same process for `options.watch`
|
|
68
|
+
// changes. The authored config and its imports must not come from the
|
|
69
|
+
// previous setup's module cache.
|
|
70
|
+
moduleCache: false
|
|
71
|
+
});
|
|
72
|
+
let loaded;
|
|
73
|
+
try {
|
|
74
|
+
loaded = importer(configPath);
|
|
75
|
+
} finally {
|
|
76
|
+
clearLocalNativeModules(nativeRequire.cache, nuxt.options.rootDir);
|
|
77
|
+
}
|
|
53
78
|
return loaded?.default || loaded || {};
|
|
54
79
|
}
|
|
55
80
|
|
|
@@ -193,11 +218,8 @@ const registerContentDevRuntime = (nuxt, options, contentContext) => {
|
|
|
193
218
|
const isIgnored = makeIgnored(contentContext.ignores);
|
|
194
219
|
let viteServer;
|
|
195
220
|
if (options.watch !== false) {
|
|
196
|
-
nuxt.
|
|
197
|
-
|
|
198
|
-
nuxt.options.vite.plugins.push({
|
|
199
|
-
name: "ginko-content-hmr",
|
|
200
|
-
configureServer(server) {
|
|
221
|
+
nuxt.hook("vite:serverCreated", (server, environment) => {
|
|
222
|
+
if (environment.isClient) {
|
|
201
223
|
viteServer = server;
|
|
202
224
|
}
|
|
203
225
|
});
|
|
@@ -1868,6 +1890,12 @@ const module$1 = defineNuxtModule({
|
|
|
1868
1890
|
noExternal: runtimeInlineDependencies
|
|
1869
1891
|
});
|
|
1870
1892
|
const contentConfigPath = resolveContentConfigPath(nuxt);
|
|
1893
|
+
if (nuxt.options.dev && options.watch !== false && contentConfigPath) {
|
|
1894
|
+
nuxt.options.watch ||= [];
|
|
1895
|
+
if (!nuxt.options.watch.includes(contentConfigPath)) {
|
|
1896
|
+
nuxt.options.watch.push(contentConfigPath);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1871
1899
|
const appContentConfig = await loadContentConfig(nuxt);
|
|
1872
1900
|
if (!contentConfigPath || !appContentConfig.collections || !Object.keys(appContentConfig.collections).length) {
|
|
1873
1901
|
throw new Error("@lupinum/ginko-content requires a content.config.ts with at least one collection. Define collections with defineContentConfig({ collections: { ... } }).");
|
|
@@ -1935,7 +1963,12 @@ const module$1 = defineNuxtModule({
|
|
|
1935
1963
|
search: resolvedSearch,
|
|
1936
1964
|
validation: options.validation || "report"
|
|
1937
1965
|
};
|
|
1938
|
-
|
|
1966
|
+
const contentCacheDir = resolve$1(nuxt.options.buildDir, "content-cache");
|
|
1967
|
+
if (nuxt.options.dev) {
|
|
1968
|
+
await rm(contentCacheDir, { recursive: true, force: true });
|
|
1969
|
+
} else {
|
|
1970
|
+
await rm(resolve$1(contentCacheDir, "validation.json"), { force: true });
|
|
1971
|
+
}
|
|
1939
1972
|
const layers = nuxt.options._layers || [{ cwd: nuxt.options.rootDir, config: {} }];
|
|
1940
1973
|
const nitroPublicAssets = nuxt.options.nitro?.publicAssets || [];
|
|
1941
1974
|
contentContext.validationPublicAssets = await collectContentValidationPublicAssets({
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
type ContentHot = {
|
|
2
|
+
on: (event: 'ginko-content:update', callback: (data: unknown) => void) => void;
|
|
3
|
+
};
|
|
4
|
+
export declare function registerContentHotReload(hot: ContentHot | undefined, isClient: boolean, refresh: () => unknown): void;
|
|
1
5
|
declare const _default: any;
|
|
2
6
|
export default _default;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { defineNuxtPlugin } from "#imports";
|
|
2
|
-
export
|
|
3
|
-
if (
|
|
4
|
-
|
|
1
|
+
import { defineNuxtPlugin, refreshNuxtData } from "#imports";
|
|
2
|
+
export function registerContentHotReload(hot, isClient, refresh) {
|
|
3
|
+
if (!hot || !isClient) {
|
|
4
|
+
return;
|
|
5
5
|
}
|
|
6
|
+
hot.on("ginko-content:update", (data) => {
|
|
7
|
+
if (data && typeof data === "object") {
|
|
8
|
+
refresh();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export default defineNuxtPlugin(() => {
|
|
13
|
+
registerContentHotReload(import.meta.hot, import.meta.client, refreshNuxtData);
|
|
6
14
|
});
|
package/dist/web-types.json
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { refreshNuxtData } from "#imports";
|
|
2
|
-
let registered = false;
|
|
3
|
-
const onContentUpdate = (data) => {
|
|
4
|
-
if (!data || typeof data !== "object") {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
refreshNuxtData();
|
|
8
|
-
};
|
|
9
|
-
export function registerContentHotReload(hot = import.meta.hot, isClient = import.meta.client) {
|
|
10
|
-
if (!hot || !isClient || registered) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
registered = true;
|
|
14
|
-
hot.on("ginko-content:update", onContentUpdate);
|
|
15
|
-
}
|