@nx/eslint 19.0.6 → 19.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint",
3
- "version": "19.0.6",
3
+ "version": "19.0.8",
4
4
  "private": false,
5
5
  "description": "The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.",
6
6
  "repository": {
@@ -13,7 +13,8 @@
13
13
  "Web",
14
14
  "Lint",
15
15
  "ESLint",
16
- "CLI"
16
+ "CLI",
17
+ "Testing"
17
18
  ],
18
19
  "main": "./index",
19
20
  "typings": "./index.d.ts",
@@ -30,18 +31,19 @@
30
31
  "generators": "./generators.json",
31
32
  "executors": "./executors.json",
32
33
  "peerDependencies": {
33
- "js-yaml": "npm:@zkochan/js-yaml@0.0.7"
34
+ "@zkochan/js-yaml": "0.0.7"
34
35
  },
35
36
  "dependencies": {
36
- "@nx/devkit": "19.0.6",
37
- "@nx/js": "19.0.6",
38
- "eslint": "^8.0.0 || ^9.0.0",
37
+ "@nx/devkit": "19.0.8",
38
+ "@nx/js": "19.0.8",
39
+ "eslint": "^8.0.0",
40
+ "semver": "^7.5.3",
39
41
  "tslib": "^2.3.0",
40
42
  "typescript": "~5.4.2",
41
- "@nx/linter": "19.0.6"
43
+ "@nx/linter": "19.0.8"
42
44
  },
43
45
  "peerDependenciesMeta": {
44
- "js-yaml": {
46
+ "@zkochan/js-yaml": {
45
47
  "optional": true
46
48
  }
47
49
  },
@@ -6,7 +6,6 @@ const eslint_file_1 = require("../utils/eslint-file");
6
6
  const path_1 = require("path");
7
7
  const versions_1 = require("../../utils/versions");
8
8
  const json_converter_1 = require("./converters/json-converter");
9
- const js_yaml_1 = require("js-yaml");
10
9
  async function convertToFlatConfigGenerator(tree, options) {
11
10
  const eslintFile = (0, eslint_file_1.findEslintFile)(tree);
12
11
  if (!eslintFile) {
@@ -112,7 +111,8 @@ function convertConfigToFlatConfig(tree, root, source, target, ignorePath) {
112
111
  }
113
112
  if (source.endsWith('.yaml') || source.endsWith('.yml')) {
114
113
  const originalContent = tree.read(`${root}/${source}`, 'utf-8');
115
- const config = (0, js_yaml_1.load)(originalContent, {
114
+ const { load } = require('@zkochan/js-yaml');
115
+ const config = load(originalContent, {
116
116
  json: true,
117
117
  filename: source,
118
118
  });
@@ -7,6 +7,7 @@ const globs_1 = require("nx/src/utils/globs");
7
7
  const workspace_context_1 = require("nx/src/utils/workspace-context");
8
8
  const config_file_1 = require("../utils/config-file");
9
9
  const resolve_eslint_class_1 = require("../utils/resolve-eslint-class");
10
+ const semver_1 = require("semver");
10
11
  const DEFAULT_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'html', 'vue'];
11
12
  exports.createNodes = [
12
13
  (0, globs_1.combineGlobPatterns)([
@@ -41,6 +42,7 @@ exports.createNodes = [
41
42
  const dedupedProjectRoots = Array.from(new Set(projectFiles.map((f) => (0, node_path_1.dirname)(f)))).sort((a, b) => (a !== b && isSubDir(a, b) ? -1 : 1));
42
43
  const excludePatterns = dedupedProjectRoots.map((root) => `${root}/**/*`);
43
44
  const ESLint = await (0, resolve_eslint_class_1.resolveESLintClass)((0, config_file_1.isFlatConfig)(configFilePath));
45
+ const eslintVersion = ESLint.version;
44
46
  const childProjectRoots = new Set();
45
47
  await Promise.all(dedupedProjectRoots.map(async (childProjectRoot, index) => {
46
48
  // anything after is either a nested project or a sibling project, can be excluded
@@ -61,11 +63,11 @@ exports.createNodes = [
61
63
  }));
62
64
  const uniqueChildProjectRoots = Array.from(childProjectRoots);
63
65
  return {
64
- projects: getProjectsUsingESLintConfig(configFilePath, uniqueChildProjectRoots, options, context),
66
+ projects: getProjectsUsingESLintConfig(configFilePath, uniqueChildProjectRoots, eslintVersion, options, context),
65
67
  };
66
68
  },
67
69
  ];
68
- function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, options, context) {
70
+ function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, eslintVersion, options, context) {
69
71
  const projects = {};
70
72
  const rootEslintConfig = [
71
73
  config_file_1.baseEsLintConfigFile,
@@ -86,12 +88,12 @@ function getProjectsUsingESLintConfig(configFilePath, childProjectRoots, options
86
88
  eslintConfigs.unshift(rootEslintConfig);
87
89
  }
88
90
  projects[projectRoot] = {
89
- targets: buildEslintTargets(eslintConfigs, projectRoot, context.workspaceRoot, options, isStandaloneWorkspace),
91
+ targets: buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, context.workspaceRoot, options, isStandaloneWorkspace),
90
92
  };
91
93
  }
92
94
  return projects;
93
95
  }
94
- function buildEslintTargets(eslintConfigs, projectRoot, workspaceRoot, options, isStandaloneWorkspace = false) {
96
+ function buildEslintTargets(eslintConfigs, eslintVersion, projectRoot, workspaceRoot, options, isStandaloneWorkspace = false) {
95
97
  const isRootProject = projectRoot === '.';
96
98
  const targets = {};
97
99
  const targetConfig = {
@@ -115,9 +117,13 @@ function buildEslintTargets(eslintConfigs, projectRoot, workspaceRoot, options,
115
117
  };
116
118
  // Always set the environment variable to ensure that the ESLint CLI can run on eslint v8 and v9
117
119
  const useFlatConfig = eslintConfigs.some((config) => (0, config_file_1.isFlatConfig)(config));
118
- targetConfig.options.env = {
119
- ESLINT_USE_FLAT_CONFIG: useFlatConfig ? 'true' : 'false',
120
- };
120
+ // Flat config is default for 9.0.0+
121
+ const defaultSetting = (0, semver_1.gte)(eslintVersion, '9.0.0');
122
+ if (useFlatConfig !== defaultSetting) {
123
+ targetConfig.options.env = {
124
+ ESLINT_USE_FLAT_CONFIG: useFlatConfig ? 'true' : 'false',
125
+ };
126
+ }
121
127
  targets[options.targetName] = targetConfig;
122
128
  return targets;
123
129
  }