Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement glob support for workspace names in bun install #1918

Closed
Tracked by #2450
Jarred-Sumner opened this issue Jan 28, 2023 · 7 comments · Fixed by #10462
Closed
Tracked by #2450

Implement glob support for workspace names in bun install #1918

Jarred-Sumner opened this issue Jan 28, 2023 · 7 comments · Fixed by #10462
Assignees
Labels
atw bun install Something that relates to the npm-compatible client enhancement New feature or request

Comments

@Jarred-Sumner
Copy link
Collaborator

We can likely use @The-King-of-Toasters' globlin for matching globs. The main question there is if we could somehow make it an iterator while respecting things like negative matching patterns.

The code is here:

bun/src/install/lockfile.zig

Lines 2711 to 2740 in 8d622ad

var workspace_dir = std.fs.cwd().openIterableDir(path, .{}) catch |err| {
if (err == error.FileNotFound) {
log.addErrorFmt(
&source,
item.loc,
allocator,
"Workspace not found \"{s}\" in \"{s}\"",
.{
path,
std.os.getcwd(allocator.alloc(u8, bun.MAX_PATH_BYTES) catch unreachable) catch unreachable,
},
) catch {};
} else log.addErrorFmt(
&source,
item.loc,
allocator,
"{s} opening workspace package \"{s}\" from \"{s}\"",
.{
@errorName(err),
path,
std.os.getcwd(allocator.alloc(u8, bun.MAX_PATH_BYTES) catch unreachable) catch unreachable,
},
) catch {};
workspace_names[i] = "";
// report errors for multiple workspaces
continue;
};
defer workspace_dir.close();
var workspace_file = workspace_dir.dir.openFile("package.json", .{ .mode = .read_only }) catch |err| {

There are three changes to make there:

  1. When there is a glob to match against (any workspace name contains either a "*" or a "{" character or a "!" character), we instead allocate all the workspaces name patterns into a temporary string array and then iterate through each one
  2. The current code path which only supports exact names should continue to exist only when there are no workspace names with glob-like patterns. Ideally we could still make it work with this code path if you specify just a directory name like "packages/" (note the trailing slash) or "packages/*".
  3. The current code path should be modified to only open the package.json for the directory directly, rather than open the directory for the worskpace then open the package.json then close the directory. It is inefficient to open directories unnecessarily.
@Electroid Electroid added enhancement New feature or request bun install Something that relates to the npm-compatible client labels Jan 28, 2023
@Jarred-Sumner
Copy link
Collaborator Author

A limited version of this is available in Bun v0.5.8. Just a trailing /* is implemented.

@Kleywalker
Copy link

Are there any plans to implement multi level globs? I use bun in a complex monorepo. The limited version with trailing /* gets quite confusing pretty fast.

@denieler
Copy link

denieler commented Dec 4, 2023

This is absolutely necessary feature 🙇‍♂️

@andyjessop
Copy link

I have an nx repo and I'm just converting to bun, but this is currently a deal-breaker. I have nested folders inside, e.g. packages/, but I cannot access them with global nx commands without using a pattern like packages/**/*. But if I use that then Bun won't install anything. Is there a way to ignore this error?

@Kleywalker
Copy link

Are there any news on this topic yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
atw bun install Something that relates to the npm-compatible client enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@Jarred-Sumner @andyjessop @denieler @Electroid @Kleywalker @zackradisic and others