Git Product home page Git Product logo

Comments (12)

arcanis avatar arcanis commented on June 24, 2024 1

This isn't a PnP issue, more a missing import-meta-resolve feature (standard Node.js loader support), see #10 (comment)

from import-meta-resolve.

JounQin avatar JounQin commented on June 24, 2024 1

What do you mean by

So using Yarn like this means you can’t use node

There is yarn node

Is that normal for Yarn users? That they can’t call commitlint? They have to wrap it in yarn commitlint?

When use yarn, the user must use yarn commitlint, like npx commitlint, there is no yarn global binaries anymore.


Use import.meta.resolve. Don‘t use this package.

I'd love to, but we're still targeting on Node < 20, and the second parameter is still experimental.

There are use cases when you do or don’t want loaders. I like not having to load all that code to support loaders.

Understand, I'm fine with not supporting loaders(or yarn P'n'P actually) personally.

from import-meta-resolve.

wooorm avatar wooorm commented on June 24, 2024 1

I think it’s interesting, the Yarn PnP thing. But it intentionally does lots of things differently. As you show, it has to wrap CLIs and node itself. So it’s not going to work with several tools.

As for supporting loaders, I think it would be a lot of work. Also to maintain. I don’t think anyone is interested in doing that work. See #10 (comment).

from import-meta-resolve.

wooorm avatar wooorm commented on June 24, 2024

It can’t work, see #10.

from import-meta-resolve.

JounQin avatar JounQin commented on June 24, 2024

Yeah, I looked through that issue, and hope the yarn berry team can help.

cc @arcanis @merceyz @paul-soporan @larixer

from import-meta-resolve.

JounQin avatar JounQin commented on June 24, 2024

I think we'd better discuss in this new issue instead of the closed one.

So I quoted @arcanis's comment here.

As I understand it (I backported recent changes just now), loaders are implemented above resolve: nodejs/node@3ebe753/lib/internal/modules/esm/loader.js.

It's the other way around - import.meta.resolve must go through loaders. If it wasn't, calling import(import.meta.resolve(...)) wouldn't work, which would be unacceptable. You can easily check it:

import {register} from 'module';

// export async function resolve() {
//   return {shortCircuit: true, url: 'file:///lol'};
// }
register('data:application/javascript;charset=utf-8,export%20async%20function%20resolve%28%29%20%7B%0D%0A%20%20return%20%7BshortCircuit%3A%20true%2C%20url%3A%20%27file%3A%2F%2F%2Flol%27%7D%3B%0D%0A%7D');

console.log(import.meta.resolve('foo'));

Prints

file:///hello

In other words, import-meta-resolve should implement loader support to be on parity with import.meta.resolve, this isn't an issue with PnP itself.

from import-meta-resolve.

wooorm avatar wooorm commented on June 24, 2024

It's the other way around - import.meta.resolve must go through loaders

Then where is the code in Node that does that?

I know that it’s still done by the function at import.meta.resolve. But it’s not in the code Node uses to resolve things. Similar to how import.meta.url can’t be polyfilled.

In other words, import-meta-resolve should implement loader support to be on parity with import.meta.resolve

Where is the API in Node to find which loaders are currently turned on? I don’t think it exists. I don’t think this can be done.

from import-meta-resolve.

wooorm avatar wooorm commented on June 24, 2024

Joun, what you are asking for is that people have to specify --loader some-yarn-loader to your commit-lint CLI.
Do you really want that?

from import-meta-resolve.

JounQin avatar JounQin commented on June 24, 2024

@wooorm I don't think that's the solution? yarn will call its own .pnp.loader.mjs automatically without user action.

image

from import-meta-resolve.

wooorm avatar wooorm commented on June 24, 2024

Yes that’s a loader. Someone has to use it?
If you want this package to support loaders like Node does, then it would mean someone has to do commitlint --loader .pnp.loader.mjs?

from import-meta-resolve.

JounQin avatar JounQin commented on June 24, 2024

@wooorm

No, the user don't need to do like that, he/she would only need to run yarn commitlint, no need to specific --loader option. What means yarn wraps --loader .pnp.loader.mjs for the user automatically.

image

from import-meta-resolve.

wooorm avatar wooorm commented on June 24, 2024

It sort of does that. It can’t exactly, because your CLI calls Node: https://github.com/conventional-changelog/commitlint/blob/87b1d36d23005b9c1d010ff6a49d1de7f4888cfe/%40commitlint/cli/cli.js.
Yarn is injecting environment variables.
So using Yarn like this means you can’t use node. Jeez.
Is that normal for Yarn users? That they can’t call commitlint? They have to wrap it in yarn commitlint?


Use import.meta.resolve. Don‘t use this package. The readme says that no loaders (and no env variables) are supported: https://github.com/wooorm/import-meta-resolve#differences-to-node.

import.meta.resolve is stable now. Loaders are incredibly complex. You are free to try it, I think it would be another project the size of this one.
There are use cases when you do or don’t want loaders. I like not having to load all that code to support loaders.

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.