-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: include exporting as default logic
- Loading branch information
Showing
15 changed files
with
1,095 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Default CJS exports | ||
|
||
This document will cover all the types of default exports that can be generated by [rollup-plugin-dts](https://github.com/Swatinem/rollup-plugin-dts) plugin. | ||
|
||
### Export default without specifier from the module itself (index.ts in the fixture) | ||
|
||
The following example can be found in the [reexport-types](../../../../test/cjs-types-fixture/reexport-types) fixture, check `index.ts` module. | ||
|
||
Given the following code: | ||
```ts | ||
// module.ts | ||
export default function foo() {} | ||
``` | ||
|
||
`rollup-plugin-dts` will generate: | ||
```ts | ||
// module.d.[c]ts | ||
declare function foo(): void; | ||
|
||
export { foo as default }; | ||
``` | ||
|
||
we need to convert it to: | ||
```ts | ||
// module.d.[c]ts | ||
declare function foo(): void; | ||
|
||
export = foo; | ||
``` | ||
|
||
### Exporting default from default import | ||
|
||
The following example can be found in the [reexport-default](../../../../test/cjs-types-fixture/reexport-default) fixture, check `index.ts` module. | ||
|
||
Given the following code: | ||
```ts | ||
// module.ts | ||
import MagicString from "magic-string"; | ||
export default MagicString; | ||
``` | ||
|
||
`rollup-plugin-dts` will generate: | ||
```ts | ||
// module.d.[c]ts | ||
import MagicString from 'magic-string'; | ||
export { default } from 'magic-string'; | ||
``` | ||
|
||
we need to convert it to (doesn't require adding the import): | ||
```ts | ||
// module.d.[c]ts | ||
import MagicString from 'magic-string'; | ||
export = MagicString; | ||
``` | ||
|
||
### Exporting default with specifier | ||
|
||
The following example can be found in the [reexport-types](../../../../test/cjs-types-fixture/reexport-types) fixture, check `all.ts` module. | ||
|
||
Given the following code: | ||
```ts | ||
// module.ts | ||
export type * from "./index.ts"; | ||
export { default } from "./index.ts"; | ||
``` | ||
|
||
`rollup-plugin-dts` will generate: | ||
```ts | ||
// module.d.[c]ts | ||
// otherexports and otherexporttypes when present | ||
export { otherexports, type otherexporttypes, default } from './index.js'; | ||
``` | ||
|
||
we need to convert it to (requires adding the import): | ||
```ts | ||
// module.d.[c]ts | ||
import _default from './index.js'; | ||
export = _default; | ||
// otherexports and otherexporttypes when present | ||
export { otherexports, type otherexporttypes } from './index.js'; | ||
``` | ||
|
||
### Exporting default from named import as default export with specifier | ||
|
||
The following example can be found in the [reexport-default](../../../../test/cjs-types-fixture/reexport-default) fixture, check `asdefault.ts` module. | ||
|
||
Given the following code: | ||
```ts | ||
// module.ts | ||
import { resolve } from "pathe"; | ||
export default resolve; | ||
``` | ||
|
||
`rollup-plugin-dts` will generate: | ||
```ts | ||
// module.d.[c]ts | ||
import { resolve } from 'pathe'; | ||
export { resolve as default } from 'pathe'; | ||
``` | ||
|
||
we need to convert it to (doesn't require adding the import): | ||
```ts | ||
// module.d.[c]ts | ||
import { resolve } from 'pathe'; | ||
export = resolve; | ||
``` | ||
|
||
### Exporting named export as default with specifier | ||
|
||
The following example can be found in the [reexport-default](../../../../test/cjs-types-fixture/reexport-default) fixture, check `asdefault.ts` module. | ||
|
||
Given the following code: | ||
```ts | ||
// module.ts | ||
export { resolve as default } from "pathe"; | ||
``` | ||
|
||
`rollup-plugin-dts` will generate: | ||
```ts | ||
// module.d.[c]ts | ||
export { resolve as default } from 'pathe'; | ||
``` | ||
|
||
we need to convert it to (requires adding the import): | ||
```ts | ||
// module.d.[c]ts | ||
import { resolve } from 'pathe'; | ||
export = resolve; | ||
``` |
Oops, something went wrong.