From 1a2dfa27af86bfd7b7e133394c3eaa9fe8e085ff Mon Sep 17 00:00:00 2001 From: Kanad Gupta <8854718+kanadgupta@users.noreply.github.com> Date: Mon, 25 Sep 2023 18:13:46 -0500 Subject: [PATCH] fix: reorganize exports to get default export working (#295) * fix: reorganize exports to get default export working * fix: tests + lint --- __tests__/index.test.ts | 4 ++-- package.json | 4 ++++ src/index.ts | 11 ++--------- src/lib/types.ts | 4 ++++ tsup.config.ts | 3 +-- 5 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 src/lib/types.ts diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index d03eeb2..9478663 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -6,8 +6,8 @@ import path from 'node:path'; import fetchMock from 'fetch-mock'; import { describe, afterEach, beforeAll, beforeEach, it, expect } from 'vitest'; -import OASNormalize, { getAPIDefinitionType, isAPIDefinition } from '../src'; -import { isOpenAPI, isPostman, isSwagger } from '../src/lib/utils'; +import OASNormalize from '../src'; +import { getAPIDefinitionType, isAPIDefinition, isOpenAPI, isPostman, isSwagger } from '../src/lib/utils'; function cloneObject(obj) { return JSON.parse(JSON.stringify(obj)); diff --git a/package.json b/package.json index 0edede6..9f61d16 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,10 @@ "require": "./dist/index.cjs", "import": "./dist/index.js" }, + "./lib/types": { + "require": "./dist/lib/types.cjs", + "import": "./dist/lib/types.js" + }, "./lib/utils": { "require": "./dist/lib/utils.cjs", "import": "./dist/lib/utils.js" diff --git a/src/index.ts b/src/index.ts index 3b709f5..f1025fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import type { Options } from './lib/types'; import type { OpenAPI } from 'openapi-types'; import fs from 'node:fs'; @@ -9,14 +10,6 @@ import converter from 'swagger2openapi'; import * as utils from './lib/utils'; -export interface Options { - colorizeErrors?: boolean; - enablePaths?: boolean; -} - -export const isAPIDefinition = utils.isAPIDefinition; -export const getAPIDefinitionType = utils.getAPIDefinitionType; - export default class OASNormalize { cache: { bundle?: false | OpenAPI.Document; @@ -215,7 +208,7 @@ export default class OASNormalize { */ version() { return this.load().then(schema => { - switch (getAPIDefinitionType(schema)) { + switch (utils.getAPIDefinitionType(schema)) { case 'openapi': return { specification: 'openapi', diff --git a/src/lib/types.ts b/src/lib/types.ts new file mode 100644 index 0000000..41a9efd --- /dev/null +++ b/src/lib/types.ts @@ -0,0 +1,4 @@ +export interface Options { + colorizeErrors?: boolean; + enablePaths?: boolean; +} diff --git a/tsup.config.ts b/tsup.config.ts index c8ac506..7f496bf 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -9,12 +9,11 @@ export default defineConfig((options: Options) => ({ cjsInterop: true, clean: true, dts: true, - entry: ['src/lib/utils.ts', 'src/index.ts'], + entry: ['src/index.ts', 'src/lib/types.ts', 'src/lib/utils.ts'], format: ['esm', 'cjs'], minify: false, shims: true, silent: !options.watch, sourcemap: true, splitting: true, - treeshake: true, }));