diff --git a/spec/bun/lucky.test.js b/spec/bun/lucky.test.js index 181235e08..c10dc13bd 100644 --- a/spec/bun/lucky.test.js +++ b/spec/bun/lucky.test.js @@ -200,6 +200,34 @@ describe('buildAssets', () => { expect(LuckyBun.manifest['js/admin.js']).toBe('js/admin.js') }) + test('builds TypeScript files', async () => { + await setupProject( + {'src/js/app.ts': 'const msg: string = "hello"\nconsole.log(msg)'}, + {entryPoints: {js: ['src/js/app.ts']}} + ) + await LuckyBun.buildJS() + + expect(LuckyBun.manifest['js/app.js']).toBe('js/app.js') + expect(existsSync(join(TEST_DIR, 'public/assets/js/app.js'))).toBe(true) + expect(readOutput('js/app.js')).toContain('hello') + }) + + test('builds TSX files', async () => { + await setupProject( + { + 'src/js/app.tsx': [ + 'function App(): string { return "tsx works" }', + 'console.log(App())' + ].join('\n') + }, + {entryPoints: {js: ['src/js/app.tsx']}} + ) + await LuckyBun.buildJS() + + expect(LuckyBun.manifest['js/app.js']).toBe('js/app.js') + expect(existsSync(join(TEST_DIR, 'public/assets/js/app.js'))).toBe(true) + }) + test('builds multiple CSS entry points', async () => { await buildCSS( { @@ -388,6 +416,21 @@ describe('aliases plugin', () => { expect(content).toContain('https://example.com/bg.png') }) + test('replaces $/ references in TypeScript imports', async () => { + await setupProject( + { + 'src/js/app.ts': "import utils from '$/lib/utils.ts'\nconsole.log(utils)", + 'lib/utils.ts': 'const val: number = 99\nexport default val' + }, + {entryPoints: {js: ['src/js/app.ts']}} + ) + await LuckyBun.buildJS() + const content = readOutput('js/app.js') + + expect(content).not.toContain('$/') + expect(content).toContain('99') + }) + test('leaves non-alias imports untouched', async () => { const content = await buildJS({ 'src/js/app.js': "import {x} from './utils.js'\nconsole.log(x)", diff --git a/src/bun/plugins/index.js b/src/bun/plugins/index.js index 2c23590eb..47f42ac0f 100644 --- a/src/bun/plugins/index.js +++ b/src/bun/plugins/index.js @@ -20,7 +20,8 @@ function transformPipeline(type, transforms) { let content = await Bun.file(args.path).text() for (const transform of transforms) content = await transform(content, args) - return {contents: content, loader: type} + const ext = args.path.split('.').pop() + return {contents: content, loader: ext} }) } }