Skip to content

Commit

Permalink
fix(BootstrapCommand): symlink binaries of scoped packages correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur authored Apr 6, 2017
1 parent 2be31cd commit e4b9454
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/commands/BootstrapCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,20 @@ export default class BootstrapCommand extends Command {
* @param {Function} callback
*/
createBinaryLink(src, dest, name, bin, callback) {
const safeName = name[0] === "@"
? name.substring(name.indexOf("/") + 1)
: name;
const destBinFolder = path.join(dest, ".bin");
// The `bin` in a package.json may be either a string or an object.
// Normalize to an object.
const bins = typeof bin === "string"
? { [name]: bin }
? { [safeName]: bin }
: bin;
const srcBinFiles = [];
const destBinFiles = [];
Object.keys(bins).forEach((name) => {
srcBinFiles.push(path.join(src, bins[name]));
destBinFiles.push(path.join(destBinFolder, name));
Object.keys(bins).forEach((binName) => {
srcBinFiles.push(path.join(src, bins[binName]));
destBinFiles.push(path.join(destBinFolder, binName));
});
// make sure when have a destination folder (node_modules/.bin)
const actions = [(cb) => FileSystemUtilities.mkdirp(destBinFolder, cb)];
Expand Down
4 changes: 2 additions & 2 deletions test/BootstrapCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe("BootstrapCommand", () => {
"package-1 should be symlinked to package-3"
);
assert.equal(
normalize(resolveSymlink(path.join(testDir, "packages", "package-3", "node_modules", "package-2"))),
normalize(resolveSymlink(path.join(testDir, "packages", "package-3", "node_modules", "@test", "package-2"))),
normalize(path.join(testDir, "packages", "package-2")),
"package-2 should be symlinked to package-3"
);
Expand Down Expand Up @@ -342,7 +342,7 @@ describe("BootstrapCommand", () => {
"package-1 should be symlinked to package-3"
);
assert.equal(
normalize(resolveSymlink(path.join(testDir, "packages", "package-3", "node_modules", "package-2"))),
normalize(resolveSymlink(path.join(testDir, "packages", "package-3", "node_modules", "@test", "package-2"))),
normalize(path.join(testDir, "packages", "package-2")),
"package-2 should be symlinked to package-3"
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "package-2",
"name": "@test/package-2",
"version": "1.0.0",
"bin": "cli.js",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"devDependencies": {
"@test/package-1": "^1.0.0",
"package-2": "^1.0.0",
"@test/package-2": "^1.0.0",
"foo": "0.1.12"
}
}

0 comments on commit e4b9454

Please sign in to comment.