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/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
borodean committed Jul 15, 2017
2 parents 5e739f6 + e870649 commit 384ee77
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "airbnb/legacy",
"extends": "airbnb-base/legacy",
"root": true
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.sublime-*
.nyc_output
coverage
node_modules
npm-debug.log
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.sublime-*
.eslintrc
.gitignore
.npmignore
.nyc_output
.travis.yml
appveyor.yml
coverage
media
npm-debug.log
test
159 changes: 159 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# Change log

## 4.2.0
**Features:**

* Add `cache` option to cache resolved dimensions (https://github.com/borodean/postcss-assets/pull/73).

## 4.1.0
**Features:**

* `relative` option supports what `relativeTo` option did in 3.x: if a string is passed, paths are generated relatively to a path in that string. A behavior of relating to input files by passing `true` is kept untouched.

**Under the hood:**

* Code updated to match [Airbnb code style](https://github.com/airbnb/javascript).
* Tests converted to ES6 syntax.

## 4.0.1
**Bugfixes**
- Works fine with no options provided (https://github.com/assetsjs/postcss-assets/issues/45).

## 4.0.0
**Breaking**
- Removes `relativeTo` option, introduces `relative` one.

There is no need to specify a particular file to relate to anymore - set `relative` to `true` and Assets would resolve URLs relatively to the current CSS file.

This solves the issue when you have stylesheets in different folders and want relative paths — previously there was an option to relate only to a single directory.

(https://github.com/assetsjs/postcss-assets/issues/42)

**Features**
- Load paths now accept globs:

```js
var options = { loadPaths: ['images', 'assets/**/img'] };
```

(https://github.com/assetsjs/postcss-assets/issues/40)

- Load paths now also accept single strings:

```js
var options = { loadPaths: 'assets/**/img' };
```

**Bugfixes**
- Really fixes the SVG rendering on Internet Explorer.
- SCSS flags are preserved (https://github.com/assetsjs/postcss-assets/issues/43).
- No more funky file names in the repo to make Windows archiver happy (https://github.com/assetsjs/postcss-assets/issues/35).
- Allows numbers to be returned from the cachebuster function.

**Under the hood**
- Coverage hits 100%.
- Automated tests against the latest stable nodejs, v0.12 and v4.
- Builds are automatically tested on Windows by [AppVeyor](https://ci.appveyor.com/project/borodean/postcss-assets).
- Switches tests from Mocha to [AVA](https://github.com/sindresorhus/ava).
- Uses [Calipers](https://github.com/calipersjs/calipers) for image measurement instead of image-size.
- Replaces custom function mapper with [postcss-functions](https://github.com/andyjansson/postcss-functions).
- Extracts assets processing logic to the [Assets](https://github.com/assetsjs/assets) module.
- Cleans up dependencies.

## 3.0.3
**Bugfixes**
- no longer uses private `image-size` fork, so properly installs on Windows (https://github.com/borodean/postcss-assets/pull/30, https://github.com/borodean/postcss-assets/issues/32);
- properly calculates dimensions of SVGs with percentage values of `width`/`height` attributes (https://github.com/borodean/postcss-assets/issues/33).

## 3.0.2
**Bugfixes**
* IE understands generated SVG (https://github.com/borodean/postcss-assets/issues/24).

## 3.0.1
**Bugfixes**
- Preserves Microsoft filters (https://github.com/borodean/postcss-assets/issues/27).

**Under the hood**
- Uses ESLint instead of JSHint/JSCS.

## 3.0.0
**API updates**
* better PostCSS 5.0 API conformance (https://github.com/borodean/postcss-assets/issues/25).

## 2.1.4
Since private `image-size` fork was removed, releases 2.1.0—3.0.2 has stopped working. While 3.0.3 release fixes this for the 3.0.x versions, this release is fixing the same for the 2.1.x.

**Bugfixes**
- no longer uses private `image-size` fork (https://github.com/borodean/postcss-assets/issues/37)

## 2.1.3
**Bugfixes**
- better PostCSS plugin API conformance (https://github.com/borodean/postcss-assets/pull/21). This allows plugin to be used with Webpack.

## 2.1.2
**Under the hood**
* [PostCSS Plugin Guidelines](https://github.com/postcss/postcss/blob/master/docs/guidelines/plugin.md) conformance (https://github.com/borodean/postcss-assets/issues/20);
* continious integration tests on both Node.js and io.js;
* shows coverage statistics on the repository page.

## 2.1.1
**Bugfixes**
- fix path separator handling on Windows (https://github.com/borodean/postcss-assets/issues/19).

**Under the hood**
- covers 99% of the code;
- explains code with comments.

## 2.1.0
**API updates**
- extends cachebuster to support modifying the filename (https://github.com/borodean/postcss-assets/pull/17, [docs](https://github.com/borodean/postcss-assets#cachebuster)).

**Bugfixes**
- uses [forked version of image-size](https://github.com/borodean/image-size) to support viewbox-only svgs;
- properly encodes some tricky SVG files (https://github.com/borodean/postcss-assets/pull/18).

**Under the hood**
- uses [Gulp](http://gulpjs.com/) for development routines;
- validates code style with [JSHint](http://jshint.com/) and [JSCS](http://jscs.info/).

## 2.0.0
**API updates**
- Renames `url()` function to `resolve()` https://github.com/borodean/postcss-assets/issues/13
- Resolves assets relative to the source file https://github.com/borodean/postcss-assets/issues/7
- Starts throwing errors instead of warnings https://github.com/borodean/postcss-assets/issues/8
- Fixes a bug when complex URL declarations were crashing Gonzales https://github.com/borodean/postcss-assets/issues/15

**Under the hood**
- Tests with Mocha/Chai instead of Tape https://github.com/borodean/postcss-assets/issues/12
- Updates dependencies upto the latest versions

## 1.1.4
Allows to use common PostCSS plugin API (https://github.com/borodean/postcss-assets/issues/6)
Fixes quotes when inlining SVG (https://github.com/borodean/postcss-assets/pull/14)

## 1.1.3
Base64-encodes with Buffer.

## 1.1.2
Cachebuster recognizes resolved paths.

## 1.1.1
Uses PostCSS 4.0.

## 1.1.0
Introduces [cachebuster](https://github.com/borodean/postcss-assets#cachebuster).

## 1.0.0
* [`width`, `height` and `size` functions][1] are introduced to measure image dimesions with high density pixels support;
* [`inline` function][2] introduced to inline files;
* `url` function automagic is removed;
* `inline.maxSize` option is removed;
* all modifiers are removed.
[1]: https://github.com/borodean/postcss-assets/tree/3168ab2b07cf537240ecc20e0eb7688434987614#image-dimensions
[2]: https://github.com/borodean/postcss-assets/tree/3168ab2b07cf537240ecc20e0eb7688434987614#inlining-files

## 0.9.1
Inlines SVG as UTF-8, not Base64.

## 0.9.0
Hello, world.
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<h1 align="center">
<img src="https://rawgit.com/assetsjs/assets/develop/media/logo.svg" alt="assets">
</h1>
# ![postcss-assets](https://rawgit.com/assetsjs/postcss-assets/develop/media/postcss-assets.svg)

PostCSS Assets is an asset manager for CSS. It isolates stylesheets from environmental changes, gets image sizes and inlines files.

Expand Down Expand Up @@ -237,10 +235,11 @@ SVG files would be inlined unencoded, because [then they benefit in size](http:/
Full list of options
--------------------

| Option | Description | Default |
|:-----------------|:----------------------------------------------------------------------------------|:--------|
| `basePath` | Root directory of the project. | `.` |
| `baseUrl` | URL of the project when running the web server. | `/` |
| `cachebuster` | If cache should be busted. Pass a function to define custom busting strategy. | `false` |
| `loadPaths` | Specific directories to look for the files. | `[]` |
| `relative` | Directory to relate to when resolving URLs. When `true`, relates to the input file. When `false`, disables relative URLs. | `false` |
| Option | Description | Default |
|:--------------|:----------------------------------------------------------------------------------|:--------|
| `basePath` | Root directory of the project. | `.` |
| `baseUrl` | URL of the project when running the web server. | `/` |
| `cachebuster` | If cache should be busted. Pass a function to define custom busting strategy. | `false` |
| `loadPaths` | Specific directories to look for the files. | `[]` |
| `relative` | Directory to relate to when resolving URLs. When `true`, relates to the input file. When `false`, disables relative URLs. | `false` |
| `cache` | When `true`, if the input file not been modifed, use the results before cached. | `false` |
6 changes: 6 additions & 0 deletions lib/__utils__/generateFileUniqueId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var fs = require('fs');

module.exports = function generateFileUniqueId(resolvedPath) {
var mtime = fs.statSync(resolvedPath).mtime;
return mtime.getTime().toString(16);
};
36 changes: 31 additions & 5 deletions index.js → lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ var Assets = require('assets');
var dirname = require('path').dirname;
var functions = require('postcss-functions');
var postcss = require('postcss');
var quote = require('./lib/quote');
var unescapeCss = require('./lib/unescape-css');
var unquote = require('./lib/unquote');
var quote = require('./quote');
var unescapeCss = require('./unescape-css');
var unquote = require('./unquote');
var util = require('util');
var Promise = require('bluebird');
var generateFileUniqueId = require('./__utils__/generateFileUniqueId');

var cachedDimensions = {};

function formatUrl(url) {
return util.format('url(%s)', quote(url));
Expand Down Expand Up @@ -34,8 +38,29 @@ function plugin(options) {
resolver = new Assets(options);

function measure(path, density) {
return resolver.size(path)
.then(function correctDensity(size) {
var cached = null;
var id = '';
var getSizePromise = null;

return resolver.path(path).then(function measureSize(resolvedPath) {
if (params.cache) {
cached = cachedDimensions[resolvedPath];
id = generateFileUniqueId(resolvedPath);
}

if (cached && id && cached[id]) {
getSizePromise = Promise.resolve(cached[id]);
} else {
getSizePromise = resolver.size(path).then(function cacheSize(size) {
if (params.cache && id) {
cachedDimensions[resolvedPath] = {};
cachedDimensions[resolvedPath][id] = size;
}
return size;
});
}

return getSizePromise.then(function correctDensity(size) {
if (density !== undefined) {
return {
width: Number((size.width / density).toFixed(4)),
Expand All @@ -44,6 +69,7 @@ function plugin(options) {
}
return size;
});
});
}

return postcss()
Expand Down
1 change: 1 addition & 0 deletions media/postcss-assets.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 20 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-assets",
"version": "4.1.0",
"version": "4.2.0",
"description": "PostCSS plugin to manage assets",
"keywords": [
"assets",
Expand All @@ -13,29 +13,38 @@
"size",
"url"
],
"bugs": "https://github.com/assetsjs/assets/issues",
"license": "MIT",
"author": "Vadym Borodin <[email protected]> (http://borodean.com)",
"contributors": [
"Alexey Plutalov <[email protected]> (https://twitter.com/demiazz)",
"Andrey Sitnik <[email protected]> (http://sitnik.ru)",
"Dave Clayton <[email protected]> (http://www.dave78.com)",
"Alexey Plutalov (https://github.com/demiazz)",
"Andrey Sitnik (https://github.com/ai)",
"Dave Clayton (https://github.com/davedx)",
"Ivan Vlasenko (https://github.com/avanes)",
"Pascal Duez (http://pascalduez.me)"
"Liucw (https://github.com/booxood)",
"Pascal Duez (https://github.com/pascalduez)"
],
"main": "./lib",
"repository": "assetsjs/postcss-assets",
"scripts": {
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"test": "eslint --ignore-path .gitignore . && nyc --reporter=text --reporter=html ./node_modules/ava/cli.js"
},
"dependencies": {
"assets": "^2.0.0",
"postcss": "^5.0.12",
"assets": "^2.1.0",
"bluebird": "^3.5.0",
"postcss": "^5.2.0",
"postcss-functions": "^2.1.0"
},
"devDependencies": {
"ava": "^0.13.0",
"eslint": "^2.5.3",
"eslint-config-airbnb": "^6.2.0",
"nyc": "^6.1.1"
"ava": "^0.16.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"
},
"engines": {
"node": ">=0.12"
}
}
5 changes: 4 additions & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "airbnb/base"
"extends": "airbnb-base",
"rules": {
"import/no-extraneous-dependencies": "off"
}
}
Loading

0 comments on commit 384ee77

Please sign in to comment.