diff --git a/.eslintrc b/.eslintrc index cac942a0..048eacbc 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,9 +1,6 @@ { - "extends": ["@readme/eslint-config", "@readme/eslint-config/typescript"], + "extends": ["@readme/eslint-config", "@readme/eslint-config/esm", "@readme/eslint-config/typescript"], "root": true, - "rules": { - "unicorn/prefer-node-protocol": "error" - }, "overrides": [ { "files": ["bin/**"], diff --git a/.gitignore b/.gitignore index 1eae0cf6..bfb2263b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist/ node_modules/ +**/*.tsbuildinfo diff --git a/bin/build-markdown.js b/bin/build-markdown.js index 2c7dcdc9..457dae62 100644 --- a/bin/build-markdown.js +++ b/bin/build-markdown.js @@ -1,5 +1,5 @@ -const fs = require('node:fs'); -const path = require('node:path'); +import fs from 'node:fs'; +import path from 'node:path'; const readme = fs.readFileSync('README.md', 'utf-8'); diff --git a/package-lock.json b/package-lock.json index ba89f888..02f92976 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,13 +12,15 @@ "@commitlint/cli": "^17.6.6", "@commitlint/config-conventional": "^17.7.0", "@readme/eslint-config": "^13.0.1", + "@tsconfig/node18": "^18.2.2", "alex": "^11.0.1", "conventional-changelog-cli": "^4.1.0", "eslint": "^8.48.0", "husky": "^8.0.3", "knip": "^2.24.1", "lerna": "^7.2.0", - "prettier": "^3.0.3" + "prettier": "^3.0.3", + "tsup": "^7.2.0" }, "engines": { "node": ">=16" @@ -3205,25 +3207,30 @@ "integrity": "sha512-/dBh9qw3QhJYqlGwt2I+KUP/lQ6nytdCx3aq+GpMUhibLHF3O7fwoowNcTwlbnwtyJ+TJYTIIrp3oVUlRNx3fA==" }, "node_modules/@readme/httpsnippet": { - "version": "7.1.2", - "resolved": "https://registry.npmjs.org/@readme/httpsnippet/-/httpsnippet-7.1.2.tgz", - "integrity": "sha512-jnFAUT//yrIWm6vgSdOWHXvnuPcAAOKhvfUN+Fu2JUfvAEJd9QtvvCeW2AbilyyGVkxqveyQueB9IzV0DEldOA==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/@readme/httpsnippet/-/httpsnippet-8.0.1.tgz", + "integrity": "sha512-gqD8hRlQcyemWNFPtSqOAWrEqXyDfCgi0dK0+dANhgaACCW6OTHWwZFLXOBcYY8g408Ndus80ZCAZSfWZEvBOA==", "peer": true, "dependencies": { - "form-data": "^4.0.0", - "map-stream": "^0.0.7", + "formdata-to-string": "^2.0.0", "qs": "^6.11.2", "stringify-object": "^3.3.0" }, "engines": { - "node": ">=16" + "node": ">=18" } }, - "node_modules/@readme/httpsnippet/node_modules/map-stream": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.0.7.tgz", - "integrity": "sha512-C0X0KQmGm3N2ftbTGBhSyuydQ+vV1LC3f3zPvT3RXHXNZrvfPZcoXp/N5DOa8vedX/rTMm2CjTtivFg2STJMRQ==", - "peer": true + "node_modules/@readme/httpsnippet/node_modules/formdata-to-string": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/formdata-to-string/-/formdata-to-string-2.0.0.tgz", + "integrity": "sha512-jU9hZPj5totkwtwlfwkglElnmxumzAMSjaYQkVv0WcY3bOQeOduoVjnm1OVpeQextS+sXtjKjQUrFWUB8MWUzA==", + "peer": true, + "dependencies": { + "undici": "^5.24.0" + }, + "engines": { + "node": ">=18" + } }, "node_modules/@readme/json-schema-ref-parser": { "version": "1.2.0", @@ -3243,25 +3250,25 @@ "dev": true }, "node_modules/@readme/oas-extensions": { - "version": "20.0.1", - "resolved": "https://registry.npmjs.org/@readme/oas-extensions/-/oas-extensions-20.0.1.tgz", - "integrity": "sha512-vVI51JwhL0R1KlBaFy1ovcn/6Bkv9Kylfrqew3ua8ueBFY1GuSDENjAgYg0YENqFOiviEDu8FXbHNlfFuUYPnA==", + "version": "20.0.4", + "resolved": "https://registry.npmjs.org/@readme/oas-extensions/-/oas-extensions-20.0.4.tgz", + "integrity": "sha512-dP44B6ojZ572vhf51l5U4OVSE/IRTJP2P9t5bH16bP3X38dbXLYIYisd92NQ0jhvUxRPvx1a2qDWNdQ88GWQkQ==", + "dependencies": { + "oas": "^23.0.0" + }, "engines": { "node": ">=18" - }, - "peerDependencies": { - "oas": "^22.0.0" } }, "node_modules/@readme/oas-to-har": { - "version": "23.0.9", - "resolved": "https://registry.npmjs.org/@readme/oas-to-har/-/oas-to-har-23.0.9.tgz", - "integrity": "sha512-tUBwf1LZJ4mQvnmPO2QxVjcisI94vMgNBZ63kfF2Pj/+fSdgSbGw4aJTqk8tGmwNnobCRYOy4kQt0ykDuS2H/A==", + "version": "23.0.12", + "resolved": "https://registry.npmjs.org/@readme/oas-to-har/-/oas-to-har-23.0.12.tgz", + "integrity": "sha512-XXJtD/BQwlCeyTFY9ztHz/enNbVYC83kjDVXaBsoTDbCJtFVdo+dcz6Zux7hrABLTJTPAl/L8A4hqBbMBO7kbg==", "dependencies": { "@readme/data-urls": "^3.0.0", - "@readme/oas-extensions": "^20.0.0", + "@readme/oas-extensions": "^20.0.4", "lodash": "^4.17.21", - "oas": "^22.0.0", + "oas": "^23.0.0", "qs": "^6.11.2", "remove-undefined-objects": "^4.0.1" }, @@ -3472,6 +3479,12 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true }, + "node_modules/@tsconfig/node18": { + "version": "18.2.2", + "resolved": "https://registry.npmjs.org/@tsconfig/node18/-/node18-18.2.2.tgz", + "integrity": "sha512-d6McJeGsuoRlwWZmVIeE8CUA27lu6jLjvv1JzqmpsytOYYbVi1tHZEnwCNVOXnj4pyLvneZlFlpXUK+X9wBWyw==", + "dev": true + }, "node_modules/@tufjs/canonical-json": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@tufjs/canonical-json/-/canonical-json-1.0.0.tgz", @@ -4504,6 +4517,25 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/any-promise": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", + "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==", + "dev": true + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/api": { "resolved": "packages/api", "link": true @@ -4761,7 +4793,8 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true }, "node_modules/available-typed-arrays": { "version": "1.0.5", @@ -4862,6 +4895,15 @@ "node": ">=0.6" } }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/bl": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", @@ -5060,6 +5102,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/bundle-require": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/bundle-require/-/bundle-require-4.0.2.tgz", + "integrity": "sha512-jwzPOChofl67PSTW2SGubV9HBQAhhR2i6nskiOThauo9dzwDUgOWQScFVaJkjEfYX+UXiD+LEx8EblQMc2wIag==", + "dev": true, + "dependencies": { + "load-tsconfig": "^0.2.3" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "peerDependencies": { + "esbuild": ">=0.17" + } + }, "node_modules/busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -5351,6 +5408,45 @@ "node": "*" } }, + "node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/chownr": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", @@ -5594,6 +5690,7 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -7279,6 +7376,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, "engines": { "node": ">=0.4.0" } @@ -9360,6 +9458,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -11235,6 +11334,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/is-boolean-object": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", @@ -11990,6 +12101,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/joycon": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz", + "integrity": "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -13369,6 +13489,15 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/lilconfig": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz", + "integrity": "sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==", + "dev": true, + "engines": { + "node": ">=10" + } + }, "node_modules/limit-spawn": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/limit-spawn/-/limit-spawn-0.0.3.tgz", @@ -13425,6 +13554,15 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/load-tsconfig": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/load-tsconfig/-/load-tsconfig-0.2.5.tgz", + "integrity": "sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, "node_modules/local-pkg": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.4.3.tgz", @@ -15095,6 +15233,7 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "dev": true, "engines": { "node": ">= 0.6" } @@ -15103,6 +15242,7 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dev": true, "dependencies": { "mime-db": "1.52.0" }, @@ -15476,6 +15616,17 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, + "node_modules/mz": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", + "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", + "dev": true, + "dependencies": { + "any-promise": "^1.0.0", + "object-assign": "^4.0.1", + "thenify-all": "^1.0.0" + } + }, "node_modules/nanoid": { "version": "3.3.6", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", @@ -15745,6 +15896,15 @@ "node": "^16.14.0 || >=18.0.0" } }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/normalize-url": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-8.0.0.tgz", @@ -16237,9 +16397,9 @@ } }, "node_modules/oas": { - "version": "22.0.0", - "resolved": "https://registry.npmjs.org/oas/-/oas-22.0.0.tgz", - "integrity": "sha512-/amjB0O1qy8frcQdnoEmClGVuc7ibxvxG1DkTr8Uh7utxsuziZTWiJQNk9MA7abg8AQbsEhj3nBVoHapi+ABag==", + "version": "23.0.0", + "resolved": "https://registry.npmjs.org/oas/-/oas-23.0.0.tgz", + "integrity": "sha512-e3G5pdnuw/hFSVtnNmVwDQHr29j3SG6KaL6C6QjfKVnbLqwRWQ+5gHx7Ky5ABxxGtQ17jZLjXl4f/vX9IMgUbg==", "dependencies": { "@readme/json-schema-ref-parser": "^1.2.0", "@types/json-schema": "^7.0.11", @@ -16247,7 +16407,7 @@ "jsonpath-plus": "^7.2.0", "jsonpointer": "^5.0.0", "memoizee": "^0.4.14", - "oas-normalize": "^11.0.0", + "oas-normalize": "^11.0.1", "openapi-types": "^12.1.1", "path-to-regexp": "^6.2.0", "remove-undefined-objects": "^4.0.2" @@ -16278,9 +16438,9 @@ } }, "node_modules/oas-normalize": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/oas-normalize/-/oas-normalize-11.0.0.tgz", - "integrity": "sha512-AUxoheSKJEMrF2YK7Qz8BpR0Gz8JDuOSpAOqeTW7N1StfMbxcBxCTkWoQuQoNlS7RuZh7D+0BtZO/yYF3r6olg==", + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/oas-normalize/-/oas-normalize-11.0.1.tgz", + "integrity": "sha512-y+tM2XhLys9o2MNnQBtcRgi6u86jjqTXR2MCMX3rf379t7uVdTqfJPhUD/ruxNSIxSIf+jtO3tPCwCKFScyJCg==", "dependencies": { "@readme/openapi-parser": "^2.5.0", "@readme/postman-to-openapi": "^4.1.0", @@ -17151,6 +17311,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/pirates": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz", + "integrity": "sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==", + "dev": true, + "engines": { + "node": ">= 6" + } + }, "node_modules/pkg-dir": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", @@ -17270,6 +17439,44 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/postcss-load-config": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/postcss-load-config/-/postcss-load-config-4.0.1.tgz", + "integrity": "sha512-vEJIc8RdiBRu3oRAI0ymerOn+7rPuMvRXslTvZUKZonDHFIczxztIyJ1urxM1x9JXEikvpWWTUUqal5j/8QgvA==", + "dev": true, + "dependencies": { + "lilconfig": "^2.0.5", + "yaml": "^2.1.1" + }, + "engines": { + "node": ">= 14" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + "peerDependencies": { + "postcss": ">=8.0.9", + "ts-node": ">=9.0.0" + }, + "peerDependenciesMeta": { + "postcss": { + "optional": true + }, + "ts-node": { + "optional": true + } + } + }, + "node_modules/postcss-load-config/node_modules/yaml": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.3.2.tgz", + "integrity": "sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg==", + "dev": true, + "engines": { + "node": ">= 14" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -17894,6 +18101,18 @@ "node": ">= 6" } }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/redent": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-4.0.0.tgz", @@ -19358,6 +19577,63 @@ "node": ">=4" } }, + "node_modules/sucrase": { + "version": "3.34.0", + "resolved": "https://registry.npmjs.org/sucrase/-/sucrase-3.34.0.tgz", + "integrity": "sha512-70/LQEZ07TEcxiU2dz51FKaE6hCTWC6vr7FOk3Gr0U60C3shtAN+H+BFr9XlYe5xqf3RA8nrc+VIwzCfnxuXJw==", + "dev": true, + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.2", + "commander": "^4.0.0", + "glob": "7.1.6", + "lines-and-columns": "^1.1.6", + "mz": "^2.7.0", + "pirates": "^4.0.1", + "ts-interface-checker": "^0.1.9" + }, + "bin": { + "sucrase": "bin/sucrase", + "sucrase-node": "bin/sucrase-node" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/sucrase/node_modules/commander": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", + "integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==", + "dev": true, + "engines": { + "node": ">= 6" + } + }, + "node_modules/sucrase/node_modules/glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/sucrase/node_modules/lines-and-columns": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", + "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", + "dev": true + }, "node_modules/summary": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/summary/-/summary-2.1.0.tgz", @@ -19583,6 +19859,27 @@ "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, + "node_modules/thenify": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz", + "integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==", + "dev": true, + "dependencies": { + "any-promise": "^1.0.0" + } + }, + "node_modules/thenify-all": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", + "integrity": "sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==", + "dev": true, + "dependencies": { + "thenify": ">= 3.1.0 < 4" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -19727,6 +20024,15 @@ "punycode": "^2.1.0" } }, + "node_modules/tree-kill": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", + "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==", + "dev": true, + "bin": { + "tree-kill": "cli.js" + } + }, "node_modules/trim-newlines": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-4.1.1.tgz", @@ -19766,6 +20072,12 @@ "typescript": ">=4.2.0" } }, + "node_modules/ts-interface-checker": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", + "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==", + "dev": true + }, "node_modules/ts-morph": { "version": "17.0.1", "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-17.0.1.tgz", @@ -19857,6 +20169,74 @@ "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", "dev": true }, + "node_modules/tsup": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/tsup/-/tsup-7.2.0.tgz", + "integrity": "sha512-vDHlczXbgUvY3rWvqFEbSqmC1L7woozbzngMqTtL2PGBODTtWlRwGDDawhvWzr5c1QjKe4OAKqJGfE1xeXUvtQ==", + "dev": true, + "dependencies": { + "bundle-require": "^4.0.0", + "cac": "^6.7.12", + "chokidar": "^3.5.1", + "debug": "^4.3.1", + "esbuild": "^0.18.2", + "execa": "^5.0.0", + "globby": "^11.0.3", + "joycon": "^3.0.1", + "postcss-load-config": "^4.0.1", + "resolve-from": "^5.0.0", + "rollup": "^3.2.5", + "source-map": "0.8.0-beta.0", + "sucrase": "^3.20.3", + "tree-kill": "^1.2.2" + }, + "bin": { + "tsup": "dist/cli-default.js", + "tsup-node": "dist/cli-node.js" + }, + "engines": { + "node": ">=16.14" + }, + "peerDependencies": { + "@swc/core": "^1", + "postcss": "^8.4.12", + "typescript": ">=4.1.0" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "postcss": { + "optional": true + }, + "typescript": { + "optional": true + } + } + }, + "node_modules/tsup/node_modules/source-map": { + "version": "0.8.0-beta.0", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz", + "integrity": "sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==", + "dev": true, + "dependencies": { + "whatwg-url": "^7.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/tsup/node_modules/whatwg-url": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz", + "integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==", + "dev": true, + "dependencies": { + "lodash.sortby": "^4.7.0", + "tr46": "^1.0.1", + "webidl-conversions": "^4.0.2" + } + }, "node_modules/tsutils": { "version": "3.21.0", "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", @@ -21619,7 +21999,7 @@ "lodash.deburr": "^4.1.0", "lodash.setwith": "^4.3.2", "lodash.startcase": "^4.4.0", - "oas": "^22.0.0", + "oas": "^23.0.0", "ora": "^5.4.1", "prompts": "^2.4.2", "semver": "^7.3.8", @@ -21628,7 +22008,7 @@ "validate-npm-package-name": "^5.0.0" }, "bin": { - "api": "bin/api" + "api": "bin/api.js" }, "devDependencies": { "@api/test-utils": "file:../test-utils", @@ -21645,7 +22025,7 @@ "@types/validate-npm-package-name": "^4.0.0", "@vitest/coverage-v8": "^0.34.4", "fetch-mock": "^9.11.0", - "oas-normalize": "^11.0.0", + "oas-normalize": "^11.0.1", "type-fest": "^4.3.1", "typescript": "^5.2.2", "unique-temp-dir": "^1.0.0", @@ -21660,15 +22040,15 @@ "version": "7.0.0-alpha.3", "license": "MIT", "dependencies": { - "@readme/oas-to-har": "^23.0.8", + "@readme/oas-to-har": "^23.0.12", "caseless": "^0.12.0", "datauri": "^4.1.0", "fetch-har": "^11.0.1", "get-stream": "^6.0.1", "json-schema-traverse": "^1.0.0", "lodash.merge": "^4.6.2", - "oas": "^22.0.0", - "remove-undefined-objects": "^3.0.0" + "oas": "^23.0.0", + "remove-undefined-objects": "^4.0.2" }, "devDependencies": { "@api/test-utils": "file:../test-utils", @@ -21684,14 +22064,6 @@ "node": ">=18" } }, - "packages/core/node_modules/remove-undefined-objects": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/remove-undefined-objects/-/remove-undefined-objects-3.0.0.tgz", - "integrity": "sha512-nxG1yYfc/Jxi+bNCBiqKhxVJPE+QvziIOKbD+Dxc93Uisz92v/ZYpo4WR0TJuf+dk2xE8lW2WPJsA3mDFzXy8w==", - "engines": { - "node": ">=16" - } - }, "packages/httpsnippet-client-api": { "version": "7.0.0-alpha.2", "license": "MIT", @@ -21712,8 +22084,8 @@ "node": ">=18" }, "peerDependencies": { - "@readme/httpsnippet": ">=4", - "oas": "^22.0.0" + "@readme/httpsnippet": ">=8", + "oas": "^23.0.0" } }, "packages/test-utils": { @@ -21727,7 +22099,7 @@ }, "devDependencies": { "@types/caseless": "^0.12.3", - "oas": "^22.0.0", + "oas": "^23.0.0", "typescript": "^5.2.2" } } diff --git a/package.json b/package.json index 1c5f116d..3647d321 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,15 @@ { "name": "api-monorepo", "private": true, + "type": "module", "scripts": { "alex": "alex .", + "attw": "npx lerna run attw --stream", "build": "lerna run build --stream", "build-docs": "node bin/build-markdown.js", "clean": "lerna clean", - "lint": "knip && npm run lint:types && npm run lint:js && npm run prettier", + "lint": "npm run lint:types && npm run lint:js && npm run prettier", + "lint:deadcode": "knip", "lint:js": "eslint . --ext .js,.ts", "lint:types": "npm run lint:types --if-present --workspaces", "prepare": "husky install", @@ -33,13 +36,15 @@ "@commitlint/cli": "^17.6.6", "@commitlint/config-conventional": "^17.7.0", "@readme/eslint-config": "^13.0.1", + "@tsconfig/node18": "^18.2.2", "alex": "^11.0.1", "conventional-changelog-cli": "^4.1.0", "eslint": "^8.48.0", "husky": "^8.0.3", "knip": "^2.24.1", "lerna": "^7.2.0", - "prettier": "^3.0.3" + "prettier": "^3.0.3", + "tsup": "^7.2.0" }, "commitlint": { "extends": [ diff --git a/packages/api/.eslintrc b/packages/api/.eslintrc deleted file mode 100644 index 9a22ff04..00000000 --- a/packages/api/.eslintrc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "overrides": [ - { - "files": ["bin/api"], - "rules": { - "import/extensions": "off", - "import/no-unresolved": "off" - } - }, - { - "files": ["example.js"], - "rules": { - "@typescript-eslint/no-var-requires": "off", - "no-console": "off" - } - } - ] -} diff --git a/packages/api/bin/api b/packages/api/bin/api deleted file mode 100755 index b1b75c68..00000000 --- a/packages/api/bin/api +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env node -require('../dist/bin'); diff --git a/packages/api/bin/api.js b/packages/api/bin/api.js new file mode 100755 index 00000000..c7ad3e20 --- /dev/null +++ b/packages/api/bin/api.js @@ -0,0 +1,2 @@ +#!/usr/bin/env node +import '../dist/bin.js'; diff --git a/packages/api/package.json b/packages/api/package.json index a9c988e4..e92808a6 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -2,10 +2,12 @@ "name": "api", "version": "7.0.0-alpha.3", "description": "Magical SDK generation from an OpenAPI definition 🪄", + "type": "module", "bin": { - "api": "./bin/api" + "api": "bin/api.js" }, "scripts": { + "attw": "attw --pack --format table-flipped", "build": "tsc", "debug:bin": "node -r ts-node/register src/bin.ts", "lint:types": "tsc --noEmit", @@ -47,7 +49,7 @@ "lodash.deburr": "^4.1.0", "lodash.setwith": "^4.3.2", "lodash.startcase": "^4.4.0", - "oas": "^22.0.0", + "oas": "^23.0.0", "ora": "^5.4.1", "prompts": "^2.4.2", "semver": "^7.3.8", @@ -70,7 +72,7 @@ "@types/validate-npm-package-name": "^4.0.0", "@vitest/coverage-v8": "^0.34.4", "fetch-mock": "^9.11.0", - "oas-normalize": "^11.0.0", + "oas-normalize": "^11.0.1", "type-fest": "^4.3.1", "typescript": "^5.2.2", "unique-temp-dir": "^1.0.0", diff --git a/packages/api/src/bin.ts b/packages/api/src/bin.ts index e45a89d0..8027e77a 100644 --- a/packages/api/src/bin.ts +++ b/packages/api/src/bin.ts @@ -1,7 +1,7 @@ import { Command } from 'commander'; -import commands from './commands'; -import * as pkg from './packageInfo'; +import commands from './commands/index.js'; +import * as pkg from './packageInfo.js'; (async () => { const program = new Command(); diff --git a/packages/api/src/codegen/index.ts b/packages/api/src/codegen/index.ts index 3e6c1b5b..6194d1e6 100644 --- a/packages/api/src/codegen/index.ts +++ b/packages/api/src/codegen/index.ts @@ -1,7 +1,7 @@ -import type CodeGeneratorLanguage from './language'; +import type CodeGeneratorLanguage from './language.js'; import type Oas from 'oas'; -import TSGenerator from './languages/typescript'; +import TSGenerator from './languages/typescript.js'; export type SupportedLanguages = 'js' | 'js-cjs' | 'js-esm' | 'ts'; diff --git a/packages/api/src/codegen/language.ts b/packages/api/src/codegen/language.ts index 8e4061c1..fe60186d 100644 --- a/packages/api/src/codegen/language.ts +++ b/packages/api/src/codegen/language.ts @@ -1,7 +1,7 @@ -import type Storage from '../storage'; +import type Storage from '../storage.js'; import type Oas from 'oas'; -import { PACKAGE_NAME, PACKAGE_VERSION } from '../packageInfo'; +import { PACKAGE_NAME, PACKAGE_VERSION } from '../packageInfo.js'; export interface InstallerOptions { /** diff --git a/packages/api/src/codegen/languages/typescript.ts b/packages/api/src/codegen/languages/typescript.ts index f440f292..c2ba92db 100644 --- a/packages/api/src/codegen/languages/typescript.ts +++ b/packages/api/src/codegen/languages/typescript.ts @@ -1,5 +1,5 @@ -import type Storage from '../../storage'; -import type { InstallerOptions } from '../language'; +import type Storage from '../../storage.js'; +import type { InstallerOptions } from '../language.js'; import type Oas from 'oas'; import type Operation from 'oas/operation'; import type { HttpMethods, SchemaObject } from 'oas/rmoas.types'; @@ -21,10 +21,10 @@ import setWith from 'lodash.setwith'; import semver from 'semver'; import { IndentationText, Project, QuoteKind, ScriptTarget, VariableDeclarationKind } from 'ts-morph'; -import logger from '../../logger'; -import CodeGeneratorLanguage from '../language'; +import logger from '../../logger.js'; +import CodeGeneratorLanguage from '../language.js'; -import { docblockEscape, generateTypeName, wordWrap } from './typescript/util'; +import { docblockEscape, generateTypeName, wordWrap } from './typescript/util.js'; export interface TSGeneratorOptions { compilerTarget?: 'cjs' | 'esm'; diff --git a/packages/api/src/commands/index.ts b/packages/api/src/commands/index.ts index 6b91a0ea..e250397c 100644 --- a/packages/api/src/commands/index.ts +++ b/packages/api/src/commands/index.ts @@ -1,4 +1,4 @@ -import installCommand from './install'; +import installCommand from './install.js'; export default { install: installCommand, diff --git a/packages/api/src/commands/install.ts b/packages/api/src/commands/install.ts index 19a9e893..c6233a06 100644 --- a/packages/api/src/commands/install.ts +++ b/packages/api/src/commands/install.ts @@ -1,15 +1,15 @@ -import type { SupportedLanguages } from '../codegen'; +import type { SupportedLanguages } from '../codegen/index.js'; import { Command, Option } from 'commander'; import figures from 'figures'; import Oas from 'oas'; import ora from 'ora'; -import codegen from '../codegen'; -import Fetcher from '../fetcher'; -import promptTerminal from '../lib/prompt'; -import logger from '../logger'; -import Storage from '../storage'; +import codegen from '../codegen/index.js'; +import Fetcher from '../fetcher.js'; +import promptTerminal from '../lib/prompt.js'; +import logger from '../logger.js'; +import Storage from '../storage.js'; // @todo log logs to `.api/.logs` and have `.logs` ignored const cmd = new Command(); diff --git a/packages/api/src/storage.ts b/packages/api/src/storage.ts index 99c0b391..3de2fa43 100644 --- a/packages/api/src/storage.ts +++ b/packages/api/src/storage.ts @@ -6,8 +6,8 @@ import path from 'node:path'; import ssri from 'ssri'; import validateNPMPackageName from 'validate-npm-package-name'; -import Fetcher from './fetcher'; -import { PACKAGE_VERSION } from './packageInfo'; +import Fetcher from './fetcher.js'; +import { PACKAGE_VERSION } from './packageInfo.js'; export default class Storage { static dir: string; diff --git a/packages/api/test/codegen/languages/typescript.test.ts b/packages/api/test/codegen/languages/typescript.test.ts index aadb1546..c869d1f0 100644 --- a/packages/api/test/codegen/languages/typescript.test.ts +++ b/packages/api/test/codegen/languages/typescript.test.ts @@ -1,18 +1,17 @@ -import type { TSGeneratorOptions } from '../../../src/codegen/languages/typescript'; +import type { TSGeneratorOptions } from '../../../src/codegen/languages/typescript.js'; import fs from 'node:fs/promises'; import path from 'node:path'; -import { responses as mockResponse } from '@api/test-utils/fetch-mock'; -import loadSpec from '@api/test-utils/load-spec'; +import { loadSpec, responses as mockResponse } from '@api/test-utils'; import fetchMock from 'fetch-mock'; import Oas from 'oas'; import uniqueTempDir from 'unique-temp-dir'; import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest'; -import TSGenerator from '../../../src/codegen/languages/typescript'; -import * as packageInfo from '../../../src/packageInfo'; -import Storage from '../../../src/storage'; +import TSGenerator from '../../../src/codegen/languages/typescript.js'; +import * as packageInfo from '../../../src/packageInfo.js'; +import Storage from '../../../src/storage.js'; function assertSDKFixture(file: string, fixture: string, opts: TSGeneratorOptions = {}) { return async () => { @@ -172,7 +171,7 @@ describe('typescript', () => { }); it('should be able to make an API request (TS)', async () => { - const sdk = await import('../../__fixtures__/sdk/simple-ts').then(r => r.default); + const sdk = await import('../../__fixtures__/sdk/simple-ts/index.js').then(r => r.default); fetchMock.get('http://petstore.swagger.io/v2/pet/findByStatus?status=available', mockResponse.searchParams); await sdk.findPetsByStatus({ status: ['available'] }).then(({ data, status, headers, res }) => { @@ -184,7 +183,7 @@ describe('typescript', () => { }); it('should be able to make an API request with an `accept` header`', async () => { - const sdk = await import('../../__fixtures__/sdk/simple-ts').then(r => r.default); + const sdk = await import('../../__fixtures__/sdk/simple-ts/index.js').then(r => r.default); fetchMock.get('http://petstore.swagger.io/v2/pet/findByStatus?status=available', mockResponse.headers); await sdk @@ -197,8 +196,15 @@ describe('typescript', () => { }); }); - it('should be able to make an API request (JS + CommonJS)', async () => { - const sdk = await import('../../__fixtures__/sdk/simple-js-cjs').then(r => r.default); + /** + * This test is impossible to run now because its a `.js` file that's loading ESM code. The + * CJS SDK we're generating here should have a `.cjs` extension but we're going to overhaul + * this entire codegen process with `tsup` so this test is being skipped for now. + * + * @see {@link https://github.com/readmeio/api/pull/734} + */ + it.skip('should be able to make an API request (JS + CommonJS)', async () => { + const sdk = await import('../../__fixtures__/sdk/simple-js-cjs/index.js').then(r => r.default); fetchMock.get('http://petstore.swagger.io/v2/pet/findByStatus?status=available', mockResponse.searchParams); await sdk.findPetsByStatus({ status: ['available'] }).then(({ data, status, headers, res }) => { @@ -210,7 +216,7 @@ describe('typescript', () => { }); it('should be able to make an API request (JS + ESM)', async () => { - const sdk = await import('../../__fixtures__/sdk/simple-js-esm').then(r => r.default); + const sdk = await import('../../__fixtures__/sdk/simple-js-esm/index.js').then(r => r.default); fetchMock.get('http://petstore.swagger.io/v2/pet/findByStatus?status=available', mockResponse.searchParams); await sdk.findPetsByStatus({ status: ['available'] }).then(({ data, status, headers, res }) => { diff --git a/packages/api/test/codegen/languages/typescript/smoketest.test.ts b/packages/api/test/codegen/languages/typescript/smoketest.test.ts index b06fa000..ef7b0d86 100644 --- a/packages/api/test/codegen/languages/typescript/smoketest.test.ts +++ b/packages/api/test/codegen/languages/typescript/smoketest.test.ts @@ -20,7 +20,7 @@ import Oas from 'oas'; import OASNormalize from 'oas-normalize'; import { describe, it, expect } from 'vitest'; -import TSGenerator from '../../../../src/codegen/languages/typescript'; +import TSGenerator from '../../../../src/codegen/languages/typescript.js'; // These APIs don't have any schemas so they should only be generating an `index.ts`. const APIS_WITHOUT_SCHEMAS = ['poemist.com']; diff --git a/packages/api/test/codegen/languages/typescript/utils.test.ts b/packages/api/test/codegen/languages/typescript/utils.test.ts index 7e1cc579..f4eee2e2 100644 --- a/packages/api/test/codegen/languages/typescript/utils.test.ts +++ b/packages/api/test/codegen/languages/typescript/utils.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from 'vitest'; -import { docblockEscape, generateTypeName, wordWrap } from '../../../../src/codegen/languages/typescript/util'; +import { docblockEscape, generateTypeName, wordWrap } from '../../../../src/codegen/languages/typescript/util.js'; describe('ts codegen utils', () => { describe('#docblockEscape', () => { diff --git a/packages/api/test/fetcher.test.ts b/packages/api/test/fetcher.test.ts index 5acf7be9..cc37b432 100644 --- a/packages/api/test/fetcher.test.ts +++ b/packages/api/test/fetcher.test.ts @@ -1,11 +1,11 @@ import assert from 'node:assert'; import fs from 'node:fs/promises'; -import loadSpec from '@api/test-utils/load-spec'; +import { loadSpec } from '@api/test-utils'; import fetchMock from 'fetch-mock'; import { describe, beforeAll, it, expect } from 'vitest'; -import Fetcher from '../src/fetcher'; +import Fetcher from '../src/fetcher.js'; let readmeSpec; diff --git a/packages/api/test/global.d.ts b/packages/api/test/global.d.ts index eace3e8b..a0ba3927 100644 --- a/packages/api/test/global.d.ts +++ b/packages/api/test/global.d.ts @@ -1 +1,2 @@ -import '@api/test-utils/vitest.matchers'; +// eslint-disable-next-line import/extensions +import '@api/test-utils/vitest.matchers.ts'; diff --git a/packages/api/test/storage.test.ts b/packages/api/test/storage.test.ts index 3fab7cf1..5b2102aa 100644 --- a/packages/api/test/storage.test.ts +++ b/packages/api/test/storage.test.ts @@ -4,13 +4,13 @@ import assert from 'node:assert'; import fs from 'node:fs/promises'; import path from 'node:path'; -import loadSpec from '@api/test-utils/load-spec'; +import { loadSpec } from '@api/test-utils'; import fetchMock from 'fetch-mock'; import uniqueTempDir from 'unique-temp-dir'; import { describe, beforeAll, beforeEach, afterEach, it, expect } from 'vitest'; -import { PACKAGE_VERSION } from '../src/packageInfo'; -import Storage from '../src/storage'; +import { PACKAGE_VERSION } from '../src/packageInfo.js'; +import Storage from '../src/storage.js'; let petstoreSimple; diff --git a/packages/api/tsconfig.json b/packages/api/tsconfig.json index b2535fb1..ea11e325 100644 --- a/packages/api/tsconfig.json +++ b/packages/api/tsconfig.json @@ -1,16 +1,9 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { - "allowJs": true, - "baseUrl": "./src", - "declaration": true, "esModuleInterop": true, - "lib": ["DOM", "DOM.Iterable", "ES2020"], - "module": "NodeNext", - "noImplicitAny": true, - "outDir": "dist/", - "skipLibCheck": true, - "strict": true, - "useUnknownInCatchVariables": false + "lib": ["DOM", "DOM.Iterable", "ES2023"], + "outDir": "dist/" }, "include": ["./src/**/*"] } diff --git a/packages/api/vitest.config.ts b/packages/api/vitest.config.ts index e5d0af9b..a05d79b4 100644 --- a/packages/api/vitest.config.ts +++ b/packages/api/vitest.config.ts @@ -11,7 +11,7 @@ export default defineConfig({ '**/helpers/**', '**/smoketest.test.ts', ], - setupFiles: ['@api/test-utils/vitest.matchers.ts'], + setupFiles: ['../test-utils/vitest.matchers.ts'], testTimeout: 20000, }, }); diff --git a/packages/core/package.json b/packages/core/package.json index a68ffb35..5d16e2bf 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -2,10 +2,25 @@ "name": "@readme/api-core", "version": "7.0.0-alpha.3", "description": "The magic behind `api` 🧙", - "main": "./dist/index.js", - "types": "./dist/index.d.ts", + "sideEffects": false, + "type": "module", + "exports": { + ".": { + "require": "./dist/index.cjs", + "import": "./dist/index.js" + }, + "./errors/fetchError": { + "require": "./dist/errors/fetchError.cjs", + "import": "./dist/errors/fetchError.js" + }, + "./package.json": "./package.json" + }, + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.cts", "scripts": { - "build": "tsc", + "attw": "attw --pack --format table-flipped", + "build": "tsup", "lint:types": "tsc --noEmit", "prebuild": "rm -rf dist/", "prepack": "npm run build", @@ -13,7 +28,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/readmeio/api.git", + "url": "git+https://github.com/readmeio/api.git", "directory": "packages/core" }, "homepage": "https://api.readme.dev", @@ -26,15 +41,15 @@ "node": ">=18" }, "dependencies": { - "@readme/oas-to-har": "^23.0.8", + "@readme/oas-to-har": "^23.0.12", "caseless": "^0.12.0", "datauri": "^4.1.0", "fetch-har": "^11.0.1", "get-stream": "^6.0.1", "json-schema-traverse": "^1.0.0", "lodash.merge": "^4.6.2", - "oas": "^22.0.0", - "remove-undefined-objects": "^3.0.0" + "oas": "^23.0.0", + "remove-undefined-objects": "^4.0.2" }, "devDependencies": { "@api/test-utils": "file:../test-utils", diff --git a/packages/core/src/errors/fetchError.ts b/packages/core/src/errors/fetchError.ts index ef86011a..c06008f3 100644 --- a/packages/core/src/errors/fetchError.ts +++ b/packages/core/src/errors/fetchError.ts @@ -1,4 +1,4 @@ -class FetchError extends Error { +export default class FetchError extends Error { /** HTTP Status */ status: Status; @@ -27,5 +27,3 @@ class FetchError extends Error { Object.setPrototypeOf(this, FetchError.prototype); } } - -export default FetchError; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 66b7349c..f516f1a4 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -6,12 +6,8 @@ import type { HttpMethods } from 'oas/rmoas.types'; import oasToHar from '@readme/oas-to-har'; import fetchHar from 'fetch-har'; -import FetchError from './errors/fetchError'; -import getJSONSchemaDefaults from './lib/getJSONSchemaDefaults'; -import parseResponse from './lib/parseResponse'; -import prepareAuth from './lib/prepareAuth'; -import prepareParams from './lib/prepareParams'; -import prepareServer from './lib/prepareServer'; +import FetchError from './errors/fetchError.js'; +import { parseResponse, prepareAuth, prepareParams, prepareServer } from './lib/index.js'; export interface ConfigOptions { /** @@ -35,8 +31,6 @@ type Enumerate = Acc['length'] exte export type HTTPMethodRange = Exclude, Enumerate>; -export { getJSONSchemaDefaults, parseResponse, prepareAuth, prepareParams, prepareServer }; - export default class APICore { spec!: Oas; diff --git a/packages/core/src/lib/index.ts b/packages/core/src/lib/index.ts new file mode 100644 index 00000000..b66b0b18 --- /dev/null +++ b/packages/core/src/lib/index.ts @@ -0,0 +1,7 @@ +import getJSONSchemaDefaults from './getJSONSchemaDefaults.js'; +import parseResponse from './parseResponse.js'; +import prepareAuth from './prepareAuth.js'; +import prepareParams from './prepareParams.js'; +import prepareServer from './prepareServer.js'; + +export { getJSONSchemaDefaults, parseResponse, prepareAuth, prepareParams, prepareServer }; diff --git a/packages/core/src/lib/prepareParams.ts b/packages/core/src/lib/prepareParams.ts index 9e6ef863..d9fb2cfb 100644 --- a/packages/core/src/lib/prepareParams.ts +++ b/packages/core/src/lib/prepareParams.ts @@ -7,13 +7,13 @@ import path from 'node:path'; import stream from 'node:stream'; import caseless from 'caseless'; -import DatauriParser from 'datauri/parser'; -import datauri from 'datauri/sync'; +import DatauriParser from 'datauri/parser.js'; +import datauri from 'datauri/sync.js'; import getStream from 'get-stream'; import lodashMerge from 'lodash.merge'; import removeUndefinedObjects from 'remove-undefined-objects'; -import getJSONSchemaDefaults from './getJSONSchemaDefaults'; +import getJSONSchemaDefaults from './getJSONSchemaDefaults.js'; // These headers are normally only defined by the OpenAPI definition but we allow the user to // manually supply them in their `metadata` parameter if they wish. diff --git a/packages/core/test/global.d.ts b/packages/core/test/global.d.ts index eace3e8b..a0ba3927 100644 --- a/packages/core/test/global.d.ts +++ b/packages/core/test/global.d.ts @@ -1 +1,2 @@ -import '@api/test-utils/vitest.matchers'; +// eslint-disable-next-line import/extensions +import '@api/test-utils/vitest.matchers.ts'; diff --git a/packages/core/test/index.test.ts b/packages/core/test/index.test.ts index e8ee0c11..0b2015e2 100644 --- a/packages/core/test/index.test.ts +++ b/packages/core/test/index.test.ts @@ -1,14 +1,13 @@ import assert from 'node:assert'; -import { responses as mockResponse } from '@api/test-utils/fetch-mock'; -import loadSpec from '@api/test-utils/load-spec'; +import { loadSpec, responses as mockResponse } from '@api/test-utils'; import datauri from 'datauri'; import fetchMock from 'fetch-mock'; import Oas from 'oas'; import { describe, beforeEach, afterEach, it, expect } from 'vitest'; -import APICore from '../src'; -import FetchError from '../src/errors/fetchError'; +import FetchError from '../src/errors/fetchError.js'; +import APICore from '../src/index.js'; describe('APICore', () => { let fileUploads: APICore; diff --git a/packages/core/test/lib/getJSONSchemaDefaults.test.ts b/packages/core/test/lib/getJSONSchemaDefaults.test.ts index 60799d30..74f408cb 100644 --- a/packages/core/test/lib/getJSONSchemaDefaults.test.ts +++ b/packages/core/test/lib/getJSONSchemaDefaults.test.ts @@ -1,8 +1,8 @@ -import loadSpec from '@api/test-utils/load-spec'; +import { loadSpec } from '@api/test-utils'; import Oas from 'oas'; import { describe, it, expect } from 'vitest'; -import getJSONSchemaDefaults from '../../src/lib/getJSONSchemaDefaults'; +import getJSONSchemaDefaults from '../../src/lib/getJSONSchemaDefaults.js'; describe('#getJSONSchemaDefaults()', () => { it('should get defaults off an operation', async () => { diff --git a/packages/core/test/lib/parseResponse.test.ts b/packages/core/test/lib/parseResponse.test.ts index 623ca556..3d923192 100644 --- a/packages/core/test/lib/parseResponse.test.ts +++ b/packages/core/test/lib/parseResponse.test.ts @@ -1,6 +1,6 @@ import { describe, beforeEach, it, expect } from 'vitest'; -import parseResponse from '../../src/lib/parseResponse'; +import parseResponse from '../../src/lib/parseResponse.js'; const responseBody = JSON.stringify({ id: 9205436248879918000, diff --git a/packages/core/test/lib/prepareAuth.test.ts b/packages/core/test/lib/prepareAuth.test.ts index 11d6f3cb..026e13de 100644 --- a/packages/core/test/lib/prepareAuth.test.ts +++ b/packages/core/test/lib/prepareAuth.test.ts @@ -1,10 +1,10 @@ import type { OASDocument } from 'oas/rmoas.types'; -import loadSpec from '@api/test-utils/load-spec'; +import { loadSpec } from '@api/test-utils'; import Oas from 'oas'; import { describe, beforeAll, it, expect } from 'vitest'; -import prepareAuth from '../../src/lib/prepareAuth'; +import prepareAuth from '../../src/lib/prepareAuth.js'; let oas: Oas; @@ -167,7 +167,7 @@ describe('#prepareAuth()', () => { let securityMultipleOas; beforeAll(async () => { - authQuirksOas = await loadSpec(require.resolve('@api/test-utils/definitions/auth-quirks.json')); + authQuirksOas = await loadSpec('@api/test-utils/definitions/auth-quirks.json'); securityMultipleOas = await loadSpec('@readme/oas-examples/3.0/json/security-multiple.json'); }); diff --git a/packages/core/test/lib/prepareParams.test.ts b/packages/core/test/lib/prepareParams.test.ts index 3b4b49f6..a57fc877 100644 --- a/packages/core/test/lib/prepareParams.test.ts +++ b/packages/core/test/lib/prepareParams.test.ts @@ -1,11 +1,11 @@ import fs from 'node:fs'; +import { loadSpec } from '@api/test-utils'; import payloadExamples from '@api/test-utils/definitions/payloads.json'; -import loadSpec from '@api/test-utils/load-spec'; import Oas from 'oas'; import { describe, beforeEach, it, expect } from 'vitest'; -import prepareParams from '../../src/lib/prepareParams'; +import prepareParams from '../../src/lib/prepareParams.js'; describe('#prepareParams', () => { let fileUploads: Oas; @@ -381,7 +381,7 @@ describe('#prepareParams', () => { describe('quirks', () => { it('should not send special headers in body payloads', async () => { - const basiq = await import('@api/test-utils/definitions/basiq.json').then(Oas.init); + const basiq = await loadSpec('@api/test-utils/definitions/basiq.json').then(Oas.init); await basiq.dereference(); const operation = basiq.operation('/token', 'post'); @@ -400,7 +400,7 @@ describe('#prepareParams', () => { }); it('should not duplicate a supplied header parameter if that header casing matches the spec', async () => { - const basiq = await import('@api/test-utils/definitions/basiq.json').then(Oas.init); + const basiq = await loadSpec('@api/test-utils/definitions/basiq.json').then(Oas.init); await basiq.dereference(); const operation = basiq.operation('/token', 'post'); diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 4b816c6d..ac844c7e 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,15 +1,8 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { - "allowJs": true, - "baseUrl": "./src", - "declaration": true, - "esModuleInterop": true, - "lib": ["DOM", "DOM.Iterable", "ES2020"], - "module": "NodeNext", - "noImplicitAny": true, - "outDir": "dist/", - "skipLibCheck": true, - "strict": true + "lib": ["DOM", "DOM.Iterable", "ES2023"], + "outDir": "dist/" }, "include": ["./src/**/*"] } diff --git a/packages/core/tsup.config.ts b/packages/core/tsup.config.ts new file mode 100644 index 00000000..9137a0cb --- /dev/null +++ b/packages/core/tsup.config.ts @@ -0,0 +1,15 @@ +import type { Options } from 'tsup'; + +// eslint-disable-next-line import/no-extraneous-dependencies +import { defineConfig } from 'tsup'; + +// eslint-disable-next-line import/no-relative-packages +import config from '../../tsup.config.js'; + +export default defineConfig((options: Options) => ({ + ...options, + ...config, + + entry: ['src/errors/fetchError.ts', 'src/index.ts'], + silent: !options.watch, +})); diff --git a/packages/core/vitest.config.ts b/packages/core/vitest.config.ts index 8d5bc084..cad99f26 100644 --- a/packages/core/vitest.config.ts +++ b/packages/core/vitest.config.ts @@ -3,6 +3,6 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { - setupFiles: ['@api/test-utils/vitest.matchers.ts'], + setupFiles: ['../test-utils/vitest.matchers.ts'], }, }); diff --git a/packages/httpsnippet-client-api/package.json b/packages/httpsnippet-client-api/package.json index a1f2f4b4..aa4ba649 100644 --- a/packages/httpsnippet-client-api/package.json +++ b/packages/httpsnippet-client-api/package.json @@ -2,10 +2,21 @@ "name": "httpsnippet-client-api", "version": "7.0.0-alpha.2", "description": "An HTTPSnippet client for generating snippets for the `api` module.", - "main": "./dist/index.js", - "types": "./dist/index.d.ts", + "sideEffects": false, + "type": "module", + "exports": { + ".": { + "require": "./dist/index.cjs", + "import": "./dist/index.js" + }, + "./package.json": "./package.json" + }, + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.cts", "scripts": { - "build": "tsc", + "attw": "attw --pack --format table-flipped", + "build": "tsup", "lint:types": "tsc --noEmit", "prebuild": "rm -rf dist/", "prepack": "npm run build", @@ -29,8 +40,8 @@ "stringify-object": "^3.3.0" }, "peerDependencies": { - "@readme/httpsnippet": ">=4", - "oas": "^22.0.0" + "@readme/httpsnippet": ">=8", + "oas": "^23.0.0" }, "devDependencies": { "@readme/oas-examples": "^5.12.0", diff --git a/packages/httpsnippet-client-api/src/index.ts b/packages/httpsnippet-client-api/src/index.ts index 9925fe90..9407999e 100644 --- a/packages/httpsnippet-client-api/src/index.ts +++ b/packages/httpsnippet-client-api/src/index.ts @@ -74,7 +74,7 @@ function getAuthSources(operation: Operation) { return matchers; } -export interface APIOptions { +interface APIOptions { apiDefinition: OASDocument; apiDefinitionUri: string; escapeBrackets?: boolean; @@ -87,6 +87,7 @@ const client: Client = { title: 'API', link: 'https://npm.im/api', description: 'Automatic SDK generation from an OpenAPI definition.', + extname: '.js', }, convert: ({ cookiesObj, headersObj, postData, queryObj, url, ...source }, options) => { const opts = { diff --git a/packages/httpsnippet-client-api/test/__datasets__/alternate-server/index.ts b/packages/httpsnippet-client-api/test/__datasets__/alternate-server/index.ts index 69aa8240..c2939c33 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/alternate-server/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/alternate-server/index.ts @@ -1,4 +1,5 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; +import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/server-variables.json'; @@ -16,7 +17,7 @@ const mock: SnippetMock = { queryString: [], url: 'http://dev.local/v2/global', }, - definition, + definition: definition as OASDocument, }; export default mock; diff --git a/packages/httpsnippet-client-api/test/__datasets__/application-form-encoded/index.ts b/packages/httpsnippet-client-api/test/__datasets__/application-form-encoded/index.ts index 7e6f6362..013339ad 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/application-form-encoded/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/application-form-encoded/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/application-json/index.ts b/packages/httpsnippet-client-api/test/__datasets__/application-json/index.ts index e9d7a9d9..58a08244 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/application-json/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/application-json/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/auth-apikey-cookie/index.ts b/packages/httpsnippet-client-api/test/__datasets__/auth-apikey-cookie/index.ts index 8527be8f..654b434f 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/auth-apikey-cookie/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/auth-apikey-cookie/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/security.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/auth-apikey-header/index.ts b/packages/httpsnippet-client-api/test/__datasets__/auth-apikey-header/index.ts index 01e322e2..5b620de9 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/auth-apikey-header/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/auth-apikey-header/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/security.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/auth-basic-full/index.ts b/packages/httpsnippet-client-api/test/__datasets__/auth-basic-full/index.ts index 92d87edd..877491f5 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/auth-basic-full/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/auth-basic-full/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/readme.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/auth-basic-password-only/index.ts b/packages/httpsnippet-client-api/test/__datasets__/auth-basic-password-only/index.ts index 7cf7346e..55d2b511 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/auth-basic-password-only/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/auth-basic-password-only/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/readme.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/auth-basic-username-only/index.ts b/packages/httpsnippet-client-api/test/__datasets__/auth-basic-username-only/index.ts index 2391ddde..f1d090da 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/auth-basic-username-only/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/auth-basic-username-only/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/readme.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/auth-bearer/index.ts b/packages/httpsnippet-client-api/test/__datasets__/auth-bearer/index.ts index 92091836..a7e5aa49 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/auth-bearer/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/auth-bearer/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/security.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/auth-query/index.ts b/packages/httpsnippet-client-api/test/__datasets__/auth-query/index.ts index c73a3c5e..f7cc865e 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/auth-query/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/auth-query/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/security.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/cookies/index.ts b/packages/httpsnippet-client-api/test/__datasets__/cookies/index.ts index d18d64ca..5e4a9954 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/cookies/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/cookies/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/full-many-query-params/index.ts b/packages/httpsnippet-client-api/test/__datasets__/full-many-query-params/index.ts index 8947728f..82193b29 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/full-many-query-params/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/full-many-query-params/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/full/index.ts b/packages/httpsnippet-client-api/test/__datasets__/full/index.ts index a349cbfa..21fe1235 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/full/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/full/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/headers/index.ts b/packages/httpsnippet-client-api/test/__datasets__/headers/index.ts index ec5f6ecc..bcb2fd5a 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/headers/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/headers/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/http-insecure/index.ts b/packages/httpsnippet-client-api/test/__datasets__/http-insecure/index.ts index 5c44193a..b213dbcb 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/http-insecure/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/http-insecure/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/issue-128/index.ts b/packages/httpsnippet-client-api/test/__datasets__/issue-128/index.ts index 23331bfb..70d9a22f 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/issue-128/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/issue-128/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/issue-76/index.ts b/packages/httpsnippet-client-api/test/__datasets__/issue-76/index.ts index e9bff379..6fb9a2fa 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/issue-76/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/issue-76/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/issue-78-operationid/index.ts b/packages/httpsnippet-client-api/test/__datasets__/issue-78-operationid/index.ts index e8a6947c..d71d2484 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/issue-78-operationid/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/issue-78-operationid/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/issue-78/index.ts b/packages/httpsnippet-client-api/test/__datasets__/issue-78/index.ts index e6f286d7..ac901557 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/issue-78/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/issue-78/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/jsonObj-multiline/index.ts b/packages/httpsnippet-client-api/test/__datasets__/jsonObj-multiline/index.ts index 6beac1ef..683238b6 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/jsonObj-multiline/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/jsonObj-multiline/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/jsonObj-null-value/index.ts b/packages/httpsnippet-client-api/test/__datasets__/jsonObj-null-value/index.ts index 85076af8..17eddbc3 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/jsonObj-null-value/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/jsonObj-null-value/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/multipart-data/index.ts b/packages/httpsnippet-client-api/test/__datasets__/multipart-data/index.ts index d6e416ae..9e8edde8 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/multipart-data/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/multipart-data/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/multipart-file/index.ts b/packages/httpsnippet-client-api/test/__datasets__/multipart-file/index.ts index 10f179cb..ef471967 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/multipart-file/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/multipart-file/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/multipart-form-data-no-params/index.ts b/packages/httpsnippet-client-api/test/__datasets__/multipart-form-data-no-params/index.ts index 07d9fa36..cfa6d3d8 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/multipart-form-data-no-params/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/multipart-form-data-no-params/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/multipart-form-data/index.ts b/packages/httpsnippet-client-api/test/__datasets__/multipart-form-data/index.ts index 1adb17b0..31118975 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/multipart-form-data/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/multipart-form-data/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/operationid-non-alphanumerical/index.ts b/packages/httpsnippet-client-api/test/__datasets__/operationid-non-alphanumerical/index.ts index 1ee5274c..e673329b 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/operationid-non-alphanumerical/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/operationid-non-alphanumerical/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/operationid-with-underscores/index.ts b/packages/httpsnippet-client-api/test/__datasets__/operationid-with-underscores/index.ts index ce9aa8b9..5ea62337 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/operationid-with-underscores/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/operationid-with-underscores/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/parameter-special-characters/index.ts b/packages/httpsnippet-client-api/test/__datasets__/parameter-special-characters/index.ts index 1df4d307..8f8cf8b0 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/parameter-special-characters/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/parameter-special-characters/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/petstore/index.ts b/packages/httpsnippet-client-api/test/__datasets__/petstore/index.ts index 5d45e912..51f45bd9 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/petstore/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/petstore/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from '@readme/oas-examples/3.0/json/petstore.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/query/index.ts b/packages/httpsnippet-client-api/test/__datasets__/query/index.ts index 5d0d1452..bf7f9479 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/query/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/query/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/short/index.ts b/packages/httpsnippet-client-api/test/__datasets__/short/index.ts index b92cd594..c56365c5 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/short/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/short/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/__datasets__/text-plain/index.ts b/packages/httpsnippet-client-api/test/__datasets__/text-plain/index.ts index 9b7502b5..d2d0e908 100644 --- a/packages/httpsnippet-client-api/test/__datasets__/text-plain/index.ts +++ b/packages/httpsnippet-client-api/test/__datasets__/text-plain/index.ts @@ -1,4 +1,4 @@ -import type { SnippetMock } from '../../index.test'; +import type { SnippetMock } from '../../index.test.js'; import type { OASDocument } from 'oas/rmoas.types'; import definition from './openapi.json'; diff --git a/packages/httpsnippet-client-api/test/index.test.ts b/packages/httpsnippet-client-api/test/index.test.ts index 6ce76ff5..1710dea7 100644 --- a/packages/httpsnippet-client-api/test/index.test.ts +++ b/packages/httpsnippet-client-api/test/index.test.ts @@ -1,5 +1,5 @@ import type { HarRequest, Request } from '@readme/httpsnippet'; -import type { Client } from '@readme/httpsnippet/dist/targets/targets'; +import type { Client } from '@readme/httpsnippet/targets'; import type { OASDocument } from 'oas/rmoas.types'; import { readdirSync } from 'node:fs'; @@ -11,7 +11,7 @@ import readme from '@readme/oas-examples/3.0/json/readme.json'; import openapiParser from '@readme/openapi-parser'; import { describe, afterEach, beforeEach, expect, it, vi } from 'vitest'; -import client from '../src'; +import client from '../src/index.js'; const DATASETS_DIR = path.join(__dirname, '__datasets__'); const SNIPPETS = readdirSync(DATASETS_DIR); @@ -43,6 +43,7 @@ describe('httpsnippet-client-api', () => { title: 'API', link: 'https://npm.im/api', description: 'Automatic SDK generation from an OpenAPI definition.', + extname: '.js', }); }); @@ -50,24 +51,22 @@ describe('httpsnippet-client-api', () => { const { har } = await getSnippetDataset('petstore'); const snippet = new HTTPSnippet(har); - expect(() => { - snippet.convert('node', 'api'); - }).toThrow(/must have an `apiDefinitionUri` option supplied/); + await expect(snippet.convert('node', 'api')).rejects.toThrow(/must have an `apiDefinitionUri` option supplied/); }); it('should error if no apiDefinition was supplied', async () => { const { har } = await getSnippetDataset('petstore'); const snippet = new HTTPSnippet(har); - expect(() => { + await expect( snippet.convert('node', 'api', { apiDefinitionUri: 'https://api.example.com/openapi.json', - }); - }).toThrow(/must have an `apiDefinition` option supplied/); + }), + ).rejects.toThrow(/must have an `apiDefinition` option supplied/); }); // This test should fail because the url in the HAR is missing `/v1` in the path. - it('should error if no matching operation was found in the apiDefinition', () => { + it('should error if no matching operation was found in the apiDefinition', async () => { const har = { httpVersion: 'HTTP/1.1', method: 'GET', @@ -80,12 +79,12 @@ describe('httpsnippet-client-api', () => { const snippet = new HTTPSnippet(har as Request); - expect(() => { + await expect( snippet.convert('node', 'api', { apiDefinitionUri: 'https://api.example.com/openapi.json', apiDefinition: readme, - }); - }).toThrow(/unable to locate a matching operation/i); + }), + ).rejects.toThrow(/unable to locate a matching operation/i); }); describe('snippets', () => { @@ -111,7 +110,7 @@ describe('httpsnippet-client-api', () => { it('should generate the expected snippet', async () => { const expected = await fs.readFile(path.join(DATASETS_DIR, snippet, 'output.js'), 'utf-8'); - const code = new HTTPSnippet(mock.har).convert('node', 'api', { + const code = await new HTTPSnippet(mock.har).convert('node', 'api', { apiDefinitionUri: `https://api.example.com/${snippet}.json`, apiDefinition: mock.definition, }); diff --git a/packages/httpsnippet-client-api/tsconfig.json b/packages/httpsnippet-client-api/tsconfig.json index 2fbaed02..1ab262c9 100644 --- a/packages/httpsnippet-client-api/tsconfig.json +++ b/packages/httpsnippet-client-api/tsconfig.json @@ -1,15 +1,8 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { - "allowJs": true, - "baseUrl": "./src", - "declaration": true, - "esModuleInterop": true, - "lib": ["DOM", "ES2020"], - "module": "NodeNext", - "noImplicitAny": true, - "outDir": "dist/", - "skipLibCheck": true, - "strict": true + "lib": ["DOM", "ES2023"], + "outDir": "dist/" }, "include": ["./src/**/*"] } diff --git a/packages/httpsnippet-client-api/tsup.config.ts b/packages/httpsnippet-client-api/tsup.config.ts new file mode 100644 index 00000000..f8a9cf70 --- /dev/null +++ b/packages/httpsnippet-client-api/tsup.config.ts @@ -0,0 +1,15 @@ +import type { Options } from 'tsup'; + +// eslint-disable-next-line import/no-extraneous-dependencies +import { defineConfig } from 'tsup'; + +// eslint-disable-next-line import/no-relative-packages +import config from '../../tsup.config.js'; + +export default defineConfig((options: Options) => ({ + ...options, + ...config, + + entry: ['src/index.ts'], + silent: !options.watch, +})); diff --git a/packages/test-utils/index.ts b/packages/test-utils/index.ts new file mode 100644 index 00000000..9b921a4a --- /dev/null +++ b/packages/test-utils/index.ts @@ -0,0 +1,2 @@ +export * from './fetch-mock.js'; +export * from './load-spec.js'; diff --git a/packages/test-utils/load-spec.ts b/packages/test-utils/load-spec.ts index 0ebdc959..d1b0dcb0 100644 --- a/packages/test-utils/load-spec.ts +++ b/packages/test-utils/load-spec.ts @@ -3,6 +3,6 @@ * we may need to sometimes fully clone a spec to test something. This is just a small DIY wrapper * for doing so. */ -export default function loadSpec(spec: string) { +export function loadSpec(spec: string) { return import(spec).then(({ default: data }) => JSON.stringify(data)).then(JSON.parse); } diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 0162b615..0fe14ba1 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -13,7 +13,7 @@ }, "devDependencies": { "@types/caseless": "^0.12.3", - "oas": "^22.0.0", + "oas": "^23.0.0", "typescript": "^5.2.2" }, "prettier": "@readme/eslint-config/prettier" diff --git a/packages/test-utils/tsconfig.json b/packages/test-utils/tsconfig.json index 682fddeb..ee3ff1b6 100644 --- a/packages/test-utils/tsconfig.json +++ b/packages/test-utils/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "../../tsconfig.base.json", "compilerOptions": { - "allowJs": true, - "baseUrl": "./src", - "declaration": true, - "esModuleInterop": true, - "module": "NodeNext", - "noEmit": true, - "noImplicitAny": true, - "skipLibCheck": true, - "strict": true + "lib": ["DOM", "ES2023"], + "noEmit": true }, "include": ["./**/*"] } diff --git a/packages/test-utils/vitest.matchers.ts b/packages/test-utils/vitest.matchers.ts index f9fa80b0..9b3c8f35 100644 --- a/packages/test-utils/vitest.matchers.ts +++ b/packages/test-utils/vitest.matchers.ts @@ -48,6 +48,7 @@ expect.extend({ }, toHaveHeader(obj: Headers, header: string, expected: RegExp | (string | number)[] | string) { + // @ts-expect-error `Headers.entries()` exists despite what the types here suggest. const headers = caseless(Object.fromEntries(Array.from(obj.entries()))); // Header value should match a given regex. diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000..dc62d702 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,12 @@ +{ + "extends": "@tsconfig/node18/tsconfig.json", + "compilerOptions": { + "allowJs": true, + "baseUrl": "src/", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true, + "useUnknownInCatchVariables": false + } +} 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;