benoror / better-npm-run

🏃‍♂️ Better NPM scripts runner
MIT License
639 stars 56 forks source link

Unable to differentiate between consumed and appended arguments. #68

Closed shrugs closed 7 years ago

shrugs commented 7 years ago

Given a package.json like so (react-native project):

{
  "scripts": {
    "bundle-ios:staging": "bnr bundle-ios -p .env.staging"
  },
  "betterScripts": {
    "bundle-ios": "node node_modules/react-native/local-cli/cli.js bundle --platform ios --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle"
  }
}

better-npm-run attempts to execute the following command: node node_modules/react-native/local-cli/cli.js bundle --platform ios --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle -p .env.staging. The react-native cli then complains about the -p argument that it doesn't understand. The issue, of course, is that there's no way to differentiate between an argument that should be consumed by better-npm-run and arguments to be appended to the generated command.

I suggest changing the cli signature to better-npm-run [options] <script-name> [extraArgs]. Then we'll be able to easily determine which options should be consumed by bnr and which should be consumed by the generated command.

With a change like this, the following example would work:

{
  "scripts": {
    "bundle-ios:staging": "bnr -p .env.staging bundle-ios --dev true",
    "bundle-ios:production": "bnr -p .env.production bundle-ios --dev false"
  },
  "betterScripts": {
    "bundle-ios": "node node_modules/react-native/local-cli/cli.js bundle --platform ios --entry-file index.ios.js --bundle-output ios/main.jsbundle"
  }
}
benoror commented 7 years ago

Fixed via https://github.com/benoror/better-npm-run/pull/70