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: Replace those 'fs-extra' functions in which we can be sure #6666

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 3 additions & 7 deletions lib/manager/mix/artifacts.ts
@@ -1,10 +1,8 @@
import fs from 'fs-extra';
import { quote } from 'shlex';
import upath from 'upath';
import { logger } from '../../logger';
import { exec } from '../../util/exec';
import { BinarySource } from '../../util/exec/common';
import { readLocalFile } from '../../util/fs';
import { readLocalFile, writeLocalFile } from '../../util/fs';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';

export async function updateArtifacts({
Expand All @@ -27,8 +25,7 @@ export async function updateArtifacts({

const lockFileName = 'mix.lock';
try {
const localPackageFileName = upath.join(cwd, packageFileName);
await fs.outputFile(localPackageFileName, newPackageFileContent);
await writeLocalFile(packageFileName, newPackageFileContent);
} catch (err) {
logger.warn({ err }, 'mix.exs could not be written');
return [
Expand Down Expand Up @@ -80,8 +77,7 @@ export async function updateArtifacts({
];
}

const localLockFileName = upath.join(cwd, lockFileName);
const newMixLockContent = await fs.readFile(localLockFileName, 'utf8');
const newMixLockContent = await readLocalFile(lockFileName, 'utf8');
if (existingLockFileContent === newMixLockContent) {
logger.debug('mix.lock is unchanged');
return null;
Expand Down
12 changes: 5 additions & 7 deletions lib/manager/pipenv/artifacts.ts
@@ -1,9 +1,9 @@
import { ensureDir, outputFile, readFile, remove } from 'fs-extra';
import { ensureDir } from 'fs-extra';
import { join } from 'upath';
import { logger } from '../../logger';
import { platform } from '../../platform';
import { ExecOptions, exec } from '../../util/exec';
import { readLocalFile } from '../../util/fs';
import { deleteLocalFile, readLocalFile, writeLocalFile } from '../../util/fs';
import {
UpdateArtifact,
UpdateArtifactsConfig,
Expand Down Expand Up @@ -54,11 +54,9 @@ export async function updateArtifacts({
return null;
}
try {
const localPipfileFileName = join(config.localDir, pipfileName);
await outputFile(localPipfileFileName, newPipfileContent);
const localLockFileName = join(config.localDir, lockFileName);
await writeLocalFile(pipfileName, newPipfileContent);
if (config.isLockFileMaintenance) {
await remove(localLockFileName);
await deleteLocalFile(lockFileName);
}
const cmd = 'pipenv lock';
const tagConstraint = getPythonConstraint(existingLockFileContent, config);
Expand All @@ -85,7 +83,7 @@ export async function updateArtifacts({
{
file: {
name: lockFileName,
contents: await readFile(localLockFileName, 'utf8'),
contents: await readLocalFile(lockFileName, 'utf8'),
},
},
];
Expand Down
4 changes: 2 additions & 2 deletions lib/manager/poetry/artifacts.ts
@@ -1,10 +1,10 @@
import is from '@sindresorhus/is';
import fs from 'fs-extra';
import { quote } from 'shlex';
import { parse } from 'toml';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import {
deleteLocalFile,
getSiblingFileName,
readLocalFile,
writeLocalFile,
Expand Down Expand Up @@ -65,7 +65,7 @@ export async function updateArtifacts({
await writeLocalFile(packageFileName, newPackageFileContent);
const cmd: string[] = [];
if (config.isLockFileMaintenance) {
await fs.remove(lockFileName);
await deleteLocalFile(lockFileName);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, not sure about this one though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be right. 🤔

cmd.push('poetry update --lock --no-interaction');
} else {
for (let i = 0; i < updatedDeps.length; i += 1) {
Expand Down
3 changes: 2 additions & 1 deletion lib/workers/repository/index.ts
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs-extra';
import { RenovateConfig } from '../../config';
import { logger, setMeta } from '../../logger';
import { platform } from '../../platform';
import { deleteLocalFile } from '../../util/fs';
import { addSplit, getSplits, splitInit } from '../../util/split';
import handleError from './error';
import { finaliseRepo } from './finalise';
Expand Down Expand Up @@ -52,7 +53,7 @@ export async function renovateRepository(
}
await platform.cleanRepo();
if (config.localDir && !config.persistRepoData) {
await fs.remove(config.localDir);
await deleteLocalFile('.');
}
const splits = getSplits();
logger.debug(splits, 'Repository timing splits (milliseconds)');
Expand Down