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