Skip to content

Commit

Permalink
fix: alias astro to @types/astro
Browse files Browse the repository at this point in the history
  • Loading branch information
williamtetlow committed Jun 2, 2022
1 parent cfb85ee commit c8816d4
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-queens-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Alias imports for astro to @types/astro
18 changes: 13 additions & 5 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
19 changes: 19 additions & 0 deletions packages/astro/test/fixtures/type-imports/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
import type { MarkdownInstance } from 'astro'
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Astro</title>
<style is:global>
h1 {
color: red;
}
</style>
</head>
<body>
<h1>Astro</h1>
<img src="/puppy.png"/>
</body>
</html>
Empty file.
16 changes: 16 additions & 0 deletions packages/astro/test/type-imports.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from 'chai';
import { loadFixture } from './test-utils.js';

describe('Type Imports', async () => {
let fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/type-imports' });
await fixture.build();
});

it('Allows importing types from "astro"', async () => {
// if the build passes then the test succeeds
expect(true).to.be.true;
});
});

0 comments on commit c8816d4

Please sign in to comment.