Skip to content

Commit d88adc4

Browse files
committed
add prettier
1 parent e89657b commit d88adc4

16 files changed

+208
-184
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/src/js/bundle
2+
*.min.js

.prettierrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

README.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,54 @@
11
### ![](./src/img/panel-icon28.png) console.diff()
2+
23
[![console.diff()](https://storage.googleapis.com/web-dev-uploads/image/WlD8wC6g8khYWPJUsQceQkhXSlv1/tbyBjqi7Zu733AAKA5n4.png)](https://chrome.google.com/webstore/detail/jsdiff-devtool/iefeamoljhdcpigpnpggeiiabpnpgonb)
34

45
Chrome devtools extension intended to display result of deep in-memory object
56
comparisons with the help of dedicated console commands.
67

78
### Features
8-
* compare objects from multiple tabs and/or between page reloads
9-
* function code included in comparison result in form of a string, may help to see if it was altered
10-
* document, dom-elements and other non-serializable objects are filtered-out from the results
11-
* self recurring references displayed only once, the rest of occurrences are filtered-out
9+
10+
- compare objects from multiple tabs and/or between page reloads
11+
- function code included in comparison result in form of a string, may help to see if it was altered
12+
- document, dom-elements and other non-serializable objects are filtered-out from the results
13+
- self recurring references displayed only once, the rest of occurrences are filtered-out
1214

1315
### API
16+
1417
```javascript
15-
console.diff(left, right); // compare left and right
16-
console.diff(next); // shorthand of diffPush while single argumented
17-
console.diffLeft(left); // update object on the left side only
18-
console.diffRight(right); // update object on the right side only
19-
console.diffPush(next); // shifts sides, right becomes left, next becomes right
18+
console.diff(left, right); // compare left and right
19+
console.diff(next); // shorthand of diffPush while single argumented
20+
console.diffLeft(left); // update object on the left side only
21+
console.diffRight(right); // update object on the right side only
22+
console.diffPush(next); // shifts sides, right becomes left, next becomes right
2023
```
2124

2225
### Usage basics
26+
2327
Historically, left side represents the old state and right side the new state.
24-
* Things that are present on the left side but missing on the right side are colour-coded as red (old).
25-
* Things that are missing on the left side but present on the right side are colour-coded as green (new).
28+
29+
- Things that are present on the left side but missing on the right side are colour-coded as red (old).
30+
- Things that are missing on the left side but present on the right side are colour-coded as green (new).
2631

2732
To track changes of the same variable in timed manner you can push it with `diffPush` or `diff`
2833
with a single argument,
2934
that will shift objects from right to left, showing differences with previous push state.
3035

3136
### How it works
32-
* `jsdiff-devtools` registers devtools panel
33-
* injects console commands that send data to `jsdiff-proxy`
34-
* injects `jsdiff-proxy` to farther communicate objects to the extension's `jsdiff-background`
35-
* when `console.diff` command invoked
36-
* argument/s are cloned in a suitable form for sending between different window contexts and sent to `jsdiff-proxy`
37-
* `jsdiff-proxy` catches the data and sends it to the `jsdiff-background` where it is stored for future consuming
38-
* when `jsdiff-panel` is mounted (visible in devtools) it listens to data expected to come from the `jsdiff-background`
39-
and displays it
37+
38+
- `jsdiff-devtools` registers devtools panel
39+
- injects console commands that send data to `jsdiff-proxy`
40+
- injects `jsdiff-proxy` to farther communicate objects to the extension's `jsdiff-background`
41+
- when `console.diff` command invoked
42+
- argument/s are cloned in a suitable form for sending between different window contexts and sent to `jsdiff-proxy`
43+
- `jsdiff-proxy` catches the data and sends it to the `jsdiff-background` where it is stored for future consuming
44+
- when `jsdiff-panel` is mounted (visible in devtools) it listens to data expected to come from the `jsdiff-background`
45+
and displays it
4046

4147
### Screenshot
48+
4249
![screenshot](./src/img/screenshot-01.png)
4350

4451
### Based on
52+
4553
- [jsondiffpatch](https://github.com/benjamine/jsondiffpatch) by Benjamín Eidelman
4654
- [vuejs](https://github.com/vuejs) by Evan You

manifest.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@
1212
},
1313
"background": {
1414
"persistent": false,
15-
"scripts": [
16-
"src/js/jsdiff-background.js"
17-
]
15+
"scripts": ["src/js/jsdiff-background.js"]
1816
},
1917
"content_security_policy": "script-src 'self'; object-src 'self'",
20-
"permissions": [
21-
"http://*/*",
22-
"https://*/*",
23-
"file:///*",
24-
"clipboardWrite"
25-
]
18+
"permissions": ["http://*/*", "https://*/*", "clipboardWrite"]
2619
}

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"scripts": {
1010
"test": "echo \"no test\" && exit 1",
1111
"dev": "webpack --progress --watch --mode=development",
12-
"prod": "NODE_ENV=production webpack --mode=production"
12+
"prod": "NODE_ENV=production webpack --mode=production",
13+
"format": "prettier . --write"
1314
},
1415
"repository": {
1516
"type": "git",
@@ -32,13 +33,13 @@
3233
"css-loader": "~6.6.0",
3334
"jsondiffpatch": "~0.4.1",
3435
"node-sass": "~7.0.3",
36+
"prettier": "^2.8.7",
3537
"sass-loader": "~12.4.0",
3638
"style-loader": "~3.3.1",
3739
"vue": "~3.2.31",
3840
"vue-loader": "~17.0.0",
3941
"webpack": "~5.77.0",
4042
"webpack-bundle-analyzer": "^4.5.0",
4143
"webpack-cli": "~4.9.2"
42-
},
43-
"dependencies": {}
44+
}
4445
}

src/js/bundle/jsdiff-panel.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/jsdiff-background.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ chrome.runtime.onConnect.addListener((port) => {
2222
if (port === con.port) {
2323
con.onDisconnect();
2424
connections.delete(tabId);
25-
break
25+
break;
2626
}
2727
}
2828
});
@@ -31,11 +31,13 @@ chrome.runtime.onConnect.addListener((port) => {
3131
chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
3232
const tabId = sender.tab && sender.tab.id;
3333

34-
if ('jsdiff-devtools-extension-api' === req.source && connections.has(tabId)) {
34+
if (
35+
'jsdiff-devtools-extension-api' === req.source &&
36+
connections.has(tabId)
37+
) {
3538
lastApiReq = req;
3639
connections.get(tabId).onApiMessage(req);
37-
}
38-
else if ('jsdiff-devtools-panel-shown' === req.type) {
40+
} else if ('jsdiff-devtools-panel-shown' === req.type) {
3941
// message from one of devtool panels
4042
sendResponse(lastApiReq);
4143
}
@@ -62,5 +64,4 @@ class Connection {
6264
onDisconnect() {
6365
this.port = null;
6466
}
65-
6667
}

src/js/jsdiff-devtools.js

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22

33
// Create panel
44
chrome.devtools.panels.create(
5-
'JSDiff',
6-
'/src/img/panel-icon28.png',
7-
'/src/jsdiff-panel.html',
8-
(panel) => {
9-
//panel.onSearch.addListener(sendMessage('jsdiff-panel-search'));
10-
//panel.onShown.addListener(sendMessage('jsdiff-panel-shown'));
11-
//panel.onHidden.addListener(sendMessage('jsdiff-panel-hidden'));
12-
}
5+
'JSDiff',
6+
'/src/img/panel-icon28.png',
7+
'/src/jsdiff-panel.html',
8+
(panel) => {
9+
//panel.onSearch.addListener(sendMessage('jsdiff-panel-search'));
10+
//panel.onShown.addListener(sendMessage('jsdiff-panel-shown'));
11+
//panel.onHidden.addListener(sendMessage('jsdiff-panel-hidden'));
12+
}
1313
);
1414

1515
// Create a connection to the background page
1616
if (chrome.devtools.inspectedWindow.tabId !== null) {
1717
// tabId may be null if user opened the devtools of the devtools
18-
const backgroundPageConnection = chrome.runtime.connect({name: 'jsdiff-devtools'});
18+
const backgroundPageConnection = chrome.runtime.connect({
19+
name: 'jsdiff-devtools',
20+
});
1921
backgroundPageConnection.postMessage({
2022
name: 'init',
21-
tabId: chrome.devtools.inspectedWindow.tabId
23+
tabId: chrome.devtools.inspectedWindow.tabId,
2224
});
2325

2426
injectScripts();
@@ -35,37 +37,34 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
3537
// us shown at: https://developer.chrome.com/extensions/devtools#content-script-to-devtools
3638
function injectScripts() {
3739
chrome.devtools.inspectedWindow.eval(
38-
`;(${jsdiff_devtools_extension_api.toString()})();`, {
39-
useContentScriptContext: false // default: false
40-
}, (res, error) => {
41-
if (res && !error) {
42-
// injected
43-
chrome.tabs.executeScript(chrome.devtools.inspectedWindow.tabId, {
44-
file: '/src/js/jsdiff-proxy.js'
45-
});
46-
}
47-
});
40+
`;(${jsdiff_devtools_extension_api.toString()})();`,
41+
{
42+
useContentScriptContext: false, // default: false
43+
},
44+
(res, error) => {
45+
if (res && !error) {
46+
// injected
47+
chrome.tabs.executeScript(chrome.devtools.inspectedWindow.tabId, {
48+
file: '/src/js/jsdiff-proxy.js',
49+
});
50+
}
51+
}
52+
);
4853
}
4954

5055
function jsdiff_devtools_extension_api() {
51-
if (typeof(console.diff) === 'function') {
56+
if (typeof console.diff === 'function') {
5257
/*already injected*/
5358
return false;
5459
}
5560

5661
function postDataAdapter(set, key, value) {
5762
try {
58-
if (
59-
value instanceof Element ||
60-
value instanceof Document
61-
) {
63+
if (value instanceof Element || value instanceof Document) {
6264
return undefined;
63-
} else if (typeof(value) === 'function') {
65+
} else if (typeof value === 'function') {
6466
return value.toString();
65-
} else if (
66-
value instanceof Object ||
67-
typeof(value) === 'object'
68-
) {
67+
} else if (value instanceof Object || typeof value === 'object') {
6968
if (set.has(value)) {
7069
return undefined;
7170
}
@@ -84,48 +83,53 @@ function jsdiff_devtools_extension_api() {
8483
if (payload.hasOwnProperty(key)) {
8584
let set = new Set();
8685
payload[key] = JSON.parse(
87-
JSON.stringify(
88-
payload[key],
89-
postDataAdapter.bind(null, set)
90-
)
86+
JSON.stringify(payload[key], postDataAdapter.bind(null, set))
9187
);
9288
set.clear();
9389
set = null;
9490
}
9591
});
96-
window.postMessage({payload, source: 'jsdiff-devtools-extension-api'}, '*');
92+
window.postMessage(
93+
{ payload, source: 'jsdiff-devtools-extension-api' },
94+
'*'
95+
);
9796
} catch (e) {
98-
console.error('%cJSDiff', `
97+
console.error(
98+
'%cJSDiff',
99+
`
99100
font-weight: 700;
100101
color: #000;
101102
background-color: yellow;
102103
padding: 2px 4px;
103104
border: 1px solid #bbb;
104105
border-radius: 4px;
105-
`, e);
106+
`,
107+
e
108+
);
106109
}
107110
}
108111

109112
Object.assign(console, {
110113
diff(left, right) {
111-
post(right === undefined? {push: left} : {left, right});
114+
post(right === undefined ? { push: left } : { left, right });
112115
},
113116

114117
diffLeft(left) {
115-
post({left});
118+
post({ left });
116119
},
117120

118121
diffRight(right) {
119-
post({right});
122+
post({ right });
120123
},
121124

122125
diffPush(push) {
123-
post({push});
126+
post({ push });
124127
},
125128
});
126129

127130
console.log(
128-
'%c✚ console.diff(left, right);', `
131+
'%c✚ console.diff(left, right);',
132+
`
129133
font-weight: 700;
130134
color: #000;
131135
background-color: yellow;
@@ -139,7 +143,7 @@ function jsdiff_devtools_extension_api() {
139143
}
140144

141145
function sendMessage(message) {
142-
return function() {
146+
return function () {
143147
chrome.runtime.sendMessage(message);
144148
};
145149
}

src/js/jsdiff-panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createApp} from 'vue';
1+
import { createApp } from 'vue';
22
import Panel from './view/panel.vue';
33

44
const app = createApp(Panel);

src/js/jsdiff-proxy.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
;(function(w, x) {
1+
(function (w, x) {
22
'use strict';
33
w.addEventListener('message', function jsdiff_devtools_extension_proxy(e) {
4-
if (// message from the same frame
5-
e.source === w &&
6-
e.data && typeof(e.data) === 'object' &&
7-
e.data.source === 'jsdiff-devtools-extension-api'
4+
if (
5+
// message from the same frame
6+
e.source === w &&
7+
e.data &&
8+
typeof e.data === 'object' &&
9+
e.data.source === 'jsdiff-devtools-extension-api'
810
) {
911
x && x.sendMessage(e.data);
1012
}

0 commit comments

Comments
 (0)