azu / monorepo-utils

A collection of utilities for monorepo/lerna. Tools for TypeScript project references etc..
164 stars 10 forks source link

workspaces-to-typescript-project-references: add option to sort references with dependent-upon logic #65

Open ernestostifano opened 1 year ago

ernestostifano commented 1 year ago

Hi guys, I was wondering if it wouldn't be that complicated to add an option to sort references using a dependent-upon logic instead of an alphabetical one (especially in the root tsconfig file).

By dependent-upon logic I mean for packages that are dependencies for other packages to appear first in the lists.

I assume you already have the required information since you need to resolve the dependency graph to create the references.

My proposal is motivated by this issue: https://github.com/typescript-eslint/typescript-eslint/issues/2094#issuecomment-1564719858

I know that it is some sort of edge case, but I think that this sorting logic could be of more value than the alphabetical one (which can be easily obtained at a latter time).

My intention is to import my tsconfig file and use the references list. This way I don't need to keep a separate list of dependencies with this particular order elsewhere.

Cheers.

azu commented 1 year ago

I am not aware of any semantic difference in the order of references. It looks like TypeScript docs does not mention it.

However, I think it makes sense to topological sort the elements of references. Currently, references is not sorted. This change will make it more stable (but this is a BREAKING CHANGE).

๐Ÿ“ old lerna has --sort option, but it will be removed. I don't think it's worth much to make it an option.

๐Ÿ“ moon has same feature for TypeScript project references. It may be worth looking into what sorting MOON does.