From b7b3bbc8356b8365f3ab8ed9c8d863b47c18a3d4 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 5 Nov 2021 12:11:18 +0100 Subject: [PATCH] [4.0.x] Fixed #33253 -- Reverted "Fixed #32319 -- Added ES module support to ManifestStaticFilesStorage." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 91e21836f667c784a8a63ab1f18d81f553e679cb. `export` and `import` directives have several syntax variants and not all of them were properly covered. Thanks Hervé Le Roy for the report. Backport of ba9ced3e9a643a05bc521f0a2e6d02e3569de374 from main --- django/contrib/staticfiles/storage.py | 9 ---- docs/ref/contrib/staticfiles.txt | 7 --- docs/releases/4.0.txt | 4 -- .../project/documents/absolute_root.js | 2 - .../project/documents/cached/module.js | 22 --------- .../project/documents/cached/module_test.js | 5 -- .../project/documents/nested/js/nested.js | 1 - tests/staticfiles_tests/test_storage.py | 46 ------------------- 8 files changed, 96 deletions(-) delete mode 100644 tests/staticfiles_tests/project/documents/absolute_root.js delete mode 100644 tests/staticfiles_tests/project/documents/cached/module.js delete mode 100644 tests/staticfiles_tests/project/documents/cached/module_test.js delete mode 100644 tests/staticfiles_tests/project/documents/nested/js/nested.js diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py index bb66304a7e..56aaac0f8e 100644 --- a/django/contrib/staticfiles/storage.py +++ b/django/contrib/staticfiles/storage.py @@ -57,15 +57,6 @@ class HashedFilesMixin: r'(?m)(?P)^(//# (?-i:sourceMappingURL)=(?P.*))$', '//# sourceMappingURL=%(url)s', ), - ( - r"""(?Pimport\s+(?s:(?P.*?))\s*from\s*["'](?P.*?)["'])""", - 'import %(imports)s from "%(url)s"', - ), - ( - r"""(?Pexport\s+(?s:(?P.*?))\s*from\s*["'](?P.*?)["'])""", - 'export %(exports)s from "%(url)s"', - ), - (r"""(?Pimport\(["'](?P.*?)["']\))""", 'import("%(url)s")'), )), ) keep_intermediate_files = True diff --git a/docs/ref/contrib/staticfiles.txt b/docs/ref/contrib/staticfiles.txt index 46a73e7c54..eb6703685b 100644 --- a/docs/ref/contrib/staticfiles.txt +++ b/docs/ref/contrib/staticfiles.txt @@ -295,8 +295,6 @@ method). The regular expressions used to find those paths * The `@import`_ rule and `url()`_ statement of `Cascading Style Sheets`_. * The `source map`_ comment in JavaScript. -* The `modules import`_ in JavaScript. -* The `modules aggregation`_ in JavaScript. For example, the ``'css/styles.css'`` file with this content: @@ -331,9 +329,6 @@ argument. For example:: Support for finding paths in the source map comments was added. - Support for finding paths to JavaScript modules in ``import`` and - ``export`` statements was added. - The ``manifest_storage`` argument was added. .. attribute:: storage.ManifestStaticFilesStorage.max_post_process_passes @@ -389,8 +384,6 @@ hashing algorithm. .. _`url()`: https://www.w3.org/TR/CSS2/syndata.html#uri .. _`Cascading Style Sheets`: https://www.w3.org/Style/CSS/ .. _`source map`: https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map -.. _`modules import`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#importing_features_into_your_script -.. _`modules aggregation`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#aggregating_modules ``ManifestFilesMixin`` ---------------------- diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index 7e6c4f62cc..e2d1c84a5f 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -217,10 +217,6 @@ Minor features replaces paths to JavaScript source map references with their hashed counterparts. -* :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` now - replaces paths to JavaScript modules in ``import`` and ``export`` statements - with their hashed counterparts. - * The new ``manifest_storage`` argument of :class:`~django.contrib.staticfiles.storage.ManifestFilesMixin` and :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` diff --git a/tests/staticfiles_tests/project/documents/absolute_root.js b/tests/staticfiles_tests/project/documents/absolute_root.js deleted file mode 100644 index 4561b0389b..0000000000 --- a/tests/staticfiles_tests/project/documents/absolute_root.js +++ /dev/null @@ -1,2 +0,0 @@ -const rootConst = "root"; -export default rootConst; diff --git a/tests/staticfiles_tests/project/documents/cached/module.js b/tests/staticfiles_tests/project/documents/cached/module.js deleted file mode 100644 index 7380ad7856..0000000000 --- a/tests/staticfiles_tests/project/documents/cached/module.js +++ /dev/null @@ -1,22 +0,0 @@ -// Static imports. -import rootConst from "/static/absolute_root.js"; -import testConst from "./module_test.js"; -import * as NewModule from "./module_test.js"; -import { testConst as alias } from "./module_test.js"; -import { firstConst, secondConst } from "./module_test.js"; -import { - firstVar as firstVarAlias, - secondVar as secondVarAlias -} from "./module_test.js"; -import relativeModule from "../nested/js/nested.js"; - -// Dynamic imports. -const dynamicModule = import("./module_test.js"); - -// Modules exports to aggregate modules. -export * from "./module_test.js"; -export { testConst } from "./module_test.js"; -export { - firstVar as firstVarAlias, - secondVar as secondVarAlias -} from "./module_test.js"; diff --git a/tests/staticfiles_tests/project/documents/cached/module_test.js b/tests/staticfiles_tests/project/documents/cached/module_test.js deleted file mode 100644 index b832b4e8a7..0000000000 --- a/tests/staticfiles_tests/project/documents/cached/module_test.js +++ /dev/null @@ -1,5 +0,0 @@ -export const testConst = "test"; -export const firstConst = "first"; -export const secondConst = "second"; -export var firstVar = "test_1"; -export var SecondVar = "test_2"; diff --git a/tests/staticfiles_tests/project/documents/nested/js/nested.js b/tests/staticfiles_tests/project/documents/nested/js/nested.js deleted file mode 100644 index 7646bbd17d..0000000000 --- a/tests/staticfiles_tests/project/documents/nested/js/nested.js +++ /dev/null @@ -1 +0,0 @@ -export default null; diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index 93335480be..41d98d4332 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -160,52 +160,6 @@ class TestHashedFiles: self.assertIn(b"https://", relfile.read()) self.assertPostCondition() - def test_module_import(self): - relpath = self.hashed_file_path('cached/module.js') - self.assertEqual(relpath, 'cached/module.91b9cf9935da.js') - tests = [ - # Relative imports. - b'import testConst from "./module_test.d489af3cf882.js";', - b'import relativeModule from "../nested/js/nested.866475c46bb4.js";', - b'import { firstConst, secondConst } from "./module_test.d489af3cf882.js";', - # Absolute import. - b'import rootConst from "/static/absolute_root.5586327fe78c.js";', - # Dynamic import. - b'const dynamicModule = import("./module_test.d489af3cf882.js");', - # Creating a module object. - b'import * as NewModule from "./module_test.d489af3cf882.js";', - # Aliases. - b'import { testConst as alias } from "./module_test.d489af3cf882.js";', - b'import {\n' - b' firstVar as firstVarAlias,\n' - b' secondVar as secondVarAlias\n' - b'} from "./module_test.d489af3cf882.js";', - ] - with storage.staticfiles_storage.open(relpath) as relfile: - content = relfile.read() - for module_import in tests: - with self.subTest(module_import=module_import): - self.assertIn(module_import, content) - self.assertPostCondition() - - def test_aggregating_modules(self): - relpath = self.hashed_file_path('cached/module.js') - self.assertEqual(relpath, 'cached/module.91b9cf9935da.js') - tests = [ - b'export * from "./module_test.d489af3cf882.js";', - b'export { testConst } from "./module_test.d489af3cf882.js";', - b'export {\n' - b' firstVar as firstVarAlias,\n' - b' secondVar as secondVarAlias\n' - b'} from "./module_test.d489af3cf882.js";', - ] - with storage.staticfiles_storage.open(relpath) as relfile: - content = relfile.read() - for module_import in tests: - with self.subTest(module_import=module_import): - self.assertIn(module_import, content) - self.assertPostCondition() - @override_settings( STATICFILES_DIRS=[os.path.join(TEST_ROOT, 'project', 'loop')], STATICFILES_FINDERS=['django.contrib.staticfiles.finders.FileSystemFinder'],