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

fix: replace non-CLI rimraf usage #13151

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions e2e/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as path from 'path';
import dedent = require('dedent');
import {ExecaReturnValue, sync as spawnSync} from 'execa';
import * as fs from 'graceful-fs';
import rimraf = require('rimraf');
import type {PackageJson} from 'type-fest';
import which = require('which');
import type {Config} from '@jest/types';
Expand Down Expand Up @@ -62,7 +61,7 @@ export const linkJestPackage = (packageName: string, cwd: string) => {
const packagePath = path.resolve(packagesDir, packageName);
const destination = path.resolve(cwd, 'node_modules/', packageName);
fs.mkdirSync(destination, {recursive: true});
rimraf.sync(destination);
fs.rmSync(destination, {force: true, recursive: true});
fs.symlinkSync(packagePath, destination, 'junction');
};

Expand All @@ -76,7 +75,8 @@ export const makeTemplate =
return values[number - 1];
});

export const cleanup = (directory: string) => rimraf.sync(directory);
export const cleanup = (directory: string) =>
fs.rmSync(directory, {force: true, recursive: true});

/**
* Creates a nested directory with files and their contents
Expand Down
7 changes: 3 additions & 4 deletions e2e/__tests__/snapshotMockFs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
*/

import * as path from 'path';
import rimraf = require('rimraf');
import {extractSummary} from '../Utils';
import {cleanup, extractSummary} from '../Utils';
import {json as runJestJson} from '../runJest';

const DIR = path.resolve(__dirname, '../snapshot-mock-fs');
const snapshotDir = path.resolve(DIR, '__tests__/__snapshots__');
const snapshotFile = path.resolve(snapshotDir, 'snapshot.test.js.snap');

beforeEach(() => rimraf.sync(snapshotDir));
afterAll(() => rimraf.sync(snapshotDir));
beforeEach(() => cleanup(snapshotDir));
afterAll(() => cleanup(snapshotDir));

test('store snapshot even if fs is mocked', () => {
const {json, exitCode, stderr} = runJestJson(DIR, ['--ci=false']);
Expand Down
4 changes: 1 addition & 3 deletions packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"jest-watcher": "workspace:^",
"micromatch": "^4.0.4",
"pretty-format": "workspace:^",
"rimraf": "^3.0.0",
"slash": "^3.0.0",
"strip-ansi": "^6.0.0"
},
Expand All @@ -47,8 +46,7 @@
"@jest/test-utils": "workspace:^",
"@types/exit": "^0.1.30",
"@types/graceful-fs": "^4.1.3",
"@types/micromatch": "^4.0.1",
"@types/rimraf": "^3.0.0"
"@types/micromatch": "^4.0.1"
},
"peerDependencies": {
"node-notifier": "^8.0.1 || ^9.0.0 || ^10.0.0"
Expand Down
9 changes: 4 additions & 5 deletions packages/jest-core/src/__tests__/watchFileChanges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import rimraf = require('rimraf');
import type {AggregatedResult} from '@jest/test-result';
import {normalize} from 'jest-config';
import type HasteMap from 'jest-haste-map';
Expand All @@ -36,8 +35,8 @@ describe('Watch mode flows with changed files', () => {
watch = interopRequireDefault(require('../watch')).default;
pipe = {write: jest.fn()} as unknown;
stdin = new MockStdin();
rimraf.sync(cacheDirectory);
rimraf.sync(testDirectory);
fs.rmSync(cacheDirectory, {force: true, recursive: true});
fs.rmSync(testDirectory, {force: true, recursive: true});
fs.mkdirSync(testDirectory);
fs.mkdirSync(cacheDirectory);
});
Expand All @@ -47,8 +46,8 @@ describe('Watch mode flows with changed files', () => {
if (hasteMapInstance) {
hasteMapInstance.end();
}
rimraf.sync(cacheDirectory);
rimraf.sync(testDirectory);
fs.rmSync(cacheDirectory, {force: true, recursive: true});
fs.rmSync(testDirectory, {force: true, recursive: true});
});

it('should correct require new files without legacy cache', async () => {
Expand Down
13 changes: 8 additions & 5 deletions packages/jest-core/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import chalk = require('chalk');
import exit = require('exit');
import rimraf = require('rimraf');
import * as fs from 'graceful-fs';
import {CustomConsole} from '@jest/console';
import type {AggregatedResult, TestContext} from '@jest/test-result';
import type {Config} from '@jest/types';
Expand Down Expand Up @@ -63,10 +63,13 @@ export async function runCLI(
}

if (argv.clearCache) {
configs.forEach(config => {
rimraf.sync(config.cacheDirectory);
process.stdout.write(`Cleared ${config.cacheDirectory}\n`);
});
// stick in a Set to dedupe the deletions
Copy link
Member Author

Choose a reason for hiding this comment

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

snuck in a minor quality of life improvement

new Set(configs.map(config => config.cacheDirectory)).forEach(
cacheDirectory => {
fs.rmSync(cacheDirectory, {force: true, recursive: true});
process.stdout.write(`Cleared ${cacheDirectory}\n`);
},
);

exit(0);
}
Expand Down
16 changes: 12 additions & 4 deletions scripts/bundleTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import chalk from 'chalk';
import fs from 'graceful-fs';
import {sync as pkgDir} from 'pkg-dir';
import prettier from 'prettier';
import rimraf from 'rimraf';
import {getPackages} from './buildUtils.mjs';

const prettierConfig = prettier.resolveConfig.sync(
Expand Down Expand Up @@ -166,10 +165,19 @@ const excludedPackages = new Set(['@jest/globals']);

let definitionFile = await fs.promises.readFile(filepath, 'utf8');

rimraf.sync(path.resolve(packageDir, 'build/**/*.d.ts'));
rimraf.sync(path.resolve(packageDir, 'dist/'));
fs.rmSync(path.resolve(packageDir, 'build/**/*.d.ts'), {
force: true,
recursive: true,
});
fs.rmSync(path.resolve(packageDir, 'dist/'), {
force: true,
recursive: true,
});
// this is invalid now, so remove it to not confuse `tsc`
rimraf.sync(path.resolve(packageDir, 'tsconfig.tsbuildinfo'));
fs.rmSync(path.resolve(packageDir, 'tsconfig.tsbuildinfo'), {
force: true,
recursive: true,
});

definitionFile = definitionFile.replace(/\r\n/g, '\n');

Expand Down
6 changes: 4 additions & 2 deletions scripts/remove-examples.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import path from 'path';
import {fileURLToPath} from 'url';
import fs from 'graceful-fs';
import rimraf from 'rimraf';
import config from '../jest.config.mjs';

const dirname = path.dirname(fileURLToPath(import.meta.url));
Expand All @@ -22,4 +21,7 @@ fs.writeFileSync(
`export default ${JSON.stringify(config, null, 2)};\n`,
);

rimraf.sync(path.resolve(dirname, '../examples/'));
fs.rmSync(path.resolve(dirname, '../examples/'), {
force: true,
recursive: true,
});
3 changes: 1 addition & 2 deletions scripts/verifyOldTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {fileURLToPath} from 'url';
import chalk from 'chalk';
import execa from 'execa';
import fs from 'graceful-fs';
import rimraf from 'rimraf';
import stripJsonComments from 'strip-json-comments';
import tempy from 'tempy';
const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -70,7 +69,7 @@ function smoketest() {
),
);
} finally {
rimraf.sync(cwd);
fs.rmSync(cwd, {force: true, recursive: true});
}
}

Expand Down
3 changes: 1 addition & 2 deletions scripts/verifyPnP.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import dedent from 'dedent';
import execa from 'execa';
import fs from 'graceful-fs';
import yaml from 'js-yaml';
import rimraf from 'rimraf';
import tempy from 'tempy';

const rootDirectory = path.resolve(
Expand Down Expand Up @@ -78,5 +77,5 @@ try {

console.log(chalk.inverse.green(' Successfully ran Jest with PnP linker '));
} finally {
rimraf.sync(cwd);
fs.rmSync(cwd, {force: true, recursive: true});
}
14 changes: 1 addition & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,6 @@ __metadata:
"@types/graceful-fs": ^4.1.3
"@types/micromatch": ^4.0.1
"@types/node": "*"
"@types/rimraf": ^3.0.0
ansi-escapes: ^4.2.1
chalk: ^4.0.0
ci-info: ^3.2.0
Expand All @@ -2640,7 +2639,6 @@ __metadata:
jest-watcher: "workspace:^"
micromatch: ^4.0.4
pretty-format: "workspace:^"
rimraf: ^3.0.0
slash: ^3.0.0
strip-ansi: ^6.0.0
peerDependencies:
Expand Down Expand Up @@ -4522,7 +4520,7 @@ __metadata:
languageName: node
linkType: hard

"@types/glob@npm:*, @types/glob@npm:^7.1.1":
"@types/glob@npm:^7.1.1":
version: 7.2.0
resolution: "@types/glob@npm:7.2.0"
dependencies:
Expand Down Expand Up @@ -4920,16 +4918,6 @@ __metadata:
languageName: node
linkType: hard

"@types/rimraf@npm:^3.0.0":
version: 3.0.2
resolution: "@types/rimraf@npm:3.0.2"
dependencies:
"@types/glob": "*"
"@types/node": "*"
checksum: b47fa302f46434cba704d20465861ad250df79467d3d289f9d6490d3aeeb41e8cb32dd80bd1a8fd833d1e185ac719fbf9be12e05ad9ce9be094d8ee8f1405347
languageName: node
linkType: hard

"@types/sax@npm:^1.2.1":
version: 1.2.4
resolution: "@types/sax@npm:1.2.4"
Expand Down