Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(common/web): keyboard processor package modularization 🧩 #7809

Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
991fb8a
chore(web): base esmodule conversion of keyboard-processor
jahorton Nov 24, 2022
ddab414
fix(web): fixes build output pathing
jahorton Nov 24, 2022
8a02ddc
feat(common/web): keyboard-processor esbuild bundling
jahorton Nov 24, 2022
6bc8ab5
change(common/web): converts common/web/recorder to ES modules
jahorton Nov 24, 2022
14b40a4
fix(common/web): in-place Node module path resolution
jahorton Nov 24, 2022
7fe069a
chore(common/web): minor cleanup
jahorton Nov 24, 2022
63b074a
fix(common/web): matching updates for recorder testing submodule
jahorton Nov 24, 2022
918a24c
chore(common/web): converts keyboard-processor unit tests
jahorton Nov 24, 2022
0eb722a
fix(common/web): test breakage from loss of former Codes access point
jahorton Nov 24, 2022
45e09d0
fix(common/web): unit test breakage from missing 'let'
jahorton Nov 24, 2022
ec6c90a
change(common/web): new Codes access point now fully readonly
jahorton Nov 24, 2022
a787350
change(common/web): build output path updates
jahorton Nov 25, 2022
17d3f40
feat(common/web): first pass a a bundled declaration for the namespac…
jahorton Nov 25, 2022
43cdd78
feat(common/web): bundled-module canary unit test
jahorton Nov 25, 2022
7c0908c
change(common/web): adds one extra module-bundle unit test
jahorton Nov 25, 2022
52c4ba4
feat(common/web): tests for side-effect auto-extension of String clas…
jahorton Nov 25, 2022
e48db51
change(common/web): different namespace-like export attempt
jahorton Nov 30, 2022
2c133df
chore(common/web): Merge branch 'change/web/util-modularization' into…
jahorton Jan 27, 2023
b171ff3
chore(common/web): cleans up cross-module imports, drops namespaced e…
jahorton Jan 27, 2023
e789479
chore(common/web): Merge branch 'change/web/util-modularization' into…
jahorton Jan 31, 2023
2a40534
change(common/web): better dev-mode declaration bundling
jahorton Jan 31, 2023
b050439
chore(common/models): Apply suggestions from code review
jahorton Feb 2, 2023
857bc80
fix(common/web): debug endpoints to com.keyman.text.Codes
jahorton Feb 2, 2023
9e45b49
fix(web): oh yeah, old keyman.osk endpoint for Codes properties
jahorton Feb 2, 2023
fab0dd5
change(common/web): another legacy endpoint tweak
jahorton Feb 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions common/test/resources/keyboards/khmer_angkor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ KeymanWeb.KR(new Keyboard_khmer_angkor());
}
function Keyboard_khmer_angkor()
{
var modCodes = com.keyman.text.Codes.modifierCodes;
var keyCodes = com.keyman.text.Codes.keyCodes;
var Codes, modCodes, keyCodes;

if(KeymanWeb.Codes) {
// ES Module attachment point
Codes = KeymanWeb.Codes;
} else if (typeof com != 'undefined' && com.keyman && com.keyman.text && com.keyman.text.Codes) {
// Pre-modularized attachment point
Codes = com.keyman.text.Codes;
}
var modCodes = Codes.modifierCodes;
var keyCodes = Codes.keyCodes;
jahorton marked this conversation as resolved.
Show resolved Hide resolved

this.KI="Keyboard_khmer_angkor";
this.KN="Khmer Angkor";
Expand Down Expand Up @@ -2804,7 +2813,7 @@ function Keyboard_khmer_angkor()
k.KO(-1,t,"»");
}
if(m) {

k.KDC(-1,t);
r=this.g_normalise(t,e);
}
Expand Down
15 changes: 12 additions & 3 deletions common/test/resources/keyboards/test_deadkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ KeymanWeb.KR(new Keyboard_test_deadkeys());
}
function Keyboard_test_deadkeys()
{
var modCodes = com.keyman.text.Codes.modifierCodes;
var keyCodes = com.keyman.text.Codes.keyCodes;
var Codes, modCodes, keyCodes;

if(KeymanWeb.Codes) {
// ES Module attachment point
Codes = KeymanWeb.Codes;
} else if (typeof com != 'undefined' && com.keyman && com.keyman.text && com.keyman.text.Codes) {
// Pre-modularized attachment point
Codes = com.keyman.text.Codes;
}
var modCodes = Codes.modifierCodes;
var keyCodes = Codes.keyCodes;
jahorton marked this conversation as resolved.
Show resolved Hide resolved

this.KI="Keyboard_test_deadkeys";
this.KN="Keyman Deadkey Stress-Tester";
Expand Down Expand Up @@ -325,7 +334,7 @@ function Keyboard_test_deadkeys()
k.KDO(-1,t,17);
}
if(m) {

k.KDC(-1,t);
r=this.g_dead_reorder(t,e);
}
Expand Down
13 changes: 11 additions & 2 deletions common/test/resources/keyboards/web_context_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ KeymanWeb.KR(new Keyboard_web_context_tests());
}
function Keyboard_web_context_tests()
{
var modCodes = keyman.osk.modifierCodes;
var keyCodes = keyman.osk.keyCodes;
var Codes, modCodes, keyCodes;

if(KeymanWeb.Codes) {
// ES Module attachment point
Codes = KeymanWeb.Codes;
} else if (typeof com != 'undefined' && com.keyman && com.keyman.text && com.keyman.text.Codes) {
// Pre-modularized attachment point
Codes = com.keyman.text.Codes;
}
var modCodes = Codes.modifierCodes;
var keyCodes = Codes.keyCodes;
jahorton marked this conversation as resolved.
Show resolved Hide resolved

this._v=(typeof keyman!="undefined"&&typeof keyman.version=="string")?parseInt(keyman.version,10):9;
this.KI="Keyboard_web_context_tests";
Expand Down
2 changes: 1 addition & 1 deletion common/web/input-processor/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"references": [
{ "path": "../../keyman-version" },
{ "path": "../../utils" },
{ "path": "../../keyboard-processor/src" },
{ "path": "../../keyboard-processor" },
{ "path": "../../../predictive-text/browser.tsconfig.json" },
],
"include": ["./**/*.ts"],
Expand Down
43 changes: 43 additions & 0 deletions common/web/keyboard-processor/build-bundler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Note: while this file is not meant to exist long-term, it provides a nice
* low-level proof-of-concept for esbuild bundling of the various Web submodules.
*
* Add some extra code at the end of src/index.ts and run it to verify successful bundling!
*/

import esbuild from 'esbuild';
import { spawn } from 'child_process';

// Bundled ES module version
esbuild.buildSync({
entryPoints: ['build/obj/index.js'],
bundle: true,
sourcemap: true,
format: "esm",
// Sets 'common/web' as a root folder for module resolution;
// this allows the keyman-version and utils imports to resolve.
//
// We also need to point it at the nested build output folder to resolve in-project
// imports when compiled - esbuild doesn't seem to pick up on the shifted base.
nodePaths: ['..', "build/obj"],
outfile: "build/lib/index.mjs",
tsconfig: 'tsconfig.json',
target: "es5"
});

// Bundled CommonJS (classic Node) module version
esbuild.buildSync({
entryPoints: ['build/obj/index.js'],
bundle: true,
sourcemap: true,
format: "cjs",
// Sets 'common/web' as a root folder for module resolution;
// this allows the keyman-version and utils imports to resolve.
//
// We also need to point it at the nested build output folder to resolve in-project
// imports when compiled - esbuild doesn't seem to pick up on the shifted base.
nodePaths: ['..', "build/obj"],
outfile: "build/lib/index.cjs",
tsconfig: 'tsconfig.json',
target: "es5"
});
9 changes: 6 additions & 3 deletions common/web/keyboard-processor/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ if builder_start_action clean; then
fi

if builder_start_action build; then
npm run tsc -- --build "$THIS_SCRIPT_PATH/src/tsconfig.json"
npm run tsc -- --build "$THIS_SCRIPT_PATH/tsconfig.json"
node ./build-bundler.js

# Declaration bundling.
npm run tsc -- --emitDeclarationOnly --outFile ./build/lib/index.d.ts

builder_finish_action success build
fi

if builder_start_action test; then
npm run tsc -- --build "$THIS_SCRIPT_PATH/src/tsconfig.bundled.json"

echo_heading "Running Keyboard Processor test suite"

FLAGS=
Expand Down
3 changes: 2 additions & 1 deletion common/web/keyboard-processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
"@keymanapp/keyman-version": "*",
"@keymanapp/web-utils": "*",
"@types/node": "^11.9.4"
}
},
"type": "module"
}
29 changes: 29 additions & 0 deletions common/web/keyboard-processor/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export * from "./keyboards/activeLayout.js";
export * from "./keyboards/defaultLayouts.js";
export { default as Keyboard } from "./keyboards/keyboard.js";
export * from "./keyboards/keyboard.js";

export { default as Codes } from "./text/codes.js";
export * from "./text/codes.js";
Comment on lines +6 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we move codes.ts into common/web/types as a future refactor.

export * from "./text/deadkeys.js";
export { default as DefaultOutput } from "./text/defaultOutput.js";
export * from "./text/defaultOutput.js";
export { default as KeyboardInterface } from "./text/kbdInterface.js";
export * from "./text/kbdInterface.js";
export { default as KeyboardProcessor } from "./text/keyboardProcessor.js";
export * from "./text/keyboardProcessor.js";
export { default as KeyEvent } from "./text/keyEvent.js";
export * from "./text/keyEvent.js";
export { default as KeyMapping } from "./text/keyMapping.js";
export { default as OutputTarget } from "./text/outputTarget.js";
export * from "./text/outputTarget.js";
export { default as RuleBehavior } from "./text/ruleBehavior.js";
export * from "./text/systemStores.js";

export * from "@keymanapp/web-utils/build/obj/index.js";

// At the top level, there should be no default export.

// Without the line below... OutputTarget would likely be aliased there, as it's
// the last `export { default as _ }` => `export * from` pairing seen above.
export default undefined;
Loading