From 59c6d89a0b0562b8c8e272d7b0c94e364ea0fad7 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Wed, 20 Sep 2023 12:57:47 -0500 Subject: [PATCH] fix: try splitting out types from default export --- package.json | 7 ++++++- src/index.ts | 20 +------------------- src/types.ts | 18 ++++++++++++++++++ tsup.config.ts | 2 +- 4 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 src/types.ts diff --git a/package.json b/package.json index 9de91c9..55c30d1 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/index.ts b/src/index.ts index 89de570..99a92d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -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; - 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. diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..c4a4511 --- /dev/null +++ b/src/types.ts @@ -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; + init?: RequestInitWithDuplex; + userAgent?: string; +} diff --git a/tsup.config.ts b/tsup.config.ts index 5339fc7..28c8e27 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -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,