Skip to content

Commit f1eb869

Browse files
committed
Require Node.js 8 and Gulp 4
1 parent 24e39ec commit f1eb869

File tree

6 files changed

+116
-110
lines changed

6 files changed

+116
-110
lines changed

.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: node_js
22
node_js:
3+
- '12'
4+
- '10'
35
- '8'
4-
- '6'
5-
- '4'

index.js

+27-20
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,47 @@ const prettyBytes = require('pretty-bytes');
77
const StreamCounter = require('stream-counter');
88
const gzipSize = require('gzip-size');
99

10-
module.exports = opts => {
11-
opts = Object.assign({
10+
module.exports = options => {
11+
options = {
1212
pretty: true,
13-
showTotal: true
14-
}, opts);
13+
showTotal: true,
14+
...options
15+
};
1516

1617
let totalSize = 0;
1718
let fileCount = 0;
1819

1920
function log(what, size) {
20-
let title = opts.title;
21+
let {title} = options;
2122
title = title ? chalk.cyan(title) + ' ' : '';
22-
size = opts.pretty ? prettyBytes(size) : (size + ' B');
23-
fancyLog(title + what + ' ' + chalk.magenta(size) + (opts.gzip ? chalk.gray(' (gzipped)') : ''));
23+
size = options.pretty ? prettyBytes(size) : (size + ' B');
24+
fancyLog(title + what + ' ' + chalk.magenta(size) + (options.gzip ? chalk.gray(' (gzipped)') : ''));
2425
}
2526

26-
return through.obj((file, enc, cb) => {
27+
return through.obj((file, encoding, callback) => {
2728
if (file.isNull()) {
28-
cb(null, file);
29+
callback(null, file);
2930
return;
3031
}
3132

32-
const finish = (err, size) => {
33-
if (err) {
34-
cb(new PluginError('gulp-size', err));
33+
const finish = (error, size) => {
34+
if (error) {
35+
callback(new PluginError('gulp-size', error));
3536
return;
3637
}
3738

3839
totalSize += size;
3940

40-
if (opts.showFiles === true && size > 0) {
41+
if (options.showFiles === true && size > 0) {
4142
log(chalk.blue(file.relative), size);
4243
}
4344

4445
fileCount++;
45-
cb(null, file);
46+
callback(null, file);
4647
};
4748

4849
if (file.isStream()) {
49-
if (opts.gzip) {
50+
if (options.gzip) {
5051
file.contents.pipe(gzipSize.stream())
5152
.on('error', finish)
5253
.on('end', function () {
@@ -63,19 +64,25 @@ module.exports = opts => {
6364
return;
6465
}
6566

66-
if (opts.gzip) {
67-
gzipSize(file.contents).then(size => finish(null, size)).catch(finish);
67+
if (options.gzip) {
68+
(async () => {
69+
try {
70+
finish(null, await gzipSize(file.contents));
71+
} catch (error) {
72+
finish(error);
73+
}
74+
})();
6875
} else {
6976
finish(null, file.contents.length);
7077
}
71-
}, function (cb) {
78+
}, function (callback) {
7279
this.size = totalSize;
7380
this.prettySize = prettyBytes(totalSize);
7481

75-
if (!(fileCount === 1 && opts.showFiles) && totalSize > 0 && fileCount > 0 && opts.showTotal) {
82+
if (!(fileCount === 1 && options.showFiles) && totalSize > 0 && fileCount > 0 && options.showTotal) {
7683
log(chalk.green('all files'), totalSize);
7784
}
7885

79-
cb();
86+
callback();
8087
});
8188
};

package.json

+53-50
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
11
{
2-
"name": "gulp-size",
3-
"version": "3.0.0",
4-
"description": "Display the size of your project",
5-
"license": "MIT",
6-
"repository": "sindresorhus/gulp-size",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11-
},
12-
"engines": {
13-
"node": ">=4"
14-
},
15-
"scripts": {
16-
"test": "xo && mocha"
17-
},
18-
"files": [
19-
"index.js"
20-
],
21-
"keywords": [
22-
"gulpplugin",
23-
"filesize",
24-
"file",
25-
"size",
26-
"log",
27-
"measure",
28-
"inspect",
29-
"debug",
30-
"gzip"
31-
],
32-
"dependencies": {
33-
"chalk": "^2.3.0",
34-
"fancy-log": "^1.3.2",
35-
"gzip-size": "^4.1.0",
36-
"plugin-error": "^0.1.2",
37-
"pretty-bytes": "^4.0.2",
38-
"stream-counter": "^1.0.0",
39-
"through2": "^2.0.0"
40-
},
41-
"devDependencies": {
42-
"mocha": "*",
43-
"vinyl": "^2.1.0",
44-
"xo": "*"
45-
},
46-
"xo": {
47-
"env": [
48-
"node",
49-
"mocha"
50-
]
51-
}
2+
"name": "gulp-size",
3+
"version": "3.0.0",
4+
"description": "Display the size of your project",
5+
"license": "MIT",
6+
"repository": "sindresorhus/gulp-size",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "[email protected]",
10+
"url": "sindresorhus.com"
11+
},
12+
"engines": {
13+
"node": ">=8"
14+
},
15+
"scripts": {
16+
"test": "xo && mocha"
17+
},
18+
"files": [
19+
"index.js"
20+
],
21+
"keywords": [
22+
"gulpplugin",
23+
"filesize",
24+
"file",
25+
"size",
26+
"log",
27+
"measure",
28+
"inspect",
29+
"debug",
30+
"gzip"
31+
],
32+
"dependencies": {
33+
"chalk": "^2.3.0",
34+
"fancy-log": "^1.3.2",
35+
"gzip-size": "^5.1.1",
36+
"plugin-error": "^1.0.1",
37+
"pretty-bytes": "^5.3.0",
38+
"stream-counter": "^1.0.0",
39+
"through2": "^3.0.1"
40+
},
41+
"devDependencies": {
42+
"mocha": "^6.2.0",
43+
"vinyl": "^2.1.0",
44+
"xo": "^0.24.0"
45+
},
46+
"peerDependencies": {
47+
"gulp": ">=4"
48+
},
49+
"xo": {
50+
"env": [
51+
"node",
52+
"mocha"
53+
]
54+
}
5255
}

readme.md

+6-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $ npm install --save-dev gulp-size
2020
const gulp = require('gulp');
2121
const size = require('gulp-size');
2222

23-
gulp.task('default', () =>
23+
exports.default = () => (
2424
gulp.src('fixture.js')
2525
.pipe(size())
2626
.pipe(gulp.dest('dist'))
@@ -30,10 +30,12 @@ gulp.task('default', () =>
3030

3131
## API
3232

33-
### size([options])
33+
### size(options?)
3434

3535
#### options
3636

37+
Type: `object`
38+
3739
##### title
3840

3941
Type: `string`<br>
@@ -90,7 +92,7 @@ const gulp = require('gulp');
9092
const size = require('gulp-size');
9193
const notify = require('gulp-notify');
9294

93-
gulp.task('default', () => {
95+
exports.default = () => {
9496
const s = size();
9597

9698
return gulp.src('fixture.js')
@@ -100,10 +102,5 @@ gulp.task('default', () => {
100102
onLast: true,
101103
message: () => `Total size ${s.prettySize}`
102104
}));
103-
});
105+
};
104106
```
105-
106-
107-
## License
108-
109-
MIT © [Sindre Sorhus](https://sindresorhus.com)

0 commit comments

Comments
 (0)