From b7df260ec89edd3bdb48b8881c8af4a4ba11843b Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Thu, 5 Oct 2023 16:48:01 -0700 Subject: [PATCH] refactor: consolidating our ts and tsup configs (#813) * refactor: consolidating our ts and tsup configs * fix: removing `lib` from our base tsconfig * fix: pr feedback * fix: pr feedback * fix: prettier issues * fix: getting builds working * fix: prettier issues --- package-lock.json | 11 +++++++++++ package.json | 1 + packages/oas-extensions/package.json | 1 + packages/oas-extensions/tsconfig.json | 15 +++------------ packages/oas-extensions/tsup.config.ts | 12 +++--------- packages/oas-normalize/.eslintrc | 3 --- packages/oas-normalize/package.json | 2 ++ packages/oas-normalize/src/.sink.d.ts | 2 -- packages/oas-normalize/tsconfig.json | 18 +++++------------- packages/oas-normalize/tsup.config.ts | 11 +++-------- packages/oas-to-har/package.json | 1 + packages/oas-to-har/tsconfig.json | 17 ++++------------- packages/oas-to-har/tsup.config.ts | 8 +++----- packages/oas/package.json | 1 + packages/oas/src/lib/helpers.ts | 2 +- .../operation/get-response-as-json-schema.ts | 4 ++-- packages/oas/tsconfig.json | 16 +++------------- packages/oas/tsup.config.ts | 11 +++-------- tsconfig.base.json | 17 +++++++++++++++++ tsup.config.ts | 14 ++++++++++++++ 20 files changed, 78 insertions(+), 89 deletions(-) delete mode 100644 packages/oas-normalize/src/.sink.d.ts create mode 100644 tsconfig.base.json create mode 100644 tsup.config.ts diff --git a/package-lock.json b/package-lock.json index 73d48218..ea93c66f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3785,6 +3785,16 @@ "integrity": "sha512-dPWnWsf+kzIG140B8z2w3fr5D03TLWbOAFQl45xUpI3vcizeXriNR5VYkWZ+WTMsUHqZ9Xlt3hrxGNANFyNQfw==", "dev": true }, + "node_modules/@types/swagger2openapi": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/@types/swagger2openapi/-/swagger2openapi-7.0.1.tgz", + "integrity": "sha512-sF3VaR+bmuI5+aF+ddIImtV/RZ7liyG1ZWuOsWsZ5NsYw794ZFH75TRO3P4SQMG4qjKnAuIigWOklYFf9YMnrw==", + "dev": true, + "dependencies": { + "@types/node": "*", + "openapi-types": "^12.1.0" + } + }, "node_modules/@types/unist": { "version": "2.0.8", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.8.tgz", @@ -20817,6 +20827,7 @@ "devDependencies": { "@readme/oas-examples": "^5.12.0", "@types/js-yaml": "^4.0.5", + "@types/swagger2openapi": "^7.0.1", "@vitest/coverage-v8": "^0.34.1", "eslint": "^8.46.0", "fetch-mock": "^9.11.0", diff --git a/package.json b/package.json index 32077088..64825008 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "private": true, "scripts": { "alex": "alex .", + "attw": "npx lerna run attw --stream", "build": "npx lerna run build --stream", "clean": "npx lerna clean", "lint": "npm run lint:types && npm run lint:js && npm run prettier", diff --git a/packages/oas-extensions/package.json b/packages/oas-extensions/package.json index 1d27c268..4e662116 100644 --- a/packages/oas-extensions/package.json +++ b/packages/oas-extensions/package.json @@ -30,6 +30,7 @@ "url": "https://github.com/readmeio/oas/issues" }, "scripts": { + "attw": "attw --pack --format table-flipped", "build": "tsup", "lint": "npm run lint:types && npm run lint:js", "lint:js": "eslint . --ext .js,.ts", diff --git a/packages/oas-extensions/tsconfig.json b/packages/oas-extensions/tsconfig.json index 61105b09..31a8aee3 100644 --- a/packages/oas-extensions/tsconfig.json +++ b/packages/oas-extensions/tsconfig.json @@ -1,14 +1,5 @@ { - "compilerOptions": { - "allowJs": true, - "baseUrl": "./src/", - "declaration": true, - "esModuleInterop": true, - "module": "ESNext", - "moduleResolution": "bundler", - "noImplicitAny": true, - "outDir": "./dist", - "target": "ES2020" - }, - "include": ["./src/**/*"] + "extends": "../../tsconfig.base.json", + "include": ["./src/**/*"], + "exclude": ["dist"] } diff --git a/packages/oas-extensions/tsup.config.ts b/packages/oas-extensions/tsup.config.ts index 3748cc67..4e236b9f 100644 --- a/packages/oas-extensions/tsup.config.ts +++ b/packages/oas-extensions/tsup.config.ts @@ -3,18 +3,12 @@ import type { Options } from 'tsup'; // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig } from 'tsup'; +import config from '../../tsup.config'; + export default defineConfig((options: Options) => ({ ...options, + ...config, - cjsInterop: true, - clean: true, - dts: true, entry: ['src/index.ts'], - format: ['esm', 'cjs'], - minify: false, - shims: true, silent: !options.watch, - splitting: true, - sourcemap: true, - treeshake: true, })); diff --git a/packages/oas-normalize/.eslintrc b/packages/oas-normalize/.eslintrc index 7462d88b..a035c5fb 100644 --- a/packages/oas-normalize/.eslintrc +++ b/packages/oas-normalize/.eslintrc @@ -6,9 +6,6 @@ "camelcase": ["error", { "allow": ["OpenAPIV3_1"] }], - // Does not play well with our `swagger2openapi` type sinkhole. - "import/order": "off", - "no-case-declarations": "off", "unicorn/prefer-node-protocol": "error" diff --git a/packages/oas-normalize/package.json b/packages/oas-normalize/package.json index 32ebc845..c154d05c 100644 --- a/packages/oas-normalize/package.json +++ b/packages/oas-normalize/package.json @@ -52,6 +52,7 @@ "url": "https://github.com/readmeio/oas/issues" }, "scripts": { + "attw": "attw --pack --format table-flipped", "build": "tsup", "lint": "npm run lint:types && npm run lint:js", "lint:js": "eslint . --ext .js,.ts", @@ -71,6 +72,7 @@ "devDependencies": { "@readme/oas-examples": "^5.12.0", "@types/js-yaml": "^4.0.5", + "@types/swagger2openapi": "^7.0.1", "@vitest/coverage-v8": "^0.34.1", "eslint": "^8.46.0", "fetch-mock": "^9.11.0", diff --git a/packages/oas-normalize/src/.sink.d.ts b/packages/oas-normalize/src/.sink.d.ts deleted file mode 100644 index 0a782139..00000000 --- a/packages/oas-normalize/src/.sink.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// These packages don't have any TS types so we need to declare a module in order to use them. -declare module 'swagger2openapi'; diff --git a/packages/oas-normalize/tsconfig.json b/packages/oas-normalize/tsconfig.json index 2da7d041..4f4a6578 100644 --- a/packages/oas-normalize/tsconfig.json +++ b/packages/oas-normalize/tsconfig.json @@ -1,17 +1,9 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { - "allowJs": true, - "baseUrl": "./src", - "declaration": true, - "esModuleInterop": true, - "module": "ESNext", - "moduleResolution": "bundler", - "outDir": "dist/", - "paths": { - "swagger2openapi": [".sink.d.ts"] - }, - "skipLibCheck": true, - "target": "ES2020" + // DOM is needed because `oas-normalize` uses `fetch`. + "lib": ["DOM"] }, - "include": ["./src/**/*"] + "include": ["./src/**/*"], + "exclude": ["dist"] } diff --git a/packages/oas-normalize/tsup.config.ts b/packages/oas-normalize/tsup.config.ts index 7f496bf7..bf70088c 100644 --- a/packages/oas-normalize/tsup.config.ts +++ b/packages/oas-normalize/tsup.config.ts @@ -3,17 +3,12 @@ import type { Options } from 'tsup'; // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig } from 'tsup'; +import config from '../../tsup.config'; + export default defineConfig((options: Options) => ({ ...options, + ...config, - cjsInterop: true, - clean: true, - dts: true, 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, })); diff --git a/packages/oas-to-har/package.json b/packages/oas-to-har/package.json index 67976a09..23bd751b 100644 --- a/packages/oas-to-har/package.json +++ b/packages/oas-to-har/package.json @@ -39,6 +39,7 @@ "url": "https://github.com/readmeio/oas/issues" }, "scripts": { + "attw": "attw --pack --format table-flipped", "build": "tsup", "lint": "npm run lint:types && npm run lint:js", "lint:js": "eslint . --ext .js,.ts", diff --git a/packages/oas-to-har/tsconfig.json b/packages/oas-to-har/tsconfig.json index b389f214..a0f9ddf1 100644 --- a/packages/oas-to-har/tsconfig.json +++ b/packages/oas-to-har/tsconfig.json @@ -1,17 +1,8 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { - "allowJs": true, - "baseUrl": "./src", - "declaration": true, - "downlevelIteration": true, - "esModuleInterop": true, - "lib": ["DOM", "ES2020"], - "module": "ESNext", - "moduleResolution": "Bundler", - "noImplicitAny": true, - "outDir": "dist/", - "skipLibCheck": true, - "target": "ES2020" + "downlevelIteration": true }, - "include": ["./src/**/*"] + "include": ["./src/**/*"], + "exclude": ["dist"] } diff --git a/packages/oas-to-har/tsup.config.ts b/packages/oas-to-har/tsup.config.ts index 04abe55c..7aed512e 100644 --- a/packages/oas-to-har/tsup.config.ts +++ b/packages/oas-to-har/tsup.config.ts @@ -1,14 +1,12 @@ // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig } from 'tsup'; +import config from '../../tsup.config.js'; + export default defineConfig(options => ({ ...options, + ...config, - cjsInterop: true, - dts: true, entry: ['src/index.ts', 'src/lib/configure-security.ts', 'src/lib/types.ts'], - format: ['esm', 'cjs'], - shims: true, silent: !options.watch, - sourcemap: true, })); diff --git a/packages/oas/package.json b/packages/oas/package.json index 15f43d71..d83a6dda 100644 --- a/packages/oas/package.json +++ b/packages/oas/package.json @@ -69,6 +69,7 @@ "url": "https://github.com/readmeio/oas/issues" }, "scripts": { + "attw": "attw --pack --format table-flipped", "build": "tsup", "lint": "npm run lint:types && npm run lint:js", "lint:js": "eslint . --ext .js,.ts", diff --git a/packages/oas/src/lib/helpers.ts b/packages/oas/src/lib/helpers.ts index f1b698ff..e679c118 100644 --- a/packages/oas/src/lib/helpers.ts +++ b/packages/oas/src/lib/helpers.ts @@ -1,4 +1,4 @@ -import type { SchemaObject } from 'rmoas.types'; +import type { SchemaObject } from '../rmoas.types'; export function hasSchemaType(schema: SchemaObject, discriminator: 'array' | 'object') { if (Array.isArray(schema.type)) { diff --git a/packages/oas/src/operation/get-response-as-json-schema.ts b/packages/oas/src/operation/get-response-as-json-schema.ts index 0886316f..934818e5 100644 --- a/packages/oas/src/operation/get-response-as-json-schema.ts +++ b/packages/oas/src/operation/get-response-as-json-schema.ts @@ -1,4 +1,4 @@ -import type Operation from 'operation'; +import type Operation from '../operation'; import type { ComponentsObject, MediaTypeObject, @@ -6,7 +6,7 @@ import type { ResponseObject, SchemaObject, HeaderObject, -} from 'rmoas.types'; +} from '../rmoas.types'; import cloneObject from '../lib/clone-object'; import { isPrimitive } from '../lib/helpers'; diff --git a/packages/oas/tsconfig.json b/packages/oas/tsconfig.json index 79701593..31a8aee3 100644 --- a/packages/oas/tsconfig.json +++ b/packages/oas/tsconfig.json @@ -1,15 +1,5 @@ { - "compilerOptions": { - "allowJs": true, - "baseUrl": "./src/", - "declaration": true, - "esModuleInterop": true, - "lib": ["ES2023"], - "module": "ESNext", - "moduleResolution": "bundler", - "noImplicitAny": true, - "outDir": "./dist", - "target": "ES2020" - }, - "include": ["./src/**/*"] + "extends": "../../tsconfig.base.json", + "include": ["./src/**/*"], + "exclude": ["dist"] } diff --git a/packages/oas/tsup.config.ts b/packages/oas/tsup.config.ts index 522c93c0..dc6178b8 100644 --- a/packages/oas/tsup.config.ts +++ b/packages/oas/tsup.config.ts @@ -3,12 +3,12 @@ import type { Options } from 'tsup'; // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig } from 'tsup'; +import config from '../../tsup.config'; + export default defineConfig((options: Options) => ({ ...options, + ...config, - cjsInterop: true, - clean: true, - dts: true, entry: [ 'src/analyzer/index.ts', 'src/lib/reducer.ts', @@ -18,10 +18,5 @@ export default defineConfig((options: Options) => ({ 'src/rmoas.types.ts', 'src/utils.ts', ], - format: ['esm', 'cjs'], - minify: false, - shims: true, silent: !options.watch, - sourcemap: true, - splitting: true, })); diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000..0a2814a8 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "allowJs": true, + "baseUrl": "./src", + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "lib": ["ES2023"], + "module": "ESNext", + "moduleResolution": "Bundler", + "noImplicitAny": true, + "outDir": "./dist", + "skipLibCheck": true, + "sourceMap": true, + "target": "ES2020" + } +} diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 00000000..75b2008c --- /dev/null +++ b/tsup.config.ts @@ -0,0 +1,14 @@ +import type { Options } from 'tsup'; + +const config: Options = { + cjsInterop: true, + clean: true, + dts: true, + format: ['esm', 'cjs'], + minify: false, + shims: true, + sourcemap: true, + splitting: true, +}; + +export default config;