swytchcode 2.16.0 → 2.16.1
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/swytchcode.js +91 -26
- package/package.json +7 -7
package/bin/swytchcode.js
CHANGED
|
@@ -265,33 +265,98 @@ let binPath;
|
|
|
265
265
|
if (explicitBin) {
|
|
266
266
|
binPath = explicitBin;
|
|
267
267
|
} else {
|
|
268
|
-
const
|
|
269
|
-
'
|
|
270
|
-
'
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
268
|
+
const isNpxContext = (process.env.npm_command || '') === 'exec' ||
|
|
269
|
+
__filename.includes('_npx') ||
|
|
270
|
+
(process.env.npm_execpath || '').includes('npx');
|
|
271
|
+
|
|
272
|
+
if (isNpxContext) {
|
|
273
|
+
try {
|
|
274
|
+
const prefix = execSync('npm prefix -g', { stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8' }).trim();
|
|
275
|
+
if (prefix) {
|
|
276
|
+
const candidates = process.platform === 'win32'
|
|
277
|
+
? ['swytchcode.cmd', 'swytchcode.ps1', 'swytchcode'].map(n => path.join(prefix, n))
|
|
278
|
+
: [path.join(prefix, 'bin', 'swytchcode')];
|
|
279
|
+
const found = candidates.find(p => fs.existsSync(p));
|
|
280
|
+
if (found && !found.includes('_npx')) {
|
|
281
|
+
let localVersion = '0.0.0';
|
|
282
|
+
try { localVersion = require('../package.json').version || '0.0.0'; } catch (_) {}
|
|
283
|
+
|
|
284
|
+
let globalVersion = '0.0.0';
|
|
285
|
+
try {
|
|
286
|
+
const globalPkgPath = process.platform === 'win32'
|
|
287
|
+
? path.join(prefix, 'node_modules', 'swytchcode', 'package.json')
|
|
288
|
+
: path.join(prefix, 'lib', 'node_modules', 'swytchcode', 'package.json');
|
|
289
|
+
if (fs.existsSync(globalPkgPath)) {
|
|
290
|
+
globalVersion = JSON.parse(fs.readFileSync(globalPkgPath, 'utf8')).version || '0.0.0';
|
|
291
|
+
}
|
|
292
|
+
} catch (_) {}
|
|
293
|
+
|
|
294
|
+
const cmp = (a, b) => {
|
|
295
|
+
const pa = a.split('-'), pb = b.split('-');
|
|
296
|
+
const na = pa[0].split('.').map(Number), nb = pb[0].split('.').map(Number);
|
|
297
|
+
for (let i = 0; i < 3; i++) {
|
|
298
|
+
const x = na[i] || 0, y = nb[i] || 0;
|
|
299
|
+
if (x > y) return 1;
|
|
300
|
+
if (x < y) return -1;
|
|
301
|
+
}
|
|
302
|
+
if (!pa[1] && pb[1]) return 1;
|
|
303
|
+
if (pa[1] && !pb[1]) return -1;
|
|
304
|
+
if (!pa[1] && !pb[1]) return 0;
|
|
305
|
+
const ra = pa[1].split('.'), rb = pb[1].split('.');
|
|
306
|
+
for (let i = 0; i < Math.max(ra.length, rb.length); i++) {
|
|
307
|
+
if (i >= ra.length) return -1;
|
|
308
|
+
if (i >= rb.length) return 1;
|
|
309
|
+
const nx = Number(ra[i]), ny = Number(rb[i]);
|
|
310
|
+
const xIsNum = !isNaN(nx), yIsNum = !isNaN(ny);
|
|
311
|
+
if (xIsNum && !yIsNum) return -1;
|
|
312
|
+
if (!xIsNum && yIsNum) return 1;
|
|
313
|
+
if (xIsNum && yIsNum) {
|
|
314
|
+
if (nx !== ny) return nx > ny ? 1 : -1;
|
|
315
|
+
} else if (ra[i] !== rb[i]) {
|
|
316
|
+
return ra[i] > rb[i] ? 1 : -1;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return 0;
|
|
320
|
+
};
|
|
321
|
+
const globalIsNewer = cmp(globalVersion, localVersion) > 0;
|
|
322
|
+
|
|
323
|
+
if (globalIsNewer) {
|
|
324
|
+
binPath = found;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
} catch (_) {}
|
|
285
329
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
330
|
+
|
|
331
|
+
if (!binPath) {
|
|
332
|
+
const PLATFORM_PACKAGES = {
|
|
333
|
+
'darwin-arm64': 'swytchcode-cli-darwin-arm64',
|
|
334
|
+
'darwin-x64': 'swytchcode-cli-darwin-x64',
|
|
335
|
+
'linux-arm64': 'swytchcode-cli-linux-arm64',
|
|
336
|
+
'linux-x64': 'swytchcode-cli-linux-x64',
|
|
337
|
+
'win32-arm64': 'swytchcode-cli-win32-arm64',
|
|
338
|
+
'win32-x64': 'swytchcode-cli-win32-x64',
|
|
339
|
+
};
|
|
340
|
+
const key = `${process.platform}-${process.arch}`;
|
|
341
|
+
const pkg = PLATFORM_PACKAGES[key];
|
|
342
|
+
if (!pkg) {
|
|
343
|
+
err(
|
|
344
|
+
`swytchcode: unsupported platform "${key}".\n` +
|
|
345
|
+
`Supported: ${Object.keys(PLATFORM_PACKAGES).join(', ')}\n` +
|
|
346
|
+
`Install via curl instead: https://cli.swytchcode.com`
|
|
347
|
+
);
|
|
348
|
+
process.exit(1);
|
|
349
|
+
}
|
|
350
|
+
const binName = process.platform === 'win32' ? 'swytchcode.exe' : 'swytchcode';
|
|
351
|
+
try {
|
|
352
|
+
binPath = require.resolve(`${pkg}/bin/${binName}`);
|
|
353
|
+
} catch (_) {
|
|
354
|
+
err(
|
|
355
|
+
`swytchcode: could not find the binary for "${key}".\n` +
|
|
356
|
+
`Try reinstalling: npm install -g swytchcode`
|
|
357
|
+
);
|
|
358
|
+
process.exit(1);
|
|
359
|
+
}
|
|
295
360
|
}
|
|
296
361
|
}
|
|
297
362
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swytchcode",
|
|
3
|
-
"version": "2.16.
|
|
3
|
+
"version": "2.16.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://gitlab.com/swytchcode/cli.git"
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"README.md"
|
|
29
29
|
],
|
|
30
30
|
"optionalDependencies": {
|
|
31
|
-
"swytchcode-cli-darwin-arm64": "2.16.
|
|
32
|
-
"swytchcode-cli-darwin-x64": "2.16.
|
|
33
|
-
"swytchcode-cli-linux-arm64": "2.16.
|
|
34
|
-
"swytchcode-cli-linux-x64": "2.16.
|
|
35
|
-
"swytchcode-cli-win32-arm64": "2.16.
|
|
36
|
-
"swytchcode-cli-win32-x64": "2.16.
|
|
31
|
+
"swytchcode-cli-darwin-arm64": "2.16.1",
|
|
32
|
+
"swytchcode-cli-darwin-x64": "2.16.1",
|
|
33
|
+
"swytchcode-cli-linux-arm64": "2.16.1",
|
|
34
|
+
"swytchcode-cli-linux-x64": "2.16.1",
|
|
35
|
+
"swytchcode-cli-win32-arm64": "2.16.1",
|
|
36
|
+
"swytchcode-cli-win32-x64": "2.16.1"
|
|
37
37
|
}
|
|
38
38
|
}
|