Skip to content

Specify multiple default collections #12157

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexeagle opened this issue Sep 5, 2018 · 17 comments · Fixed by #22860
Closed

Specify multiple default collections #12157

alexeagle opened this issue Sep 5, 2018 · 17 comments · Fixed by #22860
Assignees
Labels
area: @angular/cli feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Milestone

Comments

@alexeagle
Copy link
Contributor

From @jeffbcross on October 31, 2017 22:4

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Area

- [] devkit
- [x] schematics

Desired functionality

It'd be nice to have multiple collections configured in my CLI project instead of a single default collection. I.e. I'd like to have a project that gives preference to nrwl/schematics but will fall back to angular/schematics if I try to generate something not provided by nrwl/schematics. This would make it easier to publish many focused schematics without requiring the user to specify the collection each time they're generating something new. My naive suggestion is to change the .angular-cli.json schema from a single collection value to a cascading array of collections like so:

"defaults": {
  "collection": "nrwl/schematics"
}
"defaults": {
  "collections": [
    "nrwl/schematics",
    "angular/schematics"
  ]
}

Then when calling ng generate, schematics would use the first collection that provides a matching schematic.

This issue seems cross-cutting between CLI and Schematics, so I thought this repository was the most appropriate place to open it, but lmk if I should open it on angular/angular-cli.

(This may seem similar to #34, but it's more focused on end user experience than schematics author experience).

Copied from original issue: angular/devkit#249

@alexeagle alexeagle added the feature Issue that requests a new feature label Sep 5, 2018
@alexeagle
Copy link
Contributor Author

From @tomastrajan on December 2, 2017 7:37

Hey guys!

I was able to implement this in @angular/cli exclusively and was rather a small change. Basically just retrieving of schematics property as array and filtering for first matching schematics / collection pair.

Still have to look into tests though. Also it is possible that you might have had plan for other solution so please let me know.

Also check following screens for the new behavior.

Display help for ng generate with all available collections and their schematics

schema1

Display detailed help for particular schematics (first matching schematics / collection pair wins so the order in schematics property in angular-cli.json matters)

schema2

Generate items using schematics from different collections (again, first matching schematics / collection pair wins so the order in schematics property in angular-cli.json matters)

schema3

@alexeagle
Copy link
Contributor Author

From @tomastrajan on December 2, 2017 13:57

Hi @jeffbcross @hansl

There is now open PR with initial working implementation of this feature on angular/angular-cli repo. Please let me know if its a good base to make this work.

Cheers 🍺

@alexeagle
Copy link
Contributor Author

From @myspivey on January 31, 2018 15:40

Would like this as well.

@alexeagle
Copy link
Contributor Author

From @Hotell on March 17, 2018 18:1

any update on this?

this is totally needed for great DX.

Enforcing users to write --collection @my-foo-bar/super-schematics all the time when switching between collections is super annoying...

thx

@alexeagle
Copy link
Contributor Author

From @tomastrajan on March 17, 2018 19:46

From what I have seen in nrwl/schematics currently the way to go is to extend @schematics/angular in your custom collection.json.

That way you don't have to delegate every schematic manualy, provide default ones out of the box and add custom on top of that.

Thr big downside is that this leads to ONE custom collection set as a new default for angular-cli.json.

This unfortunatelly doesn't support "multiple small focused collections from different authors" use case. 😞

@alexeagle
Copy link
Contributor Author

From @Hotell on March 17, 2018 20:49

Yeah I know, but this is to restrictive and repetitive and hard to maintain overall.

Maybe, just guys, can you please give some statement or so, why @tomastrajan PR wasn't accepted yet or what are the plans ? I know we are all super busy, but would appreciate some response.

thank you 🖖

@alexeagle
Copy link
Contributor Author

From @clydin on March 20, 2018 18:57

Schematic collection extension supports 1 or more schematics with the last taking precedence. The currently envisioned concept is for a custom collection to be placed within the project and that collection to extend from any other schematic collections with the option to directly define other custom schematics if desired. As the schematic extension logic is fully implemented within the core of the schematics system, having similar but repeated logic within the CLI itself represents a maintenance and supportability concern.

@alexeagle
Copy link
Contributor Author

From @clydin on March 20, 2018 19:6

For reference, the collection extension PR: angular/devkit#398

@alexeagle
Copy link
Contributor Author

From @james-schwartzkopf on March 23, 2018 16:29

I think I like that idea long term, at least assuming there will be an easy command for the user to run to add a schematic collection without needing to know the details of collection.json (maybe handled by ng add my-schematic?).

Short term I dislike that every project is adding @schematics/angular to their schematic collections. I'd rather leave it up to the user to compose the schematic collections that make sense for their project. I think it's likely to lead to a mess as users pressure package authors to extend more and more external collections so they can have one collection to rule them all.

I know no one likes to give timelines, but I can't help but ask, any idea on a timeline for this (custom collection in the project)? Is it planned for any release yet? Any issue to track?

@alexeagle
Copy link
Contributor Author

From @hansl on March 23, 2018 19:12

custom collection in the project

You can already do that.

@alexeagle
Copy link
Contributor Author

From @james-schwartzkopf on March 23, 2018 19:24

Yeah, but there's none there by default in a project created by ng new. So everyone's adding @schematics/angular to their schematic collections since it doesn't seen to be straightforward how you add a collection without having to use --collection either for the new collection or for @schematics/angular.

@leon
Copy link
Contributor

leon commented Sep 26, 2019

It's been a year since the last comment.
Any progress on this?

@leon leon unassigned hansl Sep 26, 2019
@Splaktar
Copy link
Contributor

Splaktar commented Sep 26, 2019

I don't believe so. It could certainly use some 👍 on the first post to help it get some attention.

@greetclock
Copy link

I also faced it. For me, would be great to use @ngrx/schematics and @ngneat/spectator schematics at the same time.

@G-Cyrille
Copy link

It definitely would be great for working with different sets of schematics !
I currently switch manually from one set to the other (@ngrx/schematics <-> @ionic/angular-toolkit)

@konradst
Copy link

konradst commented Sep 5, 2020

Yep, it would be especially useful for mobile dev. I also have to switch between @ngrx/schematics and @nativescript/schematics

@angular-robot angular-robot bot added the feature: under consideration Feature request for which voting has completed and the request is now under consideration label Feb 1, 2022
@ngbot ngbot bot added this to the needsTriage milestone Mar 3, 2022
@alan-agius4 alan-agius4 changed the title feat(schematics): specify multiple default collections Specify multiple default collections Mar 3, 2022
dgp1130 pushed a commit that referenced this issue Mar 22, 2022
The `schematicCollections` can be placed under the `cli` option in the global `.angular.json` configuration, at the root or at project level in `angular.json` .

```jsonc
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "cli": {
    "schematicCollections": ["@schematics/angular", "@angular/material"]
  }
  // ...
}
```

**Rationale**
When this option is not configured and a user would like to run a schematic which is not part of `@schematics/angular`,
the collection name needs to be provided to `ng generate` command in the form of `[collection-name:schematic-name]`. This make the `ng generate` command too verbose for repeated usages.

This is where `schematicCollections` comes handle. When adding `@angular/material` to the list of `schematicCollections`, the generate command will try to locate the schematic in the specified collections.

```
ng generate navigation
```

is equivalent to:

```
ng generate @angular/material:navigation
```

**Conflicting schematic names**
When multiple collections have a schematic with the same name. Both `ng generate` and `ng new` will run the first schematic matched based on the ordering (as specified) of `schematicCollections`.

DEPRECATED:

The `defaultCollection` workspace option has been deprecated in favor of `schematicCollections`.

Before
```json
"defaultCollection": "@angular/material"
```

After
```json
"schematicCollections": ["@angular/material"]
```

Closes #12157
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular/cli feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants