Skip to content

Commit

Permalink
fix(symlink-binary): Use Package.lazy() instead of private resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Dec 20, 2018
1 parent 858caf3 commit 83fe3ef
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 26 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions utils/symlink-binary/__tests__/symlink-binary.test.js
@@ -1,21 +1,18 @@
"use strict";

const path = require("path");
const readPkg = require("read-pkg");

const Package = require("@lerna/package");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const pkgMatchers = require("@lerna-test/pkg-matchers");

// file under test
const symlinkBinary = require("..");

expect.extend(pkgMatchers);
expect.extend(require("@lerna-test/pkg-matchers"));

describe("symlink-binary", () => {
it("should work with references", async () => {
it("should work with path references", async () => {
const testDir = await initFixture("links");
const srcPath = path.join(testDir, "packages/package-2");
const dstPath = path.join(testDir, "packages/package-3");
Expand All @@ -25,16 +22,12 @@ describe("symlink-binary", () => {
expect(dstPath).toHaveBinaryLinks("links-2");
});

it("should work with packages", async () => {
it("should work with Package instances", async () => {
const testDir = await initFixture("links");
const srcPath = path.join(testDir, "packages/package-2");
const dstPath = path.join(testDir, "packages/package-3");
const [srcJson, dstJson] = await Promise.all([
readPkg(srcPath, { normalize: false }),
readPkg(dstPath, { normalize: false }),
]);

await symlinkBinary(new Package(srcJson, srcPath), new Package(dstJson, dstPath));
await symlinkBinary(Package.lazy(srcPath), Package.lazy(dstPath));

expect(dstPath).toHaveBinaryLinks("links-2");
});
Expand Down
3 changes: 1 addition & 2 deletions utils/symlink-binary/package.json
Expand Up @@ -33,7 +33,6 @@
"@lerna/create-symlink": "file:../create-symlink",
"@lerna/package": "file:../../core/package",
"fs-extra": "^7.0.0",
"p-map": "^1.2.0",
"read-pkg": "^3.0.0"
"p-map": "^1.2.0"
}
}
12 changes: 1 addition & 11 deletions utils/symlink-binary/symlink-binary.js
Expand Up @@ -3,7 +3,6 @@
const fs = require("fs-extra");
const path = require("path");
const pMap = require("p-map");
const readPkg = require("read-pkg");

const Package = require("@lerna/package");
const createSymlink = require("@lerna/create-symlink");
Expand All @@ -17,7 +16,7 @@ module.exports = symlinkBinary;
* @returns {Promise}
*/
function symlinkBinary(srcPackageRef, destPackageRef) {
return Promise.all([resolvePackageRef(srcPackageRef), resolvePackageRef(destPackageRef)]).then(
return Promise.all([Package.lazy(srcPackageRef), Package.lazy(destPackageRef)]).then(
([srcPackage, destPackage]) => {
const actions = Object.keys(srcPackage.bin).map(name => {
const src = path.join(srcPackage.location, srcPackage.bin[name]);
Expand All @@ -44,12 +43,3 @@ function symlinkBinary(srcPackageRef, destPackageRef) {
}
);
}

function resolvePackageRef(pkgRef) {
// don't use instanceof because it fails across nested module boundaries
if (typeof pkgRef !== "string" && pkgRef.location) {
return pkgRef;
}

return readPkg(pkgRef, { normalize: false }).then(json => new Package(json, pkgRef));
}

0 comments on commit 83fe3ef

Please sign in to comment.