From d72ecd6e7384f94af33e2984aa99e9191e40e822 Mon Sep 17 00:00:00 2001 From: Edouard Bozon Date: Mon, 23 Oct 2023 20:29:02 +0200 Subject: [PATCH] feat(devkit): mark `ExecutorContext` props required --- docs/generated/devkit/ExecutorContext.md | 15 ++++----------- .../module-federation-dev-server.impl.ts | 10 +++++----- .../webpack-dev-server/webpack-dev-server.impl.ts | 9 +++++++-- packages/cypress/src/utils/ct-helpers.ts | 4 ++++ packages/cypress/src/utils/find-target-options.ts | 4 ++++ packages/devkit/src/utils/convert-nx-executor.ts | 4 ++++ packages/js/src/executors/tsc/tsc.impl.spec.ts | 8 ++++++++ packages/next/plugins/component-testing.ts | 7 +++++++ packages/nx/src/config/misc-interfaces.ts | 14 ++++---------- 9 files changed, 47 insertions(+), 28 deletions(-) diff --git a/docs/generated/devkit/ExecutorContext.md b/docs/generated/devkit/ExecutorContext.md index 66d17e482d9ed..887daba042e17 100644 --- a/docs/generated/devkit/ExecutorContext.md +++ b/docs/generated/devkit/ExecutorContext.md @@ -47,23 +47,19 @@ Enable verbose logging ### nxJsonConfiguration -• `Optional` **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)<`string`[] \| `"*"`\> +• **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)<`string`[] \| `"*"`\> The contents of nx.json. -@todo(vsavkin): mark this as required for v17 - --- ### projectGraph -• `Optional` **projectGraph**: [`ProjectGraph`](../../devkit/documents/ProjectGraph) +• **projectGraph**: [`ProjectGraph`](../../devkit/documents/ProjectGraph) A snapshot of the project graph as it existed when the Nx command was kicked off -@todo(vsavkin) mark this required for v17 - --- ### projectName @@ -76,12 +72,10 @@ The name of the project being executed on ### projectsConfigurations -• `Optional` **projectsConfigurations**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) +• **projectsConfigurations**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) Projects config -@todo(vsavkin): mark this as required for v17 - --- ### root @@ -119,8 +113,7 @@ it existed when the Nx command was kicked off ### workspace -• `Optional` **workspace**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) & [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)<`string`[] \| `"*"`\> +• **workspace**: [`ProjectsConfigurations`](../../devkit/documents/ProjectsConfigurations) & [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)<`string`[] \| `"*"`\> Deprecated. Use projectsConfigurations or nxJsonConfiguration The full workspace configuration -@todo(vsavkin): remove after v17 diff --git a/packages/angular/src/builders/module-federation-dev-server/module-federation-dev-server.impl.ts b/packages/angular/src/builders/module-federation-dev-server/module-federation-dev-server.impl.ts index 32b89533dcaea..9aa846e781476 100644 --- a/packages/angular/src/builders/module-federation-dev-server/module-federation-dev-server.impl.ts +++ b/packages/angular/src/builders/module-federation-dev-server/module-federation-dev-server.impl.ts @@ -9,11 +9,7 @@ import { scheduleTarget } from 'nx/src/adapter/ngcli-adapter'; import { executeWebpackDevServerBuilder } from '../webpack-dev-server/webpack-dev-server.impl'; import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph'; import { getExecutorInformation } from 'nx/src/command-line/run/executor-utils'; -import { - getDynamicRemotes, - getStaticRemotes, - validateDevRemotes, -} from '../utilities/module-federation'; +import { validateDevRemotes } from '../utilities/module-federation'; import { existsSync } from 'fs'; import { extname, join } from 'path'; import { @@ -64,6 +60,10 @@ export function executeModuleFederationDevServerBuilder( projectsConfigurations: readProjectsConfigurationFromProjectGraph(projectGraph), nxJsonConfiguration: readNxJson(), + workspace: { + version: 2, + projects: workspaceProjects, + }, } ) ) diff --git a/packages/angular/src/builders/webpack-dev-server/webpack-dev-server.impl.ts b/packages/angular/src/builders/webpack-dev-server/webpack-dev-server.impl.ts index ed890083fefe7..a3ab37a405a1b 100644 --- a/packages/angular/src/builders/webpack-dev-server/webpack-dev-server.impl.ts +++ b/packages/angular/src/builders/webpack-dev-server/webpack-dev-server.impl.ts @@ -2,7 +2,6 @@ import { joinPathFragments, parseTargetString, readCachedProjectGraph, - readNxJson, } from '@nx/devkit'; import { WebpackNxBuildCoordinationPlugin } from '@nx/webpack/src/plugins/webpack-nx-build-coordination-plugin'; import { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils'; @@ -19,7 +18,6 @@ import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs'; import { from } from 'rxjs'; import { switchMap } from 'rxjs/operators'; import { getRootTsConfigPath } from '@nx/js'; -import { join } from 'path'; type BuildTargetOptions = { tsConfig: string; @@ -36,12 +34,19 @@ export function executeWebpackDevServerBuilder( const options = normalizeOptions(rawOptions); + const projectsConfigurations = { + version: 2, + projects: {}, + }; const parsedBrowserTarget = parseTargetString(options.browserTarget, { cwd: context.currentDirectory, projectGraph: readCachedProjectGraph(), projectName: context.target.project, root: context.workspaceRoot, isVerbose: false, + projectsConfigurations, + workspace: projectsConfigurations, + nxJsonConfiguration: {}, }); const browserTargetProjectConfiguration = readCachedProjectConfiguration( parsedBrowserTarget.project diff --git a/packages/cypress/src/utils/ct-helpers.ts b/packages/cypress/src/utils/ct-helpers.ts index 99466e8b7f75b..0b7e2414b397c 100644 --- a/packages/cypress/src/utils/ct-helpers.ts +++ b/packages/cypress/src/utils/ct-helpers.ts @@ -124,5 +124,9 @@ export function createExecutorContext( projectName, projectsConfigurations, nxJsonConfiguration, + workspace: { + version: 2, + projects: projectsConfigurations.projects, + }, }; } diff --git a/packages/cypress/src/utils/find-target-options.ts b/packages/cypress/src/utils/find-target-options.ts index a47f37e941282..755b8110f2777 100644 --- a/packages/cypress/src/utils/find-target-options.ts +++ b/packages/cypress/src/utils/find-target-options.ts @@ -244,5 +244,9 @@ function createExecutorContext( projectName, projectsConfigurations, nxJsonConfiguration, + workspace: { + version: 2, + projects: projectsConfigurations.projects, + }, }; } diff --git a/packages/devkit/src/utils/convert-nx-executor.ts b/packages/devkit/src/utils/convert-nx-executor.ts index 8bae918420e68..e2f1077cc0a9e 100644 --- a/packages/devkit/src/utils/convert-nx-executor.ts +++ b/packages/devkit/src/utils/convert-nx-executor.ts @@ -51,6 +51,10 @@ export function convertNxExecutor(executor: Executor) { projectGraph: null, taskGraph: null, isVerbose: false, + workspace: { + version: 2, + projects: projectsConfigurations.projects, + }, }; return executor(options, context); }; diff --git a/packages/js/src/executors/tsc/tsc.impl.spec.ts b/packages/js/src/executors/tsc/tsc.impl.spec.ts index 8842387c2d8bf..8f9f6e1327d0c 100644 --- a/packages/js/src/executors/tsc/tsc.impl.spec.ts +++ b/packages/js/src/executors/tsc/tsc.impl.spec.ts @@ -16,6 +16,14 @@ describe('tscExecutor', () => { projects: {}, }, nxJsonConfiguration: {}, + projectGraph: { + nodes: {}, + dependencies: {}, + }, + workspace: { + version: 2, + projects: {}, + }, isVerbose: false, projectName: 'example', targetName: 'build', diff --git a/packages/next/plugins/component-testing.ts b/packages/next/plugins/component-testing.ts index 2280ef836da36..d7c9dd59b6d7a 100644 --- a/packages/next/plugins/component-testing.ts +++ b/packages/next/plugins/component-testing.ts @@ -58,12 +58,19 @@ export function nxComponentTestingPreset( let buildFileReplacements = []; let buildOuputPath = `dist/${ctProjectName}/.next`; if (buildTarget) { + const projectsConfigurations = { + version: 2, + projects: {}, + }; const parsedBuildTarget = parseTargetString(buildTarget, { cwd: process.cwd(), root: workspaceRoot, isVerbose: false, projectName: ctProjectName, projectGraph: graph, + projectsConfigurations, + workspace: projectsConfigurations, + nxJsonConfiguration: {}, }); const buildProjectConfig = graph.nodes[parsedBuildTarget.project]?.data; const buildExecutorContext = createExecutorContext( diff --git a/packages/nx/src/config/misc-interfaces.ts b/packages/nx/src/config/misc-interfaces.ts index 0736e16e114cd..280d0099cc1b9 100644 --- a/packages/nx/src/config/misc-interfaces.ts +++ b/packages/nx/src/config/misc-interfaces.ts @@ -195,16 +195,13 @@ export interface ExecutorContext { /** * Projects config * - * @todo(vsavkin): mark this as required for v17 */ - projectsConfigurations?: ProjectsConfigurations; + projectsConfigurations: ProjectsConfigurations; /** * The contents of nx.json. - * - * @todo(vsavkin): mark this as required for v17 */ - nxJsonConfiguration?: NxJsonConfiguration; + nxJsonConfiguration: NxJsonConfiguration; /** * The current working directory @@ -219,10 +216,8 @@ export interface ExecutorContext { /** * A snapshot of the project graph as * it existed when the Nx command was kicked off - * - * @todo(vsavkin) mark this required for v17 */ - projectGraph?: ProjectGraph; + projectGraph: ProjectGraph; /** * A snapshot of the task graph as @@ -233,7 +228,6 @@ export interface ExecutorContext { /** * Deprecated. Use projectsConfigurations or nxJsonConfiguration * The full workspace configuration - * @todo(vsavkin): remove after v17 */ - workspace?: ProjectsConfigurations & NxJsonConfiguration; + workspace: ProjectsConfigurations & NxJsonConfiguration; }