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

Already on GitHub? Sign in to your account

[feature] Sync project dependencies to tsconfig compilerOptions paths #319

Closed
edwardwilson opened this issue Sep 15, 2022 · 6 comments
Closed
Labels
enhancement New feature or request

Comments

@edwardwilson
Copy link

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 edwardwilson added the enhancement New feature or request label Sep 15, 2022
@milesj
Copy link
Collaborator

milesj commented Sep 15, 2022

@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?

@edwardwilson
Copy link
Author

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';

@milesj
Copy link
Collaborator

milesj commented Sep 16, 2022

@edwardwilson Yeah makes sense. I'll look into add a setting for this.

@milesj
Copy link
Collaborator

milesj commented Oct 5, 2022

@edwardwilson I started working on this here: #352

Before I finish, just want to make sure this is what you were looking for.

@edwardwilson
Copy link
Author

Looks great! Nice work as always ☺️

@milesj
Copy link
Collaborator

milesj commented Oct 5, 2022

@edwardwilson Awesome. Will land in the next release 👍

Gonna close this for now.

@milesj milesj closed this as completed Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants