fix: unable to load json inside npm packages (#3191)

This commit is contained in:
Marvin Hagemeister
2025-08-05 16:00:58 +02:00
committed by GitHub
parent c2a5812644
commit a6a16dbd18
3 changed files with 103 additions and 391 deletions
+44
View File
@@ -685,6 +685,50 @@ export const app = new App()
sanitizeResources: false,
});
Deno.test({
name: "Builder - island that imports json entry",
fn: async () => {
const root = path.join(import.meta.dirname!, "..", "..");
await using _tmp = await withTmpDir({ dir: root, prefix: "tmp_builder_" });
await using _outDir = await withTmpDir();
const tmp = _tmp.dir;
await writeFiles(tmp, {
"deno.json": JSON.stringify({
links: [path.relative(tmp, root)],
workspace: [],
compilerOptions: {
jsx: "react-jsx",
jsxImportSource: "preact",
},
imports: {
"fresh": "jsr:@fresh/core@*",
"preact": "npm:preact@*",
"@preact/signals": "npm:@preact/signals@*",
"mime-db": "npm:mime-db@*",
},
}),
"islands/Foo.tsx": `import * as mime from "mime-db"
export const Foo = () => {
console.log(mime);
return <h1>ok</h1>
}`,
"routes/index.ts": `export default () => <Foo />`,
"main.ts": `import { App, staticFiles } from "fresh";
export const app = new App()
.use(staticFiles())
.fsRoutes();`,
});
const builder = new Builder({
root: tmp,
});
await builder.build();
},
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test("specToName", () => {
// HTTP
expect(specToName("http://example.com")).toEqual("example");