kitstore-cli 1.0.96 → 1.0.97
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/config.js +28 -0
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -64,8 +64,34 @@ async function loadBundledDefaultConfig() {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
catch (err) {
|
|
67
|
+
// Strategy 1 failed, try Strategy 1.5
|
|
67
68
|
// Strategy 1 failed, try Strategy 2
|
|
68
69
|
}
|
|
70
|
+
// Strategy 1.5: Try to find package.json by walking up from __dirname
|
|
71
|
+
// This handles cases where require.resolve doesn't work in some npm/npx contexts
|
|
72
|
+
try {
|
|
73
|
+
let currentDir = path.dirname(__dirname); // Start from cli/dist/../ (cli/)
|
|
74
|
+
let attempts = 0;
|
|
75
|
+
while (currentDir !== path.dirname(currentDir) && attempts < 10) { // Avoid infinite loop
|
|
76
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
77
|
+
const defaultConfigPath = path.join(currentDir, 'default-config.json');
|
|
78
|
+
if (await fs.pathExists(packageJsonPath) && await fs.pathExists(defaultConfigPath)) {
|
|
79
|
+
const packageJson = await fs.readJson(packageJsonPath);
|
|
80
|
+
if (packageJson.name === 'kitstore-cli') {
|
|
81
|
+
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
82
|
+
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
83
|
+
return defaultConfig;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
currentDir = path.dirname(currentDir);
|
|
88
|
+
attempts++;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
// Strategy 1.5 failed, try Strategy 2
|
|
93
|
+
// Strategy 1.5 failed, continue to Strategy 2
|
|
94
|
+
}
|
|
69
95
|
// Strategy 2: Use __dirname relative path (works in development/local builds and many npm-installed layouts)
|
|
70
96
|
// - When running from source or local tarball, __dirname points to dist/ directory.
|
|
71
97
|
// - When running from npm-installed package, __dirname also typically points to dist/ directory.
|
|
@@ -81,6 +107,7 @@ async function loadBundledDefaultConfig() {
|
|
|
81
107
|
}
|
|
82
108
|
catch (err) {
|
|
83
109
|
// Strategy 2 failed, try Strategy 3
|
|
110
|
+
// Strategy 2 failed, try Strategy 3
|
|
84
111
|
}
|
|
85
112
|
// Strategy 3: Use require.resolve to find the compiled config module, then resolve config relative to it
|
|
86
113
|
// - This works when the package is installed via npm and we can resolve our own module entrypoint.
|
|
@@ -101,6 +128,7 @@ async function loadBundledDefaultConfig() {
|
|
|
101
128
|
}
|
|
102
129
|
catch (err) {
|
|
103
130
|
// Strategy 3 failed, try Strategy 4
|
|
131
|
+
// Strategy 3 failed, try Strategy 4
|
|
104
132
|
}
|
|
105
133
|
// Strategy 4: Try to find default-config.json in process.cwd()/node_modules/kitstore-cli/
|
|
106
134
|
// This works when running from a project that has kitstore-cli installed locally
|