-
Notifications
You must be signed in to change notification settings - Fork 26
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
ability to test / detect if a module is a CJS module (parse without the exception) #35
Comments
Trying to parse a module is not enough. For example, you cannot know if this is an ES module or a CJS module just by parsing it, and at runtime it has two different behaviors: console.log("is script?", this !== undefined); |
Sure, I understand a Or maybe there is a way with a combination of tools? Just trying to get it be "good enough". 😃 |
The proper way of detecting CJS vs ESM is to use these rules, which is what Node.js and the various bundlers do. |
Ah, excellent! Thank you so much for sharing, will definitely dive head first into that then. 👀 |
Detecting modules based on whether they use module syntax can be brittle - hence why we use type package boundaries in Node.js. |
Hello! 👋
Just started using this package for a project I've been working on, and one of my use cases is detecting if a package from node_modules is a CommonJS module. It would be great if this package could be extended with an additional function, something like
test
orvalidate
, that would effectively be likeparse
, but rather thanthrow
on not being able to analyze the module, it would just returntrue
/false
instead.For example, this is how I am making it work now by using
parse
.i haven't looked into the code here yet, but if you are inclined to support something like, and you think it could be classified as a "good first issue", I would be happy to try and help.
I was thinking the usage could look something like this
Thanks in advance for your consideration on this, and additionally thanks for all your great work on this and other projects of yours, like es-module-shims and SystemJS. Great stuff! ⭐
The text was updated successfully, but these errors were encountered: