@tikkhun/version 2025.7.8 → 2026.4.13

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.
Files changed (54) hide show
  1. package/README.md +179 -5
  2. package/dist/cli/date-version.js +4 -3
  3. package/dist/cli/date-version.mjs +4 -3
  4. package/dist/cli/node-version.js +4 -3
  5. package/dist/cli/node-version.mjs +4 -3
  6. package/dist/cli/semantic-version.js +4 -3
  7. package/dist/cli/semantic-version.mjs +4 -3
  8. package/dist/cli/shared.d.mts +130 -0
  9. package/dist/cli/shared.d.ts +130 -0
  10. package/dist/cli/shared.js +6 -0
  11. package/dist/cli/shared.mjs +6 -0
  12. package/dist/lib/VersionManager.d.mts +49 -14
  13. package/dist/lib/VersionManager.d.ts +49 -14
  14. package/dist/lib/VersionManager.js +4 -3
  15. package/dist/lib/VersionManager.mjs +4 -3
  16. package/dist/lib/VersionUpdateResult.d.mts +36 -24
  17. package/dist/lib/VersionUpdateResult.d.ts +36 -24
  18. package/dist/lib/VersionUpdateResult.js +2 -2
  19. package/dist/lib/VersionUpdateResult.mjs +2 -2
  20. package/dist/lib/getter/NodeVersionGetter.js +1 -1
  21. package/dist/lib/getter/NodeVersionGetter.mjs +1 -1
  22. package/dist/lib/getter/SemanticVersionGetter.js +1 -1
  23. package/dist/lib/getter/SemanticVersionGetter.mjs +1 -1
  24. package/dist/lib/getter/index.js +1 -1
  25. package/dist/lib/getter/index.mjs +1 -1
  26. package/dist/lib/index.d.mts +4 -1
  27. package/dist/lib/index.d.ts +4 -1
  28. package/dist/lib/index.js +4 -3
  29. package/dist/lib/index.mjs +4 -3
  30. package/dist/lib/store/ConfigStore.d.mts +69 -0
  31. package/dist/lib/store/ConfigStore.d.ts +69 -0
  32. package/dist/lib/store/ConfigStore.js +6 -0
  33. package/dist/lib/store/ConfigStore.mjs +6 -0
  34. package/dist/lib/store/JsonStore.d.mts +32 -9
  35. package/dist/lib/store/JsonStore.d.ts +32 -9
  36. package/dist/lib/store/JsonStore.js +4 -3
  37. package/dist/lib/store/JsonStore.mjs +4 -3
  38. package/dist/lib/store/Store.d.mts +182 -4
  39. package/dist/lib/store/Store.d.ts +182 -4
  40. package/dist/lib/store/StoreFactory.d.mts +14 -0
  41. package/dist/lib/store/StoreFactory.d.ts +14 -0
  42. package/dist/lib/store/StoreFactory.js +6 -0
  43. package/dist/lib/store/StoreFactory.mjs +6 -0
  44. package/dist/lib/store/TextStore.d.mts +62 -6
  45. package/dist/lib/store/TextStore.d.ts +62 -6
  46. package/dist/lib/store/TextStore.js +3 -3
  47. package/dist/lib/store/TextStore.mjs +3 -3
  48. package/dist/lib/store/index.d.mts +3 -1
  49. package/dist/lib/store/index.d.ts +3 -1
  50. package/dist/lib/store/index.js +4 -3
  51. package/dist/lib/store/index.mjs +4 -3
  52. package/dist/lib/utils.js +1 -1
  53. package/dist/lib/utils.mjs +1 -1
  54. package/package.json +10 -6
@@ -1,5 +1,5 @@
1
- 'use strict';var e=require('fs'),i=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var e__default=/*#__PURE__*/_interopDefault(e);var i__default=/*#__PURE__*/_interopDefault(i);/**
1
+ 'use strict';var fsExtra=require('fs-extra');/**
2
2
  @tikkhun/version
3
- 2025.7.7
3
+ 2026.4.13
4
4
  */
5
- var r=process.cwd();var l={file:""},o=class{constructor(t){this.opts=t,this.filePath=i__default.default.join(r,this.opts.file);}update(t){try{return typeof t!="string"&&(t=JSON.stringify(t)),e__default.default.writeFileSync(this.filePath,t,"utf8"),!0}catch(p){return false}}};exports.DEFAULT_TEXT_STORE_OPTIONS=l;exports.TextStore=o;
5
+ var w=Object.defineProperty,T=Object.defineProperties;var E=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var p=(i,t,e)=>t in i?w(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e,c=(i,t)=>{for(var e in t||(t={}))S.call(t,e)&&p(i,e,t[e]);if(h)for(var e of h(t))V.call(t,e)&&p(i,e,t[e]);return i},d=(i,t)=>T(i,E(t));var a=(i,t,e)=>new Promise((s,r)=>{var o=n=>{try{u(e.next(n));}catch(l){r(l);}},g=n=>{try{u(e.throw(n));}catch(l){r(l);}},u=n=>n.done?s(n.value):Promise.resolve(n.value).then(o,g);u((e=e.apply(i,t)).next());});var R={file:"",mode:"raw",trim:true,replacement:"{{version}}"},m=class{constructor(t){this.target=c(c({type:"text"},R),t);}get(){return a(this,null,function*(){var t;try{if(!(yield fsExtra.pathExists(this.target.file)))return this.createGetError(`file is not found: ${this.target.file}`);let e=yield fsExtra.readFile(this.target.file,(t=this.target.encoding)!=null?t:"utf8"),s=this.resolveValueFromText(e);return s===void 0?this.createGetError("version is not found in text content"):{action:"get",success:!0,file:this.target.file,type:this.target.type,value:s}}catch(e){return this.createGetError(this.getErrorMessage(e))}})}set(t){return a(this,null,function*(){try{let e=yield this.get(),s=e.success?e.value:void 0,r=yield this.createNextText(t);return yield this.writeText(r),{action:"set",success:!0,file:this.target.file,type:this.target.type,oldValue:s,newValue:t}}catch(e){return {action:"set",success:false,file:this.target.file,type:this.target.type,newValue:t,message:this.getErrorMessage(e)}}})}update(t){return a(this,null,function*(){let e=yield this.set(t);return d(c({},e),{action:"update"})})}resolveValueFromText(t){var e;if(this.target.mode==="replace"){let r=this.createPattern().exec(t);if(!r)return;let o=(e=r.groups)==null?void 0:e.version;return o!==void 0?o:r[1]!==void 0?r[1]:r[0]}return this.target.trim?t.trim():t}createNextText(t){return a(this,null,function*(){var e,s;if(this.target.mode==="replace"){if(!(yield fsExtra.pathExists(this.target.file)))throw new Error(`file is not found: ${this.target.file}`);let r=yield fsExtra.readFile(this.target.file,(e=this.target.encoding)!=null?e:"utf8");if(!this.createPattern().test(r))throw new Error("pattern is not matched");let g=((s=this.target.replacement)!=null?s:"{{version}}").replaceAll("{{version}}",String(t));return r.replace(this.createPattern(),g)}return String(t)})}writeText(t){return a(this,null,function*(){var e;if(!(yield fsExtra.pathExists(this.target.file))){if(!this.target.createIfNotExists)throw new Error(`file is not found: ${this.target.file}`);yield fsExtra.ensureFile(this.target.file);}yield fsExtra.writeFile(this.target.file,t,(e=this.target.encoding)!=null?e:"utf8");})}createPattern(){if(!this.target.pattern)throw new Error("pattern is required when text mode is replace");return new RegExp(this.target.pattern,this.target.flags)}createGetError(t){return {action:"get",success:false,file:this.target.file,type:this.target.type,message:t}}getErrorMessage(t){return t instanceof Error?t.message:String(t)}};exports.DEFAULT_TEXT_STORE_OPTIONS=R;exports.TextStore=m;
@@ -1,5 +1,5 @@
1
- import e from'fs';import i from'path';/**
1
+ import {pathExists,readFile,ensureFile,writeFile}from'fs-extra';/**
2
2
  @tikkhun/version
3
- 2025.7.7
3
+ 2026.4.13
4
4
  */
5
- var r=process.cwd();var l={file:""},o=class{constructor(t){this.opts=t,this.filePath=i.join(r,this.opts.file);}update(t){try{return typeof t!="string"&&(t=JSON.stringify(t)),e.writeFileSync(this.filePath,t,"utf8"),!0}catch(p){return false}}};export{l as DEFAULT_TEXT_STORE_OPTIONS,o as TextStore};
5
+ var w=Object.defineProperty,T=Object.defineProperties;var E=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var p=(i,t,e)=>t in i?w(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e,c=(i,t)=>{for(var e in t||(t={}))S.call(t,e)&&p(i,e,t[e]);if(h)for(var e of h(t))V.call(t,e)&&p(i,e,t[e]);return i},d=(i,t)=>T(i,E(t));var a=(i,t,e)=>new Promise((s,r)=>{var o=n=>{try{u(e.next(n));}catch(l){r(l);}},g=n=>{try{u(e.throw(n));}catch(l){r(l);}},u=n=>n.done?s(n.value):Promise.resolve(n.value).then(o,g);u((e=e.apply(i,t)).next());});var R={file:"",mode:"raw",trim:true,replacement:"{{version}}"},m=class{constructor(t){this.target=c(c({type:"text"},R),t);}get(){return a(this,null,function*(){var t;try{if(!(yield pathExists(this.target.file)))return this.createGetError(`file is not found: ${this.target.file}`);let e=yield readFile(this.target.file,(t=this.target.encoding)!=null?t:"utf8"),s=this.resolveValueFromText(e);return s===void 0?this.createGetError("version is not found in text content"):{action:"get",success:!0,file:this.target.file,type:this.target.type,value:s}}catch(e){return this.createGetError(this.getErrorMessage(e))}})}set(t){return a(this,null,function*(){try{let e=yield this.get(),s=e.success?e.value:void 0,r=yield this.createNextText(t);return yield this.writeText(r),{action:"set",success:!0,file:this.target.file,type:this.target.type,oldValue:s,newValue:t}}catch(e){return {action:"set",success:false,file:this.target.file,type:this.target.type,newValue:t,message:this.getErrorMessage(e)}}})}update(t){return a(this,null,function*(){let e=yield this.set(t);return d(c({},e),{action:"update"})})}resolveValueFromText(t){var e;if(this.target.mode==="replace"){let r=this.createPattern().exec(t);if(!r)return;let o=(e=r.groups)==null?void 0:e.version;return o!==void 0?o:r[1]!==void 0?r[1]:r[0]}return this.target.trim?t.trim():t}createNextText(t){return a(this,null,function*(){var e,s;if(this.target.mode==="replace"){if(!(yield pathExists(this.target.file)))throw new Error(`file is not found: ${this.target.file}`);let r=yield readFile(this.target.file,(e=this.target.encoding)!=null?e:"utf8");if(!this.createPattern().test(r))throw new Error("pattern is not matched");let g=((s=this.target.replacement)!=null?s:"{{version}}").replaceAll("{{version}}",String(t));return r.replace(this.createPattern(),g)}return String(t)})}writeText(t){return a(this,null,function*(){var e;if(!(yield pathExists(this.target.file))){if(!this.target.createIfNotExists)throw new Error(`file is not found: ${this.target.file}`);yield ensureFile(this.target.file);}yield writeFile(this.target.file,t,(e=this.target.encoding)!=null?e:"utf8");})}createPattern(){if(!this.target.pattern)throw new Error("pattern is required when text mode is replace");return new RegExp(this.target.pattern,this.target.flags)}createGetError(t){return {action:"get",success:false,file:this.target.file,type:this.target.type,message:t}}getErrorMessage(t){return t instanceof Error?t.message:String(t)}};export{R as DEFAULT_TEXT_STORE_OPTIONS,m as TextStore};
@@ -1,3 +1,5 @@
1
+ export { ConfigStore } from './ConfigStore.mjs';
1
2
  export { DEFAULT_JSON_STORE_OPTIONS, JsonStore, JsonStoreOptions } from './JsonStore.mjs';
2
- export { Store, StoreOptions } from './Store.mjs';
3
+ export { BaseVersionTarget, CustomVersionTarget, Store, StoreGetResult, StoreResult, StoreSetResult, StructuredVersionTarget, StructuredVersionTargetType, TextStoreMode, TextVersionTarget, VersionTarget, VersionValue } from './Store.mjs';
4
+ export { StoreFactory } from './StoreFactory.mjs';
3
5
  export { DEFAULT_TEXT_STORE_OPTIONS, TextStore, TextStoreOptions } from './TextStore.mjs';
@@ -1,3 +1,5 @@
1
+ export { ConfigStore } from './ConfigStore.js';
1
2
  export { DEFAULT_JSON_STORE_OPTIONS, JsonStore, JsonStoreOptions } from './JsonStore.js';
2
- export { Store, StoreOptions } from './Store.js';
3
+ export { BaseVersionTarget, CustomVersionTarget, Store, StoreGetResult, StoreResult, StoreSetResult, StructuredVersionTarget, StructuredVersionTargetType, TextStoreMode, TextVersionTarget, VersionTarget, VersionValue } from './Store.js';
4
+ export { StoreFactory } from './StoreFactory.js';
3
5
  export { DEFAULT_TEXT_STORE_OPTIONS, TextStore, TextStoreOptions } from './TextStore.js';
@@ -1,5 +1,6 @@
1
- 'use strict';var fsExtra=require('fs-extra'),E=require('fs'),d=require('path');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var E__default=/*#__PURE__*/_interopDefault(E);var d__default=/*#__PURE__*/_interopDefault(d);/**
1
+ 'use strict';var fsExtra=require('fs-extra'),fastXmlParser=require('fast-xml-parser'),E=require('js-yaml'),lodash=require('lodash'),smolToml=require('smol-toml');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var E__default=/*#__PURE__*/_interopDefault(E);/**
2
2
  @tikkhun/version
3
- 2025.7.7
3
+ 2026.4.13
4
4
  */
5
- var T=Object.defineProperty,x=Object.defineProperties;var g=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var a=(r,t,o)=>t in r?T(r,t,{enumerable:true,configurable:true,writable:true,value:o}):r[t]=o,f=(r,t)=>{for(var o in t||(t={}))w.call(t,o)&&a(r,o,t[o]);if(p)for(var o of p(t))J.call(t,o)&&a(r,o,t[o]);return r},c=(r,t)=>x(r,g(t));var l=(r,t,o)=>new Promise((h,n)=>{var u=e=>{try{s(o.next(e));}catch(i){n(i);}},y=e=>{try{s(o.throw(e));}catch(i){n(i);}},s=e=>e.done?h(e.value):Promise.resolve(e.value).then(u,y);s((o=o.apply(r,t)).next());});var _={file:"package.json",key:"version"},m=class{constructor(t){this.opts=Object.assign({},_,t);}update(t){return l(this,null,function*(){try{let o=yield fsExtra.readJson(this.opts.file);return yield fsExtra.writeJson(this.opts.file,c(f({},o),{[this.opts.key]:t}),{spaces:2}),!0}catch(o){return false}})}};var O=process.cwd();var R={file:""},S=class{constructor(t){this.opts=t,this.filePath=d__default.default.join(O,this.opts.file);}update(t){try{return typeof t!="string"&&(t=JSON.stringify(t)),E__default.default.writeFileSync(this.filePath,t,"utf8"),!0}catch(o){return false}}};exports.DEFAULT_JSON_STORE_OPTIONS=_;exports.DEFAULT_TEXT_STORE_OPTIONS=R;exports.JsonStore=m;exports.TextStore=S;
5
+ var P=Object.defineProperty,G=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var S=(n,t,e)=>t in n?P(n,t,{enumerable:true,configurable:true,writable:true,value:e}):n[t]=e,u=(n,t)=>{for(var e in t||(t={}))b.call(t,e)&&S(n,e,t[e]);if(w)for(var e of w(t))k.call(t,e)&&S(n,e,t[e]);return n},f=(n,t)=>G(n,C(t));var a=(n,t,e)=>new Promise((s,r)=>{var i=o=>{try{g(e.next(o));}catch(d){r(d);}},c=o=>{try{g(e.throw(o));}catch(d){r(d);}},g=o=>o.done?s(o.value):Promise.resolve(o.value).then(i,c);g((e=e.apply(n,t)).next());});var l=class{constructor(t){this.target=t;}get(){return a(this,null,function*(){var t;try{if(!(yield fsExtra.pathExists(this.target.file)))return this.createGetError(`file is not found: ${this.target.file}`);let e=yield this.loadStructuredConfig(),s=this.target.path?lodash.get(e,this.target.path):e;return s===void 0?this.createGetError(`path is not found: ${(t=this.target.path)!=null?t:"<root>"}`):typeof s!="string"&&typeof s!="number"?this.createGetError(`value is not string or number: ${JSON.stringify(s)}`):{action:"get",success:!0,file:this.target.file,type:this.target.type,value:s}}catch(e){return this.createGetError(this.getErrorMessage(e))}})}set(t){return a(this,null,function*(){try{let e=yield this.get(),s=e.success?e.value:void 0,r=yield fsExtra.pathExists(this.target.file);if(!r){if(!this.target.createIfNotExists)return this.createSetError(t,`file is not found: ${this.target.file}`,s,"set");yield fsExtra.ensureFile(this.target.file);}let i=r?yield this.loadStructuredConfig():{};if(this.target.path)lodash.set(i,this.target.path,t),yield this.saveStructuredConfig(i);else {if(typeof i=="object"&&i!==null&&!Array.isArray(i))return this.createSetError(t,"path is required for structured target",s,"set");yield this.saveStructuredConfig(t);}return {action:"set",success:!0,file:this.target.file,type:this.target.type,oldValue:s,newValue:t}}catch(e){return this.createSetError(t,this.getErrorMessage(e),void 0,"set")}})}update(t){return a(this,null,function*(){let e=yield this.set(t);return f(u({},e),{action:"update"})})}createGetError(t){return {action:"get",success:false,file:this.target.file,type:this.target.type,message:t}}createSetError(t,e,s,r="set"){return {action:r,success:false,file:this.target.file,type:this.target.type,oldValue:s,newValue:t,message:e}}getErrorMessage(t){return t instanceof Error?t.message:String(t)}loadStructuredConfig(){return a(this,null,function*(){var e;let t=yield fsExtra.readFile(this.target.file,(e=this.target.encoding)!=null?e:"utf8");switch(this.target.type){case "json":return JSON.parse(t);case "yaml":return E__default.default.load(t);case "toml":return smolToml.parse(t);case "xml":return new fastXmlParser.XMLParser({ignoreAttributes:true}).parse(t);case "env":return this.parseEnvContent(t);default:throw new Error(`unsupported structured target type: ${this.target.type}`)}})}saveStructuredConfig(t){return a(this,null,function*(){var s;let e=(s=this.target.encoding)!=null?s:"utf8";switch(this.target.type){case "json":yield fsExtra.writeFile(this.target.file,JSON.stringify(t,null,2),e);return;case "yaml":yield fsExtra.writeFile(this.target.file,E__default.default.dump(t),e);return;case "toml":yield fsExtra.writeFile(this.target.file,smolToml.stringify(t),e);return;case "xml":yield fsExtra.writeFile(this.target.file,new fastXmlParser.XMLBuilder({format:true,ignoreAttributes:true}).build(t),e);return;case "env":yield fsExtra.writeFile(this.target.file,this.stringifyEnvContent(t),e);return;default:throw new Error(`unsupported structured target type: ${this.target.type}`)}})}parseEnvContent(t){let e={},s=t.split(/\r?\n/);for(let r of s){let i=r.trim();if(!i||i.startsWith("#"))continue;let c=i.indexOf("=");if(c<0)continue;let g=i.slice(0,c).trim(),o=i.slice(c+1).trim();lodash.set(e,g.replace(/__/g,"."),o);}return e}stringifyEnvContent(t){let e=[],s=(r,i)=>{if(r!==null&&typeof r=="object"&&!Array.isArray(r)){for(let[g,o]of Object.entries(r))s(o,[...i,g]);return}let c=i.join("__").toUpperCase();e.push(`${c}=${r!=null?r:""}`);};for(let[r,i]of Object.entries(t))s(i,[r]);return e.join(`
6
+ `)}};var M={file:"package.json",key:"version"},T=class extends l{constructor(t){var r;let e=Object.assign({},M,t),s={type:"json",file:e.file,path:(r=e.path)!=null?r:e.key,createIfNotExists:e.createIfNotExists};super(s);}};var L={file:"",mode:"raw",trim:true,replacement:"{{version}}"},h=class{constructor(t){this.target=u(u({type:"text"},L),t);}get(){return a(this,null,function*(){var t;try{if(!(yield fsExtra.pathExists(this.target.file)))return this.createGetError(`file is not found: ${this.target.file}`);let e=yield fsExtra.readFile(this.target.file,(t=this.target.encoding)!=null?t:"utf8"),s=this.resolveValueFromText(e);return s===void 0?this.createGetError("version is not found in text content"):{action:"get",success:!0,file:this.target.file,type:this.target.type,value:s}}catch(e){return this.createGetError(this.getErrorMessage(e))}})}set(t){return a(this,null,function*(){try{let e=yield this.get(),s=e.success?e.value:void 0,r=yield this.createNextText(t);return yield this.writeText(r),{action:"set",success:!0,file:this.target.file,type:this.target.type,oldValue:s,newValue:t}}catch(e){return {action:"set",success:false,file:this.target.file,type:this.target.type,newValue:t,message:this.getErrorMessage(e)}}})}update(t){return a(this,null,function*(){let e=yield this.set(t);return f(u({},e),{action:"update"})})}resolveValueFromText(t){var e;if(this.target.mode==="replace"){let r=this.createPattern().exec(t);if(!r)return;let i=(e=r.groups)==null?void 0:e.version;return i!==void 0?i:r[1]!==void 0?r[1]:r[0]}return this.target.trim?t.trim():t}createNextText(t){return a(this,null,function*(){var e,s;if(this.target.mode==="replace"){if(!(yield fsExtra.pathExists(this.target.file)))throw new Error(`file is not found: ${this.target.file}`);let r=yield fsExtra.readFile(this.target.file,(e=this.target.encoding)!=null?e:"utf8");if(!this.createPattern().test(r))throw new Error("pattern is not matched");let c=((s=this.target.replacement)!=null?s:"{{version}}").replaceAll("{{version}}",String(t));return r.replace(this.createPattern(),c)}return String(t)})}writeText(t){return a(this,null,function*(){var e;if(!(yield fsExtra.pathExists(this.target.file))){if(!this.target.createIfNotExists)throw new Error(`file is not found: ${this.target.file}`);yield fsExtra.ensureFile(this.target.file);}yield fsExtra.writeFile(this.target.file,t,(e=this.target.encoding)!=null?e:"utf8");})}createPattern(){if(!this.target.pattern)throw new Error("pattern is required when text mode is replace");return new RegExp(this.target.pattern,this.target.flags)}createGetError(t){return {action:"get",success:false,file:this.target.file,type:this.target.type,message:t}}getErrorMessage(t){return t instanceof Error?t.message:String(t)}};var O=class{static create(t){return t.type==="text"?new h(t):t.type==="custom"?new y(t):new l(t)}},y=class{constructor(t){this.target=t;}get(){return a(this,null,function*(){if(!this.target.get)return {action:"get",success:false,file:this.target.file,type:this.target.type,message:"custom get is not implemented"};try{let t=yield this.target.get(this.target.file);return {action:"get",success:!0,file:this.target.file,type:this.target.type,value:t}}catch(t){return {action:"get",success:false,file:this.target.file,type:this.target.type,message:t instanceof Error?t.message:String(t)}}})}set(t){return a(this,null,function*(){try{let e=yield this.get();return this.target.set?(yield this.target.set(t,this.target.file),{action:"set",success:!0,file:this.target.file,type:this.target.type,oldValue:e.success?e.value:void 0,newValue:t}):{action:"set",success:!1,file:this.target.file,type:this.target.type,oldValue:e.success?e.value:void 0,newValue:t,message:"custom set is not implemented"}}catch(e){return {action:"set",success:false,file:this.target.file,type:this.target.type,newValue:t,message:e instanceof Error?e.message:String(e)}}})}update(t){return a(this,null,function*(){let e=yield this.set(t);return f(u({},e),{action:"update"})})}};exports.ConfigStore=l;exports.DEFAULT_JSON_STORE_OPTIONS=M;exports.DEFAULT_TEXT_STORE_OPTIONS=L;exports.JsonStore=T;exports.StoreFactory=O;exports.TextStore=h;
@@ -1,5 +1,6 @@
1
- import {readJson,writeJson}from'fs-extra';import E from'fs';import d from'path';/**
1
+ import {pathExists,ensureFile,readFile,writeFile}from'fs-extra';import {XMLParser,XMLBuilder}from'fast-xml-parser';import E from'js-yaml';import {set,get}from'lodash';import {parse,stringify}from'smol-toml';/**
2
2
  @tikkhun/version
3
- 2025.7.7
3
+ 2026.4.13
4
4
  */
5
- var T=Object.defineProperty,x=Object.defineProperties;var g=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var a=(r,t,o)=>t in r?T(r,t,{enumerable:true,configurable:true,writable:true,value:o}):r[t]=o,f=(r,t)=>{for(var o in t||(t={}))w.call(t,o)&&a(r,o,t[o]);if(p)for(var o of p(t))J.call(t,o)&&a(r,o,t[o]);return r},c=(r,t)=>x(r,g(t));var l=(r,t,o)=>new Promise((h,n)=>{var u=e=>{try{s(o.next(e));}catch(i){n(i);}},y=e=>{try{s(o.throw(e));}catch(i){n(i);}},s=e=>e.done?h(e.value):Promise.resolve(e.value).then(u,y);s((o=o.apply(r,t)).next());});var _={file:"package.json",key:"version"},m=class{constructor(t){this.opts=Object.assign({},_,t);}update(t){return l(this,null,function*(){try{let o=yield readJson(this.opts.file);return yield writeJson(this.opts.file,c(f({},o),{[this.opts.key]:t}),{spaces:2}),!0}catch(o){return false}})}};var O=process.cwd();var R={file:""},S=class{constructor(t){this.opts=t,this.filePath=d.join(O,this.opts.file);}update(t){try{return typeof t!="string"&&(t=JSON.stringify(t)),E.writeFileSync(this.filePath,t,"utf8"),!0}catch(o){return false}}};export{_ as DEFAULT_JSON_STORE_OPTIONS,R as DEFAULT_TEXT_STORE_OPTIONS,m as JsonStore,S as TextStore};
5
+ var P=Object.defineProperty,G=Object.defineProperties;var C=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var S=(n,t,e)=>t in n?P(n,t,{enumerable:true,configurable:true,writable:true,value:e}):n[t]=e,u=(n,t)=>{for(var e in t||(t={}))b.call(t,e)&&S(n,e,t[e]);if(w)for(var e of w(t))k.call(t,e)&&S(n,e,t[e]);return n},f=(n,t)=>G(n,C(t));var a=(n,t,e)=>new Promise((s,r)=>{var i=o=>{try{g(e.next(o));}catch(d){r(d);}},c=o=>{try{g(e.throw(o));}catch(d){r(d);}},g=o=>o.done?s(o.value):Promise.resolve(o.value).then(i,c);g((e=e.apply(n,t)).next());});var l=class{constructor(t){this.target=t;}get(){return a(this,null,function*(){var t;try{if(!(yield pathExists(this.target.file)))return this.createGetError(`file is not found: ${this.target.file}`);let e=yield this.loadStructuredConfig(),s=this.target.path?get(e,this.target.path):e;return s===void 0?this.createGetError(`path is not found: ${(t=this.target.path)!=null?t:"<root>"}`):typeof s!="string"&&typeof s!="number"?this.createGetError(`value is not string or number: ${JSON.stringify(s)}`):{action:"get",success:!0,file:this.target.file,type:this.target.type,value:s}}catch(e){return this.createGetError(this.getErrorMessage(e))}})}set(t){return a(this,null,function*(){try{let e=yield this.get(),s=e.success?e.value:void 0,r=yield pathExists(this.target.file);if(!r){if(!this.target.createIfNotExists)return this.createSetError(t,`file is not found: ${this.target.file}`,s,"set");yield ensureFile(this.target.file);}let i=r?yield this.loadStructuredConfig():{};if(this.target.path)set(i,this.target.path,t),yield this.saveStructuredConfig(i);else {if(typeof i=="object"&&i!==null&&!Array.isArray(i))return this.createSetError(t,"path is required for structured target",s,"set");yield this.saveStructuredConfig(t);}return {action:"set",success:!0,file:this.target.file,type:this.target.type,oldValue:s,newValue:t}}catch(e){return this.createSetError(t,this.getErrorMessage(e),void 0,"set")}})}update(t){return a(this,null,function*(){let e=yield this.set(t);return f(u({},e),{action:"update"})})}createGetError(t){return {action:"get",success:false,file:this.target.file,type:this.target.type,message:t}}createSetError(t,e,s,r="set"){return {action:r,success:false,file:this.target.file,type:this.target.type,oldValue:s,newValue:t,message:e}}getErrorMessage(t){return t instanceof Error?t.message:String(t)}loadStructuredConfig(){return a(this,null,function*(){var e;let t=yield readFile(this.target.file,(e=this.target.encoding)!=null?e:"utf8");switch(this.target.type){case "json":return JSON.parse(t);case "yaml":return E.load(t);case "toml":return parse(t);case "xml":return new XMLParser({ignoreAttributes:true}).parse(t);case "env":return this.parseEnvContent(t);default:throw new Error(`unsupported structured target type: ${this.target.type}`)}})}saveStructuredConfig(t){return a(this,null,function*(){var s;let e=(s=this.target.encoding)!=null?s:"utf8";switch(this.target.type){case "json":yield writeFile(this.target.file,JSON.stringify(t,null,2),e);return;case "yaml":yield writeFile(this.target.file,E.dump(t),e);return;case "toml":yield writeFile(this.target.file,stringify(t),e);return;case "xml":yield writeFile(this.target.file,new XMLBuilder({format:true,ignoreAttributes:true}).build(t),e);return;case "env":yield writeFile(this.target.file,this.stringifyEnvContent(t),e);return;default:throw new Error(`unsupported structured target type: ${this.target.type}`)}})}parseEnvContent(t){let e={},s=t.split(/\r?\n/);for(let r of s){let i=r.trim();if(!i||i.startsWith("#"))continue;let c=i.indexOf("=");if(c<0)continue;let g=i.slice(0,c).trim(),o=i.slice(c+1).trim();set(e,g.replace(/__/g,"."),o);}return e}stringifyEnvContent(t){let e=[],s=(r,i)=>{if(r!==null&&typeof r=="object"&&!Array.isArray(r)){for(let[g,o]of Object.entries(r))s(o,[...i,g]);return}let c=i.join("__").toUpperCase();e.push(`${c}=${r!=null?r:""}`);};for(let[r,i]of Object.entries(t))s(i,[r]);return e.join(`
6
+ `)}};var M={file:"package.json",key:"version"},T=class extends l{constructor(t){var r;let e=Object.assign({},M,t),s={type:"json",file:e.file,path:(r=e.path)!=null?r:e.key,createIfNotExists:e.createIfNotExists};super(s);}};var L={file:"",mode:"raw",trim:true,replacement:"{{version}}"},h=class{constructor(t){this.target=u(u({type:"text"},L),t);}get(){return a(this,null,function*(){var t;try{if(!(yield pathExists(this.target.file)))return this.createGetError(`file is not found: ${this.target.file}`);let e=yield readFile(this.target.file,(t=this.target.encoding)!=null?t:"utf8"),s=this.resolveValueFromText(e);return s===void 0?this.createGetError("version is not found in text content"):{action:"get",success:!0,file:this.target.file,type:this.target.type,value:s}}catch(e){return this.createGetError(this.getErrorMessage(e))}})}set(t){return a(this,null,function*(){try{let e=yield this.get(),s=e.success?e.value:void 0,r=yield this.createNextText(t);return yield this.writeText(r),{action:"set",success:!0,file:this.target.file,type:this.target.type,oldValue:s,newValue:t}}catch(e){return {action:"set",success:false,file:this.target.file,type:this.target.type,newValue:t,message:this.getErrorMessage(e)}}})}update(t){return a(this,null,function*(){let e=yield this.set(t);return f(u({},e),{action:"update"})})}resolveValueFromText(t){var e;if(this.target.mode==="replace"){let r=this.createPattern().exec(t);if(!r)return;let i=(e=r.groups)==null?void 0:e.version;return i!==void 0?i:r[1]!==void 0?r[1]:r[0]}return this.target.trim?t.trim():t}createNextText(t){return a(this,null,function*(){var e,s;if(this.target.mode==="replace"){if(!(yield pathExists(this.target.file)))throw new Error(`file is not found: ${this.target.file}`);let r=yield readFile(this.target.file,(e=this.target.encoding)!=null?e:"utf8");if(!this.createPattern().test(r))throw new Error("pattern is not matched");let c=((s=this.target.replacement)!=null?s:"{{version}}").replaceAll("{{version}}",String(t));return r.replace(this.createPattern(),c)}return String(t)})}writeText(t){return a(this,null,function*(){var e;if(!(yield pathExists(this.target.file))){if(!this.target.createIfNotExists)throw new Error(`file is not found: ${this.target.file}`);yield ensureFile(this.target.file);}yield writeFile(this.target.file,t,(e=this.target.encoding)!=null?e:"utf8");})}createPattern(){if(!this.target.pattern)throw new Error("pattern is required when text mode is replace");return new RegExp(this.target.pattern,this.target.flags)}createGetError(t){return {action:"get",success:false,file:this.target.file,type:this.target.type,message:t}}getErrorMessage(t){return t instanceof Error?t.message:String(t)}};var O=class{static create(t){return t.type==="text"?new h(t):t.type==="custom"?new y(t):new l(t)}},y=class{constructor(t){this.target=t;}get(){return a(this,null,function*(){if(!this.target.get)return {action:"get",success:false,file:this.target.file,type:this.target.type,message:"custom get is not implemented"};try{let t=yield this.target.get(this.target.file);return {action:"get",success:!0,file:this.target.file,type:this.target.type,value:t}}catch(t){return {action:"get",success:false,file:this.target.file,type:this.target.type,message:t instanceof Error?t.message:String(t)}}})}set(t){return a(this,null,function*(){try{let e=yield this.get();return this.target.set?(yield this.target.set(t,this.target.file),{action:"set",success:!0,file:this.target.file,type:this.target.type,oldValue:e.success?e.value:void 0,newValue:t}):{action:"set",success:!1,file:this.target.file,type:this.target.type,oldValue:e.success?e.value:void 0,newValue:t,message:"custom set is not implemented"}}catch(e){return {action:"set",success:false,file:this.target.file,type:this.target.type,newValue:t,message:e instanceof Error?e.message:String(e)}}})}update(t){return a(this,null,function*(){let e=yield this.set(t);return f(u({},e),{action:"update"})})}};export{l as ConfigStore,M as DEFAULT_JSON_STORE_OPTIONS,L as DEFAULT_TEXT_STORE_OPTIONS,T as JsonStore,O as StoreFactory,h as TextStore};
package/dist/lib/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';/**
2
2
  @tikkhun/version
3
- 2025.7.7
3
+ 2026.4.13
4
4
  */
5
5
  var c=process.cwd();exports.workspace=c;
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  @tikkhun/version
3
- 2025.7.7
3
+ 2026.4.13
4
4
  */
5
5
  var c=process.cwd();export{c as workspace};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tikkhun/version",
3
- "version": "2025.7.8",
3
+ "version": "2026.4.13",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "date-version": "./dist/cli/date-version.js",
@@ -31,16 +31,20 @@
31
31
  "license": "ISC",
32
32
  "dependencies": {
33
33
  "commander": "^14.0.0",
34
- "dayjs": "^1.11.13",
35
- "fs-extra": "^11.3.0",
34
+ "dayjs": "^1.11.18",
35
+ "fast-xml-parser": "^5.2.5",
36
+ "fs-extra": "^11.3.1",
37
+ "js-yaml": "^4.1.0",
38
+ "lodash": "^4.17.21",
39
+ "smol-toml": "^1.4.2",
36
40
  "@tikkhun/utils": "^1.0.19",
37
- "@tikkhun/date-version": "^0.0.1",
38
- "@tikkhun/logger": "^1.0.8"
41
+ "@tikkhun/logger": "^1.0.8",
42
+ "@tikkhun/date-version": "^0.0.1"
39
43
  },
40
44
  "devDependencies": {
41
45
  "@types/fs-extra": "^11.0.4",
42
46
  "@types/node": "^24.0.10",
43
- "tsx": "^4.20.3",
47
+ "tsx": "^4.20.5",
44
48
  "tsup": "^8.5.0",
45
49
  "vitest": "^3.2.4"
46
50
  },