Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
requirements: Remove django-webpack-loader.
Anders Kaseorg738532ba513b
diff --git a/docs/subsystems/html-css.md b/docs/subsystems/html-css.mdindex 09210e9c125..fb1b7d4f052 100644--- a/docs/subsystems/html-css.md+++ b/docs/subsystems/html-css.md@@ -164,7 +164,7 @@ webpack build, JS minification and a host of other steps for getting the assetsready for deployment.You can trace which source files are included in which HTML templates-by comparing the `render_entrypoint` calls in the HTML templates under+by comparing the `entrypoint` variables in the HTML templates under`templates/` with the bundles declared in `tools/webpack.assets.json`.### Adding static filesdiff --git a/requirements/common.in b/requirements/common.inindex bead5c285ad..85d31d7048a 100644--- a/requirements/common.in+++ b/requirements/common.in@@ -99,9 +99,6 @@ tornado==4.* # https://github.com/zulip/zulip/issues/8913# Fast JSON parserorjson-# Django extension for serving webpack modules-django-webpack4-loader-# Needed for iOS push notificationsapns2diff --git a/requirements/dev.txt b/requirements/dev.txtindex 86042b0e504..28b10b6dd0c 100644--- a/requirements/dev.txt+++ b/requirements/dev.txt@@ -378,10 +378,6 @@ django-two-factor-auth[call,phonenumberslite,sms]==1.13 \--hash=sha256:24c2850a687c86800f4aa4131b7cebadf56f35be04ca359c4990578df1cc249a \--hash=sha256:afb60e62f22b1f29a568666c0444ab05cabe8acc4d7c54d833d67f7b50f842fd# via -r requirements/common.in-django-webpack4-loader==0.0.5 \- --hash=sha256:baa043c4601ed763d161490e2888cf6aa93a2fd9b60681e6b19e35dc7fcb155d \- --hash=sha256:be90257041170f39c025ff674c9064569c9303b464536488b6a6cedd8e3d28be- # via -r requirements/common.indjango[argon2]==3.1.7 \--hash=sha256:32ce792ee9b6a0cbbec340123e229ac9f765dff8c2a4ae9247a14b2ba3a365a7 \--hash=sha256:baf099db36ad31f970775d0be5587cc58a6256a6771a44eb795b554d45f211b8diff --git a/requirements/prod.txt b/requirements/prod.txtindex 4d8b9130d05..cbdb58355c5 100644--- a/requirements/prod.txt+++ b/requirements/prod.txt@@ -244,10 +244,6 @@ django-two-factor-auth[call,phonenumberslite,sms]==1.13 \--hash=sha256:24c2850a687c86800f4aa4131b7cebadf56f35be04ca359c4990578df1cc249a \--hash=sha256:afb60e62f22b1f29a568666c0444ab05cabe8acc4d7c54d833d67f7b50f842fd# via -r requirements/common.in-django-webpack4-loader==0.0.5 \- --hash=sha256:baa043c4601ed763d161490e2888cf6aa93a2fd9b60681e6b19e35dc7fcb155d \- --hash=sha256:be90257041170f39c025ff674c9064569c9303b464536488b6a6cedd8e3d28be- # via -r requirements/common.indjango[argon2]==3.1.7 \--hash=sha256:32ce792ee9b6a0cbbec340123e229ac9f765dff8c2a4ae9247a14b2ba3a365a7 \--hash=sha256:baf099db36ad31f970775d0be5587cc58a6256a6771a44eb795b554d45f211b8diff --git a/templates/zerver/base.html b/templates/zerver/base.htmlindex 2e83a756d00..0525ae29cb7 100644--- a/templates/zerver/base.html+++ b/templates/zerver/base.html@@ -26,8 +26,13 @@{% endif %}{% block webpack %}- {{ render_entrypoint(entrypoint, 'css', attrs='nonce="%s"' % (csp_nonce,) if csp_nonce else '') }}- {{ render_entrypoint(entrypoint, 'js', attrs='defer nonce="%s"' % (csp_nonce,) if csp_nonce else 'defer') }}+ {% for filename in webpack_entry(entrypoint) -%}+ {% if filename.endswith(".css") -%}+ <link href="{{ filename }}" rel="stylesheet" {% if csp_nonce %}nonce="{{ csp_nonce }}"{% endif %} />+ {% elif filename.endswith(".js") -%}+ <script src="{{ filename }}" defer {% if csp_nonce %}nonce="{{ csp_nonce }}"{% endif %}></script>+ {% endif -%}+ {% endfor %}{% endblock %}{% block customhead %}diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.pyindex ff93741ece8..ba21dfc7448 100644--- a/tools/linter_lib/custom_check.py+++ b/tools/linter_lib/custom_check.py@@ -610,7 +610,6 @@ html_rules: List["Rule"] = ["templates/zerver/hello.html","templates/corporate/upgrade.html",},- "good_lines": ["{{ render_entrypoint('landing-page') }}"],"bad_lines": ['<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>'],diff --git a/zerver/templatetags/app_filters.py b/zerver/templatetags/app_filters.pyindex ab3db8fe3a6..d577100bb2b 100644--- a/zerver/templatetags/app_filters.py+++ b/zerver/templatetags/app_filters.py@@ -1,3 +1,4 @@+import timefrom typing import Any, List, Mapping, Optionalimport markdown@@ -5,6 +6,9 @@ import markdown.extensions.admonitionimport markdown.extensions.codehiliteimport markdown.extensions.extraimport markdown.extensions.toc+import orjson+from django.conf import settings+from django.contrib.staticfiles.storage import staticfiles_storagefrom django.template import Library, enginesfrom django.utils.safestring import mark_safefrom jinja2.exceptions import TemplateNotFound@@ -167,3 +171,26 @@ def render_markdown_path(rendered_html = jinja.from_string(html).render(context)return mark_safe(rendered_html)+++def webpack_entry(entrypoint: str) -> List[str]:+ while True:+ with open(settings.WEBPACK_STATS_FILE, "rb") as f:+ stats = orjson.loads(f.read())+ status = stats["status"]+ if not settings.DEBUG or status != "compiling":+ break+ time.sleep(0.2)++ if status != "done":+ raise RuntimeError("Webpack compilation was not successful")++ return [+ chunk_file["publicPath"]+ if "publicPath" in chunk_file+ else staticfiles_storage.url(settings.WEBPACK_BUNDLES + chunk_file["name"])+ for chunk in stats["entryPoints"][entrypoint]+ for chunk_file in chunk+ if chunk_file["name"].endswith((".css", ".js"))+ and not chunk_file["name"].endswith(".hot-update.js")+ ]diff --git a/zproject/computed_settings.py b/zproject/computed_settings.pyindex c0e307b2628..f4d881ad4fa 100644--- a/zproject/computed_settings.py+++ b/zproject/computed_settings.py@@ -210,7 +210,6 @@ INSTALLED_APPS = ["django.contrib.sessions","django.contrib.staticfiles","confirmation",- "webpack_loader","zerver","social_django",# 2FA related apps.@@ -576,16 +575,11 @@ FILE_UPLOAD_MAX_MEMORY_SIZE = 0STATICFILES_DIRS = ["static/"]if DEBUG:- WEBPACK_STATS_FILE = os.path.join("var", "webpack-stats-dev.json")+ WEBPACK_BUNDLES = "../webpack/"+ WEBPACK_STATS_FILE = os.path.join(DEPLOY_ROOT, "var", "webpack-stats-dev.json")else:- WEBPACK_STATS_FILE = "webpack-stats-production.json"-WEBPACK_LOADER = {- "DEFAULT": {- "CACHE": not DEBUG,- "BUNDLE_DIR_NAME": "../webpack/" if DEBUG else "webpack-bundles/",- "STATS_FILE": os.path.join(DEPLOY_ROOT, WEBPACK_STATS_FILE),- },-}+ WEBPACK_BUNDLES = "webpack-bundles/"+ WEBPACK_STATS_FILE = os.path.join(DEPLOY_ROOT, "webpack-stats-production.json")######################################################################### TEMPLATES SETTINGS@@ -607,7 +601,6 @@ base_template_engine_settings: Dict[str, Any] = {"extensions": ["jinja2.ext.i18n","jinja2.ext.autoescape",- "webpack_loader.contrib.jinja2ext.WebpackExtension",],"context_processors": ["zerver.context_processors.zulip_default_context",diff --git a/zproject/jinja2/__init__.py b/zproject/jinja2/__init__.pyindex ff54d05fb36..74009676611 100644--- a/zproject/jinja2/__init__.py+++ b/zproject/jinja2/__init__.py@@ -9,7 +9,7 @@ from django.utils.timesince import timesincefrom jinja2 import Environmentfrom two_factor.templatetags.two_factor import device_action-from zerver.templatetags.app_filters import display_list, render_markdown_path+from zerver.templatetags.app_filters import display_list, render_markdown_path, webpack_entrydef environment(**options: Any) -> Environment:@@ -17,13 +17,12 @@ def environment(**options: Any) -> Environment:env.globals.update(default_page_params={"debug_mode": settings.DEBUG,- "webpack_public_path": staticfiles_storage.url(- settings.WEBPACK_LOADER["DEFAULT"]["BUNDLE_DIR_NAME"],- ),+ "webpack_public_path": staticfiles_storage.url(settings.WEBPACK_BUNDLES),},static=staticfiles_storage.url,url=reverse,render_markdown_path=render_markdown_path,+ webpack_entry=webpack_entry,)env.install_gettext_translations(translation, True)diff --git a/zproject/test_extra_settings.py b/zproject/test_extra_settings.pyindex b183a0576a7..34b43ccd3b6 100644--- a/zproject/test_extra_settings.py+++ b/zproject/test_extra_settings.py@@ -14,7 +14,6 @@ from .settings import (EXTERNAL_HOST,LOCAL_DATABASE_PASSWORD,LOGGING,- WEBPACK_LOADER,)FULL_STACK_ZULIP_TEST = "FULL_STACK_ZULIP_TEST" in os.environ@@ -109,11 +108,10 @@ SESSION_ENGINE = "django.contrib.sessions.backends.db"# Use production config from Webpack in testsif PUPPETEER_TESTS:- WEBPACK_FILE = "webpack-stats-production.json"+ WEBPACK_STATS_FILE = os.path.join(DEPLOY_ROOT, "webpack-stats-production.json")else:- WEBPACK_FILE = os.path.join("var", "webpack-stats-test.json")-WEBPACK_LOADER["DEFAULT"]["BUNDLE_DIR_NAME"] = "webpack-bundles/"-WEBPACK_LOADER["DEFAULT"]["STATS_FILE"] = os.path.join(DEPLOY_ROOT, WEBPACK_FILE)+ WEBPACK_STATS_FILE = os.path.join(DEPLOY_ROOT, "var", "webpack-stats-test.json")+WEBPACK_BUNDLES = "webpack-bundles/"# Don't auto-restart Tornado server during automated testsAUTORELOAD = False