Fix tsconfig alias baseUrl handling for "." and ".." imports (#6920)

This commit is contained in:
Bjorn Lu 2023-04-27 18:30:17 +08:00 committed by GitHub
parent 465a1a5efe
commit b89042553e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix tsconfig alias baseUrl handling for "." and ".." imports

View file

@ -48,7 +48,7 @@ const getConfigAlias = (settings: AstroSettings): Alias[] | null => {
// - `baseUrl` changes the way non-relative specifiers are resolved
// - if `baseUrl` exists then all non-relative specifiers are resolved relative to it
aliases.push({
find: /^(?!\.*\/|\w:)(.+)$/,
find: /^(?!\.*\/|\.*$|\w:)(.+)$/,
replacement: `${[...normalizePath(resolvedBaseUrl)]
.map((segment) => (segment === '$' ? '$$' : segment))
.join('')}/$1`,

View file

@ -61,6 +61,7 @@ describe('Aliases with tsconfig.json', () => {
expect($('#foo').text()).to.equal('foo');
expect($('#constants-foo').text()).to.equal('foo');
expect($('#constants-index').text()).to.equal('index');
});
it('can load namespace packages with @* paths', async () => {
@ -107,6 +108,7 @@ describe('Aliases with tsconfig.json', () => {
expect($('#foo').text()).to.equal('foo');
expect($('#constants-foo').text()).to.equal('foo');
expect($('#constants-index').text()).to.equal('index');
});
it('can load namespace packages with @* paths', async () => {

View file

@ -4,7 +4,7 @@ import Foo from 'src/components/Foo.astro';
import StyleComp from 'src/components/Style.astro';
import Alias from '@components/Alias.svelte';
import { namespace } from '@test/namespace-package'
import { foo } from 'src/utils/constants';
import { foo, index } from 'src/utils/constants';
import '@styles/main.css';
---
<html lang="en">
@ -21,6 +21,7 @@ import '@styles/main.css';
<Alias client:load />
<p id="namespace">{namespace}</p>
<p id="constants-foo">{foo}</p>
<p id="constants-index">{index}</p>
<p id="style-red">style-red</p>
<p id="style-blue">style-blue</p>
</main>

View file

@ -1 +1,3 @@
export * from '.'
export const foo = 'foo'

View file

@ -0,0 +1 @@
export const index = 'index'