Skip to content

Commit

Permalink
fix: vite failing in dev when source map is empty string (#39)
Browse files Browse the repository at this point in the history
* fix: `deno.lock` integrity error not being shown

* fix: vite failing in dev when source map is empty string
  • Loading branch information
marvinhagemeister authored Jan 30, 2025
1 parent 5cda6a8 commit 2d1d989
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
8 changes: 7 additions & 1 deletion src/resolvePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ export default function denoPlugin(
logLevel: "debug",
});

// Issue: https://github.com/denoland/deno-vite-plugin/issues/38
// Esbuild uses an empty string as empty value and vite expects
// `null` to be the empty value. This seems to be only the case in
// `dev` mode
const map = result.map === "" ? null : result.map;

return {
code: result.code,
map: result.map,
map,
};
},
};
Expand Down
11 changes: 8 additions & 3 deletions src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ export async function resolveDeno(
// There is no JS-API in Deno to get the final file path in Deno's
// cache directory. The `deno info` command reveals that information
// though, so we can use that.
const output = await new Promise<string | null>((resolve) => {
const output = await new Promise<string | null>((resolve, reject) => {
execFile(DENO_BINARY, ["info", "--json", id], { cwd }, (error, stdout) => {
if (error) resolve(null);
else resolve(stdout);
if (error) {
if (String(error).includes("Integrity check failed")) {
reject(error);
} else {
resolve(null);
}
} else resolve(stdout);
});
});

Expand Down
20 changes: 7 additions & 13 deletions tests/fixture/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2d1d989

Please sign in to comment.