npm-link-up
Version:
Use this package to link your projects together for local development.
51 lines (50 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const cp = require("child_process");
const path = require("path");
exports.mapPaths = (searchRoots, dirname, cb) => {
const mappedRoots = searchRoots
.map(v => String(v || '').trim())
.filter(Boolean)
.map(function (v) {
return `echo "${v}"`;
});
const k = cp.spawn('bash', [], {
env: Object.assign({}, process.env, {
NPM_LINK_UP: 'yes'
})
});
k.stdin.end(mappedRoots.join(';'));
const results = [];
k.stdout.setEncoding('utf8');
k.stderr.setEncoding('utf8');
k.stderr.pipe(process.stderr);
k.stdout.on('data', d => {
String(d || '').split('\n')
.map(v => String(v || '').trim())
.filter(Boolean).forEach(v => {
results.push(v);
});
});
k.once('error', e => {
cb(e || new Error('Missing error - error was mia.'));
});
k.once('exit', code => {
if (code > 0) {
return cb({ code: code });
}
const pths = [];
results.map(d => String(d || '').trim())
.filter(Boolean)
.sort((a, b) => (a.length - b.length))
.forEach(v => {
const s = !pths.some(p => {
return p.startsWith(v + '/');
});
if (s) {
pths.push(v);
}
});
cb(null, pths.map(p => path.isAbsolute(p) ? p : path.resolve(dirname + '/' + p)));
});
};