Skip to content

Commit

Permalink
Fix tsconfig alias baseUrl handling for "." and ".." imports (#6920)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Apr 27, 2023
1 parent 465a1a5 commit b890425
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-plums-drum.md
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix tsconfig alias baseUrl handling for "." and ".." imports
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-config-alias/index.ts
Expand Up @@ -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`,
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/test/alias-tsconfig.test.js
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
Expand Up @@ -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">
Expand All @@ -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>
Expand Down
@@ -1 +1,3 @@
export * from '.'

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

0 comments on commit b890425

Please sign in to comment.