install-module-linked
Version:
Installs and symlinks a module into node_modules
32 lines • 1.46 kB
JavaScript
;
var path = require('path');
var spawn = require('cross-spawn-cb');
var spawnOptions = require('node-version-utils').spawnOptions;
var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
var major = +process.versions.node.split('.')[0];
var execPath = null;
module.exports = function install(specifier, dest, callback) {
if (major > 0) return spawn('npm', [
'install',
specifier
], {
cwd: dest
}, callback);
if (!execPath) {
var satisfiesSemverSync = require('node-exec-path').satisfiesSemverSync;
execPath = satisfiesSemverSync('>0.12'); // must be more than node 0.12
if (!execPath) return callback(new Error('install-module-linked a version of node >0.12 to use npm install'));
}
try {
var installPath = isWindows ? path.join(execPath, '..') : path.join(execPath, '..', '..');
var options = spawnOptions(installPath, {
execPath: execPath,
callbacks: true
});
var res = require('function-exec-sync')(options, __filename, specifier, dest);
callback(null, res);
} catch (err) {
callback(err);
}
};
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }