Skip to content

Commit

Permalink
fix: use graceful-fs all over instead of monkey patching fs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jan 22, 2020
1 parent e5a9ecc commit f2a03ac
Show file tree
Hide file tree
Showing 64 changed files with 91 additions and 70 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Expand Up @@ -124,6 +124,13 @@ module.exports = {
// https://github.com/benmosher/eslint-plugin-import/issues/645
'import/order': 0,
'no-console': 0,
'no-restricted-imports': [
2,
{
message: 'Please use graceful-fs instead.',
name: 'fs',
},
],
'no-unused-vars': 2,
'prettier/prettier': 2,
'sort-imports': [2, {ignoreDeclarationSort: true}],
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[*]` Use `graceful-fs` directly in every package instead of relying on `fs` being monkey patched

### Chore & Maintenance

### Performance
Expand Down Expand Up @@ -114,8 +116,6 @@
- `[jest-types]` Mark `InitialOptions` as `Partial` ([#8848](https://github.com/facebook/jest/pull/8848))
- `[jest-config]` Refactor `normalize` to be more type safe ([#8848](https://github.com/facebook/jest/pull/8848))

### Performance

## 24.9.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion e2e/Utils.ts
Expand Up @@ -6,8 +6,8 @@
*
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {Config} from '@jest/types';

// eslint-disable-next-line import/named
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/clearCache.test.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import runJest from '../runJest';

const CACHE = path.resolve(tmpdir(), 'clear-cache-directory');
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageRemapping.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {readFileSync} from 'fs';
import * as path from 'path';
import {readFileSync} from 'graceful-fs';
import {cleanup, run} from '../Utils';
import runJest from '../runJest';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageReport.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary, run} from '../Utils';
import runJest from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageTransformInstrumented.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {readFileSync} from 'fs';
import * as path from 'path';
import {readFileSync} from 'graceful-fs';
import {cleanup, run} from '../Utils';
import runJest from '../runJest';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/globalSetup.test.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import runJest, {json as runWithJson} from '../runJest';
import {cleanup, run} from '../Utils';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/globalTeardown.test.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {createDirectory} from 'jest-util';
import runJest, {json as runWithJson} from '../runJest';
import {cleanup, run} from '../Utils';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/jsonReporter.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import runJest from '../runJest';

describe('JSON Reporter', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/setupFilesAfterEnvConfig.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {json as runWithJson} from '../runJest';
import {writeFiles} from '../Utils';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/snapshot.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary} from '../Utils';
import runJest, {json as runWithJson} from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/snapshotResolver.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import runJest from '../runJest';

const snapshotDir = path.resolve(
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/testEnvironmentAsync.test.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import {tmpdir} from 'os';
import * as fs from 'graceful-fs';
import runJest from '../runJest';
import {cleanup} from '../Utils';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/testRetries.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {skipSuiteOnJasmine} from '@jest/test-utils';
import runJest from '../runJest';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/toMatchInlineSnapshot.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, makeTemplate, writeFiles} from '../Utils';
import runJest from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/toMatchSnapshotWithStringSerializer.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {cleanup, makeTemplate, writeFiles} from '../Utils';
import runJest from '../runJest';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts
Expand Up @@ -6,7 +6,7 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, makeTemplate, writeFiles} from '../Utils';
import runJest from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts
Expand Up @@ -6,7 +6,7 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, makeTemplate, writeFiles} from '../Utils';
import runJest from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/runJest.ts
Expand Up @@ -7,8 +7,8 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import {Writable} from 'stream';
import * as fs from 'graceful-fs';
import execa = require('execa');
import {FormattedTestResults} from '@jest/test-result';
import stripAnsi = require('strip-ansi');
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-jest/package.json
Expand Up @@ -17,10 +17,12 @@
"babel-plugin-istanbul": "^6.0.0",
"babel-preset-jest": "^25.1.0",
"chalk": "^3.0.0",
"graceful-fs": "^4.2.3",
"slash": "^3.0.0"
},
"devDependencies": {
"@babel/core": "^7.1.0"
"@babel/core": "^7.1.0",
"@types/graceful-fs": "^4.1.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-jest/src/index.ts
Expand Up @@ -6,8 +6,8 @@
*/

import {createHash} from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {Transformer} from '@jest/transform';
import {Config} from '@jest/types';
import {
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-circus/package.json
Expand Up @@ -31,8 +31,10 @@
"@jest/test-utils": "^25.1.0",
"@types/babel__traverse": "^7.0.4",
"@types/co": "^4.6.0",
"@types/graceful-fs": "^4.1.3",
"@types/stack-utils": "^1.0.1",
"execa": "^3.2.0",
"graceful-fs": "^4.2.3",
"jest-runtime": "^25.1.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/__mocks__/testUtils.ts
Expand Up @@ -5,10 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import {createHash} from 'crypto';
import * as fs from 'graceful-fs';
// eslint-disable-next-line import/named
import {ExecaSyncReturnValue, sync as spawnSync} from 'execa';
import {skipSuiteOnWindows} from '@jest/test-utils';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-cli/package.json
Expand Up @@ -10,6 +10,7 @@
"@jest/types": "^25.1.0",
"chalk": "^3.0.0",
"exit": "^0.1.2",
"graceful-fs": "^4.2.3",
"import-local": "^3.0.2",
"is-ci": "^2.0.0",
"jest-config": "^25.1.0",
Expand All @@ -22,6 +23,7 @@
"devDependencies": {
"@types/exit": "^0.1.30",
"@types/is-ci": "^2.0.0",
"@types/graceful-fs": "^4.1.3",
"@types/prompts": "^2.0.1",
"@types/yargs": "^15.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/init/__tests__/init.test.js
Expand Up @@ -6,8 +6,8 @@
*/

/* eslint-disable no-eval */
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import prompts from 'prompts';
import {constants} from 'jest-config';
import init from '../';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/init/index.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import chalk = require('chalk');
import prompts = require('prompts');
import {sync as realpath} from 'realpath-native';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-config/package.json
Expand Up @@ -16,6 +16,7 @@
"babel-jest": "^25.1.0",
"chalk": "^3.0.0",
"glob": "^7.1.1",
"graceful-fs": "^4.2.3",
"jest-environment-jsdom": "^25.1.0",
"jest-environment-node": "^25.1.0",
"jest-get-type": "^25.1.0",
Expand All @@ -31,6 +32,7 @@
"devDependencies": {
"@types/babel__core": "^7.0.4",
"@types/glob": "^7.1.1",
"@types/graceful-fs": "^4.1.3",
"@types/micromatch": "^4.0.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {Config} from '@jest/types';
import chalk = require('chalk');
import {sync as realpath} from 'realpath-native';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/readConfigFileAndSetRootDir.ts
Expand Up @@ -6,7 +6,7 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import * as fs from 'graceful-fs';
import {Config} from '@jest/types';
// @ts-ignore: vendored
import jsonlint from './vendor/jsonlint';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/resolveConfigPath.ts
Expand Up @@ -6,7 +6,7 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import * as fs from 'graceful-fs';
import {Config} from '@jest/types';
import {
JEST_CONFIG_BASE_NAME,
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-core/src/__tests__/watch-file-changes.test.ts
Expand Up @@ -7,8 +7,8 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import {tmpdir} from 'os';
import * as fs from 'graceful-fs';
import {JestHook} from 'jest-watcher';
import Runtime = require('jest-runtime');
import {normalize} from 'jest-config';
Expand Down Expand Up @@ -56,8 +56,8 @@ describe('Watch mode flows with changed files', () => {
`
require('./lost-file.js');
describe('Fake test', () => {
it('Hey', () => {
it('Hey', () => {
});
});
`,
Expand Down
4 changes: 0 additions & 4 deletions packages/jest-core/src/cli/index.ts
Expand Up @@ -38,10 +38,6 @@ export const runCLI = async (
results: AggregatedResult;
globalConfig: Config.GlobalConfig;
}> => {
const realFs = require('fs');
const fs = require('graceful-fs');
fs.gracefulify(realFs);

let results: AggregatedResult | undefined;

// If we output a JSON object, we can't write anything to stdout, since
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/crawlers/node.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import {spawn} from 'child_process';
import * as fs from 'graceful-fs';
import H from '../constants';
import * as fastPath from '../lib/fast_path';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/index.ts
Expand Up @@ -8,9 +8,9 @@
import {execSync} from 'child_process';
import {createHash} from 'crypto';
import {EventEmitter} from 'events';
import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {NodeWatcher, Watcher as SaneWatcher} from 'sane';
import {Config} from '@jest/types';
import serializer from 'jest-serializer';
Expand Down

0 comments on commit f2a03ac

Please sign in to comment.