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

Eliminiate custom TS System instance #680

Merged
merged 1 commit into from
Jun 16, 2024

Conversation

geigerzaehler
Copy link
Contributor

Follow-up to #673

The custom instance was previously responsible for resolving mapped paths to files handled by an external loader (e.g. .vue files) or treated as-is (e.g. .png). Now, tsconfig-paths does the path mapping resolution.

Note that the custom system resolver was really only hit for mapped paths. For non-mapped paths resolveSync() would already resolve the file.

That’s my best guess explanation why we can make this change. Please let me know if I overlooked something.

It also looks like this does make resolution faster. I ran it multiple times against the TanStack/query repo (because it has the most time spent in resolveModuleName()) and I’m seeing a 5-20% decrease in time spent in resolveModuleName(). (Take this with a grain of salt, though, since it’s only a rudimentary evaluation.)

Copy link

netlify bot commented Jun 14, 2024

‼️ Deploy request for knip rejected.

Name Link
🔨 Latest commit 7d64367

@geigerzaehler

This comment was marked as outdated.

@geigerzaehler geigerzaehler marked this pull request as ready for review June 14, 2024 14:33
Copy link
Collaborator

@webpro webpro left a comment

Choose a reason for hiding this comment

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

Thanks @geigerzaehler, this is great! Just what I was hoping for. Given that it also handles the external repos just fine I'm confident we can merge this.

Just a few nitpicks left.

const resolvedFileName = resolveSync(sanitizedSpecifier, containingFile, [
...DEFAULT_EXTENSIONS,
...customCompilerExtensions,
]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can go back as extensions in the createCustomModuleResolver scope (slight perf cost to unnecessarily keep re-creating this array with a spread operator).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense and fixed

@@ -91,12 +91,29 @@ export function createCustomModuleResolver(

return {
resolvedFileName,
extension: virtualFileExtensions.includes(ext) ? ts.Extension.Js : ext,
extension: getExtension(resolvedFileName),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we using a function with customCompilerExtensions.some and customCompilerExtensions.includes? Maybe we can make it consistent/fast with a Set + Set.has?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I removed the function and made it more consistent.

The custom instance was previously responsible for resolving mapped
paths to files handled by an external loader (e.g. `.vue` files) or
treated as-is (e.g. `.png`). Now, `tsconfig-paths` does the path mapping
resolution.

Note that the custom system resolver was realy only hit for mapped
paths. For non-mapped paths `resolveSync()` would already resolve the
file.
@webpro
Copy link
Collaborator

webpro commented Jun 16, 2024

This is so good! Thanks, @geigerzaehler.

@webpro webpro merged commit d7325c6 into webpro-nl:main Jun 16, 2024
11 checks passed
@webpro
Copy link
Collaborator

webpro commented Jun 16, 2024

🚀 This pull request is included in v5.20.0. See Release 5.20.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

@geigerzaehler geigerzaehler deleted the no-custom-ts-sys branch June 16, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants