Skip to content

Commit a60c448

Browse files
committed
Merge branch 'master' into feature/optional-width
2 parents 2d4fc57 + 2737977 commit a60c448

File tree

12 files changed

+94
-162
lines changed

12 files changed

+94
-162
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

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [9.0.1](https://github.com/yargs/cliui/compare/v9.0.0...v9.0.1) (2025-03-17)
6+
7+
8+
### Bug Fixes
9+
10+
* make require("cliui") work as expected for CJS ([04ccc25](https://github.com/yargs/cliui/commit/04ccc250e30a059292c03fa1ef0a8661f8d93dfe))
11+
12+
## [9.0.0](https://github.com/yargs/cliui/compare/v8.0.1...v9.0.0) (2025-03-16)
13+
14+
15+
### ⚠ BREAKING CHANGES
16+
17+
* cliui is now ESM only ([#165](https://github.com/yargs/cliui/issues/165))
18+
19+
### Features
20+
21+
* cliui is now ESM only ([#165](https://github.com/yargs/cliui/issues/165)) ([5a521de](https://github.com/yargs/cliui/commit/5a521de7ea88f262236394c8d96775bcf50ff0a4))
22+
523
## [8.0.1](https://github.com/yargs/cliui/compare/v8.0.0...v8.0.1) (2022-10-01)
624

725

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ easily create complex multi-column command-line-interfaces.
99

1010
## Example
1111

12+
```bash
13+
npm i cliui@latest chalk@latest
14+
```
15+
1216
```js
1317
const ui = require('cliui')()
18+
const {Chalk} = require('chalk');
19+
const chalk = new Chalk();
1420

1521
ui.div('Usage: $0 [command] [options]')
1622

@@ -46,7 +52,9 @@ As of `v7` `cliui` supports [Deno](https://github.com/denoland/deno) and
4652
[ESM](https://nodejs.org/api/esm.html#esm_ecmascript_modules):
4753

4854
```typescript
49-
import cliui from "https://deno.land/x/cliui/deno.ts";
55+
import cliui from "cliui";
56+
import chalk from "chalk";
57+
// Deno: import cliui from "https://deno.land/x/cliui/deno.ts";
5058

5159
const ui = cliui({})
5260

@@ -57,11 +65,23 @@ ui.div({
5765
padding: [2, 0, 1, 0]
5866
})
5967

60-
ui.div({
61-
text: "-f, --file",
62-
width: 20,
63-
padding: [0, 4, 0, 4]
64-
})
68+
ui.div(
69+
{
70+
text: "-f, --file",
71+
width: 20,
72+
padding: [0, 4, 0, 4]
73+
},
74+
{
75+
text: "the file to load." +
76+
chalk.green("(if this description is long it wraps).")
77+
,
78+
width: 20
79+
},
80+
{
81+
text: chalk.red("[required]"),
82+
align: 'right'
83+
}
84+
)
6585

6686
console.log(ui.toString())
6787
```

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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
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
}
14+
15+
export {ui as 'module.exports'};

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
@@ -352,7 +352,7 @@ function _minWidth (col: Column) {
352352
}
353353

354354
function getWindowWidth (): number {
355-
/* istanbul ignore next: depends on terminal */
355+
/* c8 ignore next 5: depends on terminal */
356356
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
357357
return process.stdout.columns
358358
}
@@ -374,7 +374,7 @@ function alignCenter (str: string, width: number): string {
374374
str = str.trim()
375375
const strWidth = mixin.stringWidth(str)
376376

377-
/* istanbul ignore next */
377+
/* c8 ignore next 3 */
378378
if (strWidth >= width) {
379379
return str
380380
}

lib/string-utils.ts

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

package.json

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
{
22
"name": "cliui",
3-
"version": "8.0.1",
3+
"version": "9.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",
66-
"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",
57+
"eslint-plugin-n": "^14.0.0",
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', () => {

0 commit comments

Comments
 (0)