-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Closes #105
- Loading branch information
Showing
16 changed files
with
470 additions
and
1 deletion.
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
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,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; |
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,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,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 | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
[ | ||
"@semantic-release/npm", | ||
{ | ||
"pkgRoot": "../../dist/a", | ||
"npmPublish": false | ||
} | ||
] | ||
] | ||
} |
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,13 @@ | ||
{ | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
[ | ||
"@semantic-release/npm", | ||
{ | ||
"pkgRoot": "../../dist/b", | ||
"npmPublish": false | ||
} | ||
] | ||
] | ||
} |
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,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 | ||
} | ||
] | ||
] | ||
} |
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,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"]); | ||
}); | ||
}); |
Oops, something went wrong.