Skip to content

Commit

Permalink
fix: restore the types field in the package.json file (#28)
Browse files Browse the repository at this point in the history
TypeScript may not use the `"types"` import condition.

For example, if the value of the `moduleResolution` option is `"node"`. In this case, TypeScript uses the `types` field and the `"types"` import condition is not used.

So even if the `"types"` import condition is used, `package.json` still needs the `types` field for fallback. Therefore, I have restored the `types` field that was removed in f724043.

Resolves #26

- [x] I tested this change

    ```console
    $ pnpm run build && pnpm pack
    $
    $ mkdir test-pr-28 && cd test-pr-28
    $
    $ echo '{}' > ./package.json
    $ echo '{ "compilerOptions": { "moduleResolution": "node", "esModuleInterop": true, "strict": true } }' > ./tsconfig.node.json
    $ echo '{ "compilerOptions": { "moduleResolution": "node16", "esModuleInterop": true, "strict": true } }' > ./tsconfig.node16.json
    $
    $ echo 'console.log(require("used-pm")())' > foo.cjs
    $ echo 'import currentPackageManager from "used-pm"; console.log(currentPackageManager())' > foo.mjs
    $ cp foo.mjs foo.cts
    $ cp foo.mjs foo.mts
    $
    $ npm i typescript ../used-pm-1.0.2.tgz # I am using the npm command by intention. When using pnpm, used-pm 1.0.2 released to npm may be added instead of used-pm-1.0.2.tgz due to global caching
    $
    $ pnpm exec node foo.cjs && pnpm exec node foo.mjs && pnpm exec tsc -p tsconfig.node16.json --noEmit && pnpm exec tsc -p tsconfig.node.json --noEmit
    ```
  • Loading branch information
sounisi5011 committed May 29, 2023
1 parent bf32d74 commit 963e138
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
}
},
"types": "./dist/index.d.cts",
"files": [
"./dist/"
],
Expand Down

0 comments on commit 963e138

Please sign in to comment.