@angular/cli 18.1.0-next.3 → 18.1.0-rc.1

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.
@@ -22,11 +22,39 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
22
22
  }) : function(o, v) {
23
23
  o["default"] = v;
24
24
  });
25
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
26
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
27
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
28
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
29
- return c > 3 && r && Object.defineProperty(target, key, r), r;
25
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
26
+ var useValue = arguments.length > 2;
27
+ for (var i = 0; i < initializers.length; i++) {
28
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
29
+ }
30
+ return useValue ? value : void 0;
31
+ };
32
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
33
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
34
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
35
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
36
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
37
+ var _, done = false;
38
+ for (var i = decorators.length - 1; i >= 0; i--) {
39
+ var context = {};
40
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
41
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
42
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
43
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
44
+ if (kind === "accessor") {
45
+ if (result === void 0) continue;
46
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
47
+ if (_ = accept(result.get)) descriptor.get = _;
48
+ if (_ = accept(result.set)) descriptor.set = _;
49
+ if (_ = accept(result.init)) initializers.unshift(_);
50
+ }
51
+ else if (_ = accept(result)) {
52
+ if (kind === "field") initializers.unshift(_);
53
+ else descriptor[key] = _;
54
+ }
55
+ }
56
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
57
+ done = true;
30
58
  };
31
59
  var __importStar = (this && this.__importStar) || function (mod) {
32
60
  if (mod && mod.__esModule) return mod;
@@ -35,9 +63,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
35
63
  __setModuleDefault(result, mod);
36
64
  return result;
37
65
  };
38
- var __metadata = (this && this.__metadata) || function (k, v) {
39
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
40
- };
41
66
  var __importDefault = (this && this.__importDefault) || function (mod) {
42
67
  return (mod && mod.__esModule) ? mod : { "default": mod };
43
68
  };
@@ -62,213 +87,217 @@ var CommandScope;
62
87
  /** Command can run inside and outside an Angular workspace. */
63
88
  CommandScope[CommandScope["Both"] = 2] = "Both";
64
89
  })(CommandScope || (exports.CommandScope = CommandScope = {}));
65
- class CommandModule {
66
- context;
67
- shouldReportAnalytics = true;
68
- scope = CommandScope.Both;
69
- optionsWithAnalytics = new Map();
70
- constructor(context) {
71
- this.context = context;
72
- }
73
- /**
74
- * Description object which contains the long command descroption.
75
- * This is used to generate JSON help wich is used in AIO.
76
- *
77
- * `false` will result in a hidden command.
78
- */
79
- get fullDescribe() {
80
- return this.describe === false
81
- ? false
82
- : {
83
- describe: this.describe,
84
- ...(this.longDescriptionPath
85
- ? {
86
- longDescriptionRelativePath: path
87
- .relative(path.join(__dirname, '../../../../'), this.longDescriptionPath)
88
- .replace(/\\/g, path.posix.sep),
89
- longDescription: (0, fs_1.readFileSync)(this.longDescriptionPath, 'utf8').replace(/\r\n/g, '\n'),
90
- }
91
- : {}),
92
- };
93
- }
94
- get commandName() {
95
- return this.command.split(' ', 1)[0];
96
- }
97
- async handler(args) {
98
- const { _, $0, ...options } = args;
99
- // Camelize options as yargs will return the object in kebab-case when camel casing is disabled.
100
- const camelCasedOptions = {};
101
- for (const [key, value] of Object.entries(options)) {
102
- camelCasedOptions[helpers_1.Parser.camelCase(key)] = value;
90
+ let CommandModule = (() => {
91
+ let _instanceExtraInitializers = [];
92
+ let _getAnalytics_decorators;
93
+ return class CommandModule {
94
+ static {
95
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
96
+ _getAnalytics_decorators = [memoize_1.memoize];
97
+ __esDecorate(this, null, _getAnalytics_decorators, { kind: "method", name: "getAnalytics", static: false, private: false, access: { has: obj => "getAnalytics" in obj, get: obj => obj.getAnalytics }, metadata: _metadata }, null, _instanceExtraInitializers);
98
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
103
99
  }
104
- // Set up autocompletion if appropriate.
105
- const autocompletionExitCode = await (0, completion_1.considerSettingUpAutocompletion)(this.commandName, this.context.logger);
106
- if (autocompletionExitCode !== undefined) {
107
- process.exitCode = autocompletionExitCode;
108
- return;
100
+ context = __runInitializers(this, _instanceExtraInitializers);
101
+ shouldReportAnalytics = true;
102
+ scope = CommandScope.Both;
103
+ optionsWithAnalytics = new Map();
104
+ constructor(context) {
105
+ this.context = context;
109
106
  }
110
- // Gather and report analytics.
111
- const analytics = await this.getAnalytics();
112
- const stopPeriodicFlushes = analytics && analytics.periodFlush();
113
- let exitCode;
114
- try {
115
- if (analytics) {
116
- this.reportCommandRunAnalytics(analytics);
117
- this.reportWorkspaceInfoAnalytics(analytics);
118
- }
119
- exitCode = await this.run(camelCasedOptions);
107
+ /**
108
+ * Description object which contains the long command descroption.
109
+ * This is used to generate JSON help wich is used in AIO.
110
+ *
111
+ * `false` will result in a hidden command.
112
+ */
113
+ get fullDescribe() {
114
+ return this.describe === false
115
+ ? false
116
+ : {
117
+ describe: this.describe,
118
+ ...(this.longDescriptionPath
119
+ ? {
120
+ longDescriptionRelativePath: path
121
+ .relative(path.join(__dirname, '../../../../'), this.longDescriptionPath)
122
+ .replace(/\\/g, path.posix.sep),
123
+ longDescription: (0, fs_1.readFileSync)(this.longDescriptionPath, 'utf8').replace(/\r\n/g, '\n'),
124
+ }
125
+ : {}),
126
+ };
120
127
  }
121
- catch (e) {
122
- if (e instanceof core_1.schema.SchemaValidationException) {
123
- this.context.logger.fatal(`Error: ${e.message}`);
124
- exitCode = 1;
125
- }
126
- else {
127
- throw e;
128
- }
128
+ get commandName() {
129
+ return this.command.split(' ', 1)[0];
129
130
  }
130
- finally {
131
- await stopPeriodicFlushes?.();
132
- if (typeof exitCode === 'number' && exitCode > 0) {
133
- process.exitCode = exitCode;
131
+ async handler(args) {
132
+ const { _, $0, ...options } = args;
133
+ // Camelize options as yargs will return the object in kebab-case when camel casing is disabled.
134
+ const camelCasedOptions = {};
135
+ for (const [key, value] of Object.entries(options)) {
136
+ camelCasedOptions[helpers_1.Parser.camelCase(key)] = value;
134
137
  }
135
- }
136
- }
137
- async getAnalytics() {
138
- if (!this.shouldReportAnalytics) {
139
- return undefined;
140
- }
141
- const userId = await (0, analytics_1.getAnalyticsUserId)(this.context,
142
- // Don't prompt on `ng update`, 'ng version' or `ng analytics`.
143
- ['version', 'update', 'analytics'].includes(this.commandName));
144
- return userId ? new analytics_collector_1.AnalyticsCollector(this.context, userId) : undefined;
145
- }
146
- /**
147
- * Adds schema options to a command also this keeps track of options that are required for analytics.
148
- * **Note:** This method should be called from the command bundler method.
149
- */
150
- addSchemaOptionsToCommand(localYargs, options) {
151
- const booleanOptionsWithNoPrefix = new Set();
152
- for (const option of options) {
153
- const { default: defaultVal, positional, deprecated, description, alias, userAnalytics, type, hidden, name, choices, } = option;
154
- const sharedOptions = {
155
- alias,
156
- hidden,
157
- description,
158
- deprecated,
159
- choices,
160
- // This should only be done when `--help` is used otherwise default will override options set in angular.json.
161
- ...(this.context.args.options.help ? { default: defaultVal } : {}),
162
- };
163
- let dashedName = core_1.strings.dasherize(name);
164
- // Handle options which have been defined in the schema with `no` prefix.
165
- if (type === 'boolean' && dashedName.startsWith('no-')) {
166
- dashedName = dashedName.slice(3);
167
- booleanOptionsWithNoPrefix.add(dashedName);
138
+ // Set up autocompletion if appropriate.
139
+ const autocompletionExitCode = await (0, completion_1.considerSettingUpAutocompletion)(this.commandName, this.context.logger);
140
+ if (autocompletionExitCode !== undefined) {
141
+ process.exitCode = autocompletionExitCode;
142
+ return;
168
143
  }
169
- if (positional === undefined) {
170
- localYargs = localYargs.option(dashedName, {
171
- type,
172
- ...sharedOptions,
173
- });
144
+ // Gather and report analytics.
145
+ const analytics = await this.getAnalytics();
146
+ const stopPeriodicFlushes = analytics && analytics.periodFlush();
147
+ let exitCode;
148
+ try {
149
+ if (analytics) {
150
+ this.reportCommandRunAnalytics(analytics);
151
+ this.reportWorkspaceInfoAnalytics(analytics);
152
+ }
153
+ exitCode = await this.run(camelCasedOptions);
154
+ }
155
+ catch (e) {
156
+ if (e instanceof core_1.schema.SchemaValidationException) {
157
+ this.context.logger.fatal(`Error: ${e.message}`);
158
+ exitCode = 1;
159
+ }
160
+ else {
161
+ throw e;
162
+ }
174
163
  }
175
- else {
176
- localYargs = localYargs.positional(dashedName, {
177
- type: type === 'array' || type === 'count' ? 'string' : type,
178
- ...sharedOptions,
179
- });
164
+ finally {
165
+ await stopPeriodicFlushes?.();
166
+ if (typeof exitCode === 'number' && exitCode > 0) {
167
+ process.exitCode = exitCode;
168
+ }
180
169
  }
181
- // Record option of analytics.
182
- if (userAnalytics !== undefined) {
183
- this.optionsWithAnalytics.set(name, userAnalytics);
170
+ }
171
+ async getAnalytics() {
172
+ if (!this.shouldReportAnalytics) {
173
+ return undefined;
184
174
  }
175
+ const userId = await (0, analytics_1.getAnalyticsUserId)(this.context,
176
+ // Don't prompt on `ng update`, 'ng version' or `ng analytics`.
177
+ ['version', 'update', 'analytics'].includes(this.commandName));
178
+ return userId ? new analytics_collector_1.AnalyticsCollector(this.context, userId) : undefined;
185
179
  }
186
- // Handle options which have been defined in the schema with `no` prefix.
187
- if (booleanOptionsWithNoPrefix.size) {
188
- localYargs.middleware((options) => {
189
- for (const key of booleanOptionsWithNoPrefix) {
190
- if (key in options) {
191
- options[`no-${key}`] = !options[key];
192
- delete options[key];
193
- }
180
+ /**
181
+ * Adds schema options to a command also this keeps track of options that are required for analytics.
182
+ * **Note:** This method should be called from the command bundler method.
183
+ */
184
+ addSchemaOptionsToCommand(localYargs, options) {
185
+ const booleanOptionsWithNoPrefix = new Set();
186
+ for (const option of options) {
187
+ const { default: defaultVal, positional, deprecated, description, alias, userAnalytics, type, hidden, name, choices, } = option;
188
+ const sharedOptions = {
189
+ alias,
190
+ hidden,
191
+ description,
192
+ deprecated,
193
+ choices,
194
+ // This should only be done when `--help` is used otherwise default will override options set in angular.json.
195
+ ...(this.context.args.options.help ? { default: defaultVal } : {}),
196
+ };
197
+ let dashedName = core_1.strings.dasherize(name);
198
+ // Handle options which have been defined in the schema with `no` prefix.
199
+ if (type === 'boolean' && dashedName.startsWith('no-')) {
200
+ dashedName = dashedName.slice(3);
201
+ booleanOptionsWithNoPrefix.add(dashedName);
202
+ }
203
+ if (positional === undefined) {
204
+ localYargs = localYargs.option(dashedName, {
205
+ type,
206
+ ...sharedOptions,
207
+ });
208
+ }
209
+ else {
210
+ localYargs = localYargs.positional(dashedName, {
211
+ type: type === 'array' || type === 'count' ? 'string' : type,
212
+ ...sharedOptions,
213
+ });
194
214
  }
195
- }, false);
215
+ // Record option of analytics.
216
+ if (userAnalytics !== undefined) {
217
+ this.optionsWithAnalytics.set(name, userAnalytics);
218
+ }
219
+ }
220
+ // Handle options which have been defined in the schema with `no` prefix.
221
+ if (booleanOptionsWithNoPrefix.size) {
222
+ localYargs.middleware((options) => {
223
+ for (const key of booleanOptionsWithNoPrefix) {
224
+ if (key in options) {
225
+ options[`no-${key}`] = !options[key];
226
+ delete options[key];
227
+ }
228
+ }
229
+ }, false);
230
+ }
231
+ return localYargs;
196
232
  }
197
- return localYargs;
198
- }
199
- getWorkspaceOrThrow() {
200
- const { workspace } = this.context;
201
- if (!workspace) {
202
- throw new CommandModuleError('A workspace is required for this command.');
233
+ getWorkspaceOrThrow() {
234
+ const { workspace } = this.context;
235
+ if (!workspace) {
236
+ throw new CommandModuleError('A workspace is required for this command.');
237
+ }
238
+ return workspace;
203
239
  }
204
- return workspace;
205
- }
206
- /**
207
- * Flush on an interval (if the event loop is waiting).
208
- *
209
- * @returns a method that when called will terminate the periodic
210
- * flush and call flush one last time.
211
- */
212
- getAnalyticsParameters(options) {
213
- const parameters = {};
214
- const validEventCustomDimensionAndMetrics = new Set([
215
- ...Object.values(analytics_parameters_1.EventCustomDimension),
216
- ...Object.values(analytics_parameters_1.EventCustomMetric),
217
- ]);
218
- for (const [name, ua] of this.optionsWithAnalytics) {
219
- const value = options[name];
220
- if ((typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') &&
221
- validEventCustomDimensionAndMetrics.has(ua)) {
222
- parameters[ua] = value;
240
+ /**
241
+ * Flush on an interval (if the event loop is waiting).
242
+ *
243
+ * @returns a method that when called will terminate the periodic
244
+ * flush and call flush one last time.
245
+ */
246
+ getAnalyticsParameters(options) {
247
+ const parameters = {};
248
+ const validEventCustomDimensionAndMetrics = new Set([
249
+ ...Object.values(analytics_parameters_1.EventCustomDimension),
250
+ ...Object.values(analytics_parameters_1.EventCustomMetric),
251
+ ]);
252
+ for (const [name, ua] of this.optionsWithAnalytics) {
253
+ const value = options[name];
254
+ if ((typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') &&
255
+ validEventCustomDimensionAndMetrics.has(ua)) {
256
+ parameters[ua] = value;
257
+ }
223
258
  }
259
+ return parameters;
224
260
  }
225
- return parameters;
226
- }
227
- reportCommandRunAnalytics(analytics) {
228
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
229
- const internalMethods = yargs_1.default.getInternalMethods();
230
- // $0 generate component [name] -> generate_component
231
- // $0 add <collection> -> add
232
- const fullCommand = internalMethods.getUsageInstance().getUsage()[0][0]
233
- .split(' ')
234
- .filter((x) => {
235
- const code = x.charCodeAt(0);
236
- return code >= 97 && code <= 122;
237
- })
238
- .join('_');
239
- analytics.reportCommandRunEvent(fullCommand);
240
- }
241
- reportWorkspaceInfoAnalytics(analytics) {
242
- const { workspace } = this.context;
243
- if (!workspace) {
244
- return;
261
+ reportCommandRunAnalytics(analytics) {
262
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
263
+ const internalMethods = yargs_1.default.getInternalMethods();
264
+ // $0 generate component [name] -> generate_component
265
+ // $0 add <collection> -> add
266
+ const fullCommand = internalMethods.getUsageInstance().getUsage()[0][0]
267
+ .split(' ')
268
+ .filter((x) => {
269
+ const code = x.charCodeAt(0);
270
+ return code >= 97 && code <= 122;
271
+ })
272
+ .join('_');
273
+ analytics.reportCommandRunEvent(fullCommand);
245
274
  }
246
- let applicationProjectsCount = 0;
247
- let librariesProjectsCount = 0;
248
- for (const project of workspace.projects.values()) {
249
- switch (project.extensions['projectType']) {
250
- case 'application':
251
- applicationProjectsCount++;
252
- break;
253
- case 'library':
254
- librariesProjectsCount++;
255
- break;
275
+ reportWorkspaceInfoAnalytics(analytics) {
276
+ const { workspace } = this.context;
277
+ if (!workspace) {
278
+ return;
279
+ }
280
+ let applicationProjectsCount = 0;
281
+ let librariesProjectsCount = 0;
282
+ for (const project of workspace.projects.values()) {
283
+ switch (project.extensions['projectType']) {
284
+ case 'application':
285
+ applicationProjectsCount++;
286
+ break;
287
+ case 'library':
288
+ librariesProjectsCount++;
289
+ break;
290
+ }
256
291
  }
292
+ analytics.reportWorkspaceInfoEvent({
293
+ [analytics_parameters_1.EventCustomMetric.AllProjectsCount]: librariesProjectsCount + applicationProjectsCount,
294
+ [analytics_parameters_1.EventCustomMetric.ApplicationProjectsCount]: applicationProjectsCount,
295
+ [analytics_parameters_1.EventCustomMetric.LibraryProjectsCount]: librariesProjectsCount,
296
+ });
257
297
  }
258
- analytics.reportWorkspaceInfoEvent({
259
- [analytics_parameters_1.EventCustomMetric.AllProjectsCount]: librariesProjectsCount + applicationProjectsCount,
260
- [analytics_parameters_1.EventCustomMetric.ApplicationProjectsCount]: applicationProjectsCount,
261
- [analytics_parameters_1.EventCustomMetric.LibraryProjectsCount]: librariesProjectsCount,
262
- });
263
- }
264
- }
298
+ };
299
+ })();
265
300
  exports.CommandModule = CommandModule;
266
- __decorate([
267
- memoize_1.memoize,
268
- __metadata("design:type", Function),
269
- __metadata("design:paramtypes", []),
270
- __metadata("design:returntype", Promise)
271
- ], CommandModule.prototype, "getAnalytics", null);
272
301
  /**
273
302
  * Creates an known command module error.
274
303
  * This is used so during executation we can filter between known validation error and real non handled errors.