diff options
Diffstat (limited to 'src/resolver/resolver.zig')
-rw-r--r-- | src/resolver/resolver.zig | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 7dc07a5b1..0c97ea6c8 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -827,6 +827,20 @@ pub fn NewResolver(cache_files: bool) type { unreachable; } + const node_module_root_string = std.fs.path.sep_str ++ "node_modules" ++ std.fs.path.sep_str; + + pub fn rootNodeModulePackageJSON( + r: *ThisResolver, + result: *const Result, + ) ?*const PackageJSON { + const absolute = result.path_pair.primary.text; + var end = strings.lastIndexOf(absolute, node_module_root_string) orelse return null; + end += node_module_root_string.len; + end += strings.indexOfChar(absolute[end..], std.fs.path.sep) orelse return null; + + const dir_info = (r.dirInfoCached(absolute[0 .. end + 1]) catch null) orelse return null; + return dir_info.package_json; + } pub fn loadNodeModules(r: *ThisResolver, import_path: string, kind: ast.ImportKind, _dir_info: *DirInfo) ?MatchResult { var res = _loadNodeModules(r, import_path, kind, _dir_info) orelse return null; |