Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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