-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
[Javascript] Added support for commonjs in nodejs package #4217
Conversation
Signed-off-by: Adrian Jutrowski <adrian.jutrowski@gmail.com>
Hey, nobody's enforcing anything, and we welcome contributors. Let's see how this works for other devs looking for CommonJS support. |
@Tarjei400 thank you :-) will have a look. @ericvergnaud thanks for notification. |
@enessoylu I just mean that at the moment library requires ESM in a project and this is "enforcing" ESM in a project, I didnt mean anyone per se :P Anyways thanks for taking a look, I think it will be a usefull addition for this package! |
I think adding Following down this path should help with the TypeScript target as well. For example as of TypeScript 5.0 you can do the following with
And with TypeScript 5 the package entry point & types can be toggled in the |
@jharris4 I will take a look later this afternoon for all cases you mentioned , however in my case I can only import cjs file in node project. |
7f57971
to
3a86783
Compare
@jharris4 Sorry it took some time. I checked that export solution and added tests for nodejs esm/commonjs and updated PR |
…mpacted Signed-off-by: Adrian Jutrowski <adrian.jutrowski@gmail.com>
@@ -0,0 +1,31 @@ | |||
"use strict"; | |||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use an explanation of the code in this file. Why can't we just write "require('antlr4')" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I just transpiled it with ts, but you are right require will do the job. Changed 👍
runtime/JavaScript/webpack.config.js
Outdated
@@ -5,68 +5,63 @@ import {fileURLToPath} from "url"; | |||
const __filename = fileURLToPath(import.meta.url); | |||
const __dirname = path.dirname(__filename); | |||
|
|||
const nodeConfig = { | |||
|
|||
const buildConfig = ( platform, extentions ) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exten*t*ions or extensions ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type, fixed
If I understand correctly, this PR would generate esm and cjs for web and node, without touching any runtime code ? Sounds promising! Awaiting for my inline comments to be addressed. |
…require Signed-off-by: Adrian Jutrowski <adrian.jutrowski@gmail.com>
Correct @ericvergnaud :D Addressed your comments! |
Good stuff! Thanks so much, I know for sure this will make many developers happy. |
Myself included :D Also thanks for this great tool! |
Fixes #4211 |
@Tarjei400 big thanks for this 😊 |
NiceBeste Grüße,Nils BaumgartnerAm 10.11.2023 um 09:43 schrieb Andy Edwards ***@***.***>:
@Tarjei400 big thanks for this 😊
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
No package should enforce upon creator a need to migrate to ESM. As per this pull request, I added webpack configuration that produces cjs and mjs files Correspoding to CommonJS and ESM module. After this pull request if will be up to a project which one to use.
Cheers!