Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop loading unsupported attributes into ManifestEntry #103

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion django_vite/core/asset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class ManifestEntry(NamedTuple):
file: str
src: Optional[str] = None
isEntry: Optional[bool] = False
isDynamicEntry: Optional[bool] = False
css: Optional[List[str]] = []
imports: Optional[List[str]] = []
dynamicImports: Optional[List[str]] = []


class ManifestClient:
Expand Down Expand Up @@ -166,7 +168,12 @@ def _parse_manifest(self) -> ParsedManifestOutput:
manifest_json = json.loads(manifest_content)

for path, manifest_entry_data in manifest_json.items():
manifest_entry = ManifestEntry(**manifest_entry_data)
filtered_manifest_entry_data = {
key: value
for key, value in manifest_entry_data.items()
if key in ManifestEntry._fields
}
manifest_entry = ManifestEntry(**filtered_manifest_entry_data)
entries[path] = manifest_entry
if self.legacy_polyfills_motif in path:
legacy_polyfills_entry = manifest_entry
Expand Down
19 changes: 19 additions & 0 deletions tests/data/staticfiles/dynamic-entry-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"main.js": {
"file": "assets/main.4889e940.js",
"src": "main.js",
"isEntry": true,
"dynamicImports": ["views/foo.js"],
"css": ["assets/main.b82dbe22.css"],
"assets": ["assets/asset.0ab0f9cd.png"]
},
"views/foo.js": {
"file": "assets/foo.869aea0d.js",
"src": "views/foo.js",
"isDynamicEntry": true,
"imports": ["_shared.83069a53.js"]
},
"_shared.83069a53.js": {
"file": "assets/shared.83069a53.js"
}
}
22 changes: 22 additions & 0 deletions tests/tests/test_asset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,25 @@ def test_parse_manifest_during_dev_mode(dev_mode_true):
default_app = DjangoViteAssetLoader.instance()._apps["default"]
manifest_client = default_app.manifest
assert manifest_client._parse_manifest() == manifest_client.ParsedManifestOutput()


@pytest.mark.parametrize(
"patch_settings",
[
{
"DJANGO_VITE_DEV_MODE": False,
"DJANGO_VITE_MANIFEST_PATH": "dynamic-entry-manifest.json",
},
{
"DJANGO_VITE": {
"default": {
"dev_mode": False,
"manifest_path": "dynamic-entry-manifest.json",
}
}
},
],
)
def test_load_dynamic_import_manifest(patch_settings):
warnings = check_loader_instance()
assert len(warnings) == 0