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
javascript: Support Node.js subpath imports #18934
Conversation
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.
Thanks!
@@ -110,8 +129,10 @@ async def infer_js_source_dependencies( | |||
owning_targets = await Get(Targets, Addresses(owners)) | |||
|
|||
non_path_string_bases = FrozenOrderedSet( | |||
os.path.basename(non_path_string) for non_path_string in import_strings - path_strings | |||
non_path_string.split(os.path.sep, 1)[0] |
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.
Nit: For split(.., 1)
, partition
can be a little bit cleaner: https://docs.python.org/3/library/stdtypes.html#str.partition
|
||
@staticmethod | ||
def _to_import_pattern(string: str) -> re.Pattern[str]: | ||
return re.compile(r"^" + re.escape(string).replace(r"\*", "(.*)")) |
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.
Are these supposed to match files recursively, or only within a directory? If the latter, you might want to use ([^/]*)
?
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.
The '*' token is a string replacement token, not a glob. So I think the answer is the former statement is correct.
See https://nodejs.org/api/packages.html#subpath-patterns, specifically this bit
* maps expose nested subpaths as it is a string replacement syntax only.
b857162
to
386bc38
Compare
Adds support for the inference impl to inspect
package.json#imports
, and backwards map this object to find dependencies known by pants.Relevant part of Node.js docs: https://nodejs.org/api/packages.html#subpath-imports.