-
Notifications
You must be signed in to change notification settings - Fork 43
Enabling import meta resolve by default? #550
Comments
Because Domenic has made a similar proposal for the browser with roughly the same API, but as a synchronous variant - whatwg/html#5572. The sync / async concern between browsers and Node.js is a tricky one to get agreement on, which is tricky without any open standards space to truly discuss this stuff. I've posted an issue to Deno to see if there is interest here - denoland/deno#7296. |
Also I do think it's a critical part of the implementation since |
I've added the meeting agenda label, let's try to discuss this further. |
I think we had previously discussed exposing this as Thoughts? |
One minor thing consideration there is conditional resolution. |
I do like the API being usable to determine either require or import personally. |
The major blocker to @bmeck do you mean via the distinction of To explain the benefits of Consider loading a template: const template = await (await fetch(await import.meta.resolve('pkg/template.html')).text(); It is possible for the build tool to use the const template = await (await fetch(import.meta.url + '../assets/template.html')) where assets are relocated by the build process based on their references. The other benefit is that this resolver pattern can be transferrable between runtimes, instead of needing some advanced "superResolve" library that can work cross-environment. |
I mean having 1 function that I can throw data into that handles all the basic resolutions I might be curious about. This is not in any way critical as if we have N functions I can just wrap them into a single function anyway. |
Removing from agenda for now. We can bring this up again if we want to revisit |
just ran into this again and the "hack" won't work anymore 😅 e.g. And I guess basically, no one will have an export map like "exports": {
"package.json": "./package.json"
} what I want to do is read the My idea is to resolve the package directory and then do a regular sooo is there any other way to resolve the package directory? strawman proposal const pkgPath = import.meta.resolvePackage('@foo/bar'); // <<<<------ new method?
const pkgJsonStream = await fs.promises.readFile(path.join(pkgPath, 'package.json'));
const pkgJson = JSON.parse(pkgJsonStream.toString());
const keys = Object.keys(pkgJson.exports);
for (let i = 0; i < keys.length; i += 1) {
const exportKey = keys[i];
const exportValue = pksJson.exports[i];
// add exportsKey to import map
// resolve dependency package? - e.g. check if it's also in the root or a sub node_modules folder
const dependency = mport.meta.resolvePackage('@foo/bar', exportValue);
// ... recursive go through dependency tree
} hmmm or would it better to "just" walk the node_modules folders myself 🤔 |
I ran into this issue where |
It’s not reasonable to ask users to use any experimental feature. By definition, experimental features could change or disappear at any time. This one in particular seems unlikely to ship in its current form, per whatwg/html#5572 (comment) |
same issue here, why was this closed? |
The
|
This is resolved by 20.6.0 whenever it ships. |
Thanks! |
When using esm there seems to be no way to resolve paths to a packages 🤔
In a commonjs project, I currently have this "gem" 😅
with
--experimental-import-meta-resolve
I can basically replaceresolvedNodePackagePath
withawait import.meta.resolve(...)
.However, as long as it's an experimental flag it is kind of a tough sell to users and additionally, it requires some trickery for
bins
😅So hence my question any chance this is going to be unflagged any time soon?
The text was updated successfully, but these errors were encountered: