-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import is from '@sindresorhus/is'; | ||
import { TEMPORARY_ERROR } from '../../../constants/error-messages'; | ||
import { logger } from '../../../logger'; | ||
import { exec } from '../../../util/exec'; | ||
import type { ExecOptions } from '../../../util/exec/types'; | ||
import { | ||
deleteLocalFile, | ||
readLocalFile, | ||
writeLocalFile, | ||
} from '../../../util/fs'; | ||
import type { UpdateArtifact, UpdateArtifactsResult } from '../types'; | ||
|
||
export async function updateArtifacts( | ||
updateArtifact: UpdateArtifact | ||
): Promise<UpdateArtifactsResult[] | null> { | ||
const { packageFileName, updatedDeps, newPackageFileContent, config } = | ||
updateArtifact; | ||
logger.debug({ updateArtifact }, `bun.updateArtifacts(${packageFileName})`); | ||
const isLockFileMaintenance = config.updateType === 'lockFileMaintenance'; | ||
|
||
if (is.emptyArray(updatedDeps) && !isLockFileMaintenance) { | ||
logger.debug('No updated bun deps - returning null'); | ||
return null; | ||
} | ||
|
||
const lockFileName = config.lockFiles?.[0]; | ||
|
||
if (!lockFileName) { | ||
logger.debug(`No ${lockFileName} found`); | ||
return null; | ||
} | ||
|
||
const oldLockFileContent = await readLocalFile(lockFileName, 'utf8'); | ||
if (!oldLockFileContent) { | ||
logger.debug(`No ${lockFileName} found`); | ||
return null; | ||
} | ||
|
||
try { | ||
await writeLocalFile(packageFileName, newPackageFileContent); | ||
if (config.isLockFileMaintenance) { | ||
await deleteLocalFile(lockFileName); | ||
} | ||
|
||
const execOptions: ExecOptions = { | ||
cwdFile: packageFileName, | ||
docker: {}, | ||
toolConstraints: [ | ||
{ | ||
toolName: 'bun', | ||
}, | ||
], | ||
}; | ||
|
||
await exec('bun install', execOptions); | ||
const newLockFileContent = await readLocalFile(lockFileName, 'utf8'); | ||
if (oldLockFileContent === newLockFileContent) { | ||
return null; | ||
} | ||
return [ | ||
{ | ||
file: { | ||
type: 'addition', | ||
path: lockFileName, | ||
contents: newLockFileContent, | ||
}, | ||
}, | ||
]; | ||
} catch (err) { | ||
// istanbul ignore if | ||
if (err.message === TEMPORARY_ERROR) { | ||
throw err; | ||
} | ||
logger.warn({ lockfile: lockFileName, err }, `Failed to update lock file`); | ||
return [ | ||
{ | ||
artifactError: { | ||
lockFile: lockFileName, | ||
stderr: err.message, | ||
}, | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { logger } from '../../../../logger'; | ||
import { getSiblingFileName, readLocalFile } from '../../../../util/fs'; | ||
|
||
import { extractPackageJson } from '../../npm/extract/common/package-file'; | ||
import type { NpmPackage } from '../../npm/extract/types'; | ||
import type { NpmManagerData } from '../../npm/types'; | ||
import type { ExtractConfig, PackageFile } from '../../types'; | ||
|
||
function safeParseJson(json: string): any { | ||
try { | ||
return JSON.parse(json); | ||
} catch (err) { | ||
logger.debug({ err }, 'Error parsing JSON'); | ||
return null; | ||
} | ||
} | ||
|
||
function matchesName(fileName: string, name: string): boolean { | ||
return fileName === name || fileName.endsWith(`/${name}`); | ||
} | ||
|
||
export async function extractAllPackageFiles( | ||
config: ExtractConfig, | ||
matchedFiles: string[] | ||
): Promise<PackageFile[]> { | ||
const packageFiles: PackageFile<NpmManagerData>[] = []; | ||
for (const matchedFile of matchedFiles) { | ||
if (!matchesName(matchedFile, 'bun.lockb')) { | ||
logger.warn({ matchedFile }, 'Invalid bun lockfile match'); | ||
continue; | ||
} | ||
const packageFile = getSiblingFileName(matchedFile, 'package.json'); | ||
const packageFileContent = await readLocalFile(packageFile, 'utf8'); | ||
if (!packageFileContent) { | ||
logger.debug({ packageFileName: packageFile }, 'No package.json found'); | ||
continue; | ||
} | ||
const packageJson: NpmPackage = safeParseJson(packageFileContent); | ||
if (!packageJson) { | ||
logger.debug({ packageFileName: packageFile }, 'Invalid package.json'); | ||
continue; | ||
} | ||
|
||
const extracted = extractPackageJson(packageJson, packageFile); | ||
if (!extracted) { | ||
logger.debug({ packageFileName: packageFile }, 'No dependencies found'); | ||
continue; | ||
} | ||
packageFiles.push({ | ||
...extracted, | ||
packageFile, | ||
lockFiles: [matchedFile], | ||
}); | ||
} | ||
|
||
return packageFiles; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Category } from '../../../constants'; | ||
import { GithubTagsDatasource } from '../../datasource/github-tags'; | ||
import { NpmDatasource } from '../../datasource/npm'; | ||
import * as npmVersioning from '../../versioning/npm'; | ||
|
||
export { updateArtifacts } from './artifacts'; | ||
export { extractAllPackageFiles } from './extract'; | ||
export { getRangeStrategy, updateDependency } from '../npm'; | ||
|
||
export const supercedesManagers = ['npm']; | ||
export const supportsLockFileMaintenance = true; | ||
|
||
export const defaultConfig = { | ||
fileMatch: ['(^|/)bun\\.lockb$'], | ||
versioning: npmVersioning.id, | ||
digest: { | ||
prBodyDefinitions: { | ||
Change: | ||
'{{#if displayFrom}}`{{{displayFrom}}}` -> {{else}}{{#if currentValue}}`{{{currentValue}}}` -> {{/if}}{{/if}}{{#if displayTo}}`{{{displayTo}}}`{{else}}`{{{newValue}}}`{{/if}}', | ||
}, | ||
}, | ||
prBodyDefinitions: { | ||
Change: | ||
"[{{#if displayFrom}}`{{{displayFrom}}}` -> {{else}}{{#if currentValue}}`{{{currentValue}}}` -> {{/if}}{{/if}}{{#if displayTo}}`{{{displayTo}}}`{{else}}`{{{newValue}}}`{{/if}}]({{#if depName}}https://renovatebot.com/diffs/npm/{{replace '/' '%2f' depName}}/{{{currentVersion}}}/{{{newVersion}}}{{/if}})", | ||
}, | ||
}; | ||
|
||
export const categories: Category[] = ['js']; | ||
|
||
export const supportedDatasources = [GithubTagsDatasource.id, NpmDatasource.id]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Used for updating bun projects. | ||
Bun is a tool for JavaScript projects and therefore an alternative to managers like npm, pnpm and Yarn. | ||
|
||
If a `package.json` is found to be part of `bun` manager results then the same file will be excluded from the `npm` manager results so that it's not duplicated. | ||
This means that supporting a `bun.lockb` file in addition to other JS lock files is not supported - Bun will take priority. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters