From 0f439f8cd1c5193865de98ef97e5df5c88720498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJamesHenry=E2=80=9D?= Date: Mon, 12 Feb 2024 17:50:52 +0400 Subject: [PATCH] chore(core): try and fix failing e2e --- docs/generated/devkit/CreateNodesContext.md | 22 +++++++++---------- ...place-project-configuration-with-plugin.ts | 6 ++--- .../src/utils/update-package-scripts.ts | 6 ++--- packages/eslint/src/plugins/plugin.ts | 16 +++++++++----- .../utils/project-configuration-utils.ts | 2 +- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/docs/generated/devkit/CreateNodesContext.md b/docs/generated/devkit/CreateNodesContext.md index c358b228327869..2869591ec94b3c 100644 --- a/docs/generated/devkit/CreateNodesContext.md +++ b/docs/generated/devkit/CreateNodesContext.md @@ -6,32 +6,32 @@ Context for [CreateNodesFunction](../../devkit/documents/CreateNodesFunction) ### Properties -- [matchingFiles](../../devkit/documents/CreateNodesContext#matchingfiles): string[] +- [allConfigFiles](../../devkit/documents/CreateNodesContext#allconfigfiles): string[] +- [matchingConfigFiles](../../devkit/documents/CreateNodesContext#matchingconfigfiles): string[] - [nxJsonConfiguration](../../devkit/documents/CreateNodesContext#nxjsonconfiguration): NxJsonConfiguration -- [workspaceFiles](../../devkit/documents/CreateNodesContext#workspacefiles): string[] - [workspaceRoot](../../devkit/documents/CreateNodesContext#workspaceroot): string ## Properties -### matchingFiles +### allConfigFiles -• `Readonly` **matchingFiles**: `string`[] +• `Readonly` **allConfigFiles**: `string`[] -The subset of non-ignored files which match the createNodes pattern +All configuration files identified in the workspace --- -### nxJsonConfiguration +### matchingConfigFiles -• `Readonly` **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\> +• `Readonly` **matchingConfigFiles**: `string`[] ---- +The subset of configuration files which match the createNodes pattern -### workspaceFiles +--- -• `Readonly` **workspaceFiles**: `string`[] +### nxJsonConfiguration -All non-ignored files in the workspace +• `Readonly` **nxJsonConfiguration**: [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration)\<`string`[] \| `"*"`\> --- diff --git a/packages/devkit/src/utils/replace-project-configuration-with-plugin.ts b/packages/devkit/src/utils/replace-project-configuration-with-plugin.ts index 10a4af8f928f01..1f4e4d8c477d80 100644 --- a/packages/devkit/src/utils/replace-project-configuration-with-plugin.ts +++ b/packages/devkit/src/utils/replace-project-configuration-with-plugin.ts @@ -3,7 +3,7 @@ import type { TargetConfiguration, } from 'nx/src/config/workspace-json-project-json'; import type { Tree } from 'nx/src/generators/tree'; -import type { CreateNodes } from 'nx/src/utils/nx-plugin'; +import type { CreateNodes } from 'nx/src/project-graph/plugins'; import { requireNx } from '../../nx'; const { readNxJson, @@ -48,8 +48,8 @@ export async function replaceProjectConfigurationsWithPlugin( const nodes = await createNodesFunction(configFile, pluginOptions, { workspaceRoot: tree.root, nxJsonConfiguration: readNxJson(tree), - workspaceFiles: configFiles, - matchingFiles: configFiles, + allConfigFiles: configFiles, + matchingConfigFiles: configFiles, }); const node = nodes.projects[Object.keys(nodes.projects)[0]]; diff --git a/packages/devkit/src/utils/update-package-scripts.ts b/packages/devkit/src/utils/update-package-scripts.ts index c042cc61ce2a65..e949d9051aee29 100644 --- a/packages/devkit/src/utils/update-package-scripts.ts +++ b/packages/devkit/src/utils/update-package-scripts.ts @@ -4,7 +4,7 @@ import type { CreateNodes, CreateNodesFunction, CreateNodesResult, -} from 'nx/src/utils/nx-plugin'; +} from 'nx/src/project-graph/plugins'; import type { PackageJson } from 'nx/src/utils/package-json'; import { basename, dirname } from 'path'; import * as yargs from 'yargs-parser'; @@ -70,8 +70,8 @@ async function processProject( { nxJsonConfiguration, workspaceRoot, - workspaceFiles, - matchingFiles, + allConfigFiles: workspaceFiles, + matchingConfigFiles: matchingFiles, } ); diff --git a/packages/eslint/src/plugins/plugin.ts b/packages/eslint/src/plugins/plugin.ts index df3dd69c056375..1d293d1582feb4 100644 --- a/packages/eslint/src/plugins/plugin.ts +++ b/packages/eslint/src/plugins/plugin.ts @@ -26,6 +26,9 @@ export const createNodes: CreateNodes = [ (configFilePath, options, context) => { options = normalizeOptions(options); + // TODO: Figure out why this is required to protect against failures in e2e-run + (context as any).workspaceFiles = context.workspaceFiles ?? []; + const configDir = dirname(configFilePath); if (configDir === '.') { return { @@ -53,24 +56,23 @@ function getProjectsUsingRootESLintConfig( context: CreateNodesContext ): CreateNodesResult['projects'] { const projects: CreateNodesResult['projects'] = {}; - const workspaceFiles = context.workspaceFiles ?? []; // If there's no src folder, it's not a standalone project, so a project.json would be explicitly required to add the root to the mapping const isStandaloneWorkspace = - workspaceFiles.some((f) => f.startsWith('src')) && - workspaceFiles.includes('package.json'); + context.workspaceFiles.some((f) => f.startsWith('src')) && + context.workspaceFiles.includes('package.json'); if (isStandaloneWorkspace) { projects['.'] = { targets: buildEslintTargets([configFilePath], '.', options, true), }; - } else if (workspaceFiles.includes('project.json')) { + } else if (context.workspaceFiles.includes('project.json')) { projects['.'] = { targets: buildEslintTargets([configFilePath], '.', options), }; } // Some nested projects may require a lint target based on this root level config as well (in the case they don't have their own) - const childProjectRoots = workspaceFiles + const childProjectRoots = context.workspaceFiles .filter( (f) => f.includes('/') && @@ -82,7 +84,9 @@ function getProjectsUsingRootESLintConfig( const childProjectsWithoutEslintConfig = childProjectRoots.filter( (childProjectRoot) => !ESLINT_CONFIG_FILENAMES.some((eslintConfigFile) => - workspaceFiles.includes(join(childProjectRoot, eslintConfigFile)) + context.workspaceFiles.includes( + join(childProjectRoot, eslintConfigFile) + ) ) ); 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 c0f80b38fa196a..c901f98f5396bc 100644 --- a/packages/nx/src/project-graph/utils/project-configuration-utils.ts +++ b/packages/nx/src/project-graph/utils/project-configuration-utils.ts @@ -225,7 +225,7 @@ export function buildProjectsConfigurationsFromProjectPathsAndPlugins( nxJsonConfiguration: nxJson, workspaceRoot: root, allConfigFiles, - matchingConfigFiles + matchingConfigFiles, }).catch((e) => shutdownPluginWorkers().then(() => { throw e;