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 18 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.4",
"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
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.0.4",
"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 @@ -35,7 +48,10 @@
"format:check": "prettier --check \"*/**/*.{js,json,md,ts}\"",
"format": "prettier --write \"*/**/*.{js,json,md,ts}\"",
"unbuild": "rimraf dist artifacts deployments cache .nyc_output *.tsbuildinfo",
"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: 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,7 +1,7 @@
import { PasskeyArgType, PasskeyClient, extractPasskeyCoordinates } from '@safe-global/protocol-kit'
import { PasskeyArgType, PasskeyClient, extractPasskeyCoordinates } from '../src'
import { asHex } from '../src/utils/types'
import { WebAuthnCredentials } from './webauthnShim'
import { WalletClient, keccak256, toBytes, Transport, Chain, Account } from 'viem'
import { asHex } from '@safe-global/protocol-kit/utils/types'

let singleInstance: WebAuthnCredentials

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
9 changes: 6 additions & 3 deletions packages/protocol-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,
"declaration": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"outDir": "dist"
},
"include": ["src/**/*"]
"include": ["src/**/*", "test-utils/**/*"],
"exclude": ["dist", "test"]
}
9 changes: 6 additions & 3 deletions packages/protocol-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/protocol-kit/*": ["./src/*"]
}
},
"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.2.4",
"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 @@ -19,7 +37,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": "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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hex, encodePacked } from 'viem'
import { EthSafeSignature } from '@safe-global/protocol-kit'
import EthSafeOperation from './SafeOperation'
import * as fixtures from './testing-utils/fixtures'
import { fixtures } from '@safe-global/relay-kit/test-utils'

describe('SafeOperation', () => {
it('should create a SafeOperation from an UserOperation', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PimlicoFeeEstimator } from './PimlicoFeeEstimator'
import * as fixtures from '../testing-utils/fixtures'
import { fixtures } from '@safe-global/relay-kit/test-utils'
import * as constants from '../constants'

jest.mock('../utils', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ENTRYPOINT_ADDRESS_V06, ENTRYPOINT_ADDRESS_V07 } from '../constants'
import { ENTRYPOINT_ADDRESS_V06, ENTRYPOINT_ADDRESS_V07 } from '../src/packs/safe-4337/constants'

export const OWNER_1 = '0xFfAC5578BE8AC1B2B9D13b34cAf4A074B96B8A1b'
export const OWNER_2 = '0x3059EfD1BCe33be41eeEfd5fb6D520d7fEd54E43'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { encodeFunctionData, parseAbi } from 'viem'
import { Safe4337InitOptions } from '../types'
import { Safe4337Pack } from '../Safe4337Pack'
import { Safe4337InitOptions } from '../src/packs/safe-4337/types'
import { Safe4337Pack } from '../src/packs/safe-4337/Safe4337Pack'
import * as fixtures from './fixtures'

export const generateTransferCallData = (to: string, value: bigint) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/relay-kit/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * as fixtures from './fixtures'
export * from './helpers'
export {
ENTRYPOINT_ABI,
ENTRYPOINT_ADDRESS_V06,
RPC_4337_CALLS
} from '../src/packs/safe-4337/constants'
7 changes: 3 additions & 4 deletions packages/relay-kit/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../../tsconfig.settings.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true,
"outDir": "dist"
},
"include": ["src/**/*"],
"exclude": ["src/**/*.test.ts", "src/**/*.test-d.ts"]
"include": ["src/**/*", "test-utils/**/*"],
"exclude": ["dist", "src/**/*.test.ts", "src/**/*.test-d.ts"]
}
9 changes: 6 additions & 3 deletions packages/relay-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/relay-kit/*": ["./src/*"]
}
},
"include": ["src/**/*"]
"include": ["src/**/*"],
"exclude": ["dist"]
}
Loading
Loading