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

fix(js): handle arbitrary nested ts path mappings when re-mapping them to the outputs #27429

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

leosvelperez
Copy link
Member

@leosvelperez leosvelperez commented Aug 14, 2024

Current Behavior

When re-mapping a TS path mapping like "@foo/lib1/plugins/some-file": ["packages/lib1/src/plugins/some-file.ts"], it results in:

"@foo/lib1/plugins/some-file": [
  "dist/packages/lib1/plugins/some-file",
  "dist/packages/lib1/src/plugins/some-file.ts"
]

The first path is wrong because it's missing the src directory, and the second one has a file extension that's not in the output.

Expected Behavior

When re-mapping a TS path mapping like "@foo/lib1/plugins/some-file": ["packages/lib1/src/plugins/some-file.ts"], it should result in:

"@foo/lib1/plugins/some-file": [
  "dist/packages/lib1/plugins/some-file",
  "dist/packages/lib1/src/plugins/some-file",
  "dist/packages/lib1/src/plugins/some-file.ts"
]

In this case, the second path would correctly point to the output. It doesn't have an extension, which allows the compiler to pick up the correct one.

Note that while the first and third paths are still not valid for this specific use case, they could still be valid for other use cases, and in any case, they're still kept for backward compatibility. The util to re-map these paths is currently very generic and generates potentially valid paths. The invalid paths for a given use case won't throw an error as long as there's one that's valid.

Related Issue(s)

Fixes #21699

@leosvelperez leosvelperez self-assigned this Aug 14, 2024
@leosvelperez leosvelperez requested a review from a team as a code owner August 14, 2024 13:09
Copy link

vercel bot commented Aug 14, 2024

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

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Aug 14, 2024 1:11pm

@leosvelperez leosvelperez merged commit 89f6ad4 into master Aug 16, 2024
6 checks passed
@leosvelperez leosvelperez deleted the js/fix-ts-path-re-mapping branch August 16, 2024 14:00
FrozenPandaz pushed a commit that referenced this pull request Aug 19, 2024
…m to the outputs (#27429)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

When re-mapping a TS path mapping like `"@foo/lib1/plugins/some-file":
["packages/lib1/src/plugins/some-file.ts"]`, it results in:

```json
"@foo/lib1/plugins/some-file": [
  "dist/packages/lib1/plugins/some-file",
  "dist/packages/lib1/src/plugins/some-file.ts"
]
```

The first path is wrong because it's missing the `src` directory, and
the second one has a file extension that's not in the output.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

When re-mapping a TS path mapping like `"@foo/lib1/plugins/some-file":
["packages/lib1/src/plugins/some-file.ts"]`, it should result in:

```json
"@foo/lib1/plugins/some-file": [
  "dist/packages/lib1/plugins/some-file",
  "dist/packages/lib1/src/plugins/some-file",
  "dist/packages/lib1/src/plugins/some-file.ts"
]
```

In this case, the second path would correctly point to the output. It
doesn't have an extension, which allows the compiler to pick up the
correct one.

Note that while the first and third paths are still not valid for this
specific use case, they could still be valid for other use cases, and in
any case, they're still kept for backward compatibility. The util to
re-map these paths is currently very generic and generates potentially
valid paths. The invalid paths for a given use case won't throw an error
as long as there's one that's valid.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #21699

(cherry picked from commit 89f6ad4)
Copy link

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 24, 2024
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 Executor Mangles Nested Subpaths
2 participants