File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -211,6 +211,14 @@ def test_it_reports_modules_as_such(self):
211211
212212 assert _resolve_text_type (response , "js" ) == ESM_TEXT_TYPE
213213
214+ @pytest .mark .parametrize ("text_type" , ["css" , "html" , None ])
215+ def test_it_leaves_non_js_under_the_module_modifier_to_pywb (self , text_type ):
216+ # A module resolves assets relative to `import.meta.url`, which carries
217+ # the module modifier, so CSS and images arrive under it too.
218+ response = self .response_for (f"{ ESM_MOD } /https://example.com/style.css" )
219+
220+ assert _resolve_text_type (response , text_type ) == text_type
221+
214222 def test_it_leaves_everything_else_to_pywb (self ):
215223 response = self .response_for ("js_/https://example.com/app.js" )
216224
Original file line number Diff line number Diff line change @@ -96,10 +96,14 @@ def _resolve_text_type(self, text_type):
9696 module is left to the original.
9797 """
9898
99- if self .url_rewriter .wburl .mod == ESM_MOD :
99+ text_type = _PYWB_RESOLVE_TEXT_TYPE (self , text_type )
100+
101+ # Only JS gets the module wrapper: assets a module resolves relative to
102+ # `import.meta.url` (CSS, images) arrive under the module modifier too.
103+ if text_type == "js" and self .url_rewriter .wburl .mod == ESM_MOD :
100104 return ESM_TEXT_TYPE
101105
102- return _PYWB_RESOLVE_TEXT_TYPE ( self , text_type )
106+ return text_type
103107
104108
105109def _patch_esm_rewriting ():
You can’t perform that action at this time.
0 commit comments