@simbo/find-git-repository-root 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @simbo/find-git-repository-root
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - d1e7d92: Initial Release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [5092b1b]
12
+ - @simbo/is-git-repository-root@1.0.0
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2025 Simon Lepel <simbo@simbo.de> (https://simbo.de)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Find Git Repository Root
2
+
3
+ [📦 **`@simbo/find-git-repository-root`**](https://npmjs.com/package/@simbo/find-git-repository-root)
4
+
5
+ A lightweight utility for locating the **root directory of a Git repository**.
6
+
7
+ It searches upward from a given directory until it finds a valid repository root
8
+ (a directory containing a `.git `folder).
9
+
10
+ This package builds on [find-up](https://npmjs.com/package/find-up) and
11
+ [`@simbo/is-git-repository-root`](https://npmjs.com/package/@simbo/is-git-repository-root).
12
+
13
+ ## Features
14
+
15
+ - Detects the **root directory** of a Git repository
16
+
17
+ - Returns the absolute path to the Git repository root
18
+
19
+ - Uses upward search from a given working directory (defaults to
20
+ `process.cwd()`)
21
+
22
+ - Async and Promise-based API
23
+
24
+ - Fully typed with TypeScript
25
+
26
+ ## Installation
27
+
28
+ Install `@simbo/find-git-repository-root` from the npm registry:
29
+
30
+ ```bash
31
+ npm i [-D] @simbo/find-git-repository-root
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ For a complete API reference, see the
37
+ [documentation](https://simbo.codes/packages/modules/_simbo_find-git-repository-root/).
38
+
39
+ ### Example
40
+
41
+ ```ts
42
+ import { findGitRepositoryRoot } from '@simbo/find-git-repository-root';
43
+
44
+ // Default: start from current working directory
45
+ const root = await findGitRepositoryRoot();
46
+
47
+ // Or specify a starting directory
48
+ const rootFromPath = await findGitRepositoryRoot('/path/to/subdir');
49
+ ```
50
+
51
+ If no Git repository root is found, the function resolves to `undefined`.
52
+
53
+ ## License
54
+
55
+ [MIT © Simon Lepel](http://simbo.mit-license.org/2025/)
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Finds the root directory of a Git repository by searching upwards from the given working directory.
3
+ *
4
+ * It uses `@simbo/is-git-repository-root` to check if a directory is a Git repository root.
5
+ *
6
+ * @param workingDir - The directory from which to start searching for the Git root. Defaults to the current working directory.
7
+ * @returns A promise that resolves to the path of the Git repository root, or undefined if not found.
8
+ */
9
+ export declare function findGitRepositoryRoot(workingDir?: string): Promise<string | undefined>;
@@ -0,0 +1,16 @@
1
+ import { cwd } from 'node:process';
2
+ import { isGitRepositoryRoot } from '@simbo/is-git-repository-root';
3
+ import { findUp } from 'find-up';
4
+ /**
5
+ * Finds the root directory of a Git repository by searching upwards from the given working directory.
6
+ *
7
+ * It uses `@simbo/is-git-repository-root` to check if a directory is a Git repository root.
8
+ *
9
+ * @param workingDir - The directory from which to start searching for the Git root. Defaults to the current working directory.
10
+ * @returns A promise that resolves to the path of the Git repository root, or undefined if not found.
11
+ */
12
+ export async function findGitRepositoryRoot(workingDir = cwd()) {
13
+ const matcher = async (path) => (await isGitRepositoryRoot(path)) ? path : undefined;
14
+ return findUp(matcher, { cwd: workingDir, type: 'directory' });
15
+ }
16
+ //# sourceMappingURL=find-git-repository-root.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-git-repository-root.js","sourceRoot":"","sources":["../src/find-git-repository-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,UAAU,GAAG,GAAG,EAAE;IAC5D,MAAM,OAAO,GAAG,KAAK,EAAE,IAAY,EAA+B,EAAE,CAClE,CAAC,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACvD,OAAO,MAAM,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@simbo/find-git-repository-root",
3
+ "description": "A lightweight utility for locating the root directory of a Git repository.",
4
+ "version": "1.0.0",
5
+ "keywords": [
6
+ "git",
7
+ "repository",
8
+ "root",
9
+ "find",
10
+ "detect",
11
+ "git-root",
12
+ "is-root",
13
+ "directory",
14
+ "path",
15
+ "utility",
16
+ "typescript"
17
+ ],
18
+ "author": "Simon Lepel <simbo@simbo.de> (https://simbo.de/)",
19
+ "license": "MIT",
20
+ "homepage": "http://github.com/simbo/packages/tree/main/packages/find-git-repository-root",
21
+ "repository": "github:simbo/packages",
22
+ "bugs": "https://github.com/simbo/packages/issues",
23
+ "engines": {
24
+ "node": ">=20"
25
+ },
26
+ "type": "module",
27
+ "exports": {
28
+ ".": "./dist/find-git-repository-root.js"
29
+ },
30
+ "files": [
31
+ "CHANGELOG.md",
32
+ "dist",
33
+ "LICENSE.md",
34
+ "README.md"
35
+ ],
36
+ "dependencies": {
37
+ "find-up": "^7.0.0",
38
+ "@simbo/is-git-repository-root": "1.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@ianvs/prettier-plugin-sort-imports": "^4.6.2",
42
+ "@types/node": "^20.19.11",
43
+ "@vitest/coverage-v8": "^3.2.4",
44
+ "@vitest/ui": "^3.2.4",
45
+ "eslint": "^9.34.0",
46
+ "jiti": "^2.5.1",
47
+ "prettier": "^3.6.2",
48
+ "prettier-plugin-organize-attributes": "^1.0.0",
49
+ "typescript": "^5.9.2",
50
+ "vitest": "^3.2.4",
51
+ "@simbo/eslint-config": "1.0.2",
52
+ "@simbo/prettier-config": "1.0.3",
53
+ "@simbo/tsconfig": "1.0.3"
54
+ },
55
+ "scripts": {
56
+ "build": "tsc --project tsconfig.build.json",
57
+ "check:eslint": "eslint --config ./eslint.config.ts --max-warnings 0",
58
+ "check:format": "prettier --check .",
59
+ "check:types": "tsc --noEmit",
60
+ "clean:dist": "rm -rf dist",
61
+ "fix:eslint": "pnpm run check:eslint --fix",
62
+ "fix:format": "prettier --write .",
63
+ "test": "vitest run --coverage",
64
+ "test:ui": "pnpm run test:watch --ui",
65
+ "test:watch": "vitest dev --coverage"
66
+ }
67
+ }