Fix tsconfig alias baseUrl handling for "." and ".." imports (#6920)
This commit is contained in:
parent
465a1a5efe
commit
b89042553e
6 changed files with 13 additions and 2 deletions
5
.changeset/funny-plums-drum.md
Normal file
5
.changeset/funny-plums-drum.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix tsconfig alias baseUrl handling for "." and ".." imports
|
|
@ -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`,
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
export * from '.'
|
||||
|
||||
export const foo = 'foo'
|
||||
|
|
1
packages/astro/test/fixtures/alias-tsconfig/src/utils/index.js
vendored
Normal file
1
packages/astro/test/fixtures/alias-tsconfig/src/utils/index.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export const index = 'index'
|
Loading…
Reference in a new issue