forked from MrBin99/django-vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check_loader_instance checks every app
- Loading branch information
Showing
2 changed files
with
62 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,21 @@ | ||
from contextlib import suppress | ||
|
||
from django.apps import AppConfig | ||
from django.core.checks import Warning, register | ||
from django.core import checks | ||
|
||
from .core.exceptions import DjangoViteManifestError | ||
from .templatetags.django_vite import DjangoViteAssetLoader | ||
from django_vite.core.asset_loader import DjangoViteAssetLoader | ||
|
||
|
||
class DjangoViteAppConfig(AppConfig): | ||
name = "django_vite" | ||
verbose_name = "Django Vite" | ||
|
||
def ready(self) -> None: | ||
with suppress(DjangoViteManifestError): | ||
# Create Loader instance at startup to prevent threading problems, | ||
# but do not crash while doing so. | ||
DjangoViteAssetLoader.instance() | ||
# Make Loader instance at startup to prevent threading problems | ||
# but do not crash while doing so. | ||
DjangoViteAssetLoader.instance() | ||
|
||
# Check for potential errors with loading manifests in DjangoViteConfigs. | ||
checks.register(check_loader_instance, checks.Tags.staticfiles) | ||
|
||
@register | ||
def check_loader_instance(**kwargs): | ||
"""Raise a warning during startup when instance retrieval fails.""" | ||
|
||
try: | ||
# Make Loader instance at startup to prevent threading problems | ||
DjangoViteAssetLoader.instance() | ||
return [] | ||
except DjangoViteManifestError as exception: | ||
return [ | ||
Warning( | ||
exception, | ||
id="DJANGO_VITE", | ||
hint=( | ||
"Make sure you have generated a manifest file, " | ||
"and that the DJANGO_VITE_MANIFEST_PATH points " | ||
"to the correct location." | ||
), | ||
) | ||
] | ||
def check_loader_instance(**kwargs): | ||
return DjangoViteAssetLoader.instance().check(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters