Skip to content

Commit

Permalink
Merge pull request #148 from niksy/postcss-8-support
Browse files Browse the repository at this point in the history
Add support for PostCSS 8
  • Loading branch information
sergcen committed Oct 23, 2020
2 parents 396829b + 2da8782 commit 2d959f9
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
node_modules
test/fixtures/*.actual.css
test/fixtures/build
test/fixtures/test
.idea
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,7 +10,7 @@
## Installation

```console
$ npm install postcss-url
$ npm install postcss postcss-url
```

## Basic example - rebase
Expand Down
89 changes: 79 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -26,16 +26,19 @@
"mime": "2.3.1",
"minimatch": "3.0.4",
"mkdirp": "0.5.0",
"postcss": "7.0.2",
"xxhashjs": "0.2.1"
},
"devDependencies": {
"chai": "4.1.2",
"eslint": "5.16.0",
"mocha": "5.2.0",
"npmpub": "4.1.0",
"postcss": "8.1.2",
"postcss-import": "12.0.0"
},
"peerDependencies": {
"postcss": "8.1.2"
},
"scripts": {
"lint": "eslint --fix .",
"tests": "mocha",
Expand Down
34 changes: 18 additions & 16 deletions src/index.js
@@ -1,30 +1,32 @@
'use strict';

const path = require('path');
const postcss = require('postcss');

const declProcessor = require('./lib/decl-processor').declProcessor;

/**
*
* @type {Plugin}
*/
module.exports = postcss.plugin('postcss-url', (options) => {
const plugin = (options) => {
options = options || {};

return function(styles, result) {
const promises = [];
const opts = result.opts;
const from = opts.from ? path.dirname(opts.from) : '.';
const to = opts.to ? path.dirname(opts.to) : from;
return {
postcssPlugin: 'postcss-url',
Once(styles, { result }) {
const promises = [];
const opts = result.opts;
const from = opts.from ? path.dirname(opts.from) : '.';
const to = opts.to ? path.dirname(opts.to) : from;

styles.walkDecls((decl) =>
promises.push(declProcessor(from, to, options, result, decl))
);
styles.walkDecls((decl) =>
promises.push(declProcessor(from, to, options, result, decl))
);

return Promise.all(promises);
return Promise.all(promises);
}
};
});
};

plugin.postcss = true;

module.exports = plugin;

/**
* @callback PostcssUrl~UrlProcessor
Expand Down
8 changes: 4 additions & 4 deletions test/setup.js
Expand Up @@ -13,15 +13,15 @@ global.postcssUrl = url;
function compareFixtures(name, msg, opts, postcssOpts, plugin) {
it(msg, () => {
opts = opts || {};
const pcss = postcss();
const plugins = [];

if (plugin) {
pcss.use(plugin());
plugins.push(plugin());
}

pcss.use(url(opts));
plugins.push(url(opts));

return pcss.process(read(`fixtures/${name}`), postcssOpts)
return postcss(plugins).process(read(`fixtures/${name}`), postcssOpts)
.then((result) => {
const actual = result.css;
const expected = read(`fixtures/${name}.expected`);
Expand Down

0 comments on commit 2d959f9

Please sign in to comment.