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(devkit): correct nx-json typing after plugin tweaks #19706

Merged
merged 1 commit into from
Oct 18, 2023
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
4 changes: 2 additions & 2 deletions docs/generated/devkit/NxJsonConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Nx.json configuration
- [nxCloudEncryptionKey](../../devkit/documents/NxJsonConfiguration#nxcloudencryptionkey): string
- [nxCloudUrl](../../devkit/documents/NxJsonConfiguration#nxcloudurl): string
- [parallel](../../devkit/documents/NxJsonConfiguration#parallel): number
- [plugins](../../devkit/documents/NxJsonConfiguration#plugins): PluginDefinition[]
- [plugins](../../devkit/documents/NxJsonConfiguration#plugins): PluginConfiguration[]
- [pluginsConfig](../../devkit/documents/NxJsonConfiguration#pluginsconfig): Record<string, Record<string, unknown>>
- [release](../../devkit/documents/NxJsonConfiguration#release): NxReleaseConfiguration
- [targetDefaults](../../devkit/documents/NxJsonConfiguration#targetdefaults): TargetDefaults
Expand Down Expand Up @@ -198,7 +198,7 @@ Specifies how many tasks can be run in parallel.

### plugins

`Optional` **plugins**: `PluginDefinition`[]
`Optional` **plugins**: [`PluginConfiguration`](../../devkit/documents/PluginConfiguration)[]

Plugins for extending the project graph

Expand Down
3 changes: 3 additions & 0 deletions docs/generated/devkit/PluginConfiguration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Type alias: PluginConfiguration

Ƭ **PluginConfiguration**: `string` \| { `options?`: `unknown` ; `plugin`: `string` }
1 change: 1 addition & 0 deletions docs/generated/devkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ It only uses language primitives and immutable objects
- [NxPluginV1](../../devkit/documents/NxPluginV1)
- [NxPluginV2](../../devkit/documents/NxPluginV2)
- [PackageManager](../../devkit/documents/PackageManager)
- [PluginConfiguration](../../devkit/documents/PluginConfiguration)
- [ProjectGraphNode](../../devkit/documents/ProjectGraphNode)
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
- [ProjectType](../../devkit/documents/ProjectType)
Expand Down
4 changes: 2 additions & 2 deletions docs/generated/devkit/Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use ProjectsConfigurations or NxJsonConfiguration
- [nxCloudEncryptionKey](../../devkit/documents/Workspace#nxcloudencryptionkey): string
- [nxCloudUrl](../../devkit/documents/Workspace#nxcloudurl): string
- [parallel](../../devkit/documents/Workspace#parallel): number
- [plugins](../../devkit/documents/Workspace#plugins): PluginDefinition[]
- [plugins](../../devkit/documents/Workspace#plugins): PluginConfiguration[]
- [pluginsConfig](../../devkit/documents/Workspace#pluginsconfig): Record<string, Record<string, unknown>>
- [projects](../../devkit/documents/Workspace#projects): Record<string, ProjectConfiguration>
- [release](../../devkit/documents/Workspace#release): NxReleaseConfiguration
Expand Down Expand Up @@ -254,7 +254,7 @@ Specifies how many tasks can be run in parallel.

### plugins

• `Optional` **plugins**: `PluginDefinition`[]
• `Optional` **plugins**: [`PluginConfiguration`](../../devkit/documents/PluginConfiguration)[]

Plugins for extending the project graph

Expand Down
1 change: 1 addition & 0 deletions docs/generated/packages/devkit/documents/nx_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ It only uses language primitives and immutable objects
- [NxPluginV1](../../devkit/documents/NxPluginV1)
- [NxPluginV2](../../devkit/documents/NxPluginV2)
- [PackageManager](../../devkit/documents/PackageManager)
- [PluginConfiguration](../../devkit/documents/PluginConfiguration)
- [ProjectGraphNode](../../devkit/documents/ProjectGraphNode)
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
- [ProjectType](../../devkit/documents/ProjectType)
Expand Down
6 changes: 3 additions & 3 deletions packages/nx/src/config/nx-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
/**
* Plugins for extending the project graph
*/
plugins?: PluginDefinition[];
plugins?: PluginConfiguration[];

/**
* Configuration for Nx Plugins
Expand Down Expand Up @@ -225,9 +225,9 @@ export interface NxJsonConfiguration<T = '*' | string[]> {
useDaemonProcess?: boolean;
}

export type PluginDefinition =
export type PluginConfiguration =
| string
| { plugin: string; options?: Record<string, unknown> };
| { plugin: string; options?: unknown };

export function readNxJson(root: string = workspaceRoot): NxJsonConfiguration {
const nxJson = join(root, 'nx.json');
Expand Down
1 change: 1 addition & 0 deletions packages/nx/src/devkit-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type {
ImplicitDependencyEntry,
ImplicitJsonSubsetDependency,
NxJsonConfiguration,
PluginConfiguration,
TargetDefaults,
NxAffectedConfig,
} from './config/nx-json';
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/project-graph/nx-deps-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync } from 'fs';
import { ensureDirSync, renameSync } from 'fs-extra';
import { join } from 'path';
import { performance } from 'perf_hooks';
import { NxJsonConfiguration, PluginDefinition } from '../config/nx-json';
import { NxJsonConfiguration, PluginConfiguration } from '../config/nx-json';
import {
FileData,
FileMap,
Expand Down Expand Up @@ -328,7 +328,7 @@ function processProjectNode(
type PluginData = {
name: string;
version: string;
options?: Record<string, unknown>;
options?: unknown;
};

function getNxJsonPluginsData(
Expand Down
20 changes: 10 additions & 10 deletions packages/nx/src/utils/nx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { normalizePath } from './path';
import { dirname, join } from 'path';
import { getNxRequirePaths } from './installation-directory';
import { readTsConfig } from '../plugins/js/utils/typescript';
import { NxJsonConfiguration, PluginDefinition } from '../config/nx-json';
import { NxJsonConfiguration, PluginConfiguration } from '../config/nx-json';

import type * as ts from 'typescript';
import { retrieveProjectConfigurationsWithoutPluginInference } from '../project-graph/utils/retrieve-workspace-files';
Expand Down Expand Up @@ -194,14 +194,14 @@ function getPluginPathAndName(
}

export async function loadNxPluginAsync(
pluginDefinition: PluginDefinition,
pluginConfiguration: PluginConfiguration,
paths: string[],
root: string
): Promise<LoadedNxPlugin> {
const { plugin: moduleName, options } =
typeof pluginDefinition === 'object'
? pluginDefinition
: { plugin: pluginDefinition, options: undefined };
typeof pluginConfiguration === 'object'
? pluginConfiguration
: { plugin: pluginConfiguration, options: undefined };
let pluginModule = nxPluginCache.get(moduleName);
if (pluginModule) {
return { plugin: pluginModule, options };
Expand All @@ -217,14 +217,14 @@ export async function loadNxPluginAsync(
}

function loadNxPluginSync(
pluginDefinition: PluginDefinition,
pluginConfiguration: PluginConfiguration,
paths: string[],
root: string
): LoadedNxPlugin {
const { plugin: moduleName, options } =
typeof pluginDefinition === 'object'
? pluginDefinition
: { plugin: pluginDefinition, options: undefined };
typeof pluginConfiguration === 'object'
? pluginConfiguration
: { plugin: pluginConfiguration, options: undefined };
let pluginModule = nxPluginCache.get(moduleName);
if (pluginModule) {
return { plugin: pluginModule, options };
Expand Down Expand Up @@ -280,7 +280,7 @@ export function loadNxPluginsSync(
}

export async function loadNxPlugins(
plugins: PluginDefinition[],
plugins: PluginConfiguration[],
paths = getNxRequirePaths(),
root = workspaceRoot
): Promise<LoadedNxPlugin[]> {
Expand Down