2. - When do we need to create npm module?
- How to create npm module?
- How to easy import modules into the project?
- How to publish npm artifact?
- Where we should store npm modules?
- public and private npm registry
- How to maintain modules without PAIN
Modules and artifacts in NPM
3. NPM modules. Why
- Isolating components that are duplicated in multiple projects
- Flexibility in development
- Using the advantages of versioning
- Convenience during release
- Common standards for working with components
6. NPM CLI
- npm publish (publish your package):
- configure package.json
- describe README.MD
- set default credentials
- tap npm publish
- enjoy public registry
- npm pack (own artifact):
- setup your package.json
- tap npm pack
- get file <name>-<version>.tgz
- OK. WHAT'S NEXT?
7.
8. Registry
default (https://registry.npmjs.org)
- public (may do anything with any dependencies)
- private:
- MyGet (https://www.myget.org) —which costs US$
9/month for starter plan and you only would have 2
contributors and 1GB storage
- NPM Org (https://www.npmjs.com)—which costs US$ 7 per
user per month. (Organize packages and teams into
permissions groups)
- *Custom solution
left-pad - as an example of unexpected behavior of public registry
(https://www.npmjs.com/policies/terms)
9.
10. Artifactory
- Artifactory provides full support for managing npm packages and
ensures optimal and reliable access to npmjs.org.
- The ability to access multiple npm registries from a single URL by
aggregating them under a Virtual Repository. This overcomes the
limitation of the npm client which can only access a single registry at
a time.
- Support for flexible npm repository layouts that allow you to
organize your npm packages and assign access privileges
according to projects or development teams.
* duplication of dependencies using the virtual repository Artifactory -
will protect dependencies from deletion / renaming case
11.
12. Recommendations
- Choose the right solution for each individual situation (git
dependency, public/private registry, registry provider...)
- Try to avoid public registry
- Follow the rules of semantic versioning
- Don't fuck up with package.json dependencies specification ^, ~
- Collect old artifacts
- Build process of deployment your npm modules with a team
(example: prefix for development, republish package terms)
- CI / CD
13. Semantic Versioning
semver.org
- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards-
compatible manner, and
- PATCH version when you make backwards-compatible bug
fixes.
14. Basic CI/CD flow
example
- unit tests - run on each commit. Quality control.
- manual publish - publish npm module to artifactory. Manual
action. Appends a prefix to the artifact name
- manual unpublish - remove npm module from artifactory
- autopublish - triggered only when changes were merged in
master. Publish npm module to artifactory without any prefixes