From f50ba67a2368a84b4df9b0efe9e113c370856de0 Mon Sep 17 00:00:00 2001 From: Andrey Parvatkin Date: Tue, 18 Dec 2018 18:06:01 +0400 Subject: [PATCH 01/14] fix "TypeError: main.startsWith is not a function" error (#75) * fix "TypeError: main.startsWith is not a function" error if "main" isn't a string Fixes https://github.com/tradle/rn-nodeify/issues/74 --- cmd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd.js b/cmd.js index 7613b35..c60477e 100755 --- a/cmd.js +++ b/cmd.js @@ -323,7 +323,7 @@ function fixPackageJSON (modules, file, overwrite) { const { main } = pkgJson - if (main) { + if (typeof main === 'string') { const alt = main.startsWith('./') ? main.slice(2) : './' + main if (depBrowser[alt]) { depBrowser[main] = depBrowser[alt] From ea456db433956aa734be6f2eca149b59f1257a39 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Thu, 20 Dec 2018 07:55:59 -0500 Subject: [PATCH 02/14] 10.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea7e1e9..153abee 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "type": "git", "url": "https://github.com/mvayngrib/rn-nodeify.git" }, - "version": "10.0.0", + "version": "10.0.1", "preferGlobal": true, "bin": "./cmd.js", "license": "MIT", From 1e8cb50683c7ba6a3fd15e52d41fae604558ce37 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Thu, 14 Feb 2019 08:50:45 -0500 Subject: [PATCH 03/14] chore: update git repo url in package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 153abee..8d4f934 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "rn-nodeify", "repository": { "type": "git", - "url": "https://github.com/mvayngrib/rn-nodeify.git" + "url": "https://github.com/tradle/rn-nodeify.git" }, "version": "10.0.1", "preferGlobal": true, From 6b850e6a0837fa5ff2e5c4acf5b5cf79f396e56e Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Thu, 14 Feb 2019 10:00:31 -0500 Subject: [PATCH 04/14] docs: update repo links, install instructions in README --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 80af834..7731ccb 100644 --- a/readme.md +++ b/readme.md @@ -70,12 +70,12 @@ Some shims may require linking libraries, be sure to run `react-native link` aft ### Example Apps / Workflows -* the [react-native-crypto](https://github.com/mvayngrib/react-native-crypto) package has an example workflow for using crypto in a React Native app +* the [react-native-crypto](https://github.com/tradle/react-native-crypto) package has an example workflow for using crypto in a React Native app * this [example React Native app](https://github.com/mvayngrib/adexample) shows how you can use [levelup](https://github.com/Level/levelup) in React Native ### Example Workflow -copied from [react-native-crypto](https://github.com/mvayngrib/react-native-crypto) +copied from [react-native-crypto](https://github.com/tradle/react-native-crypto) 1. Install and shim ```sh @@ -84,7 +84,7 @@ copied from [react-native-crypto](https://github.com/mvayngrib/react-native-cryp npm i --save react-native-randombytes react-native link react-native-randombytes # install latest rn-nodeify - npm i --save-dev mvayngrib/rn-nodeify + npm i --save-dev rn-nodeify@latest # install node core shims and recursively hack package.json files # in ./node_modules to add/update the "browser"/"react-native" field with relevant mappings ./node_modules/.bin/rn-nodeify --hack --install @@ -110,6 +110,6 @@ copied from [react-native-crypto](https://github.com/mvayngrib/react-native-cryp - removing the packager cache helps as well sometimes (`rm -fr $TMPDIR/react-*`) - rn-nodeify currently uses `npm` to install shims. PRs are welcome to make it compatible with `yarn` - use `npm@3`. `npm@5` has some issues that cause `node_modules` to disappear. See: - - https://github.com/mvayngrib/rn-nodeify/issues/42 + - https://github.com/tradle/rn-nodeify/issues/42 - https://github.com/infinitered/ignite/issues/1101 - https://github.com/npm/npm/issues/16839 From 86763a2e44f80b2089eae13ca3593260a93aac16 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Thu, 21 Mar 2019 09:06:13 -0400 Subject: [PATCH 05/14] docs: --yarn option --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7731ccb..4ba6ad9 100644 --- a/readme.md +++ b/readme.md @@ -30,6 +30,7 @@ rn-nodeify --install install node core shims (default: install all), fix the "browser" and "react-native" fields in the package.json's of dependencies --hack hack individual packages that are known to make the React Native packager choke +--yarn use yarn instead of npm ``` ### Examples @@ -108,7 +109,6 @@ copied from [react-native-crypto](https://github.com/tradle/react-native-crypto) - when installing a package from git, the postinstall hook isn't triggered, run it manually instead (`npm run postinstall`) - restart the react-native packager after installing a module! - removing the packager cache helps as well sometimes (`rm -fr $TMPDIR/react-*`) -- rn-nodeify currently uses `npm` to install shims. PRs are welcome to make it compatible with `yarn` - use `npm@3`. `npm@5` has some issues that cause `node_modules` to disappear. See: - https://github.com/tradle/rn-nodeify/issues/42 - https://github.com/infinitered/ignite/issues/1101 From c72171f82d0ce93331377a7554b2ae610808b9ef Mon Sep 17 00:00:00 2001 From: Bryan Goldstein Date: Sun, 18 Aug 2019 20:18:38 -0400 Subject: [PATCH 06/14] fix ulimit issues on large projects (#82) * fix ulimit issues on large projects we spent several days troubleshooting the ulimit issues we were running into on wsl and this was the only way we managed to fix it * change writeFile to writeFileSync --- cmd.js | 112 +++++++++++++++++++++++++++------------------------------ 1 file changed, 53 insertions(+), 59 deletions(-) diff --git a/cmd.js b/cmd.js index c60477e..05917b3 100755 --- a/cmd.js +++ b/cmd.js @@ -274,79 +274,73 @@ function hackPackageJSONs (modules, done) { function fixPackageJSON (modules, file, overwrite) { if (file.split(path.sep).indexOf('react-native') >= 0) return - fs.readFile(path.resolve(file), { encoding: 'utf8' }, function (err, contents) { - if (err) throw err - - // var browser = pick(baseBrowser, modules) - var pkgJson - try { - pkgJson = JSON.parse(contents) - } catch (err) { - console.warn('failed to parse', file) - return - } + var contents = fs.readFileSync(path.resolve(file), { encoding: 'utf8' }) + + // var browser = pick(baseBrowser, modules) + var pkgJson + try { + pkgJson = JSON.parse(contents) + } catch (err) { + console.warn('failed to parse', file) + return + } - // if (shims[pkgJson.name]) { - // log('skipping', pkgJson.name) - // return - // } + // if (shims[pkgJson.name]) { + // log('skipping', pkgJson.name) + // return + // } - // if (pkgJson.name === 'readable-stream') debugger + // if (pkgJson.name === 'readable-stream') debugger - var orgBrowser = pkgJson['react-native'] || pkgJson.browser || pkgJson.browserify || {} - if (typeof orgBrowser === 'string') { - orgBrowser = {} - orgBrowser[pkgJson.main || 'index.js'] = pkgJson['react-native'] || pkgJson.browser || pkgJson.browserify - } + var orgBrowser = pkgJson['react-native'] || pkgJson.browser || pkgJson.browserify || {} + if (typeof orgBrowser === 'string') { + orgBrowser = {} + orgBrowser[pkgJson.main || 'index.js'] = pkgJson['react-native'] || pkgJson.browser || pkgJson.browserify + } - var depBrowser = extend({}, orgBrowser) - for (var p in browser) { - if (modules.indexOf(p) === -1) continue + var depBrowser = extend({}, orgBrowser) + for (var p in browser) { + if (modules.indexOf(p) === -1) continue - if (!(p in orgBrowser)) { - depBrowser[p] = browser[p] + if (!(p in orgBrowser)) { + depBrowser[p] = browser[p] + } else { + if (!overwrite && orgBrowser[p] !== browser[p]) { + log('not overwriting mapping', p, orgBrowser[p]) } else { - if (!overwrite && orgBrowser[p] !== browser[p]) { - log('not overwriting mapping', p, orgBrowser[p]) - } else { - depBrowser[p] = browser[p] - } + depBrowser[p] = browser[p] } } + } - modules.forEach(function (p) { - if (depBrowser[p] === false && browser[p] !== false) { - log('removing browser exclude', file, p) - delete depBrowser[p] - } - }) - - - const { main } = pkgJson - if (typeof main === 'string') { - const alt = main.startsWith('./') ? main.slice(2) : './' + main - if (depBrowser[alt]) { - depBrowser[main] = depBrowser[alt] - log(`normalized "main" browser mapping in ${pkgJson.name}, fixed here: https://github.com/facebook/metro-bundler/pull/3`) - delete depBrowser[alt] - } + modules.forEach(function (p) { + if (depBrowser[p] === false && browser[p] !== false) { + log('removing browser exclude', file, p) + delete depBrowser[p] } + }) - if (pkgJson.name === 'constants-browserify') { - // otherwise react-native packager chokes for some reason - delete depBrowser.constants - } - if (!deepEqual(orgBrowser, depBrowser)) { - pkgJson.browser = pkgJson['react-native'] = depBrowser - delete pkgJson.browserify - fs.writeFile(file, JSON.stringify(pkgJson, null, 2), rethrow) + const { main } = pkgJson + if (typeof main === 'string') { + const alt = main.startsWith('./') ? main.slice(2) : './' + main + if (depBrowser[alt]) { + depBrowser[main] = depBrowser[alt] + log(`normalized "main" browser mapping in ${pkgJson.name}, fixed here: https://github.com/facebook/metro-bundler/pull/3`) + delete depBrowser[alt] } - }) -} + } -function rethrow (err) { - if (err) throw err + if (pkgJson.name === 'constants-browserify') { + // otherwise react-native packager chokes for some reason + delete depBrowser.constants + } + + if (!deepEqual(orgBrowser, depBrowser)) { + pkgJson.browser = pkgJson['react-native'] = depBrowser + delete pkgJson.browserify + fs.writeFileSync(file, JSON.stringify(pkgJson, null, 2)) + } } function runHelp () { From 580705c3ee0227298d0d12dba413f7aa3bb24ebb Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Sun, 18 Aug 2019 20:19:57 -0400 Subject: [PATCH 07/14] 10.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d4f934..bc54161 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "type": "git", "url": "https://github.com/tradle/rn-nodeify.git" }, - "version": "10.0.1", + "version": "10.1.0", "preferGlobal": true, "bin": "./cmd.js", "license": "MIT", From 03f8236bae7a60ee2d1b19974e7ce9da9bae0686 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Wed, 9 Oct 2019 18:48:35 -0400 Subject: [PATCH 08/14] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c844db6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Tradle + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 0e2317a1fcc4dcbeaf96809cd2252131ddccd4c6 Mon Sep 17 00:00:00 2001 From: Jonathan Haar Date: Fri, 11 Oct 2019 07:40:40 -0600 Subject: [PATCH 09/14] fix: add a new line at the end of package.json to align with yarn and npm (#84) --- cmd.js | 4 ++-- pkg-hacks.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd.js b/cmd.js index 05917b3..ef97b13 100755 --- a/cmd.js +++ b/cmd.js @@ -219,7 +219,7 @@ function installShims ({ modules, overwrite }, done) { installLine += ' ' }) - fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2), function (err) { + fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', function (err) { if (err) throw err if (installLine.trim() === BASE_INSTALL_LINE) { @@ -339,7 +339,7 @@ function fixPackageJSON (modules, file, overwrite) { if (!deepEqual(orgBrowser, depBrowser)) { pkgJson.browser = pkgJson['react-native'] = depBrowser delete pkgJson.browserify - fs.writeFileSync(file, JSON.stringify(pkgJson, null, 2)) + fs.writeFileSync(file, JSON.stringify(pkgJson, null, 2) + '\n') } } diff --git a/pkg-hacks.js b/pkg-hacks.js index bbbdd3c..25f4dbd 100644 --- a/pkg-hacks.js +++ b/pkg-hacks.js @@ -546,7 +546,7 @@ function body (fn) { } function prettify (json) { - return JSON.stringify(json, null, 2) + return JSON.stringify(json, null, 2) + '\n' } function isInReactNative (file) { From 6ee562221d891e817a630b39783aede685094241 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Fri, 11 Oct 2019 09:42:16 -0400 Subject: [PATCH 10/14] factor our prettify fn --- cmd.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd.js b/cmd.js index ef97b13..ae3790c 100755 --- a/cmd.js +++ b/cmd.js @@ -219,7 +219,7 @@ function installShims ({ modules, overwrite }, done) { installLine += ' ' }) - fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n', function (err) { + fs.writeFile(pkgPath, prettify(pkg), function (err) { if (err) throw err if (installLine.trim() === BASE_INSTALL_LINE) { @@ -339,7 +339,7 @@ function fixPackageJSON (modules, file, overwrite) { if (!deepEqual(orgBrowser, depBrowser)) { pkgJson.browser = pkgJson['react-native'] = depBrowser delete pkgJson.browserify - fs.writeFileSync(file, JSON.stringify(pkgJson, null, 2) + '\n') + fs.writeFileSync(file, prettify(pkgJson)) } } @@ -367,3 +367,7 @@ function runHelp () { function log () { console.log.apply(console, arguments) } + +function prettify (json) { + return JSON.stringify(json, null, 2) + '\n' +} From 300ca4460c3e4ffa01c45b3a122ce182dc1a0c5a Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Fri, 11 Oct 2019 09:44:53 -0400 Subject: [PATCH 11/14] 10.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc54161..4dc0f91 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "type": "git", "url": "https://github.com/tradle/rn-nodeify.git" }, - "version": "10.1.0", + "version": "10.2.0", "preferGlobal": true, "bin": "./cmd.js", "license": "MIT", From b98b0998f9ea47328214de5508956c7889d123ae Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Mon, 19 Oct 2020 15:24:58 -0400 Subject: [PATCH 12/14] fix: pbkdf2 hack (#99) --- pkg-hacks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg-hacks.js b/pkg-hacks.js index 25f4dbd..5004ce0 100644 --- a/pkg-hacks.js +++ b/pkg-hacks.js @@ -520,7 +520,7 @@ var hackers = [ hack: function (file, contents) { if (isInReactNative(file)) return - var fixed = contents.replace('process.version', '"' + process.version + '"') + var fixed = contents.replace(/process.version/g, '"' + process.version + '"') return contents === fixed ? null : fixed } From dc4ea4daa68ff347abcc6cb2ca799375ad1f8990 Mon Sep 17 00:00:00 2001 From: Fabian Kutsche Date: Mon, 19 Apr 2021 18:36:35 +0200 Subject: [PATCH 13/14] fix: pbkdf2 hack not breaking in specific versions (#105) * fix: pbkdf2 hack not breaking in specific versions * fix: add escape to prevent false regex matches --- pkg-hacks.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg-hacks.js b/pkg-hacks.js index 5004ce0..6ac639a 100644 --- a/pkg-hacks.js +++ b/pkg-hacks.js @@ -520,7 +520,9 @@ var hackers = [ hack: function (file, contents) { if (isInReactNative(file)) return - var fixed = contents.replace(/process.version/g, '"' + process.version + '"') + var fixed = contents + .replace(/global\.process\.version/g, '"' + process.version + '"') + .replace(/process\.version/g, '"' + process.version + '"') return contents === fixed ? null : fixed } From 338d8d6ba8438403093e9409e9a9d88ad884926f Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Mon, 19 Apr 2021 12:36:58 -0400 Subject: [PATCH 14/14] 10.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4dc0f91..2b511af 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "type": "git", "url": "https://github.com/tradle/rn-nodeify.git" }, - "version": "10.2.0", + "version": "10.3.0", "preferGlobal": true, "bin": "./cmd.js", "license": "MIT",