Skip to content

Commit

Permalink
fixed encoded source url issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Dec 7, 2024
1 parent ff7fd57 commit a63e168
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

- 2.11.4
- fixed encoded source url issue

- 2.11.3
- fixed cli to support `merge` command

Expand Down
14 changes: 12 additions & 2 deletions lib/utils/source-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,23 @@ const filterPath = (str) => {
return ls.join('/');
};

const betterFileURLToPath = (url) => {
try {
url = fileURLToPath(url);
} catch (e) {
url = decodeURIComponent(url);
url = fileURLToPath(url);
}
return url;
};

const normalizeSourcePath = (sourceUrl, baseDir) => {

// includes anonymous and everything

// file url
if (sourceUrl.startsWith('file:')) {
const relPath = Util.relativePath(fileURLToPath(sourceUrl), baseDir);
const relPath = Util.relativePath(betterFileURLToPath(sourceUrl), baseDir);
return filterPath(relPath);
}

Expand Down Expand Up @@ -108,7 +118,7 @@ const normalizeSourcePath = (sourceUrl, baseDir) => {

// relative path
const fileUrl = pathToFileURL(sourceUrl).toString();
const relPath = Util.relativePath(fileURLToPath(fileUrl), baseDir);
const relPath = Util.relativePath(betterFileURLToPath(fileUrl), baseDir);
return filterPath(relPath);
};

Expand Down

0 comments on commit a63e168

Please sign in to comment.