|
6 | 6 | * found in the LICENSE file at https://angular.dev/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import { NodePackageDoesNotSupportSchematics } from '@angular-devkit/schematics/tools'; |
10 | 9 | import { Listr, ListrRenderer, ListrTaskWrapper, color, figures } from 'listr2'; |
11 | 10 | import assert from 'node:assert'; |
12 | 11 | import { createRequire } from 'node:module'; |
@@ -52,6 +51,8 @@ interface AddCommandTaskContext { |
52 | 51 | executeSchematic: AddCommandModule['executeSchematic']; |
53 | 52 | getPeerDependencyConflicts: AddCommandModule['getPeerDependencyConflicts']; |
54 | 53 | dryRun?: boolean; |
| 54 | + hasSchematics?: boolean; |
| 55 | + homepage?: string; |
55 | 56 | } |
56 | 57 |
|
57 | 58 | type AddCommandTaskWrapper = ListrTaskWrapper< |
@@ -217,8 +218,21 @@ export default class AddCommandModule |
217 | 218 | const result = await tasks.run(taskContext); |
218 | 219 | assert(result.collectionName, 'Collection name should always be available'); |
219 | 220 |
|
| 221 | + if (!result.hasSchematics) { |
| 222 | + let message = options.dryRun |
| 223 | + ? 'The package does not provide any `ng add` actions, so no further actions would be taken.' |
| 224 | + : 'Package installed successfully. The package does not provide any `ng add` actions, so no further actions were taken.'; |
| 225 | + |
| 226 | + if (result.homepage) { |
| 227 | + message += `\nFor more information about this package, visit its homepage at ${result.homepage}`; |
| 228 | + } |
| 229 | + logger.info(message); |
| 230 | + |
| 231 | + return; |
| 232 | + } |
| 233 | + |
220 | 234 | if (options.dryRun) { |
221 | | - logger.info('The package schematic would be executed next.'); |
| 235 | + logger.info("The package's `ng add` actions would be executed next."); |
222 | 236 |
|
223 | 237 | return; |
224 | 238 | } |
@@ -384,8 +398,10 @@ export default class AddCommandModule |
384 | 398 | ); |
385 | 399 | } |
386 | 400 |
|
| 401 | + context.hasSchematics = !!manifest.schematics; |
387 | 402 | context.savePackage = manifest['ng-add']?.save; |
388 | 403 | context.collectionName = manifest.name; |
| 404 | + context.homepage = manifest.homepage; |
389 | 405 |
|
390 | 406 | if (await this.getPeerDependencyConflicts(manifest)) { |
391 | 407 | task.output = color.yellow( |
@@ -534,46 +550,33 @@ export default class AddCommandModule |
534 | 550 | return false; |
535 | 551 | } |
536 | 552 |
|
537 | | - private async executeSchematic( |
| 553 | + private executeSchematic( |
538 | 554 | options: Options<AddCommandArgs> & OtherOptions, |
539 | 555 | ): Promise<number | void> { |
540 | | - try { |
541 | | - const { |
542 | | - verbose, |
543 | | - skipConfirmation, |
| 556 | + const { |
| 557 | + verbose, |
| 558 | + skipConfirmation, |
| 559 | + interactive, |
| 560 | + force, |
| 561 | + dryRun, |
| 562 | + registry, |
| 563 | + defaults, |
| 564 | + collection: collectionName, |
| 565 | + ...schematicOptions |
| 566 | + } = options; |
| 567 | + |
| 568 | + return this.runSchematic({ |
| 569 | + schematicOptions, |
| 570 | + schematicName: this.schematicName, |
| 571 | + collectionName, |
| 572 | + executionOptions: { |
544 | 573 | interactive, |
545 | 574 | force, |
546 | 575 | dryRun, |
547 | | - registry, |
548 | 576 | defaults, |
549 | | - collection: collectionName, |
550 | | - ...schematicOptions |
551 | | - } = options; |
552 | | - |
553 | | - return await this.runSchematic({ |
554 | | - schematicOptions, |
555 | | - schematicName: this.schematicName, |
556 | | - collectionName, |
557 | | - executionOptions: { |
558 | | - interactive, |
559 | | - force, |
560 | | - dryRun, |
561 | | - defaults, |
562 | | - packageRegistry: registry, |
563 | | - }, |
564 | | - }); |
565 | | - } catch (e) { |
566 | | - if (e instanceof NodePackageDoesNotSupportSchematics) { |
567 | | - this.context.logger.error( |
568 | | - 'The package that you are trying to add does not support schematics.' + |
569 | | - 'You can try using a different version of the package or contact the package author to add ng-add support.', |
570 | | - ); |
571 | | - |
572 | | - return 1; |
573 | | - } |
574 | | - |
575 | | - throw e; |
576 | | - } |
| 577 | + packageRegistry: registry, |
| 578 | + }, |
| 579 | + }); |
577 | 580 | } |
578 | 581 |
|
579 | 582 | private async findProjectVersion(name: string): Promise<string | null> { |
|
0 commit comments