From bbf6ea5b20259ba4b85c87dff3db7fe761ee24ee Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Wed, 17 Jan 2024 09:47:59 +0700 Subject: [PATCH 1/5] chore(web): normalizes worker source paths in srcmap --- common/web/lm-worker/build.sh | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/common/web/lm-worker/build.sh b/common/web/lm-worker/build.sh index b7b50071618..e73e90e551e 100755 --- a/common/web/lm-worker/build.sh +++ b/common/web/lm-worker/build.sh @@ -28,10 +28,13 @@ LIB=./build/lib bundle_cmd="node ../es-bundling/build/common-bundle.mjs" +SRCMAP_CLEANER="node $KEYMAN_ROOT/web/build/tools/building/sourcemap-root/index.js" + ################################ Main script ################################ builder_describe \ "Compiles the Language Modeling Layer for common use in predictive text and autocorrective applications." \ + "@/web/src/tools/building/sourcemap-root" \ "@/common/web/keyman-version" \ "@/common/web/es-bundling" \ "@/common/models/wordbreakers" \ @@ -49,12 +52,24 @@ function do_build() { tsc -b $builder_verbose || builder_die "Could not build worker." $bundle_cmd build/obj/worker-main.js \ - --out $INTERMEDIATE/worker-main.es5.js + --out $INTERMEDIATE/worker-main.es5.js \ + --sourceRoot '@keymanapp/keyman/common/web/lm-worker/src/main' + + $SRCMAP_CLEANER \ + $INTERMEDIATE/worker-main.es5.js.map \ + $INTERMEDIATE/worker-main.es5.js.map \ + --clean $bundle_cmd build/obj/worker-main.js \ --out $INTERMEDIATE/worker-main.min.es5.js \ --minify \ - --profile build/filesize-profile.es5.log + --profile build/filesize-profile.es5.log \ + --sourceRoot '@keymanapp/keyman/common/web/lm-worker/src/main' + + $SRCMAP_CLEANER \ + $INTERMEDIATE/worker-main.min.es5.js.map \ + $INTERMEDIATE/worker-main.min.es5.js.map \ + --clean EXT_FLAGS= if builder_has_option --ci; then @@ -79,13 +94,25 @@ function do_build() { # The ES6 target needs no polyfills - we go straight to the wrapped version. $bundle_cmd src/main/worker-main.ts \ --out $INTERMEDIATE/worker-main.js \ - --target "es6" + --target "es6" \ + --sourceRoot '@keymanapp/keyman/common/web/lm-worker/src/main' + + $SRCMAP_CLEANER \ + $INTERMEDIATE/worker-main.js.map \ + $INTERMEDIATE/worker-main.js.map \ + --clean $bundle_cmd src/main/worker-main.ts \ --out $INTERMEDIATE/worker-main.min.js \ --minify \ --profile build/filesize-profile.log \ - --target "es6" + --target "es6" \ + --sourceRoot '@keymanapp/keyman/common/web/lm-worker/src/main' + + $SRCMAP_CLEANER \ + $INTERMEDIATE/worker-main.min.js.map \ + $INTERMEDIATE/worker-main.min.js.map \ + --clean node build-wrapper.js $INTERMEDIATE/worker-main.js \ --out $LIB/worker-main.wrapped.js \ From 5a0a79e93bb42f17fde734a1b60415d548d081aa Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Wed, 17 Jan 2024 11:34:53 +0700 Subject: [PATCH 2/5] chore(web): inlines app/webview sourcemap b/c Android WebView inspection reqt --- .../java/com/keyman/engine/KMManager.java | 8 ----- .../Classes/Resource Management/Storage.swift | 7 ---- ios/engine/build.sh | 6 ---- web/src/app/webview/build.sh | 12 ++++--- .../tools/building/sourcemap-root/index.ts | 33 +++++++++++++++---- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index 3f9135bd9c1..3bb5c82e06c 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -293,9 +293,7 @@ public String toString() { protected static final String KMFilename_KeyboardHtml = "keyboard.html"; protected static final String KMFilename_KeyboardHtml_Legacy = "keyboard.es5.html"; protected static final String KMFilename_JSEngine = "keymanweb-webview.js"; - protected static final String KMFilename_JSEngine_Sourcemap = "keymanweb-webview.js.map"; protected static final String KMFilename_JSLegacyEngine = "keymanweb-webview.es5.js"; - protected static final String KMFilename_JSLegacyEngine_Sourcemap = "keymanweb-webview.es5.js.map"; protected static final String KMFilename_JSSentry = "sentry.min.js"; protected static final String KMFilename_JSSentryInit = "keyman-sentry.js"; protected static final String KMFilename_AndroidHost = "android-host.js"; @@ -867,17 +865,11 @@ private static void copyAssets(Context context) { copyAssetWithRename(context, KMFilename_KeyboardHtml_Legacy, KMFilename_KeyboardHtml, "", true); copyAsset(context, KMFilename_JSLegacyEngine, "", true); - if (KMManager.isDebugMode()) { - copyAsset(context, KMFilename_JSLegacyEngine_Sourcemap, "", true); - } } else { copyAsset(context, KMFilename_KeyboardHtml, "", true); // For versions of Chrome with full ES6 support, we use the ES6 artifact. copyAsset(context, KMFilename_JSEngine, "", true); - if (KMManager.isDebugMode()) { - copyAsset(context, KMFilename_JSEngine_Sourcemap, "", true); - } } // Is still built targeting ES5. diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/Storage.swift b/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/Storage.swift index a344d445b95..98c2ce877aa 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/Storage.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/Storage.swift @@ -236,13 +236,6 @@ extension Storage { resourceName: "keyman-sentry.js", dstDir: baseDir, excludeFromBackup: true) - // For debug compilations - IF we have a sourcemap file, copy that over too. - if bundle.url(forResource: "keymanweb-webview.js.map", withExtension: nil) != nil { - try Storage.copy(from: bundle, - resourceName: "keymanweb-webview.js.map", - dstDir: baseDir, - excludeFromBackup: true) - } try Storage.copy(from: bundle, resourceName: "kmwosk.css", dstDir: baseDir, diff --git a/ios/engine/build.sh b/ios/engine/build.sh index 8a77c519ce1..910440a97fa 100755 --- a/ios/engine/build.sh +++ b/ios/engine/build.sh @@ -111,12 +111,6 @@ function update_bundle ( ) { cp "$KMW_RESOURCES/osk/keymanweb-osk.ttf" "$BUNDLE_PATH/keymanweb-osk.ttf" cp "$KMW_PRODUCT/keymanweb-webview.js" "$BUNDLE_PATH/keymanweb-webview.js" - if builder_is_debug_build; then - cp "$KMW_PRODUCT/keymanweb-webview.js.map" "$BUNDLE_PATH/keymanweb-webview.js.map" - else - rm -f "$BUNDLE_PATH/keymanweb-webview.js.map" - fi - cp "$KEYMAN_ROOT/node_modules/@sentry/browser/build/bundle.min.js" "$BUNDLE_PATH/sentry.min.js" cp "$KEYMAN_ROOT/common/web/sentry-manager/build/lib/index.js" "$BUNDLE_PATH/keyman-sentry.js" } diff --git a/web/src/app/webview/build.sh b/web/src/app/webview/build.sh index 4e6c7a6440a..d471dfa21ea 100755 --- a/web/src/app/webview/build.sh +++ b/web/src/app/webview/build.sh @@ -72,12 +72,16 @@ compile_and_copy() { cp -R "$KEYMAN_ROOT/web/src/resources/osk/." "$KEYMAN_ROOT/web/build/app/resources/osk/" # Clean the sourcemaps of .. and . components - for sourcemap in "$KEYMAN_ROOT/web/build/$SUBPROJECT_NAME/debug/"*.map; do - node "$KEYMAN_ROOT/web/build/tools/building/sourcemap-root/index.js" null "$sourcemap" --clean + for script in "$KEYMAN_ROOT/web/build/$SUBPROJECT_NAME/debug/"*.js; do + sourcemap="$script.map" + node "$KEYMAN_ROOT/web/build/tools/building/sourcemap-root/index.js" \ + "$script" "$sourcemap" --clean --inline done - for sourcemap in "$KEYMAN_ROOT/web/build/$SUBPROJECT_NAME/release/"*.map; do - node "$KEYMAN_ROOT/web/build/tools/building/sourcemap-root/index.js" null "$sourcemap" --clean + for script in "$KEYMAN_ROOT/web/build/$SUBPROJECT_NAME/release/"*.js; do + sourcemap="$script.map" + node "$KEYMAN_ROOT/web/build/tools/building/sourcemap-root/index.js" \ + "$script" "$sourcemap" --clean --inline done node map-polyfill-bundler.js diff --git a/web/src/tools/building/sourcemap-root/index.ts b/web/src/tools/building/sourcemap-root/index.ts index 6b42f499b95..20c5c0135d2 100644 --- a/web/src/tools/building/sourcemap-root/index.ts +++ b/web/src/tools/building/sourcemap-root/index.ts @@ -1,13 +1,19 @@ import SourcemapRemapper from "@keymanapp/sourcemap-path-remapper" +import convertSourceMap from 'convert-source-map'; // Transforms sourcemaps among various common formats. + // Base64, stringified-JSON, end-of-file comment... +import fs from 'fs'; function displayHelp() { console.log("KeymanWeb's sourcemap-cleansing tool. This tool is designed to produce clean filepaths"); console.log("in the sourcemaps for ease of reference in browser and Sentry, copying the clean paths TS"); console.log("is able to provide, whereas Closure's minification is not."); console.log(""); - console.log("Usage: node sourcemap-root [-c|--clean] [-s|--sourceRoot ]"); + console.log("Usage: node sourcemap-root [-c|--clean] [-s|--sourceRoot ]"); console.log(" -c|--clean Runs source-filepath cleaning operations."); + console.log(" -i|--inline Inlines as a comment within ."); console.log(" -s|--sourceRoot Sets the input sourcemap's 'sourceRoot' to ."); + console.log(""); + console.log(" is ignored unless the --inline option is specified."); } // By default, any node-based process has two command-line args: @@ -38,15 +44,17 @@ function assert_is_map(filename: string) { process.exit(1); } } -// Verify the first parameter is a sourcemap filepath. -// let sourceFile = process.argv[2]; // Used to be necessary, but no longer is. -let destFile = process.argv[3]; -assert_is_map(destFile); +// Verify the second parameter is a sourcemap filepath. +let scriptFile = process.argv[2]; +let mapFile = process.argv[3]; + +assert_is_map(mapFile); // Now to process any additional flags. var sourceRoot = ""; let shouldClean = false; +let shouldInline = false; // Starting at [5] - optional command-line arguments for(let procArgIndex = 4; procArgIndex < process.argv.length; procArgIndex++) { @@ -62,6 +70,10 @@ for(let procArgIndex = 4; procArgIndex < process.argv.length; procArgIndex++) { case "--clean": shouldClean = true; break; + case "-i": + case "--inline": + shouldInline = true; + break; case "-s": case "--sourceRoot": procArgIndex++; @@ -72,7 +84,7 @@ for(let procArgIndex = 4; procArgIndex < process.argv.length; procArgIndex++) { } } -let srcMap = SourcemapRemapper.fromFile(destFile); +let srcMap = SourcemapRemapper.fromFile(mapFile); if(shouldClean) { // Keeps "@keymanapp/keyman" as sourceRoot, but prepends all `sources` entries with @@ -84,4 +96,11 @@ if(sourceRoot) { srcMap.sourceRoot = sourceRoot; } -srcMap.toFile(destFile); \ No newline at end of file +srcMap.toFile(mapFile); + +if(shouldInline) { + const mapToInline = SourcemapRemapper.fromFile(mapFile).sourceRoot; + const inlineableComment = convertSourceMap.fromObject(mapToInline).toComment(); + + fs.appendFileSync(scriptFile, `\n${inlineableComment}`); +} From 2296c9f4f48dc1c21fb923d478aef25066b4134b Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Wed, 17 Jan 2024 12:02:27 +0700 Subject: [PATCH 3/5] change(web): inlined srcmaps only for debug, not release --- web/src/app/webview/build.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/src/app/webview/build.sh b/web/src/app/webview/build.sh index d471dfa21ea..28acdde1272 100755 --- a/web/src/app/webview/build.sh +++ b/web/src/app/webview/build.sh @@ -78,10 +78,12 @@ compile_and_copy() { "$script" "$sourcemap" --clean --inline done + # Do NOT inline sourcemaps for release builds - we don't want them to affect + # load time. for script in "$KEYMAN_ROOT/web/build/$SUBPROJECT_NAME/release/"*.js; do sourcemap="$script.map" node "$KEYMAN_ROOT/web/build/tools/building/sourcemap-root/index.js" \ - "$script" "$sourcemap" --clean --inline + "$script" "$sourcemap" --clean done node map-polyfill-bundler.js From 4f98977859a9db1294444d3e2875bccc1ceeb883 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Mon, 22 Jan 2024 11:11:50 +0700 Subject: [PATCH 4/5] fix(android/engine): Add RECEIVER_EXPORTED flag for broadcast receiver --- .../com/keyman/engine/cloud/CloudDownloadMgr.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/cloud/CloudDownloadMgr.java b/android/KMEA/app/src/main/java/com/keyman/engine/cloud/CloudDownloadMgr.java index 87e96353df4..8c0d4403cb1 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/cloud/CloudDownloadMgr.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/cloud/CloudDownloadMgr.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.net.Uri; +import android.os.Build; import android.util.Log; import com.keyman.engine.util.KMLog; @@ -59,7 +60,15 @@ public synchronized void initialize(Context aContext) if(isInitialized) return; try { - aContext.registerReceiver(completeListener, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); + // Runtime-registered boradcasts receivers must specify export behavior to indicate whether + // or not the receiver should be exported to all other apps on the device + // https://developer.android.com/about/versions/14/behavior-changes-14#runtime-receivers-exported + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + aContext.registerReceiver(completeListener, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), + Context.RECEIVER_EXPORTED); + } else { + aContext.registerReceiver(completeListener, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); + } } catch (IllegalStateException e) { String message = "initialize error: "; KMLog.LogException(TAG, message, e); From 7e1629431a0a6aa4f4df6717549787fd2ea0bf10 Mon Sep 17 00:00:00 2001 From: Keyman Build Agent Date: Mon, 22 Jan 2024 13:02:45 -0500 Subject: [PATCH 5/5] auto: increment master version to 17.0.250 --- HISTORY.md | 5 +++++ VERSION.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 63340a2f0a9..c851fcd5335 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,10 @@ # Keyman Version History +## 17.0.249 alpha 2024-01-22 + +* feat(web): suggestion banner UI enhancements - suggestion expanding + scrollable banner (#7934) +* chore(web): worker sourcemap cleanup, mobile app webview sourcemap compat (#10413) + ## 17.0.248 alpha 2024-01-19 * chore(android): Update targetSdkVersion to 34 (#10393) diff --git a/VERSION.md b/VERSION.md index 2cefd7daf49..a6fde2b0554 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -17.0.249 \ No newline at end of file +17.0.250 \ No newline at end of file