moon icon indicating copy to clipboard operation
moon copied to clipboard

[feature] Sync project dependencies to tsconfig compilerOptions paths

Open edwardwilson opened this issue 3 years ago • 3 comments

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 avatar Sep 15 '22 21:09 edwardwilson

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

milesj avatar Sep 15 '22 22:09 milesj

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 avatar Sep 16 '22 07:09 edwardwilson

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

milesj avatar Sep 16 '22 16:09 milesj

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

milesj avatar Oct 05 '22 17:10 milesj

Looks great! Nice work as always ☺️

edwardwilson avatar Oct 05 '22 17:10 edwardwilson

@edwardwilson Awesome. Will land in the next release 👍

Gonna close this for now.

milesj avatar Oct 05 '22 19:10 milesj