mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 23:18:47 +00:00
Compare commits
1 Commits
ciro/fix-a
...
don/fix/pa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61d019c8e4 |
@@ -46,7 +46,7 @@ fn createImportRecord(this: *HTMLScanner, input_path: []const u8, kind: ImportKi
|
||||
} else input_path;
|
||||
|
||||
const record = ImportRecord{
|
||||
.path = fs.Path.init(try this.allocator.dupeZ(u8, path_to_use)),
|
||||
.path = fs.Path.initFile(try this.allocator.dupeZ(u8, path_to_use)),
|
||||
.kind = kind,
|
||||
.range = logger.Range.None,
|
||||
};
|
||||
|
||||
@@ -158,7 +158,7 @@ pub fn initPending(loader: Loader, pending: resolver.Result) OutputFile {
|
||||
pub fn initFile(file: std.fs.File, pathname: string, size: usize) OutputFile {
|
||||
return .{
|
||||
.loader = .file,
|
||||
.src_path = Fs.Path.init(pathname),
|
||||
.src_path = Fs.Path.initFile(pathname),
|
||||
.size = size,
|
||||
.value = .{ .copy = FileOperation.fromFile(file.handle, pathname) },
|
||||
};
|
||||
@@ -203,7 +203,7 @@ pub fn init(options: Options) OutputFile {
|
||||
return .{
|
||||
.loader = options.loader,
|
||||
.input_loader = options.input_loader,
|
||||
.src_path = Fs.Path.init(options.input_path),
|
||||
.src_path = Fs.Path.initFile(options.input_path),
|
||||
.dest_path = options.output_path,
|
||||
.size = options.size orelse switch (options.data) {
|
||||
.buffer => |buf| buf.data.len,
|
||||
|
||||
@@ -157,7 +157,7 @@ pub const ResolveMessage = struct {
|
||||
resolve_error.* = ResolveMessage{
|
||||
.msg = msg.clone(allocator) catch unreachable,
|
||||
.allocator = allocator,
|
||||
.referrer = Fs.Path.init(referrer),
|
||||
.referrer = Fs.Path.initFile(referrer),
|
||||
};
|
||||
return resolve_error.toJS(globalThis);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ pub const RuntimeTranspilerStore = struct {
|
||||
loader: bun.options.Loader,
|
||||
) *anyopaque {
|
||||
var job: *TranspilerJob = this.store.get();
|
||||
const owned_path = Fs.Path.init(bun.default_allocator.dupe(u8, path.text) catch unreachable);
|
||||
const owned_path = Fs.Path.initFile(bun.default_allocator.dupe(u8, path.text) catch unreachable);
|
||||
const promise = JSC.JSInternalPromise.create(globalObject);
|
||||
job.* = TranspilerJob{
|
||||
.non_threadsafe_input_specifier = input_specifier,
|
||||
@@ -617,7 +617,7 @@ pub const RuntimeTranspilerStore = struct {
|
||||
}
|
||||
|
||||
if (strings.hasPrefixComptime(import_record.path.text, "bun:")) {
|
||||
import_record.path = Fs.Path.init(import_record.path.text["bun:".len..]);
|
||||
import_record.path = Fs.Path.initFile(import_record.path.text["bun:".len..]);
|
||||
import_record.path.namespace = "bun";
|
||||
import_record.is_external_without_side_effects = true;
|
||||
|
||||
@@ -1071,7 +1071,7 @@ pub const ModuleLoader = struct {
|
||||
opts.promise_ptr.?.* = this_promise.asInternalPromise().?;
|
||||
const referrer = buf.append(opts.referrer);
|
||||
const specifier = buf.append(opts.specifier);
|
||||
const path = Fs.Path.init(buf.append(opts.path.text));
|
||||
const path = Fs.Path.initFile(buf.append(opts.path.text));
|
||||
|
||||
return AsyncModule{
|
||||
.parse_result = opts.parse_result,
|
||||
@@ -2554,7 +2554,7 @@ pub const ModuleLoader = struct {
|
||||
|
||||
var virtual_source = logger.Source.initPathString(specifier, source_code_slice.slice());
|
||||
var log = logger.Log.init(jsc_vm.allocator);
|
||||
const path = Fs.Path.init(specifier);
|
||||
const path = Fs.Path.initFile(specifier);
|
||||
|
||||
const loader = if (loader_ != ._none)
|
||||
options.Loader.fromAPI(loader_)
|
||||
|
||||
@@ -4752,10 +4752,10 @@ pub const Blob = struct {
|
||||
|
||||
pub fn getLoader(blob: *const Blob, jsc_vm: *VirtualMachine) ?bun.options.Loader {
|
||||
if (blob.getFileName()) |filename| {
|
||||
const current_path = bun.fs.Path.init(filename);
|
||||
const current_path = bun.fs.Path.initWithNamespace(filename, "blob");
|
||||
return current_path.loader(&jsc_vm.transpiler.options.loaders) orelse .tsx;
|
||||
} else if (blob.getMimeTypeOrContentType()) |mime_type| {
|
||||
return .fromMimeType(mime_type);
|
||||
return bun.options.Loader.fromMimeType(mime_type);
|
||||
} else {
|
||||
// Be maximally permissive.
|
||||
return .tsx;
|
||||
|
||||
@@ -100,6 +100,7 @@ const Analytics = @import("../analytics/analytics_thread.zig");
|
||||
const URL = @import("../url.zig").URL;
|
||||
const Linker = linker.Linker;
|
||||
const Resolver = _resolver.Resolver;
|
||||
const ResolverResult = _resolver.Result;
|
||||
const TOML = @import("../toml/toml_parser.zig").TOML;
|
||||
const EntryPoints = bun.transpiler.EntryPoints;
|
||||
const Dependency = js_ast.Dependency;
|
||||
@@ -2354,12 +2355,7 @@ pub const BundleV2 = struct {
|
||||
.success => |result| {
|
||||
var out_source_index: ?Index = null;
|
||||
if (!result.external) {
|
||||
var path = Fs.Path.init(result.path);
|
||||
if (result.namespace.len == 0 or strings.eqlComptime(result.namespace, "file")) {
|
||||
path.namespace = "file";
|
||||
} else {
|
||||
path.namespace = result.namespace;
|
||||
}
|
||||
var path = Fs.Path.initWithNamespace(result.path, result.namespace);
|
||||
|
||||
const existing = this.pathToSourceIndexMap(resolve.import_record.original_target).getOrPut(this.graph.allocator, path.hashKey()) catch unreachable;
|
||||
if (!existing.found_existing) {
|
||||
@@ -3031,7 +3027,7 @@ pub const BundleV2 = struct {
|
||||
}
|
||||
|
||||
if (strings.hasPrefixComptime(import_record.path.text, "bun:")) {
|
||||
import_record.path = Fs.Path.init(import_record.path.text["bun:".len..]);
|
||||
import_record.path = Fs.Path.initFile(import_record.path.text["bun:".len..]);
|
||||
import_record.path.namespace = "bun";
|
||||
import_record.source_index = Index.invalid;
|
||||
import_record.is_external_without_side_effects = true;
|
||||
@@ -3059,7 +3055,7 @@ pub const BundleV2 = struct {
|
||||
continue;
|
||||
}
|
||||
|
||||
const transpiler, const bake_graph: bake.Graph, const target =
|
||||
const transpiler: *Transpiler, const bake_graph: bake.Graph, const target =
|
||||
if (import_record.tag == .bake_resolve_to_ssr_graph)
|
||||
brk: {
|
||||
if (this.framework == null) {
|
||||
@@ -3098,7 +3094,7 @@ pub const BundleV2 = struct {
|
||||
};
|
||||
|
||||
var had_busted_dir_cache = false;
|
||||
var resolve_result = inner: while (true) break transpiler.resolver.resolveWithFramework(
|
||||
var resolve_result: ResolverResult = inner: while (true) break transpiler.resolver.resolveWithFramework(
|
||||
source_dir,
|
||||
import_record.path.text,
|
||||
import_record.kind,
|
||||
@@ -4561,7 +4557,7 @@ pub const ParseTask = struct {
|
||||
switch (file) {
|
||||
.code => |code| break :brk .{ .contents = code, .fd = bun.invalid_fd },
|
||||
.import => |path| {
|
||||
file_path.* = Fs.Path.init(path);
|
||||
file_path.* = Fs.Path.initFile(path);
|
||||
break :lookup_builtin;
|
||||
},
|
||||
}
|
||||
@@ -11099,7 +11095,7 @@ pub const LinkerContext = struct {
|
||||
continue;
|
||||
},
|
||||
};
|
||||
p.* = bun.fs.Path.init(DataURL.encodeStringAsShortestDataURL(allocator, "text/css", std.mem.trim(u8, print_result.code, " \n\r\t")));
|
||||
p.* = bun.fs.Path.initFile(DataURL.encodeStringAsShortestDataURL(allocator, "text/css", std.mem.trim(u8, print_result.code, " \n\r\t")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11684,7 +11680,7 @@ pub const LinkerContext = struct {
|
||||
cross_chunk_import_records.appendAssumeCapacity(
|
||||
.{
|
||||
.kind = import_record.import_kind,
|
||||
.path = Fs.Path.init(ctx.chunks[import_record.chunk_index].unique_key),
|
||||
.path = Fs.Path.initFile(ctx.chunks[import_record.chunk_index].unique_key),
|
||||
.range = Logger.Range.None,
|
||||
},
|
||||
);
|
||||
@@ -17787,7 +17783,7 @@ pub const AstBuilder = struct {
|
||||
pub fn addImportRecord(p: *AstBuilder, path: []const u8, kind: ImportKind) !u32 {
|
||||
const index = p.import_records.items.len;
|
||||
try p.import_records.append(p.allocator, .{
|
||||
.path = bun.fs.Path.init(path),
|
||||
.path = bun.fs.Path.initFile(path),
|
||||
.kind = kind,
|
||||
.range = .{},
|
||||
});
|
||||
|
||||
@@ -1408,7 +1408,7 @@ pub const BundlerAtRuleParser = struct {
|
||||
const import_record_index = this.import_records.len;
|
||||
import_rule.import_record_idx = import_record_index;
|
||||
this.import_records.push(this.allocator, ImportRecord{
|
||||
.path = bun.fs.Path.init(import_rule.url),
|
||||
.path = bun.fs.Path.initFile(import_rule.url),
|
||||
.kind = if (import_rule.supports != null) .at_conditional else .at,
|
||||
.range = bun.logger.Range{
|
||||
.loc = bun.logger.Loc{ .start = @intCast(start_position) },
|
||||
@@ -3420,7 +3420,7 @@ pub fn StyleSheet(comptime AtRule: type) type {
|
||||
const import_record_idx = new_import_records.len;
|
||||
import_rule.import_record_idx = import_record_idx;
|
||||
new_import_records.push(allocator, ImportRecord{
|
||||
.path = bun.fs.Path.init(import_rule.url),
|
||||
.path = bun.fs.Path.initFile(import_rule.url),
|
||||
.kind = if (import_rule.supports != null) .at_conditional else .at,
|
||||
.range = bun.logger.Range.None,
|
||||
}) catch bun.outOfMemory();
|
||||
@@ -3850,7 +3850,7 @@ pub const Parser = struct {
|
||||
if (this.import_records) |import_records| {
|
||||
const idx = import_records.len;
|
||||
import_records.push(this.allocator(), ImportRecord{
|
||||
.path = bun.fs.Path.init(url),
|
||||
.path = bun.fs.Path.initFile(url),
|
||||
.kind = kind,
|
||||
.range = bun.logger.Range{
|
||||
.loc = bun.logger.Loc{ .start = @intCast(start_position) },
|
||||
|
||||
@@ -1257,7 +1257,7 @@ pub fn NewBundler(
|
||||
const entry = try this.fs_reader.readFile(this.fs, url, 0, true, input_fd);
|
||||
return logger.Source.initFile(
|
||||
.{
|
||||
.path = Fs.Path.init(url),
|
||||
.path = Fs.Path.initFile(url),
|
||||
.contents = entry.contents,
|
||||
},
|
||||
this.allocator,
|
||||
|
||||
154
src/fs.zig
154
src/fs.zig
@@ -27,8 +27,6 @@ const WPathBuffer = bun.WPathBuffer;
|
||||
|
||||
pub const debug = Output.scoped(.fs, true);
|
||||
|
||||
// pub const FilesystemImplementation = @import("fs_impl.zig");
|
||||
|
||||
pub const Preallocate = struct {
|
||||
pub const Counts = struct {
|
||||
pub const dir_entry: usize = 2048;
|
||||
@@ -1186,9 +1184,9 @@ pub const FileSystem = struct {
|
||||
if (size == 0) {
|
||||
if (comptime use_shared_buffer) {
|
||||
shared_buffer.reset();
|
||||
return PathContentsPair{ .path = Path.init(path), .contents = shared_buffer.list.items };
|
||||
return PathContentsPair{ .path = Path.initWithNamespace(path), .contents = shared_buffer.list.items };
|
||||
} else {
|
||||
return PathContentsPair{ .path = Path.init(path), .contents = "" };
|
||||
return PathContentsPair{ .path = Path.initFile(path), .contents = "" };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1269,7 +1267,7 @@ pub const FileSystem = struct {
|
||||
}
|
||||
if (comptime Environment.isWindows) try file.seekTo(prev_file_pos.?);
|
||||
|
||||
return PathContentsPair{ .path = Path.init(path), .contents = file_contents };
|
||||
return PathContentsPair{ .path = Path.initFile(path), .contents = file_contents };
|
||||
}
|
||||
|
||||
break :brk buf[0..read_count];
|
||||
@@ -1292,7 +1290,7 @@ pub const FileSystem = struct {
|
||||
@memcpy(buf[0..initial_read.len], initial_read);
|
||||
|
||||
if (size == 0) {
|
||||
return PathContentsPair{ .path = Path.init(path), .contents = "" };
|
||||
return PathContentsPair{ .path = Path.initFile(path), .contents = "" };
|
||||
}
|
||||
|
||||
// stick a zero at the end
|
||||
@@ -1312,7 +1310,7 @@ pub const FileSystem = struct {
|
||||
}
|
||||
}
|
||||
|
||||
return PathContentsPair{ .path = Path.init(path), .contents = file_contents };
|
||||
return PathContentsPair{ .path = Path.initFile(path), .contents = file_contents };
|
||||
}
|
||||
|
||||
pub fn kindFromAbsolute(
|
||||
@@ -1695,7 +1693,7 @@ pub const Path = struct {
|
||||
/// for content hashes), this should contain forward slashes on Windows.
|
||||
pretty: string,
|
||||
/// The location of this resource. For the `file` namespace, this is
|
||||
/// an absolute path with native slashes.
|
||||
/// usually an absolute path with native slashes.
|
||||
text: string,
|
||||
namespace: string,
|
||||
// TODO(@paperdave): investigate removing or simplifying this property (it's 64 bytes)
|
||||
@@ -1703,6 +1701,66 @@ pub const Path = struct {
|
||||
is_disabled: bool = false,
|
||||
is_symlink: bool = false,
|
||||
|
||||
// files may use "file" or an empty string as their namespace
|
||||
const file = "";
|
||||
|
||||
pub const empty = Fs.Path.initFile("");
|
||||
|
||||
/// Create a new `Path` to the given url, path, etc.
|
||||
///
|
||||
/// The Path's namespace will be determined from `text`. If you already know
|
||||
/// what the namespace should be, use `initWithNamespace` instead.
|
||||
pub fn init(text: string) Path {
|
||||
return Path.initWithPrettyAndNamespace(text, text, Path.determineNamespace(text));
|
||||
}
|
||||
|
||||
/// Create a new `Path` to the given url, path, etc.
|
||||
///
|
||||
/// The Path's namespace will be determined from `text`. If you already know
|
||||
/// what the namespace should be, use `initWithNamespace` instead.
|
||||
pub fn initWithPretty(text: string, pretty: string) Path {
|
||||
return Path.initWithPrettyAndNamespace(text, pretty, Path.determineNamespace(text));
|
||||
}
|
||||
|
||||
/// Create a `Path` representing an absolute or relative path to a file.
|
||||
pub fn initFile(path: string) callconv(bun.callconv_inline) Path {
|
||||
return Path.initWithNamespace(path, file);
|
||||
}
|
||||
|
||||
/// Create a new `Path` with a pre-determined namespace.
|
||||
pub fn initWithNamespace(text: string, namespace: string) Path {
|
||||
return Path.initWithPrettyAndNamespace(text, text, namespace);
|
||||
}
|
||||
|
||||
pub fn initWithPrettyAndNamespace(text: string, pretty: string, namespace: string) Path {
|
||||
return Path{
|
||||
.pretty = pretty,
|
||||
.text = text,
|
||||
.namespace = namespace,
|
||||
.name = PathName.init(text),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn initWithNamespaceVirtual(comptime text: string, comptime namespace: string, comptime package: string) Path {
|
||||
return comptime Path{
|
||||
.pretty = namespace ++ ":" ++ package,
|
||||
.is_symlink = true,
|
||||
.text = text,
|
||||
.namespace = namespace,
|
||||
.name = PathName.init(text),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn initForKitBuiltIn(comptime namespace: string, comptime package: string) Path {
|
||||
return comptime Path{
|
||||
.pretty = namespace ++ ":" ++ package,
|
||||
.is_symlink = true,
|
||||
.text = "_bun/" ++ package,
|
||||
.namespace = namespace,
|
||||
.name = PathName.init(package),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn isFile(this: *const Path) bool {
|
||||
return this.namespace.len == 0 or strings.eqlComptime(this.namespace, "file");
|
||||
}
|
||||
@@ -1816,7 +1874,7 @@ pub const Path = struct {
|
||||
return this.*;
|
||||
}
|
||||
|
||||
var new_path = Fs.Path.init(try FileSystem.FilenameStore.instance.append([]const u8, this.text));
|
||||
var new_path = Fs.Path.initFile(try FileSystem.FilenameStore.instance.append([]const u8, this.text));
|
||||
new_path.pretty = this.text;
|
||||
new_path.namespace = this.namespace;
|
||||
new_path.is_symlink = this.is_symlink;
|
||||
@@ -1826,7 +1884,7 @@ pub const Path = struct {
|
||||
return this.*;
|
||||
}
|
||||
|
||||
var new_path = Fs.Path.init(try FileSystem.FilenameStore.instance.append([]const u8, this.text));
|
||||
var new_path = Fs.Path.initFile(try FileSystem.FilenameStore.instance.append([]const u8, this.text));
|
||||
new_path.pretty = "";
|
||||
new_path.namespace = this.namespace;
|
||||
new_path.is_symlink = this.is_symlink;
|
||||
@@ -1835,9 +1893,8 @@ pub const Path = struct {
|
||||
if (FileSystem.FilenameStore.instance.exists(this.text) or FileSystem.DirnameStore.instance.exists(this.text)) {
|
||||
return this.*;
|
||||
}
|
||||
var new_path = Fs.Path.init(try FileSystem.FilenameStore.instance.append([]const u8, this.text));
|
||||
var new_path = Fs.Path.initWithNamespace(try FileSystem.FilenameStore.instance.append([]const u8, this.text), this.namespace);
|
||||
new_path.pretty = this.text[start_len[0]..][0..start_len[1]];
|
||||
new_path.namespace = this.namespace;
|
||||
new_path.is_symlink = this.is_symlink;
|
||||
return new_path;
|
||||
} else {
|
||||
@@ -1846,14 +1903,14 @@ pub const Path = struct {
|
||||
(FileSystem.FilenameStore.instance.exists(this.pretty) or
|
||||
FileSystem.DirnameStore.instance.exists(this.pretty)))
|
||||
{
|
||||
bun.debugAssert(this.isFile());
|
||||
return this.*;
|
||||
}
|
||||
|
||||
if (strings.indexOf(this.text, this.pretty)) |offset| {
|
||||
var text = try FileSystem.FilenameStore.instance.append([]const u8, this.text);
|
||||
var new_path = Fs.Path.init(text);
|
||||
var new_path = Fs.Path.initWithNamespace(text, this.namespace);
|
||||
new_path.pretty = text[offset..][0..this.pretty.len];
|
||||
new_path.namespace = this.namespace;
|
||||
new_path.is_symlink = this.is_symlink;
|
||||
return new_path;
|
||||
} else {
|
||||
@@ -1862,10 +1919,9 @@ pub const Path = struct {
|
||||
buf.ptr[this.text.len] = 0;
|
||||
const new_pretty = buf[this.text.len + 1 ..][0..this.pretty.len];
|
||||
bun.copy(u8, buf[this.text.len + 1 ..], this.pretty);
|
||||
var new_path = Fs.Path.init(buf[0..this.text.len]);
|
||||
var new_path = Fs.Path.initWithNamespace(buf[0..this.text.len], this.namespace);
|
||||
buf.ptr[buf.len - 1] = 0;
|
||||
new_path.pretty = new_pretty;
|
||||
new_path.namespace = this.namespace;
|
||||
new_path.is_symlink = this.is_symlink;
|
||||
return new_path;
|
||||
}
|
||||
@@ -1885,9 +1941,8 @@ pub const Path = struct {
|
||||
return new;
|
||||
}
|
||||
|
||||
pub const empty = Fs.Path.init("");
|
||||
|
||||
pub fn setRealpath(this: *Path, to: string) void {
|
||||
bun.debugAssert(this.isFile());
|
||||
const old_path = this.text;
|
||||
this.text = to;
|
||||
this.name = PathName.init(to);
|
||||
@@ -1903,53 +1958,6 @@ pub const Path = struct {
|
||||
return try std.fmt.allocPrint(allocator, "{s}://{s}", .{ p.namespace, p.text });
|
||||
}
|
||||
|
||||
pub fn init(text: string) Path {
|
||||
return Path{
|
||||
.pretty = text,
|
||||
.text = text,
|
||||
.namespace = "file",
|
||||
.name = PathName.init(text),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn initWithPretty(text: string, pretty: string) Path {
|
||||
return Path{
|
||||
.pretty = pretty,
|
||||
.text = text,
|
||||
.namespace = "file",
|
||||
.name = PathName.init(text),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn initWithNamespace(text: string, namespace: string) Path {
|
||||
return Path{
|
||||
.pretty = text,
|
||||
.text = text,
|
||||
.namespace = namespace,
|
||||
.name = PathName.init(text),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn initWithNamespaceVirtual(comptime text: string, comptime namespace: string, comptime package: string) Path {
|
||||
return comptime Path{
|
||||
.pretty = namespace ++ ":" ++ package,
|
||||
.is_symlink = true,
|
||||
.text = text,
|
||||
.namespace = namespace,
|
||||
.name = PathName.init(text),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn initForKitBuiltIn(comptime namespace: string, comptime package: string) Path {
|
||||
return comptime Path{
|
||||
.pretty = namespace ++ ":" ++ package,
|
||||
.is_symlink = true,
|
||||
.text = "_bun/" ++ package,
|
||||
.namespace = namespace,
|
||||
.name = PathName.init(package),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn isBefore(a: *Path, b: Path) bool {
|
||||
return a.namespace > b.namespace ||
|
||||
(a.namespace == b.namespace and (a.text < b.text ||
|
||||
@@ -1971,10 +1979,14 @@ pub const Path = struct {
|
||||
else
|
||||
path.pretty;
|
||||
}
|
||||
|
||||
fn determineNamespace(text: string) string {
|
||||
if (text.len < 5) return file; // "data:", etc.
|
||||
// Avoid searching all of `text` as an optimization. Most namespaces are 4
|
||||
// characters, so 8 should give enough slack for uncommon cases
|
||||
return if (bun.strings.indexOfChar(text[0..@min(text.len, 8)], ':')) |colon|
|
||||
text[0..colon]
|
||||
else
|
||||
file;
|
||||
}
|
||||
};
|
||||
|
||||
// pub fn customRealpath(allocator: std.mem.Allocator, path: string) !string {
|
||||
// var opened = try std.posix.open(path, if (Environment.isLinux) bun.O.PATH else bun.O.RDONLY, 0);
|
||||
// defer std.posix.close(opened);
|
||||
|
||||
// }
|
||||
|
||||
@@ -5216,7 +5216,7 @@ fn NewParser_(
|
||||
|
||||
str.resolveRopeIfNeeded(p.allocator);
|
||||
const pathname = str.string(p.allocator) catch unreachable;
|
||||
const path = fs.Path.init(pathname);
|
||||
const path = fs.Path.initFile(pathname);
|
||||
|
||||
const handles_import_errors = p.fn_or_arrow_data_visit.try_body_count != 0;
|
||||
|
||||
@@ -13021,7 +13021,7 @@ fn NewParser_(
|
||||
}
|
||||
|
||||
pub fn addImportRecordByRange(p: *P, kind: ImportKind, range: logger.Range, name: string) u32 {
|
||||
return p.addImportRecordByRangeAndPath(kind, range, fs.Path.init(name));
|
||||
return p.addImportRecordByRangeAndPath(kind, range, fs.Path.initFile(name));
|
||||
}
|
||||
|
||||
pub fn addImportRecordByRangeAndPath(p: *P, kind: ImportKind, range: logger.Range, path: fs.Path) u32 {
|
||||
|
||||
@@ -221,8 +221,7 @@ pub const Linker = struct {
|
||||
}
|
||||
|
||||
if (strings.hasPrefixComptime(import_record.path.text, "bun:")) {
|
||||
import_record.path = Fs.Path.init(import_record.path.text["bun:".len..]);
|
||||
import_record.path.namespace = "bun";
|
||||
import_record.path = Fs.Path.initWithNamespace(import_record.path.text["bun:".len..], "bun");
|
||||
|
||||
if (strings.eqlComptime(import_record.path.text, "test")) {
|
||||
import_record.tag = .bun_test;
|
||||
@@ -350,7 +349,7 @@ pub const Linker = struct {
|
||||
|
||||
if (strings.eqlComptime(namespace, "bun") or strings.eqlComptime(namespace, "file") or namespace.len == 0) {
|
||||
const relative_name = linker.fs.relative(source_dir, source_path);
|
||||
return Fs.Path.initWithPretty(source_path, relative_name);
|
||||
return Fs.Path.initWithPrettyAndNamespace(source_path, relative_name, namespace);
|
||||
} else {
|
||||
return Fs.Path.initWithNamespace(source_path, namespace);
|
||||
}
|
||||
@@ -360,7 +359,7 @@ pub const Linker = struct {
|
||||
|
||||
var pretty: string = undefined;
|
||||
if (use_hashed_name) {
|
||||
var basepath = Fs.Path.init(source_path);
|
||||
var basepath = Fs.Path.initFile(source_path);
|
||||
const basename = try linker.getHashedFilename(basepath, null);
|
||||
const dir = basepath.name.dirWithTrailingSlash();
|
||||
var _pretty = try linker.allocator.alloc(u8, dir.len + basename.len + basepath.name.ext.len);
|
||||
@@ -388,7 +387,7 @@ pub const Linker = struct {
|
||||
if (strings.eqlComptime(namespace, "node")) {
|
||||
if (comptime Environment.isDebug) bun.assert(strings.eqlComptime(source_path[0..5], "node:"));
|
||||
|
||||
return Fs.Path.init(try std.fmt.allocPrint(
|
||||
return Fs.Path.initWithNamespace(try std.fmt.allocPrint(
|
||||
linker.allocator,
|
||||
// assumption: already starts with "node:"
|
||||
"{s}/{s}",
|
||||
@@ -396,7 +395,7 @@ pub const Linker = struct {
|
||||
strings.withoutTrailingSlash(origin.href),
|
||||
strings.withoutLeadingSlash(source_path),
|
||||
},
|
||||
));
|
||||
), "node");
|
||||
} else {
|
||||
var absolute_pathname = Fs.PathName.init(source_path);
|
||||
|
||||
@@ -416,19 +415,19 @@ pub const Linker = struct {
|
||||
var basename = std.fs.path.basename(base);
|
||||
|
||||
if (use_hashed_name) {
|
||||
const basepath = Fs.Path.init(source_path);
|
||||
const basepath = Fs.Path.initFile(source_path);
|
||||
|
||||
basename = try linker.getHashedFilename(basepath, null);
|
||||
}
|
||||
|
||||
return Fs.Path.init(try origin.joinAlloc(
|
||||
return Fs.Path.initWithNamespace(try origin.joinAlloc(
|
||||
linker.allocator,
|
||||
"",
|
||||
dirname,
|
||||
basename,
|
||||
absolute_pathname.ext,
|
||||
source_path,
|
||||
));
|
||||
), namespace);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1422,7 +1422,7 @@ pub const Source = struct {
|
||||
};
|
||||
|
||||
pub fn initEmptyFile(filepath: string) Source {
|
||||
const path = fs.Path.init(filepath);
|
||||
const path = fs.Path.initFile(filepath);
|
||||
return Source{ .path = path, .contents = "" };
|
||||
}
|
||||
|
||||
@@ -1447,7 +1447,7 @@ pub const Source = struct {
|
||||
}
|
||||
|
||||
pub fn initPathString(pathString: string, contents: string) Source {
|
||||
const path = fs.Path.init(pathString);
|
||||
const path = fs.Path.initFile(pathString);
|
||||
return Source{ .path = path, .contents = contents };
|
||||
}
|
||||
|
||||
|
||||
@@ -982,7 +982,7 @@ pub fn getLoaderAndVirtualSource(
|
||||
jsc_vm,
|
||||
specifier_str,
|
||||
);
|
||||
var path = Fs.Path.init(normalized_file_path_from_specifier);
|
||||
var path = Fs.Path.initFile(normalized_file_path_from_specifier);
|
||||
|
||||
var loader: ?Loader = path.loader(&jsc_vm.transpiler.options.loaders);
|
||||
var virtual_source: ?*logger.Source = null;
|
||||
@@ -1006,7 +1006,7 @@ pub fn getLoaderAndVirtualSource(
|
||||
// "file:" loader makes no sense for blobs
|
||||
// so let's default to tsx.
|
||||
if (blob.getFileName()) |filename| {
|
||||
const current_path = Fs.Path.init(filename);
|
||||
const current_path = Fs.Path.initFile(filename);
|
||||
|
||||
// Only treat it as a file if is a Bun.file()
|
||||
if (blob.needsToReadFile()) {
|
||||
@@ -2043,7 +2043,7 @@ pub const TransformOptions = struct {
|
||||
assert(entryPointName.len > 0);
|
||||
|
||||
const entryPoint = Fs.File{
|
||||
.path = Fs.Path.init(entryPointName),
|
||||
.path = Fs.Path.initFile(entryPointName),
|
||||
.contents = code,
|
||||
};
|
||||
|
||||
|
||||
@@ -604,7 +604,7 @@ pub const PackageJSON = struct {
|
||||
null,
|
||||
) catch |err| {
|
||||
if (err != error.IsDir) {
|
||||
r.log.addErrorFmt(null, logger.Loc.Empty, allocator, "Cannot read file \"{s}\": {s}", .{ r.prettyPath(fs.Path.init(input_path)), @errorName(err) }) catch unreachable;
|
||||
r.log.addErrorFmt(null, logger.Loc.Empty, allocator, "Cannot read file \"{s}\": {s}", .{ r.prettyPath(fs.Path.initFile(input_path)), @errorName(err) }) catch unreachable;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -615,7 +615,7 @@ pub const PackageJSON = struct {
|
||||
debug.addNoteFmt("The file \"{s}\" exists", .{package_json_path});
|
||||
}
|
||||
|
||||
const key_path = fs.Path.init(package_json_path);
|
||||
const key_path = fs.Path.initFile(package_json_path);
|
||||
|
||||
var json_source = logger.Source.initPathString(key_path.text, entry.contents);
|
||||
json_source.path.pretty = r.prettyPath(json_source.path);
|
||||
|
||||
@@ -719,7 +719,9 @@ pub const Resolver = struct {
|
||||
.success = Result{
|
||||
.import_kind = kind,
|
||||
.path_pair = PathPair{
|
||||
.primary = Path.init(import_path),
|
||||
// NOTE: not actually a "file" but we want this to
|
||||
// follow the same code path as files.
|
||||
.primary = Path.initFile(import_path),
|
||||
},
|
||||
.is_external = true,
|
||||
.module_type = .cjs,
|
||||
@@ -808,7 +810,7 @@ pub const Resolver = struct {
|
||||
.success = Result{
|
||||
.import_kind = kind,
|
||||
.path_pair = PathPair{
|
||||
.primary = Path.init(import_path),
|
||||
.primary = Path.initFile(import_path),
|
||||
},
|
||||
.is_standalone_module = true,
|
||||
.module_type = .esm,
|
||||
@@ -828,7 +830,7 @@ pub const Resolver = struct {
|
||||
.success = Result{
|
||||
.import_kind = kind,
|
||||
.path_pair = PathPair{
|
||||
.primary = Path.init(file.name),
|
||||
.primary = Path.initFile(file.name),
|
||||
},
|
||||
.is_standalone_module = true,
|
||||
.module_type = .esm,
|
||||
@@ -1171,7 +1173,7 @@ pub const Resolver = struct {
|
||||
|
||||
return .{
|
||||
.success = Result{
|
||||
.path_pair = .{ .primary = Path.init(import_path) },
|
||||
.path_pair = .{ .primary = Path.initFile(import_path) },
|
||||
.is_external = true,
|
||||
},
|
||||
};
|
||||
@@ -1216,7 +1218,7 @@ pub const Resolver = struct {
|
||||
|
||||
return .{
|
||||
.success = Result{
|
||||
.path_pair = .{ .primary = Path.init(r.fs.dirname_store.append(@TypeOf(abs_path), abs_path) catch unreachable) },
|
||||
.path_pair = .{ .primary = Path.initFile(r.fs.dirname_store.append(@TypeOf(abs_path), abs_path) catch unreachable) },
|
||||
.is_external = true,
|
||||
},
|
||||
};
|
||||
@@ -1235,7 +1237,7 @@ pub const Resolver = struct {
|
||||
|
||||
// Is the path disabled?
|
||||
if (remap.len == 0) {
|
||||
var _path = Path.init(r.fs.dirname_store.append(string, abs_path) catch unreachable);
|
||||
var _path = Path.initFile(r.fs.dirname_store.append(string, abs_path) catch unreachable);
|
||||
_path.is_disabled = true;
|
||||
return .{
|
||||
.success = Result{
|
||||
@@ -1350,7 +1352,7 @@ pub const Resolver = struct {
|
||||
}
|
||||
return .{
|
||||
.success = Result{
|
||||
.path_pair = .{ .primary = Path.init(query) },
|
||||
.path_pair = .{ .primary = Path.initFile(query) },
|
||||
.is_external = true,
|
||||
},
|
||||
};
|
||||
@@ -1433,7 +1435,7 @@ pub const Resolver = struct {
|
||||
// "browser": {"module": false}
|
||||
// the module doesn't exist and it's disabled
|
||||
// so we should just not try to load it
|
||||
var primary = Path.init(import_path);
|
||||
var primary = Path.initFile(import_path);
|
||||
primary.is_disabled = true;
|
||||
return .{
|
||||
.success = Result{
|
||||
@@ -2010,7 +2012,7 @@ pub const Resolver = struct {
|
||||
if (err == error.FileNotFound) {
|
||||
switch (manager.getPreinstallState(resolved_package_id)) {
|
||||
.done => {
|
||||
var path = Fs.Path.init(import_path);
|
||||
var path = Fs.Path.initFile(import_path);
|
||||
path.is_disabled = true;
|
||||
// this might mean the package is disabled
|
||||
return .{
|
||||
@@ -2538,7 +2540,7 @@ pub const Resolver = struct {
|
||||
// The file name needs to be persistent because it can have errors
|
||||
// and if those errors need to print the filename
|
||||
// then it will be undefined memory if we parse another tsconfig.json late
|
||||
const key_path = Fs.Path.init(r.fs.dirname_store.append(string, file) catch unreachable);
|
||||
const key_path = Fs.Path.initFile(r.fs.dirname_store.append(string, file) catch unreachable);
|
||||
|
||||
const source = logger.Source.initPathString(key_path.text, entry.contents);
|
||||
const file_dir = source.path.sourceDir();
|
||||
@@ -2830,7 +2832,7 @@ pub const Resolver = struct {
|
||||
r.dir_cache.markNotFound(queue_top.result);
|
||||
rfs.entries.markNotFound(cached_dir_entry_result);
|
||||
if (comptime enable_logging) {
|
||||
const pretty = r.prettyPath(Path.init(queue_top.unsafe_path));
|
||||
const pretty = r.prettyPath(Path.initFile(queue_top.unsafe_path));
|
||||
|
||||
r.log.addErrorFmt(
|
||||
null,
|
||||
@@ -3133,7 +3135,7 @@ pub const Resolver = struct {
|
||||
if (JSC.HardcodedModule.Aliases.has(esm_resolution.path, r.opts.target)) {
|
||||
return .{
|
||||
.success = .{
|
||||
.path_pair = .{ .primary = bun.fs.Path.init(esm_resolution.path) },
|
||||
.path_pair = .{ .primary = bun.fs.Path.initFile(esm_resolution.path) },
|
||||
.is_external = true,
|
||||
},
|
||||
};
|
||||
@@ -3346,7 +3348,7 @@ pub const Resolver = struct {
|
||||
if (remap.len == 0) {
|
||||
const paths = [_]string{ path, field_rel_path };
|
||||
const new_path = r.fs.absAlloc(r.allocator, &paths) catch unreachable;
|
||||
var _path = Path.init(new_path);
|
||||
var _path = Path.initFile(new_path);
|
||||
_path.is_disabled = true;
|
||||
return MatchResult{
|
||||
.path_pair = PathPair{
|
||||
@@ -3368,14 +3370,14 @@ pub const Resolver = struct {
|
||||
if (r.loadAsFile(field_abs_path, extension_order)) |result| {
|
||||
if (dir_info.package_json) |package_json| {
|
||||
return MatchResult{
|
||||
.path_pair = PathPair{ .primary = Fs.Path.init(result.path) },
|
||||
.path_pair = PathPair{ .primary = Fs.Path.initFile(result.path) },
|
||||
.package_json = package_json,
|
||||
.dirname_fd = result.dirname_fd,
|
||||
};
|
||||
}
|
||||
|
||||
return MatchResult{
|
||||
.path_pair = PathPair{ .primary = Fs.Path.init(result.path) },
|
||||
.path_pair = PathPair{ .primary = Fs.Path.initFile(result.path) },
|
||||
.dirname_fd = result.dirname_fd,
|
||||
.diff_case = result.diff_case,
|
||||
};
|
||||
@@ -3496,7 +3498,7 @@ pub const Resolver = struct {
|
||||
|
||||
if (dir_info.package_json) |package_json| {
|
||||
return MatchResult{
|
||||
.path_pair = .{ .primary = Path.init(out_buf) },
|
||||
.path_pair = .{ .primary = Path.initFile(out_buf) },
|
||||
.diff_case = lookup.diff_case,
|
||||
.package_json = package_json,
|
||||
.dirname_fd = dir_info.getFileDescriptor(),
|
||||
@@ -3504,7 +3506,7 @@ pub const Resolver = struct {
|
||||
}
|
||||
|
||||
return MatchResult{
|
||||
.path_pair = .{ .primary = Path.init(out_buf) },
|
||||
.path_pair = .{ .primary = Path.initFile(out_buf) },
|
||||
.diff_case = lookup.diff_case,
|
||||
|
||||
.dirname_fd = dir_info.getFileDescriptor(),
|
||||
@@ -3547,7 +3549,7 @@ pub const Resolver = struct {
|
||||
if (remap.len == 0) {
|
||||
const paths = [_]string{ path, field_rel_path };
|
||||
const new_path = r.fs.absBuf(&paths, bufs(.remap_path));
|
||||
var _path = Path.init(new_path);
|
||||
var _path = Path.initFile(new_path);
|
||||
_path.is_disabled = true;
|
||||
return MatchResult{
|
||||
.path_pair = PathPair{
|
||||
@@ -3562,7 +3564,7 @@ pub const Resolver = struct {
|
||||
|
||||
// Is this a file
|
||||
if (r.loadAsFile(remapped_abs, extension_order)) |file_result| {
|
||||
return MatchResult{ .dirname_fd = file_result.dirname_fd, .path_pair = .{ .primary = Path.init(file_result.path) }, .diff_case = file_result.diff_case };
|
||||
return MatchResult{ .dirname_fd = file_result.dirname_fd, .path_pair = .{ .primary = Path.initFile(file_result.path) }, .diff_case = file_result.diff_case };
|
||||
}
|
||||
|
||||
// Is it a directory with an index?
|
||||
@@ -3594,7 +3596,7 @@ pub const Resolver = struct {
|
||||
if ((r.dirInfoCached(file.path[0 .. node_modules_folder_offset + package_name_length]) catch null)) |package_dir_info| {
|
||||
if (package_dir_info.package_json) |package_json| {
|
||||
return MatchResult{
|
||||
.path_pair = .{ .primary = Path.init(file.path) },
|
||||
.path_pair = .{ .primary = Path.initFile(file.path) },
|
||||
.diff_case = file.diff_case,
|
||||
.dirname_fd = file.dirname_fd,
|
||||
.package_json = package_json,
|
||||
@@ -3610,7 +3612,7 @@ pub const Resolver = struct {
|
||||
}
|
||||
|
||||
return MatchResult{
|
||||
.path_pair = .{ .primary = Path.init(file.path) },
|
||||
.path_pair = .{ .primary = Path.initFile(file.path) },
|
||||
.diff_case = file.diff_case,
|
||||
.dirname_fd = file.dirname_fd,
|
||||
.file_fd = file.file_fd,
|
||||
@@ -3771,7 +3773,7 @@ pub const Resolver = struct {
|
||||
r.allocator,
|
||||
"Cannot read directory \"{s}\": {s}",
|
||||
.{
|
||||
r.prettyPath(Path.init(dir_path)),
|
||||
r.prettyPath(Path.initFile(dir_path)),
|
||||
@errorName(dir_entry.err.original_err),
|
||||
},
|
||||
) catch {};
|
||||
@@ -4135,7 +4137,7 @@ pub const Resolver = struct {
|
||||
tsconfigpath,
|
||||
if (FeatureFlags.store_file_descriptors) fd else .zero,
|
||||
) catch |err| brk: {
|
||||
const pretty = r.prettyPath(Path.init(tsconfigpath));
|
||||
const pretty = r.prettyPath(Path.initFile(tsconfigpath));
|
||||
|
||||
if (err == error.ENOENT or err == error.FileNotFound) {
|
||||
r.log.addErrorFmt(null, logger.Loc.Empty, r.allocator, "Cannot find tsconfig file {}", .{bun.fmt.QuotedFormatter{ .text = pretty }}) catch {};
|
||||
|
||||
@@ -4461,7 +4461,7 @@ pub fn indexOfCharUsize(slice: []const u8, char: u8) ?usize {
|
||||
if (slice.len == 0)
|
||||
return null;
|
||||
|
||||
if (comptime !Environment.isNative) {
|
||||
if (@inComptime() or comptime !Environment.isNative) {
|
||||
return std.mem.indexOfScalar(u8, slice, char);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user