From 2d1d989aaaea268352a9d4a17958c597b81763ee Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 30 Jan 2025 12:44:15 +0100 Subject: [PATCH] fix: vite failing in dev when source map is empty string (#39) * fix: `deno.lock` integrity error not being shown * fix: vite failing in dev when source map is empty string --- src/resolvePlugin.ts | 8 +++++++- src/resolver.ts | 11 ++++++++--- tests/fixture/deno.lock | 20 +++++++------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/resolvePlugin.ts b/src/resolvePlugin.ts index dfad7da..2187388 100644 --- a/src/resolvePlugin.ts +++ b/src/resolvePlugin.ts @@ -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, }; }, }; diff --git a/src/resolver.ts b/src/resolver.ts index 8a0833d..51bb3cd 100644 --- a/src/resolver.ts +++ b/src/resolver.ts @@ -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((resolve) => { + const output = await new Promise((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); }); }); diff --git a/tests/fixture/deno.lock b/tests/fixture/deno.lock index 2471038..19c240f 100644 --- a/tests/fixture/deno.lock +++ b/tests/fixture/deno.lock @@ -1,27 +1,21 @@ { "version": "4", "specifiers": { - "jsr:@std/path@*": "1.0.6", - "jsr:@std/path@^1.0.6": "1.0.6", - "npm:preact@*": "10.24.0", - "npm:preact@^10.24.0": "10.24.0" + "jsr:@std/path@^1.0.6": "1.0.8", + "npm:preact@^10.24.0": "10.25.4" }, "jsr": { - "@std/path@1.0.6": { - "integrity": "ab2c55f902b380cf28e0eec501b4906e4c1960d13f00e11cfbcd21de15f18fed" + "@std/path@1.0.8": { + "integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be" } }, "npm": { - "preact@10.24.0": { - "integrity": "sha512-aK8Cf+jkfyuZ0ZZRG9FbYqwmEiGQ4y/PUO4SuTWoyWL244nZZh7bd5h2APd4rSNDYTBNghg1L+5iJN3Skxtbsw==" + "preact@10.25.4": { + "integrity": "sha512-jLdZDb+Q+odkHJ+MpW/9U5cODzqnB+fy2EiHSZES7ldV5LK7yjlVzTp7R8Xy6W6y75kfK8iWYtFVH7lvjwrCMA==" } }, - "redirects": { - "https://esm.sh/preact": "https://esm.sh/preact@10.24.0" - }, "remote": { - "https://esm.sh/preact@10.24.0": "ab23d4024a0fc68b1632d7e3b5d157d774d5698152b5303adfbda35064e91c7b", - "https://esm.sh/stable/preact@10.24.0/denonext/preact.mjs": "c914516d9df1c45afa542a588beb077ff6a1ab57ec97eb4593006e8794c1752e" + "https://esm.sh/preact@10.25.4/denonext/preact.mjs": "5b19c5a3daab9e9f4f4bed775afbb84dd4de2b8cc670ee332f5458c53a6a2d45" }, "workspace": { "dependencies": [