Skip to content

@nx/eslint:lint-project create a fresh graph at every run #27849

Closed
@beaussan

Description

@beaussan

Current Behavior

@nx/eslint:lint-project create a fresh graph every time, making custom plugins wrapping other generators (such as @nx/react:library) test creating a lot of graph, running the tests extremely slow

 PASS   my-plugin  my-plugin/src/generator.spec.ts (26.856 s)
  lib generator
    ✓ should generate 5 libs with skipEslint=false (25324 ms)
    ✓ should generate 5 libs with skipEslint=true (167 ms)

Expected Behavior

@nx/eslint:lint-project read the cached graph instead of creating a new graph every time

GitHub Repo

https://github.com/beaussan/repro-nx-plugin-test-daemon

Steps to Reproduce

Here is a test file that trigger the issue:

import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { libraryGenerator as nxReactLibGenerator } from '@nx/react/src/generators/library/library';
import { Linter } from '@nx/eslint';

const numberOfLibs = 5;

describe('lib generator', () => {
  let tree: Tree;

  beforeEach(() => {
    tree = createTreeWithEmptyWorkspace();
  });

  it(`should generate ${numberOfLibs} libs with skipEslint=false`, async () => {
    for (let i = 0; i < numberOfLibs; i++) {
      await nxReactLibGenerator(tree, {
        bundler: 'vite',
        // waiting on an answer for a better way from the nx team, since their getRelativeCwd is not a public api _yet_.
        compiler: 'babel',
        directory: `my-lib-${i}`,
        linter: Linter.EsLint,
        name: `my-lib-${i}`,
        projectNameAndRootFormat: 'as-provided',
        setParserOptionsProject: true,
        skipPackageJson: true,
        skipTsConfig: true,
        style: 'styled-components',
        unitTestRunner: 'vitest',
      });
      const config = readProjectConfiguration(tree, `my-lib-${i}`);
      expect(config).toBeDefined();
    }
  }, 90000);

  it(`should generate ${numberOfLibs} libs with skipEslint=true`, async () => {
    for (let i = 0; i < numberOfLibs; i++) {
      await nxReactLibGenerator(tree, {
        bundler: 'vite',
        // waiting on an answer for a better way from the nx team, since their getRelativeCwd is not a public api _yet_.
        compiler: 'babel',
        directory: `my-lib-${i}`,
        linter: Linter.None,
        name: `my-lib-${i}`,
        projectNameAndRootFormat: 'as-provided',
        setParserOptionsProject: true,
        skipPackageJson: true,
        skipTsConfig: true,
        style: 'styled-components',
        unitTestRunner: 'vitest',
      });
      const config = readProjectConfiguration(tree, `my-lib-${i}`);
      expect(config).toBeDefined();
    }
  }, 90000);
});

Nx Report

Node           : 20.11.1
OS             : darwin-arm64
Native Target  : aarch64-macos
yarn           : 4.4.1

nx                 : 19.6.5
@nx/js             : 19.6.5
@nx/jest           : 19.6.5
@nx/linter         : 19.6.5
@nx/eslint         : 19.6.5
@nx/workspace      : 19.6.5
@nx/devkit         : 19.6.5
@nx/eslint-plugin  : 19.6.5
@nx/plugin         : 19.6.5
@nx/react          : 19.6.5
@nrwl/tao          : 19.6.5
@nx/vite           : 19.6.5
@nx/web            : 19.6.5
typescript         : 5.5.4

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Metadata

Metadata

Assignees

Labels

priority: mediumMedium Priority (not high, not low priority)scope: linterIssues related to Eslint support in Nxtype: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions