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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM crystallang/crystal:latest
WORKDIR /data

COPY --from=oven/bun:latest /usr/local/bin/bun /usr/local/bin/bun

RUN apt-get update && \
apt-get install -y curl libreadline-dev && \
apt-get install -y curl libreadline-dev unzip && \
curl -fsSL https://bun.sh/install | bash && \
ln -s /root/.bun/bin/bun /usr/local/bin/bun && \
# Cleanup leftovers
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Expand Down
2 changes: 1 addition & 1 deletion script/test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -eu

COMPOSE="docker compose run --rm app"
COMPOSE="docker compose run --remove-orphans --rm app"

printf "\nrunning specs with 'crystal spec'\n\n"
$COMPOSE crystal spec "$@"
Expand Down
46 changes: 23 additions & 23 deletions spec/bun/lucky.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,43 +229,43 @@ describe('writeManifest', () => {
await LuckyBun.writeManifest()

const content = readFileSync(
join(TEST_DIR, 'public/assets/manifest.json'),
join(TEST_DIR, 'public/bun-manifest.json'),
'utf-8'
)
expect(JSON.parse(content)).toEqual({'js/app.js': 'js/app-abc123.js'})
})
})

describe('outDir', () => {
test('throws if config not loaded', () => {
LuckyBun.config = null
expect(() => LuckyBun.outDir).toThrow('Config is not loaded')
})

test('returns full path when config loaded', () => {
test('writes manifest relative to project root, not outDir', async () => {
LuckyBun.root = TEST_DIR
LuckyBun.loadConfig()
expect(LuckyBun.outDir).toBe(join(TEST_DIR, 'public/assets'))
LuckyBun.manifest = {'js/app.js': 'js/app-abc123.js'}

await LuckyBun.writeManifest()

const correctPath = join(TEST_DIR, 'public/bun-manifest.json')
const buggyPath = join(TEST_DIR, 'public/assets/public/bun-manifest.json')

expect(existsSync(correctPath)).toBe(true)
expect(existsSync(buggyPath)).toBe(false)
})
})

describe('cssAliasPlugin', () => {
test('replaces $/ with src path', async () => {
mkdirSync(join(TEST_DIR, 'src/css'), {recursive: true})
mkdirSync(join(TEST_DIR, 'src/images'), {recursive: true})
writeFileSync(join(TEST_DIR, 'src/images/bg.png'), 'fake')
test('respects custom manifestPath from config', async () => {
mkdirSync(join(TEST_DIR, 'config'), {recursive: true})
writeFileSync(
join(TEST_DIR, 'src/css/app.css'),
"body { background: url('$/images/bg.png'); }"
join(TEST_DIR, 'config/bun.json'),
JSON.stringify({manifestPath: 'dist/manifest.json'})
)

LuckyBun.root = TEST_DIR
LuckyBun.loadConfig()
await LuckyBun.buildCSS()
LuckyBun.manifest = {'css/app.css': 'css/app-def456.css'}

await LuckyBun.writeManifest()

const manifestPath = join(TEST_DIR, 'dist/manifest.json')
const content = JSON.parse(readFileSync(manifestPath, 'utf-8'))

const cssPath = join(TEST_DIR, 'public/assets/css/app.css')
const content = readFileSync(cssPath, 'utf-8')
expect(content).toContain('/src/')
expect(content).not.toContain('$/')
expect(existsSync(manifestPath)).toBe(true)
expect(content).toEqual({'css/app.css': 'css/app-def456.css'})
})
})
8 changes: 3 additions & 5 deletions src/bun/lucky.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,9 @@ export default {

// Writes the asset manifest.
async writeManifest() {
mkdirSync(this.outDir, {recursive: true})
await Bun.write(
join(this.outDir, this.config.manifestPath),
JSON.stringify(this.manifest, null, 2)
)
const manifestFullPath = join(this.root, this.config.manifestPath)
mkdirSync(dirname(manifestFullPath), {recursive: true})
await Bun.write(manifestFullPath, JSON.stringify(this.manifest, null, 2))
},

// Performs a full new build based on the current environment.
Expand Down