Skip to content

Commit

Permalink
fix: -0 bug described in issue #33
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhleung committed Aug 2, 2018
1 parent ac7e6c6 commit a671eca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
/lib/
/test/

# Sandbox (for tests)
fixtures/sandbox/node_modules/*


## From https://raw.githubusercontent.com/github/gitignore/master/Node.gitignore
# Logs
logs
Expand Down
13 changes: 12 additions & 1 deletion src/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spawn } from "child_process";
import path from "path";
import test from "tape";

/**
Expand All @@ -9,14 +10,16 @@ import test from "tape";
function spawnCli(extraArgs) {
return spawn(
"node",
["--require", "babel-register", "cli.js"].concat(extraArgs)
["--require", "babel-register", "cli.js"].concat(extraArgs),
{ cwd: path.join(__dirname, "..", "fixtures", "sandbox") }
);
}

/**
* Gets the resulting install command given the provided arguments
* @async
* @param {string[]} extraArgs - arguments to be passed to the CLI
* @param {boolean} noDryRun - whether to actually run the command or not
* @returns {Promise<string>} - a Promise which resolves to the resulting install command
*/
async function getCliInstallCommand(extraArgs) {
Expand Down Expand Up @@ -83,6 +86,14 @@ test("adds an explicit `--no-save` when using `--silent` with NPM", t => {
}, t.fail);
});

test("installs packages correctly even if package name ends with '-0'", t => {
const cli = spawnCli("enzyme-adapter-react-16@1.1.1");
cli.on("exit", code => {
t.equal(code, 0, `errored, exit code was ${code}`);
t.end();
});
});

// @todo - tests for the actual install process
// see https://github.com/sindresorhus/has-yarn/blob/master/test.js for details
// Perhaps abstract the functionality of getting the package name
Expand Down
10 changes: 9 additions & 1 deletion src/install-peerdeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,18 @@ function installPeerDeps(
// I know I can push it, but I'll just
// keep concatenating for consistency
args = args.concat(subcommand);
// See issue #33 - issue with "-0"
function fixPackageName(packageName) {
if (packageName.substr(-2) === "-0") {
// Remove -0
return packageName.substr(0, packageName.length - 2);
}
return packageName;
}
// If we have spaces in our args spawn()
// cries foul so we'll split the packagesString
// into an array of individual packages
args = args.concat(packagesString.split(" "));
args = args.concat(packagesString.split(" ").map(fixPackageName));
// If devFlag is empty, then we'd be adding an empty arg
// That causes the command to fail
if (devFlag !== "") {
Expand Down

0 comments on commit a671eca

Please sign in to comment.