Skip to content

Commit e9fb2e5

Browse files
authored
Merge pull request #299 from isaacs/master
Upgrade to tar version 3
2 parents e7bb6cd + 81f2e60 commit e9fb2e5

File tree

6 files changed

+76
-73
lines changed

6 files changed

+76
-73
lines changed

appveyor.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,9 @@ install:
1717
- ps: Install-Product node $env:nodejs_version $env:Platform
1818
- ps: Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
1919
- npm config get
20-
# upgrade node-gyp to dodge 2013 compile issue present in the node gyp bundled with node v0.10
21-
# https://github.com/nodejs/node-gyp/issues/972#issuecomment-231055109
22-
# but we upgrade using my fork since 3.x upstream will now break node v0.10.x support
23-
- IF "%nodejs_version:~0,1%"=="0" npm install https://github.com/springmeyer/node-gyp/tarball/v3.x
2420
# upgrade node-gyp to dodge https://github.com/mapbox/node-pre-gyp/issues/209#issuecomment-307641388
2521
# and allow make node 4.x x86 builds work
26-
# https://github.com/mapbox/node-pre-gyp/issues/209#issuecomment-217690537
27-
- IF "%nodejs_version:~0,1%"=="4" npm install [email protected]
28-
# downgrade npm to avoid multiple npm bugs:
29-
# 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)
30-
# 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
31-
# for node v8 this dodges https://github.com/mapbox/node-pre-gyp/issues/302
32-
- npm install [email protected] -g
22+
- IF "%nodejs_version:~0,1%" EQU "4" npm install [email protected]
3323
- node --version
3424
- npm --version
3525
- node -e "console.log(process.arch);"
@@ -38,8 +28,10 @@ install:
3828
- IF /I "%PLATFORM%" == "x64" CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
3929
- IF /I "%PLATFORM%" == "x86" CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
4030
- npm install
31+
# workaround https://github.com/mapbox/node-pre-gyp/issues/300#issuecomment-328179994
32+
- IF "%nodejs_version:~0,1%" GEQ "6" npm install npm@2 -g
4133
- npm test
4234

4335
build: off
4436
test: off
45-
deploy: off
37+
deploy: off

lib/install.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ exports.usage = 'Attempts to install pre-built binary for module';
66

77
var fs = require('fs');
88
var path = require('path');
9-
var zlib = require('zlib');
109
var log = require('npmlog');
1110
var existsAsync = fs.exists || path.exists;
1211
var versioning = require('./util/versioning.js');
12+
var mkdirp = require('mkdirp');
1313

1414
var npgVersion = 'unknown';
1515
try {
@@ -75,8 +75,7 @@ function place_binary(from,to,opts,callback) {
7575
if (!req) return callback(new Error("empty req"));
7676
var badDownload = false;
7777
var extractCount = 0;
78-
var gunzip = zlib.createGunzip();
79-
var extracter = require('tar').Extract({ path: to, strip: 1});
78+
var tar = require('tar');
8079

8180
function afterTarball(err) {
8281
if (err) return callback(err);
@@ -89,18 +88,10 @@ function place_binary(from,to,opts,callback) {
8988
}
9089

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

99-
gunzip.on('error', callback);
100-
extracter.on('entry', filter_func);
101-
extracter.on('error', callback);
102-
extracter.on('end', afterTarball);
103-
10495
req.on('error', function(err) {
10596
badDownload = true;
10697
return callback(err);
@@ -120,7 +111,11 @@ function place_binary(from,to,opts,callback) {
120111
return callback(err);
121112
}
122113
// start unzipping and untaring
123-
req.pipe(gunzip).pipe(extracter);
114+
req.pipe(tar.extract({
115+
cwd: to,
116+
strip: 1,
117+
onentry: filter_func
118+
}).on('close', afterTarball).on('error', callback));
124119
});
125120
});
126121
}
@@ -187,25 +182,32 @@ function install(gyp, argv, callback) {
187182
var from = opts.hosted_tarball;
188183
var to = opts.module_path;
189184
var binary_module = path.join(to,opts.module_name + '.node');
190-
if (existsAsync(binary_module,function(found) {
185+
existsAsync(binary_module,function(found) {
191186
if (found && !update_binary) {
192187
console.log('['+package_json.name+'] Success: "' + binary_module + '" already installed');
193188
console.log('Pass --update-binary to reinstall or --build-from-source to recompile');
194189
return callback();
195190
} else {
196191
if (!update_binary) log.info('check','checked for "' + binary_module + '" (not found)');
197-
place_binary(from,to,opts,function(err) {
198-
if (err && should_do_fallback_build) {
199-
print_fallback_error(err,opts,package_json);
200-
return do_build(gyp,argv,callback);
201-
} else if (err) {
202-
return callback(err);
192+
mkdirp(to,function(err) {
193+
if (err) {
194+
after_place(err);
203195
} else {
204-
console.log('['+package_json.name+'] Success: "' + binary_module + '" is installed via remote');
205-
return callback();
196+
place_binary(from,to,opts,after_place);
206197
}
207198
});
208199
}
209-
}));
200+
function after_place(err) {
201+
if (err && should_do_fallback_build) {
202+
print_fallback_error(err,opts,package_json);
203+
return do_build(gyp,argv,callback);
204+
} else if (err) {
205+
return callback(err);
206+
} else {
207+
console.log('['+package_json.name+'] Success: "' + binary_module + '" is installed via remote');
208+
return callback();
209+
}
210+
}
211+
});
210212
}
211213
}

lib/package.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ var fs = require('fs');
88
var path = require('path');
99
var log = require('npmlog');
1010
var versioning = require('./util/versioning.js');
11-
var write = require('fs').createWriteStream;
1211
var existsAsync = fs.exists || path.exists;
1312
var mkdirp = require('mkdirp');
13+
var tar = require('tar');
1414

1515
function _package(gyp, argv, callback) {
16-
var pack = require('tar-pack').pack;
16+
var packlist = require('npm-packlist');
1717
var package_json = JSON.parse(fs.readFileSync('./package.json'));
1818
var opts = versioning.evaluate(package_json, gyp.opts);
1919
var from = opts.module_path;
@@ -30,17 +30,21 @@ function _package(gyp, argv, callback) {
3030
return true;
3131
};
3232
mkdirp(path.dirname(tarball),function(err) {
33-
if (err) throw err;
34-
pack(from, { filter: filter_func })
35-
.pipe(write(tarball))
36-
.on('error', function(err) {
37-
if (err) console.error('['+package_json.name+'] ' + err.message);
38-
return callback(err);
39-
})
40-
.on('close', function() {
41-
log.info('package','Binary staged at "' + tarball + '"');
42-
return callback();
43-
});
33+
from = path.dirname(from);
34+
if (err) return callback(err);
35+
packlist({ path: from }).then(function(files) {
36+
tar.create({
37+
portable: true,
38+
gzip: true,
39+
onentry: filter_func,
40+
file: tarball,
41+
cwd: from
42+
}, files, function(err) {
43+
if (err) console.error('['+package_json.name+'] ' + err.message);
44+
else log.info('package','Binary staged at "' + tarball + '"');
45+
return callback(err);
46+
});
47+
}, callback);
4448
});
4549
});
4650
}

lib/testpackage.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ var log = require('npmlog');
1010
var existsAsync = fs.exists || path.exists;
1111
var versioning = require('./util/versioning.js');
1212
var testbinary = require('./testbinary.js');
13-
var read = require('fs').createReadStream;
14-
var zlib = require('zlib');
13+
var tar = require('tar');
14+
var mkdirp = require('mkdirp');
1515

1616
function testpackage(gyp, argv, callback) {
1717
var package_json = JSON.parse(fs.readFileSync('./package.json'));
@@ -22,19 +22,24 @@ function testpackage(gyp, argv, callback) {
2222
return callback(new Error("Cannot test package because " + tarball + " missing: run `node-pre-gyp package` first"));
2323
}
2424
var to = opts.module_path;
25-
var gunzip = zlib.createGunzip();
26-
var extracter = require('tar').Extract({ path: to, strip: 1 });
2725
function filter_func(entry) {
28-
// ensure directories are +x
29-
// https://github.com/mapnik/node-mapnik/issues/262
30-
entry.props.mode |= (entry.props.mode >>> 2) & parseInt('0111',8);
31-
log.info('install','unpacking ' + entry.path);
26+
log.info('install','unpacking [' + entry.path + ']');
3227
}
33-
gunzip.on('error', callback);
34-
extracter.on('error', callback);
35-
extracter.on('entry', filter_func);
36-
extracter.on('end', function(err) {
37-
if (err) return callback(err);
28+
29+
mkdirp(to, function(err) {
30+
if (err) {
31+
return callback(err);
32+
} else {
33+
tar.extract({
34+
file: tarball,
35+
cwd: to,
36+
strip: 1,
37+
onentry: filter_func
38+
}).then(after_extract, callback);
39+
}
40+
});
41+
42+
function after_extract() {
3843
testbinary(gyp,argv,function(err) {
3944
if (err) {
4045
return callback(err);
@@ -43,7 +48,6 @@ function testpackage(gyp, argv, callback) {
4348
return callback();
4449
}
4550
});
46-
});
47-
read(tarball).pipe(gunzip).pipe(extracter);
51+
}
4852
});
4953
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,21 @@
2222
"dependencies": {
2323
"mkdirp": "^0.5.1",
2424
"nopt": "^4.0.1",
25+
"npm-packlist": "^1.1.6",
2526
"npmlog": "^4.0.2",
2627
"rc": "^1.1.7",
2728
"request": "2.83.0",
2829
"rimraf": "^2.6.1",
2930
"semver": "^5.3.0",
30-
"detect-libc": "^1.0.2",
31-
"tar": "^2.2.1",
32-
"tar-pack": "^3.4.0"
31+
"tar": "^4"
32+
"detect-libc": "^1.0.2"
3333
},
3434
"devDependencies": {
3535
"tape": "^4.6.3",
3636
"aws-sdk": "^2.28.0",
3737
"retire": "^1.2.12",
38-
"jshint": "^2.9.4"
38+
"jshint": "^2.9.4",
39+
"tape": "^4.6.3"
3940
},
4041
"jshintConfig": {
4142
"node": true,

test/app1/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
22
"name": "node-pre-gyp-test-app1",
33
"author": "Dane Springmeyer <springmeyer>",
4-
"description":"node-pre-gyp test",
5-
"repository" : {
6-
"type" : "git",
7-
"url" : "git://github.com/mapbox/node-pre-gyp.git"
4+
"description": "node-pre-gyp test",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/mapbox/node-pre-gyp.git"
88
},
99
"license": "BSD-3-Clause",
1010
"version": "0.1.0",
1111
"main": "./index.js",
1212
"binary": {
1313
"module_name": "app1",
1414
"module_path": "./lib/binding/",
15-
"host":"https://node-pre-gyp-tests.s3-us-west-1.amazonaws.com"
15+
"host": "https://node-pre-gyp-tests.s3-us-west-1.amazonaws.com"
1616
},
1717
"scripts": {
18-
"install":"node-pre-gyp install --fallback-to-build",
19-
"test":"node index.js"
18+
"install": "node-pre-gyp install --fallback-to-build",
19+
"test": "node index.js"
2020
}
2121
}

0 commit comments

Comments
 (0)