From 7b19d20e9569f974aad5a4bffef1d7e151b45fda Mon Sep 17 00:00:00 2001 From: Juan Carlos Blanco Delgado Date: Sat, 14 Dec 2024 19:36:37 +0000 Subject: [PATCH] feat: checking for extends options to be type of string Fixes #1180 --- lib/index.js | 2 +- test/tasks.interactive.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 151733d5..7e883127 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,7 +14,7 @@ const runTasks = async (opts, di) => { Object.assign(container, di); container.config = container.config || new Config(opts); - if ('extends' in container.config.options) { + if (typeof container.config.options?.extends === 'string') { /** * If the configuration has an 'extends' property, fetch the remote configuration * and merge it into the local configuration options. diff --git a/test/tasks.interactive.js b/test/tasks.interactive.js index c94149cd..388643b0 100644 --- a/test/tasks.interactive.js +++ b/test/tasks.interactive.js @@ -113,6 +113,8 @@ test.serial('should run tasks using extended configuration', async t => { const { name, latestVersion, version } = await runTasks({}, container); + t.is(fetchStub.callCount, 1); + const commands = _.flatten(exec.args).filter(arg => typeof arg === 'string' && arg.startsWith('echo')); t.true(commands.includes(validationExtendedConfiguration)); @@ -124,6 +126,29 @@ test.serial('should run tasks using extended configuration', async t => { fetchStub.restore(); }); +test.serial('should run tasks not using extended configuration as it is not a string', async t => { + sh.mv('.git', 'foo'); + + const fetchStub = sandbox.stub(global, 'fetch'); + + const config = { + $schema: 'https://unpkg.com/release-it@17/schema/release-it.json', + extends: false + }; + + const container = getContainer(config); + + const { name, latestVersion, version } = await runTasks({}, container); + + t.is(fetchStub.callCount, 0); + + t.is(version, '0.0.1'); + t.true(log.obtrusive.firstCall.args[0].includes(`release ${name} (currently at ${latestVersion})`)); + t.regex(log.log.lastCall.args[0], /Done \(in [0-9]+s\.\)/); + + fetchStub.restore(); +}); + test.serial('should not run hooks for disabled release-cycle methods', async t => { const hooks = getHooks(['version', 'git', 'github', 'gitlab', 'npm']);