dependency.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.dev/license
  7. */
  8. import { Rule } from '@angular-devkit/schematics';
  9. /**
  10. * An enum used to specify the type of a dependency found within a package manifest
  11. * file (`package.json`).
  12. */
  13. export declare enum DependencyType {
  14. Default = "dependencies",
  15. Dev = "devDependencies",
  16. Peer = "peerDependencies"
  17. }
  18. /**
  19. * An enum used to specify the dependency installation behavior for the {@link addDependency}
  20. * schematics rule. The installation behavior affects if and when {@link NodePackageInstallTask}
  21. * will be scheduled when using the rule.
  22. */
  23. export declare enum InstallBehavior {
  24. /**
  25. * No installation will occur as a result of the rule when specified.
  26. *
  27. * NOTE: This does not prevent other rules from scheduling a {@link NodePackageInstallTask}
  28. * which may install the dependency.
  29. */
  30. None = 0,
  31. /**
  32. * Automatically determine the need to schedule a {@link NodePackageInstallTask} based on
  33. * previous usage of the {@link addDependency} within the schematic.
  34. */
  35. Auto = 1,
  36. /**
  37. * Always schedule a {@link NodePackageInstallTask} when the rule is executed.
  38. */
  39. Always = 2
  40. }
  41. /**
  42. * An enum used to specify the existing dependency behavior for the {@link addDependency}
  43. * schematics rule. The existing behavior affects whether the named dependency will be added
  44. * to the `package.json` when the dependency is already present with a differing specifier.
  45. */
  46. export declare enum ExistingBehavior {
  47. /**
  48. * The dependency will not be added or otherwise changed if it already exists.
  49. */
  50. Skip = 0,
  51. /**
  52. * The dependency's existing specifier will be replaced with the specifier provided in the
  53. * {@link addDependency} call. A warning will also be shown during schematic execution to
  54. * notify the user of the replacement.
  55. */
  56. Replace = 1
  57. }
  58. /**
  59. * Adds a package as a dependency to a `package.json`. By default the `package.json` located
  60. * at the schematic's root will be used. The `manifestPath` option can be used to explicitly specify
  61. * a `package.json` in different location. The type of the dependency can also be specified instead
  62. * of the default of the `dependencies` section by using the `type` option for either `devDependencies`
  63. * or `peerDependencies`.
  64. *
  65. * When using this rule, {@link NodePackageInstallTask} does not need to be included directly by
  66. * a schematic. A package manager install task will be automatically scheduled as needed.
  67. *
  68. * @param name The name of the package to add.
  69. * @param specifier The package specifier for the package to add. Typically a SemVer range.
  70. * @param options An optional object that can contain the `type` of the dependency
  71. * and/or a path (`packageJsonPath`) of a manifest file (`package.json`) to modify.
  72. * @returns A Schematics {@link Rule}
  73. */
  74. export declare function addDependency(name: string, specifier: string, options?: {
  75. /**
  76. * The type of the dependency determines the section of the `package.json` to which the
  77. * dependency will be added. Defaults to {@link DependencyType.Default} (`dependencies`).
  78. */
  79. type?: DependencyType;
  80. /**
  81. * The path of the package manifest file (`package.json`) that will be modified.
  82. * Defaults to `/package.json`.
  83. */
  84. packageJsonPath?: string;
  85. /**
  86. * The dependency installation behavior to use to determine whether a
  87. * {@link NodePackageInstallTask} should be scheduled after adding the dependency.
  88. * Defaults to {@link InstallBehavior.Auto}.
  89. */
  90. install?: InstallBehavior;
  91. /**
  92. * The behavior to use when the dependency already exists within the `package.json`.
  93. * Defaults to {@link ExistingBehavior.Replace}.
  94. */
  95. existing?: ExistingBehavior;
  96. }): Rule;