Skip to content

Instantly share code, notes, and snippets.

@necccc
Created October 20, 2019 14:30
Show Gist options
  • Save necccc/785b92c93320596090fc233e44b35f98 to your computer and use it in GitHub Desktop.
Save necccc/785b92c93320596090fc233e44b35f98 to your computer and use it in GitHub Desktop.
Gist for "npm authoring basics" - https://nec.is/writing/npm-authoring-basics/
# deprecate a single version
npm deprecate [email protected] "this version is not supported any more, pelase update"
# deprecate everything below a version
# mind the double-qoutes around the version information!
npm deprecate my-module@"< 1.0.4" "critical bug fixed in 1.0.4, please update"
$ npm i [email protected]
npm http fetch GET 200 http://registry.npmjs.org/my-module 760ms
npm WARN deprecated [email protected]: critical bug fixed in 1.0.4, please update
{
"files": [
"dist",
"src"
]
}
{
"scripts": {
// using babel as a global module or local dependency,
// exits with an error if the host hasn't installed depdencies or installed babel as global
"babel": "babel src --out dist",
// using babel as a local dependency
// works even if there is no global babel installed
"babel": "./node_modules/babel-cli/bin/babel src --out dist"
// using npx
// same as the previous one, but much shorter, nicer and readable
"babel": "npx babel src --out dist"
}
}
{
// your module compiled to commonJS
"main": "dist/module.js"
"browser": {
// use a request-like module based on Fetch in the browser
"request": "./shims/request-with-fetch.js",
// basically this happens
"code-for-node.js": "code-for-browser.js"
},
// your code in ES Modules format
"module": "esm/module.js"
}
{
"scripts": {
// these can be ran outside the 'run' command
"start": "",
"stop": "",
"test": "",
// these are accessibe via 'npm run ...'
"build": "",
"clean": "",
// these run before or after the scripts they are bound to by name
"prebuild": "",
"preclean": "",
"postclean": "",
}
}
# log in to an org
npm login --scope=@myorg
# init an npm project within a scope/org
npm init --scope=myorg
# publish a scoped, and public package
npm publish --access=public
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment