Skip to content
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

Some feedback #17

Closed
jasnell opened this issue Mar 16, 2018 · 7 comments
Closed

Some feedback #17

jasnell opened this issue Mar 16, 2018 · 7 comments

Comments

@jasnell
Copy link

jasnell commented Mar 16, 2018

First off great to see explorations on this... some feedback.

Consider the following case...

{
  "path_prefix": "/node_modules",
  "packages": {
    "index.js": { "main": "src/index.js" },
  }
}

In an application that also has an index.js at it's root. What does import * from 'index.js' load? That is, how does this deal with naming collisions?

There's a danger here in recreating the hell that is Java classpaths.

Another approach to this could be to take a more generic http/http2 centric approach and allow an origin to declare client-side aliases for various resources. These would amount to a client side 302 or 303 response.

For instance:

HTTP/1.1 200 OK
Link: </node_modules/lodash.js>; rel="alias"; anchor="lodash"
Content-Type: application-js

import * from "lodash"
@justinfagnani
Copy link
Collaborator

Thanks!

I'm unsure why would you define a package named "index.js" and import as "index.js", why not just do:

import * from './src/index.js';

Which skips the package name map altogether.

Can you further describe why you wanted to define a file as a package?

@matthewp
Copy link

import * from 'index.js' should always load your index.js "package", because it's a bare module specifiers and bare specifiers are always looked up from the packagemap.

@ljharb
Copy link

ljharb commented Mar 16, 2018

It’d be for the same reasons people put symlinks in their node_modules or use a babel transform or webpack alias for the package root; but since the package map would only apply to bare imports - ie, only things that aren’t prefixed with a dot or protocol or slash, iirc - i don’t think there’d be any collision (as said here)

@matthewp
Copy link

matthewp commented Mar 16, 2018

@justinfagnani This is actually going to be /node_modules/index.js/src/index.js. I think @jasnell is bringing this up as a point because there would possibly be a collision if bare specifiers defaulted to normal URL rules.

Once #6 is complete hopefully that will clarify what happens in the case that a bare specifier doesn't match anything in the packagemap. My hope is that will error like it does today.

@justinfagnani
Copy link
Collaborator

Once #6 is complete hopefully that will clarify what happens in the case that a bare specifier doesn't match anything in the packagemap. My hope is that will error like it does today.

Oh definitely, that will throw.

@jasnell
Copy link
Author

jasnell commented Mar 16, 2018

@matthewp ... yes, that's it exactly. The example was a bit off because I threw it together quickly but I'm glad the point came across.

@domenic
Copy link
Collaborator

domenic commented Nov 2, 2018

The proposal has changed a lot, so let me close this. In the newest iteration, it's intentionally in-scope to allow remapping of URLs like ./src/index.js, as well as bare specifiers like index.js.

@domenic domenic closed this as completed Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants