mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
Fix browser error reporting to find webpack source map files.
When we switched to using webpack, source map files weren't being logged in the expected place.
This commit is contained in:
committed by
Tim Abbott
parent
7778a66171
commit
5932896ebb
@@ -5,15 +5,15 @@ import os.path
|
|||||||
import sourcemap
|
import sourcemap
|
||||||
from six.moves import map
|
from six.moves import map
|
||||||
|
|
||||||
from typing import Dict, Text
|
from typing import Dict, List, Text
|
||||||
|
|
||||||
|
|
||||||
class SourceMap(object):
|
class SourceMap(object):
|
||||||
'''Map (line, column) pairs from generated to source file.'''
|
'''Map (line, column) pairs from generated to source file.'''
|
||||||
|
|
||||||
def __init__(self, sourcemap_dir):
|
def __init__(self, sourcemap_dirs):
|
||||||
# type: (Text) -> None
|
# type: (List[Text]) -> None
|
||||||
self._dir = sourcemap_dir
|
self._dirs = sourcemap_dirs
|
||||||
self._indices = {} # type: Dict[Text, sourcemap.SourceMapDecoder]
|
self._indices = {} # type: Dict[Text, sourcemap.SourceMapDecoder]
|
||||||
|
|
||||||
def _index_for(self, minified_src):
|
def _index_for(self, minified_src):
|
||||||
@@ -21,8 +21,12 @@ class SourceMap(object):
|
|||||||
'''Return the source map index for minified_src, loading it if not
|
'''Return the source map index for minified_src, loading it if not
|
||||||
already loaded.'''
|
already loaded.'''
|
||||||
if minified_src not in self._indices:
|
if minified_src not in self._indices:
|
||||||
with open(os.path.join(self._dir, minified_src + '.map')) as fp:
|
for source_dir in self._dirs:
|
||||||
|
filename = os.path.join(source_dir, minified_src + '.map')
|
||||||
|
if os.path.isfile(filename):
|
||||||
|
with open(filename) as fp:
|
||||||
self._indices[minified_src] = sourcemap.load(fp)
|
self._indices[minified_src] = sourcemap.load(fp)
|
||||||
|
break
|
||||||
|
|
||||||
return self._indices[minified_src]
|
return self._indices[minified_src]
|
||||||
|
|
||||||
@@ -31,7 +35,7 @@ class SourceMap(object):
|
|||||||
out = '' # type: Text
|
out = '' # type: Text
|
||||||
for ln in stacktrace.splitlines():
|
for ln in stacktrace.splitlines():
|
||||||
out += ln + '\n'
|
out += ln + '\n'
|
||||||
match = re.search(r'/static/min/(.+)(\.[0-9a-f]+)\.js:(\d+):(\d+)', ln)
|
match = re.search(r'/static/(?:webpack-bundles|min)/(.+)(\.[\.0-9a-f]+)\.js:(\d+):(\d+)', ln)
|
||||||
if match:
|
if match:
|
||||||
# Get the appropriate source map for the minified file.
|
# Get the appropriate source map for the minified file.
|
||||||
minified_src = match.groups()[0] + '.js'
|
minified_src = match.groups()[0] + '.js'
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ def get_js_source_map():
|
|||||||
# type: () -> Optional[SourceMap]
|
# type: () -> Optional[SourceMap]
|
||||||
global js_source_map
|
global js_source_map
|
||||||
if not js_source_map and not (settings.DEVELOPMENT or settings.TEST_SUITE):
|
if not js_source_map and not (settings.DEVELOPMENT or settings.TEST_SUITE):
|
||||||
js_source_map = SourceMap(os.path.join(
|
js_source_map = SourceMap([
|
||||||
settings.DEPLOY_ROOT, 'prod-static/source-map'))
|
os.path.join(settings.DEPLOY_ROOT, 'prod-static/source-map'),
|
||||||
|
os.path.join(settings.DEPLOY_ROOT, 'prod-static/serve/webpack-bundles')
|
||||||
|
])
|
||||||
return js_source_map
|
return js_source_map
|
||||||
|
|
||||||
@authenticated_json_post_view
|
@authenticated_json_post_view
|
||||||
|
|||||||
Reference in New Issue
Block a user