@omni-oss/set-version 0.1.1 → 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,24 @@
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
+
13
+ ## @omni-oss/set-version-v0.1.2 - 2026-03-14
14
+ #### Bug Fixes
15
+ - error when constructing NoConfigFoundError - (804af84) - Clarence Manuel
16
+ #### Miscellaneous Chores
17
+ - upgrade npm dependencies - (4323b60) - Clarence Manuel
18
+ - utilize bun catalogs - (40fe122) - Clarence Manuel
19
+ - bump node version [skip ci] - (04067be) - Clarence Manuel
20
+
21
+ - - -
22
+
5
23
  ## @omni-oss/set-version-v0.1.1 - 2026-02-07
6
24
  #### Bug Fixes
7
25
  - (**@omni-oss/set-version**) dist file names - (b6e453e) - Clarence Manuel
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-BCvo12D0.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 { B as o, f as a, s as e } from "./index-DjY1h20_.mjs";
2
- export {
3
- o as BUILT_IN_PROFILES,
4
- a as findConfig,
5
- e 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
- "use strict";const d=require("@commander-js/extra-typings"),i=require("./index-BCvo12D0.js"),f="@omni-oss/set-version",g="Sets version of various package manifests",h="0.1.1",c=new d.Command;c.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(l,n)=>{try{n.dryRun&&console.log("Dry run enabled, no changes will be written to disk");const o=await i.findConfig(n.dir,!1),r=n.builtInProfiles?[...i.BUILT_IN_PROFILES,...o?.profiles??[]]:o?.profiles??[];if(!r.length){console.warn("No profiles are configured, nothing to do");return}const s=await i.setVersion(n.dir,l,r,{dryRun:n.dryRun});if(s.length){const t=s.filter(e=>e.changed),a=s.filter(e=>!e.changed);console.log(`Matched ${t.length} file(s), updated ${t.length} file(s), skipped ${a.length} file(s)`);for(const e of t)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)}});c.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,36 +1,25 @@
1
1
  #!/usr/bin/env bun
2
- import { Command as c } from "@commander-js/extra-typings";
3
- import { f as d, B as f, s as g } from "./index-DjY1h20_.mjs";
4
- const h = "@omni-oss/set-version", p = "Sets version of various package manifests", u = "0.1.1", a = new c();
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(
8
- "Dry run enabled, no changes will be written to disk"
9
- );
10
- const n = await d(o.dir, !1), i = o.builtInProfiles ? [...f, ...n?.profiles ?? []] : n?.profiles ?? [];
11
- if (!i.length) {
12
- console.warn("No profiles are configured, nothing to do");
13
- return;
14
- }
15
- const s = await g(o.dir, l, i, {
16
- dryRun: o.dryRun
17
- });
18
- if (s.length) {
19
- const t = s.filter((e) => e.changed), r = s.filter((e) => !e.changed);
20
- console.log(
21
- `Matched ${t.length} file(s), updated ${t.length} file(s), skipped ${r.length} file(s)`
22
- );
23
- for (const e of t)
24
- console.log(` * [UPDATED]: ${e.path}`);
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");
32
- } catch (n) {
33
- console.error(n), process.exit(1);
34
- }
35
- });
36
- 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.1",
4
+ "version": "0.2.0",
5
5
  "bin": "./dist/set-version.mjs",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -22,22 +22,22 @@
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.4",
27
+ "fast-xml-parser": "^5.5.8",
28
28
  "yaml": "^2.8.2",
29
- "comment-json": "^4.5.1",
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": "^0.1.1",
35
- "@omni-oss/vite-config": "^0.1.0",
36
- "@omni-oss/vitest-config": "^0.0.0",
37
- "vite": "^7.3.1",
38
- "vitest": "^4.0.18",
39
- "@types/node": "25.2.0",
40
- "@types/bun": "^1.3.8",
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
  }
@@ -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;
@@ -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
- };