Skip to content

Commit b1d56a8

Browse files
committed
fix(publish): retain Redis command assets
1 parent 80af56b commit b1d56a8

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
"scripts": {
2828
"build": "bun --bun build.ts",
29-
"verify:package": "bun --bun run build && bun scripts/verify-published-artifact.ts",
29+
"verify:package": "bun run --cwd packages/bun-queue build.ts && bun scripts/verify-published-artifact.ts",
3030
"compile": "bun build ./bin/cli.ts --compile --minify --outfile bin/queue",
3131
"compile:all": "bun run compile:linux-x64 && bun run compile:linux-arm64 && bun run compile:windows-x64 && bun run compile:darwin-x64 && bun run compile:darwin-arm64",
3232
"compile:linux-x64": "bun build ./bin/cli.ts --compile --minify --target=bun-linux-x64 --outfile bin/queue-linux-x64",

packages/bun-queue/build.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { dts } from 'bun-plugin-dtsx'
2+
import { cpSync, rmSync, statSync } from 'node:fs'
23

34
// Library build only. The CLI (bin/cli.ts) is shipped as a compiled
45
// binary via the `compile` script, not through dist — including it here
56
// shifted Bun's output root and emitted dist/src/index.js instead of the
67
// dist/index.js that package exports resolve to.
8+
rmSync('./dist', { recursive: true, force: true })
9+
710
await Bun.build({
811
entrypoints: ['src/index.ts'],
912
outdir: './dist',
1013
target: 'bun',
1114
minify: true,
1215
plugins: [dts({ build: { config: { root: 'src' } } })],
1316
})
17+
18+
// Redis commands are runtime assets loaded relative to the compiled module.
19+
// Keep the package-local build used by prepublishOnly complete on a clean
20+
// checkout instead of relying on a prior root build to populate dist.
21+
cpSync('src/commands', 'dist/commands', {
22+
recursive: true,
23+
filter: source => statSync(source).isDirectory() || source.endsWith('.lua'),
24+
})

scripts/verify-published-artifact.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33
import { existsSync } from 'node:fs'
44
import { resolve } from 'node:path'
55

6+
interface PackedFile { path: string }
7+
interface PackReport { files?: PackedFile[] }
8+
9+
const pack = Bun.spawnSync([
10+
'npm',
11+
'pack',
12+
'--dry-run',
13+
'--json',
14+
'--workspace',
15+
'packages/bun-queue',
16+
], {
17+
cwd: resolve(import.meta.dir, '..'),
18+
stdout: 'pipe',
19+
stderr: 'pipe',
20+
})
21+
if (!pack.success)
22+
throw new Error(`npm pack verification failed: ${pack.stderr.toString()}`)
23+
24+
const reports = JSON.parse(pack.stdout.toString()) as PackReport[]
25+
const packedFiles = new Set(reports[0]?.files?.map(file => file.path) || [])
26+
if (!packedFiles.has('dist/commands/addStandardJob-8.lua') || !packedFiles.has('dist/commands/includes/storeJob.lua'))
27+
throw new Error('Publishable npm tarball is missing Redis command assets')
28+
629
const commandDir = resolve(import.meta.dir, '../packages/bun-queue/dist/commands')
730
if (!existsSync(resolve(commandDir, 'addStandardJob-8.lua')) || !existsSync(resolve(commandDir, 'includes/storeJob.lua')))
831
throw new Error('Published dist is missing Redis command assets')
@@ -22,7 +45,7 @@ try {
2245
if (stored?.data?.artifact !== 'published-dist') throw new Error('Published queue could not round-trip a job')
2346
await queue.removeJob(job.id)
2447
if (await queue.getJob(job.id)) throw new Error('Published queue could not remove a job')
25-
console.log(`Published queue artifact loaded ${commandDir} and passed a live Redis round trip`)
48+
console.log(`Publishable npm artifact includes ${packedFiles.size} files, loaded ${commandDir}, and passed a live Redis round trip`)
2649
}
2750
finally {
2851
await queue.empty()

0 commit comments

Comments
 (0)