From 0a1b33349fc12d9927e6eef2b66588afedf517a1 Mon Sep 17 00:00:00 2001 From: Kevin Whinnery Date: Mon, 24 Jul 2023 10:58:05 -0400 Subject: [PATCH] Update esbuild target for Deno (#7687) Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> --- .changeset/khaki-chicken-pay.md | 5 +++++ packages/integrations/deno/src/index.ts | 2 +- packages/integrations/deno/test/basics.test.ts | 9 +++++++++ .../test/fixtures/basics/src/pages/index.astro | 2 ++ .../deno/test/fixtures/basics/src/util/data.ts | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .changeset/khaki-chicken-pay.md create mode 100644 packages/integrations/deno/test/fixtures/basics/src/util/data.ts diff --git a/.changeset/khaki-chicken-pay.md b/.changeset/khaki-chicken-pay.md new file mode 100644 index 000000000000..02b8ca56d1f8 --- /dev/null +++ b/.changeset/khaki-chicken-pay.md @@ -0,0 +1,5 @@ +--- +'@astrojs/deno': minor +--- + +Update build target for Deno to esnext to allow supported language features on the runtime. diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts index 986449b18700..db645eb697d1 100644 --- a/packages/integrations/deno/src/index.ts +++ b/packages/integrations/deno/src/index.ts @@ -168,7 +168,7 @@ export default function createIntegration(args?: Options): AstroIntegration { const pth = fileURLToPath(entryUrl); await esbuild.build({ - target: 'es2020', + target: 'esnext', platform: 'browser', entryPoints: [pth], outfile: pth, diff --git a/packages/integrations/deno/test/basics.test.ts b/packages/integrations/deno/test/basics.test.ts index 5d3f116ddf1d..cdb0c616e212 100644 --- a/packages/integrations/deno/test/basics.test.ts +++ b/packages/integrations/deno/test/basics.test.ts @@ -67,6 +67,15 @@ Deno.test({ assertEquals(p!.innerText, varContent); }); + await t.step('Can use a module with top-level await', async () => { + const resp = await fetch(app.url); + const html = await resp.text(); + + const doc = new DOMParser().parseFromString(html, `text/html`); + const p = doc!.querySelector('p#module-value'); + assertEquals(p!.innerText, 'bar'); + }); + await t.step('Works with Markdown', async () => { const resp = await fetch(new URL('markdown', app.url)); const html = await resp.text(); diff --git a/packages/integrations/deno/test/fixtures/basics/src/pages/index.astro b/packages/integrations/deno/test/fixtures/basics/src/pages/index.astro index 29fce0190ea1..650f60062aba 100644 --- a/packages/integrations/deno/test/fixtures/basics/src/pages/index.astro +++ b/packages/integrations/deno/test/fixtures/basics/src/pages/index.astro @@ -1,4 +1,5 @@ --- +import { someData } from '../util/data'; import ReactComponent from '../components/React.jsx'; const envValue = import.meta.env.SOME_VARIABLE; --- @@ -10,6 +11,7 @@ const envValue = import.meta.env.SOME_VARIABLE;

Basic App on Deno

{envValue}

+

{someData.foo}

diff --git a/packages/integrations/deno/test/fixtures/basics/src/util/data.ts b/packages/integrations/deno/test/fixtures/basics/src/util/data.ts new file mode 100644 index 000000000000..a9b71d2d951b --- /dev/null +++ b/packages/integrations/deno/test/fixtures/basics/src/util/data.ts @@ -0,0 +1,14 @@ +export interface Data { + foo: string; +} + +export async function getData(): Promise { + return new Promise((resolve, _reject) => { + setTimeout(() => { + resolve({ foo: "bar" }); + }, 100); + }); +} + +// Testing top-level await, a feature supported in esnext +export const someData = await getData();