Skip to content

Commit 1007040

Browse files
authored
feat(#105): also bump deps in package distribution folder (#106)
Closes #105
1 parent b8eb1c2 commit 1007040

16 files changed

+470
-1
lines changed

lib/createInlinePluginCreator.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
const debug = require("debug")("msr:inlinePlugin");
22
const getCommitsFiltered = require("./getCommitsFiltered");
3+
const getPkgRootOptions = require("./getPkgRootOptions");
4+
const getManifest = require("./getManifest");
5+
const cleanPath = require("./cleanPath");
36
const { getTagHead } = require("./git");
47
const { updateManifestDeps, resolveReleaseType } = require("./updateDeps");
8+
const { uniqBy } = require("lodash");
59

610
/**
711
* Create an inline plugin creator for a multirelease.
@@ -226,7 +230,24 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags)
226230
getLucky("_readyForTagging", pkg);
227231
await waitFor("_readyForTagging", pkg);
228232

229-
updateManifestDeps(pkg);
233+
// Get all manifests that potentially needs to be updated
234+
const pkgs = uniqBy(
235+
[
236+
pkg,
237+
...getPkgRootOptions(context).map((pkgRoot) => {
238+
const manifestPath = cleanPath(`${pkgRoot}/package.json`, context.cwd);
239+
return {
240+
path: manifestPath,
241+
manifest: getManifest(manifestPath),
242+
_depsChanged: pkg._depsChanged,
243+
};
244+
}),
245+
],
246+
"path"
247+
);
248+
249+
// Loop through each manifest and update its dependencies if needed
250+
pkgs.forEach((item) => updateManifestDeps(item));
230251
pkg._depsUpdated = true;
231252

232253
const res = await plugins.prepare(context);

lib/getPkgRootOptions.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { isArray, isPlainObject, isNil } = require("lodash");
2+
3+
/**
4+
* Get all the 'pkgRoot' options from plugins.
5+
*
6+
* @param {MultiContext} context The multi-semantic-release context.
7+
* @returns {string[]} An array containing all the pkgRoot options (if any) or an empty array otherwise.
8+
*
9+
* @internal
10+
*/
11+
function getPkgRootOptions(context) {
12+
const plugins = context.options.plugins ? context.options.plugins : [];
13+
return plugins.reduce((pkgRootOptions, plugin) => {
14+
let config;
15+
if (isArray(plugin) && plugin.length > 1) {
16+
config = plugin[1];
17+
} else if (isPlainObject(plugin) && !isNil(plugin.path)) {
18+
({ ...config } = plugin);
19+
}
20+
if (config && config.pkgRoot && !pkgRootOptions.includes(config.pkgRoot)) {
21+
pkgRootOptions.push(config.pkgRoot);
22+
}
23+
return pkgRootOptions;
24+
}, []);
25+
}
26+
27+
// Exports.
28+
module.exports = getPkgRootOptions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "msr-test-a",
3+
"version": "0.0.0",
4+
"peerDependencies": {
5+
"msr-test-c": "*",
6+
"left-pad": "latest"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "msr-test-b",
3+
"version": "0.0.0",
4+
"dependencies": {
5+
"msr-test-a": "*"
6+
},
7+
"devDependencies": {
8+
"msr-test-c": "*",
9+
"left-pad": "latest"
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "msr-test-c",
3+
"version": "0.0.0",
4+
"devDependencies": {
5+
"msr-test-b": "*",
6+
"msr-test-d": "*"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "msr-test-d",
3+
"version": "0.0.0"
4+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "msr-test-pkgroot-options",
3+
"author": "Badisi <https://github.com/Badisi>",
4+
"version": "0.0.0-semantically-released",
5+
"private": true,
6+
"license": "0BSD",
7+
"engines": {
8+
"node": ">=8.3"
9+
},
10+
"workspaces": [
11+
"packages/*"
12+
],
13+
"release": {
14+
"plugins": [
15+
"@semantic-release/commit-analyzer",
16+
"@semantic-release/release-notes-generator",
17+
[
18+
"@semantic-release/npm",
19+
{
20+
"npmPublish": false
21+
}
22+
]
23+
],
24+
"noCi": true
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"plugins": [
3+
"@semantic-release/commit-analyzer",
4+
"@semantic-release/release-notes-generator",
5+
[
6+
"@semantic-release/npm",
7+
{
8+
"pkgRoot": "../../dist/a",
9+
"npmPublish": false
10+
}
11+
]
12+
]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "msr-test-a",
3+
"version": "0.0.0",
4+
"peerDependencies": {
5+
"msr-test-c": "*",
6+
"left-pad": "latest"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"plugins": [
3+
"@semantic-release/commit-analyzer",
4+
"@semantic-release/release-notes-generator",
5+
[
6+
"@semantic-release/npm",
7+
{
8+
"pkgRoot": "../../dist/b",
9+
"npmPublish": false
10+
}
11+
]
12+
]
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "msr-test-b",
3+
"version": "0.0.0",
4+
"dependencies": {
5+
"msr-test-a": "*"
6+
},
7+
"devDependencies": {
8+
"msr-test-c": "*",
9+
"left-pad": "latest"
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"tagFormat": "multi-semantic-release-test-c@v${version}",
3+
"plugins": [
4+
"@semantic-release/commit-analyzer",
5+
"@semantic-release/release-notes-generator",
6+
[
7+
"@semantic-release/npm",
8+
{
9+
"pkgRoot": "../../dist/c",
10+
"npmPublish": false
11+
}
12+
]
13+
]
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "msr-test-c",
3+
"version": "0.0.0",
4+
"devDependencies": {
5+
"msr-test-b": "*",
6+
"msr-test-d": "*"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "msr-test-d",
3+
"version": "0.0.0"
4+
}

test/lib/getPkgRootOptions.test.js

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
const getPkgRootOptions = require("../../lib/getPkgRootOptions");
2+
3+
// Clear mocks before tests.
4+
beforeEach(() => {
5+
jest.clearAllMocks(); // Clear all mocks.
6+
require.cache = {}; // Clear the require cache so modules are loaded fresh.
7+
});
8+
9+
// Tests.
10+
describe("getPkgRootOptions()", () => {
11+
test("no plugins: Should not find any options", async () => {
12+
expect(getPkgRootOptions({ options: {} })).toEqual([]);
13+
});
14+
test("plugins without options: Should not find any options", async () => {
15+
const context = {
16+
options: {
17+
plugins: [
18+
"@semantic-release/commit-analyzer",
19+
"@semantic-release/release-notes-generator",
20+
"@semantic-release/npm",
21+
],
22+
},
23+
};
24+
expect(getPkgRootOptions(context)).toEqual([]);
25+
});
26+
test("plugin as array: Should find one option", async () => {
27+
const context = {
28+
options: {
29+
plugins: [
30+
"@semantic-release/commit-analyzer",
31+
"@semantic-release/release-notes-generator",
32+
[
33+
"@semantic-release/npm",
34+
{
35+
pkgRoot: "../../dist/a",
36+
npmPublish: false,
37+
},
38+
],
39+
],
40+
},
41+
};
42+
expect(getPkgRootOptions(context)).toEqual(["../../dist/a"]);
43+
});
44+
test("plugin as object: Should find one option", async () => {
45+
const context = {
46+
options: {
47+
plugins: [
48+
"@semantic-release/commit-analyzer",
49+
"@semantic-release/release-notes-generator",
50+
{
51+
path: "@semantic-release/npm",
52+
pkgRoot: "../../dist/a",
53+
npmPublish: false,
54+
},
55+
],
56+
},
57+
};
58+
expect(getPkgRootOptions(context)).toEqual(["../../dist/a"]);
59+
});
60+
test("Should find multiple options", async () => {
61+
const context = {
62+
options: {
63+
plugins: [
64+
[
65+
"@semantic-release/custom-plugin",
66+
{
67+
pkgRoot: "../../dist/a",
68+
},
69+
],
70+
"@semantic-release/release-notes-generator",
71+
[
72+
"@semantic-release/npm",
73+
{
74+
pkgRoot: "../../dist/b",
75+
npmPublish: false,
76+
},
77+
],
78+
],
79+
},
80+
};
81+
expect(getPkgRootOptions(context)).toEqual(["../../dist/a", "../../dist/b"]);
82+
});
83+
test("Should not dedupe options", async () => {
84+
const context = {
85+
options: {
86+
plugins: [
87+
[
88+
"@semantic-release/custom-plugin",
89+
{
90+
pkgRoot: "../../dist/a",
91+
},
92+
],
93+
"@semantic-release/release-notes-generator",
94+
[
95+
"@semantic-release/npm",
96+
{
97+
pkgRoot: "../../dist/a",
98+
npmPublish: false,
99+
},
100+
],
101+
],
102+
},
103+
};
104+
expect(getPkgRootOptions(context)).toEqual(["../../dist/a"]);
105+
});
106+
});

0 commit comments

Comments
 (0)