Skip to content

Commit 77c80e2

Browse files
authored
fix(javascript): add class-proposal plugin for client-common (#765)
1 parent bf82d9e commit 77c80e2

File tree

8 files changed

+789
-452
lines changed

8 files changed

+789
-452
lines changed

clients/algoliasearch-client-javascript/bundlesize.config.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@
22
"files": [
33
{
44
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
5-
"maxSize": "7.80KB"
5+
"maxSize": "7.85KB"
66
},
77
{
88
"path": "packages/algoliasearch/dist/lite/lite.umd.js",
9-
"maxSize": "3.80KB"
9+
"maxSize": "3.85KB"
1010
},
1111
{
1212
"path": "packages/client-abtesting/dist/client-abtesting.umd.js",
13-
"maxSize": "3.95KB"
13+
"maxSize": "4.00KB"
1414
},
1515
{
1616
"path": "packages/client-analytics/dist/client-analytics.umd.js",
17-
"maxSize": "4.55KB"
17+
"maxSize": "4.60KB"
1818
},
1919
{
2020
"path": "packages/client-insights/dist/client-insights.umd.js",
21-
"maxSize": "3.75KB"
21+
"maxSize": "3.85KB"
2222
},
2323
{
2424
"path": "packages/client-personalization/dist/client-personalization.umd.js",
25-
"maxSize": "3.95KB"
25+
"maxSize": "4.00KB"
2626
},
2727
{
2828
"path": "packages/client-query-suggestions/dist/client-query-suggestions.umd.js",
29-
"maxSize": "4.00KB"
29+
"maxSize": "4.05KB"
3030
},
3131
{
3232
"path": "packages/client-search/dist/client-search.umd.js",
33-
"maxSize": "6.55KB"
33+
"maxSize": "6.65KB"
3434
},
3535
{
3636
"path": "packages/client-sources/dist/client-sources.umd.js",
37-
"maxSize": "3.80KB"
37+
"maxSize": "3.85KB"
3838
},
3939
{
4040
"path": "packages/recommend/dist/recommend.umd.js",
41-
"maxSize": "3.80KB"
41+
"maxSize": "3.85KB"
4242
}
4343
]
4444
}

clients/algoliasearch-client-javascript/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"test:types": "yarn tsc --noEmit"
1818
},
1919
"devDependencies": {
20-
"@babel/core": "7.18.5",
21-
"@babel/plugin-proposal-class-properties": "7.17.12",
22-
"@babel/plugin-transform-runtime": "7.18.5",
23-
"@babel/preset-env": "7.18.2",
24-
"@babel/runtime": "7.18.3",
20+
"@babel/core": "7.18.6",
21+
"@babel/plugin-proposal-class-properties": "7.18.6",
22+
"@babel/plugin-transform-runtime": "7.18.6",
23+
"@babel/preset-env": "7.18.6",
24+
"@babel/runtime": "7.18.6",
2525
"@rollup/plugin-babel": "5.3.1",
2626
"@rollup/plugin-node-resolve": "13.3.0",
2727
"@types/jest": "28.1.3",

clients/algoliasearch-client-javascript/packages/client-common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@types/node": "16.11.41",
2323
"jest": "28.1.1",
2424
"jest-environment-jsdom": "28.1.1",
25+
"ts-jest": "28.0.5",
2526
"typescript": "4.7.4"
2627
},
2728
"engines": {
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import type { Response, StackFrame } from '../types';
22

3-
class ErrorWithStackTrace extends Error {
4-
stackTrace: StackFrame[];
3+
export class AlgoliaError extends Error {
4+
name: string;
55

6-
constructor(message: string, stackTrace: StackFrame[]) {
6+
constructor(message: string, name: string) {
77
super(message);
8+
this.name = name ?? 'AlgoliaError';
9+
}
10+
}
11+
12+
export class ErrorWithStackTrace extends AlgoliaError {
13+
stackTrace: StackFrame[];
14+
15+
constructor(message: string, stackTrace: StackFrame[], name: string) {
16+
super(message, name);
817
// the array and object should be frozen to reflect the stackTrace at the time of the error
918
this.stackTrace = stackTrace;
1019
}
@@ -14,7 +23,8 @@ export class RetryError extends ErrorWithStackTrace {
1423
constructor(stackTrace: StackFrame[]) {
1524
super(
1625
'Unreachable hosts - your application id may be incorrect. If the error persists, contact [email protected].',
17-
stackTrace
26+
stackTrace,
27+
'RetryError'
1828
);
1929
}
2030
}
@@ -23,16 +33,16 @@ export class ApiError extends ErrorWithStackTrace {
2333
status: number;
2434

2535
constructor(message: string, status: number, stackTrace: StackFrame[]) {
26-
super(message, stackTrace);
36+
super(message, stackTrace, 'ApiError');
2737
this.status = status;
2838
}
2939
}
3040

31-
export class DeserializationError extends Error {
41+
export class DeserializationError extends AlgoliaError {
3242
response: Response;
3343

3444
constructor(message: string, response: Response) {
35-
super(message);
45+
super(message, 'DeserializationError');
3646
this.response = response;
3747
}
3848
}

clients/algoliasearch-client-javascript/rollup.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ packageConfigs.forEach((packageConfig) => {
8080
];
8181
}
8282

83+
const clientCommonPlugins =
84+
packageConfig.package === 'client-common'
85+
? [
86+
babel({
87+
babelrc: false,
88+
extensions: ['.ts'],
89+
exclude: 'node_modules/**',
90+
plugins: ['@babel/plugin-proposal-class-properties'],
91+
}),
92+
]
93+
: [];
94+
8395
rollupConfig.push({
8496
input: path.resolve(clientPath, packageConfig.input),
8597
external: [...packageConfig.dependencies, ...packageConfig.external],
@@ -101,6 +113,7 @@ packageConfigs.forEach((packageConfig) => {
101113
}),
102114
...umdConfig.transpilerPlugins,
103115
...umdConfig.compressorPlugins,
116+
...clientCommonPlugins,
104117
],
105118
output: bundlers[format],
106119
onwarn(msg, warn) {

0 commit comments

Comments
 (0)