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

[WIP] Convert imports and exports to ES6 #1121

Closed
wants to merge 14 commits into from

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Dec 16, 2019

This is against travis/sourcemaps because it breaks everything.

Changes:

  • Imports and exports are all ES6-style - see below for more info)
  • Minification on the browser bundle (it was trivial to add - just add uglifyify)
  • Moved the browser bundle into lib/browser to collapse the tree a bit
  • Migrated the browser and regular indexes into src/ for more logical transpiling and IDE suggestions (many IDEs don't look at ignored directories, but will if you compile the entry point)
  • Tests are now pointed at src instead of lib - this is for ES6 imports/exports and future typechecking.

The old module.exports syntax doesn't work downstream in the react-sdk or riot-web layers anymore, so this brings it up to 2019 standards.

We do not use default exports anymore because they are discouraged by the ES6 community. It's not an official recommendation, but it's certainly commonplace.

This also changes browser-index.js and index.js to use the src tree instead of lib. This is primarily to have IDEs autocomplete the package more easily, and because we're compiling this all in the riot-web layer it doesn't really matter. We still export lib and dist/browser-matrix.js for backwards compatibility (ie: everyone who has imported from matrix-js-sdk/lib/whatever or uses <script> tags). In a future version/PR we could drop these if we feel like it.

This commit does not address the test failures that are almost certainly caused by this change. While we're here, the ancient "use strict"; flags have been removed as well.

Some files were not as easily converted. Most were simple keyword changes though there are a couple instances where the file structure is redone to accommodate ES6 exports.

The old `module.exports` syntax doesn't work downstream in the react-sdk or riot-web layers anymore, so this brings it up to 2019 standards. 

We do not use default exports anymore because they are discouraged by the ES6 community. It's not an official recommendation, but it's certainly commonplace. 

This also changes browser-index.js and index.js to use the `src` tree instead of `lib`. This is primarily to have IDEs autocomplete the package more easily, and because we're compiling this all in the riot-web layer it doesn't really matter. We still export `lib` and `dist/browser-matrix.js` for backwards compatibility (ie: everyone who has imported from `matrix-js-sdk/lib/whatever` or uses `<script>` tags). In a future version/PR we could drop these if we feel like it.

This commit does not address the test failures that are almost certainly caused by this change. While we're here, the ancient `"use strict";` flags have been removed as well.

Some files were not as easily converted. Most were simple keyword changes though there are a couple instances where the file structure is redone to accommodate ES6 exports.
@turt2live turt2live self-assigned this Dec 16, 2019
@@ -1,11 +1,8 @@
{
"sourceMaps": "inline",
"sourceMaps": true,
Copy link
Member Author

Choose a reason for hiding this comment

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

with true we just let babel decide what is best for us. When we need inline sourcemaps we ask for them.

"presets": [
["@babel/preset-env", {
"targets": {
"browsers": [
"last 2 versions"
],
Copy link
Member Author

Choose a reason for hiding this comment

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

browserify takes care of the browser for us.

package.json Outdated
"build": "yarn clean && git rev-parse HEAD > git-revision.txt && yarn build:compile && yarn build:compile-browser && yarn build:types",
"build:types": "tsc --emitDeclarationOnly",
"build:compile": "babel src -s -d lib --verbose --extensions \".ts,.js\"",
"build:compile-browser": "mkdirp dist && browserify -d browser-index.js -t [ babelify --sourceMaps=inline ] > dist/browser-matrix.js",
"build:compile-browser": "mkdirp lib/browser && browserify -d src/browser-index.js -p [ tsify -p ./tsconfig.json ] -t [ babelify --sourceMaps=inline ] -t uglifyify > lib/browser/matrix.js",
Copy link
Member Author

Choose a reason for hiding this comment

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

tsify is so we can load typescript from src. uglifify is for minification.

@@ -24,9 +24,6 @@ limitations under the License.
* See also `megolm.spec.js`.
*/

"use strict";
import 'source-map-support/register';
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need these imports anymore - they actually make the test's sourcemaps wrong.

@turt2live
Copy link
Member Author

Now that this passes, I'm going to chop it up into more sensible PRs.

Dist is where you Distribute things.
@turt2live turt2live changed the title Convert imports and exports to ES6 [WIP] Convert imports and exports to ES6 Dec 17, 2019
@turt2live turt2live closed this Dec 17, 2019
@turt2live turt2live deleted the travis/babel7-es6 branch December 17, 2019 23:34
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.

1 participant