Skip to content

Commit

Permalink
update urlToFilepath
Browse files Browse the repository at this point in the history
  • Loading branch information
dmail committed Nov 24, 2024
1 parent a4c2b2b commit 807ff74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions packages/independent/server/src/internal/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,19 @@ export const fileSystemPathToUrl = (value) => {

export const urlToFileSystemPath = (url) => {
const urlObject = new URL(url);
let urlString = String(url);
if (urlString[urlString.length - 1] === "/") {
// remove trailing / so that nodejs path becomes predictable otherwise it logs
// the trailing slash on linux but does not on windows
urlString = urlString.slice(0, -1);
}
let urlString;
if (urlObject.hash) {
const origin =
urlObject.protocol === "file:" ? "file://" : urlObject.origin;
urlString = `${origin}${urlObject.pathname}${urlObject.search}%23${urlObject.hash.slice(1)}`;
} else {
urlString = urlObject.href;
}
const fileSystemPath = fileURLToPath(urlString);
if (fileSystemPath[fileSystemPath.length - 1] === "/") {
// remove trailing / so that nodejs path becomes predictable otherwise it logs
// the trailing slash on linux but does not on windows
return fileSystemPath.slice(0, -1);
}
return fileSystemPath;
};
14 changes: 8 additions & 6 deletions packages/independent/urls/src/url_to_filesystem_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import { fileURLToPath } from "node:url";

export const urlToFileSystemPath = (url) => {
const urlObject = new URL(url);
let urlString = String(url);
if (urlString[urlString.length - 1] === "/") {
// remove trailing / so that nodejs path becomes predictable otherwise it logs
// the trailing slash on linux but does not on windows
urlString = urlString.slice(0, -1);
}
let urlString;
if (urlObject.hash) {
const origin =
urlObject.protocol === "file:" ? "file://" : urlObject.origin;
urlString = `${origin}${urlObject.pathname}${urlObject.search}%23${urlObject.hash.slice(1)}`;
} else {
urlString = urlObject.href;
}
const fileSystemPath = fileURLToPath(urlString);
if (fileSystemPath[fileSystemPath.length - 1] === "/") {
// remove trailing / so that nodejs path becomes predictable otherwise it logs
// the trailing slash on linux but does not on windows
return fileSystemPath.slice(0, -1);
}
return fileSystemPath;
};

0 comments on commit 807ff74

Please sign in to comment.