Skip to content

Commit

Permalink
Update esbuild target for Deno (withastro#7687)
Browse files Browse the repository at this point in the history
Co-authored-by: Erika <[email protected]>
  • Loading branch information
kwhinnery and Princesseuh authored Jul 24, 2023
1 parent e80896a commit 0a1b333
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/khaki-chicken-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/deno': minor
---

Update build target for Deno to esnext to allow supported language features on the runtime.
2 changes: 1 addition & 1 deletion packages/integrations/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions packages/integrations/deno/test/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
import { someData } from '../util/data';
import ReactComponent from '../components/React.jsx';
const envValue = import.meta.env.SOME_VARIABLE;
---
Expand All @@ -10,6 +11,7 @@ const envValue = import.meta.env.SOME_VARIABLE;
<body>
<h1>Basic App on Deno</h1>
<p id="env-value">{envValue}</p>
<p id="module-value">{someData.foo}</p>
<ReactComponent />
</body>
</html>
14 changes: 14 additions & 0 deletions packages/integrations/deno/test/fixtures/basics/src/util/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface Data {
foo: string;
}

export async function getData(): Promise<Data> {
return new Promise((resolve, _reject) => {
setTimeout(() => {
resolve({ foo: "bar" });
}, 100);
});
}

// Testing top-level await, a feature supported in esnext
export const someData = await getData();

0 comments on commit 0a1b333

Please sign in to comment.