Skip to content

Commit

Permalink
feat: add proper wrapping for esm and Deno by updating dependencies
Browse files Browse the repository at this point in the history
- add esm test to npm run script
- run full tests from esm

Co-authored-by: Momtchil Momtchev <momtchil@momtchev.com>
  • Loading branch information
shadowspawn and mmomtchev committed May 27, 2023
1 parent af3145d commit 3cfe03d
Show file tree
Hide file tree
Showing 12 changed files with 549 additions and 599 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ jobs:
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:
Expand Down
8 changes: 4 additions & 4 deletions deno.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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 wrap from 'wrap-ansi'
import stripAnsi from 'strip-ansi'
import stringWidth from 'string-width'

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

export default function ui (opts) {
return cliui(opts, {
stringWidth: (str) => {
return [...str].length
},
stringWidth,
stripAnsi,
wrap
})
Expand Down
7 changes: 4 additions & 3 deletions lib/cjs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Bootstrap cliui with CommonJS dependencies:
import { cliui, UIOptions } from './index.js'
const stringWidth = require('string-width')
const stripAnsi = require('strip-ansi')
const wrap = require('wrap-ansi')
import stringWidth from 'string-width'
import wrap from 'wrap-ansi'
import stripAnsi from 'strip-ansi'

export default function ui (opts: UIOptions) {
return cliui(opts, {
stringWidth,
Expand Down
30 changes: 0 additions & 30 deletions lib/string-utils.ts

This file was deleted.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"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",
"test": "c8 mocha ./test/cjs/*.cjs ./test/esm/*.mjs",
"postest": "check",
"coverage": "c8 report --check-coverage",
"precompile": "rimraf build",
Expand Down Expand Up @@ -49,12 +48,15 @@
"author": "Ben Coe <ben@npmjs.com>",
"license": "ISC",
"dependencies": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.1",
"wrap-ansi": "^7.0.0"
"string-width": "^5.1.2",
"strip-ansi": "^7.0.1",
"wrap-ansi": "^8.1.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-node-resolve": "^15.0.2",
"@types/node": "^14.0.27",
"@types/wrap-ansi": "^8.0.1",
"@typescript-eslint/eslint-plugin": "^4.0.0",
"@typescript-eslint/parser": "^4.0.0",
"c8": "^7.3.0",
Expand All @@ -67,8 +69,8 @@
"gts": "^3.0.0",
"mocha": "^10.0.0",
"rimraf": "^3.0.2",
"rollup": "^2.23.1",
"rollup-plugin-ts": "^3.0.2",
"rollup": "^2.79.1",
"rollup-plugin-ts": "^3.2.0",
"standardx": "^7.0.0",
"typescript": "^4.0.0"
},
Expand Down
10 changes: 9 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import ts from 'rollup-plugin-ts'
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'

// These two transient dependencies are still CommonJS:
// 'node_modules/emoji-regex/index.js',
// 'node_modules/eastasianwidth/eastasianwidth.js'

const output = {
format: 'cjs',
Expand All @@ -12,6 +18,8 @@ export default {
input: './lib/cjs.ts',
output,
plugins: [
ts({ /* options */ })
ts({ /* options */ }),
nodeResolve(),
commonjs()
]
}
4 changes: 4 additions & 0 deletions test/cjs/cliui-test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { runTests } = require('../shared-tests.cjs')
const cliui = require('../../build/index.cjs')

runTests(cliui, 'CJS')
Loading

0 comments on commit 3cfe03d

Please sign in to comment.