@pnpm/link-bins
Advanced tools
Comparing version 3.0.3 to 4.0.0
"use strict"; | ||
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()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,38 +7,34 @@ const flatten = require("arr-flatten"); | ||
const path = require("path"); | ||
function default_1(modules, warn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const dirs = yield getDirectories(modules, warn); | ||
const subdirs = yield Promise.all(dirs.map((dir) => { | ||
return isScopedPkgsDir(dir) ? getDirectories(dir, warn) : Promise.resolve([dir]); | ||
})); | ||
return flatten(subdirs); | ||
}); | ||
async function default_1(modules, warn) { | ||
const dirs = await getDirectories(modules, warn); | ||
const subdirs = await Promise.all(dirs.map((dir) => { | ||
return isScopedPkgsDir(dir) ? getDirectories(dir, warn) : Promise.resolve([dir]); | ||
})); | ||
return flatten(subdirs); | ||
} | ||
exports.default = default_1; | ||
function getDirectories(srcPath, warn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let dirs; | ||
async function getDirectories(srcPath, warn) { | ||
let dirs; | ||
try { | ||
dirs = await fs.readdir(srcPath); | ||
} | ||
catch (err) { | ||
if (err.code !== 'ENOENT') { | ||
throw err; | ||
} | ||
dirs = []; | ||
} | ||
return pFilter(dirs | ||
.filter((relativePath) => relativePath[0] !== '.') // ignore directories like .bin, .store, etc | ||
.map((relativePath) => path.join(srcPath, relativePath)), async (absolutePath) => { | ||
try { | ||
dirs = yield fs.readdir(srcPath); | ||
const stats = await fs.stat(absolutePath); | ||
return stats.isDirectory(); | ||
} | ||
catch (err) { | ||
if (err.code !== 'ENOENT') { | ||
if (err.code !== 'ENOENT') | ||
throw err; | ||
} | ||
dirs = []; | ||
warn(`Cannot find file at ${absolutePath} although it was listed by readdir`); | ||
return false; | ||
} | ||
return pFilter(dirs | ||
.filter((relativePath) => relativePath[0] !== '.') // ignore directories like .bin, .store, etc | ||
.map((relativePath) => path.join(srcPath, relativePath)), (absolutePath) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const stats = yield fs.stat(absolutePath); | ||
return stats.isDirectory(); | ||
} | ||
catch (err) { | ||
if (err.code !== 'ENOENT') | ||
throw err; | ||
warn(`Cannot find file at ${absolutePath} although it was listed by readdir`); | ||
return false; | ||
} | ||
})); | ||
}); | ||
@@ -53,0 +41,0 @@ } |
134
lib/index.js
"use strict"; | ||
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()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -25,5 +17,5 @@ const package_bins_1 = require("@pnpm/package-bins"); | ||
const POWER_SHELL_IS_SUPPORTED = IS_WINDOWS; | ||
exports.default = (modules, binPath, opts) => __awaiter(this, void 0, void 0, function* () { | ||
const pkgDirs = yield getPkgDirs_1.default(modules, opts.warn); | ||
const allCmds = R.unnest((yield Promise.all(pkgDirs | ||
exports.default = async (modules, binPath, opts) => { | ||
const pkgDirs = await getPkgDirs_1.default(modules, opts.warn); | ||
const allCmds = R.unnest((await Promise.all(pkgDirs | ||
.map(normalizePath) | ||
@@ -33,80 +25,66 @@ .map((target) => getPackageBins(target, opts.warn)))) | ||
return linkBins(allCmds, binPath, opts); | ||
}); | ||
function linkBinsOfPackages(pkgs, binsTarget, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!pkgs.length) | ||
return; | ||
const allCmds = R.unnest((yield Promise.all(pkgs | ||
.map((pkg) => getPackageBinsFromPackageJson(pkg.manifest, pkg.location)))) | ||
.filter((cmds) => cmds.length)); | ||
return linkBins(allCmds, binsTarget, opts); | ||
}); | ||
}; | ||
async function linkBinsOfPackages(pkgs, binsTarget, opts) { | ||
if (!pkgs.length) | ||
return; | ||
const allCmds = R.unnest((await Promise.all(pkgs | ||
.map((pkg) => getPackageBinsFromPackageJson(pkg.manifest, pkg.location)))) | ||
.filter((cmds) => cmds.length)); | ||
return linkBins(allCmds, binsTarget, opts); | ||
} | ||
exports.linkBinsOfPackages = linkBinsOfPackages; | ||
function linkBins(allCmds, binPath, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!allCmds.length) | ||
async function linkBins(allCmds, binPath, opts) { | ||
if (!allCmds.length) | ||
return; | ||
await mkdirp(binPath); | ||
const [cmdsWithOwnName, cmdsWithOtherNames] = R.partition((cmd) => cmd.ownName, allCmds); | ||
await Promise.all(cmdsWithOwnName.map((cmd) => linkBin(cmd, binPath))); | ||
const usedNames = R.fromPairs(cmdsWithOwnName.map((cmd) => [cmd.name, cmd.name])); | ||
await Promise.all(cmdsWithOtherNames.map((cmd) => { | ||
if (usedNames[cmd.name]) { | ||
opts.warn(`Cannot link bin "${cmd.name}" of "${cmd.pkgName}" to "${binPath}". A package called "${usedNames[cmd.name]}" already has its bin linked.`); | ||
return; | ||
yield mkdirp(binPath); | ||
const [cmdsWithOwnName, cmdsWithOtherNames] = R.partition((cmd) => cmd.ownName, allCmds); | ||
yield Promise.all(cmdsWithOwnName.map((cmd) => linkBin(cmd, binPath))); | ||
const usedNames = R.fromPairs(cmdsWithOwnName.map((cmd) => [cmd.name, cmd.name])); | ||
yield Promise.all(cmdsWithOtherNames.map((cmd) => { | ||
if (usedNames[cmd.name]) { | ||
opts.warn(`Cannot link bin "${cmd.name}" of "${cmd.pkgName}" to "${binPath}". A package called "${usedNames[cmd.name]}" already has its bin linked.`); | ||
return; | ||
} | ||
usedNames[cmd.name] = cmd.pkgName; | ||
return linkBin(cmd, binPath); | ||
})); | ||
}); | ||
} | ||
function getPackageBins(target, warn) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const pkg = yield safeReadPkg(target); | ||
if (!pkg) { | ||
warn(`There's a directory in node_modules without package.json: ${target}`); | ||
return []; | ||
} | ||
return getPackageBinsFromPackageJson(pkg, target); | ||
}); | ||
usedNames[cmd.name] = cmd.pkgName; | ||
return linkBin(cmd, binPath); | ||
})); | ||
} | ||
function getPackageBinsFromPackageJson(pkgJson, pkgPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const cmds = yield package_bins_1.default(pkgJson, pkgPath); | ||
return cmds.map((cmd) => (Object.assign({}, cmd, { ownName: cmd.name === pkgJson.name, pkgName: pkgJson.name }))); | ||
}); | ||
async function getPackageBins(target, warn) { | ||
const pkg = await safeReadPkg(target); | ||
if (!pkg) { | ||
warn(`There's a directory in node_modules without package.json: ${target}`); | ||
return []; | ||
} | ||
return getPackageBinsFromPackageJson(pkg, target); | ||
} | ||
function linkBin(cmd, binPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const externalBinPath = path.join(binPath, cmd.name); | ||
if (EXECUTABLE_SHEBANG_SUPPORTED) { | ||
yield fs.chmod(cmd.path, 0o755); | ||
} | ||
const nodePath = yield getBinNodePaths(cmd.path); | ||
return cmdShim(cmd.path, externalBinPath, { | ||
createPwshFile: POWER_SHELL_IS_SUPPORTED, | ||
nodePath, | ||
}); | ||
}); | ||
async function getPackageBinsFromPackageJson(pkgJson, pkgPath) { | ||
const cmds = await package_bins_1.default(pkgJson, pkgPath); | ||
return cmds.map((cmd) => (Object.assign({}, cmd, { ownName: cmd.name === pkgJson.name, pkgName: pkgJson.name }))); | ||
} | ||
function getBinNodePaths(target) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const targetRealPath = yield fs.realpath(target); | ||
return R.union(Module._nodeModulePaths(targetRealPath), Module._nodeModulePaths(target)); | ||
async function linkBin(cmd, binPath) { | ||
const externalBinPath = path.join(binPath, cmd.name); | ||
if (EXECUTABLE_SHEBANG_SUPPORTED) { | ||
await fs.chmod(cmd.path, 0o755); | ||
} | ||
const nodePath = await getBinNodePaths(cmd.path); | ||
return cmdShim(cmd.path, externalBinPath, { | ||
createPwshFile: POWER_SHELL_IS_SUPPORTED, | ||
nodePath, | ||
}); | ||
} | ||
function safeReadPkg(pkgPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield read_package_json_1.fromDir(pkgPath); | ||
async function getBinNodePaths(target) { | ||
const targetRealPath = await fs.realpath(target); | ||
return R.union(Module._nodeModulePaths(targetRealPath), Module._nodeModulePaths(target)); | ||
} | ||
async function safeReadPkg(pkgPath) { | ||
try { | ||
return await read_package_json_1.fromDir(pkgPath); | ||
} | ||
catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return null; | ||
} | ||
catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return null; | ||
} | ||
throw err; | ||
} | ||
}); | ||
throw err; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pnpm/link-bins", | ||
"version": "3.0.3", | ||
"version": "4.0.0", | ||
"description": "Link bins to node_modules/.bin", | ||
@@ -11,3 +11,3 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8" | ||
}, | ||
@@ -37,5 +37,5 @@ "scripts": { | ||
"dependencies": { | ||
"@pnpm/package-bins": "^2.0.0", | ||
"@pnpm/read-package-json": "^1.0.0", | ||
"@pnpm/types": "^2.0.0", | ||
"@pnpm/package-bins": "^3.0.0", | ||
"@pnpm/read-package-json": "^2.0.0", | ||
"@pnpm/types": "^3.0.0", | ||
"@types/mz": "^0.0.32", | ||
@@ -67,3 +67,3 @@ "@types/node": "^9.6.5 || 10", | ||
"tempy": "^0.2.1", | ||
"ts-node": "^7.0.0", | ||
"ts-node": "^8.0.0", | ||
"tslint": "^5.8.0", | ||
@@ -70,0 +70,0 @@ "typescript": "^3.0.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14207
142
+ Added@pnpm/package-bins@3.1.1(transitive)
+ Added@pnpm/read-package-json@2.0.3(transitive)
+ Added@pnpm/types@3.2.0(transitive)
+ Addedp-filter@2.1.0(transitive)
+ Addedp-map@2.1.0(transitive)
+ Addedread-package-json@2.1.0(transitive)
- Removed@pnpm/package-bins@2.0.0(transitive)
- Removed@pnpm/read-package-json@1.1.1(transitive)
- Removed@pnpm/types@2.0.0(transitive)
- Removedarray-buffer-byte-length@1.0.1(transitive)
- Removedarray.prototype.reduce@1.0.7(transitive)
- Removedarraybuffer.prototype.slice@1.0.3(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddata-view-buffer@1.0.1(transitive)
- Removeddata-view-byte-length@1.0.1(transitive)
- Removeddata-view-byte-offset@1.0.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removedes-abstract@1.23.3(transitive)
- Removedes-array-method-boxes-properly@1.0.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedes-set-tostringtag@2.0.3(transitive)
- Removedes-to-primitive@1.2.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction.prototype.name@1.1.6(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedget-symbol-description@1.0.2(transitive)
- Removedglobalthis@1.0.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-bigints@1.0.2(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedinternal-slot@1.0.7(transitive)
- Removedis-array-buffer@3.0.4(transitive)
- Removedis-bigint@1.0.4(transitive)
- Removedis-boolean-object@1.1.2(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-data-view@1.0.1(transitive)
- Removedis-date-object@1.0.5(transitive)
- Removedis-negative-zero@2.0.3(transitive)
- Removedis-number-object@1.0.7(transitive)
- Removedis-regex@1.1.4(transitive)
- Removedis-shared-array-buffer@1.0.3(transitive)
- Removedis-string@1.0.7(transitive)
- Removedis-symbol@1.0.4(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedis-weakref@1.0.2(transitive)
- Removedisarray@2.0.5(transitive)
- Removedobject-inspect@1.13.2(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.5(transitive)
- Removedobject.getownpropertydescriptors@2.1.8(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedread-package-json@2.0.13(transitive)
- Removedregexp.prototype.flags@1.5.3(transitive)
- Removedsafe-array-concat@1.1.2(transitive)
- Removedsafe-regex-test@1.0.3(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedstring.prototype.trim@1.2.9(transitive)
- Removedstring.prototype.trimend@1.0.8(transitive)
- Removedstring.prototype.trimstart@1.0.8(transitive)
- Removedtyped-array-buffer@1.0.2(transitive)
- Removedtyped-array-byte-length@1.0.1(transitive)
- Removedtyped-array-byte-offset@1.0.2(transitive)
- Removedtyped-array-length@1.0.6(transitive)
- Removedunbox-primitive@1.0.2(transitive)
- Removedutil.promisify@1.1.2(transitive)
- Removedwhich-boxed-primitive@1.0.2(transitive)
- Removedwhich-typed-array@1.1.15(transitive)
Updated@pnpm/package-bins@^3.0.0
Updated@pnpm/types@^3.0.0