Skip to content

Commit

Permalink
Apply solution without isGlobalProject
Browse files Browse the repository at this point in the history
  • Loading branch information
kenrick95 committed Nov 22, 2019
1 parent d4de301 commit e6d6c66
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
18 changes: 4 additions & 14 deletions packages/jest-cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,9 @@ export async function run(maybeArgv?: Array<string>, project?: Config.Path) {
return;
}

const {isGlobalProject, projects} = getProjectListFromCLIArgs(
argv,
project,
);

const {results, globalConfig} = await runCLI(
argv,
projects,
isGlobalProject,
);
const projects = getProjectListFromCLIArgs(argv, project);

const {results, globalConfig} = await runCLI(argv, projects);
readResultsAndExit(results, globalConfig);
} catch (error) {
clearLine(process.stderr);
Expand Down Expand Up @@ -90,7 +83,6 @@ const getProjectListFromCLIArgs = (
argv: Config.Argv,
project?: Config.Path,
) => {
let isGlobalProject = false;
const projects = argv.projects ? argv.projects : [];

if (project) {
Expand All @@ -100,19 +92,17 @@ const getProjectListFromCLIArgs = (
if (!projects.length && process.platform === 'win32') {
try {
projects.push(realpath(process.cwd()));
isGlobalProject = true;
} catch (err) {
// do nothing, just catch error
// process.binding('fs').realpath can throw, e.g. on mapped drives
}
}

if (!projects.length) {
isGlobalProject = true;
projects.push(process.cwd());
}

return {isGlobalProject, projects};
return projects;
};

const readResultsAndExit = (
Expand Down
8 changes: 5 additions & 3 deletions packages/jest-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as fs from 'fs';
import * as path from 'path';
import {Config} from '@jest/types';
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 @@ -263,7 +264,6 @@ This usually means that your ${chalk.bold(
export function readConfigs(
argv: Config.Argv,
projectPaths: Array<Config.Path>,
isGlobalProject: boolean,
): {
globalConfig: Config.GlobalConfig;
configs: Array<Config.ProjectConfig>;
Expand Down Expand Up @@ -308,10 +308,12 @@ export function readConfigs(
return true;
})
.map((root, projectIndex) => {
// Skip on all except: projectIndex === 0, and isGlobalProject, and projects.length === 1
// Skip on all except: projectIndex === 0, projects[0] === process.cwd() or realpath(process.cwd()) on Windows, and projects.length === 1
const skipArgvConfigOption = !(
projectIndex === 0 &&
isGlobalProject &&
(process.platform === 'win32'
? projects[0] === realpath(process.cwd())
: projects[0] === process.cwd()) &&
projects.length === 1
);
return readConfig(
Expand Down
2 changes: 0 additions & 2 deletions packages/jest-core/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type OnCompleteCallback = (results: AggregatedResult) => void;
export const runCLI = async (
argv: Config.Argv,
projects: Array<Config.Path>,
isGlobalProject: boolean,
): Promise<{
results: AggregatedResult;
globalConfig: Config.GlobalConfig;
Expand All @@ -53,7 +52,6 @@ export const runCLI = async (
const {globalConfig, configs, hasDeprecationWarnings} = readConfigs(
argv,
projects,
isGlobalProject,
);

if (argv.debug) {
Expand Down

0 comments on commit e6d6c66

Please sign in to comment.