mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
refactor: Import from 'fs-extra' explicitly (#6673)
This commit is contained in:
parent
807d48e07d
commit
78e319f0fc
3 changed files with 33 additions and 26 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import * as fs from 'fs-extra';
|
import { stat } from 'fs-extra';
|
||||||
import Git from 'simple-git/promise';
|
import Git from 'simple-git/promise';
|
||||||
import { logger } from '../../logger';
|
import { logger } from '../../logger';
|
||||||
import { platform } from '../../platform';
|
import { platform } from '../../platform';
|
||||||
|
@ -57,7 +57,7 @@ export async function updateArtifacts({
|
||||||
let cmd = await prepareGradleCommand(
|
let cmd = await prepareGradleCommand(
|
||||||
gradlew,
|
gradlew,
|
||||||
projectDir,
|
projectDir,
|
||||||
await fs.stat(gradlewPath).catch(() => null),
|
await stat(gradlewPath).catch(() => null),
|
||||||
`wrapper`
|
`wrapper`
|
||||||
);
|
);
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Stats } from 'fs';
|
import { Stats } from 'fs';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as fs from 'fs-extra';
|
import { chmod, stat } from 'fs-extra';
|
||||||
import upath from 'upath';
|
import upath from 'upath';
|
||||||
import { LANGUAGE_JAVA } from '../../constants/languages';
|
import { LANGUAGE_JAVA } from '../../constants/languages';
|
||||||
import * as datasourceMaven from '../../datasource/maven';
|
import * as datasourceMaven from '../../datasource/maven';
|
||||||
|
@ -53,7 +53,7 @@ export async function prepareGradleCommand(
|
||||||
// if the file is not executable by others
|
// if the file is not executable by others
|
||||||
if ((gradlew.mode & 0o1) === 0) {
|
if ((gradlew.mode & 0o1) === 0) {
|
||||||
// add the execution permission to the owner, group and others
|
// add the execution permission to the owner, group and others
|
||||||
await fs.chmod(upath.join(cwd, gradlewName), gradlew.mode | 0o111);
|
await chmod(upath.join(cwd, gradlewName), gradlew.mode | 0o111);
|
||||||
}
|
}
|
||||||
if (args === null) {
|
if (args === null) {
|
||||||
return gradlewName;
|
return gradlewName;
|
||||||
|
@ -124,9 +124,9 @@ export async function extractAllPackageFiles(
|
||||||
for (const packageFile of packageFiles) {
|
for (const packageFile of packageFiles) {
|
||||||
const dirname = upath.dirname(packageFile);
|
const dirname = upath.dirname(packageFile);
|
||||||
const gradlewPath = upath.join(dirname, gradleWrapperFileName(config));
|
const gradlewPath = upath.join(dirname, gradleWrapperFileName(config));
|
||||||
gradlew = await fs
|
gradlew = await stat(upath.join(config.localDir, gradlewPath)).catch(
|
||||||
.stat(upath.join(config.localDir, gradlewPath))
|
() => null
|
||||||
.catch(() => null);
|
);
|
||||||
|
|
||||||
if (['build.gradle', 'build.gradle.kts'].includes(packageFile)) {
|
if (['build.gradle', 'build.gradle.kts'].includes(packageFile)) {
|
||||||
rootBuildGradle = packageFile;
|
rootBuildGradle = packageFile;
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import {
|
||||||
|
ensureDir,
|
||||||
|
outputFile,
|
||||||
|
readFile,
|
||||||
|
remove,
|
||||||
|
unlink,
|
||||||
|
writeFile,
|
||||||
|
} from 'fs-extra';
|
||||||
import upath from 'upath';
|
import upath from 'upath';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
|
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
|
||||||
|
@ -118,14 +125,14 @@ export async function writeExistingFiles(
|
||||||
const npmrcFile = upath.join(config.localDir, '.npmrc');
|
const npmrcFile = upath.join(config.localDir, '.npmrc');
|
||||||
if (config.npmrc) {
|
if (config.npmrc) {
|
||||||
logger.debug(`Writing repo .npmrc (${config.localDir})`);
|
logger.debug(`Writing repo .npmrc (${config.localDir})`);
|
||||||
await fs.outputFile(npmrcFile, config.npmrc);
|
await outputFile(npmrcFile, config.npmrc);
|
||||||
} else if (config.ignoreNpmrcFile) {
|
} else if (config.ignoreNpmrcFile) {
|
||||||
logger.debug('Removing ignored .npmrc file before artifact generation');
|
logger.debug('Removing ignored .npmrc file before artifact generation');
|
||||||
await fs.remove(npmrcFile);
|
await remove(npmrcFile);
|
||||||
}
|
}
|
||||||
if (config.yarnrc) {
|
if (config.yarnrc) {
|
||||||
logger.debug(`Writing repo .yarnrc (${config.localDir})`);
|
logger.debug(`Writing repo .yarnrc (${config.localDir})`);
|
||||||
await fs.outputFile(upath.join(config.localDir, '.yarnrc'), config.yarnrc);
|
await outputFile(upath.join(config.localDir, '.yarnrc'), config.yarnrc);
|
||||||
}
|
}
|
||||||
if (!packageFiles.npm) {
|
if (!packageFiles.npm) {
|
||||||
return;
|
return;
|
||||||
|
@ -142,11 +149,11 @@ export async function writeExistingFiles(
|
||||||
);
|
);
|
||||||
const npmrc = packageFile.npmrc || config.npmrc;
|
const npmrc = packageFile.npmrc || config.npmrc;
|
||||||
if (npmrc) {
|
if (npmrc) {
|
||||||
await fs.outputFile(upath.join(basedir, '.npmrc'), npmrc);
|
await outputFile(upath.join(basedir, '.npmrc'), npmrc);
|
||||||
}
|
}
|
||||||
if (packageFile.yarnrc) {
|
if (packageFile.yarnrc) {
|
||||||
logger.debug(`Writing .yarnrc to ${basedir}`);
|
logger.debug(`Writing .yarnrc to ${basedir}`);
|
||||||
await fs.outputFile(
|
await outputFile(
|
||||||
upath.join(basedir, '.yarnrc'),
|
upath.join(basedir, '.yarnrc'),
|
||||||
packageFile.yarnrc
|
packageFile.yarnrc
|
||||||
.replace('--install.pure-lockfile true', '')
|
.replace('--install.pure-lockfile true', '')
|
||||||
|
@ -161,7 +168,7 @@ export async function writeExistingFiles(
|
||||||
config.reuseLockFiles === false
|
config.reuseLockFiles === false
|
||||||
) {
|
) {
|
||||||
logger.debug(`Ensuring ${npmLock} is removed`);
|
logger.debug(`Ensuring ${npmLock} is removed`);
|
||||||
await fs.remove(npmLockPath);
|
await remove(npmLockPath);
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`Writing ${npmLock}`);
|
logger.debug(`Writing ${npmLock}`);
|
||||||
let existingNpmLock = await platform.getFile(npmLock);
|
let existingNpmLock = await platform.getFile(npmLock);
|
||||||
|
@ -191,7 +198,7 @@ export async function writeExistingFiles(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await fs.outputFile(npmLockPath, existingNpmLock);
|
await outputFile(npmLockPath, existingNpmLock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const { yarnLock } = packageFile;
|
const { yarnLock } = packageFile;
|
||||||
|
@ -239,7 +246,7 @@ export async function writeUpdatedPackageFiles(
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn({ err }, 'Error adding token to package files');
|
logger.warn({ err }, 'Error adding token to package files');
|
||||||
}
|
}
|
||||||
await fs.outputFile(
|
await outputFile(
|
||||||
upath.join(config.localDir, packageFile.name),
|
upath.join(config.localDir, packageFile.name),
|
||||||
JSON.stringify(massagedFile)
|
JSON.stringify(massagedFile)
|
||||||
);
|
);
|
||||||
|
@ -265,7 +272,7 @@ async function getNpmrcContent(dir: string): Promise<string | null> {
|
||||||
const npmrcFilePath = upath.join(dir, '.npmrc');
|
const npmrcFilePath = upath.join(dir, '.npmrc');
|
||||||
let originalNpmrcContent = null;
|
let originalNpmrcContent = null;
|
||||||
try {
|
try {
|
||||||
originalNpmrcContent = await fs.readFile(npmrcFilePath, 'utf8');
|
originalNpmrcContent = await readFile(npmrcFilePath, 'utf8');
|
||||||
logger.debug('npmrc file found in repository');
|
logger.debug('npmrc file found in repository');
|
||||||
} catch {
|
} catch {
|
||||||
logger.debug('No npmrc file found in repository');
|
logger.debug('No npmrc file found in repository');
|
||||||
|
@ -288,7 +295,7 @@ async function updateNpmrcContent(
|
||||||
try {
|
try {
|
||||||
const newContent = newNpmrc.join('\n');
|
const newContent = newNpmrc.join('\n');
|
||||||
if (newContent !== originalContent) {
|
if (newContent !== originalContent) {
|
||||||
await fs.writeFile(npmrcFilePath, newContent);
|
await writeFile(npmrcFilePath, newContent);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
logger.warn('Unable to write custom npmrc file');
|
logger.warn('Unable to write custom npmrc file');
|
||||||
|
@ -303,13 +310,13 @@ async function resetNpmrcContent(
|
||||||
const npmrcFilePath = upath.join(dir, '.npmrc');
|
const npmrcFilePath = upath.join(dir, '.npmrc');
|
||||||
if (originalContent) {
|
if (originalContent) {
|
||||||
try {
|
try {
|
||||||
await fs.writeFile(npmrcFilePath, originalContent);
|
await writeFile(npmrcFilePath, originalContent);
|
||||||
} catch {
|
} catch {
|
||||||
logger.warn('Unable to reset npmrc to original contents');
|
logger.warn('Unable to reset npmrc to original contents');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
await fs.unlink(npmrcFilePath);
|
await unlink(npmrcFilePath);
|
||||||
} catch {
|
} catch {
|
||||||
logger.warn('Unable to delete custom npmrc');
|
logger.warn('Unable to delete custom npmrc');
|
||||||
}
|
}
|
||||||
|
@ -377,13 +384,13 @@ export async function getAdditionalFiles(
|
||||||
]);
|
]);
|
||||||
env.NPM_CONFIG_CACHE =
|
env.NPM_CONFIG_CACHE =
|
||||||
env.NPM_CONFIG_CACHE || upath.join(config.cacheDir, './others/npm');
|
env.NPM_CONFIG_CACHE || upath.join(config.cacheDir, './others/npm');
|
||||||
await fs.ensureDir(env.NPM_CONFIG_CACHE);
|
await ensureDir(env.NPM_CONFIG_CACHE);
|
||||||
env.YARN_CACHE_FOLDER =
|
env.YARN_CACHE_FOLDER =
|
||||||
env.YARN_CACHE_FOLDER || upath.join(config.cacheDir, './others/yarn');
|
env.YARN_CACHE_FOLDER || upath.join(config.cacheDir, './others/yarn');
|
||||||
await fs.ensureDir(env.YARN_CACHE_FOLDER);
|
await ensureDir(env.YARN_CACHE_FOLDER);
|
||||||
env.npm_config_store =
|
env.npm_config_store =
|
||||||
env.npm_config_store || upath.join(config.cacheDir, './others/pnpm');
|
env.npm_config_store || upath.join(config.cacheDir, './others/pnpm');
|
||||||
await fs.ensureDir(env.npm_config_store);
|
await ensureDir(env.npm_config_store);
|
||||||
env.NODE_ENV = 'dev';
|
env.NODE_ENV = 'dev';
|
||||||
|
|
||||||
let token = '';
|
let token = '';
|
||||||
|
@ -540,7 +547,7 @@ export async function getAdditionalFiles(
|
||||||
const localModified = upath.join(config.localDir, f);
|
const localModified = upath.join(config.localDir, f);
|
||||||
updatedArtifacts.push({
|
updatedArtifacts.push({
|
||||||
name: f,
|
name: f,
|
||||||
contents: await fs.readFile(localModified),
|
contents: await readFile(localModified),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -719,9 +726,9 @@ export async function getAdditionalFiles(
|
||||||
try {
|
try {
|
||||||
let newContent: string;
|
let newContent: string;
|
||||||
try {
|
try {
|
||||||
newContent = await fs.readFile(lockFilePath, 'utf8');
|
newContent = await readFile(lockFilePath, 'utf8');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
newContent = await fs.readFile(
|
newContent = await readFile(
|
||||||
lockFilePath.replace(
|
lockFilePath.replace(
|
||||||
'npm-shrinkwrap.json',
|
'npm-shrinkwrap.json',
|
||||||
'package-lock.json'
|
'package-lock.json'
|
||||||
|
|
Loading…
Reference in a new issue