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

feat: CoffeeScript ESM loader #5401

Open
wdavidw opened this issue Feb 22, 2022 · 1 comment · May be fixed by #5423
Open

feat: CoffeeScript ESM loader #5401

wdavidw opened this issue Feb 22, 2022 · 1 comment · May be fixed by #5423

Comments

@wdavidw
Copy link

wdavidw commented Feb 22, 2022

Request type

feature

Description

ESM support in the latest Node.js version induce a new loading mechanism. Instead of the current register strategy, a Node.js ESM loader must be provided. I couln't find one yet available for CoffeeScript.

Context

While converting some of my packages to ES modules, I had to update the Mocha.js arguments used in the unit tests to no longer use --require coffeescript/register but --loader my-coffee-esm-loader instead. I search through the repository but I couldn't fine one. There are some good examples such as nodejs/node#36396 and the official Node.js doc on ESM transpiler loader. You can see it in action in the CSV parser.

This is in the context of Mocha but the same apply with Node.js since the --loader argument of Mocha is a Node.js one.

While the traditional CommonJS way to activate CoffeeScript was node --require coffeescript/register ..., the ESM counterpart is now node --loader my-coffee-esm-loader ....

Proposal

Would you be interested to include an official Node.js ESM loader in this package, or would you rather me publish an external package ? It wouldn't take long to prepare a pull request, the code is just a few lines and heavily inspired from nodejs/node#36396.

@GeoffreyBooth
Copy link
Collaborator

Hi, I wrote nodejs/node#36396. It’s been my intention to ship an ESM CoffeeScript loader as part of this package, since this package already includes a CommonJS loader (in coffeescript/register). There’s a loader already written here: https://github.com/GeoffreyBooth/node-loaders/tree/main/coffeescript-loader

As you can see in its README, at least when I wrote it it didn’t work for imports of CommonJS files. That’s why I didn’t propose it over here, as just about any project has some CommonJS imports (maybe not of first-party code, but of dependencies). But perhaps this can be addressed? Clearly other projects like ts-node have shipped loaders using the current API, so maybe there’s a way around this limitation.

If you’d like to open a PR here to add a CoffeeScript loader, I would ask that:

  • It be written in CoffeeScript and compiled into lib like everything else, ideally without requiring a new cake command. It could be part of the main codebase like register is.
  • You try to solve the “imports of CommonJS” issue. If there’s no workaround, we would need to document this as a prominent known issue.
  • You find a way to test it. I think this would probably involve spawning a Node child process that can take the loader as a --loader argument.

How does this sound?

@usrtax usrtax linked a pull request Aug 1, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants