Skip to content

fix(js): improve @nx/js/typescript plugin check for buildable libraries#32405

Merged
leosvelperez merged 1 commit intomasterfrom
fix/tsc-plugin-buildable-check
Aug 19, 2025
Merged

fix(js): improve @nx/js/typescript plugin check for buildable libraries#32405
leosvelperez merged 1 commit intomasterfrom
fix/tsc-plugin-buildable-check

Conversation

@leosvelperez
Copy link
Copy Markdown
Member

@leosvelperez leosvelperez commented Aug 19, 2025

Current Behavior

The @nx/js/typescript plugin exhibits the following wrong behaviors when it comes to determining whether a project is buildable:

  • Having a custom conditional export other than development pointing to a source file means the project is not buildable
  • Having any conditional export pointing to source files means the project is not buildable
  • It falls back to check against included files when outDir is defined

The above creates issues where some buildable libraries are not identified.

Expected Behavior

The @nx/js/typescript plugin should behave as follows (simplified) when it comes to determining whether a project is buildable:

  • If outFile is defined:
    • If the . entry point is defined and it's pointing to the outFile or any of its conditional exports are pointing to the outFile, it's buildable
    • If exports is not defined and main or module are defined and pointing to the outFile, it's buildable
    • Otherwise, it's not buildable
  • Otherwise, if outDir is defined:
    • If the . entry point is defined and it's pointing to a path contained in the outDir or any of its conditional exports are pointing to a path contained in the outDir, it's buildable
    • If exports is not defined and main or module are defined and pointing to a path contained in the outDir, it's buildable
    • Otherwise, it's not buildable
  • Otherwise (no outFile and no outDir):
    • If the . entry point is defined and it's pointing to a path not matched by the files or include patterns or any of its conditional exports are pointing to a path not matched by the files or include patterns, it's buildable
    • If exports is not defined and main or module are defined and pointing to a path not matched by the files or include patterns, it's buildable
    • Otherwise, it's not buildable

The above also ensures that custom conditional exports are not a factor, given that all that is needed is that at least one conditional export is deemed non-buildable.

Related Issue(s)

Fixes #32116
Fixes #32290

@leosvelperez leosvelperez self-assigned this Aug 19, 2025
@leosvelperez leosvelperez requested a review from a team as a code owner August 19, 2025 11:17
@leosvelperez leosvelperez requested a review from Coly010 August 19, 2025 11:17
@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Aug 19, 2025 11:30am

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Aug 19, 2025

View your CI Pipeline Execution ↗ for commit 36fa48c

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 13m 54s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 2m 6s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 7s View ↗
nx documentation ✅ Succeeded 36s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-19 12:44:24 UTC

@leosvelperez leosvelperez enabled auto-merge (squash) August 19, 2025 12:27
@leosvelperez leosvelperez merged commit 4bf937e into master Aug 19, 2025
7 of 8 checks passed
@leosvelperez leosvelperez deleted the fix/tsc-plugin-buildable-check branch August 19, 2025 12:44
FrozenPandaz pushed a commit that referenced this pull request Aug 22, 2025
…ries (#32405)

## Current Behavior

The `@nx/js/typescript` plugin exhibits the following wrong behaviors
when it comes to determining whether a project is buildable:

- Having a custom conditional export other than `development` pointing
to a source file means the project is not buildable
- Having any conditional export pointing to source files means the
project is not buildable
- It falls back to check against included files when `outDir` is defined

The above creates issues where some buildable libraries are not
identified.

## Expected Behavior

The `@nx/js/typescript` plugin should behave as follows (simplified)
when it comes to determining whether a project is buildable:

- If `outFile` is defined:
- If the `.` entry point is defined and it's pointing to the `outFile`
or any of its conditional exports are pointing to the `outFile`, it's
buildable
- If `exports` is not defined and `main` or `module` are defined and
pointing to the `outFile`, it's buildable
  - Otherwise, it's not buildable
- Otherwise, if `outDir` is defined:
- If the `.` entry point is defined and it's pointing to a path
contained in the `outDir` or any of its conditional exports are pointing
to a path contained in the `outDir`, it's buildable
- If `exports` is not defined and `main` or `module` are defined and
pointing to a path contained in the `outDir`, it's buildable
  - Otherwise, it's not buildable
- Otherwise (no `outFile` and no `outDir`):
- If the `.` entry point is defined and it's pointing to a path not
matched by the `files` or `include` patterns or any of its conditional
exports are pointing to a path not matched by the `files` or `include`
patterns, it's buildable
- If `exports` is not defined and `main` or `module` are defined and
pointing to a path not matched by the `files` or `include` patterns,
it's buildable
  - Otherwise, it's not buildable

The above also ensures that custom conditional exports are not a factor,
given that all that is needed is that at least one conditional export is
deemed non-buildable.

## Related Issue(s)

Fixes #32116
Fixes #32290

(cherry picked from commit 4bf937e)
@github-actions
Copy link
Copy Markdown
Contributor

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 github-actions Bot locked as resolved and limited conversation to collaborators Aug 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript plugin doesn't find buildable project without exports["."] Renaming the development export condition causes library to be non-buildable

2 participants