Skip to content

Commit 7344e67

Browse files
committed
remove Path
1 parent 23cc87c commit 7344e67

File tree

10 files changed

+96
-123
lines changed

10 files changed

+96
-123
lines changed

packages/jest-resolve/src/ModuleNotFoundError.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
import * as path from 'path';
99
import slash = require('slash');
10-
import type {Config} from '@jest/types';
1110

1211
export default class ModuleNotFoundError extends Error {
1312
public code = 'MODULE_NOT_FOUND';
1413
public hint?: string;
15-
public requireStack?: Array<Config.Path>;
14+
public requireStack?: Array<string>;
1615
public siblingWithSimilarExtensionFound?: boolean;
1716
public moduleName?: string;
1817

@@ -24,7 +23,7 @@ export default class ModuleNotFoundError extends Error {
2423
this.moduleName = moduleName;
2524
}
2625

27-
public buildMessage(rootDir: Config.Path): void {
26+
public buildMessage(rootDir: string): void {
2827
if (!this._originalMessage) {
2928
this._originalMessage = this.message || '';
3029
}

packages/jest-resolve/src/__mocks__/conditions/node_modules/exports/package.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "__mocks__",
33
"version": "1.0.0",
4-
"dependencies": {
5-
}
4+
"dependencies": {}
65
}

packages/jest-resolve/src/defaultResolver.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
resolve as resolveExports,
1414
} from 'resolve.exports';
1515
import slash = require('slash');
16-
import type {Config} from '@jest/types';
1716
import {
1817
PkgJson,
1918
isDirectoryAsync,
@@ -30,14 +29,14 @@ const resolveSync = resolveAsync.sync;
3029
// copy from `resolve`'s types so we don't have their types in our definition
3130
// files
3231
export interface ResolverOptions {
33-
basedir: Config.Path;
32+
basedir: string;
3433
browser?: boolean;
3534
conditions?: Array<string>;
3635
defaultResolver: typeof defaultResolver;
3736
extensions?: Array<string>;
3837
moduleDirectory?: Array<string>;
39-
paths?: Array<Config.Path>;
40-
rootDir?: Config.Path;
38+
paths?: Array<string>;
39+
rootDir?: string;
4140
packageFilter?: (pkg: PkgJson, dir: string) => PkgJson;
4241
pathFilter?: (pkg: PkgJson, path: string, relativePath: string) => string;
4342
}
@@ -56,9 +55,9 @@ declare global {
5655
}
5756

5857
export function defaultResolver(
59-
path: Config.Path,
58+
path: string,
6059
options: ResolverOptions,
61-
): Config.Path {
60+
): string {
6261
// Yarn 2 adds support to `resolve` automatically so the pnpResolver is only
6362
// needed for Yarn 1 which implements version 1 of the pnp spec
6463
if (process.versions.pnp === '1') {
@@ -73,9 +72,9 @@ export function defaultResolver(
7372
}
7473

7574
export async function defaultResolverAsync(
76-
path: Config.Path,
75+
path: string,
7776
options: ResolverOptionsAsync,
78-
): Promise<Config.Path> {
77+
): Promise<string> {
7978
// Yarn 2 adds support to `resolve` automatically so the pnpResolver is only
8079
// needed for Yarn 1 which implements version 1 of the pnp spec
8180
if (process.versions.pnp === '1') {
@@ -101,7 +100,7 @@ export async function defaultResolverAsync(
101100
* getSyncResolveOptions returns resolution options that are used synchronously.
102101
*/
103102
function getSyncResolveOptions(
104-
path: Config.Path,
103+
path: string,
105104
options: ResolverOptions,
106105
): resolveAsync.SyncOpts {
107106
return {
@@ -120,7 +119,7 @@ function getSyncResolveOptions(
120119
* getAsyncResolveOptions returns resolution options that are used asynchronously.
121120
*/
122121
function getAsyncResolveOptions(
123-
path: Config.Path,
122+
path: string,
124123
options: ResolverOptionsAsync,
125124
): resolveAsync.AsyncOpts {
126125
return {
@@ -139,13 +138,13 @@ function getAsyncResolveOptions(
139138
* helper functions
140139
*/
141140

142-
function readPackageSync(_: unknown, file: Config.Path): PkgJson {
141+
function readPackageSync(_: unknown, file: string): PkgJson {
143142
return readPackageCached(file);
144143
}
145144

146145
function readPackageAsync(
147146
_: unknown,
148-
pkgfile: Config.Path,
147+
pkgfile: string,
149148
cb: (err: Error | null, pkgJson?: PkgJson) => void,
150149
): void {
151150
try {
@@ -158,7 +157,7 @@ function readPackageAsync(
158157
}
159158

160159
function createPackageFilter(
161-
originalPath: Config.Path,
160+
originalPath: string,
162161
userFilter?: ResolverOptions['packageFilter'],
163162
): ResolverOptions['packageFilter'] {
164163
if (shouldIgnoreRequestForExports(originalPath)) {
@@ -186,7 +185,7 @@ function createPackageFilter(
186185
}
187186

188187
function createPathFilter(
189-
originalPath: Config.Path,
188+
originalPath: string,
190189
conditions?: Array<string>,
191190
userFilter?: ResolverOptions['pathFilter'],
192191
): ResolverOptions['pathFilter'] {
@@ -221,5 +220,5 @@ function createPathFilter(
221220
}
222221

223222
// if it's a relative import or an absolute path, exports are ignored
224-
const shouldIgnoreRequestForExports = (path: Config.Path) =>
223+
const shouldIgnoreRequestForExports = (path: string) =>
225224
path.startsWith('.') || isAbsolute(path);

packages/jest-resolve/src/fileWalkers.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import {dirname, resolve} from 'path';
99
import * as fs from 'graceful-fs';
10-
import type {Config} from '@jest/types';
1110
import {tryRealpath} from 'jest-util';
1211

1312
export function clearFsCache(): void {
@@ -53,7 +52,7 @@ function statSyncCached(path: string): IPathType {
5352
}
5453

5554
const checkedRealpathPaths = new Map<string, string>();
56-
function realpathCached(path: Config.Path): Config.Path {
55+
function realpathCached(path: string): string {
5756
let result = checkedRealpathPaths.get(path);
5857

5958
if (result != null) {
@@ -75,7 +74,7 @@ function realpathCached(path: Config.Path): Config.Path {
7574
export type PkgJson = Record<string, unknown>;
7675

7776
const packageContents = new Map<string, PkgJson>();
78-
export function readPackageCached(path: Config.Path): PkgJson {
77+
export function readPackageCached(path: string): PkgJson {
7978
let result = packageContents.get(path);
8079

8180
if (result != null) {
@@ -92,9 +91,7 @@ export function readPackageCached(path: Config.Path): PkgJson {
9291
// adapted from
9392
// https://github.com/lukeed/escalade/blob/2477005062cdbd8407afc90d3f48f4930354252b/src/sync.js
9493
// to use cached `fs` calls
95-
export function findClosestPackageJson(
96-
start: Config.Path,
97-
): Config.Path | undefined {
94+
export function findClosestPackageJson(start: string): string | undefined {
9895
let dir = resolve('.', start);
9996
if (!isDirectorySync(dir)) {
10097
dir = dirname(dir);
@@ -120,12 +117,12 @@ export function findClosestPackageJson(
120117
/*
121118
* helper functions
122119
*/
123-
export function isFileSync(file: Config.Path): boolean {
120+
export function isFileSync(file: string): boolean {
124121
return statSyncCached(file) === IPathType.FILE;
125122
}
126123

127124
export function isFileAsync(
128-
file: Config.Path,
125+
file: string,
129126
cb: (err: Error | null, isFile?: boolean) => void,
130127
): void {
131128
try {
@@ -137,12 +134,12 @@ export function isFileAsync(
137134
}
138135
}
139136

140-
export function isDirectorySync(dir: Config.Path): boolean {
137+
export function isDirectorySync(dir: string): boolean {
141138
return statSyncCached(dir) === IPathType.DIRECTORY;
142139
}
143140

144141
export function isDirectoryAsync(
145-
dir: Config.Path,
142+
dir: string,
146143
cb: (err: Error | null, isDir?: boolean) => void,
147144
): void {
148145
try {
@@ -154,13 +151,13 @@ export function isDirectoryAsync(
154151
}
155152
}
156153

157-
export function realpathSync(file: Config.Path): Config.Path {
154+
export function realpathSync(file: string): string {
158155
return realpathCached(file);
159156
}
160157

161158
export function realpathAsync(
162-
file: Config.Path,
163-
cb: (err: Error | null, resolved?: Config.Path) => void,
159+
file: string,
160+
cb: (err: Error | null, resolved?: string) => void,
164161
): void {
165162
try {
166163
// TODO: create an async version of realpathCached

packages/jest-resolve/src/nodeModulesPaths.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
*/
99

1010
import * as path from 'path';
11-
import type {Config} from '@jest/types';
1211
import {tryRealpath} from 'jest-util';
1312

1413
type NodeModulesPathsOptions = {
1514
moduleDirectory?: Array<string>;
16-
paths?: Array<Config.Path>;
15+
paths?: Array<string>;
1716
};
1817

1918
export default function nodeModulesPaths(
20-
basedir: Config.Path,
19+
basedir: string,
2120
options: NodeModulesPathsOptions,
22-
): Array<Config.Path> {
21+
): Array<string> {
2322
const modules =
2423
options && options.moduleDirectory
2524
? Array.from(options.moduleDirectory)
@@ -46,15 +45,15 @@ export default function nodeModulesPaths(
4645
physicalBasedir = basedirAbs;
4746
}
4847

49-
const paths: Array<Config.Path> = [physicalBasedir];
48+
const paths: Array<string> = [physicalBasedir];
5049
let parsed = path.parse(physicalBasedir);
5150
while (parsed.dir !== paths[paths.length - 1]) {
5251
paths.push(parsed.dir);
5352
parsed = path.parse(parsed.dir);
5453
}
5554

5655
const dirs = paths
57-
.reduce<Array<Config.Path>>(
56+
.reduce<Array<string>>(
5857
(dirs, aPath) =>
5958
dirs.concat(
6059
modules.map(moduleDir =>

0 commit comments

Comments
 (0)