@angular-eslint/schematics 18.0.0-alpha.13 → 18.0.0-alpha.14

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.
@@ -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"}
@@ -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":"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,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"}
@@ -8,7 +8,8 @@ exports.default = (0, devkit_imports_1.convertNxGenerator)(async (tree, options)
8
8
  const { setParserOptionsProject, ...angularOptions } = options;
9
9
  const applicationGenerator = (0, devkit_imports_1.wrapAngularDevkitSchematic)('@schematics/angular', 'application');
10
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);
11
13
  // Update the lint builder and config in angular.json
12
14
  (0, utils_1.addESLintTargetToProject)(tree, options.name, 'lint');
13
- (0, utils_1.createESLintConfigForProject)(tree, options.name, options.setParserOptionsProject ?? false);
14
15
  });
@@ -1 +1 @@
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,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"}
@@ -8,7 +8,8 @@ exports.default = (0, devkit_imports_1.convertNxGenerator)(async (tree, options)
8
8
  const { setParserOptionsProject, ...angularOptions } = options;
9
9
  const libraryGenerator = (0, devkit_imports_1.wrapAngularDevkitSchematic)('@schematics/angular', 'library');
10
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);
11
13
  // Update the lint builder and config in angular.json
12
14
  (0, utils_1.addESLintTargetToProject)(tree, options.name, 'lint');
13
- (0, utils_1.createESLintConfigForProject)(tree, options.name, options.setParserOptionsProject ?? false);
14
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,CA2B/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,19 +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
- let useFlatConfig = true;
148
- const existingESLintVersion = json.devDependencies['eslint'];
149
- if (existingESLintVersion) {
150
- const v = semver_1.default.minVersion(existingESLintVersion);
151
- if (v) {
152
- useFlatConfig = semver_1.default.gte(v.raw, '9.0.0');
153
- }
154
- }
138
+ const useFlatConfig = (0, utils_1.shouldUseFlatConfig)(host, json);
155
139
  return (0, schematics_1.chain)([
156
140
  addAngularESLintPackages(json, useFlatConfig),
157
141
  applyESLintConfigIfSingleProjectWithNoExistingTSLint(useFlatConfig),
package/dist/utils.d.ts CHANGED
@@ -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;AAM/E,OAAO,KAAK,E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,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,7 +3,7 @@ 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
9
  const ignore_1 = __importDefault(require("ignore"));
@@ -324,35 +324,9 @@ function createESLintConfigForProject(tree, projectName, setParserOptionsProject
324
324
  const targets = existingProjectConfig.architect || existingProjectConfig.targets;
325
325
  const { root: projectRoot, projectType, prefix } = existingProjectConfig;
326
326
  const hasE2e = !!targets?.e2e;
327
- /**
328
- * In order to support both flat config and eslintrc we need to dynamically figure out
329
- * what the user should be using based on:
330
- * - their existing files
331
- * - their eslint version
332
- */
333
- let useFlatConfig = true;
327
+ const useFlatConfig = shouldUseFlatConfig(tree);
334
328
  const alreadyHasRootFlatConfig = tree.exists('eslint.config.js');
335
329
  const alreadyHasRootESLintRC = tree.exists('.eslintrc.json');
336
- if (alreadyHasRootFlatConfig) {
337
- useFlatConfig = true;
338
- }
339
- else if (alreadyHasRootESLintRC) {
340
- useFlatConfig = false;
341
- }
342
- else {
343
- // If no existing config file, check if they are using at least eslint 9 (when flat config became the default)
344
- let eslintVersion;
345
- try {
346
- eslintVersion = JSON.parse(tree.read('package.json', 'utf-8'))
347
- .devDependencies?.['eslint'];
348
- // eslint-disable-next-line no-empty
349
- }
350
- catch { }
351
- if (eslintVersion) {
352
- const v = semver_1.default.minVersion(eslintVersion);
353
- useFlatConfig = semver_1.default.gte(v.raw, '9.0.0');
354
- }
355
- }
356
330
  /**
357
331
  * If the root is an empty string it must be the initial project created at the
358
332
  * root by the Angular CLI's workspace schematic
@@ -431,3 +405,39 @@ function updateSchematicDefaults(angularJson, schematicFullName, defaultValues)
431
405
  return angularJson;
432
406
  }
433
407
  exports.updateSchematicDefaults = updateSchematicDefaults;
408
+ /**
409
+ * In order to support both flat config and eslintrc we need to dynamically figure out
410
+ * what the user should be using based on:
411
+ * - their existing files
412
+ * - their eslint version
413
+ */
414
+ function shouldUseFlatConfig(tree, existingJson) {
415
+ let useFlatConfig = true;
416
+ try {
417
+ const alreadyHasRootFlatConfig = tree.exists('eslint.config.js');
418
+ const alreadyHasRootESLintRC = tree.exists('.eslintrc.json');
419
+ if (alreadyHasRootFlatConfig) {
420
+ useFlatConfig = true;
421
+ }
422
+ else if (alreadyHasRootESLintRC) {
423
+ useFlatConfig = false;
424
+ }
425
+ else {
426
+ const json = existingJson ??
427
+ JSON.parse(tree.read('package.json').toString('utf-8'));
428
+ json.devDependencies = json.devDependencies || {};
429
+ const existingESLintVersion = json.devDependencies['eslint'];
430
+ if (existingESLintVersion) {
431
+ const v = semver_1.default.minVersion(existingESLintVersion);
432
+ if (v) {
433
+ useFlatConfig = semver_1.default.gte(v.raw, '9.0.0');
434
+ }
435
+ }
436
+ }
437
+ return useFlatConfig;
438
+ }
439
+ catch {
440
+ return useFlatConfig;
441
+ }
442
+ }
443
+ 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.13",
3
+ "version": "18.0.0-alpha.14",
4
4
  "description": "Angular Schematics for angular-eslint",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -34,17 +34,16 @@
34
34
  "save": false
35
35
  },
36
36
  "dependencies": {
37
- "@angular-eslint/eslint-plugin": "18.0.0-alpha.13",
38
- "@angular-eslint/eslint-plugin-template": "18.0.0-alpha.13",
37
+ "@angular-eslint/eslint-plugin": "18.0.0-alpha.14",
38
+ "@angular-eslint/eslint-plugin-template": "18.0.0-alpha.14",
39
39
  "@nx/devkit": "^19.0.6",
40
40
  "ignore": "5.3.1",
41
41
  "nx": "^19.0.6",
42
- "strip-json-comments": "3.1.1",
43
- "tmp": "0.2.3"
42
+ "semver": "7.6.2",
43
+ "strip-json-comments": "3.1.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/tmp": "0.2.6",
47
- "@typescript-eslint/utils": "8.0.0-alpha.17",
46
+ "@typescript-eslint/utils": "8.0.0-alpha.20",
48
47
  "eslint": "9.3.0"
49
48
  },
50
49
  "peerDependencies": {