diff --git a/.changeset/funny-plums-drum.md b/.changeset/funny-plums-drum.md
new file mode 100644
index 000000000..7409d3f34
--- /dev/null
+++ b/.changeset/funny-plums-drum.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix tsconfig alias baseUrl handling for "." and ".." imports
diff --git a/packages/astro/src/vite-plugin-config-alias/index.ts b/packages/astro/src/vite-plugin-config-alias/index.ts
index 5cd7a7623..b3698c834 100644
--- a/packages/astro/src/vite-plugin-config-alias/index.ts
+++ b/packages/astro/src/vite-plugin-config-alias/index.ts
@@ -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`,
diff --git a/packages/astro/test/alias-tsconfig.test.js b/packages/astro/test/alias-tsconfig.test.js
index 84dd50c2f..4668ea66e 100644
--- a/packages/astro/test/alias-tsconfig.test.js
+++ b/packages/astro/test/alias-tsconfig.test.js
@@ -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 () => {
diff --git a/packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro b/packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro
index a3feb613b..076d608c6 100644
--- a/packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro
+++ b/packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro
@@ -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';
---
@@ -21,6 +21,7 @@ import '@styles/main.css';
{namespace}
{foo}
+{index}
style-red
style-blue
diff --git a/packages/astro/test/fixtures/alias-tsconfig/src/utils/constants.js b/packages/astro/test/fixtures/alias-tsconfig/src/utils/constants.js index cb3564682..28e8a5c17 100644 --- a/packages/astro/test/fixtures/alias-tsconfig/src/utils/constants.js +++ b/packages/astro/test/fixtures/alias-tsconfig/src/utils/constants.js @@ -1 +1,3 @@ +export * from '.' + export const foo = 'foo' diff --git a/packages/astro/test/fixtures/alias-tsconfig/src/utils/index.js b/packages/astro/test/fixtures/alias-tsconfig/src/utils/index.js new file mode 100644 index 000000000..96896d711 --- /dev/null +++ b/packages/astro/test/fixtures/alias-tsconfig/src/utils/index.js @@ -0,0 +1 @@ +export const index = 'index'