Skip to content

Commit 71226af

Browse files
GeeWizWowantongolub
authored andcommitted
chore: restore cli flag definitions
1 parent c98ff10 commit 71226af

File tree

2 files changed

+78
-29
lines changed

2 files changed

+78
-29
lines changed

bin/cli.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,42 @@ const cli = meow(
3535
const argvStart = process.argv.includes("--") ? process.argv.indexOf("--") + 1 : 2;
3636
return process.argv.slice(argvStart);
3737
},
38+
booleanDefault: undefined,
39+
flags: {
40+
sequentialInit: {
41+
type: "boolean",
42+
},
43+
sequentialPrepare: {
44+
type: "boolean",
45+
},
46+
firstParent: {
47+
type: "boolean",
48+
},
49+
debug: {
50+
type: "boolean",
51+
},
52+
"deps.bump": {
53+
type: "string",
54+
},
55+
"deps.release": {
56+
type: "string",
57+
},
58+
"deps.prefix": {
59+
type: "string",
60+
},
61+
ignorePrivate: {
62+
type: "boolean",
63+
},
64+
ignorePackages: {
65+
type: "string",
66+
},
67+
tagFormat: {
68+
type: "string",
69+
},
70+
dryRun: {
71+
type: "boolean",
72+
},
73+
},
3874
}
3975
);
4076

lib/getConfigMultiSemrel.js

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { cosmiconfig } from "cosmiconfig";
22
import { default as resolveFrom } from "resolve-from";
33
import { pickBy, isNil, castArray } from "lodash-es";
4+
import { createRequire } from "module";
45

56
const CONFIG_NAME = "multi-release";
67
const CONFIG_FILES = [
@@ -15,6 +16,19 @@ const CONFIG_FILES = [
1516
`${CONFIG_NAME}.config.cjs`,
1617
];
1718

19+
const mergeConfig = (a = {}, b = {}) => {
20+
return {
21+
...a,
22+
// Remove `null` and `undefined` options so they can be replaced with default ones
23+
...pickBy(b, (option) => !isNil(option)),
24+
// Treat nested objects differently as otherwise we'll loose undefined keys
25+
deps: {
26+
...a.deps,
27+
...pickBy(b.deps, (option) => !isNil(option)),
28+
},
29+
};
30+
};
31+
1832
/**
1933
* Get the multi semantic release configuration options for a given directory.
2034
*
@@ -26,42 +40,41 @@ const CONFIG_FILES = [
2640
*/
2741
export default async function getConfig(cwd, cliOptions) {
2842
const { config } = (await cosmiconfig(CONFIG_NAME, { searchPlaces: CONFIG_FILES }).search(cwd)) || {};
29-
const { extends: extendPaths, ...rest } = { ...config, ...cliOptions };
43+
const { extends: extendPaths, ...rest } = { ...config };
3044

3145
let options = rest;
3246

3347
if (extendPaths) {
34-
// If `extends` is defined, load and merge each shareable config with `options`
35-
options = {
36-
...castArray(extendPaths).reduce((result, extendPath) => {
37-
const extendsOptions = require(resolveFrom.silent(__dirname, extendPath) ||
38-
resolveFrom(cwd, extendPath));
39-
return { ...result, ...extendsOptions };
40-
}, {}),
41-
...options,
42-
};
48+
const require = createRequire(import.meta.url);
49+
// If `extends` is defined, load and merge each shareable config
50+
const extendedOptions = castArray(extendPaths).reduce((result, extendPath) => {
51+
const extendsOptions = require(resolveFrom(cwd, extendPath));
52+
return mergeConfig(result, extendsOptions);
53+
}, {});
54+
55+
options = mergeConfig(options, extendedOptions);
4356
}
4457

4558
// Set default options values if not defined yet
46-
options = {
47-
sequentialInit: false,
48-
sequentialPrepare: true,
49-
firstParent: false,
50-
debug: false,
51-
ignorePrivate: true,
52-
ignorePackages: "",
53-
tagFormat: "${name}@${version}",
54-
dryRun: false,
55-
// Remove `null` and `undefined` options so they can be replaced with default ones
56-
...pickBy(options, (option) => !isNil(option)),
57-
// Treat nested objects differently as otherwise we'll loose undefined keys
58-
deps: {
59-
bump: "override",
60-
release: "patch",
61-
prefix: "",
62-
...pickBy(options.deps, (option) => !isNil(option)),
59+
options = mergeConfig(
60+
{
61+
sequentialInit: false,
62+
sequentialPrepare: true,
63+
firstParent: false,
64+
debug: false,
65+
ignorePrivate: true,
66+
ignorePackages: "",
67+
tagFormat: "${name}@${version}",
68+
dryRun: false,
69+
deps: {
70+
bump: "override",
71+
release: "patch",
72+
prefix: "",
73+
},
6374
},
64-
};
75+
options
76+
);
6577

66-
return options;
78+
// Finally merge CLI options last so they always win
79+
return mergeConfig(options, cliOptions);
6780
}

0 commit comments

Comments
 (0)