Skip to content

Commit

Permalink
Clean up typing and make it compatible with both CJS and ESM
Browse files Browse the repository at this point in the history
Update `tsconfig.json`, `package.json`, and `jest.config.js` for ESM compatibility.

* **`tsconfig.json`**
  - Add `"module": "ESNext"` to `compilerOptions`.
  - Add `"moduleResolution": "node"` to `compilerOptions`.

* **`package.json`**
  - Add `"exports": { ".": { "import": "./lib/index.mjs", "require": "./lib/index.js" } }`.
  - Add `"type": "module"`.

* **`jest.config.js`**
  - Add `"transform": { "^.+\\.tsx?$": ["ts-jest", { "useESM": true }] }`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/jpwilliams/waitgroup?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
jpwilliams committed Nov 27, 2024
1 parent 7fa5203 commit cbd5be6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
'<rootDir>/src'
],
transform: {
'^.+\\.tsx?$': 'ts-jest'
'^.+\\.tsx?$': ['ts-jest', { useESM: true }]
},
verbose: true,
testEnvironment: 'node'
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,12 @@
"onchange": "^7.1.0",
"ts-jest": "^29.1.2",
"typescript": "^5.4.2"
}
},
"exports": {
".": {
"import": "./lib/index.mjs",
"require": "./lib/index.js"
}
},
"type": "module"
}
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"noUnusedLocals": true,
"pretty": true,
"strict": true, // includes noImplicitAny, noImplicitThis, alwaysStrict and all strict options
"outDir": "lib"
"outDir": "lib",
"module": "ESNext",
"moduleResolution": "node"
},
"include": [
"src/**/*"
Expand Down

0 comments on commit cbd5be6

Please sign in to comment.