Skip to content

Commit

Permalink
Merge pull request #11881 from keymanapp/change/web/11878_remove-es5
Browse files Browse the repository at this point in the history
change(web): remove support for es5 🏗️
  • Loading branch information
ermshiperete committed Jul 31, 2024
2 parents e8e28b6 + 1389d40 commit 10ed10d
Show file tree
Hide file tree
Showing 46 changed files with 181 additions and 335 deletions.
2 changes: 0 additions & 2 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ KMEA/**/assets/keymanandroid.js
KMEA/**/assets/keyman.js.map
KMEA/**/assets/keymanweb-webview.js
KMEA/**/assets/keymanweb-webview.js.map
KMEA/**/assets/keymanweb-webview.es5.js
KMEA/**/assets/keymanweb-webview.es5.js.map
KMEA/**/assets/map-polyfill.js
KMEA/**/assets/sentry.min.js
KMEA/**/assets/keyman-sentry.js
Expand Down
30 changes: 0 additions & 30 deletions android/KMEA/app/src/main/assets/keyboard.es5.html

This file was deleted.

32 changes: 5 additions & 27 deletions android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ public String toString() {

// Keyman files
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_JSLegacyEngine = "keymanweb-webview.es5.js";
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";
Expand Down Expand Up @@ -858,25 +856,11 @@ public static boolean copyHTMLBannerAssets(Context context, String path) {
private static void copyAssets(Context context) {
AssetManager assetManager = context.getAssets();

// Will build a temp WebView in order to check Chrome version internally.
boolean legacyMode = WebViewUtils.getEngineWebViewVersionStatus(context, null, null) != WebViewUtils.EngineWebViewVersionStatus.FULL;

try {
// Copy KMW files
if(legacyMode) {
// Replaces the standard ES6-friendly version of the host page with a legacy one that
// includes polyfill requests and that links the legacy, ES5-compatible version of KMW.
copyAssetWithRename(context, KMFilename_KeyboardHtml_Legacy, KMFilename_KeyboardHtml, "", true);

copyAsset(context, KMFilename_JSLegacyEngine, "", 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);
}
copyAsset(context, KMFilename_KeyboardHtml, "", true);

// Is still built targeting ES5.
copyAsset(context, KMFilename_JSEngine, "", true);
copyAsset(context, KMFilename_JSSentry, "", true);
copyAsset(context, KMFilename_JSSentryInit, "", true);
copyAsset(context, KMFilename_AndroidHost, "", true);
Expand All @@ -887,12 +871,6 @@ private static void copyAssets(Context context) {
// Copy default keyboard font
copyAsset(context, KMDefault_KeyboardFont, "", true);

if(legacyMode) {
copyAsset(context, KMFilename_JSPolyfill, "", true);
copyAsset(context, KMFilename_JSPolyfill2, "", true);
copyAsset(context, KMFilename_JSPolyfill3, "", true);
}

// Keyboard packages directory
File packagesDir = new File(getPackagesDir());
if (!packagesDir.exists()) {
Expand Down Expand Up @@ -1638,7 +1616,7 @@ public static boolean removeKeyboard(Context context, int position) {

public static boolean isDefaultKey(String key) {
return (
key != null &&
key != null &&
key.equals(KMString.format("%s_%s", KMDefault_LanguageID, KMDefault_KeyboardID)));
}

Expand Down Expand Up @@ -2084,11 +2062,11 @@ public static Point getWindowSize(Context context) {
wm.getDefaultDisplay().getSize(size);
return size;
}

WindowMetrics windowMetrics = wm.getCurrentWindowMetrics();
return new Point(
windowMetrics.getBounds().width(),
windowMetrics.getBounds().height());
windowMetrics.getBounds().height());
}

public static float getWindowDensity(Context context) {
Expand Down
2 changes: 0 additions & 2 deletions android/KMEA/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ if builder_start_action build:engine; then
echo "Copying Keyman Web artifacts"
cp "$KEYMAN_WEB_ROOT/build/app/webview/$CONFIG/keymanweb-webview.js" "$ENGINE_ASSETS/keymanweb-webview.js"
cp "$KEYMAN_WEB_ROOT/build/app/webview/$CONFIG/keymanweb-webview.js.map" "$ENGINE_ASSETS/keymanweb-webview.js.map"
cp "$KEYMAN_WEB_ROOT/build/app/webview/$CONFIG/keymanweb-webview.es5.js" "$ENGINE_ASSETS/keymanweb-webview.es5.js"
cp "$KEYMAN_WEB_ROOT/build/app/webview/$CONFIG/keymanweb-webview.es5.js.map" "$ENGINE_ASSETS/keymanweb-webview.es5.js.map"
cp "$KEYMAN_WEB_ROOT/build/app/webview/$CONFIG/map-polyfill.js" "$ENGINE_ASSETS/map-polyfill.js"
cp "$KEYMAN_WEB_ROOT/build/app/resources/osk/ajax-loader.gif" "$ENGINE_ASSETS/ajax-loader.gif"
cp "$KEYMAN_WEB_ROOT/build/app/resources/osk/kmwosk.css" "$ENGINE_ASSETS/kmwosk.css"
Expand Down
2 changes: 1 addition & 1 deletion common/tools/sourcemap-path-remapper/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"inlineSources": true,
"sourceRoot": "/common/tools/sourcemap-path-remapper/src",
"lib": ["dom", "es6"],
"target": "es5",
"target": "es6",
"types": ["node"],
"downlevelIteration": true,
"baseUrl": "./",
Expand Down
3 changes: 1 addition & 2 deletions common/web/es-bundling/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
################################ Main script ################################

builder_describe "Builds KMW's esbuild-oriented common configuration & tooling" \
"@/common/web/tslib" \
"clean" \
"configure" \
"build"
Expand All @@ -24,4 +23,4 @@ builder_parse "$@"

builder_run_action configure verify_npm_setup
builder_run_action clean rm -rf build/
builder_run_action build tsc -b tsconfig.json
builder_run_action build tsc -b tsconfig.json
4 changes: 2 additions & 2 deletions common/web/es-bundling/src/common-bundle.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let profilePath;
let sourceRoot;
let platform;

let jsVersionTarget='es5';
let jsVersionTarget='es6';

function doHelp(errCode?: number) {
console.log(`
Expand Down Expand Up @@ -141,4 +141,4 @@ const results = await esbuild.build(config);
if(results.metafile) {
let filesizeProfile = await esbuild.analyzeMetafile(results.metafile, { verbose: true });
fs.writeFileSync(profilePath, filesizeProfile);
}
}
7 changes: 2 additions & 5 deletions common/web/es-bundling/src/configuration.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import type * as esbuild from 'esbuild';
import { pluginForDowncompiledClassTreeshaking } from './classTreeshaker.mjs';

export const esmConfiguration: esbuild.BuildOptions = {
alias: {
'tslib': '@keymanapp/tslib'
},
bundle: true,
format: "esm",
outExtension: { '.js': '.mjs'},
plugins: [ pluginForDowncompiledClassTreeshaking ],
sourcemap: true,
sourcesContent: true,
target: "es5"
target: "es6"
};

export const iifeConfiguration: esbuild.BuildOptions = {
Expand Down Expand Up @@ -70,4 +67,4 @@ export function bundleObjEntryPoints(configFolder: 'lib' | 'debug' | 'release',
entryPoints: path,
outdir: mappedRoot
};
}
}
24 changes: 17 additions & 7 deletions common/web/keyboard-processor/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
. "${THIS_SCRIPT%/*}/../../../resources/build/builder.inc.sh"
## END STANDARD BUILD SCRIPT INCLUDE

. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
. "${KEYMAN_ROOT}/resources/shellHelperFunctions.sh"

BUNDLE_CMD="node $KEYMAN_ROOT/common/web/es-bundling/build/common-bundle.mjs"
BUNDLE_CMD="node ${KEYMAN_ROOT}/common/web/es-bundling/build/common-bundle.mjs"

################################ Main script ################################

Expand Down Expand Up @@ -42,25 +42,35 @@ function do_configure() {
}

function do_build() {
tsc --build "$THIS_SCRIPT_PATH/tsconfig.all.json"
tsc --build "${THIS_SCRIPT_PATH}/tsconfig.all.json"

# Base product - the main keyboard processor
$BUNDLE_CMD "${KEYMAN_ROOT}/common/web/keyboard-processor/build/obj/index.js" \
builder_echo "Bundle base product - the main keyboard processor"
${BUNDLE_CMD} "${KEYMAN_ROOT}/common/web/keyboard-processor/build/obj/index.js" \
--out "${KEYMAN_ROOT}/common/web/keyboard-processor/build/lib/index.mjs" \
--format esm

# The DOM-oriented keyboard loader
$BUNDLE_CMD "${KEYMAN_ROOT}/common/web/keyboard-processor/build/obj/keyboards/loaders/dom-keyboard-loader.js" \
builder_echo "Bundle the DOM-oriented keyboard loader"
${BUNDLE_CMD} "${KEYMAN_ROOT}/common/web/keyboard-processor/build/obj/keyboards/loaders/dom-keyboard-loader.js" \
--out "${KEYMAN_ROOT}/common/web/keyboard-processor/build/lib/dom-keyboard-loader.mjs" \
--format esm

# The Node-oriented keyboard loader
$BUNDLE_CMD "${KEYMAN_ROOT}/common/web/keyboard-processor/build/obj/keyboards/loaders/node-keyboard-loader.js" \
builder_echo "Bundle the Node-oriented keyboard loader"
${BUNDLE_CMD} "${KEYMAN_ROOT}/common/web/keyboard-processor/build/obj/keyboards/loaders/node-keyboard-loader.js" \
--out "${KEYMAN_ROOT}/common/web/keyboard-processor/build/lib/node-keyboard-loader.mjs" \
--format esm \
--platform node

# Tests
builder_echo "Bundle tests"
${BUNDLE_CMD} "${KEYMAN_ROOT}/common/web/keyboard-processor/build/tests/dom/cases/domKeyboardLoader.spec.js" \
--out "${KEYMAN_ROOT}/common/web/keyboard-processor/build/tests/dom/domKeyboardLoader.spec.mjs" \
--format esm

# Declaration bundling.
builder_echo "Declaration bundling"
tsc --emitDeclarationOnly --outFile ./build/lib/index.d.ts
tsc --emitDeclarationOnly --outFile ./build/lib/dom-keyboard-loader.d.ts -p src/keyboards/loaders/tsconfig.dom.json
tsc --emitDeclarationOnly --outFile ./build/lib/node-keyboard-loader.d.ts -p src/keyboards/loaders/tsconfig.node.json
Expand All @@ -82,4 +92,4 @@ function do_test() {
builder_run_action configure do_configure
builder_run_action clean rm -rf ./build
builder_run_action build do_build
builder_run_action test do_test
builder_run_action test do_test
5 changes: 2 additions & 3 deletions common/web/keyboard-processor/src/text/stringDivergence.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Future TODO: import from @keymanapp/common-types... once we no longer need to support ES5.
import { Uni_IsSurrogate1, Uni_IsSurrogate2 } from '@keymanapp/web-utils';
import { Uni_IsSurrogate1, Uni_IsSurrogate2 } from '@keymanapp/common-types';

/**
* Returns the index for the code point divergence point between two strings, as measured in code
Expand Down Expand Up @@ -90,4 +89,4 @@ export function findCommonSubstringEndIndex(str1: string, str2: string, commonSu
}

return index;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { assert } from 'chai';

import { DOMKeyboardLoader } from '@keymanapp/keyboard-processor/dom-keyboard-loader';
import { extendString, KeyboardHarness, Keyboard, KeyboardInterface, MinimalKeymanGlobal, Mock, DeviceSpec } from '@keymanapp/keyboard-processor';
import { extendString, KeyboardHarness, Keyboard, KeyboardInterface, MinimalKeymanGlobal, Mock, DeviceSpec, KeyboardKeymanGlobal } from '@keymanapp/keyboard-processor';

declare let window: typeof globalThis;
// KeymanEngine from the web/ folder... when available.
// At this level, though... we just mock it.
declare let keyman: KeyboardKeymanGlobal;
declare let KeymanWeb: KeyboardInterface;

// Note: rule processing tests will fail if string extensions are not established beforehand.
extendString();
Expand All @@ -15,8 +21,8 @@ const device: DeviceSpec = {

describe('Keyboard loading in DOM', function() {
afterEach(() => {
if(window['KeymanWeb']) {
window['KeymanWeb'].uninstall();
if (KeymanWeb) {
KeymanWeb.uninstall();
}
})

Expand All @@ -29,8 +35,10 @@ describe('Keyboard loading in DOM', function() {
assert.equal(keyboard.id, 'Keyboard_khmer_angkor');
assert.isTrue(keyboard.isChiral);
assert.isFalse(keyboard.isCJK);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);
assert.isOk(KeymanWeb);
assert.isOk(keyman);
assert.isOk(keyman.osk);
assert.isOk(keyman.osk.keyCodes);

// Should be cleared post-keyboard-load.
assert.isNotOk(harness.loadedKeyboard);
Expand All @@ -46,17 +54,21 @@ describe('Keyboard loading in DOM', function() {
assert.equal(keyboard.id, 'Keyboard_khmer_angkor');
assert.isTrue(keyboard.isChiral);
assert.isFalse(keyboard.isCJK);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);
assert.isOk(KeymanWeb);
assert.isOk(keyman);
assert.isOk(keyman.osk);
assert.isOk(keyman.osk.keyCodes);

// TODO: verify actual rule processing.
const nullKeyEvent = keyboard.constructNullKeyEvent(device);
const mock = new Mock();
const result = harness.processKeystroke(mock, nullKeyEvent);

assert.isOk(result);
assert.isOk(window['KeymanWeb']);
assert.isOk(window['keyman']);
assert.isOk(KeymanWeb);
assert.isOk(keyman);
assert.isOk(keyman.osk);
assert.isOk(keyman.osk.keyCodes);

// Should be cleared post-keyboard-load.
assert.isNotOk(harness.loadedKeyboard);
Expand Down Expand Up @@ -95,4 +107,4 @@ describe('Keyboard loading in DOM', function() {

harness.activeKeyboard = lao_keyboard;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
concurrency: 10,
nodeResolve: true,
files: [
'**/*.spec.ts'
'build/tests/dom/**/*.spec.mjs'
],
middleware: [
// Rewrites short-hand paths for test resources, making them fully relative to the repo root.
Expand Down Expand Up @@ -59,4 +59,4 @@ export default {
// open: true,
// manual: true,
rootDir: KEYMAN_ROOT
}
}
11 changes: 11 additions & 0 deletions common/web/keyboard-processor/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "../",
"outDir": "../build/tests/",
"tsBuildInfoFile": "../build/tests/tsconfig.tsbuildinfo",
"rootDir": "./"
},
"include": [ "./dom/**/*.ts"],
"exclude": []
}
5 changes: 3 additions & 2 deletions common/web/keyboard-processor/tsconfig.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"baseUrl": "./",
"outDir": "build/obj/",
"tsBuildInfoFile": "build/obj/tsconfig.all.tsbuildinfo",
"rootDir": "./src"
"rootDir": "./src/"
},
"references": [
{ "path": "./src/keyboards/loaders/tsconfig.dom.json" },
{ "path": "./src/keyboards/loaders/tsconfig.node.json" }
{ "path": "./src/keyboards/loaders/tsconfig.node.json" },
{ "path": "./tests/tsconfig.json" },
],
// Actual main-body compilation is in tsconfig.json. This config is just a wrapper
// to trigger all three components at once.
Expand Down
4 changes: 2 additions & 2 deletions common/web/keyboard-processor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"baseUrl": "./",
"outDir": "build/obj/",
"tsBuildInfoFile": "build/obj/tsconfig.tsbuildinfo",
"rootDir": "./src"
"rootDir": "./src/"
},
"references": [
{ "path": "../types" },
{ "path": "../../models/types" },
{ "path": "../keyman-version/" },
{ "path": "../utils/" }
],
"include": ["./src/**/*.ts"],
"include": [ "./src/**/*.ts"],
"exclude": ["./src/keyboards/loaders/**/*.ts"]
}
Loading

0 comments on commit 10ed10d

Please sign in to comment.