forked from tradle/rn-nodeify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 779c34d
Showing
8 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"zlib": "browserify-zlib", | ||
"console": "console-browserify", | ||
"constants": "constants-browserify", | ||
"crypto": "crypto-browserify", | ||
"dns": "dns.js", | ||
"net": "utp", | ||
"domain": "domain-browser", | ||
"http": "http-browserify", | ||
"https": "https-browserify", | ||
"os": "os-browserify", | ||
"path": "path-browserify", | ||
"querystring": "querystring-es3", | ||
"fs": "react-native-level-fs", | ||
"_stream_transform": "readable-stream/transform", | ||
"_stream_readable": "readable-stream/readable", | ||
"_stream_writable": "readable-stream/writable", | ||
"_stream_duplex": "readable-stream/duplex", | ||
"_stream_passthrough": "readable-stream/passthrough", | ||
"dgram": "react-native-udp", | ||
"stream": "stream-browserify", | ||
"timers": "timers-browserify", | ||
"tty": "tty-browserify", | ||
"vm": "vm-browserify" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs') | ||
var path = require('path') | ||
var semver = require('semver') | ||
var proc = require('child_process') | ||
var extend = require('xtend') | ||
var find = require('findit') | ||
var allShims = require('./shims.json') | ||
var browser = require('./browser.json') | ||
var pkg = require('./package.json') | ||
var argv = process.argv.slice(2) | ||
|
||
installShims(argv.length ? argv : Object.keys(allShims)) | ||
hackPackageJSONs() | ||
|
||
function installShims (shims) { | ||
shims.forEach(function (name) { | ||
var modPath = path.resolve('./node_modules/' + name) | ||
fs.exists(modPath, function (exists) { | ||
if (exists) { | ||
var existingVer = require(modPath + '/package.json').version | ||
if (semver.satisfies(existingVer, shims[name])) { | ||
console.log('not reinstalling ' + name) | ||
return | ||
} | ||
} | ||
|
||
proc.execSync('npm install --save ' + name + '@' + allShims[name], { | ||
cwd: process.cwd(), | ||
env: process.env, | ||
stdio: 'inherit' | ||
}) | ||
}) | ||
}) | ||
|
||
fs.exists('./shim.js', function (exists) { | ||
if (exists) return | ||
|
||
fs.readFile(path.join(__dirname, 'shim.js'), { encoding: 'utf8' }, function (err, contents) { | ||
if (err) throw err | ||
|
||
fs.writeFile('./shim.js', contents, rethrow) | ||
}) | ||
}) | ||
} | ||
|
||
function hackPackageJSONs () { | ||
var finder = find('./node_modules') | ||
|
||
finder.on('file', function (file) { | ||
if (!/\/package\.json$/.test(file)) return | ||
|
||
fs.readFile(path.resolve(file), { encoding: 'utf8' }, function (err, contents) { | ||
if (err) throw err | ||
|
||
var pkgJson | ||
try { | ||
pkgJson = JSON.parse(contents) | ||
} catch (err) { | ||
console.warn('failed to parse', file) | ||
return | ||
} | ||
|
||
var orgBrowser = pkgJson.browser | ||
var depBrowser = extend(browser) | ||
var save | ||
if (typeof orgBrowser === 'string') { | ||
depBrowser[pkgJson.main] = pkgJson.browser | ||
save = true | ||
} else { | ||
if (typeof orgBrowser === 'object') { | ||
depBrowser = extend(depBrowser, orgBrowser) | ||
} else { | ||
save = true | ||
} | ||
} | ||
|
||
if (!save) { | ||
for (var p in depBrowser) { | ||
if (!orgBrowser[p]) { | ||
save = true | ||
} else if (depBrowser[p] !== browser[p]) { | ||
console.log('not overwriting mapping', p, orgBrowser[p]) | ||
} | ||
} | ||
} | ||
|
||
if (save) { | ||
pkgJson.browser = depBrowser | ||
fs.writeFile(file, JSON.stringify(pkgJson, null, 2), rethrow) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
function rethrow (err) { | ||
if (err) throw err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "rn-nodeify", | ||
"version": "1.0.0", | ||
"preferGlobal": true, | ||
"bin": "./cmd.js", | ||
"dependencies": { | ||
"findit": "^2.0.0", | ||
"fs-extra": "^0.22.1", | ||
"semver": "^5.0.1", | ||
"xtend": "^4.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# rn-nodify | ||
[](https://nodei.co/npm/rn-nodify/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if (typeof __dirname === 'undefined') global.__dirname = '/' | ||
if (typeof __filename === 'undefined') global.__filename = '' | ||
if (typeof process === 'undefined') { | ||
global.process = require('process') | ||
process.browser = false | ||
} | ||
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"assert": "^1.1.1", | ||
"browserify-zlib": "~0.1.4", | ||
"buffer": "^3.0.3", | ||
"inherits": "^2.0.1", | ||
"console-browserify": "^1.1.0", | ||
"constants-browserify": "0.0.1", | ||
"crypto-browserify": "~3.2.6", | ||
"dns.js": "^1.0.1", | ||
"domain-browser": "^1.1.1", | ||
"events": "^1.0.0", | ||
"http-browserify": "^1.3.2", | ||
"https-browserify": "0.0.0", | ||
"os-browserify": "~0.1.2", | ||
"path-browserify": "0.0.0", | ||
"process": "^0.11.0", | ||
"punycode": "^1.2.4", | ||
"querystring-es3": "~0.2.0", | ||
"react-native-level-fs": "^1.0.3", | ||
"react-native-udp": "0.0.12", | ||
"readable-stream": "^1.1.13", | ||
"stream-browserify": "^1.0.0", | ||
"string_decoder": "~0.10.25", | ||
"timers-browserify": "^1.0.1", | ||
"tty-browserify": "0.0.0", | ||
"url": "~0.10.1", | ||
"util": "~0.10.3", | ||
"utp": "0.0.8", | ||
"vm-browserify": "0.0.4" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var test = require('tape') | ||
|
||
test('dummy test', function (t) { | ||
t.end() | ||
}) |