Skip to content

Commit

Permalink
Fix incorrect offset calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
vrugtehagel committed Jul 14, 2024
1 parent 7d00701 commit 6c11ba5
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/asset-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ export async function assetHash(
if(references.length == 0) return;
const content = await fs.readFile(path, { encoding: "utf8" });
let transformed = content;
let offset = 0;
for(const reference of references){
reference.endIndex += offset;
const { endIndex, hasParams, hash } = reference;
transformed = hasParams
? stringSplice(transformed, endIndex + 1, 0, `${param}=${hash}&`)
: stringSplice(transformed, endIndex, 0, `?${param}=${hash}`);
offset += param.length + hash.length + 2;
}
await fs.writeFile(path, transformed);
}));
Expand Down

0 comments on commit 6c11ba5

Please sign in to comment.