8

I have created an npm package script for npx depcheck and one of its parameters, --ignore, its value is getting very long and I expect will get longer.

"audit:depcheck": "npx depcheck --specials=bin --ignore-dirs=dist,node_modules --ignores=tslint,gts,ts-node,ts-node-dev,typescript,mocha,winston,passport-springcm,passport-box,passport-dropbox-oauth2,passport-google-oauth20,passport-microsoft,mocha,nyc",

Tried: I have tried just simply breaking the very long script into new lines but this approach is not JSON compliant.

Goal: Do the same thing, but readable within 110 character width editor.

Jeff
  • 1,917
  • 1
  • 25
  • 43
  • Possible duplicate of [How can I continue a text string in a JSON object onto another line?](https://stackoverflow.com/questions/30231280/how-can-i-continue-a-text-string-in-a-json-object-onto-another-line) – RobC Jul 02 '19 at 12:46

1 Answers1

5

You can write a shell script, like (do not copy-paste it exactly, just to get the idea):

#!/usr/bin/env bash
npx depcheck --specials=bin --ignore-dirs=dist,node_modules --ignores=tslint,gts,ts-node,ts-node-dev,typescript,mocha,winston,passport-springcm,passport-box,passport-dropbox-oauth2,passport-google-oauth20,passport-microsoft,mocha,nyc

Name it something descriptive, for example npx_depcheck.sh or something else you want. Then call the shell script from package.json:

"audit:depcheck": "./npx_depcheck.sh",

Note: make sure your script can run: chmod u+x ./npx_depcheck.sh

Edit: as @RobC wrote, this solution expects that the system has a shell. The point is, you can attach any kind of scripts, just keep in mind that different environments have different runtimes and tools (a Node.js script makes sense, since the environment where you want to run your application most likely has Node.JS installed).

Bence László
  • 494
  • 2
  • 5
  • 14
  • 10
    This will fail cross-platform, i.e. via windows `cmd.exe` which doesn't have `sh`. It would be better to invoke a _node.js_ script instead of a `.sh` script via npm-scripts, e.g. `"scripts": { "audit:depcheck": "node ./npx_depcheck.js" }`. In `npx_depcheck.js` shell out the `npx ...` command using, e.g. [`child_process.exec()`](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback) or [`child_process.execSync()`](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options). – RobC Jul 04 '19 at 14:35