Skip to content

Commit d28392e

Browse files
committed
fix: correctly verify otpUrl config option
1 parent 04d64ff commit d28392e

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ let verified;
1111
let prepared;
1212

1313
async function verifyConditions(pluginConfig, context) {
14-
// If the npm publish plugin is used and has `npmPublish`, `tarballDir` or `pkgRoot` configured, validate them now in order to prevent any release if the configuration is wrong
14+
// If the npm publish plugin is used and has `npmPublish`, `tarballDir`, `pkgRoot` or `otpUrl` configured, validate them now in order to prevent any release if the configuration is wrong
1515
if (context.options.publish) {
1616
const publishPlugin =
1717
castArray(context.options.publish).find(config => config.path && config.path === '@semantic-release/npm') || {};
1818

1919
pluginConfig.npmPublish = defaultTo(pluginConfig.npmPublish, publishPlugin.npmPublish);
2020
pluginConfig.tarballDir = defaultTo(pluginConfig.tarballDir, publishPlugin.tarballDir);
2121
pluginConfig.pkgRoot = defaultTo(pluginConfig.pkgRoot, publishPlugin.pkgRoot);
22+
pluginConfig.otpUrl = defaultTo(pluginConfig.otpUrl, publishPlugin.otpUrl);
2223
}
2324

2425
const errors = verifyNpmConfig(pluginConfig);

lib/definitions/errors.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Your configuration for the \`tarballDir\` option is \`${tarballDir}\`.`,
2121
details: `The [pkgRoot option](${linkify('README.md#pkgroot')}) option, if defined, must be a \`String\`.
2222
2323
Your configuration for the \`pkgRoot\` option is \`${pkgRoot}\`.`,
24+
}),
25+
EINVALIDOTPURL: ({otpUrl}) => ({
26+
message: 'Invalid `otpUrl` option.',
27+
details: `The [otpUrl option](${linkify('README.md#otpurl')}) option, if defined, must be a \`String\`.
28+
29+
Your configuration for the \`otpUrl\` option is \`${otpUrl}\`.`,
2430
}),
2531
ENONPMTOKEN: ({registry}) => ({
2632
message: 'No npm token specified.',

lib/verify-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const VALIDATORS = {
1010
otpUrl: isNonEmptyString,
1111
};
1212

13-
module.exports = ({npmPublish, tarballDir, pkgRoot}) => {
14-
const errors = Object.entries({npmPublish, tarballDir, pkgRoot}).reduce(
13+
module.exports = ({npmPublish, tarballDir, pkgRoot, otpUrl}) => {
14+
const errors = Object.entries({npmPublish, tarballDir, pkgRoot, otpUrl}).reduce(
1515
(errors, [option, value]) =>
1616
!isNil(value) && !VALIDATORS[option](value)
1717
? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})]

test/verify-config.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ test.beforeEach(t => {
88
t.context.logger = {log: t.context.log};
99
});
1010

11-
test('Verify "npmPublish", "tarballDir" and "pkgRoot" options', async t => {
12-
t.deepEqual(await verify({npmPublish: true, tarballDir: 'release', pkgRoot: 'dist'}, {}, t.context.logger), []);
11+
test('Verify "npmPublish", "tarballDir", "pkgRoot" and "otpUrl" options', async t => {
12+
t.deepEqual(await verify({npmPublish: true, tarballDir: 'release', pkgRoot: 'dist', otpUrl: 'http://0.0.0.0/my-otp-provider'}, {}, t.context.logger), []);
1313
});
1414

1515
test('Return SemanticReleaseError if "npmPublish" option is not a Boolean', async t => {
@@ -36,6 +36,14 @@ test('Return SemanticReleaseError if "pkgRoot" option is not a String', async t
3636
t.is(error.code, 'EINVALIDPKGROOT');
3737
});
3838

39+
test('Return SemanticReleaseError if "otpUrl" option is not a String', async t => {
40+
const otpUrl = 42;
41+
const [error] = await verify({otpUrl}, {}, t.context.logger);
42+
43+
t.is(error.name, 'SemanticReleaseError');
44+
t.is(error.code, 'EINVALIDOTPURL');
45+
});
46+
3947
test('Return SemanticReleaseError Array if multiple config are invalid', async t => {
4048
const npmPublish = 42;
4149
const tarballDir = 42;

0 commit comments

Comments
 (0)