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

fix(linter): convert root projects correctly to inferred and remove default option values #27035

Merged
merged 1 commit into from
Jul 22, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { minimatch } from 'minimatch';
import { deepStrictEqual } from 'node:assert';
import { join } from 'node:path/posix';
import type {
InputDefinition,
ProjectConfiguration,
Expand Down Expand Up @@ -39,7 +40,8 @@ type PostTargetTransformer = (
inferredTargetConfiguration: InferredTargetConfiguration
) => TargetConfiguration | Promise<TargetConfiguration>;
type SkipTargetFilter = (
targetConfiguration: TargetConfiguration
targetOptions: Record<string, unknown>,
projectConfiguration: ProjectConfiguration
) => false | string;
type SkipProjectFilter = (
projectConfiguration: ProjectConfiguration
Expand All @@ -58,7 +60,6 @@ class ExecutorToPluginMigrator<T> {
#nxJson: NxJsonConfiguration;
#targetDefaultsForExecutor: Partial<TargetConfiguration>;
#targetAndProjectsToMigrate: Map<string, Set<string>>;
#pluginToAddForTarget: Map<string, ExpandedPluginConfiguration<T>>;
#createNodes?: CreateNodes<T>;
#createNodesV2?: CreateNodesV2<T>;
#createNodesResultsForTargets: Map<string, ConfigurationResult>;
Expand Down Expand Up @@ -108,7 +109,6 @@ class ExecutorToPluginMigrator<T> {
nxJson.plugins ??= [];
this.#nxJson = nxJson;
this.#targetAndProjectsToMigrate = new Map();
this.#pluginToAddForTarget = new Map();
this.#createNodesResultsForTargets = new Map();
this.#skippedProjects = new Set();

Expand All @@ -118,18 +118,11 @@ class ExecutorToPluginMigrator<T> {
}

async #migrateTarget(targetName: string) {
const include: string[] = [];
for (const projectName of this.#targetAndProjectsToMigrate.get(
targetName
)) {
include.push(await this.#migrateProject(projectName, targetName));
await this.#migrateProject(projectName, targetName);
}

this.#pluginToAddForTarget.set(targetName, {
plugin: this.#pluginPath,
options: this.#pluginOptionsBuilder(targetName),
include,
});
}

async #migrateProject(projectName: string, targetName: string) {
Expand Down Expand Up @@ -180,8 +173,6 @@ class ExecutorToPluginMigrator<T> {
}

updateProjectConfiguration(this.tree, projectName, projectConfig);

return `${projectFromGraph.data.root}/**/*`;
}

#mergeInputs(
Expand Down Expand Up @@ -237,7 +228,12 @@ class ExecutorToPluginMigrator<T> {
forEachExecutorOptions(
this.tree,
this.#executor,
(targetConfiguration, projectName, targetName, configurationName) => {
(
options: Record<string, unknown>,
projectName,
targetName,
configurationName
) => {
if (this.#skippedProjects.has(projectName) || configurationName) {
return;
}
Expand All @@ -263,9 +259,12 @@ class ExecutorToPluginMigrator<T> {
return;
}

const skipTargetReason = this.#skipTargetFilter(targetConfiguration);
const skipTargetReason = this.#skipTargetFilter(
options,
this.#projectGraph.nodes[projectName].data
);
if (skipTargetReason) {
const errorMsg = `${targetName} target on project "${projectName}" cannot be migrated. ${skipTargetReason}`;
const errorMsg = `The ${targetName} target on project "${projectName}" cannot be migrated. ${skipTargetReason}`;
if (this.#specificProjectToMigrate) {
throw new Error(errorMsg);
} else {
Expand Down Expand Up @@ -538,7 +537,10 @@ async function addPluginRegistrations<T>(
)
);

const projectIncludeGlob = `${projectGraph.nodes[project].data.root}/**/*`;
const projectIncludeGlob =
projectGraph.nodes[project].data.root === '.'
? '*'
: join(projectGraph.nodes[project].data.root, '**/*');
if (!existingPlugin) {
nxJson.plugins ??= [];
const plugin: ExpandedPluginConfiguration = {
Expand Down
Loading