-
Notifications
You must be signed in to change notification settings - Fork 208
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
simplify package path resolution #8186
base: master
Are you sure you want to change the base?
Changes from 2 commits
346d665
e08e39a
a54c366
49b01fb
859ae99
2940517
f467a51
e0454b3
e011f51
ba20dba
67f2cf1
a62b8a8
9f9f7c1
edb3e5f
2b709ef
979f444
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,14 @@ import { resolve } from 'import-meta-resolve'; | |
|
||
/** | ||
* @param {string} specifier | ||
* @param {string} base | ||
* @returns {string} file system absolute path of the package resource specifier | ||
*/ | ||
export const pkgAbsPath = specifier => { | ||
const href = resolve(specifier, import.meta.url); | ||
export const resolvePath = (specifier, base) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
const href = resolve(specifier, base); | ||
return url.fileURLToPath(href); | ||
}; | ||
|
||
export const makeResolvePath = base => { | ||
return specifier => resolvePath(specifier, base); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, this is a good compromise. @warner I would encourage us to in general migrate as much of our API surface to treating file URLs as first-class, starting with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should not be. Hiding the mechanism of resolution obscures the limitations of its use. I strongly prefer inlining
url.filePathToURL(resolve(specifier, import.meta.url))
since this works anywhere without qualification.If we kept this function, we would need to express the qualifications: it can only be reliably used for absolute module specifiers like
@foo/bar
and not for relative module specifiers like./foo.js
within this package. The resolution of an absolute specifier is not guaranteed to be consistent between packages, differing version constraints between packages, and varying node_modules layout algorithms.The reason for these limitations is that it uses its own
import.meta.url
instead of receiving the referrer specifier as a parameter.That is to say, if present, this function should not be exported to other packages, which is antithetical to exporting it from
tools.js
and its usage throughout this change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This I hadn't considered.
What if this function took
parent
the wayimport-meta-resolve
does?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this function accepted the
import.meta.url
from the caller, I would be converted from a “hard no” to a “soft no”, on the grounds that I’d prefer transparency at the call site.url.fileURLToPath(resolve(specifier, import.meta.url))
is very clear and not very long. Just removing the await is an improvement.