Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rewrite gyp files to 'binding.gyp'

  • Loading branch information...
commit 3ec0a8dc9148e376862dd60e92c2f8ad65d19f41 1 parent dbae7f2
@isaacs isaacs authored
Showing with 33 additions and 5 deletions.
  1. +33 −5 lib/utils/read-json.js
View
38 lib/utils/read-json.js
@@ -40,10 +40,39 @@ function readJson (jsonFile, opts, cb) {
gypfile = opts.gypfile
next()
} else {
- fs.readFile( path.join(path.dirname(jsonFile), "bindings.gyp")
- , function (er, data) {
- gypfile = opts.gypfile = !er
+ var pkgdir = path.dirname(jsonFile)
+
+ function hasGyp (has) {
+ gypfile = opts.gypfile = has
next()
+ }
+
+ fs.readdir(pkgdir, function (er, gf) {
+ // this would be weird.
+ if (er) return hasGyp(false)
+
+ // see if there are any *.gyp files in there.
+ // If there are, then copy them to binding.gyp
+ // if there are not, then just proceed without
+ gf = gf.filter(function (f) {
+ return f.match(/\.gyp$/)
+ })
+ gf = gf[0]
+ if (!gf) return hasGyp(false)
+ if (gf === "binding.gyp") return hasGyp(true)
+
+ // need to rename. windows is annoying.
+ // why not fs.rename? because we just saw the file, so it'll
+ // be cached for potentially several seconds on a network share.
+ return fs.readFile(path.resolve(pkgdir, gf), function (er, d) {
+ if (er) return hasGyp(false)
+ fs.writeFile(path.resolve(pkgdir, "binding.gyp"), d, function (er) {
+ if (er) return hasGyp(false)
+ fs.unlink(path.resolve(pkgdir, gf), function (er) {
+ return hasGyp(!er)
+ })
+ })
+ })
})
}
@@ -349,8 +378,7 @@ function processObject (opts, cb) { return function (er, json) {
if (opts.gypfile && !json.prebuilt) {
log.verbose([json.prebuilt, opts], "has bindings.gyp")
if (!scripts.install && !scripts.preinstall) {
- scripts.preinstall = "node-gyp clean || (exit 0)"
- scripts.install = "node-gyp configure && node-gyp build"
+ scripts.install = "node-gyp rebuild"
json.scripts = scripts
}
}

0 comments on commit 3ec0a8d

Please sign in to comment.
Something went wrong with that request. Please try again.