Skip to content

feat!: cliui is now ESM only #165

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

Merged
merged 5 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [12, 16, 18]
node: [20, 22]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
Expand All @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 22
- run: npm install
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
Expand All @@ -39,28 +39,19 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 22
- run: npm install
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm test
- run: npm run coverage
esm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm run test:esm
deno:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
node-version: 22
- run: npm install
- run: npm run compile
- uses: denolib/setup-deno@v2
Expand Down
10 changes: 5 additions & 5 deletions deno.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Bootstrap cliui with CommonJS dependencies:
import { cliui, UI } from './build/lib/index.js'
import type { UIOptions } from './build/lib/index.d.ts'
import { wrap, stripAnsi } from './build/lib/string-utils.js'
import stringWidth from 'string-width'
import stripAnsi from 'strip-ansi'
import wrapAnsi from 'wrap-ansi'

export default function ui (opts: UIOptions): UI {
return cliui(opts, {
stringWidth: (str: string) => {
return [...str].length
},
stringWidth,
stripAnsi,
wrap
wrap: wrapAnsi
})
}
10 changes: 5 additions & 5 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Bootstrap cliui with CommonJS dependencies:
import { cliui } from './build/lib/index.js'
import { wrap, stripAnsi } from './build/lib/string-utils.js'
import stringWidth from 'string-width'
import stripAnsi from 'strip-ansi'
import wrapAnsi from 'wrap-ansi'

export default function ui (opts) {
return cliui(opts, {
stringWidth: (str) => {
return [...str].length
},
stringWidth,
stripAnsi,
wrap
wrap: wrapAnsi
})
}
12 changes: 0 additions & 12 deletions lib/cjs.ts

This file was deleted.

4 changes: 2 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function _minWidth (col: Column) {
}

function getWindowWidth (): number {
/* istanbul ignore next: depends on terminal */
/* c8 ignore next 5: depends on terminal */
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
return process.stdout.columns
}
Expand All @@ -371,7 +371,7 @@ function alignCenter (str: string, width: number): string {
str = str.trim()
const strWidth = mixin.stringWidth(str)

/* istanbul ignore next */
/* c8 ignore next 3 */
if (strWidth >= width) {
return str
}
Expand Down
30 changes: 0 additions & 30 deletions lib/string-utils.ts

This file was deleted.

47 changes: 18 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@
"name": "cliui",
"version": "8.0.1",
"description": "easily create complex multi-column command-line-interfaces",
"main": "build/index.cjs",
"main": "build/index.mjs",
"exports": {
".": [
{
"import": "./index.mjs",
"require": "./build/index.cjs"
},
"./build/index.cjs"
]
".": "./index.mjs"
},
"type": "module",
"module": "./index.mjs",
"scripts": {
"check": "standardx '**/*.ts' && standardx '**/*.js' && standardx '**/*.cjs'",
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js' && standardx --fix '**/*.cjs'",
"pretest": "rimraf build && tsc -p tsconfig.test.json && cross-env NODE_ENV=test npm run build:cjs",
"test": "c8 mocha ./test/*.cjs",
"test:esm": "c8 mocha ./test/esm/cliui-test.mjs",
"check": "standardx '**/*.ts' && standardx '**/*.js'",
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js'",
"pretest": "rimraf build && tsc -p tsconfig.test.json",
"test": "c8 mocha ./test/*.mjs",
"postest": "check",
"coverage": "c8 report --check-coverage",
"precompile": "rimraf build",
"compile": "tsc",
"postcompile": "npm run build:cjs",
"build:cjs": "rollup -c",
"prepare": "npm run compile"
},
"repository": "yargs/cliui",
Expand All @@ -49,35 +40,33 @@
"author": "Ben Coe <[email protected]>",
"license": "ISC",
"dependencies": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.1",
"wrap-ansi": "^7.0.0"
"string-width": "^7.2.0",
"strip-ansi": "^7.1.0",
"wrap-ansi": "^9.0.0"
},
"devDependencies": {
"@types/node": "^14.0.27",
"@types/node": "^22.13.10",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"c8": "^7.3.0",
"chai": "^4.2.0",
"chalk": "^4.1.0",
"c8": "^10.1.3",
"chai": "^5.2.0",
"chalk": "^5.4.1",
"cross-env": "^7.0.2",
"eslint": "^7.6.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-node": "^11.1.0",
"gts": "^3.0.0",
"mocha": "^10.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.23.1",
"rollup-plugin-ts": "^3.0.2",
"gts": "^6.0.2",
"mocha": "^11.1.0",
"rimraf": "^6.0.1",
"standardx": "^7.0.0",
"typescript": "^4.0.0"
"typescript": "^5.8.2"
},
"files": [
"build",
"index.mjs",
"!*.d.ts"
],
"engines": {
"node": ">=12"
"node": ">=20"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm bumping into some issues in yargs with Node@<20.19.0, should we consider making this our base engine version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 20.19.0 around something in particular? require(esm) ?

In which case, we might want a minimum for node 22 as well.

I am not against the idea of minimum versions within a major when there is a reason. (I need to remind myself that the early minor versions were before LTS status, so clearly not all equal! 😆 )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this had been merged when I made this command. No reply necessary!

}
}
12 changes: 5 additions & 7 deletions test/cliui.cjs → test/cliui.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict'
import chalk from 'chalk'
import cliui from '../index.mjs'
import stripAnsi from 'strip-ansi'
import { should } from 'chai'

/* global describe, it */

require('chai').should()
should()

// Force chalk to enable color, if it's disabled the test fails.
process.env.FORCE_COLOR = 1

const chalk = require('chalk')
const cliui = require('../build/index.cjs')
const stripAnsi = require('strip-ansi')

describe('cliui', () => {
describe('resetOutput', () => {
it('should set lines to empty', () => {
Expand Down
11 changes: 7 additions & 4 deletions test/deno/cliui-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
} from 'https://deno.land/std/testing/asserts.ts'
import cliui from '../../deno.ts'

// Just run a couple of the tests as a light check working from the Deno runtime.

Deno.test("wraps text at 'width' if a single column is given", () => {
const ui = cliui({
width: 10
Expand Down Expand Up @@ -39,10 +41,11 @@ Deno.test('evenly divides text across columns if multiple columns are given', ()
// TODO: we should flesh out the Deno and ESM implementation
// such that it spreads words out over multiple columns appropriately:
const expected = [
'i am a string ti am a seconi am a third',
'hat should be wd string tha string that',
'rapped t should be should be w',
' wrapped rapped'
'i am a string i am a i am a third',
'that should be second string that',
'wrapped string that should be',
' should be wrapped',
' wrapped'
]

ui.toString().split('\n').forEach((line: string, i: number) => {
Expand Down
47 changes: 0 additions & 47 deletions test/esm/cliui-test.mjs

This file was deleted.