From e5c61ed7165d5fcfb6df96ffd27fb0ac7a7ee37b Mon Sep 17 00:00:00 2001 From: Isaac Elliott Date: Wed, 5 Jun 2024 14:17:58 +1000 Subject: [PATCH] Remove Nix store path from source maps 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. --- ChangeLog.md | 1 + default.nix | 32 ++++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 01cd5df1e..ef85d8e9f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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 diff --git a/default.nix b/default.nix index 29fd2126f..67a7ab9e8 100644 --- a/default.nix +++ b/default.nix @@ -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 '';