From bbb3aad611c1394905ec0defefce4b3b8d208c76 Mon Sep 17 00:00:00 2001 From: "Pweaver (Paul Weaver)" Date: Wed, 24 May 2017 11:31:00 -0700 Subject: [PATCH] Add typescript support to asset compilation. --- package.json | 8 ++++++-- static/ts/tsconfig.json | 18 ++++++++++++++++++ static/ts/tslint.json | 9 +++++++++ tools/lint | 2 ++ tools/webpack.config.js | 25 ++++++++++++++++++++++++- version.py | 2 +- 6 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 static/ts/tsconfig.json create mode 100644 static/ts/tslint.json diff --git a/package.json b/package.json index 4b427c3af7..660d985d38 100644 --- a/package.json +++ b/package.json @@ -8,17 +8,20 @@ "clipboard": "1.5.16", "handlebars": "4.0.6", "i18next": "3.4.4", - "i18next-parser": "0.11.1", - "i18next-xhr-backend": "0.5.4", "i18next-browser-languagedetector": "0.3.0", "i18next-localstorage-cache": "0.3.0", + "i18next-parser": "0.11.1", + "i18next-xhr-backend": "0.5.4", "jquery": "2.2.3", "jquery-validation": "1.16.0", "katex": "0.7.1", "moment": "2.18.1", "moment-timezone": "0.5.12", "plotly.js": "1.19.2", + "source-map-loader": "0.2.1", "string.prototype.codepointat": "0.2.0", + "ts-loader": "2.1.0", + "typescript": "2.3.3", "underscore": "1.8.3", "webpack": "2.5.1", "webpack-bundle-tracker": "0.2.0", @@ -36,6 +39,7 @@ "nwmatcher": "1.3.6", "phantomjs-prebuilt": "2.1.14", "svgo": "0.7.2", + "tslint": "5.3.2", "webpack-dev-server": "2.4.1", "xmlhttprequest": "1.5.0" }, diff --git a/static/ts/tsconfig.json b/static/ts/tsconfig.json new file mode 100644 index 0000000000..19a6cbf4ba --- /dev/null +++ b/static/ts/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "outDir": "../webpack-bundles/", + "sourceMap": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "removeComments": false, + "noImplicitAny": false, + "noFallthroughCasesInSwitch": true, + "suppressImplicitAnyIndexErrors": true, + "newLine": "lf", + "module": "commonjs", + "target": "es5", + "jsx": "react", + "allowJs": false + }, + "rootDir": "../.." +} diff --git a/static/ts/tslint.json b/static/ts/tslint.json new file mode 100644 index 0000000000..7b73ab8410 --- /dev/null +++ b/static/ts/tslint.json @@ -0,0 +1,9 @@ +{ + "defaultSeverity": "error", + "extends": [ + "tslint:recommended" + ], + "jsRules": {}, + "rules": {}, + "rulesDirectory": [] +} diff --git a/tools/lint b/tools/lint index 13b2281632..b2b0594968 100755 --- a/tools/lint +++ b/tools/lint @@ -700,6 +700,8 @@ def run(): external_linter('add_class', ['tools/find-add-class']) external_linter('css', ['tools/check-css'], ['css']) external_linter('eslint', ['node', 'node_modules/.bin/eslint', '--quiet'], ['js']) + external_linter('tslint', ['node', 'node_modules/.bin/tslint', '-c', + 'static/ts/tslint.json'], ['ts']) external_linter('puppet', ['puppet', 'parser', 'validate'], ['pp']) external_linter('templates', ['tools/check-templates'], ['handlebars', 'html']) external_linter('urls', ['tools/check-urls']) diff --git a/tools/webpack.config.js b/tools/webpack.config.js index ecf81e640c..acd9d7e33d 100644 --- a/tools/webpack.config.js +++ b/tools/webpack.config.js @@ -6,10 +6,33 @@ module.exports = { entry: assets, module: { noParse: /(min)\.js/, - }, + rules: [ + // Run the typescript compilier on .ts files before webpack + { + test: /\.tsx?$/, + loader: 'ts-loader', + }, + // This loads and transforms sourcemap files from other compiliers. + // The typescript comilier will generate a sourcemap and source-map-loaded will output + // the correct sourcemap from that. + { + enforce: 'pre', + test: /\.js$/, + loader: "source-map-loader", + }, + { + enforce: 'pre', + test: /\.tsx?$/, + use: "source-map-loader", + }, + ], + }, output: { path: path.resolve(__dirname, '../static/webpack-bundles'), filename: '[name].js', }, plugins: [], + resolve: { + extensions: [".tsx", ".ts", ".js", ".json"], + }, }; diff --git a/version.py b/version.py index 161ff0fb1c..19e8ddb050 100644 --- a/version.py +++ b/version.py @@ -1,2 +1,2 @@ ZULIP_VERSION = "1.5.1+git" -PROVISION_VERSION = '5.2' +PROVISION_VERSION = '5.3'