Skip to content

Commit 6054461

Browse files
committed
fix a public resolving issue
1 parent 6fb8ff1 commit 6054461

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

index.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,28 @@ exports.resolve = (source, file, config) => {
7575
actualSource = pathParts.join(path.sep);
7676
}
7777

78-
// public dir
79-
// TODO this can lead to incorrect path error if `actualSource` is absolute path and DNE.
80-
if (viteConfig.publicDir !== false) {
81-
const publicDir = viteConfig.publicDir ?? "public";
82-
if (actualSource.charAt(0) === "/" && !fs.existsSync(actualSource)) {
83-
actualSource = path.join(path.resolve(publicDir), actualSource);
78+
// resolve module
79+
let resolvedPath = "";
80+
try {
81+
resolvedPath = resolve.sync(actualSource, {
82+
basedir: path.dirname(file),
83+
extensions,
84+
});
85+
}
86+
catch (err) {
87+
if (viteConfig.publicDir !== false) {
88+
const publicDir = viteConfig.publicDir ?? "public";
89+
const publicActualSource = path.join(path.resolve(publicDir), actualSource);
90+
resolvedPath = resolve.sync(publicActualSource, {
91+
basedir: path.dirname(file),
92+
extensions,
93+
});
94+
}
95+
else {
96+
throw new Error("source cannot be resolved in actual path nor in 'Public' path.");
8497
}
8598
}
8699

87-
// resolve module
88-
const resolvedPath = resolve.sync(actualSource, {
89-
basedir: path.dirname(file),
90-
extensions,
91-
});
92-
93100
log("resolved to:", resolvedPath);
94101
return { found: true, path: resolvedPath };
95102
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-import-resolver-vite",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Vite module resolution plugin for eslint-plugin-import.",
55
"keywords": [
66
"eslint",

0 commit comments

Comments
 (0)