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
This commit is contained in:
parent
67ad33debf
commit
207f58d171
6 changed files with 78 additions and 9 deletions
8
.changeset/spicy-turkeys-clean.md
Normal file
8
.changeset/spicy-turkeys-clean.md
Normal file
|
@ -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
|
|
@ -96,11 +96,19 @@ export async function createVite(
|
||||||
postcss: astroConfig.style.postcss || {},
|
postcss: astroConfig.style.postcss || {},
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: [
|
||||||
// This is needed for Deno compatibility, as the non-browser version
|
{
|
||||||
// of this module depends on Node `crypto`
|
// This is needed for Deno compatibility, as the non-browser version
|
||||||
randombytes: 'randombytes/browser',
|
// 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)
|
// Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html)
|
||||||
ssr: {
|
ssr: {
|
||||||
|
|
19
packages/astro/test/fixtures/type-imports/src/pages/index.astro
vendored
Normal file
19
packages/astro/test/fixtures/type-imports/src/pages/index.astro
vendored
Normal file
|
@ -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>
|
16
packages/astro/test/type-imports.test.js
Normal file
16
packages/astro/test/type-imports.test.js
Normal file
|
@ -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;
|
||||||
|
});
|
||||||
|
});
|
|
@ -25,8 +25,17 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
||||||
if (target === 'server') {
|
if (target === 'server') {
|
||||||
vite.resolve = vite.resolve || {};
|
vite.resolve = vite.resolve || {};
|
||||||
vite.resolve.alias = vite.resolve.alias || {};
|
vite.resolve.alias = vite.resolve.alias || {};
|
||||||
const alias = vite.resolve.alias as Record<string, string>;
|
|
||||||
alias['react-dom/server'] = 'react-dom/server.browser';
|
const aliases = [{ find: 'react-dom/server', replacement: 'react-dom/server.browser' }];
|
||||||
|
|
||||||
|
if (Array.isArray(vite.resolve.alias)) {
|
||||||
|
vite.resolve.alias = [...vite.resolve.alias, ...aliases];
|
||||||
|
} else {
|
||||||
|
for (const alias of aliases) {
|
||||||
|
(vite.resolve.alias as Record<string, string>)[alias.find] = alias.replacement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vite.ssr = {
|
vite.ssr = {
|
||||||
noExternal: true,
|
noExternal: true,
|
||||||
};
|
};
|
||||||
|
|
|
@ -89,8 +89,17 @@ export function netlifyEdgeFunctions({ dist }: NetlifyEdgeFunctionsOptions = {})
|
||||||
if (target === 'server') {
|
if (target === 'server') {
|
||||||
vite.resolve = vite.resolve || {};
|
vite.resolve = vite.resolve || {};
|
||||||
vite.resolve.alias = vite.resolve.alias || {};
|
vite.resolve.alias = vite.resolve.alias || {};
|
||||||
const alias = vite.resolve.alias as Record<string, string>;
|
|
||||||
alias['react-dom/server'] = 'react-dom/server.browser';
|
const aliases = [{ find: 'react-dom/server', replacement: 'react-dom/server.browser' }];
|
||||||
|
|
||||||
|
if (Array.isArray(vite.resolve.alias)) {
|
||||||
|
vite.resolve.alias = [...vite.resolve.alias, ...aliases];
|
||||||
|
} else {
|
||||||
|
for (const alias of aliases) {
|
||||||
|
(vite.resolve.alias as Record<string, string>)[alias.find] = alias.replacement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vite.ssr = {
|
vite.ssr = {
|
||||||
noExternal: true,
|
noExternal: true,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue