Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions test-e2e/fixtures/load-preact-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export function loadPreactVersion(): Plugin {
const entry = pkg.exports[modName].import;

const code = fs.readFileSync(path.join(versionDir, entry), "utf-8");
const map = fs.readFileSync(
path.join(versionDir, entry + ".map"),
"utf-8",
);
const map = findMap(path.join(versionDir, entry + ".map"));

return {
code: code.replace(
Expand Down Expand Up @@ -106,10 +103,7 @@ export function loadPreactVersion(): Plugin {
path.join(versionDir, importee),
"utf-8",
);
const map = fs.readFileSync(
path.join(versionDir, importee + ".map"),
"utf-8",
);
const map = findMap(path.join(versionDir, importee + ".map"));
const out = {
code: code.replace(
/["']preact/g,
Expand Down Expand Up @@ -138,10 +132,7 @@ export function loadPreactVersion(): Plugin {
}

const code = fs.readFileSync(path.join(folder, importee), "utf-8");
const map = fs.readFileSync(
path.join(folder, importee + ".map"),
"utf-8",
);
const map = findMap(path.join(folder, importee + ".map"));
const out = {
code: code.replace(
/(["'])preact/g,
Expand All @@ -162,3 +153,18 @@ export function loadPreactVersion(): Plugin {
},
};
}

// Preact 10's `.mjs` files are renamed copies of the `.module.js` output.
// We don't attempt to rewrite the sourcemap comment paths within, nor do we
// offer `.mjs.map` files, so we need to fallback to `.module.js.map` for X.
function findMap(path: string) {
let map = "";
try {
map = fs.readFileSync(path, "utf-8");
} catch (e) {
if (e.code !== "ENOENT") throw e;
map = fs.readFileSync(path.replace(".mjs", ".module.js"), "utf-8");
}

return map;
}
Loading