Инструменты пользователя

Инструменты сайта


service:npm

Настройка сборки

На примере Teamcity

# Частный репозиторий
npm config set registry="https://nexus-ci.example.com/repository/project-npm/"
npm config set //nexus-ci.example.com/repository/project-npm/:_auth=$(echo -n "%nexus_username%:%nexus_password%" |base64)
# Игнор кривого SSL-сертификата
npm config set strict-ssl false
# Скачать зависимости
npm install --verbose
 
# Включить verbose mode глобально
npm config set loglevel verbose
 
# Грохнуть старые логи (чтобы их не было в артефактах)
#rm -f "$HOME/.npm/_logs/*.log" # не помогает
npm config set logs-max 1
 
# Почистить кэш (обычно не нужно)
npm cache clean
 
# Удалить конфиг
npmrc=$(npm config get userconfig)
[ -f $npmrc ] && rm $npmrc
 
# Список всех зависимостей
npm ls --all
# Зависимости для конкретного компонента
npm ls [dependency]
# Задать глубину
npm ls --depth=[depth]

https://docs.npmjs.com/cli/v11/configuring-npm/npmrc#auth-related-configuration

Docker

git clone https://github.com/cutenode/good-first-issue.git # Тестовый репозиторий
cd good-first-issue
# Список зависимостей
readarray -t deps <<< "$(docker run --rm --name npm -v $PWD:/app -w /app node npm ls -s --all |awk '{print $NF}')"
unset deps[0]
echo "${deps[@]}"
# boxen@^4.2.0 chalk@^3.0.0 commander@^4.0.1 inquirer@^7.0.0 jest@^23.6.0 libgfi@^1.1.1 open@^7.0.0 standard@^14.0.0 strip-ansi@^6.0.0

Using npm's "ls" command for fun and insight

Ошибки

Self-signed certificate in certificate chain

Сборка надолго зависает и заканчивается ошибкой, зависимости не скачиваются, в логах ругань на кривой SSL-сертификат. Решение (при отсутствии более правильного)

npm config set strict-ssl false

https://stackoverflow.com/questions/9626990/receiving-error-error-ssl-error-self-signed-cert-in-chain-while-using-npm

Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"

Невозможно скачать модули из Нексуса, ошибка HTTP 401.

npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"

Решение: поменять username и _password на _auth.

repo='nexus.example.com/repository/project-npm'
npmbin='%teamcity.tool.node-20.14.0%/bin/npm'
# Get modules
$npmbin config set registry="https://$repo/"
#$npmbin config set //$repo/:username=%nexus_username%
#$npmbin config set //$repo/:_password=%nexus_password%
$npmbin config set //$repo/:_auth=$(echo -n "%nexus_username%:%nexus_password%" |base64)
$npmbin config set strict-ssl false
$npmbin install --verbose
service/npm.txt · Последнее изменение: — viacheslav

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki