Skip to content

Commit

Permalink
feat(#105): also bump deps in package distribution folder (#106)
Browse files Browse the repository at this point in the history
Closes #105
  • Loading branch information
Badisi committed Apr 15, 2022
1 parent b8eb1c2 commit 1007040
Show file tree
Hide file tree
Showing 16 changed files with 470 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const debug = require("debug")("msr:inlinePlugin");
const getCommitsFiltered = require("./getCommitsFiltered");
const getPkgRootOptions = require("./getPkgRootOptions");
const getManifest = require("./getManifest");
const cleanPath = require("./cleanPath");
const { getTagHead } = require("./git");
const { updateManifestDeps, resolveReleaseType } = require("./updateDeps");
const { uniqBy } = require("lodash");

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

updateManifestDeps(pkg);
// Get all manifests that potentially needs to be updated
const pkgs = uniqBy(
[
pkg,
...getPkgRootOptions(context).map((pkgRoot) => {
const manifestPath = cleanPath(`${pkgRoot}/package.json`, context.cwd);
return {
path: manifestPath,
manifest: getManifest(manifestPath),
_depsChanged: pkg._depsChanged,
};
}),
],
"path"
);

// Loop through each manifest and update its dependencies if needed
pkgs.forEach((item) => updateManifestDeps(item));
pkg._depsUpdated = true;

const res = await plugins.prepare(context);
Expand Down
28 changes: 28 additions & 0 deletions lib/getPkgRootOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { isArray, isPlainObject, isNil } = require("lodash");

/**
* Get all the 'pkgRoot' options from plugins.
*
* @param {MultiContext} context The multi-semantic-release context.
* @returns {string[]} An array containing all the pkgRoot options (if any) or an empty array otherwise.
*
* @internal
*/
function getPkgRootOptions(context) {
const plugins = context.options.plugins ? context.options.plugins : [];
return plugins.reduce((pkgRootOptions, plugin) => {
let config;
if (isArray(plugin) && plugin.length > 1) {
config = plugin[1];
} else if (isPlainObject(plugin) && !isNil(plugin.path)) {
({ ...config } = plugin);
}
if (config && config.pkgRoot && !pkgRootOptions.includes(config.pkgRoot)) {
pkgRootOptions.push(config.pkgRoot);
}
return pkgRootOptions;
}, []);
}

// Exports.
module.exports = getPkgRootOptions;
8 changes: 8 additions & 0 deletions test/fixtures/pkgRootOptions/dist/a/package.json
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"
}
}
11 changes: 11 additions & 0 deletions test/fixtures/pkgRootOptions/dist/b/package.json
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"
}
}
8 changes: 8 additions & 0 deletions test/fixtures/pkgRootOptions/dist/c/package.json
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": "*"
}
}
4 changes: 4 additions & 0 deletions test/fixtures/pkgRootOptions/dist/d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "msr-test-d",
"version": "0.0.0"
}
26 changes: 26 additions & 0 deletions test/fixtures/pkgRootOptions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "msr-test-pkgroot-options",
"author": "Badisi <https://github.com/Badisi>",
"version": "0.0.0-semantically-released",
"private": true,
"license": "0BSD",
"engines": {
"node": ">=8.3"
},
"workspaces": [
"packages/*"
],
"release": {
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"npmPublish": false
}
]
],
"noCi": true
}
}
13 changes: 13 additions & 0 deletions test/fixtures/pkgRootOptions/packages/a/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"pkgRoot": "../../dist/a",
"npmPublish": false
}
]
]
}
8 changes: 8 additions & 0 deletions test/fixtures/pkgRootOptions/packages/a/package.json
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"
}
}
13 changes: 13 additions & 0 deletions test/fixtures/pkgRootOptions/packages/b/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"pkgRoot": "../../dist/b",
"npmPublish": false
}
]
]
}
11 changes: 11 additions & 0 deletions test/fixtures/pkgRootOptions/packages/b/package.json
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"
}
}
14 changes: 14 additions & 0 deletions test/fixtures/pkgRootOptions/packages/c/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"tagFormat": "multi-semantic-release-test-c@v${version}",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
"pkgRoot": "../../dist/c",
"npmPublish": false
}
]
]
}
8 changes: 8 additions & 0 deletions test/fixtures/pkgRootOptions/packages/c/package.json
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": "*"
}
}
4 changes: 4 additions & 0 deletions test/fixtures/pkgRootOptions/packages/d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "msr-test-d",
"version": "0.0.0"
}
106 changes: 106 additions & 0 deletions test/lib/getPkgRootOptions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const getPkgRootOptions = require("../../lib/getPkgRootOptions");

// Clear mocks before tests.
beforeEach(() => {
jest.clearAllMocks(); // Clear all mocks.
require.cache = {}; // Clear the require cache so modules are loaded fresh.
});

// Tests.
describe("getPkgRootOptions()", () => {
test("no plugins: Should not find any options", async () => {
expect(getPkgRootOptions({ options: {} })).toEqual([]);
});
test("plugins without options: Should not find any options", async () => {
const context = {
options: {
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
],
},
};
expect(getPkgRootOptions(context)).toEqual([]);
});
test("plugin as array: Should find one option", async () => {
const context = {
options: {
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
pkgRoot: "../../dist/a",
npmPublish: false,
},
],
],
},
};
expect(getPkgRootOptions(context)).toEqual(["../../dist/a"]);
});
test("plugin as object: Should find one option", async () => {
const context = {
options: {
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
{
path: "@semantic-release/npm",
pkgRoot: "../../dist/a",
npmPublish: false,
},
],
},
};
expect(getPkgRootOptions(context)).toEqual(["../../dist/a"]);
});
test("Should find multiple options", async () => {
const context = {
options: {
plugins: [
[
"@semantic-release/custom-plugin",
{
pkgRoot: "../../dist/a",
},
],
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
pkgRoot: "../../dist/b",
npmPublish: false,
},
],
],
},
};
expect(getPkgRootOptions(context)).toEqual(["../../dist/a", "../../dist/b"]);
});
test("Should not dedupe options", async () => {
const context = {
options: {
plugins: [
[
"@semantic-release/custom-plugin",
{
pkgRoot: "../../dist/a",
},
],
"@semantic-release/release-notes-generator",
[
"@semantic-release/npm",
{
pkgRoot: "../../dist/a",
npmPublish: false,
},
],
],
},
};
expect(getPkgRootOptions(context)).toEqual(["../../dist/a"]);
});
});
Loading

0 comments on commit 1007040

Please sign in to comment.