feat(common/models): tslib use, treeshaking in lm-worker

This commit is contained in:
Joshua A. Horton 2023-06-08 14:39:55 +07:00
parent 9a6a2f88bf
commit fed4618d02
7 changed files with 21 additions and 9 deletions

View file

@ -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" \

View file

@ -7,6 +7,7 @@
"moduleResolution": "node16",
"sourceMap": true,
"sourceRoot": "/common/models/templates/src",
"importHelpers": true,
"inlineSources": true,
"strict": true,
"lib": ["es6"],

View file

@ -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;
}

View file

@ -8,6 +8,7 @@
"moduleResolution": "Node16",
"declaration": true,
"sourceMap": true,
"importHelpers": true,
"inlineSources": true,
"sourceRoot": "/common/models/wordbreakers/src",
"strict": true,

View file

@ -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);

View file

@ -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" \

View file

@ -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",