Skip to content

Commit

Permalink
Revert "Fix tsconfig alias regression (#6617)"
Browse files Browse the repository at this point in the history
This reverts commit 38e6ec2.
  • Loading branch information
bholmesdev committed Mar 23, 2023
1 parent 58c612b commit 8726aa3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
12 changes: 5 additions & 7 deletions packages/astro/src/vite-plugin-config-alias/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,16 @@ export default function configAliasVitePlugin({
};
}
},
async resolveId(id, importer, options) {
if (id.startsWith('.') || path.isAbsolute(id)) return;
resolveId(id) {
if (id.startsWith('.') || id.startsWith('/')) 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);

return await this.resolve(resolved, importer, {
skipSelf: true,
...options,
});
if (fs.existsSync(resolved)) {
return resolved;
}
},
};
}
8 changes: 1 addition & 7 deletions packages/astro/test/alias-tsconfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,10 @@ 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!");
});
});
});
32 changes: 14 additions & 18 deletions packages/astro/test/fixtures/alias-tsconfig/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
---
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 { whoImI } from 'src/ts-file';
const mistery = whoImI();
import '@styles/main.css'
---

<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 />
<div id="mistery">{mistery}</div>
</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 />
</main>
</body>
</html>
3 changes: 0 additions & 3 deletions packages/astro/test/fixtures/alias-tsconfig/src/ts-file.ts

This file was deleted.

0 comments on commit 8726aa3

Please sign in to comment.