diff --git a/common/models/templates/build.sh b/common/models/templates/build.sh index b5ae2a8c23..0fe305ca5a 100755 --- a/common/models/templates/build.sh +++ b/common/models/templates/build.sh @@ -18,8 +18,9 @@ cd "$(dirname "$THIS_SCRIPT")" ################################ Main script ################################ builder_describe "Builds the predictive-text model template implementation module" \ - "@../../web/keyman-version" \ - "@../wordbreakers" \ + "@/common/web/keyman-version" \ + "@/common/web/tslib" \ + "@/common/models/wordbreakers" \ "clean" \ "configure" \ "build" \ diff --git a/common/models/templates/tsconfig.json b/common/models/templates/tsconfig.json index 9284bddd20..7ff603ef29 100644 --- a/common/models/templates/tsconfig.json +++ b/common/models/templates/tsconfig.json @@ -7,6 +7,7 @@ "moduleResolution": "node16", "sourceMap": true, "sourceRoot": "/common/models/templates/src", + "importHelpers": true, "inlineSources": true, "strict": true, "lib": ["es6"], diff --git a/common/models/wordbreakers/src/default/index.ts b/common/models/wordbreakers/src/default/index.ts index 65dbd0faf0..20e159ed19 100644 --- a/common/models/wordbreakers/src/default/index.ts +++ b/common/models/wordbreakers/src/default/index.ts @@ -431,7 +431,7 @@ function findBoundaries(text: string, options?: DefaultWordBreakerOptions): numb } // Do not break across certain punctuation // WB6: (Don't break before apostrophes in contractions) - const SET_ALL_MIDLETTER = [WordBreakProperty.MidLetter, ...SET_MIDNUMLETQ]; + const SET_ALL_MIDLETTER = [WordBreakProperty.MidLetter].concat(SET_MIDNUMLETQ); if(state.match(null, SET_AHLETTER, SET_ALL_MIDLETTER, SET_AHLETTER)) { continue; } @@ -474,7 +474,7 @@ function findBoundaries(text: string, options?: DefaultWordBreakerOptions): numb } // Do not break within sequences, such as 3.2, 3,456.789 // WB11 - const SET_ALL_MIDNUM = [WordBreakProperty.MidNum, ...SET_MIDNUMLETQ]; + const SET_ALL_MIDNUM = [WordBreakProperty.MidNum].concat(SET_MIDNUMLETQ); if(state.match([WordBreakProperty.Numeric], SET_ALL_MIDNUM, [WordBreakProperty.Numeric], null)) { continue; } @@ -488,9 +488,7 @@ function findBoundaries(text: string, options?: DefaultWordBreakerOptions): numb } // Do not break from extenders (e.g., U+202F NARROW NO-BREAK SPACE) // WB13a - const SET_NUM_KAT_LET = [WordBreakProperty.Katakana, - WordBreakProperty.Numeric, - ...SET_AHLETTER]; + const SET_NUM_KAT_LET = [WordBreakProperty.Katakana, WordBreakProperty.Numeric].concat(SET_AHLETTER); if(state.match(null, SET_NUM_KAT_LET, [WordBreakProperty.ExtendNumLet], null)) { continue; } diff --git a/common/models/wordbreakers/tsconfig.json b/common/models/wordbreakers/tsconfig.json index 6c029da40a..549b7410d6 100644 --- a/common/models/wordbreakers/tsconfig.json +++ b/common/models/wordbreakers/tsconfig.json @@ -8,6 +8,7 @@ "moduleResolution": "Node16", "declaration": true, "sourceMap": true, + "importHelpers": true, "inlineSources": true, "sourceRoot": "/common/models/wordbreakers/src", "strict": true, diff --git a/common/web/lm-worker/build-bundler.js b/common/web/lm-worker/build-bundler.js index 605ff3cd40..eb7bb5ea41 100644 --- a/common/web/lm-worker/build-bundler.js +++ b/common/web/lm-worker/build-bundler.js @@ -6,8 +6,8 @@ */ import esbuild from 'esbuild'; -import { spawn } from 'child_process'; import fs from 'fs'; +import { determineNeededDowncompileHelpers, buildTslibTreeshaker } from '@keymanapp/tslib/esbuild-tools'; /* * Refer to https://github.com/microsoft/TypeScript/issues/13721#issuecomment-307259227 - @@ -92,7 +92,12 @@ await esbuild.build({ target: "es5" }); +// The one that's actually a component of our releases. + const embeddedWorkerBuildOptions = { + alias: { + 'tslib': '@keymanapp/tslib' + }, bundle: true, sourcemap: true, format: "iife", @@ -106,6 +111,10 @@ const embeddedWorkerBuildOptions = { target: "es5" } +// Prepare the needed setup for `tslib` treeshaking. +const unusedHelpers = await determineNeededDowncompileHelpers(embeddedWorkerBuildOptions); +embeddedWorkerBuildOptions.plugins = [buildTslibTreeshaker(unusedHelpers), ...embeddedWorkerBuildOptions.plugins]; + // Direct-use version await esbuild.build(embeddedWorkerBuildOptions); diff --git a/common/web/lm-worker/build.sh b/common/web/lm-worker/build.sh index 75a72df12d..82fba9bb39 100755 --- a/common/web/lm-worker/build.sh +++ b/common/web/lm-worker/build.sh @@ -28,6 +28,7 @@ WORKER_OUTPUT_FILENAME=build/lib/worker-main.js builder_describe \ "Compiles the Language Modeling Layer for common use in predictive text and autocorrective applications." \ "@/common/web/keyman-version" \ + "@/common/web/tslib" \ "@/common/models/wordbreakers" \ "@/common/models/templates" \ "@/common/tools/sourcemap-path-remapper" \ diff --git a/common/web/lm-worker/tsconfig.json b/common/web/lm-worker/tsconfig.json index 551f1645a9..2fdda0135a 100644 --- a/common/web/lm-worker/tsconfig.json +++ b/common/web/lm-worker/tsconfig.json @@ -5,7 +5,8 @@ "allowJs": false, "declaration": true, "module": "es6", - "moduleResolution": "node", + "moduleResolution": "node16", + "importHelpers": true, "inlineSourceMap": true, "inlineSources": true, "sourceRoot": "/common/web/lm-worker/src",