LinuxCommandLibrary

bun-link

Link local packages for development

TLDR

Link the package globally

$ bun link
copy

Link a package locally to a project
$ bun link [package_name]
copy

Link directly from a local path
$ bun link [path/to/package]
copy

Unlink a package
$ bun unlink [package_name]
copy

Unlink a global package
$ bun unlink --global [package_name]
copy

Display help
$ bun link --help
copy

SYNOPSIS

bun link [<package-dir>]

PARAMETERS

<package-dir>
    Optional. The path to the package directory that you want to link globally. If this argument is omitted, bun link will default to linking the current working directory.

DESCRIPTION

bun link is a command provided by the Bun JavaScript runtime, designed to facilitate local development of packages and libraries. It works by creating a symbolic link from Bun's global package link directory to a specified local package directory. This mechanism allows other projects that depend on the linked package to resolve it to your local version, rather than fetching it from a remote registry or relying on a published version.

This functionality is crucial for developers working on multiple interdependent packages, such as in a monorepo setup, or when developing a library and testing its changes directly within a consuming application. It enables rapid iteration and testing without the need to publish new versions or manage complex local path configurations. Essentially, bun link provides an efficient way to simulate a globally installed package using your local, work-in-progress code.

While sharing conceptual similarities with npm link and pnpm link, bun link is integrated into Bun's high-performance ecosystem, leveraging its fast module resolution and file system operations.

CAVEATS

bun link requires the Bun runtime to be installed on your system.
This command is primarily for local development and prototyping; it should not be used for managing dependencies in production environments.
Be mindful of potential version conflicts or unexpected behavior if multiple projects link different versions of the same package globally.
To remove a globally linked package, you typically use the bun unlink command.

PURPOSE OF LOCAL LINKING

The primary purpose of local linking is to enable developers to iterate on changes in a package or library and immediately test those changes within a consuming application without the overhead of publishing or repeatedly installing local path dependencies. It streamlines the development workflow for interdependent projects.

GLOBAL LINK DIRECTORY

When bun link is executed, it typically creates a symbolic link within Bun's internal global link directory (e.g., often located in a user's home directory under a .bun configuration path). This central location allows other projects managed by Bun to easily discover and use the locally linked package.

HISTORY

The bun link command has been a core feature of the Bun JavaScript runtime since its early development stages. It was included to ensure Bun provided a complete and ergonomic developer experience, mirroring essential functionalities found in other modern JavaScript package managers. Its development reflects Bun's commitment to offering high-performance alternatives for common Node.js and npm workflows, focusing on speed and a native-like feel for package management operations.

SEE ALSO

bun install (Bun command), bun unlink (Bun command), ln(1), npm-link(1), pnpm-link(1)

Copied to clipboard