Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webpack: Build a ZULIP_VERSION global constant into the built product.
Alex Vandivera8181152b7f9
diff --git a/.eslintrc.json b/.eslintrc.jsonindex b493cd93fd5..a2753f03ab9 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -237,6 +237,9 @@"browser": true,"node": false},+ "globals": {+ "ZULIP_VERSION": false+ },"rules": {"no-console": "error"},diff --git a/tools/webpack b/tools/webpackindex 8e8beb65162..ca9704dcebc 100755--- a/tools/webpack+++ b/tools/webpack@@ -3,11 +3,17 @@ import argparseimport jsonimport osimport subprocess+import sysfrom typing import NoReturn+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))+os.chdir(os.path.join(os.path.dirname(__file__), "../web"))+from version import ZULIP_VERSION++def build_for_prod_or_puppeteer(quiet: bool) -> NoReturn:"""Builds for production, writing the output to disk"""@@ -15,7 +21,11 @@ def build_for_prod_or_puppeteer(quiet: bool) -> NoReturn:with open("/proc/meminfo") as meminfo:if int(next(meminfo).split()[1]) < 3 * 1024 * 1024:webpack_args += ["--max-old-space-size=1536"]- webpack_args += ["../node_modules/.bin/webpack-cli", "--mode=production"]+ webpack_args += [+ "../node_modules/.bin/webpack-cli",+ "--mode=production",+ f"--env=ZULIP_VERSION={ZULIP_VERSION}",+ ]if quiet:webpack_args += ["--stats=errors-only"]os.execvp(webpack_args[0], webpack_args)diff --git a/web/src/global.d.ts b/web/src/global.d.tsindex b1fb6e68a3f..5bdd7711fb4 100644--- a/web/src/global.d.ts+++ b/web/src/global.d.ts@@ -9,3 +9,5 @@ interface JQuery {expectOne(): JQuery;tab(action?: string): this; // From web/third/bootstrap}++declare const ZULIP_VERSION: string;diff --git a/web/webpack.config.ts b/web/webpack.config.tsindex 1f9a657fbd6..1577a53662a 100644--- a/web/webpack.config.ts+++ b/web/webpack.config.ts@@ -5,6 +5,7 @@ import path from "path";import CssMinimizerPlugin from "css-minimizer-webpack-plugin";import HtmlWebpackPlugin from "html-webpack-plugin";import MiniCssExtractPlugin from "mini-css-extract-plugin";+import {DefinePlugin} from "webpack";import type webpack from "webpack";import BundleTracker from "webpack-bundle-tracker";@@ -12,7 +13,10 @@ import DebugRequirePlugin from "./debug-require-webpack-plugin";import assets from "./webpack.assets.json";import dev_assets from "./webpack.dev-assets.json";-export default (env: {minimize?: boolean} = {}, argv: {mode?: string}): webpack.Configuration[] => {+export default (+ env: {minimize?: boolean; ZULIP_VERSION?: string} = {},+ argv: {mode?: string},+): webpack.Configuration[] => {const production: boolean = argv.mode === "production";const baseConfig: webpack.Configuration = {@@ -194,6 +198,9 @@ export default (env: {minimize?: boolean} = {}, argv: {mode?: string}): webpack.},},plugins: [+ new DefinePlugin({+ ZULIP_VERSION: JSON.stringify(env.ZULIP_VERSION || "development"),+ }),new DebugRequirePlugin(),new BundleTracker({filename: production