diff --git a/src/build/deps.ts b/src/build/deps.ts index c84c9c77..c3508ead 100644 --- a/src/build/deps.ts +++ b/src/build/deps.ts @@ -7,14 +7,14 @@ export { escape as regexpEscape } from "https://deno.land/std@0.190.0/regexp/esc // -- esbuild -- // @deno-types="https://deno.land/x/esbuild@v0.17.11/mod.d.ts" -import * as esbuildWasm from "https://deno.land/x/esbuild@v0.17.11/wasm.js"; -import * as esbuildNative from "https://deno.land/x/esbuild@v0.17.11/mod.js"; +import * as esbuildWasm from "https://deno.land/x/esbuild@v0.17.19/wasm.js"; +import * as esbuildNative from "https://deno.land/x/esbuild@v0.17.19/mod.js"; // @ts-ignore trust me // deno-lint-ignore no-deprecated-deno-api const esbuild: typeof esbuildWasm = Deno.run === undefined ? esbuildWasm : esbuildNative; -const esbuildWasmURL = new URL("./esbuild_v0.17.11.wasm", import.meta.url).href; +const esbuildWasmURL = new URL("./esbuild_v0.17.19.wasm", import.meta.url).href; export { esbuild, esbuildWasm as esbuildTypes, esbuildWasmURL }; -export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.7.2/mod.ts"; +export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.1/mod.ts"; diff --git a/src/build/esbuild.ts b/src/build/esbuild.ts index 91aafee2..fa7b0d65 100644 --- a/src/build/esbuild.ts +++ b/src/build/esbuild.ts @@ -54,7 +54,7 @@ export class EsbuildBuilder implements Builder { const bundle = await esbuild.build({ entryPoints: opts.entrypoints, - platform: "neutral", + platform: "browser", target: ["chrome99", "firefox99", "safari15"], format: "esm", diff --git a/src/build/esbuild_v0.17.11.wasm b/src/build/esbuild_v0.17.19.wasm similarity index 62% rename from src/build/esbuild_v0.17.11.wasm rename to src/build/esbuild_v0.17.19.wasm index 359e887a..1d350d7c 100644 Binary files a/src/build/esbuild_v0.17.11.wasm and b/src/build/esbuild_v0.17.19.wasm differ diff --git a/tests/fixture_npm/deno.json b/tests/fixture_npm/deno.json new file mode 100644 index 00000000..f6bc377f --- /dev/null +++ b/tests/fixture_npm/deno.json @@ -0,0 +1,15 @@ +{ + "lock": false, + "imports": { + "$fresh/": "../../", + "preact": "https://esm.sh/preact@10.15.1", + "preact/": "https://esm.sh/preact@10.15.1/", + "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3", + "@preact/signals": "https://esm.sh/*@preact/signals@1.1.3", + "@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3" + }, + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "preact" + } +} diff --git a/tests/fixture_npm/dev.ts b/tests/fixture_npm/dev.ts new file mode 100755 index 00000000..2d85d6c1 --- /dev/null +++ b/tests/fixture_npm/dev.ts @@ -0,0 +1,5 @@ +#!/usr/bin/env -S deno run -A --watch=static/,routes/ + +import dev from "$fresh/dev.ts"; + +await dev(import.meta.url, "./main.ts"); diff --git a/tests/fixture_npm/fresh.gen.ts b/tests/fixture_npm/fresh.gen.ts new file mode 100644 index 00000000..e3235c83 --- /dev/null +++ b/tests/fixture_npm/fresh.gen.ts @@ -0,0 +1,18 @@ +// DO NOT EDIT. This file is generated by fresh. +// This file SHOULD be checked into source version control. +// This file is automatically updated during development when running `dev.ts`. + +import * as $0 from "./routes/index.tsx"; +import * as $$0 from "./islands/Test.tsx"; + +const manifest = { + routes: { + "./routes/index.tsx": $0, + }, + islands: { + "./islands/Test.tsx": $$0, + }, + baseUrl: import.meta.url, +}; + +export default manifest; diff --git a/tests/fixture_npm/islands/Test.tsx b/tests/fixture_npm/islands/Test.tsx new file mode 100644 index 00000000..eefe625a --- /dev/null +++ b/tests/fixture_npm/islands/Test.tsx @@ -0,0 +1,8 @@ +import { IS_BROWSER } from "../../../runtime.ts"; +import isNumber from "npm:is-number"; + +export default function Test() { + let id = IS_BROWSER ? "browser" : "server"; + id += "-" + String(isNumber(1)); + return
{id}
; +} diff --git a/tests/fixture_npm/main.ts b/tests/fixture_npm/main.ts new file mode 100644 index 00000000..bb97cc80 --- /dev/null +++ b/tests/fixture_npm/main.ts @@ -0,0 +1,10 @@ +/// +/// +/// +/// +/// + +import { start } from "$fresh/server.ts"; +import routes from "./fresh.gen.ts"; + +await start(routes); diff --git a/tests/fixture_npm/routes/index.tsx b/tests/fixture_npm/routes/index.tsx new file mode 100644 index 00000000..756b2980 --- /dev/null +++ b/tests/fixture_npm/routes/index.tsx @@ -0,0 +1,9 @@ +import Test from "../islands/Test.tsx"; + +export default function Home() { + return ( +
+ +
+ ); +} diff --git a/tests/islands_test.ts b/tests/islands_test.ts index 3e363865..3b7d3ca5 100644 --- a/tests/islands_test.ts +++ b/tests/islands_test.ts @@ -58,9 +58,13 @@ Deno.test({ sanitizeResources: false, }); -async function withPage(fn: (page: Page) => Promise) { +function withPage(fn: (page: Page) => Promise) { + return withPageName("./tests/fixture/main.ts", fn); +} + +async function withPageName(name: string, fn: (page: Page) => Promise) { const serverProcess = new Deno.Command(Deno.execPath(), { - args: ["run", "-A", "./tests/fixture/main.ts"], + args: ["run", "-A", name], stdout: "piped", stderr: "inherit", }).spawn(); @@ -222,3 +226,22 @@ Deno.test({ sanitizeOps: false, sanitizeResources: false, }); + +Deno.test({ + name: "island using `npm:` specifiers", + + async fn(_t) { + await withPageName("./tests/fixture_npm/main.ts", async (page) => { + await page.setJavaScriptEnabled(false); + await page.goto("http://localhost:8000/", { waitUntil: "networkidle2" }); + assert(await page.waitForSelector("#server-true")); + + await page.setJavaScriptEnabled(true); + await page.reload({ waitUntil: "networkidle2" }); + assert(await page.waitForSelector("#browser-true")); + }); + }, + + sanitizeOps: false, + sanitizeResources: false, +});