@nocobase/cli 2.1.11-test.5 → 2.1.11-test.7
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/lib/self-manager.js +60 -6
- package/package.json +1 -1
package/dist/lib/self-manager.js
CHANGED
|
@@ -116,6 +116,9 @@ function detectInstallMethod(packageRoot, options = {}) {
|
|
|
116
116
|
if (options.yarnGlobalDir && isSubPath(options.yarnGlobalDir, packageRoot)) {
|
|
117
117
|
return 'yarn-global';
|
|
118
118
|
}
|
|
119
|
+
if (options.pnpmGlobalRoot && isPnpmGlobalRootPath(options.pnpmGlobalRoot, packageRoot)) {
|
|
120
|
+
return 'pnpm-global';
|
|
121
|
+
}
|
|
119
122
|
if (isPnpmGlobalPath(packageRoot)) {
|
|
120
123
|
return 'pnpm-global';
|
|
121
124
|
}
|
|
@@ -133,6 +136,25 @@ function isPnpmGlobalPath(packageRoot) {
|
|
|
133
136
|
}
|
|
134
137
|
return segments.slice(globalIndex + 2).includes('node_modules');
|
|
135
138
|
}
|
|
139
|
+
function isPnpmGlobalRootPath(pnpmGlobalRoot, packageRoot) {
|
|
140
|
+
if (isSubPath(pnpmGlobalRoot, packageRoot)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
const normalizedGlobalRoot = normalizePath(pnpmGlobalRoot);
|
|
144
|
+
const globalNodeModulesDir = path.basename(normalizedGlobalRoot) === 'node_modules'
|
|
145
|
+
? normalizedGlobalRoot
|
|
146
|
+
: path.join(normalizedGlobalRoot, 'node_modules');
|
|
147
|
+
const globalProjectDir = path.dirname(globalNodeModulesDir);
|
|
148
|
+
if (!isSubPath(globalProjectDir, packageRoot)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const segments = normalizePath(packageRoot).split(path.sep).filter(Boolean);
|
|
152
|
+
const pnpmStoreIndex = segments.indexOf('.pnpm');
|
|
153
|
+
if (pnpmStoreIndex === -1) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return segments.slice(pnpmStoreIndex + 1).includes('node_modules');
|
|
157
|
+
}
|
|
136
158
|
function readCurrentBinPath(currentBinPath) {
|
|
137
159
|
const candidate = String(currentBinPath ?? process.argv[1] ?? '').trim();
|
|
138
160
|
if (!candidate) {
|
|
@@ -140,11 +162,35 @@ function readCurrentBinPath(currentBinPath) {
|
|
|
140
162
|
}
|
|
141
163
|
return normalizePath(candidate);
|
|
142
164
|
}
|
|
165
|
+
function cleanCommandPath(value) {
|
|
166
|
+
const trimmed = value.trim();
|
|
167
|
+
return trimmed ? trimmed : undefined;
|
|
168
|
+
}
|
|
143
169
|
async function readGlobalPrefix(commandOutputFn) {
|
|
144
170
|
try {
|
|
145
|
-
return (await commandOutputFn('npm', ['prefix', '-g'], {
|
|
171
|
+
return cleanCommandPath(await commandOutputFn('npm', ['prefix', '-g'], {
|
|
146
172
|
errorName: 'npm prefix',
|
|
147
|
-
}))
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function readPnpmGlobalBin(commandOutputFn) {
|
|
180
|
+
try {
|
|
181
|
+
return cleanCommandPath(await commandOutputFn('pnpm', ['bin', '-g'], {
|
|
182
|
+
errorName: 'pnpm bin',
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async function readPnpmGlobalRoot(commandOutputFn) {
|
|
190
|
+
try {
|
|
191
|
+
return cleanCommandPath(await commandOutputFn('pnpm', ['root', '-g'], {
|
|
192
|
+
errorName: 'pnpm root',
|
|
193
|
+
}));
|
|
148
194
|
}
|
|
149
195
|
catch {
|
|
150
196
|
return undefined;
|
|
@@ -152,9 +198,9 @@ async function readGlobalPrefix(commandOutputFn) {
|
|
|
152
198
|
}
|
|
153
199
|
async function readYarnGlobalDir(commandOutputFn) {
|
|
154
200
|
try {
|
|
155
|
-
return (await commandOutputFn('yarn', ['global', 'dir'], {
|
|
201
|
+
return cleanCommandPath(await commandOutputFn('yarn', ['global', 'dir'], {
|
|
156
202
|
errorName: 'yarn global dir',
|
|
157
|
-
}))
|
|
203
|
+
}));
|
|
158
204
|
}
|
|
159
205
|
catch {
|
|
160
206
|
return undefined;
|
|
@@ -162,9 +208,9 @@ async function readYarnGlobalDir(commandOutputFn) {
|
|
|
162
208
|
}
|
|
163
209
|
async function readYarnGlobalBin(commandOutputFn) {
|
|
164
210
|
try {
|
|
165
|
-
return (await commandOutputFn('yarn', ['global', 'bin'], {
|
|
211
|
+
return cleanCommandPath(await commandOutputFn('yarn', ['global', 'bin'], {
|
|
166
212
|
errorName: 'yarn global bin',
|
|
167
|
-
}))
|
|
213
|
+
}));
|
|
168
214
|
}
|
|
169
215
|
catch {
|
|
170
216
|
return undefined;
|
|
@@ -227,12 +273,16 @@ export async function inspectSelfInstall(options = {}) {
|
|
|
227
273
|
const commandOutputFn = options.commandOutputFn ?? commandOutput;
|
|
228
274
|
const currentBinPath = readCurrentBinPath(options.currentBinPath);
|
|
229
275
|
const globalPrefix = await readGlobalPrefix(commandOutputFn);
|
|
276
|
+
const pnpmGlobalBin = await readPnpmGlobalBin(commandOutputFn);
|
|
277
|
+
const pnpmGlobalRoot = await readPnpmGlobalRoot(commandOutputFn);
|
|
230
278
|
const yarnGlobalDir = await readYarnGlobalDir(commandOutputFn);
|
|
231
279
|
const yarnGlobalBin = await readYarnGlobalBin(commandOutputFn);
|
|
232
280
|
const installMethod = detectInstallMethodFromSignals({
|
|
233
281
|
packageRoot,
|
|
234
282
|
currentBinPath,
|
|
235
283
|
globalPrefix,
|
|
284
|
+
pnpmGlobalBin,
|
|
285
|
+
pnpmGlobalRoot,
|
|
236
286
|
yarnGlobalBin,
|
|
237
287
|
yarnGlobalDir,
|
|
238
288
|
});
|
|
@@ -246,8 +296,12 @@ function detectInstallMethodFromSignals(options) {
|
|
|
246
296
|
if (options.currentBinPath && options.yarnGlobalBin && isSubPath(options.yarnGlobalBin, options.currentBinPath)) {
|
|
247
297
|
return 'yarn-global';
|
|
248
298
|
}
|
|
299
|
+
if (options.currentBinPath && options.pnpmGlobalBin && isSubPath(options.pnpmGlobalBin, options.currentBinPath)) {
|
|
300
|
+
return 'pnpm-global';
|
|
301
|
+
}
|
|
249
302
|
return detectInstallMethod(options.packageRoot, {
|
|
250
303
|
globalPrefix: options.globalPrefix,
|
|
304
|
+
pnpmGlobalRoot: options.pnpmGlobalRoot,
|
|
251
305
|
yarnGlobalDir: options.yarnGlobalDir,
|
|
252
306
|
});
|
|
253
307
|
}
|