-
-
Notifications
You must be signed in to change notification settings - Fork 589
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
Conversation
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.
@@ -1,11 +1,8 @@ | |||
{ | |||
"sourceMaps": "inline", | |||
"sourceMaps": true, |
There was a problem hiding this comment.
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" | ||
], |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
Now that this passes, I'm going to chop it up into more sensible PRs. |
Dist is where you Distribute things.
This is against
travis/sourcemaps
because it breaks everything.Changes:
lib/browser
to collapse the tree a bitsrc/
for more logical transpiling and IDE suggestions (many IDEs don't look at ignored directories, but will if you compile the entry point)src
instead oflib
- 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 oflib
. 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 exportlib
anddist/browser-matrix.js
for backwards compatibility (ie: everyone who has imported frommatrix-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.