Merge pull request #621 from dao/master

Fix node compatibility
This commit is contained in:
Franck R 2022-03-18 18:41:55 +11:00 committed by GitHub
commit e55177d78d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 185 additions and 7 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Enable usage in NodeJS by fixing `exports` field and usage of the `crypto` module.
## [0.19.1] - 2022-03-10
### Added

View File

@ -11,7 +11,7 @@
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"js-waku": "file:../../build/esm",
"js-waku": "file:../../",
"protons": "^2.0.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
@ -21,9 +21,96 @@
"cra-webpack-rewired": "^1.0.1"
}
},
"../..": {
"version": "0.19.1",
"license": "MIT OR Apache-2.0",
"dependencies": {
"@chainsafe/libp2p-noise": "^5.0.0",
"@ethersproject/rlp": "^5.5.0",
"debug": "^4.3.1",
"dns-query": "^0.8.0",
"hi-base32": "^0.5.1",
"it-concat": "^2.0.0",
"it-length-prefixed": "^5.0.2",
"js-sha3": "^0.8.0",
"libp2p": "^0.36.2",
"libp2p-bootstrap": "^0.14.0",
"libp2p-gossipsub": "^0.13.0",
"libp2p-mplex": "^0.10.4",
"libp2p-websockets": "^0.16.1",
"multiaddr": "^10.0.1",
"multihashes": "^4.0.3",
"protobufjs": "^6.8.8",
"secp256k1": "^4.0.2",
"uuid": "^8.3.2"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@size-limit/preset-big-lib": "^7.0.8",
"@types/app-root-path": "^1.2.4",
"@types/bl": "^5.0.2",
"@types/chai": "^4.2.15",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.6",
"@types/secp256k1": "^4.0.2",
"@types/tail": "^2.0.0",
"@types/uuid": "^8.3.0",
"@types/varint": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"app-root-path": "^3.0.0",
"assert": "^2.0.0",
"buffer": "^6.0.3",
"chai": "^4.3.4",
"crypto-browserify": "^3.12.0",
"cspell": "^5.14.0",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^4.0.2",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"fast-check": "^2.14.0",
"gh-pages": "^3.2.3",
"husky": "^7.0.4",
"isomorphic-fetch": "^3.0.0",
"jsdom": "^19.0.0",
"jsdom-global": "^3.0.2",
"karma": "^6.3.12",
"karma-chrome-launcher": "^3.1.0",
"karma-env-preprocessor": "^0.1.1",
"karma-mocha": "^2.0.1",
"karma-typescript": "^5.5.3",
"lint-staged": "^12.3.4",
"mocha": "^9.1.3",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"p-timeout": "^4.1.0",
"portfinder": "^1.0.28",
"prettier": "^2.1.1",
"process": "^0.11.10",
"puppeteer": "^13.0.1",
"size-limit": "^7.0.8",
"stream-browserify": "^3.0.0",
"tail": "^2.2.0",
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"ts-proto": "^1.82.5",
"typedoc": "^0.22.10",
"typedoc-plugin-no-inherit": "^1.3.1",
"typescript": "^4.5.5",
"varint": "^6.0.0",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0"
},
"engines": {
"node": ">=16"
}
},
"../../build/esm": {
"name": "js-waku",
"version": "0.0.1"
"version": "0.0.1",
"extraneous": true
},
"node_modules/@babel/code-frame": {
"version": "7.16.7",
@ -10494,7 +10581,7 @@
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
},
"node_modules/js-waku": {
"resolved": "../../build/esm",
"resolved": "../..",
"link": true
},
"node_modules/js-yaml": {
@ -24133,7 +24220,84 @@
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
},
"js-waku": {
"version": "file:../../build/esm"
"version": "file:../..",
"requires": {
"@chainsafe/libp2p-noise": "^5.0.0",
"@ethersproject/rlp": "^5.5.0",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@size-limit/preset-big-lib": "^7.0.8",
"@types/app-root-path": "^1.2.4",
"@types/bl": "^5.0.2",
"@types/chai": "^4.2.15",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.6",
"@types/secp256k1": "^4.0.2",
"@types/tail": "^2.0.0",
"@types/uuid": "^8.3.0",
"@types/varint": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"app-root-path": "^3.0.0",
"assert": "^2.0.0",
"buffer": "^6.0.3",
"chai": "^4.3.4",
"crypto-browserify": "^3.12.0",
"cspell": "^5.14.0",
"debug": "^4.3.1",
"dns-query": "^0.8.0",
"eslint": "^8.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^4.0.2",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.0.0",
"fast-check": "^2.14.0",
"gh-pages": "^3.2.3",
"hi-base32": "^0.5.1",
"husky": "^7.0.4",
"isomorphic-fetch": "^3.0.0",
"it-concat": "^2.0.0",
"it-length-prefixed": "^5.0.2",
"js-sha3": "^0.8.0",
"jsdom": "^19.0.0",
"jsdom-global": "^3.0.2",
"karma": "^6.3.12",
"karma-chrome-launcher": "^3.1.0",
"karma-env-preprocessor": "^0.1.1",
"karma-mocha": "^2.0.1",
"karma-typescript": "^5.5.3",
"libp2p": "^0.36.2",
"libp2p-bootstrap": "^0.14.0",
"libp2p-gossipsub": "^0.13.0",
"libp2p-mplex": "^0.10.4",
"libp2p-websockets": "^0.16.1",
"lint-staged": "^12.3.4",
"mocha": "^9.1.3",
"multiaddr": "^10.0.1",
"multihashes": "^4.0.3",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"p-timeout": "^4.1.0",
"portfinder": "^1.0.28",
"prettier": "^2.1.1",
"process": "^0.11.10",
"protobufjs": "^6.8.8",
"puppeteer": "^13.0.1",
"secp256k1": "^4.0.2",
"size-limit": "^7.0.8",
"stream-browserify": "^3.0.0",
"tail": "^2.2.0",
"ts-loader": "^9.2.6",
"ts-node": "^10.4.0",
"ts-proto": "^1.82.5",
"typedoc": "^0.22.10",
"typedoc-plugin-no-inherit": "^1.3.1",
"typescript": "^4.5.5",
"uuid": "^8.3.2",
"varint": "^6.0.0",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0"
}
},
"js-yaml": {
"version": "3.14.1",

View File

@ -6,7 +6,7 @@
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"js-waku": "file:../../build/esm",
"js-waku": "file:../../",
"protons": "^2.0.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",

View File

@ -5,7 +5,13 @@
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
"module": "build/esm/index.js",
"exports": "./",
"exports": {
"node": {
"module": "./build/esm/index.js",
"import": "./build/main/index.js"
},
"default": "./build/main/index.js"
},
"repository": "https://github.com/status-im/js-waku",
"license": "MIT OR Apache-2.0",
"keywords": [

View File

@ -11,7 +11,11 @@ declare global {
}
}
const crypto = window.crypto || window.msCrypto || nodeCrypto.webcrypto;
const crypto =
(typeof window !== "undefined" &&
(window as Window) &&
(window.crypto || window.msCrypto)) ||
(nodeCrypto.webcrypto as unknown as Crypto);
const subtle: SubtleCrypto = crypto.subtle || crypto.webkitSubtle;
if (subtle === undefined) {