Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes:
1. Update dependencies to the latest version.
2. Upgrade babel
3. Upgrade eslint
4. Upgrade Rollup
5. Cleanup rollup config.
6. Introduce Terser instead of Uglify
  • Loading branch information
Visweshwaran Suryanarayanan committed Aug 6, 2019
commit d936f20087c997bc84ba1a6549b59f856d458171
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
"es2015"
"@babel/preset-env"
]
}
4,961 changes: 4,961 additions & 0 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"description": "Logger for Redux",
"main": "dist/redux-logger.js",
"scripts": {
"lint": "eslint src",
"lint": "eslint src --fix",
"test": "npm run lint && npm run spec",
"spec": "nyc --all --silent --require babel-core/register mocha --plugins transform-inline-environment-variables --recursive spec/*.spec.js",
"spec": "nyc --all --silent --require @babel/register mocha --plugins transform-inline-environment-variables --recursive spec/*.spec.js",
"spec:watch": "npm run spec -- --watch",
"coverage": "nyc report",
"coverage:html": "nyc report --reporter=html && http-server -p 8077 ./coverage -o",
"coverage:production": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"clean": "rimraf dist",
"clean": "rimraf dist .nyc_output",
"build": "rollup -c",
"precommit": "npm test",
"prepublish": "npm run clean && npm test && npm run build"
Expand Down Expand Up @@ -58,31 +58,31 @@
},
"homepage": "https://github.com/theaqua/redux-logger#readme",
"devDependencies": {
"babel-core": "^6.24.0",
"babel-plugin-external-helpers": "^6.22.0",
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"babel-plugin-transform-inline-environment-variables": "6.8.0",
"babel-preset-es2015": "^6.24.0",
"chai": "3.5.0",
"codecov": "1.0.1",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"http-server": "0.9.0",
"husky": "^0.13.2",
"mocha": "3.1.2",
"nyc": "9.0.1",
"redux": "^3.6.0",
"rimraf": "^2.6.1",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-uglify": "^1.0.2",
"sinon": "^1.17.7"
"chai": "4.2.0",
"codecov": "3.5.0",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^17.1.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.3",
"http-server": "0.11.1",
"husky": "^3.0.2",
"mocha": "6.2.0",
"nyc": "14.1.1",
"redux": "^4.0.4",
"rimraf": "^2.6.3",
"rollup": "^1.18.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.2",
"rollup-plugin-node-resolve": "^5.2.0",
"sinon": "^7.4.0"
},
"dependencies": {
"deep-diff": "^0.3.5"
"@babel/register": "^7.5.5",
"deep-diff": "^1.0.2",
"rollup-plugin-terser": "^5.1.1"
}
}
26 changes: 13 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import uglify from 'rollup-plugin-uglify';
import { terser } from 'rollup-plugin-terser';

export default {
entry: 'src/index.js',
format: 'umd',
exports: 'named',
moduleName: 'reduxLogger',
dest: 'dist/redux-logger.js',
input: 'src/index.js',
output: {
file: 'dist/redux-logger.js',
format: 'umd',
exports: 'named',
name: 'reduxLogger',
},
plugins: [
babel({
babelrc: false,
exclude: /node_modules/,
presets: [
[
'es2015',
'@babel/env',
{
modules: false,
},
],
],
plugins: ['external-helpers'],
}),
commonjs({
include: 'node_modules/**',
include: /node_modules/,
}),
nodeResolve({
jsnext: true,
main: true,
browser: true,
mainFields: ['module', 'jsnext', 'main', 'browser'],
}),
uglify(),
terser(),
],
};
32 changes: 16 additions & 16 deletions spec/diff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('Diff', () => {
expect(style('A')).to.equal('color: #2196F3; font-weight: bold');
});
});

describe('render', () => {
it('should return an array indicating the changes', () => {
expect(render({
Expand All @@ -21,22 +21,22 @@ context('Diff', () => {
rhs: 'picard',
})).to.eql(['captain.name', 'kirk', '→', 'picard']);
});

it('should return an array indicating an added property/element', () => {
expect(render({
kind: 'N',
path: ['crew', 'engineer'],
rhs: 'geordi',
})).to.eql(['crew.engineer', 'geordi']);
});

it('should return an array indicating a removed property/element', () => {
expect(render({
kind: 'D',
path: ['crew', 'security'],
})).to.eql(['crew.security']);
});

it('should return an array indicating a changed index', () => {
expect(render({
kind: 'A',
Expand All @@ -51,15 +51,15 @@ context('Diff', () => {
rhs: 'after',
}]);
});

it('should return an empty array', () => {
expect(render({})).to.eql([]);
});
});

describe('diffLogger', () => {
let logger;

beforeEach(() => {
logger = {
log: sinon.spy(),
Expand All @@ -68,27 +68,27 @@ context('Diff', () => {
group: sinon.spy(),
};
});

it('should show no diff with group collapsed', () => {
diffLogger({}, {}, logger, true);

expect(logger.group.calledOnce).to.be.false;
expect(logger.groupCollapsed.calledOnce).to.be.true;
expect(logger.groupEnd.calledOnce).to.be.true;
expect(logger.log.calledOnce).to.be.true;
expect(logger.log.calledWith('—— no diff ——')).to.be.true;
});

it('should show no diff with group not collapsed', () => {
diffLogger({}, {}, logger, false);

expect(logger.group.calledOnce).to.be.true;
expect(logger.groupCollapsed.calledOnce).to.be.false;
expect(logger.groupEnd.calledOnce).to.be.true;
expect(logger.log.calledOnce).to.be.true;
expect(logger.log.calledWith('—— no diff ——')).to.be.true;
});

it('should log no diff without group', () => {
const loggerWithNoGroupCollapsed = Object.assign({}, logger, {
groupCollapsed: () => {
Expand All @@ -98,17 +98,17 @@ context('Diff', () => {
throw new Error();
},
});

diffLogger({}, {}, loggerWithNoGroupCollapsed, true);

expect(loggerWithNoGroupCollapsed.log.calledWith('diff')).to.be.true;
expect(loggerWithNoGroupCollapsed.log.calledWith('—— no diff ——')).to.be.true;
expect(loggerWithNoGroupCollapsed.log.calledWith('—— diff end —— ')).to.be.true;
});

it('should log the diffs', () => {
diffLogger({ name: 'kirk' }, { name: 'picard' }, logger, false);

expect(logger.log.calledWithExactly('%c CHANGED:', 'color: #2196F3; font-weight: bold', 'name', 'kirk', '→', 'picard')).to.be.true;
});
});
Expand Down
12 changes: 7 additions & 5 deletions src/diff.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import differ from 'deep-diff';
import DeepDiff from 'deep-diff';

// https://github.com/flitbit/diff#differences
const dictionary = {
Expand All @@ -22,7 +22,9 @@ const dictionary = {

export const style = kind => `color: ${dictionary[kind].color}; font-weight: bold`;

export const render = ({ kind, path, lhs, rhs, index, item }) => {
export const render = ({
kind, path, lhs, rhs, index, item,
}) => {
switch (kind) {
case 'E':
return [path.join('.'), lhs, '→', rhs];
Expand All @@ -38,7 +40,7 @@ export const render = ({ kind, path, lhs, rhs, index, item }) => {
};

export default (prevState, newState, logger, isCollapsed) => {
const diff = differ(prevState, newState);
const difference = DeepDiff(prevState, newState);
try {
if (isCollapsed) {
logger.groupCollapsed('diff');
Expand All @@ -49,8 +51,8 @@ export default (prevState, newState, logger, isCollapsed) => {
logger.log('diff');
}

if (diff) {
diff.forEach((elem) => {
if (difference) {
difference.forEach((elem) => {
const { kind } = elem;
const output = render(elem);
logger.log(`%c ${dictionary[kind].text}`, style(kind), ...output);
Expand Down
13 changes: 5 additions & 8 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ export const pad = (num, maxLength) => repeat('0', maxLength - num.toString().le
export const formatTime = time => `${pad(time.getHours(), 2)}:${pad(time.getMinutes(), 2)}:${pad(time.getSeconds(), 2)}.${pad(time.getMilliseconds(), 3)}`;

// Use performance API if it's available in order to get better precision
export const timer =
(typeof performance !== 'undefined' && performance !== null) && typeof performance.now === 'function' ?
performance :
Date;
export const timer = (typeof performance !== 'undefined' && performance !== null) && typeof performance.now === 'function'
? performance
: Date;

export const directlyApplied = ({ getState, dispatch }) => !!(getState && dispatch);

export const hasLogger = ({ logger }) => logger;

export const shouldNotLog = ({ predicate }, getState, action) =>
(typeof predicate === 'function' && !predicate(getState, action));
export const shouldNotLog = ({ predicate }, getState, action) => (typeof predicate === 'function' && !predicate(getState, action));

export const shouldDiff = ({ diff, diffPredicate }, getState, action) =>
!!(diff && typeof diffPredicate === 'function' && diffPredicate(getState, action));
export const shouldDiff = ({ diff, diffPredicate }, getState, action) => !!(diff && typeof diffPredicate === 'function' && diffPredicate(getState, action));

export const emptyLogger = () => () => next => action => next(action);

Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ function createLogger(options = {}) {
took,
nextState,
}],
loggerOptions);
loggerOptions,
);

if (error) throw error;
return returnedValue;
Expand Down