From 60cdd7f3bb44268f03497b65bf1f307d6d6dbf24 Mon Sep 17 00:00:00 2001 From: jahorton Date: Wed, 18 May 2022 15:03:04 +0700 Subject: [PATCH] chore(web): reverts keyboard-processor demodularization from #6597 --- common/web/keyboard-processor/src/build.sh | 2 +- .../src/tsconfig.bundled.json | 15 +++++++ common/web/keyboard-processor/test.sh | 43 ++++--------------- .../tests/cases/basic-engine.js | 9 ++-- .../tests/cases/basic-init.js | 11 +++-- .../tests/cases/chirality.js | 8 ++-- .../tests/cases/deadkeys.js | 10 ++--- .../tests/cases/engine/context.js | 18 ++++---- .../tests/cases/engine/notany_context.js | 10 ++++- .../tests/cases/engine/stores.js | 10 ++--- .../cases/engine/unmatched_final_group.js | 9 ++-- .../tests/cases/transcriptions.js | 5 ++- .../tests/cases/versions.js | 7 ++- 13 files changed, 76 insertions(+), 81 deletions(-) create mode 100644 common/web/keyboard-processor/src/tsconfig.bundled.json diff --git a/common/web/keyboard-processor/src/build.sh b/common/web/keyboard-processor/src/build.sh index 12927e49d6f..ba1435f98db 100755 --- a/common/web/keyboard-processor/src/build.sh +++ b/common/web/keyboard-processor/src/build.sh @@ -7,7 +7,7 @@ set -eu ## START STANDARD BUILD SCRIPT INCLUDE # adjust relative paths as necessary THIS_SCRIPT="$(greadlink -f "${BASH_SOURCE[0]}" 2>/dev/null || readlink -f "${BASH_SOURCE[0]}")" -. "$(dirname "$THIS_SCRIPT")/../../../../../resources/build/build-utils.sh" +. "$(dirname "$THIS_SCRIPT")/../../../../resources/build/build-utils.sh" . "$KEYMAN_ROOT/resources/shellHelperFunctions.sh" ## END STANDARD BUILD SCRIPT INCLUDE diff --git a/common/web/keyboard-processor/src/tsconfig.bundled.json b/common/web/keyboard-processor/src/tsconfig.bundled.json new file mode 100644 index 00000000000..695ec8f0e4f --- /dev/null +++ b/common/web/keyboard-processor/src/tsconfig.bundled.json @@ -0,0 +1,15 @@ +{ + // This variant of the tsconfig.json exists to create a 'leaf', 'bundled' + // version of the keyboard-processor build product. The same reference + // cannot be prepended twice in a composite tsc build, posing problems + // for certain down-line builds if the two tsconfigs are not differentiated. + "extends": "./tsconfig.json", + "compilerOptions": { + "outFile": "../build/index.bundled.js" + }, + "references": [ + { "path": "../../../models/types" }, + { "path": "../../web-environment/", "prepend": true }, + { "path": "../../utils/", "prepend": true} + ] +} diff --git a/common/web/keyboard-processor/test.sh b/common/web/keyboard-processor/test.sh index f6c0f43aa23..2d86e09d267 100755 --- a/common/web/keyboard-processor/test.sh +++ b/common/web/keyboard-processor/test.sh @@ -58,43 +58,16 @@ test-headless ( ) { FLAGS="$FLAGS --reporter mocha-teamcity-reporter" fi - # Poor Man's Modules until we support ES6 throughout - PREPEND=./tests/cases/prepend.js - rm -f $PREPEND - for n in tests/cases/*.js; do - echo $n - (cat ../web-environment/build/index.js; echo) > $PREPEND - (cat ../utils/build/index.js; echo) >> $PREPEND - (cat ../recorder/build/nodeProctor/index.js; echo) >> $PREPEND - (cat ../keyboard-processor/build/index.js; echo) >> $PREPEND - (cat $n; echo) >> $PREPEND; - npm run mocha -- --recursive $FLAGS $PREPEND || die - rm $PREPEND - done - - # Poor Man's Modules until we support ES6 throughout - PREPEND=./tests/cases/engine/prepend.js - rm -f $PREPEND - for n in tests/cases/engine/*.js; do - echo $n - (cat ../web-environment/build/index.js; echo) > $PREPEND - (cat ../utils/build/index.js; echo) >> $PREPEND - (cat ../recorder/build/nodeProctor/index.js; echo) >> $PREPEND - (cat ../keyboard-processor/build/index.js; echo) >> $PREPEND - (cat $n; echo) >> $PREPEND; - npm run mocha -- --recursive $FLAGS $PREPEND || die - rm $PREPEND - done - - # npm run mocha -- --recursive $FLAGS ./tests/cases/ + npm run mocha -- --recursive $FLAGS ./tests/cases/ } -if [ $FETCH_DEPS = true ]; then - # Build test dependency - pushd "$KEYMAN_ROOT/common/web/recorder/src" - ./build.sh -skip-package-install || fail "recorder-core compilation failed." - popd -fi +# Build test dependency +pushd "$KEYMAN_ROOT/common/web/recorder/src" +./build.sh -skip-package-install || fail "recorder-core compilation failed." +popd + +# Compile web's `keyboard-processor` module." +npm run tsc -- -b src/tsconfig.bundled.json || fail "Failed to compile the testing version of the core/web/keyboard-processor module." # Run headless (browserless) tests. echo_heading "Running Keyboard Processor test suite" diff --git a/common/web/keyboard-processor/tests/cases/basic-engine.js b/common/web/keyboard-processor/tests/cases/basic-engine.js index 0459aa50152..4b886d1184f 100644 --- a/common/web/keyboard-processor/tests/cases/basic-engine.js +++ b/common/web/keyboard-processor/tests/cases/basic-engine.js @@ -2,11 +2,12 @@ var assert = require('chai').assert; let fs = require('fs'); let vm = require('vm'); -let KeyboardProcessor = com.keyman.text.KeyboardProcessor; -global.keyman = {}; +let KeyboardProcessor = require('../../build/index.bundled.js'); -// Initialize supplementary plane string extensions -String.kmwEnableSupplementaryPlane(false); +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. + +let KMWRecorder = require('../../../recorder/build/nodeProctor'); describe('Engine - Basic Simulation', function() { let testJSONtext = fs.readFileSync('../../test/resources/json/engine_tests/basic_lao_simulation.json'); diff --git a/common/web/keyboard-processor/tests/cases/basic-init.js b/common/web/keyboard-processor/tests/cases/basic-init.js index 9c19a903737..b9a41499d7c 100644 --- a/common/web/keyboard-processor/tests/cases/basic-init.js +++ b/common/web/keyboard-processor/tests/cases/basic-init.js @@ -2,12 +2,15 @@ var assert = require('chai').assert; var fs = require("fs"); var vm = require("vm"); -let KeyboardProcessor = com.keyman.text.KeyboardProcessor; -global.keyman = {}; -global.com = com; +let KeyboardProcessor = require('../../build/index.bundled.js'); + +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. +global.keyman = {}; // So that keyboard-based checks against the global `keyman` succeed. + // 10.0+ dependent keyboards, like khmer_angkor, will otherwise fail to load. // Initialize supplementary plane string extensions -String.kmwEnableSupplementaryPlane(false); +String.kmwEnableSupplementaryPlane(false); // Test the KeyboardProcessor interface. describe('KeyboardProcessor', function() { diff --git a/common/web/keyboard-processor/tests/cases/chirality.js b/common/web/keyboard-processor/tests/cases/chirality.js index e8e5b48646e..123dfe023a5 100644 --- a/common/web/keyboard-processor/tests/cases/chirality.js +++ b/common/web/keyboard-processor/tests/cases/chirality.js @@ -2,11 +2,11 @@ var assert = require('chai').assert; let fs = require('fs'); let vm = require('vm'); -let KeyboardProcessor = com.keyman.text.KeyboardProcessor; -global.keyman = {}; +let KeyboardProcessor = require('../../build/index.bundled.js'); +let KMWRecorder = require('../../../recorder/build/nodeProctor'); -// Initialize supplementary plane string extensions -String.kmwEnableSupplementaryPlane(false); +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. describe('Engine - Chirality', function() { let testJSONtext = fs.readFileSync('../../test/resources/json/engine_tests/chirality.json'); diff --git a/common/web/keyboard-processor/tests/cases/deadkeys.js b/common/web/keyboard-processor/tests/cases/deadkeys.js index cfe83e2b00b..0510c60ea28 100644 --- a/common/web/keyboard-processor/tests/cases/deadkeys.js +++ b/common/web/keyboard-processor/tests/cases/deadkeys.js @@ -2,12 +2,12 @@ var assert = require('chai').assert; let fs = require('fs'); let vm = require('vm'); -let KeyboardProcessor = com.keyman.text.KeyboardProcessor; -global.keyman = {}; -global.com = com; +let KeyboardProcessor = require('../../build/index.bundled.js'); -// Initialize supplementary plane string extensions -String.kmwEnableSupplementaryPlane(false); +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. + +let KMWRecorder = require('../../../recorder/build/nodeProctor'); describe('Engine - Deadkeys', function() { let testJSONtext = fs.readFileSync('../../test/resources/json/engine_tests/deadkeys.json'); diff --git a/common/web/keyboard-processor/tests/cases/engine/context.js b/common/web/keyboard-processor/tests/cases/engine/context.js index 91f2f703dc7..8b8fb34e9ee 100644 --- a/common/web/keyboard-processor/tests/cases/engine/context.js +++ b/common/web/keyboard-processor/tests/cases/engine/context.js @@ -2,12 +2,12 @@ var assert = require('chai').assert; let fs = require('fs'); let vm = require('vm'); -let KeyboardProcessor = com.keyman.text.KeyboardProcessor; -global.keyman = {}; -global.com = com; +let KeyboardProcessor = require('../../../build/index.bundled.js'); -// Initialize supplementary plane string extensions -String.kmwEnableSupplementaryPlane(false); +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. + +let KMWRecorder = require('../../../../recorder/build/nodeProctor'); /* * ABOUT THIS TEST SUITE @@ -68,8 +68,7 @@ function runEngineRuleSet(ruleSet, defaultNoun) { ruleSeq.test(proctor, target); // Now for the real test! - let processor = new KeyboardProcessor(); - processor.device = device; + let processor = new KeyboardProcessor(device); processor.activeKeyboard = keyboard; var res = processor.keyboardInterface.fullContextMatch(ruleDef.n, target, ruleDef.rule); @@ -983,7 +982,7 @@ var NOTANY_NUL_RULE_SET = [ NOTANY_NUL_TEST_1, NOTANY_NUL_TEST_2, NOTANY_NUL_TES describe('Engine - Context Matching', function() { before(function() { - let kp = new KeyboardProcessor(); + let kp = new KeyboardProcessor(device); // These two lines will load a keyboard from its file; headless-mode `registerKeyboard` will // automatically set the keyboard as active. @@ -1008,8 +1007,7 @@ describe('Engine - Context Matching', function() { ruleSeq.test(proctor, target); // Now for the real test! - let processor = new KeyboardProcessor(); - processor.device = device; + let processor = new KeyboardProcessor(device); processor.activeKeyboard = keyboard; var res = processor.keyboardInterface._BuildExtendedContext(ruleDef.n, ruleDef.ln, target); diff --git a/common/web/keyboard-processor/tests/cases/engine/notany_context.js b/common/web/keyboard-processor/tests/cases/engine/notany_context.js index f03ec38e91d..2c0ba3585dd 100644 --- a/common/web/keyboard-processor/tests/cases/engine/notany_context.js +++ b/common/web/keyboard-processor/tests/cases/engine/notany_context.js @@ -2,8 +2,14 @@ const assert = require('chai').assert; const fs = require('fs'); const vm = require('vm'); -let KeyboardProcessor = com.keyman.text.KeyboardProcessor; -global.keyman = {}; +let KeyboardProcessor = require('../../../build/index.bundled.js'); + +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. +global.keyman = {}; // So that keyboard-based checks against the global `keyman` succeed. + // 10.0+ dependent keyboards, like khmer_angkor, will otherwise fail to load. + +let KMWRecorder = require('../../../../recorder/build/nodeProctor'); // Initialize supplementary plane string extensions String.kmwEnableSupplementaryPlane(false); diff --git a/common/web/keyboard-processor/tests/cases/engine/stores.js b/common/web/keyboard-processor/tests/cases/engine/stores.js index 4b14748c20e..530ed0c9319 100644 --- a/common/web/keyboard-processor/tests/cases/engine/stores.js +++ b/common/web/keyboard-processor/tests/cases/engine/stores.js @@ -2,11 +2,10 @@ var assert = require('chai').assert; let fs = require('fs'); let vm = require('vm'); -let KeyboardProcessor = com.keyman.text.KeyboardProcessor; -global.keyman = {}; +let KeyboardProcessor = require('../../../build/index.bundled.js'); -// Initialize supplementary plane string extensions -String.kmwEnableSupplementaryPlane(false); +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. let device = { formFactor: 'desktop', @@ -23,8 +22,7 @@ describe('Engine - Stores', function() { } it('Store \'Explosion\'', function() { - let processor = new KeyboardProcessor(); - processor.device = device; + let processor = new KeyboardProcessor(device); // A 'hollow' Keyboard that only follows default rules. That said, we need a Keyboard // instance to host cache data for our exploded store tests. processor.activeKeyboard = new com.keyman.keyboards.Keyboard(); diff --git a/common/web/keyboard-processor/tests/cases/engine/unmatched_final_group.js b/common/web/keyboard-processor/tests/cases/engine/unmatched_final_group.js index 84a7a309ac1..68a04c2ee99 100644 --- a/common/web/keyboard-processor/tests/cases/engine/unmatched_final_group.js +++ b/common/web/keyboard-processor/tests/cases/engine/unmatched_final_group.js @@ -2,11 +2,12 @@ var assert = require('chai').assert; let fs = require('fs'); let vm = require('vm'); -let KeyboardProcessor = com.keyman.text.KeyboardProcessor; -global.keyman = {}; +let KeyboardProcessor = require('../../../build/index.bundled.js'); -// Initialize supplementary plane string extensions -String.kmwEnableSupplementaryPlane(false); +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. + +let KMWRecorder = require('../../../../recorder/build/nodeProctor'); describe('Engine - Unmatched Final Groups', function() { let testJSONtext = fs.readFileSync('../../test/resources/json/engine_tests/ghp_enter.json'); diff --git a/common/web/keyboard-processor/tests/cases/transcriptions.js b/common/web/keyboard-processor/tests/cases/transcriptions.js index c351ded8d0e..11619557206 100644 --- a/common/web/keyboard-processor/tests/cases/transcriptions.js +++ b/common/web/keyboard-processor/tests/cases/transcriptions.js @@ -1,8 +1,9 @@ var assert = require('chai').assert; +let KeyboardProcessor = require('../../build/index.bundled.js'); -global.keyman = {}; +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. -// Initialize supplementary plane string extensions String.kmwEnableSupplementaryPlane(false); describe("Transcriptions and Transforms", function() { diff --git a/common/web/keyboard-processor/tests/cases/versions.js b/common/web/keyboard-processor/tests/cases/versions.js index e3c6a42768e..2e7f6ae142c 100644 --- a/common/web/keyboard-processor/tests/cases/versions.js +++ b/common/web/keyboard-processor/tests/cases/versions.js @@ -1,9 +1,8 @@ var assert = require('chai').assert; +let KeyboardProcessor = require('../../build/index.bundled.js'); -global.keyman = {}; - -// Initialize supplementary plane string extensions -String.kmwEnableSupplementaryPlane(false); +// Required initialization setup. +global.com = KeyboardProcessor.com; // exports all keyboard-processor namespacing. describe('Version Logic', function() { it('Should provide a default, fallback value when nothing is specified', function() {