Skip to content

Commit

Permalink
Merge branch 'nrwl:master' into eslint/fix-lintable-files-collect
Browse files Browse the repository at this point in the history
  • Loading branch information
gunter1020 authored Jun 25, 2024
2 parents ca7e250 + 8872ca5 commit 34bb4d8
Show file tree
Hide file tree
Showing 65 changed files with 3,713 additions and 204 deletions.
8 changes: 8 additions & 0 deletions docs/generated/manifests/menus.json
Original file line number Diff line number Diff line change
Expand Up @@ -9891,6 +9891,14 @@
"children": [],
"isExternal": false,
"disableCollapsible": false
},
{
"id": "convert-to-inferred",
"path": "/nx-api/webpack/generators/convert-to-inferred",
"name": "convert-to-inferred",
"children": [],
"isExternal": false,
"disableCollapsible": false
}
],
"isExternal": false,
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/manifests/nx-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3242,6 +3242,15 @@
"originalFilePath": "/packages/webpack/src/generators/convert-config-to-webpack-plugin/schema.json",
"path": "/nx-api/webpack/generators/convert-config-to-webpack-plugin",
"type": "generator"
},
"/nx-api/webpack/generators/convert-to-inferred": {
"description": "Convert existing Webpack project(s) using `@nx/webpack:wepack` executor to use `@nx/webpack/plugin`.",
"file": "generated/packages/webpack/generators/convert-to-inferred.json",
"hidden": false,
"name": "convert-to-inferred",
"originalFilePath": "/packages/webpack/src/generators/convert-to-inferred/schema.json",
"path": "/nx-api/webpack/generators/convert-to-inferred",
"type": "generator"
}
},
"path": "/nx-api/webpack"
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/packages-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,15 @@
"originalFilePath": "/packages/webpack/src/generators/convert-config-to-webpack-plugin/schema.json",
"path": "webpack/generators/convert-config-to-webpack-plugin",
"type": "generator"
},
{
"description": "Convert existing Webpack project(s) using `@nx/webpack:wepack` executor to use `@nx/webpack/plugin`.",
"file": "generated/packages/webpack/generators/convert-to-inferred.json",
"hidden": false,
"name": "convert-to-inferred",
"originalFilePath": "/packages/webpack/src/generators/convert-to-inferred/schema.json",
"path": "webpack/generators/convert-to-inferred",
"type": "generator"
}
],
"githubRoot": "https://github.com/nrwl/nx/blob/master",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "convert-to-inferred",
"factory": "./src/generators/convert-to-inferred/convert-to-inferred#convertToInferred",
"schema": {
"$schema": "https://json-schema.org/schema",
"$id": "NxWebpackConvertToInferred",
"description": "Convert existing Webpack project(s) using `@nx/webpack:wepack` executor to use `@nx/webpack/plugin`.",
"title": "Convert a Webpack project from executor to plugin",
"type": "object",
"properties": {
"project": {
"type": "string",
"description": "The project to convert from using the `@nx/webpack:webpack` executor to use `@nx/webpack/plugin`. If not provided, all projects using the `@nx/webpack:webpack` executor will be converted.",
"x-priority": "important"
},
"skipFormat": {
"type": "boolean",
"description": "Whether to format files.",
"default": false
}
},
"presets": []
},
"description": "Convert existing Webpack project(s) using `@nx/webpack:wepack` executor to use `@nx/webpack/plugin`.",
"implementation": "/packages/webpack/src/generators/convert-to-inferred/convert-to-inferred#convertToInferred.ts",
"aliases": [],
"hidden": false,
"path": "/packages/webpack/src/generators/convert-to-inferred/schema.json",
"type": "generator"
}
1 change: 1 addition & 0 deletions docs/shared/reference/sitemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@
- [init](/nx-api/webpack/generators/init)
- [configuration](/nx-api/webpack/generators/configuration)
- [convert-config-to-webpack-plugin](/nx-api/webpack/generators/convert-config-to-webpack-plugin)
- [convert-to-inferred](/nx-api/webpack/generators/convert-to-inferred)
- [workspace](/nx-api/workspace)
- [documents](/nx-api/workspace/documents)
- [Overview](/nx-api/workspace/documents/overview)
Expand Down
Binary file modified e2e/gradle/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions e2e/gradle/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
validateDistributionUrl=false
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions e2e/gradle/src/gradle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Gradle', () => {
createFile(
`app2/build.gradle`,
`plugins {
id 'gradleProject.groovy-application-conventions'
id 'buildlogic.groovy-application-conventions'
}
dependencies {
Expand All @@ -64,7 +64,7 @@ dependencies {
createFile(
`app2/build.gradle.kts`,
`plugins {
id("gradleProject.kotlin-library-conventions")
id("buildlogic.kotlin-application-conventions")
}
dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ describe('app migrator', () => {
jest.clearAllMocks();
});

it('should not migrate project when validation fails', async () => {
// add project with no root
const project = addProject('app1', {} as any);
const migrator = new AppMigrator(tree, {}, project);

await migrator.migrate();

expect(tree.exists('apps/app1/project.json')).toBe(false);
const { projects } = readJson(tree, 'angular.json');
expect(projects.app1).toBeDefined();
});

describe('validation', () => {
it('should fail validation when the project root is not specified', async () => {
const project = addProject('app1', {} as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ export class AppMigrator extends ProjectMigrator<SupportedTargets> {
}

override async migrate(): Promise<void> {
await super.migrate();

if (this.skipMigration === true) {
return;
}

await super.migrate();

this.updateProjectConfiguration();

await this.e2eMigrator.migrate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ describe('lib migrator', () => {
jest.clearAllMocks();
});

it('should not migrate project when validation fails', async () => {
// add project with no root
const project = addProject('lib1', {} as any);
const migrator = new LibMigrator(tree, {}, project);

await migrator.migrate();

expect(tree.exists('libs/lib1/project.json')).toBe(false);
const { projects } = readJson(tree, 'angular.json');
expect(projects.lib1).toBeDefined();
});

describe('validation', () => {
it('should fail validation when the project root is not specified', async () => {
const project = addProject('lib1', {} as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class LibMigrator extends ProjectMigrator {
}

override async migrate(): Promise<void> {
await super.migrate();

if (this.skipMigration === true) {
return;
}

await super.migrate();

await this.updateProjectConfiguration();
this.moveProjectFiles();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from 'chalk';
import chalk = require('chalk');
import {
arrayToString,
getProjectValidationResultMessage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from 'chalk';
import chalk = require('chalk');
import type { ValidationError } from './types';

export function arrayToString(array: string[]): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class AggregatedLog {
}

flushLogs(): void {
if (this.logs.size === 0) {
return;
}

let fullLog = '';
for (const executorName of this.logs.keys()) {
fullLog = `${fullLog}${output.bold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import {
ProjectConfigurationsError,
} from 'nx/src/devkit-internals';
import type { ConfigurationResult } from 'nx/src/project-graph/utils/project-configuration-utils';
import type { InputDefinition } from 'nx/src/config/workspace-json-project-json';
import type {
InputDefinition,
ProjectConfiguration,
} from 'nx/src/config/workspace-json-project-json';

type PluginOptionsBuilder<T> = (targetName: string) => T;
type PostTargetTransformer = (
Expand All @@ -38,7 +41,10 @@ type PostTargetTransformer = (
) => TargetConfiguration | Promise<TargetConfiguration>;
type SkipTargetFilter = (
targetConfiguration: TargetConfiguration
) => [boolean, string];
) => false | string;
type SkipProjectFilter = (
projectConfiguration: ProjectConfiguration
) => false | string;

class ExecutorToPluginMigrator<T> {
readonly tree: Tree;
Expand All @@ -48,6 +54,7 @@ class ExecutorToPluginMigrator<T> {
readonly #pluginOptionsBuilder: PluginOptionsBuilder<T>;
readonly #postTargetTransformer: PostTargetTransformer;
readonly #skipTargetFilter: SkipTargetFilter;
readonly #skipProjectFilter: SkipProjectFilter;
readonly #specificProjectToMigrate: string;
#nxJson: NxJsonConfiguration;
#targetDefaultsForExecutor: Partial<TargetConfiguration>;
Expand All @@ -56,6 +63,7 @@ class ExecutorToPluginMigrator<T> {
#createNodes?: CreateNodes<T>;
#createNodesV2?: CreateNodesV2<T>;
#createNodesResultsForTargets: Map<string, ConfigurationResult>;
#skippedProjects: Set<string>;

constructor(
tree: Tree,
Expand All @@ -67,7 +75,10 @@ class ExecutorToPluginMigrator<T> {
createNodes?: CreateNodes<T>,
createNodesV2?: CreateNodesV2<T>,
specificProjectToMigrate?: string,
skipTargetFilter?: SkipTargetFilter
filters?: {
skipProjectFilter?: SkipProjectFilter;
skipTargetFilter?: SkipTargetFilter;
}
) {
this.tree = tree;
this.#projectGraph = projectGraph;
Expand All @@ -78,7 +89,9 @@ class ExecutorToPluginMigrator<T> {
this.#createNodes = createNodes;
this.#createNodesV2 = createNodesV2;
this.#specificProjectToMigrate = specificProjectToMigrate;
this.#skipTargetFilter = skipTargetFilter ?? ((...args) => [false, '']);
this.#skipProjectFilter =
filters?.skipProjectFilter ?? ((...args) => false);
this.#skipTargetFilter = filters?.skipTargetFilter ?? ((...args) => false);
}

async run(): Promise<Map<string, Set<string>>> {
Expand All @@ -99,6 +112,7 @@ class ExecutorToPluginMigrator<T> {
this.#targetAndProjectsToMigrate = new Map();
this.#pluginToAddForTarget = new Map();
this.#createNodesResultsForTargets = new Map();
this.#skippedProjects = new Set();

this.#getTargetDefaultsForExecutor();
this.#getTargetAndProjectsToMigrate();
Expand Down Expand Up @@ -311,7 +325,7 @@ class ExecutorToPluginMigrator<T> {
this.tree,
this.#executor,
(targetConfiguration, projectName, targetName, configurationName) => {
if (configurationName) {
if (this.#skippedProjects.has(projectName) || configurationName) {
return;
}

Expand All @@ -322,10 +336,23 @@ class ExecutorToPluginMigrator<T> {
return;
}

const [skipTarget, reasonTargetWasSkipped] =
this.#skipTargetFilter(targetConfiguration);
if (skipTarget) {
const errorMsg = `${targetName} target on project "${projectName}" cannot be migrated. ${reasonTargetWasSkipped}`;
const skipProjectReason = this.#skipProjectFilter(
this.#projectGraph.nodes[projectName].data
);
if (skipProjectReason) {
this.#skippedProjects.add(projectName);
const errorMsg = `The "${projectName}" project cannot be migrated. ${skipProjectReason}`;
if (this.#specificProjectToMigrate) {
throw new Error(errorMsg);
}

console.warn(errorMsg);
return;
}

const skipTargetReason = this.#skipTargetFilter(targetConfiguration);
if (skipTargetReason) {
const errorMsg = `${targetName} target on project "${projectName}" cannot be migrated. ${skipTargetReason}`;
if (this.#specificProjectToMigrate) {
throw new Error(errorMsg);
} else {
Expand Down Expand Up @@ -375,6 +402,7 @@ class ExecutorToPluginMigrator<T> {
return;
}

global.NX_GRAPH_CREATION = true;
for (const targetName of this.#targetAndProjectsToMigrate.keys()) {
const loadedPlugin = new LoadedNxPlugin(
{
Expand All @@ -398,12 +426,14 @@ class ExecutorToPluginMigrator<T> {
if (e instanceof ProjectConfigurationsError) {
projectConfigs = e.partialProjectConfigurationsResult;
} else {
global.NX_GRAPH_CREATION = false;
throw e;
}
}

this.#createNodesResultsForTargets.set(targetName, projectConfigs);
}
global.NX_GRAPH_CREATION = false;
}
}

Expand All @@ -416,7 +446,10 @@ export async function migrateExecutorToPlugin<T>(
postTargetTransformer: PostTargetTransformer,
createNodes: CreateNodesV2<T>,
specificProjectToMigrate?: string,
skipTargetFilter?: SkipTargetFilter
filters?: {
skipProjectFilter?: SkipProjectFilter;
skipTargetFilter?: SkipTargetFilter;
}
): Promise<Map<string, Set<string>>> {
const migrator = new ExecutorToPluginMigrator<T>(
tree,
Expand All @@ -428,7 +461,7 @@ export async function migrateExecutorToPlugin<T>(
undefined,
createNodes,
specificProjectToMigrate,
skipTargetFilter
filters
);
return await migrator.run();
}
Expand All @@ -442,7 +475,10 @@ export async function migrateExecutorToPluginV1<T>(
postTargetTransformer: PostTargetTransformer,
createNodes: CreateNodes<T>,
specificProjectToMigrate?: string,
skipTargetFilter?: SkipTargetFilter
filters?: {
skipProjectFilter?: SkipProjectFilter;
skipTargetFilter?: SkipTargetFilter;
}
): Promise<Map<string, Set<string>>> {
const migrator = new ExecutorToPluginMigrator<T>(
tree,
Expand All @@ -454,7 +490,7 @@ export async function migrateExecutorToPluginV1<T>(
createNodes,
undefined,
specificProjectToMigrate,
skipTargetFilter
filters
);
return await migrator.run();
}
Expand Down
9 changes: 8 additions & 1 deletion packages/gradle/migrations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"generators": {},
"generators": {
"add-project-report-all": {
"version": "19.4.0-beta.1",
"cli": "nx",
"description": "Add task projectReportAll to build.gradle file",
"factory": "./src/migrations/19-4-0/add-project-report-all"
}
},
"packageJsonUpdates": {}
}
8 changes: 8 additions & 0 deletions packages/gradle/migrations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import json = require('./migrations.json');

import { assertValidMigrationPaths } from '@nx/devkit/internal-testing-utils';
import { MigrationsJson } from '@nx/devkit';

describe('gradle migrations', () => {
assertValidMigrationPaths(json as MigrationsJson, __dirname);
});
Loading

0 comments on commit 34bb4d8

Please sign in to comment.