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

TypeScript declarations should generate MainModule type name based on user inputs #21470

Open
jnickg opened this issue Mar 4, 2024 · 5 comments
Assignees

Comments

@jnickg
Copy link
Contributor

jnickg commented Mar 4, 2024

Currently, users generating TypeScript declarations as part of compilation always get a file where the wasm module's main type is named MainModule. One consequence of this is that users generating packages directly from the TSD and wasm/js output wind up with name collisions, if they import multiple modules into another project. Working around this is not difficult (shown below) but it does betray the fact that, at the time of writing, wasm module type names are hard-coded to be MainModule.

import { MainModule as MyModule1 } from "my-package-1"; // Must use "as" to prevent name collision
import { MainModule as MyModule2 } from "my-package-2";

Further, users can specify names using -s EXPORT_NAME=MyModule (though this isn't always 1:1 with what we'd want to call the module's type), so having an output type name of MainModule can be confusing to users.

Per a conversation in #21460, and #20296, align TSD generation with EXPORT_NAME or a new setting e.g. MODULE_NAME, so that users can set this name automatically.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 9, 2024

Since this type is already encapsulated within the module perhaps its OK for the names to collide?

FWIW I reallly don't like MainModule as a name, but that is a different issue.

Presumably it might even be useful to have them all called the same thing if you are working with multiple modules.

If we do decide that unique names within the module are a good idea how about using the -o filename as the default?

e.g. ./emcc -o foo.js would default to EXPORT_NAME or foo?

Also, is this issue a duplicate of #20952?

@skywalker212
Copy link

Can I work on this issue?

@brendandahl
Copy link
Collaborator

Sure, though I think this is less of an issue now. With modularize enabled, the export will be a default so the name doesn't really matter e.g. export default function MainModuleFactory .

@skywalker212
Copy link

Thanks, I want to start contributing to emscripten, so I will use this as a starting point!

@skywalker212
Copy link

Sure, though I think this is less of an issue now. With modularize enabled, the export will be a default so the name doesn't really matter e.g. export default function MainModuleFactory .

I understand what you meant now, I was thinking EXPORT_NAME is used in the name of the interface of the module instead of the name of the factory function that creates the module. As you mentioned, in this case there is no point in changing the export name.

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

No branches or pull requests

4 participants