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

How would loader hooks/extensions/plugins leverage this? #11

Open
jkrems opened this issue Nov 7, 2018 · 5 comments
Open

How would loader hooks/extensions/plugins leverage this? #11

jkrems opened this issue Nov 7, 2018 · 5 comments

Comments

@jkrems
Copy link
Owner

jkrems commented Nov 7, 2018

If I'm writing a custom resolution algorithm, will there be a way to still leverage this behavior? Let's say I resolve to a package mapped to non-file: URLs. How do I still allow that package to specify exports?

@bmeck
Copy link

bmeck commented Nov 8, 2018

also of note,

if using import "foo/bar"; from main.mjs what is passed to loaders?

{specifier: "foo/bar", referrer: refTo("main.mjs")} would require the loader to lookup foo/package.json to find out what foo/bar is pointing to if it wants to know the actual file location. However, foo/package.json could have been overridden it seems?

@jkrems
Copy link
Owner Author

jkrems commented Nov 8, 2018

  1. We should track that /package.json is blacklisted at the very least. I don't think I would want to open that particular can of worms.
  2. Thanks for those additional questions! Also interesting in the context of arbitrary resource loading - who and when and how does load package.json and provides this data.

@GeoffreyBooth
Copy link
Collaborator

Currently import statements only import .mjs files, so importing package.json isn’t possible; but we might as well blacklist it and package-lock.json I suppose, or maybe wait until someone proposes allowing import statements of JSON to address it then.

So I guess this theoretical loader does its work before Node tries to resolve these references, so Node doesn’t know the file paths to pass to the loader. But Node could perhaps load package.json and pass its contents to any loaders, to avoid double (or more) lookups of package.json from the file system.

@jkrems
Copy link
Owner Author

jkrems commented Nov 9, 2018

@GeoffreyBooth The issue would be redirecting the package.json. E.g.:

{
  "exports": {
    "/package.json": "./run-random-code-to-generate-data.mjs"
  }
}

@jkrems
Copy link
Owner Author

jkrems commented Nov 9, 2018

Also, for additional context: The import-map proposal goes beyond ESM import but is introducing a context-sensitive import: URL scheme that may be used for resource loading in general. It stands to reason that the meta data would be loaded via the same resource system that would also provide the package contents. This is all very forward/future looking at this point.

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

3 participants