-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workspaces): add support for npm, pnpm, bolt (#52)
- Loading branch information
Showing
47 changed files
with
645 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ _But_ in multi-semantic-release this configuration can be done globally (in your | |
|
||
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 automatically detects packages within workspaces for the following package-managers: | ||
|
||
### yarn / npm (Version 7.x) | ||
|
||
Make sure to have a `workspaces` attribute inside your `package.json` project file. In there, you can set a list of packages that you might want to process in the msr process, as well as ignore others. For example, let's say your project has 4 packages (i.e. a, b, c and d) and you want to process only a and d (ignore b and c). You can set the following structure in your `package.json` file: | ||
```json | ||
{ | ||
|
@@ -58,6 +62,52 @@ Make sure to have a `workspaces` attribute inside your `package.json` project fi | |
} | ||
``` | ||
|
||
### pnpm | ||
|
||
Make sure to have a `packages` attribute inside your `pnpm-workspace.yaml` in the root of your project. | ||
In there, you can set a list of packages that you might want to process in the msr process, as well as ignore others. | ||
For example, let's say your project has 4 packages (i.e. a, b, c and d) and you want to process only a and d (ignore b and c). You can set the following structure in your `pnpm-workspace.yaml` file: | ||
|
||
```yaml | ||
packages: | ||
- 'packages/**' | ||
- '!packages/b/**' | ||
- '!packages/c/**' | ||
``` | ||
### bolt | ||
Make sure to have a `bolt.workspaces` attribute inside your `package.json` project file. | ||
In there, you can set a list of packages that you might want to process in the msr process, as well as ignore others. | ||
For example, let's say your project has 4 packages (i.e. a, b, c and d) and you want to process only a and d (ignore b and c). You can set the following structure in your `package.json` file: | ||
|
||
```json | ||
{ | ||
"name": "msr-test-bolt", | ||
"author": "Dave Houlbrooke <[email protected]", | ||
"version": "0.0.0-semantically-released", | ||
"private": true, | ||
"license": "0BSD", | ||
"engines": { | ||
"node": ">=8.3" | ||
}, | ||
"bolt": { | ||
"workspaces": [ | ||
"packages/*", | ||
"!packages/b/**", | ||
"!packages/c/**" | ||
] | ||
}, | ||
"release": { | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator" | ||
], | ||
"noCi": true | ||
} | ||
} | ||
``` | ||
|
||
## CLI | ||
There are several tweaks to adapt **msr** to some corner cases: | ||
|
||
|
@@ -103,7 +153,12 @@ multirelease([ | |
|
||
### Support for monorepos | ||
|
||
Automatically finds packages as long as workspaces are configured as-per [Yarn workspaces](https://yarnpkg.com/lang/en/docs/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)._ | ||
Automatically finds packages as long as workspaces are configured as-per the workspace-feature of one of the support package managers. | ||
|
||
- [Yarn workspaces](https://yarnpkg.com/lang/en/docs/workspaces/). | ||
- [Npm workspaces (Version 7.x)](https://docs.npmjs.com/cli/v7/using-npm/workspaces) | ||
- [pnpm workspace](https://pnpm.js.org/workspaces/) | ||
- [bolt workspaces](https://github.com/boltpkg/bolt#configuration) | ||
|
||
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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const getManifest = require("./getManifest"); | ||
const glob = require("./glob"); | ||
const path = require("path"); | ||
const { getPackagesSync } = require("@manypkg/get-packages"); | ||
|
||
/** | ||
* Return array of package.json for workspace packages. | ||
* | ||
* @param {string} cwd The current working directory where a package.json file can be found. | ||
* @param {string[]|null} ignorePackages (Optional) Packages to be ignored passed via cli. | ||
* @returns {string[]} An array of package.json files corresponding to the workspaces setting in package.json | ||
*/ | ||
function getPackagePaths(cwd, ignorePackages = null) { | ||
let workspace; | ||
// Ignore exceptions as we will rely on `getManifest` validation | ||
try { | ||
workspace = getPackagesSync(cwd); | ||
} catch (e) { | ||
/**/ | ||
} | ||
workspace = workspace || { | ||
tool: "root", | ||
root: { dir: cwd }, | ||
}; | ||
workspace.root.packageJson = getManifest(path.join(workspace.root.dir, "package.json")); | ||
|
||
if (workspace.tool === "root") { | ||
workspace.packages = []; | ||
} | ||
|
||
// remove cwd from results | ||
const packages = workspace.packages.map((p) => path.relative(cwd, p.dir)); | ||
|
||
// If packages to be ignored come from CLI, we need to combine them with the ones from manifest workspaces | ||
if (Array.isArray(ignorePackages)) packages.push(...ignorePackages.map((p) => `!${p}`)); | ||
|
||
// Turn workspaces into list of package.json files. | ||
const workspacePackages = glob( | ||
packages.map((p) => p.replace(/\/?$/, "/package.json")), | ||
{ | ||
cwd: cwd, | ||
absolute: true, | ||
gitignore: true, | ||
} | ||
); | ||
|
||
// Must have at least one workspace-package. | ||
if (!workspacePackages.length) | ||
throw new TypeError("package.json: Project must contain one or more workspace-packages"); | ||
|
||
// Return. | ||
return workspacePackages; | ||
} | ||
|
||
// Exports. | ||
module.exports = getPackagePaths; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "msr-test-bolt", | ||
"author": "Dave Houlbrooke <[email protected]>", | ||
"version": "0.0.0-semantically-released", | ||
"private": true, | ||
"license": "0BSD", | ||
"engines": { | ||
"node": ">=8.3" | ||
}, | ||
"bolt": { | ||
"workspaces": [ | ||
"packages/*" | ||
] | ||
}, | ||
"release": { | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator" | ||
], | ||
"noCi": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "msr-test-a", | ||
"version": "0.0.0", | ||
"peerDependencies": { | ||
"msr-test-c": "*", | ||
"left-pad": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "msr-test-b", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"msr-test-a": "*" | ||
}, | ||
"devDependencies": { | ||
"msr-test-c": "*", | ||
"left-pad": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"tagFormat": "multi-semantic-release-test-c@v${version}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "msr-test-c", | ||
"version": "0.0.0", | ||
"devDependencies": { | ||
"msr-test-b": "*", | ||
"msr-test-d": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "msr-test-d", | ||
"version": "0.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "msr-test-bolt", | ||
"author": "Dave Houlbrooke <[email protected]", | ||
"version": "0.0.0-semantically-released", | ||
"private": true, | ||
"license": "0BSD", | ||
"engines": { | ||
"node": ">=8.3" | ||
}, | ||
"bolt": { | ||
"workspaces": [ | ||
"packages/*", | ||
"!packages/d/**" | ||
] | ||
}, | ||
"release": { | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator" | ||
], | ||
"noCi": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "msr-test-a", | ||
"version": "0.0.0", | ||
"peerDependencies": { | ||
"msr-test-c": "*", | ||
"left-pad": "latest" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/fixtures/boltWorkspacesIgnore/packages/b/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
{ | ||
"name": "msr-test-b", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"msr-test-a": "*" | ||
}, | ||
"devDependencies": { | ||
"msr-test-c": "*", | ||
"left-pad": "latest" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/boltWorkspacesIgnore/packages/c/.releaserc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"tagFormat": "multi-semantic-release-test-c@v${version}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "msr-test-c", | ||
"version": "0.0.0", | ||
"devDependencies": { | ||
"msr-test-b": "*", | ||
"msr-test-d": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "msr-test-d", | ||
"version": "0.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "msr-test-bolt", | ||
"author": "Dave Houlbrooke <[email protected]>", | ||
"version": "0.0.0-semantically-released", | ||
"private": true, | ||
"license": "0BSD", | ||
"engines": { | ||
"node": ">=8.3" | ||
}, | ||
"bolt": { | ||
}, | ||
"release": { | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator" | ||
], | ||
"noCi": true | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/fixtures/boltWorkspacesUndefined/packages/a/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "msr-test-a", | ||
"version": "0.0.0", | ||
"peerDependencies": { | ||
"msr-test-c": "*", | ||
"left-pad": "latest" | ||
} | ||
} |
Oops, something went wrong.