New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@angular-devkit/schematics] Getting package manager info from @angular/cli #22463
Comments
I am curios to know what is the use-case that you need to know package manager. |
I'm currently building a tool to generate devcontainers configuration for JS projects (incl. Angular with Currently I've implemented my own logic for that especially as I also would like to support pnpm outside Angular projects, so consider this request as nice-to-have. I made the Angular logic a bit simpler than what's currently implemented in ng CLI, here's my code for anyone's interested: export function getPackageManager(tree: Tree): string {
let packageManager = getPackageManagerFromConfig(tree);
if (packageManager) {
return packageManager;
}
const hasYarnLock = tree.exists('yarn.lock');
const hasNpmLock = tree.exists('package-lock.json');
packageManager = hasYarnLock && !hasNpmLock ? 'yarn' : 'npm';
return packageManager;
}
function getPackageManagerFromConfig(tree: Tree): string | null {
const config = tree.read('angular.json');
if (!config) {
return null;
}
const angularJson = JSON.parse(config.toString()) as Record<string, any>;
return (angularJson.cli?.packageManager as string) ?? null;
} |
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list. You can find more details about the feature request process in our documentation. |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
馃殌 Feature request
Command (mark with an
x
)Description
I'm currently developing a schematics that needs to know which package manager the user is using for its project. I found that the logic of detection the package manager already exists within the ng cli (reading from angular.json config or heuristic from workspace), but does not seem to be exposed to the schematics context or options (AFAIK).
Describe the solution you'd like
I would like a way to get the package manager information when the schematics is running in an ng cli context without having to duplicate all the the logic in the schematics itself.
Describe alternatives you've considered
Not sure what would be the best option here: pass on the packageManager info as a schematics option directly, or expose the package manager detection tools directly as an import'able package in your schematics, or something else.
The text was updated successfully, but these errors were encountered: