angular / angular-cli

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

Schematics: Edit files in different places of monorepo #24362

Open dgp1130 opened 1 year ago

dgp1130 commented 1 year ago

Command

generate

Description

From http://b/120993063.

In large monorepos (such as google3), it is often common to want to edit files in multiple directories from a schematic. Java paths in particular run into this in google3, where users might want to generate foo/bar/baz.ts, java/com/corp/foo/bar/baz.java, and javatests/com/corp/foo/bar/baz.java.

Schematics currently restricts users to the current directory, so this use case doesn't work intuitively.

Describe the solution you'd like

I'm not sure about the proper solution to this problem. I do agree with the current behavior that schematics should be scoped to a particular directory and prevent accesses outside of that, both for security and usability reasons. That said, I think this monorepo issue is a very real problem, so it would be nice to have some kind of support for it.

Some strawman ideas for a solution:

Describe alternatives you've considered

Best alternative is to run the schematic in the monorepo root, but this can be awkward for users who cd in to their particular project directory.

I think you can also edit external files via a Task, but then you're throwing away a lot of the ergonomics of schematics, so that's not a great escape hatch. I guess you could schedule a Task which reruns the schematic in a different directory?

angular-robot[bot] commented 1 year ago

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[bot] commented 1 year 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 1 year 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.

Hyperxq commented 3 months ago

Command

generate

Description

From http://b/120993063.

In large monorepos (such as google3), it is often common to want to edit files in multiple directories from a schematic. Java paths in particular run into this in google3, where users might want to generate foo/bar/baz.ts, java/com/corp/foo/bar/baz.java, and javatests/com/corp/foo/bar/baz.java.

Schematics currently restricts users to the current directory, so this use case doesn't work intuitively.

Describe the solution you'd like

I'm not sure about the proper solution to this problem. I do agree with the current behavior that schematics should be scoped to a particular directory and prevent accesses outside of that, both for security and usability reasons. That said, I think this monorepo issue is a very real problem, so it would be nice to have some kind of support for it.

Some strawman ideas for a solution:

  • Let schematics "cd" into a different directory and use that as the root. So even if it's run in foo/bar/, it could use ../../ as its root and access the whole monorepo.
  • Let schematics declare the root directory in their schema relative to the project root: { "root": "../../" }.
  • Prompt users to give access to directories outside the default one in a permissions model. This is probably the safest but also the most annoying to use.

Describe alternatives you've considered

Best alternative is to run the schematic in the monorepo root, but this can be awkward for users who cd in to their particular project directory.

I think you can also edit external files via a Task, but then you're throwing away a lot of the ergonomics of schematics, so that's not a great escape hatch. I guess you could schedule a Task which reruns the schematic in a different directory?

I am not sure if that will help you until Angular schematics team is implementing this feature but you can execute schematics with pbuilder no matter the workspace, this is the link.