aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-06-19 18:23:15 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-06-19 18:23:15 -0700
commit3d9028f0eed792f088fc04a878e436a36699fb82 (patch)
treeb9fd1716ac6536b19a4bc0fd019ac14c588a196e
parent3f10c8790629ab157d9377759cc50a4b962cc6f4 (diff)
downloadbun-3d9028f0eed792f088fc04a878e436a36699fb82.tar.gz
bun-3d9028f0eed792f088fc04a878e436a36699fb82.tar.zst
bun-3d9028f0eed792f088fc04a878e436a36699fb82.zip
Show line counts for CSS
-rw-r--r--src/bundler.zig8
-rw-r--r--src/css_scanner.zig19
-rw-r--r--src/http.zig6
3 files changed, 22 insertions, 11 deletions
diff --git a/src/bundler.zig b/src/bundler.zig
index 1bcf12a58..8b4263c53 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -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,
diff --git a/src/css_scanner.zig b/src/css_scanner.zig
index 1bfada0a0..d26fbf1a1 100644
--- a/src/css_scanner.zig
+++ b/src/css_scanner.zig
@@ -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 {
diff --git a/src/http.zig b/src/http.zig
index bd7b3477f..269274b56 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -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()),
};