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

Better support ng new use cases #20351

Open
2 tasks done
dgp1130 opened this issue Mar 22, 2021 · 5 comments
Open
2 tasks done

Better support ng new use cases #20351

dgp1130 opened this issue Mar 22, 2021 · 5 comments
Labels
area: schematics/angular feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature type: RFC / discussion / question
Milestone

Comments

@dgp1130
Copy link
Collaborator

dgp1130 commented Mar 22, 2021

馃殌 Feature request

/cc @mgechev

Command (mark with an x)

  • new
  • generate

Description

We should rethink some of the DX around ng new, as it was originally intended to make new Angular applications, but has expanded somewhat, particularly with monorepos. There are three things in particular which are a bit awkward:

  1. There is no way to create an Angular library (using the CLI) without using a monorepo structure. This may not be desired and makes library authorship a little more awkward.
  2. To use a monorepo structure, users are supposed to use ng new --create-application=false, which is a pretty awkward syntax and doesn't make clear that this is intended for a monorepo/multi-app workspace.
  3. Reevaluate the definition of "workspace". I can't speak for others, but I always interpreted a "workspace" as effectively a monorepository for Angular apps. Looking through docs, it seems that anything with an angular.json file is technically a "workspace", so ng new technically creates a workspace, even though it isn't a monorepo. I think this definition of "workspace" only really applies internally so we should think more critically about the language here.

Additional context: https://twitter.com/justinfagnani/status/1373336274384293889

Describe the solution you'd like

I'm thinking we could add an extra flag to ng new to decide whether to make a standalone application (ng new --type app), a multi-app workspace (ng new --type workspace, equivalent to today's ng new --create-application=false), or a standalone library (ng new --type library). Note that ng new --type app and ng new --type library both technically create a "workspace" per the above definition. We might want to either tweak the definition of "workspace" to mean "a multi-app Angular repo" or use something like ng new --type empty-workspace.

This would be distinguished from ng generate because ng new makes a new repository while ng generate works within an existing repository. Arguably we should merge ng new and ng generate (maybe inferring from file path context whether a new repository is required).

Some of the broader questions we should discuss:

  1. How should we position Angular "workspaces"? Are they for monorepositories or not?
  2. How should ng new and ng generate work together or be merged?

Describe alternatives you've considered

Apparently you can use ng-packagr to generate a library without a workspace, but you're losing a lot of the benefits of the CLI by doing so: https://twitter.com/Splaktar/status/1373373386802479105

@anatoly13
Copy link

I would like to add few words here.

The "newProjectRoot" option from angular.json is quite confusing when working with workspace.
Projects of all types (apps and libs) are created under the same folder (by default it is "projects" folder).

For example in NX monorepo there are two folders - apps and libs. This helps to distinguish applications from libraries and provide better project structure.

Alternatives:

  1. Replace "newProjectRoot" option with two new options, something like "newApplicationRoot" and "newLibraryRoot".

  2. Allow to the user to decide under which folder to create application or library and just update angular.json with the path to the newly created application or library:

D:\Projects\my-workspace\apps
ng generate application app1

"root": "/apps/app1",
"sourceRoot": "/apps/app1/src",

or

D:\Projects\my-workspace\libs
ng generate library lib1

"root": "/libs/lib1",
"sourceRoot": "/libs/lib1/src",

Thanks!

@alan-agius4
Copy link
Collaborator

#11101 is also somewhat related.

@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 1, 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 angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Feb 1, 2022
@ngbot ngbot bot modified the milestones: Backlog, needsTriage Feb 1, 2022
@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 21, 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 Feb 21, 2022
@mgechev mgechev added feature: in backlog Feature request for which voting has completed and is now in the backlog and removed feature: insufficient votes Label to add when the not a sufficient number of votes or comments from unique authors labels Feb 22, 2022
@dgp1130
Copy link
Collaborator Author

dgp1130 commented Mar 24, 2022

This came up again in https://twitter.com/justinfagnani/status/1506778260914335749, it's quite difficult to make a repository with Angular library and a demo application without having to conceptualize it as a monorepo. I made https://github.com/dgp1130/ng-root-lib/ to demonstrate how to make a repository structure with a library at the root and a demo app under demo/. It's definitely possible, but requires a lot of modifications to angular.json, tsconfig.json, and ng-package.json, which are easy to miss without clear error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: schematics/angular feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature type: RFC / discussion / question
Projects
None yet
Development

No branches or pull requests

4 participants