Skip to content

Instantly share code, notes, and snippets.



Last active Aug 23, 2018
What would you like to do?


This script will help you create scripts to fix the problem caused by enable no-bin-link option of NPM or Yarn.


Put command_patch.js to your work dir, and run it.

node command_patch.js

And it will create scripts that is associate to CLI scripts of every modules automatic.
All command of modules in your workdir will be usable after that.
I will write a npm module to make it better when I have free time.



const fs = require("fs");
const path = require("path");
// get package list from package.json
const packageList = require("./package.json").devDependencies;
// get all package name from packageList
const packageNameList = Object.keys(packageList);
const CLIList = [];
const convertPath = (packageName, binaryPath) => path.resolve(`./node_modules/${packageName}/`, binaryPath);
for (let packageName of packageNameList) {
// load package config
const packageConf = require(`./node_modules/${packageName}/package.json`);
if ("bin" in packageConf) {
if (typeof packageConf.bin !== "string") {
for (let cmd of Object.keys(packageConf.bin)) {
cmd, convertPath(packageName, packageConf.bin[cmd]),
} else {
packageName, convertPath(packageName, packageConf.bin), true,
if (!fs.existsSync("./node_modules/.bin")) {
} else {
// TODO: safe check
// make script
for (const item of CLIList) {
const [filename, binPath, _] = item;
const script = `
node "${binPath}" $*
fs.writeFileSync(`./node_modules/.bin/${filename}`, script);
fs.chmodSync(`./node_modules/.bin/${filename}`, 777);
// console.log(CLIList);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.