@simbo/git-refs 0.0.0-stage → 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 +17 -0
- package/LICENSE.md +20 -0
- package/README.md +116 -2
- package/dist/find-ref-name-problem.d.ts +14 -0
- package/dist/find-ref-name-problem.js +65 -0
- package/dist/find-ref-name-problem.js.map +1 -0
- package/dist/git-ref-name-error.d.ts +23 -0
- package/dist/git-ref-name-error.js +27 -0
- package/dist/git-ref-name-error.js.map +1 -0
- package/dist/git-refs-constants.d.ts +21 -0
- package/dist/git-refs-constants.js +22 -0
- package/dist/git-refs-constants.js.map +1 -0
- package/dist/git-refs.types.d.ts +86 -0
- package/dist/git-refs.types.js +2 -0
- package/dist/git-refs.types.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/parse-ref.d.ts +11 -0
- package/dist/parse-ref.js +26 -0
- package/dist/parse-ref.js.map +1 -0
- package/dist/ref-name.d.ts +18 -0
- package/dist/ref-name.js +26 -0
- package/dist/ref-name.js.map +1 -0
- package/package.json +64 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @simbo/git-refs
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 4e9a630: Add package `@simbo/git-refs` to validate Git ref names, parse refs
|
|
8
|
+
and provide the common ref prefixes.
|
|
9
|
+
|
|
10
|
+
- `findRefNameProblem()`, `isValidRefName()` and `assertRefName()` check names
|
|
11
|
+
by the rules of `git check-ref-format`, with the options `allowOneLevel` and
|
|
12
|
+
`branch`, and report a `reason` such as `double-dot` or `trailing-slash`.
|
|
13
|
+
- `parseRef()` splits a full ref into its type (`branch`, `tag`, `remote`,
|
|
14
|
+
`pull` or `other`) and the name below its prefix.
|
|
15
|
+
- The constants `GIT_REFS_PREFIX`, `GIT_REFS_HEADS_PREFIX`,
|
|
16
|
+
`GIT_REFS_TAGS_PREFIX`, `GIT_REFS_REMOTES_PREFIX` and
|
|
17
|
+
`GIT_REFS_PULL_PREFIX`.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2026 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
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Git Refs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
📦 [**`@simbo/git-refs`**](https://npmjs.com/package/@simbo/git-refs)
|
|
4
|
+
|
|
5
|
+
Validates Git ref names by the rules of `git check-ref-format`, splits refs such
|
|
6
|
+
as `refs/tags/v1.2.3` into their type and name, and provides the common ref
|
|
7
|
+
prefixes.
|
|
8
|
+
|
|
9
|
+
Made for tools that build or accept branch and tag names and want to reject what
|
|
10
|
+
Git would reject, before running Git.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- The rules of `git check-ref-format`, with the options `allowOneLevel` and
|
|
15
|
+
`branch`, tested against Git itself
|
|
16
|
+
|
|
17
|
+
- A machine-readable `reason` and a readable message for every problem
|
|
18
|
+
|
|
19
|
+
- `parseRef()` for branches, tags, remote-tracking branches and the pull request
|
|
20
|
+
refs of GitHub
|
|
21
|
+
|
|
22
|
+
- No dependencies, no Git at runtime
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
Requires Node.js `^24.15.0 || >=26.0.0`.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
Install `@simbo/git-refs` from the npm registry:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm i @simbo/git-refs
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
For a complete API reference, see the
|
|
39
|
+
[documentation](https://simbo.de/packages/modules/_simbo_git-refs/).
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import {
|
|
43
|
+
assertRefName,
|
|
44
|
+
findRefNameProblem,
|
|
45
|
+
GIT_REFS_TAGS_PREFIX,
|
|
46
|
+
isValidRefName,
|
|
47
|
+
parseRef,
|
|
48
|
+
} from '@simbo/git-refs';
|
|
49
|
+
|
|
50
|
+
isValidRefName('refs/tags/v1.2.3'); // true
|
|
51
|
+
isValidRefName('main', { branch: true }); // true
|
|
52
|
+
isValidRefName('HEAD', { allowOneLevel: true }); // true
|
|
53
|
+
|
|
54
|
+
findRefNameProblem(`${GIT_REFS_TAGS_PREFIX}v1..2`);
|
|
55
|
+
// { reason: 'double-dot', message: 'contains ".."' }
|
|
56
|
+
|
|
57
|
+
assertRefName('refs/heads/feature/'); // throws a GitRefNameError
|
|
58
|
+
|
|
59
|
+
parseRef('refs/pull/123/merge');
|
|
60
|
+
// { ref: 'refs/pull/123/merge', type: 'pull', name: '123/merge' }
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Ref Names
|
|
64
|
+
|
|
65
|
+
`findRefNameProblem()` returns the first problem or `undefined`;
|
|
66
|
+
`isValidRefName()` returns a boolean; `assertRefName()` throws a
|
|
67
|
+
`GitRefNameError` with `refName` and `reason`.
|
|
68
|
+
|
|
69
|
+
| Reason | Git does not allow |
|
|
70
|
+
| ----------------------- | ---------------------------------------------------------------- |
|
|
71
|
+
| `empty` | an empty name |
|
|
72
|
+
| `at-sign` | the name `@` |
|
|
73
|
+
| `forbidden-character` | control characters, spaces, `~`, `^`, `:`, `?`, `*`, `[` and `\` |
|
|
74
|
+
| `double-dot` | `..` |
|
|
75
|
+
| `at-brace` | `@{` |
|
|
76
|
+
| `leading-slash` | a leading `/` |
|
|
77
|
+
| `trailing-slash` | a trailing `/` |
|
|
78
|
+
| `double-slash` | `//` |
|
|
79
|
+
| `trailing-dot` | a trailing `.` |
|
|
80
|
+
| `component-leading-dot` | a path component that starts with `.` |
|
|
81
|
+
| `component-lock-suffix` | a path component that ends with `.lock` |
|
|
82
|
+
| `one-level` | a name without `/`, unless `allowOneLevel` is set |
|
|
83
|
+
| `leading-dash` | a branch name that starts with `-` (`branch`) |
|
|
84
|
+
| `head` | the branch name `HEAD` (`branch`) |
|
|
85
|
+
|
|
86
|
+
The options follow `git check-ref-format`:
|
|
87
|
+
|
|
88
|
+
- Without options, the name is a full ref name such as `refs/heads/main`, which
|
|
89
|
+
must contain a `/`.
|
|
90
|
+
- `allowOneLevel`, like `--allow-onelevel`, also accepts names like `HEAD`.
|
|
91
|
+
- `branch`, like `--branch`, checks a short branch name such as `main` as
|
|
92
|
+
`refs/heads/<name>`; it must neither start with `-` nor be `HEAD`. Unlike
|
|
93
|
+
`git check-ref-format --branch`, it does not expand `@{-1}`.
|
|
94
|
+
|
|
95
|
+
To check a tag name such as `v1.2.3`, check the full ref:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
isValidRefName(`${GIT_REFS_TAGS_PREFIX}${tag}`);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Refs
|
|
102
|
+
|
|
103
|
+
`parseRef()` splits a full ref into its `type` and the `name` below its prefix.
|
|
104
|
+
It returns `undefined` for anything that does not start with `refs/` or has no
|
|
105
|
+
name below its prefix, and does not validate the name.
|
|
106
|
+
|
|
107
|
+
| Type | Prefix | Constant | Example |
|
|
108
|
+
| -------- | --------------- | ------------------------- | -------------------------- |
|
|
109
|
+
| `branch` | `refs/heads/` | `GIT_REFS_HEADS_PREFIX` | `refs/heads/main` |
|
|
110
|
+
| `tag` | `refs/tags/` | `GIT_REFS_TAGS_PREFIX` | `refs/tags/v1.2.3` |
|
|
111
|
+
| `remote` | `refs/remotes/` | `GIT_REFS_REMOTES_PREFIX` | `refs/remotes/origin/main` |
|
|
112
|
+
| `pull` | `refs/pull/` | `GIT_REFS_PULL_PREFIX` | `refs/pull/123/merge` |
|
|
113
|
+
| `other` | `refs/` | `GIT_REFS_PREFIX` | `refs/notes/commits` |
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
[MIT © Simon Lepel](https://simbo.mit-license.org/2026/)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RefNameOptions, RefNameProblem } from './git-refs.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks a ref name by the rules of `git check-ref-format` and returns the
|
|
4
|
+
* first problem.
|
|
5
|
+
*
|
|
6
|
+
* Without options, the name is a full ref name such as `refs/tags/v1.2.3`,
|
|
7
|
+
* which must contain a `/`. With `allowOneLevel`, names like `HEAD` are
|
|
8
|
+
* accepted. With `branch`, the name is a short branch name such as `main`.
|
|
9
|
+
*
|
|
10
|
+
* @param name - The ref name.
|
|
11
|
+
* @param options - Options like those of `git check-ref-format`.
|
|
12
|
+
* @returns The first problem, or `undefined` if Git allows the name.
|
|
13
|
+
*/
|
|
14
|
+
export declare function findRefNameProblem(name: string, options?: RefNameOptions): RefNameProblem | undefined;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GIT_REFS_HEADS_PREFIX } from './git-refs-constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Characters that Git does not allow in ref names.
|
|
4
|
+
*/
|
|
5
|
+
// eslint-disable-next-line no-control-regex
|
|
6
|
+
const FORBIDDEN_CHARACTER = /[\u{0}-\u{20}\u{7F}~^:?*[\\]/u;
|
|
7
|
+
/**
|
|
8
|
+
* Checks a ref name by the rules of `git check-ref-format` and returns the
|
|
9
|
+
* first problem.
|
|
10
|
+
*
|
|
11
|
+
* Without options, the name is a full ref name such as `refs/tags/v1.2.3`,
|
|
12
|
+
* which must contain a `/`. With `allowOneLevel`, names like `HEAD` are
|
|
13
|
+
* accepted. With `branch`, the name is a short branch name such as `main`.
|
|
14
|
+
*
|
|
15
|
+
* @param name - The ref name.
|
|
16
|
+
* @param options - Options like those of `git check-ref-format`.
|
|
17
|
+
* @returns The first problem, or `undefined` if Git allows the name.
|
|
18
|
+
*/
|
|
19
|
+
export function findRefNameProblem(name, options = {}) {
|
|
20
|
+
if (options.branch === true) {
|
|
21
|
+
return findBranchProblem(name) ?? findRefNameProblem(`${GIT_REFS_HEADS_PREFIX}${name}`, { allowOneLevel: false });
|
|
22
|
+
}
|
|
23
|
+
const forbidden = FORBIDDEN_CHARACTER.exec(name)?.[0];
|
|
24
|
+
const components = name.split('/');
|
|
25
|
+
const checks = [
|
|
26
|
+
[name === '', 'empty', 'is empty'],
|
|
27
|
+
[name === '@', 'at-sign', 'is "@"'],
|
|
28
|
+
[forbidden !== undefined, 'forbidden-character', `contains ${JSON.stringify(forbidden)}`],
|
|
29
|
+
[name.includes('..'), 'double-dot', 'contains ".."'],
|
|
30
|
+
[name.includes('@{'), 'at-brace', 'contains "@{"'],
|
|
31
|
+
[name.startsWith('/'), 'leading-slash', 'starts with "/"'],
|
|
32
|
+
[name.endsWith('/'), 'trailing-slash', 'ends with "/"'],
|
|
33
|
+
[name.includes('//'), 'double-slash', 'contains "//"'],
|
|
34
|
+
[name.endsWith('.'), 'trailing-dot', 'ends with "."'],
|
|
35
|
+
[
|
|
36
|
+
components.some(component => component.startsWith('.')),
|
|
37
|
+
'component-leading-dot',
|
|
38
|
+
'has a path component that starts with "."',
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
components.some(component => component.endsWith('.lock')),
|
|
42
|
+
'component-lock-suffix',
|
|
43
|
+
'has a path component that ends with ".lock"',
|
|
44
|
+
],
|
|
45
|
+
[options.allowOneLevel !== true && !name.includes('/'), 'one-level', 'has no "/"'],
|
|
46
|
+
];
|
|
47
|
+
const problem = checks.find(([failed]) => failed);
|
|
48
|
+
return problem === undefined ? undefined : { reason: problem[1], message: problem[2] };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks the rules that only apply to short branch names.
|
|
52
|
+
*
|
|
53
|
+
* @param name - The branch name.
|
|
54
|
+
* @returns The problem, or `undefined`.
|
|
55
|
+
*/
|
|
56
|
+
function findBranchProblem(name) {
|
|
57
|
+
if (name === '')
|
|
58
|
+
return { reason: 'empty', message: 'is empty' };
|
|
59
|
+
if (name.startsWith('-'))
|
|
60
|
+
return { reason: 'leading-dash', message: 'starts with "-"' };
|
|
61
|
+
if (name === 'HEAD')
|
|
62
|
+
return { reason: 'head', message: 'is "HEAD"' };
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=find-ref-name-problem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-ref-name-problem.js","sourceRoot":"","sources":["../src/find-ref-name-problem.ts"],"names":[],"mappings":"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","sourcesContent":["import { GIT_REFS_HEADS_PREFIX } from './git-refs-constants.js';\nimport type { RefNameOptions, RefNameProblem, RefNameProblemReason } from './git-refs.types.js';\n\n/**\n * Characters that Git does not allow in ref names.\n */\n// eslint-disable-next-line no-control-regex\nconst FORBIDDEN_CHARACTER = /[\\u{0}-\\u{20}\\u{7F}~^:?*[\\\\]/u;\n\n/**\n * Checks a ref name by the rules of `git check-ref-format` and returns the\n * first problem.\n *\n * Without options, the name is a full ref name such as `refs/tags/v1.2.3`,\n * which must contain a `/`. With `allowOneLevel`, names like `HEAD` are\n * accepted. With `branch`, the name is a short branch name such as `main`.\n *\n * @param name - The ref name.\n * @param options - Options like those of `git check-ref-format`.\n * @returns The first problem, or `undefined` if Git allows the name.\n */\nexport function findRefNameProblem(name: string, options: RefNameOptions = {}): RefNameProblem | undefined {\n if (options.branch === true) {\n return findBranchProblem(name) ?? findRefNameProblem(`${GIT_REFS_HEADS_PREFIX}${name}`, { allowOneLevel: false });\n }\n const forbidden = FORBIDDEN_CHARACTER.exec(name)?.[0];\n const components = name.split('/');\n const checks: [boolean, RefNameProblemReason, string][] = [\n [name === '', 'empty', 'is empty'],\n [name === '@', 'at-sign', 'is \"@\"'],\n [forbidden !== undefined, 'forbidden-character', `contains ${JSON.stringify(forbidden)}`],\n [name.includes('..'), 'double-dot', 'contains \"..\"'],\n [name.includes('@{'), 'at-brace', 'contains \"@{\"'],\n [name.startsWith('/'), 'leading-slash', 'starts with \"/\"'],\n [name.endsWith('/'), 'trailing-slash', 'ends with \"/\"'],\n [name.includes('//'), 'double-slash', 'contains \"//\"'],\n [name.endsWith('.'), 'trailing-dot', 'ends with \".\"'],\n [\n components.some(component => component.startsWith('.')),\n 'component-leading-dot',\n 'has a path component that starts with \".\"',\n ],\n [\n components.some(component => component.endsWith('.lock')),\n 'component-lock-suffix',\n 'has a path component that ends with \".lock\"',\n ],\n [options.allowOneLevel !== true && !name.includes('/'), 'one-level', 'has no \"/\"'],\n ];\n const problem = checks.find(([failed]) => failed);\n return problem === undefined ? undefined : { reason: problem[1], message: problem[2] };\n}\n\n/**\n * Checks the rules that only apply to short branch names.\n *\n * @param name - The branch name.\n * @returns The problem, or `undefined`.\n */\nfunction findBranchProblem(name: string): RefNameProblem | undefined {\n if (name === '') return { reason: 'empty', message: 'is empty' };\n if (name.startsWith('-')) return { reason: 'leading-dash', message: 'starts with \"-\"' };\n if (name === 'HEAD') return { reason: 'head', message: 'is \"HEAD\"' };\n return undefined;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RefNameProblemReason } from './git-refs.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* An error thrown when Git does not allow a ref name.
|
|
4
|
+
*/
|
|
5
|
+
export declare class GitRefNameError extends Error {
|
|
6
|
+
readonly name = "GitRefNameError";
|
|
7
|
+
/**
|
|
8
|
+
* The ref name.
|
|
9
|
+
*/
|
|
10
|
+
readonly refName: string;
|
|
11
|
+
/**
|
|
12
|
+
* Why Git does not allow the name.
|
|
13
|
+
*/
|
|
14
|
+
readonly reason: RefNameProblemReason;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an error for a ref name.
|
|
17
|
+
*
|
|
18
|
+
* @param refName - The ref name.
|
|
19
|
+
* @param reason - Why Git does not allow the name.
|
|
20
|
+
* @param problem - What makes the name invalid, such as `contains ".."`.
|
|
21
|
+
*/
|
|
22
|
+
constructor(refName: string, reason: RefNameProblemReason, problem: string);
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error thrown when Git does not allow a ref name.
|
|
3
|
+
*/
|
|
4
|
+
export class GitRefNameError extends Error {
|
|
5
|
+
name = 'GitRefNameError';
|
|
6
|
+
/**
|
|
7
|
+
* The ref name.
|
|
8
|
+
*/
|
|
9
|
+
refName;
|
|
10
|
+
/**
|
|
11
|
+
* Why Git does not allow the name.
|
|
12
|
+
*/
|
|
13
|
+
reason;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an error for a ref name.
|
|
16
|
+
*
|
|
17
|
+
* @param refName - The ref name.
|
|
18
|
+
* @param reason - Why Git does not allow the name.
|
|
19
|
+
* @param problem - What makes the name invalid, such as `contains ".."`.
|
|
20
|
+
*/
|
|
21
|
+
constructor(refName, reason, problem) {
|
|
22
|
+
super(`Invalid Git ref name "${refName}": it ${problem}.`);
|
|
23
|
+
this.refName = refName;
|
|
24
|
+
this.reason = reason;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=git-ref-name-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-ref-name-error.js","sourceRoot":"","sources":["../src/git-ref-name-error.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACf,IAAI,GAAG,iBAAiB,CAAC;IAElD;;OAEG;IACa,OAAO,CAAS;IAEhC;;OAEG;IACa,MAAM,CAAuB;IAE7C;;;;;;OAMG;IACH,YAAmB,OAAe,EAAE,MAA4B,EAAE,OAAe;QAC/E,KAAK,CAAC,yBAAyB,OAAO,SAAS,OAAO,GAAG,CAAC,CAAC;QAC3D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF","sourcesContent":["import type { RefNameProblemReason } from './git-refs.types.js';\n\n/**\n * An error thrown when Git does not allow a ref name.\n */\nexport class GitRefNameError extends Error {\n public override readonly name = 'GitRefNameError';\n\n /**\n * The ref name.\n */\n public readonly refName: string;\n\n /**\n * Why Git does not allow the name.\n */\n public readonly reason: RefNameProblemReason;\n\n /**\n * Creates an error for a ref name.\n *\n * @param refName - The ref name.\n * @param reason - Why Git does not allow the name.\n * @param problem - What makes the name invalid, such as `contains \"..\"`.\n */\n public constructor(refName: string, reason: RefNameProblemReason, problem: string) {\n super(`Invalid Git ref name \"${refName}\": it ${problem}.`);\n this.refName = refName;\n this.reason = reason;\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prefix of all refs.
|
|
3
|
+
*/
|
|
4
|
+
export declare const GIT_REFS_PREFIX = "refs/";
|
|
5
|
+
/**
|
|
6
|
+
* The prefix of branches.
|
|
7
|
+
*/
|
|
8
|
+
export declare const GIT_REFS_HEADS_PREFIX = "refs/heads/";
|
|
9
|
+
/**
|
|
10
|
+
* The prefix of tags.
|
|
11
|
+
*/
|
|
12
|
+
export declare const GIT_REFS_TAGS_PREFIX = "refs/tags/";
|
|
13
|
+
/**
|
|
14
|
+
* The prefix of remote-tracking branches.
|
|
15
|
+
*/
|
|
16
|
+
export declare const GIT_REFS_REMOTES_PREFIX = "refs/remotes/";
|
|
17
|
+
/**
|
|
18
|
+
* The prefix of the pull request refs of GitHub, such as `refs/pull/123/merge`
|
|
19
|
+
* and `refs/pull/123/head`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const GIT_REFS_PULL_PREFIX = "refs/pull/";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The prefix of all refs.
|
|
3
|
+
*/
|
|
4
|
+
export const GIT_REFS_PREFIX = 'refs/';
|
|
5
|
+
/**
|
|
6
|
+
* The prefix of branches.
|
|
7
|
+
*/
|
|
8
|
+
export const GIT_REFS_HEADS_PREFIX = `${GIT_REFS_PREFIX}heads/`;
|
|
9
|
+
/**
|
|
10
|
+
* The prefix of tags.
|
|
11
|
+
*/
|
|
12
|
+
export const GIT_REFS_TAGS_PREFIX = `${GIT_REFS_PREFIX}tags/`;
|
|
13
|
+
/**
|
|
14
|
+
* The prefix of remote-tracking branches.
|
|
15
|
+
*/
|
|
16
|
+
export const GIT_REFS_REMOTES_PREFIX = `${GIT_REFS_PREFIX}remotes/`;
|
|
17
|
+
/**
|
|
18
|
+
* The prefix of the pull request refs of GitHub, such as `refs/pull/123/merge`
|
|
19
|
+
* and `refs/pull/123/head`.
|
|
20
|
+
*/
|
|
21
|
+
export const GIT_REFS_PULL_PREFIX = `${GIT_REFS_PREFIX}pull/`;
|
|
22
|
+
//# sourceMappingURL=git-refs-constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-refs-constants.js","sourceRoot":"","sources":["../src/git-refs-constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,eAAe,QAAQ,CAAC;AAEhE;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,eAAe,OAAO,CAAC;AAE9D;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,eAAe,UAAU,CAAC;AAEpE;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,eAAe,OAAO,CAAC","sourcesContent":["/**\n * The prefix of all refs.\n */\nexport const GIT_REFS_PREFIX = 'refs/';\n\n/**\n * The prefix of branches.\n */\nexport const GIT_REFS_HEADS_PREFIX = `${GIT_REFS_PREFIX}heads/`;\n\n/**\n * The prefix of tags.\n */\nexport const GIT_REFS_TAGS_PREFIX = `${GIT_REFS_PREFIX}tags/`;\n\n/**\n * The prefix of remote-tracking branches.\n */\nexport const GIT_REFS_REMOTES_PREFIX = `${GIT_REFS_PREFIX}remotes/`;\n\n/**\n * The prefix of the pull request refs of GitHub, such as `refs/pull/123/merge`\n * and `refs/pull/123/head`.\n */\nexport const GIT_REFS_PULL_PREFIX = `${GIT_REFS_PREFIX}pull/`;\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why Git does not allow a ref name.
|
|
3
|
+
*
|
|
4
|
+
* - `empty`: the name is empty
|
|
5
|
+
* - `at-sign`: the name is the single character `@`
|
|
6
|
+
* - `forbidden-character`: a control character, space, `~`, `^`, `:`, `?`, `*`, `[` or `\`
|
|
7
|
+
* - `double-dot`: `..`
|
|
8
|
+
* - `at-brace`: `@{`
|
|
9
|
+
* - `leading-slash`: the name starts with `/`
|
|
10
|
+
* - `trailing-slash`: the name ends with `/`
|
|
11
|
+
* - `double-slash`: `//`
|
|
12
|
+
* - `trailing-dot`: the name ends with `.`
|
|
13
|
+
* - `component-leading-dot`: a path component starts with `.`
|
|
14
|
+
* - `component-lock-suffix`: a path component ends with `.lock`
|
|
15
|
+
* - `one-level`: the name has no `/`, and one-level names are not allowed
|
|
16
|
+
* - `leading-dash`: a branch name starts with `-`
|
|
17
|
+
* - `head`: the branch name is `HEAD`
|
|
18
|
+
*/
|
|
19
|
+
export type RefNameProblemReason = 'empty' | 'at-sign' | 'forbidden-character' | 'double-dot' | 'at-brace' | 'leading-slash' | 'trailing-slash' | 'double-slash' | 'trailing-dot' | 'component-leading-dot' | 'component-lock-suffix' | 'one-level' | 'leading-dash' | 'head';
|
|
20
|
+
/**
|
|
21
|
+
* A reason why Git does not allow a ref name.
|
|
22
|
+
*/
|
|
23
|
+
export interface RefNameProblem {
|
|
24
|
+
/**
|
|
25
|
+
* Why Git does not allow the name.
|
|
26
|
+
*/
|
|
27
|
+
reason: RefNameProblemReason;
|
|
28
|
+
/**
|
|
29
|
+
* What makes the name invalid, to follow the name in a sentence, such as
|
|
30
|
+
* `contains ".."`.
|
|
31
|
+
*/
|
|
32
|
+
message: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The options for checking a ref name, like the options of
|
|
36
|
+
* `git check-ref-format`.
|
|
37
|
+
*/
|
|
38
|
+
export interface RefNameOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Whether to accept names without `/`, such as `HEAD`, like
|
|
41
|
+
* `--allow-onelevel`. Ignored for branches.
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
allowOneLevel?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the name is a short branch name, such as `main`, like `--branch`:
|
|
48
|
+
* it is checked as `refs/heads/<name>`, and must neither start with `-` nor
|
|
49
|
+
* be `HEAD`. Unlike `git check-ref-format --branch`, shorthands such as
|
|
50
|
+
* `@{-1}` are not expanded, because that needs a repository, so they are
|
|
51
|
+
* invalid.
|
|
52
|
+
*
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
branch?: boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The type of a ref, by its prefix.
|
|
59
|
+
*
|
|
60
|
+
* - `branch`: `refs/heads/…`
|
|
61
|
+
* - `tag`: `refs/tags/…`
|
|
62
|
+
* - `remote`: `refs/remotes/…`
|
|
63
|
+
* - `pull`: `refs/pull/…`, the pull request refs of GitHub
|
|
64
|
+
* - `other`: any other ref below `refs/`
|
|
65
|
+
*/
|
|
66
|
+
export type RefType = 'branch' | 'tag' | 'remote' | 'pull' | 'other';
|
|
67
|
+
/**
|
|
68
|
+
* A ref split into its type and the name below its prefix.
|
|
69
|
+
*/
|
|
70
|
+
export interface ParsedRef {
|
|
71
|
+
/**
|
|
72
|
+
* The full ref, such as `refs/tags/v1.2.3`.
|
|
73
|
+
*/
|
|
74
|
+
ref: string;
|
|
75
|
+
/**
|
|
76
|
+
* The type of the ref.
|
|
77
|
+
*/
|
|
78
|
+
type: RefType;
|
|
79
|
+
/**
|
|
80
|
+
* The name below the prefix of the type, such as `v1.2.3` for
|
|
81
|
+
* `refs/tags/v1.2.3`, `origin/main` for `refs/remotes/origin/main`,
|
|
82
|
+
* `123/merge` for `refs/pull/123/merge`, or the name below `refs/` for
|
|
83
|
+
* other refs.
|
|
84
|
+
*/
|
|
85
|
+
name: string;
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-refs.types.js","sourceRoot":"","sources":["../src/git-refs.types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Why Git does not allow a ref name.\n *\n * - `empty`: the name is empty\n * - `at-sign`: the name is the single character `@`\n * - `forbidden-character`: a control character, space, `~`, `^`, `:`, `?`, `*`, `[` or `\\`\n * - `double-dot`: `..`\n * - `at-brace`: `@{`\n * - `leading-slash`: the name starts with `/`\n * - `trailing-slash`: the name ends with `/`\n * - `double-slash`: `//`\n * - `trailing-dot`: the name ends with `.`\n * - `component-leading-dot`: a path component starts with `.`\n * - `component-lock-suffix`: a path component ends with `.lock`\n * - `one-level`: the name has no `/`, and one-level names are not allowed\n * - `leading-dash`: a branch name starts with `-`\n * - `head`: the branch name is `HEAD`\n */\nexport type RefNameProblemReason =\n | 'empty'\n | 'at-sign'\n | 'forbidden-character'\n | 'double-dot'\n | 'at-brace'\n | 'leading-slash'\n | 'trailing-slash'\n | 'double-slash'\n | 'trailing-dot'\n | 'component-leading-dot'\n | 'component-lock-suffix'\n | 'one-level'\n | 'leading-dash'\n | 'head';\n\n/**\n * A reason why Git does not allow a ref name.\n */\nexport interface RefNameProblem {\n /**\n * Why Git does not allow the name.\n */\n reason: RefNameProblemReason;\n\n /**\n * What makes the name invalid, to follow the name in a sentence, such as\n * `contains \"..\"`.\n */\n message: string;\n}\n\n/**\n * The options for checking a ref name, like the options of\n * `git check-ref-format`.\n */\nexport interface RefNameOptions {\n /**\n * Whether to accept names without `/`, such as `HEAD`, like\n * `--allow-onelevel`. Ignored for branches.\n *\n * @default false\n */\n allowOneLevel?: boolean;\n\n /**\n * Whether the name is a short branch name, such as `main`, like `--branch`:\n * it is checked as `refs/heads/<name>`, and must neither start with `-` nor\n * be `HEAD`. Unlike `git check-ref-format --branch`, shorthands such as\n * `@{-1}` are not expanded, because that needs a repository, so they are\n * invalid.\n *\n * @default false\n */\n branch?: boolean;\n}\n\n/**\n * The type of a ref, by its prefix.\n *\n * - `branch`: `refs/heads/…`\n * - `tag`: `refs/tags/…`\n * - `remote`: `refs/remotes/…`\n * - `pull`: `refs/pull/…`, the pull request refs of GitHub\n * - `other`: any other ref below `refs/`\n */\nexport type RefType = 'branch' | 'tag' | 'remote' | 'pull' | 'other';\n\n/**\n * A ref split into its type and the name below its prefix.\n */\nexport interface ParsedRef {\n /**\n * The full ref, such as `refs/tags/v1.2.3`.\n */\n ref: string;\n\n /**\n * The type of the ref.\n */\n type: RefType;\n\n /**\n * The name below the prefix of the type, such as `v1.2.3` for\n * `refs/tags/v1.2.3`, `origin/main` for `refs/remotes/origin/main`,\n * `123/merge` for `refs/pull/123/merge`, or the name below `refs/` for\n * other refs.\n */\n name: string;\n}\n"]}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AAExC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC","sourcesContent":["export * from './find-ref-name-problem.js';\nexport * from './git-ref-name-error.js';\nexport * from './git-refs-constants.js';\nexport type * from './git-refs.types.js';\nexport * from './parse-ref.js';\nexport * from './ref-name.js';\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ParsedRef } from './git-refs.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Splits a full ref into its type and the name below its prefix, such as
|
|
4
|
+
* `refs/tags/v1.2.3` into the type `tag` and the name `v1.2.3`.
|
|
5
|
+
*
|
|
6
|
+
* The ref is not validated; use `findRefNameProblem()` for that.
|
|
7
|
+
*
|
|
8
|
+
* @param ref - The full ref, such as `refs/heads/main`.
|
|
9
|
+
* @returns The parsed ref, or `undefined` if the ref does not start with `refs/` or has no name below its prefix.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseRef(ref: string): ParsedRef | undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GIT_REFS_HEADS_PREFIX, GIT_REFS_PREFIX, GIT_REFS_PULL_PREFIX, GIT_REFS_REMOTES_PREFIX, GIT_REFS_TAGS_PREFIX, } from './git-refs-constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* The prefixes of the ref types, most specific first.
|
|
4
|
+
*/
|
|
5
|
+
const PREFIXES = [
|
|
6
|
+
['branch', GIT_REFS_HEADS_PREFIX],
|
|
7
|
+
['tag', GIT_REFS_TAGS_PREFIX],
|
|
8
|
+
['remote', GIT_REFS_REMOTES_PREFIX],
|
|
9
|
+
['pull', GIT_REFS_PULL_PREFIX],
|
|
10
|
+
['other', GIT_REFS_PREFIX],
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* Splits a full ref into its type and the name below its prefix, such as
|
|
14
|
+
* `refs/tags/v1.2.3` into the type `tag` and the name `v1.2.3`.
|
|
15
|
+
*
|
|
16
|
+
* The ref is not validated; use `findRefNameProblem()` for that.
|
|
17
|
+
*
|
|
18
|
+
* @param ref - The full ref, such as `refs/heads/main`.
|
|
19
|
+
* @returns The parsed ref, or `undefined` if the ref does not start with `refs/` or has no name below its prefix.
|
|
20
|
+
*/
|
|
21
|
+
export function parseRef(ref) {
|
|
22
|
+
const match = PREFIXES.find(([, prefix]) => ref.startsWith(prefix));
|
|
23
|
+
const name = match === undefined ? '' : ref.slice(match[1].length);
|
|
24
|
+
return match === undefined || name === '' ? undefined : { ref, type: match[0], name };
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=parse-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-ref.js","sourceRoot":"","sources":["../src/parse-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AAGjC;;GAEG;AACH,MAAM,QAAQ,GAAiC;IAC7C,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACjC,CAAC,KAAK,EAAE,oBAAoB,CAAC;IAC7B,CAAC,QAAQ,EAAE,uBAAuB,CAAC;IACnC,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAC9B,CAAC,OAAO,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,MAAM,IAAI,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACnE,OAAO,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;AACxF,CAAC","sourcesContent":["import {\n GIT_REFS_HEADS_PREFIX,\n GIT_REFS_PREFIX,\n GIT_REFS_PULL_PREFIX,\n GIT_REFS_REMOTES_PREFIX,\n GIT_REFS_TAGS_PREFIX,\n} from './git-refs-constants.js';\nimport type { ParsedRef, RefType } from './git-refs.types.js';\n\n/**\n * The prefixes of the ref types, most specific first.\n */\nconst PREFIXES: readonly [RefType, string][] = [\n ['branch', GIT_REFS_HEADS_PREFIX],\n ['tag', GIT_REFS_TAGS_PREFIX],\n ['remote', GIT_REFS_REMOTES_PREFIX],\n ['pull', GIT_REFS_PULL_PREFIX],\n ['other', GIT_REFS_PREFIX],\n];\n\n/**\n * Splits a full ref into its type and the name below its prefix, such as\n * `refs/tags/v1.2.3` into the type `tag` and the name `v1.2.3`.\n *\n * The ref is not validated; use `findRefNameProblem()` for that.\n *\n * @param ref - The full ref, such as `refs/heads/main`.\n * @returns The parsed ref, or `undefined` if the ref does not start with `refs/` or has no name below its prefix.\n */\nexport function parseRef(ref: string): ParsedRef | undefined {\n const match = PREFIXES.find(([, prefix]) => ref.startsWith(prefix));\n const name = match === undefined ? '' : ref.slice(match[1].length);\n return match === undefined || name === '' ? undefined : { ref, type: match[0], name };\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RefNameOptions } from './git-refs.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether Git allows a ref name, by the rules of `git check-ref-format`.
|
|
4
|
+
*
|
|
5
|
+
* @param name - The ref name.
|
|
6
|
+
* @param options - Options like those of `git check-ref-format`.
|
|
7
|
+
* @returns Whether Git allows the name.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isValidRefName(name: string, options?: RefNameOptions): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Throws if Git does not allow a ref name, by the rules of
|
|
12
|
+
* `git check-ref-format`.
|
|
13
|
+
*
|
|
14
|
+
* @param name - The ref name.
|
|
15
|
+
* @param options - Options like those of `git check-ref-format`.
|
|
16
|
+
* @throws {GitRefNameError} With the reason of the first problem.
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertRefName(name: string, options?: RefNameOptions): void;
|
package/dist/ref-name.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { findRefNameProblem } from './find-ref-name-problem.js';
|
|
2
|
+
import { GitRefNameError } from './git-ref-name-error.js';
|
|
3
|
+
/**
|
|
4
|
+
* Checks whether Git allows a ref name, by the rules of `git check-ref-format`.
|
|
5
|
+
*
|
|
6
|
+
* @param name - The ref name.
|
|
7
|
+
* @param options - Options like those of `git check-ref-format`.
|
|
8
|
+
* @returns Whether Git allows the name.
|
|
9
|
+
*/
|
|
10
|
+
export function isValidRefName(name, options = {}) {
|
|
11
|
+
return findRefNameProblem(name, options) === undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Throws if Git does not allow a ref name, by the rules of
|
|
15
|
+
* `git check-ref-format`.
|
|
16
|
+
*
|
|
17
|
+
* @param name - The ref name.
|
|
18
|
+
* @param options - Options like those of `git check-ref-format`.
|
|
19
|
+
* @throws {GitRefNameError} With the reason of the first problem.
|
|
20
|
+
*/
|
|
21
|
+
export function assertRefName(name, options = {}) {
|
|
22
|
+
const problem = findRefNameProblem(name, options);
|
|
23
|
+
if (problem !== undefined)
|
|
24
|
+
throw new GitRefNameError(name, problem.reason, problem.message);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=ref-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-name.js","sourceRoot":"","sources":["../src/ref-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,UAA0B,EAAE;IACvE,OAAO,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,SAAS,CAAC;AACzD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,UAA0B,EAAE;IACtE,MAAM,OAAO,GAAG,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,IAAI,OAAO,KAAK,SAAS;QAAE,MAAM,IAAI,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["import { findRefNameProblem } from './find-ref-name-problem.js';\nimport { GitRefNameError } from './git-ref-name-error.js';\nimport type { RefNameOptions } from './git-refs.types.js';\n\n/**\n * Checks whether Git allows a ref name, by the rules of `git check-ref-format`.\n *\n * @param name - The ref name.\n * @param options - Options like those of `git check-ref-format`.\n * @returns Whether Git allows the name.\n */\nexport function isValidRefName(name: string, options: RefNameOptions = {}): boolean {\n return findRefNameProblem(name, options) === undefined;\n}\n\n/**\n * Throws if Git does not allow a ref name, by the rules of\n * `git check-ref-format`.\n *\n * @param name - The ref name.\n * @param options - Options like those of `git check-ref-format`.\n * @throws {GitRefNameError} With the reason of the first problem.\n */\nexport function assertRefName(name: string, options: RefNameOptions = {}): void {\n const problem = findRefNameProblem(name, options);\n if (problem !== undefined) throw new GitRefNameError(name, problem.reason, problem.message);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simbo/git-refs",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Validates Git ref names by the rules of git check-ref-format, parses refs such as refs/tags/v1.2.3, and provides the common ref prefixes.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"git",
|
|
7
|
+
"ref",
|
|
8
|
+
"refs",
|
|
9
|
+
"ref-name",
|
|
10
|
+
"check-ref-format",
|
|
11
|
+
"branch",
|
|
12
|
+
"tag",
|
|
13
|
+
"validation"
|
|
14
|
+
],
|
|
15
|
+
"author": "Simon Lepel <simbo@simbo.de> (https://simbo.de/)",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"homepage": "https://github.com/simbo/packages/tree/main/packages/git-refs",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/simbo/packages.git",
|
|
21
|
+
"directory": "packages/git-refs"
|
|
22
|
+
},
|
|
23
|
+
"bugs": "https://github.com/simbo/packages/issues",
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "^24.15.0 || >=26.0.0"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"CHANGELOG.md",
|
|
34
|
+
"dist",
|
|
35
|
+
"LICENSE.md",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
40
|
+
"@simbo/eslint-config": "7.0.1",
|
|
41
|
+
"@simbo/tsconfig": "5.0.1",
|
|
42
|
+
"@types/node": "^24.19.4",
|
|
43
|
+
"@vitest/coverage-v8": "^5.1.2",
|
|
44
|
+
"@vitest/ui": "^5.1.2",
|
|
45
|
+
"eslint": "^10.16.0",
|
|
46
|
+
"jiti": "^2.7.0",
|
|
47
|
+
"publint": "^0.3.25",
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"vitest": "^5.1.2"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc --project tsconfig.build.json",
|
|
53
|
+
"check": "pnpm run check:eslint && pnpm run check:types",
|
|
54
|
+
"check:eslint": "eslint --config ./eslint.config.ts --max-warnings 0",
|
|
55
|
+
"check:pack": "pnpm pack --out node_modules/.cache/check-pack/package.tgz && publint node_modules/.cache/check-pack/package.tgz --strict && attw node_modules/.cache/check-pack/package.tgz --profile esm-only",
|
|
56
|
+
"check:types": "tsc --noEmit",
|
|
57
|
+
"clean": "pnpm run clean:dist && pnpm run clean:coverage && pnpm run clean:turbo && pnpm run clean:node_modules",
|
|
58
|
+
"clean:dist": "rm -rf dist",
|
|
59
|
+
"clean:node_modules": "rm -rf node_modules",
|
|
60
|
+
"clean:turbo": "rm -rf .turbo",
|
|
61
|
+
"clean:coverage": "rm -rf coverage",
|
|
62
|
+
"fix:eslint": "pnpm run check:eslint --fix",
|
|
63
|
+
"test": "vitest run --coverage",
|
|
64
|
+
"test:ui": "pnpm run test:watch --ui",
|
|
65
|
+
"test:watch": "vitest dev --coverage"
|
|
66
|
+
}
|
|
6
67
|
}
|