moon
moon copied to clipboard
[feature] Sync project dependencies to tsconfig compilerOptions paths
Is your feature request related to a problem? Please describe.
When working with TypeScript monorepo projects to improve import paths we can use path mapping to improve the import paths within the project using the referenced package. It is frustrating to have to manually apply these project path mappings.
Describe the solution you'd like
When the tsconfig references sync happens, the compilerOptions path mapping is also synced.
Describe alternatives you've considered
NX nwrl tooling does this as part of its project linking. Otherwise, it has to be manually configured.
Additional context How the tsconfig could be configured
{
"extends": "../tsconfig.options.json",
"compilerOptions": {
"rootDir": "./src",
"paths": {
"@namespace/package-a": ["../packageA/src/index.ts"],
"@namespace/package-a/*": ["../packageA/src/*"]
}
},
"exclude": ["dist"],
"include": ["./src"],
"references": [
{
"path": "../packageA"
}
]
}
@edwardwilson Interesting. Wouldn't @namespace/package-a already be available for importing because of node_modules symlinking? Or is this overwriting that to use the source files?
When paired with the package.json pointing to src/index.ts we can use import {} from '@namespace/package-a '.
If however we want to achieve the following, we need to have a path mapping into the src folder ../packageA/src/* or we require an independent build of the package and to consume it like any other npm package with a structured dist folder.
import {x} from '@namespace/package-a/x';
import {y} from '@namespace/package-a/y';
@edwardwilson Yeah makes sense. I'll look into add a setting for this.
@edwardwilson I started working on this here: https://github.com/moonrepo/moon/pull/352
Before I finish, just want to make sure this is what you were looking for.
Looks great! Nice work as always ☺️
@edwardwilson Awesome. Will land in the next release 👍
Gonna close this for now.