@ng-annotate/angular 0.2.1 → 0.2.2

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": "@ng-annotate/angular",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "schematics": "./schematics/collection.json",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3,6 +3,22 @@ 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 MIN_ANGULAR_MAJOR = 21;
7
+ function checkAngularVersion() {
8
+ return (tree) => {
9
+ const pkgPath = 'package.json';
10
+ if (!tree.exists(pkgPath))
11
+ return;
12
+ const pkg = JSON.parse(tree.read(pkgPath).toString('utf-8'));
13
+ const version = (pkg['dependencies']?.['@angular/core'] ?? pkg['devDependencies']?.['@angular/core']) || '';
14
+ const match = version.match(/(\d+)/);
15
+ const major = match ? parseInt(match[1], 10) : 0;
16
+ if (major > 0 && major < MIN_ANGULAR_MAJOR) {
17
+ throw new schematics_1.SchematicsException(`@ng-annotate/angular requires Angular ${MIN_ANGULAR_MAJOR} or higher. ` +
18
+ `Found: ${version}`);
19
+ }
20
+ };
21
+ }
6
22
  function addVitePlugin() {
7
23
  return (tree, context) => {
8
24
  const candidates = ['vite.config.ts', 'vite.config.js', 'vite.config.mts'];
@@ -89,6 +105,6 @@ function addDevDependency() {
89
105
  function default_1() {
90
106
  return (tree, context) => {
91
107
  context.logger.info('Setting up @ng-annotate/vite-plugin...');
92
- return (0, schematics_1.chain)([addDevDependency(), addVitePlugin(), addProviders(), addMcpConfig()])(tree, context);
108
+ return (0, schematics_1.chain)([checkAngularVersion(), addDevDependency(), addVitePlugin(), addProviders(), addMcpConfig()])(tree, context);
93
109
  };
94
110
  }
@@ -1,6 +1,31 @@
1
- import { Rule, SchematicContext, Tree, chain } from '@angular-devkit/schematics';
1
+ import { Rule, SchematicContext, Tree, chain, SchematicsException } from '@angular-devkit/schematics';
2
2
  import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
3
3
 
4
+ const MIN_ANGULAR_MAJOR = 21;
5
+
6
+ function checkAngularVersion(): Rule {
7
+ return (tree: Tree) => {
8
+ const pkgPath = 'package.json';
9
+ if (!tree.exists(pkgPath)) return;
10
+
11
+ const pkg = JSON.parse(tree.read(pkgPath)!.toString('utf-8')) as Record<
12
+ string,
13
+ Record<string, string>
14
+ >;
15
+ const version: string =
16
+ (pkg['dependencies']?.['@angular/core'] ?? pkg['devDependencies']?.['@angular/core']) || '';
17
+ const match = version.match(/(\d+)/);
18
+ const major = match ? parseInt(match[1], 10) : 0;
19
+
20
+ if (major > 0 && major < MIN_ANGULAR_MAJOR) {
21
+ throw new SchematicsException(
22
+ `@ng-annotate/angular requires Angular ${MIN_ANGULAR_MAJOR} or higher. ` +
23
+ `Found: ${version}`,
24
+ );
25
+ }
26
+ };
27
+ }
28
+
4
29
  function addVitePlugin(): Rule {
5
30
  return (tree: Tree, context: SchematicContext) => {
6
31
  const candidates = ['vite.config.ts', 'vite.config.js', 'vite.config.mts'];
@@ -119,7 +144,7 @@ function addDevDependency(): Rule {
119
144
  export default function (): Rule {
120
145
  return (tree: Tree, context: SchematicContext) => {
121
146
  context.logger.info('Setting up @ng-annotate/vite-plugin...');
122
- return chain([addDevDependency(), addVitePlugin(), addProviders(), addMcpConfig()])(
147
+ return chain([checkAngularVersion(), addDevDependency(), addVitePlugin(), addProviders(), addMcpConfig()])(
123
148
  tree,
124
149
  context,
125
150
  );