Skip to content

Commit

Permalink
feat(publish): Add --contents option
Browse files Browse the repository at this point in the history
Fixes #1817

Probably a billion others, as well
  • Loading branch information
evocateur committed Dec 21, 2018
1 parent 09fccd3 commit 5e790e5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
14 changes: 14 additions & 0 deletions commands/publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ This is useful when a previous `lerna publish` failed to publish all packages to
`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:

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

> The intended use case for this flag is a per commit level release or nightly release.
### `--contents`

Subdirectory to publish. Must apply to ALL packages, and MUST contain a package.json file.

This comment has been minimized.

Copy link
@FezVrasta

FezVrasta Dec 21, 2018

Contributor

Thanks for the feature! Is there any particular reason of why this is limited to all or nothing? Would you accept a PR to add granular support?

This comment has been minimized.

Copy link
@evocateur

evocateur Dec 22, 2018

Author Member

I implemented the feature request in the manner demonstrated by np. If you can't apply the same build steps to all packages in a monorepo, it's more than likely there are too many unrelated packages in that monorepo.

I'm not likely to ever use the feature myself (I consider it an anti-pattern), so PRs are the only way it will change.

Package lifecycles will still be run in the original leaf directory.
You should probably use one of those lifecycles (`prepare`, `prepublishOnly`, or `prepack`) to _create_ the subdirectory and whatnot.

If you're into unnecessarily complicated publishing, this will give you joy.

```sh
lerna publish --contents dist
# publish the "dist" subfolder of every Lerna-managed leaf package
```

### `--git-reset`

Ensures the working tree is reset by any changes the `publish` command makes.
Expand Down
16 changes: 16 additions & 0 deletions commands/publish/__tests__/publish-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,22 @@ Set {
});
});

describe("--contents", () => {
it("allows you to do fancy angular crap", async () => {
const cwd = await initFixture("lifecycle");

await lernaPublish(cwd)("--contents", "dist");

for (const name of ["package-1", "package-2"]) {
expect(packDirectory).toHaveBeenCalledWith(
expect.objectContaining({ name }),
expect.stringContaining(`packages/${name}/dist`),
expect.any(Object)
);
}
});
});

describe("in a cyclical repo", () => {
it("should throw an error with --reject-cycles", async () => {
expect.assertions(1);
Expand Down
6 changes: 6 additions & 0 deletions commands/publish/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ exports.builder = yargs => {
requiresArg: true,
defaultDescription: "alpha",
},
contents: {
describe: "Subdirectory to publish. Must apply to ALL packages.",
type: "string",
requiresArg: true,
defaultDescription: ".",
},
"npm-tag": {
describe: "Publish packages with the specified npm dist-tag",
type: "string",
Expand Down
5 changes: 4 additions & 1 deletion commands/publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,16 @@ class PublishCommand extends Command {
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepublishOnly"));
chain = chain.then(() => this.runPackageLifecycle(this.project.manifest, "prepack"));

const { contents } = this.options;
const getLocation = contents ? pkg => path.resolve(pkg.location, contents) : pkg => pkg.location;

const opts = this.conf.snapshot;
const mapper = pPipe(
[
this.options.requireScripts && (pkg => this.execScript(pkg, "prepublish")),

pkg =>
pulseTillDone(packDirectory(pkg, pkg.location, opts)).then(packed => {
pulseTillDone(packDirectory(pkg, getLocation(pkg), opts)).then(packed => {
tracker.completeWork(1);

// store metadata for use in this.publishPacked()
Expand Down

0 comments on commit 5e790e5

Please sign in to comment.