From 3bc65d9613823b2fbfad5e95f1f5a9f1151069bf Mon Sep 17 00:00:00 2001 From: romainmenke Date: Sat, 20 Nov 2021 16:20:53 +0100 Subject: [PATCH 1/3] wip --- .../postcss-dir-pseudo-class/.editorconfig | 15 ----------- .../.github/workflows/test.yml | 18 ------------- plugins/postcss-dir-pseudo-class/package.json | 26 +++++++------------ 3 files changed, 10 insertions(+), 49 deletions(-) delete mode 100644 plugins/postcss-dir-pseudo-class/.editorconfig delete mode 100644 plugins/postcss-dir-pseudo-class/.github/workflows/test.yml diff --git a/plugins/postcss-dir-pseudo-class/.editorconfig b/plugins/postcss-dir-pseudo-class/.editorconfig deleted file mode 100644 index e06d7982b..000000000 --- a/plugins/postcss-dir-pseudo-class/.editorconfig +++ /dev/null @@ -1,15 +0,0 @@ -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_style = tab -insert_final_newline = true -trim_trailing_whitespace = true - -[*.md] -trim_trailing_whitespace = false - -[*.{json,md,yml}] -indent_size = 2 -indent_style = space diff --git a/plugins/postcss-dir-pseudo-class/.github/workflows/test.yml b/plugins/postcss-dir-pseudo-class/.github/workflows/test.yml deleted file mode 100644 index 4a287db8e..000000000 --- a/plugins/postcss-dir-pseudo-class/.github/workflows/test.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: test -on: - push: - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - node: [12, 16] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} - - - run: yarn install --ignore-scripts - - run: yarn run test diff --git a/plugins/postcss-dir-pseudo-class/package.json b/plugins/postcss-dir-pseudo-class/package.json index d52d4a1dc..081e5ab6c 100644 --- a/plugins/postcss-dir-pseudo-class/package.json +++ b/plugins/postcss-dir-pseudo-class/package.json @@ -4,21 +4,21 @@ "description": "Use the :dir pseudo-class in CSS", "author": "Jonathan Neal ", "license": "CC0-1.0", - "repository": "jonathantneal/postcss-dir-pseudo-class", "homepage": "https://github.com/jonathantneal/postcss-dir-pseudo-class#readme", "bugs": "https://github.com/jonathantneal/postcss-dir-pseudo-class/issues", "files": [ "index.js" ], "scripts": { - "prepublishOnly": "npm test", + "prepublishOnly": "npm run build --if-present && npm run test --if-present", "test": "echo 'Running tests...'; npm run test:js && npm run test:tape", "test:ec": "echint --ignore index.*.js test", "test:js": "eslint *.js --cache --ignore-path .gitignore --quiet", - "test:tape": "postcss-tape" + "test:tape": "postcss-tape", + "stryker": "stryker run --logLevel error" }, "engines": { - "node": ">=12" + "node": "^12 || ^14 || >=16" }, "dependencies": { "postcss-selector-parser": "6.0.6" @@ -33,17 +33,6 @@ "peerDependencies": { "postcss": "^8.3" }, - "eslintConfig": { - "extends": "dev", - "rules": { - "complexity": [ - "error", - { - "max": 30 - } - ] - } - }, "keywords": [ "postcss", "css", @@ -59,5 +48,10 @@ "right", "right-to-left", "rtl" - ] + ], + "repository": { + "type": "git", + "url": "https://github.com/csstools/postcss-plugins.git", + "directory": "" + } } From 069d2082aec82f8335e2a930309569d76bac756b Mon Sep 17 00:00:00 2001 From: romainmenke Date: Sat, 20 Nov 2021 18:11:56 +0100 Subject: [PATCH 2/3] migrate postcss-dir-pseudo-class --- plugins/postcss-dir-pseudo-class/.gitignore | 4 +- .../postcss-dir-pseudo-class/CONTRIBUTING.md | 65 ------------------- plugins/postcss-dir-pseudo-class/README.md | 8 +-- plugins/postcss-dir-pseudo-class/package.json | 34 ++++++---- plugins/postcss-dir-pseudo-class/src/cli.js | 17 +++++ .../{ => src}/index.js | 26 ++++---- 6 files changed, 55 insertions(+), 99 deletions(-) delete mode 100644 plugins/postcss-dir-pseudo-class/CONTRIBUTING.md create mode 100644 plugins/postcss-dir-pseudo-class/src/cli.js rename plugins/postcss-dir-pseudo-class/{ => src}/index.js (92%) diff --git a/plugins/postcss-dir-pseudo-class/.gitignore b/plugins/postcss-dir-pseudo-class/.gitignore index 683bd2956..b5d13c8c0 100644 --- a/plugins/postcss-dir-pseudo-class/.gitignore +++ b/plugins/postcss-dir-pseudo-class/.gitignore @@ -1,10 +1,10 @@ node_modules -index.*.* +dist package-lock.json yarn.lock *.log* *.result.css -.* +*.result.css.map !.editorconfig !.gitignore !.rollup.js diff --git a/plugins/postcss-dir-pseudo-class/CONTRIBUTING.md b/plugins/postcss-dir-pseudo-class/CONTRIBUTING.md deleted file mode 100644 index 76d75aa12..000000000 --- a/plugins/postcss-dir-pseudo-class/CONTRIBUTING.md +++ /dev/null @@ -1,65 +0,0 @@ -# Contributing to PostCSS Dir Pseudo Class - -You want to help? You rock! Now, take a moment to be sure your contributions -make sense to everyone else. - -## Reporting Issues - -Found a problem? Want a new feature? - -- See if your issue or idea has [already been reported]. -- Provide a [reduced test case] or a [live example]. - -Remember, a bug is a _demonstrable problem_ caused by _our_ code. - -## Submitting Pull Requests - -Pull requests are the greatest contributions, so be sure they are focused in -scope and avoid unrelated commits. - -1. To begin; [fork this project], clone your fork, and add our upstream. - ```bash - # Clone your fork of the repo into the current directory - git clone git@github.com:YOUR_USER/postcss-dir-pseudo-class.git - - # Navigate to the newly cloned directory - cd postcss-dir-pseudo-class - - # Assign the original repo to a remote called "upstream" - git remote add upstream git@github.com:jonathantneal/postcss-dir-pseudo-class.git - - # Install the tools necessary for testing - npm install - ``` - -2. Create a branch for your feature or fix: - ```bash - # Move into a new branch for your feature - git checkout -b feature/thing - ``` - ```bash - # Move into a new branch for your fix - git checkout -b fix/something - ``` - -3. If your code follows our practices, then push your feature branch: - ```bash - # Test current code - npm test - ``` - ```bash - # Push the branch for your new feature - git push origin feature/thing - ``` - ```bash - # Or, push the branch for your update - git push origin update/something - ``` - -That’s it! Now [open a pull request] with a clear title and description. - -[already been reported]: issues -[fork this project]: fork -[live example]: https://codepen.io/pen -[open a pull request]: https://help.github.com/articles/using-pull-requests/ -[reduced test case]: https://css-tricks.com/reduced-test-cases/ diff --git a/plugins/postcss-dir-pseudo-class/README.md b/plugins/postcss-dir-pseudo-class/README.md index 99cfbfc80..56940098a 100644 --- a/plugins/postcss-dir-pseudo-class/README.md +++ b/plugins/postcss-dir-pseudo-class/README.md @@ -150,20 +150,18 @@ article h3:dir(ltr) { } ``` -[cli-img]: https://github.com/csstools/postcss-dir-pseudo-class/workflows/test/badge.svg -[cli-url]: https://github.com/csstools/postcss-dir-pseudo-class/actions/workflows/test.yml?query=workflow/test +[cli-img]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml/badge.svg +[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test [css-img]: https://cssdb.org/badge/dir-pseudo-class.svg [css-url]: https://cssdb.org/#dir-pseudo-class [git-img]: https://img.shields.io/badge/support-chat-blue.svg [git-url]: https://gitter.im/postcss/postcss [npm-img]: https://img.shields.io/npm/v/postcss-dir-pseudo-class.svg [npm-url]: https://www.npmjs.com/package/postcss-dir-pseudo-class -[win-img]: https://img.shields.io/appveyor/ci/jonathantneal/postcss-dir-pseudo-class.svg -[win-url]: https://ci.appveyor.com/project/jonathantneal/postcss-dir-pseudo-class [Gulp PostCSS]: https://github.com/postcss/gulp-postcss [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss [PostCSS]: https://github.com/postcss/postcss [PostCSS Loader]: https://github.com/postcss/postcss-loader -[PostCSS Dir Pseudo Class]: https://github.com/jonathantneal/postcss-dir-pseudo-class +[PostCSS Dir Pseudo Class]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class [Selectors]: https://www.w3.org/TR/selectors-4/#the-dir-pseudo diff --git a/plugins/postcss-dir-pseudo-class/package.json b/plugins/postcss-dir-pseudo-class/package.json index 081e5ab6c..d17b60034 100644 --- a/plugins/postcss-dir-pseudo-class/package.json +++ b/plugins/postcss-dir-pseudo-class/package.json @@ -4,18 +4,27 @@ "description": "Use the :dir pseudo-class in CSS", "author": "Jonathan Neal ", "license": "CC0-1.0", - "homepage": "https://github.com/jonathantneal/postcss-dir-pseudo-class#readme", - "bugs": "https://github.com/jonathantneal/postcss-dir-pseudo-class/issues", + "homepage": "https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class#readme", + "bugs": "https://github.com/csstools/postcss-plugins/issues", + "main": "dist/index.cjs", + "module": "dist/index.mjs", "files": [ - "index.js" + "CHANGELOG.md", + "INSTALL.md", + "LICENSE.md", + "README.md", + "dist" ], + "bin": { + "postcss-dir-pseudo-class": "dist/cli.mjs" + }, "scripts": { - "prepublishOnly": "npm run build --if-present && npm run test --if-present", - "test": "echo 'Running tests...'; npm run test:js && npm run test:tape", - "test:ec": "echint --ignore index.*.js test", - "test:js": "eslint *.js --cache --ignore-path .gitignore --quiet", - "test:tape": "postcss-tape", - "stryker": "stryker run --logLevel error" + "prepublishOnly": "npm run build && npm run test", + "lint": "eslint src/**/*.js", + "test": "postcss-tape", + "build": "rollup -c ../../rollup/default.js", + "stryker": "stryker run --logLevel error", + "cli": "postcss-dir-pseudo-class" }, "engines": { "node": "^12 || ^14 || >=16" @@ -24,11 +33,8 @@ "postcss-selector-parser": "6.0.6" }, "devDependencies": { - "eslint": "7.32.0", - "eslint-config-dev": "2.0.0", "postcss": "8.3.6", - "postcss-tape": "6.0.1", - "pre-commit": "1.2.2" + "postcss-tape": "6.0.1" }, "peerDependencies": { "postcss": "^8.3" @@ -52,6 +58,6 @@ "repository": { "type": "git", "url": "https://github.com/csstools/postcss-plugins.git", - "directory": "" + "directory": "plugins/postcss-dir-pseudo-class" } } diff --git a/plugins/postcss-dir-pseudo-class/src/cli.js b/plugins/postcss-dir-pseudo-class/src/cli.js new file mode 100644 index 000000000..39452ef27 --- /dev/null +++ b/plugins/postcss-dir-pseudo-class/src/cli.js @@ -0,0 +1,17 @@ +import plugin from './index'; +import { cli, helpTextLogger } from '@csstools/base-cli'; + +cli( + plugin, + ['dir', 'preserve', 'shadow'], + helpTextLogger( + 'postcss-dir-pseudo-class', + 'PostCSS Dir Pseudo Class', + 'Lets you style by directionality using the `:dir()` pseudo-class in CSS', + { + dir: 'ltr', + preserve: true, + shadow: true, + }, + ), +); diff --git a/plugins/postcss-dir-pseudo-class/index.js b/plugins/postcss-dir-pseudo-class/src/index.js similarity index 92% rename from plugins/postcss-dir-pseudo-class/index.js rename to plugins/postcss-dir-pseudo-class/src/index.js index 186d39863..053f7db72 100644 --- a/plugins/postcss-dir-pseudo-class/index.js +++ b/plugins/postcss-dir-pseudo-class/src/index.js @@ -1,6 +1,6 @@ const selectorParser = require('postcss-selector-parser'); -const dirRegex = /:dir\([^\)]*\)/; +const dirRegex = /:dir\([^)]*\)/; module.exports = function creator(opts) { const dir = Object(opts).dir; @@ -16,7 +16,7 @@ module.exports = function creator(opts) { return; } - let currentRule = rule + let currentRule = rule; // conditionally preserve the original rule if (preserve) { @@ -40,7 +40,7 @@ module.exports = function creator(opts) { // preserve the selector tree if (prevIsSpaceCombinator && (nextIsSpaceCombinator || !next)) { node.replaceWith( - selectorParser.universal() + selectorParser.universal(), ); } else { node.remove(); @@ -55,8 +55,8 @@ module.exports = function creator(opts) { if (first && !firstIsHtml && !firstIsRoot && !firstIsSpaceCombinator) { selector.prepend( selectorParser.combinator({ - value: ' ' - }) + value: ' ', + }), ); } @@ -71,18 +71,18 @@ module.exports = function creator(opts) { attribute: 'dir', operator: '=', quoteMark: '"', - value: `"${ value }"` + value: `"${ value }"`, }); // :host-context([dir]) for Shadow DOM CSS const hostContextPseudo = selectorParser.pseudo({ - value: ':host-context' + value: ':host-context', }); hostContextPseudo.append(dirAttr); // not[dir] attribute const notDirAttr = selectorParser.pseudo({ - value: `${firstIsHtml || firstIsRoot ? '' : 'html'}:not` + value: `${firstIsHtml || firstIsRoot ? '' : 'html'}:not`, }); notDirAttr.append( @@ -90,8 +90,8 @@ module.exports = function creator(opts) { attribute: 'dir', operator: '=', quoteMark: '"', - value: `"${ 'ltr' === value ? 'rtl' : 'ltr' }"` - }) + value: `"${ 'ltr' === value ? 'rtl' : 'ltr' }"`, + }), ); if (isdir) { @@ -117,8 +117,8 @@ module.exports = function creator(opts) { }); }); }).processSync(currentRule.selector); - } - } -} + }, + }; +}; module.exports.postcss = true; From 884858a208d788bf92733f554f79a44962c58d62 Mon Sep 17 00:00:00 2001 From: Romain Menke <11521496+romainmenke@users.noreply.github.com> Date: Sat, 20 Nov 2021 19:04:43 +0100 Subject: [PATCH 3/3] cleanup --- plugins/postcss-dir-pseudo-class/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/postcss-dir-pseudo-class/package.json b/plugins/postcss-dir-pseudo-class/package.json index d17b60034..d65a523ae 100644 --- a/plugins/postcss-dir-pseudo-class/package.json +++ b/plugins/postcss-dir-pseudo-class/package.json @@ -23,8 +23,7 @@ "lint": "eslint src/**/*.js", "test": "postcss-tape", "build": "rollup -c ../../rollup/default.js", - "stryker": "stryker run --logLevel error", - "cli": "postcss-dir-pseudo-class" + "stryker": "stryker run --logLevel error" }, "engines": { "node": "^12 || ^14 || >=16"