Skip to content

Commit

Permalink
fix: somehow --dts-bundle works now
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed May 18, 2020
1 parent 282c912 commit 87de6e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ tsup index.ts --dts

This will emit `./dist/index.js` and `./dist/index.d.ts`.

If you want to bundle types from `node_modules` as well, use the `--dts-bundle` flag instead, which implicitly set `--dts` flag as well. (Note that this is experimental.)

### Bundle files and node modules

```bash
Expand Down
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ export async function createRollupConfigs(files: string[], options: Options) {

const getRollupConfig = async ({
dts,
dtsBundle,
}: {
dts?: boolean
dtsBundle?: boolean
}): Promise<{
name: string
inputConfig: InputOptions
Expand Down Expand Up @@ -74,13 +76,11 @@ export async function createRollupConfigs(files: string[], options: Options) {
jsxFragment: options.jsxFragment,
define: options.define,
}),
dts &&
(await import('rollup-plugin-dts').then((res) => res.default())),
!dts &&
(!dts || dtsBundle) &&
resolvePlugin({
bundle: options.bundle,
external: options.external,
dtsBundle: options.dtsBundle,
dtsBundle: dtsBundle,
}),
!dts &&
commonjsPlugin({
Expand All @@ -96,6 +96,8 @@ export async function createRollupConfigs(files: string[], options: Options) {
return isExternal(options.external, name)
},
}),
dts &&
(await import('rollup-plugin-dts').then((res) => res.default())),
sizePlugin(),
].filter(Boolean),
},
Expand All @@ -110,7 +112,9 @@ export async function createRollupConfigs(files: string[], options: Options) {
const rollupConfigs = [await getRollupConfig({})]

if (options.dts) {
rollupConfigs.push(await getRollupConfig({ dts: true }))
rollupConfigs.push(
await getRollupConfig({ dts: true, dtsBundle: options.dtsBundle })
)
}

return rollupConfigs
Expand Down
5 changes: 2 additions & 3 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ runTest('simple', {
'foo.js': `export default 'foo'`,
})

// Somehow it can't bundle graphql-tools
runTest(
'bundle graphql-tools with dts enabled',
'bundle graphql-tools with dts bundle',
{
'input.ts': `export { makeExecutableSchema, SchemaDirectiveVisitor } from 'graphql-tools'`,
},
{
flags: ['--bundle', '--dts'],
flags: ['--bundle', '--dts-bundle'],
snapshot: false,
}
)

0 comments on commit 87de6e1

Please sign in to comment.