Skip to content

Commit 709f2e0

Browse files
committed
feat: print debug log
1 parent b9a1595 commit 709f2e0

File tree

4 files changed

+32
-35
lines changed

4 files changed

+32
-35
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
},
100100
"dependencies": {
101101
"@rollup/pluginutils": "^5.1.3",
102+
"debug": "^4.3.7",
102103
"magic-string": "^0.30.12",
103104
"oxc-parser": "^0.36.0",
104105
"unplugin": "^1.16.0"
@@ -109,6 +110,7 @@
109110
"@swc/core": "^1.9.2",
110111
"@sxzz/eslint-config": "^4.4.1",
111112
"@sxzz/prettier-config": "^2.0.2",
113+
"@types/debug": "^4.1.12",
112114
"@types/node": "^22.9.0",
113115
"bumpp": "^9.8.1",
114116
"esbuild": "^0.24.0",

pnpm-lock.yaml

Lines changed: 6 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Foo = 'bar'

src/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { mkdir, readFile, writeFile } from 'node:fs/promises'
77
import path from 'node:path'
88
import { createFilter } from '@rollup/pluginutils'
9+
import Debug from 'debug'
910
import MagicString from 'magic-string'
1011
import { parseAsync } from 'oxc-parser'
1112
import {
@@ -36,8 +37,12 @@ import type {
3637
PluginContext,
3738
} from 'rollup'
3839

40+
const debug = Debug('unplugin-isolated-decl')
41+
3942
export type { Options }
4043

44+
export type * from './core/types'
45+
4146
/**
4247
* The main unplugin instance.
4348
*/
@@ -117,6 +122,9 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
117122
code = s.toString()
118123
}
119124

125+
const label = debug.enabled && `[${options.transformer}]`
126+
debug(label, 'transform', id)
127+
120128
let result: TransformResult
121129
switch (options.transformer) {
122130
case 'oxc':
@@ -133,6 +141,12 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
133141
)
134142
}
135143
const { code: sourceText, errors } = result
144+
debug(
145+
label,
146+
'transformed',
147+
id,
148+
errors.length ? 'with errors' : 'successfully',
149+
)
136150
if (errors.length) {
137151
if (options.ignoreErrors) {
138152
context.warn(errors[0])
@@ -143,7 +157,10 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
143157
}
144158
addOutput(id, sourceText)
145159

146-
if (!program) return
160+
if (!program) {
161+
debug('cannot parse', id)
162+
return
163+
}
147164
const typeImports = program.body.filter(
148165
(
149166
node,
@@ -189,6 +206,7 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
189206
} catch {
190207
continue
191208
}
209+
debug('transform type import:', resolved)
192210
await transform(context, source, resolved)
193211
}
194212
}
@@ -233,6 +251,7 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
233251
if (options.patchCjsDefaultExport && fileName.endsWith('.d.cts')) {
234252
source = patchCjsDefaultExport(source)
235253
}
254+
debug('[rollup] emit dts file:', fileName)
236255
this.emitFile({
237256
type: 'asset',
238257
fileName,
@@ -293,6 +312,7 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
293312
if (options.patchCjsDefaultExport && fileName.endsWith('.d.cts')) {
294313
source = patchCjsDefaultExport(source)
295314
}
315+
debug('[farm] emit dts file:', fileName)
296316
farmPluginContext.emitFile({
297317
type: 'asset',
298318
fileName,
@@ -352,7 +372,9 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
352372
if (write) {
353373
await mkdir(path.dirname(filePath), { recursive: true })
354374
await writeFile(filePath, source)
375+
debug('[esbuild] write dts file:', filePath)
355376
} else {
377+
debug('[esbuild] emit dts file:', filePath)
356378
result.outputFiles!.push({
357379
path: filePath,
358380
contents: textEncoder.encode(source),

0 commit comments

Comments
 (0)