Skip to content

Commit 5a521de

Browse files
authored
feat!: cliui is now ESM only (#165)
1 parent af3145d commit 5a521de

File tree

10 files changed

+46
-154
lines changed

10 files changed

+46
-154
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
node: [12, 16, 18]
13+
node: [20, 22]
1414
steps:
1515
- uses: actions/checkout@v1
1616
- uses: actions/setup-node@v1
@@ -28,7 +28,7 @@ jobs:
2828
- uses: actions/checkout@v2
2929
- uses: actions/setup-node@v1
3030
with:
31-
node-version: 12
31+
node-version: 22
3232
- run: npm install
3333
env:
3434
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
@@ -39,28 +39,19 @@ jobs:
3939
- uses: actions/checkout@v2
4040
- uses: actions/setup-node@v1
4141
with:
42-
node-version: 14
42+
node-version: 22
4343
- run: npm install
4444
env:
4545
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
4646
- run: npm test
4747
- run: npm run coverage
48-
esm:
49-
runs-on: ubuntu-latest
50-
steps:
51-
- uses: actions/checkout@v2
52-
- uses: actions/setup-node@v1
53-
with:
54-
node-version: 14
55-
- run: npm install
56-
- run: npm run test:esm
5748
deno:
5849
runs-on: ubuntu-latest
5950
steps:
6051
- uses: actions/checkout@v2
6152
- uses: actions/setup-node@v1
6253
with:
63-
node-version: 14
54+
node-version: 22
6455
- run: npm install
6556
- run: npm run compile
6657
- uses: denolib/setup-deno@v2

deno.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Bootstrap cliui with CommonJS dependencies:
22
import { cliui, UI } from './build/lib/index.js'
33
import type { UIOptions } from './build/lib/index.d.ts'
4-
import { wrap, stripAnsi } from './build/lib/string-utils.js'
4+
import stringWidth from 'string-width'
5+
import stripAnsi from 'strip-ansi'
6+
import wrapAnsi from 'wrap-ansi'
57

68
export default function ui (opts: UIOptions): UI {
79
return cliui(opts, {
8-
stringWidth: (str: string) => {
9-
return [...str].length
10-
},
10+
stringWidth,
1111
stripAnsi,
12-
wrap
12+
wrap: wrapAnsi
1313
})
1414
}

index.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Bootstrap cliui with CommonJS dependencies:
22
import { cliui } from './build/lib/index.js'
3-
import { wrap, stripAnsi } from './build/lib/string-utils.js'
3+
import stringWidth from 'string-width'
4+
import stripAnsi from 'strip-ansi'
5+
import wrapAnsi from 'wrap-ansi'
46

57
export default function ui (opts) {
68
return cliui(opts, {
7-
stringWidth: (str) => {
8-
return [...str].length
9-
},
9+
stringWidth,
1010
stripAnsi,
11-
wrap
11+
wrap: wrapAnsi
1212
})
1313
}

lib/cjs.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ function _minWidth (col: Column) {
349349
}
350350

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

374-
/* istanbul ignore next */
374+
/* c8 ignore next 3 */
375375
if (strWidth >= width) {
376376
return str
377377
}

lib/string-utils.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

package.json

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,21 @@
22
"name": "cliui",
33
"version": "8.0.1",
44
"description": "easily create complex multi-column command-line-interfaces",
5-
"main": "build/index.cjs",
5+
"main": "build/index.mjs",
66
"exports": {
7-
".": [
8-
{
9-
"import": "./index.mjs",
10-
"require": "./build/index.cjs"
11-
},
12-
"./build/index.cjs"
13-
]
7+
".": "./index.mjs"
148
},
159
"type": "module",
1610
"module": "./index.mjs",
1711
"scripts": {
18-
"check": "standardx '**/*.ts' && standardx '**/*.js' && standardx '**/*.cjs'",
19-
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js' && standardx --fix '**/*.cjs'",
20-
"pretest": "rimraf build && tsc -p tsconfig.test.json && cross-env NODE_ENV=test npm run build:cjs",
21-
"test": "c8 mocha ./test/*.cjs",
22-
"test:esm": "c8 mocha ./test/esm/cliui-test.mjs",
12+
"check": "standardx '**/*.ts' && standardx '**/*.js'",
13+
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js'",
14+
"pretest": "rimraf build && tsc -p tsconfig.test.json",
15+
"test": "c8 mocha ./test/*.mjs",
2316
"postest": "check",
2417
"coverage": "c8 report --check-coverage",
2518
"precompile": "rimraf build",
2619
"compile": "tsc",
27-
"postcompile": "npm run build:cjs",
28-
"build:cjs": "rollup -c",
2920
"prepare": "npm run compile"
3021
},
3122
"repository": "yargs/cliui",
@@ -49,35 +40,33 @@
4940
"author": "Ben Coe <[email protected]>",
5041
"license": "ISC",
5142
"dependencies": {
52-
"string-width": "^4.2.0",
53-
"strip-ansi": "^6.0.1",
54-
"wrap-ansi": "^7.0.0"
43+
"string-width": "^7.2.0",
44+
"strip-ansi": "^7.1.0",
45+
"wrap-ansi": "^9.0.0"
5546
},
5647
"devDependencies": {
57-
"@types/node": "^14.0.27",
48+
"@types/node": "^22.13.10",
5849
"@typescript-eslint/eslint-plugin": "^4.0.0",
5950
"@typescript-eslint/parser": "^4.0.0",
60-
"c8": "^7.3.0",
61-
"chai": "^4.2.0",
62-
"chalk": "^4.1.0",
51+
"c8": "^10.1.3",
52+
"chai": "^5.2.0",
53+
"chalk": "^5.4.1",
6354
"cross-env": "^7.0.2",
6455
"eslint": "^7.6.0",
6556
"eslint-plugin-import": "^2.22.0",
6657
"eslint-plugin-node": "^11.1.0",
67-
"gts": "^3.0.0",
68-
"mocha": "^10.0.0",
69-
"rimraf": "^3.0.2",
70-
"rollup": "^2.23.1",
71-
"rollup-plugin-ts": "^3.0.2",
58+
"gts": "^6.0.2",
59+
"mocha": "^11.1.0",
60+
"rimraf": "^6.0.1",
7261
"standardx": "^7.0.0",
73-
"typescript": "^4.0.0"
62+
"typescript": "^5.8.2"
7463
},
7564
"files": [
7665
"build",
7766
"index.mjs",
7867
"!*.d.ts"
7968
],
8069
"engines": {
81-
"node": ">=12"
70+
"node": ">=20"
8271
}
8372
}

test/cliui.cjs renamed to test/cliui.mjs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
'use strict'
1+
import chalk from 'chalk'
2+
import cliui from '../index.mjs'
3+
import stripAnsi from 'strip-ansi'
4+
import { should } from 'chai'
25

36
/* global describe, it */
4-
5-
require('chai').should()
7+
should()
68

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

10-
const chalk = require('chalk')
11-
const cliui = require('../build/index.cjs')
12-
const stripAnsi = require('strip-ansi')
13-
1412
describe('cliui', () => {
1513
describe('resetOutput', () => {
1614
it('should set lines to empty', () => {

test/deno/cliui-test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
} from 'https://deno.land/std/testing/asserts.ts'
77
import cliui from '../../deno.ts'
88

9+
// Just run a couple of the tests as a light check working from the Deno runtime.
10+
911
Deno.test("wraps text at 'width' if a single column is given", () => {
1012
const ui = cliui({
1113
width: 10
@@ -39,10 +41,11 @@ Deno.test('evenly divides text across columns if multiple columns are given', ()
3941
// TODO: we should flesh out the Deno and ESM implementation
4042
// such that it spreads words out over multiple columns appropriately:
4143
const expected = [
42-
'i am a string ti am a seconi am a third',
43-
'hat should be wd string tha string that',
44-
'rapped t should be should be w',
45-
' wrapped rapped'
44+
'i am a string i am a i am a third',
45+
'that should be second string that',
46+
'wrapped string that should be',
47+
' should be wrapped',
48+
' wrapped'
4649
]
4750

4851
ui.toString().split('\n').forEach((line: string, i: number) => {

test/esm/cliui-test.mjs

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)