Skip to content

Commit

Permalink
Upgrade to postcss 7, refactored code to current plugin boilerplate
Browse files Browse the repository at this point in the history
closes #15
  • Loading branch information
robkorv committed Nov 11, 2018
1 parent d0dca54 commit 60b5a9a
Show file tree
Hide file tree
Showing 9 changed files with 3,786 additions and 1,049 deletions.
14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
language: node_js
cache: yarn
node_js:
- node
- "8"
- "6"
- "4"
install:
- YARN_IGNORE_ENGINES=true yarn
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.0.0 - Upgrade to postcss 7, refactored code to current plugin boilerplate
* [#15](https://github.com/robkorv/postcss-selector-prefix/issues/15) main and developer dependencies upgraded to last major versions.
* Refactored code to match the current [plugin boilerplate](https://github.com/postcss/postcss-plugin-boilerplate)

## 3.0.1 - Dev dependencies update
* [#13](https://github.com/robkorv/postcss-selector-prefix/issues/13) developer dependencies updated following a vulnerability report.
* fixed links in 2.1.0 changelog lines.
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [PostCSS Selector Prefix](https://github.com/robkorv/postcss-selector-prefix)
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![devDependency Status][daviddm-image-dev]][daviddm-url-dev]

[PostCSS] plugin to add a selector prefix to all selectors.

Expand Down Expand Up @@ -68,6 +68,8 @@ postcss([ require('postcss-selector-prefix')('#prefix') ])
[npm-url]: https://npmjs.org/package/postcss-selector-prefix
[travis-image]: https://travis-ci.org/robkorv/postcss-selector-prefix.svg?branch=master
[travis-url]: https://travis-ci.org/robkorv/postcss-selector-prefix
[daviddm-image]: https://david-dm.org/robkorv/postcss-selector-prefix.svg?theme=shields.io
[daviddm-image]: https://david-dm.org/robkorv/postcss-selector-prefix.svg
[daviddm-url]: https://david-dm.org/robkorv/postcss-selector-prefix
[daviddm-image-dev]: https://david-dm.org/robkorv/postcss-selector-prefix/dev-status.svg
[daviddm-url-dev]: https://david-dm.org/robkorv/postcss-selector-prefix?type=dev
[PostCSS]: https://github.com/postcss/postcss
41 changes: 22 additions & 19 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
'use strict';
var eslint = require('gulp-eslint')
var gulp = require('gulp')
var jest = require('gulp-jest').default

const eslint = require('gulp-eslint');
const mocha = require('gulp-mocha');
const gulp = require('gulp');
var files = ['index.js', 'test/*.js', 'gulpfile.js']

let files = ['index.js', 'test/*.js', 'gulpfile.js'];
function lintTask (cb) {
gulp.src(files)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
cb()
}

function lintTask(cb) {
function lintWatchTask (cb) {
gulp.src(files)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
cb();
cb()
}

function testTask(cb) {
function testTask (cb) {
gulp.src('test/*.js', { read: false })
.pipe(mocha());
cb();
.pipe(jest())
cb()
}

const defaultTask = gulp.series(lintTask, testTask);
var defaultTask = gulp.series(lintTask, testTask)

function watchTask(cb) {
gulp.watch(files, defaultTask);
cb();
function watchTask (cb) {
gulp.watch(files, gulp.series(lintWatchTask, testTask))
cb()
}

const devTask = gulp.series(defaultTask, watchTask);

exports.default = defaultTask;
exports.dev = devTask;
exports.default = defaultTask
exports.watch = gulp.series(lintWatchTask, testTask, watchTask)
37 changes: 18 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
'use strict';
const postcss = require('postcss');
const escapeStringRegexp = require('escape-string-regexp');
var postcss = require('postcss')
var escapeStringRegexp = require('escape-string-regexp')

let plugin = postcss.plugin('postcss-selector-prefix', (prefix) => {
return (root) => {
root.walkRules((rule) => {
var plugin = postcss.plugin('postcss-selector-prefix', function (prefix) {
return function (root) {
root.walkRules(function (rule) {
// don't touch @keyframes children
if (rule.parent && rule.parent.name === 'keyframes') {
return;
return
}
rule.selectors = rule.selectors.map((selector) => {
rule.selectors = rule.selectors.map(function (selector) {
// replace combinator selectors that can't be prefixed.
selector = selector.replace(
/^html\.body\.|^html\.|^body\./, prefix + '.'
);
)

// replace descendant combinators that can't be prefixed.
selector = selector.replace(/^body$|^html$/, prefix);
selector = selector.replace(/^body$|^html$/, prefix)

// create prefix regex.
let escapedPrefix = escapeStringRegexp(prefix);
let re = new RegExp('^' + escapedPrefix);
var escapedPrefix = escapeStringRegexp(prefix)
var re = new RegExp('^' + escapedPrefix) // eslint-disable-line security/detect-non-literal-regexp

// don't prefix the already prefixed.
if (selector.match(re)) {
return selector;
return selector
} else {
return prefix + ' ' + selector;
return prefix + ' ' + selector
}
});
});
};
});
})
})
}
})

module.exports = plugin;
module.exports = plugin
Loading

0 comments on commit 60b5a9a

Please sign in to comment.