@@ -4,24 +4,18 @@ const types = @import("../types.zig");
44const errors = @import ("../errors.zig" );
55const utils = @import ("../utils.zig" );
66
7- // Zig 0.16+ IO helper
8- var io_instance : std.Io.Threaded = .init_single_threaded ;
9- fn getIo () std.Io {
10- return io_instance .io ();
11- }
12-
13- /// Check if a file exists using cross-platform Io.Dir
7+ /// Check if a file exists
148fn fileExists (path : []const u8 ) bool {
15- const file = std .Io . Dir . cwd ().openFile (getIo (), path , .{ . mode = .read_only }) catch return false ;
16- file .close (getIo () );
9+ const file = std .fs . cwd ().openFile (path , .{}) catch return false ;
10+ file .close ();
1711 return true ;
1812}
1913
2014/// Strip single-line (//) and multi-line (/* */) comments from JSON content
2115fn stripJsonComments (allocator : std.mem.Allocator , content : []const u8 ) ! []const u8 {
22- var result = std .ArrayList (u8 ){} ;
23- try result .ensureTotalCapacity (allocator , content .len );
24- errdefer result .deinit (allocator );
16+ var result = std .ArrayList (u8 ). init ( allocator ) ;
17+ try result .ensureTotalCapacity (content .len );
18+ errdefer result .deinit ();
2519
2620 var i : usize = 0 ;
2721 var in_string = false ;
@@ -33,12 +27,12 @@ fn stripJsonComments(allocator: std.mem.Allocator, content: []const u8) ![]const
3327 // Handle string literals (comments inside strings should not be stripped)
3428 if (c == '"' and ! escape_next ) {
3529 in_string = ! in_string ;
36- try result .append (allocator , c );
30+ try result .append (c );
3731 continue ;
3832 }
3933
4034 if (in_string ) {
41- try result .append (allocator , c );
35+ try result .append (c );
4236 escape_next = (c == '\\ ' and ! escape_next );
4337 continue ;
4438 }
@@ -50,7 +44,7 @@ fn stripJsonComments(allocator: std.mem.Allocator, content: []const u8) ![]const
5044 // Skip until end of line
5145 i += 2 ;
5246 while (i < content .len and content [i ] != '\n ' ) : (i += 1 ) {}
53- if (i < content .len ) try result .append (allocator , '\n ' ); // Preserve newline
47+ if (i < content .len ) try result .append ('\n ' ); // Preserve newline
5448 continue ;
5549 }
5650
@@ -67,10 +61,10 @@ fn stripJsonComments(allocator: std.mem.Allocator, content: []const u8) ![]const
6761 continue ;
6862 }
6963
70- try result .append (allocator , c );
64+ try result .append (c );
7165 }
7266
73- return result .toOwnedSlice (allocator );
67+ return try result .toOwnedSlice ();
7468}
7569
7670/// File loader service for discovering and loading configuration files
@@ -156,33 +150,18 @@ pub const FileLoader = struct {
156150 return self .loadTypeScriptConfig (path );
157151 }
158152
159- // Use cross-platform Io.Dir for file access
160- const file = std .Io . Dir . cwd ().openFile (getIo (), path , .{ . mode = .read_only }) catch | err | {
153+ // Open file
154+ const file = std .fs . cwd ().openFile (path , .{}) catch | err | {
161155 return switch (err ) {
162156 error .FileNotFound = > errors .ZigConfigError .ConfigFileNotFound ,
163157 error .AccessDenied = > errors .ZigConfigError .ConfigFilePermissionDenied ,
164158 else = > errors .ZigConfigError .ConfigFileInvalid ,
165159 };
166160 };
167- defer file .close (getIo ());
168-
169- // Read file content using Io.File (cross-platform)
170- var content = std .ArrayList (u8 ).empty ;
171- defer content .deinit (self .allocator );
172-
173- var buf : [4096 ]u8 = undefined ;
174- while (true ) {
175- const bufs = [_ ][]u8 {& buf };
176- const n = file .readStreaming (getIo (), & bufs ) catch {
177- return errors .ZigConfigError .ConfigFileInvalid ;
178- };
179- if (n == 0 ) break ;
180- content .appendSlice (self .allocator , buf [0.. n ]) catch {
181- return errors .ZigConfigError .ConfigFileInvalid ;
182- };
183- }
161+ defer file .close ();
184162
185- const owned_content = content .toOwnedSlice (self .allocator ) catch {
163+ // Read file content
164+ const owned_content = file .readToEndAlloc (self .allocator , 1024 * 1024 ) catch {
186165 return errors .ZigConfigError .ConfigFileInvalid ;
187166 };
188167 defer self .allocator .free (owned_content );
@@ -226,8 +205,9 @@ pub const FileLoader = struct {
226205 ) catch return errors .ZigConfigError .ConfigFileInvalid ;
227206 defer self .allocator .free (script );
228207
229- // Use cross-platform std.process.run to execute bun
230- const result = std .process .run (self .allocator , getIo (), .{
208+ // Use std.process.Child to execute bun
209+ const result = std .process .Child .run (.{
210+ .allocator = self .allocator ,
231211 .argv = &.{ "bun" , "-e" , script },
232212 }) catch {
233213 return errors .ZigConfigError .ConfigFileInvalid ;
@@ -260,12 +240,12 @@ pub const FileLoader = struct {
260240 /// Get file modification time for cache invalidation
261241 pub fn getModTime (self : * FileLoader , path : []const u8 ) ! i64 {
262242 _ = self ;
263- // Open file using cross-platform Io.Dir and use File. stat
264- const file = std .Io . Dir . cwd ().openFile (getIo (), path , .{ . mode = .read_only }) catch return error .FileNotFound ;
265- defer file .close (getIo () );
266- const stat = try file .stat (getIo () );
267- // mtime is in nanoseconds, convert to seconds
268- return @intCast (@divTrunc (stat .mtime . nanoseconds , std .time .ns_per_s ));
243+ // Open file and use stat
244+ const file = std .fs . cwd ().openFile (path , .{}) catch return error .FileNotFound ;
245+ defer file .close ();
246+ const stat = try file .stat ();
247+ // mtime is in nanoseconds (i128) , convert to seconds
248+ return @intCast (@divTrunc (stat .mtime , std .time .ns_per_s ));
269249 }
270250};
271251
@@ -294,9 +274,9 @@ test "FileLoader.findConfigFile finds in project root" {
294274 var tmp = std .testing .tmpDir (.{});
295275 defer tmp .cleanup ();
296276
297- const file = try tmp .dir .createFile (getIo (), "test.json" , .{});
298- defer file .close (getIo () );
299- try file .writePositionalAll ( getIo (), "{}" , 0 );
277+ const file = try tmp .dir .createFile ("test.json" , .{});
278+ defer file .close ();
279+ try file .writeAll ( "{}" );
300280
301281 const cwd = try tmpDirRealPath (allocator , & tmp , "." );
302282 defer allocator .free (cwd );
@@ -330,9 +310,9 @@ test "FileLoader.loadConfigFile parses JSON" {
330310 var tmp = std .testing .tmpDir (.{});
331311 defer tmp .cleanup ();
332312
333- const file = try tmp .dir .createFile (getIo (), "test.json" , .{});
334- defer file .close (getIo () );
335- try file .writePositionalAll ( getIo (), "{\" key\" : \" value\" }" , 0 );
313+ const file = try tmp .dir .createFile ("test.json" , .{});
314+ defer file .close ();
315+ try file .writeAll ( "{\" key\" : \" value\" }" );
336316
337317 const path = try tmpDirRealPath (allocator , & tmp , "test.json" );
338318 defer allocator .free (path );
0 commit comments