From b171ff342e7ee71a1456f8323a830e3a2e8693db Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Fri, 27 Jan 2023 11:45:30 +0700 Subject: [PATCH] chore(common/web): cleans up cross-module imports, drops namespaced export setup --- .../web/keyboard-processor/build-bundler.js | 44 +++---------------- .../web/keyboard-processor/src/com-index.ts | 1 - .../src/index-namespaced.ts | 14 ------ common/web/keyboard-processor/src/index.ts | 9 +++- .../keyboard-processor/src/keyboards/index.ts | 23 ---------- .../keyboard-processor/src/keyman-index.ts | 3 -- .../web/keyboard-processor/src/text/index.ts | 10 ----- .../src/text/kbdInterface.ts | 5 +-- .../keyboard-processor/src/text/keyEvent.ts | 2 +- .../web/keyboard-processor/src/utils-index.ts | 1 - .../tests/temp-bundle-test.js | 16 ------- common/web/recorder/src/index.ts | 5 +-- common/web/recorder/src/nodeProctor.ts | 8 +--- common/web/recorder/src/proctor.ts | 2 +- 14 files changed, 22 insertions(+), 121 deletions(-) delete mode 100644 common/web/keyboard-processor/src/com-index.ts delete mode 100644 common/web/keyboard-processor/src/index-namespaced.ts delete mode 100644 common/web/keyboard-processor/src/keyboards/index.ts delete mode 100644 common/web/keyboard-processor/src/keyman-index.ts delete mode 100644 common/web/keyboard-processor/src/text/index.ts delete mode 100644 common/web/keyboard-processor/src/utils-index.ts delete mode 100644 common/web/keyboard-processor/tests/temp-bundle-test.js diff --git a/common/web/keyboard-processor/build-bundler.js b/common/web/keyboard-processor/build-bundler.js index 522cb9333a..1d1b44508e 100644 --- a/common/web/keyboard-processor/build-bundler.js +++ b/common/web/keyboard-processor/build-bundler.js @@ -8,25 +8,6 @@ import esbuild from 'esbuild'; import { spawn } from 'child_process'; -// Browser / namespace-targeted bundle -esbuild.buildSync({ - entryPoints: ['build/obj/index-namespaced.js'], - bundle: true, - sourcemap: true, - minify: true, - format: "iife", - keepNames: true, - // 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.namespaced.js", - tsconfig: 'tsconfig.json', - target: "es5" -}); - // Bundled ES module version esbuild.buildSync({ entryPoints: ['build/obj/index.js'], @@ -68,22 +49,9 @@ const dtsBundleCommand = spawn('npx dts-bundle-generator --project tsconfig.json dtsBundleCommand.stdout.on('data', data => console.log(data.toString())); dtsBundleCommand.stderr.on('data', data => console.error(data.toString())); -// Forces synchronicity; done mostly so that the logs don't get jumbled up. -dtsBundleCommand.on('exit', () => { - if(dtsBundleCommand.exitCode != 0) { - process.exit(dtsBundleCommand.exitCode); - } - - const namespacedDtsBundleCmd = spawn('npx dts-bundle-generator --project tsconfig.json -o build/lib/index.namespaced.d.ts src/index-namespaced.ts', { - shell: true - }); - - namespacedDtsBundleCmd.stdout.on('data', data => console.log(data.toString())); - namespacedDtsBundleCmd.stderr.on('data', data => console.error(data.toString())); - - namespacedDtsBundleCmd.on('exit', () => { - if(namespacedDtsBundleCmd.exitCode != 0) { - process.exit(namespacedDtsBundleCmd.exitCode); - } - }) -}); \ No newline at end of file +// // Forces synchronicity; done mostly so that the logs don't get jumbled up. +// dtsBundleCommand.on('exit', () => { +// if(dtsBundleCommand.exitCode != 0) { +// process.exit(dtsBundleCommand.exitCode); +// } +// }); \ No newline at end of file diff --git a/common/web/keyboard-processor/src/com-index.ts b/common/web/keyboard-processor/src/com-index.ts deleted file mode 100644 index 179f865420..0000000000 --- a/common/web/keyboard-processor/src/com-index.ts +++ /dev/null @@ -1 +0,0 @@ -export * as keyman from './keyman-index.js'; \ No newline at end of file diff --git a/common/web/keyboard-processor/src/index-namespaced.ts b/common/web/keyboard-processor/src/index-namespaced.ts deleted file mode 100644 index c41cc9c0ac..0000000000 --- a/common/web/keyboard-processor/src/index-namespaced.ts +++ /dev/null @@ -1,14 +0,0 @@ -// This file exists as a bundling intermediary that attempts to present all of -// keyboard-processor's offerings in the 'old', namespaced format - at least, -// as of the time that this submodule was converted to ES6 module use. - -// Unfortunately, the declaration-bundling tool that works well for the modules... -// struggles a bit here. - -import * as com from "./com-index.js"; - -// Make sure the declaration-merger code pays attention. -export * as com from "./com-index.js"; - -// Force-exports it as the global it always was. -com.keyman.utils.getGlobalObject()['com'] = com; diff --git a/common/web/keyboard-processor/src/index.ts b/common/web/keyboard-processor/src/index.ts index 7672682ab1..11ca9a1f78 100644 --- a/common/web/keyboard-processor/src/index.ts +++ b/common/web/keyboard-processor/src/index.ts @@ -13,10 +13,17 @@ 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"; \ No newline at end of file +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; \ No newline at end of file diff --git a/common/web/keyboard-processor/src/keyboards/index.ts b/common/web/keyboard-processor/src/keyboards/index.ts deleted file mode 100644 index bf3e3e6e47..0000000000 --- a/common/web/keyboard-processor/src/keyboards/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -// This file exists as a bundling intermediary that attempts to present all of -// keyboard-processor's offerings in the 'old', namespaced format - at least, -// as of the time that this submodule was converted to ES6 module use. - -// Unfortunately, the declaration-bundling tool that works well for the modules... -// struggles a bit here. - -export { - ActiveKey, - ActiveRow, - ActiveLayer, - ActiveLayout -} from "./activeLayout.js"; - -export { - Layouts -} from "./defaultLayouts.js"; - -export { default as Keyboard} from "./keyboard.js"; -export { - LayoutState -} from "./keyboard.js"; - diff --git a/common/web/keyboard-processor/src/keyman-index.ts b/common/web/keyboard-processor/src/keyman-index.ts deleted file mode 100644 index e56fa94019..0000000000 --- a/common/web/keyboard-processor/src/keyman-index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * as keyboards from './keyboards/index.js'; -export * as text from './text/index.js'; -export * as utils from './utils-index.js'; \ No newline at end of file diff --git a/common/web/keyboard-processor/src/text/index.ts b/common/web/keyboard-processor/src/text/index.ts deleted file mode 100644 index d4276cfed1..0000000000 --- a/common/web/keyboard-processor/src/text/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -export { default as Codes } from "./codes.js"; -export { Deadkey, DeadkeyTracker } from "./deadkeys.js"; -export { default as DefaultOutput, EmulationKeystrokes } from "./defaultOutput.js"; -export { default as KeyboardInterface, KeyInformation, SystemStoreIDs } from "./kbdInterface.js"; -export { default as KeyboardProcessor } from "./keyboardProcessor.js"; -export { default as KeyEvent } from "./keyEvent.js"; -export { default as KeyMapping } from "./keyMapping.js"; -export { default as OutputTarget, TextTransform, Transcription, Mock } from "./outputTarget.js"; -export { default as RuleBehavior } from "./ruleBehavior.js"; -export { SystemStore, MutableSystemStore, PlatformSystemStore } from "./systemStores.js"; \ No newline at end of file diff --git a/common/web/keyboard-processor/src/text/kbdInterface.ts b/common/web/keyboard-processor/src/text/kbdInterface.ts index 1a618c5b0b..1dc1d54e60 100644 --- a/common/web/keyboard-processor/src/text/kbdInterface.ts +++ b/common/web/keyboard-processor/src/text/kbdInterface.ts @@ -5,20 +5,19 @@ //#region Imports +import { type DeviceSpec } from "@keymanapp/web-utils/build/obj/index.js"; + import Codes from "./codes.js"; import type KeyEvent from "./keyEvent.js"; import type { Deadkey } from "./deadkeys.js"; import KeyMapping from "./keyMapping.js"; import { SystemStore, MutableSystemStore, PlatformSystemStore } from "./systemStores.js"; import type { VariableStoreSerializer } from "./keyboardProcessor.js"; - import type OutputTarget from "./outputTarget.js"; import { Mock } from "./outputTarget.js"; - import RuleBehavior from "./ruleBehavior.js"; import Keyboard, { VariableStoreDictionary } from "../keyboards/keyboard.js"; -import { type DeviceSpec } from "@keymanapp/web-utils/build/obj/index.js"; //#endregion diff --git a/common/web/keyboard-processor/src/text/keyEvent.ts b/common/web/keyboard-processor/src/text/keyEvent.ts index 4d4387d723..bc29dd1c83 100644 --- a/common/web/keyboard-processor/src/text/keyEvent.ts +++ b/common/web/keyboard-processor/src/text/keyEvent.ts @@ -1,5 +1,5 @@ import type Keyboard from "../keyboards/keyboard.js"; -import type DeviceSpec from "@keymanapp/web-utils/build/obj/deviceSpec.js"; +import {type DeviceSpec} from "@keymanapp/web-utils/build/obj/index.js"; // Represents a probability distribution over a keyboard's keys. // Defined here to avoid compilation issues. diff --git a/common/web/keyboard-processor/src/utils-index.ts b/common/web/keyboard-processor/src/utils-index.ts deleted file mode 100644 index 0b6995ee90..0000000000 --- a/common/web/keyboard-processor/src/utils-index.ts +++ /dev/null @@ -1 +0,0 @@ -export { deepCopy, DeviceSpec, extendString, globalObject as getGlobalObject, Version } from "@keymanapp/web-utils/build/obj/index.js"; \ No newline at end of file diff --git a/common/web/keyboard-processor/tests/temp-bundle-test.js b/common/web/keyboard-processor/tests/temp-bundle-test.js deleted file mode 100644 index 0e4433f12c..0000000000 --- a/common/web/keyboard-processor/tests/temp-bundle-test.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * A temporary file to validate that the bundled version really is bundled and is usable in a - * similar manner to its old format. - */ - -// Loads `com` into the global namespace. -import * as _ from '../build/bundled/index.js'; - -console.log(`Int code for ALT: ${com.keyman.text.Codes.modifierCodes['ALT']}`); - -console.log(new com.keyman.keyboards.Keyboard(null)); - -console.log(); - -// make sure we bundled `utils` as well! -console.log(`Verifying proper handling of version 16.0: ${new com.keyman.utils.Version([16, 0]).toString()}`); \ No newline at end of file diff --git a/common/web/recorder/src/index.ts b/common/web/recorder/src/index.ts index ac6d8f7b70..5943c99fc5 100644 --- a/common/web/recorder/src/index.ts +++ b/common/web/recorder/src/index.ts @@ -1,8 +1,7 @@ /// -import KeyEvent, { KeyDistribution } from "@keymanapp/keyboard-processor/build/obj/text/keyEvent.js"; -import type OutputTarget from "@keymanapp/keyboard-processor/build/obj/text/outputTarget.js"; -import { Mock } from "@keymanapp/keyboard-processor/build/obj/text/outputTarget.js"; +import { type OutputTarget } from "@keymanapp/keyboard-processor/build/obj/index.js"; +import { KeyDistribution, KeyEvent, Mock } from "@keymanapp/keyboard-processor/build/obj/index.js"; import Proctor from "./proctor.js"; diff --git a/common/web/recorder/src/nodeProctor.ts b/common/web/recorder/src/nodeProctor.ts index 6650f48d61..6a759eb4bb 100644 --- a/common/web/recorder/src/nodeProctor.ts +++ b/common/web/recorder/src/nodeProctor.ts @@ -8,13 +8,9 @@ import { RecordedSyntheticKeystroke } from "./index.js"; -import Keyboard from "@keymanapp/keyboard-processor/build/obj/keyboards/keyboard.js"; -import type KeyEvent from "@keymanapp/keyboard-processor/build/obj/text/keyEvent.js"; -import KeyboardProcessor from "@keymanapp/keyboard-processor/build/obj/text/keyboardProcessor.js"; -import type OutputTarget from "@keymanapp/keyboard-processor/build/obj/text/outputTarget.js"; -import { Mock } from "@keymanapp/keyboard-processor/build/obj/text/outputTarget.js"; +import { Keyboard, type KeyEvent, KeyboardProcessor, Mock, type OutputTarget } from "@keymanapp/keyboard-processor/build/obj/index.js"; -import DeviceSpec from "@keymanapp/web-utils/build/obj/deviceSpec.js"; +import { DeviceSpec } from "@keymanapp/web-utils/build/obj/index.js"; export default class NodeProctor extends Proctor { private keyboard: Keyboard; diff --git a/common/web/recorder/src/proctor.ts b/common/web/recorder/src/proctor.ts index 347271fb0a..412e0909c1 100644 --- a/common/web/recorder/src/proctor.ts +++ b/common/web/recorder/src/proctor.ts @@ -1,5 +1,5 @@ import { type DeviceSpec } from "@keymanapp/web-utils/build/obj/index.js"; -import type OutputTarget from "@keymanapp/keyboard-processor/build/obj/text/outputTarget.js"; +import { type OutputTarget } from "@keymanapp/keyboard-processor/build/obj/index.js"; import type { KeyboardTest, TestSet, TestSequence } from "./index.js";