Skip to content

Commit

Permalink
fix(overrides): removed the deprecated ability to provide overrides f…
Browse files Browse the repository at this point in the history
…or certain config options

BREAKING CHANGE: the deprecated ability to provide `overrides` has now been removed. use `decisions`
instead
  • Loading branch information
travi committed Sep 2, 2024
1 parent 1eeac4a commit 432eb6c
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 146 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const {
packageTypes: {},
packageBundlers: {}
},
overrides: {npmAccount: accountName},
ciServices: {},
decisions: {
[questionNames.DIALECT]: dialects.BABEL,
Expand Down
16 changes: 0 additions & 16 deletions docs/api/scaffold.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Language scaffolder for JavaScript projects
* [`babelPreset` __object__ (_optional_)](#babelpreset-object-optional)
* [`typescript`: __object__ (_optional_)](#typescript-object-optional)
* [`remark`: __string__ (_optional_)](#remark-string-optional)
* [`overrides` __object__ (_optional_)](#overrides-object-optional)

## Arguments

Expand Down Expand Up @@ -159,18 +158,3 @@ to be used for the project

name of the package to use as a preset for configuring [remark](https://remark.js.org/)
in the scaffolded project

### `overrides` __object__ (_optional_)

__DEPRECATED__ use [decisions](#decisions-object-optional) instead

* `npmAccount` __string__ (_optional_)
the account the package should be published under. used to suggest a
[scope](https://docs.npmjs.com/misc/scope). defaults to `$ npm whoami`
* `author` __object__ (_optional_)
[details](https://docs.npmjs.com/files/package.json#people-fields-author-contributors)
about the package author

* `name` __string__ (_required_) defaults to `$npm config get init.author.name`
* `email` __string__ (_optional_) defaults to `$npm config get init.author.email`
* `url` __string__ (_optional_) defaults to `$npm config get init.author.url`
1 change: 0 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const {
packageTypes: {},
packageBundlers: {}
},
overrides: {npmAccount: accountName},
ciServices: {},
decisions: {
[questionNames.DIALECT]: dialects.BABEL,
Expand Down
70 changes: 0 additions & 70 deletions src/options-validator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,75 +444,6 @@ suite('options validator', () => {
});
});

suite('overrides', () => {
const email = any.email();

test('that `npmAccount` can be overridden', () => {
validate({
projectRoot: any.string(),
projectName: any.string(),
visibility: any.fromList(['Public', 'Private']),
license: any.string(),
vcs: {host: any.word(), owner: any.word(), name: any.word()},
description: any.string(),
overrides: {npmAccount: any.word()}
});
});

suite('author', () => {
test('that `author` can be overridden', () => {
validate({
projectRoot: any.string(),
projectName: any.string(),
visibility: any.fromList(['Public', 'Private']),
license: any.string(),
vcs: {host: any.word(), owner: any.word(), name: any.word()},
description: any.string(),
overrides: {author: {name: any.string(), email, url: any.url()}}
});
});
});

test('that `author.name` is required', () => assert.throws(
() => validate({
projectRoot: any.string(),
projectName: any.string(),
visibility: any.fromList(['Public', 'Private']),
license: any.string(),
vcs: {host: any.word(), owner: any.word(), name: any.word()},
description: any.string(),
overrides: {author: {}}
}),
'"overrides.author.name" is required'
));

test('that `author.email` must be an email address when provided', () => assert.throws(
() => validate({
projectRoot: any.string(),
projectName: any.string(),
visibility: any.fromList(['Public', 'Private']),
license: any.string(),
vcs: {host: any.word(), owner: any.word(), name: any.word()},
description: any.string(),
overrides: {author: {name: any.string(), email: any.word()}}
}),
'"overrides.author.email" must be a valid email'
));

test('that `author.url` must be a valid uri when provided', () => assert.throws(
() => validate({
projectRoot: any.string(),
projectName: any.string(),
visibility: any.fromList(['Public', 'Private']),
license: any.string(),
vcs: {host: any.word(), owner: any.word(), name: any.word()},
description: any.string(),
overrides: {author: {name: any.string(), email, url: any.string()}}
}),
'"overrides.author.url" must be a valid uri'
));
});

suite('ci services', () => {
const ciServiceName = any.word();

Expand Down Expand Up @@ -902,7 +833,6 @@ suite('options validator', () => {
{
...options,
configs: {},
overrides: {},
plugins: {
applicationTypes: {},
packageTypes: {},
Expand Down
10 changes: 0 additions & 10 deletions src/options-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ export function validate(options) {
remark: joi.string()
}).default({})
})
.keys({
overrides: joi.object({
npmAccount: joi.string(),
author: joi.object({
name: joi.string().required(),
email: joi.string().email(),
url: joi.string().uri()
})
}).default({})
})
.keys({
ciServices: joi.object().pattern(/^/, joi.object({
scaffolder: joi.func().arity(1).required(),
Expand Down
45 changes: 5 additions & 40 deletions src/prompts/questions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ suite('prompts', () => {
.resolves({...answers, [questionNames.CONFIGURE_LINTING]: any.word()});

assert.deepEqual(
await prompt({}, ciServices, hosts, visibility, vcs, decisions, configs),
await prompt(ciServices, hosts, visibility, vcs, decisions, configs),
{
tests,
projectType,
Expand All @@ -201,7 +201,7 @@ suite('prompts', () => {
prompts.prompt.resolves({...answers, [questionNames.CONFIGURE_LINTING]: false});

assert.deepEqual(
await prompt({}, ciServices, {}, visibility, vcs, decisions),
await prompt(ciServices, {}, visibility, vcs, decisions),
{
tests,
projectType,
Expand All @@ -218,41 +218,6 @@ suite('prompts', () => {
);
});

test('that defaults are overridden by the provided options', async () => {
const npmAccount = any.word();
const authorOverrides = {name: any.string(), email: any.string(), url: any.url()};
const get = sinon.stub();
npmConf.default.returns({get});
prompts.prompt.resolves(answers);

await prompt({npmAccount, author: authorOverrides}, ciServices, {}, visibility, vcs, {});

assert.calledWith(
prompts.prompt,
sinon.match(value => 1 === value.filter((
question => questionNames.SCOPE === question.name && npmAccount === question.default
)).length)
);
assert.calledWith(
prompts.prompt,
sinon.match(value => 1 === value.filter((
question => questionNames.AUTHOR_NAME === question.name && authorOverrides.name === question.default
)).length)
);
assert.calledWith(
prompts.prompt,
sinon.match(value => 1 === value.filter((
question => questionNames.AUTHOR_EMAIL === question.name && authorOverrides.email === question.default
)).length)
);
assert.calledWith(
prompts.prompt,
sinon.match(value => 1 === value.filter((
question => questionNames.AUTHOR_URL === question.name && authorOverrides.url === question.default
)).length)
);
});

test('that sub-projects are not asked about node version since already defined by the parent project', async () => {
execa.default.withArgs('npm', ['whoami']).resolves({stdout: any.word()});
npmConf.default.returns({get: () => undefined});
Expand All @@ -261,7 +226,7 @@ suite('prompts', () => {
.returns(commonQuestions);
prompts.prompt.resolves(answers);

await prompt({}, ciServices, {}, 'Private', vcs, null, null, pathWithinParent);
await prompt(ciServices, {}, 'Private', vcs, null, null, pathWithinParent);

assert.neverCalledWith(
prompts.prompt,
Expand All @@ -277,7 +242,7 @@ suite('prompts', () => {
.returns(commonQuestions);
prompts.prompt.resolves(answers);

await prompt({}, ciServices, {}, 'Private', vcs, null, null, pathWithinParent);
await prompt(ciServices, {}, 'Private', vcs, null, null, pathWithinParent);

assert.neverCalledWith(
prompts.prompt,
Expand All @@ -293,7 +258,7 @@ suite('prompts', () => {
.returns(commonQuestions);
prompts.prompt.resolves(answers);

await prompt({}, ciServices, {}, 'Public', vcs, {}, null, pathWithinParent);
await prompt(ciServices, {}, 'Public', vcs, {}, null, pathWithinParent);

assert.calledWith(
prompts.prompt,
Expand Down
5 changes: 2 additions & 3 deletions src/prompts/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function authorQuestions({name, email, url}) {
}

export async function prompt(
{npmAccount, author},
ciServices,
hosts,
visibility,
Expand Down Expand Up @@ -114,9 +113,9 @@ export async function prompt(
message: 'What is the scope?',
when: scopePromptShouldBePresentedFactory(visibility),
validate: validateScope(visibility),
default: npmAccount || maybeLoggedInNpmUsername
default: maybeLoggedInNpmUsername
},
...authorQuestions(author || {
...authorQuestions({
name: npmConf.get('init.author.name'),
email: npmConf.get('init.author.email'),
url: npmConf.get('init.author.url')
Expand Down
4 changes: 1 addition & 3 deletions src/scaffolder/scaffolder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ suite('javascript project scaffolder', () => {
const tests = {unit: unitTested, integration: integrationTested};
const vcsDetails = any.simpleObject();
const chosenCiService = any.word();
const overrides = any.simpleObject();
const description = any.sentence();
const babelPresetName = any.string();
const babelPreset = {name: babelPresetName};
Expand Down Expand Up @@ -197,7 +196,7 @@ suite('javascript project scaffolder', () => {
.resolves(projectTypePluginResults);
packageScaffolder.default.withArgs(packageScaffoldingInputs).resolves(any.simpleObject());
prompts.prompt
.withArgs(overrides, ciServices, hosts, visibility, vcsDetails, decisions, configs, pathWithinParent)
.withArgs(ciServices, hosts, visibility, vcsDetails, decisions, configs, pathWithinParent)
.resolves(commonPromptAnswers);
jsCore.scaffoldChoice
.withArgs(
Expand Down Expand Up @@ -259,7 +258,6 @@ suite('javascript project scaffolder', () => {
unitTestFrameworks
},
ciServices,
overrides,
hosts,
projectName,
license,
Expand Down
3 changes: 1 addition & 2 deletions src/scaffolder/scaffolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default async function (options) {
vcs,
description,
configs,
overrides,
ciServices,
hosts,
decisions,
Expand All @@ -58,7 +57,7 @@ export default async function (options) {
provideExample,
packageManager,
dialect
} = await prompt(overrides, ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);
} = await prompt(ciServices, hosts, visibility, vcs, decisions, configs, pathWithinParent);

info('Writing project files', {level: 'secondary'});

Expand Down

0 comments on commit 432eb6c

Please sign in to comment.