change-versions 1.0.0 → 1.1.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/dist/cli.js +18 -16
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var oe=(e,n,t)=>()=>{if(e)try{n=e(e=0)}catch(r){t=[r]}if(t)throw t[0];return n};function ae(){let e=(process.env.LC_ALL||process.env.LC_MESSAGES||process.env.LANG||"").split(".")[0];return/^zh/i.test(e)?"zh":"en"}function i(e,n,t=ae()){let r=un[e][t];if(n)for(let[s,o]of Object.entries(n))r=r.replaceAll(`{${s}}`,String(o));return r}var un;var x=oe(()=>{un={publishHeadChanged:{zh:"发布 hook 改变了 HEAD。下一步: 检查该提交,让 hook 只更新忽略的构建产物后重跑 publish",en:"A publish hook changed HEAD. Review that commit and keep hooks limited to ignored build output before retrying publish"},wrongBranch:{zh:"当前分支不是 {branch}。下一步: 切换到该分支后重跑 version",en:"Current branch is not {branch}. Next: switch to that branch and rerun version"},releaseVersionMismatch:{zh:"{name} 当前版本 {actual} 与 version 提交中的 {expected} 不一致。下一步: 检查提交和 package.json 后再发布",en:"{name} is at {actual}, but the version commit records {expected}. Check the commit and package.json before publishing"},releaseContentsChanged:{zh:"待发布包在 version 提交后又有改动。下一步: 先完成新一轮 version,再发布对应提交",en:"Release packages changed after the version commit. Next: create a new version commit before publishing"},unexpectedRegistryVersion:{zh:"registry 未返回预期版本 {name}@{version},无法确认是否已发布",en:"The registry did not return the expected version {name}@{version}"},dirtyTree:{zh:"工作区不干净。下一步: 提交或还原后,重跑刚才那条命令",en:"Working tree is dirty. Next: commit or restore your changes, then rerun the same command"},gitFailed:{zh:`git 失败。下一步: 在 git 仓库里重跑
|
|
3
3
|
{detail}`,en:`git failed. Next: rerun this inside a git repository
|
|
4
4
|
{detail}`},noPackagesSince:{zh:"自 {rev} 以来没有需要升版的包",en:"No packages to version since {rev}"},changedHeader:{zh:"变更:",en:"Changed:"},dependentsHeader:{zh:"依赖方:",en:"Dependents:"},confirmVersions:{zh:"以上版本是否确认?",en:"Apply these versions?"},cancelledVersion:{zh:"已取消。还没改文件。想继续就再跑同一条命令",en:"Cancelled. No files were changed. Rerun the same command to continue"},branchPushFailed:{zh:`分支推送失败。commit 已在本地。下一步: git push origin {branch},不要重跑 version
|
|
5
5
|
{detail}`,en:`Branch push failed. The commit is local. Next: git push origin {branch}. Do not rerun version
|
|
@@ -9,16 +9,18 @@ var ae=(e,n,t)=>()=>{if(e)try{n=e(e=0)}catch(r){t=[r]}if(t)throw t[0];return n};
|
|
|
9
9
|
{detail}`,en:`Network failed after 2 retries. Later packages were not published and no git tag was created. Next: rerun the same publish. Do not rerun version
|
|
10
10
|
{detail}`},notLoggedIn:{zh:"未登录 {registry}。下一步: npm login --registry={registry},然后重跑同一条 publish。不要重跑 version",en:"Not logged in to {registry}. Next: npm login --registry={registry}, then rerun the same publish. Do not rerun version"},registryUnreachable:{zh:`无法访问 {registry}。下一步: 检查网络后重跑同一条 publish。不要重跑 version
|
|
11
11
|
{detail}`,en:`Cannot reach {registry}. Next: check the network, then rerun the same publish. Do not rerun version
|
|
12
|
-
{detail}`},noNpmRegistry:{zh
|
|
12
|
+
{detail}`},noNpmRegistry:{zh:`读不到 npm registry:
|
|
13
|
+
{detail}`,en:`Cannot read the npm registry:
|
|
14
|
+
{detail}`},npmFailed:{zh:"npm 失败",en:"npm failed"},npmViewFailed:{zh:"npm view 失败",en:"npm view failed"},hookFailed:{zh:`{name} 失败。下一步: 修好 hook 后重跑 publish。不上传,不打 git tag
|
|
13
15
|
{detail}`,en:`{name} failed. Next: fix the hook, then rerun publish. Nothing was uploaded and no git tag was created
|
|
14
|
-
{detail}`},beforePublishDirty:{zh:"beforePublish 改了被跟踪的文件。下一步: hook 只能改 git 忽略的构建产物,弄干净后重跑 publish",en:"beforePublish changed tracked files. Next: the hook may only change gitignored build output. Clean the tree, then rerun publish"},afterPublishDirty:{zh:"afterPublish 改了被跟踪的文件,还没打 git tag。下一步: 让 hook 不改被跟踪的文件,弄干净后重跑 publish",en:"afterPublish changed tracked files, so no git tag was created. Next: keep the hook off tracked files, clean the tree, then rerun publish"},configUnreadable:{zh:"配置读不了: {file}。下一步: 补上 include,删掉不认识的字段",en:"Cannot read config: {file}. Next: add include and remove unknown fields"},packagesDirMissing:{zh:"找不到目录 {dir}",en:"Directory not found: {dir}"},packageJsonIncomplete:{zh:"{folder} 的 package.json 缺少 name 或 version",en:"{folder} package.json is missing name or version"},publicDependsOnPrivate:{zh:"public 包 {name} 不能依赖 private 包 {dep}。下一步: 改依赖后重跑 version",en:"Public package {name} cannot depend on private package {dep}. Next: change the dependency, then rerun version"},missingVersionField:{zh:"{folder} 缺少 version",en:"{folder} is missing version"},badBump:{zh:"档位非法: {bump}。可用 {list}",en:"Invalid bump: {bump}. Use {list}"},preidRequired:{zh:"{kind} 必须带 --preid。预发布用 prepatch 这类档位",en:"{kind} requires --preid. Use a pre* bump for prereleases"},preidForbidden:{zh:"正式版不能带 --preid。预发布用 prepatch 这类档位",en:"A stable bump cannot take --preid. Use a pre* bump for prereleases"},badLine:{zh:"第 {line} 行无法解析",en:"Cannot parse line {line}"},unknownField:{zh:"不认识的字段 {name}",en:"Unknown field {name}"},missingValue:{zh:"{name} 缺少值",en:"{name} is missing a value"},includeRequired:{zh:"include 不能为空。下一步: 补上 include,删掉不认识的字段",en:"include must not be empty. Next: add include and remove unknown fields"},commitMessageNeedsToken:{zh:"commitMessage 需要 %s",en:"commitMessage must contain %s"},patternBang:{zh:"模式不能包含 !: {pattern}",en:"Patterns cannot contain !: {pattern}"},patternClass:{zh:"不支持字符组: {pattern}",en:"Character classes are not supported: {pattern}"},badHook:{zh:"hooks 无法解析: {line}",en:"Cannot parse hooks: {line}"},unknownHook:{zh:"不认识的 hook {name}",en:"Unknown hook {name}"},hookMissingCommand:{zh:"{name} 缺少命令",en:"{name} is missing a command"},badPatternLine:{zh:"路径列表无法解析: {line}",en:"Cannot parse path list: {line}"},badSemver:{zh:"无法解析版本 {version}",en:"Cannot parse version {version}"},dependencyCycle:{zh:"依赖成环: {name}",en:"Dependency cycle: {name}"},bumpRequired:{zh:"非交互环境必须写上档位",en:"A bump is required when not interactive"},chooseIndex:{zh:"请输入序号: ",en:"Enter a number: "},invalidChoice:{zh:"无效选择: {answer}",en:"Invalid choice: {answer}"},emptyAnswer:{zh:"(空)",en:"(empty)"},yesRequired:{zh:"非交互环境需要 --yes",en:"Pass --yes when not interactive"},commandFailed:{zh:"{command} 失败: {detail}",en:"{command} failed: {detail}"},commandFailedShort:{zh:"{command} 失败",en:"{command} failed"},commandExit:{zh:"{command} 退出 {code}",en:"{command} exited {code}"},cliDescription:{zh:"只给需要发的包升版本,再按那次提交发布",en:"Version only the packages that need a release, then publish that commit"},optRoot:{zh:"仓库根目录",en:"Repository root"},optVersionsFile:{zh:"配置文件",en:"Config file"},optPackages:{zh:"覆盖 packagesDir",en:"Override packagesDir"},cmdChanged:{zh:"列出会升版的包",en:"List packages that would be versioned"},optBaseline:{zh:"这一次的比较起点,SHA 或 tag",en:"Comparison start for this run, SHA or tag"},cmdVersion:{zh:"升版本并提交",en:"Bump versions and commit"},argBump:{zh:"patch、minor、major、prerelease、prepatch、preminor、premajor",en:"patch, minor, major, prerelease, prepatch, preminor, or premajor"},optPreid:{zh:"预发布标识,pre* 必填",en:"Prerelease identifier, required for pre*"},optYes:{zh:"跳过确认",en:"Skip confirmation"},optDryRunVersion:{zh:"只打印旧版本到新版本",en:"Print old and new versions only"},optBranch:{zh:"覆盖配置里的 branch",en:"Override branch from the config"},optCommitMessage:{zh:"覆盖 commitMessage",en:"Override commitMessage"},cmdPublish:{zh:"发布最近一次 version 提交里的包",en:"Publish packages listed in the latest version commit"},optDistTag:{zh:"npm dist-tag",en:"npm dist-tag"},optDryRunPublish:{zh:"只打印将执行的 hook、npm publish 和 git tag",en:"Print the hooks, npm publish commands, and git tags without running them"},cmdInit:{zh:"写入带注释的配置",en:"Write a commented config file"},optYesInit:{zh:"不提问,按探测到的目录写默认配置",en:"Write defaults from the detected directory, without prompts"},configExists:{zh:"已有 {file}。下一步: 直接改这个文件,或删掉后重跑 init",en:"Config already exists: {file}. Next: edit that file, or delete it and rerun init"},initIntro:{zh:"写入 {file}",en:"Write {file}"},initFoundDirs:{zh:"发现包目录: {dirs}",en:"Package directories: {dirs}"},initPackagesDir:{zh:"包目录",en:"Package directory"},initInclude:{zh:"源码路径,逗号分隔",en:"Source paths, comma-separated"},initExclude:{zh:"排除路径,逗号分隔",en:"Excluded paths, comma-separated"},initBranch:{zh:"推送分支,回车跳过",en:"Branch to push, Enter to skip"},initBeforeCommit:{zh:"beforeCommit,回车跳过",en:"beforeCommit, Enter to skip"},initBeforePublish:{zh:"beforePublish,回车跳过",en:"beforePublish, Enter to skip"},initWrote:{zh:"已写入 {file}",en:"Wrote {file}"},initNotePackagesDir:{zh:"包所在目录。这次可用 --packages 覆盖",en:"Directory of packages. Override once with --packages"},initNoteCommitMessage:{zh:"%s 换成档位。有 --preid 时再空一格接上,例如 bump: prerelease alpha。查找看正文末尾的 Co-authored-by: change-versions <publish@change-versions.com>,不改提交作者",en:"%s becomes the bump. With --preid, a space and the id follow, for example bump: prerelease alpha. Lookup uses the Co-authored-by: change-versions <publish@change-versions.com> trailer. The commit author stays unchanged"},initNoteBranch:{zh:"不写就不推送。version 只推这个分支,不推 tag",en:"Omit to skip pushing. version pushes this branch only, not tags"},initNoteBeforeCommit:{zh:"版本和 CHANGELOG 写完之后、git commit 之前。失败会退回 HEAD",en:"After versions and CHANGELOG are written, before git commit. Failure restores HEAD"},initNoteBeforePublish:{zh:"确认之后、npm publish 之前。只能改 git 忽略的构建产物",en:"After confirm, before npm publish. May only change gitignored build output"},initNoteAfterPublish:{zh:"要发的包都已在 registry 上之后。不能把工作区弄脏",en:"After every selected package is on the registry. Must leave the tree clean"},initNoteInclude:{zh:"相对仓库根。* 和 ? 不跨过 /,** 可以。命中目录时,目录里的文件也算",en:"Relative to the repo root. * and ? do not cross /, ** may. A matching directory includes files under it"},initNoteExclude:{zh:"命中这里的文件不触发升版。package.json 另比,去掉 devDependencies 后有差异才算",en:"Files that match here do not trigger a bump. package.json is compared separately, after dropping devDependencies"}}});import
|
|
15
|
-
`)){if(!a.startsWith(s))continue;let g=a.slice(s.length),d=g.split("/")[0];if(!d||!g.includes("/")||!r.has(d))continue;let m=o.get(d)??[];m.push(a),o.set(d,m)}return o}function Re(e,n,t,r,s,o){let a=[],g=[];for(let d of e){let m=n.get(d);if(!m?.length){g.push(d);continue}let p=`${o}/${d}/package.json`;if(m.some((k)=>k!==p&&
|
|
16
|
-
`)){let r=/^(\S+) (\S+) => (\S+)$/.exec(t.trim());if(r)n.push({name:r[1],from:r[2],to:r[3]})}return n}function
|
|
16
|
+
{detail}`},beforePublishDirty:{zh:"beforePublish 改了被跟踪的文件。下一步: hook 只能改 git 忽略的构建产物,弄干净后重跑 publish",en:"beforePublish changed tracked files. Next: the hook may only change gitignored build output. Clean the tree, then rerun publish"},afterPublishDirty:{zh:"afterPublish 改了被跟踪的文件,还没打 git tag。下一步: 让 hook 不改被跟踪的文件,弄干净后重跑 publish",en:"afterPublish changed tracked files, so no git tag was created. Next: keep the hook off tracked files, clean the tree, then rerun publish"},configUnreadable:{zh:"配置读不了: {file}。下一步: 补上 include,删掉不认识的字段",en:"Cannot read config: {file}. Next: add include and remove unknown fields"},packagesDirMissing:{zh:"找不到目录 {dir}",en:"Directory not found: {dir}"},packageJsonIncomplete:{zh:"{folder} 的 package.json 缺少 name 或 version",en:"{folder} package.json is missing name or version"},publicDependsOnPrivate:{zh:"public 包 {name} 不能依赖 private 包 {dep}。下一步: 改依赖后重跑 version",en:"Public package {name} cannot depend on private package {dep}. Next: change the dependency, then rerun version"},missingVersionField:{zh:"{folder} 缺少 version",en:"{folder} is missing version"},badBump:{zh:"档位非法: {bump}。可用 {list}",en:"Invalid bump: {bump}. Use {list}"},preidRequired:{zh:"{kind} 必须带 --preid。预发布用 prepatch 这类档位",en:"{kind} requires --preid. Use a pre* bump for prereleases"},preidForbidden:{zh:"正式版不能带 --preid。预发布用 prepatch 这类档位",en:"A stable bump cannot take --preid. Use a pre* bump for prereleases"},badLine:{zh:"第 {line} 行无法解析",en:"Cannot parse line {line}"},unknownField:{zh:"不认识的字段 {name}",en:"Unknown field {name}"},missingValue:{zh:"{name} 缺少值",en:"{name} is missing a value"},includeRequired:{zh:"include 不能为空。下一步: 补上 include,删掉不认识的字段",en:"include must not be empty. Next: add include and remove unknown fields"},commitMessageNeedsToken:{zh:"commitMessage 需要 %s",en:"commitMessage must contain %s"},patternBang:{zh:"模式不能包含 !: {pattern}",en:"Patterns cannot contain !: {pattern}"},patternClass:{zh:"不支持字符组: {pattern}",en:"Character classes are not supported: {pattern}"},badHook:{zh:"hooks 无法解析: {line}",en:"Cannot parse hooks: {line}"},unknownHook:{zh:"不认识的 hook {name}",en:"Unknown hook {name}"},hookMissingCommand:{zh:"{name} 缺少命令",en:"{name} is missing a command"},badPatternLine:{zh:"路径列表无法解析: {line}",en:"Cannot parse path list: {line}"},badSemver:{zh:"无法解析版本 {version}",en:"Cannot parse version {version}"},dependencyCycle:{zh:"依赖成环: {name}",en:"Dependency cycle: {name}"},bumpRequired:{zh:"非交互环境必须写上档位",en:"A bump is required when not interactive"},chooseIndex:{zh:"请输入序号: ",en:"Enter a number: "},invalidChoice:{zh:"无效选择: {answer}",en:"Invalid choice: {answer}"},emptyAnswer:{zh:"(空)",en:"(empty)"},yesRequired:{zh:"非交互环境需要 --yes",en:"Pass --yes when not interactive"},commandFailed:{zh:"{command} 失败: {detail}",en:"{command} failed: {detail}"},commandFailedShort:{zh:"{command} 失败",en:"{command} failed"},commandExit:{zh:"{command} 退出 {code}",en:"{command} exited {code}"},cliDescription:{zh:"只给需要发的包升版本,再按那次提交发布",en:"Version only the packages that need a release, then publish that commit"},optRoot:{zh:"仓库根目录",en:"Repository root"},optVersionsFile:{zh:"配置文件",en:"Config file"},optPackages:{zh:"覆盖 packagesDir",en:"Override packagesDir"},cmdChanged:{zh:"列出会升版的包",en:"List packages that would be versioned"},optBaseline:{zh:"这一次的比较起点,SHA 或 tag",en:"Comparison start for this run, SHA or tag"},cmdVersion:{zh:"升版本并提交",en:"Bump versions and commit"},argBump:{zh:"patch、minor、major、prerelease、prepatch、preminor、premajor",en:"patch, minor, major, prerelease, prepatch, preminor, or premajor"},optPreid:{zh:"预发布标识,pre* 必填",en:"Prerelease identifier, required for pre*"},optYes:{zh:"跳过确认",en:"Skip confirmation"},optDryRunVersion:{zh:"只打印旧版本到新版本",en:"Print old and new versions only"},optBranch:{zh:"覆盖配置里的 branch",en:"Override branch from the config"},optCommitMessage:{zh:"覆盖 commitMessage",en:"Override commitMessage"},cmdPublish:{zh:"发布最近一次 version 提交里的包",en:"Publish packages listed in the latest version commit"},optDistTag:{zh:"npm dist-tag",en:"npm dist-tag"},optDryRunPublish:{zh:"只打印将执行的 hook、npm publish 和 git tag",en:"Print the hooks, npm publish commands, and git tags without running them"},cmdInit:{zh:"写入带注释的配置",en:"Write a commented config file"},optYesInit:{zh:"不提问,按探测到的目录写默认配置",en:"Write defaults from the detected directory, without prompts"},configExists:{zh:"已有 {file}。下一步: 直接改这个文件,或删掉后重跑 init",en:"Config already exists: {file}. Next: edit that file, or delete it and rerun init"},initIntro:{zh:"写入 {file}",en:"Write {file}"},initFoundDirs:{zh:"发现包目录: {dirs}",en:"Package directories: {dirs}"},initPackagesDir:{zh:"包目录",en:"Package directory"},initInclude:{zh:"源码路径,逗号分隔",en:"Source paths, comma-separated"},initExclude:{zh:"排除路径,逗号分隔",en:"Excluded paths, comma-separated"},initBranch:{zh:"推送分支,回车跳过",en:"Branch to push, Enter to skip"},initBeforeCommit:{zh:"beforeCommit,回车跳过",en:"beforeCommit, Enter to skip"},initBeforePublish:{zh:"beforePublish,回车跳过",en:"beforePublish, Enter to skip"},initWrote:{zh:"已写入 {file}",en:"Wrote {file}"},initNotePackagesDir:{zh:"包所在目录。这次可用 --packages 覆盖",en:"Directory of packages. Override once with --packages"},initNoteCommitMessage:{zh:"%s 换成档位。有 --preid 时再空一格接上,例如 bump: prerelease alpha。查找看正文末尾的 Co-authored-by: change-versions <publish@change-versions.com>,不改提交作者",en:"%s becomes the bump. With --preid, a space and the id follow, for example bump: prerelease alpha. Lookup uses the Co-authored-by: change-versions <publish@change-versions.com> trailer. The commit author stays unchanged"},initNoteBranch:{zh:"不写就不推送。version 只推这个分支,不推 tag",en:"Omit to skip pushing. version pushes this branch only, not tags"},initNoteBeforeCommit:{zh:"版本和 CHANGELOG 写完之后、git commit 之前。失败会退回 HEAD",en:"After versions and CHANGELOG are written, before git commit. Failure restores HEAD"},initNoteBeforePublish:{zh:"确认之后、npm publish 之前。只能改 git 忽略的构建产物",en:"After confirm, before npm publish. May only change gitignored build output"},initNoteAfterPublish:{zh:"要发的包都已在 registry 上之后。不能把工作区弄脏",en:"After every selected package is on the registry. Must leave the tree clean"},initNoteInclude:{zh:"相对仓库根。* 和 ? 不跨过 /,** 可以。命中目录时,目录里的文件也算",en:"Relative to the repo root. * and ? do not cross /, ** may. A matching directory includes files under it"},initNoteExclude:{zh:"命中这里的文件不触发升版。package.json 另比,去掉 devDependencies 后有差异才算",en:"Files that match here do not trigger a bump. package.json is compared separately, after dropping devDependencies"}}});import xe from"picomatch";import _ from"semver";import{YAMLParseError as fn,parse as hn}from"yaml";function ge(e){return De.has(e)}function ze(e,n){if(!Pe.includes(e))throw new c(i("badBump",{bump:e,list:Pe.join(", ")}));let t=e;if(bn.has(t)&&!n)throw new c(i("preidRequired",{kind:t}));if(De.has(t)&&n)throw new c(i("preidForbidden"));return t}function U(e){let n=kn(e);for(let d of Object.keys(n))if(!wn.has(d))throw new c(i("unknownField",{name:d}));let t=n.packagesDir===void 0?"packages":ce(n.packagesDir,"packagesDir"),r=n.commitMessage===void 0?"bump: %s":ce(n.commitMessage,"commitMessage"),s=n.branch===void 0?void 0:ce(n.branch,"branch"),o=n.hooks==null?{}:vn(n.hooks),a=n.include==null?[]:Ce(n.include,"include"),g=n.exclude==null?[]:Ce(n.exclude,"exclude");if(!a.length)throw new c(i("includeRequired"));if(!r.includes("%s"))throw new c(i("commitMessageNeedsToken"));for(let d of[...a,...g]){if(d.includes("!"))throw new c(i("patternBang",{pattern:d}));if(/\[[^\]]+\]/.test(d))throw new c(i("patternClass",{pattern:d}))}return{packagesDir:t,commitMessage:r,branch:s,hooks:o,include:a,exclude:g}}function kn(e){try{let n=hn(e);if(n==null)return{};if(!Ne(n))throw new c(i("badLine",{line:1}));return n}catch(n){if(n instanceof c)throw n;if(n instanceof fn)throw new c(i("badLine",{line:n.linePos?.[0]?.line??1}));throw n}}function vn(e){if(!Ne(e))throw new c(i("badHook",{line:"hooks"}));let n={};for(let[t,r]of Object.entries(e)){if(!yn.has(t))throw new c(i("unknownHook",{name:t}));if(typeof r!=="string"||!r)throw new c(i("hookMissingCommand",{name:t}));n[t]=r}return n}function Ce(e,n){if(!Array.isArray(e))throw new c(i("badPatternLine",{line:n}));return e.map((t)=>{if(typeof t!=="string"||!t)throw new c(i("badPatternLine",{line:n}));return t})}function ce(e,n){if(typeof e!=="string"||!e)throw new c(i("missingValue",{name:n}));return e}function Ne(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function Se(e,n){let t={dot:!0};if(xe(n,t)(e))return!0;if(n.endsWith("/**"))return!1;return xe(`${n}/**`,t)(e)}function de(e,n,t){return n.some((r)=>Se(e,r))&&!t.some((r)=>Se(e,r))}function Fe(e,n,t){let r=new Set(t),s=`${n}/`,o=new Map;for(let a of e.split(`
|
|
17
|
+
`)){if(!a.startsWith(s))continue;let g=a.slice(s.length),d=g.split("/")[0];if(!d||!g.includes("/")||!r.has(d))continue;let m=o.get(d)??[];m.push(a),o.set(d,m)}return o}function Re(e,n,t,r,s,o){let a=[],g=[];for(let d of e){let m=n.get(d);if(!m?.length){g.push(d);continue}let p=`${o}/${d}/package.json`;if(m.some((k)=>k!==p&&de(k,t,r))||m.includes(p)&&!s(d))a.push(d);else g.push(d)}return{changed:a,ignored:g}}function je(e,n){return JSON.stringify(J($e(e)))===JSON.stringify(J($e(n)))}function $e(e){if(!e||typeof e!=="object"||Array.isArray(e))return e;let n={...e};return delete n.devDependencies,n}function J(e){if(Array.isArray(e))return e.map(J);if(e&&typeof e==="object"){let n=e;return Object.fromEntries(Object.keys(n).sort().map((t)=>[t,J(n[t])]))}return e}function Be(e,n,t){let r=t?_.inc(e,n,t):_.inc(e,n);if(!r)throw new c(i("badSemver",{version:e}));return r}function Ae(e,n,t){let r=new Set(n),s=new Map(e.map((a)=>[a,[]]));for(let a of e)for(let g of t(a))s.get(g)?.push(a);let o=[...n];while(o.length){let a=o.pop();if(!a)break;for(let g of s.get(a)??[]){if(r.has(g))continue;r.add(g),o.push(g)}}return e.filter((a)=>r.has(a))}function Ee(e,n,t){let r=e.replace("%s",n);return t?`${r} ${t}`:r}function Y(e){return e.length>0&&e.every((n)=>Boolean(_.valid(n.to))&&_.prerelease(n.to)==null)}function Te(e){return/^v\d/.test(e)}function Me(e){return/^v\d+\.\d+\.\d+$/.test(e)}function Z(e){let n=[];for(let t of e.split(`
|
|
18
|
+
`)){let r=/^(\S+) (\S+) => (\S+)$/.exec(t.trim());if(r)n.push({name:r[1],from:r[2],to:r[3]})}return n}function Ie(e){let n=new Map(e.map((o)=>[o.folder,o])),t=new Set,r=[],s=(o,a)=>{if(t.has(o.folder))return;if(a.has(o.folder))throw new c(i("dependencyCycle",{name:o.name}));a.add(o.folder);for(let g of o.deps){let d=n.get(g);if(d)s(d,a)}a.delete(o.folder),t.add(o.folder),r.push(o)};for(let o of e)s(o,new Set);return r}function Q(e){return/ENEEDAUTH|E401|E403|need auth|not logged in|401 Unauthorized|403 Forbidden/i.test(e)}function le(e){try{return JSON.parse(e)?.error?.code==="E404"}catch{return!1}}var c,Pe,De,bn,wn,yn,xn="publish@change-versions.com",Pn,K;var P=oe(()=>{x();c=class c extends Error{auth;constructor(e,n=!1){super(e);this.name="Fail",this.auth=n}};Pe=["patch","minor","major","prerelease","prepatch","preminor","premajor"],De=new Set(["patch","minor","major"]),bn=new Set(["prerelease","prepatch","preminor","premajor"]);wn=new Set(["packagesDir","commitMessage","branch","hooks","include","exclude"]),yn=new Set(["beforeCommit","beforePublish","afterPublish"]);Pn=`change-versions <${xn}>`,K=`Co-authored-by: ${Pn}`});import{CommitParser as Vn}from"conventional-commits-parser";import{writeChangelogString as Gn}from"conventional-changelog-writer";function an(e){return e.find((n)=>Y(Z(n.body)))?.hash}function cn(e,n,t,r,s,o){let a=`${t}/${n}/package.json`,g=`${t}/${n}/`,d=[];for(let m of e)if(m.files.some((u)=>u!==a&&u.startsWith(g)&&de(u,r,s))||m.files.includes(a)&&o.has(m.hash))d.push({hash:m.hash,body:m.body});return d}async function gn(e){let n=new Date().toISOString().slice(0,10),t=[`## ${e.version} (${n})`];if(e.previousTag){let o=`../../compare/${encodeURIComponent(e.previousTag)}...${encodeURIComponent(e.currentTag)}`;t.push(`[${e.previousTag}...${e.currentTag}](${o})`)}let r=new Vn({noteKeywords:["BREAKING CHANGE","BREAKING-CHANGE"]}),s=[];for(let o of e.messages){let a;try{a=r.parse(o.body)}catch{continue}s.push({...a,hash:o.hash.slice(0,7),notes:a.notes??[],subject:a.subject})}if(s.length){let a=(await Gn(s,{version:e.version,date:n},{groupBy:"type",mainTemplate:Wn,transform(g){let m=(g.notes??[]).some((u)=>/breaking/i.test(u.title)),p=g.type??"";if(qn.has(p)&&!m)return null;if(!sn[p]&&!m)return null;return{type:sn[p]??null}}})).trim();if(a)t.push("",a);else if(e.dependencies.length)t.push("",on(e.dependencies))}else if(e.dependencies.length)t.push("",on(e.dependencies).trimEnd());return`${t.join(`
|
|
17
19
|
`).trim()}
|
|
18
|
-
`}function
|
|
20
|
+
`}function on(e){return`### Dependencies
|
|
19
21
|
|
|
20
22
|
* update dependencies ${e.map((n)=>`${n.name}@${n.version}`).join(", ")}
|
|
21
|
-
`}var
|
|
23
|
+
`}var qn,sn,Wn=`{{#each commitGroups}}
|
|
22
24
|
{{#if title}}
|
|
23
25
|
### {{title}}
|
|
24
26
|
|
|
@@ -36,18 +38,18 @@ var ae=(e,n,t)=>()=>{if(e)try{n=e(e=0)}catch(r){t=[r]}if(t)throw t[0];return n};
|
|
|
36
38
|
{{/each}}
|
|
37
39
|
|
|
38
40
|
{{/each}}
|
|
39
|
-
`;var
|
|
41
|
+
`;var dn=oe(()=>{P();qn=new Set(["docs","style","chore","refactor","test","build","ci"]),sn={feat:"Features",feature:"Features",fix:"Bug Fixes",perf:"Performance Improvements",revert:"Reverts"}});import{Command as nt}from"commander";import{readFileSync as tt}from"node:fs";import $n from"node:path";import{styleText as pn}from"node:util";function N(e,n,t){return pn(e,n,{stream:t})}function D(e){return N(["bold","cyan"],e,process.stdout)}function F(e){return N("bold",e,process.stdout)}function R(e){return N("green",e,process.stdout)}function v(e){return N("dim",e,process.stdout)}function V(e){return N("cyan",e,process.stdout)}function ve(e,n,t){return`${F(e)} ${v(n)} ${v("=>")} ${R(t)}`}function M(e){let[n,...t]=e.split(`
|
|
40
42
|
`),r=N("red",n,process.stderr);if(!t.length)return r;return[r,...t.map((s)=>N("yellow",s,process.stderr))].join(`
|
|
41
|
-
`)}x();x();P();import{spawn as
|
|
42
|
-
`).filter(Boolean).map((t)=>{let[r,s]=t.split("\x1F");return{hash:r,subject:s??""}})}async function G(e){let n=await w("git",["log","-F",`--grep=${
|
|
43
|
+
`)}x();x();P();import{spawn as Oe,spawnSync as He}from"node:child_process";function f(e,n,t){return new Promise((r)=>{let s=Oe(e,n,{cwd:t,stdio:["ignore","pipe","pipe"]}),o="",a="";s.stdout.on("data",(g)=>{o+=g}),s.stderr.on("data",(g)=>{a+=g}),s.on("error",(g)=>r({code:1,stdout:o,stderr:`${a}${g.message}`})),s.on("close",(g)=>r({code:g??1,stdout:o,stderr:a}))})}async function w(e,n,t){let r=await f(e,n,t);if(r.code!==0){let s=(r.stderr||r.stdout).trim();throw new c(s?i("commandFailed",{command:e,detail:s}):i("commandFailedShort",{command:e}))}return r.stdout}function X(e,n,t){return new Promise((r,s)=>{let o=Oe(e,n,{cwd:t,stdio:"inherit"});o.on("error",s),o.on("exit",(a)=>{if(a===0)r();else s(new c(i("commandExit",{command:e,code:a??1})))})})}function me(e,n="HEAD"){He("git",["reset","--hard",n],{cwd:e,stdio:"inherit"}),He("git",["clean","-fd"],{cwd:e,stdio:"inherit"})}x();P();import I from"node:fs";import ee from"node:path";x();P();function Le(e){let n=e.packages.map((d)=>d.folder),t=new Map(e.packages.map((d)=>[d.folder,d])),r=new Map(e.packages.map((d)=>[d.name,d])),s=new Map(e.packages.map((d)=>[d.name,d.folder])),{changed:o}=Re(n,e.filesByFolder,e.include,e.exclude,(d)=>e.devOnly.has(d),e.packagesDir),a=Ae(n,o,(d)=>Cn(t.get(d),s));for(let d of a){let m=t.get(d);if(!m||m.private)continue;for(let p of Object.keys(m.dependencies??{}))if(r.get(p)?.private)throw new c(i("publicDependsOnPrivate",{name:m.name,dep:p}))}let g=new Set(o);return{changed:o,dependents:a.filter((d)=>!g.has(d))}}function Cn(e,n){if(!e)return[];return[...Object.keys(e.dependencies??{}),...Object.keys(e.devDependencies??{})].flatMap((r)=>{let s=n.get(r);return s?[s]:[]})}function H(e,n){let t=ee.resolve(e,n);if(!I.existsSync(t))throw new c(i("configUnreadable",{file:n}));return U(I.readFileSync(t,"utf8"))}function O(e,n){let t=ee.join(e,n);if(!I.existsSync(t))throw new c(i("packagesDirMissing",{dir:n}));return I.readdirSync(t).filter((r)=>!r.startsWith(".")&&I.existsSync(ee.join(t,r,"package.json")))}function y(e,n,t){let r=JSON.parse(I.readFileSync(ee.join(e,n,t,"package.json"),"utf8"));if(!r.name||!r.version)throw new c(i("packageJsonIncomplete",{folder:t}));return r}function ne(e,n){let t=[];for(let r of["dependencies","devDependencies"])for(let s of Object.keys(e[r]??{})){let o=n.get(s);if(o)t.push(o)}return t}async function L(e){let n=await f("git",["status","--porcelain"],e);if(n.code!==0)throw new c(i("gitFailed",{detail:n.stderr.trim()}));if(n.stdout.trim())throw new c(i("dirtyTree"))}async function pe(e,n){let t=await f("git",["status","--porcelain"],e);if(t.code!==0)throw new c(i("gitFailed",{detail:t.stderr.trim()}));if(t.stdout.trim())throw new c(n)}async function ue(e){return(await w("git",["log","--format=%H%x1f%s"],e)).split(`
|
|
44
|
+
`).filter(Boolean).map((t)=>{let[r,s]=t.split("\x1F");return{hash:r,subject:s??""}})}async function G(e){let n=await w("git",["log","-F",`--grep=${K}`,"--format=%H%x1f%s%x1f%b%x1e"],e),t=[];for(let r of n.split("\x1E")){let s=r.replace(/^\n/,"").trim();if(!s)continue;let[o,a,g]=s.split("\x1F");if(!o)continue;t.push({hash:o,subject:a??"",body:g??""})}return t}async function fe(e,n){if(n){let o=await f("git",["rev-parse","--verify",`${n}^{commit}`],e);if(o.code!==0)throw new c(i("badBaseline",{rev:n}));return o.stdout.trim()}if((await f("git",["rev-parse","--verify","HEAD"],e)).code!==0)throw new c(i("noBaseline"));let r=await G(e);if(r[0])return r[0].hash;return(await ue(e)).find((o)=>Te(o.subject))?.hash??Sn()}async function te(e,n,t){let r=await fe(e,t),s=O(e,n.packagesDir),o=await w("git",["diff","--name-only",r,"HEAD"],e),a=Fe(o,n.packagesDir,s),g=new Set;for(let[p,u]of a){let k=`${n.packagesDir}/${p}/package.json`;if(u.includes(k)&&await he(e,r,"HEAD",k))g.add(p)}let{changed:d,dependents:m}=Le({packages:s.map((p)=>({...y(e,n.packagesDir,p),folder:p})),filesByFolder:a,devOnly:g,include:n.include,exclude:n.exclude,packagesDir:n.packagesDir});return{baseline:r,changed:d,dependents:m}}async function he(e,n,t,r){let s=await Ve(e,`${n}:${r}`),o=await Ve(e,`${t}:${r}`);if(s===null||o===null)return!1;try{return je(JSON.parse(s),JSON.parse(o))}catch{return!1}}async function Ve(e,n){let t=await f("git",["show",n],e);return t.code===0?t.stdout:null}function Sn(){throw new c(i("noBaseline"))}async function Ge(e){let n=$n.resolve(e.root),t=H(n,e.versionsFile);if(e.packages)t.packagesDir=e.packages;await L(n);let{baseline:r,changed:s,dependents:o}=await te(n,t,e.baseline);if(!s.length&&!o.length){let a=(await w("git",["rev-parse","--short",r],n)).trim();console.log(v(i("noPackagesSince",{rev:a})));return}console.log(D(i("changedHeader")));for(let a of s)console.log(` ${F(y(n,t.packagesDir,a).name)}`);if(o.length){console.log(D(i("dependentsHeader")));for(let a of o)console.log(` ${R(y(n,t.packagesDir,a).name)}`)}}import C from"node:fs";import B from"node:path";x();P();import Dn from"node:readline/promises";import{stdin as qe,stdout as We}from"node:process";x();P();function be(e){let n=Dn.createInterface({input:qe,output:We});return n.question(e).finally(()=>n.close())}function q(){return Boolean(qe.isTTY&&We.isTTY)}async function _e(e,n){if(!q())throw new c(i("bumpRequired"));console.log(D(e)),n.forEach((s,o)=>{console.log(` ${F(String(o+1))}) ${s}`)});let t=(await be(i("chooseIndex"))).trim(),r=Number(t)-1;if(!Number.isInteger(r)||r<0||r>=n.length)throw new c(i("invalidChoice",{answer:t||i("emptyAnswer")}));return n[r]}async function j(e,n=""){if(!q())throw new c(i("yesRequired"));let t=n?` [${n}]`:"";return(await be(`${e}${t} `)).trim()||n}async function re(e){if(!q())throw new c(i("yesRequired"));console.log(D(e));let n=(await be("[y/N] ")).trim().toLowerCase();return n==="y"||n==="yes"}function zn(e){let n=new Set,t=[];for(let r of[...jn(e),...Bn(e)]){if(n.has(r))continue;n.add(r),t.push(r)}return t}function Nn(e,n=ae()){let t=(o,a="")=>i(o,void 0,n).split(`
|
|
43
45
|
`).map((g)=>`${a}# ${g}`).join(`
|
|
44
46
|
`),r=(o,a,g,d)=>[t(d," "),a?` ${o}: ${W(a)}`:` # ${o}: ${g}`].join(`
|
|
45
47
|
`),s=[t("initNotePackagesDir"),`packagesDir: ${W(e.packagesDir)}`,"",t("initNoteCommitMessage"),'commitMessage: "bump: %s"',"",t("initNoteBranch"),e.branch?`branch: ${W(e.branch)}`:"# branch: main","","hooks:",r("beforeCommit",e.beforeCommit,"bun install","initNoteBeforeCommit"),r("beforePublish",e.beforePublish,"bun run build","initNoteBeforePublish"),r("afterPublish",void 0,"echo published","initNoteAfterPublish"),"",t("initNoteInclude"),"include:",...e.include.map((o)=>` - ${W(o)}`),` # - ${e.packagesDir}/*/bin`,"",t("initNoteExclude")];if(e.exclude.length)s.push("exclude:",...e.exclude.map((o)=>` - ${W(o)}`));else s.push("# exclude:",`# - ${e.packagesDir}/*/src/**/__tests__/**`);return`${s.join(`
|
|
46
48
|
`)}
|
|
47
|
-
`}async function
|
|
48
|
-
`);await w("git",["add","--all"],n),await w("git",["commit","-m",m,"-m",p,"-m",
|
|
49
|
-
${
|
|
49
|
+
`}async function Ue(e){let n=B.resolve(e.root),t=B.resolve(n,e.versionsFile);if(C.existsSync(t))throw new c(i("configExists",{file:e.versionsFile}));let r=zn(n),s=r[0]??"packages",o=e.yes?Fn(s):await Rn(e.versionsFile,r,s);if(!o.include.length)throw new c(i("includeRequired"));let a=Nn(o);U(a),C.mkdirSync(B.dirname(t),{recursive:!0}),C.writeFileSync(t,a),console.log(R(i("initWrote",{file:e.versionsFile})))}function Fn(e){return{packagesDir:e,include:[`${e}/*/src`],exclude:[`${e}/*/src/**/__tests__/**`]}}async function Rn(e,n,t){if(!q())throw new c(i("yesRequired"));if(console.log(D(i("initIntro",{file:e}))),n.length)console.log(v(i("initFoundDirs",{dirs:n.join(", ")})));let r=await j(i("initPackagesDir"),t),s=Je(await j(i("initInclude"),`${r}/*/src`)),o=Je(await j(i("initExclude"),`${r}/*/src/**/__tests__/**`)),a=await j(i("initBranch")),g=await j(i("initBeforeCommit")),d=await j(i("initBeforePublish"));return{packagesDir:r,branch:a||void 0,beforeCommit:g||void 0,beforePublish:d||void 0,include:s,exclude:o}}function Je(e){return e.split(",").map((n)=>n.trim()).filter(Boolean)}function W(e){return/^[A-Za-z0-9_./@*+-]+$/.test(e)?e:JSON.stringify(e)}function jn(e){return En(e).flatMap((n)=>{let t=n.replace(/\/\*\*?$/,"");if(!t||t===n||t.includes("*"))return[];return C.existsSync(B.join(e,t))?[t]:[]})}function Bn(e){if(!C.existsSync(e))return[];let n=[];for(let t of C.readdirSync(e)){if(t.startsWith(".")||t==="node_modules")continue;let r=B.join(e,t);if(!C.statSync(r).isDirectory())continue;if(An(r))n.push(t)}return n}function An(e){return C.readdirSync(e).some((n)=>C.existsSync(B.join(e,n,"package.json")))}function En(e){let n=B.join(e,"package.json");if(!C.existsSync(n))return[];try{let t=JSON.parse(C.readFileSync(n,"utf8")),r=Array.isArray(t.workspaces)?t.workspaces:t.workspaces?.packages;return Array.isArray(r)?r.filter((s)=>typeof s==="string"):[]}catch{return[]}}import Ye from"node:path";x();P();P();function Ke(e){let n=[];if(e.beforePublish)n.push({kind:"hook",name:"beforePublish",command:e.beforePublish});for(let t of Ie(e.packages.filter((r)=>!r.private))){let r=t.registry??"";n.push(t.published?{kind:"dist-tag",name:t.name,version:t.version,folder:t.folder,registry:r,tag:e.distTag}:{kind:"publish",name:t.name,version:t.version,folder:t.folder,registry:r,tag:e.distTag})}if(e.afterPublish)n.push({kind:"hook",name:"afterPublish",command:e.afterPublish});if(e.formal)for(let t of e.packages)n.push({kind:"tag",name:t.name,version:t.version,commit:e.commit});return n}async function tn(e){let n=Ye.resolve(e.root);await L(n);let t=(await w("git",["rev-parse","HEAD"],n)).trim(),r=H(n,e.versionsFile);if(e.packages)r.packagesDir=e.packages;let s=await Mn(n);if(!s?.lines.length)throw new c(i("noVersionCommit"));let o=O(n,r.packagesDir),a=new Map(o.map((l)=>[y(n,r.packagesDir,l).name,l])),g=s.lines.map((l)=>{let b=a.get(l.name);if(!b)throw new c(i("packageNotInDir",{dir:r.packagesDir,name:l.name}));let T=y(n,r.packagesDir,b);if(T.version!==l.to)throw new c(i("releaseVersionMismatch",{name:l.name,expected:l.to,actual:T.version}));return{...l,folder:b,pkg:T,deps:ne(T,a)}}),d=await f("git",["diff","--quiet",s.hash,"HEAD","--",...g.map((l)=>`${r.packagesDir}/${l.folder}`)],n);if(d.code===1)throw new c(i("releaseContentsChanged"));if(d.code!==0)throw new c(i("gitFailed",{detail:d.stderr.trim()}));let m=Y(s.lines);if(m)await rn(n,g,s.hash);let p=new Map;for(let l of g){if(l.pkg.private)continue;p.set(l.folder,await Ln(n,l.pkg))}let u=new Set;for(let l of g){let b=p.get(l.folder);if(!b||u.has(b))continue;u.add(b),await On(n,b)}let k=new Set;for(let l of g){if(l.pkg.private)continue;let b=p.get(l.folder);if(!b)continue;await Qe(async()=>{if(await Hn(n,l.name,l.to,b))k.add(l.folder)})}let h=Ke({packages:g.map((l)=>({name:l.name,version:l.to,folder:l.folder,private:l.pkg.private,deps:l.deps,registry:p.get(l.folder),published:k.has(l.folder)})),distTag:e.distTag,formal:m,commit:s.hash,beforePublish:r.hooks.beforePublish,afterPublish:r.hooks.afterPublish});if(e.dryRun){for(let l of h)console.log(Tn(l));if(!m)console.log(v(i("noGitTag")));return}console.log(D(i("willPublish")));for(let l of g){let b=l.pkg.private?` ${v(i("privateMark"))}`:"";console.log(` ${F(l.name)} ${R(l.to)}${b}`)}if(!e.yes&&!await re(i("confirmPublish")))throw new c(i("cancelledPublish"));let z=()=>{console.error(M(i("publishInterrupted"))),process.exit(1)};process.on("SIGINT",z),process.on("SIGTERM",z);try{await nn(n,r.hooks.beforePublish,"beforePublish"),await pe(n,i("beforePublishDirty")),await Ze(n,t);for(let l of h){if(l.kind!=="publish"&&l.kind!=="dist-tag")continue;let b=Ye.join(n,r.packagesDir,l.folder);await Qe(async()=>{if(l.kind==="dist-tag")await Xe(n,["dist-tag","add",`${l.name}@${l.version}`,l.tag,`--registry=${l.registry}`],l.registry);else await Xe(b,["publish",`--tag=${l.tag}`,`--registry=${l.registry}`],l.registry)})}if(await nn(n,r.hooks.afterPublish,"afterPublish"),await pe(n,i("afterPublishDirty")),await Ze(n,t),m)await In(n,r.branch,g,s.hash)}finally{process.off("SIGINT",z),process.off("SIGTERM",z)}}function Tn(e){if(e.kind==="hook")return`${v(`${e.name}:`)} ${V(e.command)}`;if(e.kind==="tag")return V(`git tag ${e.name}@${e.version} ${e.commit}`);if(e.kind==="dist-tag")return V(`npm dist-tag add ${e.name}@${e.version} ${e.tag} --registry=${e.registry}`);return V(`npm publish --tag=${e.tag} --registry=${e.registry} ${e.name}@${e.version}`)}async function Mn(e){if((await f("git",["rev-parse","--verify","HEAD"],e)).code!==0)return null;let t=(await G(e))[0];if(!t)return null;let r=Z(t.body);if(!r.length)return null;return{hash:t.hash,subject:t.subject,lines:r}}async function In(e,n,t,r){await rn(e,t,r);let s=t.map((a)=>`${a.name}@${a.to}`);for(let a of s){if((await f("git",["rev-parse","--verify",`refs/tags/${a}^{commit}`],e)).code===0)continue;await w("git",["tag",a,r],e)}if(!n)return;let o=await f("git",["push","origin",...s.map((a)=>`refs/tags/${a}`)],e);if(o.code!==0)throw new c(i("tagPushFailed",{detail:o.stderr.trim()}))}async function rn(e,n,t){for(let r of n){let s=`${r.name}@${r.to}`,o=await f("git",["rev-parse","--verify",`refs/tags/${s}^{commit}`],e);if(o.code===0&&o.stdout.trim()!==t)throw new c(i("tagPointsElsewhere",{tag:s}))}}async function Ze(e,n){if((await w("git",["rev-parse","HEAD"],e)).trim()!==n)throw new c(i("publishHeadChanged"))}async function Qe(e){let n="";for(let t=0;t<3;t++)try{await e();return}catch(r){if(r instanceof c&&r.auth)throw r;n=r instanceof Error?r.message:String(r)}throw new c(i("networkFailed",{detail:n}))}async function Xe(e,n,t){let r=await f("npm",n,e);if(r.code===0)return;let s=`${r.stderr}${r.stdout}`;if(process.stderr.write(r.stderr),Q(s))throw new c(i("notLoggedIn",{registry:t}),!0);throw Error(s.trim()||i("npmFailed"))}async function Hn(e,n,t,r){let s=await f("npm",["view",`${n}@${t}`,"version","--json",`--registry=${r}`],e);if(s.code===0){let a;try{a=JSON.parse(s.stdout)}catch{}if(a===t)return!0;throw Error(i("unexpectedRegistryVersion",{name:n,version:t}))}let o=`${s.stderr}${s.stdout}`;if(Q(o))throw new c(i("notLoggedIn",{registry:r}),!0);if(le(s.stdout)||le(s.stderr))return!1;throw Error(o.trim()||i("npmViewFailed"))}async function On(e,n){let t=await f("npm",["whoami",`--registry=${n}`],e);if(t.code===0)return;let r=`${t.stderr}${t.stdout}`;if(Q(r))throw new c(i("notLoggedIn",{registry:n}),!0);throw new c(i("registryUnreachable",{registry:n,detail:r.trim()}))}async function Ln(e,n){if(n.publishConfig?.registry)return n.publishConfig.registry.replace(/\/$/,"");if(n.name.startsWith("@")&&n.name.includes("/")){let r=n.name.slice(0,n.name.indexOf("/")),s=await en(e,`${r}:registry`);if(s&&s!=="undefined"&&s!=="null")return s.replace(/\/$/,"")}let t=await en(e,"registry");if(!t||t==="undefined"||t==="null")throw new c(i("noNpmRegistry",{detail:"npm config get registry: empty value"}));return t.replace(/\/$/,"")}async function en(e,n){let t=await f("npm",["config","get",n],e);if(t.code!==0){let r=t.stderr.trim()||t.stdout.trim()||`npm config get ${n}: exit ${t.code}`;throw new c(i("noNpmRegistry",{detail:r}))}return t.stdout.trim()}async function nn(e,n,t){if(!n)return;try{await X("sh",["-c",n],e)}catch(r){let s=r instanceof Error?r.message:String(r);throw new c(i("hookFailed",{name:t,detail:s}))}}import A from"node:fs";import ie from"node:path";x();P();var _n=["patch","minor","major"],Jn=["prerelease","prepatch","preminor","premajor"];async function ln(e){let n=ie.resolve(e.root),t=H(n,e.versionsFile);if(e.packages)t.packagesDir=e.packages;if(e.messageFromCli&&e.commitMessage)t.commitMessage=e.commitMessage;if(e.branchFromCli)t.branch=e.branch||void 0;if(await L(n),t.branch){let m=await f("git",["symbolic-ref","--quiet","--short","HEAD"],n);if(m.code!==0||m.stdout.trim()!==t.branch)throw new c(i("wrongBranch",{branch:t.branch}))}let r=await te(n,t,e.baseline);if(!r.changed.length&&!r.dependents.length){let m=(await w("git",["rev-parse","--short",r.baseline],n)).trim();console.log(v(i("noPackagesSince",{rev:m})));return}let s=await Un(e.bump,e.preid),o=ge(s)?void 0:e.preid,a=[...r.changed,...r.dependents].map((m)=>{let p=y(n,t.packagesDir,m);return{folder:m,name:p.name,from:p.version,to:Be(p.version,s,o)}});for(let m of a)console.log(ve(m.name,m.from,m.to));if(e.dryRun)return;if(!e.yes&&!await re(i("confirmVersions")))throw new c(i("cancelledVersion"));let g=Kn(n,(await w("git",["rev-parse","HEAD"],n)).trim());try{for(let u of a)Xn(n,t.packagesDir,u.folder,u.to);if(et(n,t.packagesDir),ge(s))await Yn(n,t,a,e.baseline);if(t.hooks.beforeCommit)await X("sh",["-c",t.hooks.beforeCommit],n);let m=Ee(t.commitMessage,s,o),p=a.map((u)=>`${u.name} ${u.from} => ${u.to}`).join(`
|
|
50
|
+
`);await w("git",["add","--all"],n),await w("git",["commit","-m",m,"-m",p,"-m",K],n),g.disarm()}catch(m){await g.fail(m)}if(!t.branch)return;let d=await f("git",["push","origin",t.branch],n);if(d.code!==0)throw new c(i("branchPushFailed",{branch:t.branch,detail:d.stderr.trim()}))}async function Un(e,n){let t=e??await _e(i("chooseBump"),n?Jn:_n);return ze(t,n)}function Kn(e,n){let t=!0,r=()=>{if(!t)return;t=!1,me(e,n),console.error(M(i("versionRestored"))),process.exit(1)};return process.on("SIGINT",r),process.on("SIGTERM",r),{disarm(){t=!1,process.off("SIGINT",r),process.off("SIGTERM",r)},fail(s){if(t)t=!1,process.off("SIGINT",r),process.off("SIGTERM",r),me(e,n);throw s}}}async function Yn(e,n,t,r){await Promise.resolve().then(() => dn());let g=await G(e),d=(await ue(e)).find((h)=>Me(h.subject))?.hash,m=an(g)??d??(r?await fe(e,r):void 0),p=await Zn(e,m),u=new Set(t.map((h)=>h.folder)),k=new Map(O(e,n.packagesDir).map((h)=>[y(e,n.packagesDir,h).name,h]));for(let h of t){let z=`${n.packagesDir}/${h.folder}/package.json`,l=new Set;for(let S of p)if(S.files.includes(z)&&await Qn(e,S.hash,z))l.add(S.hash);let b=cn(p,h.folder,n.packagesDir,n.include,n.exclude,l),T=y(e,n.packagesDir,h.folder),mn=b.length?[]:ne(T,k).filter((S)=>u.has(S)).map((S)=>y(e,n.packagesDir,S)).map((S)=>({name:S.name,version:S.version})),ye=await gn({messages:b,version:h.to,previousTag:`${h.name}@${h.from}`,currentTag:`${h.name}@${h.to}`,dependencies:mn}),se=ie.join(e,n.packagesDir,h.folder,"CHANGELOG.md"),ke=A.existsSync(se)?A.readFileSync(se,"utf8"):"";A.writeFileSync(se,ke?`${ye}
|
|
51
|
+
${ke}`:ye)}}async function Zn(e,n){let t=n?["rev-list","--reverse",`${n}..HEAD`]:["rev-list","--reverse","HEAD"],r=(await w("git",t,e)).split(`
|
|
50
52
|
`).filter(Boolean),s=[];for(let o of r){let a=await w("git",["log","-1","--format=%B",o],e),g=await f("git",["diff-tree","--no-commit-id","--name-only","-r","--root",o],e);s.push({hash:o,body:a,files:g.code===0?g.stdout.split(`
|
|
51
|
-
`).filter(Boolean):[]})}return s}async function
|
|
52
|
-
`)}function
|
|
53
|
-
`)}}}x();P();var
|
|
53
|
+
`).filter(Boolean):[]})}return s}async function Qn(e,n,t){return!await he(e,`${n}^`,n,t)}function Xn(e,n,t,r){let s=ie.join(e,n,t,"package.json"),o=A.readFileSync(s,"utf8"),a=JSON.parse(o);if(typeof a.version!=="string")throw new c(i("missingVersionField",{folder:t}));a.version=r;let g=/\n([\t ]+)"/.exec(o)?.[1]??" ";A.writeFileSync(s,JSON.stringify(a,null,g)+`
|
|
54
|
+
`)}function et(e,n){let t=O(e,n),r=new Map(t.map((s)=>[y(e,n,s).name,y(e,n,s)]));for(let s of t){let o=ie.join(e,n,s,"package.json"),a=A.readFileSync(o,"utf8"),g=JSON.parse(a),d=!1;for(let m of["dependencies","devDependencies"])for(let p of Object.keys(g[m]??{})){let u=r.get(p);if(!u)continue;let k=`^${u.version}`;if(g[m][p]!==k)g[m][p]=k,d=!0}if(d){let m=/\n([\t ]+)"/.exec(a)?.[1]??" ";A.writeFileSync(o,JSON.stringify(g,null,m)+`
|
|
55
|
+
`)}}}x();P();var E=new nt;E.name("change-versions").version(JSON.parse(tt(new URL("../package.json",import.meta.url),"utf8")).version).description(i("cliDescription"));function we(e){return e.option("--root <dir>",i("optRoot"),process.cwd()).option("--versions-file <file>",i("optVersionsFile"),"change-versions.yml").option("--packages <dir>",i("optPackages"))}E.command("init").description(i("cmdInit")).option("--root <dir>",i("optRoot"),process.cwd()).option("--versions-file <file>",i("optVersionsFile"),"change-versions.yml").option("--yes",i("optYesInit")).action(async function(){let e=this.opts();await Ue(e)});we(E.command("changed").description(i("cmdChanged"))).option("--baseline <rev>",i("optBaseline")).action(async function(){let e=this.opts();await Ge(e)});we(E.command("version").description(i("cmdVersion")).argument("[bump]",i("argBump"))).option("--preid <id>",i("optPreid")).option("--yes",i("optYes")).option("--dry-run",i("optDryRunVersion")).option("--baseline <rev>",i("optBaseline")).option("--branch <name>",i("optBranch")).option("--commit-message <template>",i("optCommitMessage")).action(async function(e){let n=this.opts();await ln({...n,bump:e,branchFromCli:this.getOptionValueSource("branch")==="cli",messageFromCli:this.getOptionValueSource("commitMessage")==="cli"})});we(E.command("publish").description(i("cmdPublish"))).option("--dist-tag <tag>",i("optDistTag"),"latest").option("--yes",i("optYes")).option("--dry-run",i("optDryRunPublish")).action(async function(){let e=this.opts();await tn(e)});if(process.argv.length<=2)E.help();E.parseAsync(process.argv).catch((e)=>{if(e instanceof c)console.error(M(e.message));else console.error(e);process.exit(1)});
|