Skip to content

Commit

Permalink
chore(prettier): setup prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
terinjokes committed Mar 20, 2017
1 parent ec8ba54 commit da3e18f
Show file tree
Hide file tree
Showing 15 changed files with 588 additions and 351 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Expand Up @@ -3,6 +3,14 @@ sudo: false
node_js:
- 0.10
- 0.12
- 4
- 6
- 7
matrix:
include:
- node_js: 4
env: LINT_TEST=true
script:
- "if [[ -n $LINT_TEST ]]; then npm run lint; fi"
- npm run test
after_success:
- npm run coverage
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -3,7 +3,7 @@ var uglify = require('uglify-js');
var minifier = require('./minifier');
var GulpUglifyError = require('./lib/gulp-uglify-error');

module.exports = function (opts) {
module.exports = function(opts) {
return minifier(opts, uglify);
};

Expand Down
19 changes: 11 additions & 8 deletions lib/log.js
Expand Up @@ -4,12 +4,15 @@ var each = require('lodash/fp/forEach');

var levels = ['debug', 'info', 'warn', 'error'];

each(function (level) {
module.exports[level] = function () {
if (hasLog()) {
var log = require('gulplog');
each(
function(level) {
module.exports[level] = function() {
if (hasLog()) {
var log = require('gulplog');

log[level].apply(log, arguments);
}
};
}, levels);
log[level].apply(log, arguments);
}
};
},
levels
);
26 changes: 16 additions & 10 deletions minifier.js
Expand Up @@ -38,7 +38,7 @@ function setup(opts) {
if (options.preserveComments === 'all') {
options.output.comments = true;
} else if (options.preserveComments === 'some') {
// preserve comments with directives or that start with a bang (!)
// Preserve comments with directives or that start with a bang (!)
options.output.comments = /^!|@preserve|@license|@cc_on/i;
} else if (options.preserveComments === 'license') {
options.output.comments = saveLicense;
Expand All @@ -49,7 +49,7 @@ function setup(opts) {
return options;
}

module.exports = function (opts, uglify) {
module.exports = function(opts, uglify) {
function minify(file, encoding, callback) {
var options = setup(opts || {});
var sources;
Expand All @@ -70,16 +70,22 @@ module.exports = function (opts, uglify) {
}
options.outSourceMap = file.relative;

sources = zipObject(file.sourceMap.sources, file.sourceMap.sourcesContent);
sources = zipObject(
file.sourceMap.sources,
file.sourceMap.sourcesContent
);
}

var mangled = trycatch(function () {
var map = {};
map[file.relative] = String(file.contents);
var m = uglify.minify(map, options);
m.code = new Buffer(m.code.replace(reSourceMapComment, ''));
return m;
}, createError(file, 'unable to minify JavaScript'));
var mangled = trycatch(
function() {
var map = {};
map[file.relative] = String(file.contents);
var m = uglify.minify(map, options);
m.code = new Buffer(m.code.replace(reSourceMapComment, ''));
return m;
},
createError(file, 'unable to minify JavaScript')
);

if (mangled instanceof GulpUglifyError) {
return callback(mangled);
Expand Down
40 changes: 35 additions & 5 deletions package.json
Expand Up @@ -5,10 +5,17 @@
"author": "Terin Stock <terinjokes@gmail.com>",
"bugs": "https://github.com/terinjokes/gulp-uglify/issues",
"dependencies": {
"eslint": "^3.18.0",

This comment has been minimized.

Copy link
@ViktorAksionov

ViktorAksionov Mar 20, 2017

Why it published as Patch but not as Major? It introduces many errors with shrinkwrap at least in our code.

This comment has been minimized.

Copy link
@jchip

jchip Mar 21, 2017

why were these eslint packages and prettier not added to devDependencies only?

This comment has been minimized.

Copy link
@terinjokes

terinjokes Mar 21, 2017

Author Owner

@jchip They totally should have, my mistake.

This comment has been minimized.

Copy link
@terinjokes

terinjokes Mar 21, 2017

Author Owner

Moved to devDeps in 2.1.2, sorry about this @ViktorAksionov. Totally my mistake while reviewing the diff.

This comment has been minimized.

Copy link
@ViktorAksionov

ViktorAksionov Mar 21, 2017

thx

"eslint-config-prettier": "^1.5.0",
"eslint-config-xo": "^0.18.1",
"eslint-plugin-no-use-extend-native": "^0.3.12",
"eslint-plugin-prettier": "^2.0.1",
"eslint-plugin-unicorn": "^2.1.0",
"gulplog": "^1.0.0",
"has-gulplog": "^0.1.0",
"lodash": "^4.13.1",
"make-error-cause": "^1.1.1",
"prettier": "^0.22.0",
"through2": "^2.0.0",
"uglify-js": "~2.8.10",
"uglify-save-license": "^0.4.1",
Expand All @@ -26,8 +33,7 @@
"semver": "^5.3.0",
"tape": "^4.0.0",
"testdouble": "^1.6.0",
"vinyl": "^2.0.0",
"xo": "^0.16.0"
"vinyl": "^2.0.0"
},
"homepage": "https://github.com/terinjokes/gulp-uglify/",
"keywords": [
Expand All @@ -36,16 +42,40 @@
"license": "MIT",
"main": "index.js",
"repository": "terinjokes/gulp-uglify",
"xo": {
"space": true
"eslintConfig": {
"env": {
"node": true
},
"extends": [
"xo",
"prettier"
],
"plugins": [
"unicorn",
"no-use-extend-native",
"prettier"
],
"rules": {
"prettier/prettier": [
"error",
{
"printWidth": 80,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false
}
]
}
},
"files": [
"index.js",
"minifier.js",
"lib/"
],
"scripts": {
"test": "xo && mocha --require intelli-espower-loader",
"lint": "eslint *.js lib test",
"test": "mocha --require intelli-espower-loader",
"coverage": "cat ./coverage/lcov.info | coveralls"
},
"greenkeeper": {
Expand Down
2 changes: 1 addition & 1 deletion test/_helper.js
Expand Up @@ -2,6 +2,6 @@
var td = require('testdouble');
var mocha = require('mocha');

mocha.afterEach(function () {
mocha.afterEach(function() {
td.reset();
});
124 changes: 69 additions & 55 deletions test/comments.js
Expand Up @@ -13,73 +13,87 @@ var pipe = mississippi.pipe;
var to = mississippi.to;
var from = mississippi.from;

describe('preserveComments option', function () {
beforeEach(function () {
describe('preserveComments option', function() {
beforeEach(function() {
this.testFile = new Vinyl({
cwd: '/home/terin/broken-promises/',
base: '/home/terin/broken-promises/test',
path: '/home/terin/broken-promises/test/test1.js',
contents: new Buffer('"use strict";\nfunction foobar(){}\n/* comment one */\n/* comment three */\n/*! comment two MIT */\nfunction itsatrap(){}')
contents: new Buffer(
'"use strict";\nfunction foobar(){}\n/* comment one */\n/* comment three */\n/*! comment two MIT */\nfunction itsatrap(){}'
)
});
});

it('should preserve all comments', function (done) {
pipe([
from.obj([this.testFile]),
gulpUglify({preserveComments: 'all'}),
to.obj(function (newFile, enc, next) {
var contents = newFile.contents.toString();
assert.ok(/one/.test(contents), 'has comment one');
assert.ok(/two/.test(contents), 'has comment two');
assert.ok(/three/.test(contents), 'has comment three');
next();
})
], done);
it('should preserve all comments', function(done) {
pipe(
[
from.obj([this.testFile]),
gulpUglify({preserveComments: 'all'}),
to.obj(function(newFile, enc, next) {
var contents = newFile.contents.toString();
assert.ok(/one/.test(contents), 'has comment one');
assert.ok(/two/.test(contents), 'has comment two');
assert.ok(/three/.test(contents), 'has comment three');
next();
})
],
done
);
});

it('should preserve some comments', function (done) {
pipe([
from.obj([this.testFile]),
gulpUglify({preserveComments: 'some'}),
to.obj(function (newFile, enc, next) {
var contents = newFile.contents.toString();
assert.ok(!/one/.test(contents), 'does not have comment one');
assert.ok(/two/.test(contents), 'has comment two');
assert.ok(!/three/.test(contents), 'does not have comment three');
next();
})
], done);
it('should preserve some comments', function(done) {
pipe(
[
from.obj([this.testFile]),
gulpUglify({preserveComments: 'some'}),
to.obj(function(newFile, enc, next) {
var contents = newFile.contents.toString();
assert.ok(!/one/.test(contents), 'does not have comment one');
assert.ok(/two/.test(contents), 'has comment two');
assert.ok(!/three/.test(contents), 'does not have comment three');
next();
})
],
done
);
});

it('should preserve license comments', function (done) {
pipe([
from.obj([this.testFile]),
gulpUglify({preserveComments: 'license'}),
to.obj(function (newFile, enc, next) {
var contents = newFile.contents.toString();
assert.ok(!/one/.test(contents), 'does not have comment one');
assert.ok(/two/.test(contents), 'has comment two');
assert.ok(!/three/.test(contents), 'does not have comment three');
next();
})
], done);
it('should preserve license comments', function(done) {
pipe(
[
from.obj([this.testFile]),
gulpUglify({preserveComments: 'license'}),
to.obj(function(newFile, enc, next) {
var contents = newFile.contents.toString();
assert.ok(!/one/.test(contents), 'does not have comment one');
assert.ok(/two/.test(contents), 'has comment two');
assert.ok(!/three/.test(contents), 'does not have comment three');
next();
})
],
done
);
});

it('should preserve comments that fn returns true for', function (done) {
pipe([
from.obj([this.testFile]),
gulpUglify({
preserveComments: function (node, comment) {
return /three/.test(comment.value);
}
}),
to.obj(function (newFile, enc, next) {
var contents = newFile.contents.toString();
assert.ok(!/one/.test(contents), 'does not have comment one');
assert.ok(!/two/.test(contents), 'does not have comment two');
assert.ok(/three/.test(contents), 'has comment three');
next();
})
], done);
it('should preserve comments that fn returns true for', function(done) {
pipe(
[
from.obj([this.testFile]),
gulpUglify({
preserveComments: function(node, comment) {
return /three/.test(comment.value);
}
}),
to.obj(function(newFile, enc, next) {
var contents = newFile.contents.toString();
assert.ok(!/one/.test(contents), 'does not have comment one');
assert.ok(!/two/.test(contents), 'does not have comment two');
assert.ok(/three/.test(contents), 'has comment three');
next();
})
],
done
);
});
});
18 changes: 12 additions & 6 deletions test/create-error.js
Expand Up @@ -9,8 +9,8 @@ var describe = mocha.describe;
var it = mocha.it;
var beforeEach = mocha.beforeEach;

describe('createError', function () {
beforeEach(function () {
describe('createError', function() {
beforeEach(function() {
var testOkContentsInput = '"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))';
this.testFile = new Vinyl({
cwd: '/home/terin/broken-promises/',
Expand All @@ -20,22 +20,28 @@ describe('createError', function () {
});
});

it('should have expected error message', function () {
it('should have expected error message', function() {
var e = createError(this.testFile, 'error message text', null);

assert.ok(e instanceof Error, 'argument should be of type Error');
assert.ok(e instanceof GulpUglifyError, 'argument should be of type GulpUglifyError');
assert.ok(
e instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.equal(e.message, 'error message text');
assert.ok(!e.cause, 'should not contain a cause');
});

it('should wrap cause', function () {
it('should wrap cause', function() {
var cause = new Error('boom!');
var e = createError(this.testFile, 'error message text', cause);

assert.ok(e instanceof Error, 'argument should be of type Error');
assert.ok(e instanceof GulpUglifyError, 'argument should be of type GulpUglifyError');
assert.ok(
e instanceof GulpUglifyError,
'argument should be of type GulpUglifyError'
);
assert.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify');
assert.ok(e.message.match(/^error message text/));
assert.equal(e.cause, cause);
Expand Down

0 comments on commit da3e18f

Please sign in to comment.