pnpm
Version:
A fast implementation of npm install
45 lines • 1.86 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
const fs = require('mz/fs');
const path = require('path');
const flatten = require('arr-flatten');
function default_1(modules) {
return __awaiter(this, void 0, void 0, function* () {
const dirs = yield getDirectories(modules);
const subdirs = yield Promise.all(dirs.map((dir) => {
return isScopedPkgsDir(dir) ? getDirectories(dir) : Promise.resolve([dir]);
}));
return flatten(subdirs);
});
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
function getDirectories(srcPath) {
return __awaiter(this, void 0, void 0, function* () {
let dirs;
try {
dirs = yield fs.readdir(srcPath);
}
catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
dirs = [];
}
return dirs
.filter(relativePath => relativePath[0] !== '.') // ignore directories like .bin, .store, etc
.map(relativePath => path.join(srcPath, relativePath))
.filter(absolutePath => fs.statSync(absolutePath).isDirectory());
});
}
function isScopedPkgsDir(dirPath) {
return path.basename(dirPath)[0] === '@';
}
//# sourceMappingURL=getPkgDirs.js.map