Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What naming convention do I use for scripts in package.json?

Tags:

In package.json I have this script name with two words lint and fix. How should I make a right name?

There are options:

  1. lowerCamelCase - lintFix
  2. UpperCamelCase - LintFix
  3. snake_case - lint_fix
  4. kebab-case - lint-fix
  5. gulp-style with a colon delimiter - lint:fix
  6. Any another delimiter.

What option is right? And why?

like image 835
galkin Avatar asked Jul 11 '17 12:07

galkin


People also ask

How do you call a script in a package json?

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 should I name a package JSON file?

A package. json file must contain "name" and "version" fields. The "name" field contains your package's name, and must be lowercase and one word, and may contain hyphens and underscores. The "version" field must be in the form x.x.x and follow the semantic versioning guidelines.

What does scripts mean in package json?

Scripts are stored in a project's package. json file, which means they're shared amongst everyone using the codebase. They help automate repetitive tasks, and mean having to learn fewer tools. Node npm scripts also ensure that everyone is using the same command with the same flags.


2 Answers

Please always use kebab case. The colon is a throwback to gulp, and it looks terrible. I hate it.

Disclaimer: My opinions are often wrong and I had a dysfunctional family.

like image 133
John Henckel Avatar answered Sep 18 '22 14:09

John Henckel


There is no official naming convention. Before npm@v4 standard scripts had only one word, for example test, start, prestart. npm@v4 introduced a new script prepublishOnly*.

So now, the best practice is use lowerCamelCase.

*Reference: https://iamakulov.com/notes/npm-4-prepublish/

like image 30
galkin Avatar answered Sep 21 '22 14:09

galkin