Skip to content

Commit

Permalink
Merge pull request #7809 from keymanapp/change/common/web/keyboard-pr…
Browse files Browse the repository at this point in the history
…ocessor-modularization

change(common/web): keyboard processor package modularization 🧩
  • Loading branch information
jahorton authored Feb 2, 2023
2 parents 84e80fc + fab0dd5 commit caa4165
Show file tree
Hide file tree
Showing 43 changed files with 5,702 additions and 5,620 deletions.
2 changes: 1 addition & 1 deletion common/test/resources/keyboards/khmer_angkor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2804,7 +2804,7 @@ function Keyboard_khmer_angkor()
k.KO(-1,t,"»");
}
if(m) {

k.KDC(-1,t);
r=this.g_normalise(t,e);
}
Expand Down
2 changes: 1 addition & 1 deletion common/test/resources/keyboards/test_deadkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,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
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";
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

0 comments on commit caa4165

Please sign in to comment.