Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor: Replace those 'fs-extra' functions in which we can be sure (#…
  • Loading branch information
zharinov committed Jul 3, 2020
1 parent 632ceaf commit 46ec89e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
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);
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

0 comments on commit 46ec89e

Please sign in to comment.