nx
nx copied to clipboard
feat(js): support wildcard/nested tsconfig paths
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!
☁️ Nx Cloud Report
CI is running/has finished running commands for commit 23ca27e7cdd0e652b0627b78be6d0f66adae1caf. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this branch
✅ Successfully ran 12 targets
nx affected --target=e2e --base=dc092b531fe10ecfba07d6f9e2bb504d4a465661 --head=23ca27e7cdd0e652b0627b78be6d0f66adae1caf --exclude=e2e-storybook,e2e-storybook-angular,e2e-react-native,e2e-detox --parallel=1nx affected --target=lint --base=dc092b531fe10ecfba07d6f9e2bb504d4a465661 --head=23ca27e7cdd0e652b0627b78be6d0f66adae1caf --parallel=3nx affected --target=build --base=dc092b531fe10ecfba07d6f9e2bb504d4a465661 --head=23ca27e7cdd0e652b0627b78be6d0f66adae1caf --parallel=3nx affected --target=test --base=dc092b531fe10ecfba07d6f9e2bb504d4a465661 --head=23ca27e7cdd0e652b0627b78be6d0f66adae1caf --parallel=1nx-cloud record -- yarn nx workspace-lintnx-cloud record -- yarn documentationnx build typedoc-themenx-cloud record -- yarn depchecknx-cloud record -- yarn check-lock-filesnx-cloud record -- yarn check-commitnx-cloud record -- yarn nx format:check --base=dc092b531fe10ecfba07d6f9e2bb504d4a465661 --head=23ca27e7cdd0e652b0627b78be6d0f66adae1cafnx-cloud record -- yarn check-imports
Sent with 💌 from NxCloud.
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) |
Waiting for this to be merged. Importing all to a single index.ts file is just too burdensome for large libraries.
@SeanSanker hey, thanks for the PR. Can we add an e2e test for this?
Amazing! 👏 This would make Nx viable for us :)
please active again author
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
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
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:
- run the generators to create a project
- modify the
tsconfig.base.jsonto reference wildcard paths withupdateJson - run a library generator
- add some source files with
updateFile - 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 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.
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.