Skip to content

Commit

Permalink
feat: lower compilation target to es2015 (#957)
Browse files Browse the repository at this point in the history
## This PR

- replace the es2022 error cause with a custom implementation
- lower compilation target from es2022 to es2015

### Related Issues

Fixes #956

### Notes

The tests pass, but I still want to manually build and test the outputs
in a real application to ensure everything works as expected.

Signed-off-by: Michael Beemer <[email protected]>
  • Loading branch information
beeme1mr authored Jun 11, 2024
1 parent d202994 commit c2d6c17
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ node 16+, npm 8+ are recommended.

### Compilation Target(s)

We target `es2022`, and publish both ES-modules and CommonJS modules.
We target `es2015`, and publish both ES-modules and CommonJS modules.

### Installation and Dependencies

Expand Down
2 changes: 1 addition & 1 deletion packages/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

### Requirements

- ES2022-compatible web browser (Chrome, Edge, Firefox, etc)
- ES2015-compatible web browser (Chrome, Edge, Firefox, etc)

### Install

Expand Down
6 changes: 3 additions & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"test": "jest --verbose",
"lint": "eslint ./",
"clean": "shx rm -rf ./dist",
"build:web-esm": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2022 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
"build:web-cjs": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2022 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:web-esm": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2015 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
"build:web-cjs": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2015 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
"build": "npm run clean && npm run build:web-esm && npm run build:web-cjs && npm run build:rollup-types",
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
Expand Down Expand Up @@ -51,4 +51,4 @@
"devDependencies": {
"@openfeature/core": "1.2.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class InMemoryProvider implements Provider {
}
this._context = context;
} catch (err) {
throw new Error('initialization failure', { cause: err });
throw new GeneralError('initialization failure', { cause: err });
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"ES2022",
"ES2015",
"DOM"
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
Expand All @@ -24,7 +24,7 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "ES2022", /* Specify what module code is generated. */
"module": "ES2015", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down
6 changes: 3 additions & 3 deletions packages/nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"test": "jest --verbose",
"lint": "eslint ./",
"clean": "shx rm -rf ./dist",
"build:esm": "esbuild src/index.ts --bundle --external:@nestjs/* --external:@openfeature/server-sdk --sourcemap --target=es2022 --platform=node --format=esm --outfile=./dist/esm/index.js --analyze",
"build:cjs": "esbuild src/index.ts --bundle --external:@nestjs/* --external:@openfeature/server-sdk --sourcemap --target=es2022 --platform=node --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:esm": "esbuild src/index.ts --bundle --external:@nestjs/* --external:@openfeature/server-sdk --sourcemap --target=es2015 --platform=node --format=esm --outfile=./dist/esm/index.js --analyze",
"build:cjs": "esbuild src/index.ts --bundle --external:@nestjs/* --external:@openfeature/server-sdk --sourcemap --target=es2015 --platform=node --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:rollup-types",
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
Expand Down Expand Up @@ -60,4 +60,4 @@
"@types/supertest": "^6.0.0",
"supertest": "^7.0.0"
}
}
}
6 changes: 3 additions & 3 deletions packages/nest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ES2022",
"target": "ES2015",
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"ES2022"
"ES2015"
],
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
Expand All @@ -27,7 +27,7 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "ES2022",
"module": "ES2015",
/* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ In addition to the feature provided by the [web sdk](https://openfeature.dev/doc

### Requirements

- ES2022-compatible web browser (Chrome, Edge, Firefox, etc)
- ES2015-compatible web browser (Chrome, Edge, Firefox, etc)
- React version 16.8+

### Install
Expand Down
6 changes: 3 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"test": "jest --verbose",
"lint": "eslint ./",
"clean": "shx rm -rf ./dist",
"build:react-esm": "esbuild src/index.ts --bundle --external:react --external:@openfeature/web-sdk --sourcemap --target=es2022 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
"build:react-cjs": "esbuild src/index.ts --bundle --external:react --external:@openfeature/web-sdk --sourcemap --target=es2022 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:react-esm": "esbuild src/index.ts --bundle --external:react --external:@openfeature/web-sdk --sourcemap --target=es2015 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
"build:react-cjs": "esbuild src/index.ts --bundle --external:react --external:@openfeature/web-sdk --sourcemap --target=es2015 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
"build": "npm run clean && npm run build:react-esm && npm run build:react-cjs && npm run build:rollup-types",
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
Expand Down Expand Up @@ -53,4 +53,4 @@
"@openfeature/core": "*",
"@openfeature/web-sdk": "*"
}
}
}
6 changes: 3 additions & 3 deletions packages/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"ES2022",
"ES2015",
"DOM"
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
Expand All @@ -25,7 +25,7 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "ES2022", /* Specify what module code is generated. */
"module": "ES2015", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down
6 changes: 3 additions & 3 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"test": "jest --verbose",
"lint": "eslint ./",
"clean": "shx rm -rf ./dist",
"build:esm": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2022 --platform=node --format=esm --outfile=./dist/esm/index.js --analyze",
"build:cjs": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2022 --platform=node --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:esm": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2015 --platform=node --format=esm --outfile=./dist/esm/index.js --analyze",
"build:cjs": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2015 --platform=node --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:rollup-types",
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
Expand Down Expand Up @@ -53,4 +53,4 @@
"devDependencies": {
"@openfeature/core": "1.2.0"
}
}
}
6 changes: 3 additions & 3 deletions packages/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"ES2022",
"ES2015",
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
Expand All @@ -23,7 +23,7 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "ES2022", /* Specify what module code is generated. */
"module": "ES2015", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"lint": "eslint ./",
"clean": "shx rm -rf ./dist",
"type": "tsc --project ./tsconfig.json --declaration --emitDeclarationOnly",
"build:esm": "esbuild src/index.ts --bundle --external:events --sourcemap --target=es2022 --format=esm --outfile=./dist/esm/index.js --analyze",
"build:cjs": "esbuild src/index.ts --bundle --external:events --sourcemap --target=es2022 --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:esm": "esbuild src/index.ts --bundle --external:events --sourcemap --target=es2015 --format=esm --outfile=./dist/esm/index.js --analyze",
"build:cjs": "esbuild src/index.ts --bundle --external:events --sourcemap --target=es2015 --format=cjs --outfile=./dist/cjs/index.js --analyze",
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:rollup-types",
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
Expand All @@ -45,4 +45,4 @@
"flags",
"toggles"
]
}
}
2 changes: 1 addition & 1 deletion packages/shared/src/errors/flag-not-found-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenFeatureError } from './open-feature-error-abstract';
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
import { ErrorCode } from '../evaluation';

export class FlagNotFoundError extends OpenFeatureError {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/errors/general-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenFeatureError } from './open-feature-error-abstract';
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
import { ErrorCode } from '../evaluation';

export class GeneralError extends OpenFeatureError {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/errors/invalid-context-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenFeatureError } from './open-feature-error-abstract';
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
import { ErrorCode } from '../evaluation';

export class InvalidContextError extends OpenFeatureError {
Expand Down
12 changes: 11 additions & 1 deletion packages/shared/src/errors/open-feature-error-abstract.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { ErrorCode } from '../evaluation';

/**
* Error Options were added in ES2022. Manually adding the type so that an
* earlier target can be used.
*/
export type ErrorOptions = {
cause?: unknown
};

export abstract class OpenFeatureError extends Error {
abstract code: ErrorCode;
cause?: unknown;
constructor(message?: string, options?: ErrorOptions) {
super(message, options);
super(message);
Object.setPrototypeOf(this, OpenFeatureError.prototype);
this.name = 'OpenFeatureError';
this.cause = options?.cause;
}
}
2 changes: 1 addition & 1 deletion packages/shared/src/errors/parse-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenFeatureError } from './open-feature-error-abstract';
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
import { ErrorCode } from '../evaluation';

export class ParseError extends OpenFeatureError {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/errors/provider-fatal-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenFeatureError } from './open-feature-error-abstract';
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
import { ErrorCode } from '../evaluation';

export class ProviderFatalError extends OpenFeatureError {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/errors/provider-not-ready-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenFeatureError } from './open-feature-error-abstract';
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
import { ErrorCode } from '../evaluation';

export class ProviderNotReadyError extends OpenFeatureError {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/errors/targeting-key-missing-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenFeatureError } from './open-feature-error-abstract';
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
import { ErrorCode } from '../evaluation';

export class TargetingKeyMissingError extends OpenFeatureError {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/errors/type-mismatch-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OpenFeatureError } from './open-feature-error-abstract';
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
import { ErrorCode } from '../evaluation';

export class TypeMismatchError extends OpenFeatureError {
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"ES2022"
"ES2015"
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
Expand All @@ -23,7 +23,7 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "ES2022", /* Specify what module code is generated. */
"module": "ES2015", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"ES2022",
"ES2015",
"DOM"
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
Expand All @@ -24,7 +24,7 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "ES2022", /* Specify what module code is generated. */
"module": "ES2015", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down

0 comments on commit c2d6c17

Please sign in to comment.