Skip to content

Commit

Permalink
refactor: organize native glob code (#15914)
Browse files Browse the repository at this point in the history
Co-authored-by: DonIsaac <DonIsaac@users.noreply.github.com>
  • Loading branch information
DonIsaac and DonIsaac authored Dec 21, 2024
1 parent 50eec00 commit acb9fdf
Show file tree
Hide file tree
Showing 9 changed files with 2,245 additions and 2,215 deletions.
5 changes: 2 additions & 3 deletions src/bun.js/api/glob.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Glob = @This();
const globImpl = @import("../../glob.zig");
const globImplAscii = @import("../../glob_ascii.zig");
const GlobWalker = globImpl.BunGlobWalker;
const PathLike = @import("../node/types.zig").PathLike;
const ArgumentsSlice = @import("../node/types.zig").ArgumentsSlice;
Expand Down Expand Up @@ -407,7 +406,7 @@ pub fn match(this: *Glob, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame
var str = str_arg.toSlice(globalThis, arena.allocator());
defer str.deinit();

if (this.is_ascii and isAllAscii(str.slice())) return JSC.JSValue.jsBoolean(globImplAscii.match(this.pattern, str.slice()));
if (this.is_ascii and isAllAscii(str.slice())) return JSC.JSValue.jsBoolean(globImpl.Ascii.match(this.pattern, str.slice()));

const codepoints = codepoints: {
if (this.pattern_codepoints) |cp| break :codepoints cp.items[0..];
Expand All @@ -422,7 +421,7 @@ pub fn match(this: *Glob, globalThis: *JSGlobalObject, callframe: *JSC.CallFrame
break :codepoints codepoints.items[0..codepoints.items.len];
};

return if (globImpl.matchImpl(codepoints, str.slice()).matches()) .true else .false;
return if (globImpl.walk.matchImpl(codepoints, str.slice()).matches()) .true else .false;
}

pub fn convertUtf8(codepoints: *std.ArrayList(u32), pattern: []const u8) !void {
Expand Down
6 changes: 3 additions & 3 deletions src/cli/filter_arg.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn globIgnoreFn(val: []const u8) bool {
return false;
}

const GlobWalker = Glob.GlobWalker_(globIgnoreFn, Glob.DirEntryAccessor, false);
const GlobWalker = Glob.GlobWalker(globIgnoreFn, Glob.walk.DirEntryAccessor, false);

pub fn getCandidatePackagePatterns(allocator: std.mem.Allocator, log: *bun.logger.Log, out_patterns: *std.ArrayList([]u8), workdir_: []const u8, root_buf: *bun.PathBuffer) ![]const u8 {
bun.JSAst.Expr.Data.Store.create();
Expand Down Expand Up @@ -187,7 +187,7 @@ pub const FilterSet = struct {

pub fn matchesPath(self: *const FilterSet, path: []const u8) bool {
for (self.filters) |filter| {
if (Glob.matchImpl(filter.codepoints, path).matches()) {
if (Glob.walk.matchImpl(filter.codepoints, path).matches()) {
return true;
}
}
Expand All @@ -200,7 +200,7 @@ pub const FilterSet = struct {
.name => name,
.path => path,
};
if (Glob.matchImpl(filter.codepoints, target).matches()) {
if (Glob.walk.matchImpl(filter.codepoints, target).matches()) {
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli/outdated_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ pub const OutdatedCommand = struct {

const abs_res_path = path.joinAbsString(FileSystem.instance.top_level_dir, &[_]string{res_path}, .posix);

if (!glob.matchImpl(pattern, strings.withoutTrailingSlash(abs_res_path)).matches()) {
if (!glob.walk.matchImpl(pattern, strings.withoutTrailingSlash(abs_res_path)).matches()) {
break :matched false;
}
},
.name => |pattern| {
const name = pkg_names[workspace_pkg_id].slice(string_buf);

if (!glob.matchImpl(pattern, name).matches()) {
if (!glob.walk.matchImpl(pattern, name).matches()) {
break :matched false;
}
},
Expand Down Expand Up @@ -331,7 +331,7 @@ pub const OutdatedCommand = struct {
.path => unreachable,
.name => |name_pattern| {
if (name_pattern.len == 0) continue;
if (!glob.matchImpl(name_pattern, dep.name.slice(string_buf)).matches()) {
if (!glob.walk.matchImpl(name_pattern, dep.name.slice(string_buf)).matches()) {
break :match false;
}
},
Expand Down
8 changes: 4 additions & 4 deletions src/cli/pack_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub const PackCommand = struct {
// normally the behavior of `index.js` and `**/index.js` are the same,
// but includes require `**/`
const match_path = if (include.@"leading **/") entry_name else entry_subpath;
switch (glob.matchImpl(include.glob, match_path)) {
switch (glob.walk.matchImpl(include.glob, match_path)) {
.match => included = true,
.negate_no_match => included = false,

Expand Down Expand Up @@ -976,7 +976,7 @@ pub const PackCommand = struct {

// check default ignores that only apply to the root project directory
for (root_default_ignore_patterns) |pattern| {
switch (glob.matchImpl(pattern, entry_name)) {
switch (glob.walk.matchImpl(pattern, entry_name)) {
.match => {
// cannot be reversed
return .{
Expand All @@ -1003,7 +1003,7 @@ pub const PackCommand = struct {

for (default_ignore_patterns) |pattern_info| {
const pattern, const can_override = pattern_info;
switch (glob.matchImpl(pattern, entry_name)) {
switch (glob.walk.matchImpl(pattern, entry_name)) {
.match => {
if (can_override) {
ignored = true;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ pub const PackCommand = struct {
if (pattern.dirs_only and entry.kind != .directory) continue;

const match_path = if (pattern.rel_path) rel else entry_name;
switch (glob.matchImpl(pattern.glob, match_path)) {
switch (glob.walk.matchImpl(pattern.glob, match_path)) {
.match => {
ignored = true;
ignore_pattern = pattern.glob;
Expand Down
Loading

0 comments on commit acb9fdf

Please sign in to comment.