@nocobase/cli 2.1.11-test.7 → 2.1.11-test.9
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 +57 -1
- package/package.json +1 -1
package/dist/lib/self-manager.js
CHANGED
|
@@ -116,7 +116,12 @@ function detectInstallMethod(packageRoot, options = {}) {
|
|
|
116
116
|
if (options.yarnGlobalDir && isSubPath(options.yarnGlobalDir, packageRoot)) {
|
|
117
117
|
return 'yarn-global';
|
|
118
118
|
}
|
|
119
|
-
if (
|
|
119
|
+
if (isPnpmGlobalInstallPath({
|
|
120
|
+
packageName: options.packageName ?? DEFAULT_PACKAGE_NAME,
|
|
121
|
+
packageRoot,
|
|
122
|
+
pnpmGlobalBin: options.pnpmGlobalBin,
|
|
123
|
+
pnpmGlobalRoot: options.pnpmGlobalRoot,
|
|
124
|
+
})) {
|
|
120
125
|
return 'pnpm-global';
|
|
121
126
|
}
|
|
122
127
|
if (isPnpmGlobalPath(packageRoot)) {
|
|
@@ -136,6 +141,17 @@ function isPnpmGlobalPath(packageRoot) {
|
|
|
136
141
|
}
|
|
137
142
|
return segments.slice(globalIndex + 2).includes('node_modules');
|
|
138
143
|
}
|
|
144
|
+
function packageNameToPath(packageName) {
|
|
145
|
+
return packageName.split('/').filter(Boolean);
|
|
146
|
+
}
|
|
147
|
+
function isSameRealPath(left, right) {
|
|
148
|
+
try {
|
|
149
|
+
return normalizePath(fs.realpathSync(left)) === normalizePath(fs.realpathSync(right));
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
139
155
|
function isPnpmGlobalRootPath(pnpmGlobalRoot, packageRoot) {
|
|
140
156
|
if (isSubPath(pnpmGlobalRoot, packageRoot)) {
|
|
141
157
|
return true;
|
|
@@ -155,6 +171,41 @@ function isPnpmGlobalRootPath(pnpmGlobalRoot, packageRoot) {
|
|
|
155
171
|
}
|
|
156
172
|
return segments.slice(pnpmStoreIndex + 1).includes('node_modules');
|
|
157
173
|
}
|
|
174
|
+
function isPnpmGlobalPackagePath(pnpmGlobalRoot, packageRoot, packageName) {
|
|
175
|
+
return isSameRealPath(path.join(pnpmGlobalRoot, ...packageNameToPath(packageName)), packageRoot);
|
|
176
|
+
}
|
|
177
|
+
function isPnpmGlobalBinProjectPath(pnpmGlobalBin, packageRoot, packageName) {
|
|
178
|
+
const pnpmHome = path.dirname(normalizePath(pnpmGlobalBin));
|
|
179
|
+
const globalDir = path.join(pnpmHome, 'global');
|
|
180
|
+
if (isSubPath(globalDir, packageRoot)) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
let entries;
|
|
184
|
+
try {
|
|
185
|
+
entries = fs.readdirSync(globalDir);
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return entries.some((entry) => {
|
|
191
|
+
const pnpmGlobalRoot = path.join(globalDir, entry, 'node_modules');
|
|
192
|
+
return isPnpmGlobalRootPath(pnpmGlobalRoot, packageRoot)
|
|
193
|
+
|| isPnpmGlobalPackagePath(pnpmGlobalRoot, packageRoot, packageName);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function isPnpmGlobalInstallPath(options) {
|
|
197
|
+
if (options.pnpmGlobalRoot) {
|
|
198
|
+
const matchedRoot = isPnpmGlobalRootPath(options.pnpmGlobalRoot, options.packageRoot)
|
|
199
|
+
|| isPnpmGlobalPackagePath(options.pnpmGlobalRoot, options.packageRoot, options.packageName);
|
|
200
|
+
if (matchedRoot) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (options.pnpmGlobalBin) {
|
|
205
|
+
return isPnpmGlobalBinProjectPath(options.pnpmGlobalBin, options.packageRoot, options.packageName);
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
158
209
|
function readCurrentBinPath(currentBinPath) {
|
|
159
210
|
const candidate = String(currentBinPath ?? process.argv[1] ?? '').trim();
|
|
160
211
|
if (!candidate) {
|
|
@@ -270,6 +321,7 @@ export function getSelfUpdatePackageSpec(status) {
|
|
|
270
321
|
}
|
|
271
322
|
export async function inspectSelfInstall(options = {}) {
|
|
272
323
|
const packageRoot = options.packageRoot ? normalizePath(options.packageRoot) : PACKAGE_ROOT;
|
|
324
|
+
const packageName = options.packageName ?? DEFAULT_PACKAGE_NAME;
|
|
273
325
|
const commandOutputFn = options.commandOutputFn ?? commandOutput;
|
|
274
326
|
const currentBinPath = readCurrentBinPath(options.currentBinPath);
|
|
275
327
|
const globalPrefix = await readGlobalPrefix(commandOutputFn);
|
|
@@ -281,6 +333,7 @@ export async function inspectSelfInstall(options = {}) {
|
|
|
281
333
|
packageRoot,
|
|
282
334
|
currentBinPath,
|
|
283
335
|
globalPrefix,
|
|
336
|
+
packageName,
|
|
284
337
|
pnpmGlobalBin,
|
|
285
338
|
pnpmGlobalRoot,
|
|
286
339
|
yarnGlobalBin,
|
|
@@ -301,6 +354,8 @@ function detectInstallMethodFromSignals(options) {
|
|
|
301
354
|
}
|
|
302
355
|
return detectInstallMethod(options.packageRoot, {
|
|
303
356
|
globalPrefix: options.globalPrefix,
|
|
357
|
+
packageName: options.packageName,
|
|
358
|
+
pnpmGlobalBin: options.pnpmGlobalBin,
|
|
304
359
|
pnpmGlobalRoot: options.pnpmGlobalRoot,
|
|
305
360
|
yarnGlobalDir: options.yarnGlobalDir,
|
|
306
361
|
});
|
|
@@ -312,6 +367,7 @@ export async function inspectSelfStatus(options = {}) {
|
|
|
312
367
|
const channel = options.channel && options.channel !== 'auto' ? options.channel : detectChannel(currentVersion);
|
|
313
368
|
const commandOutputFn = options.commandOutputFn ?? commandOutput;
|
|
314
369
|
const { installMethod, globalPrefix } = await inspectSelfInstall({
|
|
370
|
+
packageName,
|
|
315
371
|
packageRoot,
|
|
316
372
|
commandOutputFn,
|
|
317
373
|
});
|