@schematics/angular 15.0.0 → 15.1.0-next.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.
@@ -1,5 +1,5 @@
1
1
  import { Injectable } from '@angular/core';
2
- import { <%= implementationImports %> } from '@angular/router';
2
+ import { <%= routerImports %> } from '@angular/router';
3
3
  import { Observable } from 'rxjs';
4
4
 
5
5
  @Injectable({
package/guard/index.js CHANGED
@@ -14,26 +14,35 @@ function default_1(options) {
14
14
  if (!options.implements) {
15
15
  throw new schematics_1.SchematicsException('Option "implements" is required.');
16
16
  }
17
- const implementations = options.implements
18
- .map((implement) => (implement === 'CanDeactivate' ? 'CanDeactivate<unknown>' : implement))
19
- .join(', ');
20
- const commonRouterNameImports = ['ActivatedRouteSnapshot', 'RouterStateSnapshot'];
21
- const routerNamedImports = [...options.implements, 'UrlTree'];
22
- if (options.implements.includes(schema_1.Implement.CanLoad) ||
23
- options.implements.includes(schema_1.Implement.CanMatch)) {
24
- routerNamedImports.push('Route', 'UrlSegment');
25
- if (options.implements.length > 1) {
26
- routerNamedImports.push(...commonRouterNameImports);
27
- }
17
+ if (options.implements.length > 1 && options.functional) {
18
+ throw new schematics_1.SchematicsException('Can only specify one value for implements when generating a functional guard.');
19
+ }
20
+ if (options.functional) {
21
+ const guardType = options.implements[0] + 'Fn';
22
+ return (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './type-files' }, { guardType });
28
23
  }
29
24
  else {
30
- routerNamedImports.push(...commonRouterNameImports);
25
+ const implementations = options.implements
26
+ .map((implement) => (implement === 'CanDeactivate' ? 'CanDeactivate<unknown>' : implement))
27
+ .join(', ');
28
+ const commonRouterNameImports = ['ActivatedRouteSnapshot', 'RouterStateSnapshot'];
29
+ const routerNamedImports = [...options.implements, 'UrlTree'];
30
+ if (options.implements.includes(schema_1.Implement.CanLoad) ||
31
+ options.implements.includes(schema_1.Implement.CanMatch)) {
32
+ routerNamedImports.push('Route', 'UrlSegment');
33
+ if (options.implements.length > 1) {
34
+ routerNamedImports.push(...commonRouterNameImports);
35
+ }
36
+ }
37
+ else {
38
+ routerNamedImports.push(...commonRouterNameImports);
39
+ }
40
+ routerNamedImports.sort();
41
+ const routerImports = routerNamedImports.join(', ');
42
+ return (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './implements-files' }, {
43
+ implementations,
44
+ routerImports,
45
+ });
31
46
  }
32
- routerNamedImports.sort();
33
- const implementationImports = routerNamedImports.join(', ');
34
- return (0, generate_from_files_1.generateFromFiles)(options, {
35
- implementations,
36
- implementationImports,
37
- });
38
47
  }
39
48
  exports.default = default_1;
package/guard/schema.d.ts CHANGED
@@ -7,7 +7,11 @@ export interface Schema {
7
7
  */
8
8
  flat?: boolean;
9
9
  /**
10
- * Specifies which interfaces to implement.
10
+ * Specifies whether to generate a guard as a function.
11
+ */
12
+ functional?: boolean;
13
+ /**
14
+ * Specifies which type of guard to create.
11
15
  */
12
16
  implements?: Implement[];
13
17
  /**
package/guard/schema.json CHANGED
@@ -41,9 +41,14 @@
41
41
  "$source": "projectName"
42
42
  }
43
43
  },
44
+ "functional": {
45
+ "type": "boolean",
46
+ "description": "Specifies whether to generate a guard as a function.",
47
+ "default": false
48
+ },
44
49
  "implements": {
45
50
  "type": "array",
46
- "description": "Specifies which interfaces to implement.",
51
+ "description": "Specifies which type of guard to create.",
47
52
  "uniqueItems": true,
48
53
  "minItems": 1,
49
54
  "items": {
@@ -51,7 +56,7 @@
51
56
  "type": "string"
52
57
  },
53
58
  "default": ["CanActivate"],
54
- "x-prompt": "Which interfaces would you like to implement?"
59
+ "x-prompt": "Which type of guard would you like to create?"
55
60
  }
56
61
  },
57
62
  "required": ["name", "project"]
@@ -0,0 +1,18 @@
1
+ import { EnvironmentInjector } from '@angular/core';
2
+ import { TestBed } from '@angular/core/testing';
3
+ import { <%= guardType %> } from '@angular/router';
4
+
5
+ import { <%= camelize(name) %>Guard } from './<%= dasherize(name) %>.guard';
6
+
7
+ describe('<%= camelize(name) %>Guard', () => {
8
+ const executeGuard: <%= guardType %> = (...guardParameters) =>
9
+ TestBed.inject(EnvironmentInjector).runInContext(() => <%= camelize(name) %>Guard(...guardParameters));
10
+
11
+ beforeEach(() => {
12
+ TestBed.configureTestingModule({});
13
+ });
14
+
15
+ it('should be created', () => {
16
+ expect(<%= camelize(name) %>Guard).toBeTruthy();
17
+ });
18
+ });
@@ -0,0 +1,9 @@
1
+ import { <%= guardType %> } from '@angular/router';
2
+
3
+ export const <%= camelize(name) %>Guard: <%= guardType %><% if (guardType === 'CanDeactivateFn') { %><unknown><% } %> = <%
4
+ if (guardType === 'CanMatchFn' || guardType === 'CanLoadFn') { %>(route, segments)<% }
5
+ %><% if (guardType === 'CanActivateFn') { %>(route, state)<% }
6
+ %><% if (guardType === 'CanActivateChildFn') { %>(childRoute, state)<% }
7
+ %><% if (guardType === 'CanDeactivateFn') { %>(component, currentRoute, currentState, nextState)<% } %> => {
8
+ return true;
9
+ }
@@ -7,5 +7,6 @@
7
7
  },
8
8
  "dependencies": {
9
9
  "tslib": "^<%= tsLibLatestVersion %>"
10
- }
11
- }
10
+ },
11
+ "sideEffects": false
12
+ }
@@ -11,19 +11,26 @@ const json_file_1 = require("../../utility/json-file");
11
11
  const workspace_1 = require("../../utility/workspace");
12
12
  const workspace_models_1 = require("../../utility/workspace-models");
13
13
  function default_1() {
14
- return async (host) => {
14
+ return async (host, context) => {
15
15
  // Workspace level tsconfig
16
16
  updateTarget(host, 'tsconfig.json');
17
17
  const workspace = await (0, workspace_1.getWorkspace)(host);
18
18
  // Find all tsconfig which are refereces used by builders
19
19
  for (const [, project] of workspace.projects) {
20
- for (const [, target] of project.targets) {
20
+ for (const [targetName, target] of project.targets) {
21
21
  // Update all other known CLI builders that use a tsconfig
22
22
  const tsConfigs = [target.options || {}, ...Object.values(target.configurations || {})]
23
23
  .filter((opt) => typeof (opt === null || opt === void 0 ? void 0 : opt.tsConfig) === 'string')
24
24
  .map((opt) => opt.tsConfig);
25
- const uniqueTsConfigs = [...new Set(tsConfigs)];
26
- if (uniqueTsConfigs.length < 1) {
25
+ const uniqueTsConfigs = new Set(tsConfigs);
26
+ for (const tsConfig of uniqueTsConfigs) {
27
+ if (host.exists(tsConfig)) {
28
+ continue;
29
+ }
30
+ uniqueTsConfigs.delete(tsConfig);
31
+ context.logger.warn(`'${tsConfig}' referenced in the '${targetName}' target does not exist.`);
32
+ }
33
+ if (!uniqueTsConfigs.size) {
27
34
  continue;
28
35
  }
29
36
  switch (target.builder) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematics/angular",
3
- "version": "15.0.0",
3
+ "version": "15.1.0-next.0",
4
4
  "description": "Schematics specific to Angular",
5
5
  "homepage": "https://github.com/angular/angular-cli",
6
6
  "keywords": [
@@ -23,8 +23,8 @@
23
23
  },
24
24
  "schematics": "./collection.json",
25
25
  "dependencies": {
26
- "@angular-devkit/core": "15.0.0",
27
- "@angular-devkit/schematics": "15.0.0",
26
+ "@angular-devkit/core": "15.1.0-next.0",
27
+ "@angular-devkit/schematics": "15.1.0-next.0",
28
28
  "jsonc-parser": "3.2.0"
29
29
  },
30
30
  "repository": {
@@ -0,0 +1,17 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { ResolveFn } from '@angular/router';
3
+
4
+ import { <%= camelize(name) %>Resolver } from './<%= dasherize(name) %>.resolver';
5
+
6
+ describe('<%= camelize(name) %>Resolver', () => {
7
+ const executeResolver: ResolveFn<boolean> = (...resolverParameters) =>
8
+ TestBed.inject(EnvironmentInjector).runInContext(() => <%= camelize(name) %>Resolver(...resolverParameters));
9
+
10
+ beforeEach(() => {
11
+ TestBed.configureTestingModule({});
12
+ });
13
+
14
+ it('should be created', () => {
15
+ expect(resolver).toBeTruthy();
16
+ });
17
+ });
@@ -0,0 +1,5 @@
1
+ import { ResolveFn } from '@angular/router';
2
+
3
+ export const <%= camelize(name) %>Resolver: ResolveFn<boolean> = (route, state) => {
4
+ return true;
5
+ }
package/resolver/index.js CHANGED
@@ -9,6 +9,8 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  const generate_from_files_1 = require("../utility/generate-from-files");
11
11
  function default_1(options) {
12
- return (0, generate_from_files_1.generateFromFiles)(options);
12
+ return options.functional
13
+ ? (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './functional-files' })
14
+ : (0, generate_from_files_1.generateFromFiles)({ ...options, templateFilesDirectory: './class-files' });
13
15
  }
14
16
  exports.default = default_1;
@@ -6,6 +6,10 @@ export interface Schema {
6
6
  * When true (the default), creates the new files at the top level of the current project.
7
7
  */
8
8
  flat?: boolean;
9
+ /**
10
+ * Creates the resolver as a `ResolveFn`.
11
+ */
12
+ functional?: boolean;
9
13
  /**
10
14
  * The name of the new resolver.
11
15
  */
@@ -25,6 +25,11 @@
25
25
  "description": "When true (the default), creates the new files at the top level of the current project.",
26
26
  "default": true
27
27
  },
28
+ "functional": {
29
+ "type": "boolean",
30
+ "description": "Creates the resolver as a `ResolveFn`.",
31
+ "default": false
32
+ },
28
33
  "path": {
29
34
  "type": "string",
30
35
  "format": "path",
@@ -13,5 +13,6 @@ export interface GenerateFromFilesOptions {
13
13
  prefix?: string;
14
14
  project: string;
15
15
  skipTests?: boolean;
16
+ templateFilesDirectory?: string;
16
17
  }
17
18
  export declare function generateFromFiles(options: GenerateFromFilesOptions, extraTemplateValues?: Record<string, string | ((v: string) => string)>): Rule;
@@ -14,7 +14,7 @@ const validation_1 = require("./validation");
14
14
  const workspace_1 = require("./workspace");
15
15
  function generateFromFiles(options, extraTemplateValues = {}) {
16
16
  return async (host) => {
17
- var _a, _b, _c;
17
+ var _a, _b, _c, _d;
18
18
  (_a = options.path) !== null && _a !== void 0 ? _a : (options.path = await (0, workspace_1.createDefaultPath)(host, options.project));
19
19
  (_b = options.prefix) !== null && _b !== void 0 ? _b : (options.prefix = '');
20
20
  (_c = options.flat) !== null && _c !== void 0 ? _c : (options.flat = true);
@@ -22,7 +22,8 @@ function generateFromFiles(options, extraTemplateValues = {}) {
22
22
  options.name = parsedPath.name;
23
23
  options.path = parsedPath.path;
24
24
  (0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
25
- const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
25
+ const templateFilesDirectory = (_d = options.templateFilesDirectory) !== null && _d !== void 0 ? _d : './files';
26
+ const templateSource = (0, schematics_1.apply)((0, schematics_1.url)(templateFilesDirectory), [
26
27
  options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
27
28
  (0, schematics_1.applyTemplates)({
28
29
  ...schematics_1.strings,
@@ -12,7 +12,7 @@
12
12
  "karma-jasmine-html-reporter": "~2.0.0",
13
13
  "karma-jasmine": "~5.1.0",
14
14
  "karma": "~6.4.0",
15
- "ng-packagr": "^15.0.0",
15
+ "ng-packagr": "^15.0.0-next.0",
16
16
  "protractor": "~7.0.0",
17
17
  "rxjs": "~7.5.0",
18
18
  "tslib": "^2.3.0",
@@ -13,7 +13,7 @@ exports.latestVersions = {
13
13
  // but ts_library doesn't support JSON inputs.
14
14
  ...require('./latest-versions/package.json')['dependencies'],
15
15
  // As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current
16
- Angular: '^15.0.0',
16
+ Angular: '^15.0.0-next.0',
17
17
  // Since @angular-devkit/build-angular and @schematics/angular are always
18
18
  // published together from the same monorepo, and they are both
19
19
  // non-experimental, they will always have the same version.