Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(web): remove support for es5 #11881

Open
wants to merge 3 commits into
base: refactor/web/typescript
Choose a base branch
from

Conversation

ermshiperete
Copy link
Contributor

Fixes: #11878

@keymanapp-test-bot skip

@keymanapp-test-bot keymanapp-test-bot bot added this to the A18S5 milestone Jun 26, 2024
@ermshiperete ermshiperete marked this pull request as ready for review July 2, 2024 17:20
@ermshiperete ermshiperete changed the base branch from master to refactor/web/typescript July 2, 2024 17:21
@ermshiperete ermshiperete marked this pull request as draft July 2, 2024 21:07
@ermshiperete ermshiperete force-pushed the change/web/11878_remove-es5 branch 2 times, most recently from 68a1330 to a1bdce0 Compare July 4, 2024 16:52
ermshiperete and others added 3 commits July 4, 2024 20:49
…'s version

Node's version has special behavior for events named 'error' - if no handler, it auto-throws.  EventEmitter3 does not include this.
This fixes building all dependencies, e.g. when running `./build.sh test`
which previously failed because it didn't build all necessary targets.
@ermshiperete ermshiperete force-pushed the change/web/11878_remove-es5 branch 2 times, most recently from c2f69cc to 2d9d847 Compare July 4, 2024 20:21
@ermshiperete ermshiperete marked this pull request as ready for review July 4, 2024 21:15
@@ -45,21 +45,26 @@ function do_build() {
tsc --build "$THIS_SCRIPT_PATH/tsconfig.all.json"

# Base product - the main keyboard processor
$BUNDLE_CMD "${KEYMAN_ROOT}/common/web/keyboard-processor/build/obj/index.js" \
${BUNDLE_CMD} "${KEYMAN_ROOT}/common/web/keyboard-processor/build/obj/src/index.js" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change in path here?

Copy link
Contributor

@jahorton jahorton Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, just to be clear - be very careful when changing the build-output paths like this - it has a tendency to have unwanted side effects in the end-result sourcemap files, often causing the pathing structure shown when debugging via Chrome to become very messy and thus more difficult to utilize.

Part of the reason the /src/ bit wasn't in there to begin with is that omitting it allows the compiled *.js files to be at the same depth as their source counterparts, and that seriously simplifies the sourcemap-editing operations that we apply during top-level compilation. (I forget some of the details; the main reason it was so helpful might be fully in the past, but there's a chance it could be something that would still apply even now.)

Comment on lines +18 to +19
if(window['KeymanWeb' as any]) {
(window['KeymanWeb' as any] as any).uninstall();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using this at the file's top:

declare let KeymanWeb: KeyboardInterface

It's possible to declare globals with type, after which you won't need the as any stuff.

We already use this pattern in a few places, such as the spot below:

declare var keyman: KeymanEngine

With that in place, it doesn't fix the window['keyman'] pattern, but it does allow us to just assume that keyman exists as a global, which achieves what we're really after anyway.

@@ -21,7 +21,7 @@ export default {
concurrency: 10,
nodeResolve: true,
files: [
'**/*.spec.ts'
'build/lib/**/*.spec.mjs'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would strongly prefer a specific build folder for tests, then a specific folder for each test set.

Something like build/test/dom/**/*.spec.mjs - this pattern is being maintained for /web/src/test/auto/dom/ tests, so why not be consistent with the pattern and reuse it here?

(While this module's headless tests aren't yet in TS, they could then go under build/test/headless/**.)

A general pattern is for lib folders to hold bundled / fully-compiled outputs, not testing files... right? Or am I just mistaken about that? Either way, that's a pattern I've held to strongly with the lower-level packages; test file outputs do not belong in that folder, in my opinion. Too messy.

'src/test/auto/dom/cases/attachment/**/*.spec.html',
'src/test/auto/dom/cases/attachment/**/*.spec.ts'
'build/test/dom/cases/attachment/**/*.spec.html',
'build/test/dom/cases/attachment/**/*.spec.mjs'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To compare with the comment I made for keyboard-processor tests: note how the build/test/dom/** pattern is being used here, with minimal changes to boot.

Copy link
Contributor

@jahorton jahorton Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this file exists to polyfill for things that would be otherwise missing with ES5, etc. There's a strong chance we should be able to eliminate this script entirely, though it'd take a bit of extra work.

(To be clear, that "extra work" could be done later; just make a tracking issue if so.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, it would be nice to drop this if viable. I'll want to double-check the outputs to ensure that we aren't getting duplicated/triplicated tslib helper functions due to it, just to be sure, but the comments originally at the top here suggest that we should be fine.

The Web filesize-increase reporter should signal a significant spike in filesize if it's not resolving the helpers properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... Hmm. We went from +32 bytes from the prior PR to +4619 bytes in this one. It's definitely worth double-checking the build output for duplicated helpers, then.

Comment on lines +326 to +330
if(this.listenerCount('error') > 0) {
this.emit('error', err);
} else {
throw err;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other reviewers, just in case:

We use eventemitter3 so that Web can safely compile against common/web/types; events is a Node-specific package that won't exist in the browser. There is one particular point of divergence between the two types:

  • In events, .emit('error') will actually throw the error if there are no registered listeners.
  • In eventemitter3, this specialized behavior is omitted. It will never throw on .emit('error') regardless of listener count.

This is the one spot in xml2js that uses .emit('error'), so we opted for a precise adjustment to accommodate for the difference between the two implementations that will replicate the behavior of the original. One of the common/web/types unit tests fails otherwise due to reliance on the pattern.

configure "/node_modules" \
build "/web/build/test/dom/cases/attachment/outputTargetForElement.spec.html" \
build:app/browser "/web/build/app/browser/lib/index.mjs" \
build:app/WebViews "/web/build/app/webview/${config}/keymanweb-webview.js" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
build:app/WebViews "/web/build/app/webview/${config}/keymanweb-webview.js" \
build:app/webview "/web/build/app/webview/${config}/keymanweb-webview.js" \

@darcywong00 darcywong00 added this to the A18S6 milestone Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

change(web): remove ES5 support
3 participants