Skip to content

Convert to TypeScript and ES6 modules#176

Merged
khaledhosny merged 33 commits intomainfrom
ts
Apr 5, 2026
Merged

Convert to TypeScript and ES6 modules#176
khaledhosny merged 33 commits intomainfrom
ts

Conversation

@khaledhosny
Copy link
Copy Markdown
Contributor

No description provided.

@khaledhosny khaledhosny linked an issue Apr 1, 2026 that may be closed by this pull request
@khaledhosny
Copy link
Copy Markdown
Contributor Author

This looks like a big rewrite, but most of the actual code is unchanged.

@khaledhosny
Copy link
Copy Markdown
Contributor Author

@akash-joshi @graphicore @justvanrossum @lianghai

Please take a look. There are many API breakages, but nothing fundamental. I took the opportunity to cleanup some (of what I think are) API warts, but you probably have more insight on the actual use of the library. This is a chance to get any API improvements we want since we are breaking API already.

@lianghai
Copy link
Copy Markdown

lianghai commented Apr 2, 2026

Since .ts files are being renamed to .ts files anyway, this is a good opportunity to move them into a src directory, so there’s a clear separation between the JS/TS source files and the build-time Wasm-generating logic.

Also I wonder if the “hb” and “hbjs” files can have more explicit names, because I always find it kinda confusing to mentally navigate around the similar looking but different concepts of “harfbuzzjs”, “hbjs”, “hb”, and “harfbuzz”. For example, can hbjs.ts be either merged into index.ts, or broken down to smaller files with more specific names? Can hb.wasm/js be renamed to harfbuzz.wasm/js if they’re meant to be the Wasm build and JS wrapper (?) of harfbuzz/src/harfbuzz.cc?

Comment thread .github/workflows/docs.yml Outdated
Comment thread hbjs.ts Outdated
Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread index.ts Outdated
Comment thread hb.d.ts Outdated
Comment thread hbjs.ts Outdated

// Module-level WASM state (set once by init)
let Module: any;
let exports: any;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we were to use embind we could avoid these any.... maybe later.

@tomasdev
Copy link
Copy Markdown

tomasdev commented Apr 2, 2026

Overall looks okay, my main concern is around security of the test dependencies.

Then ideally it would use emscripten instead of just em++ so we get some free types and we are able to remove all any

@khaledhosny
Copy link
Copy Markdown
Contributor Author

Since .ts files are being renamed to .ts files anyway, this is a good opportunity to move them into a src directory, so there’s a clear separation between the JS/TS source files and the build-time Wasm-generating logic.

Good idea. We didn’t use a bundler before, so a single file made sense. I have now split the source code into roughly one file per class.

Also I wonder if the “hb” and “hbjs” files can have more explicit names, because I always find it kinda confusing to mentally navigate around the similar looking but different concepts of “harfbuzzjs”, “hbjs”, “hb”, and “harfbuzz”. For example, can hbjs.ts be either merged into index.ts, or broken down to smaller files with more specific names? Can hb.wasm/js be renamed to harfbuzz.wasm/js if they’re meant to be the Wasm build and JS wrapper (?) of harfbuzz/src/harfbuzz.cc?

I unified things on harfbuzz.

@khaledhosny
Copy link
Copy Markdown
Contributor Author

Then ideally it would use emscripten instead of just em++ so we get some free types and we are able to remove all any

Can you elaborate? I thought em++ is emscripten.

Comment thread src/types.ts
/** EmscriptenModule extended with MODULARIZE runtime methods. */
export interface HarfBuzzModule extends EmscriptenModule {
wasmExports: Record<string, (...args: any[]) => any>;
addFunction(func: (...args: any[]) => any, signature: string): number;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't -s EXTRA_EXPORTED_RUNTIME_METHODS provide these?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the interface. The EmscriptenModule interface does not include these.

@khaledhosny khaledhosny merged commit 9888736 into main Apr 5, 2026
2 checks passed
@khaledhosny khaledhosny deleted the ts branch April 5, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose constants/enums?

3 participants