Git Product home page Git Product logo

Comments (8)

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

In browsers/Node.js import.meta.resolve takes a single parameter, so you don't really "notice" that the parent is the file URL and not the folder URL.

from import-meta-resolve.

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

https://github.com/nodejs/node/blob/1b60054fffc0c67a711cdf3efbcc8f44afab0ce2/lib/repl.js#L461

pathToFileURL(path.join(process.cwd(), 'repl')), apparently

from import-meta-resolve.

wooorm avatar wooorm commented on July 22, 2024 1

IMO this is all more about how URLs resolve. Where <a href="x"> goes to. I don’t see the web changing that. It depends on whether you’re on https://example.com/y or https://example.com/y/:

new URL('x', 'https://example.com/y').href // 'https://example.com/x'
new URL('x', 'https://example.com/y/').href // 'https://example.com/y/x'

process.cwd

You can solve it with url.pathToFileURL(process.cwd() + path.sep).


Anyway, this is a copy of Node. Changes go in Node.

In browsers/Node.js import.meta.resolve takes a single parameter, so you don't really "notice" that the parent is the file URL and not the folder URL.
β€” @nicolo-ribaudo

Small nit: they do accept a second parameter. They default to import.meta.url but you can pass any URL. That is impossible to polyfill, so it must be passed explicitly here.

from import-meta-resolve.

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

Supporting both folders and files as the base is ambiguous: if both foo/index.js and foo/bar/index.js exist, what does resolve("./index.js", "foo/bar") resolve to?

The readme currently says that the second parameter is "the absolute parent module URL", maybe it should either be made more prominent or more explicit that a module is a file πŸ€”

from import-meta-resolve.

wooorm avatar wooorm commented on July 22, 2024

I don't see how this issue is here?

Anyway, yeah, its the same as browsers. It matters where you resolve from

from import-meta-resolve.

fabiospampinato avatar fabiospampinato commented on July 22, 2024

I don't see how this issue is here?

Right this is maybe out of place πŸ€” However, the description is "Resolve things like Node.js.", but when I fire up a REPL and import something what file is Node resolving things from?

from import-meta-resolve.

wooorm avatar wooorm commented on July 22, 2024

I think youre looking for import.meta.url? Thats whats also in the docs here as a recommendation.
In ESM i always use that; basically never process.cwd

from import-meta-resolve.

fabiospampinato avatar fabiospampinato commented on July 22, 2024

@wooorm yeah but the REPL is a weird environment:

Screen Shot 2023-12-12 at 18 37 36

Anyway, closing this to keep things tidy. Worth thinking about special-casing what happens if the input path is a folder for convenience, either by throwing with a more specific reason or by doing something else, imo.


process.cwd() is needed in situations where for example you need to load some plugins, like you do prettier --plugin whatever, and that whatever plugin should be loaded from the process.cwd() basically.

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.