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

This commit is contained in:
Sergio Zharinov 2020-07-04 14:47:52 +04:00 committed by GitHub
parent 807d48e07d
commit 78e319f0fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 26 deletions

View file

@ -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';
@ -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) {

View file

@ -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';
@ -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;
@ -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;

View file

@ -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';
@ -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;
@ -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', '')
@ -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);
@ -191,7 +198,7 @@ export async function writeExistingFiles(
);
}
}
await fs.outputFile(npmLockPath, existingNpmLock);
await outputFile(npmLockPath, existingNpmLock);
}
}
const { yarnLock } = packageFile;
@ -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)
);
@ -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');
@ -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');
@ -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');
}
@ -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 = '';
@ -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),
});
}
}
@ -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'