Skip to content

Commit

Permalink
fix: improve virtual module id for non-slash delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
SegaraRai committed Jul 24, 2024
1 parent 6c2d028 commit 9eb83de
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/frameworks/vite/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const DEFAULT_VITE_ID_OPTIONS = {

function stringifySourceId(id: string, root: string): string {
const normalizedId = normalizePath(id);
if (normalizedId === root) {
return RELATIVE_PREFIX.slice(0, -1);
if (normalizedId === root || normalizedId === root + "/") {
return RELATIVE_PREFIX;
}

const shortened = normalizePath(id).startsWith(root + "/")
const shortened = normalizedId.startsWith(root + "/")
? (RELATIVE_PREFIX + id.slice(root.length + 1)).replace(/\/$/, "")
: id;
return shortened.replaceAll("\0", "__x00__");
Expand Down Expand Up @@ -74,7 +74,11 @@ export function stringifyId(
return `${PREFIX}${filenamePrefix}${name}`;
}

return `${PREFIX}${stringifySourceId(sourceId, root)}${delimiter}${filenamePrefix}${name}`;
const stringifiedSourceId = stringifySourceId(sourceId, root);
const normalizedDelimiter = stringifiedSourceId.endsWith("/")
? delimiter.replace(/^\//, "")
: delimiter;
return `${PREFIX}${stringifiedSourceId}${normalizedDelimiter}${filenamePrefix}${name}`;
}

export function createIdFunctions(
Expand Down

0 comments on commit 9eb83de

Please sign in to comment.