8000 feat: use `fix-dts-default-cjs-exports` to transform CJS types (#1310) · egoist/tsup@c654e5f · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit c654e5f

Browse files
authored
feat: use fix-dts-default-cjs-exports to transform CJS types (#1310)
1 parent 773d27e commit c654e5f

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"consola": "^3.4.0",
5959
"debug": "^4.4.0",
6060
"esbuild": "^0.25.0",
61+
"fix-dts-default-cjs-exports": "^1.0.0",
6162
"joycon": "^3.1.1",
6263
"picocolors": "^1.1.1",
6364
"postcss-load-config": "^6.0.1",

pnpm-lock.yaml

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

src/rollup.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { getProductionDeps, loadPkg } from './load'
1111
import { reportSize } from './lib/report-size'
1212
import type { NormalizedOptions } from './'
1313
import type { InputOptions, OutputOptions, Plugin } from 'rollup'
14+
import { FixDtsDefaultCjsExportsPlugin } from 'fix-dts-default-cjs-exports/rollup'
1415

1516
const logger = createLogger()
1617

@@ -89,25 +90,6 @@ const getRollupConfig = async (
8990
},
9091
}
9192

92-
const fixCjsExport: Plugin = {
93-
name: 'tsup:fix-cjs-export',
94-
renderChunk(code, info) {
95-
if (
96-
info.type !== 'chunk' ||
97-
!/\.(ts|cts)$/.test(info.fileName) ||
98-
!info.isEntry ||
99-
info.exports?.length !== 1 ||
100-
info.exports[0] !== 'default'
101-
)
102-
return
103-
104-
return code.replace(
105-
/(?<=(?<=[;}]|^)\s*export\s*){\s*([\w$]+)\s*as\s+default\s*}/,
106-
`= $1`,
107-
)
108-
},
109-
}
110-
11193
return {
11294
inputConfig: {
11395
input: dtsOptions.entry,
@@ -167,7 +149,7 @@ const getRollupConfig = async (
167149
entryFileNames: `[name]${outputExtension}`,
168150
chunkFileNames: `[name]-[hash]${outputExtension}`,
169151
plugins: [
170-
format === 'cjs' && options.cjsInterop && fixCjsExport,
152+
format === 'cjs' && options.cjsInterop && FixDtsDefaultCjsExportsPlugin(),
171153
].filter(Boolean),
172154
}
173155
}),

0 commit comments

Comments
 (0)
0