rn-branch-guard 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +63 -0
- package/package.json +19 -0
- package/readme.md +22 -0
- package/templates/post-checkout +11 -0
package/bin/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { execSync } = require("child_process");
|
|
6
|
+
|
|
7
|
+
const projectRoot = process.cwd();
|
|
8
|
+
const hooksDir = path.join(projectRoot, ".githooks");
|
|
9
|
+
const templateHook = path.join(__dirname, "..", "templates", "post-checkout");
|
|
10
|
+
const targetHook = path.join(hooksDir, "post-checkout");
|
|
11
|
+
|
|
12
|
+
function log(message) {
|
|
13
|
+
console.log(`[rn-branch-guard] ${message}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function ensureGitRepository() {
|
|
17
|
+
try {
|
|
18
|
+
execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
|
|
19
|
+
} catch {
|
|
20
|
+
log("This directory is not a Git repository.");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function ensureHooksDirectory() {
|
|
26
|
+
if (!fs.existsSync(hooksDir)) {
|
|
27
|
+
fs.mkdirSync(hooksDir, { recursive: true });
|
|
28
|
+
log("Created .githooks directory.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function ensureTemplateExists() {
|
|
33
|
+
if (!fs.existsSync(templateHook)) {
|
|
34
|
+
log(`Template file not found: ${templateHook}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function installHook() {
|
|
40
|
+
fs.copyFileSync(templateHook, targetHook);
|
|
41
|
+
log("Installed post-checkout hook.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function setHooksPath() {
|
|
45
|
+
try {
|
|
46
|
+
execSync("git config core.hooksPath .githooks", { stdio: "ignore" });
|
|
47
|
+
log("Configured Git hooks path to .githooks.");
|
|
48
|
+
} catch {
|
|
49
|
+
log("Failed to set Git hooks path.");
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function main() {
|
|
55
|
+
ensureGitRepository();
|
|
56
|
+
ensureHooksDirectory();
|
|
57
|
+
ensureTemplateExists();
|
|
58
|
+
installHook();
|
|
59
|
+
setHooksPath();
|
|
60
|
+
log("Setup complete.");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rn-branch-guard",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Install a Git post-checkout hook that warns when dependency files change between branches.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"rn-branch-guard": "bin/index.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin",
|
|
10
|
+
"templates"
|
|
11
|
+
],
|
|
12
|
+
"keywords": [
|
|
13
|
+
"react-native",
|
|
14
|
+
"expo",
|
|
15
|
+
"git-hooks",
|
|
16
|
+
"cli"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT"
|
|
19
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# rn-branch-guard
|
|
2
|
+
|
|
3
|
+
A tiny CLI that installs a Git `post-checkout` hook to warn you when dependency files change between branches.
|
|
4
|
+
|
|
5
|
+
## Why?
|
|
6
|
+
|
|
7
|
+
When switching branches in React Native / Expo projects, dependency files may change while your installed packages remain outdated. This often causes confusing build or runtime errors.
|
|
8
|
+
|
|
9
|
+
`rn-branch-guard` helps by showing a warning after checkout when files like these change:
|
|
10
|
+
|
|
11
|
+
- `package.json`
|
|
12
|
+
- `package-lock.json`
|
|
13
|
+
- `yarn.lock`
|
|
14
|
+
- `pnpm-lock.yaml`
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Run this inside your project:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx rn-branch-guard
|
|
22
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
CHANGED=$(git diff --name-only HEAD@{1} HEAD | grep -E "package.json|package-lock.json|yarn.lock|pnpm-lock.yaml")
|
|
4
|
+
|
|
5
|
+
if [ -n "$CHANGED" ]; then
|
|
6
|
+
echo ""
|
|
7
|
+
echo "📦 Dependency files changed between branches."
|
|
8
|
+
echo "⚠️ Run your package manager install command."
|
|
9
|
+
echo " Examples: npm install / yarn install / pnpm install"
|
|
10
|
+
echo ""
|
|
11
|
+
fi
|