Skip to content

Commit

Permalink
Merge branch 'master' into napi-support
Browse files Browse the repository at this point in the history
  • Loading branch information
springmeyer authored Mar 10, 2018
2 parents 9684ef6 + cf3ebb6 commit c31cce4
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 85 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ addons:

env:
matrix:
- NODE_VERSION="0.10"
- NODE_VERSION="6" RETIRE=true
- NODE_VERSION="4"
- NODE_VERSION="5"
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# node-pre-gyp changelog

## 0.7.1

- Upgraded to tar v4.x

## 0.7.0

- Updated request and hawk (#347)
- Dropped node v0.10.x support

## 0.6.40

- Improved error reporting if an install fails

## 0.6.39

- Support for node v9
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ See the [Frequently Ask Questions](https://github.com/mapbox/node-pre-gyp/wiki/F

## Depends

- Node.js >= node v0.10.x
- Node.js >= node v4.x

## Install

Expand Down Expand Up @@ -74,7 +74,7 @@ Options include:
- `--update-binary`: reinstall by replacing previously installed local binary with remote binary
- `--runtime=node-webkit`: customize the runtime: `node`, `electron` and `node-webkit` are the valid options
- `--fallback-to-build`: fallback to building from source if pre-built binary is not available
- `--target=0.10.25`: Pass the target node or node-webkit version to compile against
- `--target=0.4.0`: Pass the target node or node-webkit version to compile against
- `--target_arch=ia32`: Pass the target arch and override the host `arch`. Valid values are 'ia32','x64', or `arm`.
- `--target_platform=win32`: Pass the target platform and override the host `platform`. Valid values are `linux`, `darwin`, `win32`, `sunos`, `freebsd`, `openbsd`, and `aix`.

Expand Down Expand Up @@ -557,8 +557,8 @@ os:
env:
matrix:
- NODE_VERSION="0.10"
- NODE_VERSION="0.11.14"
- NODE_VERSION="4"
- NODE_VERSION="6"
before_install:
- rm -rf ~/.nvm/ && git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
Expand Down Expand Up @@ -593,8 +593,8 @@ By doing:
```yml
env:
matrix:
- NODE_VERSION="0.10"
- NODE_VERSION="0.11.14"
- NODE_VERSION="4"
- NODE_VERSION="6"
before_install:
- rm -rf ~/.nvm/ && git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
Expand All @@ -607,8 +607,8 @@ You can easily recreate the previous behavior of this matrix:

```yml
node_js:
- "0.10"
- "0.11.14"
- "4"
- "6"
```

#### 4) Publish when you want
Expand Down
17 changes: 4 additions & 13 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ os: Visual Studio 2015

environment:
matrix:
- nodejs_version: 0.10
- nodejs_version: 4
- nodejs_version: 6
- nodejs_version: 8
Expand All @@ -18,19 +17,9 @@ install:
- ps: Install-Product node $env:nodejs_version $env:Platform
- ps: Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
- npm config get
# upgrade node-gyp to dodge 2013 compile issue present in the node gyp bundled with node v0.10
# https://github.com/nodejs/node-gyp/issues/972#issuecomment-231055109
# but we upgrade using my fork since 3.x upstream will now break node v0.10.x support
- IF "%nodejs_version:~0,1%"=="0" npm install https://github.com/springmeyer/node-gyp/tarball/v3.x
# upgrade node-gyp to dodge https://github.com/mapbox/node-pre-gyp/issues/209#issuecomment-307641388
# and allow make node 4.x x86 builds work
# https://github.com/mapbox/node-pre-gyp/issues/209#issuecomment-217690537
- IF "%nodejs_version:~0,1%"=="4" npm install [email protected]
# downgrade npm to avoid multiple npm bugs:
# for node v6 this dodges npm 3.10.10 bug whereby --nodedir/--dist-url is not passed to node-gyp (https://github.com/mapbox/node-pre-gyp/issues/300)
# for all node x86 versions this dodges a mysterious ELIFECYCLE error: https://ci.appveyor.com/project/Mapbox/node-pre-gyp/build/1.0.582/job/b8q2nud6vkj0s6qo#L233
# for node v8 this dodges https://github.com/mapbox/node-pre-gyp/issues/302
- npm install [email protected] -g
- IF "%nodejs_version:~0,1%" EQU "4" npm install [email protected]
- node --version
- npm --version
- node -e "console.log(process.arch);"
Expand All @@ -39,8 +28,10 @@ install:
- IF /I "%PLATFORM%" == "x64" CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
- IF /I "%PLATFORM%" == "x86" CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
- npm install
# workaround https://github.com/mapbox/node-pre-gyp/issues/300#issuecomment-328179994
- IF "%nodejs_version:~0,1%" GEQ "6" npm install npm@2 -g
- npm test

build: off
test: off
deploy: off
deploy: off
46 changes: 24 additions & 22 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ exports.usage = 'Attempts to install pre-built binary for module';

var fs = require('fs');
var path = require('path');
var zlib = require('zlib');
var log = require('npmlog');
var existsAsync = fs.exists || path.exists;
var versioning = require('./util/versioning.js');
var napi = require('./util/napi.js');
var mkdirp = require('mkdirp');

var npgVersion = 'unknown';
try {
Expand Down Expand Up @@ -76,8 +76,7 @@ function place_binary(from,to,opts,callback) {
if (!req) return callback(new Error("empty req"));
var badDownload = false;
var extractCount = 0;
var gunzip = zlib.createGunzip();
var extracter = require('tar').Extract({ path: to, strip: 1});
var tar = require('tar');

function afterTarball(err) {
if (err) return callback(err);
Expand All @@ -90,18 +89,10 @@ function place_binary(from,to,opts,callback) {
}

function filter_func(entry) {
// ensure directories are +x
// https://github.com/mapnik/node-mapnik/issues/262
entry.props.mode |= (entry.props.mode >>> 2) & parseInt('0111',8);
log.info('install','unpacking ' + entry.path);
extractCount++;
}

gunzip.on('error', callback);
extracter.on('entry', filter_func);
extracter.on('error', callback);
extracter.on('end', afterTarball);

req.on('error', function(err) {
badDownload = true;
return callback(err);
Expand All @@ -121,7 +112,11 @@ function place_binary(from,to,opts,callback) {
return callback(err);
}
// start unzipping and untaring
req.pipe(gunzip).pipe(extracter);
req.pipe(tar.extract({
cwd: to,
strip: 1,
onentry: filter_func
}).on('close', afterTarball).on('error', callback));
});
});
}
Expand Down Expand Up @@ -190,25 +185,32 @@ function install(gyp, argv, callback) {
var from = opts.hosted_tarball;
var to = opts.module_path;
var binary_module = path.join(to,opts.module_name + '.node');
if (existsAsync(binary_module,function(found) {
existsAsync(binary_module,function(found) {
if (found && !update_binary) {
console.log('['+package_json.name+'] Success: "' + binary_module + '" already installed');
console.log('Pass --update-binary to reinstall or --build-from-source to recompile');
return callback();
} else {
if (!update_binary) log.info('check','checked for "' + binary_module + '" (not found)');
place_binary(from,to,opts,function(err) {
if (err && should_do_fallback_build) {
print_fallback_error(err,opts,package_json);
return do_build(gyp,argv,callback);
} else if (err) {
return callback(err);
mkdirp(to,function(err) {
if (err) {
after_place(err);
} else {
console.log('['+package_json.name+'] Success: "' + binary_module + '" is installed via remote');
return callback();
place_binary(from,to,opts,after_place);
}
});
}
}));
function after_place(err) {
if (err && should_do_fallback_build) {
print_fallback_error(err,opts,package_json);
return do_build(gyp,argv,callback);
} else if (err) {
return callback(err);
} else {
console.log('['+package_json.name+'] Success: "' + binary_module + '" is installed via remote');
return callback();
}
}
});
}
}
29 changes: 17 additions & 12 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ var napi = require('./util/napi.js');
var write = require('fs').createWriteStream;
var existsAsync = fs.exists || path.exists;
var mkdirp = require('mkdirp');
var tar = require('tar');

function _package(gyp, argv, callback) {
var pack = require('tar-pack').pack;
var packlist = require('npm-packlist');
var package_json = JSON.parse(fs.readFileSync('./package.json'));
var napi_build_version = napi.get_napi_build_version_from_command_args(argv);
var opts = versioning.evaluate(package_json, gyp.opts, napi_build_version);
Expand All @@ -32,17 +33,21 @@ function _package(gyp, argv, callback) {
return true;
};
mkdirp(path.dirname(tarball),function(err) {
if (err) throw err;
pack(from, { filter: filter_func })
.pipe(write(tarball))
.on('error', function(err) {
if (err) console.error('['+package_json.name+'] ' + err.message);
return callback(err);
})
.on('close', function() {
log.info('package','Binary staged at "' + tarball + '"');
return callback();
});
from = path.dirname(from);
if (err) return callback(err);
packlist({ path: from }).then(function(files) {
tar.create({
portable: true,
gzip: true,
onentry: filter_func,
file: tarball,
cwd: from
}, files, function(err) {
if (err) console.error('['+package_json.name+'] ' + err.message);
else log.info('package','Binary staged at "' + tarball + '"');
return callback(err);
});
}, callback);
});
});
}
34 changes: 19 additions & 15 deletions lib/testpackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var existsAsync = fs.exists || path.exists;
var versioning = require('./util/versioning.js');
var napi = require('./util/napi.js');
var testbinary = require('./testbinary.js');
var read = require('fs').createReadStream;
var zlib = require('zlib');
var tar = require('tar');
var mkdirp = require('mkdirp');

function testpackage(gyp, argv, callback) {
var package_json = JSON.parse(fs.readFileSync('./package.json'));
Expand All @@ -24,19 +24,24 @@ function testpackage(gyp, argv, callback) {
return callback(new Error("Cannot test package because " + tarball + " missing: run `node-pre-gyp package` first"));
}
var to = opts.module_path;
var gunzip = zlib.createGunzip();
var extracter = require('tar').Extract({ path: to, strip: 1 });
function filter_func(entry) {
// ensure directories are +x
// https://github.com/mapnik/node-mapnik/issues/262
entry.props.mode |= (entry.props.mode >>> 2) & parseInt('0111',8);
log.info('install','unpacking ' + entry.path);
log.info('install','unpacking [' + entry.path + ']');
}
gunzip.on('error', callback);
extracter.on('error', callback);
extracter.on('entry', filter_func);
extracter.on('end', function(err) {
if (err) return callback(err);

mkdirp(to, function(err) {
if (err) {
return callback(err);
} else {
tar.extract({
file: tarball,
cwd: to,
strip: 1,
onentry: filter_func
}).then(after_extract, callback);
}
});

function after_extract() {
testbinary(gyp,argv,function(err) {
if (err) {
return callback(err);
Expand All @@ -45,7 +50,6 @@ function testpackage(gyp, argv, callback) {
return callback();
}
});
});
read(tarball).pipe(gunzip).pipe(extracter);
}
});
}
Loading

0 comments on commit c31cce4

Please sign in to comment.