Coder Social home page Coder Social logo

Comments (5)

nicolo-ribaudo avatar nicolo-ribaudo commented on July 30, 2024 1

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);

from cjs-module-lexer.

nicolo-ribaudo avatar nicolo-ribaudo commented on July 30, 2024 1

The proper way of detecting CJS vs ESM is to use these rules, which is what Node.js and the various bundlers do.

from cjs-module-lexer.

thescientist13 avatar thescientist13 commented on July 30, 2024

Sure, I understand a detect function would just be as limited as parse is, but it would still be nice to get the functionality of parse, but just without the Error being thrown if the lexar can't analyze it correctly. I understand there is some naivety in the approach, and my project absolutely favors users going down the ESM path, so it's mostly just for a convenience and a way to nudge people away from CommonJS in their dependency trees, (e.g. lodash vs lodash-es).

Or maybe there is a way with a combination of tools? Just trying to get it be "good enough". 😃

from cjs-module-lexer.

thescientist13 avatar thescientist13 commented on July 30, 2024

Ah, excellent! Thank you so much for sharing, will definitely dive head first into that then. 👀

from cjs-module-lexer.

guybedford avatar guybedford commented on July 30, 2024

Detecting modules based on whether they use module syntax can be brittle - hence why we use type package boundaries in Node.js.

from cjs-module-lexer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.