Skip to content

Commit

Permalink
feat: provide exports for CommonJS modules (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-fricke committed May 27, 2024
1 parent a19d3da commit 37da681
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-swans-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-msw": minor
---

Added compilation and exports for CommonJS modules. This makes OpenAPI-MSW usable in projects that still use CommonJS as their module system.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coverage
cjs
dist
node_modules
test/fixtures/*.ts
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tsEslint from "typescript-eslint";

export default tsEslint.config(
{
ignores: ["coverage", "dist", "test/fixtures/*.ts"],
ignores: ["coverage", "cjs", "dist", "test/fixtures/*.ts"],
},
eslint.configs.recommended,
...tsEslint.configs.recommended,
Expand Down
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,31 @@
"description": "Tiny, type-safe wrapper around MSW for type inference from OpenAPI schemas.",
"repository": "github:christoph-fricke/openapi-msw",
"files": [
"cjs",
"dist",
"CHANGELOG.md",
"README.md",
"LICENSE"
],
"sideEffects": false,
"types": "./dist/exports/main.d.ts",
"main": "./cjs/exports/main.js",
"module": "./dist/exports/main.js",
"exports": {
".": {
"types": "./dist/exports/main.d.ts",
"import": "./dist/exports/main.js"
"types": {
"import": "./dist/exports/main.d.ts",
"require": "./cjs/exports/main.d.js"
},
"import": "./dist/exports/main.js",
"require": "./cjs/exports/main.js"
}
},
"scripts": {
"prepare": "husky",
"build": "rimraf ./dist && tsc -p tsconfig.build.json",
"build": "npm run build:esm && npm run build:cjs",
"build:esm": "rimraf ./dist && tsc -p tsconfig.build.json",
"build:cjs": "rimraf ./cjs && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > ./cjs/package.json",
"format": "prettier --write .",
"lint": "eslint . && prettier -c .",
"generate": "openapi-typescript -c ./test/fixtures/.redocly.yml",
Expand Down
10 changes: 10 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "./tsconfig.build.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"verbatimModuleSyntax": false,
"outDir": "./cjs"
}
}

0 comments on commit 37da681

Please sign in to comment.