Skip to content
Permalink
Browse files
feat(npm-publish): Add npmPack export
  • Loading branch information
evocateur committed Aug 8, 2018
1 parent be453cd commit 088ea5442b625837b659fbb4068c5790de0c9feb
Showing 3 changed files with 32 additions and 0 deletions.
@@ -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;
@@ -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,
});
});
});
});
@@ -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);
}

0 comments on commit 088ea54

Please sign in to comment.