@dyrected/nuxt 2.5.12 → 2.5.14
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 +30 -5
- package/dist/runtime/server/handler.mjs +4 -4
- package/dist/runtime/server/plugins/db.mjs +5 -2
- package/dist/runtime/server/plugins/loadConfig.d.ts +0 -1
- package/dist/runtime/server/plugins/loadConfig.mjs +20 -12
- package/package.json +5 -5
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addServerHandler, addPlugin, addComponent, addImports, addServerPlugin } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, addServerHandler, addPlugin, addComponent, addImports, addTemplate, addServerPlugin } from '@nuxt/kit';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { existsSync } from 'fs';
|
|
4
4
|
import { createRequire } from 'module';
|
|
@@ -76,7 +76,21 @@ const module = defineNuxtModule({
|
|
|
76
76
|
if (configPath) {
|
|
77
77
|
console.log("[dyrected/nuxt] Auto-detected config at:", configPath);
|
|
78
78
|
runtimeConfig.configPath = configPath;
|
|
79
|
-
|
|
79
|
+
let loadConfigPath = resolver.resolve("./runtime/server/plugins/loadConfig.ts");
|
|
80
|
+
if (!existsSync(loadConfigPath)) {
|
|
81
|
+
loadConfigPath = resolver.resolve("./runtime/server/plugins/loadConfig.mjs");
|
|
82
|
+
}
|
|
83
|
+
runtimeConfig.loadConfigPath = loadConfigPath;
|
|
84
|
+
let dbPluginSrc = resolver.resolve("./runtime/server/plugins/db.ts");
|
|
85
|
+
if (!existsSync(dbPluginSrc)) {
|
|
86
|
+
dbPluginSrc = resolver.resolve("./runtime/server/plugins/db.mjs");
|
|
87
|
+
}
|
|
88
|
+
const dbPluginTemplate = addTemplate({
|
|
89
|
+
src: dbPluginSrc,
|
|
90
|
+
filename: "dyrected-db-plugin.ts",
|
|
91
|
+
write: true
|
|
92
|
+
});
|
|
93
|
+
addServerPlugin(dbPluginTemplate.dst);
|
|
80
94
|
} else {
|
|
81
95
|
console.warn("[dyrected/nuxt] Could not find dyrected.config.ts. Self-hosted database re-hydration might fail.");
|
|
82
96
|
}
|
|
@@ -111,10 +125,14 @@ const module = defineNuxtModule({
|
|
|
111
125
|
if (nuxt.options.vite) {
|
|
112
126
|
nuxt.options.vite.optimizeDeps = nuxt.options.vite.optimizeDeps || {};
|
|
113
127
|
nuxt.options.vite.optimizeDeps.include = nuxt.options.vite.optimizeDeps.include || [];
|
|
114
|
-
const toInclude = ["react", "react-dom", "react-router-dom", "@tanstack/react-query"
|
|
128
|
+
const toInclude = ["react", "react-dom", "react-router-dom", "@tanstack/react-query"];
|
|
115
129
|
for (const dep of toInclude) {
|
|
116
|
-
|
|
117
|
-
|
|
130
|
+
try {
|
|
131
|
+
_require.resolve(dep);
|
|
132
|
+
if (!nuxt.options.vite.optimizeDeps.include.includes(dep)) {
|
|
133
|
+
nuxt.options.vite.optimizeDeps.include.push(dep);
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
118
136
|
}
|
|
119
137
|
}
|
|
120
138
|
nuxt.options.vite.optimizeDeps.exclude = nuxt.options.vite.optimizeDeps.exclude || [];
|
|
@@ -126,6 +144,13 @@ const module = defineNuxtModule({
|
|
|
126
144
|
}
|
|
127
145
|
}
|
|
128
146
|
nuxt.options.build.transpile.push("@dyrected/sdk", "@dyrected/vue", "@dyrected/admin");
|
|
147
|
+
const optionsAny = nuxt.options;
|
|
148
|
+
optionsAny.nitro = optionsAny.nitro || {};
|
|
149
|
+
optionsAny.nitro.externals = optionsAny.nitro.externals || {};
|
|
150
|
+
optionsAny.nitro.externals.inline = optionsAny.nitro.externals.inline || [];
|
|
151
|
+
if (!optionsAny.nitro.externals.inline.includes("@dyrected/nuxt")) {
|
|
152
|
+
optionsAny.nitro.externals.inline.push("@dyrected/nuxt");
|
|
153
|
+
}
|
|
129
154
|
nuxt.hook("vite:extendConfig", (config) => {
|
|
130
155
|
const plugins = config.plugins ?? [];
|
|
131
156
|
const unctxPlugin = plugins.find((p) => p && typeof p === "object" && p.name === "unctx:transform");
|
|
@@ -2,15 +2,15 @@ import { defineEventHandler, getRequestURL } from "h3";
|
|
|
2
2
|
import { createDyrectedApp } from "@dyrected/core/server";
|
|
3
3
|
import { useRuntimeConfig } from "#imports";
|
|
4
4
|
let app;
|
|
5
|
+
let lastVersion = 0;
|
|
5
6
|
export default defineEventHandler(async (event) => {
|
|
6
7
|
const config = useRuntimeConfig().dyrected;
|
|
7
|
-
|
|
8
|
+
const currentVersion = globalThis.__dyrected_config_version || 0;
|
|
9
|
+
if (!app || currentVersion !== lastVersion) {
|
|
10
|
+
lastVersion = currentVersion;
|
|
8
11
|
let dyrectedConfig = { ...config };
|
|
9
12
|
if (globalThis.__dyrected_config) {
|
|
10
13
|
const gConfig = globalThis.__dyrected_config;
|
|
11
|
-
console.log("[dyrected/nuxt] raw __dyrected_config:", gConfig);
|
|
12
|
-
console.log("[dyrected/nuxt] raw __dyrected_config keys:", Object.keys(gConfig || {}));
|
|
13
|
-
console.log("[dyrected/nuxt] raw __dyrected_config default keys:", Object.keys(gConfig?.default || {}));
|
|
14
14
|
const configObj = gConfig.default && (gConfig.default.collections || gConfig.default.globals || gConfig.default.db) ? gConfig.default : gConfig;
|
|
15
15
|
console.log("[dyrected/nuxt] chosen configObj keys:", Object.keys(configObj || {}));
|
|
16
16
|
dyrectedConfig = { ...dyrectedConfig, ...configObj };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { defineNitroPlugin } from "nitropack/runtime";
|
|
2
1
|
import { useRuntimeConfig } from "#imports";
|
|
3
|
-
|
|
2
|
+
const defineNitroPlugin = (def) => def;
|
|
4
3
|
export default defineNitroPlugin(async (nitroApp) => {
|
|
5
4
|
const runtimeConfig = useRuntimeConfig().dyrected;
|
|
6
5
|
if (runtimeConfig?.configPath) {
|
|
7
6
|
try {
|
|
8
7
|
const configPath = runtimeConfig.configPath;
|
|
8
|
+
const loadConfigPath = runtimeConfig.loadConfigPath;
|
|
9
|
+
const { loadDyrectedConfig, ConfigLoadError } = await import(loadConfigPath);
|
|
9
10
|
let userConfig = null;
|
|
10
11
|
try {
|
|
11
12
|
userConfig = await loadDyrectedConfig(configPath);
|
|
@@ -30,6 +31,7 @@ export default defineNitroPlugin(async (nitroApp) => {
|
|
|
30
31
|
const newConfig = await loadDyrectedConfig(configPath);
|
|
31
32
|
const newObj = newConfig.default && (newConfig.default.collections || newConfig.default.globals || newConfig.default.db) ? newConfig.default : newConfig;
|
|
32
33
|
globalThis.__dyrected_config = newObj;
|
|
34
|
+
globalThis.__dyrected_config_version = (globalThis.__dyrected_config_version || 0) + 1;
|
|
33
35
|
if (newObj.db) {
|
|
34
36
|
globalThis.__dyrected_db = newObj.db;
|
|
35
37
|
console.log("[dyrected/nuxt] Database hot\u2011reloaded");
|
|
@@ -38,6 +40,7 @@ export default defineNitroPlugin(async (nitroApp) => {
|
|
|
38
40
|
globalThis.__dyrected_storage = newObj.storage;
|
|
39
41
|
console.log("[dyrected/nuxt] Storage hot\u2011reloaded");
|
|
40
42
|
}
|
|
43
|
+
console.log("[dyrected/nuxt] Configuration hot-reloaded (version " + globalThis.__dyrected_config_version + ")");
|
|
41
44
|
} catch (e) {
|
|
42
45
|
console.error("[dyrected/nuxt] Hot\u2011reload failed:", e);
|
|
43
46
|
}
|
|
@@ -4,6 +4,5 @@ export declare class ConfigLoadError extends Error {
|
|
|
4
4
|
/**
|
|
5
5
|
* Load a Dyrected configuration file.
|
|
6
6
|
* Supports .ts, .mjs, .cjs directly via jiti.
|
|
7
|
-
* For .js files it validates that no TypeScript‑only syntax is present.
|
|
8
7
|
*/
|
|
9
8
|
export declare function loadDyrectedConfig(configPath: string): Promise<any>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { promises as fs } from "fs";
|
|
3
2
|
export class ConfigLoadError extends Error {
|
|
4
3
|
constructor(message) {
|
|
5
4
|
super(message);
|
|
@@ -7,24 +6,33 @@ export class ConfigLoadError extends Error {
|
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
8
|
export async function loadDyrectedConfig(configPath) {
|
|
10
|
-
const ext = path.extname(configPath);
|
|
11
|
-
const raw = await fs.readFile(configPath, "utf-8");
|
|
12
|
-
if (ext === ".js" && /[!?:]/.test(raw)) {
|
|
13
|
-
throw new ConfigLoadError(
|
|
14
|
-
`The file "${configPath}" is a .js file but contains TypeScript\u2011specific syntax. Rename it to .ts (or .mjs/.cjs) or remove the TypeScript tokens.`
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
9
|
const jitiMod = await import("jiti");
|
|
18
|
-
|
|
10
|
+
const resolvedPath = path.resolve(configPath);
|
|
19
11
|
if (typeof jitiMod.createJiti === "function") {
|
|
20
12
|
const jitiInstance = jitiMod.createJiti(import.meta.url, {
|
|
21
13
|
esmResolve: true,
|
|
22
14
|
interopDefault: true
|
|
23
15
|
});
|
|
24
|
-
|
|
16
|
+
if (jitiInstance.cache) {
|
|
17
|
+
delete jitiInstance.cache[resolvedPath];
|
|
18
|
+
for (const k of Object.keys(jitiInstance.cache)) {
|
|
19
|
+
if (path.resolve(k) === resolvedPath) {
|
|
20
|
+
delete jitiInstance.cache[k];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return await jitiInstance.import(configPath);
|
|
25
25
|
} else {
|
|
26
26
|
const jitiDefault = jitiMod.default || jitiMod;
|
|
27
|
-
loader =
|
|
27
|
+
const loader = jitiDefault(import.meta.url, { esmResolve: true, interopDefault: true });
|
|
28
|
+
if (loader.cache) {
|
|
29
|
+
delete loader.cache[resolvedPath];
|
|
30
|
+
for (const k of Object.keys(loader.cache)) {
|
|
31
|
+
if (path.resolve(k) === resolvedPath) {
|
|
32
|
+
delete loader.cache[k];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return loader(configPath);
|
|
28
37
|
}
|
|
29
|
-
return await loader(configPath);
|
|
30
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dyrected/nuxt",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/module.mjs",
|
|
6
6
|
"types": "./dist/module.d.ts",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@nuxt/kit": "^3.11.2",
|
|
12
12
|
"h3": "^1.15.0",
|
|
13
|
-
"@dyrected/admin": "2.5.
|
|
14
|
-
"@dyrected/sdk": "2.5.
|
|
15
|
-
"@dyrected/core": "2.5.
|
|
16
|
-
"@dyrected/vue": "2.5.
|
|
13
|
+
"@dyrected/admin": "2.5.14",
|
|
14
|
+
"@dyrected/sdk": "2.5.14",
|
|
15
|
+
"@dyrected/core": "2.5.14",
|
|
16
|
+
"@dyrected/vue": "2.5.14"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"nuxt": "^3.0.0",
|