@nocobase/cli 2.1.11-test.1 → 2.1.11-test.3

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.
@@ -142,6 +142,13 @@ function getInstallMethodCacheFile() {
142
142
  function getInstallMethodCacheKey(packageRoot) {
143
143
  return normalizePath(path.join(packageRoot, 'bin', 'run.js'));
144
144
  }
145
+ function readCurrentBinPath(currentBinPath) {
146
+ const candidate = String(currentBinPath ?? process.argv[1] ?? '').trim();
147
+ if (!candidate) {
148
+ return undefined;
149
+ }
150
+ return normalizePath(candidate);
151
+ }
145
152
  async function readInstallMethodCache() {
146
153
  try {
147
154
  const raw = await fsp.readFile(getInstallMethodCacheFile(), 'utf8');
@@ -188,6 +195,16 @@ async function readYarnGlobalDir(commandOutputFn) {
188
195
  return undefined;
189
196
  }
190
197
  }
198
+ async function readYarnGlobalBin(commandOutputFn) {
199
+ try {
200
+ return (await commandOutputFn('yarn', ['global', 'bin'], {
201
+ errorName: 'yarn global bin',
202
+ })).trim();
203
+ }
204
+ catch {
205
+ return undefined;
206
+ }
207
+ }
191
208
  async function readDistTags(packageName, commandOutputFn) {
192
209
  const output = await commandOutputFn('npm', ['view', packageName, 'dist-tags', '--json'], {
193
210
  errorName: 'npm view',
@@ -244,17 +261,28 @@ export async function inspectSelfInstall(options = {}) {
244
261
  const packageRoot = options.packageRoot ? normalizePath(options.packageRoot) : PACKAGE_ROOT;
245
262
  const commandOutputFn = options.commandOutputFn ?? commandOutput;
246
263
  const cachedInstallMethod = await readCachedInstallMethod(packageRoot);
264
+ const currentBinPath = readCurrentBinPath(options.currentBinPath);
247
265
  const globalPrefix = cachedInstallMethod?.globalPrefix ?? await readGlobalPrefix(commandOutputFn);
248
266
  const yarnGlobalDir = cachedInstallMethod?.yarnGlobalDir ?? await readYarnGlobalDir(commandOutputFn);
249
- const installMethod = cachedInstallMethod?.installMethod
250
- ?? detectInstallMethod(packageRoot, {
251
- globalPrefix,
252
- yarnGlobalDir,
253
- });
254
- if (!cachedInstallMethod) {
267
+ const yarnGlobalBin = cachedInstallMethod?.yarnGlobalBin ?? await readYarnGlobalBin(commandOutputFn);
268
+ const detectedInstallMethod = detectInstallMethodFromSignals({
269
+ packageRoot,
270
+ currentBinPath,
271
+ globalPrefix,
272
+ yarnGlobalBin,
273
+ yarnGlobalDir,
274
+ });
275
+ const installMethod = cachedInstallMethod?.installMethod === detectedInstallMethod
276
+ ? cachedInstallMethod.installMethod
277
+ : detectedInstallMethod;
278
+ if (!cachedInstallMethod
279
+ || cachedInstallMethod.currentBinPath !== currentBinPath
280
+ || cachedInstallMethod.installMethod !== installMethod) {
255
281
  await writeCachedInstallMethod(packageRoot, {
256
282
  installMethod,
283
+ currentBinPath,
257
284
  globalPrefix,
285
+ yarnGlobalBin,
258
286
  yarnGlobalDir,
259
287
  });
260
288
  }
@@ -264,6 +292,15 @@ export async function inspectSelfInstall(options = {}) {
264
292
  globalPrefix,
265
293
  };
266
294
  }
295
+ function detectInstallMethodFromSignals(options) {
296
+ if (options.currentBinPath && options.yarnGlobalBin && isSubPath(options.yarnGlobalBin, options.currentBinPath)) {
297
+ return 'yarn-global';
298
+ }
299
+ return detectInstallMethod(options.packageRoot, {
300
+ globalPrefix: options.globalPrefix,
301
+ yarnGlobalDir: options.yarnGlobalDir,
302
+ });
303
+ }
267
304
  export async function inspectSelfStatus(options = {}) {
268
305
  const packageRoot = options.packageRoot ? normalizePath(options.packageRoot) : PACKAGE_ROOT;
269
306
  const packageName = options.packageName ?? DEFAULT_PACKAGE_NAME;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "2.1.11-test.1",
3
+ "version": "2.1.11-test.3",
4
4
  "description": "NocoBase Command Line Tool",
5
5
  "type": "module",
6
6
  "main": "dist/generated/command-registry.js",