-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
change(common/web): keyboard processor package modularization 🧩 #7809
Conversation
User Test ResultsTest specification and instructions User tests are not required |
24a46bf
to
1966468
Compare
…s for smp by modules
… change/common/web/keyboard-processor-modularization
OK... after a bit of work, I've figured out how to use So, the point of concern, from a declare module "text/keyboardProcessor" {
import type Keyboard from "keyboards/keyboard";
import KeyEvent from "text/keyEvent";
import type { MutableSystemStore } from "text/systemStores";
import type OutputTarget from "text/outputTarget";
import KeyboardInterface, { VariableStore } from "text/kbdInterface";
import RuleBehavior from "text/ruleBehavior";
import { DeviceSpec } from "@keymanapp/web-utils/build/obj/index.js";
// ...
} Note that final That said, Observations: declare module "@keymanapp/web-utils/build/obj/index.js" { /* ... */ } Adding the above block will redirect all import references to this module declaration. That said, unfortunately you can't nest another But! <reference path="some-declaration-file.d.ts"/> Such statements are totally legal within declaration files and can be used to 'attach' one to another, sort of like a pseudo-import for the referenced file's declarations. So, the path forward:
Limitations:
While not optimal, it's at least reasonably viable without being too fiddly. Note that we can also simply... not bother with this for now; the declarations work flawlessly for local development on components (or all of) Keyman Engine for Web. It only matters if and when we publish components / the engine itself to |
Ideally, we move
Not clear what you are saying here -- are you saying we need to change the compiler to emit something different for debug keyboards? Thus, debug keyboards built for Keyman 17+ will have different references to debug keyboards built for earlier versions?
I think we don't bother with this for now. We're not doing npm publishing of KMW at this point, so we can cross this bridge at the time that we do. |
I've come to that conclusion, too.
Yep. Maybe I didn't imply it strongly enough there? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only minor things, I think
export { default as Codes } from "./text/codes.js"; | ||
export * from "./text/codes.js"; |
There was a problem hiding this comment.
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 enum SystemStoreIDs { | ||
TSS_LAYER = 33, | ||
TSS_PLATFORM = 31, | ||
TSS_NEWLAYER = 42, | ||
TSS_OLDLAYER = 43 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ideally belongs in common/web/types longer term
import KeyboardProcessor from '@keymanapp/keyboard-processor/build/obj/text/keyboardProcessor.js'; | ||
import { KeyboardTest } from '@keymanapp/recorder-core/build/obj/index.js'; | ||
import NodeProctor from '@keymanapp/recorder-core/build/obj/nodeProctor.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to be able to reduce this to:
import KeyboardProcessor from '@keymanapp/keyboard-processor/build/obj/text/keyboardProcessor.js'; | |
import { KeyboardTest } from '@keymanapp/recorder-core/build/obj/index.js'; | |
import NodeProctor from '@keymanapp/recorder-core/build/obj/nodeProctor.js'; | |
import KeyboardProcessor from '@keymanapp/keyboard-processor'; | |
import NodeProctor, { KeyboardTest } from '@keymanapp/recorder-core'; |
Co-authored-by: Marc Durdin <marc@durdin.net>
Continuing from #7800, this PR helps address #7309 by fully converting our internal
@keymanapp/keyboard-processor
package (and the testing package@keymanapp/recorder-core
) to ES6 modules - including the former's unit tests!Setting reviews to "no whitespace-only changes" is highly advised. As of 7849377:
(Namespaces were generally the top-level indent; dropping them means removing the indent, hence the huge line-count difference.)
Note that this change removes the
com.keyman.text.Codes
access point for theCodes
object; conversion to ES6 modules does mean that we'll be dropping the namespaces, hence no morecom
. After a bit of thought, I figured the ideal spot to move it would be as a property ofKeyboardInterface
, a global object (during operational KeymanWeb) that we must continue to support. Since even compiled keyboards still reference that... may as well add an access point to it and redirect debug keyboards there for theCodes
object.Took a while to get the unit tests working; by default, ES module compilation doesn't actually care to ensure a smooth Node-based execution experience. Fortunately, telling
tsc
to use Node's module resolution and relying onnode_modules
-based paths for scripts from linked projects seems to do the trick - both theesbuild
bundler andnode
execution for unit tests are happy this way.Finally, the new
index.ts
file may be worth a look - it publishes the 'old' namespace-style organization ofkeyboard-processor
and writes it to the global object... so in theory, with a bit more work, we may be able to link higher-level namespaced code with the modularized version seen here.Now, whether or not that - putting energy into a hybrid state - is worth the effort... is a different question. I'm not sure how well it'd work with the namespaced projects' setup at the moment. That said, I'm also not sure how easy it'll be to properly modularize the top-level KMW code... some of that source has interesting cross-effects across files, which may need serious cleanup before modularizing. I'm honestly more afraid of the latter than the former.
@keymanapp-test-bot skip