@udondan/avanti 0.24.0 → 0.25.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/README.md +467 -66
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +75 -12
- package/dist/commands/diff.js.map +1 -1
- package/dist/commands/lock.d.ts.map +1 -1
- package/dist/commands/lock.js +3 -2
- package/dist/commands/lock.js.map +1 -1
- package/dist/commands/log.d.ts.map +1 -1
- package/dist/commands/log.js +7 -5
- package/dist/commands/log.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +675 -36
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/reset.d.ts.map +1 -1
- package/dist/commands/reset.js +43 -11
- package/dist/commands/reset.js.map +1 -1
- package/dist/commands/revert.d.ts.map +1 -1
- package/dist/commands/revert.js +68 -14
- package/dist/commands/revert.js.map +1 -1
- package/dist/condition.d.ts.map +1 -1
- package/dist/condition.js +9 -6
- package/dist/condition.js.map +1 -1
- package/dist/config-writeback.d.ts.map +1 -1
- package/dist/config-writeback.js +17 -0
- package/dist/config-writeback.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +244 -3
- package/dist/config.js.map +1 -1
- package/dist/diff.d.ts +19 -0
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +317 -12
- package/dist/diff.js.map +1 -1
- package/dist/extract.d.ts +4 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +142 -0
- package/dist/extract.js.map +1 -0
- package/dist/filter.d.ts +3 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +126 -0
- package/dist/filter.js.map +1 -0
- package/dist/history.d.ts +7 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +89 -9
- package/dist/history.js.map +1 -1
- package/dist/paths.d.ts +4 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +97 -0
- package/dist/paths.js.map +1 -1
- package/dist/processors/ini.d.ts +33 -0
- package/dist/processors/ini.d.ts.map +1 -0
- package/dist/processors/ini.js +500 -0
- package/dist/processors/ini.js.map +1 -0
- package/dist/processors/insert.d.ts.map +1 -1
- package/dist/processors/insert.js +338 -15
- package/dist/processors/insert.js.map +1 -1
- package/dist/processors/on.d.ts +4 -0
- package/dist/processors/on.d.ts.map +1 -0
- package/dist/processors/on.js +54 -0
- package/dist/processors/on.js.map +1 -0
- package/dist/ref.d.ts +21 -0
- package/dist/ref.d.ts.map +1 -0
- package/dist/ref.js +65 -0
- package/dist/ref.js.map +1 -0
- package/dist/sources/bitbucket.d.ts.map +1 -1
- package/dist/sources/bitbucket.js +51 -12
- package/dist/sources/bitbucket.js.map +1 -1
- package/dist/sources/git.d.ts.map +1 -1
- package/dist/sources/git.js +54 -6
- package/dist/sources/git.js.map +1 -1
- package/dist/sources/github.d.ts.map +1 -1
- package/dist/sources/github.js +188 -51
- package/dist/sources/github.js.map +1 -1
- package/dist/sources/gitlab.d.ts.map +1 -1
- package/dist/sources/gitlab.js +242 -44
- package/dist/sources/gitlab.js.map +1 -1
- package/dist/sources/index.d.ts +3 -1
- package/dist/sources/index.d.ts.map +1 -1
- package/dist/sources/index.js +170 -34
- package/dist/sources/index.js.map +1 -1
- package/dist/sources/local.d.ts +3 -0
- package/dist/sources/local.d.ts.map +1 -1
- package/dist/sources/local.js +44 -0
- package/dist/sources/local.js.map +1 -1
- package/dist/types.d.ts +38 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables-remote.d.ts.map +1 -1
- package/dist/variables-remote.js +2 -1
- package/dist/variables-remote.js.map +1 -1
- package/dist/variables.d.ts +1 -0
- package/dist/variables.d.ts.map +1 -1
- package/dist/variables.js +37 -2
- package/dist/variables.js.map +1 -1
- package/dist/writer.d.ts +17 -0
- package/dist/writer.d.ts.map +1 -1
- package/dist/writer.js +848 -20
- package/dist/writer.js.map +1 -1
- package/package.json +11 -7
package/dist/ref.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SEMVER_PATTERN = void 0;
|
|
4
|
+
exports.maxSemverTag = maxSemverTag;
|
|
5
|
+
exports.isLatestSentinel = isLatestSentinel;
|
|
6
|
+
exports.isRecentSentinel = isRecentSentinel;
|
|
7
|
+
exports.parseRefPattern = parseRefPattern;
|
|
8
|
+
/** Matches stable semver tags: vX.Y.Z or X.Y.Z (exactly three components). */
|
|
9
|
+
exports.SEMVER_PATTERN = /^v?\d+\.\d+\.\d+$/;
|
|
10
|
+
function parseSemver(tag) {
|
|
11
|
+
const m = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(tag);
|
|
12
|
+
if (!m)
|
|
13
|
+
return [0, 0, 0];
|
|
14
|
+
return [parseInt(m[1], 10), parseInt(m[2], 10), parseInt(m[3], 10)];
|
|
15
|
+
}
|
|
16
|
+
/** Return the tag with the highest semver among the given list, or null if the list is empty or contains no semver tags. */
|
|
17
|
+
function maxSemverTag(tags) {
|
|
18
|
+
const valid = tags.filter((t) => exports.SEMVER_PATTERN.test(t));
|
|
19
|
+
if (!valid.length)
|
|
20
|
+
return null;
|
|
21
|
+
return valid.reduce((best, tag) => {
|
|
22
|
+
const [bMaj, bMin, bPatch] = parseSemver(best);
|
|
23
|
+
const [tMaj, tMin, tPatch] = parseSemver(tag);
|
|
24
|
+
if (tMaj !== bMaj)
|
|
25
|
+
return tMaj > bMaj ? tag : best;
|
|
26
|
+
if (tMin !== bMin)
|
|
27
|
+
return tMin > bMin ? tag : best;
|
|
28
|
+
return tPatch > bPatch ? tag : best;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function isLatestSentinel(ref) {
|
|
32
|
+
return ref === '$latest';
|
|
33
|
+
}
|
|
34
|
+
function isRecentSentinel(ref) {
|
|
35
|
+
return ref === '$recent';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parse a regex pattern from a ref string of the form `/pattern/` or `/pattern/flags`.
|
|
39
|
+
* Returns the compiled RegExp, or null if the ref does not match that form.
|
|
40
|
+
* Throws if the pattern body or flags are syntactically invalid.
|
|
41
|
+
*
|
|
42
|
+
* Supported subset (intentional differences from JS regex literal syntax):
|
|
43
|
+
* - The pattern body must be non-empty: `//` is not recognised and returns null
|
|
44
|
+
* (treated as a literal ref, since an empty pattern is not useful for tag matching).
|
|
45
|
+
* - The closing `/` is the last `/` in the string, so inner unescaped slashes are
|
|
46
|
+
* absorbed into the pattern body (e.g. `/foo/bar/` → pattern `foo/bar`).
|
|
47
|
+
* - Stateful flags `g` and `y` are silently stripped because callers use `.test()`.
|
|
48
|
+
* - Any other unrecognised flags cause `new RegExp()` to throw a descriptive error.
|
|
49
|
+
*/
|
|
50
|
+
function parseRefPattern(ref) {
|
|
51
|
+
const m = /^\/(.+)\/([A-Za-z]*)$/.exec(ref);
|
|
52
|
+
if (!m)
|
|
53
|
+
return null;
|
|
54
|
+
// Strip stateful flags (g=global, y=sticky) — callers use .test() in loops
|
|
55
|
+
const flags = m[2].replace(/[gy]/g, '') || undefined;
|
|
56
|
+
try {
|
|
57
|
+
return new RegExp(m[1], flags);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw new Error(`Invalid ref pattern "${ref}": ${e.message}`, {
|
|
61
|
+
cause: e,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=ref.js.map
|
package/dist/ref.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":";;;AAUA,oCAUC;AAED,4CAEC;AAED,4CAEC;AAeD,0CAYC;AAvDD,8EAA8E;AACjE,QAAA,cAAc,GAAG,mBAAmB,CAAC;AAElD,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,CAAC,GAAG,yBAAyB,CAAC,IAAI,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AAC;AAC3B,CAAC;AAED,SAAgB,gBAAgB,CAAC,GAAuB;IACtD,OAAO,GAAG,KAAK,SAAS,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,eAAe,CAAC,GAAW;IACzC,MAAM,CAAC,GAAG,uBAAuB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,2EAA2E;IAC3E,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC;IACrD,IAAI,CAAC;QACH,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,MAAO,CAAW,CAAC,OAAO,EAAE,EAAE;YACvE,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitbucket.d.ts","sourceRoot":"","sources":["../../src/sources/bitbucket.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bitbucket.d.ts","sourceRoot":"","sources":["../../src/sources/bitbucket.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B;AAsMD,wBAAsB,cAAc,CAClC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,eAAe,CAAC,CAwC1B"}
|
|
@@ -4,6 +4,7 @@ exports.fetchBitbucket = fetchBitbucket;
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fetch_1 = require("../fetch");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
|
+
const ref_1 = require("../ref");
|
|
7
8
|
function getApiBase(override) {
|
|
8
9
|
const host = override?.trim() ||
|
|
9
10
|
process.env.BITBUCKET_HOST?.trim() ||
|
|
@@ -26,22 +27,60 @@ function apiHeaders() {
|
|
|
26
27
|
return headers;
|
|
27
28
|
}
|
|
28
29
|
async function resolveRef(workspace, repo, ref, host) {
|
|
29
|
-
|
|
30
|
+
const pattern = ref ? (0, ref_1.parseRefPattern)(ref) : null;
|
|
31
|
+
if (!(0, ref_1.isLatestSentinel)(ref) && !(0, ref_1.isRecentSentinel)(ref) && !pattern && ref) {
|
|
30
32
|
return ref;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
}
|
|
34
|
+
if (!ref) {
|
|
35
|
+
// No ref: return default branch
|
|
36
|
+
const repoRes = await (0, fetch_1.fetchWithRetry)(`${getApiBase(host)}/repositories/${workspace}/${repo}`, { headers: apiHeaders() });
|
|
37
|
+
if (!repoRes.ok) {
|
|
38
|
+
throw new Error(`Failed to resolve ref for ${workspace}/${repo}: HTTP ${repoRes.status}`);
|
|
39
|
+
}
|
|
40
|
+
const repoData = (await repoRes.json());
|
|
41
|
+
return repoData.mainbranch?.name ?? 'main';
|
|
42
|
+
}
|
|
43
|
+
// $latest: paginate tags and track the highest semver incrementally
|
|
44
|
+
if ((0, ref_1.isLatestSentinel)(ref)) {
|
|
45
|
+
let best = null;
|
|
46
|
+
let url = `${getApiBase(host)}/repositories/${workspace}/${repo}/refs/tags?sort=-name&pagelen=100`;
|
|
47
|
+
while (url) {
|
|
48
|
+
const res = await (0, fetch_1.fetchWithRetry)(url, { headers: apiHeaders() });
|
|
49
|
+
if (!res.ok)
|
|
50
|
+
throw new Error(`Failed to list tags for ${workspace}/${repo}: HTTP ${res.status}`);
|
|
51
|
+
const data = (await res.json());
|
|
52
|
+
const candidate = (0, ref_1.maxSemverTag)(data.values.map((t) => t.name));
|
|
53
|
+
if (candidate && (!best || (0, ref_1.maxSemverTag)([best, candidate]) === candidate))
|
|
54
|
+
best = candidate;
|
|
55
|
+
url = data.next ?? null;
|
|
37
56
|
}
|
|
57
|
+
if (best)
|
|
58
|
+
return best;
|
|
59
|
+
throw new Error(`No semver tags found for ${workspace}/${repo} (needed to resolve $latest)`);
|
|
38
60
|
}
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
61
|
+
// $recent: most recently committed tag (sort by target commit date)
|
|
62
|
+
if ((0, ref_1.isRecentSentinel)(ref)) {
|
|
63
|
+
const tagsRes = await (0, fetch_1.fetchWithRetry)(`${getApiBase(host)}/repositories/${workspace}/${repo}/refs/tags?sort=-target.date&pagelen=1`, { headers: apiHeaders() });
|
|
64
|
+
if (!tagsRes.ok)
|
|
65
|
+
throw new Error(`Failed to resolve $recent for ${workspace}/${repo}: HTTP ${tagsRes.status}`);
|
|
66
|
+
const data = (await tagsRes.json());
|
|
67
|
+
if (data.values.length > 0)
|
|
68
|
+
return data.values[0].name;
|
|
69
|
+
throw new Error(`No tags found for ${workspace}/${repo} (needed to resolve $recent)`);
|
|
70
|
+
}
|
|
71
|
+
// Pattern: paginate tags sorted by target date, short-circuit on first match
|
|
72
|
+
let patternUrl = `${getApiBase(host)}/repositories/${workspace}/${repo}/refs/tags?sort=-target.date&pagelen=100`;
|
|
73
|
+
while (patternUrl) {
|
|
74
|
+
const res = await (0, fetch_1.fetchWithRetry)(patternUrl, { headers: apiHeaders() });
|
|
75
|
+
if (!res.ok)
|
|
76
|
+
throw new Error(`Failed to list tags for ${workspace}/${repo}: HTTP ${res.status}`);
|
|
77
|
+
const data = (await res.json());
|
|
78
|
+
const found = data.values.find((t) => pattern.test(t.name));
|
|
79
|
+
if (found)
|
|
80
|
+
return found.name;
|
|
81
|
+
patternUrl = data.next ?? null;
|
|
42
82
|
}
|
|
43
|
-
|
|
44
|
-
return repoData.mainbranch?.name ?? 'main';
|
|
83
|
+
throw new Error(`No tags matching "${ref}" found for ${workspace}/${repo}`);
|
|
45
84
|
}
|
|
46
85
|
// Returns file content, or null if the path is a directory.
|
|
47
86
|
async function fetchFileOrDetect(workspace, repo, filePath, ref, host) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitbucket.js","sourceRoot":"","sources":["../../src/sources/bitbucket.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"bitbucket.js","sourceRoot":"","sources":["../../src/sources/bitbucket.ts"],"names":[],"mappings":";;AAkNA,wCA8CC;AAhQD,+BAAqC;AACrC,oCAA0C;AAC1C,sCAAoC;AACpC,gCAKgB;AAMhB,SAAS,UAAU,CAAC,QAAiB;IACnC,MAAM,IAAI,GACR,QAAQ,EAAE,IAAI,EAAE;QAChB,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,EAAE;QAClC,mBAAmB,CAAC;IACtB,OAAO,WAAW,IAAI,MAAM,CAAC;AAC/B,CAAC;AAED,SAAS,UAAU;IACjB,MAAM,OAAO,GAA2B,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;IACnE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC;IAClD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC;IAClD,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;QACnB,2FAA2F;QAC3F,OAAO,CAAC,aAAa,GAAG,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvF,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,KAAK,EAAE,CAAC;QACV,iDAAiD;QACjD,OAAO,CAAC,aAAa,GAAG,UAAU,KAAK,EAAE,CAAC;IAC5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EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/sources/git.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/sources/git.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B;AA8CD,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAMjD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB,CAwBA;AAwDD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CA8E5E"}
|
package/dist/sources/git.js
CHANGED
|
@@ -41,6 +41,7 @@ const fs = __importStar(require("fs"));
|
|
|
41
41
|
const os = __importStar(require("os"));
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
const logger_1 = require("../logger");
|
|
44
|
+
const ref_1 = require("../ref");
|
|
44
45
|
function run(cmd, args, opts = {}) {
|
|
45
46
|
const result = (0, child_process_1.spawnSync)(cmd, args, { encoding: 'utf8', cwd: opts.cwd });
|
|
46
47
|
if (result.error)
|
|
@@ -98,6 +99,47 @@ function parseGitRemoteSpec(spec) {
|
|
|
98
99
|
}
|
|
99
100
|
return { repo, file, ref };
|
|
100
101
|
}
|
|
102
|
+
function resolveGitRef(repo, ref, pattern) {
|
|
103
|
+
const wantSemver = (0, ref_1.isLatestSentinel)(ref);
|
|
104
|
+
const wantRecent = (0, ref_1.isRecentSentinel)(ref);
|
|
105
|
+
(0, logger_1.verbose)(`git: listing remote tags for ${redactGitUrl(repo)}`);
|
|
106
|
+
// ls-remote --sort is not reliably supported across Git versions and lacks
|
|
107
|
+
// creatordates for tag objects, so we fetch all tags and filter client-side.
|
|
108
|
+
const result = run('git', [
|
|
109
|
+
'ls-remote',
|
|
110
|
+
'--tags',
|
|
111
|
+
'--refs',
|
|
112
|
+
repo,
|
|
113
|
+
'refs/tags/*',
|
|
114
|
+
]);
|
|
115
|
+
if (result.status !== 0) {
|
|
116
|
+
throw new Error(`Failed to list tags for ${redactGitUrl(repo)}: ${result.stderr.trim()}`);
|
|
117
|
+
}
|
|
118
|
+
const names = result.stdout
|
|
119
|
+
.trim()
|
|
120
|
+
.split('\n')
|
|
121
|
+
.filter(Boolean)
|
|
122
|
+
.map((line) => {
|
|
123
|
+
const ref = line.split('\t')[1] ?? '';
|
|
124
|
+
return ref.replace(/^refs\/tags\//, '').replace(/\^\{\}$/, '');
|
|
125
|
+
})
|
|
126
|
+
.filter(Boolean);
|
|
127
|
+
// $latest: pick the highest semver tag using semantic comparison
|
|
128
|
+
if (wantSemver) {
|
|
129
|
+
const found = (0, ref_1.maxSemverTag)(names);
|
|
130
|
+
if (found)
|
|
131
|
+
return found;
|
|
132
|
+
throw new Error(`No semver tags found for ${redactGitUrl(repo)} (needed to resolve $latest)`);
|
|
133
|
+
}
|
|
134
|
+
// $recent / pattern: first match in ls-remote output order
|
|
135
|
+
const filterFn = pattern ? (n) => pattern.test(n) : () => true;
|
|
136
|
+
const found = names.find(filterFn);
|
|
137
|
+
if (found)
|
|
138
|
+
return found;
|
|
139
|
+
if (wantRecent)
|
|
140
|
+
throw new Error(`No tags found for ${redactGitUrl(repo)} (needed to resolve $recent)`);
|
|
141
|
+
throw new Error(`No tags matching "${ref}" found for ${redactGitUrl(repo)}`);
|
|
142
|
+
}
|
|
101
143
|
function fetchGit(repo, file, ref) {
|
|
102
144
|
const normalized = path.normalize(file);
|
|
103
145
|
if (path.isAbsolute(file) ||
|
|
@@ -108,10 +150,14 @@ function fetchGit(repo, file, ref) {
|
|
|
108
150
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'avanti-git-'));
|
|
109
151
|
try {
|
|
110
152
|
const repoDir = path.join(tmpDir, 'repo');
|
|
111
|
-
|
|
153
|
+
const refPattern = ref ? (0, ref_1.parseRefPattern)(ref) : null;
|
|
154
|
+
const resolvedRef = ref && ((0, ref_1.isLatestSentinel)(ref) || (0, ref_1.isRecentSentinel)(ref) || refPattern)
|
|
155
|
+
? resolveGitRef(repo, ref, refPattern)
|
|
156
|
+
: ref;
|
|
157
|
+
if (!resolvedRef || !looksLikeCommitHash(resolvedRef)) {
|
|
112
158
|
const args = ['clone', '--depth', '1'];
|
|
113
|
-
if (
|
|
114
|
-
args.push('--branch',
|
|
159
|
+
if (resolvedRef)
|
|
160
|
+
args.push('--branch', resolvedRef);
|
|
115
161
|
(0, logger_1.verbose)(`git ${args.join(' ')} ${redactGitUrl(repo)} <tmpdir>`);
|
|
116
162
|
args.push(repo, repoDir);
|
|
117
163
|
const res = run('git', args);
|
|
@@ -125,10 +171,12 @@ function fetchGit(repo, file, ref) {
|
|
|
125
171
|
if (cloneRes.status !== 0) {
|
|
126
172
|
throw new Error(`git clone failed: ${cloneRes.stderr.trim()}`);
|
|
127
173
|
}
|
|
128
|
-
(0, logger_1.verbose)(`git checkout ${
|
|
129
|
-
const checkoutRes = run('git', ['checkout',
|
|
174
|
+
(0, logger_1.verbose)(`git checkout ${resolvedRef}`);
|
|
175
|
+
const checkoutRes = run('git', ['checkout', resolvedRef], {
|
|
176
|
+
cwd: repoDir,
|
|
177
|
+
});
|
|
130
178
|
if (checkoutRes.status !== 0) {
|
|
131
|
-
throw new Error(`git checkout ${
|
|
179
|
+
throw new Error(`git checkout ${resolvedRef} failed: ${checkoutRes.stderr.trim()}`);
|
|
132
180
|
}
|
|
133
181
|
}
|
|
134
182
|
const normalizedFile = file.replace(/\/$/, '');
|
package/dist/sources/git.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/sources/git.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/sources/git.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DA,wCAMC;AAED,gDA4BC;AAwDD,4BA8EC;AAtOD,iDAA0C;AAC1C,uCAAyB;AACzB,uCAAyB;AACzB,2CAA6B;AAC7B,sCAAoC;AACpC,gCAKgB;AAMhB,SAAS,GAAG,CACV,GAAW,EACX,IAAc,EACd,OAAyB,EAAE;IAE3B,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,GAAG,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IACzE,IAAI,MAAM,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,WAAW,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3E,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAW;IACtC,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,YAAY,CACnB,IAAY,EACZ,GAAW,EACX,KAA0B;IAE1B,KAAK,MAAM,KAAK,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACjE,IAAI,KAAK,CAAC,cAAc,EAAE;YAAE,SAAS;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KA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appings":"
|
|
1
|
+
{"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/sources/github.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAWpC,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5B;AAwlBD,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,GAChB,OAAO,CAAC,YAAY,CAAC,CAgCvB;AAED,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,IAAI,CAAC,EAAE,MAAM,EACb,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,GAChB,OAAO,CAAC,YAAY,CAAC,CAyCvB"}
|
package/dist/sources/github.js
CHANGED
|
@@ -41,6 +41,7 @@ const os = __importStar(require("os"));
|
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
42
|
const fetch_1 = require("../fetch");
|
|
43
43
|
const logger_1 = require("../logger");
|
|
44
|
+
const ref_1 = require("../ref");
|
|
44
45
|
function normalizeVia(via) {
|
|
45
46
|
if (!via)
|
|
46
47
|
return ['api', 'cli'];
|
|
@@ -225,13 +226,80 @@ function listTreeViaCli(repo, dirPath, ref, host) {
|
|
|
225
226
|
}
|
|
226
227
|
return res.stdout.trim().split('\n').filter(Boolean);
|
|
227
228
|
}
|
|
229
|
+
async function findHighestSemverTagApi(repo, host) {
|
|
230
|
+
let best = null;
|
|
231
|
+
const perPage = 100;
|
|
232
|
+
for (let page = 1;; page++) {
|
|
233
|
+
const res = await (0, fetch_1.fetchWithRetry)(`${getApiBase(host)}/repos/${repo}/tags?per_page=${perPage}&page=${page}`, { headers: apiHeaders() });
|
|
234
|
+
if (!res.ok)
|
|
235
|
+
throw new HttpError(res.status, `Failed to list tags for ${repo}: HTTP ${res.status}`);
|
|
236
|
+
const tags = (await res.json());
|
|
237
|
+
const candidate = (0, ref_1.maxSemverTag)(tags.map((t) => t.name));
|
|
238
|
+
if (candidate && (!best || (0, ref_1.maxSemverTag)([best, candidate]) === candidate))
|
|
239
|
+
best = candidate;
|
|
240
|
+
if (tags.length < perPage)
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
return best;
|
|
244
|
+
}
|
|
245
|
+
async function findTagMatchingPatternApi(repo, pattern, host) {
|
|
246
|
+
const perPage = 100;
|
|
247
|
+
for (let page = 1;; page++) {
|
|
248
|
+
const res = await (0, fetch_1.fetchWithRetry)(`${getApiBase(host)}/repos/${repo}/tags?per_page=${perPage}&page=${page}`, { headers: apiHeaders() });
|
|
249
|
+
if (!res.ok)
|
|
250
|
+
throw new HttpError(res.status, `Failed to list tags for ${repo}: HTTP ${res.status}`);
|
|
251
|
+
const tags = (await res.json());
|
|
252
|
+
const found = tags.find((t) => pattern.test(t.name));
|
|
253
|
+
if (found)
|
|
254
|
+
return found.name;
|
|
255
|
+
if (tags.length < perPage)
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
function findTagMatchingPatternCli(repo, pattern, host) {
|
|
261
|
+
const args = [
|
|
262
|
+
'api',
|
|
263
|
+
...hostnameArgs(host),
|
|
264
|
+
'--paginate',
|
|
265
|
+
`repos/${repo}/tags`,
|
|
266
|
+
'--jq',
|
|
267
|
+
'.[].name',
|
|
268
|
+
];
|
|
269
|
+
(0, logger_1.verbose)(`github: gh: gh ${args.join(' ')}`);
|
|
270
|
+
const res = ghRun(args);
|
|
271
|
+
if (res.status !== 0)
|
|
272
|
+
throw new Error(`Failed to list tags for ${repo}: ${res.stderr.trim() || 'gh exited with status ' + res.status}`);
|
|
273
|
+
return (res.stdout
|
|
274
|
+
.trim()
|
|
275
|
+
.split('\n')
|
|
276
|
+
.filter(Boolean)
|
|
277
|
+
.find((n) => pattern.test(n)) ?? null);
|
|
278
|
+
}
|
|
279
|
+
function findHighestSemverTagCli(repo, host) {
|
|
280
|
+
const args = [
|
|
281
|
+
'api',
|
|
282
|
+
...hostnameArgs(host),
|
|
283
|
+
'--paginate',
|
|
284
|
+
`repos/${repo}/tags`,
|
|
285
|
+
'--jq',
|
|
286
|
+
'.[].name',
|
|
287
|
+
];
|
|
288
|
+
(0, logger_1.verbose)(`github: gh: gh ${args.join(' ')}`);
|
|
289
|
+
const res = ghRun(args);
|
|
290
|
+
if (res.status !== 0)
|
|
291
|
+
throw new Error(`Failed to list tags for ${repo}: ${res.stderr.trim() || 'gh exited with status ' + res.status}`);
|
|
292
|
+
return (0, ref_1.maxSemverTag)(res.stdout.trim().split('\n').filter(Boolean));
|
|
293
|
+
}
|
|
228
294
|
async function resolveRef(repo, ref, host, transports = ['api', 'cli']) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
295
|
+
const pattern = ref ? (0, ref_1.parseRefPattern)(ref) : null;
|
|
296
|
+
if (!(0, ref_1.isLatestSentinel)(ref) && !(0, ref_1.isRecentSentinel)(ref) && !pattern) {
|
|
297
|
+
return ref || 'HEAD';
|
|
298
|
+
}
|
|
299
|
+
(0, logger_1.verbose)(`github: resolving "${ref}" for ${repo}`);
|
|
232
300
|
if (transports[0] === 'cli') {
|
|
233
301
|
try {
|
|
234
|
-
return resolveRefViaCli(repo, host);
|
|
302
|
+
return resolveRefViaCli(repo, ref, host);
|
|
235
303
|
}
|
|
236
304
|
catch (e) {
|
|
237
305
|
if (!transports.includes('api'))
|
|
@@ -239,64 +307,131 @@ async function resolveRef(repo, ref, host, transports = ['api', 'cli']) {
|
|
|
239
307
|
}
|
|
240
308
|
}
|
|
241
309
|
const withCliFallback = transports[0] === 'api' && transports.includes('cli');
|
|
242
|
-
//
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
catch (e) {
|
|
248
|
-
if (isNetworkError(e) && withCliFallback && isGhAvailable()) {
|
|
249
|
-
(0, logger_1.verbose)(`github: HTTP fetch failed, falling back to gh`);
|
|
250
|
-
return resolveRefViaCli(repo, host);
|
|
310
|
+
// Pattern: paginate tags and return first match
|
|
311
|
+
if (pattern) {
|
|
312
|
+
let found;
|
|
313
|
+
try {
|
|
314
|
+
found = await findTagMatchingPatternApi(repo, pattern, host);
|
|
251
315
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
316
|
+
catch (e) {
|
|
317
|
+
if (isNetworkError(e) && withCliFallback && isGhAvailable()) {
|
|
318
|
+
(0, logger_1.verbose)(`github: HTTP fetch failed, falling back to gh`);
|
|
319
|
+
return resolveRefViaCli(repo, ref, host);
|
|
320
|
+
}
|
|
321
|
+
if (e instanceof HttpError &&
|
|
322
|
+
shouldFallback(e.status) &&
|
|
323
|
+
withCliFallback &&
|
|
324
|
+
isGhAvailable()) {
|
|
325
|
+
(0, logger_1.verbose)(`github: API returned ${e.status}, falling back to gh`);
|
|
326
|
+
return resolveRefViaCli(repo, ref, host);
|
|
327
|
+
}
|
|
328
|
+
throw e;
|
|
329
|
+
}
|
|
330
|
+
if (found !== null)
|
|
331
|
+
return found;
|
|
332
|
+
throw new Error(`No tags matching "${ref}" found for ${repo}`);
|
|
257
333
|
}
|
|
258
|
-
//
|
|
259
|
-
if (
|
|
260
|
-
let
|
|
334
|
+
// $latest: try releases/latest first (semantic "latest stable release"), then scan semver tags
|
|
335
|
+
if ((0, ref_1.isLatestSentinel)(ref)) {
|
|
336
|
+
let relRes;
|
|
261
337
|
try {
|
|
262
|
-
|
|
338
|
+
relRes = await (0, fetch_1.fetchWithRetry)(`${getApiBase(host)}/repos/${repo}/releases/latest`, { headers: apiHeaders() });
|
|
263
339
|
}
|
|
264
340
|
catch (e) {
|
|
265
341
|
if (isNetworkError(e) && withCliFallback && isGhAvailable()) {
|
|
266
342
|
(0, logger_1.verbose)(`github: HTTP fetch failed, falling back to gh`);
|
|
267
|
-
return resolveRefViaCli(repo, host);
|
|
343
|
+
return resolveRefViaCli(repo, ref, host);
|
|
268
344
|
}
|
|
269
345
|
throw e;
|
|
270
346
|
}
|
|
271
|
-
if (
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
274
|
-
return
|
|
275
|
-
|
|
347
|
+
if (relRes.ok) {
|
|
348
|
+
const rel = (await relRes.json());
|
|
349
|
+
if (ref_1.SEMVER_PATTERN.test(rel.tag_name))
|
|
350
|
+
return rel.tag_name;
|
|
351
|
+
// non-semver release tag: fall through to tag scan
|
|
352
|
+
}
|
|
353
|
+
else if (relRes.status !== 404) {
|
|
354
|
+
if (shouldFallback(relRes.status) && withCliFallback && isGhAvailable()) {
|
|
355
|
+
return resolveRefViaCli(repo, ref, host);
|
|
356
|
+
}
|
|
357
|
+
throw new Error(`Failed to resolve "${ref}" for ${repo}: HTTP ${relRes.status}`);
|
|
358
|
+
}
|
|
359
|
+
let found;
|
|
360
|
+
try {
|
|
361
|
+
found = await findHighestSemverTagApi(repo, host);
|
|
276
362
|
}
|
|
277
|
-
|
|
278
|
-
|
|
363
|
+
catch (e) {
|
|
364
|
+
if (isNetworkError(e) && withCliFallback && isGhAvailable()) {
|
|
365
|
+
(0, logger_1.verbose)(`github: HTTP fetch failed, falling back to gh`);
|
|
366
|
+
return resolveRefViaCli(repo, ref, host);
|
|
367
|
+
}
|
|
368
|
+
if (e instanceof HttpError &&
|
|
369
|
+
shouldFallback(e.status) &&
|
|
370
|
+
withCliFallback &&
|
|
371
|
+
isGhAvailable()) {
|
|
372
|
+
(0, logger_1.verbose)(`github: API returned ${e.status}, falling back to gh`);
|
|
373
|
+
return resolveRefViaCli(repo, ref, host);
|
|
374
|
+
}
|
|
375
|
+
throw e;
|
|
376
|
+
}
|
|
377
|
+
if (found !== null)
|
|
378
|
+
return found;
|
|
379
|
+
throw new Error(`No semver tags found for ${repo} (needed to resolve $latest)`);
|
|
380
|
+
}
|
|
381
|
+
// $recent: most recently created tag (not releases/latest, which reflects publication order)
|
|
382
|
+
let tagRes;
|
|
383
|
+
try {
|
|
384
|
+
tagRes = await (0, fetch_1.fetchWithRetry)(`${getApiBase(host)}/repos/${repo}/tags?per_page=1`, { headers: apiHeaders() });
|
|
385
|
+
}
|
|
386
|
+
catch (e) {
|
|
387
|
+
if (isNetworkError(e) && withCliFallback && isGhAvailable()) {
|
|
388
|
+
(0, logger_1.verbose)(`github: HTTP fetch failed, falling back to gh`);
|
|
389
|
+
return resolveRefViaCli(repo, ref, host);
|
|
279
390
|
}
|
|
280
|
-
throw
|
|
391
|
+
throw e;
|
|
392
|
+
}
|
|
393
|
+
if (tagRes.ok) {
|
|
394
|
+
const tags = (await tagRes.json());
|
|
395
|
+
if (tags.length)
|
|
396
|
+
return tags[0].name;
|
|
397
|
+
throw new Error(`No tags found for ${repo} (needed to resolve $recent)`);
|
|
281
398
|
}
|
|
282
|
-
if (shouldFallback(
|
|
283
|
-
return resolveRefViaCli(repo, host);
|
|
399
|
+
if (shouldFallback(tagRes.status) && withCliFallback && isGhAvailable()) {
|
|
400
|
+
return resolveRefViaCli(repo, ref, host);
|
|
284
401
|
}
|
|
285
|
-
throw new Error(`Failed to resolve $
|
|
402
|
+
throw new Error(`Failed to resolve "${ref}" for ${repo}: HTTP ${tagRes.status}`);
|
|
286
403
|
}
|
|
287
|
-
function resolveRefViaCli(repo, host) {
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
404
|
+
function resolveRefViaCli(repo, ref, host) {
|
|
405
|
+
const pattern = (0, ref_1.parseRefPattern)(ref);
|
|
406
|
+
if (pattern) {
|
|
407
|
+
const found = findTagMatchingPatternCli(repo, pattern, host);
|
|
408
|
+
if (found !== null)
|
|
409
|
+
return found;
|
|
410
|
+
throw new Error(`No tags matching "${ref}" found for ${repo}`);
|
|
411
|
+
}
|
|
412
|
+
// $latest: try releases/latest first, then scan semver tags
|
|
413
|
+
if ((0, ref_1.isLatestSentinel)(ref)) {
|
|
414
|
+
const relArgs = [
|
|
415
|
+
'api',
|
|
416
|
+
...hostnameArgs(host),
|
|
417
|
+
`repos/${repo}/releases/latest`,
|
|
418
|
+
'--jq',
|
|
419
|
+
'.tag_name',
|
|
420
|
+
];
|
|
421
|
+
(0, logger_1.verbose)(`github: gh fallback: gh ${relArgs.join(' ')}`);
|
|
422
|
+
const res = ghRun(relArgs);
|
|
423
|
+
if (res.status === 0 && res.stdout.trim()) {
|
|
424
|
+
const tag = res.stdout.trim();
|
|
425
|
+
if (ref_1.SEMVER_PATTERN.test(tag))
|
|
426
|
+
return tag;
|
|
427
|
+
// non-semver release: fall through to tag search
|
|
428
|
+
}
|
|
429
|
+
const found = findHighestSemverTagCli(repo, host);
|
|
430
|
+
if (found !== null)
|
|
431
|
+
return found;
|
|
432
|
+
throw new Error(`No semver tags found for ${repo} (needed to resolve $latest)`);
|
|
433
|
+
}
|
|
434
|
+
// $recent: most recently created tag (not releases/latest, which reflects publication order)
|
|
300
435
|
const tagArgs = [
|
|
301
436
|
'api',
|
|
302
437
|
...hostnameArgs(host),
|
|
@@ -306,10 +441,12 @@ function resolveRefViaCli(repo, host) {
|
|
|
306
441
|
];
|
|
307
442
|
(0, logger_1.verbose)(`github: gh fallback: gh ${tagArgs.join(' ')}`);
|
|
308
443
|
const tagRes = ghRun(tagArgs);
|
|
309
|
-
if (tagRes.status !== 0
|
|
310
|
-
throw new Error(`
|
|
311
|
-
|
|
312
|
-
|
|
444
|
+
if (tagRes.status !== 0)
|
|
445
|
+
throw new Error(`Failed to list tags for ${repo}: ${tagRes.stderr.trim() || 'gh exited with status ' + tagRes.status}`);
|
|
446
|
+
const tagName = tagRes.stdout.trim();
|
|
447
|
+
if (!tagName || tagName === 'null')
|
|
448
|
+
throw new Error(`No tags found for ${repo} (needed to resolve $recent)`);
|
|
449
|
+
return tagName;
|
|
313
450
|
}
|
|
314
451
|
async function fetchReleaseAssetsViaApi(repo, tag, host) {
|
|
315
452
|
const res = await (0, fetch_1.fetchWithRetry)(`${getApiBase(host)}/repos/${repo}/releases/tags/${encodeURIComponent(tag)}`, { headers: apiHeaders() });
|