From d84d4217dfe0afbf18f0fab478ca44ca7c70d855 Mon Sep 17 00:00:00 2001 From: Paul Desmond Parker Date: Fri, 18 Jul 2025 20:14:40 +0800 Subject: [PATCH 1/3] fix: mismatched ethers types when in esm project Fix mismatch of ethers/lib.commonjs Provider with ethers/lib.esm Provider. This has been an issue when attempting to construct configuration driven provider fallbacks for did-resolver Drilling down to the Provider type via this package within an esm package yielded a `lib.commonjs` `Provider` that did not match the esm ethers `Provider`. Restructure build directories into `lib.commonjs` and `lib.esm`. Matches structure in ethers.js Adjust .gitignore to exclude new out directories Separated into two tsconfig files named `tsconfig.{common,esm}.json` [package.json] Removed `source` [not in spec] Removed `type`, `module`, and `types` from top level Added `import` and `require` to `exports` and re-added `types` Modified `files` to point to new out dirs, removed LICENSE (included by default), and src (no utility). Modified script `clean` Added new `build:` scripts both called from `build` --- .gitignore | 5 +++-- esm/index.js | 28 -------------------------- esm/package.json | 3 --- package.json | 29 +++++++++++++-------------- tsconfig.json => tsconfig.common.json | 5 +++-- tsconfig.esm.json | 26 ++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 50 deletions(-) delete mode 100644 esm/index.js delete mode 100644 esm/package.json rename tsconfig.json => tsconfig.common.json (89%) create mode 100644 tsconfig.esm.json diff --git a/.gitignore b/.gitignore index b3c6a9d3..6f62f773 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -lib/ +lib.commonjs/ +lib.esm/ # Created by https://www.gitignore.io/api/node,linux,macos,windows,intellij # Edit at https://www.gitignore.io/?templates=node,linux,macos,windows,intellij @@ -224,4 +225,4 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -# End of https://www.gitignore.io/api/node,linux,macos,windows,intellij \ No newline at end of file +# End of https://www.gitignore.io/api/node,linux,macos,windows,intellij diff --git a/esm/index.js b/esm/index.js deleted file mode 100644 index 509ddbaf..00000000 --- a/esm/index.js +++ /dev/null @@ -1,28 +0,0 @@ -import cjsModule from '../lib/index.js' - -const getResolver = cjsModule.getResolver -const deployments = cjsModule.deployments -const REGISTRY = cjsModule.REGISTRY -const bytes32toString = cjsModule.bytes32toString -const stringToBytes32 = cjsModule.stringToBytes32 -const EthrDidController = cjsModule.EthrDidController -const verificationMethodTypes = cjsModule.verificationMethodTypes -const identifierMatcher = cjsModule.identifierMatcher -const interpretIdentifier = cjsModule.interpretIdentifier -const Errors = cjsModule.Errors -const EthereumDIDRegistry = cjsModule.EthereumDIDRegistry - -export { - getResolver, - deployments, - REGISTRY, - bytes32toString, - stringToBytes32, - EthrDidController, - verificationMethodTypes, - identifierMatcher, - interpretIdentifier, - Errors, - EthereumDIDRegistry, - cjsModule as default -} diff --git a/esm/package.json b/esm/package.json deleted file mode 100644 index 3dbc1ca5..00000000 --- a/esm/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "type": "module" -} diff --git a/package.json b/package.json index 7eb6a1c2..e4617ac3 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,15 @@ "name": "ethr-did-resolver", "version": "11.0.4", "description": "Resolve DID documents for ethereum addresses and public keys", - "type": "commonjs", - "source": "./src/index.ts", - "main": "./lib/index.js", - "module": "./esm/index.js", - "types": "./lib/index.d.ts", + "main": "./lib.commonjs/index.js", "exports": { - ".": { - "types": "./lib/index.d.ts", - "import": "./esm/index.js", - "require": "./lib/index.js" + "import": { + "types": "./lib.esm/index.d.ts", + "default": "./lib.esm/index.js" + }, + "require": { + "types": "./lib.commonjs/index.d.ts", + "default": "./lib.commonjs/index.js" } }, "repository": { @@ -19,10 +18,8 @@ "url": "git@github.com:decentralized-identity/ethr-did-resolver.git" }, "files": [ - "lib", - "esm", - "src", - "LICENSE" + "lib.commonjs", + "lib.esm" ], "author": "Pelle Braendgaard", "contributors": [ @@ -49,8 +46,10 @@ "scripts": { "test": "jest", "test:ci": "jest --coverage", - "build": "tsc", - "clean": "rm -rf ./lib", + "build": "yarn run build:common && yarn run build:esm", + "build:common": "tsc --project tsconfig.common.json", + "build:esm": "tsc --project tsconfig.esm.json", + "clean": "rm -rf ./lib.commonjs ./lib.esm", "format": "prettier --write \"src/**/*.[jt]s\"", "lint": "eslint --ignore-pattern \"src/**/*.test.[jt]s\" \"src/**/*.[jt]s\"", "prepublishOnly": "yarn test:ci && yarn format && yarn lint", diff --git a/tsconfig.json b/tsconfig.common.json similarity index 89% rename from tsconfig.json rename to tsconfig.common.json index 4c2f6521..e8626ec2 100644 --- a/tsconfig.json +++ b/tsconfig.common.json @@ -10,7 +10,7 @@ "declaration": true, "declarationMap": true, "sourceMap": true, - "outDir": "lib", + "outDir": "lib.commonjs", "strict": true, "skipLibCheck": true, "noImplicitThis": false, @@ -22,7 +22,8 @@ "exclude": [ "**/__tests__/*", "node_modules", - "lib" + "lib.commonjs", + "lib.esm" ], "include": [ "src" diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 00000000..98464687 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "nodenext", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "outDir": "lib.esm", + "strict": true, + "skipLibCheck": true, + "noImplicitThis": false, + "moduleResolution": "nodenext", + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "esModuleInterop": true + }, + "exclude": [ + "**/__tests__/*", + "node_modules", + "lib.commonjs", + "lib.esm" + ], + "include": [ + "src" + ] +} From 85e79b197be727ab7bfec195b1e1f6add0e90c1f Mon Sep 17 00:00:00 2001 From: Paul Desmond Parker Date: Tue, 22 Jul 2025 14:59:49 +0800 Subject: [PATCH 2/3] fix: change exports --- package.json | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e4617ac3..55a0c98e 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,10 @@ "version": "11.0.4", "description": "Resolve DID documents for ethereum addresses and public keys", "main": "./lib.commonjs/index.js", + "types": "./lib.commonjs/index.d.ts", "exports": { - "import": { - "types": "./lib.esm/index.d.ts", - "default": "./lib.esm/index.js" - }, - "require": { - "types": "./lib.commonjs/index.d.ts", + ".": { + "import": "./lib.esm/index.js", "default": "./lib.commonjs/index.js" } }, From d42bf4010174645526c283c157b3d59bcc628883 Mon Sep 17 00:00:00 2001 From: Paul Desmond Parker Date: Fri, 25 Jul 2025 14:34:23 +0800 Subject: [PATCH 3/3] fix(test): specify tsconfig in jest config --- jest.config.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/jest.config.mjs b/jest.config.mjs index 15615ee7..e43899b2 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -30,6 +30,7 @@ const config = { 'ts-jest', { useESM: true, + tsconfig: 'tsconfig.esm.json', }, ], },