Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Convert entry points to es module and create minified bundles #445

Merged
merged 16 commits into from
Apr 9, 2020

Conversation

fayyazarshad
Copy link
Contributor

@fayyazarshad fayyazarshad commented Apr 7, 2020

Summary

This is the first step in an effort to convert javascript SDK from Common JS to ES Module. The changes include

  1. Convert all the entry point files to ES Module.
  2. Minified Common JS bundles are being created for each entry point using Rollup and Terser
    main: dist/optimizely.node.min.js
    browser: dist/optimizely.browser.min.js
    react-native: dist/optimizely.react_native.min.js
  3. All the bundles including umd bundle are generated using Rollup and terser. Webpack is only being used to keep the Karma tests running.

Why Webpack for Karma?

We tried using Rollup with Karma for the same purpose but couldnt run it despite trying many times. To not block progress on the ES module conversion, we recommend moving forward with using webpack to keep running karma tests when all the bundles are being created by Rollup and terser. We can revisit and modify Karma to use Rollup later.

Note about Testapp

This PR uses a specific branch of javascript-testapp. This change is required because now testapp has to run an additional command to build the bundles which was not the case earlier. This testapp PR needs to be merged before merging this SDK branch.
https://github.com/optimizely/javascript-testapp/pull/83

Test plan

All unit tests and Full stack compatibility suite tests pass.

@fayyazarshad fayyazarshad self-assigned this Apr 7, 2020
@fayyazarshad fayyazarshad force-pushed the zeeshan/esmodule-conversion-entrypoints branch from 21b4434 to b89eed7 Compare April 7, 2020 14:37
@fayyazarshad fayyazarshad reopened this Apr 7, 2020
@fayyazarshad fayyazarshad force-pushed the zeeshan/esmodule-conversion-entrypoints branch from fee016d to b89eed7 Compare April 7, 2020 19:41
@zashraf1985 zashraf1985 changed the title Converting entry points to es module refactor: Converted entry points to es module and created minified bundles Apr 8, 2020
@zashraf1985 zashraf1985 changed the title refactor: Converted entry points to es module and created minified bundles refactor: Convert entry points to es module and create minified bundles Apr 8, 2020
# Conflicts:
#	packages/optimizely-sdk/lib/index.browser.js
#	packages/optimizely-sdk/lib/index.node.js
#	packages/optimizely-sdk/lib/index.react_native.js
@zashraf1985 zashraf1985 marked this pull request as ready for review April 8, 2020 22:02
@zashraf1985 zashraf1985 requested a review from a team as a code owner April 8, 2020 22:02
@zashraf1985 zashraf1985 removed the WIP label Apr 8, 2020
@@ -57,7 +55,6 @@ describe('javascript-sdk', function() {
sinon.stub(configValidator, 'validate');

xhr = sinon.useFakeXMLHttpRequest();
global.XMLHttpRequest = xhr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line not necessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looked redundant and removing it did not affect any tests.

"istanbul": "^0.4.5",
"json-loader": "^0.5.4",
"karma": "^4.4.1",
"karma-browserstack-launcher": "^1.5.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed? Is this used for running umd or xbrowser tests locally?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing modules that are not being used. This is in the devDependencies but is not being used in karma file. It looks like somebody added it to try karma tests locally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is necessary to run it locally, let's leave it in, otherwise OK.

"karma-mocha": "^1.3.0",
"karma-sinon": "^1.0.5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing modules which were not being used by removing and running tests. Removing this one did not fail any tests so looks like its no longer required

"istanbul": "^0.4.5",
"json-loader": "^0.5.4",
"karma": "^4.4.1",
"karma-browserstack-launcher": "^1.5.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is necessary to run it locally, let's leave it in, otherwise OK.

logging: loggerPlugin,
errorHandler: defaultErrorHandler,
eventDispatcher: defaultEventDispatcher,
enums,
Copy link
Contributor

@mjc1283 mjc1283 Apr 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I missed this. @zashraf1985 don't use the property shorthand here. This is not ES5-compatible. Needs to be enums: enums.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Done

@mjc1283 mjc1283 merged commit 8fe8c99 into master Apr 9, 2020
@mjc1283 mjc1283 deleted the zeeshan/esmodule-conversion-entrypoints branch April 9, 2020 01:24
jasonkarns added a commit to github/optimizely-javascript-sdk that referenced this pull request May 12, 2020
* v4:
  test suite doesn't pass cleanly
  prepare already runs build
  v4.0.0-github.0
  Ignore package tarballs
  Resume building non-minified ES entrypoint
  revert to master
  Expose an ESM-FULL bundle which includes optimizely deps
  Standardize ESM bundle
  Generate both min and non-min esm output
  exports option for es output is redundant. auto is best
  Use rollup --config- options for specifying bundles
  Build-all by default
  build various bundles using --config-* param
  chore: Prepare for 4.0.0 release (optimizely#468)
  fix: Removed React Native client engine temporarily (optimizely#466)
  chore: Prepare for 4.0.0-rc.2 release (optimizely#465)
  chore: Add source maps to build output (optimizely#464)
  fix(project config): Don't mutate the datafile object (optimizely#462)
  chore: Prepare for 4.0.0-rc.1 release (optimizely#461)
  chore: Prepare for js-sdk-datafile-manager 0.5.0 release (optimizely#460)
  chore(datafile manager): Remove react native datafile manager entry from package.json (optimizely#459)
  fix(datafile manager): Node datafile requests use gzip,deflate compression (optimizely#456)
  docs(datafile manager): Removed manual dependency installation requirement from docs (optimizely#457)
  chore(datafile manager): Added async storage as dev dependency (optimizely#455)
  refactor: Added a separate bundle for Json Schema Validator (optimizely#454)
  refactor: Convert lib/utils to ES module (Part 2/2) (optimizely#452)
  refactor: Convert lib/core to ES module (Part 2/2) (optimizely#450)
  chore(datafile manager): Update years in header comments (optimizely#453)
  refactor: Convert lib/core to ES module (Part 1/2) (optimizely#449)
  refactor: Convert lib/utils to ES module (Part 1/2) (optimizely#451)
  refactor: Convert lib/optimizely/* and lib/tests/* to ES module (optimizely#448)
  refactor: Convert lib/plugins from CJS to ES module (optimizely#427)
  chore: Update js-sdk-utils to 0.2.0 (optimizely#447)
  refactor: Convert entry points to es module and create minified bundles (optimizely#445)
  chore: Update CHANGELOG.MD for jsonSchemaValidator change (optimizely#443)
  Change functionality of JSON schema validation by removing skipJSONValidation entirely. Now a user needs to import jsonSchemaValidator from @optimizely/optimizely-sdk/lib/utils/json_schema_validator and pass it to createInstance when validation is desired. (optimizely#442)
  chore(datafile manager): Lint and formatting fixes for datafile manager tests (optimizely#441)
  [OASIS-6102]: changed functionality of the JSON schema validator module (optimizely#438)
  chore(datafile manager): Fix ESLint warnings & errors, apply Prettier formatting (optimizely#440)
  fix (datafile-manager): Fix boolean types, remove StaticDatafileManager, update READMe, add eslint + prettier (optimizely#436)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants