@@ -2,6 +2,7 @@ import { mkdtemp, readdir, readFile } from 'node:fs/promises'
22import { tmpdir } from 'node:os'
33import path from 'node:path'
44import { formatWithOptions } from 'node:util'
5+ import { createDebug } from 'obug'
56import { x } from 'tinyexec'
67import { fsRemove } from '../../utils/fs.ts'
78import { promiseWithResolvers } from '../../utils/general.ts'
@@ -13,6 +14,8 @@ import type { ChunksByFormat, TsdownBundle } from '../../utils/chunks.ts'
1314import type { Buffer } from 'node:buffer'
1415import type { DetectResult } from 'package-manager-detector'
1516
17+ const debug = createDebug ( 'tsdown:pkg' )
18+
1619export 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
0 commit comments