NPM
Common commands
bash
npm install <package> --save|--global
npm uninstall <package>
Gitlab NPM Registry
Authenticate
Personal access token
- Go to gitlab user account > Access Tokens
- Add a new token with api access and save
- Copy and save the token
- Set authentication
sh
npm config set -- "//gitlab.example.com/api/v4/packages/npm/:_authToken" "<token>"
Scope
Scope will be the root of your gitlab. For example: https://gitlab.com/jckoh/software-v2/lib/logger
The scope will be jckoh
Library development
- Create empty directory
- Initialize npm project and fill in required information, for package name, follow gitlab documentation Package Naming Convention
sh
npm init
- Create .npmrc at project directory
- Configure npm registry
sh
npm config set @<scope>:registry https://gitlab.com/api/v4/projects/<project_id>/packages/npm/
npm config set -- '//gitlab.com/api/v4/projects/<project_id>/packages/npm/:_authToken' "<token>"
- Publish your npm using
sh
npm publish
- You also can define your publish config at
package.json
.
json
{
"publishConfig": { "@<scope>:registry":" https://gitlab.com/api/v4/projects/<project_id>/packages/npm/" }
}
Using private npm
- Set the scope
sh
npm config set @<scope>:registry https://gitlab.com/api/v4/packages/npm/
- Install npm package
sh
npm install @scope/package
publish to npmjs.com public repository
- Init
sh
npm init --scope=@scope-name
- Publish
sh
npm publish --access public
Pnpm
Workspace
TODO
Link library
pnpm add file:<path to library>
# At library you want to share
pnpm link
# At project want to use library
pnpm link <pkg>