support bun link of scoped packages (#1892)

This commit is contained in:
Alex Lam S.L
2023-01-24 21:52:47 +02:00
committed by GitHub
parent 2edbf4d0ec
commit e47fe2ca00
3 changed files with 215 additions and 4 deletions

View File

@@ -2653,7 +2653,7 @@ pub const PackageManager = struct {
};
const not_found_fmt =
\\package \"{[name]s}\" is not linked
\\package "{[name]s}" is not linked
\\
\\To install a linked package:
\\ <cyan>bun link my-pkg-name-from-package-json<r>
@@ -4491,6 +4491,18 @@ pub const PackageManager = struct {
// delete it if it exists
node_modules.dir.deleteTree(name) catch {};
// create scope if specified
if (name[0] == '@') {
if (std.mem.indexOfScalar(u8, name, '/')) |i| {
node_modules.dir.makeDir(name[0..i]) catch |err| brk: {
if (err == error.PathAlreadyExists) break :brk;
if (manager.options.log_level != .silent)
Output.prettyErrorln("<r><red>error:<r> failed to create scope in global dir due to error {s}", .{@errorName(err)});
Global.crash();
};
}
}
// create the symlink
node_modules.dir.symLink(Fs.FileSystem.instance.topLevelDirWithoutTrailingSlash(), name, .{ .is_directory = true }) catch |err| {
if (manager.options.log_level != .silent)