Update esbuild target for Deno (#7687)

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
Kevin Whinnery 2023-07-24 10:58:05 -04:00 committed by GitHub
parent e80896a67c
commit 0a1b33349f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/deno': minor
---
Update build target for Deno to esnext to allow supported language features on the runtime.

View file

@ -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,

View file

@ -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();

View file

@ -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;
<body>
<h1>Basic App on Deno</h1>
<p id="env-value">{envValue}</p>
<p id="module-value">{someData.foo}</p>
<ReactComponent />
</body>
</html>

View file

@ -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();