Skip to content

Commit

Permalink
chore(npm): log hostRules npmrc logic (#30274)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <[email protected]>
  • Loading branch information
rarkins and secustor authored Sep 22, 2024
1 parent 2c9a076 commit b0a0a71
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit b0a0a71

Please sign in to comment.