Skip to content

Schematics: Edit files in different places of monorepo #24362

@dgp1130

Description

@dgp1130

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions