Skip to content

Commit

Permalink
fix(plugin-eslint): dynamic import for optional peer dep @nx/devkit
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Dec 4, 2023
1 parent d6a6b2a commit ab62f2f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-eslint/src/lib/nx/find-all-projects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createProjectGraphAsync } from '@nx/devkit';
import type { ESLintPluginConfig } from '../config';
import { nxProjectsToConfig } from './projects-to-config';

Expand All @@ -24,6 +23,7 @@ import { nxProjectsToConfig } from './projects-to-config';
* @returns ESLint config and patterns, intended to be passed to {@link eslintPlugin}
*/
export async function eslintConfigFromNxProjects(): Promise<ESLintPluginConfig> {
const { createProjectGraphAsync } = await import('@nx/devkit');
const projectGraph = await createProjectGraphAsync({ exitOnError: false });
return nxProjectsToConfig(projectGraph);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createProjectGraphAsync } from '@nx/devkit';
import type { ESLintPluginConfig } from '../config';
import { nxProjectsToConfig } from './projects-to-config';
import { findAllDependencies } from './traverse-graph';
Expand Down Expand Up @@ -30,6 +29,7 @@ import { findAllDependencies } from './traverse-graph';
export async function eslintConfigFromNxProject(
projectName: string,
): Promise<ESLintPluginConfig> {
const { createProjectGraphAsync } = await import('@nx/devkit');
const projectGraph = await createProjectGraphAsync({ exitOnError: false });

const dependencies = findAllDependencies(projectName, projectGraph);
Expand Down
9 changes: 4 additions & 5 deletions packages/plugin-eslint/src/lib/nx/projects-to-config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ProjectConfiguration,
ProjectGraph,
readProjectsConfigurationFromProjectGraph,
} from '@nx/devkit';
import type { ProjectConfiguration, ProjectGraph } from '@nx/devkit';
import type { ESLint } from 'eslint';
import type { ESLintPluginConfig } from '../config';
import {
Expand All @@ -16,6 +12,9 @@ export async function nxProjectsToConfig(
predicate: (project: ProjectConfiguration) => boolean = () => true,
): Promise<ESLintPluginConfig> {
// find Nx projects with lint target
const { readProjectsConfigurationFromProjectGraph } = await import(
'@nx/devkit'
);
const projectsConfiguration =
readProjectsConfigurationFromProjectGraph(projectGraph);
const projects = Object.values(projectsConfiguration.projects)
Expand Down

0 comments on commit ab62f2f

Please sign in to comment.