From 88467fd6f23bae97fe16dd7753c9b98519ca6ebf Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 25 Sep 2023 18:00:26 -0500 Subject: [PATCH 1/2] fix: reorganize exports to get default export working --- package.json | 4 ++++ src/index.ts | 11 ++--------- src/lib/types.ts | 4 ++++ tsup.config.ts | 3 +-- 4 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 src/lib/types.ts 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..f28cd83 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,14 +8,7 @@ import postmanToOpenAPI from '@readme/postman-to-openapi'; 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; +import { Options } from './lib/types'; export default class OASNormalize { cache: { @@ -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, })); From b21c02cd07980fe1de12551695d19c402fcb313b Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 25 Sep 2023 18:02:55 -0500 Subject: [PATCH 2/2] fix: tests + lint --- __tests__/index.test.ts | 4 ++-- src/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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/src/index.ts b/src/index.ts index f28cd83..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'; @@ -8,7 +9,6 @@ import postmanToOpenAPI from '@readme/postman-to-openapi'; import converter from 'swagger2openapi'; import * as utils from './lib/utils'; -import { Options } from './lib/types'; export default class OASNormalize { cache: {