From 088ea5442b625837b659fbb4068c5790de0c9feb Mon Sep 17 00:00:00 2001 From: Daniel Stockman Date: Wed, 1 Aug 2018 17:56:03 -0700 Subject: [PATCH] feat(npm-publish): Add npmPack export --- commands/__mocks__/@lerna/npm-publish.js | 10 ++++++++++ utils/npm-publish/__tests__/npm-publish.test.js | 12 ++++++++++++ utils/npm-publish/npm-publish.js | 10 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/commands/__mocks__/@lerna/npm-publish.js b/commands/__mocks__/@lerna/npm-publish.js index 591153daa9..6b2a9c0165 100644 --- a/commands/__mocks__/@lerna/npm-publish.js +++ b/commands/__mocks__/@lerna/npm-publish.js @@ -1,5 +1,6 @@ "use strict"; +const packed = new Set(); const registry = new Map(); // by default, act like a spy that populates registry @@ -9,6 +10,12 @@ const mockNpmPublish = jest.fn((pkg, tag) => { return Promise.resolve(); }); +const mockNpmPack = jest.fn(pkg => { + packed.add(pkg.name); + + return Promise.resolve(pkg.tarball); +}); + // a convenient format for assertions function order() { return Array.from(registry.keys()); @@ -17,8 +24,11 @@ function order() { // keep test data isolated afterEach(() => { registry.clear(); + packed.clear(); }); module.exports = mockNpmPublish; +module.exports.npmPack = mockNpmPack; module.exports.order = order; +module.exports.packed = packed; module.exports.registry = registry; diff --git a/utils/npm-publish/__tests__/npm-publish.test.js b/utils/npm-publish/__tests__/npm-publish.test.js index e85bad7212..293135b479 100644 --- a/utils/npm-publish/__tests__/npm-publish.test.js +++ b/utils/npm-publish/__tests__/npm-publish.test.js @@ -95,4 +95,16 @@ describe("npm-publish", () => { ); }); }); + + describe("npmPack", () => { + it("runs npm pack in a package directory", async () => { + await npmPublish.npmPack(pkg); + + expect(ChildProcessUtilities.exec).lastCalledWith("npm", ["pack"], { + cwd: pkg.location, + env: {}, + pkg, + }); + }); + }); }); diff --git a/utils/npm-publish/npm-publish.js b/utils/npm-publish/npm-publish.js index a3e2469822..906821f293 100644 --- a/utils/npm-publish/npm-publish.js +++ b/utils/npm-publish/npm-publish.js @@ -6,6 +6,7 @@ const ChildProcessUtilities = require("@lerna/child-process"); const getExecOpts = require("@lerna/get-npm-exec-opts"); module.exports = npmPublish; +module.exports.npmPack = npmPack; function npmPublish(pkg, tag, { npmClient, registry }) { log.silly("npmPublish", tag, pkg.name); @@ -26,3 +27,12 @@ function npmPublish(pkg, tag, { npmClient, registry }) { return ChildProcessUtilities.exec(npmClient, args, opts); } + +function npmPack(pkg) { + log.verbose("pack", pkg.name); + + const opts = getExecOpts(pkg); + const args = ["pack"]; + + return ChildProcessUtilities.exec("npm", args, opts); +}