yargs / cliui

easily create complex multi-column command-line-interfaces.
ISC License
371 stars 41 forks source link

cliui remove kleur colors (ESM project) #113

Open fraxken opened 3 years ago

fraxken commented 3 years ago

Hello 👋

The package cliui remove "some" colors when working with ESM. Everything is fine with CJS. I found the problem on a CLI project I just migrated and I couldn't understand why my colors were not working anymore.

I'm working on Windows 10 and Node.js v16


How to reproduce:

$ mkdir cliui_bug
$ cd cliui_bug
$ npm init -y
$ npm i kleur cliui -P
# Add type: module in package.json 

The index.js file

import kleur from "kleur";
import cliui from "cliui";
// const kleur = require("kleur");
// const cliui = require("cliui");

const { white, cyan, red } = kleur;

const ui = cliui();

const title = `${white().bold("name:")} ${cyan().bold("express")}`;
console.log(title);
ui.div(
  { text: title, width: 50 }
);
ui.div({ text: red("-------------------------------------------------------------------"), width: 70 });

console.log(ui.toString());

Output with ESM: image

The title with cliui doesn't work. If you switch the project to CJS it will work as expected.

Best Regards, Thomas

shadowspawn commented 1 year ago

A few of the key dependencies are not available for dual cjs and esm builds. The first esm build of cliui stayed "pure" and substituted in some simple routines rather than use the older cjs flavours. I think this is probably the cause of the difference you see.

There are some open issues and PR about the problem and possible solutions: #89 #138 #139 #140

fraxken commented 1 year ago

@shadowspawn Yes, we forked to drop CJS and fix the few issues we had: cliui

We plan to maintain that fork short-term (but probably not long term).