@omni-oss/set-version 0.0.3 → 0.1.2
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 +25 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +4 -4
- package/dist/set-version.cjs +2 -2
- package/dist/set-version.mjs +12 -23
- package/dist/src-BoCeBNhe.mjs +269 -0
- package/dist/src-DacLUqIe.js +1 -0
- package/package.json +12 -12
- package/dist/index-BCvo12D0.js +0 -1
- package/dist/index-DjY1h20_.mjs +0 -323
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.
|
|
3
3
|
|
|
4
4
|
- - -
|
|
5
|
+
## @omni-oss/set-version-v0.1.2 - 2026-03-14
|
|
6
|
+
#### Bug Fixes
|
|
7
|
+
- error when constructing NoConfigFoundError - (804af84) - Clarence Manuel
|
|
8
|
+
#### Miscellaneous Chores
|
|
9
|
+
- upgrade npm dependencies - (4323b60) - Clarence Manuel
|
|
10
|
+
- utilize bun catalogs - (40fe122) - Clarence Manuel
|
|
11
|
+
- bump node version [skip ci] - (04067be) - Clarence Manuel
|
|
12
|
+
|
|
13
|
+
- - -
|
|
14
|
+
|
|
15
|
+
## @omni-oss/set-version-v0.1.1 - 2026-02-07
|
|
16
|
+
#### Bug Fixes
|
|
17
|
+
- (**@omni-oss/set-version**) dist file names - (b6e453e) - Clarence Manuel
|
|
18
|
+
- declaration types output path - (ce90fa6) - Clarence Manuel
|
|
19
|
+
#### Miscellaneous Chores
|
|
20
|
+
- (**@omni-oss/set-version**) update cli dist name - (42df374) - Clarence Manuel
|
|
21
|
+
- (**@omni-oss/set-version**) update project dependencies [skip ci] - (51bd839) - Clarence Manuel
|
|
22
|
+
- use ^ for workspace package version [skip ci] - (89ba03b) - Clarence Manuel
|
|
23
|
+
- add dependencies to project.omni.yaml [skip ci] - (de71dd7) - Clarence Manuel
|
|
24
|
+
- add .npmignores [skip ci] - (14af7b3) - Clarence Manuel
|
|
25
|
+
- add publishConfig to existing packages [skip ci] - (5a48ec0) - Clarence Manuel
|
|
26
|
+
- update npm packages [skip ci] - (8fba262) - Clarence Manuel
|
|
27
|
+
|
|
28
|
+
- - -
|
|
29
|
+
|
|
5
30
|
## @omni-oss/set-version-v0.1.0 - 2026-01-31
|
|
6
31
|
#### Features
|
|
7
32
|
- (**@omni-oss/set-version**) improve error handling - (3f8a9fb) - Clarence Manuel
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./src-DacLUqIe.js");exports.BUILT_IN_PROFILES=e.BUILT_IN_PROFILES;exports.findConfig=e.findConfig;exports.setVersion=e.setVersion;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as r, r as s, t as i } from "./src-BoCeBNhe.mjs";
|
|
2
2
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
s as BUILT_IN_PROFILES,
|
|
4
|
+
i as findConfig,
|
|
5
|
+
r as setVersion
|
|
6
6
|
};
|
package/dist/set-version.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
> ${e.notChangedReasonMessage}`):console.log(` * [SKIPPED]: ${e.path}`)}else console.warn("No files updated")}catch(o){console.error(o),process.exit(1)}});
|
|
2
|
+
const i=require("./src-DacLUqIe.js");let d=require("@commander-js/extra-typings");var f="@omni-oss/set-version",g="Sets version of various package manifests",h="0.1.2",l=new d.Command;l.name(f).version(h).description(g).argument("<version>","What version to set").option("-d, --dir <dir>","Directory to set version in",process.cwd()).option("-B, --no-built-in-profiles","Do not use built-in profiles").option("--dry-run","Do not write changes to disk",!1).action(async(c,n)=>{try{n.dryRun&&console.log("Dry run enabled, no changes will be written to disk");const o=await i.findConfig(n.dir,!1),t=n.builtInProfiles?[...i.BUILT_IN_PROFILES,...o?.profiles??[]]:o?.profiles??[];if(!t.length){console.warn("No profiles are configured, nothing to do");return}const s=await i.setVersion(n.dir,c,t,{dryRun:n.dryRun});if(s.length){const r=s.filter(e=>e.changed),a=s.filter(e=>!e.changed);console.log(`Matched ${r.length} file(s), updated ${r.length} file(s), skipped ${a.length} file(s)`);for(const e of r)console.log(` * [UPDATED]: ${e.path}`);for(const e of a)e.notChangedReasonMessage?console.log(` * [SKIPPED]: ${e.path}
|
|
3
|
+
> ${e.notChangedReasonMessage}`):console.log(` * [SKIPPED]: ${e.path}`)}else console.warn("No files updated")}catch(o){console.error(o),process.exit(1)}});l.parseAsync();
|
package/dist/set-version.mjs
CHANGED
|
@@ -1,34 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { n as c, r as d, t as f } from "./src-BoCeBNhe.mjs";
|
|
3
|
+
import { Command as g } from "@commander-js/extra-typings";
|
|
4
|
+
var h = "@omni-oss/set-version", p = "Sets version of various package manifests", u = "0.1.2", a = new g();
|
|
5
5
|
a.name(h).version(u).description(p).argument("<version>", "What version to set").option("-d, --dir <dir>", "Directory to set version in", process.cwd()).option("-B, --no-built-in-profiles", "Do not use built-in profiles").option("--dry-run", "Do not write changes to disk", !1).action(async (l, o) => {
|
|
6
6
|
try {
|
|
7
|
-
o.dryRun && console.log(
|
|
8
|
-
|
|
9
|
-
);
|
|
10
|
-
const n = await d(o.dir, !1), i = o.builtInProfiles ? [...f, ...n?.profiles ?? []] : n?.profiles ?? [];
|
|
7
|
+
o.dryRun && console.log("Dry run enabled, no changes will be written to disk");
|
|
8
|
+
const n = await f(o.dir, !1), i = o.builtInProfiles ? [...d, ...n?.profiles ?? []] : n?.profiles ?? [];
|
|
11
9
|
if (!i.length) {
|
|
12
10
|
console.warn("No profiles are configured, nothing to do");
|
|
13
11
|
return;
|
|
14
12
|
}
|
|
15
|
-
const s = await
|
|
16
|
-
dryRun: o.dryRun
|
|
17
|
-
});
|
|
13
|
+
const s = await c(o.dir, l, i, { dryRun: o.dryRun });
|
|
18
14
|
if (s.length) {
|
|
19
|
-
const
|
|
20
|
-
console.log(
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (const e of r)
|
|
26
|
-
e.notChangedReasonMessage ? console.log(
|
|
27
|
-
` * [SKIPPED]: ${e.path}
|
|
28
|
-
> ${e.notChangedReasonMessage}`
|
|
29
|
-
) : console.log(` * [SKIPPED]: ${e.path}`);
|
|
30
|
-
} else
|
|
31
|
-
console.warn("No files updated");
|
|
15
|
+
const r = s.filter((e) => e.changed), t = s.filter((e) => !e.changed);
|
|
16
|
+
console.log(`Matched ${r.length} file(s), updated ${r.length} file(s), skipped ${t.length} file(s)`);
|
|
17
|
+
for (const e of r) console.log(` * [UPDATED]: ${e.path}`);
|
|
18
|
+
for (const e of t) e.notChangedReasonMessage ? console.log(` * [SKIPPED]: ${e.path}
|
|
19
|
+
> ${e.notChangedReasonMessage}`) : console.log(` * [SKIPPED]: ${e.path}`);
|
|
20
|
+
} else console.warn("No files updated");
|
|
32
21
|
} catch (n) {
|
|
33
22
|
console.error(n), process.exit(1);
|
|
34
23
|
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import u from "zod";
|
|
2
|
+
import { OptimizedSystem as U } from "@omni-oss/system-interface";
|
|
3
|
+
import h from "node:path";
|
|
4
|
+
import $ from "comment-json";
|
|
5
|
+
import { XMLBuilder as I, XMLParser as j } from "fast-xml-parser";
|
|
6
|
+
import V from "smol-toml";
|
|
7
|
+
import x from "yaml";
|
|
8
|
+
import S from "picomatch";
|
|
9
|
+
var o = /* @__PURE__ */ (function(t) {
|
|
10
|
+
return t.AUTO = "auto", t.YAML = "yaml", t.JSON = "json", t.TOML = "toml", t.XML = "xml", t;
|
|
11
|
+
})({}), Y = u.enum(o), dt = [
|
|
12
|
+
{
|
|
13
|
+
type: "path",
|
|
14
|
+
files: ["package.json"],
|
|
15
|
+
format: o.JSON,
|
|
16
|
+
path: ["version"]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: "regex",
|
|
20
|
+
files: ["Cargo.toml"],
|
|
21
|
+
pattern: '^\\s*version\\s*=\\s*"(?<version>.*)"\\s*$',
|
|
22
|
+
flags: "m"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: "path",
|
|
26
|
+
files: ["*.csproj"],
|
|
27
|
+
path: [
|
|
28
|
+
"Project",
|
|
29
|
+
"PropertyGroup",
|
|
30
|
+
"Version"
|
|
31
|
+
],
|
|
32
|
+
format: o.XML
|
|
33
|
+
}
|
|
34
|
+
], R = {
|
|
35
|
+
preserveOrder: !0,
|
|
36
|
+
commentPropName: "#comment",
|
|
37
|
+
ignoreAttributes: !1
|
|
38
|
+
}, A = {
|
|
39
|
+
__$$parser: new j(R),
|
|
40
|
+
__$$builder: new I(R),
|
|
41
|
+
parse: (t) => A.__$$parser.parse(t),
|
|
42
|
+
stringify: (t) => A.__$$builder.build(t)
|
|
43
|
+
};
|
|
44
|
+
function P(t, r, e = o.AUTO) {
|
|
45
|
+
switch (e === o.AUTO && (e = L(t)), e) {
|
|
46
|
+
case o.JSON:
|
|
47
|
+
return $.parse(r);
|
|
48
|
+
case o.YAML:
|
|
49
|
+
return x.parse(r);
|
|
50
|
+
case o.XML:
|
|
51
|
+
return A.parse(r);
|
|
52
|
+
case o.TOML:
|
|
53
|
+
return V.parse(r);
|
|
54
|
+
default:
|
|
55
|
+
throw new M(t);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function D(t, r, e = o.AUTO) {
|
|
59
|
+
switch (e === o.AUTO && (e = L(t)), e) {
|
|
60
|
+
case o.JSON:
|
|
61
|
+
return $.stringify(r, null, 4);
|
|
62
|
+
case o.YAML:
|
|
63
|
+
return x.stringify(r);
|
|
64
|
+
case o.XML:
|
|
65
|
+
return A.stringify(r);
|
|
66
|
+
case o.TOML:
|
|
67
|
+
return V.stringify(r);
|
|
68
|
+
default:
|
|
69
|
+
throw new M(t);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function L(t) {
|
|
73
|
+
switch (h.extname(t)) {
|
|
74
|
+
case ".json":
|
|
75
|
+
case ".jsonc":
|
|
76
|
+
return o.JSON;
|
|
77
|
+
case ".yaml":
|
|
78
|
+
case ".yml":
|
|
79
|
+
return o.YAML;
|
|
80
|
+
case ".xml":
|
|
81
|
+
return o.XML;
|
|
82
|
+
case ".toml":
|
|
83
|
+
return o.TOML;
|
|
84
|
+
default:
|
|
85
|
+
throw new M(t);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
var M = class extends Error {
|
|
89
|
+
constructor(t) {
|
|
90
|
+
super(`Unsupported file type for file ${t}`), super.name = this.constructor.name;
|
|
91
|
+
}
|
|
92
|
+
}, C = u.object({ files: u.string().array() }), b = C.extend({
|
|
93
|
+
path: u.array(u.union([u.string(), u.number()])),
|
|
94
|
+
format: Y.optional()
|
|
95
|
+
}), k = b.extend({ type: u.literal("path") }), H = C.extend({
|
|
96
|
+
pattern: u.string(),
|
|
97
|
+
flags: u.string().optional(),
|
|
98
|
+
capture_group: u.string().optional()
|
|
99
|
+
}), J = H.extend({ type: u.literal("regex") }), G = u.discriminatedUnion("type", [k, J]), z = u.object({ profiles: u.array(G).optional().default([]) }), B = [
|
|
100
|
+
"set-version.yaml",
|
|
101
|
+
"set-version.yml",
|
|
102
|
+
"set-version.toml",
|
|
103
|
+
"set-version.json",
|
|
104
|
+
"set-version.jsonc"
|
|
105
|
+
];
|
|
106
|
+
async function W(t, r, e) {
|
|
107
|
+
let n = h.resolve(t);
|
|
108
|
+
for (; await e.fs.isDirectory(n) && !Q(n); ) {
|
|
109
|
+
for (const a of B) {
|
|
110
|
+
const s = h.join(n, a);
|
|
111
|
+
if (await e.fs.pathExists(s) && await e.fs.isFile(s)) {
|
|
112
|
+
const f = P(s, await e.fs.readFileAsString(s)), i = z.safeParse(f);
|
|
113
|
+
if (i.success) return i.data;
|
|
114
|
+
throw new K(s, i.error.message);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
n = h.dirname(n);
|
|
118
|
+
}
|
|
119
|
+
if (r) throw new q(t);
|
|
120
|
+
}
|
|
121
|
+
var q = class extends Error {
|
|
122
|
+
constructor(t) {
|
|
123
|
+
super(t ? `No config found in ${t} or any parent directories` : "No config found"), this.dir = t, super.name = this.constructor.name;
|
|
124
|
+
}
|
|
125
|
+
}, K = class extends Error {
|
|
126
|
+
constructor(t, r) {
|
|
127
|
+
super(`Invalid config at ${t}: ${r}`), this.filePath = t, super.name = this.constructor.name;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
function Q(t) {
|
|
131
|
+
return h.parse(h.resolve(t)).root === t;
|
|
132
|
+
}
|
|
133
|
+
function X(t, r, e) {
|
|
134
|
+
return O(t, r, e, [], !1);
|
|
135
|
+
}
|
|
136
|
+
function O(t, r, e, n, a) {
|
|
137
|
+
if (r.length === 0) return e;
|
|
138
|
+
const [s, ...f] = r;
|
|
139
|
+
if (Array.isArray(t)) {
|
|
140
|
+
const c = s, l = a ? t.slice() : t;
|
|
141
|
+
if (!l[c]) throw new g(n);
|
|
142
|
+
return l[c] = O(l[c], f, e, [...n, c], a), l;
|
|
143
|
+
}
|
|
144
|
+
const i = s, p = a ? { ...t } : t;
|
|
145
|
+
if (!p[i]) throw new g(n);
|
|
146
|
+
return p[i] = O(p[i], f, e, [...n, i], a), p;
|
|
147
|
+
}
|
|
148
|
+
var g = class extends Error {
|
|
149
|
+
constructor(t) {
|
|
150
|
+
super(`No value at path ${t.join(".")}`), this.path = t, super.name = this.constructor.name;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
function Z(t, r, e, n) {
|
|
154
|
+
if (!r.test(t)) throw new F(r.source);
|
|
155
|
+
return t.replace(r, (a, ...s) => {
|
|
156
|
+
const f = s[s.length - 1], i = a, p = f[e];
|
|
157
|
+
return p === void 0 ? i : i.replace(p, n);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
var F = class extends Error {
|
|
161
|
+
constructor(t) {
|
|
162
|
+
super(`Regex ${t} did not match`), this.pattern = t, super.name = this.constructor.name;
|
|
163
|
+
}
|
|
164
|
+
}, v = /* @__PURE__ */ (function(t) {
|
|
165
|
+
return t.NO_VALUE_AT_PATH = "NO_VALUE_AT_PATH", t.REGEX_PATTERN_NOT_MATCHED = "REGEX_PATTERN_NOT_MATCHED", t.ALREADY_UP_TO_DATE = "ALREADY_UP_TO_DATE", t;
|
|
166
|
+
})({});
|
|
167
|
+
async function tt(t, r, e, n, a = {}) {
|
|
168
|
+
const s = S(Array.from(e.flatMap((c) => c.files))), f = e.map((c) => ({
|
|
169
|
+
...c,
|
|
170
|
+
glob: S(c.files)
|
|
171
|
+
})), i = await n.fs.readDirectory(t), p = [];
|
|
172
|
+
for (const c of i) {
|
|
173
|
+
if (!s(c) || !await n.fs.isFile(c)) continue;
|
|
174
|
+
const l = h.join(t, c), w = await n.fs.readFileAsString(l);
|
|
175
|
+
let m = w;
|
|
176
|
+
const N = f.filter((T) => T.glob(c));
|
|
177
|
+
if (!N.length) throw new et(c);
|
|
178
|
+
let y, E;
|
|
179
|
+
for (const T of N) try {
|
|
180
|
+
m = rt({
|
|
181
|
+
path: l,
|
|
182
|
+
content: m
|
|
183
|
+
}, r, T);
|
|
184
|
+
} catch (d) {
|
|
185
|
+
if (d instanceof g)
|
|
186
|
+
y = v.NO_VALUE_AT_PATH, E = `No value at path ${d.path.join(".")}, make sure the path is correct and it exists`;
|
|
187
|
+
else if (d instanceof F)
|
|
188
|
+
y = v.REGEX_PATTERN_NOT_MATCHED, E = `Regex pattern ${d.pattern} did not match`;
|
|
189
|
+
else throw d;
|
|
190
|
+
}
|
|
191
|
+
const _ = w !== m;
|
|
192
|
+
p.push({
|
|
193
|
+
path: l,
|
|
194
|
+
changed: _,
|
|
195
|
+
notChangedReason: _ ? void 0 : y ?? v.ALREADY_UP_TO_DATE,
|
|
196
|
+
notChangedReasonMessage: _ ? void 0 : E ?? "File already up to date"
|
|
197
|
+
}), !a.dryRun && w !== m && await n.fs.writeStringToFile(l, m);
|
|
198
|
+
}
|
|
199
|
+
return p;
|
|
200
|
+
}
|
|
201
|
+
var et = class extends Error {
|
|
202
|
+
constructor(t) {
|
|
203
|
+
super(`No profile found for file ${t}`), super.name = this.constructor.name;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
function rt(t, r, e) {
|
|
207
|
+
switch (e.type) {
|
|
208
|
+
case "path": {
|
|
209
|
+
const n = (e.format === o.AUTO ? L(t.path) : e.format) ?? o.AUTO;
|
|
210
|
+
if (e.format === o.YAML) {
|
|
211
|
+
const a = x.parseDocument(t.content);
|
|
212
|
+
return a.setIn(e.path, r), a.toString();
|
|
213
|
+
} else return e.format === o.XML ? ot(t, r, e, n) : nt(t, r, e, n);
|
|
214
|
+
}
|
|
215
|
+
case "regex": {
|
|
216
|
+
const n = new RegExp(e.pattern, e.flags ?? "m");
|
|
217
|
+
return Z(t.content, n, e.capture_group ?? "version", r);
|
|
218
|
+
}
|
|
219
|
+
default:
|
|
220
|
+
throw new at(e.type);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function nt(t, r, e, n) {
|
|
224
|
+
const a = X(P(t.path, t.content, n), e.path, r);
|
|
225
|
+
return D(t.path, a, n);
|
|
226
|
+
}
|
|
227
|
+
function ot(t, r, e, n) {
|
|
228
|
+
const a = P(t.path, t.content, n), s = X(a, st(e.path, a), r);
|
|
229
|
+
return D(t.path, s, n);
|
|
230
|
+
}
|
|
231
|
+
function st(t, r) {
|
|
232
|
+
const e = [];
|
|
233
|
+
let n = r;
|
|
234
|
+
for (const s of t) {
|
|
235
|
+
const f = Array.from(n.entries());
|
|
236
|
+
for (const [i, p] of f) {
|
|
237
|
+
if (p[s]) {
|
|
238
|
+
e.push(i, s), n = p[s];
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
if (f.length === i + 1) throw new g(t);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const a = Array.from(n.entries());
|
|
245
|
+
for (const [s, f] of a) {
|
|
246
|
+
if (f["#text"]) {
|
|
247
|
+
e.push(s, "#text");
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
if (a.length === s + 1) throw new g(t);
|
|
251
|
+
}
|
|
252
|
+
return e;
|
|
253
|
+
}
|
|
254
|
+
var at = class extends Error {
|
|
255
|
+
constructor(t) {
|
|
256
|
+
super(`Unsupported profile type ${t}`), super.name = this.constructor.name;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
async function gt(t, r, e, n = {}) {
|
|
260
|
+
return tt(t, r, e, await U.create(), n);
|
|
261
|
+
}
|
|
262
|
+
async function At(t, r) {
|
|
263
|
+
return W(t, r, await U.create());
|
|
264
|
+
}
|
|
265
|
+
export {
|
|
266
|
+
gt as n,
|
|
267
|
+
dt as r,
|
|
268
|
+
At as t
|
|
269
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var q=Object.create,D=Object.defineProperty,Y=Object.getOwnPropertyDescriptor,H=Object.getOwnPropertyNames,z=Object.getPrototypeOf,G=Object.prototype.hasOwnProperty,J=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(var o=H(r),a=0,c=o.length,s;a<c;a++)s=o[a],!G.call(e,s)&&s!==t&&D(e,s,{get:(l=>r[l]).bind(null,s),enumerable:!(n=Y(r,s))||n.enumerable});return e},h=(e,r,t)=>(t=e!=null?q(z(e)):{},J(r||!e||!e.__esModule?D(t,"default",{value:e,enumerable:!0}):t,e));let u=require("zod");u=h(u);let V=require("@omni-oss/system-interface"),d=require("node:path");d=h(d);let w=require("comment-json");w=h(w);let U=require("fast-xml-parser"),O=require("smol-toml");O=h(O);let m=require("yaml");m=h(m);let A=require("picomatch");A=h(A);var i=(function(e){return e.AUTO="auto",e.YAML="yaml",e.JSON="json",e.TOML="toml",e.XML="xml",e})({}),B=u.default.enum(i),W=[{type:"path",files:["package.json"],format:i.JSON,path:["version"]},{type:"regex",files:["Cargo.toml"],pattern:'^\\s*version\\s*=\\s*"(?<version>.*)"\\s*$',flags:"m"},{type:"path",files:["*.csproj"],path:["Project","PropertyGroup","Version"],format:i.XML}],$={preserveOrder:!0,commentPropName:"#comment",ignoreAttributes:!1},P={__$$parser:new U.XMLParser($),__$$builder:new U.XMLBuilder($),parse:e=>P.__$$parser.parse(e),stringify:e=>P.__$$builder.build(e)};function S(e,r,t=i.AUTO){switch(t===i.AUTO&&(t=b(e)),t){case i.JSON:return w.default.parse(r);case i.YAML:return m.default.parse(r);case i.XML:return P.parse(r);case i.TOML:return O.default.parse(r);default:throw new j(e)}}function C(e,r,t=i.AUTO){switch(t===i.AUTO&&(t=b(e)),t){case i.JSON:return w.default.stringify(r,null,4);case i.YAML:return m.default.stringify(r);case i.XML:return P.stringify(r);case i.TOML:return O.default.stringify(r);default:throw new j(e)}}function b(e){switch(d.default.extname(e)){case".json":case".jsonc":return i.JSON;case".yaml":case".yml":return i.YAML;case".xml":return i.XML;case".toml":return i.TOML;default:throw new j(e)}}var j=class extends Error{constructor(e){super(`Unsupported file type for file ${e}`),super.name=this.constructor.name}},I=u.default.object({files:u.default.string().array()}),k=I.extend({path:u.default.array(u.default.union([u.default.string(),u.default.number()])),format:B.optional()}),K=k.extend({type:u.default.literal("path")}),Q=I.extend({pattern:u.default.string(),flags:u.default.string().optional(),capture_group:u.default.string().optional()}),Z=Q.extend({type:u.default.literal("regex")}),ee=u.default.discriminatedUnion("type",[K,Z]),te=u.default.object({profiles:u.default.array(ee).optional().default([])}),re=["set-version.yaml","set-version.yml","set-version.toml","set-version.json","set-version.jsonc"];async function ne(e,r,t){let n=d.default.resolve(e);for(;await t.fs.isDirectory(n)&&!se(n);){for(const o of re){const a=d.default.join(n,o);if(await t.fs.pathExists(a)&&await t.fs.isFile(a)){const c=S(a,await t.fs.readFileAsString(a)),s=te.safeParse(c);if(s.success)return s.data;throw new oe(a,s.error.message)}}n=d.default.dirname(n)}if(r)throw new ae(e)}var ae=class extends Error{constructor(e){super(e?`No config found in ${e} or any parent directories`:"No config found"),this.dir=e,super.name=this.constructor.name}},oe=class extends Error{constructor(e,r){super(`Invalid config at ${e}: ${r}`),this.filePath=e,super.name=this.constructor.name}};function se(e){return d.default.parse(d.default.resolve(e)).root===e}function X(e,r,t){return N(e,r,t,[],!1)}function N(e,r,t,n,o){if(r.length===0)return t;const[a,...c]=r;if(Array.isArray(e)){const f=a,p=o?e.slice():e;if(!p[f])throw new y(n);return p[f]=N(p[f],c,t,[...n,f],o),p}const s=a,l=o?{...e}:e;if(!l[s])throw new y(n);return l[s]=N(l[s],c,t,[...n,s],o),l}var y=class extends Error{constructor(e){super(`No value at path ${e.join(".")}`),this.path=e,super.name=this.constructor.name}};function ie(e,r,t,n){if(!r.test(e))throw new F(r.source);return e.replace(r,(o,...a)=>{const c=a[a.length-1],s=o,l=c[t];return l===void 0?s:s.replace(l,n)})}var F=class extends Error{constructor(e){super(`Regex ${e} did not match`),this.pattern=e,super.name=this.constructor.name}},L=(function(e){return e.NO_VALUE_AT_PATH="NO_VALUE_AT_PATH",e.REGEX_PATTERN_NOT_MATCHED="REGEX_PATTERN_NOT_MATCHED",e.ALREADY_UP_TO_DATE="ALREADY_UP_TO_DATE",e})({});async function ue(e,r,t,n,o={}){const a=(0,A.default)(Array.from(t.flatMap(f=>f.files))),c=t.map(f=>({...f,glob:(0,A.default)(f.files)})),s=await n.fs.readDirectory(e),l=[];for(const f of s){if(!a(f)||!await n.fs.isFile(f))continue;const p=d.default.join(e,f),E=await n.fs.readFileAsString(p);let g=E;const R=c.filter(M=>M.glob(f));if(!R.length)throw new ce(f);let v,T;for(const M of R)try{g=le({path:p,content:g},r,M)}catch(_){if(_ instanceof y)v=L.NO_VALUE_AT_PATH,T=`No value at path ${_.path.join(".")}, make sure the path is correct and it exists`;else if(_ instanceof F)v=L.REGEX_PATTERN_NOT_MATCHED,T=`Regex pattern ${_.pattern} did not match`;else throw _}const x=E!==g;l.push({path:p,changed:x,notChangedReason:x?void 0:v??L.ALREADY_UP_TO_DATE,notChangedReasonMessage:x?void 0:T??"File already up to date"}),!o.dryRun&&E!==g&&await n.fs.writeStringToFile(p,g)}return l}var ce=class extends Error{constructor(e){super(`No profile found for file ${e}`),super.name=this.constructor.name}};function le(e,r,t){switch(t.type){case"path":{const n=(t.format===i.AUTO?b(e.path):t.format)??i.AUTO;if(t.format===i.YAML){const o=m.default.parseDocument(e.content);return o.setIn(t.path,r),o.toString()}else return t.format===i.XML?pe(e,r,t,n):fe(e,r,t,n)}case"regex":{const n=new RegExp(t.pattern,t.flags??"m");return ie(e.content,n,t.capture_group??"version",r)}default:throw new he(t.type)}}function fe(e,r,t,n){const o=X(S(e.path,e.content,n),t.path,r);return C(e.path,o,n)}function pe(e,r,t,n){const o=S(e.path,e.content,n),a=X(o,de(t.path,o),r);return C(e.path,a,n)}function de(e,r){const t=[];let n=r;for(const a of e){const c=Array.from(n.entries());for(const[s,l]of c){if(l[a]){t.push(s,a),n=l[a];break}if(c.length===s+1)throw new y(e)}}const o=Array.from(n.entries());for(const[a,c]of o){if(c["#text"]){t.push(a,"#text");break}if(o.length===a+1)throw new y(e)}return t}var he=class extends Error{constructor(e){super(`Unsupported profile type ${e}`),super.name=this.constructor.name}};async function ge(e,r,t,n={}){return ue(e,r,t,await V.OptimizedSystem.create(),n)}async function _e(e,r){return ne(e,r,await V.OptimizedSystem.create())}Object.defineProperty(exports,"BUILT_IN_PROFILES",{enumerable:!0,get:function(){return W}});Object.defineProperty(exports,"__toESM",{enumerable:!0,get:function(){return h}});Object.defineProperty(exports,"findConfig",{enumerable:!0,get:function(){return _e}});Object.defineProperty(exports,"setVersion",{enumerable:!0,get:function(){return ge}});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omni-oss/set-version",
|
|
3
3
|
"description": "Sets version of various package manifests",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"bin": "./dist/set-version.mjs",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -22,23 +22,23 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"zod": "^4.3.6",
|
|
24
24
|
"commander": "^14.0.3",
|
|
25
|
-
"@commander-js/extra-typings": "14.0.0",
|
|
25
|
+
"@commander-js/extra-typings": "^14.0.0",
|
|
26
26
|
"@omni-oss/system-interface": "^0.1.0",
|
|
27
|
-
"fast-xml-parser": "^5.3
|
|
27
|
+
"fast-xml-parser": "^5.5.3",
|
|
28
28
|
"yaml": "^2.8.2",
|
|
29
|
-
"comment-json": "^4.
|
|
29
|
+
"comment-json": "^4.6.2",
|
|
30
30
|
"smol-toml": "^1.6.0",
|
|
31
31
|
"picomatch": "^4.0.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@omni-oss/tsconfig": "
|
|
35
|
-
"@omni-oss/vite-config": "
|
|
36
|
-
"@omni-oss/vitest-config": "
|
|
37
|
-
"vite": "^
|
|
38
|
-
"vitest": "^4.0
|
|
39
|
-
"@types/node": "25.
|
|
40
|
-
"@types/bun": "^1.3.
|
|
34
|
+
"@omni-oss/tsconfig": "workspace:^",
|
|
35
|
+
"@omni-oss/vite-config": "workspace:^",
|
|
36
|
+
"@omni-oss/vitest-config": "workspace:^",
|
|
37
|
+
"vite": "^8.0.0",
|
|
38
|
+
"vitest": "^4.1.0",
|
|
39
|
+
"@types/node": "25.5.0",
|
|
40
|
+
"@types/bun": "^1.3.10",
|
|
41
41
|
"@types/picomatch": "^4.0.2",
|
|
42
42
|
"typescript": "^5.9.3"
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|
package/dist/index-BCvo12D0.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const f=require("zod"),v=require("@omni-oss/system-interface"),h=require("node:path"),C=require("comment-json"),$=require("fast-xml-parser"),I=require("smol-toml"),_=require("yaml"),R=require("picomatch");var o=(e=>(e.AUTO="auto",e.YAML="yaml",e.JSON="json",e.TOML="toml",e.XML="xml",e))(o||{});const b=f.enum(o),z=[{type:"path",files:["package.json"],format:o.JSON,path:["version"]},{type:"regex",files:["Cargo.toml"],pattern:'^\\s*version\\s*=\\s*"(?<version>.*)"\\s*$',flags:"m"},{type:"path",files:["*.csproj"],path:["Project","PropertyGroup","Version"],format:o.XML}],U={preserveOrder:!0,commentPropName:"#comment",ignoreAttributes:!1},y={__$$parser:new $.XMLParser(U),__$$builder:new $.XMLBuilder(U),parse:e=>y.__$$parser.parse(e),stringify:e=>y.__$$builder.build(e)};function P(e,t,r=o.AUTO){switch(r===o.AUTO&&(r=S(e)),r){case o.JSON:return C.parse(t);case o.YAML:return _.parse(t);case o.XML:return y.parse(t);case o.TOML:return I.parse(t);default:throw new T(e)}}function V(e,t,r=o.AUTO){switch(r===o.AUTO&&(r=S(e)),r){case o.JSON:return C.stringify(t,null,4);case o.YAML:return _.stringify(t);case o.XML:return y.stringify(t);case o.TOML:return I.stringify(t);default:throw new T(e)}}function S(e){switch(h.extname(e)){case".json":case".jsonc":return o.JSON;case".yaml":case".yml":return o.YAML;case".xml":return o.XML;case".toml":return o.TOML;default:throw new T(e)}}class T extends Error{constructor(t){super(`Unsupported file type for file ${t}`),super.name=this.constructor.name}}const X=f.object({files:f.string().array()}),D=X.extend({path:f.array(f.union([f.string(),f.number()])),format:b.optional()}),q=D.extend({type:f.literal("path")}),Y=X.extend({pattern:f.string(),flags:f.string().optional(),capture_group:f.string().optional()}),k=Y.extend({type:f.literal("regex")}),G=f.discriminatedUnion("type",[q,k]),J=f.object({profiles:f.array(G).optional().default([])}),B=["set-version.yaml","set-version.yml","set-version.toml","set-version.json","set-version.jsonc"];async function H(e,t,r){let n=h.resolve(e);for(;await r.fs.isDirectory(n)&&!Q(n);){for(const a of B){const s=h.join(n,a);if(await r.fs.pathExists(s)&&await r.fs.isFile(s)){const i=await r.fs.readFileAsString(s),u=P(s,i),c=J.safeParse(u);if(c.success)return c.data;throw new K(s,c.error.message)}}n=h.dirname(n)}if(t)throw new W(e)}class W extends Error{constructor(t){var r=(...n)=>(super(...n),this.dir=t,this);r(t?`No config found in ${t}`:"No config found"),super.name=this.constructor.name}}class K extends Error{constructor(t,r){super(`Invalid config at ${t}: ${r}`),this.filePath=t,super.name=this.constructor.name}}function Q(e){return h.parse(h.resolve(e)).root===e}function F(e,t,r){return M(e,t,r,[])}function M(e,t,r,n,a){if(t.length===0)return r;const[s,...i]=t;if(Array.isArray(e)){const p=s,l=e;if(!l[p])throw new m(n);return l[p]=M(l[p],i,r,[...n,p]),l}const u=s,c=e;if(!c[u])throw new m(n);return c[u]=M(c[u],i,r,[...n,u]),c}class m extends Error{constructor(t){super(`No value at path ${t.join(".")}`),this.path=t,super.name=this.constructor.name}}function Z(e,t,r,n){if(!t.test(e))throw new j(t.source);return e.replace(t,(a,...s)=>{const i=s[s.length-1],u=a,c=i[r];return c===void 0?u:u.replace(c,n)})}class j extends Error{constructor(t){super(`Regex ${t} did not match`),this.pattern=t,super.name=this.constructor.name}}async function ee(e,t,r,n,a={}){const s=Array.from(r.flatMap(l=>l.files)),i=R(s),u=r.map(l=>({...l,glob:R(l.files)})),c=await n.fs.readDirectory(e),p=[];for(const l of c){if(!i(l)||!await n.fs.isFile(l))continue;const w=h.join(e,l),A=await n.fs.readFileAsString(w);let d=A;const N=u.filter(L=>L.glob(l));if(!N.length)throw new te(l);let x,E;for(const L of N)try{d=re({path:w,content:d},t,L)}catch(g){if(g instanceof m)x="NO_VALUE_AT_PATH",E=`No value at path ${g.path.join(".")}, make sure the path is correct and it exists`;else if(g instanceof j)x="REGEX_PATTERN_NOT_MATCHED",E=`Regex pattern ${g.pattern} did not match`;else throw g}const O=A!==d;p.push({path:w,changed:O,notChangedReason:O?void 0:x??"ALREADY_UP_TO_DATE",notChangedReasonMessage:O?void 0:E??"File already up to date"}),!a.dryRun&&A!==d&&await n.fs.writeStringToFile(w,d)}return p}class te extends Error{constructor(t){super(`No profile found for file ${t}`),super.name=this.constructor.name}}function re(e,t,r){switch(r.type){case"path":{const n=(r.format===o.AUTO?S(e.path):r.format)??o.AUTO;if(r.format===o.YAML){const a=_.parseDocument(e.content);return a.setIn(r.path,t),a.toString()}else return r.format===o.XML?se(e,t,r,n):ne(e,t,r,n)}case"regex":{const n=new RegExp(r.pattern,r.flags??"m");return Z(e.content,n,r.capture_group??"version",t)}default:throw new ae(r.type)}}function ne(e,t,r,n){const a=P(e.path,e.content,n),s=F(a,r.path,t);return V(e.path,s,n)}function se(e,t,r,n){const a=P(e.path,e.content,n),s=oe(r.path,a),i=F(a,s,t);return V(e.path,i,n)}function oe(e,t){const r=[];let n=t;for(const s of e){const i=Array.from(n.entries());for(const[u,c]of i){if(c[s]){r.push(u,s),n=c[s];break}if(i.length===u+1)throw new m(e)}}const a=Array.from(n.entries());for(const[s,i]of a){if(i["#text"]){r.push(s,"#text");break}if(a.length===s+1)throw new m(e)}return r}class ae extends Error{constructor(t){super(`Unsupported profile type ${t}`),super.name=this.constructor.name}}async function ie(e,t,r,n={}){return ee(e,t,r,await v.OptimizedSystem.create(),n)}async function ce(e,t){return H(e,t,await v.OptimizedSystem.create())}exports.BUILT_IN_PROFILES=z;exports.findConfig=ce;exports.setVersion=ie;
|
package/dist/index-DjY1h20_.mjs
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import l from "zod";
|
|
2
|
-
import { OptimizedSystem as v } from "@omni-oss/system-interface";
|
|
3
|
-
import h from "node:path";
|
|
4
|
-
import U from "comment-json";
|
|
5
|
-
import { XMLBuilder as I, XMLParser as b } from "fast-xml-parser";
|
|
6
|
-
import C from "smol-toml";
|
|
7
|
-
import _ from "yaml";
|
|
8
|
-
import $ from "picomatch";
|
|
9
|
-
var s = /* @__PURE__ */ ((t) => (t.AUTO = "auto", t.YAML = "yaml", t.JSON = "json", t.TOML = "toml", t.XML = "xml", t))(s || {});
|
|
10
|
-
const D = l.enum(s), dt = [
|
|
11
|
-
{
|
|
12
|
-
type: "path",
|
|
13
|
-
files: ["package.json"],
|
|
14
|
-
format: s.JSON,
|
|
15
|
-
path: ["version"]
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
type: "regex",
|
|
19
|
-
files: ["Cargo.toml"],
|
|
20
|
-
pattern: '^\\s*version\\s*=\\s*"(?<version>.*)"\\s*$',
|
|
21
|
-
flags: "m"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
type: "path",
|
|
25
|
-
files: ["*.csproj"],
|
|
26
|
-
path: ["Project", "PropertyGroup", "Version"],
|
|
27
|
-
format: s.XML
|
|
28
|
-
}
|
|
29
|
-
], R = {
|
|
30
|
-
preserveOrder: !0,
|
|
31
|
-
// Required to keep comments near their tags
|
|
32
|
-
commentPropName: "#comment",
|
|
33
|
-
// Captures comments into this key
|
|
34
|
-
ignoreAttributes: !1
|
|
35
|
-
}, y = {
|
|
36
|
-
__$$parser: new b(R),
|
|
37
|
-
__$$builder: new I(R),
|
|
38
|
-
parse: (t) => y.__$$parser.parse(t),
|
|
39
|
-
stringify: (t) => y.__$$builder.build(t)
|
|
40
|
-
};
|
|
41
|
-
function P(t, e, r = s.AUTO) {
|
|
42
|
-
switch (r === s.AUTO && (r = S(t)), r) {
|
|
43
|
-
case s.JSON:
|
|
44
|
-
return U.parse(e);
|
|
45
|
-
case s.YAML:
|
|
46
|
-
return _.parse(e);
|
|
47
|
-
case s.XML:
|
|
48
|
-
return y.parse(e);
|
|
49
|
-
case s.TOML:
|
|
50
|
-
return C.parse(e);
|
|
51
|
-
default:
|
|
52
|
-
throw new T(t);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function V(t, e, r = s.AUTO) {
|
|
56
|
-
switch (r === s.AUTO && (r = S(t)), r) {
|
|
57
|
-
case s.JSON:
|
|
58
|
-
return U.stringify(e, null, 4);
|
|
59
|
-
case s.YAML:
|
|
60
|
-
return _.stringify(e);
|
|
61
|
-
case s.XML:
|
|
62
|
-
return y.stringify(e);
|
|
63
|
-
case s.TOML:
|
|
64
|
-
return C.stringify(e);
|
|
65
|
-
default:
|
|
66
|
-
throw new T(t);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function S(t) {
|
|
70
|
-
switch (h.extname(t)) {
|
|
71
|
-
case ".json":
|
|
72
|
-
case ".jsonc":
|
|
73
|
-
return s.JSON;
|
|
74
|
-
case ".yaml":
|
|
75
|
-
case ".yml":
|
|
76
|
-
return s.YAML;
|
|
77
|
-
case ".xml":
|
|
78
|
-
return s.XML;
|
|
79
|
-
case ".toml":
|
|
80
|
-
return s.TOML;
|
|
81
|
-
default:
|
|
82
|
-
throw new T(t);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
class T extends Error {
|
|
86
|
-
constructor(e) {
|
|
87
|
-
super(`Unsupported file type for file ${e}`), super.name = this.constructor.name;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const X = l.object({
|
|
91
|
-
files: l.string().array()
|
|
92
|
-
}), z = X.extend({
|
|
93
|
-
path: l.array(l.union([l.string(), l.number()])),
|
|
94
|
-
format: D.optional()
|
|
95
|
-
}), Y = z.extend({
|
|
96
|
-
type: l.literal("path")
|
|
97
|
-
}), k = X.extend({
|
|
98
|
-
pattern: l.string(),
|
|
99
|
-
flags: l.string().optional(),
|
|
100
|
-
capture_group: l.string().optional()
|
|
101
|
-
}), G = k.extend({
|
|
102
|
-
type: l.literal("regex")
|
|
103
|
-
}), J = l.discriminatedUnion("type", [
|
|
104
|
-
Y,
|
|
105
|
-
G
|
|
106
|
-
]), B = l.object({
|
|
107
|
-
profiles: l.array(J).optional().default([])
|
|
108
|
-
}), H = [
|
|
109
|
-
"set-version.yaml",
|
|
110
|
-
"set-version.yml",
|
|
111
|
-
"set-version.toml",
|
|
112
|
-
"set-version.json",
|
|
113
|
-
"set-version.jsonc"
|
|
114
|
-
];
|
|
115
|
-
async function W(t, e, r) {
|
|
116
|
-
let n = h.resolve(t);
|
|
117
|
-
for (; await r.fs.isDirectory(n) && !Q(n); ) {
|
|
118
|
-
for (const a of H) {
|
|
119
|
-
const o = h.join(n, a);
|
|
120
|
-
if (await r.fs.pathExists(o) && await r.fs.isFile(o)) {
|
|
121
|
-
const i = await r.fs.readFileAsString(o), u = P(o, i), c = B.safeParse(u);
|
|
122
|
-
if (c.success)
|
|
123
|
-
return c.data;
|
|
124
|
-
throw new K(
|
|
125
|
-
o,
|
|
126
|
-
c.error.message
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
n = h.dirname(n);
|
|
131
|
-
}
|
|
132
|
-
if (e)
|
|
133
|
-
throw new q(t);
|
|
134
|
-
}
|
|
135
|
-
class q extends Error {
|
|
136
|
-
constructor(e) {
|
|
137
|
-
var r = (...n) => (super(...n), this.dir = e, this);
|
|
138
|
-
r(e ? `No config found in ${e}` : "No config found"), super.name = this.constructor.name;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
class K extends Error {
|
|
142
|
-
constructor(e, r) {
|
|
143
|
-
super(`Invalid config at ${e}: ${r}`), this.filePath = e, super.name = this.constructor.name;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function Q(t) {
|
|
147
|
-
return h.parse(h.resolve(t)).root === t;
|
|
148
|
-
}
|
|
149
|
-
function j(t, e, r) {
|
|
150
|
-
return L(t, e, r, []);
|
|
151
|
-
}
|
|
152
|
-
function L(t, e, r, n, a) {
|
|
153
|
-
if (e.length === 0)
|
|
154
|
-
return r;
|
|
155
|
-
const [o, ...i] = e;
|
|
156
|
-
if (Array.isArray(t)) {
|
|
157
|
-
const p = o, f = t;
|
|
158
|
-
if (!f[p])
|
|
159
|
-
throw new g(n);
|
|
160
|
-
return f[p] = L(
|
|
161
|
-
f[p],
|
|
162
|
-
// biome-ignore lint/suspicious/noExplicitAny: expected runtime code
|
|
163
|
-
i,
|
|
164
|
-
r,
|
|
165
|
-
[...n, p]
|
|
166
|
-
), f;
|
|
167
|
-
}
|
|
168
|
-
const u = o, c = t;
|
|
169
|
-
if (!c[u])
|
|
170
|
-
throw new g(n);
|
|
171
|
-
return c[u] = L(
|
|
172
|
-
c[u],
|
|
173
|
-
// biome-ignore lint/suspicious/noExplicitAny: expected runtime code
|
|
174
|
-
i,
|
|
175
|
-
r,
|
|
176
|
-
[...n, u]
|
|
177
|
-
), c;
|
|
178
|
-
}
|
|
179
|
-
class g extends Error {
|
|
180
|
-
constructor(e) {
|
|
181
|
-
super(`No value at path ${e.join(".")}`), this.path = e, super.name = this.constructor.name;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
function Z(t, e, r, n) {
|
|
185
|
-
if (!e.test(t)) throw new F(e.source);
|
|
186
|
-
return t.replace(e, (a, ...o) => {
|
|
187
|
-
const i = o[o.length - 1], u = a, c = i[r];
|
|
188
|
-
return c === void 0 ? u : u.replace(c, n);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
class F extends Error {
|
|
192
|
-
constructor(e) {
|
|
193
|
-
super(`Regex ${e} did not match`), this.pattern = e, super.name = this.constructor.name;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
async function tt(t, e, r, n, a = {}) {
|
|
197
|
-
const o = Array.from(r.flatMap((f) => f.files)), i = $(o), u = r.map((f) => ({
|
|
198
|
-
...f,
|
|
199
|
-
glob: $(f.files)
|
|
200
|
-
})), c = await n.fs.readDirectory(t), p = [];
|
|
201
|
-
for (const f of c) {
|
|
202
|
-
if (!i(f) || !await n.fs.isFile(f))
|
|
203
|
-
continue;
|
|
204
|
-
const w = h.join(t, f), A = await n.fs.readFileAsString(w);
|
|
205
|
-
let m = A;
|
|
206
|
-
const N = u.filter((O) => O.glob(f));
|
|
207
|
-
if (!N.length)
|
|
208
|
-
throw new et(f);
|
|
209
|
-
let x, E;
|
|
210
|
-
for (const O of N)
|
|
211
|
-
try {
|
|
212
|
-
m = rt(
|
|
213
|
-
{ path: w, content: m },
|
|
214
|
-
e,
|
|
215
|
-
O
|
|
216
|
-
);
|
|
217
|
-
} catch (d) {
|
|
218
|
-
if (d instanceof g)
|
|
219
|
-
x = "NO_VALUE_AT_PATH", E = `No value at path ${d.path.join(
|
|
220
|
-
"."
|
|
221
|
-
)}, make sure the path is correct and it exists`;
|
|
222
|
-
else if (d instanceof F)
|
|
223
|
-
x = "REGEX_PATTERN_NOT_MATCHED", E = `Regex pattern ${d.pattern} did not match`;
|
|
224
|
-
else
|
|
225
|
-
throw d;
|
|
226
|
-
}
|
|
227
|
-
const M = A !== m;
|
|
228
|
-
p.push({
|
|
229
|
-
path: w,
|
|
230
|
-
changed: M,
|
|
231
|
-
notChangedReason: M ? void 0 : x ?? "ALREADY_UP_TO_DATE",
|
|
232
|
-
notChangedReasonMessage: M ? void 0 : E ?? "File already up to date"
|
|
233
|
-
}), !a.dryRun && A !== m && await n.fs.writeStringToFile(w, m);
|
|
234
|
-
}
|
|
235
|
-
return p;
|
|
236
|
-
}
|
|
237
|
-
class et extends Error {
|
|
238
|
-
constructor(e) {
|
|
239
|
-
super(`No profile found for file ${e}`), super.name = this.constructor.name;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function rt(t, e, r) {
|
|
243
|
-
switch (r.type) {
|
|
244
|
-
case "path": {
|
|
245
|
-
const n = (r.format === s.AUTO ? S(t.path) : r.format) ?? s.AUTO;
|
|
246
|
-
if (r.format === s.YAML) {
|
|
247
|
-
const a = _.parseDocument(t.content);
|
|
248
|
-
return a.setIn(r.path, e), a.toString();
|
|
249
|
-
} else return r.format === s.XML ? ot(t, e, r, n) : nt(
|
|
250
|
-
t,
|
|
251
|
-
e,
|
|
252
|
-
r,
|
|
253
|
-
n
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
case "regex": {
|
|
257
|
-
const n = new RegExp(r.pattern, r.flags ?? "m");
|
|
258
|
-
return Z(
|
|
259
|
-
t.content,
|
|
260
|
-
n,
|
|
261
|
-
r.capture_group ?? "version",
|
|
262
|
-
e
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
default:
|
|
266
|
-
throw new at(r.type);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
function nt(t, e, r, n) {
|
|
270
|
-
const a = P(t.path, t.content, n), o = j(a, r.path, e);
|
|
271
|
-
return V(t.path, o, n);
|
|
272
|
-
}
|
|
273
|
-
function ot(t, e, r, n) {
|
|
274
|
-
const a = P(t.path, t.content, n), o = st(r.path, a), i = j(a, o, e);
|
|
275
|
-
return V(t.path, i, n);
|
|
276
|
-
}
|
|
277
|
-
function st(t, e) {
|
|
278
|
-
const r = [];
|
|
279
|
-
let n = e;
|
|
280
|
-
for (const o of t) {
|
|
281
|
-
const i = Array.from(n.entries());
|
|
282
|
-
for (const [u, c] of i) {
|
|
283
|
-
if (c[o]) {
|
|
284
|
-
r.push(u, o), n = c[o];
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
if (i.length === u + 1)
|
|
288
|
-
throw new g(t);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
const a = Array.from(n.entries());
|
|
292
|
-
for (const [o, i] of a) {
|
|
293
|
-
if (i["#text"]) {
|
|
294
|
-
r.push(o, "#text");
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
if (a.length === o + 1)
|
|
298
|
-
throw new g(t);
|
|
299
|
-
}
|
|
300
|
-
return r;
|
|
301
|
-
}
|
|
302
|
-
class at extends Error {
|
|
303
|
-
constructor(e) {
|
|
304
|
-
super(`Unsupported profile type ${e}`), super.name = this.constructor.name;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
async function gt(t, e, r, n = {}) {
|
|
308
|
-
return tt(
|
|
309
|
-
t,
|
|
310
|
-
e,
|
|
311
|
-
r,
|
|
312
|
-
await v.create(),
|
|
313
|
-
n
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
async function wt(t, e) {
|
|
317
|
-
return W(t, e, await v.create());
|
|
318
|
-
}
|
|
319
|
-
export {
|
|
320
|
-
dt as B,
|
|
321
|
-
wt as f,
|
|
322
|
-
gt as s
|
|
323
|
-
};
|