Skip to content

Commit

Permalink
chore(deps): upgrade to latest stable; fix audit
Browse files Browse the repository at this point in the history
- fixes all security vulnerabilities (`npm audit` is now clean)
- remove deprecated coffee-script package. make mocha use new coffeescript's register.
- upgrade coffeescript to v2. had to change SpecialString usages to new SpecialString.
- remove unmaintained "mocha-pretty-spec-reporter" (has security vulnerability)
- remove unused "underscore".
- replace "jitter" usage with official watch capability.
  • Loading branch information
AviVahl committed Jun 8, 2021
1 parent 4a7e401 commit fa6ecbd
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 693 deletions.
2 changes: 1 addition & 1 deletion .mocharc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require: 'coffee-script/register'
require: 'coffeescript/register'
recursive: true
reporter: 'spec'
ui: 'bdd'
Expand Down
993 changes: 347 additions & 646 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 14 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,26 @@
"description": "Stylish console.log for node",
"main": "lib/RenderKid.js",
"dependencies": {
"css-select": "^2.0.2",
"dom-converter": "^0.2",
"htmlparser2": "^3.10.1",
"lodash": "^4.17.20",
"strip-ansi": "^3.0.0"
"css-select": "^4.1.3",
"dom-converter": "^0.2.0",
"htmlparser2": "^6.1.0",
"lodash": "^4.17.21",
"strip-ansi": "^6.0.0"
},
"devDependencies": {
"chai": "^4.1.2",
"chai-changes": "^1.3.4",
"chai-fuzzy": "^1.5.0",
"coffee-script": "~1.8.0",
"coffeescript": "^1.12.7",
"jitter": "^1.3.0",
"mocha": "^8.2.0",
"mocha-pretty-spec-reporter": "0.1.0-beta.2",
"sinon": "^1.14.1",
"sinon-chai": "^2.7.0",
"underscore": "^1.8.3"
"chai": "^4.3.4",
"chai-changes": "^1.3.6",
"chai-fuzzy": "^1.6.1",
"coffeescript": "^2.5.1",
"mocha": "^9.0.0",
"sinon": "^11.1.1",
"sinon-chai": "^3.7.0"
},
"scripts": {
"test": "mocha \"test/**/*.coffee\"",
"test:watch": "mocha \"test/**/*.coffee\" --watch",
"test:watch": "npm run test -- --watch",
"compile": "coffee --bare --compile --output ./lib ./src",
"compile:watch": "jitter src lib -b",
"compile:watch": "coffee --watch --bare --compile --output ./lib ./src",
"watch": "npm run compile:watch & npm run test:watch",
"winwatch": "start/b npm run compile:watch & npm run test:watch",
"prepublish": "npm run compile"
Expand Down
2 changes: 1 addition & 1 deletion src/Layout.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = class Layout

_appendLine: (text) ->
@_append text
s = SpecialString(text)
s = new SpecialString(text)
if s.length < @_config.terminalWidth
@_append '<none>\n</none>'

Expand Down
8 changes: 4 additions & 4 deletions src/layout/Block.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module.exports = class Block
_writeInline: (str) ->
# special characters (such as <bg-white>) don't require
# any wrapping...
if SpecialString(str).isOnlySpecialChars()
if new SpecialString(str).isOnlySpecialChars()
# ... and directly get appended to the layout.
@_layout._append str
return
Expand Down Expand Up @@ -205,21 +205,21 @@ module.exports = class Block
# etc, and appends it to the layout.
_writeLine: (str) ->
# we'll be cutting from our string as we go
remaining = SpecialString str
remaining = new SpecialString str

# this will continue until nothing is left of our block.
loop
# left margin...
toPrepend = @_toPrependToLine()

# ... and its length
toPrependLength = SpecialString(toPrepend).length
toPrependLength = new SpecialString(toPrepend).length

# right margin...
toAppend = @_toAppendToLine()

# ... and its length
toAppendLength = SpecialString(toAppend).length
toAppendLength = new SpecialString(toAppend).length

# how much room is left for content
roomLeft = @_layout._config.terminalWidth - (toPrependLength + toAppendLength)
Expand Down
2 changes: 1 addition & 1 deletion src/layout/SpecialString.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = class SpecialString

@_str = before + after
do @_reset
SpecialString cut
new SpecialString cut

@_countChars: (text, cb) ->
while text.length isnt 0
Expand Down
2 changes: 1 addition & 1 deletion src/layout/block/linePrependor/Default.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = class DefaultLinePrependor extends require './_LinePrependor'
_render: (inherited, options) ->
if @_lineNo is 0 and bullet = @_config.bullet
char = bullet.char
charLen = SpecialString(char).length
charLen = new SpecialString(char).length
alignment = bullet.alignment
space = @_config.amount
toWrite = char
Expand Down
42 changes: 21 additions & 21 deletions test/layout/SpecialString.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,80 @@ S = require '../../src/layout/SpecialString'
describe "SpecialString", ->
describe 'SpecialString()', ->
it 'should return instance', ->
S('s').should.be.instanceOf S
new S('s').should.be.instanceOf S

describe 'length()', ->
it 'should return correct length for normal text', ->
S('hello').length.should.equal 5
new S('hello').length.should.equal 5

it 'should return correct length for text containing tabs and tags', ->
S('<a>he<you />l\tlo</a>').length.should.equal 13
new S('<a>he<you />l\tlo</a>').length.should.equal 13

it "shouldn't count empty tags as tags", ->
S('<>><').length.should.equal 4
new S('<>><').length.should.equal 4

it "should count length of single tag as 0", ->
S('<html>').length.should.equal 0
new S('<html>').length.should.equal 0

it "should work correctly with html quoted characters", ->
S(' &gt;&lt; &sp;').length.should.equal 5
new S(' &gt;&lt; &sp;').length.should.equal 5

describe 'splitIn()', ->
it "should work correctly with normal text", ->
S("123456").splitIn(3).should.be.like ['123', '456']
new S("123456").splitIn(3).should.be.like ['123', '456']

it "should work correctly with normal text containing tabs and tags", ->
S("12\t3<hello>456").splitIn(3).should.be.like ['12', '\t', '3<hello>45', '6']
new S("12\t3<hello>456").splitIn(3).should.be.like ['12', '\t', '3<hello>45', '6']

it "should not trimLeft all lines when trimLeft is no", ->
S('abc def').splitIn(3).should.be.like ['abc', ' de', 'f']
new S('abc def').splitIn(3).should.be.like ['abc', ' de', 'f']

it "should trimLeft all lines when trimLeft is true", ->
S('abc def').splitIn(3, yes).should.be.like ['abc', 'def']
new S('abc def').splitIn(3, yes).should.be.like ['abc', 'def']

describe 'cut()', ->
it "should work correctly with text containing tabs and tags", ->
original = S("12\t3<hello>456")
original = new S("12\t3<hello>456")
cut = original.cut(2, 3)
original.str.should.equal '123<hello>456'
cut.str.should.equal '\t'

it "should trim left when trimLeft is true", ->
original = S ' 132'
original = new S ' 132'
cut = original.cut 0, 1, yes
original.str.should.equal '32'
cut.str.should.equal '1'

it "should be greedy", ->
S("ab<tag>a").cut(0, 2).str.should.equal "ab<tag>"
new S("ab<tag>a").cut(0, 2).str.should.equal "ab<tag>"

describe 'isOnlySpecialChars()', ->
it "should work", ->
S("12\t3<hello>456").isOnlySpecialChars().should.equal no
S("<hello>").isOnlySpecialChars().should.equal yes
new S("12\t3<hello>456").isOnlySpecialChars().should.equal no
new S("<hello>").isOnlySpecialChars().should.equal yes

describe 'clone()', ->
it "should return independent instance", ->
a = S('hello')
a = new S('hello')
b = a.clone()
a.str.should.equal b.str
a.should.not.equal b

describe 'trim()', ->
it "should return an independent instance", ->
s = S('')
s = new S('')
s.trim().should.not.equal s

it 'should return the same string when trim is not required', ->
S('hello').trim().str.should.equal 'hello'
new S('hello').trim().str.should.equal 'hello'

it 'should return trimmed string', ->
S(' hello').trim().str.should.equal 'hello'
new S(' hello').trim().str.should.equal 'hello'

describe 'trimLeft()', ->
it "should only trim on the left", ->
S(' hello ').trimLeft().str.should.equal 'hello '
new S(' hello ').trimLeft().str.should.equal 'hello '

describe 'trimRight()', ->
it "should only trim on the right", ->
S(' hello ').trimRight().str.should.equal ' hello'
new S(' hello ').trimRight().str.should.equal ' hello'

0 comments on commit fa6ecbd

Please sign in to comment.