Socket
Socket
Sign inDemoInstall

node-gyp

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-gyp - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

.npmignore

39

lib/build.js

@@ -9,2 +9,3 @@

var path = require('path')
, glob = require('glob')
, which = require('which')

@@ -26,5 +27,25 @@ , asyncEmit = require('./util/asyncEmit')

emitter = _e
doWhich()
if (win) {
findSolutionFile()
} else {
doWhich()
}
})
/**
* On Windows, find first build/*.sln file.
*/
function findSolutionFile () {
glob('build/*.sln', function (err, files) {
if (err) return callback(err)
if (files.length === 0) {
return callback(new Error('Could not find *.sln file. Did you run "configure"?'))
}
guessedSolution = files[0]
gyp.verbose('found first Solution file', guessedSolution)
doWhich()
})
}
function doWhich () {

@@ -57,5 +78,6 @@ // First make sure we have the build command in the PATH

var windir = process.env.WINDIR || process.env.SYSTEMROOT || 'C:\\WINDOWS'
, frameworkDir = path.join(windir, 'Microsoft.NET', 'Framework')
, versionDir = path.join(frameworkDir, 'v4.0.30319') // This is probably the most brittle part...
, msbuild = path.join(versionDir, 'msbuild.exe')
, frameworkDir = path.resolve(windir, 'Microsoft.NET', 'Framework')
, versionDir = path.resolve(frameworkDir, 'v4.0.30319') // This is probably the most brittle part...
, msbuild = path.resolve(versionDir, 'msbuild.exe')
// TODO: Check to see if this file actually exists and error out if it doesn't
command = msbuild

@@ -90,5 +112,5 @@ build()

argv.push('BUILDTYPE=' + config)
// Don't overwrite an existing Makefile
argv.push('-f')
argv.push('Makefile.gyp')
// Invoke the Makefile in the 'build' dir.
argv.push('-C')
argv.push('build')
}

@@ -102,4 +124,3 @@

if (!hasSln) {
// on windows, specify the sln file to use. "bindings.sln" by default
argv.unshift(gyp.opts.solution || 'bindings.sln')
argv.unshift(gyp.opts.solution || guessedSolution)
}

@@ -106,0 +127,0 @@ }

@@ -11,40 +11,10 @@

var rm = require('rimraf')
, glob = require('glob')
, asyncEmit = require('./util/asyncEmit')
, createHook = require('./util/hook')
, targets = []
/**
* Add the platform-specific targets to remove.
*/
if (process.platform == 'win32') {
// Remove MSVC project files
targets.push('Debug')
targets.push('Release')
targets.push('*.sln')
targets.push('*.vcxproj*')
} else {
// Remove Makefile project files
targets.push('out')
targets.push('Makefile.gyp')
targets.push('*.Makefile')
targets.push('*.target.gyp.mk')
}
if (process.platform == 'solaris') {
// Remoge the 'gyp-sun-tool' on Solaris
targets.push('gyp-sun-tool')
}
if (process.platform == 'darwin') {
// Remoge the 'gyp-mac-tool' on Darwin
targets.push('gyp-mac-tool')
}
function clean (gyp, argv, callback) {
// The list of files to be removed
var files = []
, globCount = targets.length
, counter = 0
// Remove the 'build' dir
var buildDir = 'build'
, emitter

@@ -62,33 +32,4 @@

function doClean () {
targets.forEach(function (target) {
gyp.verbose('globbing', target)
glob(target, function (err, result) {
if (err) return callback(err)
globCount--
files.push.apply(files, result)
result.forEach(function (file) {
counter++
gyp.verbose('removing', file)
rm(file, function (err) {
if (err) return callback(err)
counter--
gyp.verbose('removed', file)
if (counter === 0) {
gyp.verbose('done removing files', files)
after()
}
})
})
if (globCount === 0 && counter === 0) {
// Nothing to clean!
gyp.info('nothing to clean')
after()
}
})
})
gyp.verbose('removing "build" directory')
rm(buildDir, after)
}

@@ -95,0 +36,0 @@

@@ -21,3 +21,2 @@

var python = gyp.opts.python || 'python'
, next = win ? go : cleanupMakefile
, emitter

@@ -45,61 +44,13 @@ , version

gyp.opts.ensure = true
gyp.commands.install([ version ], next)
gyp.commands.install([ version ], go)
}
/**
* Removes any existing Makefile.gyp file, if it exists.
* Fixes: https://github.com/TooTallNate/node-gyp/issues/18
*/
function cleanupMakefile (err) {
if (err) return callback(err)
gyp.verbose('checking for Makefile.gyp')
fs.stat('Makefile.gyp', function (err, stat) {
if (err) {
if (err.code == 'ENOENT') {
// No Makefile.gyp, we're good
gyp.verbose('no Makefile.gyp exists, continuing with "configure"')
go()
} else {
// Some other error, report it
callback(err)
}
return
}
// Makefile.gyp exists, gotta remove it
gyp.verbose('found a Makefile.gyp file, removing')
fs.unlink('Makefile.gyp', function (err) {
if (err) return callback(err)
gyp.verbose('removed the Makefile.gyp file successfully')
go()
})
})
}
function go (err) {
if (err) return callback(err)
var devDir = path.join(process.env.HOME, '.node-gyp', version)
, gyp_addon = path.join(devDir, 'tools', 'gyp_addon')
var devDir = path.resolve(process.env.HOME, '.node-gyp', version)
, gyp_addon = path.resolve(devDir, 'tools', 'gyp_addon')
if (win && nodeVersion.lessThan(version, 0, 8)) {
gyp.verbose('on Windows and target version is less than 0.8; applying #2685 patch')
// if < 0.8, we need to manually apply the patch at joyent/node#2685,
// since it got merged somewhere in 0.7.x.
argv.push('-Dnode_root_dir=' + devDir)
argv.push('-I')
argv.push(path.join(devDir, 'tools', 'patch.gypi'))
}
if (!win && nodeVersion.lessThan(version, 0, 8)) {
gyp.verbose('on Unix and target version is less than 0.8; applying #2722 patch')
argv.push('-I')
argv.push(path.join(devDir, 'tools', 'patch2722.gypi'))
}
if (!win && !~argv.indexOf('-f') && !~argv.indexOf('--format')) {
gyp.verbose('gyp format was not specified; forcing "make"')
// use a 'gyp' suffix on the Makefile, as to not overwrite an existing one
argv.unshift('.gyp')
argv.unshift('--suffix')
// force the 'make' target for non-Windows

@@ -151,6 +102,2 @@ argv.unshift('make')

callback(new Error('`gyp_addon` failed with exit code: ' + code))
} else if (process.platform == 'darwin' && gyp.opts.arch != 'ia32') {
// XXX: Add a version check here when node upgrades gyp to a version that
// fixes this
remove_i386()
} else {

@@ -163,68 +110,2 @@ // we're done

/**
* Removes the lines that contain '-arch i386' from any generated
* *.target.gyp.mk files. This works around a nasty gyp bug where they
* hard-code these flags in for some reason.
*/
function remove_i386 () {
glob('**/*.target.gyp.mk', function (err, files) {
if (err) return callback(err)
var count = files.length
if (count === 0) return callback()
files.forEach(function (filename) {
remove_i386single(filename, function (err) {
if (err) return callback(err)
--count || callback()
})
})
})
}
function remove_i386single (filename, done) {
gyp.verbose('removing "-arch i386" flag from', filename)
var rs = fs.createReadStream(filename)
, lines = []
rs.setEncoding('utf8')
emitLines(rs)
rs.on('line', function (line) {
// ignore lines containing the bad flag
if (!~line.indexOf('-arch i386')) {
lines.push(line)
}
})
rs.on('end', function () {
// now save the file back with the offending lines removed
fs.writeFile(filename, lines.join('\n'), function (err) {
if (err) return done(err)
done()
})
})
}
}
/**
* A quick little thingy that takes a Stream instance and makes it emit 'line'
* events when a newline is encountered.
*/
function emitLines (stream) {
var backlog = ''
stream.on('data', function (data) {
backlog += data
var n = backlog.indexOf('\n')
// got a \n? emit one or more 'line' events
while (~n) {
stream.emit('line', backlog.substring(0, n))
backlog = backlog.substring(n + 1)
n = backlog.indexOf('\n')
}
})
stream.on('end', function () {
if (backlog) {
stream.emit('line', backlog)
}
})
}
module.exports = exports = install
exports.usage = 'Install node development files for the specified node version. Respects http_proxy/HTTP_PROXY and --proxy=<proxyurl> when downloading.'
exports.usage = 'Install node development files for the specified node version.'

@@ -16,2 +16,3 @@ /**

, mkdir = require('mkdirp')
, fstream = require('fstream')
, request = require('request')

@@ -49,4 +50,10 @@ , minimatch = require('minimatch')

// Determine which node dev files minor version we are installing
var version = nodeVersion.parse(argv[0] || gyp.opts.target)
gyp.verbose('installing version', version)
// "legacy" versions are 0.7 and 0.6
var isLegacy = nodeVersion.lessThan(version, 0, 8)
gyp.verbose('installing legacy version?', isLegacy)
if (!version) {

@@ -59,4 +66,5 @@ return callback(new Error('You must specify a version to install (like "0.7")'))

// TODO: Make ~/.node-gyp configurable
var devDir = path.join(process.env.HOME, '.node-gyp', version)
var devDir = path.resolve(process.env.HOME, '.node-gyp', version)

@@ -77,4 +85,19 @@ // If '--ensure' was passed, then don't *always* install the version,

}
gyp.verbose('version is already installed, not re-installing', version)
callback()
gyp.verbose('version is already installed, need to check "installVersion"')
var installVersionFile = path.resolve(devDir, 'installVersion')
fs.readFile(installVersionFile, 'ascii', function (err, ver) {
if (err && err.code != 'ENOENT') {
return callback(err)
}
var installVersion = parseInt(ver, 10) || 0
gyp.verbose('got "installVersion":', installVersion)
gyp.verbose('needs "installVersion":', gyp.package.installVersion)
if (installVersion < gyp.package.installVersion) {
gyp.verbose('version is no good; reinstalling')
go()
} else {
gyp.verbose('version is good')
callback()
}
})
})

@@ -129,3 +152,3 @@ } else {

if (!install.valid(trimmed)) {
if (!valid(trimmed)) {
// skip

@@ -136,4 +159,4 @@ return

var dir = path.dirname(trimmed)
, devFileDir = path.join(devDir, dir)
, devFile = path.join(devDir, trimmed)
, devFileDir = path.resolve(devDir, dir)
, devFile = path.resolve(devDir, trimmed)

@@ -172,4 +195,4 @@ if (dir !== '.') {

if (nodeVersion.lessThan(version, 0, 7)) {
// copy over gyp_addon, addon.gypi and common.gypi
if (isLegacy) {
// copy over the files from the `legacy` dir
async++

@@ -185,11 +208,6 @@ copyLegacy(deref)

if (win && nodeVersion.lessThan(version, 0, 8)) {
// before node 0.8 we need to manually link to node.lib
async++
copy2685(deref)
}
if (!win && nodeVersion.lessThan(version, 0, 8)) {
async++
copy2722(deref)
}
// write the "installVersion" file
async++
var installVersionPath = path.resolve(devDir, 'installVersion')
fs.writeFile(installVersionPath, gyp.package.installVersion + '\n', deref)

@@ -208,37 +226,34 @@ if (async === 0) {

function copyLegacy (done) {
// node 0.6.x doesn't come with the needed addon.gypi or gyp_addon
// files, so we must copy them over manually
gyp.verbose('copying "legacy" development files for version', version)
var legacyDir = path.join(__dirname, '..', 'legacy')
, toolsDir = path.join(devDir, 'tools')
// legacy versions of node (< 0.8) require the legacy files to be copied
// over since they contain many bugfixes from the current node build system
gyp.verbose('copying "legacy" gyp configuration files for version', version)
var legacyDir = path.resolve(__dirname, '..', 'legacy')
gyp.verbose('using "legacy" dir', legacyDir)
gyp.verbose('installing to "tools" dir', toolsDir)
gyp.verbose('copying to "dev" dir', devDir)
// get a listing of the files to copy
fs.readdir(legacyDir, function (err, files) {
if (err) return done(err)
var count = files.length
var reader = fstream.Reader({ path: legacyDir, type: 'Directory' })
, writer = fstream.Writer({ path: devDir, type: 'Directory' })
// copy each one over in parallel
files.forEach(function (file) {
// common.gypi is a special-case that goes in the root dir instead of
// the "tools" dir
var copyFrom = path.join(legacyDir, file)
, copyTo = path.join(file == 'common.gypi' ? devDir : toolsDir, path.basename(file))
gyp.verbose('copying from, to', copyFrom, copyTo)
copy(copyFrom, copyTo, function (err) {
// TODO: guard against multi-callbacks
if (err) return done(err)
--count || done()
})
})
reader.on('entry', function onEntry (entry) {
gyp.verbose('reading entry', entry.path)
entry.on('entry', onEntry)
})
reader.on('error', done)
writer.on('error', done)
// Like `cp -rpf`
reader.pipe(writer)
reader.on('end', done)
}
function downloadNodeLib (done) {
gyp.verbose('on windows; need to download `node.lib`')
var releaseDir = path.join(devDir, 'Release')
, debugDir = path.join(devDir, 'Debug')
gyp.verbose('on Windows; need to download `node.lib`...')
var releaseDir = path.resolve(devDir, 'Release')
, debugDir = path.resolve(devDir, 'Debug')
, patchVersion = nodeLibMap[version] || '0'
, nodeLibUrl = distUrl + '/v' + version + '.' + patchVersion + '/node.lib'
gyp.verbose('Release dir', releaseDir)

@@ -261,4 +276,4 @@ gyp.verbose('Debug dir', debugDir)

})
var releaseDirNodeLib = path.join(releaseDir, 'node.lib')
, debugDirNodeLib = path.join(debugDir, 'node.lib')
var releaseDirNodeLib = path.resolve(releaseDir, 'node.lib')
, debugDirNodeLib = path.resolve(debugDir, 'node.lib')
, rws = fs.createWriteStream(releaseDirNodeLib)

@@ -278,50 +293,29 @@ , dws = fs.createWriteStream(debugDirNodeLib)

function copy2685 (done) {
gyp.verbose('need to install the patch gypi file for #2685 for version', version)
var patchPath = path.join(__dirname, '..', '2685', 'patch.gypi')
, copyTo = path.join(devDir, 'tools', 'patch.gypi')
gyp.verbose('patch.gypi', patchPath)
gyp.verbose('copy to', copyTo)
copy(patchPath, copyTo, done)
}
function copy2722 (done) {
gyp.verbose('need to install the patch gypi file for #2722 for version', version)
var patchPath = path.join(__dirname, '..', '2722', 'patch.gypi')
, copyTo = path.join(devDir, 'tools', 'patch2722.gypi')
gyp.verbose('patch.gypi', patchPath)
gyp.verbose('copy to', copyTo)
copy(patchPath, copyTo, done)
}
})
}
})
/**
* Checks if a given filename is "valid" for this installation.
*/
function valid (file) {
// header files
return minimatch(file, 'src/*.h')
|| minimatch(file, 'deps/v8/include/**/*.h')
|| minimatch(file, 'deps/uv/include/**/*.h')
// non-legacy versions of node also extract the gyp build files
|| (!isLegacy &&
(minimatch(file, '*.gypi')
|| minimatch(file, 'tools/*.gypi')
|| minimatch(file, 'tools/gyp_addon')
|| (minimatch(file, 'tools/gyp/**') && !minimatch(file, 'tools/gyp/test/**'))
)
)
}
}
function copy (from, to, cb) {
var ws = fs.createWriteStream(to)
, rs = fs.createReadStream(from)
rs.on('error', cb)
ws.on('error', cb)
rs.pipe(ws)
rs.on('end', function () {
cb()
})
}
install.valid = function valid (file) {
return minimatch(file, '*.gypi')
|| minimatch(file, 'tools/*.gypi')
|| minimatch(file, 'tools/gyp_addon')
|| (minimatch(file, 'tools/gyp/**')
&& !minimatch(file, 'tools/gyp/test/**'))
// header files
|| minimatch(file, 'src/*.h')
|| minimatch(file, 'deps/v8/include/**/*.h')
|| minimatch(file, 'deps/uv/include/**/*.h')
}
install.trim = function trim (file) {

@@ -328,0 +322,0 @@ var firstSlash = file.indexOf('/')

@@ -16,3 +16,3 @@

// TODO: Make ~/.node-gyp configurable
var nodeGypDir = path.join(process.env.HOME, '.node-gyp')
var nodeGypDir = path.resolve(process.env.HOME, '.node-gyp')

@@ -19,0 +19,0 @@ gyp.verbose('using node-gyp dir', nodeGypDir)

@@ -18,3 +18,3 @@

// TODO: Make ~/.node-gyp configurable
var nodeGypDir = path.join(process.env.HOME, '.node-gyp')
var nodeGypDir = path.resolve(process.env.HOME, '.node-gyp')

@@ -24,3 +24,3 @@ gyp.verbose('using node-gyp dir', nodeGypDir)

var version = nodeVersion.parse(argv[0] || gyp.opts.target)
, versionPath = path.join(nodeGypDir, version)
, versionPath = path.resolve(nodeGypDir, version)

@@ -27,0 +27,0 @@ gyp.verbose('removing development files for version', version)

{ "name": "node-gyp"
, "description": "Node.js native addon build tool"
, "keywords": [ "native", "addon", "module", "c", "c++", "bindings", "gyp" ]
, "version": "0.1.4"
, "version": "0.2.0"
, "installVersion": 1
, "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)"

@@ -13,2 +14,3 @@ , "repository": { "type": "git", "url": "git://github.com/TooTallNate/node-gyp.git" }

, "glob": "3"
, "fstream": "~0.1.13"
, "minimatch": "~0.1.4"

@@ -15,0 +17,0 @@ , "mkdirp": "0.3.0"

@@ -34,7 +34,7 @@ node-gyp

* On Unix
* On Unix:
* `python`
* `make`
* A proper C/C++ compiler toolchain, like GCC
* On Windows
* On Windows:
* [Python][windows-python]

@@ -41,0 +41,0 @@ * Microsoft Visual C++ ([Express][msvc] version works well)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc