Skip to content

Commit 5b93869

Browse files
committed
feat: use a BREWLOCK env variable to locate your brew.lock
1 parent bcd9068 commit 5b93869

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
### Homebrew (recommended)
2121

2222
```bash
23-
brew tap shipworthyai/brewlock
23+
brew tap shipworthyai/brewlock https://github.com/ShipWorthyAI/brewlock.git
2424
brew install brewlock
2525
```
2626

@@ -66,7 +66,7 @@ After adding the alias, restart your shell or run `source ~/.zshrc` (or equivale
6666

6767
```bash
6868
# Install brewlock
69-
brew tap shipworthyai/brewlock
69+
brew tap shipworthyai/brewlock https://github.com/ShipWorthyAI/brewlock.git
7070
brew install brewlock
7171

7272
# Set up the alias (add to your ~/.zshrc)
@@ -111,7 +111,11 @@ brew bundle install # Installs from brew.lock with version checking
111111
### Syncing Across Machines
112112

113113
```bash
114-
# On your main machine: commit your brew.lock to your dotfiles
114+
# Option 1: Point BREWLOCK directly to your dotfiles (recommended)
115+
# Add to your shell config (~/.zshrc or ~/.bashrc):
116+
export BREWLOCK="$HOME/dotfiles/brew.lock"
117+
118+
# Option 2: Copy (or symlink) the lock file to your dotfiles
115119
cp ~/brew.lock ~/dotfiles/
116120
cd ~/dotfiles && git add brew.lock && git commit -m "Update brew.lock"
117121

@@ -122,7 +126,17 @@ brew bundle install
122126

123127
## The `brew.lock` File
124128

125-
The lock file is stored at `~/brew.lock` (in your home directory) and uses standard Brewfile syntax with added version information:
129+
By default, the lock file is stored at `~/brew.lock` (in your home directory). You can customize this location using the `BREWLOCK` environment variable:
130+
131+
```bash
132+
# Set a custom lock file path
133+
export BREWLOCK=/path/to/your/brew.lock
134+
135+
# Example: Store in your dotfiles repo
136+
export BREWLOCK="$HOME/dotfiles/brew.lock"
137+
```
138+
139+
The lock file uses standard Brewfile syntax with added version information:
126140

127141
```ruby
128142
# brewlock v1

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "brewlock",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"module": "src/index.ts",
55
"type": "module",
66
"bin": {

src/index.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { bundleInstall } from "./bundle-install.ts";
1111
import { executeBrewCommandStreaming } from "./executor.ts";
1212
import {
1313
checkLockFile,
14-
DEFAULT_LOCK_FILE,
1514
generateLockFile,
15+
getLockFilePath,
1616
readLockFile,
1717
removeEntry,
1818
upsertEntry,
@@ -28,6 +28,7 @@ export {
2828
checkLockFile,
2929
DEFAULT_LOCK_FILE,
3030
generateLockFile,
31+
getLockFilePath,
3132
parseLockFile,
3233
readLockFile,
3334
removeEntry,
@@ -97,6 +98,10 @@ EXAMPLES:
9798
brewlock check Verify installed versions match brew.lock
9899
brewlock bundle install Install from Brewfile using version constraints
99100
101+
ENVIRONMENT VARIABLES:
102+
BREWLOCK Path to the lock file (default: ~/brew.lock)
103+
Example: export BREWLOCK=/path/to/your/brew.lock
104+
100105
FILES:
101106
brew.lock Lock file in Brewfile format with version information
102107
`);
@@ -108,10 +113,11 @@ FILES:
108113
async function handleLock(): Promise<void> {
109114
console.log("Generating brew.lock from installed packages...");
110115

116+
const lockFilePath = getLockFilePath();
111117
const lockFile = await generateLockFile();
112-
await writeLockFile(lockFile, DEFAULT_LOCK_FILE);
118+
await writeLockFile(lockFile, lockFilePath);
113119

114-
console.log(`\nGenerated ${DEFAULT_LOCK_FILE} with:`);
120+
console.log(`\nGenerated ${lockFilePath} with:`);
115121
console.log(
116122
` - ${lockFile.entries.filter((e) => e.type === "tap").length} taps`
117123
);
@@ -132,7 +138,7 @@ async function handleLock(): Promise<void> {
132138
async function handleCheck(): Promise<void> {
133139
console.log("Checking installed packages against brew.lock...");
134140

135-
const result = await checkLockFile(DEFAULT_LOCK_FILE);
141+
const result = await checkLockFile(getLockFilePath());
136142

137143
if (result.matches) {
138144
console.log("\n✓ All installed packages match brew.lock");
@@ -155,7 +161,8 @@ async function updateLockFile(
155161
packages: string[],
156162
isCask: boolean
157163
): Promise<void> {
158-
let lockFile = await readLockFile(DEFAULT_LOCK_FILE);
164+
const lockFilePath = getLockFilePath();
165+
let lockFile = await readLockFile(lockFilePath);
159166
const type: PackageType = isCask ? "cask" : "brew";
160167

161168
if (
@@ -203,7 +210,7 @@ async function updateLockFile(
203210
}
204211
}
205212

206-
await writeLockFile(lockFile, DEFAULT_LOCK_FILE);
213+
await writeLockFile(lockFile, lockFilePath);
207214
}
208215

209216
/**
@@ -215,7 +222,7 @@ async function handleBundleInstall(): Promise<boolean> {
215222
);
216223

217224
const success = await bundleInstall({
218-
lockFilePath: DEFAULT_LOCK_FILE,
225+
lockFilePath: getLockFilePath(),
219226
verbose: true,
220227
});
221228

src/lock-manager.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ import {
1717
/** Default lock file path */
1818
export const DEFAULT_LOCK_FILE = join(homedir(), "brew.lock");
1919

20+
/**
21+
* Get the lock file path, checking the BREWLOCK environment variable first.
22+
* Falls back to DEFAULT_LOCK_FILE if not set.
23+
*/
24+
export function getLockFilePath(): string {
25+
const envPath = process.env.BREWLOCK;
26+
if (envPath) {
27+
return envPath;
28+
}
29+
return DEFAULT_LOCK_FILE;
30+
}
31+
2032
/** Lock file format version */
2133
const LOCK_VERSION = 1;
2234

0 commit comments

Comments
 (0)