Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@aztec/multi-semantic-release
Advanced tools
[![Travis CI](https://travis-ci.com/dhoulb/multi-semantic-release.svg?branch=master)](https://travis-ci.com/dhoulb/multi-semantic-release) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=
Proof of concept that wraps semantic-release to work with monorepos.
This package should work well, but may not be fundamentally stable enough for important production use as it's pretty dependent on how semantic-release works (so it may break or get out-of-date in future versions of semantic-release).
One of the best things about semantic-release is forgetting about version numbers. In a monorepo though there's still a lot of version number management required for local deps (packages in the same monorepo referenced in dependencies
or devDependencies
or peerDependencies
). However in multi-semantic-release the version numbers of local deps are written into package.json
at release time. This means there's no need to hard-code versions any more (we recommend just using *
asterisk instead in your repo code).
yarn add multi-semantic-release --dev
multi-semantic-release
Configuration for releases is the same as semantic-release configuration, i.e. using a release
key under package.json
or in .releaserc
file of any type e.g. .yaml
, .json
.
But in multi-semantic-release this configuration can be done globally (in your top-level dir), or per-package (in that individual package's dir). If you set both then per-package settings will override global settings.
multi-semantic-release does not support any command line arguments (this wasn't possible without duplicating files from semantic-release, which I've tried to avoid).
multi-semantic-release default exports a multirelease()
method which takes the following arguments:
packages
An array containing string paths to package.json
filesoptions
An object containing default semantic-release configuration optionsmultirelease()
returns an array of objects describing the result of the multirelease (corresponding to the packages
array that is passed in).
const multirelease = require("multi-semantic-release");
multirelease([
`${__dirname}/packages/my-pkg-1/package.json`,
`${__dirname}/packages/my-pkg-2/package.json`,
]);
Automatically finds packages as long as workspaces are configured as-per Yarn workspaces. You don't need to use Yarn but the way they define monorepos seems intuitive, and is likely what NPM will copy when they add this functionality (as rumoured).
I'm aware Lerna is the best-known tool right now, but in future it seems clear it will be replaced by functionality in Yarn and NPM directly. If you use Yarn workspaces today (January 2019), then publishing is the only remaining feature Lerna is really required for (though it'd be lovely if Yarn added parallel script execution). Thus using multi-semantic-release means you can probably remove Lerna entirely from your project.
Other packages that enable semantic-release for monorepos work by iterating into each package and running the semantic-release
command. This is conceptually simple but unfortunately not viable because:
A key requirement is handling local dep version numbers elegantly. multi-semantic-release does the following:
patch
bump on that package toopackage.json
file (overwriting any existing value)The above means that, possibly, if someone upgrades dependencies and pulls down a package from NPM during the multirelease (before all its deps have been published at their next versions), then their npm install
will fail (it will work if they try again in a few minutes). On balance I thought it was more important to be atomically correct (this situation should be fairly rare assuming projects commit their lockfiles).
This is the jankiest part of multi-semantic-release and most likely part to break relies. I expect this to cause maintenance issues down the line. In an ideal world semantic-release will bake-in support for monorepos (making this package unnecessary).
The way I ended up integrating is to create a custom "inline plugin" for semantic-release, and passing that in to semanticRelease()
as the only plugin. This then calls any other configured plugins to retrieve and potentially modify the response.
The plugin starts all release at once, then pauses them (using Promises) at various points to allow other packages in the multirelease to catch up. This is mainly needed so the version number of all packages can be established before any package is released. This allows us to do a patch
bump on releases whose local deps have bumped, and to accurately write in the version of local deps in each package.json
The inline plugin does the following:
context.commits
with a list of commits filtered to the folder onlyplugins.analyzeCommits()
to get the next release type (e.g. from @semantic-release/commit-analyzer)patch
if that's trueplugins.generateNotes()
to get the notes (e.g. from @semantic-release/release-notes-generator)dependencies
, devDependencies
, peerDependencies
in package.json
git push
asyncronously, multiple releases at once fail because Git refs aren't locked — semantic-release should use execa.sync()
so Git operations are atomic)The integration with semantic release is pretty janky — this is a quick summary of the reasons this package will be hard to maintain:
context.commits
object before it was used by @semantic-release/commit-analyzer
(so it only lists commits for the corresponding directory).context.commits
was very difficult! I did it eventually creating an inline plugin and passing it into semanticRelease()
via options.plugins
plugins.analyzeCommits()
with an overridden context.commits
— see createInlinePluginCreator.jsdependencies
in package.json points to an internal package) this step also does a patch
bump if any of them did a bump..releaserc
and then per-directory overrides for individual packages).git tag
is done asynchronouslyexeca()
in semantic release should be replaced with execa.sync()
to ensure Git's internal state is atomic. For an experiment, you may add --execasync
CLI flag that makes all calls synchronous through ritm-hook.Releases always use a tagFormat
of my-pkg-1@1.0.1
for Git tags, and always overrides any gitTag
set in semantic-release configuration.
I can personally see the potential for this option in coordinating a semantic-release (e.g. so two packages with the same tag always bump and release simultaneously). Unfortunately with the points of integration available in semantic-release, it was effectively impossible when releasing to stop a second package creating a duplicate tag (causing an error).
To make the tagFormat
option work as intended the following would need to happen:
v1.0.0
will have the same effect as Lerna's fixed mode (all changed monorepo packages released at same time)FAQs
[![Travis CI](https://travis-ci.com/dhoulb/multi-semantic-release.svg?branch=master)](https://travis-ci.com/dhoulb/multi-semantic-release) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=
We found that @aztec/multi-semantic-release demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.