Skip to content

Commit

Permalink
fix: project module resolution (#1428)
Browse files Browse the repository at this point in the history
* feat: fix nodenext module resolution; jest → vitest; remove barrel files

* fix

* chore: tweaks

* fix

* lint

* fix imports

* fix lint

---------

Co-authored-by: jxom <jakemoxey@gmail.com>
Co-authored-by: jxom <j@wevm.dev>
  • Loading branch information
3 people authored Oct 17, 2024
1 parent 8386209 commit bb531e3
Show file tree
Hide file tree
Showing 88 changed files with 2,826 additions and 4,258 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: yarn install --immutable

- name: Runs compile asset script
run: node ./compile-assets.js
run: node ./compile-assets.cjs

- name: Check Types
run: yarn typecheck
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
run: yarn install --immutable

- name: Runs compile asset script
run: node ./compile-assets.js
run: node ./compile-assets.cjs

- name: Run Unit Tests
run: yarn test
Expand Down
2 changes: 1 addition & 1 deletion examples/testapp/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
root: true,
extends: [
'preact',
'eslint:recommended',
Expand Down Expand Up @@ -68,6 +67,7 @@ module.exports = {
// TODO: change this back to error
'@typescript-eslint/no-explicit-any': 'warn',
'no-useless-constructor': 'off',
'jest/no-deprecated-functions': 'off',
'no-restricted-globals': [
'error',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = {
// TODO: change this back to error
'@typescript-eslint/no-explicit-any': 'warn',
'no-useless-constructor': 'off',
'jest/no-deprecated-functions': 'off',
'no-restricted-globals': [
'error',
{
Expand Down
9 changes: 4 additions & 5 deletions packages/wallet-sdk/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ tsconfig.build.json
.eslintignore
.eslintrc.js
.prettierignore
babel.config.js
release.sh

# Jest
jest.setup.ts
jest.config.ts
# Vitest
vitest.setup.ts
vitest.config.ts
coverage/**

compile-assets.js
compile-assets.cjs
22 changes: 0 additions & 22 deletions packages/wallet-sdk/babel.config.js

This file was deleted.

File renamed without changes.
62 changes: 0 additions & 62 deletions packages/wallet-sdk/jest.config.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/wallet-sdk/jest.setup.ts

This file was deleted.

39 changes: 20 additions & 19 deletions packages/wallet-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,60 @@
"walletlink",
"web3"
],
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"sideEffects": false,
"repository": "https://github.com/coinbase/coinbase-wallet-sdk.git",
"author": "Coinbase, Inc.",
"license": "Apache-2.0",
"scripts": {
"pretest": "node compile-assets.js",
"test": "jest",
"pretest": "node compile-assets.cjs",
"test": "vitest",
"test:coverage": "yarn test:unit && open coverage/lcov-report/index.html",
"prebuild": "rm -rf ./dist && node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';\\nexport const NAME = \\'' + require('./package.json').name + '\\';'\" > src/sdk-info.ts",
"build": "node compile-assets.js && tsc -p ./tsconfig.build.json && tsc-alias && cp -a src/vendor-js dist",
"build": "node compile-assets.cjs && tsc -p ./tsconfig.build.json && tsc-alias && cp -a src/vendor-js dist",
"dev": "yarn build && tsc --watch & nodemon --watch dist --delay 1 --exec tsc-alias",
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext .ts,.tsx --fix"
"lint": "eslint . --ext .ts,.tsx --fix",
"size": "size-limit"
},
"dependencies": {
"@noble/hashes": "^1.4.0",
"clsx": "^1.2.1",
"eventemitter3": "^5.0.1",
"preact": "^10.16.0"
"preact": "^10.24.2",
"vitest": "^2.1.2"
},
"devDependencies": {
"@babel/core": "^7.22.9",
"@babel/plugin-proposal-decorators": "^7.22.7",
"@babel/plugin-transform-react-jsx": "^7.22.5",
"@babel/preset-env": "^7.22.9",
"@babel/preset-typescript": "^7.22.5",
"@peculiar/webcrypto": "^1.4.3",
"@size-limit/preset-big-lib": "^11.1.6",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/preact": "^2.0.1",
"@types/jest": "^27.5.2",
"@testing-library/preact": "^3.2.4",
"@types/node": "^14.18.54",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"babel-jest": "^27.5.1",
"eslint": "^8.45.0",
"eslint-config-preact": "^1.3.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"glob": "^11.0.0",
"jest": "^27.5.1",
"jest-chrome": "^0.7.2",
"jest-websocket-mock": "^2.4.0",
"jsdom": "^25.0.1",
"nodemon": "^3.1.0",
"prettier": "^3.0.0",
"sass": "^1.64.1",
"ts-jest": "^27.1.5",
"ts-node": "^10.9.1",
"size-limit": "^11.1.6",
"tsc-alias": "^1.8.8",
"tslib": "^2.6.0",
"typescript": "^5.1.6"
}
},
"size-limit": [
{
"path": "./dist/index.js",
"limit": "31 KB",
"import": "*"
}
]
}
35 changes: 18 additions & 17 deletions packages/wallet-sdk/src/CoinbaseWalletProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CoinbaseWalletProvider } from './CoinbaseWalletProvider';
import { standardErrorCodes, standardErrors } from './core/error';
import * as util from './sign/util';
import { ProviderEventCallback, RequestArguments } from ':core/provider/interface';
import { AddressString } from ':core/type';
import { CoinbaseWalletProvider } from './CoinbaseWalletProvider.js';
import * as util from './sign/util.js';
import { standardErrorCodes } from ':core/error/constants.js';
import { standardErrors } from ':core/error/errors.js';
import { ProviderEventCallback, RequestArguments } from ':core/provider/interface.js';
import { AddressString } from ':core/type/index.js';

function createProvider() {
return new CoinbaseWalletProvider({
Expand All @@ -11,19 +12,19 @@ function createProvider() {
});
}

const mockHandshake = jest.fn();
const mockRequest = jest.fn();
const mockCleanup = jest.fn();
const mockFetchSignerType = jest.spyOn(util, 'fetchSignerType');
const mockStoreSignerType = jest.spyOn(util, 'storeSignerType');
const mockLoadSignerType = jest.spyOn(util, 'loadSignerType');
const mockHandshake = vi.fn();
const mockRequest = vi.fn();
const mockCleanup = vi.fn();
const mockFetchSignerType = vi.spyOn(util, 'fetchSignerType');
const mockStoreSignerType = vi.spyOn(util, 'storeSignerType');
const mockLoadSignerType = vi.spyOn(util, 'loadSignerType');

let provider: CoinbaseWalletProvider;
let callback: ProviderEventCallback;

beforeEach(() => {
jest.resetAllMocks();
jest.spyOn(util, 'createSigner').mockImplementation((params) => {
vi.resetAllMocks();
vi.spyOn(util, 'createSigner').mockImplementation((params) => {
callback = params.callback;
return {
accounts: [AddressString('0x123')],
Expand All @@ -39,7 +40,7 @@ beforeEach(() => {

describe('Event handling', () => {
it('emits disconnect event on user initiated disconnection', async () => {
const disconnectListener = jest.fn();
const disconnectListener = vi.fn();
provider.on('disconnect', disconnectListener);

await provider.disconnect();
Expand All @@ -50,7 +51,7 @@ describe('Event handling', () => {
});

it('should emit chainChanged event on chainId change', async () => {
const chainChangedListener = jest.fn();
const chainChangedListener = vi.fn();
provider.on('chainChanged', chainChangedListener);

await provider.request({ method: 'eth_requestAccounts' });
Expand All @@ -60,7 +61,7 @@ describe('Event handling', () => {
});

it('should emit accountsChanged event on account change', async () => {
const accountsChangedListener = jest.fn();
const accountsChangedListener = vi.fn();
provider.on('accountsChanged', accountsChangedListener);

await provider.request({ method: 'eth_requestAccounts' });
Expand Down Expand Up @@ -106,7 +107,7 @@ describe('Signer configuration', () => {

it('should support enable', async () => {
mockFetchSignerType.mockResolvedValue('scw');
jest.spyOn(console, 'warn').mockImplementation();
vi.spyOn(console, 'warn').mockImplementation(() => {});

await provider.enable();
expect(mockHandshake).toHaveBeenCalledWith({ method: 'eth_requestAccounts' });
Expand Down
21 changes: 11 additions & 10 deletions packages/wallet-sdk/src/CoinbaseWalletProvider.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { standardErrorCodes, standardErrors } from './core/error';
import { serializeError } from './core/error/serialize';
import { Signer } from './sign/interface.js';
import { createSigner, fetchSignerType, loadSignerType, storeSignerType } from './sign/util.js';
import { Communicator } from ':core/communicator/Communicator.js';
import { standardErrorCodes } from ':core/error/constants.js';
import { standardErrors } from ':core/error/errors.js';
import { serializeError } from ':core/error/serialize.js';
import { SignerType } from ':core/message/ConfigMessage.js';
import {
AppMetadata,
ConstructorOptions,
Preference,
ProviderEventEmitter,
ProviderInterface,
RequestArguments,
} from './core/provider/interface';
import { Signer } from './sign/interface';
import { createSigner, fetchSignerType, loadSignerType, storeSignerType } from './sign/util';
import { checkErrorForInvalidRequestArgs } from './util/provider';
import { Communicator } from ':core/communicator/Communicator';
import { SignerType } from ':core/message';
import { ScopedLocalStorage } from ':core/storage/ScopedLocalStorage';
import { hexStringFromNumber } from ':core/type/util';
} from ':core/provider/interface.js';
import { ScopedLocalStorage } from ':core/storage/ScopedLocalStorage.js';
import { hexStringFromNumber } from ':core/type/util.js';
import { checkErrorForInvalidRequestArgs } from ':util/provider.js';

export class CoinbaseWalletProvider extends ProviderEventEmitter implements ProviderInterface {
private readonly metadata: AppMetadata;
Expand Down
28 changes: 15 additions & 13 deletions packages/wallet-sdk/src/CoinbaseWalletSDK.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { CoinbaseWalletProvider } from './CoinbaseWalletProvider';
import { CoinbaseWalletSDK } from './CoinbaseWalletSDK';
import { ProviderInterface } from ':core/provider/interface';
import { getFavicon } from ':core/type/util';
import { getCoinbaseInjectedProvider } from ':util/provider';
import { Mock } from 'vitest';

jest.mock(':core/type/util');
jest.mock(':util/provider');
jest.mock('./CoinbaseWalletProvider');
jest.mock('./util/checkCrossOriginOpenerPolicy');
import { CoinbaseWalletProvider } from './CoinbaseWalletProvider.js';
import { CoinbaseWalletSDK } from './CoinbaseWalletSDK.js';
import { ProviderInterface } from ':core/provider/interface.js';
import { getFavicon } from ':core/type/util.js';
import { getCoinbaseInjectedProvider } from ':util/provider.js';

vi.mock(':core/type/util');
vi.mock(':util/provider');
vi.mock('./CoinbaseWalletProvider');
vi.mock('./util/checkCrossOriginOpenerPolicy');

describe('CoinbaseWalletSDK', () => {
test('@makeWeb3Provider - return Coinbase Injected Provider', () => {
const injectedProvider = {} as unknown as ProviderInterface;
(getCoinbaseInjectedProvider as jest.Mock).mockReturnValue(injectedProvider);
(getCoinbaseInjectedProvider as Mock).mockReturnValue(injectedProvider);

const SDK = new CoinbaseWalletSDK({
appName: 'Test',
Expand All @@ -23,7 +25,7 @@ describe('CoinbaseWalletSDK', () => {
});

test('@makeWeb3Provider - return new CoinbaseWalletProvider', () => {
(getCoinbaseInjectedProvider as jest.Mock).mockReturnValue(undefined);
(getCoinbaseInjectedProvider as Mock).mockReturnValue(undefined);

const SDK = new CoinbaseWalletSDK({
appName: 'Test',
Expand All @@ -45,8 +47,8 @@ describe('CoinbaseWalletSDK', () => {
});

test('@makeWeb3Provider - default values for metadata', () => {
(getFavicon as jest.Mock).mockReturnValue('https://dapp.xyz/pic.png');
(getCoinbaseInjectedProvider as jest.Mock).mockReturnValue(undefined);
(getFavicon as Mock).mockReturnValue('https://dapp.xyz/pic.png');
(getCoinbaseInjectedProvider as Mock).mockReturnValue(undefined);

const SDK = new CoinbaseWalletSDK({
appName: '',
Expand Down
Loading

0 comments on commit bb531e3

Please sign in to comment.