@angular-eslint/schematics 18.0.0-alpha.9 → 18.0.1-alpha.0

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/README.md CHANGED
@@ -1 +1,5 @@
1
1
  # @angular-eslint/schematics
2
+
3
+ Please see https://github.com/angular-eslint/angular-eslint for full usage instructions and guidance.
4
+
5
+ The `@angular-eslint/schematics` package is a set of custom Angular CLI Schematics which are used to add and update dependencies and configuration files which are relevant for running ESLint on an Angular workspace.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/add-eslint-to-project/index.ts"],"names":[],"mappings":"AAQA,UAAU,MAAM;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;;AAED,wBAqBG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/add-eslint-to-project/index.ts"],"names":[],"mappings":"AAQA,UAAU,MAAM;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;;AAED,wBAsBG"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const devkit_1 = require("@nx/devkit");
3
+ const devkit_imports_1 = require("../devkit-imports");
4
4
  const utils_1 = require("../utils");
5
- exports.default = (0, devkit_1.convertNxGenerator)(async (tree, options) => {
5
+ exports.default = (0, devkit_imports_1.convertNxGenerator)(async (tree, options) => {
6
6
  const projectName = (0, utils_1.determineTargetProjectName)(tree, options.project);
7
7
  if (!projectName) {
8
8
  throw new Error('\n' +
@@ -12,7 +12,8 @@ Error: You must specify a project to add ESLint to because you have multiple pro
12
12
  E.g. npx ng g @angular-eslint/schematics:add-eslint-to-project {{YOUR_PROJECT_NAME_GOES_HERE}}
13
13
  `.trim());
14
14
  }
15
+ // Create the config file first so that we can check for its existence when setting the target
16
+ (0, utils_1.createESLintConfigForProject)(tree, projectName, options.setParserOptionsProject ?? false);
15
17
  // Update the lint builder and config in angular.json
16
18
  (0, utils_1.addESLintTargetToProject)(tree, projectName, 'lint');
17
- (0, utils_1.createESLintConfigForProject)(tree, projectName, options.setParserOptionsProject ?? false);
18
19
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/application/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAMtF,UAAU,MAAO,SAAQ,aAAa;IACpC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;;AAED,wBAoBG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/application/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAWtF,UAAU,MAAO,SAAQ,aAAa;IACpC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;;AAED,wBAqBG"}
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const devkit_1 = require("@nx/devkit");
4
- const ngcli_adapter_1 = require("@nx/devkit/ngcli-adapter");
3
+ const devkit_imports_1 = require("../devkit-imports");
5
4
  const utils_1 = require("../utils");
6
- exports.default = (0, devkit_1.convertNxGenerator)(async (tree, options) => {
5
+ exports.default = (0, devkit_imports_1.convertNxGenerator)(async (tree, options) => {
7
6
  // Remove angular-eslint specific options before passing to the Angular schematic
8
7
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
8
  const { setParserOptionsProject, ...angularOptions } = options;
10
- const applicationGenerator = (0, ngcli_adapter_1.wrapAngularDevkitSchematic)('@schematics/angular', 'application');
9
+ const applicationGenerator = (0, devkit_imports_1.wrapAngularDevkitSchematic)('@schematics/angular', 'application');
11
10
  await applicationGenerator(tree, angularOptions);
11
+ // Create the config file first so that we can check for its existence when setting the target
12
+ (0, utils_1.createESLintConfigForProject)(tree, options.name, options.setParserOptionsProject ?? false);
12
13
  // Update the lint builder and config in angular.json
13
14
  (0, utils_1.addESLintTargetToProject)(tree, options.name, 'lint');
14
- (0, utils_1.createESLintConfigForProject)(tree, options.name, options.setParserOptionsProject ?? false);
15
15
  });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * In order to prevent the project graph cache from showing up at the root of the user's
3
+ * workspace, we set a custom cache directory before importing anything from `@nx/devkit`.
4
+ *
5
+ * `no-restricted-imports` eslint rule has been configured for this project to prevent
6
+ * accidental imports in other files. All imports should come from here to ensure consistency.
7
+ */
8
+ export { convertNxGenerator, offsetFromRoot, readJson, writeJson, } from '@nx/devkit';
9
+ export type { ProjectConfiguration, Tree } from '@nx/devkit';
10
+ export { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter';
11
+ //# sourceMappingURL=devkit-imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devkit-imports.d.ts","sourceRoot":"","sources":["../src/devkit-imports.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,SAAS,GACV,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,oBAAoB,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * In order to prevent the project graph cache from showing up at the root of the user's
4
+ * workspace, we set a custom cache directory before importing anything from `@nx/devkit`.
5
+ *
6
+ * `no-restricted-imports` eslint rule has been configured for this project to prevent
7
+ * accidental imports in other files. All imports should come from here to ensure consistency.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.wrapAngularDevkitSchematic = exports.writeJson = exports.readJson = exports.offsetFromRoot = exports.convertNxGenerator = void 0;
11
+ const node_path_1 = require("node:path");
12
+ process.env.NX_PROJECT_GRAPH_CACHE_DIRECTORY = (0, node_path_1.join)(__dirname, '..', '.nx-cache');
13
+ /* eslint-disable no-restricted-imports */
14
+ var devkit_1 = require("@nx/devkit");
15
+ Object.defineProperty(exports, "convertNxGenerator", { enumerable: true, get: function () { return devkit_1.convertNxGenerator; } });
16
+ Object.defineProperty(exports, "offsetFromRoot", { enumerable: true, get: function () { return devkit_1.offsetFromRoot; } });
17
+ Object.defineProperty(exports, "readJson", { enumerable: true, get: function () { return devkit_1.readJson; } });
18
+ Object.defineProperty(exports, "writeJson", { enumerable: true, get: function () { return devkit_1.writeJson; } });
19
+ var ngcli_adapter_1 = require("@nx/devkit/ngcli-adapter");
20
+ Object.defineProperty(exports, "wrapAngularDevkitSchematic", { enumerable: true, get: function () { return ngcli_adapter_1.wrapAngularDevkitSchematic; } });
21
+ /* eslint-enable no-restricted-imports */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/library/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAMlF,UAAU,MAAO,SAAQ,aAAa;IACpC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;;AAED,wBAoBG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/library/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAWlF,UAAU,MAAO,SAAQ,aAAa;IACpC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;;AAED,wBAqBG"}
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const devkit_1 = require("@nx/devkit");
4
- const ngcli_adapter_1 = require("@nx/devkit/ngcli-adapter");
3
+ const devkit_imports_1 = require("../devkit-imports");
5
4
  const utils_1 = require("../utils");
6
- exports.default = (0, devkit_1.convertNxGenerator)(async (tree, options) => {
5
+ exports.default = (0, devkit_imports_1.convertNxGenerator)(async (tree, options) => {
7
6
  // Remove angular-eslint specific options before passing to the Angular schematic
8
7
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
8
  const { setParserOptionsProject, ...angularOptions } = options;
10
- const libraryGenerator = (0, ngcli_adapter_1.wrapAngularDevkitSchematic)('@schematics/angular', 'library');
9
+ const libraryGenerator = (0, devkit_imports_1.wrapAngularDevkitSchematic)('@schematics/angular', 'library');
11
10
  await libraryGenerator(tree, angularOptions);
11
+ // Create the config file first so that we can check for its existence when setting the target
12
+ (0, utils_1.createESLintConfigForProject)(tree, options.name, options.setParserOptionsProject ?? false);
12
13
  // Update the lint builder and config in angular.json
13
14
  (0, utils_1.addESLintTargetToProject)(tree, options.name, 'lint');
14
- (0, utils_1.createESLintConfigForProject)(tree, options.name, options.setParserOptionsProject ?? false);
15
15
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAc/E,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAChD,eAAO,MAAM,kCAAkC,WAAW,CAAC;AA+K3D,MAAM,CAAC,OAAO,cAAc,IAAI,CAuB/B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ng-add/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAA0B,MAAM,4BAA4B,CAAC;AAc/E,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAChD,eAAO,MAAM,kCAAkC,WAAW,CAAC;AA+K3D,MAAM,CAAC,OAAO,cAAc,IAAI,CAa/B"}
@@ -1,12 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.FIXED_TYPESCRIPT_ESLINT_V7_VERSION = exports.FIXED_ESLINT_V8_VERSION = void 0;
7
4
  const schematics_1 = require("@angular-devkit/schematics");
8
5
  const tasks_1 = require("@angular-devkit/schematics/tasks");
9
- const semver_1 = __importDefault(require("semver"));
10
6
  const utils_1 = require("../utils");
11
7
  exports.FIXED_ESLINT_V8_VERSION = '8.57.0';
12
8
  exports.FIXED_TYPESCRIPT_ESLINT_V7_VERSION = '7.11.0';
@@ -139,13 +135,7 @@ function default_1() {
139
135
  return (host, context) => {
140
136
  const workspacePackageJSON = host.read('package.json').toString('utf-8');
141
137
  const json = JSON.parse(workspacePackageJSON);
142
- /**
143
- * Until eslint v9, typescript-eslint v8 and flat config stabilize completely, allow the user to set a previous version of eslint
144
- * as a signal for what kind of config and dependencies to set up.
145
- */
146
- json.devDependencies = json.devDependencies || {};
147
- const existingESLintVersion = json.devDependencies['eslint'];
148
- const useFlatConfig = !(existingESLintVersion && semver_1.default.major(existingESLintVersion) < 9);
138
+ const useFlatConfig = (0, utils_1.shouldUseFlatConfig)(host, json);
149
139
  return (0, schematics_1.chain)([
150
140
  addAngularESLintPackages(json, useFlatConfig),
151
141
  applyESLintConfigIfSingleProjectWithNoExistingTSLint(useFlatConfig),
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Path } from '@angular-devkit/core';
2
2
  import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
3
- import type { Tree as NxTree } from '@nx/devkit';
3
+ import type { Tree as NxTree } from './devkit-imports';
4
4
  /**
5
5
  * This method is specifically for reading JSON files in a Tree
6
6
  * @param host The host tree
@@ -66,5 +66,12 @@ export declare function determineTargetProjectName(tree: NxTree, maybeProject?:
66
66
  */
67
67
  export declare function updateSchematicCollections(angularJson: Record<string, any>): Record<string, any>;
68
68
  export declare function updateSchematicDefaults(angularJson: Record<string, any>, schematicFullName: string, defaultValues: Record<string, unknown>): Record<string, any>;
69
+ /**
70
+ * In order to support both flat config and eslintrc we need to dynamically figure out
71
+ * what the user should be using based on:
72
+ * - their existing files
73
+ * - their eslint version
74
+ */
75
+ export declare function shouldUseFlatConfig(tree: NxTree | Tree, existingJson?: Record<string, unknown>): boolean;
69
76
  export {};
70
77
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAE/E,OAAO,KAAK,EAAE,IAAI,IAAI,MAAM,EAAwB,MAAM,YAAY,CAAC;AASvE;;;;;GAKG;AAEH,wBAAgB,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAcnE;AAED;;;;;GAKG;AAEH,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAC7C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,gBAAgB,KAAK,CAAC,GAClD,IAAI,CAYN;AAED,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAE3E,wBAAgB,2BAA2B,CACzC,aAAa,EAAE;IAAE,SAAS,CAAC,EAAE,aAAa,CAAA;CAAE,GAAG;IAAE,OAAO,CAAC,EAAE,aAAa,CAAA;CAAE,GACzE,aAAa,GAAG,IAAI,CAYtB;AAqBD,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,WAAW,E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4B,CAC1C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,uBAAuB,EAAE,OAAO,QAsDjC;AAgBD,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,GAAG,IAAI,CAUf;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,uBAS1E;AAED,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,iBAAiB,EAAE,MAAM,EACzB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,uBAUvC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,OAAO,CA4BT"}
package/dist/utils.js CHANGED
@@ -3,13 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.updateSchematicDefaults = exports.updateSchematicCollections = exports.determineTargetProjectName = exports.sortObjectByKeys = exports.createESLintConfigForProject = exports.createStringifiedRootESLintConfig = exports.createRootESLintConfig = exports.visitNotIgnoredFiles = exports.addESLintTargetToProject = exports.getTargetsConfigFromProject = exports.updateJsonInTree = exports.readJsonInTree = void 0;
6
+ exports.shouldUseFlatConfig = exports.updateSchematicDefaults = exports.updateSchematicCollections = exports.determineTargetProjectName = exports.sortObjectByKeys = exports.createESLintConfigForProject = exports.createStringifiedRootESLintConfig = exports.createRootESLintConfig = exports.visitNotIgnoredFiles = exports.addESLintTargetToProject = exports.getTargetsConfigFromProject = exports.updateJsonInTree = exports.readJsonInTree = void 0;
7
7
  const core_1 = require("@angular-devkit/core");
8
8
  const schematics_1 = require("@angular-devkit/schematics");
9
- const devkit_1 = require("@nx/devkit");
10
9
  const ignore_1 = __importDefault(require("ignore"));
11
10
  const semver_1 = __importDefault(require("semver"));
12
11
  const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
12
+ const devkit_imports_1 = require("./devkit-imports");
13
13
  const DEFAULT_PREFIX = 'app';
14
14
  /**
15
15
  * This method is specifically for reading JSON files in a Tree
@@ -67,13 +67,13 @@ function serializeJson(json) {
67
67
  return `${JSON.stringify(json, null, 2)}\n`;
68
68
  }
69
69
  function readProjectConfiguration(tree, projectName) {
70
- const angularJSON = (0, devkit_1.readJson)(tree, 'angular.json');
70
+ const angularJSON = (0, devkit_imports_1.readJson)(tree, 'angular.json');
71
71
  return angularJSON.projects[projectName];
72
72
  }
73
73
  function updateProjectConfiguration(tree, projectName, projectConfig) {
74
- const angularJSON = (0, devkit_1.readJson)(tree, 'angular.json');
74
+ const angularJSON = (0, devkit_imports_1.readJson)(tree, 'angular.json');
75
75
  angularJSON.projects[projectName] = projectConfig;
76
- (0, devkit_1.writeJson)(tree, 'angular.json', angularJSON);
76
+ (0, devkit_imports_1.writeJson)(tree, 'angular.json', angularJSON);
77
77
  }
78
78
  function addESLintTargetToProject(tree, projectName, targetName) {
79
79
  const existingProjectConfig = readProjectConfiguration(tree, projectName);
@@ -94,6 +94,14 @@ function addESLintTargetToProject(tree, projectName, targetName) {
94
94
  ],
95
95
  },
96
96
  };
97
+ let eslintConfig;
98
+ if (existingProjectConfig.root !== '') {
99
+ const flatConfigPath = (0, core_1.join)(existingProjectConfig.root, 'eslint.config.js');
100
+ if (tree.exists(flatConfigPath)) {
101
+ eslintConfig = flatConfigPath;
102
+ }
103
+ }
104
+ eslintTargetConfig.options.eslintConfig = eslintConfig;
97
105
  existingProjectConfig.architect = existingProjectConfig.architect || {};
98
106
  existingProjectConfig.architect[targetName] = eslintTargetConfig;
99
107
  updateProjectConfiguration(tree, projectName, existingProjectConfig);
@@ -192,22 +200,6 @@ function createRootESLintConfig(prefix) {
192
200
  exports.createRootESLintConfig = createRootESLintConfig;
193
201
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
194
202
  function createStringifiedRootESLintConfig(prefix) {
195
- let codeRules;
196
- if (prefix) {
197
- codeRules = {
198
- '@angular-eslint/directive-selector': [
199
- 'error',
200
- { type: 'attribute', prefix, style: 'camelCase' },
201
- ],
202
- '@angular-eslint/component-selector': [
203
- 'error',
204
- { type: 'element', prefix, style: 'kebab-case' },
205
- ],
206
- };
207
- }
208
- else {
209
- codeRules = {};
210
- }
211
203
  return `// @ts-check
212
204
  const eslint = require("@eslint/js");
213
205
  const tseslint = require("typescript-eslint");
@@ -223,7 +215,26 @@ module.exports = tseslint.config(
223
215
  ...angular.configs.tsRecommended,
224
216
  ],
225
217
  processor: angular.processInlineTemplates,
226
- rules: ${JSON.stringify(codeRules, null, 2)},
218
+ rules: ${prefix
219
+ ? `{
220
+ "@angular-eslint/directive-selector": [
221
+ "error",
222
+ {
223
+ type: "attribute",
224
+ prefix: "${prefix}",
225
+ style: "camelCase",
226
+ },
227
+ ],
228
+ "@angular-eslint/component-selector": [
229
+ "error",
230
+ {
231
+ type: "element",
232
+ prefix: "${prefix}",
233
+ style: "kebab-case",
234
+ },
235
+ ],
236
+ }`
237
+ : '{}'},
227
238
  },
228
239
  {
229
240
  files: ["**/*.html"],
@@ -239,7 +250,7 @@ module.exports = tseslint.config(
239
250
  exports.createStringifiedRootESLintConfig = createStringifiedRootESLintConfig;
240
251
  function createProjectESLintConfig(projectRoot, projectType, prefix, setParserOptionsProject, hasE2e) {
241
252
  return {
242
- extends: `${(0, devkit_1.offsetFromRoot)(projectRoot)}.eslintrc.json`,
253
+ extends: `${(0, devkit_imports_1.offsetFromRoot)(projectRoot)}.eslintrc.json`,
243
254
  ignorePatterns: ['!**/*'],
244
255
  overrides: [
245
256
  {
@@ -272,7 +283,7 @@ function createProjectESLintConfig(projectRoot, projectType, prefix, setParserOp
272
283
  function createStringifiedProjectESLintConfig(projectRoot, projectType, prefix, setParserOptionsProject, hasE2e) {
273
284
  return `// @ts-check
274
285
  const tseslint = require("typescript-eslint");
275
- const rootConfig = require("${(0, devkit_1.offsetFromRoot)(projectRoot)}eslint.config.js");
286
+ const rootConfig = require("${(0, devkit_imports_1.offsetFromRoot)(projectRoot)}eslint.config.js");
276
287
 
277
288
  module.exports = tseslint.config(
278
289
  ...rootConfig,
@@ -316,35 +327,9 @@ function createESLintConfigForProject(tree, projectName, setParserOptionsProject
316
327
  const targets = existingProjectConfig.architect || existingProjectConfig.targets;
317
328
  const { root: projectRoot, projectType, prefix } = existingProjectConfig;
318
329
  const hasE2e = !!targets?.e2e;
319
- /**
320
- * In order to support both flat config and eslintrc we need to dynamically figure out
321
- * what the user should be using based on:
322
- * - their existing files
323
- * - their eslint version
324
- */
325
- let useFlatConfig = true;
330
+ const useFlatConfig = shouldUseFlatConfig(tree);
326
331
  const alreadyHasRootFlatConfig = tree.exists('eslint.config.js');
327
332
  const alreadyHasRootESLintRC = tree.exists('.eslintrc.json');
328
- if (alreadyHasRootFlatConfig) {
329
- useFlatConfig = true;
330
- }
331
- else if (alreadyHasRootESLintRC) {
332
- useFlatConfig = false;
333
- }
334
- else {
335
- // If no existing config file, check if they are using at least eslint 9 (when flat config became the default)
336
- let eslintVersion;
337
- try {
338
- eslintVersion = JSON.parse(tree.read('package.json', 'utf-8'))
339
- .devDependencies?.['eslint'];
340
- // eslint-disable-next-line no-empty
341
- }
342
- catch { }
343
- if (eslintVersion) {
344
- const v = semver_1.default.minVersion(eslintVersion);
345
- useFlatConfig = semver_1.default.gte(v.raw, '9.0.0');
346
- }
347
- }
348
333
  /**
349
334
  * If the root is an empty string it must be the initial project created at the
350
335
  * root by the Angular CLI's workspace schematic
@@ -360,7 +345,7 @@ function createESLintConfigForProject(tree, projectName, setParserOptionsProject
360
345
  tree.write((0, core_1.join)((0, core_1.normalize)(projectRoot), 'eslint.config.js'), createStringifiedProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e));
361
346
  }
362
347
  else {
363
- (0, devkit_1.writeJson)(tree, (0, core_1.join)((0, core_1.normalize)(projectRoot), '.eslintrc.json'), createProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e));
348
+ (0, devkit_imports_1.writeJson)(tree, (0, core_1.join)((0, core_1.normalize)(projectRoot), '.eslintrc.json'), createProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e));
364
349
  }
365
350
  }
366
351
  exports.createESLintConfigForProject = createESLintConfigForProject;
@@ -368,7 +353,7 @@ function createRootESLintConfigFile(tree, prefix, useFlatConfig) {
368
353
  if (useFlatConfig) {
369
354
  return tree.write('eslint.config.js', createStringifiedRootESLintConfig(prefix));
370
355
  }
371
- return (0, devkit_1.writeJson)(tree, '.eslintrc.json', createRootESLintConfig(prefix));
356
+ return (0, devkit_imports_1.writeJson)(tree, '.eslintrc.json', createRootESLintConfig(prefix));
372
357
  }
373
358
  function sortObjectByKeys(obj) {
374
359
  return Object.keys(obj)
@@ -389,7 +374,7 @@ function determineTargetProjectName(tree, maybeProject) {
389
374
  if (maybeProject) {
390
375
  return maybeProject;
391
376
  }
392
- const workspaceJson = (0, devkit_1.readJson)(tree, 'angular.json');
377
+ const workspaceJson = (0, devkit_imports_1.readJson)(tree, 'angular.json');
393
378
  const projects = Object.keys(workspaceJson.projects);
394
379
  if (projects.length === 1) {
395
380
  return projects[0];
@@ -423,3 +408,39 @@ function updateSchematicDefaults(angularJson, schematicFullName, defaultValues)
423
408
  return angularJson;
424
409
  }
425
410
  exports.updateSchematicDefaults = updateSchematicDefaults;
411
+ /**
412
+ * In order to support both flat config and eslintrc we need to dynamically figure out
413
+ * what the user should be using based on:
414
+ * - their existing files
415
+ * - their eslint version
416
+ */
417
+ function shouldUseFlatConfig(tree, existingJson) {
418
+ let useFlatConfig = true;
419
+ try {
420
+ const alreadyHasRootFlatConfig = tree.exists('eslint.config.js');
421
+ const alreadyHasRootESLintRC = tree.exists('.eslintrc.json');
422
+ if (alreadyHasRootFlatConfig) {
423
+ useFlatConfig = true;
424
+ }
425
+ else if (alreadyHasRootESLintRC) {
426
+ useFlatConfig = false;
427
+ }
428
+ else {
429
+ const json = existingJson ??
430
+ JSON.parse(tree.read('package.json').toString('utf-8'));
431
+ json.devDependencies = json.devDependencies || {};
432
+ const existingESLintVersion = json.devDependencies['eslint'];
433
+ if (existingESLintVersion) {
434
+ const v = semver_1.default.minVersion(existingESLintVersion);
435
+ if (v) {
436
+ useFlatConfig = semver_1.default.gte(v.raw, '9.0.0');
437
+ }
438
+ }
439
+ }
440
+ return useFlatConfig;
441
+ }
442
+ catch {
443
+ return useFlatConfig;
444
+ }
445
+ }
446
+ exports.shouldUseFlatConfig = shouldUseFlatConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/schematics",
3
- "version": "18.0.0-alpha.9",
3
+ "version": "18.0.1-alpha.0",
4
4
  "description": "Angular Schematics for angular-eslint",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -27,28 +27,30 @@
27
27
  "@angular-eslint/eslint-plugin",
28
28
  "@angular-eslint/eslint-plugin-template",
29
29
  "@angular-eslint/template-parser",
30
- "@angular-eslint/utils"
30
+ "@angular-eslint/test-utils",
31
+ "@angular-eslint/utils",
32
+ "angular-eslint"
31
33
  ]
32
34
  },
33
35
  "ng-add": {
34
- "save": false
36
+ "save": "devDependencies"
35
37
  },
36
38
  "dependencies": {
37
- "@angular-eslint/eslint-plugin": "18.0.0-alpha.9",
38
- "@angular-eslint/eslint-plugin-template": "18.0.0-alpha.9",
39
+ "@angular-eslint/eslint-plugin": "18.0.1-alpha.0",
40
+ "@angular-eslint/eslint-plugin-template": "18.0.1-alpha.0",
39
41
  "@nx/devkit": "^19.0.6",
40
42
  "ignore": "5.3.1",
41
43
  "nx": "^19.0.6",
42
- "strip-json-comments": "3.1.1",
43
- "tmp": "0.2.3"
44
+ "semver": "7.6.2",
45
+ "strip-json-comments": "3.1.1"
44
46
  },
45
47
  "devDependencies": {
46
- "@types/tmp": "0.2.6",
47
- "@typescript-eslint/utils": "8.0.0-alpha.17",
48
+ "@typescript-eslint/utils": "8.0.0-alpha.20",
48
49
  "eslint": "9.3.0"
49
50
  },
50
51
  "peerDependencies": {
51
- "@angular/cli": ">= 18.0.0 < 19.0.0"
52
+ "@angular-devkit/core": ">= 18.0.0 < 19.0.0",
53
+ "@angular-devkit/schematics": ">= 18.0.0 < 19.0.0"
52
54
  },
53
55
  "gitHead": "e2006e5e9c99e5a943d1a999e0efa5247d29ec24"
54
56
  }