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(es/loader): Make tsc resolver work for bare specifier #8550

Merged
merged 7 commits into from
Jan 27, 2024

Conversation

XHMM
Copy link
Contributor

@XHMM XHMM commented Jan 24, 2024

Description:
From the typescript baseUrl doc: When using bare specifiers (module specifiers that don’t begin with ./, ../, or /), baseUrl has a higher precedence than node_modules package lookups.

In the current tsc resolver implementation, when resolving bare module specifiers, baseUrl was not used except for paths, this cause the belowing resolution failed, but it worked when used in typescript project.

tsconfig.json / .swcrc:

{
    baseUrl: "."
    paths: {
        "@common/*": ["src/common/*"]
    }
}

File structure:

  • ./src/common/helper.ts
  • ./src/index.ts

./src/index.ts content:

 // tsc can resolve this, but tsc resolver cannot
import sth from "src/common/helper"

BREAKING CHANGE:

Related issue (if exists):

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@XHMM XHMM requested a review from a team as a code owner January 24, 2024 16:55
Copy link

changeset-bot bot commented Jan 24, 2024

⚠️ No Changeset found

Latest commit: 45314ea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Jan 24, 2024

CLA assistant check
All committers have signed the CLA.

@kdy1 kdy1 changed the title fix: tsc resolver baseUrl not work for bare specifier fix(es/loader): tsc resolver baseUrl not work for bare specifier Jan 25, 2024
@kdy1 kdy1 self-assigned this Jan 25, 2024
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


swc-bump:

  • swc_ecma_loader

@kdy1 kdy1 enabled auto-merge (squash) January 25, 2024 02:47
@kdy1 kdy1 changed the title fix(es/loader): tsc resolver baseUrl not work for bare specifier fix(es/loader): Make tsc resolver work for bare specifier Jan 25, 2024
@kdy1 kdy1 added this to the Planned milestone Jan 25, 2024
@kdy1 kdy1 disabled auto-merge January 25, 2024 05:00
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failed

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!


swc-bump:

  • swc_ecma_loader

@kdy1 kdy1 enabled auto-merge (squash) January 27, 2024 04:26
Copy link
Collaborator

@swc-bot swc-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review comment generated by auto-rebase script

@kdy1 kdy1 merged commit d6a4615 into swc-project:main Jan 27, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.3.107 Jan 28, 2024
@swc-project swc-project locked as resolved and limited conversation to collaborators Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants