From dafdedef9a6e8028ba3434be24f1f5c0571af094 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 24 Feb 2021 08:54:19 +0100 Subject: [PATCH] feat(toggle-scripts): supports npm < 7 --- @vates/toggle-scripts/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/@vates/toggle-scripts/index.js b/@vates/toggle-scripts/index.js index 639b888a4..a9e260685 100755 --- a/@vates/toggle-scripts/index.js +++ b/@vates/toggle-scripts/index.js @@ -10,8 +10,8 @@ const mapKeys = (object, iteratee) => { return result } -const pkgPath = process.env.npm_package_json -if (pkgPath === undefined) { +const args = process.argv.slice(2) +if (args.length === 0) { const { description, name, version } = require('./package.json') const bin = 'toggle-scripts' process.stdout.write(`Usage: ${bin} options... @@ -32,7 +32,7 @@ ${name} v${version} } const plan = { __proto__: null } -for (const arg of process.argv.slice(2)) { +for (const arg of args) { const action = arg[0] const script = arg.slice(1) @@ -45,6 +45,7 @@ for (const arg of process.argv.slice(2)) { } } +const pkgPath = process.env.npm_package_json || './package.json' const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) pkg.scripts = mapKeys(pkg.scripts, (name, scripts) => { const newName = plan[name]