Skip to content

Commit 088ea54

Browse files
committed
feat(npm-publish): Add npmPack export
1 parent be453cd commit 088ea54

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎commands/__mocks__/@lerna/npm-publish.js‎

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

3+
const packed = new Set();
34
const registry = new Map();
45

56
// by default, act like a spy that populates registry
@@ -9,6 +10,12 @@ const mockNpmPublish = jest.fn((pkg, tag) => {
910
return Promise.resolve();
1011
});
1112

13+
const mockNpmPack = jest.fn(pkg => {
14+
packed.add(pkg.name);
15+
16+
return Promise.resolve(pkg.tarball);
17+
});
18+
1219
// a convenient format for assertions
1320
function order() {
1421
return Array.from(registry.keys());
@@ -17,8 +24,11 @@ function order() {
1724
// keep test data isolated
1825
afterEach(() => {
1926
registry.clear();
27+
packed.clear();
2028
});
2129

2230
module.exports = mockNpmPublish;
31+
module.exports.npmPack = mockNpmPack;
2332
module.exports.order = order;
33+
module.exports.packed = packed;
2434
module.exports.registry = registry;

‎utils/npm-publish/__tests__/npm-publish.test.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,16 @@ describe("npm-publish", () => {
9595
);
9696
});
9797
});
98+
99+
describe("npmPack", () => {
100+
it("runs npm pack in a package directory", async () => {
101+
await npmPublish.npmPack(pkg);
102+
103+
expect(ChildProcessUtilities.exec).lastCalledWith("npm", ["pack"], {
104+
cwd: pkg.location,
105+
env: {},
106+
pkg,
107+
});
108+
});
109+
});
98110
});

‎utils/npm-publish/npm-publish.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const ChildProcessUtilities = require("@lerna/child-process");
66
const getExecOpts = require("@lerna/get-npm-exec-opts");
77

88
module.exports = npmPublish;
9+
module.exports.npmPack = npmPack;
910

1011
function npmPublish(pkg, tag, { npmClient, registry }) {
1112
log.silly("npmPublish", tag, pkg.name);
@@ -26,3 +27,12 @@ function npmPublish(pkg, tag, { npmClient, registry }) {
2627

2728
return ChildProcessUtilities.exec(npmClient, args, opts);
2829
}
30+
31+
function npmPack(pkg) {
32+
log.verbose("pack", pkg.name);
33+
34+
const opts = getExecOpts(pkg);
35+
const args = ["pack"];
36+
37+
return ChildProcessUtilities.exec("npm", args, opts);
38+
}

0 commit comments

Comments
 (0)