@depup/angular__cli 21.2.1-depup.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.
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/bin/bootstrap.js +33 -0
- package/bin/ng.js +71 -0
- package/bin/package.json +3 -0
- package/changes.json +30 -0
- package/lib/cli/index.d.ts +11 -0
- package/lib/cli/index.js +109 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/code-examples.db +0 -0
- package/lib/config/schema.json +6150 -0
- package/lib/config/workspace-schema.d.ts +1025 -0
- package/lib/config/workspace-schema.js +133 -0
- package/lib/config/workspace-schema.js.map +1 -0
- package/lib/init.d.ts +8 -0
- package/lib/init.js +162 -0
- package/lib/init.js.map +1 -0
- package/package.json +103 -0
- package/src/analytics/analytics-collector.d.ts +35 -0
- package/src/analytics/analytics-collector.js +195 -0
- package/src/analytics/analytics-collector.js.map +1 -0
- package/src/analytics/analytics-parameters.d.ts +101 -0
- package/src/analytics/analytics-parameters.js +107 -0
- package/src/analytics/analytics-parameters.js.map +1 -0
- package/src/analytics/analytics.d.ts +27 -0
- package/src/analytics/analytics.js +183 -0
- package/src/analytics/analytics.js.map +1 -0
- package/src/command-builder/architect-base-command-module.d.ts +30 -0
- package/src/command-builder/architect-base-command-module.js +244 -0
- package/src/command-builder/architect-base-command-module.js.map +1 -0
- package/src/command-builder/architect-command-module.d.ts +28 -0
- package/src/command-builder/architect-command-module.js +218 -0
- package/src/command-builder/architect-command-module.js.map +1 -0
- package/src/command-builder/command-module.d.ts +73 -0
- package/src/command-builder/command-module.js +245 -0
- package/src/command-builder/command-module.js.map +1 -0
- package/src/command-builder/command-runner.d.ts +9 -0
- package/src/command-builder/command-runner.js +195 -0
- package/src/command-builder/command-runner.js.map +1 -0
- package/src/command-builder/definitions.d.ts +41 -0
- package/src/command-builder/definitions.js +20 -0
- package/src/command-builder/definitions.js.map +1 -0
- package/src/command-builder/schematics-command-module.d.ts +41 -0
- package/src/command-builder/schematics-command-module.js +408 -0
- package/src/command-builder/schematics-command-module.js.map +1 -0
- package/src/command-builder/utilities/command.d.ts +13 -0
- package/src/command-builder/utilities/command.js +39 -0
- package/src/command-builder/utilities/command.js.map +1 -0
- package/src/command-builder/utilities/json-help.d.ts +37 -0
- package/src/command-builder/utilities/json-help.js +92 -0
- package/src/command-builder/utilities/json-help.js.map +1 -0
- package/src/command-builder/utilities/json-schema.d.ts +64 -0
- package/src/command-builder/utilities/json-schema.js +349 -0
- package/src/command-builder/utilities/json-schema.js.map +1 -0
- package/src/command-builder/utilities/normalize-options-middleware.d.ts +18 -0
- package/src/command-builder/utilities/normalize-options-middleware.js +37 -0
- package/src/command-builder/utilities/normalize-options-middleware.js.map +1 -0
- package/src/command-builder/utilities/schematic-engine-host.d.ts +15 -0
- package/src/command-builder/utilities/schematic-engine-host.js +179 -0
- package/src/command-builder/utilities/schematic-engine-host.js.map +1 -0
- package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
- package/src/command-builder/utilities/schematic-workflow.js +70 -0
- package/src/command-builder/utilities/schematic-workflow.js.map +1 -0
- package/src/commands/add/cli.d.ts +38 -0
- package/src/commands/add/cli.js +623 -0
- package/src/commands/add/cli.js.map +1 -0
- package/src/commands/add/long-description.md +7 -0
- package/src/commands/analytics/cli.d.ts +16 -0
- package/src/commands/analytics/cli.js +34 -0
- package/src/commands/analytics/cli.js.map +1 -0
- package/src/commands/analytics/info/cli.d.ts +16 -0
- package/src/commands/analytics/info/cli.js +25 -0
- package/src/commands/analytics/info/cli.js.map +1 -0
- package/src/commands/analytics/long-description.md +20 -0
- package/src/commands/analytics/settings/cli.d.ts +35 -0
- package/src/commands/analytics/settings/cli.js +54 -0
- package/src/commands/analytics/settings/cli.js.map +1 -0
- package/src/commands/build/cli.d.ts +16 -0
- package/src/commands/build/cli.js +21 -0
- package/src/commands/build/cli.js.map +1 -0
- package/src/commands/build/long-description.md +18 -0
- package/src/commands/cache/clean/cli.d.ts +17 -0
- package/src/commands/cache/clean/cli.js +32 -0
- package/src/commands/cache/clean/cli.js.map +1 -0
- package/src/commands/cache/cli.d.ts +17 -0
- package/src/commands/cache/cli.js +36 -0
- package/src/commands/cache/cli.js.map +1 -0
- package/src/commands/cache/info/cli.d.ts +20 -0
- package/src/commands/cache/info/cli.js +139 -0
- package/src/commands/cache/info/cli.js.map +1 -0
- package/src/commands/cache/long-description.md +53 -0
- package/src/commands/cache/settings/cli.d.ts +27 -0
- package/src/commands/cache/settings/cli.js +41 -0
- package/src/commands/cache/settings/cli.js.map +1 -0
- package/src/commands/cache/utilities.d.ts +11 -0
- package/src/commands/cache/utilities.js +47 -0
- package/src/commands/cache/utilities.js.map +1 -0
- package/src/commands/command-config.d.ts +17 -0
- package/src/commands/command-config.js +116 -0
- package/src/commands/command-config.js.map +1 -0
- package/src/commands/completion/cli.d.ts +16 -0
- package/src/commands/completion/cli.js +61 -0
- package/src/commands/completion/cli.js.map +1 -0
- package/src/commands/completion/long-description.md +67 -0
- package/src/commands/config/cli.d.ts +24 -0
- package/src/commands/config/cli.js +150 -0
- package/src/commands/config/cli.js.map +1 -0
- package/src/commands/config/long-description.md +13 -0
- package/src/commands/deploy/cli.d.ts +17 -0
- package/src/commands/deploy/cli.js +38 -0
- package/src/commands/deploy/cli.js.map +1 -0
- package/src/commands/deploy/long-description.md +22 -0
- package/src/commands/e2e/cli.d.ts +18 -0
- package/src/commands/e2e/cli.js +42 -0
- package/src/commands/e2e/cli.js.map +1 -0
- package/src/commands/extract-i18n/cli.d.ts +17 -0
- package/src/commands/extract-i18n/cli.js +48 -0
- package/src/commands/extract-i18n/cli.js.map +1 -0
- package/src/commands/generate/cli.d.ts +47 -0
- package/src/commands/generate/cli.js +189 -0
- package/src/commands/generate/cli.js.map +1 -0
- package/src/commands/lint/cli.d.ts +17 -0
- package/src/commands/lint/cli.js +25 -0
- package/src/commands/lint/cli.js.map +1 -0
- package/src/commands/lint/long-description.md +20 -0
- package/src/commands/make-this-awesome/cli.d.ts +17 -0
- package/src/commands/make-this-awesome/cli.js +36 -0
- package/src/commands/make-this-awesome/cli.js.map +1 -0
- package/src/commands/mcp/cli.d.ts +20 -0
- package/src/commands/mcp/cli.js +74 -0
- package/src/commands/mcp/cli.js.map +1 -0
- package/src/commands/mcp/constants.d.ts +10 -0
- package/src/commands/mcp/constants.js +16 -0
- package/src/commands/mcp/constants.js.map +1 -0
- package/src/commands/mcp/devserver.d.ts +85 -0
- package/src/commands/mcp/devserver.js +112 -0
- package/src/commands/mcp/devserver.js.map +1 -0
- package/src/commands/mcp/host.d.ts +97 -0
- package/src/commands/mcp/host.js +118 -0
- package/src/commands/mcp/host.js.map +1 -0
- package/src/commands/mcp/mcp-server.d.ts +192 -0
- package/src/commands/mcp/mcp-server.js +155 -0
- package/src/commands/mcp/mcp-server.js.map +1 -0
- package/src/commands/mcp/resources/ai-tutor.md +824 -0
- package/src/commands/mcp/resources/best-practices.md +54 -0
- package/src/commands/mcp/resources/instructions.d.ts +9 -0
- package/src/commands/mcp/resources/instructions.js +26 -0
- package/src/commands/mcp/resources/instructions.js.map +1 -0
- package/src/commands/mcp/shared-options.d.ts +12 -0
- package/src/commands/mcp/shared-options.js +22 -0
- package/src/commands/mcp/shared-options.js.map +1 -0
- package/src/commands/mcp/tools/ai-tutor.d.ts +12 -0
- package/src/commands/mcp/tools/ai-tutor.js +59 -0
- package/src/commands/mcp/tools/ai-tutor.js.map +1 -0
- package/src/commands/mcp/tools/best-practices.d.ts +13 -0
- package/src/commands/mcp/tools/best-practices.js +187 -0
- package/src/commands/mcp/tools/best-practices.js.map +1 -0
- package/src/commands/mcp/tools/build.d.ts +37 -0
- package/src/commands/mcp/tools/build.js +89 -0
- package/src/commands/mcp/tools/build.js.map +1 -0
- package/src/commands/mcp/tools/devserver/devserver-start.d.ts +31 -0
- package/src/commands/mcp/tools/devserver/devserver-start.js +91 -0
- package/src/commands/mcp/tools/devserver/devserver-start.js.map +1 -0
- package/src/commands/mcp/tools/devserver/devserver-stop.d.ts +31 -0
- package/src/commands/mcp/tools/devserver/devserver-stop.js +68 -0
- package/src/commands/mcp/tools/devserver/devserver-stop.js.map +1 -0
- package/src/commands/mcp/tools/devserver/devserver-wait-for-build.d.ts +41 -0
- package/src/commands/mcp/tools/devserver/devserver-wait-for-build.js +104 -0
- package/src/commands/mcp/tools/devserver/devserver-wait-for-build.js.map +1 -0
- package/src/commands/mcp/tools/doc-search.d.ts +21 -0
- package/src/commands/mcp/tools/doc-search.js +324 -0
- package/src/commands/mcp/tools/doc-search.js.map +1 -0
- package/src/commands/mcp/tools/e2e.d.ts +44 -0
- package/src/commands/mcp/tools/e2e.js +87 -0
- package/src/commands/mcp/tools/e2e.js.map +1 -0
- package/src/commands/mcp/tools/examples/database-discovery.d.ts +34 -0
- package/src/commands/mcp/tools/examples/database-discovery.js +87 -0
- package/src/commands/mcp/tools/examples/database-discovery.js.map +1 -0
- package/src/commands/mcp/tools/examples/database.d.ts +35 -0
- package/src/commands/mcp/tools/examples/database.js +125 -0
- package/src/commands/mcp/tools/examples/database.js.map +1 -0
- package/src/commands/mcp/tools/examples/index.d.ts +26 -0
- package/src/commands/mcp/tools/examples/index.js +149 -0
- package/src/commands/mcp/tools/examples/index.js.map +1 -0
- package/src/commands/mcp/tools/examples/query-escaper.d.ts +20 -0
- package/src/commands/mcp/tools/examples/query-escaper.js +68 -0
- package/src/commands/mcp/tools/examples/query-escaper.js.map +1 -0
- package/src/commands/mcp/tools/examples/runtime-database.d.ts +10 -0
- package/src/commands/mcp/tools/examples/runtime-database.js +192 -0
- package/src/commands/mcp/tools/examples/runtime-database.js.map +1 -0
- package/src/commands/mcp/tools/examples/schemas.d.ts +29 -0
- package/src/commands/mcp/tools/examples/schemas.js +101 -0
- package/src/commands/mcp/tools/examples/schemas.js.map +1 -0
- package/src/commands/mcp/tools/examples/utils.d.ts +14 -0
- package/src/commands/mcp/tools/examples/utils.js +31 -0
- package/src/commands/mcp/tools/examples/utils.js.map +1 -0
- package/src/commands/mcp/tools/modernize.d.ts +43 -0
- package/src/commands/mcp/tools/modernize.js +165 -0
- package/src/commands/mcp/tools/modernize.js.map +1 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/analyze-for-unsupported-zone-uses.d.ts +17 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/analyze-for-unsupported-zone-uses.js +62 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/analyze-for-unsupported-zone-uses.js.map +1 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate-single-file.d.ts +12 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate-single-file.js +73 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate-single-file.js.map +1 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate-test-file.d.ts +11 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate-test-file.js +60 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/migrate-test-file.js.map +1 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.d.ts +15 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.js +238 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/prompts.js.map +1 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/send-debug-message.d.ts +10 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/send-debug-message.js +20 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/send-debug-message.js.map +1 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/ts-utils.d.ts +35 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/ts-utils.js +136 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/ts-utils.js.map +1 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/types.d.ts +13 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/types.js +10 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/types.js.map +1 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.d.ts +16 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.js +224 -0
- package/src/commands/mcp/tools/onpush-zoneless-migration/zoneless-migration.js.map +1 -0
- package/src/commands/mcp/tools/projects.d.ts +47 -0
- package/src/commands/mcp/tools/projects.js +523 -0
- package/src/commands/mcp/tools/projects.js.map +1 -0
- package/src/commands/mcp/tools/test.d.ts +35 -0
- package/src/commands/mcp/tools/test.js +79 -0
- package/src/commands/mcp/tools/test.js.map +1 -0
- package/src/commands/mcp/tools/tool-registry.d.ts +39 -0
- package/src/commands/mcp/tools/tool-registry.js +35 -0
- package/src/commands/mcp/tools/tool-registry.js.map +1 -0
- package/src/commands/mcp/utils.d.ts +25 -0
- package/src/commands/mcp/utils.js +44 -0
- package/src/commands/mcp/utils.js.map +1 -0
- package/src/commands/mcp/workspace-utils.d.ts +53 -0
- package/src/commands/mcp/workspace-utils.js +138 -0
- package/src/commands/mcp/workspace-utils.js.map +1 -0
- package/src/commands/new/cli.d.ts +27 -0
- package/src/commands/new/cli.js +76 -0
- package/src/commands/new/cli.js.map +1 -0
- package/src/commands/new/long-description.md +15 -0
- package/src/commands/run/cli.d.ts +25 -0
- package/src/commands/run/cli.js +89 -0
- package/src/commands/run/cli.js.map +1 -0
- package/src/commands/run/long-description.md +10 -0
- package/src/commands/serve/cli.d.ts +16 -0
- package/src/commands/serve/cli.js +20 -0
- package/src/commands/serve/cli.js.map +1 -0
- package/src/commands/test/cli.d.ts +16 -0
- package/src/commands/test/cli.js +21 -0
- package/src/commands/test/cli.js.map +1 -0
- package/src/commands/test/long-description.md +2 -0
- package/src/commands/update/cli.d.ts +34 -0
- package/src/commands/update/cli.js +531 -0
- package/src/commands/update/cli.js.map +1 -0
- package/src/commands/update/long-description.md +22 -0
- package/src/commands/update/schematic/collection.json +9 -0
- package/src/commands/update/schematic/index.d.ts +11 -0
- package/src/commands/update/schematic/index.js +715 -0
- package/src/commands/update/schematic/index.js.map +1 -0
- package/src/commands/update/schematic/schema.d.ts +51 -0
- package/src/commands/update/schematic/schema.js +16 -0
- package/src/commands/update/schematic/schema.js.map +1 -0
- package/src/commands/update/schematic/schema.json +64 -0
- package/src/commands/update/utilities/cli-version.d.ts +48 -0
- package/src/commands/update/utilities/cli-version.js +196 -0
- package/src/commands/update/utilities/cli-version.js.map +1 -0
- package/src/commands/update/utilities/constants.d.ts +12 -0
- package/src/commands/update/utilities/constants.js +16 -0
- package/src/commands/update/utilities/constants.js.map +1 -0
- package/src/commands/update/utilities/git.d.ts +36 -0
- package/src/commands/update/utilities/git.js +148 -0
- package/src/commands/update/utilities/git.js.map +1 -0
- package/src/commands/update/utilities/migration.d.ts +32 -0
- package/src/commands/update/utilities/migration.js +267 -0
- package/src/commands/update/utilities/migration.js.map +1 -0
- package/src/commands/version/cli.d.ts +36 -0
- package/src/commands/version/cli.js +117 -0
- package/src/commands/version/cli.js.map +1 -0
- package/src/commands/version/version-info.d.ts +46 -0
- package/src/commands/version/version-info.js +107 -0
- package/src/commands/version/version-info.js.map +1 -0
- package/src/package-managers/discovery.d.ts +23 -0
- package/src/package-managers/discovery.js +104 -0
- package/src/package-managers/discovery.js.map +1 -0
- package/src/package-managers/error.d.ts +43 -0
- package/src/package-managers/error.js +41 -0
- package/src/package-managers/error.js.map +1 -0
- package/src/package-managers/factory.d.ts +30 -0
- package/src/package-managers/factory.js +137 -0
- package/src/package-managers/factory.js.map +1 -0
- package/src/package-managers/host.d.ts +86 -0
- package/src/package-managers/host.js +80 -0
- package/src/package-managers/host.js.map +1 -0
- package/src/package-managers/index.d.ts +13 -0
- package/src/package-managers/index.js +17 -0
- package/src/package-managers/index.js.map +1 -0
- package/src/package-managers/logger.d.ts +27 -0
- package/src/package-managers/logger.js +10 -0
- package/src/package-managers/logger.js.map +1 -0
- package/src/package-managers/package-manager-descriptor.d.ts +245 -0
- package/src/package-managers/package-manager-descriptor.js +175 -0
- package/src/package-managers/package-manager-descriptor.js.map +1 -0
- package/src/package-managers/package-manager.d.ts +191 -0
- package/src/package-managers/package-manager.js +496 -0
- package/src/package-managers/package-manager.js.map +1 -0
- package/src/package-managers/package-metadata.d.ts +91 -0
- package/src/package-managers/package-metadata.js +10 -0
- package/src/package-managers/package-metadata.js.map +1 -0
- package/src/package-managers/package-tree.d.ts +23 -0
- package/src/package-managers/package-tree.js +10 -0
- package/src/package-managers/package-tree.js.map +1 -0
- package/src/package-managers/parsers.d.ts +170 -0
- package/src/package-managers/parsers.js +467 -0
- package/src/package-managers/parsers.js.map +1 -0
- package/src/utilities/color.d.ts +9 -0
- package/src/utilities/color.js +28 -0
- package/src/utilities/color.js.map +1 -0
- package/src/utilities/completion.d.ts +30 -0
- package/src/utilities/completion.js +270 -0
- package/src/utilities/completion.js.map +1 -0
- package/src/utilities/config.d.ts +38 -0
- package/src/utilities/config.js +369 -0
- package/src/utilities/config.js.map +1 -0
- package/src/utilities/environment-options.d.ts +25 -0
- package/src/utilities/environment-options.js +60 -0
- package/src/utilities/environment-options.js.map +1 -0
- package/src/utilities/eol.d.ts +20 -0
- package/src/utilities/eol.js +35 -0
- package/src/utilities/eol.js.map +1 -0
- package/src/utilities/error.d.ts +18 -0
- package/src/utilities/error.js +41 -0
- package/src/utilities/error.js.map +1 -0
- package/src/utilities/find-up.d.ts +21 -0
- package/src/utilities/find-up.js +67 -0
- package/src/utilities/find-up.js.map +1 -0
- package/src/utilities/json-file.d.ts +24 -0
- package/src/utilities/json-file.js +179 -0
- package/src/utilities/json-file.js.map +1 -0
- package/src/utilities/log-file.d.ts +13 -0
- package/src/utilities/log-file.js +28 -0
- package/src/utilities/log-file.js.map +1 -0
- package/src/utilities/memoize.d.ts +15 -0
- package/src/utilities/memoize.js +64 -0
- package/src/utilities/memoize.js.map +1 -0
- package/src/utilities/package-metadata.d.ts +58 -0
- package/src/utilities/package-metadata.js +265 -0
- package/src/utilities/package-metadata.js.map +1 -0
- package/src/utilities/prettier.d.ts +13 -0
- package/src/utilities/prettier.js +46 -0
- package/src/utilities/prettier.js.map +1 -0
- package/src/utilities/project.d.ts +8 -0
- package/src/utilities/project.js +81 -0
- package/src/utilities/project.js.map +1 -0
- package/src/utilities/prompt.d.ts +17 -0
- package/src/utilities/prompt.js +90 -0
- package/src/utilities/prompt.js.map +1 -0
- package/src/utilities/tty.d.ts +16 -0
- package/src/utilities/tty.js +23 -0
- package/src/utilities/tty.js.map +1 -0
- package/src/utilities/version.d.ts +16 -0
- package/src/utilities/version.js +26 -0
- package/src/utilities/version.js.map +1 -0
|
@@ -0,0 +1,191 @@
|
|
|
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 npa from 'npm-package-arg';
|
|
9
|
+
import { Host } from './host';
|
|
10
|
+
import { Logger } from './logger';
|
|
11
|
+
import { PackageManagerDescriptor } from './package-manager-descriptor';
|
|
12
|
+
import { PackageManifest, PackageMetadata } from './package-metadata';
|
|
13
|
+
import { InstalledPackage } from './package-tree';
|
|
14
|
+
/**
|
|
15
|
+
* The fields to request from the registry for a package's manifest.
|
|
16
|
+
* This is a performance optimization to avoid downloading unnecessary data.
|
|
17
|
+
* These fields are the ones required by the CLI for operations like `ng add` and `ng update`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MANIFEST_FIELDS: readonly ["name", "version", "deprecated", "dependencies", "peerDependencies", "devDependencies", "homepage", "schematics", "ng-add", "ng-update"];
|
|
20
|
+
/**
|
|
21
|
+
* Options to configure the `PackageManager` instance.
|
|
22
|
+
*/
|
|
23
|
+
export interface PackageManagerOptions {
|
|
24
|
+
/**
|
|
25
|
+
* If true, no commands will be executed, but they will be logged to the logger.
|
|
26
|
+
* A logger must be provided if this is true.
|
|
27
|
+
*/
|
|
28
|
+
dryRun?: boolean;
|
|
29
|
+
/** A logger instance for debugging and dry run output. */
|
|
30
|
+
logger?: Logger;
|
|
31
|
+
/**
|
|
32
|
+
* The base path to use for temporary directories.
|
|
33
|
+
*/
|
|
34
|
+
tempDirectory?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The version of the package manager.
|
|
37
|
+
* If provided, the `getVersion` method will return this version
|
|
38
|
+
* instead of running the version command.
|
|
39
|
+
*/
|
|
40
|
+
version?: string;
|
|
41
|
+
/**
|
|
42
|
+
* An error that occurred during the initialization of the package manager.
|
|
43
|
+
* If provided, this error will be thrown when attempting to execute any command.
|
|
44
|
+
*/
|
|
45
|
+
initializationError?: Error;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A class that provides a high-level, package-manager-agnostic API for
|
|
49
|
+
* interacting with a project's dependencies.
|
|
50
|
+
*
|
|
51
|
+
* This class is an implementation of the Strategy design pattern. It is
|
|
52
|
+
* instantiated with a `PackageManagerDescriptor` that defines the specific
|
|
53
|
+
* commands and flags for a given package manager.
|
|
54
|
+
*/
|
|
55
|
+
export declare class PackageManager {
|
|
56
|
+
#private;
|
|
57
|
+
private readonly host;
|
|
58
|
+
private readonly cwd;
|
|
59
|
+
private readonly descriptor;
|
|
60
|
+
private readonly options;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new `PackageManager` instance.
|
|
63
|
+
* @param host A `Host` instance for interacting with the file system and running commands.
|
|
64
|
+
* @param cwd The absolute path to the project's working directory.
|
|
65
|
+
* @param descriptor A `PackageManagerDescriptor` that defines the commands for a specific package manager.
|
|
66
|
+
* @param options An options object to configure the instance.
|
|
67
|
+
*/
|
|
68
|
+
constructor(host: Host, cwd: string, descriptor: PackageManagerDescriptor, options?: PackageManagerOptions);
|
|
69
|
+
/**
|
|
70
|
+
* The name of the package manager's binary.
|
|
71
|
+
*/
|
|
72
|
+
get name(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Ensures that the package manager is installed and available in the PATH.
|
|
75
|
+
* If it is not, this method will throw an error with instructions on how to install it.
|
|
76
|
+
*
|
|
77
|
+
* @throws {Error} If the package manager is not installed.
|
|
78
|
+
*/
|
|
79
|
+
ensureInstalled(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Adds a package to the project's dependencies.
|
|
82
|
+
* @param packageName The name of the package to add.
|
|
83
|
+
* @param save The save strategy to use.
|
|
84
|
+
* - `exact`: The package will be saved with an exact version.
|
|
85
|
+
* - `tilde`: The package will be saved with a tilde version range (`~`).
|
|
86
|
+
* - `none`: The package will be saved with the default version range (`^`).
|
|
87
|
+
* @param asDevDependency Whether to install the package as a dev dependency.
|
|
88
|
+
* @param noLockfile Whether to skip updating the lockfile.
|
|
89
|
+
* @param options Extra options for the command.
|
|
90
|
+
* @returns A promise that resolves when the command is complete.
|
|
91
|
+
*/
|
|
92
|
+
add(packageName: string, save: 'exact' | 'tilde' | 'none', asDevDependency: boolean, noLockfile: boolean, ignoreScripts: boolean, options?: {
|
|
93
|
+
registry?: string;
|
|
94
|
+
}): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Installs all dependencies in the project.
|
|
97
|
+
* @param options Options for the installation.
|
|
98
|
+
* @param options.timeout The maximum time in milliseconds to wait for the command to complete.
|
|
99
|
+
* @param options.force If true, forces a clean install, potentially overwriting existing modules.
|
|
100
|
+
* @param options.registry The registry to use for the installation.
|
|
101
|
+
* @param options.ignoreScripts If true, prevents lifecycle scripts from being executed.
|
|
102
|
+
* @returns A promise that resolves when the command is complete.
|
|
103
|
+
*/
|
|
104
|
+
install(options?: {
|
|
105
|
+
timeout?: number;
|
|
106
|
+
force?: boolean;
|
|
107
|
+
registry?: string;
|
|
108
|
+
ignoreScripts?: boolean;
|
|
109
|
+
ignorePeerDependencies?: boolean;
|
|
110
|
+
}): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Gets the version of the package manager binary.
|
|
113
|
+
*/
|
|
114
|
+
getVersion(): Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Gets the installed details of a package from the project's dependencies.
|
|
117
|
+
* @param packageName The name of the package to check.
|
|
118
|
+
* @returns A promise that resolves to the installed package details, or `null` if the package is not installed.
|
|
119
|
+
*/
|
|
120
|
+
getInstalledPackage(packageName: string): Promise<InstalledPackage | null>;
|
|
121
|
+
/**
|
|
122
|
+
* Gets a map of all top-level dependencies installed in the project.
|
|
123
|
+
* @returns A promise that resolves to a map of package names to their installed package details.
|
|
124
|
+
*/
|
|
125
|
+
getProjectDependencies(): Promise<Map<string, InstalledPackage>>;
|
|
126
|
+
/**
|
|
127
|
+
* Fetches the registry metadata for a package. This is the full metadata,
|
|
128
|
+
* including all versions and distribution tags.
|
|
129
|
+
* @param packageName The name of the package to fetch the metadata for.
|
|
130
|
+
* @param options Options for the fetch.
|
|
131
|
+
* @param options.timeout The maximum time in milliseconds to wait for the command to complete.
|
|
132
|
+
* @param options.registry The registry to use for the fetch.
|
|
133
|
+
* @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
|
|
134
|
+
* @returns A promise that resolves to the `PackageMetadata` object, or `null` if the package is not found.
|
|
135
|
+
*/
|
|
136
|
+
getRegistryMetadata(packageName: string, options?: {
|
|
137
|
+
timeout?: number;
|
|
138
|
+
registry?: string;
|
|
139
|
+
bypassCache?: boolean;
|
|
140
|
+
}): Promise<PackageMetadata | null>;
|
|
141
|
+
/**
|
|
142
|
+
* Fetches the registry manifest for a specific version of a package.
|
|
143
|
+
* The manifest is similar to the package's `package.json` file.
|
|
144
|
+
* @param packageName The name of the package to fetch the manifest for.
|
|
145
|
+
* @param version The version of the package to fetch the manifest for.
|
|
146
|
+
* @param options Options for the fetch.
|
|
147
|
+
* @param options.timeout The maximum time in milliseconds to wait for the command to complete.
|
|
148
|
+
* @param options.registry The registry to use for the fetch.
|
|
149
|
+
* @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
|
|
150
|
+
* @returns A promise that resolves to the `PackageManifest` object, or `null` if the package is not found.
|
|
151
|
+
*/
|
|
152
|
+
getRegistryManifest(packageName: string, version: string, options?: {
|
|
153
|
+
timeout?: number;
|
|
154
|
+
registry?: string;
|
|
155
|
+
bypassCache?: boolean;
|
|
156
|
+
}): Promise<PackageManifest | null>;
|
|
157
|
+
/**
|
|
158
|
+
* Fetches the manifest for a package.
|
|
159
|
+
*
|
|
160
|
+
* This method can resolve manifests for packages from the registry, as well
|
|
161
|
+
* as those specified by file paths, directory paths, and remote tarballs.
|
|
162
|
+
* Caching is only supported for registry packages.
|
|
163
|
+
*
|
|
164
|
+
* @param specifier The package specifier to resolve the manifest for.
|
|
165
|
+
* @param options Options for the fetch.
|
|
166
|
+
* @returns A promise that resolves to the `PackageManifest` object, or `null` if the package is not found.
|
|
167
|
+
*/
|
|
168
|
+
getManifest(specifier: string | npa.Result, options?: {
|
|
169
|
+
timeout?: number;
|
|
170
|
+
registry?: string;
|
|
171
|
+
bypassCache?: boolean;
|
|
172
|
+
}): Promise<PackageManifest | null>;
|
|
173
|
+
private getTemporaryDirectory;
|
|
174
|
+
/**
|
|
175
|
+
* Acquires a package by installing it into a temporary directory. The caller is
|
|
176
|
+
* responsible for managing the lifecycle of the temporary directory by calling
|
|
177
|
+
* the returned `cleanup` function.
|
|
178
|
+
*
|
|
179
|
+
* @param specifier The specifier of the package to install.
|
|
180
|
+
* @param options Options for the installation.
|
|
181
|
+
* @returns A promise that resolves to an object containing the temporary path
|
|
182
|
+
* and a cleanup function.
|
|
183
|
+
*/
|
|
184
|
+
acquireTempPackage(specifier: string, options?: {
|
|
185
|
+
registry?: string;
|
|
186
|
+
ignoreScripts?: boolean;
|
|
187
|
+
}): Promise<{
|
|
188
|
+
workingDirectory: string;
|
|
189
|
+
cleanup: () => Promise<void>;
|
|
190
|
+
}>;
|
|
191
|
+
}
|
|
@@ -0,0 +1,496 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PackageManager = exports.MANIFEST_FIELDS = void 0;
|
|
14
|
+
/**
|
|
15
|
+
* @fileoverview This file contains the `PackageManager` class, which is the
|
|
16
|
+
* core execution engine for all package manager commands. It is designed to be
|
|
17
|
+
* a flexible and secure abstraction over the various package managers.
|
|
18
|
+
*/
|
|
19
|
+
const node_path_1 = require("node:path");
|
|
20
|
+
const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
|
|
21
|
+
const semver_1 = require("semver");
|
|
22
|
+
const error_1 = require("./error");
|
|
23
|
+
/**
|
|
24
|
+
* The fields to request from the registry for package metadata.
|
|
25
|
+
* This is a performance optimization to avoid downloading the full manifest
|
|
26
|
+
* when only summary data (like versions and tags) is needed.
|
|
27
|
+
*/
|
|
28
|
+
const METADATA_FIELDS = ['name', 'dist-tags', 'versions', 'time'];
|
|
29
|
+
/**
|
|
30
|
+
* The fields to request from the registry for a package's manifest.
|
|
31
|
+
* This is a performance optimization to avoid downloading unnecessary data.
|
|
32
|
+
* These fields are the ones required by the CLI for operations like `ng add` and `ng update`.
|
|
33
|
+
*/
|
|
34
|
+
exports.MANIFEST_FIELDS = [
|
|
35
|
+
'name',
|
|
36
|
+
'version',
|
|
37
|
+
'deprecated',
|
|
38
|
+
'dependencies',
|
|
39
|
+
'peerDependencies',
|
|
40
|
+
'devDependencies',
|
|
41
|
+
'homepage',
|
|
42
|
+
'schematics',
|
|
43
|
+
'ng-add',
|
|
44
|
+
'ng-update',
|
|
45
|
+
];
|
|
46
|
+
/**
|
|
47
|
+
* A class that provides a high-level, package-manager-agnostic API for
|
|
48
|
+
* interacting with a project's dependencies.
|
|
49
|
+
*
|
|
50
|
+
* This class is an implementation of the Strategy design pattern. It is
|
|
51
|
+
* instantiated with a `PackageManagerDescriptor` that defines the specific
|
|
52
|
+
* commands and flags for a given package manager.
|
|
53
|
+
*/
|
|
54
|
+
class PackageManager {
|
|
55
|
+
host;
|
|
56
|
+
cwd;
|
|
57
|
+
descriptor;
|
|
58
|
+
options;
|
|
59
|
+
#manifestCache = new Map();
|
|
60
|
+
#metadataCache = new Map();
|
|
61
|
+
#initializationError;
|
|
62
|
+
#dependencyCache = null;
|
|
63
|
+
#version;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new `PackageManager` instance.
|
|
66
|
+
* @param host A `Host` instance for interacting with the file system and running commands.
|
|
67
|
+
* @param cwd The absolute path to the project's working directory.
|
|
68
|
+
* @param descriptor A `PackageManagerDescriptor` that defines the commands for a specific package manager.
|
|
69
|
+
* @param options An options object to configure the instance.
|
|
70
|
+
*/
|
|
71
|
+
constructor(host, cwd, descriptor, options = {}) {
|
|
72
|
+
this.host = host;
|
|
73
|
+
this.cwd = cwd;
|
|
74
|
+
this.descriptor = descriptor;
|
|
75
|
+
this.options = options;
|
|
76
|
+
if (this.options.dryRun && !this.options.logger) {
|
|
77
|
+
throw new Error('A logger must be provided when dryRun is enabled.');
|
|
78
|
+
}
|
|
79
|
+
this.#version = options.version;
|
|
80
|
+
this.#initializationError = options.initializationError;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The name of the package manager's binary.
|
|
84
|
+
*/
|
|
85
|
+
get name() {
|
|
86
|
+
return this.descriptor.binary;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Ensures that the package manager is installed and available in the PATH.
|
|
90
|
+
* If it is not, this method will throw an error with instructions on how to install it.
|
|
91
|
+
*
|
|
92
|
+
* @throws {Error} If the package manager is not installed.
|
|
93
|
+
*/
|
|
94
|
+
ensureInstalled() {
|
|
95
|
+
if (this.#initializationError) {
|
|
96
|
+
throw this.#initializationError;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A private method to lazily populate the dependency cache.
|
|
101
|
+
* This is a performance optimization to avoid running `npm list` multiple times.
|
|
102
|
+
* @returns A promise that resolves to the dependency cache map.
|
|
103
|
+
*/
|
|
104
|
+
async #populateDependencyCache() {
|
|
105
|
+
if (this.#dependencyCache !== null) {
|
|
106
|
+
return this.#dependencyCache;
|
|
107
|
+
}
|
|
108
|
+
const args = this.descriptor.listDependenciesCommand;
|
|
109
|
+
const dependencies = await this.#fetchAndParse(args, (stdout, logger) => this.descriptor.outputParsers.listDependencies(stdout, logger));
|
|
110
|
+
return (this.#dependencyCache = dependencies ?? new Map());
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A private method to run a command using the package manager's binary.
|
|
114
|
+
* @param args The arguments to pass to the command.
|
|
115
|
+
* @param options Options for the child process.
|
|
116
|
+
* @returns A promise that resolves with the standard output and standard error of the command.
|
|
117
|
+
*/
|
|
118
|
+
async #run(args, options = {}) {
|
|
119
|
+
this.ensureInstalled();
|
|
120
|
+
const { registry, cwd, ...runOptions } = options;
|
|
121
|
+
const finalArgs = [...args];
|
|
122
|
+
let finalEnv;
|
|
123
|
+
if (registry) {
|
|
124
|
+
const registryOptions = this.descriptor.getRegistryOptions?.(registry);
|
|
125
|
+
if (!registryOptions) {
|
|
126
|
+
throw new Error(`The configured package manager, '${this.descriptor.binary}', does not support a custom registry.`);
|
|
127
|
+
}
|
|
128
|
+
if (registryOptions.args) {
|
|
129
|
+
finalArgs.push(...registryOptions.args);
|
|
130
|
+
}
|
|
131
|
+
if (registryOptions.env) {
|
|
132
|
+
finalEnv = registryOptions.env;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const executionDirectory = cwd ?? this.cwd;
|
|
136
|
+
if (this.options.dryRun) {
|
|
137
|
+
this.options.logger?.info(`[DRY RUN] Would execute in [${executionDirectory}]: ${this.descriptor.binary} ${finalArgs.join(' ')}`);
|
|
138
|
+
return { stdout: '', stderr: '' };
|
|
139
|
+
}
|
|
140
|
+
const commandResult = await this.host.runCommand(this.descriptor.binary, finalArgs, {
|
|
141
|
+
...runOptions,
|
|
142
|
+
cwd: executionDirectory,
|
|
143
|
+
stdio: 'pipe',
|
|
144
|
+
env: finalEnv,
|
|
145
|
+
});
|
|
146
|
+
return { stdout: commandResult.stdout.trim(), stderr: commandResult.stderr.trim() };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A private, generic method to encapsulate the common logic of running a command,
|
|
150
|
+
* handling errors, and parsing the output.
|
|
151
|
+
* @param args The arguments to pass to the command.
|
|
152
|
+
* @param parser A function that parses the command's stdout.
|
|
153
|
+
* @param options Options for the command, including caching.
|
|
154
|
+
* @returns A promise that resolves to the parsed data, or null if not found.
|
|
155
|
+
*/
|
|
156
|
+
async #fetchAndParse(args, parser, options = {}) {
|
|
157
|
+
const { cache, cacheKey, bypassCache, ...runOptions } = options;
|
|
158
|
+
if (!bypassCache && cache && cacheKey && cache.has(cacheKey)) {
|
|
159
|
+
return cache.get(cacheKey);
|
|
160
|
+
}
|
|
161
|
+
let stdout;
|
|
162
|
+
let stderr;
|
|
163
|
+
let exitCode;
|
|
164
|
+
let thrownError;
|
|
165
|
+
try {
|
|
166
|
+
({ stdout, stderr } = await this.#run(args, runOptions));
|
|
167
|
+
exitCode = 0;
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
thrownError = e;
|
|
171
|
+
if (e instanceof error_1.PackageManagerError) {
|
|
172
|
+
stdout = e.stdout;
|
|
173
|
+
stderr = e.stderr;
|
|
174
|
+
exitCode = e.exitCode;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// Re-throw unexpected errors
|
|
178
|
+
throw e;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Yarn classic can exit with code 0 even when an error occurs.
|
|
182
|
+
// To ensure we capture these cases, we will always attempt to parse a
|
|
183
|
+
// structured error from the output, regardless of the exit code.
|
|
184
|
+
const getError = this.descriptor.outputParsers.getError;
|
|
185
|
+
const parsedError = getError?.(stdout, this.options.logger) ?? getError?.(stderr, this.options.logger) ?? null;
|
|
186
|
+
if (parsedError) {
|
|
187
|
+
this.options.logger?.debug(`[${this.descriptor.binary}] Structured error (code: ${parsedError.code}): ${parsedError.summary}`);
|
|
188
|
+
// Special case for 'not found' errors (e.g., E404). Return null for these.
|
|
189
|
+
if (this.descriptor.isNotFound(parsedError)) {
|
|
190
|
+
if (cache && cacheKey) {
|
|
191
|
+
cache.set(cacheKey, null);
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
// For all other structured errors, throw a more informative error.
|
|
197
|
+
throw new error_1.PackageManagerError(parsedError.summary, stdout, stderr, exitCode);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// If an error was originally thrown and we didn't parse a more specific
|
|
201
|
+
// structured error, re-throw the original error now.
|
|
202
|
+
if (thrownError) {
|
|
203
|
+
throw thrownError;
|
|
204
|
+
}
|
|
205
|
+
// If we reach this point, the command succeeded and no structured error was found.
|
|
206
|
+
// We can now safely parse the successful output.
|
|
207
|
+
try {
|
|
208
|
+
const result = parser(stdout, this.options.logger);
|
|
209
|
+
if (cache && cacheKey) {
|
|
210
|
+
cache.set(cacheKey, result);
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
const message = `Failed to parse package manager output: ${e instanceof Error ? e.message : ''}`;
|
|
216
|
+
throw new error_1.PackageManagerError(message, stdout, stderr, exitCode);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Adds a package to the project's dependencies.
|
|
221
|
+
* @param packageName The name of the package to add.
|
|
222
|
+
* @param save The save strategy to use.
|
|
223
|
+
* - `exact`: The package will be saved with an exact version.
|
|
224
|
+
* - `tilde`: The package will be saved with a tilde version range (`~`).
|
|
225
|
+
* - `none`: The package will be saved with the default version range (`^`).
|
|
226
|
+
* @param asDevDependency Whether to install the package as a dev dependency.
|
|
227
|
+
* @param noLockfile Whether to skip updating the lockfile.
|
|
228
|
+
* @param options Extra options for the command.
|
|
229
|
+
* @returns A promise that resolves when the command is complete.
|
|
230
|
+
*/
|
|
231
|
+
async add(packageName, save, asDevDependency, noLockfile, ignoreScripts, options = {}) {
|
|
232
|
+
const flags = [
|
|
233
|
+
asDevDependency ? this.descriptor.saveDevFlag : '',
|
|
234
|
+
save === 'exact' ? this.descriptor.saveExactFlag : '',
|
|
235
|
+
save === 'tilde' ? this.descriptor.saveTildeFlag : '',
|
|
236
|
+
noLockfile ? this.descriptor.noLockfileFlag : '',
|
|
237
|
+
ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
|
|
238
|
+
].filter((flag) => flag);
|
|
239
|
+
const args = [this.descriptor.addCommand, packageName, ...flags];
|
|
240
|
+
await this.#run(args, options);
|
|
241
|
+
this.#dependencyCache = null;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Installs all dependencies in the project.
|
|
245
|
+
* @param options Options for the installation.
|
|
246
|
+
* @param options.timeout The maximum time in milliseconds to wait for the command to complete.
|
|
247
|
+
* @param options.force If true, forces a clean install, potentially overwriting existing modules.
|
|
248
|
+
* @param options.registry The registry to use for the installation.
|
|
249
|
+
* @param options.ignoreScripts If true, prevents lifecycle scripts from being executed.
|
|
250
|
+
* @returns A promise that resolves when the command is complete.
|
|
251
|
+
*/
|
|
252
|
+
async install(options = { ignoreScripts: true }) {
|
|
253
|
+
const flags = [
|
|
254
|
+
options.force ? this.descriptor.forceFlag : '',
|
|
255
|
+
options.ignoreScripts ? this.descriptor.ignoreScriptsFlag : '',
|
|
256
|
+
options.ignorePeerDependencies ? (this.descriptor.ignorePeerDependenciesFlag ?? '') : '',
|
|
257
|
+
].filter((flag) => flag);
|
|
258
|
+
const args = [...this.descriptor.installCommand, ...flags];
|
|
259
|
+
await this.#run(args, options);
|
|
260
|
+
this.#dependencyCache = null;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Gets the version of the package manager binary.
|
|
264
|
+
*/
|
|
265
|
+
async getVersion() {
|
|
266
|
+
if (this.#version) {
|
|
267
|
+
return this.#version;
|
|
268
|
+
}
|
|
269
|
+
const { stdout } = await this.#run(this.descriptor.versionCommand);
|
|
270
|
+
this.#version = stdout.trim();
|
|
271
|
+
if (!(0, semver_1.valid)(this.#version)) {
|
|
272
|
+
throw new Error(`Invalid semver version for ${this.name}: "${this.#version}"`);
|
|
273
|
+
}
|
|
274
|
+
return this.#version;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Gets the installed details of a package from the project's dependencies.
|
|
278
|
+
* @param packageName The name of the package to check.
|
|
279
|
+
* @returns A promise that resolves to the installed package details, or `null` if the package is not installed.
|
|
280
|
+
*/
|
|
281
|
+
async getInstalledPackage(packageName) {
|
|
282
|
+
const cache = await this.#populateDependencyCache();
|
|
283
|
+
return cache.get(packageName) ?? null;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Gets a map of all top-level dependencies installed in the project.
|
|
287
|
+
* @returns A promise that resolves to a map of package names to their installed package details.
|
|
288
|
+
*/
|
|
289
|
+
async getProjectDependencies() {
|
|
290
|
+
const cache = await this.#populateDependencyCache();
|
|
291
|
+
// Return a copy to prevent external mutations of the cache.
|
|
292
|
+
return new Map(cache);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Fetches the registry metadata for a package. This is the full metadata,
|
|
296
|
+
* including all versions and distribution tags.
|
|
297
|
+
* @param packageName The name of the package to fetch the metadata for.
|
|
298
|
+
* @param options Options for the fetch.
|
|
299
|
+
* @param options.timeout The maximum time in milliseconds to wait for the command to complete.
|
|
300
|
+
* @param options.registry The registry to use for the fetch.
|
|
301
|
+
* @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
|
|
302
|
+
* @returns A promise that resolves to the `PackageMetadata` object, or `null` if the package is not found.
|
|
303
|
+
*/
|
|
304
|
+
async getRegistryMetadata(packageName, options = {}) {
|
|
305
|
+
const commandArgs = [...this.descriptor.getManifestCommand, packageName];
|
|
306
|
+
const formatter = this.descriptor.viewCommandFieldArgFormatter;
|
|
307
|
+
if (formatter) {
|
|
308
|
+
commandArgs.push(...formatter(METADATA_FIELDS));
|
|
309
|
+
}
|
|
310
|
+
const cacheKey = options.registry ? `${packageName}|${options.registry}` : packageName;
|
|
311
|
+
return this.#fetchAndParse(commandArgs, (stdout, logger) => this.descriptor.outputParsers.getRegistryMetadata(stdout, logger), { ...options, cache: this.#metadataCache, cacheKey });
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Fetches the registry manifest for a specific version of a package.
|
|
315
|
+
* The manifest is similar to the package's `package.json` file.
|
|
316
|
+
* @param packageName The name of the package to fetch the manifest for.
|
|
317
|
+
* @param version The version of the package to fetch the manifest for.
|
|
318
|
+
* @param options Options for the fetch.
|
|
319
|
+
* @param options.timeout The maximum time in milliseconds to wait for the command to complete.
|
|
320
|
+
* @param options.registry The registry to use for the fetch.
|
|
321
|
+
* @param options.bypassCache If true, ignores the in-memory cache and fetches fresh data.
|
|
322
|
+
* @returns A promise that resolves to the `PackageManifest` object, or `null` if the package is not found.
|
|
323
|
+
*/
|
|
324
|
+
async getRegistryManifest(packageName, version, options = {}) {
|
|
325
|
+
const specifier = this.host.requiresQuoting
|
|
326
|
+
? `"${packageName}@${version}"`
|
|
327
|
+
: `${packageName}@${version}`;
|
|
328
|
+
const commandArgs = [...this.descriptor.getManifestCommand, specifier];
|
|
329
|
+
const formatter = this.descriptor.viewCommandFieldArgFormatter;
|
|
330
|
+
if (formatter) {
|
|
331
|
+
commandArgs.push(...formatter(exports.MANIFEST_FIELDS));
|
|
332
|
+
}
|
|
333
|
+
const cacheKey = options.registry ? `${specifier}|${options.registry}` : specifier;
|
|
334
|
+
const manifest = await this.#fetchAndParse(commandArgs, (stdout, logger) => this.descriptor.outputParsers.getRegistryManifest(stdout, logger), { ...options, cache: this.#manifestCache, cacheKey });
|
|
335
|
+
// If the provided version was not a specific version, also cache the specific fetched version
|
|
336
|
+
if (manifest && manifest.version !== version) {
|
|
337
|
+
const manifestSpecifier = `${manifest.name}@${manifest.version}`;
|
|
338
|
+
const manifestCacheKey = options.registry
|
|
339
|
+
? `${manifestSpecifier}|${options.registry}`
|
|
340
|
+
: manifestSpecifier;
|
|
341
|
+
this.#manifestCache.set(manifestCacheKey, manifest);
|
|
342
|
+
}
|
|
343
|
+
return manifest;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Fetches the manifest for a package.
|
|
347
|
+
*
|
|
348
|
+
* This method can resolve manifests for packages from the registry, as well
|
|
349
|
+
* as those specified by file paths, directory paths, and remote tarballs.
|
|
350
|
+
* Caching is only supported for registry packages.
|
|
351
|
+
*
|
|
352
|
+
* @param specifier The package specifier to resolve the manifest for.
|
|
353
|
+
* @param options Options for the fetch.
|
|
354
|
+
* @returns A promise that resolves to the `PackageManifest` object, or `null` if the package is not found.
|
|
355
|
+
*/
|
|
356
|
+
async getManifest(specifier, options = {}) {
|
|
357
|
+
const { name, type, fetchSpec } = typeof specifier === 'string' ? (0, npm_package_arg_1.default)(specifier) : specifier;
|
|
358
|
+
switch (type) {
|
|
359
|
+
case 'range':
|
|
360
|
+
case 'version':
|
|
361
|
+
case 'tag': {
|
|
362
|
+
if (!name) {
|
|
363
|
+
throw new Error(`Could not parse package name from specifier: ${specifier}`);
|
|
364
|
+
}
|
|
365
|
+
// `fetchSpec` is the version, range, or tag.
|
|
366
|
+
let versionSpec = fetchSpec ?? 'latest';
|
|
367
|
+
if (this.descriptor.requiresManifestVersionLookup) {
|
|
368
|
+
if (type === 'tag' || !fetchSpec) {
|
|
369
|
+
const metadata = await this.getRegistryMetadata(name, options);
|
|
370
|
+
if (!metadata) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
versionSpec = metadata['dist-tags'][versionSpec];
|
|
374
|
+
}
|
|
375
|
+
else if (type === 'range') {
|
|
376
|
+
const metadata = await this.getRegistryMetadata(name, options);
|
|
377
|
+
if (!metadata) {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
versionSpec = (0, semver_1.maxSatisfying)(metadata.versions, fetchSpec) ?? '';
|
|
381
|
+
}
|
|
382
|
+
if (!versionSpec) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return this.getRegistryManifest(name, versionSpec, options);
|
|
387
|
+
}
|
|
388
|
+
case 'directory': {
|
|
389
|
+
if (!fetchSpec) {
|
|
390
|
+
throw new Error(`Could not parse directory path from specifier: ${specifier}`);
|
|
391
|
+
}
|
|
392
|
+
const manifestPath = (0, node_path_1.join)(fetchSpec, 'package.json');
|
|
393
|
+
const manifest = await this.host.readFile(manifestPath);
|
|
394
|
+
return JSON.parse(manifest);
|
|
395
|
+
}
|
|
396
|
+
case 'file':
|
|
397
|
+
case 'remote':
|
|
398
|
+
case 'git': {
|
|
399
|
+
if (!fetchSpec) {
|
|
400
|
+
throw new Error(`Could not parse location from specifier: ${specifier}`);
|
|
401
|
+
}
|
|
402
|
+
// Caching is not supported for non-registry specifiers.
|
|
403
|
+
const { workingDirectory, cleanup } = await this.acquireTempPackage(fetchSpec, {
|
|
404
|
+
...options,
|
|
405
|
+
ignoreScripts: true,
|
|
406
|
+
});
|
|
407
|
+
try {
|
|
408
|
+
// Discover the package name by reading the temporary `package.json` file.
|
|
409
|
+
// The package manager will have added the package to the `dependencies`.
|
|
410
|
+
const tempManifest = await this.host.readFile((0, node_path_1.join)(workingDirectory, 'package.json'));
|
|
411
|
+
const { dependencies } = JSON.parse(tempManifest);
|
|
412
|
+
const packageName = dependencies && Object.keys(dependencies)[0];
|
|
413
|
+
if (!packageName) {
|
|
414
|
+
throw new Error(`Could not determine package name for specifier: ${specifier}`);
|
|
415
|
+
}
|
|
416
|
+
// The package will be installed in `<temp>/node_modules/<name>`.
|
|
417
|
+
const packagePath = (0, node_path_1.join)(workingDirectory, 'node_modules', packageName);
|
|
418
|
+
const manifestPath = (0, node_path_1.join)(packagePath, 'package.json');
|
|
419
|
+
const manifest = await this.host.readFile(manifestPath);
|
|
420
|
+
return JSON.parse(manifest);
|
|
421
|
+
}
|
|
422
|
+
finally {
|
|
423
|
+
await cleanup();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
default:
|
|
427
|
+
throw new Error(`Unsupported package specifier type: ${type}`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
async getTemporaryDirectory() {
|
|
431
|
+
const { tempDirectory } = this.options;
|
|
432
|
+
if (tempDirectory && !(0, node_path_1.relative)(this.cwd, tempDirectory).startsWith('..')) {
|
|
433
|
+
try {
|
|
434
|
+
await this.host.stat(tempDirectory);
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
// If the cache directory doesn't exist, create it.
|
|
438
|
+
await this.host.mkdir(tempDirectory, { recursive: true });
|
|
439
|
+
}
|
|
440
|
+
return tempDirectory;
|
|
441
|
+
}
|
|
442
|
+
const tempOptions = ['node_modules'];
|
|
443
|
+
for (const tempOption of tempOptions) {
|
|
444
|
+
try {
|
|
445
|
+
const directory = (0, node_path_1.resolve)(this.cwd, tempOption);
|
|
446
|
+
if ((await this.host.stat(directory)).isDirectory()) {
|
|
447
|
+
return directory;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
catch { }
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Acquires a package by installing it into a temporary directory. The caller is
|
|
455
|
+
* responsible for managing the lifecycle of the temporary directory by calling
|
|
456
|
+
* the returned `cleanup` function.
|
|
457
|
+
*
|
|
458
|
+
* @param specifier The specifier of the package to install.
|
|
459
|
+
* @param options Options for the installation.
|
|
460
|
+
* @returns A promise that resolves to an object containing the temporary path
|
|
461
|
+
* and a cleanup function.
|
|
462
|
+
*/
|
|
463
|
+
async acquireTempPackage(specifier, options = {}) {
|
|
464
|
+
const workingDirectory = await this.host.createTempDirectory(await this.getTemporaryDirectory());
|
|
465
|
+
const cleanup = () => this.host.deleteDirectory(workingDirectory);
|
|
466
|
+
// Some package managers, like yarn classic, do not write a package.json when adding a package.
|
|
467
|
+
// This can cause issues with subsequent `require.resolve` calls.
|
|
468
|
+
// Writing an empty package.json file beforehand prevents this.
|
|
469
|
+
await this.host.writeFile((0, node_path_1.join)(workingDirectory, 'package.json'), '{}');
|
|
470
|
+
// Copy configuration files if the package manager requires it (e.g., bun).
|
|
471
|
+
if (this.descriptor.copyConfigFromProject) {
|
|
472
|
+
for (const configFile of this.descriptor.configFiles) {
|
|
473
|
+
try {
|
|
474
|
+
const configPath = (0, node_path_1.join)(this.cwd, configFile);
|
|
475
|
+
await this.host.copyFile(configPath, (0, node_path_1.join)(workingDirectory, configFile));
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
// Ignore missing config files.
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const flags = [options.ignoreScripts ? this.descriptor.ignoreScriptsFlag : ''].filter((flag) => flag);
|
|
483
|
+
const args = [this.descriptor.addCommand, specifier, ...flags];
|
|
484
|
+
try {
|
|
485
|
+
await this.#run(args, { ...options, cwd: workingDirectory });
|
|
486
|
+
}
|
|
487
|
+
catch (e) {
|
|
488
|
+
// If the command fails, clean up the temporary directory immediately.
|
|
489
|
+
await cleanup();
|
|
490
|
+
throw e;
|
|
491
|
+
}
|
|
492
|
+
return { workingDirectory, cleanup };
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
exports.PackageManager = PackageManager;
|
|
496
|
+
//# sourceMappingURL=package-manager.js.map
|