[WIP] Fix ES module native support#781
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## epic-v0.7.x #781 +/- ##
===============================================
+ Coverage 87.45% 90.19% +2.73%
===============================================
Files 82 98 +16
Lines 5778 8584 +2806
Branches 391 567 +176
===============================================
+ Hits 5053 7742 +2689
- Misses 688 799 +111
- Partials 37 43 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR aims to improve native ESM support (while keeping CJS compatibility) across the monorepo packages by adjusting TypeScript emit/import behavior, package export maps, and build artifacts, and by adding consumer-level smoke tests in CI.
Changes:
- Update TS source/test imports to use explicit
.jsspecifiers and adjust TS module resolution settings for ESM builds. - Add post-build “dist marker”
package.jsonfiles (type: module/commonjs) and refineexportsmaps (including conditionaltypes). - Add ESM/CJS consumer smoke-test script and wire it into GitHub Actions CI.
Reviewed changes
Copilot reviewed 165 out of 166 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/test-consumer.cjs | Adds a temporary consumer fixture to validate ESM/CJS consumption of packed tarballs. |
| scripts/fix-dist-markers.cjs | Writes dist/es/package.json and dist/cjs/package.json marker files to enforce module type. |
| packages/test-utils/tsconfig.es.json | Uses moduleResolution: Bundler for ESM build. |
| packages/test-utils/tsconfig.cjs.json | Sets CJS build options (module + moduleResolution). |
| packages/test-utils/src/utils.ts | Updates relative import specifier to .js. |
| packages/test-utils/src/index.ts | Updates re-exports to .js specifiers. |
| packages/test-utils/package.json | Updates exports shape (types/default), adds postbuild to write dist markers, updates author. |
| packages/test-utils/.eslintrc.js | Removes per-package JS ESLint config (transition to CJS config). |
| packages/test-utils/.eslintrc.cjs | Adds per-package CJS ESLint config referencing root config. |
| packages/taco/tsconfig.es.json | Uses moduleResolution: Bundler for ESM build. |
| packages/taco/tsconfig.cjs.json | Sets CJS build options (module + moduleResolution). |
| packages/taco/test/utils.test.ts | Updates import specifier to .js. |
| packages/taco/test/test-utils.ts | Updates many internal imports to .js specifiers. |
| packages/taco/test/taco.test.ts | Updates imports to explicit .js entrypoints. |
| packages/taco/test/taco-sign.test.ts | Updates imports to .js specifiers and reformats long line for readability. |
| packages/taco/test/dkg-client.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/variable-operation.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/sequential.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/return-value-test.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/predefined/erc721.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/predefined/erc20.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/predefined/address-allowlist.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/lingo.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/if-then-else-condition.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/context.test.ts | Updates many imports to .js specifiers and adjusts import sources to explicit index files. |
| packages/taco/test/conditions/conditions.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/condition-expr.test.ts | Updates imports to .js specifiers and adjusts formatting for multi-line import. |
| packages/taco/test/conditions/compound-condition.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/time.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/signing.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/rpc.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/jwt.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/json.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/json-rpc.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/json-path.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/json-api.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/ecdsa.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/contract.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/context-variable.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/base/condition.test.ts | Updates imports to .js specifiers. |
| packages/taco/test/conditions/any-condition-schema.test.ts | Updates imports to .js specifiers. |
| packages/taco/src/tdec.ts | Replaces ethers/lib/utils imports with ethers.utils.* and updates internal imports to .js. |
| packages/taco/src/taco.ts | Replaces ethers/lib/utils usage with ethers.utils.keccak256 and updates internal imports to .js. |
| packages/taco/src/sign.ts | Updates internal imports to .js. |
| packages/taco/src/index.ts | Updates re-exports/imports to explicit index.js/.js specifiers. |
| packages/taco/src/conditions/shared.ts | Updates schema re-exports to .js specifiers. |
| packages/taco/src/conditions/sequential.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/schemas/variable-operation.ts | Updates schema import to .js. |
| packages/taco/src/conditions/schemas/utils.ts | Updates many schema imports to .js. |
| packages/taco/src/conditions/schemas/time.ts | Updates schema import to .js. |
| packages/taco/src/conditions/schemas/signing.ts | Switches to ethers top-level import and uses ethers.utils.*, updates schema imports to .js. |
| packages/taco/src/conditions/schemas/sequential.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/rpc.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/return-value-test.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/jwt.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/json.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/json-rpc.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/json-api.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/if-then-else.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/export-for-zod-doc-gen.ts | Updates export list to .js specifiers (preserving export order comments). |
| packages/taco/src/conditions/schemas/ecdsa.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/contract.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/context.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/context-variable.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/compound.ts | Updates imports to .js. |
| packages/taco/src/conditions/schemas/common.ts | Updates imports to .js. |
| packages/taco/src/conditions/predefined/index.ts | Updates predefined exports to .js. |
| packages/taco/src/conditions/predefined/erc721.ts | Updates import to .js. |
| packages/taco/src/conditions/predefined/erc20.ts | Updates import to .js. |
| packages/taco/src/conditions/predefined/address-allowlist.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/multi-condition.ts | Updates imports to .js (and formats multiline import). |
| packages/taco/src/conditions/index.ts | Updates imports/exports to .js and explicit index modules. |
| packages/taco/src/conditions/if-then-else-condition.ts | Updates imports/exports to .js. |
| packages/taco/src/conditions/context/index.ts | Updates export to .js specifier. |
| packages/taco/src/conditions/context/context.ts | Updates imports to .js specifiers. |
| packages/taco/src/conditions/condition.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/condition-factory.ts | Updates many imports to .js specifiers and reorders some imports. |
| packages/taco/src/conditions/condition-expr.ts | Updates imports to .js specifiers. |
| packages/taco/src/conditions/compound-condition.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/time.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/signing.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/rpc.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/jwt.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/json.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/json-rpc.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/json-api.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/index.ts | Updates base module exports to .js. |
| packages/taco/src/conditions/base/ecdsa.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/contract.ts | Updates imports/exports to .js specifiers. |
| packages/taco/src/conditions/base/context-variable.ts | Updates imports/exports to .js specifiers. |
| packages/taco/package.json | Updates version, exports map (types/default), and adds postbuild to write dist markers. |
| packages/taco/integration-test/sign.test.ts | Updates imports to .js specifiers. |
| packages/taco/integration-test/encrypt-decrypt.test.ts | Updates imports to .js specifiers and reorders CompoundCondition import. |
| packages/taco/integration-test/condition-lingo.test.ts | Updates imports to .js specifiers. |
| packages/taco/.eslintrc.js | Removes per-package JS ESLint config (transition to CJS config). |
| packages/taco/.eslintrc.cjs | Adds per-package CJS ESLint config referencing root config. |
| packages/taco-auth/tsconfig.es.json | Uses moduleResolution: Bundler for ESM build. |
| packages/taco-auth/tsconfig.cjs.json | Sets CJS build options (module + moduleResolution). |
| packages/taco-auth/test/auth-sig.test.ts | Updates imports to .js specifiers. |
| packages/taco-auth/test/auth-provider.test.ts | Updates imports to .js specifiers and adjusts import order. |
| packages/taco-auth/src/storage.ts | Updates import to .js specifier. |
| packages/taco-auth/src/providers/index.ts | Updates exports to .js specifiers. |
| packages/taco-auth/src/providers/eip4361/external-eip4361.ts | Updates imports to .js specifiers. |
| packages/taco-auth/src/providers/eip4361/eip4361.ts | Updates imports to .js specifiers. |
| packages/taco-auth/src/providers/eip4361/auth.ts | Updates import to .js specifier. |
| packages/taco-auth/src/providers/eip1271/eip1271.ts | Updates imports to .js specifiers. |
| packages/taco-auth/src/providers/eip1271/auth.ts | Updates import to .js specifier. |
| packages/taco-auth/src/index.ts | Updates exports to .js specifiers and explicit providers index. |
| packages/taco-auth/src/auth-sig.ts | Updates provider imports to .js specifiers. |
| packages/taco-auth/src/auth-provider.ts | Updates import to .js specifier. |
| packages/taco-auth/package.json | Updates version, exports map (types/default), and adds postbuild to write dist markers. |
| packages/taco-auth/.eslintrc.js | Removes per-package JS ESLint config (transition to CJS config). |
| packages/taco-auth/.eslintrc.cjs | Adds per-package CJS ESLint config referencing root config. |
| packages/shared/tsconfig.es.json | Uses moduleResolution: Bundler for ESM build. |
| packages/shared/tsconfig.cjs.json | Sets CJS build options (module + moduleResolution). |
| packages/shared/test/signing-coordinator-cache.test.ts | Updates imports/mocks to .js specifiers for typechain index. |
| packages/shared/test/schemas.test.ts | Updates import to explicit index.js. |
| packages/shared/test/porter.test.ts | Updates imports to .js specifiers. |
| packages/shared/src/web3.ts | Updates import to .js specifier. |
| packages/shared/src/types.ts | Updates import to .js specifier. |
| packages/shared/src/porter.ts | Updates imports to .js specifiers and formats multi-line import. |
| packages/shared/src/index.ts | Updates exports to explicit .js/index.js specifiers. |
| packages/shared/src/contracts/index.ts | Updates exports to explicit index.js specifiers. |
| packages/shared/src/contracts/ethers-typechain/index.ts | Updates generated exports/imports to .js specifiers and uses explicit factories index. |
| packages/shared/src/contracts/ethers-typechain/factories/index.ts | Updates generated factory exports to .js specifiers. |
| packages/shared/src/contracts/ethers-typechain/factories/SubscriptionManager__factory.ts | Updates generated import to .js specifier. |
| packages/shared/src/contracts/ethers-typechain/factories/SigningCoordinator__factory.ts | Updates generated import to .js specifier and reflects ABI/type updates. |
| packages/shared/src/contracts/ethers-typechain/factories/GlobalAllowList__factory.ts | Updates generated import to .js specifier. |
| packages/shared/src/contracts/ethers-typechain/factories/Coordinator__factory.ts | Updates generated import to .js specifier and reflects ABI/type updates. |
| packages/shared/src/contracts/ethers-typechain/SubscriptionManager.ts | Updates generated import to .js specifier. |
| packages/shared/src/contracts/ethers-typechain/SigningCoordinator.ts | Updates generated import to .js specifier and reflects ABI/type updates. |
| packages/shared/src/contracts/ethers-typechain/GlobalAllowList.ts | Updates generated import to .js specifier. |
| packages/shared/src/contracts/ethers-typechain/Coordinator.ts | Updates generated import to .js specifier and reflects ABI/type updates. |
| packages/shared/src/contracts/agents/subscription-manager.ts | Updates imports to .js specifiers and uses explicit typechain index. |
| packages/shared/src/contracts/agents/signing-coordinator.ts | Updates imports to .js specifiers and uses explicit typechain index/type files. |
| packages/shared/src/contracts/agents/index.ts | Updates exports to .js specifiers. |
| packages/shared/src/contracts/agents/global-allow-list.ts | Updates imports to .js specifiers and formats multi-line typechain imports. |
| packages/shared/src/contracts/agents/coordinator.ts | Updates imports to .js specifiers and uses explicit typechain index/type files. |
| packages/shared/scripts/typechain.ts | Post-processes generated TypeChain TS files to add .js extensions in relative specifiers. |
| packages/shared/package.json | Updates version, exports map (types/default), and adds postbuild to write dist markers. |
| packages/shared/.eslintrc.js | Removes per-package JS ESLint config (transition to CJS config). |
| packages/shared/.eslintrc.cjs | Adds per-package CJS ESLint config referencing root config. |
| packages/pre/tsconfig.es.json | Uses moduleResolution: Bundler for ESM build. |
| packages/pre/tsconfig.cjs.json | Sets CJS build options (module + moduleResolution). |
| packages/pre/test/utils.ts | Updates imports to .js specifiers and explicit index modules. |
| packages/pre/test/pre.test.ts | Updates imports to .js specifiers. |
| packages/pre/test/message-kit.test.ts | Updates imports to .js specifiers. |
| packages/pre/test/enrico.test.ts | Updates imports to .js specifiers. |
| packages/pre/test/cohort.test.ts | Updates imports to .js specifiers. |
| packages/pre/test/acceptance/delay-enact.test.ts | Updates imports to .js specifiers. |
| packages/pre/test/acceptance/alice-grants.test.ts | Updates imports to .js specifiers. |
| packages/pre/src/policy.ts | Updates import to .js specifier. |
| packages/pre/src/kits/message.ts | Updates import to .js specifier. |
| packages/pre/src/kits/index.ts | Updates exports to .js specifiers. |
| packages/pre/src/keyring.ts | Updates import to explicit index.js specifier. |
| packages/pre/src/index.ts | Updates exports to explicit .js specifiers. |
| packages/pre/src/characters/index.ts | Updates exports to .js specifiers. |
| packages/pre/src/characters/enrico.ts | Updates import to .js specifier. |
| packages/pre/src/characters/bob.ts | Updates imports to .js specifiers. |
| packages/pre/src/characters/alice.ts | Updates imports to .js specifiers. |
| packages/pre/package.json | Updates author, exports map (types/default), and adds postbuild to write dist markers. |
| packages/pre/.eslintrc.js | Removes per-package JS ESLint config (transition to CJS config). |
| packages/pre/.eslintrc.cjs | Adds per-package CJS ESLint config referencing root config. |
| package.json | Updates root build script to run dist marker fixer; adds ESM/CJS consumer test scripts; updates author. |
| .github/workflows/main.yml | Adds CI step to run ESM and CJS consumer smoke tests. |
| .eslintrc.cjs | Adds root ESLint config in CJS format (replacing prior .js pattern). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "module": "CommonJS", | ||
| "moduleResolution": "node" |
There was a problem hiding this comment.
moduleResolution is set to node but the codebase now uses .js extensions in TS import specifiers. This combination commonly breaks TS resolution for local modules (it will look for a real .js file). Consider using moduleResolution: node16/nodenext (or Bundler) to support .js specifiers that map to .ts sources.
| "module": "CommonJS", | ||
| "moduleResolution": "node" |
There was a problem hiding this comment.
moduleResolution is set to node while the package now uses .js in TS import specifiers. This is likely to break the CJS tsc --build step because TypeScript won't resolve ./foo.js to ./foo.ts under node resolution. Consider switching to node16/nodenext (or keeping Bundler).
| "module": "CommonJS", | |
| "moduleResolution": "node" | |
| "module": "Node16", | |
| "moduleResolution": "node16" |
| "module": "CommonJS", | ||
| "moduleResolution": "node" |
There was a problem hiding this comment.
moduleResolution is set to node but the source now imports ./*.js paths from TS. Under node resolution, TypeScript generally requires the actual .js file to exist, so this will likely break the CJS build. Consider using node16/nodenext (or Bundler) so .js specifiers can resolve to .ts sources.
| const sourceTarball = path.join(packageDir, tarballName); | ||
| const targetTarball = path.join(tempRoot, tarballName); | ||
| fs.renameSync(sourceTarball, targetTarball); | ||
| return targetTarball; |
There was a problem hiding this comment.
fs.renameSync can fail with EXDEV when moving the tarball from the package directory to a temp directory on a different filesystem (common with /tmp). Using fs.copyFileSync + fs.rmSync/unlinkSync (or fs.cpSync) avoids cross-device rename issues and makes this consumer test more reliable in CI.
| "module": "CommonJS", | ||
| "moduleResolution": "node" |
There was a problem hiding this comment.
moduleResolution is set to node while the source imports use explicit .js extensions (e.g. ./foo.js). With TypeScript, .js-in-specifier substitution to .ts generally requires moduleResolution: node16/nodenext (or keeping Bundler). As-is, the CJS build is likely to fail module resolution for these imports. Consider switching this to node16/nodenext (recommended for Node ESM/CJS dual packages) or keeping Bundler here as well for consistency with the ESM build.
| "module": "CommonJS", | ||
| "moduleResolution": "node" |
There was a problem hiding this comment.
moduleResolution is set to node while the package sources now import with .js extensions. TypeScript's ability to resolve ./x.js to ./x.ts typically requires moduleResolution: node16/nodenext (or Bundler). With node, the CJS build is likely to fail to resolve local imports. Consider using node16/nodenext here (or keeping Bundler).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 165 out of 166 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "outDir": "dist/cjs", | ||
| "module": "CommonJS" | ||
| "module": "CommonJS", | ||
| "moduleResolution": "node" | ||
| } |
There was a problem hiding this comment.
moduleResolution: "node" will not resolve the new .js-suffixed relative imports in your TS sources (e.g. packages/shared/src/web3.ts:1 imports ./utils.js, but only utils.ts exists). This is likely to break tsc --build ./tsconfig.cjs.json. Consider using moduleResolution: "Bundler" (same as the ESM build) or "NodeNext"/"Node16" so .js specifiers map to .ts sources during compilation.
| "outDir": "dist/cjs", | ||
| "module": "CommonJS" | ||
| "module": "CommonJS", | ||
| "moduleResolution": "node" | ||
| } |
There was a problem hiding this comment.
With .js extensions now used in relative imports (e.g. packages/taco/src/index.ts:22-23 exports from ./sign.js and ./taco.js), moduleResolution: "node" typically won't resolve those specifiers to the corresponding .ts sources during compilation. This is likely to break the CJS build. Consider moduleResolution: "Bundler" or "NodeNext"/"Node16" instead.
| "outDir": "dist/cjs", | ||
| "module": "CommonJS" | ||
| "module": "CommonJS", | ||
| "moduleResolution": "node" | ||
| } |
There was a problem hiding this comment.
moduleResolution: "node" will generally fail to compile TS projects that use .js-suffixed relative specifiers in source (e.g. this package now imports ./auth-provider.js, ./providers/index.js, etc.). This risks breaking tsc --build ./tsconfig.cjs.json. Use moduleResolution: "Bundler" (or "NodeNext"/"Node16") so .js specifiers can resolve to .ts inputs.
| "outDir": "dist/cjs", | ||
| "module": "CommonJS" | ||
| "module": "CommonJS", | ||
| "moduleResolution": "node" | ||
| } |
There was a problem hiding this comment.
moduleResolution: "node" is likely to break compilation now that this package's TS source uses .js extensions in relative imports (e.g. packages/test-utils/src/index.ts:1-2). Consider switching this CJS build to moduleResolution: "Bundler" (or "NodeNext"/"Node16") to allow resolving .js specifiers to .ts sources during tsc --build.
| { | ||
| "name": "@nucypher/taco", | ||
| "version": "0.7.0-alpha.12", | ||
| "version": "0.7.0-dev.es", |
There was a problem hiding this comment.
Reminder: these *-dev.es tags need to revert to proper semver before this lands.
There was a problem hiding this comment.
💯 - yep. Just temporary for now. I would like to produce a -dev.es tagged build for the people asking for the change to test out before committing it to 0.7.
…consumer script in CI.
BEFORE MERGING: update package version
Type of PR:
Required reviews:
What this does:
Reopened from #778
Issues fixed/closed:
Why it's needed:
Notes for reviewers: