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 3 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
Expand Up @@ -4,6 +4,7 @@
import { toBase64 } from '../../../../util/string';
import { isHttpUrl } from '../../../../util/url';
import type { YarnRcYmlFile } from './types';
import { logger } from '../../../../logger';

Check failure on line 7 in lib/modules/manager/npm/post-update/rules.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

`../../../../logger` import should occur before import of `../../../../util/host-rules`

export interface HostRulesResult {
additionalNpmrcContent: string[];
Expand All @@ -18,15 +19,18 @@
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 @@

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 @@
}

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
Loading