mirror of
https://github.com/withastro/astro.git
synced 2025-01-13 22:11:20 -05:00
Allow importing .ts files with .js extension
This commit is contained in:
parent
d9a67d36dc
commit
c6f337745b
5 changed files with 41 additions and 0 deletions
|
@ -216,6 +216,13 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
|||
return {
|
||||
code: `${code}${SUFFIX}`,
|
||||
map,
|
||||
meta: {
|
||||
vite: {
|
||||
// Setting this vite metadata to `ts` causes Vite to resolve .js
|
||||
// extensions to .ts files.
|
||||
lang: 'ts'
|
||||
}
|
||||
}
|
||||
};
|
||||
} catch (err: any) {
|
||||
// Verify frontmatter: a common reason that this plugin fails is that
|
||||
|
|
3
packages/astro/test/fixtures/import-ts-with-js/src/bar.ts
vendored
Normal file
3
packages/astro/test/fixtures/import-ts-with-js/src/bar.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default function() {
|
||||
return 'bar';
|
||||
}
|
3
packages/astro/test/fixtures/import-ts-with-js/src/foo.ts
vendored
Normal file
3
packages/astro/test/fixtures/import-ts-with-js/src/foo.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
import bar from './bar.js';
|
||||
|
||||
export default bar;
|
9
packages/astro/test/fixtures/import-ts-with-js/src/pages/index.astro
vendored
Normal file
9
packages/astro/test/fixtures/import-ts-with-js/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
import foo from '../foo.js';
|
||||
---
|
||||
<html>
|
||||
<head><title></title></head>
|
||||
<body>
|
||||
<h1>{ foo() }</h1>
|
||||
</body>
|
||||
</html>
|
19
packages/astro/test/import-ts-with-js.test.js
Normal file
19
packages/astro/test/import-ts-with-js.test.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { expect } from 'chai';
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
describe('Using .js extension on .ts file', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({ root: './fixtures/import-ts-with-js/' });
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('works', async () => {
|
||||
const html = await fixture.readFile('/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
expect($('h1').text()).to.equal('bar');
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue