@dyrected/nuxt 2.5.11 → 2.5.13

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@dyrected/nuxt",
3
3
  "configKey": "dyrected",
4
- "version": "2.5.10"
4
+ "version": "2.5.12"
5
5
  }
@@ -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
- if (!app) {
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,5 +1,6 @@
1
1
  import { defineNitroPlugin } from "nitropack/runtime";
2
2
  import { useRuntimeConfig } from "#imports";
3
+ import { loadDyrectedConfig, ConfigLoadError } from "./loadConfig.mjs";
3
4
  export default defineNitroPlugin(async (nitroApp) => {
4
5
  const runtimeConfig = useRuntimeConfig().dyrected;
5
6
  if (runtimeConfig?.configPath) {
@@ -7,20 +8,49 @@ export default defineNitroPlugin(async (nitroApp) => {
7
8
  const configPath = runtimeConfig.configPath;
8
9
  let userConfig = null;
9
10
  try {
10
- const { default: jiti } = await import("jiti");
11
- const loader = jiti(import.meta.url, { esmResolve: true, interopDefault: true });
12
- userConfig = loader(configPath);
11
+ userConfig = await loadDyrectedConfig(configPath);
13
12
  } catch (err) {
13
+ if (err instanceof ConfigLoadError) {
14
+ console.error("[dyrected/nuxt] Config load error:", err.message);
15
+ throw err;
16
+ }
17
+ console.warn("[dyrected/nuxt] Failed to load config via loadDyrectedConfig, falling back to native import.");
14
18
  const { pathToFileURL } = await import("url");
15
19
  const imported = await import(pathToFileURL(configPath).href);
16
20
  userConfig = imported.default || imported;
17
21
  }
18
22
  if (userConfig) {
19
- console.log("[dyrected/nuxt] plugin raw userConfig keys:", Object.keys(userConfig || {}));
20
- console.log("[dyrected/nuxt] plugin raw userConfig default keys:", Object.keys(userConfig?.default || {}));
21
23
  const configObj = userConfig.default && (userConfig.default.collections || userConfig.default.globals || userConfig.default.db) ? userConfig.default : userConfig;
22
- console.log("[dyrected/nuxt] plugin chosen configObj keys:", Object.keys(configObj || {}));
23
24
  globalThis.__dyrected_config = configObj;
25
+ if (process.env.NODE_ENV !== "production") {
26
+ const { watch } = await import("fs");
27
+ let debounceTimer = null;
28
+ const reload = async () => {
29
+ try {
30
+ const newConfig = await loadDyrectedConfig(configPath);
31
+ const newObj = newConfig.default && (newConfig.default.collections || newConfig.default.globals || newConfig.default.db) ? newConfig.default : newConfig;
32
+ globalThis.__dyrected_config = newObj;
33
+ globalThis.__dyrected_config_version = (globalThis.__dyrected_config_version || 0) + 1;
34
+ if (newObj.db) {
35
+ globalThis.__dyrected_db = newObj.db;
36
+ console.log("[dyrected/nuxt] Database hot\u2011reloaded");
37
+ }
38
+ if (newObj.storage) {
39
+ globalThis.__dyrected_storage = newObj.storage;
40
+ console.log("[dyrected/nuxt] Storage hot\u2011reloaded");
41
+ }
42
+ console.log("[dyrected/nuxt] Configuration hot-reloaded (version " + globalThis.__dyrected_config_version + ")");
43
+ } catch (e) {
44
+ console.error("[dyrected/nuxt] Hot\u2011reload failed:", e);
45
+ }
46
+ };
47
+ watch(configPath, (eventType) => {
48
+ if (eventType === "change") {
49
+ if (debounceTimer) clearTimeout(debounceTimer);
50
+ debounceTimer = setTimeout(reload, 200);
51
+ }
52
+ });
53
+ }
24
54
  if (configObj.db) {
25
55
  globalThis.__dyrected_db = configObj.db;
26
56
  console.log("[dyrected/nuxt] Database re-attached to global context");
@@ -0,0 +1,9 @@
1
+ export declare class ConfigLoadError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ /**
5
+ * Load a Dyrected configuration file.
6
+ * Supports .ts, .mjs, .cjs directly via jiti.
7
+ * For .js files it validates that no TypeScript‑only syntax is present.
8
+ */
9
+ export declare function loadDyrectedConfig(configPath: string): Promise<any>;
@@ -0,0 +1,46 @@
1
+ import path from "path";
2
+ import { promises as fs } from "fs";
3
+ export class ConfigLoadError extends Error {
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = "ConfigLoadError";
7
+ }
8
+ }
9
+ 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
+ const jitiMod = await import("jiti");
18
+ const resolvedPath = path.resolve(configPath);
19
+ if (typeof jitiMod.createJiti === "function") {
20
+ const jitiInstance = jitiMod.createJiti(import.meta.url, {
21
+ esmResolve: true,
22
+ interopDefault: true
23
+ });
24
+ if (jitiInstance.cache) {
25
+ delete jitiInstance.cache[resolvedPath];
26
+ for (const k of Object.keys(jitiInstance.cache)) {
27
+ if (path.resolve(k) === resolvedPath) {
28
+ delete jitiInstance.cache[k];
29
+ }
30
+ }
31
+ }
32
+ return await jitiInstance.import(configPath);
33
+ } else {
34
+ const jitiDefault = jitiMod.default || jitiMod;
35
+ const loader = jitiDefault(import.meta.url, { esmResolve: true, interopDefault: true });
36
+ if (loader.cache) {
37
+ delete loader.cache[resolvedPath];
38
+ for (const k of Object.keys(loader.cache)) {
39
+ if (path.resolve(k) === resolvedPath) {
40
+ delete loader.cache[k];
41
+ }
42
+ }
43
+ }
44
+ return loader(configPath);
45
+ }
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dyrected/nuxt",
3
- "version": "2.5.11",
3
+ "version": "2.5.13",
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/core": "2.5.11",
14
- "@dyrected/sdk": "2.5.11",
15
- "@dyrected/vue": "2.5.11",
16
- "@dyrected/admin": "2.5.11"
13
+ "@dyrected/core": "2.5.13",
14
+ "@dyrected/sdk": "2.5.13",
15
+ "@dyrected/vue": "2.5.13",
16
+ "@dyrected/admin": "2.5.13"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "nuxt": "^3.0.0",