Skip to content

Commit 5e790e5

Browse files
committedDec 21, 2018
feat(publish): Add --contents option
Fixes #1817 Probably a billion others, as well
1 parent 09fccd3 commit 5e790e5

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed
 

‎commands/publish/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ This is useful when a previous `lerna publish` failed to publish all packages to
5050
`lerna publish` supports all of the options provided by [`lerna version`](https://github.com/lerna/lerna/tree/master/commands/version#options) in addition to the following:
5151

5252
- [`--canary`](#--canary)
53+
- [`--contents`](#--contents)
5354
- [`--git-reset`](#--git-reset)
5455
- [`--npm-tag <dist-tag>`](#--npm-tag-dist-tag)
5556
- [`--no-verify-access`](#--no-verify-access)
@@ -77,6 +78,19 @@ When run with this flag, `lerna publish` publishes packages in a more granular w
7778

7879
> The intended use case for this flag is a per commit level release or nightly release.
7980
81+
### `--contents`
82+
83+
Subdirectory to publish. Must apply to ALL packages, and MUST contain a package.json file.
Has comments. Original line has comments.
84+
Package lifecycles will still be run in the original leaf directory.
85+
You should probably use one of those lifecycles (`prepare`, `prepublishOnly`, or `prepack`) to _create_ the subdirectory and whatnot.
86+
87+
If you're into unnecessarily complicated publishing, this will give you joy.
88+
89+
```sh
90+
lerna publish --contents dist
91+
# publish the "dist" subfolder of every Lerna-managed leaf package
92+
```
93+
8094
### `--git-reset`
8195

8296
Ensures the working tree is reset by any changes the `publish` command makes.

‎commands/publish/__tests__/publish-command.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,22 @@ Set {
366366
});
367367
});
368368

369+
describe("--contents", () => {
370+
it("allows you to do fancy angular crap", async () => {
371+
const cwd = await initFixture("lifecycle");
372+
373+
await lernaPublish(cwd)("--contents", "dist");
374+
375+
for (const name of ["package-1", "package-2"]) {
376+
expect(packDirectory).toHaveBeenCalledWith(
377+
expect.objectContaining({ name }),
378+
expect.stringContaining(`packages/${name}/dist`),
379+
expect.any(Object)
380+
);
381+
}
382+
});
383+
});
384+
369385
describe("in a cyclical repo", () => {
370386
it("should throw an error with --reject-cycles", async () => {
371387
expect.assertions(1);

‎commands/publish/command.js

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ exports.builder = yargs => {
2323
requiresArg: true,
2424
defaultDescription: "alpha",
2525
},
26+
contents: {
27+
describe: "Subdirectory to publish. Must apply to ALL packages.",
28+
type: "string",
29+
requiresArg: true,
30+
defaultDescription: ".",
31+
},
2632
"npm-tag": {
2733
describe: "Publish packages with the specified npm dist-tag",
2834
type: "string",

‎commands/publish/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,16 @@ class PublishCommand extends Command {
513513
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepublishOnly"));
514514
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepack"));
515515

516+
const { contents } = this.options;
517+
const getLocation = contents ? pkg => path.resolve(pkg.location, contents) : pkg => pkg.location;
518+
516519
const opts = this.conf.snapshot;
517520
const mapper = pPipe(
518521
[
519522
this.options.requireScripts && (pkg => this.execScript(pkg, "prepublish")),
520523

521524
pkg =>
522-
pulseTillDone(packDirectory(pkg, pkg.location, opts)).then(packed => {
525+
pulseTillDone(packDirectory(pkg, getLocation(pkg), opts)).then(packed => {
523526
tracker.completeWork(1);
524527

525528
// store metadata for use in this.publishPacked()

0 commit comments

Comments
 (0)
Please sign in to comment.