Skip to content

Runtime detection of JS shim output mode #3157

@daxpedda

Description

@daxpedda

Motivation

When re-using the JS shim for workers and worklets it's necessary to know if the shim is an ES module or a regular JS script to import it correctly. I found that common solutions just assumed that it is a ES module because everybody uses Chrome (Firefox doesn't support ES modules in workers and worklets yet).

Currently there is no way to know during runtime which it is, a re-usable library hard.

Proposed Solution

A simple static function that returns if it's a ES module or not.

Alternatives

The alternative is to continue solving this issue during build time, totally doable, just increases user friction.

Additional Context

This is similar to #3032, it's a tacked on solution to a bigger problem that won't be solved that way. This could be solved by a more expansive strategy like #3034.

I would like to figure out if we can continue to figure out more temporary solutions in the meantime, as it seems that maintainers don't have the review capacity for bigger features.

Happy to make the PR myself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions