@angular-eslint/schematics 22.1.1-alpha.13 → 22.1.1-alpha.15

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.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Shared helpers for reporting Angular major mismatches without using a
3
+ * package-manager peer on `@angular/cli`.
4
+ */
5
+ export declare const ANGULAR_PACKAGES_TO_CHECK: readonly ["@angular/core", "@angular/cli"];
6
+ export interface PackageJsonLike {
7
+ dependencies?: Record<string, string>;
8
+ devDependencies?: Record<string, string>;
9
+ peerDependencies?: Record<string, string>;
10
+ version?: string;
11
+ }
12
+ export interface AngularVersionMismatch {
13
+ packageName: string;
14
+ specifier: string;
15
+ foundMajor: number;
16
+ }
17
+ /**
18
+ * Best-effort major from a semver version or range (`^22.1.0`, `~21.2.0`,
19
+ * `>= 22.0.0 < 23.0.0`, `22.1.0`).
20
+ */
21
+ export declare function parseMajorVersion(specifier: string | undefined | null): number | null;
22
+ export declare function findDeclaredDependency(pkg: PackageJsonLike, name: string): string | undefined;
23
+ export declare function findAngularVersionMismatches(workspacePackageJson: PackageJsonLike, expectedMajor: number, installedMajors?: Partial<Record<string, number | null>>): AngularVersionMismatch[];
24
+ export declare function hasDetectableAngularVersion(workspacePackageJson: PackageJsonLike, installedMajors?: Partial<Record<string, number | null>>): boolean;
25
+ export declare function formatAngularVersionMismatchMessage(expectedMajor: number, mismatches: AngularVersionMismatch[]): string;
26
+ export declare function formatAngularVersionMatchMessage(expectedMajor: number): string;
27
+ //# sourceMappingURL=angular-version-compat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"angular-version-compat.d.ts","sourceRoot":"","sources":["../src/angular-version-compat.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,yBAAyB,4CAG5B,CAAC;AAEX,MAAM,WAAW,eAAe;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GACnC,MAAM,GAAG,IAAI,CAwBf;AAED,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,MAAM,GACX,MAAM,GAAG,SAAS,CAMpB;AAED,wBAAgB,4BAA4B,CAC1C,oBAAoB,EAAE,eAAe,EACrC,aAAa,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,GACvD,sBAAsB,EAAE,CAgB1B;AAED,wBAAgB,2BAA2B,CACzC,oBAAoB,EAAE,eAAe,EACrC,eAAe,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,GACvD,OAAO,CAWT;AAED,wBAAgB,mCAAmC,CACjD,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,sBAAsB,EAAE,GACnC,MAAM,CAcR;AAED,wBAAgB,gCAAgC,CAC9C,aAAa,EAAE,MAAM,GACpB,MAAM,CAER"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ /**
3
+ * Shared helpers for reporting Angular major mismatches without using a
4
+ * package-manager peer on `@angular/cli`.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ANGULAR_PACKAGES_TO_CHECK = void 0;
8
+ exports.parseMajorVersion = parseMajorVersion;
9
+ exports.findDeclaredDependency = findDeclaredDependency;
10
+ exports.findAngularVersionMismatches = findAngularVersionMismatches;
11
+ exports.hasDetectableAngularVersion = hasDetectableAngularVersion;
12
+ exports.formatAngularVersionMismatchMessage = formatAngularVersionMismatchMessage;
13
+ exports.formatAngularVersionMatchMessage = formatAngularVersionMatchMessage;
14
+ exports.ANGULAR_PACKAGES_TO_CHECK = [
15
+ '@angular/core',
16
+ '@angular/cli',
17
+ ];
18
+ /**
19
+ * Best-effort major from a semver version or range (`^22.1.0`, `~21.2.0`,
20
+ * `>= 22.0.0 < 23.0.0`, `22.1.0`).
21
+ */
22
+ function parseMajorVersion(specifier) {
23
+ if (!specifier) {
24
+ return null;
25
+ }
26
+ const trimmed = specifier.trim();
27
+ if (!trimmed ||
28
+ trimmed === '*' ||
29
+ trimmed === 'latest' ||
30
+ /^(workspace|catalog|file|link|portal|git|http|https):/i.test(trimmed)) {
31
+ return null;
32
+ }
33
+ const match = trimmed.match(/(\d+)/);
34
+ if (!match) {
35
+ return null;
36
+ }
37
+ const major = Number(match[1]);
38
+ // 0.x (including the e2e publish version `0.0.0-e2e`) is not an
39
+ // Angular-aligned major; treat it as undetectable rather than v0.
40
+ if (major === 0) {
41
+ return null;
42
+ }
43
+ return major;
44
+ }
45
+ function findDeclaredDependency(pkg, name) {
46
+ return (pkg.dependencies?.[name] ??
47
+ pkg.devDependencies?.[name] ??
48
+ pkg.peerDependencies?.[name]);
49
+ }
50
+ function findAngularVersionMismatches(workspacePackageJson, expectedMajor, installedMajors) {
51
+ const mismatches = [];
52
+ for (const name of exports.ANGULAR_PACKAGES_TO_CHECK) {
53
+ const declared = findDeclaredDependency(workspacePackageJson, name);
54
+ const installedMajor = installedMajors?.[name];
55
+ const major = installedMajor ?? parseMajorVersion(declared);
56
+ if (major == null || major === expectedMajor) {
57
+ continue;
58
+ }
59
+ mismatches.push({
60
+ packageName: name,
61
+ specifier: declared ?? `v${major}`,
62
+ foundMajor: major,
63
+ });
64
+ }
65
+ return mismatches;
66
+ }
67
+ function hasDetectableAngularVersion(workspacePackageJson, installedMajors) {
68
+ return exports.ANGULAR_PACKAGES_TO_CHECK.some((name) => {
69
+ const installed = installedMajors?.[name];
70
+ if (installed != null) {
71
+ return true;
72
+ }
73
+ return (parseMajorVersion(findDeclaredDependency(workspacePackageJson, name)) !==
74
+ null);
75
+ });
76
+ }
77
+ function formatAngularVersionMismatchMessage(expectedMajor, mismatches) {
78
+ const details = mismatches
79
+ .map((mismatch) => ` - ${mismatch.packageName}@${mismatch.specifier} (v${mismatch.foundMajor})`)
80
+ .join('\n');
81
+ return `
82
+ angular-eslint v${expectedMajor} is intended for Angular v${expectedMajor}.
83
+ This workspace is using a different Angular major:
84
+ ${details}
85
+
86
+ See https://github.com/angular-eslint/angular-eslint/blob/main/docs/ANGULAR_VERSION_SUPPORT.md
87
+ `.trim();
88
+ }
89
+ function formatAngularVersionMatchMessage(expectedMajor) {
90
+ return `angular-eslint v${expectedMajor} matches this workspace's Angular v${expectedMajor}.`;
91
+ }
@@ -1,9 +1,4 @@
1
1
  import type { Rule } from '@angular-devkit/schematics';
2
2
  import type { Schema } from './schema';
3
- /**
4
- * Entry point for the ng-add schematic.
5
- *
6
- * @param options Configuration options passed to the schematic.
7
- */
8
3
  export default function (options: Schema): Rule;
9
4
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAG/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAkLvC;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,MAAM,GAAG,IAAI,CAY9C"}
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;AAG/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAsNvC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,MAAM,GAAG,IAAI,CAc9C"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = default_1;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
5
  const tasks_1 = require("@angular-devkit/schematics/tasks");
6
+ const angular_version_compat_1 = require("../angular-version-compat");
6
7
  const utils_1 = require("../utils");
7
8
  const packageJSON = require('../../package.json');
8
9
  function addAngularESLintPackages(json, options) {
@@ -140,10 +141,25 @@ Please see https://github.com/angular-eslint/angular-eslint for more information
140
141
  *
141
142
  * @param options Configuration options passed to the schematic.
142
143
  */
144
+ function reportAngularVersionCompatibility(workspacePackageJson, context) {
145
+ const expectedMajor = (0, angular_version_compat_1.parseMajorVersion)(packageJSON.version);
146
+ if (expectedMajor == null) {
147
+ return;
148
+ }
149
+ const mismatches = (0, angular_version_compat_1.findAngularVersionMismatches)(workspacePackageJson, expectedMajor);
150
+ if (mismatches.length > 0) {
151
+ context.logger.warn((0, angular_version_compat_1.formatAngularVersionMismatchMessage)(expectedMajor, mismatches));
152
+ return;
153
+ }
154
+ if ((0, angular_version_compat_1.hasDetectableAngularVersion)(workspacePackageJson)) {
155
+ context.logger.info((0, angular_version_compat_1.formatAngularVersionMatchMessage)(expectedMajor));
156
+ }
157
+ }
143
158
  function default_1(options) {
144
159
  return (host, context) => {
145
160
  const workspacePackageJSON = host.read('package.json').toString('utf-8');
146
161
  const json = JSON.parse(workspacePackageJSON);
162
+ reportAngularVersionCompatibility(json, context);
147
163
  return (0, schematics_1.chain)([
148
164
  addAngularESLintPackages(json, options),
149
165
  applyESLintConfigIfSingleProjectWithNoExistingTSLint(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/schematics",
3
- "version": "22.1.1-alpha.13",
3
+ "version": "22.1.1-alpha.15",
4
4
  "description": "Angular Schematics for angular-eslint",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -36,17 +36,14 @@
36
36
  "ng-add": {
37
37
  "save": "devDependencies"
38
38
  },
39
- "peerDependencies": {
40
- "@angular/cli": ">= 22.0.0 < 23.0.0"
41
- },
42
39
  "dependencies": {
43
40
  "@angular-devkit/core": ">= 22.0.0 < 23.0.0",
44
41
  "@angular-devkit/schematics": ">= 22.0.0 < 23.0.0",
45
42
  "ignore": "7.0.6",
46
43
  "semver": "7.8.5",
47
44
  "strip-json-comments": "3.1.1",
48
- "@angular-eslint/eslint-plugin": "22.1.1-alpha.13",
49
- "@angular-eslint/eslint-plugin-template": "22.1.1-alpha.13"
45
+ "@angular-eslint/eslint-plugin": "22.1.1-alpha.15",
46
+ "@angular-eslint/eslint-plugin-template": "22.1.1-alpha.15"
50
47
  },
51
48
  "devDependencies": {
52
49
  "@eslint/js": "10.0.1",