From 98b61ba5b46622de48bb2592583757ab846212ad Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Sat, 25 Sep 2021 08:55:08 +0200 Subject: [PATCH 01/11] Replace chalk to nanocolors --- lib/css-syntax-error.es6 | 37 ++++++------ lib/terminal-highlight.es6 | 35 +++++------ package.json | 7 +-- test/browser.test.js | 23 +++---- test/css-syntax-error.test.js | 109 ++++++++++++++++++++-------------- yarn.lock | 5 ++ 6 files changed, 120 insertions(+), 96 deletions(-) diff --git a/lib/css-syntax-error.es6 b/lib/css-syntax-error.es6 index d6969877c..d42d26560 100644 --- a/lib/css-syntax-error.es6 +++ b/lib/css-syntax-error.es6 @@ -1,5 +1,4 @@ -import supportsColor from 'supports-color' -import chalk from 'chalk' +import nanocolors from 'nanocolors' import terminalHighlight from './terminal-highlight' @@ -175,7 +174,7 @@ class CssSyntaxError extends Error { let css = this.source if (terminalHighlight) { - if (typeof color === 'undefined') color = supportsColor.stdout + if (typeof color === 'undefined') color = nanocolors.isColorSupported if (color) css = terminalHighlight(css) } @@ -186,28 +185,32 @@ class CssSyntaxError extends Error { let maxWidth = String(end).length function mark (text) { - if (color && chalk.red) { - return chalk.red.bold(text) + if (color && nanocolors.red) { + return nanocolors.red(nanocolors.bold(text)) } return text } function aside (text) { - if (color && chalk.gray) { - return chalk.gray(text) + if (color && nanocolors.gray) { + return nanocolors.gray(text) } return text } - return lines.slice(start, end).map((line, index) => { - let number = start + 1 + index - let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ' - if (number === this.line) { - let spacing = aside(gutter.replace(/\d/g, ' ')) + - line.slice(0, this.column - 1).replace(/[^\t]/g, ' ') - return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^') - } - return ' ' + aside(gutter) + line - }).join('\n') + return lines + .slice(start, end) + .map((line, index) => { + let number = start + 1 + index + let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | ' + if (number === this.line) { + let spacing = + aside(gutter.replace(/\d/g, ' ')) + + line.slice(0, this.column - 1).replace(/[^\t]/g, ' ') + return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^') + } + return ' ' + aside(gutter) + line + }) + .join('\n') } /** diff --git a/lib/terminal-highlight.es6 b/lib/terminal-highlight.es6 index 10816cb2f..5c01c2bc4 100644 --- a/lib/terminal-highlight.es6 +++ b/lib/terminal-highlight.es6 @@ -1,24 +1,24 @@ -import chalk from 'chalk' +import nanocolors from 'nanocolors' import tokenizer from './tokenize' import Input from './input' const HIGHLIGHT_THEME = { - 'brackets': chalk.cyan, - 'at-word': chalk.cyan, - 'comment': chalk.gray, - 'string': chalk.green, - 'class': chalk.yellow, - 'call': chalk.cyan, - 'hash': chalk.magenta, - '(': chalk.cyan, - ')': chalk.cyan, - '{': chalk.yellow, - '}': chalk.yellow, - '[': chalk.yellow, - ']': chalk.yellow, - ':': chalk.yellow, - ';': chalk.yellow + brackets: nanocolors.cyan, + 'at-word': nanocolors.cyan, + comment: nanocolors.gray, + string: nanocolors.green, + class: nanocolors.yellow, + call: nanocolors.cyan, + hash: nanocolors.magenta, + '(': nanocolors.cyan, + ')': nanocolors.cyan, + '{': nanocolors.yellow, + '}': nanocolors.yellow, + '[': nanocolors.yellow, + ']': nanocolors.yellow, + ':': nanocolors.yellow, + ';': nanocolors.yellow } function getTokenType ([type, value], processor) { @@ -47,7 +47,8 @@ function terminalHighlight (css) { let token = processor.nextToken() let color = HIGHLIGHT_THEME[getTokenType(token, processor)] if (color) { - result += token[1].split(/\r?\n/) + result += token[1] + .split(/\r?\n/) .map(i => color(i)) .join('\n') } else { diff --git a/package.json b/package.json index ca383d90f..76c91bb71 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,8 @@ "homepage": "https://postcss.org/", "repository": "postcss/postcss", "dependencies": { - "chalk": "^2.4.2", - "source-map": "^0.6.1", - "supports-color": "^6.1.0" + "nanocolors": "^0.2.2", + "source-map": "^0.6.1" }, "devDependencies": { "@babel/core": "^7.11.6", @@ -82,8 +81,6 @@ }, "browser": { "./lib/terminal-highlight": false, - "supports-color": false, - "chalk": false, "fs": false }, "browserslist": [ diff --git a/test/browser.test.js b/test/browser.test.js index 8198e287a..f1900bbbf 100644 --- a/test/browser.test.js +++ b/test/browser.test.js @@ -1,10 +1,9 @@ -jest.doMock('fs', () => ({ })) -jest.doMock('chalk', () => ({ })) -jest.doMock('supports-color', () => ({ })) +jest.doMock('fs', () => ({})) +jest.doMock('nanocolors', () => require('nanocolors/index.browser.cjs')) let postcss = require('..') -it('shows code without chalk', () => { +it('shows code', () => { let error try { postcss.parse('a{') @@ -15,14 +14,16 @@ it('shows code without chalk', () => { throw e } } - expect(error.showSourceCode(true)).toEqual('> 1 | a{\n' + - ' | ^') + expect(error.showSourceCode(true)).toEqual('> 1 | a{\n' + ' | ^') }) it('generates source map without fs', () => { - expect(postcss([() => true]).process('a{}', { from: 'a.css', map: true }).css) - .toEqual('a{}\n/*# sourceMappingURL=data:application/json;base64,' + - 'eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImEuY3NzIl0sIm5hbWVzIjpbXSw' + - 'ibWFwcGluZ3MiOiJBQUFBLEVBQUUiLCJmaWxlIjoiYS5jc3MiLCJzb3VyY2' + - 'VzQ29udGVudCI6WyJhe30iXX0= */') + expect( + postcss([() => true]).process('a{}', { from: 'a.css', map: true }).css + ).toEqual( + 'a{}\n/*# sourceMappingURL=data:application/json;base64,' + + 'eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImEuY3NzIl0sIm5hbWVzIjpbXSw' + + 'ibWFwcGluZ3MiOiJBQUFBLEVBQUUiLCJmaWxlIjoiYS5jc3MiLCJzb3VyY2' + + 'VzQ29udGVudCI6WyJhe30iXX0= */' + ) }) diff --git a/test/css-syntax-error.test.js b/test/css-syntax-error.test.js index 503d18536..4abc7d5c3 100644 --- a/test/css-syntax-error.test.js +++ b/test/css-syntax-error.test.js @@ -1,6 +1,6 @@ +let nanocolors = require('nanocolors') let stripAnsi = require('strip-ansi') let Concat = require('concat-with-sourcemaps') -let chalk = require('chalk') let path = require('path') let CssSyntaxError = require('../lib/css-syntax-error') @@ -39,65 +39,77 @@ it('saves source', () => { }) it('has stack trace', () => { - expect(parseError('a {\n content: "\n}').stack) - .toMatch(/css-syntax-error\.test\.js/) + expect(parseError('a {\n content: "\n}').stack).toMatch( + /css-syntax-error\.test\.js/ + ) }) it('highlights broken line with colors', () => { - let c = chalk + let c = nanocolors expect(parseError('#a .b {').showSourceCode(true)).toEqual( - c.red.bold('>') + c.gray(' 1 | ') + - c.magenta('#a') + ' ' + c.yellow('.b') + ' ' + - c.yellow('{') + '\n ' + - c.gray(' | ') + c.red.bold('^')) + c.red(c.bold('>')) + + c.gray(' 1 | ') + + c.magenta('#a') + + ' ' + + c.yellow('.b') + + ' ' + + c.yellow('{') + + '\n ' + + c.gray(' | ') + + c.red(c.bold('^')) + ) }) it('highlights broken line', () => { - expect(parseError('a {\n content: "\n}').showSourceCode(false)) - .toEqual(' 1 | a {\n' + - '> 2 | content: "\n' + - ' | ^\n' + - ' 3 | }') + expect(parseError('a {\n content: "\n}').showSourceCode(false)).toEqual( + ' 1 | a {\n' + '> 2 | content: "\n' + ' | ^\n' + ' 3 | }' + ) }) it('highlights broken line, when indented with tabs', () => { - expect(parseError('a {\n\t \t content:\t"\n}').showSourceCode(false)) - .toEqual(' 1 | a {\n' + - '> 2 | \t \t content:\t"\n' + - ' | \t \t \t^\n' + - ' 3 | }') + expect( + parseError('a {\n\t \t content:\t"\n}').showSourceCode(false) + ).toEqual( + ' 1 | a {\n' + + '> 2 | \t \t content:\t"\n' + + ' | \t \t \t^\n' + + ' 3 | }' + ) }) it('highlights small code example', () => { - expect(parseError('a {').showSourceCode(false)) - .toEqual('> 1 | a {\n' + - ' | ^') + expect(parseError('a {').showSourceCode(false)).toEqual( + '> 1 | a {\n' + ' | ^' + ) }) it('add leading space for line numbers', () => { let css = '\n\n\n\n\n\n\na {\n content: "\n}\n\n\n' - expect(parseError(css).showSourceCode(false)) - .toEqual(' 7 | \n' + - ' 8 | a {\n' + - '> 9 | content: "\n' + - ' | ^\n' + - ' 10 | }\n' + - ' 11 | ') + expect(parseError(css).showSourceCode(false)).toEqual( + ' 7 | \n' + + ' 8 | a {\n' + + '> 9 | content: "\n' + + ' | ^\n' + + ' 10 | }\n' + + ' 11 | ' + ) }) it('prints with highlight', () => { - expect(stripAnsi(parseError('a {').toString())) - .toEqual('CssSyntaxError: :1:1: Unclosed block\n' + - '\n' + - '> 1 | a {\n' + - ' | ^\n') + expect(stripAnsi(parseError('a {').toString())).toEqual( + 'CssSyntaxError: :1:1: Unclosed block\n' + + '\n' + + '> 1 | a {\n' + + ' | ^\n' + ) }) it('misses highlights without source content', () => { let error = parseError('a {') error.source = null - expect(error.toString()) - .toEqual('CssSyntaxError: :1:1: Unclosed block') + expect(error.toString()).toEqual( + 'CssSyntaxError: :1:1: Unclosed block' + ) }) it('misses position without source', () => { @@ -160,8 +172,9 @@ it('does not uses wrong source map', () => { it('set source plugin', () => { let error = postcss.parse('a{}').first.error('Error', { plugin: 'PL' }) expect(error.plugin).toEqual('PL') - expect(error.toString()) - .toMatch(/^CssSyntaxError: PL: :1:1: Error/) + expect(error.toString()).toMatch( + /^CssSyntaxError: PL: :1:1: Error/ + ) }) it('set source plugin automatically', () => { @@ -171,11 +184,13 @@ it('set source plugin automatically', () => { } }) - return postcss([plugin]).process('a{}').catch(error => { - if (error.name !== 'CssSyntaxError') throw error - expect(error.plugin).toEqual('test-plugin') - expect(error.toString()).toMatch(/test-plugin/) - }) + return postcss([plugin]) + .process('a{}') + .catch(error => { + if (error.name !== 'CssSyntaxError') throw error + expect(error.plugin).toEqual('test-plugin') + expect(error.toString()).toMatch(/test-plugin/) + }) }) it('set plugin automatically in async', () => { @@ -187,8 +202,10 @@ it('set plugin automatically in async', () => { } }) - return postcss([plugin]).process('a{}').catch(error => { - if (error.name !== 'CssSyntaxError') throw error - expect(error.plugin).toEqual('async-plugin') - }) + return postcss([plugin]) + .process('a{}') + .catch(error => { + if (error.name !== 'CssSyntaxError') throw error + expect(error.plugin).toEqual('async-plugin') + }) }) diff --git a/yarn.lock b/yarn.lock index 1a309fca1..6973a0fb4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5129,6 +5129,11 @@ nan@^2.9.2: resolved "https://registry.yarnpkg.com/nan/-/nan-2.13.2.tgz#f51dc7ae66ba7d5d55e1e6d4d8092e802c9aefe7" integrity sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw== +nanocolors@^0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/nanocolors/-/nanocolors-0.2.2.tgz#94a4b7e45ecdebdbea7cb0a8349f9447a9677675" + integrity sha512-t4mwdKizEGLFeZzDbr1r6SjwKYZQEB0Z/trGsdAIsw5EadaR010/zvJ0arkw6vznyTevcMi9BtppprJ5aqLXRg== + nanomatch@^1.2.9: version "1.2.13" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" From 0c680639c3d717b4c8c0b2b2a9d1799fbf239a76 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Sat, 25 Sep 2021 08:57:32 +0200 Subject: [PATCH 02/11] Move tests to GitHub Actions --- .github/workflows/test.yml | 61 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 12 -------- appveyor.yml | 22 -------------- 3 files changed, 61 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..a7f84a2a9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,61 @@ +name: Test +on: + push: + pull_request: +env: + FORCE_COLOR: 2 +jobs: + full: + name: Node.js 16 Full + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + - name: Install Node.js + uses: actions/setup-node@v2 + with: + node-version: 16 + - name: Install dependencies + uses: bahmutov/npm-install@v1 + - name: Run tests + run: yarn test + short: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: + - 14 + - 12 + - 10 + - 8 + - 6 + name: Node.js ${{ matrix.node-version }} Quick + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + - name: Install Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + uses: bahmutov/npm-install@v1 + with: + install-command: yarn --frozen-lockfile --ignore-engines + - name: Run unit tests + run: npx jest + windows: + runs-on: windows-latest + name: Windows Quick + env: + YARN_GPG: "no" + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + - name: Install Node.js LTS + uses: actions/setup-node@v2 + with: + node-version: 16 + - name: Install dependencies + run: yarn install --frozen-lockfile + - name: Run unit tests + run: npx jest diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 599e34703..000000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: node_js -cache: yarn -node_js: - - node - - "12" - - "10" - - "8" - - "6" -git: - depth: 5 -install: - - yarn install --ignore-engines diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 385240a2e..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,22 +0,0 @@ -environment: - - matrix: - - nodejs_version: "12" - - nodejs_version: "10" - - nodejs_version: "8" - - nodejs_version: "6" - -install: - - ps: Install-Product node $env:nodejs_version - - yarn install --ignore-engines - -test_script: - - ./node_modules/.bin/gulp build - - ./node_modules/.bin/jest - -cache: - - node_modules - - "%LOCALAPPDATA%/Yarn" - -build: off -deploy: off From 8408eb4105755c43dbf09a000fd2f1308f240232 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Sat, 25 Sep 2021 08:59:30 +0200 Subject: [PATCH 03/11] Add compilation step --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a7f84a2a9..ffd6fb03b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,6 +41,8 @@ jobs: uses: bahmutov/npm-install@v1 with: install-command: yarn --frozen-lockfile --ignore-engines + - name: Compile project + run: npx gulp compile - name: Run unit tests run: npx jest windows: @@ -57,5 +59,7 @@ jobs: node-version: 16 - name: Install dependencies run: yarn install --frozen-lockfile + - name: Compile project + run: npx gulp compile - name: Run unit tests run: npx jest From 4dd0af024a915bd12d2d53990c5a4fa4129563d5 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Sat, 25 Sep 2021 09:22:58 +0200 Subject: [PATCH 04/11] Release 7.0.37 version --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b1cde29e..762779243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log This project adheres to [Semantic Versioning](http://semver.org/). +## 7.0.37 +* Backport `chalk` to `nanocolors` migration. + ## 7.0.36 * Backport ReDoS vulnerabilities from PostCSS 8. diff --git a/package.json b/package.json index 76c91bb71..65ed1da31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss", - "version": "7.0.36", + "version": "7.0.37", "description": "Tool for transforming styles with JS plugins", "engines": { "node": ">=6.0.0" From 6944e1dd808da66cee4ebf287c66c6aa0fc5c2a0 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Sat, 25 Sep 2021 09:26:06 +0200 Subject: [PATCH 05/11] Remove development keys from package.json --- gulpfile.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index 7af40b342..f0bf3c90c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -37,6 +37,8 @@ gulp.task('build:package', () => { delete json['lint-staged'] delete json.yaspeller delete json.devDependencies + delete json.browserslist + delete json.husky return json })) .pipe(gulp.dest('build')) From 3994c4aa3ce1835c9b36ae17ab94e45c21b56fb2 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Sat, 25 Sep 2021 09:29:00 +0200 Subject: [PATCH 06/11] Release 7.0.38 version --- CHANGELOG.md | 3 +++ lib/processor.es6 | 2 +- package.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 762779243..a4814257b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log This project adheres to [Semantic Versioning](http://semver.org/). +## 7.0.38 +* Update `Processor#version`. + ## 7.0.37 * Backport `chalk` to `nanocolors` migration. diff --git a/lib/processor.es6 b/lib/processor.es6 index 4f83f4560..8309a9cdc 100644 --- a/lib/processor.es6 +++ b/lib/processor.es6 @@ -25,7 +25,7 @@ class Processor { * throw new Error('This plugin works only with PostCSS 6') * } */ - this.version = '7.0.36' + this.version = '7.0.38' /** * Plugins added to this processor. * diff --git a/package.json b/package.json index 65ed1da31..6291fed1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss", - "version": "7.0.37", + "version": "7.0.38", "description": "Tool for transforming styles with JS plugins", "engines": { "node": ">=6.0.0" From 8ba21fd8f4c3bff146b8a71d2d12f31435444394 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Sat, 25 Sep 2021 09:30:39 +0200 Subject: [PATCH 07/11] Remove eslint-ci --- package.json | 3 +-- yarn.lock | 12 ------------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/package.json b/package.json index 6291fed1c..db19e9dbf 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "transpiler" ], "scripts": { - "lint": "eslint-ci *.js lib/*.es6 test/*.js", + "lint": "eslint *.js lib/*.es6 test/*.js", "test": "gulp && jest && yarn lint" }, "funding": { @@ -41,7 +41,6 @@ "concat-with-sourcemaps": "^1.1.0", "del": "^4.1.0", "eslint": "^5.16.0", - "eslint-ci": "^1.0.0", "eslint-config-postcss": "^3.0.7", "eslint-config-standard": "^12.0.0", "eslint-plugin-import": "^2.16.0", diff --git a/yarn.lock b/yarn.lock index 6973a0fb4..fc0bb92a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1871,11 +1871,6 @@ ci-info@^2.0.0: resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46" integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== -ci-job-number@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/ci-job-number/-/ci-job-number-0.3.0.tgz#34bdd114b0dece1960287bd40a57051041a2a800" - integrity sha1-NL3RFLDezhlgKHvUClcFEEGiqAA= - class-utils@^0.3.5: version "0.3.6" resolved "https://registry.yarnpkg.com/class-utils/-/class-utils-0.3.6.tgz#f93369ae8b9a7ce02fd41faad0ca83033190c463" @@ -2585,13 +2580,6 @@ escodegen@^1.9.1: optionalDependencies: source-map "~0.6.1" -eslint-ci@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/eslint-ci/-/eslint-ci-1.0.0.tgz#6bcb238c45d2bf522fad50ad190bc00a206fe2df" - integrity sha512-8Itb/739gpX11nqvWg6kkpge7NwS1o+SkhfFAItfvH9/i5IoY6NLKKKzIagHakT2WmMdnq4HfcymYh/0NGvAVA== - dependencies: - ci-job-number "^0.3.0" - eslint-config-postcss@^3.0.7: version "3.0.7" resolved "https://registry.yarnpkg.com/eslint-config-postcss/-/eslint-config-postcss-3.0.7.tgz#390d97d5ac08db9dc57630153cc0c1821559659b" From 44c581a55a9aab339ee319aa67c264b02c4a6448 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Mon, 4 Oct 2021 22:06:17 +0200 Subject: [PATCH 08/11] Replace nanocolors with picocolors --- lib/css-syntax-error.es6 | 12 ++++++------ lib/terminal-highlight.es6 | 32 ++++++++++++++++---------------- package.json | 2 +- test/browser.test.js | 2 +- test/css-syntax-error.test.js | 4 ++-- yarn.lock | 10 +++++----- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/css-syntax-error.es6 b/lib/css-syntax-error.es6 index d42d26560..f5145407f 100644 --- a/lib/css-syntax-error.es6 +++ b/lib/css-syntax-error.es6 @@ -1,4 +1,4 @@ -import nanocolors from 'nanocolors' +import pico from 'picocolors' import terminalHighlight from './terminal-highlight' @@ -174,7 +174,7 @@ class CssSyntaxError extends Error { let css = this.source if (terminalHighlight) { - if (typeof color === 'undefined') color = nanocolors.isColorSupported + if (typeof color === 'undefined') color = pico.isColorSupported if (color) css = terminalHighlight(css) } @@ -185,14 +185,14 @@ class CssSyntaxError extends Error { let maxWidth = String(end).length function mark (text) { - if (color && nanocolors.red) { - return nanocolors.red(nanocolors.bold(text)) + if (color && pico.red) { + return pico.red(pico.bold(text)) } return text } function aside (text) { - if (color && nanocolors.gray) { - return nanocolors.gray(text) + if (color && pico.gray) { + return pico.gray(text) } return text } diff --git a/lib/terminal-highlight.es6 b/lib/terminal-highlight.es6 index 5c01c2bc4..674d633d6 100644 --- a/lib/terminal-highlight.es6 +++ b/lib/terminal-highlight.es6 @@ -1,24 +1,24 @@ -import nanocolors from 'nanocolors' +import pico from 'picocolors' import tokenizer from './tokenize' import Input from './input' const HIGHLIGHT_THEME = { - brackets: nanocolors.cyan, - 'at-word': nanocolors.cyan, - comment: nanocolors.gray, - string: nanocolors.green, - class: nanocolors.yellow, - call: nanocolors.cyan, - hash: nanocolors.magenta, - '(': nanocolors.cyan, - ')': nanocolors.cyan, - '{': nanocolors.yellow, - '}': nanocolors.yellow, - '[': nanocolors.yellow, - ']': nanocolors.yellow, - ':': nanocolors.yellow, - ';': nanocolors.yellow + brackets: pico.cyan, + 'at-word': pico.cyan, + comment: pico.gray, + string: pico.green, + class: pico.yellow, + call: pico.cyan, + hash: pico.magenta, + '(': pico.cyan, + ')': pico.cyan, + '{': pico.yellow, + '}': pico.yellow, + '[': pico.yellow, + ']': pico.yellow, + ':': pico.yellow, + ';': pico.yellow } function getTokenType ([type, value], processor) { diff --git a/package.json b/package.json index db19e9dbf..2c3c07709 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "homepage": "https://postcss.org/", "repository": "postcss/postcss", "dependencies": { - "nanocolors": "^0.2.2", + "picocolors": "^0.2.1", "source-map": "^0.6.1" }, "devDependencies": { diff --git a/test/browser.test.js b/test/browser.test.js index f1900bbbf..c89a8b49e 100644 --- a/test/browser.test.js +++ b/test/browser.test.js @@ -1,5 +1,5 @@ jest.doMock('fs', () => ({})) -jest.doMock('nanocolors', () => require('nanocolors/index.browser.cjs')) +jest.doMock('picocolors', () => require('picocolors/picocolors.browser.js')) let postcss = require('..') diff --git a/test/css-syntax-error.test.js b/test/css-syntax-error.test.js index 4abc7d5c3..4a60954ad 100644 --- a/test/css-syntax-error.test.js +++ b/test/css-syntax-error.test.js @@ -1,6 +1,6 @@ -let nanocolors = require('nanocolors') let stripAnsi = require('strip-ansi') let Concat = require('concat-with-sourcemaps') +let pico = require('picocolors') let path = require('path') let CssSyntaxError = require('../lib/css-syntax-error') @@ -45,7 +45,7 @@ it('has stack trace', () => { }) it('highlights broken line with colors', () => { - let c = nanocolors + let c = pico expect(parseError('#a .b {').showSourceCode(true)).toEqual( c.red(c.bold('>')) + c.gray(' 1 | ') + diff --git a/yarn.lock b/yarn.lock index fc0bb92a1..9e829d427 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5117,11 +5117,6 @@ nan@^2.9.2: resolved "https://registry.yarnpkg.com/nan/-/nan-2.13.2.tgz#f51dc7ae66ba7d5d55e1e6d4d8092e802c9aefe7" integrity sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw== -nanocolors@^0.2.2: - version "0.2.2" - resolved "https://registry.yarnpkg.com/nanocolors/-/nanocolors-0.2.2.tgz#94a4b7e45ecdebdbea7cb0a8349f9447a9677675" - integrity sha512-t4mwdKizEGLFeZzDbr1r6SjwKYZQEB0Z/trGsdAIsw5EadaR010/zvJ0arkw6vznyTevcMi9BtppprJ5aqLXRg== - nanomatch@^1.2.9: version "1.2.13" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" @@ -5705,6 +5700,11 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= +picocolors@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-0.2.1.tgz#570670f793646851d1ba135996962abad587859f" + integrity sha512-cMlDqaLEqfSaW8Z7N5Jw+lyIW869EzT73/F5lhtY9cLGoVxSXznfgfXMO0Z5K0o0Q2TkTXq+0KFsdnSe3jDViA== + pify@^2.0.0: version "2.3.0" resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" From 6791bd3d5f7ab27ad36dc075033a5beb4bdbfe9e Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Mon, 4 Oct 2021 22:08:29 +0200 Subject: [PATCH 09/11] Reduce npm package --- package.json | 4 +++ yarn.lock | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/package.json b/package.json index 2c3c07709..890c0dee4 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@logux/eslint-config": "^28.1.0", "babel-eslint": "^10.1.0", "babel-plugin-add-module-exports": "^1.0.4", + "clean-publish": "^3.0.3", "concat-with-sourcemaps": "^1.1.0", "del": "^4.1.0", "eslint": "^5.16.0", @@ -169,6 +170,9 @@ } ] }, + "clean-publish": { + "cleanDocs": true + }, "yaspeller": { "lang": "en", "format": "markdown", diff --git a/yarn.lock b/yarn.lock index 9e829d427..68cad5029 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1881,6 +1881,15 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +clean-publish@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/clean-publish/-/clean-publish-3.0.3.tgz#d7181d9fd109765226d4174706947759b215f4c7" + integrity sha512-Ly9CrWC4yDgNQF1qaLVVUNLN/VGM2GqJC3itbamP14Ioj4+G3jwFfL2xu6pF2GNvdXEzZZxzUkCV48rbMrUfJA== + dependencies: + cross-spawn "^7.0.3" + fs-extra "^10.0.0" + lilconfig "^2.0.3" + cli-cursor@^2.0.0, cli-cursor@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" @@ -2143,6 +2152,15 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5: shebang-command "^1.2.0" which "^1.2.9" +cross-spawn@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" + integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + dependencies: + path-key "^3.1.0" + shebang-command "^2.0.0" + which "^2.0.1" + css@2.X, css@^2.2.1: version "2.2.4" resolved "https://registry.yarnpkg.com/css/-/css-2.2.4.tgz#c646755c73971f2bba6a601e2cf2fd71b1298929" @@ -3109,6 +3127,15 @@ fragment-cache@^0.2.1: dependencies: map-cache "^0.2.2" +fs-extra@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1" + integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs-extra@^7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" @@ -3326,6 +3353,11 @@ graceful-fs@4.X, graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.15, g resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00" integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA== +graceful-fs@^4.2.0: + version "4.2.8" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a" + integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg== + growly@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" @@ -4555,6 +4587,15 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" +jsonfile@^6.0.1: + version "6.1.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" + integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== + dependencies: + universalify "^2.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + jsprim@^1.2.2: version "1.4.1" resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" @@ -4684,6 +4725,11 @@ liftoff@^3.1.0: rechoir "^0.6.2" resolve "^1.1.7" +lilconfig@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-2.0.3.tgz#68f3005e921dafbd2a2afb48379986aa6d2579fd" + integrity sha512-EHKqr/+ZvdKCifpNrJCKxBTgk5XupZA3y/aCPY9mxfgBzmgh93Mt/WqjjQ38oMxXuvDokaKiM3lAgvSH2sjtHg== + lines-and-columns@^1.1.6: version "1.1.6" resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00" @@ -5650,6 +5696,11 @@ path-key@^2.0.0, path-key@^2.0.1: resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A= +path-key@^3.1.0: + version "3.1.1" + resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" + integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== + path-parse@^1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" @@ -6393,11 +6444,23 @@ shebang-command@^1.2.0: dependencies: shebang-regex "^1.0.0" +shebang-command@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" + integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== + dependencies: + shebang-regex "^3.0.0" + shebang-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= +shebang-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" + integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== + shellwords@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" @@ -7078,6 +7141,11 @@ universalify@^0.1.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== +universalify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" + integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== + unset-value@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559" @@ -7276,6 +7344,13 @@ which@^1.2.10, which@^1.2.14, which@^1.2.9, which@^1.3.0: dependencies: isexe "^2.0.0" +which@^2.0.1: + version "2.0.2" + resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" + integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== + dependencies: + isexe "^2.0.0" + wide-align@^1.1.0: version "1.1.3" resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457" From e17c1ef7623a71be5732432ca8499bc9928aa08d Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Mon, 4 Oct 2021 22:09:54 +0200 Subject: [PATCH 10/11] Release 7.0.39 version --- CHANGELOG.md | 4 ++++ lib/processor.es6 | 2 +- package.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4814257b..5b7f8563e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log This project adheres to [Semantic Versioning](http://semver.org/). +## 7.0.39 +* Reduce package size. +* Backport `nanocolors` to `picocolors` migration. + ## 7.0.38 * Update `Processor#version`. diff --git a/lib/processor.es6 b/lib/processor.es6 index 8309a9cdc..16d8ef9f9 100644 --- a/lib/processor.es6 +++ b/lib/processor.es6 @@ -25,7 +25,7 @@ class Processor { * throw new Error('This plugin works only with PostCSS 6') * } */ - this.version = '7.0.38' + this.version = '7.0.39' /** * Plugins added to this processor. * diff --git a/package.json b/package.json index 890c0dee4..0abf5fa66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss", - "version": "7.0.38", + "version": "7.0.39", "description": "Tool for transforming styles with JS plugins", "engines": { "node": ">=6.0.0" From 753a22531c12a88b7699907ac4e5449f8e28af15 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Mon, 4 Oct 2021 22:12:52 +0200 Subject: [PATCH 11/11] Remove docs from npm package --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index f0bf3c90c..19e8b7609 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -49,7 +49,7 @@ gulp.task('build:docs', () => { .trim().split(/\n+/) .concat([ 'package.json', '.npmignore', 'lib/*', 'test/*', 'CONTRIBUTING.md', - 'node_modules/**/*', 'docs/api.md', 'docs/plugins.md', '*-cn.md', + 'node_modules/**/*', 'docs/**/*', '*-cn.md', 'docs/writing-a-plugin.md', 'coverage', 'coverage/*', 'coverage/**/*' ]).map(i => '!' + i) return gulp.src(['**/*'].concat(ignore))