Skip to content

Commit

Permalink
Reuse objects
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Nov 19, 2024
1 parent 89ebb34 commit 6e84b7f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ for (const [ik, iv] of Object.entries(denoJson.imports)) {
}
if (replace.size) {
const reg = /\.m?[tj]sx?$/i;
const dec = new TextDecoder();
const enc = new TextEncoder();
const desc = Object.getOwnPropertyDescriptor(Deno, 'readFile')!;
const value = desc.value!;
desc.value = async function readFile(
Expand All @@ -52,8 +54,8 @@ if (replace.size) {
): Promise<Uint8Array> {
let r = await value.apply(this, arguments);
if (reg.test(typeof path === 'string' ? path : path.pathname)) {
r = new TextEncoder().encode(
new TextDecoder().decode(r).replace(
r = enc.encode(
dec.decode(r).replace(
/(['"])([^'"]+)(['"])/g,
(_0, q1, s, q2) => `${q1}${replace.get(s) ?? s}${q2}`,
),
Expand Down

0 comments on commit 6e84b7f

Please sign in to comment.