diff --git a/README.md b/README.md index 1885e82..24ca3b0 100644 --- a/README.md +++ b/README.md @@ -36,19 +36,20 @@ Alternatively some options may be set via CLI flags. ### Options -| Option | Type | CLI Flag | Description | -| ------ | ---- | -------- | ----------- | -| dryRun | `boolean` | `--dry-run` | Dry run mode. | -| debug | `boolean` | `--debug` | Output debugging information. | -| silent | `boolean` | `--silent` | Do not print configuration information. | -| 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. | -| sequentialInit | `boolean` | `--sequential-init` | Avoid hypothetical concurrent initialization collisions. | -| sequentialPrepare | `boolean` | `--sequential-prepare` | Avoid hypothetical concurrent preparation collisions. **True by default.** | -| firstParent | `boolean` | `--first-parent` | Apply commit filtering to current branch only. | -| ignorePrivate | `boolean` | `--ignore-private` | Exclude private packages. **True by default.** | -| 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. | -| tagFormat | `String` | `--tag-format` | Format to use when creating tag names. Should include "name" and "version" vars. Default: `"${name}@${version}"` which generates "package-name@1.0.0" | -| deps | `Object` | N/A | Depedency handling, see below for possible values. | +| Option | Type | CLI Flag | Description | +|-------------------|-------------------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| dryRun | `boolean` | `--dry-run` | Dry run mode. | +| logLevel | `String` | `--log-level` | Sets the internal logger verbosity level: `error, warn, info, debug, trace`. Defaults to `info`. | +| debug | `boolean` | `--debug` | Output debugging information. Shortcut for `--logLevel=debug`. | +| silent | `boolean` | `--silent` | Do not print configuration information. Shortcut for `--logLevel=error`. | +| 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. | +| sequentialInit | `boolean` | `--sequential-init` | Avoid hypothetical concurrent initialization collisions. | +| sequentialPrepare | `boolean` | `--sequential-prepare` | Avoid hypothetical concurrent preparation collisions. **True by default.** | +| firstParent | `boolean` | `--first-parent` | Apply commit filtering to current branch only. | +| ignorePrivate | `boolean` | `--ignore-private` | Exclude private packages. **True by default.** | +| 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. | +| tagFormat | `String` | `--tag-format` | Format to use when creating tag names. Should include "name" and "version" vars. Default: `"${name}@${version}"` which generates "package-name@1.0.0" | +| deps | `Object` | N/A | Dependency handling, see below for possible values. | ### `deps` Options diff --git a/lib/createInlinePluginCreator.js b/lib/createInlinePluginCreator.js index d6f9c5c..05bf85d 100644 --- a/lib/createInlinePluginCreator.js +++ b/lib/createInlinePluginCreator.js @@ -1,8 +1,8 @@ -import dbg from "debug"; import getCommitsFiltered from "./getCommitsFiltered.js"; import { updateManifestDeps, resolveReleaseType } from "./updateDeps.js"; +import { logger } from "./logger.js"; -const debug = dbg("msr:inlinePlugin"); +const { debug } = logger.withScope("msr:inlinePlugin"); /** * Create an inline plugin creator for a multirelease. @@ -49,7 +49,7 @@ function createInlinePluginCreator(packages, multiContext, flags) { Object.assign(context.options, context.options._pkgOptions); // And bind the actual logger. - Object.assign(pkg.loggerRef, context.logger); + Object.assign(pkg.fakeLogger, context.logger); const res = await plugins.verifyConditions(context); pkg._ready = true; diff --git a/lib/getCommitsFiltered.js b/lib/getCommitsFiltered.js index 59436d0..65f8182 100644 --- a/lib/getCommitsFiltered.js +++ b/lib/getCommitsFiltered.js @@ -4,9 +4,9 @@ import getStream from "get-stream"; import { execa } from "execa"; import { check, ValueError } from "./blork.js"; import cleanPath from "./cleanPath.js"; -import dbg from "debug"; +import { logger } from "./logger.js"; -const debug = dbg("msr:commitsFilter"); +const { debug } = logger.withScope("msr:commitsFilter"); /** * 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. diff --git a/lib/getConfigSemantic.js b/lib/getConfigSemantic.js index 9072915..e84a30b 100644 --- a/lib/getConfigSemantic.js +++ b/lib/getConfigSemantic.js @@ -1,5 +1,6 @@ import semanticGetConfig from "semantic-release/lib/get-config.js"; import { WritableStreamBuffer } from "stream-buffers"; +import { logger } from "./logger.js"; import signale from "signale"; const { Signale } = signale; @@ -14,7 +15,7 @@ const { Signale } = signale; * * @internal */ -async function getConfigSemantic({ cwd, env, stdout, stderr, logger }, options) { +async function getConfigSemantic({ cwd, env, stdout, stderr }, options) { try { // Blackhole logger (so we don't clutter output with "loaded plugin" messages). const blackhole = new Signale({ stream: new WritableStreamBuffer() }); @@ -24,7 +25,7 @@ async function getConfigSemantic({ cwd, env, stdout, stderr, logger }, options) } catch (error) { // Log error and rethrow it. // istanbul ignore next (not important) - logger.error(`Error in semantic-release getConfig(): %0`, error); + logger.failure(`Error in semantic-release getConfig(): %0`, error); // istanbul ignore next (not important) throw error; } diff --git a/lib/getLogger.js b/lib/getLogger.js deleted file mode 100644 index a00084b..0000000 --- a/lib/getLogger.js +++ /dev/null @@ -1,29 +0,0 @@ -import signale from "signale"; -const { Signale } = signale; - -/** - * Return a new Signale instance. - * _Similar to get-logger.js in semantic-release_ - * - * @param {Stream} stdout A writable stream for output. - * @param {Stream} stderr A writable stream for errors. - * @returns {Logger} An instance of Logger - * - * @internal - */ -function getLogger({ stdout, stderr }) { - return new Signale({ - config: { displayTimestamp: true, displayLabel: false }, - // scope: "multirelease", - stream: stdout, - types: { - error: { color: "red", label: "", stream: [stderr] }, - log: { color: "magenta", label: "", stream: [stdout], badge: "•" }, - success: { color: "green", label: "", stream: [stdout] }, - complete: { color: "green", label: "", stream: [stdout], badge: "🎉" }, - }, - }); -} - -// Exports. -export default getLogger; diff --git a/lib/glob.js b/lib/glob.js deleted file mode 100644 index a8a5cf9..0000000 --- a/lib/glob.js +++ /dev/null @@ -1,7 +0,0 @@ -import { globbySync } from "globby"; - -export default (...args) => { - const [pattern, ...options] = args; - - return globbySync(pattern, ...options); -}; diff --git a/lib/logger.js b/lib/logger.js new file mode 100644 index 0000000..8013f69 --- /dev/null +++ b/lib/logger.js @@ -0,0 +1,68 @@ +import dbg from "debug"; +import singnale from "signale"; + +const { Signale } = singnale; +const severityOrder = ["error", "warn", "info", "debug", "trace"]; +const assertLevel = (level, limit) => severityOrder.indexOf(level) <= severityOrder.indexOf(limit); +const aliases = { + failure: "error", + log: "info", + success: "info", + complete: "info", +}; + +export const logger = { + prefix: "msr:", + config: { + _level: "info", + _stderr: process.stderr, + _stdout: process.stdout, + _signale: {}, + set level(l) { + if (assertLevel(l, "debug")) { + dbg.enable("msr:"); + } + if (assertLevel(l, "trace")) { + dbg.enable("semantic-release:"); + } + this._level = l; + }, + get level() { + return this._level; + }, + set stdio([stderr, stdout]) { + this._stdout = stdout; + this._stderr = stderr; + this._signale = new Signale({ + config: { displayTimestamp: true, displayLabel: false }, + // scope: "multirelease", + stream: stdout, + types: { + error: { color: "red", label: "", stream: [stderr] }, + log: { color: "magenta", label: "", stream: [stdout], badge: "•" }, + success: { color: "green", label: "", stream: [stdout] }, + complete: { color: "green", label: "", stream: [stdout], badge: "🎉" }, + }, + }); + }, + get stdio() { + return [this._stderr, this._stdout]; + }, + }, + withScope(prefix) { + return { + ...this, + prefix, + debug: dbg(prefix || this.prefix), + }; + }, + ...[...severityOrder, ...Object.keys(aliases)].reduce((m, l) => { + m[l] = function (...args) { + if (assertLevel(aliases[l] || l, this.config.level)) { + (this.config._signale[l] || console[l] || (() => {}))(this.prefix, ...args); + } + }; + return m; + }, {}), + debug: dbg("msr:"), +}; diff --git a/lib/multiSemanticRelease.js b/lib/multiSemanticRelease.js index 6d412ed..4164a30 100644 --- a/lib/multiSemanticRelease.js +++ b/lib/multiSemanticRelease.js @@ -3,7 +3,7 @@ import { uniq, template, sortBy } from "lodash-es"; import { topo } from "@semrel-extra/topo"; import { dirname, join } from "path"; import { check } from "./blork.js"; -import getLogger from "./getLogger.js"; +import { logger } from "./logger.js"; import getConfig from "./getConfig.js"; import getConfigMultiSemrel from "./getConfigMultiSemrel.js"; import getConfigSemantic from "./getConfigSemantic.js"; @@ -52,6 +52,9 @@ async function multiSemanticRelease( { cwd = process.cwd(), env = process.env, stdout = process.stdout, stderr = process.stderr } = {}, _flags ) { + // Setup logger. + logger.config.stdio = [stderr, stdout]; + // Check params. if (paths) { check(paths, "paths: string[]"); @@ -92,7 +95,6 @@ async function multiSemanticRelease( paths = paths || Object.values(_packages).map((pkg) => pkg.manifestPath); // Start. - const logger = getLogger({ stdout, stderr }); logger.complete(`Started multirelease! Loading ${paths.length} packages...`); // Load packages from paths. @@ -164,14 +166,14 @@ async function getPackage(path, { globalOptions, inputOptions, env, cwd, stdout, const finalOptions = Object.assign({}, globalOptions, pkgOptions, inputOptions); // Make a fake logger so semantic-release's get-config doesn't fail. - const logger = { error() {}, log() {} }; + const fakeLogger = { error() {}, log() {} }; // 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. // 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. - const { options, plugins } = await getConfigSemantic({ cwd: dir, env, stdout, stderr, logger }, finalOptions); + const { options, plugins } = await getConfigSemantic({ cwd: dir, env, stdout, stderr }, finalOptions); // Return package object. - return { path, dir, name, manifest, deps, options, plugins, loggerRef: logger }; + return { path, dir, name, manifest, deps, options, plugins, fakeLogger: fakeLogger }; } /** diff --git a/lib/updateDeps.js b/lib/updateDeps.js index 8ea866d..3628651 100644 --- a/lib/updateDeps.js +++ b/lib/updateDeps.js @@ -1,13 +1,13 @@ import { writeFileSync } from "fs"; -import dbg from "debug"; import semver from "semver"; import { isObject, isEqual, transform } from "lodash-es"; import recognizeFormat from "./recognizeFormat.js"; import getManifest from "./getManifest.js"; import { getHighestVersion, getLatestVersion } from "./utils.js"; import { getTags } from "./git.js"; +import { logger } from "./logger.js"; -const debug = dbg("msr:updateDeps"); +const { debug } = logger.withScope("msr:updateDeps"); /** * Resolve next package version. diff --git a/package.json b/package.json index 7622a2f..a08af61 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "execa": "^6.1.0", "get-stream": "^6.0.1", "git-log-parser": "^1.2.0", - "globby": "13.1.4", "lodash-es": "^4.17.21", "meow": "^10.1.2", "promise-events": "^0.2.4", diff --git a/yarn.lock b/yarn.lock index 27ad707..a836e92 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2956,17 +2956,6 @@ fast-glob@^3.1.1: merge2 "^1.3.0" micromatch "^4.0.4" -fast-glob@^3.2.11: - version "3.2.11" - resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9" - integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew== - dependencies: - "@nodelib/fs.stat" "^2.0.2" - "@nodelib/fs.walk" "^1.2.3" - glob-parent "^5.1.2" - merge2 "^1.3.0" - micromatch "^4.0.4" - fast-glob@^3.2.12: version "3.2.12" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80" @@ -3272,17 +3261,6 @@ globals@^13.19.0: dependencies: type-fest "^0.20.2" -globby@13.1.4: - version "13.1.4" - resolved "https://registry.yarnpkg.com/globby/-/globby-13.1.4.tgz#2f91c116066bcec152465ba36e5caa4a13c01317" - integrity sha512-iui/IiiW+QrJ1X1hKH5qwlMQyv34wJAYwH1vrf8b9kBA4sNiif3gKsMHa+BrdnOpEudWjpotfa7LrTzB1ERS/g== - dependencies: - dir-glob "^3.0.1" - fast-glob "^3.2.11" - ignore "^5.2.0" - merge2 "^1.4.1" - slash "^4.0.0" - globby@^11.0.0, globby@^11.0.1: version "11.0.4" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5" @@ -4618,7 +4596,7 @@ merge-stream@^2.0.0: resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== -merge2@^1.3.0, merge2@^1.4.1: +merge2@^1.3.0: version "1.4.1" resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== @@ -5906,11 +5884,6 @@ slash@^3.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== -slash@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/slash/-/slash-4.0.0.tgz#2422372176c4c6c5addb5e2ada885af984b396a7" - integrity sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew== - smart-buffer@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae"