2023-08-15 09:31:15 +00:00
|
|
|
// TODO: types (#22198)
|
2020-08-06 05:59:22 +00:00
|
|
|
import is from '@sindresorhus/is';
|
2021-05-21 20:20:23 +00:00
|
|
|
import deepmerge from 'deepmerge';
|
2020-07-06 09:17:06 +00:00
|
|
|
import upath from 'upath';
|
2022-03-03 09:35:26 +00:00
|
|
|
import { logger } from '../../../../logger';
|
|
|
|
import { ExternalHostError } from '../../../../types/errors/external-host-error';
|
|
|
|
import { getChildProcessEnv } from '../../../../util/exec/env';
|
2020-07-04 10:47:52 +00:00
|
|
|
import {
|
2020-07-06 09:17:06 +00:00
|
|
|
deleteLocalFile,
|
2021-06-24 13:06:04 +00:00
|
|
|
ensureCacheDir,
|
2021-05-21 20:20:23 +00:00
|
|
|
getSiblingFileName,
|
|
|
|
readLocalFile,
|
|
|
|
writeLocalFile,
|
2022-03-03 09:35:26 +00:00
|
|
|
} from '../../../../util/fs';
|
2023-02-22 08:18:53 +00:00
|
|
|
import { getFile, getRepoStatus } from '../../../../util/git';
|
2022-03-03 09:35:26 +00:00
|
|
|
import type { FileChange } from '../../../../util/git/types';
|
|
|
|
import * as hostRules from '../../../../util/host-rules';
|
|
|
|
import { newlineRegex, regEx } from '../../../../util/regex';
|
|
|
|
import { ensureTrailingSlash } from '../../../../util/url';
|
2023-12-01 11:58:43 +00:00
|
|
|
import { dump, load } from '../../../../util/yaml';
|
2022-03-03 09:35:26 +00:00
|
|
|
import { NpmDatasource } from '../../../datasource/npm';
|
2023-02-22 08:18:53 +00:00
|
|
|
import { scm } from '../../../platform/scm';
|
2023-02-20 14:58:49 +00:00
|
|
|
import type { PackageFile, PostUpdateConfig, Upgrade } from '../../types';
|
2021-08-29 12:59:58 +00:00
|
|
|
import { getZeroInstallPaths } from '../extract/yarn';
|
2023-08-22 12:20:37 +00:00
|
|
|
import type { NpmManagerData } from '../types';
|
2022-03-22 03:48:25 +00:00
|
|
|
import { composeLockFile, parseLockFile } from '../utils';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as npm from './npm';
|
2019-07-25 06:17:19 +00:00
|
|
|
import * as pnpm from './pnpm';
|
2021-05-21 20:20:23 +00:00
|
|
|
import { processHostRules } from './rules';
|
2021-05-11 17:08:02 +00:00
|
|
|
import type {
|
|
|
|
AdditionalPackageFiles,
|
|
|
|
ArtifactError,
|
|
|
|
DetermineLockFileDirsResult,
|
|
|
|
WriteExistingFilesResult,
|
2022-08-05 07:49:58 +00:00
|
|
|
YarnRcYmlFile,
|
2021-05-11 17:08:02 +00:00
|
|
|
} from './types';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as yarn from './yarn';
|
2017-08-26 14:10:18 +00:00
|
|
|
|
2018-05-09 06:03:59 +00:00
|
|
|
// Strips empty values, deduplicates, and returns the directories from filenames
|
2022-04-20 06:40:20 +00:00
|
|
|
const getDirs = (arr: (string | null | undefined)[]): string[] =>
|
|
|
|
Array.from(new Set(arr.filter(is.string)));
|
2017-08-26 14:10:18 +00:00
|
|
|
|
2019-07-25 06:17:19 +00:00
|
|
|
export function determineLockFileDirs(
|
|
|
|
config: PostUpdateConfig,
|
2023-11-07 15:50:29 +00:00
|
|
|
packageFiles: AdditionalPackageFiles,
|
2019-07-25 06:17:19 +00:00
|
|
|
): DetermineLockFileDirsResult {
|
2022-04-20 06:40:20 +00:00
|
|
|
const npmLockDirs: (string | undefined)[] = [];
|
|
|
|
const yarnLockDirs: (string | undefined)[] = [];
|
|
|
|
const pnpmShrinkwrapDirs: (string | undefined)[] = [];
|
2017-08-26 14:10:18 +00:00
|
|
|
|
|
|
|
for (const upgrade of config.upgrades) {
|
2021-03-01 14:35:13 +00:00
|
|
|
if (upgrade.updateType === 'lockFileMaintenance' || upgrade.isRemediation) {
|
2023-10-05 07:12:34 +00:00
|
|
|
yarnLockDirs.push(upgrade.managerData?.yarnLock);
|
|
|
|
npmLockDirs.push(upgrade.managerData?.npmLock);
|
|
|
|
pnpmShrinkwrapDirs.push(upgrade.managerData?.pnpmShrinkwrap);
|
2021-11-08 19:20:03 +00:00
|
|
|
continue;
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
2019-01-24 05:23:08 +00:00
|
|
|
if (upgrade.isLockfileUpdate) {
|
2023-02-18 15:06:03 +00:00
|
|
|
yarnLockDirs.push(upgrade.managerData?.yarnLock);
|
|
|
|
npmLockDirs.push(upgrade.managerData?.npmLock);
|
2019-01-24 05:23:08 +00:00
|
|
|
}
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
|
|
|
|
2018-09-10 07:48:20 +00:00
|
|
|
if (
|
|
|
|
config.upgrades.every(
|
2019-07-25 06:17:19 +00:00
|
|
|
(upgrade: Upgrade) =>
|
2023-11-07 15:50:29 +00:00
|
|
|
upgrade.updateType === 'lockFileMaintenance' ||
|
|
|
|
upgrade.isLockfileUpdate,
|
2018-09-10 07:48:20 +00:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
return {
|
|
|
|
yarnLockDirs: getDirs(yarnLockDirs),
|
|
|
|
npmLockDirs: getDirs(npmLockDirs),
|
|
|
|
pnpmShrinkwrapDirs: getDirs(pnpmShrinkwrapDirs),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-18 15:06:03 +00:00
|
|
|
function getPackageFile(
|
2023-11-07 15:50:29 +00:00
|
|
|
fileName: string,
|
2023-02-20 14:58:49 +00:00
|
|
|
): Partial<PackageFile<NpmManagerData>> {
|
2018-05-09 06:03:59 +00:00
|
|
|
logger.trace('Looking for packageFile: ' + fileName);
|
2022-06-21 11:00:21 +00:00
|
|
|
|
2022-04-20 06:40:20 +00:00
|
|
|
for (const packageFile of packageFiles.npm!) {
|
2018-05-09 06:03:59 +00:00
|
|
|
if (packageFile.packageFile === fileName) {
|
|
|
|
logger.trace({ packageFile }, 'Found packageFile');
|
|
|
|
return packageFile;
|
|
|
|
}
|
|
|
|
logger.trace('No match');
|
2018-01-15 15:55:33 +00:00
|
|
|
}
|
2018-05-09 06:03:59 +00:00
|
|
|
return {};
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
|
|
|
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO #22198
|
2022-04-20 06:40:20 +00:00
|
|
|
for (const p of config.updatedPackageFiles!) {
|
2022-01-21 05:47:49 +00:00
|
|
|
logger.trace(`Checking ${String(p.path)} for lock files`);
|
|
|
|
const packageFile = getPackageFile(p.path);
|
2023-02-18 15:06:03 +00:00
|
|
|
// istanbul ignore if
|
|
|
|
if (!packageFile.managerData) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-09-27 12:29:07 +00:00
|
|
|
// push full lock file names and convert them later
|
|
|
|
yarnLockDirs.push(packageFile.managerData.yarnLock);
|
|
|
|
npmLockDirs.push(packageFile.managerData.npmLock);
|
|
|
|
pnpmShrinkwrapDirs.push(packageFile.managerData.pnpmShrinkwrap);
|
2017-08-27 06:17:34 +00:00
|
|
|
}
|
|
|
|
|
2018-02-05 19:06:24 +00:00
|
|
|
return {
|
2018-05-09 06:03:59 +00:00
|
|
|
yarnLockDirs: getDirs(yarnLockDirs),
|
|
|
|
npmLockDirs: getDirs(npmLockDirs),
|
|
|
|
pnpmShrinkwrapDirs: getDirs(pnpmShrinkwrapDirs),
|
2018-02-05 19:06:24 +00:00
|
|
|
};
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-25 06:17:19 +00:00
|
|
|
export async function writeExistingFiles(
|
|
|
|
config: PostUpdateConfig,
|
2023-11-07 15:50:29 +00:00
|
|
|
packageFiles: AdditionalPackageFiles,
|
2019-11-23 20:44:55 +00:00
|
|
|
): Promise<void> {
|
2018-05-09 06:03:59 +00:00
|
|
|
if (!packageFiles.npm) {
|
2017-08-26 14:10:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-09 06:03:59 +00:00
|
|
|
const npmFiles = packageFiles.npm;
|
2018-03-24 05:31:01 +00:00
|
|
|
logger.debug(
|
2020-04-12 16:09:36 +00:00
|
|
|
{ packageFiles: npmFiles.map((n) => n.packageFile) },
|
2023-11-07 15:50:29 +00:00
|
|
|
'Writing package.json files',
|
2018-03-24 05:31:01 +00:00
|
|
|
);
|
2018-02-09 05:55:47 +00:00
|
|
|
for (const packageFile of npmFiles) {
|
2023-02-18 15:06:03 +00:00
|
|
|
// istanbul ignore if
|
|
|
|
if (!packageFile.managerData) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO #22198
|
2022-06-21 11:00:21 +00:00
|
|
|
const basedir = upath.dirname(packageFile.packageFile!);
|
2023-01-20 11:43:49 +00:00
|
|
|
const npmrc = packageFile.npmrc;
|
2020-08-11 14:04:19 +00:00
|
|
|
const npmrcFilename = upath.join(basedir, '.npmrc');
|
2021-04-01 16:09:36 +00:00
|
|
|
if (is.string(npmrc)) {
|
2021-04-01 12:19:47 +00:00
|
|
|
try {
|
2022-04-25 13:41:10 +00:00
|
|
|
await writeLocalFile(npmrcFilename, `${npmrc}\n`);
|
2021-04-01 12:19:47 +00:00
|
|
|
} catch (err) /* istanbul ignore next */ {
|
|
|
|
logger.warn({ npmrcFilename, err }, 'Error writing .npmrc');
|
|
|
|
}
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
2023-02-18 15:06:03 +00:00
|
|
|
const npmLock = packageFile.managerData.npmLock;
|
2018-05-15 18:03:06 +00:00
|
|
|
if (npmLock) {
|
2022-04-25 13:41:10 +00:00
|
|
|
const npmLockPath = npmLock;
|
2018-07-04 17:20:34 +00:00
|
|
|
if (
|
|
|
|
process.env.RENOVATE_REUSE_PACKAGE_LOCK === 'false' ||
|
2018-07-05 10:02:53 +00:00
|
|
|
config.reuseLockFiles === false
|
2018-07-04 17:20:34 +00:00
|
|
|
) {
|
2018-05-15 18:52:25 +00:00
|
|
|
logger.debug(`Ensuring ${npmLock} is removed`);
|
2022-04-25 13:41:10 +00:00
|
|
|
await deleteLocalFile(npmLockPath);
|
2018-05-15 18:03:06 +00:00
|
|
|
} else {
|
|
|
|
logger.debug(`Writing ${npmLock}`);
|
2021-11-11 11:46:40 +00:00
|
|
|
let existingNpmLock: string;
|
|
|
|
try {
|
2022-04-20 06:40:20 +00:00
|
|
|
existingNpmLock = (await getFile(npmLock)) ?? '';
|
2022-04-25 13:41:10 +00:00
|
|
|
} catch (err) /* istanbul ignore next */ {
|
2022-03-22 03:48:25 +00:00
|
|
|
logger.warn({ err }, 'Error reading npm lock file');
|
2022-04-20 06:40:20 +00:00
|
|
|
existingNpmLock = '';
|
2021-11-11 11:46:40 +00:00
|
|
|
}
|
2022-03-22 03:48:25 +00:00
|
|
|
const { detectedIndent, lockFileParsed: npmLockParsed } =
|
|
|
|
parseLockFile(existingNpmLock);
|
2021-11-11 11:46:40 +00:00
|
|
|
if (npmLockParsed) {
|
2022-03-22 03:48:25 +00:00
|
|
|
const packageNames =
|
|
|
|
'packages' in npmLockParsed
|
|
|
|
? Object.keys(npmLockParsed.packages)
|
|
|
|
: [];
|
2022-04-20 06:40:20 +00:00
|
|
|
const widens: string[] = [];
|
2021-11-11 11:46:40 +00:00
|
|
|
let lockFileChanged = false;
|
|
|
|
for (const upgrade of config.upgrades) {
|
2022-08-18 17:08:51 +00:00
|
|
|
if (upgrade.lockFiles && !upgrade.lockFiles.includes(npmLock)) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-02-18 15:06:03 +00:00
|
|
|
if (!upgrade.managerData) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-11-08 14:20:16 +00:00
|
|
|
if (
|
2021-11-11 11:46:40 +00:00
|
|
|
upgrade.rangeStrategy === 'widen' &&
|
2023-02-18 15:06:03 +00:00
|
|
|
upgrade.managerData.npmLock === npmLock
|
2021-11-08 14:20:16 +00:00
|
|
|
) {
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO #22198
|
2022-04-20 06:40:20 +00:00
|
|
|
widens.push(upgrade.depName!);
|
2021-11-08 14:20:16 +00:00
|
|
|
}
|
2021-11-11 11:46:40 +00:00
|
|
|
const { depName } = upgrade;
|
|
|
|
for (const packageName of packageNames) {
|
|
|
|
if (
|
2022-03-22 03:48:25 +00:00
|
|
|
'packages' in npmLockParsed &&
|
|
|
|
(packageName === `node_modules/${depName}` ||
|
|
|
|
packageName.startsWith(`node_modules/${depName}/`))
|
2021-11-11 11:46:40 +00:00
|
|
|
) {
|
|
|
|
logger.trace({ packageName }, 'Massaging out package name');
|
|
|
|
lockFileChanged = true;
|
|
|
|
delete npmLockParsed.packages[packageName];
|
|
|
|
}
|
2018-10-17 10:33:49 +00:00
|
|
|
}
|
2021-11-11 11:46:40 +00:00
|
|
|
}
|
|
|
|
if (widens.length) {
|
|
|
|
logger.debug(
|
2023-11-07 15:50:29 +00:00
|
|
|
`Removing ${String(widens)} from ${npmLock} to force an update`,
|
2018-09-22 16:17:49 +00:00
|
|
|
);
|
2021-11-11 11:46:40 +00:00
|
|
|
lockFileChanged = true;
|
|
|
|
try {
|
2022-03-22 03:48:25 +00:00
|
|
|
if (
|
|
|
|
'dependencies' in npmLockParsed &&
|
|
|
|
npmLockParsed.dependencies
|
|
|
|
) {
|
2021-11-11 11:46:40 +00:00
|
|
|
widens.forEach((depName) => {
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO #22198
|
2022-04-20 06:40:20 +00:00
|
|
|
delete npmLockParsed.dependencies![depName];
|
2021-11-11 11:46:40 +00:00
|
|
|
});
|
|
|
|
}
|
2022-04-25 13:41:10 +00:00
|
|
|
} catch (err) /* istanbul ignore next */ {
|
2021-11-11 11:46:40 +00:00
|
|
|
logger.warn(
|
|
|
|
{ npmLock },
|
2023-11-07 15:50:29 +00:00
|
|
|
'Error massaging package-lock.json for widen',
|
2021-11-11 11:46:40 +00:00
|
|
|
);
|
|
|
|
}
|
2018-09-22 16:17:49 +00:00
|
|
|
}
|
2021-11-11 11:46:40 +00:00
|
|
|
if (lockFileChanged) {
|
|
|
|
logger.debug('Massaging npm lock file before writing to disk');
|
2022-03-22 03:48:25 +00:00
|
|
|
existingNpmLock = composeLockFile(npmLockParsed, detectedIndent);
|
2021-11-11 11:46:40 +00:00
|
|
|
}
|
2022-04-25 13:41:10 +00:00
|
|
|
await writeLocalFile(npmLockPath, existingNpmLock);
|
2018-09-22 16:17:49 +00:00
|
|
|
}
|
2018-05-15 18:03:06 +00:00
|
|
|
}
|
2018-03-08 08:39:32 +00:00
|
|
|
}
|
2023-02-18 15:06:03 +00:00
|
|
|
const { yarnLock } = packageFile.managerData;
|
2020-05-14 19:04:10 +00:00
|
|
|
if (yarnLock && config.reuseLockFiles === false) {
|
|
|
|
await deleteLocalFile(yarnLock);
|
2017-10-08 03:52:58 +00:00
|
|
|
}
|
2018-01-15 15:55:33 +00:00
|
|
|
// istanbul ignore next
|
2023-02-18 15:06:03 +00:00
|
|
|
if (
|
|
|
|
packageFile.managerData.pnpmShrinkwrap &&
|
|
|
|
config.reuseLockFiles === false
|
|
|
|
) {
|
|
|
|
await deleteLocalFile(packageFile.managerData.pnpmShrinkwrap);
|
2018-01-15 15:55:33 +00:00
|
|
|
}
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-23 20:44:55 +00:00
|
|
|
export async function writeUpdatedPackageFiles(
|
2023-11-07 15:50:29 +00:00
|
|
|
config: PostUpdateConfig,
|
2019-11-23 20:44:55 +00:00
|
|
|
): Promise<void> {
|
2017-08-26 14:10:18 +00:00
|
|
|
logger.trace({ config }, 'writeUpdatedPackageFiles');
|
|
|
|
logger.debug('Writing any updated package files');
|
|
|
|
if (!config.updatedPackageFiles) {
|
|
|
|
logger.debug('No files found');
|
|
|
|
return;
|
|
|
|
}
|
2022-04-14 17:05:42 +00:00
|
|
|
const supportedLockFiles = ['package-lock.json', 'yarn.lock'];
|
2017-08-26 14:10:18 +00:00
|
|
|
for (const packageFile of config.updatedPackageFiles) {
|
2022-01-21 05:47:49 +00:00
|
|
|
if (packageFile.type !== 'addition') {
|
|
|
|
continue;
|
|
|
|
}
|
2021-12-14 17:43:50 +00:00
|
|
|
if (
|
2022-01-21 05:47:49 +00:00
|
|
|
supportedLockFiles.some((fileName) => packageFile.path.endsWith(fileName))
|
2021-12-14 17:43:50 +00:00
|
|
|
) {
|
2022-01-21 05:47:49 +00:00
|
|
|
logger.debug(`Writing lock file: ${packageFile.path}`);
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO #22198
|
2022-06-21 11:00:21 +00:00
|
|
|
|
2022-06-20 16:15:40 +00:00
|
|
|
await writeLocalFile(packageFile.path, packageFile.contents!);
|
2021-11-08 19:20:03 +00:00
|
|
|
continue;
|
2021-03-01 14:35:13 +00:00
|
|
|
}
|
2022-01-21 05:47:49 +00:00
|
|
|
if (!packageFile.path.endsWith('package.json')) {
|
2021-11-08 19:20:03 +00:00
|
|
|
continue;
|
2017-09-14 20:10:51 +00:00
|
|
|
}
|
2022-01-21 05:47:49 +00:00
|
|
|
logger.debug(`Writing ${packageFile.path}`);
|
2023-08-22 12:20:37 +00:00
|
|
|
await writeLocalFile(packageFile.path, packageFile.contents!);
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 07:04:25 +00:00
|
|
|
async function getNpmrcContent(dir: string): Promise<string | null> {
|
|
|
|
const npmrcFilePath = upath.join(dir, '.npmrc');
|
2022-04-20 06:40:20 +00:00
|
|
|
let originalNpmrcContent: string | null = null;
|
2020-03-30 07:04:25 +00:00
|
|
|
try {
|
2022-04-25 13:41:10 +00:00
|
|
|
originalNpmrcContent = await readLocalFile(npmrcFilePath, 'utf8');
|
|
|
|
} catch /* istanbul ignore next */ {
|
2020-03-30 07:04:25 +00:00
|
|
|
originalNpmrcContent = null;
|
|
|
|
}
|
2023-09-04 15:43:24 +00:00
|
|
|
if (originalNpmrcContent) {
|
|
|
|
logger.debug(`npmrc file ${npmrcFilePath} found in repository`);
|
|
|
|
}
|
2020-03-30 07:04:25 +00:00
|
|
|
return originalNpmrcContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateNpmrcContent(
|
|
|
|
dir: string,
|
2022-04-20 06:40:20 +00:00
|
|
|
originalContent: string | null,
|
2023-11-07 15:50:29 +00:00
|
|
|
additionalLines: string[],
|
2020-03-30 07:04:25 +00:00
|
|
|
): Promise<void> {
|
|
|
|
const npmrcFilePath = upath.join(dir, '.npmrc');
|
|
|
|
const newNpmrc = originalContent
|
|
|
|
? [originalContent, ...additionalLines]
|
|
|
|
: additionalLines;
|
2021-04-01 12:19:47 +00:00
|
|
|
try {
|
|
|
|
const newContent = newNpmrc.join('\n');
|
|
|
|
if (newContent !== originalContent) {
|
|
|
|
logger.debug(`Writing updated .npmrc file to ${npmrcFilePath}`);
|
2022-04-25 13:41:10 +00:00
|
|
|
await writeLocalFile(npmrcFilePath, `${newContent}\n`);
|
2021-04-01 12:19:47 +00:00
|
|
|
}
|
2022-04-25 13:41:10 +00:00
|
|
|
} catch /* istanbul ignore next */ {
|
2021-04-01 12:19:47 +00:00
|
|
|
logger.warn('Unable to write custom npmrc file');
|
2020-03-30 07:04:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function resetNpmrcContent(
|
|
|
|
dir: string,
|
2023-11-07 15:50:29 +00:00
|
|
|
originalContent: string | null,
|
2020-03-30 07:04:25 +00:00
|
|
|
): Promise<void> {
|
|
|
|
const npmrcFilePath = upath.join(dir, '.npmrc');
|
|
|
|
if (originalContent) {
|
|
|
|
try {
|
2022-04-25 13:41:10 +00:00
|
|
|
await writeLocalFile(npmrcFilePath, originalContent);
|
|
|
|
} catch /* istanbul ignore next */ {
|
2020-03-30 07:04:25 +00:00
|
|
|
logger.warn('Unable to reset npmrc to original contents');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
2022-04-25 13:41:10 +00:00
|
|
|
await deleteLocalFile(npmrcFilePath);
|
|
|
|
} catch /* istanbul ignore next */ {
|
2020-03-30 07:04:25 +00:00
|
|
|
logger.warn('Unable to delete custom npmrc');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-19 21:12:30 +00:00
|
|
|
// istanbul ignore next
|
|
|
|
async function updateYarnOffline(
|
|
|
|
lockFileDir: string,
|
2023-11-07 15:50:29 +00:00
|
|
|
updatedArtifacts: FileChange[],
|
2020-10-19 21:12:30 +00:00
|
|
|
): Promise<void> {
|
|
|
|
try {
|
|
|
|
const resolvedPaths: string[] = [];
|
|
|
|
const yarnrcYml = await getFile(upath.join(lockFileDir, '.yarnrc.yml'));
|
|
|
|
const yarnrc = await getFile(upath.join(lockFileDir, '.yarnrc'));
|
|
|
|
|
|
|
|
// As .yarnrc.yml overrides .yarnrc in Yarn 1 (https://git.io/JUcco)
|
|
|
|
// both files may exist, so check for .yarnrc.yml first
|
|
|
|
if (yarnrcYml) {
|
|
|
|
// Yarn 2 (offline cache and zero-installs)
|
2021-08-29 12:59:58 +00:00
|
|
|
const paths = getZeroInstallPaths(yarnrcYml);
|
|
|
|
resolvedPaths.push(...paths.map((p) => upath.join(lockFileDir, p)));
|
2020-10-19 21:12:30 +00:00
|
|
|
} else if (yarnrc) {
|
|
|
|
// Yarn 1 (offline mirror)
|
|
|
|
const mirrorLine = yarnrc
|
2022-02-02 07:31:11 +00:00
|
|
|
.split(newlineRegex)
|
2020-10-19 21:12:30 +00:00
|
|
|
.find((line) => line.startsWith('yarn-offline-mirror '));
|
|
|
|
if (mirrorLine) {
|
2021-12-29 06:26:13 +00:00
|
|
|
const mirrorPath = ensureTrailingSlash(
|
2023-11-07 15:50:29 +00:00
|
|
|
mirrorLine.split(' ')[1].replace(regEx(/"/g), ''),
|
2021-12-29 06:26:13 +00:00
|
|
|
);
|
2020-10-19 21:12:30 +00:00
|
|
|
resolvedPaths.push(upath.join(lockFileDir, mirrorPath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.debug({ resolvedPaths }, 'updateYarnOffline resolvedPaths');
|
|
|
|
|
|
|
|
if (resolvedPaths.length) {
|
|
|
|
const status = await getRepoStatus();
|
|
|
|
for (const f of status.modified.concat(status.not_added)) {
|
|
|
|
if (resolvedPaths.some((p) => f.startsWith(p))) {
|
|
|
|
updatedArtifacts.push({
|
2022-01-21 05:47:49 +00:00
|
|
|
type: 'addition',
|
|
|
|
path: f,
|
2022-04-25 13:41:10 +00:00
|
|
|
contents: await readLocalFile(f),
|
2020-10-19 21:12:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const f of status.deleted || []) {
|
|
|
|
if (resolvedPaths.some((p) => f.startsWith(p))) {
|
2022-01-21 05:47:49 +00:00
|
|
|
updatedArtifacts.push({ type: 'deletion', path: f });
|
2020-10-19 21:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
logger.error({ err }, 'Error updating yarn offline packages');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 07:49:58 +00:00
|
|
|
// TODO: move to ./yarn.ts
|
2021-11-01 11:37:13 +00:00
|
|
|
// exported for testing
|
|
|
|
export async function updateYarnBinary(
|
|
|
|
lockFileDir: string,
|
2022-01-22 08:31:32 +00:00
|
|
|
updatedArtifacts: FileChange[],
|
2023-11-07 15:50:29 +00:00
|
|
|
existingYarnrcYmlContent: string | undefined | null,
|
2022-06-20 16:15:40 +00:00
|
|
|
): Promise<string | undefined | null> {
|
2021-11-01 11:37:13 +00:00
|
|
|
let yarnrcYml = existingYarnrcYmlContent;
|
|
|
|
try {
|
|
|
|
const yarnrcYmlFilename = upath.join(lockFileDir, '.yarnrc.yml');
|
2022-04-20 06:40:20 +00:00
|
|
|
yarnrcYml ||= (await getFile(yarnrcYmlFilename)) ?? undefined;
|
2021-11-01 11:37:13 +00:00
|
|
|
const newYarnrcYml = await readLocalFile(yarnrcYmlFilename, 'utf8');
|
|
|
|
if (!is.string(yarnrcYml) || !is.string(newYarnrcYml)) {
|
|
|
|
return existingYarnrcYmlContent;
|
|
|
|
}
|
|
|
|
|
2022-08-05 07:49:58 +00:00
|
|
|
const oldYarnPath = (load(yarnrcYml) as YarnRcYmlFile)?.yarnPath;
|
|
|
|
const newYarnPath = (load(newYarnrcYml) as YarnRcYmlFile)?.yarnPath;
|
|
|
|
if (
|
|
|
|
!is.nonEmptyStringAndNotWhitespace(oldYarnPath) ||
|
|
|
|
!is.nonEmptyStringAndNotWhitespace(newYarnPath)
|
|
|
|
) {
|
|
|
|
return existingYarnrcYmlContent;
|
|
|
|
}
|
|
|
|
|
2021-11-01 11:37:13 +00:00
|
|
|
const oldYarnFullPath = upath.join(lockFileDir, oldYarnPath);
|
|
|
|
const newYarnFullPath = upath.join(lockFileDir, newYarnPath);
|
|
|
|
logger.debug({ oldYarnPath, newYarnPath }, 'Found updated Yarn binary');
|
|
|
|
|
|
|
|
yarnrcYml = yarnrcYml.replace(oldYarnPath, newYarnPath);
|
|
|
|
updatedArtifacts.push(
|
|
|
|
{
|
2022-01-21 05:47:49 +00:00
|
|
|
type: 'addition',
|
|
|
|
path: yarnrcYmlFilename,
|
2021-11-01 11:37:13 +00:00
|
|
|
contents: yarnrcYml,
|
|
|
|
},
|
|
|
|
{
|
2022-01-21 05:47:49 +00:00
|
|
|
type: 'deletion',
|
|
|
|
path: oldYarnFullPath,
|
2021-11-01 11:37:13 +00:00
|
|
|
},
|
|
|
|
{
|
2022-01-21 05:47:49 +00:00
|
|
|
type: 'addition',
|
|
|
|
path: newYarnFullPath,
|
2021-11-01 11:37:13 +00:00
|
|
|
contents: await readLocalFile(newYarnFullPath, 'utf8'),
|
2022-01-21 05:47:49 +00:00
|
|
|
isExecutable: true,
|
2023-11-07 15:50:29 +00:00
|
|
|
},
|
2021-11-01 11:37:13 +00:00
|
|
|
);
|
|
|
|
} catch (err) /* istanbul ignore next */ {
|
|
|
|
logger.error({ err }, 'Error updating Yarn binary');
|
|
|
|
}
|
|
|
|
return existingYarnrcYmlContent && yarnrcYml;
|
|
|
|
}
|
|
|
|
|
2019-07-25 06:17:19 +00:00
|
|
|
export async function getAdditionalFiles(
|
2022-05-04 06:32:15 +00:00
|
|
|
config: PostUpdateConfig<NpmManagerData>,
|
2023-11-07 15:50:29 +00:00
|
|
|
packageFiles: AdditionalPackageFiles,
|
2019-07-25 06:17:19 +00:00
|
|
|
): Promise<WriteExistingFilesResult> {
|
2018-05-09 06:03:59 +00:00
|
|
|
logger.trace({ config }, 'getAdditionalFiles');
|
2019-07-25 06:17:19 +00:00
|
|
|
const artifactErrors: ArtifactError[] = [];
|
2022-01-22 08:31:32 +00:00
|
|
|
const updatedArtifacts: FileChange[] = [];
|
2020-08-10 14:18:08 +00:00
|
|
|
if (!packageFiles.npm?.length) {
|
2019-02-08 13:31:30 +00:00
|
|
|
return { artifactErrors, updatedArtifacts };
|
2018-05-11 05:23:26 +00:00
|
|
|
}
|
2018-03-22 09:41:26 +00:00
|
|
|
if (!config.updateLockFiles) {
|
2020-02-24 07:43:01 +00:00
|
|
|
logger.debug('Skipping lock file generation');
|
2019-02-08 13:31:30 +00:00
|
|
|
return { artifactErrors, updatedArtifacts };
|
2018-03-22 09:41:26 +00:00
|
|
|
}
|
2021-03-02 21:07:33 +00:00
|
|
|
if (
|
|
|
|
!config.updatedPackageFiles?.length &&
|
2021-05-15 10:13:19 +00:00
|
|
|
config.transitiveRemediation &&
|
|
|
|
config.upgrades?.every(
|
2023-11-07 15:50:29 +00:00
|
|
|
(upgrade) => upgrade.isRemediation ?? upgrade.isVulnerabilityAlert,
|
2021-05-15 10:13:19 +00:00
|
|
|
)
|
2021-03-02 21:07:33 +00:00
|
|
|
) {
|
|
|
|
logger.debug('Skipping lock file generation for remediations');
|
|
|
|
return { artifactErrors, updatedArtifacts };
|
|
|
|
}
|
2021-12-20 05:30:24 +00:00
|
|
|
if (
|
|
|
|
config.reuseExistingBranch &&
|
|
|
|
!config.updatedPackageFiles?.length &&
|
|
|
|
config.upgrades?.every((upgrade) => upgrade.isLockfileUpdate)
|
|
|
|
) {
|
|
|
|
logger.debug('Existing branch contains all necessary lock file updates');
|
|
|
|
return { artifactErrors, updatedArtifacts };
|
|
|
|
}
|
2018-05-11 05:23:26 +00:00
|
|
|
logger.debug('Getting updated lock files');
|
2017-10-19 12:05:10 +00:00
|
|
|
if (
|
2018-07-04 08:11:53 +00:00
|
|
|
config.updateType === 'lockFileMaintenance' &&
|
2020-05-15 10:45:03 +00:00
|
|
|
config.reuseExistingBranch &&
|
2023-02-22 08:18:53 +00:00
|
|
|
(await scm.branchExists(config.branchName))
|
2017-10-19 12:05:10 +00:00
|
|
|
) {
|
2018-03-16 05:28:46 +00:00
|
|
|
logger.debug('Skipping lockFileMaintenance update');
|
2019-02-08 13:31:30 +00:00
|
|
|
return { artifactErrors, updatedArtifacts };
|
2017-10-19 12:05:10 +00:00
|
|
|
}
|
2019-07-25 06:17:19 +00:00
|
|
|
const dirs = determineLockFileDirs(config, packageFiles);
|
2021-02-24 14:18:43 +00:00
|
|
|
logger.trace({ dirs }, 'lock file dirs');
|
2019-07-25 06:17:19 +00:00
|
|
|
await writeExistingFiles(config, packageFiles);
|
|
|
|
await writeUpdatedPackageFiles(config);
|
2017-08-26 14:10:18 +00:00
|
|
|
|
2021-05-21 20:20:23 +00:00
|
|
|
const { additionalNpmrcContent, additionalYarnRcYml } = processHostRules();
|
2020-03-30 07:04:25 +00:00
|
|
|
|
2021-08-13 11:49:49 +00:00
|
|
|
const env = {
|
|
|
|
...getChildProcessEnv(),
|
|
|
|
NPM_CONFIG_CACHE: await ensureCacheDir('npm'),
|
|
|
|
YARN_CACHE_FOLDER: await ensureCacheDir('yarn'),
|
|
|
|
YARN_GLOBAL_FOLDER: await ensureCacheDir('berry'),
|
|
|
|
npm_config_store: await ensureCacheDir('pnpm'),
|
|
|
|
NODE_ENV: 'dev',
|
|
|
|
};
|
2018-01-25 09:38:30 +00:00
|
|
|
|
2022-04-21 14:25:44 +00:00
|
|
|
let token: string | undefined;
|
2018-09-17 09:18:18 +00:00
|
|
|
try {
|
2022-04-21 14:25:44 +00:00
|
|
|
({ token } = hostRules.find({
|
2022-06-03 04:43:58 +00:00
|
|
|
hostType: 'github',
|
2019-05-24 15:40:39 +00:00
|
|
|
url: 'https://api.github.com/',
|
|
|
|
}));
|
2022-04-25 13:41:10 +00:00
|
|
|
token = token ? /* istanbul ignore next */ `${token}@` : token;
|
|
|
|
} catch (err) /* istanbul ignore next */ {
|
2018-09-17 09:18:18 +00:00
|
|
|
logger.warn({ err }, 'Error getting token for packageFile');
|
|
|
|
}
|
2022-04-21 14:25:44 +00:00
|
|
|
const tokenRe = regEx(`${token ?? ''}`, 'g', false);
|
2021-03-19 15:10:58 +00:00
|
|
|
for (const npmLock of dirs.npmLockDirs) {
|
|
|
|
const lockFileDir = upath.dirname(npmLock);
|
2022-04-25 13:41:10 +00:00
|
|
|
const npmrcContent = await getNpmrcContent(lockFileDir);
|
|
|
|
await updateNpmrcContent(lockFileDir, npmrcContent, additionalNpmrcContent);
|
2021-03-19 15:10:58 +00:00
|
|
|
const fileName = upath.basename(npmLock);
|
2018-05-09 08:42:38 +00:00
|
|
|
logger.debug(`Generating ${fileName} for ${lockFileDir}`);
|
2019-01-24 05:23:08 +00:00
|
|
|
const upgrades = config.upgrades.filter(
|
2023-11-07 15:50:29 +00:00
|
|
|
(upgrade) => upgrade.managerData?.npmLock === npmLock,
|
2019-01-24 05:23:08 +00:00
|
|
|
);
|
2017-10-19 12:05:10 +00:00
|
|
|
const res = await npm.generateLockFile(
|
2022-04-25 13:41:10 +00:00
|
|
|
lockFileDir,
|
2018-03-08 08:39:32 +00:00
|
|
|
env,
|
2018-08-15 15:13:07 +00:00
|
|
|
fileName,
|
2019-03-07 15:37:07 +00:00
|
|
|
config,
|
2023-11-07 15:50:29 +00:00
|
|
|
upgrades,
|
2017-10-19 12:05:10 +00:00
|
|
|
);
|
|
|
|
if (res.error) {
|
2018-03-21 10:17:54 +00:00
|
|
|
// istanbul ignore if
|
2020-08-10 14:18:08 +00:00
|
|
|
if (res.stderr?.includes('No matching version found for')) {
|
2018-03-21 10:17:54 +00:00
|
|
|
for (const upgrade of config.upgrades) {
|
|
|
|
if (
|
|
|
|
res.stderr.includes(
|
2023-11-07 15:50:29 +00:00
|
|
|
`No matching version found for ${upgrade.depName}`,
|
2018-03-21 10:17:54 +00:00
|
|
|
)
|
|
|
|
) {
|
2020-02-24 07:43:01 +00:00
|
|
|
logger.debug(
|
2018-05-28 18:12:17 +00:00
|
|
|
{ dependency: upgrade.depName, type: 'npm' },
|
2023-11-07 15:50:29 +00:00
|
|
|
'lock file failed for the dependency being updated - skipping branch creation',
|
2018-03-21 10:17:54 +00:00
|
|
|
);
|
2020-02-14 08:19:45 +00:00
|
|
|
const err = new Error(
|
2023-11-07 15:50:29 +00:00
|
|
|
'lock file failed for the dependency being updated - skipping branch creation',
|
2020-02-14 08:19:45 +00:00
|
|
|
);
|
2022-02-15 08:20:45 +00:00
|
|
|
throw new ExternalHostError(err, NpmDatasource.id);
|
2018-03-21 10:17:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-08 13:31:30 +00:00
|
|
|
artifactErrors.push({
|
2021-03-19 15:10:58 +00:00
|
|
|
lockFile: npmLock,
|
2018-07-14 05:50:37 +00:00
|
|
|
stderr: res.stderr,
|
|
|
|
});
|
2023-09-06 09:37:03 +00:00
|
|
|
} else if (res.lockFile) {
|
2020-07-04 12:28:49 +00:00
|
|
|
const existingContent = await getFile(
|
2021-03-19 15:10:58 +00:00
|
|
|
npmLock,
|
2023-11-07 15:50:29 +00:00
|
|
|
config.reuseExistingBranch ? config.branchName : config.baseBranch,
|
2017-08-26 14:10:18 +00:00
|
|
|
);
|
2021-03-04 05:21:55 +00:00
|
|
|
if (res.lockFile === existingContent) {
|
2021-03-19 15:10:58 +00:00
|
|
|
logger.debug(`${npmLock} hasn't changed`);
|
2021-03-04 05:21:55 +00:00
|
|
|
} else {
|
2021-03-19 15:10:58 +00:00
|
|
|
logger.debug(`${npmLock} needs updating`);
|
2019-02-08 13:31:30 +00:00
|
|
|
updatedArtifacts.push({
|
2022-01-21 05:47:49 +00:00
|
|
|
type: 'addition',
|
|
|
|
path: npmLock,
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO: can this be undefined? (#22198)
|
2022-06-21 11:00:21 +00:00
|
|
|
|
2023-09-06 09:37:03 +00:00
|
|
|
contents: res.lockFile.replace(tokenRe, ''),
|
2017-10-19 12:05:10 +00:00
|
|
|
});
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-25 13:41:10 +00:00
|
|
|
await resetNpmrcContent(lockFileDir, npmrcContent);
|
2017-10-19 12:05:10 +00:00
|
|
|
}
|
2017-08-26 14:10:18 +00:00
|
|
|
|
2021-03-19 15:10:58 +00:00
|
|
|
for (const yarnLock of dirs.yarnLockDirs) {
|
|
|
|
const lockFileDir = upath.dirname(yarnLock);
|
2022-04-25 13:41:10 +00:00
|
|
|
const npmrcContent = await getNpmrcContent(lockFileDir);
|
|
|
|
await updateNpmrcContent(lockFileDir, npmrcContent, additionalNpmrcContent);
|
2022-04-20 06:40:20 +00:00
|
|
|
let yarnRcYmlFilename: string | undefined;
|
2022-06-20 16:15:40 +00:00
|
|
|
let existingYarnrcYmlContent: string | undefined | null;
|
2022-04-25 13:41:10 +00:00
|
|
|
// istanbul ignore if: needs test
|
2021-05-21 20:20:23 +00:00
|
|
|
if (additionalYarnRcYml) {
|
|
|
|
yarnRcYmlFilename = getSiblingFileName(yarnLock, '.yarnrc.yml');
|
|
|
|
existingYarnrcYmlContent = await readLocalFile(yarnRcYmlFilename, 'utf8');
|
|
|
|
if (existingYarnrcYmlContent) {
|
|
|
|
try {
|
2021-05-26 13:01:09 +00:00
|
|
|
const existingYarnrRcYml = load(existingYarnrcYmlContent) as Record<
|
|
|
|
string,
|
|
|
|
unknown
|
|
|
|
>;
|
2021-05-21 20:20:23 +00:00
|
|
|
const updatedYarnYrcYml = deepmerge(
|
|
|
|
existingYarnrRcYml,
|
2023-11-07 15:50:29 +00:00
|
|
|
additionalYarnRcYml,
|
2021-05-21 20:20:23 +00:00
|
|
|
);
|
2021-05-26 13:01:09 +00:00
|
|
|
await writeLocalFile(yarnRcYmlFilename, dump(updatedYarnYrcYml));
|
2021-05-21 20:20:23 +00:00
|
|
|
logger.debug('Added authentication to .yarnrc.yml');
|
|
|
|
} catch (err) {
|
|
|
|
logger.warn({ err }, 'Error appending .yarnrc.yml content');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-19 12:05:10 +00:00
|
|
|
logger.debug(`Generating yarn.lock for ${lockFileDir}`);
|
2017-11-24 06:50:49 +00:00
|
|
|
const lockFileName = upath.join(lockFileDir, 'yarn.lock');
|
2019-01-24 05:23:08 +00:00
|
|
|
const upgrades = config.upgrades.filter(
|
2023-11-07 15:50:29 +00:00
|
|
|
(upgrade) => upgrade.managerData?.yarnLock === yarnLock,
|
2019-01-24 05:23:08 +00:00
|
|
|
);
|
2022-04-25 13:41:10 +00:00
|
|
|
const res = await yarn.generateLockFile(lockFileDir, env, config, upgrades);
|
2017-10-19 12:05:10 +00:00
|
|
|
if (res.error) {
|
2018-03-21 10:17:54 +00:00
|
|
|
// istanbul ignore if
|
2020-08-10 14:18:08 +00:00
|
|
|
if (res.stderr?.includes(`Couldn't find any versions for`)) {
|
2018-03-21 10:17:54 +00:00
|
|
|
for (const upgrade of config.upgrades) {
|
|
|
|
/* eslint-disable no-useless-escape */
|
|
|
|
if (
|
|
|
|
res.stderr.includes(
|
2023-11-07 15:50:29 +00:00
|
|
|
`Couldn't find any versions for \\\"${upgrade.depName}\\\"`,
|
2018-03-21 10:17:54 +00:00
|
|
|
)
|
|
|
|
) {
|
2020-02-24 07:43:01 +00:00
|
|
|
logger.debug(
|
2018-05-28 18:12:17 +00:00
|
|
|
{ dependency: upgrade.depName, type: 'yarn' },
|
2023-11-07 15:50:29 +00:00
|
|
|
'lock file failed for the dependency being updated - skipping branch creation',
|
2018-03-21 10:17:54 +00:00
|
|
|
);
|
2020-06-22 19:28:02 +00:00
|
|
|
throw new ExternalHostError(
|
2020-02-14 08:19:45 +00:00
|
|
|
new Error(
|
2023-11-07 15:50:29 +00:00
|
|
|
'lock file failed for the dependency being updated - skipping branch creation',
|
2020-06-22 19:28:02 +00:00
|
|
|
),
|
2023-11-07 15:50:29 +00:00
|
|
|
NpmDatasource.id,
|
2020-02-14 08:19:45 +00:00
|
|
|
);
|
2018-03-21 10:17:54 +00:00
|
|
|
}
|
|
|
|
/* eslint-enable no-useless-escape */
|
|
|
|
}
|
|
|
|
}
|
2019-02-08 13:31:30 +00:00
|
|
|
artifactErrors.push({
|
2021-03-19 15:10:58 +00:00
|
|
|
lockFile: yarnLock,
|
2022-06-21 11:00:21 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
2021-11-05 05:21:29 +00:00
|
|
|
stderr: res.stderr || res.stdout,
|
2018-07-14 05:50:37 +00:00
|
|
|
});
|
2017-10-19 12:05:10 +00:00
|
|
|
} else {
|
2020-07-04 12:28:49 +00:00
|
|
|
const existingContent = await getFile(
|
2017-10-19 12:05:10 +00:00
|
|
|
lockFileName,
|
2023-11-07 15:50:29 +00:00
|
|
|
config.reuseExistingBranch ? config.branchName : config.baseBranch,
|
2017-08-26 14:10:18 +00:00
|
|
|
);
|
2021-03-04 05:21:55 +00:00
|
|
|
if (res.lockFile === existingContent) {
|
|
|
|
logger.debug("yarn.lock hasn't changed");
|
|
|
|
} else {
|
2017-10-19 12:05:10 +00:00
|
|
|
logger.debug('yarn.lock needs updating');
|
2019-02-08 13:31:30 +00:00
|
|
|
updatedArtifacts.push({
|
2022-01-21 05:47:49 +00:00
|
|
|
type: 'addition',
|
|
|
|
path: lockFileName,
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO #22198
|
2022-04-20 06:40:20 +00:00
|
|
|
contents: res.lockFile!,
|
2017-10-19 12:05:10 +00:00
|
|
|
});
|
2022-04-25 13:41:10 +00:00
|
|
|
await updateYarnOffline(lockFileDir, updatedArtifacts);
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
2021-11-01 11:37:13 +00:00
|
|
|
|
2022-04-25 13:41:10 +00:00
|
|
|
// istanbul ignore if: already tested seperately, needs additional test?
|
2021-11-01 11:37:13 +00:00
|
|
|
if (upgrades.some(yarn.isYarnUpdate)) {
|
|
|
|
existingYarnrcYmlContent = await updateYarnBinary(
|
|
|
|
lockFileDir,
|
|
|
|
updatedArtifacts,
|
2023-11-07 15:50:29 +00:00
|
|
|
existingYarnrcYmlContent,
|
2021-11-01 11:37:13 +00:00
|
|
|
);
|
|
|
|
}
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
2022-04-25 13:41:10 +00:00
|
|
|
await resetNpmrcContent(lockFileDir, npmrcContent);
|
|
|
|
// istanbul ignore if: needs test
|
2021-05-21 20:20:23 +00:00
|
|
|
if (existingYarnrcYmlContent) {
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO #22198
|
2022-04-20 06:40:20 +00:00
|
|
|
await writeLocalFile(yarnRcYmlFilename!, existingYarnrcYmlContent);
|
2021-05-21 20:20:23 +00:00
|
|
|
}
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|
2018-01-15 15:55:33 +00:00
|
|
|
|
2021-03-19 15:10:58 +00:00
|
|
|
for (const pnpmShrinkwrap of dirs.pnpmShrinkwrapDirs) {
|
|
|
|
const lockFileDir = upath.dirname(pnpmShrinkwrap);
|
2022-04-25 13:41:10 +00:00
|
|
|
const npmrcContent = await getNpmrcContent(lockFileDir);
|
|
|
|
await updateNpmrcContent(lockFileDir, npmrcContent, additionalNpmrcContent);
|
2019-04-26 11:35:37 +00:00
|
|
|
logger.debug(`Generating pnpm-lock.yaml for ${lockFileDir}`);
|
2020-06-03 10:28:37 +00:00
|
|
|
const upgrades = config.upgrades.filter(
|
2023-11-07 15:50:29 +00:00
|
|
|
(upgrade) => upgrade.managerData?.pnpmShrinkwrap === pnpmShrinkwrap,
|
2020-06-03 10:28:37 +00:00
|
|
|
);
|
2022-04-25 13:41:10 +00:00
|
|
|
const res = await pnpm.generateLockFile(lockFileDir, env, config, upgrades);
|
2018-01-15 15:55:33 +00:00
|
|
|
if (res.error) {
|
2018-03-21 10:17:54 +00:00
|
|
|
// istanbul ignore if
|
2020-08-10 14:18:08 +00:00
|
|
|
if (res.stdout?.includes(`No compatible version found:`)) {
|
2018-03-21 10:17:54 +00:00
|
|
|
for (const upgrade of config.upgrades) {
|
|
|
|
if (
|
|
|
|
res.stdout.includes(
|
2023-11-07 15:50:29 +00:00
|
|
|
`No compatible version found: ${upgrade.depName}`,
|
2018-03-21 10:17:54 +00:00
|
|
|
)
|
|
|
|
) {
|
2020-02-24 07:43:01 +00:00
|
|
|
logger.debug(
|
2018-05-28 18:12:17 +00:00
|
|
|
{ dependency: upgrade.depName, type: 'pnpm' },
|
2023-11-07 15:50:29 +00:00
|
|
|
'lock file failed for the dependency being updated - skipping branch creation',
|
2018-03-21 10:17:54 +00:00
|
|
|
);
|
2020-06-22 19:28:02 +00:00
|
|
|
throw new ExternalHostError(
|
2020-02-14 08:19:45 +00:00
|
|
|
Error(
|
2023-11-07 15:50:29 +00:00
|
|
|
'lock file failed for the dependency being updated - skipping branch creation',
|
2020-06-22 19:28:02 +00:00
|
|
|
),
|
2023-11-07 15:50:29 +00:00
|
|
|
NpmDatasource.id,
|
2020-02-14 08:19:45 +00:00
|
|
|
);
|
2018-03-21 10:17:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-08 13:31:30 +00:00
|
|
|
artifactErrors.push({
|
2021-03-19 15:10:58 +00:00
|
|
|
lockFile: pnpmShrinkwrap,
|
2022-06-21 11:00:21 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
2021-06-02 06:40:54 +00:00
|
|
|
stderr: res.stderr || res.stdout,
|
2018-07-14 05:50:37 +00:00
|
|
|
});
|
2018-01-15 15:55:33 +00:00
|
|
|
} else {
|
2020-07-04 12:28:49 +00:00
|
|
|
const existingContent = await getFile(
|
2021-03-19 15:10:58 +00:00
|
|
|
pnpmShrinkwrap,
|
2023-11-07 15:50:29 +00:00
|
|
|
config.reuseExistingBranch ? config.branchName : config.baseBranch,
|
2018-01-15 15:55:33 +00:00
|
|
|
);
|
2021-03-04 05:21:55 +00:00
|
|
|
if (res.lockFile === existingContent) {
|
|
|
|
logger.debug("pnpm-lock.yaml hasn't changed");
|
|
|
|
} else {
|
2019-04-26 11:35:37 +00:00
|
|
|
logger.debug('pnpm-lock.yaml needs updating');
|
2019-02-08 13:31:30 +00:00
|
|
|
updatedArtifacts.push({
|
2022-01-21 05:47:49 +00:00
|
|
|
type: 'addition',
|
|
|
|
path: pnpmShrinkwrap,
|
2023-08-15 09:31:15 +00:00
|
|
|
// TODO: can be undefined? (#22198)
|
2022-04-20 06:40:20 +00:00
|
|
|
contents: res.lockFile!,
|
2018-01-15 15:55:33 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-04-25 13:41:10 +00:00
|
|
|
await resetNpmrcContent(lockFileDir, npmrcContent);
|
2018-01-15 15:55:33 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:31:30 +00:00
|
|
|
return { artifactErrors, updatedArtifacts };
|
2017-08-26 14:10:18 +00:00
|
|
|
}
|