Skip to content

Commit

Permalink
Merge pull request #8904 from keymanapp/change/web/common-downcompile…
Browse files Browse the repository at this point in the history
…-helpers

change(web): common downcompile helpers 🧩
  • Loading branch information
jahorton authored Jun 9, 2023
2 parents 53429b3 + 9aea971 commit 4ae1677
Show file tree
Hide file tree
Showing 50 changed files with 398 additions and 177 deletions.
3 changes: 3 additions & 0 deletions common/predictive-text/build-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import esbuild from 'esbuild';
import { spawn } from 'child_process';

await esbuild.build({
alias: {
'tslib': '@keymanapp/tslib'
},
bundle: true,
sourcemap: true,
format: "esm",
Expand Down
1 change: 1 addition & 0 deletions common/predictive-text/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cd "$(dirname "$THIS_SCRIPT")"

builder_describe "Builds the lm-layer module" \
"@/common/web/keyman-version" \
"@/common/web/tslib" \
"@/common/web/lm-worker" \
"clean" \
"configure" \
Expand Down
1 change: 1 addition & 0 deletions common/predictive-text/src/node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"declaration": true,
"module": "es6",
"moduleResolution": "Node16",
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"sourceRoot": "keyman",
Expand Down
1 change: 1 addition & 0 deletions common/predictive-text/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"declaration": true,
"module": "es6",
"moduleResolution": "Node16",
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"sourceRoot": "keyman",
Expand Down
1 change: 1 addition & 0 deletions common/predictive-text/src/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"declaration": true,
"module": "es6",
"moduleResolution": "Node16",
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"sourceRoot": "keyman",
Expand Down
1 change: 1 addition & 0 deletions common/predictive-text/tsconfig.all.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"declaration": true,
"module": "es6",
"moduleResolution": "Node16",
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"sourceRoot": "keyman",
Expand Down
6 changes: 6 additions & 0 deletions common/web/input-processor/build-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { spawn } from 'child_process';
// Bundled ES module version
esbuild.buildSync({
entryPoints: ['build/obj/index.js'],
alias: {
'tslib': '@keymanapp/tslib'
},
bundle: true,
sourcemap: true,
external: ['fs', 'vm'],
Expand All @@ -29,6 +32,9 @@ esbuild.buildSync({
// Bundled CommonJS (classic Node) module version
esbuild.buildSync({
entryPoints: ['build/obj/index.js'],
alias: {
'tslib': '@keymanapp/tslib'
},
bundle: true,
sourcemap: true,
external: ['fs', 'vm'],
Expand Down
1 change: 1 addition & 0 deletions common/web/input-processor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "es6",
"moduleResolution": "Node16",
"declaration": true,
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"sourceRoot": "keyman/",
Expand Down
15 changes: 15 additions & 0 deletions common/web/keyboard-processor/build-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { spawn } from 'child_process';

/** @type {esbuild.BuildOptions} */
const commonConfig = {
alias: {
'tslib': '@keymanapp/tslib'
},
bundle: true,
sourcemap: true,
format: "esm",
Expand All @@ -23,6 +26,9 @@ const commonConfig = {

// Bundled ES module version
esbuild.buildSync({
alias: {
'tslib': '@keymanapp/tslib'
},
entryPoints: ['build/obj/index.js'],
outfile: "build/lib/index.mjs",
format: "esm",
Expand All @@ -31,6 +37,9 @@ esbuild.buildSync({

// Bundled CommonJS (classic Node) module version
esbuild.buildSync({
alias: {
'tslib': '@keymanapp/tslib'
},
entryPoints: ['build/obj/index.js'],
outfile: 'build/lib/index.cjs',
bundle: true,
Expand All @@ -42,6 +51,9 @@ esbuild.buildSync({


esbuild.buildSync({
alias: {
'tslib': '@keymanapp/tslib'
},
entryPoints: ['build/obj/keyboards/loaders/dom-keyboard-loader.js'],
outfile: 'build/lib/dom-keyboard-loader.mjs',
format: "esm",
Expand All @@ -50,6 +62,9 @@ esbuild.buildSync({

// The node-based keyboard loader needs an extra parameter due to Node-built-in imports:
esbuild.buildSync({
alias: {
'tslib': '@keymanapp/tslib'
},
entryPoints: ['build/obj/keyboards/loaders/node-keyboard-loader.js'],
outfile: 'build/lib/node-keyboard-loader.mjs',
format: "esm",
Expand Down
1 change: 1 addition & 0 deletions common/web/keyboard-processor/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ builder_describe \
"Compiles the web-oriented utility function module." \
"@/common/web/recorder test" \
"@/common/web/keyman-version" \
"@/common/web/tslib" \
"@/common/web/utils" \
configure \
clean \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "es6",
"moduleResolution": "Node16",
"declaration": true,
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"sourceRoot": "keyman/",
Expand Down
1 change: 1 addition & 0 deletions common/web/keyboard-processor/tsconfig.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "es6",
"moduleResolution": "Node16",
"declaration": true,
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"sourceRoot": "keyman/",
Expand Down
1 change: 1 addition & 0 deletions common/web/keyboard-processor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "es6",
"moduleResolution": "Node16",
"declaration": true,
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"sourceRoot": "keyman/",
Expand Down
15 changes: 15 additions & 0 deletions common/web/tslib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The default import setup for the `tslib` package is unfortunately incompatible with `esbuild` when in ES5 mode. But...
with a little elbow grease, we can fix that with _this_ package by importing its ES5-compatible file and exporting it
as _this_ package's default export for use in anything looking to `"importHelpers"`.

To utilize this with `esbuild` while enabling the `"importHelpers"` compilation option in your tsconfig.json, you'll want
to set the following in your `esbuild` config:

```javascript
alias: {
'tslib': '@keymanapp/tslib'
},
```

Note that esbuild 0.15.16 is the minimum required version to utilize the 'alias' feature necessary to replace `tslib` for
`tsc`-generated `import { /* */ } from 'tslib'` statements that result from enabling `"importHelpers"` in a tsconfig.
27 changes: 27 additions & 0 deletions common/web/tslib/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
. "${THIS_SCRIPT%/*}/../../../resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE

. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"

cd "$THIS_SCRIPT_PATH"

################################ Main script ################################

builder_describe \
"A ES5 + esbuild compatibility wrapper for the 'tslib' package." \
clean configure build

builder_describe_outputs \
configure "/node_modules" \
build "/common/web/tslib/build/index.js"

builder_parse "$@"

builder_run_action configure verify_npm_setup
builder_run_action clean rm -rf build/
builder_run_action build tsc --build
18 changes: 18 additions & 0 deletions common/web/tslib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@keymanapp/tslib",
"description": "An ES5 + esbuild-compatible wrapper for the 'tslib' library",
"main": "./build/index.js",
"scripts": {
"build": "gosh ./build.sh build",
"clean": "gosh ./build.sh clean"
},
"dependencies": {
"tslib": "^2.5.2",
"typescript": "^4.9.5"
},
"devDependencies": {
"@keymanapp/resources-gosh": "*",
"esbuild": "^0.15.16"
},
"type": "module"
}
3 changes: 3 additions & 0 deletions common/web/tslib/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from '../../../../node_modules/tslib/tslib.js';

export * as tslib from '../../../../node_modules/tslib/tslib.js';
21 changes: 21 additions & 0 deletions common/web/tslib/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig-base.json",
"compilerOptions": {
"allowJs": true,
"module": "es6",
"moduleResolution": "Node",
"inlineSources": true,
"sourceMap": true,
"declaration": true,
"target": "es5",
"tsBuildInfoFile": "./build/tsconfig.tsbuildinfo",
"types": ["node"],
"lib": ["es6"],
"baseUrl": "./src",
"outDir": "./build/",
"rootDir": "./src"
},
"include": [
"./src/index.ts"
]
}
6 changes: 6 additions & 0 deletions common/web/utils/build-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { spawn } from 'child_process';
// Bundles to a compact ESModule
esbuild.buildSync({
entryPoints: ['build/obj/index.js'],
alias: {
'tslib': '@keymanapp/tslib'
},
bundle: true,
sourcemap: true,
//minify: true, // No need to minify a module.
Expand All @@ -24,6 +27,9 @@ esbuild.buildSync({
// Bundles to a compact CommonJS (classic Node) module
esbuild.buildSync({
entryPoints: ['build/obj/index.js'],
alias: {
'tslib': '@keymanapp/tslib'
},
bundle: true,
sourcemap: true,
//minify: true, // No need to minify a module.
Expand Down
1 change: 1 addition & 0 deletions common/web/utils/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cd "$THIS_SCRIPT_PATH"
builder_describe \
"Compiles the web-oriented utility function module." \
"@/common/web/keyman-version" \
"@/common/web/tslib" \
clean configure build test \
"--ci For use with action ${BUILDER_TERM_START}test${BUILDER_TERM_END} - emits CI-friendly test reports"

Expand Down
1 change: 1 addition & 0 deletions common/web/utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"allowJs": true,
"module": "es6",
"moduleResolution": "Node16",
"importHelpers": true,
"inlineSources": true,
"sourceMap": true,
"declaration": true,
Expand Down
Loading

0 comments on commit 4ae1677

Please sign in to comment.