Git Product home page Git Product logo

Comments (8)

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

I recently wanted to add this package as a dependency of Babel, and we are probably going to inline it in our source code so that we can compile it to CJS until we are ready to migrate to ESM: https://github.com/babel/babel/pull/14110/files#diff-754bd25a9bce7737d21fa0a30ade059884e89f9e4298c6c16ee25ad4b21e7651R531

@giltayar Maybe you could do something similar?

An alternative is to do something like https://giuseppegurgone.com/synchronizing-async-functions/ so that you can use dynamic import to load this package and also use the async resolution algorithm, while still being able to use it in a (cjs, sync) ESLint plugin. We do something similar in @babel/eslint-parser: ESLint only allows synchronous parser, but we need to run it asynchronously so we moved it to a separate worker (babel/babel#13199).

from import-meta-resolve.

wooorm avatar wooorm commented on July 22, 2024 1

Hey both!

I think we’ve reached a point where CJS users can create vendored versions of ESM packages they use? E.g.,:

npx esbuild import-meta-resolve --bundle --platform=node --outfile=vendor/import-meta-url.cjs

I think this issue also points to an old problem in esbuild: it should really start supporting async things at some point?

from import-meta-resolve.

ljharb avatar ljharb commented on July 22, 2024 1

It's generally a very bad idea to transpile code one didn't author.

from import-meta-resolve.

giltayar avatar giltayar commented on July 22, 2024 1

@ljharb @wooorm From my point of view this isn't a theoretical discussion. It's a practical one to solve a specific problem I have. And the three suggestions here, from @wooorm and @nicolo-ribaudo, seem like good practical solutions (although the "synchronized worker" sounds a bit too heavy for use in an eslint plugin).

from import-meta-resolve.

wooorm avatar wooorm commented on July 22, 2024

What is this nonsense. Esbuild, swc, webpack, whathaveyou disagree.

@ljharb i understand you were pinged but I don't think us having another ESM discussion is fruitful.

from import-meta-resolve.

ljharb avatar ljharb commented on July 22, 2024

@wooorm this isn't an ESM discussion, it's a "transpiling has caveats that only the author can understand if they apply or not" discussion. There will never be a point at which that isn't true, because the JS language doesn't permit that confidence.

from import-meta-resolve.

wooorm avatar wooorm commented on July 22, 2024

Right, I'm against compiling esm to cjs too?


Though, I assume that an eslint plugin vendoring a dependency with a good amount of tests won't pose any problems?

from import-meta-resolve.

ljharb avatar ljharb commented on July 22, 2024

Whether you compile it yourself or not is the ESM discussion we don't have to have :-) I'm saying that if you don't, nobody else should. A good amount of tests wouldn't likely cover all the platforms that are likely to break.

from import-meta-resolve.

Related Issues (18)

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.