From c83a824ff41852d90b304708b2f94a851514dcf7 Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Tue, 18 Jul 2023 11:36:27 -0400 Subject: [PATCH] Revert "refactor: remove XModule JS from Django Pipeline (#32530)" This reverts commit 4aedeb8988c2b7838e9ee210a7f3b704f2a8954d. --- cms/djangoapps/pipeline_js/utils.py | 19 +++++++++++++++++++ cms/envs/common.py | 9 +++++++++ lms/envs/common.py | 8 ++++++++ .../instructor_dashboard_2.html | 3 +-- lms/templates/wiki/preview_inline.html | 1 + xmodule/assets/README.rst | 3 +++ 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 cms/djangoapps/pipeline_js/utils.py diff --git a/cms/djangoapps/pipeline_js/utils.py b/cms/djangoapps/pipeline_js/utils.py new file mode 100644 index 000000000000..2584b023acdf --- /dev/null +++ b/cms/djangoapps/pipeline_js/utils.py @@ -0,0 +1,19 @@ +""" +Utilities for returning XModule JS (used by requirejs) +""" + + +from django.conf import settings +from django.contrib.staticfiles.storage import staticfiles_storage + + +def get_xmodule_urls(): + """ + Returns a list of the URLs to hit to grab all the XModule JS + """ + pipeline_js_settings = settings.PIPELINE['JAVASCRIPT']["module-js"] + if settings.DEBUG: + paths = [path.replace(".coffee", ".js") for path in pipeline_js_settings["source_filenames"]] + else: + paths = [pipeline_js_settings["output_filename"]] + return [staticfiles_storage.url(path) for path in paths] diff --git a/cms/envs/common.py b/cms/envs/common.py index bed1862fabd1..e3e321c56836 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -1383,6 +1383,15 @@ 'source_filenames': base_vendor_js, 'output_filename': 'js/cms-base-vendor.js', }, + 'module-js': { + 'source_filenames': ( + rooted_glob(COMMON_ROOT / 'static/', 'xmodule/descriptors/js/*.js') + + rooted_glob(COMMON_ROOT / 'static/', 'xmodule/modules/js/*.js') + + rooted_glob(COMMON_ROOT / 'static/', 'common/js/discussion/*.js') + ), + 'output_filename': 'js/cms-modules.js', + 'test_order': 1 + }, } STATICFILES_IGNORE_PATTERNS = ( diff --git a/lms/envs/common.py b/lms/envs/common.py index a9b5f0203fbf..cc953d355e68 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2580,6 +2580,14 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring 'source_filenames': main_vendor_js, 'output_filename': 'js/lms-main_vendor.js', }, + 'module-descriptor-js': { + 'source_filenames': rooted_glob(COMMON_ROOT / 'static/', 'xmodule/descriptors/js/*.js'), + 'output_filename': 'js/lms-module-descriptors.js', + }, + 'module-js': { + 'source_filenames': rooted_glob(COMMON_ROOT / 'static', 'xmodule/modules/js/*.js'), + 'output_filename': 'js/lms-modules.js', + }, 'discussion': { 'source_filenames': discussion_js, 'output_filename': 'js/discussion.js', diff --git a/lms/templates/instructor/instructor_dashboard_2/instructor_dashboard_2.html b/lms/templates/instructor/instructor_dashboard_2/instructor_dashboard_2.html index c0392f32933a..7f0046a79daf 100644 --- a/lms/templates/instructor/instructor_dashboard_2/instructor_dashboard_2.html +++ b/lms/templates/instructor/instructor_dashboard_2/instructor_dashboard_2.html @@ -54,8 +54,7 @@ - <%static:webpack entry='HtmlBlockEditor'/> - + <%static:js group='module-descriptor-js'/> <%static:js group='instructor_dash'/> <%static:js group='application'/> diff --git a/lms/templates/wiki/preview_inline.html b/lms/templates/wiki/preview_inline.html index 4fdab7a5756f..1dd3ede9208c 100644 --- a/lms/templates/wiki/preview_inline.html +++ b/lms/templates/wiki/preview_inline.html @@ -40,6 +40,7 @@

{{ title }}

{% javascript 'application' %} + {% javascript 'module-js' %} {% with mathjax_mode='wiki' %} {% include "mathjax_include.html" %} {% endwith %} diff --git a/xmodule/assets/README.rst b/xmodule/assets/README.rst index 618ba029246f..c87642384f6d 100644 --- a/xmodule/assets/README.rst +++ b/xmodule/assets/README.rst @@ -75,11 +75,14 @@ Currently, edx-platform XBlock JS is defined both here in `xmodule/assets`_ and * `VerticalBlock`_ * `LibrarySourcedBlock`_ +* Some XBlock JS is also processed through Django Pipeline and used in a couple specific legacy places. + As part of an `active build refactoring`_: * We update the older builtin XBlocks to reference their JS directly rather than using copies of it. * We will move ``webpack.xmodule.config.js`` here instead of generating it. * We will consolidate all edx-platform XBlock JS here in `xmodule/assets`_. +* We will remove XBlock JS from Django Pipeline. * We will delete the ``xmodule_assets`` script. .. _xmodule/assets: https://github.com/openedx/edx-platform/tree/master/xmodule/assets