Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: build kits with cjs and esm targets #1049

Draft
wants to merge 21 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@types/node": "^20.14.5",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"esbuild": "^0.24.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
Expand All @@ -35,7 +36,7 @@
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.8",
"typescript": "^5.3.3"
"typescript": "^5.6.3"
},
"lint-staged": {
"./packages/**/*.{js,jsx,ts,tsx}": [
Expand Down
15 changes: 12 additions & 3 deletions packages/api-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
"name": "@safe-global/api-kit",
"version": "2.5.6",
"description": "SDK that facilitates the interaction with the Safe Transaction Service API",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"types": "dist/src/index.d.ts",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"exports": {
"types": "./dist/src/index.d.ts",
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.mjs"
},
"keywords": [
"Ethereum",
"Wallet",
Expand All @@ -23,7 +29,10 @@
"format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"",
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
"unbuild": "rimraf dist .nyc_output cache",
"build": "yarn unbuild && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
"build": "yarn unbuild && yarn build:esm && yarn build:cjs && yarn build:types",
"build:esm": "esbuild ./src/index --format=esm --bundle --packages=external --outdir=dist/esm --out-extension:.js=.mjs",
"build:cjs": "esbuild ./src/index --format=cjs --bundle --packages=external --outdir=dist/cjs --out-extension:.js=.cjs",
"build:types": "NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
},
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions packages/api-kit/tests/e2e/addSafeOperation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import Safe from '@safe-global/protocol-kit'
import SafeApiKit from '@safe-global/api-kit/index'
import { getAddSafeOperationProps } from '@safe-global/api-kit/utils/safeOperation'
import { BundlerClient, Safe4337Pack } from '@safe-global/relay-kit'
import { generateTransferCallData } from '@safe-global/relay-kit/packs/safe-4337/testing-utils/helpers'
// @ts-expect-error crazy hack to get test working
import * as utils from '@safe-global/relay-kit/dist/cjs/src/packs/safe-4337/utils'
import {
generateTransferCallData,
ENTRYPOINT_ABI,
ENTRYPOINT_ADDRESS_V06,
RPC_4337_CALLS
} from '@safe-global/relay-kit/packs/safe-4337/constants'
// Needs to be imported from dist folder in order to mock the getEip4337BundlerProvider function
import * as safe4337Utils from '@safe-global/relay-kit/dist/src/packs/safe-4337/utils'
} from '@safe-global/relay-kit/test-utils'
import { getKits } from '../utils/setupKits'

chai.use(chaiAsPromised)
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('addSafeOperation', () => {
const requestStub = sinon.stub()
// Setup mocks for the bundler client
before(async () => {
sinon.stub(safe4337Utils, 'getEip4337BundlerProvider').returns({
sinon.stub(utils, 'getEip4337BundlerProvider').returns({
request: requestStub,
readContract: sinon
.stub()
Expand Down
16 changes: 8 additions & 8 deletions packages/api-kit/tests/e2e/confirmSafeOperation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import chaiAsPromised from 'chai-as-promised'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
import { BundlerClient, Safe4337InitOptions, Safe4337Pack } from '@safe-global/relay-kit'
import { generateTransferCallData } from '@safe-global/relay-kit/packs/safe-4337/testing-utils/helpers'
import {
generateTransferCallData,
ENTRYPOINT_ADDRESS_V06,
RPC_4337_CALLS
} from '@safe-global/relay-kit/test-utils'
// @ts-expect-error crazy hack to get test working
import * as utils from '@safe-global/relay-kit/dist/cjs/src/packs/safe-4337/utils'
import SafeApiKit from '@safe-global/api-kit/index'
import { getAddSafeOperationProps } from '@safe-global/api-kit/utils/safeOperation'
import { SafeOperation } from '@safe-global/types-kit'
// Needs to be imported from dist folder in order to mock the getEip4337BundlerProvider function
import * as safe4337Utils from '@safe-global/relay-kit/dist/src/packs/safe-4337/utils'
import { getApiKit, getEip1193Provider } from '../utils/setupKits'
import {
ENTRYPOINT_ADDRESS_V06,
RPC_4337_CALLS
} from '@safe-global/relay-kit/packs/safe-4337/constants'

chai.use(chaiAsPromised)
chai.use(sinonChai)
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('confirmSafeOperation', () => {
const requestStub = sinon.stub()

before(async () => {
sinon.stub(safe4337Utils, 'getEip4337BundlerProvider').returns({
sinon.stub(utils, 'getEip4337BundlerProvider').returns({
request: requestStub
} as unknown as BundlerClient)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chai from 'chai'
import SafeApiKit from '@safe-global/api-kit/index'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import { getApiKit } from '../utils/setupKits'

let safeApiKit: SafeApiKit
Expand Down
11 changes: 7 additions & 4 deletions packages/api-kit/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"extends": "../../tsconfig.settings.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true,
"outDir": "dist"
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"outDir": "dist/src"
},
"include": ["src/**/*"]
"include": ["src/**/*"],
"exclude": ["dist", "test"]
}
9 changes: 6 additions & 3 deletions packages/api-kit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"composite": true,
"outDir": "dist"
"baseUrl": "./",
"paths": {
"@safe-global/api-kit/*": ["./src/*"]
}
},
"include": ["src/**/*", "tests/**/*"]
"include": ["src/**/*", "tests/**/*"],
"exclude": ["dist"]
}
20 changes: 18 additions & 2 deletions packages/protocol-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
"name": "@safe-global/protocol-kit",
"version": "5.1.1",
"description": "SDK that facilitates the interaction with Safe Smart Accounts",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"main": "dist/cjs/src/index.cjs",
"module": "dist/esm/src/index.mjs",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"require": "./dist/cjs/src/index.cjs",
"import": "./dist/esm/src/index.mjs"
},
"./test-utils": {
"types": "./dist/test-utils/index.d.ts",
"require": "./dist/cjs/test-utils/index.cjs",
"import": "./dist/esm/test-utils/index.mjs"
}
},
"keywords": [
"Ethereum",
"Wallet",
Expand Down Expand Up @@ -36,7 +49,10 @@
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
"unbuild": "rimraf dist artifacts deployments cache .nyc_output *.tsbuildinfo",
"prebuild": "node -p \"'export const getProtocolKitVersion = () => \\'' + require('./package.json').version.split('-')[0] + '\\''\" > src/utils/getProtocolKitVersion.ts",
"build": "yarn unbuild && yarn check-safe-deployments && NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
"build": "yarn unbuild && yarn check-safe-deployments && yarn build:esm && yarn build:cjs && yarn build:types",
"build:esm": "esbuild ./src/index ./test-utils/index --format=esm --bundle --packages=external --outdir=dist/esm --out-extension:.js=.mjs",
"build:cjs": "esbuild ./src/index ./test-utils/index --format=cjs --bundle --packages=external --outdir=dist/cjs --out-extension:.js=.cjs",
"build:types": "NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import {
getSafeContract
} from './contracts/safeDeploymentContracts'
import SafeMessage from './utils/messages/SafeMessage'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import SafeProvider from './SafeProvider'
import { asHash, asHex } from './utils/types'
import { Hash, Hex, SendTransactionParameters } from 'viem'
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/contracts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
TransactionOptions,
TransactionResult
} from '@safe-global/types-kit'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import { asHex } from '../utils/types'
import {
GetContractInstanceProps,
Expand Down Expand Up @@ -504,7 +504,7 @@
}
}

export function isTypedDataSigner(signer: any): signer is Client {

Check warning on line 507 in packages/protocol-kit/src/contracts/utils.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
const isPasskeySigner = !!signer?.passkeyRawId
return (signer as unknown as WalletClient).signTypedData !== undefined || !isPasskeySigner
}
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/utils/eip-712/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
EIP712TypedDataMessage,
EIP712TypedDataTx
} from '@safe-global/types-kit'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import { hashTypedData as hashTypedStructuredData } from './encode'

const EQ_OR_GT_1_3_0 = '>=1.3.0'
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/utils/safeVersions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import { SafeContractImplementationType } from '@safe-global/protocol-kit/types'
import SafeContract_v1_0_0 from '@safe-global/protocol-kit/contracts/Safe/v1.0.0/SafeContract_v1_0_0'
import SafeContract_v1_1_1 from '@safe-global/protocol-kit/contracts/Safe/v1.1.1/SafeContract_v1_1_1'
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/utils/signatures/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { recoverAddress } from 'viem'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { SafeSignature, SafeEIP712Args, SafeTransactionData } from '@safe-global/types-kit'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import { sameString } from '../address'
import { EthSafeSignature } from './SafeSignature'
import { getEip712MessageTypes, getEip712TxTypes } from '../eip-712'
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/utils/transactions/gas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseError, CallExecutionErrorType, RawContractErrorType } from 'viem'
import { OperationType, SafeVersion, SafeTransaction } from '@safe-global/types-kit'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import Safe from '@safe-global/protocol-kit/Safe'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/src/utils/transactions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
TransactionOptions,
Transaction
} from '@safe-global/types-kit'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import { estimateGas, estimateTxGas } from './gas'
import {
Hash,
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol-kit/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './passkeys'
export * from './webauthnShim'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PasskeyArgType, PasskeyClient } from '@safe-global/protocol-kit'
import { PasskeyArgType, PasskeyClient } from '../src'
import { WebAuthnCredentials } from './webauthnShim'
import { WalletClient, keccak256, toBytes, Transport, Chain, Account } from 'viem'
import { asHex } from '@safe-global/protocol-kit/utils/types'
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/tests/e2e/eip1271.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { getEip1193Provider } from './utils/setupProvider'
import { waitSafeTxReceipt } from './utils/transactions'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'
import { asHash } from '@safe-global/protocol-kit/utils/types'

chai.use(chaiAsPromised)
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/tests/e2e/moduleManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { getEip1193Provider } from './utils/setupProvider'
import { waitSafeTxReceipt } from './utils/transactions'
import semverSatisfies from 'semver/functions/satisfies'
import semverSatisfies from 'semver/functions/satisfies.js'

chai.use(chaiAsPromised)

Expand Down
6 changes: 5 additions & 1 deletion packages/protocol-kit/tests/e2e/passkey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import {
} from '@safe-global/protocol-kit/contracts/safeDeploymentContracts'
import { getEip1193Provider } from './utils/setupProvider'
import { waitSafeTxReceipt } from './utils/transactions'
import { createMockPasskey, getWebAuthnCredentials, deployPasskeysContract } from './utils/passkeys'
import {
createMockPasskey,
getWebAuthnCredentials,
deployPasskeysContract
} from '@safe-global/protocol-kit/test-utils'

chai.use(chaiAsPromised)
chai.use(sinonChai)
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol-kit/tests/e2e/safeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getEip1193Provider } from './utils/setupProvider'
import { SafeProvider } from '@safe-global/protocol-kit/index'
import sinon from 'sinon'
import sinonChai from 'sinon-chai'
import { createMockPasskey, getWebAuthnCredentials } from './utils/passkeys'
import { createMockPasskey, getWebAuthnCredentials } from '@safe-global/protocol-kit/test-utils'
import { publicActions, walletActions } from 'viem'

chai.use(chaiAsPromised)
Expand Down
8 changes: 6 additions & 2 deletions packages/protocol-kit/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"extends": "../../tsconfig.settings.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"composite": true,
"outDir": "dist"
},
"include": ["src/**/*"]
"include": ["src/**/*", "test-utils/**/*"],
"exclude": ["dist", "test"]
}
7 changes: 6 additions & 1 deletion packages/protocol-kit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@safe-global/protocol-kit/*": ["./src/*"]
},
"composite": true,
"outDir": "dist"
},
"include": ["src/**/*", "tests/**/*", "hardhat/**/*", "hardhat.config.ts"]
"include": ["src/**/*", "tests/**/*", "hardhat/**/*", "hardhat.config.ts"],
"exclude": ["dist"]
}
2 changes: 1 addition & 1 deletion packages/relay-kit/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config = {
},
moduleNameMapper: {
'^@safe-global/protocol-kit/tests/(.*)$': '<rootDir>/../protocol-kit/tests/$1',
'^@safe-global/protocol-kit/(.*)$': '<rootDir>/../protocol-kit/src/$1',
'^@safe-global/relay-kit/test-utils$': '<rootDir>/test-utils',
'^@safe-global/relay-kit/(.*)$': '<rootDir>/src/$1'
},
testTimeout: 20000
Expand Down
27 changes: 24 additions & 3 deletions packages/relay-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,26 @@
"name": "@safe-global/relay-kit",
"version": "3.3.1",
"description": "SDK for Safe Smart Accounts with support for ERC-4337 and Relay",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"types": "dist/src/index.d.ts",
"main": "dist/cjs/src/index.js",
"module": "dist/esm/src/index.js",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"require": "./dist/cjs/src/index.js",
"import": "./dist/esm/src/index.js"
},
"./test-utils": {
"types": "./dist/test-utils/index.d.ts",
"require": "./dist/cjs/test-utils/index.js",
"import": "./dist/esm/test-utils/index.js"
},
"./dist/cjs/src/packs/safe-4337/utils": {
"types": "./dist/src/packs/safe-4337/utils.d.ts",
"require": "./dist/cjs/src/packs/safe-4337/utils.js",
"import": "./dist/esm/src/packs/safe-4337/utils.js"
}
},
"keywords": [
"Ethereum",
"Wallet",
Expand All @@ -20,7 +38,10 @@
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
"unbuild": "rimraf dist .nyc_output cache",
"prebuild": "node -p \"'export const getRelayKitVersion = () => \\'' + require('./package.json').version.split('-')[0] + '\\''\" > src/packs/safe-4337/utils/getRelayKitVersion.ts",
"build": "yarn unbuild && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json"
"build": "yarn unbuild && yarn build:esm && yarn build:cjs && yarn build:types",
"build:esm": "tsc -p tsconfig.build.json --module esnext --outDir dist/esm && tsc-alias -p tsconfig.build.json --outDir dist/esm",
"build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs && tsc-alias -p tsconfig.build.json --outDir dist/cjs",
"build:types": "NODE_OPTIONS=--max-old-space-size=8192 tsc -p tsconfig.build.json --declaration --declarationMap --emitDeclarationOnly && tsc-alias -p tsconfig.build.json"
},
"repository": {
"type": "git",
Expand Down
10 changes: 6 additions & 4 deletions packages/relay-kit/src/packs/safe-4337/Safe4337Pack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import crypto from 'crypto'
import dotenv from 'dotenv'
import * as viem from 'viem'
import Safe, * as protocolKit from '@safe-global/protocol-kit'
import { WebAuthnCredentials } from '@safe-global/protocol-kit/tests/e2e/utils/webauthnShim'
import { createMockPasskey } from '@safe-global/protocol-kit/tests/e2e/utils/passkeys'
import { WebAuthnCredentials, createMockPasskey } from '@safe-global/protocol-kit/test-utils'
import {
getAddModulesLibDeployment,
getSafe4337ModuleDeployment
Expand All @@ -12,9 +11,12 @@ import { MetaTransactionData, OperationType } from '@safe-global/types-kit'
import { Safe4337Pack } from './Safe4337Pack'
import EthSafeOperation from './SafeOperation'
import * as constants from './constants'
import * as fixtures from './testing-utils/fixtures'
import { createSafe4337Pack, generateTransferCallData } from './testing-utils/helpers'
import * as utils from './utils'
import {
fixtures,
createSafe4337Pack,
generateTransferCallData
} from '@safe-global/relay-kit/test-utils'

dotenv.config()

Expand Down
Loading
Loading