From 22288df2c0a3f3114ea373cf05b93bc0e4d6cbad Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 17 Dec 2017 11:51:39 +0100 Subject: [PATCH] refactor: extract realpath native into a separate module --- packages/jest-cli/package.json | 1 + packages/jest-cli/src/cli/index.js | 2 +- packages/jest-runtime/package.json | 1 + .../jest-runtime/src/script_transformer.js | 3 +- packages/jest-util/src/index.js | 11 ------- yarn.lock | 30 +++++++++++++++++++ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/packages/jest-cli/package.json b/packages/jest-cli/package.json index 64540479d4fb..36629349d837 100644 --- a/packages/jest-cli/package.json +++ b/packages/jest-cli/package.json @@ -28,6 +28,7 @@ "jest-worker": "^21.2.1", "micromatch": "^2.3.11", "node-notifier": "^5.1.2", + "realpath-native": "^1.0.0", "rimraf": "^2.5.4", "slash": "^1.0.0", "string-length": "^2.0.0", diff --git a/packages/jest-cli/src/cli/index.js b/packages/jest-cli/src/cli/index.js index c4c889e26fcc..ea4755411219 100644 --- a/packages/jest-cli/src/cli/index.js +++ b/packages/jest-cli/src/cli/index.js @@ -15,7 +15,6 @@ import { Console, clearLine, createDirectory, - realpath, validateCLIOptions, } from 'jest-util'; import {readConfig} from 'jest-config'; @@ -34,6 +33,7 @@ import TestWatcher from '../test_watcher'; import watch from '../watch'; import yargs from 'yargs'; import rimraf from 'rimraf'; +import {sync as realpath} from 'realpath-native'; export async function run(maybeArgv?: Argv, project?: Path) { try { diff --git a/packages/jest-runtime/package.json b/packages/jest-runtime/package.json index f1d5fc450e48..595aa8e0fbf6 100644 --- a/packages/jest-runtime/package.json +++ b/packages/jest-runtime/package.json @@ -21,6 +21,7 @@ "jest-util": "^21.2.1", "json-stable-stringify": "^1.0.1", "micromatch": "^2.3.11", + "realpath-native": "^1.0.0", "slash": "^1.0.0", "strip-bom": "3.0.0", "write-file-atomic": "^2.1.0", diff --git a/packages/jest-runtime/src/script_transformer.js b/packages/jest-runtime/src/script_transformer.js index 248a42a97635..2eb150960903 100644 --- a/packages/jest-runtime/src/script_transformer.js +++ b/packages/jest-runtime/src/script_transformer.js @@ -17,7 +17,7 @@ import type { import crypto from 'crypto'; import path from 'path'; import vm from 'vm'; -import {createDirectory, realpath} from 'jest-util'; +import {createDirectory} from 'jest-util'; import fs from 'graceful-fs'; import {transform as babelTransform} from 'babel-core'; import babelPluginIstanbul from 'babel-plugin-istanbul'; @@ -28,6 +28,7 @@ import slash from 'slash'; import {version as VERSION} from '../package.json'; import shouldInstrument from './should_instrument'; import writeFileAtomic from 'write-file-atomic'; +import {sync as realpath} from 'realpath-native'; export type Options = {| collectCoverage: boolean, diff --git a/packages/jest-util/src/index.js b/packages/jest-util/src/index.js index a8bc484a6705..b39dc6113f2b 100644 --- a/packages/jest-util/src/index.js +++ b/packages/jest-util/src/index.js @@ -8,7 +8,6 @@ */ import mkdirp from 'mkdirp'; -import fs from 'fs'; import BufferedConsole from './buffered_console'; import clearLine from './clear_line'; @@ -32,15 +31,6 @@ const createDirectory = (path: string) => { } }; -const realpath = (filepath: string) => { - if (typeof fs.realpathSync.native === 'function') { - return fs.realpathSync.native(filepath); - } - - // $FlowFixMe: This is need for node@<9.2 - return process.binding('fs').realpath(filepath, 'utf8'); -}; - module.exports = { BufferedConsole, Console, @@ -52,7 +42,6 @@ module.exports = { getConsoleOutput, installCommonGlobals, isInteractive, - realpath, setGlobal, validateCLIOptions, }; diff --git a/yarn.lock b/yarn.lock index a59d9e7ab28b..eba69ed07617 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2633,6 +2633,16 @@ errorhandler@~1.4.2: accepts "~1.3.0" escape-html "~1.0.3" +es-abstract@^1.5.1: + version "1.10.0" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.10.0.tgz#1ecb36c197842a00d8ee4c2dfd8646bb97d60864" + dependencies: + es-to-primitive "^1.1.1" + function-bind "^1.1.1" + has "^1.0.1" + is-callable "^1.1.3" + is-regex "^1.0.4" + es-abstract@^1.6.1, es-abstract@^1.7.0: version "1.9.0" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.9.0.tgz#690829a07cae36b222e7fd9b75c0d0573eb25227" @@ -5369,6 +5379,13 @@ object.entries@^1.0.4: function-bind "^1.1.0" has "^1.0.1" +object.getownpropertydescriptors@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz#8758c846f5b407adab0f236e0986f14b051caa16" + dependencies: + define-properties "^1.1.2" + es-abstract "^1.5.1" + object.omit@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/object.omit/-/object.omit-2.0.1.tgz#1a9c744829f39dbb858c76ca3579ae2a54ebd1fa" @@ -6139,6 +6156,12 @@ readdirp@^2.0.0: readable-stream "^2.0.2" set-immediate-shim "^1.0.1" +realpath-native@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/realpath-native/-/realpath-native-1.0.0.tgz#7885721a83b43bd5327609f0ddecb2482305fdf0" + dependencies: + util.promisify "^1.0.0" + rechoir@^0.6.2: version "0.6.2" resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" @@ -7392,6 +7415,13 @@ util-deprecate@1.0.2, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" +util.promisify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/util.promisify/-/util.promisify-1.0.0.tgz#440f7165a459c9a16dc145eb8e72f35687097030" + dependencies: + define-properties "^1.1.2" + object.getownpropertydescriptors "^2.0.3" + util@0.10.3, util@~0.10.1: version "0.10.3" resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9"