@igniteui/angular-templates 18.1.1400-beta.2 → 18.1.1400-beta.3

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,15 +1,16 @@
1
+ import * as ts from 'typescript';
1
2
  import { KeyValuePair, FormatSettings, PropertyAssignment, TemplateDependency, TypeScriptFileUpdate, RouteEntry } from '@igniteui/cli-core';
2
3
  import { AngularRouteLike } from './types';
3
4
  export declare class AngularTypeScriptFileUpdate extends TypeScriptFileUpdate {
4
- protected filePath: string;
5
- private standalone;
5
+ readonly filePath: string;
6
+ readonly standalone: boolean;
6
7
  protected formatSettings?: FormatSettings;
7
8
  /**
8
9
  * Creates a new AngularTypeScriptFileUpdate instance for the given file.
9
10
  * @param standalone Whether the file is a standalone component.
10
11
  * @param formatSettings Custom formatting settings to apply.
11
12
  */
12
- constructor(filePath: string, standalone?: boolean, formatSettings?: FormatSettings);
13
+ constructor(filePath: string, standalone?: boolean, formatSettings?: FormatSettings, compilerOptions?: ts.CompilerOptions);
13
14
  /**
14
15
  * Adds a route entry to the Angular routing module's routes variable instance.
15
16
  * @param route The route to add.
@@ -34,6 +35,13 @@ export declare class AngularTypeScriptFileUpdate extends TypeScriptFileUpdate {
34
35
  * @param multiline Whether to format the new entry as multiline.
35
36
  */
36
37
  addNgModuleMeta(dep: TemplateDependency, variables?: KeyValuePair<string>, multiline?: boolean): void;
38
+ /**
39
+ * Adds metadata to the arguments provided in `TestBed.configureTestingModule`.
40
+ * @param dep The dependency to add to the testing module's metadata.
41
+ * @param variables Variables to replace in the dependency strings.
42
+ * @param multiline Whether to format the new entry as multiline.
43
+ */
44
+ addTestingModuleMeta(dep: TemplateDependency, variables?: KeyValuePair<string>, multiline?: boolean): void;
37
45
  /**
38
46
  * Includes `{ bindToComponentInputs: true }` for a `forRoot` call in an `NgModule`'s `imports` member.
39
47
  *
@@ -67,6 +75,15 @@ export declare class AngularTypeScriptFileUpdate extends TypeScriptFileUpdate {
67
75
  * @param multiline Whether to format the new entry as multiline.
68
76
  */
69
77
  private mutateNgDecoratorMeta;
78
+ /**
79
+ * Updates Angular's metadata related to NgModules, Standalone Components or TestingModules.
80
+ * @param target The name of the target metadata property to update.
81
+ * @param targetMetaProp The property that is to be updated.
82
+ * @param identifiers The identifiers to add.
83
+ * @param visitorCondition The condition to find the object literal that contains the target property.
84
+ * @param multiline Whether to format the new entry as multiline.
85
+ */
86
+ private mutateNgMeta;
70
87
  /**
71
88
  * Checks if a node has an ancestor with a specific decorator.
72
89
  * @param name The name of the decorator.
@@ -80,4 +97,11 @@ export declare class AngularTypeScriptFileUpdate extends TypeScriptFileUpdate {
80
97
  * @param node The node to start checking from.
81
98
  */
82
99
  private findNgDecoratorProperty;
100
+ /**
101
+ * Calls `forRoot` on a module identifier.
102
+ * @param dep The dependency to add to the module's metadata.
103
+ * @param copy The copy of the module's metadata.
104
+ * @param args The arguments to pass to the `forRoot` call.
105
+ */
106
+ private addRootToModule;
83
107
  }
@@ -10,8 +10,8 @@ class AngularTypeScriptFileUpdate extends cli_core_1.TypeScriptFileUpdate {
10
10
  * @param standalone Whether the file is a standalone component.
11
11
  * @param formatSettings Custom formatting settings to apply.
12
12
  */
13
- constructor(filePath, standalone = false, formatSettings) {
14
- super(filePath, formatSettings);
13
+ constructor(filePath, standalone = false, formatSettings, compilerOptions) {
14
+ super(filePath, formatSettings, compilerOptions);
15
15
  this.filePath = filePath;
16
16
  this.standalone = standalone;
17
17
  this.formatSettings = formatSettings;
@@ -74,12 +74,48 @@ class AngularTypeScriptFileUpdate extends cli_core_1.TypeScriptFileUpdate {
74
74
  if (dep.from) {
75
75
  this.addImportDeclarationForDependency(copy, dep.from, variables);
76
76
  }
77
- if (dep.root && copy.imports.length > 0) {
78
- // add forRoot to the module
79
- copy.imports = copy.imports.map((i) => this.astTransformer.printer.printNode(ts.EmitHint.Unspecified, this.astTransformer.createCallExpression(i, cli_core_1.NG_FOR_ROOT_IDENTIFIER_NAME), this.astTransformer.sourceFile));
80
- }
77
+ this.addRootToModule(dep, copy);
81
78
  this.applyDecoratorMutations(cli_core_1.NG_MODULE_DECORATOR_NAME, copy, multiline);
82
79
  }
80
+ /**
81
+ * Adds metadata to the arguments provided in `TestBed.configureTestingModule`.
82
+ * @param dep The dependency to add to the testing module's metadata.
83
+ * @param variables Variables to replace in the dependency strings.
84
+ * @param multiline Whether to format the new entry as multiline.
85
+ */
86
+ addTestingModuleMeta(dep, variables, multiline = false) {
87
+ const copy = {
88
+ imports: this.asArray(dep.import || [], variables || {}),
89
+ declarations: this.asArray(dep.declare || [], variables || {}),
90
+ providers: this.asArray(dep.provide || [], variables || {}),
91
+ exports: this.asArray(dep.export || [], variables || {}),
92
+ schemas: this.asArray(dep.schema || [], variables || {}),
93
+ };
94
+ if (dep.from) {
95
+ this.addImportDeclarationForDependency(copy, dep.from, variables);
96
+ }
97
+ if (!this.standalone) {
98
+ this.addRootToModule(dep, copy);
99
+ }
100
+ const parentIsConfigureTestingModule = (node) => {
101
+ return !!this.astTransformer.findNodeAncestor(node, (_node) => {
102
+ return (ts.isCallExpression(_node) &&
103
+ ts.isPropertyAccessExpression(_node.expression) &&
104
+ ts.isIdentifier(_node.expression.name) &&
105
+ _node.expression.name.text === cli_core_1.NG_CONFIG_TESTING_MODULE);
106
+ });
107
+ };
108
+ const findTargetMetaProp = (propName) => this.astTransformer.findPropertyAssignment((node) => ts.isIdentifier(node.name) &&
109
+ node.name.text === propName &&
110
+ parentIsConfigureTestingModule(node));
111
+ for (const key of Object.keys(copy)) {
112
+ const targetMetaProp = findTargetMetaProp(key);
113
+ const identifiers = copy[key].map(ts.factory.createIdentifier);
114
+ if (copy[key].length > 0) {
115
+ this.mutateNgMeta(key, targetMetaProp, identifiers, parentIsConfigureTestingModule, multiline);
116
+ }
117
+ }
118
+ }
83
119
  /**
84
120
  * Includes `{ bindToComponentInputs: true }` for a `forRoot` call in an `NgModule`'s `imports` member.
85
121
  *
@@ -227,10 +263,21 @@ class AngularTypeScriptFileUpdate extends cli_core_1.TypeScriptFileUpdate {
227
263
  mutateNgDecoratorMeta(name, meta, target, multiline = false) {
228
264
  const identifiers = meta.map(ts.factory.createIdentifier);
229
265
  const targetMetaProp = this.findNgDecoratorProperty(name, target);
266
+ this.mutateNgMeta(target, targetMetaProp, identifiers, (node) => this.checkNgDecorator(name, node), multiline);
267
+ }
268
+ /**
269
+ * Updates Angular's metadata related to NgModules, Standalone Components or TestingModules.
270
+ * @param target The name of the target metadata property to update.
271
+ * @param targetMetaProp The property that is to be updated.
272
+ * @param identifiers The identifiers to add.
273
+ * @param visitorCondition The condition to find the object literal that contains the target property.
274
+ * @param multiline Whether to format the new entry as multiline.
275
+ */
276
+ mutateNgMeta(target, targetMetaProp, identifiers, visitorCondition, multiline) {
230
277
  const value = targetMetaProp && !ts.isArrayLiteralExpression(targetMetaProp.initializer)
231
278
  ? [targetMetaProp.initializer, ...identifiers]
232
279
  : identifiers;
233
- this.astTransformer.requestNewMemberInObjectLiteral((node) => this.checkNgDecorator(name, node), target, this.astTransformer.createArrayLiteralExpression(value, multiline), multiline);
280
+ this.astTransformer.requestNewMemberInObjectLiteral(visitorCondition, target, this.astTransformer.createArrayLiteralExpression(value, multiline), multiline);
234
281
  }
235
282
  /**
236
283
  * Checks if a node has an ancestor with a specific decorator.
@@ -256,8 +303,8 @@ class AngularTypeScriptFileUpdate extends cli_core_1.TypeScriptFileUpdate {
256
303
  * @param node The node to start checking from.
257
304
  */
258
305
  findNgDecoratorProperty(decoratorName, propName) {
259
- const ngDecoratorExists = (node) => !!this.astTransformer.findNodeAncestor(node, (node) => {
260
- const nodeExpressionToken = ts.isDecorator(node) && node.expression.getFirstToken();
306
+ const ngDecoratorExists = (node) => !!this.astTransformer.findNodeAncestor(node, (_node) => {
307
+ const nodeExpressionToken = ts.isDecorator(_node) && _node.expression.getFirstToken();
261
308
  return (ts.isIdentifier(nodeExpressionToken) &&
262
309
  nodeExpressionToken.text === decoratorName);
263
310
  });
@@ -265,5 +312,26 @@ class AngularTypeScriptFileUpdate extends cli_core_1.TypeScriptFileUpdate {
265
312
  node.name.text === propName &&
266
313
  ngDecoratorExists(node));
267
314
  }
315
+ /**
316
+ * Calls `forRoot` on a module identifier.
317
+ * @param dep The dependency to add to the module's metadata.
318
+ * @param copy The copy of the module's metadata.
319
+ * @param args The arguments to pass to the `forRoot` call.
320
+ */
321
+ addRootToModule(dep, copy, args) {
322
+ if (dep.root && copy.imports.length > 0) {
323
+ // add forRoot to the module
324
+ let forRootArgs = [
325
+ this.astTransformer.createArrayLiteralExpression([]),
326
+ ];
327
+ if (args) {
328
+ forRootArgs = Array.isArray(args)
329
+ ? args
330
+ : [this.astTransformer.createArrayLiteralExpression([args])];
331
+ }
332
+ copy.imports = copy.imports.map((i) => this.astTransformer.printer.printNode(ts.EmitHint.Unspecified, this.astTransformer.createCallExpression(i, cli_core_1.NG_FOR_ROOT_IDENTIFIER_NAME, undefined, // type args
333
+ forRootArgs), this.astTransformer.sourceFile));
334
+ }
335
+ }
268
336
  }
269
337
  exports.AngularTypeScriptFileUpdate = AngularTypeScriptFileUpdate;
@@ -5,8 +5,8 @@ import { IgxAutocompleteModule, IgxDropDownModule, IgxInputGroupModule, IgxToast
5
5
  import {
6
6
  <%=ClassName%>Component,
7
7
  <%=ClassName%>PipeStartsWith,
8
- <%=ClassName%>RegionContains }
9
- from './<%=filePrefix%>.component';
8
+ <%=ClassName%>RegionContains
9
+ } from './<%=filePrefix%>.component';
10
10
 
11
11
  describe('<%=ClassName%>Component', () => {
12
12
  let component: <%=ClassName%>Component;
@@ -14,8 +14,17 @@ describe('<%=ClassName%>Component', () => {
14
14
 
15
15
  beforeEach(waitForAsync(() => {
16
16
  TestBed.configureTestingModule({
17
- declarations: [<%=ClassName%>Component, <%=ClassName%>PipeStartsWith, <%=ClassName%>RegionContains],
18
- imports: [FormsModule, IgxDropDownModule, IgxAutocompleteModule, NoopAnimationsModule, IgxInputGroupModule, IgxToastModule]
17
+ imports: [
18
+ <%=ClassName%>Component,
19
+ <%=ClassName%>PipeStartsWith,
20
+ <%=ClassName%>RegionContains,
21
+ FormsModule,
22
+ IgxDropDownModule,
23
+ IgxAutocompleteModule,
24
+ IgxInputGroupModule,
25
+ IgxToastModule,
26
+ NoopAnimationsModule
27
+ ]
19
28
  })
20
29
  .compileComponents();
21
30
  }));
@@ -19,7 +19,6 @@ describe('<%=ClassName%>Component', () => {
19
19
 
20
20
  beforeEach(waitForAsync(() => {
21
21
  TestBed.configureTestingModule({
22
- declarations: [],
23
22
  imports: [
24
23
  FormsModule,
25
24
  BrowserAnimationsModule,
@@ -0,0 +1,23 @@
1
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2
+ import { RouterModule } from '@angular/router';
3
+ import { AppComponent } from './app.component';
4
+
5
+ describe('AppComponent', () => {
6
+ let component: AppComponent;
7
+ let fixture: ComponentFixture<AppComponent>;
8
+
9
+ beforeEach(waitForAsync(() => {
10
+ TestBed.configureTestingModule({
11
+ imports: [ AppComponent, RouterModule.forRoot([]) ]
12
+ })
13
+ .compileComponents();
14
+
15
+ fixture = TestBed.createComponent(AppComponent);
16
+ component = fixture.componentInstance;
17
+ fixture.detectChanges();
18
+ }));
19
+
20
+ it('should create', () => {
21
+ expect(component).toBeTruthy();
22
+ });
23
+ });
@@ -1,5 +1,5 @@
1
1
  import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2
- import { RouterTestingModule } from '@angular/router/testing';
2
+ import { RouterModule } from '@angular/router';
3
3
  import { HomeComponent } from './home.component';
4
4
 
5
5
  describe('HomeComponent', () => {
@@ -8,8 +8,7 @@ describe('HomeComponent', () => {
8
8
 
9
9
  beforeEach(waitForAsync(() => {
10
10
  TestBed.configureTestingModule({
11
- imports: [ RouterTestingModule ],
12
- declarations: [ HomeComponent ]
11
+ imports: [ HomeComponent, RouterModule.forRoot([]) ]
13
12
  })
14
13
  .compileComponents();
15
14
  }));
@@ -1,12 +1,13 @@
1
1
  import { TestBed, waitForAsync } from '@angular/core/testing';
2
- import { RouterTestingModule } from '@angular/router/testing';
2
+ import { RouterModule } from '@angular/router';
3
3
  import { IgxLayoutModule, IgxNavbarModule, IgxNavigationDrawerModule, IgxRippleModule } from 'igniteui-angular';
4
4
  import { AppComponent } from './app.component';
5
+
5
6
  describe('AppComponent', () => {
6
7
  beforeEach(waitForAsync(() => {
7
8
  TestBed.configureTestingModule({
8
9
  imports: [
9
- RouterTestingModule,
10
+ RouterModule.forRoot([]),
10
11
  IgxLayoutModule,
11
12
  IgxNavbarModule,
12
13
  IgxNavigationDrawerModule,
@@ -15,6 +16,7 @@ describe('AppComponent', () => {
15
16
  ]
16
17
  }).compileComponents();
17
18
  }));
19
+
18
20
  it('should create the app', waitForAsync(() => {
19
21
  const fixture = TestBed.createComponent(AppComponent);
20
22
  const app = fixture.componentInstance;
@@ -1,15 +1,16 @@
1
1
  import { TestBed, waitForAsync } from '@angular/core/testing';
2
2
  import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3
- import { RouterTestingModule } from '@angular/router/testing';
3
+ import { RouterModule } from '@angular/router';
4
4
  import { IgxLayoutModule, IgxNavbarModule, IgxNavigationDrawerModule, IgxRippleModule } from 'igniteui-angular';
5
5
  import { AppComponent } from './app.component';
6
6
  import { AuthenticationModule } from './authentication';
7
+
7
8
  describe('AppComponent', () => {
8
9
  beforeEach(waitForAsync(() => {
9
10
  TestBed.configureTestingModule({
10
11
  imports: [
11
12
  NoopAnimationsModule,
12
- RouterTestingModule,
13
+ RouterModule.forRoot([]),
13
14
  IgxNavigationDrawerModule,
14
15
  AuthenticationModule,
15
16
  IgxNavbarModule,
@@ -19,6 +20,7 @@ describe('AppComponent', () => {
19
20
  ]
20
21
  }).compileComponents();
21
22
  }));
23
+
22
24
  it('should create the app', waitForAsync(() => {
23
25
  const fixture = TestBed.createComponent(AppComponent);
24
26
  const app = fixture.componentInstance;
@@ -99,7 +99,6 @@
99
99
  "main": "src/test.ts",
100
100
  "polyfills": "src/polyfills.ts",
101
101
  "tsConfig": "tsconfig.spec.json",
102
- "karmaConfig": "karma.conf.js",
103
102
  "inlineStyleLanguage": "scss",
104
103
  "styles": [
105
104
  "src/styles.scss"
@@ -0,0 +1,24 @@
1
+ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2
+ import { RouterTestingModule } from '@angular/router/testing';
3
+ import { AppComponent } from './app.component';
4
+
5
+ describe('AppComponent', () => {
6
+ let component: AppComponent;
7
+ let fixture: ComponentFixture<AppComponent>;
8
+
9
+ beforeEach(waitForAsync(() => {
10
+ TestBed.configureTestingModule({
11
+ declarations: [ AppComponent ],
12
+ imports: [ RouterTestingModule ]
13
+ })
14
+ .compileComponents();
15
+
16
+ fixture = TestBed.createComponent(AppComponent);
17
+ component = fixture.componentInstance;
18
+ fixture.detectChanges();
19
+ }));
20
+
21
+ it('should create', () => {
22
+ expect(component).toBeTruthy();
23
+ });
24
+ });
@@ -8,8 +8,8 @@ describe('HomeComponent', () => {
8
8
 
9
9
  beforeEach(waitForAsync(() => {
10
10
  TestBed.configureTestingModule({
11
- imports: [ RouterTestingModule ],
12
- declarations: [ HomeComponent ]
11
+ declarations: [ HomeComponent ],
12
+ imports: [ RouterTestingModule ]
13
13
  })
14
14
  .compileComponents();
15
15
  }));
@@ -2,6 +2,7 @@ import { TestBed, waitForAsync } from '@angular/core/testing';
2
2
  import { RouterTestingModule } from '@angular/router/testing';
3
3
  import { IgxLayoutModule, IgxNavbarModule, IgxNavigationDrawerModule, IgxRippleModule } from 'igniteui-angular';
4
4
  import { AppComponent } from './app.component';
5
+
5
6
  describe('AppComponent', () => {
6
7
  beforeEach(waitForAsync(() => {
7
8
  TestBed.configureTestingModule({
@@ -17,6 +18,7 @@ describe('AppComponent', () => {
17
18
  ],
18
19
  }).compileComponents();
19
20
  }));
21
+
20
22
  it('should create the app', waitForAsync(() => {
21
23
  const fixture = TestBed.createComponent(AppComponent);
22
24
  const app = fixture.componentInstance;
@@ -4,6 +4,7 @@ import { RouterTestingModule } from '@angular/router/testing';
4
4
  import { IgxLayoutModule, IgxNavbarModule, IgxNavigationDrawerModule, IgxRippleModule } from 'igniteui-angular';
5
5
  import { AppComponent } from './app.component';
6
6
  import { AuthenticationModule } from './authentication';
7
+
7
8
  describe('AppComponent', () => {
8
9
  beforeEach(waitForAsync(() => {
9
10
  TestBed.configureTestingModule({
@@ -21,6 +22,7 @@ describe('AppComponent', () => {
21
22
  ],
22
23
  }).compileComponents();
23
24
  }));
25
+
24
26
  it('should create the app', waitForAsync(() => {
25
27
  const fixture = TestBed.createComponent(AppComponent);
26
28
  const app = fixture.componentInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igniteui/angular-templates",
3
- "version": "18.1.1400-beta.2",
3
+ "version": "18.1.1400-beta.3",
4
4
  "description": "Templates for Ignite UI for Angular projects and components",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,7 +12,7 @@
12
12
  "author": "Infragistics",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@igniteui/cli-core": "~14.0.0-beta.2",
15
+ "@igniteui/cli-core": "~14.0.0-beta.3",
16
16
  "typescript": "~5.4.3"
17
17
  }
18
18
  }