Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix importing types on Node 16 module resolution #424

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ npx tsc ./src/index.mjs \
--allowJs \
--emitDeclarationOnly \
--outDir $outdir/types

mv $outdir/types/opa.d.ts $outdir/types/opa.d.mts
cp $outdir/types/opa.d.mts $outdir/types/opa.d.cts
Comment on lines +45 to +46
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately separate declaration files are required. Otherwise, typescript will assume the types are either ESM or CJS depending on the value of the type field of the nearest package.json.

59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
"version": "1.8.1",
"description": "Open Policy Agent WebAssembly SDK",
"main": "./src/index.cjs",
"types": "./dist/types/opa.d.ts",
"types": "./dist/types/opa.d.cts",
"exports": {
"import": "./src/index.mjs",
"require": "./src/index.cjs"
".": {
"types": {
"import": "./dist/types/opa.d.mts",
"require": "./dist/types/opa.d.cts"
},
"import": "./src/index.mjs",
"require": "./src/index.cjs"
}
},
"files": [
"capabilities.json",
Expand Down