Skip to content

Commit 043d123

Browse files
committed
Simplify Bluebird usage
1 parent 6a2ae5b commit 043d123

File tree

9 files changed

+31
-56
lines changed

9 files changed

+31
-56
lines changed

src/core.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import debug from 'debug';
66
import RasterFactory from './factories/raster';
77
import VectorFactory from './factories/vector';
88

9-
/**
10-
* Wrap with promises.
11-
*/
12-
Promise.promisifyAll(fs);
13-
149
/**
1510
* Plugin constants.
1611
*/
@@ -86,7 +81,7 @@ export function prepareFilterBy(opts, result) {
8681

8782
// Filter non existing images
8883
opts.filterBy.unshift(image => {
89-
return fs.statAsync(image.path)
84+
return fs.stat(image.path)
9085
.catch(() => {
9186
const message = `Skip ${image.url} because doesn't exist.`;
9287

@@ -363,7 +358,7 @@ export function saveSpritesheets(opts, images, spritesheets) {
363358

364359
spritesheet.path = spritesheet.path.replace(/\\/g, '/');
365360

366-
return fs.outputFileAsync(spritesheet.path, spritesheet.image);
361+
return fs.outputFile(spritesheet.path, spritesheet.image);
367362
});
368363
}).then(spritesheets => {
369364
return [opts, images, spritesheets];

test/04-apply-filter-by.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import test from 'ava';
22
import postcss from 'postcss';
3-
import Promise from 'bluebird';
43
import _ from 'lodash';
54
import { defaults, prepareFilterBy, extractImages, applyFilterBy } from '../lib/core';
65

test/05-apply-group-by.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import test from 'ava';
22
import postcss from 'postcss';
3-
import Promise from 'bluebird';
43
import _ from 'lodash';
54
import { defaults, prepareGroupBy, extractImages, applyGroupBy } from '../lib/core';
65

test/07-run-spritesmith.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import test from 'ava';
22
import postcss from 'postcss';
33
import _ from 'lodash';
4-
import Promise from 'bluebird';
5-
import fs from 'fs';
4+
import fs from 'fs-extra';
65
import { defaults, extractImages, prepareGroupBy, applyGroupBy, runSpritesmith } from '../lib/core';
76

8-
const readFileAsync = Promise.promisify(fs.readFile);
9-
107
test.beforeEach((t) => {
118
t.context.opts = _.merge({ logger() {} }, defaults);
129
});
1310

1411
test('should generate spritesheets', async (t) => {
15-
const cssContents = await readFileAsync('./test/fixtures/basic/style.css');
12+
const cssContents = await fs.readFile('./test/fixtures/basic/style.css');
1613
const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' });
1714
let images, spritesheets, opts;
1815

@@ -24,7 +21,7 @@ test('should generate spritesheets', async (t) => {
2421
});
2522

2623
test('should generate SVG spritesheets', async (t) => {
27-
const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css');
24+
const cssContents = await fs.readFile('./test/fixtures/svg-basic/style.css');
2825
const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' });
2926
let images, spritesheets, opts;
3027

@@ -38,7 +35,7 @@ test('should generate SVG spritesheets', async (t) => {
3835
});
3936

4037
test('should generate spritesheets by groups', async (t) => {
41-
const cssContents = await readFileAsync('./test/fixtures/retina/style.css');
38+
const cssContents = await fs.readFile('./test/fixtures/retina/style.css');
4239
const ast = postcss.parse(cssContents, { from: './test/fixtures/retina/style.css' });
4340
let images, spritesheets, opts;
4441

test/08-save-spritesheets.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import test from 'ava';
22
import postcss from 'postcss';
33
import _ from 'lodash';
4-
import Promise from 'bluebird';
54
import fs from 'fs-extra';
65
import path from 'path';
76
import {
@@ -13,14 +12,12 @@ import {
1312
saveSpritesheets
1413
} from '../lib/core';
1514

16-
const readFileAsync = Promise.promisify(fs.readFile);
17-
1815
test.beforeEach((t) => {
1916
t.context.opts = _.merge({ logger() {} }, defaults);
2017
});
2118

2219
test('should save spritesheets', async (t) => {
23-
const cssContents = await readFileAsync('./test/fixtures/basic/style.css');
20+
const cssContents = await fs.readFile('./test/fixtures/basic/style.css');
2421
const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' });
2522
let images, spritesheets, opts;
2623

@@ -31,11 +28,11 @@ test('should save spritesheets', async (t) => {
3128
[ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets);
3229

3330
t.deepEqual(spritesheets[0].path, 'test/build/basic/sprite.png');
34-
t.truthy(fs.statAsync('./test/build/basic/sprite.png'));
31+
t.truthy(fs.stat('./test/build/basic/sprite.png'));
3532
});
3633

3734
test('should save SVG spritesheets', async (t) => {
38-
const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css');
35+
const cssContents = await fs.readFile('./test/fixtures/svg-basic/style.css');
3936
const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' });
4037
let images, spritesheets, opts;
4138

@@ -48,11 +45,11 @@ test('should save SVG spritesheets', async (t) => {
4845
[ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets);
4946

5047
t.deepEqual(spritesheets[0].path, 'test/build/svg-basic/sprite.svg');
51-
t.truthy(fs.statAsync('./test/build/svg-basic/sprite.svg'));
48+
t.truthy(fs.stat('./test/build/svg-basic/sprite.svg'));
5249
});
5350

5451
test('should save spritesheets by groups', async (t) => {
55-
const cssContents = await readFileAsync('./test/fixtures/retina/style.css');
52+
const cssContents = await fs.readFile('./test/fixtures/retina/style.css');
5653
const ast = postcss.parse(cssContents, { from: './test/fixtures/retina/style.css' });
5754
let images, spritesheets, opts;
5855

@@ -68,12 +65,12 @@ test('should save spritesheets by groups', async (t) => {
6865

6966
t.deepEqual(spritesheets[0].path, 'test/build/retina/sprite.png');
7067
t.deepEqual(spritesheets[1].path, 'test/build/retina/sprite.@2x.png');
71-
t.truthy(fs.statAsync('./test/build/retina/sprite.png'));
72-
t.truthy(fs.statAsync('./test/build/retina/sprite.@2x.png'));
68+
t.truthy(fs.stat('./test/build/retina/sprite.png'));
69+
t.truthy(fs.stat('./test/build/retina/sprite.@2x.png'));
7370
});
7471

7572
test('should use path provided by book', async (t) => {
76-
const cssContents = await readFileAsync('./test/fixtures/basic/style.css');
73+
const cssContents = await fs.readFile('./test/fixtures/basic/style.css');
7774
const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' });
7875
let images, spritesheets, opts;
7976

@@ -87,11 +84,11 @@ test('should use path provided by book', async (t) => {
8784
[ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets);
8885

8986
t.deepEqual(spritesheets[0].path, 'test/build/on-save-hook/custom-name.png');
90-
t.truthy(fs.statAsync('./test/build/on-save-hook/custom-name.png'));
87+
t.truthy(fs.stat('./test/build/on-save-hook/custom-name.png'));
9188
});
9289

9390
test('should throw error if path is empty', async (t) => {
94-
const cssContents = await readFileAsync('./test/fixtures/basic/style.css');
91+
const cssContents = await fs.readFile('./test/fixtures/basic/style.css');
9592
const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' });
9693
let images, spritesheets, opts;
9794

@@ -107,7 +104,7 @@ test('should throw error if path is empty', async (t) => {
107104
});
108105

109106
test('should use Promise result provided by book', async (t) => {
110-
const cssContents = await readFileAsync('./test/fixtures/basic/style.css');
107+
const cssContents = await fs.readFile('./test/fixtures/basic/style.css');
111108
const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' });
112109
let images, spritesheets, opts;
113110

@@ -121,5 +118,5 @@ test('should use Promise result provided by book', async (t) => {
121118
[ opts, images, spritesheets ] = await saveSpritesheets(t.context.opts, images, spritesheets);
122119

123120
t.deepEqual(spritesheets[0].path, 'test/build/on-save-hook/custom-name.png');
124-
t.truthy(fs.statAsync('./test/build/on-save-hook/custom-name.png'));
121+
t.truthy(fs.stat('./test/build/on-save-hook/custom-name.png'));
125122
});

test/09-map-spritesheet-props.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import test from 'ava';
22
import postcss from 'postcss';
33
import _ from 'lodash';
4-
import Promise from 'bluebird';
54
import fs from 'fs-extra';
65
import {
76
defaults,
@@ -13,14 +12,12 @@ import {
1312
applyGroupBy
1413
} from '../lib/core';
1514

16-
const readFileAsync = Promise.promisify(fs.readFile);
17-
1815
test.beforeEach((t) => {
1916
t.context.opts = _.merge({ logger() {} }, defaults);
2017
});
2118

2219
test('should add coords & spritePath to every image', async (t) => {
23-
const cssContents = await readFileAsync('./test/fixtures/basic/style.css');
20+
const cssContents = await fs.readFile('./test/fixtures/basic/style.css');
2421
const ast = postcss.parse(cssContents, { from: './test/fixtures/basic/style.css' });
2522
let images, spritesheets, opts;
2623

@@ -36,7 +33,7 @@ test('should add coords & spritePath to every image', async (t) => {
3633
});
3734

3835
test('should add coords & spritePath to every SVG image', async (t) => {
39-
const cssContents = await readFileAsync('./test/fixtures/svg-basic/style.css');
36+
const cssContents = await fs.readFile('./test/fixtures/svg-basic/style.css');
4037
const ast = postcss.parse(cssContents, { from: './test/fixtures/svg-basic/style.css' });
4138
let images, spritesheets, opts;
4239

test/10-update-references.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import test from 'ava';
22
import postcss from 'postcss';
33
import _ from 'lodash';
4-
import Promise from 'bluebird';
54
import fs from 'fs-extra';
65
import {
76
defaults,
@@ -14,15 +13,13 @@ import {
1413
updateRule
1514
} from '../lib/core';
1615

17-
const readFileAsync = Promise.promisify(fs.readFile);
18-
1916
test.beforeEach((t) => {
2017
t.context.opts = _.merge({ logger() {} }, defaults);
2118
});
2219

2320
test('should update CSS declarations', async (t) => {
24-
const input = await readFileAsync('./test/fixtures/basic/style.css');
25-
const expected = await readFileAsync('./test/expectations/basic/style.css', 'utf8');
21+
const input = await fs.readFile('./test/fixtures/basic/style.css');
22+
const expected = await fs.readFile('./test/expectations/basic/style.css', 'utf8');
2623
const ast = postcss.parse(input, { from: './test/fixtures/basic/style.css' });
2724
let images, spritesheets, opts, root;
2825

@@ -40,8 +37,8 @@ test('should update CSS declarations', async (t) => {
4037
});
4138

4239
test('should update CSS declarations with relative paths', async (t) => {
43-
const input = await readFileAsync('./test/fixtures/relative/style.css');
44-
const expected = await readFileAsync('./test/expectations/relative/style.css', 'utf8');
40+
const input = await fs.readFile('./test/fixtures/relative/style.css');
41+
const expected = await fs.readFile('./test/expectations/relative/style.css', 'utf8');
4542
const ast = postcss.parse(input, { from: './test/fixtures/relative/style.css' });
4643
let images, spritesheets, opts, root;
4744

@@ -58,8 +55,8 @@ test('should update CSS declarations with relative paths', async (t) => {
5855
});
5956

6057
test('should use function provided by onUpdateRule hook', async (t) => {
61-
const input = await readFileAsync('./test/fixtures/basic/style.css');
62-
const expected = await readFileAsync('./test/expectations/basic-on-update-rule-hook/style.css', 'utf8');
58+
const input = await fs.readFile('./test/fixtures/basic/style.css');
59+
const expected = await fs.readFile('./test/expectations/basic-on-update-rule-hook/style.css', 'utf8');
6360
const ast = postcss.parse(input, { from: './test/fixtures/basic/style.css' });
6461
let images, spritesheets, opts, root;
6562

test/11-e2e.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import test from 'ava';
22
import postcss from 'postcss';
33
import fs from 'fs-extra';
4-
import Promise from 'bluebird';
54
import path from 'path';
65
import plugin from '../lib';
76

8-
const readFileAsync = Promise.promisify(fs.readFile);
9-
107
async function run(inputPath, expectedPath, opts, t) {
11-
const input = await readFileAsync(inputPath, 'utf8');
12-
const expected = await readFileAsync(expectedPath, 'utf8');
8+
const input = await fs.readFile(inputPath, 'utf8');
9+
const expected = await fs.readFile(expectedPath, 'utf8');
1310
const processor = postcss([plugin(opts)]);
1411
const result = await processor.process(input, { from: inputPath });
1512

@@ -23,7 +20,7 @@ test('throws error', async (t) => {
2320
spritePath: './test/build/example-error/',
2421
};
2522

26-
const input = await readFileAsync(inputPath, 'utf8');
23+
const input = await fs.readFile(inputPath, 'utf8');
2724
const processor = postcss([plugin(opts)]);
2825

2926
return t.throwsAsync(() => processor.process(input, { from: inputPath }));

test/12-examples.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import test from 'ava';
22
import postcss from 'postcss';
33
import fs from 'fs-extra';
4-
import Promise from 'bluebird';
54
import path from 'path';
65
import plugin from '../lib';
76
import { updateRule } from '../lib/core';
87

9-
const readFileAsync = Promise.promisify(fs.readFile);
10-
118
async function run(inputPath, expectedPath, opts, t) {
12-
const input = await readFileAsync(inputPath, 'utf8');
13-
const expected = await readFileAsync(expectedPath, 'utf8');
9+
const input = await fs.readFile(inputPath, 'utf8');
10+
const expected = await fs.readFile(expectedPath, 'utf8');
1411
const processor = postcss([plugin(opts)]);
1512
const result = await processor.process(input, { from: inputPath });
1613

0 commit comments

Comments
 (0)