Skip to content

Commit

Permalink
fix(javascript): add class-proposal plugin for client-common (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Jun 29, 2022
1 parent bf82d9e commit 77c80e2
Show file tree
Hide file tree
Showing 8 changed files with 789 additions and 452 deletions.
20 changes: 10 additions & 10 deletions clients/algoliasearch-client-javascript/bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
"files": [
{
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
"maxSize": "7.80KB"
"maxSize": "7.85KB"
},
{
"path": "packages/algoliasearch/dist/lite/lite.umd.js",
"maxSize": "3.80KB"
"maxSize": "3.85KB"
},
{
"path": "packages/client-abtesting/dist/client-abtesting.umd.js",
"maxSize": "3.95KB"
"maxSize": "4.00KB"
},
{
"path": "packages/client-analytics/dist/client-analytics.umd.js",
"maxSize": "4.55KB"
"maxSize": "4.60KB"
},
{
"path": "packages/client-insights/dist/client-insights.umd.js",
"maxSize": "3.75KB"
"maxSize": "3.85KB"
},
{
"path": "packages/client-personalization/dist/client-personalization.umd.js",
"maxSize": "3.95KB"
"maxSize": "4.00KB"
},
{
"path": "packages/client-query-suggestions/dist/client-query-suggestions.umd.js",
"maxSize": "4.00KB"
"maxSize": "4.05KB"
},
{
"path": "packages/client-search/dist/client-search.umd.js",
"maxSize": "6.55KB"
"maxSize": "6.65KB"
},
{
"path": "packages/client-sources/dist/client-sources.umd.js",
"maxSize": "3.80KB"
"maxSize": "3.85KB"
},
{
"path": "packages/recommend/dist/recommend.umd.js",
"maxSize": "3.80KB"
"maxSize": "3.85KB"
}
]
}
10 changes: 5 additions & 5 deletions clients/algoliasearch-client-javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"test:types": "yarn tsc --noEmit"
},
"devDependencies": {
"@babel/core": "7.18.5",
"@babel/plugin-proposal-class-properties": "7.17.12",
"@babel/plugin-transform-runtime": "7.18.5",
"@babel/preset-env": "7.18.2",
"@babel/runtime": "7.18.3",
"@babel/core": "7.18.6",
"@babel/plugin-proposal-class-properties": "7.18.6",
"@babel/plugin-transform-runtime": "7.18.6",
"@babel/preset-env": "7.18.6",
"@babel/runtime": "7.18.6",
"@rollup/plugin-babel": "5.3.1",
"@rollup/plugin-node-resolve": "13.3.0",
"@types/jest": "28.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@types/node": "16.11.41",
"jest": "28.1.1",
"jest-environment-jsdom": "28.1.1",
"ts-jest": "28.0.5",
"typescript": "4.7.4"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import type { Response, StackFrame } from '../types';

class ErrorWithStackTrace extends Error {
stackTrace: StackFrame[];
export class AlgoliaError extends Error {
name: string;

constructor(message: string, stackTrace: StackFrame[]) {
constructor(message: string, name: string) {
super(message);
this.name = name ?? 'AlgoliaError';
}
}

export class ErrorWithStackTrace extends AlgoliaError {
stackTrace: StackFrame[];

constructor(message: string, stackTrace: StackFrame[], name: string) {
super(message, name);
// the array and object should be frozen to reflect the stackTrace at the time of the error
this.stackTrace = stackTrace;
}
Expand All @@ -14,7 +23,8 @@ export class RetryError extends ErrorWithStackTrace {
constructor(stackTrace: StackFrame[]) {
super(
'Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.',
stackTrace
stackTrace,
'RetryError'
);
}
}
Expand All @@ -23,16 +33,16 @@ export class ApiError extends ErrorWithStackTrace {
status: number;

constructor(message: string, status: number, stackTrace: StackFrame[]) {
super(message, stackTrace);
super(message, stackTrace, 'ApiError');
this.status = status;
}
}

export class DeserializationError extends Error {
export class DeserializationError extends AlgoliaError {
response: Response;

constructor(message: string, response: Response) {
super(message);
super(message, 'DeserializationError');
this.response = response;
}
}
13 changes: 13 additions & 0 deletions clients/algoliasearch-client-javascript/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ packageConfigs.forEach((packageConfig) => {
];
}

const clientCommonPlugins =
packageConfig.package === 'client-common'
? [
babel({
babelrc: false,
extensions: ['.ts'],
exclude: 'node_modules/**',
plugins: ['@babel/plugin-proposal-class-properties'],
}),
]
: [];

rollupConfig.push({
input: path.resolve(clientPath, packageConfig.input),
external: [...packageConfig.dependencies, ...packageConfig.external],
Expand All @@ -101,6 +113,7 @@ packageConfigs.forEach((packageConfig) => {
}),
...umdConfig.transpilerPlugins,
...umdConfig.compressorPlugins,
...clientCommonPlugins,
],
output: bundlers[format],
onwarn(msg, warn) {
Expand Down
Loading

0 comments on commit 77c80e2

Please sign in to comment.