chore(core): move readNxJson out of Workspaces (#18127)

This commit is contained in:
Emily Xiong 2023-07-21 10:07:34 -04:00 committed by GitHub
parent e12e9bb9dd
commit 717a8dd027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 78 additions and 144 deletions

View File

@ -6,7 +6,7 @@ import {
import type { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils'; import type { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
import { WebpackNxBuildCoordinationPlugin } from '@nx/webpack/src/plugins/webpack-nx-build-coordination-plugin'; import { WebpackNxBuildCoordinationPlugin } from '@nx/webpack/src/plugins/webpack-nx-build-coordination-plugin';
import { existsSync } from 'fs'; import { existsSync } from 'fs';
import { readNxJson } from 'nx/src/project-graph/file-utils'; import { readNxJson } from 'nx/src/config/nx-json';
import { isNpmProject } from 'nx/src/project-graph/operators'; import { isNpmProject } from 'nx/src/project-graph/operators';
import { getDependencyConfigs } from 'nx/src/tasks-runner/utils'; import { getDependencyConfigs } from 'nx/src/tasks-runner/utils';
import { from, Observable } from 'rxjs'; import { from, Observable } from 'rxjs';

View File

@ -13,7 +13,7 @@ import {
findProjectForPath, findProjectForPath,
} from 'nx/src/project-graph/utils/find-project-for-path'; } from 'nx/src/project-graph/utils/find-project-for-path';
import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph'; import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph';
import { readNxJson } from 'nx/src/project-graph/file-utils'; import { readNxJson } from 'nx/src/config/nx-json';
export const CY_FILE_MATCHER = new RegExp(/\.cy\.[tj]sx?$/); export const CY_FILE_MATCHER = new RegExp(/\.cy\.[tj]sx?$/);
/** /**

View File

@ -13,7 +13,7 @@ import {
Tree, Tree,
workspaceRoot, workspaceRoot,
} from '@nx/devkit'; } from '@nx/devkit';
import { readNxJson } from 'nx/src/project-graph/file-utils'; import { readNxJson } from 'nx/src/config/nx-json';
import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph'; import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph';
interface FindTargetOptions { interface FindTargetOptions {

View File

@ -47,11 +47,10 @@ export type {
*/ */
export { Workspaces } from 'nx/src/config/workspaces'; export { Workspaces } from 'nx/src/config/workspaces';
// TODO (v16): Change this to export from 'nx/src/config/configuration'
export { export {
readAllWorkspaceConfiguration, readAllWorkspaceConfiguration,
workspaceLayout, workspaceLayout,
} from 'nx/src/project-graph/file-utils'; } from 'nx/src/config/configuration';
export type { export type {
NxPlugin, NxPlugin,

View File

@ -2,7 +2,7 @@ import type { Observable } from 'rxjs';
import type { Executor, ExecutorContext } from 'nx/src/config/misc-interfaces'; import type { Executor, ExecutorContext } from 'nx/src/config/misc-interfaces';
import { requireNx } from '../../nx'; import { requireNx } from '../../nx';
const { Workspaces } = requireNx(); const { Workspaces, readNxJsonFromDisk } = requireNx();
/** /**
* Convert an Nx Executor into an Angular Devkit Builder * Convert an Nx Executor into an Angular Devkit Builder
@ -13,7 +13,9 @@ const { Workspaces } = requireNx();
export function convertNxExecutor(executor: Executor) { export function convertNxExecutor(executor: Executor) {
const builderFunction = (options, builderContext) => { const builderFunction = (options, builderContext) => {
const workspaces = new Workspaces(builderContext.workspaceRoot); const workspaces = new Workspaces(builderContext.workspaceRoot);
const nxJsonConfiguration = workspaces.readNxJson(); const nxJsonConfiguration = readNxJsonFromDisk(
builderContext.workspaceRoot
);
const projectsConfigurations = workspaces.readProjectsConfigurations({ const projectsConfigurations = workspaces.readProjectsConfigurations({
_includeProjectsFromAngularJson: true, _includeProjectsFromAngularJson: true,
}); });

View File

@ -9,7 +9,7 @@ import {
createProjectRootMappings, createProjectRootMappings,
ProjectRootMappings, ProjectRootMappings,
} from 'nx/src/project-graph/utils/find-project-for-path'; } from 'nx/src/project-graph/utils/find-project-for-path';
import { readNxJson } from 'nx/src/project-graph/file-utils'; import { readNxJson } from 'nx/src/config/nx-json';
import { TargetProjectLocator } from '@nx/js/src/internal'; import { TargetProjectLocator } from '@nx/js/src/internal';
import { readProjectFileMapCache } from 'nx/src/project-graph/nx-deps-cache'; import { readProjectFileMapCache } from 'nx/src/project-graph/nx-deps-cache';

View File

@ -1,5 +1,5 @@
import { join } from 'path'; import { join } from 'path';
import { readNxJson } from 'nx/src/project-graph/file-utils'; import { readNxJson } from 'nx/src/config/nx-json';
import { import {
getTargetInputs, getTargetInputs,
filterUsingGlobPatterns, filterUsingGlobPatterns,

View File

@ -10,10 +10,8 @@ import {
mapTargetDefaultsToDependencies, mapTargetDefaultsToDependencies,
} from '../../tasks-runner/create-task-graph'; } from '../../tasks-runner/create-task-graph';
import { NxJsonConfiguration } from '../../config/nx-json'; import { NxJsonConfiguration } from '../../config/nx-json';
import { Workspaces } from '../../config/workspaces';
import { InProcessTaskHasher } from '../../hasher/task-hasher'; import { InProcessTaskHasher } from '../../hasher/task-hasher';
import { hashTask } from '../../hasher/hash-task'; import { hashTask } from '../../hasher/hash-task';
import { workspaceRoot } from '../../utils/workspace-root';
import { getPackageManagerCommand } from '../../utils/package-manager'; import { getPackageManagerCommand } from '../../utils/package-manager';
import { fileHasher } from '../../hasher/file-hasher'; import { fileHasher } from '../../hasher/file-hasher';
import { printAffectedDeprecationMessage } from './command-object'; import { printAffectedDeprecationMessage } from './command-object';
@ -63,7 +61,6 @@ async function createTasks(
nxJson: NxJsonConfiguration, nxJson: NxJsonConfiguration,
overrides: yargs.Arguments overrides: yargs.Arguments
) { ) {
const workspaces = new Workspaces(workspaceRoot);
const defaultDependencyConfigs = mapTargetDefaultsToDependencies( const defaultDependencyConfigs = mapTargetDefaultsToDependencies(
nxJson.targetDefaults nxJson.targetDefaults
); );
@ -88,7 +85,7 @@ async function createTasks(
const tasks = Object.values(taskGraph.tasks); const tasks = Object.values(taskGraph.tasks);
await Promise.all( await Promise.all(
tasks.map((t) => hashTask(workspaces, hasher, projectGraph, {} as any, t)) tasks.map((t) => hashTask(hasher, projectGraph, {} as any, t))
); );
return tasks.map((task) => ({ return tasks.map((task) => ({

View File

@ -1,8 +1,6 @@
import { filterAffected } from '../../project-graph/affected/affected-project-graph'; import { filterAffected } from '../../project-graph/affected/affected-project-graph';
import { import { calculateFileChanges } from '../../project-graph/file-utils';
calculateFileChanges, import { readNxJson } from '../../config/nx-json';
readNxJson,
} from '../../project-graph/file-utils';
import { import {
NxArgs, NxArgs,
parseFiles, parseFiles,

View File

@ -2,10 +2,7 @@ import { Workspaces } from './workspaces';
import { workspaceRoot } from '../utils/workspace-root'; import { workspaceRoot } from '../utils/workspace-root';
import { NxJsonConfiguration } from './nx-json'; import { NxJsonConfiguration } from './nx-json';
import { ProjectsConfigurations } from './workspace-json-project-json'; import { ProjectsConfigurations } from './workspace-json-project-json';
import { readNxJson } from './nx-json';
export function readNxJson(): NxJsonConfiguration {
return new Workspaces(workspaceRoot).readNxJson();
}
// TODO(vsavkin): Remove after Nx 16 is out // TODO(vsavkin): Remove after Nx 16 is out
/** /**
@ -26,3 +23,5 @@ export function workspaceLayout(): { appsDir: string; libsDir: string } {
libsDir: nxJson.workspaceLayout?.libsDir ?? 'libs', libsDir: nxJson.workspaceLayout?.libsDir ?? 'libs',
}; };
} }
export { readNxJson } from './nx-json';

View File

@ -1,3 +1,8 @@
import { dirname, join } from 'path';
import { existsSync } from 'fs';
import { readJsonFile } from '../utils/fileutils';
import { workspaceRoot } from '../utils/workspace-root';
import { PackageManager } from '../utils/package-manager'; import { PackageManager } from '../utils/package-manager';
import { import {
InputDefinition, InputDefinition,
@ -152,3 +157,28 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
*/ */
installation?: NxInstallationConfiguration; installation?: NxInstallationConfiguration;
} }
export function readNxJson(root: string = workspaceRoot): NxJsonConfiguration {
const nxJson = join(root, 'nx.json');
if (existsSync(nxJson)) {
const nxJsonConfiguration = readJsonFile<NxJsonConfiguration>(nxJson);
if (nxJsonConfiguration.extends) {
const extendedNxJsonPath = require.resolve(nxJsonConfiguration.extends, {
paths: [dirname(nxJson)],
});
const baseNxJson = readJsonFile<NxJsonConfiguration>(extendedNxJsonPath);
return {
...baseNxJson,
...nxJsonConfiguration,
};
} else {
return nxJsonConfiguration;
}
} else {
try {
return readJsonFile(join(__dirname, '..', '..', 'presets', 'core.json'));
} catch (e) {
return {};
}
}
}

View File

@ -27,6 +27,7 @@ import {
findProjectForPath, findProjectForPath,
normalizeProjectRoot, normalizeProjectRoot,
} from '../project-graph/utils/find-project-for-path'; } from '../project-graph/utils/find-project-for-path';
import { readNxJson } from './nx-json';
export class Workspaces { export class Workspaces {
private cachedProjectsConfig: ProjectsConfigurations; private cachedProjectsConfig: ProjectsConfigurations;
@ -79,7 +80,7 @@ export class Workspaces {
) { ) {
return this.cachedProjectsConfig; return this.cachedProjectsConfig;
} }
const nxJson = this.readNxJson(); const nxJson = readNxJson(this.root);
let projectsConfigurations = buildProjectsConfigurationsFromProjectPaths( let projectsConfigurations = buildProjectsConfigurationsFromProjectPaths(
nxJson, nxJson,
globForProjectFiles( globForProjectFiles(
@ -123,7 +124,7 @@ export class Workspaces {
_ignorePluginInference?: boolean; _ignorePluginInference?: boolean;
_includeProjectsFromAngularJson?: boolean; _includeProjectsFromAngularJson?: boolean;
}): ProjectsConfigurations & NxJsonConfiguration { }): ProjectsConfigurations & NxJsonConfiguration {
const nxJson = this.readNxJson(); const nxJson = readNxJson(this.root);
return { ...this.readProjectsConfigurations(opts), ...nxJson }; return { ...this.readProjectsConfigurations(opts), ...nxJson };
} }
@ -158,37 +159,6 @@ export class Workspaces {
const nxJson = path.join(this.root, 'nx.json'); const nxJson = path.join(this.root, 'nx.json');
return existsSync(nxJson); return existsSync(nxJson);
} }
readNxJson(): NxJsonConfiguration {
const nxJson = path.join(this.root, 'nx.json');
if (existsSync(nxJson)) {
const nxJsonConfiguration = readJsonFile<NxJsonConfiguration>(nxJson);
if (nxJsonConfiguration.extends) {
const extendedNxJsonPath = require.resolve(
nxJsonConfiguration.extends,
{
paths: [dirname(nxJson)],
}
);
const baseNxJson =
readJsonFile<NxJsonConfiguration>(extendedNxJsonPath);
return {
...baseNxJson,
...nxJsonConfiguration,
};
} else {
return nxJsonConfiguration;
}
} else {
try {
return readJsonFile(
join(__dirname, '..', '..', 'presets', 'core.json')
);
} catch (e) {
return {};
}
}
}
} }
function findMatchingProjectInCwd( function findMatchingProjectInCwd(

View File

@ -23,6 +23,7 @@ import {
retrieveProjectConfigurations, retrieveProjectConfigurations,
} from '../../project-graph/utils/retrieve-workspace-files'; } from '../../project-graph/utils/retrieve-workspace-files';
import { ProjectConfiguration } from '../../config/workspace-json-project-json'; import { ProjectConfiguration } from '../../config/workspace-json-project-json';
import { readNxJson } from '../../config/nx-json';
let cachedSerializedProjectGraphPromise: Promise<{ let cachedSerializedProjectGraphPromise: Promise<{
error: Error | null; error: Error | null;
@ -170,7 +171,7 @@ async function processCollectedUpdatedAndDeletedFiles() {
); );
fileHasher.incrementalUpdate(updatedFiles, deletedFiles); fileHasher.incrementalUpdate(updatedFiles, deletedFiles);
let nxJson = new Workspaces(workspaceRoot).readNxJson(); let nxJson = readNxJson(workspaceRoot);
const projectConfigurations = await retrieveProjectConfigurations( const projectConfigurations = await retrieveProjectConfigurations(
workspaceRoot, workspaceRoot,

View File

@ -42,11 +42,10 @@ export type {
*/ */
export { Workspaces } from './config/workspaces'; export { Workspaces } from './config/workspaces';
// TODO (v16): Change this to export from './config/configuration'
export { export {
readAllWorkspaceConfiguration, readAllWorkspaceConfiguration,
workspaceLayout, workspaceLayout,
} from './project-graph/file-utils'; } from './config/configuration';
export type { NxPlugin, ProjectTargetConfigurator } from './utils/nx-plugin'; export type { NxPlugin, ProjectTargetConfigurator } from './utils/nx-plugin';

View File

@ -5,3 +5,4 @@
*/ */
export { createTempNpmDirectory } from './utils/package-manager'; export { createTempNpmDirectory } from './utils/package-manager';
export { getExecutorInformation } from './command-line/run/executor-utils'; export { getExecutorInformation } from './command-line/run/executor-utils';
export { readNxJson as readNxJsonFromDisk } from './config/nx-json';

View File

@ -4,6 +4,7 @@
import type { Observable } from 'rxjs'; import type { Observable } from 'rxjs';
import { Workspaces } from '../../config/workspaces'; import { Workspaces } from '../../config/workspaces';
import { readNxJson } from '../../config/nx-json';
import { Executor, ExecutorContext } from '../../config/misc-interfaces'; import { Executor, ExecutorContext } from '../../config/misc-interfaces';
/** /**
@ -17,7 +18,7 @@ export function convertNxExecutor(executor: Executor) {
const projectsConfigurations = workspaces.readProjectsConfigurations(); const projectsConfigurations = workspaces.readProjectsConfigurations();
const promise = async () => { const promise = async () => {
const nxJsonConfiguration = workspaces.readNxJson(); const nxJsonConfiguration = readNxJson(builderContext.workspaceRoot);
const context: ExecutorContext = { const context: ExecutorContext = {
root: builderContext.workspaceRoot, root: builderContext.workspaceRoot,
projectName: builderContext.target.project, projectName: builderContext.target.project,

View File

@ -4,7 +4,7 @@ import type { NxJsonConfiguration } from '../../config/nx-json';
import type { Tree } from '../tree'; import type { Tree } from '../tree';
import { readJson, updateJson } from './json'; import { readJson, updateJson } from './json';
import { readNxJson as readNxJsonFromDisk } from '../../project-graph/file-utils'; import { readNxJson as readNxJsonFromDisk } from '../../config/nx-json';
/** /**
* @deprecated You must pass a {@link Tree} * @deprecated You must pass a {@link Tree}

View File

@ -3,11 +3,10 @@ import { getCustomHasher } from '../tasks-runner/utils';
import { readProjectsConfigurationFromProjectGraph } from '../project-graph/project-graph'; import { readProjectsConfigurationFromProjectGraph } from '../project-graph/project-graph';
import { getInputs, TaskHasher } from './task-hasher'; import { getInputs, TaskHasher } from './task-hasher';
import { ProjectGraph } from '../config/project-graph'; import { ProjectGraph } from '../config/project-graph';
import { Workspaces } from '../config/workspaces';
import { NxJsonConfiguration } from '../config/nx-json'; import { NxJsonConfiguration } from '../config/nx-json';
import { readNxJson } from '../config/nx-json';
export async function hashTasksThatDoNotDependOnOutputsOfOtherTasks( export async function hashTasksThatDoNotDependOnOutputsOfOtherTasks(
workspaces: Workspaces,
hasher: TaskHasher, hasher: TaskHasher,
projectGraph: ProjectGraph, projectGraph: ProjectGraph,
taskGraph: TaskGraph, taskGraph: TaskGraph,
@ -16,12 +15,7 @@ export async function hashTasksThatDoNotDependOnOutputsOfOtherTasks(
const tasks = Object.values(taskGraph.tasks); const tasks = Object.values(taskGraph.tasks);
const tasksWithHashers = await Promise.all( const tasksWithHashers = await Promise.all(
tasks.map(async (task) => { tasks.map(async (task) => {
const customHasher = await getCustomHasher( const customHasher = await getCustomHasher(task, projectGraph);
task,
workspaces,
workspaces.readNxJson(),
projectGraph
);
return { task, customHasher }; return { task, customHasher };
}) })
); );
@ -48,18 +42,12 @@ export async function hashTasksThatDoNotDependOnOutputsOfOtherTasks(
} }
export async function hashTask( export async function hashTask(
workspaces: Workspaces,
hasher: TaskHasher, hasher: TaskHasher,
projectGraph: ProjectGraph, projectGraph: ProjectGraph,
taskGraph: TaskGraph, taskGraph: TaskGraph,
task: Task task: Task
) { ) {
const customHasher = await getCustomHasher( const customHasher = await getCustomHasher(task, projectGraph);
task,
workspaces,
workspaces.readNxJson(),
projectGraph
);
const projectsConfigurations = const projectsConfigurations =
readProjectsConfigurationFromProjectGraph(projectGraph); readProjectsConfigurationFromProjectGraph(projectGraph);
const { value, details } = await (customHasher const { value, details } = await (customHasher
@ -69,7 +57,7 @@ export async function hashTask(
taskGraph, taskGraph,
workspaceConfig: projectsConfigurations, // to make the change non-breaking. Remove after v18 workspaceConfig: projectsConfigurations, // to make the change non-breaking. Remove after v18
projectsConfigurations, projectsConfigurations,
nxJsonConfiguration: workspaces.readNxJson(), nxJsonConfiguration: readNxJson(),
} as any) } as any)
: hasher.hashTask(task)); : hasher.hashTask(task));
task.hash = value; task.hash = value;

View File

@ -9,7 +9,6 @@ import type { NxArgs } from '../utils/command-line-utils';
import { workspaceRoot } from '../utils/workspace-root'; import { workspaceRoot } from '../utils/workspace-root';
import { readJsonFile } from '../utils/fileutils'; import { readJsonFile } from '../utils/fileutils';
import { jsonDiff } from '../utils/json-diff'; import { jsonDiff } from '../utils/json-diff';
import ignore from 'ignore';
import { import {
readCachedProjectGraph, readCachedProjectGraph,
readProjectsConfigurationFromProjectGraph, readProjectsConfigurationFromProjectGraph,
@ -155,8 +154,7 @@ export function readPackageJson(): any {
} }
// Original Exports // Original Exports
export { FileData }; export { FileData };
// TODO(17): Remove these exports
// TODO(v16): Remove these exports
export { export {
readNxJson, readNxJson,
readAllWorkspaceConfiguration, readAllWorkspaceConfiguration,

View File

@ -16,7 +16,7 @@ import { fileExists } from '../utils/fileutils';
import { workspaceRoot } from '../utils/workspace-root'; import { workspaceRoot } from '../utils/workspace-root';
import { performance } from 'perf_hooks'; import { performance } from 'perf_hooks';
import { retrieveWorkspaceFiles } from './utils/retrieve-workspace-files'; import { retrieveWorkspaceFiles } from './utils/retrieve-workspace-files';
import { readNxJson } from './file-utils'; import { readNxJson } from '../config/nx-json';
/** /**
* Synchronously reads the latest cached copy of the workspace's ProjectGraph. * Synchronously reads the latest cached copy of the workspace's ProjectGraph.

View File

@ -252,7 +252,6 @@ export async function invokeTasksRunner({
// a distributed fashion // a distributed fashion
performance.mark('hashing:start'); performance.mark('hashing:start');
await hashTasksThatDoNotDependOnOutputsOfOtherTasks( await hashTasksThatDoNotDependOnOutputsOfOtherTasks(
new Workspaces(workspaceRoot),
hasher, hasher,
projectGraph, projectGraph,
taskGraph, taskGraph,

View File

@ -1,9 +1,7 @@
import { defaultMaxListeners } from 'events'; import { defaultMaxListeners } from 'events';
import { performance } from 'perf_hooks'; import { performance } from 'perf_hooks';
import { Workspaces } from '../config/workspaces';
import { TaskHasher } from '../hasher/task-hasher'; import { TaskHasher } from '../hasher/task-hasher';
import { ForkedProcessTaskRunner } from './forked-process-task-runner'; import { ForkedProcessTaskRunner } from './forked-process-task-runner';
import { workspaceRoot } from '../utils/workspace-root';
import { Cache } from './cache'; import { Cache } from './cache';
import { DefaultTasksRunnerOptions } from './default-tasks-runner'; import { DefaultTasksRunnerOptions } from './default-tasks-runner';
import { TaskStatus } from './tasks-runner'; import { TaskStatus } from './tasks-runner';
@ -23,16 +21,12 @@ import { DaemonClient } from '../daemon/client/client';
export class TaskOrchestrator { export class TaskOrchestrator {
private cache = new Cache(this.options); private cache = new Cache(this.options);
private workspace = new Workspaces(workspaceRoot);
private forkedProcessTaskRunner = new ForkedProcessTaskRunner(this.options); private forkedProcessTaskRunner = new ForkedProcessTaskRunner(this.options);
private readonly nxJson = this.workspace.readNxJson();
private tasksSchedule = new TasksSchedule( private tasksSchedule = new TasksSchedule(
this.hasher, this.hasher,
this.nxJson,
this.projectGraph, this.projectGraph,
this.taskGraph, this.taskGraph,
this.workspace,
this.options this.options
); );
@ -456,12 +450,7 @@ export class TaskOrchestrator {
private async pipeOutputCapture(task: Task) { private async pipeOutputCapture(task: Task) {
try { try {
const { schema } = await getExecutorForTask( const { schema } = await getExecutorForTask(task, this.projectGraph);
task,
this.workspace,
this.projectGraph,
this.nxJson
);
return ( return (
schema.outputCapture === 'pipe' || schema.outputCapture === 'pipe' ||

View File

@ -3,6 +3,7 @@ import { Workspaces } from '../config/workspaces';
import { removeTasksFromTaskGraph } from './utils'; import { removeTasksFromTaskGraph } from './utils';
import { Task, TaskGraph } from '../config/task-graph'; import { Task, TaskGraph } from '../config/task-graph';
import { DependencyType, ProjectGraph } from '../config/project-graph'; import { DependencyType, ProjectGraph } from '../config/project-graph';
import * as nxJsonUtils from '../config/nx-json';
import * as executorUtils from '../command-line/run/executor-utils'; import * as executorUtils from '../command-line/run/executor-utils';
function createMockTask(id: string): Task { function createMockTask(id: string): Task {
@ -43,11 +44,7 @@ describe('TasksSchedule', () => {
}, },
roots: ['lib1:build', 'app2:build'], roots: ['lib1:build', 'app2:build'],
}; };
const workspace: Partial<Workspaces> = { jest.spyOn(nxJsonUtils, 'readNxJson').mockReturnValue({});
readNxJson() {
return {};
},
};
jest.spyOn(executorUtils, 'getExecutorInformation').mockReturnValue({ jest.spyOn(executorUtils, 'getExecutorInformation').mockReturnValue({
schema: { schema: {
version: 2, version: 2,
@ -127,16 +124,9 @@ describe('TasksSchedule', () => {
endTask: jest.fn(), endTask: jest.fn(),
scheduleTask: jest.fn(), scheduleTask: jest.fn(),
}; };
taskSchedule = new TasksSchedule( taskSchedule = new TasksSchedule(hasher, projectGraph, taskGraph, {
hasher, lifeCycle,
{}, });
projectGraph,
taskGraph,
workspace as Workspaces,
{
lifeCycle,
}
);
}); });
describe('Without Batch Mode', () => { describe('Without Batch Mode', () => {
@ -269,11 +259,7 @@ describe('TasksSchedule', () => {
}, },
roots: ['app1:test', 'app2:test', 'lib1:test'], roots: ['app1:test', 'app2:test', 'lib1:test'],
}; };
const workspace: Partial<Workspaces> = { jest.spyOn(nxJsonUtils, 'readNxJson').mockReturnValue({});
readNxJson() {
return {};
},
};
jest.spyOn(executorUtils, 'getExecutorInformation').mockReturnValue({ jest.spyOn(executorUtils, 'getExecutorInformation').mockReturnValue({
schema: { schema: {
version: 2, version: 2,
@ -353,16 +339,9 @@ describe('TasksSchedule', () => {
endTask: jest.fn(), endTask: jest.fn(),
scheduleTask: jest.fn(), scheduleTask: jest.fn(),
}; };
taskSchedule = new TasksSchedule( taskSchedule = new TasksSchedule(hasher, projectGraph, taskGraph, {
hasher, lifeCycle,
{}, });
projectGraph,
taskGraph,
workspace as Workspaces,
{
lifeCycle,
}
);
}); });
describe('Without Batch Mode', () => { describe('Without Batch Mode', () => {

View File

@ -31,10 +31,8 @@ export class TasksSchedule {
constructor( constructor(
private readonly hasher: TaskHasher, private readonly hasher: TaskHasher,
private readonly nxJson: NxJsonConfiguration,
private readonly projectGraph: ProjectGraph, private readonly projectGraph: ProjectGraph,
private readonly taskGraph: TaskGraph, private readonly taskGraph: TaskGraph,
private readonly workspaces: Workspaces,
private readonly options: DefaultTasksRunnerOptions private readonly options: DefaultTasksRunnerOptions
) {} ) {}
@ -92,13 +90,7 @@ export class TasksSchedule {
const task = this.taskGraph.tasks[taskId]; const task = this.taskGraph.tasks[taskId];
if (!task.hash) { if (!task.hash) {
await hashTask( await hashTask(this.hasher, this.projectGraph, this.taskGraph, task);
this.workspaces,
this.hasher,
this.projectGraph,
this.taskGraph,
task
);
} }
this.notScheduledTaskGraph = removeTasksFromTaskGraph( this.notScheduledTaskGraph = removeTasksFromTaskGraph(
@ -170,9 +162,7 @@ export class TasksSchedule {
const { batchImplementationFactory } = await getExecutorForTask( const { batchImplementationFactory } = await getExecutorForTask(
task, task,
this.workspaces, this.projectGraph
this.projectGraph,
this.nxJson
); );
const executorName = await getExecutorNameForTask(task, this.projectGraph); const executorName = await getExecutorNameForTask(task, this.projectGraph);
if (rootExecutorName !== executorName) { if (rootExecutorName !== executorName) {

View File

@ -17,6 +17,7 @@ import { isRelativePath } from '../utils/fileutils';
import { serializeOverridesIntoCommandLine } from '../utils/serialize-overrides-into-command-line'; import { serializeOverridesIntoCommandLine } from '../utils/serialize-overrides-into-command-line';
import { splitByColons, splitTarget } from '../utils/split-target'; import { splitByColons, splitTarget } from '../utils/split-target';
import { getExecutorInformation } from '../command-line/run/executor-utils'; import { getExecutorInformation } from '../command-line/run/executor-utils';
import { CustomHasher } from '../config/misc-interfaces';
export function getCommandAsString(execCommand: string, task: Task) { export function getCommandAsString(execCommand: string, task: Task) {
const args = getPrintableCommandArgsForTask(task); const args = getPrintableCommandArgsForTask(task);
@ -247,9 +248,7 @@ export async function getExecutorNameForTask(
export async function getExecutorForTask( export async function getExecutorForTask(
task: Task, task: Task,
workspace: Workspaces, projectGraph: ProjectGraph
projectGraph: ProjectGraph,
nxJson: NxJsonConfiguration
) { ) {
const executor = await getExecutorNameForTask(task, projectGraph); const executor = await getExecutorNameForTask(task, projectGraph);
const [nodeModule, executorName] = executor.split(':'); const [nodeModule, executorName] = executor.split(':');
@ -259,13 +258,9 @@ export async function getExecutorForTask(
export async function getCustomHasher( export async function getCustomHasher(
task: Task, task: Task,
workspace: Workspaces,
nxJson: NxJsonConfiguration,
projectGraph: ProjectGraph projectGraph: ProjectGraph
) { ): Promise<CustomHasher> | null {
const factory = ( const factory = (await getExecutorForTask(task, projectGraph)).hasherFactory;
await getExecutorForTask(task, workspace, projectGraph, nxJson)
).hasherFactory;
return factory ? factory() : null; return factory ? factory() : null;
} }

View File

@ -2,7 +2,6 @@ import { Schema } from '../schema';
import { import {
getProjects, getProjects,
readNxJson, readNxJson,
removeProjectConfiguration,
Tree, Tree,
updateNxJson, updateNxJson,
updateProjectConfiguration, updateProjectConfiguration,