nx icon indicating copy to clipboard operation
nx copied to clipboard

feat(js): support wildcard/nested tsconfig paths

Open SeanSanker opened this issue 3 years ago • 8 comments

Current Behavior

Path references in the tsconfig.base.json file do not support nested references or wildcards.
This is due the current logic stripping the references and overwriting them with the dep.outputs array.

If you attempt to configure a wildcard path like so:

{
    "paths": {
      "@nx-and-ts/hello-tsc": ["packages/hello-tsc/src/index.ts"],
      "@nx-and-ts/hello-tsc/*": ["packages/hello-tsc/src/*"]
    }
}

Then reference it from a project:

import { helloTsc } from '@nx-and-ts/hello-tsc/lib/hello-tsc';

console.log(helloTsc());

When the project is built, the following error will be emitted:

Cannot find module '@nx-and-ts/hello-tsc/lib/hello-tsc' or its corresponding type declarations.

Expected Behavior

Nested/wildcard references should work identically to the top-level package references and should build without error.

Related Issue(s)

Fixes #11050 Related #1223 Related #10082

Note

This is my first time contributing to nx, if I did anything wrong here or missed any steps please let me know and I'll update the PR.

Thank you!

SeanSanker avatar Jul 20 '22 22:07 SeanSanker

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
nx-dev ⬜️ Ignored (Inspect) Aug 16, 2022 at 4:59AM (UTC)

vercel[bot] avatar Jul 20 '22 22:07 vercel[bot]

Waiting for this to be merged. Importing all to a single index.ts file is just too burdensome for large libraries.

namdien177 avatar Jul 22 '22 10:07 namdien177

@SeanSanker hey, thanks for the PR. Can we add an e2e test for this?

nartc avatar Jul 23 '22 02:07 nartc

Amazing! 👏 This would make Nx viable for us :)

udnes99 avatar Jul 25 '22 11:07 udnes99

please active again author

namdien177 avatar Aug 06 '22 06:08 namdien177

This is amazing! One my biggest gripes with how Nx libraries work was the lack of wildcard imports. If this PR is merged, my DX will skyrocket! Thank you, author

rafael-g-depaulo avatar Aug 08 '22 16:08 rafael-g-depaulo

Since the PR author hasn't been active for the past 2 weeks, I'll try to add some e2e tests to this PR. Thank you for your patience everyone

nartc avatar Aug 08 '22 16:08 nartc

Whoops! Sorry everyone!

I've had a tight deadline to meet for my job and wasn't able to get back to this sooner. In the future I'll make this clear by updating the thread with my status 😅

@nartc If you haven't already taken care of it, I'm more than happy to implement the tests. Would you mind giving some guidance on what those tests would look like and where they would go? My main inhibitor here (aside from free time) is that I'm not too familiar with this codebase.

I assume they'd belong here? https://github.com/nrwl/nx/blob/master/e2e/js/src/js.test.ts

For the implementation, I'd:

  1. run the generators to create a project
  2. modify the tsconfig.base.json to reference wildcard paths with updateJson
  3. run a library generator
  4. add some source files with updateFile
  5. run the build and confirm the source compiles? (something like)
expect(runCLI(`build ${lib}`)).toContain(
  'Successfully compiled: 2 files with swc'
);

I'll try to keep up with my PRs in the future!

SeanSanker avatar Aug 12 '22 22:08 SeanSanker

@SeanSanker Hi Sean, thank you for reporting back. I haven't started but I have some free-time carved out for this PR so I'm going to write the test based on your implementation. Will be updating the PR soon.

E2E test added.

nartc avatar Aug 16 '22 03:08 nartc

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

github-actions[bot] avatar Mar 17 '23 23:03 github-actions[bot]