Fix new manifest path (#6814)

* fix manifest path

* simplify

* add falback for old path

* fix var name

* remove css lookup, not needed anymore

* fix test path
This commit is contained in:
Matthias Mair 2024-03-22 10:15:20 +01:00 committed by GitHub
parent 32d161852a
commit 6ff4d5e035
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 16 deletions

View File

@ -24,14 +24,20 @@ def spa_bundle(manifest_path: Union[str, Path] = '', app: str = 'web'):
return f'{settings.STATIC_URL}{app}/{file}'
if manifest_path == '':
manifest_path = Path(__file__).parent.parent.joinpath(
'static/web/manifest.json'
manifest = Path(__file__).parent.parent.joinpath(
'static/web/.vite/manifest.json'
)
manifest = Path(manifest_path)
else:
manifest = Path(manifest_path)
if not manifest.exists():
logger.error('Manifest file not found')
return
# Try old path for manifest file
manifest = Path(__file__).parent.parent.joinpath('static/web/manifest.json')
# Final check - fail if manifest file not found
if not manifest.exists():
logger.error('Manifest file not found')
return
try:
manifest_data = json.load(manifest.open())
@ -40,13 +46,6 @@ def spa_bundle(manifest_path: Union[str, Path] = '', app: str = 'web'):
return
return_string = ''
# CSS (based on index.css file as entrypoint)
css_index = manifest_data.get('index.css')
if css_index:
return_string += (
f'<link rel="stylesheet" href="{get_url(css_index["file"])}" />'
)
# JS (based on index.html file as entrypoint)
index = manifest_data.get('index.html')
dynamic_files = index.get('dynamicImports', [])

View File

@ -26,14 +26,11 @@ class TemplateTagTest(InvenTreeTestCase):
def test_spa_bundle(self):
"""Test the 'spa_bundle' template tag."""
resp = spa_helper.spa_bundle()
self.assertTrue(
resp.startswith('<link rel="stylesheet" href="/static/web/assets/index')
)
shipped_js = resp.split('<script type="module" src="')[1:]
self.assertTrue(len(shipped_js) > 0)
self.assertTrue(len(shipped_js) == 3)
manifest_file = Path(__file__).parent.joinpath('static/web/manifest.json')
manifest_file = Path(__file__).parent.joinpath('static/web/.vite/manifest.json')
# Try with removed manifest file
manifest_file.rename(manifest_file.with_suffix('.json.bak')) # Rename
resp = resp = spa_helper.spa_bundle()