kitstore-cli 1.0.91 → 1.0.93
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 +36 -17
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -47,37 +47,56 @@ const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
|
47
47
|
async function loadBundledDefaultConfig() {
|
|
48
48
|
try {
|
|
49
49
|
// Try multiple path resolution strategies to work in both development and npm-installed contexts
|
|
50
|
-
// Strategy 1: Use
|
|
51
|
-
//
|
|
50
|
+
// Strategy 1: Use __dirname relative path (works in development/local builds and npm-installed packages)
|
|
51
|
+
// When running from source or local tarball, __dirname points to dist/ directory
|
|
52
|
+
// When running from npm-installed package, __dirname also points to dist/ directory
|
|
53
|
+
// default-config.json is at package root, so go up one level from dist/
|
|
54
|
+
const defaultConfigPath = path.join(__dirname, '..', 'default-config.json');
|
|
55
|
+
if (await fs.pathExists(defaultConfigPath)) {
|
|
56
|
+
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
57
|
+
// Validate that defaultConfig has a server property
|
|
58
|
+
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
59
|
+
return defaultConfig;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Strategy 2: Try require.resolve for package.json first (works when package is in node_modules or npx cache)
|
|
63
|
+
// This is more reliable than resolving './config' because it finds the package root directly
|
|
52
64
|
try {
|
|
53
|
-
// Try to resolve the package.json from the installed package
|
|
54
|
-
// This will work when the package is installed via npm
|
|
55
65
|
const packageJsonPath = require.resolve('kitstore-cli/package.json');
|
|
56
66
|
const packageDir = path.dirname(packageJsonPath);
|
|
57
67
|
const defaultConfigPath = path.join(packageDir, 'default-config.json');
|
|
58
68
|
if (await fs.pathExists(defaultConfigPath)) {
|
|
59
69
|
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
60
|
-
// Validate that defaultConfig has a server property
|
|
61
70
|
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
62
71
|
return defaultConfig;
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
75
|
catch (err) {
|
|
67
|
-
// Strategy
|
|
76
|
+
// Strategy 2 failed, try Strategy 3
|
|
68
77
|
}
|
|
69
|
-
// Strategy
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
// Strategy 3: Use require.resolve to find the current module, then resolve config relative to it
|
|
79
|
+
// This works when the package is installed via npm and we can resolve our own module
|
|
80
|
+
try {
|
|
81
|
+
// Resolve the current module (config.js) to get its location
|
|
82
|
+
// Use the full path from the package to be more reliable
|
|
83
|
+
const currentModulePath = require.resolve('kitstore-cli/dist/config');
|
|
84
|
+
const currentModuleDir = path.dirname(currentModulePath);
|
|
85
|
+
// Go up to package root (from dist/ to package root)
|
|
86
|
+
const packageRoot = path.dirname(currentModuleDir);
|
|
87
|
+
const defaultConfigPath = path.join(packageRoot, 'default-config.json');
|
|
88
|
+
if (await fs.pathExists(defaultConfigPath)) {
|
|
89
|
+
const defaultConfig = await fs.readJson(defaultConfigPath);
|
|
90
|
+
if (defaultConfig && typeof defaultConfig === 'object' && defaultConfig.server) {
|
|
91
|
+
return defaultConfig;
|
|
92
|
+
}
|
|
77
93
|
}
|
|
78
94
|
}
|
|
79
|
-
|
|
80
|
-
|
|
95
|
+
catch (err) {
|
|
96
|
+
// Strategy 3 failed, try Strategy 4
|
|
97
|
+
}
|
|
98
|
+
// Strategy 4: Try to find default-config.json in process.cwd()/node_modules/kitstore-cli/
|
|
99
|
+
// This works when running from a project that has kitstore-cli installed locally
|
|
81
100
|
try {
|
|
82
101
|
const nodeModulesPath = path.join(process.cwd(), 'node_modules', 'kitstore-cli', 'default-config.json');
|
|
83
102
|
if (await fs.pathExists(nodeModulesPath)) {
|
|
@@ -88,7 +107,7 @@ async function loadBundledDefaultConfig() {
|
|
|
88
107
|
}
|
|
89
108
|
}
|
|
90
109
|
catch (err) {
|
|
91
|
-
// Strategy
|
|
110
|
+
// Strategy 4 failed, continue
|
|
92
111
|
}
|
|
93
112
|
}
|
|
94
113
|
catch (err) {
|