Skip to content

Commit

Permalink
[BREAKING] Refactor the entire build process
Browse files Browse the repository at this point in the history
For element-hq/element-web#8880

Features:
* Export modern JS
* Export typings
* Export source maps that actually mean something
* No longer supporting minified builds

This is a step towards being a boring SDK and not anticipating an install location. 

This commit requires a major version bump of the SDK.
  • Loading branch information
turt2live committed Dec 10, 2019
1 parent 01f0dd4 commit 4bdabbf
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 357 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"sourceMaps": "inline",
"presets": [
["@babel/preset-env", {
"targets": {
Expand Down
35 changes: 30 additions & 5 deletions .buildkite/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
steps:
- label: ":eslint: Lint"
- label: ":eslint: JS Lint"
command:
- "yarn install"
- "yarn lint"
- "yarn lint:js"
plugins:
- docker#v3.0.1:
image: "node:10"
image: "node:12"

- label: ":tslint: TS Lint"
command:
- "yarn install"
- "yarn lint:ts"
plugins:
- docker#v3.0.1:
image: "node:12"

- label: ":typescript: Types Lint"
command:
- "yarn install"
- "yarn lint:types"
plugins:
- docker#v3.0.1:
image: "node:12"

- label: "🛠 Build"
command:
- "yarn install"
- "yarn build"
plugins:
- docker#v3.0.1:
image: "node:12"

- label: ":jest: Tests"
command:
- "yarn install"
- "yarn build" # Needed for the tests to run - we don't build on install
- "yarn test"
plugins:
- docker#v3.0.1:
image: "node:10"
image: "node:12"

- label: "📃 Docs"
command:
- "yarn install"
- "yarn gendoc"
plugins:
- docker#v3.0.1:
image: "node:10"
image: "node:12"

- wait

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ https://github.com/matrix-org/matrix-js-sdk/releases/latest and add that as a
attached to ``window`` through which you can access the SDK. See below for how to
include libolm to enable end-to-end-encryption.

Note that your application will be required to minify the JS if desired - the js-sdk
doesn't guarantee that the output will be minified.

Please check [the working browser example](examples/browser) for more information.

In Node.js
Expand Down Expand Up @@ -351,11 +354,6 @@ To build a browser version from scratch when developing::
$ yarn build
```

To constantly do builds when files are modified (using ``watchify``)::
```
$ yarn watch
```

To run tests (Jasmine)::
```
$ yarn test
Expand Down
2 changes: 1 addition & 1 deletion browser-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ if (indexedDB) {
);
}

module.exports = matrixcs; // keep export for browserify package deps
export default matrixcs; // keep export for browserify package deps
global.matrixcs = matrixcs;
53 changes: 20 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "matrix-js-sdk",
"version": "2.4.6",
"description": "Matrix Client-Server SDK for Javascript",
"main": "index.js",
"description": "Matrix Client-Server SDK for JavaScript and TypeScript",
"scripts": {
"test:watch": "jest spec/ --coverage --testEnvironment node --watch",
"test": "jest spec/ --coverage --testEnvironment node",
"gendoc": "jsdoc -c jsdoc.json -P package.json",
"start": "yarn start:init && yarn start:watch",
"start:watch": "babel src -s -d lib --verbose --extensions \".ts,.js\"",
"start:init": "babel src -s -d lib --verbose --extensions \".ts,.js\"",
"start": "echo THIS IS FOR LEGACY PURPOSES ONLY. && babel src -w -s -d lib --verbose --extensions \".ts,.js\"",
"clean": "rimraf lib dist",
"build": "babel src -s -d lib --verbose --extensions \".ts,.js\" && rimraf dist && mkdir dist && browserify -d browser-index.js | exorcist dist/browser-matrix.js.map > dist/browser-matrix.js && terser -c -m -o dist/browser-matrix.min.js --source-map \"content='dist/browser-matrix.js.map'\" dist/browser-matrix.js",
"dist": "yarn build",
"watch": "watchify -d browser-index.js -o 'exorcist dist/browser-matrix.js.map > dist/browser-matrix.js' -v",
"lint": "eslint --max-warnings 93 src spec",
"prepare": "yarn clean && yarn build && git rev-parse HEAD > git-revision.txt"
"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",
"gendoc": "jsdoc -c jsdoc.json -P package.json",
"lint": "yarn lint:types && yarn lint:ts && yarn lint:js",
"lint:js": "eslint --max-warnings 93 src spec",
"lint:types": "tsc --noEmit",
"lint:ts": "tslint --project ./tsconfig.json -t stylish",
"test": "jest spec/ --coverage --testEnvironment node",
"test:watch": "jest spec/ --coverage --testEnvironment node --watch"
},
"repository": {
"type": "git",
Expand All @@ -24,27 +24,21 @@
"keywords": [
"matrix-org"
],
"main": "./index.js",
"typings": "./lib/index.d.ts",
"browser": "browser-index.js",
"author": "matrix.org",
"license": "Apache-2.0",
"files": [
".babelrc",
".eslintrc.js",
"spec/.eslintrc.js",
"CHANGELOG.md",
"CONTRIBUTING.rst",
"LICENSE",
"README.md",
"RELEASING.md",
"examples",
"git-hooks",
"git-revision.txt",
"index.js",
"browser-index.js",
"lib",
"package.json",
"release.sh",
"spec",
"src"
],
"dependencies": {
Expand All @@ -69,30 +63,23 @@
"@babel/preset-typescript": "^7.7.4",
"@babel/register": "^7.7.4",
"@babel/runtime": "^7.7.6",
"@types/node": "12",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.9.0",
"babelify": "^10.0.0",
"better-docs": "^1.4.7",
"browserify": "^16.2.3",
"browserify-shim": "^3.8.13",
"browserify": "^16.5.0",
"eslint": "^5.12.0",
"eslint-config-google": "^0.7.1",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-jest": "^23.0.4",
"exorcist": "^1.0.1",
"jest": "^24.9.0",
"jsdoc": "^3.5.5",
"matrix-mock-request": "^1.2.3",
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
"rimraf": "^3.0.0",
"source-map-support": "^0.5.13",
"sourceify": "^1.0.0",
"terser": "^4.3.8",
"typescript": "^3.7.3",
"watchify": "^3.11.1"
},
"browserify": {
"transform": [
"sourceify"
]
"tslint": "^5.20.1",
"typescript": "^3.7.3"
}
}
2 changes: 1 addition & 1 deletion spec/unit/crypto.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TestClient from '../TestClient';
import {MatrixEvent} from '../../lib/models/event';
import Room from '../../lib/models/room';
import olmlib from '../../lib/crypto/olmlib';
import {sleep} from "../../src/utils";
import {sleep} from "../../lib/utils";

const EventEmitter = require("events").EventEmitter;

Expand Down
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es2016",
"noImplicitAny": false,
"sourceMap": false,
"outDir": "./lib",
"declaration": true,
"types": [
"node"
]
},
"include": [
"./src/**/*.ts"
]
}
72 changes: 72 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"rules": {
"class-name": false,
"comment-format": [
true
],
"curly": false,
"eofline": false,
"forin": false,
"indent": [
true,
"spaces"
],
"label-position": true,
"max-line-length": false,
"member-access": false,
"member-ordering": [
true,
"static-after-instance",
"variables-before-functions"
],
"no-arg": true,
"no-bitwise": false,
"no-console": false,
"no-construct": true,
"no-debugger": true,
"no-duplicate-variable": true,
"no-empty": false,
"no-eval": true,
"no-inferrable-types": true,
"no-shadowed-variable": true,
"no-string-literal": false,
"no-switch-case-fall-through": true,
"no-trailing-whitespace": true,
"no-unused-expression": true,
"no-use-before-declare": false,
"no-var-keyword": true,
"object-literal-sort-keys": false,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"quotemark": false,
"radix": true,
"semicolon": [
"always"
],
"triple-equals": [],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"variable-name": false,
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}
}
Loading

0 comments on commit 4bdabbf

Please sign in to comment.