Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/5.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
borodean committed Aug 31, 2017
2 parents 384ee77 + 96e8c22 commit 16bbee9
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: false
language: node_js
node_js:
- "stable"
- stable
- "6"
- "4"
- "0.12"
after_success: npm run coveralls
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## 5.0.0
**Breaking**

- Updates to PostCSS 6 (https://github.com/borodean/postcss-assets/issues/70, https://github.com/borodean/postcss-assets/issues/71, https://github.com/borodean/postcss-assets/pull/72).
- Drops nodejs 0.12 support.

## 4.2.0
**Features:**

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
environment:
matrix:
- nodejs_version: '' # is latest stable
- nodejs_version: 6
- nodejs_version: 4
- nodejs_version: 0.12

# Install scripts (runs after repo cloning)
install:
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-assets",
"version": "4.2.0",
"version": "5.0.0",
"description": "PostCSS plugin to manage assets",
"keywords": [
"assets",
Expand Down Expand Up @@ -31,18 +31,18 @@
"test": "eslint --ignore-path .gitignore . && nyc --reporter=text --reporter=html ./node_modules/ava/cli.js"
},
"dependencies": {
"assets": "^2.1.0",
"assets": "^3.0.0",
"bluebird": "^3.5.0",
"postcss": "^5.2.0",
"postcss-functions": "^2.1.0"
"postcss": "^6.0.10",
"postcss-functions": "^3.0.0"
},
"devDependencies": {
"ava": "^0.16.0",
"ava": "^0.22.0",
"coveralls": "^2.11.13",
"eslint": "^2.13.1",
"eslint-config-airbnb-base": "^3.0.1",
"eslint-plugin-import": "^1.7.0",
"nyc": "^8.3.0"
"eslint": "^4.5.0",
"eslint-config-airbnb-base": "^11.3.2",
"eslint-plugin-import": "^2.7.0",
"nyc": "^11.1.0"
},
"engines": {
"node": ">=0.12"
Expand Down
108 changes: 54 additions & 54 deletions test/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@

import fs from 'fs';
import path from 'path';
import plugin from '..';
import postcss from 'postcss';
import test from 'ava';
import plugin from '..';

function process(css, options, postcssOptions) {
return postcss().use(plugin(options)).process(css, postcssOptions);
}

test('resolves urls', (t) =>
test('resolves urls', t =>
process("a { b: resolve('picture.png') }", {
basePath: 'fixtures',
basePath: 'test/fixtures',
baseUrl: 'http://example.com/wp-content/themes',
loadPaths: ['fonts', 'images'],
})
.then((result) => {
t.is(result.css, "a { b: url('http://example.com/wp-content/themes/images/picture.png') }");
}));

test('resolves urls from the current path', (t) =>
test('resolves urls from the current path', t =>
process("a { b: resolve('picture.png') }", {
basePath: 'fixtures',
basePath: 'test/fixtures',
baseUrl: 'http://example.com/wp-content/themes',
}, {
from: path.resolve('fixtures/images/style.css'),
from: path.resolve('test/fixtures/images/style.css'),
})
.then((result) => {
t.is(result.css, "a { b: url('http://example.com/wp-content/themes/images/picture.png') }");
}));

test('resolves relative urls from the current path', (t) =>
test('resolves relative urls from the current path', t =>
process("a { b: resolve('fonts/empty-sans.woff') }", {
basePath: 'fixtures',
basePath: 'test/fixtures',
relative: true,
}, {
from: path.resolve('fixtures/images/style.css'),
from: path.resolve('test/fixtures/images/style.css'),
})
.then((result) => {
t.is(result.css, "a { b: url('../fonts/empty-sans.woff') }");
}));

test('resolves relative urls from the provided path', (t) =>
test('resolves relative urls from the provided path', t =>
process("a { b: resolve('fonts/empty-sans.woff') }", {
basePath: 'fixtures',
basePath: 'test/fixtures',
relative: 'fonts',
})
.then((result) => {
t.is(result.css, "a { b: url('empty-sans.woff') }");
}));

test('busts cache when resolving urls', (t) =>
test('busts cache when resolving urls', t =>
process("a { b: resolve('picture.png') }", {
basePath: 'fixtures',
basePath: 'test/fixtures',
baseUrl: 'http://example.com/wp-content/themes',
cachebuster(resolvedPath) {
return fs.statSync(resolvedPath).size;
Expand All @@ -64,121 +64,121 @@ test('busts cache when resolving urls', (t) =>
t.is(result.css, "a { b: url('http://example.com/wp-content/themes/images/picture.png?3061') }");
}));

test('throws when trying to resolve a non-existing file', (t) =>
test('throws when trying to resolve a non-existing file', t =>
process("a { b: resolve('non-existing.gif') }")
.then(t.fail, (err) => {
t.true(err instanceof Error);
t.is(err.message, 'Asset not found or unreadable: non-existing.gif');
}));

test('inlines data', (t) =>
test('inlines data', t =>
process("a { b: inline('picture.png') }", {
basePath: 'fixtures',
basePath: 'test/fixtures',
loadPaths: ['fonts', 'images'],
})
.then((result) => {
t.is(result.css.slice(0, 32), "a { b: url('data:image/png;base6");
t.is(result.css.slice(-32), "ufaJraBKlQAAAABJRU5ErkJggg==') }");
}));

test('inlines svg unencoded', (t) =>
test('inlines svg unencoded', t =>
process("a { b: inline('vector.svg') }", {
basePath: 'fixtures',
basePath: 'test/fixtures',
loadPaths: ['fonts', 'images'],
})
.then((result) => {
t.is(result.css.slice(0, 32), "a { b: url('data:image/svg+xml;c");
t.is(result.css.slice(-32), "z%22%2F%3E%0D%0A%3C%2Fsvg%3E') }");
}));

test('throws when trying to inline a non-existing file', (t) =>
test('throws when trying to inline a non-existing file', t =>
process("a { b: inline('non-existing.gif') }")
.then(t.fail, (err) => {
t.true(err instanceof Error);
t.is(err.message, 'Asset not found or unreadable: non-existing.gif');
}));

test('measures images', (t) =>
test('measures images', t =>
process("a { " +
"b: size('vector.svg'); " +
"c: width('picture.png'); " +
"d: height('picture.png'); " +
"}", {
basePath: 'fixtures',
loadPaths: ['fonts', 'images'],
})
.then((result) => {
t.is(result.css, "a { b: 160px 120px; c: 200px; d: 57px; }");
}));
basePath: 'test/fixtures',
loadPaths: ['fonts', 'images'],
})
.then((result) => {
t.is(result.css, "a { b: 160px 120px; c: 200px; d: 57px; }");
}));

test('measures images with set cache dimensions', (t) => {
const options = {
basePath: 'fixtures',
basePath: 'test/fixtures',
loadPaths: ['fonts', 'images'],
cache: true,
};
process("a { " +
return process("a { " +
"b: size('vector.svg'); " +
"c: width('picture.png'); " +
"d: height('picture.png'); " +
"}", options)
.then((result1) => {
t.is(result1.css, "a { b: 160px 120px; c: 200px; d: 57px; }");
.then((firstResult) => {
t.is(firstResult.css, "a { b: 160px 120px; c: 200px; d: 57px; }");

process("a { " +
return process("a { " +
"b: width('vector.svg'); " +
"c: size('picture.png'); " +
"}", options)
.then((result2) => {
t.is(result2.css, "a { b: 160px; c: 200px 57px; }");
});
});
.then((secondResult) => {
t.is(secondResult.css, "a { b: 160px; c: 200px 57px; }");
});
});
});

test('measures images with density provided', (t) =>
test('measures images with density provided', t =>
process("a { " +
"b: size('vector.svg', 2); " +
"c: width('picture.png', 2); " +
"d: height('picture.png', 2); " +
"}", {
basePath: 'fixtures',
loadPaths: ['fonts', 'images'],
})
.then((result) => {
t.is(result.css, "a { b: 80px 60px; c: 100px; d: 28.5px; }");
}));

test('throws when trying to measure a non-existing image', (t) =>
basePath: 'test/fixtures',
loadPaths: ['fonts', 'images'],
})
.then((result) => {
t.is(result.css, "a { b: 80px 60px; c: 100px; d: 28.5px; }");
}));

test('throws when trying to measure a non-existing image', t =>
process("a { b: size('non-existing.gif') }")
.then(t.fail, (err) => {
t.true(err instanceof Error);
t.is(err.message, 'Asset not found or unreadable: non-existing.gif');
}));

test('throws when trying to measure an unsupported file', (t) =>
process("a { b: size('fixtures/fonts/empty-sans.woff') }")
test('throws when trying to measure an unsupported file', t =>
process("a { b: size('test/fixtures/fonts/empty-sans.woff') }")
.then(t.fail, (err) => {
const absolutePath = path.resolve('fixtures/fonts/empty-sans.woff');
const absolutePath = path.resolve('test/fixtures/fonts/empty-sans.woff');
t.true(err instanceof Error);
t.is(err.message, `File type not supported: ${absolutePath}`);
}));

test('throws when trying to measure an invalid file', (t) =>
process("a { b: size('fixtures/images/invalid.jpg') }")
test('throws when trying to measure an invalid file', t =>
process("a { b: size('test/fixtures/images/invalid.jpg') }")
.then(t.fail, (err) => {
const absolutePath = path.resolve('fixtures/images/invalid.jpg');
const absolutePath = path.resolve('test/fixtures/images/invalid.jpg');
t.true(err instanceof Error);
t.is(err.message, `Invalid JPEG file: ${absolutePath}`);
}));

test('handles quotes and escaped characters', (t) =>
test('handles quotes and escaped characters', t =>
process("a {" +
"b: resolve(picture.png);" +
"c: resolve('picture.png');" +
'd: resolve("picture.png");' +
'e: resolve("\\70 icture.png");' +
"}", {
basePath: 'fixtures/images',
basePath: 'test/fixtures/images',
})
.then((result) => {
t.is(result.css, "a {" +
Expand All @@ -189,8 +189,8 @@ test('handles quotes and escaped characters', (t) =>
"}");
}));

test('allows usage inside media queries', (t) =>
process("@media a and (b: height('fixtures/images/picture.png')) { c { d: e }}")
test('allows usage inside media queries', t =>
process("@media a and (b: height('test/fixtures/images/picture.png')) { c { d: e }}")
.then((result) => {
t.is(result.css, "@media a and (b: 57px) { c { d: e }}");
}));
2 changes: 1 addition & 1 deletion test/quote.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint quotes: 0 */

import quote from '../lib/quote';
import test from 'ava';
import quote from '../lib/quote';

test('adds quotes', (t) => {
t.is(quote("foo"), "'foo'");
Expand Down

0 comments on commit 16bbee9

Please sign in to comment.