Skip to content

Commit

Permalink
fix: _types generation and modernizes module resolution. (#56)
Browse files Browse the repository at this point in the history
Currently, the `_types` is built using `node` module resolution, which results in this project generating invalid types.  Details about the TypeScript bug can be found at microsoft/TypeScript#60930 (comment) and there are no plans to fix it since `node` (which is equivalent to `node10`) is being deprecated in TypeScript soon.

The way this bug manifests is in files like `src/_types/core/P256.d.ts` where it would previously generate code like:�```ts
create: (hash: import("@noble/curves/abstract/utils.js").CHash) => import("@noble/curves/abstract/weierstrass.js").CurveFn;
```
when it should have generated code like this (which is what is generated after this change):�```ts
create: (hash: import("@noble/curves/abstract/utils").CHash) => import("@noble/curves/abstract/weierstrass").CurveFn;
```

For the cjs build command, I changed from `node` to `node10` to be more explicit/clear, since `node` was just an alias for `node10`.

For the esm build command, I changed it to use the tsconfig so it is less likely to get out of sync with the generated types.

Also updated .gitignore to ignore `.pnpm-store` which had 30,000 files it wanted to commit after I did `pnpm install` using the recommended version of `pnpm`.
  • Loading branch information
MicahZoltu authored Jan 15, 2025
1 parent 2769eb1 commit c3a4290
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.attest
.env
.local
.pnpm-store
_esm
_cjs
_types
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"bench": "vitest -c ./test/vitest.config.ts bench",
"bench:types": "TYPES=true vitest -c ./test/vitest.config.ts src/**/*.bench-d.ts",
"build": "pnpm clean && pnpm build:cjs && pnpm build:esm && pnpm build:types",
"build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./src/_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./src/_esm/package.json",
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./src/_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./src/_cjs/package.json",
"build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./src/_types --emitDeclarationOnly --declaration --declarationMap",
"build:esm": "tsc --project ./tsconfig.build.json --outDir ./src/_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./src/_esm/package.json",
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --moduleResolution node10 --outDir ./src/_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./src/_cjs/package.json",
"build:types": "tsc --project ./tsconfig.build.json --declarationDir ./src/_types --emitDeclarationOnly --declaration --declarationMap",
"changeset:prepublish": "pnpm version:update && pnpm build && tsx scripts/prepublish.ts",
"changeset:publish": "pnpm changeset:prepublish && changeset publish",
"changeset:version": "changeset version && pnpm version:update && pnpm format",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"importHelpers": true, // This is only used for build validation. Since we do not have `tslib` installed, this will fail if we accidentally make use of anything that'd require injection of helpers.

// Language and environment
"moduleResolution": "NodeNext",
"module": "NodeNext",
"moduleResolution": "nodenext",
"module": "nodenext",
"target": "ES2021", // Setting this to `ES2021` enables native support for `Node v16+`: https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping.
"lib": [
"ES2022", // By using ES2022 we get access to the `.cause` property on `Error` instances.
Expand Down
1 change: 0 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"src/**/*.test-d.ts"
],
"compilerOptions": {
"moduleResolution": "node",
"sourceMap": true,
"rootDir": "./src"
}
Expand Down

0 comments on commit c3a4290

Please sign in to comment.