@angular/cli 14.0.0-next.1 → 14.0.0-next.12

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.
Files changed (239) hide show
  1. package/bin/ng.js +3 -5
  2. package/lib/cli/index.d.ts +1 -2
  3. package/lib/cli/index.js +16 -45
  4. package/lib/config/schema.json +48 -15
  5. package/lib/config/workspace-schema.d.ts +18 -1
  6. package/lib/init.js +10 -9
  7. package/package.json +21 -23
  8. package/{models → src/analytics}/analytics-collector.d.ts +0 -0
  9. package/{models → src/analytics}/analytics-collector.js +8 -2
  10. package/src/analytics/analytics.d.ts +47 -0
  11. package/src/analytics/analytics.js +306 -0
  12. package/src/command-builder/architect-base-command-module.d.ts +30 -0
  13. package/src/command-builder/architect-base-command-module.js +165 -0
  14. package/src/command-builder/architect-command-module.d.ts +25 -0
  15. package/src/command-builder/architect-command-module.js +134 -0
  16. package/src/command-builder/command-module.d.ts +89 -0
  17. package/src/command-builder/command-module.js +198 -0
  18. package/{utilities/package-json.js → src/command-builder/command-runner.d.ts} +2 -2
  19. package/src/command-builder/command-runner.js +168 -0
  20. package/src/command-builder/schematics-command-module.d.ts +43 -0
  21. package/src/command-builder/schematics-command-module.js +333 -0
  22. package/src/command-builder/utilities/command.d.ts +13 -0
  23. package/src/command-builder/utilities/command.js +27 -0
  24. package/src/command-builder/utilities/json-help.d.ts +36 -0
  25. package/src/command-builder/utilities/json-help.js +94 -0
  26. package/src/command-builder/utilities/json-schema.d.ts +40 -0
  27. package/{utilities → src/command-builder/utilities}/json-schema.js +20 -121
  28. package/src/command-builder/utilities/normalize-options-middleware.d.ts +18 -0
  29. package/src/command-builder/utilities/normalize-options-middleware.js +59 -0
  30. package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +2 -2
  31. package/{models → src/command-builder/utilities}/schematic-engine-host.js +33 -18
  32. package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
  33. package/src/command-builder/utilities/schematic-workflow.js +68 -0
  34. package/src/commands/add/cli.d.ts +33 -0
  35. package/{commands/add-impl.js → src/commands/add/cli.js} +108 -80
  36. package/src/commands/add/long-description.md +7 -0
  37. package/src/commands/analytics/cli.d.ts +16 -0
  38. package/src/commands/analytics/cli.js +35 -0
  39. package/src/commands/analytics/info/cli.d.ts +16 -0
  40. package/src/commands/analytics/info/cli.js +26 -0
  41. package/src/commands/analytics/settings/cli.d.ts +35 -0
  42. package/src/commands/analytics/settings/cli.js +61 -0
  43. package/src/commands/build/cli.d.ts +16 -0
  44. package/src/commands/build/cli.js +23 -0
  45. package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
  46. package/src/commands/cache/clean/cli.d.ts +17 -0
  47. package/src/commands/cache/clean/cli.js +32 -0
  48. package/src/commands/cache/cli.d.ts +17 -0
  49. package/src/commands/cache/cli.js +38 -0
  50. package/src/commands/cache/info/cli.d.ts +20 -0
  51. package/src/commands/cache/info/cli.js +82 -0
  52. package/src/commands/cache/long-description.md +53 -0
  53. package/src/commands/cache/settings/cli.d.ts +27 -0
  54. package/src/commands/cache/settings/cli.js +42 -0
  55. package/src/commands/cache/utilities.d.ts +11 -0
  56. package/src/commands/cache/utilities.js +49 -0
  57. package/src/commands/completion/cli.d.ts +16 -0
  58. package/src/commands/completion/cli.js +31 -0
  59. package/src/commands/completion/long-description.md +1 -0
  60. package/src/commands/config/cli.d.ts +24 -0
  61. package/{commands/config-impl.js → src/commands/config/cli.js} +102 -89
  62. package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
  63. package/src/commands/deploy/cli.d.ts +17 -0
  64. package/src/commands/deploy/cli.js +49 -0
  65. package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
  66. package/src/commands/doc/cli.d.ts +23 -0
  67. package/{commands/doc-impl.js → src/commands/doc/cli.js} +41 -12
  68. package/src/commands/e2e/cli.d.ts +18 -0
  69. package/src/commands/e2e/cli.js +35 -0
  70. package/src/commands/extract-i18n/cli.d.ts +15 -0
  71. package/src/commands/extract-i18n/cli.js +20 -0
  72. package/src/commands/generate/cli.d.ts +39 -0
  73. package/src/commands/generate/cli.js +145 -0
  74. package/src/commands/lint/cli.d.ts +17 -0
  75. package/src/commands/lint/cli.js +28 -0
  76. package/{commands/lint-long.md → src/commands/lint/long-description.md} +0 -0
  77. package/src/commands/make-this-awesome/cli.d.ts +17 -0
  78. package/{commands/easter-egg-impl.js → src/commands/make-this-awesome/cli.js} +17 -10
  79. package/src/commands/new/cli.d.ts +27 -0
  80. package/src/commands/new/cli.js +82 -0
  81. package/src/commands/run/cli.d.ts +25 -0
  82. package/src/commands/run/cli.js +83 -0
  83. package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
  84. package/src/commands/serve/cli.d.ts +16 -0
  85. package/src/commands/serve/cli.js +21 -0
  86. package/src/commands/test/cli.d.ts +16 -0
  87. package/src/commands/test/cli.js +23 -0
  88. package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
  89. package/{commands/update-impl.d.ts → src/commands/update/cli.d.ts} +26 -9
  90. package/{commands/update-impl.js → src/commands/update/cli.js} +363 -316
  91. package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
  92. package/src/commands/update/schematic/index.js +33 -20
  93. package/src/commands/version/cli.d.ts +18 -0
  94. package/{commands/version-impl.js → src/commands/version/cli.js} +56 -74
  95. package/src/typings-bazel.d.ts +14 -0
  96. package/src/typings.d.ts +1 -14
  97. package/{utilities → src/utilities}/color.d.ts +0 -0
  98. package/{utilities → src/utilities}/color.js +5 -1
  99. package/{utilities → src/utilities}/config.d.ts +6 -5
  100. package/{utilities → src/utilities}/config.js +33 -19
  101. package/src/utilities/environment-options.d.ts +12 -0
  102. package/src/utilities/environment-options.js +24 -0
  103. package/{utilities → src/utilities}/find-up.d.ts +0 -0
  104. package/{utilities → src/utilities}/find-up.js +5 -1
  105. package/{utilities → src/utilities}/json-file.d.ts +0 -0
  106. package/{utilities → src/utilities}/json-file.js +1 -0
  107. package/{utilities → src/utilities}/log-file.d.ts +0 -0
  108. package/{utilities → src/utilities}/log-file.js +0 -0
  109. package/src/utilities/memoize.d.ts +15 -0
  110. package/src/utilities/memoize.js +69 -0
  111. package/src/utilities/package-manager.d.ts +41 -0
  112. package/src/utilities/package-manager.js +287 -0
  113. package/{utilities → src/utilities}/package-metadata.d.ts +15 -37
  114. package/{utilities → src/utilities}/package-metadata.js +15 -27
  115. package/{utilities → src/utilities}/package-tree.d.ts +2 -2
  116. package/{utilities → src/utilities}/package-tree.js +5 -1
  117. package/{utilities → src/utilities}/project.d.ts +0 -0
  118. package/{utilities → src/utilities}/project.js +5 -1
  119. package/{utilities → src/utilities}/prompt.d.ts +2 -0
  120. package/{utilities → src/utilities}/prompt.js +25 -4
  121. package/{utilities → src/utilities}/spinner.d.ts +0 -0
  122. package/{utilities → src/utilities}/spinner.js +0 -0
  123. package/{utilities → src/utilities}/tty.d.ts +0 -0
  124. package/{utilities → src/utilities}/tty.js +0 -0
  125. package/{models → src/utilities}/version.d.ts +2 -1
  126. package/{models → src/utilities}/version.js +6 -6
  127. package/bin/postinstall/analytics-prompt.js +0 -27
  128. package/bin/postinstall/script.js +0 -16
  129. package/commands/add-impl.d.ts +0 -21
  130. package/commands/add.d.ts +0 -42
  131. package/commands/add.js +0 -10
  132. package/commands/add.json +0 -54
  133. package/commands/add.md +0 -10
  134. package/commands/analytics-impl.d.ts +0 -13
  135. package/commands/analytics-impl.js +0 -80
  136. package/commands/analytics-long.md +0 -8
  137. package/commands/analytics.d.ts +0 -46
  138. package/commands/analytics.js +0 -31
  139. package/commands/analytics.json +0 -37
  140. package/commands/build-impl.d.ts +0 -14
  141. package/commands/build-impl.js +0 -21
  142. package/commands/build.d.ts +0 -30
  143. package/commands/build.js +0 -10
  144. package/commands/build.json +0 -16
  145. package/commands/config-impl.d.ts +0 -15
  146. package/commands/config.d.ts +0 -34
  147. package/commands/config.js +0 -10
  148. package/commands/config.json +0 -43
  149. package/commands/definitions.json +0 -66
  150. package/commands/deploy-impl.d.ts +0 -15
  151. package/commands/deploy-impl.js +0 -36
  152. package/commands/deploy.d.ts +0 -30
  153. package/commands/deploy.js +0 -10
  154. package/commands/deploy.json +0 -34
  155. package/commands/doc-impl.d.ts +0 -13
  156. package/commands/doc.d.ts +0 -39
  157. package/commands/doc.js +0 -14
  158. package/commands/doc.json +0 -46
  159. package/commands/e2e-impl.d.ts +0 -16
  160. package/commands/e2e-impl.js +0 -36
  161. package/commands/e2e-long.md +0 -4
  162. package/commands/e2e.d.ts +0 -29
  163. package/commands/e2e.js +0 -10
  164. package/commands/e2e.json +0 -17
  165. package/commands/easter-egg-impl.d.ts +0 -12
  166. package/commands/easter-egg.d.ts +0 -14
  167. package/commands/easter-egg.js +0 -10
  168. package/commands/easter-egg.json +0 -12
  169. package/commands/extract-i18n-impl.d.ts +0 -14
  170. package/commands/extract-i18n-impl.js +0 -32
  171. package/commands/extract-i18n.d.ts +0 -29
  172. package/commands/extract-i18n.js +0 -10
  173. package/commands/extract-i18n.json +0 -17
  174. package/commands/generate-impl.d.ts +0 -18
  175. package/commands/generate-impl.js +0 -89
  176. package/commands/generate.d.ts +0 -37
  177. package/commands/generate.js +0 -10
  178. package/commands/generate.json +0 -31
  179. package/commands/help-impl.d.ts +0 -12
  180. package/commands/help-impl.js +0 -26
  181. package/commands/help-long.md +0 -7
  182. package/commands/help.d.ts +0 -17
  183. package/commands/help.js +0 -10
  184. package/commands/help.json +0 -13
  185. package/commands/lint-impl.d.ts +0 -16
  186. package/commands/lint-impl.js +0 -69
  187. package/commands/lint.d.ts +0 -29
  188. package/commands/lint.js +0 -10
  189. package/commands/lint.json +0 -36
  190. package/commands/new-impl.d.ts +0 -16
  191. package/commands/new-impl.js +0 -37
  192. package/commands/new.d.ts +0 -41
  193. package/commands/new.js +0 -10
  194. package/commands/new.json +0 -34
  195. package/commands/new.md +0 -16
  196. package/commands/run-impl.d.ts +0 -13
  197. package/commands/run-impl.js +0 -22
  198. package/commands/run.d.ts +0 -30
  199. package/commands/run.js +0 -10
  200. package/commands/run.json +0 -36
  201. package/commands/serve-impl.d.ts +0 -15
  202. package/commands/serve-impl.js +0 -24
  203. package/commands/serve.d.ts +0 -29
  204. package/commands/serve.js +0 -10
  205. package/commands/serve.json +0 -17
  206. package/commands/test-impl.d.ts +0 -15
  207. package/commands/test-impl.js +0 -22
  208. package/commands/test.d.ts +0 -29
  209. package/commands/test.js +0 -10
  210. package/commands/test.json +0 -17
  211. package/commands/update.d.ts +0 -61
  212. package/commands/update.js +0 -10
  213. package/commands/update.json +0 -78
  214. package/commands/version-impl.d.ts +0 -17
  215. package/commands/version.d.ts +0 -17
  216. package/commands/version.js +0 -10
  217. package/commands/version.json +0 -13
  218. package/commands.json +0 -20
  219. package/models/analytics.d.ts +0 -58
  220. package/models/analytics.js +0 -358
  221. package/models/architect-command.d.ts +0 -35
  222. package/models/architect-command.js +0 -364
  223. package/models/command-runner.d.ts +0 -24
  224. package/models/command-runner.js +0 -241
  225. package/models/command.d.ts +0 -34
  226. package/models/command.js +0 -143
  227. package/models/interface.d.ts +0 -196
  228. package/models/interface.js +0 -31
  229. package/models/parser.d.ts +0 -39
  230. package/models/parser.js +0 -349
  231. package/models/schematic-command.d.ts +0 -55
  232. package/models/schematic-command.js +0 -485
  233. package/utilities/INITIAL_COMMIT_MESSAGE.txt +0 -8
  234. package/utilities/install-package.d.ts +0 -16
  235. package/utilities/install-package.js +0 -193
  236. package/utilities/json-schema.d.ts +0 -17
  237. package/utilities/package-json.d.ts +0 -249
  238. package/utilities/package-manager.d.ts +0 -13
  239. package/utilities/package-manager.js +0 -106
@@ -7,102 +7,9 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.parseJsonSchemaToOptions = exports.parseJsonSchemaToCommandDescription = exports.parseJsonSchemaToSubCommandDescription = exports.CommandJsonPathException = void 0;
10
+ exports.parseJsonSchemaToOptions = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
- const tools_1 = require("@angular-devkit/schematics/tools");
13
- const fs_1 = require("fs");
14
- const path_1 = require("path");
15
- const interface_1 = require("../models/interface");
16
- class CommandJsonPathException extends core_1.BaseException {
17
- constructor(path, name) {
18
- super(`File ${path} was not found while constructing the subcommand ${name}.`);
19
- this.path = path;
20
- this.name = name;
21
- }
22
- }
23
- exports.CommandJsonPathException = CommandJsonPathException;
24
- function _getEnumFromValue(value, enumeration, defaultValue) {
25
- if (typeof value !== 'string') {
26
- return defaultValue;
27
- }
28
- if (Object.values(enumeration).includes(value)) {
29
- return value;
30
- }
31
- return defaultValue;
32
- }
33
- async function parseJsonSchemaToSubCommandDescription(name, jsonPath, registry, schema) {
34
- const options = await parseJsonSchemaToOptions(registry, schema);
35
- const aliases = [];
36
- if (core_1.json.isJsonArray(schema.$aliases)) {
37
- schema.$aliases.forEach((value) => {
38
- if (typeof value == 'string') {
39
- aliases.push(value);
40
- }
41
- });
42
- }
43
- if (core_1.json.isJsonArray(schema.aliases)) {
44
- schema.aliases.forEach((value) => {
45
- if (typeof value == 'string') {
46
- aliases.push(value);
47
- }
48
- });
49
- }
50
- if (typeof schema.alias == 'string') {
51
- aliases.push(schema.alias);
52
- }
53
- let longDescription = '';
54
- if (typeof schema.$longDescription == 'string' && schema.$longDescription) {
55
- const ldPath = (0, path_1.resolve)((0, path_1.dirname)(jsonPath), schema.$longDescription);
56
- try {
57
- longDescription = (0, fs_1.readFileSync)(ldPath, 'utf-8');
58
- }
59
- catch (e) {
60
- throw new CommandJsonPathException(ldPath, name);
61
- }
62
- }
63
- let usageNotes = '';
64
- if (typeof schema.$usageNotes == 'string' && schema.$usageNotes) {
65
- const unPath = (0, path_1.resolve)((0, path_1.dirname)(jsonPath), schema.$usageNotes);
66
- try {
67
- usageNotes = (0, fs_1.readFileSync)(unPath, 'utf-8');
68
- }
69
- catch (e) {
70
- throw new CommandJsonPathException(unPath, name);
71
- }
72
- }
73
- const description = '' + (schema.description === undefined ? '' : schema.description);
74
- return {
75
- name,
76
- description,
77
- ...(longDescription ? { longDescription } : {}),
78
- ...(usageNotes ? { usageNotes } : {}),
79
- options,
80
- aliases,
81
- };
82
- }
83
- exports.parseJsonSchemaToSubCommandDescription = parseJsonSchemaToSubCommandDescription;
84
- async function parseJsonSchemaToCommandDescription(name, jsonPath, registry, schema) {
85
- const subcommand = await parseJsonSchemaToSubCommandDescription(name, jsonPath, registry, schema);
86
- // Before doing any work, let's validate the implementation.
87
- if (typeof schema.$impl != 'string') {
88
- throw new Error(`Command ${name} has an invalid implementation.`);
89
- }
90
- const ref = new tools_1.ExportStringRef(schema.$impl, (0, path_1.dirname)(jsonPath));
91
- const impl = ref.ref;
92
- if (impl === undefined || typeof impl !== 'function') {
93
- throw new Error(`Command ${name} has an invalid implementation.`);
94
- }
95
- const scope = _getEnumFromValue(schema.$scope, interface_1.CommandScope, interface_1.CommandScope.Default);
96
- const hidden = !!schema.$hidden;
97
- return {
98
- ...subcommand,
99
- scope,
100
- hidden,
101
- impl,
102
- };
103
- }
104
- exports.parseJsonSchemaToCommandDescription = parseJsonSchemaToCommandDescription;
105
- async function parseJsonSchemaToOptions(registry, schema) {
12
+ async function parseJsonSchemaToOptions(registry, schema, interactive = true) {
106
13
  const options = [];
107
14
  function visitor(current, pointer, parentSchema) {
108
15
  if (!parentSchema) {
@@ -131,8 +38,7 @@ async function parseJsonSchemaToOptions(registry, schema) {
131
38
  throw new Error('Cannot find type of schema.');
132
39
  }
133
40
  // We only support number, string or boolean (or array of those), so remove everything else.
134
- const types = [...typeSet]
135
- .filter((x) => {
41
+ const types = [...typeSet].filter((x) => {
136
42
  switch (x) {
137
43
  case 'boolean':
138
44
  case 'number':
@@ -149,8 +55,7 @@ async function parseJsonSchemaToOptions(registry, schema) {
149
55
  default:
150
56
  return false;
151
57
  }
152
- })
153
- .map((x) => _getEnumFromValue(x, interface_1.OptionType, interface_1.OptionType.String));
58
+ });
154
59
  if (types.length == 0) {
155
60
  // This means it's not usable on the command line. e.g. an Object.
156
61
  return;
@@ -190,10 +95,11 @@ async function parseJsonSchemaToOptions(registry, schema) {
190
95
  const $default = current.$default;
191
96
  const $defaultIndex = core_1.json.isJsonObject($default) && $default['$source'] == 'argv' ? $default['index'] : undefined;
192
97
  const positional = typeof $defaultIndex == 'number' ? $defaultIndex : undefined;
193
- const required = core_1.json.isJsonArray(current.required)
194
- ? current.required.indexOf(name) != -1
195
- : false;
196
- const aliases = core_1.json.isJsonArray(current.aliases)
98
+ let required = core_1.json.isJsonArray(schema.required) ? schema.required.includes(name) : false;
99
+ if (required && interactive && current['x-prompt']) {
100
+ required = false;
101
+ }
102
+ const alias = core_1.json.isJsonArray(current.aliases)
197
103
  ? [...current.aliases].map((x) => '' + x)
198
104
  : current.alias
199
105
  ? ['' + current.alias]
@@ -209,37 +115,30 @@ async function parseJsonSchemaToOptions(registry, schema) {
209
115
  const option = {
210
116
  name,
211
117
  description: '' + (current.description === undefined ? '' : current.description),
212
- ...(types.length == 1 ? { type } : { type, types }),
213
- ...(defaultValue !== undefined ? { default: defaultValue } : {}),
214
- ...(enumValues && enumValues.length > 0 ? { enum: enumValues } : {}),
118
+ type,
119
+ default: defaultValue,
120
+ choices: enumValues.length ? enumValues : undefined,
215
121
  required,
216
- aliases,
217
- ...(format !== undefined ? { format } : {}),
122
+ alias,
123
+ format,
218
124
  hidden,
219
- ...(userAnalytics ? { userAnalytics } : {}),
220
- ...(deprecated !== undefined ? { deprecated } : {}),
221
- ...(positional !== undefined ? { positional } : {}),
125
+ userAnalytics,
126
+ deprecated,
127
+ positional,
222
128
  };
223
129
  options.push(option);
224
130
  }
225
131
  const flattenedSchema = await registry.flatten(schema).toPromise();
226
132
  core_1.json.schema.visitJsonSchema(flattenedSchema, visitor);
227
- // Sort by positional.
133
+ // Sort by positional and name.
228
134
  return options.sort((a, b) => {
229
135
  if (a.positional) {
230
- if (b.positional) {
231
- return a.positional - b.positional;
232
- }
233
- else {
234
- return 1;
235
- }
136
+ return b.positional ? a.positional - b.positional : a.name.localeCompare(b.name);
236
137
  }
237
138
  else if (b.positional) {
238
139
  return -1;
239
140
  }
240
- else {
241
- return 0;
242
- }
141
+ return a.name.localeCompare(b.name);
243
142
  });
244
143
  }
245
144
  exports.parseJsonSchemaToOptions = parseJsonSchemaToOptions;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import * as yargs from 'yargs';
9
+ /**
10
+ * A Yargs middleware that normalizes non Array options when the argument has been provided multiple times.
11
+ *
12
+ * By default, when an option is non array and it is provided multiple times in the command line, yargs
13
+ * will not override it's value but instead it will be changed to an array unless `duplicate-arguments-array` is disabled.
14
+ * But this option also have an effect on real array options which isn't desired.
15
+ *
16
+ * See: https://github.com/yargs/yargs-parser/pull/163#issuecomment-516566614
17
+ */
18
+ export declare function normalizeOptionsMiddleware(args: yargs.Arguments): void;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.normalizeOptionsMiddleware = void 0;
34
+ const yargs = __importStar(require("yargs"));
35
+ /**
36
+ * A Yargs middleware that normalizes non Array options when the argument has been provided multiple times.
37
+ *
38
+ * By default, when an option is non array and it is provided multiple times in the command line, yargs
39
+ * will not override it's value but instead it will be changed to an array unless `duplicate-arguments-array` is disabled.
40
+ * But this option also have an effect on real array options which isn't desired.
41
+ *
42
+ * See: https://github.com/yargs/yargs-parser/pull/163#issuecomment-516566614
43
+ */
44
+ function normalizeOptionsMiddleware(args) {
45
+ // `getOptions` is not included in the types even though it's public API.
46
+ // https://github.com/yargs/yargs/issues/2098
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ const { array } = yargs.getOptions();
49
+ const arrayOptions = new Set(array);
50
+ for (const [key, value] of Object.entries(args)) {
51
+ if (key !== '_' && Array.isArray(value) && !arrayOptions.has(key)) {
52
+ const newValue = value.pop();
53
+ // eslint-disable-next-line no-console
54
+ console.warn(`Option '${key}' has been specified multiple times. The value '${newValue}' will be used.`);
55
+ args[key] = newValue;
56
+ }
57
+ }
58
+ }
59
+ exports.normalizeOptionsMiddleware = normalizeOptionsMiddleware;
@@ -6,9 +6,9 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { RuleFactory } from '@angular-devkit/schematics';
9
- import { NodeModulesEngineHost } from '@angular-devkit/schematics/tools';
9
+ import { FileSystemCollectionDesc, NodeModulesEngineHost } from '@angular-devkit/schematics/tools';
10
10
  export declare class SchematicEngineHost extends NodeModulesEngineHost {
11
- protected _resolveReferenceString(refString: string, parentPath: string): {
11
+ protected _resolveReferenceString(refString: string, parentPath: string, collectionDescription?: FileSystemCollectionDesc): {
12
12
  ref: RuleFactory<{}>;
13
13
  path: string;
14
14
  } | null;
@@ -21,21 +21,18 @@ const path_1 = require("path");
21
21
  const vm_1 = require("vm");
22
22
  /**
23
23
  * Environment variable to control schematic package redirection
24
- * Default: Angular schematics only
25
24
  */
26
25
  const schematicRedirectVariable = (_a = process.env['NG_SCHEMATIC_REDIRECT']) === null || _a === void 0 ? void 0 : _a.toLowerCase();
27
- function shouldWrapSchematic(schematicFile) {
26
+ function shouldWrapSchematic(schematicFile, schematicEncapsulation) {
28
27
  // Check environment variable if present
29
- if (schematicRedirectVariable !== undefined) {
30
- switch (schematicRedirectVariable) {
31
- case '0':
32
- case 'false':
33
- case 'off':
34
- case 'none':
35
- return false;
36
- case 'all':
37
- return true;
38
- }
28
+ switch (schematicRedirectVariable) {
29
+ case '0':
30
+ case 'false':
31
+ case 'off':
32
+ case 'none':
33
+ return false;
34
+ case 'all':
35
+ return true;
39
36
  }
40
37
  const normalizedSchematicFile = schematicFile.replace(/\\/g, '/');
41
38
  // Never wrap the internal update schematic when executed directly
@@ -45,17 +42,21 @@ function shouldWrapSchematic(schematicFile) {
45
42
  !normalizedSchematicFile.includes('node_modules/@angular/cli/node_modules/')) {
46
43
  return false;
47
44
  }
48
- // Default is only first-party Angular schematic packages
45
+ // Check for first-party Angular schematic packages
49
46
  // Angular schematics are safe to use in the wrapped VM context
50
- return /\/node_modules\/@(?:angular|schematics|nguniversal)\//.test(normalizedSchematicFile);
47
+ if (/\/node_modules\/@(?:angular|schematics|nguniversal)\//.test(normalizedSchematicFile)) {
48
+ return true;
49
+ }
50
+ // Otherwise use the value of the schematic collection's encapsulation option (current default of false)
51
+ return schematicEncapsulation;
51
52
  }
52
53
  class SchematicEngineHost extends tools_1.NodeModulesEngineHost {
53
- _resolveReferenceString(refString, parentPath) {
54
+ _resolveReferenceString(refString, parentPath, collectionDescription) {
54
55
  const [path, name] = refString.split('#', 2);
55
56
  // Mimic behavior of ExportStringRef class used in default behavior
56
57
  const fullPath = path[0] === '.' ? (0, path_1.resolve)(parentPath !== null && parentPath !== void 0 ? parentPath : process.cwd(), path) : path;
57
58
  const schematicFile = require.resolve(fullPath, { paths: [parentPath] });
58
- if (shouldWrapSchematic(schematicFile)) {
59
+ if (shouldWrapSchematic(schematicFile, !!(collectionDescription === null || collectionDescription === void 0 ? void 0 : collectionDescription.encapsulation))) {
59
60
  const schematicPath = (0, path_1.dirname)(schematicFile);
60
61
  const moduleCache = new Map();
61
62
  const factoryInitializer = wrap(schematicFile, schematicPath, moduleCache, name || 'default');
@@ -66,7 +67,7 @@ class SchematicEngineHost extends tools_1.NodeModulesEngineHost {
66
67
  return { ref: factory, path: schematicPath };
67
68
  }
68
69
  // All other schematics use default behavior
69
- return super._resolveReferenceString(refString, parentPath);
70
+ return super._resolveReferenceString(refString, parentPath, collectionDescription);
70
71
  }
71
72
  }
72
73
  exports.SchematicEngineHost = SchematicEngineHost;
@@ -108,6 +109,15 @@ function wrap(schematicFile, schematicDirectory, moduleCache, exportName) {
108
109
  // Provide compatibility modules for older versions of @angular/cdk
109
110
  return legacyModules[id];
110
111
  }
112
+ else if (id.startsWith('schematics:')) {
113
+ // Schematics built-in modules use the `schematics` scheme (similar to the Node.js `node` scheme)
114
+ const builtinId = id.slice(11);
115
+ const builtinModule = loadBuiltinModule(builtinId);
116
+ if (!builtinModule) {
117
+ throw new Error(`Unknown schematics built-in module '${id}' requested from schematic '${schematicFile}'`);
118
+ }
119
+ return builtinModule;
120
+ }
111
121
  else if (id.startsWith('@angular-devkit/') || id.startsWith('@schematics/')) {
112
122
  // Files should not redirect `@angular/core` and instead use the direct
113
123
  // dependency if available. This allows old major version migrations to continue to function
@@ -151,7 +161,9 @@ function wrap(schematicFile, schematicDirectory, moduleCache, exportName) {
151
161
  const schematicCode = (0, fs_1.readFileSync)(schematicFile, 'utf8');
152
162
  // `module` is required due to @angular/localize ng-add being in UMD format
153
163
  const headerCode = '(function() {\nvar exports = {};\nvar module = { exports };\n';
154
- const footerCode = exportName ? `\nreturn exports['${exportName}'];});` : '\nreturn exports;});';
164
+ const footerCode = exportName
165
+ ? `\nreturn module.exports['${exportName}'];});`
166
+ : '\nreturn module.exports;});';
155
167
  const script = new vm_1.Script(headerCode + schematicCode + footerCode, {
156
168
  filename: schematicFile,
157
169
  lineOffset: 3,
@@ -170,3 +182,6 @@ function wrap(schematicFile, schematicDirectory, moduleCache, exportName) {
170
182
  const exportsFactory = script.runInNewContext(context);
171
183
  return exportsFactory;
172
184
  }
185
+ function loadBuiltinModule(id) {
186
+ return undefined;
187
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { logging } from '@angular-devkit/core';
9
+ import { NodeWorkflow } from '@angular-devkit/schematics/tools';
10
+ export declare function subscribeToWorkflow(workflow: NodeWorkflow, logger: logging.LoggerApi): {
11
+ files: Set<string>;
12
+ error: boolean;
13
+ unsubscribe: () => void;
14
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.io/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.subscribeToWorkflow = void 0;
11
+ const core_1 = require("@angular-devkit/core");
12
+ const color_1 = require("../../utilities/color");
13
+ function subscribeToWorkflow(workflow, logger) {
14
+ const files = new Set();
15
+ let error = false;
16
+ let logs = [];
17
+ const reporterSubscription = workflow.reporter.subscribe((event) => {
18
+ // Strip leading slash to prevent confusion.
19
+ const eventPath = event.path.charAt(0) === '/' ? event.path.substring(1) : event.path;
20
+ switch (event.kind) {
21
+ case 'error':
22
+ error = true;
23
+ const desc = event.description == 'alreadyExist' ? 'already exists' : 'does not exist';
24
+ logger.error(`ERROR! ${eventPath} ${desc}.`);
25
+ break;
26
+ case 'update':
27
+ logs.push(core_1.tags.oneLine `
28
+ ${color_1.colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)
29
+ `);
30
+ files.add(eventPath);
31
+ break;
32
+ case 'create':
33
+ logs.push(core_1.tags.oneLine `
34
+ ${color_1.colors.green('CREATE')} ${eventPath} (${event.content.length} bytes)
35
+ `);
36
+ files.add(eventPath);
37
+ break;
38
+ case 'delete':
39
+ logs.push(`${color_1.colors.yellow('DELETE')} ${eventPath}`);
40
+ files.add(eventPath);
41
+ break;
42
+ case 'rename':
43
+ const eventToPath = event.to.charAt(0) === '/' ? event.to.substring(1) : event.to;
44
+ logs.push(`${color_1.colors.blue('RENAME')} ${eventPath} => ${eventToPath}`);
45
+ files.add(eventPath);
46
+ break;
47
+ }
48
+ });
49
+ const lifecycleSubscription = workflow.lifeCycle.subscribe((event) => {
50
+ if (event.kind == 'end' || event.kind == 'post-tasks-start') {
51
+ if (!error) {
52
+ // Output the logging queue, no error happened.
53
+ logs.forEach((log) => logger.info(log));
54
+ }
55
+ logs = [];
56
+ error = false;
57
+ }
58
+ });
59
+ return {
60
+ files,
61
+ error,
62
+ unsubscribe: () => {
63
+ reporterSubscription.unsubscribe();
64
+ lifecycleSubscription.unsubscribe();
65
+ },
66
+ };
67
+ }
68
+ exports.subscribeToWorkflow = subscribeToWorkflow;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.io/license
7
+ */
8
+ import { Argv } from 'yargs';
9
+ import { CommandModuleImplementation, Options, OtherOptions } from '../../command-builder/command-module';
10
+ import { SchematicsCommandArgs, SchematicsCommandModule } from '../../command-builder/schematics-command-module';
11
+ interface AddCommandArgs extends SchematicsCommandArgs {
12
+ collection: string;
13
+ verbose?: boolean;
14
+ registry?: string;
15
+ 'skip-confirmation'?: boolean;
16
+ }
17
+ export declare class AddCommandModule extends SchematicsCommandModule implements CommandModuleImplementation<AddCommandArgs> {
18
+ command: string;
19
+ describe: string;
20
+ longDescriptionPath: string;
21
+ protected allowPrivateSchematics: boolean;
22
+ private readonly schematicName;
23
+ builder(argv: Argv): Promise<Argv<AddCommandArgs>>;
24
+ run(options: Options<AddCommandArgs> & OtherOptions): Promise<number | void>;
25
+ private isProjectVersionValid;
26
+ reportAnalytics(options: OtherOptions, paths: string[]): Promise<void>;
27
+ private getCollectionName;
28
+ private isPackageInstalled;
29
+ private executeSchematic;
30
+ private findProjectVersion;
31
+ private hasMismatchedPeer;
32
+ }
33
+ export {};