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

Convert library from CommonJS to ES Module #5

Closed
eliot-akira opened this issue Apr 7, 2024 · 2 comments
Closed

Convert library from CommonJS to ES Module #5

eliot-akira opened this issue Apr 7, 2024 · 2 comments

Comments

@eliot-akira
Copy link
Contributor

eliot-akira commented Apr 7, 2024

Eventually the library should be transitioned from CommonJS style require statements like:

const path = require('path')

..into ES Module style using import, which is the new standard.

import path from 'path'

Luckily, since the Roller library is used only as a command-line tool and not meant to be imported as a module, this change shouldn't affect users of the library with projects that are still on CommonJS.

The change also involves replacing module.exports with export statements.


@nicolas-jaussaud I wanted to let you know about this change in advance, just in case it might have unintended effects. In the JS ecosystem the transition has been a bit rough, as some popular libraries converted too early and broke compatibility. It should be fine in our case though.

I was reminded of this when you mentioned tangible.config.js starting with:

module.exports = { ... }

Gradually, I'd like to convert projects (plugins, etc.) to use ES Module style imports. This can be enabled in package.json with a single line:

  "type": "module",

And changing the config file to export like this:

export default { ... }

This is already supported in the current version of Roller, as it uses await import() to load the config file instead of require().

@nicolas-jaussaud
Copy link
Contributor

Oh I see, I will try to test and make the change each time I encounter a project that uses the old syntax

Thank you for the explanation!

nicolas-jaussaud added a commit to TangibleInc/fields that referenced this issue Jul 18, 2024
@eliot-akira
Copy link
Contributor Author

Resolved:

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

2 participants