Skip to content

Commit f3e673c

Browse files
thiamsantosimevro
authored andcommitted
chore: webpack → rollup (#227)
1 parent a7fc6d7 commit f3e673c

12 files changed

+227
-93
lines changed

.babelrc

-4
This file was deleted.

.eslintignore

-3
This file was deleted.

.eslintrc

-6
This file was deleted.

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
node_js:
33
- "6"
4-
script: npm run test:production
4+
script: npm test
55

66
# Repository token must be provided in "coverage:production" npm script
77
after_success: npm run coverage:production

package.json

+38-25
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22
"name": "redux-logger",
33
"version": "3.0.1",
44
"description": "Logger for Redux",
5-
"main": "lib/index.js",
5+
"main": "dist/redux-logger.js",
6+
"module": "src/index.js",
7+
"jsnext:main": "src/index.js",
68
"scripts": {
7-
"lint": "$(npm bin)/eslint src",
8-
"test": "NODE_ENV=development npm run lint && npm run spec",
9-
"test:production": "NODE_ENV=production npm run lint && npm run spec",
10-
"spec": "NODE_PATH=src nyc --all --silent --require babel-core/register mocha --plugins transform-inline-environment-variables --recursive spec/*.spec.js",
11-
"spec:watch": "NODE_ENV=development npm run spec -- --watch",
9+
"lint": "eslint src",
10+
"test": "npm run lint && npm run spec",
11+
"spec": "nyc --all --silent --require babel-core/register mocha --plugins transform-inline-environment-variables --recursive spec/*.spec.js",
12+
"spec:watch": "npm run spec -- --watch",
1213
"coverage": "nyc report",
13-
"coverage:html": "nyc report --reporter=html && (http-server -p 8077 ./coverage & open-url http://localhost:8077/)",
14+
"coverage:html": "nyc report --reporter=html && http-server -p 8077 ./coverage -o",
1415
"coverage:production": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
15-
"clean": "$(npm bin)/rimraf dist lib",
16-
"build:lib": "$(npm bin)/babel src --out-dir lib",
17-
"build:umd": "LIBRARY_NAME=reduxLogger NODE_ENV=development $(npm bin)/webpack src/index.js dist/index.js --config webpack.build.js",
18-
"build:umd:min": "LIBRARY_NAME=reduxLogger NODE_ENV=production $(npm bin)/webpack -p src/index.js dist/index.min.js --config webpack.build.js",
19-
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
20-
"precommit": "npm run test",
21-
"prepublish": "npm run clean && npm run test:production && npm run build"
16+
"clean": "rimraf dist",
17+
"build": "rollup -c",
18+
"precommit": "npm test",
19+
"prepublish": "npm run clean && npm test && npm run build"
20+
},
21+
"babel": {
22+
"presets": [
23+
"es2015",
24+
"stage-0"
25+
]
26+
},
27+
"eslintConfig": {
28+
"extends": "airbnb",
29+
"rules": {
30+
"no-console": "off"
31+
},
32+
"env": {
33+
"browser": true,
34+
"mocha": true
35+
}
2236
},
2337
"nyc": {
2438
"exclude": [
@@ -27,12 +41,12 @@
2741
"example",
2842
"lib",
2943
"dist",
30-
"webpack.*.js"
44+
"coverage",
45+
"rollup.config.js"
3146
]
3247
},
3348
"files": [
3449
"dist",
35-
"lib",
3650
"src"
3751
],
3852
"repository": {
@@ -52,14 +66,10 @@
5266
},
5367
"homepage": "https://github.com/theaqua/redux-logger#readme",
5468
"devDependencies": {
55-
"babel-cli": "^6.24.0",
5669
"babel-core": "^6.24.0",
57-
"babel-loader": "^6.4.1",
58-
"babel-plugin-add-module-exports": "0.2.1",
59-
"babel-plugin-transform-es2015-modules-umd": "6.24.0",
70+
"babel-plugin-external-helpers": "^6.22.0",
6071
"babel-plugin-transform-inline-environment-variables": "6.8.0",
6172
"babel-preset-es2015": "^6.24.0",
62-
"babel-preset-react": "^6.23.0",
6373
"babel-preset-stage-0": "^6.22.0",
6474
"chai": "3.5.0",
6575
"codecov": "1.0.1",
@@ -72,13 +82,16 @@
7282
"husky": "^0.13.2",
7383
"mocha": "3.1.2",
7484
"nyc": "9.0.1",
75-
"open-url": "2.0.2",
7685
"redux": "^3.6.0",
7786
"rimraf": "^2.6.1",
78-
"sinon": "^1.17.7",
79-
"webpack": "1.13.3"
87+
"rollup": "^0.41.6",
88+
"rollup-plugin-babel": "^2.7.1",
89+
"rollup-plugin-commonjs": "^8.0.2",
90+
"rollup-plugin-node-resolve": "^3.0.0",
91+
"rollup-plugin-uglify": "^1.0.2",
92+
"sinon": "^1.17.7"
8093
},
8194
"dependencies": {
82-
"deep-diff": "0.3.4"
95+
"deep-diff": "^0.3.5"
8396
}
8497
}

rollup.config.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import babel from 'rollup-plugin-babel';
2+
import commonjs from 'rollup-plugin-commonjs';
3+
import nodeResolve from 'rollup-plugin-node-resolve';
4+
import uglify from 'rollup-plugin-uglify';
5+
6+
export default {
7+
entry: 'src/index.js',
8+
format: 'umd',
9+
exports: 'named',
10+
moduleName: 'reduxLogger',
11+
dest: 'dist/redux-logger.js',
12+
plugins: [
13+
babel({
14+
babelrc: false,
15+
presets: [
16+
['es2015', {
17+
modules: false,
18+
}],
19+
'stage-0'
20+
],
21+
plugins: [
22+
'external-helpers'
23+
],
24+
}),
25+
commonjs({
26+
include: 'node_modules/**',
27+
}),
28+
nodeResolve({
29+
jsnext: true,
30+
main: true,
31+
browser: true,
32+
}),
33+
uglify()
34+
]
35+
};

spec/diff.spec.js

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import sinon from 'sinon';
2+
import { expect } from 'chai';
3+
import { style, render, default as diffLogger } from '../src/diff';
4+
5+
context('Diff', () => {
6+
describe('style', () => {
7+
it('return css rules for the given kind of diff changes', () => {
8+
expect(style('E')).to.equal('color: #2196F3; font-weight: bold');
9+
expect(style('N')).to.equal('color: #4CAF50; font-weight: bold');
10+
expect(style('D')).to.equal('color: #F44336; font-weight: bold');
11+
expect(style('A')).to.equal('color: #2196F3; font-weight: bold');
12+
});
13+
});
14+
15+
describe('render', () => {
16+
it('should return an array indicating the changes', () => {
17+
expect(render({
18+
kind: 'E',
19+
path: ['capitain', 'name'],
20+
lhs: 'kirk',
21+
rhs: 'picard',
22+
})).to.eql(['capitain.name', 'kirk', '→', 'picard']);
23+
});
24+
25+
it('should return an array indicating an added property/element', () => {
26+
expect(render({
27+
kind: 'N',
28+
path: ['crew', 'engineer'],
29+
rhs: 'geordi',
30+
})).to.eql(['crew.engineer', 'geordi']);
31+
});
32+
33+
it('should return an array indicating a removed property/element', () => {
34+
expect(render({
35+
kind: 'D',
36+
path: ['crew', 'security'],
37+
})).to.eql(['crew.security']);
38+
});
39+
40+
it('should return an array indicating a changed index', () => {
41+
expect(render({
42+
kind: 'A',
43+
path: ['crew'],
44+
index: 2,
45+
item: {
46+
kind: 'N',
47+
rhs: 'after',
48+
},
49+
})).to.eql(['crew[2]', {
50+
kind: 'N',
51+
rhs: 'after',
52+
}]);
53+
});
54+
55+
it('should return an empty array', () => {
56+
expect(render({})).to.eql([]);
57+
});
58+
});
59+
60+
describe('diffLogger', () => {
61+
let logger
62+
63+
beforeEach(() => {
64+
logger = {
65+
log: sinon.spy(),
66+
groupCollapsed: sinon.spy(),
67+
groupEnd: sinon.spy(),
68+
group: sinon.spy(),
69+
};
70+
});
71+
72+
it('should show no diff with group collapsed', () => {
73+
diffLogger({}, {}, logger, true);
74+
75+
expect(logger.group.calledOnce).to.be.false;
76+
expect(logger.groupCollapsed.calledOnce).to.be.true;
77+
expect(logger.groupEnd.calledOnce).to.be.true;
78+
expect(logger.log.calledOnce).to.be.true;
79+
expect(logger.log.calledWith('—— no diff ——')).to.be.true;
80+
});
81+
82+
it('should show no diff with group not collapsed', () => {
83+
diffLogger({}, {}, logger, false);
84+
85+
expect(logger.group.calledOnce).to.be.true;
86+
expect(logger.groupCollapsed.calledOnce).to.be.false;
87+
expect(logger.groupEnd.calledOnce).to.be.true;
88+
expect(logger.log.calledOnce).to.be.true;
89+
expect(logger.log.calledWith('—— no diff ——')).to.be.true;
90+
});
91+
92+
it('should log no diff without group', () => {
93+
const loggerWithNoGroupCollapsed = Object.assign({}, logger, {
94+
groupCollapsed: () => {
95+
throw new Error()
96+
},
97+
groupEnd: () => {
98+
throw new Error()
99+
},
100+
});
101+
102+
diffLogger({}, {}, loggerWithNoGroupCollapsed, true);
103+
104+
expect(loggerWithNoGroupCollapsed.log.calledWith('diff')).to.be.true;
105+
expect(loggerWithNoGroupCollapsed.log.calledWith('—— no diff ——')).to.be.true;
106+
expect(loggerWithNoGroupCollapsed.log.calledWith('—— diff end —— ')).to.be.true;
107+
});
108+
109+
it('should log the diffs', () => {
110+
diffLogger({name: 'kirk'}, {name: 'picard'}, logger, false);
111+
112+
expect(logger.log.calledWithExactly('%c CHANGED:', 'color: #2196F3; font-weight: bold', 'name', 'kirk', '→', 'picard')).to.be.true;
113+
});
114+
});
115+
});

spec/helpers.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect } from 'chai';
2+
import { repeat, pad, formatTime } from '../src/helpers';
3+
4+
context('Helpers', () => {
5+
describe('repeat', () => {
6+
it('should repeat a string the number of indicated times', () => {
7+
expect(repeat('teacher', 3)).to.equal('teacherteacherteacher');
8+
});
9+
});
10+
11+
describe('pad', () => {
12+
it('should add leading zeros to a number given a maximun length', () => {
13+
expect(pad(56, 4)).to.equal('0056');
14+
});
15+
});
16+
17+
describe('formatTime', () => {
18+
it('should format a time given a Date object', () => {
19+
const time = new Date('December 25, 1995 23:15:30');
20+
expect(formatTime(time)).to.equal('23:15:30.000');
21+
});
22+
});
23+
});

spec/index.spec.js

+13-25
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,47 @@
1-
import { expect } from 'chai';
21
import sinon from 'sinon';
3-
42
import { applyMiddleware, createStore } from 'redux';
3+
import { default as logger, createLogger } from '../src';
54

6-
import { repeat } from 'helpers';
7-
import logger, { createLogger } from '../src';
8-
9-
context(`Helpers`, () => {
10-
describe(`repeat`, () => {
11-
it(`should repeat a string the number of indicated times`, () => {
12-
expect(repeat(`teacher`, 3)).to.equal(`teacherteacherteacher`);
13-
});
14-
});
15-
});
16-
17-
context(`default logger`, () => {
18-
describe(`init`, () => {
5+
context('default logger', () => {
6+
describe('init', () => {
197
beforeEach(() => {
20-
sinon.spy(console, `error`);
8+
sinon.spy(console, 'error');
219
});
2210

2311
afterEach(() => {
2412
console.error.restore();
2513
});
2614

27-
it(`should be ok`, () => {
15+
it('should be ok', () => {
2816
const store = createStore(() => ({}), applyMiddleware(logger));
2917

30-
store.dispatch({ type: `foo` });
18+
store.dispatch({ type: 'foo' });
3119
sinon.assert.notCalled(console.error);
3220
});
3321
});
3422
});
3523

36-
context(`createLogger`, () => {
37-
describe(`init`, () => {
24+
context('createLogger', () => {
25+
describe('init', () => {
3826
beforeEach(() => {
39-
sinon.spy(console, `error`);
27+
sinon.spy(console, 'error');
4028
});
4129

4230
afterEach(() => {
4331
console.error.restore();
4432
});
4533

46-
it(`should throw error if passed direct to applyMiddleware`, () => {
34+
it('should throw error if passed direct to applyMiddleware', () => {
4735
const store = createStore(() => ({}), applyMiddleware(createLogger));
4836

49-
store.dispatch({ type: `foo` });
37+
store.dispatch({ type: 'foo' });
5038
sinon.assert.calledOnce(console.error);
5139
});
5240

53-
it(`should be ok`, () => {
41+
it('should be ok', () => {
5442
const store = createStore(() => ({}), applyMiddleware(createLogger()));
5543

56-
store.dispatch({ type: `foo` });
44+
store.dispatch({ type: 'foo' });
5745
sinon.assert.notCalled(console.error);
5846
});
5947
});

src/diff.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ const dictionary = {
2020
},
2121
};
2222

23-
function style(kind) {
23+
export function style(kind) {
2424
return `color: ${dictionary[kind].color}; font-weight: bold`;
2525
}
2626

27-
function render(diff) {
27+
export function render(diff) {
2828
const { kind, path, lhs, rhs, index, item } = diff;
2929

3030
switch (kind) {

webpack.build.js

-4
This file was deleted.

0 commit comments

Comments
 (0)