Skip to content

Commit 28e5f04

Browse files
authored
Merge pull request #110 from codex-team/migrate-vite
chore(build): migrate to vite
2 parents a244804 + e4e9e00 commit 28e5f04

19 files changed

+2339
-5742
lines changed

.eslintrc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
browser: true,
66
},
77
rules: {
8-
"@typescript-eslint/no-magic-numbers": "off"
9-
}
8+
'@typescript-eslint/no-magic-numbers': 'off',
9+
'@typescript-eslint/strict-boolean-expressions': 'off',
10+
},
1011
};

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88
CI_JOB_NUMBER: 1
99
steps:
1010
- uses: actions/checkout@v1
11-
- name: Use Node.js 16.x
11+
- name: Use Node.js 20.x
1212
uses: actions/setup-node@v1
1313
with:
14-
node-version: 16.x
14+
node-version: 20.x
1515
- run: yarn install
1616
- run: yarn lint-test
1717

@@ -21,9 +21,9 @@ jobs:
2121
CI_JOB_NUMBER: 2
2222
steps:
2323
- uses: actions/checkout@v1
24-
- name: Use Node.js 16.x
24+
- name: Use Node.js 20.x
2525
uses: actions/setup-node@v1
2626
with:
27-
node-version: 16.x
27+
node-version: 20.x
2828
- run: yarn install
2929
- run: yarn build

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v2
1313
- uses: actions/setup-node@v1
1414
with:
15-
node-version: 16
15+
node-version: 20
1616
registry-url: https://registry.npmjs.org/
1717
- run: yarn
1818
- run: yarn lint-test

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.18.0

package.json

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22
"name": "@hawk.so/javascript",
33
"version": "3.0.9",
44
"description": "JavaScript errors tracking for Hawk.so",
5-
"main": "./dist/hawk.js",
6-
"types": "./dist/index.d.ts",
5+
"files": [
6+
"dist"
7+
],
8+
"main": "./dist/hawk.umd.js",
9+
"module": "./dist/hawk.mjs",
10+
"types": "dist/index.d.ts",
11+
"exports": {
12+
".": {
13+
"types": "./dist/index.d.ts",
14+
"import": "./dist/hawk.mjs",
15+
"require": "./dist/hawk.umd.js"
16+
}
17+
},
718
"scripts": {
8-
"dev": "webpack-dev-server --config ./webpack.config.dev.js",
9-
"build": "webpack && yarn stats",
10-
"size-build": "webpack && yarn stats",
19+
"dev": "vite",
20+
"build": "vite build",
1121
"stats": "size-limit > stats.txt",
1222
"lint": "eslint -c ./.eslintrc.js src/ --ext .ts,.js --fix",
1323
"lint-test": "eslint -c ./.eslintrc.js src/ --ext .ts,.js"
@@ -26,24 +36,18 @@
2636
},
2737
"homepage": "https://github.com/codex-team/hawk.javascript#readme",
2838
"devDependencies": {
29-
"@babel/core": "^7.9.6",
30-
"@babel/plugin-transform-async-to-generator": "^7.8.3",
31-
"@babel/preset-env": "^7.9.6",
32-
"@size-limit/preset-small-lib": "^4.5.0",
33-
"babel-loader": "^8.1.0",
39+
"@size-limit/preset-small-lib": "^11.1.6",
3440
"eslint": "^7.24.0",
3541
"eslint-config-codex": "^1.6.1",
36-
"regenerator-runtime": "^0.13.5",
37-
"size-limit": "^4.5.0",
38-
"ts-loader": "^7.0.3",
39-
"typescript": "^3.8.3",
40-
"webpack": "^4.43.0",
41-
"webpack-cli": "^3.3.11",
42-
"webpack-dev-server": "^3.11.0",
43-
"webpack-merge": "^4.2.1"
42+
"rollup-plugin-license": "^3.5.3",
43+
"size-limit": "^11.1.6",
44+
"typescript": "^5.6.3",
45+
"vite": "^5.4.9",
46+
"vue": "^2"
4447
},
4548
"dependencies": {
46-
"@hawk.so/types": "^0.1.13",
47-
"error-stack-parser": "^2.0.6"
49+
"@hawk.so/types": "^0.1.20",
50+
"error-stack-parser": "^2.1.4",
51+
"vite-plugin-dts": "^4.2.4"
4852
}
4953
}

src/catcher.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ import Socket from './modules/socket';
22
import Sanitizer from './modules/sanitizer';
33
import log from './modules/logger';
44
import StackParser from './modules/stackParser';
5-
import { HawkInitialSettings } from './types/hawk-initial-settings';
6-
import CatcherMessage from './types/catcher-message';
5+
import type { CatcherMessage, HawkInitialSettings } from '@/types';
76
import { VueIntegration } from './integrations/vue';
87
import { generateRandomId } from './utils';
9-
import {
8+
import type {
109
AffectedUser,
1110
EventContext,
1211
JavaScriptAddons,
1312
VueIntegrationAddons,
1413
Json, EncodedIntegrationToken, DecodedIntegrationToken
1514
} from '@hawk.so/types';
16-
import { JavaScriptCatcherIntegrations } from './types/integrations';
15+
import type { JavaScriptCatcherIntegrations } from './types/integrations';
1716
import { EventRejectedError } from './errors';
1817
import type { HawkJavaScriptEvent } from './types';
1918

@@ -52,7 +51,7 @@ export default class Catcher {
5251
/**
5352
* Current bundle version
5453
*/
55-
private readonly release: string;
54+
private readonly release: string | undefined;
5655

5756
/**
5857
* Current authenticated user
@@ -62,13 +61,13 @@ export default class Catcher {
6261
/**
6362
* Any additional data passed by user for sending with all messages
6463
*/
65-
private readonly context: EventContext;
64+
private readonly context: EventContext | undefined;
6665

6766
/**
6867
* This Method allows developer to filter any data you don't want sending to Hawk
6968
* If method returns false, event will not be sent
7069
*/
71-
private readonly beforeSend: (event: HawkJavaScriptEvent) => HawkJavaScriptEvent | false;
70+
private readonly beforeSend: undefined | ((event: HawkJavaScriptEvent) => HawkJavaScriptEvent | false);
7271

7372
/**
7473
* Transport for dialog between Catcher and Collector
@@ -180,7 +179,7 @@ export default class Catcher {
180179
* @param [context] - any additional data to send
181180
*/
182181
public send(message: Error | string, context?: EventContext): void {
183-
this.formatAndSend(message, undefined, context);
182+
void this.formatAndSend(message, undefined, context);
184183
}
185184

186185
/**
@@ -191,7 +190,7 @@ export default class Catcher {
191190
public connectVue(vue): void {
192191
// eslint-disable-next-line no-new
193192
new VueIntegration(vue, (error: Error, addons: VueIntegrationAddons) => {
194-
this.formatAndSend(error, {
193+
void this.formatAndSend(error, {
195194
vue: addons,
196195
});
197196
}, {
@@ -229,7 +228,7 @@ export default class Catcher {
229228
error = (event as ErrorEvent).message;
230229
}
231230

232-
this.formatAndSend(error);
231+
void this.formatAndSend(error);
233232
}
234233

235234
/**
@@ -492,18 +491,16 @@ export default class Catcher {
492491
*
493492
* @param {Error|string} error — caught error
494493
*/
495-
private getRawData(error: Error | string): Json {
496-
let errorData = null;
497-
498-
if (error instanceof Error) {
499-
errorData = {
500-
name: error.name,
501-
message: error.message,
502-
stack: error.stack,
503-
};
494+
private getRawData(error: Error | string): Json | undefined {
495+
if (!(error instanceof Error)) {
496+
return;
504497
}
505498

506-
return errorData;
499+
return {
500+
name: error.name,
501+
message: error.message,
502+
stack: error.stack ?? '',
503+
};
507504
}
508505

509506
/**

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import 'regenerator-runtime/runtime';
21
import Catcher from './catcher';
3-
export { AffectedUser } from '@hawk.so/types';
2+
export type { AffectedUser } from '@hawk.so/types';
43
export * from './types';
54

65
export default Catcher;

src/integrations/vue.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Sanitizer from './../modules/sanitizer';
2-
import { VueIntegrationAddons } from '@hawk.so/types';
2+
import type { VueIntegrationAddons } from '@hawk.so/types';
33

44
interface VueIntegrationOptions {
55
/**
@@ -31,7 +31,7 @@ export class VueIntegration {
3131
* Callback that should be triggered with caught error.
3232
* This callback is used by parent class to format and send an event.
3333
*/
34-
private readonly callback: (error: Error, addons: {[key: string]: any}) => void;
34+
private readonly callback: (error: Error, addons: VueIntegrationAddons) => void;
3535

3636
/**
3737
* Set up a new vue app
@@ -63,7 +63,7 @@ export class VueIntegration {
6363
* @param vm - vue VM
6464
* @param info - a Vue-specific error info, e.g. which lifecycle hook the error was found in.
6565
*/
66-
(err: Error, vm: { [key: string]: any }, info: string): void => {
66+
(err: Error, vm: {[key: string]: unknown}, info: string): void => {
6767
if (typeof this.existedHandler === 'function') {
6868
this.existedHandler.call(this.vue, err, vm, info);
6969
}
@@ -82,7 +82,8 @@ export class VueIntegration {
8282
* @param vm - vue VM
8383
* @param info - a Vue-specific error info, e.g. which lifecycle hook the error was found in.
8484
*/
85-
private spoilAddons(vm: {[key: string]: any}, info: string): VueIntegrationAddons {
85+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
86+
private spoilAddons(vm: { [key: string]: any }, info: string): VueIntegrationAddons {
8687
const addons: VueIntegrationAddons = {
8788
lifecycle: info,
8889
component: null,
@@ -111,7 +112,7 @@ export class VueIntegration {
111112
addons.data = {};
112113

113114
Object.entries(vm._data).forEach(([key, value]) => {
114-
addons.data[key] = Sanitizer.sanitize(value);
115+
addons.data![key] = Sanitizer.sanitize(value);
115116
});
116117
}
117118

@@ -122,7 +123,8 @@ export class VueIntegration {
122123
addons.computed = {};
123124

124125
Object.entries(vm._computedWatchers).forEach(([key, watcher]) => {
125-
addons.computed[key] = Sanitizer.sanitize((watcher as {[key: string]: any}).value);
126+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
127+
addons.computed![key] = Sanitizer.sanitize((watcher as {[key: string]: any}).value);
126128
});
127129
}
128130

@@ -136,7 +138,13 @@ export class VueIntegration {
136138
* @param info - a Vue-specific error info, e.g. which lifecycle hook the error was found in.
137139
* @param component - where error was occurred
138140
*/
139-
private printError(err: Error, info: string, component: string): void {
141+
private printError(err: Error, info: string, component: string | null): void {
142+
if (component === null) {
143+
console.error(`${info}`, err);
144+
145+
return;
146+
}
147+
140148
console.error(`${component} @ ${info}`, err);
141149
}
142150
}

src/modules/socket.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import log from './logger';
2-
import CatcherMessage from '../types/catcher-message';
2+
import type { CatcherMessage } from '@/types';
33

44
/**
55
* Custom WebSocket wrapper class
@@ -36,7 +36,7 @@ export default class Socket {
3636
/**
3737
* Websocket instance
3838
*/
39-
private ws: WebSocket;
39+
private ws: WebSocket | null;
4040

4141
/**
4242
* Reconnection tryings Timeout
@@ -60,7 +60,7 @@ export default class Socket {
6060
*/
6161
constructor({
6262
collectorEndpoint,
63-
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars, @typescript-eslint/no-unused-vars-experimental,no-unused-vars
63+
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
6464
onMessage = (message: MessageEvent): void => {},
6565
// eslint-disable-next-line @typescript-eslint/no-empty-function
6666
onClose = (): void => {},
@@ -187,7 +187,7 @@ export default class Socket {
187187
}
188188

189189
this.reconnectionTimer = setTimeout(() => {
190-
this.reconnect(true);
190+
void this.reconnect(true);
191191
}, this.reconnectionTimeout);
192192
}
193193
}
@@ -197,7 +197,13 @@ export default class Socket {
197197
*/
198198
private sendQueue(): void {
199199
while (this.eventsQueue.length) {
200-
this.send(this.eventsQueue.shift())
200+
const event = this.eventsQueue.shift();
201+
202+
if (!event) {
203+
continue;
204+
}
205+
206+
this.send(event)
201207
.catch((sendingError) => {
202208
log('WebSocket sending error', 'error', sendingError);
203209
});

0 commit comments

Comments
 (0)