keymanapp / keyman

Keyman cross platform input methods system running on Android, iOS, Linux, macOS, Windows and mobile and desktop web
https://keyman.com/
Other
394 stars 110 forks source link

bug(developer): kmc build for a ldml keyboard project fails on the keyboard_info step #10486

Closed mcdurdin closed 9 months ago

mcdurdin commented 9 months ago

With sourcemaps manually enabled:

C:\Users\mcdurdin\Documents\Keyman Developer\Projects\asdf>.\kmc.cmd build .
asdf.kpj - info KM05002: Building asdf.kpj
asdf.xml - info KM05002: Building source/asdf.xml
asdf.xml - info KM05006: source/asdf.xml built successfully.
asdf.kps - info KM05002: Building source/asdf.kps
asdf.kps - info KM05006: source/asdf.kps built successfully.
asdf.kpj - info KM05002: Building asdf.kpj
asdf.kpj - fatal KM05001: Unexpected exception: TypeError: Cannot read properties of undefined (reading 'Keyboard')

Call stack:
TypeError: Cannot read properties of undefined (reading 'Keyboard')
    at <anonymous> (C:\Program Files (x86)\kmc-keyboard-info\src\keyboard-info-compiler.ts:403:84)
    at Array.filter (<anonymous>)
    at KeyboardInfoCompiler.loadKmxFiles (C:\Program Files (x86)\kmc-keyboard-info\src\keyboard-info-compiler.ts:403:8)
    at KeyboardInfoCompiler.run (C:\Program Files (x86)\kmc-keyboard-info\src\keyboard-info-compiler.ts:139:16)
    at BuildKeyboardInfo.runCompiler (C:\Program Files (x86)\Keyman\src\commands\buildClasses\BuildActivity.ts:18:20)
    at BuildKeyboardInfo.build (C:\Program Files (x86)\Keyman\src\commands\buildClasses\BuildKeyboardInfo.ts:49:12)
    at ProjectBuilder.buildTarget (C:\Program Files (x86)\Keyman\src\commands\buildClasses\BuildProject.ts:118:18)
    at ProjectBuilder.buildProjectTargets (C:\Program Files (x86)\Keyman\src\commands\buildClasses\BuildProject.ts:94:14)
    at ProjectBuilder.run (C:\Program Files (x86)\Keyman\src\commands\buildClasses\BuildProject.ts:84:11)
    at build (C:\Program Files (x86)\Keyman\src\commands\build.ts:157:18)

    This error has been automatically reported to the Keyman team.
      Identifier:  0bf5365c150244b3b029307b57206512
      Application: Keyman Developer
      Reported at: https://sentry.io/organizations/keyman/projects/keyman-developer/events/0bf5365c150244b3b029307b57206512/

Notes:

Additional related:

Original run:

C:\Users\mcdurdin\Documents\Keyman Developer\Projects\asdf>kmc build .
asdf.kpj - info KM05002: Building asdf.kpj
asdf.xml - info KM05002: Building source/asdf.xml
asdf.xml - info KM05006: source/asdf.xml built successfully.
asdf.kps - info KM05002: Building source/asdf.kps
asdf.kps - info KM05006: source/asdf.kps built successfully.
asdf.kpj - info KM05002: Building asdf.kpj
asdf.kpj - fatal KM05001: Unexpected exception: TypeError: Cannot read properties of undefined (reading 'Keyboard')

Call stack:
TypeError: Cannot read properties of undefined (reading 'Keyboard')
    at file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:351509:116
    at Array.filter (<anonymous>)
    at KeyboardInfoCompiler.loadKmxFiles (file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:351509:30)
    at KeyboardInfoCompiler.run (file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:351327:27)
    at async BuildKeyboardInfo.runCompiler (file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:195484:20)
    at async BuildKeyboardInfo.build (file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:351730:12)
    at async ProjectBuilder.buildTarget (file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:360611:18)
    at async ProjectBuilder.buildProjectTargets (file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:360592:14)
    at async ProjectBuilder.run (file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:360584:12)
    at async build (file:///C:/Program%20Files%20(x86)/Keyman/Keyman%20Developer/kmc/kmc.mjs:361536:18)

    This error has been automatically reported to the Keyman team.
      Identifier:  9e52c2de38164546a61acf5fb31cba26
      Application: Keyman Developer
      Reported at: https://sentry.io/organizations/keyman/projects/keyman-developer/events/9e52c2de38164546a61acf5fb31cba26/
mcdurdin commented 9 months ago

So this relates to const enum exports in Typescript. tsc resolves these and inlines the constants but esbuild does not. Three options that I can see:

  1. Instead of export const enum use export enum and enable the isolatedModules typescript flag throughout to ensure we don't leak these anywhere. (this doesn't get us to where we need because export * from x appears to export const enums but still only works with tsc.
  2. Enable preserveConstEnums everywhere.
  3. Use tsc to generate js and then esbuild bundle the js. (https://github.com/thomaschaaf/esbuild-plugin-tsc?)

ref: https://github.com/evanw/esbuild/issues/128