From 2d95df28a4a76e235e65bc807d0c8c5dfddc1a3b Mon Sep 17 00:00:00 2001 From: AbigailDeng Date: Tue, 22 Oct 2024 16:11:56 +0800 Subject: [PATCH] feat: esm --- build/webpack.esModule.js | 7 +- jest-report.xml | 450 +++++++++--------- ...owser.config.js => jest.browser.config.cjs | 0 jest.node.config.js => jest.node.config.cjs | 0 package.json | 15 +- src/util/httpProvider.js | 9 +- src/util/keccak.js | 2 +- types/wallet/index.d.ts | 12 +- yarn.lock | 5 + 9 files changed, 252 insertions(+), 248 deletions(-) rename jest.browser.config.js => jest.browser.config.cjs (100%) rename jest.node.config.js => jest.node.config.cjs (100%) diff --git a/build/webpack.esModule.js b/build/webpack.esModule.js index 18cd8b02..1c342595 100644 --- a/build/webpack.esModule.js +++ b/build/webpack.esModule.js @@ -22,7 +22,12 @@ const nodeConfig = { alias: {}, fallback: { crypto: 'crypto-browserify', - stream: 'stream-browserify' + stream: 'stream-browserify', + https: false, + http: false, + child_process: false, + fs: false, + url: false } } }; diff --git a/jest-report.xml b/jest-report.xml index ea7aa9af..8e793cdb 100644 --- a/jest-report.xml +++ b/jest-report.xml @@ -1,25 +1,25 @@ - - - + + + - + - + - + - + - + - + @@ -27,39 +27,39 @@ - + - + - + - + - - + + - + - + - + - + - + - + - + @@ -71,27 +71,27 @@ - + - + - + - + - + - + - + @@ -101,425 +101,425 @@ - + - - + + - + - + + + + + + + + + + + + + + + + + - + + + + + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - - - - - - - - + + - + - - - - - + - + - + - + - + - + - - - - + + - + - - - + - + - - - + - + - + - + + + - + - + + + - + - - + + - + - - - - - - - + - - + + - - + + - - + + - + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + \ No newline at end of file diff --git a/jest.browser.config.js b/jest.browser.config.cjs similarity index 100% rename from jest.browser.config.js rename to jest.browser.config.cjs diff --git a/jest.node.config.js b/jest.node.config.cjs similarity index 100% rename from jest.node.config.js rename to jest.node.config.cjs diff --git a/package.json b/package.json index e42f1a14..bea46c92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aelf-sdk", - "version": "3.4.17-alpha.0", + "version": "3.4.17-alpha.1", "description": "aelf-sdk js library", "type": "module", "main": "dist/aelf.cjs.js", @@ -28,12 +28,12 @@ "release": "standard-version -a", "pre-commit": "lint-staged", "test": "yarn test:browser && yarn test:node", - "test:browser": "jest --config=jest.browser.config.js", - "test:browser:watch": "jest --config=jest.browser.config.js --watch", - "test:node": "jest --config=jest.node.config.js", - "test:node:watch": "jest --config=jest.node.config.js --watch", - "test:coverage": "jest --config=jest.browser.config.js --coverage", - "test:coverageNode": "jest --config=jest.node.config.js --coverage", + "test:browser": "jest --config=jest.browser.config.cjs", + "test:browser:watch": "jest --config=jest.browser.config.cjs --watch", + "test:node": "jest --config=jest.node.config.cjs", + "test:node:watch": "jest --config=jest.node.config.cjs --watch", + "test:coverage": "jest --config=jest.browser.config.cjs --coverage", + "test:coverageNode": "jest --config=jest.node.config.cjs --coverage", "prepare": "husky install", "copy-ts": "cpx \"types/**/*.ts\" dist/" }, @@ -87,6 +87,7 @@ "scryptsy": "^2.1.0", "stream-browserify": "^3.0.0", "typescript": "^5.0.4", + "xhr2": "^0.2.1", "xmlhttprequest": "^1.8.0" }, "lint-staged": { diff --git a/src/util/httpProvider.js b/src/util/httpProvider.js index 0b539560..16762716 100644 --- a/src/util/httpProvider.js +++ b/src/util/httpProvider.js @@ -3,6 +3,8 @@ * @author atom-yang */ import { stringify } from 'query-string'; +import NodeFetch, { Headers } from 'node-fetch'; +import { XMLHttpRequest as XHR } from 'xmlhttprequest'; const defaultHeaders = { Accept: 'text/plain;v=1.0', @@ -28,11 +30,8 @@ if (process.env.RUNTIME_ENV === 'browser') { } } else { // For node use xmlhttprequest - // eslint-disable-next-line global-require - RequestLibraryXMLOnly = require('xmlhttprequest').XMLHttpRequest; - // eslint-disable-next-line global-require - const NodeFetch = require('node-fetch'); - RequestLibrary = NodeFetch.default; + RequestLibraryXMLOnly = XHR; + RequestLibrary = NodeFetch; NodeHeaders = NodeFetch.Headers; isFetch = true; } diff --git a/src/util/keccak.js b/src/util/keccak.js index bd6ec839..f10dcdbb 100644 --- a/src/util/keccak.js +++ b/src/util/keccak.js @@ -1,4 +1,4 @@ -const createKeccakHash = require('keccak'); +import createKeccakHash from 'keccak'; const keccak = bits => str => { let msg; diff --git a/types/wallet/index.d.ts b/types/wallet/index.d.ts index 55620ceb..e98a7aee 100644 --- a/types/wallet/index.d.ts +++ b/types/wallet/index.d.ts @@ -1,4 +1,4 @@ -import HDNode = require('hdkey'); +import HDNode from 'hdkey'; import * as Bip39 from 'bip39'; import { ec, curve } from 'elliptic'; import { TRawTransaction, TAddress } from '../util/proto'; @@ -34,10 +34,7 @@ interface IWallet { createNewWallet(BIP44Path?: BIP44Path): IWalletInfo; getWalletByMnemonic(mnemonic: Mnemonic, BIP44Path: BIP44Path): IWalletInfo; getWalletByPrivateKey(privateKey: PrivateKey): IWalletInfo; - signTransaction( - rawTxn: TRawTransaction, - keyPair: ec.KeyPair - ): SignTransaction; + signTransaction(rawTxn: TRawTransaction, keyPair: ec.KeyPair): SignTransaction; sign(hexString: string, keyPair: ec.KeyPair): Buffer; } export declare class Wallet implements IWallet { @@ -52,10 +49,7 @@ export declare class Wallet implements IWallet { createNewWallet(BIP44Path?: BIP44Path): IWalletInfo; getWalletByMnemonic(mnemonic: Mnemonic, BIP44Path: BIP44Path): IWalletInfo; getWalletByPrivateKey(privateKey: PrivateKey): IWalletInfo; - signTransaction( - rawTxn: TRawTransaction, - keyPair: ec.KeyPair - ): SignTransaction; + signTransaction(rawTxn: TRawTransaction, keyPair: ec.KeyPair): SignTransaction; sign(hexString: string, keyPair: ec.KeyPair): Buffer; } export default Wallet; diff --git a/yarn.lock b/yarn.lock index c429ea8e..b0e795e5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10350,6 +10350,11 @@ ws@^8.11.0: resolved "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b" integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ== +xhr2@^0.2.1: + version "0.2.1" + resolved "https://registry.npmjs.org/xhr2/-/xhr2-0.2.1.tgz#4e73adc4f9cfec9cbd2157f73efdce3a5f108a93" + integrity sha512-sID0rrVCqkVNUn8t6xuv9+6FViXjUVXq8H5rWOH2rz9fDNQEd4g0EA2XlcEdJXRz5BMEn4O1pJFdT+z4YHhoWw== + xml-name-validator@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"