Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(npm): log hostRules npmrc logic #30274

Merged
merged 5 commits into from
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/modules/manager/npm/post-update/rules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import is from '@sindresorhus/is';
import { logger } from '../../../../logger';
import * as hostRules from '../../../../util/host-rules';
import { regEx } from '../../../../util/regex';
import { toBase64 } from '../../../../util/string';
Expand All @@ -18,15 +19,18 @@ export function processHostRules(): HostRulesResult {
const npmHostRules = hostRules.findAll({
hostType: 'npm',
});
logger.debug(`Found ${npmHostRules.length} npm host rule(s)`);
for (const hostRule of npmHostRules) {
if (!hostRule.resolvedHost) {
logger.debug('Skipping host rule without resolved host');
continue;
}

const matchedHost = hostRule.matchHost;
// Should never be necessary as if we have a resolvedHost, there has to be a matchHost
// istanbul ignore next
if (!matchedHost) {
logger.debug('Skipping host rule without matchHost');
continue;
}

Expand All @@ -38,6 +42,7 @@ export function processHostRules(): HostRulesResult {

if (hostRule.token) {
const key = hostRule.authType === 'Basic' ? '_auth' : '_authToken';
logger.debug(`Adding npmrc entry for ${cleanedUri} with key ${key}`);
additionalNpmrcContent.push(`${cleanedUri}:${key}=${hostRule.token}`);

if (hostRule.authType === 'Basic') {
Expand All @@ -60,6 +65,9 @@ export function processHostRules(): HostRulesResult {
}

if (is.string(hostRule.username) && is.string(hostRule.password)) {
logger.debug(
`Adding npmrc entry for ${cleanedUri} with username/password`,
);
const password = toBase64(hostRule.password);
additionalNpmrcContent.push(
`${cleanedUri}:username=${hostRule.username}`,
Expand Down