@vitnode/core 1.2.0-canary.68 → 1.2.0-canary.70

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.
@@ -1 +1 @@
1
- {"version":3,"file":"get-config.d.ts","sourceRoot":"","sources":["../../scripts/get-config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEhF,KAAK,UAAU,CAAC,CAAC,SAAS,YAAY,GAAG,QAAQ,IAAI,CAAC,SAAS,QAAQ,GACnE,aAAa,GACb,gBAAgB,CAAC;AAErB,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,YAAY,GAAG,QAAQ,EAAE,WAEhE;IACD,IAAI,CAAC,EAAE,CAAC,CAAC;CACV,KAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAaxB,CAAC"}
1
+ {"version":3,"file":"get-config.d.ts","sourceRoot":"","sources":["../../scripts/get-config.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEhF,KAAK,UAAU,CAAC,CAAC,SAAS,YAAY,GAAG,QAAQ,IAAI,CAAC,SAAS,QAAQ,GACnE,aAAa,GACb,gBAAgB,CAAC;AAoDrB,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,YAAY,GAAG,QAAQ,EAAE,WAEhE;IACD,IAAI,CAAC,EAAE,CAAC,CAAC;CACV,KAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAoCxB,CAAC"}
@@ -1,11 +1,62 @@
1
+ import { createJiti } from "jiti";
2
+ import { existsSync, readdirSync, statSync } from "node:fs";
1
3
  import { join } from "node:path";
2
- import { pathToFileURL } from "node:url";
4
+ const findConfigFile = (baseDir, filename, maxDepth = 4) => {
5
+ const searchRecursively = (dir, depth) => {
6
+ if (depth > maxDepth)
7
+ return null;
8
+ try {
9
+ const configPath = join(dir, "src", filename);
10
+ if (existsSync(configPath)) {
11
+ return configPath;
12
+ }
13
+ const items = readdirSync(dir);
14
+ for (const item of items) {
15
+ if (item === "node_modules" ||
16
+ item.startsWith(".") ||
17
+ item === "dist" ||
18
+ item === "build" ||
19
+ item === "out") {
20
+ continue;
21
+ }
22
+ const itemPath = join(dir, item);
23
+ try {
24
+ if (statSync(itemPath).isDirectory()) {
25
+ const found = searchRecursively(itemPath, depth + 1);
26
+ if (found)
27
+ return found;
28
+ }
29
+ }
30
+ catch {
31
+ }
32
+ }
33
+ }
34
+ catch {
35
+ }
36
+ return null;
37
+ };
38
+ return searchRecursively(baseDir, 0);
39
+ };
3
40
  export const getConfig = async ({ type = "config", }) => {
4
- const configPath = join(process.cwd(), "src", `vitnode.${type}.ts`);
41
+ const cwd = process.cwd();
42
+ const filename = `vitnode.${type}.ts`;
43
+ const configPath = findConfigFile(cwd, filename);
44
+ if (!configPath) {
45
+ console.error(`Config file not found: ${filename}`);
46
+ console.error(`Searched recursively in ${cwd} (excluding node_modules, .*, dist, build, out)`);
47
+ process.exit(1);
48
+ }
5
49
  try {
6
- const configUrl = pathToFileURL(configPath).href;
7
- const loaded = await import(configUrl);
8
- const config = type === "config" ? loaded.vitNodeConfig : loaded.vitNodeApiConfig;
50
+ const configVarName = type === "config" ? "vitNodeConfig" : "vitNodeApiConfig";
51
+ const jiti = createJiti(import.meta.url, {
52
+ interopDefault: true,
53
+ });
54
+ const loaded = (await jiti.import(configPath));
55
+ const config = loaded[configVarName];
56
+ if (!config) {
57
+ console.error(`Export "${configVarName}" not found in ${configPath}`);
58
+ process.exit(1);
59
+ }
9
60
  return config;
10
61
  }
11
62
  catch (error) {