Files
2026-03-22 03:21:45 +02:00

89 lines
1.8 KiB
JavaScript

"use strict";
// Minimal CommonJS shim for Chalk.
//
// Pulsar/Atom's compile-cache loads packages via CommonJS `require()`.
// `chalk@5` is ESM-only and crashes with `import` syntax errors.
//
// This shim provides a callable function with common style properties
// (e.g. chalk.red, chalk.green, chalk.underline, etc.). It does NOT emit ANSI
// codes; it simply concatenates inputs into plain strings.
function joinArgs(args) {
return args
.map(function (value) {
return value === undefined ? "" : String(value);
})
.join(" ");
}
function chalk() {
// Support template tag usage: chalk`hello ${name}`
if (
arguments.length > 0 &&
Array.isArray(arguments[0]) &&
Object.prototype.hasOwnProperty.call(arguments[0], "raw")
) {
var strings = arguments[0];
var out = "";
for (var i = 0; i < strings.length; i++) {
out += strings[i];
if (i + 1 < arguments.length) out += String(arguments[i + 1]);
}
return out;
}
return joinArgs([].slice.call(arguments));
}
function styleFn() {
return chalk.apply(null, arguments);
}
// Common set of style keys used by dependencies in this repo.
var STYLE_KEYS = [
"reset",
"bold",
"dim",
"italic",
"underline",
"inverse",
"hidden",
"strikethrough",
"black",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
"gray",
"grey",
];
function attachStyles(target) {
for (var i = 0; i < STYLE_KEYS.length; i++) {
target[STYLE_KEYS[i]] = styleFn;
}
// Allow chaining: chalk.red.bold.underline('x')
for (var j = 0; j < STYLE_KEYS.length; j++) {
styleFn[STYLE_KEYS[j]] = styleFn;
}
}
attachStyles(chalk);
// Chalk v5 also exports a Chalk class and helpers; provide minimal stubs.
function Chalk() {
return chalk;
}
chalk.Chalk = Chalk;
chalk.supportsColor = false;
chalk.level = 0;
module.exports = chalk;
module.exports.default = chalk;
module.exports.__esModule = true;