Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: handle empty bin strings #6515

Merged
merged 4 commits into from Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa

## Master

- Fixes handling of empty string entries for bin in package.json

[#6515](https://github.com/yarnpkg/yarn/pull/6515) - [**Ryan Burrows**](https://github.com/rhburrows)

- Adds support for basic auth for registries with paths, such as artifactory

[#5322](https://github.com/yarnpkg/yarn/pull/5322) - [**Karolis Narkevicius**](https://twitter.com/KidkArolis)
Expand Down
6 changes: 6 additions & 0 deletions __tests__/__snapshots__/normalize-manifest.js.snap
Expand Up @@ -90,6 +90,12 @@ Array [
]
`;

exports[`empty bin string: empty bin string 1`] = `
Array [
"foo: No license field",
]
`;

exports[`engines array: engines array 1`] = `
Array [
"No license field",
Expand Down
10 changes: 10 additions & 0 deletions __tests__/commands/install/bin-links.js
Expand Up @@ -175,6 +175,16 @@ test('can use link protocol to install a package that would not be found via nod
});
});

test('empty bin string does not create a link', (): Promise<void> => {
return runInstall({binLinks: true}, 'install-empty-bin', async config => {
const binScripts = await fs.walk(path.join(config.cwd, 'node_modules', '.bin'));
const linkCount = process.platform === 'win32' ? 2 : 1;
expect(binScripts).toHaveLength(linkCount);

expect(await linkAt(config, 'node_modules', '.bin', 'depB')).toEqual('../depB/depb.js');
});
});

describe('with nohoist', () => {
// address https://github.com/yarnpkg/yarn/issues/5487
test('nohoist bin should be linked to its own local module', (): Promise<void> => {
Expand Down
@@ -0,0 +1,5 @@
{
"name": "depA",
"version": "0.0.0",
"bin": ""
}
2 changes: 2 additions & 0 deletions __tests__/fixtures/install/install-empty-bin/depB/depb.js
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log('depB');
@@ -0,0 +1,5 @@
{
"name": "depB",
"version": "0.0.0",
"bin": "./depb.js"
}
9 changes: 9 additions & 0 deletions __tests__/fixtures/install/install-empty-bin/package.json
@@ -0,0 +1,9 @@
{
"name": "test",
"version": "0.0.0",
"bin": "",
"dependencies": {
"depA": "file:depA",
"depB": "file:depB"
}
}
@@ -0,0 +1,4 @@
{
"name": "foo",
"bin": ""
}
@@ -0,0 +1,5 @@
{
"name": "foo",
"version": "",
"bin": ""
}
2 changes: 1 addition & 1 deletion src/util/normalize-manifest/fix.js
Expand Up @@ -153,7 +153,7 @@ export default (async function(
// if the `bin` field is as string then expand it to an object with a single property
// based on the original `bin` field and `name field`
// { name: "foo", bin: "cli.js" } -> { name: "foo", bin: { foo: "cli.js" } }
if (typeof info.name === 'string' && typeof info.bin === 'string') {
if (typeof info.name === 'string' && typeof info.bin === 'string' && info.bin.length > 0) {
// Remove scoped package name for consistency with NPM's bin field fixing behaviour
const name = info.name.replace(/^@[^\/]+\//, '');
info.bin = {[name]: info.bin};
Expand Down