mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Show line counts for CSS
This commit is contained in:
@@ -895,7 +895,7 @@ pub fn NewBundler(cache_files: bool) type {
|
||||
return BuildResolveResultPair{
|
||||
.written = brk: {
|
||||
if (bundler.options.hot_module_reloading) {
|
||||
break :brk try CSSBundlerHMR.bundle(
|
||||
break :brk (try CSSBundlerHMR.bundle(
|
||||
resolve_result.path_pair.primary.text,
|
||||
bundler.fs,
|
||||
writer,
|
||||
@@ -906,9 +906,9 @@ pub fn NewBundler(cache_files: bool) type {
|
||||
allocator,
|
||||
bundler.log,
|
||||
&bundler.linker,
|
||||
);
|
||||
)).written;
|
||||
} else {
|
||||
break :brk try CSSBundler.bundle(
|
||||
break :brk (try CSSBundler.bundle(
|
||||
resolve_result.path_pair.primary.text,
|
||||
bundler.fs,
|
||||
writer,
|
||||
@@ -919,7 +919,7 @@ pub fn NewBundler(cache_files: bool) type {
|
||||
allocator,
|
||||
bundler.log,
|
||||
&bundler.linker,
|
||||
);
|
||||
)).written;
|
||||
}
|
||||
},
|
||||
.input_fd = file_descriptor,
|
||||
|
||||
@@ -806,7 +806,7 @@ pub fn NewWriter(
|
||||
try scanner.next(.scan, @TypeOf(writer), writer, scanChunk);
|
||||
}
|
||||
|
||||
pub fn append(writer: *Writer, log: *logger.Log, allocator: *std.mem.Allocator) !void {
|
||||
pub fn append(writer: *Writer, log: *logger.Log, allocator: *std.mem.Allocator) !usize {
|
||||
var scanner = Scanner.init(
|
||||
log,
|
||||
|
||||
@@ -815,6 +815,7 @@ pub fn NewWriter(
|
||||
);
|
||||
|
||||
try scanner.next(.omit, @TypeOf(writer), writer, writeBundledChunk);
|
||||
return scanner.approximate_newline_count;
|
||||
}
|
||||
|
||||
pub fn run(writer: *Writer, log: *logger.Log, allocator: *std.mem.Allocator) !void {
|
||||
@@ -981,6 +982,11 @@ pub fn NewWriter(
|
||||
};
|
||||
}
|
||||
|
||||
pub const CodeCount = struct {
|
||||
approximate_newline_count: usize = 0,
|
||||
written: usize = 0,
|
||||
};
|
||||
|
||||
const ImportQueueFifo = std.fifo.LinearFifo(u32, .Dynamic);
|
||||
const QueuedList = std.ArrayList(u32);
|
||||
threadlocal var global_queued: QueuedList = undefined;
|
||||
@@ -1017,7 +1023,7 @@ pub fn NewBundler(
|
||||
allocator: *std.mem.Allocator,
|
||||
log: *logger.Log,
|
||||
linker: Linker,
|
||||
) !usize {
|
||||
) !CodeCount {
|
||||
if (!has_set_global_queue) {
|
||||
global_queued = QueuedList.init(alloc.static);
|
||||
global_import_queud = ImportQueueFifo.init(alloc.static);
|
||||
@@ -1072,6 +1078,7 @@ pub fn NewBundler(
|
||||
try this.writeAll(int_buf_print[0..int_buf_size]);
|
||||
try this.writeAll(") {}\n");
|
||||
}
|
||||
var lines_of_code: usize = 0;
|
||||
|
||||
// We LIFO
|
||||
var i: i32 = @intCast(i32, this.bundle_queue.items.len - 1);
|
||||
@@ -1093,11 +1100,15 @@ pub fn NewBundler(
|
||||
try this.writeAll("/* ");
|
||||
try this.writeAll(file_path);
|
||||
try this.writeAll("*/\n");
|
||||
try css.append(log, allocator);
|
||||
lines_of_code += try css.append(log, allocator);
|
||||
}
|
||||
|
||||
try this.writer.done();
|
||||
return css.written;
|
||||
|
||||
return CodeCount{
|
||||
.written = css.written,
|
||||
.approximate_newline_count = lines_of_code,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn getSource(this: *CSSBundler, url: string, input_fd: StoredFileDescriptorType) !logger.Source {
|
||||
|
||||
@@ -533,7 +533,7 @@ pub const RequestContext = struct {
|
||||
|
||||
this.printer.ctx.reset();
|
||||
|
||||
const written = brk: {
|
||||
const count = brk: {
|
||||
if (this.bundler.options.hot_module_reloading) {
|
||||
break :brk try CSSBundlerHMR.bundle(
|
||||
file_path_str,
|
||||
@@ -570,13 +570,13 @@ pub const RequestContext = struct {
|
||||
.from_timestamp = from_timestamp,
|
||||
.loader = .css,
|
||||
.module_path = this.bundler.fs.relativeTo(file_path_str),
|
||||
.blob_length = @truncate(u32, written),
|
||||
.blob_length = @truncate(u32, count.written),
|
||||
// .log = std.mem.zeroes(Api.Log),
|
||||
},
|
||||
},
|
||||
.id = id,
|
||||
.bytes = this.printer.ctx.written,
|
||||
.approximate_newline_count = 0,
|
||||
.approximate_newline_count = count.approximate_newline_count,
|
||||
// .approximate_newline_count = parse_result.ast.approximate_newline_count,
|
||||
.timestamp = WebsocketHandler.toTimestamp(this.timer.read()),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user