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

chore: remove dependency on realpath-native #9952

Merged
merged 7 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- `[*]` [**BREAKING**] TypeScript definitions requires a minimum of TypeScript v3.8 ([#9823](https://github.com/facebook/jest/pull/9823))
- `[*]` [**BREAKING**] Drop support for Node 8 ([#9423](https://github.com/facebook/jest/pull/9423))
- `[*]` Upgrade to chalk@4 ([#9752](https://github.com/facebook/jest/pull/9752))
- `[*]` Remove usage of `realpath-native`
Copy link
Member Author

Choose a reason for hiding this comment

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

Should link the pr

- `[jest-runtime]` [**BREAKING**] Remove long-deprecated `require.requireActual` and `require.requireMock` methods ([#9854](https://github.com/facebook/jest/pull/9854))
- `[expect, jest-mock, pretty-format]` [**BREAKING**] Remove `build-es5` from package ([#9945](https://github.com/facebook/jest/pull/9945))
- `[jest-haste-map]` [**BREAKING**] removed `providesModuleNodeModules` ([#8535](https://github.com/facebook/jest/pull/8535))
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/moduleNameMapper.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ FAIL __tests__/index.js
12 | module.exports = () => 'test';
13 |

at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:542:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:541:17)
at Object.require (index.js:10:1)
`;

Expand Down Expand Up @@ -65,6 +65,6 @@ FAIL __tests__/index.js
12 | module.exports = () => 'test';
13 |

at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:542:17)
at createNoMappedModuleFoundError (../../packages/jest-resolve/build/index.js:541:17)
at Object.require (index.js:10:1)
`;
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ FAIL __tests__/test.js
| ^
9 |

at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:297:11)
at Resolver.resolveModule (../../packages/jest-resolve/build/index.js:296:11)
at Object.require (index.js:8:18)
`;
4 changes: 2 additions & 2 deletions e2e/__tests__/hasteMapSize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import {tmpdir} from 'os';
import * as path from 'path';
import {realpathSync} from 'graceful-fs';
import HasteMap = require('jest-haste-map');
import {sync as realpath} from 'realpath-native';
import {cleanup, writeFiles} from '../Utils';

const DIR = path.resolve(realpath(tmpdir()), 'haste_map_size');
const DIR = path.resolve(realpathSync.native(tmpdir()), 'haste_map_size');

beforeEach(() => {
cleanup(DIR);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"prettier": "^2.0.1",
"progress": "^2.0.0",
"promise": "^8.0.2",
"realpath-native": "^2.0.0",
"resolve": "^1.15.0",
"rimraf": "^3.0.0",
"semver": "^6.3.0",
Expand Down
1 change: 0 additions & 1 deletion packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"jest-util": "^26.0.0-alpha.0",
"jest-validate": "^26.0.0-alpha.0",
"prompts": "^2.0.1",
"realpath-native": "^2.0.0",
"yargs": "^15.3.1"
},
"devDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import * as path from 'path';
import type {Config} from '@jest/types';
import type {AggregatedResult} from '@jest/test-result';
import {clearLine} from 'jest-util';
import {clearLine, tryRealpath} from 'jest-util';
import {validateCLIOptions} from 'jest-validate';
import {deprecationEntries} from 'jest-config';
import {getVersion, runCLI} from '@jest/core';
import chalk = require('chalk');
import exit = require('exit');
import yargs = require('yargs');
import {sync as realpath} from 'realpath-native';
import init from '../init';
import * as args from './args';

Expand Down Expand Up @@ -97,7 +96,7 @@ const getProjectListFromCLIArgs = (

if (!projects.length && process.platform === 'win32') {
try {
projects.push(realpath(process.cwd()));
projects.push(tryRealpath(process.cwd()));
} catch (err) {
// do nothing, just catch error
// process.binding('fs').realpath can throw, e.g. on mapped drives
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ 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';
import {constants} from 'jest-config';
import {tryRealpath} from 'jest-util';
import defaultQuestions, {testScriptQuestion} from './questions';
import {MalformedPackageJsonError, NotFoundPackageJsonError} from './errors';
import generateConfigFile from './generate_config_file';
Expand All @@ -35,7 +35,7 @@ type PromptsResults = {
const getConfigFilename = (ext: string) => JEST_CONFIG_BASE_NAME + ext;

export default async (
rootDir: string = realpath(process.cwd()),
rootDir: string = tryRealpath(process.cwd()),
): Promise<void> => {
// prerequisite checks
const projectPackageJsonPath: string = path.join(rootDir, PACKAGE_JSON);
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"jest-util": "^26.0.0-alpha.0",
"jest-validate": "^26.0.0-alpha.0",
"micromatch": "^4.0.2",
"pretty-format": "^26.0.0-alpha.0",
"realpath-native": "^2.0.0"
"pretty-format": "^26.0.0-alpha.0"
},
"devDependencies": {
"@types/babel__core": "^7.0.4",
Expand Down
7 changes: 4 additions & 3 deletions packages/jest-config/src/getCacheDirectory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import * as path from 'path';
import {tmpdir} from 'os';
import {sync as realpath} from 'realpath-native';
import type {Config} from '@jest/types';
import {tryRealpath} from 'jest-util';

const getCacheDirectory = () => {
const getCacheDirectory: () => Config.Path = () => {
const {getuid} = process;
const tmpdirPath = path.join(realpath(tmpdir()), 'jest');
const tmpdirPath = path.join(tryRealpath(tmpdir()), 'jest');
if (getuid == null) {
return tmpdirPath;
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import * as path from 'path';
import * as fs from 'graceful-fs';
import type {Config} from '@jest/types';
import {tryRealpath} from 'jest-util';
import chalk = require('chalk');
import {sync as realpath} from 'realpath-native';
import {isJSONString, replaceRootDirInPath} from './utils';
import normalize from './normalize';
import resolveConfigPath from './resolveConfigPath';
Expand Down Expand Up @@ -295,7 +295,7 @@ export async function readConfigs(
if (projects.length > 0) {
const projectIsCwd =
process.platform === 'win32'
? projects[0] === realpath(process.cwd())
? projects[0] === tryRealpath(process.cwd())
: projects[0] === process.cwd();

const parsedConfigs = await Promise.all(
Expand Down
7 changes: 3 additions & 4 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import {statSync} from 'graceful-fs';
import {sync as glob} from 'glob';
import type {Config} from '@jest/types';
import {ValidationError, validate} from 'jest-validate';
import {clearLine, replacePathSepForGlob} from 'jest-util';
import {clearLine, replacePathSepForGlob, tryRealpath} from 'jest-util';
import chalk = require('chalk');
import micromatch = require('micromatch');
import {sync as realpath} from 'realpath-native';
import Resolver = require('jest-resolve');
import {replacePathSepForRegex} from 'jest-regex-util';
import merge = require('deepmerge');
Expand Down Expand Up @@ -391,7 +390,7 @@ const normalizeRootDir = (

try {
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
options.rootDir = realpath(options.rootDir);
options.rootDir = tryRealpath(options.rootDir);
} catch (e) {
// ignored
}
Expand Down Expand Up @@ -955,7 +954,7 @@ export default function normalize(

try {
// try to resolve windows short paths, ignoring errors (permission errors, mostly)
newOptions.cwd = realpath(process.cwd());
newOptions.cwd = tryRealpath(process.cwd());
} catch (e) {
// ignored
}
Expand Down
1 change: 0 additions & 1 deletion packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"jest-watcher": "^26.0.0-alpha.0",
"micromatch": "^4.0.2",
"p-each-series": "^2.1.0",
"realpath-native": "^2.0.0",
"rimraf": "^3.0.0",
"slash": "^3.0.0",
"strip-ansi": "^6.0.0"
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import * as path from 'path';
import chalk = require('chalk');
import {sync as realpath} from 'realpath-native';
import {CustomConsole} from '@jest/console';
import {interopRequireDefault} from 'jest-util';
import {interopRequireDefault, tryRealpath} from 'jest-util';
import exit = require('exit');
import * as fs from 'graceful-fs';
import {JestHook, JestHookEmitter} from 'jest-watcher';
Expand Down Expand Up @@ -100,7 +99,7 @@ const processResults = (
}
if (isJSON) {
if (outputFile) {
const cwd = realpath(process.cwd());
const cwd = tryRealpath(process.cwd());
const filePath = path.resolve(cwd, outputFile);

fs.writeFileSync(filePath, JSON.stringify(formatTestResults(runResults)));
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-resolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"types": "build/index.d.ts",
"dependencies": {
"@jest/types": "^26.0.0-alpha.0",
"jest-util": "^26.0.0-alpha.0",
"chalk": "^4.0.0",
"graceful-fs": "^4.2.4",
"jest-pnp-resolver": "^1.2.1",
"read-pkg-up": "^7.0.1",
"realpath-native": "^2.0.0",
"resolve": "^1.17.0",
"slash": "^3.0.0"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-resolve/src/__tests__/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ describe('Resolver.getModulePaths() -> nodeModulesPaths()', () => {
// pathstrings instead of actually trying to access the physical directory.
// This test suite won't work otherwise, since we cannot make assumptions
// about the test environment when it comes to absolute paths.
jest.doMock('realpath-native', () => ({
sync: (dirInput: string) => dirInput,
jest.doMock('graceful-fs', () => ({
...jest.requireActual('graceful-fs'),
realPathSync: {
native: (dirInput: string) => dirInput,
},
}));
});

Expand Down
14 changes: 2 additions & 12 deletions packages/jest-resolve/src/defaultResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import * as fs from 'graceful-fs';
import {sync as resolveSync} from 'resolve';
import {sync as realpath} from 'realpath-native';
import pnpResolver from 'jest-pnp-resolver';
import {tryRealpath} from 'jest-util';
import type {Config} from '@jest/types';

type ResolverOptions = {
Expand Down Expand Up @@ -95,17 +95,7 @@ function realpathCached(path: Config.Path): Config.Path {
return result;
}

try {
result = realpath(path);
} catch (error) {
if (error.code !== 'ENOENT') {
throw error;
}
}

if (!result) {
result = path;
}
result = tryRealpath(path);

checkedRealpathPaths.set(path, result);

Expand Down
7 changes: 3 additions & 4 deletions packages/jest-resolve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import * as path from 'path';
import type {Config} from '@jest/types';
import type {ModuleMap} from 'jest-haste-map';
import {sync as realpath} from 'realpath-native';
import chalk = require('chalk');
import {tryRealpath} from 'jest-util';
import nodeModulesPaths from './nodeModulesPaths';
import isBuiltinModule from './isBuiltinModule';
import defaultResolver, {clearDefaultResolverCache} from './defaultResolver';
import type {ResolverConfig} from './types';
import ModuleNotFoundError from './ModuleNotFoundError';
import shouldLoadAsEsm, {clearCachedLookups} from './shouldLoadAsEsm';
import chalk = require('chalk');

type FindNodeModuleConfig = {
basedir: Config.Path;
Expand All @@ -41,8 +41,7 @@ namespace Resolver {
const NATIVE_PLATFORM = 'native';

// We might be inside a symlink.
const cwd = process.cwd();
const resolvedCwd = realpath(cwd) || cwd;
const resolvedCwd = tryRealpath(process.cwd());
const {NODE_PATH} = process.env;
const nodePaths = NODE_PATH
? NODE_PATH.split(path.delimiter)
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-resolve/src/nodeModulesPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import * as path from 'path';
import type {Config} from '@jest/types';
import {sync as realpath} from 'realpath-native';
import {tryRealpath} from 'jest-util';

type NodeModulesPathsOptions = {
moduleDirectory?: Array<string>;
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function nodeModulesPaths(
// traverses parents of the physical path, not the symlinked path
let physicalBasedir;
try {
physicalBasedir = realpath(basedirAbs);
physicalBasedir = tryRealpath(basedirAbs);
} catch (err) {
// realpath can throw, e.g. on mapped drives
physicalBasedir = basedirAbs;
Expand Down
1 change: 0 additions & 1 deletion packages/jest-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"jest-snapshot": "^26.0.0-alpha.0",
"jest-util": "^26.0.0-alpha.0",
"jest-validate": "^26.0.0-alpha.0",
"realpath-native": "^2.0.0",
"slash": "^3.0.0",
"strip-bom": "^4.0.0",
"yargs": "^15.3.1"
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-runtime/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import {cpus} from 'os';
import * as path from 'path';
import chalk = require('chalk');
import {sync as realpath} from 'realpath-native';
import yargs = require('yargs');
import type {Config} from '@jest/types';
import type {JestEnvironment} from '@jest/environment';
import {CustomConsole} from '@jest/console';
import {setGlobal} from 'jest-util';
import {setGlobal, tryRealpath} from 'jest-util';
import {validateCLIOptions} from 'jest-validate';
import {deprecationEntries, readConfig} from 'jest-config';
import {VERSION} from '../version';
Expand Down Expand Up @@ -53,7 +52,7 @@ export async function run(
return;
}

const root = realpath(process.cwd());
const root = tryRealpath(process.cwd());
const filePath = path.resolve(root, argv._[0]);

if (argv.debug) {
Expand Down
1 change: 0 additions & 1 deletion packages/jest-transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"jest-util": "^26.0.0-alpha.0",
"micromatch": "^4.0.2",
"pirates": "^4.0.1",
"realpath-native": "^2.0.0",
"slash": "^3.0.0",
"source-map": "^0.6.1",
"write-file-atomic": "^3.0.0"
Expand Down
18 changes: 7 additions & 11 deletions packages/jest-transform/src/ScriptTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import {createHash} from 'crypto';
import * as path from 'path';
import type {Config} from '@jest/types';
import {createDirectory, interopRequireDefault, isPromise} from 'jest-util';
import {
createDirectory,
interopRequireDefault,
isPromise,
tryRealpath,
} from 'jest-util';
import * as fs from 'graceful-fs';
import {transformSync as babelTransform} from '@babel/core';
// @ts-ignore: should just be `require.resolve`, but the tests mess that up
Expand All @@ -18,7 +23,6 @@ import HasteMap = require('jest-haste-map');
import stableStringify = require('fast-json-stable-stringify');
import slash = require('slash');
import {sync as writeFileAtomic} from 'write-file-atomic';
import {sync as realpath} from 'realpath-native';
import {addHook} from 'pirates';
import type {
Options,
Expand Down Expand Up @@ -247,14 +251,6 @@ export default class ScriptTransformer {
return input;
}

private _getRealPath(filepath: Config.Path): Config.Path {
try {
return realpath(filepath) || filepath;
} catch (err) {
return filepath;
}
}

// We don't want to expose transformers to the outside - this function is just
// to warm up `this._transformCache`
preloadTransformer(filepath: Config.Path): void {
Expand All @@ -269,7 +265,7 @@ export default class ScriptTransformer {
supportsDynamicImport = false,
supportsStaticESM = false,
): TransformResult {
const filename = this._getRealPath(filepath);
const filename = tryRealpath(filepath);
const transform = this._getTransformer(filename);
const cacheFilePath = this._getFileCachePath(
filename,
Expand Down
Loading