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

refactor: migrate to exsolve for module resolution #13513

Closed
wants to merge 2 commits into from

Conversation

pi0
Copy link

@pi0 pi0 commented Feb 27, 2025

This PR migrates import-meta-resolve to unjs/exsolve which is actively maintained and has features such as global cache to improve performance.

Note: exsolve utils default to resolving from CWD which I noticed was the case for both usages here.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Feb 27, 2025

⚠️ No Changeset found

Latest commit: e7f9725

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@svelte-docs-bot
Copy link

@pi0 pi0 marked this pull request as ready for review February 27, 2025 21:36
@@ -9,8 +7,7 @@ import { pathToFileURL } from 'node:url';
*/
export async function resolve_peer_dependency(dependency) {
try {
// @ts-expect-error the types are wrong
const resolved = imr.resolve(dependency, pathToFileURL(process.cwd() + '/dummy.js'));
const resolved = resolveModuleURL(dependency);
Copy link
Author

Choose a reason for hiding this comment

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

we could use { try: true } here also to avoid try/catch situation, however I didn't want to make too much changes.

@benmccann
Copy link
Member

This code is simpler, which is nice. I don't understand why that is and if we're deviating more from the import.meta.resolve API.

I think we'd drop either library as a dependency in SvelteKit 3 (#13528)

@benmccann benmccann requested a review from Rich-Harris March 2, 2025 16:38
@Rich-Harris
Copy link
Member

Thank you. I would prefer to keep things as they are, since when we're able to switch to import.meta.resolve it'll be easier that way, and there's no benefit to switching in the meantime (the caching isn't something that would benefit us, given how we're using it). The reason import-meta-resolve isn't 'actively maintained' is that it's done — it has no open issues or PRs, and fulfils its goal of ponyfilling import.meta.resolve.

@Rich-Harris Rich-Harris closed this Mar 2, 2025
@pi0
Copy link
Author

pi0 commented Mar 3, 2025

Totally fine if you like to keep things as is, I just wanted to offer a better option n in meantime (it is simpler usage and 20kb less install size I found a reason to make PR while was inspecting svelte-kit install size).

Also, a note might be worth considering, Usage of import.meta.resolve(<id>, <cwd>) is not allowed in deno (by 2.2.2 at least), it is a gray area in Bun also I think was considered to be dropped (since Node.js support is also experimental for second arg)

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.

3 participants