Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

extensions: use theextensionAlias option ofimport-resolver-typescript#2813

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
phryneas wants to merge4 commits intoimport-js:main
base:main
Choose a base branch
Loading
fromphryneas:pr/typescript-alias-extensions

Conversation

phryneas
Copy link
Contributor

TypeScript withmoduleResolution: "node16" requires imports likeimport { foo } from './tsFile.js' while on the disk, there is actually a./tsFile.ts.
The idea here is that a module import needs a file extension and that TypeScript will not change the import statement during transpilation.

Currently, this does not work with theimport/extensions rule if theeslint-import-resolver-typescript is set up - the resolver will return the original file name with the.ts extension, and the eslint rule will error since"js" !== "ts".

This PR modifies theimport/extensions rule to take theextensionAlias setting into account if thetypescript resolver is configured.

Related issues:#2729 and#2776

simondean, 0x80, karlhorky, and danmichaelo reacted with heart emojikarlhorky reacted with rocket emojikarlhorky reacted with eyes emoji
of `import-resolver-typescript`
Comment on lines +195 to +203
/**
* Taken from `eslint-import-resolver-typescript`.
* This could be imported from current versions of that plugin,
* but this project still depends on an older version.
* Also, importing it would add a dependency, or at least an
* optional peer dependency - copying the code seems like the
* more sane option.
* [LICENSE](https://github.com/import-js/eslint-import-resolver-typescript/blob/71b23a206514842fef70a99220e5ffb1d6da2a0e/LICENSE)
*/
Copy link
Member

Choose a reason for hiding this comment

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

is it that we depend on an oldermajor of that plugin? or that we depend on an older minor or patch?

Probably a better option would be extracting the code into its own package, that both we and eslint-import-resolver-typescript use.@JounQin, thoughts?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

eslint-plugin-import doesn't have anydependency oneslint-import-resolver-typescript yet, but adevDependency on1.0.0 || 1.1.0 - the current version is3.5.5.
I didn't want to add a new dependency here just for that one config object, but I'm happy with whatever solution we end up with here :)

Copy link
Member

Choose a reason for hiding this comment

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

ah, true enough. adding a dependency is fine, but perhaps the resolver's not ideal to add. hopefully an extracted package is viable.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

If that doesn't work, we could go for anpeerDependency withpeerDependenciesMetaoptional: true.
If the package is there, use it, if it isn't we should avoid the relevant codeblock anyways.

Copy link
Member

Choose a reason for hiding this comment

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

I don't want to rely on optional peers; any npm client older than that feature would treat it as required.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Good point. Then let's see what@JounQin has to say :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should it be a setting of import plugin to for using without TypeScript resolver? For example, could webpack resolver resolves same path?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I think that's already thesettings['import/resolver'].typescript setting?
If that's set, the import plugin will use the TS resolver, otherwise not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

https://webpack.js.org/configuration/resolve/#resolveextensionalias

I mean the webpack resolver could also resolve different extensions if it's working correctly? Then only relying on the typescript resolver's setting seems incorrect to me.

Copy link
ContributorAuthor

@phryneasphryneasJul 11, 2023
edited
Loading

Choose a reason for hiding this comment

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

Maybe? I don't know what that one does, or if anyone ever had this problem with it.
The problem at hand is that this is something TypeScript expects with thenode16 target, for at least the last 5 releases of TypeScript, and it is not supported by theimports/extensions rule. There doesn't seem any way of asking the resolver "is this a valid replacement file extension for this other extension", since the resolver is pretty much hidden from the rule, so I don't know a way of implementing this better.

Co-authored-by: Jordan Harband <ljharb@gmail.com>
@phryneas
Copy link
ContributorAuthor

Little heads up: It's already late here, and tomorrow is public holiday, so I'll probably add the requested changes on Wednesday.

ljharb reacted with thumbs up emoji

@phryneas
Copy link
ContributorAuthor

Changes are in from my side :)

@Patryk-B

This comment was marked as off-topic.

@ljharbljharb marked this pull request as draftJuly 25, 2023 22:56
@ljharb
Copy link
Member

I've rebased this; if all tests pass, then the only open question seems to be whether we can extract this logic into a package that is shared by both this plugin and the typescript resolver (cc@JounQin)

simondean reacted with thumbs up emoji

@beamery-tomht

This comment was marked as spam.

@JounQin
Copy link
Collaborator

I've rebased this; if all tests pass, then the only open question seems to be whether we can extract this logic into a package that is shared by both this plugin and the typescript resolver (cc@JounQin)

I'm fine to share a package but it seems the version strategy is very different betweeneslint-plugin-import vseslint-import-resolver-typescript. (I don't want to support old Node versions.)

@ljharb
Copy link
Member

You wouldn’t have to, if the extracted package does, it’d work for both.

@niksy
Copy link

Anything we can do to get this merged?

@ljharb
Copy link
Member

Still waiting to figure out if we can share a common package (matching this plugin's version support).

niksy reacted with thumbs up emoji

@niksy
Copy link

What do we expect for shared package to do?

Export list of extension mappings?
Resolve to mapped extension if current context has Typescript configured forimport/resolver?
What should it be named?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ljharbljharbljharb left review comments

@JounQinJounQinJounQin left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@phryneas@Patryk-B@ljharb@beamery-tomht@JounQin@niksy

[8]ページ先頭

©2009-2025 Movatter.jp