npm package.json: How to wrap long single function scripts?

Viewed 2585

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.

1 Answers

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).

Related