Skip to content

Commit c2d6c17

Browse files
authored
feat: lower compilation target to es2015 (#957)
## 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]>
1 parent d202994 commit c2d6c17

24 files changed

+56
-46
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ node 16+, npm 8+ are recommended.
88

99
### Compilation Target(s)
1010

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

1313
### Installation and Dependencies
1414

packages/client/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
### Requirements
4646

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

4949
### Install
5050

packages/client/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"test": "jest --verbose",
1818
"lint": "eslint ./",
1919
"clean": "shx rm -rf ./dist",
20-
"build:web-esm": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2022 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
21-
"build:web-cjs": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2022 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
20+
"build:web-esm": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2015 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
21+
"build:web-cjs": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2015 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
2222
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
2323
"build": "npm run clean && npm run build:web-esm && npm run build:web-cjs && npm run build:rollup-types",
2424
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
@@ -51,4 +51,4 @@
5151
"devDependencies": {
5252
"@openfeature/core": "1.2.0"
5353
}
54-
}
54+
}

packages/client/src/provider/in-memory-provider/in-memory-provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class InMemoryProvider implements Provider {
3838
}
3939
this._context = context;
4040
} catch (err) {
41-
throw new Error('initialization failure', { cause: err });
41+
throw new GeneralError('initialization failure', { cause: err });
4242
}
4343
}
4444

packages/client/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
1010
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1111
/* Language and Environment */
12-
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
12+
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1313
"lib": [
14-
"ES2022",
14+
"ES2015",
1515
"DOM"
1616
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1717
// "jsx": "preserve", /* Specify what JSX code is generated. */
@@ -24,7 +24,7 @@
2424
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2525
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2626
/* Modules */
27-
"module": "ES2022", /* Specify what module code is generated. */
27+
"module": "ES2015", /* Specify what module code is generated. */
2828
// "rootDir": "./", /* Specify the root folder within your source files. */
2929
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
3030
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */

packages/nest/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"test": "jest --verbose",
1818
"lint": "eslint ./",
1919
"clean": "shx rm -rf ./dist",
20-
"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",
21-
"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",
20+
"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",
21+
"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",
2222
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
2323
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:rollup-types",
2424
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
@@ -60,4 +60,4 @@
6060
"@types/supertest": "^6.0.0",
6161
"supertest": "^7.0.0"
6262
}
63-
}
63+
}

packages/nest/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
1010
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1111
/* Language and Environment */
12-
"target": "ES2022",
12+
"target": "ES2015",
1313
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1414
"lib": [
15-
"ES2022"
15+
"ES2015"
1616
],
1717
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
1818
// "jsx": "preserve", /* Specify what JSX code is generated. */
@@ -27,7 +27,7 @@
2727
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2828
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2929
/* Modules */
30-
"module": "ES2022",
30+
"module": "ES2015",
3131
/* Specify what module code is generated. */
3232
// "rootDir": "./", /* Specify the root folder within your source files. */
3333
"moduleResolution": "node",

packages/react/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ In addition to the feature provided by the [web sdk](https://openfeature.dev/doc
6161

6262
### Requirements
6363

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

6767
### Install

packages/react/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"test": "jest --verbose",
1818
"lint": "eslint ./",
1919
"clean": "shx rm -rf ./dist",
20-
"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",
21-
"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",
20+
"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",
21+
"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",
2222
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
2323
"build": "npm run clean && npm run build:react-esm && npm run build:react-cjs && npm run build:rollup-types",
2424
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
@@ -53,4 +53,4 @@
5353
"@openfeature/core": "*",
5454
"@openfeature/web-sdk": "*"
5555
}
56-
}
56+
}

packages/react/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212
/* Language and Environment */
13-
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
13+
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1414
"lib": [
15-
"ES2022",
15+
"ES2015",
1616
"DOM"
1717
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1818
// "jsx": "preserve", /* Specify what JSX code is generated. */
@@ -25,7 +25,7 @@
2525
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2626
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2727
/* Modules */
28-
"module": "ES2022", /* Specify what module code is generated. */
28+
"module": "ES2015", /* Specify what module code is generated. */
2929
// "rootDir": "./", /* Specify the root folder within your source files. */
3030
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
3131
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */

packages/server/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"test": "jest --verbose",
1818
"lint": "eslint ./",
1919
"clean": "shx rm -rf ./dist",
20-
"build:esm": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2022 --platform=node --format=esm --outfile=./dist/esm/index.js --analyze",
21-
"build:cjs": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2022 --platform=node --format=cjs --outfile=./dist/cjs/index.js --analyze",
20+
"build:esm": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2015 --platform=node --format=esm --outfile=./dist/esm/index.js --analyze",
21+
"build:cjs": "esbuild src/index.ts --bundle --external:@openfeature/core --sourcemap --target=es2015 --platform=node --format=cjs --outfile=./dist/cjs/index.js --analyze",
2222
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
2323
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:rollup-types",
2424
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
@@ -53,4 +53,4 @@
5353
"devDependencies": {
5454
"@openfeature/core": "1.2.0"
5555
}
56-
}
56+
}

packages/server/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
1010
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1111
/* Language and Environment */
12-
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
12+
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1313
"lib": [
14-
"ES2022",
14+
"ES2015",
1515
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@@ -23,7 +23,7 @@
2323
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2424
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2525
/* Modules */
26-
"module": "ES2022", /* Specify what module code is generated. */
26+
"module": "ES2015", /* Specify what module code is generated. */
2727
// "rootDir": "./", /* Specify the root folder within your source files. */
2828
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
2929
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */

packages/shared/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"lint": "eslint ./",
2020
"clean": "shx rm -rf ./dist",
2121
"type": "tsc --project ./tsconfig.json --declaration --emitDeclarationOnly",
22-
"build:esm": "esbuild src/index.ts --bundle --external:events --sourcemap --target=es2022 --format=esm --outfile=./dist/esm/index.js --analyze",
23-
"build:cjs": "esbuild src/index.ts --bundle --external:events --sourcemap --target=es2022 --format=cjs --outfile=./dist/cjs/index.js --analyze",
22+
"build:esm": "esbuild src/index.ts --bundle --external:events --sourcemap --target=es2015 --format=esm --outfile=./dist/esm/index.js --analyze",
23+
"build:cjs": "esbuild src/index.ts --bundle --external:events --sourcemap --target=es2015 --format=cjs --outfile=./dist/cjs/index.js --analyze",
2424
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
2525
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:rollup-types",
2626
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
@@ -45,4 +45,4 @@
4545
"flags",
4646
"toggles"
4747
]
48-
}
48+
}

packages/shared/src/errors/flag-not-found-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeatureError } from './open-feature-error-abstract';
1+
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
22
import { ErrorCode } from '../evaluation';
33

44
export class FlagNotFoundError extends OpenFeatureError {

packages/shared/src/errors/general-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeatureError } from './open-feature-error-abstract';
1+
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
22
import { ErrorCode } from '../evaluation';
33

44
export class GeneralError extends OpenFeatureError {

packages/shared/src/errors/invalid-context-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeatureError } from './open-feature-error-abstract';
1+
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
22
import { ErrorCode } from '../evaluation';
33

44
export class InvalidContextError extends OpenFeatureError {
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import { ErrorCode } from '../evaluation';
22

3+
/**
4+
* Error Options were added in ES2022. Manually adding the type so that an
5+
* earlier target can be used.
6+
*/
7+
export type ErrorOptions = {
8+
cause?: unknown
9+
};
10+
311
export abstract class OpenFeatureError extends Error {
412
abstract code: ErrorCode;
13+
cause?: unknown;
514
constructor(message?: string, options?: ErrorOptions) {
6-
super(message, options);
15+
super(message);
716
Object.setPrototypeOf(this, OpenFeatureError.prototype);
817
this.name = 'OpenFeatureError';
18+
this.cause = options?.cause;
919
}
1020
}

packages/shared/src/errors/parse-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeatureError } from './open-feature-error-abstract';
1+
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
22
import { ErrorCode } from '../evaluation';
33

44
export class ParseError extends OpenFeatureError {

packages/shared/src/errors/provider-fatal-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeatureError } from './open-feature-error-abstract';
1+
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
22
import { ErrorCode } from '../evaluation';
33

44
export class ProviderFatalError extends OpenFeatureError {

packages/shared/src/errors/provider-not-ready-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeatureError } from './open-feature-error-abstract';
1+
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
22
import { ErrorCode } from '../evaluation';
33

44
export class ProviderNotReadyError extends OpenFeatureError {

packages/shared/src/errors/targeting-key-missing-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeatureError } from './open-feature-error-abstract';
1+
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
22
import { ErrorCode } from '../evaluation';
33

44
export class TargetingKeyMissingError extends OpenFeatureError {

packages/shared/src/errors/type-mismatch-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeatureError } from './open-feature-error-abstract';
1+
import { ErrorOptions, OpenFeatureError } from './open-feature-error-abstract';
22
import { ErrorCode } from '../evaluation';
33

44
export class TypeMismatchError extends OpenFeatureError {

packages/shared/tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
1010
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1111
/* Language and Environment */
12-
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
12+
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1313
"lib": [
14-
"ES2022"
14+
"ES2015"
1515
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@@ -23,7 +23,7 @@
2323
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2424
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2525
/* Modules */
26-
"module": "ES2022", /* Specify what module code is generated. */
26+
"module": "ES2015", /* Specify what module code is generated. */
2727
// "rootDir": "./", /* Specify the root folder within your source files. */
2828
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
2929
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */

tsconfig.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
1010
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1111
/* Language and Environment */
12-
"target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
12+
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1313
"lib": [
14-
"ES2022",
14+
"ES2015",
1515
"DOM"
1616
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1717
// "jsx": "preserve", /* Specify what JSX code is generated. */
@@ -24,7 +24,7 @@
2424
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2525
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
2626
/* Modules */
27-
"module": "ES2022", /* Specify what module code is generated. */
27+
"module": "ES2015", /* Specify what module code is generated. */
2828
// "rootDir": "./", /* Specify the root folder within your source files. */
2929
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
3030
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */

0 commit comments

Comments
 (0)