Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(laverna): create laverna #836

Merged
merged 12 commits into from
Jan 31, 2024
Merged

feat(laverna): create laverna #836

merged 12 commits into from
Jan 31, 2024

Conversation

boneskull
Copy link
Contributor

@boneskull boneskull commented Jan 10, 2024

Laverna

image

Publish multiple workspaces (that's all)

If you're familiar with lerna, Laverna does this: lerna publish from-package.

If you're unfamiliar with it: Laverna publishes all workspaces that haven't yet been published.

Features

Laverna is a thin wrapper around npm publish which:

  • Invokes npm publish for all workspaces that haven't yet been published
  • Handles new packages (via a flag)
  • Ignores private packages
  • Requires a confirmation (by default)
  • Provides a "dry-run" mode
  • Prints all output from npm publish, including the output of npm pack, to enable review

Non-Features

Perhaps more importantly, Laverna:

  • Builds nothing
  • Bumps no versions
  • Does not write to package.json
  • Does not interact with git (no tags, no commits, no pushes)
  • Does not interact with GitHub (no releases)
  • Does not cache anything

Supported Environments

  • Node.js v18.13.0+
  • npm v8.19.3+

Install

It's recommended to install as a dev dependency:

npm install @lavamoat/laverna -D

Usage Summary

laverna [options..]

Publish multiple workspaces (that's all)

Options:

 --dryRun        - Enable dry-run mode
 --root=<path>   - Path to workspace root (default: current working dir)
 --newPkg=<name> - Workspace <name> has never been published (repeatable)
 --yes/-y        - Skip confirmation prompt

Problems? Visit https://github.com/LavaMoat/lavamoat/issues

Examples

Using Release Please or Similar

For a typical release workflow, you might:

  1. Bump workspace versions (e.g. via release-please-action)
  2. In your updated working copy's workspace root, run npm exec laverna (or npm exec laverna -- --dry-run first)
  3. Bask in glory

Publishing a New Package

If you're publishing a package in a new workspace, you might:

  1. Set the initial version of the new package (call it foo) in its package.json.
  2. Run npm exec laverna -- --newPkg=foo (or npm exec laverna -- --newPkg=foo --dry-run first)
  3. Profit

Automating Publishes

You'll need to figure out how to add --newPkg to your CI/CD pipeline. Otherwise, use the --yes flag when invoking laverna.

API

Laverna provides a programmable JavaScript API (for what it's worth).

Refer to the TypeScript definitions for details.

Notes

LavaMoat needed something that did this, but didn't need Lerna for anything else. So, here we are.

License

Copyright © 2023 Consensys, Inc. Licensed MIT

@boneskull
Copy link
Contributor Author

boneskull commented Jan 10, 2024

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@boneskull boneskull force-pushed the boneskull/laverna branch 3 times, most recently from 89887b2 to 6fb048c Compare January 10, 2024 20:42
@boneskull boneskull added the enhancement New feature or request label Jan 10, 2024
@boneskull boneskull self-assigned this Jan 10, 2024
@boneskull boneskull force-pushed the boneskull/laverna branch 2 times, most recently from 12033ce to 27b6a8b Compare January 10, 2024 23:15
@boneskull

This comment was marked as resolved.

@boneskull boneskull force-pushed the boneskull/laverna branch 3 times, most recently from 2107946 to e9b7ce9 Compare January 11, 2024 22:32
@boneskull
Copy link
Contributor Author

Note that this requires a minimum version of Node.js v18.13.0. The entire test suite cannot be run in an older version of Node.js. It's probably too painful to exempt testing just this package from the GHA matrix, so I've done this via a dynamic Ava config.

The reasoning is twofold:

  1. We should probably not publish new packages which support on an EOL version of Node.js; that's unnecessary tech debt
  2. I found myself re-implementing spies/mocks. But node:test exports a mock namespace-like object which provides exactly what I needed.

@boneskull boneskull marked this pull request as ready for review January 11, 2024 22:37
@boneskull boneskull requested review from legobeat and a team as code owners January 11, 2024 22:37
@boneskull
Copy link
Contributor Author

Oh, and the reason I'm doing this in the first place is that it's absolutely a thing that other projects will find useful (including my own). So... yes, selfish reasons.

@boneskull
Copy link
Contributor Author

REVIEWER(S)

This is mostly just a refactored scripts/publish.js which landed in #727. I wrote some more tests and cleaned it up for public consumption.

@boneskull boneskull force-pushed the boneskull/laverna branch 2 times, most recently from 1c89786 to 7fe8e03 Compare January 17, 2024 21:05
@github-actions github-actions bot added dependencies Pull requests that update a dependency file chore overhead, tests, dev env, etc. documentation Docs, examples, tutorials, and associated tooling labels Jan 17, 2024
@boneskull boneskull removed the documentation Docs, examples, tutorials, and associated tooling label Jan 17, 2024
@github-actions github-actions bot added the documentation Docs, examples, tutorials, and associated tooling label Jan 18, 2024
@boneskull
Copy link
Contributor Author

@legobeat ping

@boneskull boneskull force-pushed the boneskull/laverna branch 2 times, most recently from 5dc115e to d6eb067 Compare January 29, 2024 22:13
@boneskull
Copy link
Contributor Author

@legobeat I think I've got everything here...

@naugtur
Copy link
Member

naugtur commented Jan 31, 2024

While we still want to avoid breaking older Node.js support for our users, none of us are using it.
We are the users of laverna. It's ok to skip testing it in old Node.js versions.

With the script testing cleanup moved to the other PR, I think this is ready to merge.

@@ -96,6 +96,7 @@
"prettier": {
"jsdocCommentLineStrategy": "keep",
"jsdocPreferCodeFences": true,
"jsdocTagsOrder": "{\"template\": 24.5}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this and therefore fear it. I'm a simple man. Please help me understand why we want this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, well, I would have explained myself, but it's package.json, so.

hosseinmd/prettier-plugin-jsdoc#226

summary: string
detail: string
}
}} */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier went bonkers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, changes to this file should not be in this PR. I'll pull that out

@naugtur
Copy link
Member

naugtur commented Jan 31, 2024

TS errors in tests:

Error: packages/laverna/test/laverna.spec.js(24,44): error TS2694: Namespace '"node:test"' has no exported member 'Mock'.
Error: packages/laverna/test/laverna.spec.js(25,35): error TS2694: Namespace '"node:test"' has no exported member 'Mock'.
Error: packages/laverna/test/laverna.spec.js(419,6): error TS7006: Parameter 'call' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(422,16): error TS7006: Parameter 'arg' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(506,6): error TS7006: Parameter 'call' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(508,21): error TS7006: Parameter 'arg' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(530,6): error TS7006: Parameter 'call' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(532,21): error TS7006: Parameter 'arg' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(693,6): error TS7006: Parameter 'call' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(696,16): error TS7006: Parameter 'arg' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(756,6): error TS7006: Parameter 'call' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(758,21): error TS7006: Parameter 'arg' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(788,6): error TS7006: Parameter 'call' implicitly has an 'any' type.
Error: packages/laverna/test/laverna.spec.js(791,16): error TS7006: Parameter 'arg' implicitly has an 'any' type.
Error: Process completed with exit code 2.

This is marked as the change request blocking the merge and also as resolved. Should we consider it done?

boneskull and others added 10 commits January 31, 2024 13:00
This copies `scripts/publish.js` into its own package named `@lavamoat/laverna`.
This adds support for `--new-pkg` and `--dry-run`, though it remains undocumented.

If someone uses both `--new-pkg` and `--newPkg` and/or `--dry-run` and `--dryRun`, Laverna will exit with an error.
- `--dry-run` and `--dryRun` are both supported w/o conflict
- `--newPkg` and `--new-pkg` are both supported w/o conflict
Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
boneskull and others added 2 commits January 31, 2024 14:17
Co-authored-by: Zbyszek Tenerowicz <naugtur@gmail.com>
@boneskull boneskull merged commit f175102 into main Jan 31, 2024
12 checks passed
@boneskull boneskull deleted the boneskull/laverna branch January 31, 2024 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore overhead, tests, dev env, etc. dependencies Pull requests that update a dependency file documentation Docs, examples, tutorials, and associated tooling enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants