-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pack and unpack preserving exec perms on all package bins
This addresses the problem brought up by @boneskull on isaacs/node-tar#210 (comment) If a package is created on a Windows system, the file will not have the executable bit set, as Windows determines executable status by the filename extension. Thus, installing with '--no-bin-links' produces a package that can't be used as expected. This change does the following: - While extracting, if the manifest has been loaded, then the mode of any bin targets is made executable. - If the manifest is not loaded, then AFTER extraction, the mode of all bin targets is set appropriately. (Only relevant for the FileFetcher class, as the others will all have access to the manifest earlier in the process.) - When packing, all bin targets are given an executable mode in the archive. Thus, newer npm will properly handle archives created without proper modes, and will always produce proper modes for the benefit of other/older clients regardless of what fs.stat says. Strict in what we publish, liberal in what we install.
- Loading branch information
Showing
23 changed files
with
228 additions
and
18 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
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
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
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,24 @@ | ||
// Function to determine whether a path is in the package.bin set. | ||
// Used to prevent issues when people publish a package from a | ||
// windows machine, and then install with --no-bin-links. | ||
// | ||
// Note: this is not possible in remote or file fetchers, since | ||
// we don't have the manifest until AFTER we've unpacked. But the | ||
// main use case is registry fetching with git a distant second, | ||
// so that's an acceptable edge case to not handle. | ||
|
||
const binObj = (name, bin) => | ||
typeof bin === 'string' ? { [name]: bin } : bin | ||
|
||
const hasBin = (pkg, path) => { | ||
const bin = binObj(pkg.name, pkg.bin) | ||
const p = path.replace(/^[^\\\/]*\//, '') | ||
for (const [k, v] of Object.entries(bin)) { | ||
if (v === p) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
module.exports = (pkg, path) => | ||
pkg && pkg.bin ? hasBin(pkg, path) : false |
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
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,13 @@ | ||
/* IMPORTANT | ||
* This snapshot file is auto-generated, but designed for humans. | ||
* It should be checked into source control and tracked carefully. | ||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests. | ||
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[`test/fetcher.js TAP make bins executable > results of unpack 1`] = ` | ||
Object { | ||
"integrity": "sha512-TqzCjecWyQe8vqLbT0nv/OaWf0ptRZ2DnPmiuGUYJJb70shp02+/uu37IJSkM2ZEP1SAOeKrYrWPVIIYW+d//g==", | ||
"resolved": "{CWD}/test/fixtures/bin-object.tgz", | ||
} | ||
` |
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,13 @@ | ||
/* IMPORTANT | ||
* This snapshot file is auto-generated, but designed for humans. | ||
* It should be checked into source control and tracked carefully. | ||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests. | ||
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[`test/fetcher.js fake-sudo TAP make bins executable > results of unpack 1`] = ` | ||
Object { | ||
"integrity": "sha512-TqzCjecWyQe8vqLbT0nv/OaWf0ptRZ2DnPmiuGUYJJb70shp02+/uu37IJSkM2ZEP1SAOeKrYrWPVIIYW+d//g==", | ||
"resolved": "{CWD}/test/fixtures/bin-object.tgz", | ||
} | ||
` |
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
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
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
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
Binary file not shown.
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 @@ | ||
{"name":"bin-object","version":"1.2.3","bin":{"bin-object":"script.js"}} |
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 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs') | ||
const assert = require('assert') | ||
assert.equal(fs.statSync(__filename).mode & 0o111, 0o111) | ||
console.log('ok') |
Binary file not shown.
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 @@ | ||
{"name":"bin-string","version":"1.2.3","bin":"script.js"} |
Binary file not shown.
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 @@ | ||
{"name":"bin-object","version":"1.2.3","bin":{"bin-object":"script.js"}} |
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 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs') | ||
const assert = require('assert') | ||
assert.equal(fs.statSync(__filename).mode & 0o111, 0o111) | ||
console.log('ok') |
Binary file not shown.
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 @@ | ||
{"name":"bin-string","version":"1.2.3","bin":"script.js"} |
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 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs') | ||
const assert = require('assert') | ||
assert.equal(fs.statSync(__filename).mode & 0o111, 0o111) | ||
console.log('ok') |
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,8 @@ | ||
const isPackageBin = require('../../lib/util/is-package-bin.js') | ||
const t = require('tap') | ||
|
||
t.ok(isPackageBin({bin:'foo'}, 'package/foo'), 'finds string') | ||
t.ok(isPackageBin({bin:{bar:'foo'}}, 'package/foo'), 'finds in obj') | ||
t.notOk(isPackageBin(null, 'anything'), 'return false if pkg is not') | ||
t.notOk(isPackageBin({bin:'foo'}, 'package/bar'), 'not the bin string') | ||
t.notOk(isPackageBin({bin:{bar:'foo'}}, 'package/bar'), 'not in obj') |