Skip to content

Commit

Permalink
fix(deps): Switch to actively-maintained @zkochan/cmd-shim
Browse files Browse the repository at this point in the history
This addresses a bug with missing link sources on Windows, among other things.
  • Loading branch information
evocateur committed Jul 22, 2019
1 parent f25854d commit 60d1100
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 31 deletions.
15 changes: 12 additions & 3 deletions helpers/pkg-matchers/index.js
@@ -1,7 +1,6 @@
"use strict";

const fs = require("fs");
const os = require("os");
const path = require("path");
const semver = require("semver");
const Package = require("@lerna/package");
Expand Down Expand Up @@ -81,8 +80,18 @@ function createDependencyMatcher(dependencyType) {
function toHaveBinaryLinks(received, ...inputs) {
const pkg = Package.lazy(received);
const links =
os.platform() === "win32"
? inputs.reduce((acc, input) => [...acc, input, [input, "cmd"].join(".")], [])
process.platform === "win32"
? inputs.reduce(
(acc, input) => [
...acc,
input,
// cmd.exe
[input, "cmd"].join("."),
// powershell
[input, "ps1"].join("."),
],
[]
)
: inputs;

const expectedName = `expected ${pkg.name}`;
Expand Down
60 changes: 50 additions & 10 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -56,6 +56,7 @@
"@lerna-test/show-commit": "file:helpers/show-commit",
"@lerna-test/silence-logging": "file:helpers/silence-logging",
"@lerna-test/update-lerna-config": "file:helpers/update-lerna-config",
"@zkochan/cmd-shim": "^3.1.0",
"camelcase": "^5.3.1",
"debug": "^4.1.1",
"eslint": "^5.16.0",
Expand Down
12 changes: 5 additions & 7 deletions utils/create-symlink/__tests__/create-symlink.test.js
@@ -1,12 +1,11 @@
"use strict";

jest.mock("cmd-shim");
jest.mock("@zkochan/cmd-shim");
jest.mock("fs-extra");

const cmdShim = require("cmd-shim");
const cmdShim = require("@zkochan/cmd-shim");
const fs = require("fs-extra");
const path = require("path");
const callsBack = require("@lerna-test/calls-back");
const createSymlink = require("..");

const linkRelative = (from, to) => path.relative(path.dirname(to), from);
Expand All @@ -16,8 +15,7 @@ describe("create-symlink", () => {
fs.unlink.mockResolvedValue();
fs.symlink.mockResolvedValue();
fs.pathExists.mockResolvedValue(true);
// cmdShim is a traditional errback
cmdShim.mockImplementation(callsBack());
cmdShim.mockResolvedValue();

if (process.platform !== "win32") {
it("creates relative symlink to a directory", async () => {
Expand Down Expand Up @@ -63,11 +61,11 @@ describe("create-symlink", () => {
await createSymlink(src, dst, type);

expect(fs.lstat).not.toHaveBeenCalled();
expect(cmdShim).toHaveBeenLastCalledWith(src, dst, expect.any(Function));
expect(cmdShim).toHaveBeenLastCalledWith(src, dst);
});

it("rejects when cmd-shim errors", async () => {
cmdShim.mockImplementationOnce(callsBack(new Error("yikes")));
cmdShim.mockImplementationOnce(() => Promise.reject(new Error("yikes")));

try {
await createSymlink("src", "dst", "exec");
Expand Down
12 changes: 2 additions & 10 deletions utils/create-symlink/create-symlink.js
@@ -1,6 +1,6 @@
"use strict";

const cmdShim = require("cmd-shim");
const cmdShim = require("@zkochan/cmd-shim");
const fs = require("fs-extra");
const log = require("npmlog");
const path = require("path");
Expand Down Expand Up @@ -49,15 +49,7 @@ function createPosixSymlink(origin, dest, _type) {

function createWindowsSymlink(src, dest, type) {
if (type === "exec") {
return new Promise((resolve, reject) => {
cmdShim(src, dest, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
return cmdShim(src, dest);
}

return createSymbolicLink(src, dest, type);
Expand Down
2 changes: 1 addition & 1 deletion utils/create-symlink/package.json
Expand Up @@ -31,7 +31,7 @@
"test": "echo \"Run tests from root\" && exit 1"
},
"dependencies": {
"cmd-shim": "^2.0.2",
"@zkochan/cmd-shim": "^3.1.0",
"fs-extra": "^8.1.0",
"npmlog": "^4.1.2"
}
Expand Down

0 comments on commit 60d1100

Please sign in to comment.