From 565ffb18fb3a641269c38b66c29ba7d05c8c139f Mon Sep 17 00:00:00 2001 From: Dylan Oliver Date: Thu, 17 Mar 2022 22:29:03 -0400 Subject: [PATCH 1/4] fix package.json exports to work in node as well as browser --- package.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e5328d7449..0c6158e92d 100644 --- a/package.json +++ b/package.json @@ -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": [ From 9cf2924f7be838d1442e9bb852afbc7d6faa1b67 Mon Sep 17 00:00:00 2001 From: Dylan Oliver Date: Thu, 17 Mar 2022 22:30:27 -0400 Subject: [PATCH 2/4] check presence of window before using it and appease ts types --- src/lib/crypto.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/crypto.ts b/src/lib/crypto.ts index 87011c3d99..fb6cd705a5 100644 --- a/src/lib/crypto.ts +++ b/src/lib/crypto.ts @@ -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) { From ff0cc1bc38af4bfbc8906f664c2593c044d63375 Mon Sep 17 00:00:00 2001 From: Dylan Oliver Date: Thu, 17 Mar 2022 22:31:42 -0400 Subject: [PATCH 3/4] example relay-reactjs-chat app works importing whole package rather than subpath --- examples/relay-reactjs-chat/package-lock.json | 172 +++++++++++++++++- examples/relay-reactjs-chat/package.json | 2 +- 2 files changed, 169 insertions(+), 5 deletions(-) diff --git a/examples/relay-reactjs-chat/package-lock.json b/examples/relay-reactjs-chat/package-lock.json index 7d6d3197a7..1b17f28fc4 100644 --- a/examples/relay-reactjs-chat/package-lock.json +++ b/examples/relay-reactjs-chat/package-lock.json @@ -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", diff --git a/examples/relay-reactjs-chat/package.json b/examples/relay-reactjs-chat/package.json index cc300e095d..52814a60b2 100644 --- a/examples/relay-reactjs-chat/package.json +++ b/examples/relay-reactjs-chat/package.json @@ -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", From d2e9a57604a3718e19319363c818c3efb508e496 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Fri, 18 Mar 2022 14:47:25 +1100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e02b224fc9..31c513ee2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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