From 9ece602c33a96da1a022f0b44ce6a950dc7beb6f Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Tue, 26 Mar 2024 17:58:54 -0400 Subject: [PATCH] chore(repo): docs + format --- docs/generated/devkit/CreateNodes.md | 2 +- .../devkit/ExpandedPluginConfiguration.md | 12 ++++++++++++ docs/generated/devkit/PluginConfiguration.md | 2 +- docs/generated/devkit/README.md | 1 + .../packages/devkit/documents/nx_devkit.md | 1 + nx.json | 2 +- .../src/utils/convert-nx-executor.spec.ts | 8 ++++---- packages/nx/src/config/nx-json.ts | 4 +--- .../project-graph-incremental-recomputation.ts | 6 ++---- .../update-15-1-0/set-project-names.ts | 8 ++++---- .../nx/src/plugins/target-defaults/symbols.ts | 2 +- packages/nx/src/project-graph/error-types.ts | 2 +- packages/nx/src/project-graph/file-utils.ts | 14 +++++++++----- packages/nx/src/project-graph/plugins/index.ts | 5 +---- .../src/project-graph/plugins/internal-api.ts | 6 ++---- .../nx/src/project-graph/plugins/public-api.ts | 2 +- packages/nx/src/project-graph/plugins/utils.ts | 5 ----- .../utils/project-configuration-utils.ts | 17 ++++++++--------- .../nx/src/utils/plugins/plugin-capabilities.ts | 2 +- 19 files changed, 52 insertions(+), 49 deletions(-) create mode 100644 docs/generated/devkit/ExpandedPluginConfiguration.md diff --git a/docs/generated/devkit/CreateNodes.md b/docs/generated/devkit/CreateNodes.md index 766261c911cab4..ed46857f91b7cd 100644 --- a/docs/generated/devkit/CreateNodes.md +++ b/docs/generated/devkit/CreateNodes.md @@ -1,6 +1,6 @@ # Type alias: CreateNodes\ -Ƭ **CreateNodes**\<`T`\>: readonly [configFilePattern: string, createNodesFunction: CreateNodesFunction\] +Ƭ **CreateNodes**\<`T`\>: readonly [projectFilePattern: string, createNodesFunction: CreateNodesFunction\] A pair of file patterns and [CreateNodesFunction](../../devkit/documents/CreateNodesFunction) diff --git a/docs/generated/devkit/ExpandedPluginConfiguration.md b/docs/generated/devkit/ExpandedPluginConfiguration.md new file mode 100644 index 00000000000000..58ad5aafc1ae5d --- /dev/null +++ b/docs/generated/devkit/ExpandedPluginConfiguration.md @@ -0,0 +1,12 @@ +# Type alias: ExpandedPluginConfiguration + +Ƭ **ExpandedPluginConfiguration**: `Object` + +#### Type declaration + +| Name | Type | +| :--------- | :--------- | +| `exclude?` | `string`[] | +| `include?` | `string`[] | +| `options?` | `unknown` | +| `plugin` | `string` | diff --git a/docs/generated/devkit/PluginConfiguration.md b/docs/generated/devkit/PluginConfiguration.md index 64b7b8baf8acc2..fd55cbdc880921 100644 --- a/docs/generated/devkit/PluginConfiguration.md +++ b/docs/generated/devkit/PluginConfiguration.md @@ -1,3 +1,3 @@ # Type alias: PluginConfiguration -Ƭ **PluginConfiguration**: `string` \| \{ `exclude?`: `string`[] ; `include?`: `string`[] ; `options?`: `unknown` ; `plugin`: `string` } +Ƭ **PluginConfiguration**: `string` \| [`ExpandedPluginConfiguration`](../../devkit/documents/ExpandedPluginConfiguration) diff --git a/docs/generated/devkit/README.md b/docs/generated/devkit/README.md index 25f19c02c7193d..af2f0bfb1ead13 100644 --- a/docs/generated/devkit/README.md +++ b/docs/generated/devkit/README.md @@ -69,6 +69,7 @@ It only uses language primitives and immutable objects - [CustomHasher](../../devkit/documents/CustomHasher) - [DynamicDependency](../../devkit/documents/DynamicDependency) - [Executor](../../devkit/documents/Executor) +- [ExpandedPluginConfiguration](../../devkit/documents/ExpandedPluginConfiguration) - [Generator](../../devkit/documents/Generator) - [GeneratorCallback](../../devkit/documents/GeneratorCallback) - [Hasher](../../devkit/documents/Hasher) diff --git a/docs/generated/packages/devkit/documents/nx_devkit.md b/docs/generated/packages/devkit/documents/nx_devkit.md index 25f19c02c7193d..af2f0bfb1ead13 100644 --- a/docs/generated/packages/devkit/documents/nx_devkit.md +++ b/docs/generated/packages/devkit/documents/nx_devkit.md @@ -69,6 +69,7 @@ It only uses language primitives and immutable objects - [CustomHasher](../../devkit/documents/CustomHasher) - [DynamicDependency](../../devkit/documents/DynamicDependency) - [Executor](../../devkit/documents/Executor) +- [ExpandedPluginConfiguration](../../devkit/documents/ExpandedPluginConfiguration) - [Generator](../../devkit/documents/Generator) - [GeneratorCallback](../../devkit/documents/GeneratorCallback) - [Hasher](../../devkit/documents/Hasher) diff --git a/nx.json b/nx.json index cbdae48da3798d..ca8d3540dcc891 100644 --- a/nx.json +++ b/nx.json @@ -221,6 +221,6 @@ "nxCloudUrl": "https://staging.nx.app", "parallel": 1, "cacheDirectory": "/tmp/nx-cache", - "bust": 5, + "bust": 6, "defaultBase": "master" } diff --git a/packages/devkit/src/utils/convert-nx-executor.spec.ts b/packages/devkit/src/utils/convert-nx-executor.spec.ts index 8e89f8d701efff..d212316ea821e3 100644 --- a/packages/devkit/src/utils/convert-nx-executor.spec.ts +++ b/packages/devkit/src/utils/convert-nx-executor.spec.ts @@ -1,10 +1,9 @@ -import { requireNx } from '../../nx'; +import { TempFs } from '../../internal-testing-utils'; import { convertNxExecutor } from './convert-nx-executor'; -const { workspaceRoot } = requireNx(); - describe('Convert Nx Executor', () => { it('should convertNxExecutor to builder correctly and produce the same output', async () => { + const fs = new TempFs('convert-nx-executor'); // ARRANGE const { schema } = require('@angular-devkit/core'); const { @@ -16,7 +15,7 @@ describe('Convert Nx Executor', () => { const registry = new schema.CoreSchemaRegistry(); registry.addPostTransform(schema.transforms.addUndefinedDefaults); const testArchitectHost = new TestingArchitectHost(); - testArchitectHost.workspaceRoot = workspaceRoot; + testArchitectHost.workspaceRoot = fs.tempDir; const architect = new Architect(testArchitectHost, registry); const convertedExecutor = convertNxExecutor(echoExecutor); @@ -90,6 +89,7 @@ describe('Convert Nx Executor', () => { expect(convertedExecutor.handler.toString()).toEqual( realBuilder.handler.toString() ); + fs.cleanup(); }); }); diff --git a/packages/nx/src/config/nx-json.ts b/packages/nx/src/config/nx-json.ts index 1146732cb4116c..83c7d2bac22d6e 100644 --- a/packages/nx/src/config/nx-json.ts +++ b/packages/nx/src/config/nx-json.ts @@ -436,9 +436,7 @@ export interface NxJsonConfiguration { useInferencePlugins?: boolean; } -export type PluginConfiguration = - | string - | ExpandedPluginConfiguration; +export type PluginConfiguration = string | ExpandedPluginConfiguration; export type ExpandedPluginConfiguration = { plugin: string; diff --git a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts index fbc260c696dce0..846b357f65e530 100644 --- a/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts +++ b/packages/nx/src/daemon/server/project-graph-incremental-recomputation.ts @@ -32,13 +32,11 @@ import { workspaceRoot } from '../../utils/workspace-root'; import { notifyFileWatcherSockets } from './file-watching/file-watcher-sockets'; import { serverLogger } from './logger'; import { NxWorkspaceFilesExternals } from '../../native'; -import { - ConfigurationResult, -} from '../../project-graph/utils/project-configuration-utils'; +import { ConfigurationResult } from '../../project-graph/utils/project-configuration-utils'; import { DaemonProjectGraphError } from '../daemon-project-graph-error'; import { LoadedNxPlugin } from '../../project-graph/plugins/internal-api'; import { getPlugins } from './plugins'; -import { ProjectConfigurationsError } from 'nx/src/project-graph/error-types'; +import { ProjectConfigurationsError } from '../../project-graph/error-types'; interface SerializedProjectGraph { error: Error | null; diff --git a/packages/nx/src/migrations/update-15-1-0/set-project-names.ts b/packages/nx/src/migrations/update-15-1-0/set-project-names.ts index aed9f9b5f6965d..f61e283fa3064b 100644 --- a/packages/nx/src/migrations/update-15-1-0/set-project-names.ts +++ b/packages/nx/src/migrations/update-15-1-0/set-project-names.ts @@ -8,11 +8,11 @@ import { loadNxPlugins } from '../../project-graph/plugins/internal-api'; export default async function (tree: Tree) { const nxJson = readNxJson(tree); - const [plugins, cleanup] = (await loadNxPlugins(nxJson?.plugins ?? [], tree.root)) - const projectFiles = retrieveProjectConfigurationPaths( - tree.root, - plugins + const [plugins, cleanup] = await loadNxPlugins( + nxJson?.plugins ?? [], + tree.root ); + const projectFiles = retrieveProjectConfigurationPaths(tree.root, plugins); const projectJsons = projectFiles.filter((f) => f.endsWith('project.json')); for (let f of projectJsons) { diff --git a/packages/nx/src/plugins/target-defaults/symbols.ts b/packages/nx/src/plugins/target-defaults/symbols.ts index b47b7e77e9c9f9..e42ced0cc9c8eb 100644 --- a/packages/nx/src/plugins/target-defaults/symbols.ts +++ b/packages/nx/src/plugins/target-defaults/symbols.ts @@ -15,4 +15,4 @@ export const ONLY_MODIFIES_EXISTING_TARGET = 'NX_ONLY_MODIFIES_EXISTING_TARGET'; * NOTE: This cannot be a symbol, as they are not serialized in JSON the communication * between the plugin-worker and the main process. */ -export const OVERRIDE_SOURCE_FILE = 'NX_OVERRIDE_SOURCE_FILE'; \ No newline at end of file +export const OVERRIDE_SOURCE_FILE = 'NX_OVERRIDE_SOURCE_FILE'; diff --git a/packages/nx/src/project-graph/error-types.ts b/packages/nx/src/project-graph/error-types.ts index 2ef3193b45325c..87ca50d23af91f 100644 --- a/packages/nx/src/project-graph/error-types.ts +++ b/packages/nx/src/project-graph/error-types.ts @@ -95,4 +95,4 @@ export function isMergeNodesError(e: unknown): e is MergeNodesError { 'name' in e && e?.name === MergeNodesError.prototype.name) ); -} \ No newline at end of file +} diff --git a/packages/nx/src/project-graph/file-utils.ts b/packages/nx/src/project-graph/file-utils.ts index 3d73a37a05ece0..800654067c2254 100644 --- a/packages/nx/src/project-graph/file-utils.ts +++ b/packages/nx/src/project-graph/file-utils.ts @@ -204,11 +204,15 @@ function getProjectsSyncNoInference(root: string, nxJson: NxJsonConfiguration) { ); for (const file of matchingConfigFiles) { if (minimatch(file, pattern, { dot: true })) { - let r = createNodes(file, {}, { - nxJsonConfiguration: nxJson, - workspaceRoot: root, - configFiles: matchingConfigFiles, - }) as CreateNodesResult; + let r = createNodes( + file, + {}, + { + nxJsonConfiguration: nxJson, + workspaceRoot: root, + configFiles: matchingConfigFiles, + } + ) as CreateNodesResult; for (const node in r.projects) { const project = { root: node, diff --git a/packages/nx/src/project-graph/plugins/index.ts b/packages/nx/src/project-graph/plugins/index.ts index d22ae00ed187b3..f48519b8afa778 100644 --- a/packages/nx/src/project-graph/plugins/index.ts +++ b/packages/nx/src/project-graph/plugins/index.ts @@ -1,6 +1,3 @@ export * from './public-api'; -export { - readPluginPackageJson, - registerPluginTSTranspiler, -} from './loader'; +export { readPluginPackageJson, registerPluginTSTranspiler } from './loader'; diff --git a/packages/nx/src/project-graph/plugins/internal-api.ts b/packages/nx/src/project-graph/plugins/internal-api.ts index 375a515e18b985..8271c0e2457ed7 100644 --- a/packages/nx/src/project-graph/plugins/internal-api.ts +++ b/packages/nx/src/project-graph/plugins/internal-api.ts @@ -15,7 +15,7 @@ import { CreateNodesResult, NxPluginV2, } from './public-api'; -import { ProjectGraphProcessor } from 'nx/src/config/project-graph'; +import { ProjectGraphProcessor } from '../../config/project-graph'; import { runCreateNodesInParallel } from './utils'; import { loadNxPluginInIsolation } from './isolation'; import { loadNxPlugin, unregisterPluginTSTranspiler } from './loader'; @@ -89,12 +89,10 @@ export async function loadNxPlugins( const result: Promise[] = []; const loadingMethod = - process.env.NX_PLUGIN_ISOLATION === 'true' + process.env.NX_ISOLATE_PLUGINS === 'true' ? loadNxPluginInIsolation : loadNxPlugin; - console.log(loadingMethod === loadNxPluginInIsolation ? 'isolated' : 'not isolated') - plugins = await normalizePlugins(plugins, root); const cleanupFunctions: Array<() => void> = []; diff --git a/packages/nx/src/project-graph/plugins/public-api.ts b/packages/nx/src/project-graph/plugins/public-api.ts index db6796c6f3d09c..835ecf77c081d3 100644 --- a/packages/nx/src/project-graph/plugins/public-api.ts +++ b/packages/nx/src/project-graph/plugins/public-api.ts @@ -22,7 +22,7 @@ export interface CreateNodesContext { /** * The subset of configuration files which match the createNodes pattern */ - readonly configFiles: string[]; + readonly configFiles: string[]; } /** diff --git a/packages/nx/src/project-graph/plugins/utils.ts b/packages/nx/src/project-graph/plugins/utils.ts index 51eb9d1a9f7ac8..3285682c214a41 100644 --- a/packages/nx/src/project-graph/plugins/utils.ts +++ b/packages/nx/src/project-graph/plugins/utils.ts @@ -56,11 +56,6 @@ export async function runCreateNodesInParallel( ): Promise { performance.mark(`${plugin.name}:createNodes - start`); - console.log('FINDING NODES', { - plugin: plugin.name, - configFiles, - }) - const promises: Array< CreateNodesResultWithContext | Promise > = configFiles.map((file) => { diff --git a/packages/nx/src/project-graph/utils/project-configuration-utils.ts b/packages/nx/src/project-graph/utils/project-configuration-utils.ts index eedd51d054d26e..de21d66bfa652a 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -353,15 +353,14 @@ export async function createProjectConfigurations( nxJsonConfiguration: nxJson, workspaceRoot: root, configFiles: matchingConfigFiles, - }) - .catch((e) => { - if (isAggregateCreateNodesError(e)) { - errors.push(...e.errors); - return e.partialResults; - } else { - throw e; - } - }); + }).catch((e) => { + if (isAggregateCreateNodesError(e)) { + errors.push(...e.errors); + return e.partialResults; + } else { + throw e; + } + }); results.push(r); } diff --git a/packages/nx/src/utils/plugins/plugin-capabilities.ts b/packages/nx/src/utils/plugins/plugin-capabilities.ts index 595d552bd03a28..875a2150d24584 100644 --- a/packages/nx/src/utils/plugins/plugin-capabilities.ts +++ b/packages/nx/src/utils/plugins/plugin-capabilities.ts @@ -3,6 +3,7 @@ import { dirname, join } from 'path'; import { ProjectConfiguration } from '../../config/workspace-json-project-json'; import { NxPlugin, readPluginPackageJson } from '../../project-graph/plugins'; +import { loadNxPlugin } from '../../project-graph/plugins/loader'; import { readJsonFile } from '../fileutils'; import { getNxRequirePaths } from '../installation-directory'; import { output } from '../output'; @@ -12,7 +13,6 @@ import { workspaceRoot } from '../workspace-root'; import { hasElements } from './shared'; import type { PluginCapabilities } from './models'; -import { loadNxPlugin } from 'nx/src/project-graph/plugins/loader'; function tryGetCollection( packageJsonPath: string,