Skip to content

Commit

Permalink
fix ts loader
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosqsilva committed Sep 4, 2024
1 parent 6e86a58 commit 448bef8
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions scraper/loader/ts-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,29 @@ import { transform } from "oxc-transform";
const extensionsRegex = /\.tsx?$/;

export async function load(url, context, nextLoad) {
if (extensionsRegex.test(url)) {
const { source: rawSource } = await nextLoad(url, {
...context,
format: "module",
});
if (extensionsRegex.test(url)) {
const { source: rawSource } = await nextLoad(url, {
...context,
format: "module",
});

const { sourceText: transformedSource, map } = transform(
fileURLToPath(url),
rawSource.toString(),
{ sourcemap: true }
);
const { code, map } = transform(fileURLToPath(url), rawSource.toString(), {
sourcemap: true,
});

// TODO this should be handled by oxc with an inline sourcemap option
const mapString = JSON.stringify(map);
const sourceWithMap = `${transformedSource}\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(
mapString
).toString("base64")}`;
// TODO this should be handled by oxc with an inline sourcemap option
const mapString = JSON.stringify(map);
const sourceWithMap = `${code}\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(
mapString,
).toString("base64")}`;

return {
format: "module",
shortCircuit: true,
source: sourceWithMap,
};
}
return {
format: "module",
shortCircuit: true,
source: sourceWithMap,
};
}

// Let Node.js handle all other URLs.
return nextLoad(url);
// Let Node.js handle all other URLs.
return nextLoad(url);
}

0 comments on commit 448bef8

Please sign in to comment.