aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-05-27 00:40:47 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-05-27 00:40:47 -0700
commit8036244eb23f51521e330fce1fe449c2330b1292 (patch)
treea24599a9abe62ee4db6cd01b8fabcd7b82c6cd5b /src
parent6e46883ca7b901d56e4bbdb24fa900bbdb732379 (diff)
downloadbun-8036244eb23f51521e330fce1fe449c2330b1292.tar.gz
bun-8036244eb23f51521e330fce1fe449c2330b1292.tar.zst
bun-8036244eb23f51521e330fce1fe449c2330b1292.zip
fuckin with absolute paths
Former-commit-id: 453cfa5689a97b2167015d8f5b6940d11f895aa3
Diffstat (limited to 'src')
-rw-r--r--src/fs.zig70
-rw-r--r--src/global.zig9
-rw-r--r--src/resolver/resolve_path.zig166
-rw-r--r--src/resolver/resolver.zig36
4 files changed, 214 insertions, 67 deletions
diff --git a/src/fs.zig b/src/fs.zig
index fb0e2c3ce..32961d171 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -246,12 +246,20 @@ pub const FileSystem = struct {
// }
pub fn normalize(f: *@This(), str: string) string {
- return @call(.{ .modifier = .always_inline }, path_handler.normalizeAndJoin, .{ f.top_level_dir, .auto, str });
+ return @call(.{ .modifier = .always_inline }, path_handler.normalizeString, .{ str, true, .auto });
}
pub fn join(f: *@This(), parts: anytype) string {
- return @call(.{ .modifier = .always_inline }, path_handler.normalizeAndJoinString, .{
- f.top_level_dir,
+ return @call(.{ .modifier = .always_inline }, path_handler.joinStringBuf, .{
+ &join_buf,
+ parts,
+ .auto,
+ });
+ }
+
+ pub fn joinBuf(f: *@This(), parts: anytype, buf: []u8) string {
+ return @call(.{ .modifier = .always_inline }, path_handler.joinStringBuf, .{
+ buf,
parts,
.auto,
});
@@ -279,6 +287,13 @@ pub const FileSystem = struct {
});
}
+ pub fn relativeFrom(f: *@This(), from: string) string {
+ return @call(.{ .modifier = .always_inline }, path_handler.relative, .{
+ from,
+ f.top_level_dir,
+ });
+ }
+
pub fn relativeToAlloc(f: *@This(), allocator: *std.mem.Allocator, to: string) string {
return @call(.{ .modifier = .always_inline }, path_handler.relativeAlloc, .{
allocator,
@@ -287,6 +302,27 @@ pub const FileSystem = struct {
});
}
+ pub fn absAlloc(f: *@This(), allocator: *std.mem.Allocator, parts: anytype) !string {
+ const joined = path_handler.joinAbsString(
+ f.top_level_dir,
+ parts,
+ .auto,
+ );
+ return try allocator.dupe(u8, joined);
+ }
+
+ pub fn abs(f: *@This(), parts: anytype) string {
+ return path_handler.joinAbsString(
+ f.top_level_dir,
+ parts,
+ .auto,
+ );
+ }
+
+ pub fn absBuf(f: *@This(), parts: anytype, buf: []u8) string {
+ return path_handler.joinAbsStringBuf(f.top_level_dir, buf, parts, .auto);
+ }
+
pub fn joinAlloc(f: *@This(), allocator: *std.mem.Allocator, parts: anytype) !string {
const joined = f.join(parts);
return try allocator.dupe(u8, joined);
@@ -315,12 +351,30 @@ pub const FileSystem = struct {
watcher_mutex: Mutex = Mutex.init(),
cwd: string,
parent_fs: *FileSystem = undefined,
+ file_limit: usize = 32,
+ file_quota: usize = 32,
+
+ // Always try to max out how many files we can keep open
+ pub fn adjustUlimit() usize {
+ var limit = std.os.getrlimit(.NOFILE) catch return 32;
+ if (limit.cur < limit.max) {
+ var new_limit = std.mem.zeroes(std.os.rlimit);
+ new_limit.cur = limit.max;
+ new_limit.max = limit.max;
+ std.os.setrlimit(.NOFILE, new_limit) catch return limit.cur;
+ return new_limit.cur;
+ }
+ return limit.cur;
+ }
pub fn init(allocator: *std.mem.Allocator, cwd: string, enable_watcher: bool) RealFS {
+ const file_limit = adjustUlimit();
return RealFS{
.entries = EntriesOption.Map.init(allocator),
.allocator = allocator,
.cwd = cwd,
+ .file_limit = file_limit,
+ .file_quota = file_limit,
.limiter = Limiter.init(allocator),
.watcher = if (enable_watcher) std.StringHashMap(WatchData).init(allocator) else null,
};
@@ -624,7 +678,7 @@ pub const FileSystem = struct {
pub fn kind(fs: *RealFS, _dir: string, base: string) !Entry.Cache {
var dir = _dir;
var combo = [2]string{ dir, base };
- var entry_path = path_handler.normalizeAndJoinString(fs.cwd, &combo, .auto);
+ var entry_path = path_handler.joinAbsString(fs.cwd, &combo, .auto);
fs.limiter.before();
defer fs.limiter.after();
@@ -651,7 +705,7 @@ pub const FileSystem = struct {
combo[0] = dir;
combo[1] = link;
- link = path_handler.normalizeAndJoinStringBuf(fs.cwd, out_slice, &combo, .auto);
+ link = path_handler.joinAbsStringBuf(fs.cwd, out_slice, &combo, .auto);
}
// TODO: do we need to clean the path?
symlink = link;
@@ -748,6 +802,7 @@ pub const PathName = struct {
var base = path;
var ext = path;
var dir = path;
+ var is_absolute = true;
var _i = strings.lastIndexOfChar(path, '/');
while (_i) |i| {
@@ -755,6 +810,7 @@ pub const PathName = struct {
if (i + 1 != path.len) {
base = path[i + 1 ..];
dir = path[0..i];
+ is_absolute = false;
break;
}
@@ -771,6 +827,10 @@ pub const PathName = struct {
base = base[0..dot];
}
+ if (is_absolute) {
+ dir = &([_]u8{});
+ }
+
return PathName{
.dir = dir,
.base = base,
diff --git a/src/global.zig b/src/global.zig
index 2d38cbf79..81263e658 100644
--- a/src/global.zig
+++ b/src/global.zig
@@ -22,8 +22,13 @@ pub const isWindows = std.Target.current.os.tag == .windows;
pub const FeatureFlags = struct {
pub const strong_etags_for_built_files = true;
pub const keep_alive = true;
+
+ // it just doesn't work well.
pub const use_std_path_relative = false;
+ pub const use_std_path_join = false;
+
pub const print_ast = false;
+ pub const disable_printing_null = false;
};
pub const enableTracing = true;
@@ -62,6 +67,10 @@ pub const Output = struct {
return source.error_stream.writer();
}
+ pub fn writer() @typeInfo(@TypeOf(Source.StreamType.writer)).Fn.return_type.? {
+ return source.stream.writer();
+ }
+
pub fn printErrorable(comptime fmt: string, args: anytype) !void {
if (isWasm) {
try source.stream.seekTo(0);
diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig
index f56ed55c8..d5e56b418 100644
--- a/src/resolver/resolve_path.zig
+++ b/src/resolver/resolve_path.zig
@@ -139,7 +139,7 @@ pub fn longestCommonPathGeneric(strings: []const []const u8, comptime separator:
// To detect /app/public is actually a folder, we do one more loop through the strings
// and say, "do one of you have a path separator after what we thought was the end?"
for (strings) |str| {
- if (str.len > index) {
+ if (str.len > index + 1) {
if (@call(.{ .modifier = .always_inline }, isPathSeparator, .{str[index]})) {
return str[0 .. index + 2];
}
@@ -572,25 +572,25 @@ pub fn normalizeStringAlloc(allocator: *std.mem.Allocator, str: []const u8, comp
return try allocator.dupe(u8, normalizeString(str, allow_above_root, _platform));
}
-pub fn normalizeAndJoin2(_cwd: []const u8, comptime _platform: Platform, part: anytype, part2: anytype) []const u8 {
+pub fn joinAbs2(_cwd: []const u8, comptime _platform: Platform, part: anytype, part2: anytype) []const u8 {
const parts = [_][]const u8{ part, part2 };
- const slice = normalizeAndJoinString(_cwd, &parts, _platform);
+ const slice = joinAbsString(_cwd, &parts, _platform);
return slice;
}
-pub fn normalizeAndJoin(_cwd: []const u8, comptime _platform: Platform, part: anytype) []const u8 {
+pub fn joinAbs(_cwd: []const u8, comptime _platform: Platform, part: anytype) []const u8 {
const parts = [_][]const u8{
part,
};
- const slice = normalizeAndJoinString(_cwd, &parts, _platform);
+ const slice = joinAbsString(_cwd, &parts, _platform);
return slice;
}
// Convert parts of potentially invalid file paths into a single valid filpeath
// without querying the filesystem
// This is the equivalent of
-pub fn normalizeAndJoinString(_cwd: []const u8, parts: anytype, comptime _platform: Platform) []const u8 {
- return normalizeAndJoinStringBuf(
+pub fn joinAbsString(_cwd: []const u8, parts: anytype, comptime _platform: Platform) []const u8 {
+ return joinAbsStringBuf(
_cwd,
&parser_join_input_buffer,
parts,
@@ -598,7 +598,60 @@ pub fn normalizeAndJoinString(_cwd: []const u8, parts: anytype, comptime _platfo
);
}
-pub fn normalizeAndJoinStringBuf(_cwd: []const u8, buf: []u8, parts: anytype, comptime _platform: Platform) []const u8 {
+pub fn joinStringBuf(buf: []u8, _parts: anytype, comptime _platform: Platform) []const u8 {
+ if (FeatureFlags.use_std_path_join) {
+ var alloc = std.heap.FixedBufferAllocator.init(buf);
+ return std.fs.path.join(&alloc.allocator, _parts) catch unreachable;
+ }
+
+ if (_parts.len == 0) {
+ return _cwd;
+ }
+
+ var parts = _parts;
+
+ var written: usize = 0;
+ const platform = comptime _platform.resolve();
+
+ for (_parts) |part| {
+ if (part.len == 0 or (part.len == 1 and part[1] == '.')) {
+ continue;
+ }
+
+ if (!platform.isSeparator(part[part.len - 1])) {
+ parser_join_input_buffer[written] = platform.separator();
+ written += 1;
+ }
+
+ std.mem.copy(
+ u8,
+ parser_join_input_buffer[written..],
+ part,
+ );
+ written += part.len;
+ }
+
+ // Preserve leading separator
+ if (_parts[0][0] == _platform.separator()) {
+ const out = switch (platform) {
+ .loose => normalizeStringLooseBuf(parser_join_input_buffer[0..written], buf[1..], false, false),
+ .windows => normalizeStringWindows(parser_join_input_buffer[0..written], buf[1..], false, false),
+ else => normalizeStringPosixBuf(parser_join_input_buffer[0..written], buf[1..], false, false),
+ };
+ buf[0] = _platform.separator();
+
+ return buf[0 .. out.len + 1];
+ } else {
+ return switch (platform) {
+ .loose => normalizeStringLooseBuf(parser_join_input_buffer[0..written], buf[0..], false, false),
+ .windows => normalizeStringWindows(parser_join_input_buffer[0..written], buf[0..], false, false),
+ else => normalizeStringPosixBuf(parser_join_input_buffer[0..written], buf[0..], false, false),
+ };
+ }
+}
+
+pub fn joinAbsStringBuf(_cwd: []const u8, buf: []u8, _parts: anytype, comptime _platform: Platform) []const u8 {
+ var parts: []const []const u8 = _parts;
if (parts.len == 0) {
return _cwd;
}
@@ -615,22 +668,41 @@ pub fn normalizeAndJoinStringBuf(_cwd: []const u8, buf: []u8, parts: anytype, co
// Windows leading separators can be a lot of things...
// So we need to do this instead of just checking the first char.
var leading_separator: []const u8 = "";
- if (_platform.leadingSeparatorIndex(parts[0])) |leading_separator_i| {
- leading_separator = parts[0][0 .. leading_separator_i + 1];
- ignore_cwd = true;
- }
- if (!ignore_cwd) {
+ var start_part: i32 = -1;
+ for (parts) |part, i| {
+ if (part.len > 0) {
+ if (_platform.leadingSeparatorIndex(parts[i])) |leading_separator_i| {
+ leading_separator = parts[i][0 .. leading_separator_i + 1];
+ start_part = @intCast(i32, i);
+ }
+ }
+ }
+ var start: []const u8 = "";
+
+ // Handle joining absolute strings
+ // Any string which starts with a leading separator is considered absolute
+ if (start_part > -1) {
+ const start_part_i = @intCast(usize, start_part);
+ start = parts[start_part_i];
+ if (parts.len > start_part_i + 1) {
+ parts = parts[start_part_i + 1 ..];
+ } else {
+ parts = &([_][]const u8{});
+ }
+ } else {
leading_separator = cwd[0 .. 1 + (_platform.leadingSeparatorIndex(_cwd) orelse unreachable)]; // cwd must be absolute
- cwd = _cwd[leading_separator.len..cwd.len];
- out = cwd.len;
- std.debug.assert(out < buf.len);
- std.mem.copy(u8, buf[0..out], cwd);
+ start = _cwd;
}
+ out = start.len;
+ std.debug.assert(out < buf.len);
+ std.mem.copy(u8, buf[0..out], start);
+
for (parts) |part, i| {
- // This never returns leading separators.
- var normalized_part = normalizeString(part, true, _platform);
+ // Do not normalize here
+ // It will break stuff!
+ var normalized_part = part;
if (normalized_part.len == 0) {
continue;
}
@@ -645,10 +717,10 @@ pub fn normalizeAndJoinStringBuf(_cwd: []const u8, buf: []u8, parts: anytype, co
out += 1;
- const start = out;
+ const offset = out;
out += normalized_part.len;
std.debug.assert(out < buf.len);
- std.mem.copy(u8, buf[start..out], normalized_part);
+ std.mem.copy(u8, buf[offset..out], normalized_part);
}
// One last normalization, to remove any ../ added
@@ -760,7 +832,7 @@ pub fn normalizeStringLooseBuf(str: []const u8, buf: []u8, comptime allow_above_
);
}
-test "normalizeAndJoinStringPosix" {
+test "joinAbsStringPosix" {
var t = tester.Tester.t(std.heap.c_allocator);
defer t.report(@src());
const string = []const u8;
@@ -768,45 +840,51 @@ test "normalizeAndJoinStringPosix" {
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/bar/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "bar", "file.js" }, .posix),
+ joinAbsString(cwd, [_]string{ "foo", "bar", "file.js" }, .posix),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "bar", "../file.js" }, .posix),
+ joinAbsString(cwd, [_]string{ "foo", "bar", "../file.js" }, .posix),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "./bar", "../file.js" }, .posix),
+ joinAbsString(cwd, [_]string{ "foo", "./bar", "../file.js" }, .posix),
+ @src(),
+ );
+
+ _ = t.expect(
+ "/Users/jarredsumner/Code/app/foo/file.js",
+ joinAbsString(cwd, [_]string{ "", "../../file.js" }, .posix),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "././././foo", "././././bar././././", "../file.js" }, .posix),
+ joinAbsString(cwd, [_]string{ "././././foo", "././././bar././././", "../file.js" }, .posix),
@src(),
);
_ = t.expect(
"/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .posix),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .posix),
@src(),
);
_ = t.expect(
"/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .posix),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .posix),
@src(),
);
_ = t.expect(
"/Code/app/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .posix),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .posix),
@src(),
);
}
-test "normalizeAndJoinStringLoose" {
+test "joinAbsStringLoose" {
var t = tester.Tester.t(std.heap.c_allocator);
defer t.report(@src());
const string = []const u8;
@@ -814,81 +892,81 @@ test "normalizeAndJoinStringLoose" {
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/bar/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "bar", "file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "foo", "bar", "file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "bar", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "foo", "bar", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "./bar", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "foo", "./bar", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "././././foo", "././././bar././././", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "././././foo", "././././bar././././", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Code/app/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/bar/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "bar", "file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "foo", "bar", "file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "bar", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "foo", "bar", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "foo", "./bar", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "foo", "./bar", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Users/jarredsumner/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ ".\\.\\.\\.\\foo", "././././bar././././", "..\\file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ ".\\.\\.\\.\\foo", "././././bar././././", "..\\file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", "././././bar././././", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Code/app/foo/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", ".", "././././bar././././", ".", "../file.js" }, .loose),
@src(),
);
_ = t.expect(
"/Code/app/file.js",
- normalizeAndJoinString(cwd, [_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .loose),
+ joinAbsString(cwd, [_]string{ "/Code/app", "././././foo", "..", "././././bar././././", ".", "../file.js" }, .loose),
@src(),
);
}
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index 9096f99df..b28a28e4b 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -466,7 +466,7 @@ pub const Resolver = struct {
if (check_relative) {
const parts = [_]string{ source_dir, import_path };
- const abs_path = r.fs.joinBuf(&parts, &relative_abs_path_buf);
+ const abs_path = r.fs.absBuf(&parts, &relative_abs_path_buf);
if (r.opts.external.abs_paths.count() > 0 and r.opts.external.abs_paths.exists(abs_path)) {
// If the string literal in the source text is an absolute path and has
@@ -478,7 +478,7 @@ pub const Resolver = struct {
}
return Result{
- .path_pair = .{ .primary = Path.init(abs_path) },
+ .path_pair = .{ .primary = Path.init(r.fs.filename_store.append(abs_path) catch unreachable) },
.is_external = true,
};
}
@@ -493,7 +493,7 @@ pub const Resolver = struct {
if (r.checkBrowserMap(pkg, rel_path)) |remap| {
// Is the path disabled?
if (remap.len == 0) {
- var _path = Path.init(abs_path);
+ var _path = Path.init(r.fs.filename_store.append(abs_path) catch unreachable);
_path.is_disabled = true;
return Result{
.path_pair = PathPair{
@@ -661,7 +661,7 @@ pub const Resolver = struct {
if (tsconfig.hasBaseURL()) {
const base = tsconfig.base_url;
const paths = [_]string{ base, import_path };
- const abs = r.fs.joinBuf(&paths, &load_as_file_or_directory_via_tsconfig_base_path);
+ const abs = r.fs.absBuf(&paths, &load_as_file_or_directory_via_tsconfig_base_path);
if (r.loadAsFileOrDirectory(abs, kind)) |res| {
return res;
@@ -676,7 +676,7 @@ pub const Resolver = struct {
// don't ever want to search for "node_modules/node_modules"
if (dir_info.has_node_modules) {
var _paths = [_]string{ dir_info.abs_path, "node_modules", import_path };
- const abs_path = r.fs.join(&_paths);
+ const abs_path = r.fs.abs(&_paths);
if (r.debug_logs) |*debug| {
debug.addNoteFmt("Checking for a package in the directory \"{s}\"", .{abs_path}) catch {};
}
@@ -704,7 +704,7 @@ pub const Resolver = struct {
return r.loadNodeModules(import_path, kind, source_dir_info);
} else {
const paths = [_]string{ source_dir_info.abs_path, import_path };
- var resolved = r.fs.joinBuf(&paths, &resolve_without_remapping_buf);
+ var resolved = r.fs.absBuf(&paths, &resolve_without_remapping_buf);
return r.loadAsFileOrDirectory(resolved, kind);
}
}
@@ -727,7 +727,7 @@ pub const Resolver = struct {
// // // Skip "node_modules" folders
// // if (!strings.eql(std.fs.path.basename(current), "node_modules")) {
// // var paths1 = [_]string{ current, "node_modules", extends };
- // // var join1 = r.fs.joinAlloc(ctx.r.allocator, &paths1) catch unreachable;
+ // // var join1 = r.fs.absAlloc(ctx.r.allocator, &paths1) catch unreachable;
// // const res = ctx.r.parseTSConfig(join1, ctx.visited) catch |err| {
// // if (err == error.ENOENT) {
// // continue;
@@ -760,14 +760,14 @@ pub const Resolver = struct {
// this might leak
if (!std.fs.path.isAbsolute(result.base_url)) {
const paths = [_]string{ file_dir, result.base_url };
- result.base_url = r.fs.filename_store.append(r.fs.joinBuf(&paths, &tsconfig_base_url_buf)) catch unreachable;
+ result.base_url = r.fs.filename_store.append(r.fs.absBuf(&paths, &tsconfig_base_url_buf)) catch unreachable;
}
}
if (result.paths.count() > 0 and (result.base_url_for_paths.len == 0 or !std.fs.path.isAbsolute(result.base_url_for_paths))) {
// this might leak
const paths = [_]string{ file_dir, result.base_url };
- result.base_url_for_paths = r.fs.filename_store.append(r.fs.joinBuf(&paths, &tsconfig_base_url_buf)) catch unreachable;
+ result.base_url_for_paths = r.fs.filename_store.append(r.fs.absBuf(&paths, &tsconfig_base_url_buf)) catch unreachable;
}
return result;
@@ -1035,7 +1035,7 @@ pub const Resolver = struct {
if (!std.fs.path.isAbsolute(absolute_original_path)) {
const parts = [_]string{ abs_base_url, original_path };
- absolute_original_path = r.fs.joinAlloc(r.allocator, &parts) catch unreachable;
+ absolute_original_path = r.fs.absAlloc(r.allocator, &parts) catch unreachable;
was_alloc = true;
}
@@ -1119,7 +1119,7 @@ pub const Resolver = struct {
var did_allocate = false;
if (!std.fs.path.isAbsolute(region)) {
var paths = [_]string{ abs_base_url, original_path };
- absolute_original_path = r.fs.joinAlloc(r.allocator, &paths) catch unreachable;
+ absolute_original_path = r.fs.absAlloc(r.allocator, &paths) catch unreachable;
did_allocate = true;
} else {
absolute_original_path = std.mem.dupe(r.allocator, u8, region) catch unreachable;
@@ -1214,7 +1214,7 @@ pub const Resolver = struct {
// Is the path disabled?
if (remap.len == 0) {
const paths = [_]string{ path, field_rel_path };
- const new_path = r.fs.joinAlloc(r.allocator, &paths) catch unreachable;
+ const new_path = r.fs.absAlloc(r.allocator, &paths) catch unreachable;
var _path = Path.init(new_path);
_path.is_disabled = true;
return MatchResult{
@@ -1229,7 +1229,7 @@ pub const Resolver = struct {
}
}
const _paths = [_]string{ field_rel_path, path };
- const field_abs_path = r.fs.joinAlloc(r.allocator, &_paths) catch unreachable;
+ const field_abs_path = r.fs.absAlloc(r.allocator, &_paths) catch unreachable;
const field_dir_info = (r.dirInfoCached(field_abs_path) catch null) orelse {
r.allocator.free(field_abs_path);
@@ -1254,7 +1254,7 @@ pub const Resolver = struct {
if (entries.get(base)) |lookup| {
if (lookup.entry.kind(rfs) == .file) {
const parts = [_]string{ path, base };
- const out_buf = r.fs.joinAlloc(r.allocator, &parts) catch unreachable;
+ const out_buf = r.fs.absAlloc(r.allocator, &parts) catch unreachable;
if (r.debug_logs) |*debug| {
debug.addNoteFmt("Found file: \"{s}\"", .{out_buf}) catch unreachable;
}
@@ -1281,7 +1281,7 @@ pub const Resolver = struct {
// This doesn't really make sense to me.
if (remap.len == 0) {
const paths = [_]string{ path, field_rel_path };
- const new_path = r.fs.joinAlloc(r.allocator, &paths) catch unreachable;
+ const new_path = r.fs.absAlloc(r.allocator, &paths) catch unreachable;
var _path = Path.init(new_path);
_path.is_disabled = true;
return MatchResult{
@@ -1292,7 +1292,7 @@ pub const Resolver = struct {
}
const new_paths = [_]string{ path, remap };
- const remapped_abs = r.fs.joinAlloc(r.allocator, &new_paths) catch unreachable;
+ const remapped_abs = r.fs.absAlloc(r.allocator, &new_paths) catch unreachable;
// Is this a file
if (r.loadAsFile(remapped_abs, extension_order)) |file_result| {
@@ -1646,7 +1646,7 @@ pub const Resolver = struct {
if (entry.kind(rfs) == .file) {
const parts = [_]string{ path, "tsconfig.json" };
- tsconfig_path = r.fs.joinBuf(&parts, &dir_info_uncached_filename_buf);
+ tsconfig_path = r.fs.absBuf(&parts, &dir_info_uncached_filename_buf);
}
}
if (tsconfig_path == null) {
@@ -1654,7 +1654,7 @@ pub const Resolver = struct {
const entry = lookup.entry;
if (entry.kind(rfs) == .file) {
const parts = [_]string{ path, "jsconfig.json" };
- tsconfig_path = r.fs.joinBuf(&parts, &dir_info_uncached_filename_buf);
+ tsconfig_path = r.fs.absBuf(&parts, &dir_info_uncached_filename_buf);
}
}
}