Skip to content

Commit 3fb6584

Browse files
committed
feat: introduce log-level config option
1 parent fb95190 commit 3fb6584

11 files changed

+100
-92
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ Alternatively some options may be set via CLI flags.
3636

3737
### Options
3838

39-
| Option | Type | CLI Flag | Description |
40-
| ------ | ---- | -------- | ----------- |
41-
| dryRun | `boolean` | `--dry-run` | Dry run mode. |
42-
| debug | `boolean` | `--debug` | Output debugging information. |
43-
| silent | `boolean` | `--silent` | Do not print configuration information. |
44-
| extends | `String \| Array` | N/A | List of modules or file paths containing a shareable configuration. If multiple shareable configurations are set, they will be imported in the order defined with each configuration option taking precedence over the options defined in the previous. |
45-
| sequentialInit | `boolean` | `--sequential-init` | Avoid hypothetical concurrent initialization collisions. |
46-
| sequentialPrepare | `boolean` | `--sequential-prepare` | Avoid hypothetical concurrent preparation collisions. **True by default.** |
47-
| firstParent | `boolean` | `--first-parent` | Apply commit filtering to current branch only. |
48-
| ignorePrivate | `boolean` | `--ignore-private` | Exclude private packages. **True by default.** |
49-
| ignorePackages | `String \| Array` | `--ignore-packages` | Packages list to be ignored on bumping process (appended to the ones that already exist at package.json workspaces). If using the CLI flag, supply a comma seperated list of strings. |
50-
| tagFormat | `String` | `--tag-format` | Format to use when creating tag names. Should include "name" and "version" vars. Default: `"${name}@${version}"` which generates "[email protected]" |
51-
| deps | `Object` | N/A | Depedency handling, see below for possible values. |
39+
| Option | Type | CLI Flag | Description |
40+
|-------------------|-------------------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
41+
| dryRun | `boolean` | `--dry-run` | Dry run mode. |
42+
| logLevel | `String` | `--log-level` | Sets the internal logger verbosity level: `error, warn, info, debug, trace`. Defaults to `info`. |
43+
| debug | `boolean` | `--debug` | Output debugging information. Shortcut for `--logLevel=debug`. |
44+
| silent | `boolean` | `--silent` | Do not print configuration information. Shortcut for `--logLevel=error`. |
45+
| extends | `String \| Array` | N/A | List of modules or file paths containing a shareable configuration. If multiple shareable configurations are set, they will be imported in the order defined with each configuration option taking precedence over the options defined in the previous. |
46+
| sequentialInit | `boolean` | `--sequential-init` | Avoid hypothetical concurrent initialization collisions. |
47+
| sequentialPrepare | `boolean` | `--sequential-prepare` | Avoid hypothetical concurrent preparation collisions. **True by default.** |
48+
| firstParent | `boolean` | `--first-parent` | Apply commit filtering to current branch only. |
49+
| ignorePrivate | `boolean` | `--ignore-private` | Exclude private packages. **True by default.** |
50+
| ignorePackages | `String \| Array` | `--ignore-packages` | Packages list to be ignored on bumping process (appended to the ones that already exist at package.json workspaces). If using the CLI flag, supply a comma seperated list of strings. |
51+
| tagFormat | `String` | `--tag-format` | Format to use when creating tag names. Should include "name" and "version" vars. Default: `"${name}@${version}"` which generates "[email protected]" |
52+
| deps | `Object` | N/A | Dependency handling, see below for possible values. |
5253

5354
### `deps` Options
5455

lib/createInlinePluginCreator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import dbg from "debug";
21
import getCommitsFiltered from "./getCommitsFiltered.js";
32
import { updateManifestDeps, resolveReleaseType } from "./updateDeps.js";
3+
import { logger } from "./logger.js";
44

5-
const debug = dbg("msr:inlinePlugin");
5+
const { debug } = logger.withScope("msr:inlinePlugin");
66

77
/**
88
* Create an inline plugin creator for a multirelease.
@@ -49,7 +49,7 @@ function createInlinePluginCreator(packages, multiContext, flags) {
4949
Object.assign(context.options, context.options._pkgOptions);
5050

5151
// And bind the actual logger.
52-
Object.assign(pkg.loggerRef, context.logger);
52+
Object.assign(pkg.fakeLogger, context.logger);
5353

5454
const res = await plugins.verifyConditions(context);
5555
pkg._ready = true;

lib/getCommitsFiltered.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import getStream from "get-stream";
44
import { execa } from "execa";
55
import { check, ValueError } from "./blork.js";
66
import cleanPath from "./cleanPath.js";
7-
import dbg from "debug";
7+
import { logger } from "./logger.js";
88

9-
const debug = dbg("msr:commitsFilter");
9+
const { debug } = logger.withScope("msr:commitsFilter");
1010

1111
/**
1212
* Retrieve the list of commits on the current branch since the commit sha associated with the last release, or all the commits of the current branch if there is no last released version.

lib/getConfigSemantic.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import semanticGetConfig from "semantic-release/lib/get-config.js";
22
import { WritableStreamBuffer } from "stream-buffers";
3+
import { logger } from "./logger.js";
34
import signale from "signale";
45

56
const { Signale } = signale;
@@ -14,7 +15,7 @@ const { Signale } = signale;
1415
*
1516
* @internal
1617
*/
17-
async function getConfigSemantic({ cwd, env, stdout, stderr, logger }, options) {
18+
async function getConfigSemantic({ cwd, env, stdout, stderr }, options) {
1819
try {
1920
// Blackhole logger (so we don't clutter output with "loaded plugin" messages).
2021
const blackhole = new Signale({ stream: new WritableStreamBuffer() });
@@ -24,7 +25,7 @@ async function getConfigSemantic({ cwd, env, stdout, stderr, logger }, options)
2425
} catch (error) {
2526
// Log error and rethrow it.
2627
// istanbul ignore next (not important)
27-
logger.error(`Error in semantic-release getConfig(): %0`, error);
28+
logger.failure(`Error in semantic-release getConfig(): %0`, error);
2829
// istanbul ignore next (not important)
2930
throw error;
3031
}

lib/getLogger.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

lib/glob.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/logger.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import dbg from "debug";
2+
import singnale from "signale";
3+
4+
const { Signale } = singnale;
5+
const severityOrder = ["error", "warn", "info", "debug", "trace"];
6+
const assertLevel = (level, limit) => severityOrder.indexOf(level) <= severityOrder.indexOf(limit);
7+
const aliases = {
8+
failure: "error",
9+
log: "info",
10+
success: "info",
11+
complete: "info",
12+
};
13+
14+
export const logger = {
15+
prefix: "msr:",
16+
config: {
17+
_level: "info",
18+
_stderr: process.stderr,
19+
_stdout: process.stdout,
20+
_signale: {},
21+
set level(l) {
22+
if (assertLevel(l, "debug")) {
23+
dbg.enable("msr:");
24+
}
25+
if (assertLevel(l, "trace")) {
26+
dbg.enable("semantic-release:");
27+
}
28+
this._level = l;
29+
},
30+
get level() {
31+
return this._level;
32+
},
33+
set stdio([stderr, stdout]) {
34+
this._stdout = stdout;
35+
this._stderr = stderr;
36+
this._signale = new Signale({
37+
config: { displayTimestamp: true, displayLabel: false },
38+
// scope: "multirelease",
39+
stream: stdout,
40+
types: {
41+
error: { color: "red", label: "", stream: [stderr] },
42+
log: { color: "magenta", label: "", stream: [stdout], badge: "•" },
43+
success: { color: "green", label: "", stream: [stdout] },
44+
complete: { color: "green", label: "", stream: [stdout], badge: "🎉" },
45+
},
46+
});
47+
},
48+
get stdio() {
49+
return [this._stderr, this._stdout];
50+
},
51+
},
52+
withScope(prefix) {
53+
return {
54+
...this,
55+
prefix,
56+
debug: dbg(prefix || this.prefix),
57+
};
58+
},
59+
...[...severityOrder, ...Object.keys(aliases)].reduce((m, l) => {
60+
m[l] = function (...args) {
61+
if (assertLevel(aliases[l] || l, this.config.level)) {
62+
(this.config._signale[l] || console[l] || (() => {}))(this.prefix, ...args);
63+
}
64+
};
65+
return m;
66+
}, {}),
67+
debug: dbg("msr:"),
68+
};

lib/multiSemanticRelease.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { uniq, template, sortBy } from "lodash-es";
33
import { topo } from "@semrel-extra/topo";
44
import { dirname, join } from "path";
55
import { check } from "./blork.js";
6-
import getLogger from "./getLogger.js";
6+
import { logger } from "./logger.js";
77
import getConfig from "./getConfig.js";
88
import getConfigMultiSemrel from "./getConfigMultiSemrel.js";
99
import getConfigSemantic from "./getConfigSemantic.js";
@@ -52,6 +52,9 @@ async function multiSemanticRelease(
5252
{ cwd = process.cwd(), env = process.env, stdout = process.stdout, stderr = process.stderr } = {},
5353
_flags
5454
) {
55+
// Setup logger.
56+
logger.config.stdio = [stderr, stdout];
57+
5558
// Check params.
5659
if (paths) {
5760
check(paths, "paths: string[]");
@@ -92,7 +95,6 @@ async function multiSemanticRelease(
9295
paths = paths || Object.values(_packages).map((pkg) => pkg.manifestPath);
9396

9497
// Start.
95-
const logger = getLogger({ stdout, stderr });
9698
logger.complete(`Started multirelease! Loading ${paths.length} packages...`);
9799

98100
// Load packages from paths.
@@ -164,14 +166,14 @@ async function getPackage(path, { globalOptions, inputOptions, env, cwd, stdout,
164166
const finalOptions = Object.assign({}, globalOptions, pkgOptions, inputOptions);
165167

166168
// Make a fake logger so semantic-release's get-config doesn't fail.
167-
const logger = { error() {}, log() {} };
169+
const fakeLogger = { error() {}, log() {} };
168170

169171
// Use semantic-release's internal config with the final options (now we have the right `options.plugins` setting) to get the plugins object and the options including defaults.
170172
// We need this so we can call e.g. plugins.analyzeCommit() to be able to affect the input and output of the whole set of plugins.
171-
const { options, plugins } = await getConfigSemantic({ cwd: dir, env, stdout, stderr, logger }, finalOptions);
173+
const { options, plugins } = await getConfigSemantic({ cwd: dir, env, stdout, stderr }, finalOptions);
172174

173175
// Return package object.
174-
return { path, dir, name, manifest, deps, options, plugins, loggerRef: logger };
176+
return { path, dir, name, manifest, deps, options, plugins, fakeLogger: fakeLogger };
175177
}
176178

177179
/**

lib/updateDeps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { writeFileSync } from "fs";
2-
import dbg from "debug";
32
import semver from "semver";
43
import { isObject, isEqual, transform } from "lodash-es";
54
import recognizeFormat from "./recognizeFormat.js";
65
import getManifest from "./getManifest.js";
76
import { getHighestVersion, getLatestVersion } from "./utils.js";
87
import { getTags } from "./git.js";
8+
import { logger } from "./logger.js";
99

10-
const debug = dbg("msr:updateDeps");
10+
const { debug } = logger.withScope("msr:updateDeps");
1111

1212
/**
1313
* Resolve next package version.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"execa": "^6.1.0",
6464
"get-stream": "^6.0.1",
6565
"git-log-parser": "^1.2.0",
66-
"globby": "13.1.4",
6766
"lodash-es": "^4.17.21",
6867
"meow": "^10.1.2",
6968
"promise-events": "^0.2.4",

yarn.lock

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,17 +2956,6 @@ fast-glob@^3.1.1:
29562956
merge2 "^1.3.0"
29572957
micromatch "^4.0.4"
29582958

2959-
fast-glob@^3.2.11:
2960-
version "3.2.11"
2961-
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
2962-
integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==
2963-
dependencies:
2964-
"@nodelib/fs.stat" "^2.0.2"
2965-
"@nodelib/fs.walk" "^1.2.3"
2966-
glob-parent "^5.1.2"
2967-
merge2 "^1.3.0"
2968-
micromatch "^4.0.4"
2969-
29702959
fast-glob@^3.2.12:
29712960
version "3.2.12"
29722961
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80"
@@ -3272,17 +3261,6 @@ globals@^13.19.0:
32723261
dependencies:
32733262
type-fest "^0.20.2"
32743263

3275-
3276-
version "13.1.4"
3277-
resolved "https://registry.yarnpkg.com/globby/-/globby-13.1.4.tgz#2f91c116066bcec152465ba36e5caa4a13c01317"
3278-
integrity sha512-iui/IiiW+QrJ1X1hKH5qwlMQyv34wJAYwH1vrf8b9kBA4sNiif3gKsMHa+BrdnOpEudWjpotfa7LrTzB1ERS/g==
3279-
dependencies:
3280-
dir-glob "^3.0.1"
3281-
fast-glob "^3.2.11"
3282-
ignore "^5.2.0"
3283-
merge2 "^1.4.1"
3284-
slash "^4.0.0"
3285-
32863264
globby@^11.0.0, globby@^11.0.1:
32873265
version "11.0.4"
32883266
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5"
@@ -4618,7 +4596,7 @@ merge-stream@^2.0.0:
46184596
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
46194597
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==
46204598

4621-
merge2@^1.3.0, merge2@^1.4.1:
4599+
merge2@^1.3.0:
46224600
version "1.4.1"
46234601
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
46244602
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
@@ -5906,11 +5884,6 @@ slash@^3.0.0:
59065884
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
59075885
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==
59085886

5909-
slash@^4.0.0:
5910-
version "4.0.0"
5911-
resolved "https://registry.yarnpkg.com/slash/-/slash-4.0.0.tgz#2422372176c4c6c5addb5e2ada885af984b396a7"
5912-
integrity sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==
5913-
59145887
smart-buffer@^4.2.0:
59155888
version "4.2.0"
59165889
resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae"

0 commit comments

Comments
 (0)