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

refactor: Import from 'fs-extra' explicitly #6673

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/manager/gradle-wrapper/artifacts.ts
@@ -1,5 +1,5 @@
import { resolve } from 'path';
import * as fs from 'fs-extra';
import { stat } from 'fs-extra';
import Git from 'simple-git/promise';
import { logger } from '../../logger';
import { platform } from '../../platform';
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function updateArtifacts({
let cmd = await prepareGradleCommand(
gradlew,
projectDir,
await fs.stat(gradlewPath).catch(() => null),
await stat(gradlewPath).catch(() => null),
`wrapper`
);
if (!cmd) {
Expand Down
10 changes: 5 additions & 5 deletions lib/manager/gradle/index.ts
@@ -1,6 +1,6 @@
import { Stats } from 'fs';
import * as os from 'os';
import * as fs from 'fs-extra';
import { chmod, stat } from 'fs-extra';
import upath from 'upath';
import { LANGUAGE_JAVA } from '../../constants/languages';
import * as datasourceMaven from '../../datasource/maven';
Expand Down Expand Up @@ -53,7 +53,7 @@ export async function prepareGradleCommand(
// if the file is not executable by others
if ((gradlew.mode & 0o1) === 0) {
// 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) {
return gradlewName;
Expand Down Expand Up @@ -124,9 +124,9 @@ export async function extractAllPackageFiles(
for (const packageFile of packageFiles) {
const dirname = upath.dirname(packageFile);
const gradlewPath = upath.join(dirname, gradleWrapperFileName(config));
gradlew = await fs
.stat(upath.join(config.localDir, gradlewPath))
.catch(() => null);
gradlew = await stat(upath.join(config.localDir, gradlewPath)).catch(
() => null
);

if (['build.gradle', 'build.gradle.kts'].includes(packageFile)) {
rootBuildGradle = packageFile;
Expand Down
45 changes: 26 additions & 19 deletions lib/manager/npm/post-update/index.ts
@@ -1,5 +1,12 @@
import path from 'path';
import fs from 'fs-extra';
import {
ensureDir,
outputFile,
readFile,
remove,
unlink,
writeFile,
} from 'fs-extra';
import upath from 'upath';
// eslint-disable-next-line import/no-unresolved
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
Expand Down Expand Up @@ -118,14 +125,14 @@ export async function writeExistingFiles(
const npmrcFile = upath.join(config.localDir, '.npmrc');
if (config.npmrc) {
logger.debug(`Writing repo .npmrc (${config.localDir})`);
await fs.outputFile(npmrcFile, config.npmrc);
await outputFile(npmrcFile, config.npmrc);
} else if (config.ignoreNpmrcFile) {
logger.debug('Removing ignored .npmrc file before artifact generation');
await fs.remove(npmrcFile);
await remove(npmrcFile);
}
if (config.yarnrc) {
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) {
return;
Expand All @@ -142,11 +149,11 @@ export async function writeExistingFiles(
);
const npmrc = packageFile.npmrc || config.npmrc;
if (npmrc) {
await fs.outputFile(upath.join(basedir, '.npmrc'), npmrc);
await outputFile(upath.join(basedir, '.npmrc'), npmrc);
}
if (packageFile.yarnrc) {
logger.debug(`Writing .yarnrc to ${basedir}`);
await fs.outputFile(
await outputFile(
upath.join(basedir, '.yarnrc'),
packageFile.yarnrc
.replace('--install.pure-lockfile true', '')
Expand All @@ -161,7 +168,7 @@ export async function writeExistingFiles(
config.reuseLockFiles === false
) {
logger.debug(`Ensuring ${npmLock} is removed`);
await fs.remove(npmLockPath);
await remove(npmLockPath);
} else {
logger.debug(`Writing ${npmLock}`);
let existingNpmLock = await platform.getFile(npmLock);
Expand Down Expand Up @@ -191,7 +198,7 @@ export async function writeExistingFiles(
);
}
}
await fs.outputFile(npmLockPath, existingNpmLock);
await outputFile(npmLockPath, existingNpmLock);
}
}
const { yarnLock } = packageFile;
Expand Down Expand Up @@ -239,7 +246,7 @@ export async function writeUpdatedPackageFiles(
} catch (err) {
logger.warn({ err }, 'Error adding token to package files');
}
await fs.outputFile(
await outputFile(
upath.join(config.localDir, packageFile.name),
JSON.stringify(massagedFile)
);
Expand All @@ -265,7 +272,7 @@ async function getNpmrcContent(dir: string): Promise<string | null> {
const npmrcFilePath = upath.join(dir, '.npmrc');
let originalNpmrcContent = null;
try {
originalNpmrcContent = await fs.readFile(npmrcFilePath, 'utf8');
originalNpmrcContent = await readFile(npmrcFilePath, 'utf8');
logger.debug('npmrc file found in repository');
} catch {
logger.debug('No npmrc file found in repository');
Expand All @@ -288,7 +295,7 @@ async function updateNpmrcContent(
try {
const newContent = newNpmrc.join('\n');
if (newContent !== originalContent) {
await fs.writeFile(npmrcFilePath, newContent);
await writeFile(npmrcFilePath, newContent);
}
} catch {
logger.warn('Unable to write custom npmrc file');
Expand All @@ -303,13 +310,13 @@ async function resetNpmrcContent(
const npmrcFilePath = upath.join(dir, '.npmrc');
if (originalContent) {
try {
await fs.writeFile(npmrcFilePath, originalContent);
await writeFile(npmrcFilePath, originalContent);
} catch {
logger.warn('Unable to reset npmrc to original contents');
}
} else {
try {
await fs.unlink(npmrcFilePath);
await unlink(npmrcFilePath);
} catch {
logger.warn('Unable to delete custom npmrc');
}
Expand Down Expand Up @@ -377,13 +384,13 @@ export async function getAdditionalFiles(
]);
env.NPM_CONFIG_CACHE =
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 || 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 || upath.join(config.cacheDir, './others/pnpm');
await fs.ensureDir(env.npm_config_store);
await ensureDir(env.npm_config_store);
env.NODE_ENV = 'dev';

let token = '';
Expand Down Expand Up @@ -540,7 +547,7 @@ export async function getAdditionalFiles(
const localModified = upath.join(config.localDir, f);
updatedArtifacts.push({
name: f,
contents: await fs.readFile(localModified),
contents: await readFile(localModified),
});
}
}
Expand Down Expand Up @@ -719,9 +726,9 @@ export async function getAdditionalFiles(
try {
let newContent: string;
try {
newContent = await fs.readFile(lockFilePath, 'utf8');
newContent = await readFile(lockFilePath, 'utf8');
} catch (err) {
newContent = await fs.readFile(
newContent = await readFile(
lockFilePath.replace(
'npm-shrinkwrap.json',
'package-lock.json'
Expand Down