From 0d1b93828404ecf4eff5db7142f6113bf984770a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 22 Jan 2020 14:45:20 +0100 Subject: [PATCH] fix: use graceful-fs all over instead of monkey patching fs --- .eslintrc.js | 7 +++++++ CHANGELOG.md | 4 ++-- e2e/Utils.ts | 2 +- e2e/__tests__/clearCache.test.ts | 2 +- e2e/__tests__/coverageRemapping.test.ts | 2 +- e2e/__tests__/coverageReport.test.ts | 2 +- e2e/__tests__/coverageTransformInstrumented.test.ts | 2 +- e2e/__tests__/globalSetup.test.ts | 2 +- e2e/__tests__/globalTeardown.test.ts | 2 +- e2e/__tests__/jsonReporter.test.ts | 2 +- e2e/__tests__/setupFilesAfterEnvConfig.test.ts | 2 +- e2e/__tests__/snapshot.test.ts | 2 +- e2e/__tests__/snapshotResolver.test.ts | 2 +- e2e/__tests__/testEnvironmentAsync.test.ts | 2 +- e2e/__tests__/testRetries.test.ts | 2 +- e2e/__tests__/toMatchInlineSnapshot.test.ts | 2 +- e2e/__tests__/toMatchSnapshotWithStringSerializer.test.ts | 2 +- e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts | 2 +- e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts | 2 +- e2e/runJest.ts | 2 +- packages/babel-jest/package.json | 4 +++- packages/babel-jest/src/index.ts | 2 +- packages/jest-circus/package.json | 2 ++ packages/jest-circus/src/__mocks__/testUtils.ts | 2 +- packages/jest-cli/package.json | 2 ++ packages/jest-cli/src/init/__tests__/init.test.js | 2 +- packages/jest-cli/src/init/index.ts | 2 +- packages/jest-config/package.json | 2 ++ packages/jest-config/src/index.ts | 2 +- packages/jest-config/src/readConfigFileAndSetRootDir.ts | 2 +- packages/jest-config/src/resolveConfigPath.ts | 2 +- .../jest-core/src/__tests__/watch-file-changes.test.ts | 6 +++--- packages/jest-core/src/cli/index.ts | 4 ---- packages/jest-haste-map/src/crawlers/node.ts | 2 +- packages/jest-haste-map/src/index.ts | 2 +- packages/jest-haste-map/src/lib/FSEventsWatcher.ts | 2 +- packages/jest-haste-map/src/lib/WatchmanWatcher.js | 2 +- packages/jest-haste-map/src/types.ts | 4 ++-- packages/jest-message-util/package.json | 2 ++ packages/jest-message-util/src/index.ts | 2 +- packages/jest-reporters/package.json | 2 ++ packages/jest-reporters/src/coverage_reporter.ts | 2 +- packages/jest-reporters/src/coverage_worker.ts | 2 +- packages/jest-reporters/src/generateEmptyCoverage.ts | 2 +- packages/jest-resolve/package.json | 2 ++ packages/jest-resolve/src/__tests__/resolve.test.ts | 4 ++-- packages/jest-resolve/src/defaultResolver.ts | 2 +- packages/jest-runtime/src/cli/index.ts | 4 ---- packages/jest-serializer/package.json | 4 ++++ packages/jest-serializer/src/__tests__/index.test.ts | 4 +--- packages/jest-serializer/src/index.ts | 2 +- packages/jest-snapshot/package.json | 2 ++ packages/jest-snapshot/src/State.ts | 2 +- .../jest-snapshot/src/__tests__/inline_snapshots.test.ts | 4 ++-- packages/jest-snapshot/src/__tests__/utils.test.ts | 4 ++-- packages/jest-snapshot/src/index.ts | 2 +- packages/jest-snapshot/src/inline_snapshots.ts | 2 +- packages/jest-snapshot/src/utils.ts | 2 +- packages/jest-source-map/src/__tests__/getCallsite.test.ts | 4 ++-- packages/jest-test-sequencer/package.json | 4 ++++ .../src/__tests__/test_sequencer.test.js | 3 +-- packages/jest-test-sequencer/src/index.ts | 2 +- packages/jest-util/package.json | 1 + packages/jest-util/src/installCommonGlobals.ts | 2 +- 64 files changed, 91 insertions(+), 70 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7a9721db88f2..17fd60b4b87d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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}], diff --git a/CHANGELOG.md b/CHANGELOG.md index 783ad7cbfd6a..3f2b7020e9fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[*]` Use `graceful-fs` directly in every package instead of relying on `fs` being monkey patched ([#9443](https://github.com/facebook/jest/pull/9443)) + ### Chore & Maintenance ### Performance @@ -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 diff --git a/e2e/Utils.ts b/e2e/Utils.ts index a98e2e6bca39..d3b7530a13c2 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -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 diff --git a/e2e/__tests__/clearCache.test.ts b/e2e/__tests__/clearCache.test.ts index 859800c939d4..3f7897c0b9a4 100644 --- a/e2e/__tests__/clearCache.test.ts +++ b/e2e/__tests__/clearCache.test.ts @@ -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'); diff --git a/e2e/__tests__/coverageRemapping.test.ts b/e2e/__tests__/coverageRemapping.test.ts index 07172e613b77..9883f2053778 100644 --- a/e2e/__tests__/coverageRemapping.test.ts +++ b/e2e/__tests__/coverageRemapping.test.ts @@ -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'; diff --git a/e2e/__tests__/coverageReport.test.ts b/e2e/__tests__/coverageReport.test.ts index bb72df69521b..d3182ae5d553 100644 --- a/e2e/__tests__/coverageReport.test.ts +++ b/e2e/__tests__/coverageReport.test.ts @@ -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'; diff --git a/e2e/__tests__/coverageTransformInstrumented.test.ts b/e2e/__tests__/coverageTransformInstrumented.test.ts index c16b07fab5ce..7e0ff66eafb2 100644 --- a/e2e/__tests__/coverageTransformInstrumented.test.ts +++ b/e2e/__tests__/coverageTransformInstrumented.test.ts @@ -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'; diff --git a/e2e/__tests__/globalSetup.test.ts b/e2e/__tests__/globalSetup.test.ts index 8e9a582f2ea7..106c89a17d23 100644 --- a/e2e/__tests__/globalSetup.test.ts +++ b/e2e/__tests__/globalSetup.test.ts @@ -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'; diff --git a/e2e/__tests__/globalTeardown.test.ts b/e2e/__tests__/globalTeardown.test.ts index b05d94cfabcd..7964048bbc70 100644 --- a/e2e/__tests__/globalTeardown.test.ts +++ b/e2e/__tests__/globalTeardown.test.ts @@ -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'; diff --git a/e2e/__tests__/jsonReporter.test.ts b/e2e/__tests__/jsonReporter.test.ts index 0f8c9068d687..b84adfe938ba 100644 --- a/e2e/__tests__/jsonReporter.test.ts +++ b/e2e/__tests__/jsonReporter.test.ts @@ -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', () => { diff --git a/e2e/__tests__/setupFilesAfterEnvConfig.test.ts b/e2e/__tests__/setupFilesAfterEnvConfig.test.ts index a5955368e2a1..a9c0b791b82b 100644 --- a/e2e/__tests__/setupFilesAfterEnvConfig.test.ts +++ b/e2e/__tests__/setupFilesAfterEnvConfig.test.ts @@ -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'; diff --git a/e2e/__tests__/snapshot.test.ts b/e2e/__tests__/snapshot.test.ts index 7cda913f7c44..5396a73b7f95 100644 --- a/e2e/__tests__/snapshot.test.ts +++ b/e2e/__tests__/snapshot.test.ts @@ -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'; diff --git a/e2e/__tests__/snapshotResolver.test.ts b/e2e/__tests__/snapshotResolver.test.ts index f5c3a08a4b25..f94e0690ed39 100644 --- a/e2e/__tests__/snapshotResolver.test.ts +++ b/e2e/__tests__/snapshotResolver.test.ts @@ -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( diff --git a/e2e/__tests__/testEnvironmentAsync.test.ts b/e2e/__tests__/testEnvironmentAsync.test.ts index fd0d7804ed46..114af7aae14f 100644 --- a/e2e/__tests__/testEnvironmentAsync.test.ts +++ b/e2e/__tests__/testEnvironmentAsync.test.ts @@ -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'; diff --git a/e2e/__tests__/testRetries.test.ts b/e2e/__tests__/testRetries.test.ts index cedf680ea0a2..c7a3587a448d 100644 --- a/e2e/__tests__/testRetries.test.ts +++ b/e2e/__tests__/testRetries.test.ts @@ -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'; diff --git a/e2e/__tests__/toMatchInlineSnapshot.test.ts b/e2e/__tests__/toMatchInlineSnapshot.test.ts index a58cb03fffae..48ef3029fa07 100644 --- a/e2e/__tests__/toMatchInlineSnapshot.test.ts +++ b/e2e/__tests__/toMatchInlineSnapshot.test.ts @@ -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'; diff --git a/e2e/__tests__/toMatchSnapshotWithStringSerializer.test.ts b/e2e/__tests__/toMatchSnapshotWithStringSerializer.test.ts index b96515af5415..2accc5696386 100644 --- a/e2e/__tests__/toMatchSnapshotWithStringSerializer.test.ts +++ b/e2e/__tests__/toMatchSnapshotWithStringSerializer.test.ts @@ -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'; diff --git a/e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts b/e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts index c795a8aeb14f..da71c55de379 100644 --- a/e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts +++ b/e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts @@ -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'; diff --git a/e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts b/e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts index ed579226a02f..de3a3010ccf7 100644 --- a/e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts +++ b/e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts @@ -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'; diff --git a/e2e/runJest.ts b/e2e/runJest.ts index 7eb6c19216e5..938c351dc2c6 100644 --- a/e2e/runJest.ts +++ b/e2e/runJest.ts @@ -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'); diff --git a/packages/babel-jest/package.json b/packages/babel-jest/package.json index 5efebdfa82bc..f058046f4bcb 100644 --- a/packages/babel-jest/package.json +++ b/packages/babel-jest/package.json @@ -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" diff --git a/packages/babel-jest/src/index.ts b/packages/babel-jest/src/index.ts index bddce17bd536..6342a6be2c8d 100644 --- a/packages/babel-jest/src/index.ts +++ b/packages/babel-jest/src/index.ts @@ -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 { diff --git a/packages/jest-circus/package.json b/packages/jest-circus/package.json index 78b8d142d779..395a069acffd 100644 --- a/packages/jest-circus/package.json +++ b/packages/jest-circus/package.json @@ -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": { diff --git a/packages/jest-circus/src/__mocks__/testUtils.ts b/packages/jest-circus/src/__mocks__/testUtils.ts index 8886eb27017f..742046e268f8 100644 --- a/packages/jest-circus/src/__mocks__/testUtils.ts +++ b/packages/jest-circus/src/__mocks__/testUtils.ts @@ -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'; diff --git a/packages/jest-cli/package.json b/packages/jest-cli/package.json index ff069eb85c62..120de06f1901 100644 --- a/packages/jest-cli/package.json +++ b/packages/jest-cli/package.json @@ -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", @@ -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" }, diff --git a/packages/jest-cli/src/init/__tests__/init.test.js b/packages/jest-cli/src/init/__tests__/init.test.js index afc2acdca315..4c785324c72a 100644 --- a/packages/jest-cli/src/init/__tests__/init.test.js +++ b/packages/jest-cli/src/init/__tests__/init.test.js @@ -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 '../'; diff --git a/packages/jest-cli/src/init/index.ts b/packages/jest-cli/src/init/index.ts index faafb4792bf8..aee4f1cb3cd8 100644 --- a/packages/jest-cli/src/init/index.ts +++ b/packages/jest-cli/src/init/index.ts @@ -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'; diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 90af6dbd3892..c424d2db8ca2 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -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", @@ -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": { diff --git a/packages/jest-config/src/index.ts b/packages/jest-config/src/index.ts index 495879ce59ed..a9ab1e17b591 100644 --- a/packages/jest-config/src/index.ts +++ b/packages/jest-config/src/index.ts @@ -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'; diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 96576e9c28e9..68a9496c14ea 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -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'; diff --git a/packages/jest-config/src/resolveConfigPath.ts b/packages/jest-config/src/resolveConfigPath.ts index d4773eef1e4e..9d5dd081dfbf 100644 --- a/packages/jest-config/src/resolveConfigPath.ts +++ b/packages/jest-config/src/resolveConfigPath.ts @@ -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, diff --git a/packages/jest-core/src/__tests__/watch-file-changes.test.ts b/packages/jest-core/src/__tests__/watch-file-changes.test.ts index cfc43aaff8cd..86b82d9c9de6 100644 --- a/packages/jest-core/src/__tests__/watch-file-changes.test.ts +++ b/packages/jest-core/src/__tests__/watch-file-changes.test.ts @@ -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'; @@ -56,8 +56,8 @@ describe('Watch mode flows with changed files', () => { ` require('./lost-file.js'); describe('Fake test', () => { - it('Hey', () => { - + it('Hey', () => { + }); }); `, diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index eea54b856180..4aa9d46f79ab 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -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 diff --git a/packages/jest-haste-map/src/crawlers/node.ts b/packages/jest-haste-map/src/crawlers/node.ts index 6e6b6b5d4c9d..b1df5144bc24 100644 --- a/packages/jest-haste-map/src/crawlers/node.ts +++ b/packages/jest-haste-map/src/crawlers/node.ts @@ -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 { diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 2e5e827a59ba..f50a5fe51dea 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -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'; diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index 8034fde92163..23a89cda37d3 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -6,9 +6,9 @@ * */ -import * as fs from 'fs'; import * as path from 'path'; import {EventEmitter} from 'events'; +import * as fs from 'graceful-fs'; import anymatch, {Matcher} from 'anymatch'; import micromatch = require('micromatch'); // @ts-ignore no types diff --git a/packages/jest-haste-map/src/lib/WatchmanWatcher.js b/packages/jest-haste-map/src/lib/WatchmanWatcher.js index af0f49c45abd..22d5a2570765 100644 --- a/packages/jest-haste-map/src/lib/WatchmanWatcher.js +++ b/packages/jest-haste-map/src/lib/WatchmanWatcher.js @@ -5,10 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -import fs from 'fs'; import path from 'path'; import assert from 'assert'; import {EventEmitter} from 'events'; +import * as fs from 'graceful-fs'; import watchman from 'fb-watchman'; import common from 'sane/src/common'; import RecrawlWarning from 'sane/src/utils/recrawl-warning-dedupe'; diff --git a/packages/jest-haste-map/src/types.ts b/packages/jest-haste-map/src/types.ts index aa1b4ee5e24e..6c7adbdc5dea 100644 --- a/packages/jest-haste-map/src/types.ts +++ b/packages/jest-haste-map/src/types.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import * as fs from 'fs'; +import {Stats} from 'graceful-fs'; import {Config} from '@jest/types'; import ModuleMap from './ModuleMap'; import HasteFS from './HasteFS'; @@ -107,7 +107,7 @@ export type HTypeValue = HType[keyof HType]; export type EventsQueue = Array<{ filePath: Config.Path; - stat: fs.Stats | undefined; + stat: Stats | undefined; type: string; }>; diff --git a/packages/jest-message-util/package.json b/packages/jest-message-util/package.json index 86471e991e94..f5de7c544bba 100644 --- a/packages/jest-message-util/package.json +++ b/packages/jest-message-util/package.json @@ -18,12 +18,14 @@ "@jest/types": "^25.1.0", "@types/stack-utils": "^1.0.1", "chalk": "^3.0.0", + "graceful-fs": "^4.2.3", "micromatch": "^4.0.2", "slash": "^3.0.0", "stack-utils": "^1.0.1" }, "devDependencies": { "@types/babel__code-frame": "^7.0.0", + "@types/graceful-fs": "^4.1.3", "@types/micromatch": "^4.0.0" }, "publishConfig": { diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index 66cee3dbc6cc..cf9ddd063e27 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -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 {AssertionResult, SerializableError} from '@jest/test-result'; import chalk = require('chalk'); diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index 2458c9f50d0f..14ff61237b13 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -14,6 +14,7 @@ "chalk": "^3.0.0", "collect-v8-coverage": "^1.0.0", "exit": "^0.1.2", + "graceful-fs": "^4.2.3", "glob": "^7.1.2", "istanbul-lib-coverage": "^3.0.0", "istanbul-lib-instrument": "^4.0.0", @@ -34,6 +35,7 @@ "devDependencies": { "@types/exit": "^0.1.30", "@types/glob": "^7.1.1", + "@types/graceful-fs": "^4.1.3", "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-lib-instrument": "^1.7.2", "@types/istanbul-lib-report": "^1.1.0", diff --git a/packages/jest-reporters/src/coverage_reporter.ts b/packages/jest-reporters/src/coverage_reporter.ts index 09ce73f3f39f..f884abeafdf9 100644 --- a/packages/jest-reporters/src/coverage_reporter.ts +++ b/packages/jest-reporters/src/coverage_reporter.ts @@ -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 { AggregatedResult, diff --git a/packages/jest-reporters/src/coverage_worker.ts b/packages/jest-reporters/src/coverage_worker.ts index eb0d056d2644..6c2c4faa6985 100644 --- a/packages/jest-reporters/src/coverage_worker.ts +++ b/packages/jest-reporters/src/coverage_worker.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import {Config} from '@jest/types'; import exit = require('exit'); import {CoverageReporterSerializedOptions} from './types'; diff --git a/packages/jest-reporters/src/generateEmptyCoverage.ts b/packages/jest-reporters/src/generateEmptyCoverage.ts index b026e9861b3e..5ced53d16230 100644 --- a/packages/jest-reporters/src/generateEmptyCoverage.ts +++ b/packages/jest-reporters/src/generateEmptyCoverage.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import {Config} from '@jest/types'; import {readInitialCoverage} from 'istanbul-lib-instrument'; import {FileCoverage, createFileCoverage} from 'istanbul-lib-coverage'; diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index 014b44d0997a..de95045fa091 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -13,11 +13,13 @@ "@jest/types": "^25.1.0", "browser-resolve": "^1.11.3", "chalk": "^3.0.0", + "graceful-fs": "^4.2.3", "jest-pnp-resolver": "^1.2.1", "realpath-native": "^1.1.0" }, "devDependencies": { "@types/browser-resolve": "^0.0.5", + "@types/graceful-fs": "^4.1.3", "jest-haste-map": "^25.1.0" }, "engines": { diff --git a/packages/jest-resolve/src/__tests__/resolve.test.ts b/packages/jest-resolve/src/__tests__/resolve.test.ts index c136ba0e5c6d..777d1da8f4e2 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.ts +++ b/packages/jest-resolve/src/__tests__/resolve.test.ts @@ -6,10 +6,10 @@ * */ -import * as fs from 'fs'; import * as path from 'path'; +import * as fs from 'graceful-fs'; import {ModuleMap} from 'jest-haste-map'; -import Resolver from '../'; +import Resolver = require('../'); // @ts-ignore: js file import userResolver from '../__mocks__/userResolver'; import nodeModulesPaths from '../nodeModulesPaths'; diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index 3c88694e5982..010d7782fd79 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -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 {sync as browserResolve} from 'browser-resolve'; import pnpResolver from 'jest-pnp-resolver'; import {Config} from '@jest/types'; diff --git a/packages/jest-runtime/src/cli/index.ts b/packages/jest-runtime/src/cli/index.ts index 3d1a9ddd2b03..4f301cf41123 100644 --- a/packages/jest-runtime/src/cli/index.ts +++ b/packages/jest-runtime/src/cli/index.ts @@ -21,10 +21,6 @@ import {Context} from '../types'; import * as args from './args'; export async function run(cliArgv?: Config.Argv, cliInfo?: Array) { - const realFs = require('fs'); - const fs = require('graceful-fs'); - fs.gracefulify(realFs); - let argv; if (cliArgv) { argv = cliArgv; diff --git a/packages/jest-serializer/package.json b/packages/jest-serializer/package.json index d8ca797f20c7..5a014907db9f 100644 --- a/packages/jest-serializer/package.json +++ b/packages/jest-serializer/package.json @@ -12,6 +12,10 @@ "license": "MIT", "main": "build/index.js", "types": "build/index.d.ts", + "dependencies": { + "@types/graceful-fs": "^4.1.3", + "graceful-fs": "^4.2.3" + }, "publishConfig": { "access": "public" }, diff --git a/packages/jest-serializer/src/__tests__/index.test.ts b/packages/jest-serializer/src/__tests__/index.test.ts index f27a68911932..45a6951315a8 100644 --- a/packages/jest-serializer/src/__tests__/index.test.ts +++ b/packages/jest-serializer/src/__tests__/index.test.ts @@ -5,11 +5,9 @@ * LICENSE file in the root directory of this source tree. */ -'use strict'; - -import * as fs from 'fs'; import {tmpdir} from 'os'; import * as path from 'path'; +import * as fs from 'graceful-fs'; import prettyFormat = require('pretty-format'); import serializer from '..'; diff --git a/packages/jest-serializer/src/index.ts b/packages/jest-serializer/src/index.ts index 1a3d3c28a4bf..5ea1f462ef37 100644 --- a/packages/jest-serializer/src/index.ts +++ b/packages/jest-serializer/src/index.ts @@ -7,8 +7,8 @@ // TODO: Remove this /// -import * as fs from 'fs'; import {deserialize as v8Deserialize, serialize as v8Serialize} from 'v8'; +import * as fs from 'graceful-fs'; type Path = string; diff --git a/packages/jest-snapshot/package.json b/packages/jest-snapshot/package.json index 408b8f77e83d..7acf1458b8bf 100644 --- a/packages/jest-snapshot/package.json +++ b/packages/jest-snapshot/package.json @@ -14,6 +14,7 @@ "@jest/types": "^25.1.0", "chalk": "^3.0.0", "expect": "^25.1.0", + "graceful-fs": "^4.2.3", "jest-diff": "^25.1.0", "jest-get-type": "^25.1.0", "jest-matcher-utils": "^25.1.0", @@ -26,6 +27,7 @@ }, "devDependencies": { "@babel/traverse": "^7.3.4", + "@types/graceful-fs": "^4.1.3", "@types/mkdirp": "^0.5.2", "@types/natural-compare": "^1.4.0", "@types/prettier": "^1.16.1", diff --git a/packages/jest-snapshot/src/State.ts b/packages/jest-snapshot/src/State.ts index da0ee884a8db..baa2e29b0544 100644 --- a/packages/jest-snapshot/src/State.ts +++ b/packages/jest-snapshot/src/State.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import {Config} from '@jest/types'; import {getStackTraceLines, getTopFrame} from 'jest-message-util'; diff --git a/packages/jest-snapshot/src/__tests__/inline_snapshots.test.ts b/packages/jest-snapshot/src/__tests__/inline_snapshots.test.ts index ceb3ac422d8b..c191a743cbcd 100644 --- a/packages/jest-snapshot/src/__tests__/inline_snapshots.test.ts +++ b/packages/jest-snapshot/src/__tests__/inline_snapshots.test.ts @@ -6,7 +6,7 @@ */ jest.mock('fs', () => ({ - ...jest.genMockFromModule('fs'), + ...jest.genMockFromModule('fs'), existsSync: jest.fn().mockReturnValue(true), readdirSync: jest.fn().mockReturnValue([]), statSync: jest.fn(filePath => ({ @@ -15,8 +15,8 @@ jest.mock('fs', () => ({ })); jest.mock('prettier'); -import * as fs from 'fs'; import * as path from 'path'; +import * as fs from 'graceful-fs'; import prettier from 'prettier'; import babelTraverse from '@babel/traverse'; import {Frame} from 'jest-message-util'; diff --git a/packages/jest-snapshot/src/__tests__/utils.test.ts b/packages/jest-snapshot/src/__tests__/utils.test.ts index df0845440f49..6a521f739277 100644 --- a/packages/jest-snapshot/src/__tests__/utils.test.ts +++ b/packages/jest-snapshot/src/__tests__/utils.test.ts @@ -6,12 +6,12 @@ */ jest.mock('fs', () => ({ - ...jest.genMockFromModule('fs'), + ...jest.genMockFromModule('fs'), existsSync: jest.fn().mockReturnValue(true), })); -import * as fs from 'fs'; import * as path from 'path'; +import * as fs from 'graceful-fs'; import assert = require('assert'); import chalk = require('chalk'); diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index 1fbabce0fc22..1a5898cfe2bb 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import {Config} from '@jest/types'; import {FS as HasteFS} from 'jest-haste-map'; // eslint-disable-line import/no-extraneous-dependencies diff --git a/packages/jest-snapshot/src/inline_snapshots.ts b/packages/jest-snapshot/src/inline_snapshots.ts index e54d62ba08c6..49060e2413b5 100644 --- a/packages/jest-snapshot/src/inline_snapshots.ts +++ b/packages/jest-snapshot/src/inline_snapshots.ts @@ -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 semver = require('semver'); import { CallExpression, diff --git a/packages/jest-snapshot/src/utils.ts b/packages/jest-snapshot/src/utils.ts index 602f6812a718..48f58fd716cd 100644 --- a/packages/jest-snapshot/src/utils.ts +++ b/packages/jest-snapshot/src/utils.ts @@ -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 {sync as mkdirp} from 'mkdirp'; import naturalCompare = require('natural-compare'); import chalk = require('chalk'); diff --git a/packages/jest-source-map/src/__tests__/getCallsite.test.ts b/packages/jest-source-map/src/__tests__/getCallsite.test.ts index 0de9b483bc64..468bbb14105c 100644 --- a/packages/jest-source-map/src/__tests__/getCallsite.test.ts +++ b/packages/jest-source-map/src/__tests__/getCallsite.test.ts @@ -5,13 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import SourceMap from 'source-map'; import getCallsite from '../getCallsite'; // Node 10.5.x compatibility jest.mock('fs', () => ({ - ...jest.genMockFromModule('fs'), + ...jest.genMockFromModule('fs'), ReadStream: jest.requireActual('fs').ReadStream, WriteStream: jest.requireActual('fs').WriteStream, })); diff --git a/packages/jest-test-sequencer/package.json b/packages/jest-test-sequencer/package.json index 7d198a9ba21f..9c7616481e02 100644 --- a/packages/jest-test-sequencer/package.json +++ b/packages/jest-test-sequencer/package.json @@ -11,10 +11,14 @@ "types": "build/index.d.ts", "dependencies": { "@jest/test-result": "^25.1.0", + "graceful-fs": "^4.2.3", "jest-haste-map": "^25.1.0", "jest-runner": "^25.1.0", "jest-runtime": "^25.1.0" }, + "devDependencies": { + "@types/graceful-fs": "^4.1.3" + }, "engines": { "node": ">= 8.3" }, diff --git a/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.js b/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.js index 005338de0063..a5441a2ed762 100644 --- a/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.js +++ b/packages/jest-test-sequencer/src/__tests__/test_sequencer.test.js @@ -4,10 +4,9 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -'use strict'; -import * as fs from 'fs'; import * as path from 'path'; +import * as fs from 'graceful-fs'; import TestSequencer from '../index'; jest.mock('fs', () => ({ diff --git a/packages/jest-test-sequencer/src/index.ts b/packages/jest-test-sequencer/src/index.ts index 4098be5d0edf..86200eddd76e 100644 --- a/packages/jest-test-sequencer/src/index.ts +++ b/packages/jest-test-sequencer/src/index.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import {AggregatedResult} from '@jest/test-result'; import {getCacheFilePath} from 'jest-haste-map'; import {Context} from 'jest-runtime'; diff --git a/packages/jest-util/package.json b/packages/jest-util/package.json index fd94ad0fa1d5..8894fa926ffb 100644 --- a/packages/jest-util/package.json +++ b/packages/jest-util/package.json @@ -12,6 +12,7 @@ "dependencies": { "@jest/types": "^25.1.0", "chalk": "^3.0.0", + "graceful-fs": "^4.2.3", "is-ci": "^2.0.0", "mkdirp": "^0.5.1" }, diff --git a/packages/jest-util/src/installCommonGlobals.ts b/packages/jest-util/src/installCommonGlobals.ts index afd2c0dfd706..6c6da466c17e 100644 --- a/packages/jest-util/src/installCommonGlobals.ts +++ b/packages/jest-util/src/installCommonGlobals.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import * as fs from 'fs'; +import * as fs from 'graceful-fs'; import {Config} from '@jest/types'; import createProcessObject from './createProcessObject'; import deepCyclicCopy from './deepCyclicCopy';