Skip to content

Commit 60d1100

Browse files
committed
fix(deps): Switch to actively-maintained @zkochan/cmd-shim
This addresses a bug with missing link sources on Windows, among other things.
1 parent f25854d commit 60d1100

File tree

6 files changed

+71
-31
lines changed

6 files changed

+71
-31
lines changed

helpers/pkg-matchers/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22

33
const fs = require("fs");
4-
const os = require("os");
54
const path = require("path");
65
const semver = require("semver");
76
const Package = require("@lerna/package");
@@ -81,8 +80,18 @@ function createDependencyMatcher(dependencyType) {
8180
function toHaveBinaryLinks(received, ...inputs) {
8281
const pkg = Package.lazy(received);
8382
const links =
84-
os.platform() === "win32"
85-
? inputs.reduce((acc, input) => [...acc, input, [input, "cmd"].join(".")], [])
83+
process.platform === "win32"
84+
? inputs.reduce(
85+
(acc, input) => [
86+
...acc,
87+
input,
88+
// cmd.exe
89+
[input, "cmd"].join("."),
90+
// powershell
91+
[input, "ps1"].join("."),
92+
],
93+
[]
94+
)
8695
: inputs;
8796

8897
const expectedName = `expected ${pkg.name}`;

package-lock.json

Lines changed: 50 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@lerna-test/show-commit": "file:helpers/show-commit",
5757
"@lerna-test/silence-logging": "file:helpers/silence-logging",
5858
"@lerna-test/update-lerna-config": "file:helpers/update-lerna-config",
59+
"@zkochan/cmd-shim": "^3.1.0",
5960
"camelcase": "^5.3.1",
6061
"debug": "^4.1.1",
6162
"eslint": "^5.16.0",

utils/create-symlink/__tests__/create-symlink.test.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"use strict";
22

3-
jest.mock("cmd-shim");
3+
jest.mock("@zkochan/cmd-shim");
44
jest.mock("fs-extra");
55

6-
const cmdShim = require("cmd-shim");
6+
const cmdShim = require("@zkochan/cmd-shim");
77
const fs = require("fs-extra");
88
const path = require("path");
9-
const callsBack = require("@lerna-test/calls-back");
109
const createSymlink = require("..");
1110

1211
const linkRelative = (from, to) => path.relative(path.dirname(to), from);
@@ -16,8 +15,7 @@ describe("create-symlink", () => {
1615
fs.unlink.mockResolvedValue();
1716
fs.symlink.mockResolvedValue();
1817
fs.pathExists.mockResolvedValue(true);
19-
// cmdShim is a traditional errback
20-
cmdShim.mockImplementation(callsBack());
18+
cmdShim.mockResolvedValue();
2119

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

6563
expect(fs.lstat).not.toHaveBeenCalled();
66-
expect(cmdShim).toHaveBeenLastCalledWith(src, dst, expect.any(Function));
64+
expect(cmdShim).toHaveBeenLastCalledWith(src, dst);
6765
});
6866

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

7270
try {
7371
await createSymlink("src", "dst", "exec");

utils/create-symlink/create-symlink.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
const cmdShim = require("cmd-shim");
3+
const cmdShim = require("@zkochan/cmd-shim");
44
const fs = require("fs-extra");
55
const log = require("npmlog");
66
const path = require("path");
@@ -49,15 +49,7 @@ function createPosixSymlink(origin, dest, _type) {
4949

5050
function createWindowsSymlink(src, dest, type) {
5151
if (type === "exec") {
52-
return new Promise((resolve, reject) => {
53-
cmdShim(src, dest, err => {
54-
if (err) {
55-
reject(err);
56-
} else {
57-
resolve();
58-
}
59-
});
60-
});
52+
return cmdShim(src, dest);
6153
}
6254

6355
return createSymbolicLink(src, dest, type);

utils/create-symlink/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"test": "echo \"Run tests from root\" && exit 1"
3232
},
3333
"dependencies": {
34-
"cmd-shim": "^2.0.2",
34+
"@zkochan/cmd-shim": "^3.1.0",
3535
"fs-extra": "^8.1.0",
3636
"npmlog": "^4.1.2"
3737
}

0 commit comments

Comments
 (0)