mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
Fix tsconfig alias regression (#6617)
This commit is contained in:
parent
b37b865400
commit
38e6ec21e2
5 changed files with 40 additions and 20 deletions
5
.changeset/curly-wasps-matter.md
Normal file
5
.changeset/curly-wasps-matter.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix tsconfig alias regression
|
|
@ -72,16 +72,18 @@ export default function configAliasVitePlugin({
|
|||
};
|
||||
}
|
||||
},
|
||||
resolveId(id) {
|
||||
if (id.startsWith('.') || id.startsWith('/')) return;
|
||||
async resolveId(id, importer, options) {
|
||||
if (id.startsWith('.') || path.isAbsolute(id)) return;
|
||||
|
||||
// Handle baseUrl mapping for non-relative and non-root imports.
|
||||
// Since TypeScript only applies `baseUrl` autocompletions for files that exist
|
||||
// in the filesystem only, we can use this heuristic to skip resolve if needed.
|
||||
const resolved = path.posix.join(resolvedBaseUrl, id);
|
||||
if (fs.existsSync(resolved)) {
|
||||
return resolved;
|
||||
}
|
||||
|
||||
return await this.resolve(resolved, importer, {
|
||||
skipSelf: true,
|
||||
...options,
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -44,10 +44,16 @@ describe('Aliases with tsconfig.json', () => {
|
|||
|
||||
it('works in css @import', async () => {
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
console.log(html);
|
||||
// imported css should be bundled
|
||||
expect(html).to.include('#style-red');
|
||||
expect(html).to.include('#style-blue');
|
||||
});
|
||||
|
||||
it('can load load typescript files without .ts or .d.ts extensions', async () => {
|
||||
const html = await fixture.fetch('/').then((res) => res.text());
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('#mistery').text()).to.equal("I'm a TypeScript file!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,20 +1,24 @@
|
|||
---
|
||||
import Client from '@components/Client.svelte'
|
||||
import Client from '@components/Client.svelte';
|
||||
import Foo from 'src/components/Foo.astro';
|
||||
import StyleComp from 'src/components/Style.astro';
|
||||
import '@styles/main.css'
|
||||
import '@styles/main.css';
|
||||
import { whoImI } from 'src/ts-file';
|
||||
const mistery = whoImI();
|
||||
---
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Aliases using tsconfig</title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<Client client:load />
|
||||
<Foo />
|
||||
<StyleComp />
|
||||
</main>
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<title>Aliases using tsconfig</title>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<Client client:load />
|
||||
<Foo />
|
||||
<StyleComp />
|
||||
<div id="mistery">{mistery}</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
|
3
packages/astro/test/fixtures/alias-tsconfig/src/ts-file.ts
vendored
Normal file
3
packages/astro/test/fixtures/alias-tsconfig/src/ts-file.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function whoImI() {
|
||||
return "I'm a TypeScript file!";
|
||||
}
|
Loading…
Reference in a new issue