diff --git a/src/build/esbuild.ts b/src/build/esbuild.ts index 051a8a9b..fc9f90e6 100644 --- a/src/build/esbuild.ts +++ b/src/build/esbuild.ts @@ -2,7 +2,7 @@ import { type BuildOptions, type OnLoadOptions, type Plugin, -} from "https://deno.land/x/esbuild@v0.19.4/mod.js"; +} from "https://deno.land/x/esbuild@v0.19.11/mod.js"; import { denoPlugins, fromFileUrl, regexpEscape, relative } from "./deps.ts"; import { Builder, BuildSnapshot } from "./mod.ts"; @@ -39,10 +39,10 @@ export class EsbuildBuilder implements Builder { // deno-lint-ignore no-deprecated-deno-api Deno.run === undefined || Deno.env.get("FRESH_ESBUILD_LOADER") === "portable" - ? await import("https://deno.land/x/esbuild@v0.19.4/wasm.js") - : await import("https://deno.land/x/esbuild@v0.19.4/mod.js"); + ? await import("https://deno.land/x/esbuild@v0.19.11/wasm.js") + : await import("https://deno.land/x/esbuild@v0.19.11/mod.js"); const esbuildWasmURL = - new URL("./esbuild_v0.19.4.wasm", import.meta.url).href; + new URL("./esbuild_v0.19.11.wasm", import.meta.url).href; // deno-lint-ignore no-deprecated-deno-api if (Deno.run === undefined) { @@ -97,6 +97,7 @@ export class EsbuildBuilder implements Builder { plugins: [ devClientUrlPlugin(opts.basePath), buildIdPlugin(opts.buildID), + // @ts-ignore TODO: types in esbuild loader need to be updated ...denoPlugins({ configPath: opts.configPath }), ], }); @@ -104,9 +105,11 @@ export class EsbuildBuilder implements Builder { const files = new Map(); const dependencies = new Map(); - for (const file of bundle.outputFiles) { - const path = relative(absWorkingDir, file.path); - files.set(path, file.contents); + if (bundle.outputFiles) { + for (const file of bundle.outputFiles) { + const path = relative(absWorkingDir, file.path); + files.set(path, file.contents); + } } files.set( @@ -114,13 +117,15 @@ export class EsbuildBuilder implements Builder { new TextEncoder().encode(JSON.stringify(bundle.metafile)), ); - const metaOutputs = new Map(Object.entries(bundle.metafile.outputs)); + if (bundle.metafile) { + const metaOutputs = new Map(Object.entries(bundle.metafile.outputs)); - for (const [path, entry] of metaOutputs.entries()) { - const imports = entry.imports - .filter(({ kind }) => kind === "import-statement") - .map(({ path }) => path); - dependencies.set(path, imports); + for (const [path, entry] of metaOutputs.entries()) { + const imports = entry.imports + .filter(({ kind }) => kind === "import-statement") + .map(({ path }) => path); + dependencies.set(path, imports); + } } return new EsbuildSnapshot(files, dependencies); diff --git a/src/build/esbuild_v0.19.4.wasm b/src/build/esbuild_v0.19.11.wasm similarity index 64% rename from src/build/esbuild_v0.19.4.wasm rename to src/build/esbuild_v0.19.11.wasm index 6e465479..6b208de4 100644 Binary files a/src/build/esbuild_v0.19.4.wasm and b/src/build/esbuild_v0.19.11.wasm differ diff --git a/tests/fixture/fresh.gen.ts b/tests/fixture/fresh.gen.ts index feaf1c2e..bc2a6804 100644 --- a/tests/fixture/fresh.gen.ts +++ b/tests/fixture/fresh.gen.ts @@ -35,6 +35,7 @@ import * as $i18n_lang_lang from "./routes/i18n/[[lang]]/lang.tsx"; import * as $index from "./routes/index.tsx"; import * as $intercept from "./routes/intercept.tsx"; import * as $intercept_args from "./routes/intercept_args.tsx"; +import * as $island_json from "./routes/island_json.tsx"; import * as $islands_index from "./routes/islands/index.tsx"; import * as $islands_multiple_island_exports from "./routes/islands/multiple_island_exports.tsx"; import * as $islands_returning_null from "./routes/islands/returning_null.tsx"; @@ -88,6 +89,7 @@ import * as $Foo_Bar from "./islands/Foo.Bar.tsx"; import * as $FormIsland from "./islands/FormIsland.tsx"; import * as $Greeter from "./islands/Greeter.tsx"; import * as $HookIsland from "./islands/HookIsland.tsx"; +import * as $JsonIsland from "./islands/JsonIsland.tsx"; import * as $MultipleCounters from "./islands/MultipleCounters.tsx"; import * as $ReturningNull from "./islands/ReturningNull.tsx"; import * as $RootFragment from "./islands/RootFragment.tsx"; @@ -139,6 +141,7 @@ const manifest = { "./routes/index.tsx": $index, "./routes/intercept.tsx": $intercept, "./routes/intercept_args.tsx": $intercept_args, + "./routes/island_json.tsx": $island_json, "./routes/islands/index.tsx": $islands_index, "./routes/islands/multiple_island_exports.tsx": $islands_multiple_island_exports, @@ -209,6 +212,7 @@ const manifest = { "./islands/FormIsland.tsx": $FormIsland, "./islands/Greeter.tsx": $Greeter, "./islands/HookIsland.tsx": $HookIsland, + "./islands/JsonIsland.tsx": $JsonIsland, "./islands/MultipleCounters.tsx": $MultipleCounters, "./islands/ReturningNull.tsx": $ReturningNull, "./islands/RootFragment.tsx": $RootFragment, diff --git a/tests/fixture/islands/JsonIsland.tsx b/tests/fixture/islands/JsonIsland.tsx new file mode 100644 index 00000000..5feee1c6 --- /dev/null +++ b/tests/fixture/islands/JsonIsland.tsx @@ -0,0 +1,5 @@ +import json from "./data.json" with { type: "json" }; + +export default function JsonIsland() { + return
{JSON.stringify(json,null, 2)}
; +} diff --git a/tests/fixture/islands/data.json b/tests/fixture/islands/data.json new file mode 100644 index 00000000..e99d055b --- /dev/null +++ b/tests/fixture/islands/data.json @@ -0,0 +1,3 @@ +{ + "foo": "it works" +} diff --git a/tests/fixture/routes/island_json.tsx b/tests/fixture/routes/island_json.tsx new file mode 100644 index 00000000..4aee517a --- /dev/null +++ b/tests/fixture/routes/island_json.tsx @@ -0,0 +1,5 @@ +import JsonIsland from "../islands/JsonIsland.tsx"; + +export default function Page() { + return ; +} diff --git a/tests/islands_test.ts b/tests/islands_test.ts index 332a21db..37f753a3 100644 --- a/tests/islands_test.ts +++ b/tests/islands_test.ts @@ -98,6 +98,17 @@ Deno.test("island tests with ", async (t) => { }); }); +Deno.test("island with json import", async () => { + await withPage(async (page, address) => { + await page.goto(`${address}/island_json`, { + waitUntil: "networkidle2", + }); + + const json = await page.$eval("pre", (el) => el.textContent); + assertEquals(JSON.parse(json), { foo: "it works" }); + }); +}); + Deno.test("island with fragment as root", async () => { await withPage(async (page, address) => { await page.goto(`${address}/islands/root_fragment`);