From 60d1100a559f13b617c06714bc5283054270d3b6 Mon Sep 17 00:00:00 2001 From: Daniel Stockman Date: Fri, 19 Jul 2019 11:23:19 -0700 Subject: [PATCH] fix(deps): Switch to actively-maintained `@zkochan/cmd-shim` This addresses a bug with missing link sources on Windows, among other things. --- helpers/pkg-matchers/index.js | 15 ++++- package-lock.json | 60 +++++++++++++++---- package.json | 1 + .../__tests__/create-symlink.test.js | 12 ++-- utils/create-symlink/create-symlink.js | 12 +--- utils/create-symlink/package.json | 2 +- 6 files changed, 71 insertions(+), 31 deletions(-) diff --git a/helpers/pkg-matchers/index.js b/helpers/pkg-matchers/index.js index 8c9cfa4ddb..b0ab95444f 100644 --- a/helpers/pkg-matchers/index.js +++ b/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"); @@ -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}`; diff --git a/package-lock.json b/package-lock.json index f2e9f26ebd..25ef2545ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -937,7 +937,7 @@ "@lerna/create-symlink": { "version": "file:utils/create-symlink", "requires": { - "cmd-shim": "^2.0.2", + "@zkochan/cmd-shim": "^3.1.0", "fs-extra": "^8.1.0", "npmlog": "^4.1.2" } @@ -1585,6 +1585,16 @@ "integrity": "sha512-SOhuU4wNBxhhTHxYaiG5NY4HBhDIDnJF60GU+2LqHAdKKer86//e4yg69aENCtQ04n0ovz+tq2YPME5t5yp4pw==", "dev": true }, + "@zkochan/cmd-shim": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@zkochan/cmd-shim/-/cmd-shim-3.1.0.tgz", + "integrity": "sha512-o8l0+x7C7sMZU3v9GuJIAU10qQLtwR1dtRQIOmlNMtyaqhmpXOzx1HWiYoWfmmf9HHZoAkXpc9TM9PQYF9d4Jg==", + "requires": { + "is-windows": "^1.0.0", + "mkdirp-promise": "^5.0.1", + "mz": "^2.5.0" + } + }, "JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", @@ -1678,6 +1688,11 @@ "color-convert": "^1.9.0" } }, + "any-promise": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", + "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=" + }, "anymatch": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz", @@ -2269,15 +2284,6 @@ "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=" }, - "cmd-shim": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/cmd-shim/-/cmd-shim-2.0.2.tgz", - "integrity": "sha1-b8vamUg6j9FdfTChlspp1oii79s=", - "requires": { - "graceful-fs": "^4.1.2", - "mkdirp": "~0.5.0" - } - }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -6485,6 +6491,14 @@ "minimist": "0.0.8" } }, + "mkdirp-promise": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/mkdirp-promise/-/mkdirp-promise-5.0.1.tgz", + "integrity": "sha1-6bj2jlUsaKnBcTuEiD96HdA5uKE=", + "requires": { + "mkdirp": "*" + } + }, "modify-values": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/modify-values/-/modify-values-1.0.1.tgz", @@ -6524,6 +6538,16 @@ "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz", "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=" }, + "mz": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", + "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", + "requires": { + "any-promise": "^1.0.0", + "object-assign": "^4.0.1", + "thenify-all": "^1.0.0" + } + }, "nan": { "version": "2.14.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", @@ -8541,6 +8565,22 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, + "thenify": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.0.tgz", + "integrity": "sha1-5p44obq+lpsBCCB5eLn2K4hgSDk=", + "requires": { + "any-promise": "^1.0.0" + } + }, + "thenify-all": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", + "integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=", + "requires": { + "thenify": ">= 3.1.0 < 4" + } + }, "throat": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/throat/-/throat-4.1.0.tgz", diff --git a/package.json b/package.json index 3df488e230..7d593f80bc 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/utils/create-symlink/__tests__/create-symlink.test.js b/utils/create-symlink/__tests__/create-symlink.test.js index 79663ad327..928d278521 100644 --- a/utils/create-symlink/__tests__/create-symlink.test.js +++ b/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); @@ -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 () => { @@ -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"); diff --git a/utils/create-symlink/create-symlink.js b/utils/create-symlink/create-symlink.js index 77ff2fe8cf..13e324f588 100644 --- a/utils/create-symlink/create-symlink.js +++ b/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"); @@ -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); diff --git a/utils/create-symlink/package.json b/utils/create-symlink/package.json index b2aa47b5b1..8315865ff2 100644 --- a/utils/create-symlink/package.json +++ b/utils/create-symlink/package.json @@ -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" }