Skip to content

Instantly share code, notes, and snippets.

@DaneTheory
Last active June 24, 2021 09:34
Show Gist options
  • Select an option

  • Save DaneTheory/3e5bc10ba162e7756dd8fcb485898a9a to your computer and use it in GitHub Desktop.

Select an option

Save DaneTheory/3e5bc10ba162e7756dd8fcb485898a9a to your computer and use it in GitHub Desktop.
The Package (dot) JSON: A story of love, triumph, and general witchcraft/wizardry - InitFields: Name
[{
"npm:current": {
"ref": "https://docs.npmjs.com/cli/v7/configuring-npm/package-json#name",
"source": [
"If you plan to publish your package, the most important things in your 'package.json' are the name and version fields as they will be required. The name and version together form an identifier that is assumed to be completely unique. Changes to the package should come along with changes to the version. If you don't plan to publish your package, the name and version fields are optional.",
"The name is what your thing is called.",
["Some rules:",
[
"The name must be less than or equal to 214 characters. This includes the scope for scoped packages.",
"The names of scoped packages can begin with a dot or an underscore. This is not permitted without a scope.",
"New packages must not have uppercase letters in the name.",
"The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can't contain any non-URL-safe characters."
]
],
["Some tips:",
[
"Don't use the same name as a core Node module.",
"Don't put \"js\" or \"node\" in the name. It's assumed that it's js, since you're writing a package.json file, and you can specify the engine using the \"engines\" field.",
"The name will probably be passed as an argument to require(), so it should be something short, but also reasonably descriptive.",
["You may want to check the npm registry to see if there's something by that name already, before you get too attached to it.", "https://www.npmjs.com"]
]
],
"A name can be optionally prefixed by a scope, e.g. @myorg/mypackage."
]
},
"npm:legacy": {
"ref": "https://docs.npmjs.com/cli/v6/configuring-npm/package-json#name",
"source": [
"If you plan to publish your package, the most important things in your 'package.json' are the name and version fields as they will be required. The name and version together form an identifier that is assumed to be completely unique. Changes to the package should come along with changes to the version. If you don't plan to publish your package, the name and version fields are optional.",
"The name is what your thing is called.",
["Some rules:",
[
"The name must be less than or equal to 214 characters. This includes the scope for scoped packages.",
"The names of scoped packages can begin with a dot or an underscore. This is not permitted without a scope.",
"New packages must not have uppercase letters in the name.",
"The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can't contain any non-URL-safe characters."
]
],
["Some tips:",
[
"Don't use the same name as a core Node module.",
"Don't put \"js\" or \"node\" in the name. It's assumed that it's js, since you're writing a package.json file, and you can specify the engine using the \"engines\" field.",
"The name will probably be passed as an argument to require(), so it should be something short, but also reasonably descriptive.",
["You may want to check the npm registry to see if there's something by that name already, before you get too attached to it.", "https://www.npmjs.com"]
]
],
"A name can be optionally prefixed by a scope, e.g. @myorg/mypackage."
]
},
"yarn:current": {
"ref": "https://yarnpkg.com/configuration/manifest#name",
"source": [
"The name of the package. Used to identify it across the application, especially amongst multiple workspaces. The first part of the name (here @scope/) is optional and is used as a namespace).",
"_example_:\"name\": \"@scope/name\":_example_"
]
},
"yarn:legacy": {
"ref": "https://classic.yarnpkg.com/en/docs/package-json/#toc-name",
"source": [
"This is the name of your package. It gets used in URLs, as an argument on the command line, and as the directory name inside 'node_modules'.",
"_example_:{ \n \"name\": \"my-awesome-package\" \n }:_example_",
["Rules", [
"Must be less than or equal to 214 characters (including the '@scope/' for scoped packages).",
"Must not start with a dot ('.') or an underscore ('_').",
"Must not have an uppercase letter in the name.",
"Must use only URL-safe characters."
]],
["Tips", [
"Don’t use the same name as a core Node.js module.",
"Don’t put 'js' or 'node' in the name.",
"Keep names short and descriptive. You want people to understand what it is from the name, but it will also be used in 'require()' calls.",
"Make sure that there isn’t something in the _url[https://www.npmjs.com/]_:registry:_url_ with the same name."
]]
]
}
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment