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: resolve modules if folder contains a package.json file #187

Merged
merged 4 commits into from Oct 20, 2022

Conversation

sanderson-ut
Copy link
Contributor

@sanderson-ut sanderson-ut commented Sep 28, 2022

getMappedPath resolves files by trying a number of different file extensions and filtering out those that aren't a file. This does not work when a TSConfig path alias resolves to a directory containing built assets, and described by a package.json, e.g. @foo/bar -> node_modules/foo/bar/dist.

If the tsconfig path is mapped to a folder that doesn't contain an index.${ext} file, then getMappedPath returns undefined as the folder itself is not a file. However, in some cases it is ok for this to resolve to the directory as the package.json contains a typings entry that references a .d.ts file, which is correctly handled by enhanced-resolve.

#188

getMappedPath only resolves to files that exist. This does not
work when a TSConfig path alias resolves to a module folder
containing built assets, and described by a package.json, e.g.
foo/dist.

If the tsconfig path is mapped to a folder, then getMappedPath
returns undefined as the folder is not a file. However, in somes
cases it is ok for this to resolve as the package.json contains
a `typings` entry that references a .d.ts file, which is
correctly handled by enhanced-resolve
@changeset-bot
Copy link

changeset-bot bot commented Sep 28, 2022

🦋 Changeset detected

Latest commit: 27b4ce8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-import-resolver-typescript Patch

Not sure what this means? Click here to learn what changesets are.

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 28, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

src/index.ts Outdated Show resolved Hide resolved
@JounQin JounQin marked this pull request as ready for review October 11, 2022 02:32
Use `path.sep` as the file separator instead of `/` so that this
works on both Windows and Unix.

Rename input parameter from `path` to `modulePath` so that it
doesn't override `node:path`
src/index.ts Outdated Show resolved Hide resolved
Co-authored-by: JounQin <admin@1stg.me>
@JounQin JounQin merged commit 7a91daf into import-js:master Oct 20, 2022
@JounQin
Copy link
Collaborator

JounQin commented Oct 20, 2022

@scott-ut Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants