Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 02f38fe

Browse files
authored
refactor: Added a separate bundle for Json Schema Validator (optimizely#454)
Summary: Since all the code was common JS earlier, json schema validator could be imported directly from source code. Now its no longer possible because its converted to Es module. Created a separate Cjs bundle for json schema validator to serve the same purpose. Test plan: Manually tested thoroughly
1 parent 81d2cac commit 02f38fe

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/optimizely-sdk/CHANGELOG.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
- Removed `Promise` polyfill from browser entry point ([417](https://github.com/optimizely/javascript-sdk/pull/417)).
1414
- Changed functionality of JSON schema validation in all entry points ([442](https://github.com/optimizely/javascript-sdk/pull/442)).
1515
- Previously, `skipJSONValidation` flag was used by the user to specify whether the JSON object should be validated.
16-
- Now, `skipJSONValidation` has been removed entirely from all entry points. Instead, a user will need to import `jsonSchemaValidator` from `@optimizely/optimizely-sdk/lib/utils/json_schema_validator` and pass it to `createInstance` to perform validation as shown below:
16+
- Now, `skipJSONValidation` has been removed entirely from all entry points. Instead, a user will need to import `jsonSchemaValidator` from `@optimizely/optimizely-sdk/dist/optimizely.json_schema_validator.min.js` and pass it to `createInstance` to perform validation as shown below:
1717

1818
```js
1919
const optimizelySDK = require('@optimizely/optimizely-sdk');
20-
const jsonSchemaValidator = require('@optimizely/optimizely-sdk/lib/utils/json_schema_validator');
20+
const jsonSchemaValidator = require('@optimizely/optimizely-sdk/dist/optimizely.json_schema_validator.min');
2121

2222
// Require JSON schema validation for the datafile
2323
var optimizelyClientInstance = optimizely.createInstance({

packages/optimizely-sdk/rollup.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,27 @@ const umdconfig = {
8787
],
8888
};
8989

90+
// A separate bundle for json schema validator.
91+
const jsonSchemaValidatorConfig = {
92+
plugins: [
93+
resolve(),
94+
commonjs(),
95+
],
96+
external: ['json-schema', '@optimizely/js-sdk-utils'],
97+
input: 'lib/utils/json_schema_validator/index.js',
98+
output: {
99+
exports: 'named',
100+
format: 'cjs',
101+
file: 'dist/optimizely.json_schema_validator.min.js',
102+
plugins: [ terser() ],
103+
}
104+
};
105+
90106
export default [
91107
BUILD_ALL && getCjsConfigForPlatform('node'),
92108
BUILD_ALL && getCjsConfigForPlatform('browser'),
93109
BUILD_ALL && getCjsConfigForPlatform('react_native'),
94110
BUILD_ALL && esModuleConfig,
111+
BUILD_ALL && jsonSchemaValidatorConfig,
95112
(BUILD_ALL || BUILD_UMD_BUNDLE) && umdconfig,
96113
].filter(config => config);

0 commit comments

Comments
 (0)