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 Path and Glob #12406

Merged
merged 5 commits into from Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -47,6 +47,7 @@
- `[jest-serializer]` [**BREAKING**] Deprecate package in favour of using `v8` APIs directly ([#12391](https://github.com/facebook/jest/pull/12391))
- `[jest-snapshot]` [**BREAKING**] Migrate to ESM ([#12342](https://github.com/facebook/jest/pull/12342))
- `[jest-transform]` Update `write-file-atomic` to v4 ([#12357](https://github.com/facebook/jest/pull/12357))
- `[jest-types]` [**BREAKING**] Remove `Config.Glob` and `Config.Path` ([#12406](https://github.com/facebook/jest/pull/12406))
- `[jest]` Use `index.ts` instead of `jest.ts` as main export ([#12329](https://github.com/facebook/jest/pull/12329))
- `[docs]` Add note about not mixing `done()` with Promises ([#11077](https://github.com/facebook/jest/pull/11077))

Expand Down
11 changes: 4 additions & 7 deletions e2e/Utils.ts
Expand Up @@ -20,7 +20,7 @@ interface RunResult extends ExecaReturnValue {
}
export const run = (
cmd: string,
cwd?: Config.Path,
cwd?: string,
env?: Record<string, string>,
): RunResult => {
const args = cmd.split(/\s/).slice(1);
Expand All @@ -44,10 +44,7 @@ export const run = (
return result;
};

export const runYarnInstall = (
cwd: Config.Path,
env?: Record<string, string>,
) => {
export const runYarnInstall = (cwd: string, env?: Record<string, string>) => {
const lockfilePath = path.resolve(cwd, 'yarn.lock');
let exists = true;

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

export const linkJestPackage = (packageName: string, cwd: Config.Path) => {
export const linkJestPackage = (packageName: string, cwd: string) => {
const packagesDir = path.resolve(__dirname, '../packages');
const packagePath = path.resolve(packagesDir, packageName);
const destination = path.resolve(cwd, 'node_modules/', packageName);
Expand Down Expand Up @@ -182,7 +179,7 @@ const DEFAULT_PACKAGE_JSON: JestPackageJson = {
};

export const createEmptyPackage = (
directory: Config.Path,
directory: string,
packageJson: PackageJson = DEFAULT_PACKAGE_JSON,
) => {
const packageJsonWithDefaults = {
Expand Down
1 change: 0 additions & 1 deletion packages/babel-jest/package.json
Expand Up @@ -19,7 +19,6 @@
},
"dependencies": {
"@jest/transform": "^28.0.0-alpha.1",
"@jest/types": "^28.0.0-alpha.1",
"@types/babel__core": "^7.1.14",
"babel-plugin-istanbul": "^6.1.1",
"babel-preset-jest": "^28.0.0-alpha.0",
Expand Down
25 changes: 12 additions & 13 deletions packages/babel-jest/src/index.ts
Expand Up @@ -20,7 +20,6 @@ import type {
TransformOptions as JestTransformOptions,
SyncTransformer,
} from '@jest/transform';
import type {Config} from '@jest/types';
import {loadPartialConfig, loadPartialConfigAsync} from './loadBabelConfig';

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

function assertLoadedBabelConfig(
babelConfig: Readonly<PartialConfig> | null,
cwd: Config.Path,
filename: Config.Path,
cwd: string,
filename: string,
): asserts babelConfig {
if (!babelConfig) {
throw new Error(
Expand Down Expand Up @@ -72,7 +71,7 @@ function addIstanbulInstrumentation(

function getCacheKeyFromConfig(
sourceText: string,
sourcePath: Config.Path,
sourcePath: string,
babelOptions: PartialConfig,
transformOptions: JestTransformOptions,
): string {
Expand Down Expand Up @@ -104,8 +103,8 @@ function getCacheKeyFromConfig(
}

function loadBabelConfig(
cwd: Config.Path,
filename: Config.Path,
cwd: string,
filename: string,
transformOptions: TransformOptions,
): PartialConfig {
const babelConfig = loadPartialConfig(transformOptions);
Expand All @@ -116,8 +115,8 @@ function loadBabelConfig(
}

async function loadBabelConfigAsync(
cwd: Config.Path,
filename: Config.Path,
cwd: string,
filename: string,
transformOptions: TransformOptions,
): Promise<PartialConfig> {
const babelConfig = await loadPartialConfigAsync(transformOptions);
Expand All @@ -128,8 +127,8 @@ async function loadBabelConfigAsync(
}

function loadBabelOptions(
cwd: Config.Path,
filename: Config.Path,
cwd: string,
filename: string,
transformOptions: TransformOptions,
jestTransformOptions: JestTransformOptions,
): TransformOptions {
Expand All @@ -139,8 +138,8 @@ function loadBabelOptions(
}

async function loadBabelOptionsAsync(
cwd: Config.Path,
filename: Config.Path,
cwd: string,
filename: string,
transformOptions: TransformOptions,
jestTransformOptions: JestTransformOptions,
): Promise<TransformOptions> {
Expand Down Expand Up @@ -169,7 +168,7 @@ export const createTransformer: CreateTransformer = userOptions => {
} as const;

function mergeBabelTransformOptions(
filename: Config.Path,
filename: string,
transformOptions: JestTransformOptions,
): TransformOptions {
const {cwd} = transformOptions.config;
Expand Down
6 changes: 1 addition & 5 deletions packages/babel-jest/tsconfig.json
Expand Up @@ -7,9 +7,5 @@
"include": ["./src/**/*"],
"exclude": ["./**/__tests__/**/*"],
// TODO: include `babel-preset-jest` if it's ever in TS even though we don't care about its types
"references": [
{"path": "../jest-transform"},
{"path": "../jest-types"},
{"path": "../test-utils"}
]
"references": [{"path": "../jest-transform"}, {"path": "../test-utils"}]
}
1 change: 0 additions & 1 deletion packages/expect/package.json
Expand Up @@ -19,7 +19,6 @@
},
"dependencies": {
"@jest/expect-utils": "^28.0.0-alpha.1",
"@jest/types": "^28.0.0-alpha.1",
"jest-get-type": "^28.0.0-alpha.0",
"jest-matcher-utils": "^28.0.0-alpha.1",
"jest-message-util": "^28.0.0-alpha.1"
Expand Down
3 changes: 1 addition & 2 deletions packages/expect/src/types.ts
Expand Up @@ -7,7 +7,6 @@
*/

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

Expand Down Expand Up @@ -56,7 +55,7 @@ export interface MatcherState {
isNot: boolean;
promise: string;
suppressedErrors: Array<Error>;
testPath?: Config.Path;
testPath?: string;
utils: typeof jestMatcherUtils & {
iterableEquality: Tester;
subsetEquality: Tester;
Expand Down
1 change: 0 additions & 1 deletion packages/expect/tsconfig.json
Expand Up @@ -11,7 +11,6 @@
{"path": "../jest-get-type"},
{"path": "../jest-matcher-utils"},
{"path": "../jest-message-util"},
{"path": "../jest-types"},
{"path": "../test-utils"}
]
}
1 change: 0 additions & 1 deletion packages/jest-changed-files/package.json
Expand Up @@ -17,7 +17,6 @@
"./package.json": "./package.json"
},
"dependencies": {
"@jest/types": "^28.0.0-alpha.1",
"execa": "^5.0.0",
"throat": "^6.0.1"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-changed-files/src/git.ts
Expand Up @@ -8,13 +8,12 @@

import * as path from 'path';
import execa = require('execa');
import type {Config} from '@jest/types';
import type {SCMAdapter} from './types';

const findChangedFilesUsingCommand = async (
args: Array<string>,
cwd: Config.Path,
): Promise<Array<Config.Path>> => {
cwd: string,
): Promise<Array<string>> => {
let result: execa.ExecaReturnValue;

try {
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-changed-files/src/index.ts
Expand Up @@ -7,7 +7,6 @@
*/

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

export const getChangedFilesForRoots = async (
roots: Array<Config.Path>,
roots: Array<string>,
options: Options,
): ChangedFilesPromise => {
const repos = await findRepos(roots);
Expand Down Expand Up @@ -56,7 +55,7 @@ export const getChangedFilesForRoots = async (
return {changedFiles, repos};
};

export const findRepos = async (roots: Array<Config.Path>): Promise<Repos> => {
export const findRepos = async (roots: Array<string>): Promise<Repos> => {
const gitRepos = await Promise.all(
roots.reduce<Array<RootPromise>>(
(promises, root) => promises.concat(findGitRoot(root)),
Expand Down
13 changes: 4 additions & 9 deletions packages/jest-changed-files/src/types.ts
Expand Up @@ -5,24 +5,19 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Config} from '@jest/types';

export type Options = {
lastCommit?: boolean;
withAncestor?: boolean;
changedSince?: string;
includePaths?: Array<Config.Path>;
includePaths?: Array<string>;
};

type Paths = Set<Config.Path>;
type Paths = Set<string>;
export type Repos = {git: Paths; hg: Paths};
export type ChangedFiles = {repos: Repos; changedFiles: Paths};
export type ChangedFilesPromise = Promise<ChangedFiles>;

export type SCMAdapter = {
findChangedFiles: (
cwd: Config.Path,
options: Options,
) => Promise<Array<Config.Path>>;
getRoot: (cwd: Config.Path) => Promise<Config.Path | null>;
findChangedFiles: (cwd: string, options: Options) => Promise<Array<string>>;
getRoot: (cwd: string) => Promise<string | null>;
};
3 changes: 1 addition & 2 deletions packages/jest-changed-files/tsconfig.json
Expand Up @@ -4,6 +4,5 @@
"rootDir": "src",
"outDir": "build"
},
"include": ["./src/**/*"],
"references": [{"path": "../jest-types"}]
"include": ["./src/**/*"]
}
Expand Up @@ -54,8 +54,8 @@ export const initialize = async ({
config: Config.ProjectConfig;
environment: JestEnvironment;
globalConfig: Config.GlobalConfig;
localRequire: <T = unknown>(path: Config.Path) => T;
testPath: Config.Path;
localRequire: <T = unknown>(path: string) => T;
testPath: string;
parentProcess: Process;
sendMessageToJest?: TestFileEvent;
setGlobalsForRuntime: (globals: JestGlobals) => void;
Expand Down
7 changes: 2 additions & 5 deletions packages/jest-cli/src/cli/index.ts
Expand Up @@ -20,7 +20,7 @@ import * as args from './args';

export async function run(
maybeArgv?: Array<string>,
project?: Config.Path,
project?: string,
): Promise<void> {
try {
const argv = await buildArgv(maybeArgv);
Expand Down Expand Up @@ -85,10 +85,7 @@ export async function buildArgv(
);
}

const getProjectListFromCLIArgs = (
argv: Config.Argv,
project?: Config.Path,
) => {
const getProjectListFromCLIArgs = (argv: Config.Argv, project?: string) => {
const projects = argv.projects ? argv.projects : [];

if (project) {
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-config/src/getCacheDirectory.ts
Expand Up @@ -7,10 +7,9 @@

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

const getCacheDirectory: () => Config.Path = () => {
const getCacheDirectory: () => string = () => {
const {getuid} = process;
const tmpdirPath = path.join(tryRealpath(tmpdir()), 'jest');
if (getuid == null) {
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-config/src/index.ts
Expand Up @@ -25,21 +25,21 @@ export {default as descriptions} from './Descriptions';
export {constants};

type ReadConfig = {
configPath: Config.Path | null | undefined;
configPath: string | null | undefined;
globalConfig: Config.GlobalConfig;
hasDeprecationWarnings: boolean;
projectConfig: Config.ProjectConfig;
};

export async function readConfig(
argv: Config.Argv,
packageRootOrConfig: Config.Path | Config.InitialOptions,
packageRootOrConfig: string | Config.InitialOptions,
// Whether it needs to look into `--config` arg passed to CLI.
// It only used to read initial config. If the initial config contains
// `project` property, we don't want to read `--config` value and rather
// read individual configs for every project.
skipArgvConfigOption?: boolean,
parentConfigDirname?: Config.Path | null,
parentConfigDirname?: string | null,
projectIndex = Infinity,
skipMultipleConfigWarning = false,
): Promise<ReadConfig> {
Expand Down Expand Up @@ -278,7 +278,7 @@ This usually means that your ${chalk.bold(
// (and only) project.
export async function readConfigs(
argv: Config.Argv,
projectPaths: Array<Config.Path>,
projectPaths: Array<string>,
): Promise<{
globalConfig: Config.GlobalConfig;
configs: Array<Config.ProjectConfig>;
Expand All @@ -288,7 +288,7 @@ export async function readConfigs(
let hasDeprecationWarnings;
let configs: Array<Config.ProjectConfig> = [];
let projects = projectPaths;
let configPath: Config.Path | null | undefined;
let configPath: string | null | undefined;

if (projectPaths.length === 1) {
const parsedConfig = await readConfig(argv, projects[0]);
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-config/src/normalize.ts
Expand Up @@ -54,7 +54,7 @@ type AllOptions = Config.ProjectConfig & Config.GlobalConfig;
const createConfigError = (message: string) =>
new ValidationError(ERROR, message, DOCUMENTATION_NOTE);

function verifyDirectoryExists(path: Config.Path, key: string) {
function verifyDirectoryExists(path: string, key: string) {
try {
const rootStat = statSync(path);

Expand Down Expand Up @@ -257,7 +257,7 @@ const normalizeCollectCoverageOnlyFrom = (
key: keyof Pick<Config.InitialOptions, 'collectCoverageOnlyFrom'>,
) => {
const initialCollectCoverageFrom = options[key];
const collectCoverageOnlyFrom: Array<Config.Glob> = Array.isArray(
const collectCoverageOnlyFrom: Array<string> = Array.isArray(
initialCollectCoverageFrom,
)
? initialCollectCoverageFrom // passed from argv
Expand All @@ -278,7 +278,7 @@ const normalizeCollectCoverageFrom = (
key: keyof Pick<Config.InitialOptions, 'collectCoverageFrom'>,
) => {
const initialCollectCoverageFrom = options[key];
let value: Array<Config.Glob> | undefined;
let value: Array<string> | undefined;
if (!initialCollectCoverageFrom) {
value = [];
}
Expand Down Expand Up @@ -366,7 +366,7 @@ const normalizePreprocessor = (

const normalizeMissingOptions = (
options: Config.InitialOptionsWithRootDir,
configPath: Config.Path | null | undefined,
configPath: string | null | undefined,
projectIndex: number,
): Config.InitialOptionsWithRootDir => {
if (!options.name) {
Expand Down Expand Up @@ -550,7 +550,7 @@ function validateExtensionsToTreatAsEsm(
export default async function normalize(
initialOptions: Config.InitialOptions,
argv: Config.Argv,
configPath?: Config.Path | null,
configPath?: string | null,
projectIndex = Infinity,
): Promise<{
hasDeprecationWarnings: boolean;
Expand Down