@angular/cli 21.0.0-next.1 → 21.0.0-next.10

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 (223) hide show
  1. package/lib/cli/index.js +1 -0
  2. package/lib/cli/index.js.map +1 -0
  3. package/lib/code-examples.db +0 -0
  4. package/lib/config/schema.json +272 -46
  5. package/lib/config/workspace-schema.d.ts +55 -0
  6. package/lib/config/workspace-schema.js +22 -1
  7. package/lib/config/workspace-schema.js.map +1 -0
  8. package/lib/init.js +1 -0
  9. package/lib/init.js.map +1 -0
  10. package/package.json +24 -23
  11. package/src/analytics/analytics-collector.js +1 -0
  12. package/src/analytics/analytics-collector.js.map +1 -0
  13. package/src/analytics/analytics-parameters.js +1 -0
  14. package/src/analytics/analytics-parameters.js.map +1 -0
  15. package/src/analytics/analytics.js +1 -0
  16. package/src/analytics/analytics.js.map +1 -0
  17. package/src/command-builder/architect-base-command-module.js +1 -0
  18. package/src/command-builder/architect-base-command-module.js.map +1 -0
  19. package/src/command-builder/architect-command-module.js +21 -7
  20. package/src/command-builder/architect-command-module.js.map +1 -0
  21. package/src/command-builder/command-module.js +1 -0
  22. package/src/command-builder/command-module.js.map +1 -0
  23. package/src/command-builder/command-runner.js +2 -2
  24. package/src/command-builder/command-runner.js.map +1 -0
  25. package/src/command-builder/schematics-command-module.js +1 -0
  26. package/src/command-builder/schematics-command-module.js.map +1 -0
  27. package/src/command-builder/utilities/command.js +1 -0
  28. package/src/command-builder/utilities/command.js.map +1 -0
  29. package/src/command-builder/utilities/json-help.js +1 -0
  30. package/src/command-builder/utilities/json-help.js.map +1 -0
  31. package/src/command-builder/utilities/json-schema.d.ts +13 -1
  32. package/src/command-builder/utilities/json-schema.js +180 -100
  33. package/src/command-builder/utilities/json-schema.js.map +1 -0
  34. package/src/command-builder/utilities/normalize-options-middleware.js +1 -0
  35. package/src/command-builder/utilities/normalize-options-middleware.js.map +1 -0
  36. package/src/command-builder/utilities/schematic-engine-host.js +1 -0
  37. package/src/command-builder/utilities/schematic-engine-host.js.map +1 -0
  38. package/src/command-builder/utilities/schematic-workflow.js +1 -0
  39. package/src/command-builder/utilities/schematic-workflow.js.map +1 -0
  40. package/src/commands/add/cli.js +66 -26
  41. package/src/commands/add/cli.js.map +1 -0
  42. package/src/commands/analytics/cli.js +1 -0
  43. package/src/commands/analytics/cli.js.map +1 -0
  44. package/src/commands/analytics/info/cli.js +1 -0
  45. package/src/commands/analytics/info/cli.js.map +1 -0
  46. package/src/commands/analytics/settings/cli.js +1 -0
  47. package/src/commands/analytics/settings/cli.js.map +1 -0
  48. package/src/commands/build/cli.js +1 -0
  49. package/src/commands/build/cli.js.map +1 -0
  50. package/src/commands/cache/clean/cli.js +1 -0
  51. package/src/commands/cache/clean/cli.js.map +1 -0
  52. package/src/commands/cache/cli.js +1 -0
  53. package/src/commands/cache/cli.js.map +1 -0
  54. package/src/commands/cache/info/cli.js +36 -11
  55. package/src/commands/cache/info/cli.js.map +1 -0
  56. package/src/commands/cache/settings/cli.js +1 -0
  57. package/src/commands/cache/settings/cli.js.map +1 -0
  58. package/src/commands/cache/utilities.js +1 -0
  59. package/src/commands/cache/utilities.js.map +1 -0
  60. package/src/commands/command-config.js +1 -0
  61. package/src/commands/command-config.js.map +1 -0
  62. package/src/commands/completion/cli.js +1 -0
  63. package/src/commands/completion/cli.js.map +1 -0
  64. package/src/commands/config/cli.js +1 -0
  65. package/src/commands/config/cli.js.map +1 -0
  66. package/src/commands/deploy/cli.js +1 -0
  67. package/src/commands/deploy/cli.js.map +1 -0
  68. package/src/commands/e2e/cli.js +1 -0
  69. package/src/commands/e2e/cli.js.map +1 -0
  70. package/src/commands/extract-i18n/cli.js +1 -0
  71. package/src/commands/extract-i18n/cli.js.map +1 -0
  72. package/src/commands/generate/cli.js +1 -0
  73. package/src/commands/generate/cli.js.map +1 -0
  74. package/src/commands/lint/cli.js +1 -0
  75. package/src/commands/lint/cli.js.map +1 -0
  76. package/src/commands/make-this-awesome/cli.js +1 -0
  77. package/src/commands/make-this-awesome/cli.js.map +1 -0
  78. package/src/commands/mcp/cli.js +1 -0
  79. package/src/commands/mcp/cli.js.map +1 -0
  80. package/src/commands/mcp/constants.d.ts +1 -1
  81. package/src/commands/mcp/constants.js +2 -1
  82. package/src/commands/mcp/constants.js.map +1 -0
  83. package/src/commands/mcp/mcp-server.d.ts +3 -3
  84. package/src/commands/mcp/mcp-server.js +40 -4
  85. package/src/commands/mcp/mcp-server.js.map +1 -0
  86. package/src/commands/mcp/resources/ai-tutor.md +627 -0
  87. package/src/commands/mcp/resources/instructions.js +1 -0
  88. package/src/commands/mcp/resources/instructions.js.map +1 -0
  89. package/src/commands/mcp/tools/ai-tutor.d.ts +8 -0
  90. package/src/commands/mcp/tools/ai-tutor.js +62 -0
  91. package/src/commands/mcp/tools/ai-tutor.js.map +1 -0
  92. package/src/commands/mcp/tools/best-practices.d.ts +4 -1
  93. package/src/commands/mcp/tools/best-practices.js +167 -22
  94. package/src/commands/mcp/tools/best-practices.js.map +1 -0
  95. package/src/commands/mcp/tools/doc-search.d.ts +20 -1
  96. package/src/commands/mcp/tools/doc-search.js +186 -67
  97. package/src/commands/mcp/tools/doc-search.js.map +1 -0
  98. package/src/commands/mcp/tools/examples.d.ts +35 -1
  99. package/src/commands/mcp/tools/examples.js +414 -56
  100. package/src/commands/mcp/tools/examples.js.map +1 -0
  101. package/src/commands/mcp/tools/modernize.js +29 -17
  102. package/src/commands/mcp/tools/modernize.js.map +1 -0
  103. package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.d.ts +17 -0
  104. package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.js +62 -0
  105. package/src/commands/mcp/tools/onpush-zoneless-migration/analyze_for_unsupported_zone_uses.js.map +1 -0
  106. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.d.ts +12 -0
  107. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.js +73 -0
  108. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_single_file.js.map +1 -0
  109. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.d.ts +11 -0
  110. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.js +106 -0
  111. package/src/commands/mcp/tools/onpush-zoneless-migration/migrate_test_file.js.map +1 -0
  112. package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.d.ts +15 -0
  113. package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.js +238 -0
  114. package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.js.map +1 -0
  115. package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.d.ts +10 -0
  116. package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.js +20 -0
  117. package/src/commands/mcp/tools/onpush-zoneless-migration/send_debug_message.js.map +1 -0
  118. package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.d.ts +36 -0
  119. package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.js +136 -0
  120. package/src/commands/mcp/tools/onpush-zoneless-migration/ts_utils.js.map +1 -0
  121. package/src/commands/mcp/tools/onpush-zoneless-migration/types.d.ts +13 -0
  122. package/src/commands/mcp/tools/onpush-zoneless-migration/types.js +10 -0
  123. package/src/commands/mcp/tools/onpush-zoneless-migration/types.js.map +1 -0
  124. package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.d.ts +14 -0
  125. package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.js +228 -0
  126. package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.js.map +1 -0
  127. package/src/commands/mcp/tools/projects.d.ts +75 -16
  128. package/src/commands/mcp/tools/projects.js +427 -30
  129. package/src/commands/mcp/tools/projects.js.map +1 -0
  130. package/src/commands/mcp/tools/tool-registry.d.ts +2 -1
  131. package/src/commands/mcp/tools/tool-registry.js +4 -2
  132. package/src/commands/mcp/tools/tool-registry.js.map +1 -0
  133. package/src/commands/new/cli.js +2 -0
  134. package/src/commands/new/cli.js.map +1 -0
  135. package/src/commands/run/cli.js +1 -0
  136. package/src/commands/run/cli.js.map +1 -0
  137. package/src/commands/serve/cli.js +1 -0
  138. package/src/commands/serve/cli.js.map +1 -0
  139. package/src/commands/test/cli.js +1 -0
  140. package/src/commands/test/cli.js.map +1 -0
  141. package/src/commands/update/cli.js +1 -0
  142. package/src/commands/update/cli.js.map +1 -0
  143. package/src/commands/update/schematic/index.js +1 -0
  144. package/src/commands/update/schematic/index.js.map +1 -0
  145. package/src/commands/update/schematic/schema.js +1 -0
  146. package/src/commands/update/schematic/schema.js.map +1 -0
  147. package/src/commands/version/cli.d.ts +3 -7
  148. package/src/commands/version/cli.js +50 -49
  149. package/src/commands/version/cli.js.map +1 -0
  150. package/src/commands/version/version-info.d.ts +28 -10
  151. package/src/commands/version/version-info.js +34 -50
  152. package/src/commands/version/version-info.js.map +1 -0
  153. package/src/package-managers/discovery.d.ts +23 -0
  154. package/src/package-managers/discovery.js +110 -0
  155. package/src/package-managers/discovery.js.map +1 -0
  156. package/src/package-managers/error.d.ts +31 -0
  157. package/src/package-managers/error.js +41 -0
  158. package/src/package-managers/error.js.map +1 -0
  159. package/src/package-managers/factory.d.ts +25 -0
  160. package/src/package-managers/factory.js +123 -0
  161. package/src/package-managers/factory.js.map +1 -0
  162. package/src/package-managers/host.d.ts +64 -0
  163. package/src/package-managers/host.js +69 -0
  164. package/src/package-managers/host.js.map +1 -0
  165. package/src/package-managers/index.d.ts +12 -0
  166. package/src/package-managers/index.js +15 -0
  167. package/src/package-managers/index.js.map +1 -0
  168. package/src/package-managers/logger.d.ts +27 -0
  169. package/src/package-managers/logger.js +10 -0
  170. package/src/package-managers/logger.js.map +1 -0
  171. package/src/package-managers/package-manager-descriptor.d.ts +204 -0
  172. package/src/package-managers/package-manager-descriptor.js +147 -0
  173. package/src/package-managers/package-manager-descriptor.js.map +1 -0
  174. package/src/package-managers/package-manager.d.ts +144 -0
  175. package/src/package-managers/package-manager.js +304 -0
  176. package/src/package-managers/package-manager.js.map +1 -0
  177. package/src/package-managers/package-metadata.d.ts +87 -0
  178. package/src/package-managers/package-metadata.js +10 -0
  179. package/src/package-managers/package-metadata.js.map +1 -0
  180. package/src/package-managers/package-tree.d.ts +23 -0
  181. package/src/package-managers/package-tree.js +10 -0
  182. package/src/package-managers/package-tree.js.map +1 -0
  183. package/src/package-managers/parsers.d.ts +92 -0
  184. package/src/package-managers/parsers.js +234 -0
  185. package/src/package-managers/parsers.js.map +1 -0
  186. package/src/package-managers/testing/mock-host.d.ts +26 -0
  187. package/src/package-managers/testing/mock-host.js +53 -0
  188. package/src/package-managers/testing/mock-host.js.map +1 -0
  189. package/src/utilities/color.js +1 -0
  190. package/src/utilities/color.js.map +1 -0
  191. package/src/utilities/completion.js +1 -0
  192. package/src/utilities/completion.js.map +1 -0
  193. package/src/utilities/config.js +1 -0
  194. package/src/utilities/config.js.map +1 -0
  195. package/src/utilities/environment-options.js +1 -0
  196. package/src/utilities/environment-options.js.map +1 -0
  197. package/src/utilities/eol.js +1 -0
  198. package/src/utilities/eol.js.map +1 -0
  199. package/src/utilities/error.js +1 -0
  200. package/src/utilities/error.js.map +1 -0
  201. package/src/utilities/find-up.js +1 -0
  202. package/src/utilities/find-up.js.map +1 -0
  203. package/src/utilities/json-file.js +1 -0
  204. package/src/utilities/json-file.js.map +1 -0
  205. package/src/utilities/log-file.js +1 -0
  206. package/src/utilities/log-file.js.map +1 -0
  207. package/src/utilities/memoize.js +1 -0
  208. package/src/utilities/memoize.js.map +1 -0
  209. package/src/utilities/package-manager.d.ts +12 -0
  210. package/src/utilities/package-manager.js +52 -35
  211. package/src/utilities/package-manager.js.map +1 -0
  212. package/src/utilities/package-metadata.js +1 -0
  213. package/src/utilities/package-metadata.js.map +1 -0
  214. package/src/utilities/package-tree.js +1 -0
  215. package/src/utilities/package-tree.js.map +1 -0
  216. package/src/utilities/project.js +1 -0
  217. package/src/utilities/project.js.map +1 -0
  218. package/src/utilities/prompt.js +1 -0
  219. package/src/utilities/prompt.js.map +1 -0
  220. package/src/utilities/tty.js +1 -0
  221. package/src/utilities/tty.js.map +1 -0
  222. package/src/utilities/version.js +2 -1
  223. package/src/utilities/version.js.map +1 -0
@@ -0,0 +1,147 @@
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.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PACKAGE_MANAGER_PRECEDENCE = exports.SUPPORTED_PACKAGE_MANAGERS = void 0;
11
+ const parsers_1 = require("./parsers");
12
+ /**
13
+ * A map of supported package managers to their descriptors.
14
+ * This is the single source of truth for all package-manager-specific
15
+ * configuration and behavior.
16
+ *
17
+ * Each descriptor is intentionally explicit and self-contained. This approach
18
+ * avoids inheritance or fallback logic between package managers, ensuring that
19
+ * the behavior for each one is clear, predictable, and easy to modify in
20
+ * isolation. For example, `yarn-classic` does not inherit any properties from
21
+ * the `yarn` descriptor; it is a complete and independent definition.
22
+ */
23
+ exports.SUPPORTED_PACKAGE_MANAGERS = {
24
+ npm: {
25
+ binary: 'npm',
26
+ lockfiles: ['package-lock.json', 'npm-shrinkwrap.json'],
27
+ addCommand: 'install',
28
+ installCommand: ['install'],
29
+ forceFlag: '--force',
30
+ saveExactFlag: '--save-exact',
31
+ saveTildeFlag: '--save-tilde',
32
+ saveDevFlag: '--save-dev',
33
+ noLockfileFlag: '--no-package-lock',
34
+ ignoreScriptsFlag: '--ignore-scripts',
35
+ getRegistryOptions: (registry) => ({ args: ['--registry', registry] }),
36
+ versionCommand: ['--version'],
37
+ listDependenciesCommand: ['list', '--depth=0', '--json=true', '--all=true'],
38
+ getManifestCommand: ['view', '--json'],
39
+ viewCommandFieldArgFormatter: (fields) => [...fields],
40
+ outputParsers: {
41
+ listDependencies: parsers_1.parseNpmLikeDependencies,
42
+ getPackageManifest: parsers_1.parseNpmLikeManifest,
43
+ getRegistryMetadata: parsers_1.parseNpmLikeMetadata,
44
+ },
45
+ },
46
+ yarn: {
47
+ binary: 'yarn',
48
+ lockfiles: ['yarn.lock'],
49
+ addCommand: 'add',
50
+ installCommand: ['install'],
51
+ forceFlag: '--force',
52
+ saveExactFlag: '--exact',
53
+ saveTildeFlag: '--tilde',
54
+ saveDevFlag: '--dev',
55
+ noLockfileFlag: '--no-lockfile',
56
+ ignoreScriptsFlag: '--ignore-scripts',
57
+ getRegistryOptions: (registry) => ({ env: { NPM_CONFIG_REGISTRY: registry } }),
58
+ versionCommand: ['--version'],
59
+ listDependenciesCommand: ['list', '--depth=0', '--json', '--recursive=false'],
60
+ getManifestCommand: ['npm', 'info', '--json'],
61
+ viewCommandFieldArgFormatter: (fields) => ['--fields', fields.join(',')],
62
+ outputParsers: {
63
+ listDependencies: parsers_1.parseYarnModernDependencies,
64
+ getPackageManifest: parsers_1.parseNpmLikeManifest,
65
+ getRegistryMetadata: parsers_1.parseNpmLikeMetadata,
66
+ },
67
+ },
68
+ 'yarn-classic': {
69
+ binary: 'yarn',
70
+ // This is intentionally empty. `yarn-classic` is not a discoverable package manager.
71
+ // The discovery process finds `yarn` via `yarn.lock`, and the factory logic
72
+ // determines whether it is classic or modern by checking the installed version.
73
+ lockfiles: [],
74
+ addCommand: 'add',
75
+ installCommand: ['install'],
76
+ forceFlag: '--force',
77
+ saveExactFlag: '--exact',
78
+ saveTildeFlag: '--tilde',
79
+ saveDevFlag: '--dev',
80
+ noLockfileFlag: '--no-lockfile',
81
+ ignoreScriptsFlag: '--ignore-scripts',
82
+ getRegistryOptions: (registry) => ({ args: ['--registry', registry] }),
83
+ versionCommand: ['--version'],
84
+ listDependenciesCommand: ['list', '--depth=0', '--json'],
85
+ getManifestCommand: ['info', '--json'],
86
+ outputParsers: {
87
+ listDependencies: parsers_1.parseYarnClassicDependencies,
88
+ getPackageManifest: parsers_1.parseYarnLegacyManifest,
89
+ getRegistryMetadata: parsers_1.parseNpmLikeMetadata,
90
+ },
91
+ },
92
+ pnpm: {
93
+ binary: 'pnpm',
94
+ lockfiles: ['pnpm-lock.yaml'],
95
+ addCommand: 'add',
96
+ installCommand: ['install'],
97
+ forceFlag: '--force',
98
+ saveExactFlag: '--save-exact',
99
+ saveTildeFlag: '--save-tilde',
100
+ saveDevFlag: '--save-dev',
101
+ noLockfileFlag: '--no-lockfile',
102
+ ignoreScriptsFlag: '--ignore-scripts',
103
+ getRegistryOptions: (registry) => ({ args: ['--registry', registry] }),
104
+ versionCommand: ['--version'],
105
+ listDependenciesCommand: ['list', '--depth=0', '--json'],
106
+ getManifestCommand: ['view', '--json'],
107
+ viewCommandFieldArgFormatter: (fields) => [...fields],
108
+ outputParsers: {
109
+ listDependencies: parsers_1.parseNpmLikeDependencies,
110
+ getPackageManifest: parsers_1.parseNpmLikeManifest,
111
+ getRegistryMetadata: parsers_1.parseNpmLikeMetadata,
112
+ },
113
+ },
114
+ bun: {
115
+ binary: 'bun',
116
+ lockfiles: ['bun.lockb', 'bun.lock'],
117
+ addCommand: 'add',
118
+ installCommand: ['install'],
119
+ forceFlag: '--force',
120
+ saveExactFlag: '--exact',
121
+ saveTildeFlag: '', // Bun does not have a flag for tilde, it defaults to caret.
122
+ saveDevFlag: '--development',
123
+ noLockfileFlag: '', // Bun does not have a flag for this.
124
+ ignoreScriptsFlag: '--ignore-scripts',
125
+ getRegistryOptions: (registry) => ({ args: ['--registry', registry] }),
126
+ versionCommand: ['--version'],
127
+ listDependenciesCommand: ['pm', 'ls', '--json'],
128
+ getManifestCommand: ['pm', 'view', '--json'],
129
+ viewCommandFieldArgFormatter: (fields) => [...fields],
130
+ outputParsers: {
131
+ listDependencies: parsers_1.parseNpmLikeDependencies,
132
+ getPackageManifest: parsers_1.parseNpmLikeManifest,
133
+ getRegistryMetadata: parsers_1.parseNpmLikeMetadata,
134
+ },
135
+ },
136
+ };
137
+ /**
138
+ * The order of precedence for package managers.
139
+ * This is a best-effort ordering based on estimated Angular community usage and default presence.
140
+ */
141
+ exports.PACKAGE_MANAGER_PRECEDENCE = [
142
+ 'pnpm',
143
+ 'yarn',
144
+ 'bun',
145
+ 'npm',
146
+ ];
147
+ //# sourceMappingURL=package-manager-descriptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-manager-descriptor.js","sourceRoot":"","sources":["package-manager-descriptor.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAWH,uCAOmB;AAsEnB;;;;;;;;;;GAUG;AACU,QAAA,0BAA0B,GAAG;IACxC,GAAG,EAAE;QACH,MAAM,EAAE,KAAK;QACb,SAAS,EAAE,CAAC,mBAAmB,EAAE,qBAAqB,CAAC;QACvD,UAAU,EAAE,SAAS;QACrB,cAAc,EAAE,CAAC,SAAS,CAAC;QAC3B,SAAS,EAAE,SAAS;QACpB,aAAa,EAAE,cAAc;QAC7B,aAAa,EAAE,cAAc;QAC7B,WAAW,EAAE,YAAY;QACzB,cAAc,EAAE,mBAAmB;QACnC,iBAAiB,EAAE,kBAAkB;QACrC,kBAAkB,EAAE,CAAC,QAAgB,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC9E,cAAc,EAAE,CAAC,WAAW,CAAC;QAC7B,uBAAuB,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,CAAC;QAC3E,kBAAkB,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;QACtC,4BAA4B,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;QACrD,aAAa,EAAE;YACb,gBAAgB,EAAE,kCAAwB;YAC1C,kBAAkB,EAAE,8BAAoB;YACxC,mBAAmB,EAAE,8BAAoB;SAC1C;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,CAAC,WAAW,CAAC;QACxB,UAAU,EAAE,KAAK;QACjB,cAAc,EAAE,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C;QACzD,iBAAiB,EAAE,kBAAkB;QACrC,kBAAkB,EAAE,CAAC,QAAgB,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,CAAC;QAC9E,cAAc,EAAE,CAAC,WAAW,CAAC;QAC7B,uBAAuB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC;QAC/C,kBAAkB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC;QAC5C,4BAA4B,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;QACrD,aAAa,EAAE;YACb,gBAAgB,EAAE,kCAAwB;YAC1C,kBAAkB,EAAE,8BAAoB;YACxC,mBAAmB,EAAE,8BAAoB;SAC1C;KACF;CACiD,CAAC;AAErD;;;GAGG;AACU,QAAA,0BAA0B,GAAkC;IACvE,MAAM;IACN,MAAM;IACN,KAAK;IACL,KAAK;CACN,CAAC"}
@@ -0,0 +1,144 @@
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 { Host } from './host';
9
+ import { Logger } from './logger';
10
+ import { PackageManagerDescriptor } from './package-manager-descriptor';
11
+ import { PackageManifest, PackageMetadata } from './package-metadata';
12
+ import { InstalledPackage } from './package-tree';
13
+ /**
14
+ * Options to configure the `PackageManager` instance.
15
+ */
16
+ export interface PackageManagerOptions {
17
+ /**
18
+ * If true, no commands will be executed, but they will be logged to the logger.
19
+ * A logger must be provided if this is true.
20
+ */
21
+ dryRun?: boolean;
22
+ /** A logger instance for debugging and dry run output. */
23
+ logger?: Logger;
24
+ }
25
+ /**
26
+ * A class that provides a high-level, package-manager-agnostic API for
27
+ * interacting with a project's dependencies.
28
+ *
29
+ * This class is an implementation of the Strategy design pattern. It is
30
+ * instantiated with a `PackageManagerDescriptor` that defines the specific
31
+ * commands and flags for a given package manager.
32
+ */
33
+ export declare class PackageManager {
34
+ #private;
35
+ private readonly host;
36
+ private readonly cwd;
37
+ private readonly descriptor;
38
+ private readonly options;
39
+ /**
40
+ * Creates a new `PackageManager` instance.
41
+ * @param host A `Host` instance for interacting with the file system and running commands.
42
+ * @param cwd The absolute path to the project's working directory.
43
+ * @param descriptor A `PackageManagerDescriptor` that defines the commands for a specific package manager.
44
+ * @param options An options object to configure the instance.
45
+ */
46
+ constructor(host: Host, cwd: string, descriptor: PackageManagerDescriptor, options?: PackageManagerOptions);
47
+ /**
48
+ * The name of the package manager's binary.
49
+ */
50
+ get name(): string;
51
+ /**
52
+ * Adds a package to the project's dependencies.
53
+ * @param packageName The name of the package to add.
54
+ * @param save The save strategy to use.
55
+ * - `exact`: The package will be saved with an exact version.
56
+ * - `tilde`: The package will be saved with a tilde version range (`~`).
57
+ * - `none`: The package will be saved with the default version range (`^`).
58
+ * @param asDevDependency Whether to install the package as a dev dependency.
59
+ * @param noLockfile Whether to skip updating the lockfile.
60
+ * @param options Extra options for the command.
61
+ * @returns A promise that resolves when the command is complete.
62
+ */
63
+ add(packageName: string, save: 'exact' | 'tilde' | 'none', asDevDependency: boolean, noLockfile: boolean, ignoreScripts: boolean, options?: {
64
+ registry?: string;
65
+ }): Promise<void>;
66
+ /**
67
+ * Installs all dependencies in the project.
68
+ * @param options Options for the installation.
69
+ * @param options.timeout The maximum time in milliseconds to wait for the command to complete.
70
+ * @param options.force If true, forces a clean install, potentially overwriting existing modules.
71
+ * @param options.registry The registry to use for the installation.
72
+ * @param options.ignoreScripts If true, prevents lifecycle scripts from being executed.
73
+ * @returns A promise that resolves when the command is complete.
74
+ */
75
+ install(options?: {
76
+ timeout?: number;
77
+ force?: boolean;
78
+ registry?: string;
79
+ ignoreScripts?: boolean;
80
+ }): Promise<void>;
81
+ /**
82
+ * Gets the version of the package manager binary.
83
+ * @returns A promise that resolves to the trimmed version string.
84
+ */
85
+ getVersion(): Promise<string>;
86
+ /**
87
+ * Gets the installed details of a package from the project's dependencies.
88
+ * @param packageName The name of the package to check.
89
+ * @returns A promise that resolves to the installed package details, or `null` if the package is not installed.
90
+ */
91
+ getInstalledPackage(packageName: string): Promise<InstalledPackage | null>;
92
+ /**
93
+ * Gets a map of all top-level dependencies installed in the project.
94
+ * @returns A promise that resolves to a map of package names to their installed package details.
95
+ */
96
+ getProjectDependencies(): Promise<Map<string, InstalledPackage>>;
97
+ /**
98
+ * Fetches the registry metadata for a package. This is the full metadata,
99
+ * including all versions and distribution tags.
100
+ * @param packageName The name of the package to fetch the metadata for.
101
+ * @param options Options for the fetch.
102
+ * @param options.timeout The maximum time in milliseconds to wait for the command to complete.
103
+ * @param options.registry The registry to use for the fetch.
104
+ * @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
105
+ * @returns A promise that resolves to the `PackageMetadata` object, or `null` if the package is not found.
106
+ */
107
+ getRegistryMetadata(packageName: string, options?: {
108
+ timeout?: number;
109
+ registry?: string;
110
+ bypassCache?: boolean;
111
+ }): Promise<PackageMetadata | null>;
112
+ /**
113
+ * Fetches the registry manifest for a specific version of a package.
114
+ * The manifest is similar to the package's `package.json` file.
115
+ * @param packageName The name of the package to fetch the manifest for.
116
+ * @param version The version of the package to fetch the manifest for.
117
+ * @param options Options for the fetch.
118
+ * @param options.timeout The maximum time in milliseconds to wait for the command to complete.
119
+ * @param options.registry The registry to use for the fetch.
120
+ * @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
121
+ * @returns A promise that resolves to the `PackageManifest` object, or `null` if the package is not found.
122
+ */
123
+ getPackageManifest(packageName: string, version: string, options?: {
124
+ timeout?: number;
125
+ registry?: string;
126
+ bypassCache?: boolean;
127
+ }): Promise<PackageManifest | null>;
128
+ /**
129
+ * Acquires a package by installing it into a temporary directory. The caller is
130
+ * responsible for managing the lifecycle of the temporary directory by calling
131
+ * the returned `cleanup` function.
132
+ *
133
+ * @param packageName The name of the package to install.
134
+ * @param options Options for the installation.
135
+ * @returns A promise that resolves to an object containing the temporary path
136
+ * and a cleanup function.
137
+ */
138
+ acquireTempPackage(packageName: string, options?: {
139
+ registry?: string;
140
+ }): Promise<{
141
+ workingDirectory: string;
142
+ cleanup: () => Promise<void>;
143
+ }>;
144
+ }
@@ -0,0 +1,304 @@
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.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PackageManager = void 0;
11
+ /**
12
+ * @fileoverview This file contains the `PackageManager` class, which is the
13
+ * core execution engine for all package manager commands. It is designed to be
14
+ * a flexible and secure abstraction over the various package managers.
15
+ */
16
+ const node_path_1 = require("node:path");
17
+ const error_1 = require("./error");
18
+ /**
19
+ * The fields to request from the registry for package metadata.
20
+ * This is a performance optimization to avoid downloading the full manifest
21
+ * when only summary data (like versions and tags) is needed.
22
+ */
23
+ const METADATA_FIELDS = ['name', 'dist-tags', 'versions', 'time'];
24
+ /**
25
+ * The fields to request from the registry for a package's manifest.
26
+ * This is a performance optimization to avoid downloading unnecessary data.
27
+ * These fields are the ones required by the CLI for operations like `ng add` and `ng update`.
28
+ */
29
+ const MANIFEST_FIELDS = [
30
+ 'name',
31
+ 'version',
32
+ 'deprecated',
33
+ 'dependencies',
34
+ 'peerDependencies',
35
+ 'devDependencies',
36
+ 'homepage',
37
+ 'schematics',
38
+ 'ng-add',
39
+ 'ng-update',
40
+ ];
41
+ /**
42
+ * A class that provides a high-level, package-manager-agnostic API for
43
+ * interacting with a project's dependencies.
44
+ *
45
+ * This class is an implementation of the Strategy design pattern. It is
46
+ * instantiated with a `PackageManagerDescriptor` that defines the specific
47
+ * commands and flags for a given package manager.
48
+ */
49
+ class PackageManager {
50
+ host;
51
+ cwd;
52
+ descriptor;
53
+ options;
54
+ #manifestCache = new Map();
55
+ #metadataCache = new Map();
56
+ #dependencyCache = null;
57
+ /**
58
+ * Creates a new `PackageManager` instance.
59
+ * @param host A `Host` instance for interacting with the file system and running commands.
60
+ * @param cwd The absolute path to the project's working directory.
61
+ * @param descriptor A `PackageManagerDescriptor` that defines the commands for a specific package manager.
62
+ * @param options An options object to configure the instance.
63
+ */
64
+ constructor(host, cwd, descriptor, options = {}) {
65
+ this.host = host;
66
+ this.cwd = cwd;
67
+ this.descriptor = descriptor;
68
+ this.options = options;
69
+ if (this.options.dryRun && !this.options.logger) {
70
+ throw new Error('A logger must be provided when dryRun is enabled.');
71
+ }
72
+ }
73
+ /**
74
+ * The name of the package manager's binary.
75
+ */
76
+ get name() {
77
+ return this.descriptor.binary;
78
+ }
79
+ /**
80
+ * A private method to lazily populate the dependency cache.
81
+ * This is a performance optimization to avoid running `npm list` multiple times.
82
+ * @returns A promise that resolves to the dependency cache map.
83
+ */
84
+ async #populateDependencyCache() {
85
+ if (this.#dependencyCache !== null) {
86
+ return this.#dependencyCache;
87
+ }
88
+ const args = this.descriptor.listDependenciesCommand;
89
+ const dependencies = await this.#fetchAndParse(args, (stdout, logger) => this.descriptor.outputParsers.listDependencies(stdout, logger));
90
+ return (this.#dependencyCache = dependencies ?? new Map());
91
+ }
92
+ /**
93
+ * A private method to run a command using the package manager's binary.
94
+ * @param args The arguments to pass to the command.
95
+ * @param options Options for the child process.
96
+ * @returns A promise that resolves with the standard output and standard error of the command.
97
+ */
98
+ async #run(args, options = {}) {
99
+ const { registry, cwd, ...runOptions } = options;
100
+ const finalArgs = [...args];
101
+ let finalEnv;
102
+ if (registry) {
103
+ const registryOptions = this.descriptor.getRegistryOptions?.(registry);
104
+ if (!registryOptions) {
105
+ throw new Error(`The configured package manager, '${this.descriptor.binary}', does not support a custom registry.`);
106
+ }
107
+ if (registryOptions.args) {
108
+ finalArgs.push(...registryOptions.args);
109
+ }
110
+ if (registryOptions.env) {
111
+ finalEnv = registryOptions.env;
112
+ }
113
+ }
114
+ const executionDirectory = cwd ?? this.cwd;
115
+ if (this.options.dryRun) {
116
+ this.options.logger?.info(`[DRY RUN] Would execute in [${executionDirectory}]: ${this.descriptor.binary} ${finalArgs.join(' ')}`);
117
+ return { stdout: '', stderr: '' };
118
+ }
119
+ return this.host.runCommand(this.descriptor.binary, finalArgs, {
120
+ ...runOptions,
121
+ cwd: executionDirectory,
122
+ stdio: 'pipe',
123
+ env: finalEnv,
124
+ });
125
+ }
126
+ /**
127
+ * A private, generic method to encapsulate the common logic of running a command,
128
+ * handling errors, and parsing the output.
129
+ * @param args The arguments to pass to the command.
130
+ * @param parser A function that parses the command's stdout.
131
+ * @param options Options for the command, including caching.
132
+ * @returns A promise that resolves to the parsed data, or null if not found.
133
+ */
134
+ async #fetchAndParse(args, parser, options = {}) {
135
+ const { cache, cacheKey, bypassCache, ...runOptions } = options;
136
+ if (!bypassCache && cache && cacheKey && cache.has(cacheKey)) {
137
+ return cache.get(cacheKey);
138
+ }
139
+ let stdout;
140
+ let stderr;
141
+ try {
142
+ ({ stdout, stderr } = await this.#run(args, runOptions));
143
+ }
144
+ catch (e) {
145
+ if (e instanceof error_1.PackageManagerError && typeof e.exitCode === 'number' && e.exitCode !== 0) {
146
+ // Some package managers exit with a non-zero code when the package is not found.
147
+ if (cache && cacheKey) {
148
+ cache.set(cacheKey, null);
149
+ }
150
+ return null;
151
+ }
152
+ throw e;
153
+ }
154
+ try {
155
+ const result = parser(stdout, this.options.logger);
156
+ if (cache && cacheKey) {
157
+ cache.set(cacheKey, result);
158
+ }
159
+ return result;
160
+ }
161
+ catch (e) {
162
+ const message = `Failed to parse package manager output: ${e instanceof Error ? e.message : ''}`;
163
+ throw new error_1.PackageManagerError(message, stdout, stderr, 0);
164
+ }
165
+ }
166
+ /**
167
+ * Adds a package to the project's dependencies.
168
+ * @param packageName The name of the package to add.
169
+ * @param save The save strategy to use.
170
+ * - `exact`: The package will be saved with an exact version.
171
+ * - `tilde`: The package will be saved with a tilde version range (`~`).
172
+ * - `none`: The package will be saved with the default version range (`^`).
173
+ * @param asDevDependency Whether to install the package as a dev dependency.
174
+ * @param noLockfile Whether to skip updating the lockfile.
175
+ * @param options Extra options for the command.
176
+ * @returns A promise that resolves when the command is complete.
177
+ */
178
+ async add(packageName, save, asDevDependency, noLockfile, ignoreScripts, options = {}) {
179
+ const flags = [
180
+ asDevDependency ? this.descriptor.saveDevFlag : '',
181
+ save === 'exact' ? this.descriptor.saveExactFlag : '',
182
+ save === 'tilde' ? this.descriptor.saveTildeFlag : '',
183
+ noLockfile ? this.descriptor.noLockfileFlag : '',
184
+ ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
185
+ ].filter((flag) => flag);
186
+ const args = [this.descriptor.addCommand, packageName, ...flags];
187
+ await this.#run(args, options);
188
+ this.#dependencyCache = null;
189
+ }
190
+ /**
191
+ * Installs all dependencies in the project.
192
+ * @param options Options for the installation.
193
+ * @param options.timeout The maximum time in milliseconds to wait for the command to complete.
194
+ * @param options.force If true, forces a clean install, potentially overwriting existing modules.
195
+ * @param options.registry The registry to use for the installation.
196
+ * @param options.ignoreScripts If true, prevents lifecycle scripts from being executed.
197
+ * @returns A promise that resolves when the command is complete.
198
+ */
199
+ async install(options = { ignoreScripts: true }) {
200
+ const flags = [
201
+ options.force ? this.descriptor.forceFlag : '',
202
+ options.ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
203
+ ].filter((flag) => flag);
204
+ const args = [...this.descriptor.installCommand, ...flags];
205
+ await this.#run(args, options);
206
+ this.#dependencyCache = null;
207
+ }
208
+ /**
209
+ * Gets the version of the package manager binary.
210
+ * @returns A promise that resolves to the trimmed version string.
211
+ */
212
+ async getVersion() {
213
+ const { stdout } = await this.#run(this.descriptor.versionCommand);
214
+ return stdout.trim();
215
+ }
216
+ /**
217
+ * Gets the installed details of a package from the project's dependencies.
218
+ * @param packageName The name of the package to check.
219
+ * @returns A promise that resolves to the installed package details, or `null` if the package is not installed.
220
+ */
221
+ async getInstalledPackage(packageName) {
222
+ const cache = await this.#populateDependencyCache();
223
+ return cache.get(packageName) ?? null;
224
+ }
225
+ /**
226
+ * Gets a map of all top-level dependencies installed in the project.
227
+ * @returns A promise that resolves to a map of package names to their installed package details.
228
+ */
229
+ async getProjectDependencies() {
230
+ const cache = await this.#populateDependencyCache();
231
+ // Return a copy to prevent external mutations of the cache.
232
+ return new Map(cache);
233
+ }
234
+ /**
235
+ * Fetches the registry metadata for a package. This is the full metadata,
236
+ * including all versions and distribution tags.
237
+ * @param packageName The name of the package to fetch the metadata for.
238
+ * @param options Options for the fetch.
239
+ * @param options.timeout The maximum time in milliseconds to wait for the command to complete.
240
+ * @param options.registry The registry to use for the fetch.
241
+ * @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
242
+ * @returns A promise that resolves to the `PackageMetadata` object, or `null` if the package is not found.
243
+ */
244
+ async getRegistryMetadata(packageName, options = {}) {
245
+ const commandArgs = [...this.descriptor.getManifestCommand, packageName];
246
+ const formatter = this.descriptor.viewCommandFieldArgFormatter;
247
+ if (formatter) {
248
+ commandArgs.push(...formatter(METADATA_FIELDS));
249
+ }
250
+ const cacheKey = options.registry ? `${packageName}|${options.registry}` : packageName;
251
+ return this.#fetchAndParse(commandArgs, (stdout, logger) => this.descriptor.outputParsers.getRegistryMetadata(stdout, logger), { ...options, cache: this.#metadataCache, cacheKey });
252
+ }
253
+ /**
254
+ * Fetches the registry manifest for a specific version of a package.
255
+ * The manifest is similar to the package's `package.json` file.
256
+ * @param packageName The name of the package to fetch the manifest for.
257
+ * @param version The version of the package to fetch the manifest for.
258
+ * @param options Options for the fetch.
259
+ * @param options.timeout The maximum time in milliseconds to wait for the command to complete.
260
+ * @param options.registry The registry to use for the fetch.
261
+ * @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
262
+ * @returns A promise that resolves to the `PackageManifest` object, or `null` if the package is not found.
263
+ */
264
+ async getPackageManifest(packageName, version, options = {}) {
265
+ const specifier = `${packageName}@${version}`;
266
+ const commandArgs = [...this.descriptor.getManifestCommand, specifier];
267
+ const formatter = this.descriptor.viewCommandFieldArgFormatter;
268
+ if (formatter) {
269
+ commandArgs.push(...formatter(MANIFEST_FIELDS));
270
+ }
271
+ const cacheKey = options.registry ? `${specifier}|${options.registry}` : specifier;
272
+ return this.#fetchAndParse(commandArgs, (stdout, logger) => this.descriptor.outputParsers.getPackageManifest(stdout, logger), { ...options, cache: this.#manifestCache, cacheKey });
273
+ }
274
+ /**
275
+ * Acquires a package by installing it into a temporary directory. The caller is
276
+ * responsible for managing the lifecycle of the temporary directory by calling
277
+ * the returned `cleanup` function.
278
+ *
279
+ * @param packageName The name of the package to install.
280
+ * @param options Options for the installation.
281
+ * @returns A promise that resolves to an object containing the temporary path
282
+ * and a cleanup function.
283
+ */
284
+ async acquireTempPackage(packageName, options = {}) {
285
+ const workingDirectory = await this.host.createTempDirectory();
286
+ const cleanup = () => this.host.deleteDirectory(workingDirectory);
287
+ // Some package managers, like yarn classic, do not write a package.json when adding a package.
288
+ // This can cause issues with subsequent `require.resolve` calls.
289
+ // Writing an empty package.json file beforehand prevents this.
290
+ await this.host.writeFile((0, node_path_1.join)(workingDirectory, 'package.json'), '{}');
291
+ const args = [this.descriptor.addCommand, packageName];
292
+ try {
293
+ await this.#run(args, { ...options, cwd: workingDirectory });
294
+ }
295
+ catch (e) {
296
+ // If the command fails, clean up the temporary directory immediately.
297
+ await cleanup();
298
+ throw e;
299
+ }
300
+ return { workingDirectory, cleanup };
301
+ }
302
+ }
303
+ exports.PackageManager = PackageManager;
304
+ //# sourceMappingURL=package-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-manager.js","sourceRoot":"","sources":["package-manager.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH;;;;GAIG;AAEH,yCAAiC;AACjC,mCAA8C;AAO9C;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,CAAU,CAAC;AAE3E;;;;GAIG;AACH,MAAM,eAAe,GAAG;IACtB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