Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(npm-publish): Add npmPack export
  • Loading branch information
evocateur committed Aug 8, 2018
1 parent be453cd commit 088ea54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 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
Expand All @@ -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());
Expand All @@ -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;
12 changes: 12 additions & 0 deletions utils/npm-publish/__tests__/npm-publish.test.js
Expand Up @@ -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,
});
});
});
});
10 changes: 10 additions & 0 deletions utils/npm-publish/npm-publish.js
Expand Up @@ -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);
Expand All @@ -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);
}

0 comments on commit 088ea54

Please sign in to comment.