Skip to content

Commit 199f981

Browse files
authored
chore: remove Path and Glob (#12406)
1 parent 4f4538c commit 199f981

File tree

86 files changed

+401
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+401
-490
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- `[jest-serializer]` [**BREAKING**] Deprecate package in favour of using `v8` APIs directly ([#12391](https://github.com/facebook/jest/pull/12391))
4949
- `[jest-snapshot]` [**BREAKING**] Migrate to ESM ([#12342](https://github.com/facebook/jest/pull/12342))
5050
- `[jest-transform]` Update `write-file-atomic` to v4 ([#12357](https://github.com/facebook/jest/pull/12357))
51+
- `[jest-types]` [**BREAKING**] Remove `Config.Glob` and `Config.Path` ([#12406](https://github.com/facebook/jest/pull/12406))
5152
- `[jest]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329))
5253

5354
### Performance

e2e/Utils.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface RunResult extends ExecaReturnValue {
2020
}
2121
export const run = (
2222
cmd: string,
23-
cwd?: Config.Path,
23+
cwd?: string,
2424
env?: Record<string, string>,
2525
): RunResult => {
2626
const args = cmd.split(/\s/).slice(1);
@@ -44,10 +44,7 @@ export const run = (
4444
return result;
4545
};
4646

47-
export const runYarnInstall = (
48-
cwd: Config.Path,
49-
env?: Record<string, string>,
50-
) => {
47+
export const runYarnInstall = (cwd: string, env?: Record<string, string>) => {
5148
const lockfilePath = path.resolve(cwd, 'yarn.lock');
5249
let exists = true;
5350

@@ -60,7 +57,7 @@ export const runYarnInstall = (
6057
return run(exists ? 'yarn install --immutable' : 'yarn install', cwd, env);
6158
};
6259

63-
export const linkJestPackage = (packageName: string, cwd: Config.Path) => {
60+
export const linkJestPackage = (packageName: string, cwd: string) => {
6461
const packagesDir = path.resolve(__dirname, '../packages');
6562
const packagePath = path.resolve(packagesDir, packageName);
6663
const destination = path.resolve(cwd, 'node_modules/', packageName);
@@ -182,7 +179,7 @@ const DEFAULT_PACKAGE_JSON: JestPackageJson = {
182179
};
183180

184181
export const createEmptyPackage = (
185-
directory: Config.Path,
182+
directory: string,
186183
packageJson: PackageJson = DEFAULT_PACKAGE_JSON,
187184
) => {
188185
const packageJsonWithDefaults = {

packages/babel-jest/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
},
2020
"dependencies": {
2121
"@jest/transform": "^28.0.0-alpha.1",
22-
"@jest/types": "^28.0.0-alpha.1",
2322
"@types/babel__core": "^7.1.14",
2423
"babel-plugin-istanbul": "^6.1.1",
2524
"babel-preset-jest": "^28.0.0-alpha.0",

packages/babel-jest/src/index.ts

+12-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import type {
2020
TransformOptions as JestTransformOptions,
2121
SyncTransformer,
2222
} from '@jest/transform';
23-
import type {Config} from '@jest/types';
2423
import {loadPartialConfig, loadPartialConfigAsync} from './loadBabelConfig';
2524

2625
const THIS_FILE = fs.readFileSync(__filename);
@@ -31,8 +30,8 @@ type CreateTransformer = SyncTransformer<TransformOptions>['createTransformer'];
3130

3231
function assertLoadedBabelConfig(
3332
babelConfig: Readonly<PartialConfig> | null,
34-
cwd: Config.Path,
35-
filename: Config.Path,
33+
cwd: string,
34+
filename: string,
3635
): asserts babelConfig {
3736
if (!babelConfig) {
3837
throw new Error(
@@ -72,7 +71,7 @@ function addIstanbulInstrumentation(
7271

7372
function getCacheKeyFromConfig(
7473
sourceText: string,
75-
sourcePath: Config.Path,
74+
sourcePath: string,
7675
babelOptions: PartialConfig,
7776
transformOptions: JestTransformOptions,
7877
): string {
@@ -104,8 +103,8 @@ function getCacheKeyFromConfig(
104103
}
105104

106105
function loadBabelConfig(
107-
cwd: Config.Path,
108-
filename: Config.Path,
106+
cwd: string,
107+
filename: string,
109108
transformOptions: TransformOptions,
110109
): PartialConfig {
111110
const babelConfig = loadPartialConfig(transformOptions);
@@ -116,8 +115,8 @@ function loadBabelConfig(
116115
}
117116

118117
async function loadBabelConfigAsync(
119-
cwd: Config.Path,
120-
filename: Config.Path,
118+
cwd: string,
119+
filename: string,
121120
transformOptions: TransformOptions,
122121
): Promise<PartialConfig> {
123122
const babelConfig = await loadPartialConfigAsync(transformOptions);
@@ -128,8 +127,8 @@ async function loadBabelConfigAsync(
128127
}
129128

130129
function loadBabelOptions(
131-
cwd: Config.Path,
132-
filename: Config.Path,
130+
cwd: string,
131+
filename: string,
133132
transformOptions: TransformOptions,
134133
jestTransformOptions: JestTransformOptions,
135134
): TransformOptions {
@@ -139,8 +138,8 @@ function loadBabelOptions(
139138
}
140139

141140
async function loadBabelOptionsAsync(
142-
cwd: Config.Path,
143-
filename: Config.Path,
141+
cwd: string,
142+
filename: string,
144143
transformOptions: TransformOptions,
145144
jestTransformOptions: JestTransformOptions,
146145
): Promise<TransformOptions> {
@@ -169,7 +168,7 @@ export const createTransformer: CreateTransformer = userOptions => {
169168
} as const;
170169

171170
function mergeBabelTransformOptions(
172-
filename: Config.Path,
171+
filename: string,
173172
transformOptions: JestTransformOptions,
174173
): TransformOptions {
175174
const {cwd} = transformOptions.config;

packages/babel-jest/tsconfig.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@
77
"include": ["./src/**/*"],
88
"exclude": ["./**/__tests__/**/*"],
99
// TODO: include `babel-preset-jest` if it's ever in TS even though we don't care about its types
10-
"references": [
11-
{"path": "../jest-transform"},
12-
{"path": "../jest-types"},
13-
{"path": "../test-utils"}
14-
]
10+
"references": [{"path": "../jest-transform"}, {"path": "../test-utils"}]
1511
}

packages/expect/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
},
2020
"dependencies": {
2121
"@jest/expect-utils": "^28.0.0-alpha.1",
22-
"@jest/types": "^28.0.0-alpha.1",
2322
"jest-get-type": "^28.0.0-alpha.0",
2423
"jest-matcher-utils": "^28.0.0-alpha.1",
2524
"jest-message-util": "^28.0.0-alpha.1"

packages/expect/src/types.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import type {EqualsFunction, Tester} from '@jest/expect-utils';
10-
import type {Config} from '@jest/types';
1110
import type * as jestMatcherUtils from 'jest-matcher-utils';
1211
import {INTERNAL_MATCHER_FLAG} from './jestMatchersObject';
1312

@@ -56,7 +55,7 @@ export interface MatcherState {
5655
isNot: boolean;
5756
promise: string;
5857
suppressedErrors: Array<Error>;
59-
testPath?: Config.Path;
58+
testPath?: string;
6059
utils: typeof jestMatcherUtils & {
6160
iterableEquality: Tester;
6261
subsetEquality: Tester;

packages/expect/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
{"path": "../jest-get-type"},
1212
{"path": "../jest-matcher-utils"},
1313
{"path": "../jest-message-util"},
14-
{"path": "../jest-types"},
1514
{"path": "../test-utils"}
1615
]
1716
}

packages/jest-changed-files/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"./package.json": "./package.json"
1818
},
1919
"dependencies": {
20-
"@jest/types": "^28.0.0-alpha.1",
2120
"execa": "^5.0.0",
2221
"throat": "^6.0.1"
2322
},

packages/jest-changed-files/src/git.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
import * as path from 'path';
1010
import execa = require('execa');
11-
import type {Config} from '@jest/types';
1211
import type {SCMAdapter} from './types';
1312

1413
const findChangedFilesUsingCommand = async (
1514
args: Array<string>,
16-
cwd: Config.Path,
17-
): Promise<Array<Config.Path>> => {
15+
cwd: string,
16+
): Promise<Array<string>> => {
1817
let result: execa.ExecaReturnValue;
1918

2019
try {

packages/jest-changed-files/src/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import throat from 'throat';
10-
import type {Config} from '@jest/types';
1110
import git from './git';
1211
import hg from './hg';
1312
import type {ChangedFilesPromise, Options, Repos, SCMAdapter} from './types';
@@ -28,7 +27,7 @@ const findGitRoot = (dir: string) => mutex(() => git.getRoot(dir));
2827
const findHgRoot = (dir: string) => mutex(() => hg.getRoot(dir));
2928

3029
export const getChangedFilesForRoots = async (
31-
roots: Array<Config.Path>,
30+
roots: Array<string>,
3231
options: Options,
3332
): ChangedFilesPromise => {
3433
const repos = await findRepos(roots);
@@ -56,7 +55,7 @@ export const getChangedFilesForRoots = async (
5655
return {changedFiles, repos};
5756
};
5857

59-
export const findRepos = async (roots: Array<Config.Path>): Promise<Repos> => {
58+
export const findRepos = async (roots: Array<string>): Promise<Repos> => {
6059
const gitRepos = await Promise.all(
6160
roots.reduce<Array<RootPromise>>(
6261
(promises, root) => promises.concat(findGitRoot(root)),

packages/jest-changed-files/src/types.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,19 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import type {Config} from '@jest/types';
9-
108
export type Options = {
119
lastCommit?: boolean;
1210
withAncestor?: boolean;
1311
changedSince?: string;
14-
includePaths?: Array<Config.Path>;
12+
includePaths?: Array<string>;
1513
};
1614

17-
type Paths = Set<Config.Path>;
15+
type Paths = Set<string>;
1816
export type Repos = {git: Paths; hg: Paths};
1917
export type ChangedFiles = {repos: Repos; changedFiles: Paths};
2018
export type ChangedFilesPromise = Promise<ChangedFiles>;
2119

2220
export type SCMAdapter = {
23-
findChangedFiles: (
24-
cwd: Config.Path,
25-
options: Options,
26-
) => Promise<Array<Config.Path>>;
27-
getRoot: (cwd: Config.Path) => Promise<Config.Path | null>;
21+
findChangedFiles: (cwd: string, options: Options) => Promise<Array<string>>;
22+
getRoot: (cwd: string) => Promise<string | null>;
2823
};

packages/jest-changed-files/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
"rootDir": "src",
55
"outDir": "build"
66
},
7-
"include": ["./src/**/*"],
8-
"references": [{"path": "../jest-types"}]
7+
"include": ["./src/**/*"]
98
}

packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export const initialize = async ({
5454
config: Config.ProjectConfig;
5555
environment: JestEnvironment;
5656
globalConfig: Config.GlobalConfig;
57-
localRequire: <T = unknown>(path: Config.Path) => T;
58-
testPath: Config.Path;
57+
localRequire: <T = unknown>(path: string) => T;
58+
testPath: string;
5959
parentProcess: Process;
6060
sendMessageToJest?: TestFileEvent;
6161
setGlobalsForRuntime: (globals: JestGlobals) => void;

packages/jest-cli/src/cli/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import * as args from './args';
2020

2121
export async function run(
2222
maybeArgv?: Array<string>,
23-
project?: Config.Path,
23+
project?: string,
2424
): Promise<void> {
2525
try {
2626
const argv = await buildArgv(maybeArgv);
@@ -85,10 +85,7 @@ export async function buildArgv(
8585
);
8686
}
8787

88-
const getProjectListFromCLIArgs = (
89-
argv: Config.Argv,
90-
project?: Config.Path,
91-
) => {
88+
const getProjectListFromCLIArgs = (argv: Config.Argv, project?: string) => {
9289
const projects = argv.projects ? argv.projects : [];
9390

9491
if (project) {

packages/jest-config/src/getCacheDirectory.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
import {tmpdir} from 'os';
99
import * as path from 'path';
10-
import type {Config} from '@jest/types';
1110
import {tryRealpath} from 'jest-util';
1211

13-
const getCacheDirectory: () => Config.Path = () => {
12+
const getCacheDirectory: () => string = () => {
1413
const {getuid} = process;
1514
const tmpdirPath = path.join(tryRealpath(tmpdir()), 'jest');
1615
if (getuid == null) {

packages/jest-config/src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ export {default as descriptions} from './Descriptions';
2525
export {constants};
2626

2727
type ReadConfig = {
28-
configPath: Config.Path | null | undefined;
28+
configPath: string | null | undefined;
2929
globalConfig: Config.GlobalConfig;
3030
hasDeprecationWarnings: boolean;
3131
projectConfig: Config.ProjectConfig;
3232
};
3333

3434
export async function readConfig(
3535
argv: Config.Argv,
36-
packageRootOrConfig: Config.Path | Config.InitialOptions,
36+
packageRootOrConfig: string | Config.InitialOptions,
3737
// Whether it needs to look into `--config` arg passed to CLI.
3838
// It only used to read initial config. If the initial config contains
3939
// `project` property, we don't want to read `--config` value and rather
4040
// read individual configs for every project.
4141
skipArgvConfigOption?: boolean,
42-
parentConfigDirname?: Config.Path | null,
42+
parentConfigDirname?: string | null,
4343
projectIndex = Infinity,
4444
skipMultipleConfigWarning = false,
4545
): Promise<ReadConfig> {
@@ -278,7 +278,7 @@ This usually means that your ${chalk.bold(
278278
// (and only) project.
279279
export async function readConfigs(
280280
argv: Config.Argv,
281-
projectPaths: Array<Config.Path>,
281+
projectPaths: Array<string>,
282282
): Promise<{
283283
globalConfig: Config.GlobalConfig;
284284
configs: Array<Config.ProjectConfig>;
@@ -288,7 +288,7 @@ export async function readConfigs(
288288
let hasDeprecationWarnings;
289289
let configs: Array<Config.ProjectConfig> = [];
290290
let projects = projectPaths;
291-
let configPath: Config.Path | null | undefined;
291+
let configPath: string | null | undefined;
292292

293293
if (projectPaths.length === 1) {
294294
const parsedConfig = await readConfig(argv, projects[0]);

packages/jest-config/src/normalize.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type AllOptions = Config.ProjectConfig & Config.GlobalConfig;
5454
const createConfigError = (message: string) =>
5555
new ValidationError(ERROR, message, DOCUMENTATION_NOTE);
5656

57-
function verifyDirectoryExists(path: Config.Path, key: string) {
57+
function verifyDirectoryExists(path: string, key: string) {
5858
try {
5959
const rootStat = statSync(path);
6060

@@ -257,7 +257,7 @@ const normalizeCollectCoverageOnlyFrom = (
257257
key: keyof Pick<Config.InitialOptions, 'collectCoverageOnlyFrom'>,
258258
) => {
259259
const initialCollectCoverageFrom = options[key];
260-
const collectCoverageOnlyFrom: Array<Config.Glob> = Array.isArray(
260+
const collectCoverageOnlyFrom: Array<string> = Array.isArray(
261261
initialCollectCoverageFrom,
262262
)
263263
? initialCollectCoverageFrom // passed from argv
@@ -278,7 +278,7 @@ const normalizeCollectCoverageFrom = (
278278
key: keyof Pick<Config.InitialOptions, 'collectCoverageFrom'>,
279279
) => {
280280
const initialCollectCoverageFrom = options[key];
281-
let value: Array<Config.Glob> | undefined;
281+
let value: Array<string> | undefined;
282282
if (!initialCollectCoverageFrom) {
283283
value = [];
284284
}
@@ -366,7 +366,7 @@ const normalizePreprocessor = (
366366

367367
const normalizeMissingOptions = (
368368
options: Config.InitialOptionsWithRootDir,
369-
configPath: Config.Path | null | undefined,
369+
configPath: string | null | undefined,
370370
projectIndex: number,
371371
): Config.InitialOptionsWithRootDir => {
372372
if (!options.name) {
@@ -550,7 +550,7 @@ function validateExtensionsToTreatAsEsm(
550550
export default async function normalize(
551551
initialOptions: Config.InitialOptions,
552552
argv: Config.Argv,
553-
configPath?: Config.Path | null,
553+
configPath?: string | null,
554554
projectIndex = Infinity,
555555
): Promise<{
556556
hasDeprecationWarnings: boolean;

0 commit comments

Comments
 (0)