From 34ab2bf641a8dc7ab467bdef31eebd543bd516f4 Mon Sep 17 00:00:00 2001 From: Stephen Dahl <stephendahl443+github@gmail.com> Date: Tue, 18 Feb 2025 02:36:56 -0800 Subject: [PATCH] feat(bun): update npmrc during bun updates (#34213) --- lib/modules/manager/bun/artifacts.spec.ts | 8 ++++++++ lib/modules/manager/bun/artifacts.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/modules/manager/bun/artifacts.spec.ts b/lib/modules/manager/bun/artifacts.spec.ts index 99bd3b0e73..69fe52308d 100644 --- a/lib/modules/manager/bun/artifacts.spec.ts +++ b/lib/modules/manager/bun/artifacts.spec.ts @@ -65,6 +65,8 @@ describe('modules/manager/bun/artifacts', () => { ]; const oldLock = Buffer.from('old'); fs.readFile.mockResolvedValueOnce(oldLock as never); + // npmrc + fs.readFile.mockResolvedValueOnce('# dummy' as never); const newLock = Buffer.from('new'); fs.readFile.mockResolvedValueOnce(newLock as never); expect(await updateArtifacts(updateArtifact)).toEqual([ @@ -85,6 +87,8 @@ describe('modules/manager/bun/artifacts', () => { updateArtifact.config.updateType = 'lockFileMaintenance'; const oldLock = Buffer.from('old'); fs.readFile.mockResolvedValueOnce(oldLock as never); + // npmrc + fs.readFile.mockResolvedValueOnce('# dummy' as never); const newLock = Buffer.from('new'); fs.readFile.mockResolvedValueOnce(newLock as never); expect(await updateArtifacts(updateArtifact)).toEqual([ @@ -159,6 +163,8 @@ describe('modules/manager/bun/artifacts', () => { ]; const oldLock = Buffer.from('old'); fs.readFile.mockResolvedValueOnce(oldLock as never); + // npmrc + fs.readFile.mockResolvedValueOnce('# dummy' as never); const newLock = Buffer.from('new'); fs.readFile.mockResolvedValueOnce(newLock as never); expect(await updateArtifacts(updateArtifact)).toEqual([ @@ -179,6 +185,8 @@ describe('modules/manager/bun/artifacts', () => { updateArtifact.config.updateType = 'lockFileMaintenance'; const oldLock = Buffer.from('old'); fs.readFile.mockResolvedValueOnce(oldLock as never); + // npmrc + fs.readFile.mockResolvedValueOnce('# dummy' as never); const newLock = Buffer.from('new'); fs.readFile.mockResolvedValueOnce(newLock as never); expect(await updateArtifacts(updateArtifact)).toEqual([ diff --git a/lib/modules/manager/bun/artifacts.ts b/lib/modules/manager/bun/artifacts.ts index 4e47817c74..3c1d84352c 100644 --- a/lib/modules/manager/bun/artifacts.ts +++ b/lib/modules/manager/bun/artifacts.ts @@ -1,4 +1,5 @@ import is from '@sindresorhus/is'; +import upath from 'upath'; import { GlobalConfig } from '../../../config/global'; import { TEMPORARY_ERROR } from '../../../constants/error-messages'; import { logger } from '../../../logger'; @@ -9,6 +10,12 @@ import { readLocalFile, writeLocalFile, } from '../../../util/fs'; +import { processHostRules } from '../npm/post-update/rules'; +import { + getNpmrcContent, + resetNpmrcContent, + updateNpmrcContent, +} from '../npm/utils'; import type { UpdateArtifact, UpdateArtifactsResult } from '../types'; export async function updateArtifacts( @@ -39,6 +46,11 @@ export async function updateArtifacts( return null; } + const pkgFileDir = upath.dirname(packageFileName); + const npmrcContent = await getNpmrcContent(pkgFileDir); + const { additionalNpmrcContent } = processHostRules(); + await updateNpmrcContent(pkgFileDir, npmrcContent, additionalNpmrcContent); + try { await writeLocalFile(packageFileName, newPackageFileContent); if (isLockFileMaintenance) { @@ -64,6 +76,8 @@ export async function updateArtifacts( }; await exec(cmd, execOptions); + await resetNpmrcContent(pkgFileDir, npmrcContent); + const newLockFileContent = await readLocalFile(lockFileName); if ( !newLockFileContent || -- GitLab