flitbit / json-ptr

A complete implementation of JSON Pointer (RFC 6901) for nodejs and modern browsers.
MIT License
91 stars 28 forks source link

Update package.json export statements for TS 4.7 Node ESM Support #54

Closed elimumford closed 2 years ago

elimumford commented 2 years ago

Update package.json export statements for TS 4.7 Node ESM Support. See for more information https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-rc/#ecmascript-module-support-in-node-js

When v3.1.0 is consumed in a project configured as such, TS presents this error:

Could not find a declaration file for module 'json-ptr'. './node_modules/json-ptr/dist/esm/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/json-ptr` if it exists or add a new declaration (.d.ts) file containing `declare module 'json-ptr';`ts(7016)

This update uses the simplest format that works in testing, but there is a more verbose option, but not sure of it's impact on other environments:

  "exports": {
    ".": {
      "import": {
        "default": "./dist/esm/index.js",
        "types": "./dist/types/index.d.ts"
      },
      "require": {
        "default": "./dist/cjs/index.js",
        "types": "./dist/types/index.d.ts"
      }
    }
  }

I've tried other potential options such as /// <reference path="" /> directives and trying to include the .d.ts in the tsconfig includes/paths. These didn't change behaviors, so my guess is the TS team didn't opt for mixed support levels, hence the issue to begin with.

Note, package-lock also contains the minimist 1.2.5 => 1.2.6 update to address a critical vulnerability in that library. This matches the changes in the bot PR https://github.com/flitbit/json-ptr/pull/53