Skip to content

Commit

Permalink
Replace colorette to nanocolors
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Sep 21, 2021
1 parent b15781c commit a482e70
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lib/css-syntax-error.js
@@ -1,6 +1,6 @@
'use strict'

let { red, bold, gray, options: colorette } = require('colorette')
let { red, bold, gray, isColorSupported } = require('nanocolors')

let terminalHighlight = require('./terminal-highlight')

Expand Down Expand Up @@ -44,7 +44,7 @@ class CssSyntaxError extends Error {
if (!this.source) return ''

let css = this.source
if (color == null) color = colorette.enabled
if (color == null) color = isColorSupported
if (terminalHighlight) {
if (color) css = terminalHighlight(css)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/terminal-highlight.js
@@ -1,6 +1,6 @@
'use strict'

let { cyan, gray, green, yellow, magenta } = require('colorette')
let { cyan, gray, green, yellow, magenta } = require('nanocolors')

let tokenizer = require('./tokenize')

Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -67,7 +67,7 @@
"url": "https://github.com/postcss/postcss/issues"
},
"dependencies": {
"colorette": "^1.3.0",
"nanocolors": "^0.1.1",
"nanoid": "^3.1.25",
"source-map-js": "^0.6.2"
},
Expand Down Expand Up @@ -131,7 +131,6 @@
"browser": {
"./lib/terminal-highlight": false,
"source-map-js": false,
"colorette": false,
"path": false,
"url": false,
"fs": false
Expand Down
32 changes: 5 additions & 27 deletions test/browser.test.ts
@@ -1,17 +1,13 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { options, bold, red, gray, yellow } from 'colorette'
import { bold, red, gray, yellow } from 'nanocolors'

beforeEach(() => {
jest.resetModules()
jest.doMock('fs', () => ({}))
jest.doMock('colorette', () => ({ options, bold, red, gray, yellow }))
jest.doMock('nanocolors', () => ({ bold, red, gray, yellow }))
})

afterEach(() => {
options.enabled = true
})

it('shows code with colors (default)', () => {
it('shows code with colors', () => {
let postcss = require('../lib/postcss.js')

let error
Expand All @@ -24,7 +20,7 @@ it('shows code with colors (default)', () => {
throw e
}
}
expect(error.showSourceCode()).toEqual(
expect(error.showSourceCode(true)).toEqual(
bold(red('>')) +
gray(' 1 | ') +
'a' +
Expand All @@ -35,25 +31,7 @@ it('shows code with colors (default)', () => {
)
})

it('shows code without colors (default)', () => {
let postcss = require('../lib/postcss.js')

let error
options.enabled = false

try {
postcss.parse('a{')
} catch (e) {
if (e.name === 'CssSyntaxError') {
error = e
} else {
throw e
}
}
expect(error.showSourceCode()).toEqual('> 1 | a{\n' + ' | ^')
})

it('shows code without colors (setting)', () => {
it('shows code without colors', () => {
let postcss = require('../lib/postcss.js')

let error
Expand Down
2 changes: 1 addition & 1 deletion test/css-syntax-error.test.ts
@@ -1,4 +1,4 @@
import { red, bold, magenta, yellow, gray, cyan } from 'colorette'
import { red, bold, magenta, yellow, gray, cyan } from 'nanocolors'
import { join, resolve as pathResolve } from 'path'
import { pathToFileURL } from 'url'
import stripAnsi from 'strip-ansi'
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -4662,6 +4662,11 @@ nan@^2.12.1:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.15.0.tgz#3f34a473ff18e15c1b5626b62903b5ad6e665fee"
integrity sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==

nanocolors@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/nanocolors/-/nanocolors-0.1.1.tgz#1b148b06c6279084709675fb3d699e0cdc668114"
integrity sha512-9XCSSmaAkJVops0tOTkt1lUXO8iO7vTYr1X45I8kCbgP2cMS9RvPGVnp/Ou+ISsm9JhKpKCON7zwOFyWcWrzhA==

nanodelay@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/nanodelay/-/nanodelay-1.0.8.tgz#e6ff3d94f6c80b300b8fb1bbeb2eae0b5506ad0a"
Expand Down

0 comments on commit a482e70

Please sign in to comment.