generator-mico-cli 0.1.8 → 0.1.10
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/bin/mico.js +43 -8
- package/package.json +1 -1
package/bin/mico.js
CHANGED
|
@@ -96,6 +96,45 @@ function askForUpdate(current, latest) {
|
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* 检测当前使用的包管理器
|
|
101
|
+
* 通过检查可执行文件的安装路径来判断
|
|
102
|
+
* @returns {'npm' | 'pnpm' | 'yarn'}
|
|
103
|
+
*/
|
|
104
|
+
function detectPackageManager() {
|
|
105
|
+
// 首先检查环境变量(通过包管理器脚本运行时有效)
|
|
106
|
+
const npmUserAgent = process.env.npm_config_user_agent || '';
|
|
107
|
+
if (npmUserAgent.includes('pnpm')) return 'pnpm';
|
|
108
|
+
if (npmUserAgent.includes('yarn')) return 'yarn';
|
|
109
|
+
|
|
110
|
+
// 检查当前脚本的安装路径
|
|
111
|
+
// pnpm 全局安装路径通常包含: pnpm, .local/share/pnpm, Library/pnpm
|
|
112
|
+
const scriptPath = process.argv[1] || '';
|
|
113
|
+
const scriptPathLower = scriptPath.toLowerCase();
|
|
114
|
+
if (
|
|
115
|
+
scriptPathLower.includes('pnpm') ||
|
|
116
|
+
scriptPathLower.includes('.local/share/pnpm') ||
|
|
117
|
+
scriptPathLower.includes('library/pnpm')
|
|
118
|
+
) {
|
|
119
|
+
return 'pnpm';
|
|
120
|
+
}
|
|
121
|
+
if (scriptPathLower.includes('yarn')) return 'yarn';
|
|
122
|
+
|
|
123
|
+
// 检查 rootDir 路径(当前包的安装位置)
|
|
124
|
+
const rootDirLower = rootDir.toLowerCase();
|
|
125
|
+
if (
|
|
126
|
+
rootDirLower.includes('pnpm') ||
|
|
127
|
+
rootDirLower.includes('.local/share/pnpm') ||
|
|
128
|
+
rootDirLower.includes('library/pnpm')
|
|
129
|
+
) {
|
|
130
|
+
return 'pnpm';
|
|
131
|
+
}
|
|
132
|
+
if (rootDirLower.includes('yarn')) return 'yarn';
|
|
133
|
+
|
|
134
|
+
// 默认使用 npm
|
|
135
|
+
return 'npm';
|
|
136
|
+
}
|
|
137
|
+
|
|
99
138
|
/**
|
|
100
139
|
* 执行更新
|
|
101
140
|
* @param {string} latestVersion - 要更新到的版本号
|
|
@@ -106,15 +145,9 @@ function performUpdate(latestVersion) {
|
|
|
106
145
|
console.log(' ⏳ Updating mico-cli...');
|
|
107
146
|
|
|
108
147
|
// 检测包管理器
|
|
109
|
-
const
|
|
110
|
-
let pm = 'npm';
|
|
111
|
-
if (npmUserAgent.includes('pnpm')) {
|
|
112
|
-
pm = 'pnpm';
|
|
113
|
-
} else if (npmUserAgent.includes('yarn')) {
|
|
114
|
-
pm = 'yarn';
|
|
115
|
-
}
|
|
148
|
+
const pm = detectPackageManager();
|
|
116
149
|
|
|
117
|
-
//
|
|
150
|
+
// 指定具体版本号,避免缓存问题
|
|
118
151
|
const packageSpec = latestVersion ? `${pkg.name}@${latestVersion}` : `${pkg.name}@latest`;
|
|
119
152
|
|
|
120
153
|
// 执行全局安装
|
|
@@ -124,6 +157,8 @@ function performUpdate(latestVersion) {
|
|
|
124
157
|
? ['global', 'add', packageSpec]
|
|
125
158
|
: ['install', '-g', packageSpec];
|
|
126
159
|
|
|
160
|
+
console.log(` Using ${pm} to install ${packageSpec}`);
|
|
161
|
+
|
|
127
162
|
const result = spawnSync(installCmd, installArgs, {
|
|
128
163
|
stdio: 'inherit',
|
|
129
164
|
shell: process.platform === 'win32'
|