Rules_nodejs: Ability to control the extension of entrypoints

Created on 29 Nov 2019  路  8Comments  路  Source: bazelbuild/rules_nodejs

馃殌 Feature request

With node 13 es modules have become supported without the flag. However, to able to run a file as "es module" instead of commonjs you need to change the extension of the js file to .mjs which is not supported by rollup_bundle currently.

Relevant Rules

rollup_bundle
-->

Description

Currently, the rollup_bundle rule doesn鈥檛 have the ability to output files with different extensions (.cjs or .mjs) rather than .js.

Describe the solution you'd like

I've thought about a solution that simply checks if the output file name already has an extension before putting the .js extension as a suffix. If it does it won't append '.js' as a suffix.

The logic will be done at https://github.com/bazelbuild/rules_nodejs/blob/master/packages/rollup/src/rollup_bundle.bzl#L227

Describe alternatives you've considered

  • Write a genrule that renames the output files
enhancement help wanted

All 8 comments

That would be a useful feature to allow for an .mjs output.

The API shape for that would have to be:

rollup_bundle(
    name = "bundle",
    entry_points = {
        "index.js": "bundle.mjs"
    }
)

as

rollup_bundle(
    name = "bundle",
    entry_point = "index.js",
)

assumes a bundle.js output.

To test if the output file has an extension we'd have to test for a set of expected extensions such as ['.mjs'] since the output filename could be my.bundle.

Finally, the .map output file key just below L227 would need to take into account the extension out:

        if sourcemap == "true":
            result[out_without_extension + "_map"] = "%s.map" % result[out]

@alexeagle May have some better ideas but I think this would be a useful addition.

@gregmagolan I would like to work on if @alexeagle eagle has no other ideas.

@thesayyn and @gregmagolan - what is the status of this?

Sorry I didn't see this earlier, that proposal sounds fine to me!

@evahowe @alexeagle I would happily send a PR for this. Probably a few days later.

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs in two weeks. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

This issue was automatically closed because it went two weeks without a reply since it was labeled "Can Close?"

this is still relevant IMHO. This shouldn't be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

UebelAndre picture UebelAndre  路  4Comments

purkhusid picture purkhusid  路  6Comments

joeljeske picture joeljeske  路  6Comments

samertm picture samertm  路  7Comments

solomatov picture solomatov  路  7Comments