Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions spec/bun/lucky.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -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)",
Expand Down
3 changes: 2 additions & 1 deletion src/bun/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
})
}
}
Expand Down
Loading