From ec9914e0b9473a75a5d1fe32ea4311555eb81b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=BCller?= Date: Wed, 16 Sep 2020 20:09:26 +0200 Subject: [PATCH 1/3] bump to postcss 8, bump dependencies, improve speed using postcss 8 api --- README.md | 3 +++ index.js | 30 +++++++++++++++++------------- package.json | 17 ++++++++++++----- test.js | 36 ++++++++++++++++++------------------ 4 files changed, 50 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index b65aa16..51043af 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,9 @@ } ``` +### Installation +`npm install --save-dev postcss postcss-replace-overflow-wrap` + ## Usage ```js diff --git a/index.js b/index.js index e56b67f..a661048 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,19 @@ -var postcss = require('postcss') +// @ts-check -module.exports = postcss.plugin('postcss-replace-overflow-wrap', function (opts) { - opts = opts || {} - var method = opts.method || 'replace' +module.exports = function (opts) { + opts = opts || {} + var method = opts.method || 'replace' + return { + postcssPlugin: 'postcss-replace-overflow-wrap', + Declaration: { + 'overflow-wrap': decl => { + decl.cloneBefore({ prop: 'word-wrap' }) + if (method === 'replace') { + decl.remove() + } + } + } + } +} - return function (css) { - css.walkDecls('overflow-wrap', function (decl) { - decl.cloneBefore({ prop: 'word-wrap' }) - if (method === 'replace') { - decl.remove() - } - }) - } -}) +module.exports.postcss = true diff --git a/package.json b/package.json index 8b649d2..c472005 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,7 @@ "files": [ "index.js" ], - "dependencies": { - "postcss": "^7.0.2" - }, + "dependencies": {}, "devDependencies": { "ava": "^0.25.0", "eslint": "^5.3.0", @@ -34,7 +32,11 @@ "eslint-plugin-node": "^7.0.1", "eslint-plugin-promise": "^3.8.0", "eslint-plugin-security": "^1.4.0", - "eslint-plugin-standard": "^3.1.0" + "eslint-plugin-standard": "^3.1.0", + "postcss": "^8.0.3" + }, + "peerDependencies": { + "postcss": "^8.0.3" }, "scripts": { "test": "ava && eslint *.js" @@ -43,7 +45,12 @@ "extends": "eslint-config-postcss/es5", "rules": { "max-len": 0, - "es5/no-modules": false + "es5/no-modules": false, + "indent": [ + "warn", + 4 + ], + "es5/no-arrow-functions": 0 } } } diff --git a/test.js b/test.js index 72cecb6..0bd69f2 100644 --- a/test.js +++ b/test.js @@ -3,31 +3,31 @@ import test from 'ava' import plugin from './' -function run (t, input, output, opts = { }) { //eslint-disable-line - return postcss([plugin(opts)]).process(input) - .then(function (result) { - t.deepEqual(result.css, output) - t.deepEqual(result.warnings().length, 0) - }) +function run(t, input, output, opts = {}) { //eslint-disable-line + return postcss([plugin(opts)]).process(input) + .then(function (result) { + t.deepEqual(result.css, output) + t.deepEqual(result.warnings().length, 0) + }) } test('replace overflow-wrap with word-wrap, no options', function (t) { - return run(t, - '.someClass{ overflow-wrap: break-word; }', - '.someClass{ word-wrap: break-word; }' - , {}) + return run(t, + '.someClass{ overflow-wrap: break-word; }', + '.someClass{ word-wrap: break-word; }' + , {}) }) test('add word-wrap right before overflow-wrap due to passed arg', function (t) { - return run(t, - '.anotherClass{font-size:1rem;overflow-wrap:break-word;}', - '.anotherClass{font-size:1rem;word-wrap:break-word;overflow-wrap:break-word;}' - , { method: 'copy' }) + return run(t, + '.anotherClass{font-size:1rem;overflow-wrap:break-word;}', + '.anotherClass{font-size:1rem;word-wrap:break-word;overflow-wrap:break-word;}' + , { method: 'copy' }) }) test('replace overflow-wrap with word-wrap, replace method', function (t) { - return run(t, - 'main { overflow-wrap: normal; }', - 'main { word-wrap: normal; }' - , { method: 'replace' }) + return run(t, + 'main { overflow-wrap: normal; }', + 'main { word-wrap: normal; }' + , { method: 'replace' }) }) From f7c1388dc590d5bcde7c9de360d8a28cf6009d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=BCller?= Date: Wed, 16 Sep 2020 20:09:32 +0200 Subject: [PATCH 2/3] 4.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c472005..edeb595 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-replace-overflow-wrap", - "version": "3.0.0", + "version": "4.0.0", "description": "PostCSS plugin to replace overflow-wrap with word-wrap or optionally retain both declarations.", "keywords": [ "postcss", From 9fee648455ab6758a58f93bf39e4cc12ef03887b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=BCller?= Date: Wed, 16 Sep 2020 20:11:57 +0200 Subject: [PATCH 3/3] update readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 51043af..9c8f5f3 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,11 @@ ### Installation `npm install --save-dev postcss postcss-replace-overflow-wrap` +For Postcss 7 or earlier use Version 3 or earlier: + +`npm install --save-dev postcss-replace-overflow-wrap@3` + + ## Usage ```js