monorepo-utils icon indicating copy to clipboard operation
monorepo-utils copied to clipboard

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

Open ernestostifano opened this issue 2 years ago โ€ข 1 comments

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.

ernestostifano avatar May 29 '23 09:05 ernestostifano

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

  • https://www.typescriptlang.org/docs/handbook/project-references.html

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).

  • #44

๐Ÿ“ 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.

azu avatar May 31 '23 00:05 azu