Skip to content

Commit

Permalink
Remove Nix store path from source maps
Browse files Browse the repository at this point in the history
Obelisk successfully serves minified JS, the corresponding unminified JS,
and the source map that relates the two. But the source map's `sources`
field contains the Nix store path of the unminified JS, not a URL. Browsers
try to fetch the source code from a bogus URL:
`https://example.com/nix/store/HASH-compressedJs/frontend.jsexe/all.unminified.js`.

This change improves the situation by tweaking the arguments to
`closure-compiler`; using relative paths to the JS files instead of absolute
paths.

Works on Chromium, but Firefox still has trouble.
  • Loading branch information
isaac-uptrust committed Jun 5, 2024
1 parent b50ac6a commit e5c61ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project's release branch is `master`. This log is written from the perspect

* Obelisk.Route: add pathQueryEncoder and generalizeIdentity
* [#1071](https://github.com/obsidiansystems/obelisk/pull/1071): Support deployment information repository sub-directories
* [#1084](https://github.com/obsidiansystems/obelisk/pull/1084): Fix source maps on Chrome

## v1.3.0.0
* [#1047](https://github.com/obsidiansystems/obelisk/pull/1047): Update default ios sdk to 15
Expand Down
32 changes: 26 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,36 @@ in rec {
set -euo pipefail
cd '${haskellLib.justStaticExecutables frontend}'
shopt -s globstar
for f in **/all.js; do
dir="$out/$(basename "$(dirname "$f")")"
base=$(pwd)
mkdir -p "$out"
cd "$out"
for f in $base/**/all.js; do
dir="$(basename "$(dirname "$f")")"
mkdir -p "$dir"
ln -s "$(realpath "$f")" "$dir/all.unminified.js"
pushd "$dir"
ln -s "$(realpath "$f")" "$out/$dir/all.unminified.js"
${if optimizationLevel == null then ''
ln -s "$dir/all.unminified.js" "$dir/all.js"
ln -s "$out/$dir/all.unminified.js" "$out/$dir/all.js"
'' else ''
# NOTE: "--error_format JSON" avoids closurecompiler crashes when trying to report errors.
'${pkgs.closurecompiler}/bin/closure-compiler' --error_format JSON ${if externs == null then "" else "--externs '${externs}'"} --externs '${reflex-platform.ghcjsExternsJs}' -O '${optimizationLevel}' --jscomp_warning=checkVars --warning_level=QUIET --create_source_map="$dir/all.js.map" --source_map_format=V3 --js_output_file="$dir/all.js" "$dir/all.unminified.js"
echo '//# sourceMappingURL=all.js.map' >> "$dir/all.js"
'${pkgs.closurecompiler}/bin/closure-compiler' \
--error_format JSON \
${if externs == null then "" else "--externs '${externs}'"} \
--externs '${reflex-platform.ghcjsExternsJs}' \
-O '${optimizationLevel}' \
--jscomp_warning=checkVars \
--warning_level=QUIET \
--create_source_map="all.js.map" \
--source_map_format=V3 \
--js_output_file="all.js" \
"all.unminified.js"
echo '//# sourceMappingURL=all.js.map' >> "all.js"
popd
''}
done
'';
Expand Down

0 comments on commit e5c61ed

Please sign in to comment.