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/packagepublish to npmjs.com public repository
- Init
sh
npm init --scope=@scope-name- Publish
sh
npm publish --access publicPnpm
Workspace
create pnpm-workspace.yaml file in the root folder
yaml
packages:
- apps/*
- packages/*
- test/*To install a library to an app
bash
pnpm add @company/lib --filter ./ --workspaceLink library
pnpm add file:<path to library>
# At library you want to share
pnpm link
# At project want to use library
pnpm link <pkg>Security
Minimum Release Age
ini
; per project (./.npmrc) or global (~/.npmrc)
min-release-age=7yaml
# per project (./pnpm-workspace.yaml) or global (~/.config/pnpm/config.yaml)
minimumReleaseAge: 10080toml
# per project (./bunfig.toml) or global ($HOME/.bunfig.toml) or ($XDG_CONFIG_HOME/.bunfig.toml)
[install]
minimumReleaseAge = 604800Disable install scripts
ini
# .npmrc
ignore-scripts=trueBlock git dependencies
ini
# .npmrc
allow-git=none
# or
allow-git=rootyaml
# pnpm-workspace.yaml
blockExoticSubdeps: true
trustPolicy: no-downgrade