@longzai-intelligence-dependencies/cli 0.0.10 → 0.0.11
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/index.js +8 -8
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -159,7 +159,7 @@ Expecting one of '${n.join(`', '`)}'`);return this._lifeCycleHooks[e]?this._life
|
|
|
159
159
|
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
160
160
|
- ${t?`searched for local subcommand relative to directory '${t}'`:`no directory for search for local subcommand, use .executableDir() to supply a custom directory`}`;throw Error(r)}_executeSubCommand(e,t){t=t.slice();let a=!1,s=[`.js`,`.ts`,`.tsx`,`.mjs`,`.cjs`];function c(e,t){let n=r.resolve(e,t);if(i.existsSync(n))return n;if(s.includes(r.extname(t)))return;let a=s.find(e=>i.existsSync(`${n}${e}`));if(a)return`${n}${a}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let u=e._executableFile||`${this._name}-${e._name}`,d=this._executableDir||``;if(this._scriptPath){let e;try{e=i.realpathSync(this._scriptPath)}catch{e=this._scriptPath}d=r.resolve(r.dirname(e),d)}if(d){let t=c(d,u);if(!t&&!e._executableFile&&this._scriptPath){let n=r.basename(this._scriptPath,r.extname(this._scriptPath));n!==this._name&&(t=c(d,`${n}-${e._name}`))}u=t||u}a=s.includes(r.extname(u));let f;o.platform===`win32`?(this._checkForMissingExecutable(u,d,e._name),t.unshift(u),t=g(o.execArgv).concat(t),f=n.spawn(o.execPath,t,{stdio:`inherit`})):a?(t.unshift(u),t=g(o.execArgv).concat(t),f=n.spawn(o.argv[0],t,{stdio:`inherit`})):f=n.spawn(u,t,{stdio:`inherit`}),f.killed||[`SIGUSR1`,`SIGUSR2`,`SIGTERM`,`SIGINT`,`SIGHUP`].forEach(e=>{o.on(e,()=>{f.killed===!1&&f.exitCode===null&&f.kill(e)})});let p=this._exitCallback;f.on(`close`,e=>{e??=1,p?p(new l(e,`commander.executeSubCommandAsync`,`(close)`)):o.exit(e)}),f.on(`error`,t=>{if(t.code===`ENOENT`)this._checkForMissingExecutable(u,d,e._name);else if(t.code===`EACCES`)throw Error(`'${u}' not executable`);if(!p)o.exit(1);else{let e=new l(1,`commander.executeSubCommandAsync`,`(error)`);e.nestedError=t,p(e)}}),this.runningCommand=f}_dispatchSubcommand(e,t,n){let r=this._findCommand(e);r||this.help({error:!0}),r._prepareForParse();let i;return i=this._chainOrCallSubCommandHook(i,r,`preSubcommand`),i=this._chainOrCall(i,()=>{if(r._executableHandler)this._executeSubCommand(r,t.concat(n));else return r._parseCommand(t,n)}),i}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??`--help`])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(e,t,n)=>{let r=t;if(t!==null&&e.parseArg){let i=`error: command-argument value '${t}' is invalid for argument '${e.name()}'.`;r=this._callParseArg(e,t,n,i)}return r};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,r)=>{let i=n.defaultValue;n.variadic?r<this.args.length?(i=this.args.slice(r),n.parseArg&&(i=i.reduce((t,r)=>e(n,r,t),n.defaultValue))):i===void 0&&(i=[]):r<this.args.length&&(i=this.args[r],n.parseArg&&(i=e(n,i,n.defaultValue))),t[r]=i}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then==`function`?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,r=[];return this._getCommandAndAncestors().reverse().filter(e=>e._lifeCycleHooks[t]!==void 0).forEach(e=>{e._lifeCycleHooks[t].forEach(t=>{r.push({hookedCommand:e,callback:t})})}),t===`postAction`&&r.reverse(),r.forEach(e=>{n=this._chainOrCall(n,()=>e.callback(e.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let r=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(e=>{r=this._chainOrCall(r,()=>e(this,t))}),r}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},i=`command:${this.name()}`;if(this._actionHandler){r(),this._processArguments();let n;return n=this._chainOrCallHooks(n,`preAction`),n=this._chainOrCall(n,()=>this._actionHandler(this.processedArgs)),this.parent&&(n=this._chainOrCall(n,()=>{this.parent.emit(i,e,t)})),n=this._chainOrCallHooks(n,`postAction`),n}if(this.parent?.listenerCount(i))r(),this._processArguments(),this.parent.emit(i,e,t);else if(e.length){if(this._findCommand(`*`))return this._dispatchSubcommand(`*`,e,t);this.listenerCount(`command:*`)?this.emit(`command:*`,e,t):this.commands.length?this.unknownCommand():(r(),this._processArguments())}else this.commands.length?(r(),this.help({error:!0})):(r(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(e=>{let t=e.attributeName();return this.getOptionValue(t)!==void 0&&this.getOptionValueSource(t)!=="default"});e.filter(e=>e.conflictsWith.length>0).forEach(t=>{let n=e.find(e=>t.conflictsWith.includes(e.attributeName()));n&&this._conflictingOption(t,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],r=t;function i(e){return e.length>1&&e[0]===`-`}let a=e=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(e)?!this._getCommandAndAncestors().some(e=>e.options.map(e=>e.short).some(e=>/^-\d$/.test(e))):!1,o=null,s=null,c=0;for(;c<e.length||s;){let l=s??e[c++];if(s=null,l===`--`){r===n&&r.push(l),r.push(...e.slice(c));break}if(o&&(!i(l)||a(l)))this.emit(`option:${o.name()}`,l);else{if(o=null,i(l)){let t=this._findOption(l);if(t){if(t.required){let n=e[c++];n===void 0&&this.optionMissingArgument(t),this.emit(`option:${t.name()}`,n)}else if(t.optional){let n=null;c<e.length&&(!i(e[c])||a(e[c]))&&(n=e[c++]),this.emit(`option:${t.name()}`,n)}else this.emit(`option:${t.name()}`);o=t.variadic?t:null;continue}}if(l.length>2&&l[0]===`-`&&l[1]!==`-`){let e=this._findOption(`-${l[1]}`);if(e){e.required||e.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${e.name()}`,l.slice(2)):(this.emit(`option:${e.name()}`),s=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){let e=l.indexOf(`=`),t=this._findOption(l.slice(0,e));if(t&&(t.required||t.optional)){this.emit(`option:${t.name()}`,l.slice(e+1));continue}}if(r===t&&i(l)&&!(this.commands.length===0&&a(l))&&(r=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(l)){t.push(l),n.push(...e.slice(c));break}if(this._getHelpCommand()&&l===this._getHelpCommand().name()){t.push(l,...e.slice(c));break}if(this._defaultCommandName){n.push(l,...e.slice(c));break}}if(this._passThroughOptions){r.push(l,...e.slice(c));break}r.push(l)}}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let t=this.options[n].attributeName();e[t]=t===this._versionOptionName?this._version:this[t]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}\n`,this._outputConfiguration.writeErr),typeof this._showHelpAfterError==`string`?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
|
|
161
161
|
`),this.outputHelp({error:!0}));let n=t||{},r=n.exitCode||1,i=n.code||`commander.error`;this._exit(r,i,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in o.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||[`default`,`config`,`env`].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,o.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new p(this.options),t=e=>this.getOptionValue(e)!==void 0&&![`default`,`implied`].includes(this.getOptionValueSource(e));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(e=>{Object.keys(e.implied).filter(e=>!t(e)).forEach(t=>{this.setOptionValueWithSource(t,e.implied[t],`implied`)})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:`commander.missingArgument`})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:`commander.optionMissingArgument`})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:`commander.missingMandatoryOptionValue`})}_conflictingOption(e,t){let n=e=>{let t=e.attributeName(),n=this.getOptionValue(t),r=this.options.find(e=>e.negate&&t===e.attributeName()),i=this.options.find(e=>!e.negate&&t===e.attributeName());return r&&(r.presetArg===void 0&&n===!1||r.presetArg!==void 0&&n===r.presetArg)?r:i||e},r=e=>{let t=n(e),r=t.attributeName();return this.getOptionValueSource(r)===`env`?`environment variable '${t.envVar}'`:`option '${t.flags}'`},i=`error: ${r(e)} cannot be used with ${r(t)}`;this.error(i,{code:`commander.conflictingOption`})}unknownOption(e){if(this._allowUnknownOption)return;let t=``;if(e.startsWith(`--`)&&this._showSuggestionAfterError){let n=[],r=this;do{let e=r.createHelp().visibleOptions(r).filter(e=>e.long).map(e=>e.long);n=n.concat(e),r=r.parent}while(r&&!r._enablePositionalOptions);t=m(e,n)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:`commander.unknownOption`})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?``:`s`,r=`error: too many arguments${this.parent?` for '${this.name()}'`:``}. Expected ${t} argument${n} but got ${e.length}.`;this.error(r,{code:`commander.excessArguments`})}unknownCommand(){let e=this.args[0],t=``;if(this._showSuggestionAfterError){let n=[];this.createHelp().visibleCommands(this).forEach(e=>{n.push(e.name()),e.alias()&&n.push(e.alias())}),t=m(e,n)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:`commander.unknownCommand`})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t||=`-V, --version`,n||=`output the version number`;let r=this.createOption(t,n);return this._versionOptionName=r.attributeName(),this._registerOption(r),this.on(`option:`+r.name(),()=>{this._outputConfiguration.writeOut(`${e}\n`),this._exit(0,`commander.version`,e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw Error(`Command alias can't be the same as its name`);let n=this.parent?._findCommand(e);if(n){let t=[n.name()].concat(n.aliases()).join(`|`);throw Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${t}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(e=>this.alias(e)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let e=this.registeredArguments.map(e=>c(e));return[].concat(this.options.length||this._helpOption!==null?`[options]`:[],this.commands.length?`[command]`:[],this.registeredArguments.length?e:[]).join(` `)}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??``:(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??``:(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??``:(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=r.basename(e,r.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let r=t.formatHelp(this,t);return n.hasColors?r:this._outputConfiguration.stripColor(r)}_getOutputContext(e){e||={};let t=!!e.error,n,r,i;return t?(n=e=>this._outputConfiguration.writeErr(e),r=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth()):(n=e=>this._outputConfiguration.writeOut(e),r=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth()),{error:t,write:e=>(r||(e=this._outputConfiguration.stripColor(e)),n(e)),hasColors:r,helpWidth:i}}outputHelp(e){let t;typeof e==`function`&&(t=e,e=void 0);let n=this._getOutputContext(e),r={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(e=>e.emit(`beforeAllHelp`,r)),this.emit(`beforeHelp`,r);let i=this.helpInformation({error:n.error});if(t&&(i=t(i),typeof i!=`string`&&!Buffer.isBuffer(i)))throw Error(`outputHelp callback must return a string or a Buffer`);n.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit(`afterHelp`,r),this._getCommandAndAncestors().forEach(e=>e.emit(`afterAllHelp`,r))}helpOption(e,t){return typeof e==`boolean`?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??`-h, --help`,t??`display help for command`),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(o.exitCode??0);t===0&&e&&typeof e!=`function`&&e.error&&(t=1),this._exit(t,`commander.help`,`(outputHelp)`)}addHelpText(e,t){let n=[`beforeAll`,`before`,`after`,`afterAll`];if(!n.includes(e))throw Error(`Unexpected value for position to addHelpText.
|
|
162
|
-
Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function g(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function _(){if(o.env.NO_COLOR||o.env.FORCE_COLOR===`0`||o.env.FORCE_COLOR===`false`)return!1;if(o.env.FORCE_COLOR||o.env.CLICOLOR_FORCE!==void 0)return!0}e.Command=h,e.useColor=_}));const{program:xd,createCommand:Sd,createArgument:Cd,createOption:wd,CommanderError:Td,InvalidArgumentError:Ed,InvalidOptionArgumentError:Dd,Command:Od,Argument:kd,Option:Ad,Help:jd}=(/* @__PURE__ */ t((/* @__PURE__ */ n((e=>{let{Argument:t}=gd(),{Command:n}=bd(),{CommanderError:r,InvalidArgumentError:i}=hd(),{Help:a}=_d(),{Option:o}=vd();e.program=new n,e.createCommand=e=>new n(e),e.createOption=(e,t)=>new o(e,t),e.createArgument=(e,n)=>new t(e,n),e.Command=n,e.Option=o,e.Argument=t,e.Help=a,e.CommanderError=r,e.InvalidArgumentError=i,e.InvalidOptionArgumentError=i})))(),1)).default;let Md;function Nd(){return Md??=md(`@longzai-intelligence-cli/core/provider`),Md}const Pd={red:e=>e,green:e=>e,yellow:e=>e,blue:e=>e,cyan:e=>e,magenta:e=>e,gray:e=>e,bold:e=>e,dim:e=>e};let Fd={select:async(e,t)=>t[0]?.value??``,textInput:async(e,t)=>t?.defaultValue??``,confirm:async(e,t)=>t?.defaultValue??!1,spinner:()=>({start:e=>Nd().info(e),stop:e=>Nd().info(e)}),note:(e,t)=>{t?Nd().info(`${t}: ${e}`):Nd().info(e)},log:{info:e=>Nd().info(e),success:e=>Nd().info(e),warn:e=>Nd().warn(e),error:e=>Nd().error(e),step:e=>Nd().info(e)}},Id=Pd;function Ld(e){Fd=e}function Rd(e){Id=e}function zd(){return Fd}function Bd(){return Id}const Vd=()=>`0.0.
|
|
162
|
+
Expecting one of '${n.join(`', '`)}'`);let r=`${e}Help`;return this.on(r,e=>{let n;n=typeof t==`function`?t({error:e.error,command:e.command}):t,n&&e.write(`${n}\n`)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(e=>t.is(e))&&(this.outputHelp(),this._exit(0,`commander.helpDisplayed`,`(outputHelp)`))}};function g(e){return e.map(e=>{if(!e.startsWith(`--inspect`))return e;let t,n=`127.0.0.1`,r=`9229`,i;return(i=e.match(/^(--inspect(-brk)?)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))===null?(i=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=i[1],n=i[3],r=i[4]):(t=i[1],/^\d+$/.test(i[3])?r=i[3]:n=i[3]):t=i[1],t&&r!==`0`?`${t}=${n}:${parseInt(r)+1}`:e})}function _(){if(o.env.NO_COLOR||o.env.FORCE_COLOR===`0`||o.env.FORCE_COLOR===`false`)return!1;if(o.env.FORCE_COLOR||o.env.CLICOLOR_FORCE!==void 0)return!0}e.Command=h,e.useColor=_}));const{program:xd,createCommand:Sd,createArgument:Cd,createOption:wd,CommanderError:Td,InvalidArgumentError:Ed,InvalidOptionArgumentError:Dd,Command:Od,Argument:kd,Option:Ad,Help:jd}=(/* @__PURE__ */ t((/* @__PURE__ */ n((e=>{let{Argument:t}=gd(),{Command:n}=bd(),{CommanderError:r,InvalidArgumentError:i}=hd(),{Help:a}=_d(),{Option:o}=vd();e.program=new n,e.createCommand=e=>new n(e),e.createOption=(e,t)=>new o(e,t),e.createArgument=(e,n)=>new t(e,n),e.Command=n,e.Option=o,e.Argument=t,e.Help=a,e.CommanderError=r,e.InvalidArgumentError=i,e.InvalidOptionArgumentError=i})))(),1)).default;let Md;function Nd(){return Md??=md(`@longzai-intelligence-cli/core/provider`),Md}const Pd={red:e=>e,green:e=>e,yellow:e=>e,blue:e=>e,cyan:e=>e,magenta:e=>e,gray:e=>e,bold:e=>e,dim:e=>e};let Fd={select:async(e,t)=>t[0]?.value??``,textInput:async(e,t)=>t?.defaultValue??``,confirm:async(e,t)=>t?.defaultValue??!1,spinner:()=>({start:e=>Nd().info(e),stop:e=>Nd().info(e)}),note:(e,t)=>{t?Nd().info(`${t}: ${e}`):Nd().info(e)},log:{info:e=>Nd().info(e),success:e=>Nd().info(e),warn:e=>Nd().warn(e),error:e=>Nd().error(e),step:e=>Nd().info(e)}},Id=Pd;function Ld(e){Fd=e}function Rd(e){Id=e}function zd(){return Fd}function Bd(){return Id}const Vd=()=>`0.0.11`;function Hd(e){let t=e.version??Vd();e.interaction&&Ld(e.interaction),e.color&&Rd(e.color);let n=new Od;return n.name(e.name).version(t,`-v, --version`,`输出 ${e.name} 的版本号`),e.description&&n.description(e.description),n}let Ud;function Wd(){return Ud??=md(`@longzai-intelligence-cli/core/define-command`),Ud}function Gd(e,t){let n=e.commands.find(e=>e.name()===t);return n===void 0?e.command(t):n}function Kd(e,t){if(t.length===1){let n=t[0];if(n===void 0)throw Error(`defineCommand: segments 为空,无法解析命令名`);return e.command(n)}let[n,...r]=t;if(n===void 0)throw Error(`defineCommand: segments 首段为空,无法解析父命令名`);let i=r.pop();if(i===void 0)throw Error(`defineCommand: segments 末段为空,无法解析子命令名`);let a=Gd(e,n);for(let e of r)a=Gd(a,e);return a.command(i)}function qd(e,t){let n=Kd(e,t.name.split(` `).filter(e=>e.length>0));t.description&&n.description(t.description);for(let e of t.arguments??[])e.description?n.argument(e.signature,e.description):n.argument(e.signature);for(let e of t.options??[])e.defaultValue===void 0?n.option(e.flags,e.description??``):n.option(e.flags,e.description??``,e.defaultValue);n.action(async(...e)=>{let n=e[e.length-1];if(!(n instanceof Od))return;let r=n.opts(),i=n.args,a=t.schema.safeParse(r);if(!a.success){let e=a.error.issues.map(e=>e.message).join(`, `);Wd().error(Bd().red(`参数校验失败: ${e}`)),zd().log.error(`参数校验失败: ${e}`),process.exit(1)}await t.action(a.data,i)})}var Jd=/* @__PURE__ */ T(import.meta.url);function Yd(e){let t=b(e);return t.length>1&&t[t.length-1]===w&&(t=t.substring(0,t.length-1)),t}const Xd=/[\\/]/g;function Zd(e,t){return e.replace(Xd,t)}const Qd=/^[a-z]:[\\/]$/i;function $d(e){return e===`/`||Qd.test(e)}function ef(e,t){let{resolvePaths:n,normalizePath:r,pathSeparator:i}=t,a=process.platform===`win32`&&e.includes(`/`)||e.startsWith(`.`);return n&&(e=C(e)),(r||a)&&(e=Yd(e)),e===`.`?``:Zd(e[e.length-1]===i?e:e+i,i)}function tf(e,t){return t+e}function nf(e,t){return function(n,r){return r.startsWith(e)?r.slice(e.length)+n:Zd(S(e,r),t.pathSeparator)+t.pathSeparator+n}}function rf(e){return e}function af(e,t,n){return t+e+n}function of(e,t){let{relativePaths:n,includeBasePath:r}=t;return n&&e?nf(e,t):r?tf:rf}function sf(e){return function(t,n){n.push(t.substring(e.length)||`.`)}}function cf(e){return function(t,n,r){let i=t.substring(e.length)||`.`;r.every(e=>e(i,!0))&&n.push(i)}}const lf=(e,t)=>{t.push(e||`.`)},uf=(e,t,n)=>{let r=e||`.`;n.every(e=>e(r,!0))&&t.push(r)},df=()=>{};function ff(e,t){let{includeDirs:n,filters:r,relativePaths:i}=t;return n?i?r&&r.length?cf(e):sf(e):r&&r.length?uf:lf:df}const pf=(e,t,n,r)=>{r.every(t=>t(e,!1))&&n.files++},mf=(e,t,n,r)=>{r.every(t=>t(e,!1))&&t.push(e)},hf=(e,t,n,r)=>{n.files++},gf=(e,t)=>{t.push(e)},_f=()=>{};function vf(e){let{excludeFiles:t,filters:n,onlyCounts:r}=e;return t?_f:n&&n.length?r?pf:mf:r?hf:gf}const yf=e=>e,bf=()=>[``].slice(0,0);function xf(e){return e.group?bf:yf}const Sf=(e,t,n)=>{e.push({directory:t,files:n,dir:t})},Cf=()=>{};function wf(e){return e.group?Sf:Cf}const Tf=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue(),i.realpath(e,(o,s)=>{if(o)return r.dequeue(a?null:o,t);i.stat(s,(i,o)=>{if(i)return r.dequeue(a?null:i,t);if(o.isDirectory()&&Of(e,s,t))return r.dequeue(null,t);n(o,s),r.dequeue(null,t)})})},Ef=function(e,t,n){let{queue:r,fs:i,options:{suppressErrors:a}}=t;r.enqueue();try{let r=i.realpathSync(e),a=i.statSync(r);if(a.isDirectory()&&Of(e,r,t))return;n(a,r)}catch(e){if(!a)throw e}};function Df(e,t){return!e.resolveSymlinks||e.excludeSymlinks?null:t?Ef:Tf}function Of(e,t,n){if(n.options.useRealPaths)return kf(t,n);let r=v(e),i=1;for(;r!==n.root&&i<2;){let e=n.symlinks.get(r);e&&(e===t||e.startsWith(t)||t.startsWith(e))?i++:r=v(r)}return n.symlinks.set(e,t),i>1}function kf(e,t){return t.visited.includes(e+t.options.pathSeparator)}const Af=e=>e.counts,jf=e=>e.groups,Mf=e=>e.paths,Nf=e=>e.paths.slice(0,e.options.maxFiles),Pf=(e,t,n)=>(Rf(t,n,e.counts,e.options.suppressErrors),null),Ff=(e,t,n)=>(Rf(t,n,e.paths,e.options.suppressErrors),null),If=(e,t,n)=>(Rf(t,n,e.paths.slice(0,e.options.maxFiles),e.options.suppressErrors),null),Lf=(e,t,n)=>(Rf(t,n,e.groups,e.options.suppressErrors),null);function Rf(e,t,n,r){t(e&&!r?e:null,n)}function zf(e,t){let{onlyCounts:n,group:r,maxFiles:i}=e;return n?t?Af:Pf:r?t?jf:Lf:i?t?Nf:If:t?Mf:Ff}const Bf={withFileTypes:!0},Vf=(e,t,n,r,i)=>{if(e.queue.enqueue(),r<0)return e.queue.dequeue(null,e);let{fs:a}=e;e.visited.push(t),e.counts.directories++,a.readdir(t||`.`,Bf,(t,a=[])=>{i(a,n,r),e.queue.dequeue(e.options.suppressErrors?null:t,e)})},Hf=(e,t,n,r,i)=>{let{fs:a}=e;if(r<0)return;e.visited.push(t),e.counts.directories++;let o=[];try{o=a.readdirSync(t||`.`,Bf)}catch(t){if(!e.options.suppressErrors)throw t}i(o,n,r)};function Uf(e){return e?Hf:Vf}var Wf=class{count=0;constructor(e){this.onQueueEmpty=e}enqueue(){return this.count++,this.count}dequeue(e,t){this.onQueueEmpty&&(--this.count<=0||e)&&(this.onQueueEmpty(e,t),e&&(t.controller.abort(),this.onQueueEmpty=void 0))}},Gf=class{_files=0;_directories=0;set files(e){this._files=e}get files(){return this._files}set directories(e){this._directories=e}get directories(){return this._directories}
|
|
163
163
|
/* c8 ignore next 3 */
|
|
164
164
|
get dirs(){return this._directories}},Kf=class{aborted=!1;abort(){this.aborted=!0}},qf=class{root;isSynchronous;state;joinPath;pushDirectory;pushFile;getArray;groupFiles;resolveSymlink;walkDirectory;callbackInvoker;constructor(e,t,n){this.isSynchronous=!n,this.callbackInvoker=zf(t,this.isSynchronous),this.root=ef(e,t),this.state={root:$d(this.root)?this.root:this.root.slice(0,-1),paths:[``].slice(0,0),groups:[],counts:new Gf,options:t,queue:new Wf((e,t)=>this.callbackInvoker(t,e,n)),symlinks:/* @__PURE__ */ new Map,visited:[``].slice(0,0),controller:new Kf,fs:t.fs||u},this.joinPath=of(this.root,t),this.pushDirectory=ff(this.root,t),this.pushFile=vf(t),this.getArray=xf(t),this.groupFiles=wf(t),this.resolveSymlink=Df(t,this.isSynchronous),this.walkDirectory=Uf(this.isSynchronous)}start(){return this.pushDirectory(this.root,this.state.paths,this.state.options.filters),this.walkDirectory(this.state,this.root,this.root,this.state.options.maxDepth,this.walk),this.isSynchronous?this.callbackInvoker(this.state,null):null}walk=(e,t,n)=>{let{paths:r,options:{filters:i,resolveSymlinks:a,excludeSymlinks:o,exclude:s,maxFiles:c,signal:l,useRealPaths:u,pathSeparator:d},controller:f}=this.state;if(f.aborted||l&&l.aborted||c&&r.length>c)return;let p=this.getArray(this.state.paths);for(let c=0;c<e.length;++c){let l=e[c];if(l.isFile()||l.isSymbolicLink()&&!a&&!o){let e=this.joinPath(l.name,t);this.pushFile(e,p,this.state.counts,i)}else if(l.isDirectory()){let e=af(l.name,t,this.state.options.pathSeparator);if(s&&s(l.name,e))continue;this.pushDirectory(e,r,i),this.walkDirectory(this.state,e,e,n-1,this.walk)}else if(this.resolveSymlink&&l.isSymbolicLink()){let e=tf(l.name,t);this.resolveSymlink(e,this.state,(t,r)=>{if(t.isDirectory()){if(r=ef(r,this.state.options),s&&s(l.name,u?r:e+d))return;this.walkDirectory(this.state,r,u?r:e+d,n-1,this.walk)}else{r=u?r:e;let t=_(r),n=ef(v(r),this.state.options);r=this.joinPath(t,n),this.pushFile(r,p,this.state.counts,i)}})}}this.groupFiles(this.state.groups,t,p)}};function Jf(e,t){return new Promise((n,r)=>{Yf(e,t,(e,t)=>{if(e)return r(e);n(t)})})}function Yf(e,t,n){new qf(e,t,n).start()}function Xf(e,t){return new qf(e,t).start()}var Zf=class{constructor(e,t){this.root=e,this.options=t}withPromise(){return Jf(this.root,this.options)}withCallback(e){Yf(this.root,this.options,e)}sync(){return Xf(this.root,this.options)}};let Qf=null;
|
|
165
165
|
/* c8 ignore next 6 */
|
|
@@ -317,12 +317,12 @@ default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.l
|
|
|
317
317
|
/* istanbul ignore else should not happen */
|
|
318
318
|
n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2);if(t.type===`block-map`&&(this.type===`map-value-ind`&&t.indent===e.indent||this.type===`newline`&&!t.items[t.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type===`map-value-ind`&&t.type!==`flow-collection`){let n=l(c(t));d(e);let r=e.end.splice(1,e.end.length);r.push(this.sourceToken);let i={type:`block-map`,offset:e.offset,indent:e.indent,items:[{start:n,key:e,sep:r}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=i}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let e=this.source.indexOf(`
|
|
319
319
|
`)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
|
|
320
|
-
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=l(c(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=l(c(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),Mb=/* @__PURE__ */ n((e=>{var t=wb(),n=sb(),r=cb(),i=My(),a=Q(),o=Ab(),s=jb();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),Nb=(/* @__PURE__ */ n((e=>{var t=wb(),n=sb(),r=ab(),i=cb(),a=Cy(),o=Q(),s=Fy(),c=wy(),l=Ly(),u=zy();Ob();var d=kb(),f=Ab(),p=jb(),m=Mb(),h=_y();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync})))();function Pb(e){let t=(0,Nb.parseDocument)(e),n=!1;function r(r){e=r,t=(0,Nb.parseDocument)(e),n=!1}function i(e,r){let i=e.length===1?t.contents:t.getIn(e.slice(0,-1));i||(i=t.createNode({}),t.setIn(e.slice(0,-1),i));let a=e[e.length-1],o=i.items.find(e=>typeof e.key==`string`?e.key===a:e.key.value===a),s=i.items.map(e=>typeof e.key==`string`?e.key:String(e.key.value));if(!o){let e=0;for(;e<s.length&&!(s[e].localeCompare(a)>0);e++);o=new Nb.Pair(a,r),i.items.splice(e,0,o),n=!0}else if((0,Nb.isAlias)(o.value)){let e=Fb(t,o.value);e&&e.value!==r&&(e.value=r,n=!0)}else!o.value||typeof o.value==`string`?o.value!==r&&(o.value=r,n=!0):o.value.value!==r&&(o.value.value=r,n=!0)}function a(e,n,r){let i=t.toJSON()||{},a=e==="default"?i.catalog?.[n]:i.catalogs?.[e]?.[n];if(a===r)return{conflicts:!1,newCatalogName:e,existingSpecifier:a};if(a){let t=Ib(r);return{conflicts:!0,existingSpecifier:a,newCatalogName:e==="default"?`conflicts_${n}_${t}`:`conflicts_${e}_${t}`}}return{conflicts:!1,newCatalogName:e}}function o(e,t,n){let{newCatalogName:r}=a(e,t,n);s(r,t,n)}function s(e,n,r){let a=t.toJSON()?.catalogs?.default!==void 0;i(e==="default"&&!a?[`catalog`,n]:[`catalogs`,e,n],r)}function c(e){let n=[],r=t.toJSON()||{};if(r.catalogs)for(let t of Object.keys(r.catalogs))r.catalogs[t]?.[e]&&n.push(t);return r.catalog&&r.catalog[e]&&n.push(`default`),n}return{getDocument(){return t},setContent:r,hasChanged:()=>n,toJSON:()=>t.toJSON(),toString:n=>{let r=e.split(`'`).length>=e.split(`"`).length;return t.toString({singleQuote:r,...n})},setPath:i,setPackage:s,setPackageNoConflicts:o,getPackageCatalogs:c,hasSpecifierConflicts:a}}function Fb(e,t){let n;return(0,Nb.visit)(e,{Scalar:(e,r,i)=>{r.anchor===t.source&&typeof r.value==`string`&&(n=r)}}),n}function Ib(e){return e.replace(/\^/g,`h`).replace(/~/g,`t`).replace(/\./g,`_`).replace(/</g,`l`).replace(/>/g,`g`).replace(/=/g,`e`).replace(/\*/g,`s`).replace(/@/g,`a`).replace(/\|/g,`p`).replace(/&/g,`n`).replace(/-/g,`m`).replace(/\+/g,`u`).replace(/\s/g,`_`)}function Lb(e){return e??=[],Array.isArray(e)?e:[e]}function Rb(e){return typeof e==`object`&&!!e&&`json`in e&&typeof e.json==`function`}function zb(e){if(Rb(e))return e.json();throw TypeError(`response does not implement json()`)}const Bb=3e4,Vb=`version-upgrade@npm node/${F.version}`,Hb=Object.assign((e,t)=>{let n=new Headers(t?.headers);return n.set(`user-agent`,Vb),cv(e,{...t,headers:n})},{preconnect:()=>{}});async function Ub(e,t,n,r){let i;for(let a=0;a<=r;a++)try{return await Promise.race([e(),new Promise((e,i)=>setTimeout(()=>i(/* @__PURE__ */ Error(`Timeout requesting "${t}" (attempt ${a+1}/${r+1})`)),n))])}catch(e){if(i=e instanceof Error?e:Error(String(e)),a<r){let e=Math.min(1e3*2**a,1e4);await new Promise(t=>setTimeout(t,e))}}throw i??Error(`Unexpected state: all retries exhausted for "${t}" but no error captured`)}async function Wb(e,t=!1,n,r=Bb,i=3){let a=await Ub(()=>Qg(e,{cwd:n,force:t,fetch:Hb,metadata:!0,throw:!1}),e,r,i);if(!qb(a))throw Error(`Invalid package metadata received for "${e}"`);let o=a;if(`error`in o)throw Error(`Failed to fetch package "${e}": ${o.error}`);return Kb(o)}async function Gb(e,t=Bb,n=3){let r=await Ub(()=>Hb(new URL(`${e}/meta.json`,`https://jsr.io/`),{headers:{accept:`application/json`}}).then(e=>zb(e)),e,t,n);if(!Jb(r))throw Error(`Invalid JSR package metadata received for "${e}"`);let i=r;return{versions:Object.keys(i.versions),tags:{latest:i.latest}}}function Kb(e){let t=Object.keys(e.versionsMeta),n=Object.fromEntries(Object.entries(e.versionsMeta).flatMap(([e,t])=>t.deprecated==null?[]:[[e,t.deprecated]])),r=Object.fromEntries(Object.entries(e.versionsMeta).map(([e,t])=>[e,t.engines?.node]).filter(([,e])=>e)),i=Object.fromEntries(Object.entries(e.versionsMeta).map(([e,t])=>[e,t.provenance]).filter(([,e])=>e)),a=Object.fromEntries(Object.entries(e.versionsMeta).map(([e,t])=>[e,t.integrity]).filter(([,e])=>e));return{tags:e.distTags,versions:t,time:{...Object.fromEntries(Object.entries(e.versionsMeta).filter(([,e])=>e.time).map(([e,t])=>[e,t.time])),created:e.timeCreated,modified:e.timeModified},nodeSemver:r,provenance:i,deprecated:Object.keys(n).length>0?n:void 0,integrity:a}}function qb(e){return typeof e==`object`&&!!e&&`versionsMeta`in e&&`distTags`in e}function Jb(e){return typeof e==`object`&&!!e&&`scope`in e&&`name`in e&&`latest`in e&&`versions`in e}let Yb=null;const Xb=()=>(Yb===null&&(Yb=md(`packages/version-upgrade/src/io/cache`)),Yb),Zb=(0,dm.default)(`version-upgrade:cache`);let Qb={},$b=!1;const ex=sm(s.tmpdir(),`version-upgrade`),tx=sm(ex,`cache.json`),nx=18e5;function rx(){return Date.now()}function ix(e){return rx()-e}async function ax(){E(tx)&&ix(D(tx).mtimeMs)<nx?(Zb(`cache loaded from ${tx}`),Qb=JSON.parse(await O.readFile(tx,`utf-8`))):Zb(`no cache found`)}async function ox(){if($b)try{await O.mkdir(ex,{recursive:!0}),await O.writeFile(tx,JSON.stringify(Qb),`utf-8`),Zb(`cache saved to ${tx}`)}catch(e){Xb().error(`Failed to save cache`,e instanceof Error?e:Error(String(e)))}}async function sx(e,t=`npm`,n,r,i){let a,o=`${t}:${e}`;if(Qb[o]){if(ix(Qb[o].cacheTime)<nx)return Zb(`cache hit for ${o}`),Qb[o].data;delete Qb[o]}try{let a=t===`jsr`?await Gb(e,r,i):await Wb(e,!1,n,r,i);if(a)return Qb[o]={data:a,cacheTime:rx()},$b=!0,a}catch(e){a=e}return{tags:{},versions:[],error:a instanceof Error&&a.message||String(a),deprecated:{}}}const cx=[`**/node_modules/**`,`**/dist/**`,`**/public/**`,`**/fixture/**`,`**/fixtures/**`];function lx(e,t=[]){if(!e)return{};let n={};for(let[r,i]of Object.entries(e))if(typeof i==`object`&&i){let e={};for(let[t,n]of Object.entries(i))e[t]=n;n={...n,...lx(e,[...t,r])}}else typeof i==`string`&&(n[r]={version:i,parents:t});return n}function ux(e,t){let n=t.split(`.`).reduce((e,t)=>{if(typeof e==`object`&&e){let n={};for(let[t,r]of Object.entries(e))n[t]=r;return n[t]}},e);if(typeof n==`object`&&n){let e={};for(let[t,r]of Object.entries(n))e[t]=r;return lx(e)}return{}}function dx(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))t[n]=r;return t}return{}}function fx(e,t,n){let r=t.split(`.`),i=r.pop();if(i===void 0)return;let a=e;for(let e of r){(typeof a[e]!=`object`||a[e]===null)&&(a[e]={});let t=dx(a[e]);a[e]=t,a=t}a[i]=n}function px(e,t,n){return Object.entries(ux(e,t)||{}).map(([e,{version:r,parents:i}])=>mx({name:e,version:r,type:t,shouldUpdate:n,parents:i}))}function mx({name:e,version:t,type:n,shouldUpdate:r,parents:i,hexHash:a}){let o={name:e,currentVersion:t,parents:i,source:n,update:r(e)};return a&&(o.hexHash=a),o}function hx(e,t){let n={};return e.filter(e=>e.source===t).sort((e,t)=>(e.aliasName||e.name).localeCompare(t.aliasName||t.name)).forEach(e=>{let t=e.update?e.targetVersion:e.currentVersion,r=n;if(e.parents&&e.parents.length>0){let t=n;for(let n of e.parents){(typeof t[n]!=`object`||t[n]===null)&&(t[n]={});let e=dx(t[n]);t[n]=e,t=e}r=t}if(e.aliasName===void 0)r[e.name]=t;else{let n=e.protocol?`${e.protocol}:`:``;r[e.aliasName]=`${n}${e.protocol===`jsr`?t:gx(e,t)}`}}),n}function gx(e,t){let n=t?`@${t}`:``;return`${e.name}${n}`}async function _x(e,t,n,r){let i=sm(t.cwd??``,e),a=r??JSON.parse(await ce(i,`utf-8`)),o=[];function s(t,r){let o=Object.entries(r).map(([e,t])=>mx({name:e,version:t,type:`bun-workspace`,shouldUpdate:n}));return{name:t,private:!0,version:``,type:`bun-workspace`,relative:e,filepath:i,raw:a,deps:o,resolved:[]}}let c=a?.workspaces;if(c&&typeof c==`object`){let e=bx(c);if(e.catalog&&typeof e.catalog==`object`&&o.push(s(`bun-catalog:default`,xx(e.catalog))),e.catalogs&&typeof e.catalogs==`object`){let t=Sx(e.catalogs);for(let e of Object.keys(t)){let n=t[e];n&&o.push(s(`bun-catalog:${e}`,n))}}}return o}async function vx(e,t){let n=hx(e.resolved,`bun-workspace`);if(Object.keys(n).length&&e.name.startsWith(`bun-catalog:`)){let t=e.name.replace(`bun-catalog:`,``),r=bx(e.raw.workspaces??{});if(e.raw.workspaces=r,t==="default")r.catalog={...xx(r.catalog??{}),...xx(n)};else{let e=Sx(r.catalogs??{});r.catalogs=e,e[t]||(e[t]={}),e[t]={...e[t],...xx(n)}}await yx(e.filepath,e.raw)}}async function yx(e,t){let n;try{n=_v(await ce(e,`utf-8`)).indent}catch{}let r=JSON.stringify(t,null,n||` `);await R(e,`${r}\n`,`utf-8`)}function bx(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))t[n]=r;return t}return{}}function xx(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))typeof r==`string`&&(t[n]=r);return t}return{}}function Sx(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))if(typeof r==`object`&&r&&!Array.isArray(r)){let e={};for(let[t,n]of Object.entries(r))typeof n==`string`&&(e[t]=n);t[n]=e}return t}return{}}let Cx=null;const wx=()=>(Cx===null&&(Cx=md(`packages/version-upgrade/src/addons/vscode`)),Cx);function Tx(e,t){if(typeof e==`object`&&e){for(let[n,r]of Object.entries(e))if(n===t&&typeof r==`string`)return r}}function Ex(e){if(e==null)return!1;let t=e.engines;return Tx(t,`vscode`)!==void 0}function Dx(e){for(let t of[`dependencies`,`devDependencies`,`peerDependencies`]){let n=Tx(e[t],`@types/vscode`);if(n!==void 0)return n}return``}const Ox=[{beforeWrite(e){if(!Ex(e.raw)||e.raw==null)return;let t=e.raw,n=Dx(t);if(!n||n.includes(`:`))return;let r=t.engines,i=Tx(r,`vscode`);if(!i)return;let a=hy(i),o=hy(n);if(a&&o&&Rv(o,a)){wx().info(`[taze addon] Updated VS Code engine field to ${n}`);let e=/[>^<:~]/.test(n)?n:`^${n}`;if(typeof r==`object`&&r){let n={};for(let[t,i]of Object.entries(r))n[t]=t===`vscode`?e:i;t.engines=n}}}}];function kx(e){return I.from(e.slice(7),`base64`).toString(`hex`)}function Ax(e){return typeof e==`object`&&!!e&&`version`in e&&typeof e.version==`string`}const jx=[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`,`packageManager`,`pnpm.overrides`,`resolutions`,`overrides`];function Mx(e,t){return t.depFields?.[e]===!1?!1:e!==`peerDependencies`||!!t.peer}async function Nx(e,t,n,r){let i=sm(t.cwd??``,e),a=r??await Qx(i),o=[];for(let e of jx)if(Mx(e,t)){if(e===`packageManager`){let e=a.packageManager;if(typeof e==`string`){let t=e.indexOf(`@`),r=t>0?e.slice(0,t):``,i=t>0?e.slice(t+1):``,a=i.indexOf(`+`),s=a>=0?i.slice(0,a):i,c=a>=0?i.slice(a+1):``,l=c.indexOf(`.`),u=l>=0?c.slice(l+1):void 0;o.push(mx({name:r,version:`^${s}`,type:`packageManager`,shouldUpdate:n,hexHash:u}))}}else o.push(...px(a,e,n))}let s=typeof a.name==`string`?a.name:``,c=typeof a.version==`string`?a.version:``;return[{name:s,private:!!a.private,version:c,type:`package.json`,relative:e,filepath:i,raw:a,deps:o,resolved:[]}]}async function Px(e,t){let n=!1;for(let r of jx)if(Mx(r,t)){if(r===`packageManager`){let t=Object.entries(hx(e.resolved,`packageManager`))[0];if(t){e.raw||={};let[r,i]=t,a=typeof i==`string`?i.replace(`^`,``):String(i),o=`${r}@${a}`,s=e.resolved.find(e=>e.source===`packageManager`&&e.name===r);if(s?.hexHash){let e=s.pkgData?.integrity?.[a];if(e){let t=kx(e);o=`${o}+sha512.${t}`}}e.raw.packageManager=o,n=!0}}else{let t=ux(e.raw,r),i=hx(e.resolved,r),a={};for(let[e,n]of Object.entries(t||{}))Ax(n)&&(a[e]=n.version);for(let[e,t]of Object.entries(i||{}))a[e]=t;Object.keys(a).length>0&&(fx(e.raw,r,a),n=!0)}}if(n){for(let n of t.addons||Ox)await n.beforeWrite?.(e,t);await $x(e.filepath,e.raw||{})}}const Fx=[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`,`packageManager`,`pnpm.overrides`,`resolutions`,`overrides`];function Ix(e,t){return e===`peerDependencies`?!!t.peer:t.depFields?.[e]!==!1}async function Lx(e){let t=await se.readFile(e,`utf-8`);if(!t)return new Nb.Document({});let n=(0,Nb.parseDocument)(t,{merge:!0}),r=n.toJS();if(n.errors.length||typeof r!=`object`||Array.isArray(r))throw TypeError(`Invalid package.yaml structure in ${e}`);return n}async function Rx(e,t){let{amount:n,type:r}=await se.readFile(e,`utf-8`).then(_v).catch(()=>({amount:2,type:`space`})),i=(0,Nb.stringify)(t,{indent:(r===`tab`?2:n)??2,aliasDuplicateObjects:!1,lineWidth:0}).replace(/^(\s*)"(@[^":]+)":/gm,`$1'$2':`);await se.writeFile(e,i,`utf-8`)}async function zx(e,t,n){let r=sm(t.cwd??``,e),i=await Lx(r),a=[];for(let e of Fx)if(Ix(e,t)){if(e===`packageManager`){let t=i.get(e);if(typeof t==`string`){let e=t.split(`@`),r=e[0]??``,i=(e[1]??``).split(`+`)[0];a.push(mx({name:r,version:`^${i??``}`,type:`packageManager`,shouldUpdate:n}))}}else{let t={},r=i.toJS();if(typeof r==`object`&&r&&!Array.isArray(r))for(let[e,n]of Object.entries(r))t[e]=n;a.push(...px(t,e,n))}}let o=i.get(`name`),s=i.get(`version`);return[{name:typeof o==`string`?o:``,private:!!i.get(`private`),version:typeof s==`string`?s:``,type:`package.yaml`,relative:e,filepath:r,get raw(){return i.toJS()},deps:a,yamlDocument:i,resolved:[]}]}async function Bx(e,t){let n=!1;if(e.type!==`package.yaml`)throw Error(`Package type is not supported`);let r=e.yamlDocument||new Nb.Document(e.raw);for(let i of Fx)if(Ix(i,t)){if(i===`packageManager`){let t=Object.entries(hx(e.resolved,`packageManager`))[0];if(t){let[e,i]=t,a=typeof i==`string`?i.replace(`^`,``):``;r.set(`packageManager`,`${e}@${a}`),n=!0}}else{let t=ux(Vx(r),i);t&&Object.keys(t).length>0&&(Object.entries(hx(e.resolved,i)).forEach(([e,t])=>r.setIn([...i.split(`.`),e],t)),n=!0)}}if(n){for(let n of t.addons||Ox)await n.beforeWrite?.(e,t);await Rx(e.filepath,r)}}function Vx(e){let t=e.toJS();if(typeof t==`object`&&t&&!Array.isArray(t)){let e={};for(let[n,r]of Object.entries(t))e[n]=r;return e}return{}}async function Hx(e,t,n){let r=sm(t.cwd??``,e),i=Pb(await ce(r,`utf-8`)),a=i.getDocument().toJSON(),o=[];function s(t,o){let s=Object.entries(o).map(([e,t])=>mx({name:e,version:t,type:`pnpm-workspace`,shouldUpdate:n}));return{name:t,private:!0,version:``,type:`pnpm-workspace.yaml`,relative:e,filepath:r,raw:a,context:i,deps:s,resolved:[]}}if(a?.catalog&&o.push(s(`pnpm-catalog:default`,a.catalog)),a?.catalogs)for(let e of Object.keys(a.catalogs))o.push(s(`pnpm-catalog:${e}`,a.catalogs[e]));return a?.overrides&&o.push(s(`pnpm-workspace:overrides`,a.overrides)),o}async function Ux(e,t){let n=hx(e.resolved,`pnpm-workspace`);if(Object.keys(n).length){if(e.name.startsWith(`pnpm-catalog:`)){let t=e.name.replace(`pnpm-catalog:`,``);for(let[r,i]of Object.entries(n))typeof i==`string`&&e.context.setPackage(t,r,i)}else{let t=e.name.replace(`pnpm-workspace:`,``).split(/\./g);for(let[r,i]of Object.entries(n))e.context.setPath([...t,r],i)}e.context.hasChanged()&&await Wx(e,e.context)}}function Wx(e,t){return R(e.filepath,t.toString(),`utf8`)}async function Gx(e,t,n){let r=sm(t.cwd??``,e),i=Pb(await ce(r,`utf-8`)),a=i.getDocument().toJSON(),o=[];function s(t,o){let s=Object.entries(o).map(([e,t])=>mx({name:e,version:t,type:`yarn-workspace`,shouldUpdate:n}));return{name:t,private:!0,version:``,type:`.yarnrc.yml`,relative:e,filepath:r,raw:a,context:i,deps:s,resolved:[]}}if(a?.catalog&&o.push(s(`yarn-catalog:default`,a.catalog)),a?.catalogs)for(let e of Object.keys(a.catalogs))o.push(s(`yarn-catalog:${e}`,a.catalogs[e]));return o}async function Kx(e,t){let n=hx(e.resolved,`yarn-workspace`);if(Object.keys(n).length){if(e.name.startsWith(`yarn-catalog:`)){let t=e.name.replace(`yarn-catalog:`,``);for(let[r,i]of Object.entries(n))typeof i==`string`&&e.context.setPackage(t,r,i)}else{let t=e.name.replace(`yarn-workspace:`,``).split(/\./g);for(let[r,i]of Object.entries(n))e.context.setPath([...t,r],i)}e.context.hasChanged()&&await qx(e,e.context)}}function qx(e,t){return R(e.filepath,t.toString(),`utf8`)}function Jx(e){return e.replace(/[.+?^${}()|[\]\\]/g,`\\$&`)}function Yx(e){if(e.startsWith(`/`)){let t=e.lastIndexOf(`/`),n=e.substring(1,t),r=e.substring(t+1,e.length);return new RegExp(n,r)}return RegExp(`^${Jx(e).replace(/\*+/g,`.*?`)}$`)}function Xx(e,t=!0){if(!e||e.length===0)return()=>t;let n=Lb(e).flatMap(e=>e.split(`,`)).map(Yx);return e=>{for(let t of n)if(t.test(e))return!0;return!1}}function Zx(e,t){let n=Xx(e,!0),r=Xx(t,!1);return e=>!r(e)&&n(e)}async function Qx(e){return JSON.parse(await O.readFile(e,`utf-8`))}async function $x(e,t){let n=_v(await O.readFile(e,`utf-8`)).indent||` `;await O.writeFile(e,`${JSON.stringify(t,null,n)}\n`,`utf-8`)}async function eS(e,t){switch(e.type){case`package.json`:return Px(e,t);case`package.yaml`:return Bx(e,t);case`pnpm-workspace.yaml`:return Ux(e,t);case`bun-workspace`:return vx(e,t);case`.yarnrc.yml`:return Kx(e,t);default:throw Error(`Unsupported package type: ${e.type}`)}}async function tS(e,t,n){if(e.endsWith(`pnpm-workspace.yaml`))return Hx(e,t,n);if(e.endsWith(`.yarnrc.yml`))return Gx(e,t,n);if(e.endsWith(`package.yaml`))return zx(e,t,n);if(e.endsWith(`package.json`)){let r=sm(t.cwd??``,e);try{let i=await Qx(r),a=i?.workspaces;if(a&&typeof a==`object`&&(`catalog`in a||`catalogs`in a)){let r=sm(t.cwd||F.cwd());if(E(am(r,`bun.lockb`))||E(am(r,`bun.lock`))){let r=await _x(e,t,n,i),a=await Nx(e,t,n,i);return[...r,...a]}}return Nx(e,t,n,i)}catch{}}return Nx(e,t,n)}async function nS(e){let t=[],n=sm(e.cwd||F.cwd()),r=Zx(e.include,e.exclude);if(e.recursive){let n=await Pp(`**/package.yaml`,{ignore:cx.concat(e.ignorePaths||[]),cwd:e.cwd,onlyFiles:!0,dot:!1,expandDirectories:!1}),r=await Pp(`**/package.json`,{ignore:cx.concat(e.ignorePaths||[]),cwd:e.cwd,onlyFiles:!0,dot:!1,expandDirectories:!1}),i=/* @__PURE__ */ new Set;for(let e of n){t.push(e);let n=um(e);i.add(n)}for(let e of r){let n=um(e);i.has(n)||t.push(e)}}else t=await Pp(`package.{yaml,json}`,{cwd:n});return t=t.sort((e,t)=>e.localeCompare(t)),e.ignoreOtherWorkspaces&&(t=(await Promise.all(t.map(async e=>{if(!e.includes(`/`))return[e];let t=am(n,e),r=bv(`.git`,{cwd:t,last:n});if(r&&um(r)!==n)return[];let i=bv(`pnpm-workspace.yaml`,{cwd:t,last:n});if(i&&um(i)!==n)return[];let a=bv(`.yarnrc.yml`,{cwd:t,last:n});if(a&&um(a)!==n)return[];let o=bv(`bun.lockb`,{cwd:t,last:n})||bv(`bun.lock`,{cwd:t,last:n});return o&&um(o)!==n?[]:[e]}))).flat()),E(am(n,`pnpm-workspace.yaml`))&&t.unshift(`pnpm-workspace.yaml`),E(am(n,`.yarnrc.yml`))&&t.unshift(`.yarnrc.yml`),(await Promise.all(t.map(t=>tS(t,e,r)))).flat()}const rS={error:-1,major:0,minor:1,patch:2,"":3};function iS(e){return e.sort((e,t)=>rS[e.diff||``]-rS[t.diff||``])}function aS(e,t){if(t.packageMode){for(let n of Object.keys(t.packageMode))if(Yx(n).test(e))return t.packageMode[n]}}function oS(e,t){let n=[];for(let r of Lb(t.maturityPeriodExclude).flatMap(e=>e.split(`,`))){let t=r.trim();if(!t)continue;let i=t.startsWith(`/`)?-1:t.lastIndexOf(`@`);if(!Yx(i>0?t.slice(0,i):t).test(e))continue;if(i<=0)return!0;let a=t.slice(i+1).split(`||`).map(e=>e.trim()).filter(Boolean);n.push(...a)}return n}function sS(e,t){for(let n of t)if(my(e,n,{includePrerelease:!0}))return!0;return!1}const cS=new P;function lS(e){return e.match(/(@[^/]+\/)?([^/]+)/g)||[]}function uS(e){return e.match(/[^>]+/g)||[]}function dS(e){return/^(?:https?:|git\+|github:)/.test(e)}function fS(e){return/^(?:link|file|workspace|catalog):/.test(e)}function pS(e){return/^(?:npm|jsr):/.test(e)}function mS(e){return e===`npm`?`npm`:e===`jsr`?`jsr`:`npm`}function hS(e){let t=e.indexOf(`:`),n=mS(e.slice(0,t)),r=e.slice(t+1);if(n===`npm`){let e=r.lastIndexOf(`@`);return e>0?{protocol:n,name:r.substring(0,e),version:r.substring(e+1)}:{protocol:n,name:r,version:``}}return{protocol:n,name:``,version:r}}function gS(e){let t=[`>=`,`<=`,`>`,`<`,`~`,`^`],n=e.trim();if(n===`*`||n===``)return`*`;if(n[0]===`~`||n[0]===`^`)return n[0];for(let e of t)if(n.startsWith(e))return e;if(n.includes(`x`)){let e=n.split(`.`);if(e[0]===`x`)return`*`;if(e[1]===`x`)return`^`;if(e[2]===`x`)return`~`}return n.length>0&&n.charCodeAt(0)>=48&&n.charCodeAt(0)<=57?``:null}function _S(e,t){if(!gy(e))return null;if(t==="default")return e;let n=hy(e);return n?{major:`>=`,minor:`^`,patch:`~`}[t]+n:null}function vS(e,t){return e==null||t==null?null:t===`*`?`*`:t+e}function yS(e,t){return vS(t,gS(e))}function bS(e,t,n,r){let i=null;if(n===`latest`){let t=r.latest;i=t!=null&&e.includes(t)?t:e.at(-1)??null}else if(n===`newest`)i=e.at(-1)??null;else if(n===`next`){let t=r.next;i=t!=null&&e.includes(t)?t:e.at(-1)??null}else if(n===`stable`){let n=_S(t,`default`);if(!n)return;e.filter(e=>!e.includes(`-`)).forEach(e=>{my(e,n)&&(!i||Rv(e,i))&&(i=e)})}else if(n==="default"&&(t===`*`||t.trim()===``))return;else{let a=_S(t,n);if(!a)throw Error(`invalid_range`);let o=r.latest??null;o&&!my(o,a)&&(o=null),e.forEach(e=>{!my(e,a)||o&&!Vv(e,o)||i&&!Rv(e,i)||(i=e)})}if(i)return i}function xS(e,t){return e.filter(e=>!t[e])}function SS(e,t,n){if(!t||n<=0)return e;let r=/* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).getTime()-n*24*60*60*1e3);return e.filter(e=>{let n=t[e];return!n||new Date(n)<r})}function CS(e,t,n){let{tags:r}=e.pkgData,i=wS(e,n);if(i.length!==0)return e.filteredVersions=i,bS(i,e.currentVersion,t,r)}function wS(e,t){let{versions:n,deprecated:r,time:i}=e.pkgData,a=n;r&&Object.keys(r).length>0&&(a=xS(a,r));let o=oS(e.name,t);if(t.maturityPeriod&&t.maturityPeriod>0&&o!==!0){let e=a;if(a=SS(e,i,t.maturityPeriod),o.length>0){let t=new Set(a);a=e.filter(e=>t.has(e)||sS(e,o))}}return a}function TS(e,t,n){let r=CS(e,`latest`,n);return r&&Rv(r,t)?r:void 0}function ES(e,t,n=!0,r=!1){let i=/^\d+/.test(e.currentVersion);if(i&&!r)e.targetVersion=e.currentVersion,e.targetVersionTime=e.currentVersionTime,e.diff=null,e.update=!1;else{if(e.targetVersion=yS(e.currentVersion,t)||e.currentVersion,e.targetVersionTime=e.pkgData.time?.[t],e.currentProvenance=e.pkgData.provenance?.[e.currentVersion],e.targetProvenance=e.pkgData.provenance?.[e.targetVersion],e.provenanceDowngraded=!(!e.currentProvenance||e.targetProvenance)||e.currentProvenance===`trustedPublisher`&&e.targetProvenance===!0,i&&Lv(e.currentVersion,e.targetVersion)){let{versions:t,time:n={},tags:r}=e.pkgData,i=bS(e.filteredVersions??t,e.currentVersion,`minor`,r);i&&(e.targetVersion=i,e.targetVersionTime=n[e.targetVersion])}try{let t=hy(e.currentVersion),n=hy(e.targetVersion);if(!t||!n)throw Error(`invalid_version`);e.currentVersionTime=e.pkgData.time?.[t.toString()],e.diff=DS(t,n),e.update=e.diff!==null&&Bv(t,n)}catch(t){if(!n)throw t;e.targetVersion=e.currentVersion,e.diff=`error`,e.update=!1}}}function DS(e,t){if(Lv(e,t))return null;let n=my(t,`~${e}`,{includePrerelease:!0}),r=my(t,`^${e}`,{includePrerelease:!0}),i=my(t,`>=${e}`,{includePrerelease:!0});return n?r?`patch`:`major`:r?`minor`:i?`major`:`error`}function OS(e,t){return{...e,diff:null,targetVersion:e.currentVersion,update:!1,provenanceDowngraded:!1,pkgData:{tags:{},versions:[]},...t}}function kS(e){return e!=null&&e!==`ignore`?e:`default`}async function AS(e,t,n=()=>!0){let r={...e,diff:null,targetVersion:e.currentVersion,update:e.update,provenanceDowngraded:!1,pkgData:{tags:{},versions:[]}},i=aS(r.name,t),a=t.mode,o=i?i===a?a:a==="default"?i:`ignore`:a;if(fS(e.currentVersion)||dS(e.currentVersion)||!e.update||!await Promise.resolve(n(e))||o===`ignore`)return OS(e);if(pS(e.currentVersion)){let{name:t,version:n,protocol:i}=hS(e.currentVersion);if(r.name=t||r.name,r.currentVersion=n,r.aliasName=e.name,r.protocol=i,!n)return OS(e,{name:r.name,currentVersion:n,aliasName:e.name,protocol:i})}let s=r.name;r.source===`resolutions`?s=lS(r.name).pop()??r.name:r.source===`pnpm.overrides`&&(s=uS(r.name).pop()??r.name);let c=await sx(s,r.protocol,t.cwd,t.timeout,t.retries),{error:l,deprecated:u}=c;r.pkgData=c;let d=null,f;if(l==null)try{if(u&&typeof u==`object`&&r.currentVersion&&u[r.currentVersion])return OS(e,{name:r.name,currentVersion:r.currentVersion,aliasName:r.aliasName,protocol:r.protocol});if(f=CS(r,kS(o),t),!f)return OS(e,{name:r.name,currentVersion:r.currentVersion,aliasName:r.aliasName,protocol:r.protocol,pkgData:c})}catch(e){d=e instanceof Error?e.message:String(e)}else d=l;f?ES(r,f,void 0,t.includeLocked):r.targetVersion=r.currentVersion,r.targetVersion===r.currentVersion&&(r.diff=null,r.update=!1);try{let e=hy(f||r.targetVersion||``);e&&(r.latestVersionAvailable=TS(r,e,t));let{nodecompat:n=!0}=t;if(n){let t=F.version,{nodeSemver:n}=r.pkgData;if(n&&e?.version&&e?.version in n){let i=n[e.version];r.nodeCompatibleVersion={compatible:i!=null&&my(t,i),semver:i??``}}}}catch{}return d&&(r.diff=`error`,r.update=!1,r.resolveError=d),r}async function jS(e,t,n=()=>!0,r=()=>{}){let i=e.length,a=0,{concurrency:o=10}=t,s=cS.getStore()||qp(o);return Promise.all(e.map(e=>s.add(async()=>{let o=await AS(e,t,n);return a+=1,r(e.name,a,i),o})))}async function MS(e,t,n,r){let i=await jS(e.deps,t,n,(t,n,i)=>r?.(e.name,t,n,i));return iS(i),e.resolved=i,e}async function NS(e,t={}){e.force||await ax();let n=await nS(e);t.afterPackagesLoaded?.(n);let r=n.filter(e=>e.private).map(e=>e.name).filter(e=>e),i=e=>!r.includes(e.name),a=0,o=(e,n,r,i)=>{a++,t.onDependencyResolved?.(e,n,a,i)},s=qp(e.concurrency||10);return await cS.run(s,()=>Promise.all(n.map(async n=>{t.beforePackageStart?.(n),await PS(n,e,i,{...t,onDependencyResolved:o}),t.afterPackageEnd?.(n)}))),t.afterPackagesEnd?.(n),await ox(),{packages:n}}async function PS(e,t,n=()=>!0,r={}){await MS(e,t,n,r.onDependencyResolved);let{resolved:i}=e,a=i.filter(e=>e.update);return t.write&&a.length&&await Promise.resolve(r.beforePackageWrite?.(e))!==!1&&(await eS(e,t),r.afterPackageWrite?.(e)),e}function FS(e){return{ok:!0,value:e}}function IS(e){return{ok:!1,error:e}}const LS=/^[a-z][a-z0-9-]*$/,RS=[`edition-root`,`customer-root`,`single-repo`],zS=Ac([`high`,`normal`,`low`]),BS=Ac(RS),VS=/\S/,HS=yc({id:U().regex(LS,`范围 id 非法(应为小写字母开头的字母数字连字符)`),kind:BS,remotes:gc(U().regex(VS,`远程位置非法(不得为空串或纯空白)`)).default([]),tags:gc(U().regex(VS,`标签非法(不得为空串或纯空白)`)).default([]),priority:zS.default(`normal`),excludes:gc(U().min(1)).default([]),projectPriorities:Oc(U(),zS).default({})}).check(e=>{e.value.kind===`single-repo`&&(e.value.excludes.length>0&&e.issues.push({code:`custom`,input:e.value,path:[`excludes`],message:`single-repo 范围禁用 excludes(声明的即唯一项目,如需排除请改用 edition-root/customer-root)`}),Object.keys(e.value.projectPriorities).length>0&&e.issues.push({code:`custom`,input:e.value,path:[`projectPriorities`],message:`single-repo 范围禁用 projectPriorities(优先级直接设于 scope 级)`}))}),US=`scopes`,WS=/^[a-z][a-z0-9-]*\.scope\.ts$/;async function GS(e){let t=j(e,US);if(!E(t))return IS({code:`SCOPES_DIR_MISSING`,message:`声明域目录缺失:${t}(应为 project-registry 仓根下 ${US}/,含 *.scope.ts 声明文件)`});let n=A(t).filter(e=>WS.test(e)).sort((e,t)=>e<t?-1:1);if(n.length===0)return IS({code:`SCOPE_REGISTRY_EMPTY`,message:`范围声明域为空:${t}(无 *.scope.ts——范围消失属配置事故,如需清空请显式移除 registryRoot 配置)`});let r=/* @__PURE__ */ new Set,i=[];for(let e of n){let n=j(t,e),a=await import(N(n).href),o=HS.safeParse(a.default);if(!o.success){let e=o.error.issues[0];return IS({code:`SCOPE_DECLARATION_INVALID`,message:`范围声明结构非法:${n}(${e?.path.join(`.`)??``} ${e?.message??``})`})}let s=e.replace(/\.scope\.ts$/,``);if(o.data.id!==s)return IS({code:`SCOPE_ID_MISMATCH`,message:`范围 id 与文件名不一致:${n}(id=${o.data.id},应为 ${s}——命名即身份)`});if(r.has(o.data.id))return IS({code:`SCOPE_ID_CONFLICT`,message:`范围 id 重复:${o.data.id}(声明域内同 id 即同范围,不得重复声明)`});r.add(o.data.id),i.push(o.data)}return FS(i)}const KS=`LZI_PROJECT_REGISTRY_ROOT`,qS=`LZI_PROJECT_MARKDOWN_REGISTRY_ROOT`,JS=`LZI_PROJECT_SCOPE_ROOTS`,YS=`LZI_PROJECT_MARKDOWN_SCOPE_ROOTS`,XS=/^[a-z][a-z0-9-]*=\/\S+$/;function ZS(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function QS(e){let t=/* @__PURE__ */ new Map;for(let n of ZS(e)){if(!XS.test(n))return IS({message:`范围根映射段非法:${n}(应为 id=绝对路径 形态,id 为小写字母开头的字母数字连字符)`});let e=n.indexOf(`=`),r=n.slice(0,e),i=M(n.slice(e+1));if(t.has(r))return IS({message:`范围根映射 id 重复:${r}(同一范围不得重复映射)`});t.set(r,i)}return FS(t)}function $S(e,t,n,r){return e!==void 0&&t!==void 0&&e.trim()!==t.trim()?IS({code:`ACQUISITION_ENV_INVALID`,message:`环境变量双名冲突:${n} 与 ${r} 同时在场且值不一致(请统一使用新名 ${n})`,variables:[n,r]}):FS({value:e??t,variables:e===void 0?t===void 0?[]:[r]:[n]})}function eC(e=process.env){let t=$S(e[KS],e[qS],KS,qS);if(!t.ok)return IS(t.error);let n=$S(e[JS],e[YS],JS,YS);if(!n.ok)return IS(n.error);let r;if(n.value.value!==void 0){let e=QS(n.value.value);if(!e.ok)return IS({code:`ACQUISITION_ENV_INVALID`,message:e.error.message,variables:[...n.value.variables]});r=e.value}return FS({registryRoot:t.value.value===void 0?void 0:M(t.value.value.trim()),scopeRoots:r})}const tC=/^[A-Za-z0-9_][A-Za-z0-9._-]*$/;function nC(e,t){return e.name<t.name?-1:+(e.name>t.name)}function rC(e){return E(j(e,`.git`))}function iC(e,t){return t.get(e.id)}function aC(e,t,n,r){if(n.has(e.id))return IS({code:`SCOPE_ID_CONFLICT`,message:`范围 id 冲突:${e.id}(声明域内不得重复)`});n.add(e.id);let i=iC(e,t);return i===void 0?IS({code:`SCOPE_ROOT_UNMAPPED`,message:`范围根未映射:${e.id}(声明零本地路径,请在 .env 的 LZI_PROJECT_SCOPE_ROOTS 或 LZI_PROJECT_MARKDOWN_SCOPE_ROOTS 补 id=绝对路径 映射)`}):E(i)?FS({def:e,root:i,sourceId:r}):IS({code:`DIR_NOT_FOUND`,message:`范围根不存在:${i}(范围 ${e.id} 机内映射目标)`})}function oC(e,t){let n=[],r=[];for(let i of[...A(e.root,{withFileTypes:!0})].sort(nC)){if(i.name.startsWith(`.`))continue;if(!i.isDirectory()){r.push({scope:e.def.id,entry:i.name,reason:`ROOT_FILE`});continue}if(e.def.excludes.includes(i.name)){r.push({scope:e.def.id,entry:i.name,reason:`EXCLUDED`});continue}let a=j(e.root,i.name);t!==void 0&&M(a)===M(t)?r.push({scope:e.def.id,entry:i.name,reason:`EXCLUDED_PATH`}):!rC(a)||!tC.test(i.name)?r.push({scope:e.def.id,entry:i.name,reason:`NOT_A_REPO`}):n.push({scope:e.def.id,scopeKind:e.def.kind,priority:e.def.projectPriorities[i.name]??e.def.priority,sourceId:e.sourceId,project:i.name,path:a})}return{scope:e.def.id,scopeKind:e.def.kind,priority:e.def.priority,scopeRoot:e.root,sourceId:e.sourceId,projects:n,skipped:r}}function sC(e,t){let n=ee(e.root);return t!==void 0&&M(e.root)===M(t)||!rC(e.root)||!tC.test(n)?IS({code:`SCOPE_ROOT_INVALID`,message:`single-repo 范围根非法:${e.root}(应为含 .git 的合规项目目录,且不得为排除路径)`}):FS({scope:e.def.id,scopeKind:`single-repo`,priority:e.def.priority,scopeRoot:e.root,sourceId:e.sourceId,projects:[{scope:e.def.id,scopeKind:`single-repo`,priority:e.def.priority,sourceId:e.sourceId,project:n,path:e.root}]})}function cC(e,t,n){let r=[],i=[],a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Map;for(let s of e){let e=aC(s,n.scopeRoots,a,n.sourceId);if(!e.ok)return IS(e.error);let c,l=[];if(s.kind===`single-repo`){let n=sC(e.value,t);if(!n.ok)return IS(n.error);c=n.value}else{let n=oC(e.value,t);c=n,l=n.skipped}for(let e of c.projects){let t=o.get(e.project);if(t!==void 0)return IS({code:`PROJECT_NAME_CONFLICT`,message:`项目名跨范围冲突:${e.project}(${t} 与 ${e.scope} 均含此名;归档平铺要求项目名全局唯一,可在后登记范围的 excludes 中显式排除)`});o.set(e.project,e.scope)}r.push(c),i.push(...l)}return r.sort((e,t)=>e.scope<t.scope?-1:+(e.scope>t.scope)),i.sort((e,t)=>e.scope===t.scope?e.entry<t.entry?-1:+(e.entry>t.entry):e.scope<t.scope?-1:1),FS({scopes:r,skipped:i})}const lC=l(ae);function uC(e){return typeof e==`object`&&!!e&&`stderr`in e}async function dC(e,t){try{let{stdout:n}=await lC(`git`,[`-C`,e,...t],{encoding:`utf8`});return{ok:!0,stdout:n.trim()}}catch(e){let t=uC(e)?e.stderr:void 0;return{ok:!1,stderr:typeof t==`string`?t:String(e)}}}function fC(e){return typeof e==`object`&&!!e}function pC(e){let t=j(e,`package.json`);if(!E(t))return{packageName:null,description:null};let n;try{n=JSON.parse(k(t,`utf8`))}catch{return{packageName:null,description:null}}if(!fC(n))return{packageName:null,description:null};let r=n.name,i=n.description;return{packageName:typeof r==`string`&&r!==``?r:null,description:typeof i==`string`&&i!==``?i:null}}async function mC(e){let t=await dC(e.path,[`rev-parse`,`--git-dir`]);if(!t.ok)return IS({code:`INSPECT_FAILED`,scope:e.scope,project:e.project,message:`仓库健康探测失败:${e.path}(${t.stderr})`});let n=await dC(e.path,[`remote`,`get-url`,`origin`]),r=n.ok&&n.stdout!==``?n.stdout:null,i=pC(e.path);return FS({scope:e.scope,scopeKind:e.scopeKind,priority:e.priority,sourceId:e.sourceId,project:e.project,projectPath:e.path,remoteUrl:r,packageName:i.packageName,description:i.description})}async function hC(e,t,n){let r=Math.max(1,Math.floor(t)),i=[],a=0;for(;a<e.length;){let t=e.slice(a,a+r),o=await Promise.all(t.map((e,t)=>n(e,a+t)));i.push(...o),a+=r}return i}async function gC(e={}){let t=eC(e.processEnv??process.env);if(!t.ok)return IS(t.error);let n=e.registryRoot??t.value.registryRoot;if(n===void 0)return IS({code:`ACQUISITION_ENV_INVALID`,message:`未定位 registry 仓根(请在 .env 配置 LZI_PROJECT_REGISTRY_ROOT 或显式传入 registryRoot)`});let r=await GS(n);if(!r.ok)return IS(r.error);let i=e.scopeRoots??t.value.scopeRoots??/* @__PURE__ */ new Map,a=e.scopeIds===void 0?void 0:new Set(e.scopeIds),o=a===void 0?[]:[...a].filter(e=>!r.value.some(t=>t.id===e));if(o.length>0)return IS({code:`SCOPE_SELECTOR_UNKNOWN`,message:`圈定的范围 id 不在声明域:${o.join(`、`)}(合法范围 id:${r.value.map(e=>e.id).join(`、`)})`});let s=r.value,c=[];if(a!==void 0){s=r.value.filter(e=>a.has(e.id));let e=s.filter(e=>!i.has(e.id)).map(e=>e.id);if(e.length>0)return IS({code:`SCOPE_ROOT_UNMAPPED`,message:`范围根未映射:${e.join(`、`)}(声明零本地路径,请在 .env 的 LZI_PROJECT_SCOPE_ROOTS 补 id=绝对路径 映射)`})}else if(s=r.value.filter(e=>i.has(e.id)),c=r.value.filter(e=>!i.has(e.id)).map(e=>e.id),s.length===0)return IS({code:`SCOPE_ROOT_UNMAPPED`,message:`范围根未映射:${r.value.map(e=>e.id).join(`、`)}(本机未配置任何范围根映射,请在 .env 的 LZI_PROJECT_SCOPE_ROOTS 补 id=绝对路径 映射)`});let l=cC(s,e.excludePath,{scopeRoots:i,sourceId:`scope-declarations`});if(!l.ok)return IS(l.error);let u=l.value.scopes.flatMap(e=>[...e.projects]),d=[],f=/* @__PURE__ */ new Map;if(e.inspect===!0){let e=await hC(u,16,async e=>mC(e));for(let t of e)t.ok?f.set(t.value.project,t.value):d.push({scope:t.error.scope,project:t.error.project,message:t.error.message})}let p=u.map(e=>{let t=f.get(e.project);return{scope:e.scope,scopeKind:e.scopeKind,priority:e.priority,sourceId:e.sourceId,project:e.project,path:e.path,remoteUrl:t?.remoteUrl??null,packageName:t?.packageName??null,description:t?.description??null}});return FS({registryRoot:n,scopes:l.value.scopes,projects:p,skipped:l.value.skipped,unmappedScopes:c,inspectFailures:d,inspected:e.inspect===!0})}const _C={RED:`\x1B[0;31m`,GREEN:`\x1B[0;32m`,YELLOW:`\x1B[1;33m`,BLUE:`\x1B[0;34m`,RESET:`\x1B[0m`};function vC(e){return e.map(e=>{if(typeof e==`string`)return e;if(e instanceof Error)return e.message;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `)}function $(...e){process.stdout.write(`${vC(e)}\n`)}function yC(...e){process.stderr.write(`${vC(e)}\n`)}const bC=async()=>{let e=await Gp();return e?(e.source===`legacy-dev-tools`&&$(`提示: 经 lzi-dev.config.ts 共享读取依赖工具配置,建议补建 lzi-dependencies.config.ts`),e.config):($(`提示: 未找到配置文件 lzi-dependencies.config.ts,使用默认配置`),{})},xC=[`**/node_modules/**`,`**/oh_modules/**`,`**/target/**`,`**/dist/**`,`**/build/**`,`**/.turbo/**`],SC=e=>!e||e.length===0?xC:[...xC,...e],CC=vc({name:U().optional(),workspaces:fc().optional(),devDependencies:Oc(U(),U()).optional()}),wC=async()=>{let e=process.cwd();$(`正在扫描 ${e} 下的 package.json 文件...`);let t=null;try{let n=CC.safeParse(await Bun.file(`${e}/package.json`).json());t=n.success?n.data:null}catch{t=null}t===null&&($(`未找到可解析的 workspace 根 package.json,请在仓库根目录执行本命令`),process.exit(1));let n=await bC(),r=SC(n.hoisting?.ignorePaths),i=new Set(n.hoisting?.allowlist??[]),a=t.devDependencies??{},o=await Pp(`**/package.json`,{cwd:e,ignore:r,onlyFiles:!0,dot:!1}),s=0,c=[];for(let t of o){if(t===`package.json`)continue;let n=null;try{let r=CC.safeParse(await Bun.file(`${e}/${t}`).json());n=r.success?r.data:null}catch{n=null}if(n===null||n.workspaces!==void 0)continue;let r=n.devDependencies??{};if(Object.keys(r).length!==0){s+=1;for(let[o,s]of Object.entries(r)){let r=a[o];r===void 0||i.has(o)||c.push({packageName:n.name??t,relPath:re(e,`${e}/${t}`),dependency:o,subRange:s,rootRange:r,drifted:s!==r})}}}if($(`找到 ${s} 个子包,根声明开发依赖 ${Object.keys(a).length} 项`),c.length===0)$(`所有子包均未重复声明根已有的开发依赖`);else{$(`
|
|
320
|
+
`,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=l(c(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=l(c(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}}})),Mb=/* @__PURE__ */ n((e=>{var t=wb(),n=sb(),r=cb(),i=My(),a=Q(),o=Ab(),s=jb();function c(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new o.LineCounter||null,prettyErrors:t}}function l(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=Array.from(l.compose(o.parse(e)));if(a&&i)for(let t of u)t.errors.forEach(r.prettifyError(e,i)),t.warnings.forEach(r.prettifyError(e,i));return u.length>0?u:Object.assign([],{empty:!0},l.streamInfo())}function u(e,n={}){let{lineCounter:i,prettyErrors:a}=c(n),o=new s.Parser(i?.addNewLine),l=new t.Composer(n),u=null;for(let t of l.compose(o.parse(e),!0,e.length))if(!u)u=t;else if(u.options.logLevel!==`silent`){u.errors.push(new r.YAMLParseError(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return a&&i&&(u.errors.forEach(r.prettifyError(e,i)),u.warnings.forEach(r.prettifyError(e,i))),u}function d(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let a=u(e,n);if(!a)return null;if(a.warnings.forEach(e=>i.warn(a.options.logLevel,e)),a.errors.length>0){if(a.options.logLevel!==`silent`)throw a.errors[0];a.errors=[]}return a.toJS(Object.assign({reviver:r},n))}function f(e,t,r){let i=null;if(typeof t==`function`||Array.isArray(t)?i=t:r===void 0&&t&&(r=t),typeof r==`string`&&(r=r.length),typeof r==`number`){let e=Math.round(r);r=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=r??t??{};if(!e)return}return a.isDocument(e)&&!i?e.toString(r):new n.Document(e,i,r).toString(r)}e.parse=d,e.parseAllDocuments=l,e.parseDocument=u,e.stringify=f})),Nb=(/* @__PURE__ */ n((e=>{var t=wb(),n=sb(),r=ab(),i=cb(),a=Cy(),o=Q(),s=Fy(),c=wy(),l=Ly(),u=zy();Ob();var d=kb(),f=Ab(),p=jb(),m=Mb(),h=_y();e.Composer=t.Composer,e.Document=n.Document,e.Schema=r.Schema,e.YAMLError=i.YAMLError,e.YAMLParseError=i.YAMLParseError,e.YAMLWarning=i.YAMLWarning,e.Alias=a.Alias,e.isAlias=o.isAlias,e.isCollection=o.isCollection,e.isDocument=o.isDocument,e.isMap=o.isMap,e.isNode=o.isNode,e.isPair=o.isPair,e.isScalar=o.isScalar,e.isSeq=o.isSeq,e.Pair=s.Pair,e.Scalar=c.Scalar,e.YAMLMap=l.YAMLMap,e.YAMLSeq=u.YAMLSeq,e.Lexer=d.Lexer,e.LineCounter=f.LineCounter,e.Parser=p.Parser,e.parse=m.parse,e.parseAllDocuments=m.parseAllDocuments,e.parseDocument=m.parseDocument,e.stringify=m.stringify,e.visit=h.visit,e.visitAsync=h.visitAsync})))();function Pb(e){let t=(0,Nb.parseDocument)(e),n=!1;function r(r){e=r,t=(0,Nb.parseDocument)(e),n=!1}function i(e,r){let i=e.length===1?t.contents:t.getIn(e.slice(0,-1));i||(i=t.createNode({}),t.setIn(e.slice(0,-1),i));let a=e[e.length-1],o=i.items.find(e=>typeof e.key==`string`?e.key===a:e.key.value===a),s=i.items.map(e=>typeof e.key==`string`?e.key:String(e.key.value));if(!o){let e=0;for(;e<s.length&&!(s[e].localeCompare(a)>0);e++);o=new Nb.Pair(a,r),i.items.splice(e,0,o),n=!0}else if((0,Nb.isAlias)(o.value)){let e=Fb(t,o.value);e&&e.value!==r&&(e.value=r,n=!0)}else!o.value||typeof o.value==`string`?o.value!==r&&(o.value=r,n=!0):o.value.value!==r&&(o.value.value=r,n=!0)}function a(e,n,r){let i=t.toJSON()||{},a=e==="default"?i.catalog?.[n]:i.catalogs?.[e]?.[n];if(a===r)return{conflicts:!1,newCatalogName:e,existingSpecifier:a};if(a){let t=Ib(r);return{conflicts:!0,existingSpecifier:a,newCatalogName:e==="default"?`conflicts_${n}_${t}`:`conflicts_${e}_${t}`}}return{conflicts:!1,newCatalogName:e}}function o(e,t,n){let{newCatalogName:r}=a(e,t,n);s(r,t,n)}function s(e,n,r){let a=t.toJSON()?.catalogs?.default!==void 0;i(e==="default"&&!a?[`catalog`,n]:[`catalogs`,e,n],r)}function c(e){let n=[],r=t.toJSON()||{};if(r.catalogs)for(let t of Object.keys(r.catalogs))r.catalogs[t]?.[e]&&n.push(t);return r.catalog&&r.catalog[e]&&n.push(`default`),n}return{getDocument(){return t},setContent:r,hasChanged:()=>n,toJSON:()=>t.toJSON(),toString:n=>{let r=e.split(`'`).length>=e.split(`"`).length;return t.toString({singleQuote:r,...n})},setPath:i,setPackage:s,setPackageNoConflicts:o,getPackageCatalogs:c,hasSpecifierConflicts:a}}function Fb(e,t){let n;return(0,Nb.visit)(e,{Scalar:(e,r,i)=>{r.anchor===t.source&&typeof r.value==`string`&&(n=r)}}),n}function Ib(e){return e.replace(/\^/g,`h`).replace(/~/g,`t`).replace(/\./g,`_`).replace(/</g,`l`).replace(/>/g,`g`).replace(/=/g,`e`).replace(/\*/g,`s`).replace(/@/g,`a`).replace(/\|/g,`p`).replace(/&/g,`n`).replace(/-/g,`m`).replace(/\+/g,`u`).replace(/\s/g,`_`)}function Lb(e){return e??=[],Array.isArray(e)?e:[e]}function Rb(e){return typeof e==`object`&&!!e&&`json`in e&&typeof e.json==`function`}function zb(e){if(Rb(e))return e.json();throw TypeError(`response does not implement json()`)}const Bb=3e4,Vb=`version-upgrade@npm node/${F.version}`,Hb=Object.assign((e,t)=>{let n=new Headers(t?.headers);return n.set(`user-agent`,Vb),cv(e,{...t,headers:n})},{preconnect:()=>{}});async function Ub(e,t,n,r){let i;for(let a=0;a<=r;a++)try{return await Promise.race([e(),new Promise((e,i)=>setTimeout(()=>i(/* @__PURE__ */ Error(`Timeout requesting "${t}" (attempt ${a+1}/${r+1})`)),n))])}catch(e){if(i=e instanceof Error?e:Error(String(e)),a<r){let e=Math.min(1e3*2**a,1e4);await new Promise(t=>setTimeout(t,e))}}throw i??Error(`Unexpected state: all retries exhausted for "${t}" but no error captured`)}async function Wb(e,t=!1,n,r=Bb,i=3){let a=await Ub(()=>Qg(e,{cwd:n,force:t,fetch:Hb,metadata:!0,throw:!1}),e,r,i);if(!qb(a))throw Error(`Invalid package metadata received for "${e}"`);let o=a;if(`error`in o)throw Error(`Failed to fetch package "${e}": ${o.error}`);return Kb(o)}async function Gb(e,t=Bb,n=3){let r=await Ub(()=>Hb(new URL(`${e}/meta.json`,`https://jsr.io/`),{headers:{accept:`application/json`}}).then(e=>zb(e)),e,t,n);if(!Jb(r))throw Error(`Invalid JSR package metadata received for "${e}"`);let i=r;return{versions:Object.keys(i.versions),tags:{latest:i.latest}}}function Kb(e){let t=Object.keys(e.versionsMeta),n=Object.fromEntries(Object.entries(e.versionsMeta).flatMap(([e,t])=>t.deprecated==null?[]:[[e,t.deprecated]])),r=Object.fromEntries(Object.entries(e.versionsMeta).map(([e,t])=>[e,t.engines?.node]).filter(([,e])=>e)),i=Object.fromEntries(Object.entries(e.versionsMeta).map(([e,t])=>[e,t.provenance]).filter(([,e])=>e)),a=Object.fromEntries(Object.entries(e.versionsMeta).map(([e,t])=>[e,t.integrity]).filter(([,e])=>e));return{tags:e.distTags,versions:t,time:{...Object.fromEntries(Object.entries(e.versionsMeta).filter(([,e])=>e.time).map(([e,t])=>[e,t.time])),created:e.timeCreated,modified:e.timeModified},nodeSemver:r,provenance:i,deprecated:Object.keys(n).length>0?n:void 0,integrity:a}}function qb(e){return typeof e==`object`&&!!e&&`versionsMeta`in e&&`distTags`in e}function Jb(e){return typeof e==`object`&&!!e&&`scope`in e&&`name`in e&&`latest`in e&&`versions`in e}let Yb=null;const Xb=()=>(Yb===null&&(Yb=md(`packages/version-upgrade/src/io/cache`)),Yb),Zb=(0,dm.default)(`version-upgrade:cache`);let Qb={},$b=!1;const ex=sm(s.tmpdir(),`version-upgrade`),tx=sm(ex,`cache.json`),nx=18e5;function rx(){return Date.now()}function ix(e){return rx()-e}async function ax(){E(tx)&&ix(D(tx).mtimeMs)<nx?(Zb(`cache loaded from ${tx}`),Qb=JSON.parse(await O.readFile(tx,`utf-8`))):Zb(`no cache found`)}async function ox(){if($b)try{await O.mkdir(ex,{recursive:!0}),await O.writeFile(tx,JSON.stringify(Qb),`utf-8`),Zb(`cache saved to ${tx}`)}catch(e){Xb().error(`Failed to save cache`,e instanceof Error?e:Error(String(e)))}}async function sx(e,t=`npm`,n,r,i){let a,o=`${t}:${e}`;if(Qb[o]){if(ix(Qb[o].cacheTime)<nx)return Zb(`cache hit for ${o}`),Qb[o].data;delete Qb[o]}try{let a=t===`jsr`?await Gb(e,r,i):await Wb(e,!1,n,r,i);if(a)return Qb[o]={data:a,cacheTime:rx()},$b=!0,a}catch(e){a=e}return{tags:{},versions:[],error:a instanceof Error&&a.message||String(a),deprecated:{}}}const cx=[`**/node_modules/**`,`**/dist/**`,`**/public/**`,`**/fixture/**`,`**/fixtures/**`];function lx(e,t=[]){if(!e)return{};let n={};for(let[r,i]of Object.entries(e))if(typeof i==`object`&&i){let e={};for(let[t,n]of Object.entries(i))e[t]=n;n={...n,...lx(e,[...t,r])}}else typeof i==`string`&&(n[r]={version:i,parents:t});return n}function ux(e,t){let n=t.split(`.`).reduce((e,t)=>{if(typeof e==`object`&&e){let n={};for(let[t,r]of Object.entries(e))n[t]=r;return n[t]}},e);if(typeof n==`object`&&n){let e={};for(let[t,r]of Object.entries(n))e[t]=r;return lx(e)}return{}}function dx(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))t[n]=r;return t}return{}}function fx(e,t,n){let r=t.split(`.`),i=r.pop();if(i===void 0)return;let a=e;for(let e of r){(typeof a[e]!=`object`||a[e]===null)&&(a[e]={});let t=dx(a[e]);a[e]=t,a=t}a[i]=n}function px(e,t,n){return Object.entries(ux(e,t)||{}).map(([e,{version:r,parents:i}])=>mx({name:e,version:r,type:t,shouldUpdate:n,parents:i}))}function mx({name:e,version:t,type:n,shouldUpdate:r,parents:i,hexHash:a}){let o={name:e,currentVersion:t,parents:i,source:n,update:r(e)};return a&&(o.hexHash=a),o}function hx(e,t){let n={};return e.filter(e=>e.source===t).sort((e,t)=>(e.aliasName||e.name).localeCompare(t.aliasName||t.name)).forEach(e=>{let t=e.update?e.targetVersion:e.currentVersion,r=n;if(e.parents&&e.parents.length>0){let t=n;for(let n of e.parents){(typeof t[n]!=`object`||t[n]===null)&&(t[n]={});let e=dx(t[n]);t[n]=e,t=e}r=t}if(e.aliasName===void 0)r[e.name]=t;else{let n=e.protocol?`${e.protocol}:`:``;r[e.aliasName]=`${n}${e.protocol===`jsr`?t:gx(e,t)}`}}),n}function gx(e,t){let n=t?`@${t}`:``;return`${e.name}${n}`}async function _x(e,t,n,r){let i=sm(t.cwd??``,e),a=r??JSON.parse(await ce(i,`utf-8`)),o=[];function s(t,r){let o=Object.entries(r).map(([e,t])=>mx({name:e,version:t,type:`bun-workspace`,shouldUpdate:n}));return{name:t,private:!0,version:``,type:`bun-workspace`,relative:e,filepath:i,raw:a,deps:o,resolved:[]}}let c=a?.workspaces;if(c&&typeof c==`object`){let e=bx(c);if(e.catalog&&typeof e.catalog==`object`&&o.push(s(`bun-catalog:default`,xx(e.catalog))),e.catalogs&&typeof e.catalogs==`object`){let t=Sx(e.catalogs);for(let e of Object.keys(t)){let n=t[e];n&&o.push(s(`bun-catalog:${e}`,n))}}}return o}async function vx(e,t){let n=hx(e.resolved,`bun-workspace`);if(Object.keys(n).length&&e.name.startsWith(`bun-catalog:`)){let t=e.name.replace(`bun-catalog:`,``),r=bx(e.raw.workspaces??{});if(e.raw.workspaces=r,t==="default")r.catalog={...xx(r.catalog??{}),...xx(n)};else{let e=Sx(r.catalogs??{});r.catalogs=e,e[t]||(e[t]={}),e[t]={...e[t],...xx(n)}}await yx(e.filepath,e.raw)}}async function yx(e,t){let n;try{n=_v(await ce(e,`utf-8`)).indent}catch{}let r=JSON.stringify(t,null,n||` `);await R(e,`${r}\n`,`utf-8`)}function bx(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))t[n]=r;return t}return{}}function xx(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))typeof r==`string`&&(t[n]=r);return t}return{}}function Sx(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))if(typeof r==`object`&&r&&!Array.isArray(r)){let e={};for(let[t,n]of Object.entries(r))typeof n==`string`&&(e[t]=n);t[n]=e}return t}return{}}let Cx=null;const wx=()=>(Cx===null&&(Cx=md(`packages/version-upgrade/src/addons/vscode`)),Cx);function Tx(e,t){if(typeof e==`object`&&e){for(let[n,r]of Object.entries(e))if(n===t&&typeof r==`string`)return r}}function Ex(e){if(e==null)return!1;let t=e.engines;return Tx(t,`vscode`)!==void 0}function Dx(e){for(let t of[`dependencies`,`devDependencies`,`peerDependencies`]){let n=Tx(e[t],`@types/vscode`);if(n!==void 0)return n}return``}const Ox=[{beforeWrite(e){if(!Ex(e.raw)||e.raw==null)return;let t=e.raw,n=Dx(t);if(!n||n.includes(`:`))return;let r=t.engines,i=Tx(r,`vscode`);if(!i)return;let a=hy(i),o=hy(n);if(a&&o&&Rv(o,a)){wx().info(`[taze addon] Updated VS Code engine field to ${n}`);let e=/[>^<:~]/.test(n)?n:`^${n}`;if(typeof r==`object`&&r){let n={};for(let[t,i]of Object.entries(r))n[t]=t===`vscode`?e:i;t.engines=n}}}}];function kx(e){return I.from(e.slice(7),`base64`).toString(`hex`)}function Ax(e){return typeof e==`object`&&!!e&&`version`in e&&typeof e.version==`string`}const jx=[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`,`packageManager`,`pnpm.overrides`,`resolutions`,`overrides`];function Mx(e,t){return t.depFields?.[e]===!1?!1:e!==`peerDependencies`||!!t.peer}async function Nx(e,t,n,r){let i=sm(t.cwd??``,e),a=r??await Qx(i),o=[];for(let e of jx)if(Mx(e,t)){if(e===`packageManager`){let e=a.packageManager;if(typeof e==`string`){let t=e.indexOf(`@`),r=t>0?e.slice(0,t):``,i=t>0?e.slice(t+1):``,a=i.indexOf(`+`),s=a>=0?i.slice(0,a):i,c=a>=0?i.slice(a+1):``,l=c.indexOf(`.`),u=l>=0?c.slice(l+1):void 0;o.push(mx({name:r,version:`^${s}`,type:`packageManager`,shouldUpdate:n,hexHash:u}))}}else o.push(...px(a,e,n))}let s=typeof a.name==`string`?a.name:``,c=typeof a.version==`string`?a.version:``;return[{name:s,private:!!a.private,version:c,type:`package.json`,relative:e,filepath:i,raw:a,deps:o,resolved:[]}]}async function Px(e,t){let n=!1;for(let r of jx)if(Mx(r,t)){if(r===`packageManager`){let t=Object.entries(hx(e.resolved,`packageManager`))[0];if(t){e.raw||={};let[r,i]=t,a=typeof i==`string`?i.replace(`^`,``):String(i),o=`${r}@${a}`,s=e.resolved.find(e=>e.source===`packageManager`&&e.name===r);if(s?.hexHash){let e=s.pkgData?.integrity?.[a];if(e){let t=kx(e);o=`${o}+sha512.${t}`}}e.raw.packageManager=o,n=!0}}else{let t=ux(e.raw,r),i=hx(e.resolved,r),a={};for(let[e,n]of Object.entries(t||{}))Ax(n)&&(a[e]=n.version);for(let[e,t]of Object.entries(i||{}))a[e]=t;Object.keys(a).length>0&&(fx(e.raw,r,a),n=!0)}}if(n){for(let n of t.addons||Ox)await n.beforeWrite?.(e,t);await $x(e.filepath,e.raw||{})}}const Fx=[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`,`packageManager`,`pnpm.overrides`,`resolutions`,`overrides`];function Ix(e,t){return e===`peerDependencies`?!!t.peer:t.depFields?.[e]!==!1}async function Lx(e){let t=await se.readFile(e,`utf-8`);if(!t)return new Nb.Document({});let n=(0,Nb.parseDocument)(t,{merge:!0}),r=n.toJS();if(n.errors.length||typeof r!=`object`||Array.isArray(r))throw TypeError(`Invalid package.yaml structure in ${e}`);return n}async function Rx(e,t){let{amount:n,type:r}=await se.readFile(e,`utf-8`).then(_v).catch(()=>({amount:2,type:`space`})),i=(0,Nb.stringify)(t,{indent:(r===`tab`?2:n)??2,aliasDuplicateObjects:!1,lineWidth:0}).replace(/^(\s*)"(@[^":]+)":/gm,`$1'$2':`);await se.writeFile(e,i,`utf-8`)}async function zx(e,t,n){let r=sm(t.cwd??``,e),i=await Lx(r),a=[];for(let e of Fx)if(Ix(e,t)){if(e===`packageManager`){let t=i.get(e);if(typeof t==`string`){let e=t.split(`@`),r=e[0]??``,i=(e[1]??``).split(`+`)[0];a.push(mx({name:r,version:`^${i??``}`,type:`packageManager`,shouldUpdate:n}))}}else{let t={},r=i.toJS();if(typeof r==`object`&&r&&!Array.isArray(r))for(let[e,n]of Object.entries(r))t[e]=n;a.push(...px(t,e,n))}}let o=i.get(`name`),s=i.get(`version`);return[{name:typeof o==`string`?o:``,private:!!i.get(`private`),version:typeof s==`string`?s:``,type:`package.yaml`,relative:e,filepath:r,get raw(){return i.toJS()},deps:a,yamlDocument:i,resolved:[]}]}async function Bx(e,t){let n=!1;if(e.type!==`package.yaml`)throw Error(`Package type is not supported`);let r=e.yamlDocument||new Nb.Document(e.raw);for(let i of Fx)if(Ix(i,t)){if(i===`packageManager`){let t=Object.entries(hx(e.resolved,`packageManager`))[0];if(t){let[e,i]=t,a=typeof i==`string`?i.replace(`^`,``):``;r.set(`packageManager`,`${e}@${a}`),n=!0}}else{let t=ux(Vx(r),i);t&&Object.keys(t).length>0&&(Object.entries(hx(e.resolved,i)).forEach(([e,t])=>r.setIn([...i.split(`.`),e],t)),n=!0)}}if(n){for(let n of t.addons||Ox)await n.beforeWrite?.(e,t);await Rx(e.filepath,r)}}function Vx(e){let t=e.toJS();if(typeof t==`object`&&t&&!Array.isArray(t)){let e={};for(let[n,r]of Object.entries(t))e[n]=r;return e}return{}}async function Hx(e,t,n){let r=sm(t.cwd??``,e),i=Pb(await ce(r,`utf-8`)),a=i.getDocument().toJSON(),o=[];function s(t,o){let s=Object.entries(o).map(([e,t])=>mx({name:e,version:t,type:`pnpm-workspace`,shouldUpdate:n}));return{name:t,private:!0,version:``,type:`pnpm-workspace.yaml`,relative:e,filepath:r,raw:a,context:i,deps:s,resolved:[]}}if(a?.catalog&&o.push(s(`pnpm-catalog:default`,a.catalog)),a?.catalogs)for(let e of Object.keys(a.catalogs))o.push(s(`pnpm-catalog:${e}`,a.catalogs[e]));return a?.overrides&&o.push(s(`pnpm-workspace:overrides`,a.overrides)),o}async function Ux(e,t){let n=hx(e.resolved,`pnpm-workspace`);if(Object.keys(n).length){if(e.name.startsWith(`pnpm-catalog:`)){let t=e.name.replace(`pnpm-catalog:`,``);for(let[r,i]of Object.entries(n))typeof i==`string`&&e.context.setPackage(t,r,i)}else{let t=e.name.replace(`pnpm-workspace:`,``).split(/\./g);for(let[r,i]of Object.entries(n))e.context.setPath([...t,r],i)}e.context.hasChanged()&&await Wx(e,e.context)}}function Wx(e,t){return R(e.filepath,t.toString(),`utf8`)}async function Gx(e,t,n){let r=sm(t.cwd??``,e),i=Pb(await ce(r,`utf-8`)),a=i.getDocument().toJSON(),o=[];function s(t,o){let s=Object.entries(o).map(([e,t])=>mx({name:e,version:t,type:`yarn-workspace`,shouldUpdate:n}));return{name:t,private:!0,version:``,type:`.yarnrc.yml`,relative:e,filepath:r,raw:a,context:i,deps:s,resolved:[]}}if(a?.catalog&&o.push(s(`yarn-catalog:default`,a.catalog)),a?.catalogs)for(let e of Object.keys(a.catalogs))o.push(s(`yarn-catalog:${e}`,a.catalogs[e]));return o}async function Kx(e,t){let n=hx(e.resolved,`yarn-workspace`);if(Object.keys(n).length){if(e.name.startsWith(`yarn-catalog:`)){let t=e.name.replace(`yarn-catalog:`,``);for(let[r,i]of Object.entries(n))typeof i==`string`&&e.context.setPackage(t,r,i)}else{let t=e.name.replace(`yarn-workspace:`,``).split(/\./g);for(let[r,i]of Object.entries(n))e.context.setPath([...t,r],i)}e.context.hasChanged()&&await qx(e,e.context)}}function qx(e,t){return R(e.filepath,t.toString(),`utf8`)}function Jx(e){return e.replace(/[.+?^${}()|[\]\\]/g,`\\$&`)}function Yx(e){if(e.startsWith(`/`)){let t=e.lastIndexOf(`/`),n=e.substring(1,t),r=e.substring(t+1,e.length);return new RegExp(n,r)}return RegExp(`^${Jx(e).replace(/\*+/g,`.*?`)}$`)}function Xx(e,t=!0){if(!e||e.length===0)return()=>t;let n=Lb(e).flatMap(e=>e.split(`,`)).map(Yx);return e=>{for(let t of n)if(t.test(e))return!0;return!1}}function Zx(e,t){let n=Xx(e,!0),r=Xx(t,!1);return e=>!r(e)&&n(e)}async function Qx(e){return JSON.parse(await O.readFile(e,`utf-8`))}async function $x(e,t){let n=_v(await O.readFile(e,`utf-8`)).indent||` `;await O.writeFile(e,`${JSON.stringify(t,null,n)}\n`,`utf-8`)}async function eS(e,t){switch(e.type){case`package.json`:return Px(e,t);case`package.yaml`:return Bx(e,t);case`pnpm-workspace.yaml`:return Ux(e,t);case`bun-workspace`:return vx(e,t);case`.yarnrc.yml`:return Kx(e,t);default:throw Error(`Unsupported package type: ${e.type}`)}}async function tS(e,t,n){if(e.endsWith(`pnpm-workspace.yaml`))return Hx(e,t,n);if(e.endsWith(`.yarnrc.yml`))return Gx(e,t,n);if(e.endsWith(`package.yaml`))return zx(e,t,n);if(e.endsWith(`package.json`)){let r=sm(t.cwd??``,e);try{let i=await Qx(r),a=i?.workspaces;if(a&&typeof a==`object`&&(`catalog`in a||`catalogs`in a)){let r=sm(t.cwd||F.cwd());if(E(am(r,`bun.lockb`))||E(am(r,`bun.lock`))){let r=await _x(e,t,n,i),a=await Nx(e,t,n,i);return[...r,...a]}}return Nx(e,t,n,i)}catch{}}return Nx(e,t,n)}async function nS(e){let t=[],n=sm(e.cwd||F.cwd()),r=Zx(e.include,e.exclude);if(e.recursive){let n=await Pp(`**/package.yaml`,{ignore:cx.concat(e.ignorePaths||[]),cwd:e.cwd,onlyFiles:!0,dot:!1,expandDirectories:!1}),r=await Pp(`**/package.json`,{ignore:cx.concat(e.ignorePaths||[]),cwd:e.cwd,onlyFiles:!0,dot:!1,expandDirectories:!1}),i=/* @__PURE__ */ new Set;for(let e of n){t.push(e);let n=um(e);i.add(n)}for(let e of r){let n=um(e);i.has(n)||t.push(e)}}else t=await Pp(`package.{yaml,json}`,{cwd:n});return t=t.sort((e,t)=>e.localeCompare(t)),e.ignoreOtherWorkspaces&&(t=(await Promise.all(t.map(async e=>{if(!e.includes(`/`))return[e];let t=am(n,e),r=bv(`.git`,{cwd:t,last:n});if(r&&um(r)!==n)return[];let i=bv(`pnpm-workspace.yaml`,{cwd:t,last:n});if(i&&um(i)!==n)return[];let a=bv(`.yarnrc.yml`,{cwd:t,last:n});if(a&&um(a)!==n)return[];let o=bv(`bun.lockb`,{cwd:t,last:n})||bv(`bun.lock`,{cwd:t,last:n});return o&&um(o)!==n?[]:[e]}))).flat()),E(am(n,`pnpm-workspace.yaml`))&&t.unshift(`pnpm-workspace.yaml`),E(am(n,`.yarnrc.yml`))&&t.unshift(`.yarnrc.yml`),(await Promise.all(t.map(t=>tS(t,e,r)))).flat()}const rS={error:-1,major:0,minor:1,patch:2,"":3};function iS(e){return e.sort((e,t)=>rS[e.diff||``]-rS[t.diff||``])}function aS(e,t){if(t.packageMode){for(let n of Object.keys(t.packageMode))if(Yx(n).test(e))return t.packageMode[n]}}function oS(e,t){let n=[];for(let r of Lb(t.maturityPeriodExclude).flatMap(e=>e.split(`,`))){let t=r.trim();if(!t)continue;let i=t.startsWith(`/`)?-1:t.lastIndexOf(`@`);if(!Yx(i>0?t.slice(0,i):t).test(e))continue;if(i<=0)return!0;let a=t.slice(i+1).split(`||`).map(e=>e.trim()).filter(Boolean);n.push(...a)}return n}function sS(e,t){for(let n of t)if(my(e,n,{includePrerelease:!0}))return!0;return!1}const cS=new P;function lS(e){return e.match(/(@[^/]+\/)?([^/]+)/g)||[]}function uS(e){return e.match(/[^>]+/g)||[]}function dS(e){return/^(?:https?:|git\+|github:)/.test(e)}function fS(e){return/^(?:link|file|workspace|catalog):/.test(e)}function pS(e){return/^(?:npm|jsr):/.test(e)}function mS(e){return e===`npm`?`npm`:e===`jsr`?`jsr`:`npm`}function hS(e){let t=e.indexOf(`:`),n=mS(e.slice(0,t)),r=e.slice(t+1);if(n===`npm`){let e=r.lastIndexOf(`@`);return e>0?{protocol:n,name:r.substring(0,e),version:r.substring(e+1)}:{protocol:n,name:r,version:``}}return{protocol:n,name:``,version:r}}function gS(e){let t=[`>=`,`<=`,`>`,`<`,`~`,`^`],n=e.trim();if(n===`*`||n===``)return`*`;if(n[0]===`~`||n[0]===`^`)return n[0];for(let e of t)if(n.startsWith(e))return e;if(n.includes(`x`)){let e=n.split(`.`);if(e[0]===`x`)return`*`;if(e[1]===`x`)return`^`;if(e[2]===`x`)return`~`}return n.length>0&&n.charCodeAt(0)>=48&&n.charCodeAt(0)<=57?``:null}function _S(e,t){if(!gy(e))return null;if(t==="default")return e;let n=hy(e);return n?{major:`>=`,minor:`^`,patch:`~`}[t]+n:null}function vS(e,t){return e==null||t==null?null:t===`*`?`*`:t+e}function yS(e,t){return vS(t,gS(e))}function bS(e,t,n,r){let i=null;if(n===`latest`){let t=r.latest;i=t!=null&&e.includes(t)?t:e.at(-1)??null}else if(n===`newest`)i=e.at(-1)??null;else if(n===`next`){let t=r.next;i=t!=null&&e.includes(t)?t:e.at(-1)??null}else if(n===`stable`){let n=_S(t,`default`);if(!n)return;e.filter(e=>!e.includes(`-`)).forEach(e=>{my(e,n)&&(!i||Rv(e,i))&&(i=e)})}else if(n==="default"&&(t===`*`||t.trim()===``))return;else{let a=_S(t,n);if(!a)throw Error(`invalid_range`);let o=r.latest??null;o&&!my(o,a)&&(o=null),e.forEach(e=>{my(e,a)&&(o&&!Vv(e,o)||i&&!Rv(e,i)||(i=e))})}if(i)return i}function xS(e,t){return e.filter(e=>!t[e])}function SS(e,t,n){if(!t||n<=0)return e;let r=/* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).getTime()-n*24*60*60*1e3);return e.filter(e=>{let n=t[e];return!n||new Date(n)<r})}function CS(e,t,n){let{tags:r}=e.pkgData,i=wS(e,n);if(i.length!==0)return e.filteredVersions=i,bS(i,e.currentVersion,t,r)}function wS(e,t){let{versions:n,deprecated:r,time:i}=e.pkgData,a=n;r&&Object.keys(r).length>0&&(a=xS(a,r));let o=oS(e.name,t);if(t.maturityPeriod&&t.maturityPeriod>0&&o!==!0){let e=a;if(a=SS(e,i,t.maturityPeriod),o.length>0){let t=new Set(a);a=e.filter(e=>t.has(e)||sS(e,o))}}return a}function TS(e,t,n){let r=CS(e,`latest`,n);return r&&Rv(r,t)?r:void 0}function ES(e,t,n=!0,r=!1){let i=/^\d+/.test(e.currentVersion);if(i&&!r)e.targetVersion=e.currentVersion,e.targetVersionTime=e.currentVersionTime,e.diff=null,e.update=!1;else{if(e.targetVersion=yS(e.currentVersion,t)||e.currentVersion,e.targetVersionTime=e.pkgData.time?.[t],e.currentProvenance=e.pkgData.provenance?.[e.currentVersion],e.targetProvenance=e.pkgData.provenance?.[e.targetVersion],e.provenanceDowngraded=!(!e.currentProvenance||e.targetProvenance)||e.currentProvenance===`trustedPublisher`&&e.targetProvenance===!0,i&&Lv(e.currentVersion,e.targetVersion)){let{versions:t,time:n={},tags:r}=e.pkgData,i=bS(e.filteredVersions??t,e.currentVersion,`minor`,r);i&&(e.targetVersion=i,e.targetVersionTime=n[e.targetVersion])}try{let t=hy(e.currentVersion),n=hy(e.targetVersion);if(!t||!n)throw Error(`invalid_version`);e.currentVersionTime=e.pkgData.time?.[t.toString()],e.diff=DS(t,n),e.update=e.diff!==null&&Bv(t,n)}catch(t){if(!n)throw t;e.targetVersion=e.currentVersion,e.diff=`error`,e.update=!1}}}function DS(e,t){if(Lv(e,t))return null;let n=my(t,`~${e}`,{includePrerelease:!0}),r=my(t,`^${e}`,{includePrerelease:!0}),i=my(t,`>=${e}`,{includePrerelease:!0});return n?r?`patch`:`major`:r?`minor`:i?`major`:`error`}function OS(e,t){return{...e,diff:null,targetVersion:e.currentVersion,update:!1,provenanceDowngraded:!1,pkgData:{tags:{},versions:[]},...t}}function kS(e){return e!=null&&e!==`ignore`?e:`default`}async function AS(e,t,n=()=>!0){let r={...e,diff:null,targetVersion:e.currentVersion,update:e.update,provenanceDowngraded:!1,pkgData:{tags:{},versions:[]}},i=aS(r.name,t),a=t.mode,o=i?i===a?a:a==="default"?i:`ignore`:a;if(fS(e.currentVersion)||dS(e.currentVersion)||!e.update||!await Promise.resolve(n(e))||o===`ignore`)return OS(e);if(pS(e.currentVersion)){let{name:t,version:n,protocol:i}=hS(e.currentVersion);if(r.name=t||r.name,r.currentVersion=n,r.aliasName=e.name,r.protocol=i,!n)return OS(e,{name:r.name,currentVersion:n,aliasName:e.name,protocol:i})}let s=r.name;r.source===`resolutions`?s=lS(r.name).pop()??r.name:r.source===`pnpm.overrides`&&(s=uS(r.name).pop()??r.name);let c=await sx(s,r.protocol,t.cwd,t.timeout,t.retries),{error:l,deprecated:u}=c;r.pkgData=c;let d=null,f;if(l==null)try{if(u&&typeof u==`object`&&r.currentVersion&&u[r.currentVersion])return OS(e,{name:r.name,currentVersion:r.currentVersion,aliasName:r.aliasName,protocol:r.protocol});if(f=CS(r,kS(o),t),!f)return OS(e,{name:r.name,currentVersion:r.currentVersion,aliasName:r.aliasName,protocol:r.protocol,pkgData:c})}catch(e){d=e instanceof Error?e.message:String(e)}else d=l;f?ES(r,f,void 0,t.includeLocked):r.targetVersion=r.currentVersion,r.targetVersion===r.currentVersion&&(r.diff=null,r.update=!1);try{let e=hy(f||r.targetVersion||``);e&&(r.latestVersionAvailable=TS(r,e,t));let{nodecompat:n=!0}=t;if(n){let t=F.version,{nodeSemver:n}=r.pkgData;if(n&&e?.version&&e?.version in n){let i=n[e.version];r.nodeCompatibleVersion={compatible:i!=null&&my(t,i),semver:i??``}}}}catch{}return d&&(r.diff=`error`,r.update=!1,r.resolveError=d),r}async function jS(e,t,n=()=>!0,r=()=>{}){let i=e.length,a=0,{concurrency:o=10}=t,s=cS.getStore()||qp(o);return Promise.all(e.map(e=>s.add(async()=>{let o=await AS(e,t,n);return a+=1,r(e.name,a,i),o})))}async function MS(e,t,n,r){let i=await jS(e.deps,t,n,(t,n,i)=>r?.(e.name,t,n,i));return iS(i),e.resolved=i,e}async function NS(e,t={}){e.force||await ax();let n=await nS(e);t.afterPackagesLoaded?.(n);let r=n.filter(e=>e.private).map(e=>e.name).filter(e=>e),i=e=>!r.includes(e.name),a=0,o=(e,n,r,i)=>{a++,t.onDependencyResolved?.(e,n,a,i)},s=qp(e.concurrency||10);return await cS.run(s,()=>Promise.all(n.map(async n=>{t.beforePackageStart?.(n),await PS(n,e,i,{...t,onDependencyResolved:o}),t.afterPackageEnd?.(n)}))),t.afterPackagesEnd?.(n),await ox(),{packages:n}}async function PS(e,t,n=()=>!0,r={}){await MS(e,t,n,r.onDependencyResolved);let{resolved:i}=e,a=i.filter(e=>e.update);return t.write&&a.length&&await Promise.resolve(r.beforePackageWrite?.(e))!==!1&&(await eS(e,t),r.afterPackageWrite?.(e)),e}function FS(e){return{ok:!0,value:e}}function IS(e){return{ok:!1,error:e}}const LS=/^[a-z][a-z0-9-]*$/,RS=[`edition-root`,`customer-root`,`single-repo`],zS=Ac([`high`,`normal`,`low`]),BS=Ac(RS),VS=/\S/,HS=yc({id:U().regex(LS,`范围 id 非法(应为小写字母开头的字母数字连字符)`),kind:BS,remotes:gc(U().regex(VS,`远程位置非法(不得为空串或纯空白)`)).default([]),tags:gc(U().regex(VS,`标签非法(不得为空串或纯空白)`)).default([]),priority:zS.default(`normal`),excludes:gc(U().min(1)).default([]),projectPriorities:Oc(U(),zS).default({})}).check(e=>{e.value.kind===`single-repo`&&(e.value.excludes.length>0&&e.issues.push({code:`custom`,input:e.value,path:[`excludes`],message:`single-repo 范围禁用 excludes(声明的即唯一项目,如需排除请改用 edition-root/customer-root)`}),Object.keys(e.value.projectPriorities).length>0&&e.issues.push({code:`custom`,input:e.value,path:[`projectPriorities`],message:`single-repo 范围禁用 projectPriorities(优先级直接设于 scope 级)`}))}),US=`scopes`,WS=/^[a-z][a-z0-9-]*\.scope\.ts$/;async function GS(e){let t=j(e,US);if(!E(t))return IS({code:`SCOPES_DIR_MISSING`,message:`声明域目录缺失:${t}(应为 project-registry 仓根下 ${US}/,含 *.scope.ts 声明文件)`});let n=A(t).filter(e=>WS.test(e)).sort((e,t)=>e<t?-1:1);if(n.length===0)return IS({code:`SCOPE_REGISTRY_EMPTY`,message:`范围声明域为空:${t}(无 *.scope.ts——范围消失属配置事故,如需清空请显式移除 registryRoot 配置)`});let r=/* @__PURE__ */ new Set,i=[];for(let e of n){let n=j(t,e),a=await import(N(n).href),o=HS.safeParse(a.default);if(!o.success){let e=o.error.issues[0];return IS({code:`SCOPE_DECLARATION_INVALID`,message:`范围声明结构非法:${n}(${e?.path.join(`.`)??``} ${e?.message??``})`})}let s=e.replace(/\.scope\.ts$/,``);if(o.data.id!==s)return IS({code:`SCOPE_ID_MISMATCH`,message:`范围 id 与文件名不一致:${n}(id=${o.data.id},应为 ${s}——命名即身份)`});if(r.has(o.data.id))return IS({code:`SCOPE_ID_CONFLICT`,message:`范围 id 重复:${o.data.id}(声明域内同 id 即同范围,不得重复声明)`});r.add(o.data.id),i.push(o.data)}return FS(i)}const KS=`LZI_PROJECT_REGISTRY_ROOT`,qS=`LZI_PROJECT_MARKDOWN_REGISTRY_ROOT`,JS=`LZI_PROJECT_SCOPE_ROOTS`,YS=`LZI_PROJECT_MARKDOWN_SCOPE_ROOTS`,XS=/^[a-z][a-z0-9-]*=\/\S+$/;function ZS(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e!==``)}function QS(e){let t=/* @__PURE__ */ new Map;for(let n of ZS(e)){if(!XS.test(n))return IS({message:`范围根映射段非法:${n}(应为 id=绝对路径 形态,id 为小写字母开头的字母数字连字符)`});let e=n.indexOf(`=`),r=n.slice(0,e),i=M(n.slice(e+1));if(t.has(r))return IS({message:`范围根映射 id 重复:${r}(同一范围不得重复映射)`});t.set(r,i)}return FS(t)}function $S(e,t,n,r){return e!==void 0&&t!==void 0&&e.trim()!==t.trim()?IS({code:`ACQUISITION_ENV_INVALID`,message:`环境变量双名冲突:${n} 与 ${r} 同时在场且值不一致(请统一使用新名 ${n})`,variables:[n,r]}):FS({value:e??t,variables:e===void 0?t===void 0?[]:[r]:[n]})}function eC(e=process.env){let t=$S(e[KS],e[qS],KS,qS);if(!t.ok)return IS(t.error);let n=$S(e[JS],e[YS],JS,YS);if(!n.ok)return IS(n.error);let r;if(n.value.value!==void 0){let e=QS(n.value.value);if(!e.ok)return IS({code:`ACQUISITION_ENV_INVALID`,message:e.error.message,variables:[...n.value.variables]});r=e.value}return FS({registryRoot:t.value.value===void 0?void 0:M(t.value.value.trim()),scopeRoots:r})}const tC=/^[A-Za-z0-9_][A-Za-z0-9._-]*$/;function nC(e,t){return e.name<t.name?-1:+(e.name>t.name)}function rC(e){return E(j(e,`.git`))}function iC(e,t){return t.get(e.id)}function aC(e,t,n,r){if(n.has(e.id))return IS({code:`SCOPE_ID_CONFLICT`,message:`范围 id 冲突:${e.id}(声明域内不得重复)`});n.add(e.id);let i=iC(e,t);return i===void 0?IS({code:`SCOPE_ROOT_UNMAPPED`,message:`范围根未映射:${e.id}(声明零本地路径,请在 .env 的 LZI_PROJECT_SCOPE_ROOTS 或 LZI_PROJECT_MARKDOWN_SCOPE_ROOTS 补 id=绝对路径 映射)`}):E(i)?FS({def:e,root:i,sourceId:r}):IS({code:`DIR_NOT_FOUND`,message:`范围根不存在:${i}(范围 ${e.id} 机内映射目标)`})}function oC(e,t){let n=[],r=[];for(let i of[...A(e.root,{withFileTypes:!0})].sort(nC)){if(i.name.startsWith(`.`))continue;if(!i.isDirectory()){r.push({scope:e.def.id,entry:i.name,reason:`ROOT_FILE`});continue}if(e.def.excludes.includes(i.name)){r.push({scope:e.def.id,entry:i.name,reason:`EXCLUDED`});continue}let a=j(e.root,i.name);t!==void 0&&M(a)===M(t)?r.push({scope:e.def.id,entry:i.name,reason:`EXCLUDED_PATH`}):!rC(a)||!tC.test(i.name)?r.push({scope:e.def.id,entry:i.name,reason:`NOT_A_REPO`}):n.push({scope:e.def.id,scopeKind:e.def.kind,priority:e.def.projectPriorities[i.name]??e.def.priority,sourceId:e.sourceId,project:i.name,path:a})}return{scope:e.def.id,scopeKind:e.def.kind,priority:e.def.priority,scopeRoot:e.root,sourceId:e.sourceId,projects:n,skipped:r}}function sC(e,t){let n=ee(e.root);return t!==void 0&&M(e.root)===M(t)||!rC(e.root)||!tC.test(n)?IS({code:`SCOPE_ROOT_INVALID`,message:`single-repo 范围根非法:${e.root}(应为含 .git 的合规项目目录,且不得为排除路径)`}):FS({scope:e.def.id,scopeKind:`single-repo`,priority:e.def.priority,scopeRoot:e.root,sourceId:e.sourceId,projects:[{scope:e.def.id,scopeKind:`single-repo`,priority:e.def.priority,sourceId:e.sourceId,project:n,path:e.root}]})}function cC(e,t,n){let r=[],i=[],a=/* @__PURE__ */ new Set,o=/* @__PURE__ */ new Map;for(let s of e){let e=aC(s,n.scopeRoots,a,n.sourceId);if(!e.ok)return IS(e.error);let c,l=[];if(s.kind===`single-repo`){let n=sC(e.value,t);if(!n.ok)return IS(n.error);c=n.value}else{let n=oC(e.value,t);c=n,l=n.skipped}for(let e of c.projects){let t=o.get(e.project);if(t!==void 0)return IS({code:`PROJECT_NAME_CONFLICT`,message:`项目名跨范围冲突:${e.project}(${t} 与 ${e.scope} 均含此名;归档平铺要求项目名全局唯一,可在后登记范围的 excludes 中显式排除)`});o.set(e.project,e.scope)}r.push(c),i.push(...l)}return r.sort((e,t)=>e.scope<t.scope?-1:+(e.scope>t.scope)),i.sort((e,t)=>e.scope===t.scope?e.entry<t.entry?-1:+(e.entry>t.entry):e.scope<t.scope?-1:1),FS({scopes:r,skipped:i})}const lC=l(ae);function uC(e){return typeof e==`object`&&!!e&&`stderr`in e}async function dC(e,t){try{let{stdout:n}=await lC(`git`,[`-C`,e,...t],{encoding:`utf8`});return{ok:!0,stdout:n.trim()}}catch(e){let t=uC(e)?e.stderr:void 0;return{ok:!1,stderr:typeof t==`string`?t:String(e)}}}function fC(e){return typeof e==`object`&&!!e}function pC(e){let t=j(e,`package.json`);if(!E(t))return{packageName:null,description:null};let n;try{n=JSON.parse(k(t,`utf8`))}catch{return{packageName:null,description:null}}if(!fC(n))return{packageName:null,description:null};let r=n.name,i=n.description;return{packageName:typeof r==`string`&&r!==``?r:null,description:typeof i==`string`&&i!==``?i:null}}async function mC(e){let t=await dC(e.path,[`rev-parse`,`--git-dir`]);if(!t.ok)return IS({code:`INSPECT_FAILED`,scope:e.scope,project:e.project,message:`仓库健康探测失败:${e.path}(${t.stderr})`});let n=await dC(e.path,[`remote`,`get-url`,`origin`]),r=n.ok&&n.stdout!==``?n.stdout:null,i=pC(e.path);return FS({scope:e.scope,scopeKind:e.scopeKind,priority:e.priority,sourceId:e.sourceId,project:e.project,projectPath:e.path,remoteUrl:r,packageName:i.packageName,description:i.description})}async function hC(e,t,n){let r=Math.max(1,Math.floor(t)),i=[],a=0;for(;a<e.length;){let t=e.slice(a,a+r),o=await Promise.all(t.map((e,t)=>n(e,a+t)));i.push(...o),a+=r}return i}async function gC(e={}){let t=eC(e.processEnv??process.env);if(!t.ok)return IS(t.error);let n=e.registryRoot??t.value.registryRoot;if(n===void 0)return IS({code:`ACQUISITION_ENV_INVALID`,message:`未定位 registry 仓根(请在 .env 配置 LZI_PROJECT_REGISTRY_ROOT 或显式传入 registryRoot)`});let r=await GS(n);if(!r.ok)return IS(r.error);let i=e.scopeRoots??t.value.scopeRoots??/* @__PURE__ */ new Map,a=e.scopeIds===void 0?void 0:new Set(e.scopeIds),o=a===void 0?[]:[...a].filter(e=>!r.value.some(t=>t.id===e));if(o.length>0)return IS({code:`SCOPE_SELECTOR_UNKNOWN`,message:`圈定的范围 id 不在声明域:${o.join(`、`)}(合法范围 id:${r.value.map(e=>e.id).join(`、`)})`});let s=r.value,c=[];if(a!==void 0){s=r.value.filter(e=>a.has(e.id));let e=s.filter(e=>!i.has(e.id)).map(e=>e.id);if(e.length>0)return IS({code:`SCOPE_ROOT_UNMAPPED`,message:`范围根未映射:${e.join(`、`)}(声明零本地路径,请在 .env 的 LZI_PROJECT_SCOPE_ROOTS 补 id=绝对路径 映射)`})}else if(s=r.value.filter(e=>i.has(e.id)),c=r.value.filter(e=>!i.has(e.id)).map(e=>e.id),s.length===0)return IS({code:`SCOPE_ROOT_UNMAPPED`,message:`范围根未映射:${r.value.map(e=>e.id).join(`、`)}(本机未配置任何范围根映射,请在 .env 的 LZI_PROJECT_SCOPE_ROOTS 补 id=绝对路径 映射)`});let l=cC(s,e.excludePath,{scopeRoots:i,sourceId:`scope-declarations`});if(!l.ok)return IS(l.error);let u=l.value.scopes.flatMap(e=>[...e.projects]),d=[],f=/* @__PURE__ */ new Map;if(e.inspect===!0){let e=await hC(u,16,async e=>mC(e));for(let t of e)t.ok?f.set(t.value.project,t.value):d.push({scope:t.error.scope,project:t.error.project,message:t.error.message})}let p=u.map(e=>{let t=f.get(e.project);return{scope:e.scope,scopeKind:e.scopeKind,priority:e.priority,sourceId:e.sourceId,project:e.project,path:e.path,remoteUrl:t?.remoteUrl??null,packageName:t?.packageName??null,description:t?.description??null}});return FS({registryRoot:n,scopes:l.value.scopes,projects:p,skipped:l.value.skipped,unmappedScopes:c,inspectFailures:d,inspected:e.inspect===!0})}const _C={RED:`\x1B[0;31m`,GREEN:`\x1B[0;32m`,YELLOW:`\x1B[1;33m`,BLUE:`\x1B[0;34m`,RESET:`\x1B[0m`};function vC(e){return e.map(e=>{if(typeof e==`string`)return e;if(e instanceof Error)return e.message;try{return JSON.stringify(e)}catch{return String(e)}}).join(` `)}function $(...e){process.stdout.write(`${vC(e)}\n`)}function yC(...e){process.stderr.write(`${vC(e)}\n`)}const bC=async()=>{let e=await Gp();return e?(e.source===`legacy-dev-tools`&&$(`提示: 经 lzi-dev.config.ts 共享读取依赖工具配置,建议补建 lzi-dependencies.config.ts`),e.config):($(`提示: 未找到配置文件 lzi-dependencies.config.ts,使用默认配置`),{})},xC=[`**/node_modules/**`,`**/oh_modules/**`,`**/target/**`,`**/dist/**`,`**/build/**`,`**/.turbo/**`],SC=e=>!e||e.length===0?xC:[...xC,...e],CC=vc({name:U().optional(),workspaces:fc().optional(),devDependencies:Oc(U(),U()).optional()}),wC=async()=>{let e=process.cwd();$(`正在扫描 ${e} 下的 package.json 文件...`);let t=null;try{let n=CC.safeParse(await Bun.file(`${e}/package.json`).json());t=n.success?n.data:null}catch{t=null}t===null&&($(`未找到可解析的 workspace 根 package.json,请在仓库根目录执行本命令`),process.exit(1));let n=await bC(),r=SC(n.hoisting?.ignorePaths),i=new Set(n.hoisting?.allowlist??[]),a=t.devDependencies??{},o=await Pp(`**/package.json`,{cwd:e,ignore:r,onlyFiles:!0,dot:!1}),s=0,c=[];for(let t of o){if(t===`package.json`)continue;let n=null;try{let r=CC.safeParse(await Bun.file(`${e}/${t}`).json());n=r.success?r.data:null}catch{n=null}if(n===null||n.workspaces!==void 0)continue;let r=n.devDependencies??{};if(Object.keys(r).length!==0){s+=1;for(let[o,s]of Object.entries(r)){let r=a[o];r===void 0||i.has(o)||c.push({packageName:n.name??t,relPath:re(e,`${e}/${t}`),dependency:o,subRange:s,rootRange:r,drifted:s!==r})}}}if($(`找到 ${s} 个子包,根声明开发依赖 ${Object.keys(a).length} 项`),c.length===0)$(`所有子包均未重复声明根已有的开发依赖`);else{$(`
|
|
321
321
|
以下子包重复声明根已有的开发依赖:`);for(let e of c){let t=e.drifted?` 版本漂移`:``;$(` ${e.packageName} ${e.relPath}`),$(` ${e.dependency} 子声明 ${e.subRange} 根声明 ${e.rootRange}${t}`)}$(`共 ${c.length} 处重复声明,处置口径见 ADR 0036`),process.exit(1)}},TC=vc({name:U().optional(),overrides:Oc(U(),fc()).optional(),pnpm:vc({overrides:Oc(U(),fc()).optional()}).optional(),resolutions:Oc(U(),fc()).optional()}),EC=e=>typeof e==`string`?e:`嵌套对象`,DC=async()=>{let e=process.cwd();$(`正在扫描 ${e} 下的 package.json 文件...`);let t=null;try{let n=TC.safeParse(await Bun.file(`${e}/package.json`).json());t=n.success?n.data:null}catch{t=null}t===null&&($(`未找到可解析的仓库根 package.json,请在仓库根目录执行本命令`),process.exit(1));let n=await bC(),r=SC(n.overrides?.ignorePaths),i=new Set(n.overrides?.allowlist??[]),a=await Pp(`**/package.json`,{cwd:e,ignore:r,onlyFiles:!0,dot:!1}),o=0,s=[];for(let t of a){let n=null;try{let r=TC.safeParse(await Bun.file(`${e}/${t}`).json());n=r.success?r.data:null}catch{n=null}if(n===null)continue;o+=1;let r=[[`overrides`,n.overrides??{}],[`pnpm.overrides`,n.pnpm?.overrides??{}],[`resolutions`,n.resolutions??{}]];for(let[a,o]of r)for(let[r,c]of Object.entries(o))i.has(r)||s.push({packageName:n.name??t,relPath:re(e,`${e}/${t}`),field:a,entry:r,value:EC(c)})}if($(`扫描到 ${o} 个清单,登记豁免条目 ${i.size} 项`),s.length===0)$(`全部清单均未声明未豁免的 overrides 族强制版本字段`);else{$(`
|
|
322
|
-
以下清单声明了未豁免的 overrides 族强制版本字段:`);for(let e of s)$(` ${e.packageName} ${e.relPath}`),$(` ${e.field} ${e.entry} ${e.value}`);$(`共 ${s.length} 处强制版本条目,处置口径见 ADR 0153,豁免须经特别申请登记于 lzi-dependencies.config.ts 的 overrides.allowlist`),process.exit(1)}},OC=/* @__PURE__ */ new Set(/* @__PURE__ */ `@longzai-intelligence-agent-tools.@longzai-intelligence-api.@longzai-intelligence-builder.@longzai-intelligence-bun.@longzai-intelligence-changelog.@longzai-intelligence-decision.@longzai-intelligence-dependencies.@longzai-intelligence-dev-tools.@longzai-intelligence-env.@longzai-intelligence-features.@longzai-intelligence-git.@longzai-intelligence-issues.@longzai-intelligence-ledger.@longzai-intelligence-markdown.@longzai-intelligence-oxfmt.@longzai-intelligence-oxlint.@longzai-intelligence-release.@longzai-intelligence-screenshots.@longzai-intelligence-shared-config.@longzai-intelligence-standards.@longzai-intelligence-taro.@longzai-intelligence-tsconfig.@longzai-intelligence-tsgo.@longzai-intelligence-typescript.@longzai-intelligence-version.@longzai-intelligence-vitest.@longzai-intelligence-vscode.@longzai-intelligence-changeset.@longzai-intelligence-cli.@longzai-intelligence-config.@longzai-intelligence-deploy.@longzai-intelligence-dimensions.@longzai-intelligence-docs.@longzai-intelligence-findings.@longzai-intelligence-git-commit.@longzai-intelligence-git-swarm.@longzai-intelligence-lint.@longzai-intelligence-mechanisms.@longzai-intelligence-npm-registry.@longzai-intelligence-pitfalls.@longzai-intelligence-port.@longzai-intelligence-prettier.@longzai-intelligence-project-registry.@longzai-intelligence-readme.@longzai-intelligence-records.@longzai-intelligence-reflections.@longzai-intelligence-remote-machine.@longzai-intelligence-runtime.@longzai-intelligence-runtime-registry.@longzai-intelligence-scripts.@longzai-intelligence-specs.@longzai-intelligence-testing.@longzai-intelligence-toolchain.@longzai-intelligence-tsdoc.@longzai-intelligence-vite.@longzai-intelligence-wifi.@longzai-intelligence-growth.@longzai-intelligence-inbox.@longzai-intelligence-kol.@longzai-intelligence-one-digest.@longzai-intelligence-code-report.@longzai-intelligence-competition-registry.@longzai-intelligence-journals.@longzai-intelligence-music-video.@longzai-intelligence-nation.@longzai-intelligence-paper-report.@longzai-intelligence-closed-loop-markdown.@longzai-intelligence-crossref-markdown.@longzai-intelligence-disk-space-markdown.@longzai-intelligence-github-trending-markdown.@longzai-intelligence-input-markdown.@longzai-intelligence-journals-markdown.@longzai-intelligence-kol-markdown.@longzai-intelligence-knowledge-markdown.@longzai-intelligence-okr-markdown.@longzai-intelligence-open-router-markdown.@longzai-intelligence-philosophy-markdown.@longzai-intelligence-project-markdown.@longzai-intelligence-roadmap-markdown.@longzai-intelligence-rss-markdown.@longzai-intelligence-schedule-markdown.@longzai-intelligence-task-markdown.@longzai-intelligence-workflow-markdown.@longzai-intelligence-bilibili-markdown-private.@longzai-intelligence-douyin-markdown-private.@longzai-intelligence-law-markdown-private.@longzai-intelligence-release-workflow-private.@longzai-intelligence-research-report-markdown-private.@longzai-intelligence-research-report-private.@longzai-intelligence-runtime-registry-private.@longzai-intelligence-strategy-consulting-markdown-private.@longzai-intelligence-twitter-markdown-private.@longzai-intelligence-xiaohongshu-markdown-private.@longzai-intelligence-youtube-markdown-private.@longzai-intelligence-youtube-private`.split(`.`)),kC=[`dependencies`,`devDependencies`],AC=e=>{if(!e.startsWith(`@longzai-intelligence-`))return null;let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)},jC=(e,t)=>{if(e.workspaces===void 0)return{inScope:!1,violations:[]};let n=[];for(let r of kC){let i=e[r]??{};for(let[e]of Object.entries(i)){let i=AC(e);i===null||t.has(e)||OC.has(i)||n.push({dependency:e,field:r})}}return{inScope:!0,violations:n}},MC=`@longzai-intelligence`,NC=vc({workspaces:fc().optional(),dependencies:Oc(U(),U()).optional(),devDependencies:Oc(U(),U()).optional()}),PC=async()=>{let e=await FC(),t=process.env.npm_config_registry;process.env.npm_config_registry=`https://registry.npmjs.org/`;let n;try{n=await LC(void 0)}finally{t===void 0?delete process.env.npm_config_registry:process.env.npm_config_registry=t}let r=RC(n);$(`
|
|
323
|
-
--- 检查结果 ---`);let i=0;if(i+=
|
|
324
|
-
--- 根清单依赖准入 ---`),t.violations.length===0)return $(`工作区根清单未发现业务依赖`),0;for(let e of t.violations)$(` ${e.dependency} ${e.field}`);return $(`共 ${t.violations.length} 处业务依赖出现在工作区根清单,业务依赖应下沉到实际使用的子包,处置口径见 ADR 0182`),t.violations.length},
|
|
325
|
-
`).map(e=>e.trim()).filter(e=>e.length>0).filter(t=>E(j(e,t)))]:[`package.json`]},
|
|
326
|
-
--- 检查结果 ---`);for(let e of o){let t=e.resolved.filter(e=>e.update);if(t.length>0){s+=t.length,$(`\n${e.name||e.relative}:`);for(let e of t){let t=e.diff??``;$(` ${e.name}: ${e.currentVersion} -> ${e.targetVersion} (${t})`)}}}s===0?$(`所有依赖已是最新版本`):($(`\n共发现 ${s} 个可更新依赖`),e.write?$(`已写入 package.json`):$(`使用 --write 参数写入 package.json`))};function
|
|
322
|
+
以下清单声明了未豁免的 overrides 族强制版本字段:`);for(let e of s)$(` ${e.packageName} ${e.relPath}`),$(` ${e.field} ${e.entry} ${e.value}`);$(`共 ${s.length} 处强制版本条目,处置口径见 ADR 0153,豁免须经特别申请登记于 lzi-dependencies.config.ts 的 overrides.allowlist`),process.exit(1)}},OC=/* @__PURE__ */ new Set(/* @__PURE__ */ `@longzai-intelligence-agent-tools/cli.@longzai-intelligence-agent-tools/config.@longzai-intelligence-api/cli.@longzai-intelligence-api/config.@longzai-intelligence-api/core.@longzai-intelligence-builder/cli.@longzai-intelligence-builder/config.@longzai-intelligence-builder/core.@longzai-intelligence-builder/dual.@longzai-intelligence-builder/esm.@longzai-intelligence-builder/utils.@longzai-intelligence-bun/cli.@longzai-intelligence-bun/config.@longzai-intelligence-bun/presets.@longzai-intelligence-changelog/cli.@longzai-intelligence-changelog/config.@longzai-intelligence-decision/cli.@longzai-intelligence-decision/config.@longzai-intelligence-dependencies/cli.@longzai-intelligence-dependencies/config.@longzai-intelligence-dev-tools/cli.@longzai-intelligence-dev-tools/config.@longzai-intelligence-dev-tools/port-registry.@longzai-intelligence-dev-tools/vite-plugin.@longzai-intelligence-env/cli.@longzai-intelligence-env/config.@longzai-intelligence-env/core.@longzai-intelligence-features/cli.@longzai-intelligence-features/config.@longzai-intelligence-features/ledger.@longzai-intelligence-git/cli.@longzai-intelligence-git/config.@longzai-intelligence-issues/cli.@longzai-intelligence-issues/config.@longzai-intelligence-ledger/cli.@longzai-intelligence-ledger/config.@longzai-intelligence-ledger/core.@longzai-intelligence-markdown/cli.@longzai-intelligence-markdown/config.@longzai-intelligence-oxfmt/config.@longzai-intelligence-oxlint/architecture-core-plugin.@longzai-intelligence-oxlint/architecture-domain-plugin.@longzai-intelligence-oxlint/architecture-electron-plugin.@longzai-intelligence-oxlint/architecture-library-plugin.@longzai-intelligence-oxlint/architecture-plugin.@longzai-intelligence-oxlint/cli.@longzai-intelligence-oxlint/code-style-plugin.@longzai-intelligence-oxlint/composer-plugin.@longzai-intelligence-oxlint/core.@longzai-intelligence-oxlint/design-rules-plugin.@longzai-intelligence-oxlint/elysia-route-plugin.@longzai-intelligence-oxlint/eslint-config-plugin.@longzai-intelligence-oxlint/file-naming-plugin.@longzai-intelligence-oxlint/lzi-builder-config-plugin.@longzai-intelligence-oxlint/lzi-config-plugin.@longzai-intelligence-oxlint/nestjs-route-plugin.@longzai-intelligence-oxlint/oxlint-config.@longzai-intelligence-oxlint/package-json-plugin.@longzai-intelligence-oxlint/perfectionist-plugin.@longzai-intelligence-oxlint/presets.@longzai-intelligence-oxlint/react-plugin.@longzai-intelligence-oxlint/schema-type-separation-plugin.@longzai-intelligence-oxlint/stylistic-plugin.@longzai-intelligence-oxlint/testing.@longzai-intelligence-oxlint/tsconfig-plugin.@longzai-intelligence-oxlint/tsdoc-plugin.@longzai-intelligence-oxlint/tsdown-config-plugin.@longzai-intelligence-oxlint/tsup-config-plugin.@longzai-intelligence-oxlint/typeorm-plugin.@longzai-intelligence-oxlint/typescript-eslint-plugin.@longzai-intelligence-oxlint/utils.@longzai-intelligence-oxlint/vitest-config-plugin.@longzai-intelligence-oxlint/zod-plugin.@longzai-intelligence-release/cli.@longzai-intelligence-release/config.@longzai-intelligence-screenshots/cli.@longzai-intelligence-screenshots/config.@longzai-intelligence-screenshots/ledger.@longzai-intelligence-shared-config/core.@longzai-intelligence-standards/cli.@longzai-intelligence-standards/config.@longzai-intelligence-taro/cli.@longzai-intelligence-tsconfig/cli.@longzai-intelligence-tsconfig/config.@longzai-intelligence-tsconfig/core.@longzai-intelligence-tsgo/cli.@longzai-intelligence-typescript/bun-config.@longzai-intelligence-typescript/resolve-aliases.@longzai-intelligence-version/cli.@longzai-intelligence-version/config.@longzai-intelligence-vitest/config.@longzai-intelligence-vscode/cli.@longzai-intelligence-vscode/config.@longzai-intelligence-changeset/core.@longzai-intelligence-cli/core.@longzai-intelligence-cli/standard.@longzai-intelligence-config/cli.@longzai-intelligence-config/core.@longzai-intelligence-config/registry.@longzai-intelligence-deploy/cli.@longzai-intelligence-deploy/config.@longzai-intelligence-dimensions/cli.@longzai-intelligence-dimensions/config.@longzai-intelligence-dimensions/core.@longzai-intelligence-docs/cli.@longzai-intelligence-docs/compile-plugin.@longzai-intelligence-docs/config.@longzai-intelligence-docs/core.@longzai-intelligence-docs/eslint-plugin-markdown-links.@longzai-intelligence-docs/numbering-plugin.@longzai-intelligence-findings/cli.@longzai-intelligence-findings/config.@longzai-intelligence-findings/ledger.@longzai-intelligence-git-commit/cli.@longzai-intelligence-git-commit/config.@longzai-intelligence-git-swarm/cli.@longzai-intelligence-git-swarm/config.@longzai-intelligence-lint/cli.@longzai-intelligence-mechanisms/cli.@longzai-intelligence-mechanisms/config.@longzai-intelligence-mechanisms/core.@longzai-intelligence-npm-registry/cli.@longzai-intelligence-npm-registry/config.@longzai-intelligence-pitfalls/cli.@longzai-intelligence-pitfalls/config.@longzai-intelligence-pitfalls/ledger.@longzai-intelligence-port/cli.@longzai-intelligence-port/core.@longzai-intelligence-port/registry.@longzai-intelligence-prettier/config.@longzai-intelligence-prettier/markdown-plugin.@longzai-intelligence-project-registry/core.@longzai-intelligence-readme/cli.@longzai-intelligence-readme/config.@longzai-intelligence-readme/core.@longzai-intelligence-records/cli.@longzai-intelligence-records/config.@longzai-intelligence-records/ledger.@longzai-intelligence-reflections/cli.@longzai-intelligence-reflections/config.@longzai-intelligence-reflections/ledger.@longzai-intelligence-remote-machine/config.@longzai-intelligence-runtime-registry/cli.@longzai-intelligence-runtime/cli.@longzai-intelligence-runtime/config.@longzai-intelligence-scripts/cli.@longzai-intelligence-scripts/config.@longzai-intelligence-scripts/core.@longzai-intelligence-specs/cli.@longzai-intelligence-specs/config.@longzai-intelligence-specs/ledger.@longzai-intelligence-testing/cli.@longzai-intelligence-testing/config.@longzai-intelligence-testing/registry.@longzai-intelligence-toolchain/cli.@longzai-intelligence-toolchain/config.@longzai-intelligence-tsdoc/cli.@longzai-intelligence-tsdoc/config.@longzai-intelligence-vite/cli.@longzai-intelligence-wifi/cli.@longzai-intelligence-wifi/config.@longzai-intelligence-growth/cli.@longzai-intelligence-growth/config.@longzai-intelligence-growth/core.@longzai-intelligence-inbox/cli.@longzai-intelligence-inbox/config.@longzai-intelligence-inbox/core.@longzai-intelligence-kol/cli.@longzai-intelligence-kol/config.@longzai-intelligence-kol/core.@longzai-intelligence-one-digest/cli.@longzai-intelligence-one-digest/config.@longzai-intelligence-one-digest/core.@longzai-intelligence-closed-loop-markdown/cli.@longzai-intelligence-closed-loop-markdown/config.@longzai-intelligence-code-report/config.@longzai-intelligence-competition-registry/registry.@longzai-intelligence-crossref-markdown/cli.@longzai-intelligence-crossref-markdown/config.@longzai-intelligence-disk-space-markdown/config.@longzai-intelligence-github-trending-markdown/cli.@longzai-intelligence-github-trending-markdown/config.@longzai-intelligence-input-markdown/cli.@longzai-intelligence-input-markdown/config.@longzai-intelligence-journals-markdown/cli.@longzai-intelligence-journals-markdown/config.@longzai-intelligence-journals/config.@longzai-intelligence-knowledge-markdown/cli.@longzai-intelligence-knowledge-markdown/config.@longzai-intelligence-kol-markdown/cli.@longzai-intelligence-kol-markdown/config.@longzai-intelligence-music-video/config.@longzai-intelligence-nation/config.@longzai-intelligence-okr-markdown/config.@longzai-intelligence-open-router-markdown/cli.@longzai-intelligence-open-router-markdown/config.@longzai-intelligence-paper-report/cli.@longzai-intelligence-paper-report/config.@longzai-intelligence-philosophy-markdown/config.@longzai-intelligence-project-markdown/config.@longzai-intelligence-roadmap-markdown/config.@longzai-intelligence-rss-markdown/cli.@longzai-intelligence-rss-markdown/config.@longzai-intelligence-schedule-markdown/config.@longzai-intelligence-task-markdown/config.@longzai-intelligence-workflow-markdown/config.@longzai-intelligence-bilibili-markdown-private/cli.@longzai-intelligence-bilibili-markdown-private/config.@longzai-intelligence-douyin-markdown-private/cli.@longzai-intelligence-douyin-markdown-private/config.@longzai-intelligence-law-markdown-private/cli.@longzai-intelligence-law-markdown-private/config.@longzai-intelligence-release-workflow-private/publish-repository-plugin.@longzai-intelligence-release-workflow-private/workflow-repository-plugin.@longzai-intelligence-research-report-markdown-private/cli.@longzai-intelligence-research-report-markdown-private/config.@longzai-intelligence-research-report-private/core.@longzai-intelligence-runtime-registry-private/data.@longzai-intelligence-strategy-consulting-markdown-private/cli.@longzai-intelligence-strategy-consulting-markdown-private/config.@longzai-intelligence-twitter-markdown-private/cli.@longzai-intelligence-twitter-markdown-private/config.@longzai-intelligence-xiaohongshu-markdown-private/cli.@longzai-intelligence-xiaohongshu-markdown-private/config.@longzai-intelligence-youtube-markdown-private/cli.@longzai-intelligence-youtube-markdown-private/config.@longzai-intelligence-youtube-private/config.@longzai-intelligence-zhihu-markdown-private/config`.split(`.`)),kC=[`dependencies`,`devDependencies`],AC=(e,t)=>{if(e.workspaces===void 0)return{inScope:!1,violations:[]};let n=[];for(let r of kC){let i=e[r]??{};for(let[e]of Object.entries(i))e.startsWith(`@longzai-intelligence-`)&&!t.has(e)&&(OC.has(e)||n.push({dependency:e,field:r}))}return{inScope:!0,violations:n}},jC=`@longzai-intelligence`,MC=vc({workspaces:fc().optional(),dependencies:Oc(U(),U()).optional(),devDependencies:Oc(U(),U()).optional()}),NC=async()=>{let e=await PC(),t=process.env.npm_config_registry;process.env.npm_config_registry=`https://registry.npmjs.org/`;let n;try{n=await IC(void 0)}finally{t===void 0?delete process.env.npm_config_registry:process.env.npm_config_registry=t}let r=LC(n);$(`
|
|
323
|
+
--- 检查结果 ---`);let i=0;if(i+=RC(n,new Set(r),!1),r.length>0){$(`\n回退基线:${r.length} 个内部包在 npm 无记录,按本机 registry 配置复查`);let e=await IC(r);i+=RC(e,new Set(r),!0)}i===0?$(`全部 Longzai Intelligence 包依赖均为最新版`):yC(`\n共 ${i} 个内部包依赖非最新版,修复指引: 在仓根执行 lzi-dependencies upgrade --write 或 bun run version:upgrade`);let a=e+i;a!==0&&process.exit(Math.min(a,255))},PC=async()=>{let e=null;try{let t=MC.safeParse(await Bun.file(`${process.cwd()}/package.json`).json());e=t.success?t.data:null}catch{e=null}if(e===null)return 0;let t=AC(e,await FC());if(!t.inScope)return 0;if($(`
|
|
324
|
+
--- 根清单依赖准入 ---`),t.violations.length===0)return $(`工作区根清单未发现业务依赖`),0;for(let e of t.violations)$(` ${e.dependency} ${e.field}`);return $(`共 ${t.violations.length} 处业务依赖出现在工作区根清单,业务依赖应下沉到实际使用的子包,处置口径见 ADR 0182`),t.violations.length},FC=async()=>{let e=await bC();return new Set(e.rootManifest?.allowlist??[])},IC=async e=>{let t=(await bC()).upgrade??{},{packages:n}=await NS({cwd:process.cwd(),mode:`latest`,write:!1,recursive:t.recursive??!0,timeout:t.timeout??3e4,retries:t.retries??3,exclude:t.exclude??[],include:e===void 0?t.include??[]:[...e],depFields:t.depFields,ignorePaths:t.ignorePaths??[],concurrency:t.concurrency??10,force:!1,all:!1,install:!1,update:!1,interactive:!1,group:!0,includeLocked:!1,timediff:!0,nodecompat:!0,loglevel:`silent`,silent:!0,failOnOutdated:!1},{afterPackagesLoaded:e=>{$(`扫描到 ${e.length} 个包,正在校验 Longzai Intelligence 依赖新鲜度...`)}});return n},LC=e=>{let t=/* @__PURE__ */ new Set;for(let n of e)for(let e of n.resolved)e.name.startsWith(jC)&&e.resolveError!=null&&t.add(e.name);return[...t]},RC=(e,t,n)=>{let r=0;for(let i of e){let e=i.resolved.filter(e=>!e.update||!e.name.startsWith(jC)?!1:n?t.has(e.name):!t.has(e.name));if(e.length!==0){r+=e.length,$(`\n${i.name||i.relative}:`);for(let t of e){let e=t.diff??``,r=n?`,回退基线`:``;$(` ${t.name}: ${t.currentVersion} -> ${t.targetVersion} ${e}${r}`)}}}return r};function zC(e){let t=e;for(;;){if(E(j(t,`longzai-intelligence-globals`))||E(j(t,`lzi-architecture.yaml`)))return t;let e=j(t,`..`);if(e===t)return;t=e}}function BC(e){return e.filter(e=>E(j(e.path,`package.json`))).map(e=>({name:e.project,dir:e.path}))}async function VC(e){if(e.projectScope!==void 0){let t=await gC({scopeIds:[e.projectScope]});return t.ok||(yC(`错误: 项目范围解析失败: ${t.error.message}`),yC(`提示: 请确认 .env 配置 LZI_PROJECT_REGISTRY_ROOT 与 LZI_PROJECT_SCOPE_ROOTS`),process.exit(1)),{registryRoot:t.value.registryRoot,scopeId:e.projectScope,projects:BC(t.value.projects),source:`env`}}let t=zC(e.cwd??process.cwd());t===void 0&&(yC(`错误: 未定位产品群聚合根(一级子目录应存在 longzai-intelligence-globals 仓)`),yC(`提示: 请自产品群内任意仓库运行,或使用 --project-scope <id> 显式圈定范围`),process.exit(1));let n=ee(t),r=j(t,`longzai-intelligence-project-registry`);E(j(r,`scopes`))||(yC(`错误: registry 声明域缺失: ${j(r,`scopes`)}`),yC(`提示: 请确认 longzai-intelligence-project-registry 仓已在聚合根就位`),process.exit(1));let i=await gC({registryRoot:r,scopeIds:[n],scopeRoots:/* @__PURE__ */ new Map([[n,t]])});return i.ok||(yC(`错误: 项目范围解析失败: ${i.error.message}`),process.exit(1)),{registryRoot:r,scopeId:n,projects:BC(i.value.projects),source:`structure`}}const HC=(e,t)=>Bun.spawnSync([`git`,`diff`,`--quiet`,`HEAD`,`--`,t],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,UC=e=>{let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`("${t}/[^"]+":\\s*")[^"]*(")`,`g`)},WC=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),GC=e=>/^[~^]?\d/.test(e),KC=(e,t)=>`${/^[~^]/.exec(e)?.[0]??``}${t}`,qC=e=>{let t=Bun.spawnSync([`git`,`ls-files`,`--`,`*/package.json`],{cwd:e,stdout:`pipe`,stderr:`pipe`});return t.exitCode===0?[`package.json`,...(t.stdout?.toString()??``).trim().split(`
|
|
325
|
+
`).map(e=>e.trim()).filter(e=>e.length>0).filter(t=>E(j(e,t)))]:[`package.json`]},JC=(e,t,n)=>Bun.spawnSync([`git`,`commit`,...t,`-m`,n],{cwd:e,stdout:`pipe`,stderr:`pipe`}).exitCode===0,YC=async(e,t,n)=>{let r=await Bun.file(e).text(),i=[],a=[],o=[],s;for(t.lastIndex=0;(s=t.exec(r))!==null;){let e=s[0],t=s[1]??``,r=s[2]??``,i=/^"([^"]+)"/.exec(t)?.[1]??``,a=e.slice(t.length,e.length-r.length),c=n(i,a);a!==c&&GC(a)&&o.push({name:i,oldVersion:a,targetVersion:c,prefix:t,suffix:r})}if(o.length===0)return{matchedPackages:i,changes:a};let c=r;for(let e of o){let t=RegExp(`("${WC(e.name)}":\\s*")[^"]*(")`);c=c.replace(t,`$1${e.targetVersion}$2`),i.push(e.name),a.push({name:e.name,from:e.oldVersion,to:e.targetVersion})}return await Bun.write(e,c),{matchedPackages:i,changes:a}},XC=async(e,t,n)=>{let r=await Bun.file(e).text(),i=[],a=[];t.lastIndex=0;let o;for(;(o=t.exec(r))!==null;){let e=o[0],t=o[1]??``,r=o[2]??``,s=/^"([^"]+)"/.exec(t)?.[1]??``,c=e.slice(t.length,e.length-r.length),l=n(s,c);c!==l&&GC(c)&&(i.push(s),a.push({name:s,from:c,to:l}))}return{matchedPackages:i,changes:a}},ZC=async(e,t,n,r,i)=>{let{name:a,dir:o}=e,s=qC(o),c=[],l=[],u=[],d=[];for(let e of s){let r=j(o,e),a=await XC(r,t,n);if(a.matchedPackages.length!==0){if(!HC(o,e))u.push(e);else{if(i)c.push(...a.matchedPackages),l.push(...a.changes);else{let e=await YC(r,t,n);c.push(...e.matchedPackages),l.push(...e.changes)}d.push(e)}}}return d.length===0?u.length>0?{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`skipped-dirty`,reason:`package.json 已有未提交改动:${u.join(`,`)}`}:{name:a,dir:o,matchedPackages:c,changes:l,status:`skipped-nochange`,reason:`无匹配 scope 或已是目标版本`}:i||JC(o,d,r)?{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`success`}:{name:a,dir:o,matchedPackages:c,changes:l,skippedFiles:u,status:`failed`,reason:`git commit 失败,文件已修改,需人工介入`}},QC=async(e,t)=>{let n=/* @__PURE__ */ new Set;for(let r of e){let e=qC(r.dir);for(let i of e){let e=j(r.dir,i),a=await Bun.file(e).text();t.lastIndex=0;let o;for(;(o=t.exec(a))!==null;){let e=o[1]??``,t=/^"([^"]+)"/.exec(e)?.[1];t&&n.add(t)}}}return[...n]},$C=async(e,t)=>{let n=/* @__PURE__ */ new Map,r=[],i=0,a=async e=>{let t=await sx(e),i=t.tags?.latest;if(i===void 0){let n=t.error instanceof Error?t.error.message:t.error??`未找到 dist-tags.latest`;r.push({name:e,reason:n})}else n.set(e,i)},o=async()=>{for(;i<e.length;){let t=e[i];i++,t!==void 0&&await a(t)}},s=Array.from({length:Math.min(t,e.length)},()=>o());if(await Promise.all(s),r.length>0){yC(`${_C.RED}错误: 部分包查询 npm latest 失败,已中止(0 文件改动、0 提交)${_C.RESET}`);for(let e of r)yC(` ${e.name}: ${e.reason}`);process.exit(1)}return n},ew=async e=>{let{scope:t,version:n,message:r,dryRun:i}=e,a=e.concurrency??10,o=await VC({projectScope:e.projectScope}),s=n===void 0,c=s?`latest(各自 npm 最新)`:n,l=r??(s?`chore: bump ${t} deps to latest`:`chore: bump ${t} deps to ${n.replace(/^[~^]/,``)}`),u=UC(t);$(`${_C.BLUE}═══ version upgrade-across ═══${_C.RESET}`),$(`项目获取来源: ${o.source===`structure`?`结构锚点(cwd 上溯聚合根)`:`显式圈定(--project-scope)`}`),$(`registry: ${o.registryRoot}`),$(`项目范围: ${o.scopeId}`),$(`升级范围: ${t} 下的所有包 -> ${c}`),$(`并发数: ${a}`),i&&$(`${_C.YELLOW}[dry-run] 预览模式,不写文件、不提交${_C.RESET}`),$(``);let d=o.projects;$(`发现 ${d.length} 个子项目,并发处理(并发 ${a})...`),$(``);let f;if(s){let e=await QC(d,u);if(e.length===0){$(`${_C.YELLOW}未匹配到任何 ${t} 下的包,结束${_C.RESET}`);return}$(`匹配到 ${e.length} 个 ${t} 下的包,查询 npm latest...`);let n=await $C(e,a);f=(e,t)=>KC(t,n.get(e)??``)}else{let e=n??``;f=()=>e}let p=[],m=0,h=d.length;await(async(e,t)=>{let n=0,r=async()=>{for(;n<e.length;){let t=e[n];if(n++,t===void 0)break;let r=await ZC(t,u,f,l,i);p.push(r),m++;let a=r.status===`success`?`${_C.GREEN}✓${_C.RESET}`:r.status===`failed`?`${_C.RED}✗${_C.RESET}`:`·`;$(` [${m}/${h}] ${a} ${t.name}`)}},a=Array.from({length:Math.min(t,e.length)},()=>r());await Promise.all(a)})(d,a),$(``),tw(p,i)},tw=(e,t)=>{let n=e.filter(e=>e.status===`success`),r=e.filter(e=>e.status===`skipped-dirty`),i=e.filter(e=>e.status===`skipped-nochange`),a=e.filter(e=>e.status===`failed`);$(`${_C.BLUE}═══ 处理结果 ═══${_C.RESET}`);let o=t?`将提交`:`已提交`;$(`${_C.GREEN}✓ ${o}: ${n.length}${_C.RESET}`);for(let e of n){let t=e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `);$(` ${e.name}`),$(` ${t}`),e.skippedFiles!==void 0&&e.skippedFiles.length>0&&$(` ⚠ 脏文件跳过:${e.skippedFiles.join(`,`)}`)}if(r.length>0){$(``),$(`${_C.YELLOW}⚠ 跳过(文件已改动): ${r.length}${_C.RESET}`);for(let e of r)$(` ${e.name}: ${e.reason}`)}if(i.length>0&&($(``),$(`跳过(无匹配/已是目标版本): ${i.length}`)),a.length>0){$(``),$(`${_C.RED}✗ 失败(需人工介入): ${a.length}${_C.RESET}`);for(let e of a)$(` ${e.name}: ${e.reason}`),$(` ${e.changes.map(e=>`${e.name.split(`/`).pop()}: ${e.from} → ${e.to}`).join(`, `)}`)}$(``),$(`${_C.BLUE}汇总: ${n.length} ${o} / ${r.length} 跳过(dirty) / ${i.length} 跳过(无变更) / ${a.length} 失败${_C.RESET}`),!t&&n.length>0&&($(``),$(`下一步:推送到远程`),$(` bun push-all`)),a.length>0&&(process.exitCode=1)},nw=Ac([`default`,`major`,`minor`,`patch`,`latest`,`newest`]).default(`default`),rw=async e=>{let t=(await bC()).upgrade??{},n=e.mode||t.mode||`default`,r=nw.safeParse(n),i=r.success?r.data:`default`,a=[...e.scope?[`${e.scope}/*`]:[],...t.include??[]],{packages:o}=await NS({cwd:process.cwd(),mode:i,write:!e.dryRun&&e.write,recursive:t.recursive??!0,timeout:t.timeout??3e4,retries:t.retries??3,exclude:t.exclude??[],include:a,depFields:t.depFields,ignorePaths:t.ignorePaths??[],concurrency:t.concurrency??10,force:!1,all:!1,install:!1,update:!1,interactive:!1,group:!0,includeLocked:!1,timediff:!0,nodecompat:!0,loglevel:`info`,silent:!1,failOnOutdated:!1},{afterPackagesLoaded:e=>{$(`扫描到 ${e.length} 个包,正在检查依赖更新...`)},beforePackageStart:e=>{$(`正在检查 ${e.name||e.relative}...`)},afterPackageEnd:e=>{let t=e.resolved.filter(e=>e.update).length;$(t>0?` ✓ ${e.name||e.relative}: 发现 ${t} 个可更新依赖`:` ✓ ${e.name||e.relative}: 所有依赖已是最新`)},afterPackageWrite:e=>{$(` 📝 已写入 ${e.name||e.relative}`)}}),s=0;$(`
|
|
326
|
+
--- 检查结果 ---`);for(let e of o){let t=e.resolved.filter(e=>e.update);if(t.length>0){s+=t.length,$(`\n${e.name||e.relative}:`);for(let e of t){let t=e.diff??``;$(` ${e.name}: ${e.currentVersion} -> ${e.targetVersion} (${t})`)}}}s===0?$(`所有依赖已是最新版本`):($(`\n共发现 ${s} 个可更新依赖`),e.write?$(`已写入 package.json`):$(`使用 --write 参数写入 package.json`))};function iw(e){qd(e,{name:`upgrade`,description:`检查依赖版本更新`,arguments:[{signature:`[mode]`,description:`升级模式(major/minor/patch/latest/newest)`},{signature:`[scope]`,description:`可选。仅升级指定 scope 下的依赖(如 @longzai-intelligence-oxlint),内部展开为 include @scope/*`}],options:[{flags:`--write`,description:`将更新写入 package.json`},{flags:`--dry-run`,description:`仅预览`}],schema:bc({write:uc().optional(),dryRun:uc().optional()}),action:async(e,t)=>{let n=t[0],r=t[1];await rw({mode:n,write:e.write===!0,dryRun:e.dryRun===!0,scope:r})}}),qd(e,{name:`upgrade-across`,description:`跨产品群批量升级依赖(项目清单经 project-registry 声明域获取)`,options:[{flags:`--scope <scope>`,description:`依赖 scope(必填,如 @longzai-intelligence-builder)`},{flags:`--target <version>`,description:`目标版本号(可选,如 ^0.0.8。省略时自动取每个匹配包的 npm latest)`},{flags:`-m, --message <message>`,description:`自定义提交信息`},{flags:`--project-scope <id>`,description:`显式圈定项目范围(缺省自动取当前 edition 范围)`},{flags:`--concurrency <n>`,description:`并发数(默认 10)`},{flags:`--dry-run`,description:`仅预览(不写文件、不提交)`}],schema:bc({scope:U().optional(),target:U().optional(),message:U().optional(),config:U().optional(),concurrency:ol().int().positive().optional(),projectScope:U().optional(),dryRun:uc().optional()}),action:async e=>{e.scope||(process.stderr.write(`错误: upgrade-across 需要指定 --scope <@scope>
|
|
327
327
|
`),process.stderr.write(`示例: --scope @longzai-intelligence-builder
|
|
328
|
-
`),process.exit(1)),await
|
|
328
|
+
`),process.exit(1)),await ew({scope:e.scope,version:e.target,message:e.message,projectScope:e.projectScope,concurrency:e.concurrency,dryRun:e.dryRun===!0})}}),qd(e,{name:`check`,description:`校验全部 Longzai Intelligence 包依赖是否为 registry 最新版`,schema:bc({}),action:async()=>{await NC()}})}function aw(e){qd(e,{name:`hoisting check`,description:`检查子包开发依赖是否重复声明 workspace 根已有依赖`,schema:bc({}),action:async()=>{await wC()}})}function ow(e){qd(e,{name:`overrides check`,description:`检查 package.json 是否声明未豁免的强制版本字段`,schema:bc({}),action:async()=>{await DC()}})}function sw(){let e=Hd({name:`lzi-dependencies`,description:`Longzai Intelligence 依赖版本管理工具`,version:`0.0.11`});return iw(e),aw(e),ow(e),e}async function cw(){await sw().parseAsync(process.argv)}import.meta.main===!0&&await cw();export{sw as buildProgram};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-dependencies/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Longzai Intelligence 依赖版本管理 CLI(bin lzi-dependencies)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@longzai-intelligence-cli/core": "^0.0.12",
|
|
42
|
-
"@longzai-intelligence-dependencies/core": "0.0.
|
|
42
|
+
"@longzai-intelligence-dependencies/core": "0.0.11",
|
|
43
43
|
"@longzai-intelligence-logger/node": "^0.1.8"
|
|
44
44
|
}
|
|
45
45
|
}
|