Skip to content

Commit

Permalink
Fix CLI option passing (#58)
Browse files Browse the repository at this point in the history
* Fix CLI option passing
  • Loading branch information
Noviny committed May 31, 2019
1 parent 9fb57d7 commit c00e65e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .changeset/92ba93d7/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"releases": [{ "name": "@changesets/cli", "type": "patch" }],
"dependents": []
}
1 change: 1 addition & 0 deletions .changeset/92ba93d7/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where unprovided command line options overrode the config file, leading to incorrect states
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# I rolled all of the file updates into a single function! BUT there are no tests for dependents being updated

Check
2 changes: 2 additions & 0 deletions packages/cli/src/commands/bump/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import { defaultConfig } from "../../utils/constants";

export default async function version(opts) {
let userConfig = await resolveConfig(opts.cwd);

userConfig =
userConfig && userConfig.versionOptions ? userConfig.versionOptions : {};
const config = { ...defaultConfig.versionOptions, ...userConfig, ...opts };

const cwd = config.cwd || process.cwd();
const allPackages = await bolt.getWorkspaces({ cwd });
const changesetBase = await getChangesetBase(cwd);
Expand Down
44 changes: 37 additions & 7 deletions packages/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ const { input, flags } = meow(
{
flags: {
commit: {
type: "boolean"
type: "boolean",
// Command line options need to be undefined, otherwise their
// default value overrides the user's provided config in their
// config file
default: undefined
},
updateChangelog: {
type: "boolean",
default: true
default: undefined
},
skipCI: {
type: "boolean"
type: "boolean",
default: undefined
},
public: {
type: "boolean"
type: "boolean",
default: undefined
},
sinceMaster: {
type: "boolean"
Expand Down Expand Up @@ -69,21 +75,45 @@ const cwd = process.cwd();
output
} = flags;

// Command line options need to be undefined, otherwise their
// default value overrides the user's provided config in their
// config file. For this reason, we only assign them to this
// object as and when they exist.
const config = { cwd };

switch (input[0]) {
case "init": {
await init({ cwd });
return;
}
case "add": {
await add({ cwd, commit });
if (commit !== undefined) {
config.commit = commit;
}
await add(config);
return;
}
case "bump": {
await bump({ cwd, updateChangelog, skipCI, commit });
// We only assign them to this
// object as and when they exist.
if (updateChangelog !== undefined) {
config.updateChangelog = updateChangelog;
}
if (skipCI !== undefined) {
config.skipCI = skipCI;
}
if (commit !== undefined) {
config.commit = commit;
}
await bump(config);
return;
}
case "release": {
await release({ cwd, public: isPublic });
if (isPublic !== undefined) {
// This exists as
config.public = isPublic;
}
await release(config);
return;
}
case "status": {
Expand Down

0 comments on commit c00e65e

Please sign in to comment.