Skip to content
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

Open
4 of 15 tasks
sinedied opened this issue Jan 10, 2022 · 5 comments
Open
4 of 15 tasks
Labels
feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature Issue that requests a new feature

Comments

@sinedied
Copy link
Contributor

sinedied commented Jan 10, 2022

馃殌 Feature request

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

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.

@alan-agius4 alan-agius4 added the feature Issue that requests a new feature label Jan 13, 2022
@alan-agius4
Copy link
Collaborator

I am curios to know what is the use-case that you need to know package manager.

@sinedied
Copy link
Contributor Author

I'm currently building a tool to generate devcontainers configuration for JS projects (incl. Angular with ng add), and to properly set up the container I need to know which package manager the user would like to use.

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;
}

@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Feb 1, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 1, 2022

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.

@angular-robot
Copy link
Contributor

angular-robot bot commented Mar 13, 2022

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.

@angular-robot
Copy link
Contributor

angular-robot bot commented Apr 1, 2022

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.

@angular-robot angular-robot bot added feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors and removed feature: votes required Feature request which is currently still in the voting phase labels Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

2 participants