@justprove/mobilevc 0.1.0 → 0.1.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/mobilevc.js +33 -2
- package/package.json +1 -1
package/bin/mobilevc.js
CHANGED
|
@@ -400,14 +400,45 @@ function resolveBinaryInfo(platformTarget) {
|
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
function resolveInstalledPackageRoot(packageName) {
|
|
403
|
+
const packageJsonSuffix = packageName.split('/').join(path.sep);
|
|
404
|
+
const candidatePackageJsonPaths = [
|
|
405
|
+
safeResolve(() => require.resolve(`${packageName}/package.json`)),
|
|
406
|
+
safeResolve(() => require.resolve(`${packageName}/package.json`, { paths: [__dirname, process.cwd()] })),
|
|
407
|
+
path.join(__dirname, '..', 'node_modules', packageJsonSuffix, 'package.json'),
|
|
408
|
+
path.join(__dirname, '..', '..', packageJsonSuffix, 'package.json'),
|
|
409
|
+
path.join(getGlobalNodeModulesRoot(), packageJsonSuffix, 'package.json'),
|
|
410
|
+
].filter(Boolean);
|
|
411
|
+
|
|
412
|
+
for (const packageJsonPath of candidatePackageJsonPaths) {
|
|
413
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
414
|
+
return path.dirname(packageJsonPath);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function safeResolve(fn) {
|
|
403
422
|
try {
|
|
404
|
-
|
|
405
|
-
return path.dirname(packageJsonPath);
|
|
423
|
+
return fn();
|
|
406
424
|
} catch (_) {
|
|
407
425
|
return null;
|
|
408
426
|
}
|
|
409
427
|
}
|
|
410
428
|
|
|
429
|
+
function getGlobalNodeModulesRoot() {
|
|
430
|
+
const npmRoot = spawnSync('npm', ['root', '-g'], { encoding: 'utf8' });
|
|
431
|
+
if (npmRoot.status === 0) {
|
|
432
|
+
return String(npmRoot.stdout || '').trim();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (process.platform === 'win32') {
|
|
436
|
+
return path.join(process.env.APPDATA || '', 'npm', 'node_modules');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return '/usr/local/lib/node_modules';
|
|
440
|
+
}
|
|
441
|
+
|
|
411
442
|
function getPlatformTarget() {
|
|
412
443
|
return `${process.platform}-${process.arch}`;
|
|
413
444
|
}
|