Socket
Socket
Sign inDemoInstall

@pnpm/link-bins

Package Overview
Dependencies
14
Maintainers
2
Versions
138
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 2.0.0

11

lib/index.d.ts

@@ -1,6 +0,7 @@

declare const _default: (modules: string, binPath: string, exceptPkgName?: string | undefined) => Promise<void[]>;
import { PackageJson } from '@pnpm/types';
declare const _default: (modules: string, binPath: string, exceptPkgName?: string | undefined) => Promise<void>;
export default _default;
/**
* Links executable into `node_modules/.bin`.
*/
export declare function linkPackageBins(target: string, binPath: string): Promise<void>;
export declare function linkBinsOfPackages(pkgs: Array<{
manifest: PackageJson;
location: string;
}>, binsTarget: string): Promise<void>;

@@ -26,29 +26,61 @@ "use strict";

const pkgDirs = yield getPkgDirs_1.default(modules);
return Promise.all(pkgDirs
.map((pkgDir) => normalizePath(pkgDir))
const allCmds = R.unnest((yield Promise.all(pkgDirs
.map(normalizePath)
.filter((pkgDir) => !exceptPkgName || !pkgDir.endsWith(`/${exceptPkgName}`))
.map((pkgDir) => linkPackageBins(pkgDir, binPath)));
.map(getPackageBins)))
.filter((cmds) => cmds.length));
return linkBins(allCmds, binPath);
});
/**
* Links executable into `node_modules/.bin`.
*/
function linkPackageBins(target, binPath) {
function linkBinsOfPackages(pkgs, binsTarget) {
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);
});
}
exports.linkBinsOfPackages = linkBinsOfPackages;
function linkBins(allCmds, binPath) {
return __awaiter(this, void 0, void 0, function* () {
if (!allCmds.length)
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]) {
logger_1.default.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) {
return __awaiter(this, void 0, void 0, function* () {
const pkg = yield safeReadPkg(path.join(target, 'package.json'));
if (!pkg) {
logger_1.default.warn(`There's a directory in node_modules without package.json: ${target}`);
return;
return [];
}
const cmds = yield package_bins_1.default(pkg, target);
if (!cmds.length)
return;
yield mkdirp(binPath);
yield Promise.all(cmds.map((cmd) => __awaiter(this, void 0, void 0, function* () {
const externalBinPath = path.join(binPath, cmd.name);
const nodePath = (yield getBinNodePaths(target)).join(path.delimiter);
return cmdShim(cmd.path, externalBinPath, { nodePath });
})));
return getPackageBinsFromPackageJson(pkg, target);
});
}
exports.linkPackageBins = linkPackageBins;
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 })));
});
}
function linkBin(cmd, binPath) {
return __awaiter(this, void 0, void 0, function* () {
const externalBinPath = path.join(binPath, cmd.name);
const nodePath = (yield getBinNodePaths(cmd.path)).join(path.delimiter);
return cmdShim(cmd.path, externalBinPath, { nodePath });
});
}
function getBinNodePaths(target) {

@@ -55,0 +87,0 @@ return __awaiter(this, void 0, void 0, function* () {

{
"name": "@pnpm/link-bins",
"version": "1.0.3",
"version": "2.0.0",
"description": "Link bins to node_modules/.bin",

@@ -11,3 +11,3 @@ "main": "lib/index.js",

"engines": {
"node": ">=4"
"node": ">=6"
},

@@ -14,0 +14,0 @@ "scripts": {

@@ -22,3 +22,3 @@ # @pnpm/link-bins

await linkPackageBins('node_modules/some-pkg', 'node_modules/.bin')
await linkBinsOfPackages([{manifest: packageJson, location: pathToPackage}], 'node_modules/.bin')
```

@@ -25,0 +25,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc