From 207f58d1715ac024cc7c81b76e26aa49fca5173f Mon Sep 17 00:00:00 2001 From: William Tetlow <9057181+williamtetlow@users.noreply.github.com> Date: Thu, 2 Jun 2022 18:54:35 +0100 Subject: [PATCH] fix: alias astro to @types/astro (#3503) * fix: alias astro to @types/astro * fix: handle resolve.alias being array * chore: add integrations patch to changeset * chore: remove empty file --- .changeset/spicy-turkeys-clean.md | 8 ++++++++ packages/astro/src/core/create-vite.ts | 18 +++++++++++++----- .../type-imports/src/pages/index.astro | 19 +++++++++++++++++++ packages/astro/test/type-imports.test.js | 16 ++++++++++++++++ packages/integrations/deno/src/index.ts | 13 +++++++++++-- .../netlify/src/integration-edge-functions.ts | 13 +++++++++++-- 6 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 .changeset/spicy-turkeys-clean.md create mode 100644 packages/astro/test/fixtures/type-imports/src/pages/index.astro create mode 100644 packages/astro/test/type-imports.test.js diff --git a/.changeset/spicy-turkeys-clean.md b/.changeset/spicy-turkeys-clean.md new file mode 100644 index 000000000..d417138b1 --- /dev/null +++ b/.changeset/spicy-turkeys-clean.md @@ -0,0 +1,8 @@ +--- +'astro': patch +'@astrojs/deno': patch +'@astrojs/netlify': patch +--- + +Alias `from 'astro'` imports to `'@astro/types'` +Update Deno and Netlify integrations to handle vite.resolves.alias as an array diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index 8270028d4..a3feff5aa 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -96,11 +96,19 @@ export async function createVite( postcss: astroConfig.style.postcss || {}, }, resolve: { - alias: { - // This is needed for Deno compatibility, as the non-browser version - // of this module depends on Node `crypto` - randombytes: 'randombytes/browser', - }, + alias: [ + { + // This is needed for Deno compatibility, as the non-browser version + // of this module depends on Node `crypto` + find: 'randombytes', + replacement: 'randombytes/browser', + }, + { + // Typings are imported from 'astro' (e.g. import { Type } from 'astro') + find: /^astro$/, + replacement: fileURLToPath(new URL('../@types/astro', import.meta.url)), + }, + ], }, // Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html) ssr: { diff --git a/packages/astro/test/fixtures/type-imports/src/pages/index.astro b/packages/astro/test/fixtures/type-imports/src/pages/index.astro new file mode 100644 index 000000000..3577834fb --- /dev/null +++ b/packages/astro/test/fixtures/type-imports/src/pages/index.astro @@ -0,0 +1,19 @@ +--- +import type { MarkdownInstance } from 'astro' +--- + +
+ + +