Skip to content

Commit b890425

Browse files
authored
Fix tsconfig alias baseUrl handling for "." and ".." imports (#6920)
1 parent 465a1a5 commit b890425

File tree

6 files changed

+13
-2
lines changed

6 files changed

+13
-2
lines changed

.changeset/funny-plums-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fix tsconfig alias baseUrl handling for "." and ".." imports

packages/astro/src/vite-plugin-config-alias/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const getConfigAlias = (settings: AstroSettings): Alias[] | null => {
4848
// - `baseUrl` changes the way non-relative specifiers are resolved
4949
// - if `baseUrl` exists then all non-relative specifiers are resolved relative to it
5050
aliases.push({
51-
find: /^(?!\.*\/|\w:)(.+)$/,
51+
find: /^(?!\.*\/|\.*$|\w:)(.+)$/,
5252
replacement: `${[...normalizePath(resolvedBaseUrl)]
5353
.map((segment) => (segment === '$' ? '$$' : segment))
5454
.join('')}/$1`,

packages/astro/test/alias-tsconfig.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe('Aliases with tsconfig.json', () => {
6161

6262
expect($('#foo').text()).to.equal('foo');
6363
expect($('#constants-foo').text()).to.equal('foo');
64+
expect($('#constants-index').text()).to.equal('index');
6465
});
6566

6667
it('can load namespace packages with @* paths', async () => {
@@ -107,6 +108,7 @@ describe('Aliases with tsconfig.json', () => {
107108

108109
expect($('#foo').text()).to.equal('foo');
109110
expect($('#constants-foo').text()).to.equal('foo');
111+
expect($('#constants-index').text()).to.equal('index');
110112
});
111113

112114
it('can load namespace packages with @* paths', async () => {

packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Foo from 'src/components/Foo.astro';
44
import StyleComp from 'src/components/Style.astro';
55
import Alias from '@components/Alias.svelte';
66
import { namespace } from '@test/namespace-package'
7-
import { foo } from 'src/utils/constants';
7+
import { foo, index } from 'src/utils/constants';
88
import '@styles/main.css';
99
---
1010
<html lang="en">
@@ -21,6 +21,7 @@ import '@styles/main.css';
2121
<Alias client:load />
2222
<p id="namespace">{namespace}</p>
2323
<p id="constants-foo">{foo}</p>
24+
<p id="constants-index">{index}</p>
2425
<p id="style-red">style-red</p>
2526
<p id="style-blue">style-blue</p>
2627
</main>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
export * from '.'
2+
13
export const foo = 'foo'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const index = 'index'

0 commit comments

Comments
 (0)