Skip to content

Commit 7741dc4

Browse files
committed
deprecate terser
1 parent c8736b8 commit 7741dc4

File tree

12 files changed

+149
-40
lines changed

12 files changed

+149
-40
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/bundle/js
22
.ts-built
33
*.min.js
4+
pnpm-lock.yaml

Makefile

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
ZIP_FILE="extension.zip"
2-
HASH_ALG="sha384"
2+
HASH_ALG=sha384
3+
BIN=node_modules/.bin
34

4-
.PHONY: install all dev prod build format lint clean
5+
.PHONY:
6+
install all dev prod build format lint clean
57

68
install:
79
npm i -g pnpm
@@ -11,28 +13,32 @@ all: build
1113

1214
dev:
1315
NODE_OPTIONS="--loader=ts-node/esm" \
14-
./node_modules/.bin/webpack --progress --watch --mode=development
16+
$(BIN)/webpack --progress --watch --mode=development
1517

1618
prod:
1719
NODE_OPTIONS="--loader=ts-node/esm --no-warnings=ExperimentalWarning" \
18-
NODE_ENV="production" \
19-
./node_modules/.bin/webpack --mode=production
20+
NODE_ENV="production" \
21+
$(BIN)/webpack --mode=production
2022

2123
build:
2224
make lint
2325
make prod
24-
26+
make zip
27+
make print_zip_hash
28+
29+
zip:
2530
rm -rf $(ZIP_FILE)
2631
zip -r $(ZIP_FILE) ./bundle ./manifest.json > /dev/null
2732

33+
print_zip_hash:
2834
FILE_HASH=$$(openssl dgst -$(HASH_ALG) -binary $(ZIP_FILE) | openssl base64 -A); \
29-
echo "$(ZIP_FILE) (hash-$(HASH_ALG)): $$FILE_HASH"
35+
echo "$(ZIP_FILE) $(HASH_ALG):$$FILE_HASH"
3036

3137
format:
32-
./node_modules/.bin/prettier . --write
38+
$(BIN)/prettier . --write
3339

3440
lint:
35-
./node_modules/.bin/tsc -noEmit
41+
$(BIN)/tsc -noEmit
3642

3743
clean:
3844
rm -rf ./node_modules

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Chrome extension to compare objects in memory with console.diff(old, new) devtoo
6666

6767
[i10]: https://github.com/zendive/jsdiff/issues/10
6868

69-
- Compared objects, after being serialized, and stored in `chrome.storage.local` wich has 10MB limit.
69+
- Compared objects, after being serialized, stored in `chrome.storage.local` wich has 10MB limit (before chrome v114 was 5MB).
7070

7171
### API
7272

@@ -100,7 +100,7 @@ console.diffLeft(Date.now());
100100
console.diffRight(Date.now());
101101
```
102102

103-
- **console.diff\_(\*)** - deprecated, left for backward compatibility, uses `nativeClone` based of JSON.parse(JSON.stringify(...)) serialization method
103+
- **console.diff\_(\*)** - uses deprecated `nativeClone` serialization method, based of JSON.parse(JSON.stringify(...)), left for backward compatibility
104104

105105
### Usage basics
106106

bundle/js/jsdiff-panel.js

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

bundle/js/jsdiff-proxy.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.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"sass": "1.64.1",
3636
"sass-loader": "13.3.2",
3737
"style-loader": "3.3.3",
38-
"terser-webpack-plugin": "5.3.9",
3938
"ts-node": "10.9.1",
4039
"typescript": "5.1.6",
4140
"vue": "3.3.4",

pnpm-lock.yaml

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

src/api/proxy.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ export function proxyMessageGate(
1818
export async function proxyCompareHandler(
1919
e: MessageEvent<ICompareMessage>
2020
): Promise<void> {
21-
const current = e.data.payload;
22-
const { lastApiReq: old } = await chrome.storage.local.get(['lastApiReq']);
23-
const next = processComparisonObject(old, current);
24-
2521
try {
22+
const current = e.data.payload;
23+
const { lastApiReq: old } = await chrome.storage.local.get(['lastApiReq']);
24+
const next = processComparisonObject(
25+
old as ICompareMessagePayload,
26+
current
27+
);
28+
2629
// may throw
2730
await chrome.storage.local.set({ lastApiReq: next, lastError: '' });
2831

src/api/~zip.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import pako from 'pako';
2+
3+
export class CompressedLocalStorage {
4+
static async get(propName: string): Promise<unknown> {
5+
return CompressedLocalStorage.getEncoded(propName);
6+
// return CompressedLocalStorage.getAsIs(propName);
7+
}
8+
9+
static async set(propName: string, obj: unknown): Promise<void> {
10+
CompressedLocalStorage.setEncoded(propName, obj);
11+
// CompressedLocalStorage.setAsIs(propName, obj);
12+
}
13+
14+
static async getAsIs(propName: string): Promise<unknown> {
15+
const storePropName = `${propName}_${storePropNameSufix}`;
16+
const store = await chrome.storage.local.get([storePropName]);
17+
18+
return store[storePropName];
19+
}
20+
21+
static async setAsIs(propName: string, obj: unknown): Promise<void> {
22+
const storePropName = `${propName}_${storePropNameSufix}`;
23+
const store = { [storePropName]: obj };
24+
25+
await chrome.storage.local.set(store);
26+
}
27+
28+
static async getEncoded(propName: string): Promise<unknown> {
29+
const storePropName = `${propName}_${storePropNameSufix}`;
30+
const store = await chrome.storage.local.get([storePropName]);
31+
let rv;
32+
33+
if (store[storePropName]) {
34+
rv = decode(store[storePropName]);
35+
}
36+
37+
return rv;
38+
}
39+
40+
static async setEncoded(propName: string, obj: unknown): Promise<void> {
41+
const storePropName = `${propName}_${storePropNameSufix}`;
42+
const encoded = encode(obj);
43+
const store = { [storePropName]: encoded };
44+
45+
await chrome.storage.local.set(store);
46+
}
47+
}
48+
49+
const storePropNameSufix = 'v2';
50+
51+
function encode(obj: unknown): string {
52+
const objStr = JSON.stringify(obj);
53+
const uint8 = pako.deflate(objStr);
54+
const rv = uint8ToString(uint8);
55+
56+
return rv;
57+
}
58+
59+
function decode(input: string): unknown {
60+
// Problem in input: char DCD4 -> becomes FFFD FFFD FFFD
61+
const uint8 = stringToUint8(input);
62+
const str = pako.inflate(uint8, { to: 'string' });
63+
const rv = JSON.parse(str);
64+
65+
return rv;
66+
}
67+
68+
export function uint8ToString(arr: Uint8Array): string {
69+
const N = arr.length;
70+
let encodedString = N % 2 === 0 ? '\x00' : '\x01';
71+
72+
for (let n = 0; n < N; n += 2) {
73+
const highOrderByte = arr[n];
74+
const lowOrderByte = n + 1 < N ? arr[n + 1] : 0x00;
75+
// Padding if odd number of elements
76+
77+
const combinedWord = (highOrderByte << 8) | lowOrderByte;
78+
encodedString += String.fromCharCode(combinedWord);
79+
}
80+
81+
return encodedString;
82+
}
83+
84+
function stringToUint8(str: string): Uint8Array {
85+
const isOddLength = str[0] === '\x01';
86+
const rv: number[] = [];
87+
const N = str.length;
88+
const last_n = N - 1;
89+
90+
for (let n = 1; n < N; n++) {
91+
const charCode = str.charCodeAt(n);
92+
const highOrderByte = charCode >> 8;
93+
const lowOrderByte = (charCode << 8) >> 8;
94+
95+
rv.push(highOrderByte);
96+
97+
if (n < last_n || !isOddLength) {
98+
rv.push(lowOrderByte);
99+
}
100+
}
101+
102+
return Uint8Array.from(rv);
103+
}

src/view/panel.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<button
2222
class="btn"
23-
title="Clear results"
23+
:title="`Clear results (${state.storagaSize})`"
2424
@click="onClearResults"
2525
v-text="'Clear'"
2626
/>
@@ -99,6 +99,7 @@ const state = reactive({
9999
now: appStartTimestamp,
100100
inprogress: false,
101101
lastError: '',
102+
storagaSize: 0,
102103
});
103104
const compare = ref<ICompareState>({
104105
timestamp: 0,
@@ -137,12 +138,16 @@ onMounted(async () => {
137138
]);
138139
139140
if (hasValue(lastApiReq)) {
140-
$_onDiffRequest(lastApiReq);
141+
$_onDiffRequest(lastApiReq as ICompareState);
141142
}
142143
143144
state.lastError = lastError || '';
145+
state.storagaSize = await chrome.storage.local.getBytesInUse();
144146
145147
chrome.runtime.onMessage.addListener($_onRuntimeMessage);
148+
chrome.storage.onChanged.addListener(async () => {
149+
state.storagaSize = await chrome.storage.local.getBytesInUse();
150+
});
146151
});
147152
148153
onUnmounted(() => {
@@ -190,7 +195,7 @@ async function $_onRuntimeMessage(req: TRuntimeMessageOptions) {
190195
const { lastApiReq } = await chrome.storage.local.get(['lastApiReq']);
191196
192197
if (hasValue(lastApiReq)) {
193-
$_onDiffRequest(lastApiReq);
198+
$_onDiffRequest(lastApiReq as ICompareState);
194199
}
195200
} else if (
196201
'jsdiff-devtools-to-panel-search' === req.source &&

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
}
2424
},
2525
"include": ["src"],
26-
"exclude": [".ts-built", "bundle"]
26+
"exclude": [".ts-built", "bundle", "**/~*.ts"]
2727
}

webpack.config.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CleanWebpackPlugin } from 'clean-webpack-plugin';
44
import { VueLoaderPlugin } from 'vue-loader';
55
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
66
import { fileURLToPath } from 'url';
7-
import TerserPlugin from 'terser-webpack-plugin';
7+
import { EsbuildPlugin } from 'esbuild-loader';
88

99
const __filename = fileURLToPath(import.meta.url);
1010
const __dirname = path.dirname(__filename);
@@ -42,10 +42,10 @@ export default function (
4242
plugins: [
4343
new CleanWebpackPlugin(),
4444
new VueLoaderPlugin(),
45-
// http://127.0.0.1:8888
4645
isProd
4746
? () => {}
4847
: new BundleAnalyzerPlugin({
48+
// http://127.0.0.1:8888
4949
openAnalyzer: false,
5050
logLevel: 'silent',
5151
}),
@@ -79,12 +79,7 @@ export default function (
7979
optimization: {
8080
splitChunks: false,
8181
minimize: isProd,
82-
minimizer: [
83-
new TerserPlugin({
84-
minify: TerserPlugin.esbuildMinify,
85-
terserOptions: {},
86-
}),
87-
],
82+
minimizer: [new EsbuildPlugin()],
8883
},
8984

9085
devtool: isProd ? false : 'source-map',

0 commit comments

Comments
 (0)