angular / angular-cli

CLI tool for Angular
https://cli.angular.io
MIT License
26.76k stars 11.98k forks source link

Have NodePackageInstallTask use project directory if no directory specified #21680

Open mcalmus opened 3 years ago

mcalmus commented 3 years ago

πŸš€ Feature request

Command (mark with an x)

Description

A clear and concise description of the problem or missing capability... `NodePackageInstallTask` is frequently used by add tasks such as `ng-add` in `@angular/material`. If a schematic like this is called from a custom `ng-new` schematic using `externalSchematic` the install fails because it is run from some non-project directory rather than from inside the newly created project directory. ### Describe the solution you'd like If you have a solution in mind, please describe it. Since schematics knows the location of `package.json` it should by default run `NodePackageInstallTask` from that same directory rather than using the working directory. This would unfortunately qualify as a "breaking" change so a configuration option might be necessary to allow for the "old" (current) behavior once this change is made. ### Describe alternatives you've considered Have you considered any alternative solutions or workarounds? The only work-around I've been able to do is essentially replicating the behaviors of third-party schematic "add" tasks within my custom schematic and then running install after the fact which is less than ideal.
mcalmus commented 3 years ago

Related to https://github.com/angular/components/issues/23436

alan-agius4 commented 3 years ago

Can you please share a snipper of the custom ng-new schematic, is a workspace being created?

mcalmus commented 3 years ago

Yes. A workspace is being created. Here is a snipped of the chain of calls.

  return chain([
    mergeWith(
      apply(empty(), [
        externalSchematic('@schematics/angular', 'workspace', workspaceOptions),
        externalSchematic('@schematics/angular', 'application', applicationOptions),
        ....
        options.skipMaterial ? noop() : externalSchematic('@angular/material', 'ng-add', materialInstallOptions),
        ...
mcalmus commented 3 years ago

Following up. Is the provided snippet sufficient?

alan-agius4 commented 3 years ago

Yes it is.

angular-robot[bot] commented 2 years ago

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[bot] commented 2 years ago

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.

mcalmus commented 2 years ago

Could this fix similarly be used here? https://github.com/angular/angular-cli/commit/db0cb5593dcde395f1877f7c9b6bdf911cd26654