Skip to content

Commit

Permalink
feat(core): move forEachExecutorOptions to devkit (#15547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 authored Mar 10, 2023
1 parent 46b3767 commit c3a58e9
Show file tree
Hide file tree
Showing 54 changed files with 77 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';

const executors = [
'@angular-devkit/build-angular:browser',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';

export default async function (tree: Tree) {
const nxJson = readNxJson(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Tree } from '@nrwl/devkit';
import { formatFiles } from '@nrwl/devkit';
import * as ts from 'typescript';
import { Builders } from '@schematics/angular/utility/workspace-models';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { FileChangeRecorder } from '../../utils/file-change-recorder';

export default async function (tree: Tree) {
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/utils/get-mf-projects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Tree } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';

export function getMFProjects(
tree: Tree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
updateJson,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { CypressExecutorOptions } from '../../executors/cypress/cypress.impl';
import {
addConfigToTsConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
updateJson,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import * as ts from 'typescript';
import { CypressExecutorOptions } from '../../executors/cypress/cypress.impl';
Expand Down Expand Up @@ -165,4 +165,5 @@ function cacheComponentTestTarget(tree: Tree) {
},
}));
}

export default updateCypressConfigsPresets;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { CypressExecutorOptions } from '@nrwl/cypress/src/executors/cypress/cypress.impl';

export default async function (tree: Tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
Tree,
visitNotIgnoredFiles,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { checkAndCleanWithSemver } from '@nrwl/devkit/src/utils/semver';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import { gte } from 'semver';
import * as ts from 'typescript';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Tree,
visitNotIgnoredFiles,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import { extname } from 'path';
import * as ts from 'typescript';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
GeneratorCallback,
getProjects,
installPackagesTask,
stripIndents,
Tree,
updateJson,
visitNotIgnoredFiles,
installPackagesTask,
GeneratorCallback,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import {
CallExpression,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addProjectConfiguration, Tree } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { addProjectConfiguration, Tree } from 'nx/src/devkit-exports';
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports';

import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from './executor-options-utils';

describe('forEachExecutorOptions', () => {
let tree: Tree;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
Tree,
getProjects,
ProjectConfiguration,
ProjectGraph,
} from '@nrwl/devkit';
import type { Tree } from 'nx/src/generators/tree';
import type { ProjectGraph } from 'nx/src/config/project-graph';
import type { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json';
import { requireNx } from '../../nx';

const { getProjects } = requireNx();

type CallBack<T> = (
currentValue: T,
Expand All @@ -25,7 +25,7 @@ export function forEachExecutorOptions<Options>(
* Callback that is called for each options configured for a builder
*/
callback: CallBack<Options>
) {
): void {
forEachProjectConfig(getProjects(tree), executorName, callback);
}

Expand All @@ -37,7 +37,7 @@ export function forEachExecutorOptionsInGraph<Options>(
graph: ProjectGraph,
executorName: string,
callback: CallBack<Options>
) {
): void {
const projects = new Map<string, ProjectConfiguration>();
Object.values(graph.nodes).forEach((p) => projects.set(p.name, p.data));

Expand All @@ -48,7 +48,7 @@ function forEachProjectConfig<Options>(
projects: Map<string, ProjectConfiguration>,
executorName: string,
callback: CallBack<Options>
) {
): void {
for (const [projectName, project] of projects) {
for (const [targetName, target] of Object.entries(project.targets || {})) {
if (executorName !== target.executor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
Tree,
updateJson,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import {
addPropertyToJestConfig,
removePropertyFromJestConfig,
} from '@nrwl/jest';
import { JestExecutorOptions } from '@nrwl/jest/src/executors/jest/schema';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { join } from 'path';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import {
stripIndents,
Tree,
} from '@nrwl/devkit';

import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { join } from 'path';
import {
addPropertyToJestConfig,
removePropertyFromJestConfig,
} from '../../utils/config/update-config';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { JestExecutorOptions } from '../../executors/jest/schema';

function updateJestConfig(tree: Tree) {
Expand Down
3 changes: 1 addition & 2 deletions packages/jest/src/migrations/update-12-1-2/update-ts-jest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { formatFiles, logger, stripIndents, Tree } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { join } from 'path';

import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { JestExecutorOptions } from '../../executors/jest/schema';
import {
addPropertyToJestConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import {
stripIndents,
Tree,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { join } from 'path';

import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { JestExecutorOptions } from '../../executors/jest/schema';
import { addPropertyToJestConfig } from '../../utils/config/update-config';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { formatFiles, logger, stripIndents, Tree } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { join } from 'path';

import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { JestExecutorOptions } from '../../executors/jest/schema';
import {
addPropertyToJestConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import {
formatFiles,
logger,
Expand All @@ -8,6 +7,7 @@ import {
updateJson,
visitNotIgnoredFiles,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { basename } from 'path';
import { JestExecutorOptions } from '../../executors/jest/schema';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
readProjectConfiguration,
Tree,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { JestExecutorOptions } from '../../executors/jest/schema';
import { jestConfigObject } from '../../utils/config/functions';
import { nxVersion } from '../../utils/versions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
updateJson,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { extname } from 'path';
import { JestExecutorOptions } from '../../executors/jest/schema';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';

const allowedExt = ['.ts', '.js'];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addDependenciesToPackageJson, GeneratorCallback } from '@nrwl/devkit';
import type { Tree } from '@nrwl/devkit';
import { addDependenciesToPackageJson } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { tsNodeVersion } from '../../utils/versions';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import type { BinaryExpression } from 'typescript';
import type { JestExecutorOptions } from '../../executors/jest/schema';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addDependenciesToPackageJson, readJson, Tree } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import { isStringLiteralLike, PropertyAssignment } from 'typescript';
import { JestExecutorOptions } from '../../executors/jest/schema';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Tree,
visitNotIgnoredFiles,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import * as ts from 'typescript';
import { JestExecutorOptions } from '../../executors/jest/schema';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatFiles, readNxJson, Tree, updateNxJson } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';

export default async function (tree: Tree) {
const nxJson = readNxJson(tree);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
createProjectGraphAsync,
formatFiles,
logger,
stripIndents,
Tree,
createProjectGraphAsync,
} from '@nrwl/devkit';
import { forEachExecutorOptionsInGraph } from '@nrwl/devkit/src/generators/executor-options-utils';
import { TS_QUERY_JEST_CONFIG_PREFIX } from '../../utils/ast-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import * as ts from 'typescript';
import { JestExecutorOptions } from '../../executors/jest/schema';
import { forEachExecutorOptionsInGraph } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { findRootJestPreset } from '../../utils/config/find-root-jest-files';

export async function updateConfigsJest29(tree: Tree) {
Expand Down Expand Up @@ -226,4 +226,5 @@ function getNodeWithComments(fullText: string, node: ts.Node) {
}
return node.getText();
}

export default updateConfigsJest29;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Tree,
visitNotIgnoredFiles,
} from '@nrwl/devkit';
import { forEachExecutorOptionsInGraph } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptionsInGraph } from '@nrwl/devkit/src/generators/executor-options-utils';
import { tsquery } from '@phenomnomnominal/tsquery';
import {
CallExpression,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readProjectConfiguration, Tree, updateJson } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { join } from 'path';
import { SwcExecutorOptions } from '../../utils/schema';
import { defaultExclude } from '../../utils/swc/add-swc-config';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readProjectConfiguration, Tree, updateJson } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { SwcExecutorOptions } from '../../utils/schema';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { join } from 'path';

export function excludeJestConfigSwcrc(tree: Tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { SwcExecutorOptions } from '../../utils/schema';

type OldSwcExecutorOptions = SwcExecutorOptions & { swcrcPath?: string };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { SwcExecutorOptions } from '../../utils/schema';
import { tsquery } from '@phenomnomnominal/tsquery';
import type { TemplateSpan } from 'typescript';
Expand Down
2 changes: 1 addition & 1 deletion packages/linter/src/generators/utils/eslint-targets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Tree } from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';

export function getEslintTargets(tree: Tree) {
const eslintTargetNames = new Set<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';

export default async function update(host: Tree) {
forEachExecutorOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';

export default async function update(tree: Tree) {
forEachExecutorOptions(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
addDependenciesToPackageJson,
formatFiles,
getProjects,
readProjectConfiguration,
Tree,
updateProjectConfiguration,
} from '@nrwl/devkit';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { forEachExecutorOptions } from '@nrwl/devkit/src/generators/executor-options-utils';
import { nxVersion } from '@nrwl/workspace/src/utils/versions';

export default async function update(host: Tree) {
Expand Down
Loading

1 comment on commit c3a58e9

@vercel
Copy link

@vercel vercel bot commented on c3a58e9 Mar 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.