Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: Use new stats format on loader
  • Loading branch information
gilmrjc committed Jul 28, 2020
commit 017fd795510c7b74bfe720447abcce14a8261649
4 changes: 2 additions & 2 deletions tests/app/tests/test_webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_timeouts(self):
with open(
settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'], 'w'
) as stats_file:
stats_file.write(json.dumps({'status': 'compiling'}))
stats_file.write(json.dumps({'status': 'compile'}))
loader = get_loader(DEFAULT_CONFIG)
loader.config['TIMEOUT'] = 0.1
with self.assertRaises(WebpackLoaderTimeoutError):
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_request_blocking(self):
view = TemplateView.as_view(template_name='home.html')

with self.settings(DEBUG=True):
open(settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'], 'w').write(json.dumps({'status': 'compiling'}))
open(settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'], 'w').write(json.dumps({'status': 'compile'}))
then = time.time()
request = self.factory.get('/')
result = view(request)
Expand Down
23 changes: 16 additions & 7 deletions webpack_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ def get_assets(self):
return self.load_assets()

def filter_chunks(self, chunks):
assets = self.get_assets()

for chunk in chunks:
ignore = any(regex.match(chunk['name'])
ignore = any(regex.match(chunk)
for regex in self.config['ignores'])
if not ignore:
chunk['url'] = self.get_chunk_url(chunk)
yield chunk
files = assets['assets']
url = self.get_chunk_url(files[chunk])
yield { 'name': chunk, 'url': url }

def get_chunk_url(self, chunk):
public_path = chunk.get('publicPath')
def get_chunk_url(self, chunk_file):
public_path = chunk_file.get('publicPath')
if public_path:
return public_path

relpath = '{0}{1}'.format(
self.config['BUNDLE_DIR_NAME'], chunk['name']
self.config['BUNDLE_DIR_NAME'], chunk_file['name']
)
return staticfiles_storage.url(relpath)

Expand All @@ -64,7 +67,7 @@ def get_bundle(self, bundle_name):
timeout = self.config['TIMEOUT'] or 0
timed_out = False
start = time.time()
while assets['status'] == 'compiling' and not timed_out:
while assets['status'] == 'compile' and not timed_out:
time.sleep(self.config['POLL_INTERVAL'])
if timeout and (time.time() - timeout > start):
timed_out = True
Expand All @@ -80,6 +83,12 @@ def get_bundle(self, bundle_name):
chunks = assets['chunks'].get(bundle_name, None)
if chunks is None:
raise WebpackBundleLookupError('Cannot resolve bundle {0}.'.format(bundle_name))

for chunk in chunks:
asset = assets['assets'][chunk]
if asset is None:
raise WebpackBundleLookupError('Cannot resolve asset {0}.'.format(chunk))

return self.filter_chunks(chunks)

elif assets.get('status') == 'error':
Expand Down