Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 750
Jeff Tanner Avatar asked Jul 01 '19 21:07

Jeff Tanner


People also ask

How do I specify scripts in package json?

To define an NPM script, set its name and write the script under the 'scripts' property of your package. json file: To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command. Some predefined aliases convert to npm run, like npm test or npm start, you can use them interchangeably.

What is lint in package json?

npm-package-json-lint is a configurable linter that helps enforce standards for your package. json file. By default no rules are enabled.

Can I modify package JSON file?

"edit-package-json" is an NPM package that makes changes to "package. json" files. It can be used on the command line (as "editPackageJson") or from within a Node app.


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

like image 60
Bence László Avatar answered Dec 16 '22 19:12

Bence László