mirror of
https://github.com/renovatebot/renovate.git
synced 2025-03-14 16:23:00 +00:00
refactor: Call 'fs-extra' functions via proxies (#6683)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
parent
50e36a1f59
commit
c3fc80a285
10 changed files with 93 additions and 20 deletions
lib
manager
util/fs
workers/branch/lock-files
|
@ -1,20 +1,19 @@
|
|||
import path from 'path';
|
||||
import upath from 'upath';
|
||||
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
|
||||
import { id as npmId } from '../../../datasource/npm';
|
||||
import { logger } from '../../../logger';
|
||||
import { ExternalHostError } from '../../../types/errors/external-host-error';
|
||||
import { getChildProcessEnv } from '../../../util/exec/env';
|
||||
import {
|
||||
deleteLocalFile,
|
||||
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';
|
||||
import { id as npmId } from '../../../datasource/npm';
|
||||
import { logger } from '../../../logger';
|
||||
import { ExternalHostError } from '../../../types/errors/external-host-error';
|
||||
import { getChildProcessEnv } from '../../../util/exec/env';
|
||||
import { deleteLocalFile } from '../../../util/fs';
|
||||
} from '../../../util/fs';
|
||||
import { branchExists, getFile, getRepoStatus } from '../../../util/git';
|
||||
import * as hostRules from '../../../util/host-rules';
|
||||
import { PackageFile, PostUpdateConfig, Upgrade } from '../../common';
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import { exec as _exec } from 'child_process';
|
||||
import path from 'path';
|
||||
import _fs from 'fs-extra';
|
||||
import { envMock, mockExecAll } from '../../../../test/execUtil';
|
||||
import { mocked } from '../../../../test/util';
|
||||
import { BinarySource } from '../../../util/exec/common';
|
||||
import * as _env from '../../../util/exec/env';
|
||||
import * as _fs from '../../../util/fs/proxies';
|
||||
import * as npmHelper from './npm';
|
||||
|
||||
jest.mock('fs-extra');
|
||||
jest.mock('child_process');
|
||||
jest.mock('../../../util/exec/env');
|
||||
jest.mock('../../../util/fs/proxies');
|
||||
jest.mock('./node-version');
|
||||
|
||||
const exec: jest.Mock<typeof _exec> = _exec as any;
|
||||
|
@ -64,7 +64,7 @@ describe('generateLockFile', () => {
|
|||
});
|
||||
it('performs npm-shrinkwrap.json updates', async () => {
|
||||
const execSnapshots = mockExecAll(exec);
|
||||
fs.pathExists.mockImplementationOnce(() => true);
|
||||
fs.pathExists.mockResolvedValueOnce(true);
|
||||
fs.move = jest.fn();
|
||||
fs.readFile = jest.fn(() => 'package-lock-contents') as never;
|
||||
const skipInstalls = true;
|
||||
|
@ -93,7 +93,7 @@ describe('generateLockFile', () => {
|
|||
});
|
||||
it('performs npm-shrinkwrap.json updates (no package-lock.json)', async () => {
|
||||
const execSnapshots = mockExecAll(exec);
|
||||
fs.pathExists.mockImplementationOnce(() => false);
|
||||
fs.pathExists.mockResolvedValueOnce(false);
|
||||
fs.move = jest.fn();
|
||||
fs.readFile = jest.fn((_, _1) => 'package-lock-contents') as never;
|
||||
const skipInstalls = true;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { move, pathExists, readFile, remove } from 'fs-extra';
|
||||
import { validRange } from 'semver';
|
||||
import { quote } from 'shlex';
|
||||
import { join } from 'upath';
|
||||
import { SYSTEM_INSUFFICIENT_DISK_SPACE } from '../../../constants/error-messages';
|
||||
import { logger } from '../../../logger';
|
||||
import { ExecOptions, exec } from '../../../util/exec';
|
||||
import { move, pathExists, readFile, remove } from '../../../util/fs';
|
||||
import { PostUpdateConfig, Upgrade } from '../../common';
|
||||
import { getNodeConstraint } from './node-version';
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { exec as _exec } from 'child_process';
|
||||
import _fs from 'fs-extra';
|
||||
import { envMock, mockExecAll } from '../../../../test/execUtil';
|
||||
import { mocked } from '../../../../test/util';
|
||||
import * as _env from '../../../util/exec/env';
|
||||
import * as _fs from '../../../util/fs/proxies';
|
||||
import { PostUpdateConfig } from '../../common';
|
||||
import * as _pnpmHelper from './pnpm';
|
||||
|
||||
jest.mock('fs-extra');
|
||||
jest.mock('child_process');
|
||||
jest.mock('../../../util/exec/env');
|
||||
jest.mock('../../../util/fs/proxies');
|
||||
jest.mock('./node-version');
|
||||
|
||||
const exec: jest.Mock<typeof _exec> = _exec as any;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { readFile, remove } from 'fs-extra';
|
||||
import { validRange } from 'semver';
|
||||
import { quote } from 'shlex';
|
||||
import { join } from 'upath';
|
||||
import { logger } from '../../../logger';
|
||||
import { ExecOptions, exec } from '../../../util/exec';
|
||||
import { readFile, remove } from '../../../util/fs';
|
||||
import { PostUpdateConfig, Upgrade } from '../../common';
|
||||
import { getNodeConstraint } from './node-version';
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import is from '@sindresorhus/is';
|
||||
import { readFile, remove } from 'fs-extra';
|
||||
import { validRange } from 'semver';
|
||||
import { quote } from 'shlex';
|
||||
import { join } from 'upath';
|
||||
|
@ -8,6 +7,7 @@ import { id as npmId } from '../../../datasource/npm';
|
|||
import { logger } from '../../../logger';
|
||||
import { ExternalHostError } from '../../../types/errors/external-host-error';
|
||||
import { ExecOptions, exec } from '../../../util/exec';
|
||||
import { readFile, remove } from '../../../util/fs';
|
||||
import { PostUpdateConfig, Upgrade } from '../../common';
|
||||
import { getNodeConstraint } from './node-version';
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import * as path from 'path';
|
||||
import findUp from 'find-up';
|
||||
import { readFile } from 'fs-extra';
|
||||
import { XmlDocument } from 'xmldoc';
|
||||
import * as datasourceNuget from '../../datasource/nuget';
|
||||
import { logger } from '../../logger';
|
||||
import { SkipReason } from '../../types';
|
||||
import { clone } from '../../util/clone';
|
||||
import { readFile } from '../../util/fs';
|
||||
import { get } from '../../versioning';
|
||||
import * as semverVersioning from '../../versioning/semver';
|
||||
import { ExtractConfig, PackageDependency, PackageFile } from '../common';
|
||||
|
|
|
@ -3,6 +3,8 @@ import { join, parse } from 'upath';
|
|||
import { RenovateConfig } from '../../config/common';
|
||||
import { logger } from '../../logger';
|
||||
|
||||
export * from './proxies';
|
||||
|
||||
let localDir = '';
|
||||
let cacheDir = '';
|
||||
|
||||
|
|
72
lib/util/fs/proxies.ts
Normal file
72
lib/util/fs/proxies.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import * as fs from 'fs-extra';
|
||||
import { MoveOptions, WriteFileOptions } from 'fs-extra';
|
||||
|
||||
// istanbul ignore next
|
||||
export function stat(path: string | Buffer): Promise<fs.Stats> {
|
||||
return fs.stat(path);
|
||||
}
|
||||
|
||||
// istanbul ignore next
|
||||
export function chmod(
|
||||
path: string | Buffer,
|
||||
mode: string | number
|
||||
): Promise<void> {
|
||||
return fs.chmod(path, mode);
|
||||
}
|
||||
|
||||
export async function readFile(fileName: string): Promise<Buffer>;
|
||||
export async function readFile(
|
||||
fileName: string,
|
||||
encoding: 'utf8'
|
||||
): Promise<string>;
|
||||
export async function readFile(
|
||||
fileName: string,
|
||||
encoding?: string
|
||||
): Promise<string | Buffer> {
|
||||
return fs.readFile(fileName, encoding);
|
||||
}
|
||||
|
||||
// istanbul ignore next
|
||||
export async function writeFile(
|
||||
fileName: string,
|
||||
fileContent: string
|
||||
): Promise<void> {
|
||||
return fs.writeFile(fileName, fileContent);
|
||||
}
|
||||
|
||||
// istanbul ignore next
|
||||
export async function outputFile(
|
||||
file: string,
|
||||
data: any,
|
||||
options?: WriteFileOptions | string
|
||||
): Promise<void> {
|
||||
return fs.outputFile(file, data, options);
|
||||
}
|
||||
|
||||
export async function remove(dir: string): Promise<void> {
|
||||
return fs.remove(dir);
|
||||
}
|
||||
|
||||
// istanbul ignore next
|
||||
export async function unlink(path: string | Buffer): Promise<void> {
|
||||
return fs.unlink(path);
|
||||
}
|
||||
|
||||
// istanbul ignore next
|
||||
export async function exists(path: string): Promise<boolean> {
|
||||
return fs.pathExists(path);
|
||||
}
|
||||
|
||||
// istanbul ignore next
|
||||
export async function pathExists(path: string): Promise<boolean> {
|
||||
return fs.pathExists(path);
|
||||
}
|
||||
|
||||
// istanbul ignore next
|
||||
export function move(
|
||||
src: string,
|
||||
dest: string,
|
||||
options?: MoveOptions
|
||||
): Promise<void> {
|
||||
return fs.move(src, dest, options);
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
import _fs from 'fs-extra';
|
||||
import { git, mocked } from '../../../../test/util';
|
||||
import { getConfig } from '../../../config/defaults';
|
||||
import { PostUpdateConfig } from '../../../manager/common';
|
||||
|
@ -7,6 +6,7 @@ import * as _lerna from '../../../manager/npm/post-update/lerna';
|
|||
import * as _npm from '../../../manager/npm/post-update/npm';
|
||||
import * as _pnpm from '../../../manager/npm/post-update/pnpm';
|
||||
import * as _yarn from '../../../manager/npm/post-update/yarn';
|
||||
import * as _fs from '../../../util/fs/proxies';
|
||||
import * as _hostRules from '../../../util/host-rules';
|
||||
|
||||
const defaultConfig = getConfig();
|
||||
|
|
Loading…
Reference in a new issue