Skip to content

Commit 5de04ad

Browse files
sxzzCopilot
andcommitted
fix(debug): enhance debug logging for pack tarball
Co-authored-by: Copilot <copilot@github.com>
1 parent 82fa153 commit 5de04ad

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/features/pkg/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { mkdtemp, readdir, readFile } from 'node:fs/promises'
22
import { tmpdir } from 'node:os'
33
import path from 'node:path'
44
import { formatWithOptions } from 'node:util'
5+
import { createDebug } from 'obug'
56
import { x } from 'tinyexec'
67
import { fsRemove } from '../../utils/fs.ts'
78
import { promiseWithResolvers } from '../../utils/general.ts'
@@ -13,6 +14,8 @@ import type { ChunksByFormat, TsdownBundle } from '../../utils/chunks.ts'
1314
import type { Buffer } from 'node:buffer'
1415
import type { DetectResult } from 'package-manager-detector'
1516

17+
const debug = createDebug('tsdown:pkg')
18+
1619
export interface BundleByPkg {
1720
[pkgPath: string]: {
1821
promise: Promise<void>
@@ -122,13 +125,20 @@ async function packTarball(
122125

123126
try {
124127
const detected = await detect({ cwd: pkgDir })
128+
debug('Detected package manager: %o', detected)
125129
if (detected?.name === 'deno') {
126130
throw new Error(`Cannot pack tarball for Deno projects at ${pkgDir}`)
127131
}
128132
const tarballPath = await pack(pkgDir, detected, destination, true)
133+
debug('Packed tarball at %s', tarballPath)
134+
129135
return readFile(tarballPath)
130136
} finally {
131-
await fsRemove(destination)
137+
if (debug.enabled) {
138+
debug('Preserving pack directory for debugging: %s', destination)
139+
} else {
140+
await fsRemove(destination)
141+
}
132142
}
133143
}
134144

src/features/rolldown.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ async function resolveOutputOptions(
278278
}
279279

280280
export async function getDebugRolldownDir(): Promise<string | undefined> {
281-
if (!debug.enabled) return
282-
return await mkdtemp(path.join(tmpdir(), 'tsdown-config-'))
281+
if (debug.enabled) {
282+
return await mkdtemp(path.join(tmpdir(), 'tsdown-config-'))
283+
}
283284
}
284285

285286
export async function debugBuildOptions(

0 commit comments

Comments
 (0)