Last change
on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
817 bytes
|
Line | |
---|
1 | // Function to determine whether a path is in the package.bin set.
|
---|
2 | // Used to prevent issues when people publish a package from a
|
---|
3 | // windows machine, and then install with --no-bin-links.
|
---|
4 | //
|
---|
5 | // Note: this is not possible in remote or file fetchers, since
|
---|
6 | // we don't have the manifest until AFTER we've unpacked. But the
|
---|
7 | // main use case is registry fetching with git a distant second,
|
---|
8 | // so that's an acceptable edge case to not handle.
|
---|
9 |
|
---|
10 | const binObj = (name, bin) =>
|
---|
11 | typeof bin === 'string' ? { [name]: bin } : bin
|
---|
12 |
|
---|
13 | const hasBin = (pkg, path) => {
|
---|
14 | const bin = binObj(pkg.name, pkg.bin)
|
---|
15 | const p = path.replace(/^[^\\\/]*\//, '')
|
---|
16 | for (const [k, v] of Object.entries(bin)) {
|
---|
17 | if (v === p)
|
---|
18 | return true
|
---|
19 | }
|
---|
20 | return false
|
---|
21 | }
|
---|
22 |
|
---|
23 | module.exports = (pkg, path) =>
|
---|
24 | pkg && pkg.bin ? hasBin(pkg, path) : false
|
---|
Note:
See
TracBrowser
for help on using the repository browser.