Skip to content

Commit

Permalink
fix: try splitting out types from default export
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Sep 20, 2023
1 parent ff39a68 commit 59c6d89
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"./types": {
"import": "./dist/types.mjs",
"require": "./dist/types.js"
},
"./package.json": "./package.json"
},
"engines": {
"node": ">=18"
Expand Down
20 changes: 1 addition & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FetchHAROptions, RequestInitWithDuplex } from './types.js';
import type { DataURL as npmDataURL } from '@readme/data-urls';
import type { Har } from 'har-format';

Expand All @@ -24,25 +25,6 @@ if (!globalThis.File) {
}
}

interface RequestInitWithDuplex extends RequestInit {
/**
* `RequestInit#duplex` does not yet exist in the TS `lib.dom.d.ts` definition yet the native
* fetch implementation in Node 18+, `undici`, requires it for certain POST payloads.
*
* @see {@link https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1483}
* @see {@link https://github.com/nodejs/node/issues/46221}
* @see {@link https://fetch.spec.whatwg.org/#request-class}
* @see {@link https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts}
*/
duplex?: 'half';
}

export interface FetchHAROptions {
files?: Record<string, Blob | Buffer>;
init?: RequestInitWithDuplex;
userAgent?: string;
}

type DataURL = npmDataURL & {
// `parse-data-url` doesn't explicitly support `name` in data URLs but if it's there it'll be
// returned back to us.
Expand Down
18 changes: 18 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface RequestInitWithDuplex extends RequestInit {
/**
* `RequestInit#duplex` does not yet exist in the TS `lib.dom.d.ts` definition yet the native
* fetch implementation in Node 18+, `undici`, requires it for certain POST payloads.
*
* @see {@link https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1483}
* @see {@link https://github.com/nodejs/node/issues/46221}
* @see {@link https://fetch.spec.whatwg.org/#request-class}
* @see {@link https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts}
*/
duplex?: 'half';
}

export interface FetchHAROptions {
files?: Record<string, Blob | Buffer>;
init?: RequestInitWithDuplex;
userAgent?: string;
}
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig((options: Options) => ({

clean: true,
dts: true,
entry: ['src/index.ts'],
entry: ['src/index.ts', 'src/types.ts'],
format: ['esm', 'cjs'],
minify: false,
shims: true,
Expand Down

0 comments on commit 59c6d89

Please sign in to comment.