@nocobase/cli 2.1.11-test.6 → 2.1.11-test.8

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.
@@ -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 (options.pnpmGlobalRoot && isSubPath(options.pnpmGlobalRoot, packageRoot)) {
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,71 @@ 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
+ }
155
+ function isPnpmGlobalRootPath(pnpmGlobalRoot, packageRoot) {
156
+ if (isSubPath(pnpmGlobalRoot, packageRoot)) {
157
+ return true;
158
+ }
159
+ const normalizedGlobalRoot = normalizePath(pnpmGlobalRoot);
160
+ const globalNodeModulesDir = path.basename(normalizedGlobalRoot) === 'node_modules'
161
+ ? normalizedGlobalRoot
162
+ : path.join(normalizedGlobalRoot, 'node_modules');
163
+ const globalProjectDir = path.dirname(globalNodeModulesDir);
164
+ if (!isSubPath(globalProjectDir, packageRoot)) {
165
+ return false;
166
+ }
167
+ const segments = normalizePath(packageRoot).split(path.sep).filter(Boolean);
168
+ const pnpmStoreIndex = segments.indexOf('.pnpm');
169
+ if (pnpmStoreIndex === -1) {
170
+ return false;
171
+ }
172
+ return segments.slice(pnpmStoreIndex + 1).includes('node_modules');
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
+ }
139
209
  function readCurrentBinPath(currentBinPath) {
140
210
  const candidate = String(currentBinPath ?? process.argv[1] ?? '').trim();
141
211
  if (!candidate) {
@@ -251,6 +321,7 @@ export function getSelfUpdatePackageSpec(status) {
251
321
  }
252
322
  export async function inspectSelfInstall(options = {}) {
253
323
  const packageRoot = options.packageRoot ? normalizePath(options.packageRoot) : PACKAGE_ROOT;
324
+ const packageName = options.packageName ?? DEFAULT_PACKAGE_NAME;
254
325
  const commandOutputFn = options.commandOutputFn ?? commandOutput;
255
326
  const currentBinPath = readCurrentBinPath(options.currentBinPath);
256
327
  const globalPrefix = await readGlobalPrefix(commandOutputFn);
@@ -262,6 +333,7 @@ export async function inspectSelfInstall(options = {}) {
262
333
  packageRoot,
263
334
  currentBinPath,
264
335
  globalPrefix,
336
+ packageName,
265
337
  pnpmGlobalBin,
266
338
  pnpmGlobalRoot,
267
339
  yarnGlobalBin,
@@ -282,6 +354,8 @@ function detectInstallMethodFromSignals(options) {
282
354
  }
283
355
  return detectInstallMethod(options.packageRoot, {
284
356
  globalPrefix: options.globalPrefix,
357
+ packageName: options.packageName,
358
+ pnpmGlobalBin: options.pnpmGlobalBin,
285
359
  pnpmGlobalRoot: options.pnpmGlobalRoot,
286
360
  yarnGlobalDir: options.yarnGlobalDir,
287
361
  });
@@ -293,6 +367,7 @@ export async function inspectSelfStatus(options = {}) {
293
367
  const channel = options.channel && options.channel !== 'auto' ? options.channel : detectChannel(currentVersion);
294
368
  const commandOutputFn = options.commandOutputFn ?? commandOutput;
295
369
  const { installMethod, globalPrefix } = await inspectSelfInstall({
370
+ packageName,
296
371
  packageRoot,
297
372
  commandOutputFn,
298
373
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "2.1.11-test.6",
3
+ "version": "2.1.11-test.8",
4
4
  "description": "NocoBase Command Line Tool",
5
5
  "type": "module",
6
6
  "main": "dist/generated/command-registry.js",