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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/adapter-auto/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { execSync } from 'node:child_process';
import { pathToFileURL } from 'node:url';
import { resolve } from 'import-meta-resolve';
import { resolveModuleURL } from 'exsolve';
import { adapters } from './adapters.js';
import { dirname, join } from 'node:path';
import { existsSync } from 'node:fs';
Expand Down Expand Up @@ -40,10 +39,7 @@ function detect_package_manager() {

/** @param {string} name */
function import_from_cwd(name) {
const cwd = pathToFileURL(process.cwd()).href;
const url = resolve(name, cwd + '/x.js');

return import(url);
return import(resolveModuleURL(name));
}

/** @typedef {import('@sveltejs/kit').Adapter} Adapter */
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-auto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"vitest": "^3.0.1"
},
"dependencies": {
"import-meta-resolve": "^4.1.0"
"exsolve": "^1.0.1"
},
"peerDependencies": {
"@sveltejs/kit": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"cookie": "^0.6.0",
"devalue": "^5.1.0",
"esm-env": "^1.2.2",
"import-meta-resolve": "^4.1.0",
"exsolve": "^1.0.1",
"kleur": "^4.1.5",
"magic-string": "^0.30.5",
"mrmime": "^2.0.0",
Expand Down
7 changes: 2 additions & 5 deletions packages/kit/src/utils/import.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as imr from 'import-meta-resolve';
import process from 'node:process';
import { pathToFileURL } from 'node:url';
import { resolveModuleURL } from 'exsolve';

/**
* Resolve a dependency relative to the current working directory,
Expand All @@ -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);
return await import(resolved);
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.

} catch {
try {
Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading