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

feat(devkit): mark ExecutorContext props required #19803

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 4 additions & 11 deletions docs/generated/devkit/ExecutorContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -64,6 +60,10 @@ export function executeModuleFederationDevServerBuilder(
projectsConfigurations:
readProjectsConfigurationFromProjectGraph(projectGraph),
nxJsonConfiguration: readNxJson(),
workspace: {
version: 2,
projects: workspaceProjects,
},
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/cypress/src/utils/ct-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,9 @@ export function createExecutorContext(
projectName,
projectsConfigurations,
nxJsonConfiguration,
workspace: {
version: 2,
projects: projectsConfigurations.projects,
},
};
}
4 changes: 4 additions & 0 deletions packages/cypress/src/utils/find-target-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,9 @@ function createExecutorContext(
projectName,
projectsConfigurations,
nxJsonConfiguration,
workspace: {
version: 2,
projects: projectsConfigurations.projects,
},
};
}
9 changes: 9 additions & 0 deletions packages/devkit/src/executors/parse-target-string.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ describe('parseTargetString', () => {
externalNodes: {},
version: '',
},
workspace: {
version: 2,
projects: {},
},
projectsConfigurations: {
version: 2,
projects: {},
},
nxJsonConfiguration: {},
};

it.each(cases)('$input -> $expected', ({ input, expected }) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/devkit/src/utils/convert-nx-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import { ExecutorContext } from 'nx/src/config/misc-interfaces';
import path = require('path');

describe('buildEsbuildOptions', () => {
const context: ExecutorContext = {
projectName: 'myapp',
projectsConfigurations: {
version: 2,
projects: {
myapp: {
root: 'apps/myapp',
},
const projectsConfigurations = {
version: 2,
projects: {
myapp: {
root: 'apps/myapp',
},
},
};
const context: ExecutorContext = {
projectName: 'myapp',
projectsConfigurations,
projectGraph: {
nodes: {
myapp: {
Expand All @@ -33,6 +34,7 @@ describe('buildEsbuildOptions', () => {
outputPath: 'dist/apps/myapp',
},
},
workspace: projectsConfigurations,
};

it('should include environment variables for platform === browser', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ describe('normalizeOptions', () => {
},
dependencies: {},
},
workspace: {
version: 2,
projects: {},
},
projectsConfigurations: {
version: 2,
projects: {},
},
nxJsonConfiguration: {},
};

it('should handle single entry point options', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint/src/executors/lint/lint.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ describe('Linter Builder', () => {
},
},
nxJsonConfiguration: {},
workspace: {
version: 2,
projects: {},
},
projectGraph: {
nodes: {},
dependencies: {},
},
isVerbose: false,
};
mockLintFiles.mockImplementation(() => mockReports);
Expand Down
8 changes: 8 additions & 0 deletions packages/jest/src/executors/jest/jest.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ describe('Jest Executor', () => {
},
cwd: '/root',
isVerbose: true,
workspace: {
version: 2,
projects: {},
},
projectGraph: {
nodes: {},
dependencies: {},
},
};
});

Expand Down
8 changes: 8 additions & 0 deletions packages/js/src/executors/tsc/tsc.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ describe('tscExecutor', () => {
projects: {},
},
nxJsonConfiguration: {},
projectGraph: {
nodes: {},
dependencies: {},
},
workspace: {
version: 2,
projects: {},
},
isVerbose: false,
projectName: 'example',
targetName: 'build',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,15 @@ describe('updatePackageJson', () => {
cwd: '',
targetName: 'build',
projectGraph,
nxJsonConfiguration: {},
projectsConfigurations: {
version: 2,
projects: {},
},
workspace: {
version: 2,
projects: {},
},
};

it('should generate new package if missing', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/next/plugins/component-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 4 additions & 10 deletions packages/nx/src/config/misc-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
}
8 changes: 8 additions & 0 deletions packages/rollup/src/executors/rollup/rollup.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ describe('rollupExecutor', () => {
isVerbose: false,
projectName: 'example',
targetName: 'build',
projectGraph: {
nodes: {},
dependencies: {},
},
workspace: {
version: 2,
projects: {},
},
};
testOptions = {
compiler: 'babel',
Expand Down