-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@uppy/companion: remove chalk
from dependencies
#5178
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment was marked as off-topic.
This comment was marked as off-topic.
Diff output filesdiff --git a/packages/@uppy/companion/lib/server/logger.js b/packages/@uppy/companion/lib/server/logger.js
index 3abec84..7407ff0 100644
--- a/packages/@uppy/companion/lib/server/logger.js
+++ b/packages/@uppy/companion/lib/server/logger.js
@@ -1,8 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
-const chalk = require("chalk");
const escapeStringRegexp = require("escape-string-regexp");
const util = require("node:util");
+const supportsColors = require("supports-color");
const valuesToMask = [];
/**
* Adds a list of strings that should be masked by the logger.
@@ -34,6 +34,9 @@ let processName = "companion";
exports.setProcessName = (newProcessName) => {
processName = newProcessName;
};
+const styleText = typeof util.styleText === "function" && supportsColors.stderr
+ ? util.styleText
+ : (style, text) => text;
/**
* message log
*
@@ -42,9 +45,9 @@ exports.setProcessName = (newProcessName) => {
* @param {string} params.tag a unique tag to easily search for this message
* @param {string} params.level error | info | debug
* @param {string} [params.traceId] a unique id to easily trace logs tied to a request
- * @param {Function} [params.color] function to display the log in appropriate color
+ * @param {string[]} [params.color] Format(s) that can be passed to `util.styleText`.
*/
-const log = ({ arg, tag = "", level, traceId = "", color = (message) => message }) => {
+const log = ({ arg, tag = "", level, traceId = "", color = [] }) => {
const time = new Date().toISOString();
const whitespace = tag && traceId ? " " : "";
function msgToString() {
@@ -62,7 +65,10 @@ const log = ({ arg, tag = "", level, traceId = "", color = (message) => message
const msgString = msgToString();
const masked = maskMessage(msgString);
// eslint-disable-next-line no-console
- console.log(color(`${processName}: ${time} [${level}] ${traceId}${whitespace}${tag}`), color(masked));
+ console.log(
+ styleText(color, `${processName}: ${time} [${level}] ${traceId}${whitespace}${tag}`),
+ styleText(color, masked),
+ );
};
/**
* INFO level log
@@ -82,7 +88,7 @@ exports.info = (msg, tag, traceId) => {
* @param {string} [traceId] a unique id to easily trace logs tied to a request
*/
exports.warn = (msg, tag, traceId) => {
- log({ arg: msg, tag, level: "warn", traceId, color: chalk.bold.yellow });
+ log({ arg: msg, tag, level: "warn", traceId, color: ["bold", "yellow"] });
};
/**
* ERROR level log
@@ -92,7 +98,7 @@ exports.warn = (msg, tag, traceId) => {
* @param {string} [traceId] a unique id to easily trace logs tied to a request
*/
exports.error = (msg, tag, traceId) => {
- log({ arg: msg, tag, level: "error", traceId, color: chalk.bold.red });
+ log({ arg: msg, tag, level: "error", traceId, color: ["bold", "red"] });
};
/**
* DEBUG level log
@@ -103,6 +109,6 @@ exports.error = (msg, tag, traceId) => {
*/
exports.debug = (msg, tag, traceId) => {
if (process.env.NODE_ENV !== "production") {
- log({ arg: msg, tag, level: "debug", traceId, color: chalk.bold.blue });
+ log({ arg: msg, tag, level: "debug", traceId, color: ["bold", "blue"] });
}
}; |
Murderlon
reviewed
May 16, 2024
mifi
reviewed
May 21, 2024
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
github-actions bot
added a commit
that referenced
this pull request
May 23, 2024
| Package | Version | Package | Version | | ----------------- | ------------ | ----------------- | ------------ | | @uppy/companion | 5.0.0-beta.8 | @uppy/xhr-upload | 4.0.0-beta.5 | | @uppy/transloadit | 4.0.0-beta.6 | uppy | 4.0.0-beta.9 | - @uppy/companion: remove `chalk` from dependencies (Antoine du Hamel / #5178) - @uppy/transloadit: do not cancel assembly when removing all files (Merlijn Vos / #5191) - @uppy/xhr-upload: fix regression for lowercase HTTP methods (Antoine du Hamel / #5179) - meta: improve changelog generator (Antoine du Hamel / #5190)
Murderlon
added a commit
that referenced
this pull request
May 28, 2024
* 4.x: (38 commits) docs: assume tree-shaking bundler is the most common case (#5160) @uppy/core: remove `reason` (#5159) Release: uppy@4.0.0-beta.9 (#5194) Release: uppy@3.25.5 (#5193) @uppy/companion: remove `chalk` from dependencies (#5178) @uppy/transloadit: do not cancel assembly when removing all files (#5191) @uppy/xhr-upload: fix regression for lowercase HTTP methods (#5179) meta: improve changelog generator (#5190) Release: uppy@4.0.0-beta.8 (#5189) examples: add SvelteKit example (#5181) @uppy/companion: fix missing `await` Release: uppy@3.25.4 (#5188) @uppy/svelte: do not attempt removing plugin before it's created (#5186) Update facebook.mdx fixup! @uppy/tus: fix no headers passed to companion if argument is a function (#5182) @uppy/core: resolve some (breaking) TODOs (#4824) @uppy/tus: fix no headers passed to companion if argument is a function (#5182) @uppy/companion: fix google drive gsuite export large size (#5144) @uppy/companion: encode `uploadId` (#5168) @uppy/companion: bump `express-session` (#5177) ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We can use the built-in https://nodejs.org/api/util.html#utilstyletextformat-text utility – it's not (yet?) available on Node.js 18.x, so I implemented a fallback (which consists in outputing the plain text, without the colors).