@angular-devkit/schematics 14.2.0-next.0 → 14.2.0-rc.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-devkit/schematics",
3
- "version": "14.2.0-next.0",
3
+ "version": "14.2.0-rc.0",
4
4
  "description": "Angular Schematics - Library",
5
5
  "main": "src/index.js",
6
6
  "typings": "src/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "schematics"
19
19
  ],
20
20
  "dependencies": {
21
- "@angular-devkit/core": "14.2.0-next.0",
21
+ "@angular-devkit/core": "14.2.0-rc.0",
22
22
  "jsonc-parser": "3.1.0",
23
23
  "magic-string": "0.26.2",
24
24
  "ora": "5.4.1",
@@ -9,7 +9,6 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.SchematicImpl = exports.InvalidSchematicsNameException = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
- const rxjs_1 = require("rxjs");
13
12
  const operators_1 = require("rxjs/operators");
14
13
  const call_1 = require("../rules/call");
15
14
  const scoped_1 = require("../tree/scoped");
@@ -49,7 +48,7 @@ class SchematicImpl {
49
48
  else {
50
49
  input = tree;
51
50
  }
52
- return (0, call_1.callRule)(this._factory(transformedOptions), (0, rxjs_1.of)(input), context).pipe((0, operators_1.map)((output) => {
51
+ return (0, call_1.callRule)(this._factory(transformedOptions), input, context).pipe((0, operators_1.map)((output) => {
53
52
  if (output === input) {
54
53
  return tree;
55
54
  }
package/src/rules/call.js CHANGED
@@ -53,58 +53,41 @@ class InvalidSourceResultException extends core_1.BaseException {
53
53
  }
54
54
  exports.InvalidSourceResultException = InvalidSourceResultException;
55
55
  function callSource(source, context) {
56
- const result = source(context);
57
- if ((0, rxjs_1.isObservable)(result)) {
58
- // Only return the last Tree, and make sure it's a Tree.
59
- return result.pipe((0, operators_1.defaultIfEmpty)(), (0, operators_1.last)(), (0, operators_1.tap)((inner) => {
60
- if (!inner || !(interface_1.TreeSymbol in inner)) {
61
- throw new InvalidSourceResultException(inner);
62
- }
63
- }));
64
- }
65
- else if (result && interface_1.TreeSymbol in result) {
66
- return (0, rxjs_1.of)(result);
67
- }
68
- else {
69
- return (0, rxjs_1.throwError)(new InvalidSourceResultException(result));
70
- }
56
+ return (0, rxjs_1.defer)(async () => {
57
+ let result = source(context);
58
+ if ((0, rxjs_1.isObservable)(result)) {
59
+ result = await result.pipe((0, operators_1.defaultIfEmpty)()).toPromise();
60
+ }
61
+ if (result && interface_1.TreeSymbol in result) {
62
+ return result;
63
+ }
64
+ throw new InvalidSourceResultException(result);
65
+ });
71
66
  }
72
67
  exports.callSource = callSource;
73
68
  function callRule(rule, input, context) {
74
- return ((0, rxjs_1.isObservable)(input) ? input : (0, rxjs_1.of)(input)).pipe((0, operators_1.mergeMap)((inputTree) => {
75
- const result = rule(inputTree, context);
76
- if (!result) {
77
- return (0, rxjs_1.of)(inputTree);
78
- }
79
- else if (typeof result == 'function') {
80
- // This is considered a Rule, chain the rule and return its output.
81
- return callRule(result, inputTree, context);
82
- }
83
- else if ((0, rxjs_1.isObservable)(result)) {
84
- // Only return the last Tree, and make sure it's a Tree.
85
- return result.pipe((0, operators_1.defaultIfEmpty)(), (0, operators_1.last)(), (0, operators_1.tap)((inner) => {
86
- if (!inner || !(interface_1.TreeSymbol in inner)) {
87
- throw new InvalidRuleResultException(inner);
88
- }
89
- }));
90
- }
91
- else if ((0, core_1.isPromise)(result)) {
92
- return (0, rxjs_1.from)(result).pipe((0, operators_1.mergeMap)((inner) => {
93
- if (typeof inner === 'function') {
94
- // This is considered a Rule, chain the rule and return its output.
95
- return callRule(inner, inputTree, context);
96
- }
97
- else {
98
- return (0, rxjs_1.of)(inputTree);
99
- }
100
- }));
101
- }
102
- else if (interface_1.TreeSymbol in result) {
103
- return (0, rxjs_1.of)(result);
104
- }
105
- else {
106
- return (0, rxjs_1.throwError)(new InvalidRuleResultException(result));
107
- }
108
- }));
69
+ if ((0, rxjs_1.isObservable)(input)) {
70
+ return input.pipe((0, operators_1.mergeMap)((inputTree) => callRuleAsync(rule, inputTree, context)));
71
+ }
72
+ else {
73
+ return (0, rxjs_1.defer)(() => callRuleAsync(rule, input, context));
74
+ }
109
75
  }
110
76
  exports.callRule = callRule;
77
+ async function callRuleAsync(rule, tree, context) {
78
+ let result = await rule(tree, context);
79
+ while (typeof result === 'function') {
80
+ // This is considered a Rule, chain the rule and return its output.
81
+ result = await result(tree, context);
82
+ }
83
+ if (typeof result === 'undefined') {
84
+ return tree;
85
+ }
86
+ if ((0, rxjs_1.isObservable)(result)) {
87
+ result = await result.pipe((0, operators_1.defaultIfEmpty)(tree)).toPromise();
88
+ }
89
+ if (interface_1.TreeSymbol in result) {
90
+ return result;
91
+ }
92
+ throw new InvalidRuleResultException(result);
93
+ }