Simplify importing#184
Conversation
|
Okay now I’m slowly getting to understand this project’s structure.
Now I see this PR already takes advantage of top-level await in index.ts, which become available on most platforms around five years ago. If the intention is to allow users (who still can’t benefit from top-level await) to avoid importing index.ts (so they can import |
|
I don't think Top-level await can be problematic when using bundlers: esbuild doesn't support it, and I've had some work-around-able issues with rolldown. Rollup and webpack support it perfectly, though, as do browsers, node, bun, deno, etc. Having top-level-await by default makes sense to me since it makes the package so much easier to use. |
Uh, Or are you talking about something else?
Do I understand it correctly that your recommendation is to provide a simple, default API that takes advantage of top-level await (for environments that support it fine), but make sure using this package doesn’t depend on it (so, eg, esbuild and rolldown users can avoid loading the problematic module)? |
You're right, I got lost in the code.
Yeah. I think this PR will work for most people, and if anyone runs into TLA issues or wants more control over the WASM request in the browser, we could export |
|
I don’t really care about people running ancient systems, this is generally a web-facing code where people on old systems are doing themselves a disfavor security-wise. But if all is needed is exporting |
Do WASM initialization at module load time, so that explicit await is
not needed:
import * as hb from "harfbuzzjs";
let face = new hb.Face(new hb.Blob(data));
or:
import {Blob, Face} from "harfbuzzjs";
let face = new Face(new Blob(data));
5c5f66c to
c8969c8
Compare
For cases where top-level await is not supported, or when WASM locations
needs to be overridden:
import { createHarfBuzz, init, Face } from "harfbuzzjs";
init(await createHarfBuzz({ locateFile: ... }));
|
I think I’m done tweaking this, is it OK now? |
|
Looks good enough – let’s move on! A question for @chearon, not meant to block this PR: I thought |
|
@khaledhosny @chearon, oh I realized that And for users who don’t have a problem with top-level await, they don’t need |
Right, I came to the same conclusion while writing the migration guide last night, but I forgot to update this PR. I’ll drop it now. |
|
Now, the question is what to do about |
|
Uh, I thought for users who can’t depend on top-level await they can just import
Were you actually talking about the re-exporting from index.ts (feels as unnecessary as the re-exporting of |
But we don’t have |
|
Ah! That’s the missing piece in my understanding of this whole discussion between you and @chearon! (My understanding of bundling is very limited.) Yeah it’s tricky. Sounds like there’s several directions:
|
|
Also, is this relevant? https://tsdown.dev/recipes/wasm-support |
|
I’m inclined to drop the re-export of |
I’d like to keep the separate WASM file, so people can import it manually and add whatever JS interface they like on top if it. It is a use case we always supported and advertised, and I don’t see a pressing need to break it. |
See the discussion in #184
Do WASM initialization at module load time, so that explicit await is not needed:
or: