@omni-oss/set-version 0.1.2 → 0.2.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 CHANGED
@@ -2,6 +2,14 @@
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.2.0 - 2026-03-21
6
+ #### Features
7
+ - implement --arg flag for passing custom args - (25d09a9) - Clarence Manuel
8
+ #### Miscellaneous Chores
9
+ - update vite configs - (e326f27) - Clarence Manuel
10
+
11
+ - - -
12
+
5
13
  ## @omni-oss/set-version-v0.1.2 - 2026-03-14
6
14
  #### Bug Fixes
7
15
  - error when constructing NoConfigFoundError - (804af84) - Clarence Manuel
package/dist/index.cjs CHANGED
@@ -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;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./src-CwnzY9pr.js`);exports.BUILT_IN_PROFILES=e.r,exports.findConfig=e.t,exports.setVersion=e.n;
package/dist/index.mjs CHANGED
@@ -1,6 +1,2 @@
1
- import { n as r, r as s, t as i } from "./src-BoCeBNhe.mjs";
2
- export {
3
- s as BUILT_IN_PROFILES,
4
- i as findConfig,
5
- r as setVersion
6
- };
1
+ import { n as e, r as t, t as n } from "./src-3Oz8CztN.mjs";
2
+ export { t as BUILT_IN_PROFILES, n as findConfig, e as setVersion };
@@ -1,3 +1,2 @@
1
1
  #!/usr/bin/env bun
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();
2
+ const e=require(`./src-CwnzY9pr.js`);let t=require(`@commander-js/extra-typings`);var n=`@omni-oss/set-version`,r=`Sets version of various package manifests`,i=`0.2.0`,a=new t.Command;a.name(n).version(i).description(r).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(t,n)=>{try{n.dryRun&&console.log(`Dry run enabled, no changes will be written to disk`);let r=await e.t(n.dir,!1),i=n.builtInProfiles?[...e.r,...r?.profiles??[]]:r?.profiles??[];if(!i.length){console.warn(`No profiles are configured, nothing to do`);return}let a=await e.n(n.dir,t,i,{dryRun:n.dryRun});if(a.length){let e=a.filter(e=>e.changed),t=a.filter(e=>!e.changed);console.log(`Matched ${e.length} file(s), updated ${e.length} file(s), skipped ${t.length} file(s)`);for(let t of e)console.log(` * [UPDATED]: ${t.path}`);for(let e of t)e.notChangedReasonMessage?console.log(` * [SKIPPED]: ${e.path}\n > ${e.notChangedReasonMessage}`):console.log(` * [SKIPPED]: ${e.path}`)}else console.warn(`No files updated`)}catch(e){console.error(e),process.exit(1)}}),a.parseAsync();
@@ -1,25 +1,25 @@
1
1
  #!/usr/bin/env bun
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
- 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
- try {
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 ?? [];
9
- if (!i.length) {
10
- console.warn("No profiles are configured, nothing to do");
11
- return;
12
- }
13
- const s = await c(o.dir, l, i, { dryRun: o.dryRun });
14
- if (s.length) {
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");
21
- } catch (n) {
22
- console.error(n), process.exit(1);
23
- }
24
- });
25
- a.parseAsync();
2
+ import { n as e, r as t, t as n } from "./src-3Oz8CztN.mjs";
3
+ import { Command as r } from "@commander-js/extra-typings";
4
+ //#region package.json
5
+ var i = "@omni-oss/set-version", a = "Sets version of various package manifests", o = "0.2.0", s = new r();
6
+ s.name(i).version(o).description(a).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 (r, i) => {
7
+ try {
8
+ i.dryRun && console.log("Dry run enabled, no changes will be written to disk");
9
+ let a = await n(i.dir, !1), o = i.builtInProfiles ? [...t, ...a?.profiles ?? []] : a?.profiles ?? [];
10
+ if (!o.length) {
11
+ console.warn("No profiles are configured, nothing to do");
12
+ return;
13
+ }
14
+ let s = await e(i.dir, r, o, { dryRun: i.dryRun });
15
+ if (s.length) {
16
+ let e = s.filter((e) => e.changed), t = s.filter((e) => !e.changed);
17
+ console.log(`Matched ${e.length} file(s), updated ${e.length} file(s), skipped ${t.length} file(s)`);
18
+ for (let t of e) console.log(` * [UPDATED]: ${t.path}`);
19
+ for (let e of t) e.notChangedReasonMessage ? console.log(` * [SKIPPED]: ${e.path}\n > ${e.notChangedReasonMessage}`) : console.log(` * [SKIPPED]: ${e.path}`);
20
+ } else console.warn("No files updated");
21
+ } catch (e) {
22
+ console.error(e), process.exit(1);
23
+ }
24
+ }), s.parseAsync();
25
+ //#endregion
@@ -0,0 +1,253 @@
1
+ import e from "zod";
2
+ import { OptimizedSystem as t } from "@omni-oss/system-interface";
3
+ import n from "node:path";
4
+ import r from "comment-json";
5
+ import { XMLBuilder as i, XMLParser as a } from "fast-xml-parser";
6
+ import o from "smol-toml";
7
+ import s from "yaml";
8
+ import c from "picomatch";
9
+ //#region src/lib/format.ts
10
+ var l = /* @__PURE__ */ function(e) {
11
+ return e.AUTO = "auto", e.YAML = "yaml", e.JSON = "json", e.TOML = "toml", e.XML = "xml", e;
12
+ }({}), u = e.enum(l), d = [
13
+ {
14
+ type: "path",
15
+ files: ["package.json"],
16
+ format: l.JSON,
17
+ path: ["version"]
18
+ },
19
+ {
20
+ type: "regex",
21
+ files: ["Cargo.toml"],
22
+ pattern: "^\\s*version\\s*=\\s*\"(?<version>.*)\"\\s*$",
23
+ flags: "m"
24
+ },
25
+ {
26
+ type: "path",
27
+ files: ["*.csproj"],
28
+ path: [
29
+ "Project",
30
+ "PropertyGroup",
31
+ "Version"
32
+ ],
33
+ format: l.XML
34
+ }
35
+ ], f = {
36
+ preserveOrder: !0,
37
+ commentPropName: "#comment",
38
+ ignoreAttributes: !1
39
+ }, p = {
40
+ __$$parser: new a(f),
41
+ __$$builder: new i(f),
42
+ parse: (e) => p.__$$parser.parse(e),
43
+ stringify: (e) => p.__$$builder.build(e)
44
+ };
45
+ function m(e, t, n = l.AUTO) {
46
+ switch (n === l.AUTO && (n = g(e)), n) {
47
+ case l.JSON: return r.parse(t);
48
+ case l.YAML: return s.parse(t);
49
+ case l.XML: return p.parse(t);
50
+ case l.TOML: return o.parse(t);
51
+ default: throw new _(e);
52
+ }
53
+ }
54
+ function h(e, t, n = l.AUTO) {
55
+ switch (n === l.AUTO && (n = g(e)), n) {
56
+ case l.JSON: return r.stringify(t, null, 4);
57
+ case l.YAML: return s.stringify(t);
58
+ case l.XML: return p.stringify(t);
59
+ case l.TOML: return o.stringify(t);
60
+ default: throw new _(e);
61
+ }
62
+ }
63
+ function g(e) {
64
+ switch (n.extname(e)) {
65
+ case ".json":
66
+ case ".jsonc": return l.JSON;
67
+ case ".yaml":
68
+ case ".yml": return l.YAML;
69
+ case ".xml": return l.XML;
70
+ case ".toml": return l.TOML;
71
+ default: throw new _(e);
72
+ }
73
+ }
74
+ var _ = class extends Error {
75
+ constructor(e) {
76
+ super(`Unsupported file type for file ${e}`), super.name = this.constructor.name;
77
+ }
78
+ }, v = e.object({ files: e.string().array() }), y = v.extend({
79
+ path: e.array(e.union([e.string(), e.number()])),
80
+ format: u.optional()
81
+ }).extend({ type: e.literal("path") }), b = v.extend({
82
+ pattern: e.string(),
83
+ flags: e.string().optional(),
84
+ capture_group: e.string().optional()
85
+ }).extend({ type: e.literal("regex") }), x = e.discriminatedUnion("type", [y, b]), S = e.object({ profiles: e.array(x).optional().default([]) }), C = [
86
+ "set-version.yaml",
87
+ "set-version.yml",
88
+ "set-version.toml",
89
+ "set-version.json",
90
+ "set-version.jsonc"
91
+ ];
92
+ async function w(e, t, r) {
93
+ let i = n.resolve(e);
94
+ for (; await r.fs.isDirectory(i) && !D(i);) {
95
+ for (let e of C) {
96
+ let t = n.join(i, e);
97
+ if (await r.fs.pathExists(t) && await r.fs.isFile(t)) {
98
+ let e = m(t, await r.fs.readFileAsString(t)), n = S.safeParse(e);
99
+ if (n.success) return n.data;
100
+ throw new E(t, n.error.message);
101
+ }
102
+ }
103
+ i = n.dirname(i);
104
+ }
105
+ if (t) throw new T(e);
106
+ }
107
+ var T = class extends Error {
108
+ constructor(e) {
109
+ super(e ? `No config found in ${e} or any parent directories` : "No config found"), this.dir = e, super.name = this.constructor.name;
110
+ }
111
+ }, E = class extends Error {
112
+ constructor(e, t) {
113
+ super(`Invalid config at ${e}: ${t}`), this.filePath = e, super.name = this.constructor.name;
114
+ }
115
+ };
116
+ function D(e) {
117
+ return n.parse(n.resolve(e)).root === e;
118
+ }
119
+ //#endregion
120
+ //#region src/lib/set-value.ts
121
+ function O(e, t, n) {
122
+ return k(e, t, n, [], !1);
123
+ }
124
+ function k(e, t, n, r, i) {
125
+ if (t.length === 0) return n;
126
+ let [a, ...o] = t;
127
+ if (Array.isArray(e)) {
128
+ let t = a, s = i ? e.slice() : e;
129
+ if (!s[t]) throw new A(r);
130
+ return s[t] = k(s[t], o, n, [...r, t], i), s;
131
+ }
132
+ let s = a, c = i ? { ...e } : e;
133
+ if (!c[s]) throw new A(r);
134
+ return c[s] = k(c[s], o, n, [...r, s], i), c;
135
+ }
136
+ var A = class extends Error {
137
+ constructor(e) {
138
+ super(`No value at path ${e.join(".")}`), this.path = e, super.name = this.constructor.name;
139
+ }
140
+ };
141
+ //#endregion
142
+ //#region src/lib/string-utils.ts
143
+ function j(e, t, n, r) {
144
+ if (!t.test(e)) throw new M(t.source);
145
+ return e.replace(t, (e, ...t) => {
146
+ let i = t[t.length - 1], a = e, o = i[n];
147
+ return o === void 0 ? a : a.replace(o, r);
148
+ });
149
+ }
150
+ var M = class extends Error {
151
+ constructor(e) {
152
+ super(`Regex ${e} did not match`), this.pattern = e, super.name = this.constructor.name;
153
+ }
154
+ }, N = /* @__PURE__ */ function(e) {
155
+ 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;
156
+ }({});
157
+ async function P(e, t, r, i, a = {}) {
158
+ let o = c(Array.from(r.flatMap((e) => e.files))), s = r.map((e) => ({
159
+ ...e,
160
+ glob: c(e.files)
161
+ })), l = await i.fs.readDirectory(e), u = [];
162
+ for (let r of l) {
163
+ if (!o(r) || !await i.fs.isFile(r)) continue;
164
+ let c = n.join(e, r), l = await i.fs.readFileAsString(c), d = l, f = s.filter((e) => e.glob(r));
165
+ if (!f.length) throw new F(r);
166
+ let p, m;
167
+ for (let e of f) try {
168
+ d = I({
169
+ path: c,
170
+ content: d
171
+ }, t, e);
172
+ } catch (e) {
173
+ if (e instanceof A) p = N.NO_VALUE_AT_PATH, m = `No value at path ${e.path.join(".")}, make sure the path is correct and it exists`;
174
+ else if (e instanceof M) p = N.REGEX_PATTERN_NOT_MATCHED, m = `Regex pattern ${e.pattern} did not match`;
175
+ else throw e;
176
+ }
177
+ let h = l !== d;
178
+ u.push({
179
+ path: c,
180
+ changed: h,
181
+ notChangedReason: h ? void 0 : p ?? N.ALREADY_UP_TO_DATE,
182
+ notChangedReasonMessage: h ? void 0 : m ?? "File already up to date"
183
+ }), !a.dryRun && l !== d && await i.fs.writeStringToFile(c, d);
184
+ }
185
+ return u;
186
+ }
187
+ var F = class extends Error {
188
+ constructor(e) {
189
+ super(`No profile found for file ${e}`), super.name = this.constructor.name;
190
+ }
191
+ };
192
+ function I(e, t, n) {
193
+ switch (n.type) {
194
+ case "path": {
195
+ let r = (n.format === l.AUTO ? g(e.path) : n.format) ?? l.AUTO;
196
+ if (n.format === l.YAML) {
197
+ let r = s.parseDocument(e.content);
198
+ return r.setIn(n.path, t), r.toString();
199
+ } else if (n.format === l.XML) return R(e, t, n, r);
200
+ else return L(e, t, n, r);
201
+ }
202
+ case "regex": {
203
+ let r = new RegExp(n.pattern, n.flags ?? "m");
204
+ return j(e.content, r, n.capture_group ?? "version", t);
205
+ }
206
+ default: throw new B(n.type);
207
+ }
208
+ }
209
+ function L(e, t, n, r) {
210
+ let i = O(m(e.path, e.content, r), n.path, t);
211
+ return h(e.path, i, r);
212
+ }
213
+ function R(e, t, n, r) {
214
+ let i = m(e.path, e.content, r), a = O(i, z(n.path, i), t);
215
+ return h(e.path, a, r);
216
+ }
217
+ function z(e, t) {
218
+ let n = [], r = t;
219
+ for (let t of e) {
220
+ let i = Array.from(r.entries());
221
+ for (let [a, o] of i) {
222
+ if (o[t]) {
223
+ n.push(a, t), r = o[t];
224
+ break;
225
+ }
226
+ if (i.length === a + 1) throw new A(e);
227
+ }
228
+ }
229
+ let i = Array.from(r.entries());
230
+ for (let [t, r] of i) {
231
+ if (r["#text"]) {
232
+ n.push(t, "#text");
233
+ break;
234
+ }
235
+ if (i.length === t + 1) throw new A(e);
236
+ }
237
+ return n;
238
+ }
239
+ var B = class extends Error {
240
+ constructor(e) {
241
+ super(`Unsupported profile type ${e}`), super.name = this.constructor.name;
242
+ }
243
+ };
244
+ //#endregion
245
+ //#region src/lib/index.ts
246
+ async function V(e, n, r, i = {}) {
247
+ return P(e, n, r, await t.create(), i);
248
+ }
249
+ async function H(e, n) {
250
+ return w(e, n, await t.create());
251
+ }
252
+ //#endregion
253
+ export { V as n, d as r, H as t };
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`zod`);c=s(c);let l=require(`@omni-oss/system-interface`),u=require(`node:path`);u=s(u);let d=require(`comment-json`);d=s(d);let f=require(`fast-xml-parser`),p=require(`smol-toml`);p=s(p);let m=require(`yaml`);m=s(m);let h=require(`picomatch`);h=s(h);var g=function(e){return e.AUTO=`auto`,e.YAML=`yaml`,e.JSON=`json`,e.TOML=`toml`,e.XML=`xml`,e}({}),_=c.default.enum(g),v=[{type:`path`,files:[`package.json`],format:g.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:g.XML}],y={preserveOrder:!0,commentPropName:`#comment`,ignoreAttributes:!1},b={__$$parser:new f.XMLParser(y),__$$builder:new f.XMLBuilder(y),parse:e=>b.__$$parser.parse(e),stringify:e=>b.__$$builder.build(e)};function x(e,t,n=g.AUTO){switch(n===g.AUTO&&(n=C(e)),n){case g.JSON:return d.default.parse(t);case g.YAML:return m.default.parse(t);case g.XML:return b.parse(t);case g.TOML:return p.default.parse(t);default:throw new w(e)}}function S(e,t,n=g.AUTO){switch(n===g.AUTO&&(n=C(e)),n){case g.JSON:return d.default.stringify(t,null,4);case g.YAML:return m.default.stringify(t);case g.XML:return b.stringify(t);case g.TOML:return p.default.stringify(t);default:throw new w(e)}}function C(e){switch(u.default.extname(e)){case`.json`:case`.jsonc`:return g.JSON;case`.yaml`:case`.yml`:return g.YAML;case`.xml`:return g.XML;case`.toml`:return g.TOML;default:throw new w(e)}}var w=class extends Error{constructor(e){super(`Unsupported file type for file ${e}`),super.name=this.constructor.name}},T=c.default.object({files:c.default.string().array()}),E=T.extend({path:c.default.array(c.default.union([c.default.string(),c.default.number()])),format:_.optional()}).extend({type:c.default.literal(`path`)}),D=T.extend({pattern:c.default.string(),flags:c.default.string().optional(),capture_group:c.default.string().optional()}).extend({type:c.default.literal(`regex`)}),O=c.default.discriminatedUnion(`type`,[E,D]),k=c.default.object({profiles:c.default.array(O).optional().default([])}),A=[`set-version.yaml`,`set-version.yml`,`set-version.toml`,`set-version.json`,`set-version.jsonc`];async function j(e,t,n){let r=u.default.resolve(e);for(;await n.fs.isDirectory(r)&&!P(r);){for(let e of A){let t=u.default.join(r,e);if(await n.fs.pathExists(t)&&await n.fs.isFile(t)){let e=x(t,await n.fs.readFileAsString(t)),r=k.safeParse(e);if(r.success)return r.data;throw new N(t,r.error.message)}}r=u.default.dirname(r)}if(t)throw new M(e)}var M=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}},N=class extends Error{constructor(e,t){super(`Invalid config at ${e}: ${t}`),this.filePath=e,super.name=this.constructor.name}};function P(e){return u.default.parse(u.default.resolve(e)).root===e}function F(e,t,n){return I(e,t,n,[],!1)}function I(e,t,n,r,i){if(t.length===0)return n;let[a,...o]=t;if(Array.isArray(e)){let t=a,s=i?e.slice():e;if(!s[t])throw new L(r);return s[t]=I(s[t],o,n,[...r,t],i),s}let s=a,c=i?{...e}:e;if(!c[s])throw new L(r);return c[s]=I(c[s],o,n,[...r,s],i),c}var L=class extends Error{constructor(e){super(`No value at path ${e.join(`.`)}`),this.path=e,super.name=this.constructor.name}};function R(e,t,n,r){if(!t.test(e))throw new z(t.source);return e.replace(t,(e,...t)=>{let i=t[t.length-1],a=e,o=i[n];return o===void 0?a:a.replace(o,r)})}var z=class extends Error{constructor(e){super(`Regex ${e} did not match`),this.pattern=e,super.name=this.constructor.name}},B=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 V(e,t,n,r,i={}){let a=(0,h.default)(Array.from(n.flatMap(e=>e.files))),o=n.map(e=>({...e,glob:(0,h.default)(e.files)})),s=await r.fs.readDirectory(e),c=[];for(let n of s){if(!a(n)||!await r.fs.isFile(n))continue;let s=u.default.join(e,n),l=await r.fs.readFileAsString(s),d=l,f=o.filter(e=>e.glob(n));if(!f.length)throw new H(n);let p,m;for(let e of f)try{d=U({path:s,content:d},t,e)}catch(e){if(e instanceof L)p=B.NO_VALUE_AT_PATH,m=`No value at path ${e.path.join(`.`)}, make sure the path is correct and it exists`;else if(e instanceof z)p=B.REGEX_PATTERN_NOT_MATCHED,m=`Regex pattern ${e.pattern} did not match`;else throw e}let h=l!==d;c.push({path:s,changed:h,notChangedReason:h?void 0:p??B.ALREADY_UP_TO_DATE,notChangedReasonMessage:h?void 0:m??`File already up to date`}),!i.dryRun&&l!==d&&await r.fs.writeStringToFile(s,d)}return c}var H=class extends Error{constructor(e){super(`No profile found for file ${e}`),super.name=this.constructor.name}};function U(e,t,n){switch(n.type){case`path`:{let r=(n.format===g.AUTO?C(e.path):n.format)??g.AUTO;if(n.format===g.YAML){let r=m.default.parseDocument(e.content);return r.setIn(n.path,t),r.toString()}else if(n.format===g.XML)return G(e,t,n,r);else return W(e,t,n,r)}case`regex`:{let r=new RegExp(n.pattern,n.flags??`m`);return R(e.content,r,n.capture_group??`version`,t)}default:throw new q(n.type)}}function W(e,t,n,r){let i=F(x(e.path,e.content,r),n.path,t);return S(e.path,i,r)}function G(e,t,n,r){let i=x(e.path,e.content,r),a=F(i,K(n.path,i),t);return S(e.path,a,r)}function K(e,t){let n=[],r=t;for(let t of e){let i=Array.from(r.entries());for(let[a,o]of i){if(o[t]){n.push(a,t),r=o[t];break}if(i.length===a+1)throw new L(e)}}let i=Array.from(r.entries());for(let[t,r]of i){if(r[`#text`]){n.push(t,`#text`);break}if(i.length===t+1)throw new L(e)}return n}var q=class extends Error{constructor(e){super(`Unsupported profile type ${e}`),super.name=this.constructor.name}};async function J(e,t,n,r={}){return V(e,t,n,await l.OptimizedSystem.create(),r)}async function Y(e,t){return j(e,t,await l.OptimizedSystem.create())}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return Y}});
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.1.2",
4
+ "version": "0.2.0",
5
5
  "bin": "./dist/set-version.mjs",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -24,7 +24,7 @@
24
24
  "commander": "^14.0.3",
25
25
  "@commander-js/extra-typings": "^14.0.0",
26
26
  "@omni-oss/system-interface": "^0.1.0",
27
- "fast-xml-parser": "^5.5.3",
27
+ "fast-xml-parser": "^5.5.8",
28
28
  "yaml": "^2.8.2",
29
29
  "comment-json": "^4.6.2",
30
30
  "smol-toml": "^1.6.0",
@@ -1,269 +0,0 @@
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
- };
@@ -1 +0,0 @@
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}});