@gjsify/cli 0.64.3-next.261 → 0.64.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.gjs.mjs CHANGED
@@ -145,7 +145,7 @@ fi
145
145
  `)}`:``;n.fail(N(`Missing required argument: %s`,`Missing required arguments: %s`,Object.keys(C).length,Object.keys(C).join(`, `)+S))}},F.unknownArguments=function unknownArguments(S,C,I,H,W=!0){let q=t.getInternalMethods().getCommandInstance().getCommands(),Y=[],X=t.getInternalMethods().getContext();if(Object.keys(S).forEach(n=>{!bp.includes(n)&&!Object.prototype.hasOwnProperty.call(I,n)&&!Object.prototype.hasOwnProperty.call(t.getInternalMethods().getParseContext(),n)&&!F.isValidAndSomeAliasIsNotNew(n,C)&&Y.push(n)}),W&&(X.commands.length>0||q.length>0||H)&&S._.slice(X.commands.length).forEach(t=>{q.includes(``+t)||Y.push(``+t)}),W){let n=t.getDemandedCommands()._?.max||0,C=X.commands.length+n;C<S._.length&&S._.slice(C).forEach(t=>{t=String(t),!X.commands.includes(t)&&!Y.includes(t)&&Y.push(t)})}Y.length&&n.fail(N(`Unknown argument: %s`,`Unknown arguments: %s`,Y.length,Y.map(t=>t.trim()?t:`"${t}"`).join(`, `)))},F.unknownCommands=function unknownCommands(S){let C=t.getInternalMethods().getCommandInstance().getCommands(),F=[],I=t.getInternalMethods().getContext();return(I.commands.length>0||C.length>0)&&S._.slice(I.commands.length).forEach(t=>{C.includes(``+t)||F.push(``+t)}),F.length>0?(n.fail(N(`Unknown command: %s`,`Unknown commands: %s`,F.length,F.join(`, `))),!0):!1},F.isValidAndSomeAliasIsNotNew=function isValidAndSomeAliasIsNotNew(n,S){if(!Object.prototype.hasOwnProperty.call(S,n))return!1;let C=t.parsed.newAliases;return[n,...S[n]].some(t=>!Object.prototype.hasOwnProperty.call(C,t)||!C[n])},F.limitedChoices=function limitedChoices(S){let N=t.getOptions(),F={};if(!Object.keys(N.choices).length)return;Object.keys(S).forEach(t=>{bp.indexOf(t)===-1&&Object.prototype.hasOwnProperty.call(N.choices,t)&&[].concat(S[t]).forEach(n=>{N.choices[t].indexOf(n)===-1&&n!==void 0&&(F[t]=(F[t]||[]).concat(n))})});let I=Object.keys(F);if(!I.length)return;let H=C(`Invalid values:`);I.forEach(t=>{H+=`\n ${C(`Argument: %s, Given: %s, Choices: %s`,t,n.stringifiedValues(F[t]),n.stringifiedValues(N.choices[t]))}`}),n.fail(H)};let I={};F.implies=function implies(n,C){argsert(`<string|object> [array|number|string]`,[n,C],arguments.length),typeof n==`object`?Object.keys(n).forEach(t=>{F.implies(t,n[t])}):(t.global(n),I[n]||(I[n]=[]),Array.isArray(C)?C.forEach(t=>F.implies(n,t)):(assertNotStrictEqual(C,void 0,S),I[n].push(C)))},F.getImplied=function getImplied(){return I};function keyExists(t,n){let S=Number(n);return n=isNaN(S)?n:S,typeof n==`number`?n=t._.length>=n:n.match(/^--no-.+/)?(n=n.match(/^--no-(.+)/)[1],n=!Object.prototype.hasOwnProperty.call(t,n)):n=Object.prototype.hasOwnProperty.call(t,n),n}F.implications=function implications(t){let S=[];if(Object.keys(I).forEach(n=>{let C=n;(I[n]||[]).forEach(n=>{let N=C,F=n;N=keyExists(t,N),n=keyExists(t,n),N&&!n&&S.push(` ${C} -> ${F}`)})}),S.length){let t=`${C(`Implications failed:`)}\n`;S.forEach(n=>{t+=n}),n.fail(t)}};let H={};F.conflicts=function conflicts(n,S){argsert(`<string|object> [array|string]`,[n,S],arguments.length),typeof n==`object`?Object.keys(n).forEach(t=>{F.conflicts(t,n[t])}):(t.global(n),H[n]||(H[n]=[]),Array.isArray(S)?S.forEach(t=>F.conflicts(n,t)):H[n].push(S))},F.getConflicting=()=>H,F.conflicting=function conflictingFn(N){Object.keys(N).forEach(t=>{H[t]&&H[t].forEach(S=>{S&&N[t]!==void 0&&N[S]!==void 0&&n.fail(C(`Arguments %s and %s are mutually exclusive`,t,S))})}),t.getInternalMethods().getParserConfiguration()[`strip-dashed`]&&Object.keys(H).forEach(t=>{H[t].forEach(F=>{F&&N[S.Parser.camelCase(t)]!==void 0&&N[S.Parser.camelCase(F)]!==void 0&&n.fail(C(`Arguments %s and %s are mutually exclusive`,t,F))})})},F.recommendCommands=function recommendCommands(t,S){S=S.sort((t,n)=>n.length-t.length);let N=null,F=1/0;for(let n=0,C;(C=S[n])!==void 0;n++){let n=levenshtein(t,C);n<=3&&n<F&&(F=n,N=C)}N&&n.fail(C(`Did you mean %s?`,N))},F.reset=function reset(t){return I=objFilter(I,n=>!t[n]),H=objFilter(H,n=>!t[n]),F};let W=[];return F.freeze=function freeze(){W.push({implied:I,conflicting:H})},F.unfreeze=function unfreeze(){let t=W.pop();assertNotStrictEqual(t,void 0,S),{implied:I,conflicting:H}=t},F}var bp,xp=__esmMin(()=>{ap(),tp(),yp(),dp(),bp=[`$0`,`--`,`_`]});function YargsFactory(t){return(n=[],S=t.process.cwd(),C)=>{let N=new YargsInstance(n,S,C,t);return Object.defineProperty(N,"argv",{get:()=>N.parse(),enumerable:!0}),N.help(),N.version(),N}}function isYargsInstance(t){return!!t&&typeof t.getInternalMethods==`function`}var __classPrivateFieldSet,__classPrivateFieldGet,Sp,Cp,wp,Tp,Ep,Dp,Op,kp,Ap,jp,Mp,Np,Pp,Fp,Ip,Lp,Rp,zp,Bp,Vp,Hp,Up,Wp,Gp,Kp,qp,Jp,Yp,Xp,Zp,Qp,$p,em,tm,nm,im,am,om,sm,cm,lm,um,dm,fm,pm,mm,hm,gm,_m,vm,ym,bm,xm,Sm,Cm,wm,Tm,Em,Dm,Om,km,Am,jm,Mm,Nm,Pm,Fm,Im,Lm,Rm,zm,Bm,YargsInstance,Vm=__esmMin(()=>{_e(),up(),tp(),Cl(),pp(),ap(),vp(),xp(),dp(),El(),op(),np(),sp(),fp(),__classPrivateFieldSet=function(t,n,S,C,N){if(C===`m`)throw TypeError(`Private method is not writable`);if(C===`a`&&!N)throw TypeError(`Private accessor was defined without a setter`);if(typeof n==`function`?t!==n||!N:!n.has(t))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return C===`a`?N.call(t,S):N?N.value=S:n.set(t,S),S},__classPrivateFieldGet=function(t,n,S,C){if(S===`a`&&!C)throw TypeError(`Private accessor was defined without a getter`);if(typeof n==`function`?t!==n||!C:!n.has(t))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return S===`m`?C:S===`a`?C.call(t):C?C.value:n.get(t)},im=Symbol(`copyDoubleDash`),am=Symbol(`copyDoubleDash`),om=Symbol(`deleteFromParserHintObject`),sm=Symbol(`emitWarning`),cm=Symbol(`freeze`),lm=Symbol(`getDollarZero`),um=Symbol(`getParserConfiguration`),dm=Symbol(`getUsageConfiguration`),fm=Symbol(`guessLocale`),pm=Symbol(`guessVersion`),mm=Symbol(`parsePositionalNumbers`),hm=Symbol(`pkgUp`),gm=Symbol(`populateParserHintArray`),_m=Symbol(`populateParserHintSingleValueDictionary`),vm=Symbol(`populateParserHintArrayDictionary`),ym=Symbol(`populateParserHintDictionary`),bm=Symbol(`sanitizeKey`),xm=Symbol(`setKey`),Sm=Symbol(`unfreeze`),Cm=Symbol(`validateAsync`),wm=Symbol(`getCommandInstance`),Tm=Symbol(`getContext`),Em=Symbol(`getHasOutput`),Dm=Symbol(`getLoggerInstance`),Om=Symbol(`getParseContext`),km=Symbol(`getUsageInstance`),Am=Symbol(`getValidationInstance`),jm=Symbol(`hasParseCallback`),Mm=Symbol(`isGlobalContext`),Nm=Symbol(`postProcess`),Pm=Symbol(`rebase`),Fm=Symbol(`reset`),Im=Symbol(`runYargsParserAndExecuteCommands`),Lm=Symbol(`runValidation`),Rm=Symbol(`setHasOutput`),zm=Symbol(`kTrackManuallySetKeys`),Bm=`en_US`,YargsInstance=class{constructor(t=[],n,S,C){this.customScriptName=!1,this.parsed=!1,Sp.set(this,void 0),Cp.set(this,void 0),wp.set(this,{commands:[],fullCommands:[]}),Tp.set(this,null),Ep.set(this,null),Dp.set(this,`show-hidden`),Op.set(this,null),kp.set(this,!0),Ap.set(this,{}),jp.set(this,!0),Mp.set(this,[]),Np.set(this,void 0),Pp.set(this,{}),Fp.set(this,!1),Ip.set(this,null),Lp.set(this,!0),Rp.set(this,void 0),zp.set(this,``),Bp.set(this,void 0),Vp.set(this,void 0),Hp.set(this,{}),Up.set(this,null),Wp.set(this,null),Gp.set(this,{}),Kp.set(this,{}),qp.set(this,void 0),Jp.set(this,!1),Yp.set(this,void 0),Xp.set(this,!1),Zp.set(this,!1),Qp.set(this,!1),$p.set(this,void 0),em.set(this,{}),tm.set(this,null),nm.set(this,void 0),__classPrivateFieldSet(this,Yp,C,`f`),__classPrivateFieldSet(this,qp,t,`f`),__classPrivateFieldSet(this,Cp,n,`f`),__classPrivateFieldSet(this,Vp,S,`f`),__classPrivateFieldSet(this,Np,new GlobalMiddleware(this),`f`),this.$0=this[lm](),this[Fm](),__classPrivateFieldSet(this,Sp,__classPrivateFieldGet(this,Sp,`f`),`f`),__classPrivateFieldSet(this,$p,__classPrivateFieldGet(this,$p,`f`),`f`),__classPrivateFieldSet(this,nm,__classPrivateFieldGet(this,nm,`f`),`f`),__classPrivateFieldSet(this,Bp,__classPrivateFieldGet(this,Bp,`f`),`f`),__classPrivateFieldGet(this,Bp,`f`).showHiddenOpt=__classPrivateFieldGet(this,Dp,`f`),__classPrivateFieldSet(this,Rp,this[am](),`f`),__classPrivateFieldGet(this,Yp,`f`).y18n.setLocale(Bm)}addHelpOpt(t,n){return argsert(`[string|boolean] [string]`,[t,n],arguments.length),__classPrivateFieldGet(this,Ip,`f`)&&(this[om](__classPrivateFieldGet(this,Ip,`f`)),__classPrivateFieldSet(this,Ip,null,`f`)),t===!1&&n===void 0?this:(__classPrivateFieldSet(this,Ip,typeof t==`string`?t:`help`,`f`),this.boolean(__classPrivateFieldGet(this,Ip,`f`)),this.describe(__classPrivateFieldGet(this,Ip,`f`),n||__classPrivateFieldGet(this,$p,`f`).deferY18nLookup(`Show help`)),this)}help(t,n){return this.addHelpOpt(t,n)}addShowHiddenOpt(t,n){if(argsert(`[string|boolean] [string]`,[t,n],arguments.length),t===!1&&n===void 0)return this;let S=typeof t==`string`?t:__classPrivateFieldGet(this,Dp,`f`);return this.boolean(S),this.describe(S,n||__classPrivateFieldGet(this,$p,`f`).deferY18nLookup(`Show hidden options`)),__classPrivateFieldGet(this,Bp,`f`).showHiddenOpt=S,this}showHidden(t,n){return this.addShowHiddenOpt(t,n)}alias(t,n){return argsert(`<object|string|array> [string|array]`,[t,n],arguments.length),this[vm](this.alias.bind(this),`alias`,t,n),this}array(t){return argsert(`<array|string>`,[t],arguments.length),this[gm](`array`,t),this[zm](t),this}boolean(t){return argsert(`<array|string>`,[t],arguments.length),this[gm](`boolean`,t),this[zm](t),this}check(t,n){return argsert(`<function> [boolean]`,[t,n],arguments.length),this.middleware((n,S)=>maybeAsyncResult(()=>t(n,S.getOptions()),S=>(S?(typeof S==`string`||S instanceof Error)&&__classPrivateFieldGet(this,$p,`f`).fail(S.toString(),S):__classPrivateFieldGet(this,$p,`f`).fail(__classPrivateFieldGet(this,Yp,`f`).y18n.__(`Argument check failed: %s`,t.toString())),n),t=>(__classPrivateFieldGet(this,$p,`f`).fail(t.message?t.message:t.toString(),t),n)),!1,n),this}choices(t,n){return argsert(`<object|string|array> [string|array]`,[t,n],arguments.length),this[vm](this.choices.bind(this),`choices`,t,n),this}coerce(t,n){if(argsert(`<object|string|array> [function]`,[t,n],arguments.length),Array.isArray(t)){if(!n)throw new Sl(`coerce callback must be provided`);for(let S of t)this.coerce(S,n);return this}else if(typeof t==`object`){for(let n of Object.keys(t))this.coerce(n,t[n]);return this}if(!n)throw new Sl(`coerce callback must be provided`);let S=t;return __classPrivateFieldGet(this,Bp,`f`).key[S]=!0,__classPrivateFieldGet(this,Np,`f`).addCoerceMiddleware((t,C)=>{let N=C.getAliases()[S]??[],F=[S,...N].filter(n=>Object.prototype.hasOwnProperty.call(t,n));return F.length===0?t:maybeAsyncResult(()=>n(t[F[0]]),n=>(F.forEach(S=>{t[S]=n}),t),t=>{throw new Sl(t.message)})},S),this}conflicts(t,n){return argsert(`<string|object> [string|array]`,[t,n],arguments.length),__classPrivateFieldGet(this,nm,`f`).conflicts(t,n),this}config(t=`config`,n,S){return argsert(`[object|string] [string|function] [function]`,[t,n,S],arguments.length),typeof t==`object`&&!Array.isArray(t)?(t=applyExtends(t,__classPrivateFieldGet(this,Cp,`f`),this[um]()[`deep-merge-config`]||!1,__classPrivateFieldGet(this,Yp,`f`)),__classPrivateFieldGet(this,Bp,`f`).configObjects=(__classPrivateFieldGet(this,Bp,`f`).configObjects||[]).concat(t),this):(typeof n==`function`&&(S=n,n=void 0),this.describe(t,n||__classPrivateFieldGet(this,$p,`f`).deferY18nLookup(`Path to JSON config file`)),(Array.isArray(t)?t:[t]).forEach(t=>{__classPrivateFieldGet(this,Bp,`f`).config[t]=S||!0}),this)}completion(t,n,S){return argsert(`[string] [string|boolean|function] [function]`,[t,n,S],arguments.length),typeof n==`function`&&(S=n,n=void 0),__classPrivateFieldSet(this,Ep,t||__classPrivateFieldGet(this,Ep,`f`)||`completion`,`f`),!n&&n!==!1&&(n=`generate completion script`),this.command(__classPrivateFieldGet(this,Ep,`f`),n),S&&__classPrivateFieldGet(this,Tp,`f`).registerFunction(S),this}command(t,n,S,C,N,F){return argsert(`<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]`,[t,n,S,C,N,F],arguments.length),__classPrivateFieldGet(this,Sp,`f`).addHandler(t,n,S,C,N,F),this}commands(t,n,S,C,N,F){return this.command(t,n,S,C,N,F)}commandDir(t,n){argsert(`<string> [object]`,[t,n],arguments.length);let S=__classPrivateFieldGet(this,Vp,`f`)||__classPrivateFieldGet(this,Yp,`f`).require;return __classPrivateFieldGet(this,Sp,`f`).addDirectory(t,S,__classPrivateFieldGet(this,Yp,`f`).getCallerFile(),n),this}count(t){return argsert(`<array|string>`,[t],arguments.length),this[gm](`count`,t),this[zm](t),this}default(t,n,S){return argsert(`<object|string|array> [*] [string]`,[t,n,S],arguments.length),S&&(assertSingleKey(t,__classPrivateFieldGet(this,Yp,`f`)),__classPrivateFieldGet(this,Bp,`f`).defaultDescription[t]=S),typeof n==`function`&&(assertSingleKey(t,__classPrivateFieldGet(this,Yp,`f`)),__classPrivateFieldGet(this,Bp,`f`).defaultDescription[t]||(__classPrivateFieldGet(this,Bp,`f`).defaultDescription[t]=__classPrivateFieldGet(this,$p,`f`).functionDescription(n)),n=n.call()),this[_m](this.default.bind(this),`default`,t,n),this}defaults(t,n,S){return this.default(t,n,S)}demandCommand(t=1,n,S,C){return argsert(`[number] [number|string] [string|null|undefined] [string|null|undefined]`,[t,n,S,C],arguments.length),typeof n!=`number`&&(S=n,n=1/0),this.global(`_`,!1),__classPrivateFieldGet(this,Bp,`f`).demandedCommands._={min:t,max:n,minMsg:S,maxMsg:C},this}demand(t,n,S){return Array.isArray(n)?(n.forEach(t=>{assertNotStrictEqual(S,!0,__classPrivateFieldGet(this,Yp,`f`)),this.demandOption(t,S)}),n=1/0):typeof n!=`number`&&(S=n,n=1/0),typeof t==`number`?(assertNotStrictEqual(S,!0,__classPrivateFieldGet(this,Yp,`f`)),this.demandCommand(t,n,S,S)):Array.isArray(t)?t.forEach(t=>{assertNotStrictEqual(S,!0,__classPrivateFieldGet(this,Yp,`f`)),this.demandOption(t,S)}):typeof S==`string`?this.demandOption(t,S):(S===!0||S===void 0)&&this.demandOption(t),this}demandOption(t,n){return argsert(`<object|string|array> [string]`,[t,n],arguments.length),this[_m](this.demandOption.bind(this),`demandedOptions`,t,n),this}deprecateOption(t,n){return argsert(`<string> [string|boolean]`,[t,n],arguments.length),__classPrivateFieldGet(this,Bp,`f`).deprecatedOptions[t]=n,this}describe(t,n){return argsert(`<object|string|array> [string]`,[t,n],arguments.length),this[xm](t,!0),__classPrivateFieldGet(this,$p,`f`).describe(t,n),this}detectLocale(t){return argsert(`<boolean>`,[t],arguments.length),__classPrivateFieldSet(this,kp,t,`f`),this}env(t){return argsert(`[string|boolean]`,[t],arguments.length),t===!1?delete __classPrivateFieldGet(this,Bp,`f`).envPrefix:__classPrivateFieldGet(this,Bp,`f`).envPrefix=t||``,this}epilogue(t){return argsert(`<string>`,[t],arguments.length),__classPrivateFieldGet(this,$p,`f`).epilog(t),this}epilog(t){return this.epilogue(t)}example(t,n){return argsert(`<string|array> [string]`,[t,n],arguments.length),Array.isArray(t)?t.forEach(t=>this.example(...t)):__classPrivateFieldGet(this,$p,`f`).example(t,n),this}exit(t,n){__classPrivateFieldSet(this,Fp,!0,`f`),__classPrivateFieldSet(this,Op,n,`f`),__classPrivateFieldGet(this,jp,`f`)&&__classPrivateFieldGet(this,Yp,`f`).process.exit(t)}exitProcess(t=!0){return argsert(`[boolean]`,[t],arguments.length),__classPrivateFieldSet(this,jp,t,`f`),this}fail(t){if(argsert(`<function|boolean>`,[t],arguments.length),typeof t==`boolean`&&t!==!1)throw new Sl(`Invalid first argument. Expected function or boolean 'false'`);return __classPrivateFieldGet(this,$p,`f`).failFn(t),this}getAliases(){return this.parsed?this.parsed.aliases:{}}async getCompletion(t,n){return argsert(`<array> [function]`,[t,n],arguments.length),n?__classPrivateFieldGet(this,Tp,`f`).getCompletion(t,n):new Promise((n,S)=>{__classPrivateFieldGet(this,Tp,`f`).getCompletion(t,(t,C)=>{t?S(t):n(C)})})}getDemandedOptions(){return argsert([],0),__classPrivateFieldGet(this,Bp,`f`).demandedOptions}getDemandedCommands(){return argsert([],0),__classPrivateFieldGet(this,Bp,`f`).demandedCommands}getDeprecatedOptions(){return argsert([],0),__classPrivateFieldGet(this,Bp,`f`).deprecatedOptions}getDetectLocale(){return __classPrivateFieldGet(this,kp,`f`)}getExitProcess(){return __classPrivateFieldGet(this,jp,`f`)}getGroups(){return Object.assign({},__classPrivateFieldGet(this,Pp,`f`),__classPrivateFieldGet(this,Kp,`f`))}getHelp(){if(__classPrivateFieldSet(this,Fp,!0,`f`),!__classPrivateFieldGet(this,$p,`f`).hasCachedHelpMessage()){if(!this.parsed){let t=this[Im](__classPrivateFieldGet(this,qp,`f`),void 0,void 0,0,!0);if(isPromise(t))return t.then(()=>__classPrivateFieldGet(this,$p,`f`).help())}let t=__classPrivateFieldGet(this,Sp,`f`).runDefaultBuilderOn(this);if(isPromise(t))return t.then(()=>__classPrivateFieldGet(this,$p,`f`).help())}return Promise.resolve(__classPrivateFieldGet(this,$p,`f`).help())}getOptions(){return __classPrivateFieldGet(this,Bp,`f`)}getStrict(){return __classPrivateFieldGet(this,Xp,`f`)}getStrictCommands(){return __classPrivateFieldGet(this,Zp,`f`)}getStrictOptions(){return __classPrivateFieldGet(this,Qp,`f`)}global(t,n){return argsert(`<string|array> [boolean]`,[t,n],arguments.length),t=[].concat(t),n===!1?t.forEach(t=>{__classPrivateFieldGet(this,Bp,`f`).local.includes(t)||__classPrivateFieldGet(this,Bp,`f`).local.push(t)}):__classPrivateFieldGet(this,Bp,`f`).local=__classPrivateFieldGet(this,Bp,`f`).local.filter(n=>t.indexOf(n)===-1),this}group(t,n){argsert(`<string|array> <string>`,[t,n],arguments.length);let S=__classPrivateFieldGet(this,Kp,`f`)[n]||__classPrivateFieldGet(this,Pp,`f`)[n];__classPrivateFieldGet(this,Kp,`f`)[n]&&delete __classPrivateFieldGet(this,Kp,`f`)[n];let C={};return __classPrivateFieldGet(this,Pp,`f`)[n]=(S||[]).concat(t).filter(t=>C[t]?!1:C[t]=!0),this}hide(t){return argsert(`<string>`,[t],arguments.length),__classPrivateFieldGet(this,Bp,`f`).hiddenOptions.push(t),this}implies(t,n){return argsert(`<string|object> [number|string|array]`,[t,n],arguments.length),__classPrivateFieldGet(this,nm,`f`).implies(t,n),this}locale(t){return argsert(`[string]`,[t],arguments.length),t===void 0?(this[fm](),__classPrivateFieldGet(this,Yp,`f`).y18n.getLocale()):(__classPrivateFieldSet(this,kp,!1,`f`),__classPrivateFieldGet(this,Yp,`f`).y18n.setLocale(t),this)}middleware(t,n,S){return __classPrivateFieldGet(this,Np,`f`).addMiddleware(t,!!n,S)}nargs(t,n){return argsert(`<string|object|array> [number]`,[t,n],arguments.length),this[_m](this.nargs.bind(this),`narg`,t,n),this}normalize(t){return argsert(`<array|string>`,[t],arguments.length),this[gm](`normalize`,t),this}number(t){return argsert(`<array|string>`,[t],arguments.length),this[gm](`number`,t),this[zm](t),this}option(t,n){if(argsert(`<string|object> [object]`,[t,n],arguments.length),typeof t==`object`)Object.keys(t).forEach(n=>{this.options(n,t[n])});else{typeof n!=`object`&&(n={}),this[zm](t),__classPrivateFieldGet(this,tm,`f`)&&(t===`version`||n?.alias===`version`)&&this[sm]([`"version" is a reserved word.`,`Please do one of the following:`,'- Disable version with `yargs.version(false)` if using "version" as an option',"- Use the built-in `yargs.version` method instead (if applicable)",`- Use a different option key`,`https://yargs.js.org/docs/#api-reference-version`].join(`
146
146
  `),void 0,`versionWarning`),__classPrivateFieldGet(this,Bp,`f`).key[t]=!0,n.alias&&this.alias(t,n.alias);let S=n.deprecate||n.deprecated;S&&this.deprecateOption(t,S);let C=n.demand||n.required||n.require;C&&this.demand(t,C),n.demandOption&&this.demandOption(t,typeof n.demandOption==`string`?n.demandOption:void 0),n.conflicts&&this.conflicts(t,n.conflicts),`default`in n&&this.default(t,n.default),n.implies!==void 0&&this.implies(t,n.implies),n.nargs!==void 0&&this.nargs(t,n.nargs),n.config&&this.config(t,n.configParser),n.normalize&&this.normalize(t),n.choices&&this.choices(t,n.choices),n.coerce&&this.coerce(t,n.coerce),n.group&&this.group(t,n.group),(n.boolean||n.type===`boolean`)&&(this.boolean(t),n.alias&&this.boolean(n.alias)),(n.array||n.type===`array`)&&(this.array(t),n.alias&&this.array(n.alias)),(n.number||n.type===`number`)&&(this.number(t),n.alias&&this.number(n.alias)),(n.string||n.type===`string`)&&(this.string(t),n.alias&&this.string(n.alias)),(n.count||n.type===`count`)&&this.count(t),typeof n.global==`boolean`&&this.global(t,n.global),n.defaultDescription&&(__classPrivateFieldGet(this,Bp,`f`).defaultDescription[t]=n.defaultDescription),n.skipValidation&&this.skipValidation(t);let N=n.describe||n.description||n.desc,F=__classPrivateFieldGet(this,$p,`f`).getDescriptions();(!Object.prototype.hasOwnProperty.call(F,t)||typeof N==`string`)&&this.describe(t,N),n.hidden&&this.hide(t),n.requiresArg&&this.requiresArg(t)}return this}options(t,n){return this.option(t,n)}parse(t,n,S){argsert(`[string|array] [function|boolean|object] [function]`,[t,n,S],arguments.length),this[cm](),t===void 0&&(t=__classPrivateFieldGet(this,qp,`f`)),typeof n==`object`&&(__classPrivateFieldSet(this,Wp,n,`f`),n=S),typeof n==`function`&&(__classPrivateFieldSet(this,Up,n,`f`),n=!1),n||__classPrivateFieldSet(this,qp,t,`f`),__classPrivateFieldGet(this,Up,`f`)&&__classPrivateFieldSet(this,jp,!1,`f`);let C=this[Im](t,!!n),N=this.parsed;return __classPrivateFieldGet(this,Tp,`f`).setParsed(this.parsed),isPromise(C)?C.then(t=>(__classPrivateFieldGet(this,Up,`f`)&&__classPrivateFieldGet(this,Up,`f`).call(this,__classPrivateFieldGet(this,Op,`f`),t,__classPrivateFieldGet(this,zp,`f`)),t)).catch(t=>{throw __classPrivateFieldGet(this,Up,`f`)&&__classPrivateFieldGet(this,Up,`f`)(t,this.parsed.argv,__classPrivateFieldGet(this,zp,`f`)),t}).finally(()=>{this[Sm](),this.parsed=N}):(__classPrivateFieldGet(this,Up,`f`)&&__classPrivateFieldGet(this,Up,`f`).call(this,__classPrivateFieldGet(this,Op,`f`),C,__classPrivateFieldGet(this,zp,`f`)),this[Sm](),this.parsed=N,C)}parseAsync(t,n,S){let C=this.parse(t,n,S);return isPromise(C)?C:Promise.resolve(C)}parseSync(t,n,S){let C=this.parse(t,n,S);if(isPromise(C))throw new Sl(`.parseSync() must not be used with asynchronous builders, handlers, or middleware`);return C}parserConfiguration(t){return argsert(`<object>`,[t],arguments.length),__classPrivateFieldSet(this,Hp,t,`f`),this}pkgConf(t,n){argsert(`<string> [string]`,[t,n],arguments.length);let S=null,C=this[hm](n||__classPrivateFieldGet(this,Cp,`f`));return C[t]&&typeof C[t]==`object`&&(S=applyExtends(C[t],n||__classPrivateFieldGet(this,Cp,`f`),this[um]()[`deep-merge-config`]||!1,__classPrivateFieldGet(this,Yp,`f`)),__classPrivateFieldGet(this,Bp,`f`).configObjects=(__classPrivateFieldGet(this,Bp,`f`).configObjects||[]).concat(S)),this}positional(t,n){argsert(`<string> <object>`,[t,n],arguments.length);let S=[`default`,`defaultDescription`,`implies`,`normalize`,`choices`,`conflicts`,`coerce`,`type`,`describe`,`desc`,`description`,`alias`];n=objFilter(n,(t,n)=>t===`type`&&![`string`,`number`,`boolean`].includes(n)?!1:S.includes(t));let C=__classPrivateFieldGet(this,wp,`f`).fullCommands[__classPrivateFieldGet(this,wp,`f`).fullCommands.length-1],N=C?__classPrivateFieldGet(this,Sp,`f`).cmdToParseOptions(C):{array:[],alias:{},default:{},demand:{}};return objectKeys(N).forEach(S=>{let C=N[S];Array.isArray(C)?C.indexOf(t)!==-1&&(n[S]=!0):C[t]&&!(S in n)&&(n[S]=C[t])}),this.group(t,__classPrivateFieldGet(this,$p,`f`).getPositionalGroupName()),this.option(t,n)}recommendCommands(t=!0){return argsert(`[boolean]`,[t],arguments.length),__classPrivateFieldSet(this,Jp,t,`f`),this}required(t,n,S){return this.demand(t,n,S)}require(t,n,S){return this.demand(t,n,S)}requiresArg(t){return argsert(`<array|string|object> [number]`,[t],arguments.length),typeof t==`string`&&__classPrivateFieldGet(this,Bp,`f`).narg[t]||this[_m](this.requiresArg.bind(this),`narg`,t,NaN),this}showCompletionScript(t,n){return argsert(`[string] [string]`,[t,n],arguments.length),t||=this.$0,__classPrivateFieldGet(this,Rp,`f`).log(__classPrivateFieldGet(this,Tp,`f`).generateCompletionScript(t,n||__classPrivateFieldGet(this,Ep,`f`)||`completion`)),this}showHelp(t){if(argsert(`[string|function]`,[t],arguments.length),__classPrivateFieldSet(this,Fp,!0,`f`),!__classPrivateFieldGet(this,$p,`f`).hasCachedHelpMessage()){if(!this.parsed){let n=this[Im](__classPrivateFieldGet(this,qp,`f`),void 0,void 0,0,!0);if(isPromise(n))return n.then(()=>{__classPrivateFieldGet(this,$p,`f`).showHelp(t)}),this}let n=__classPrivateFieldGet(this,Sp,`f`).runDefaultBuilderOn(this);if(isPromise(n))return n.then(()=>{__classPrivateFieldGet(this,$p,`f`).showHelp(t)}),this}return __classPrivateFieldGet(this,$p,`f`).showHelp(t),this}scriptName(t){return this.customScriptName=!0,this.$0=t,this}showHelpOnFail(t,n){return argsert(`[boolean|string] [string]`,[t,n],arguments.length),__classPrivateFieldGet(this,$p,`f`).showHelpOnFail(t,n),this}showVersion(t){return argsert(`[string|function]`,[t],arguments.length),__classPrivateFieldGet(this,$p,`f`).showVersion(t),this}skipValidation(t){return argsert(`<array|string>`,[t],arguments.length),this[gm](`skipValidation`,t),this}strict(t){return argsert(`[boolean]`,[t],arguments.length),__classPrivateFieldSet(this,Xp,t!==!1,`f`),this}strictCommands(t){return argsert(`[boolean]`,[t],arguments.length),__classPrivateFieldSet(this,Zp,t!==!1,`f`),this}strictOptions(t){return argsert(`[boolean]`,[t],arguments.length),__classPrivateFieldSet(this,Qp,t!==!1,`f`),this}string(t){return argsert(`<array|string>`,[t],arguments.length),this[gm](`string`,t),this[zm](t),this}terminalWidth(){return argsert([],0),__classPrivateFieldGet(this,Yp,`f`).process.stdColumns}updateLocale(t){return this.updateStrings(t)}updateStrings(t){return argsert(`<object>`,[t],arguments.length),__classPrivateFieldSet(this,kp,!1,`f`),__classPrivateFieldGet(this,Yp,`f`).y18n.updateLocale(t),this}usage(t,n,S,C){if(argsert(`<string|null|undefined> [string|boolean] [function|object] [function]`,[t,n,S,C],arguments.length),n!==void 0){if(assertNotStrictEqual(t,null,__classPrivateFieldGet(this,Yp,`f`)),(t||``).match(/^\$0( |$)/))return this.command(t,n,S,C);throw new Sl(`.usage() description must start with $0 if being used as alias for .command()`)}else return __classPrivateFieldGet(this,$p,`f`).usage(t),this}usageConfiguration(t){return argsert(`<object>`,[t],arguments.length),__classPrivateFieldSet(this,em,t,`f`),this}version(t,n,S){let C=`version`;if(argsert(`[boolean|string] [string] [string]`,[t,n,S],arguments.length),__classPrivateFieldGet(this,tm,`f`)&&(this[om](__classPrivateFieldGet(this,tm,`f`)),__classPrivateFieldGet(this,$p,`f`).version(void 0),__classPrivateFieldSet(this,tm,null,`f`)),arguments.length===0)S=this[pm](),t=C;else if(arguments.length===1){if(t===!1)return this;S=t,t=C}else arguments.length===2&&(S=n,n=void 0);return __classPrivateFieldSet(this,tm,typeof t==`string`?t:C,`f`),n||=__classPrivateFieldGet(this,$p,`f`).deferY18nLookup(`Show version number`),__classPrivateFieldGet(this,$p,`f`).version(S||void 0),this.boolean(__classPrivateFieldGet(this,tm,`f`)),this.describe(__classPrivateFieldGet(this,tm,`f`),n),this}wrap(t){return argsert(`<number|null|undefined>`,[t],arguments.length),__classPrivateFieldGet(this,$p,`f`).wrap(t),this}[(Sp=new WeakMap,Cp=new WeakMap,wp=new WeakMap,Tp=new WeakMap,Ep=new WeakMap,Dp=new WeakMap,Op=new WeakMap,kp=new WeakMap,Ap=new WeakMap,jp=new WeakMap,Mp=new WeakMap,Np=new WeakMap,Pp=new WeakMap,Fp=new WeakMap,Ip=new WeakMap,Lp=new WeakMap,Rp=new WeakMap,zp=new WeakMap,Bp=new WeakMap,Vp=new WeakMap,Hp=new WeakMap,Up=new WeakMap,Wp=new WeakMap,Gp=new WeakMap,Kp=new WeakMap,qp=new WeakMap,Jp=new WeakMap,Yp=new WeakMap,Xp=new WeakMap,Zp=new WeakMap,Qp=new WeakMap,$p=new WeakMap,em=new WeakMap,tm=new WeakMap,nm=new WeakMap,im)](t){if(!t._||!t[`--`])return t;t._.push.apply(t._,t[`--`]);try{delete t[`--`]}catch{}return t}[am](){return{log:(...t)=>{this[jm]()||ge.log(...t),__classPrivateFieldSet(this,Fp,!0,`f`),__classPrivateFieldGet(this,zp,`f`).length&&__classPrivateFieldSet(this,zp,__classPrivateFieldGet(this,zp,`f`)+`
147
147
  `,`f`),__classPrivateFieldSet(this,zp,__classPrivateFieldGet(this,zp,`f`)+t.join(` `),`f`)},error:(...t)=>{this[jm]()||ge.error(...t),__classPrivateFieldSet(this,Fp,!0,`f`),__classPrivateFieldGet(this,zp,`f`).length&&__classPrivateFieldSet(this,zp,__classPrivateFieldGet(this,zp,`f`)+`
148
- `,`f`),__classPrivateFieldSet(this,zp,__classPrivateFieldGet(this,zp,`f`)+t.join(` `),`f`)}}}[om](t){objectKeys(__classPrivateFieldGet(this,Bp,`f`)).forEach(n=>{if((t=>t===`configObjects`)(n))return;let S=__classPrivateFieldGet(this,Bp,`f`)[n];Array.isArray(S)?S.includes(t)&&S.splice(S.indexOf(t),1):typeof S==`object`&&delete S[t]}),delete __classPrivateFieldGet(this,$p,`f`).getDescriptions()[t]}[sm](t,n,S){__classPrivateFieldGet(this,Ap,`f`)[S]||(__classPrivateFieldGet(this,Yp,`f`).process.emitWarning(t,n),__classPrivateFieldGet(this,Ap,`f`)[S]=!0)}[cm](){__classPrivateFieldGet(this,Mp,`f`).push({options:__classPrivateFieldGet(this,Bp,`f`),configObjects:__classPrivateFieldGet(this,Bp,`f`).configObjects.slice(0),exitProcess:__classPrivateFieldGet(this,jp,`f`),groups:__classPrivateFieldGet(this,Pp,`f`),strict:__classPrivateFieldGet(this,Xp,`f`),strictCommands:__classPrivateFieldGet(this,Zp,`f`),strictOptions:__classPrivateFieldGet(this,Qp,`f`),completionCommand:__classPrivateFieldGet(this,Ep,`f`),output:__classPrivateFieldGet(this,zp,`f`),exitError:__classPrivateFieldGet(this,Op,`f`),hasOutput:__classPrivateFieldGet(this,Fp,`f`),parsed:this.parsed,parseFn:__classPrivateFieldGet(this,Up,`f`),parseContext:__classPrivateFieldGet(this,Wp,`f`)}),__classPrivateFieldGet(this,$p,`f`).freeze(),__classPrivateFieldGet(this,nm,`f`).freeze(),__classPrivateFieldGet(this,Sp,`f`).freeze(),__classPrivateFieldGet(this,Np,`f`).freeze()}[lm](){let t=``,n;return n=/\b(node|iojs|electron)(\.exe)?$/.test(__classPrivateFieldGet(this,Yp,`f`).process.argv()[0])?__classPrivateFieldGet(this,Yp,`f`).process.argv().slice(1,2):__classPrivateFieldGet(this,Yp,`f`).process.argv().slice(0,1),t=n.map(t=>{let n=this[Pm](__classPrivateFieldGet(this,Cp,`f`),t);return t.match(/^(\/|([a-zA-Z]:)?\\)/)&&n.length<t.length?n:t}).join(` `).trim(),__classPrivateFieldGet(this,Yp,`f`).getEnv(`_`)&&__classPrivateFieldGet(this,Yp,`f`).getProcessArgvBin()===__classPrivateFieldGet(this,Yp,`f`).getEnv(`_`)&&(t=__classPrivateFieldGet(this,Yp,`f`).getEnv(`_`).replace(`${__classPrivateFieldGet(this,Yp,`f`).path.dirname(__classPrivateFieldGet(this,Yp,`f`).process.execPath())}/`,``)),t}[um](){return __classPrivateFieldGet(this,Hp,`f`)}[dm](){return __classPrivateFieldGet(this,em,`f`)}[fm](){if(!__classPrivateFieldGet(this,kp,`f`))return;let t=__classPrivateFieldGet(this,Yp,`f`).getEnv(`LC_ALL`)||__classPrivateFieldGet(this,Yp,`f`).getEnv(`LC_MESSAGES`)||__classPrivateFieldGet(this,Yp,`f`).getEnv(`LANG`)||__classPrivateFieldGet(this,Yp,`f`).getEnv(`LANGUAGE`)||`en_US`;this.locale(t.replace(/[.:].*/,``))}[pm](){return this[hm]().version||`unknown`}[mm](t){let n=t[`--`]?t[`--`]:t._;for(let t=0,S;(S=n[t])!==void 0;t++)__classPrivateFieldGet(this,Yp,`f`).Parser.looksLikeNumber(S)&&Number.isSafeInteger(Math.floor(parseFloat(`${S}`)))&&(n[t]=Number(S));return t}[hm](t){let n=t||`*`;if(__classPrivateFieldGet(this,Gp,`f`)[n])return __classPrivateFieldGet(this,Gp,`f`)[n];let S={};try{let n=t||__classPrivateFieldGet(this,Yp,`f`).mainFilename;__classPrivateFieldGet(this,Yp,`f`).path.extname(n)&&(n=__classPrivateFieldGet(this,Yp,`f`).path.dirname(n));let C=__classPrivateFieldGet(this,Yp,`f`).findUp(n,(t,n)=>{if(n.includes(`package.json`))return`package.json`});assertNotStrictEqual(C,void 0,__classPrivateFieldGet(this,Yp,`f`)),S=JSON.parse(__classPrivateFieldGet(this,Yp,`f`).readFileSync(C,`utf8`))}catch{}return __classPrivateFieldGet(this,Gp,`f`)[n]=S||{},__classPrivateFieldGet(this,Gp,`f`)[n]}[gm](t,n){n=[].concat(n),n.forEach(n=>{n=this[bm](n),__classPrivateFieldGet(this,Bp,`f`)[t].push(n)})}[_m](t,n,S,C){this[ym](t,n,S,C,(t,n,S)=>{__classPrivateFieldGet(this,Bp,`f`)[t][n]=S})}[vm](t,n,S,C){this[ym](t,n,S,C,(t,n,S)=>{__classPrivateFieldGet(this,Bp,`f`)[t][n]=(__classPrivateFieldGet(this,Bp,`f`)[t][n]||[]).concat(S)})}[ym](t,n,S,C,N){if(Array.isArray(S))S.forEach(n=>{t(n,C)});else if((t=>typeof t==`object`)(S))for(let n of objectKeys(S))t(n,S[n]);else N(n,this[bm](S),C)}[bm](t){return t===`__proto__`?`___proto___`:t}[xm](t,n){return this[_m](this[xm].bind(this),`key`,t,n),this}[Sm](){var t,n,S,C,N,F,I,H,W,q,Y,X;let Z=__classPrivateFieldGet(this,Mp,`f`).pop();assertNotStrictEqual(Z,void 0,__classPrivateFieldGet(this,Yp,`f`));let te;t=this,n=this,S=this,C=this,N=this,F=this,I=this,H=this,W=this,q=this,Y=this,X=this,{options:{set value(n){__classPrivateFieldSet(t,Bp,n,`f`)}}.value,configObjects:te,exitProcess:{set value(t){__classPrivateFieldSet(n,jp,t,`f`)}}.value,groups:{set value(t){__classPrivateFieldSet(S,Pp,t,`f`)}}.value,output:{set value(t){__classPrivateFieldSet(C,zp,t,`f`)}}.value,exitError:{set value(t){__classPrivateFieldSet(N,Op,t,`f`)}}.value,hasOutput:{set value(t){__classPrivateFieldSet(F,Fp,t,`f`)}}.value,parsed:this.parsed,strict:{set value(t){__classPrivateFieldSet(I,Xp,t,`f`)}}.value,strictCommands:{set value(t){__classPrivateFieldSet(H,Zp,t,`f`)}}.value,strictOptions:{set value(t){__classPrivateFieldSet(W,Qp,t,`f`)}}.value,completionCommand:{set value(t){__classPrivateFieldSet(q,Ep,t,`f`)}}.value,parseFn:{set value(t){__classPrivateFieldSet(Y,Up,t,`f`)}}.value,parseContext:{set value(t){__classPrivateFieldSet(X,Wp,t,`f`)}}.value}=Z,__classPrivateFieldGet(this,Bp,`f`).configObjects=te,__classPrivateFieldGet(this,$p,`f`).unfreeze(),__classPrivateFieldGet(this,nm,`f`).unfreeze(),__classPrivateFieldGet(this,Sp,`f`).unfreeze(),__classPrivateFieldGet(this,Np,`f`).unfreeze()}[Cm](t,n){return maybeAsyncResult(n,n=>(t(n),n))}getInternalMethods(){return{getCommandInstance:this[wm].bind(this),getContext:this[Tm].bind(this),getHasOutput:this[Em].bind(this),getLoggerInstance:this[Dm].bind(this),getParseContext:this[Om].bind(this),getParserConfiguration:this[um].bind(this),getUsageConfiguration:this[dm].bind(this),getUsageInstance:this[km].bind(this),getValidationInstance:this[Am].bind(this),hasParseCallback:this[jm].bind(this),isGlobalContext:this[Mm].bind(this),postProcess:this[Nm].bind(this),reset:this[Fm].bind(this),runValidation:this[Lm].bind(this),runYargsParserAndExecuteCommands:this[Im].bind(this),setHasOutput:this[Rm].bind(this)}}[wm](){return __classPrivateFieldGet(this,Sp,`f`)}[Tm](){return __classPrivateFieldGet(this,wp,`f`)}[Em](){return __classPrivateFieldGet(this,Fp,`f`)}[Dm](){return __classPrivateFieldGet(this,Rp,`f`)}[Om](){return __classPrivateFieldGet(this,Wp,`f`)||{}}[km](){return __classPrivateFieldGet(this,$p,`f`)}[Am](){return __classPrivateFieldGet(this,nm,`f`)}[jm](){return!!__classPrivateFieldGet(this,Up,`f`)}[Mm](){return __classPrivateFieldGet(this,Lp,`f`)}[Nm](t,n,S,C){return S||isPromise(t)?t:(n||(t=this[im](t)),(this[um]()[`parse-positional-numbers`]||this[um]()[`parse-positional-numbers`]===void 0)&&(t=this[mm](t)),C&&(t=applyMiddleware(t,this,__classPrivateFieldGet(this,Np,`f`).getMiddleware(),!1)),t)}[Fm](t={}){__classPrivateFieldSet(this,Bp,__classPrivateFieldGet(this,Bp,`f`)||{},`f`);let n={};n.local=__classPrivateFieldGet(this,Bp,`f`).local||[],n.configObjects=__classPrivateFieldGet(this,Bp,`f`).configObjects||[];let S={};return n.local.forEach(n=>{S[n]=!0,(t[n]||[]).forEach(t=>{S[t]=!0})}),Object.assign(__classPrivateFieldGet(this,Kp,`f`),Object.keys(__classPrivateFieldGet(this,Pp,`f`)).reduce((t,n)=>{let C=__classPrivateFieldGet(this,Pp,`f`)[n].filter(t=>!(t in S));return C.length>0&&(t[n]=C),t},{})),__classPrivateFieldSet(this,Pp,{},`f`),[`array`,`boolean`,`string`,`skipValidation`,`count`,`normalize`,`number`,`hiddenOptions`].forEach(t=>{n[t]=(__classPrivateFieldGet(this,Bp,`f`)[t]||[]).filter(t=>!S[t])}),[`narg`,`key`,`alias`,`default`,`defaultDescription`,`config`,`choices`,`demandedOptions`,`demandedCommands`,`deprecatedOptions`].forEach(t=>{n[t]=objFilter(__classPrivateFieldGet(this,Bp,`f`)[t],t=>!S[t])}),n.envPrefix=__classPrivateFieldGet(this,Bp,`f`).envPrefix,__classPrivateFieldSet(this,Bp,n,`f`),__classPrivateFieldSet(this,$p,__classPrivateFieldGet(this,$p,`f`)?__classPrivateFieldGet(this,$p,`f`).reset(S):usage(this,__classPrivateFieldGet(this,Yp,`f`)),`f`),__classPrivateFieldSet(this,nm,__classPrivateFieldGet(this,nm,`f`)?__classPrivateFieldGet(this,nm,`f`).reset(S):validation(this,__classPrivateFieldGet(this,$p,`f`),__classPrivateFieldGet(this,Yp,`f`)),`f`),__classPrivateFieldSet(this,Sp,__classPrivateFieldGet(this,Sp,`f`)?__classPrivateFieldGet(this,Sp,`f`).reset():command(__classPrivateFieldGet(this,$p,`f`),__classPrivateFieldGet(this,nm,`f`),__classPrivateFieldGet(this,Np,`f`),__classPrivateFieldGet(this,Yp,`f`)),`f`),__classPrivateFieldGet(this,Tp,`f`)||__classPrivateFieldSet(this,Tp,completion(this,__classPrivateFieldGet(this,$p,`f`),__classPrivateFieldGet(this,Sp,`f`),__classPrivateFieldGet(this,Yp,`f`)),`f`),__classPrivateFieldGet(this,Np,`f`).reset(),__classPrivateFieldSet(this,Ep,null,`f`),__classPrivateFieldSet(this,zp,``,`f`),__classPrivateFieldSet(this,Op,null,`f`),__classPrivateFieldSet(this,Fp,!1,`f`),this.parsed=!1,this}[Pm](t,n){return __classPrivateFieldGet(this,Yp,`f`).path.relative(t,n)}[Im](t,n,S,C=0,N=!1){let F=!!S||N;t||=__classPrivateFieldGet(this,qp,`f`),__classPrivateFieldGet(this,Bp,`f`).__=__classPrivateFieldGet(this,Yp,`f`).y18n.__,__classPrivateFieldGet(this,Bp,`f`).configuration=this[um]();let I=!!__classPrivateFieldGet(this,Bp,`f`).configuration[`populate--`],H=Object.assign({},__classPrivateFieldGet(this,Bp,`f`).configuration,{"populate--":!0}),W=__classPrivateFieldGet(this,Yp,`f`).Parser.detailed(t,Object.assign({},__classPrivateFieldGet(this,Bp,`f`),{configuration:{"parse-positional-numbers":!1,...H}})),q=Object.assign(W.argv,__classPrivateFieldGet(this,Wp,`f`)),Y,X=W.aliases,Z=!1,te=!1;Object.keys(q).forEach(t=>{t===__classPrivateFieldGet(this,Ip,`f`)&&q[t]?Z=!0:t===__classPrivateFieldGet(this,tm,`f`)&&q[t]&&(te=!0)}),q.$0=this.$0,this.parsed=W,C===0&&__classPrivateFieldGet(this,$p,`f`).clearCachedHelpMessage();try{if(this[fm](),n)return this[Nm](q,I,!!S,!1);__classPrivateFieldGet(this,Ip,`f`)&&[__classPrivateFieldGet(this,Ip,`f`)].concat(X[__classPrivateFieldGet(this,Ip,`f`)]||[]).filter(t=>t.length>1).includes(``+q._[q._.length-1])&&(q._.pop(),Z=!0),__classPrivateFieldSet(this,Lp,!1,`f`);let H=__classPrivateFieldGet(this,Sp,`f`).getCommands(),ne=__classPrivateFieldGet(this,Tp,`f`)?.completionKey?[__classPrivateFieldGet(this,Tp,`f`)?.completionKey,...this.getAliases()[__classPrivateFieldGet(this,Tp,`f`)?.completionKey]??[]].some(t=>Object.prototype.hasOwnProperty.call(q,t)):!1,re=Z||ne||N;if(q._.length){if(H.length){let t;for(let n=C||0,F;q._[n]!==void 0;n++)if(F=String(q._[n]),H.includes(F)&&F!==__classPrivateFieldGet(this,Ep,`f`)){let t=__classPrivateFieldGet(this,Sp,`f`).runCommand(F,this,W,n+1,N,Z||te||N);return this[Nm](t,I,!!S,!1)}else if(!t&&F!==__classPrivateFieldGet(this,Ep,`f`)){t=F;break}!__classPrivateFieldGet(this,Sp,`f`).hasDefaultCommand()&&__classPrivateFieldGet(this,Jp,`f`)&&t&&!re&&__classPrivateFieldGet(this,nm,`f`).recommendCommands(t,H)}__classPrivateFieldGet(this,Ep,`f`)&&q._.includes(__classPrivateFieldGet(this,Ep,`f`))&&!ne&&(__classPrivateFieldGet(this,jp,`f`)&&setBlocking(!0),this.showCompletionScript(),this.exit(0))}if(__classPrivateFieldGet(this,Sp,`f`).hasDefaultCommand()&&!re){let t=__classPrivateFieldGet(this,Sp,`f`).runCommand(null,this,W,0,N,Z||te||N);return this[Nm](t,I,!!S,!1)}if(ne){__classPrivateFieldGet(this,jp,`f`)&&setBlocking(!0),t=[].concat(t);let n=t.slice(t.indexOf(`--${__classPrivateFieldGet(this,Tp,`f`).completionKey}`)+1);return __classPrivateFieldGet(this,Tp,`f`).getCompletion(n,(t,n)=>{if(t)throw new Sl(t.message);(n||[]).forEach(t=>{__classPrivateFieldGet(this,Rp,`f`).log(t)}),this.exit(0)}),this[Nm](q,!I,!!S,!1)}if(__classPrivateFieldGet(this,Fp,`f`)||(Z?(__classPrivateFieldGet(this,jp,`f`)&&setBlocking(!0),F=!0,this.showHelp(t=>{__classPrivateFieldGet(this,Rp,`f`).log(t),this.exit(0)})):te&&(__classPrivateFieldGet(this,jp,`f`)&&setBlocking(!0),F=!0,__classPrivateFieldGet(this,$p,`f`).showVersion(`log`),this.exit(0))),!F&&__classPrivateFieldGet(this,Bp,`f`).skipValidation.length>0&&(F=Object.keys(q).some(t=>__classPrivateFieldGet(this,Bp,`f`).skipValidation.indexOf(t)>=0&&q[t]===!0)),!F){if(W.error)throw new Sl(W.error.message);if(!ne){let t=this[Lm](X,{},W.error);S||(Y=applyMiddleware(q,this,__classPrivateFieldGet(this,Np,`f`).getMiddleware(),!0)),Y=this[Cm](t,Y??q),isPromise(Y)&&!S&&(Y=Y.then(()=>applyMiddleware(q,this,__classPrivateFieldGet(this,Np,`f`).getMiddleware(),!1)))}}}catch(t){if(t instanceof Sl)__classPrivateFieldGet(this,$p,`f`).fail(t.message,t);else throw t}return this[Nm](Y??q,I,!!S,!0)}[Lm](t,n,S,C){let N={...this.getDemandedOptions()};return F=>{if(S)throw new Sl(S.message);__classPrivateFieldGet(this,nm,`f`).nonOptionCount(F),__classPrivateFieldGet(this,nm,`f`).requiredArguments(F,N);let I=!1;__classPrivateFieldGet(this,Zp,`f`)&&(I=__classPrivateFieldGet(this,nm,`f`).unknownCommands(F)),__classPrivateFieldGet(this,Xp,`f`)&&!I?__classPrivateFieldGet(this,nm,`f`).unknownArguments(F,t,n,!!C):__classPrivateFieldGet(this,Qp,`f`)&&__classPrivateFieldGet(this,nm,`f`).unknownArguments(F,t,{},!1,!1),__classPrivateFieldGet(this,nm,`f`).limitedChoices(F),__classPrivateFieldGet(this,nm,`f`).implications(F),__classPrivateFieldGet(this,nm,`f`).conflicting(F)}}[Rm](){__classPrivateFieldSet(this,Fp,!0,`f`)}[zm](t){if(typeof t==`string`)__classPrivateFieldGet(this,Bp,`f`).key[t]=!0;else for(let n of t)__classPrivateFieldGet(this,Bp,`f`).key[n]=!0}}}),Hm,Um=__esmMin(()=>{ep(),Vm(),Hm=YargsFactory($f)});function classifyCliFailure(t,n){return typeof t==`string`&&t.length>0?{kind:`usage`,message:t}:{kind:`runtime`}}var Wm=__esmMin(()=>{});function buildHeaders(t,n){let S={"user-agent":`gjsify-install/0.64.3-next.261`,"accept-encoding":n.acceptEncoding??`identity`};if(n.npmrc){let C=resolveAuthForUrl(t,n.npmrc);C&&(S.authorization=C)}if(n.headers)for(let[t,C]of Object.entries(n.headers))S[t.toLowerCase()]=C;return S}function resolveAuthForUrl(t,n){let S=pathPrefixes(new URL(t));for(let t of S){let S=n.authTokens[t];if(S)return`Bearer ${S}`;let C=n.basicAuth[t];if(C)return`Basic ${btoa(`${C.username}:${C.password}`)}`}return null}function pathPrefixes(t){let n=t.pathname.split(`/`).filter(Boolean),S=[];for(let C=n.length;C>=0;C--){let N=n.slice(0,C).join(`/`);S.push(N?`//${t.host}/${N}`:`//${t.host}`)}return S}var Gm=__esmMin(()=>{}),PackageNotFoundError,IntegrityError,RegistryTimeoutError,RegistryUnreachableError,Km=__esmMin(()=>{PackageNotFoundError=class extends Error{name;url;constructor(t,n){super(`Package not found in registry: ${t} (${n})`),this.name=t,this.url=n,this.name=`PackageNotFoundError`}},IntegrityError=class extends Error{url;integrity;constructor(t,n){super(`Tarball integrity mismatch for ${t} (expected ${n})`),this.url=t,this.integrity=n,this.name=`IntegrityError`}},RegistryTimeoutError=class extends Error{url;timeoutMs;attempts;constructor(t,n,S){let C=Math.round(n/100)/10,N=Math.round(n*S/100)/10;super(`@gjsify/npm-registry: GET ${t} timed out after ${C}s × ${S} attempt(s) (total ~${N}s). This usually means the registry CDN is slow or unreachable.`),this.url=t,this.timeoutMs=n,this.attempts=S,this.name=`RegistryTimeoutError`}},RegistryUnreachableError=class extends Error{url;attempts;elapsedMs;constructor(t,n,S,C){let N=Math.round(S/100)/10,F=C instanceof Error?C.message:String(C);super(`@gjsify/npm-registry: GET ${t} failed after ${n} attempt(s) over ~${N}s: ${F}. This usually means the registry or the network dropped out.`),this.url=t,this.attempts=n,this.elapsedMs=S,this.name=`RegistryUnreachableError`,this.cause=C}}});function registryFor(t,n){if(n&&t.startsWith(`@`)){let S=t.slice(0,t.indexOf(`/`)),C=n.scopes[S];if(C)return ensureTrailingSlash$1(C)}return n?.registry?ensureTrailingSlash$1(n.registry):qm}function parseNpmrc(t){let n={registry:qm,scopes:{},authTokens:{},basicAuth:{}},S=t.split(/\r?\n/),C={};for(let t of S){let S=t.replace(/^\s+|\s+$/g,``);if(!S||S.startsWith(`#`)||S.startsWith(`;`))continue;let N=S.indexOf(`=`);if(N<0)continue;let F=S.slice(0,N).trim(),I=expandEnv(stripQuotes(S.slice(N+1).trim()));if(F===`registry`){n.registry=ensureTrailingSlash$1(I);continue}let H=F.match(/^(@[^:]+):registry$/);if(H){n.scopes[H[1]]=ensureTrailingSlash$1(I);continue}let W=F.match(/^\/\/(.+):_authToken$/);if(W){n.authTokens[normalizeAuthHost(W[1])]=I;continue}let q=F.match(/^\/\/(.+):username$/);if(q){(C[normalizeAuthHost(q[1])]??={}).user=I;continue}let Y=F.match(/^\/\/(.+):_password$/);if(Y){let t=base64Decode$1(I);(C[normalizeAuthHost(Y[1])]??={}).pass=t;continue}}for(let[t,S]of Object.entries(C))S.user&&S.pass!==void 0&&(n.basicAuth[t]={username:S.user,password:S.pass});return n}function normalizeAuthHost(t){return`//${t.replace(/\/+$/,``)}`}function ensureTrailingSlash$1(t){return t.endsWith(`/`)?t:t+`/`}function stripQuotes(t){return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}function expandEnv(t){return t.replace(/\$\{([A-Z0-9_]+)\}/gi,(t,n)=>globalThis.process?.env?.[n]??``)}function base64Decode$1(t){return atob(t)}var qm,Jm=__esmMin(()=>{qm=`https://registry.npmjs.org/`,__name$1(ensureTrailingSlash$1,`ensureTrailingSlash`),__name$1(base64Decode$1,`base64Decode`)});async function fetchWithRetry(t,n,S){let C=S.fetch??globalThis.fetch;if(!C)throw Error(`@gjsify/npm-registry: globalThis.fetch is missing`);let N=Math.max(0,S.retries??5),F=Math.max(0,S.retryDelayMs??1e3),I=Math.max(0,S.timeoutMs??3e4),H=S.retryNotFound??!1,W=Date.now(),q=0,Y,X=0;for(;;){if(n.signal?.aborted)throw signalAbortError(n.signal);let Z=I>0?new AbortController:null,te=Z===null?null:setTimeout(()=>Z.abort(Error(`@gjsify/npm-registry: per-request timeout ${I}ms`)),I),ne=composeSignals(n.signal,Z?.signal);try{let F=await C(t,{...n,signal:ne}),I=isRetryableStatus(F.status)||H&&F.status===404;if(F.ok||!I||q>=N)return S.read?await S.read(F):F;try{await F.arrayBuffer()}catch{}Y=Error(`HTTP ${F.status} ${F.statusText}`)}catch(S){let C=Z!==null&&Z.signal.aborted,F=n.signal?.aborted===!0;if(C&&!F){if(X++,q>=N)throw new RegistryTimeoutError(t,I,X);Y=S}else if(F)throw signalAbortError(n.signal);else{if(!isRetryableError(S))throw S;if(q>=N)throw new RegistryUnreachableError(t,q+1,Date.now()-W,S);Y=S}}finally{te!==null&&clearTimeout(te)}let re=Math.min(F*2**q,8e3);S.onRetry?.({attempt:q+1,error:Y,delayMs:re}),await delay$1(re,n.signal),q++}}function composeSignals(t,n){return t?n?AbortSignal.any([t,n]):t:n}function isRetryableStatus(t){return t===408||t===425||t===429||t===500||t===502||t===503||t===504||t===521||t===522||t===524||t===525}function isRetryableError(t){if(t&&typeof t==`object`&&`name`in t&&t.name===`AbortError`)return!1;if(t instanceof TypeError)return!0;if(t&&typeof t==`object`&&`name`in t){let n=t.name;if(n===`FetchError`)return!0;if(n===`AbortError`)return!1}let n=t?.cause;if(n&&typeof n==`object`&&`code`in n){let t=n.code;if(typeof t==`string`)return t===`ECONNRESET`||t===`ECONNREFUSED`||t===`ENETUNREACH`||t===`ENOTFOUND`||t===`ETIMEDOUT`||t===`EAI_AGAIN`||t===`UND_ERR_SOCKET`||t===`UND_ERR_CONNECT_TIMEOUT`}return!1}function delay$1(t,n){return t<=0?Promise.resolve():new Promise((S,C)=>{let N=setTimeout(()=>{n?.removeEventListener?.(`abort`,onAbort),S()},t),onAbort=()=>{clearTimeout(N),C(signalAbortError(n))};if(n?.aborted){clearTimeout(N),C(signalAbortError(n));return}n?.addEventListener?.(`abort`,onAbort,{once:!0})})}function signalAbortError(t){let n=t&&`reason`in t?t.reason:void 0;if(n instanceof Error)return n;let S=Error(`Aborted`);return S.name=`AbortError`,S}var Ym=__esmMin(()=>{Km(),__name$1(delay$1,`delay`)});async function verifyIntegrity(t,n){let S=n.trim().split(/\s+/);for(let n of S){let S=n.indexOf(`-`);if(S<0)continue;let C=n.slice(0,S).toLowerCase(),N=n.slice(S+1),F=globalThis.crypto?.subtle;if(!F)throw Error(`@gjsify/npm-registry: globalThis.crypto.subtle is missing`);let I=subriToWebCryptoAlgo(C);if(!I)continue;let H=await F.digest(I,dataAsArrayBuffer(t));if(bytesToBase64(new Uint8Array(H))===N)return!0}return!1}function subriToWebCryptoAlgo(t){switch(t){case`sha1`:return`SHA-1`;case`sha256`:return`SHA-256`;case`sha384`:return`SHA-384`;case`sha512`:return`SHA-512`;default:return null}}function dataAsArrayBuffer(t){if(t.byteOffset===0&&t.byteLength===t.buffer.byteLength)return t.buffer;let n=new Uint8Array(t.byteLength);return n.set(t),n.buffer}function bytesToBase64(t){let n=``;for(let S=0;S<t.length;S++)n+=String.fromCharCode(t[S]);return btoa(n)}var Xm=__esmMin(()=>{});function assertPackument(t,n){if(!n||typeof n!=`object`)throw TypeError(`registry: ${t} packument is not an object`);let S=n;if(typeof S.name!=`string`)throw TypeError(`registry: ${t} packument missing string name`);if(!S.versions||typeof S.versions!=`object`)throw TypeError(`registry: ${t} packument missing versions map`)}function packumentUrl(t,n){let S=ensureTrailingSlash$1(n);if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n<0)throw TypeError(`Invalid scoped package name: ${t}`);let C=t.slice(0,n),N=t.slice(n+1);return`${S}${encodeURIComponent(C)}/${encodeURIComponent(N)}`}return`${S}${encodeURIComponent(t)}`}async function fetchPackumentConditional(t,n={}){let S=packumentUrl(t,n.registry??registryFor(t,n.npmrc)),C=buildHeaders(S,{...n,acceptEncoding:`gzip`});C.accept??=n.fullMetadata?`application/json`:`application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*`,n.ifNoneMatch&&(C[`if-none-match`]=n.ifNoneMatch);let N=await fetchWithRetry(S,{headers:C,signal:n.signal},{fetch:n.fetch,retries:n.retries,retryDelayMs:n.retryDelayMs,timeoutMs:n.timeoutMs,onRetry:n.onRetry,read:async n=>{if(n.status===304){try{await n.arrayBuffer()}catch{}return{status:`not-modified`}}if(!n.ok)throw n.status===404||n.status===406?new PackageNotFoundError(t,S):Error(`registry GET ${S} -> ${n.status} ${n.statusText}`);return{status:`fresh`,body:await decodeJsonBody(n),etag:n.headers.get(`etag`)??void 0}}});if(N.status===`not-modified`)return{status:`not-modified`,etag:n.ifNoneMatch};let F=N.body;return assertPackument(t,F),{status:`fresh`,packument:F,etag:N.etag}}async function decodeJsonBody(t){return t.json()}async function fetchPackument(t,n={}){let S=await fetchPackumentConditional(t,n);if(!S.packument)throw Error(`registry: ${t} returned 304 Not Modified to an unconditional request`);return S.packument}var Zm=__esmMin(()=>{Gm(),Km(),Jm(),Ym()});async function fetchTarball(t,n={}){let S=buildHeaders(t,{...n,acceptEncoding:`identity`});S.accept??=`application/octet-stream`;let C=await fetchWithRetry(t,{headers:S,signal:n.signal},{fetch:n.fetch,retries:n.retries,retryDelayMs:n.retryDelayMs,timeoutMs:n.timeoutMs,onRetry:n.onRetry,retryNotFound:n.retryNotFound??!0,read:async n=>{if(!n.ok)throw Error(`tarball GET ${t} -> ${n.status} ${n.statusText}`);return new Uint8Array(await n.arrayBuffer())}});if(n.integrity&&!await verifyIntegrity(C,n.integrity))throw new IntegrityError(t,n.integrity);return C}var Qm=__esmMin(()=>{Gm(),Km(),Ym(),Xm()});async function whoami(t,n){let S=`${ensureTrailingSlash$1(t)}-/whoami`,C=buildHeaders(S,{npmrc:n});C.accept=`application/json`;let N=globalThis.fetch;if(!N)throw Error(`@gjsify/npm-registry: globalThis.fetch is missing`);let F=await N(S,{method:`GET`,headers:C});if(!F.ok)throw Error(`whoami GET ${S} -> ${F.status} ${F.statusText}`);let I=await F.json();if(I&&typeof I==`object`&&`username`in I){let t=I.username;if(typeof t==`string`&&t.length>0)return{username:t}}return{}}var $m=__esmMin(()=>{Gm(),Jm()}),eh=__esmMin(()=>{Gm(),Km(),Jm(),Xm(),Zm(),Qm(),$m()});function escapePackageName(t){return t.replace(`/`,`%2f`)}function buildPublishHeaders(t,n){let S=buildHeaders(t,{npmrc:n.npmrc});return S[`content-type`]=`application/json`,S[`npm-command`]=`publish`,S[`npm-auth-type`]=n.otp?`legacy`:`web`,S[`user-agent`]=n.userAgent??defaultUserAgent(),n.otp&&(S[`npm-otp`]=n.otp),n.authorization&&(S.authorization=n.authorization),S}function cliVersion(){return th===void 0&&(th=`0.64.3-next.261`),th}function cliPackageDir(){let t=globalThis.process?.env?.GJSIFY_CLI_PACKAGE_JSON,n;try{n=En(t||fileURLToPath(import.meta.url))}catch{return null}for(let t=0;t<12;t++){try{if(JSON.parse(readFileSync(`${n}/package.json`,`utf8`)).name===`@gjsify/cli`)return n}catch{}let t=En(n);if(t===n)break;n=t}return null}function defaultUserAgent(){let t=globalThis.process,n=t?.arch??`x64`,S=t?.platform??`linux`;return`gjsify-publish/${cliVersion()} (${S} ${n})`}var th,nh=__esmMin(()=>{Rd(),Pn(),Gn(),eh()}),rh,ih=__esmMin(()=>{rh=`gjsify`});function parseDeclaredChannel(t,n){if(!(t===void 0||t===``)){if(ah.includes(t))return t;throw Error(`${n}: "${String(t)}" is not a distribution channel. Known: ${ah.join(`, `)}.`)}}function channelAllowsDonations(t){return t!==void 0&&oh[t]===!0}var ah,oh,sh,ch=__esmMin(()=>{ah=[`flathub`,`web`,`microsoft-store`,`apple-app-store`],oh={flathub:!0,web:!0,"microsoft-store":!1,"apple-app-store":!1},sh=`GJSIFY_CHANNEL`}),lh=__commonJSMin(((t,n)=>{let S=(Pn(),__toCommonJS(yn)),C=(Il(),__toCommonJS(Ml)),N=(Rd(),__toCommonJS(Id)),resolveFrom=(t,n,F)=>{if(typeof t!=`string`)throw TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof t}\``);if(typeof n!=`string`)throw TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof n}\``);try{t=N.realpathSync(t)}catch(n){if(n.code===`ENOENT`)t=S.resolve(t);else if(F)return null;else throw n}let I=S.join(t,`noop.js`),resolveFileName=()=>C._resolveFilename(n,{id:I,filename:I,paths:C._nodeModulePaths(t)});if(F)try{return resolveFileName()}catch{return null}return resolveFileName()};n.exports=(t,n)=>resolveFrom(t,n),n.exports.silent=(t,n)=>resolveFrom(t,n,!0)})),uh=__commonJSMin(((t,n)=>{let callsites=()=>{let t=Error.prepareStackTrace;Error.prepareStackTrace=(t,n)=>n;let n=Error().stack.slice(1);return Error.prepareStackTrace=t,n};n.exports=callsites,n.exports.default=callsites})),dh=__commonJSMin(((t,n)=>{let S=uh();n.exports=t=>{let n=S();if(!t)return n[2].getFileName();let C=!1;n.shift();for(let S of n){let n=S.getFileName();if(typeof n==`string`){if(n===t){C=!0;continue}if(n!==`module.js`&&C&&n!==t)return n}}}})),fh=__commonJSMin(((t,n)=>{var{__gjsifyModuleDir:S,__gjsifyModuleFile:C}=(Bl(),__toCommonJS(Ll)),N=S(`import-fresh/index.js`),F=C(`import-fresh/index.js`);let I=(Pn(),__toCommonJS(yn)),H=lh(),W=dh();n.exports=t=>{if(typeof t!=`string`)throw TypeError(`Expected a string`);let n=W(F),S=n?I.dirname(n):N,C=H(S,t),q=Y.cache[C];if(q&&q.parent){let t=q.parent.children.length;for(;t--;)q.parent.children[t].id===C&&q.parent.children.splice(t,1)}delete Y.cache[C];let X=Y.cache[n];return X===void 0||X.require===void 0?Y(C):X.require(C)}})),ph=__commonJSMin(((t,n)=>{n.exports=function isArrayish(t){return t?t instanceof Array||Array.isArray(t)||t.length>=0&&t.splice instanceof Function:!1}})),mh=__commonJSMin(((t,n)=>{var S=(Tu(),__toCommonJS(xu)),C=ph(),N=function errorEx(t,n){(!t||t.constructor!==String)&&(n=t||{},t=Error.name);var N=function ErrorEXError(S){if(!this)return new ErrorEXError(S);S=S instanceof Error?S.message:S||this.message,Error.call(this,S),Error.captureStackTrace(this,N),this.name=t,Object.defineProperty(this,"message",{configurable:!0,enumerable:!1,get:function(){var t=S.split(/\r?\n/g);for(var N in n)if(n.hasOwnProperty(N)){var F=n[N];`message`in F&&(t=F.message(this[N],t)||t,C(t)||(t=[t]))}return t.join(`
148
+ `,`f`),__classPrivateFieldSet(this,zp,__classPrivateFieldGet(this,zp,`f`)+t.join(` `),`f`)}}}[om](t){objectKeys(__classPrivateFieldGet(this,Bp,`f`)).forEach(n=>{if((t=>t===`configObjects`)(n))return;let S=__classPrivateFieldGet(this,Bp,`f`)[n];Array.isArray(S)?S.includes(t)&&S.splice(S.indexOf(t),1):typeof S==`object`&&delete S[t]}),delete __classPrivateFieldGet(this,$p,`f`).getDescriptions()[t]}[sm](t,n,S){__classPrivateFieldGet(this,Ap,`f`)[S]||(__classPrivateFieldGet(this,Yp,`f`).process.emitWarning(t,n),__classPrivateFieldGet(this,Ap,`f`)[S]=!0)}[cm](){__classPrivateFieldGet(this,Mp,`f`).push({options:__classPrivateFieldGet(this,Bp,`f`),configObjects:__classPrivateFieldGet(this,Bp,`f`).configObjects.slice(0),exitProcess:__classPrivateFieldGet(this,jp,`f`),groups:__classPrivateFieldGet(this,Pp,`f`),strict:__classPrivateFieldGet(this,Xp,`f`),strictCommands:__classPrivateFieldGet(this,Zp,`f`),strictOptions:__classPrivateFieldGet(this,Qp,`f`),completionCommand:__classPrivateFieldGet(this,Ep,`f`),output:__classPrivateFieldGet(this,zp,`f`),exitError:__classPrivateFieldGet(this,Op,`f`),hasOutput:__classPrivateFieldGet(this,Fp,`f`),parsed:this.parsed,parseFn:__classPrivateFieldGet(this,Up,`f`),parseContext:__classPrivateFieldGet(this,Wp,`f`)}),__classPrivateFieldGet(this,$p,`f`).freeze(),__classPrivateFieldGet(this,nm,`f`).freeze(),__classPrivateFieldGet(this,Sp,`f`).freeze(),__classPrivateFieldGet(this,Np,`f`).freeze()}[lm](){let t=``,n;return n=/\b(node|iojs|electron)(\.exe)?$/.test(__classPrivateFieldGet(this,Yp,`f`).process.argv()[0])?__classPrivateFieldGet(this,Yp,`f`).process.argv().slice(1,2):__classPrivateFieldGet(this,Yp,`f`).process.argv().slice(0,1),t=n.map(t=>{let n=this[Pm](__classPrivateFieldGet(this,Cp,`f`),t);return t.match(/^(\/|([a-zA-Z]:)?\\)/)&&n.length<t.length?n:t}).join(` `).trim(),__classPrivateFieldGet(this,Yp,`f`).getEnv(`_`)&&__classPrivateFieldGet(this,Yp,`f`).getProcessArgvBin()===__classPrivateFieldGet(this,Yp,`f`).getEnv(`_`)&&(t=__classPrivateFieldGet(this,Yp,`f`).getEnv(`_`).replace(`${__classPrivateFieldGet(this,Yp,`f`).path.dirname(__classPrivateFieldGet(this,Yp,`f`).process.execPath())}/`,``)),t}[um](){return __classPrivateFieldGet(this,Hp,`f`)}[dm](){return __classPrivateFieldGet(this,em,`f`)}[fm](){if(!__classPrivateFieldGet(this,kp,`f`))return;let t=__classPrivateFieldGet(this,Yp,`f`).getEnv(`LC_ALL`)||__classPrivateFieldGet(this,Yp,`f`).getEnv(`LC_MESSAGES`)||__classPrivateFieldGet(this,Yp,`f`).getEnv(`LANG`)||__classPrivateFieldGet(this,Yp,`f`).getEnv(`LANGUAGE`)||`en_US`;this.locale(t.replace(/[.:].*/,``))}[pm](){return this[hm]().version||`unknown`}[mm](t){let n=t[`--`]?t[`--`]:t._;for(let t=0,S;(S=n[t])!==void 0;t++)__classPrivateFieldGet(this,Yp,`f`).Parser.looksLikeNumber(S)&&Number.isSafeInteger(Math.floor(parseFloat(`${S}`)))&&(n[t]=Number(S));return t}[hm](t){let n=t||`*`;if(__classPrivateFieldGet(this,Gp,`f`)[n])return __classPrivateFieldGet(this,Gp,`f`)[n];let S={};try{let n=t||__classPrivateFieldGet(this,Yp,`f`).mainFilename;__classPrivateFieldGet(this,Yp,`f`).path.extname(n)&&(n=__classPrivateFieldGet(this,Yp,`f`).path.dirname(n));let C=__classPrivateFieldGet(this,Yp,`f`).findUp(n,(t,n)=>{if(n.includes(`package.json`))return`package.json`});assertNotStrictEqual(C,void 0,__classPrivateFieldGet(this,Yp,`f`)),S=JSON.parse(__classPrivateFieldGet(this,Yp,`f`).readFileSync(C,`utf8`))}catch{}return __classPrivateFieldGet(this,Gp,`f`)[n]=S||{},__classPrivateFieldGet(this,Gp,`f`)[n]}[gm](t,n){n=[].concat(n),n.forEach(n=>{n=this[bm](n),__classPrivateFieldGet(this,Bp,`f`)[t].push(n)})}[_m](t,n,S,C){this[ym](t,n,S,C,(t,n,S)=>{__classPrivateFieldGet(this,Bp,`f`)[t][n]=S})}[vm](t,n,S,C){this[ym](t,n,S,C,(t,n,S)=>{__classPrivateFieldGet(this,Bp,`f`)[t][n]=(__classPrivateFieldGet(this,Bp,`f`)[t][n]||[]).concat(S)})}[ym](t,n,S,C,N){if(Array.isArray(S))S.forEach(n=>{t(n,C)});else if((t=>typeof t==`object`)(S))for(let n of objectKeys(S))t(n,S[n]);else N(n,this[bm](S),C)}[bm](t){return t===`__proto__`?`___proto___`:t}[xm](t,n){return this[_m](this[xm].bind(this),`key`,t,n),this}[Sm](){var t,n,S,C,N,F,I,H,W,q,Y,X;let Z=__classPrivateFieldGet(this,Mp,`f`).pop();assertNotStrictEqual(Z,void 0,__classPrivateFieldGet(this,Yp,`f`));let te;t=this,n=this,S=this,C=this,N=this,F=this,I=this,H=this,W=this,q=this,Y=this,X=this,{options:{set value(n){__classPrivateFieldSet(t,Bp,n,`f`)}}.value,configObjects:te,exitProcess:{set value(t){__classPrivateFieldSet(n,jp,t,`f`)}}.value,groups:{set value(t){__classPrivateFieldSet(S,Pp,t,`f`)}}.value,output:{set value(t){__classPrivateFieldSet(C,zp,t,`f`)}}.value,exitError:{set value(t){__classPrivateFieldSet(N,Op,t,`f`)}}.value,hasOutput:{set value(t){__classPrivateFieldSet(F,Fp,t,`f`)}}.value,parsed:this.parsed,strict:{set value(t){__classPrivateFieldSet(I,Xp,t,`f`)}}.value,strictCommands:{set value(t){__classPrivateFieldSet(H,Zp,t,`f`)}}.value,strictOptions:{set value(t){__classPrivateFieldSet(W,Qp,t,`f`)}}.value,completionCommand:{set value(t){__classPrivateFieldSet(q,Ep,t,`f`)}}.value,parseFn:{set value(t){__classPrivateFieldSet(Y,Up,t,`f`)}}.value,parseContext:{set value(t){__classPrivateFieldSet(X,Wp,t,`f`)}}.value}=Z,__classPrivateFieldGet(this,Bp,`f`).configObjects=te,__classPrivateFieldGet(this,$p,`f`).unfreeze(),__classPrivateFieldGet(this,nm,`f`).unfreeze(),__classPrivateFieldGet(this,Sp,`f`).unfreeze(),__classPrivateFieldGet(this,Np,`f`).unfreeze()}[Cm](t,n){return maybeAsyncResult(n,n=>(t(n),n))}getInternalMethods(){return{getCommandInstance:this[wm].bind(this),getContext:this[Tm].bind(this),getHasOutput:this[Em].bind(this),getLoggerInstance:this[Dm].bind(this),getParseContext:this[Om].bind(this),getParserConfiguration:this[um].bind(this),getUsageConfiguration:this[dm].bind(this),getUsageInstance:this[km].bind(this),getValidationInstance:this[Am].bind(this),hasParseCallback:this[jm].bind(this),isGlobalContext:this[Mm].bind(this),postProcess:this[Nm].bind(this),reset:this[Fm].bind(this),runValidation:this[Lm].bind(this),runYargsParserAndExecuteCommands:this[Im].bind(this),setHasOutput:this[Rm].bind(this)}}[wm](){return __classPrivateFieldGet(this,Sp,`f`)}[Tm](){return __classPrivateFieldGet(this,wp,`f`)}[Em](){return __classPrivateFieldGet(this,Fp,`f`)}[Dm](){return __classPrivateFieldGet(this,Rp,`f`)}[Om](){return __classPrivateFieldGet(this,Wp,`f`)||{}}[km](){return __classPrivateFieldGet(this,$p,`f`)}[Am](){return __classPrivateFieldGet(this,nm,`f`)}[jm](){return!!__classPrivateFieldGet(this,Up,`f`)}[Mm](){return __classPrivateFieldGet(this,Lp,`f`)}[Nm](t,n,S,C){return S||isPromise(t)?t:(n||(t=this[im](t)),(this[um]()[`parse-positional-numbers`]||this[um]()[`parse-positional-numbers`]===void 0)&&(t=this[mm](t)),C&&(t=applyMiddleware(t,this,__classPrivateFieldGet(this,Np,`f`).getMiddleware(),!1)),t)}[Fm](t={}){__classPrivateFieldSet(this,Bp,__classPrivateFieldGet(this,Bp,`f`)||{},`f`);let n={};n.local=__classPrivateFieldGet(this,Bp,`f`).local||[],n.configObjects=__classPrivateFieldGet(this,Bp,`f`).configObjects||[];let S={};return n.local.forEach(n=>{S[n]=!0,(t[n]||[]).forEach(t=>{S[t]=!0})}),Object.assign(__classPrivateFieldGet(this,Kp,`f`),Object.keys(__classPrivateFieldGet(this,Pp,`f`)).reduce((t,n)=>{let C=__classPrivateFieldGet(this,Pp,`f`)[n].filter(t=>!(t in S));return C.length>0&&(t[n]=C),t},{})),__classPrivateFieldSet(this,Pp,{},`f`),[`array`,`boolean`,`string`,`skipValidation`,`count`,`normalize`,`number`,`hiddenOptions`].forEach(t=>{n[t]=(__classPrivateFieldGet(this,Bp,`f`)[t]||[]).filter(t=>!S[t])}),[`narg`,`key`,`alias`,`default`,`defaultDescription`,`config`,`choices`,`demandedOptions`,`demandedCommands`,`deprecatedOptions`].forEach(t=>{n[t]=objFilter(__classPrivateFieldGet(this,Bp,`f`)[t],t=>!S[t])}),n.envPrefix=__classPrivateFieldGet(this,Bp,`f`).envPrefix,__classPrivateFieldSet(this,Bp,n,`f`),__classPrivateFieldSet(this,$p,__classPrivateFieldGet(this,$p,`f`)?__classPrivateFieldGet(this,$p,`f`).reset(S):usage(this,__classPrivateFieldGet(this,Yp,`f`)),`f`),__classPrivateFieldSet(this,nm,__classPrivateFieldGet(this,nm,`f`)?__classPrivateFieldGet(this,nm,`f`).reset(S):validation(this,__classPrivateFieldGet(this,$p,`f`),__classPrivateFieldGet(this,Yp,`f`)),`f`),__classPrivateFieldSet(this,Sp,__classPrivateFieldGet(this,Sp,`f`)?__classPrivateFieldGet(this,Sp,`f`).reset():command(__classPrivateFieldGet(this,$p,`f`),__classPrivateFieldGet(this,nm,`f`),__classPrivateFieldGet(this,Np,`f`),__classPrivateFieldGet(this,Yp,`f`)),`f`),__classPrivateFieldGet(this,Tp,`f`)||__classPrivateFieldSet(this,Tp,completion(this,__classPrivateFieldGet(this,$p,`f`),__classPrivateFieldGet(this,Sp,`f`),__classPrivateFieldGet(this,Yp,`f`)),`f`),__classPrivateFieldGet(this,Np,`f`).reset(),__classPrivateFieldSet(this,Ep,null,`f`),__classPrivateFieldSet(this,zp,``,`f`),__classPrivateFieldSet(this,Op,null,`f`),__classPrivateFieldSet(this,Fp,!1,`f`),this.parsed=!1,this}[Pm](t,n){return __classPrivateFieldGet(this,Yp,`f`).path.relative(t,n)}[Im](t,n,S,C=0,N=!1){let F=!!S||N;t||=__classPrivateFieldGet(this,qp,`f`),__classPrivateFieldGet(this,Bp,`f`).__=__classPrivateFieldGet(this,Yp,`f`).y18n.__,__classPrivateFieldGet(this,Bp,`f`).configuration=this[um]();let I=!!__classPrivateFieldGet(this,Bp,`f`).configuration[`populate--`],H=Object.assign({},__classPrivateFieldGet(this,Bp,`f`).configuration,{"populate--":!0}),W=__classPrivateFieldGet(this,Yp,`f`).Parser.detailed(t,Object.assign({},__classPrivateFieldGet(this,Bp,`f`),{configuration:{"parse-positional-numbers":!1,...H}})),q=Object.assign(W.argv,__classPrivateFieldGet(this,Wp,`f`)),Y,X=W.aliases,Z=!1,te=!1;Object.keys(q).forEach(t=>{t===__classPrivateFieldGet(this,Ip,`f`)&&q[t]?Z=!0:t===__classPrivateFieldGet(this,tm,`f`)&&q[t]&&(te=!0)}),q.$0=this.$0,this.parsed=W,C===0&&__classPrivateFieldGet(this,$p,`f`).clearCachedHelpMessage();try{if(this[fm](),n)return this[Nm](q,I,!!S,!1);__classPrivateFieldGet(this,Ip,`f`)&&[__classPrivateFieldGet(this,Ip,`f`)].concat(X[__classPrivateFieldGet(this,Ip,`f`)]||[]).filter(t=>t.length>1).includes(``+q._[q._.length-1])&&(q._.pop(),Z=!0),__classPrivateFieldSet(this,Lp,!1,`f`);let H=__classPrivateFieldGet(this,Sp,`f`).getCommands(),ne=__classPrivateFieldGet(this,Tp,`f`)?.completionKey?[__classPrivateFieldGet(this,Tp,`f`)?.completionKey,...this.getAliases()[__classPrivateFieldGet(this,Tp,`f`)?.completionKey]??[]].some(t=>Object.prototype.hasOwnProperty.call(q,t)):!1,re=Z||ne||N;if(q._.length){if(H.length){let t;for(let n=C||0,F;q._[n]!==void 0;n++)if(F=String(q._[n]),H.includes(F)&&F!==__classPrivateFieldGet(this,Ep,`f`)){let t=__classPrivateFieldGet(this,Sp,`f`).runCommand(F,this,W,n+1,N,Z||te||N);return this[Nm](t,I,!!S,!1)}else if(!t&&F!==__classPrivateFieldGet(this,Ep,`f`)){t=F;break}!__classPrivateFieldGet(this,Sp,`f`).hasDefaultCommand()&&__classPrivateFieldGet(this,Jp,`f`)&&t&&!re&&__classPrivateFieldGet(this,nm,`f`).recommendCommands(t,H)}__classPrivateFieldGet(this,Ep,`f`)&&q._.includes(__classPrivateFieldGet(this,Ep,`f`))&&!ne&&(__classPrivateFieldGet(this,jp,`f`)&&setBlocking(!0),this.showCompletionScript(),this.exit(0))}if(__classPrivateFieldGet(this,Sp,`f`).hasDefaultCommand()&&!re){let t=__classPrivateFieldGet(this,Sp,`f`).runCommand(null,this,W,0,N,Z||te||N);return this[Nm](t,I,!!S,!1)}if(ne){__classPrivateFieldGet(this,jp,`f`)&&setBlocking(!0),t=[].concat(t);let n=t.slice(t.indexOf(`--${__classPrivateFieldGet(this,Tp,`f`).completionKey}`)+1);return __classPrivateFieldGet(this,Tp,`f`).getCompletion(n,(t,n)=>{if(t)throw new Sl(t.message);(n||[]).forEach(t=>{__classPrivateFieldGet(this,Rp,`f`).log(t)}),this.exit(0)}),this[Nm](q,!I,!!S,!1)}if(__classPrivateFieldGet(this,Fp,`f`)||(Z?(__classPrivateFieldGet(this,jp,`f`)&&setBlocking(!0),F=!0,this.showHelp(t=>{__classPrivateFieldGet(this,Rp,`f`).log(t),this.exit(0)})):te&&(__classPrivateFieldGet(this,jp,`f`)&&setBlocking(!0),F=!0,__classPrivateFieldGet(this,$p,`f`).showVersion(`log`),this.exit(0))),!F&&__classPrivateFieldGet(this,Bp,`f`).skipValidation.length>0&&(F=Object.keys(q).some(t=>__classPrivateFieldGet(this,Bp,`f`).skipValidation.indexOf(t)>=0&&q[t]===!0)),!F){if(W.error)throw new Sl(W.error.message);if(!ne){let t=this[Lm](X,{},W.error);S||(Y=applyMiddleware(q,this,__classPrivateFieldGet(this,Np,`f`).getMiddleware(),!0)),Y=this[Cm](t,Y??q),isPromise(Y)&&!S&&(Y=Y.then(()=>applyMiddleware(q,this,__classPrivateFieldGet(this,Np,`f`).getMiddleware(),!1)))}}}catch(t){if(t instanceof Sl)__classPrivateFieldGet(this,$p,`f`).fail(t.message,t);else throw t}return this[Nm](Y??q,I,!!S,!0)}[Lm](t,n,S,C){let N={...this.getDemandedOptions()};return F=>{if(S)throw new Sl(S.message);__classPrivateFieldGet(this,nm,`f`).nonOptionCount(F),__classPrivateFieldGet(this,nm,`f`).requiredArguments(F,N);let I=!1;__classPrivateFieldGet(this,Zp,`f`)&&(I=__classPrivateFieldGet(this,nm,`f`).unknownCommands(F)),__classPrivateFieldGet(this,Xp,`f`)&&!I?__classPrivateFieldGet(this,nm,`f`).unknownArguments(F,t,n,!!C):__classPrivateFieldGet(this,Qp,`f`)&&__classPrivateFieldGet(this,nm,`f`).unknownArguments(F,t,{},!1,!1),__classPrivateFieldGet(this,nm,`f`).limitedChoices(F),__classPrivateFieldGet(this,nm,`f`).implications(F),__classPrivateFieldGet(this,nm,`f`).conflicting(F)}}[Rm](){__classPrivateFieldSet(this,Fp,!0,`f`)}[zm](t){if(typeof t==`string`)__classPrivateFieldGet(this,Bp,`f`).key[t]=!0;else for(let n of t)__classPrivateFieldGet(this,Bp,`f`).key[n]=!0}}}),Hm,Um=__esmMin(()=>{ep(),Vm(),Hm=YargsFactory($f)});function classifyCliFailure(t,n){return typeof t==`string`&&t.length>0?{kind:`usage`,message:t}:{kind:`runtime`}}var Wm=__esmMin(()=>{});function buildHeaders(t,n){let S={"user-agent":`gjsify-install/0.64.4`,"accept-encoding":n.acceptEncoding??`identity`};if(n.npmrc){let C=resolveAuthForUrl(t,n.npmrc);C&&(S.authorization=C)}if(n.headers)for(let[t,C]of Object.entries(n.headers))S[t.toLowerCase()]=C;return S}function resolveAuthForUrl(t,n){let S=pathPrefixes(new URL(t));for(let t of S){let S=n.authTokens[t];if(S)return`Bearer ${S}`;let C=n.basicAuth[t];if(C)return`Basic ${btoa(`${C.username}:${C.password}`)}`}return null}function pathPrefixes(t){let n=t.pathname.split(`/`).filter(Boolean),S=[];for(let C=n.length;C>=0;C--){let N=n.slice(0,C).join(`/`);S.push(N?`//${t.host}/${N}`:`//${t.host}`)}return S}var Gm=__esmMin(()=>{}),PackageNotFoundError,IntegrityError,RegistryTimeoutError,RegistryUnreachableError,Km=__esmMin(()=>{PackageNotFoundError=class extends Error{name;url;constructor(t,n){super(`Package not found in registry: ${t} (${n})`),this.name=t,this.url=n,this.name=`PackageNotFoundError`}},IntegrityError=class extends Error{url;integrity;constructor(t,n){super(`Tarball integrity mismatch for ${t} (expected ${n})`),this.url=t,this.integrity=n,this.name=`IntegrityError`}},RegistryTimeoutError=class extends Error{url;timeoutMs;attempts;constructor(t,n,S){let C=Math.round(n/100)/10,N=Math.round(n*S/100)/10;super(`@gjsify/npm-registry: GET ${t} timed out after ${C}s × ${S} attempt(s) (total ~${N}s). This usually means the registry CDN is slow or unreachable.`),this.url=t,this.timeoutMs=n,this.attempts=S,this.name=`RegistryTimeoutError`}},RegistryUnreachableError=class extends Error{url;attempts;elapsedMs;constructor(t,n,S,C){let N=Math.round(S/100)/10,F=C instanceof Error?C.message:String(C);super(`@gjsify/npm-registry: GET ${t} failed after ${n} attempt(s) over ~${N}s: ${F}. This usually means the registry or the network dropped out.`),this.url=t,this.attempts=n,this.elapsedMs=S,this.name=`RegistryUnreachableError`,this.cause=C}}});function registryFor(t,n){if(n&&t.startsWith(`@`)){let S=t.slice(0,t.indexOf(`/`)),C=n.scopes[S];if(C)return ensureTrailingSlash$1(C)}return n?.registry?ensureTrailingSlash$1(n.registry):qm}function parseNpmrc(t){let n={registry:qm,scopes:{},authTokens:{},basicAuth:{}},S=t.split(/\r?\n/),C={};for(let t of S){let S=t.replace(/^\s+|\s+$/g,``);if(!S||S.startsWith(`#`)||S.startsWith(`;`))continue;let N=S.indexOf(`=`);if(N<0)continue;let F=S.slice(0,N).trim(),I=expandEnv(stripQuotes(S.slice(N+1).trim()));if(F===`registry`){n.registry=ensureTrailingSlash$1(I);continue}let H=F.match(/^(@[^:]+):registry$/);if(H){n.scopes[H[1]]=ensureTrailingSlash$1(I);continue}let W=F.match(/^\/\/(.+):_authToken$/);if(W){n.authTokens[normalizeAuthHost(W[1])]=I;continue}let q=F.match(/^\/\/(.+):username$/);if(q){(C[normalizeAuthHost(q[1])]??={}).user=I;continue}let Y=F.match(/^\/\/(.+):_password$/);if(Y){let t=base64Decode$1(I);(C[normalizeAuthHost(Y[1])]??={}).pass=t;continue}}for(let[t,S]of Object.entries(C))S.user&&S.pass!==void 0&&(n.basicAuth[t]={username:S.user,password:S.pass});return n}function normalizeAuthHost(t){return`//${t.replace(/\/+$/,``)}`}function ensureTrailingSlash$1(t){return t.endsWith(`/`)?t:t+`/`}function stripQuotes(t){return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?t.slice(1,-1):t}function expandEnv(t){return t.replace(/\$\{([A-Z0-9_]+)\}/gi,(t,n)=>globalThis.process?.env?.[n]??``)}function base64Decode$1(t){return atob(t)}var qm,Jm=__esmMin(()=>{qm=`https://registry.npmjs.org/`,__name$1(ensureTrailingSlash$1,`ensureTrailingSlash`),__name$1(base64Decode$1,`base64Decode`)});async function fetchWithRetry(t,n,S){let C=S.fetch??globalThis.fetch;if(!C)throw Error(`@gjsify/npm-registry: globalThis.fetch is missing`);let N=Math.max(0,S.retries??5),F=Math.max(0,S.retryDelayMs??1e3),I=Math.max(0,S.timeoutMs??3e4),H=S.retryNotFound??!1,W=Date.now(),q=0,Y,X=0;for(;;){if(n.signal?.aborted)throw signalAbortError(n.signal);let Z=I>0?new AbortController:null,te=Z===null?null:setTimeout(()=>Z.abort(Error(`@gjsify/npm-registry: per-request timeout ${I}ms`)),I),ne=composeSignals(n.signal,Z?.signal);try{let F=await C(t,{...n,signal:ne}),I=isRetryableStatus(F.status)||H&&F.status===404;if(F.ok||!I||q>=N)return S.read?await S.read(F):F;try{await F.arrayBuffer()}catch{}Y=Error(`HTTP ${F.status} ${F.statusText}`)}catch(S){let C=Z!==null&&Z.signal.aborted,F=n.signal?.aborted===!0;if(C&&!F){if(X++,q>=N)throw new RegistryTimeoutError(t,I,X);Y=S}else if(F)throw signalAbortError(n.signal);else{if(!isRetryableError(S))throw S;if(q>=N)throw new RegistryUnreachableError(t,q+1,Date.now()-W,S);Y=S}}finally{te!==null&&clearTimeout(te)}let re=Math.min(F*2**q,8e3);S.onRetry?.({attempt:q+1,error:Y,delayMs:re}),await delay$1(re,n.signal),q++}}function composeSignals(t,n){return t?n?AbortSignal.any([t,n]):t:n}function isRetryableStatus(t){return t===408||t===425||t===429||t===500||t===502||t===503||t===504||t===521||t===522||t===524||t===525}function isRetryableError(t){if(t&&typeof t==`object`&&`name`in t&&t.name===`AbortError`)return!1;if(t instanceof TypeError)return!0;if(t&&typeof t==`object`&&`name`in t){let n=t.name;if(n===`FetchError`)return!0;if(n===`AbortError`)return!1}let n=t?.cause;if(n&&typeof n==`object`&&`code`in n){let t=n.code;if(typeof t==`string`)return t===`ECONNRESET`||t===`ECONNREFUSED`||t===`ENETUNREACH`||t===`ENOTFOUND`||t===`ETIMEDOUT`||t===`EAI_AGAIN`||t===`UND_ERR_SOCKET`||t===`UND_ERR_CONNECT_TIMEOUT`}return!1}function delay$1(t,n){return t<=0?Promise.resolve():new Promise((S,C)=>{let N=setTimeout(()=>{n?.removeEventListener?.(`abort`,onAbort),S()},t),onAbort=()=>{clearTimeout(N),C(signalAbortError(n))};if(n?.aborted){clearTimeout(N),C(signalAbortError(n));return}n?.addEventListener?.(`abort`,onAbort,{once:!0})})}function signalAbortError(t){let n=t&&`reason`in t?t.reason:void 0;if(n instanceof Error)return n;let S=Error(`Aborted`);return S.name=`AbortError`,S}var Ym=__esmMin(()=>{Km(),__name$1(delay$1,`delay`)});async function verifyIntegrity(t,n){let S=n.trim().split(/\s+/);for(let n of S){let S=n.indexOf(`-`);if(S<0)continue;let C=n.slice(0,S).toLowerCase(),N=n.slice(S+1),F=globalThis.crypto?.subtle;if(!F)throw Error(`@gjsify/npm-registry: globalThis.crypto.subtle is missing`);let I=subriToWebCryptoAlgo(C);if(!I)continue;let H=await F.digest(I,dataAsArrayBuffer(t));if(bytesToBase64(new Uint8Array(H))===N)return!0}return!1}function subriToWebCryptoAlgo(t){switch(t){case`sha1`:return`SHA-1`;case`sha256`:return`SHA-256`;case`sha384`:return`SHA-384`;case`sha512`:return`SHA-512`;default:return null}}function dataAsArrayBuffer(t){if(t.byteOffset===0&&t.byteLength===t.buffer.byteLength)return t.buffer;let n=new Uint8Array(t.byteLength);return n.set(t),n.buffer}function bytesToBase64(t){let n=``;for(let S=0;S<t.length;S++)n+=String.fromCharCode(t[S]);return btoa(n)}var Xm=__esmMin(()=>{});function assertPackument(t,n){if(!n||typeof n!=`object`)throw TypeError(`registry: ${t} packument is not an object`);let S=n;if(typeof S.name!=`string`)throw TypeError(`registry: ${t} packument missing string name`);if(!S.versions||typeof S.versions!=`object`)throw TypeError(`registry: ${t} packument missing versions map`)}function packumentUrl(t,n){let S=ensureTrailingSlash$1(n);if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n<0)throw TypeError(`Invalid scoped package name: ${t}`);let C=t.slice(0,n),N=t.slice(n+1);return`${S}${encodeURIComponent(C)}/${encodeURIComponent(N)}`}return`${S}${encodeURIComponent(t)}`}async function fetchPackumentConditional(t,n={}){let S=packumentUrl(t,n.registry??registryFor(t,n.npmrc)),C=buildHeaders(S,{...n,acceptEncoding:`gzip`});C.accept??=n.fullMetadata?`application/json`:`application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*`,n.ifNoneMatch&&(C[`if-none-match`]=n.ifNoneMatch);let N=await fetchWithRetry(S,{headers:C,signal:n.signal},{fetch:n.fetch,retries:n.retries,retryDelayMs:n.retryDelayMs,timeoutMs:n.timeoutMs,onRetry:n.onRetry,read:async n=>{if(n.status===304){try{await n.arrayBuffer()}catch{}return{status:`not-modified`}}if(!n.ok)throw n.status===404||n.status===406?new PackageNotFoundError(t,S):Error(`registry GET ${S} -> ${n.status} ${n.statusText}`);return{status:`fresh`,body:await decodeJsonBody(n),etag:n.headers.get(`etag`)??void 0}}});if(N.status===`not-modified`)return{status:`not-modified`,etag:n.ifNoneMatch};let F=N.body;return assertPackument(t,F),{status:`fresh`,packument:F,etag:N.etag}}async function decodeJsonBody(t){return t.json()}async function fetchPackument(t,n={}){let S=await fetchPackumentConditional(t,n);if(!S.packument)throw Error(`registry: ${t} returned 304 Not Modified to an unconditional request`);return S.packument}var Zm=__esmMin(()=>{Gm(),Km(),Jm(),Ym()});async function fetchTarball(t,n={}){let S=buildHeaders(t,{...n,acceptEncoding:`identity`});S.accept??=`application/octet-stream`;let C=await fetchWithRetry(t,{headers:S,signal:n.signal},{fetch:n.fetch,retries:n.retries,retryDelayMs:n.retryDelayMs,timeoutMs:n.timeoutMs,onRetry:n.onRetry,retryNotFound:n.retryNotFound??!0,read:async n=>{if(!n.ok)throw Error(`tarball GET ${t} -> ${n.status} ${n.statusText}`);return new Uint8Array(await n.arrayBuffer())}});if(n.integrity&&!await verifyIntegrity(C,n.integrity))throw new IntegrityError(t,n.integrity);return C}var Qm=__esmMin(()=>{Gm(),Km(),Ym(),Xm()});async function whoami(t,n){let S=`${ensureTrailingSlash$1(t)}-/whoami`,C=buildHeaders(S,{npmrc:n});C.accept=`application/json`;let N=globalThis.fetch;if(!N)throw Error(`@gjsify/npm-registry: globalThis.fetch is missing`);let F=await N(S,{method:`GET`,headers:C});if(!F.ok)throw Error(`whoami GET ${S} -> ${F.status} ${F.statusText}`);let I=await F.json();if(I&&typeof I==`object`&&`username`in I){let t=I.username;if(typeof t==`string`&&t.length>0)return{username:t}}return{}}var $m=__esmMin(()=>{Gm(),Jm()}),eh=__esmMin(()=>{Gm(),Km(),Jm(),Xm(),Zm(),Qm(),$m()});function escapePackageName(t){return t.replace(`/`,`%2f`)}function buildPublishHeaders(t,n){let S=buildHeaders(t,{npmrc:n.npmrc});return S[`content-type`]=`application/json`,S[`npm-command`]=`publish`,S[`npm-auth-type`]=n.otp?`legacy`:`web`,S[`user-agent`]=n.userAgent??defaultUserAgent(),n.otp&&(S[`npm-otp`]=n.otp),n.authorization&&(S.authorization=n.authorization),S}function cliVersion(){return th===void 0&&(th=`0.64.4`),th}function cliPackageDir(){let t=globalThis.process?.env?.GJSIFY_CLI_PACKAGE_JSON,n;try{n=En(t||fileURLToPath(import.meta.url))}catch{return null}for(let t=0;t<12;t++){try{if(JSON.parse(readFileSync(`${n}/package.json`,`utf8`)).name===`@gjsify/cli`)return n}catch{}let t=En(n);if(t===n)break;n=t}return null}function defaultUserAgent(){let t=globalThis.process,n=t?.arch??`x64`,S=t?.platform??`linux`;return`gjsify-publish/${cliVersion()} (${S} ${n})`}var th,nh=__esmMin(()=>{Rd(),Pn(),Gn(),eh()}),rh,ih=__esmMin(()=>{rh=`gjsify`});function parseDeclaredChannel(t,n){if(!(t===void 0||t===``)){if(ah.includes(t))return t;throw Error(`${n}: "${String(t)}" is not a distribution channel. Known: ${ah.join(`, `)}.`)}}function channelAllowsDonations(t){return t!==void 0&&oh[t]===!0}var ah,oh,sh,ch=__esmMin(()=>{ah=[`flathub`,`web`,`microsoft-store`,`apple-app-store`],oh={flathub:!0,web:!0,"microsoft-store":!1,"apple-app-store":!1},sh=`GJSIFY_CHANNEL`}),lh=__commonJSMin(((t,n)=>{let S=(Pn(),__toCommonJS(yn)),C=(Il(),__toCommonJS(Ml)),N=(Rd(),__toCommonJS(Id)),resolveFrom=(t,n,F)=>{if(typeof t!=`string`)throw TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof t}\``);if(typeof n!=`string`)throw TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof n}\``);try{t=N.realpathSync(t)}catch(n){if(n.code===`ENOENT`)t=S.resolve(t);else if(F)return null;else throw n}let I=S.join(t,`noop.js`),resolveFileName=()=>C._resolveFilename(n,{id:I,filename:I,paths:C._nodeModulePaths(t)});if(F)try{return resolveFileName()}catch{return null}return resolveFileName()};n.exports=(t,n)=>resolveFrom(t,n),n.exports.silent=(t,n)=>resolveFrom(t,n,!0)})),uh=__commonJSMin(((t,n)=>{let callsites=()=>{let t=Error.prepareStackTrace;Error.prepareStackTrace=(t,n)=>n;let n=Error().stack.slice(1);return Error.prepareStackTrace=t,n};n.exports=callsites,n.exports.default=callsites})),dh=__commonJSMin(((t,n)=>{let S=uh();n.exports=t=>{let n=S();if(!t)return n[2].getFileName();let C=!1;n.shift();for(let S of n){let n=S.getFileName();if(typeof n==`string`){if(n===t){C=!0;continue}if(n!==`module.js`&&C&&n!==t)return n}}}})),fh=__commonJSMin(((t,n)=>{var{__gjsifyModuleDir:S,__gjsifyModuleFile:C}=(Bl(),__toCommonJS(Ll)),N=S(`import-fresh/index.js`),F=C(`import-fresh/index.js`);let I=(Pn(),__toCommonJS(yn)),H=lh(),W=dh();n.exports=t=>{if(typeof t!=`string`)throw TypeError(`Expected a string`);let n=W(F),S=n?I.dirname(n):N,C=H(S,t),q=Y.cache[C];if(q&&q.parent){let t=q.parent.children.length;for(;t--;)q.parent.children[t].id===C&&q.parent.children.splice(t,1)}delete Y.cache[C];let X=Y.cache[n];return X===void 0||X.require===void 0?Y(C):X.require(C)}})),ph=__commonJSMin(((t,n)=>{n.exports=function isArrayish(t){return t?t instanceof Array||Array.isArray(t)||t.length>=0&&t.splice instanceof Function:!1}})),mh=__commonJSMin(((t,n)=>{var S=(Tu(),__toCommonJS(xu)),C=ph(),N=function errorEx(t,n){(!t||t.constructor!==String)&&(n=t||{},t=Error.name);var N=function ErrorEXError(S){if(!this)return new ErrorEXError(S);S=S instanceof Error?S.message:S||this.message,Error.call(this,S),Error.captureStackTrace(this,N),this.name=t,Object.defineProperty(this,"message",{configurable:!0,enumerable:!1,get:function(){var t=S.split(/\r?\n/g);for(var N in n)if(n.hasOwnProperty(N)){var F=n[N];`message`in F&&(t=F.message(this[N],t)||t,C(t)||(t=[t]))}return t.join(`
149
149
  `)},set:function(t){S=t}});var F=null,I=Object.getOwnPropertyDescriptor(this,`stack`),H=I.get,W=I.value;delete I.value,delete I.writable,I.set=function(t){F=t},I.get=function(){var t=(F||(H?H.call(this):W)).split(/\r?\n+/g);F||(t[0]=this.name+`: `+this.message);var S=1;for(var C in n)if(n.hasOwnProperty(C)){var N=n[C];if(`line`in N){var I=N.line(this[C]);I&&t.splice(S++,0,` `+I)}`stack`in N&&N.stack(this[C],t)}return t.join(`
150
150
  `)},Object.defineProperty(this,"stack",I)};return Object.setPrototypeOf?(Object.setPrototypeOf(N.prototype,Error.prototype),Object.setPrototypeOf(N,Error)):S.inherits(N,Error),N};N.append=function(t,n){return{message:function(S,C){return S||=n,S&&(C[0]+=` `+t.replace(`%s`,S.toString())),C}}},N.line=function(t,n){return{line:function(S){return S||=n,S?t.replace(`%s`,S.toString()):null}}},n.exports=N})),hh=__commonJSMin(((t,n)=>{let hexify=t=>{let n=t.charCodeAt(0).toString(16).toUpperCase();return`0x`+(n.length%2?`0`:``)+n},parseError=(t,n,S)=>{if(!n)return{message:t.message+` while parsing empty string`,position:0};let C=t.message.match(/^Unexpected token (.) .*position\s+(\d+)/i),N=C?+C[2]:t.message.match(/^Unexpected end of JSON.*/i)?n.length-1:null,F=C?t.message.replace(/^Unexpected token ./,`Unexpected token ${JSON.stringify(C[1])} (${hexify(C[1])})`):t.message;if(N!=null){let t=N<=S?0:N-S,C=N+S>=n.length?n.length:N+S,I=(t===0?``:`...`)+n.slice(t,C)+(C===n.length?``:`...`);return{message:F+` while parsing ${n===I?``:`near `}${JSON.stringify(I)}`,position:N}}else return{message:F+` while parsing '${n.slice(0,S*2)}'`,position:0}};var JSONParseError=class extends SyntaxError{constructor(t,n,S,C){S||=20;let N=parseError(t,n,S);super(N.message),Object.assign(this,N),this.code=`EJSONPARSE`,this.systemError=t,Error.captureStackTrace(this,C||this.constructor)}get name(){return this.constructor.name}set name(t){}get[Symbol.toStringTag](){return this.constructor.name}};let S=Symbol.for(`indent`),C=Symbol.for(`newline`),N=/^\s*[{\[]((?:\r?\n)+)([\s\t]*)/,F=/^(?:\{\}|\[\])((?:\r?\n)+)?$/,parseJson=(t,n,I)=>{let H=stripBOM(t);I||=20;try{let[,t=`
151
151
  `,I=` `]=H.match(F)||H.match(N)||[,``,``],W=JSON.parse(H,n);return W&&typeof W==`object`&&(W[C]=t,W[S]=I),W}catch(n){if(typeof t!=`string`&&!Buffer.isBuffer(t)){let S=Array.isArray(t)&&t.length===0;throw Object.assign(TypeError(`Cannot parse ${S?`an empty array`:String(t)}`),{code:`EJSONPARSE`,systemError:n})}throw new JSONParseError(n,H,I,parseJson)}},stripBOM=t=>String(t).replace(/^\uFEFF/,``);n.exports=parseJson,parseJson.JSONParseError=JSONParseError,parseJson.noExceptions=(t,n)=>{try{return JSON.parse(stripBOM(t),n)}catch{}}})),gh=__commonJSMin((t=>{t.__esModule=!0,t.LinesAndColumns=void 0;var n=`
@@ -793,11 +793,11 @@ Build it from the gjsify repo root — both are idempotent and skip already-buil
793
793
  gjsify run --node-script scripts/bootstrap-native-facades.mjs # just the facades
794
794
  Under Node the facades are built by the CLI's own Node entry (npm \`rolldown\`); under GJS by the \`gjsify\` on PATH, which carries its own engine when it was installed with \`gjs -m install.mjs\`.
795
795
  If you are READING THIS ON A GJS HOST, that global engine is what could not be reached: this workspace symlink shadowed it, because \`require.resolve\` returned the package DIRECTORY instead of failing. That is fixed in \`@gjsify/module\`, so a \`gjsify\` OLDER than the fix still stops here — update it (\`gjs -m install.mjs\`), or seed \`lib/\` from the published package, which ships it.`;let S=[`The JS facade is built, so this is the typelib/prebuild lookup failing.`],C=missingSystemDepsFor(`@gjsify/rolldown-native`),N=C.map(t=>t.name).join(`, `),F=C.length>0?buildInstallCommand(detectPackageManager$1(),C):null,I=C.length===0?void 0:F?`Install it:\n ${F}`:`Install ${N} with your system package manager (this host's manager was not recognised, so no command is suggested rather than a wrong one).`;if(AF!==null&&S.push(`\nNOT MEASURED — the native-library probe could not be loaded, so nothing below is a reading of this host:\n ${AF instanceof Error?AF.message:String(AF)}`),OF&&kF?S.push(`\nMEASURED CAUSE — ${new kF.NativeLibraryLoadError(OF,I).message}`):C.length>0&&(S.push(`\nMEASURED CAUSE — a system library the engine's prebuild loads is MISSING: ${N}.\nThe prebuild is present but its typelib cannot open its backing library, which GJS reports as \`Unsupported type void, deriving from fundamental void\` — a message that names nothing. This is a system package, not an npm one.`),I&&S.push(I)),C.length===0&&!OF){let t=activateNativePrebuilds().find(t=>t.name.startsWith(`@gjsify/rolldown-native`));S.push(t?`\nEvery declared system library resolves and ${t.name}'s prebuild (${t.prebuildsDir}) IS on girepository's search paths, so it is present but did not load.`:`\nEvery declared system library resolves, so most likely no prebuild exists for ${process.platform}/${process.arch} — no @gjsify/rolldown-native prebuild directory was found walking up from ${process.cwd()}.`)}return S.push("\nRunning the build under Node also works — there the npm `rolldown` crate is used instead."),S.join(`
796
- `)}function resolveImportTargetForGjs(t){if(!isGjs())return t;let n=resolveNpmPackage(t,{bundleUrl:import.meta.url});return n?pathToFileURL(n).href:t}async function bundleToChunks(t){if(await shouldUseNative()){let n=await tryLoadNative();if(!n)throw Error(`@gjsify/rolldown-native not loadable`);let S=t.rolldownInput.plugins??[],C=[];for(let t of S)isPluginObject(t)&&C.push(toNativePlugin(t));let N=liftTransformExtras(stripUnserializable({...t.rolldownInput,input:normalizeInputForNative(t.rolldownInput.input),format:t.format}));delete N.plugins;let F=await n.bundleWithPlugins(N,C);reportNativeWarnings(F,t.rolldownInput);let I=[];for(let t of F.output)t.type===`chunk`&&I.push(t.code);return I}let n=await(await loadNpmRolldown())(t.rolldownInput);try{let S=await n.generate({format:t.format,minify:!1,sourcemap:!1}),C=[];for(let t of S.output)t.type===`chunk`&&C.push(t.code);return C}finally{await n.close()}}async function runWatch(t){if(await shouldUseNative())throw Error("`gjsify build --watch` requires the npm `rolldown` engine. The native engine (`@gjsify/rolldown-native`) does not expose a watcher API. Run the watch loop under Node (`node lib/index.js build … --watch`) or set `GJSIFY_BUNDLER=npm`.");let n=await import(resolveImportTargetForGjs(`rolldown`)),S=t.output??{};return n.watch({...t,output:S})}function warnNoNativeWatchList(){EF||(EF=!0,ge.warn("[gjsify] this `@gjsify/rolldown-native` build reports no watch list: it predates `addWatchFile`, so a file a plugin read itself (a stylesheet’s `@import` chain, an inlined `readFileSync`) cannot be declared as a build input. `gjsify test` will rebuild the affected bundles on every run rather than trust a set it cannot see. Upgrade the engine (it ships in the same release train as the CLI)."))}async function runBundle(t,n={}){if(await shouldUseNative())return await runNativeBundle(t,n);let S=await(await loadNpmRolldown())(t);try{let C=await S.write(t.output??{});return n.onWatchFiles&&n.onWatchFiles({files:await S.watchFiles,reportedByEngine:!0}),C}finally{await S.close()}}function resolveNativeLibraryModule(t={}){let n=`@gjsify/utils/native-library`;return resolveNpmPackage(n,t)??createRequire(t.bundleUrl??import.meta.url).resolve(n)}async function utilsCore(){return kF===null&&(kF=await import(pathToFileURL(resolveNativeLibraryModule({bundleUrl:import.meta.url})).href)),kF}async function shouldUseNative(){let t=(globalThis.process?.env??{}).GJSIFY_BUNDLER;if(t===`npm`)return!1;if(t===`native`){if(!await tryLoadNative())throw Error(`GJSIFY_BUNDLER=native but @gjsify/rolldown-native is not loadable (no prebuild for this architecture, or not running under GJS).`+(isGjs()?`\n${diagnoseNativeEngine()}`:``));return!0}return isGjs()?await tryLoadNative()!==null:!1}function findRolldownNativeDir(t,n){let S=wn(`node_modules`,`@gjsify`,`rolldown-native`,`package.json`),C=[t];n&&n!==t&&C.push(n);for(let t of C){let n=t;for(let t=0;t<12;t++){if(existsSync(wn(n,S)))return wn(n,`node_modules`,`@gjsify`,`rolldown-native`);let t=xn(n,`..`);if(t===n)break;n=t}}return null}async function tryLoadNative(){return DF||(DF=(async()=>{if(!isGjs())return null;try{activateNativePrebuilds();let t=`@gjsify/rolldown-native`,n=t;if(isGjs()){let S=En(fileURLToPath(import.meta.url)),C=resolveNpmPackage(t,{bundleUrl:import.meta.url}),N=C?null:(()=>{let n=findRolldownNativeDir(process.cwd(),S);if(!n)return null;try{return createRequire(pathToFileURL(wn(n,`__gjsify_resolve__.js`)).href).resolve(t)}catch{return null}})();n=pathToFileURL(C??N??createRequire(import.meta.url).resolve(t)).href}let S=await import(n);if(!S.hasNativeRolldown())return null;let C=null;try{C=await utilsCore()}catch(t){AF=t}return C!==null&&(OF=C.probeNativeLibrary(`GjsifyRolldown`),OF)?null:S}catch{return null}})(),DF)}async function runNativeBundle(t,n={}){let S=await tryLoadNative();if(!S)throw Error(`@gjsify/rolldown-native not loadable`);let C=t.plugins??[],N=[];for(let t of C)isPluginObject(t)&&N.push(toNativePlugin(t));let{output:F,plugins:I,...H}=t,W=liftTransformExtras(stripUnserializable({...H,...F,input:normalizeInputForNative(t.input)}));globalThis.process?.env?.GJSIFY_DEBUG_NATIVE_OPTS&&ge.error(`[gjsify-bundler-pick] native opts JSON:`,JSON.stringify(W));let q=await S.bundleWithPlugins(W,N);reportNativeWarnings(q,t),n.onWatchFiles&&(q.watchedFiles===void 0?(warnNoNativeWatchList(),n.onWatchFiles({files:[],reportedByEngine:!1})):n.onWatchFiles({files:q.watchedFiles,reportedByEngine:!0}));let Y=t.output??{},X=Y.dir??(Y.file?En(Y.file):process.cwd());X&&await yd.mkdir(X,{recursive:!0});for(let t of q.output){let n=Y.file&&t.type===`chunk`&&q.output.length===1?Y.file:wn(X,t.fileName);await yd.mkdir(En(n),{recursive:!0}),t.type===`chunk`?(await yd.writeFile(n,t.code,`utf8`),typeof t.map==`string`&&await yd.writeFile(`${n}.map`,t.map,`utf8`)):t.sourceText!==void 0&&await yd.writeFile(n,t.sourceText,`utf8`)}return synthRolldownOutput(q)}function reportNativeWarnings(t,n){if(n.logLevel===`silent`||!Array.isArray(t.warnings)||t.warnings.length===0)return;let S=new Set;for(let n of t.warnings)S.has(n)||(S.add(n),ge.warn(`[gjsify-bundler] ${n}`))}function stripUnserializable(t){let n={};for(let[S,C]of Object.entries(t)){if(typeof C==`function`){if(!jF.has(S)){jF.add(S);let t=S===`external`?" Function `external` predicates are NOT supported by the native engine — pass exact names as a string array and/or enforce shape rules via a resolveId plugin returning `{ external: true }` (see externalsPlugin in @gjsify/rolldown-plugin-gjsify).":` Function-valued options do not survive the JSON boundary to the Rust core.`;ge.warn(`[gjsify-bundler] dropping non-serializable option "${S}" for the native rolldown engine — behavior may diverge from npm rolldown.${t}`)}continue}if(S===`external`&&Array.isArray(C)){let t=C.find(t=>typeof t!=`string`);if(t!==void 0)throw Error(`gjsify build: \`external\` entries must be exact string names under the native rolldown engine (got ${t instanceof RegExp?t.toString():typeof t}). RegExp/function externals are only supported by npm rolldown — use exact names or a resolveId plugin returning \`{ external: true }\`.`);n[S]=C;continue}if(S===`sourcemap`){let t=translateSourcemapOption(C);t!==void 0&&(n[S]=t);continue}n[S]=C}return n}function translateSourcemapOption(t){if(t===!0||t===`file`||t===`File`)return`File`;if(t===`inline`||t===`Inline`)return`Inline`;if(t===`hidden`||t===`Hidden`)return`Hidden`}function liftTransformExtras(t){let n=t.transform;if(!n)return t;let S={},C={...n};for(let t of[`define`,`inject`])t in C&&(S[t]=C[t],delete C[t]);return S.inject!==void 0&&!Array.isArray(S.inject)&&(S.inject=mapToInjectArray(S.inject)),{...t,transform:Object.keys(C).length===0?void 0:C,...S}}function mapToInjectArray(t){let n=[];for(let[S,C]of Object.entries(t))if(typeof C==`string`)n.push({type:`named`,imported:`default`,from:C,alias:S});else{let[t,N]=C;N===`*`?n.push({type:`namespace`,from:t,alias:S}):n.push({type:`named`,from:t,imported:N,alias:S})}return n}function normalizeInputForNative(t){return t===void 0?[]:typeof t==`string`?[{import:t}]:Array.isArray(t)?t.map(t=>typeof t==`string`?{import:t}:t):Object.entries(t).map(([t,n])=>({name:t,import:n}))}function isPluginObject(t){return typeof t==`object`&&!!t&&!Array.isArray(t)}function pickHook(t){if(typeof t==`function`)return{fn:t};if(typeof t==`object`&&t&&`handler`in t){let n=t,S=filterToRegexSource(n.filter?.id),C={fn:n.handler};return S!==void 0&&(C.idFilter=S),C}}function filterToRegexSource(t){if(t!==void 0){if(Array.isArray(t)){let n=t.map(oneToSource).filter(t=>t!==void 0);return n.length===0?void 0:n.length===1?n[0]:`(?:${n.join(`|`)})`}return oneToSource(t)}}function oneToSource(t){if(t instanceof RegExp)return t.source;if(typeof t==`string`)return t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function toNativePlugin(t){let n={name:typeof t.name==`string`?t.name:`unnamed-plugin`},S={},C=pickHook(t.load);C&&(n.load=C.fn,C.idFilter&&(S.load=C.idFilter));let N=pickHook(t.transform);N&&(n.transform=N.fn,N.idFilter&&(S.transform=N.idFilter));let F=pickHook(t.resolveId);F&&(n.resolveId=F.fn,F.idFilter&&(S.resolveId=F.idFilter));let I=pickHook(t.renderChunk);I&&(n.renderChunk=I.fn);let H=pickHook(t.banner);H&&(n.banner=H.fn);let W=pickHook(t.footer);W&&(n.footer=W.fn);let q=pickHook(t.intro);q&&(n.intro=q.fn);let Y=pickHook(t.outro);Y&&(n.outro=Y.fn);let X=pickHook(t.buildStart);X&&(n.buildStart=X.fn);let Z=pickHook(t.buildEnd);Z&&(n.buildEnd=Z.fn);let te=pickHook(t.generateBundle);te&&(n.generateBundle=te.fn);let ne=pickHook(t.writeBundle);ne&&(n.writeBundle=ne.fn);let re=pickHook(t.closeBundle);return re&&(n.closeBundle=re.fn),Object.keys(S).length>0&&(n.idFilter=S),n}function synthRolldownOutput(t){return{output:t.output.map(t=>t.type===`chunk`?{type:`chunk`,fileName:t.fileName,code:t.code,name:t.name,isEntry:t.isEntry,isDynamicEntry:t.isDynamicEntry,map:t.map??null,sourcemapFileName:t.sourcemapFilename??null,imports:t.imports,dynamicImports:t.dynamicImports,facadeModuleId:null,moduleIds:[],modules:{},exports:[],referencedFiles:[],importedBindings:{}}:{type:`asset`,fileName:t.fileName,names:t.names,originalFileNames:t.originalFileNames,source:t.sourceText??``,needsCodeReference:!1})}}var EF,DF,OF,kF,AF,jF,MF=__esmMin(()=>{_e(),Rd(),Pn(),Il(),Gn(),nF(),vF(),TF(),d_(),EF=!1,DF=null,OF=null,kF=null,AF=null,jF=new Set});function isPluginByName(t){return typeof t==`object`&&!!t&&typeof t.name==`string`&&!(`apply`in t)&&!(`resolveId`in t)&&!(`load`in t)&&!(`transform`in t)&&!(`renderChunk`in t)&&!(`generateBundle`in t)}async function resolveUserPlugins(t,n,S={}){let C=S.loadModule??defaultLoadModule,N=createRequire(wn(n,`package.json`)),F=[];for(let S of t){if(!isPluginByName(S)){F.push(S);continue}let t;try{t=N.resolve(S.name)}catch(t){throw Error(`gjsify config: failed to resolve plugin "${S.name}" from ${n}. Add it to your project's dependencies, or pass a Plugin object directly. (${t.message})`)}let I=await C(t,S.name),H=S.export??`default`,W=I[H];if(typeof W!=`function`){let t=Object.keys(I).filter(t=>typeof I[t]==`function`);throw Error(`gjsify config: plugin "${S.name}" has no function export "${H}". Available function exports: ${t.length?t.join(`, `):`(none)`}.`)}let q=await W(S.options);if(q==null)throw Error(`gjsify config: plugin "${S.name}" factory returned ${q}. Check the plugin's signature — it should return a Rolldown/Vite plugin object.`);F.push(q)}return F}var defaultLoadModule,NF=__esmMin(()=>{Il(),Pn(),Gn(),defaultLoadModule=async t=>await import(pathToFileURL(t).href)}),PF,FF=__esmMin(()=>{PF={"@gjsify/buffer/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/canvas2d/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/canvas":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/document":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/font-face":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/image":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/location":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/match-media":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/observers":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/domparser/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/gamepad/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`Navigator`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`dispatchEvent`,`navigator`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/iframe/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`HTMLIFrameElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/buffer":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/encoding":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/microtask":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/navigator":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`Navigator`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`navigator`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/process":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/structured-clone":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/timers":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/url":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`URL`,`URLSearchParams`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/web-globals/register/formdata":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`FormData`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/web-globals/register/performance":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webaudio/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webgl/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WebGL2RenderingContext`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webrtc/register/data-channel":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`Event`,`EventTarget`,`File`,`MessageEvent`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webrtc/register/error":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`Event`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webrtc/register/media":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`Event`,`EventTarget`,`File`,`MediaStream`,`MediaStreamTrack`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webrtc/register/media-devices":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CountQueuingStrategy.DOMException.Event.EventTarget.File.MediaStream.MediaStreamTrack.Navigator.ReadableStream.TextDecoderStream.TextEncoderStream.TransformStream.WritableStream.atob.btoa.clearTimeout.navigator.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"@gjsify/webrtc/register/peer-connection":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CountQueuingStrategy.DOMException.Event.EventTarget.File.MediaStream.MediaStreamTrack.MessageEvent.RTCSessionDescription.ReadableStream.TextDecoderStream.TextEncoderStream.TransformStream.WritableStream.atob.btoa.clearTimeout.crypto.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"abort-controller/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"compression-streams/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CompressionStream`,`CountQueuingStrategy`,`DOMException`,`DecompressionStream`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-events/register/custom-events":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-events/register/event-target":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-events/register/global-event-target":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-events/register/ui-events":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-exception/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"eventsource/register":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CompressionStream.CountQueuingStrategy.DOMException.DecompressionStream.Event.EventSource.EventTarget.File.Headers.MessageEvent.ReadableStream.Request.Response.TextDecoderStream.TextEncoderStream.TransformStream.URL.URLSearchParams.WritableStream.atob.btoa.clearTimeout.fetch.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"fetch/register/fetch":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CompressionStream.CountQueuingStrategy.DOMException.DecompressionStream.File.Headers.ReadableStream.Request.Response.TextDecoderStream.TextEncoderStream.TransformStream.URL.URLSearchParams.WritableStream.atob.btoa.clearTimeout.fetch.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"fetch/register/xhr":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CompressionStream.CountQueuingStrategy.DOMException.DecompressionStream.File.Headers.ReadableStream.Request.Response.TextDecoderStream.TextEncoderStream.TransformStream.URL.URLSearchParams.WritableStream.XMLHttpRequest.XMLHttpRequestUpload.atob.btoa.clearTimeout.fetch.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"message-channel/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`MessageChannel`,`MessagePort`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/queuing":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/readable":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/text-streams":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/transform":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/writable":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"webassembly/register/promise":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WebAssembly`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"webcrypto/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`crypto`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"websocket/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`]}});function expandWithClosure(t,n){let S=new Set(t),C=[...t];for(;C.length>0;){let t=C.pop(),N=IF[t];if(!N)continue;let F=LF[N];if(F)for(let t of F)n.has(t)||IF[t]&&(S.has(t)||(S.add(t),C.push(t)))}return S}function isSubset(t,n){for(let S of t)if(!n.has(S))return!1;return!0}async function applyExcludeGlobals(t,n,S,C,N,F=N){if(C?.length)for(let n of C)t.delete(n);let I=detectedToRegisterPaths(t);for(let t of S)I.add(t);if(emitGiBackedDiagnostic(I,t,F),!C?.length)return{detected:t,injectPath:n};let H=F?filterResolvableRegisterPaths(I,F):I;return{detected:t,injectPath:H.size>0?await writeRegisterInjectFile(H,N)??void 0:void 0}}function detectedToRegisterPaths(t){let n=new Set;for(let S of t){let t=IF[S];t&&n.add(t)}return n}function giNamespacesForRegister(t){for(let n of Object.keys(RF))if(t===n||t.startsWith(n+`/`))return RF[n];return null}function describeGiBackedInjection(t,n){let S=new Set,C=new Set;for(let n of t){let t=giNamespacesForRegister(n);if(t){S.add(n);for(let n of t)C.add(n)}}if(S.size===0)return null;let N=[...n].filter(t=>{let n=IF[t];return!!n&&S.has(n)}).sort();return`[gjsify] note: --globals auto injected GTK/GNOME-backed register(s) — this bundle now requires ${[...C].sort().map(t=>`gi://${t}`).join(`, `)} at load.`+(N.length?` Triggered by: ${N.join(`, `)}.`:``)+` If it runs headless / SSR / in a GTK-less container it will throw "Typelib … not found"; drop those globals via excludeGlobals or pin an explicit --globals allowlist (e.g. node).`}function emitGiBackedDiagnostic(t,n,S){if(BF)return;let C=new Set;for(let n of t)giNamespacesForRegister(n)&&(S&&!isRegisterPathResolvable(n,S)||C.add(n));let N=describeGiBackedInjection(C,n);N&&(BF=!0,ge.warn(N))}function isFullConfig(t){return typeof t==`object`&&!!t&&!Array.isArray(t)&&`plugins`in t&&`options`in t}function mergeTransformOptions(t,n){if(!t)return n;if(!n)return t;let S={...t,...n};return(t.define||n.define)&&(S.define={...t.define,...n.define}),(t.inject||n.inject)&&(S.inject={...t.inject,...n.inject}),S}function mergeResolveOptions(t,n){return t?n?{...t,...n}:t:n}async function detectAutoGlobals(t,n,S,C,N={},F=defaultBundler){let I=N.extraGlobalsList?resolveGlobalsList(N.extraGlobalsList):new Set,H=new Set(N.excludeGlobals??[]),W=N.cwd,q=W&&N.toolchainDir?[W,N.toolchainDir]:W,Y=new Set,X;I.size>0&&(X=await writeRegisterInjectFile(q?filterResolvableRegisterPaths(I,q):I,W)??void 0);let Z=(t.plugins??[]).filter(t=>{let n=t&&typeof t==`object`&&`name`in t?t.name:void 0;return n!==`gjsify`&&n!==`gjsify-orchestrator`});for(let te=1;te<=zF;te++){let ne=await S({...n,autoGlobalsInject:X,skipProcessStub:!0}),re,ie;isFullConfig(ne)?(ie=ne.options,re=ne.plugins):re=ne;let ae=X?appendInjectAsEntry(t.input,X):t.input,oe=mergeResolveOptions(ie?.resolve,t.resolve),Q=t.external??ie?.external,se=mergeTransformOptions(ie?.transform,t.transform),ce=ie?.treeshake,le=Array.isArray(re)?re:[re],ue=await F({rolldownInput:{input:ae,external:Q,resolve:oe,transform:se,plugins:[...Z,...le],logLevel:`silent`,...ce===void 0?{}:{treeshake:ce}},format:t.format??`esm`});if(ue.length===0)return{detected:new Set,injectPath:X};let de=new Set;for(let t=0;t<ue.length;t++){let n=ue[t]??``;try{for(let t of detectFreeGlobals(n))de.add(t)}catch(S){if(globalThis.process?.env?.GJSIFY_DEBUG_AUTO_GLOBALS){let S=await Promise.resolve().then(()=>(Lg(),kg)),C=(await Promise.resolve().then(()=>(Pn(),yn))).join(S.tmpdir(),`gjsify-auto-globals-failed-chunk-${t}.mjs`);try{(await Promise.resolve().then(()=>(Rd(),Id))).writeFileSync(C,n),ge.error(`[gjsify-auto-globals] parse failed on chunk #${t} — wrote ${C} for inspection`)}catch{}}throw S}}if(H.size>0)for(let t of H)de.delete(t);if(isSubset(de,Y)){if(C){let t=[...Y].sort(),n=I.size>0?` (+ ${I.size} extra register module(s))`:``;ge.debug(`[gjsify] --globals auto: converged after ${te-1} iteration(s), ${Y.size} global(s)${t.length?`: `+t.join(`, `):``}${n}`)}return applyExcludeGlobals(Y,X,I,N.excludeGlobals,W,q)}let fe=N.disableClosureExpansion?de:expandWithClosure(de,H);C&&fe.size>de.size&&ge.debug(`[gjsify] --globals auto: closure map expanded ${de.size} → ${fe.size} global(s)`),te>1&&C&&ge.debug("[gjsify] --globals auto: detection grew past the closure-map expansion — the committed register-globals-closure map looks stale. Regenerate via `node packages/infra/cli/scripts/generate-register-closure.mjs`."),Y=new Set([...Y,...fe]);let pe=detectedToRegisterPaths(Y);for(let t of I)pe.add(t);if(q&&(pe=filterResolvableRegisterPaths(pe,q)),pe.size===0)return{detected:Y,injectPath:void 0};if(X=await writeRegisterInjectFile(pe,W)??void 0,C){let t=[...Y].sort();ge.debug(`[gjsify] --globals auto: iteration ${te}, ${Y.size} global(s)${t.length?`: `+t.join(`, `):``}`)}}return C&&ge.debug(`[gjsify] --globals auto: hit max iterations (${zF}), using last detected set`),applyExcludeGlobals(Y,X,I,N.excludeGlobals,W,q)}async function detectNodeGiGlobals(t,n,S,C=defaultBundler){let N=await S(n),F,I;isFullConfig(N)?(I=N.options,F=N.plugins):F=N;let H=(t.plugins??[]).filter(t=>{let n=t&&typeof t==`object`&&`name`in t?t.name:void 0;return n!==`gjsify`&&n!==`gjsify-orchestrator`}),W=Array.isArray(F)?F:[F],q=I?{...I}:{};delete q.output;let Y;try{Y=await C({rolldownInput:{...q,input:t.input,external:t.external??q.external,resolve:mergeResolveOptions(q.resolve,t.resolve),transform:mergeTransformOptions(q.transform,t.transform),plugins:[...H,...W],logLevel:`silent`},format:t.format??`esm`})}catch(t){return ge.warn(`[gjsify] --app node: could not analyse the bundle for GJS ambient globals (${t instanceof Error?t.message:String(t)}); skipping @gjsify/node-gi/globals injection. If this build uses print/imports/ARGV, add \`import '@gjsify/node-gi/globals'\` to the entry or pass --globals.`),!1}for(let t of Y)if(detectGjsAmbientGlobals(t).size>0||detectNodeGiModuleImports(t))return!0;return!1}function appendInjectAsEntry(t,n){return t===void 0?[n]:typeof t==`string`?[t,n]:Array.isArray(t)?[...t,n]:{...t,__gjsify_inject:n}}var defaultBundler,IF,LF,RF,zF,BF,VF=__esmMin(()=>{_e(),iS(),lS(),qx(),FF(),defaultBundler=async({rolldownInput:t,format:n})=>{let S=await(await import(`rolldown`)).rolldown(t);try{let t=await S.generate({format:n,minify:!1,sourcemap:!1}),C=[];for(let n of t.output)n.type===`chunk`&&C.push(n.code);return C}finally{await S.close()}},IF=Wx,LF=PF,RF=Kx,zF=5,BF=!1}),HF=__esmMin(()=>{lS(),iS(),VF()});function findPnpRoot(t){let n=t;for(;;){if(existsSync(wn(n,`.pnp.cjs`)))return n;let t=En(n);if(t===n)return null;n=t}}async function loadPnpApi(){try{let t=await import(`pnpapi`);return t.default??t}catch{return null}}async function pnpPlugin(t={}){let n=t.issuerUrl??import.meta.url;if(!findPnpRoot(process.cwd()))return null;let S=await loadPnpApi();if(S===null)return null;let C=fileURLToPath(n),N=createRequire(C),F=t.relayPackages??[`@gjsify/node-polyfills`,`@gjsify/web-polyfills`],I=[];for(let t of F)try{I.push(N.resolve(`${t}/package.json`))}catch{}return{name:`gjsify-pnp`,resolveId:{order:`pre`,async handler(t,n){if(t.startsWith(`.`)||t.startsWith(`/`))return null;if(t.startsWith(`gi://`))return{id:t,external:!0};if(t.startsWith(`node:`))return await this.resolve(t,n,{skipSelf:!0});if(!n)return null;let N=n.startsWith(`file://`)?fileURLToPath(n):n;try{let n=S.resolveRequest(t,N);return n===null?null:{id:n}}catch(n){if(!isUndeclaredDependency(n))throw n;try{let n=S.resolveRequest(t,C);if(n!==null)return{id:n}}catch(t){if(!isUndeclaredDependency(t))throw t}for(let n of I)try{let C=S.resolveRequest(t,n);if(C!==null)return{id:C}}catch(t){if(!isUndeclaredDependency(t))throw t}return null}}},async load(t){if(!t.includes(`/.yarn/`)&&!t.includes(`.zip/`))return null;try{return{code:await readFile$1(t,`utf8`)}}catch(n){let S=n instanceof Error?n.message:String(n);this.error(`gjsify-pnp: failed to read ${t}: ${S}`)}}}}function isUndeclaredDependency(t){return typeof t==`object`&&!!t&&`pnpCode`in t&&t.pnpCode===`UNDECLARED_DEPENDENCY`}var UF=__esmMin(()=>{Il(),Gn(),Pn(),Rd(),xd()});function normalizeBundlerOptions(t){let n=t.bundler??{},S=n;if(typeof n.define==`object`&&n.define!==null){GF||(GF=!0,ge.warn(`[gjsify] WARNING: 'bundler.define' is not a valid Rolldown option and would be silently ignored — it has been auto-mapped to 'bundler.transform.define'. Move 'define' under 'bundler.transform.define' in your config to suppress this warning and avoid a ReferenceError at GJS load time.`));let{define:t,...C}=n;S={...C,transform:{...C.transform,define:{...t,...C.transform?.define}}}}if(!t.esbuild)return S;WF||(WF=!0,ge.warn(`[gjsify] DEPRECATION: the 'esbuild' config key is deprecated and will be removed in 0.5.0. Rename it to 'bundler' (typed as RolldownOptions). See the migration notes in the gjsify CHANGELOG.`));let C=legacyEsbuildToRolldown(t.esbuild),N={...C,...S};return(C.output||S.output)&&(N.output={...C.output,...S.output}),(C.transform||S.transform)&&(N.transform={...C.transform,...S.transform},(C.transform?.define||S.transform?.define)&&(N.transform.define={...C.transform?.define,...S.transform?.define})),(C.resolve||S.resolve)&&(N.resolve={...C.resolve,...S.resolve}),N}function legacyEsbuildToRolldown(t){let n={},S={},C={},N={};return t.outfile!==void 0&&(S.file=t.outfile),t.outdir!==void 0&&(S.dir=t.outdir),t.format!==void 0&&(S.format=t.format),t.minify!==void 0&&(S.minify=t.minify),t.sourcemap!==void 0&&(S.sourcemap=t.sourcemap===`inline`?`inline`:!!t.sourcemap),t.banner?.js!==void 0&&(S.banner=t.banner.js),t.target!==void 0&&(C.target=Array.isArray(t.target)?t.target.join(`,`):t.target),t.define!==void 0&&(C.define=t.define),t.mainFields!==void 0&&(N.mainFields=t.mainFields),t.conditions!==void 0&&(N.conditionNames=t.conditions),t.external!==void 0&&(n.external=t.external),t.platform!==void 0&&(n.platform=t.platform),Object.keys(S).length>0&&(n.output=S),Object.keys(C).length>0&&(n.transform=C),Object.keys(N).length>0&&(n.resolve=N),n}function mergeBundlerOptions(t,n){let{input:S,external:C,...N}=n,F={...t,...N};return(t.output||n.output)&&(F.output={...t.output,...n.output}),(t.transform||n.transform)&&(F.transform={...t.transform,...n.transform},(t.transform?.define||n.transform?.define)&&(F.transform.define={...t.transform?.define,...n.transform?.define}),(t.transform?.inject||n.transform?.inject)&&(F.transform.inject={...t.transform?.inject,...n.transform?.inject})),(t.resolve||n.resolve)&&(F.resolve={...t.resolve,...n.resolve}),F}var WF,GF,KF=__esmMin(()=>{_e(),WF=!1,GF=!1});function inputSourceDirs(t,n){let S=[],push=t=>{typeof t==`string`&&t.length>0&&S.push(t)};typeof t==`string`?push(t):Array.isArray(t)?t.forEach(push):t&&typeof t==`object`&&Object.values(t).forEach(push);let C=xn(n),N=new Set;for(let t of S){let n=t.replace(/\\/g,`/`),S=n.search(/[*?{}[\]()!+@]/),F=S===-1?n:n.slice(0,S);F=S===-1?On(F)?En(F):F:F.replace(/\/[^/]*$/,``);let I=xn(C,F||`.`);I!==C&&N.add(I)}return[...N]}function isInsideOrEqual(t,n){let S=Tn(n,t);return S===``||!S.startsWith(`..`)&&!Cn(S)}function isOutdirInsideSource(t,n,S){let C=xn(S,t);return n.some(t=>isInsideOrEqual(C,t))}function libraryOutputLeakError(t){return Error(`gjsify build --library: refusing to write output into "${t}", which holds the input source — a library build there produces src/*.js duplicates, *2.js, a _virtual/ helper dir, and a nested preserve-modules tree, silently corrupting the sources. This output dir was derived from package.json "main"/"module" pointing at a source path. Fix it by pointing "main"/"module" at the built library (e.g. lib/index.js) or by passing an explicit --outdir <dir> outside the source tree.`)}var qF=__esmMin(()=>{Pn()});function detectHtmlEntry(t){if(!t)return null;let isHtml=t=>typeof t==`string`&&/\.html?$/i.test(t);if(typeof t==`string`)return isHtml(t)?t:null;if(Array.isArray(t))return t.length===1&&isHtml(t[0])?t[0]:null;if(typeof t==`object`){let n=Object.values(t);return n.length===1&&isHtml(n[0])?n[0]:null}return null}function parseHtmlEntry(t,n){for(let S of n.matchAll(JF)){let n=S[0],C=YF.exec(n);if(!C)continue;let N=C[1];if(!XF.test(N))return{moduleEntry:Cn(N)?N:xn(En(t),N),scriptTag:n,scriptSrc:N}}throw Error(`gjsify build: ${t} has no local <script type="module" src="…"> to bundle. Add one pointing at your app entry (e.g. <script type="module" src="./main.ts">).`)}function emitBrowserHtml(t){let{htmlSource:n,scriptTag:S,scriptSrc:C,jsOutPath:N,outHtmlPath:F}=t,I=Tn(En(F),N).split(/[\\/]/).join(`/`);I.startsWith(`.`)||(I=`./${I}`);let H=S.replace(YF,t=>t.replace(C,I));return n.replace(S,H)}function htmlOutPathFor(t){return xn(En(t),`index.html`)}var JF,YF,XF,ZF=__esmMin(()=>{Pn(),JF=/<script\b[^>]*\btype\s*=\s*["']module["'][^>]*>(?:<\/script>)?/gi,YF=/\bsrc\s*=\s*["']([^"']+)["']/i,XF=/^(?:https?:)?\/\//i});function findDisallowedNodeImports(t,n=QF){let S=new Set;for(let C of t)for(let t of C.imports??[])t.startsWith(`node:`)&&(n.includes(t)||S.add(t));return[...S].sort()}function isBareSpecifier(t){return t.startsWith(`.`)||t.startsWith(`/`)||t.startsWith(`\\`)?!1:!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(t)}function findUnresolvableBareImports(t,n={}){let S=new Set(n.emitted??[]),C=new Set;for(let N of t)for(let t of N.imports??[])t.startsWith(`node:`)||isBareSpecifier(t)&&(S.has(t)||n.isExternal?.(t)||C.add(t));return[...C].sort()}function assertGjsBundleLoadable(t,n,S={}){let C=findDisallowedNodeImports(t);if(C.length>0)throw Error(`gjsify build --app gjs: ${n} still imports ${C.length} bare \`node:\` module(s), which stock GJS cannot resolve — it would fail at load with "ImportError: Unsupported URI scheme for importing: node".
796
+ `)}function resolveImportTargetForGjs(t){if(!isGjs())return t;let n=resolveNpmPackage(t,{bundleUrl:import.meta.url});return n?pathToFileURL(n).href:t}async function bundleToChunks(t){if(await shouldUseNative()){let n=await tryLoadNative();if(!n)throw Error(`@gjsify/rolldown-native not loadable`);let S=t.rolldownInput.plugins??[],C=[];for(let t of S)isPluginObject(t)&&C.push(toNativePlugin(t));let N=liftTransformExtras(stripUnserializable({...t.rolldownInput,input:normalizeInputForNative(t.rolldownInput.input),format:t.format}));delete N.plugins;let F=await n.bundleWithPlugins(N,C);reportNativeWarnings(F,t.rolldownInput);let I=[];for(let t of F.output)t.type===`chunk`&&I.push(t.code);return I}let n=await(await loadNpmRolldown())(t.rolldownInput);try{let S=await n.generate({format:t.format,minify:!1,sourcemap:!1}),C=[];for(let t of S.output)t.type===`chunk`&&C.push(t.code);return C}finally{await n.close()}}async function runWatch(t){if(await shouldUseNative())throw Error("`gjsify build --watch` requires the npm `rolldown` engine. The native engine (`@gjsify/rolldown-native`) does not expose a watcher API. Run the watch loop under Node (`node lib/index.js build … --watch`) or set `GJSIFY_BUNDLER=npm`.");let n=await import(resolveImportTargetForGjs(`rolldown`)),S=t.output??{};return n.watch({...t,output:S})}function warnNoNativeWatchList(){EF||(EF=!0,ge.warn("[gjsify] this `@gjsify/rolldown-native` build reports no watch list: it predates `addWatchFile`, so a file a plugin read itself (a stylesheet’s `@import` chain, an inlined `readFileSync`) cannot be declared as a build input. `gjsify test` will rebuild the affected bundles on every run rather than trust a set it cannot see. Upgrade the engine (it ships in the same release train as the CLI)."))}async function runBundle(t,n={}){if(await shouldUseNative())return await runNativeBundle(t,n);let S=await(await loadNpmRolldown())(t);try{let C=await S.write(t.output??{});return n.onWatchFiles&&n.onWatchFiles({files:await S.watchFiles,reportedByEngine:!0}),C}finally{await S.close()}}function resolveNativeLibraryModule(t={}){let n=`@gjsify/utils/native-library`;return resolveNpmPackage(n,t)??createRequire(t.bundleUrl??import.meta.url).resolve(n)}async function utilsCore(){return kF===null&&(kF=await import(pathToFileURL(resolveNativeLibraryModule({bundleUrl:import.meta.url})).href)),kF}async function shouldUseNative(){let t=(globalThis.process?.env??{}).GJSIFY_BUNDLER;if(t===`npm`)return!1;if(t===`native`){if(!await tryLoadNative())throw Error(`GJSIFY_BUNDLER=native but @gjsify/rolldown-native is not loadable (no prebuild for this architecture, or not running under GJS).`+(isGjs()?`\n${diagnoseNativeEngine()}`:``));return!0}return isGjs()?await tryLoadNative()!==null:!1}function findRolldownNativeDir(t,n){let S=wn(`node_modules`,`@gjsify`,`rolldown-native`,`package.json`),C=[t];n&&n!==t&&C.push(n);for(let t of C){let n=t;for(let t=0;t<12;t++){if(existsSync(wn(n,S)))return wn(n,`node_modules`,`@gjsify`,`rolldown-native`);let t=xn(n,`..`);if(t===n)break;n=t}}return null}async function tryLoadNative(){return DF||(DF=(async()=>{if(!isGjs())return null;try{activateNativePrebuilds();let t=`@gjsify/rolldown-native`,n=t;if(isGjs()){let S=En(fileURLToPath(import.meta.url)),C=resolveNpmPackage(t,{bundleUrl:import.meta.url}),N=C?null:(()=>{let n=findRolldownNativeDir(process.cwd(),S);if(!n)return null;try{return createRequire(pathToFileURL(wn(n,`__gjsify_resolve__.js`)).href).resolve(t)}catch{return null}})();n=pathToFileURL(C??N??createRequire(import.meta.url).resolve(t)).href}let S=await import(n);if(!S.hasNativeRolldown())return null;let C=null;try{C=await utilsCore()}catch(t){AF=t}return C!==null&&(OF=C.probeNativeLibrary(`GjsifyRolldown`),OF)?null:S}catch{return null}})(),DF)}async function runNativeBundle(t,n={}){let S=await tryLoadNative();if(!S)throw Error(`@gjsify/rolldown-native not loadable`);let C=t.plugins??[],N=[];for(let t of C)isPluginObject(t)&&N.push(toNativePlugin(t));let{output:F,plugins:I,...H}=t,W=liftTransformExtras(stripUnserializable({...H,...F,input:normalizeInputForNative(t.input)}));globalThis.process?.env?.GJSIFY_DEBUG_NATIVE_OPTS&&ge.error(`[gjsify-bundler-pick] native opts JSON:`,JSON.stringify(W));let q=await S.bundleWithPlugins(W,N);reportNativeWarnings(q,t),n.onWatchFiles&&(q.watchedFiles===void 0?(warnNoNativeWatchList(),n.onWatchFiles({files:[],reportedByEngine:!1})):n.onWatchFiles({files:q.watchedFiles,reportedByEngine:!0}));let Y=t.output??{},X=Y.dir??(Y.file?En(Y.file):process.cwd());X&&await yd.mkdir(X,{recursive:!0});for(let t of q.output){let n=Y.file&&t.type===`chunk`&&q.output.length===1?Y.file:wn(X,t.fileName);await yd.mkdir(En(n),{recursive:!0}),t.type===`chunk`?(await yd.writeFile(n,t.code,`utf8`),typeof t.map==`string`&&await yd.writeFile(`${n}.map`,t.map,`utf8`)):t.sourceText!==void 0&&await yd.writeFile(n,t.sourceText,`utf8`)}return synthRolldownOutput(q)}function reportNativeWarnings(t,n){if(n.logLevel===`silent`||!Array.isArray(t.warnings)||t.warnings.length===0)return;let S=new Set;for(let n of t.warnings)S.has(n)||(S.add(n),ge.warn(`[gjsify-bundler] ${n}`))}function stripUnserializable(t){let n={};for(let[S,C]of Object.entries(t)){if(typeof C==`function`){if(!jF.has(S)){jF.add(S);let t=S===`external`?" Function `external` predicates are NOT supported by the native engine — pass exact names as a string array and/or enforce shape rules via a resolveId plugin returning `{ external: true }` (see externalsPlugin in @gjsify/rolldown-plugin-gjsify).":` Function-valued options do not survive the JSON boundary to the Rust core.`;ge.warn(`[gjsify-bundler] dropping non-serializable option "${S}" for the native rolldown engine — behavior may diverge from npm rolldown.${t}`)}continue}if(S===`external`&&Array.isArray(C)){let t=C.find(t=>typeof t!=`string`);if(t!==void 0)throw Error(`gjsify build: \`external\` entries must be exact string names under the native rolldown engine (got ${t instanceof RegExp?t.toString():typeof t}). RegExp/function externals are only supported by npm rolldown — use exact names or a resolveId plugin returning \`{ external: true }\`.`);n[S]=C;continue}if(S===`sourcemap`){let t=translateSourcemapOption(C);t!==void 0&&(n[S]=t);continue}n[S]=C}return n}function translateSourcemapOption(t){if(t===!0||t===`file`||t===`File`)return`File`;if(t===`inline`||t===`Inline`)return`Inline`;if(t===`hidden`||t===`Hidden`)return`Hidden`}function liftTransformExtras(t){let n=t.transform;if(!n)return t;let S={},C={...n};for(let t of[`define`,`inject`])t in C&&(S[t]=C[t],delete C[t]);return S.inject!==void 0&&!Array.isArray(S.inject)&&(S.inject=mapToInjectArray(S.inject)),{...t,transform:Object.keys(C).length===0?void 0:C,...S}}function mapToInjectArray(t){let n=[];for(let[S,C]of Object.entries(t))if(typeof C==`string`)n.push({type:`named`,imported:`default`,from:C,alias:S});else{let[t,N]=C;N===`*`?n.push({type:`namespace`,from:t,alias:S}):n.push({type:`named`,from:t,imported:N,alias:S})}return n}function normalizeInputForNative(t){return t===void 0?[]:typeof t==`string`?[{import:t}]:Array.isArray(t)?t.map(t=>typeof t==`string`?{import:t}:t):Object.entries(t).map(([t,n])=>({name:t,import:n}))}function isPluginObject(t){return typeof t==`object`&&!!t&&!Array.isArray(t)}function pickHook(t){if(typeof t==`function`)return{fn:t};if(typeof t==`object`&&t&&`handler`in t){let n=t,S=filterToRegexSource(n.filter?.id),C={fn:n.handler};return S!==void 0&&(C.idFilter=S),C}}function filterToRegexSource(t){if(t!==void 0){if(Array.isArray(t)){let n=t.map(oneToSource).filter(t=>t!==void 0);return n.length===0?void 0:n.length===1?n[0]:`(?:${n.join(`|`)})`}return oneToSource(t)}}function oneToSource(t){if(t instanceof RegExp)return t.source;if(typeof t==`string`)return t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function toNativePlugin(t){let n={name:typeof t.name==`string`?t.name:`unnamed-plugin`},S={},C=pickHook(t.load);C&&(n.load=C.fn,C.idFilter&&(S.load=C.idFilter));let N=pickHook(t.transform);N&&(n.transform=N.fn,N.idFilter&&(S.transform=N.idFilter));let F=pickHook(t.resolveId);F&&(n.resolveId=F.fn,F.idFilter&&(S.resolveId=F.idFilter));let I=pickHook(t.renderChunk);I&&(n.renderChunk=I.fn);let H=pickHook(t.banner);H&&(n.banner=H.fn);let W=pickHook(t.footer);W&&(n.footer=W.fn);let q=pickHook(t.intro);q&&(n.intro=q.fn);let Y=pickHook(t.outro);Y&&(n.outro=Y.fn);let X=pickHook(t.buildStart);X&&(n.buildStart=X.fn);let Z=pickHook(t.buildEnd);Z&&(n.buildEnd=Z.fn);let te=pickHook(t.generateBundle);te&&(n.generateBundle=te.fn);let ne=pickHook(t.writeBundle);ne&&(n.writeBundle=ne.fn);let re=pickHook(t.closeBundle);return re&&(n.closeBundle=re.fn),Object.keys(S).length>0&&(n.idFilter=S),n}function synthRolldownOutput(t){return{output:t.output.map(t=>t.type===`chunk`?{type:`chunk`,fileName:t.fileName,code:t.code,name:t.name,isEntry:t.isEntry,isDynamicEntry:t.isDynamicEntry,map:t.map??null,sourcemapFileName:t.sourcemapFilename??null,imports:t.imports,dynamicImports:t.dynamicImports,facadeModuleId:null,moduleIds:[],modules:{},exports:[],referencedFiles:[],importedBindings:{}}:{type:`asset`,fileName:t.fileName,names:t.names,originalFileNames:t.originalFileNames,source:t.sourceText??``,needsCodeReference:!1})}}var EF,DF,OF,kF,AF,jF,MF=__esmMin(()=>{_e(),Rd(),Pn(),Il(),Gn(),nF(),vF(),TF(),d_(),EF=!1,DF=null,OF=null,kF=null,AF=null,jF=new Set});function isPluginByName(t){return typeof t==`object`&&!!t&&typeof t.name==`string`&&!(`apply`in t)&&!(`resolveId`in t)&&!(`load`in t)&&!(`transform`in t)&&!(`renderChunk`in t)&&!(`generateBundle`in t)}async function resolveUserPlugins(t,n,S={}){let C=S.loadModule??defaultLoadModule,N=createRequire(wn(n,`package.json`)),F=[];for(let S of t){if(!isPluginByName(S)){F.push(S);continue}let t;try{t=N.resolve(S.name)}catch(t){throw Error(`gjsify config: failed to resolve plugin "${S.name}" from ${n}. Add it to your project's dependencies, or pass a Plugin object directly. (${t.message})`)}let I=await C(t,S.name),H=S.export??`default`,W=I[H];if(typeof W!=`function`){let t=Object.keys(I).filter(t=>typeof I[t]==`function`);throw Error(`gjsify config: plugin "${S.name}" has no function export "${H}". Available function exports: ${t.length?t.join(`, `):`(none)`}.`)}let q=await W(S.options);if(q==null)throw Error(`gjsify config: plugin "${S.name}" factory returned ${q}. Check the plugin's signature — it should return a Rolldown/Vite plugin object.`);F.push(q)}return F}var defaultLoadModule,NF=__esmMin(()=>{Il(),Pn(),Gn(),defaultLoadModule=async t=>await import(pathToFileURL(t).href)}),PF,FF=__esmMin(()=>{PF={"@gjsify/buffer/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/canvas2d/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/canvas":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/document":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/font-face":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/image":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/location":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/match-media":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/dom-elements/register/observers":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/domparser/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/gamepad/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`Navigator`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`dispatchEvent`,`navigator`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/iframe/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`HTMLIFrameElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/buffer":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/encoding":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/microtask":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/navigator":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`Navigator`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`navigator`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/process":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/structured-clone":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/timers":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/node-globals/register/url":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`URL`,`URLSearchParams`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/web-globals/register/formdata":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`FormData`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/web-globals/register/performance":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webaudio/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webgl/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`Path2D`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WebGL2RenderingContext`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`document`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webrtc/register/data-channel":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`Event`,`EventTarget`,`File`,`MessageEvent`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webrtc/register/error":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`Event`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webrtc/register/media":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`Event`,`EventTarget`,`File`,`MediaStream`,`MediaStreamTrack`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@gjsify/webrtc/register/media-devices":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CountQueuingStrategy.DOMException.Event.EventTarget.File.MediaStream.MediaStreamTrack.Navigator.ReadableStream.TextDecoderStream.TextEncoderStream.TransformStream.WritableStream.atob.btoa.clearTimeout.navigator.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"@gjsify/webrtc/register/peer-connection":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CountQueuingStrategy.DOMException.Event.EventTarget.File.MediaStream.MediaStreamTrack.MessageEvent.RTCSessionDescription.ReadableStream.TextDecoderStream.TextEncoderStream.TransformStream.WritableStream.atob.btoa.clearTimeout.crypto.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"abort-controller/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"compression-streams/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CompressionStream`,`CountQueuingStrategy`,`DOMException`,`DecompressionStream`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-events/register/custom-events":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-events/register/event-target":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-events/register/global-event-target":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-events/register/ui-events":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"dom-exception/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"eventsource/register":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CompressionStream.CountQueuingStrategy.DOMException.DecompressionStream.Event.EventSource.EventTarget.File.Headers.MessageEvent.ReadableStream.Request.Response.TextDecoderStream.TextEncoderStream.TransformStream.URL.URLSearchParams.WritableStream.atob.btoa.clearTimeout.fetch.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"fetch/register/fetch":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CompressionStream.CountQueuingStrategy.DOMException.DecompressionStream.File.Headers.ReadableStream.Request.Response.TextDecoderStream.TextEncoderStream.TransformStream.URL.URLSearchParams.WritableStream.atob.btoa.clearTimeout.fetch.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"fetch/register/xhr":`AbortController.AbortSignal.Blob.Buffer.ByteLengthQueuingStrategy.CompressionStream.CountQueuingStrategy.DOMException.DecompressionStream.File.Headers.ReadableStream.Request.Response.TextDecoderStream.TextEncoderStream.TransformStream.URL.URLSearchParams.WritableStream.XMLHttpRequest.XMLHttpRequestUpload.atob.btoa.clearTimeout.fetch.performance.process.queueMicrotask.setTimeout.structuredClone`.split(`.`),"message-channel/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`MessageChannel`,`MessagePort`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/queuing":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/readable":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/text-streams":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/transform":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"web-streams/register/writable":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"webassembly/register/promise":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WebAssembly`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"webcrypto/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`crypto`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"websocket/register":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`clearTimeout`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`]}});function expandWithClosure(t,n){let S=new Set(t),C=[...t];for(;C.length>0;){let t=C.pop(),N=IF[t];if(!N)continue;let F=LF[N];if(F)for(let t of F)n.has(t)||IF[t]&&(S.has(t)||(S.add(t),C.push(t)))}return S}function isSubset(t,n){for(let S of t)if(!n.has(S))return!1;return!0}async function applyExcludeGlobals(t,n,S,C,N,F=N){if(C?.length)for(let n of C)t.delete(n);let I=detectedToRegisterPaths(t);for(let t of S)I.add(t);if(emitGiBackedDiagnostic(I,t,F),!C?.length)return{detected:t,injectPath:n};let H=F?filterResolvableRegisterPaths(I,F):I;return{detected:t,injectPath:H.size>0?await writeRegisterInjectFile(H,N)??void 0:void 0}}function detectedToRegisterPaths(t){let n=new Set;for(let S of t){let t=IF[S];t&&n.add(t)}return n}function giNamespacesForRegister(t){for(let n of Object.keys(RF))if(t===n||t.startsWith(n+`/`))return RF[n];return null}function describeGiBackedInjection(t,n){let S=new Set,C=new Set;for(let n of t){let t=giNamespacesForRegister(n);if(t){S.add(n);for(let n of t)C.add(n)}}if(S.size===0)return null;let N=[...n].filter(t=>{let n=IF[t];return!!n&&S.has(n)}).sort();return`[gjsify] note: --globals auto injected GTK/GNOME-backed register(s) — this bundle now requires ${[...C].sort().map(t=>`gi://${t}`).join(`, `)} at load.`+(N.length?` Triggered by: ${N.join(`, `)}.`:``)+` If it runs headless / SSR / in a GTK-less container it will throw "Typelib … not found"; drop those globals via excludeGlobals or pin an explicit --globals allowlist (e.g. node).`}function emitGiBackedDiagnostic(t,n,S){if(BF)return;let C=new Set;for(let n of t)giNamespacesForRegister(n)&&(S&&!isRegisterPathResolvable(n,S)||C.add(n));let N=describeGiBackedInjection(C,n);N&&(BF=!0,ge.warn(N))}function isFullConfig(t){return typeof t==`object`&&!!t&&!Array.isArray(t)&&`plugins`in t&&`options`in t}function mergeTransformOptions(t,n){if(!t)return n;if(!n)return t;let S={...t,...n};return(t.define||n.define)&&(S.define={...t.define,...n.define}),(t.inject||n.inject)&&(S.inject={...t.inject,...n.inject}),S}function mergeResolveOptions(t,n){return t?n?{...t,...n}:t:n}async function detectAutoGlobals(t,n,S,C,N={},F=defaultBundler){let I=N.extraGlobalsList?resolveGlobalsList(N.extraGlobalsList):new Set,H=new Set(N.excludeGlobals??[]),W=N.cwd,q=W&&N.toolchainDir?[W,N.toolchainDir]:W,Y=new Set,X;I.size>0&&(X=await writeRegisterInjectFile(q?filterResolvableRegisterPaths(I,q):I,W)??void 0);let Z=(t.plugins??[]).filter(t=>{let n=t&&typeof t==`object`&&`name`in t?t.name:void 0;return n!==`gjsify`&&n!==`gjsify-orchestrator`});for(let te=1;te<=zF;te++){let ne=await S({...n,autoGlobalsInject:X,skipProcessStub:!0}),re,ie;isFullConfig(ne)?(ie=ne.options,re=ne.plugins):re=ne;let ae=X?appendInjectAsEntry(t.input,X):t.input,oe=mergeResolveOptions(ie?.resolve,t.resolve),Q=t.external??ie?.external,se=mergeTransformOptions(ie?.transform,t.transform),ce=ie?.treeshake,le=Array.isArray(re)?re:[re],ue=await F({rolldownInput:{input:ae,external:Q,resolve:oe,transform:se,plugins:[...Z,...le],logLevel:`silent`,...ce===void 0?{}:{treeshake:ce}},format:t.format??`esm`});if(ue.length===0)return{detected:new Set,injectPath:X};let de=new Set;for(let t=0;t<ue.length;t++){let n=ue[t]??``;try{for(let t of detectFreeGlobals(n))de.add(t)}catch(S){if(globalThis.process?.env?.GJSIFY_DEBUG_AUTO_GLOBALS){let S=await Promise.resolve().then(()=>(Lg(),kg)),C=(await Promise.resolve().then(()=>(Pn(),yn))).join(S.tmpdir(),`gjsify-auto-globals-failed-chunk-${t}.mjs`);try{(await Promise.resolve().then(()=>(Rd(),Id))).writeFileSync(C,n),ge.error(`[gjsify-auto-globals] parse failed on chunk #${t} — wrote ${C} for inspection`)}catch{}}throw S}}if(H.size>0)for(let t of H)de.delete(t);if(isSubset(de,Y)){if(C){let t=[...Y].sort(),n=I.size>0?` (+ ${I.size} extra register module(s))`:``;ge.debug(`[gjsify] --globals auto: converged after ${te-1} iteration(s), ${Y.size} global(s)${t.length?`: `+t.join(`, `):``}${n}`)}return applyExcludeGlobals(Y,X,I,N.excludeGlobals,W,q)}let fe=N.disableClosureExpansion?de:expandWithClosure(de,H);C&&fe.size>de.size&&ge.debug(`[gjsify] --globals auto: closure map expanded ${de.size} → ${fe.size} global(s)`),te>1&&C&&ge.debug("[gjsify] --globals auto: detection grew past the closure-map expansion — the committed register-globals-closure map looks stale. Regenerate via `node packages/infra/cli/scripts/generate-register-closure.mjs`."),Y=new Set([...Y,...fe]);let pe=detectedToRegisterPaths(Y);for(let t of I)pe.add(t);if(q&&(pe=filterResolvableRegisterPaths(pe,q)),pe.size===0)return{detected:Y,injectPath:void 0};if(X=await writeRegisterInjectFile(pe,W)??void 0,C){let t=[...Y].sort();ge.debug(`[gjsify] --globals auto: iteration ${te}, ${Y.size} global(s)${t.length?`: `+t.join(`, `):``}`)}}return C&&ge.debug(`[gjsify] --globals auto: hit max iterations (${zF}), using last detected set`),applyExcludeGlobals(Y,X,I,N.excludeGlobals,W,q)}async function detectNodeGiGlobals(t,n,S,C=defaultBundler){let N=await S(n),F,I;isFullConfig(N)?(I=N.options,F=N.plugins):F=N;let H=(t.plugins??[]).filter(t=>{let n=t&&typeof t==`object`&&`name`in t?t.name:void 0;return n!==`gjsify`&&n!==`gjsify-orchestrator`}),W=Array.isArray(F)?F:[F],q=I?{...I}:{};delete q.output;let Y;try{Y=await C({rolldownInput:{...q,input:t.input,external:t.external??q.external,resolve:mergeResolveOptions(q.resolve,t.resolve),transform:mergeTransformOptions(q.transform,t.transform),plugins:[...H,...W],logLevel:`silent`},format:t.format??`esm`})}catch(t){return ge.warn(`[gjsify] --app node: could not analyse the bundle for GJS ambient globals (${t instanceof Error?t.message:String(t)}); skipping @gjsify/node-gi/globals injection. If this build uses print/imports/ARGV, add \`import '@gjsify/node-gi/globals'\` to the entry or pass --globals.`),!1}for(let t of Y)if(detectGjsAmbientGlobals(t).size>0||detectNodeGiModuleImports(t))return!0;return!1}function appendInjectAsEntry(t,n){return t===void 0?[n]:typeof t==`string`?[t,n]:Array.isArray(t)?[...t,n]:{...t,__gjsify_inject:n}}var defaultBundler,IF,LF,RF,zF,BF,VF=__esmMin(()=>{_e(),iS(),lS(),qx(),FF(),defaultBundler=async({rolldownInput:t,format:n})=>{let S=await(await import(`rolldown`)).rolldown(t);try{let t=await S.generate({format:n,minify:!1,sourcemap:!1}),C=[];for(let n of t.output)n.type===`chunk`&&C.push(n.code);return C}finally{await S.close()}},IF=Wx,LF=PF,RF=Kx,zF=5,BF=!1}),HF=__esmMin(()=>{lS(),iS(),VF()});function findPnpRoot(t){let n=t;for(;;){if(existsSync(wn(n,`.pnp.cjs`)))return n;let t=En(n);if(t===n)return null;n=t}}async function loadPnpApi(){try{let t=await import(`pnpapi`);return t.default??t}catch{return null}}async function pnpPlugin(t={}){let n=t.issuerUrl??import.meta.url;if(!findPnpRoot(process.cwd()))return null;let S=await loadPnpApi();if(S===null)return null;let C=fileURLToPath(n),N=createRequire(C),F=t.relayPackages??[`@gjsify/node-polyfills`,`@gjsify/web-polyfills`],I=[];for(let t of F)try{I.push(N.resolve(`${t}/package.json`))}catch{}return{name:`gjsify-pnp`,resolveId:{order:`pre`,async handler(t,n){if(t.startsWith(`.`)||t.startsWith(`/`))return null;if(t.startsWith(`gi://`))return{id:t,external:!0};if(t.startsWith(`node:`))return await this.resolve(t,n,{skipSelf:!0});if(!n)return null;let N=n.startsWith(`file://`)?fileURLToPath(n):n;try{let n=S.resolveRequest(t,N);return n===null?null:{id:n}}catch(n){if(!isUndeclaredDependency(n))throw n;try{let n=S.resolveRequest(t,C);if(n!==null)return{id:n}}catch(t){if(!isUndeclaredDependency(t))throw t}for(let n of I)try{let C=S.resolveRequest(t,n);if(C!==null)return{id:C}}catch(t){if(!isUndeclaredDependency(t))throw t}return null}}},async load(t){if(!t.includes(`/.yarn/`)&&!t.includes(`.zip/`))return null;try{return{code:await readFile$1(t,`utf8`)}}catch(n){let S=n instanceof Error?n.message:String(n);this.error(`gjsify-pnp: failed to read ${t}: ${S}`)}}}}function isUndeclaredDependency(t){return typeof t==`object`&&!!t&&`pnpCode`in t&&t.pnpCode===`UNDECLARED_DEPENDENCY`}var UF=__esmMin(()=>{Il(),Gn(),Pn(),Rd(),xd()});function normalizeBundlerOptions(t){let n=t.bundler??{},S=n;if(typeof n.define==`object`&&n.define!==null){GF||(GF=!0,ge.warn(`[gjsify] WARNING: 'bundler.define' is not a valid Rolldown option and would be silently ignored — it has been auto-mapped to 'bundler.transform.define'. Move 'define' under 'bundler.transform.define' in your config to suppress this warning and avoid a ReferenceError at GJS load time.`));let{define:t,...C}=n;S={...C,transform:{...C.transform,define:{...t,...C.transform?.define}}}}if(!t.esbuild)return S;WF||(WF=!0,ge.warn(`[gjsify] DEPRECATION: the 'esbuild' config key is deprecated and will be removed in 0.5.0. Rename it to 'bundler' (typed as RolldownOptions). See the migration notes in the gjsify CHANGELOG.`));let C=legacyEsbuildToRolldown(t.esbuild),N={...C,...S};return(C.output||S.output)&&(N.output={...C.output,...S.output}),(C.transform||S.transform)&&(N.transform={...C.transform,...S.transform},(C.transform?.define||S.transform?.define)&&(N.transform.define={...C.transform?.define,...S.transform?.define})),(C.resolve||S.resolve)&&(N.resolve={...C.resolve,...S.resolve}),N}function legacyEsbuildToRolldown(t){let n={},S={},C={},N={};return t.outfile!==void 0&&(S.file=t.outfile),t.outdir!==void 0&&(S.dir=t.outdir),t.format!==void 0&&(S.format=t.format),t.minify!==void 0&&(S.minify=t.minify),t.sourcemap!==void 0&&(S.sourcemap=t.sourcemap===`inline`?`inline`:!!t.sourcemap),t.banner?.js!==void 0&&(S.banner=t.banner.js),t.target!==void 0&&(C.target=Array.isArray(t.target)?t.target.join(`,`):t.target),t.define!==void 0&&(C.define=t.define),t.mainFields!==void 0&&(N.mainFields=t.mainFields),t.conditions!==void 0&&(N.conditionNames=t.conditions),t.external!==void 0&&(n.external=t.external),t.platform!==void 0&&(n.platform=t.platform),Object.keys(S).length>0&&(n.output=S),Object.keys(C).length>0&&(n.transform=C),Object.keys(N).length>0&&(n.resolve=N),n}function mergeBundlerOptions(t,n){let{input:S,external:C,...N}=n,F={...t,...N};return(t.output||n.output)&&(F.output={...t.output,...n.output}),(t.transform||n.transform)&&(F.transform={...t.transform,...n.transform},(t.transform?.define||n.transform?.define)&&(F.transform.define={...t.transform?.define,...n.transform?.define}),(t.transform?.inject||n.transform?.inject)&&(F.transform.inject={...t.transform?.inject,...n.transform?.inject})),(t.resolve||n.resolve)&&(F.resolve={...t.resolve,...n.resolve}),F}var WF,GF,KF=__esmMin(()=>{_e(),WF=!1,GF=!1});function inputSourceDirs(t,n){let S=[],push=t=>{typeof t==`string`&&t.length>0&&S.push(t)};typeof t==`string`?push(t):Array.isArray(t)?t.forEach(push):t&&typeof t==`object`&&Object.values(t).forEach(push);let C=xn(n),N=new Set;for(let t of S){let n=t.replace(/\\/g,`/`),S=n.search(/[*?{}[\]()!+@]/),F=S===-1?n:n.slice(0,S);F=S===-1?On(F)?En(F):F:F.replace(/\/[^/]*$/,``);let I=xn(C,F||`.`);I!==C&&N.add(I)}return[...N]}function isInsideOrEqual(t,n){let S=Tn(n,t);return S===``||!S.startsWith(`..`)&&!Cn(S)}function isOutdirInsideSource(t,n,S){let C=xn(S,t);return n.some(t=>isInsideOrEqual(C,t))}function libraryOutputLeakError(t){return Error(`gjsify build --library: refusing to write output into "${t}", which holds the input source — a library build there produces src/*.js duplicates, *2.js, a _virtual/ helper dir, and a nested preserve-modules tree, silently corrupting the sources. This output dir was derived from package.json "main"/"module" pointing at a source path. Fix it by pointing "main"/"module" at the built library (e.g. lib/index.js) or by passing an explicit --outdir <dir> outside the source tree.`)}var qF=__esmMin(()=>{Pn()});function detectHtmlEntry(t){if(!t)return null;let isHtml=t=>typeof t==`string`&&/\.html?$/i.test(t);if(typeof t==`string`)return isHtml(t)?t:null;if(Array.isArray(t))return t.length===1&&isHtml(t[0])?t[0]:null;if(typeof t==`object`){let n=Object.values(t);return n.length===1&&isHtml(n[0])?n[0]:null}return null}function parseHtmlEntry(t,n){for(let S of n.matchAll(JF)){let n=S[0],C=YF.exec(n);if(!C)continue;let N=C[1];if(!XF.test(N))return{moduleEntry:Cn(N)?N:xn(En(t),N),scriptTag:n,scriptSrc:N}}throw Error(`gjsify build: ${t} has no local <script type="module" src="…"> to bundle. Add one pointing at your app entry (e.g. <script type="module" src="./main.ts">).`)}function collectLinkedAssets(t,n){let S=[],C=new Map,N=new Set;for(let F of n.matchAll(ZF)){let n=F[0];if(!($F.exec(n)?.[1].toLowerCase().split(/\s+/)??[]).some(t=>eI.has(t)))continue;let I=QF.exec(n)?.[1];if(!I||tI.test(I))continue;let H=I.replace(/[?#].*$/,``),W=Cn(H)?H:xn(En(t),H),q=C.get(W);if(!q){let t=On(W),n=Dn(W,t);q=`assets/${n}${t}`;for(let S=1;N.has(q);S++)q=`assets/${n}-${S}${t}`;N.add(q),C.set(W,q)}S.push({linkTag:n,href:I,source:W,target:q})}return S}function emitBrowserHtml(t){let{htmlSource:n,scriptTag:S,scriptSrc:C,jsOutPath:N,outHtmlPath:F,assets:I=[]}=t,H=Tn(En(F),N).split(/[\\/]/).join(`/`);H.startsWith(`.`)||(H=`./${H}`);let W=S.replace(YF,t=>t.replace(C,H)),q=n.replace(S,W);for(let{linkTag:t,href:n,target:S}of new Map(I.map(t=>[t.linkTag,t])).values()){let C=t.replace(QF,t=>t.replace(n,`./${S}`));q=q.split(t).join(C)}return q}function htmlOutPathFor(t){return xn(En(t),`index.html`)}var JF,YF,XF,ZF,QF,$F,eI,tI,nI=__esmMin(()=>{Pn(),JF=/<script\b[^>]*\btype\s*=\s*["']module["'][^>]*>(?:<\/script>)?/gi,YF=/\bsrc\s*=\s*["']([^"']+)["']/i,XF=/^(?:https?:)?\/\//i,ZF=/<link\b[^>]*>/gi,QF=/\bhref\s*=\s*["']([^"']+)["']/i,$F=/\brel\s*=\s*["']([^"']+)["']/i,eI=new Set([`icon`,`apple-touch-icon`,`mask-icon`]),tI=/^(?:[a-z][a-z0-9+.-]*:|\/)/i});function findDisallowedNodeImports(t,n=rI){let S=new Set;for(let C of t)for(let t of C.imports??[])t.startsWith(`node:`)&&(n.includes(t)||S.add(t));return[...S].sort()}function isBareSpecifier(t){return t.startsWith(`.`)||t.startsWith(`/`)||t.startsWith(`\\`)?!1:!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(t)}function findUnresolvableBareImports(t,n={}){let S=new Set(n.emitted??[]),C=new Set;for(let N of t)for(let t of N.imports??[])t.startsWith(`node:`)||isBareSpecifier(t)&&(S.has(t)||n.isExternal?.(t)||C.add(t));return[...C].sort()}function assertGjsBundleLoadable(t,n,S={}){let C=findDisallowedNodeImports(t);if(C.length>0)throw Error(`gjsify build --app gjs: ${n} still imports ${C.length} bare \`node:\` module(s), which stock GJS cannot resolve — it would fail at load with "ImportError: Unsupported URI scheme for importing: node".
797
797
  `+C.map(t=>` - ${t}`).join(`
798
798
  `)+"\n\nThese should have been aliased to their `@gjsify/*` polyfills. The usual cause is that the alias TARGET could not be resolved, so the bundler externalised the import instead (look for UNRESOLVED_IMPORT warnings above): e.g. a workspace checkout whose `@gjsify/*` packages have no built `lib/`. Build the workspace first (`gjsify run build:infra`), or fix the resolution, then rebuild.");let N=findUnresolvableBareImports(t,S);if(N.length!==0)throw Error(`gjsify build --app gjs: ${n} statically imports ${N.length} bare package specifier(s) nothing in this build resolves or declares external. GJS has no node_modules walker and does not follow \`package.json#exports\`, so it aborts the whole module graph at load with "ImportError: Module not found: <specifier>".
799
799
  `+N.map(t=>` - ${t}`).join(`
800
- `)+'\n\nRolldown reports these as UNRESOLVED_IMPORT WARNINGS and re-emits the original specifier, which is why the build reached this point at all. Likely causes:\n - the package is not installed — add it as a dependency and `gjsify install`.\n - a JSX entry with no JSX configuration: oxc then defaults to the automatic runtime with `importSource: "react"`, so the bundle imports `react/jsx-runtime`. Point `gjsify.bundler.transform.jsx.importSource` (or tsconfig `"jsxImportSource"`) at a runtime this project HAS, or use `"jsx": "preserve"` plus the framework compiler that consumes it.\n - the specifier is meant to be provided by the host at runtime — then say so, with `gjsify.bundler.external`.')}function assertGjsBundleParses(t,n){for(let S of t){let t=S.code;if(typeof t!=`string`||t.length===0)continue;let C=locateSurvivingJsx(t);if(C!==null)throw Error(formatSurvivingJsx(C,S.fileName?`${n} (${S.fileName})`:n))}}var QF,$F=__esmMin(()=>{dM(),QF=[]});function describeJsxConfig(t){let{transformJsx:n,tsconfigJsx:S,tsconfigJsxImportSource:C}=t;return{configured:n!==void 0||S!==void 0||C!==void 0,preserves:n===void 0?S===`preserve`:n===`preserve`}}function collectEntryPaths(t){return typeof t==`string`?[t]:Array.isArray(t)?t.filter(t=>typeof t==`string`):typeof t==`object`&&t?Object.values(t).filter(t=>typeof t==`string`):[]}function findJsxEntryPoint(t){return t.find(t=>eI.test(t))}function jsxConfigMissingError(t){return Error(`gjsify build --app gjs: ${t} contains JSX, but nothing configures a JSX transform — not \`gjsify.bundler.transform.jsx\`, and not tsconfig \`compilerOptions.jsx\`.
800
+ `)+'\n\nRolldown reports these as UNRESOLVED_IMPORT WARNINGS and re-emits the original specifier, which is why the build reached this point at all. Likely causes:\n - the package is not installed — add it as a dependency and `gjsify install`.\n - a JSX entry with no JSX configuration: oxc then defaults to the automatic runtime with `importSource: "react"`, so the bundle imports `react/jsx-runtime`. Point `gjsify.bundler.transform.jsx.importSource` (or tsconfig `"jsxImportSource"`) at a runtime this project HAS, or use `"jsx": "preserve"` plus the framework compiler that consumes it.\n - the specifier is meant to be provided by the host at runtime — then say so, with `gjsify.bundler.external`.')}function assertGjsBundleParses(t,n){for(let S of t){let t=S.code;if(typeof t!=`string`||t.length===0)continue;let C=locateSurvivingJsx(t);if(C!==null)throw Error(formatSurvivingJsx(C,S.fileName?`${n} (${S.fileName})`:n))}}var rI,iI=__esmMin(()=>{dM(),rI=[]});function describeJsxConfig(t){let{transformJsx:n,tsconfigJsx:S,tsconfigJsxImportSource:C}=t;return{configured:n!==void 0||S!==void 0||C!==void 0,preserves:n===void 0?S===`preserve`:n===`preserve`}}function collectEntryPaths(t){return typeof t==`string`?[t]:Array.isArray(t)?t.filter(t=>typeof t==`string`):typeof t==`object`&&t?Object.values(t).filter(t=>typeof t==`string`):[]}function findJsxEntryPoint(t){return t.find(t=>aI.test(t))}function jsxConfigMissingError(t){return Error(`gjsify build --app gjs: ${t} contains JSX, but nothing configures a JSX transform — not \`gjsify.bundler.transform.jsx\`, and not tsconfig \`compilerOptions.jsx\`.
801
801
 
802
802
  Left unset, the bundler's transformer defaults to the automatic runtime with \`importSource: "react"\`, so the bundle would import \`react/jsx-runtime\`. GJS cannot resolve a bare specifier at all (no node_modules walker, no \`exports\` map), so the build would exit 0 with an UNRESOLVED_IMPORT warning and the artifact would abort at load with "ImportError: Module not found: react/jsx-runtime" — and where react IS installed it would render React elements, which a GTK host does nothing with.
803
803
 
@@ -812,23 +812,23 @@ Configure one of:
812
812
  or the same in tsconfig: \`"jsx": "react-jsx"\` + \`"jsxImportSource": "<pkg>"\`. NOT
813
813
  \`@gjsify/gtk-host\` — its \`/jsx-runtime\` is a TYPE surface and throws when called.
814
814
  - \`"jsx": false\`, if this entry should contain no JSX at all: the transformer then
815
- reports the JSX itself instead of compiling it for a runtime that is not there.`)}var eI,tI=__esmMin(()=>{eI=/\.(?:jsx|tsx|mjsx|cjsx|mtsx|ctsx)$/i});function giSystemProbes(){let t=new Map;for(let[n,S]of Object.entries(oF)){let C=nI[n];if(!C)throw Error(`[gjsify] PROBED_GI_LIBDIRS names '${n}' but HOST_MARKERS does not: a bundle cannot ask process.platform, so an ungated candidate would be prepended on every host that happens to have the directory.`);for(let n of S)t.set(`${n}\u0000${C}`,[n,`${n}/${sF}`,C])}return[...t.entries()].sort(([t],[n])=>t<n?-1:+(t>n)).map(([,t])=>t)}var nI,rI=__esmMin(()=>{lF(),nI={darwin:`/System/Library/CoreServices/SystemVersion.plist`}});function escapeRawNulForGjs(t){let n=t.split(`\0`);return{code:n.join(`\\x00`),replaced:n.length-1}}var iI=__esmMin(()=>{});function findUnshimmedGjsGlobals(t){return[...detectGjsAmbientGlobals(t)].sort()}function assertNodeBundleGlobalsShimmed(t,n){let S=findUnshimmedGjsGlobals(t);if(S.length!==0)throw Error(`gjsify build --app node: ${n} references ${S.length} GJS ambient global(s) that nothing installs on node/bun/deno, so the bundle throws \`ReferenceError: <name> is not defined\` the first time that code runs:
815
+ reports the JSX itself instead of compiling it for a runtime that is not there.`)}var aI,oI=__esmMin(()=>{aI=/\.(?:jsx|tsx|mjsx|cjsx|mtsx|ctsx)$/i});function giSystemProbes(){let t=new Map;for(let[n,S]of Object.entries(oF)){let C=sI[n];if(!C)throw Error(`[gjsify] PROBED_GI_LIBDIRS names '${n}' but HOST_MARKERS does not: a bundle cannot ask process.platform, so an ungated candidate would be prepended on every host that happens to have the directory.`);for(let n of S)t.set(`${n}\u0000${C}`,[n,`${n}/${sF}`,C])}return[...t.entries()].sort(([t],[n])=>t<n?-1:+(t>n)).map(([,t])=>t)}var sI,cI=__esmMin(()=>{lF(),sI={darwin:`/System/Library/CoreServices/SystemVersion.plist`}});function escapeRawNulForGjs(t){let n=t.split(`\0`);return{code:n.join(`\\x00`),replaced:n.length-1}}var lI=__esmMin(()=>{});function findUnshimmedGjsGlobals(t){return[...detectGjsAmbientGlobals(t)].sort()}function assertNodeBundleGlobalsShimmed(t,n){let S=findUnshimmedGjsGlobals(t);if(S.length!==0)throw Error(`gjsify build --app node: ${n} references ${S.length} GJS ambient global(s) that nothing installs on node/bun/deno, so the bundle throws \`ReferenceError: <name> is not defined\` the first time that code runs:
816
816
  `+S.map(t=>` - ${t}`).join(`
817
- `)+"\n\nThe `@gjsify/node-gi/globals` shim seeds them, but it is injected only when the pre-build detection pass finds them — and that pass did not. The two passes therefore disagreed about the module graph. Either the detection ran against a different graph than the one emitted (check that anything feeding `isGjsSourceBuild()` — the `--globals` register stub, `nodeGiGlobalsInject` — is settled BEFORE `detectNodeGiGlobals`), or the offending package should stop reaching for the legacy `imports` object: `gi://<Ns>` and the bare `system`/`gettext`/`cairo` built-ins resolve on both runtimes, `imports` does not.")}var aI=__esmMin(()=>{HF()});function splitWorkspaceSpecifier(t,n){if(t.startsWith(`.`)||t.startsWith(`/`)||t.includes(`:`))return null;let S=t.split(`/`),C=t.startsWith(`@`)?[2]:[1];for(let t of C){let C=S.slice(0,t).join(`/`);if(!n.has(C))continue;let N=S.slice(t).join(`/`);return{name:C,subpath:N?`./${N}`:`.`}}return null}function staticStringValue(t){if(t?.type===`Literal`)return typeof t.value==`string`?t.value:null;if(t?.type===`TemplateLiteral`&&t.expressions?.length===0){let n=t.quasis?.[0]?.value?.cooked;return typeof n==`string`?n:null}return null}function walkModuleAst(t,n){let S;try{S=parse$2(t,{ecmaVersion:`latest`,sourceType:`module`,allowHashBang:!0})}catch{return}let descend=t=>{if(!t||typeof t!=`object`)return;if(Array.isArray(t)){for(let n of t)descend(n);return}let S=t;n(S);for(let[t,n]of Object.entries(S))t===`type`||t===`start`||t===`end`||t===`loc`||descend(n)};descend(S)}function importedSpecifier(t){return t.type!==`ImportDeclaration`&&t.type!==`ExportNamedDeclaration`&&t.type!==`ExportAllDeclaration`&&t.type!==`ImportExpression`?null:staticStringValue(t.source)}function moduleSpecifiers$1(t){let n=[];return walkModuleAst(t,t=>{let S=importedSpecifier(t);S!==null&&n.push(S)}),n}function resolveRelative(t,n){let S=xn(En(t),n);for(let t of[S,`${S}.js`,`${S}.mjs`,wn(S,`index.js`)])try{if(statSync(t).isFile())return t}catch{}return null}function workspaceEntry(t,n){let S=t.manifest,pick=t=>{if(typeof t==`string`)return t;if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t;for(let t of[`node`,`import`,`default`,`gjs`])if(t in n){let S=pick(n[t]);if(S)return S}return null},C=null;if(typeof S.exports==`string`?C=n===`.`?S.exports:null:S.exports&&typeof S.exports==`object`&&(C=pick(S.exports[n])),!C&&n===`.`&&(C=typeof S.module==`string`?S.module:null,C??=typeof S.main==`string`?S.main:null),!C)return null;let N=xn(t.location,C);return existsSync(N)?N:null}function workspacePeers(t,n){return Object.keys(t.peerDependencies??{}).filter(t=>n.has(t))}function cliRuntimeClosure(t,n={}){let S=new Map(t.map(t=>[t.name,t])),C=new Set,N=n.entry,F=n.cliManifest;if(N===void 0||F===void 0){let t=cliPackageDir(),n=null;if(t)try{n=JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{}if(F??=n,N===void 0){let S=n?.bin,C=typeof S==`string`?S:S?.gjsify??n?.main;N=t&&C?xn(t,C):null}}for(let t of workspacePeers(F??{},S))C.add(t);if(!N||!existsSync(N))return C;let I=new Set,H=[N];for(;H.length>0;){let t=H.shift();if(I.has(t))continue;I.add(t);let n;try{n=readFileSync(t,`utf8`)}catch{continue}for(let N of moduleSpecifiers$1(n)){if(N.startsWith(`.`)){let n=resolveRelative(t,N);n&&H.push(n);continue}let n=splitWorkspaceSpecifier(N,S),F=n?S.get(n.name):void 0;if(!n||!F)continue;C.add(n.name);for(let t of workspacePeers(F.manifest,S))C.add(t);let I=workspaceEntry(F,n.subpath);I&&H.push(I)}}return C}var oI=__esmMin(()=>{Bx(),Rd(),Pn(),nh(),__name$1(moduleSpecifiers$1,`moduleSpecifiers`)});function scanGiNamespaces(t){return scanGiRequirements(t).namespaces}function scanGiRequirements(t){let n=new Set,S=new Set,C=new Set,N=new Set,F=[];walkModuleAst(t,t=>{let S=importedSpecifier(t);if(S!==null){let F=parseGiSpecifier(S);F!==null&&n.add(F),t.type===`ImportDeclaration`&&S===sI&&collectNodeGiBindings(t,C,N);return}if(t.type===`VariableDeclarator`&&loadsNodeGiModule(t.init)){let n=t.id;n?.type===`Identifier`&&typeof n.name==`string`&&N.add(n.name);return}t.type===`CallExpression`&&F.push(t)});for(let t of F){let F=optionalMarkerNamespace(t);if(F!==null){S.add(F);continue}let I=requireGiNamespace(t,C,N);I!==null&&n.add(I)}return{namespaces:[...n].sort(),optional:[...S].filter(t=>n.has(t)).sort()}}function optionalMarkerNamespace(t){let n=t.callee;if(n?.type!==`MemberExpression`||n.computed!==!0)return null;let S=n.property;if(S?.type!==`CallExpression`)return null;let C=S.callee,N=C?.type===`MemberExpression`?C.object:void 0,F=C?.type===`MemberExpression`?C.property:void 0;if(N?.type!==`Identifier`||N.name!==`Symbol`||F?.type!==`Identifier`||F.name!==`for`||staticStringValue((S.arguments??[])[0])!==`gjsify.optionalGi`)return null;let I=n.object;if(I?.type!==`Identifier`||I.name!==`globalThis`)return null;let H=t.arguments??[],W=staticStringValue(H[0]);if(W===null||!cI.test(W))return null;let q=staticStringValue(H[1]);return q===null||q===``?W:`${W}-${q}`}function parseGiSpecifier(t){if(!t.startsWith(`gi://`))return null;let[n,S]=t.slice(5).split(`?`,2);if(n===void 0||!cI.test(n))return null;if(S===void 0)return n;let C=/(?:^|&)version=([^&]+)/.exec(S)?.[1];return C===void 0?n:`${n}-${C}`}function collectNodeGiBindings(t,n,S){let C=t.specifiers??[];for(let t of C){let C=t.local;if(C?.type!==`Identifier`||typeof C.name!=`string`)continue;let N=t.imported;t.type===`ImportNamespaceSpecifier`?S.add(C.name):(t.type===`ImportDefaultSpecifier`||N?.type===`Identifier`&&N.name===`requireGi`)&&n.add(C.name)}}function loadsNodeGiModule(t){if(!t||typeof t!=`object`)return!1;let n=t;return n.type===`CallExpression`?staticStringValue((n.arguments??[])[0])===sI:!1}function requireGiNamespace(t,n,S){let C=t.callee,N=!1;if(C?.type===`Identifier`)N=typeof C.name==`string`&&n.has(C.name);else if(C?.type===`MemberExpression`&&C.computed!==!0){let t=C.property;if(t?.type!==`Identifier`||t.name!==`requireGi`)return null;let n=C.object;N=loadsNodeGiModule(n)||n?.type===`Identifier`&&typeof n.name==`string`&&S.has(n.name)}if(!N)return null;let F=t.arguments??[],I=staticStringValue(F[0]);if(I===null||!cI.test(I))return null;let H=staticStringValue(F[1]);return H===null?I:`${I}-${H}`}var sI,cI,lI=__esmMin(()=>{dM(),oI(),sI=`@gjsify/node-gi/gi`,cI=/^[A-Za-z][A-Za-z\d_]*$/});function namespaceOf(t){let n=t.indexOf(`-`);return n===-1?t:t.slice(0,n)}function planGiSelection({declared:t,scanned:n}){let S=new Map;for(let n of t){let t=namespaceOf(n),C=S.get(t);(C===void 0||C===t&&n!==t)&&S.set(t,n)}let C=[...new Set(n.map(namespaceOf).filter(t=>!S.has(t)&&!uI.has(t)))].sort();if(C.length>0)throw Error(`The bundle imports ${C.join(`, `)}, which nativescript.giNamespaces does not declare. An Android APK carries only the typelibs the config selects (ADR 0117), so this would install and then throw at the import. Add ${C.length===1?`it`:`them`} to nativescript.giNamespaces, or stop importing ${C.length===1?`it`:`them`}.`);let N=new Set(n.map(namespaceOf)),F=[...S.entries()].filter(([t])=>!N.has(t)).map(([,t])=>t).sort();return{selected:[...S.values()].sort(),unscanned:F}}var uI,dI=__esmMin(()=>{uI=new Set([`GLib`,`GObject`,`Gio`,`GioUnix`,`GLibUnix`,`GModule`,`GIRepository`])});function hasWildcard(t){return t.includes(`*`)||t.includes(`?`)}function segmentToRegExp(t){let n=t.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/\\\\]*`).replace(/\?/g,`[^/\\\\]`);return RegExp(`^${n}$`)}function assertInsideCwd(t,n,S){let C=Tn(S,t);if(C===``)throw Error(`gjsify clear: refusing to delete the working directory itself ("${n}").`);if(C===`..`||C.startsWith(`..${jn}`)||Cn(C))throw Error(`gjsify clear: "${n}" resolves to ${t}, outside the working directory ${S}. Only paths inside the package may be cleared.`)}function resolveClearTargets(t,n){let S=[],C=new Set;for(let N of t)for(let t of expandTarget(N,n))assertInsideCwd(t,N,n.cwd),!C.has(t)&&(C.add(t),S.push(t));return S}function expandTarget(t,n){let S=Dn(t),C=En(t);if(hasWildcard(C))throw Error(`gjsify clear: a wildcard is only supported in the last path segment — got "${t}".`);if(!hasWildcard(S))return[xn(n.cwd,t)];let N=xn(n.cwd,C);assertInsideCwdOrSelf(N,t,n.cwd);let F=segmentToRegExp(S),I;try{I=n.readdir(N)}catch{return[]}return I.filter(t=>F.test(t)).sort().map(t=>wn(N,t))}function assertInsideCwdOrSelf(t,n,S){Tn(S,t)!==``&&assertInsideCwd(t,n,S)}var fI=__esmMin(()=>{Pn()});function tokenizeSimpleCommand(t,n={}){let S=n.allowGlobs===!0?mI:pI,C=[],N=``,F=!1,I=null;for(let n=0;n<t.length;n++){let H=t[n];if(I===`'`){H===`'`?I=null:N+=H;continue}if(I===`"`){if(H===`"`)I=null;else if(H===`\\`&&(t[n+1]===`"`||t[n+1]===`\\`))N+=t[++n];else if(H===`$`||H==="`")return null;else N+=H;continue}if(H===`'`||H===`"`){I=H,F=!0;continue}if(H===` `||H===` `){F&&=(C.push(N),N=``,!1);continue}if(S.includes(H))return null;N+=H,F=!0}return I?null:(F&&C.push(N),C)}function gjsifyCommandArgv(t,n={}){let S=tokenizeSimpleCommand(t,n);return!S||S.length<2||S[0]!==`gjsify`?null:S.slice(1)}var pI,mI,hI=__esmMin(()=>{pI=`|&;<>\`$()\\
818
- \r*?{}[]~#!`,mI=pI.replace(`*`,``).replace(`?`,``)});function packageOutputPaths(t){let n=t?.scripts?.clear;if(n===void 0)return[...gI];let S=gjsifyCommandArgv(n,{allowGlobs:!0});return S===null||S[0]!==`clear`?[]:[...S.slice(1).filter(t=>!t.startsWith(`-`)),...gI]}function readPackageManifest(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf-8`))}catch{return null}}function makeOutputMatcher(t){let n=t.map(t=>t.split(/[\\/]+/).filter(t=>t!==``&&t!==`.`).map(t=>hasWildcard(t)?segmentToRegExp(t):t)).filter(t=>t.length>0);return t=>{let S=t.split(`/`);for(let t of n){if(t.length>S.length)continue;let n=!0;for(let C=0;C<t.length;C++){let N=t[C],F=S[C];if(typeof N==`string`?N!==F:!N.test(F)){n=!1;break}}if(n)return!0}return!1}}function walk(t,n,S,C){let N;try{N=readdirSync(t)}catch{return}N.sort();for(let F of N){if(F===`node_modules`||F.startsWith(`.`))continue;let N=n===``?F:`${n}/${F}`;if(S(N))continue;let I=wn(t,F),H;try{H=lstatSync(I)}catch{continue}H.isSymbolicLink()?C.push({rel:N,abs:I,link:readLinkTarget(I)}):H.isDirectory()?walk(I,N,S,C):H.isFile()&&C.push({rel:N,abs:I})}}function readLinkTarget(t){try{return readlinkSync(t)}catch{return``}}function packageBuildInputs(t,n={}){let S=[...packageOutputPaths(n.manifest===void 0?readPackageManifest(t):n.manifest),...n.extraOutputs??[]],C=[];return walk(t,``,makeOutputMatcher(S),C),C}function newestInputMtimeMs(t){let n=0;for(let S of t)try{let{mtimeMs:t}=statSync(S.abs);t>n&&(n=t)}catch{return 1/0}return n}function newestDepSignalMtimeMs(t){let n=0,S=t;for(;;){for(let t of _I){let C=wn(S,t);if(existsSync(C))try{let{mtimeMs:t}=statSync(C);t>n&&(n=t)}catch{}}let t=En(S);if(t===S)return n;S=t}}var gI,_I,vI=__esmMin(()=>{Rd(),Pn(),fI(),hI(),gI=[`lib`,`dist`,`dist-templates`],_I=[`gjsify-lock.json`,`package-lock.json`,`yarn.lock`,`pnpm-lock.yaml`]}),yI=__exportAll$5({BuildAction:()=>xI});function isUnsafeDefaultOutput(t){if(/\.[cm]?tsx?$/i.test(t))return!0;let n=t.replace(/\\/g,`/`);return!!/(?:^|\/)src\//.test(n)}async function buildPnpPlugin(){return pnpPlugin({issuerUrl:import.meta.url})}function shortHash(t){let n=5381;for(let S=0;S<t.length;S++)n=(n<<5)+n+t.charCodeAt(S)>>>0;return n.toString(16).padStart(8,`0`)}function isTruthyEnv(t){return t===`1`||t===`true`||t===`yes`}async function newestLockfileMtime(t){let n=0;for(let S of _I)try{let C=await stat$1(wn(t,S));C.mtimeMs>n&&(n=C.mtimeMs)}catch{}return n}function runningCliFile(){try{return fileURLToPath(import.meta.url)}catch{return null}}async function isBundleFresh(t,n,S,C){try{let N=await stat$1(t),F=await stat$1(n),I=await newestLockfileMtime(S),H=C===void 0?0:(await stat$1(C)).mtimeMs;return N.mtimeMs>=Math.max(F.mtimeMs,I,H)}catch{return!1}}async function runOneLibraryBuild(t){let n=await gjsifyPlugin({input:t.userBundler.input,output:t.output,userAliases:t.userAliases},t.pluginOpts);return await runBundle({...mergeBundlerOptions(n.options,t.userBundler),plugins:[...t.pnpPlugins,...n.prePlugins,...t.userPlugins,...n.plugins]})}var bI,xI,SI=__esmMin(()=>{_e(),MF(),dM(),d_(),NF(),HF(),UF(),Pn(),Gn(),xd(),KF(),qF(),ZF(),$F(),tI(),rI(),iI(),aI(),lI(),dI(),vI(),bI=`#!/usr/bin/env -S gjs -m`,xI=class BuildAction{configData;constructor(t={}){this.configData=t}async buildLibrary(){let{verbose:t,library:n,typescript:S,exclude:C,aliases:N}=this.configData,F=n??{},I=normalizeBundlerOptions(this.configData),H=process.cwd(),W=inputSourceDirs(I.input,H),assertDerivedOutdirSafe=t=>{if(t&&isOutdirInsideSource(t,W,H))throw libraryOutputLeakError(t)},q=F.module?En(F.module):void 0,Y=F.main?En(F.main):void 0,X=F.module?On(F.module):`.js`,Z=F.main?On(F.main):`.js`,te=q&&Y&&q!==Y,ne=await buildPnpPlugin(),re=ne?[ne]:[],ie=textLoaderPlugin({loaders:this.configData.loaders}),ae=ie?[ie]:[];if(I.plugins?.length){let n=await resolveUserPlugins(I.plugins,process.cwd(),isGjs()?{loadModule:(n,S)=>this.loadPluginViaGjsBundle(n,S,t)}:{});ae.push(...n)}let oe=[];if(te){assertDerivedOutdirSafe(q),assertDerivedOutdirSafe(Y);let n=q.includes(`/cjs`)||X===`.cjs`?`cjs`:`esm`;oe.push(await runOneLibraryBuild({pluginOpts:{debug:t,library:n,exclude:C,reflection:S?.reflection,jsExtension:X},userBundler:I,output:{dir:q},userAliases:N,pnpPlugins:re,userPlugins:ae}));let F=Y.includes(`/cjs`)||Z===`.cjs`?`cjs`:`esm`;oe.push(await runOneLibraryBuild({pluginOpts:{debug:t,library:F,exclude:C,reflection:S?.reflection,jsExtension:Z},userBundler:I,output:{dir:Y},userAliases:N,pnpPlugins:re,userPlugins:ae}))}else{let n=I.output?.dir,H=I.output?.file??F.module??F.main,W=H?On(H):`.js`,q=n??(H?En(H):void 0);n===void 0&&assertDerivedOutdirSafe(q);let Y=I.output?.format??(q?.includes(`/cjs`)||W===`.cjs`?`cjs`:`esm`);oe.push(await runOneLibraryBuild({pluginOpts:{debug:t,library:Y,exclude:C,reflection:S?.reflection,jsExtension:W},userBundler:I,output:{dir:q},userAliases:N,pnpPlugins:re,userPlugins:ae}))}return oe}parseGlobalsValue(t){if(t===void 0)return{autoMode:!0,extras:``};if(t===`none`||t===``)return{autoMode:!1,extras:``};let n=t.split(`,`).map(t=>t.trim()).filter(Boolean);return{autoMode:n.includes(`auto`),extras:n.filter(t=>t!==`auto`).join(`,`)}}async resolveGlobalsInject(t,n,S){if(t!==`gjs`&&t!==`node`||!n)return;let C=resolveGlobalsList(n);if(C.size===0)return;let N=await writeRegisterInjectFile(C,process.cwd(),{reverseBridgeOverride:t===`node`});return S&&N&&ge.debug(`[gjsify] globals: injected ${C.size} register module(s) from --globals ${n}`),N??void 0}async applyShebang(t,n,S){if(!n){S&&ge.warn(`[gjsify] --shebang skipped: no single outfile (use --outfile for executables)`);return}let C=t===`node`?Fj:bI,N=resolveShebangLine(this.configData.shebang,C)??C,F=await readFile$1(n,`utf-8`);F.startsWith(`#!`)?S&&ge.debug(`[gjsify] --shebang skipped: ${n} already starts with a shebang`):await writeFile$1(n,N+`
819
- `+F),await chmod$1(n,493),S&&ge.debug(`[gjsify] --shebang: wrote ${N} + chmod 0o755 to ${n}`)}async escapeRawNul(t,n,S){let C=[];if(t)C.push(t);else if(n)try{for(let t of await readdir$1(n))(t.endsWith(`.mjs`)||t.endsWith(`.js`))&&C.push(xn(n,t))}catch(t){if(t?.code===`ENOENT`)return;throw t}for(let t of C){let n;try{n=await readFile$1(t,`utf-8`)}catch(t){if(t?.code===`ENOENT`)continue;throw t}let{code:C,replaced:N}=escapeRawNulForGjs(n);N!==0&&(await writeFile$1(t,C),S&&ge.debug(`[gjsify] escaped ${N} raw NUL byte(s) in ${t} so GJS can load it`))}}assertGjsOutputLoadable(t,n,S,C){assertGjsBundleLoadable((t.output??[]).filter(t=>t.type===`chunk`),n??S??`the GJS bundle`,{isExternal:createGjsExternalsPredicate(C??[]),emitted:(t.output??[]).map(t=>t.fileName)})}assertNodeOutputGlobals(t,n,S){let C=n??S??`the node bundle`;for(let n of t.output??[]){if(n.type!==`chunk`)continue;let t=n.code;typeof t!=`string`||t.length===0||assertNodeBundleGlobalsShimmed(t,n.fileName?`${C} (${n.fileName})`:C)}}assertNativescriptGiSelected(t,n,S){let C=n??S??`the nativescript bundle`,N=new Set;for(let n of t.output??[]){if(n.type!==`chunk`)continue;let t=n.code;if(!(typeof t!=`string`||t.length===0))for(let n of scanGiNamespaces(t))N.add(n)}let F;try{F=planGiSelection({declared:this.configData.nativescript?.giNamespaces??[],scanned:[...N]})}catch(t){throw Error(`gjsify build: ${C}: ${t.message}`)}for(let t of F.unscanned)ge.warn(`[gjsify] --app nativescript: nativescript.giNamespaces declares ${t}, which ${C} does not appear to import. The APK carries it anyway — drop it if nothing needs it, since every selected namespace costs APK size.`)}async applyBrowserHtml(t,n,S){let C=xn(n),N=htmlOutPathFor(C),F=emitBrowserHtml({htmlSource:t.htmlSource,scriptTag:t.scriptTag,scriptSrc:t.scriptSrc,jsOutPath:C,outHtmlPath:N});await mkdir$1(En(N),{recursive:!0}),await writeFile$1(N,F),S&&ge.debug(`[gjsify] --app browser: wrote ${N}`)}async loadPluginViaGjsBundle(t,n,S){let C=await this.bundlePluginForGjs(t,n,S);try{return await import(pathToFileURL(C).href)}catch(t){throw Error(`gjsify config: failed to import the GJS bundle for plugin "${n}" (bundled to ${C}). (${t.message})`)}}async bundlePluginForGjs(t,n,S){try{return await BuildAction.bundleFileForGjsCached(t,{cacheSubdir:`plugins`,label:n,verbose:S,noCacheEnv:`GJSIFY_NO_PLUGIN_CACHE`,resolveFromToolchain:!0})}catch(t){throw Error(`gjsify config: failed to bundle plugin "${n}" for GJS (needed because GJS can't import packages that use exports-map subpaths directly). (${t.message})`)}}static async bundleFileForGjsCached(t,n){let S=process.cwd(),C=wn(S,`node_modules`,`.cache`,`gjsify`,n.cacheSubdir),N=n.label.replace(/[^a-zA-Z0-9._-]/g,`_`),F=n.resolveFromToolchain===!0?runningCliFile():null,I=wn(C,`${N}-${shortHash(n.globals===void 0&&n.excludeGlobals===void 0&&F===null?t:`${t} ${JSON.stringify([n.globals??null,n.excludeGlobals??null,F])}`)}`,`${Dn(t).replace(/\.[cm]?[jt]sx?$/i,``)}.mjs`);return!(n.cache===!1||n.noCacheEnv&&isTruthyEnv(process.env[n.noCacheEnv]))&&await isBundleFresh(I,t,S,F??void 0)?(n.verbose&&ge.debug(`[gjsify] reusing cached GJS bundle ${I}`),I):(n.verbose&&ge.debug(`[gjsify] bundling ${t} for GJS → ${I}`),await BuildAction.bundleFileForGjs(t,I,{...n,toolchainAnchor:F}),I)}static async bundleFileForGjs(t,n,S){await mkdir$1(En(n),{recursive:!0}),await new BuildAction({verbose:S.verbose,...S.globals===void 0?{}:{globals:S.globals},...S.excludeGlobals===void 0?{}:{excludeGlobals:S.excludeGlobals},bundler:{input:t,output:{file:n},...S.define?{transform:{define:S.define}}:{},...S.logLevel?{logLevel:S.logLevel}:{}}}).buildApp(`gjs`,{preserveDefaultExport:S.preserveDefaultExport??!0,...S.toolchainAnchor?{toolchainAnchor:S.toolchainAnchor}:{}})}static runningCliFile(){return runningCliFile()}async buildApp(t=`gjs`,n={}){let{verbose:S,typescript:C,exclude:N,library:F,aliases:I,excludeGlobals:H}=this.configData,W=normalizeBundlerOptions(this.configData),q=describeJsxConfig({transformJsx:W.transform?.jsx,tsconfigJsx:C?.compilerOptions?.jsx,tsconfigJsxImportSource:C?.compilerOptions?.jsxImportSource});if(t===`gjs`&&!q.configured){let t=findJsxEntryPoint(collectEntryPaths(await globToEntryPoints(W.input,N)));if(t!==void 0)throw jsxConfigMissingError(t)}let Y=null;if(t===`browser`){let t=detectHtmlEntry(W.input);if(t){let n=await readFile$1(t,`utf-8`),{moduleEntry:S,scriptTag:C,scriptSrc:N}=parseHtmlEntry(t,n);W.input=S,Y={htmlSource:n,scriptTag:C,scriptSrc:N}}}let X=W.output?.format??(W.output?.file?.endsWith(`.cjs`)?`cjs`:`esm`),Z=X===`iife`?`esm`:X,te=W.output?.file,ne=W.output?.dir;if(!te&&!ne&&(F?.main||F?.module)){let t=Z===`cjs`?F.main??F.module:F.module??F.main;if(t&&isUnsafeDefaultOutput(t))throw Error(`gjsify build: refusing to default --outfile to ${t} (would overwrite a TypeScript source file). Pass --outfile/--outdir explicitly, or set "gjsify.bundler.output.file" in package.json.`);te=t}if(Y&&!te)throw Error(`gjsify build: an .html entry needs an explicit --outfile (e.g. --outfile dist-app/app.js); the emitted index.html is written beside it.`);let{consoleShim:re,globals:ie,dialect:ae,giRenderer:oe}=this.configData,Q=Array.isArray(W.external)?W.external:void 0,se=typeof W.output?.banner==`string`?W.output.banner:void 0,ce={debug:S,app:t,format:Z,exclude:N,reflection:C?.reflection,consoleShim:re,...ae===void 0?{}:{dialect:ae},...oe===!0?{giRenderer:!0}:{},...I?{aliases:I}:{},...n.preserveDefaultExport?{preserveDefaultExport:!0}:{},...n.toolchainAnchor===void 0?{}:{toolchainAnchor:n.toolchainAnchor}},{autoMode:le,extras:ue}=this.parseGlobalsValue(ie),de=await buildPnpPlugin(),fe=de?[de]:[],pe=textLoaderPlugin({loaders:this.configData.loaders}),me=pe?[pe]:[];if(W.plugins?.length){let t=await resolveUserPlugins(W.plugins,process.cwd(),isGjs()?{loadModule:(t,n)=>this.loadPluginViaGjsBundle(t,n,S)}:{});me.push(...t)}if(t===`gjs`&&le){let gjsifyPluginFactory=async t=>{let n=await gjsifyPlugin({input:W.input,output:{file:te,dir:ne},userExternal:Q,userBanner:se,userAliases:I,shebang:this.configData.shebang},t);return{options:n.options,plugins:n.plugins}},{injectPath:t}=await detectAutoGlobals({input:W.input,plugins:[...fe,...me],external:W.external,transform:W.transform,format:Z},ce,gjsifyPluginFactory,S,{extraGlobalsList:ue,excludeGlobals:H,cwd:process.cwd(),...n.toolchainAnchor===void 0?{}:{toolchainDir:En(n.toolchainAnchor)}},bundleToChunks);ce.autoGlobalsInject=t}else if(t===`node`&&le){ue&&(ce.autoGlobalsInject=await this.resolveGlobalsInject(t,ue,S));let gjsifyPluginFactory=async t=>{let n=await gjsifyPlugin({input:W.input,output:{file:te,dir:ne},userExternal:Q,userBanner:se,userAliases:I,shebang:this.configData.shebang},t);return{options:n.options,plugins:n.plugins}};await detectNodeGiGlobals({input:W.input,plugins:[...fe,...me],external:W.external,transform:W.transform,format:Z},ce,gjsifyPluginFactory,bundleToChunks)&&(ce.nodeGiGlobalsInject=!0)}else ue&&(ce.autoGlobalsInject=await this.resolveGlobalsInject(t,ue,S));let he=t===`gjs`?giSystemProbes():void 0,ge=await gjsifyPlugin({input:W.input,output:{file:te,dir:ne},userExternal:Q,userBanner:se,userAliases:I,shebang:this.configData.shebang,giSystemProbes:he},ce),_e={...mergeBundlerOptions(ge.options,W),plugins:[...fe,...ge.prePlugins,...me,...ge.plugins]};if(n.watch)return await this.runWatchLoop(_e,t,te,ne,S),[];let ve=await runBundle(_e,{onWatchFiles:n.onWatchFiles});return t===`gjs`&&await this.escapeRawNul(te,ne,S),(t===`gjs`||t===`node`)&&this.configData.shebang&&await this.applyShebang(t,te,S),t===`gjs`&&(this.assertGjsOutputLoadable(ve,te,ne,Q),q.preserves&&assertGjsBundleParses((ve.output??[]).filter(t=>t.type===`chunk`),te??ne??`the GJS bundle`)),t===`node`&&le&&!ce.nodeGiGlobalsInject&&this.assertNodeOutputGlobals(ve,te,ne),t===`nativescript`&&this.assertNativescriptGiSelected(ve,te,ne),t===`browser`&&Y&&te&&await this.applyBrowserHtml(Y,te,S),[ve]}async runWatchLoop(t,n,S,C,N){let F=await runWatch(t),I=new Promise(t=>{F.on(`close`,()=>t())}),H=!1,shutdown=async()=>{if(!H){H=!0,ge.log(`
820
- [gjsify build --watch] stopping watcher…`);try{await F.close()}catch(t){ge.error(`[gjsify build --watch] watcher close error:`,t)}}};process.on(`SIGINT`,shutdown),process.on(`SIGTERM`,shutdown),F.on(`event`,async t=>{switch(t.code){case`START`:N&&ge.log(`[gjsify build --watch] rebuild start`);break;case`BUNDLE_START`:ge.log(`[gjsify build --watch] building…`);break;case`BUNDLE_END`:ge.log(`[gjsify build --watch] built in ${t.duration}ms`);try{n===`gjs`&&await this.escapeRawNul(S,C,N),(n===`gjs`||n===`node`)&&this.configData.shebang&&await this.applyShebang(n,S,N)}finally{await t.result.close()}break;case`END`:ge.log(`[gjsify build --watch] waiting for changes…`);break;case`ERROR`:ge.error(`[gjsify build --watch] build failed:`,t.error?.message??t.error),N&&t.error?.stack&&ge.error(t.error.stack);try{await t.result.close()}catch{}break}}),N&&F.on(`change`,(t,n)=>{ge.log(`[gjsify build --watch] ${n.event}: ${t}`)}),await I}async start(t={app:`gjs`}){if(t.library){if(t.watch)throw Error(`gjsify build: --watch is not supported with --library (library mode would emit watcher rebuilds for every produced format; use --app gjs|node|browser instead).`);return await this.buildLibrary()}return await this.buildApp(t.app,{watch:t.watch,onWatchFiles:t.onWatchFiles})}}});function isModuleResolutionFailure(t){let n=t instanceof Error?t.message:String(t);return/Unsupported URI scheme|\bnode:|Cannot find (module|package)|Module not found|ERR_MODULE_NOT_FOUND|Failed to resolve/i.test(n)}async function loadConfigViaGjsBundle(t,n){let S;try{let{BuildAction:C}=await Promise.resolve().then(()=>(SI(),yI));S=await C.bundleFileForGjsCached(t,{cacheSubdir:`config`,label:Dn(t),verbose:n,noCacheEnv:`GJSIFY_NO_CONFIG_CACHE`,define:{"import.meta.url":JSON.stringify(pathToFileURL(t).href)},resolveFromToolchain:!0})}catch(n){throw Error(`gjsify: failed to bundle the config ${t} for the GJS CLI. Fixes: run the build under Node (\`npx gjsify …\`), keep the config to plain values / \`process.env\`, or move settings into \`package.json#gjsify\`. (${n.message})`)}try{let t=await import(pathToFileURL(S).href);return t.default??t}catch(n){throw Error(`gjsify: bundled the config ${t} for GJS but could not import the result (${S}). (${n.message})`)}}function defaultSearchPlaces(t){return[`package.json`,`.${t}rc`,`.${t}rc.json`,`.${t}rc.yaml`,`.${t}rc.yml`,`.${t}rc.js`,`.${t}rc.ts`,`.${t}rc.mjs`,`.${t}rc.cjs`,`${t}.config.js`,`${t}.config.ts`,`${t}.config.mjs`,`${t}.config.cjs`]}function merge(t,...n){for(let S of n)if(S)for(let n of Object.keys(S)){let C=t[n],N=S[n];N!==void 0&&(isPlainObject(C)&&isPlainObject(N)?merge(C,N):t[n]=N)}return t}function isPlainObject(t){return typeof t==`object`&&!!t&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype}function readDottedPath(t,n){if(!n.includes(`.`))return t[n];let S=t;for(let t of n.split(`.`)){if(typeof S!=`object`||!S)return;S=S[t]}return S}var CI,gjsConfigLoader,wI,Config,TI=__esmMin(()=>{_e(),ih(),ch(),CI=u_(),Pn(),Gn(),d_(),W_(),dM(),_v(),TN(),UP(),gjsConfigLoader=async t=>{try{let n=await import(pathToFileURL(t).href);return n.default??n}catch(n){if(!isModuleResolutionFailure(n))throw n;return loadConfigViaGjsBundle(t,!!process.env.GJSIFY_DEBUG)}},wI=isGjs()?{".js":gjsConfigLoader,".mjs":gjsConfigLoader,".cjs":gjsConfigLoader}:{},Config=class{loadOptions={};constructor(t={}){Object.keys(t).length&&(this.loadOptions=t)}async load(t){let n=await(0,CI.cosmiconfig)(rh,{...this.loadOptions,searchPlaces:(this.loadOptions.searchPlaces??defaultSearchPlaces(`gjsify`)).filter(t=>t!==`package.json`),loaders:{...wI,...this.loadOptions.loaders}}).search(t),S={};try{let n=await this.readPackageJSON(t);isPlainObject(n?.gjsify)&&merge(S,n.gjsify)}catch{}return n?.config&&isPlainObject(n.config)&&merge(S,n.config),S.bundler||={},S.library||={},S.typescript||={},{config:S,filepath:n?.filepath??``,isEmpty:!n&&Object.keys(S).length===3}}async readPackageJSON(t){return t=await resolvePackageJSON(t),await readPackageJSON(t)}async readTSConfig(t){return LP(t)?.config||{}}async forNodeScript(t){let{config:n}=await this.load(En(t));return{globals:n.nodeScript?.globals??n.globals,excludeGlobals:n.nodeScript?.excludeGlobals??n.excludeGlobals}}async forCommand(t=process.cwd()){let{config:n}=await this.load(t);return n}async forBuild(t){let n=await this.load(process.cwd()),S={...n.config},C=n.filepath||process.cwd(),N=await this.readPackageJSON(C),F=await this.readTSConfig(C);if(F.reflection||=t.reflection,S.verbose=t.verbose||t.logLevel===`debug`||t.logLevel===`verbose`,S.exclude=t.exclude||[],t.consoleShim!==void 0&&(S.consoleShim=t.consoleShim),t.giRenderer!==void 0&&(S.giRenderer=t.giRenderer),t.dialect!==void 0){if(!isSourceDialect(t.dialect))throw Error(`gjsify build: "${t.dialect}" is not a source dialect. Known: ${G_.join(`, `)}. This is the dialect the SOURCE is written in — not gjsify.runtimes, which declares the runtime a package RUNS on.`);S.dialect=t.dialect}if(t.app!==void 0&&(S.app=t.app),S.app??=buildAppForRuntime(hostRuntime$1()),S.dialect!==void 0&&!K_.has(S.app))throw Error(`gjsify build: --dialect ${S.dialect} has no effect on --app ${S.app}. It composes on ${[...K_].join(` and `)} only. Drop the dialect, or build one of those targets.`);if(S.giRenderer===!0&&!iv.includes(S.app))throw Error(`gjsify build: --gi-renderer has no effect on --app ${S.app}. It composes on ${iv.join(` and `)} only — the targets with no GObject introspection to answer \`gi://\` with. \`--app gjs\` resolves it natively and \`--app node\` through @gjsify/node-gi, so neither needs a widget renderer standing in for it.`);if(S.nativescript?.giNamespaces!==void 0&&S.app!==`nativescript`)throw Error(`gjsify build: nativescript.giNamespaces has no effect on --app ${S.app}. It selects what an Android APK carries (ADR 0117); every other target resolves \`gi://\` against a GI stack the host already has.`);for(let t of S.nativescript?.giNamespaces??[])if(!/^[A-Za-z][A-Za-z\d_]*(-\d+(\.\d+)*)?$/.test(t))throw Error(`gjsify build: nativescript.giNamespaces entry "${t}" is not a GI namespace. Write it as \`Gtk\` or \`Gtk-4.0\`.`);if(t.globals!==void 0&&(S.globals=t.globals),S.globals??=`auto`,t.shebang!==void 0&&(S.shebang=t.shebang),t.excludeGlobals){let n=(Array.isArray(t.excludeGlobals)?t.excludeGlobals.join(`,`):String(t.excludeGlobals)).split(`,`).map(t=>t.trim()).filter(Boolean);n.length&&(S.excludeGlobals=[...S.excludeGlobals??[],...n])}merge(S.library??={},N,S.library),merge(S.typescript??={},F,S.typescript);let parseKvPairs=(t,n)=>{let S={};for(let C of t){let t=C.indexOf(`=`);if(t===-1)throw Error(`Invalid --${n} value '${C}'. Expected KEY=VALUE.`);let N=C.slice(0,t).trim(),F=C.slice(t+1);if(!N)throw Error(`Invalid --${n} value '${C}'. Empty key.`);S[N]=F}return S},I=parseKvPairs(t.define??[],`define`),H=parseDeclaredChannel(t.channel??process.env.GJSIFY_CHANNEL??S.ship?.channel,t.channel===void 0?`gjsify.ship.channel`:`--channel`);H!==void 0&&I.__GJSIFY_CHANNEL__===void 0&&(I.__GJSIFY_CHANNEL__=JSON.stringify(H));let W=parseKvPairs(t.alias??[],`alias`);Object.keys(W).length&&(S.aliases={...S.aliases,...W});let q={};if(S.defineFromPackageJson)for(let[t,n]of Object.entries(S.defineFromPackageJson)){if(!n||typeof n.field!=`string`||!n.field)throw Error(`gjsify config: defineFromPackageJson["${t}"] is missing a "field" string`);let S=readDottedPath(N,n.field);q[t]=S===void 0?`undefined`:JSON.stringify(S)}let Y={};if(S.defineFromEnv)for(let[t,n]of Object.entries(S.defineFromEnv)){if(!n||typeof n.env!=`string`||!n.env)throw Error(`gjsify config: defineFromEnv["${t}"] is missing an "env" string`);let S=process.env[n.env],C=S===void 0?n.default:S;Y[t]=C===void 0?`undefined`:JSON.stringify(C)}let X=S.bundler??={},Z=X.output??={},te=X.transform??={};return t.entryPoints?.length&&(X.input=t.entryPoints),X.input||=[`src/index.ts`],t.outfile!==void 0&&(Z.file=t.outfile),t.outdir!==void 0&&(Z.dir=t.outdir),t.format!==void 0&&(Z.format=t.format),t.minify!==void 0&&(Z.minify=t.minify),Z.minify===void 0&&(Z.minify=!0),Z.minify===!0&&(Z.keepNames=!0),t.logLevel&&(X.logLevel={silent:`silent`,error:`warn`,warning:`warn`,warn:`warn`,info:`info`,debug:`debug`,verbose:`debug`}[t.logLevel]??`warn`),t.external?.length&&(X.external=[...Array.isArray(X.external)?X.external:[],...t.external]),(Object.keys(I).length||Object.keys(q).length||Object.keys(Y).length)&&(te.define={...te.define,...q,...Y,...I}),S.verbose&&ge.debug(`configData`,S),S}}}),EI,DI=__esmMin(()=>{TI(),SI(),dM(),EI={command:`build [entryPoints..]`,description:`Build and bundle your Gjs project`,builder:t=>t.option(`entry-points`,{description:`The entry points you want to bundle. Defaults to bundler.input from package.json#gjsify or .gjsifyrc.js, falling back to src/index.ts when neither is set.`,array:!0,type:`string`,defaultDescription:`src/index.ts (fallback)`,coerce:t=>[...new Set(t)]}).option(`exclude`,{description:`An array of glob patterns to exclude entry-points and aliases`,array:!0,type:`string`,default:[]}).option(`verbose`,{description:`Switch on the verbose mode`,type:`boolean`,default:!1}).option(`app`,{description:"Build target for an application. Defaults to the target of the HOST runtime running the CLI: gjs when run under gjs, node when run under node/bun/deno (both consume the --app node bundle). Set `gjsify.app` in package.json#gjsify to override the host default.",type:`string`,choices:[`gjs`,`node`,`browser`,`nativescript`],defaultDescription:`host runtime target (gjs on gjs, else node)`}).option(`format`,{description:`Override the default output format`,type:`string`,choices:[`iife`,`esm`,`cjs`]}).option(`minify`,{description:`Minify the bundled output. Defaults to true; use --no-minify to emit pretty-printed code (e.g. for debugging or readable bundle review).`,type:`boolean`,defaultDescription:`true`}).option(`library`,{description:`Use this if you want to build a library for Gjsify`,type:`boolean`,default:!1}).option(`outfile`,{alias:`o`,description:`Sets the output file name for the build operation. If no outfile is specified, the outfile will be parsed from the package.json. Only used if application mode is active`,type:`string`,normalize:!0}).option(`outdir`,{alias:`d`,description:`Sets the output directory for the build operation. If no outdir is specified, the outdir will be parsed from the package.json. Only used if library mode is active`,type:`string`,normalize:!0}).option(`reflection`,{alias:`r`,description:`Enables TypeScript types on runtime using Deepkit's type compiler`,type:`boolean`,default:!1}).option(`log-level`,{description:`The log level can be changed to prevent esbuild from printing warning and/or error messages to the terminal`,type:`string`,choices:[`silent`,`error`,`warning`,`info`,`debug`,`verbose`],default:`warning`}).option(`channel`,{description:`Distribution channel this build is for (ADR 0113): flathub, web, microsoft-store or apple-app-store. Sets the __GJSIFY_CHANNEL__ define that @gjsify/distribution reads; overrides gjsify.ship.channel. Unset builds report no donation UI.`,type:`string`,choices:[`flathub`,`web`,`microsoft-store`,`apple-app-store`]}).option(`dialect`,{description:`The dialect the SOURCE is written in. 'react-native' aliases 'react-native' onto '@gjsify/react-native' and fails the build on an import whose ADR 0032 support-table status is not supported/partial. GJS and Node app builds. This is NOT gjsify.runtimes['react-native'], which declares the runtime a package RUNS on — the two answer opposite questions.`,type:`string`,choices:[...G_]}).option(`gi-renderer`,{description:"Resolve `gi://Ns?version=X` to the target's widget renderer instead of an empty module (ADR 0034 stage 9): --app browser answers gi://Adw and gi://Gtk out of @gjsify/adwaita-web, --app nativescript out of @gjsify/adwaita-nativescript. A namespace with no renderer, and a ?version= the renderer's vocabulary was not generated against, both FAIL the build by name. Off by default — a gi:// import on those targets is usually a GJS-only code path pulled in transitively.",type:`boolean`}).option(`console-shim`,{description:`Inject a console shim into GJS builds for clean output without the GLib prefix and with working ANSI colors. Use --no-console-shim to disable. Only applies to GJS app builds.`,type:`boolean`,default:!0}).option(`globals`,{description:"Comma-separated list of global identifiers, 'auto' (default) to detect automatically from the bundled output, or 'none' to disable. The 'auto' token may be combined with explicit identifiers/groups (e.g. 'auto,dom') for cases where the detector cannot statically see a global because it's accessed via indirection. Each identifier is mapped to the corresponding `@gjsify/<pkg>/register` module and injected into the bundle. See the CLI Reference docs for the full list of known identifiers. Only applies to GJS app builds.",type:`string`}).option(`shebang`,{description:"Prepend a target-appropriate shebang to the output and mark it executable (chmod 755): `#!/usr/bin/env -S gjs -m` for --app gjs, `#!/usr/bin/env node` for --app node. Applies to GJS and Node app builds with a single --outfile. Default: false (use --shebang to enable, or set `shebang: true` in `.gjsifyrc.js`).",type:`boolean`}).option(`external`,{description:"Module names that should NOT be bundled — EXACT package names only, matched literally on both bundler engines (no globs). Repeat the flag or pass a comma-separated list (e.g. --external typedoc,prettier). Appended to the per-app built-in externals; register subpaths (`<pkg>/register[/…]`) are always force-inlined for --app gjs regardless of this flag.",array:!0,type:`string`,default:[],coerce:t=>t.flatMap(t=>t.split(`,`).map(t=>t.trim()).filter(Boolean))}).option(`define`,{description:`Substitute compile-time constants. Each entry is KEY=VALUE where VALUE is a JS expression (string literals must be quoted: --define VERSION='"1.2.3"'). Repeat the flag or pass comma-separated. See https://esbuild.github.io/api/#define`,array:!0,type:`string`,default:[]}).option(`alias`,{description:`Map module specifiers at bundle time. Each entry is FROM=TO (e.g. --alias typedoc=@gjsify/empty). Layered on top of the built-in alias map. Useful for stubbing heavy deps the test scenario never executes.`,array:!0,type:`string`,default:[],coerce:t=>t.flatMap(t=>t.split(`,`).map(t=>t.trim()).filter(Boolean))}).option(`exclude-globals`,{description:`Comma-separated global identifiers to remove from auto-detection results. Use for false positives from dead browser-compat code whose polyfills require unavailable native libraries (e.g. --exclude-globals fetch,XMLHttpRequest).`,type:`string`}).option(`watch`,{alias:`w`,description:"Watch source files and rebuild on change. Logs each rebuild with duration; clean SIGINT shutdown. Only valid with --app gjs|node|browser (rejected with --library). Requires the npm `rolldown` engine — run under Node, not the GJS-bundled CLI.",type:`boolean`,default:!1}),handler:async t=>{let n=await new Config().forBuild(t);await new xI(n).start({library:t.library,app:n.app,watch:t.watch})}}}),OI,kI=__esmMin(()=>{_e(),xd(),Rd(),Pn(),fI(),OI={command:`clear [paths..]`,description:"Delete build output recursively. Portable replacement for `rm -rf` in package `clear` scripts.",builder:t=>t.positional(`paths`,{description:"Files and directories to delete, relative to the current package. A missing path is not an error. `*` and `?` are honoured in the last segment.",type:`string`,array:!0}).option(`dry-run`,{description:`Print what would be deleted and exit without touching anything.`,type:`boolean`,default:!1}).option(`verbose`,{alias:`v`,description:`Print each path as it is deleted.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.paths??[];if(S.length===0)throw Error(`gjsify clear: no paths given. Usage: gjsify clear <paths…>`);let C=resolveClearTargets(S,{cwd:n,readdir:readdirSync});for(let S of C){let C=Tn(n,S);if(t.dryRun){let t=await stat$1(S).then(()=>!0,()=>!1);ge.log(`gjsify clear: would remove ${C}${t?``:` (absent)`}`);continue}await rm$1(S,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),t.verbose&&ge.log(`gjsify clear: removed ${C}`)}}}});function isDirectoryDestination(t,n){return n.endsWith(`/`)||n.endsWith(`\\`)||t.length>1?!0:t.some(t=>hasWildcard(t))}function assertWritableDestination(t,n,S,C){let N=Tn(S,t);if(N===``){if(C)return;throw Error(`gjsify copy: "${n}" is the working directory itself. Name a file, or add a trailing "/" to copy INTO the directory.`)}if(N===`..`||N.startsWith(`..${jn}`)||Cn(N))throw Error(`gjsify copy: "${n}" resolves to ${t}, outside the working directory ${S}. Only paths inside the package may be written.`)}function expandSource(t,n){let S=Dn(t),C=En(t);if(hasWildcard(C))throw Error(`gjsify copy: a wildcard is only supported in the last path segment — got "${t}".`);if(!hasWildcard(S))return[xn(n.cwd,t)];let N=xn(n.cwd,C),F=segmentToRegExp(S),I;try{I=n.readdir(N)}catch{return[]}return I.filter(t=>F.test(t)).sort().map(t=>wn(N,t))}function planCopy(t,n){if(t.length<2)throw Error(`gjsify copy: needs at least one source and a destination. Usage: gjsify copy <sources…> <dest>`);let S=t.slice(0,-1),C=t[t.length-1];if(C===``)throw Error(`gjsify copy: the destination is empty.`);let N=isDirectoryDestination(S,C),F=xn(n.cwd,C);assertWritableDestination(F,C,n.cwd,N);let I=[];for(let t of S){if(t===``)throw Error(`gjsify copy: a source path is empty.`);I.push(...expandSource(t,n))}if(!N&&I.length!==1)throw Error(`gjsify copy: "${C}" names a single destination, but ${I.length} sources resolved.`);let H=[],W=new Set;for(let t of I){let n=N?wn(F,Dn(t)):F;if(t===n)throw Error(`gjsify copy: "${t}" is its own destination.`);if(W.has(n))throw Error(`gjsify copy: two sources would both be written to ${n}.`);W.add(n),H.push({from:t,to:n})}return H}var AI=__esmMin(()=>{Pn(),fI()}),jI,MI=__esmMin(()=>{_e(),xd(),Rd(),Pn(),AI(),jI={command:`copy [paths..]`,description:"Copy files and directories into the build output. Portable replacement for `mkdir -p` + `cp -r` in package scripts.",builder:t=>t.positional(`paths`,{description:'One or more sources followed by the destination. The destination is a DIRECTORY when it ends with "/", when several sources are given, or when a source carries a wildcard; otherwise it is the exact target path. Missing parent directories are created. `*` and `?` are honoured in the last segment of a source.',type:`string`,array:!0}).option(`dry-run`,{description:`Print what would be copied and exit without touching anything.`,type:`boolean`,default:!1}).option(`verbose`,{alias:`v`,description:`Print each path as it is copied.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.paths??[];if(S.length<2)throw Error(`gjsify copy: needs at least one source and a destination. Usage: gjsify copy <sources…> <dest>`);let C=planCopy(S,{cwd:n,readdir:readdirSync}),show=t=>{let S=Tn(n,t);return S===``?`.`:S};for(let{from:n,to:S}of C){if(t.dryRun){ge.log(`gjsify copy: would copy ${show(n)} -> ${show(S)}`);continue}await mkdir$1(En(S),{recursive:!0}),await cpPromises(n,S,{recursive:!0,force:!0}),t.verbose&&ge.log(`gjsify copy: ${show(n)} -> ${show(S)}`)}}}});function doubleDashArgs(t){let n=t[`--`];if(n==null)return[];if(!Array.isArray(n))throw Error(`gjsify: internal error — yargs' \`--\` slot holds a ${typeof n} rather than an array, so the arguments after \`--\` cannot be forwarded. The command builder must set \`parserConfiguration({ 'populate--': true })\`.`);return n.map((t,n)=>{if(typeof t==`string`)return t;throw Error(`gjsify: internal error — the argument after \`--\` at position ${n} arrived as a ${typeof t} (${String(t)}) instead of a string, so forwarding it would change what the caller wrote. The command builder must set \`parserConfiguration({ 'parse-positional-numbers': false })\` alongside \`populate--\`.`)})}var NI=__esmMin(()=>{});function splitEnvArgv(t){let n=[],S=0;for(;S<t.length;S++){let C=PI.exec(t[S]);if(!C)break;n.push([C[1],C[2]])}return S>=t.length?null:{assignments:n,command:t[S],args:t.slice(S+1)}}function joinEnvArgv(t,n){return n.length===0?[...t]:splitEnvArgv(t)?[...t,`--`,...n]:[...t,...n]}function applyAssignments(t,n,S=process.platform){let C={...t};for(let[t,N]of n){if(S===`win32`)for(let n of Object.keys(C))n!==t&&n.toLowerCase()===t.toLowerCase()&&delete C[n];C[t]=N}return C}var PI,FI,II=__esmMin(()=>{_e(),NI(),V_(),PI=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s,FI={command:`env <entries..>`,description:"Run a command with extra environment variables: `gjsify env NAME=VALUE… <command> [args…]`. Portable replacement for the POSIX `NAME=value command` prefix, which cmd.exe cannot run.",builder:t=>t.positional(`entries`,{description:"`NAME=VALUE` assignments, then the command and its arguments.",type:`string`,array:!0}).version(!1).help(!1).parserConfiguration({"populate--":!0,"parse-positional-numbers":!1,"unknown-options-as-args":!0}),handler:async t=>{let n=splitEnvArgv(joinEnvArgv(t.entries??[],doubleDashArgs(t)));if(!n)return ge.error(`gjsify env: no command given. Usage: gjsify env NAME=VALUE… <command> [args…]`),process.exit(1);let{assignments:S,command:C,args:N}=n,F;try{F=await spawnToCompletion(C,N,{completion:`exit`,env:applyAssignments(process.env,S)})}catch(t){let n=t;return ge.error(n.code===`ENOENT`?`gjsify env: \`${C}\` not found on PATH`:`gjsify env: ${C}: ${n.message}`),process.exit(127)}return F.code===0?process.exit(0):(F.code===null&&ge.error(`gjsify env: ${C} ended by ${describeExit(F)}`),process.exit(F.code??1))}}});function parseShebang(t){let n=LI.exec(t.trim());return n?{variables:n[1]??``,prog:n[2]??``,args:n[3]??``}:null}function replaceDollarWithPercentPair(t){return t.replace(/\$\{?([^$@#?\- \t{}:]+)\}?/g,(t,n)=>`%${n}%`)}function convertToSetCommands(t){let n=``;for(let S of t.split(` `)){let t=S.indexOf(`=`);if(t<=0)continue;let C=S.slice(0,t).trim(),N=S.slice(t+1).trim();C&&N&&(n+=`@SET ${C}=${replaceDollarWithPercentPair(N)}\r\n`)}return n}function buildCmdShim(t,n){let S=t.split(`\\`).join(`/`),C=S.split(`/`).join(`\\`),N=S,F=n?.prog??``,I=n?.args??``,H=n?.variables??``,W=F?F.split(`\\`).join(`/`):``,q=W?`"${W}$exe"`:``,Y=``,X=``,Z=``;F?(Y=`"%dp0%\\${F}.exe"`,X=`"$basedir/${F}"`,Z=`"$basedir/${F}$exe"`,C=`"%dp0%\\${C}"`,S=`"$basedir_win/${S}"`,N=`"$basedir/${N}"`):(F=`"%dp0%\\${C}"`,W=`"$basedir/${S}"`,q=W,I=``,C=``,S=``,N=``);let te;if(Y){let t=I.trim();te=RI+convertToSetCommands(H)+`\r
817
+ `)+"\n\nThe `@gjsify/node-gi/globals` shim seeds them, but it is injected only when the pre-build detection pass finds them — and that pass did not. The two passes therefore disagreed about the module graph. Either the detection ran against a different graph than the one emitted (check that anything feeding `isGjsSourceBuild()` — the `--globals` register stub, `nodeGiGlobalsInject` — is settled BEFORE `detectNodeGiGlobals`), or the offending package should stop reaching for the legacy `imports` object: `gi://<Ns>` and the bare `system`/`gettext`/`cairo` built-ins resolve on both runtimes, `imports` does not.")}var uI=__esmMin(()=>{HF()});function splitWorkspaceSpecifier(t,n){if(t.startsWith(`.`)||t.startsWith(`/`)||t.includes(`:`))return null;let S=t.split(`/`),C=t.startsWith(`@`)?[2]:[1];for(let t of C){let C=S.slice(0,t).join(`/`);if(!n.has(C))continue;let N=S.slice(t).join(`/`);return{name:C,subpath:N?`./${N}`:`.`}}return null}function staticStringValue(t){if(t?.type===`Literal`)return typeof t.value==`string`?t.value:null;if(t?.type===`TemplateLiteral`&&t.expressions?.length===0){let n=t.quasis?.[0]?.value?.cooked;return typeof n==`string`?n:null}return null}function walkModuleAst(t,n){let S;try{S=parse$2(t,{ecmaVersion:`latest`,sourceType:`module`,allowHashBang:!0})}catch{return}let descend=t=>{if(!t||typeof t!=`object`)return;if(Array.isArray(t)){for(let n of t)descend(n);return}let S=t;n(S);for(let[t,n]of Object.entries(S))t===`type`||t===`start`||t===`end`||t===`loc`||descend(n)};descend(S)}function importedSpecifier(t){return t.type!==`ImportDeclaration`&&t.type!==`ExportNamedDeclaration`&&t.type!==`ExportAllDeclaration`&&t.type!==`ImportExpression`?null:staticStringValue(t.source)}function moduleSpecifiers$1(t){let n=[];return walkModuleAst(t,t=>{let S=importedSpecifier(t);S!==null&&n.push(S)}),n}function resolveRelative(t,n){let S=xn(En(t),n);for(let t of[S,`${S}.js`,`${S}.mjs`,wn(S,`index.js`)])try{if(statSync(t).isFile())return t}catch{}return null}function workspaceEntry(t,n){let S=t.manifest,pick=t=>{if(typeof t==`string`)return t;if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t;for(let t of[`node`,`import`,`default`,`gjs`])if(t in n){let S=pick(n[t]);if(S)return S}return null},C=null;if(typeof S.exports==`string`?C=n===`.`?S.exports:null:S.exports&&typeof S.exports==`object`&&(C=pick(S.exports[n])),!C&&n===`.`&&(C=typeof S.module==`string`?S.module:null,C??=typeof S.main==`string`?S.main:null),!C)return null;let N=xn(t.location,C);return existsSync(N)?N:null}function workspacePeers(t,n){return Object.keys(t.peerDependencies??{}).filter(t=>n.has(t))}function cliRuntimeClosure(t,n={}){let S=new Map(t.map(t=>[t.name,t])),C=new Set,N=n.entry,F=n.cliManifest;if(N===void 0||F===void 0){let t=cliPackageDir(),n=null;if(t)try{n=JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{}if(F??=n,N===void 0){let S=n?.bin,C=typeof S==`string`?S:S?.gjsify??n?.main;N=t&&C?xn(t,C):null}}for(let t of workspacePeers(F??{},S))C.add(t);if(!N||!existsSync(N))return C;let I=new Set,H=[N];for(;H.length>0;){let t=H.shift();if(I.has(t))continue;I.add(t);let n;try{n=readFileSync(t,`utf8`)}catch{continue}for(let N of moduleSpecifiers$1(n)){if(N.startsWith(`.`)){let n=resolveRelative(t,N);n&&H.push(n);continue}let n=splitWorkspaceSpecifier(N,S),F=n?S.get(n.name):void 0;if(!n||!F)continue;C.add(n.name);for(let t of workspacePeers(F.manifest,S))C.add(t);let I=workspaceEntry(F,n.subpath);I&&H.push(I)}}return C}var dI=__esmMin(()=>{Bx(),Rd(),Pn(),nh(),__name$1(moduleSpecifiers$1,`moduleSpecifiers`)});function scanGiNamespaces(t){return scanGiRequirements(t).namespaces}function scanGiRequirements(t){let n=new Set,S=new Set,C=new Set,N=new Set,F=[];walkModuleAst(t,t=>{let S=importedSpecifier(t);if(S!==null){let F=parseGiSpecifier(S);F!==null&&n.add(F),t.type===`ImportDeclaration`&&S===fI&&collectNodeGiBindings(t,C,N);return}if(t.type===`VariableDeclarator`&&loadsNodeGiModule(t.init)){let n=t.id;n?.type===`Identifier`&&typeof n.name==`string`&&N.add(n.name);return}t.type===`CallExpression`&&F.push(t)});for(let t of F){let F=optionalMarkerNamespace(t);if(F!==null){S.add(F);continue}let I=requireGiNamespace(t,C,N);I!==null&&n.add(I)}return{namespaces:[...n].sort(),optional:[...S].filter(t=>n.has(t)).sort()}}function optionalMarkerNamespace(t){let n=t.callee;if(n?.type!==`MemberExpression`||n.computed!==!0)return null;let S=n.property;if(S?.type!==`CallExpression`)return null;let C=S.callee,N=C?.type===`MemberExpression`?C.object:void 0,F=C?.type===`MemberExpression`?C.property:void 0;if(N?.type!==`Identifier`||N.name!==`Symbol`||F?.type!==`Identifier`||F.name!==`for`||staticStringValue((S.arguments??[])[0])!==`gjsify.optionalGi`)return null;let I=n.object;if(I?.type!==`Identifier`||I.name!==`globalThis`)return null;let H=t.arguments??[],W=staticStringValue(H[0]);if(W===null||!pI.test(W))return null;let q=staticStringValue(H[1]);return q===null||q===``?W:`${W}-${q}`}function parseGiSpecifier(t){if(!t.startsWith(`gi://`))return null;let[n,S]=t.slice(5).split(`?`,2);if(n===void 0||!pI.test(n))return null;if(S===void 0)return n;let C=/(?:^|&)version=([^&]+)/.exec(S)?.[1];return C===void 0?n:`${n}-${C}`}function collectNodeGiBindings(t,n,S){let C=t.specifiers??[];for(let t of C){let C=t.local;if(C?.type!==`Identifier`||typeof C.name!=`string`)continue;let N=t.imported;t.type===`ImportNamespaceSpecifier`?S.add(C.name):(t.type===`ImportDefaultSpecifier`||N?.type===`Identifier`&&N.name===`requireGi`)&&n.add(C.name)}}function loadsNodeGiModule(t){if(!t||typeof t!=`object`)return!1;let n=t;return n.type===`CallExpression`?staticStringValue((n.arguments??[])[0])===fI:!1}function requireGiNamespace(t,n,S){let C=t.callee,N=!1;if(C?.type===`Identifier`)N=typeof C.name==`string`&&n.has(C.name);else if(C?.type===`MemberExpression`&&C.computed!==!0){let t=C.property;if(t?.type!==`Identifier`||t.name!==`requireGi`)return null;let n=C.object;N=loadsNodeGiModule(n)||n?.type===`Identifier`&&typeof n.name==`string`&&S.has(n.name)}if(!N)return null;let F=t.arguments??[],I=staticStringValue(F[0]);if(I===null||!pI.test(I))return null;let H=staticStringValue(F[1]);return H===null?I:`${I}-${H}`}var fI,pI,mI=__esmMin(()=>{dM(),dI(),fI=`@gjsify/node-gi/gi`,pI=/^[A-Za-z][A-Za-z\d_]*$/});function namespaceOf(t){let n=t.indexOf(`-`);return n===-1?t:t.slice(0,n)}function planGiSelection({declared:t,scanned:n}){let S=new Map;for(let n of t){let t=namespaceOf(n),C=S.get(t);(C===void 0||C===t&&n!==t)&&S.set(t,n)}let C=[...new Set(n.map(namespaceOf).filter(t=>!S.has(t)&&!hI.has(t)))].sort();if(C.length>0)throw Error(`The bundle imports ${C.join(`, `)}, which nativescript.giNamespaces does not declare. An Android APK carries only the typelibs the config selects (ADR 0117), so this would install and then throw at the import. Add ${C.length===1?`it`:`them`} to nativescript.giNamespaces, or stop importing ${C.length===1?`it`:`them`}.`);let N=new Set(n.map(namespaceOf)),F=[...S.entries()].filter(([t])=>!N.has(t)).map(([,t])=>t).sort();return{selected:[...S.values()].sort(),unscanned:F}}var hI,gI=__esmMin(()=>{hI=new Set([`GLib`,`GObject`,`Gio`,`GioUnix`,`GLibUnix`,`GModule`,`GIRepository`])});function hasWildcard(t){return t.includes(`*`)||t.includes(`?`)}function segmentToRegExp(t){let n=t.replace(/[.+^${}()|[\]\\]/g,`\\$&`).replace(/\*/g,`[^/\\\\]*`).replace(/\?/g,`[^/\\\\]`);return RegExp(`^${n}$`)}function assertInsideCwd(t,n,S){let C=Tn(S,t);if(C===``)throw Error(`gjsify clear: refusing to delete the working directory itself ("${n}").`);if(C===`..`||C.startsWith(`..${jn}`)||Cn(C))throw Error(`gjsify clear: "${n}" resolves to ${t}, outside the working directory ${S}. Only paths inside the package may be cleared.`)}function resolveClearTargets(t,n){let S=[],C=new Set;for(let N of t)for(let t of expandTarget(N,n))assertInsideCwd(t,N,n.cwd),!C.has(t)&&(C.add(t),S.push(t));return S}function expandTarget(t,n){let S=Dn(t),C=En(t);if(hasWildcard(C))throw Error(`gjsify clear: a wildcard is only supported in the last path segment — got "${t}".`);if(!hasWildcard(S))return[xn(n.cwd,t)];let N=xn(n.cwd,C);assertInsideCwdOrSelf(N,t,n.cwd);let F=segmentToRegExp(S),I;try{I=n.readdir(N)}catch{return[]}return I.filter(t=>F.test(t)).sort().map(t=>wn(N,t))}function assertInsideCwdOrSelf(t,n,S){Tn(S,t)!==``&&assertInsideCwd(t,n,S)}var _I=__esmMin(()=>{Pn()});function tokenizeSimpleCommand(t,n={}){let S=n.allowGlobs===!0?yI:vI,C=[],N=``,F=!1,I=null;for(let n=0;n<t.length;n++){let H=t[n];if(I===`'`){H===`'`?I=null:N+=H;continue}if(I===`"`){if(H===`"`)I=null;else if(H===`\\`&&(t[n+1]===`"`||t[n+1]===`\\`))N+=t[++n];else if(H===`$`||H==="`")return null;else N+=H;continue}if(H===`'`||H===`"`){I=H,F=!0;continue}if(H===` `||H===` `){F&&=(C.push(N),N=``,!1);continue}if(S.includes(H))return null;N+=H,F=!0}return I?null:(F&&C.push(N),C)}function gjsifyCommandArgv(t,n={}){let S=tokenizeSimpleCommand(t,n);return!S||S.length<2||S[0]!==`gjsify`?null:S.slice(1)}var vI,yI,bI=__esmMin(()=>{vI=`|&;<>\`$()\\
818
+ \r*?{}[]~#!`,yI=vI.replace(`*`,``).replace(`?`,``)});function packageOutputPaths(t){let n=t?.scripts?.clear;if(n===void 0)return[...xI];let S=gjsifyCommandArgv(n,{allowGlobs:!0});return S===null||S[0]!==`clear`?[]:[...S.slice(1).filter(t=>!t.startsWith(`-`)),...xI]}function readPackageManifest(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf-8`))}catch{return null}}function makeOutputMatcher(t){let n=t.map(t=>t.split(/[\\/]+/).filter(t=>t!==``&&t!==`.`).map(t=>hasWildcard(t)?segmentToRegExp(t):t)).filter(t=>t.length>0);return t=>{let S=t.split(`/`);for(let t of n){if(t.length>S.length)continue;let n=!0;for(let C=0;C<t.length;C++){let N=t[C],F=S[C];if(typeof N==`string`?N!==F:!N.test(F)){n=!1;break}}if(n)return!0}return!1}}function walk(t,n,S,C){let N;try{N=readdirSync(t)}catch{return}N.sort();for(let F of N){if(F===`node_modules`||F.startsWith(`.`))continue;let N=n===``?F:`${n}/${F}`;if(S(N))continue;let I=wn(t,F),H;try{H=lstatSync(I)}catch{continue}H.isSymbolicLink()?C.push({rel:N,abs:I,link:readLinkTarget(I)}):H.isDirectory()?walk(I,N,S,C):H.isFile()&&C.push({rel:N,abs:I})}}function readLinkTarget(t){try{return readlinkSync(t)}catch{return``}}function packageBuildInputs(t,n={}){let S=[...packageOutputPaths(n.manifest===void 0?readPackageManifest(t):n.manifest),...n.extraOutputs??[]],C=[];return walk(t,``,makeOutputMatcher(S),C),C}function newestInputMtimeMs(t){let n=0;for(let S of t)try{let{mtimeMs:t}=statSync(S.abs);t>n&&(n=t)}catch{return 1/0}return n}function newestDepSignalMtimeMs(t){let n=0,S=t;for(;;){for(let t of SI){let C=wn(S,t);if(existsSync(C))try{let{mtimeMs:t}=statSync(C);t>n&&(n=t)}catch{}}let t=En(S);if(t===S)return n;S=t}}var xI,SI,CI=__esmMin(()=>{Rd(),Pn(),_I(),bI(),xI=[`lib`,`dist`,`dist-templates`],SI=[`gjsify-lock.json`,`package-lock.json`,`yarn.lock`,`pnpm-lock.yaml`]}),wI=__exportAll$5({BuildAction:()=>EI});function isUnsafeDefaultOutput(t){if(/\.[cm]?tsx?$/i.test(t))return!0;let n=t.replace(/\\/g,`/`);return!!/(?:^|\/)src\//.test(n)}async function buildPnpPlugin(){return pnpPlugin({issuerUrl:import.meta.url})}function shortHash(t){let n=5381;for(let S=0;S<t.length;S++)n=(n<<5)+n+t.charCodeAt(S)>>>0;return n.toString(16).padStart(8,`0`)}function isTruthyEnv(t){return t===`1`||t===`true`||t===`yes`}async function newestLockfileMtime(t){let n=0;for(let S of SI)try{let C=await stat$1(wn(t,S));C.mtimeMs>n&&(n=C.mtimeMs)}catch{}return n}function runningCliFile(){try{return fileURLToPath(import.meta.url)}catch{return null}}async function isBundleFresh(t,n,S,C){try{let N=await stat$1(t),F=await stat$1(n),I=await newestLockfileMtime(S),H=C===void 0?0:(await stat$1(C)).mtimeMs;return N.mtimeMs>=Math.max(F.mtimeMs,I,H)}catch{return!1}}async function runOneLibraryBuild(t){let n=await gjsifyPlugin({input:t.userBundler.input,output:t.output,userAliases:t.userAliases},t.pluginOpts);return await runBundle({...mergeBundlerOptions(n.options,t.userBundler),plugins:[...t.pnpPlugins,...n.prePlugins,...t.userPlugins,...n.plugins]})}var TI,EI,DI=__esmMin(()=>{_e(),MF(),dM(),d_(),NF(),HF(),UF(),Pn(),Gn(),xd(),KF(),qF(),nI(),iI(),oI(),cI(),lI(),uI(),mI(),gI(),CI(),TI=`#!/usr/bin/env -S gjs -m`,EI=class BuildAction{configData;constructor(t={}){this.configData=t}async buildLibrary(){let{verbose:t,library:n,typescript:S,exclude:C,aliases:N}=this.configData,F=n??{},I=normalizeBundlerOptions(this.configData),H=process.cwd(),W=inputSourceDirs(I.input,H),assertDerivedOutdirSafe=t=>{if(t&&isOutdirInsideSource(t,W,H))throw libraryOutputLeakError(t)},q=F.module?En(F.module):void 0,Y=F.main?En(F.main):void 0,X=F.module?On(F.module):`.js`,Z=F.main?On(F.main):`.js`,te=q&&Y&&q!==Y,ne=await buildPnpPlugin(),re=ne?[ne]:[],ie=textLoaderPlugin({loaders:this.configData.loaders}),ae=ie?[ie]:[];if(I.plugins?.length){let n=await resolveUserPlugins(I.plugins,process.cwd(),isGjs()?{loadModule:(n,S)=>this.loadPluginViaGjsBundle(n,S,t)}:{});ae.push(...n)}let oe=[];if(te){assertDerivedOutdirSafe(q),assertDerivedOutdirSafe(Y);let n=q.includes(`/cjs`)||X===`.cjs`?`cjs`:`esm`;oe.push(await runOneLibraryBuild({pluginOpts:{debug:t,library:n,exclude:C,reflection:S?.reflection,jsExtension:X},userBundler:I,output:{dir:q},userAliases:N,pnpPlugins:re,userPlugins:ae}));let F=Y.includes(`/cjs`)||Z===`.cjs`?`cjs`:`esm`;oe.push(await runOneLibraryBuild({pluginOpts:{debug:t,library:F,exclude:C,reflection:S?.reflection,jsExtension:Z},userBundler:I,output:{dir:Y},userAliases:N,pnpPlugins:re,userPlugins:ae}))}else{let n=I.output?.dir,H=I.output?.file??F.module??F.main,W=H?On(H):`.js`,q=n??(H?En(H):void 0);n===void 0&&assertDerivedOutdirSafe(q);let Y=I.output?.format??(q?.includes(`/cjs`)||W===`.cjs`?`cjs`:`esm`);oe.push(await runOneLibraryBuild({pluginOpts:{debug:t,library:Y,exclude:C,reflection:S?.reflection,jsExtension:W},userBundler:I,output:{dir:q},userAliases:N,pnpPlugins:re,userPlugins:ae}))}return oe}parseGlobalsValue(t){if(t===void 0)return{autoMode:!0,extras:``};if(t===`none`||t===``)return{autoMode:!1,extras:``};let n=t.split(`,`).map(t=>t.trim()).filter(Boolean);return{autoMode:n.includes(`auto`),extras:n.filter(t=>t!==`auto`).join(`,`)}}async resolveGlobalsInject(t,n,S){if(t!==`gjs`&&t!==`node`||!n)return;let C=resolveGlobalsList(n);if(C.size===0)return;let N=await writeRegisterInjectFile(C,process.cwd(),{reverseBridgeOverride:t===`node`});return S&&N&&ge.debug(`[gjsify] globals: injected ${C.size} register module(s) from --globals ${n}`),N??void 0}async applyShebang(t,n,S){if(!n){S&&ge.warn(`[gjsify] --shebang skipped: no single outfile (use --outfile for executables)`);return}let C=t===`node`?Fj:TI,N=resolveShebangLine(this.configData.shebang,C)??C,F=await readFile$1(n,`utf-8`);F.startsWith(`#!`)?S&&ge.debug(`[gjsify] --shebang skipped: ${n} already starts with a shebang`):await writeFile$1(n,N+`
819
+ `+F),await chmod$1(n,493),S&&ge.debug(`[gjsify] --shebang: wrote ${N} + chmod 0o755 to ${n}`)}async escapeRawNul(t,n,S){let C=[];if(t)C.push(t);else if(n)try{for(let t of await readdir$1(n))(t.endsWith(`.mjs`)||t.endsWith(`.js`))&&C.push(xn(n,t))}catch(t){if(t?.code===`ENOENT`)return;throw t}for(let t of C){let n;try{n=await readFile$1(t,`utf-8`)}catch(t){if(t?.code===`ENOENT`)continue;throw t}let{code:C,replaced:N}=escapeRawNulForGjs(n);N!==0&&(await writeFile$1(t,C),S&&ge.debug(`[gjsify] escaped ${N} raw NUL byte(s) in ${t} so GJS can load it`))}}assertGjsOutputLoadable(t,n,S,C){assertGjsBundleLoadable((t.output??[]).filter(t=>t.type===`chunk`),n??S??`the GJS bundle`,{isExternal:createGjsExternalsPredicate(C??[]),emitted:(t.output??[]).map(t=>t.fileName)})}assertNodeOutputGlobals(t,n,S){let C=n??S??`the node bundle`;for(let n of t.output??[]){if(n.type!==`chunk`)continue;let t=n.code;typeof t!=`string`||t.length===0||assertNodeBundleGlobalsShimmed(t,n.fileName?`${C} (${n.fileName})`:C)}}assertNativescriptGiSelected(t,n,S){let C=n??S??`the nativescript bundle`,N=new Set;for(let n of t.output??[]){if(n.type!==`chunk`)continue;let t=n.code;if(!(typeof t!=`string`||t.length===0))for(let n of scanGiNamespaces(t))N.add(n)}let F;try{F=planGiSelection({declared:this.configData.nativescript?.giNamespaces??[],scanned:[...N]})}catch(t){throw Error(`gjsify build: ${C}: ${t.message}`)}for(let t of F.unscanned)ge.warn(`[gjsify] --app nativescript: nativescript.giNamespaces declares ${t}, which ${C} does not appear to import. The APK carries it anyway — drop it if nothing needs it, since every selected namespace costs APK size.`)}async applyBrowserHtml(t,n,S){let C=xn(n),N=htmlOutPathFor(C),F=emitBrowserHtml({htmlSource:t.htmlSource,scriptTag:t.scriptTag,scriptSrc:t.scriptSrc,jsOutPath:C,outHtmlPath:N,assets:t.assets});await mkdir$1(En(N),{recursive:!0}),await writeFile$1(N,F);for(let{source:n,target:S}of new Map(t.assets.map(t=>[t.target,t])).values()){let t=xn(En(N),S);await mkdir$1(En(t),{recursive:!0}),await copyFile$1(n,t)}S&&ge.debug(`[gjsify] --app browser: wrote ${N}`)}async loadPluginViaGjsBundle(t,n,S){let C=await this.bundlePluginForGjs(t,n,S);try{return await import(pathToFileURL(C).href)}catch(t){throw Error(`gjsify config: failed to import the GJS bundle for plugin "${n}" (bundled to ${C}). (${t.message})`)}}async bundlePluginForGjs(t,n,S){try{return await BuildAction.bundleFileForGjsCached(t,{cacheSubdir:`plugins`,label:n,verbose:S,noCacheEnv:`GJSIFY_NO_PLUGIN_CACHE`,resolveFromToolchain:!0})}catch(t){throw Error(`gjsify config: failed to bundle plugin "${n}" for GJS (needed because GJS can't import packages that use exports-map subpaths directly). (${t.message})`)}}static async bundleFileForGjsCached(t,n){let S=process.cwd(),C=wn(S,`node_modules`,`.cache`,`gjsify`,n.cacheSubdir),N=n.label.replace(/[^a-zA-Z0-9._-]/g,`_`),F=n.resolveFromToolchain===!0?runningCliFile():null,I=wn(C,`${N}-${shortHash(n.globals===void 0&&n.excludeGlobals===void 0&&F===null?t:`${t} ${JSON.stringify([n.globals??null,n.excludeGlobals??null,F])}`)}`,`${Dn(t).replace(/\.[cm]?[jt]sx?$/i,``)}.mjs`);return!(n.cache===!1||n.noCacheEnv&&isTruthyEnv(process.env[n.noCacheEnv]))&&await isBundleFresh(I,t,S,F??void 0)?(n.verbose&&ge.debug(`[gjsify] reusing cached GJS bundle ${I}`),I):(n.verbose&&ge.debug(`[gjsify] bundling ${t} for GJS → ${I}`),await BuildAction.bundleFileForGjs(t,I,{...n,toolchainAnchor:F}),I)}static async bundleFileForGjs(t,n,S){await mkdir$1(En(n),{recursive:!0}),await new BuildAction({verbose:S.verbose,...S.globals===void 0?{}:{globals:S.globals},...S.excludeGlobals===void 0?{}:{excludeGlobals:S.excludeGlobals},bundler:{input:t,output:{file:n},...S.define?{transform:{define:S.define}}:{},...S.logLevel?{logLevel:S.logLevel}:{}}}).buildApp(`gjs`,{preserveDefaultExport:S.preserveDefaultExport??!0,...S.toolchainAnchor?{toolchainAnchor:S.toolchainAnchor}:{}})}static runningCliFile(){return runningCliFile()}async buildApp(t=`gjs`,n={}){let{verbose:S,typescript:C,exclude:N,library:F,aliases:I,excludeGlobals:H}=this.configData,W=normalizeBundlerOptions(this.configData),q=describeJsxConfig({transformJsx:W.transform?.jsx,tsconfigJsx:C?.compilerOptions?.jsx,tsconfigJsxImportSource:C?.compilerOptions?.jsxImportSource});if(t===`gjs`&&!q.configured){let t=findJsxEntryPoint(collectEntryPaths(await globToEntryPoints(W.input,N)));if(t!==void 0)throw jsxConfigMissingError(t)}let Y=null;if(t===`browser`){let t=detectHtmlEntry(W.input);if(t){let n=await readFile$1(t,`utf-8`),{moduleEntry:S,scriptTag:C,scriptSrc:N}=parseHtmlEntry(t,n);W.input=S,Y={htmlSource:n,scriptTag:C,scriptSrc:N,assets:collectLinkedAssets(t,n)}}}let X=W.output?.format??(W.output?.file?.endsWith(`.cjs`)?`cjs`:`esm`),Z=X===`iife`?`esm`:X,te=W.output?.file,ne=W.output?.dir;if(!te&&!ne&&(F?.main||F?.module)){let t=Z===`cjs`?F.main??F.module:F.module??F.main;if(t&&isUnsafeDefaultOutput(t))throw Error(`gjsify build: refusing to default --outfile to ${t} (would overwrite a TypeScript source file). Pass --outfile/--outdir explicitly, or set "gjsify.bundler.output.file" in package.json.`);te=t}if(Y&&!te)throw Error(`gjsify build: an .html entry needs an explicit --outfile (e.g. --outfile dist-app/app.js); the emitted index.html is written beside it.`);let{consoleShim:re,globals:ie,dialect:ae,giRenderer:oe}=this.configData,Q=Array.isArray(W.external)?W.external:void 0,se=typeof W.output?.banner==`string`?W.output.banner:void 0,ce={debug:S,app:t,format:Z,exclude:N,reflection:C?.reflection,consoleShim:re,...ae===void 0?{}:{dialect:ae},...oe===!0?{giRenderer:!0}:{},...I?{aliases:I}:{},...n.preserveDefaultExport?{preserveDefaultExport:!0}:{},...n.toolchainAnchor===void 0?{}:{toolchainAnchor:n.toolchainAnchor}},{autoMode:le,extras:ue}=this.parseGlobalsValue(ie),de=await buildPnpPlugin(),fe=de?[de]:[],pe=textLoaderPlugin({loaders:this.configData.loaders}),me=pe?[pe]:[];if(W.plugins?.length){let t=await resolveUserPlugins(W.plugins,process.cwd(),isGjs()?{loadModule:(t,n)=>this.loadPluginViaGjsBundle(t,n,S)}:{});me.push(...t)}if(t===`gjs`&&le){let gjsifyPluginFactory=async t=>{let n=await gjsifyPlugin({input:W.input,output:{file:te,dir:ne},userExternal:Q,userBanner:se,userAliases:I,shebang:this.configData.shebang},t);return{options:n.options,plugins:n.plugins}},{injectPath:t}=await detectAutoGlobals({input:W.input,plugins:[...fe,...me],external:W.external,transform:W.transform,format:Z},ce,gjsifyPluginFactory,S,{extraGlobalsList:ue,excludeGlobals:H,cwd:process.cwd(),...n.toolchainAnchor===void 0?{}:{toolchainDir:En(n.toolchainAnchor)}},bundleToChunks);ce.autoGlobalsInject=t}else if(t===`node`&&le){ue&&(ce.autoGlobalsInject=await this.resolveGlobalsInject(t,ue,S));let gjsifyPluginFactory=async t=>{let n=await gjsifyPlugin({input:W.input,output:{file:te,dir:ne},userExternal:Q,userBanner:se,userAliases:I,shebang:this.configData.shebang},t);return{options:n.options,plugins:n.plugins}};await detectNodeGiGlobals({input:W.input,plugins:[...fe,...me],external:W.external,transform:W.transform,format:Z},ce,gjsifyPluginFactory,bundleToChunks)&&(ce.nodeGiGlobalsInject=!0)}else ue&&(ce.autoGlobalsInject=await this.resolveGlobalsInject(t,ue,S));let he=t===`gjs`?giSystemProbes():void 0,ge=await gjsifyPlugin({input:W.input,output:{file:te,dir:ne},userExternal:Q,userBanner:se,userAliases:I,shebang:this.configData.shebang,giSystemProbes:he},ce),_e={...mergeBundlerOptions(ge.options,W),plugins:[...fe,...ge.prePlugins,...me,...ge.plugins]};if(n.watch)return await this.runWatchLoop(_e,t,te,ne,S),[];let ve=await runBundle(_e,{onWatchFiles:n.onWatchFiles});return t===`gjs`&&await this.escapeRawNul(te,ne,S),(t===`gjs`||t===`node`)&&this.configData.shebang&&await this.applyShebang(t,te,S),t===`gjs`&&(this.assertGjsOutputLoadable(ve,te,ne,Q),q.preserves&&assertGjsBundleParses((ve.output??[]).filter(t=>t.type===`chunk`),te??ne??`the GJS bundle`)),t===`node`&&le&&!ce.nodeGiGlobalsInject&&this.assertNodeOutputGlobals(ve,te,ne),t===`nativescript`&&this.assertNativescriptGiSelected(ve,te,ne),t===`browser`&&Y&&te&&await this.applyBrowserHtml(Y,te,S),[ve]}async runWatchLoop(t,n,S,C,N){let F=await runWatch(t),I=new Promise(t=>{F.on(`close`,()=>t())}),H=!1,shutdown=async()=>{if(!H){H=!0,ge.log(`
820
+ [gjsify build --watch] stopping watcher…`);try{await F.close()}catch(t){ge.error(`[gjsify build --watch] watcher close error:`,t)}}};process.on(`SIGINT`,shutdown),process.on(`SIGTERM`,shutdown),F.on(`event`,async t=>{switch(t.code){case`START`:N&&ge.log(`[gjsify build --watch] rebuild start`);break;case`BUNDLE_START`:ge.log(`[gjsify build --watch] building…`);break;case`BUNDLE_END`:ge.log(`[gjsify build --watch] built in ${t.duration}ms`);try{n===`gjs`&&await this.escapeRawNul(S,C,N),(n===`gjs`||n===`node`)&&this.configData.shebang&&await this.applyShebang(n,S,N)}finally{await t.result.close()}break;case`END`:ge.log(`[gjsify build --watch] waiting for changes…`);break;case`ERROR`:ge.error(`[gjsify build --watch] build failed:`,t.error?.message??t.error),N&&t.error?.stack&&ge.error(t.error.stack);try{await t.result.close()}catch{}break}}),N&&F.on(`change`,(t,n)=>{ge.log(`[gjsify build --watch] ${n.event}: ${t}`)}),await I}async start(t={app:`gjs`}){if(t.library){if(t.watch)throw Error(`gjsify build: --watch is not supported with --library (library mode would emit watcher rebuilds for every produced format; use --app gjs|node|browser instead).`);return await this.buildLibrary()}return await this.buildApp(t.app,{watch:t.watch,onWatchFiles:t.onWatchFiles})}}});function isModuleResolutionFailure(t){let n=t instanceof Error?t.message:String(t);return/Unsupported URI scheme|\bnode:|Cannot find (module|package)|Module not found|ERR_MODULE_NOT_FOUND|Failed to resolve/i.test(n)}async function loadConfigViaGjsBundle(t,n){let S;try{let{BuildAction:C}=await Promise.resolve().then(()=>(DI(),wI));S=await C.bundleFileForGjsCached(t,{cacheSubdir:`config`,label:Dn(t),verbose:n,noCacheEnv:`GJSIFY_NO_CONFIG_CACHE`,define:{"import.meta.url":JSON.stringify(pathToFileURL(t).href)},resolveFromToolchain:!0})}catch(n){throw Error(`gjsify: failed to bundle the config ${t} for the GJS CLI. Fixes: run the build under Node (\`npx gjsify …\`), keep the config to plain values / \`process.env\`, or move settings into \`package.json#gjsify\`. (${n.message})`)}try{let t=await import(pathToFileURL(S).href);return t.default??t}catch(n){throw Error(`gjsify: bundled the config ${t} for GJS but could not import the result (${S}). (${n.message})`)}}function defaultSearchPlaces(t){return[`package.json`,`.${t}rc`,`.${t}rc.json`,`.${t}rc.yaml`,`.${t}rc.yml`,`.${t}rc.js`,`.${t}rc.ts`,`.${t}rc.mjs`,`.${t}rc.cjs`,`${t}.config.js`,`${t}.config.ts`,`${t}.config.mjs`,`${t}.config.cjs`]}function merge(t,...n){for(let S of n)if(S)for(let n of Object.keys(S)){let C=t[n],N=S[n];N!==void 0&&(isPlainObject(C)&&isPlainObject(N)?merge(C,N):t[n]=N)}return t}function isPlainObject(t){return typeof t==`object`&&!!t&&!Array.isArray(t)&&Object.getPrototypeOf(t)===Object.prototype}function readDottedPath(t,n){if(!n.includes(`.`))return t[n];let S=t;for(let t of n.split(`.`)){if(typeof S!=`object`||!S)return;S=S[t]}return S}var OI,gjsConfigLoader,kI,Config,AI=__esmMin(()=>{_e(),ih(),ch(),OI=u_(),Pn(),Gn(),d_(),W_(),dM(),_v(),TN(),UP(),gjsConfigLoader=async t=>{try{let n=await import(pathToFileURL(t).href);return n.default??n}catch(n){if(!isModuleResolutionFailure(n))throw n;return loadConfigViaGjsBundle(t,!!process.env.GJSIFY_DEBUG)}},kI=isGjs()?{".js":gjsConfigLoader,".mjs":gjsConfigLoader,".cjs":gjsConfigLoader}:{},Config=class{loadOptions={};constructor(t={}){Object.keys(t).length&&(this.loadOptions=t)}async load(t){let n=await(0,OI.cosmiconfig)(rh,{...this.loadOptions,searchPlaces:(this.loadOptions.searchPlaces??defaultSearchPlaces(`gjsify`)).filter(t=>t!==`package.json`),loaders:{...kI,...this.loadOptions.loaders}}).search(t),S={};try{let n=await this.readPackageJSON(t);isPlainObject(n?.gjsify)&&merge(S,n.gjsify)}catch{}return n?.config&&isPlainObject(n.config)&&merge(S,n.config),S.bundler||={},S.library||={},S.typescript||={},{config:S,filepath:n?.filepath??``,isEmpty:!n&&Object.keys(S).length===3}}async readPackageJSON(t){return t=await resolvePackageJSON(t),await readPackageJSON(t)}async readTSConfig(t){return LP(t)?.config||{}}async forNodeScript(t){let{config:n}=await this.load(En(t));return{globals:n.nodeScript?.globals??n.globals,excludeGlobals:n.nodeScript?.excludeGlobals??n.excludeGlobals}}async forCommand(t=process.cwd()){let{config:n}=await this.load(t);return n}async forBuild(t){let n=await this.load(process.cwd()),S={...n.config},C=n.filepath||process.cwd(),N=await this.readPackageJSON(C),F=await this.readTSConfig(C);if(F.reflection||=t.reflection,S.verbose=t.verbose||t.logLevel===`debug`||t.logLevel===`verbose`,S.exclude=t.exclude||[],t.consoleShim!==void 0&&(S.consoleShim=t.consoleShim),t.giRenderer!==void 0&&(S.giRenderer=t.giRenderer),t.dialect!==void 0){if(!isSourceDialect(t.dialect))throw Error(`gjsify build: "${t.dialect}" is not a source dialect. Known: ${G_.join(`, `)}. This is the dialect the SOURCE is written in — not gjsify.runtimes, which declares the runtime a package RUNS on.`);S.dialect=t.dialect}if(t.app!==void 0&&(S.app=t.app),S.app??=buildAppForRuntime(hostRuntime$1()),S.dialect!==void 0&&!K_.has(S.app))throw Error(`gjsify build: --dialect ${S.dialect} has no effect on --app ${S.app}. It composes on ${[...K_].join(` and `)} only. Drop the dialect, or build one of those targets.`);if(S.giRenderer===!0&&!iv.includes(S.app))throw Error(`gjsify build: --gi-renderer has no effect on --app ${S.app}. It composes on ${iv.join(` and `)} only — the targets with no GObject introspection to answer \`gi://\` with. \`--app gjs\` resolves it natively and \`--app node\` through @gjsify/node-gi, so neither needs a widget renderer standing in for it.`);if(S.nativescript?.giNamespaces!==void 0&&S.app!==`nativescript`)throw Error(`gjsify build: nativescript.giNamespaces has no effect on --app ${S.app}. It selects what an Android APK carries (ADR 0117); every other target resolves \`gi://\` against a GI stack the host already has.`);for(let t of S.nativescript?.giNamespaces??[])if(!/^[A-Za-z][A-Za-z\d_]*(-\d+(\.\d+)*)?$/.test(t))throw Error(`gjsify build: nativescript.giNamespaces entry "${t}" is not a GI namespace. Write it as \`Gtk\` or \`Gtk-4.0\`.`);if(t.globals!==void 0&&(S.globals=t.globals),S.globals??=`auto`,t.shebang!==void 0&&(S.shebang=t.shebang),t.excludeGlobals){let n=(Array.isArray(t.excludeGlobals)?t.excludeGlobals.join(`,`):String(t.excludeGlobals)).split(`,`).map(t=>t.trim()).filter(Boolean);n.length&&(S.excludeGlobals=[...S.excludeGlobals??[],...n])}merge(S.library??={},N,S.library),merge(S.typescript??={},F,S.typescript);let parseKvPairs=(t,n)=>{let S={};for(let C of t){let t=C.indexOf(`=`);if(t===-1)throw Error(`Invalid --${n} value '${C}'. Expected KEY=VALUE.`);let N=C.slice(0,t).trim(),F=C.slice(t+1);if(!N)throw Error(`Invalid --${n} value '${C}'. Empty key.`);S[N]=F}return S},I=parseKvPairs(t.define??[],`define`),H=parseDeclaredChannel(t.channel??process.env.GJSIFY_CHANNEL??S.ship?.channel,t.channel===void 0?`gjsify.ship.channel`:`--channel`);H!==void 0&&I.__GJSIFY_CHANNEL__===void 0&&(I.__GJSIFY_CHANNEL__=JSON.stringify(H));let W=parseKvPairs(t.alias??[],`alias`);Object.keys(W).length&&(S.aliases={...S.aliases,...W});let q={};if(S.defineFromPackageJson)for(let[t,n]of Object.entries(S.defineFromPackageJson)){if(!n||typeof n.field!=`string`||!n.field)throw Error(`gjsify config: defineFromPackageJson["${t}"] is missing a "field" string`);let S=readDottedPath(N,n.field);q[t]=S===void 0?`undefined`:JSON.stringify(S)}let Y={};if(S.defineFromEnv)for(let[t,n]of Object.entries(S.defineFromEnv)){if(!n||typeof n.env!=`string`||!n.env)throw Error(`gjsify config: defineFromEnv["${t}"] is missing an "env" string`);let S=process.env[n.env],C=S===void 0?n.default:S;Y[t]=C===void 0?`undefined`:JSON.stringify(C)}let X=S.bundler??={},Z=X.output??={},te=X.transform??={};return t.entryPoints?.length&&(X.input=t.entryPoints),X.input||=[`src/index.ts`],t.outfile!==void 0&&(Z.file=t.outfile),t.outdir!==void 0&&(Z.dir=t.outdir),t.format!==void 0&&(Z.format=t.format),t.minify!==void 0&&(Z.minify=t.minify),Z.minify===void 0&&(Z.minify=!0),Z.minify===!0&&(Z.keepNames=!0),t.logLevel&&(X.logLevel={silent:`silent`,error:`warn`,warning:`warn`,warn:`warn`,info:`info`,debug:`debug`,verbose:`debug`}[t.logLevel]??`warn`),t.external?.length&&(X.external=[...Array.isArray(X.external)?X.external:[],...t.external]),(Object.keys(I).length||Object.keys(q).length||Object.keys(Y).length)&&(te.define={...te.define,...q,...Y,...I}),S.verbose&&ge.debug(`configData`,S),S}}}),jI,MI=__esmMin(()=>{AI(),DI(),dM(),jI={command:`build [entryPoints..]`,description:`Build and bundle your Gjs project`,builder:t=>t.option(`entry-points`,{description:`The entry points you want to bundle. Defaults to bundler.input from package.json#gjsify or .gjsifyrc.js, falling back to src/index.ts when neither is set.`,array:!0,type:`string`,defaultDescription:`src/index.ts (fallback)`,coerce:t=>[...new Set(t)]}).option(`exclude`,{description:`An array of glob patterns to exclude entry-points and aliases`,array:!0,type:`string`,default:[]}).option(`verbose`,{description:`Switch on the verbose mode`,type:`boolean`,default:!1}).option(`app`,{description:"Build target for an application. Defaults to the target of the HOST runtime running the CLI: gjs when run under gjs, node when run under node/bun/deno (both consume the --app node bundle). Set `gjsify.app` in package.json#gjsify to override the host default.",type:`string`,choices:[`gjs`,`node`,`browser`,`nativescript`],defaultDescription:`host runtime target (gjs on gjs, else node)`}).option(`format`,{description:`Override the default output format`,type:`string`,choices:[`iife`,`esm`,`cjs`]}).option(`minify`,{description:`Minify the bundled output. Defaults to true; use --no-minify to emit pretty-printed code (e.g. for debugging or readable bundle review).`,type:`boolean`,defaultDescription:`true`}).option(`library`,{description:`Use this if you want to build a library for Gjsify`,type:`boolean`,default:!1}).option(`outfile`,{alias:`o`,description:`Sets the output file name for the build operation. If no outfile is specified, the outfile will be parsed from the package.json. Only used if application mode is active`,type:`string`,normalize:!0}).option(`outdir`,{alias:`d`,description:`Sets the output directory for the build operation. If no outdir is specified, the outdir will be parsed from the package.json. Only used if library mode is active`,type:`string`,normalize:!0}).option(`reflection`,{alias:`r`,description:`Enables TypeScript types on runtime using Deepkit's type compiler`,type:`boolean`,default:!1}).option(`log-level`,{description:`The log level can be changed to prevent esbuild from printing warning and/or error messages to the terminal`,type:`string`,choices:[`silent`,`error`,`warning`,`info`,`debug`,`verbose`],default:`warning`}).option(`channel`,{description:`Distribution channel this build is for (ADR 0113): flathub, web, microsoft-store or apple-app-store. Sets the __GJSIFY_CHANNEL__ define that @gjsify/distribution reads; overrides gjsify.ship.channel. Unset builds report no donation UI.`,type:`string`,choices:[`flathub`,`web`,`microsoft-store`,`apple-app-store`]}).option(`dialect`,{description:`The dialect the SOURCE is written in. 'react-native' aliases 'react-native' onto '@gjsify/react-native' and fails the build on an import whose ADR 0032 support-table status is not supported/partial. GJS and Node app builds. This is NOT gjsify.runtimes['react-native'], which declares the runtime a package RUNS on — the two answer opposite questions.`,type:`string`,choices:[...G_]}).option(`gi-renderer`,{description:"Resolve `gi://Ns?version=X` to the target's widget renderer instead of an empty module (ADR 0034 stage 9): --app browser answers gi://Adw and gi://Gtk out of @gjsify/adwaita-web, --app nativescript out of @gjsify/adwaita-nativescript. A namespace with no renderer, and a ?version= the renderer's vocabulary was not generated against, both FAIL the build by name. Off by default — a gi:// import on those targets is usually a GJS-only code path pulled in transitively.",type:`boolean`}).option(`console-shim`,{description:`Inject a console shim into GJS builds for clean output without the GLib prefix and with working ANSI colors. Use --no-console-shim to disable. Only applies to GJS app builds.`,type:`boolean`,default:!0}).option(`globals`,{description:"Comma-separated list of global identifiers, 'auto' (default) to detect automatically from the bundled output, or 'none' to disable. The 'auto' token may be combined with explicit identifiers/groups (e.g. 'auto,dom') for cases where the detector cannot statically see a global because it's accessed via indirection. Each identifier is mapped to the corresponding `@gjsify/<pkg>/register` module and injected into the bundle. See the CLI Reference docs for the full list of known identifiers. Only applies to GJS app builds.",type:`string`}).option(`shebang`,{description:"Prepend a target-appropriate shebang to the output and mark it executable (chmod 755): `#!/usr/bin/env -S gjs -m` for --app gjs, `#!/usr/bin/env node` for --app node. Applies to GJS and Node app builds with a single --outfile. Default: false (use --shebang to enable, or set `shebang: true` in `.gjsifyrc.js`).",type:`boolean`}).option(`external`,{description:"Module names that should NOT be bundled — EXACT package names only, matched literally on both bundler engines (no globs). Repeat the flag or pass a comma-separated list (e.g. --external typedoc,prettier). Appended to the per-app built-in externals; register subpaths (`<pkg>/register[/…]`) are always force-inlined for --app gjs regardless of this flag.",array:!0,type:`string`,default:[],coerce:t=>t.flatMap(t=>t.split(`,`).map(t=>t.trim()).filter(Boolean))}).option(`define`,{description:`Substitute compile-time constants. Each entry is KEY=VALUE where VALUE is a JS expression (string literals must be quoted: --define VERSION='"1.2.3"'). Repeat the flag or pass comma-separated. See https://esbuild.github.io/api/#define`,array:!0,type:`string`,default:[]}).option(`alias`,{description:`Map module specifiers at bundle time. Each entry is FROM=TO (e.g. --alias typedoc=@gjsify/empty). Layered on top of the built-in alias map. Useful for stubbing heavy deps the test scenario never executes.`,array:!0,type:`string`,default:[],coerce:t=>t.flatMap(t=>t.split(`,`).map(t=>t.trim()).filter(Boolean))}).option(`exclude-globals`,{description:`Comma-separated global identifiers to remove from auto-detection results. Use for false positives from dead browser-compat code whose polyfills require unavailable native libraries (e.g. --exclude-globals fetch,XMLHttpRequest).`,type:`string`}).option(`watch`,{alias:`w`,description:"Watch source files and rebuild on change. Logs each rebuild with duration; clean SIGINT shutdown. Only valid with --app gjs|node|browser (rejected with --library). Requires the npm `rolldown` engine — run under Node, not the GJS-bundled CLI.",type:`boolean`,default:!1}),handler:async t=>{let n=await new Config().forBuild(t);await new EI(n).start({library:t.library,app:n.app,watch:t.watch})}}}),NI,PI=__esmMin(()=>{_e(),xd(),Rd(),Pn(),_I(),NI={command:`clear [paths..]`,description:"Delete build output recursively. Portable replacement for `rm -rf` in package `clear` scripts.",builder:t=>t.positional(`paths`,{description:"Files and directories to delete, relative to the current package. A missing path is not an error. `*` and `?` are honoured in the last segment.",type:`string`,array:!0}).option(`dry-run`,{description:`Print what would be deleted and exit without touching anything.`,type:`boolean`,default:!1}).option(`verbose`,{alias:`v`,description:`Print each path as it is deleted.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.paths??[];if(S.length===0)throw Error(`gjsify clear: no paths given. Usage: gjsify clear <paths…>`);let C=resolveClearTargets(S,{cwd:n,readdir:readdirSync});for(let S of C){let C=Tn(n,S);if(t.dryRun){let t=await stat$1(S).then(()=>!0,()=>!1);ge.log(`gjsify clear: would remove ${C}${t?``:` (absent)`}`);continue}await rm$1(S,{recursive:!0,force:!0,maxRetries:3,retryDelay:100}),t.verbose&&ge.log(`gjsify clear: removed ${C}`)}}}});function isDirectoryDestination(t,n){return n.endsWith(`/`)||n.endsWith(`\\`)||t.length>1?!0:t.some(t=>hasWildcard(t))}function assertWritableDestination(t,n,S,C){let N=Tn(S,t);if(N===``){if(C)return;throw Error(`gjsify copy: "${n}" is the working directory itself. Name a file, or add a trailing "/" to copy INTO the directory.`)}if(N===`..`||N.startsWith(`..${jn}`)||Cn(N))throw Error(`gjsify copy: "${n}" resolves to ${t}, outside the working directory ${S}. Only paths inside the package may be written.`)}function expandSource(t,n){let S=Dn(t),C=En(t);if(hasWildcard(C))throw Error(`gjsify copy: a wildcard is only supported in the last path segment — got "${t}".`);if(!hasWildcard(S))return[xn(n.cwd,t)];let N=xn(n.cwd,C),F=segmentToRegExp(S),I;try{I=n.readdir(N)}catch{return[]}return I.filter(t=>F.test(t)).sort().map(t=>wn(N,t))}function planCopy(t,n){if(t.length<2)throw Error(`gjsify copy: needs at least one source and a destination. Usage: gjsify copy <sources…> <dest>`);let S=t.slice(0,-1),C=t[t.length-1];if(C===``)throw Error(`gjsify copy: the destination is empty.`);let N=isDirectoryDestination(S,C),F=xn(n.cwd,C);assertWritableDestination(F,C,n.cwd,N);let I=[];for(let t of S){if(t===``)throw Error(`gjsify copy: a source path is empty.`);I.push(...expandSource(t,n))}if(!N&&I.length!==1)throw Error(`gjsify copy: "${C}" names a single destination, but ${I.length} sources resolved.`);let H=[],W=new Set;for(let t of I){let n=N?wn(F,Dn(t)):F;if(t===n)throw Error(`gjsify copy: "${t}" is its own destination.`);if(W.has(n))throw Error(`gjsify copy: two sources would both be written to ${n}.`);W.add(n),H.push({from:t,to:n})}return H}var FI=__esmMin(()=>{Pn(),_I()}),II,LI=__esmMin(()=>{_e(),xd(),Rd(),Pn(),FI(),II={command:`copy [paths..]`,description:"Copy files and directories into the build output. Portable replacement for `mkdir -p` + `cp -r` in package scripts.",builder:t=>t.positional(`paths`,{description:'One or more sources followed by the destination. The destination is a DIRECTORY when it ends with "/", when several sources are given, or when a source carries a wildcard; otherwise it is the exact target path. Missing parent directories are created. `*` and `?` are honoured in the last segment of a source.',type:`string`,array:!0}).option(`dry-run`,{description:`Print what would be copied and exit without touching anything.`,type:`boolean`,default:!1}).option(`verbose`,{alias:`v`,description:`Print each path as it is copied.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.paths??[];if(S.length<2)throw Error(`gjsify copy: needs at least one source and a destination. Usage: gjsify copy <sources…> <dest>`);let C=planCopy(S,{cwd:n,readdir:readdirSync}),show=t=>{let S=Tn(n,t);return S===``?`.`:S};for(let{from:n,to:S}of C){if(t.dryRun){ge.log(`gjsify copy: would copy ${show(n)} -> ${show(S)}`);continue}await mkdir$1(En(S),{recursive:!0}),await cpPromises(n,S,{recursive:!0,force:!0}),t.verbose&&ge.log(`gjsify copy: ${show(n)} -> ${show(S)}`)}}}});function doubleDashArgs(t){let n=t[`--`];if(n==null)return[];if(!Array.isArray(n))throw Error(`gjsify: internal error — yargs' \`--\` slot holds a ${typeof n} rather than an array, so the arguments after \`--\` cannot be forwarded. The command builder must set \`parserConfiguration({ 'populate--': true })\`.`);return n.map((t,n)=>{if(typeof t==`string`)return t;throw Error(`gjsify: internal error — the argument after \`--\` at position ${n} arrived as a ${typeof t} (${String(t)}) instead of a string, so forwarding it would change what the caller wrote. The command builder must set \`parserConfiguration({ 'parse-positional-numbers': false })\` alongside \`populate--\`.`)})}var RI=__esmMin(()=>{});function splitEnvArgv(t){let n=[],S=0;for(;S<t.length;S++){let C=zI.exec(t[S]);if(!C)break;n.push([C[1],C[2]])}return S>=t.length?null:{assignments:n,command:t[S],args:t.slice(S+1)}}function joinEnvArgv(t,n){return n.length===0?[...t]:splitEnvArgv(t)?[...t,`--`,...n]:[...t,...n]}function applyAssignments(t,n,S=process.platform){let C={...t};for(let[t,N]of n){if(S===`win32`)for(let n of Object.keys(C))n!==t&&n.toLowerCase()===t.toLowerCase()&&delete C[n];C[t]=N}return C}var zI,BI,VI=__esmMin(()=>{_e(),RI(),V_(),zI=/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s,BI={command:`env <entries..>`,description:"Run a command with extra environment variables: `gjsify env NAME=VALUE… <command> [args…]`. Portable replacement for the POSIX `NAME=value command` prefix, which cmd.exe cannot run.",builder:t=>t.positional(`entries`,{description:"`NAME=VALUE` assignments, then the command and its arguments.",type:`string`,array:!0}).version(!1).help(!1).parserConfiguration({"populate--":!0,"parse-positional-numbers":!1,"unknown-options-as-args":!0}),handler:async t=>{let n=splitEnvArgv(joinEnvArgv(t.entries??[],doubleDashArgs(t)));if(!n)return ge.error(`gjsify env: no command given. Usage: gjsify env NAME=VALUE… <command> [args…]`),process.exit(1);let{assignments:S,command:C,args:N}=n,F;try{F=await spawnToCompletion(C,N,{completion:`exit`,env:applyAssignments(process.env,S)})}catch(t){let n=t;return ge.error(n.code===`ENOENT`?`gjsify env: \`${C}\` not found on PATH`:`gjsify env: ${C}: ${n.message}`),process.exit(127)}return F.code===0?process.exit(0):(F.code===null&&ge.error(`gjsify env: ${C} ended by ${describeExit(F)}`),process.exit(F.code??1))}}});function parseShebang(t){let n=HI.exec(t.trim());return n?{variables:n[1]??``,prog:n[2]??``,args:n[3]??``}:null}function replaceDollarWithPercentPair(t){return t.replace(/\$\{?([^$@#?\- \t{}:]+)\}?/g,(t,n)=>`%${n}%`)}function convertToSetCommands(t){let n=``;for(let S of t.split(` `)){let t=S.indexOf(`=`);if(t<=0)continue;let C=S.slice(0,t).trim(),N=S.slice(t+1).trim();C&&N&&(n+=`@SET ${C}=${replaceDollarWithPercentPair(N)}\r\n`)}return n}function buildCmdShim(t,n){let S=t.split(`\\`).join(`/`),C=S.split(`/`).join(`\\`),N=S,F=n?.prog??``,I=n?.args??``,H=n?.variables??``,W=F?F.split(`\\`).join(`/`):``,q=W?`"${W}$exe"`:``,Y=``,X=``,Z=``;F?(Y=`"%dp0%\\${F}.exe"`,X=`"$basedir/${F}"`,Z=`"$basedir/${F}$exe"`,C=`"%dp0%\\${C}"`,S=`"$basedir_win/${S}"`,N=`"$basedir/${N}"`):(F=`"%dp0%\\${C}"`,W=`"$basedir/${S}"`,q=W,I=``,C=``,S=``,N=``);let te;if(Y){let t=I.trim();te=WI+convertToSetCommands(H)+`\r
821
821
  IF EXIST ${Y} (\r\n SET "_prog=${Y.replace(/(^")|("$)/g,``)}"\r\n) ELSE (\r
822
822
  SET "_prog=${F.replace(/(^")|("$)/g,``)}"\r\n)\r
823
823
  \r
824
- endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & set PATHEXT=%PATHEXT:;.JS;=;% & "%_prog%" ${t} ${C} %*\r\n`}else te=`${RI}${F} ${I} ${C} %*\r\n`;let ne=`#!/bin/sh\n${zI}`;X?ne+=`PROG_EXE=${X.replace(/"$/,`.exe"`)}\nif ! [ -x "\$PROG_EXE" ]; then
824
+ endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & set PATHEXT=%PATHEXT:;.JS;=;% & "%_prog%" ${t} ${C} %*\r\n`}else te=`${WI}${F} ${I} ${C} %*\r\n`;let ne=`#!/bin/sh\n${GI}`;X?ne+=`PROG_EXE=${X.replace(/"$/,`.exe"`)}\nif ! [ -x "\$PROG_EXE" ]; then
825
825
  PROG_EXE=${X}\n if ! [ -x "\$PROG_EXE" ]; then
826
826
  PROG_EXE=${W}\n if ! [ -x "\$PROG_EXE" ]; then
827
827
  PROG_EXE=${W}.exe\n fi
828
828
  fi
829
829
  fi
830
830
 
831
- exec ${H}"$PROG_EXE" ${I} ${S} "$@"\n`:ne+=`exec ${W} ${I} ${S} "$@"\n`;let re=BI;return Z?re+=`\$ret=0
831
+ exec ${H}"$PROG_EXE" ${I} ${S} "$@"\n`:ne+=`exec ${W} ${I} ${S} "$@"\n`;let re=KI;return Z?re+=`\$ret=0
832
832
  if (Test-Path ${Z}) {\n # Support pipeline input
833
833
  if (\$MyInvocation.ExpectingInput) {
834
834
  $input | & ${Z} ${I} ${N} $args\n } else {
@@ -847,7 +847,7 @@ if (\$MyInvocation.ExpectingInput) {
847
847
  $input | & ${q} ${N} $args\n} else {
848
848
  & ${q} ${N} $args\n}
849
849
  exit \$LASTEXITCODE
850
- `,{sh:ne,cmd:te,ps1:re}}function buildLauncherShims(t){let{interpreter:n,interpreterArgs:S=[],target:C,prependEnv:N={},fallback:F}=t,I=C.split(`/`).join(`\\`),H=S.length>0?`${S.join(` `)} `:``,W=Object.entries(N),q=F===void 0?``:F.target.split(`/`).join(`\\`),Y=F?.interpreterArgs!==void 0&&F.interpreterArgs.length>0?`${F.interpreterArgs.join(` `)} `:``,X=RI;for(let[t,n]of W)X+=`@SET "${t}=${n};%${t}%"\r\n`;F===void 0?X+=`${n} ${H}"${I}" %*\r\n`:X+=`@where ${n} >NUL 2>NUL\r\n@IF %ERRORLEVEL% EQU 0 (\r\n ${n} ${H}"${I}" %*\r\n) ELSE (\r\n ${F.interpreter} ${Y}"${q}" %*\r\n)\r\n`;let Z=`#!/usr/bin/env pwsh
850
+ `,{sh:ne,cmd:te,ps1:re}}function buildLauncherShims(t){let{interpreter:n,interpreterArgs:S=[],target:C,prependEnv:N={},fallback:F}=t,I=C.split(`/`).join(`\\`),H=S.length>0?`${S.join(` `)} `:``,W=Object.entries(N),q=F===void 0?``:F.target.split(`/`).join(`\\`),Y=F?.interpreterArgs!==void 0&&F.interpreterArgs.length>0?`${F.interpreterArgs.join(` `)} `:``,X=WI;for(let[t,n]of W)X+=`@SET "${t}=${n};%${t}%"\r\n`;F===void 0?X+=`${n} ${H}"${I}" %*\r\n`:X+=`@where ${n} >NUL 2>NUL\r\n@IF %ERRORLEVEL% EQU 0 (\r\n ${n} ${H}"${I}" %*\r\n) ELSE (\r\n ${F.interpreter} ${Y}"${q}" %*\r\n)\r\n`;let Z=`#!/usr/bin/env pwsh
851
851
  `;for(let[t,n]of W)Z+=`$env:${t} = "${n};" + $env:${t}\n`;let te=S.map(t=>`"${t}" `).join(``);if(F===void 0)Z+=`# Support pipeline input
852
852
  if (\$MyInvocation.ExpectingInput) {
853
853
  $input | & "${n}" ${te}"${I}" $args\n} else {
@@ -860,7 +860,7 @@ if (\$MyInvocation.ExpectingInput) {
860
860
  & \$exe @exeArgs \$script \$args
861
861
  }
862
862
  `}return Z+=`exit $LASTEXITCODE
863
- `,{cmd:X,ps1:Z}}function shQuote(t){return`'${t.replace(/'/g,`'\\''`)}'`}function buildNativeEnvPreamble(t,n=[],S={}){let C=S.platform??process.platform,N=S.arch??process.arch,F=S.libc===void 0?detectHostLibc(C):S.libc,{name:I,separator:H}=libraryPathVar(C);if(C===`win32`){if(n.length===0)return``;let t=shQuote(n.join(H));return`GI_TYPELIB_PATH=${t}\${GI_TYPELIB_PATH:+"${H}$GI_TYPELIB_PATH"}\n${I}=${t}\${${I}:+"${H}$${I}"}\nexport GI_TYPELIB_PATH ${I}\n`}let W=`${t.replace(/\/+$/,``)}/node_modules/`,q=n.filter(t=>!t.startsWith(W)),Y=prebuildDirCandidates(C,N,void 0,F),X=[];for(let n of Y)X.push(`${shQuote(t)}/node_modules/@*/*/prebuilds/${n}`),X.push(`${shQuote(t)}/node_modules/*/prebuilds/${n}`);return`gjsify_np=${q.length>0?shQuote(q.join(H)):`''`}\nfor gjsify_d in ${X.join(` `)}; do\n [ -d "$gjsify_d" ] || continue\n for gjsify_t in "$gjsify_d"/*.typelib; do\n if [ -f "$gjsify_t" ]; then gjsify_np="\${gjsify_np:+$gjsify_np${H}}$gjsify_d"; break; fi\n done\ndone\nif [ -n "$gjsify_np" ]; then\n GI_TYPELIB_PATH="$gjsify_np\${GI_TYPELIB_PATH:+${H}$GI_TYPELIB_PATH}"\n ${I}="$gjsify_np\${${I}:+${H}$${I}}"\n export GI_TYPELIB_PATH ${I}\nfi\nunset gjsify_np gjsify_d gjsify_t\n`+dyldFallbackPreamble(C)}function dyldFallbackPreamble(t){return t===`darwin`?`DYLD_FALLBACK_LIBRARY_PATH="\${DYLD_FALLBACK_LIBRARY_PATH:+$DYLD_FALLBACK_LIBRARY_PATH:}${dyldDefaultFallbackDirs({HOME:`$HOME`}).join(`:`)}"\nexport DYLD_FALLBACK_LIBRARY_PATH\n`:``}function shQuoteArg(t){return shQuote(t)}function normalizeBinMap(t,n){let S=new Map;if(typeof n==`string`){let C=t.startsWith(`@`)?t.slice(t.indexOf(`/`)+1):t;return S.set(C,n),S}for(let[t,C]of Object.entries(n))S.set(t,C);return S}function pickBinMap(t,n){let S=n.gjsify?.bin,C=n.bin;return S===void 0?C===void 0?null:{map:normalizeBinMap(t,C),isGjsBin:!1,nodeFallback:null}:{map:normalizeBinMap(t,S),isGjsBin:!0,nodeFallback:C===void 0?null:normalizeBinMap(t,C)}}function buildShLauncher(t,n){let S=n.isGjsBundle?n.envPreamble??``:``,C=n.gjs===void 0||n.gjs===`gjs`?`gjs`:shQuote(n.gjs);return n.isGjsBundle&&n.nodeFallbackAbs!==void 0?`#!/bin/sh\nif command -v ${C} >/dev/null 2>&1; then\n${S}exec ${C} -m ${shQuote(t)} "$@"\nfi\nexec node ${shQuote(n.nodeFallbackAbs)} "$@"\n`:`#!/bin/sh\n${S}${n.isGjsBundle?`exec ${C} -m ${shQuote(t)} "$@"`:`exec ${shQuote(t)} "$@"`}\n`}function isGjsBundlePath(t){return t.endsWith(`.gjs.mjs`)||t.endsWith(`.mjs`)}var LI,RI,zI,BI,VI=__esmMin(()=>{CF(),lF(),LI=/^#!\s*(?:\/usr\/bin\/env\s+(?:-S\s+)?((?:[^ \t=]+=[^ \t=]+\s+)*))?([^ \t]+)(.*)$/,RI=`@ECHO off\r
863
+ `,{cmd:X,ps1:Z}}function shQuote(t){return`'${t.replace(/'/g,`'\\''`)}'`}function buildNativeEnvPreamble(t,n=[],S={}){let C=S.platform??process.platform,N=S.arch??process.arch,F=S.libc===void 0?detectHostLibc(C):S.libc,{name:I,separator:H}=libraryPathVar(C);if(C===`win32`){if(n.length===0)return``;let t=shQuote(n.join(H));return`GI_TYPELIB_PATH=${t}\${GI_TYPELIB_PATH:+"${H}$GI_TYPELIB_PATH"}\n${I}=${t}\${${I}:+"${H}$${I}"}\nexport GI_TYPELIB_PATH ${I}\n`}let W=`${t.replace(/\/+$/,``)}/node_modules/`,q=n.filter(t=>!t.startsWith(W)),Y=prebuildDirCandidates(C,N,void 0,F),X=[];for(let n of Y)X.push(`${shQuote(t)}/node_modules/@*/*/prebuilds/${n}`),X.push(`${shQuote(t)}/node_modules/*/prebuilds/${n}`);return`gjsify_np=${q.length>0?shQuote(q.join(H)):`''`}\nfor gjsify_d in ${X.join(` `)}; do\n [ -d "$gjsify_d" ] || continue\n for gjsify_t in "$gjsify_d"/*.typelib; do\n if [ -f "$gjsify_t" ]; then gjsify_np="\${gjsify_np:+$gjsify_np${H}}$gjsify_d"; break; fi\n done\ndone\nif [ -n "$gjsify_np" ]; then\n GI_TYPELIB_PATH="$gjsify_np\${GI_TYPELIB_PATH:+${H}$GI_TYPELIB_PATH}"\n ${I}="$gjsify_np\${${I}:+${H}$${I}}"\n export GI_TYPELIB_PATH ${I}\nfi\nunset gjsify_np gjsify_d gjsify_t\n`+dyldFallbackPreamble(C)}function dyldFallbackPreamble(t){return t===`darwin`?`DYLD_FALLBACK_LIBRARY_PATH="\${DYLD_FALLBACK_LIBRARY_PATH:+$DYLD_FALLBACK_LIBRARY_PATH:}${dyldDefaultFallbackDirs({HOME:`$HOME`}).join(`:`)}"\nexport DYLD_FALLBACK_LIBRARY_PATH\n`:``}function shQuoteArg(t){return shQuote(t)}function normalizeBinMap(t,n){let S=new Map;if(typeof n==`string`){let C=t.startsWith(`@`)?t.slice(t.indexOf(`/`)+1):t;return S.set(C,n),S}for(let[t,C]of Object.entries(n))S.set(t,C);return S}function pickBinMap(t,n){let S=n.gjsify?.bin,C=n.bin;return S===void 0?C===void 0?null:{map:normalizeBinMap(t,C),isGjsBin:!1,nodeFallback:null}:{map:normalizeBinMap(t,S),isGjsBin:!0,nodeFallback:C===void 0?null:normalizeBinMap(t,C)}}function buildShLauncher(t,n){let S=n.isGjsBundle?n.envPreamble??``:``,C=n.gjs===void 0||n.gjs===`gjs`?`gjs`:shQuote(n.gjs);return n.isGjsBundle&&n.nodeFallbackAbs!==void 0?`#!/bin/sh\nif command -v ${C} >/dev/null 2>&1; then\n${S}exec ${C} -m ${shQuote(t)} "$@"\nfi\nexec node ${shQuote(n.nodeFallbackAbs)} "$@"\n`:`#!/bin/sh\n${S}${n.isGjsBundle?`exec ${C} -m ${shQuote(t)} "$@"`:`exec ${shQuote(t)} "$@"`}\n`}function isGjsBundlePath(t){return t.endsWith(`.gjs.mjs`)||t.endsWith(`.mjs`)}var HI,WI,GI,KI,qI=__esmMin(()=>{CF(),lF(),HI=/^#!\s*(?:\/usr\/bin\/env\s+(?:-S\s+)?((?:[^ \t=]+=[^ \t=]+\s+)*))?([^ \t]+)(.*)$/,WI=`@ECHO off\r
864
864
  GOTO start\r
865
865
  :find_dp0\r
866
866
  SET dp0=%~dp0\r
@@ -868,7 +868,7 @@ EXIT /b\r
868
868
  :start\r
869
869
  SETLOCAL\r
870
870
  CALL :find_dp0\r
871
- `,zI=`basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
871
+ `,GI=`basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
872
872
  basedir_win="$basedir"
873
873
 
874
874
  case \`uname -a\` in
@@ -888,7 +888,7 @@ case \`uname -a\` in
888
888
  ;;
889
889
  esac
890
890
 
891
- `,BI=`#!/usr/bin/env pwsh
891
+ `,KI=`#!/usr/bin/env pwsh
892
892
  $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
893
893
 
894
894
  $exe=""
@@ -897,37 +897,37 @@ if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
897
897
  # are installed in the same directory
898
898
  $exe=".exe"
899
899
  }
900
- `});function splitExecArgv(t,n=[]){let S={runtime:null,rebuild:!1,verbose:!1},setRuntime=t=>{if(t===void 0||!HI.includes(t))throw new ExecPlanError(`gjsify exec: --runtime expects one of ${HI.join(`, `)}, got ${t===void 0?`nothing`:`"${t}"`}.`);S.runtime=t},C=0;for(;C<t.length;C++){let n=t[C];if(!n.startsWith(`-`))break;if(n===`--rebuild`)S.rebuild=!0;else if(n===`--verbose`)S.verbose=!0;else if(n===`--runtime`)setRuntime(t[++C]);else if(n.startsWith(`--runtime=`))setRuntime(n.slice(10));else throw new ExecPlanError(`gjsify exec: unknown option "${n}" before the bin name. Options for the bin go AFTER it (\`gjsify exec <bin> --flag\`); gjsify exec itself takes --runtime <gjs|node|bun|deno>, --rebuild, --verbose.`)}if(C<t.length)return{...S,bin:t[C],args:[...t.slice(C+1),...n.length?[`--`,...n]:[]]};if(n.length>0)return{...S,bin:n[0],args:n.slice(1)};throw new ExecPlanError(`gjsify exec: no bin given. Usage: gjsify exec [--runtime <r>] [--rebuild] <bin> [args…]`)}function readManifest$1(t){return readPackageJson$2(wn(t,`package.json`))}function realOrNull(t){try{return realpathSync(t)}catch{return null}}function isInsideNodeModules(t){return t.split(jn).includes(`node_modules`)}function binFromPackage(t,n,S){let C=readManifest$1(t);if(!C?.name)return null;let N=C.bin===void 0?void 0:normalizeBinMap(C.name,C.bin).get(n),F=C.gjsify?.bin===void 0?void 0:normalizeBinMap(C.name,C.gjsify.bin).get(n);if(N===void 0&&F===void 0)return null;let I=realOrNull(t)??xn(t),H=N===void 0?null:realOrNull(wn(t,N)),W=F===void 0?null:realOrNull(wn(t,F));return H===null&&W===null?null:{binName:n,pkgName:C.name,pkgVersion:C.version??`0.0.0`,pkgDir:I,entry:H,gjsEntry:W,nodeModules:S,installed:isInsideNodeModules(I)}}function listPackages(t){let n=[],S;try{S=readdirSync(t)}catch{return n}for(let C of S)if(!C.startsWith(`.`))if(C.startsWith(`@`)){let S;try{S=readdirSync(wn(t,C))}catch{continue}for(let N of S)n.push(wn(t,C,N))}else n.push(wn(t,C));return n}function ownerOfLinkedBin(t,n,S){let C=En(t);for(;;){if(existsSync(wn(C,`package.json`))){let N=binFromPackage(C,n,S);if(N&&(N.entry===t||N.gjsEntry===t))return N}let N=En(C);if(N===C)return null;C=N}}function resolveExecBin(t,n){let S=[],C=xn(n);for(;;){if(existsSync(wn(C,`package.json`))){let n=binFromPackage(C,t,null);if(n)return n;break}let n=En(C);if(n===C)break;C=n}for(C=xn(n);;){let n=wn(C,`node_modules`);if(existsSync(n)){S.push(n);let C=wn(n,`.bin`);if([t,`${t}.cmd`].some(t=>existsSync(wn(C,t)))){let S=wn(C,t),N=(()=>{try{return lstatSync(S).isSymbolicLink()}catch{return!1}})()?realOrNull(S):null,F=N?ownerOfLinkedBin(N,t,n):null;if(F)return F;let I=listPackages(n).sort((n,S)=>Number(Dn(S)===t)-Number(Dn(n)===t));for(let S of I){let C=binFromPackage(S,t,n);if(C)return C}}}let N=En(C);if(N===C)break;C=N}throw new ExecBinNotFoundError(t,S)}function planExec(t,n){if(n===`gjs`){if(t.gjsEntry)return{kind:`gjs-bundle`,file:t.gjsEntry};if(t.entry)return{kind:`rebuild`,entry:t.entry}}else if(t.entry)return{kind:`direct`,runtime:n,file:t.entry};else throw new ExecPlanError(`gjsify exec: "${t.binName}" from ${t.pkgName} is declared only as a GJS bundle (\`gjsify.bin\`), which ${n} cannot run. Run it on GJS: \`gjsify exec --runtime gjs ${t.binName}\`.`);throw new ExecPlanError(`gjsify exec: "${t.binName}" from ${t.pkgName} names no file that exists.`)}function execCacheKey(t){let n=JSON.stringify([`gjsify-exec/v1`,t.pkgName,t.pkgVersion,t.entry.split(jn).join(`/`),t.cliVersion,t.lockfileHash]);return createHash(`sha256`).update(n).digest(`hex`)}function findProjectLockfile(t){let n=xn(t);for(;;){for(let t of WI){let S=wn(n,t);if(existsSync(S))return S}let t=En(n);if(t===n)return null;n=t}}function hashFile(t){return createHash(`sha256`).update(readFileSync(t)).digest(`hex`)}function execCacheRoot(t){return wn(t,`.cache`,`gjsify`,`exec`)}function execArtifactPath(t,n,S,C){return wn(t,`${`${n.pkgName}@${n.pkgVersion}`.replace(/[^a-zA-Z0-9._@-]/g,`_`)}-${C.slice(0,16)}`,artifactFileName(S))}function artifactFileName(t){return Dn(t).replace(/\.cjs$/i,`.mjs`)}function entryWithinPackage(t,n){return Tn(t.pkgDir,n)}var HI,ExecBinNotFoundError,ExecPlanError,WI,GI=__esmMin(()=>{Qc(),Rd(),Pn(),VI(),vI(),$P(),HI=[`gjs`,`node`,`bun`,`deno`],ExecBinNotFoundError=class extends Error{binName;searched;constructor(t,n){super(`gjsify exec: no bin named "${t}" in this project.\nLooked in the nearest package.json and in:\n${n.map(t=>` ${t}`).join(`
901
- `)||` (no node_modules found)`}\nInstall the package that provides it (\`gjsify install <pkg>\`), or use \`gjsify dlx\` for a one-off run.`),this.binName=t,this.searched=n,this.name=`ExecBinNotFoundError`}},ExecPlanError=class extends Error{constructor(t){super(t),this.name=`ExecPlanError`}},__name$1(readManifest$1,`readManifest`),WI=[..._I,`bun.lock`,`bun.lockb`]});function hangGraceMs(t){let n=t.GJSIFY_HANG_GRACE_MS;if(n===void 0||n.trim()===``)return KI;let S=Number(n);return Number.isFinite(S)&&S>=0?S:KI}function heartbeatEnv(t,n){let S={...t};return n?S.GJSIFY_UNIT_HEARTBEAT=n:delete S.GJSIFY_UNIT_HEARTBEAT,S}function parseHeartbeat(t){if(!t)return null;let n=t.split(`
900
+ `});function splitExecArgv(t,n=[]){let S={runtime:null,rebuild:!1,verbose:!1},setRuntime=t=>{if(t===void 0||!JI.includes(t))throw new ExecPlanError(`gjsify exec: --runtime expects one of ${JI.join(`, `)}, got ${t===void 0?`nothing`:`"${t}"`}.`);S.runtime=t},C=0;for(;C<t.length;C++){let n=t[C];if(!n.startsWith(`-`))break;if(n===`--rebuild`)S.rebuild=!0;else if(n===`--verbose`)S.verbose=!0;else if(n===`--runtime`)setRuntime(t[++C]);else if(n.startsWith(`--runtime=`))setRuntime(n.slice(10));else throw new ExecPlanError(`gjsify exec: unknown option "${n}" before the bin name. Options for the bin go AFTER it (\`gjsify exec <bin> --flag\`); gjsify exec itself takes --runtime <gjs|node|bun|deno>, --rebuild, --verbose.`)}if(C<t.length)return{...S,bin:t[C],args:[...t.slice(C+1),...n.length?[`--`,...n]:[]]};if(n.length>0)return{...S,bin:n[0],args:n.slice(1)};throw new ExecPlanError(`gjsify exec: no bin given. Usage: gjsify exec [--runtime <r>] [--rebuild] <bin> [args…]`)}function readManifest$1(t){return readPackageJson$2(wn(t,`package.json`))}function realOrNull(t){try{return realpathSync(t)}catch{return null}}function isInsideNodeModules(t){return t.split(jn).includes(`node_modules`)}function binFromPackage(t,n,S){let C=readManifest$1(t);if(!C?.name)return null;let N=C.bin===void 0?void 0:normalizeBinMap(C.name,C.bin).get(n),F=C.gjsify?.bin===void 0?void 0:normalizeBinMap(C.name,C.gjsify.bin).get(n);if(N===void 0&&F===void 0)return null;let I=realOrNull(t)??xn(t),H=N===void 0?null:realOrNull(wn(t,N)),W=F===void 0?null:realOrNull(wn(t,F));return H===null&&W===null?null:{binName:n,pkgName:C.name,pkgVersion:C.version??`0.0.0`,pkgDir:I,entry:H,gjsEntry:W,nodeModules:S,installed:isInsideNodeModules(I)}}function listPackages(t){let n=[],S;try{S=readdirSync(t)}catch{return n}for(let C of S)if(!C.startsWith(`.`))if(C.startsWith(`@`)){let S;try{S=readdirSync(wn(t,C))}catch{continue}for(let N of S)n.push(wn(t,C,N))}else n.push(wn(t,C));return n}function ownerOfLinkedBin(t,n,S){let C=En(t);for(;;){if(existsSync(wn(C,`package.json`))){let N=binFromPackage(C,n,S);if(N&&(N.entry===t||N.gjsEntry===t))return N}let N=En(C);if(N===C)return null;C=N}}function resolveExecBin(t,n){let S=[],C=xn(n);for(;;){if(existsSync(wn(C,`package.json`))){let n=binFromPackage(C,t,null);if(n)return n;break}let n=En(C);if(n===C)break;C=n}for(C=xn(n);;){let n=wn(C,`node_modules`);if(existsSync(n)){S.push(n);let C=wn(n,`.bin`);if([t,`${t}.cmd`].some(t=>existsSync(wn(C,t)))){let S=wn(C,t),N=(()=>{try{return lstatSync(S).isSymbolicLink()}catch{return!1}})()?realOrNull(S):null,F=N?ownerOfLinkedBin(N,t,n):null;if(F)return F;let I=listPackages(n).sort((n,S)=>Number(Dn(S)===t)-Number(Dn(n)===t));for(let S of I){let C=binFromPackage(S,t,n);if(C)return C}}}let N=En(C);if(N===C)break;C=N}throw new ExecBinNotFoundError(t,S)}function planExec(t,n){if(n===`gjs`){if(t.gjsEntry)return{kind:`gjs-bundle`,file:t.gjsEntry};if(t.entry)return{kind:`rebuild`,entry:t.entry}}else if(t.entry)return{kind:`direct`,runtime:n,file:t.entry};else throw new ExecPlanError(`gjsify exec: "${t.binName}" from ${t.pkgName} is declared only as a GJS bundle (\`gjsify.bin\`), which ${n} cannot run. Run it on GJS: \`gjsify exec --runtime gjs ${t.binName}\`.`);throw new ExecPlanError(`gjsify exec: "${t.binName}" from ${t.pkgName} names no file that exists.`)}function execCacheKey(t){let n=JSON.stringify([`gjsify-exec/v1`,t.pkgName,t.pkgVersion,t.entry.split(jn).join(`/`),t.cliVersion,t.lockfileHash]);return createHash(`sha256`).update(n).digest(`hex`)}function findProjectLockfile(t){let n=xn(t);for(;;){for(let t of YI){let S=wn(n,t);if(existsSync(S))return S}let t=En(n);if(t===n)return null;n=t}}function hashFile(t){return createHash(`sha256`).update(readFileSync(t)).digest(`hex`)}function execCacheRoot(t){return wn(t,`.cache`,`gjsify`,`exec`)}function execArtifactPath(t,n,S,C){return wn(t,`${`${n.pkgName}@${n.pkgVersion}`.replace(/[^a-zA-Z0-9._@-]/g,`_`)}-${C.slice(0,16)}`,artifactFileName(S))}function artifactFileName(t){return Dn(t).replace(/\.cjs$/i,`.mjs`)}function entryWithinPackage(t,n){return Tn(t.pkgDir,n)}var JI,ExecBinNotFoundError,ExecPlanError,YI,XI=__esmMin(()=>{Qc(),Rd(),Pn(),qI(),CI(),$P(),JI=[`gjs`,`node`,`bun`,`deno`],ExecBinNotFoundError=class extends Error{binName;searched;constructor(t,n){super(`gjsify exec: no bin named "${t}" in this project.\nLooked in the nearest package.json and in:\n${n.map(t=>` ${t}`).join(`
901
+ `)||` (no node_modules found)`}\nInstall the package that provides it (\`gjsify install <pkg>\`), or use \`gjsify dlx\` for a one-off run.`),this.binName=t,this.searched=n,this.name=`ExecBinNotFoundError`}},ExecPlanError=class extends Error{constructor(t){super(t),this.name=`ExecPlanError`}},__name$1(readManifest$1,`readManifest`),YI=[...SI,`bun.lock`,`bun.lockb`]});function hangGraceMs(t){let n=t.GJSIFY_HANG_GRACE_MS;if(n===void 0||n.trim()===``)return ZI;let S=Number(n);return Number.isFinite(S)&&S>=0?S:ZI}function heartbeatEnv(t,n){let S={...t};return n?S.GJSIFY_UNIT_HEARTBEAT=n:delete S.GJSIFY_UNIT_HEARTBEAT,S}function parseHeartbeat(t){if(!t)return null;let n=t.split(`
902
902
  `,1)[0]??``,S=n.indexOf(` `);if(S<0)return null;let C=Number(n.slice(0,S));if(!Number.isFinite(C)||C<0)return null;let N=n.slice(S+1).trim();return N.length===0?null:{deadlineMs:C,label:N}}function formatHangReport(t){let n=[`⏱ hang: "${t.label}" is ${Math.round(t.overdueMs/1e3)}s past its own deadline`,` gjs pid ${t.pid} stopped turning its main loop, so @gjsify/unit's timeout cannot fire`,` (see packages/gjs/unit/src/heartbeat.ts). Killing it rather than holding the job open.`];if(t.backtrace){n.push(` native backtrace at the moment of the hang:`);for(let S of t.backtrace.split(`
903
903
  `))n.push(` ${S}`)}else n.push(` no native backtrace: eu-stack (elfutils) absent, refused the attach, or found nothing`);return t.graceMs!==void 0&&(n.push(` a test that legitimately blocks the loop this long: raise GJSIFY_HANG_GRACE_MS`),n.push(` (now ${t.graceMs} ms, 0 disables this guard).`)),n.join(`
904
904
  `)}function captureNativeBacktrace(t,n=40){try{let S=spawnSync(`eu-stack`,[`-p`,String(t)],{encoding:`utf8`,timeout:5e3,maxBuffer:4*1024*1024}),C=typeof S.stdout==`string`?S.stdout.trim():``;return C.length===0?void 0:C.split(`
905
905
  `).slice(0,n).join(`
906
- `)}catch{return}}function createHangWatchdog(t){let n=t.now??Date.now,S=t.graceMs??3e4,C,N=!1,tick=()=>{if(N)return;let C=parseHeartbeat(t.read());!C||C.deadlineMs<=0||n()-(C.deadlineMs+S)<0||(N=!0,stop(),t.onHang(C,n()-C.deadlineMs))},stop=()=>{C!==void 0&&clearInterval(C),C=void 0};return{tick,start:(t=qI)=>{C===void 0&&(C=setInterval(tick,t))},stop}}var KI,qI,JI=__esmMin(()=>{P_(),KI=3e4,qI=1e3}),YI=__exportAll$5({computeNativeEnvForBundle:()=>computeNativeEnvForBundle,runGjsBundle:()=>runGjsBundle});function computeNativeEnvForBundle(t,n=process.cwd(),S=process.env,C=[]){let N=xn(t),F=[],I=new Set;for(let t of[n,En(N),...C])for(let n of detectNativePackages(t))I.has(n.name)||(I.add(n.name),F.push(n));let H=buildNativeEnv(F,{env:S});return{env:H,envPrefix:Object.entries(H).filter(([t,n])=>n!==void 0&&n!==``&&n!==S[t]).map(([t,n])=>`${t}=${n}`).join(` `)}}function safeMkdtemp(){try{return mkdtempSync(wn(tmpdir(),`gjsify-hb-`))}catch{return}}async function runGjsBundle(t,n=[],S){let{env:C,envPrefix:N}=computeNativeEnvForBundle(t,process.cwd(),process.env,S.nativeRoots),F=hangGraceMs(process.env),I=F>0?safeMkdtemp():void 0,H=I?wn(I,`unit.heartbeat`):void 0,W=heartbeatEnv({...process.env,...C},H),q=[`-m`,t,...n],Y=[`gjs`,...q.map(t=>t.includes(` `)?`"${t}"`:t)].join(` `);S.quiet||ge.error(`$ ${N?`${N} `:``}${Y}`);let failed=t=>(process.exitCode=t,process.exit(t)),X,Z=!1,te=H?createHangWatchdog({read:()=>{try{return readFileSync(H,`utf8`)}catch{return null}},graceMs:F,onHang:(t,n)=>{let S=X?.pid;S!==void 0&&(Z=!0,ge.error(formatHangReport({label:t.label,overdueMs:n,pid:S,graceMs:F,backtrace:captureNativeBacktrace(S)})),X?.kill(`SIGABRT`),setTimeout(()=>X?.kill(`SIGKILL`),2e3))}}):void 0,ne;try{ne=await spawnToCompletion(`gjs`,q,{completion:S.completion,env:W,onSpawn:t=>{X=t,te?.start()}})}catch(t){return ge.error(t.message),failed(1)}finally{te?.stop(),I&&rmSync(I,{recursive:!0,force:!0})}if(Z)return failed(ne.code??1);if(ne.code!==0)return S.quietExit||ge.error(`gjs exited with ${describeExit(ne)}`),failed(ne.code??1);if(S.exitOnSuccess)return process.exit(0)}var XI=__esmMin(()=>{_e(),Rd(),Lg(),Pn(),CF(),V_(),JI()}),ZI=__exportAll$5({bundleRequiresNodeGi:()=>bundleRequiresNodeGi,nodeBinary:()=>nodeBinary,resolveNodeGi:()=>resolveNodeGi,resolveNodeGiForBundle:()=>resolveNodeGiForBundle,runNodeBundle:()=>runNodeBundle,runRuntimeBundle:()=>runRuntimeBundle});function resolveNodeGi(t){let n=xn(t);for(;;){if(existsSync(wn(n,`node_modules`,`@gjsify`,`node-gi`,`package.json`)))return wn(n,`node_modules`,`@gjsify`,`node-gi`);let t=xn(n,`..`);if(t===n)return null;n=t}}function resolveNodeGiForBundle(t,n){return resolveNodeGi(En(xn(t)))??resolveNodeGi(n)}function nodeBinary(){return isNode()&&process.execPath?process.execPath:`node`}async function runNodeBundle(t,n=[],S){let C=process.cwd();if(!resolveNodeGiForBundle(t,C))throw Error(`Cannot run this bundle on Node: \`@gjsify/node-gi\` is not installed.
906
+ `)}catch{return}}function createHangWatchdog(t){let n=t.now??Date.now,S=t.graceMs??3e4,C,N=!1,tick=()=>{if(N)return;let C=parseHeartbeat(t.read());!C||C.deadlineMs<=0||n()-(C.deadlineMs+S)<0||(N=!0,stop(),t.onHang(C,n()-C.deadlineMs))},stop=()=>{C!==void 0&&clearInterval(C),C=void 0};return{tick,start:(t=QI)=>{C===void 0&&(C=setInterval(tick,t))},stop}}var ZI,QI,$I=__esmMin(()=>{P_(),ZI=3e4,QI=1e3}),eL=__exportAll$5({computeNativeEnvForBundle:()=>computeNativeEnvForBundle,runGjsBundle:()=>runGjsBundle});function computeNativeEnvForBundle(t,n=process.cwd(),S=process.env,C=[]){let N=xn(t),F=[],I=new Set;for(let t of[n,En(N),...C])for(let n of detectNativePackages(t))I.has(n.name)||(I.add(n.name),F.push(n));let H=buildNativeEnv(F,{env:S});return{env:H,envPrefix:Object.entries(H).filter(([t,n])=>n!==void 0&&n!==``&&n!==S[t]).map(([t,n])=>`${t}=${n}`).join(` `)}}function safeMkdtemp(){try{return mkdtempSync(wn(tmpdir(),`gjsify-hb-`))}catch{return}}async function runGjsBundle(t,n=[],S){let{env:C,envPrefix:N}=computeNativeEnvForBundle(t,process.cwd(),process.env,S.nativeRoots),F=hangGraceMs(process.env),I=F>0?safeMkdtemp():void 0,H=I?wn(I,`unit.heartbeat`):void 0,W=heartbeatEnv({...process.env,...C},H),q=[`-m`,t,...n],Y=[`gjs`,...q.map(t=>t.includes(` `)?`"${t}"`:t)].join(` `);S.quiet||ge.error(`$ ${N?`${N} `:``}${Y}`);let failed=t=>(process.exitCode=t,process.exit(t)),X,Z=!1,te=H?createHangWatchdog({read:()=>{try{return readFileSync(H,`utf8`)}catch{return null}},graceMs:F,onHang:(t,n)=>{let S=X?.pid;S!==void 0&&(Z=!0,ge.error(formatHangReport({label:t.label,overdueMs:n,pid:S,graceMs:F,backtrace:captureNativeBacktrace(S)})),X?.kill(`SIGABRT`),setTimeout(()=>X?.kill(`SIGKILL`),2e3))}}):void 0,ne;try{ne=await spawnToCompletion(`gjs`,q,{completion:S.completion,env:W,onSpawn:t=>{X=t,te?.start()}})}catch(t){return ge.error(t.message),failed(1)}finally{te?.stop(),I&&rmSync(I,{recursive:!0,force:!0})}if(Z)return failed(ne.code??1);if(ne.code!==0)return S.quietExit||ge.error(`gjs exited with ${describeExit(ne)}`),failed(ne.code??1);if(S.exitOnSuccess)return process.exit(0)}var tL=__esmMin(()=>{_e(),Rd(),Lg(),Pn(),CF(),V_(),$I()}),nL=__exportAll$5({bundleRequiresNodeGi:()=>bundleRequiresNodeGi,nodeBinary:()=>nodeBinary,resolveNodeGi:()=>resolveNodeGi,resolveNodeGiForBundle:()=>resolveNodeGiForBundle,runNodeBundle:()=>runNodeBundle,runRuntimeBundle:()=>runRuntimeBundle});function resolveNodeGi(t){let n=xn(t);for(;;){if(existsSync(wn(n,`node_modules`,`@gjsify`,`node-gi`,`package.json`)))return wn(n,`node_modules`,`@gjsify`,`node-gi`);let t=xn(n,`..`);if(t===n)return null;n=t}}function resolveNodeGiForBundle(t,n){return resolveNodeGi(En(xn(t)))??resolveNodeGi(n)}function nodeBinary(){return isNode()&&process.execPath?process.execPath:`node`}async function runNodeBundle(t,n=[],S){let C=process.cwd();if(!resolveNodeGiForBundle(t,C))throw Error(`Cannot run this bundle on Node: \`@gjsify/node-gi\` is not installed.
907
907
  Add @gjsify/node-gi as a dependency to run it on Node, e.g.:
908
908
  "devDependencies": { "@gjsify/node-gi": "^0.13.0" }`);let{env:N,envPrefix:F}=computeNativeEnvForBundle(t,C),I={...process.env,...N},H=nodeBinary(),W=[t,...n],q=[H,...W.map(t=>t.includes(` `)?`"${t}"`:t)].join(` `);ge.error(`$ ${F?`${F} `:``}${q}`);let Y;try{Y=await spawnToCompletion(H,W,{completion:S.completion,env:I})}catch(t){return ge.error(t.message),process.exit(1)}if(Y.code!==0)return ge.error(`node exited with ${describeExit(Y)}`),process.exit(Y.code??1);if(S.exitOnSuccess)return process.exit(0)}function bundleRequiresNodeGi(t){try{return readFileSync(t,`utf-8`).includes(`@gjsify/node-gi`)}catch{return!1}}async function runRuntimeBundle(t,n,S=[],C){let N=process.cwd(),F=xn(n);if(bundleRequiresNodeGi(F)&&!resolveNodeGiForBundle(F,N))throw Error(`Cannot run this bundle on ${t}: it uses gi:// via \`@gjsify/node-gi\`, which is not installed.\nAdd @gjsify/node-gi as a dependency to run gi:// code off GJS, e.g.:
909
- "dependencies": { "@gjsify/node-gi": "^0.13.0" }`);let{env:I,envPrefix:H}=computeNativeEnvForBundle(F,N),W={...process.env,...I},[,q]=U_[t].launch(F,S),Y=t===`node`?nodeBinary():U_[t].probe,X=[Y,...q.map(t=>t.includes(` `)?`"${t}"`:t)].join(` `);C.quiet||ge.error(`$ ${H?`${H} `:``}${X}`);let failed=t=>(process.exitCode=t,process.exit(t)),Z;try{Z=await spawnToCompletion(Y,q,{completion:C.completion,env:W})}catch(t){return ge.error(t.message),failed(1)}if(Z.code!==0)return C.quietExit||ge.error(`${t} exited with ${describeExit(Z)}`),failed(Z.code??1);if(C.exitOnSuccess)return process.exit(0)}var QI=__esmMin(()=>{_e(),Rd(),Pn(),d_(),XI(),W_(),V_()});function nearestNodeModules(t){let n=xn(t);for(;;){let t=wn(n,`node_modules`);if(existsSync(t))return t;let S=En(n);if(S===n)return null;n=S}}async function rebuildForGjs(t,n,S){let C=t.nodeModules??nearestNodeModules(process.cwd())??wn(t.pkgDir,`node_modules`),N=findProjectLockfile(En(C)),F=execCacheKey({pkgName:t.pkgName,pkgVersion:t.pkgVersion,entry:entryWithinPackage(t,n),cliVersion:cliVersion(),lockfileHash:N?hashFile(N):null}),I=execArtifactPath(execCacheRoot(C),t,n,t.installed?F:`local`),H=t.installed&&!S.rebuild;if(H&&existsSync(I))return S.verbose&&ge.error(`gjsify exec: reusing ${I}`),I;ge.error(`gjsify exec: rebuilding ${t.pkgName}@${t.pkgVersion} "${t.binName}" for GJS…`);let W=En(I),q=`${W}.tmp-${process.pid.toString(16)}-${Date.now().toString(16)}`,Y=wn(q,Dn(I));try{let{BuildAction:C}=await Promise.resolve().then(()=>(SI(),yI));await C.bundleFileForGjs(n,Y,{verbose:S.verbose,preserveDefaultExport:!1,...t.installed?{}:{define:{"import.meta.url":JSON.stringify(pathToFileURL(n).href)}},toolchainAnchor:C.runningCliFile(),...S.verbose?{}:{logLevel:`silent`}})}catch(C){throw rmSync(q,{recursive:!0,force:!0}),new ExecRebuildError(t,n,C,S.verbose)}if(H&&existsSync(I))return rmSync(q,{recursive:!0,force:!0}),I;rmSync(W,{recursive:!0,force:!0});try{renameSync(q,W)}catch(t){if(rmSync(q,{recursive:!0,force:!0}),!existsSync(I))throw t}return pruneStaleArtifacts(En(W),t,Dn(W)),I}function pruneStaleArtifacts(t,n,S){let C=`${n.pkgName}@${n.pkgVersion}`.replace(/[^a-zA-Z0-9._@-]/g,`_`),N;try{N=readdirSync(t)}catch{return}for(let n of N)n===S||!n.startsWith(`${C}-`)||n.includes(`.tmp-`)||rmSync(wn(t,n),{recursive:!0,force:!0})}var ExecRebuildError,$I,eL=__esmMin(()=>{_e(),Rd(),Pn(),Gn(),d_(),NI(),GI(),nh(),XI(),QI(),ExecRebuildError=class extends Error{constructor(t,n,S,C){let N=S instanceof Error?S.message:String(S);super(`gjsify exec: rebuilding "${t.binName}" (${t.pkgName}@${t.pkgVersion}) for GJS failed.\n entry: ${n}\nNothing was run — gjsify exec never falls back to another runtime on its own. To run it on Node explicitly: \`gjsify exec --runtime node ${t.binName}\`.\n`+(C?``:`Re-run with \`gjsify exec --verbose ${t.binName}\` for the bundler's warnings.\n`)+`Bundler diagnostics:\n${N}`,{cause:S}),this.name=`ExecRebuildError`}},$I={command:`exec <entries..>`,description:"Run an installed npm bin on the runtime gjsify runs on: `gjsify exec [--runtime gjs|node|bun|deno] [--rebuild] [--verbose] <bin> [args…]`. On Node/Bun/Deno the bin runs unchanged; on GJS it is rebuilt `--app gjs` once, cached under node_modules/.cache/gjsify/exec/, and run with gjs. Options go BEFORE the bin; everything after it is the bin's own.",builder:t=>t.positional(`entries`,{description:`gjsify exec options, then the bin name and its arguments.`,type:`string`,array:!0}).version(!1).help(!1).parserConfiguration({"populate--":!0,"parse-positional-numbers":!1,"unknown-options-as-args":!0}),handler:async t=>{let n,S,C;try{n=splitExecArgv(t.entries??[],doubleDashArgs(t)),S=resolveExecBin(n.bin,process.cwd()),C=planExec(S,n.runtime??hostRuntime$1())}catch(t){if(t instanceof ExecBinNotFoundError)return ge.error(t.message),process.exit(127);if(t instanceof ExecPlanError)return ge.error(t.message),process.exit(1);throw t}let N={completion:`exit`,exitOnSuccess:!0,quiet:!n.verbose,quietExit:!0};if(C.kind===`direct`){await runRuntimeBundle(C.runtime,C.file,n.args,N);return}if(C.kind===`gjs-bundle`){await runGjsBundle(C.file,n.args,N);return}let F=await rebuildForGjs(S,C.entry,{rebuild:n.rebuild,verbose:n.verbose}),I=cliPackageDir();await runGjsBundle(F,n.args,{...N,nativeRoots:I?[I]:[]})}}});function bundleInputsPath(t){return`${t}.inputs.json`}function idToPath(t){if(t===``||t.startsWith(`\0`))return null;let n=t.search(/[?#]/);if(n===-1)return t;let S=t.slice(0,n);return isFile(S)?S:t}function isFile(t){try{return statSync(t).isFile()}catch{return!1}}function isToolchainScratch(t){return t.includes(`${jn}node_modules${jn}.cache${jn}`)}function resolutionFilesFor(t){let n=[];for(let S=En(t);;S=En(S)){let t=wn(S,`package.json`);if(existsSync(t)){n.push(t);let C=wn(S,`tsconfig.json`);return existsSync(C)&&n.push(C),n}if(En(S)===S)return n}}function createBundleInputsRecorder(t){let n=new Set,S=!0,record=t=>{let S=idToPath(t);S!==null&&n.add(S)},C={name:`gjsify:bundle-inputs`,transform(t,n){record(n)}},inputs=()=>{let t=[],S=new Set;for(let C of n){let n;try{n=statSync(C).isFile()}catch{continue}if(!n||isToolchainScratch(C))continue;t.push(C);let N=En(C);if(!S.has(N)){S.add(N);for(let n of resolutionFilesFor(C))t.push(n)}}return[...new Set(t)].sort()};return{plugin:C,addWatchFiles(t){t.reportedByEngine||(S=!1);for(let n of t.files)record(n)},inputs,write(){let n=bundleInputsPath(t),C={version:2,inputs:inputs(),watchList:S},N=`${n}.tmp`;try{mkdirSync(En(n),{recursive:!0}),writeFileSync(N,`${JSON.stringify(C,null,2)}\n`,`utf-8`),renameSync(N,n)}catch(t){try{rmSync(N,{force:!0})}catch{}ge.warn(`[gjsify test] could not record the build inputs beside ${n} (${t.message}) — the next run judges freshness by the package walk alone, which cannot see outside this package.`)}}}}function readBundleInputs(t){let n;try{n=JSON.parse(readFileSync(bundleInputsPath(t),`utf-8`))}catch{return null}return n?.version!==2||!Array.isArray(n.inputs)?null:{inputs:n.inputs.filter(t=>typeof t==`string`),watchList:n.watchList===!0}}function newestBundleInputMtimeMs(t){let n=0;for(let S of t)try{let{mtimeMs:t}=statSync(S);t>n&&(n=t)}catch{return 1/0}return n}var tL=__esmMin(()=>{_e(),Rd(),Pn()});async function buildTestBundle(t,n,S,C){let N=await new Config().forBuild({entryPoints:[t],outfile:n,app:S,verbose:C??!1,logLevel:`warning`,exclude:[]});N.library={...N.library};let F=createBundleInputsRecorder(n);N.bundler={...N.bundler,input:[t],output:{...N.bundler?.output,file:n},plugins:[...N.bundler?.plugins??[],F.plugin]},await new xI(N).start({app:S,library:!1,onWatchFiles:t=>F.addWatchFiles(t)}),F.write()}async function runTestBundle(t,n){if(n===`gjs`){await runGjsBundle(t,[],{completion:`exit`});return}let S=await spawnToCompletion(nodeBinary(),[t],{completion:`exit`});if(S.code!==0)throw Error(`node exited with ${describeExit(S)}`)}function isFresh(t,n,S,C){if(!existsSync(t))return!1;try{let N=statSync(t).mtimeMs,F=[],I=Tn(S,C).split(jn).join(`/`);I!==``&&!I.startsWith(`../`)&&F.push(I);let H=readBundleInputs(t);return H!==null&&!H.watchList?!1:N>=Math.max(newestInputMtimeMs(packageBuildInputs(S,{extraOutputs:F})),H===null?0:newestBundleInputMtimeMs(H.inputs),statSync(n).mtimeMs,newestDepSignalMtimeMs(S))}catch{return!1}}var nL,rL=__esmMin(()=>{_e(),Rd(),Pn(),tL(),vI(),W_(),QI(),V_(),TI(),SI(),XI(),nL={command:`test`,description:"Build + run the package’s `src/test.mts` suite on GJS and Node and aggregate the results. Replaces the per-package `build:test:{gjs,node}` + `test:{gjs,node}` script boilerplate.",builder:t=>t.option(`runtime`,{description:`Target runtime. Default: both.`,type:`string`,choices:[`gjs`,`node`,`all`],default:`all`}).option(`entry`,{description:"Path to the test entry. Default: `src/test.mts` (or `gjsify.test.entry`).",type:`string`,normalize:!0}).option(`outdir`,{description:"Output directory for the built test bundles. Default: `dist/`.",type:`string`,normalize:!0}).option(`rebuild`,{description:`Always rebuild the test bundles, even when they look up-to-date.`,type:`boolean`,default:!1}).option(`build`,{description:`Build before running. Default: true (use --no-build to skip when bundles already exist).`,type:`boolean`,default:!0}).option(`verbose`,{description:`Print resolved entry/outdir + per-step timing.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=(await new Config().forBuild({}).catch(()=>({}))).test??{},C=xn(n,t.entry??S.entry??`src/test.mts`),N=xn(n,t.outdir??S.outdir??`dist`);if(!existsSync(C))return ge.error(`[gjsify test] no test entry at ${Tn(n,C)} — add an \`src/test.mts\` that aggregates your \`@gjsify/unit\` suites, or set \`gjsify.test.entry\` in package.json.`),process.exit(1);let F=t.runtime===`gjs`||t.runtime===`node`,I=t.runtime===`gjs`?[`gjs`]:t.runtime===`node`?[`node`]:S.runtimes&&S.runtimes.length>0?S.runtimes:[`gjs`,`node`],H=F?I:I.filter(t=>isRuntimeAvailable(t));for(let t of I.filter(t=>!H.includes(t)))ge.log(`[gjsify test] skipping ${t} — no \`${U_[t].probe}\` on PATH (not requested explicitly)`);if(H.length===0)return ge.error(`[gjsify test] none of the default runtimes (${I.join(`, `)}) is available on this host.\n Install one, or pin the set: \`gjsify test --runtime <rt>\` / \`gjsify.test.runtimes\` in package.json.`),process.exit(1);let W=[];for(let S of H){let F=wn(N,`test.${S}.mjs`);if(t.build!==!1)if(t.rebuild||!isFresh(F,C,n,N)){let N=Date.now();t.verbose&&ge.log(`[gjsify test] building → ${Tn(n,F)} (—app ${S})`);try{await buildTestBundle(C,F,S,t.verbose),t.verbose&&ge.log(`[gjsify test] built ${S} in ${Date.now()-N}ms`)}catch(t){ge.error(`[gjsify test] build failed for ${S}:`,t.message),W.push({runtime:S,ok:!1,durationMs:0,error:`build failed`});continue}}else t.verbose&&ge.log(`[gjsify test] ${S}: bundle is up-to-date — skipping build (use --rebuild to force)`);else if(!existsSync(F)){ge.error(`[gjsify test] --no-build but ${Tn(n,F)} doesn't exist. Build first or drop --no-build.`),W.push({runtime:S,ok:!1,durationMs:0,error:`no bundle`});continue}let I=Date.now();try{await runTestBundle(F,S),W.push({runtime:S,ok:!0,durationMs:Date.now()-I})}catch(t){W.push({runtime:S,ok:!1,durationMs:Date.now()-I,error:t.message})}}let q=W.map(t=>`${t.ok?`✅`:`❌`} ${t.runtime} (${t.durationMs}ms)${t.error?` — ${t.error}`:``}`).join(` `);if(ge.log(`[gjsify test] ${q}`),W.some(t=>!t.ok))return process.exit(1);process.exit(0)}}});function readPackageJson$1(t){if(!existsSync(t))return null;let n=readFileSync(t,`utf-8`);try{return JSON.parse(n)}catch(n){throw Error(`gjsify install: ${t} is not valid JSON: ${n.message}`)}}function writePackageJson(t,n){let S=sortKnownDepFields(n);writeFileSync(t,JSON.stringify(S,null,2)+`
910
- `,`utf-8`)}function parseSpec$2(t){if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)return{name:t};let S=t.indexOf(`@`,n+1);return S===-1?{name:t}:{name:t.slice(0,S),range:t.slice(S+1)}}let n=t.indexOf(`@`);return n===-1?{name:t}:{name:t.slice(0,n),range:t.slice(n+1)}}function projectSpecsFromPackageJson(t){let n=[];for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=t[S];if(C)for(let[t,S]of Object.entries(C))typeof S==`string`&&(/^(workspace|link|file|portal|git\+|https?):/.test(S)||n.push(`${t}@${S}`))}return n}function addDependencyEntry(t,n,S,C){t[C]===void 0&&(t[C]={}),t[C][n]=S}function defaultRangeFromVersion(t){return`^${t}`}function sortKnownDepFields(t){let n={...t};for(let t of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let S=n[t];S&&(n[t]=Object.fromEntries(Object.entries(S).sort(([t],[n])=>t<n?-1:+(t>n))))}return n}var iL=__esmMin(()=>{Rd(),__name$1(readPackageJson$1,`readPackageJson`),__name$1(parseSpec$2,`parseSpec`)});function scriptCacheEnabled(){let t=process.env.GJSIFY_NODE_SCRIPT_CACHE;return t===`1`||t===`true`||t===`yes`}async function runNodeScript(t,n=[],S){let C=xn(t);if(!existsSync(C)||!statSync(C).isFile())return ge.error(`gjsify run --node-script: no such file: ${C}`),process.exit(1);let N=hostRuntime$1();if(N!==`gjs`){await runRuntimeBundle(N,C,n,{completion:S.completion,exitOnSuccess:S.exitOnSuccess,quiet:!0});return}let{BuildAction:F}=await Promise.resolve().then(()=>(SI(),yI)),{globals:I,excludeGlobals:H}=await new Config().forNodeScript(C),W;try{W=await F.bundleFileForGjsCached(C,{cacheSubdir:`node-scripts`,label:Dn(C),cache:scriptCacheEnabled(),preserveDefaultExport:!1,define:{"import.meta.url":JSON.stringify(pathToFileURL(C).href)},globals:I,excludeGlobals:H,resolveFromToolchain:!0})}catch(t){throw Error(`gjsify run --node-script: failed to bundle ${C} for GJS. The script must import only what gjsify can provide under GJS (node: builtins, workspace packages, pure-JS npm deps). (${t.message})`)}await runGjsBundle(W,n,{completion:S.completion,exitOnSuccess:S.exitOnSuccess,quiet:!0})}var aL=__esmMin(()=>{_e(),Rd(),Pn(),Gn(),d_(),TI(),XI(),QI()});function gjsifyCacheRoot(t,n){let S=process.env.XDG_CACHE_HOME;return wn(S&&S.length>0?S:wn(homedir(),`.cache`),`gjsify`,t,n)}function atomicWrite(t,n){try{atomicWriteStrict(t,n)}catch{}}function atomicWriteStrict(t,n){mkdirSync(wn(t,`..`),{recursive:!0});let S=`${t}.tmp.${process.pid}`;writeFileSync(S,n),renameSync(S,t)}function readCacheFile(t){if(!existsSync(t))return null;try{let n=readFileSync(t);return n.length===0?null:n}catch{return null}}var oL=__esmMin(()=>{Rd(),Lg(),Pn()});function makeProgressReporter(t={}){if(t.enabled===!1)return cL;let n=t.stream??process.stderr,S=!!n.isTTY;return t.enabled??!0?S?makeTtyReporter(n):makePlainReporter(n):cL}function makeTtyReporter(t){let n=0,S=``;function render(C,N=!1){let F=Date.now();!N&&F-n<33&&C===S||(n=F,S=C,t.write(`\r\x1B[2K`+C))}function clearLine(){t.write(`\r\x1B[2K`),S=``}return{beginPhase(n,S){render(formatBar(n,0,S,void 0,t.columns??80),!0)},update(n){render(formatBar(n.phase,n.current,n.total,n.name,t.columns??80))},endPhase(n){let S=sL[n];clearLine(),t.write(`gjsify install: ${S} done\n`)}}}function makePlainReporter(t){let n=0,S=0;return{beginPhase(C,N){n=Date.now(),S=0,t.write(`gjsify install: ${sL[C]} ${N} package(s)\n`)},update(C){let N=Date.now();if(N-n<lL||C.current<=S)return;n=N,S=C.current;let F=C.total>0?Math.round(C.current/C.total*100):0;t.write(`gjsify install: ${sL[C.phase]} ${C.current}/${C.total} (${F}%)\n`)},endPhase(n){t.write(`gjsify install: ${sL[n]} done\n`)}}}function formatBar(t,n,S,C,N){let F=sL[t],I=S>0?Math.min(1,n/S):0,H=`${n}/${S}`,W=`gjsify install: ${F} `,q=` ${H}`+(C?` ${C}`:``),Y=Math.max(8,Math.min(40,N-W.length-q.length-4)),X=Math.round(I*Y),Z=`█`.repeat(X)+`░`.repeat(Y-X),te=`${W}[${Z}]${q}`;if(te.length>N){let t=te.length-N+1,n=C&&C.length>t?C.slice(0,C.length-t-1)+`…`:``;te=`${W}[${Z}] ${H}${n?` `+n:``}`}return te}var sL,cL,lL,uL=__esmMin(()=>{sL={resolve:`resolving`,download:`downloading`,extract:`extracting`,link:`linking bins`},cL={update(){},beginPhase(){},endPhase(){}},lL=5e3});function parseTar(t){let n=[],S=null,C=null,N=null,F=0;for(;F+512<=t.length;){let I=t.subarray(F,F+512);if(allZeros(I)){let n=t.subarray(F+512,F+2*512);if(n.length===512&&allZeros(n))break;F+=512;continue}if(!validateChecksum(I))throw new TarParseError(`Bad header checksum at offset ${F} — file is not a valid tar archive`);let H=readString(I,0,100),W=parseOctal(I,100,8),q=parseOctal(I,124,12),Y=parseOctal(I,136,12),X=String.fromCharCode(I[156]||0),Z=readString(I,157,100),te=readString(I,257,6),ne=readString(I,345,155),re=readString(I,265,32),ie=readString(I,297,32);F+=512;let ae=t.subarray(F,F+q);if(F+=alignToBlock(q),X===`x`){S=parsePaxRecords(ae);continue}if(X===`g`)continue;if(X===`L`){C=bytesToString(ae).replace(/\0+$/,``);continue}if(X===`K`){N=bytesToString(ae).replace(/\0+$/,``);continue}let oe=H;te===`ustar`&&ne!==``&&(oe=`${ne}/${H}`),C!==null&&(oe=C,C=null);let Q=Z;if(N!==null&&(Q=N,N=null),S!==null){let C=S.get(`path`);C!==void 0&&(oe=C);let N=S.get(`linkpath`);N!==void 0&&(Q=N);let I=S.get(`size`);if(I!==void 0){let C=Number(I);if(Number.isFinite(C)){let N=F-alignToBlock(q),I=t.subarray(N,N+C);F=N+alignToBlock(C),S=null,n.push(buildEntry(oe,Q,X,W,Y,re,ie,I));continue}}S=null}n.push(buildEntry(oe,Q,X,W,Y,re,ie,ae))}return n}function buildEntry(t,n,S,C,N,F,I,H){return{name:t,linkname:n,type:typeflagToType(S,t),mode:C,mtime:N,body:H,uname:F,gname:I}}function typeflagToType(t,n){switch(t){case`0`:case`\0`:case``:return n.endsWith(`/`)?`directory`:`file`;case`1`:return`hardlink`;case`2`:return`symlink`;case`5`:return`directory`;case`x`:return`pax-header`;case`g`:return`pax-global`;case`L`:return`gnu-longname`;case`K`:return`gnu-longlink`;default:return`unknown`}}function parsePaxRecords(t){let n=new Map,S=0;for(;S<t.length;){let C=S;for(;C<t.length&&t[C]!==32;)C++;if(C>=t.length)break;let N=bytesToString(t.subarray(S,C)),F=Number(N);if(!Number.isFinite(F)||F<=0)break;let I=S+F;if(I>t.length)break;let H=bytesToString(t.subarray(C+1,I-1)),W=H.indexOf(`=`);if(W>0){let t=H.slice(0,W),S=H.slice(W+1);n.set(t,S)}S=I}return n}function readString(t,n,S){let C=n,N=n+S;for(;C<N&&t[C]!==0;)C++;return bytesToString(t.subarray(n,C))}function bytesToString(t){return new TextDecoder(`utf-8`,{fatal:!1}).decode(t)}function parseOctal(t,n,S){if(S>0&&t[n]&128){let C=t[n]&127;for(let N=1;N<S;N++)C=C*256+t[n+N];return C}let C=``;for(let N=0;N<S;N++){let S=t[n+N];S===0||S===32||(C+=String.fromCharCode(S))}return C===``?0:parseInt(C,8)}function alignToBlock(t){return Math.ceil(t/512)*512}function allZeros(t){for(let n=0;n<t.length;n++)if(t[n]!==0)return!1;return!0}function validateChecksum(t){let n=parseOctal(t,148,8),S=0,C=0;for(let n=0;n<512;n++){let N=n>=148&&n<156?32:t[n];S+=N,C+=N>127?N-256:N}return n===S||n===C}var TarParseError,dL=__esmMin(()=>{TarParseError=class extends Error{constructor(t){super(t),this.name=`TarParseError`}}});function createTarball(t){let n=[];for(let S of t){if(`directory`in S&&S.directory===!0){n.push(buildHeader$1(ensureTrailingSlash(S.name),0,`5`,S.mode??493,S.mtime??0));continue}let t=S,C=typeof t.body==`string`?new TextEncoder().encode(t.body):t.body,N=t.mode??defaultFileMode(C);n.push(buildHeader$1(t.name,C.byteLength,`0`,N,t.mtime??0)),n.push(C);let F=padTo512(C.byteLength);F>0&&n.push(new Uint8Array(F))}return n.push(new Uint8Array(512*2)),concatChunks(n)}function buildHeader$1(t,n,S,C,N){let{prefix:F,basename:I}=splitPathForUstar(t),H=new Uint8Array(512);writeAscii(H,I,0,100),writeOctal(H,C&4095,100,7),H[107]=0,writeOctal(H,0,108,7),H[115]=0,writeOctal(H,0,116,7),H[123]=0,writeOctal(H,n,124,11),H[135]=0,writeOctal(H,N,136,11),H[147]=0;for(let t=148;t<156;t++)H[t]=32;H[156]=S.charCodeAt(0),writeAscii(H,`ustar\0`,257,6),writeAscii(H,`00`,263,2),F&&writeAscii(H,F,345,155);let W=0;for(let t=0;t<512;t++)W+=H[t];return writeAscii(H,W.toString(8).padStart(6,`0`),148,6),H[154]=0,H[155]=32,H}function splitPathForUstar(t){if(t.length<=100)return{prefix:``,basename:t};if(t.length>255)throw Error(`createTarball: path too long (${t.length} > 255 chars): ${t}`);for(let n=Math.min(t.length-1,155);n>0;n--)if(t[n]===`/`&&t.length-n-1<=100)return{prefix:t.slice(0,n),basename:t.slice(n+1)};throw Error(`createTarball: cannot split path into ustar prefix+basename (basename slot is 100 chars): ${t}`)}function writeAscii(t,n,S,C){let N=new TextEncoder().encode(n);if(N.length>C)throw Error(`createTarball: field too long (${N.length} > ${C}): "${n}"`);t.set(N,S)}function writeOctal(t,n,S,C){writeAscii(t,n.toString(8).padStart(C,`0`),S,C)}function padTo512(t){let n=t%512;return n===0?0:512-n}function ensureTrailingSlash(t){return t.endsWith(`/`)?t:`${t}/`}function defaultFileMode(t){return t.length>=2&&t[0]===35&&t[1]===33?493:420}function concatChunks(t){let n=0;for(let S of t)n+=S.byteLength;let S=new Uint8Array(n),C=0;for(let n of t)S.set(n,C),C+=n.byteLength;return S}var fL=__esmMin(()=>{__name$1(buildHeader$1,`buildHeader`)});async function extractTarball(t,n,S={}){let C=t instanceof Uint8Array?t:new Uint8Array(t),N=parseTar(S.gzip??(C.length>=2&&C[0]===31&&C[1]===139)?await gunzip(C):C);mkdirSync(n,{recursive:!0});let F=S.strip??1,I=S.preventEscape??!0,H={files:[],directories:[],symlinks:[],skipped:0};for(let t of N){let C=stripComponents(t.name,F);if(C===null||C===``){H.skipped++;continue}let N=xn(n,C);if(I&&!isInside$2(N,n))throw Error(`tar: refusing to extract ${t.name} outside ${n} (resolved=${N})`);if(S.filter&&!S.filter(t,N)){H.skipped++;continue}if(t.type===`directory`){mkdirSync(N,{recursive:!0}),H.directories.push(N);continue}if(t.type===`file`){mkdirSync(En(N),{recursive:!0}),writeFileSync(N,t.body);let n=S.chmod?.(t,N)??t.mode&511;if(n>0)try{chmodSync(N,n)}catch{}H.files.push(N);continue}if(t.type===`symlink`){mkdirSync(En(N),{recursive:!0});try{symlinkSync(t.linkname,N),H.symlinks.push(N)}catch{writeFileSync(N,t.linkname),H.files.push(N)}continue}H.skipped++}return H}async function gunzip(t){let n=globalThis.DecompressionStream;if(typeof n!=`function`)throw Error(`@gjsify/tar: globalThis.DecompressionStream is not available — import '@gjsify/compression-streams/register' on GJS to register it`);return drainStream(new Blob([new Uint8Array(t)]).stream().pipeThrough(new n(`gzip`)))}async function gzip(t,n){if(n?.level!==void 0){let{gzipSync:S}=await Promise.resolve().then(()=>(ua(),oa));return new Uint8Array(S(t,{level:n.level}))}let S=globalThis.CompressionStream;if(typeof S!=`function`)throw Error(`@gjsify/tar: globalThis.CompressionStream is not available — import '@gjsify/compression-streams/register' on GJS to register it`);return drainStream(new Blob([new Uint8Array(t)]).stream().pipeThrough(new S(`gzip`)))}async function drainStream(t){let n=[],S=0,C=t.getReader();for(;;){let{value:t,done:N}=await C.read();if(N)break;let F=t instanceof Uint8Array?t:new Uint8Array(t);n.push(F),S+=F.length}let N=new Uint8Array(S),F=0;for(let t of n)N.set(t,F),F+=t.length;return N}function stripComponents(t,n){if(n<=0)return t;let S=t.split(`/`).filter(t=>t!==``);return S.length<=n?null:S.slice(n).join(`/`)}function isInside$2(t,n){let S=Tn(n,t);return S!==``&&!S.startsWith(`..`)&&!Cn(S)}var pL=__esmMin(()=>{dL(),Rd(),Pn(),__name$1(isInside$2,`isInside`)}),mL=__exportAll$5({BLOCK_SIZE:()=>512,TarParseError:()=>TarParseError,createTarball:()=>createTarball,extractTarball:()=>extractTarball,gunzip:()=>gunzip,gzip:()=>gzip,parseTar:()=>parseTar}),hL=__esmMin(()=>{dL(),fL(),pL()});function isPidAlive(t){if(existsSync(`/proc/self`))return existsSync(`/proc/${t}`);try{return process.kill(t,0),!0}catch(t){return t.code!==`ESRCH`}}function parsePsPidPpid(t){let n=new Map;for(let S of t.split(`
911
- `)){let t=/^\s*(\d+)\s+(\d+)\s*$/.exec(S);if(!t)continue;let C=Number(t[1]),N=Number(t[2]);if(C<=0||N<=0||C===N)continue;let F=n.get(N);F?F.push(C):n.set(N,[C])}return n}function readProcChildren(t){let n;try{n=readdirSync(`/proc/${t}/task`)}catch{return null}let S=[],C=!1;for(let N of n)try{let n=readFileSync(`/proc/${t}/task/${N}/children`,`utf-8`);C=!0;for(let t of n.trim().split(/\s+/)){let n=Number(t);Number.isInteger(n)&&n>0&&S.push(n)}}catch{}return C?S:null}function procPpidMap(){let t=new Map,n=[];try{n=readdirSync(`/proc`)}catch{return t}for(let S of n){let n=Number(S);if(!(!Number.isInteger(n)||n<=0))try{let S=readFileSync(`/proc/${n}/stat`,`utf-8`),C=S.slice(S.lastIndexOf(`)`)+2).split(` `),N=Number(C[1]);if(!Number.isInteger(N)||N<=0)continue;let F=t.get(N);F?F.push(n):t.set(N,[n])}catch{}}return t}function osPpidMap(){let[t,n]=process.platform===`win32`?[`powershell.exe`,[`-NoProfile`,`-NonInteractive`,`-Command`,`Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId) $($_.ParentProcessId)" }`]]:[`ps`,[`-A`,`-o`,`pid=,ppid=`]];try{let S=spawnSync(t,n,{encoding:`utf-8`});return S.status!==0||typeof S.stdout!=`string`?new Map:parsePsPidPpid(S.stdout)}catch{return new Map}}function collectDescendants(t){let n=[],S=new Set([t]),C=[t],N=null;for(;C.length>0;){let t=C.shift(),F=N?null:readProcChildren(t);F===null&&(N||(N=procPpidMap(),N.size===0&&(N=osPpidMap())),F=N.get(t)??[]);for(let t of F)S.has(t)||(S.add(t),n.push(t),C.push(t))}return n}var gL=__esmMin(()=>{P_(),Rd()});function staleMs(){let t=process.env.GJSIFY_INSTALL_LOCK_STALE_MS;if(t!==void 0){let n=Number(t);if(Number.isFinite(n)&&n>0)return n}return yL}function lockingDisabled(){let t=process.env.GJSIFY_INSTALL_LOCK;if(t===void 0)return!1;let n=t.trim();return n===`0`||n===`false`}function mtimeMs(t){try{return statSync(t).mtimeMs}catch{return null}}function assessLock(t){let n=wn(t,vL),S=null;try{S=JSON.parse(readFileSync(n,`utf-8`))}catch{S=null}let C=Date.now();if(S&&typeof S.pid==`number`){if(!isPidAlive(S.pid))return{stale:!0,reason:`owner pid ${S.pid} is gone`,ownerPid:S.pid};let t=typeof S.startedAt==`number`?S.startedAt:mtimeMs(n);return t!==null&&C-t>staleMs()?{stale:!0,reason:`owner pid ${S.pid} exceeded the ${staleMs()}ms staleness budget`,ownerPid:S.pid}:{stale:!1,ownerPid:S.pid}}let N=mtimeMs(t);return N===null?{stale:!1}:C-N>bL?{stale:!0,reason:`no owner recorded within the acquire grace period`}:{stale:!1}}function stealStaleLock(t){let n=`${t}.stale-${process.pid}-${++wL}`;try{renameSync(t,n)}catch{return!1}try{rmSync(n,{recursive:!0,force:!0})}catch{}return!0}function abortErr(t){let n=t&&`reason`in t?t.reason:void 0;if(n instanceof Error)return n;let S=Error(`Aborted`);return S.name=`AbortError`,S}function delay(t,n){return t<=0?Promise.resolve():new Promise((S,C)=>{let onAbort=()=>{clearTimeout(N),C(abortErr(n))},N=setTimeout(()=>{n?.removeEventListener?.(`abort`,onAbort),S()},t);if(n?.aborted){clearTimeout(N),C(abortErr(n));return}n?.addEventListener?.(`abort`,onAbort,{once:!0})})}function makeHandle(t){let n=!1;return{release(){if(n)return;n=!0;let S=CL.get(t);if(S&&(S.count--,!(S.count>0))){CL.delete(t);try{let n=JSON.parse(readFileSync(wn(t,vL),`utf-8`));if(n.nonce!==void 0&&n.nonce!==S.nonce)return}catch{}try{rmSync(t,{recursive:!0,force:!0})}catch{}}}}}async function acquireInstallLock(t,n={}){if(lockingDisabled())return{release(){}};let S;try{S=realpathSync(t)}catch{S=xn(t)}let C=wn(S,`node_modules`,_L),N=CL.get(C);if(N)return N.count++,makeHandle(C);mkdirSync(En(C),{recursive:!0});let F=`${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`,I=xL,H=!1;for(;;){if(n.signal?.aborted)throw abortErr(n.signal);try{return mkdirSync(C),writeFileSync(wn(C,vL),JSON.stringify({pid:process.pid,nonce:F,startedAt:Date.now()})),CL.set(C,{count:1,nonce:F}),makeHandle(C)}catch(t){if(t.code!==`EEXIST`)throw t}let t=assessLock(C);if(t.stale){stealStaleLock(C)&&ge.warn(`gjsify install: removed stale install lock (${t.reason}) — ${C}`);continue}if(!H){H=!0;let n=t.ownerPid===void 0?``:` (pid ${t.ownerPid})`;ge.warn(`gjsify install: waiting for a concurrent install${n} to release ${C} …`)}await delay(I,n.signal),I=Math.min(Math.round(I*1.6),SL)}}var _L,vL,yL,bL,xL,SL,CL,wL,TL=__esmMin(()=>{_e(),Rd(),Pn(),gL(),_L=`.gjsify-install-lock`,vL=`owner.json`,yL=35*6e4,bL=15e3,xL=150,SL=1e3,CL=new Map,wL=0});function cacheRoot$1(){return gjsifyCacheRoot(`tarballs`,EL)}function parseSri$1(t){if(!t)return null;let n=t.indexOf(`-`);if(n<=0||n===t.length-1)return null;let S=t.slice(0,n),C=t.slice(n+1).replace(/=+$/,``),N=$e.from(C,`base64`).toString(`hex`);return N.length<4?null:{algorithm:S,hex:N}}function pathFor$3(t){let n=parseSri$1(t);if(!n)return null;let S=n.hex.slice(0,2);return wn(cacheRoot$1(),n.algorithm,S,`${n.hex}.tgz`)}async function getCachedTarball(t){let n=pathFor$3(t);if(!n||!t)return null;let S=readCacheFile(n);if(!S)return null;if(await verifyIntegrity(S,t))return S;try{unlinkSync(n)}catch{}return null}function putCachedTarball(t,n){let S=pathFor$3(t);S&&(existsSync(S)||atomicWrite(S,n))}function npmCacacheContentDir(){let t=process.env.GJSIFY_NPM_CACHE;if(t!==void 0){let n=t.trim();return n===``||n===`0`||n===`false`?null:wn(n.endsWith(`_cacache`)?n:wn(n,`_cacache`),`content-v2`)}let n=process.env.npm_config_cache;return wn(n&&n.length>0?n:wn(homedir(),`.npm`),`_cacache`,`content-v2`)}function npmCachePathFor(t){let n=npmCacacheContentDir();if(!n)return null;let S=parseSri$1(t);return S?wn(n,S.algorithm,S.hex.slice(0,2),S.hex.slice(2,4),S.hex.slice(4)):null}async function getForeignCachedTarball(t){let n=npmCachePathFor(t);if(!n||!t)return null;let S=readCacheFile(n);return S&&await verifyIntegrity(S,t)?S:null}var EL,DL=__esmMin(()=>{lt(),Rd(),Lg(),Pn(),eh(),oL(),EL=`v1`,__name$1(cacheRoot$1,`cacheRoot`),__name$1(parseSri$1,`parseSri`),__name$1(pathFor$3,`pathFor`)});function isEnabled(){let t=process.env.GJSIFY_PACKUMENT_CACHE;if(t===void 0)return!0;let n=t.trim();return!(n===`0`||n===`false`||n===``)}function cacheRoot(){return gjsifyCacheRoot(`metadata`,OL)}function shardFor(t){let n=2166136261;for(let S=0;S<t.length;S++)n^=t.charCodeAt(S),n=Math.imul(n,16777619);return(n>>>0&255).toString(16).padStart(2,`0`)}function encodePart(t){return encodeURIComponent(t).replace(/\*/g,`%2A`)}function packumentCacheKey(t,n,S){return`${S},${encodePart(t)},${encodePart(n)}`}function pathFor$2(t,n,S){if(!isEnabled())return null;let C=packumentCacheKey(t,n,S);return wn(cacheRoot(),shardFor(C),`${C}.json`)}function getCachedPackument(t,n,S=`corgi`){let C=pathFor$2(t,n,S);if(!C)return null;let N=readCacheFile(C);if(!N)return null;try{let t=JSON.parse(N.toString(`utf-8`));return typeof t.etag!=`string`||!t.etag||!t.packument||typeof t.packument!=`object`?null:{etag:t.etag,packument:t.packument}}catch{return null}}function putCachedPackument(t,n,S,C,N=`corgi`){if(!S)return;let F=pathFor$2(t,n,N);F&&atomicWrite(F,JSON.stringify({etag:S,packument:C}))}var OL,kL=__esmMin(()=>{Pn(),oL(),OL=`v3`,__name$1(pathFor$2,`pathFor`)});function parseNodeMajor(t){return Number.parseInt(String(t).split(`.`,1)[0]??``,10)}function nativeBackendNodeError(t,n){if(!n)return null;let S=parseNodeMajor(t);return!Number.isFinite(S)||S>=24?null:`gjsify install (native backend) requires Node ≥ 24, but this is Node ${t}. Its prebuilt native modules are ABI-locked to Node 24 and crash on older majors. Use Node 24 (nvm/asdf locally, actions/setup-node in CI), or run with --backend npm.`}function onRealNode(){return gjsSystemVersion()===void 0?isNode():!1}function assertNativeBackendNodeVersion(){let t=nativeBackendNodeError(process.versions.node,onRealNode());if(t)throw Error(t)}var AL=__esmMin(()=>{d_()});function normalizePath(t){let n=jn===`/`?t:t.split(jn).join(`/`);return n.endsWith(`/`)?n.slice(0,-1):n}function findExtraneous(t){let n=new Set(t.expected.map(t=>normalizePath(t.installPath))),S=t.installed.filter(t=>t.bundles&&!t.linked).map(n=>`${normalizePath(Tn(t.prefix,n.dir))}/node_modules/`),C=[];for(let N of t.installed){if(N.linked)continue;let F=normalizePath(Tn(t.prefix,N.dir));F===``||F.startsWith(`..`)||n.has(F)||S.some(t=>F.startsWith(t))||C.push({installPath:F,name:N.name,version:N.version})}C.sort((t,n)=>t.installPath<n.installPath?-1:+(t.installPath>n.installPath));let N=[];for(let t of C){let n=N[N.length-1];n&&t.installPath.startsWith(`${n.installPath}/`)||N.push(t)}return N}function formatExtraneousError(t,n){let S=t.slice(0,20),C=S.map(t=>` ${t.installPath} (${t.name}@${t.version})`);return t.length>S.length&&C.push(` … and ${t.length-S.length} more`),[`install: --immutable, but ${n}/node_modules holds ${t.length} package(s) that gjsify-lock.json does not describe.`,`--immutable installs the lockfile and removes nothing, so each of these would survive the install and be resolved, bundled and type-checked as if it belonged (gjsify#1683: a nested copy of an already-hoisted package → TS2883, one type with two identities).`,...C,"Fix: delete those directories — or the whole node_modules — and re-run. A plain `gjsify install` does NOT clear them: it only ever adds, and its prune pass judges foreign-PLATFORM packages alone (prune-prefix.ts), so an undescribed package survives both. Deleting is currently the only thing that removes one. In CI this usually means a cache entry was restored from a DIFFERENT lockfile."].join(`
912
- `)}var jL=__esmMin(()=>{Pn()});function dirLinkTarget(t,n,S=ML){return S===`junction`?xn(n):Tn(En(t),n)}function linkDirSync(t,n){assertAbsolute(n),symlinkSync(dirLinkTarget(t,n),t,NL)}function replicateLinkSync(t,n){let S=readlinkSync(t);if(!dirLinksAreJunctions()){symlinkSync(S,n);return}let C=xn(En(t),S),N;try{N=statSync(C).isDirectory()}catch{symlinkSync(S,n);return}N?symlinkSync(C,n,`junction`):symlinkSync(S,n,`file`)}function assertAbsolute(t){if(xn(t)!==t)throw TypeError(`linkDir: target must be an absolute path, got ${JSON.stringify(t)}. Node resolves a Windows junction target against the process CWD rather than the link's own directory, so a relative target silently points somewhere else there.`)}var ML,NL,dirLinksAreJunctions,PL=__esmMin(()=>{Rd(),xd(),Pn(),ML=process.platform===`win32`?`junction`:`symlink`,NL=ML===`junction`?`junction`:void 0,dirLinksAreJunctions=()=>ML===`junction`});function checkList(t,n){let S=typeof n==`string`?[n]:n;if(S.length===1&&S[0]===`any`)return!0;let C=0,N=!1;for(let n of S){let S=n.charAt(0)===`!`,F=S?n.slice(1):n;if(S){if(C++,t===F)return!1}else N||=t===F}return N||C===S.length}function checkPlatform(t,n){let S=t.os?checkList(n.os,t.os):!0,C=t.cpu?checkList(n.cpu,t.cpu):!0,N=t.libc?checkList(n.libc,t.libc):!0;return t.libc&&!n.libc&&(N=!1),{ok:S&&C&&N,current:{os:n.os,cpu:n.cpu,libc:n.libc},required:{os:t.os,cpu:t.cpu,libc:t.libc}}}function declaresPlatform(t){return!!(t.os||t.cpu||t.libc)}function badPlatformError(t,n){let S=Error(`Unsupported platform for ${t}: wanted ${JSON.stringify(n.required)} (current: ${JSON.stringify(n.current)})`);return S.code=`EBADPLATFORM`,S.pkgid=t,S.current=n.current,S.required=n.required,S}function isMuslSharedObject(t){return t.includes(`libc.musl-`)||t.includes(`ld-musl-`)}function libcFromLddFile(t){let n=t.readTextFile(FL);if(n!==null)return n.includes(`musl`)?`musl`:n.includes(`GNU C Library`)?`glibc`:null}function libcFromReportData(t){return t.glibcVersionRuntime?`glibc`:Array.isArray(t.sharedObjects)&&t.sharedObjects.some(t=>isMuslSharedObject(String(t)))?`musl`:null}function libcFromLoaderScan(t,n=IL){let S=!1;for(let C of n){let n=t.listDir(C);if(n)for(let t of n){if(t.startsWith(`ld-linux`))return`glibc`;t.startsWith(`ld-musl-`)&&(S=!0)}}return S?`musl`:null}function detectLibc(t,n){if(t!==`linux`)return;let S=libcFromLddFile(n);if(S!==void 0)return S??void 0;let C=n.diagnosticReport();return C===null?libcFromLoaderScan(n)??void 0:libcFromReportData(C)??void 0}function defaultLibcProbeHost(){return{readTextFile(t){try{return readFileSync(t,`utf-8`)}catch{return null}},listDir(t){try{return readdirSync(t)}catch{return null}},diagnosticReport(){let t=process.report;if(!t||typeof t.getReport!=`function`)return null;let n=t.excludeNetwork;t.excludeNetwork=!0;try{let n=t.getReport();return{glibcVersionRuntime:n.header?.glibcVersionRuntime,sharedObjects:n.sharedObjects}}finally{t.excludeNetwork=n}}}}function hostLibc(t,n=defaultLibcProbeHost()){return RL||=(LL=detectLibc(t,n),!0),LL}function readPlatformOverrides(t){let pick=n=>{let S=t[n];if(typeof S!=`string`)return;let C=S.trim();return C===``?void 0:C},n={},S=pick(`npm_config_os`),C=pick(`npm_config_cpu`),N=pick(`npm_config_libc`);return S!==void 0&&(n.os=S),C!==void 0&&(n.cpu=C),N!==void 0&&(n.libc=N),n}function readPlatformForce(t){let n=t.npm_config_force;if(typeof n!=`string`)return!1;let S=n.trim().toLowerCase();return S===`true`||S===`1`}function resolveHostPlatform(t={}){let n=readPlatformOverrides(t.env??process.env),S=n.os??t.platform??process.platform;return{os:S,cpu:n.cpu??t.arch??process.arch,libc:n.libc??(S===`linux`?hostLibc(S,t.probe??defaultLibcProbeHost()):void 0)}}function describePlatformTarget(t){return`${t.os}-${t.cpu}${t.libc?`-${t.libc}`:``}`}var FL,IL,LL,RL,zL=__esmMin(()=>{Rd(),FL=`/usr/bin/ldd`,IL=[`/lib`,`/lib64`,`/usr/lib`],RL=!1});function isReservedEntry(t){return t.startsWith(`.`)}function readManifest(t){try{let n=JSON.parse(readFileSync(wn(t,`package.json`),`utf8`)),S={os:n.os,cpu:n.cpu,libc:n.libc};return{name:typeof n.name==`string`?n.name:void 0,version:typeof n.version==`string`?n.version:void 0,platform:declaresPlatform(S)?S:void 0,bundles:[n.bundleDependencies,n.bundledDependencies].some(t=>t===!0||Array.isArray(t)&&t.length>0)}}catch{return null}}function collect(t,n){let S;try{S=readdirSync(t,{withFileTypes:!0})}catch{return}for(let C of S){if(isReservedEntry(C.name))continue;let S=wn(t,C.name);if(C.name.startsWith(`@`)){let t;try{t=readdirSync(S,{withFileTypes:!0})}catch{continue}for(let C of t)isReservedEntry(C.name)||addPackage(wn(S,C.name),n);continue}addPackage(S,n)}}function addPackage(t,n){let S=!1;try{S=lstatSync(t).isSymbolicLink()}catch{return}let C=readManifest(t);n.push({name:C?.name??t,version:C?.version??`0.0.0`,dir:t,linked:S,platform:C?.platform,bundles:C?.bundles}),S||collect(wn(t,`node_modules`),n)}function scanPrefix(t){let n=[];return collect(wn(t,`node_modules`),n),n}function planPlatformPrune(t,n){let S=[];for(let C of t){if(C.linked||!C.platform)continue;let t=checkPlatform(C.platform,n);t.ok||S.push({pkg:C,bytes:0,verdict:t})}return S}function dirBytes(t){let n=0,S=[t];for(;S.length>0;){let t=S.pop(),C;try{C=readdirSync(t,{withFileTypes:!0})}catch{continue}for(let N of C){let C=wn(t,N.name);if(N.isDirectory())S.push(C);else if(N.isFile())try{n+=statSync(C).size}catch{}}}return n}function planPrune(t){let n=scanPrefix(t.prefix),S=planPlatformPrune(n,t.target);for(let t of S)t.bytes=dirBytes(t.pkg.dir);return{prefix:t.prefix,target:t.target,scanned:n.length,entries:S,bytes:S.reduce((t,n)=>t+n.bytes,0)}}function executePrune(t,n={}){let S=[],C=[],N=[],F=n.remove??(t=>rmSync(t,{recursive:!0,force:!0,maxRetries:10}));if(!n.dryRun){for(let n of t.entries)try{F(n.pkg.dir),S.push(n)}catch(t){C.push({entry:n,error:t.message})}N.push(...pruneDeadBinLinks(t.prefix))}return{plan:t,removed:S,failed:C,bytes:S.reduce((t,n)=>t+n.bytes,0),binLinks:N}}function pruneDeadBinLinks(t){let n=wn(t,`node_modules`,`.bin`),S=[],C;try{C=readdirSync(n,{withFileTypes:!0})}catch{return S}for(let t of C){let C=wn(n,t.name);try{if(!lstatSync(C).isSymbolicLink()||existsSync(C))continue;unlinkSync(C),S.push(t.name)}catch{}}return S}function humanBytes(t){if(t<1024)return`${t} B`;let n=[`KB`,`MB`,`GB`],S=t/1024,C=0;for(;S>=1024&&C<n.length-1;)S/=1024,C+=1;return`${S.toFixed(1)} ${n[C]}`}function formatPruneReport(t,n){let{plan:S}=t,C=[`${S.prefix} · target ${describePlatformTarget(S.target)} · scanned ${S.scanned} package(s)`];if(S.entries.length===0)return C.push(`nothing to prune — no installed package declares a platform this target cannot use.`),C.join(`
913
- `);let N=n.verbose?S.entries:S.entries.slice(0,BL);for(let t of N){let n=JSON.stringify(t.verdict.required);C.push(` ${t.pkg.name}@${t.pkg.version} ${humanBytes(t.bytes)} requires ${n}`)}N.length<S.entries.length&&C.push(` … and ${S.entries.length-N.length} more (--verbose to list them)`),C.push(n.dryRun?`would free ${humanBytes(S.bytes)} across ${S.entries.length} package(s) (apparent size)`:`freed ${humanBytes(t.bytes)} across ${t.removed.length} package(s) (apparent size)`),t.binLinks.length>0&&C.push(`removed ${t.binLinks.length} dangling .bin link(s): ${t.binLinks.join(`, `)}`);for(let n of t.failed)C.push(`FAILED ${n.entry.pkg.name}: ${n.error}`);return C.join(`
914
- `)}function automaticPruneRefusal(t,n){return Object.keys(readPlatformOverrides(t)).length>0?`the platform target was overridden on the command line`:n?`--immutable`:null}function pruneAfterInstall(t,n,S={}){try{if(automaticPruneRefusal(S.env??process.env,S.immutable??!1))return;let C=planPrune({prefix:t,target:n});if(C.entries.length===0)return;let N=executePrune(C);if(N.removed.length===0)return;let F=S.hint?` (${S.hint} to review)`:``;ge.log(`gjsify: pruned ${N.removed.length} package(s) this host cannot use, freeing ${humanBytes(N.bytes)}${F}`)}catch(t){process.env.GJSIFY_DEBUG&&ge.error(`gjsify: prune skipped — ${t.message}`)}}var BL,VL=__esmMin(()=>{_e(),Rd(),Pn(),zL(),BL=10});function devLinkPath(t){return wn(t,HL)}function readDevLinkOverride(t){let n=devLinkPath(t);if(!existsSync(n))return null;let S;try{S=JSON.parse(readFileSync(n,`utf-8`))}catch(t){throw Error(`gjsify link: ${n} is not valid JSON (${t instanceof Error?t.message:String(t)}). Fix it or run \`gjsify unlink\`.`)}if(!S||typeof S!=`object`)throw Error(`gjsify link: ${n} must contain a JSON object.`);let C=S;if(C.version!==1)throw Error(`gjsify link: ${n} declares version ${JSON.stringify(C.version)}; this CLI understands version 1 only.`);if(typeof C.checkout!=`string`||C.checkout.trim()===``)throw Error(`gjsify link: ${n} has no "checkout" path.`);return{version:1,checkout:Cn(C.checkout)?C.checkout:xn(t,C.checkout),packages:Array.isArray(C.packages)?C.packages.filter(t=>typeof t==`string`):[]}}function writeDevLinkOverride(t,n){let S=devLinkPath(t);return writeFileSync(S,JSON.stringify(n,null,2)+`
909
+ "dependencies": { "@gjsify/node-gi": "^0.13.0" }`);let{env:I,envPrefix:H}=computeNativeEnvForBundle(F,N),W={...process.env,...I},[,q]=U_[t].launch(F,S),Y=t===`node`?nodeBinary():U_[t].probe,X=[Y,...q.map(t=>t.includes(` `)?`"${t}"`:t)].join(` `);C.quiet||ge.error(`$ ${H?`${H} `:``}${X}`);let failed=t=>(process.exitCode=t,process.exit(t)),Z;try{Z=await spawnToCompletion(Y,q,{completion:C.completion,env:W})}catch(t){return ge.error(t.message),failed(1)}if(Z.code!==0)return C.quietExit||ge.error(`${t} exited with ${describeExit(Z)}`),failed(Z.code??1);if(C.exitOnSuccess)return process.exit(0)}var rL=__esmMin(()=>{_e(),Rd(),Pn(),d_(),tL(),W_(),V_()});function nearestNodeModules(t){let n=xn(t);for(;;){let t=wn(n,`node_modules`);if(existsSync(t))return t;let S=En(n);if(S===n)return null;n=S}}async function rebuildForGjs(t,n,S){let C=t.nodeModules??nearestNodeModules(process.cwd())??wn(t.pkgDir,`node_modules`),N=findProjectLockfile(En(C)),F=execCacheKey({pkgName:t.pkgName,pkgVersion:t.pkgVersion,entry:entryWithinPackage(t,n),cliVersion:cliVersion(),lockfileHash:N?hashFile(N):null}),I=execArtifactPath(execCacheRoot(C),t,n,t.installed?F:`local`),H=t.installed&&!S.rebuild;if(H&&existsSync(I))return S.verbose&&ge.error(`gjsify exec: reusing ${I}`),I;ge.error(`gjsify exec: rebuilding ${t.pkgName}@${t.pkgVersion} "${t.binName}" for GJS…`);let W=En(I),q=`${W}.tmp-${process.pid.toString(16)}-${Date.now().toString(16)}`,Y=wn(q,Dn(I));try{let{BuildAction:C}=await Promise.resolve().then(()=>(DI(),wI));await C.bundleFileForGjs(n,Y,{verbose:S.verbose,preserveDefaultExport:!1,...t.installed?{}:{define:{"import.meta.url":JSON.stringify(pathToFileURL(n).href)}},toolchainAnchor:C.runningCliFile(),...S.verbose?{}:{logLevel:`silent`}})}catch(C){throw rmSync(q,{recursive:!0,force:!0}),new ExecRebuildError(t,n,C,S.verbose)}if(H&&existsSync(I))return rmSync(q,{recursive:!0,force:!0}),I;rmSync(W,{recursive:!0,force:!0});try{renameSync(q,W)}catch(t){if(rmSync(q,{recursive:!0,force:!0}),!existsSync(I))throw t}return pruneStaleArtifacts(En(W),t,Dn(W)),I}function pruneStaleArtifacts(t,n,S){let C=`${n.pkgName}@${n.pkgVersion}`.replace(/[^a-zA-Z0-9._@-]/g,`_`),N;try{N=readdirSync(t)}catch{return}for(let n of N)n===S||!n.startsWith(`${C}-`)||n.includes(`.tmp-`)||rmSync(wn(t,n),{recursive:!0,force:!0})}var ExecRebuildError,iL,aL=__esmMin(()=>{_e(),Rd(),Pn(),Gn(),d_(),RI(),XI(),nh(),tL(),rL(),ExecRebuildError=class extends Error{constructor(t,n,S,C){let N=S instanceof Error?S.message:String(S);super(`gjsify exec: rebuilding "${t.binName}" (${t.pkgName}@${t.pkgVersion}) for GJS failed.\n entry: ${n}\nNothing was run — gjsify exec never falls back to another runtime on its own. To run it on Node explicitly: \`gjsify exec --runtime node ${t.binName}\`.\n`+(C?``:`Re-run with \`gjsify exec --verbose ${t.binName}\` for the bundler's warnings.\n`)+`Bundler diagnostics:\n${N}`,{cause:S}),this.name=`ExecRebuildError`}},iL={command:`exec <entries..>`,description:"Run an installed npm bin on the runtime gjsify runs on: `gjsify exec [--runtime gjs|node|bun|deno] [--rebuild] [--verbose] <bin> [args…]`. On Node/Bun/Deno the bin runs unchanged; on GJS it is rebuilt `--app gjs` once, cached under node_modules/.cache/gjsify/exec/, and run with gjs. Options go BEFORE the bin; everything after it is the bin's own.",builder:t=>t.positional(`entries`,{description:`gjsify exec options, then the bin name and its arguments.`,type:`string`,array:!0}).version(!1).help(!1).parserConfiguration({"populate--":!0,"parse-positional-numbers":!1,"unknown-options-as-args":!0}),handler:async t=>{let n,S,C;try{n=splitExecArgv(t.entries??[],doubleDashArgs(t)),S=resolveExecBin(n.bin,process.cwd()),C=planExec(S,n.runtime??hostRuntime$1())}catch(t){if(t instanceof ExecBinNotFoundError)return ge.error(t.message),process.exit(127);if(t instanceof ExecPlanError)return ge.error(t.message),process.exit(1);throw t}let N={completion:`exit`,exitOnSuccess:!0,quiet:!n.verbose,quietExit:!0};if(C.kind===`direct`){await runRuntimeBundle(C.runtime,C.file,n.args,N);return}if(C.kind===`gjs-bundle`){await runGjsBundle(C.file,n.args,N);return}let F=await rebuildForGjs(S,C.entry,{rebuild:n.rebuild,verbose:n.verbose}),I=cliPackageDir();await runGjsBundle(F,n.args,{...N,nativeRoots:I?[I]:[]})}}});function bundleInputsPath(t){return`${t}.inputs.json`}function idToPath(t){if(t===``||t.startsWith(`\0`))return null;let n=t.search(/[?#]/);if(n===-1)return t;let S=t.slice(0,n);return isFile(S)?S:t}function isFile(t){try{return statSync(t).isFile()}catch{return!1}}function isToolchainScratch(t){return t.includes(`${jn}node_modules${jn}.cache${jn}`)}function resolutionFilesFor(t){let n=[];for(let S=En(t);;S=En(S)){let t=wn(S,`package.json`);if(existsSync(t)){n.push(t);let C=wn(S,`tsconfig.json`);return existsSync(C)&&n.push(C),n}if(En(S)===S)return n}}function createBundleInputsRecorder(t){let n=new Set,S=!0,record=t=>{let S=idToPath(t);S!==null&&n.add(S)},C={name:`gjsify:bundle-inputs`,transform(t,n){record(n)}},inputs=()=>{let t=[],S=new Set;for(let C of n){let n;try{n=statSync(C).isFile()}catch{continue}if(!n||isToolchainScratch(C))continue;t.push(C);let N=En(C);if(!S.has(N)){S.add(N);for(let n of resolutionFilesFor(C))t.push(n)}}return[...new Set(t)].sort()};return{plugin:C,addWatchFiles(t){t.reportedByEngine||(S=!1);for(let n of t.files)record(n)},inputs,write(){let n=bundleInputsPath(t),C={version:2,inputs:inputs(),watchList:S},N=`${n}.tmp`;try{mkdirSync(En(n),{recursive:!0}),writeFileSync(N,`${JSON.stringify(C,null,2)}\n`,`utf-8`),renameSync(N,n)}catch(t){try{rmSync(N,{force:!0})}catch{}ge.warn(`[gjsify test] could not record the build inputs beside ${n} (${t.message}) — the next run judges freshness by the package walk alone, which cannot see outside this package.`)}}}}function readBundleInputs(t){let n;try{n=JSON.parse(readFileSync(bundleInputsPath(t),`utf-8`))}catch{return null}return n?.version!==2||!Array.isArray(n.inputs)?null:{inputs:n.inputs.filter(t=>typeof t==`string`),watchList:n.watchList===!0}}function newestBundleInputMtimeMs(t){let n=0;for(let S of t)try{let{mtimeMs:t}=statSync(S);t>n&&(n=t)}catch{return 1/0}return n}var oL=__esmMin(()=>{_e(),Rd(),Pn()});async function buildTestBundle(t,n,S,C){let N=await new Config().forBuild({entryPoints:[t],outfile:n,app:S,verbose:C??!1,logLevel:`warning`,exclude:[]});N.library={...N.library};let F=createBundleInputsRecorder(n);N.bundler={...N.bundler,input:[t],output:{...N.bundler?.output,file:n},plugins:[...N.bundler?.plugins??[],F.plugin]},await new EI(N).start({app:S,library:!1,onWatchFiles:t=>F.addWatchFiles(t)}),F.write()}async function runTestBundle(t,n){if(n===`gjs`){await runGjsBundle(t,[],{completion:`exit`});return}let S=await spawnToCompletion(nodeBinary(),[t],{completion:`exit`});if(S.code!==0)throw Error(`node exited with ${describeExit(S)}`)}function isFresh(t,n,S,C){if(!existsSync(t))return!1;try{let N=statSync(t).mtimeMs,F=[],I=Tn(S,C).split(jn).join(`/`);I!==``&&!I.startsWith(`../`)&&F.push(I);let H=readBundleInputs(t);return H!==null&&!H.watchList?!1:N>=Math.max(newestInputMtimeMs(packageBuildInputs(S,{extraOutputs:F})),H===null?0:newestBundleInputMtimeMs(H.inputs),statSync(n).mtimeMs,newestDepSignalMtimeMs(S))}catch{return!1}}var sL,cL=__esmMin(()=>{_e(),Rd(),Pn(),oL(),CI(),W_(),rL(),V_(),AI(),DI(),tL(),sL={command:`test`,description:"Build + run the package’s `src/test.mts` suite on GJS and Node and aggregate the results. Replaces the per-package `build:test:{gjs,node}` + `test:{gjs,node}` script boilerplate.",builder:t=>t.option(`runtime`,{description:`Target runtime. Default: both.`,type:`string`,choices:[`gjs`,`node`,`all`],default:`all`}).option(`entry`,{description:"Path to the test entry. Default: `src/test.mts` (or `gjsify.test.entry`).",type:`string`,normalize:!0}).option(`outdir`,{description:"Output directory for the built test bundles. Default: `dist/`.",type:`string`,normalize:!0}).option(`rebuild`,{description:`Always rebuild the test bundles, even when they look up-to-date.`,type:`boolean`,default:!1}).option(`build`,{description:`Build before running. Default: true (use --no-build to skip when bundles already exist).`,type:`boolean`,default:!0}).option(`verbose`,{description:`Print resolved entry/outdir + per-step timing.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=(await new Config().forBuild({}).catch(()=>({}))).test??{},C=xn(n,t.entry??S.entry??`src/test.mts`),N=xn(n,t.outdir??S.outdir??`dist`);if(!existsSync(C))return ge.error(`[gjsify test] no test entry at ${Tn(n,C)} — add an \`src/test.mts\` that aggregates your \`@gjsify/unit\` suites, or set \`gjsify.test.entry\` in package.json.`),process.exit(1);let F=t.runtime===`gjs`||t.runtime===`node`,I=t.runtime===`gjs`?[`gjs`]:t.runtime===`node`?[`node`]:S.runtimes&&S.runtimes.length>0?S.runtimes:[`gjs`,`node`],H=F?I:I.filter(t=>isRuntimeAvailable(t));for(let t of I.filter(t=>!H.includes(t)))ge.log(`[gjsify test] skipping ${t} — no \`${U_[t].probe}\` on PATH (not requested explicitly)`);if(H.length===0)return ge.error(`[gjsify test] none of the default runtimes (${I.join(`, `)}) is available on this host.\n Install one, or pin the set: \`gjsify test --runtime <rt>\` / \`gjsify.test.runtimes\` in package.json.`),process.exit(1);let W=[];for(let S of H){let F=wn(N,`test.${S}.mjs`);if(t.build!==!1)if(t.rebuild||!isFresh(F,C,n,N)){let N=Date.now();t.verbose&&ge.log(`[gjsify test] building → ${Tn(n,F)} (—app ${S})`);try{await buildTestBundle(C,F,S,t.verbose),t.verbose&&ge.log(`[gjsify test] built ${S} in ${Date.now()-N}ms`)}catch(t){ge.error(`[gjsify test] build failed for ${S}:`,t.message),W.push({runtime:S,ok:!1,durationMs:0,error:`build failed`});continue}}else t.verbose&&ge.log(`[gjsify test] ${S}: bundle is up-to-date — skipping build (use --rebuild to force)`);else if(!existsSync(F)){ge.error(`[gjsify test] --no-build but ${Tn(n,F)} doesn't exist. Build first or drop --no-build.`),W.push({runtime:S,ok:!1,durationMs:0,error:`no bundle`});continue}let I=Date.now();try{await runTestBundle(F,S),W.push({runtime:S,ok:!0,durationMs:Date.now()-I})}catch(t){W.push({runtime:S,ok:!1,durationMs:Date.now()-I,error:t.message})}}let q=W.map(t=>`${t.ok?`✅`:`❌`} ${t.runtime} (${t.durationMs}ms)${t.error?` — ${t.error}`:``}`).join(` `);if(ge.log(`[gjsify test] ${q}`),W.some(t=>!t.ok))return process.exit(1);process.exit(0)}}});function readPackageJson$1(t){if(!existsSync(t))return null;let n=readFileSync(t,`utf-8`);try{return JSON.parse(n)}catch(n){throw Error(`gjsify install: ${t} is not valid JSON: ${n.message}`)}}function writePackageJson(t,n){let S=sortKnownDepFields(n);writeFileSync(t,JSON.stringify(S,null,2)+`
910
+ `,`utf-8`)}function parseSpec$2(t){if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)return{name:t};let S=t.indexOf(`@`,n+1);return S===-1?{name:t}:{name:t.slice(0,S),range:t.slice(S+1)}}let n=t.indexOf(`@`);return n===-1?{name:t}:{name:t.slice(0,n),range:t.slice(n+1)}}function projectSpecsFromPackageJson(t){let n=[];for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=t[S];if(C)for(let[t,S]of Object.entries(C))typeof S==`string`&&(/^(workspace|link|file|portal|git\+|https?):/.test(S)||n.push(`${t}@${S}`))}return n}function addDependencyEntry(t,n,S,C){t[C]===void 0&&(t[C]={}),t[C][n]=S}function defaultRangeFromVersion(t){return`^${t}`}function sortKnownDepFields(t){let n={...t};for(let t of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let S=n[t];S&&(n[t]=Object.fromEntries(Object.entries(S).sort(([t],[n])=>t<n?-1:+(t>n))))}return n}var lL=__esmMin(()=>{Rd(),__name$1(readPackageJson$1,`readPackageJson`),__name$1(parseSpec$2,`parseSpec`)});function scriptCacheEnabled(){let t=process.env.GJSIFY_NODE_SCRIPT_CACHE;return t===`1`||t===`true`||t===`yes`}async function runNodeScript(t,n=[],S){let C=xn(t);if(!existsSync(C)||!statSync(C).isFile())return ge.error(`gjsify run --node-script: no such file: ${C}`),process.exit(1);let N=hostRuntime$1();if(N!==`gjs`){await runRuntimeBundle(N,C,n,{completion:S.completion,exitOnSuccess:S.exitOnSuccess,quiet:!0});return}let{BuildAction:F}=await Promise.resolve().then(()=>(DI(),wI)),{globals:I,excludeGlobals:H}=await new Config().forNodeScript(C),W;try{W=await F.bundleFileForGjsCached(C,{cacheSubdir:`node-scripts`,label:Dn(C),cache:scriptCacheEnabled(),preserveDefaultExport:!1,define:{"import.meta.url":JSON.stringify(pathToFileURL(C).href)},globals:I,excludeGlobals:H,resolveFromToolchain:!0})}catch(t){throw Error(`gjsify run --node-script: failed to bundle ${C} for GJS. The script must import only what gjsify can provide under GJS (node: builtins, workspace packages, pure-JS npm deps). (${t.message})`)}await runGjsBundle(W,n,{completion:S.completion,exitOnSuccess:S.exitOnSuccess,quiet:!0})}var uL=__esmMin(()=>{_e(),Rd(),Pn(),Gn(),d_(),AI(),tL(),rL()});function gjsifyCacheRoot(t,n){let S=process.env.XDG_CACHE_HOME;return wn(S&&S.length>0?S:wn(homedir(),`.cache`),`gjsify`,t,n)}function atomicWrite(t,n){try{atomicWriteStrict(t,n)}catch{}}function atomicWriteStrict(t,n){mkdirSync(wn(t,`..`),{recursive:!0});let S=`${t}.tmp.${process.pid}`;writeFileSync(S,n),renameSync(S,t)}function readCacheFile(t){if(!existsSync(t))return null;try{let n=readFileSync(t);return n.length===0?null:n}catch{return null}}var dL=__esmMin(()=>{Rd(),Lg(),Pn()});function makeProgressReporter(t={}){if(t.enabled===!1)return pL;let n=t.stream??process.stderr,S=!!n.isTTY;return t.enabled??!0?S?makeTtyReporter(n):makePlainReporter(n):pL}function makeTtyReporter(t){let n=0,S=``;function render(C,N=!1){let F=Date.now();!N&&F-n<33&&C===S||(n=F,S=C,t.write(`\r\x1B[2K`+C))}function clearLine(){t.write(`\r\x1B[2K`),S=``}return{beginPhase(n,S){render(formatBar(n,0,S,void 0,t.columns??80),!0)},update(n){render(formatBar(n.phase,n.current,n.total,n.name,t.columns??80))},endPhase(n){let S=fL[n];clearLine(),t.write(`gjsify install: ${S} done\n`)}}}function makePlainReporter(t){let n=0,S=0;return{beginPhase(C,N){n=Date.now(),S=0,t.write(`gjsify install: ${fL[C]} ${N} package(s)\n`)},update(C){let N=Date.now();if(N-n<mL||C.current<=S)return;n=N,S=C.current;let F=C.total>0?Math.round(C.current/C.total*100):0;t.write(`gjsify install: ${fL[C.phase]} ${C.current}/${C.total} (${F}%)\n`)},endPhase(n){t.write(`gjsify install: ${fL[n]} done\n`)}}}function formatBar(t,n,S,C,N){let F=fL[t],I=S>0?Math.min(1,n/S):0,H=`${n}/${S}`,W=`gjsify install: ${F} `,q=` ${H}`+(C?` ${C}`:``),Y=Math.max(8,Math.min(40,N-W.length-q.length-4)),X=Math.round(I*Y),Z=`█`.repeat(X)+`░`.repeat(Y-X),te=`${W}[${Z}]${q}`;if(te.length>N){let t=te.length-N+1,n=C&&C.length>t?C.slice(0,C.length-t-1)+`…`:``;te=`${W}[${Z}] ${H}${n?` `+n:``}`}return te}var fL,pL,mL,hL=__esmMin(()=>{fL={resolve:`resolving`,download:`downloading`,extract:`extracting`,link:`linking bins`},pL={update(){},beginPhase(){},endPhase(){}},mL=5e3});function parseTar(t){let n=[],S=null,C=null,N=null,F=0;for(;F+512<=t.length;){let I=t.subarray(F,F+512);if(allZeros(I)){let n=t.subarray(F+512,F+2*512);if(n.length===512&&allZeros(n))break;F+=512;continue}if(!validateChecksum(I))throw new TarParseError(`Bad header checksum at offset ${F} — file is not a valid tar archive`);let H=readString(I,0,100),W=parseOctal(I,100,8),q=parseOctal(I,124,12),Y=parseOctal(I,136,12),X=String.fromCharCode(I[156]||0),Z=readString(I,157,100),te=readString(I,257,6),ne=readString(I,345,155),re=readString(I,265,32),ie=readString(I,297,32);F+=512;let ae=t.subarray(F,F+q);if(F+=alignToBlock(q),X===`x`){S=parsePaxRecords(ae);continue}if(X===`g`)continue;if(X===`L`){C=bytesToString(ae).replace(/\0+$/,``);continue}if(X===`K`){N=bytesToString(ae).replace(/\0+$/,``);continue}let oe=H;te===`ustar`&&ne!==``&&(oe=`${ne}/${H}`),C!==null&&(oe=C,C=null);let Q=Z;if(N!==null&&(Q=N,N=null),S!==null){let C=S.get(`path`);C!==void 0&&(oe=C);let N=S.get(`linkpath`);N!==void 0&&(Q=N);let I=S.get(`size`);if(I!==void 0){let C=Number(I);if(Number.isFinite(C)){let N=F-alignToBlock(q),I=t.subarray(N,N+C);F=N+alignToBlock(C),S=null,n.push(buildEntry(oe,Q,X,W,Y,re,ie,I));continue}}S=null}n.push(buildEntry(oe,Q,X,W,Y,re,ie,ae))}return n}function buildEntry(t,n,S,C,N,F,I,H){return{name:t,linkname:n,type:typeflagToType(S,t),mode:C,mtime:N,body:H,uname:F,gname:I}}function typeflagToType(t,n){switch(t){case`0`:case`\0`:case``:return n.endsWith(`/`)?`directory`:`file`;case`1`:return`hardlink`;case`2`:return`symlink`;case`5`:return`directory`;case`x`:return`pax-header`;case`g`:return`pax-global`;case`L`:return`gnu-longname`;case`K`:return`gnu-longlink`;default:return`unknown`}}function parsePaxRecords(t){let n=new Map,S=0;for(;S<t.length;){let C=S;for(;C<t.length&&t[C]!==32;)C++;if(C>=t.length)break;let N=bytesToString(t.subarray(S,C)),F=Number(N);if(!Number.isFinite(F)||F<=0)break;let I=S+F;if(I>t.length)break;let H=bytesToString(t.subarray(C+1,I-1)),W=H.indexOf(`=`);if(W>0){let t=H.slice(0,W),S=H.slice(W+1);n.set(t,S)}S=I}return n}function readString(t,n,S){let C=n,N=n+S;for(;C<N&&t[C]!==0;)C++;return bytesToString(t.subarray(n,C))}function bytesToString(t){return new TextDecoder(`utf-8`,{fatal:!1}).decode(t)}function parseOctal(t,n,S){if(S>0&&t[n]&128){let C=t[n]&127;for(let N=1;N<S;N++)C=C*256+t[n+N];return C}let C=``;for(let N=0;N<S;N++){let S=t[n+N];S===0||S===32||(C+=String.fromCharCode(S))}return C===``?0:parseInt(C,8)}function alignToBlock(t){return Math.ceil(t/512)*512}function allZeros(t){for(let n=0;n<t.length;n++)if(t[n]!==0)return!1;return!0}function validateChecksum(t){let n=parseOctal(t,148,8),S=0,C=0;for(let n=0;n<512;n++){let N=n>=148&&n<156?32:t[n];S+=N,C+=N>127?N-256:N}return n===S||n===C}var TarParseError,gL=__esmMin(()=>{TarParseError=class extends Error{constructor(t){super(t),this.name=`TarParseError`}}});function createTarball(t){let n=[];for(let S of t){if(`directory`in S&&S.directory===!0){n.push(buildHeader$1(ensureTrailingSlash(S.name),0,`5`,S.mode??493,S.mtime??0));continue}let t=S,C=typeof t.body==`string`?new TextEncoder().encode(t.body):t.body,N=t.mode??defaultFileMode(C);n.push(buildHeader$1(t.name,C.byteLength,`0`,N,t.mtime??0)),n.push(C);let F=padTo512(C.byteLength);F>0&&n.push(new Uint8Array(F))}return n.push(new Uint8Array(512*2)),concatChunks(n)}function buildHeader$1(t,n,S,C,N){let{prefix:F,basename:I}=splitPathForUstar(t),H=new Uint8Array(512);writeAscii(H,I,0,100),writeOctal(H,C&4095,100,7),H[107]=0,writeOctal(H,0,108,7),H[115]=0,writeOctal(H,0,116,7),H[123]=0,writeOctal(H,n,124,11),H[135]=0,writeOctal(H,N,136,11),H[147]=0;for(let t=148;t<156;t++)H[t]=32;H[156]=S.charCodeAt(0),writeAscii(H,`ustar\0`,257,6),writeAscii(H,`00`,263,2),F&&writeAscii(H,F,345,155);let W=0;for(let t=0;t<512;t++)W+=H[t];return writeAscii(H,W.toString(8).padStart(6,`0`),148,6),H[154]=0,H[155]=32,H}function splitPathForUstar(t){if(t.length<=100)return{prefix:``,basename:t};if(t.length>255)throw Error(`createTarball: path too long (${t.length} > 255 chars): ${t}`);for(let n=Math.min(t.length-1,155);n>0;n--)if(t[n]===`/`&&t.length-n-1<=100)return{prefix:t.slice(0,n),basename:t.slice(n+1)};throw Error(`createTarball: cannot split path into ustar prefix+basename (basename slot is 100 chars): ${t}`)}function writeAscii(t,n,S,C){let N=new TextEncoder().encode(n);if(N.length>C)throw Error(`createTarball: field too long (${N.length} > ${C}): "${n}"`);t.set(N,S)}function writeOctal(t,n,S,C){writeAscii(t,n.toString(8).padStart(C,`0`),S,C)}function padTo512(t){let n=t%512;return n===0?0:512-n}function ensureTrailingSlash(t){return t.endsWith(`/`)?t:`${t}/`}function defaultFileMode(t){return t.length>=2&&t[0]===35&&t[1]===33?493:420}function concatChunks(t){let n=0;for(let S of t)n+=S.byteLength;let S=new Uint8Array(n),C=0;for(let n of t)S.set(n,C),C+=n.byteLength;return S}var _L=__esmMin(()=>{__name$1(buildHeader$1,`buildHeader`)});async function extractTarball(t,n,S={}){let C=t instanceof Uint8Array?t:new Uint8Array(t),N=parseTar(S.gzip??(C.length>=2&&C[0]===31&&C[1]===139)?await gunzip(C):C);mkdirSync(n,{recursive:!0});let F=S.strip??1,I=S.preventEscape??!0,H={files:[],directories:[],symlinks:[],skipped:0};for(let t of N){let C=stripComponents(t.name,F);if(C===null||C===``){H.skipped++;continue}let N=xn(n,C);if(I&&!isInside$2(N,n))throw Error(`tar: refusing to extract ${t.name} outside ${n} (resolved=${N})`);if(S.filter&&!S.filter(t,N)){H.skipped++;continue}if(t.type===`directory`){mkdirSync(N,{recursive:!0}),H.directories.push(N);continue}if(t.type===`file`){mkdirSync(En(N),{recursive:!0}),writeFileSync(N,t.body);let n=S.chmod?.(t,N)??t.mode&511;if(n>0)try{chmodSync(N,n)}catch{}H.files.push(N);continue}if(t.type===`symlink`){mkdirSync(En(N),{recursive:!0});try{symlinkSync(t.linkname,N),H.symlinks.push(N)}catch{writeFileSync(N,t.linkname),H.files.push(N)}continue}H.skipped++}return H}async function gunzip(t){let n=globalThis.DecompressionStream;if(typeof n!=`function`)throw Error(`@gjsify/tar: globalThis.DecompressionStream is not available — import '@gjsify/compression-streams/register' on GJS to register it`);return drainStream(new Blob([new Uint8Array(t)]).stream().pipeThrough(new n(`gzip`)))}async function gzip(t,n){if(n?.level!==void 0){let{gzipSync:S}=await Promise.resolve().then(()=>(ua(),oa));return new Uint8Array(S(t,{level:n.level}))}let S=globalThis.CompressionStream;if(typeof S!=`function`)throw Error(`@gjsify/tar: globalThis.CompressionStream is not available — import '@gjsify/compression-streams/register' on GJS to register it`);return drainStream(new Blob([new Uint8Array(t)]).stream().pipeThrough(new S(`gzip`)))}async function drainStream(t){let n=[],S=0,C=t.getReader();for(;;){let{value:t,done:N}=await C.read();if(N)break;let F=t instanceof Uint8Array?t:new Uint8Array(t);n.push(F),S+=F.length}let N=new Uint8Array(S),F=0;for(let t of n)N.set(t,F),F+=t.length;return N}function stripComponents(t,n){if(n<=0)return t;let S=t.split(`/`).filter(t=>t!==``);return S.length<=n?null:S.slice(n).join(`/`)}function isInside$2(t,n){let S=Tn(n,t);return S!==``&&!S.startsWith(`..`)&&!Cn(S)}var vL=__esmMin(()=>{gL(),Rd(),Pn(),__name$1(isInside$2,`isInside`)}),yL=__exportAll$5({BLOCK_SIZE:()=>512,TarParseError:()=>TarParseError,createTarball:()=>createTarball,extractTarball:()=>extractTarball,gunzip:()=>gunzip,gzip:()=>gzip,parseTar:()=>parseTar}),bL=__esmMin(()=>{gL(),_L(),vL()});function isPidAlive(t){if(existsSync(`/proc/self`))return existsSync(`/proc/${t}`);try{return process.kill(t,0),!0}catch(t){return t.code!==`ESRCH`}}function parsePsPidPpid(t){let n=new Map;for(let S of t.split(`
911
+ `)){let t=/^\s*(\d+)\s+(\d+)\s*$/.exec(S);if(!t)continue;let C=Number(t[1]),N=Number(t[2]);if(C<=0||N<=0||C===N)continue;let F=n.get(N);F?F.push(C):n.set(N,[C])}return n}function readProcChildren(t){let n;try{n=readdirSync(`/proc/${t}/task`)}catch{return null}let S=[],C=!1;for(let N of n)try{let n=readFileSync(`/proc/${t}/task/${N}/children`,`utf-8`);C=!0;for(let t of n.trim().split(/\s+/)){let n=Number(t);Number.isInteger(n)&&n>0&&S.push(n)}}catch{}return C?S:null}function procPpidMap(){let t=new Map,n=[];try{n=readdirSync(`/proc`)}catch{return t}for(let S of n){let n=Number(S);if(!(!Number.isInteger(n)||n<=0))try{let S=readFileSync(`/proc/${n}/stat`,`utf-8`),C=S.slice(S.lastIndexOf(`)`)+2).split(` `),N=Number(C[1]);if(!Number.isInteger(N)||N<=0)continue;let F=t.get(N);F?F.push(n):t.set(N,[n])}catch{}}return t}function osPpidMap(){let[t,n]=process.platform===`win32`?[`powershell.exe`,[`-NoProfile`,`-NonInteractive`,`-Command`,`Get-CimInstance Win32_Process | ForEach-Object { "$($_.ProcessId) $($_.ParentProcessId)" }`]]:[`ps`,[`-A`,`-o`,`pid=,ppid=`]];try{let S=spawnSync(t,n,{encoding:`utf-8`});return S.status!==0||typeof S.stdout!=`string`?new Map:parsePsPidPpid(S.stdout)}catch{return new Map}}function collectDescendants(t){let n=[],S=new Set([t]),C=[t],N=null;for(;C.length>0;){let t=C.shift(),F=N?null:readProcChildren(t);F===null&&(N||(N=procPpidMap(),N.size===0&&(N=osPpidMap())),F=N.get(t)??[]);for(let t of F)S.has(t)||(S.add(t),n.push(t),C.push(t))}return n}var xL=__esmMin(()=>{P_(),Rd()});function staleMs(){let t=process.env.GJSIFY_INSTALL_LOCK_STALE_MS;if(t!==void 0){let n=Number(t);if(Number.isFinite(n)&&n>0)return n}return wL}function lockingDisabled(){let t=process.env.GJSIFY_INSTALL_LOCK;if(t===void 0)return!1;let n=t.trim();return n===`0`||n===`false`}function mtimeMs(t){try{return statSync(t).mtimeMs}catch{return null}}function assessLock(t){let n=wn(t,CL),S=null;try{S=JSON.parse(readFileSync(n,`utf-8`))}catch{S=null}let C=Date.now();if(S&&typeof S.pid==`number`){if(!isPidAlive(S.pid))return{stale:!0,reason:`owner pid ${S.pid} is gone`,ownerPid:S.pid};let t=typeof S.startedAt==`number`?S.startedAt:mtimeMs(n);return t!==null&&C-t>staleMs()?{stale:!0,reason:`owner pid ${S.pid} exceeded the ${staleMs()}ms staleness budget`,ownerPid:S.pid}:{stale:!1,ownerPid:S.pid}}let N=mtimeMs(t);return N===null?{stale:!1}:C-N>TL?{stale:!0,reason:`no owner recorded within the acquire grace period`}:{stale:!1}}function stealStaleLock(t){let n=`${t}.stale-${process.pid}-${++kL}`;try{renameSync(t,n)}catch{return!1}try{rmSync(n,{recursive:!0,force:!0})}catch{}return!0}function abortErr(t){let n=t&&`reason`in t?t.reason:void 0;if(n instanceof Error)return n;let S=Error(`Aborted`);return S.name=`AbortError`,S}function delay(t,n){return t<=0?Promise.resolve():new Promise((S,C)=>{let onAbort=()=>{clearTimeout(N),C(abortErr(n))},N=setTimeout(()=>{n?.removeEventListener?.(`abort`,onAbort),S()},t);if(n?.aborted){clearTimeout(N),C(abortErr(n));return}n?.addEventListener?.(`abort`,onAbort,{once:!0})})}function makeHandle(t){let n=!1;return{release(){if(n)return;n=!0;let S=OL.get(t);if(S&&(S.count--,!(S.count>0))){OL.delete(t);try{let n=JSON.parse(readFileSync(wn(t,CL),`utf-8`));if(n.nonce!==void 0&&n.nonce!==S.nonce)return}catch{}try{rmSync(t,{recursive:!0,force:!0})}catch{}}}}}async function acquireInstallLock(t,n={}){if(lockingDisabled())return{release(){}};let S;try{S=realpathSync(t)}catch{S=xn(t)}let C=wn(S,`node_modules`,SL),N=OL.get(C);if(N)return N.count++,makeHandle(C);mkdirSync(En(C),{recursive:!0});let F=`${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}`,I=EL,H=!1;for(;;){if(n.signal?.aborted)throw abortErr(n.signal);try{return mkdirSync(C),writeFileSync(wn(C,CL),JSON.stringify({pid:process.pid,nonce:F,startedAt:Date.now()})),OL.set(C,{count:1,nonce:F}),makeHandle(C)}catch(t){if(t.code!==`EEXIST`)throw t}let t=assessLock(C);if(t.stale){stealStaleLock(C)&&ge.warn(`gjsify install: removed stale install lock (${t.reason}) — ${C}`);continue}if(!H){H=!0;let n=t.ownerPid===void 0?``:` (pid ${t.ownerPid})`;ge.warn(`gjsify install: waiting for a concurrent install${n} to release ${C} …`)}await delay(I,n.signal),I=Math.min(Math.round(I*1.6),DL)}}var SL,CL,wL,TL,EL,DL,OL,kL,AL=__esmMin(()=>{_e(),Rd(),Pn(),xL(),SL=`.gjsify-install-lock`,CL=`owner.json`,wL=35*6e4,TL=15e3,EL=150,DL=1e3,OL=new Map,kL=0});function cacheRoot$1(){return gjsifyCacheRoot(`tarballs`,jL)}function parseSri$1(t){if(!t)return null;let n=t.indexOf(`-`);if(n<=0||n===t.length-1)return null;let S=t.slice(0,n),C=t.slice(n+1).replace(/=+$/,``),N=$e.from(C,`base64`).toString(`hex`);return N.length<4?null:{algorithm:S,hex:N}}function pathFor$3(t){let n=parseSri$1(t);if(!n)return null;let S=n.hex.slice(0,2);return wn(cacheRoot$1(),n.algorithm,S,`${n.hex}.tgz`)}async function getCachedTarball(t){let n=pathFor$3(t);if(!n||!t)return null;let S=readCacheFile(n);if(!S)return null;if(await verifyIntegrity(S,t))return S;try{unlinkSync(n)}catch{}return null}function putCachedTarball(t,n){let S=pathFor$3(t);S&&(existsSync(S)||atomicWrite(S,n))}function npmCacacheContentDir(){let t=process.env.GJSIFY_NPM_CACHE;if(t!==void 0){let n=t.trim();return n===``||n===`0`||n===`false`?null:wn(n.endsWith(`_cacache`)?n:wn(n,`_cacache`),`content-v2`)}let n=process.env.npm_config_cache;return wn(n&&n.length>0?n:wn(homedir(),`.npm`),`_cacache`,`content-v2`)}function npmCachePathFor(t){let n=npmCacacheContentDir();if(!n)return null;let S=parseSri$1(t);return S?wn(n,S.algorithm,S.hex.slice(0,2),S.hex.slice(2,4),S.hex.slice(4)):null}async function getForeignCachedTarball(t){let n=npmCachePathFor(t);if(!n||!t)return null;let S=readCacheFile(n);return S&&await verifyIntegrity(S,t)?S:null}var jL,ML=__esmMin(()=>{lt(),Rd(),Lg(),Pn(),eh(),dL(),jL=`v1`,__name$1(cacheRoot$1,`cacheRoot`),__name$1(parseSri$1,`parseSri`),__name$1(pathFor$3,`pathFor`)});function isEnabled(){let t=process.env.GJSIFY_PACKUMENT_CACHE;if(t===void 0)return!0;let n=t.trim();return!(n===`0`||n===`false`||n===``)}function cacheRoot(){return gjsifyCacheRoot(`metadata`,NL)}function shardFor(t){let n=2166136261;for(let S=0;S<t.length;S++)n^=t.charCodeAt(S),n=Math.imul(n,16777619);return(n>>>0&255).toString(16).padStart(2,`0`)}function encodePart(t){return encodeURIComponent(t).replace(/\*/g,`%2A`)}function packumentCacheKey(t,n,S){return`${S},${encodePart(t)},${encodePart(n)}`}function pathFor$2(t,n,S){if(!isEnabled())return null;let C=packumentCacheKey(t,n,S);return wn(cacheRoot(),shardFor(C),`${C}.json`)}function getCachedPackument(t,n,S=`corgi`){let C=pathFor$2(t,n,S);if(!C)return null;let N=readCacheFile(C);if(!N)return null;try{let t=JSON.parse(N.toString(`utf-8`));return typeof t.etag!=`string`||!t.etag||!t.packument||typeof t.packument!=`object`?null:{etag:t.etag,packument:t.packument}}catch{return null}}function putCachedPackument(t,n,S,C,N=`corgi`){if(!S)return;let F=pathFor$2(t,n,N);F&&atomicWrite(F,JSON.stringify({etag:S,packument:C}))}var NL,PL=__esmMin(()=>{Pn(),dL(),NL=`v3`,__name$1(pathFor$2,`pathFor`)});function parseNodeMajor(t){return Number.parseInt(String(t).split(`.`,1)[0]??``,10)}function nativeBackendNodeError(t,n){if(!n)return null;let S=parseNodeMajor(t);return!Number.isFinite(S)||S>=24?null:`gjsify install (native backend) requires Node ≥ 24, but this is Node ${t}. Its prebuilt native modules are ABI-locked to Node 24 and crash on older majors. Use Node 24 (nvm/asdf locally, actions/setup-node in CI), or run with --backend npm.`}function onRealNode(){return gjsSystemVersion()===void 0?isNode():!1}function assertNativeBackendNodeVersion(){let t=nativeBackendNodeError(process.versions.node,onRealNode());if(t)throw Error(t)}var FL=__esmMin(()=>{d_()});function normalizePath(t){let n=jn===`/`?t:t.split(jn).join(`/`);return n.endsWith(`/`)?n.slice(0,-1):n}function findExtraneous(t){let n=new Set(t.expected.map(t=>normalizePath(t.installPath))),S=t.installed.filter(t=>t.bundles&&!t.linked).map(n=>`${normalizePath(Tn(t.prefix,n.dir))}/node_modules/`),C=[];for(let N of t.installed){if(N.linked)continue;let F=normalizePath(Tn(t.prefix,N.dir));F===``||F.startsWith(`..`)||n.has(F)||S.some(t=>F.startsWith(t))||C.push({installPath:F,name:N.name,version:N.version})}C.sort((t,n)=>t.installPath<n.installPath?-1:+(t.installPath>n.installPath));let N=[];for(let t of C){let n=N[N.length-1];n&&t.installPath.startsWith(`${n.installPath}/`)||N.push(t)}return N}function formatExtraneousError(t,n){let S=t.slice(0,20),C=S.map(t=>` ${t.installPath} (${t.name}@${t.version})`);return t.length>S.length&&C.push(` … and ${t.length-S.length} more`),[`install: --immutable, but ${n}/node_modules holds ${t.length} package(s) that gjsify-lock.json does not describe.`,`--immutable installs the lockfile and removes nothing, so each of these would survive the install and be resolved, bundled and type-checked as if it belonged (gjsify#1683: a nested copy of an already-hoisted package → TS2883, one type with two identities).`,...C,"Fix: delete those directories — or the whole node_modules — and re-run. A plain `gjsify install` does NOT clear them: it only ever adds, and its prune pass judges foreign-PLATFORM packages alone (prune-prefix.ts), so an undescribed package survives both. Deleting is currently the only thing that removes one. In CI this usually means a cache entry was restored from a DIFFERENT lockfile."].join(`
912
+ `)}var IL=__esmMin(()=>{Pn()});function dirLinkTarget(t,n,S=LL){return S===`junction`?xn(n):Tn(En(t),n)}function linkDirSync(t,n){assertAbsolute(n),symlinkSync(dirLinkTarget(t,n),t,RL)}function replicateLinkSync(t,n){let S=readlinkSync(t);if(!dirLinksAreJunctions()){symlinkSync(S,n);return}let C=xn(En(t),S),N;try{N=statSync(C).isDirectory()}catch{symlinkSync(S,n);return}N?symlinkSync(C,n,`junction`):symlinkSync(S,n,`file`)}function assertAbsolute(t){if(xn(t)!==t)throw TypeError(`linkDir: target must be an absolute path, got ${JSON.stringify(t)}. Node resolves a Windows junction target against the process CWD rather than the link's own directory, so a relative target silently points somewhere else there.`)}var LL,RL,dirLinksAreJunctions,zL=__esmMin(()=>{Rd(),xd(),Pn(),LL=process.platform===`win32`?`junction`:`symlink`,RL=LL===`junction`?`junction`:void 0,dirLinksAreJunctions=()=>LL===`junction`});function checkList(t,n){let S=typeof n==`string`?[n]:n;if(S.length===1&&S[0]===`any`)return!0;let C=0,N=!1;for(let n of S){let S=n.charAt(0)===`!`,F=S?n.slice(1):n;if(S){if(C++,t===F)return!1}else N||=t===F}return N||C===S.length}function checkPlatform(t,n){let S=t.os?checkList(n.os,t.os):!0,C=t.cpu?checkList(n.cpu,t.cpu):!0,N=t.libc?checkList(n.libc,t.libc):!0;return t.libc&&!n.libc&&(N=!1),{ok:S&&C&&N,current:{os:n.os,cpu:n.cpu,libc:n.libc},required:{os:t.os,cpu:t.cpu,libc:t.libc}}}function declaresPlatform(t){return!!(t.os||t.cpu||t.libc)}function badPlatformError(t,n){let S=Error(`Unsupported platform for ${t}: wanted ${JSON.stringify(n.required)} (current: ${JSON.stringify(n.current)})`);return S.code=`EBADPLATFORM`,S.pkgid=t,S.current=n.current,S.required=n.required,S}function isMuslSharedObject(t){return t.includes(`libc.musl-`)||t.includes(`ld-musl-`)}function libcFromLddFile(t){let n=t.readTextFile(BL);if(n!==null)return n.includes(`musl`)?`musl`:n.includes(`GNU C Library`)?`glibc`:null}function libcFromReportData(t){return t.glibcVersionRuntime?`glibc`:Array.isArray(t.sharedObjects)&&t.sharedObjects.some(t=>isMuslSharedObject(String(t)))?`musl`:null}function libcFromLoaderScan(t,n=VL){let S=!1;for(let C of n){let n=t.listDir(C);if(n)for(let t of n){if(t.startsWith(`ld-linux`))return`glibc`;t.startsWith(`ld-musl-`)&&(S=!0)}}return S?`musl`:null}function detectLibc(t,n){if(t!==`linux`)return;let S=libcFromLddFile(n);if(S!==void 0)return S??void 0;let C=n.diagnosticReport();return C===null?libcFromLoaderScan(n)??void 0:libcFromReportData(C)??void 0}function defaultLibcProbeHost(){return{readTextFile(t){try{return readFileSync(t,`utf-8`)}catch{return null}},listDir(t){try{return readdirSync(t)}catch{return null}},diagnosticReport(){let t=process.report;if(!t||typeof t.getReport!=`function`)return null;let n=t.excludeNetwork;t.excludeNetwork=!0;try{let n=t.getReport();return{glibcVersionRuntime:n.header?.glibcVersionRuntime,sharedObjects:n.sharedObjects}}finally{t.excludeNetwork=n}}}}function hostLibc(t,n=defaultLibcProbeHost()){return UL||=(HL=detectLibc(t,n),!0),HL}function readPlatformOverrides(t){let pick=n=>{let S=t[n];if(typeof S!=`string`)return;let C=S.trim();return C===``?void 0:C},n={},S=pick(`npm_config_os`),C=pick(`npm_config_cpu`),N=pick(`npm_config_libc`);return S!==void 0&&(n.os=S),C!==void 0&&(n.cpu=C),N!==void 0&&(n.libc=N),n}function readPlatformForce(t){let n=t.npm_config_force;if(typeof n!=`string`)return!1;let S=n.trim().toLowerCase();return S===`true`||S===`1`}function resolveHostPlatform(t={}){let n=readPlatformOverrides(t.env??process.env),S=n.os??t.platform??process.platform;return{os:S,cpu:n.cpu??t.arch??process.arch,libc:n.libc??(S===`linux`?hostLibc(S,t.probe??defaultLibcProbeHost()):void 0)}}function describePlatformTarget(t){return`${t.os}-${t.cpu}${t.libc?`-${t.libc}`:``}`}var BL,VL,HL,UL,WL=__esmMin(()=>{Rd(),BL=`/usr/bin/ldd`,VL=[`/lib`,`/lib64`,`/usr/lib`],UL=!1});function isReservedEntry(t){return t.startsWith(`.`)}function readManifest(t){try{let n=JSON.parse(readFileSync(wn(t,`package.json`),`utf8`)),S={os:n.os,cpu:n.cpu,libc:n.libc};return{name:typeof n.name==`string`?n.name:void 0,version:typeof n.version==`string`?n.version:void 0,platform:declaresPlatform(S)?S:void 0,bundles:[n.bundleDependencies,n.bundledDependencies].some(t=>t===!0||Array.isArray(t)&&t.length>0)}}catch{return null}}function collect(t,n){let S;try{S=readdirSync(t,{withFileTypes:!0})}catch{return}for(let C of S){if(isReservedEntry(C.name))continue;let S=wn(t,C.name);if(C.name.startsWith(`@`)){let t;try{t=readdirSync(S,{withFileTypes:!0})}catch{continue}for(let C of t)isReservedEntry(C.name)||addPackage(wn(S,C.name),n);continue}addPackage(S,n)}}function addPackage(t,n){let S=!1;try{S=lstatSync(t).isSymbolicLink()}catch{return}let C=readManifest(t);n.push({name:C?.name??t,version:C?.version??`0.0.0`,dir:t,linked:S,platform:C?.platform,bundles:C?.bundles}),S||collect(wn(t,`node_modules`),n)}function scanPrefix(t){let n=[];return collect(wn(t,`node_modules`),n),n}function planPlatformPrune(t,n){let S=[];for(let C of t){if(C.linked||!C.platform)continue;let t=checkPlatform(C.platform,n);t.ok||S.push({pkg:C,bytes:0,verdict:t})}return S}function dirBytes(t){let n=0,S=[t];for(;S.length>0;){let t=S.pop(),C;try{C=readdirSync(t,{withFileTypes:!0})}catch{continue}for(let N of C){let C=wn(t,N.name);if(N.isDirectory())S.push(C);else if(N.isFile())try{n+=statSync(C).size}catch{}}}return n}function planPrune(t){let n=scanPrefix(t.prefix),S=planPlatformPrune(n,t.target);for(let t of S)t.bytes=dirBytes(t.pkg.dir);return{prefix:t.prefix,target:t.target,scanned:n.length,entries:S,bytes:S.reduce((t,n)=>t+n.bytes,0)}}function executePrune(t,n={}){let S=[],C=[],N=[],F=n.remove??(t=>rmSync(t,{recursive:!0,force:!0,maxRetries:10}));if(!n.dryRun){for(let n of t.entries)try{F(n.pkg.dir),S.push(n)}catch(t){C.push({entry:n,error:t.message})}N.push(...pruneDeadBinLinks(t.prefix))}return{plan:t,removed:S,failed:C,bytes:S.reduce((t,n)=>t+n.bytes,0),binLinks:N}}function pruneDeadBinLinks(t){let n=wn(t,`node_modules`,`.bin`),S=[],C;try{C=readdirSync(n,{withFileTypes:!0})}catch{return S}for(let t of C){let C=wn(n,t.name);try{if(!lstatSync(C).isSymbolicLink()||existsSync(C))continue;unlinkSync(C),S.push(t.name)}catch{}}return S}function humanBytes(t){if(t<1024)return`${t} B`;let n=[`KB`,`MB`,`GB`],S=t/1024,C=0;for(;S>=1024&&C<n.length-1;)S/=1024,C+=1;return`${S.toFixed(1)} ${n[C]}`}function formatPruneReport(t,n){let{plan:S}=t,C=[`${S.prefix} · target ${describePlatformTarget(S.target)} · scanned ${S.scanned} package(s)`];if(S.entries.length===0)return C.push(`nothing to prune — no installed package declares a platform this target cannot use.`),C.join(`
913
+ `);let N=n.verbose?S.entries:S.entries.slice(0,GL);for(let t of N){let n=JSON.stringify(t.verdict.required);C.push(` ${t.pkg.name}@${t.pkg.version} ${humanBytes(t.bytes)} requires ${n}`)}N.length<S.entries.length&&C.push(` … and ${S.entries.length-N.length} more (--verbose to list them)`),C.push(n.dryRun?`would free ${humanBytes(S.bytes)} across ${S.entries.length} package(s) (apparent size)`:`freed ${humanBytes(t.bytes)} across ${t.removed.length} package(s) (apparent size)`),t.binLinks.length>0&&C.push(`removed ${t.binLinks.length} dangling .bin link(s): ${t.binLinks.join(`, `)}`);for(let n of t.failed)C.push(`FAILED ${n.entry.pkg.name}: ${n.error}`);return C.join(`
914
+ `)}function automaticPruneRefusal(t,n){return Object.keys(readPlatformOverrides(t)).length>0?`the platform target was overridden on the command line`:n?`--immutable`:null}function pruneAfterInstall(t,n,S={}){try{if(automaticPruneRefusal(S.env??process.env,S.immutable??!1))return;let C=planPrune({prefix:t,target:n});if(C.entries.length===0)return;let N=executePrune(C);if(N.removed.length===0)return;let F=S.hint?` (${S.hint} to review)`:``;ge.log(`gjsify: pruned ${N.removed.length} package(s) this host cannot use, freeing ${humanBytes(N.bytes)}${F}`)}catch(t){process.env.GJSIFY_DEBUG&&ge.error(`gjsify: prune skipped — ${t.message}`)}}var GL,KL=__esmMin(()=>{_e(),Rd(),Pn(),WL(),GL=10});function devLinkPath(t){return wn(t,qL)}function readDevLinkOverride(t){let n=devLinkPath(t);if(!existsSync(n))return null;let S;try{S=JSON.parse(readFileSync(n,`utf-8`))}catch(t){throw Error(`gjsify link: ${n} is not valid JSON (${t instanceof Error?t.message:String(t)}). Fix it or run \`gjsify unlink\`.`)}if(!S||typeof S!=`object`)throw Error(`gjsify link: ${n} must contain a JSON object.`);let C=S;if(C.version!==1)throw Error(`gjsify link: ${n} declares version ${JSON.stringify(C.version)}; this CLI understands version 1 only.`);if(typeof C.checkout!=`string`||C.checkout.trim()===``)throw Error(`gjsify link: ${n} has no "checkout" path.`);return{version:1,checkout:Cn(C.checkout)?C.checkout:xn(t,C.checkout),packages:Array.isArray(C.packages)?C.packages.filter(t=>typeof t==`string`):[]}}function writeDevLinkOverride(t,n){let S=devLinkPath(t);return writeFileSync(S,JSON.stringify(n,null,2)+`
915
915
  `),S}function removeDevLinkOverride(t){let n=devLinkPath(t);return existsSync(n)?(rmSync(n),n):null}function devLinkRoot(t){if(existsSync(devLinkPath(t)))return t;let n=findWorkspaceRoot(t);return n&&existsSync(devLinkPath(n))?n:t}function resolveCheckoutWorkspaces(t,n){if(!existsSync(t))throw Error(`gjsify link: the linked checkout ${t} does not exist (named by ${n}). Point it at a gjsify checkout, or run \`gjsify unlink\`.`);let S=readPackageJson$2(wn(t,`package.json`));if(!S||S.workspaces===void 0)throw Error(`gjsify link: ${t} is not a gjsify workspace — ${wn(t,`package.json`)} ${S?`declares no "workspaces" field`:`is missing or unreadable`} (named by ${n}).`);let C;try{C=discoverWorkspaces(t)}catch(S){throw Error(`gjsify link: ${t} declares "workspaces" but they could not be discovered (${S instanceof Error?S.message:String(S)}); named by ${n}.`)}if(C.length===0)throw Error(`gjsify link: ${t} declares "workspaces" but none were found (named by ${n}).`);return C}function consumerKnownNames(t){let n=new Set,S=[readPackageJson$2(wn(t,`package.json`))];try{for(let n of discoverWorkspaces(t))S.push(n.manifest)}catch{}for(let t of S)if(t)for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`]){let C=t[S];if(!(!C||typeof C!=`object`))for(let t of Object.keys(C))n.add(t)}for(let S of scanPrefix(t))n.add(S.name);return n}function planDevLinks(t){let n=t.patterns.length>0?filterWorkspaces(t.workspaces,{include:[...t.patterns]}):[...t.workspaces],S=[];for(let C of n)C.name&&t.knownNames.has(C.name)&&S.push({name:C.name,target:C.location,linkPath:wn(t.consumerRoot,`node_modules`,C.name)});return S.sort((t,n)=>t.name<n.name?-1:+(t.name>n.name)),S}function prepareDevLinks(t){let n=readDevLinkOverride(t);if(!n)return null;let S=devLinkPath(t),C=planDevLinks({consumerRoot:t,workspaces:resolveCheckoutWorkspaces(n.checkout,S),patterns:n.packages,knownNames:consumerKnownNames(t)});return{overridePath:S,consumerRoot:t,checkout:n.checkout,links:C,names:new Set(C.map(t=>t.name))}}function applyDevLinks(t){assertDevLinksBuilt(t);let n=[];for(let S of t)linkAlreadyPointsAt(S.linkPath,S.target)||(mkdirSync(En(S.linkPath),{recursive:!0}),rmSync(S.linkPath,{recursive:!0,force:!0,maxRetries:10,retryDelay:100}),linkDirSync(S.linkPath,S.target),n.push(S));return n}function removeDevLinks(t){let n=[];for(let S of t){let t=!1;try{t=lstatSync(S.linkPath).isSymbolicLink()}catch{continue}t&&linkAlreadyPointsAt(S.linkPath,S.target)&&(rmSync(S.linkPath,{recursive:!0,force:!0,maxRetries:10,retryDelay:100}),n.push(S))}return n}function linkAlreadyPointsAt(t,n){try{return lstatSync(t).isSymbolicLink()?realpathSync(t)===realpathSync(n):!1}catch{return!1}}function scanDevLinks(t,n){let S=[];for(let t of n)try{S.push(realpathSync(t))}catch{}if(S.length===0)return[];let C=wn(t,`node_modules`),N=[],consider=t=>{let n=wn(C,t),F;try{if(!lstatSync(n).isSymbolicLink())return;F=realpathSync(n)}catch{return}S.some(t=>F===t||F.startsWith(t+jn))&&N.push({name:t,target:F,linkPath:n})},F;try{F=readdirSync(C)}catch{return[]}for(let t of F)if(!t.startsWith(`.`)){if(t.startsWith(`@`)){let n;try{n=readdirSync(wn(C,t))}catch{continue}for(let S of n)consider(`${t}/${S}`);continue}consider(t)}return N.sort((t,n)=>t.name<n.name?-1:+(t.name>n.name)),N}function retireDevLinks(t,n,S){return removeDevLinks(scanDevLinks(t,n).filter(t=>!S.has(t.name)))}function unbuiltDevLinks(t){let n=[];for(let S of t){let t;try{t=JSON.parse(readFileSync(wn(S.target,`package.json`),`utf-8`))}catch(t){n.push({link:S,reason:`its package.json is missing or unreadable (${t instanceof Error?t.message:String(t)})`});continue}let C=[];for(let n of[`main`,`module`]){let S=t[n];typeof S==`string`&&C.push(S)}let N=t.exports;typeof N==`string`?C.push(N):N&&typeof N==`object`&&collectStringLeaves(N[`.`],C),C.length!==0&&(C.some(t=>existsSync(wn(S.target,t)))||n.push({link:S,reason:`none of its declared entry points exist yet (${C.join(`, `)})`}))}return n}function formatUnbuiltDevLinks(t){let n=t.map(t=>` ${t.link.name} ${t.link.target}\n ${t.reason}`).join(`
916
916
  `);return`gjsify link: ${t.length} linked package(s) are not built, so linking them would hand the consumer a tree whose first import fails with MODULE_NOT_FOUND:\n${n}\n Build them in the checkout (\`gjsify run build\` there) and re-run, or narrow the selection with \`gjsify link <checkout> --packages <glob>\`. A link does not build.`}function assertDevLinksBuilt(t){let n=unbuiltDevLinks(t);if(n.length!==0)throw Error(formatUnbuiltDevLinks(n))}function collectStringLeaves(t,n){if(typeof t==`string`){n.push(t);return}if(!(!t||typeof t!=`object`))for(let S of Object.values(t))collectStringLeaves(S,n)}function ensureLocallyIgnored(t){let n=resolveGitDir(t);if(!n.commonDir)return n.why;let S=wn(t,`.gitignore`);if(existsSync(S)&&fileMentionsPattern(S,`.gjsify-link.json`))return`already-ignored`;let C=wn(n.commonDir,`info`,`exclude`);if(existsSync(C)&&fileMentionsPattern(C,`.gjsify-link.json`))return`already-ignored`;mkdirSync(En(C),{recursive:!0});let N=existsSync(C)?readFileSync(C,`utf-8`):``;return writeFileSync(C,`${N}${N===``||N.endsWith(`
917
917
  `)?``:`
918
- `}${UL}\n${HL}\n`),`added`}function removeLocalIgnore(t){let n=resolveGitDir(t);if(!n.commonDir)return n.why;let S=wn(n.commonDir,`info`,`exclude`),C;try{C=readFileSync(S,`utf-8`)}catch{return`absent`}let N=C.split(/\r?\n/),F=[],I=!1;for(let t=0;t<N.length;t++){if(!I&&N[t]?.trim()===UL&&(N[t+1]?.trim()===`.gjsify-link.json`||N[t+1]?.trim()===`/.gjsify-link.json`)){t++,I=!0;continue}F.push(N[t]??``)}return I?(writeFileSync(S,F.join(`
919
- `)),`removed`):`absent`}function fileMentionsPattern(t,n){let S;try{S=readFileSync(t,`utf-8`)}catch{return!1}return S.split(/\r?\n/).some(t=>{let S=t.trim();return S===n||S===`/${n}`})}function resolveGitDir(t){let n=wn(t,`.git`),S;try{S=statSync(n)}catch{return{commonDir:null,why:`no-git`}}if(S.isDirectory())return{commonDir:n,why:`no-git`};let C;try{C=readFileSync(n,`utf-8`).trim()}catch{return{commonDir:null,why:`unreadable-git`}}let N=/^gitdir:\s*(.+)$/.exec(C)?.[1]?.trim();return N?followCommondir(Cn(N)?N:xn(t,N)):{commonDir:null,why:`unreadable-git`}}function followCommondir(t){let n=wn(t,`commondir`);if(!existsSync(n))return{commonDir:t,why:`no-git`};let S;try{S=readFileSync(n,`utf-8`)}catch{return{commonDir:null,why:`unreadable-git`}}let C=S.trim();if(!C)return{commonDir:null,why:`unreadable-git`};let N=Cn(C)?C:xn(t,C);return existsSync(N)?{commonDir:N,why:`no-git`}:{commonDir:null,why:`unreadable-git`}}function assertNoDevLinkUnderImmutable(t){let n=devLinkRoot(t),S=devLinkPath(n);if(!existsSync(S))return;let C=`(unreadable)`;try{C=readDevLinkOverride(n)?.checkout??C}catch{}throw Error(`gjsify install --immutable: a development link override is active — ${S}\nIt points at ${C}, so this install would build from a local checkout instead of what ${wn(n,`gjsify-lock.json`)} pins. --immutable builds only what is committed.\nRun \`gjsify unlink\` (in ${n}) or delete ${HL}, then re-run.`)}var HL,UL,WL=__esmMin(()=>{Rd(),Pn(),QP(),PL(),$P(),VL(),eF(),HL=`.gjsify-link.json`,UL=`# gjsify link — local development override, never commit`}),GL=__exportAll$5({applyPlatformFilter:()=>applyPlatformFilter,computeOptionalFlags:()=>computeOptionalFlags,installPackagesNative:()=>installPackagesNative,parseSpec:()=>parseSpec$1,parseSpecName:()=>parseSpecName,pickVersion:()=>pickVersion,reachableInstallPaths:()=>reachableInstallPaths,readLockfileNodes:()=>readLockfileNodes,requiredDepEntries:()=>requiredDepEntries,requiredPeerEntries:()=>requiredPeerEntries,warnMissingNativeBuilds:()=>warnMissingNativeBuilds,writeBinEntry:()=>writeBinEntry});async function installPackagesNative(t){if(assertNativeBackendNodeVersion(),t.specs.length===0)throw Error(`installPackagesNative: empty specs list`);mkdirSync(t.prefix,{recursive:!0});let n=await loadNpmrc$1(t),S=makeLogger(t.verbose??!1),C=await acquireInstallLock(t.prefix,{signal:t.signal});try{return await installPackagesNativeLocked(t,n,S)}finally{C.release()}}async function installPackagesNativeLocked(t,n,S){let C=t.progress,N=wn(t.prefix,qL),F=readLockfile(N),I=resolveHostPlatform(),H=readPlatformForce(process.env);S(`install: platform target %s%s`,describePlatformTarget(I),H?` (--force: checks bypassed)`:``);let W,q=!1,Y=new Set;if(t.frozen||t.focusSpecs){let n=t.frozen?`--immutable`:`--focus`,C=t.frozen?`(without --immutable)`:`(without --focus)`;if(!F)throw Error(`install: ${n} requires ${qL} at ${t.prefix} — none found. Run \`gjsify install\` ${C} to generate one and commit it.`);let I=describeLockfileDrift(F,t.specs);if(I)throw Error(`install: ${n} but ${N} is stale.\n${I}\nRe-run \`gjsify install\` ${C} to refresh the lockfile.`);if(S(`install: %s, using lockfile (%d package(s))`,n,Object.keys(F.packages).length),W=lockfileToNodes(F),t.frozen&&assertNoExtraneous(t.prefix,W),t.focusSpecs){let n=reachableInstallPaths(W,t.focusSpecs.map(parseSpecName));S(`install: --focus keeps %d of %d lockfile package(s)`,n.size,W.length),W=W.filter(t=>n.has(t.installPath))}}else if(!t.refreshLockfile&&F&&F.lockfileVersion===JL&&F.peersResolved===!0&&lockfileMatchesRequest(F,t.specs))S(`install: using lockfile (%d package(s))`,Object.keys(F.packages).length),W=lockfileToNodes(F);else{let N=!t.refreshLockfile&&F?buildPreferredVersions(F):void 0;S(`install: resolving %d top-level spec(s) → %s%s`,t.specs.length,t.prefix,N?` (preserving ${N.size} locked name(s))`:``);let I=await resolveDeps(t.specs,n,S,t.overrides,t.skipDeps,t.signal,C,N,t.workspaceNames,t.specOrigins,t.optionalSpecs,t.linkedNames);W=I.nodes,Y=I.skippedEdges,q=!0}computeOptionalFlags(W,requiredTopLevelNames(t.focusSpecs??t.specs,t.optionalSpecs),S),assertRequiredEdgesResolved(W,Y),q&&t.lockfile&&(writeLockfile(N,t.specs,W),S(`install: wrote %s (%d entries)`,qL,W.length));let X=W;if(t.workspaceNames&&t.workspaceNames.size>0){let n=X.length;X=X.filter(n=>!t.workspaceNames.has(n.name));let C=n-X.length;C>0&&S(`install: %d workspace-provided package(s) symlinked, not fetched`,C)}if(t.linkedNames&&t.linkedNames.size>0){let n=X.length;X=X.filter(n=>!t.linkedNames.has(n.name));let C=n-X.length;C>0&&S(`install: %d dev-linked package(s) provided by a local checkout, not fetched`,C)}let Z=applyPlatformFilter(X,I,H,S);return S(`install: downloading %d tarball(s)`,Z.length),await downloadAndExtractAll(Z,t.prefix,n,S,t.signal,C),await linkBins(Z,t.prefix,S),warnMissingNativeBuilds(Z,t.prefix,S),S(`install: done`),topLevelResolutions(t.specs,W)}function assertNoExtraneous(t,n){let S=findExtraneous({prefix:t,installed:scanPrefix(t),expected:n});if(S.length!==0)throw Error(formatExtraneousError(S,t))}function errMsg(t){return t instanceof Error?t.message:String(t)}function applyPlatformFilter(t,n,S,C){let N=[],F=0;for(let I of t){let t=I.platform;if(!t||!declaresPlatform(t)){N.push(I);continue}let H=checkPlatform(t,n);if(H.ok){N.push(I);continue}let W=`${I.name}@${I.version}`;if(!I.optional){if(S){C(`platform-forced: %s (required, incompatible, installed anyway via --force)`,W),N.push(I);continue}throw badPlatformError(W,H)}I.inert=!0,F++,C(`platform-skip: %s (%s) current=%s required=%s`,W,I.installPath,JSON.stringify(H.current),JSON.stringify(H.required))}return F>0&&C(`install: %d optional package(s) inert — not installable on %s`,F,describePlatformTarget(n)),N}function warnMissingNativeBuilds(t,n,S){let C=process.platform,N=process.arch,F=[`preinstall`,`install`,`postinstall`];for(let I of t){let t=wn(n,I.installPath),H;try{H=JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))?.scripts}catch{continue}if(!H||typeof H!=`object`)continue;let W=F.find(t=>typeof H[t]==`string`);if(W===void 0)continue;let q=!1;try{let n=wn(t,`prebuilds`);for(let t of readdirSync(n))if(t.startsWith(`${C}-`)&&readdirSync(wn(n,t)).length>0){q=!0;break}}catch{}if(!q)try{q=readdirSync(wn(t,`build`,`Release`)).some(t=>t.endsWith(`.node`)||t.endsWith(`.so`))}catch{}q||S("install: WARNING — %s declares a native `%s` build script but ships no %s-%s prebuild, and gjsify install does not run build scripts (node-free). It will not load until built: run `node-gyp rebuild` in %s, or use a version that ships a %s-%s prebuild.",I.name,W,C,N,I.installPath,C,N)}}function topLevelResolutions(t,n){let S=new Map;for(let t of n)t.installPath===`node_modules/${t.name}`&&S.set(t.name,t);let C=[];for(let n of t){let t=parseSpecName(n),N=S.get(t);N&&C.push({name:N.name,version:N.version})}return C}function parseSpecName(t){if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)return t;let S=t.indexOf(`@`,n+1);return S===-1?t:t.slice(0,S)}let n=t.indexOf(`@`);return n===-1?t:t.slice(0,n)}async function resolveDeps(t,n,S,C,N,F,I,H,W,q,Y,X){I?.beginPhase(`resolve`,t.length);let applyOverride=(t,n)=>{if(!C)return n;let N=C[t];return typeof N!=`string`||N.length===0||N===n?n:(S(`install: override %s %s → %s`,t,n,N),N)},Z=new Map,fetchPkg=t=>{let C=Z.get(t);if(C)return C;let N=fetchPackumentWithDiskCache(t,n,S,F,`full`);return Z.set(t,N),N},te=new Map,ne=new Map,re=new Set,ie=new Map,ae=t.map(parseSpec$1).map(t=>{let n=applyOverride(t.name,t.range),S=ie.get(t.name);S||(S=new Map,ie.set(t.name,S));let C=S.get(n);C||(C=new Set,S.set(n,C));for(let n of q?.get(`${t.name}@${t.range}`)??[])C.add(n);return{from:null,name:t.name,range:n,required:!Y?.has(t.name)}});for(;ae.length>0;){let t=ae.splice(0,ae.length),n=[],C=new Set;for(let S of t)Z.has(S.name)||C.has(S.name)||(C.add(S.name),n.push(S.name));await prefetchPackuments(n,fetchPkg,F);for(let n=0;n<t.length;n++){let C=t[n];if(W?.has(C.name))continue;let F=findVisible(C.from,C.name,te);if(F&&satisfiesRange(F.version,C.range))continue;if(C.peerOf){let t=C.from===null?`node_modules/${C.name}`:`${C.from}/node_modules/${C.name}`,n=te.get(t);if(n){ge.warn(`[gjsify] warning: peer dependency conflict: ${C.peerOf.name}@${C.peerOf.version} wants ${C.name}@${C.range}, but ${n.version} is installed at ${n.installPath} — keeping it (npm's non-strict behaviour).`);continue}}let q=null;try{let F=await fetchPkg(C.name),W=preferredVersionFor(H?.get(C.name),C.range);if(q=pickVersion(F,C.range,W),!q)throw Error(`No version of ${C.name} satisfies ${C.range}`);let Y=F.versions[q];if(!Y)throw Error(`Packument for ${C.name} promised ${q} but no entry exists`);let X=decidePlacement(C.from,C.name,q,ne),Z={name:C.name,version:q,tarballUrl:Y.dist.tarball,integrity:Y.dist.integrity,installPath:X,dependencies:Y.dependencies??{},optionalDependencies:Y.optionalDependencies??{},peerDependencies:nonEmpty(Y.peerDependencies),peerDependenciesMeta:nonEmpty(Y.peerDependenciesMeta),bin:Y.bin,platform:platformDeclarationOf(Y),optional:!C.required};if(te.set(X,Z),X===`node_modules/${C.name}`&&ne.set(C.name,Z),S(`resolve: %s@%s ← %s (at %s)`,C.name,q,C.range,X),I?.update({phase:`resolve`,current:te.size,total:te.size+(t.length-n-1)+ae.length,name:`${C.name}@${q}`}),!N){let t=parentInstallPath(X);for(let[n,S]of requiredPeerEntries(Z))ae.push({from:t,name:n,range:applyOverride(n,S),required:!Z.optional,peerOf:Z});for(let[t,n]of requiredDepEntries(Z))ae.push({from:X,name:t,range:applyOverride(t,n),required:!Z.optional});for(let[t,n]of Object.entries(Z.optionalDependencies))ae.push({from:X,name:t,range:applyOverride(t,n),required:!1})}}catch(t){if(X?.has(C.name)&&t instanceof PackageNotFoundError){S(`resolve: dev-linked %s not published — provided by the local checkout`,C.name);continue}if(!C.required){re.add(edgeKey(C.peerOf?.installPath??C.from,C.name)),S(`resolve: optional dep %s@%s skipped (%s)`,C.name,C.range,errMsg(t));continue}throw t}}}return I?.endPhase(`resolve`),emitTopLevelConflictWarnings(ie,ne),{nodes:Array.from(te.values()),skippedEdges:re}}function platformDeclarationOf(t){let n={os:t.os,cpu:t.cpu,libc:t.libc};return declaresPlatform(n)?n:void 0}function edgeKey(t,n){return`${t??``}\n${n}`}function parseEdgeKey(t){let n=t.indexOf(`
920
- `),S=t.slice(0,n);return{from:S===``?null:S,name:t.slice(n+1)}}function requiredTopLevelNames(t,n){let S=new Set;for(let C of t){let t=parseSpecName(C);n?.has(t)||S.add(t)}return S}function requiredDepEntries(t){let n=[];for(let[S,C]of Object.entries(t.dependencies))S in t.optionalDependencies||n.push([S,C]);return n}function requiredPeerEntries(t){let n=[];for(let[S,C]of Object.entries(t.peerDependencies??{}))t.peerDependenciesMeta?.[S]?.optional!==!0&&(S in t.dependencies||S in t.optionalDependencies||n.push([S,C]));return n}function computeOptionalFlags(t,n,S){let C=new Map;for(let n of t)C.set(n.installPath,n);let N=new Set,F=[],enter=t=>{N.has(t.installPath)||(N.add(t.installPath),F.push(t.installPath))};for(let t of n){let n=C.get(`node_modules/${t}`);n&&enter(n)}for(;F.length>0;){let t=F.pop();if(t===void 0)break;let n=C.get(t);if(n)for(let[S]of[...requiredDepEntries(n),...requiredPeerEntries(n)]){let n=findVisible(t,S,C);n&&enter(n)}}let I=0;for(let n of t){let t=!N.has(n.installPath);(n.optional??!1)!==t&&I++,n.optional=t}S(`install: optionality fixpoint — %d of %d node(s) reachable only via optional edges%s`,t.length-N.size,t.length,I>0?`; corrected ${I} incoming flag(s)`:``)}function reachableInstallPaths(t,n){let S=new Map;for(let n of t)S.set(n.installPath,n);let C=new Set,N=[],enter=t=>{!t||C.has(t.installPath)||(C.add(t.installPath),N.push(t))};for(let t of n)enter(S.get(`node_modules/${t}`));for(let t=N.pop();t;t=N.pop()){let n=[...Object.keys(t.dependencies),...Object.keys(t.optionalDependencies),...requiredPeerEntries(t).map(([t])=>t)];for(let C of n)enter(findVisible(t.installPath,C,S))}return C}function readLockfileNodes(t){let n=readLockfile(t);return n?lockfileToNodes(n):null}function assertRequiredEdgesResolved(t,n){if(n.size===0)return;let S=new Map;for(let n of t)S.set(n.installPath,n);for(let t of n){let{from:n,name:C}=parseEdgeKey(t);if(n===null)continue;let N=S.get(n);if(N&&!N.optional&&!(C in N.optionalDependencies))throw Error(`install: required dependency ${C} of ${N.name}@${N.version} (${N.installPath}) could not be resolved.\nThe failure was tolerated during the walk because ${N.name} looked optional at that point, but the final dependency graph makes it required — so ${C} is required too and the tree would be incomplete.\nRe-run with --verbose and look for the "resolve: optional dep ${C}@… skipped (…)" line for the underlying cause.`)}}function emitTopLevelConflictWarnings(t,n){for(let[S,C]of t){if(C.size<2)continue;let t=n.get(S);if(!t)continue;let describe=(t,n)=>n.size>0?`${t} (requested by ${[...n].join(`, `)})`:t,N=[],F=[];for(let[n,S]of C){let C;try{C=satisfies(t.version,new YP(n))}catch{continue}(C?N:F).push(describe(n,S))}F.length!==0&&ge.warn(`[gjsify] warning: version conflict for ${S}: installed ${t.version} at ${t.installPath} — does NOT satisfy ${F.join(`, `)}`+(N.length>0?`; satisfies ${N.join(`, `)}`:``)+`. One hoisted copy serves all requesters until the per-workspace dedup pass lands (Phase D.8).`)}}async function fetchPackumentWithDiskCache(t,n,S,C,N=`corgi`){let F=registryFor(t,n),I=N===`full`,H=getCachedPackument(F,t,N),onRetry=({attempt:n,error:C,delayMs:F})=>{S(`packument %s (%s): retry %d after %dms (%s)`,t,N,n,F,errMsg(C))},W=await fetchPackumentConditional(t,{npmrc:n,signal:C,ifNoneMatch:H?.etag,fullMetadata:I,onRetry});return W.status===`not-modified`&&H?(S(`packument-cache-hit: %s (%s, 304, etag %s)`,t,N,H.etag),H.packument):W.status===`fresh`&&W.packument?(W.etag&&putCachedPackument(F,t,W.etag,W.packument,N),W.packument):fetchPackument(t,{npmrc:n,signal:C,fullMetadata:I,onRetry})}async function prefetchPackuments(t,n,S){if(t.length===0)return;let C=0,N=Math.max(1,Math.min(KL,t.length)),worker=async()=>{for(;C<t.length;){if(S?.aborted)return;let N=t[C++];try{await n(N)}catch{}}};await Promise.all(Array.from({length:N},()=>worker()))}function findVisible(t,n,S){let C=[];if(t!==null){C.push(`${t}/node_modules/${n}`);let S=t;for(;;){let t=S.lastIndexOf(`/node_modules/`);if(t<0||(S=S.slice(0,t),C.push(`${S}/node_modules/${n}`),S===``))break}}C.push(`node_modules/${n}`);for(let t of C){let n=S.get(t);if(n)return n}return null}function parentInstallPath(t){let n=t.lastIndexOf(`/node_modules/`);return n<0?null:t.slice(0,n)}function decidePlacement(t,n,S,C){let N=C.get(n);return!N||N.version===S||t===null?`node_modules/${n}`:`${t}/node_modules/${n}`}function satisfiesRange(t,n){try{return satisfies(t,new YP(n))}catch{return!1}}function readLockfile(t){if(!existsSync(t))return null;try{let n=JSON.parse(readFileSync(t,`utf-8`));return!YL.has(n.lockfileVersion)||!n.packages||typeof n.packages!=`object`?null:n}catch{return null}}function writeLockfile(t,n,S){let C={},N=[...S].sort((t,n)=>t.installPath<n.installPath?-1:+(t.installPath>n.installPath));for(let t of N)C[t.installPath]={version:t.version,resolved:t.tarballUrl,integrity:t.integrity,dependencies:Object.keys(t.dependencies).length>0?t.dependencies:void 0,optionalDependencies:Object.keys(t.optionalDependencies).length>0?t.optionalDependencies:void 0,peerDependencies:nonEmpty(t.peerDependencies),peerDependenciesMeta:nonEmpty(t.peerDependenciesMeta),bin:t.bin,os:t.platform?.os,cpu:t.platform?.cpu,libc:t.platform?.libc,optional:t.optional?!0:void 0};let F={lockfileVersion:JL,requested:[...n],packages:C,peersResolved:!0};atomicWriteStrict(t,JSON.stringify(F,null,2)+`
918
+ `}${JL}\n${qL}\n`),`added`}function removeLocalIgnore(t){let n=resolveGitDir(t);if(!n.commonDir)return n.why;let S=wn(n.commonDir,`info`,`exclude`),C;try{C=readFileSync(S,`utf-8`)}catch{return`absent`}let N=C.split(/\r?\n/),F=[],I=!1;for(let t=0;t<N.length;t++){if(!I&&N[t]?.trim()===JL&&(N[t+1]?.trim()===`.gjsify-link.json`||N[t+1]?.trim()===`/.gjsify-link.json`)){t++,I=!0;continue}F.push(N[t]??``)}return I?(writeFileSync(S,F.join(`
919
+ `)),`removed`):`absent`}function fileMentionsPattern(t,n){let S;try{S=readFileSync(t,`utf-8`)}catch{return!1}return S.split(/\r?\n/).some(t=>{let S=t.trim();return S===n||S===`/${n}`})}function resolveGitDir(t){let n=wn(t,`.git`),S;try{S=statSync(n)}catch{return{commonDir:null,why:`no-git`}}if(S.isDirectory())return{commonDir:n,why:`no-git`};let C;try{C=readFileSync(n,`utf-8`).trim()}catch{return{commonDir:null,why:`unreadable-git`}}let N=/^gitdir:\s*(.+)$/.exec(C)?.[1]?.trim();return N?followCommondir(Cn(N)?N:xn(t,N)):{commonDir:null,why:`unreadable-git`}}function followCommondir(t){let n=wn(t,`commondir`);if(!existsSync(n))return{commonDir:t,why:`no-git`};let S;try{S=readFileSync(n,`utf-8`)}catch{return{commonDir:null,why:`unreadable-git`}}let C=S.trim();if(!C)return{commonDir:null,why:`unreadable-git`};let N=Cn(C)?C:xn(t,C);return existsSync(N)?{commonDir:N,why:`no-git`}:{commonDir:null,why:`unreadable-git`}}function assertNoDevLinkUnderImmutable(t){let n=devLinkRoot(t),S=devLinkPath(n);if(!existsSync(S))return;let C=`(unreadable)`;try{C=readDevLinkOverride(n)?.checkout??C}catch{}throw Error(`gjsify install --immutable: a development link override is active — ${S}\nIt points at ${C}, so this install would build from a local checkout instead of what ${wn(n,`gjsify-lock.json`)} pins. --immutable builds only what is committed.\nRun \`gjsify unlink\` (in ${n}) or delete ${qL}, then re-run.`)}var qL,JL,YL=__esmMin(()=>{Rd(),Pn(),QP(),zL(),$P(),KL(),eF(),qL=`.gjsify-link.json`,JL=`# gjsify link — local development override, never commit`}),XL=__exportAll$5({applyPlatformFilter:()=>applyPlatformFilter,computeOptionalFlags:()=>computeOptionalFlags,installPackagesNative:()=>installPackagesNative,parseSpec:()=>parseSpec$1,parseSpecName:()=>parseSpecName,pickVersion:()=>pickVersion,reachableInstallPaths:()=>reachableInstallPaths,readLockfileNodes:()=>readLockfileNodes,requiredDepEntries:()=>requiredDepEntries,requiredPeerEntries:()=>requiredPeerEntries,warnMissingNativeBuilds:()=>warnMissingNativeBuilds,writeBinEntry:()=>writeBinEntry});async function installPackagesNative(t){if(assertNativeBackendNodeVersion(),t.specs.length===0)throw Error(`installPackagesNative: empty specs list`);mkdirSync(t.prefix,{recursive:!0});let n=await loadNpmrc$1(t),S=makeLogger(t.verbose??!1),C=await acquireInstallLock(t.prefix,{signal:t.signal});try{return await installPackagesNativeLocked(t,n,S)}finally{C.release()}}async function installPackagesNativeLocked(t,n,S){let C=t.progress,N=wn(t.prefix,QL),F=readLockfile(N),I=resolveHostPlatform(),H=readPlatformForce(process.env);S(`install: platform target %s%s`,describePlatformTarget(I),H?` (--force: checks bypassed)`:``);let W,q=!1,Y=new Set;if(t.frozen||t.focusSpecs){let n=t.frozen?`--immutable`:`--focus`,C=t.frozen?`(without --immutable)`:`(without --focus)`;if(!F)throw Error(`install: ${n} requires ${QL} at ${t.prefix} — none found. Run \`gjsify install\` ${C} to generate one and commit it.`);let I=describeLockfileDrift(F,t.specs);if(I)throw Error(`install: ${n} but ${N} is stale.\n${I}\nRe-run \`gjsify install\` ${C} to refresh the lockfile.`);if(S(`install: %s, using lockfile (%d package(s))`,n,Object.keys(F.packages).length),W=lockfileToNodes(F),t.frozen&&assertNoExtraneous(t.prefix,W),t.focusSpecs){let n=reachableInstallPaths(W,t.focusSpecs.map(parseSpecName));S(`install: --focus keeps %d of %d lockfile package(s)`,n.size,W.length),W=W.filter(t=>n.has(t.installPath))}}else if(!t.refreshLockfile&&F&&F.lockfileVersion===$L&&F.peersResolved===!0&&lockfileMatchesRequest(F,t.specs))S(`install: using lockfile (%d package(s))`,Object.keys(F.packages).length),W=lockfileToNodes(F);else{let N=!t.refreshLockfile&&F?buildPreferredVersions(F):void 0;S(`install: resolving %d top-level spec(s) → %s%s`,t.specs.length,t.prefix,N?` (preserving ${N.size} locked name(s))`:``);let I=await resolveDeps(t.specs,n,S,t.overrides,t.skipDeps,t.signal,C,N,t.workspaceNames,t.specOrigins,t.optionalSpecs,t.linkedNames);W=I.nodes,Y=I.skippedEdges,q=!0}computeOptionalFlags(W,requiredTopLevelNames(t.focusSpecs??t.specs,t.optionalSpecs),S),assertRequiredEdgesResolved(W,Y),q&&t.lockfile&&(writeLockfile(N,t.specs,W),S(`install: wrote %s (%d entries)`,QL,W.length));let X=W;if(t.workspaceNames&&t.workspaceNames.size>0){let n=X.length;X=X.filter(n=>!t.workspaceNames.has(n.name));let C=n-X.length;C>0&&S(`install: %d workspace-provided package(s) symlinked, not fetched`,C)}if(t.linkedNames&&t.linkedNames.size>0){let n=X.length;X=X.filter(n=>!t.linkedNames.has(n.name));let C=n-X.length;C>0&&S(`install: %d dev-linked package(s) provided by a local checkout, not fetched`,C)}let Z=applyPlatformFilter(X,I,H,S);return S(`install: downloading %d tarball(s)`,Z.length),await downloadAndExtractAll(Z,t.prefix,n,S,t.signal,C),await linkBins(Z,t.prefix,S),warnMissingNativeBuilds(Z,t.prefix,S),S(`install: done`),topLevelResolutions(t.specs,W)}function assertNoExtraneous(t,n){let S=findExtraneous({prefix:t,installed:scanPrefix(t),expected:n});if(S.length!==0)throw Error(formatExtraneousError(S,t))}function errMsg(t){return t instanceof Error?t.message:String(t)}function applyPlatformFilter(t,n,S,C){let N=[],F=0;for(let I of t){let t=I.platform;if(!t||!declaresPlatform(t)){N.push(I);continue}let H=checkPlatform(t,n);if(H.ok){N.push(I);continue}let W=`${I.name}@${I.version}`;if(!I.optional){if(S){C(`platform-forced: %s (required, incompatible, installed anyway via --force)`,W),N.push(I);continue}throw badPlatformError(W,H)}I.inert=!0,F++,C(`platform-skip: %s (%s) current=%s required=%s`,W,I.installPath,JSON.stringify(H.current),JSON.stringify(H.required))}return F>0&&C(`install: %d optional package(s) inert — not installable on %s`,F,describePlatformTarget(n)),N}function warnMissingNativeBuilds(t,n,S){let C=process.platform,N=process.arch,F=[`preinstall`,`install`,`postinstall`];for(let I of t){let t=wn(n,I.installPath),H;try{H=JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))?.scripts}catch{continue}if(!H||typeof H!=`object`)continue;let W=F.find(t=>typeof H[t]==`string`);if(W===void 0)continue;let q=!1;try{let n=wn(t,`prebuilds`);for(let t of readdirSync(n))if(t.startsWith(`${C}-`)&&readdirSync(wn(n,t)).length>0){q=!0;break}}catch{}if(!q)try{q=readdirSync(wn(t,`build`,`Release`)).some(t=>t.endsWith(`.node`)||t.endsWith(`.so`))}catch{}q||S("install: WARNING — %s declares a native `%s` build script but ships no %s-%s prebuild, and gjsify install does not run build scripts (node-free). It will not load until built: run `node-gyp rebuild` in %s, or use a version that ships a %s-%s prebuild.",I.name,W,C,N,I.installPath,C,N)}}function topLevelResolutions(t,n){let S=new Map;for(let t of n)t.installPath===`node_modules/${t.name}`&&S.set(t.name,t);let C=[];for(let n of t){let t=parseSpecName(n),N=S.get(t);N&&C.push({name:N.name,version:N.version})}return C}function parseSpecName(t){if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)return t;let S=t.indexOf(`@`,n+1);return S===-1?t:t.slice(0,S)}let n=t.indexOf(`@`);return n===-1?t:t.slice(0,n)}async function resolveDeps(t,n,S,C,N,F,I,H,W,q,Y,X){I?.beginPhase(`resolve`,t.length);let applyOverride=(t,n)=>{if(!C)return n;let N=C[t];return typeof N!=`string`||N.length===0||N===n?n:(S(`install: override %s %s → %s`,t,n,N),N)},Z=new Map,fetchPkg=t=>{let C=Z.get(t);if(C)return C;let N=fetchPackumentWithDiskCache(t,n,S,F,`full`);return Z.set(t,N),N},te=new Map,ne=new Map,re=new Set,ie=new Map,ae=t.map(parseSpec$1).map(t=>{let n=applyOverride(t.name,t.range),S=ie.get(t.name);S||(S=new Map,ie.set(t.name,S));let C=S.get(n);C||(C=new Set,S.set(n,C));for(let n of q?.get(`${t.name}@${t.range}`)??[])C.add(n);return{from:null,name:t.name,range:n,required:!Y?.has(t.name)}});for(;ae.length>0;){let t=ae.splice(0,ae.length),n=[],C=new Set;for(let S of t)Z.has(S.name)||C.has(S.name)||(C.add(S.name),n.push(S.name));await prefetchPackuments(n,fetchPkg,F);for(let n=0;n<t.length;n++){let C=t[n];if(W?.has(C.name))continue;let F=findVisible(C.from,C.name,te);if(F&&satisfiesRange(F.version,C.range))continue;if(C.peerOf){let t=C.from===null?`node_modules/${C.name}`:`${C.from}/node_modules/${C.name}`,n=te.get(t);if(n){ge.warn(`[gjsify] warning: peer dependency conflict: ${C.peerOf.name}@${C.peerOf.version} wants ${C.name}@${C.range}, but ${n.version} is installed at ${n.installPath} — keeping it (npm's non-strict behaviour).`);continue}}let q=null;try{let F=await fetchPkg(C.name),W=preferredVersionFor(H?.get(C.name),C.range);if(q=pickVersion(F,C.range,W),!q)throw Error(`No version of ${C.name} satisfies ${C.range}`);let Y=F.versions[q];if(!Y)throw Error(`Packument for ${C.name} promised ${q} but no entry exists`);let X=decidePlacement(C.from,C.name,q,ne),Z={name:C.name,version:q,tarballUrl:Y.dist.tarball,integrity:Y.dist.integrity,installPath:X,dependencies:Y.dependencies??{},optionalDependencies:Y.optionalDependencies??{},peerDependencies:nonEmpty(Y.peerDependencies),peerDependenciesMeta:nonEmpty(Y.peerDependenciesMeta),bin:Y.bin,platform:platformDeclarationOf(Y),optional:!C.required};if(te.set(X,Z),X===`node_modules/${C.name}`&&ne.set(C.name,Z),S(`resolve: %s@%s ← %s (at %s)`,C.name,q,C.range,X),I?.update({phase:`resolve`,current:te.size,total:te.size+(t.length-n-1)+ae.length,name:`${C.name}@${q}`}),!N){let t=parentInstallPath(X);for(let[n,S]of requiredPeerEntries(Z))ae.push({from:t,name:n,range:applyOverride(n,S),required:!Z.optional,peerOf:Z});for(let[t,n]of requiredDepEntries(Z))ae.push({from:X,name:t,range:applyOverride(t,n),required:!Z.optional});for(let[t,n]of Object.entries(Z.optionalDependencies))ae.push({from:X,name:t,range:applyOverride(t,n),required:!1})}}catch(t){if(X?.has(C.name)&&t instanceof PackageNotFoundError){S(`resolve: dev-linked %s not published — provided by the local checkout`,C.name);continue}if(!C.required){re.add(edgeKey(C.peerOf?.installPath??C.from,C.name)),S(`resolve: optional dep %s@%s skipped (%s)`,C.name,C.range,errMsg(t));continue}throw t}}}return I?.endPhase(`resolve`),emitTopLevelConflictWarnings(ie,ne),{nodes:Array.from(te.values()),skippedEdges:re}}function platformDeclarationOf(t){let n={os:t.os,cpu:t.cpu,libc:t.libc};return declaresPlatform(n)?n:void 0}function edgeKey(t,n){return`${t??``}\n${n}`}function parseEdgeKey(t){let n=t.indexOf(`
920
+ `),S=t.slice(0,n);return{from:S===``?null:S,name:t.slice(n+1)}}function requiredTopLevelNames(t,n){let S=new Set;for(let C of t){let t=parseSpecName(C);n?.has(t)||S.add(t)}return S}function requiredDepEntries(t){let n=[];for(let[S,C]of Object.entries(t.dependencies))S in t.optionalDependencies||n.push([S,C]);return n}function requiredPeerEntries(t){let n=[];for(let[S,C]of Object.entries(t.peerDependencies??{}))t.peerDependenciesMeta?.[S]?.optional!==!0&&(S in t.dependencies||S in t.optionalDependencies||n.push([S,C]));return n}function computeOptionalFlags(t,n,S){let C=new Map;for(let n of t)C.set(n.installPath,n);let N=new Set,F=[],enter=t=>{N.has(t.installPath)||(N.add(t.installPath),F.push(t.installPath))};for(let t of n){let n=C.get(`node_modules/${t}`);n&&enter(n)}for(;F.length>0;){let t=F.pop();if(t===void 0)break;let n=C.get(t);if(n)for(let[S]of[...requiredDepEntries(n),...requiredPeerEntries(n)]){let n=findVisible(t,S,C);n&&enter(n)}}let I=0;for(let n of t){let t=!N.has(n.installPath);(n.optional??!1)!==t&&I++,n.optional=t}S(`install: optionality fixpoint — %d of %d node(s) reachable only via optional edges%s`,t.length-N.size,t.length,I>0?`; corrected ${I} incoming flag(s)`:``)}function reachableInstallPaths(t,n){let S=new Map;for(let n of t)S.set(n.installPath,n);let C=new Set,N=[],enter=t=>{!t||C.has(t.installPath)||(C.add(t.installPath),N.push(t))};for(let t of n)enter(S.get(`node_modules/${t}`));for(let t=N.pop();t;t=N.pop()){let n=[...Object.keys(t.dependencies),...Object.keys(t.optionalDependencies),...requiredPeerEntries(t).map(([t])=>t)];for(let C of n)enter(findVisible(t.installPath,C,S))}return C}function readLockfileNodes(t){let n=readLockfile(t);return n?lockfileToNodes(n):null}function assertRequiredEdgesResolved(t,n){if(n.size===0)return;let S=new Map;for(let n of t)S.set(n.installPath,n);for(let t of n){let{from:n,name:C}=parseEdgeKey(t);if(n===null)continue;let N=S.get(n);if(N&&!N.optional&&!(C in N.optionalDependencies))throw Error(`install: required dependency ${C} of ${N.name}@${N.version} (${N.installPath}) could not be resolved.\nThe failure was tolerated during the walk because ${N.name} looked optional at that point, but the final dependency graph makes it required — so ${C} is required too and the tree would be incomplete.\nRe-run with --verbose and look for the "resolve: optional dep ${C}@… skipped (…)" line for the underlying cause.`)}}function emitTopLevelConflictWarnings(t,n){for(let[S,C]of t){if(C.size<2)continue;let t=n.get(S);if(!t)continue;let describe=(t,n)=>n.size>0?`${t} (requested by ${[...n].join(`, `)})`:t,N=[],F=[];for(let[n,S]of C){let C;try{C=satisfies(t.version,new YP(n))}catch{continue}(C?N:F).push(describe(n,S))}F.length!==0&&ge.warn(`[gjsify] warning: version conflict for ${S}: installed ${t.version} at ${t.installPath} — does NOT satisfy ${F.join(`, `)}`+(N.length>0?`; satisfies ${N.join(`, `)}`:``)+`. One hoisted copy serves all requesters until the per-workspace dedup pass lands (Phase D.8).`)}}async function fetchPackumentWithDiskCache(t,n,S,C,N=`corgi`){let F=registryFor(t,n),I=N===`full`,H=getCachedPackument(F,t,N),onRetry=({attempt:n,error:C,delayMs:F})=>{S(`packument %s (%s): retry %d after %dms (%s)`,t,N,n,F,errMsg(C))},W=await fetchPackumentConditional(t,{npmrc:n,signal:C,ifNoneMatch:H?.etag,fullMetadata:I,onRetry});return W.status===`not-modified`&&H?(S(`packument-cache-hit: %s (%s, 304, etag %s)`,t,N,H.etag),H.packument):W.status===`fresh`&&W.packument?(W.etag&&putCachedPackument(F,t,W.etag,W.packument,N),W.packument):fetchPackument(t,{npmrc:n,signal:C,fullMetadata:I,onRetry})}async function prefetchPackuments(t,n,S){if(t.length===0)return;let C=0,N=Math.max(1,Math.min(ZL,t.length)),worker=async()=>{for(;C<t.length;){if(S?.aborted)return;let N=t[C++];try{await n(N)}catch{}}};await Promise.all(Array.from({length:N},()=>worker()))}function findVisible(t,n,S){let C=[];if(t!==null){C.push(`${t}/node_modules/${n}`);let S=t;for(;;){let t=S.lastIndexOf(`/node_modules/`);if(t<0||(S=S.slice(0,t),C.push(`${S}/node_modules/${n}`),S===``))break}}C.push(`node_modules/${n}`);for(let t of C){let n=S.get(t);if(n)return n}return null}function parentInstallPath(t){let n=t.lastIndexOf(`/node_modules/`);return n<0?null:t.slice(0,n)}function decidePlacement(t,n,S,C){let N=C.get(n);return!N||N.version===S||t===null?`node_modules/${n}`:`${t}/node_modules/${n}`}function satisfiesRange(t,n){try{return satisfies(t,new YP(n))}catch{return!1}}function readLockfile(t){if(!existsSync(t))return null;try{let n=JSON.parse(readFileSync(t,`utf-8`));return!eR.has(n.lockfileVersion)||!n.packages||typeof n.packages!=`object`?null:n}catch{return null}}function writeLockfile(t,n,S){let C={},N=[...S].sort((t,n)=>t.installPath<n.installPath?-1:+(t.installPath>n.installPath));for(let t of N)C[t.installPath]={version:t.version,resolved:t.tarballUrl,integrity:t.integrity,dependencies:Object.keys(t.dependencies).length>0?t.dependencies:void 0,optionalDependencies:Object.keys(t.optionalDependencies).length>0?t.optionalDependencies:void 0,peerDependencies:nonEmpty(t.peerDependencies),peerDependenciesMeta:nonEmpty(t.peerDependenciesMeta),bin:t.bin,os:t.platform?.os,cpu:t.platform?.cpu,libc:t.platform?.libc,optional:t.optional?!0:void 0};let F={lockfileVersion:$L,requested:[...n],packages:C,peersResolved:!0};atomicWriteStrict(t,JSON.stringify(F,null,2)+`
921
921
  `)}function nonEmpty(t){return t&&Object.keys(t).length>0?t:void 0}function buildPreferredVersions(t){let n=new Map;for(let[S,C]of Object.entries(t.packages)){let t=nameFromInstallPath(S),N=n.get(t);N||(N=new Set,n.set(t,N)),N.add(C.version)}return n}function preferredVersionFor(t,n){if(!t||t.size===0)return;let S;for(let C of t)satisfiesRange(C,n)&&(S===void 0||new SemVer(C).compare(new SemVer(S))>0)&&(S=C);return S}function lockfileToNodes(t){return Object.entries(t.packages).map(([t,n])=>{let S={os:n.os,cpu:n.cpu,libc:n.libc};return{name:nameFromInstallPath(t),version:n.version,tarballUrl:n.resolved,integrity:n.integrity,installPath:t,dependencies:n.dependencies??{},optionalDependencies:n.optionalDependencies??{},peerDependencies:n.peerDependencies,peerDependenciesMeta:n.peerDependenciesMeta,bin:n.bin,platform:declaresPlatform(S)?S:void 0,optional:n.optional===!0}})}function nameFromInstallPath(t){let n=t.lastIndexOf(`/node_modules/`);return n<0?t.replace(/^node_modules\//,``):t.slice(n+14)}function lockfileMatchesRequest(t,n){if(t.requested.length!==n.length)return!1;let S=[...t.requested].sort(),C=[...n].sort();return S.every((t,n)=>t===C[n])}function describeLockfileDrift(t,n){let S=new Set(t.requested),C=new Set(n),N=[],F=[];for(let t of C)S.has(t)||N.push(t);for(let t of S)C.has(t)||F.push(t);if(N.length===0&&F.length===0)return null;let I=[];return N.length>0&&I.push(` + ${N.sort().join(`
922
922
  + `)}`),F.length>0&&I.push(` - ${F.sort().join(`
923
923
  - `)}`),I.join(`
924
- `)}function parseSpec$1(t){if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n<0)throw Error(`Invalid spec (scoped name without slash): ${t}`);let S=t.indexOf(`@`,n);return S<0?{name:t,range:`latest`}:{name:t.slice(0,S),range:t.slice(S+1)||`latest`}}let n=t.indexOf(`@`);return n<0?{name:t,range:`latest`}:{name:t.slice(0,n),range:t.slice(n+1)||`latest`}}function pickVersion(t,n,S){if(S&&t.versions[S]&&satisfiesRange(S,n))return S;if(t[`dist-tags`][n])return t[`dist-tags`][n];let C;try{C=new YP(n)}catch{throw Error(`Invalid version range for ${t.name}: ${n}`)}return maxSatisfying(Object.keys(t.versions).filter(t=>{try{return new SemVer(t),!0}catch{return!1}}),C)}async function downloadAndExtractAll(t,n,S,C,N,F){let I=[...t].sort((t,n)=>depth$1(t.installPath)-depth$1(n.installPath)||(t.installPath<n.installPath?-1:1)),H=[],W=Math.max(1,Math.min(KL,I.length));F?.beginPhase(`download`,I.length);let q=0,Y=0,tickProgress=(t,n)=>{q++,n&&Y++,F?.update({phase:`download`,current:q,total:I.length,name:`${t.name}@${t.version}`})},X=0,Z=I.findIndex(t=>depth$1(t.installPath)>1),te=Z<0?I.length:Z;for(;X<te;){if(N?.aborted)throw abortError(N);let t=I[X++];if(!t)break;tickProgress(t,await extractOne(t,n,S,C,N))}for(let t=0;t<W;t++)H.push((async()=>{for(;;){if(N?.aborted)throw abortError(N);let t=X++;if(t>=I.length)return;let F=I[t];if(!F)return;let H=await extractOne(F,n,S,C,N);tickProgress(F,H)}})());await Promise.all(H),F?.endPhase(`download`),Y>0&&C(`install: %d/%d package(s) already up to date — extracted %d`,Y,I.length,I.length-Y)}function isAlreadyExtracted(t,n){let S=wn(t,`package.json`),C;try{C=readFileSync(S,`utf-8`)}catch{return!1}try{let t=JSON.parse(C);return!(t.version!==n.version||typeof t.name==`string`&&t.name!==n.name)}catch{return!1}}async function extractOne(t,n,S,C,N){let F=wn(n,t.installPath);if(assertNodeModulesDest(F,t,n),process.env.GJSIFY_INSTALL_FORCE_EXTRACT!==`1`&&isAlreadyExtracted(F,t))return C(`up-to-date: %s@%s (already extracted at %s)`,t.name,t.version,t.installPath),!0;let I=await getCachedTarball(t.integrity);return I?C(`cache-hit: %s@%s ← %s`,t.name,t.version,t.integrity):(I=await getForeignCachedTarball(t.integrity))?(C(`npm-cache-hit: %s@%s ← %s`,t.name,t.version,t.integrity),putCachedTarball(t.integrity,I)):(C(`fetch: %s@%s ← %s (→ %s)`,t.name,t.version,t.tarballUrl,t.installPath),I=await fetchTarball(t.tarballUrl,{npmrc:S,signal:N,integrity:t.integrity,onRetry:({attempt:n,error:S,delayMs:N})=>{C(`tarball %s@%s: retry %d after %dms (%s)`,t.name,t.version,n,N,errMsg(S))}}),putCachedTarball(t.integrity,I)),rmWithRetry(F),mkdirSync(F,{recursive:!0}),await extractWithStallGuard(I,F,t,N),!1}async function extractWithStallGuard(t,n,S,C){if(XL===0&&!C){await extractTarball(t,n);return}let N,onAbort;try{await new Promise((F,I)=>{if(process.env.GJSIFY_TEST_HANG_EXTRACT!==`1`&&extractTarball(t,n).then(()=>F(),I),XL>0&&(N=setTimeout(()=>{I(Error(`gjsify install: extract of ${S.name}@${S.version} stalled for ${Math.round(XL/1e3)}s (${S.installPath}) — the tarball decompress/write never completed. This is usually a dropped Gio stream event under GJS; re-run the install. Override the cap with GJSIFY_EXTRACT_STALL_MS=<ms> (0 disables it).`))},XL),N.unref?.()),C){if(C.aborted){I(abortError(C));return}onAbort=()=>I(abortError(C)),C.addEventListener(`abort`,onAbort,{once:!0})}})}finally{N&&clearTimeout(N),C&&onAbort&&C.removeEventListener(`abort`,onAbort)}}function abortError(t){let n=t&&`reason`in t?t.reason:void 0;if(n instanceof Error)return n;let S=Error(`Aborted`);return S.name=`AbortError`,S}function assertNodeModulesDest(t,n,S){if(!t.split(jn).includes(`node_modules`))throw Error(`gjsify install: refusing to extract ${n.name}@${n.version} into ${t} — target is not inside a node_modules/ directory. This would overwrite working-tree files. A workspace package likely leaked into the fetch queue (it must be symlinked, not fetched).`);let C;try{C=realpathSync(t)}catch{return}if(!C.split(jn).includes(`node_modules`))throw Error(`gjsify install: refusing to extract ${n.name}@${n.version} — ${t} resolves to ${C}, which is outside any node_modules/ directory (likely a symlink to a workspace source tree). Extracting here would delete working-tree source files.${devLinkRemedy(S,t)}`)}function devLinkRemedy(t,n){let S=devLinkRoot(t),C=devLinkPath(S);return`\n If a \`gjsify link\` development link put it there${existsSync(C)?` — ${C} is present`:``}: run \`gjsify unlink\` in ${S} to remove the links and restore the registry copies, or \`gjsify link <checkout> --packages …\` to re-select. If no override is left, delete ${n} by hand and re-run.`}function depth$1(t){return t.split(`/node_modules/`).length}function readShebang$1(t){let n;try{n=readFileSync(t,`utf-8`)}catch{return null}return parseShebang(n.trimStart().split(/\r*\n/,1)[0]??``)}function writeBinEntry(t){let{binDir:n,binName:S,targetAbs:C,gjs:N,nodeFallbackAbs:F}=t,I=t.platform??process.platform,H=wn(n,S);if(N){let t=isGjsBundlePath(C);for(let t of[H,`${H}.cmd`,`${H}.ps1`])rmWithRetry(t);writeFileSync(H,buildShLauncher(C,{envPreamble:N.envPreamble,isGjsBundle:t,nodeFallbackAbs:F}));try{chmodSync(H,493)}catch{}if(I===`win32`&&t){let t=N.prebuildDirs.join(`;`),n=buildLauncherShims({interpreter:`gjs`,interpreterArgs:[`-m`],target:C,prependEnv:N.prebuildDirs.length>0?{GI_TYPELIB_PATH:t,PATH:t}:{},fallback:F===void 0?void 0:{interpreter:`node`,target:F}});writeFileSync(`${H}.cmd`,n.cmd),writeFileSync(`${H}.ps1`,n.ps1)}return}if(I===`win32`){let{sh:t,cmd:S,ps1:N}=buildCmdShim(Tn(n,C).split(`\\`).join(`/`),readShebang$1(C));for(let[n,C]of[[H,t],[`${H}.cmd`,S],[`${H}.ps1`,N]]){rmWithRetry(n),writeFileSync(n,C);try{chmodSync(n,493)}catch{}}return}rmWithRetry(H);let W=Tn(n,C);try{symlinkSync(W,H)}catch{copyFileSync(C,H),chmodSync(H,493)}}async function linkBins(t,n,S){let C=wn(n,`node_modules`,`.bin`),N=0,F,gjsEnvForPrefix=()=>{if(F===void 0){let t=detectNativePackages(n).map(t=>t.prebuildsDir);F={envPreamble:buildNativeEnvPreamble(n,t),prebuildDirs:t}}return F};for(let S of t){if(depth$1(S.installPath)!==1)continue;let t=wn(n,S.installPath),F=readInstalledManifest(t)??(S.bin===void 0?null:{bin:S.bin});if(F===null)continue;let I=pickBinMap(S.name,F);if(!(I===null||I.map.size===0)){mkdirSync(C,{recursive:!0});for(let[n,S]of I.map){let F=wn(t,S);if(!existsSync(F))continue;try{chmodSync(F,493)}catch{}let H=I.nodeFallback?.get(n),W=H===void 0?void 0:wn(t,H);writeBinEntry({binDir:C,binName:n,targetAbs:F,gjs:I.isGjsBin?gjsEnvForPrefix():void 0,nodeFallbackAbs:W!==void 0&&existsSync(W)?W:void 0}),N++}}}N>0&&S(`bin: linked %d entry(ies) under .bin/`,N)}function readInstalledManifest(t){try{let n=readFileSync(wn(t,`package.json`),`utf-8`);return JSON.parse(n)}catch{return null}}function rmWithRetry(t){rmSync(t,{recursive:!0,force:!0,maxRetries:10,retryDelay:100})}async function loadNpmrc$1(t){let n=homedir(),S={registry:t.registry??qm,scopes:{},authTokens:{},basicAuth:{}};for(let C of[wn(n,`.npmrc`),wn(t.prefix,`.npmrc`)])if(existsSync(C))try{let t=parseNpmrc(readFileSync(C,`utf-8`));S={...S,...t,scopes:{...S.scopes,...t.scopes}}}catch(t){ge.warn(`gjsify install: ignoring malformed ${C}: ${t.message}`)}let C=process.env.npm_config_registry;return C&&(S.registry=C),t.registry&&(S.registry=t.registry),S}function makeLogger(t){return t?(t,...n)=>{let S=t.replace(/%s|%d/g,()=>String(n.shift()));process.stderr.write(`gjsify install: ${S}\n`)}:()=>{}}var KL,qL,JL,YL,XL,ZL=__esmMin(()=>{_e(),Rd(),Pn(),Lg(),XP(),eh(),hL(),oL(),TL(),DL(),kL(),AL(),VI(),CF(),jL(),WL(),VL(),zL(),KL=Number(process.env.GJSIFY_INSTALL_CONCURRENCY??`16`)||16,qL=`gjsify-lock.json`,JL=4,YL=new Set([2,3,JL]),__name$1(parseSpec$1,`parseSpec`),XL=(()=>{let t=process.env.GJSIFY_EXTRACT_STALL_MS;if(t===void 0)return 12e4;let n=Number(t);return Number.isFinite(n)&&n>=0?n:12e4})(),__name$1(depth$1,`depth`),__name$1(readShebang$1,`readShebang`),__name$1(loadNpmrc$1,`loadNpmrc`)}),QL=__exportAll$5({installPackages:()=>installPackages,makeProgressReporter:()=>makeProgressReporter});async function installPackages(t){if($L===`npm`)return await installViaNpm(t),{installed:[]};let{installPackagesNative:n}=await Promise.resolve().then(()=>(ZL(),GL));return{installed:await n(t)}}async function installViaNpm({prefix:t,specs:n,verbose:S,registry:C}){if(n.length===0)throw Error(`installPackages: empty specs list`);writeFileSync(wn(t,`package.json`),JSON.stringify({name:`gjsify-dlx-cache`,version:`0.0.0`,private:!0},null,2)),C&&writeFileSync(wn(t,`.npmrc`),`registry=${C}\n`);let{code:N}=await spawnToCompletion(`npm`,[`install`,`--no-package-lock`,`--no-audit`,`--no-fund`,`--prefix`,t,...S?[`--loglevel`,`verbose`]:[`--loglevel`,`warn`],...n],{completion:`return`,notFound:t=>Error(`npm not found on PATH — install Node.js, or unset GJSIFY_INSTALL_BACKEND to use the default native backend (${t.message})`)});if(N!==0)throw Error(`npm install exited with code ${N}`)}var $L,eR=__esmMin(()=>{Rd(),Pn(),V_(),uL(),$L=process.env.GJSIFY_INSTALL_BACKEND??`native`});function defaultGlobalLayout(){let t=process.env.GJSIFY_GLOBAL_PREFIX,n=process.env.GJSIFY_GLOBAL_BIN_DIR,S=homedir(),C=process.env.XDG_DATA_HOME??wn(S,`.local`,`share`);return{prefix:t??wn(C,`gjsify`,`global`),binDir:n??wn(S,`.local`,`bin`)}}function hasBundlerEngineInstalled(t){let n=new Set(detectNativePackages(t).map(t=>t.name));if(n.has(`@gjsify/rolldown-native`))return!0;let S=detectHostLibc(process.platform);return hostPlatformTokens(process.platform,process.arch,S).some(t=>n.has(platformPackageName(nR,t)))}async function installGjsEnginePackages(t,n,S={}){let C=S.verbose??!1,N=S.installFn??(async n=>{let{installPackages:S}=await Promise.resolve().then(()=>(eR(),QL));await S({prefix:t,specs:[n],verbose:C})});for(let t of tR){let S=n?`${t}@${n}`:t;try{await N(S)}catch(S){let N=S instanceof Error?S.message:String(S);t===`@gjsify/rolldown-native`?ge.warn(`\nWarning: could not install the GJS bundler engine ${t}@${n} — ${N}\n \`gjsify build\` (and storybook / flatpak) will fail under GJS until it is present.\n This usually means no prebuild is published for this platform (${process.platform}/${process.arch}).`):C&&ge.warn(`gjsify install: optional GJS engine ${t}@${n} not installed — ${N}`)}}}function linkGlobalBins(t,n){mkdirSync(n.binDir,{recursive:!0});let S=[],C=detectNativePackages(n.prefix).map(t=>t.prebuildsDir),N=buildNativeEnvPreamble(n.prefix,C);for(let F of t){let t=wn(n.prefix,`node_modules`,F),I=wn(t,`package.json`);if(!existsSync(I))continue;let H=pickBinMap(F,readJson(I));if(!(H===null||H.map.size===0))for(let[F,I]of H.map){let W=wn(t,I);if(!existsSync(W))continue;try{chmodSync(W,493)}catch{}let q=wn(n.binDir,F);for(let t of[q,`${q}.cmd`,`${q}.ps1`])rmSync(t,{force:!0,maxRetries:10,retryDelay:100});let Y=isGjsBundlePath(W),X=H.nodeFallback?.get(F),Z=X===void 0?void 0:wn(t,X),te=Z!==void 0&&existsSync(Z)?Z:void 0;if(writeFileSync(q,buildShLauncher(W,{envPreamble:N,isGjsBundle:Y,nodeFallbackAbs:te})),chmodSync(q,493),process.platform===`win32`){let t=C.join(`;`),n=Y&&C.length>0?{GI_TYPELIB_PATH:t,PATH:t}:{},S=Y?null:readShebangOf(W),N=buildLauncherShims(Y?{interpreter:`gjs`,interpreterArgs:[`-m`],target:W,prependEnv:n,fallback:te===void 0?void 0:{interpreter:`node`,target:te}}:{interpreter:S?.prog||`node`,interpreterArgs:S?.args.trim()?S.args.trim().split(/\s+/):[],target:W});writeFileSync(`${q}.cmd`,N.cmd),writeFileSync(`${q}.ps1`,N.ps1)}S.push({name:F,target:W,link:q})}}return S}function readShebangOf(t){try{return parseShebang(readFileSync(t,`utf-8`).trimStart().split(/\r*\n/,1)[0]??``)}catch{return null}}function readJson(t){return JSON.parse(readFileSync(t,`utf-8`))}function globalLayoutIsDefault(t=process.env){return!t.GJSIFY_GLOBAL_PREFIX&&!t.GJSIFY_GLOBAL_BIN_DIR}function pathFor$1(t){return t===`win32`?hn:pn}function searchPathEntries(t,n){let S=pathFor$1(n),C=n===`win32`?`;`:`:`;return t.split(C).filter(Boolean).map(t=>S.resolve(t))}function binDirOnPath(t){let n=pathFor$1(process.platform).resolve(t);return searchPathEntries(process.env.PATH??``,process.platform).includes(n)}function resolveBinOnPath(t,n={}){let S=n.platform??process.platform,C=n.pathValue??process.env.PATH??``,N=n.exists??existsSync,F=S===`win32`?[...(n.pathExt??process.env.PATHEXT??rR).split(`;`).filter(Boolean).map(t=>t.startsWith(`.`)?t:`.${t}`),``]:[``],I=pathFor$1(S);for(let n of searchPathEntries(C,S))for(let S of F){let C=I.join(n,`${t}${S}`);if(N(C))return C}return null}function specToPackageName(t){if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n<0)return t;let S=t.indexOf(`@`,n);return S<0?t:t.slice(0,S)}let n=t.indexOf(`@`);return n<0?t:t.slice(0,n)}var tR,nR,rR,iR=__esmMin(()=>{_e(),Rd(),Lg(),Pn(),CF(),VI(),tR=[`@gjsify/rolldown-native`,`@gjsify/lightningcss-native`,`@gjsify/oxfmt-native`],nR=`@gjsify/rolldown-native`,__name$1(pathFor$1,`pathFor`),rR=`.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC`});function usingSelfShim(){return oR}function pathWithoutSelfShim(t=process.env.PATH??``,n=process.env.GJSIFY_SHIM_DIR,S=Mn){return n?t.split(S).filter(t=>t!==n).join(S):t}function needsSelfShim(t){if(t.gjs)return!0;let n=Tn(t.workspaceRoot,t.selfEntry);return n===``||n.startsWith(`..`)||Cn(n)}function ensureGjsifyShimOnPath(){if(aR)return;aR=!0;let t=process.env.GJSIFY_SHIM_DIR;if(t&&existsSync(wn(t,`gjsify`))){oR=!0,(process.env.PATH??``).split(Mn).includes(t)||(process.env.PATH=t+Mn+(process.env.PATH??``));return}let n=isGjs(),S=fileURLToPath(n?import.meta.url:new URL(`../index.js`,import.meta.url));if(!needsSelfShim({gjs:n,selfEntry:S,workspaceRoot:findWorkspaceRoot(process.cwd())??process.cwd()}))return;let C=n?process.env.GJS_CONSOLE||`gjs`:`node`,N=n?selfShimPreamble(S):``,F={gjsify:n?buildShLauncher(S,{isGjsBundle:!0,envPreamble:N,gjs:C}):`#!/bin/sh\nexec "${C}" "${S}" "$@"\n`};if(!n&&process.platform===`win32`){let{cmd:t,ps1:n}=buildLauncherShims({interpreter:C,interpreterArgs:[],target:S});F[`gjsify.cmd`]=t,F[`gjsify.ps1`]=n}let I=buildNodeShim(n,S,N);I&&(F[`${sR}/node`]=I);let H=materializeShimDir(F);oR=!0,process.env.GJSIFY_SHIM_DIR=H,process.env.PATH=H+Mn+(process.env.PATH??``)}function materializeShimDir(t,n=gjsifyCacheRoot(`shim`,`v1`)){let S=Object.keys(t).sort(),C=createHash(`sha256`);for(let n of S)C.update(`${n}\0${t[n]}\0`);let N=C.digest(`hex`).slice(0,16);try{return writeShimDir(wn(n,N),t,S)}catch{return writeShimDir(mkdtempSync(wn(tmpdir(),`gjsify-shim-`)),t,S)}}function writeShimDir(t,n,S){for(let C of S){let S=wn(t,C);if(existsSync(S)&&readFileSync(S,`utf8`)===n[C])continue;mkdirSync(En(S),{recursive:!0});let N=`${S}.tmp.${process.pid}`;try{writeFileSync(N,n[C],{mode:493}),chmodSync(N,493),renameSync(N,S)}catch(t){throw rmSync(N,{force:!0}),t}}return t}function selfShimScanRoot(t){let n=t.search(/[\\/]node_modules[\\/]/);return n>0?t.slice(0,n):findWorkspaceRoot(En(t))??En(t)}function selfShimPreamble(t){let n=[];try{n=detectNativePackages(En(t)).map(t=>t.prebuildsDir)}catch{}return buildNativeEnvPreamble(selfShimScanRoot(t),n)}function dyldCarryPreamble(t,n){return t===`darwin`?Object.keys(n).filter(t=>/^DYLD_[A-Z_]+$/.test(t)&&n[t]).sort().map(t=>`${t}=${shQuoteArg(n[t])}\nexport ${t}\n`).join(``):``}function nodeShimDir(){let t=process.env.GJSIFY_SHIM_DIR;if(!t)return null;let n=wn(t,sR);return existsSync(wn(n,`node`))?n:null}function buildNodeShim(t,n,S){if(!t||resolveBinOnPath(`node`))return null;let C=process.env.GJS_CONSOLE||`gjs`;return`#!/bin/sh
924
+ `)}function parseSpec$1(t){if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n<0)throw Error(`Invalid spec (scoped name without slash): ${t}`);let S=t.indexOf(`@`,n);return S<0?{name:t,range:`latest`}:{name:t.slice(0,S),range:t.slice(S+1)||`latest`}}let n=t.indexOf(`@`);return n<0?{name:t,range:`latest`}:{name:t.slice(0,n),range:t.slice(n+1)||`latest`}}function pickVersion(t,n,S){if(S&&t.versions[S]&&satisfiesRange(S,n))return S;if(t[`dist-tags`][n])return t[`dist-tags`][n];let C;try{C=new YP(n)}catch{throw Error(`Invalid version range for ${t.name}: ${n}`)}return maxSatisfying(Object.keys(t.versions).filter(t=>{try{return new SemVer(t),!0}catch{return!1}}),C)}async function downloadAndExtractAll(t,n,S,C,N,F){let I=[...t].sort((t,n)=>depth$1(t.installPath)-depth$1(n.installPath)||(t.installPath<n.installPath?-1:1)),H=[],W=Math.max(1,Math.min(ZL,I.length));F?.beginPhase(`download`,I.length);let q=0,Y=0,tickProgress=(t,n)=>{q++,n&&Y++,F?.update({phase:`download`,current:q,total:I.length,name:`${t.name}@${t.version}`})},X=0,Z=I.findIndex(t=>depth$1(t.installPath)>1),te=Z<0?I.length:Z;for(;X<te;){if(N?.aborted)throw abortError(N);let t=I[X++];if(!t)break;tickProgress(t,await extractOne(t,n,S,C,N))}for(let t=0;t<W;t++)H.push((async()=>{for(;;){if(N?.aborted)throw abortError(N);let t=X++;if(t>=I.length)return;let F=I[t];if(!F)return;let H=await extractOne(F,n,S,C,N);tickProgress(F,H)}})());await Promise.all(H),F?.endPhase(`download`),Y>0&&C(`install: %d/%d package(s) already up to date — extracted %d`,Y,I.length,I.length-Y)}function isAlreadyExtracted(t,n){let S=wn(t,`package.json`),C;try{C=readFileSync(S,`utf-8`)}catch{return!1}try{let t=JSON.parse(C);return!(t.version!==n.version||typeof t.name==`string`&&t.name!==n.name)}catch{return!1}}async function extractOne(t,n,S,C,N){let F=wn(n,t.installPath);if(assertNodeModulesDest(F,t,n),process.env.GJSIFY_INSTALL_FORCE_EXTRACT!==`1`&&isAlreadyExtracted(F,t))return C(`up-to-date: %s@%s (already extracted at %s)`,t.name,t.version,t.installPath),!0;let I=await getCachedTarball(t.integrity);return I?C(`cache-hit: %s@%s ← %s`,t.name,t.version,t.integrity):(I=await getForeignCachedTarball(t.integrity))?(C(`npm-cache-hit: %s@%s ← %s`,t.name,t.version,t.integrity),putCachedTarball(t.integrity,I)):(C(`fetch: %s@%s ← %s (→ %s)`,t.name,t.version,t.tarballUrl,t.installPath),I=await fetchTarball(t.tarballUrl,{npmrc:S,signal:N,integrity:t.integrity,onRetry:({attempt:n,error:S,delayMs:N})=>{C(`tarball %s@%s: retry %d after %dms (%s)`,t.name,t.version,n,N,errMsg(S))}}),putCachedTarball(t.integrity,I)),rmWithRetry(F),mkdirSync(F,{recursive:!0}),await extractWithStallGuard(I,F,t,N),!1}async function extractWithStallGuard(t,n,S,C){if(tR===0&&!C){await extractTarball(t,n);return}let N,onAbort;try{await new Promise((F,I)=>{if(process.env.GJSIFY_TEST_HANG_EXTRACT!==`1`&&extractTarball(t,n).then(()=>F(),I),tR>0&&(N=setTimeout(()=>{I(Error(`gjsify install: extract of ${S.name}@${S.version} stalled for ${Math.round(tR/1e3)}s (${S.installPath}) — the tarball decompress/write never completed. This is usually a dropped Gio stream event under GJS; re-run the install. Override the cap with GJSIFY_EXTRACT_STALL_MS=<ms> (0 disables it).`))},tR),N.unref?.()),C){if(C.aborted){I(abortError(C));return}onAbort=()=>I(abortError(C)),C.addEventListener(`abort`,onAbort,{once:!0})}})}finally{N&&clearTimeout(N),C&&onAbort&&C.removeEventListener(`abort`,onAbort)}}function abortError(t){let n=t&&`reason`in t?t.reason:void 0;if(n instanceof Error)return n;let S=Error(`Aborted`);return S.name=`AbortError`,S}function assertNodeModulesDest(t,n,S){if(!t.split(jn).includes(`node_modules`))throw Error(`gjsify install: refusing to extract ${n.name}@${n.version} into ${t} — target is not inside a node_modules/ directory. This would overwrite working-tree files. A workspace package likely leaked into the fetch queue (it must be symlinked, not fetched).`);let C;try{C=realpathSync(t)}catch{return}if(!C.split(jn).includes(`node_modules`))throw Error(`gjsify install: refusing to extract ${n.name}@${n.version} — ${t} resolves to ${C}, which is outside any node_modules/ directory (likely a symlink to a workspace source tree). Extracting here would delete working-tree source files.${devLinkRemedy(S,t)}`)}function devLinkRemedy(t,n){let S=devLinkRoot(t),C=devLinkPath(S);return`\n If a \`gjsify link\` development link put it there${existsSync(C)?` — ${C} is present`:``}: run \`gjsify unlink\` in ${S} to remove the links and restore the registry copies, or \`gjsify link <checkout> --packages …\` to re-select. If no override is left, delete ${n} by hand and re-run.`}function depth$1(t){return t.split(`/node_modules/`).length}function readShebang$1(t){let n;try{n=readFileSync(t,`utf-8`)}catch{return null}return parseShebang(n.trimStart().split(/\r*\n/,1)[0]??``)}function writeBinEntry(t){let{binDir:n,binName:S,targetAbs:C,gjs:N,nodeFallbackAbs:F}=t,I=t.platform??process.platform,H=wn(n,S);if(N){let t=isGjsBundlePath(C);for(let t of[H,`${H}.cmd`,`${H}.ps1`])rmWithRetry(t);writeFileSync(H,buildShLauncher(C,{envPreamble:N.envPreamble,isGjsBundle:t,nodeFallbackAbs:F}));try{chmodSync(H,493)}catch{}if(I===`win32`&&t){let t=N.prebuildDirs.join(`;`),n=buildLauncherShims({interpreter:`gjs`,interpreterArgs:[`-m`],target:C,prependEnv:N.prebuildDirs.length>0?{GI_TYPELIB_PATH:t,PATH:t}:{},fallback:F===void 0?void 0:{interpreter:`node`,target:F}});writeFileSync(`${H}.cmd`,n.cmd),writeFileSync(`${H}.ps1`,n.ps1)}return}if(I===`win32`){let{sh:t,cmd:S,ps1:N}=buildCmdShim(Tn(n,C).split(`\\`).join(`/`),readShebang$1(C));for(let[n,C]of[[H,t],[`${H}.cmd`,S],[`${H}.ps1`,N]]){rmWithRetry(n),writeFileSync(n,C);try{chmodSync(n,493)}catch{}}return}rmWithRetry(H);let W=Tn(n,C);try{symlinkSync(W,H)}catch{copyFileSync(C,H),chmodSync(H,493)}}async function linkBins(t,n,S){let C=wn(n,`node_modules`,`.bin`),N=0,F,gjsEnvForPrefix=()=>{if(F===void 0){let t=detectNativePackages(n).map(t=>t.prebuildsDir);F={envPreamble:buildNativeEnvPreamble(n,t),prebuildDirs:t}}return F};for(let S of t){if(depth$1(S.installPath)!==1)continue;let t=wn(n,S.installPath),F=readInstalledManifest(t)??(S.bin===void 0?null:{bin:S.bin});if(F===null)continue;let I=pickBinMap(S.name,F);if(!(I===null||I.map.size===0)){mkdirSync(C,{recursive:!0});for(let[n,S]of I.map){let F=wn(t,S);if(!existsSync(F))continue;try{chmodSync(F,493)}catch{}let H=I.nodeFallback?.get(n),W=H===void 0?void 0:wn(t,H);writeBinEntry({binDir:C,binName:n,targetAbs:F,gjs:I.isGjsBin?gjsEnvForPrefix():void 0,nodeFallbackAbs:W!==void 0&&existsSync(W)?W:void 0}),N++}}}N>0&&S(`bin: linked %d entry(ies) under .bin/`,N)}function readInstalledManifest(t){try{let n=readFileSync(wn(t,`package.json`),`utf-8`);return JSON.parse(n)}catch{return null}}function rmWithRetry(t){rmSync(t,{recursive:!0,force:!0,maxRetries:10,retryDelay:100})}async function loadNpmrc$1(t){let n=homedir(),S={registry:t.registry??qm,scopes:{},authTokens:{},basicAuth:{}};for(let C of[wn(n,`.npmrc`),wn(t.prefix,`.npmrc`)])if(existsSync(C))try{let t=parseNpmrc(readFileSync(C,`utf-8`));S={...S,...t,scopes:{...S.scopes,...t.scopes}}}catch(t){ge.warn(`gjsify install: ignoring malformed ${C}: ${t.message}`)}let C=process.env.npm_config_registry;return C&&(S.registry=C),t.registry&&(S.registry=t.registry),S}function makeLogger(t){return t?(t,...n)=>{let S=t.replace(/%s|%d/g,()=>String(n.shift()));process.stderr.write(`gjsify install: ${S}\n`)}:()=>{}}var ZL,QL,$L,eR,tR,nR=__esmMin(()=>{_e(),Rd(),Pn(),Lg(),XP(),eh(),bL(),dL(),AL(),ML(),PL(),FL(),qI(),CF(),IL(),YL(),KL(),WL(),ZL=Number(process.env.GJSIFY_INSTALL_CONCURRENCY??`16`)||16,QL=`gjsify-lock.json`,$L=4,eR=new Set([2,3,$L]),__name$1(parseSpec$1,`parseSpec`),tR=(()=>{let t=process.env.GJSIFY_EXTRACT_STALL_MS;if(t===void 0)return 12e4;let n=Number(t);return Number.isFinite(n)&&n>=0?n:12e4})(),__name$1(depth$1,`depth`),__name$1(readShebang$1,`readShebang`),__name$1(loadNpmrc$1,`loadNpmrc`)}),rR=__exportAll$5({installPackages:()=>installPackages,makeProgressReporter:()=>makeProgressReporter});async function installPackages(t){if(iR===`npm`)return await installViaNpm(t),{installed:[]};let{installPackagesNative:n}=await Promise.resolve().then(()=>(nR(),XL));return{installed:await n(t)}}async function installViaNpm({prefix:t,specs:n,verbose:S,registry:C}){if(n.length===0)throw Error(`installPackages: empty specs list`);writeFileSync(wn(t,`package.json`),JSON.stringify({name:`gjsify-dlx-cache`,version:`0.0.0`,private:!0},null,2)),C&&writeFileSync(wn(t,`.npmrc`),`registry=${C}\n`);let{code:N}=await spawnToCompletion(`npm`,[`install`,`--no-package-lock`,`--no-audit`,`--no-fund`,`--prefix`,t,...S?[`--loglevel`,`verbose`]:[`--loglevel`,`warn`],...n],{completion:`return`,notFound:t=>Error(`npm not found on PATH — install Node.js, or unset GJSIFY_INSTALL_BACKEND to use the default native backend (${t.message})`)});if(N!==0)throw Error(`npm install exited with code ${N}`)}var iR,aR=__esmMin(()=>{Rd(),Pn(),V_(),hL(),iR=process.env.GJSIFY_INSTALL_BACKEND??`native`});function defaultGlobalLayout(){let t=process.env.GJSIFY_GLOBAL_PREFIX,n=process.env.GJSIFY_GLOBAL_BIN_DIR,S=homedir(),C=process.env.XDG_DATA_HOME??wn(S,`.local`,`share`);return{prefix:t??wn(C,`gjsify`,`global`),binDir:n??wn(S,`.local`,`bin`)}}function hasBundlerEngineInstalled(t){let n=new Set(detectNativePackages(t).map(t=>t.name));if(n.has(`@gjsify/rolldown-native`))return!0;let S=detectHostLibc(process.platform);return hostPlatformTokens(process.platform,process.arch,S).some(t=>n.has(platformPackageName(sR,t)))}async function installGjsEnginePackages(t,n,S={}){let C=S.verbose??!1,N=S.installFn??(async n=>{let{installPackages:S}=await Promise.resolve().then(()=>(aR(),rR));await S({prefix:t,specs:[n],verbose:C})});for(let t of oR){let S=n?`${t}@${n}`:t;try{await N(S)}catch(S){let N=S instanceof Error?S.message:String(S);t===`@gjsify/rolldown-native`?ge.warn(`\nWarning: could not install the GJS bundler engine ${t}@${n} — ${N}\n \`gjsify build\` (and storybook / flatpak) will fail under GJS until it is present.\n This usually means no prebuild is published for this platform (${process.platform}/${process.arch}).`):C&&ge.warn(`gjsify install: optional GJS engine ${t}@${n} not installed — ${N}`)}}}function linkGlobalBins(t,n){mkdirSync(n.binDir,{recursive:!0});let S=[],C=detectNativePackages(n.prefix).map(t=>t.prebuildsDir),N=buildNativeEnvPreamble(n.prefix,C);for(let F of t){let t=wn(n.prefix,`node_modules`,F),I=wn(t,`package.json`);if(!existsSync(I))continue;let H=pickBinMap(F,readJson(I));if(!(H===null||H.map.size===0))for(let[F,I]of H.map){let W=wn(t,I);if(!existsSync(W))continue;try{chmodSync(W,493)}catch{}let q=wn(n.binDir,F);for(let t of[q,`${q}.cmd`,`${q}.ps1`])rmSync(t,{force:!0,maxRetries:10,retryDelay:100});let Y=isGjsBundlePath(W),X=H.nodeFallback?.get(F),Z=X===void 0?void 0:wn(t,X),te=Z!==void 0&&existsSync(Z)?Z:void 0;if(writeFileSync(q,buildShLauncher(W,{envPreamble:N,isGjsBundle:Y,nodeFallbackAbs:te})),chmodSync(q,493),process.platform===`win32`){let t=C.join(`;`),n=Y&&C.length>0?{GI_TYPELIB_PATH:t,PATH:t}:{},S=Y?null:readShebangOf(W),N=buildLauncherShims(Y?{interpreter:`gjs`,interpreterArgs:[`-m`],target:W,prependEnv:n,fallback:te===void 0?void 0:{interpreter:`node`,target:te}}:{interpreter:S?.prog||`node`,interpreterArgs:S?.args.trim()?S.args.trim().split(/\s+/):[],target:W});writeFileSync(`${q}.cmd`,N.cmd),writeFileSync(`${q}.ps1`,N.ps1)}S.push({name:F,target:W,link:q})}}return S}function readShebangOf(t){try{return parseShebang(readFileSync(t,`utf-8`).trimStart().split(/\r*\n/,1)[0]??``)}catch{return null}}function readJson(t){return JSON.parse(readFileSync(t,`utf-8`))}function globalLayoutIsDefault(t=process.env){return!t.GJSIFY_GLOBAL_PREFIX&&!t.GJSIFY_GLOBAL_BIN_DIR}function pathFor$1(t){return t===`win32`?hn:pn}function searchPathEntries(t,n){let S=pathFor$1(n),C=n===`win32`?`;`:`:`;return t.split(C).filter(Boolean).map(t=>S.resolve(t))}function binDirOnPath(t){let n=pathFor$1(process.platform).resolve(t);return searchPathEntries(process.env.PATH??``,process.platform).includes(n)}function resolveBinOnPath(t,n={}){let S=n.platform??process.platform,C=n.pathValue??process.env.PATH??``,N=n.exists??existsSync,F=S===`win32`?[...(n.pathExt??process.env.PATHEXT??cR).split(`;`).filter(Boolean).map(t=>t.startsWith(`.`)?t:`.${t}`),``]:[``],I=pathFor$1(S);for(let n of searchPathEntries(C,S))for(let S of F){let C=I.join(n,`${t}${S}`);if(N(C))return C}return null}function specToPackageName(t){if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n<0)return t;let S=t.indexOf(`@`,n);return S<0?t:t.slice(0,S)}let n=t.indexOf(`@`);return n<0?t:t.slice(0,n)}var oR,sR,cR,lR=__esmMin(()=>{_e(),Rd(),Lg(),Pn(),CF(),qI(),oR=[`@gjsify/rolldown-native`,`@gjsify/lightningcss-native`,`@gjsify/oxfmt-native`],sR=`@gjsify/rolldown-native`,__name$1(pathFor$1,`pathFor`),cR=`.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC`});function usingSelfShim(){return dR}function pathWithoutSelfShim(t=process.env.PATH??``,n=process.env.GJSIFY_SHIM_DIR,S=Mn){return n?t.split(S).filter(t=>t!==n).join(S):t}function needsSelfShim(t){if(t.gjs)return!0;let n=Tn(t.workspaceRoot,t.selfEntry);return n===``||n.startsWith(`..`)||Cn(n)}function ensureGjsifyShimOnPath(){if(uR)return;uR=!0;let t=process.env.GJSIFY_SHIM_DIR;if(t&&existsSync(wn(t,`gjsify`))){dR=!0,(process.env.PATH??``).split(Mn).includes(t)||(process.env.PATH=t+Mn+(process.env.PATH??``));return}let n=isGjs(),S=fileURLToPath(n?import.meta.url:new URL(`../index.js`,import.meta.url));if(!needsSelfShim({gjs:n,selfEntry:S,workspaceRoot:findWorkspaceRoot(process.cwd())??process.cwd()}))return;let C=n?process.env.GJS_CONSOLE||`gjs`:`node`,N=n?selfShimPreamble(S):``,F={gjsify:n?buildShLauncher(S,{isGjsBundle:!0,envPreamble:N,gjs:C}):`#!/bin/sh\nexec "${C}" "${S}" "$@"\n`};if(!n&&process.platform===`win32`){let{cmd:t,ps1:n}=buildLauncherShims({interpreter:C,interpreterArgs:[],target:S});F[`gjsify.cmd`]=t,F[`gjsify.ps1`]=n}let I=buildNodeShim(n,S,N);I&&(F[`${fR}/node`]=I);let H=materializeShimDir(F);dR=!0,process.env.GJSIFY_SHIM_DIR=H,process.env.PATH=H+Mn+(process.env.PATH??``)}function materializeShimDir(t,n=gjsifyCacheRoot(`shim`,`v1`)){let S=Object.keys(t).sort(),C=createHash(`sha256`);for(let n of S)C.update(`${n}\0${t[n]}\0`);let N=C.digest(`hex`).slice(0,16);try{return writeShimDir(wn(n,N),t,S)}catch{return writeShimDir(mkdtempSync(wn(tmpdir(),`gjsify-shim-`)),t,S)}}function writeShimDir(t,n,S){for(let C of S){let S=wn(t,C);if(existsSync(S)&&readFileSync(S,`utf8`)===n[C])continue;mkdirSync(En(S),{recursive:!0});let N=`${S}.tmp.${process.pid}`;try{writeFileSync(N,n[C],{mode:493}),chmodSync(N,493),renameSync(N,S)}catch(t){throw rmSync(N,{force:!0}),t}}return t}function selfShimScanRoot(t){let n=t.search(/[\\/]node_modules[\\/]/);return n>0?t.slice(0,n):findWorkspaceRoot(En(t))??En(t)}function selfShimPreamble(t){let n=[];try{n=detectNativePackages(En(t)).map(t=>t.prebuildsDir)}catch{}return buildNativeEnvPreamble(selfShimScanRoot(t),n)}function dyldCarryPreamble(t,n){return t===`darwin`?Object.keys(n).filter(t=>/^DYLD_[A-Z_]+$/.test(t)&&n[t]).sort().map(t=>`${t}=${shQuoteArg(n[t])}\nexport ${t}\n`).join(``):``}function nodeShimDir(){let t=process.env.GJSIFY_SHIM_DIR;if(!t)return null;let n=wn(t,fR);return existsSync(wn(n,`node`))?n:null}function buildNodeShim(t,n,S){if(!t||resolveBinOnPath(`node`))return null;let C=process.env.GJS_CONSOLE||`gjs`;return`#!/bin/sh
925
925
  `+dyldCarryPreamble(process.platform,process.env)+`case "$1" in
926
926
  -*) echo "gjsify: this host has no node; the gjsify shim runs a SCRIPT FILE only" >&2
927
927
  echo "gjsify: got: node $*" >&2
928
928
  exit 127 ;;
929
929
  esac
930
- `+S+`exec "${C}" -m "${n}" run --node-script "$@"\n`}var aR,oR,sR,cR=__esmMin(()=>{Qc(),Rd(),Lg(),Pn(),Gn(),d_(),VI(),CF(),oL(),iR(),eF(),aR=!1,oR=!1,sR=`node-shim`});function markDaemonCommand(){lR=!0}function isDaemonCommand(){return lR}var lR,uR=__esmMin(()=>{lR=!1});async function runTargetOnRuntime(t,n,S){if(!looksLikeFile(n))return ge.error(`gjsify run: --runtime ${t} needs a bundle FILE, but "${n}" is not a path.\n Build first (e.g. \`gjsify build src/app.ts --app ${t===`gjs`?`gjs`:`node`} --outfile dist/app.${t===`gjs`?`gjs`:`node`}.mjs\`), then run the output file.`),process.exit(1);let C=readPackageJson$1(wn(process.cwd(),`package.json`)),N=checkRuntimeSupported(t,readDeclaredRuntimes(C),C?.name??n);if(!N.ok)return ge.error(`gjsify run: ${N.message}`),process.exit(1);let F=xn(n);t===`gjs`?await runGjsBundle(F,S,{completion:`exit`,exitOnSuccess:!0}):await runRuntimeBundle(t,F,S,{completion:`exit`,exitOnSuccess:!0})}function isLikelyGjsBundle(t){if(/\.gjs\.[mc]?js$/.test(t))return!0;try{let n=readFileSync(t,`utf-8`).slice(0,65536);return n.startsWith(`#!/usr/bin/env -S gjs`)||/(?:from|import)\s*["']gi:\/\//.test(n)||/\bimports\.(?:gi|system)\b/.test(n)}catch{return!1}}function looksLikeFile(t){if(t.startsWith(`./`)||t.startsWith(`../`)||t.startsWith(`/`)||t.includes(`/`)||t.includes(`\\`)||/\.(c?js|mjs|cjs|gjs)$/.test(t))return!0;try{return statSync(t).isFile()}catch{return!1}}async function runScriptInWorkspace(t,n,S){let C=findWorkspaceRoot(process.cwd())??process.cwd(),N;try{N=discoverWorkspaces(C)}catch(t){return ge.error(`gjsify run: could not read workspaces at ${C}: ${t.message}`),process.exit(1)}let F=N.find(n=>n.name===t||n.relativeLocation===t||Dn(n.location)===t);if(!F){let n=N.map(t=>t.relativeLocation).join(`, `)||`<none>`;return ge.error(`gjsify run: no workspace "${t}" under ${C} (available: ${n})`),process.exit(1)}await runScript(n,S,F.location)}async function runScript(t,n,S=process.cwd()){let C=wn(S,`package.json`),N=readPackageJson$1(C);if(!N)return ge.error(`gjsify run: no package.json in ${S}`),process.exit(1);let F=N.scripts??{},I=F[t];if(typeof I!=`string`){let n=Object.keys(F).join(`, `)||`<none>`;return ge.error(`gjsify run: no script "${t}" in ${C} (available: ${n})`),process.exit(1)}let H=findWorkspaceRoot(S),W=[wn(S,`node_modules`,`.bin`)];H&&H!==S&&W.push(wn(H,`node_modules`,`.bin`)),process.env.GJSIFY_SHIM_DIR&&W.unshift(process.env.GJSIFY_SHIM_DIR);let q=nodeShimDir();q&&W.unshift(q);let Y=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`},X={...process.env,...Y,PATH:[...W,process.env.PATH??``].filter(Boolean).join(Mn),npm_lifecycle_event:t,npm_package_name:N.name??``,npm_package_version:N.version??``},Z=isGjs()?gjsifyInProcessArgv(I,n):null;if(Z){process.env.PATH=X.PATH,process.env.npm_lifecycle_event=X.npm_lifecycle_event,process.env.npm_package_name=X.npm_package_name,process.env.npm_package_version=X.npm_package_version,X.FORCE_COLOR!==void 0&&(process.env.FORCE_COLOR=X.FORCE_COLOR),S!==process.cwd()&&process.chdir(S);let t=!1;try{let{runCli:t}=await Promise.resolve().then(()=>(IK(),FK));await t(Z)}catch(n){ge.error(n.message),t=!0}if(!t&&isDaemonCommand())return;let n=t?1:process.exitCode==null?0:Number(process.exitCode);return process.exit(n)}let te=n.length>0?`${I} ${n.map(shellEscape).join(` `)}`:I,ne;try{ne=await spawnToCompletion(te,[],{completion:`exit`,cwd:S,env:X,shell:!0})}catch(t){return ge.error(t.message),process.exit(1)}return ne.code===0?process.exit(0):(ge.error(`script "${t}" exited with ${describeExit(ne)}`),process.exit(1))}function shellEscape(t){return/^[a-zA-Z0-9_\-./=:@,]+$/.test(t)?t:`'${t.replace(/'/g,`'\\''`)}'`}function gjsifyInProcessArgv(t,n){let S=gjsifyCommandArgv(t);return S?[...S,...n]:null}var dR,fR=__esmMin(()=>{_e(),Rd(),Pn(),NI(),V_(),XI(),QI(),iL(),aL(),cR(),eF(),hI(),uR(),QP(),d_(),W_(),dR={command:`run <target> [args..]`,description:"Run a script from package.json (yarn-run-style) or a GJS bundle file. If <target> resolves to a file on disk (or has a path-like prefix), it is launched via gjs with LD_LIBRARY_PATH + GI_TYPELIB_PATH set for native packages. Otherwise it is looked up in the current package.json `scripts`.",builder:t=>t.positional(`target`,{description:"Either a script name (looked up in package.json `scripts`) or a path to a GJS bundle (e.g. dist/gjs.js).",type:`string`,demandOption:!0}).positional(`args`,{description:`Extra arguments passed through to the script / gjs.`,type:`string`,array:!0,default:[]}).option(`workspace`,{alias:`w`,type:`string`,description:"Run <target> as a script in the named workspace (by name or path), like `npm run <script> -w <name>`."}).option(`node-script`,{type:`boolean`,default:!1,description:"Treat <target> as an unbundled Node-style script (imports `node:` builtins) and run it on the host runtime. Under GJS the file is bundled `--app gjs` on the fly first, which is what makes a repo script runnable on a host that has no Node."}).option(`runtime`,{type:`string`,choices:H_,description:"Runtime to launch a bundle FILE on: gjs (default, `--app gjs` bundle) | node | bun | deno (the `--app node` bundle). Forces file mode."}).version(!1).help(!1).parserConfiguration({"populate--":!0,"parse-positional-numbers":!1,"unknown-options-as-args":!0}),handler:async t=>{let n=t.target,S=[...t.args??[],...doubleDashArgs(t)];if(t.nodeScript===!0){let isSet=t=>typeof t==`string`&&t.length>0,C=isSet(t.runtime)?`--runtime`:isSet(t.workspace)?`--workspace`:null;if(C)return ge.error(`gjsify run: --node-script cannot be combined with ${C}.`),process.exit(1);await runNodeScript(n,S,{completion:`exit`,exitOnSuccess:!0});return}let C=t.runtime;if(typeof C==`string`&&C.length>0){if(typeof t.workspace==`string`&&t.workspace.length>0)return ge.error(`gjsify run: --runtime cannot be combined with --workspace (file mode vs script mode).`),process.exit(1);if(!isExampleRuntime(C))return ge.error(`gjsify run: unknown --runtime "${C}" (expected: ${H_.join(`, `)}).`),process.exit(1);await runTargetOnRuntime(C,n,S);return}if(typeof t.workspace==`string`&&t.workspace.length>0){await runScriptInWorkspace(t.workspace,n,S);return}let N=readPackageJson$1(wn(process.cwd(),`package.json`));if(!(N?.scripts&&typeof N.scripts[n]==`string`)&&looksLikeFile(n)){let t=xn(n),C=hostRuntime$1(),N=C===`gjs`||isLikelyGjsBundle(t)?`gjs`:C;N===`gjs`?await runGjsBundle(t,S,{completion:`exit`,exitOnSuccess:!0}):await runRuntimeBundle(N,t,S,{completion:`exit`,exitOnSuccess:!0});return}await runScript(n,S)}}}),pR,mR=__esmMin(()=>{_e(),Pn(),CF(),pR={command:`info [file]`,description:`Show native gjsify packages detected in node_modules and the env vars needed to run a GJS bundle directly with gjs.`,builder:t=>t.positional(`file`,{description:`Optional: the GJS bundle path to include in the example command (e.g. dist/gjs.js)`,type:`string`,normalize:!0}).option(`export`,{description:`Output only shell export statements suitable for eval (eval $(gjsify info --export))`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.file?xn(t.file):null,C=detectNativePackages(n),N=buildNativeEnv(C),F=Object.entries(N).filter(([,t])=>t!==void 0);if(t.export){for(let[t,n]of F)ge.log(`export ${t}="${n}"`);return}if(C.length===0){ge.log(`No native gjsify packages detected in node_modules.`),ge.log(`Native packages declare "gjsify": { "prebuilds": "<dir>" } in their package.json.`);return}ge.log(`Native packages detected:`);for(let t of C)ge.log(` ${t.name} → ${t.prebuildsDir}`);ge.log(``),ge.log(`To run your app directly with gjs, set:`);for(let[t,n]of F)ge.log(` export ${t}="${n}"`);S?ge.log(` gjs -m ${S}`):ge.log(` gjs -m <your-bundle.js>`),ge.log(``),ge.log(`Or use gjsify run to handle this automatically:`),S?ge.log(` gjsify run ${t.file}`):ge.log(` gjsify run <your-bundle.js>`)}}}),hR,gR=__esmMin(()=>{_e(),vF(),hR={command:`system-check`,description:"Check that required system dependencies (GJS, GTK4, libsoup3, …) are installed. Optional dependencies are detected only when their @gjsify/* package is in your project. (Previously called `gjsify check`; the bare name now runs TypeScript checks across the workspace — see `gjsify check --help`.)",builder:t=>t.option(`json`,{description:`Output results as JSON`,type:`boolean`,default:!1}),handler:async t=>{let n=runAllChecks(process.cwd()),S=detectPackageManager$1(),C=checkTypeSkew(process.cwd()),N=n.filter(t=>!t.found&&t.severity===`required`),F=n.filter(t=>!t.found&&t.severity===`optional`),I=[...N,...F];if(t.json)return ge.log(JSON.stringify({packageManager:S,deps:n,typeSkew:C},null,2)),process.exit(+(N.length>0));ge.log(`System dependency check
930
+ `+S+`exec "${C}" -m "${n}" run --node-script "$@"\n`}var uR,dR,fR,pR=__esmMin(()=>{Qc(),Rd(),Lg(),Pn(),Gn(),d_(),qI(),CF(),dL(),lR(),eF(),uR=!1,dR=!1,fR=`node-shim`});function markDaemonCommand(){mR=!0}function isDaemonCommand(){return mR}var mR,hR=__esmMin(()=>{mR=!1});async function runTargetOnRuntime(t,n,S){if(!looksLikeFile(n))return ge.error(`gjsify run: --runtime ${t} needs a bundle FILE, but "${n}" is not a path.\n Build first (e.g. \`gjsify build src/app.ts --app ${t===`gjs`?`gjs`:`node`} --outfile dist/app.${t===`gjs`?`gjs`:`node`}.mjs\`), then run the output file.`),process.exit(1);let C=readPackageJson$1(wn(process.cwd(),`package.json`)),N=checkRuntimeSupported(t,readDeclaredRuntimes(C),C?.name??n);if(!N.ok)return ge.error(`gjsify run: ${N.message}`),process.exit(1);let F=xn(n);t===`gjs`?await runGjsBundle(F,S,{completion:`exit`,exitOnSuccess:!0}):await runRuntimeBundle(t,F,S,{completion:`exit`,exitOnSuccess:!0})}function isLikelyGjsBundle(t){if(/\.gjs\.[mc]?js$/.test(t))return!0;try{let n=readFileSync(t,`utf-8`).slice(0,65536);return n.startsWith(`#!/usr/bin/env -S gjs`)||/(?:from|import)\s*["']gi:\/\//.test(n)||/\bimports\.(?:gi|system)\b/.test(n)}catch{return!1}}function looksLikeFile(t){if(t.startsWith(`./`)||t.startsWith(`../`)||t.startsWith(`/`)||t.includes(`/`)||t.includes(`\\`)||/\.(c?js|mjs|cjs|gjs)$/.test(t))return!0;try{return statSync(t).isFile()}catch{return!1}}async function runScriptInWorkspace(t,n,S){let C=findWorkspaceRoot(process.cwd())??process.cwd(),N;try{N=discoverWorkspaces(C)}catch(t){return ge.error(`gjsify run: could not read workspaces at ${C}: ${t.message}`),process.exit(1)}let F=N.find(n=>n.name===t||n.relativeLocation===t||Dn(n.location)===t);if(!F){let n=N.map(t=>t.relativeLocation).join(`, `)||`<none>`;return ge.error(`gjsify run: no workspace "${t}" under ${C} (available: ${n})`),process.exit(1)}await runScript(n,S,F.location)}async function runScript(t,n,S=process.cwd()){let C=wn(S,`package.json`),N=readPackageJson$1(C);if(!N)return ge.error(`gjsify run: no package.json in ${S}`),process.exit(1);let F=N.scripts??{},I=F[t];if(typeof I!=`string`){let n=Object.keys(F).join(`, `)||`<none>`;return ge.error(`gjsify run: no script "${t}" in ${C} (available: ${n})`),process.exit(1)}let H=findWorkspaceRoot(S),W=[wn(S,`node_modules`,`.bin`)];H&&H!==S&&W.push(wn(H,`node_modules`,`.bin`)),process.env.GJSIFY_SHIM_DIR&&W.unshift(process.env.GJSIFY_SHIM_DIR);let q=nodeShimDir();q&&W.unshift(q);let Y=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`},X={...process.env,...Y,PATH:[...W,process.env.PATH??``].filter(Boolean).join(Mn),npm_lifecycle_event:t,npm_package_name:N.name??``,npm_package_version:N.version??``},Z=isGjs()?gjsifyInProcessArgv(I,n):null;if(Z){process.env.PATH=X.PATH,process.env.npm_lifecycle_event=X.npm_lifecycle_event,process.env.npm_package_name=X.npm_package_name,process.env.npm_package_version=X.npm_package_version,X.FORCE_COLOR!==void 0&&(process.env.FORCE_COLOR=X.FORCE_COLOR),S!==process.cwd()&&process.chdir(S);let t=!1;try{let{runCli:t}=await Promise.resolve().then(()=>(UK(),HK));await t(Z)}catch(n){ge.error(n.message),t=!0}if(!t&&isDaemonCommand())return;let n=t?1:process.exitCode==null?0:Number(process.exitCode);return process.exit(n)}let te=n.length>0?`${I} ${n.map(shellEscape).join(` `)}`:I,ne;try{ne=await spawnToCompletion(te,[],{completion:`exit`,cwd:S,env:X,shell:!0})}catch(t){return ge.error(t.message),process.exit(1)}return ne.code===0?process.exit(0):(ge.error(`script "${t}" exited with ${describeExit(ne)}`),process.exit(1))}function shellEscape(t){return/^[a-zA-Z0-9_\-./=:@,]+$/.test(t)?t:`'${t.replace(/'/g,`'\\''`)}'`}function gjsifyInProcessArgv(t,n){let S=gjsifyCommandArgv(t);return S?[...S,...n]:null}var gR,_R=__esmMin(()=>{_e(),Rd(),Pn(),RI(),V_(),tL(),rL(),lL(),uL(),pR(),eF(),bI(),hR(),QP(),d_(),W_(),gR={command:`run <target> [args..]`,description:"Run a script from package.json (yarn-run-style) or a GJS bundle file. If <target> resolves to a file on disk (or has a path-like prefix), it is launched via gjs with LD_LIBRARY_PATH + GI_TYPELIB_PATH set for native packages. Otherwise it is looked up in the current package.json `scripts`.",builder:t=>t.positional(`target`,{description:"Either a script name (looked up in package.json `scripts`) or a path to a GJS bundle (e.g. dist/gjs.js).",type:`string`,demandOption:!0}).positional(`args`,{description:`Extra arguments passed through to the script / gjs.`,type:`string`,array:!0,default:[]}).option(`workspace`,{alias:`w`,type:`string`,description:"Run <target> as a script in the named workspace (by name or path), like `npm run <script> -w <name>`."}).option(`node-script`,{type:`boolean`,default:!1,description:"Treat <target> as an unbundled Node-style script (imports `node:` builtins) and run it on the host runtime. Under GJS the file is bundled `--app gjs` on the fly first, which is what makes a repo script runnable on a host that has no Node."}).option(`runtime`,{type:`string`,choices:H_,description:"Runtime to launch a bundle FILE on: gjs (default, `--app gjs` bundle) | node | bun | deno (the `--app node` bundle). Forces file mode."}).version(!1).help(!1).parserConfiguration({"populate--":!0,"parse-positional-numbers":!1,"unknown-options-as-args":!0}),handler:async t=>{let n=t.target,S=[...t.args??[],...doubleDashArgs(t)];if(t.nodeScript===!0){let isSet=t=>typeof t==`string`&&t.length>0,C=isSet(t.runtime)?`--runtime`:isSet(t.workspace)?`--workspace`:null;if(C)return ge.error(`gjsify run: --node-script cannot be combined with ${C}.`),process.exit(1);await runNodeScript(n,S,{completion:`exit`,exitOnSuccess:!0});return}let C=t.runtime;if(typeof C==`string`&&C.length>0){if(typeof t.workspace==`string`&&t.workspace.length>0)return ge.error(`gjsify run: --runtime cannot be combined with --workspace (file mode vs script mode).`),process.exit(1);if(!isExampleRuntime(C))return ge.error(`gjsify run: unknown --runtime "${C}" (expected: ${H_.join(`, `)}).`),process.exit(1);await runTargetOnRuntime(C,n,S);return}if(typeof t.workspace==`string`&&t.workspace.length>0){await runScriptInWorkspace(t.workspace,n,S);return}let N=readPackageJson$1(wn(process.cwd(),`package.json`));if(!(N?.scripts&&typeof N.scripts[n]==`string`)&&looksLikeFile(n)){let t=xn(n),C=hostRuntime$1(),N=C===`gjs`||isLikelyGjsBundle(t)?`gjs`:C;N===`gjs`?await runGjsBundle(t,S,{completion:`exit`,exitOnSuccess:!0}):await runRuntimeBundle(N,t,S,{completion:`exit`,exitOnSuccess:!0});return}await runScript(n,S)}}}),vR,yR=__esmMin(()=>{_e(),Pn(),CF(),vR={command:`info [file]`,description:`Show native gjsify packages detected in node_modules and the env vars needed to run a GJS bundle directly with gjs.`,builder:t=>t.positional(`file`,{description:`Optional: the GJS bundle path to include in the example command (e.g. dist/gjs.js)`,type:`string`,normalize:!0}).option(`export`,{description:`Output only shell export statements suitable for eval (eval $(gjsify info --export))`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.file?xn(t.file):null,C=detectNativePackages(n),N=buildNativeEnv(C),F=Object.entries(N).filter(([,t])=>t!==void 0);if(t.export){for(let[t,n]of F)ge.log(`export ${t}="${n}"`);return}if(C.length===0){ge.log(`No native gjsify packages detected in node_modules.`),ge.log(`Native packages declare "gjsify": { "prebuilds": "<dir>" } in their package.json.`);return}ge.log(`Native packages detected:`);for(let t of C)ge.log(` ${t.name} → ${t.prebuildsDir}`);ge.log(``),ge.log(`To run your app directly with gjs, set:`);for(let[t,n]of F)ge.log(` export ${t}="${n}"`);S?ge.log(` gjs -m ${S}`):ge.log(` gjs -m <your-bundle.js>`),ge.log(``),ge.log(`Or use gjsify run to handle this automatically:`),S?ge.log(` gjsify run ${t.file}`):ge.log(` gjsify run <your-bundle.js>`)}}}),bR,xR=__esmMin(()=>{_e(),vF(),bR={command:`system-check`,description:"Check that required system dependencies (GJS, GTK4, libsoup3, …) are installed. Optional dependencies are detected only when their @gjsify/* package is in your project. (Previously called `gjsify check`; the bare name now runs TypeScript checks across the workspace — see `gjsify check --help`.)",builder:t=>t.option(`json`,{description:`Output results as JSON`,type:`boolean`,default:!1}),handler:async t=>{let n=runAllChecks(process.cwd()),S=detectPackageManager$1(),C=checkTypeSkew(process.cwd()),N=n.filter(t=>!t.found&&t.severity===`required`),F=n.filter(t=>!t.found&&t.severity===`optional`),I=[...N,...F];if(t.json)return ge.log(JSON.stringify({packageManager:S,deps:n,typeSkew:C},null,2)),process.exit(+(N.length>0));ge.log(`System dependency check
931
931
  `);let H=n.filter(t=>t.severity===`required`),W=n.filter(t=>t.severity===`optional`);if(H.length>0){ge.log(`Required:`);for(let t of H){let n=t.found?`✓`:`✗`,S=t.version?` (${t.version})`:``;ge.log(` ${n} ${t.name}${S}`)}}if(W.length>0){ge.log(`
932
932
  Optional:`);for(let t of W){let n=t.found?`✓`:`⚠`,S=t.version?` (${t.version})`:``,C=t.requiredBy&&t.requiredBy.length>0?` — needed by ${t.requiredBy.join(`, `)}`:``;ge.log(` ${n} ${t.name}${S}${C}`)}}if(C.length>0){ge.log(`
933
933
  Type/runtime version skew:`);for(let t of C){let n=t.relation===`ahead`?`⚠`:`ℹ`;ge.log(` ${n} ${t.typePackage} describes ${t.declared}, installed ${t.pkgConfig} is ${t.installed}`)}C.some(t=>t.relation===`ahead`)&&ge.log(`
@@ -939,19 +939,19 @@ Type/runtime version skew:`);for(let t of C){let n=t.relation===`ahead`?`⚠`:`
939
939
  All dependencies found.`);return}N.length>0&&ge.log(`\nMissing required: ${N.map(t=>t.name).join(`, `)}`),F.length>0&&ge.log(`Missing optional: ${F.map(t=>t.name).join(`, `)}`);let q=buildInstallCommand(S,I);q?ge.log(`\nTo install:\n ${q}`):ge.log(`
940
940
  No install command available for your package manager. Install manually.`),process.exit(+(N.length>0))}}});function prefixLines(t,n,S,C){let N=``,F=``,emit=t=>{C?F+=t:n.write(t)};return t.setEncoding(`utf-8`),t.on(`data`,t=>{N+=t;let n;for(;(n=N.indexOf(`
941
941
  `))!==-1;)emit(S+N.slice(0,n+1)),N=N.slice(n+1)}),t.on(`end`,()=>{N.length>0&&emit(S+N+`
942
- `)}),()=>{F.length>0&&(n.write(F),F=``)}}var _R=__esmMin(()=>{});function buildCacheEnabledByEnv(t=process.env){let n=t.GJSIFY_BUILD_CACHE;return n===void 0?!1:n!==``&&n!==`0`&&n!==`false`}function buildCacheRoot(t){return wn(t,`node_modules`,`.cache`,`gjsify`,`build`)}function sanitizePackageDirName(t){return`${t.replace(/^@/,``).replace(/[^A-Za-z0-9._-]/g,`-`)}-${createHash(`sha256`).update(t).digest(`hex`).slice(0,8)}`}function hashFileStream(t){let n=createHash(`sha256`),S=openSync(t,`r`);try{let t=Buffer.alloc(64*1024);for(;;){let C=readSync(S,t,0,t.length,null);if(C<=0)break;n.update(t.subarray(0,C))}}finally{closeSync(S)}return n.digest(`hex`)}function hashPackageInputs(t){let n=packageBuildInputs(t),S=createHash(`sha256`);S.update(`gjsify-build-cache-inputs/v4
942
+ `)}),()=>{F.length>0&&(n.write(F),F=``)}}var SR=__esmMin(()=>{});function buildCacheEnabledByEnv(t=process.env){let n=t.GJSIFY_BUILD_CACHE;return n===void 0?!1:n!==``&&n!==`0`&&n!==`false`}function buildCacheRoot(t){return wn(t,`node_modules`,`.cache`,`gjsify`,`build`)}function sanitizePackageDirName(t){return`${t.replace(/^@/,``).replace(/[^A-Za-z0-9._-]/g,`-`)}-${createHash(`sha256`).update(t).digest(`hex`).slice(0,8)}`}function hashFileStream(t){let n=createHash(`sha256`),S=openSync(t,`r`);try{let t=Buffer.alloc(64*1024);for(;;){let C=readSync(S,t,0,t.length,null);if(C<=0)break;n.update(t.subarray(0,C))}}finally{closeSync(S)}return n.digest(`hex`)}function hashPackageInputs(t){let n=packageBuildInputs(t),S=createHash(`sha256`);S.update(`gjsify-build-cache-inputs/v4
943
943
  `);for(let t of n){if(t.link!==void 0){let n;try{n=hashFileStream(t.abs)}catch{n=`link:${t.link}`}S.update(`${t.rel} ${n}\n`);continue}try{S.update(`${t.rel} ${hashFileStream(t.abs)}\n`)}catch{S.update(`${t.rel} unreadable\n`)}}return S.digest(`hex`)}function walkFiles(t,n,S){let C;try{C=readdirSync(t)}catch{return}C.sort();for(let N of C){if(N===`node_modules`)continue;let C=wn(t,N),F=n===``?N:`${n}/${N}`,I;try{I=lstatSync(C)}catch{continue}if(I.isSymbolicLink())try{S.push({rel:F,abs:C,link:readlinkSync(C)})}catch{}else I.isDirectory()?walkFiles(C,F,S):I.isFile()&&S.push({rel:F,abs:C})}}function hashOutputDirs(t,n){let S=createHash(`sha256`);S.update(`gjsify-build-cache-outputs/v4
944
- `);for(let C of[...n].sort()){let n=wn(t,C);if(!existsSync(n)){S.update(`${C} absent\n`);continue}let N=[];walkFiles(n,C,N);for(let t of N){if(t.link!==void 0){S.update(`${t.rel} link:${t.link}\n`);continue}try{S.update(`${t.rel} ${hashFileStream(t.abs)}\n`)}catch{S.update(`${t.rel} unreadable\n`)}}}return S.digest(`hex`)}function outputUnits(t){let n=[];for(let S of vR){let C=wn(t,S);if(!existsSync(C))continue;let N;try{N=readdirSync(C).filter(t=>t!==`node_modules`&&!isBuildInfo(t))}catch{continue}let F=N.every(t=>{try{return lstatSync(wn(C,t)).isDirectory()}catch{return!1}});if(N.length===0||!F){n.push(S);continue}for(let t of[...N].sort())n.push(`${S}/${t}`)}return n}function signatureOf(t,n){let S=[];walkFiles(wn(t,n),n,S);let C=createHash(`sha256`);for(let t of S){let n=`link`;if(t.link===void 0)try{let S=lstatSync(t.abs);n=`${S.size}:${S.mtimeMs}`}catch{n=`gone`}C.update(`${t.rel} ${n}\n`)}return C.digest(`hex`)}function snapshotOutputDirs(t){let n={};for(let t of vR)n[t]=null;for(let S of outputUnits(t))n[S]=signatureOf(t,S);return n}function modifiedOutputDirs(t,n){let S=[];for(let C of outputUnits(t))signatureOf(t,C)!==(n[C]??null)&&S.push(C);return S.sort()}function composeCacheKey(t){let n=createHash(`sha256`);n.update(`gjsify-build-cache/v4
945
- `),n.update(`script:${t.script}\n`);for(let S of t.args??[])n.update(`arg:${S}\n`);for(let S of Object.keys(t.toolchain).sort())n.update(`tool:${S}@${t.toolchain[S]}\n`);n.update(`self:${t.ownHash}\n`);let S=t.depHashes instanceof Map?t.depHashes:new Map(Object.entries(t.depHashes));for(let t of[...S.keys()].sort())n.update(`dep:${t} ${S.get(t)}\n`);return n.digest(`hex`).slice(0,32)}function resolveToolchainVersions(t){let n={};for(let S of yR){let C=`none`;try{let n=readFileSync(wn(t,`node_modules`,...S.split(`/`),`package.json`),`utf-8`),N=JSON.parse(n);typeof N.version==`string`&&(C=N.version)}catch{}S===`@gjsify/cli`&&C===`none`&&(C=readOwnCliVersion()??`none`),n[S]=C}return n}function readOwnCliVersion(){try{let t=En(fileURLToPath(import.meta.url));for(let n=0;n<4;n++){let n=wn(t,`package.json`);if(existsSync(n)){let t=JSON.parse(readFileSync(n,`utf-8`));if(t.name===`@gjsify/cli`&&typeof t.version==`string`)return t.version}t=En(t)}}catch{}return null}function copyDirRecursive(t,n){mkdirSync(n,{recursive:!0});for(let S of readdirSync(t).sort()){let C=wn(t,S),N=wn(n,S),F=lstatSync(C);if(F.isSymbolicLink())replicateLinkSync(C,N);else if(F.isDirectory())copyDirRecursive(C,N);else if(F.isFile()){copyFileSync(C,N);try{chmodSync(N,F.mode&511)}catch{}}}}function buildCacheEntryDir(t,n,S){return wn(t,sanitizePackageDirName(n),S)}function readCacheEntry(t,n,S){let C=wn(bR(t,n,S),`manifest.json`);try{let N=JSON.parse(readFileSync(C,`utf-8`));if(N.version!==1||N.layout!==`v4`||N.package!==n||N.key!==S||!Array.isArray(N.dirs))return null;for(let C of N.dirs)if(!existsSync(wn(bR(t,n,S),`outputs`,C)))return null;return N}catch{return null}}function storeCacheEntry(t,n,S,C,N){let F=bR(t,n.name,S),I=`${F}.tmp-${process.pid}`;try{rmSync(I,{recursive:!0,force:!0}),mkdirSync(wn(I,`outputs`),{recursive:!0});for(let t of N)copyDirRecursive(wn(n.location,t),wn(I,`outputs`,t));let H=new Date().toISOString(),W={version:1,layout:`v4`,package:n.name,script:C,key:S,dirs:[...N],outputsHash:hashOutputDirs(n.location,N),createdAt:H,usedAt:H};return writeFileSync(wn(I,`manifest.json`),JSON.stringify(W,null,2)),rmSync(F,{recursive:!0,force:!0}),renameSync(I,F),pruneCacheEntries(t,n.name),W}catch{try{rmSync(I,{recursive:!0,force:!0})}catch{}return null}}function restoreCacheEntry(t,n,S){let C=bR(t,n.name,S.key);try{if(S.dirs.length>0&&hashOutputDirs(n.location,S.dirs)===S.outputsHash)return touchManifestUsed(C,S),`up-to-date`;for(let t of S.dirs){let S=wn(n.location,t);rmSync(S,{recursive:!0,force:!0}),copyDirRecursive(wn(C,`outputs`,t),S)}return touchManifestUsed(C,S),S.dirs.length>0?`restored`:`up-to-date`}catch{return null}}function touchManifestUsed(t,n){try{n.usedAt=new Date().toISOString(),writeFileSync(wn(t,`manifest.json`),JSON.stringify(n,null,2))}catch{}}function pruneCacheEntries(t,n,S=2){let C=wn(t,sanitizePackageDirName(n)),N;try{N=readdirSync(C)}catch{return}let F=[];for(let t of N){if(t.includes(`.tmp-`)){try{rmSync(wn(C,t),{recursive:!0,force:!0})}catch{}continue}let n=``;try{let S=JSON.parse(readFileSync(wn(C,t,`manifest.json`),`utf-8`));n=S.usedAt??S.createdAt??``}catch{}F.push({name:t,stamp:n})}if(!(F.length<=S)){F.sort((t,n)=>t.stamp<n.stamp?1:t.stamp>n.stamp?-1:0);for(let t of F.slice(S))try{rmSync(wn(C,t.name),{recursive:!0,force:!0})}catch{}}}function buildCacheOptedOut(t){return t.manifest.gjsify?.buildCache===!1}var vR,yR,isBuildInfo,bR,BuildCacheRunner,xR=__esmMin(()=>{_e(),Qc(),Rd(),Pn(),Gn(),QP(),PL(),vI(),vR=gI,yR=[`@gjsify/cli`,`@gjsify/tsc`,`rolldown`,`typescript`],isBuildInfo=t=>t.endsWith(`.tsbuildinfo`),bR=buildCacheEntryDir,BuildCacheRunner=class{options;cacheRoot;graph;toolchain;ownHashes=new Map;closures=new Map;keys=new Map;log;constructor(t){this.options=t,this.cacheRoot=buildCacheRoot(t.root),this.graph=buildDependencyGraph(t.workspaces,{includeDev:!0,includePeer:!0,includeOptional:!0}),this.toolchain=resolveToolchainVersions(t.root),this.log=t.log??(t=>ge.error(t));for(let n of t.targets??[])if(this.graph.byName.has(n)){this.ownHashOf(n);for(let t of this.closureOf(n))this.ownHashOf(t)}}ownHashOf(t){let n=this.ownHashes.get(t);if(n===void 0){let S=this.graph.byName.get(t);n=S?hashPackageInputs(S.location):`unknown-workspace`,this.ownHashes.set(t,n)}return n}closureOf(t){let n=this.closures.get(t);if(n===void 0){let S=new Set,C=[...this.graph.edges.get(t)??[]];for(;C.length>0;){let n=C.shift();if(!(n===t||S.has(n))){S.add(n);for(let N of this.graph.edges.get(n)??[])!S.has(N)&&N!==t&&C.push(N)}}n=[...S].sort(),this.closures.set(t,n)}return n}keyFor(t){let n=this.keys.get(t.name);if(n===void 0){let S=new Map;for(let n of this.closureOf(t.name))S.set(n,this.ownHashOf(n));n=composeCacheKey({script:this.options.script,args:this.options.args,toolchain:this.toolchain,ownHash:this.ownHashOf(t.name),depHashes:S}),this.keys.set(t.name,n)}return n}tryRestore(t){try{if(buildCacheOptedOut(t))return this.log(`[gjsify build-cache] ${t.name}: opted out (gjsify.buildCache=false) — running uncached`),!1;let n=this.keyFor(t),S=readCacheEntry(this.cacheRoot,t.name,n);if(!S||S.script!==this.options.script)return this.log(`[gjsify build-cache] ${t.name}: miss ${n} — running "${this.options.script}"`),!1;let C=restoreCacheEntry(this.cacheRoot,t,S);if(C===null)return this.log(`[gjsify build-cache] ${t.name}: entry ${n} unrestorable — running "${this.options.script}"`),!1;let N=S.dirs.length>0?S.dirs.join(`, `):`no output dirs`;return this.log(`[gjsify build-cache] ${t.name}: hit ${n} — ${C===`restored`?`restored ${N}`:`${N} up to date`} (skipped "${this.options.script}")`),!0}catch(n){return this.log(`[gjsify build-cache] ${t.name}: cache error (${n.message}) — running uncached`),!1}}snapshotOutputs(t){try{return snapshotOutputDirs(t.location)}catch{return{}}}storeAfterSuccess(t,n){try{if(buildCacheOptedOut(t))return;let S=this.keyFor(t),C=modifiedOutputDirs(t.location,n);if(storeCacheEntry(this.cacheRoot,t,S,this.options.script,C)){let n=C.length>0?C.join(`, `):`no output dirs modified`;this.log(`[gjsify build-cache] ${t.name}: stored ${S} (${n})`)}}catch(n){this.log(`[gjsify build-cache] ${t.name}: store failed (${n.message}) — continuing`)}}}});function editDistance(t,n){if(t===n)return 0;if(t.length===0)return n.length;if(n.length===0)return t.length;let S=Array.from({length:n.length+1},(t,n)=>n),C=Array.from({length:n.length+1},()=>0);for(let N=1;N<=t.length;N++){C[0]=N;for(let F=1;F<=n.length;F++){let I=t[N-1]===n[F-1]?0:1;C[F]=Math.min(S[F]+1,C[F-1]+1,S[F-1]+I)}[S,C]=[C,S]}return S[n.length]}function suggestClosest(t,n){if(n.length===0)return;let S=t.toLowerCase(),C=Math.max(2,Math.floor(t.length/3)),N,F=1/0;for(let t of n){let n=editDistance(S,t.toLowerCase());n<F&&(F=n,N=t)}return N!==void 0&&F<=C?N:void 0}var SR=__esmMin(()=>{});function reportUnlinked(t,n){for(let S of t)n.has(S.from)&&ge.error(`gjsify workspace: "${S.from}" depends on "${S.to}": ${S.spec}, which the local workspace (${S.to}@${S.version}) does not satisfy — NOT built as a dependency. npm and yarn take that one from the registry; \`gjsify install\` links the local one anyway, so if it is the local one you mean, make the range admit ${S.version}.`)}async function runOne$1(t,n,S,C,N,F){if(F&&F.tryRestore(t))return;let I=F?.snapshotOutputs(t),H=C===`gjsify`?[`run`,n,...S]:[`run`,n,...S.length>0?[`--`,...S]:[]];N&&ge.error(`[${t.name}] $ ${C} ${H.join(` `)}`);let{code:W}=await spawnToCompletion(C,H,{completion:`exit`,cwd:t.location,color:!0});if(W!==0)throw Error(`${C} ${H.join(` `)} exited with code ${W}`);F&&I&&F.storeAfterSuccess(t,I)}function detectPackageManager(){if(isGjs()||usingSelfShim())return`gjsify`;let t=process.env.npm_config_user_agent??``;return t.startsWith(`yarn/`)?`yarn`:t.startsWith(`gjsify/`)?`gjsify`:`npm`}var CR,wR=__esmMin(()=>{_e(),V_(),QP(),eF(),xR(),d_(),cR(),SR(),CR={command:`workspace <name> <script> [args..]`,description:"Run a workspace script. Both `workspace <name> <script>` and the yarn spelling `workspace <name> run <script>` work.",builder:t=>t.positional(`name`,{description:"Workspace name (matches package.json `name` field).",type:`string`,demandOption:!0}).positional(`script`,{description:`Script name to run inside that workspace.`,type:`string`,demandOption:!0}).positional(`args`,{description:`Extra arguments forwarded to the script.`,type:`string`,array:!0}).option(`with-dependencies`,{description:"Pre-build the target workspace's transitive workspace dependencies in topological order before running the script in the target. Deps that don't declare the script are skipped (--if-present behaviour). Replaces manual `gjsify workspace A build && gjsify workspace B build && …` chains.",type:`boolean`,alias:[`d`,`t`,`topological`],default:!1}).option(`include-dev`,{description:"When --with-dependencies is set, also walk devDependencies (production deps only by default — matches `gjsify foreach -t`).",type:`boolean`,default:!1}).option(`continue-on-error`,{description:`When --with-dependencies is set, keep running remaining deps after one fails (default: stop on first failure).`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo every spawned command before running it.`,type:`boolean`,alias:`v`,default:!1}).option(`cached`,{description:`Content-hash build cache (ADR 0006): skip the script for a workspace whose inputs (src/**, package.json, tsconfig*.json, transitive workspace deps, toolchain versions) are unchanged and restore its stored outputs instead; on miss run it and store the output dirs it modified. Also applies to the deps run via --with-dependencies. Default from GJSIFY_BUILD_CACHE=1.`,type:`boolean`}),handler:async t=>{let n=findWorkspaceRoot(process.cwd())??process.cwd(),S=discoverWorkspaces(n),C=S.find(n=>n.name===t.name);if(!C){let C=suggestClosest(t.name,S.map(t=>t.name)),N=C?` — did you mean "${C}"?`:``;return ge.error(`gjsify workspace: no workspace named "${t.name}"${N} (discovered ${S.length} workspace(s) under ${n})`),process.exit(1)}let N=detectPackageManager(),F=t.verbose===!0,I=t[`with-dependencies`]===!0,H=t[`continue-on-error`]===!0,W=t.script,q=t.args??[];W===`run`&&q.length>0&&([W,...q]=q);let Y=C.manifest.scripts??{};if(typeof Y[W]!=`string`){let n=suggestClosest(W,Object.keys(Y));return ge.error(`gjsify workspace: workspace "${t.name}" has no script "${W}"`+(n?` — did you mean "${n}"?`:``)),process.exit(1)}let X;if(I){let n=t[`include-dev`]===!0,N=buildDependencyGraph(S,{includeDev:n}),F=affectedClosure(N,[C.name]),I=S.filter(t=>F.has(t.name));reportUnlinked(N.unlinked,F),X=topologicalSort(buildDependencyGraph(I,{includeDev:n})),X.length===1&&ge.error(`gjsify workspace: --with-dependencies found no workspace dependencies of "${C.name}" — running "${W}" in it alone.`)}else X=[C];let Z=t.cached??buildCacheEnabledByEnv()?new BuildCacheRunner({root:n,workspaces:S,script:W,args:q,targets:X.map(t=>t.name)}):void 0,te=[];for(let t of X){if(typeof(t.manifest.scripts??{})[W]!=`string`){F&&ge.error(`[${t.name}] (no "${W}" script — skipping)`);continue}try{await runOne$1(t,W,q,N,F,Z)}catch(n){let S=n instanceof Error?n:Error(String(n));if(ge.error(`[${t.name}] ${S.message}`),!H)return process.exit(1);te.push({workspace:t.name,error:S})}}return te.length>0?(ge.error(`gjsify workspace: ${te.length} workspace(s) failed: ${te.map(t=>t.workspace).join(`, `)}`),process.exit(1)):process.exit(0)}},__name$1(runOne$1,`runOne`)});async function runCheck(t,n){let S=[],C=detectPackageManager();if(C===`gjsify`&&readPackageJson$2(wn(t.location,`package.json`))?.scripts?.check===void 0)return 0;let N=C===`gjsify`?[`run`,`check`]:[`run`,`check`,`--if-present`];try{let{code:F}=await spawnToCompletion(C,N,{completion:`exit`,cwd:t.location,stdio:n===null?`inherit`:`pipe`,onSpawn:t=>{let C=!process.stdout.isTTY;if(n!==null&&t.stdout&&t.stderr){let N=`[${n}] `;S.push(prefixLines(t.stdout,process.stdout,N,C)),S.push(prefixLines(t.stderr,process.stderr,N,C))}}});for(let t of S)t();return F??1}catch{for(let t of S)t();return 1}}var TR,ER=__esmMin(()=>{_e(),_R(),V_(),$P(),Pn(),Lg(),QP(),eF(),wR(),TR={command:`check`,description:"Run `npm run check` (TypeScript type-check) across the current workspace. In a workspace root: walks every package with a `check` script (excludes @girs/*; honours --include/--exclude). In a single package: runs the local `check` script directly. Symmetric peer of `gjsify format` / `lint` / `fix`. (Legacy system-dep `gjsify check` is now `gjsify system-check` — see #254.)",builder:t=>t.option(`include`,{description:`Only run in workspaces matching these glob patterns (repeatable).`,type:`string`,array:!0}).option(`exclude`,{description:`Skip workspaces matching these glob patterns (repeatable). Always excludes @girs/*.`,type:`string`,array:!0}).option(`parallel`,{description:`Run workspace checks in parallel (default). Use --no-parallel to run them sequentially with full per-workspace output.`,type:`boolean`,alias:`p`,default:!0}).option(`jobs`,{description:`Max parallel workers (when --parallel). Default: os.cpus().length.`,type:`number`,alias:`j`}).option(`verbose`,{description:`Log the per-workspace command before spawning.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=findWorkspaceRoot(n);if(S&&n!==S&&readPackageJson$2(wn(n,`package.json`))?.scripts?.check){t.verbose&&ge.log(`[check] cwd=${n} → npm run check`);let{code:S}=await spawnToCompletion(detectPackageManager(),[`run`,`check`],{cwd:n,completion:`exit`});return process.exit(S??1)}if(!S)return ge.error("gjsify check: no workspace root found from cwd. Run inside a workspace (or a package within one) with `npm run check` defined."),process.exit(1);let C=discoverWorkspaces(S),N=[`@girs/*`,...t.exclude??[]],F=filterWorkspaces(C,{include:t.include,exclude:N}).filter(t=>t.manifest.scripts?.check!==void 0);if(F.length===0)return ge.error("gjsify check: no workspaces with a `check` script found."),process.exit(1);if(t.verbose&&ge.log(`[check] root=${S} workspaces=${F.length} parallel=${t.parallel?`yes`:`no`}`),!t.parallel){let n=0,S=0;for(let C of F){t.verbose&&ge.log(`[check] → ${C.name}`);let N=await runCheck(C,null);N!==0&&(S++,n===0&&(n=N))}return n!==0&&ge.error(`gjsify check: failures in ${S} workspace(s)`),process.exit(n)}let I=t.jobs??Math.max(1,cpus().length),H=[],W=0,q=[];for(let t=0;t<I;t++)q.push((async()=>{for(;;){let t=W++;if(t>=F.length)return;let n=F[t],S=await runCheck(n,n.name);S!==0&&H.push({name:n.name,code:S})}})());if(await Promise.all(q),H.length>0){ge.error(`\ngjsify check: ${H.length} of ${F.length} workspace(s) failed:`);for(let t of H)ge.error(` ✗ ${t.name} (exit ${t.code})`);return process.exit(1)}t.verbose&&ge.log(`\ngjsify check: ${F.length} workspace(s) green.`),process.exit(0)}}});function manifestPath(){let t=process.env.GJSIFY_SHOWCASES_MANIFEST;if(t)return t;let n=En(fileURLToPath(import.meta.url)),S=[wn(n,`..`,`..`,`showcases.json`),wn(n,`..`,`showcases.json`)];return S.find(t=>existsSync(t))??S[0]}function discoverShowcases(){let t=manifestPath();if(!existsSync(t))return[];let n;try{n=JSON.parse(readFileSync(t,`utf-8`))}catch{return[]}if(!Array.isArray(n.showcases))return[];let S=n.showcases.map(t=>({name:t.name,packageName:t.package,category:t.category,description:t.description??``}));return S.sort((t,n)=>t.category.localeCompare(n.category)||t.name.localeCompare(n.name)),S}function findShowcase(t){return discoverShowcases().find(n=>n.name===t)}var DR=__esmMin(()=>{Rd(),Pn(),Gn()});function parseSpec(t){if(!t)throw Error(`dlx: empty package spec`);if(t.startsWith(`./`)||t.startsWith(`../`)||Cn(t)||existsSync(t))return{kind:`local`,path:xn(t)};let n=t,S,C=t.lastIndexOf(`@`);if(C>0&&(n=t.slice(0,C),S=t.slice(C+1)),!OR.test(n))throw Error(`dlx: invalid package name "${n}"`);return{kind:`registry`,name:n,version:S,spec:t}}var OR,kR=__esmMin(()=>{Rd(),Pn(),OR=/^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/});function resolveGjsEntry(t,n){let S=wn(t,`package.json`);if(!existsSync(S))throw Error(`dlx: no package.json found at ${t}`);let C=JSON.parse(readFileSync(S,`utf-8`)),N=C.gjsify?.bin,F=C.gjsify?.main,I=C.main,H,W=null,q=!1;if(n!==null){if(!N||!N[n]){let S=N?Object.keys(N).join(`, `):`(none)`;throw Error(`dlx: package "${C.name??t}" has no GJS bin named "${n}" — known: ${S}`)}H=N[n],W=n}else if(N&&Object.keys(N).length===1){let t=Object.keys(N)[0];H=N[t],W=t}else F?H=F:I&&(H=I,q=!0);if(N&&Object.keys(N).length>1&&n===null){let n=Object.keys(N).join(`, `);throw Error(`dlx: package "${C.name??t}" defines multiple GJS bins — pass one of: ${n}`)}if(!H)throw Error(`dlx: package "${C.name??t}" has no GJS entry — set \`gjsify.main\` (or \`gjsify.bin\`) in its package.json`);let Y=xn(t,H);if(!existsSync(Y))throw Error(`dlx: GJS entry not found: ${Y}`);return{bundlePath:Y,binName:W,fromFallback:q}}function resolveNodeEntry(t){let n=wn(t,`package.json`);if(!existsSync(n))throw Error(`no package.json found at ${t}`);let S=JSON.parse(readFileSync(n,`utf-8`)),C=S.gjsify?.example?.node;if(C){let n=xn(t,C);if(!existsSync(n))throw Error(`declared node entry not found: ${n} (gjsify.example.node)`);return n}let N=S.gjsify?.main??(S.gjsify?.bin?Object.values(S.gjsify.bin)[0]:void 0)??S.main;if(!N)throw Error(`package "${S.name??t}" has no entry to derive a node bundle from — set \`gjsify.example.node\` to its \`--app node\` bundle path.`);let F=N.replace(/\.gjs\.(js|mjs|cjs)$/,``).replace(/\.(js|mjs|cjs)$/,``),I=[`${F}.node.mjs`,`${F}.node.js`,`${F}.node.cjs`];for(let n of I){let S=xn(t,n);if(existsSync(S))return S}throw Error(`package "${S.name??t}" has no \`--app node\` bundle — looked for ${I.join(`, `)}.\n Build one (e.g. \`gjsify build src/app.ts --app node --outfile dist/app.node.mjs\`) or set \`gjsify.example.node\` to its path.`)}var AR=__esmMin(()=>{Rd(),Pn()});function lexCompare(t,n){return t<n?-1:+(t>n)}function createCacheKey(t){let n=[...t.packages].sort(lexCompare),S=Object.entries(t.registries??{}).sort(([t],[n])=>lexCompare(t,n)),C=JSON.stringify([n,S]);return createHash(`sha256`).update(C).digest(`hex`)}function dlxCacheRoot(){let t=process.env.XDG_CACHE_HOME,n=wn(t&&t.length>0?t:wn(homedir(),`.cache`),`gjsify`,`dlx`);return mkdirSync(n,{recursive:!0}),n}function cacheDirFor(t){let n=wn(dlxCacheRoot(),t);return mkdirSync(n,{recursive:!0}),n}function makePrepareDir(t){let n=wn(t,`${Date.now().toString(16)}-${process.pid.toString(16)}`);return mkdirSync(n,{recursive:!0}),n}function getValidCachedPkg(t,n=MR){let S=wn(t,`pkg`),C;try{C=lstatSync(S)}catch(t){if(t.code===`ENOENT`)return;throw t}if(!C.isSymbolicLink())return;let N;try{N=realpathSync(S)}catch{return}return Date.now()-C.mtime.getTime()<=n*jR?N:void 0}function symlinkSwap(t,n,S={}){let C=S.junctions??dirLinksAreJunctions(),N=wn(t,`pkg`),F=wn(t,`pkg.tmp-${Date.now().toString(16)}-${process.pid.toString(16)}`);linkDirSync(F,n);try{C&&rmSync(N,{force:!0,recursive:!1,maxRetries:10,retryDelay:100}),renameSync(F,N)}catch(t){let S=t.code;if(S===`EBUSY`||S===`EPERM`||S===`EEXIST`||S===`EACCES`){rmSync(F,{force:!0});try{return realpathSync(N)}catch{return realpathSync(n)}}throw t}return realpathSync(N)}function resolveInstalledPkgDir(t,n){return xn(t,`node_modules`,n)}var jR,MR,NR=__esmMin(()=>{Qc(),Rd(),Lg(),Pn(),PL(),jR=6e4,MR=1440*7});async function ensurePkgDir(t,n){if(t.kind===`local`)return{pkgDir:t.path,cachedPkgName:null};let S=[t.spec,...n.extraSpecs??[]],C=cacheDirFor(createCacheKey({packages:S})),N=n.cacheMaxAge>0?getValidCachedPkg(C,n.cacheMaxAge):void 0;if(N)return{pkgDir:resolveInstalledPkgDir(N,t.name),cachedPkgName:t.name};let F=makePrepareDir(C),I=makeProgressReporter({enabled:!n.verbose});return await installPackages({prefix:F,specs:S,verbose:n.verbose,registry:n.registry,lockfile:!0,frozen:n.frozen,progress:I}),{pkgDir:resolveInstalledPkgDir(symlinkSwap(C,F),t.name),cachedPkgName:t.name}}function splitBinAndArgs(t,n,S){if(!n)return{binName:null,extraArgs:S};let C=wn(t,`package.json`);if(existsSync(C))try{let t=JSON.parse(readFileSync(C,`utf-8`)).gjsify?.bin;if(t&&Object.prototype.hasOwnProperty.call(t,n))return{binName:n,extraArgs:S}}catch{}return{binName:null,extraArgs:[n,...S]}}var PR,FR=__esmMin(()=>{_e(),XI(),kR(),AR(),NI(),NR(),eR(),Rd(),Pn(),PR={command:`dlx <spec> [binOrArg] [extraArgs..]`,description:`Run the GJS bundle of an npm-published package without installing it locally.`,builder:t=>t.parserConfiguration({"populate--":!0,"parse-positional-numbers":!1}).positional(`spec`,{description:"Package spec (`name`, `name@version`, `@scope/name@spec`, or local path).",type:`string`,demandOption:!0}).positional(`binOrArg`,{description:"Optional bin name when the package defines `gjsify.bin` with multiple entries; otherwise treated as the first argument forwarded to the bundle. To pass a flag here (e.g. `--help`) use the `--` separator: `gjsify dlx <pkg> -- --help`.",type:`string`}).positional(`extraArgs`,{description:"Extra args forwarded to `gjs -m <bundle>`. Use `--` before flags to bypass gjsify-level parsing (`gjsify dlx <pkg> -- --help --verbose`).",type:`string`,array:!0}).option(`cache-max-age`,{description:`Cache TTL in minutes. Defaults to 7 days. Use 0 to bypass cache.`,type:`number`,default:1440*7}).option(`reinstall`,{description:`Bypass the cache for this run (alias for --cache-max-age=0).`,type:`boolean`,default:!1}).option(`frozen`,{description:`Use the project-local gjsify-lock.json verbatim — fail if missing or stale (no resolver pass).`,type:`boolean`,default:!1}).option(`verbose`,{description:`Verbose logging (passes --loglevel verbose to npm).`,type:`boolean`,default:!1}).option(`registry`,{description:`Registry URL override.`,type:`string`}),handler:async t=>{let n=parseSpec(t.spec),S=t.reinstall?0:t[`cache-max-age`],{pkgDir:C,cachedPkgName:N}=await ensurePkgDir(n,{verbose:t.verbose,registry:t.registry,cacheMaxAge:S,frozen:t.frozen}),F=[...t.extraArgs??[],...doubleDashArgs(t)],{binName:I,extraArgs:H}=splitBinAndArgs(C,t.binOrArg,F),W=resolveGjsEntry(C,I);W.fromFallback&&ge.warn(`[gjsify dlx] package "${N??n.kind}" declares no \`gjsify.main\` — falling back to package.json#main. Add \`gjsify.main\` to silence.`),await runGjsBundle(W.bundlePath,H,{completion:`exit`,exitOnSuccess:!0})}}});async function loadNpmrc(t){let n=[],S=wn(t,`.npmrc`);existsSync(S)&&n.push(readFileSync(S,`utf-8`));let C=process.env.NPM_CONFIG_USERCONFIG;if(C&&existsSync(C))n.push(readFileSync(C,`utf-8`));else{let t=wn(homedir(),`.npmrc`);existsSync(t)&&n.push(readFileSync(t,`utf-8`))}return parseNpmrc(n.join(`
946
- `).replace(/\$\{([A-Z_][A-Z0-9_]*)\}/gi,(t,n)=>process.env[n]??``))}function hasAnyAuthToken(t){return Object.keys(t.authTokens).length>0}function hasAnyCredential(t){return hasAnyAuthToken(t)||Object.keys(t.basicAuth).length>0}var IR=__esmMin(()=>{Rd(),Lg(),Pn(),eh()});function readCliVersion(){let t=cliVersion();return t===`unknown`?void 0:t}function runningAs(t){return t?`[gjsify ${t}] `:``}async function resolveShowcaseDir(t,n,S=[]){let C=resolveLocalShowcaseDir(t);if(C)return C;let{pkgDir:N}=await ensurePkgDir(parseSpec(n?`${t.packageName}@${n}`:t.packageName),{verbose:!1,cacheMaxAge:1440*7,frozen:!1,extraSpecs:S});return N}function resolveLocalShowcaseDir(t){try{let n=createRequire(import.meta.url).resolve(`${t.packageName}/package.json`);if(existsSync(n))return En(n)}catch{}return null}function gtkRuntimeSpecs(t){let n=`${process.platform}-${process.arch}`;if(![`win32-x64`,`darwin-arm64`,`darwin-x64`].includes(n))return[];let S=`@gjsify/gtk-runtime-${n}`;return[t?`${S}@${t}`:S]}async function preflightDeclaredRuntimes(t,n){try{return declaredRuntimesFromPackument(await fetchPackument(t.packageName,{npmrc:await loadNpmrc(process.cwd()),fullMetadata:!0}),n)}catch{return}}function declaredRuntimesFromPackument(t,n){let S=n??t[`dist-tags`]?.latest,C=S?t.versions?.[S]:void 0;if(C)return readDeclaredRuntimes(C)}async function runShowcaseOnRuntime(t,n,S){if(resolveLocalShowcaseDir(t)===null){let C=await preflightDeclaredRuntimes(t,S);if(C!==void 0){let S=checkRuntimeSupported(n,C,t.name);if(!S.ok)return ge.error(S.message),process.exit(1)}}let C;try{C=await resolveShowcaseDir(t,S,[S?`@gjsify/node-gi@${S}`:`@gjsify/node-gi`,...gtkRuntimeSpecs(S)])}catch(n){return ge.error(`Could not resolve showcase "${t.name}": ${n.message}`),process.exit(1)}let N={};try{N=JSON.parse(readFileSync(`${C}/package.json`,`utf-8`))}catch{}let F=checkRuntimeSupported(n,readDeclaredRuntimes(N),t.name);if(!F.ok)return ge.error(F.message),process.exit(1);let I;try{I=resolveNodeEntry(C)}catch(C){let F=typeof N.name==`string`?`${N.name}@${S??`?`}`:t.packageName;return ge.error(`Cannot run showcase "${t.name}" on ${n}: ${C.message}\n\n ${F} declares --runtime ${n} but ships no \`--app node\` bundle, so that\n version of the showcase cannot run there. You are running gjsify ${S??`(unknown)`},\n and \`showcase\` pins the showcase to the CLI's own version.\n\n ${LR}\n\n Or run it on GJS, which every showcase ships: gjsify showcase ${t.name} --runtime gjs`),process.exit(1)}ge.log(`Running showcase: ${t.name} ${runningAs(S)}on ${n} (${I})\n`);try{await runRuntimeBundle(n,I,[],{completion:`exit`,exitOnSuccess:!0})}catch(t){return ge.error(`${t.message}\n\n The showcase and the \`@gjsify/node-gi\` bridge it needs are both installed by THIS CLI\n (gjsify ${S??`(unknown)`}) into its own cache, so a missing bridge points at the CLI\n rather than at anything in your project.\n\n ${LR}`),process.exit(1)}}var LR,RR,zR=__esmMin(()=>{_e(),DR(),vF(),Il(),Pn(),Rd(),FR(),eh(),IR(),kR(),nh(),AR(),QI(),W_(),LR=`A package runner reuses a CACHED copy of an unpinned bin. Force the current one:
944
+ `);for(let C of[...n].sort()){let n=wn(t,C);if(!existsSync(n)){S.update(`${C} absent\n`);continue}let N=[];walkFiles(n,C,N);for(let t of N){if(t.link!==void 0){S.update(`${t.rel} link:${t.link}\n`);continue}try{S.update(`${t.rel} ${hashFileStream(t.abs)}\n`)}catch{S.update(`${t.rel} unreadable\n`)}}}return S.digest(`hex`)}function outputUnits(t){let n=[];for(let S of CR){let C=wn(t,S);if(!existsSync(C))continue;let N;try{N=readdirSync(C).filter(t=>t!==`node_modules`&&!isBuildInfo(t))}catch{continue}let F=N.every(t=>{try{return lstatSync(wn(C,t)).isDirectory()}catch{return!1}});if(N.length===0||!F){n.push(S);continue}for(let t of[...N].sort())n.push(`${S}/${t}`)}return n}function signatureOf(t,n){let S=[];walkFiles(wn(t,n),n,S);let C=createHash(`sha256`);for(let t of S){let n=`link`;if(t.link===void 0)try{let S=lstatSync(t.abs);n=`${S.size}:${S.mtimeMs}`}catch{n=`gone`}C.update(`${t.rel} ${n}\n`)}return C.digest(`hex`)}function snapshotOutputDirs(t){let n={};for(let t of CR)n[t]=null;for(let S of outputUnits(t))n[S]=signatureOf(t,S);return n}function modifiedOutputDirs(t,n){let S=[];for(let C of outputUnits(t))signatureOf(t,C)!==(n[C]??null)&&S.push(C);return S.sort()}function composeCacheKey(t){let n=createHash(`sha256`);n.update(`gjsify-build-cache/v4
945
+ `),n.update(`script:${t.script}\n`);for(let S of t.args??[])n.update(`arg:${S}\n`);for(let S of Object.keys(t.toolchain).sort())n.update(`tool:${S}@${t.toolchain[S]}\n`);n.update(`self:${t.ownHash}\n`);let S=t.depHashes instanceof Map?t.depHashes:new Map(Object.entries(t.depHashes));for(let t of[...S.keys()].sort())n.update(`dep:${t} ${S.get(t)}\n`);return n.digest(`hex`).slice(0,32)}function resolveToolchainVersions(t){let n={};for(let S of wR){let C=`none`;try{let n=readFileSync(wn(t,`node_modules`,...S.split(`/`),`package.json`),`utf-8`),N=JSON.parse(n);typeof N.version==`string`&&(C=N.version)}catch{}S===`@gjsify/cli`&&C===`none`&&(C=readOwnCliVersion()??`none`),n[S]=C}return n}function readOwnCliVersion(){try{let t=En(fileURLToPath(import.meta.url));for(let n=0;n<4;n++){let n=wn(t,`package.json`);if(existsSync(n)){let t=JSON.parse(readFileSync(n,`utf-8`));if(t.name===`@gjsify/cli`&&typeof t.version==`string`)return t.version}t=En(t)}}catch{}return null}function copyDirRecursive(t,n){mkdirSync(n,{recursive:!0});for(let S of readdirSync(t).sort()){let C=wn(t,S),N=wn(n,S),F=lstatSync(C);if(F.isSymbolicLink())replicateLinkSync(C,N);else if(F.isDirectory())copyDirRecursive(C,N);else if(F.isFile()){copyFileSync(C,N);try{chmodSync(N,F.mode&511)}catch{}}}}function buildCacheEntryDir(t,n,S){return wn(t,sanitizePackageDirName(n),S)}function readCacheEntry(t,n,S){let C=wn(TR(t,n,S),`manifest.json`);try{let N=JSON.parse(readFileSync(C,`utf-8`));if(N.version!==1||N.layout!==`v4`||N.package!==n||N.key!==S||!Array.isArray(N.dirs))return null;for(let C of N.dirs)if(!existsSync(wn(TR(t,n,S),`outputs`,C)))return null;return N}catch{return null}}function storeCacheEntry(t,n,S,C,N){let F=TR(t,n.name,S),I=`${F}.tmp-${process.pid}`;try{rmSync(I,{recursive:!0,force:!0}),mkdirSync(wn(I,`outputs`),{recursive:!0});for(let t of N)copyDirRecursive(wn(n.location,t),wn(I,`outputs`,t));let H=new Date().toISOString(),W={version:1,layout:`v4`,package:n.name,script:C,key:S,dirs:[...N],outputsHash:hashOutputDirs(n.location,N),createdAt:H,usedAt:H};return writeFileSync(wn(I,`manifest.json`),JSON.stringify(W,null,2)),rmSync(F,{recursive:!0,force:!0}),renameSync(I,F),pruneCacheEntries(t,n.name),W}catch{try{rmSync(I,{recursive:!0,force:!0})}catch{}return null}}function restoreCacheEntry(t,n,S){let C=TR(t,n.name,S.key);try{if(S.dirs.length>0&&hashOutputDirs(n.location,S.dirs)===S.outputsHash)return touchManifestUsed(C,S),`up-to-date`;for(let t of S.dirs){let S=wn(n.location,t);rmSync(S,{recursive:!0,force:!0}),copyDirRecursive(wn(C,`outputs`,t),S)}return touchManifestUsed(C,S),S.dirs.length>0?`restored`:`up-to-date`}catch{return null}}function touchManifestUsed(t,n){try{n.usedAt=new Date().toISOString(),writeFileSync(wn(t,`manifest.json`),JSON.stringify(n,null,2))}catch{}}function pruneCacheEntries(t,n,S=2){let C=wn(t,sanitizePackageDirName(n)),N;try{N=readdirSync(C)}catch{return}let F=[];for(let t of N){if(t.includes(`.tmp-`)){try{rmSync(wn(C,t),{recursive:!0,force:!0})}catch{}continue}let n=``;try{let S=JSON.parse(readFileSync(wn(C,t,`manifest.json`),`utf-8`));n=S.usedAt??S.createdAt??``}catch{}F.push({name:t,stamp:n})}if(!(F.length<=S)){F.sort((t,n)=>t.stamp<n.stamp?1:t.stamp>n.stamp?-1:0);for(let t of F.slice(S))try{rmSync(wn(C,t.name),{recursive:!0,force:!0})}catch{}}}function buildCacheOptedOut(t){return t.manifest.gjsify?.buildCache===!1}var CR,wR,isBuildInfo,TR,BuildCacheRunner,ER=__esmMin(()=>{_e(),Qc(),Rd(),Pn(),Gn(),QP(),zL(),CI(),CR=xI,wR=[`@gjsify/cli`,`@gjsify/tsc`,`rolldown`,`typescript`],isBuildInfo=t=>t.endsWith(`.tsbuildinfo`),TR=buildCacheEntryDir,BuildCacheRunner=class{options;cacheRoot;graph;toolchain;ownHashes=new Map;closures=new Map;keys=new Map;log;constructor(t){this.options=t,this.cacheRoot=buildCacheRoot(t.root),this.graph=buildDependencyGraph(t.workspaces,{includeDev:!0,includePeer:!0,includeOptional:!0}),this.toolchain=resolveToolchainVersions(t.root),this.log=t.log??(t=>ge.error(t));for(let n of t.targets??[])if(this.graph.byName.has(n)){this.ownHashOf(n);for(let t of this.closureOf(n))this.ownHashOf(t)}}ownHashOf(t){let n=this.ownHashes.get(t);if(n===void 0){let S=this.graph.byName.get(t);n=S?hashPackageInputs(S.location):`unknown-workspace`,this.ownHashes.set(t,n)}return n}closureOf(t){let n=this.closures.get(t);if(n===void 0){let S=new Set,C=[...this.graph.edges.get(t)??[]];for(;C.length>0;){let n=C.shift();if(!(n===t||S.has(n))){S.add(n);for(let N of this.graph.edges.get(n)??[])!S.has(N)&&N!==t&&C.push(N)}}n=[...S].sort(),this.closures.set(t,n)}return n}keyFor(t){let n=this.keys.get(t.name);if(n===void 0){let S=new Map;for(let n of this.closureOf(t.name))S.set(n,this.ownHashOf(n));n=composeCacheKey({script:this.options.script,args:this.options.args,toolchain:this.toolchain,ownHash:this.ownHashOf(t.name),depHashes:S}),this.keys.set(t.name,n)}return n}tryRestore(t){try{if(buildCacheOptedOut(t))return this.log(`[gjsify build-cache] ${t.name}: opted out (gjsify.buildCache=false) — running uncached`),!1;let n=this.keyFor(t),S=readCacheEntry(this.cacheRoot,t.name,n);if(!S||S.script!==this.options.script)return this.log(`[gjsify build-cache] ${t.name}: miss ${n} — running "${this.options.script}"`),!1;let C=restoreCacheEntry(this.cacheRoot,t,S);if(C===null)return this.log(`[gjsify build-cache] ${t.name}: entry ${n} unrestorable — running "${this.options.script}"`),!1;let N=S.dirs.length>0?S.dirs.join(`, `):`no output dirs`;return this.log(`[gjsify build-cache] ${t.name}: hit ${n} — ${C===`restored`?`restored ${N}`:`${N} up to date`} (skipped "${this.options.script}")`),!0}catch(n){return this.log(`[gjsify build-cache] ${t.name}: cache error (${n.message}) — running uncached`),!1}}snapshotOutputs(t){try{return snapshotOutputDirs(t.location)}catch{return{}}}storeAfterSuccess(t,n){try{if(buildCacheOptedOut(t))return;let S=this.keyFor(t),C=modifiedOutputDirs(t.location,n);if(storeCacheEntry(this.cacheRoot,t,S,this.options.script,C)){let n=C.length>0?C.join(`, `):`no output dirs modified`;this.log(`[gjsify build-cache] ${t.name}: stored ${S} (${n})`)}}catch(n){this.log(`[gjsify build-cache] ${t.name}: store failed (${n.message}) — continuing`)}}}});function editDistance(t,n){if(t===n)return 0;if(t.length===0)return n.length;if(n.length===0)return t.length;let S=Array.from({length:n.length+1},(t,n)=>n),C=Array.from({length:n.length+1},()=>0);for(let N=1;N<=t.length;N++){C[0]=N;for(let F=1;F<=n.length;F++){let I=t[N-1]===n[F-1]?0:1;C[F]=Math.min(S[F]+1,C[F-1]+1,S[F-1]+I)}[S,C]=[C,S]}return S[n.length]}function suggestClosest(t,n){if(n.length===0)return;let S=t.toLowerCase(),C=Math.max(2,Math.floor(t.length/3)),N,F=1/0;for(let t of n){let n=editDistance(S,t.toLowerCase());n<F&&(F=n,N=t)}return N!==void 0&&F<=C?N:void 0}var DR=__esmMin(()=>{});function reportUnlinked(t,n){for(let S of t)n.has(S.from)&&ge.error(`gjsify workspace: "${S.from}" depends on "${S.to}": ${S.spec}, which the local workspace (${S.to}@${S.version}) does not satisfy — NOT built as a dependency. npm and yarn take that one from the registry; \`gjsify install\` links the local one anyway, so if it is the local one you mean, make the range admit ${S.version}.`)}async function runOne$1(t,n,S,C,N,F){if(F&&F.tryRestore(t))return;let I=F?.snapshotOutputs(t),H=C===`gjsify`?[`run`,n,...S]:[`run`,n,...S.length>0?[`--`,...S]:[]];N&&ge.error(`[${t.name}] $ ${C} ${H.join(` `)}`);let{code:W}=await spawnToCompletion(C,H,{completion:`exit`,cwd:t.location,color:!0});if(W!==0)throw Error(`${C} ${H.join(` `)} exited with code ${W}`);F&&I&&F.storeAfterSuccess(t,I)}function detectPackageManager(){if(isGjs()||usingSelfShim())return`gjsify`;let t=process.env.npm_config_user_agent??``;return t.startsWith(`yarn/`)?`yarn`:t.startsWith(`gjsify/`)?`gjsify`:`npm`}var OR,kR=__esmMin(()=>{_e(),V_(),QP(),eF(),ER(),d_(),pR(),DR(),OR={command:`workspace <name> <script> [args..]`,description:"Run a workspace script. Both `workspace <name> <script>` and the yarn spelling `workspace <name> run <script>` work.",builder:t=>t.positional(`name`,{description:"Workspace name (matches package.json `name` field).",type:`string`,demandOption:!0}).positional(`script`,{description:`Script name to run inside that workspace.`,type:`string`,demandOption:!0}).positional(`args`,{description:`Extra arguments forwarded to the script.`,type:`string`,array:!0}).option(`with-dependencies`,{description:"Pre-build the target workspace's transitive workspace dependencies in topological order before running the script in the target. Deps that don't declare the script are skipped (--if-present behaviour). Replaces manual `gjsify workspace A build && gjsify workspace B build && …` chains.",type:`boolean`,alias:[`d`,`t`,`topological`],default:!1}).option(`include-dev`,{description:"When --with-dependencies is set, also walk devDependencies (production deps only by default — matches `gjsify foreach -t`).",type:`boolean`,default:!1}).option(`continue-on-error`,{description:`When --with-dependencies is set, keep running remaining deps after one fails (default: stop on first failure).`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo every spawned command before running it.`,type:`boolean`,alias:`v`,default:!1}).option(`cached`,{description:`Content-hash build cache (ADR 0006): skip the script for a workspace whose inputs (src/**, package.json, tsconfig*.json, transitive workspace deps, toolchain versions) are unchanged and restore its stored outputs instead; on miss run it and store the output dirs it modified. Also applies to the deps run via --with-dependencies. Default from GJSIFY_BUILD_CACHE=1.`,type:`boolean`}),handler:async t=>{let n=findWorkspaceRoot(process.cwd())??process.cwd(),S=discoverWorkspaces(n),C=S.find(n=>n.name===t.name);if(!C){let C=suggestClosest(t.name,S.map(t=>t.name)),N=C?` — did you mean "${C}"?`:``;return ge.error(`gjsify workspace: no workspace named "${t.name}"${N} (discovered ${S.length} workspace(s) under ${n})`),process.exit(1)}let N=detectPackageManager(),F=t.verbose===!0,I=t[`with-dependencies`]===!0,H=t[`continue-on-error`]===!0,W=t.script,q=t.args??[];W===`run`&&q.length>0&&([W,...q]=q);let Y=C.manifest.scripts??{};if(typeof Y[W]!=`string`){let n=suggestClosest(W,Object.keys(Y));return ge.error(`gjsify workspace: workspace "${t.name}" has no script "${W}"`+(n?` — did you mean "${n}"?`:``)),process.exit(1)}let X;if(I){let n=t[`include-dev`]===!0,N=buildDependencyGraph(S,{includeDev:n}),F=affectedClosure(N,[C.name]),I=S.filter(t=>F.has(t.name));reportUnlinked(N.unlinked,F),X=topologicalSort(buildDependencyGraph(I,{includeDev:n})),X.length===1&&ge.error(`gjsify workspace: --with-dependencies found no workspace dependencies of "${C.name}" — running "${W}" in it alone.`)}else X=[C];let Z=t.cached??buildCacheEnabledByEnv()?new BuildCacheRunner({root:n,workspaces:S,script:W,args:q,targets:X.map(t=>t.name)}):void 0,te=[];for(let t of X){if(typeof(t.manifest.scripts??{})[W]!=`string`){F&&ge.error(`[${t.name}] (no "${W}" script — skipping)`);continue}try{await runOne$1(t,W,q,N,F,Z)}catch(n){let S=n instanceof Error?n:Error(String(n));if(ge.error(`[${t.name}] ${S.message}`),!H)return process.exit(1);te.push({workspace:t.name,error:S})}}return te.length>0?(ge.error(`gjsify workspace: ${te.length} workspace(s) failed: ${te.map(t=>t.workspace).join(`, `)}`),process.exit(1)):process.exit(0)}},__name$1(runOne$1,`runOne`)});async function runCheck(t,n){let S=[],C=detectPackageManager();if(C===`gjsify`&&readPackageJson$2(wn(t.location,`package.json`))?.scripts?.check===void 0)return 0;let N=C===`gjsify`?[`run`,`check`]:[`run`,`check`,`--if-present`];try{let{code:F}=await spawnToCompletion(C,N,{completion:`exit`,cwd:t.location,stdio:n===null?`inherit`:`pipe`,onSpawn:t=>{let C=!process.stdout.isTTY;if(n!==null&&t.stdout&&t.stderr){let N=`[${n}] `;S.push(prefixLines(t.stdout,process.stdout,N,C)),S.push(prefixLines(t.stderr,process.stderr,N,C))}}});for(let t of S)t();return F??1}catch{for(let t of S)t();return 1}}var AR,jR=__esmMin(()=>{_e(),SR(),V_(),$P(),Pn(),Lg(),QP(),eF(),kR(),AR={command:`check`,description:"Run `npm run check` (TypeScript type-check) across the current workspace. In a workspace root: walks every package with a `check` script (excludes @girs/*; honours --include/--exclude). In a single package: runs the local `check` script directly. Symmetric peer of `gjsify format` / `lint` / `fix`. (Legacy system-dep `gjsify check` is now `gjsify system-check` — see #254.)",builder:t=>t.option(`include`,{description:`Only run in workspaces matching these glob patterns (repeatable).`,type:`string`,array:!0}).option(`exclude`,{description:`Skip workspaces matching these glob patterns (repeatable). Always excludes @girs/*.`,type:`string`,array:!0}).option(`parallel`,{description:`Run workspace checks in parallel (default). Use --no-parallel to run them sequentially with full per-workspace output.`,type:`boolean`,alias:`p`,default:!0}).option(`jobs`,{description:`Max parallel workers (when --parallel). Default: os.cpus().length.`,type:`number`,alias:`j`}).option(`verbose`,{description:`Log the per-workspace command before spawning.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=findWorkspaceRoot(n);if(S&&n!==S&&readPackageJson$2(wn(n,`package.json`))?.scripts?.check){t.verbose&&ge.log(`[check] cwd=${n} → npm run check`);let{code:S}=await spawnToCompletion(detectPackageManager(),[`run`,`check`],{cwd:n,completion:`exit`});return process.exit(S??1)}if(!S)return ge.error("gjsify check: no workspace root found from cwd. Run inside a workspace (or a package within one) with `npm run check` defined."),process.exit(1);let C=discoverWorkspaces(S),N=[`@girs/*`,...t.exclude??[]],F=filterWorkspaces(C,{include:t.include,exclude:N}).filter(t=>t.manifest.scripts?.check!==void 0);if(F.length===0)return ge.error("gjsify check: no workspaces with a `check` script found."),process.exit(1);if(t.verbose&&ge.log(`[check] root=${S} workspaces=${F.length} parallel=${t.parallel?`yes`:`no`}`),!t.parallel){let n=0,S=0;for(let C of F){t.verbose&&ge.log(`[check] → ${C.name}`);let N=await runCheck(C,null);N!==0&&(S++,n===0&&(n=N))}return n!==0&&ge.error(`gjsify check: failures in ${S} workspace(s)`),process.exit(n)}let I=t.jobs??Math.max(1,cpus().length),H=[],W=0,q=[];for(let t=0;t<I;t++)q.push((async()=>{for(;;){let t=W++;if(t>=F.length)return;let n=F[t],S=await runCheck(n,n.name);S!==0&&H.push({name:n.name,code:S})}})());if(await Promise.all(q),H.length>0){ge.error(`\ngjsify check: ${H.length} of ${F.length} workspace(s) failed:`);for(let t of H)ge.error(` ✗ ${t.name} (exit ${t.code})`);return process.exit(1)}t.verbose&&ge.log(`\ngjsify check: ${F.length} workspace(s) green.`),process.exit(0)}}});function manifestPath(){let t=process.env.GJSIFY_SHOWCASES_MANIFEST;if(t)return t;let n=En(fileURLToPath(import.meta.url)),S=[wn(n,`..`,`..`,`showcases.json`),wn(n,`..`,`showcases.json`)];return S.find(t=>existsSync(t))??S[0]}function discoverShowcases(){let t=manifestPath();if(!existsSync(t))return[];let n;try{n=JSON.parse(readFileSync(t,`utf-8`))}catch{return[]}if(!Array.isArray(n.showcases))return[];let S=n.showcases.map(t=>({name:t.name,packageName:t.package,category:t.category,description:t.description??``}));return S.sort((t,n)=>t.category.localeCompare(n.category)||t.name.localeCompare(n.name)),S}function findShowcase(t){return discoverShowcases().find(n=>n.name===t)}var MR=__esmMin(()=>{Rd(),Pn(),Gn()});function parseSpec(t){if(!t)throw Error(`dlx: empty package spec`);if(t.startsWith(`./`)||t.startsWith(`../`)||Cn(t)||existsSync(t))return{kind:`local`,path:xn(t)};let n=t,S,C=t.lastIndexOf(`@`);if(C>0&&(n=t.slice(0,C),S=t.slice(C+1)),!NR.test(n))throw Error(`dlx: invalid package name "${n}"`);return{kind:`registry`,name:n,version:S,spec:t}}var NR,PR=__esmMin(()=>{Rd(),Pn(),NR=/^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/});function resolveGjsEntry(t,n){let S=wn(t,`package.json`);if(!existsSync(S))throw Error(`dlx: no package.json found at ${t}`);let C=JSON.parse(readFileSync(S,`utf-8`)),N=C.gjsify?.bin,F=C.gjsify?.main,I=C.main,H,W=null,q=!1;if(n!==null){if(!N||!N[n]){let S=N?Object.keys(N).join(`, `):`(none)`;throw Error(`dlx: package "${C.name??t}" has no GJS bin named "${n}" — known: ${S}`)}H=N[n],W=n}else if(N&&Object.keys(N).length===1){let t=Object.keys(N)[0];H=N[t],W=t}else F?H=F:I&&(H=I,q=!0);if(N&&Object.keys(N).length>1&&n===null){let n=Object.keys(N).join(`, `);throw Error(`dlx: package "${C.name??t}" defines multiple GJS bins — pass one of: ${n}`)}if(!H)throw Error(`dlx: package "${C.name??t}" has no GJS entry — set \`gjsify.main\` (or \`gjsify.bin\`) in its package.json`);let Y=xn(t,H);if(!existsSync(Y))throw Error(`dlx: GJS entry not found: ${Y}`);return{bundlePath:Y,binName:W,fromFallback:q}}function resolveNodeEntry(t){let n=wn(t,`package.json`);if(!existsSync(n))throw Error(`no package.json found at ${t}`);let S=JSON.parse(readFileSync(n,`utf-8`)),C=S.gjsify?.example?.node;if(C){let n=xn(t,C);if(!existsSync(n))throw Error(`declared node entry not found: ${n} (gjsify.example.node)`);return n}let N=S.gjsify?.main??(S.gjsify?.bin?Object.values(S.gjsify.bin)[0]:void 0)??S.main;if(!N)throw Error(`package "${S.name??t}" has no entry to derive a node bundle from — set \`gjsify.example.node\` to its \`--app node\` bundle path.`);let F=N.replace(/\.gjs\.(js|mjs|cjs)$/,``).replace(/\.(js|mjs|cjs)$/,``),I=[`${F}.node.mjs`,`${F}.node.js`,`${F}.node.cjs`];for(let n of I){let S=xn(t,n);if(existsSync(S))return S}throw Error(`package "${S.name??t}" has no \`--app node\` bundle — looked for ${I.join(`, `)}.\n Build one (e.g. \`gjsify build src/app.ts --app node --outfile dist/app.node.mjs\`) or set \`gjsify.example.node\` to its path.`)}var FR=__esmMin(()=>{Rd(),Pn()});function lexCompare(t,n){return t<n?-1:+(t>n)}function createCacheKey(t){let n=[...t.packages].sort(lexCompare),S=Object.entries(t.registries??{}).sort(([t],[n])=>lexCompare(t,n)),C=JSON.stringify([n,S]);return createHash(`sha256`).update(C).digest(`hex`)}function dlxCacheRoot(){let t=process.env.XDG_CACHE_HOME,n=wn(t&&t.length>0?t:wn(homedir(),`.cache`),`gjsify`,`dlx`);return mkdirSync(n,{recursive:!0}),n}function cacheDirFor(t){let n=wn(dlxCacheRoot(),t);return mkdirSync(n,{recursive:!0}),n}function makePrepareDir(t){let n=wn(t,`${Date.now().toString(16)}-${process.pid.toString(16)}`);return mkdirSync(n,{recursive:!0}),n}function getValidCachedPkg(t,n=LR){let S=wn(t,`pkg`),C;try{C=lstatSync(S)}catch(t){if(t.code===`ENOENT`)return;throw t}if(!C.isSymbolicLink())return;let N;try{N=realpathSync(S)}catch{return}return Date.now()-C.mtime.getTime()<=n*IR?N:void 0}function symlinkSwap(t,n,S={}){let C=S.junctions??dirLinksAreJunctions(),N=wn(t,`pkg`),F=wn(t,`pkg.tmp-${Date.now().toString(16)}-${process.pid.toString(16)}`);linkDirSync(F,n);try{C&&rmSync(N,{force:!0,recursive:!1,maxRetries:10,retryDelay:100}),renameSync(F,N)}catch(t){let S=t.code;if(S===`EBUSY`||S===`EPERM`||S===`EEXIST`||S===`EACCES`){rmSync(F,{force:!0});try{return realpathSync(N)}catch{return realpathSync(n)}}throw t}return realpathSync(N)}function resolveInstalledPkgDir(t,n){return xn(t,`node_modules`,n)}var IR,LR,RR=__esmMin(()=>{Qc(),Rd(),Lg(),Pn(),zL(),IR=6e4,LR=1440*7});async function ensurePkgDir(t,n){if(t.kind===`local`)return{pkgDir:t.path,cachedPkgName:null};let S=[t.spec,...n.extraSpecs??[]],C=cacheDirFor(createCacheKey({packages:S})),N=n.cacheMaxAge>0?getValidCachedPkg(C,n.cacheMaxAge):void 0;if(N)return{pkgDir:resolveInstalledPkgDir(N,t.name),cachedPkgName:t.name};let F=makePrepareDir(C),I=makeProgressReporter({enabled:!n.verbose});return await installPackages({prefix:F,specs:S,verbose:n.verbose,registry:n.registry,lockfile:!0,frozen:n.frozen,progress:I}),{pkgDir:resolveInstalledPkgDir(symlinkSwap(C,F),t.name),cachedPkgName:t.name}}function splitBinAndArgs(t,n,S){if(!n)return{binName:null,extraArgs:S};let C=wn(t,`package.json`);if(existsSync(C))try{let t=JSON.parse(readFileSync(C,`utf-8`)).gjsify?.bin;if(t&&Object.prototype.hasOwnProperty.call(t,n))return{binName:n,extraArgs:S}}catch{}return{binName:null,extraArgs:[n,...S]}}var zR,BR=__esmMin(()=>{_e(),tL(),PR(),FR(),RI(),RR(),aR(),Rd(),Pn(),zR={command:`dlx <spec> [binOrArg] [extraArgs..]`,description:`Run the GJS bundle of an npm-published package without installing it locally.`,builder:t=>t.parserConfiguration({"populate--":!0,"parse-positional-numbers":!1}).positional(`spec`,{description:"Package spec (`name`, `name@version`, `@scope/name@spec`, or local path).",type:`string`,demandOption:!0}).positional(`binOrArg`,{description:"Optional bin name when the package defines `gjsify.bin` with multiple entries; otherwise treated as the first argument forwarded to the bundle. To pass a flag here (e.g. `--help`) use the `--` separator: `gjsify dlx <pkg> -- --help`.",type:`string`}).positional(`extraArgs`,{description:"Extra args forwarded to `gjs -m <bundle>`. Use `--` before flags to bypass gjsify-level parsing (`gjsify dlx <pkg> -- --help --verbose`).",type:`string`,array:!0}).option(`cache-max-age`,{description:`Cache TTL in minutes. Defaults to 7 days. Use 0 to bypass cache.`,type:`number`,default:1440*7}).option(`reinstall`,{description:`Bypass the cache for this run (alias for --cache-max-age=0).`,type:`boolean`,default:!1}).option(`frozen`,{description:`Use the project-local gjsify-lock.json verbatim — fail if missing or stale (no resolver pass).`,type:`boolean`,default:!1}).option(`verbose`,{description:`Verbose logging (passes --loglevel verbose to npm).`,type:`boolean`,default:!1}).option(`registry`,{description:`Registry URL override.`,type:`string`}),handler:async t=>{let n=parseSpec(t.spec),S=t.reinstall?0:t[`cache-max-age`],{pkgDir:C,cachedPkgName:N}=await ensurePkgDir(n,{verbose:t.verbose,registry:t.registry,cacheMaxAge:S,frozen:t.frozen}),F=[...t.extraArgs??[],...doubleDashArgs(t)],{binName:I,extraArgs:H}=splitBinAndArgs(C,t.binOrArg,F),W=resolveGjsEntry(C,I);W.fromFallback&&ge.warn(`[gjsify dlx] package "${N??n.kind}" declares no \`gjsify.main\` — falling back to package.json#main. Add \`gjsify.main\` to silence.`),await runGjsBundle(W.bundlePath,H,{completion:`exit`,exitOnSuccess:!0})}}});async function loadNpmrc(t){let n=[],S=wn(t,`.npmrc`);existsSync(S)&&n.push(readFileSync(S,`utf-8`));let C=process.env.NPM_CONFIG_USERCONFIG;if(C&&existsSync(C))n.push(readFileSync(C,`utf-8`));else{let t=wn(homedir(),`.npmrc`);existsSync(t)&&n.push(readFileSync(t,`utf-8`))}return parseNpmrc(n.join(`
946
+ `).replace(/\$\{([A-Z_][A-Z0-9_]*)\}/gi,(t,n)=>process.env[n]??``))}function hasAnyAuthToken(t){return Object.keys(t.authTokens).length>0}function hasAnyCredential(t){return hasAnyAuthToken(t)||Object.keys(t.basicAuth).length>0}var VR=__esmMin(()=>{Rd(),Lg(),Pn(),eh()});function readCliVersion(){let t=cliVersion();return t===`unknown`?void 0:t}function runningAs(t){return t?`[gjsify ${t}] `:``}async function resolveShowcaseDir(t,n,S=[]){let C=resolveLocalShowcaseDir(t);if(C)return C;let{pkgDir:N}=await ensurePkgDir(parseSpec(n?`${t.packageName}@${n}`:t.packageName),{verbose:!1,cacheMaxAge:1440*7,frozen:!1,extraSpecs:S});return N}function resolveLocalShowcaseDir(t){try{let n=createRequire(import.meta.url).resolve(`${t.packageName}/package.json`);if(existsSync(n))return En(n)}catch{}return null}function gtkRuntimeSpecs(t){let n=`${process.platform}-${process.arch}`;if(![`win32-x64`,`darwin-arm64`,`darwin-x64`].includes(n))return[];let S=`@gjsify/gtk-runtime-${n}`;return[t?`${S}@${t}`:S]}async function preflightDeclaredRuntimes(t,n){try{return declaredRuntimesFromPackument(await fetchPackument(t.packageName,{npmrc:await loadNpmrc(process.cwd()),fullMetadata:!0}),n)}catch{return}}function declaredRuntimesFromPackument(t,n){let S=n??t[`dist-tags`]?.latest,C=S?t.versions?.[S]:void 0;if(C)return readDeclaredRuntimes(C)}async function runShowcaseOnRuntime(t,n,S){if(resolveLocalShowcaseDir(t)===null){let C=await preflightDeclaredRuntimes(t,S);if(C!==void 0){let S=checkRuntimeSupported(n,C,t.name);if(!S.ok)return ge.error(S.message),process.exit(1)}}let C;try{C=await resolveShowcaseDir(t,S,[S?`@gjsify/node-gi@${S}`:`@gjsify/node-gi`,...gtkRuntimeSpecs(S)])}catch(n){return ge.error(`Could not resolve showcase "${t.name}": ${n.message}`),process.exit(1)}let N={};try{N=JSON.parse(readFileSync(`${C}/package.json`,`utf-8`))}catch{}let F=checkRuntimeSupported(n,readDeclaredRuntimes(N),t.name);if(!F.ok)return ge.error(F.message),process.exit(1);let I;try{I=resolveNodeEntry(C)}catch(C){let F=typeof N.name==`string`?`${N.name}@${S??`?`}`:t.packageName;return ge.error(`Cannot run showcase "${t.name}" on ${n}: ${C.message}\n\n ${F} declares --runtime ${n} but ships no \`--app node\` bundle, so that\n version of the showcase cannot run there. You are running gjsify ${S??`(unknown)`},\n and \`showcase\` pins the showcase to the CLI's own version.\n\n ${HR}\n\n Or run it on GJS, which every showcase ships: gjsify showcase ${t.name} --runtime gjs`),process.exit(1)}ge.log(`Running showcase: ${t.name} ${runningAs(S)}on ${n} (${I})\n`);try{await runRuntimeBundle(n,I,[],{completion:`exit`,exitOnSuccess:!0})}catch(t){return ge.error(`${t.message}\n\n The showcase and the \`@gjsify/node-gi\` bridge it needs are both installed by THIS CLI\n (gjsify ${S??`(unknown)`}) into its own cache, so a missing bridge points at the CLI\n rather than at anything in your project.\n\n ${HR}`),process.exit(1)}}var HR,UR,WR=__esmMin(()=>{_e(),MR(),vF(),Il(),Pn(),Rd(),BR(),eh(),VR(),PR(),nh(),FR(),rL(),W_(),HR=`A package runner reuses a CACHED copy of an unpinned bin. Force the current one:
947
947
  npx @gjsify/cli@latest showcase <name>
948
948
  bunx @gjsify/cli@latest showcase <name>
949
- deno run -A --reload --min-dep-age 0 npm:@gjsify/cli@latest showcase <name>`,RR={command:`showcase [name]`,description:`List or run curated gjsify showcase applications.`,builder:t=>t.positional(`name`,{description:`Showcase name to run (omit to list all)`,type:`string`}).option(`json`,{description:`Output as JSON`,type:`boolean`,default:!1}).option(`list`,{description:`List available showcases`,type:`boolean`,default:!1}).option(`runtime`,{type:`string`,choices:H_,defaultDescription:`gjs when gjs is installed, else the host runtime`,description:"Runtime to run the showcase on: gjs | node | bun | deno (default: gjs when installed, else the host runtime). node/bun/deno run its `--app node` bundle."}),handler:async t=>{if(!t.name||t.list){let n=discoverShowcases();if(t.json){ge.log(JSON.stringify(n,null,2));return}if(n.length===0){ge.log("No showcases found. The CLI ships a curated list in `showcases.json`; if it is missing the CLI install is incomplete.");return}let S=new Map;for(let t of n){let n=S.get(t.category)??[];n.push(t),S.set(t.category,n)}ge.log(`Available gjsify showcases:
949
+ deno run -A --reload --min-dep-age 0 npm:@gjsify/cli@latest showcase <name>`,UR={command:`showcase [name]`,description:`List or run curated gjsify showcase applications.`,builder:t=>t.positional(`name`,{description:`Showcase name to run (omit to list all)`,type:`string`}).option(`json`,{description:`Output as JSON`,type:`boolean`,default:!1}).option(`list`,{description:`List available showcases`,type:`boolean`,default:!1}).option(`runtime`,{type:`string`,choices:H_,defaultDescription:`gjs when gjs is installed, else the host runtime`,description:"Runtime to run the showcase on: gjs | node | bun | deno (default: gjs when installed, else the host runtime). node/bun/deno run its `--app node` bundle."}),handler:async t=>{if(!t.name||t.list){let n=discoverShowcases();if(t.json){ge.log(JSON.stringify(n,null,2));return}if(n.length===0){ge.log("No showcases found. The CLI ships a curated list in `showcases.json`; if it is missing the CLI install is incomplete.");return}let S=new Map;for(let t of n){let n=S.get(t.category)??[];n.push(t),S.set(t.category,n)}ge.log(`Available gjsify showcases:
950
950
  `);for(let[t,n]of S){ge.log(` ${t.toUpperCase()}:`);let S=Math.max(...n.map(t=>t.name.length));for(let t of n){let n=` `.repeat(S-t.name.length+2),C=t.description?`${n}${t.description}`:``;ge.log(` ${t.name}${C}`)}ge.log(``)}ge.log(`Run a showcase: gjsify showcase <name>`);return}let n=findShowcase(t.name);if(!n)return ge.error(`Unknown showcase: "${t.name}"`),ge.error(`Run "gjsify showcase" to list available showcases.`),process.exit(1);let S=t.runtime??defaultExampleRuntime();if(!isExampleRuntime(S))return ge.error(`Unknown --runtime "${S}" (expected: ${H_.join(`, `)}).`),process.exit(1);if(requiresGjsSystemDeps(S)){let t=runMinimalChecks().filter(t=>!t.found&&t.severity===`required`);if(t.length>0){ge.error(`Missing system dependencies:
951
- `);for(let n of t)ge.error(` ✗ ${n.name}`);let n=buildInstallCommand(detectPackageManager$1(),t);return n&&ge.error(`\nInstall with:\n ${n}`),process.exit(1)}}let C=readCliVersion();if(S!==`gjs`){await runShowcaseOnRuntime(n,S,C);return}let N=C?`${n.packageName}@${C}`:n.packageName;ge.log(`Running showcase: ${n.name} ${runningAs(C)}(via gjsify dlx ${N})\n`);try{let{runCli:t}=await Promise.resolve().then(()=>(IK(),FK));await t([`dlx`,N])}catch(t){ge.error(t.message),process.exit(1)}}}});function resolveTemplatesRoot(){let t=En(fileURLToPath(import.meta.url)),n=[wn(t,`..`,`dist-templates`),wn(t,`dist-templates`)];try{let t=createRequire(import.meta.url).resolve(`@gjsify/create-app/package.json`);n.splice(1,0,wn(En(t),`dist-templates`))}catch{}return n.find(t=>existsSync(t))}function discoverTemplates(){let t=resolveTemplatesRoot();if(!t)return[];let n=[];for(let S of readdirSync(t)){let C=wn(t,S),N=wn(C,`package.json`);if(!statSync(C).isDirectory()||!existsSync(N))continue;let F=BR[S]??``;try{let t=JSON.parse(readFileSync(N,`utf-8`));typeof t.description==`string`&&t.description.trim()&&(F=t.description)}catch{}n.push({name:S,description:F,path:C})}return n.sort((t,n)=>t.name.localeCompare(n.name)),n}function findTemplate(t){return discoverTemplates().find(n=>n.name===t)}var BR,VR=__esmMin(()=>{Rd(),Il(),Pn(),Gn(),BR={"gtk-minimal":`Minimal GTK4 app — Gtk.ApplicationWindow + Gtk.Label, no Adwaita (Blueprint UI).`,cli:`Command-line tool using yargs (Node.js + GJS).`,"adw-canvas2d":`Adwaita app with HTML Canvas 2D rendering (Blueprint UI).`,"adw-webgl":`Adwaita app with WebGL + three.js (Blueprint UI).`,"adw-game":`Adwaita game shell using Excalibur.js, WebGL → Canvas2D fallback.`,"web-server-hono":`HTTP server using Hono (Web-standard fetch-style API).`,"web-server-express":`HTTP server using Express (familiar Node.js stack).`}});function installCommandLine(t){return[t,...UR[t]].join(` `)}function runScriptCommand(t){return WR[t]}function packageManagersForRuntime(t){return GR[t]}function hostRuntime(){let t=globalThis;return t.Bun===void 0?t.Deno===void 0?t.imports?.gi===void 0?`node`:`gjs`:`deno`:`bun`}function defaultRuntimeFor(t,n){if(n)return t.find(t=>packageManagersForRuntime(t)?.includes(n));let S=hostRuntime();return t.includes(S)?S:t[0]}function startScriptFor(t){return t===`gjs`?`start`:`start:${t}`}var HR,UR,WR,GR,KR,qR=__esmMin(()=>{HR=[`npm`,`yarn`,`pnpm`,`gjsify`,`bun`,`deno`],UR={npm:[`install`,`--no-audit`,`--no-fund`],yarn:[`install`],pnpm:[`install`],gjsify:[`install`],bun:[`install`],deno:[`install`]},WR={npm:`npm run`,yarn:`yarn`,pnpm:`pnpm`,gjsify:`gjsify run`,bun:`bun run`,deno:`deno task`},GR={gjs:[`gjsify`],node:[`npm`,`yarn`,`pnpm`,`gjsify`],bun:[`bun`],deno:[`deno`]},KR={gjs:`GNOME JavaScript — no Node.js needed at runtime.`,node:`Node.js — gi:// via the @gjsify/node-gi bridge.`,bun:`Bun — runs the same --app node bundle.`,deno:`Deno — runs the same --app node bundle.`}});function selectRuntime(t){let{flag:n,offered:S,manager:C,interactive:N}=t;if(n!==void 0)return S.length>0&&!S.includes(n)?{kind:`error`,message:`this template does not run on "${n}". Declared runtimes: ${S.join(`, `)}.`}:{kind:`value`,value:n};if(S.length===1)return{kind:`value`,value:S[0]};if(S.length===0)return{kind:`error`,message:`this template declares no runtime this scaffolder can install for.`};let F=defaultRuntimeFor(S,C);return F===void 0?{kind:`error`,message:`no runtime this template declares installs with "${C}". Declared runtimes: ${S.join(`, `)}.`}:C===void 0?N?{kind:`prompt`,choices:S,initial:F}:{kind:`auto`,value:F,notice:`--runtime not given, using "${F}". Runs on: ${S.join(`, `)}.`}:{kind:`auto`,value:F,notice:`Setting up for ${F} — the runtime ${C} installs for.`}}function selectPackageManager(t){let{flag:n,runtime:S,install:C,interactive:N}=t,F=packageManagersForRuntime(S);return F===void 0||F.length===0?{kind:`error`,message:`no package manager known for runtime "${S}".`}:n===void 0?F.length===1?{kind:`auto`,value:F[0],notice:`Using ${F[0]} — the only package manager that installs for ${S}.`}:N?{kind:`prompt`,choices:F,initial:F[0]}:C?{kind:`error`,message:`--package-manager is required with --install in non-interactive mode. Package managers for ${S}: ${F.join(`, `)}.`}:{kind:`auto`,value:F[0],notice:`--package-manager not given, using "${F[0]}" for ${S}.`}:F.includes(n)?{kind:`value`,value:n}:{kind:`error`,message:`"${n}" cannot install a project you intend to run on ${S}. Package managers for ${S}: ${F.join(`, `)}.`}}var JR=__esmMin(()=>{qR()});function applicationIdFor(t){let n=t.replace(/[^A-Za-z0-9_-]/g,`-`);return`org.gjsify.${/^[0-9]/.test(n)?`app-${n}`:n}`}function sanitizeProjectName(t){let n=t.trim();if(!n)throw Error(`Project name cannot be empty.`);let S=n.toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/^[._-]+/,``).replace(/[._-]+$/,``);if(!S)throw Error(`"${t}" is not a valid npm package name.`);return S}function isDirEmpty(t){return existsSync(t)?readdirSync(t).length===0:!0}async function createProject(t){let n=sanitizeProjectName(t.projectName),{template:S,force:C=!1,install:N=!1}=t,F=findTemplate(S);if(!F){let t=discoverTemplates().map(t=>t.name).join(`, `);throw Error(`Unknown template "${S}". Available templates: ${t||`(none — run "yarn build" first)`}`)}let I=supportedRuntimes(F),H=t.runtime??defaultRuntimeFor(I,t.packageManager)??hostRuntime(),W=packageManagersForRuntime(H);if(!W)throw Error(`Template "${F.name}" was asked for runtime "${H}", which this version of @gjsify/create-app has no installer mapping for. Upgrade it, or pick one of: ${I.join(`, `)||`(none)`}.`);let q=t.packageManager??W[0];if(!W.includes(q))throw Error(`"${q}" cannot install a project you intend to run on ${H}. Package managers for ${H}: ${W.join(`, `)}.`);let Y=xn(process.cwd(),n);if(existsSync(Y)&&!isDirEmpty(Y)&&!C)return ge.error(`Error: Directory "${n}" exists and is not empty. Use --force to scaffold into it anyway.`),process.exit(1);if(ge.log(`Creating new Gjsify project in ${Y} (template: ${F.name})...`),mkdirSync(Y,{recursive:!0}),cpSync(F.path,Y,{recursive:!0}),substituteTemplateSentinels(Y,n),N){let t=installCommandLine(q);ge.log(`Running ${t}...`);let n=spawnSync(t,{cwd:Y,stdio:`inherit`,shell:!0});n.error?ge.warn(`${q} install could not start (${n.error.message}); re-run it manually.`):n.status!==0&&ge.warn(`${q} install failed; re-run it manually in the project directory.`)}printNextSteps(n,F,N,q,H)}function substituteTemplateSentinels(t,n){let S=[[YR,n],[XR,applicationIdFor(n)]],C=new Set([`node_modules`,`dist`,`lib`]),N=[t];for(;N.length>0;){let t=N.pop();for(let n of readdirSync(t,{withFileTypes:!0})){let F=wn(t,n.name);if(n.isDirectory()){C.has(n.name)||N.push(F);continue}if(!n.isFile())continue;let I=n.name.lastIndexOf(`.`),H=I>=0?n.name.slice(I):``;if(!ZR.has(H))continue;let W=readFileSync(F,`utf-8`),q=W;for(let[t,n]of S)q=q.replaceAll(t,n);q!==W&&writeFileSync(F,q)}}}function printNextSteps(t,n,S,C,N){let F=runScriptCommand(C),I=templateScripts(n),H=startScriptFor(N);ge.log(``),ge.log(`Project created from template "${n.name}", set up for ${N}.`),ge.log(``),ge.log(`Next steps:`),ge.log(` cd ${t}`),S||ge.log(` ${C} install`),N===`gjs`&&I.dev?ge.log(` ${F} dev`):(ge.log(` ${F} build`),ge.log(` ${F} ${H}`)),ge.log(``);let W=supportedRuntimes(n).filter(t=>t!==N&&I[startScriptFor(t)]);if(W.length>0){ge.log(`Also runs on ${W.join(`, `)}:`);for(let t of W)ge.log(` ${F} ${startScriptFor(t)}`);ge.log(``)}}function templateManifest(t){try{return JSON.parse(readFileSync(wn(t.path,`package.json`),`utf-8`))}catch{return{}}}function templateScripts(t){let n=templateManifest(t).scripts;return n?Object.fromEntries(Object.entries(n).filter(t=>typeof t[1]==`string`)):{}}function supportedRuntimes(t){let n=templateManifest(t).gjsify?.example?.runtimes;return Array.isArray(n)?n.filter(t=>typeof t==`string`&&packageManagersForRuntime(t)!==void 0):[]}var YR,XR,ZR,QR=__esmMin(()=>{_e(),P_(),Rd(),Pn(),VR(),qR(),JR(),YR=`new-gjsify-app`,XR=`org.gjsify.example`,ZR=new Set([`.json`,`.md`,`.ts`,`.tsx`,`.js`,`.mjs`,`.cjs`,`.blp`,`.html`,`.css`,`.scss`,`.xml`,`.ui`,`.txt`])});function isCancelled(t){return t instanceof Error&&t.message===ez}function render(t,n,S){S||an.write(`\x1b[${t.length}A`);for(let S=0;S<t.length;S++){let C=t[S],N=S===n?`${$R.cyan}❯${$R.reset}`:` `,F=S===n?`${$R.bold}${$R.green}${C.label}${$R.reset}`:C.label,I=C.description?` ${$R.dim}${C.description}${$R.reset}`:``;an.write(`\x1b[2K\r ${N} ${F}${I}\n`)}}function promptChoice(t,n,S=0){return n.length===0?Promise.reject(Error(`Nothing to choose for "${t}".`)):new Promise((C,N)=>{let F=S>=0&&S<n.length?S:0;an.write(`${$R.bold}${t}${$R.reset} ${$R.dim}(↑/↓ to navigate, Enter to confirm, Ctrl+C to cancel)${$R.reset}\n`),render(n,F,!0),emitKeypressEvents(on),on.isTTY&&on.setRawMode(!0),on.resume();let cleanup=()=>{on.removeListener(`keypress`,onKeypress),on.isTTY&&on.setRawMode(!1),on.pause()},onKeypress=(t,S)=>{if(S){if(S.ctrl&&S.name===`c`){cleanup(),an.write(`
952
- `),N(Error(ez));return}S.name===`up`||S.name===`k`?(F=(F-1+n.length)%n.length,render(n,F,!1)):S.name===`down`||S.name===`j`?(F=(F+1)%n.length,render(n,F,!1)):(S.name===`return`||S.name===`enter`)&&(cleanup(),C(n[F].value))}};on.on(`keypress`,onKeypress)})}function promptTemplate(t){return t.length===0?Promise.reject(Error(`No templates available.`)):promptChoice(`Select a template`,t.map(t=>({value:t,label:t.name,description:t.description})))}function promptRuntime(t,n){return promptChoice(`Select a runtime`,t.map(t=>({value:t,label:t,description:KR[t]??``})),t.indexOf(n))}function promptPackageManager(t,n){return promptChoice(`Select a package manager`,t.map(t=>({value:t,label:t,description:``})),t.indexOf(n))}async function settle(t,n){switch(t.kind){case`value`:return t.value;case`auto`:return ge.error(t.notice),t.value;case`prompt`:try{return await n(t.choices,t.initial)}catch(t){if(!isCancelled(t))throw t;ge.error(`Cancelled.`);return}case`error`:ge.error(`Error: ${t.message}`);return}}async function promptSetup(t){let{offered:n,install:S,interactive:C}=t,N=await settle(selectRuntime({flag:t.runtime,offered:n,manager:t.packageManager,interactive:C}),(t,n)=>promptRuntime(t,n));if(N===void 0)return;let F=await settle(selectPackageManager({flag:t.packageManager,runtime:N,install:S,interactive:C}),(t,n)=>promptPackageManager(t,n));if(F!==void 0)return{runtime:N,packageManager:F}}var $R,ez,tz=__esmMin(()=>{_e(),sn(),Ad(),qR(),JR(),$R={reset:`\x1B[0m`,bold:`\x1B[1m`,dim:`\x1B[2m`,cyan:`\x1B[36m`,green:`\x1B[32m`},ez=`Cancelled by user`}),nz,rz=__esmMin(()=>{_e(),QR(),tz(),nz={command:`create [project-name]`,description:`Scaffold a new Gjsify project in a new directory.`,builder:t=>{let n=discoverTemplates(),S=n.map(t=>t.name),C=[...new Set(n.flatMap(t=>supportedRuntimes(t)))];return t.positional(`project-name`,{describe:`Name of the project directory to create`,type:`string`,default:`my-gjs-app`}).option(`template`,{alias:`t`,describe:`Template to scaffold from`,type:`string`,choices:S.length>0?S:void 0}).option(`runtime`,{alias:`r`,describe:`Runtime to set the project up for. Decides which package managers are offered and which start script the next steps name.`,type:`string`,choices:C.length>0?C:void 0}).option(`force`,{alias:`f`,describe:`Scaffold into a non-empty directory`,type:`boolean`,default:!1}).option(`install`,{describe:`Install dependencies after scaffolding`,type:`boolean`,default:!1}).option(`package-manager`,{alias:`p`,describe:"Package manager to install with, and to name in the printed next steps. Must be one the chosen runtime can install for. `gjsify` is the only one that works on a host with no Node.js.",type:`string`,choices:HR})},handler:async t=>{let n=!!process.stdin.isTTY,S=discoverTemplates(),C=t.template;if(!C){if(!n){let t=S.map(t=>t.name).join(`, `);return ge.error(`Error: --template is required in non-interactive mode. Available templates: ${t||`(none)`}`),process.exit(1)}let t=await promptTemplate(S).catch(t=>{if(!isCancelled(t))throw t;ge.error(`Cancelled.`)});if(t===void 0)return process.exit(1);C=t.name}let N=S.find(t=>t.name===C),F=await promptSetup({offered:N?supportedRuntimes(N):[],runtime:t.runtime,packageManager:t[`package-manager`],install:t.install,interactive:n});if(F===void 0)return process.exit(1);await createProject({projectName:t[`project-name`],template:C,runtime:F.runtime,force:t.force,install:t.install,packageManager:F.packageManager})}}});function defaultTargetFor(t){let n=Dn(t,On(t));return xn(En(t),n)}var iz,az,oz=__esmMin(()=>{_e(),P_(),xd(),Pn(),Tu(),iz=promisify(execFile),az={command:`gresource <xml>`,description:"Compile a GResource XML descriptor into a binary .gresource bundle (wraps `glib-compile-resources`).",builder:t=>t.positional(`xml`,{description:`Path to the .gresource.xml descriptor`,type:`string`,normalize:!0,demandOption:!0}).option(`sourcedir`,{description:`Directory containing the resource files referenced by <xml>`,type:`string`,normalize:!0}).option(`target`,{alias:`t`,description:`Output .gresource file (default: <xml-without-.xml> next to <xml>)`,type:`string`,normalize:!0}).option(`verbose`,{description:`Print the underlying glib-compile-resources invocation`,type:`boolean`,default:!1}),handler:async t=>{let n=xn(t.xml),S=t.target?xn(t.target):defaultTargetFor(n),C=[`--sourcedir=${t.sourcedir?xn(t.sourcedir):En(n)}`,`--target=${S}`,n];t.verbose&&ge.log(`[gjsify gresource] glib-compile-resources ${C.join(` `)}`),await mkdir$1(En(S),{recursive:!0});try{let{stdout:n,stderr:N}=await iz(`glib-compile-resources`,C);n&&process.stdout.write(n),N&&process.stderr.write(N),t.verbose&&ge.log(`[gjsify gresource] wrote ${S}`)}catch(t){let n=t;n?.code===`ENOENT`?ge.error(`[gjsify gresource] glib-compile-resources not found. Install it via your distro (package: glib2-devel / libglib2.0-dev).`):(n?.stderr&&process.stderr.write(n.stderr),ge.error(`[gjsify gresource] glib-compile-resources failed${n?.code===void 0?``:` (exit ${n.code})`}`)),process.exitCode=typeof n?.code==`number`?n.code:1}}}});function mergeCatalogues(t){let n=t.template,S=new Set;for(let{locale:n}of t.catalogues){if(S.has(n))throw Error(`mergeCatalogues: two catalogues both claim locale "${n}". msgfmt APPENDS each --locale, so the chain would emit a duplicate key (desktop-file-validate: "multiple keys named Name[${n}]"; appstreamcli: "tag-duplicated") from two exit-0 calls. Merge them into one .po first (msgcat --use-first) and pass that.`);S.add(n)}for(let[S,C]of t.catalogues.entries()){let N=wn(t.workDir,`${S}${t.extension}`),F=[t.mode,`--template=${n}`,`--locale=${C.locale}`,`--output-file=${N}`,C.po];t.onCall?.(F),execFileSync(`msgfmt`,F,{stdio:`pipe`}),n=N}return n}var sz=__esmMin(()=>{P_(),Pn()});async function listLanguages(t){return(await readdir$1(t)).filter(t=>t.endsWith(`.po`)&&!t.startsWith(`.`)).map(t=>t.slice(0,-3)).sort()}function stripXmlComments(t){return t.replace(/<!--[\s\S]*?-->/g,``)}async function ensureDir(t){await mkdir$1(t,{recursive:!0})}async function fileExists(t){try{return await stat$1(t),!0}catch{return!1}}async function compileMerged(t){let n=await listLanguages(t.poDir);if(n.length===0){ge.warn(`[gjsify gettext] no .po files found in ${t.poDir}`);return}let S=wn(t.outDir,t.filename);await ensureDir(t.outDir);let C=await mkdtemp$1(wn(tmpdir(),`gjsify-gettext-`));try{let N=await readFile$1(mergeCatalogues({mode:`--${t.format}`,template:t.template,extension:`-${Dn(t.template).replace(/\.in$/,``)}`,catalogues:n.map(n=>({locale:n,po:wn(t.poDir,`${n}.po`)})),workDir:C,onCall:t.verbose?t=>ge.log(`[gjsify gettext] msgfmt ${t.join(` `)}`):void 0}),`utf-8`);await writeFile$1(S,t.removeXmlComments&&t.format===`xml`?stripXmlComments(N):N)}finally{await rm$1(C,{recursive:!0,force:!0})}t.verbose&&ge.log(`[gjsify gettext] merged ${n.length} language(s) into ${S}`)}async function compileCatalogues(t){let n=await listLanguages(t.poDir);if(n.length===0){ge.warn(`[gjsify gettext] no .po files found in ${t.poDir}`);return}for(let S of n){let n=wn(t.outDir,S,`LC_MESSAGES`);await ensureDir(n);let C=[`--output-file=${wn(n,t.filename)}`,wn(t.poDir,`${S}.po`)];t.verbose&&ge.log(`[gjsify gettext] msgfmt ${C.join(` `)}`),await cz(`msgfmt`,C)}t.verbose&&ge.log(`[gjsify gettext] compiled ${n.length} language(s) into ${t.outDir}`)}function defaultFilename(t,n,S){switch(n){case`mo`:return`${t}.mo`;case`desktop`:return`${t}.desktop`;case`xml`:return S?Dn(S.replace(/\.in$/,``)):`${t}.xml`}}var cz,lz,uz=__esmMin(()=>{_e(),P_(),xd(),Lg(),Pn(),Tu(),sz(),cz=promisify(execFile),lz={command:`gettext <poDir> <outDir>`,description:`Compile gettext .po files to .mo (per-language locale tree), or merge every catalogue into a .desktop / AppStream template via msgfmt --desktop / --xml.`,builder:t=>t.positional(`poDir`,{description:`Directory containing <lang>.po files`,type:`string`,normalize:!0,demandOption:!0}).positional(`outDir`,{description:`Output directory (locale tree for --format=mo, plain dir for xml/desktop)`,type:`string`,normalize:!0,demandOption:!0}).option(`domain`,{description:"Text domain / application ID (e.g. `org.pixelrpg.maker`)",type:`string`,normalize:!0,demandOption:!0}).option(`format`,{description:`Output format`,type:`string`,choices:[`mo`,`xml`,`desktop`],default:`mo`}).option(`template`,{description:"Required for --format=xml|desktop: the file msgfmt substitutes into. Its SUFFIX matters — msgfmt --xml finds its ITS rules by filename pattern, so an AppStream template must be named `*.metainfo.xml[.in]`.",type:`string`,normalize:!0}).option(`metainfo`,{description:`Deprecated alias for --template.`,type:`string`,normalize:!0,hidden:!0}).option(`filename`,{description:`Override the output filename (defaults to <domain>.<ext>)`,type:`string`,normalize:!0}).option(`remove-xml-comments`,{description:`For --format=xml: strip XML comments from the compiled output`,type:`boolean`,default:!0}).option(`verbose`,{description:`Print each msgfmt invocation`,type:`boolean`,default:!1}),handler:async t=>{let n=xn(t.poDir),S=xn(t.outDir),C=t.domain,N=t.format??`mo`,F=t.template??t.metainfo,I=F?xn(F):void 0,H=t.filename??defaultFilename(C,N,I),W=!!t.verbose,q=!!t[`remove-xml-comments`];if(!await fileExists(n)){ge.error(`[gjsify gettext] PO directory does not exist: ${n}`),process.exitCode=1;return}if(N!==`mo`&&I===void 0){ge.error(`[gjsify gettext] --format=${N} needs a template to substitute into: pass \`--template <file>\`. msgfmt has no way to produce this format from .po files alone.`+(N===`xml`?" Name it `*.metainfo.xml[.in]` — msgfmt --xml finds its ITS rules by filename pattern.":``)),process.exitCode=1;return}try{N===`mo`?await compileCatalogues({poDir:n,outDir:S,filename:H,verbose:W}):await compileMerged({poDir:n,outDir:S,format:N,template:I,filename:H,removeXmlComments:q,verbose:W})}catch(t){let n=t;n?.code===`ENOENT`?ge.error(`[gjsify gettext] msgfmt not found. Install it via your distro (package: gettext).`):(n?.stderr&&process.stderr.write(n.stderr),ge.error(`[gjsify gettext] msgfmt failed${n?.code===void 0?``:` (exit ${n.code})`}`)),process.exitCode=typeof n?.code==`number`?n.code:1}}}}),dz,fz,pz=__esmMin(()=>{_e(),P_(),xd(),Pn(),Tu(),dz=promisify(execFile),fz={command:`gsettings <schemadir>`,description:"Compile GSettings schema XML files into a binary gschemas.compiled (wraps `glib-compile-schemas`).",builder:t=>t.positional(`schemadir`,{description:`Directory containing *.gschema.xml descriptors`,type:`string`,normalize:!0,demandOption:!0}).option(`targetdir`,{alias:`t`,description:`Directory to write gschemas.compiled (default: <schemadir>)`,type:`string`,normalize:!0}).option(`strict`,{description:`Abort on any schema warning (passes --strict to glib-compile-schemas)`,type:`boolean`,default:!0}).option(`verbose`,{description:`Print the underlying glib-compile-schemas invocation`,type:`boolean`,default:!1}),handler:async t=>{let n=xn(t.schemadir),S=t.targetdir?xn(t.targetdir):n,C=[];t.strict&&C.push(`--strict`),C.push(`--targetdir=${S}`),C.push(n),t.verbose&&ge.log(`[gjsify gsettings] glib-compile-schemas ${C.join(` `)}`),await mkdir$1(S,{recursive:!0});try{let{stdout:n,stderr:N}=await dz(`glib-compile-schemas`,C);n&&process.stdout.write(n),N&&process.stderr.write(N),t.verbose&&ge.log(`[gjsify gsettings] wrote ${S}/gschemas.compiled`)}catch(t){let n=t;n?.code===`ENOENT`?ge.error(`[gjsify gsettings] glib-compile-schemas not found. Install it via your distro (package: glib2-devel / libglib2.0-dev).`):(n?.stderr&&process.stderr.write(n.stderr),ge.error(`[gjsify gsettings] glib-compile-schemas failed${n?.code===void 0?``:` (exit ${n.code})`}`)),process.exitCode=typeof n?.code==`number`?n.code:1}}}});function readPackageJson(t){let n=xn(t,`package.json`),S;try{S=readFileSync(n,`utf-8`)}catch{throw Error(`gjsify flatpak: no package.json found at ${n}`)}try{return JSON.parse(S)}catch(t){throw Error(`gjsify flatpak: package.json at ${n} is not valid JSON: ${t.message}`)}}function looksLikeAppId(t){return typeof t==`string`&&/^[A-Za-z][A-Za-z0-9_-]*(\.[A-Za-z][A-Za-z0-9_-]*){2,}$/.test(t)}function defaultCiContainer(t,n){return`ghcr.io/flathub-infra/flatpak-github-actions:${`${t}-${n}`}`}var mz,hz=__esmMin(()=>{Rd(),Pn(),mz=`gjsify-sources.json`});function resolveRuntime(t,n){let S=n.runtime??t?.runtime??`gnome`;if(S!==`gnome`&&S!==`freedesktop`)throw Error(`gjsify flatpak: unknown runtime "${S}" (expected "gnome" or "freedesktop")`);let C=n.runtimeVersion??t?.runtimeVersion??(S===`gnome`?`50`:`24.08`);return S===`gnome`?{runtime:S,runtimeId:`org.gnome.Platform`,sdk:`org.gnome.Sdk`,runtimeVersion:C}:{runtime:S,runtimeId:`org.freedesktop.Platform`,sdk:`org.freedesktop.Sdk`,runtimeVersion:C}}function deriveAppendPath(t){let n=[];for(let S of t){let t=/^org\.freedesktop\.Sdk\.Extension\.([A-Za-z0-9-]+)$/.exec(S);t&&n.push(`/usr/lib/sdk/${t[1]}/bin`)}return n.push(`/app/bin`),n}var gz,_z,vz=__esmMin(()=>{gz=[`--device=dri`,`--share=ipc`,`--socket=fallback-x11`,`--socket=wayland`],_z=[]});function pickFlatpakBuildKeys(t,n){let S=t??{},C={},N=[];for(let t of bz){let F=S[t];if(F!==void 0){C[t]=F;continue}let I=n[t];I!==void 0&&N.push(t),C[t]=I}return{values:C,fromLegacy:N}}function resolveShipFlatpakSettings(t){let n=t.ship.flatpak??{},{values:S,fromLegacy:C}=pickFlatpakBuildKeys(n,t.flatpak),N=resolveRuntime(S,{}),F=S.sdkExtensions??[],{appendPath:I,finishArgs:H,cleanup:W}=S;return{settings:{runtime:N.runtimeId,runtimeVersion:N.runtimeVersion,sdk:N.sdk,branch:n.branch??`stable`,sdkExtensions:[...F],appendPath:I??(F.length>0?deriveAppendPath(F):[]),finishArgs:H??(t.kind===`cli`?_z:gz),cleanup:[...new Set([...W??[],...t.kind===`app`?[xz]:[]])]},warnings:C.length===0?[]:[deprecationWarning(C)]}}function assertNoDroppedFlatpakModules(t){let n=[`modules`,`extraModules`].filter(n=>(t[n]?.length??0)>0);if(n.length===0)return;let S=n.map(t=>`gjsify.flatpak.${t}`).join(` and `);throw Error(`gjsify ship: ${S} ${n.length>1?`are`:`is`} set, but the \`flatpak\` target renders ONE module, the staged payload, and would drop ${n.length>1?`them`:`it`} (ADR 0024 § 2). Build this Flatpak with \`gjsify flatpak init\` + \`gjsify flatpak build\`, which honour the key, or leave \`flatpak\` out of \`--target\` / \`gjsify.ship.targets\`.`)}function deprecationWarning(t){let n=t.map(t=>`gjsify.flatpak.${t}`).join(`, `),S=t.map(t=>`gjsify.ship.flatpak.${t}`).join(`, `);return`DEPRECATION: ${n} ${t.length>1?`are`:`is`} read by \`gjsify ship\` for compatibility and will be removed in ${yz}. Move ${t.length>1?`them`:`it`} to ${S} — both spellings resolve until then, and \`gjsify.ship.flatpak\` wins where both are set. The app METADATA in \`gjsify.flatpak\` (name, summary, developer, categories, licence) is NOT deprecated: both blocks describe the same application and either may carry it (ADR 0024 § 8).`}var yz,bz,xz,Sz=__esmMin(()=>{vz(),yz=`1.0.0`,bz=[`runtime`,`runtimeVersion`,`sdkExtensions`,`appendPath`,`finishArgs`,`cleanup`],xz=`/share/icons/hicolor/scalable`});function loadDesktopTemplate(){return Cz}function validateAppMetadata(t){let n=t.metadata,S=t.configKey,C=[];return(!n.developer?.id||!n.developer?.name)&&C.push({field:`${S}.developer`,hint:`Set \`${S}.developer = { "id": "io.github.you", "name": "Your Name" }\` in package.json. The id is reverse-DNS.`}),n.summary||C.push({field:`${S}.summary`,hint:`One-line app summary, ≤80 chars, no trailing period. Example: "Learn 6502 assembly language".`}),n.description||C.push({field:`${S}.description`,hint:`Plain text (split on blank lines) or DescriptionBlock[] for rich content with bullet lists + translator hints.`}),n.license?.project||C.push({field:`${S}.license.project`,hint:`SPDX identifier of the project license, e.g. "MIT", "GPL-3.0-or-later".`}),n.homepageUrl||C.push({field:`${S}.homepageUrl`,hint:`Required by Flathub. Example: "https://github.com/you/your-repo".`}),C}function renderMetainfoApp$1(t){return renderMetainfo(t,`desktop-application`)}function renderMetainfoCli$1(t){return renderMetainfo(t,`console-application`)}function renderDesktopEntry(t){let n=t.metadata,S=(n.categories??[`Utility`]).join(`;`)+`;`,C=n.keywords?.length?`Keywords=${n.keywords.join(`;`)};\n`:``,N=n.provides?.mimetypes??[],F=N.length?`MimeType=${N.join(`;`)};\n`:``;return substitute(loadDesktopTemplate(),{NAME:t.name,SUMMARY:n.summary??t.name,COMMAND:`${t.command}${execFieldCode(N)}`,APP_ID:t.appId,CATEGORIES_LINE:S,KEYWORDS_LINE:C,MIMETYPES_LINE:F})}function execFieldCode(t){return t.some(t=>t.startsWith(`x-scheme-handler/`))?` %u`:t.length>0?` %f`:``}function renderMetainfo(t,n){let S=t.metadata,C=t.copyrightYear??new Date().getFullYear(),N=S.developer?.name??``,F=[];F.push(`<?xml version="1.0" encoding="UTF-8"?>`),F.push(`<!-- Copyright ${C} ${escapeXml(N)} -->`),F.push(`<component type="${n}">`),F.push(` <id>${escapeXml(t.appId)}</id>`),F.push(` <metadata_license>${escapeXml(S.license?.metadata??`CC0-1.0`)}</metadata_license>`),F.push(` <project_license>${escapeXml(S.license?.project??``)}</project_license>`),F.push(` <name>${escapeXml(t.name)}</name>`),pushTranslatorHint(F,S.summaryTranslatorHint,` `),F.push(` <summary>${escapeXml(S.summary??t.name)}</summary>`),S.iconRemote&&F.push(` <icon type="remote">${escapeXml(S.iconRemote)}</icon>`),F.push(` <description>`);for(let t of renderDescriptionBlocks(S.description??``,` `))F.push(t);if(F.push(` </description>`),S.developer?.id&&S.developer?.name){F.push(` <developer id="${escapeXml(S.developer.id)}">`);let t=S.developer.nameTranslatable===!0?``:` translate="no"`;F.push(` <name${t}>${escapeXml(S.developer.name)}</name>`),S.developer.email&&F.push(` <email>${escapeXml(S.developer.email)}</email>`),F.push(` </developer>`)}n===`desktop-application`&&F.push(` <launchable type="desktop-id">${escapeXml(t.appId)}.desktop</launchable>`),S.screenshots?.length&&(F.push(` <screenshots>`),S.screenshots.forEach((t,n)=>{let S=t.type??(n===0?`default`:void 0),C=S?` type="${escapeXml(S)}"`:``,N=t.environment?` environment="${escapeXml(t.environment)}"`:``;F.push(` <screenshot${C}${N}>`),F.push(` <image>${escapeXml(t.url)}</image>`);for(let[n,S]of Object.entries(t.localizedUrls??{}))F.push(` <image xml:lang="${escapeXml(n)}">${escapeXml(S)}</image>`);t.caption&&(pushTranslatorHint(F,t.captionTranslatorHint,` `),F.push(` <caption>${escapeXml(t.caption)}</caption>`)),F.push(` </screenshot>`)}),F.push(` </screenshots>`)),S.homepageUrl&&F.push(` <url type="homepage">${escapeXml(S.homepageUrl)}</url>`),S.bugtrackerUrl&&F.push(` <url type="bugtracker">${escapeXml(S.bugtrackerUrl)}</url>`),S.vcsBrowserUrl&&F.push(` <url type="vcs-browser">${escapeXml(S.vcsBrowserUrl)}</url>`),S.donationUrl&&channelAllowsDonations(t.channel)&&F.push(` <url type="donation">${escapeXml(S.donationUrl)}</url>`),S.translateUrl&&F.push(` <url type="translate">${escapeXml(S.translateUrl)}</url>`);let I=normaliseContentRating(S.contentRating);if(I.attributes&&Object.keys(I.attributes).length>0){F.push(` <content_rating type="${escapeXml(I.type)}">`);for(let[t,n]of Object.entries(I.attributes))F.push(` <content_attribute id="${escapeXml(t)}">${escapeXml(n)}</content_attribute>`);F.push(` </content_rating>`)}else F.push(` <content_rating type="${escapeXml(I.type)}" />`);if(S.releases?.length){F.push(` <releases>`);for(let t of S.releases)if(t.description===void 0)F.push(` <release version="${escapeXml(t.version)}" date="${escapeXml(t.date)}" />`);else{F.push(` <release version="${escapeXml(t.version)}" date="${escapeXml(t.date)}">`),F.push(` <description>`);for(let n of renderDescriptionBlocks(t.description,` `))F.push(n);F.push(` </description>`),F.push(` </release>`)}F.push(` </releases>`)}if(S.categories?.length){F.push(` <categories>`);for(let t of S.categories)F.push(` <category>${escapeXml(t)}</category>`);F.push(` </categories>`)}if(S.keywords?.length){F.push(` <keywords>`);for(let t of S.keywords)F.push(` <keyword>${escapeXml(t)}</keyword>`);F.push(` </keywords>`)}if(n===`desktop-application`&&S.branding&&(F.push(` <branding>`),F.push(` <color type="primary" scheme_preference="light">${escapeXml(S.branding.accentLight)}</color>`),F.push(` <color type="primary" scheme_preference="dark">${escapeXml(S.branding.accentDark)}</color>`),F.push(` </branding>`)),S.kudos?.length){F.push(` <kudos>`);for(let t of S.kudos)F.push(` <kudo>${escapeXml(t)}</kudo>`);F.push(` </kudos>`)}let H=S.provides?.binaries??[t.command],W=S.provides?.mimetypes??[],q=S.provides?.dbus??[];if(H.length||W.length||q.length){F.push(` <provides>`);for(let t of H)F.push(` <binary>${escapeXml(t)}</binary>`);for(let t of W)F.push(` <mediatype>${escapeXml(t)}</mediatype>`);for(let t of q)F.push(` <dbus type="${escapeXml(t.type)}">${escapeXml(t.id)}</dbus>`);F.push(` </provides>`)}if(S.supports?.controls?.length||S.supports?.internet){F.push(` <supports>`);for(let t of S.supports.controls??[])F.push(` <control>${escapeXml(t)}</control>`);S.supports.internet&&F.push(` <internet>${escapeXml(S.supports.internet)}</internet>`),F.push(` </supports>`)}if(S.requires?.displayLengthMin||S.requires?.controls?.length||S.requires?.internet){F.push(` <requires>`),S.requires.displayLengthMin&&F.push(` <display_length compare="ge">${S.requires.displayLengthMin}</display_length>`);for(let t of S.requires.controls??[])F.push(` <control>${escapeXml(t)}</control>`);S.requires.internet&&F.push(` <internet>${escapeXml(S.requires.internet)}</internet>`),F.push(` </requires>`)}if(S.recommends?.displayLengthMin||S.recommends?.controls?.length){F.push(` <recommends>`),S.recommends.displayLengthMin&&F.push(` <display_length compare="ge">${S.recommends.displayLengthMin}</display_length>`);for(let t of S.recommends.controls??[])F.push(` <control>${escapeXml(t)}</control>`);F.push(` </recommends>`)}return F.push(`</component>`),F.join(`
951
+ `);for(let n of t)ge.error(` ✗ ${n.name}`);let n=buildInstallCommand(detectPackageManager$1(),t);return n&&ge.error(`\nInstall with:\n ${n}`),process.exit(1)}}let C=readCliVersion();if(S!==`gjs`){await runShowcaseOnRuntime(n,S,C);return}let N=C?`${n.packageName}@${C}`:n.packageName;ge.log(`Running showcase: ${n.name} ${runningAs(C)}(via gjsify dlx ${N})\n`);try{let{runCli:t}=await Promise.resolve().then(()=>(UK(),HK));await t([`dlx`,N])}catch(t){ge.error(t.message),process.exit(1)}}}});function resolveTemplatesRoot(){let t=En(fileURLToPath(import.meta.url)),n=[wn(t,`..`,`dist-templates`),wn(t,`dist-templates`)];try{let t=createRequire(import.meta.url).resolve(`@gjsify/create-app/package.json`);n.splice(1,0,wn(En(t),`dist-templates`))}catch{}return n.find(t=>existsSync(t))}function discoverTemplates(){let t=resolveTemplatesRoot();if(!t)return[];let n=[];for(let S of readdirSync(t)){let C=wn(t,S),N=wn(C,`package.json`);if(!statSync(C).isDirectory()||!existsSync(N))continue;let F=GR[S]??``;try{let t=JSON.parse(readFileSync(N,`utf-8`));typeof t.description==`string`&&t.description.trim()&&(F=t.description)}catch{}n.push({name:S,description:F,path:C})}return n.sort((t,n)=>t.name.localeCompare(n.name)),n}function findTemplate(t){return discoverTemplates().find(n=>n.name===t)}var GR,KR=__esmMin(()=>{Rd(),Il(),Pn(),Gn(),GR={"gtk-minimal":`Minimal GTK4 app — Gtk.ApplicationWindow + Gtk.Label, no Adwaita (Blueprint UI).`,cli:`Command-line tool using yargs (Node.js + GJS).`,"adw-canvas2d":`Adwaita app with HTML Canvas 2D rendering (Blueprint UI).`,"adw-webgl":`Adwaita app with WebGL + three.js (Blueprint UI).`,"adw-game":`Adwaita game shell using Excalibur.js, WebGL → Canvas2D fallback.`,"web-server-hono":`HTTP server using Hono (Web-standard fetch-style API).`,"web-server-express":`HTTP server using Express (familiar Node.js stack).`}});function installCommandLine(t){return[t,...JR[t]].join(` `)}function runScriptCommand(t){return YR[t]}function packageManagersForRuntime(t){return XR[t]}function hostRuntime(){let t=globalThis;return t.Bun===void 0?t.Deno===void 0?t.imports?.gi===void 0?`node`:`gjs`:`deno`:`bun`}function defaultRuntimeFor(t,n){if(n)return t.find(t=>packageManagersForRuntime(t)?.includes(n));let S=hostRuntime();return t.includes(S)?S:t[0]}function startScriptFor(t){return t===`gjs`?`start`:`start:${t}`}var qR,JR,YR,XR,ZR,QR=__esmMin(()=>{qR=[`npm`,`yarn`,`pnpm`,`gjsify`,`bun`,`deno`],JR={npm:[`install`,`--no-audit`,`--no-fund`],yarn:[`install`],pnpm:[`install`],gjsify:[`install`],bun:[`install`],deno:[`install`]},YR={npm:`npm run`,yarn:`yarn`,pnpm:`pnpm`,gjsify:`gjsify run`,bun:`bun run`,deno:`deno task`},XR={gjs:[`gjsify`],node:[`npm`,`yarn`,`pnpm`,`gjsify`],bun:[`bun`],deno:[`deno`]},ZR={gjs:`GNOME JavaScript — no Node.js needed at runtime.`,node:`Node.js — gi:// via the @gjsify/node-gi bridge.`,bun:`Bun — runs the same --app node bundle.`,deno:`Deno — runs the same --app node bundle.`}});function selectRuntime(t){let{flag:n,offered:S,manager:C,interactive:N}=t;if(n!==void 0)return S.length>0&&!S.includes(n)?{kind:`error`,message:`this template does not run on "${n}". Declared runtimes: ${S.join(`, `)}.`}:{kind:`value`,value:n};if(S.length===1)return{kind:`value`,value:S[0]};if(S.length===0)return{kind:`error`,message:`this template declares no runtime this scaffolder can install for.`};let F=defaultRuntimeFor(S,C);return F===void 0?{kind:`error`,message:`no runtime this template declares installs with "${C}". Declared runtimes: ${S.join(`, `)}.`}:C===void 0?N?{kind:`prompt`,choices:S,initial:F}:{kind:`auto`,value:F,notice:`--runtime not given, using "${F}". Runs on: ${S.join(`, `)}.`}:{kind:`auto`,value:F,notice:`Setting up for ${F} — the runtime ${C} installs for.`}}function selectPackageManager(t){let{flag:n,runtime:S,install:C,interactive:N}=t,F=packageManagersForRuntime(S);return F===void 0||F.length===0?{kind:`error`,message:`no package manager known for runtime "${S}".`}:n===void 0?F.length===1?{kind:`auto`,value:F[0],notice:`Using ${F[0]} — the only package manager that installs for ${S}.`}:N?{kind:`prompt`,choices:F,initial:F[0]}:C?{kind:`error`,message:`--package-manager is required with --install in non-interactive mode. Package managers for ${S}: ${F.join(`, `)}.`}:{kind:`auto`,value:F[0],notice:`--package-manager not given, using "${F[0]}" for ${S}.`}:F.includes(n)?{kind:`value`,value:n}:{kind:`error`,message:`"${n}" cannot install a project you intend to run on ${S}. Package managers for ${S}: ${F.join(`, `)}.`}}var $R=__esmMin(()=>{QR()});function applicationIdFor(t){let n=t.replace(/[^A-Za-z0-9_-]/g,`-`);return`org.gjsify.${/^[0-9]/.test(n)?`app-${n}`:n}`}function sanitizeProjectName(t){let n=t.trim();if(!n)throw Error(`Project name cannot be empty.`);let S=n.toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/^[._-]+/,``).replace(/[._-]+$/,``);if(!S)throw Error(`"${t}" is not a valid npm package name.`);return S}function isDirEmpty(t){return existsSync(t)?readdirSync(t).length===0:!0}async function createProject(t){let n=sanitizeProjectName(t.projectName),{template:S,force:C=!1,install:N=!1}=t,F=findTemplate(S);if(!F){let t=discoverTemplates().map(t=>t.name).join(`, `);throw Error(`Unknown template "${S}". Available templates: ${t||`(none — run "yarn build" first)`}`)}let I=supportedRuntimes(F),H=t.runtime??defaultRuntimeFor(I,t.packageManager)??hostRuntime(),W=packageManagersForRuntime(H);if(!W)throw Error(`Template "${F.name}" was asked for runtime "${H}", which this version of @gjsify/create-app has no installer mapping for. Upgrade it, or pick one of: ${I.join(`, `)||`(none)`}.`);let q=t.packageManager??W[0];if(!W.includes(q))throw Error(`"${q}" cannot install a project you intend to run on ${H}. Package managers for ${H}: ${W.join(`, `)}.`);let Y=xn(process.cwd(),n);if(existsSync(Y)&&!isDirEmpty(Y)&&!C)return ge.error(`Error: Directory "${n}" exists and is not empty. Use --force to scaffold into it anyway.`),process.exit(1);if(ge.log(`Creating new Gjsify project in ${Y} (template: ${F.name})...`),mkdirSync(Y,{recursive:!0}),cpSync(F.path,Y,{recursive:!0}),substituteTemplateSentinels(Y,n),N){let t=installCommandLine(q);ge.log(`Running ${t}...`);let n=spawnSync(t,{cwd:Y,stdio:`inherit`,shell:!0});n.error?ge.warn(`${q} install could not start (${n.error.message}); re-run it manually.`):n.status!==0&&ge.warn(`${q} install failed; re-run it manually in the project directory.`)}printNextSteps(n,F,N,q,H)}function substituteTemplateSentinels(t,n){let S=[[ez,n],[tz,applicationIdFor(n)]],C=new Set([`node_modules`,`dist`,`lib`]),N=[t];for(;N.length>0;){let t=N.pop();for(let n of readdirSync(t,{withFileTypes:!0})){let F=wn(t,n.name);if(n.isDirectory()){C.has(n.name)||N.push(F);continue}if(!n.isFile())continue;let I=n.name.lastIndexOf(`.`),H=I>=0?n.name.slice(I):``;if(!nz.has(H))continue;let W=readFileSync(F,`utf-8`),q=W;for(let[t,n]of S)q=q.replaceAll(t,n);q!==W&&writeFileSync(F,q)}}}function printNextSteps(t,n,S,C,N){let F=runScriptCommand(C),I=templateScripts(n),H=startScriptFor(N);ge.log(``),ge.log(`Project created from template "${n.name}", set up for ${N}.`),ge.log(``),ge.log(`Next steps:`),ge.log(` cd ${t}`),S||ge.log(` ${C} install`),N===`gjs`&&I.dev?ge.log(` ${F} dev`):(ge.log(` ${F} build`),ge.log(` ${F} ${H}`)),ge.log(``);let W=supportedRuntimes(n).filter(t=>t!==N&&I[startScriptFor(t)]);if(W.length>0){ge.log(`Also runs on ${W.join(`, `)}:`);for(let t of W)ge.log(` ${F} ${startScriptFor(t)}`);ge.log(``)}}function templateManifest(t){try{return JSON.parse(readFileSync(wn(t.path,`package.json`),`utf-8`))}catch{return{}}}function templateScripts(t){let n=templateManifest(t).scripts;return n?Object.fromEntries(Object.entries(n).filter(t=>typeof t[1]==`string`)):{}}function supportedRuntimes(t){let n=templateManifest(t).gjsify?.example?.runtimes;return Array.isArray(n)?n.filter(t=>typeof t==`string`&&packageManagersForRuntime(t)!==void 0):[]}var ez,tz,nz,rz=__esmMin(()=>{_e(),P_(),Rd(),Pn(),KR(),QR(),$R(),ez=`new-gjsify-app`,tz=`org.gjsify.example`,nz=new Set([`.json`,`.md`,`.ts`,`.tsx`,`.js`,`.mjs`,`.cjs`,`.blp`,`.html`,`.css`,`.scss`,`.xml`,`.ui`,`.txt`])});function isCancelled(t){return t instanceof Error&&t.message===az}function render(t,n,S){S||an.write(`\x1b[${t.length}A`);for(let S=0;S<t.length;S++){let C=t[S],N=S===n?`${iz.cyan}❯${iz.reset}`:` `,F=S===n?`${iz.bold}${iz.green}${C.label}${iz.reset}`:C.label,I=C.description?` ${iz.dim}${C.description}${iz.reset}`:``;an.write(`\x1b[2K\r ${N} ${F}${I}\n`)}}function promptChoice(t,n,S=0){return n.length===0?Promise.reject(Error(`Nothing to choose for "${t}".`)):new Promise((C,N)=>{let F=S>=0&&S<n.length?S:0;an.write(`${iz.bold}${t}${iz.reset} ${iz.dim}(↑/↓ to navigate, Enter to confirm, Ctrl+C to cancel)${iz.reset}\n`),render(n,F,!0),emitKeypressEvents(on),on.isTTY&&on.setRawMode(!0),on.resume();let cleanup=()=>{on.removeListener(`keypress`,onKeypress),on.isTTY&&on.setRawMode(!1),on.pause()},onKeypress=(t,S)=>{if(S){if(S.ctrl&&S.name===`c`){cleanup(),an.write(`
952
+ `),N(Error(az));return}S.name===`up`||S.name===`k`?(F=(F-1+n.length)%n.length,render(n,F,!1)):S.name===`down`||S.name===`j`?(F=(F+1)%n.length,render(n,F,!1)):(S.name===`return`||S.name===`enter`)&&(cleanup(),C(n[F].value))}};on.on(`keypress`,onKeypress)})}function promptTemplate(t){return t.length===0?Promise.reject(Error(`No templates available.`)):promptChoice(`Select a template`,t.map(t=>({value:t,label:t.name,description:t.description})))}function promptRuntime(t,n){return promptChoice(`Select a runtime`,t.map(t=>({value:t,label:t,description:ZR[t]??``})),t.indexOf(n))}function promptPackageManager(t,n){return promptChoice(`Select a package manager`,t.map(t=>({value:t,label:t,description:``})),t.indexOf(n))}async function settle(t,n){switch(t.kind){case`value`:return t.value;case`auto`:return ge.error(t.notice),t.value;case`prompt`:try{return await n(t.choices,t.initial)}catch(t){if(!isCancelled(t))throw t;ge.error(`Cancelled.`);return}case`error`:ge.error(`Error: ${t.message}`);return}}async function promptSetup(t){let{offered:n,install:S,interactive:C}=t,N=await settle(selectRuntime({flag:t.runtime,offered:n,manager:t.packageManager,interactive:C}),(t,n)=>promptRuntime(t,n));if(N===void 0)return;let F=await settle(selectPackageManager({flag:t.packageManager,runtime:N,install:S,interactive:C}),(t,n)=>promptPackageManager(t,n));if(F!==void 0)return{runtime:N,packageManager:F}}var iz,az,oz=__esmMin(()=>{_e(),sn(),Ad(),QR(),$R(),iz={reset:`\x1B[0m`,bold:`\x1B[1m`,dim:`\x1B[2m`,cyan:`\x1B[36m`,green:`\x1B[32m`},az=`Cancelled by user`}),sz,cz=__esmMin(()=>{_e(),rz(),oz(),sz={command:`create [project-name]`,description:`Scaffold a new Gjsify project in a new directory.`,builder:t=>{let n=discoverTemplates(),S=n.map(t=>t.name),C=[...new Set(n.flatMap(t=>supportedRuntimes(t)))];return t.positional(`project-name`,{describe:`Name of the project directory to create`,type:`string`,default:`my-gjs-app`}).option(`template`,{alias:`t`,describe:`Template to scaffold from`,type:`string`,choices:S.length>0?S:void 0}).option(`runtime`,{alias:`r`,describe:`Runtime to set the project up for. Decides which package managers are offered and which start script the next steps name.`,type:`string`,choices:C.length>0?C:void 0}).option(`force`,{alias:`f`,describe:`Scaffold into a non-empty directory`,type:`boolean`,default:!1}).option(`install`,{describe:`Install dependencies after scaffolding`,type:`boolean`,default:!1}).option(`package-manager`,{alias:`p`,describe:"Package manager to install with, and to name in the printed next steps. Must be one the chosen runtime can install for. `gjsify` is the only one that works on a host with no Node.js.",type:`string`,choices:qR})},handler:async t=>{let n=!!process.stdin.isTTY,S=discoverTemplates(),C=t.template;if(!C){if(!n){let t=S.map(t=>t.name).join(`, `);return ge.error(`Error: --template is required in non-interactive mode. Available templates: ${t||`(none)`}`),process.exit(1)}let t=await promptTemplate(S).catch(t=>{if(!isCancelled(t))throw t;ge.error(`Cancelled.`)});if(t===void 0)return process.exit(1);C=t.name}let N=S.find(t=>t.name===C),F=await promptSetup({offered:N?supportedRuntimes(N):[],runtime:t.runtime,packageManager:t[`package-manager`],install:t.install,interactive:n});if(F===void 0)return process.exit(1);await createProject({projectName:t[`project-name`],template:C,runtime:F.runtime,force:t.force,install:t.install,packageManager:F.packageManager})}}});function defaultTargetFor(t){let n=Dn(t,On(t));return xn(En(t),n)}var lz,uz,dz=__esmMin(()=>{_e(),P_(),xd(),Pn(),Tu(),lz=promisify(execFile),uz={command:`gresource <xml>`,description:"Compile a GResource XML descriptor into a binary .gresource bundle (wraps `glib-compile-resources`).",builder:t=>t.positional(`xml`,{description:`Path to the .gresource.xml descriptor`,type:`string`,normalize:!0,demandOption:!0}).option(`sourcedir`,{description:`Directory containing the resource files referenced by <xml>`,type:`string`,normalize:!0}).option(`target`,{alias:`t`,description:`Output .gresource file (default: <xml-without-.xml> next to <xml>)`,type:`string`,normalize:!0}).option(`verbose`,{description:`Print the underlying glib-compile-resources invocation`,type:`boolean`,default:!1}),handler:async t=>{let n=xn(t.xml),S=t.target?xn(t.target):defaultTargetFor(n),C=[`--sourcedir=${t.sourcedir?xn(t.sourcedir):En(n)}`,`--target=${S}`,n];t.verbose&&ge.log(`[gjsify gresource] glib-compile-resources ${C.join(` `)}`),await mkdir$1(En(S),{recursive:!0});try{let{stdout:n,stderr:N}=await lz(`glib-compile-resources`,C);n&&process.stdout.write(n),N&&process.stderr.write(N),t.verbose&&ge.log(`[gjsify gresource] wrote ${S}`)}catch(t){let n=t;n?.code===`ENOENT`?ge.error(`[gjsify gresource] glib-compile-resources not found. Install it via your distro (package: glib2-devel / libglib2.0-dev).`):(n?.stderr&&process.stderr.write(n.stderr),ge.error(`[gjsify gresource] glib-compile-resources failed${n?.code===void 0?``:` (exit ${n.code})`}`)),process.exitCode=typeof n?.code==`number`?n.code:1}}}});function mergeCatalogues(t){let n=t.template,S=new Set;for(let{locale:n}of t.catalogues){if(S.has(n))throw Error(`mergeCatalogues: two catalogues both claim locale "${n}". msgfmt APPENDS each --locale, so the chain would emit a duplicate key (desktop-file-validate: "multiple keys named Name[${n}]"; appstreamcli: "tag-duplicated") from two exit-0 calls. Merge them into one .po first (msgcat --use-first) and pass that.`);S.add(n)}for(let[S,C]of t.catalogues.entries()){let N=wn(t.workDir,`${S}${t.extension}`),F=[t.mode,`--template=${n}`,`--locale=${C.locale}`,`--output-file=${N}`,C.po];t.onCall?.(F),execFileSync(`msgfmt`,F,{stdio:`pipe`}),n=N}return n}var fz=__esmMin(()=>{P_(),Pn()});async function listLanguages(t){return(await readdir$1(t)).filter(t=>t.endsWith(`.po`)&&!t.startsWith(`.`)).map(t=>t.slice(0,-3)).sort()}function stripXmlComments(t){return t.replace(/<!--[\s\S]*?-->/g,``)}async function ensureDir(t){await mkdir$1(t,{recursive:!0})}async function fileExists(t){try{return await stat$1(t),!0}catch{return!1}}async function compileMerged(t){let n=await listLanguages(t.poDir);if(n.length===0){ge.warn(`[gjsify gettext] no .po files found in ${t.poDir}`);return}let S=wn(t.outDir,t.filename);await ensureDir(t.outDir);let C=await mkdtemp$1(wn(tmpdir(),`gjsify-gettext-`));try{let N=await readFile$1(mergeCatalogues({mode:`--${t.format}`,template:t.template,extension:`-${Dn(t.template).replace(/\.in$/,``)}`,catalogues:n.map(n=>({locale:n,po:wn(t.poDir,`${n}.po`)})),workDir:C,onCall:t.verbose?t=>ge.log(`[gjsify gettext] msgfmt ${t.join(` `)}`):void 0}),`utf-8`);await writeFile$1(S,t.removeXmlComments&&t.format===`xml`?stripXmlComments(N):N)}finally{await rm$1(C,{recursive:!0,force:!0})}t.verbose&&ge.log(`[gjsify gettext] merged ${n.length} language(s) into ${S}`)}async function compileCatalogues(t){let n=await listLanguages(t.poDir);if(n.length===0){ge.warn(`[gjsify gettext] no .po files found in ${t.poDir}`);return}for(let S of n){let n=wn(t.outDir,S,`LC_MESSAGES`);await ensureDir(n);let C=[`--output-file=${wn(n,t.filename)}`,wn(t.poDir,`${S}.po`)];t.verbose&&ge.log(`[gjsify gettext] msgfmt ${C.join(` `)}`),await pz(`msgfmt`,C)}t.verbose&&ge.log(`[gjsify gettext] compiled ${n.length} language(s) into ${t.outDir}`)}function defaultFilename(t,n,S){switch(n){case`mo`:return`${t}.mo`;case`desktop`:return`${t}.desktop`;case`xml`:return S?Dn(S.replace(/\.in$/,``)):`${t}.xml`}}var pz,mz,hz=__esmMin(()=>{_e(),P_(),xd(),Lg(),Pn(),Tu(),fz(),pz=promisify(execFile),mz={command:`gettext <poDir> <outDir>`,description:`Compile gettext .po files to .mo (per-language locale tree), or merge every catalogue into a .desktop / AppStream template via msgfmt --desktop / --xml.`,builder:t=>t.positional(`poDir`,{description:`Directory containing <lang>.po files`,type:`string`,normalize:!0,demandOption:!0}).positional(`outDir`,{description:`Output directory (locale tree for --format=mo, plain dir for xml/desktop)`,type:`string`,normalize:!0,demandOption:!0}).option(`domain`,{description:"Text domain / application ID (e.g. `org.pixelrpg.maker`)",type:`string`,normalize:!0,demandOption:!0}).option(`format`,{description:`Output format`,type:`string`,choices:[`mo`,`xml`,`desktop`],default:`mo`}).option(`template`,{description:"Required for --format=xml|desktop: the file msgfmt substitutes into. Its SUFFIX matters — msgfmt --xml finds its ITS rules by filename pattern, so an AppStream template must be named `*.metainfo.xml[.in]`.",type:`string`,normalize:!0}).option(`metainfo`,{description:`Deprecated alias for --template.`,type:`string`,normalize:!0,hidden:!0}).option(`filename`,{description:`Override the output filename (defaults to <domain>.<ext>)`,type:`string`,normalize:!0}).option(`remove-xml-comments`,{description:`For --format=xml: strip XML comments from the compiled output`,type:`boolean`,default:!0}).option(`verbose`,{description:`Print each msgfmt invocation`,type:`boolean`,default:!1}),handler:async t=>{let n=xn(t.poDir),S=xn(t.outDir),C=t.domain,N=t.format??`mo`,F=t.template??t.metainfo,I=F?xn(F):void 0,H=t.filename??defaultFilename(C,N,I),W=!!t.verbose,q=!!t[`remove-xml-comments`];if(!await fileExists(n)){ge.error(`[gjsify gettext] PO directory does not exist: ${n}`),process.exitCode=1;return}if(N!==`mo`&&I===void 0){ge.error(`[gjsify gettext] --format=${N} needs a template to substitute into: pass \`--template <file>\`. msgfmt has no way to produce this format from .po files alone.`+(N===`xml`?" Name it `*.metainfo.xml[.in]` — msgfmt --xml finds its ITS rules by filename pattern.":``)),process.exitCode=1;return}try{N===`mo`?await compileCatalogues({poDir:n,outDir:S,filename:H,verbose:W}):await compileMerged({poDir:n,outDir:S,format:N,template:I,filename:H,removeXmlComments:q,verbose:W})}catch(t){let n=t;n?.code===`ENOENT`?ge.error(`[gjsify gettext] msgfmt not found. Install it via your distro (package: gettext).`):(n?.stderr&&process.stderr.write(n.stderr),ge.error(`[gjsify gettext] msgfmt failed${n?.code===void 0?``:` (exit ${n.code})`}`)),process.exitCode=typeof n?.code==`number`?n.code:1}}}}),gz,_z,vz=__esmMin(()=>{_e(),P_(),xd(),Pn(),Tu(),gz=promisify(execFile),_z={command:`gsettings <schemadir>`,description:"Compile GSettings schema XML files into a binary gschemas.compiled (wraps `glib-compile-schemas`).",builder:t=>t.positional(`schemadir`,{description:`Directory containing *.gschema.xml descriptors`,type:`string`,normalize:!0,demandOption:!0}).option(`targetdir`,{alias:`t`,description:`Directory to write gschemas.compiled (default: <schemadir>)`,type:`string`,normalize:!0}).option(`strict`,{description:`Abort on any schema warning (passes --strict to glib-compile-schemas)`,type:`boolean`,default:!0}).option(`verbose`,{description:`Print the underlying glib-compile-schemas invocation`,type:`boolean`,default:!1}),handler:async t=>{let n=xn(t.schemadir),S=t.targetdir?xn(t.targetdir):n,C=[];t.strict&&C.push(`--strict`),C.push(`--targetdir=${S}`),C.push(n),t.verbose&&ge.log(`[gjsify gsettings] glib-compile-schemas ${C.join(` `)}`),await mkdir$1(S,{recursive:!0});try{let{stdout:n,stderr:N}=await gz(`glib-compile-schemas`,C);n&&process.stdout.write(n),N&&process.stderr.write(N),t.verbose&&ge.log(`[gjsify gsettings] wrote ${S}/gschemas.compiled`)}catch(t){let n=t;n?.code===`ENOENT`?ge.error(`[gjsify gsettings] glib-compile-schemas not found. Install it via your distro (package: glib2-devel / libglib2.0-dev).`):(n?.stderr&&process.stderr.write(n.stderr),ge.error(`[gjsify gsettings] glib-compile-schemas failed${n?.code===void 0?``:` (exit ${n.code})`}`)),process.exitCode=typeof n?.code==`number`?n.code:1}}}});function readPackageJson(t){let n=xn(t,`package.json`),S;try{S=readFileSync(n,`utf-8`)}catch{throw Error(`gjsify flatpak: no package.json found at ${n}`)}try{return JSON.parse(S)}catch(t){throw Error(`gjsify flatpak: package.json at ${n} is not valid JSON: ${t.message}`)}}function looksLikeAppId(t){return typeof t==`string`&&/^[A-Za-z][A-Za-z0-9_-]*(\.[A-Za-z][A-Za-z0-9_-]*){2,}$/.test(t)}function defaultCiContainer(t,n){return`ghcr.io/flathub-infra/flatpak-github-actions:${`${t}-${n}`}`}var yz,bz=__esmMin(()=>{Rd(),Pn(),yz=`gjsify-sources.json`});function resolveRuntime(t,n){let S=n.runtime??t?.runtime??`gnome`;if(S!==`gnome`&&S!==`freedesktop`)throw Error(`gjsify flatpak: unknown runtime "${S}" (expected "gnome" or "freedesktop")`);let C=n.runtimeVersion??t?.runtimeVersion??(S===`gnome`?`50`:`24.08`);return S===`gnome`?{runtime:S,runtimeId:`org.gnome.Platform`,sdk:`org.gnome.Sdk`,runtimeVersion:C}:{runtime:S,runtimeId:`org.freedesktop.Platform`,sdk:`org.freedesktop.Sdk`,runtimeVersion:C}}function deriveAppendPath(t){let n=[];for(let S of t){let t=/^org\.freedesktop\.Sdk\.Extension\.([A-Za-z0-9-]+)$/.exec(S);t&&n.push(`/usr/lib/sdk/${t[1]}/bin`)}return n.push(`/app/bin`),n}var xz,Sz,Cz=__esmMin(()=>{xz=[`--device=dri`,`--share=ipc`,`--socket=fallback-x11`,`--socket=wayland`],Sz=[]});function pickFlatpakBuildKeys(t,n){let S=t??{},C={},N=[];for(let t of Tz){let F=S[t];if(F!==void 0){C[t]=F;continue}let I=n[t];I!==void 0&&N.push(t),C[t]=I}return{values:C,fromLegacy:N}}function resolveShipFlatpakSettings(t){let n=t.ship.flatpak??{},{values:S,fromLegacy:C}=pickFlatpakBuildKeys(n,t.flatpak),N=resolveRuntime(S,{}),F=S.sdkExtensions??[],{appendPath:I,finishArgs:H,cleanup:W}=S;return{settings:{runtime:N.runtimeId,runtimeVersion:N.runtimeVersion,sdk:N.sdk,branch:n.branch??`stable`,sdkExtensions:[...F],appendPath:I??(F.length>0?deriveAppendPath(F):[]),finishArgs:H??(t.kind===`cli`?Sz:xz),cleanup:[...new Set([...W??[],...t.kind===`app`?[Ez]:[]])]},warnings:C.length===0?[]:[deprecationWarning(C)]}}function assertNoDroppedFlatpakModules(t){let n=[`modules`,`extraModules`].filter(n=>(t[n]?.length??0)>0);if(n.length===0)return;let S=n.map(t=>`gjsify.flatpak.${t}`).join(` and `);throw Error(`gjsify ship: ${S} ${n.length>1?`are`:`is`} set, but the \`flatpak\` target renders ONE module, the staged payload, and would drop ${n.length>1?`them`:`it`} (ADR 0024 § 2). Build this Flatpak with \`gjsify flatpak init\` + \`gjsify flatpak build\`, which honour the key, or leave \`flatpak\` out of \`--target\` / \`gjsify.ship.targets\`.`)}function deprecationWarning(t){let n=t.map(t=>`gjsify.flatpak.${t}`).join(`, `),S=t.map(t=>`gjsify.ship.flatpak.${t}`).join(`, `);return`DEPRECATION: ${n} ${t.length>1?`are`:`is`} read by \`gjsify ship\` for compatibility and will be removed in ${wz}. Move ${t.length>1?`them`:`it`} to ${S} — both spellings resolve until then, and \`gjsify.ship.flatpak\` wins where both are set. The app METADATA in \`gjsify.flatpak\` (name, summary, developer, categories, licence) is NOT deprecated: both blocks describe the same application and either may carry it (ADR 0024 § 8).`}var wz,Tz,Ez,Dz=__esmMin(()=>{Cz(),wz=`1.0.0`,Tz=[`runtime`,`runtimeVersion`,`sdkExtensions`,`appendPath`,`finishArgs`,`cleanup`],Ez=`/share/icons/hicolor/scalable`});function loadDesktopTemplate(){return Oz}function validateAppMetadata(t){let n=t.metadata,S=t.configKey,C=[];return(!n.developer?.id||!n.developer?.name)&&C.push({field:`${S}.developer`,hint:`Set \`${S}.developer = { "id": "io.github.you", "name": "Your Name" }\` in package.json. The id is reverse-DNS.`}),n.summary||C.push({field:`${S}.summary`,hint:`One-line app summary, ≤80 chars, no trailing period. Example: "Learn 6502 assembly language".`}),n.description||C.push({field:`${S}.description`,hint:`Plain text (split on blank lines) or DescriptionBlock[] for rich content with bullet lists + translator hints.`}),n.license?.project||C.push({field:`${S}.license.project`,hint:`SPDX identifier of the project license, e.g. "MIT", "GPL-3.0-or-later".`}),n.homepageUrl||C.push({field:`${S}.homepageUrl`,hint:`Required by Flathub. Example: "https://github.com/you/your-repo".`}),C}function renderMetainfoApp$1(t){return renderMetainfo(t,`desktop-application`)}function renderMetainfoCli$1(t){return renderMetainfo(t,`console-application`)}function renderDesktopEntry(t){let n=t.metadata,S=(n.categories??[`Utility`]).join(`;`)+`;`,C=n.keywords?.length?`Keywords=${n.keywords.join(`;`)};\n`:``,N=n.provides?.mimetypes??[],F=N.length?`MimeType=${N.join(`;`)};\n`:``;return substitute(loadDesktopTemplate(),{NAME:t.name,SUMMARY:n.summary??t.name,COMMAND:`${t.command}${execFieldCode(N)}`,APP_ID:t.appId,CATEGORIES_LINE:S,KEYWORDS_LINE:C,MIMETYPES_LINE:F})}function execFieldCode(t){return t.some(t=>t.startsWith(`x-scheme-handler/`))?` %u`:t.length>0?` %f`:``}function renderMetainfo(t,n){let S=t.metadata,C=t.copyrightYear??new Date().getFullYear(),N=S.developer?.name??``,F=[];F.push(`<?xml version="1.0" encoding="UTF-8"?>`),F.push(`<!-- Copyright ${C} ${escapeXml(N)} -->`),F.push(`<component type="${n}">`),F.push(` <id>${escapeXml(t.appId)}</id>`),F.push(` <metadata_license>${escapeXml(S.license?.metadata??`CC0-1.0`)}</metadata_license>`),F.push(` <project_license>${escapeXml(S.license?.project??``)}</project_license>`),F.push(` <name>${escapeXml(t.name)}</name>`),pushTranslatorHint(F,S.summaryTranslatorHint,` `),F.push(` <summary>${escapeXml(S.summary??t.name)}</summary>`),S.iconRemote&&F.push(` <icon type="remote">${escapeXml(S.iconRemote)}</icon>`),F.push(` <description>`);for(let t of renderDescriptionBlocks(S.description??``,` `))F.push(t);if(F.push(` </description>`),S.developer?.id&&S.developer?.name){F.push(` <developer id="${escapeXml(S.developer.id)}">`);let t=S.developer.nameTranslatable===!0?``:` translate="no"`;F.push(` <name${t}>${escapeXml(S.developer.name)}</name>`),S.developer.email&&F.push(` <email>${escapeXml(S.developer.email)}</email>`),F.push(` </developer>`)}n===`desktop-application`&&F.push(` <launchable type="desktop-id">${escapeXml(t.appId)}.desktop</launchable>`),S.screenshots?.length&&(F.push(` <screenshots>`),S.screenshots.forEach((t,n)=>{let S=t.type??(n===0?`default`:void 0),C=S?` type="${escapeXml(S)}"`:``,N=t.environment?` environment="${escapeXml(t.environment)}"`:``;F.push(` <screenshot${C}${N}>`),F.push(` <image>${escapeXml(t.url)}</image>`);for(let[n,S]of Object.entries(t.localizedUrls??{}))F.push(` <image xml:lang="${escapeXml(n)}">${escapeXml(S)}</image>`);t.caption&&(pushTranslatorHint(F,t.captionTranslatorHint,` `),F.push(` <caption>${escapeXml(t.caption)}</caption>`)),F.push(` </screenshot>`)}),F.push(` </screenshots>`)),S.homepageUrl&&F.push(` <url type="homepage">${escapeXml(S.homepageUrl)}</url>`),S.bugtrackerUrl&&F.push(` <url type="bugtracker">${escapeXml(S.bugtrackerUrl)}</url>`),S.vcsBrowserUrl&&F.push(` <url type="vcs-browser">${escapeXml(S.vcsBrowserUrl)}</url>`),S.donationUrl&&channelAllowsDonations(t.channel)&&F.push(` <url type="donation">${escapeXml(S.donationUrl)}</url>`),S.translateUrl&&F.push(` <url type="translate">${escapeXml(S.translateUrl)}</url>`);let I=normaliseContentRating(S.contentRating);if(I.attributes&&Object.keys(I.attributes).length>0){F.push(` <content_rating type="${escapeXml(I.type)}">`);for(let[t,n]of Object.entries(I.attributes))F.push(` <content_attribute id="${escapeXml(t)}">${escapeXml(n)}</content_attribute>`);F.push(` </content_rating>`)}else F.push(` <content_rating type="${escapeXml(I.type)}" />`);if(S.releases?.length){F.push(` <releases>`);for(let t of S.releases)if(t.description===void 0)F.push(` <release version="${escapeXml(t.version)}" date="${escapeXml(t.date)}" />`);else{F.push(` <release version="${escapeXml(t.version)}" date="${escapeXml(t.date)}">`),F.push(` <description>`);for(let n of renderDescriptionBlocks(t.description,` `))F.push(n);F.push(` </description>`),F.push(` </release>`)}F.push(` </releases>`)}if(S.categories?.length){F.push(` <categories>`);for(let t of S.categories)F.push(` <category>${escapeXml(t)}</category>`);F.push(` </categories>`)}if(S.keywords?.length){F.push(` <keywords>`);for(let t of S.keywords)F.push(` <keyword>${escapeXml(t)}</keyword>`);F.push(` </keywords>`)}if(n===`desktop-application`&&S.branding&&(F.push(` <branding>`),F.push(` <color type="primary" scheme_preference="light">${escapeXml(S.branding.accentLight)}</color>`),F.push(` <color type="primary" scheme_preference="dark">${escapeXml(S.branding.accentDark)}</color>`),F.push(` </branding>`)),S.kudos?.length){F.push(` <kudos>`);for(let t of S.kudos)F.push(` <kudo>${escapeXml(t)}</kudo>`);F.push(` </kudos>`)}let H=S.provides?.binaries??[t.command],W=S.provides?.mimetypes??[],q=S.provides?.dbus??[];if(H.length||W.length||q.length){F.push(` <provides>`);for(let t of H)F.push(` <binary>${escapeXml(t)}</binary>`);for(let t of W)F.push(` <mediatype>${escapeXml(t)}</mediatype>`);for(let t of q)F.push(` <dbus type="${escapeXml(t.type)}">${escapeXml(t.id)}</dbus>`);F.push(` </provides>`)}if(S.supports?.controls?.length||S.supports?.internet){F.push(` <supports>`);for(let t of S.supports.controls??[])F.push(` <control>${escapeXml(t)}</control>`);S.supports.internet&&F.push(` <internet>${escapeXml(S.supports.internet)}</internet>`),F.push(` </supports>`)}if(S.requires?.displayLengthMin||S.requires?.controls?.length||S.requires?.internet){F.push(` <requires>`),S.requires.displayLengthMin&&F.push(` <display_length compare="ge">${S.requires.displayLengthMin}</display_length>`);for(let t of S.requires.controls??[])F.push(` <control>${escapeXml(t)}</control>`);S.requires.internet&&F.push(` <internet>${escapeXml(S.requires.internet)}</internet>`),F.push(` </requires>`)}if(S.recommends?.displayLengthMin||S.recommends?.controls?.length){F.push(` <recommends>`),S.recommends.displayLengthMin&&F.push(` <display_length compare="ge">${S.recommends.displayLengthMin}</display_length>`);for(let t of S.recommends.controls??[])F.push(` <control>${escapeXml(t)}</control>`);F.push(` </recommends>`)}return F.push(`</component>`),F.join(`
953
953
  `)+`
954
- `}function renderDescriptionBlocks(t,n){let S=typeof t==`string`?stringToBlocks(t):t,C=[];for(let t of S)if(`p`in t)pushTranslatorHint(C,t.translatorHint,n),C.push(`${n}<p>${escapeXml(t.p.trim().replace(/\s+/g,` `))}</p>`);else{pushTranslatorHint(C,t.translatorHint,n),C.push(`${n}<ul>`);for(let S of t.ul)typeof S==`string`?C.push(`${n} <li>${escapeXml(S)}</li>`):(pushTranslatorHint(C,S.translatorHint,`${n} `),C.push(`${n} <li>${escapeXml(S.item)}</li>`));C.push(`${n}</ul>`)}return C}function stringToBlocks(t){return t.trim().split(/\n\n+/).map(t=>({p:t.trim().replace(/\s+/g,` `)}))}function pushTranslatorHint(t,n,S){n&&t.push(`${S}<!-- TRANSLATORS: ${n} -->`)}function normaliseContentRating(t){return t===void 0?{type:`oars-1.1`}:typeof t==`string`?{type:t}:{type:t.type??`oars-1.1`,attributes:t.attributes}}function substitute(t,n){let S=t;for(let[t,C]of Object.entries(n))S=S.split(`{{${t}}}`).join(C);return S}function escapeXml(t){return t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}var Cz,wz=__esmMin(()=>{ch(),Cz=`[Desktop Entry]
954
+ `}function renderDescriptionBlocks(t,n){let S=typeof t==`string`?stringToBlocks(t):t,C=[];for(let t of S)if(`p`in t)pushTranslatorHint(C,t.translatorHint,n),C.push(`${n}<p>${escapeXml(t.p.trim().replace(/\s+/g,` `))}</p>`);else{pushTranslatorHint(C,t.translatorHint,n),C.push(`${n}<ul>`);for(let S of t.ul)typeof S==`string`?C.push(`${n} <li>${escapeXml(S)}</li>`):(pushTranslatorHint(C,S.translatorHint,`${n} `),C.push(`${n} <li>${escapeXml(S.item)}</li>`));C.push(`${n}</ul>`)}return C}function stringToBlocks(t){return t.trim().split(/\n\n+/).map(t=>({p:t.trim().replace(/\s+/g,` `)}))}function pushTranslatorHint(t,n,S){n&&t.push(`${S}<!-- TRANSLATORS: ${n} -->`)}function normaliseContentRating(t){return t===void 0?{type:`oars-1.1`}:typeof t==`string`?{type:t}:{type:t.type??`oars-1.1`,attributes:t.attributes}}function substitute(t,n){let S=t;for(let[t,C]of Object.entries(n))S=S.split(`{{${t}}}`).join(C);return S}function escapeXml(t){return t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}var Oz,kz=__esmMin(()=>{ch(),Oz=`[Desktop Entry]
955
955
  Name={{NAME}}
956
956
  Comment={{SUMMARY}}
957
957
  Exec={{COMMAND}}
@@ -965,7 +965,7 @@ StartupWMClass={{APP_ID}}
965
965
  `}function loadFlathubCliTemplate(){return`{
966
966
  "skip-icons-check": true
967
967
  }
968
- `}function toMetadataInputs(t){return{appId:t.appId,name:t.name,command:t.command,kind:t.kind,metadata:t.flatpak,channel:`flathub`,configKey:`gjsify.flatpak`}}function validateScaffoldInputs(t){return validateAppMetadata(toMetadataInputs(t))}function renderMetainfoApp(t){return renderMetainfoApp$1(toMetadataInputs(t))}function renderMetainfoCli(t){return renderMetainfoCli$1(toMetadataInputs(t))}function renderDesktop(t){return renderDesktopEntry(toMetadataInputs(t))}function renderFlathubJson(t){return t===`cli`?loadFlathubCliTemplate():loadFlathubAppTemplate()}var Tz=__esmMin(()=>{wz()});function oxcBindingSuffix(){let t=process.platform,n=process.arch,S;if(t===`linux`)S=`linux`;else if(t===`darwin`)S=`darwin`;else if(t===`win32`)S=`win32`;else throw Error(`[gjsify oxc] Unsupported platform: ${t}`);let C;if(n===`x64`)C=`x64`;else if(n===`arm64`)C=`arm64`;else throw Error(`[gjsify oxc] Unsupported arch on ${S}: ${n}`);if(S===`linux`){let t=hostLibc(`linux`)===`musl`?`musl`:`gnu`;return`${S}-${C}-${t}`}return S===`win32`?`${S}-${C}-msvc`:`${S}-${C}`}function bindingPackageName(t){return`${t===`oxlint`?`@oxlint`:`@oxfmt`}/binding-${oxcBindingSuffix()}`}function probeNodeModules(t,n,S){let C=wn(t,`node_modules`,n,S);return existsSync(C)?C:null}function findOxcLauncher(t,n=process.cwd()){let S=wn(`bin`,t),C=probeNodeModules(n,t,S);if(C)return C;let N=findWorkspaceRoot(n);if(N&&N!==n){let n=probeNodeModules(N,t,S);if(n)return n}let F=xn(n,`..`);for(let n=0;n<6;n++){let n=probeNodeModules(F,t,S);if(n)return n;let C=xn(F,`..`);if(C===F)break;F=C}throw new OxcNotFoundError(t,n)}function findOxlintConfig(t=process.cwd()){return findConfigFile(t,[`.oxlintrc.json`])}function findOxfmtConfig(t=process.cwd()){return findConfigFile(t,[`.oxfmtrc`,`.oxfmtrc.json`])}function findConfigFile(t,n){let S=t;for(let t=0;t<12;t++){for(let t of n){let n=wn(S,t);if(existsSync(n))return n}let t=xn(S,`..`);if(t===S)break;S=t}return null}async function tryLoadNativeOxfmt(){return Ez||(Ez=(async()=>{if(!isGjs())return null;try{activateNativePrebuilds();let t=`@gjsify/oxfmt-native`,n=await import(pathToFileURL(resolveNpmPackage(t,{bundleUrl:import.meta.url})??createRequire(import.meta.url).resolve(t)).href);if(!n.hasNativeOxfmt())return null;let S;try{let t=pathToFileURL(resolveNpmPackage(`@gjsify/utils/native-library`,{bundleUrl:import.meta.url})??createRequire(import.meta.url).resolve(`@gjsify/utils/native-library`)).href;({openNativeLibrary:S}=await import(t))}catch(t){return Dz=t instanceof Error?t:Error(String(t)),null}return Dz=S(`GjsifyOxfmt`),Dz?null:n}catch{return null}})(),Ez)}async function shouldUseNativeOxfmt(){let t=(globalThis.process?.env??{}).GJSIFY_OXFMT;if(t===`npm`)return!1;if(t===`native`){if(!await tryLoadNativeOxfmt())throw Error(`GJSIFY_OXFMT=native but @gjsify/oxfmt-native is not loadable (no prebuild for this architecture, or not running under GJS).`+(Dz?`\n${Dz.message}`:``));return!0}if(!isGjs())return!1;let n=await tryLoadNativeOxfmt()!==null;return!n&&Dz&&ge.debug(Dz.message),n}async function runOxc(t,n,S={}){if(t===`oxfmt`&&await shouldUseNativeOxfmt()){let t=await tryLoadNativeOxfmt();if(!t)throw Error(`@gjsify/oxfmt-native not loadable`);return S.verbose&&ge.log(`[gjsify oxc] @gjsify/oxfmt-native (in-process) ${n.join(` `)}`),t.runOxfmt(n)}return spawnOxcLauncher(t,n,S)}function spawnOxcLauncher(t,n,S={}){let C=S.cwd??process.cwd(),N=findOxcLauncher(t,C),F=nodeBinary();return S.verbose&&ge.log(`[gjsify oxc] ${F} ${N} ${n.join(` `)}`),spawnToCompletion(F,[N,...n],{completion:`return`,cwd:C,notFound:()=>new OxcNotFoundError(t,C,F)}).then(({code:n,signal:S})=>S===null?n??0:(ge.error(`[gjsify oxc] ${t} terminated by signal ${S}`),1))}function runOxlint(t,n={}){return runOxc(`oxlint`,t,n)}function runOxfmt(t,n={}){return runOxc(`oxfmt`,t,n)}function loadOxlintTemplate(){return`{
968
+ `}function toMetadataInputs(t){return{appId:t.appId,name:t.name,command:t.command,kind:t.kind,metadata:t.flatpak,channel:`flathub`,configKey:`gjsify.flatpak`}}function validateScaffoldInputs(t){return validateAppMetadata(toMetadataInputs(t))}function renderMetainfoApp(t){return renderMetainfoApp$1(toMetadataInputs(t))}function renderMetainfoCli(t){return renderMetainfoCli$1(toMetadataInputs(t))}function renderDesktop(t){return renderDesktopEntry(toMetadataInputs(t))}function renderFlathubJson(t){return t===`cli`?loadFlathubCliTemplate():loadFlathubAppTemplate()}var Az=__esmMin(()=>{kz()});function oxcBindingSuffix(){let t=process.platform,n=process.arch,S;if(t===`linux`)S=`linux`;else if(t===`darwin`)S=`darwin`;else if(t===`win32`)S=`win32`;else throw Error(`[gjsify oxc] Unsupported platform: ${t}`);let C;if(n===`x64`)C=`x64`;else if(n===`arm64`)C=`arm64`;else throw Error(`[gjsify oxc] Unsupported arch on ${S}: ${n}`);if(S===`linux`){let t=hostLibc(`linux`)===`musl`?`musl`:`gnu`;return`${S}-${C}-${t}`}return S===`win32`?`${S}-${C}-msvc`:`${S}-${C}`}function bindingPackageName(t){return`${t===`oxlint`?`@oxlint`:`@oxfmt`}/binding-${oxcBindingSuffix()}`}function probeNodeModules(t,n,S){let C=wn(t,`node_modules`,n,S);return existsSync(C)?C:null}function findOxcLauncher(t,n=process.cwd()){let S=wn(`bin`,t),C=probeNodeModules(n,t,S);if(C)return C;let N=findWorkspaceRoot(n);if(N&&N!==n){let n=probeNodeModules(N,t,S);if(n)return n}let F=xn(n,`..`);for(let n=0;n<6;n++){let n=probeNodeModules(F,t,S);if(n)return n;let C=xn(F,`..`);if(C===F)break;F=C}throw new OxcNotFoundError(t,n)}function findOxlintConfig(t=process.cwd()){return findConfigFile(t,[`.oxlintrc.json`])}function findOxfmtConfig(t=process.cwd()){return findConfigFile(t,[`.oxfmtrc`,`.oxfmtrc.json`])}function findConfigFile(t,n){let S=t;for(let t=0;t<12;t++){for(let t of n){let n=wn(S,t);if(existsSync(n))return n}let t=xn(S,`..`);if(t===S)break;S=t}return null}async function tryLoadNativeOxfmt(){return jz||(jz=(async()=>{if(!isGjs())return null;try{activateNativePrebuilds();let t=`@gjsify/oxfmt-native`,n=await import(pathToFileURL(resolveNpmPackage(t,{bundleUrl:import.meta.url})??createRequire(import.meta.url).resolve(t)).href);if(!n.hasNativeOxfmt())return null;let S;try{let t=pathToFileURL(resolveNpmPackage(`@gjsify/utils/native-library`,{bundleUrl:import.meta.url})??createRequire(import.meta.url).resolve(`@gjsify/utils/native-library`)).href;({openNativeLibrary:S}=await import(t))}catch(t){return Mz=t instanceof Error?t:Error(String(t)),null}return Mz=S(`GjsifyOxfmt`),Mz?null:n}catch{return null}})(),jz)}async function shouldUseNativeOxfmt(){let t=(globalThis.process?.env??{}).GJSIFY_OXFMT;if(t===`npm`)return!1;if(t===`native`){if(!await tryLoadNativeOxfmt())throw Error(`GJSIFY_OXFMT=native but @gjsify/oxfmt-native is not loadable (no prebuild for this architecture, or not running under GJS).`+(Mz?`\n${Mz.message}`:``));return!0}if(!isGjs())return!1;let n=await tryLoadNativeOxfmt()!==null;return!n&&Mz&&ge.debug(Mz.message),n}async function runOxc(t,n,S={}){if(t===`oxfmt`&&await shouldUseNativeOxfmt()){let t=await tryLoadNativeOxfmt();if(!t)throw Error(`@gjsify/oxfmt-native not loadable`);return S.verbose&&ge.log(`[gjsify oxc] @gjsify/oxfmt-native (in-process) ${n.join(` `)}`),t.runOxfmt(n)}return spawnOxcLauncher(t,n,S)}function spawnOxcLauncher(t,n,S={}){let C=S.cwd??process.cwd(),N=findOxcLauncher(t,C),F=nodeBinary();return S.verbose&&ge.log(`[gjsify oxc] ${F} ${N} ${n.join(` `)}`),spawnToCompletion(F,[N,...n],{completion:`return`,cwd:C,notFound:()=>new OxcNotFoundError(t,C,F)}).then(({code:n,signal:S})=>S===null?n??0:(ge.error(`[gjsify oxc] ${t} terminated by signal ${S}`),1))}function runOxlint(t,n={}){return runOxc(`oxlint`,t,n)}function runOxfmt(t,n={}){return runOxc(`oxfmt`,t,n)}function loadOxlintTemplate(){return`{
969
969
  "$schema": "./node_modules/oxlint/configuration_schema.json",
970
970
  "categories": {
971
971
  "correctness": "error"
@@ -1054,11 +1054,11 @@ StartupWMClass={{APP_ID}}
1054
1054
  "**/*.metainfo.xml"
1055
1055
  ]
1056
1056
  }
1057
- `}function printOxcNotFound(t){ge.error(t.message)}function setOxcExitCode(t){process.exitCode=t,t!==0&&gjsExit(t)}function hasOxcDevDep(t=process.cwd(),n=`oxfmt`){let S=wn(t,`package.json`);if(!existsSync(S))return!1;try{let t=JSON.parse(readFileSync(S,`utf-8`));return!!(t?.devDependencies?.[n]||t?.dependencies?.[n])}catch{return!1}}var OxcNotFoundError,Ez,Dz,Oz=__esmMin(()=>{_e(),Rd(),Pn(),Il(),Gn(),zL(),eF(),nF(),TF(),QI(),V_(),d_(),OxcNotFoundError=class extends Error{tool;cwd;missingInterpreter;constructor(t,n,S){let C=(()=>{try{return bindingPackageName(t)}catch{return`@${t===`oxlint`?`oxlint`:`oxfmt`}/binding-<platform>`}})();super(S===void 0?`[gjsify oxc] ${t} not found.\n Expected: ${t}/bin/${t} in node_modules of ${n} or any workspace root above it.\n Install it via: gjsify install -D ${t}\n (this adds ${t} to devDependencies; the matching ${C} napi binding lands automatically as an optionalDependency.)`:`[gjsify oxc] cannot run ${t}: no \`${S}\` binary on PATH.\n ${t} IS installed — its launcher was found. What is missing is the\n interpreter that runs it: ${t}'s launcher is a Node ESM script.\n`+(t===`oxfmt`?" For a Node-free formatter install the GI bridge:\n gjsify install -D @gjsify/oxfmt-native\n (`gjsify format`/`fix` then run oxfmt in-process under GJS.)":" oxlint has no native GJS bridge yet — its JS-plugin host lives in the\n Node launcher — so `gjsify lint` needs Node on the host for now.")),this.tool=t,this.cwd=n,this.missingInterpreter=S,this.name=`OxcNotFoundError`}},Ez=null,Dz=null});function writeIfFresh(t,n,S,C){return existsSync(t)&&!S?(ge.log(`[gjsify flatpak init] skipped ${C}: ${t} (exists; --force to overwrite)`),null):(mkdirSync(En(t),{recursive:!0}),writeFileSync(t,n,`utf-8`),ge.log(`[gjsify flatpak init] wrote ${C}: ${t}`),t)}function friendlyName(t,n){if(t.startsWith(`@`))return t.slice(t.indexOf(`/`)+1);if(t===n){let t=n.split(`.`);return t[t.length-1]??n}return t}function mergeArrays(t,n){if(!(!t?.length&&!n?.length))return[...t??[],...n??[]]}function deriveModuleName(t){let n=t.split(`.`);return n[n.length-1]||t}var kz,Az=__esmMin(()=>{_e(),Rd(),Pn(),hz(),vz(),Sz(),Tz(),TI(),Oz(),kz={command:`init`,description:"Generate Flatpak manifest + MetaInfo XML + .desktop + flathub.json from `gjsify.flatpak` config.",builder:t=>t.option(`app-id`,{description:"Reverse-DNS app id (default: `gjsify.flatpak.appId` or package.json#name)",type:`string`}).option(`runtime`,{description:`Runtime family`,choices:[`gnome`,`freedesktop`]}).option(`runtime-version`,{description:`Runtime version (default: gnome -> 50, freedesktop -> 24.08)`,type:`string`}).option(`kind`,{description:`App kind: "app" (default, desktop) or "cli" (console-application MetaInfo, no .desktop)`,choices:[`app`,`cli`]}).option(`cli-only`,{description:"(Deprecated) Alias for `--kind cli`. Use --kind instead.",type:`boolean`,default:!1}).option(`manifest`,{description:"Output path for the manifest. Default: `<app-id>.json` in cwd.",type:`string`,normalize:!0}).option(`metainfo`,{description:"Output path for the MetaInfo XML. Default: `data/<app-id>.metainfo.xml.in` in cwd.",type:`string`,normalize:!0}).option(`desktop`,{description:"Output path for the .desktop entry (app kind only). Default: `data/<app-id>.desktop.in`.",type:`string`,normalize:!0}).option(`flathub-json`,{description:"Output path for the flathub.json policy stub. Default: `flathub.json` in cwd.",type:`string`,normalize:!0}).option(`command`,{description:`Binary name in /app/bin (default: app id)`,type:`string`}).option(`sdk-extension`,{description:`Extra SDK extension (repeatable)`,type:`string`,array:!0}).option(`finish-arg`,{description:`Extra finish-arg (repeatable). Override defaults entirely with multiple --finish-arg.`,type:`string`,array:!0}).option(`force`,{description:`Overwrite existing output files (manifest, metainfo, desktop, flathub.json)`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print the resolved manifest fields before writing`,type:`boolean`,default:!1}).option(`format`,{description:"Run `oxfmt --write` on the generated JS/TS files when `oxfmt` is detected in the project. Default: true. Pass --no-format to skip. Note: oxfmt formats JS/TS only — the JSON/XML/.desktop manifests generated here are not reformatted (CSS/JSON formatting was dropped in the oxc migration).",type:`boolean`,default:!0}),handler:async t=>{let n=await new Config().forCommand().catch(()=>({})),S=n.flatpak??{},C=process.cwd(),N=readPackageJson(C),F=t.appId??S.appId??(looksLikeAppId(N.name)?N.name:void 0);if(!F)throw Error(`gjsify flatpak init: no app id available. Pass --app-id, set gjsify.flatpak.appId in package.json, or rename the package to a reverse-DNS id like org.example.MyApp.`);let I=t.kind??S.kind??(t.cliOnly?`cli`:`app`),H=pickFlatpakBuildKeys(n.ship?.flatpak,S).values,{runtime:W,runtimeId:q,sdk:Y,runtimeVersion:X}=resolveRuntime(H,{runtime:t.runtime,runtimeVersion:t.runtimeVersion}),Z=mergeArrays(H.sdkExtensions,t.sdkExtension),te=H.appendPath??(Z?.length?deriveAppendPath(Z):void 0),ne=t.command??S.command??F,re=t.finishArg,ie=re===void 0?H.finishArgs??(I===`cli`?_z:gz):re,ae={id:F,runtime:q,"runtime-version":X,sdk:Y};Z?.length&&(ae[`sdk-extensions`]=Z),te?.length&&(ae[`build-options`]={"append-path":te.join(`:`)}),ae.command=ne,ae[`finish-args`]=ie;let oe=H.cleanup;oe?.length&&(ae.cleanup=oe);let Q=[];S.modules?.length?Q.push(...S.modules):(S.extraModules?.length&&Q.push(...S.extraModules),Q.push({name:deriveModuleName(F),buildsystem:`meson`,sources:[{type:`dir`,path:`.`}]})),ae.modules=Q;let se=[],trackWrite=t=>{t&&se.push(t)};trackWrite(writeIfFresh(xn(C,t.manifest??`${F}.json`),JSON.stringify(ae,null,2)+`
1057
+ `}function printOxcNotFound(t){ge.error(t.message)}function setOxcExitCode(t){process.exitCode=t,t!==0&&gjsExit(t)}function hasOxcDevDep(t=process.cwd(),n=`oxfmt`){let S=wn(t,`package.json`);if(!existsSync(S))return!1;try{let t=JSON.parse(readFileSync(S,`utf-8`));return!!(t?.devDependencies?.[n]||t?.dependencies?.[n])}catch{return!1}}var OxcNotFoundError,jz,Mz,Nz=__esmMin(()=>{_e(),Rd(),Pn(),Il(),Gn(),WL(),eF(),nF(),TF(),rL(),V_(),d_(),OxcNotFoundError=class extends Error{tool;cwd;missingInterpreter;constructor(t,n,S){let C=(()=>{try{return bindingPackageName(t)}catch{return`@${t===`oxlint`?`oxlint`:`oxfmt`}/binding-<platform>`}})();super(S===void 0?`[gjsify oxc] ${t} not found.\n Expected: ${t}/bin/${t} in node_modules of ${n} or any workspace root above it.\n Install it via: gjsify install -D ${t}\n (this adds ${t} to devDependencies; the matching ${C} napi binding lands automatically as an optionalDependency.)`:`[gjsify oxc] cannot run ${t}: no \`${S}\` binary on PATH.\n ${t} IS installed — its launcher was found. What is missing is the\n interpreter that runs it: ${t}'s launcher is a Node ESM script.\n`+(t===`oxfmt`?" For a Node-free formatter install the GI bridge:\n gjsify install -D @gjsify/oxfmt-native\n (`gjsify format`/`fix` then run oxfmt in-process under GJS.)":" oxlint has no native GJS bridge yet — its JS-plugin host lives in the\n Node launcher — so `gjsify lint` needs Node on the host for now.")),this.tool=t,this.cwd=n,this.missingInterpreter=S,this.name=`OxcNotFoundError`}},jz=null,Mz=null});function writeIfFresh(t,n,S,C){return existsSync(t)&&!S?(ge.log(`[gjsify flatpak init] skipped ${C}: ${t} (exists; --force to overwrite)`),null):(mkdirSync(En(t),{recursive:!0}),writeFileSync(t,n,`utf-8`),ge.log(`[gjsify flatpak init] wrote ${C}: ${t}`),t)}function friendlyName(t,n){if(t.startsWith(`@`))return t.slice(t.indexOf(`/`)+1);if(t===n){let t=n.split(`.`);return t[t.length-1]??n}return t}function mergeArrays(t,n){if(!(!t?.length&&!n?.length))return[...t??[],...n??[]]}function deriveModuleName(t){let n=t.split(`.`);return n[n.length-1]||t}var Pz,Fz=__esmMin(()=>{_e(),Rd(),Pn(),bz(),Cz(),Dz(),Az(),AI(),Nz(),Pz={command:`init`,description:"Generate Flatpak manifest + MetaInfo XML + .desktop + flathub.json from `gjsify.flatpak` config.",builder:t=>t.option(`app-id`,{description:"Reverse-DNS app id (default: `gjsify.flatpak.appId` or package.json#name)",type:`string`}).option(`runtime`,{description:`Runtime family`,choices:[`gnome`,`freedesktop`]}).option(`runtime-version`,{description:`Runtime version (default: gnome -> 50, freedesktop -> 24.08)`,type:`string`}).option(`kind`,{description:`App kind: "app" (default, desktop) or "cli" (console-application MetaInfo, no .desktop)`,choices:[`app`,`cli`]}).option(`cli-only`,{description:"(Deprecated) Alias for `--kind cli`. Use --kind instead.",type:`boolean`,default:!1}).option(`manifest`,{description:"Output path for the manifest. Default: `<app-id>.json` in cwd.",type:`string`,normalize:!0}).option(`metainfo`,{description:"Output path for the MetaInfo XML. Default: `data/<app-id>.metainfo.xml.in` in cwd.",type:`string`,normalize:!0}).option(`desktop`,{description:"Output path for the .desktop entry (app kind only). Default: `data/<app-id>.desktop.in`.",type:`string`,normalize:!0}).option(`flathub-json`,{description:"Output path for the flathub.json policy stub. Default: `flathub.json` in cwd.",type:`string`,normalize:!0}).option(`command`,{description:`Binary name in /app/bin (default: app id)`,type:`string`}).option(`sdk-extension`,{description:`Extra SDK extension (repeatable)`,type:`string`,array:!0}).option(`finish-arg`,{description:`Extra finish-arg (repeatable). Override defaults entirely with multiple --finish-arg.`,type:`string`,array:!0}).option(`force`,{description:`Overwrite existing output files (manifest, metainfo, desktop, flathub.json)`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print the resolved manifest fields before writing`,type:`boolean`,default:!1}).option(`format`,{description:"Run `oxfmt --write` on the generated JS/TS files when `oxfmt` is detected in the project. Default: true. Pass --no-format to skip. Note: oxfmt formats JS/TS only — the JSON/XML/.desktop manifests generated here are not reformatted (CSS/JSON formatting was dropped in the oxc migration).",type:`boolean`,default:!0}),handler:async t=>{let n=await new Config().forCommand().catch(()=>({})),S=n.flatpak??{},C=process.cwd(),N=readPackageJson(C),F=t.appId??S.appId??(looksLikeAppId(N.name)?N.name:void 0);if(!F)throw Error(`gjsify flatpak init: no app id available. Pass --app-id, set gjsify.flatpak.appId in package.json, or rename the package to a reverse-DNS id like org.example.MyApp.`);let I=t.kind??S.kind??(t.cliOnly?`cli`:`app`),H=pickFlatpakBuildKeys(n.ship?.flatpak,S).values,{runtime:W,runtimeId:q,sdk:Y,runtimeVersion:X}=resolveRuntime(H,{runtime:t.runtime,runtimeVersion:t.runtimeVersion}),Z=mergeArrays(H.sdkExtensions,t.sdkExtension),te=H.appendPath??(Z?.length?deriveAppendPath(Z):void 0),ne=t.command??S.command??F,re=t.finishArg,ie=re===void 0?H.finishArgs??(I===`cli`?Sz:xz):re,ae={id:F,runtime:q,"runtime-version":X,sdk:Y};Z?.length&&(ae[`sdk-extensions`]=Z),te?.length&&(ae[`build-options`]={"append-path":te.join(`:`)}),ae.command=ne,ae[`finish-args`]=ie;let oe=H.cleanup;oe?.length&&(ae.cleanup=oe);let Q=[];S.modules?.length?Q.push(...S.modules):(S.extraModules?.length&&Q.push(...S.extraModules),Q.push({name:deriveModuleName(F),buildsystem:`meson`,sources:[{type:`dir`,path:`.`}]})),ae.modules=Q;let se=[],trackWrite=t=>{t&&se.push(t)};trackWrite(writeIfFresh(xn(C,t.manifest??`${F}.json`),JSON.stringify(ae,null,2)+`
1058
1058
  `,t.force??!1,`manifest`));let ce=N.name??F,le={appId:F,name:S.name??friendlyName(ce,F),command:ne,kind:I,flatpak:S},ue=validateScaffoldInputs(le);if(ue.length>0){ge.warn(`[gjsify flatpak init] Manifest written, but MetaInfo / .desktop are skipped — config gaps:`);for(let t of ue)ge.warn(` - ${t.field}: ${t.hint}`);ge.warn(`
1059
- Fill these fields in package.json#gjsify.flatpak (or .gjsifyrc.*) and re-run with --force.`)}else{let n=I===`cli`?renderMetainfoCli(le):renderMetainfoApp(le);trackWrite(writeIfFresh(xn(C,t.metainfo??`data/${F}.metainfo.xml.in`),n,t.force??!1,`metainfo`)),I===`app`&&(trackWrite(writeIfFresh(xn(C,t.desktop??`data/${F}.desktop.in`),renderDesktop(le),t.force??!1,`desktop`)),S.icon||ge.warn(`[gjsify flatpak init] No gjsify.flatpak.icon set. Flathub requires a scalable SVG at\n data/icons/hicolor/scalable/apps/${F}.svg`)),trackWrite(writeIfFresh(xn(C,t.flathubJson??`flathub.json`),renderFlathubJson(I),t.force??!1,`flathub.json`))}let de=se.filter(t=>/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(t));if(de.length>0&&t.format!==!1&&hasOxcDevDep(C))try{await runOxfmt([`--write`,...de],{cwd:C})}catch(t){if(t instanceof OxcNotFoundError)ge.warn("[gjsify flatpak init] post-format skipped: oxfmt declared but binding not installed. Run `gjsify install` then re-run with --force, or pass --no-format.");else throw t}t.verbose&&(ge.log(`[gjsify flatpak init] kind=${I} runtime=${q} ${X} sdk=${Y}`),ge.log(`[gjsify flatpak init] command=${ne} finish-args=${JSON.stringify(ie)}`))}}});function findDefaultManifest(t){return scanForManifest(t)??`flatpak.json`}function scanForManifest(t){let n=[];try{n=readdirSync(t)}catch{return}for(let S of n)if(S.endsWith(`.json`)&&!(S===`package.json`||S===`tsconfig.json`||S.startsWith(`.`)))try{let n=JSON.parse(readFileSync(xn(t,S),`utf-8`));if(typeof n.id==`string`&&typeof n.runtime==`string`&&Array.isArray(n.modules))return S}catch{}}function readManifestAppId(t){let n=readFileSync(t,`utf-8`),S=JSON.parse(n);if(typeof S.id!=`string`)throw Error(`gjsify flatpak build: ${t} has no string "id" field`);return S.id}async function runFlatpakBuilder(t,n){return runProc(`flatpak-builder`,t,n,{notFoundHint:"flatpak-builder not found. Install via your distro (Fedora: `sudo dnf install flatpak-builder`)."})}async function runFlatpak(t,n){return runProc(`flatpak`,t,n,{notFoundHint:`flatpak not found. Install via your distro and add Flathub: see https://flathub.org/setup.`})}async function runTar(t,n){return runProc(`tar`,t,n,{notFoundHint:`tar not found.`})}async function runProc(t,n,S,C){S.verbose&&ge.log(`[gjsify flatpak] ${t} ${n.join(` `)}`);let{code:N}=await spawnToCompletion(t,n,{completion:`exit`,notFound:()=>Error(`gjsify flatpak: ${C.notFoundHint}`)});if(N!==0)throw Error(`gjsify flatpak: ${t} exited with status ${N}`)}var jz,Mz=__esmMin(()=>{_e(),Rd(),Pn(),V_(),jz={command:`build [manifest]`,description:"Build the Flatpak via `flatpak-builder`. Wraps a typical install + export + bundle + tarball pipeline.",builder:t=>t.positional(`manifest`,{description:`Path to the Flatpak manifest (default: first *.json that looks like a manifest in cwd)`,type:`string`,normalize:!0}).option(`build-dir`,{description:`flatpak-builder working directory`,type:`string`,default:`flatpak-build`,normalize:!0}).option(`install`,{description:"After build, run `flatpak-builder --user --install` to install locally",type:`boolean`,default:!1}).option(`repo`,{description:"Export the build into the given OSTree repo (passes `--repo=<dir>` to flatpak-builder)",type:`string`,normalize:!0}).option(`bundle`,{description:"After --repo export, build a single-file bundle (`flatpak build-bundle`) at this path",type:`string`,normalize:!0}).option(`tarball`,{description:`Create a tarball of the build dir (parity with the legacy build-flatpak.sh tarball step)`,type:`string`,normalize:!0}).option(`force-clean`,{description:`Pass --force-clean to flatpak-builder (default true)`,type:`boolean`,default:!0}).option(`sandbox`,{description:`Pass --sandbox to flatpak-builder (default true)`,type:`boolean`,default:!0}).option(`delete-build-dirs`,{description:`Pass --delete-build-dirs to flatpak-builder (default true)`,type:`boolean`,default:!0}).option(`install-deps-from`,{description:"Pass --install-deps-from to flatpak-builder (e.g. `flathub`)",type:`string`}).option(`verbose`,{description:`Print the underlying flatpak-builder invocations`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=xn(n,t.manifest??findDefaultManifest(n));if(!existsSync(S))throw Error(`gjsify flatpak build: manifest ${S} not found`);let C=xn(n,t.buildDir??`flatpak-build`),N=[];if(t.forceClean!==!1&&N.push(`--force-clean`),t.sandbox!==!1&&N.push(`--sandbox`),t.deleteBuildDirs!==!1&&N.push(`--delete-build-dirs`),t.installDepsFrom&&N.push(`--install-deps-from=${t.installDepsFrom}`),existsSync(C)&&rmSync(C,{recursive:!0,force:!0}),await runFlatpakBuilder([...N,C,S],{verbose:t.verbose}),t.install&&await runFlatpakBuilder([`--user`,`--install`,`--force-clean`,C,S],{verbose:t.verbose}),t.repo){let N=xn(n,t.repo);mkdirSync(En(N),{recursive:!0}),await runFlatpakBuilder([`--repo=${N}`,`--force-clean`,C,S],{verbose:t.verbose})}if(t.bundle){if(!t.repo)throw Error(`gjsify flatpak build: --bundle requires --repo (the bundle is built from the OSTree repo).`);let C=xn(n,t.bundle);mkdirSync(En(C),{recursive:!0}),await runFlatpak([`build-bundle`,xn(n,t.repo),C,readManifestAppId(S)],{verbose:t.verbose})}if(t.tarball){let S=xn(n,t.tarball);mkdirSync(En(S),{recursive:!0}),await runTar([`-czf`,S,`-C`,C,`.`],{verbose:t.verbose})}return ge.log(`[gjsify flatpak build] done (${C})`),process.exit(0)}}});function detectLockfile(t){return existsSync(xn(t,`yarn.lock`))?`yarn.lock`:existsSync(xn(t,`package-lock.json`))?`package-lock.json`:`yarn.lock`}var Nz,Pz=__esmMin(()=>{_e(),V_(),Rd(),Pn(),Nz={command:`deps`,description:"Generate Flatpak offline-cache sources from a yarn.lock / package-lock.json (wraps `flatpak-node-generator`).",builder:t=>t.option(`lockfile`,{description:`Path to lockfile (default: yarn.lock or package-lock.json in cwd)`,type:`string`,normalize:!0}).option(`type`,{description:`Lockfile type. Default: detected from filename.`,choices:[`yarn`,`npm`]}).option(`out`,{description:`Output JSON sources file`,type:`string`,default:`flatpak-node-sources.json`,normalize:!0}).option(`xdg-layout`,{description:`Pass --xdg-layout (recommended for Yarn Berry / PnP setups)`,type:`boolean`,default:!0}).option(`electron-node-headers`,{description:`Pass --electron-node-headers`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print the underlying flatpak-node-generator invocation`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=xn(n,t.lockfile??detectLockfile(n));if(!existsSync(S))throw Error(`gjsify flatpak deps: lockfile ${S} not found (use --lockfile to override)`);let C=t.type??(S.endsWith(`package-lock.json`)?`npm`:`yarn`),N=xn(n,t.out??`flatpak-node-sources.json`);mkdirSync(En(N),{recursive:!0});let F=[C,S,`-o`,N];t.xdgLayout!==!1&&F.push(`--xdg-layout`),t.electronNodeHeaders&&F.push(`--electron-node-headers`),t.verbose&&ge.log(`[gjsify flatpak deps] flatpak-node-generator ${F.join(` `)}`);let I=await spawnToCompletion(`flatpak-node-generator`,F,{completion:`return`,notFound:()=>Error("gjsify flatpak deps: flatpak-node-generator not found. Install via `pipx install flatpak-node-generator` (see https://github.com/flatpak/flatpak-builder-tools/tree/master/node).")});if(I.code!==0)throw Error(`gjsify flatpak deps: flatpak-node-generator exited with ${describeExit(I)}`);ge.log(`[gjsify flatpak deps] wrote ${N}`)}}});function classifyDependency(t,n,S){let C=S.get(t);return C&&!Iz.test(n)?{kind:`workspace`,target:C}:n.startsWith(`workspace:`)?{kind:`missing-workspace`}:Iz.test(n)?{kind:`ignored`}:{kind:`external`}}function planFocus(t,n,S){let C=new Map(t.map(t=>[t.name,t])),N=[...new Set(n)].filter(t=>!C.has(t));if(N.length>0){let t=[...C.keys()].sort(),n=t.slice(0,Lz).join(`, `),F=t.length>Lz?`, … (${t.length-Lz} more)`:``;throw Error(`${S}: --focus names unknown workspace(s): ${N.join(`, `)}. Pass a package name from a workspace's package.json. Known workspaces: ${n}${F}.`)}let F=new Set(n.map(t=>C.get(t))),I=new Set;for(let t of F)for(let n of Fz)for(let[S,N]of Object.entries(t.manifest[n]??{})){if(typeof N!=`string`)continue;let t=classifyDependency(S,N,C);t.kind===`workspace`?F.add(t.target):t.kind===`external`&&I.add(`${S}@${N}`)}return{workspaces:t.filter(t=>F.has(t)),specs:[...I]}}var Fz,Iz,Lz,Rz=__esmMin(()=>{Fz=[`dependencies`,`devDependencies`,`optionalDependencies`],Iz=/^(link|file|portal|git\+|https?):/,Lz=20});function parseSri(t){if(!t)return null;let n=t.indexOf(`-`);if(n<=0||n===t.length-1)return null;let S=t.slice(0,n),C=t.slice(n+1).replace(/=+$/,``),N=$e.from(C,`base64`).toString(`hex`);return N.length<4?null:{algorithm:S,hex:N}}function parseNpmLike(t){let n=[],S=t,C=S.packages;if(C&&typeof C==`object`){for(let t of Object.values(C))t?.resolved&&t.integrity&&n.push({url:t.resolved,integrity:t.integrity});if(n.length>0)return n}return S.dependencies&&typeof S.dependencies==`object`&&collectV1Deps(S.dependencies,n),n}function collectV1Deps(t,n){for(let S of Object.values(t))S?.resolved&&S.integrity&&n.push({url:S.resolved,integrity:S.integrity}),S?.dependencies&&collectV1Deps(S.dependencies,n)}function parseYarnClassic(t){if(/^__metadata:/m.test(t))throw Error("gjsify flatpak sources: Yarn Berry (v2+) yarn.lock is not supported — its `checksum` is a cache hash, not a tarball SRI. Run `gjsify install` to produce a gjsify-lock.json, or use a classic (v1) yarn.lock.");let n=[],S=0;for(let C of t.split(/\n\s*\n/)){let t=C.match(/^\s+resolved\s+"([^"]+)"/m);if(!t)continue;let N=t[1].replace(/#.*$/,``),F=C.match(/^\s+integrity\s+(\S+)/m);if(!F){S++;continue}n.push({url:N,integrity:F[1]})}return S>0&&ge.warn(`[gjsify flatpak sources] ${S} yarn.lock entr(y/ies) had no integrity (pre-1.x format) and were skipped — re-lock with a modern yarn or use \`gjsify install\`.`),n}function parsePnpm(t){let n=[],S=!1,C=null;for(let N of t.split(`
1059
+ Fill these fields in package.json#gjsify.flatpak (or .gjsifyrc.*) and re-run with --force.`)}else{let n=I===`cli`?renderMetainfoCli(le):renderMetainfoApp(le);trackWrite(writeIfFresh(xn(C,t.metainfo??`data/${F}.metainfo.xml.in`),n,t.force??!1,`metainfo`)),I===`app`&&(trackWrite(writeIfFresh(xn(C,t.desktop??`data/${F}.desktop.in`),renderDesktop(le),t.force??!1,`desktop`)),S.icon||ge.warn(`[gjsify flatpak init] No gjsify.flatpak.icon set. Flathub requires a scalable SVG at\n data/icons/hicolor/scalable/apps/${F}.svg`)),trackWrite(writeIfFresh(xn(C,t.flathubJson??`flathub.json`),renderFlathubJson(I),t.force??!1,`flathub.json`))}let de=se.filter(t=>/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/.test(t));if(de.length>0&&t.format!==!1&&hasOxcDevDep(C))try{await runOxfmt([`--write`,...de],{cwd:C})}catch(t){if(t instanceof OxcNotFoundError)ge.warn("[gjsify flatpak init] post-format skipped: oxfmt declared but binding not installed. Run `gjsify install` then re-run with --force, or pass --no-format.");else throw t}t.verbose&&(ge.log(`[gjsify flatpak init] kind=${I} runtime=${q} ${X} sdk=${Y}`),ge.log(`[gjsify flatpak init] command=${ne} finish-args=${JSON.stringify(ie)}`))}}});function findDefaultManifest(t){return scanForManifest(t)??`flatpak.json`}function scanForManifest(t){let n=[];try{n=readdirSync(t)}catch{return}for(let S of n)if(S.endsWith(`.json`)&&!(S===`package.json`||S===`tsconfig.json`||S.startsWith(`.`)))try{let n=JSON.parse(readFileSync(xn(t,S),`utf-8`));if(typeof n.id==`string`&&typeof n.runtime==`string`&&Array.isArray(n.modules))return S}catch{}}function readManifestAppId(t){let n=readFileSync(t,`utf-8`),S=JSON.parse(n);if(typeof S.id!=`string`)throw Error(`gjsify flatpak build: ${t} has no string "id" field`);return S.id}async function runFlatpakBuilder(t,n){return runProc(`flatpak-builder`,t,n,{notFoundHint:"flatpak-builder not found. Install via your distro (Fedora: `sudo dnf install flatpak-builder`)."})}async function runFlatpak(t,n){return runProc(`flatpak`,t,n,{notFoundHint:`flatpak not found. Install via your distro and add Flathub: see https://flathub.org/setup.`})}async function runTar(t,n){return runProc(`tar`,t,n,{notFoundHint:`tar not found.`})}async function runProc(t,n,S,C){S.verbose&&ge.log(`[gjsify flatpak] ${t} ${n.join(` `)}`);let{code:N}=await spawnToCompletion(t,n,{completion:`exit`,notFound:()=>Error(`gjsify flatpak: ${C.notFoundHint}`)});if(N!==0)throw Error(`gjsify flatpak: ${t} exited with status ${N}`)}var Iz,Lz=__esmMin(()=>{_e(),Rd(),Pn(),V_(),Iz={command:`build [manifest]`,description:"Build the Flatpak via `flatpak-builder`. Wraps a typical install + export + bundle + tarball pipeline.",builder:t=>t.positional(`manifest`,{description:`Path to the Flatpak manifest (default: first *.json that looks like a manifest in cwd)`,type:`string`,normalize:!0}).option(`build-dir`,{description:`flatpak-builder working directory`,type:`string`,default:`flatpak-build`,normalize:!0}).option(`install`,{description:"After build, run `flatpak-builder --user --install` to install locally",type:`boolean`,default:!1}).option(`repo`,{description:"Export the build into the given OSTree repo (passes `--repo=<dir>` to flatpak-builder)",type:`string`,normalize:!0}).option(`bundle`,{description:"After --repo export, build a single-file bundle (`flatpak build-bundle`) at this path",type:`string`,normalize:!0}).option(`tarball`,{description:`Create a tarball of the build dir (parity with the legacy build-flatpak.sh tarball step)`,type:`string`,normalize:!0}).option(`force-clean`,{description:`Pass --force-clean to flatpak-builder (default true)`,type:`boolean`,default:!0}).option(`sandbox`,{description:`Pass --sandbox to flatpak-builder (default true)`,type:`boolean`,default:!0}).option(`delete-build-dirs`,{description:`Pass --delete-build-dirs to flatpak-builder (default true)`,type:`boolean`,default:!0}).option(`install-deps-from`,{description:"Pass --install-deps-from to flatpak-builder (e.g. `flathub`)",type:`string`}).option(`verbose`,{description:`Print the underlying flatpak-builder invocations`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=xn(n,t.manifest??findDefaultManifest(n));if(!existsSync(S))throw Error(`gjsify flatpak build: manifest ${S} not found`);let C=xn(n,t.buildDir??`flatpak-build`),N=[];if(t.forceClean!==!1&&N.push(`--force-clean`),t.sandbox!==!1&&N.push(`--sandbox`),t.deleteBuildDirs!==!1&&N.push(`--delete-build-dirs`),t.installDepsFrom&&N.push(`--install-deps-from=${t.installDepsFrom}`),existsSync(C)&&rmSync(C,{recursive:!0,force:!0}),await runFlatpakBuilder([...N,C,S],{verbose:t.verbose}),t.install&&await runFlatpakBuilder([`--user`,`--install`,`--force-clean`,C,S],{verbose:t.verbose}),t.repo){let N=xn(n,t.repo);mkdirSync(En(N),{recursive:!0}),await runFlatpakBuilder([`--repo=${N}`,`--force-clean`,C,S],{verbose:t.verbose})}if(t.bundle){if(!t.repo)throw Error(`gjsify flatpak build: --bundle requires --repo (the bundle is built from the OSTree repo).`);let C=xn(n,t.bundle);mkdirSync(En(C),{recursive:!0}),await runFlatpak([`build-bundle`,xn(n,t.repo),C,readManifestAppId(S)],{verbose:t.verbose})}if(t.tarball){let S=xn(n,t.tarball);mkdirSync(En(S),{recursive:!0}),await runTar([`-czf`,S,`-C`,C,`.`],{verbose:t.verbose})}return ge.log(`[gjsify flatpak build] done (${C})`),process.exit(0)}}});function detectLockfile(t){return existsSync(xn(t,`yarn.lock`))?`yarn.lock`:existsSync(xn(t,`package-lock.json`))?`package-lock.json`:`yarn.lock`}var Rz,zz=__esmMin(()=>{_e(),V_(),Rd(),Pn(),Rz={command:`deps`,description:"Generate Flatpak offline-cache sources from a yarn.lock / package-lock.json (wraps `flatpak-node-generator`).",builder:t=>t.option(`lockfile`,{description:`Path to lockfile (default: yarn.lock or package-lock.json in cwd)`,type:`string`,normalize:!0}).option(`type`,{description:`Lockfile type. Default: detected from filename.`,choices:[`yarn`,`npm`]}).option(`out`,{description:`Output JSON sources file`,type:`string`,default:`flatpak-node-sources.json`,normalize:!0}).option(`xdg-layout`,{description:`Pass --xdg-layout (recommended for Yarn Berry / PnP setups)`,type:`boolean`,default:!0}).option(`electron-node-headers`,{description:`Pass --electron-node-headers`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print the underlying flatpak-node-generator invocation`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=xn(n,t.lockfile??detectLockfile(n));if(!existsSync(S))throw Error(`gjsify flatpak deps: lockfile ${S} not found (use --lockfile to override)`);let C=t.type??(S.endsWith(`package-lock.json`)?`npm`:`yarn`),N=xn(n,t.out??`flatpak-node-sources.json`);mkdirSync(En(N),{recursive:!0});let F=[C,S,`-o`,N];t.xdgLayout!==!1&&F.push(`--xdg-layout`),t.electronNodeHeaders&&F.push(`--electron-node-headers`),t.verbose&&ge.log(`[gjsify flatpak deps] flatpak-node-generator ${F.join(` `)}`);let I=await spawnToCompletion(`flatpak-node-generator`,F,{completion:`return`,notFound:()=>Error("gjsify flatpak deps: flatpak-node-generator not found. Install via `pipx install flatpak-node-generator` (see https://github.com/flatpak/flatpak-builder-tools/tree/master/node).")});if(I.code!==0)throw Error(`gjsify flatpak deps: flatpak-node-generator exited with ${describeExit(I)}`);ge.log(`[gjsify flatpak deps] wrote ${N}`)}}});function classifyDependency(t,n,S){let C=S.get(t);return C&&!Vz.test(n)?{kind:`workspace`,target:C}:n.startsWith(`workspace:`)?{kind:`missing-workspace`}:Vz.test(n)?{kind:`ignored`}:{kind:`external`}}function planFocus(t,n,S){let C=new Map(t.map(t=>[t.name,t])),N=[...new Set(n)].filter(t=>!C.has(t));if(N.length>0){let t=[...C.keys()].sort(),n=t.slice(0,Hz).join(`, `),F=t.length>Hz?`, … (${t.length-Hz} more)`:``;throw Error(`${S}: --focus names unknown workspace(s): ${N.join(`, `)}. Pass a package name from a workspace's package.json. Known workspaces: ${n}${F}.`)}let F=new Set(n.map(t=>C.get(t))),I=new Set;for(let t of F)for(let n of Bz)for(let[S,N]of Object.entries(t.manifest[n]??{})){if(typeof N!=`string`)continue;let t=classifyDependency(S,N,C);t.kind===`workspace`?F.add(t.target):t.kind===`external`&&I.add(`${S}@${N}`)}return{workspaces:t.filter(t=>F.has(t)),specs:[...I]}}var Bz,Vz,Hz,Uz=__esmMin(()=>{Bz=[`dependencies`,`devDependencies`,`optionalDependencies`],Vz=/^(link|file|portal|git\+|https?):/,Hz=20});function parseSri(t){if(!t)return null;let n=t.indexOf(`-`);if(n<=0||n===t.length-1)return null;let S=t.slice(0,n),C=t.slice(n+1).replace(/=+$/,``),N=$e.from(C,`base64`).toString(`hex`);return N.length<4?null:{algorithm:S,hex:N}}function parseNpmLike(t){let n=[],S=t,C=S.packages;if(C&&typeof C==`object`){for(let t of Object.values(C))t?.resolved&&t.integrity&&n.push({url:t.resolved,integrity:t.integrity});if(n.length>0)return n}return S.dependencies&&typeof S.dependencies==`object`&&collectV1Deps(S.dependencies,n),n}function collectV1Deps(t,n){for(let S of Object.values(t))S?.resolved&&S.integrity&&n.push({url:S.resolved,integrity:S.integrity}),S?.dependencies&&collectV1Deps(S.dependencies,n)}function parseYarnClassic(t){if(/^__metadata:/m.test(t))throw Error("gjsify flatpak sources: Yarn Berry (v2+) yarn.lock is not supported — its `checksum` is a cache hash, not a tarball SRI. Run `gjsify install` to produce a gjsify-lock.json, or use a classic (v1) yarn.lock.");let n=[],S=0;for(let C of t.split(/\n\s*\n/)){let t=C.match(/^\s+resolved\s+"([^"]+)"/m);if(!t)continue;let N=t[1].replace(/#.*$/,``),F=C.match(/^\s+integrity\s+(\S+)/m);if(!F){S++;continue}n.push({url:N,integrity:F[1]})}return S>0&&ge.warn(`[gjsify flatpak sources] ${S} yarn.lock entr(y/ies) had no integrity (pre-1.x format) and were skipped — re-lock with a modern yarn or use \`gjsify install\`.`),n}function parsePnpm(t){let n=[],S=!1,C=null;for(let N of t.split(`
1060
1060
  `)){let t=N.replace(/\r$/,``);if(/^packages:\s*$/.test(t)){S=!0;continue}if(S&&/^[^\s#]/.test(t)&&(S=!1),!S)continue;let F=t.match(/^ {2}(?:'([^']+)'|"([^"]+)"|([^\s#][^:]*)):\s*$/);if(F){C=F[1]??F[2]??F[3]??null;continue}let I=t.match(/resolution:\s*\{([^}]*)\}/);if(I&&C){let t=I[1].match(/integrity:\s*(sha\d+-[A-Za-z0-9+/=]+)/);if(!t)continue;let S=I[1].match(/tarball:\s*([^\s,}]+)/),N=S?S[1]:reconstructNpmTarballUrl(C);N&&n.push({url:N,integrity:t[1]})}}return n}function reconstructNpmTarballUrl(t){let n,S;if(t.startsWith(`/`)){let C=t.slice(1).replace(/_.*$/,``),N=C.lastIndexOf(`/`);if(N<=0)return null;n=C.slice(0,N),S=C.slice(N+1)}else{let C=t.replace(/\(.*\)$/,``),N=C.lastIndexOf(`@`);if(N<=0)return null;n=C.slice(0,N),S=C.slice(N+1)}if(!n||!S||/[@:/]/.test(S))return null;let C=n.slice(n.lastIndexOf(`/`)+1);return`https://registry.npmjs.org/${n}/-/${C}-${S}.tgz`}function detectType(t){let n=t.toLowerCase();return n.endsWith(`pnpm-lock.yaml`)?`pnpm`:n.endsWith(`yarn.lock`)?`yarn`:n.endsWith(`package-lock.json`)?`npm`:`gjsify`}function defaultLockfile(t){for(let n of[`gjsify-lock.json`,`package-lock.json`,`yarn.lock`,`pnpm-lock.yaml`])if(existsSync(wn(t,n)))return n;return`gjsify-lock.json`}function focusedTarballs(t,n){let S=discoverWorkspaces(En(t),{includeRoot:!0}),C=planFocus(S,n,`gjsify flatpak sources`),N=readLockfileNodes(t);if(!N)throw Error(`gjsify flatpak sources: ${t} is not a readable gjsify-lock.json.`);let F=reachableInstallPaths(N,C.specs.map(parseSpecName)),I=new Set(S.map(t=>t.name));return N.filter(t=>F.has(t.installPath)&&!I.has(t.name)).flatMap(t=>t.tarballUrl&&t.integrity?[{url:t.tarballUrl,integrity:t.integrity}]:[])}function parseLockfile(t,n){let S=readFileSync(t,`utf-8`);if(n===`yarn`)return parseYarnClassic(S);if(n===`pnpm`)return parsePnpm(S);let C;try{C=JSON.parse(S)}catch(n){throw Error(`gjsify flatpak sources: ${t} is not valid JSON: ${n.message}`)}return parseNpmLike(C)}function buildModuleSnippet(t,n){return[``,`# Add the generated sources to your app module and point XDG_CACHE_HOME`,`# at the vendored cache before running gjsify offline. Example module:`,`#`,`# {`,`# "name": "my-app",`,`# "buildsystem": "simple",`,`# "build-commands": [`,`# "export XDG_CACHE_HOME=\\"$(pwd)/${n}\\"",`,`# "gjsify install --immutable",`,`# "gjsify build src/main.ts --app gjs --outfile /app/bin/my-app"`,`# ],`,`# "sources": [`,`# { "type": "dir", "path": "." },`,`# "${t}"`,`# ]`,`# }`,``].join(`
1061
- `)}var zz,Bz,Vz=__esmMin(()=>{_e(),Rd(),Pn(),lt(),QP(),Rz(),ZL(),hz(),zz=new Set([`sha256`,`sha512`]),Bz={command:`sources`,description:"Generate an offline flatpak-builder `sources` array from any lockfile (gjsify-lock.json / package-lock.json / yarn.lock / pnpm-lock.yaml) for a no-network Flathub build.",builder:t=>t.option(`lockfile`,{description:`Path to the lockfile. Default: the first of gjsify-lock.json / package-lock.json / yarn.lock / pnpm-lock.yaml found in cwd.`,type:`string`,normalize:!0}).option(`type`,{description:`Lockfile format. Default: detected from the filename.`,choices:[`gjsify`,`npm`,`yarn`,`pnpm`]}).option(`out`,{description:`Output JSON sources file`,type:`string`,default:mz,normalize:!0}).option(`cache-root`,{description:`Relative dir the tarballs download into; point XDG_CACHE_HOME here in the build. Tarballs land at <cache-root>/gjsify/tarballs/v1/<algo>/<shard>/<hex>.tgz.`,type:`string`,default:`flatpak-gjsify-cache`}).option(`focus`,{description:"Only the tarballs the named workspaces (package names), the workspaces they depend on, and their external dependencies need, as `gjsify install --focus` installs them. gjsify-lock.json only.",type:`string`,array:!0}).option(`print-module`,{description:`Also print a ready-to-paste flatpak manifest module snippet to stderr`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=xn(n,t.lockfile??defaultLockfile(n));if(!existsSync(S))throw Error(`gjsify flatpak sources: lockfile ${S} not found. Run \`gjsify install\` (or npm/yarn/pnpm) first, or pass --lockfile.`);let C=t.type??detectType(S),N=t.focus;if(N&&N.length>0&&C!==`gjsify`)throw Error(`gjsify flatpak sources: --focus reads the per-package edges of gjsify-lock.json; ${C} lockfiles are not supported with it.`);let F=N&&N.length>0?focusedTarballs(S,N):parseLockfile(S,C),I=t.cacheRoot??`flatpak-gjsify-cache`,H=new Map,W=0,q=0;for(let{url:t,integrity:n}of F){let S=parseSri(n);if(!S){W++;continue}if(!zz.has(S.algorithm)){q++;continue}let C=`${S.algorithm}:${S.hex}`;if(H.has(C))continue;let N={type:`file`,url:t,dest:`${I}/gjsify/tarballs/v1/${S.algorithm}/${S.hex.slice(0,2)}`,"dest-filename":`${S.hex}.tgz`};S.algorithm===`sha512`?N.sha512=S.hex:N.sha256=S.hex,H.set(C,N)}let Y=[...H.values()].sort((t,n)=>t.url<n.url?-1:+(t.url>n.url)),X=xn(n,t.out??`gjsify-sources.json`);mkdirSync(En(X),{recursive:!0}),writeFileSync(X,JSON.stringify(Y,null,2)+`
1061
+ `)}var Wz,Gz,Kz=__esmMin(()=>{_e(),Rd(),Pn(),lt(),QP(),Uz(),nR(),bz(),Wz=new Set([`sha256`,`sha512`]),Gz={command:`sources`,description:"Generate an offline flatpak-builder `sources` array from any lockfile (gjsify-lock.json / package-lock.json / yarn.lock / pnpm-lock.yaml) for a no-network Flathub build.",builder:t=>t.option(`lockfile`,{description:`Path to the lockfile. Default: the first of gjsify-lock.json / package-lock.json / yarn.lock / pnpm-lock.yaml found in cwd.`,type:`string`,normalize:!0}).option(`type`,{description:`Lockfile format. Default: detected from the filename.`,choices:[`gjsify`,`npm`,`yarn`,`pnpm`]}).option(`out`,{description:`Output JSON sources file`,type:`string`,default:yz,normalize:!0}).option(`cache-root`,{description:`Relative dir the tarballs download into; point XDG_CACHE_HOME here in the build. Tarballs land at <cache-root>/gjsify/tarballs/v1/<algo>/<shard>/<hex>.tgz.`,type:`string`,default:`flatpak-gjsify-cache`}).option(`focus`,{description:"Only the tarballs the named workspaces (package names), the workspaces they depend on, and their external dependencies need, as `gjsify install --focus` installs them. gjsify-lock.json only.",type:`string`,array:!0}).option(`print-module`,{description:`Also print a ready-to-paste flatpak manifest module snippet to stderr`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=xn(n,t.lockfile??defaultLockfile(n));if(!existsSync(S))throw Error(`gjsify flatpak sources: lockfile ${S} not found. Run \`gjsify install\` (or npm/yarn/pnpm) first, or pass --lockfile.`);let C=t.type??detectType(S),N=t.focus;if(N&&N.length>0&&C!==`gjsify`)throw Error(`gjsify flatpak sources: --focus reads the per-package edges of gjsify-lock.json; ${C} lockfiles are not supported with it.`);let F=N&&N.length>0?focusedTarballs(S,N):parseLockfile(S,C),I=t.cacheRoot??`flatpak-gjsify-cache`,H=new Map,W=0,q=0;for(let{url:t,integrity:n}of F){let S=parseSri(n);if(!S){W++;continue}if(!Wz.has(S.algorithm)){q++;continue}let C=`${S.algorithm}:${S.hex}`;if(H.has(C))continue;let N={type:`file`,url:t,dest:`${I}/gjsify/tarballs/v1/${S.algorithm}/${S.hex.slice(0,2)}`,"dest-filename":`${S.hex}.tgz`};S.algorithm===`sha512`?N.sha512=S.hex:N.sha256=S.hex,H.set(C,N)}let Y=[...H.values()].sort((t,n)=>t.url<n.url?-1:+(t.url>n.url)),X=xn(n,t.out??`gjsify-sources.json`);mkdirSync(En(X),{recursive:!0}),writeFileSync(X,JSON.stringify(Y,null,2)+`
1062
1062
  `),ge.log(`[gjsify flatpak sources] wrote ${X} — ${Y.length} tarball source(s) from ${C} lockfile (${F.length} locked entr${F.length===1?`y`:`ies`})`+(W?`, ${W} without a usable integrity skipped`:``)+(q?`, ${q} non-sha256/512 skipped`:``)),t.printModule&&ge.error(buildModuleSnippet(t.out??`gjsify-sources.json`,I))}}});function renderWorkflow(t){let n=`[${t.branches.map(t=>JSON.stringify(t)).join(`, `)}]`;return`name: Flatpak
1063
1063
 
1064
1064
  on:
@@ -1087,20 +1087,20 @@ jobs:
1087
1087
  manifest-path: ${t.manifest}
1088
1088
  bundle: ${t.bundle}
1089
1089
  cache-key: ${t.cacheKey}
1090
- `}var Hz,Uz=__esmMin(()=>{_e(),Rd(),Pn(),TI(),hz(),vz(),Sz(),Hz={command:`ci`,description:`Scaffold .github/workflows/flatpak.yml using the flathub-infra container + flatpak-builder@v6 action.`,builder:t=>t.option(`manifest`,{description:`Manifest path the workflow points at (default: <app-id>.json)`,type:`string`,normalize:!0}).option(`bundle`,{description:`Bundle filename produced by the action (default: <app-id>.flatpak)`,type:`string`,normalize:!0}).option(`runtime-image`,{description:"Container image override. Default derived from gjsify.flatpak.runtime + runtimeVersion (e.g. `ghcr.io/flathub-infra/flatpak-github-actions:gnome-50`).",type:`string`}).option(`branches`,{description:`Branches the workflow runs on push for (default: main)`,type:`string`,array:!0}).option(`out`,{description:`Output path`,type:`string`,default:`.github/workflows/flatpak.yml`,normalize:!0}).option(`cache-key`,{description:"Override the action `cache-key` (default: `flatpak-builder-${{ github.sha }}`)",type:`string`}).option(`force`,{description:`Overwrite an existing workflow file`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print resolved fields`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=await new Config().forCommand().catch(()=>({})),C=S.flatpak??{},N=readPackageJson(n),F=C.appId??(looksLikeAppId(N.name)?N.name:void 0);if(!F)throw Error(`gjsify flatpak ci: no app id available. Set gjsify.flatpak.appId in package.json or rename the package to a reverse-DNS id.`);let I=t.manifest??`${F}.json`,H=t.bundle??`${F}.flatpak`,W=pickFlatpakBuildKeys(S.ship?.flatpak,C).values,{runtime:q,runtimeVersion:Y}=resolveRuntime(W,{}),X=t.runtimeImage??C.ciContainer??defaultCiContainer(q,Y),Z=t.branches??C.ciBranches??[`main`],te=t.cacheKey??"flatpak-builder-${{ github.sha }}",ne=xn(n,t.out??`.github/workflows/flatpak.yml`);if(existsSync(ne)&&!t.force){if(readFileSync(ne,`utf-8`)===renderWorkflow({manifest:I,bundle:H,runtimeImage:X,branches:Z,cacheKey:te})){ge.log(`[gjsify flatpak ci] ${ne} already up to date`);return}throw Error(`gjsify flatpak ci: ${ne} exists with different content. Pass --force to overwrite.`)}let re=renderWorkflow({manifest:I,bundle:H,runtimeImage:X,branches:Z,cacheKey:te});mkdirSync(En(ne),{recursive:!0}),writeFileSync(ne,re,`utf-8`),t.verbose&&ge.log(`[gjsify flatpak ci] runtime-image=${X} manifest=${I} bundle=${H}`),ge.log(`[gjsify flatpak ci] wrote ${ne}`)}}});function buildTree(t){let n={name:`#root`,attrs:{},children:[],text:``},S=[n];for(let n of scanXml(t)){let t=S[S.length-1];if(n.kind===`text`)for(let t of S)t.text+=n.text;else if(n.kind===`open`){let C={name:normName(n.name),attrs:n.attributes,children:[],text:``};t.children.push(C),n.selfClosing||S.push(C)}else S.length>1&&S.pop()}return n}function localized(t,n){let S=new Map;for(let C of kids(t,n)){let t=clean(C.text);t!==``&&!S.has(lang(C))&&S.set(lang(C),t)}return S}function parseHex(t){let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(n===null)return null;let S=n[1];S.length===3&&(S=S.replace(/./g,t=>t+t));let C=Number.parseInt(S.slice(0,2),16)/255,N=Number.parseInt(S.slice(2,4),16)/255,F=Number.parseInt(S.slice(4,6),16)/255,I=Math.max(C,N,F),H=Math.min(C,N,F),W=(I+H)/2,q=I-H;return{s:q===0?0:q/(1-Math.abs(2*W-1)),l:W}}function readImageInfo(t){if(t.length>=24&&t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71){let u32=n=>(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0;return{kind:`raster`,width:u32(16),height:u32(20)}}if(t.length>=4&&t[0]===255&&t[1]===216){let n=2;for(;n+9<t.length;){if(t[n]!==255){n++;continue}let S=t[n+1];if(S===255){n++;continue}if(S>=192&&S<=207&&S!==196&&S!==200&&S!==204)return{kind:`raster`,height:t[n+5]<<8|t[n+6],width:t[n+7]<<8|t[n+8]};n+=2+(t[n+2]<<8|t[n+3])}return null}let n=``;for(let S=0;S<Math.min(t.length,1024);S++)n+=String.fromCharCode(t[S]);return/<svg[\s>]/.test(n)?{kind:`svg`}:null}function termPattern(t,n=`iu`){let S=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`).replace(/\s+/g,`\\s+`);return RegExp(`(^|[^\\p{L}\\p{N}])${S}($|[^\\p{L}\\p{N}])`,n)}async function lintMetainfo(t,n={}){let S=[],add=(t,n,C,N,F)=>{S.push({rule:t,severity:n,message:F,location:N,url:`${Wz}#${C}`})},C=child(buildTree(t),`component`);if(C===void 0)return add(`no-component`,`error`,`app-name`,`document`,`no <component> element found`),S;let loc=(t,n)=>n===``?t:`${t}[${n}]`,N=localized(C,`name`),F=localized(C,`summary`);for(let[t,n]of N){let S=loc(`name`,t),C=[...n].length;if(C>=20?add(`name-too-long`,`error`,`not-too-long`,S,`"${n}" is ${C} characters; a name must be shorter than 20`):C>15&&add(`name-long`,`warning`,`not-too-long`,S,`"${n}" is ${C} characters; ideally at most 15`),/\s[-–—:]\s|:\s|\(.+\)/.test(n)||/\b(web browser|editor|client|viewer|player)$/i.test(n)&&n.includes(` `))add(`name-extra-info`,`warning`,`just-the-name`,S,`"${n}" carries a description; keep just the name and put the rest in the summary`);else if(/[.-]/.test(n))add(`name-formatting`,`warning`,`no-weird-formatting`,S,`"${n}" contains a dot or dash; avoid punctuation in names`);else if(/\p{L}/u.test(n)){let t=n.replace(/[^\p{L}]/gu,``);n===n.toLowerCase()?add(`name-formatting`,`warning`,`no-weird-formatting`,S,`"${n}" is all lowercase`):t.length>1&&n===n.toUpperCase()?add(`name-formatting`,`warning`,`no-weird-formatting`,S,`"${n}" is all uppercase (exempt only for an established brand such as VLC)`):!/\s/.test(n)&&/\p{Ll}\p{Lu}/u.test(n)&&add(`name-formatting`,`warning`,`no-weird-formatting`,S,`"${n}" is camel/pascal case`)}}let I=(n.technicalTerms??[...Gz]).map(t=>({term:t,re:termPattern(t)}));for(let[t,n]of F){let S=loc(`summary`,t),C=[...n].length;C>35?add(`summary-too-long`,`error`,`not-too-long-1`,S,`"${n}" is ${C} characters; at most 35 allowed`):(C>25||C<10)&&add(`summary-length`,`warning`,`not-too-long-1`,S,`"${n}" is ${C} characters; ideal is 10 to 25`),/[.。]$/.test(n)&&add(`summary-full-stop`,`warning`,`no-weird-formatting-1`,S,`a summary does not end with a full stop`);let F=n.split(/\s+/).filter(t=>/^\p{L}/u.test(t)),H=F.filter(t=>/^\p{Lu}/u.test(t)).length;F.length>=3&&H/F.length>=.75&&add(`summary-title-case`,`warning`,`no-weird-formatting-1`,S,`use sentence case, not Title Case`);let W=qz[langBase(t===``?`en`:t)],q=n.split(/\s+/)[0]?.toLowerCase();W?.includes(q)&&add(`summary-article`,`warning`,`dont-start-with-an-article`,S,`starts with the article "${q}"; omit it or phrase it with a verb`);let Y=N.get(t)??N.get(``);Y!==void 0&&[...Y].length>=3&&termPattern(Y,`u`).test(n)&&add(`summary-repeats-name`,`warning`,`dont-repeat-the-name`,S,`repeats the app name "${Y}"`);let X=I.find(({re:t})=>t.test(n));X!==void 0&&add(`summary-technical`,`warning`,`not-technical`,S,`mentions "${X.term}"; say what the app does for people, not how it is built`)}let H=kids(C,`description`).find(t=>lang(t)===``)??child(C,`description`);if(H!==void 0){let t=F.get(``)??``,n=kids(H,`p`).filter(t=>lang(t)===``).map(t=>clean(t.text)),S=n.join(` `);t!==``&&n.length>0&&n[0].replace(/[.!]$/,``).toLowerCase()===t.toLowerCase()&&add(`description-repeats-summary`,`warning`,`dont-repeat-the-summary`,`description`,`the first paragraph repeats the summary`),t!==``&&[...S].length<Math.max(80,3*[...t].length)&&add(`description-short`,`warning`,`not-too-short`,`description`,`${[...S].length} characters; it should be substantially longer than the summary`);for(let t of[...kids(H,`ul`),...kids(H,`ol`)]){let n=kids(t,`li`).filter(t=>lang(t)===``).length;n>10&&add(`description-long-list`,`warning`,`no-super-long-lists`,`description`,`a list with ${n} items; group them or use paragraphs (max 10)`)}}let W=kids(child(C,`branding`),`color`).filter(t=>t.attrs.type===`primary`),q=W.find(t=>t.attrs.scheme_preference===`light`),Y=W.find(t=>t.attrs.scheme_preference===`dark`);if(q===void 0||Y===void 0)add(`branding-missing`,`warning`,`has-primary-brand-colors`,`branding`,`set two primary brand colors, scheme_preference="light" and "dark"`);else{let t=clean(q.text).toLowerCase(),n=clean(Y.text).toLowerCase();t===n&&add(`branding-identical`,`warning`,`good-brand-colors`,`branding`,`light and dark primary colors are the same`);let S=parseHex(t),C=parseHex(n);for(let[N,F,I]of[[`light`,S,t],[`dark`,C,n]])F!==null&&(F.s<.15||F.l>.93||F.l<.07)&&add(`branding-dull`,`warning`,`good-brand-colors`,`branding/${N}`,`${I} is near white, black or gray; brand colors should be colorful`);S!==null&&C!==null&&t!==n&&C.l>=S.l&&add(`branding-dark-not-darker`,`warning`,`good-brand-colors`,`branding/dark`,`the dark variant should be darker than the light one`)}if(n.probeImage!==void 0)for(let t of n.iconRefs??[]){let S=await n.probeImage(t);if(S!==null){S.kind===`raster`&&(S.width===S.height?S.width<256&&add(`icon-too-small`,`error`,`icon-size`,`icon`,`${t} is ${S.width}×${S.height}; use SVG or at least 256×256`):add(`icon-not-square`,`error`,`icon-size`,`icon`,`${t} is ${S.width}×${S.height}; the icon has to be square`));break}}let X=kids(child(C,`screenshots`),`screenshot`);if(X.length===0)add(`screenshot-missing`,`warning`,`at-least-one-screenshot`,`screenshots`,`at least one screenshot is expected`);else{let englishTag=t=>t===``||langBase(t)===`en`,isEnglish=t=>{let n=kids(t,`image`).map(lang);return englishTag(lang(t))&&(n.length===0||n.some(englishTag))};X.some(isEnglish)||add(`screenshot-no-english`,`warning`,`at-least-one-screenshot`,`screenshots`,`no screenshot without xml:lang (or in English)`),X[0].attrs.type!=="default"&&add(`screenshot-default-not-first`,`warning`,`at-least-one-screenshot`,`screenshot[1]`,`the first screenshot should be type="default" — it is the one users see first`);for(let t=0;t<X.length;t++){let S=X[t],C=`screenshot[${t+1}]`,N=kids(S,`caption`);N.length===0&&add(`screenshot-caption-missing`,`warning`,`image-captions`,C,`no <caption>`);for(let t of N){let n=clean(t.text),S=`${C}/${loc(`caption`,lang(t))}`;/[.。]$/.test(n)&&add(`caption-full-stop`,`warning`,`image-captions`,S,`a caption does not end with a full stop`),/^\d/.test(n)&&add(`caption-starts-with-number`,`warning`,`image-captions`,S,`a caption does not start with a number`),/[.!?]\s+\p{Lu}/u.test(n)&&add(`caption-multiple-sentences`,`warning`,`image-captions`,S,`a caption is one sentence`)}if(n.probeImage!==void 0){let t=kids(S,`image`).find(t=>(t.attrs.type??`source`)===`source`),N=t===void 0?``:clean(t.text),F=N===``?null:await n.probeImage(N);F?.kind===`raster`&&(F.width>2e3||F.height>1400)&&add(`screenshot-too-large`,`warning`,`reasonable-window-size`,C,`${F.width}×${F.height}; keep the window at most 1000×700 (2000×1400 on HiDPI)`)}}}for(let t of kids(child(C,`releases`),`release`)){let n=`release ${t.attrs.version??`?`}`,S=child(t,`description`),C=S===void 0?``:clean(S.text);if(C===``){add(`release-notes-missing`,`warning`,`release-notes-for-every-release`,n,`no release notes`);continue}Kz.some(t=>t.test(C.replace(/[.!]+$/,``)))?add(`release-notes-generic`,`warning`,`no-bug-fixes-and-performance-improvements`,n,`"${C}" says nothing about what changed`):([...C].length>600||kids(child(S,`ul`),`li`).length>10)&&add(`release-notes-long`,`warning`,`short-but-informative`,n,`release notes are long; summarise what changed for users`)}return S}function summarizeFindings(t,n){let S=0,C=0;for(let N of t)N.severity===`error`||n?S++:C++;return{errors:S,warnings:C}}function formatFinding(t,n){return`${(n?`error`:t.severity).padEnd(7)} ${t.rule} ${t.location}: ${t.message}\n ${t.url}`}var Wz,Gz,Kz,qz,normName,child,kids,clean,lang,langBase,Jz=__esmMin(()=>{He(),Wz=`https://docs.flathub.org/docs/for-app-authors/metainfo-guidelines/quality-guidelines`,Gz=`GTK.GTK3.GTK4.Qt.Qt5.Qt6.libadwaita.Electron.Rust.Python.JavaScript.TypeScript.GJS.Flatpak.written in.open source.open-source.free software.FOSS.app.application.tool.client.wrapper.App.Anwendung.Werkzeug`.split(`.`),Kz=[/^(minor |various |general |misc(ellaneous)? )?bug ?fix(es)?( (and|&) (minor )?(performance )?(improvements?|fixes|tweaks))?$/i,/^(minor |various |general )?(performance )?improvements?( (and|&) (bug ?fix(es)?|fixes))?$/i,/^bug ?fix(es)?,? (and )?(performance|stability) improvements?$/i,/^(performance|stability) (improvements?|fixes)( (and|&) bug ?fix(es)?)?$/i,/^(fehlerbehebungen?|fehlerkorrekturen?|verbesserungen)( (und|&) (fehlerbehebungen?|verbesserungen|leistungsverbesserungen))?$/i,/^(kleinere )?(fehlerbehebungen|verbesserungen)$/i],qz={en:[`a`,`an`,`the`],de:[`ein`,`eine`,`einen`,`einem`,`einer`,`der`,`die`,`das`,`den`,`dem`]},normName=t=>t.startsWith(`_`)?t.slice(1):t,child=(t,n)=>t?.children.find(t=>t.name===n),kids=(t,n)=>t?.children.filter(t=>t.name===n)??[],clean=t=>t.replace(/\s+/g,` `).trim(),lang=t=>t.attrs[`xml:lang`]??``,langBase=t=>t.split(/[_\-.@]/)[0].toLowerCase()});async function runQuality(t,n,S){let C=En(t),probeImage=async t=>{if(/^https?:\/\//.test(t)){if(!S.qualityNetwork)return null;try{let n=await fetch(t);return n.ok?readImageInfo(new Uint8Array(await n.arrayBuffer())):null}catch{return null}}let n=xn(C,t);return existsSync(n)?readImageInfo(new Uint8Array(readFileSync(n))):null},N=n??``,F=N?[`icons/hicolor/scalable/apps/${N}.svg`,`icons/${N}.svg`,`${N}.svg`,`${N}.png`,`../data/icons/hicolor/scalable/apps/${N}.svg`]:[],I=await lintMetainfo(readFileSync(t,`utf-8`),{probeImage,iconRefs:F}),H=S.strict===!0,{errors:W,warnings:q}=summarizeFindings(I,H);if(S.json)ge.log(JSON.stringify({file:t,errors:W,warnings:q,findings:I.map(t=>({...t,severity:H?`error`:t.severity}))},null,2));else{for(let t of I)ge.log(formatFinding(t,H));ge.log(`[gjsify flatpak check] ${W===0?`OK`:`FAIL`}: quality ${t} — ${W} error(s), ${q} warning(s)`)}return W===0}function resolveAppId(t,n,S){if(n.appId)return n.appId;try{let t=readPackageJson(S);if(looksLikeAppId(t.name))return t.name}catch{}if(t)return t.replace(/\.json$/,``)}function resolveManifestPath(t,n,S){if(t)return xn(S,t);if(n)return xn(S,`${n}.json`);let C=readdirSync(S).filter(t=>t.endsWith(`.json`)&&!t.startsWith(`package`));if(C.length===1)return xn(S,C[0]);throw Error(`gjsify flatpak check: no manifest path given and could not auto-detect. Pass the manifest as a positional argument.`)}async function runLinter(t,n,S){let C;try{C=await spawnToCompletion(t,n,{completion:`return`,stdio:S?`inherit`:`capture`})}catch(n){let S=n;return S.code===`ENOENT`?ge.error(`[gjsify flatpak check] ${t} not found in PATH.\nInstall via:\n flatpak install -y flathub org.flatpak.Builder\n alias ${t}="flatpak run --command=${t} org.flatpak.Builder"`):ge.error(`[gjsify flatpak check] ${t} failed to spawn: ${S.message}`),!1}let N=C.code===0;return ge.log(`[gjsify flatpak check] ${N?`OK`:`FAIL`}: ${t} ${n.join(` `)}`),!N&&!S&&(C.stdout?.trim()&&ge.log(C.stdout.trimEnd()),C.stderr?.trim()&&ge.error(C.stderr.trimEnd())),N}var Yz,Xz=__esmMin(()=>{_e(),Rd(),Pn(),V_(),hz(),TI(),Jz(),Yz={command:`check [manifest]`,description:`Run Flathub pre-submission linters: appstreamcli validate + flatpak-builder-lint.`,builder:t=>t.positional(`manifest`,{description:"Path to the Flatpak manifest. Auto-detects `<app-id>.json` if omitted.",type:`string`,normalize:!0}).option(`repo`,{description:"Built ostree-repo path. If given, also runs `flatpak-builder-lint repo`.",type:`string`,normalize:!0}).option(`metainfo`,{description:"MetaInfo XML path. Default: `data/<app-id>.metainfo.xml.in`.",type:`string`,normalize:!0}).option(`appstream`,{description:"Run `appstreamcli validate --strict` (default: true).",type:`boolean`,default:!0}).option(`quality`,{description:`Run Flathub's quality guidelines (name, summary, branding, screenshots, release notes) on the MetaInfo (default: true).`,type:`boolean`,default:!0}).option(`strict`,{description:`Treat quality warnings as errors.`,type:`boolean`,default:!1}).option(`json`,{description:`Print the quality findings as JSON (and nothing else on stdout).`,type:`boolean`,default:!1}).option(`quality-network`,{description:`Let the quality check fetch http(s) screenshot/icon URLs to measure their size.`,type:`boolean`,default:!1}).option(`builder-lint`,{description:"Run `flatpak-builder-lint manifest` (default: true).",type:`boolean`,default:!0}).option(`verbose`,{description:`Stream linter stdout/stderr verbatim.`,type:`boolean`,default:!1}),handler:async t=>{let n=(await new Config().forCommand().catch(()=>({}))).flatpak??{},S=process.cwd(),C=resolveAppId(t.manifest,n,S),N=resolveManifestPath(t.manifest,C,S),F=xn(S,t.metainfo??`data/${C??`unknown`}.metainfo.xml.in`),I=0;if(t.appstream!==!1&&(existsSync(F)?await runLinter(`appstreamcli`,[`validate`,`--strict`,F],t.verbose??!1)||I++:ge.warn(`[gjsify flatpak check] skipping appstreamcli — ${F} not found`)),t.quality!==!1&&(existsSync(F)?await runQuality(F,C,t)||I++:ge.warn(`[gjsify flatpak check] skipping quality check — ${F} not found`)),t.builderLint!==!1&&!t.json){if(!existsSync(N))return ge.error(`[gjsify flatpak check] manifest not found: ${N}`),process.exit(1);await runLinter(`flatpak-builder-lint`,[`manifest`,N],t.verbose??!1)||I++,t.repo&&(await runLinter(`flatpak-builder-lint`,[`repo`,xn(S,t.repo)],t.verbose??!1)||I++)}if(I>0)return ge.error(`\n[gjsify flatpak check] ${I} check(s) failed.`),process.exit(1);ge.log(`[gjsify flatpak check] all checks passed.`)}}});async function readSourceListAtTag(t,n,S,C){let N;try{let{stdout:C}=await Zz(`git`,[`show`,`${n}:${S}`],{cwd:t,maxBuffer:64*1024*1024});N=C}catch(N){return await assertGitMeantAbsent(t,n,S,N),C&&ge.log(`[gjsify flatpak sync-flathub] ${S} not present at ${n} — skipping`),null}if(N.trim()===``)return C&&ge.log(`[gjsify flatpak sync-flathub] ${S} is empty at ${n} — skipping`),null;let F;try{F=JSON.parse(N)}catch(t){throw Error(`[gjsify flatpak sync-flathub] ${S} at ${n} is not JSON: `+(t instanceof Error?t.message:String(t)))}if(!Array.isArray(F)||F.length===0)throw Error(`[gjsify flatpak sync-flathub] ${S} at ${n} is not a non-empty array of flatpak sources`);return N}async function assertGitMeantAbsent(t,n,S,C){if(typeof C?.code!=`number`)throw Error(`[gjsify flatpak sync-flathub] could not run \`git show ${n}:${S}\` — `+(C instanceof Error?C.message:String(C)));if(!await Zz(`git`,[`rev-parse`,`--verify`,`--quiet`,`${n}^{commit}`],{cwd:t}).then(({stdout:t})=>t.trim()).catch(()=>``))throw Error(`[gjsify flatpak sync-flathub] ${n} does not resolve in ${t}, so whether it carries ${S} is unanswered. Run \`git fetch --tags\`, pass --version <an existing tag>, or run from the app checkout.`)}async function resolveLatestTag$1(t,n){try{let{stdout:S}=await Zz(`git`,[`describe`,`--tags`,`--abbrev=0`],{cwd:t});return n&&ge.log(`[gjsify flatpak sync-flathub] resolved latest tag → ${S.trim()}`),S.trim()||null}catch{return null}}async function resolveCommitForTag(t,n,S){try{let{stdout:C}=await Zz(`git`,[`rev-list`,`-n`,`1`,n],{cwd:t}),N=C.trim();if(!N)throw Error(`empty rev-list output`);return S&&ge.log(`[gjsify flatpak sync-flathub] resolved ${n} → ${N}`),N}catch(t){throw Error(`[gjsify flatpak sync-flathub] tag ${n} not found locally. Run \`git fetch --tags\` or pass --commit <sha>.\n underlying error: ${t instanceof Error?t.message:String(t)}`)}}function normaliseBranchSegment(t){return t.replace(/^v/,``).replace(/[^A-Za-z0-9._-]/g,`-`)}function flathubCacheRoot(){return wn(process.env.XDG_CACHE_HOME||wn(homedir(),`.cache`),`gjsify`,`flathub-sync`)}async function ensureClone(t,n,S){if(existsSync(wn(t,`.git`))){S&&ge.log(`[gjsify flatpak sync-flathub] reusing clone at ${t}`),await gitInRepo(t,[`fetch`,`origin`],S);let n=await detectDefaultBranch(t,S);await gitInRepo(t,[`checkout`,n],S),await gitInRepo(t,[`reset`,`--hard`,`origin/${n}`],S);return}mkdirSync(xn(t,`..`),{recursive:!0});let C=`https://github.com/${n}.git`;S&&ge.log(`[gjsify flatpak sync-flathub] git clone ${C} ${t}`);try{await Zz(`git`,[`clone`,C,t])}catch(t){throw t?.code===`ENOENT`?Error("[gjsify flatpak sync-flathub] `git` not found. Install git from your distro (Fedora: `dnf install git`, Debian: `apt install git`)."):t}}async function detectDefaultBranch(t,n){try{let{stdout:S}=await Zz(`git`,[`remote`,`show`,`origin`],{cwd:t}),C=S.match(/HEAD branch: (\S+)/);if(C&&C[1]&&C[1]!==`(unknown)`)return n&&ge.log(`[gjsify flatpak sync-flathub] default branch → ${C[1]}`),C[1]}catch{}return`master`}async function gitInRepo(t,n,S){S&&ge.log(`[gjsify flatpak sync-flathub] git ${n.join(` `)} (in ${t})`);let C=await spawnToCompletion(`git`,n,{completion:`return`,cwd:t,notFound:()=>Error("[gjsify flatpak sync-flathub] `git` not found. Install it from your distro.")});if(C.code!==0)throw Error(`git ${n[0]} exited ${describeExit(C)}`)}async function ghCreate(t,n,S,C,N,F){let I=[`pr`,`create`,`--repo`,n,`--head`,S,`--title`,`Update to ${C}`,`--body`,N];F&&ge.log(`[gjsify flatpak sync-flathub] gh ${I.join(` `)} (in ${t})`);let H=await spawnToCompletion(`gh`,I,{completion:`return`,cwd:t,notFound:()=>Error("[gjsify flatpak sync-flathub] `gh` (GitHub CLI) not found. Install via `dnf install gh` (Fedora), `apt install gh` (Debian/Ubuntu), or `flatpak install -y flathub com.github.cli`.")});if(H.code!==0)throw Error(`gh pr create exited ${describeExit(H)}`)}function editManifest(t,n){let S=JSON.parse(t),C=S.modules??[];if(C.length===0)throw Error(`[gjsify flatpak sync-flathub] manifest has no modules`);let N=C[0].sources??[];if(N.length===0)throw Error(`[gjsify flatpak sync-flathub] modules[0] has no sources`);let isObject=t=>typeof t==`object`,F=n.sourceIndex??N.findIndex(t=>isObject(t)&&t.type===`git`);if(F<0||F>=N.length)throw Error(`[gjsify flatpak sync-flathub] no git source found in modules[0].sources (use --source-index <n>)`);let I=N[F];if(!isObject(I)||I.type!==`git`){let t=isObject(I)?`type is "${I.type}"`:`is the file reference "${I}"`;throw Error(`[gjsify flatpak sync-flathub] modules[0].sources[${F}] ${t}, expected a git source`)}let H=I;H.tag=n.tag,H.commit=n.commit,H[`x-checker-data`]||={type:`git`,"tag-pattern":`^v(\\d+\\.\\d+\\.\\d+)$`,"version-scheme":`semantic`},n.sourcesFile&&!namesFile(N,n.sourcesFile)&&N.push(n.sourcesFile);let W=detectIndent$1(t);return JSON.stringify(S,null,W)+(t.endsWith(`
1090
+ `}var qz,Jz=__esmMin(()=>{_e(),Rd(),Pn(),AI(),bz(),Cz(),Dz(),qz={command:`ci`,description:`Scaffold .github/workflows/flatpak.yml using the flathub-infra container + flatpak-builder@v6 action.`,builder:t=>t.option(`manifest`,{description:`Manifest path the workflow points at (default: <app-id>.json)`,type:`string`,normalize:!0}).option(`bundle`,{description:`Bundle filename produced by the action (default: <app-id>.flatpak)`,type:`string`,normalize:!0}).option(`runtime-image`,{description:"Container image override. Default derived from gjsify.flatpak.runtime + runtimeVersion (e.g. `ghcr.io/flathub-infra/flatpak-github-actions:gnome-50`).",type:`string`}).option(`branches`,{description:`Branches the workflow runs on push for (default: main)`,type:`string`,array:!0}).option(`out`,{description:`Output path`,type:`string`,default:`.github/workflows/flatpak.yml`,normalize:!0}).option(`cache-key`,{description:"Override the action `cache-key` (default: `flatpak-builder-${{ github.sha }}`)",type:`string`}).option(`force`,{description:`Overwrite an existing workflow file`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print resolved fields`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=await new Config().forCommand().catch(()=>({})),C=S.flatpak??{},N=readPackageJson(n),F=C.appId??(looksLikeAppId(N.name)?N.name:void 0);if(!F)throw Error(`gjsify flatpak ci: no app id available. Set gjsify.flatpak.appId in package.json or rename the package to a reverse-DNS id.`);let I=t.manifest??`${F}.json`,H=t.bundle??`${F}.flatpak`,W=pickFlatpakBuildKeys(S.ship?.flatpak,C).values,{runtime:q,runtimeVersion:Y}=resolveRuntime(W,{}),X=t.runtimeImage??C.ciContainer??defaultCiContainer(q,Y),Z=t.branches??C.ciBranches??[`main`],te=t.cacheKey??"flatpak-builder-${{ github.sha }}",ne=xn(n,t.out??`.github/workflows/flatpak.yml`);if(existsSync(ne)&&!t.force){if(readFileSync(ne,`utf-8`)===renderWorkflow({manifest:I,bundle:H,runtimeImage:X,branches:Z,cacheKey:te})){ge.log(`[gjsify flatpak ci] ${ne} already up to date`);return}throw Error(`gjsify flatpak ci: ${ne} exists with different content. Pass --force to overwrite.`)}let re=renderWorkflow({manifest:I,bundle:H,runtimeImage:X,branches:Z,cacheKey:te});mkdirSync(En(ne),{recursive:!0}),writeFileSync(ne,re,`utf-8`),t.verbose&&ge.log(`[gjsify flatpak ci] runtime-image=${X} manifest=${I} bundle=${H}`),ge.log(`[gjsify flatpak ci] wrote ${ne}`)}}});function buildTree(t){let n={name:`#root`,attrs:{},children:[],text:``},S=[n];for(let n of scanXml(t)){let t=S[S.length-1];if(n.kind===`text`)for(let t of S)t.text+=n.text;else if(n.kind===`open`){let C={name:normName(n.name),attrs:n.attributes,children:[],text:``};t.children.push(C),n.selfClosing||S.push(C)}else S.length>1&&S.pop()}return n}function localized(t,n){let S=new Map;for(let C of kids(t,n)){let t=clean(C.text);t!==``&&!S.has(lang(C))&&S.set(lang(C),t)}return S}function parseHex(t){let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());if(n===null)return null;let S=n[1];S.length===3&&(S=S.replace(/./g,t=>t+t));let C=Number.parseInt(S.slice(0,2),16)/255,N=Number.parseInt(S.slice(2,4),16)/255,F=Number.parseInt(S.slice(4,6),16)/255,I=Math.max(C,N,F),H=Math.min(C,N,F),W=(I+H)/2,q=I-H;return{s:q===0?0:q/(1-Math.abs(2*W-1)),l:W}}function readImageInfo(t){if(t.length>=24&&t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71){let u32=n=>(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0;return{kind:`raster`,width:u32(16),height:u32(20)}}if(t.length>=4&&t[0]===255&&t[1]===216){let n=2;for(;n+9<t.length;){if(t[n]!==255){n++;continue}let S=t[n+1];if(S===255){n++;continue}if(S>=192&&S<=207&&S!==196&&S!==200&&S!==204)return{kind:`raster`,height:t[n+5]<<8|t[n+6],width:t[n+7]<<8|t[n+8]};n+=2+(t[n+2]<<8|t[n+3])}return null}let n=``;for(let S=0;S<Math.min(t.length,1024);S++)n+=String.fromCharCode(t[S]);return/<svg[\s>]/.test(n)?{kind:`svg`}:null}function termPattern(t,n=`iu`){let S=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`).replace(/\s+/g,`\\s+`);return RegExp(`(^|[^\\p{L}\\p{N}])${S}($|[^\\p{L}\\p{N}])`,n)}async function lintMetainfo(t,n={}){let S=[],add=(t,n,C,N,F)=>{S.push({rule:t,severity:n,message:F,location:N,url:`${Yz}#${C}`})},C=child(buildTree(t),`component`);if(C===void 0)return add(`no-component`,`error`,`app-name`,`document`,`no <component> element found`),S;let loc=(t,n)=>n===``?t:`${t}[${n}]`,N=localized(C,`name`),F=localized(C,`summary`);for(let[t,n]of N){let S=loc(`name`,t),C=[...n].length;if(C>=20?add(`name-too-long`,`error`,`not-too-long`,S,`"${n}" is ${C} characters; a name must be shorter than 20`):C>15&&add(`name-long`,`warning`,`not-too-long`,S,`"${n}" is ${C} characters; ideally at most 15`),/\s[-–—:]\s|:\s|\(.+\)/.test(n)||/\b(web browser|editor|client|viewer|player)$/i.test(n)&&n.includes(` `))add(`name-extra-info`,`warning`,`just-the-name`,S,`"${n}" carries a description; keep just the name and put the rest in the summary`);else if(/[.-]/.test(n))add(`name-formatting`,`warning`,`no-weird-formatting`,S,`"${n}" contains a dot or dash; avoid punctuation in names`);else if(/\p{L}/u.test(n)){let t=n.replace(/[^\p{L}]/gu,``);n===n.toLowerCase()?add(`name-formatting`,`warning`,`no-weird-formatting`,S,`"${n}" is all lowercase`):t.length>1&&n===n.toUpperCase()?add(`name-formatting`,`warning`,`no-weird-formatting`,S,`"${n}" is all uppercase (exempt only for an established brand such as VLC)`):!/\s/.test(n)&&/\p{Ll}\p{Lu}/u.test(n)&&add(`name-formatting`,`warning`,`no-weird-formatting`,S,`"${n}" is camel/pascal case`)}}let I=(n.technicalTerms??[...Xz]).map(t=>({term:t,re:termPattern(t)}));for(let[t,n]of F){let S=loc(`summary`,t),C=[...n].length;C>35?add(`summary-too-long`,`error`,`not-too-long-1`,S,`"${n}" is ${C} characters; at most 35 allowed`):(C>25||C<10)&&add(`summary-length`,`warning`,`not-too-long-1`,S,`"${n}" is ${C} characters; ideal is 10 to 25`),/[.。]$/.test(n)&&add(`summary-full-stop`,`warning`,`no-weird-formatting-1`,S,`a summary does not end with a full stop`);let F=n.split(/\s+/).filter(t=>/^\p{L}/u.test(t)),H=F.filter(t=>/^\p{Lu}/u.test(t)).length;F.length>=3&&H/F.length>=.75&&add(`summary-title-case`,`warning`,`no-weird-formatting-1`,S,`use sentence case, not Title Case`);let W=Qz[langBase(t===``?`en`:t)],q=n.split(/\s+/)[0]?.toLowerCase();W?.includes(q)&&add(`summary-article`,`warning`,`dont-start-with-an-article`,S,`starts with the article "${q}"; omit it or phrase it with a verb`);let Y=N.get(t)??N.get(``);Y!==void 0&&[...Y].length>=3&&termPattern(Y,`u`).test(n)&&add(`summary-repeats-name`,`warning`,`dont-repeat-the-name`,S,`repeats the app name "${Y}"`);let X=I.find(({re:t})=>t.test(n));X!==void 0&&add(`summary-technical`,`warning`,`not-technical`,S,`mentions "${X.term}"; say what the app does for people, not how it is built`)}let H=kids(C,`description`).find(t=>lang(t)===``)??child(C,`description`);if(H!==void 0){let t=F.get(``)??``,n=kids(H,`p`).filter(t=>lang(t)===``).map(t=>clean(t.text)),S=n.join(` `);t!==``&&n.length>0&&n[0].replace(/[.!]$/,``).toLowerCase()===t.toLowerCase()&&add(`description-repeats-summary`,`warning`,`dont-repeat-the-summary`,`description`,`the first paragraph repeats the summary`),t!==``&&[...S].length<Math.max(80,3*[...t].length)&&add(`description-short`,`warning`,`not-too-short`,`description`,`${[...S].length} characters; it should be substantially longer than the summary`);for(let t of[...kids(H,`ul`),...kids(H,`ol`)]){let n=kids(t,`li`).filter(t=>lang(t)===``).length;n>10&&add(`description-long-list`,`warning`,`no-super-long-lists`,`description`,`a list with ${n} items; group them or use paragraphs (max 10)`)}}let W=kids(child(C,`branding`),`color`).filter(t=>t.attrs.type===`primary`),q=W.find(t=>t.attrs.scheme_preference===`light`),Y=W.find(t=>t.attrs.scheme_preference===`dark`);if(q===void 0||Y===void 0)add(`branding-missing`,`warning`,`has-primary-brand-colors`,`branding`,`set two primary brand colors, scheme_preference="light" and "dark"`);else{let t=clean(q.text).toLowerCase(),n=clean(Y.text).toLowerCase();t===n&&add(`branding-identical`,`warning`,`good-brand-colors`,`branding`,`light and dark primary colors are the same`);let S=parseHex(t),C=parseHex(n);for(let[N,F,I]of[[`light`,S,t],[`dark`,C,n]])F!==null&&(F.s<.15||F.l>.93||F.l<.07)&&add(`branding-dull`,`warning`,`good-brand-colors`,`branding/${N}`,`${I} is near white, black or gray; brand colors should be colorful`);S!==null&&C!==null&&t!==n&&C.l>=S.l&&add(`branding-dark-not-darker`,`warning`,`good-brand-colors`,`branding/dark`,`the dark variant should be darker than the light one`)}if(n.probeImage!==void 0)for(let t of n.iconRefs??[]){let S=await n.probeImage(t);if(S!==null){S.kind===`raster`&&(S.width===S.height?S.width<256&&add(`icon-too-small`,`error`,`icon-size`,`icon`,`${t} is ${S.width}×${S.height}; use SVG or at least 256×256`):add(`icon-not-square`,`error`,`icon-size`,`icon`,`${t} is ${S.width}×${S.height}; the icon has to be square`));break}}let X=kids(child(C,`screenshots`),`screenshot`);if(X.length===0)add(`screenshot-missing`,`warning`,`at-least-one-screenshot`,`screenshots`,`at least one screenshot is expected`);else{let englishTag=t=>t===``||langBase(t)===`en`,isEnglish=t=>{let n=kids(t,`image`).map(lang);return englishTag(lang(t))&&(n.length===0||n.some(englishTag))};X.some(isEnglish)||add(`screenshot-no-english`,`warning`,`at-least-one-screenshot`,`screenshots`,`no screenshot without xml:lang (or in English)`),X[0].attrs.type!=="default"&&add(`screenshot-default-not-first`,`warning`,`at-least-one-screenshot`,`screenshot[1]`,`the first screenshot should be type="default" — it is the one users see first`);for(let t=0;t<X.length;t++){let S=X[t],C=`screenshot[${t+1}]`,N=kids(S,`caption`);N.length===0&&add(`screenshot-caption-missing`,`warning`,`image-captions`,C,`no <caption>`);for(let t of N){let n=clean(t.text),S=`${C}/${loc(`caption`,lang(t))}`;/[.。]$/.test(n)&&add(`caption-full-stop`,`warning`,`image-captions`,S,`a caption does not end with a full stop`),/^\d/.test(n)&&add(`caption-starts-with-number`,`warning`,`image-captions`,S,`a caption does not start with a number`),/[.!?]\s+\p{Lu}/u.test(n)&&add(`caption-multiple-sentences`,`warning`,`image-captions`,S,`a caption is one sentence`)}if(n.probeImage!==void 0){let t=kids(S,`image`).find(t=>(t.attrs.type??`source`)===`source`),N=t===void 0?``:clean(t.text),F=N===``?null:await n.probeImage(N);F?.kind===`raster`&&(F.width>2e3||F.height>1400)&&add(`screenshot-too-large`,`warning`,`reasonable-window-size`,C,`${F.width}×${F.height}; keep the window at most 1000×700 (2000×1400 on HiDPI)`)}}}for(let t of kids(child(C,`releases`),`release`)){let n=`release ${t.attrs.version??`?`}`,S=child(t,`description`),C=S===void 0?``:clean(S.text);if(C===``){add(`release-notes-missing`,`warning`,`release-notes-for-every-release`,n,`no release notes`);continue}Zz.some(t=>t.test(C.replace(/[.!]+$/,``)))?add(`release-notes-generic`,`warning`,`no-bug-fixes-and-performance-improvements`,n,`"${C}" says nothing about what changed`):([...C].length>600||kids(child(S,`ul`),`li`).length>10)&&add(`release-notes-long`,`warning`,`short-but-informative`,n,`release notes are long; summarise what changed for users`)}return S}function summarizeFindings(t,n){let S=0,C=0;for(let N of t)N.severity===`error`||n?S++:C++;return{errors:S,warnings:C}}function formatFinding(t,n){return`${(n?`error`:t.severity).padEnd(7)} ${t.rule} ${t.location}: ${t.message}\n ${t.url}`}var Yz,Xz,Zz,Qz,normName,child,kids,clean,lang,langBase,$z=__esmMin(()=>{He(),Yz=`https://docs.flathub.org/docs/for-app-authors/metainfo-guidelines/quality-guidelines`,Xz=`GTK.GTK3.GTK4.Qt.Qt5.Qt6.libadwaita.Electron.Rust.Python.JavaScript.TypeScript.GJS.Flatpak.written in.open source.open-source.free software.FOSS.app.application.tool.client.wrapper.App.Anwendung.Werkzeug`.split(`.`),Zz=[/^(minor |various |general |misc(ellaneous)? )?bug ?fix(es)?( (and|&) (minor )?(performance )?(improvements?|fixes|tweaks))?$/i,/^(minor |various |general )?(performance )?improvements?( (and|&) (bug ?fix(es)?|fixes))?$/i,/^bug ?fix(es)?,? (and )?(performance|stability) improvements?$/i,/^(performance|stability) (improvements?|fixes)( (and|&) bug ?fix(es)?)?$/i,/^(fehlerbehebungen?|fehlerkorrekturen?|verbesserungen)( (und|&) (fehlerbehebungen?|verbesserungen|leistungsverbesserungen))?$/i,/^(kleinere )?(fehlerbehebungen|verbesserungen)$/i],Qz={en:[`a`,`an`,`the`],de:[`ein`,`eine`,`einen`,`einem`,`einer`,`der`,`die`,`das`,`den`,`dem`]},normName=t=>t.startsWith(`_`)?t.slice(1):t,child=(t,n)=>t?.children.find(t=>t.name===n),kids=(t,n)=>t?.children.filter(t=>t.name===n)??[],clean=t=>t.replace(/\s+/g,` `).trim(),lang=t=>t.attrs[`xml:lang`]??``,langBase=t=>t.split(/[_\-.@]/)[0].toLowerCase()});async function runQuality(t,n,S){let C=En(t),probeImage=async t=>{if(/^https?:\/\//.test(t)){if(!S.qualityNetwork)return null;try{let n=await fetch(t);return n.ok?readImageInfo(new Uint8Array(await n.arrayBuffer())):null}catch{return null}}let n=xn(C,t);return existsSync(n)?readImageInfo(new Uint8Array(readFileSync(n))):null},N=n??``,F=N?[`icons/hicolor/scalable/apps/${N}.svg`,`icons/${N}.svg`,`${N}.svg`,`${N}.png`,`../data/icons/hicolor/scalable/apps/${N}.svg`]:[],I=await lintMetainfo(readFileSync(t,`utf-8`),{probeImage,iconRefs:F}),H=S.strict===!0,{errors:W,warnings:q}=summarizeFindings(I,H);if(S.json)ge.log(JSON.stringify({file:t,errors:W,warnings:q,findings:I.map(t=>({...t,severity:H?`error`:t.severity}))},null,2));else{for(let t of I)ge.log(formatFinding(t,H));ge.log(`[gjsify flatpak check] ${W===0?`OK`:`FAIL`}: quality ${t} — ${W} error(s), ${q} warning(s)`)}return W===0}function resolveAppId(t,n,S){if(n.appId)return n.appId;try{let t=readPackageJson(S);if(looksLikeAppId(t.name))return t.name}catch{}if(t)return t.replace(/\.json$/,``)}function resolveManifestPath(t,n,S){if(t)return xn(S,t);if(n)return xn(S,`${n}.json`);let C=readdirSync(S).filter(t=>t.endsWith(`.json`)&&!t.startsWith(`package`));if(C.length===1)return xn(S,C[0]);throw Error(`gjsify flatpak check: no manifest path given and could not auto-detect. Pass the manifest as a positional argument.`)}async function runLinter(t,n,S){let C;try{C=await spawnToCompletion(t,n,{completion:`return`,stdio:S?`inherit`:`capture`})}catch(n){let S=n;return S.code===`ENOENT`?ge.error(`[gjsify flatpak check] ${t} not found in PATH.\nInstall via:\n flatpak install -y flathub org.flatpak.Builder\n alias ${t}="flatpak run --command=${t} org.flatpak.Builder"`):ge.error(`[gjsify flatpak check] ${t} failed to spawn: ${S.message}`),!1}let N=C.code===0;return ge.log(`[gjsify flatpak check] ${N?`OK`:`FAIL`}: ${t} ${n.join(` `)}`),!N&&!S&&(C.stdout?.trim()&&ge.log(C.stdout.trimEnd()),C.stderr?.trim()&&ge.error(C.stderr.trimEnd())),N}var eB,tB=__esmMin(()=>{_e(),Rd(),Pn(),V_(),bz(),AI(),$z(),eB={command:`check [manifest]`,description:`Run Flathub pre-submission linters: appstreamcli validate + flatpak-builder-lint.`,builder:t=>t.positional(`manifest`,{description:"Path to the Flatpak manifest. Auto-detects `<app-id>.json` if omitted.",type:`string`,normalize:!0}).option(`repo`,{description:"Built ostree-repo path. If given, also runs `flatpak-builder-lint repo`.",type:`string`,normalize:!0}).option(`metainfo`,{description:"MetaInfo XML path. Default: `data/<app-id>.metainfo.xml.in`.",type:`string`,normalize:!0}).option(`appstream`,{description:"Run `appstreamcli validate --strict` (default: true).",type:`boolean`,default:!0}).option(`quality`,{description:`Run Flathub's quality guidelines (name, summary, branding, screenshots, release notes) on the MetaInfo (default: true).`,type:`boolean`,default:!0}).option(`strict`,{description:`Treat quality warnings as errors.`,type:`boolean`,default:!1}).option(`json`,{description:`Print the quality findings as JSON (and nothing else on stdout).`,type:`boolean`,default:!1}).option(`quality-network`,{description:`Let the quality check fetch http(s) screenshot/icon URLs to measure their size.`,type:`boolean`,default:!1}).option(`builder-lint`,{description:"Run `flatpak-builder-lint manifest` (default: true).",type:`boolean`,default:!0}).option(`verbose`,{description:`Stream linter stdout/stderr verbatim.`,type:`boolean`,default:!1}),handler:async t=>{let n=(await new Config().forCommand().catch(()=>({}))).flatpak??{},S=process.cwd(),C=resolveAppId(t.manifest,n,S),N=resolveManifestPath(t.manifest,C,S),F=xn(S,t.metainfo??`data/${C??`unknown`}.metainfo.xml.in`),I=0;if(t.appstream!==!1&&(existsSync(F)?await runLinter(`appstreamcli`,[`validate`,`--strict`,F],t.verbose??!1)||I++:ge.warn(`[gjsify flatpak check] skipping appstreamcli — ${F} not found`)),t.quality!==!1&&(existsSync(F)?await runQuality(F,C,t)||I++:ge.warn(`[gjsify flatpak check] skipping quality check — ${F} not found`)),t.builderLint!==!1&&!t.json){if(!existsSync(N))return ge.error(`[gjsify flatpak check] manifest not found: ${N}`),process.exit(1);await runLinter(`flatpak-builder-lint`,[`manifest`,N],t.verbose??!1)||I++,t.repo&&(await runLinter(`flatpak-builder-lint`,[`repo`,xn(S,t.repo)],t.verbose??!1)||I++)}if(I>0)return ge.error(`\n[gjsify flatpak check] ${I} check(s) failed.`),process.exit(1);ge.log(`[gjsify flatpak check] all checks passed.`)}}});async function readSourceListAtTag(t,n,S,C){let N;try{let{stdout:C}=await nB(`git`,[`show`,`${n}:${S}`],{cwd:t,maxBuffer:64*1024*1024});N=C}catch(N){return await assertGitMeantAbsent(t,n,S,N),C&&ge.log(`[gjsify flatpak sync-flathub] ${S} not present at ${n} — skipping`),null}if(N.trim()===``)return C&&ge.log(`[gjsify flatpak sync-flathub] ${S} is empty at ${n} — skipping`),null;let F;try{F=JSON.parse(N)}catch(t){throw Error(`[gjsify flatpak sync-flathub] ${S} at ${n} is not JSON: `+(t instanceof Error?t.message:String(t)))}if(!Array.isArray(F)||F.length===0)throw Error(`[gjsify flatpak sync-flathub] ${S} at ${n} is not a non-empty array of flatpak sources`);return N}async function assertGitMeantAbsent(t,n,S,C){if(typeof C?.code!=`number`)throw Error(`[gjsify flatpak sync-flathub] could not run \`git show ${n}:${S}\` — `+(C instanceof Error?C.message:String(C)));if(!await nB(`git`,[`rev-parse`,`--verify`,`--quiet`,`${n}^{commit}`],{cwd:t}).then(({stdout:t})=>t.trim()).catch(()=>``))throw Error(`[gjsify flatpak sync-flathub] ${n} does not resolve in ${t}, so whether it carries ${S} is unanswered. Run \`git fetch --tags\`, pass --version <an existing tag>, or run from the app checkout.`)}async function resolveLatestTag$1(t,n){try{let{stdout:S}=await nB(`git`,[`describe`,`--tags`,`--abbrev=0`],{cwd:t});return n&&ge.log(`[gjsify flatpak sync-flathub] resolved latest tag → ${S.trim()}`),S.trim()||null}catch{return null}}async function resolveCommitForTag(t,n,S){try{let{stdout:C}=await nB(`git`,[`rev-list`,`-n`,`1`,n],{cwd:t}),N=C.trim();if(!N)throw Error(`empty rev-list output`);return S&&ge.log(`[gjsify flatpak sync-flathub] resolved ${n} → ${N}`),N}catch(t){throw Error(`[gjsify flatpak sync-flathub] tag ${n} not found locally. Run \`git fetch --tags\` or pass --commit <sha>.\n underlying error: ${t instanceof Error?t.message:String(t)}`)}}function normaliseBranchSegment(t){return t.replace(/^v/,``).replace(/[^A-Za-z0-9._-]/g,`-`)}function flathubCacheRoot(){return wn(process.env.XDG_CACHE_HOME||wn(homedir(),`.cache`),`gjsify`,`flathub-sync`)}async function ensureClone(t,n,S){if(existsSync(wn(t,`.git`))){S&&ge.log(`[gjsify flatpak sync-flathub] reusing clone at ${t}`),await gitInRepo(t,[`fetch`,`origin`],S);let n=await detectDefaultBranch(t,S);await gitInRepo(t,[`checkout`,n],S),await gitInRepo(t,[`reset`,`--hard`,`origin/${n}`],S);return}mkdirSync(xn(t,`..`),{recursive:!0});let C=`https://github.com/${n}.git`;S&&ge.log(`[gjsify flatpak sync-flathub] git clone ${C} ${t}`);try{await nB(`git`,[`clone`,C,t])}catch(t){throw t?.code===`ENOENT`?Error("[gjsify flatpak sync-flathub] `git` not found. Install git from your distro (Fedora: `dnf install git`, Debian: `apt install git`)."):t}}async function detectDefaultBranch(t,n){try{let{stdout:S}=await nB(`git`,[`remote`,`show`,`origin`],{cwd:t}),C=S.match(/HEAD branch: (\S+)/);if(C&&C[1]&&C[1]!==`(unknown)`)return n&&ge.log(`[gjsify flatpak sync-flathub] default branch → ${C[1]}`),C[1]}catch{}return`master`}async function gitInRepo(t,n,S){S&&ge.log(`[gjsify flatpak sync-flathub] git ${n.join(` `)} (in ${t})`);let C=await spawnToCompletion(`git`,n,{completion:`return`,cwd:t,notFound:()=>Error("[gjsify flatpak sync-flathub] `git` not found. Install it from your distro.")});if(C.code!==0)throw Error(`git ${n[0]} exited ${describeExit(C)}`)}async function ghCreate(t,n,S,C,N,F){let I=[`pr`,`create`,`--repo`,n,`--head`,S,`--title`,`Update to ${C}`,`--body`,N];F&&ge.log(`[gjsify flatpak sync-flathub] gh ${I.join(` `)} (in ${t})`);let H=await spawnToCompletion(`gh`,I,{completion:`return`,cwd:t,notFound:()=>Error("[gjsify flatpak sync-flathub] `gh` (GitHub CLI) not found. Install via `dnf install gh` (Fedora), `apt install gh` (Debian/Ubuntu), or `flatpak install -y flathub com.github.cli`.")});if(H.code!==0)throw Error(`gh pr create exited ${describeExit(H)}`)}function editManifest(t,n){let S=JSON.parse(t),C=S.modules??[];if(C.length===0)throw Error(`[gjsify flatpak sync-flathub] manifest has no modules`);let N=C[0].sources??[];if(N.length===0)throw Error(`[gjsify flatpak sync-flathub] modules[0] has no sources`);let isObject=t=>typeof t==`object`,F=n.sourceIndex??N.findIndex(t=>isObject(t)&&t.type===`git`);if(F<0||F>=N.length)throw Error(`[gjsify flatpak sync-flathub] no git source found in modules[0].sources (use --source-index <n>)`);let I=N[F];if(!isObject(I)||I.type!==`git`){let t=isObject(I)?`type is "${I.type}"`:`is the file reference "${I}"`;throw Error(`[gjsify flatpak sync-flathub] modules[0].sources[${F}] ${t}, expected a git source`)}let H=I;H.tag=n.tag,H.commit=n.commit,H[`x-checker-data`]||={type:`git`,"tag-pattern":`^v(\\d+\\.\\d+\\.\\d+)$`,"version-scheme":`semantic`},n.sourcesFile&&!namesFile(N,n.sourcesFile)&&N.push(n.sourcesFile);let W=detectIndent$1(t);return JSON.stringify(S,null,W)+(t.endsWith(`
1091
1091
  `)?`
1092
- `:``)}function namesFile(t,n){let S=stripDotSlash(n);return t.some(t=>typeof t==`string`&&stripDotSlash(t)===S)}function stripDotSlash(t){return t.replace(/^\.\//,``)}function detectIndent$1(t){let n=t.match(/^\{\n( +)/);return n?n[1].length:2}var Zz,Qz,$z=__esmMin(()=>{_e(),Rd(),Pn(),Lg(),P_(),V_(),Tu(),TI(),hz(),Zz=promisify(execFile),Qz={command:`sync-flathub`,description:`Update the per-app Flathub tracking-repo manifest to a new git tag + commit. Clones, edits, commits, optionally opens a PR.`,builder:t=>t.version(!1).option(`version`,{description:"Git tag to sync to. Default: `git describe --tags --abbrev=0` in cwd.",type:`string`}).option(`app-id`,{description:"Reverse-DNS app id. Default: `gjsify.flatpak.appId`.",type:`string`}).option(`flathub-repo`,{description:"Flathub tracking-repo (owner/name). Default: `flathub/<appId>`.",type:`string`}).option(`commit`,{description:"Commit SHA to pin. Default: resolved via `git rev-list -n 1 <version>` in cwd.",type:`string`}).option(`branch`,{description:"Branch name in the flathub-repo. Default: `update-to-<version>`.",type:`string`}).option(`sources-file`,{description:`Generated offline tarball list to carry into the Flathub repo and name in the manifest. Default: \`${mz}\`. Skipped when the tag does not carry it.`,type:`string`,default:mz}).option(`source-index`,{description:"Index into modules[0].sources[] to update (when manifest has multiple sources). Default: first `type: git` source.",type:`number`}).option(`pr`,{description:"After commit + push, open a PR via `gh pr create`. Pass `--no-pr` to skip and stop after push.",type:`boolean`,default:!0}).option(`dry-run`,{description:`Show what would be edited; touch no files, run no git commands.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo every git / gh invocation before running.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=(await new Config().forCommand().catch(()=>({}))).flatpak??{},C=t.appId??S.appId??readPackageJson(n).name;if(!C)throw Error(`[gjsify flatpak sync-flathub] no app id available — pass --app-id or set gjsify.flatpak.appId.`);let N=t.flathubRepo??S.flathubRepo??`flathub/${C}`,F=t.version??await resolveLatestTag$1(n,t.verbose);if(!F)throw Error(`[gjsify flatpak sync-flathub] no version resolved — pass --version vX.Y.Z or create a git tag locally.`);let I=t.commit??await resolveCommitForTag(n,F,t.verbose),H=t.branch??`update-to-${normaliseBranchSegment(F)}`;if(ge.log(`[gjsify flatpak sync-flathub] appId=${C}`),ge.log(`[gjsify flatpak sync-flathub] flathubRepo=${N}`),ge.log(`[gjsify flatpak sync-flathub] version=${F}`),ge.log(`[gjsify flatpak sync-flathub] commit=${I}`),ge.log(`[gjsify flatpak sync-flathub] branch=${H}`),t.dryRun){ge.log(`[gjsify flatpak sync-flathub] --dry-run set; not cloning / writing / pushing.`);return}let W=flathubCacheRoot(),q=wn(W,N.replace(`/`,`__`));mkdirSync(W,{recursive:!0}),await ensureClone(q,N,t.verbose);let Y=wn(q,`${C}.json`);if(!existsSync(Y))throw Error(`[gjsify flatpak sync-flathub] Flathub manifest not found at ${Y} — wrong appId / wrong flathub-repo?`);let X=t.sourcesFile??`gjsify-sources.json`,Z=await readSourceListAtTag(n,F,X,t.verbose),te=!1;if(Z!==null){let t=wn(q,X);te=!existsSync(t)||readFileSync(t,`utf-8`)!==Z,te&&(writeFileSync(t,Z,`utf-8`),ge.log(`[gjsify flatpak sync-flathub] ${X} copied from ${F}`))}let ne=readFileSync(Y,`utf-8`),re=editManifest(ne,{tag:F,commit:I,sourceIndex:t.sourceIndex,sourcesFile:Z===null?void 0:X});if(re===ne&&!te){ge.log(`[gjsify flatpak sync-flathub] manifest already at ${F} — nothing to do.`);return}if(writeFileSync(Y,re,`utf-8`),ge.log(`[gjsify flatpak sync-flathub] manifest patched at ${Y}`),await gitInRepo(q,[`checkout`,`-B`,H],t.verbose),await gitInRepo(q,[`add`,`.`],t.verbose),await gitInRepo(q,[`commit`,`-m`,`Update to ${F}`],t.verbose),t.pr===!1){ge.log(`[gjsify flatpak sync-flathub] --no-pr set; branch ${H} committed locally in ${q}.`);return}await gitInRepo(q,[`push`,`-u`,`origin`,H,`--force-with-lease`],t.verbose),await ghCreate(q,N,H,F,`Auto-generated by \`gjsify flatpak sync-flathub\`.\n\n- Version: \`${F}\`\n- Commit: \`${I}\`\n`,t.verbose)}},__name$1(resolveLatestTag$1,`resolveLatestTag`),__name$1(detectIndent$1,`detectIndent`)});async function loadFlathubSource(t,n){let S;if(t.against){if(!existsSync(t.against))throw Error(`[gjsify flatpak diff] --against path ${t.against} does not exist`);S=readFileSync(t.against,`utf-8`)}else S=await fetchFlathubManifest(t.flathubRepo,t.appId,t.verbose);let C;try{C=JSON.parse(S)}catch(t){throw Error(`[gjsify flatpak diff] failed to parse Flathub manifest as JSON: ${t.message}`)}let N=(C.modules??[])[0]?.sources??[];if(N.length===0)return null;let F=n??N.findIndex(t=>isSourceObject(t)&&t.type===`git`);if(F<0||F>=N.length)return null;let I=N[F];return isSourceObject(I)?I:null}function isSourceObject(t){return typeof t==`object`&&!!t}async function fetchFlathubManifest(t,n,S){for(let C of[`master`,`main`]){let N=`https://raw.githubusercontent.com/${t}/${C}/${n}.json`;S&&ge.log(`[gjsify flatpak diff] fetch ${N}`);try{let t=await fetch(N);if(t.ok)return await t.text();S&&ge.log(`[gjsify flatpak diff] ${C} → HTTP ${t.status}`)}catch(t){S&&ge.log(`[gjsify flatpak diff] ${C} fetch error: ${t.message}`)}}throw Error(`[gjsify flatpak diff] could not fetch flathub manifest from ${t} on master or main`)}async function resolveLatestTag(t,n){try{let{stdout:S}=await eB(`git`,[`describe`,`--tags`,`--abbrev=0`],{cwd:t}),C=S.trim();return n&&ge.log(`[gjsify flatpak diff] local latest tag → ${C}`),C||null}catch{return null}}var eB,tB,nB=__esmMin(()=>{_e(),Rd(),P_(),Tu(),TI(),hz(),eB=promisify(execFile),tB={command:`diff`,description:`Compare the per-app Flathub tracking-repo manifest against the local git state and report version / commit drift.`,builder:t=>t.version(!1).option(`version`,{description:"Local version to compare against. Default: `git describe --tags --abbrev=0` in cwd.",type:`string`}).option(`app-id`,{description:"Reverse-DNS app id. Default: `gjsify.flatpak.appId`.",type:`string`}).option(`flathub-repo`,{description:"Flathub tracking-repo (owner/name). Default: `gjsify.flatpak.flathubRepo` or `flathub/<appId>`.",type:`string`}).option(`against`,{description:`Read the Flathub manifest from a local file instead of fetching it. Useful in CI or offline.`,type:`string`}).option(`detail`,{description:`Also print the full Flathub manifest source entry alongside the resolved local version.`,type:`boolean`,default:!1}).option(`source-index`,{description:`Index into modules[0].sources[] to inspect (when the manifest has multiple sources).`,type:`number`}).option(`verbose`,{description:`Echo fetch URL + resolved values.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=(await new Config().forCommand().catch(()=>({}))).flatpak??{},C=t.appId??S.appId??readPackageJson(n).name;if(!C)throw Error(`[gjsify flatpak diff] no app id available — pass --app-id or set gjsify.flatpak.appId.`);let N=t.flathubRepo??S.flathubRepo??`flathub/${C}`,F=t.version??await resolveLatestTag(n,t.verbose),I=await loadFlathubSource({appId:C,flathubRepo:N,against:t.against,verbose:t.verbose},t.sourceIndex),H=I?.tag,W=I?.commit;if(ge.log(`[gjsify flatpak diff] appId=${C}`),ge.log(`[gjsify flatpak diff] flathubRepo=${N}`),ge.log(`[gjsify flatpak diff] flathub: tag=${H??`(missing)`} commit=${W??`(missing)`}`),ge.log(`[gjsify flatpak diff] local: tag=${F??`(none)`}`),t.detail&&I&&(ge.log(`[gjsify flatpak diff] flathub manifest source:`),ge.log(JSON.stringify(I,null,2))),!F){ge.warn("[gjsify flatpak diff] no local git tag found — cut a release (`git tag vX.Y.Z`) or pass --version vX.Y.Z to compare against an explicit value.");return}if(!H)return ge.warn("[gjsify flatpak diff] flathub manifest has no `tag` field on the inspected source."),process.exit(1);if(H===F){ge.log(`✅ in sync (${F})`);return}ge.log(`❌ drift detected — flathub=${H} vs local=${F}`),ge.log(` run \`gjsify flatpak sync-flathub --version ${F}\` to update the Flathub manifest.`),process.exit(1)}}});function resolveCliEntry(){return xn(xn(En(fileURLToPath(import.meta.url)),`..`,`..`),`index.js`)}async function runNode(t,n){let S=await spawnToCompletion(`node`,t,{completion:`return`,cwd:n});if(S.code!==0)throw Error(`sub-command exited with ${describeExit(S)}: node ${t.join(` `)}`)}var rB,iB,aB=__esmMin(()=>{_e(),P_(),V_(),Tu(),Gn(),Pn(),rB=promisify(execFile),iB={command:`release <version>`,description:"Cut a release end-to-end: regenerate Flathub assets, run linters, create + push the git tag, then open the Flathub PR. Each step delegates to the equivalent `gjsify flatpak <sub>` command.",builder:t=>t.version(!1).positional(`version`,{description:"Release tag, e.g. `v0.6.6`.",type:`string`,demandOption:!0}).option(`skip-init`,{description:"Skip the `flatpak init --force` regen step.",type:`boolean`,default:!1}).option(`skip-check`,{description:"Skip the `flatpak check` linter step.",type:`boolean`,default:!1}).option(`skip-tag`,{description:"Skip the `git tag` + `git push --tags` step (use when the tag was already created out-of-band).",type:`boolean`,default:!1}).option(`push-tag`,{description:`Push the created tag after creating it. Default: true.`,type:`boolean`,default:!0}).option(`flathub-repo`,{description:`Flathub tracking-repo override forwarded to sync-flathub.`,type:`string`}).option(`dry-run`,{description:`Print each step that would run without executing any of them.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo every sub-command invocation.`,type:`boolean`,default:!1}),handler:async t=>{let n=typeof t.version==`string`?t.version.trim():``;if(!n)throw Error(`[gjsify flatpak release] missing <version> positional`);let S=resolveCliEntry(),C=process.cwd(),N=[];t.skipInit||N.push({name:`init`,args:[S,`flatpak`,`init`,`--force`]}),t.skipCheck||N.push({name:`check`,args:[S,`flatpak`,`check`]});let F=[S,`flatpak`,`sync-flathub`,`--version`,n];if(t.flathubRepo&&F.push(`--flathub-repo`,t.flathubRepo),t.verbose&&F.push(`--verbose`),ge.log(`[gjsify flatpak release] starting release of ${n}`),t.dryRun){ge.log(`[gjsify flatpak release] --dry-run set; printing plan only:`);for(let t of N)ge.log(` · ${t.name}: node ${t.args.join(` `)}`);t.skipTag||ge.log(` · tag: git tag ${n}${t.pushTag===!1?``:` && git push origin `+n}`),ge.log(` · sync: node ${F.join(` `)}`);return}for(let n of N)t.verbose&&ge.log(`[gjsify flatpak release] step ${n.name}: node ${n.args.join(` `)}`),await runNode(n.args,C),ge.log(`[gjsify flatpak release] ${n.name} ✔`);if(!t.skipTag){t.verbose&&ge.log(`[gjsify flatpak release] git tag ${n}`);try{await rB(`git`,[`tag`,n],{cwd:C}),ge.log(`[gjsify flatpak release] tag ${n} created`)}catch(t){throw Error(`[gjsify flatpak release] git tag failed (${t.message}). If the tag already exists, re-run with --skip-tag.`)}t.pushTag!==!1&&(t.verbose&&ge.log(`[gjsify flatpak release] git push origin ${n}`),await rB(`git`,[`push`,`origin`,n],{cwd:C}),ge.log(`[gjsify flatpak release] tag pushed`))}t.verbose&&ge.log(`[gjsify flatpak release] sync: node ${F.join(` `)}`),await runNode(F,C),ge.log(`[gjsify flatpak release] ✅ release ${n} complete`)}}}),oB,sB=__esmMin(()=>{Az(),Mz(),Pz(),Vz(),Uz(),Xz(),$z(),nB(),aB(),oB={command:`flatpak <subcommand>`,description:`Flatpak toolchain: init/build/deps/sources/ci/check/sync-flathub/diff/release subcommands for shipping GJS apps and CLIs as Flatpaks.`,builder:t=>t.command(kz.command,kz.description,kz.builder,kz.handler).command(jz.command,jz.description,jz.builder,jz.handler).command(Nz.command,Nz.description,Nz.builder,Nz.handler).command(Bz.command,Bz.description,Bz.builder,Bz.handler).command(Hz.command,Hz.description,Hz.builder,Hz.handler).command(Yz.command,Yz.description,Yz.builder,Yz.handler).command(Qz.command,Qz.description,Qz.builder,Qz.handler).command(tB.command,tB.description,tB.builder,tB.handler).command(iB.command,iB.description,iB.builder,iB.handler).demandCommand(1).strict()}});function concatBytes(t){let n=0;for(let S of t)n+=S.byteLength;let S=new Uint8Array(n),C=0;for(let n of t)S.set(n,C),C+=n.byteLength;return S}function encodeUtf8(t){return new TextEncoder().encode(t)}var cB=__esmMin(()=>{});function createArArchive(t){let n=[encodeUtf8(lB)];for(let S of t)n.push(buildMemberHeader(S)),n.push(S.data),S.data.byteLength%2==1&&n.push(encodeUtf8(`
1092
+ `:``)}function namesFile(t,n){let S=stripDotSlash(n);return t.some(t=>typeof t==`string`&&stripDotSlash(t)===S)}function stripDotSlash(t){return t.replace(/^\.\//,``)}function detectIndent$1(t){let n=t.match(/^\{\n( +)/);return n?n[1].length:2}var nB,rB,iB=__esmMin(()=>{_e(),Rd(),Pn(),Lg(),P_(),V_(),Tu(),AI(),bz(),nB=promisify(execFile),rB={command:`sync-flathub`,description:`Update the per-app Flathub tracking-repo manifest to a new git tag + commit. Clones, edits, commits, optionally opens a PR.`,builder:t=>t.version(!1).option(`version`,{description:"Git tag to sync to. Default: `git describe --tags --abbrev=0` in cwd.",type:`string`}).option(`app-id`,{description:"Reverse-DNS app id. Default: `gjsify.flatpak.appId`.",type:`string`}).option(`flathub-repo`,{description:"Flathub tracking-repo (owner/name). Default: `flathub/<appId>`.",type:`string`}).option(`commit`,{description:"Commit SHA to pin. Default: resolved via `git rev-list -n 1 <version>` in cwd.",type:`string`}).option(`branch`,{description:"Branch name in the flathub-repo. Default: `update-to-<version>`.",type:`string`}).option(`sources-file`,{description:`Generated offline tarball list to carry into the Flathub repo and name in the manifest. Default: \`${yz}\`. Skipped when the tag does not carry it.`,type:`string`,default:yz}).option(`source-index`,{description:"Index into modules[0].sources[] to update (when manifest has multiple sources). Default: first `type: git` source.",type:`number`}).option(`pr`,{description:"After commit + push, open a PR via `gh pr create`. Pass `--no-pr` to skip and stop after push.",type:`boolean`,default:!0}).option(`dry-run`,{description:`Show what would be edited; touch no files, run no git commands.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo every git / gh invocation before running.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=(await new Config().forCommand().catch(()=>({}))).flatpak??{},C=t.appId??S.appId??readPackageJson(n).name;if(!C)throw Error(`[gjsify flatpak sync-flathub] no app id available — pass --app-id or set gjsify.flatpak.appId.`);let N=t.flathubRepo??S.flathubRepo??`flathub/${C}`,F=t.version??await resolveLatestTag$1(n,t.verbose);if(!F)throw Error(`[gjsify flatpak sync-flathub] no version resolved — pass --version vX.Y.Z or create a git tag locally.`);let I=t.commit??await resolveCommitForTag(n,F,t.verbose),H=t.branch??`update-to-${normaliseBranchSegment(F)}`;if(ge.log(`[gjsify flatpak sync-flathub] appId=${C}`),ge.log(`[gjsify flatpak sync-flathub] flathubRepo=${N}`),ge.log(`[gjsify flatpak sync-flathub] version=${F}`),ge.log(`[gjsify flatpak sync-flathub] commit=${I}`),ge.log(`[gjsify flatpak sync-flathub] branch=${H}`),t.dryRun){ge.log(`[gjsify flatpak sync-flathub] --dry-run set; not cloning / writing / pushing.`);return}let W=flathubCacheRoot(),q=wn(W,N.replace(`/`,`__`));mkdirSync(W,{recursive:!0}),await ensureClone(q,N,t.verbose);let Y=wn(q,`${C}.json`);if(!existsSync(Y))throw Error(`[gjsify flatpak sync-flathub] Flathub manifest not found at ${Y} — wrong appId / wrong flathub-repo?`);let X=t.sourcesFile??`gjsify-sources.json`,Z=await readSourceListAtTag(n,F,X,t.verbose),te=!1;if(Z!==null){let t=wn(q,X);te=!existsSync(t)||readFileSync(t,`utf-8`)!==Z,te&&(writeFileSync(t,Z,`utf-8`),ge.log(`[gjsify flatpak sync-flathub] ${X} copied from ${F}`))}let ne=readFileSync(Y,`utf-8`),re=editManifest(ne,{tag:F,commit:I,sourceIndex:t.sourceIndex,sourcesFile:Z===null?void 0:X});if(re===ne&&!te){ge.log(`[gjsify flatpak sync-flathub] manifest already at ${F} — nothing to do.`);return}if(writeFileSync(Y,re,`utf-8`),ge.log(`[gjsify flatpak sync-flathub] manifest patched at ${Y}`),await gitInRepo(q,[`checkout`,`-B`,H],t.verbose),await gitInRepo(q,[`add`,`.`],t.verbose),await gitInRepo(q,[`commit`,`-m`,`Update to ${F}`],t.verbose),t.pr===!1){ge.log(`[gjsify flatpak sync-flathub] --no-pr set; branch ${H} committed locally in ${q}.`);return}await gitInRepo(q,[`push`,`-u`,`origin`,H,`--force-with-lease`],t.verbose),await ghCreate(q,N,H,F,`Auto-generated by \`gjsify flatpak sync-flathub\`.\n\n- Version: \`${F}\`\n- Commit: \`${I}\`\n`,t.verbose)}},__name$1(resolveLatestTag$1,`resolveLatestTag`),__name$1(detectIndent$1,`detectIndent`)});async function loadFlathubSource(t,n){let S;if(t.against){if(!existsSync(t.against))throw Error(`[gjsify flatpak diff] --against path ${t.against} does not exist`);S=readFileSync(t.against,`utf-8`)}else S=await fetchFlathubManifest(t.flathubRepo,t.appId,t.verbose);let C;try{C=JSON.parse(S)}catch(t){throw Error(`[gjsify flatpak diff] failed to parse Flathub manifest as JSON: ${t.message}`)}let N=(C.modules??[])[0]?.sources??[];if(N.length===0)return null;let F=n??N.findIndex(t=>isSourceObject(t)&&t.type===`git`);if(F<0||F>=N.length)return null;let I=N[F];return isSourceObject(I)?I:null}function isSourceObject(t){return typeof t==`object`&&!!t}async function fetchFlathubManifest(t,n,S){for(let C of[`master`,`main`]){let N=`https://raw.githubusercontent.com/${t}/${C}/${n}.json`;S&&ge.log(`[gjsify flatpak diff] fetch ${N}`);try{let t=await fetch(N);if(t.ok)return await t.text();S&&ge.log(`[gjsify flatpak diff] ${C} → HTTP ${t.status}`)}catch(t){S&&ge.log(`[gjsify flatpak diff] ${C} fetch error: ${t.message}`)}}throw Error(`[gjsify flatpak diff] could not fetch flathub manifest from ${t} on master or main`)}async function resolveLatestTag(t,n){try{let{stdout:S}=await aB(`git`,[`describe`,`--tags`,`--abbrev=0`],{cwd:t}),C=S.trim();return n&&ge.log(`[gjsify flatpak diff] local latest tag → ${C}`),C||null}catch{return null}}var aB,oB,sB=__esmMin(()=>{_e(),Rd(),P_(),Tu(),AI(),bz(),aB=promisify(execFile),oB={command:`diff`,description:`Compare the per-app Flathub tracking-repo manifest against the local git state and report version / commit drift.`,builder:t=>t.version(!1).option(`version`,{description:"Local version to compare against. Default: `git describe --tags --abbrev=0` in cwd.",type:`string`}).option(`app-id`,{description:"Reverse-DNS app id. Default: `gjsify.flatpak.appId`.",type:`string`}).option(`flathub-repo`,{description:"Flathub tracking-repo (owner/name). Default: `gjsify.flatpak.flathubRepo` or `flathub/<appId>`.",type:`string`}).option(`against`,{description:`Read the Flathub manifest from a local file instead of fetching it. Useful in CI or offline.`,type:`string`}).option(`detail`,{description:`Also print the full Flathub manifest source entry alongside the resolved local version.`,type:`boolean`,default:!1}).option(`source-index`,{description:`Index into modules[0].sources[] to inspect (when the manifest has multiple sources).`,type:`number`}).option(`verbose`,{description:`Echo fetch URL + resolved values.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=(await new Config().forCommand().catch(()=>({}))).flatpak??{},C=t.appId??S.appId??readPackageJson(n).name;if(!C)throw Error(`[gjsify flatpak diff] no app id available — pass --app-id or set gjsify.flatpak.appId.`);let N=t.flathubRepo??S.flathubRepo??`flathub/${C}`,F=t.version??await resolveLatestTag(n,t.verbose),I=await loadFlathubSource({appId:C,flathubRepo:N,against:t.against,verbose:t.verbose},t.sourceIndex),H=I?.tag,W=I?.commit;if(ge.log(`[gjsify flatpak diff] appId=${C}`),ge.log(`[gjsify flatpak diff] flathubRepo=${N}`),ge.log(`[gjsify flatpak diff] flathub: tag=${H??`(missing)`} commit=${W??`(missing)`}`),ge.log(`[gjsify flatpak diff] local: tag=${F??`(none)`}`),t.detail&&I&&(ge.log(`[gjsify flatpak diff] flathub manifest source:`),ge.log(JSON.stringify(I,null,2))),!F){ge.warn("[gjsify flatpak diff] no local git tag found — cut a release (`git tag vX.Y.Z`) or pass --version vX.Y.Z to compare against an explicit value.");return}if(!H)return ge.warn("[gjsify flatpak diff] flathub manifest has no `tag` field on the inspected source."),process.exit(1);if(H===F){ge.log(`✅ in sync (${F})`);return}ge.log(`❌ drift detected — flathub=${H} vs local=${F}`),ge.log(` run \`gjsify flatpak sync-flathub --version ${F}\` to update the Flathub manifest.`),process.exit(1)}}});function resolveCliEntry(){return xn(xn(En(fileURLToPath(import.meta.url)),`..`,`..`),`index.js`)}async function runNode(t,n){let S=await spawnToCompletion(`node`,t,{completion:`return`,cwd:n});if(S.code!==0)throw Error(`sub-command exited with ${describeExit(S)}: node ${t.join(` `)}`)}var cB,lB,uB=__esmMin(()=>{_e(),P_(),V_(),Tu(),Gn(),Pn(),cB=promisify(execFile),lB={command:`release <version>`,description:"Cut a release end-to-end: regenerate Flathub assets, run linters, create + push the git tag, then open the Flathub PR. Each step delegates to the equivalent `gjsify flatpak <sub>` command.",builder:t=>t.version(!1).positional(`version`,{description:"Release tag, e.g. `v0.6.6`.",type:`string`,demandOption:!0}).option(`skip-init`,{description:"Skip the `flatpak init --force` regen step.",type:`boolean`,default:!1}).option(`skip-check`,{description:"Skip the `flatpak check` linter step.",type:`boolean`,default:!1}).option(`skip-tag`,{description:"Skip the `git tag` + `git push --tags` step (use when the tag was already created out-of-band).",type:`boolean`,default:!1}).option(`push-tag`,{description:`Push the created tag after creating it. Default: true.`,type:`boolean`,default:!0}).option(`flathub-repo`,{description:`Flathub tracking-repo override forwarded to sync-flathub.`,type:`string`}).option(`dry-run`,{description:`Print each step that would run without executing any of them.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo every sub-command invocation.`,type:`boolean`,default:!1}),handler:async t=>{let n=typeof t.version==`string`?t.version.trim():``;if(!n)throw Error(`[gjsify flatpak release] missing <version> positional`);let S=resolveCliEntry(),C=process.cwd(),N=[];t.skipInit||N.push({name:`init`,args:[S,`flatpak`,`init`,`--force`]}),t.skipCheck||N.push({name:`check`,args:[S,`flatpak`,`check`]});let F=[S,`flatpak`,`sync-flathub`,`--version`,n];if(t.flathubRepo&&F.push(`--flathub-repo`,t.flathubRepo),t.verbose&&F.push(`--verbose`),ge.log(`[gjsify flatpak release] starting release of ${n}`),t.dryRun){ge.log(`[gjsify flatpak release] --dry-run set; printing plan only:`);for(let t of N)ge.log(` · ${t.name}: node ${t.args.join(` `)}`);t.skipTag||ge.log(` · tag: git tag ${n}${t.pushTag===!1?``:` && git push origin `+n}`),ge.log(` · sync: node ${F.join(` `)}`);return}for(let n of N)t.verbose&&ge.log(`[gjsify flatpak release] step ${n.name}: node ${n.args.join(` `)}`),await runNode(n.args,C),ge.log(`[gjsify flatpak release] ${n.name} ✔`);if(!t.skipTag){t.verbose&&ge.log(`[gjsify flatpak release] git tag ${n}`);try{await cB(`git`,[`tag`,n],{cwd:C}),ge.log(`[gjsify flatpak release] tag ${n} created`)}catch(t){throw Error(`[gjsify flatpak release] git tag failed (${t.message}). If the tag already exists, re-run with --skip-tag.`)}t.pushTag!==!1&&(t.verbose&&ge.log(`[gjsify flatpak release] git push origin ${n}`),await cB(`git`,[`push`,`origin`,n],{cwd:C}),ge.log(`[gjsify flatpak release] tag pushed`))}t.verbose&&ge.log(`[gjsify flatpak release] sync: node ${F.join(` `)}`),await runNode(F,C),ge.log(`[gjsify flatpak release] ✅ release ${n} complete`)}}}),dB,fB=__esmMin(()=>{Fz(),Lz(),zz(),Kz(),Jz(),tB(),iB(),sB(),uB(),dB={command:`flatpak <subcommand>`,description:`Flatpak toolchain: init/build/deps/sources/ci/check/sync-flathub/diff/release subcommands for shipping GJS apps and CLIs as Flatpaks.`,builder:t=>t.command(Pz.command,Pz.description,Pz.builder,Pz.handler).command(Iz.command,Iz.description,Iz.builder,Iz.handler).command(Rz.command,Rz.description,Rz.builder,Rz.handler).command(Gz.command,Gz.description,Gz.builder,Gz.handler).command(qz.command,qz.description,qz.builder,qz.handler).command(eB.command,eB.description,eB.builder,eB.handler).command(rB.command,rB.description,rB.builder,rB.handler).command(oB.command,oB.description,oB.builder,oB.handler).command(lB.command,lB.description,lB.builder,lB.handler).demandCommand(1).strict()}});function concatBytes(t){let n=0;for(let S of t)n+=S.byteLength;let S=new Uint8Array(n),C=0;for(let n of t)S.set(n,C),C+=n.byteLength;return S}function encodeUtf8(t){return new TextEncoder().encode(t)}var pB=__esmMin(()=>{});function createArArchive(t){let n=[encodeUtf8(mB)];for(let S of t)n.push(buildMemberHeader(S)),n.push(S.data),S.data.byteLength%2==1&&n.push(encodeUtf8(`
1093
1093
  `));return concatBytes(n)}function buildMemberHeader(t){let n=pad(t.name,16)+pad(String(t.mtime??0),12)+pad(`0`,6)+pad(`0`,6)+pad((t.mode??33188).toString(8),8)+pad(String(t.data.byteLength),10)+`\`
1094
- `;if(n.length!==uB)throw Error(`gjsify ship: internal error — ar header is ${n.length} bytes, expected ${uB}.`);return encodeUtf8(n)}function pad(t,n){if(t.length>n)throw Error(`gjsify ship: ar header field "${t}" does not fit in ${n} bytes.`);return t.padEnd(n,` `)}var lB,uB,dB=__esmMin(()=>{cB(),lB=`!<arch>
1095
- `,uB=60});function warnAboutGjsFloor(t,n){return!hB[t]||compareVersions(n,`1.82.3`)<=0||compareVersions(n,`1.88.1`)===0?[]:[`gjsify ship: \`Depends: gjs (>= ${n})\` is not satisfiable on Debian stable — ${mB}. The package installs on forky/sid and on distributions with a newer GJS. Set \`gjsify.ship.minGjsVersion\` if this bundle genuinely runs on an older GJS; do NOT lower it to make apt happy, because the result is an install that succeeds and an app that does not start.`]}function warnAboutNodeFloor(t,n){return!_B[t]||compareVersions(n,`22`)<=0?[]:[`gjsify ship: \`Depends: nodejs (>= ${n})\` is not satisfiable on any current DEB stable/LTS — ${gB}. The package installs on forky/sid and on distributions with a newer Node. Set \`gjsify.ship.minNodeVersion\` if this bundle genuinely runs on an older Node; do NOT lower it to make apt happy, because the result is an install that succeeds and an app that dies on the first syntax or API the older interpreter does not have.`]}function compareVersions(t,n){let S=t.split(`.`).map(Number),C=n.split(`.`).map(Number);for(let t=0;t<Math.max(S.length,C.length);t++){let n=(S[t]??0)-(C[t]??0);if(n!==0)return n}return 0}function hostProvidedNamespaces(t,n=[]){let S=new Set;for(let t of n){let n=/([A-Za-z0-9]+)-([\d.]+)\.typelib$/.exec(t);n&&(S.add(`${n[1]}-${n[2]}`),S.add(n[1]))}return[...new Set(t)].sort().filter(t=>!yB.test(t)&&!S.has(t))}function deriveDepends(t,n){let S=n.interpreter===`node`?[`${fB[t]} >= ${n.minNodeVersion??`24`}`]:[`gjs >= ${n.minGjsVersion??`1.86`}`],C=[],N=new Set(n.optionalNamespaces??[]),F=[],I=[];for(let H of hostProvidedNamespaces(n.namespaces,n.bundledTypelibs)){let W=lookupTypelib(H,n.typelibPackages);if(W===void 0){(N.has(H)?I:F).push(H);continue}N.has(H)&&!S.includes(W[t])?C.push(W[t]):S.push(W[t])}if(F.length>0)throw Error(`gjsify ship: the bundle imports ${F.map(t=>`gi://${t.split(`-`)[0]}`).join(`, `)}, and no ${t} package is known to ship ${F.length>1?`those typelibs`:`that typelib`}. An undeclared runtime dependency does not fail here — it fails on a user's machine after the download. Fill the gap in package.json:
1094
+ `;if(n.length!==hB)throw Error(`gjsify ship: internal error — ar header is ${n.length} bytes, expected ${hB}.`);return encodeUtf8(n)}function pad(t,n){if(t.length>n)throw Error(`gjsify ship: ar header field "${t}" does not fit in ${n} bytes.`);return t.padEnd(n,` `)}var mB,hB,gB=__esmMin(()=>{pB(),mB=`!<arch>
1095
+ `,hB=60});function warnAboutGjsFloor(t,n){return!bB[t]||compareVersions(n,`1.82.3`)<=0||compareVersions(n,`1.88.1`)===0?[]:[`gjsify ship: \`Depends: gjs (>= ${n})\` is not satisfiable on Debian stable — ${yB}. The package installs on forky/sid and on distributions with a newer GJS. Set \`gjsify.ship.minGjsVersion\` if this bundle genuinely runs on an older GJS; do NOT lower it to make apt happy, because the result is an install that succeeds and an app that does not start.`]}function warnAboutNodeFloor(t,n){return!SB[t]||compareVersions(n,`22`)<=0?[]:[`gjsify ship: \`Depends: nodejs (>= ${n})\` is not satisfiable on any current DEB stable/LTS — ${xB}. The package installs on forky/sid and on distributions with a newer Node. Set \`gjsify.ship.minNodeVersion\` if this bundle genuinely runs on an older Node; do NOT lower it to make apt happy, because the result is an install that succeeds and an app that dies on the first syntax or API the older interpreter does not have.`]}function compareVersions(t,n){let S=t.split(`.`).map(Number),C=n.split(`.`).map(Number);for(let t=0;t<Math.max(S.length,C.length);t++){let n=(S[t]??0)-(C[t]??0);if(n!==0)return n}return 0}function hostProvidedNamespaces(t,n=[]){let S=new Set;for(let t of n){let n=/([A-Za-z0-9]+)-([\d.]+)\.typelib$/.exec(t);n&&(S.add(`${n[1]}-${n[2]}`),S.add(n[1]))}return[...new Set(t)].sort().filter(t=>!wB.test(t)&&!S.has(t))}function deriveDepends(t,n){let S=n.interpreter===`node`?[`${_B[t]} >= ${n.minNodeVersion??`24`}`]:[`gjs >= ${n.minGjsVersion??`1.86`}`],C=[],N=new Set(n.optionalNamespaces??[]),F=[],I=[];for(let H of hostProvidedNamespaces(n.namespaces,n.bundledTypelibs)){let W=lookupTypelib(H,n.typelibPackages);if(W===void 0){(N.has(H)?I:F).push(H);continue}N.has(H)&&!S.includes(W[t])?C.push(W[t]):S.push(W[t])}if(F.length>0)throw Error(`gjsify ship: the bundle imports ${F.map(t=>`gi://${t.split(`-`)[0]}`).join(`, `)}, and no ${t} package is known to ship ${F.length>1?`those typelibs`:`that typelib`}. An undeclared runtime dependency does not fail here — it fails on a user's machine after the download. Fill the gap in package.json:
1096
1096
  "gjsify": { "ship": { "typelibPackages": { ${JSON.stringify(F[0])}: { "deb": "gir1.2-…", "rpm": "…" } } } }
1097
- and please contribute the mapping back to \`utils/ship/depends.ts\` so the next project does not have to. (\`gjsify.ship.depends.<format>\` is for dependencies that are not typelibs at all — it appends, and deliberately does not silence this.)`);return n.hasIcons&&S.push(`hicolor-icon-theme`),n.hasSchemas&&S.push(pB[t]),S.push(...n.extra),{requires:[...new Set(S)],recommends:[...new Set(C)].filter(t=>!S.includes(t)),unmappedOptional:I}}function lookupTypelib(t,n={}){let S={...vB,...n},C=S[t];if(C!==void 0)return C;if(t.includes(`-`))return;let N=Object.keys(S).filter(n=>n.startsWith(`${t}-`));if(N.length===1)return S[N[0]]}function parseDepend(t){let n=/^(\S+)\s*(>=|<=|=|>|<)\s*(\S+)$/.exec(t);return n?{name:n[1],relation:n[2],version:n[3]}:{name:t.trim()}}function formatDebDepend(t){let n=parseDepend(t);if(n.relation===void 0)return n.name;let S=n.relation===`>`?`>>`:n.relation===`<`?`<<`:n.relation;return`${n.name} (${S} ${n.version})`}var fB,pB,mB,hB,gB,_B,vB,yB,bB=__esmMin(()=>{fB={deb:`nodejs`,rpm:`nodejs(engine)`},pB={deb:`libglib2.0-bin`,rpm:`glib2`},mB=`trixie ships 1.82.3 and forky 1.88.1; 1.84 and 1.86 were skipped`,hB={deb:!0,rpm:!1},gB=`trixie ships 20, forky 24; Ubuntu 24.04 LTS ships 18 and 26.04 LTS 22`,_B={deb:!0,rpm:!1},vB={"GLib-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"GObject-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"Gio-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"GioUnix-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"GModule-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"Gtk-4.0":{deb:`gir1.2-gtk-4.0`,rpm:`gtk4`},"Gdk-4.0":{deb:`gir1.2-gtk-4.0`,rpm:`gtk4`},"Gsk-4.0":{deb:`gir1.2-gtk-4.0`,rpm:`gtk4`},"Adw-1":{deb:`gir1.2-adw-1`,rpm:`libadwaita`},"GdkPixbuf-2.0":{deb:`gir1.2-gdkpixbuf-2.0`,rpm:`gdk-pixbuf2`},"Pango-1.0":{deb:`gir1.2-pango-1.0`,rpm:`pango`},"PangoCairo-1.0":{deb:`gir1.2-pango-1.0`,rpm:`pango`},"Graphene-1.0":{deb:`gir1.2-graphene-1.0`,rpm:`graphene`},"cairo-1.0":{deb:`gir1.2-freedesktop`,rpm:`gobject-introspection`},"GtkSource-5":{deb:`gir1.2-gtksource-5`,rpm:`gtksourceview5`},"WebKit-6.0":{deb:`gir1.2-webkit-6.0`,rpm:`webkitgtk6.0`},"Soup-3.0":{deb:`gir1.2-soup-3.0`,rpm:`libsoup3`},"Json-1.0":{deb:`gir1.2-json-1.0`,rpm:`json-glib`},"Gst-1.0":{deb:`gir1.2-gstreamer-1.0`,rpm:`gstreamer1`},"Secret-1":{deb:`gir1.2-secret-1`,rpm:`libsecret`},"Notify-0.7":{deb:`gir1.2-notify-0.7`,rpm:`libnotify`},"Vte-3.91":{deb:`gir1.2-vte-3.91`,rpm:`vte291-gtk4`},"Manette-0.2":{deb:`gir1.2-manette-0.2`,rpm:`libmanette`},"Gda-6.0":{deb:`gir1.2-gda-6.0`,rpm:`libgda`}},yB=/^Gjsify[A-Z]/});async function gzipDeterministic(t,n){let S=await gzip(t,n===void 0?void 0:{level:n});if(S.byteLength<10||S[0]!==31||S[1]!==139)throw Error(`gjsify ship: internal error — gzip did not produce a gzip stream.`);return S[4]=0,S[5]=0,S[6]=0,S[7]=0,S[9]=3,S}var xB=__esmMin(()=>{hL()});function isUnder(t,n){return t.startsWith(`${n}/`)}var SB,CB=__esmMin(()=>{SB={applications:`share/applications`,icons:`share/icons/hicolor`,schemas:`share/glib-2.0/schemas`,mime:`share/mime/packages`,metainfo:`share/metainfo`,locale:`share/locale`,fonts:`share/fonts`}});function cacheRefreshCommands(t,n){let S=[];return t.hasDesktopEntry&&S.push({probe:`update-desktop-database`,run:`update-desktop-database -q ${n}/${SB.applications}`}),t.hasIcons&&S.push({probe:`gtk-update-icon-cache`,run:`gtk-update-icon-cache -q -t -f ${n}/${SB.icons}`}),t.hasMimeTypes&&S.push({probe:`update-mime-database`,run:`update-mime-database ${n}/share/mime`}),t.hasSchemas&&S.push({probe:`glib-compile-schemas`,run:`glib-compile-schemas ${n}/${SB.schemas}`}),S.map(({probe:t,run:n})=>`if command -v ${t} >/dev/null 2>&1; then ${n} || true; fi`)}function renderDebScripts(t,n){let S=cacheRefreshCommands(t,n);if(S.length===0)return{};let C=S.map(t=>` ${t}`).join(`
1097
+ and please contribute the mapping back to \`utils/ship/depends.ts\` so the next project does not have to. (\`gjsify.ship.depends.<format>\` is for dependencies that are not typelibs at all — it appends, and deliberately does not silence this.)`);return n.hasIcons&&S.push(`hicolor-icon-theme`),n.hasSchemas&&S.push(vB[t]),S.push(...n.extra),{requires:[...new Set(S)],recommends:[...new Set(C)].filter(t=>!S.includes(t)),unmappedOptional:I}}function lookupTypelib(t,n={}){let S={...CB,...n},C=S[t];if(C!==void 0)return C;if(t.includes(`-`))return;let N=Object.keys(S).filter(n=>n.startsWith(`${t}-`));if(N.length===1)return S[N[0]]}function parseDepend(t){let n=/^(\S+)\s*(>=|<=|=|>|<)\s*(\S+)$/.exec(t);return n?{name:n[1],relation:n[2],version:n[3]}:{name:t.trim()}}function formatDebDepend(t){let n=parseDepend(t);if(n.relation===void 0)return n.name;let S=n.relation===`>`?`>>`:n.relation===`<`?`<<`:n.relation;return`${n.name} (${S} ${n.version})`}var _B,vB,yB,bB,xB,SB,CB,wB,TB=__esmMin(()=>{_B={deb:`nodejs`,rpm:`nodejs(engine)`},vB={deb:`libglib2.0-bin`,rpm:`glib2`},yB=`trixie ships 1.82.3 and forky 1.88.1; 1.84 and 1.86 were skipped`,bB={deb:!0,rpm:!1},xB=`trixie ships 20, forky 24; Ubuntu 24.04 LTS ships 18 and 26.04 LTS 22`,SB={deb:!0,rpm:!1},CB={"GLib-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"GObject-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"Gio-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"GioUnix-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"GModule-2.0":{deb:`gir1.2-glib-2.0`,rpm:`glib2`},"Gtk-4.0":{deb:`gir1.2-gtk-4.0`,rpm:`gtk4`},"Gdk-4.0":{deb:`gir1.2-gtk-4.0`,rpm:`gtk4`},"Gsk-4.0":{deb:`gir1.2-gtk-4.0`,rpm:`gtk4`},"Adw-1":{deb:`gir1.2-adw-1`,rpm:`libadwaita`},"GdkPixbuf-2.0":{deb:`gir1.2-gdkpixbuf-2.0`,rpm:`gdk-pixbuf2`},"Pango-1.0":{deb:`gir1.2-pango-1.0`,rpm:`pango`},"PangoCairo-1.0":{deb:`gir1.2-pango-1.0`,rpm:`pango`},"Graphene-1.0":{deb:`gir1.2-graphene-1.0`,rpm:`graphene`},"cairo-1.0":{deb:`gir1.2-freedesktop`,rpm:`gobject-introspection`},"GtkSource-5":{deb:`gir1.2-gtksource-5`,rpm:`gtksourceview5`},"WebKit-6.0":{deb:`gir1.2-webkit-6.0`,rpm:`webkitgtk6.0`},"Soup-3.0":{deb:`gir1.2-soup-3.0`,rpm:`libsoup3`},"Json-1.0":{deb:`gir1.2-json-1.0`,rpm:`json-glib`},"Gst-1.0":{deb:`gir1.2-gstreamer-1.0`,rpm:`gstreamer1`},"Secret-1":{deb:`gir1.2-secret-1`,rpm:`libsecret`},"Notify-0.7":{deb:`gir1.2-notify-0.7`,rpm:`libnotify`},"Vte-3.91":{deb:`gir1.2-vte-3.91`,rpm:`vte291-gtk4`},"Manette-0.2":{deb:`gir1.2-manette-0.2`,rpm:`libmanette`},"Gda-6.0":{deb:`gir1.2-gda-6.0`,rpm:`libgda`}},wB=/^Gjsify[A-Z]/});async function gzipDeterministic(t,n){let S=await gzip(t,n===void 0?void 0:{level:n});if(S.byteLength<10||S[0]!==31||S[1]!==139)throw Error(`gjsify ship: internal error — gzip did not produce a gzip stream.`);return S[4]=0,S[5]=0,S[6]=0,S[7]=0,S[9]=3,S}var EB=__esmMin(()=>{bL()});function isUnder(t,n){return t.startsWith(`${n}/`)}var DB,OB=__esmMin(()=>{DB={applications:`share/applications`,icons:`share/icons/hicolor`,schemas:`share/glib-2.0/schemas`,mime:`share/mime/packages`,metainfo:`share/metainfo`,locale:`share/locale`,fonts:`share/fonts`}});function cacheRefreshCommands(t,n){let S=[];return t.hasDesktopEntry&&S.push({probe:`update-desktop-database`,run:`update-desktop-database -q ${n}/${DB.applications}`}),t.hasIcons&&S.push({probe:`gtk-update-icon-cache`,run:`gtk-update-icon-cache -q -t -f ${n}/${DB.icons}`}),t.hasMimeTypes&&S.push({probe:`update-mime-database`,run:`update-mime-database ${n}/share/mime`}),t.hasSchemas&&S.push({probe:`glib-compile-schemas`,run:`glib-compile-schemas ${n}/${DB.schemas}`}),S.map(({probe:t,run:n})=>`if command -v ${t} >/dev/null 2>&1; then ${n} || true; fi`)}function renderDebScripts(t,n){let S=cacheRefreshCommands(t,n);if(S.length===0)return{};let C=S.map(t=>` ${t}`).join(`
1098
1098
  `);return{postinst:[`#!/bin/sh`,`set -e`,`if [ "$1" = "configure" ]; then`,C,`fi`,``].join(`
1099
1099
  `),postrm:[`#!/bin/sh`,`set -e`,`if [ "$1" = "remove" ]; then`,C,`fi`,``].join(`
1100
1100
  `)}}function renderRpmScriptlets(t,n){let S=cacheRefreshCommands(t,n);if(S.length===0)return{};let C=`${S.join(`
1101
- `)}\n`;return{post:C,postun:C}}var wB=__esmMin(()=>{CB()});function isSymbolicIcon(t){return On(t).toLowerCase()===`.svg`?/(?:^|[\\/])symbolic[\\/]/.test(t)?!0:Dn(t,On(t)).endsWith(`-symbolic`):!1}function iconThemeDir(t){if(isSymbolicIcon(t))return`symbolic`;if(On(t).toLowerCase()===`.svg`)return`scalable`;let n=/(?:^|[\\/])(\d{1,4})x\1(?:[\\/]|$)/.exec(t);if(n)return`${n[1]}x${n[1]}`;let S=Dn(t,On(t)).split(/[-_.]/);for(let t=S.length-1;t>=0;t--){let n=S[t];if(n!==void 0&&/^\d{1,4}$/.test(n))return`${n}x${n}`}throw Error(`gjsify ship: cannot tell what size ${t} is. Put it in a \`<size>x<size>/\` directory, end its name with the size (\`icon-128.png\`), or ship an SVG.`)}function readPngSize(t,n){if(t.length<33||EB.some((n,S)=>t[S]!==n))throw Error(`gjsify ship: ${n} is not a PNG — it does not start with the PNG signature.`);let S=new DataView(t.buffer,t.byteOffset,t.byteLength);if(S.getUint32(8)!==13||Buffer.from(t.subarray(12,16)).toString(`latin1`)!==`IHDR`)throw Error(`gjsify ship: ${n} is not a PNG this command can read — its first chunk is not IHDR.`);let C=t.length-DB.length;if(DB.some((n,S)=>t[C+S]!==n))throw Error(`gjsify ship: ${n} is truncated — it does not end with an IEND chunk, so it would embed as a picture that decodes to nothing.`);return{width:S.getUint32(16),height:S.getUint32(20)}}function rasterizerEnv(t={}){return{...t.env??process.env,...buildNativeEnv([],t)}}async function rasterizeSvg(t){if(t.sizes.length===0)return new Map;let n=t.command??`gjsify ship`,S=await(t.spawn??spawnToCompletion)(`gjs`,[`-c`,OB,t.svg,...t.sizes.map(String)],{completion:`return`,stdio:`capture`,env:rasterizerEnv(),maxBuffer:64*1024*1024,notFound:()=>Error(`${n}: \`gjs\` is not on PATH, and it is what renders ${t.svg} into the sizes an icon needs on this OS. ${TB}.`)}),C=S.stdout??``;if(S.code!==0){let C=(S.stderr??``).trim(),N=/Rsvg|Typelib|cairo/i.test(C)?` The Rsvg typelib or GJS's cairo binding is missing. ${TB}.`:``;throw Error(`${n}: rendering ${t.svg} through gjs failed (exit ${S.code??S.signal}).${N}${C===``?``:`\n ${C.split(`
1101
+ `)}\n`;return{post:C,postun:C}}var kB=__esmMin(()=>{OB()});function isSymbolicIcon(t){return On(t).toLowerCase()===`.svg`?/(?:^|[\\/])symbolic[\\/]/.test(t)?!0:Dn(t,On(t)).endsWith(`-symbolic`):!1}function iconThemeDir(t){if(isSymbolicIcon(t))return`symbolic`;if(On(t).toLowerCase()===`.svg`)return`scalable`;let n=/(?:^|[\\/])(\d{1,4})x\1(?:[\\/]|$)/.exec(t);if(n)return`${n[1]}x${n[1]}`;let S=Dn(t,On(t)).split(/[-_.]/);for(let t=S.length-1;t>=0;t--){let n=S[t];if(n!==void 0&&/^\d{1,4}$/.test(n))return`${n}x${n}`}throw Error(`gjsify ship: cannot tell what size ${t} is. Put it in a \`<size>x<size>/\` directory, end its name with the size (\`icon-128.png\`), or ship an SVG.`)}function readPngSize(t,n){if(t.length<33||jB.some((n,S)=>t[S]!==n))throw Error(`gjsify ship: ${n} is not a PNG — it does not start with the PNG signature.`);let S=new DataView(t.buffer,t.byteOffset,t.byteLength);if(S.getUint32(8)!==13||Buffer.from(t.subarray(12,16)).toString(`latin1`)!==`IHDR`)throw Error(`gjsify ship: ${n} is not a PNG this command can read — its first chunk is not IHDR.`);let C=t.length-MB.length;if(MB.some((n,S)=>t[C+S]!==n))throw Error(`gjsify ship: ${n} is truncated — it does not end with an IEND chunk, so it would embed as a picture that decodes to nothing.`);return{width:S.getUint32(16),height:S.getUint32(20)}}function rasterizerEnv(t={}){return{...t.env??process.env,...buildNativeEnv([],t)}}async function rasterizeSvg(t){if(t.sizes.length===0)return new Map;let n=t.command??`gjsify ship`,S=await(t.spawn??spawnToCompletion)(`gjs`,[`-c`,NB,t.svg,...t.sizes.map(String)],{completion:`return`,stdio:`capture`,env:rasterizerEnv(),maxBuffer:64*1024*1024,notFound:()=>Error(`${n}: \`gjs\` is not on PATH, and it is what renders ${t.svg} into the sizes an icon needs on this OS. ${AB}.`)}),C=S.stdout??``;if(S.code!==0){let C=(S.stderr??``).trim(),N=/Rsvg|Typelib|cairo/i.test(C)?` The Rsvg typelib or GJS's cairo binding is missing. ${AB}.`:``;throw Error(`${n}: rendering ${t.svg} through gjs failed (exit ${S.code??S.signal}).${N}${C===``?``:`\n ${C.split(`
1102
1102
  `).join(`
1103
- `)}`}`)}let N;try{N=JSON.parse(C)}catch{throw Error(`${n}: gjs printed something other than the rendered icon while rendering ${t.svg}: ${C.slice(0,200)}`)}let F=new Map;for(let S of t.sizes){let C=N[String(S)];if(C===void 0)throw Error(`${n}: gjs rendered no ${S} px image of ${t.svg}.`);let I=new Uint8Array(Buffer.from(C,`base64`)),{width:H,height:W}=readPngSize(I,`the ${S} px render of ${t.svg}`);if(H!==S||W!==S)throw Error(`${n}: asked gjs for a ${S} px render of ${t.svg} and got ${H}×${W}.`);F.set(S,I)}return F}async function resolveAppIcon(t){let n=t.iconFiles.filter(t=>On(t).toLowerCase()===`.svg`&&!isSymbolicIcon(t)),S=t.iconFiles.filter(t=>On(t).toLowerCase()===`.png`&&!isSymbolicIcon(t)),C=`data/icons/hicolor/scalable/apps/${t.appId}.svg`;if(n.length===0&&S.length===0)throw Error(`gjsify ship: ${t.target} needs the app's icon and the project declares none. Add a scalable SVG at ${C} (or point \`gjsify.ship.icon\` at one) and \`gjsify ship\` renders every size from it. An app with no icon here ships with the generic one, and nothing on the target OS says so.`);let N=n.find(t=>/(?:^|[\\/])scalable[\\/]/.test(t))??n[0],F=new Map,I=new Map;for(let n of S){let S=new Uint8Array(readFileSync(n)),{width:C,height:N}=readPngSize(S,n);if(C!==N)throw Error(`gjsify ship: ${n} is ${C}×${N}, and an app icon is square on every platform that reads one — Windows and macOS both index icon images by one edge length.`);let H=iconThemeDir(n);if(H!==`${C}x${C}`)throw Error(`gjsify ship: ${n} is ${C}×${N} but its path says ${H}. The theme looks the file up by the path, so this icon would be served at the wrong size — move it or resize it.`);if(!t.sizes.includes(C))continue;let W=I.get(C);if(W!==void 0)throw Error(`gjsify ship: ${n} and ${W} are both ${C} px icons. Keep one.`);I.set(C,n),F.set(C,S)}let H=t.sizes.filter(t=>!F.has(t));if(H.length>0){if(N===void 0)throw Error(`gjsify ship: ${t.target} needs the app's icon at ${H.join(`, `)} px and the project ships PNGs only for ${[...F.keys()].sort((t,n)=>t-n).join(`, `)||`no size`}. Add a scalable SVG at ${C} and the rest is rendered from it, or add ${H.map(n=>`data/icons/hicolor/${n}x${n}/apps/${t.appId}.png`).join(`, `)}.`);let n=await(t.rasterize??rasterizeSvg)({svg:N,sizes:H});for(let t of H){let S=n.get(t);if(S===void 0)throw Error(`gjsify ship: ${N} rendered no ${t} px image.`);F.set(t,S)}}return{source:I.size===0?`rendered from ${N}`:H.length===0?`${I.size} sized PNG(s) the project ships`:`${I.size} sized PNG(s) the project ships, the rest rendered from ${N}`,png:F}}function iconSizes(t){return[...t.png.keys()].sort((t,n)=>t-n)}var TB,EB,DB,OB,kB=__esmMin(()=>{Rd(),Pn(),CF(),V_(),TB="Fedora: `sudo dnf install gjs librsvg2`, Debian/Ubuntu: `sudo apt install gjs gir1.2-rsvg-2.0`, macOS: `brew install gjs librsvg gobject-introspection`",EB=[137,80,78,71,13,10,26,10],DB=[0,0,0,0,73,69,78,68,174,66,96,130],OB=`imports.gi.versions.Rsvg = '2.0';
1103
+ `)}`}`)}let N;try{N=JSON.parse(C)}catch{throw Error(`${n}: gjs printed something other than the rendered icon while rendering ${t.svg}: ${C.slice(0,200)}`)}let F=new Map;for(let S of t.sizes){let C=N[String(S)];if(C===void 0)throw Error(`${n}: gjs rendered no ${S} px image of ${t.svg}.`);let I=new Uint8Array(Buffer.from(C,`base64`)),{width:H,height:W}=readPngSize(I,`the ${S} px render of ${t.svg}`);if(H!==S||W!==S)throw Error(`${n}: asked gjs for a ${S} px render of ${t.svg} and got ${H}×${W}.`);F.set(S,I)}return F}async function resolveAppIcon(t){let n=t.iconFiles.filter(t=>On(t).toLowerCase()===`.svg`&&!isSymbolicIcon(t)),S=t.iconFiles.filter(t=>On(t).toLowerCase()===`.png`&&!isSymbolicIcon(t)),C=`data/icons/hicolor/scalable/apps/${t.appId}.svg`;if(n.length===0&&S.length===0)throw Error(`gjsify ship: ${t.target} needs the app's icon and the project declares none. Add a scalable SVG at ${C} (or point \`gjsify.ship.icon\` at one) and \`gjsify ship\` renders every size from it. An app with no icon here ships with the generic one, and nothing on the target OS says so.`);let N=n.find(t=>/(?:^|[\\/])scalable[\\/]/.test(t))??n[0],F=new Map,I=new Map;for(let n of S){let S=new Uint8Array(readFileSync(n)),{width:C,height:N}=readPngSize(S,n);if(C!==N)throw Error(`gjsify ship: ${n} is ${C}×${N}, and an app icon is square on every platform that reads one — Windows and macOS both index icon images by one edge length.`);let H=iconThemeDir(n);if(H!==`${C}x${C}`)throw Error(`gjsify ship: ${n} is ${C}×${N} but its path says ${H}. The theme looks the file up by the path, so this icon would be served at the wrong size — move it or resize it.`);if(!t.sizes.includes(C))continue;let W=I.get(C);if(W!==void 0)throw Error(`gjsify ship: ${n} and ${W} are both ${C} px icons. Keep one.`);I.set(C,n),F.set(C,S)}let H=t.sizes.filter(t=>!F.has(t));if(H.length>0){if(N===void 0)throw Error(`gjsify ship: ${t.target} needs the app's icon at ${H.join(`, `)} px and the project ships PNGs only for ${[...F.keys()].sort((t,n)=>t-n).join(`, `)||`no size`}. Add a scalable SVG at ${C} and the rest is rendered from it, or add ${H.map(n=>`data/icons/hicolor/${n}x${n}/apps/${t.appId}.png`).join(`, `)}.`);let n=await(t.rasterize??rasterizeSvg)({svg:N,sizes:H});for(let t of H){let S=n.get(t);if(S===void 0)throw Error(`gjsify ship: ${N} rendered no ${t} px image.`);F.set(t,S)}}return{source:I.size===0?`rendered from ${N}`:H.length===0?`${I.size} sized PNG(s) the project ships`:`${I.size} sized PNG(s) the project ships, the rest rendered from ${N}`,png:F}}function iconSizes(t){return[...t.png.keys()].sort((t,n)=>t-n)}var AB,jB,MB,NB,PB=__esmMin(()=>{Rd(),Pn(),CF(),V_(),AB="Fedora: `sudo dnf install gjs librsvg2`, Debian/Ubuntu: `sudo apt install gjs gir1.2-rsvg-2.0`, macOS: `brew install gjs librsvg gobject-introspection`",jB=[137,80,78,71,13,10,26,10],MB=[0,0,0,0,73,69,78,68,174,66,96,130],NB=`imports.gi.versions.Rsvg = '2.0';
1104
1104
  const { Rsvg, GLib } = imports.gi;
1105
1105
  const Cairo = imports.cairo;
1106
1106
  const [svg, ...sizes] = ARGV;
@@ -1119,58 +1119,58 @@ for (const text of sizes) {
1119
1119
  GLib.unlink(path);
1120
1120
  out[size] = GLib.base64_encode(bytes);
1121
1121
  }
1122
- print(JSON.stringify(out));`});function head(t,n){let S=Buffer.alloc(8);return S.write(t,0,`latin1`),S.writeUInt32BE(n,4),new Uint8Array(S)}function buildIcns(t){let n=AB.map(n=>{let S=t.png.get(n.size);if(S===void 0)throw Error(`gjsify ship: the macOS icon needs a ${n.size} px image (${n.iconset}) and the raster set has none — \`resolveAppIcon\` was asked for the wrong sizes.`);let{width:C,height:N}=readPngSize(S,`the ${n.size} px icon image`);if(C!==n.size||N!==n.size)throw Error(`gjsify ship: the image keyed ${n.size} in the icon raster set is ${C}×${N}.`);return{...n,png:S}}),S=concatBytes([head(`TOC `,8+8*n.length),...n.map(t=>head(t.type,8+t.png.length))]),C=n.map(t=>concatBytes([head(t.type,8+t.png.length),t.png]));return concatBytes([head(`icns`,8+S.length+C.reduce((t,n)=>t+n.length,0)),S,...C])}var AB,jB,MB=__esmMin(()=>{cB(),kB(),AB=[{type:`icp4`,size:16,iconset:`icon_16x16.png`},{type:`ic11`,size:32,iconset:`icon_16x16@2x.png`},{type:`icp5`,size:32,iconset:`icon_32x32.png`},{type:`ic12`,size:64,iconset:`icon_32x32@2x.png`},{type:`ic07`,size:128,iconset:`icon_128x128.png`},{type:`ic13`,size:256,iconset:`icon_128x128@2x.png`},{type:`ic08`,size:256,iconset:`icon_256x256.png`},{type:`ic14`,size:512,iconset:`icon_256x256@2x.png`},{type:`ic09`,size:512,iconset:`icon_512x512.png`},{type:`ic10`,size:1024,iconset:`icon_512x512@2x.png`}],jB=[...new Set(AB.map(t=>t.size))].sort((t,n)=>t-n)});function entryHead(t){let n=Buffer.alloc(8);return n.writeUInt8(t>=256?0:t,0),n.writeUInt8(t>=256?0:t,1),n.writeUInt8(0,2),n.writeUInt8(0,3),n.writeUInt16LE(1,4),n.writeUInt16LE(32,6),new Uint8Array(n)}function entries(t){let n=[];for(let S of NB){let C=t.png.get(S);if(C===void 0)throw Error(`gjsify ship: the Windows icon needs a ${S} px image and the raster set has none — \`resolveAppIcon\` was asked for the wrong sizes (it has ${[...t.png.keys()].join(`, `)}).`);let{width:N,height:F}=readPngSize(C,`the ${S} px icon image`);if(N!==S||F!==S)throw Error(`gjsify ship: the image keyed ${S} in the icon raster set is ${N}×${F}.`);if(S>256)throw Error(`gjsify ship: a Windows icon image cannot be ${S} px — 256 is the format's ceiling.`);n.push({size:S,png:C})}return n}function iconResources(t){let n=entries(t),S=Buffer.alloc(6);S.writeUInt16LE(0,0),S.writeUInt16LE(1,2),S.writeUInt16LE(n.length,4);let C=[];return n.forEach(({size:t,png:n},S)=>{let N=Buffer.alloc(6);N.writeUInt32LE(n.length,0),N.writeUInt16LE(S+1,4),C.push(entryHead(t),new Uint8Array(N))}),{group:concatBytes([new Uint8Array(S),...C]),icons:n.map(t=>t.png)}}var NB,PB=__esmMin(()=>{cB(),kB(),NB=[16,24,32,48,64,256]});function movImm32(t,n,S){let C={eax:184,ecx:185,edx:186,r8d:184,r9d:185,r14d:190}[n];(n===`r8d`||n===`r9d`||n===`r14d`)&&t.push(65),t.push(C);let N=Buffer.alloc(4);N.writeInt32LE(S|0),t.push(...N)}function movStackDword(t,n,S){t.push(199,132,36);let C=Buffer.alloc(4);C.writeInt32LE(n),t.push(...C);let N=Buffer.alloc(4);N.writeInt32LE(S|0),t.push(...N)}function movStackFromReg(t,n,S){let C={rax:132,rbx:156,rsi:180,rdi:188}[n];t.push(72,137,C,36);let N=Buffer.alloc(4);N.writeInt32LE(S),t.push(...N)}function movRaxFromStack(t,n){t.push(72,139,132,36);let S=Buffer.alloc(4);S.writeInt32LE(n),t.push(...S)}function leaStack(t,n,S){let C={rax:132,rcx:140,rdx:148,rdi:188,r9:140}[n];t.push(n===`r9`?76:72,141,C,36);let N=Buffer.alloc(4);N.writeInt32LE(S),t.push(...N)}function buildResourceSection(t,n){let S=t.icons.length,iconLangAt=t=>48+S*8+t*24,C=iconLangAt(S),N=C+16+8,F=N+16+8,dataEntryAt=t=>F+t*16,I=align(dataEntryAt(S+1),8),H=[];for(let n of[...t.icons,t.group])H.push({at:I,bytes:n}),I=align(I+n.length,8);let W=Buffer.alloc(I),directory=(t,n)=>{W.writeUInt16LE(0,t+12),W.writeUInt16LE(n,t+14)},entry=(t,n,S,C)=>{W.writeUInt32LE(n,t),W.writeUInt32LE(C?(2147483648|S)>>>0:S,t+4)},dataEntry=(t,S)=>{W.writeUInt32LE(n+S.at,dataEntryAt(t)),W.writeUInt32LE(S.bytes.length,dataEntryAt(t)+4)};directory(0,2),entry(16,3,32,!0),entry(24,14,C,!0),directory(32,S);for(let t=0;t<S;t++)entry(48+t*8,t+1,iconLangAt(t),!0),directory(iconLangAt(t),1),entry(iconLangAt(t)+16,ZB,dataEntryAt(t),!1),dataEntry(t,H[t]);directory(C,1),entry(C+16,1,N,!0),directory(N,1),entry(N+16,ZB,dataEntryAt(S),!1),dataEntry(S,H[S]);for(let t of H)W.set(t.bytes,t.at);return new Uint8Array(W)}function emitStub(){let t=new Emitter;t.push(72,131,228,240),t.push(72,129,236,VB.size&255,VB.size>>8&255,0,0),leaStack(t,`rdi`,VB.args),t.push(49,192),movImm32(t,`ecx`,(VB.size-VB.args)/8),t.push(243,72,171),t.push(49,201),t.leaRip(`rdx`,`selfBuf`),movImm32(t,`r8d`,XB.selfBuf),t.callImport(`GetModuleFileNameW`),t.push(131,248,4),t.jcc(`b`,`fail`),t.leaRip(`rdx`,`selfBuf`),t.push(137,193),t.push(72,141,4,74),t.push(102,199,64,250,99,0),t.push(102,199,64,252,109,0),t.push(102,199,64,254,100,0),t.leaRip(`rcx`,`sysBuf`),movImm32(t,`edx`,XB.sysBuf),t.callImport(`GetSystemDirectoryW`),t.leaRip(`rcx`,`cmdBuf`),t.leaRip(`rdx`,`strQuote`),t.callImport(`lstrcpyW`);for(let n of[`sysBuf`,`strCmdExe`,`selfBuf`,`strQuoteSpace`])t.leaRip(`rcx`,`cmdBuf`),t.leaRip(`rdx`,n),t.callImport(`lstrcatW`);t.callImport(`GetCommandLineW`),t.push(72,137,194),t.push(102,131,58,34),t.jcc(`ne`,`skipPlain`),t.push(72,131,194,2),t.label(`skipQuoted`),t.push(102,139,2),t.push(102,133,192),t.jcc(`e`,`argsReady`),t.push(72,131,194,2),t.push(102,131,248,34),t.jcc(`ne`,`skipQuoted`),t.jmp(`skipSpace`),t.label(`skipPlain`),t.push(102,139,2),t.push(102,133,192),t.jcc(`e`,`argsReady`),t.push(102,131,248,32),t.jcc(`e`,`skipSpace`),t.push(102,131,248,9),t.jcc(`e`,`skipSpace`),t.push(72,131,194,2),t.jmp(`skipPlain`),t.label(`skipSpace`),t.push(102,139,2),t.push(102,131,248,32),t.jcc(`e`,`skipSpaceStep`),t.push(102,131,248,9),t.jcc(`ne`,`argsReady`),t.label(`skipSpaceStep`),t.push(72,131,194,2),t.jmp(`skipSpace`),t.label(`argsReady`),t.leaRip(`rcx`,`cmdBuf`),t.callImport(`lstrcatW`),t.leaRip(`rcx`,`cmdBuf`),t.leaRip(`rdx`,`strQuote`),t.callImport(`lstrcatW`),movImm32(t,`ecx`,-10),t.callImport(`GetStdHandle`),t.push(72,137,199),movImm32(t,`ecx`,-11),t.callImport(`GetStdHandle`),t.push(72,137,195),movImm32(t,`ecx`,-12),t.callImport(`GetStdHandle`),t.push(72,137,198),t.callImport(`GetConsoleCP`),t.push(133,192),t.jcc(`ne`,`haveConsole`),movImm32(t,`r14d`,GB),t.push(72,133,219),t.jcc(`e`,`needLog`),t.push(72,131,251,255),t.jcc(`e`,`needLog`),t.push(72,133,246),t.jcc(`e`,`needLog`),t.push(72,131,254,255),t.jcc(`ne`,`useStdHandles`),t.label(`needLog`),movImm32(t,`ecx`,XB.tmpBuf),t.leaRip(`rdx`,`tmpBuf`),t.callImport(`GetTempPathW`),t.leaRip(`rcx`,`logBuf`),t.leaRip(`rdx`,`tmpBuf`),t.callImport(`lstrcpyW`),t.leaRip(`rcx`,`logBuf`),t.leaRip(`rdx`,`strLogLeaf`),t.callImport(`lstrcatW`),t.leaRip(`rcx`,`logBuf`),movImm32(t,`edx`,KB),movImm32(t,`r8d`,qB),leaStack(t,`r9`,VB.securityAttributes),movStackDword(t,VB.securityAttributes,UB),movStackDword(t,VB.securityAttributes+16,1),movStackDword(t,VB.args,JB),movStackDword(t,VB.args+8,YB),movStackDword(t,VB.args+16,0),t.callImport(`CreateFileW`),t.push(72,131,248,255),t.jcc(`e`,`create`),t.push(72,133,219),t.jcc(`e`,`logIsStdout`),t.push(72,131,251,255),t.jcc(`ne`,`stdoutKept`),t.label(`logIsStdout`),t.push(72,137,195),t.label(`stdoutKept`),t.push(72,133,246),t.jcc(`e`,`logIsStderr`),t.push(72,131,254,255),t.jcc(`ne`,`useStdHandles`),t.label(`logIsStderr`),t.push(72,137,198),t.label(`useStdHandles`),movStackFromReg(t,`rdi`,VB.startupInfo+80),movStackFromReg(t,`rbx`,VB.startupInfo+88),movStackFromReg(t,`rsi`,VB.startupInfo+96),movStackDword(t,VB.startupInfo+60,WB),t.jmp(`create`),t.label(`haveConsole`),t.push(69,49,246),t.label(`create`),movStackDword(t,VB.startupInfo,HB),t.push(49,201),t.leaRip(`rdx`,`cmdBuf`),t.push(69,49,192),t.push(69,49,201),movStackDword(t,VB.args,1),t.push(68,137,180,36);{let n=Buffer.alloc(4);n.writeInt32LE(VB.args+8),t.push(...n)}movStackDword(t,VB.args+16,0),movStackDword(t,VB.args+24,0),leaStack(t,`rax`,VB.startupInfo),movStackFromReg(t,`rax`,VB.args+32),leaStack(t,`rax`,VB.processInformation),movStackFromReg(t,`rax`,VB.args+40),t.callImport(`CreateProcessW`),t.push(133,192),t.jcc(`e`,`fail`),movRaxFromStack(t,VB.processInformation),t.push(72,137,193),movImm32(t,`edx`,-1),t.callImport(`WaitForSingleObject`),movRaxFromStack(t,VB.processInformation),t.push(72,137,193),leaStack(t,`rdx`,VB.exitCode),t.callImport(`GetExitCodeProcess`),t.push(139,140,36);{let n=Buffer.alloc(4);n.writeInt32LE(VB.exitCode),t.push(...n)}return t.callImport(`ExitProcess`),t.label(`fail`),movImm32(t,`ecx`,1),t.callImport(`ExitProcess`),t.push(204),t}function wide(t){return new Uint8Array(Buffer.from(`${t}\0`,`utf16le`))}function dataItems(t){let n=[];for(let t of BB)n.push({symbol:`iat.${t}`,bytes:new Uint8Array(8)});n.push({symbol:`iat.null`,bytes:new Uint8Array(8)}),n.push({symbol:`importDescriptors`,bytes:new Uint8Array(40)});for(let t of BB)n.push({symbol:`ilt.${t}`,bytes:new Uint8Array(8)});n.push({symbol:`ilt.null`,bytes:new Uint8Array(8)});for(let t of BB){let S=Buffer.from(`\0\0${t}\0`,`latin1`);n.push({symbol:`hint.${t}`,bytes:new Uint8Array(S.length%2==0?S:Buffer.concat([S,Buffer.alloc(1)]))})}n.push({symbol:`dllName`,bytes:new Uint8Array(Buffer.from(`KERNEL32.dll\0\0`,`latin1`))}),n.push({symbol:`strQuote`,bytes:wide(`"`)}),n.push({symbol:`strCmdExe`,bytes:wide(`\\cmd.exe" /s /c ""`)}),n.push({symbol:`strQuoteSpace`,bytes:wide(`" `)}),n.push({symbol:`strLogLeaf`,bytes:wide(t.logLeaf)});for(let[t,S]of Object.entries(XB))n.push({symbol:t,bytes:new Uint8Array(S*2)});return n}function align(t,n){return Math.ceil(t/n)*n}function buildGuiLauncher(t){if(t.logLeaf===``||/[\\/:*?"<>|]/.test(t.logLeaf))throw Error(`gjsify ship: "${t.logLeaf}" cannot be the launcher's log file name — it is empty or holds a character Windows refuses in one. The stub writes it into \`%TEMP%\`, so the value is a leaf and never a path.`);let n=emitStub(),S=n.bytes.length,C=RB,N=C+align(S,RB),F=dataItems(t),I=new Map,H=0;for(let t of F)I.set(t.symbol,H),H+=t.bytes.length;let W=H,rvaOf=t=>{let n=I.get(t);if(n===void 0)throw Error(`gjsify ship: the launcher stub names no datum "${t}".`);return N+n},q=Buffer.alloc(W);for(let t of F)q.set(t.bytes,I.get(t.symbol)??0);q.writeUInt32LE(rvaOf(`ilt.GetModuleFileNameW`),I.get(`importDescriptors`)??0),q.writeUInt32LE(rvaOf(`dllName`),(I.get(`importDescriptors`)??0)+12),q.writeUInt32LE(rvaOf(`iat.GetModuleFileNameW`),(I.get(`importDescriptors`)??0)+16);for(let t of BB){let n=BigInt(rvaOf(`hint.${t}`));q.writeBigUInt64LE(n,I.get(`ilt.${t}`)??0),q.writeBigUInt64LE(n,I.get(`iat.${t}`)??0)}let Y=n.resolve(C,rvaOf),X=align(S,LB),Z=align(W,LB),te=LB,ne=te,re=ne+X,ie=N+align(W,RB),ae=t.icon===void 0?void 0:buildResourceSection(t.icon,ie),oe=ae===void 0?0:align(ae.length,LB),Q=re+Z,se=ae===void 0?2:3,ce=ae===void 0?N+align(W,RB):ie+align(ae.length,RB),le=Buffer.alloc(Q+oe);le.write(`MZ`,0,`ascii`),le.write(`This program cannot be run in DOS mode.\r\r
1123
- $`,64,`ascii`),le.writeUInt32LE(IB,60),le.write(`PE\0\0`,IB,`ascii`),le.writeUInt16LE(FB,132),le.writeUInt16LE(se,134),le.writeUInt32LE(0,136),le.writeUInt16LE(240,148),le.writeUInt16LE(35,150),le.writeUInt16LE(523,152),le.writeUInt8(14,154),le.writeUInt32LE(X,156),le.writeUInt32LE(Z+oe,160),le.writeUInt32LE(C,168),le.writeUInt32LE(C,172),le.writeBigUInt64LE(zB,176),le.writeUInt32LE(RB,184),le.writeUInt32LE(LB,188),le.writeUInt16LE(6,192),le.writeUInt16LE(6,200),le.writeUInt32LE(ce,208),le.writeUInt32LE(te,212),le.writeUInt16LE(2,220),le.writeUInt16LE(33024,222),le.writeBigUInt64LE(1048576n,224),le.writeBigUInt64LE(4096n,232),le.writeBigUInt64LE(1048576n,240),le.writeBigUInt64LE(4096n,248),le.writeUInt32LE(16,260),le.writeUInt32LE(rvaOf(`importDescriptors`),272),le.writeUInt32LE(40,276),le.writeUInt32LE(rvaOf(`iat.GetModuleFileNameW`),360),le.writeUInt32LE((BB.length+1)*8,364),ae!==void 0&&(le.writeUInt32LE(ie,280),le.writeUInt32LE(ae.length,284));let writeSection=(t,n,S,C,N,F,I)=>{let H=392+t*40;le.write(n.padEnd(8,`\0`),H,`latin1`),le.writeUInt32LE(C,H+8),le.writeUInt32LE(S,H+12),le.writeUInt32LE(F,H+16),le.writeUInt32LE(N,H+20),le.writeUInt32LE(I,H+36)};return writeSection(0,`.text`,C,S,ne,X,1610612768),writeSection(1,`.data`,N,W,re,Z,3221225536),ae!==void 0&&writeSection(2,`.rsrc`,ie,ae.length,Q,oe,1073741888),le.set(Y,ne),le.set(q,re),ae!==void 0&&le.set(ae,Q),new Uint8Array(le)}var FB,IB,LB,RB,zB,BB,Emitter,VB,HB,UB,WB,GB,KB,qB,JB,YB,XB,ZB,QB=__esmMin(()=>{PB(),FB=34404,IB=128,LB=512,RB=4096,zB=5368709120n,BB=[`GetModuleFileNameW`,`GetSystemDirectoryW`,`GetCommandLineW`,`GetConsoleCP`,`GetStdHandle`,`GetTempPathW`,`CreateFileW`,`CreateProcessW`,`WaitForSingleObject`,`GetExitCodeProcess`,`ExitProcess`,`lstrcpyW`,`lstrcatW`],Emitter=class{bytes=[];labels=new Map;ripFixups=[];branchFixups=[];push(...t){for(let n of t)this.bytes.push(n&255)}label(t){this.labels.set(t,this.bytes.length)}ripSlot(t){this.ripFixups.push({at:this.bytes.length,symbol:t}),this.push(0,0,0,0)}branchSlot(t){this.branchFixups.push({at:this.bytes.length,label:t}),this.push(0,0,0,0)}leaRip(t,n){let S={rax:5,rcx:13,rdx:21,rdi:61,r8:5,r9:13}[t];this.push(t===`r8`||t===`r9`?76:72,141,S),this.ripSlot(n)}callImport(t){this.push(255,21),this.ripSlot(`iat.${t}`)}jmp(t){this.push(233),this.branchSlot(t)}jcc(t,n){this.push(15,{e:132,ne:133,b:130}[t]),this.branchSlot(n)}resolve(t,n){let S=Buffer.from(this.bytes);for(let{at:C,symbol:N}of this.ripFixups)S.writeInt32LE(n(N)-(t+C+4),C);for(let{at:t,label:n}of this.branchFixups){let C=this.labels.get(n);if(C===void 0)throw Error(`gjsify ship: the launcher stub jumps to no label "${n}".`);S.writeInt32LE(C-(t+4),t)}return new Uint8Array(S)}},VB={args:32,securityAttributes:80,startupInfo:112,processInformation:216,exitCode:240,size:272},HB=104,UB=24,WB=256,GB=134217728,KB=1073741824,qB=3,JB=2,YB=128,XB={sysBuf:264,selfBuf:520,tmpBuf:264,logBuf:600,cmdBuf:4096},ZB=1033});function xmlText(t){return t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function assertPlistText(t,n,S){let C=-1;for(let n of t){let t=n.codePointAt(0)??0;if(t<32&&t!==9&&t!==10&&t!==13){C=t;break}}if(C!==-1)throw Error(`gjsify ship: ${n} would carry the control character U+${C.toString(16).padStart(4,`0`).toUpperCase()}, and XML has no escape for it — the Info.plist would be unparseable by every reader macOS has. Set \`${S}\` to a value without it.`);return t}function stringEntry(t,n){return`\t<key>${t}</key>\n\t<string>${xmlText(n)}</string>`}function arrayEntry(t,n){return`\t<key>${t}</key>\n\t<array>\n${n.map(t=>`\t\t<string>${xmlText(t)}</string>`).join(`
1124
- `)}\n\t</array>`}function renderInfoPlist(t,n,S){let C=assertPlistText(t.name,`CFBundleName`,`gjsify.ship.name`),N=assertPlistText(t.binaryName,`CFBundleExecutable`,`gjsify.ship.binaryName`),F=assertPlistText(t.appId,`CFBundleIdentifier`,`gjsify.ship.appId`);return[`<?xml version="1.0" encoding="UTF-8"?>`,`<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">`,`<plist version="1.0">`,`<dict>`,...n===void 0?[]:[stringEntry(`ATSApplicationFontsPath`,n)],stringEntry(`CFBundleDevelopmentRegion`,`en`),stringEntry(`CFBundleDisplayName`,C),stringEntry(`CFBundleExecutable`,N),...S===void 0?[]:[stringEntry(`CFBundleIconFile`,S)],stringEntry(`CFBundleIdentifier`,F),stringEntry(`CFBundleInfoDictionaryVersion`,`6.0`),stringEntry(`CFBundleName`,C),stringEntry(`CFBundlePackageType`,nV),stringEntry(`CFBundleShortVersionString`,t.version),stringEntry(`CFBundleSignature`,rV),arrayEntry(`CFBundleSupportedPlatforms`,[`MacOSX`]),stringEntry(`CFBundleVersion`,`${t.version}-${t.release}`),`</dict>`,`</plist>`,``].join(`
1125
- `)}function renderPkgInfo(){return`${nV}${rV}`}function renderEntitlements(t){return[`<?xml version="1.0" encoding="UTF-8"?>`,`<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">`,`<plist version="1.0">`,`<dict>`,t.map(t=>`\t<key>${xmlText(t)}</key>\n\t<true/>`).join(`
1122
+ print(JSON.stringify(out));`});function head(t,n){let S=Buffer.alloc(8);return S.write(t,0,`latin1`),S.writeUInt32BE(n,4),new Uint8Array(S)}function buildIcns(t){let n=FB.map(n=>{let S=t.png.get(n.size);if(S===void 0)throw Error(`gjsify ship: the macOS icon needs a ${n.size} px image (${n.iconset}) and the raster set has none — \`resolveAppIcon\` was asked for the wrong sizes.`);let{width:C,height:N}=readPngSize(S,`the ${n.size} px icon image`);if(C!==n.size||N!==n.size)throw Error(`gjsify ship: the image keyed ${n.size} in the icon raster set is ${C}×${N}.`);return{...n,png:S}}),S=concatBytes([head(`TOC `,8+8*n.length),...n.map(t=>head(t.type,8+t.png.length))]),C=n.map(t=>concatBytes([head(t.type,8+t.png.length),t.png]));return concatBytes([head(`icns`,8+S.length+C.reduce((t,n)=>t+n.length,0)),S,...C])}var FB,IB,LB=__esmMin(()=>{pB(),PB(),FB=[{type:`icp4`,size:16,iconset:`icon_16x16.png`},{type:`ic11`,size:32,iconset:`icon_16x16@2x.png`},{type:`icp5`,size:32,iconset:`icon_32x32.png`},{type:`ic12`,size:64,iconset:`icon_32x32@2x.png`},{type:`ic07`,size:128,iconset:`icon_128x128.png`},{type:`ic13`,size:256,iconset:`icon_128x128@2x.png`},{type:`ic08`,size:256,iconset:`icon_256x256.png`},{type:`ic14`,size:512,iconset:`icon_256x256@2x.png`},{type:`ic09`,size:512,iconset:`icon_512x512.png`},{type:`ic10`,size:1024,iconset:`icon_512x512@2x.png`}],IB=[...new Set(FB.map(t=>t.size))].sort((t,n)=>t-n)});function entryHead(t){let n=Buffer.alloc(8);return n.writeUInt8(t>=256?0:t,0),n.writeUInt8(t>=256?0:t,1),n.writeUInt8(0,2),n.writeUInt8(0,3),n.writeUInt16LE(1,4),n.writeUInt16LE(32,6),new Uint8Array(n)}function entries(t){let n=[];for(let S of RB){let C=t.png.get(S);if(C===void 0)throw Error(`gjsify ship: the Windows icon needs a ${S} px image and the raster set has none — \`resolveAppIcon\` was asked for the wrong sizes (it has ${[...t.png.keys()].join(`, `)}).`);let{width:N,height:F}=readPngSize(C,`the ${S} px icon image`);if(N!==S||F!==S)throw Error(`gjsify ship: the image keyed ${S} in the icon raster set is ${N}×${F}.`);if(S>256)throw Error(`gjsify ship: a Windows icon image cannot be ${S} px — 256 is the format's ceiling.`);n.push({size:S,png:C})}return n}function iconResources(t){let n=entries(t),S=Buffer.alloc(6);S.writeUInt16LE(0,0),S.writeUInt16LE(1,2),S.writeUInt16LE(n.length,4);let C=[];return n.forEach(({size:t,png:n},S)=>{let N=Buffer.alloc(6);N.writeUInt32LE(n.length,0),N.writeUInt16LE(S+1,4),C.push(entryHead(t),new Uint8Array(N))}),{group:concatBytes([new Uint8Array(S),...C]),icons:n.map(t=>t.png)}}var RB,zB=__esmMin(()=>{pB(),PB(),RB=[16,24,32,48,64,256]});function movImm32(t,n,S){let C={eax:184,ecx:185,edx:186,r8d:184,r9d:185,r14d:190}[n];(n===`r8d`||n===`r9d`||n===`r14d`)&&t.push(65),t.push(C);let N=Buffer.alloc(4);N.writeInt32LE(S|0),t.push(...N)}function movStackDword(t,n,S){t.push(199,132,36);let C=Buffer.alloc(4);C.writeInt32LE(n),t.push(...C);let N=Buffer.alloc(4);N.writeInt32LE(S|0),t.push(...N)}function movStackFromReg(t,n,S){let C={rax:132,rbx:156,rsi:180,rdi:188}[n];t.push(72,137,C,36);let N=Buffer.alloc(4);N.writeInt32LE(S),t.push(...N)}function movRaxFromStack(t,n){t.push(72,139,132,36);let S=Buffer.alloc(4);S.writeInt32LE(n),t.push(...S)}function leaStack(t,n,S){let C={rax:132,rcx:140,rdx:148,rdi:188,r9:140}[n];t.push(n===`r9`?76:72,141,C,36);let N=Buffer.alloc(4);N.writeInt32LE(S),t.push(...N)}function buildResourceSection(t,n){let S=t.icons.length,iconLangAt=t=>48+S*8+t*24,C=iconLangAt(S),N=C+16+8,F=N+16+8,dataEntryAt=t=>F+t*16,I=align(dataEntryAt(S+1),8),H=[];for(let n of[...t.icons,t.group])H.push({at:I,bytes:n}),I=align(I+n.length,8);let W=Buffer.alloc(I),directory=(t,n)=>{W.writeUInt16LE(0,t+12),W.writeUInt16LE(n,t+14)},entry=(t,n,S,C)=>{W.writeUInt32LE(n,t),W.writeUInt32LE(C?(2147483648|S)>>>0:S,t+4)},dataEntry=(t,S)=>{W.writeUInt32LE(n+S.at,dataEntryAt(t)),W.writeUInt32LE(S.bytes.length,dataEntryAt(t)+4)};directory(0,2),entry(16,3,32,!0),entry(24,14,C,!0),directory(32,S);for(let t=0;t<S;t++)entry(48+t*8,t+1,iconLangAt(t),!0),directory(iconLangAt(t),1),entry(iconLangAt(t)+16,nV,dataEntryAt(t),!1),dataEntry(t,H[t]);directory(C,1),entry(C+16,1,N,!0),directory(N,1),entry(N+16,nV,dataEntryAt(S),!1),dataEntry(S,H[S]);for(let t of H)W.set(t.bytes,t.at);return new Uint8Array(W)}function emitStub(){let t=new Emitter;t.push(72,131,228,240),t.push(72,129,236,KB.size&255,KB.size>>8&255,0,0),leaStack(t,`rdi`,KB.args),t.push(49,192),movImm32(t,`ecx`,(KB.size-KB.args)/8),t.push(243,72,171),t.push(49,201),t.leaRip(`rdx`,`selfBuf`),movImm32(t,`r8d`,tV.selfBuf),t.callImport(`GetModuleFileNameW`),t.push(131,248,4),t.jcc(`b`,`fail`),t.leaRip(`rdx`,`selfBuf`),t.push(137,193),t.push(72,141,4,74),t.push(102,199,64,250,99,0),t.push(102,199,64,252,109,0),t.push(102,199,64,254,100,0),t.leaRip(`rcx`,`sysBuf`),movImm32(t,`edx`,tV.sysBuf),t.callImport(`GetSystemDirectoryW`),t.leaRip(`rcx`,`cmdBuf`),t.leaRip(`rdx`,`strQuote`),t.callImport(`lstrcpyW`);for(let n of[`sysBuf`,`strCmdExe`,`selfBuf`,`strQuoteSpace`])t.leaRip(`rcx`,`cmdBuf`),t.leaRip(`rdx`,n),t.callImport(`lstrcatW`);t.callImport(`GetCommandLineW`),t.push(72,137,194),t.push(102,131,58,34),t.jcc(`ne`,`skipPlain`),t.push(72,131,194,2),t.label(`skipQuoted`),t.push(102,139,2),t.push(102,133,192),t.jcc(`e`,`argsReady`),t.push(72,131,194,2),t.push(102,131,248,34),t.jcc(`ne`,`skipQuoted`),t.jmp(`skipSpace`),t.label(`skipPlain`),t.push(102,139,2),t.push(102,133,192),t.jcc(`e`,`argsReady`),t.push(102,131,248,32),t.jcc(`e`,`skipSpace`),t.push(102,131,248,9),t.jcc(`e`,`skipSpace`),t.push(72,131,194,2),t.jmp(`skipPlain`),t.label(`skipSpace`),t.push(102,139,2),t.push(102,131,248,32),t.jcc(`e`,`skipSpaceStep`),t.push(102,131,248,9),t.jcc(`ne`,`argsReady`),t.label(`skipSpaceStep`),t.push(72,131,194,2),t.jmp(`skipSpace`),t.label(`argsReady`),t.leaRip(`rcx`,`cmdBuf`),t.callImport(`lstrcatW`),t.leaRip(`rcx`,`cmdBuf`),t.leaRip(`rdx`,`strQuote`),t.callImport(`lstrcatW`),movImm32(t,`ecx`,-10),t.callImport(`GetStdHandle`),t.push(72,137,199),movImm32(t,`ecx`,-11),t.callImport(`GetStdHandle`),t.push(72,137,195),movImm32(t,`ecx`,-12),t.callImport(`GetStdHandle`),t.push(72,137,198),t.callImport(`GetConsoleCP`),t.push(133,192),t.jcc(`ne`,`haveConsole`),movImm32(t,`r14d`,XB),t.push(72,133,219),t.jcc(`e`,`needLog`),t.push(72,131,251,255),t.jcc(`e`,`needLog`),t.push(72,133,246),t.jcc(`e`,`needLog`),t.push(72,131,254,255),t.jcc(`ne`,`useStdHandles`),t.label(`needLog`),movImm32(t,`ecx`,tV.tmpBuf),t.leaRip(`rdx`,`tmpBuf`),t.callImport(`GetTempPathW`),t.leaRip(`rcx`,`logBuf`),t.leaRip(`rdx`,`tmpBuf`),t.callImport(`lstrcpyW`),t.leaRip(`rcx`,`logBuf`),t.leaRip(`rdx`,`strLogLeaf`),t.callImport(`lstrcatW`),t.leaRip(`rcx`,`logBuf`),movImm32(t,`edx`,ZB),movImm32(t,`r8d`,QB),leaStack(t,`r9`,KB.securityAttributes),movStackDword(t,KB.securityAttributes,JB),movStackDword(t,KB.securityAttributes+16,1),movStackDword(t,KB.args,$B),movStackDword(t,KB.args+8,eV),movStackDword(t,KB.args+16,0),t.callImport(`CreateFileW`),t.push(72,131,248,255),t.jcc(`e`,`create`),t.push(72,133,219),t.jcc(`e`,`logIsStdout`),t.push(72,131,251,255),t.jcc(`ne`,`stdoutKept`),t.label(`logIsStdout`),t.push(72,137,195),t.label(`stdoutKept`),t.push(72,133,246),t.jcc(`e`,`logIsStderr`),t.push(72,131,254,255),t.jcc(`ne`,`useStdHandles`),t.label(`logIsStderr`),t.push(72,137,198),t.label(`useStdHandles`),movStackFromReg(t,`rdi`,KB.startupInfo+80),movStackFromReg(t,`rbx`,KB.startupInfo+88),movStackFromReg(t,`rsi`,KB.startupInfo+96),movStackDword(t,KB.startupInfo+60,YB),t.jmp(`create`),t.label(`haveConsole`),t.push(69,49,246),t.label(`create`),movStackDword(t,KB.startupInfo,qB),t.push(49,201),t.leaRip(`rdx`,`cmdBuf`),t.push(69,49,192),t.push(69,49,201),movStackDword(t,KB.args,1),t.push(68,137,180,36);{let n=Buffer.alloc(4);n.writeInt32LE(KB.args+8),t.push(...n)}movStackDword(t,KB.args+16,0),movStackDword(t,KB.args+24,0),leaStack(t,`rax`,KB.startupInfo),movStackFromReg(t,`rax`,KB.args+32),leaStack(t,`rax`,KB.processInformation),movStackFromReg(t,`rax`,KB.args+40),t.callImport(`CreateProcessW`),t.push(133,192),t.jcc(`e`,`fail`),movRaxFromStack(t,KB.processInformation),t.push(72,137,193),movImm32(t,`edx`,-1),t.callImport(`WaitForSingleObject`),movRaxFromStack(t,KB.processInformation),t.push(72,137,193),leaStack(t,`rdx`,KB.exitCode),t.callImport(`GetExitCodeProcess`),t.push(139,140,36);{let n=Buffer.alloc(4);n.writeInt32LE(KB.exitCode),t.push(...n)}return t.callImport(`ExitProcess`),t.label(`fail`),movImm32(t,`ecx`,1),t.callImport(`ExitProcess`),t.push(204),t}function wide(t){return new Uint8Array(Buffer.from(`${t}\0`,`utf16le`))}function dataItems(t){let n=[];for(let t of GB)n.push({symbol:`iat.${t}`,bytes:new Uint8Array(8)});n.push({symbol:`iat.null`,bytes:new Uint8Array(8)}),n.push({symbol:`importDescriptors`,bytes:new Uint8Array(40)});for(let t of GB)n.push({symbol:`ilt.${t}`,bytes:new Uint8Array(8)});n.push({symbol:`ilt.null`,bytes:new Uint8Array(8)});for(let t of GB){let S=Buffer.from(`\0\0${t}\0`,`latin1`);n.push({symbol:`hint.${t}`,bytes:new Uint8Array(S.length%2==0?S:Buffer.concat([S,Buffer.alloc(1)]))})}n.push({symbol:`dllName`,bytes:new Uint8Array(Buffer.from(`KERNEL32.dll\0\0`,`latin1`))}),n.push({symbol:`strQuote`,bytes:wide(`"`)}),n.push({symbol:`strCmdExe`,bytes:wide(`\\cmd.exe" /s /c ""`)}),n.push({symbol:`strQuoteSpace`,bytes:wide(`" `)}),n.push({symbol:`strLogLeaf`,bytes:wide(t.logLeaf)});for(let[t,S]of Object.entries(tV))n.push({symbol:t,bytes:new Uint8Array(S*2)});return n}function align(t,n){return Math.ceil(t/n)*n}function buildGuiLauncher(t){if(t.logLeaf===``||/[\\/:*?"<>|]/.test(t.logLeaf))throw Error(`gjsify ship: "${t.logLeaf}" cannot be the launcher's log file name — it is empty or holds a character Windows refuses in one. The stub writes it into \`%TEMP%\`, so the value is a leaf and never a path.`);let n=emitStub(),S=n.bytes.length,C=UB,N=C+align(S,UB),F=dataItems(t),I=new Map,H=0;for(let t of F)I.set(t.symbol,H),H+=t.bytes.length;let W=H,rvaOf=t=>{let n=I.get(t);if(n===void 0)throw Error(`gjsify ship: the launcher stub names no datum "${t}".`);return N+n},q=Buffer.alloc(W);for(let t of F)q.set(t.bytes,I.get(t.symbol)??0);q.writeUInt32LE(rvaOf(`ilt.GetModuleFileNameW`),I.get(`importDescriptors`)??0),q.writeUInt32LE(rvaOf(`dllName`),(I.get(`importDescriptors`)??0)+12),q.writeUInt32LE(rvaOf(`iat.GetModuleFileNameW`),(I.get(`importDescriptors`)??0)+16);for(let t of GB){let n=BigInt(rvaOf(`hint.${t}`));q.writeBigUInt64LE(n,I.get(`ilt.${t}`)??0),q.writeBigUInt64LE(n,I.get(`iat.${t}`)??0)}let Y=n.resolve(C,rvaOf),X=align(S,HB),Z=align(W,HB),te=HB,ne=te,re=ne+X,ie=N+align(W,UB),ae=t.icon===void 0?void 0:buildResourceSection(t.icon,ie),oe=ae===void 0?0:align(ae.length,HB),Q=re+Z,se=ae===void 0?2:3,ce=ae===void 0?N+align(W,UB):ie+align(ae.length,UB),le=Buffer.alloc(Q+oe);le.write(`MZ`,0,`ascii`),le.write(`This program cannot be run in DOS mode.\r\r
1123
+ $`,64,`ascii`),le.writeUInt32LE(VB,60),le.write(`PE\0\0`,VB,`ascii`),le.writeUInt16LE(BB,132),le.writeUInt16LE(se,134),le.writeUInt32LE(0,136),le.writeUInt16LE(240,148),le.writeUInt16LE(35,150),le.writeUInt16LE(523,152),le.writeUInt8(14,154),le.writeUInt32LE(X,156),le.writeUInt32LE(Z+oe,160),le.writeUInt32LE(C,168),le.writeUInt32LE(C,172),le.writeBigUInt64LE(WB,176),le.writeUInt32LE(UB,184),le.writeUInt32LE(HB,188),le.writeUInt16LE(6,192),le.writeUInt16LE(6,200),le.writeUInt32LE(ce,208),le.writeUInt32LE(te,212),le.writeUInt16LE(2,220),le.writeUInt16LE(33024,222),le.writeBigUInt64LE(1048576n,224),le.writeBigUInt64LE(4096n,232),le.writeBigUInt64LE(1048576n,240),le.writeBigUInt64LE(4096n,248),le.writeUInt32LE(16,260),le.writeUInt32LE(rvaOf(`importDescriptors`),272),le.writeUInt32LE(40,276),le.writeUInt32LE(rvaOf(`iat.GetModuleFileNameW`),360),le.writeUInt32LE((GB.length+1)*8,364),ae!==void 0&&(le.writeUInt32LE(ie,280),le.writeUInt32LE(ae.length,284));let writeSection=(t,n,S,C,N,F,I)=>{let H=392+t*40;le.write(n.padEnd(8,`\0`),H,`latin1`),le.writeUInt32LE(C,H+8),le.writeUInt32LE(S,H+12),le.writeUInt32LE(F,H+16),le.writeUInt32LE(N,H+20),le.writeUInt32LE(I,H+36)};return writeSection(0,`.text`,C,S,ne,X,1610612768),writeSection(1,`.data`,N,W,re,Z,3221225536),ae!==void 0&&writeSection(2,`.rsrc`,ie,ae.length,Q,oe,1073741888),le.set(Y,ne),le.set(q,re),ae!==void 0&&le.set(ae,Q),new Uint8Array(le)}var BB,VB,HB,UB,WB,GB,Emitter,KB,qB,JB,YB,XB,ZB,QB,$B,eV,tV,nV,rV=__esmMin(()=>{zB(),BB=34404,VB=128,HB=512,UB=4096,WB=5368709120n,GB=[`GetModuleFileNameW`,`GetSystemDirectoryW`,`GetCommandLineW`,`GetConsoleCP`,`GetStdHandle`,`GetTempPathW`,`CreateFileW`,`CreateProcessW`,`WaitForSingleObject`,`GetExitCodeProcess`,`ExitProcess`,`lstrcpyW`,`lstrcatW`],Emitter=class{bytes=[];labels=new Map;ripFixups=[];branchFixups=[];push(...t){for(let n of t)this.bytes.push(n&255)}label(t){this.labels.set(t,this.bytes.length)}ripSlot(t){this.ripFixups.push({at:this.bytes.length,symbol:t}),this.push(0,0,0,0)}branchSlot(t){this.branchFixups.push({at:this.bytes.length,label:t}),this.push(0,0,0,0)}leaRip(t,n){let S={rax:5,rcx:13,rdx:21,rdi:61,r8:5,r9:13}[t];this.push(t===`r8`||t===`r9`?76:72,141,S),this.ripSlot(n)}callImport(t){this.push(255,21),this.ripSlot(`iat.${t}`)}jmp(t){this.push(233),this.branchSlot(t)}jcc(t,n){this.push(15,{e:132,ne:133,b:130}[t]),this.branchSlot(n)}resolve(t,n){let S=Buffer.from(this.bytes);for(let{at:C,symbol:N}of this.ripFixups)S.writeInt32LE(n(N)-(t+C+4),C);for(let{at:t,label:n}of this.branchFixups){let C=this.labels.get(n);if(C===void 0)throw Error(`gjsify ship: the launcher stub jumps to no label "${n}".`);S.writeInt32LE(C-(t+4),t)}return new Uint8Array(S)}},KB={args:32,securityAttributes:80,startupInfo:112,processInformation:216,exitCode:240,size:272},qB=104,JB=24,YB=256,XB=134217728,ZB=1073741824,QB=3,$B=2,eV=128,tV={sysBuf:264,selfBuf:520,tmpBuf:264,logBuf:600,cmdBuf:4096},nV=1033});function xmlText(t){return t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function assertPlistText(t,n,S){let C=-1;for(let n of t){let t=n.codePointAt(0)??0;if(t<32&&t!==9&&t!==10&&t!==13){C=t;break}}if(C!==-1)throw Error(`gjsify ship: ${n} would carry the control character U+${C.toString(16).padStart(4,`0`).toUpperCase()}, and XML has no escape for it — the Info.plist would be unparseable by every reader macOS has. Set \`${S}\` to a value without it.`);return t}function stringEntry(t,n){return`\t<key>${t}</key>\n\t<string>${xmlText(n)}</string>`}function arrayEntry(t,n){return`\t<key>${t}</key>\n\t<array>\n${n.map(t=>`\t\t<string>${xmlText(t)}</string>`).join(`
1124
+ `)}\n\t</array>`}function renderInfoPlist(t,n,S){let C=assertPlistText(t.name,`CFBundleName`,`gjsify.ship.name`),N=assertPlistText(t.binaryName,`CFBundleExecutable`,`gjsify.ship.binaryName`),F=assertPlistText(t.appId,`CFBundleIdentifier`,`gjsify.ship.appId`);return[`<?xml version="1.0" encoding="UTF-8"?>`,`<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">`,`<plist version="1.0">`,`<dict>`,...n===void 0?[]:[stringEntry(`ATSApplicationFontsPath`,n)],stringEntry(`CFBundleDevelopmentRegion`,`en`),stringEntry(`CFBundleDisplayName`,C),stringEntry(`CFBundleExecutable`,N),...S===void 0?[]:[stringEntry(`CFBundleIconFile`,S)],stringEntry(`CFBundleIdentifier`,F),stringEntry(`CFBundleInfoDictionaryVersion`,`6.0`),stringEntry(`CFBundleName`,C),stringEntry(`CFBundlePackageType`,sV),stringEntry(`CFBundleShortVersionString`,t.version),stringEntry(`CFBundleSignature`,cV),arrayEntry(`CFBundleSupportedPlatforms`,[`MacOSX`]),stringEntry(`CFBundleVersion`,`${t.version}-${t.release}`),`</dict>`,`</plist>`,``].join(`
1125
+ `)}function renderPkgInfo(){return`${sV}${cV}`}function renderEntitlements(t){return[`<?xml version="1.0" encoding="UTF-8"?>`,`<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">`,`<plist version="1.0">`,`<dict>`,t.map(t=>`\t<key>${xmlText(t)}</key>\n\t<true/>`).join(`
1126
1126
  `),`</dict>`,`</plist>`,``].join(`
1127
- `)}var $B,eV,tV,nV,rV,iV=__esmMin(()=>{$B=`Contents/Info.plist`,eV=`Contents/PkgInfo`,tV=`Contents/Resources`,nV=`APPL`,rV=`????`});function darwinFontsPath(t,n){let S=`${SB.fonts}/${t.appId}`,C=n.find(t=>t.path.startsWith(`${S}/`));if(C===void 0)return;let N=sV.darwin.dirs(t);return pn.relative(N.other,pn.dirname(place(sV.darwin,t,C.path)))}function appBundleDir(t){if(aV.test(t.name))throw Error(`gjsify ship: the macOS layout would put this app in "${t.name}.app", and a bundle directory may contain no "/", "\\" or ":" — HFS+ and the Finder swap the first two, so the bundle would not be the one its own metadata names. Set \`gjsify.ship.name\` to the display name you want on disk.`);return`${t.name}.app`}function iconFor(t,n){if(t.kind===`app`){if(t.icon===void 0){if(sV[n].icon?.required!==!0)return;throw Error(`gjsify ship: the ${n} layout writes the application's icon and was given none. A \`kind: "app"\` stage is rendered its icon by \`resolveAppIcon\` before the layout runs; reaching this row without one is a caller that skipped that step.`)}return t.icon}}function launcherPath(t,n){return pn.join(t.dirs(n).launcher,`${n.binaryName}${t.launcherExt}`)}function windowsGuiLauncherPath(t){let n=sV.windows;if(n.launcherExt.length!==4)throw Error(`gjsify ship: the windows launcher extension is "${n.launcherExt}" and the GUI stub can only reach a four-character one — it rewrites the last three characters of its own filename rather than searching for a path (\`utils/ship/pe-launcher.ts\`).`);return pn.join(n.dirs(t).launcher,`${t.binaryName}.exe`)}function windowsLaunchLogLeaf(t){return`${t.binaryName}.launch.log`}function layoutForOs(t){let n=lV.get(t);if(n===void 0)throw Error(`"${t}" is not a \`process.platform\` token this gjsify has a layout for. Known: ${cV.map(t=>sV[t].os).join(`, `)} — the \`\${process.platform}-\${process.arch}\` spelling, so \`win32\` and never \`windows\`.`);return n}function resolveLayout(t){let n=t.trim().toLowerCase();if(Object.hasOwn(sV,n))return sV[n];let S=lV.get(n);if(S!==void 0)return S;throw Error(`gjsify ship: "${t}" is not an operating system this command has a layout for. Known: ${cV.join(`, `)} (\`win32\` is accepted for \`windows\`, because that is the spelling \`--expect-target <os>-<arch>\` uses).`)}function hostLayout(t=process.platform){let n=lV.get(t);if(n===void 0)throw Error(`gjsify ship: this host is ${t}, which has no layout. Name the one you want — \`gjsify ship <${cV.join(`|`)}> --stage\` — assembly is not host-bound (ADR 0024 § A1).`);return n}function assertLayoutSupportsArch(t,n){let S=t.arches;if(!(S===null||S.only.includes(n)))throw Error(`gjsify ship: the ${t.name} layout is not assemblable for \`--arch ${n}\` — ${S.only.length===1?`the only architecture it has`:`the architectures it has`} ${S.only.length===1?`is`:`are`} ${S.only.join(`, `)}.\n ${S.why}.\n \`--arch\` names the architecture the PAYLOAD was built for and cross-compiles nothing, so there is no
1128
- flag that makes this work — the artifact would carry a runtime that does not exist.`)}function place(t,n,S){let C=t.dirs(n);if(S===`bin/${n.binaryName}`)return launcherPath(t,n);let N=`lib/${n.binaryName}/`,F=`${N}gi/`;return S.startsWith(F)?pn.join(C.native,S.slice(F.length)):S.startsWith(N)?pn.join(C.bundle,S.slice(N.length)):S.startsWith(`bin/`)?pn.join(C.launcher,S.slice(4)):S.startsWith(`share/`)?pn.join(C.data,S.slice(6)):pn.join(C.other,S)}function placeStage(t,n,S,C=[]){let N=new Map,F=[],claim=(n,S,C)=>{let I=N.get(n);if(I!==void 0)throw Error(`gjsify ship: in the ${t.name} layout both ${I} and ${S} install as ${n}. Two payload files cannot share one destination — one would silently replace the other. Rename the \`gjsify.ship.extraFiles\` destination that collides.`);N.set(n,S),F.push({...C,path:n})};for(let C of S)claim(place(t,n,C.path),C.path,C);for(let C of t.metadata(n,S))claim(C.path,`the ${t.name} layout's own metadata`,C);for(let n of C)claim(n.path,`the runtime staged into the ${t.name} artifact`,n);return F.sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}var aV,oV,sV,cV,lV,uV=__esmMin(()=>{Pn(),MB(),PB(),QB(),iV(),CB(),aV=/[/:\\]/,oV=[64,128,256],sV={linux:{name:`linux`,os:`linux`,shippedRuntime:`gjs`,launcherExt:``,root:()=>``,dirs:t=>({launcher:`bin`,bundle:`lib/${t.binaryName}`,native:`lib/${t.binaryName}/gi`,data:`share`,other:``}),icon:{sizes:oV,writes:"the hicolor theme's raster icons (`share/icons/hicolor/<n>x<n>/apps/<appId>.png`)",required:!1},metadata:(t,n)=>{let S=iconFor(t,`linux`);if(S===void 0)return[];let C=new Set(n.map(t=>t.path)),N=[];for(let n of[...S.png.keys()].sort((t,n)=>t-n)){let F=`${SB.icons}/${n}x${n}/apps/${t.appId}.png`,I=S.png.get(n);I===void 0||C.has(F)||N.push({path:place(sV.linux,t,F),mode:420,source:{kind:`bytes`,data:I}})}return N},arches:null},darwin:{name:`darwin`,os:`darwin`,shippedRuntime:`node`,runtimeGap:'the staged launcher execs an interpreter off `PATH`, which a downloaded `.app` cannot assume — macOS ships no Node, and there is no RELOCATABLE GJS (`build-gtk-runtime-darwin.mjs`: "GJS ships no relocation"), so ADR 0024 § 4 derives Node here. A self-contained bundle needs `@gjsify/node-runtime-darwin-<arch>` and a `--app node` payload (#1354 M0), or `@gjsify/gjs-runtime-darwin-<arch>` (ADR 0024 stage 7).',fontGap:"the faces are staged in `share/fonts/<appId>` and `Info.plist` carries `ATSApplicationFontsPath` at it, which is macOS's own per-app activation and the route that matters whenever Pango on macOS resolves CoreText by default — which it does on a Homebrew GTK, because that one is not built against fontconfig. A `.app` carrying the bundled GTK runtime reads the same faces through fontconfig instead: `@gjsify/node-gi`'s loader selects it with `PANGOCAIRO_BACKEND=fc` (ADR 0038 § Amendment 3), and `initFonts()` from `@gjsify/gtk-host/fonts` registers them as it does on Windows. Either way no branch is needed in your app: a CoreText map answers G_IO_ERROR_NOT_SUPPORTED and the call reports that as declined. Confirm in the shipped bundle with `PangoCairo.FontMap.get_default().list_families()`, and `PANGOCAIRO_BACKEND=bogus` to print which backends it was built with.",launcherExt:``,root:appBundleDir,dirs:t=>{let n=appBundleDir(t);return{launcher:`${n}/Contents/MacOS`,bundle:`${n}/Contents/Resources/lib`,native:`${n}/Contents/Resources/native`,data:`${n}/Contents/Resources/share`,other:`${n}/Contents/Resources`}},icon:{sizes:jB,writes:"the macOS bundle icon (`Contents/Resources/<binaryName>.icns`)",required:!0},metadata:(t,n)=>{let S=iconFor(t,`darwin`),C=S===void 0?void 0:`${t.binaryName}.icns`;return[{path:`${appBundleDir(t)}/${$B}`,mode:420,source:{kind:`text`,text:renderInfoPlist(t,darwinFontsPath(t,n),C)}},{path:`${appBundleDir(t)}/${eV}`,mode:420,source:{kind:`text`,text:renderPkgInfo()}},...S===void 0||C===void 0?[]:[{path:`${appBundleDir(t)}/${tV}/${C}`,mode:420,source:{kind:`bytes`,data:buildIcns(S)}}]]},arches:{only:[`x64`,`arm64`],why:"macOS runs on x86_64 and Apple silicon and nothing else, so those are the two `@gjsify/gtk-runtime-darwin-*` and `@gjsify/node-runtime-darwin-*` targets that exist"}},windows:{name:`windows`,os:`win32`,shippedRuntime:`node`,runtimeGap:"the staged launcher execs an interpreter off `PATH`, which a downloaded program directory cannot assume — Windows ships neither, and there is NO GJS host on Windows at all (ADR 0024 § 4), so § 4 derives Node here. A self-contained directory needs `@gjsify/node-runtime-win32-x64` and a `--app node` payload (#1354 M3).",fontGap:"the faces are staged in `share/fonts/<appId>` and the launcher exports GJSIFY_FONT_DIR at it, but WINDOWS HAS NO DECLARATIVE FONT ACTIVATION and nothing here reaches a bundled face on its own: GTK4 resolves pangowin32, whose font map is populated from DirectWrite and never from fontconfig or from GDI, unless something selects otherwise — which the bundled GTK runtime does (`PANGOCAIRO_BACKEND=fc`, ADR 0038 § Amendment 3), and an app may. MEASURED on the DirectWrite map, Windows 11 / GTK 4.22.4, rather than inferred (ADR 0038 W1-W5): a FONTCONFIG_FILE naming the staged directory moves the default font map by nothing even when it is the ONLY configuration present — that map does not read fontconfig, and exposes no config_changed or set_config with which to make it — while add_font_file on the same map a Gtk.Label renders through does register the family. So register them at startup, with one call from the GTK host layer: `import { initFonts } from '@gjsify/gtk-host/fonts'`, then `initFonts()` before the first window — it reads GJSIFY_FONT_DIR itself, registers every face it holds, and no-ops on the operating systems that already activated them. Without it the app renders in a substituted family with no error.",launcherExt:`.cmd`,root:()=>``,dirs:()=>({launcher:``,bundle:`app`,native:`lib`,data:`share`,other:``}),icon:{sizes:NB,writes:"the Windows launcher icon (`.rsrc` of `<binaryName>.exe`)",required:!0},metadata:t=>{let n=iconFor(t,`windows`);return t.arch===`x64`?[{path:windowsGuiLauncherPath(t),mode:493,source:{kind:`bytes`,data:buildGuiLauncher({logLeaf:windowsLaunchLogLeaf(t),...n===void 0?{}:{icon:iconResources(n)}})}}]:[]},arches:{only:[`x64`],why:"the arm64 GTK closure `@gjsify/gtk-runtime-win32-arm64` does not exist yet — the prefix it would be built from is no longer missing, because ADR 0089 builds it from our `gjsify/gvsbuild` fork in CI and `@gjsify/node-gi` ships a win32-arm64 prebuild against it — so what is left is the runtime package this layout would stage, ordered in `status/open-todos/windows.md` and tracked in gjsify/gjsify#1117"}}},cV=Object.keys(sV),lV=new Map(cV.map(t=>[sV[t].os,sV[t]]))});async function compileSchemasForStage(t){if(t.schemaFiles.length===0)return[];rmSync(t.workDir,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(t.workDir,{recursive:!0});for(let n of t.schemaFiles)copyFileSync(n,wn(t.workDir,Dn(n)));return await runSchemaCompiler(t.workDir),[{path:mV,mode:420,source:{kind:`file`,path:wn(t.workDir,`gschemas.compiled`)}}]}async function compileSchemasForPayload(t){let n=t.payload.filter(t=>isSchemaSource(t.path));if(n.length!==0){rmSync(t.workDir,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(t.workDir,{recursive:!0});for(let S of n)writeFileSync(wn(t.workDir,pn.basename(S.path)),S.data);return await runSchemaCompiler(t.workDir),{path:mV,mode:420,data:readFileSync(wn(t.workDir,`gschemas.compiled`))}}}function isSchemaSource(t){return t.startsWith(`${SB.schemas}/`)&&t.endsWith(`.gschema.xml`)}async function runSchemaCompiler(t){try{await dV(fV,[`--strict`,`--targetdir=${t}`,t])}catch(t){let n=t;throw n.code===`ENOENT`?Error(`gjsify ship: this artifact has no install step, so \`${fV}\` has to run HERE to turn the payload's schemas into \`${mV}\` — and it is not on PATH. Install it (${pV}). Without the compiled cache the launcher points XDG_DATA_DIRS at a schema directory GSettings aborts on, so the bundle would build and then die at its first \`Gio.Settings.new()\`.`):Error(`gjsify ship: \`${fV} --strict\` refused this project's schemas.\n${(n.stderr??``).trimEnd()}\n \`--strict\` is deliberate: without it a malformed schema is SKIPPED at exit 0 and a cache
1127
+ `)}var iV,aV,oV,sV,cV,lV=__esmMin(()=>{iV=`Contents/Info.plist`,aV=`Contents/PkgInfo`,oV=`Contents/Resources`,sV=`APPL`,cV=`????`});function darwinFontsPath(t,n){let S=`${DB.fonts}/${t.appId}`,C=n.find(t=>t.path.startsWith(`${S}/`));if(C===void 0)return;let N=fV.darwin.dirs(t);return pn.relative(N.other,pn.dirname(place(fV.darwin,t,C.path)))}function appBundleDir(t){if(uV.test(t.name))throw Error(`gjsify ship: the macOS layout would put this app in "${t.name}.app", and a bundle directory may contain no "/", "\\" or ":" — HFS+ and the Finder swap the first two, so the bundle would not be the one its own metadata names. Set \`gjsify.ship.name\` to the display name you want on disk.`);return`${t.name}.app`}function iconFor(t,n){if(t.kind===`app`){if(t.icon===void 0){if(fV[n].icon?.required!==!0)return;throw Error(`gjsify ship: the ${n} layout writes the application's icon and was given none. A \`kind: "app"\` stage is rendered its icon by \`resolveAppIcon\` before the layout runs; reaching this row without one is a caller that skipped that step.`)}return t.icon}}function launcherPath(t,n){return pn.join(t.dirs(n).launcher,`${n.binaryName}${t.launcherExt}`)}function windowsGuiLauncherPath(t){let n=fV.windows;if(n.launcherExt.length!==4)throw Error(`gjsify ship: the windows launcher extension is "${n.launcherExt}" and the GUI stub can only reach a four-character one — it rewrites the last three characters of its own filename rather than searching for a path (\`utils/ship/pe-launcher.ts\`).`);return pn.join(n.dirs(t).launcher,`${t.binaryName}.exe`)}function windowsLaunchLogLeaf(t){return`${t.binaryName}.launch.log`}function layoutForOs(t){let n=mV.get(t);if(n===void 0)throw Error(`"${t}" is not a \`process.platform\` token this gjsify has a layout for. Known: ${pV.map(t=>fV[t].os).join(`, `)} — the \`\${process.platform}-\${process.arch}\` spelling, so \`win32\` and never \`windows\`.`);return n}function resolveLayout(t){let n=t.trim().toLowerCase();if(Object.hasOwn(fV,n))return fV[n];let S=mV.get(n);if(S!==void 0)return S;throw Error(`gjsify ship: "${t}" is not an operating system this command has a layout for. Known: ${pV.join(`, `)} (\`win32\` is accepted for \`windows\`, because that is the spelling \`--expect-target <os>-<arch>\` uses).`)}function hostLayout(t=process.platform){let n=mV.get(t);if(n===void 0)throw Error(`gjsify ship: this host is ${t}, which has no layout. Name the one you want — \`gjsify ship <${pV.join(`|`)}> --stage\` — assembly is not host-bound (ADR 0024 § A1).`);return n}function assertLayoutSupportsArch(t,n){let S=t.arches;if(!(S===null||S.only.includes(n)))throw Error(`gjsify ship: the ${t.name} layout is not assemblable for \`--arch ${n}\` — ${S.only.length===1?`the only architecture it has`:`the architectures it has`} ${S.only.length===1?`is`:`are`} ${S.only.join(`, `)}.\n ${S.why}.\n \`--arch\` names the architecture the PAYLOAD was built for and cross-compiles nothing, so there is no
1128
+ flag that makes this work — the artifact would carry a runtime that does not exist.`)}function place(t,n,S){let C=t.dirs(n);if(S===`bin/${n.binaryName}`)return launcherPath(t,n);let N=`lib/${n.binaryName}/`,F=`${N}gi/`;return S.startsWith(F)?pn.join(C.native,S.slice(F.length)):S.startsWith(N)?pn.join(C.bundle,S.slice(N.length)):S.startsWith(`bin/`)?pn.join(C.launcher,S.slice(4)):S.startsWith(`share/`)?pn.join(C.data,S.slice(6)):pn.join(C.other,S)}function placeStage(t,n,S,C=[]){let N=new Map,F=[],claim=(n,S,C)=>{let I=N.get(n);if(I!==void 0)throw Error(`gjsify ship: in the ${t.name} layout both ${I} and ${S} install as ${n}. Two payload files cannot share one destination — one would silently replace the other. Rename the \`gjsify.ship.extraFiles\` destination that collides.`);N.set(n,S),F.push({...C,path:n})};for(let C of S)claim(place(t,n,C.path),C.path,C);for(let C of t.metadata(n,S))claim(C.path,`the ${t.name} layout's own metadata`,C);for(let n of C)claim(n.path,`the runtime staged into the ${t.name} artifact`,n);return F.sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}var uV,dV,fV,pV,mV,hV=__esmMin(()=>{Pn(),LB(),zB(),rV(),lV(),OB(),uV=/[/:\\]/,dV=[64,128,256],fV={linux:{name:`linux`,os:`linux`,shippedRuntime:`gjs`,launcherExt:``,root:()=>``,dirs:t=>({launcher:`bin`,bundle:`lib/${t.binaryName}`,native:`lib/${t.binaryName}/gi`,data:`share`,other:``}),icon:{sizes:dV,writes:"the hicolor theme's raster icons (`share/icons/hicolor/<n>x<n>/apps/<appId>.png`)",required:!1},metadata:(t,n)=>{let S=iconFor(t,`linux`);if(S===void 0)return[];let C=new Set(n.map(t=>t.path)),N=[];for(let n of[...S.png.keys()].sort((t,n)=>t-n)){let F=`${DB.icons}/${n}x${n}/apps/${t.appId}.png`,I=S.png.get(n);I===void 0||C.has(F)||N.push({path:place(fV.linux,t,F),mode:420,source:{kind:`bytes`,data:I}})}return N},arches:null},darwin:{name:`darwin`,os:`darwin`,shippedRuntime:`node`,runtimeGap:'the staged launcher execs an interpreter off `PATH`, which a downloaded `.app` cannot assume — macOS ships no Node, and there is no RELOCATABLE GJS (`build-gtk-runtime-darwin.mjs`: "GJS ships no relocation"), so ADR 0024 § 4 derives Node here. A self-contained bundle needs `@gjsify/node-runtime-darwin-<arch>` and a `--app node` payload (#1354 M0), or `@gjsify/gjs-runtime-darwin-<arch>` (ADR 0024 stage 7).',fontGap:"the faces are staged in `share/fonts/<appId>` and `Info.plist` carries `ATSApplicationFontsPath` at it, which is macOS's own per-app activation and the route that matters whenever Pango on macOS resolves CoreText by default — which it does on a Homebrew GTK, because that one is not built against fontconfig. A `.app` carrying the bundled GTK runtime reads the same faces through fontconfig instead: `@gjsify/node-gi`'s loader selects it with `PANGOCAIRO_BACKEND=fc` (ADR 0038 § Amendment 3), and `initFonts()` from `@gjsify/gtk-host/fonts` registers them as it does on Windows. Either way no branch is needed in your app: a CoreText map answers G_IO_ERROR_NOT_SUPPORTED and the call reports that as declined. Confirm in the shipped bundle with `PangoCairo.FontMap.get_default().list_families()`, and `PANGOCAIRO_BACKEND=bogus` to print which backends it was built with.",launcherExt:``,root:appBundleDir,dirs:t=>{let n=appBundleDir(t);return{launcher:`${n}/Contents/MacOS`,bundle:`${n}/Contents/Resources/lib`,native:`${n}/Contents/Resources/native`,data:`${n}/Contents/Resources/share`,other:`${n}/Contents/Resources`}},icon:{sizes:IB,writes:"the macOS bundle icon (`Contents/Resources/<binaryName>.icns`)",required:!0},metadata:(t,n)=>{let S=iconFor(t,`darwin`),C=S===void 0?void 0:`${t.binaryName}.icns`;return[{path:`${appBundleDir(t)}/${iV}`,mode:420,source:{kind:`text`,text:renderInfoPlist(t,darwinFontsPath(t,n),C)}},{path:`${appBundleDir(t)}/${aV}`,mode:420,source:{kind:`text`,text:renderPkgInfo()}},...S===void 0||C===void 0?[]:[{path:`${appBundleDir(t)}/${oV}/${C}`,mode:420,source:{kind:`bytes`,data:buildIcns(S)}}]]},arches:{only:[`x64`,`arm64`],why:"macOS runs on x86_64 and Apple silicon and nothing else, so those are the two `@gjsify/gtk-runtime-darwin-*` and `@gjsify/node-runtime-darwin-*` targets that exist"}},windows:{name:`windows`,os:`win32`,shippedRuntime:`node`,runtimeGap:"the staged launcher execs an interpreter off `PATH`, which a downloaded program directory cannot assume — Windows ships neither, and there is NO GJS host on Windows at all (ADR 0024 § 4), so § 4 derives Node here. A self-contained directory needs `@gjsify/node-runtime-win32-x64` and a `--app node` payload (#1354 M3).",fontGap:"the faces are staged in `share/fonts/<appId>` and the launcher exports GJSIFY_FONT_DIR at it, but WINDOWS HAS NO DECLARATIVE FONT ACTIVATION and nothing here reaches a bundled face on its own: GTK4 resolves pangowin32, whose font map is populated from DirectWrite and never from fontconfig or from GDI, unless something selects otherwise — which the bundled GTK runtime does (`PANGOCAIRO_BACKEND=fc`, ADR 0038 § Amendment 3), and an app may. MEASURED on the DirectWrite map, Windows 11 / GTK 4.22.4, rather than inferred (ADR 0038 W1-W5): a FONTCONFIG_FILE naming the staged directory moves the default font map by nothing even when it is the ONLY configuration present — that map does not read fontconfig, and exposes no config_changed or set_config with which to make it — while add_font_file on the same map a Gtk.Label renders through does register the family. So register them at startup, with one call from the GTK host layer: `import { initFonts } from '@gjsify/gtk-host/fonts'`, then `initFonts()` before the first window — it reads GJSIFY_FONT_DIR itself, registers every face it holds, and no-ops on the operating systems that already activated them. Without it the app renders in a substituted family with no error.",launcherExt:`.cmd`,root:()=>``,dirs:()=>({launcher:``,bundle:`app`,native:`lib`,data:`share`,other:``}),icon:{sizes:RB,writes:"the Windows launcher icon (`.rsrc` of `<binaryName>.exe`)",required:!0},metadata:t=>{let n=iconFor(t,`windows`);return t.arch===`x64`?[{path:windowsGuiLauncherPath(t),mode:493,source:{kind:`bytes`,data:buildGuiLauncher({logLeaf:windowsLaunchLogLeaf(t),...n===void 0?{}:{icon:iconResources(n)}})}}]:[]},arches:{only:[`x64`],why:"the arm64 GTK closure `@gjsify/gtk-runtime-win32-arm64` does not exist yet — the prefix it would be built from is no longer missing, because ADR 0089 builds it from our `gjsify/gvsbuild` fork in CI and `@gjsify/node-gi` ships a win32-arm64 prebuild against it — so what is left is the runtime package this layout would stage, ordered in `status/open-todos/windows.md` and tracked in gjsify/gjsify#1117"}}},pV=Object.keys(fV),mV=new Map(pV.map(t=>[fV[t].os,fV[t]]))});async function compileSchemasForStage(t){if(t.schemaFiles.length===0)return[];rmSync(t.workDir,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(t.workDir,{recursive:!0});for(let n of t.schemaFiles)copyFileSync(n,wn(t.workDir,Dn(n)));return await runSchemaCompiler(t.workDir),[{path:yV,mode:420,source:{kind:`file`,path:wn(t.workDir,`gschemas.compiled`)}}]}async function compileSchemasForPayload(t){let n=t.payload.filter(t=>isSchemaSource(t.path));if(n.length!==0){rmSync(t.workDir,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(t.workDir,{recursive:!0});for(let S of n)writeFileSync(wn(t.workDir,pn.basename(S.path)),S.data);return await runSchemaCompiler(t.workDir),{path:yV,mode:420,data:readFileSync(wn(t.workDir,`gschemas.compiled`))}}}function isSchemaSource(t){return t.startsWith(`${DB.schemas}/`)&&t.endsWith(`.gschema.xml`)}async function runSchemaCompiler(t){try{await gV(_V,[`--strict`,`--targetdir=${t}`,t])}catch(t){let n=t;throw n.code===`ENOENT`?Error(`gjsify ship: this artifact has no install step, so \`${_V}\` has to run HERE to turn the payload's schemas into \`${yV}\` — and it is not on PATH. Install it (${vV}). Without the compiled cache the launcher points XDG_DATA_DIRS at a schema directory GSettings aborts on, so the bundle would build and then die at its first \`Gio.Settings.new()\`.`):Error(`gjsify ship: \`${_V} --strict\` refused this project's schemas.\n${(n.stderr??``).trimEnd()}\n \`--strict\` is deliberate: without it a malformed schema is SKIPPED at exit 0 and a cache
1129
1129
  is written without it, so the app still aborts on the schema that was dropped. Fix the
1130
- file it names, or drop it from \`gjsify.ship.schemas\`.`)}}var dV,fV,pV,mV,hV=__esmMin(()=>{P_(),Pn(),Rd(),Tu(),CB(),dV=promisify(execFile),fV=`glib-compile-schemas`,pV="Fedora: `sudo dnf install glib2`, Debian/Ubuntu: `sudo apt install libglib2.0-bin`",mV=`${SB.schemas}/gschemas.compiled`});function buildTimestamp(t,n=process.env){let S=n.SOURCE_DATE_EPOCH;if(S!==void 0){let t=Number(S);if(!Number.isInteger(t)||t<0)throw Error(`gjsify ship: SOURCE_DATE_EPOCH must be a non-negative integer, got "${S}".`);return t}return Math.floor(statSync(t).mtimeMs/1e3)}function readPayloadFacts(t){let n=t.map(t=>t.path);return{hasDesktopEntry:n.some(t=>isUnder(t,SB.applications)&&t.endsWith(`.desktop`)),hasIcons:n.some(t=>isUnder(t,SB.icons)),hasSchemas:n.some(t=>isUnder(t,SB.schemas)&&t.endsWith(`.gschema.xml`)),hasMimeTypes:n.some(t=>isUnder(t,SB.mime)&&t.endsWith(`.xml`)),bundledTypelibs:n.filter(t=>t.endsWith(`.typelib`))}}function readLauncherInterpreters(t,n,S){let C=t.find(t=>t.path===launcherPath(n,S));if(C===void 0)return[];let N=new TextDecoder().decode(C.data),F=n.name===`windows`?`cmd`:`sh`,I=[];for(let t of F===`cmd`?batchCommands(N):shellExecLines(N)){let n=interpreterOf(t,F);n!==null&&I.push(n)}return[...new Set(I)]}function shellExecLines(t){return[...`\n${t}`.matchAll(/\n[ \t]*exec\s+([^\n]*)/g)].map(t=>t[1].trim())}function cmdTokens(t){let n=[],S=0;for(;S<t.length;){if(/\s/.test(t[S])){S+=1;continue}let C=S,N=!1;for(;S<t.length&&(N||!/\s/.test(t[S]));)t[S]===`"`&&(N=!N),S+=1;n.push({text:t.slice(C,S),end:S})}return n}function splitBatchBlock(t){let n=0,S=!1;for(let C=0;C<t.length;C++){let N=t[C];if(N===`"`)S=!S;else if(!S&&N===`(`)n+=1;else if(!S&&N===`)`&&(--n,n===0))return[t.slice(1,C).trim(),t.slice(C+1).trim()]}return null}function batchPrefix(t){if(t.startsWith(`(`)){let n=splitBatchBlock(t);return n===null?null:[n[0],n[1]]}let n=cmdTokens(t),word=t=>(n[t]?.text??``).toLowerCase(),after=S=>[t.slice(n[S]?.end??t.length).trim()];if(word(0)===`else`)return after(0);if(word(0)===`for`){let t=n.findIndex(t=>t.text.toLowerCase()===`do`);return t===-1?null:after(t)}if(word(0)!==`if`)return;let S=1;for(;word(S)===`not`||word(S)===`/i`;)S+=1;return _V.has(word(S))?after(S+1):word(S).includes(`==`)?after(S):vV.has(word(S+1))?after(S+2):null}function batchCommands(t){let n=[],S=t.split(/\r?\n/).map(t=>t.trim().replace(/^@+/,``).trim());for(let t=0;t<yV&&S.length>0;t++){let t=S.shift();if(t===``||t===`)`||t.startsWith(`::`))continue;let C=(cmdTokens(t)[0]?.text??``).toLowerCase();if(gV.has(C))continue;let N=batchPrefix(t);N===void 0?n.push(t):N!==null&&S.unshift(...N)}return n}function interpreterOf(t,n){if(n===`cmd`)return cmdProgramOf(t);let S=t.split(/\s+/).filter(t=>t.length>0);for(let t=0;t<2&&S.length>0;t++){let t=basenameOf(S[0]);if(t!==`env`)return t===``?null:t;S=S.slice(1).filter(t=>!t.startsWith(`-`)&&!/^[A-Za-z_][A-Za-z0-9_]*=/.test(t))}return null}function cmdProgramOf(t){let n=/^"([^"]*)"/.exec(t),S=((n===null?t.split(/\s+/)[0]??``:n[1]).replace(/^%[^%\s]*%/,``).split(/[/\\]/).pop()??``).replace(/\.exe$/i,``);return S===``?null:S}function basenameOf(t){let n=unquote(t).split(/[/\\]/);return n[n.length-1]??``}function unquote(t){let n=t[0];return(n===`"`||n===`'`)&&t.length>1&&t[t.length-1]===n?t.slice(1,-1):t}function assertLauncherMatchesInterpreter(t,n,S,C){let N=readLauncherInterpreters(t,n,S);if(N.length===0||N.includes(C))return;let F=C===`gjs`?`node`:`gjs`;if(N.includes(F))throw Error(`gjsify ship: the launcher ${launcherPath(n,S)} execs \`${F}\`, but this package would declare a dependency on \`${C}\`.\n An installed package that depends on one interpreter and runs another installs cleanly and fails
1130
+ file it names, or drop it from \`gjsify.ship.schemas\`.`)}}var gV,_V,vV,yV,bV=__esmMin(()=>{P_(),Pn(),Rd(),Tu(),OB(),gV=promisify(execFile),_V=`glib-compile-schemas`,vV="Fedora: `sudo dnf install glib2`, Debian/Ubuntu: `sudo apt install libglib2.0-bin`",yV=`${DB.schemas}/gschemas.compiled`});function buildTimestamp(t,n=process.env){let S=n.SOURCE_DATE_EPOCH;if(S!==void 0){let t=Number(S);if(!Number.isInteger(t)||t<0)throw Error(`gjsify ship: SOURCE_DATE_EPOCH must be a non-negative integer, got "${S}".`);return t}return Math.floor(statSync(t).mtimeMs/1e3)}function readPayloadFacts(t){let n=t.map(t=>t.path);return{hasDesktopEntry:n.some(t=>isUnder(t,DB.applications)&&t.endsWith(`.desktop`)),hasIcons:n.some(t=>isUnder(t,DB.icons)),hasSchemas:n.some(t=>isUnder(t,DB.schemas)&&t.endsWith(`.gschema.xml`)),hasMimeTypes:n.some(t=>isUnder(t,DB.mime)&&t.endsWith(`.xml`)),bundledTypelibs:n.filter(t=>t.endsWith(`.typelib`))}}function readLauncherInterpreters(t,n,S){let C=t.find(t=>t.path===launcherPath(n,S));if(C===void 0)return[];let N=new TextDecoder().decode(C.data),F=n.name===`windows`?`cmd`:`sh`,I=[];for(let t of F===`cmd`?batchCommands(N):shellExecLines(N)){let n=interpreterOf(t,F);n!==null&&I.push(n)}return[...new Set(I)]}function shellExecLines(t){return[...`\n${t}`.matchAll(/\n[ \t]*exec\s+([^\n]*)/g)].map(t=>t[1].trim())}function cmdTokens(t){let n=[],S=0;for(;S<t.length;){if(/\s/.test(t[S])){S+=1;continue}let C=S,N=!1;for(;S<t.length&&(N||!/\s/.test(t[S]));)t[S]===`"`&&(N=!N),S+=1;n.push({text:t.slice(C,S),end:S})}return n}function splitBatchBlock(t){let n=0,S=!1;for(let C=0;C<t.length;C++){let N=t[C];if(N===`"`)S=!S;else if(!S&&N===`(`)n+=1;else if(!S&&N===`)`&&(--n,n===0))return[t.slice(1,C).trim(),t.slice(C+1).trim()]}return null}function batchPrefix(t){if(t.startsWith(`(`)){let n=splitBatchBlock(t);return n===null?null:[n[0],n[1]]}let n=cmdTokens(t),word=t=>(n[t]?.text??``).toLowerCase(),after=S=>[t.slice(n[S]?.end??t.length).trim()];if(word(0)===`else`)return after(0);if(word(0)===`for`){let t=n.findIndex(t=>t.text.toLowerCase()===`do`);return t===-1?null:after(t)}if(word(0)!==`if`)return;let S=1;for(;word(S)===`not`||word(S)===`/i`;)S+=1;return SV.has(word(S))?after(S+1):word(S).includes(`==`)?after(S):CV.has(word(S+1))?after(S+2):null}function batchCommands(t){let n=[],S=t.split(/\r?\n/).map(t=>t.trim().replace(/^@+/,``).trim());for(let t=0;t<wV&&S.length>0;t++){let t=S.shift();if(t===``||t===`)`||t.startsWith(`::`))continue;let C=(cmdTokens(t)[0]?.text??``).toLowerCase();if(xV.has(C))continue;let N=batchPrefix(t);N===void 0?n.push(t):N!==null&&S.unshift(...N)}return n}function interpreterOf(t,n){if(n===`cmd`)return cmdProgramOf(t);let S=t.split(/\s+/).filter(t=>t.length>0);for(let t=0;t<2&&S.length>0;t++){let t=basenameOf(S[0]);if(t!==`env`)return t===``?null:t;S=S.slice(1).filter(t=>!t.startsWith(`-`)&&!/^[A-Za-z_][A-Za-z0-9_]*=/.test(t))}return null}function cmdProgramOf(t){let n=/^"([^"]*)"/.exec(t),S=((n===null?t.split(/\s+/)[0]??``:n[1]).replace(/^%[^%\s]*%/,``).split(/[/\\]/).pop()??``).replace(/\.exe$/i,``);return S===``?null:S}function basenameOf(t){let n=unquote(t).split(/[/\\]/);return n[n.length-1]??``}function unquote(t){let n=t[0];return(n===`"`||n===`'`)&&t.length>1&&t[t.length-1]===n?t.slice(1,-1):t}function assertLauncherMatchesInterpreter(t,n,S,C){let N=readLauncherInterpreters(t,n,S);if(N.length===0||N.includes(C))return;let F=C===`gjs`?`node`:`gjs`;if(N.includes(F))throw Error(`gjsify ship: the launcher ${launcherPath(n,S)} execs \`${F}\`, but this package would declare a dependency on \`${C}\`.\n An installed package that depends on one interpreter and runs another installs cleanly and fails
1131
1131
  at first launch, on the user's machine.
1132
1132
  Either set \`gjsify.ship.app.${n.os}\` to "${F}" in the project this was staged from — it overrides
1133
1133
  \`gjsify.app\` for that target alone — or fix the launcher: if it comes from \`gjsify.ship.extraFiles\`,
1134
- that override is what decides which interpreter runs and it must match the declaration.`)}function linuxInstallDependent(t){let n=[],S={hasCompiledSchemas:t.some(t=>t.path===mV)};for(let C of t){if(!isUnder(C.path,`share`)||xV.some(t=>C.path===t||isUnder(C.path,t)))continue;let t=bV.find(([t])=>isUnder(C.path,t));if(t===void 0){n.push({path:C.path,verdict:`unknown`,why:`nothing here classifies this directory — it may need an install step no non-Linux layout runs, or it may be inert; say which before shipping it`});continue}let[N,F]=t[1](S);n.push({path:C.path,verdict:N,why:F})}let C={aborts:0,unknown:1,inert:2};return n.sort((t,n)=>C[t.verdict]-C[n.verdict]||(t.path<n.path?-1:1))}function readShebangInterpreters(t){let n=new Set;for(let S of t){if(!(S.mode&73))continue;let t=readShebang(S.data);t!==null&&n.add(t)}return[...n].sort()}function readShebang(t){if(t[0]!==35||t[1]!==33)return null;let n=(new TextDecoder().decode(t.subarray(2,Math.min(t.byteLength,256))).split(`
1135
- `)[0]??``).trim().split(/\s+/)[0]??``;return n.startsWith(`/`)?n:null}function isArchIndependent(t){return!t.some(t=>isNativeBinary(t.data))}function readBinaryArch(t){if(t.byteLength<20)return null;let n=(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;if(n===2135247942){let n=t[5]===1?t[18]|t[19]<<8:t[18]<<8|t[19];return SV[n]??null}if(n===4277009102||n===4277009103)return CV[(t[4]<<24|t[5]<<16|t[6]<<8|t[7])>>>0]??null;if(n===3472551422||n===3489328638)return CV[(t[7]<<24|t[6]<<16|t[5]<<8|t[4])>>>0]??null;if(t[0]===77&&t[1]===90&&t.byteLength>=64){let n=(t[60]|t[61]<<8|t[62]<<16|t[63]<<24)>>>0;return n+6>t.byteLength||(t[n]|t[n+1]<<8|t[n+2]<<16)>>>0!=17744||t[n+3]!==0?null:wV[t[n+4]|t[n+5]<<8]??null}return null}function assertPayloadMatchesArch(t,n){for(let S of t){let t=readBinaryArch(S.data);if(!(t===null||t===n))throw Error(`gjsify ship: the payload is ${t}, but the package would be labelled ${n} — ${S.path} is built for ${t}.\n \`--arch\` names the architecture the PAYLOAD was built for; it does not cross-compile anything.
1136
- A package labelled ${n} installs on ${n} and then fails to load. Build the payload for ${n}\n (its own prebuild), or assemble the stage without \`--arch\` and label the payload you actually have.`)}}function classifyBinary(t){if(t.byteLength<4)return null;switch((t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0){case 2135247942:return`elf`;case 4277009102:case 4277009103:case 3472551422:case 3489328638:case 3405691582:return`macho`;default:return t[0]===77&&t[1]===90?`pe`:null}}function isNativeBinary(t){return classifyBinary(t)!==null}var gV,_V,vV,yV,bV,xV,SV,CV,wV,TV=__esmMin(()=>{Rd(),uV(),hV(),CB(),gV=new Set([`rem`,`set`,`setlocal`,`endlocal`,`echo`,`goto`,`exit`,`title`,`pause`,`shift`,`cd`,`chdir`,`pushd`,`popd`,`color`,`cls`,`verify`,`prompt`]),_V=new Set([`exist`,`defined`,`errorlevel`]),vV=new Set([`equ`,`neq`,`lss`,`leq`,`gtr`,`geq`]),yV=32,bV=[[SB.schemas,({hasCompiledSchemas:t})=>t?[`inert`,"the schema SOURCE; `gschemas.compiled` is staged beside it and that is what GSettings reads, so this file is carried and never opened"]:[`aborts`,"needs `glib-compile-schemas`, and the launcher points XDG_DATA_DIRS here — GSettings ABORTS on a schema directory with no `gschemas.compiled`"]],[SB.mime,()=>[`inert`,"needs `update-mime-database`; detection runs off the compiled cache"]],[SB.icons,()=>[`inert`,"needs `gtk-update-icon-cache`; neither OS reads the hicolor theme"]],[SB.applications,()=>[`inert`,`a freedesktop desktop entry; neither OS reads one`]],[SB.metainfo,()=>[`inert`,`an AppStream component; neither OS reads one`]]],xV=[SB.locale,SB.fonts,mV],SV={3:`ia32`,21:`ppc64`,22:`s390x`,40:`arm`,62:`x64`,183:`arm64`,243:`riscv64`},CV={7:`ia32`,12:`arm`,16777223:`x64`,16777228:`arm64`},wV={332:`ia32`,34404:`x64`,43620:`arm64`}});async function buildDeb(t){let{payload:n,mtime:S}=t,C=t.prefix.replace(/^\/+/,``),N=n.map(t=>({...t,tarPath:`./${pn.join(C,t.path)}`})),F=ancestorDirectories(N.map(t=>t.tarPath)),I=await gzipDeterministic(createTarball([...F.map(t=>({name:t,mode:493,mtime:S,directory:!0})),...N.map(t=>({name:t.tarPath,body:t.data,mode:t.mode,mtime:S}))])),H=renderControl(t,N.reduce((t,n)=>t+Math.ceil(n.data.byteLength/1024),0)+F.length),W=N.map(t=>`${createHash(`md5`).update(t.data).digest(`hex`)} ${t.tarPath.slice(2)}\n`).join(``),q=[{name:`./`,mode:493,mtime:S,directory:!0},{name:`./control`,body:H,mode:420,mtime:S},{name:`./md5sums`,body:W,mode:420,mtime:S}],Y=renderDebScripts(readPayloadFacts(n),t.prefix);for(let[t,n]of Object.entries(Y))q.push({name:`./${t}`,body:n,mode:493,mtime:S});let X=await gzipDeterministic(createTarball(q));return createArArchive([{name:`debian-binary`,data:new TextEncoder().encode(`2.0
1134
+ that override is what decides which interpreter runs and it must match the declaration.`)}function linuxInstallDependent(t){let n=[],S={hasCompiledSchemas:t.some(t=>t.path===yV)};for(let C of t){if(!isUnder(C.path,`share`)||EV.some(t=>C.path===t||isUnder(C.path,t)))continue;let t=TV.find(([t])=>isUnder(C.path,t));if(t===void 0){n.push({path:C.path,verdict:`unknown`,why:`nothing here classifies this directory — it may need an install step no non-Linux layout runs, or it may be inert; say which before shipping it`});continue}let[N,F]=t[1](S);n.push({path:C.path,verdict:N,why:F})}let C={aborts:0,unknown:1,inert:2};return n.sort((t,n)=>C[t.verdict]-C[n.verdict]||(t.path<n.path?-1:1))}function readShebangInterpreters(t){let n=new Set;for(let S of t){if(!(S.mode&73))continue;let t=readShebang(S.data);t!==null&&n.add(t)}return[...n].sort()}function readShebang(t){if(t[0]!==35||t[1]!==33)return null;let n=(new TextDecoder().decode(t.subarray(2,Math.min(t.byteLength,256))).split(`
1135
+ `)[0]??``).trim().split(/\s+/)[0]??``;return n.startsWith(`/`)?n:null}function isArchIndependent(t){return!t.some(t=>isNativeBinary(t.data))}function readBinaryArch(t){if(t.byteLength<20)return null;let n=(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;if(n===2135247942){let n=t[5]===1?t[18]|t[19]<<8:t[18]<<8|t[19];return DV[n]??null}if(n===4277009102||n===4277009103)return OV[(t[4]<<24|t[5]<<16|t[6]<<8|t[7])>>>0]??null;if(n===3472551422||n===3489328638)return OV[(t[7]<<24|t[6]<<16|t[5]<<8|t[4])>>>0]??null;if(t[0]===77&&t[1]===90&&t.byteLength>=64){let n=(t[60]|t[61]<<8|t[62]<<16|t[63]<<24)>>>0;return n+6>t.byteLength||(t[n]|t[n+1]<<8|t[n+2]<<16)>>>0!=17744||t[n+3]!==0?null:kV[t[n+4]|t[n+5]<<8]??null}return null}function assertPayloadMatchesArch(t,n){for(let S of t){let t=readBinaryArch(S.data);if(!(t===null||t===n))throw Error(`gjsify ship: the payload is ${t}, but the package would be labelled ${n} — ${S.path} is built for ${t}.\n \`--arch\` names the architecture the PAYLOAD was built for; it does not cross-compile anything.
1136
+ A package labelled ${n} installs on ${n} and then fails to load. Build the payload for ${n}\n (its own prebuild), or assemble the stage without \`--arch\` and label the payload you actually have.`)}}function classifyBinary(t){if(t.byteLength<4)return null;switch((t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0){case 2135247942:return`elf`;case 4277009102:case 4277009103:case 3472551422:case 3489328638:case 3405691582:return`macho`;default:return t[0]===77&&t[1]===90?`pe`:null}}function isNativeBinary(t){return classifyBinary(t)!==null}var xV,SV,CV,wV,TV,EV,DV,OV,kV,AV=__esmMin(()=>{Rd(),hV(),bV(),OB(),xV=new Set([`rem`,`set`,`setlocal`,`endlocal`,`echo`,`goto`,`exit`,`title`,`pause`,`shift`,`cd`,`chdir`,`pushd`,`popd`,`color`,`cls`,`verify`,`prompt`]),SV=new Set([`exist`,`defined`,`errorlevel`]),CV=new Set([`equ`,`neq`,`lss`,`leq`,`gtr`,`geq`]),wV=32,TV=[[DB.schemas,({hasCompiledSchemas:t})=>t?[`inert`,"the schema SOURCE; `gschemas.compiled` is staged beside it and that is what GSettings reads, so this file is carried and never opened"]:[`aborts`,"needs `glib-compile-schemas`, and the launcher points XDG_DATA_DIRS here — GSettings ABORTS on a schema directory with no `gschemas.compiled`"]],[DB.mime,()=>[`inert`,"needs `update-mime-database`; detection runs off the compiled cache"]],[DB.icons,()=>[`inert`,"needs `gtk-update-icon-cache`; neither OS reads the hicolor theme"]],[DB.applications,()=>[`inert`,`a freedesktop desktop entry; neither OS reads one`]],[DB.metainfo,()=>[`inert`,`an AppStream component; neither OS reads one`]]],EV=[DB.locale,DB.fonts,yV],DV={3:`ia32`,21:`ppc64`,22:`s390x`,40:`arm`,62:`x64`,183:`arm64`,243:`riscv64`},OV={7:`ia32`,12:`arm`,16777223:`x64`,16777228:`arm64`},kV={332:`ia32`,34404:`x64`,43620:`arm64`}});async function buildDeb(t){let{payload:n,mtime:S}=t,C=t.prefix.replace(/^\/+/,``),N=n.map(t=>({...t,tarPath:`./${pn.join(C,t.path)}`})),F=ancestorDirectories(N.map(t=>t.tarPath)),I=await gzipDeterministic(createTarball([...F.map(t=>({name:t,mode:493,mtime:S,directory:!0})),...N.map(t=>({name:t.tarPath,body:t.data,mode:t.mode,mtime:S}))])),H=renderControl(t,N.reduce((t,n)=>t+Math.ceil(n.data.byteLength/1024),0)+F.length),W=N.map(t=>`${createHash(`md5`).update(t.data).digest(`hex`)} ${t.tarPath.slice(2)}\n`).join(``),q=[{name:`./`,mode:493,mtime:S,directory:!0},{name:`./control`,body:H,mode:420,mtime:S},{name:`./md5sums`,body:W,mode:420,mtime:S}],Y=renderDebScripts(readPayloadFacts(n),t.prefix);for(let[t,n]of Object.entries(Y))q.push({name:`./${t}`,body:n,mode:493,mtime:S});let X=await gzipDeterministic(createTarball(q));return createArArchive([{name:`debian-binary`,data:new TextEncoder().encode(`2.0
1137
1137
  `),mtime:S},{name:`control.tar.gz`,data:X,mtime:S},{name:`data.tar.gz`,data:I,mtime:S}])}function singleLine(t){return t.replace(/[\r\n]+/g,` `).trim()}function ancestorDirectories(t){let n=new Set([`./`]);for(let S of t){let t=S.replace(/^\.\//,``).split(`/`);t.pop();let C=`.`;for(let S of t)C=`${C}/${S}`,n.add(`${C}/`)}return[...n].sort()}function renderControl(t,n){let{settings:S}=t,C=[[`Package`,S.binaryName],[`Version`,`${S.version}-${S.release}`],[`Architecture`,t.archLabel],[`Maintainer`,S.maintainer],[`Installed-Size`,String(n)]];t.depends.length>0&&C.push([`Depends`,t.depends.map(formatDebDepend).join(`, `)]),t.recommends!==void 0&&t.recommends.length>0&&C.push([`Recommends`,t.recommends.map(formatDebDepend).join(`, `)]),C.push([`Section`,S.section],[`Priority`,`optional`]),S.homepage&&C.push([`Homepage`,S.homepage]);let N=C.map(([t,n])=>`${t}: ${singleLine(n)}`);return N.push(`Description: ${singleLine(S.summary)}`),S.description.filter(t=>t!==S.summary).forEach((t,n)=>{n>0&&N.push(` .`),N.push(` ${t}`)}),`${N.join(`
1138
- `)}\n`}var EV=__esmMin(()=>{Qc(),Pn(),hL(),dB(),bB(),xB(),wB(),TV()});function xmlEscape(t){return t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`)}var DV=__esmMin(()=>{});function validateMimeTypes(t){let n=new Set;for(let S of t){if(!OV.test(S.type))throw Error(`gjsify ship: \`gjsify.ship.mimeTypes\` has an invalid type "${S.type}". Expected \`<media>/<subtype>\`, e.g. \`application/x-bauplan\` — update-mime-database ignores a malformed name, so the type would install and never resolve.`);if(n.has(S.type))throw Error(`gjsify ship: \`gjsify.ship.mimeTypes\` defines ${S.type} twice. Which comment and glob set win would depend on document order.`);if(n.add(S.type),S.comment.trim()===``)throw Error(`gjsify ship: ${S.type} has an empty \`comment\`. A file manager then shows the user the raw type string instead of a name.`);for(let t of S.globs??[])if(!t.includes(`*`)&&!t.includes(`?`)&&!t.includes(`[`))throw Error(`gjsify ship: ${S.type} has the glob "${t}", which matches only a file named exactly that. A suffix pattern is written \`*.${t.replace(/^\.+/,``)}\`.`);if((S.globs??[]).length===0&&S.subClassOf===void 0)throw Error(`gjsify ship: ${S.type} declares neither \`globs\` nor \`subClassOf\`, so nothing can ever match it. The type would be registered and then never assigned to a file.`)}}function renderMimePackage(t){return`<?xml version="1.0" encoding="UTF-8"?>
1138
+ `)}\n`}var jV=__esmMin(()=>{Qc(),Pn(),bL(),gB(),TB(),EB(),kB(),AV()});function xmlEscape(t){return t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`)}var MV=__esmMin(()=>{});function validateMimeTypes(t){let n=new Set;for(let S of t){if(!NV.test(S.type))throw Error(`gjsify ship: \`gjsify.ship.mimeTypes\` has an invalid type "${S.type}". Expected \`<media>/<subtype>\`, e.g. \`application/x-bauplan\` — update-mime-database ignores a malformed name, so the type would install and never resolve.`);if(n.has(S.type))throw Error(`gjsify ship: \`gjsify.ship.mimeTypes\` defines ${S.type} twice. Which comment and glob set win would depend on document order.`);if(n.add(S.type),S.comment.trim()===``)throw Error(`gjsify ship: ${S.type} has an empty \`comment\`. A file manager then shows the user the raw type string instead of a name.`);for(let t of S.globs??[])if(!t.includes(`*`)&&!t.includes(`?`)&&!t.includes(`[`))throw Error(`gjsify ship: ${S.type} has the glob "${t}", which matches only a file named exactly that. A suffix pattern is written \`*.${t.replace(/^\.+/,``)}\`.`);if((S.globs??[]).length===0&&S.subClassOf===void 0)throw Error(`gjsify ship: ${S.type} declares neither \`globs\` nor \`subClassOf\`, so nothing can ever match it. The type would be registered and then never assigned to a file.`)}}function renderMimePackage(t){return`<?xml version="1.0" encoding="UTF-8"?>
1139
1139
  <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
1140
1140
  ${t.map(t=>{let n=[` <mime-type type="${xmlEscape(t.type)}">`,` <comment>${xmlEscape(t.comment)}</comment>`];t.subClassOf!==void 0&&n.push(` <sub-class-of type="${xmlEscape(t.subClassOf)}"/>`);for(let S of t.globs??[])n.push(` <glob pattern="${xmlEscape(S)}"/>`);return t.genericIcon!==void 0&&n.push(` <generic-icon name="${xmlEscape(t.genericIcon)}"/>`),n.push(` </mime-type>`),n.join(`
1141
1141
  `)}).join(`
1142
1142
  `)}
1143
1143
  </mime-info>
1144
- `}var OV,kV=__esmMin(()=>{DV(),OV=/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/});function normaliseVersion(t){let n=[],S=t.trim();S.startsWith(`v`)&&(S=S.slice(1));let C=S.indexOf(`+`);C!==-1&&(n.push(`gjsify ship: dropped the build metadata "${S.slice(C)}" from version ${t} — neither dpkg nor rpm has a field for it. Set \`gjsify.ship.version\` to pin an exact package version.`),S=S.slice(0,C));let N=S.indexOf(`-`);if(N!==-1){let t=S.slice(N+1).replace(/-/g,`.`);S=`${S.slice(0,N)}~${t}`}if(!AV.test(S))throw Error(`gjsify ship: "${t}" is not a usable package version (normalised to "${S}"). It must start with a digit and contain only letters, digits, \`.\`, \`+\` and \`~\`. Set \`gjsify.ship.version\` in package.json to override it.`);return{version:S,warnings:n}}function assertRelease(t){if(!jV.test(t))throw Error(`gjsify ship: "${t}" is not a usable package release. It must start with a letter or digit and contain only letters, digits, \`.\`, \`+\` and \`~\`. Set \`gjsify.ship.release\` in package.json.`);return t}var AV,jV,MV=__esmMin(()=>{AV=/^\d[A-Za-z0-9.+~]*$/,jV=/^[A-Za-z0-9][A-Za-z0-9.+~]*$/});function resolveShipApp(t){let n=t.perTarget??{};for(let t of Object.keys(n))if(!Object.hasOwn(NV,t))throw Error(`gjsify ship: \`gjsify.ship.app.${t}\` is not an OS this command assembles for. Known: ${Object.keys(NV).join(`, `)} — the \`process.platform\` spelling, not the \`gjsify ship <os>\` positional's. A runtime under a key nothing reads leaves that target on \`gjsify.app\` with nothing to say so.`);let S=n[t.layoutOs],C=S!==void 0,N=C?`gjsify.ship.app.${t.layoutOs}`:`gjsify.app`,F=C?S:t.project;if(F!==void 0&&F!==`gjs`&&F!==`node`)throw Error(`gjsify ship: \`${N}\` is "${F}", and only \`gjs\` and \`node\` can be packaged. A browser bundle has no process to launch, and a NativeScript app ships as an APK/IPA through a different pipeline. ADR 0024 § 4 has the runtime-per-OS table.`);return{app:F===`node`?`node`:`gjs`,key:N,overridden:C}}function resolveShipKind(t,n){return t.kind??n.kind??`app`}function resolveShipSettings(t){let n=[],{pkg:S,ship:C,flatpak:N,discovered:F}=t,I={...N,...definedOnly(C)},H=C.mimeTypes??[];if(H.length>0){validateMimeTypes(H);let t=new Set([...I.provides?.mimetypes??[],...H.map(t=>t.type)]);I.provides={...I.provides,mimetypes:[...t]}}let W=C.binaryName??deriveBinaryName(S.name),q=C.appId??N.appId??reverseDnsOrThrow(S.name,W),Y=I.name??titleCase(W),X=resolveShipKind(C,N),Z=t.app,te=C.version??S.version;if(!te)throw Error("gjsify ship: no version — set `version` in package.json or `gjsify.ship.version`.");let ne=normaliseVersion(te);n.push(...ne.warnings);let re=I.license?.project??S.license;if(!re)throw Error('gjsify ship: no licence — set `license` in package.json (an SPDX id, e.g. "MIT") or `gjsify.ship.license.project`. Both deb and rpm carry it as a required field.');I.license={...I.license,project:re};let ie=C.maintainer??formatAuthor(S.author)??formatDeveloper(I);if(!ie)throw Error('gjsify ship: no maintainer — set `author` in package.json ("Name <you@example.com>"), `gjsify.ship.maintainer`, or `gjsify.ship.developer`. dpkg refuses a package without one.');let ae=I.summary??S.description??Y,oe=descriptionParagraphs(I.description)??[ae],Q=sectionsFor(I.categories);X===`app`&&F.iconFiles.length===0&&n.push("gjsify ship: no icon found — the installed app will show a placeholder in menus on Linux, the Flatpak will carry no catalogue icon for an app store to show, and the darwin and windows layouts refuse to stage without one. Point `gjsify.ship.icon` at an SVG (or a directory of sized PNGs).");let se=resolveShipFlatpakSettings({ship:C,flatpak:N,kind:X});return n.push(...se.warnings),{settings:{projectDir:t.projectDir,appId:q,name:Y,binaryName:W,version:ne.version,release:assertRelease(C.release??`1`),maintainer:ie,summary:ae,description:oe,license:re,licenseFile:F.licenseFile,changelogFile:F.changelogFile,homepage:I.homepageUrl??S.homepage,section:C.section??Q.section,group:C.group??Q.group,kind:X,mimeTypes:H,extraDepends:{deb:C.depends?.deb??[],rpm:C.depends?.rpm??[]},typelibPackages:C.typelibPackages??{},bundlePath:F.bundlePath,bundleDir:F.bundleDir,iconFiles:F.iconFiles,schemaFiles:F.schemaFiles,typelibFiles:F.typelibFiles,formatFiles:F.formatFiles,localeFiles:F.localeFiles,fontFiles:F.fontFiles,extraFiles:C.extraFiles??{},execArgs:C.execArgs??[],outDir:t.cli.outDir??C.outDir??`ship`,arch:t.cli.arch??process.arch,app:Z,layoutOs:t.cli.layoutOs,minGjsVersion:C.minGjsVersion??`1.86`,minNodeVersion:C.minNodeVersion??`24`,flatpak:se.settings},metadata:I,warnings:n}}function resolveShipBundle(t){let n=t.ship.bundle,S=typeof n==`object`&&n?n:{};for(let t of Object.keys(S))if(!Object.hasOwn(NV,t))throw Error(`gjsify ship: \`gjsify.ship.bundle.${t}\` is not an OS this command assembles for. Known: ${Object.keys(NV).join(`, `)} — the \`process.platform\` spelling, not the \`gjsify ship <os>\` positional's. An entry under a key nothing reads leaves that target on \`gjsify.main\` with nothing to say so.`);let C=typeof n==`string`?n:void 0,N=t.pkg.gjsify?.main??t.pkg.main,entryFor=t=>S[t]??C??N,F=S[t.layoutOs],I=entryFor(t.layoutOs),H=F===void 0?C===void 0?t.pkg.gjsify?.main===void 0?`main`:`gjsify.main`:`gjsify.ship.bundle`:`gjsify.ship.bundle.${t.layoutOs}`,W=[...new Set(Object.keys(NV).filter(n=>n!==t.layoutOs).map(entryFor).filter(t=>t!==void 0&&t!==I))];return{declared:I,key:H,overridden:F!==void 0,foreign:W}}function deriveBinaryName(t){if(!t)throw Error("gjsify ship: no package name — set `name` in package.json or `gjsify.ship.binaryName`.");let n=(t.includes(`/`)?t.split(`/`).pop():t).toLowerCase().replace(/[^a-z\d+.-]+/g,`-`).replace(/^-+|-+$/g,``);if(!/^[a-z\d][a-z\d+.-]+$/.test(n))throw Error(`gjsify ship: cannot derive a package name from "${t}" (got "${n}"). Set \`gjsify.ship.binaryName\` to something matching \`[a-z0-9][a-z0-9+.-]+\`.`);return n}function reverseDnsOrThrow(t,n){if(t&&/^[A-Za-z][\w-]*(\.[A-Za-z][\w-]*){2,}$/.test(t))return t;throw Error(`gjsify ship: no application id. Set \`gjsify.ship.appId\` (or \`gjsify.flatpak.appId\`) to a reverse-DNS id such as "io.github.you.${titleCase(n).replace(/\s+/g,``)}". It names the desktop entry, the AppStream component and the installed icon, so it cannot be guessed.`)}function definedOnly(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>t!==void 0))}function titleCase(t){return t.split(/[-_.]+/).filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(` `)}function sectionsFor(t){for(let[n,S]of PV)if(t?.includes(n))return S;return{section:`misc`,group:`Applications/System`}}function formatAuthor(t){if(typeof t==`string`)return t.replace(/\s*\([^)]*\)\s*$/,``).trim()||void 0;if(t?.name)return t.email?`${t.name} <${t.email}>`:t.name}function formatDeveloper(t){let n=t.developer;if(n?.name)return n.email?`${n.name} <${n.email}>`:n.name}function descriptionParagraphs(t){if(t===void 0)return;if(typeof t==`string`){let n=t.trim().split(/\n\n+/).map(t=>t.trim().replace(/\s+/g,` `)).filter(t=>t.length>0);return n.length>0?n:void 0}let n=[];for(let S of t)if(typeof S==`string`){let t=S.trim().replace(/\s+/g,` `);t&&n.push(t)}else if(`p`in S)n.push(S.p.trim().replace(/\s+/g,` `));else for(let t of S.ul)n.push(`* ${(typeof t==`string`?t:t.item).trim().replace(/\s+/g,` `)}`);return n.length>0?n:void 0}var NV,PV,FV,IV,LV=__esmMin(()=>{kV(),Pn(),bB(),Sz(),MV(),NV={linux:!0,darwin:!0,win32:!0},PV=[[`Development`,{section:`devel`,group:`Development/Tools`}],[`Education`,{section:`education`,group:`Applications/Education`}],[`Game`,{section:`games`,group:`Amusements/Games`}],[`Graphics`,{section:`graphics`,group:`Applications/Multimedia`}],[`AudioVideo`,{section:`sound`,group:`Applications/Multimedia`}],[`Network`,{section:`net`,group:`Applications/Internet`}],[`Office`,{section:`text`,group:`Applications/Productivity`}],[`Science`,{section:`science`,group:`Applications/Engineering`}],[`System`,{section:`admin`,group:`Applications/System`}],[`Utility`,{section:`utils`,group:`Applications/System`}]],FV=[`LICENSE`,`LICENSE.md`,`LICENSE.txt`,`COPYING`,`COPYING.md`],IV=[`CHANGELOG.md`,`CHANGELOG`,`CHANGELOG.txt`,`NEWS.md`,`NEWS`]});function discoverPayload(t){let{projectDir:n,ship:S}=t,C=resolveBundle(t),N=xn(C,`..`),F=discoverLocales(n,S.localeDir);return{bundlePath:C,bundleDir:N,bundleFiles:withoutForeignEntries(withoutLocaleTree(listFilesRecursive(N),N,n,S.localeDir),N,n,t.foreignBundles??[],C),iconFiles:discoverIcons(n,S.icon??t.flatpakIcon),schemaFiles:discoverSchemas(n,S.schemas),typelibFiles:discoverTypelibs(n,resolveBundledTypelibs(S.bundledTypelibs,t.layoutOs)),formatFiles:discoverFormatFiles(n,S,t.layoutOs),localeFiles:F,fontFiles:discoverFonts(n,S.fonts),licenseFile:discoverLicense(n,S.licenseFile),changelogFile:discoverChangelog(n,S.changelogFile)}}function discoverFormatFiles(t,n,S){let C={};if(S!==void 0&&S!==`linux`)return C;for(let[S,N]of Object.entries(n.formats??{})){if(S!==`deb`&&S!==`rpm`)throw Error(`gjsify ship: \`gjsify.ship.formats.${S}\` is not a format that carries its own files. Known: deb, rpm.`);C[S]={typelibFiles:discoverTypelibs(t,N?.bundledTypelibs),extraFiles:Object.fromEntries(Object.entries(N?.extraFiles??{}).map(([n,S])=>[n,xn(t,S)]))}}return C}function resolveBundledTypelibs(t,n){if(t===void 0||Array.isArray(t))return t??[];let S=[`linux`,`darwin`,`win32`];for(let n of Object.keys(t))if(!S.includes(n))throw Error(`gjsify ship: \`gjsify.ship.bundledTypelibs.${n}\` is not an OS this command assembles for. Known: ${S.join(`, `)} — the \`process.platform\` spelling, not the \`gjsify ship <os>\` positional's.`);if(n===void 0)throw Error("gjsify ship: `gjsify.ship.bundledTypelibs` is a per-OS table but no layout OS was given.");return t[n]??[]}function discoverTypelibs(t,n){let S=[];for(let C of n??[]){let n=xn(t,C);if(!existsSync(n))throw Error(`gjsify ship: \`gjsify.ship.bundledTypelibs\` names ${C}, which does not exist. A missing directory here means the package would install without the typelib it promises.`);for(let t of listFilesRecursive(n))(/\.(typelib|dylib|dll)$/i.test(t)||/\.so(\.\d+)*$/.test(t))&&S.push(wn(n,t))}return S}function withoutLocaleTree(t,n,S,C){if(C===void 0)return t;let N=Tn(n,xn(S,C));if(N===``||N.startsWith(`..`)||Cn(N))return t;let F=`${N.split(jn).join(pn.sep)}${pn.sep}`;return t.filter(t=>!`${t}${pn.sep}`.startsWith(F))}function discoverLocales(t,n){if(n===void 0)return[];let S=xn(t,n);if(!existsSync(S))throw Error(`gjsify ship: \`gjsify.ship.localeDir\` names ${n}, which does not exist. Compile the catalogues first (msgfmt, or @gjsify/vite-plugin-gettext) — a missing directory here means the package would install without the translations it promises.`);let C=[],N=[];for(let t of listFilesRecursive(S)){if(t.endsWith(`.po`)||t.endsWith(`.pot`)){N.push(`${t} (a .po source; bindtextdomain reads .mo only)`);continue}if(!t.endsWith(`.mo`))continue;let n=t.split(pn.sep);if(n.length!==3||n[1]!==`LC_MESSAGES`){N.push(`${t} (expected <lang>/LC_MESSAGES/<domain>.mo)`);continue}C.push({rel:n.join(`/`),abs:wn(S,t)})}if(N.length>0)throw Error(`gjsify ship: \`gjsify.ship.localeDir\` (${n}) holds files no catalogue lookup will find:\n`+N.map(t=>` ${t}`).join(`
1144
+ `}var NV,PV=__esmMin(()=>{MV(),NV=/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/});function normaliseVersion(t){let n=[],S=t.trim();S.startsWith(`v`)&&(S=S.slice(1));let C=S.indexOf(`+`);C!==-1&&(n.push(`gjsify ship: dropped the build metadata "${S.slice(C)}" from version ${t} — neither dpkg nor rpm has a field for it. Set \`gjsify.ship.version\` to pin an exact package version.`),S=S.slice(0,C));let N=S.indexOf(`-`);if(N!==-1){let t=S.slice(N+1).replace(/-/g,`.`);S=`${S.slice(0,N)}~${t}`}if(!FV.test(S))throw Error(`gjsify ship: "${t}" is not a usable package version (normalised to "${S}"). It must start with a digit and contain only letters, digits, \`.\`, \`+\` and \`~\`. Set \`gjsify.ship.version\` in package.json to override it.`);return{version:S,warnings:n}}function assertRelease(t){if(!IV.test(t))throw Error(`gjsify ship: "${t}" is not a usable package release. It must start with a letter or digit and contain only letters, digits, \`.\`, \`+\` and \`~\`. Set \`gjsify.ship.release\` in package.json.`);return t}var FV,IV,LV=__esmMin(()=>{FV=/^\d[A-Za-z0-9.+~]*$/,IV=/^[A-Za-z0-9][A-Za-z0-9.+~]*$/});function resolveShipApp(t){let n=t.perTarget??{};for(let t of Object.keys(n))if(!Object.hasOwn(RV,t))throw Error(`gjsify ship: \`gjsify.ship.app.${t}\` is not an OS this command assembles for. Known: ${Object.keys(RV).join(`, `)} — the \`process.platform\` spelling, not the \`gjsify ship <os>\` positional's. A runtime under a key nothing reads leaves that target on \`gjsify.app\` with nothing to say so.`);let S=n[t.layoutOs],C=S!==void 0,N=C?`gjsify.ship.app.${t.layoutOs}`:`gjsify.app`,F=C?S:t.project;if(F!==void 0&&F!==`gjs`&&F!==`node`)throw Error(`gjsify ship: \`${N}\` is "${F}", and only \`gjs\` and \`node\` can be packaged. A browser bundle has no process to launch, and a NativeScript app ships as an APK/IPA through a different pipeline. ADR 0024 § 4 has the runtime-per-OS table.`);return{app:F===`node`?`node`:`gjs`,key:N,overridden:C}}function resolveShipKind(t,n){return t.kind??n.kind??`app`}function resolveShipSettings(t){let n=[],{pkg:S,ship:C,flatpak:N,discovered:F}=t,I={...N,...definedOnly(C)},H=C.mimeTypes??[];if(H.length>0){validateMimeTypes(H);let t=new Set([...I.provides?.mimetypes??[],...H.map(t=>t.type)]);I.provides={...I.provides,mimetypes:[...t]}}let W=C.binaryName??deriveBinaryName(S.name),q=C.appId??N.appId??reverseDnsOrThrow(S.name,W),Y=I.name??titleCase(W),X=resolveShipKind(C,N),Z=t.app,te=C.version??S.version;if(!te)throw Error("gjsify ship: no version — set `version` in package.json or `gjsify.ship.version`.");let ne=normaliseVersion(te);n.push(...ne.warnings);let re=I.license?.project??S.license;if(!re)throw Error('gjsify ship: no licence — set `license` in package.json (an SPDX id, e.g. "MIT") or `gjsify.ship.license.project`. Both deb and rpm carry it as a required field.');I.license={...I.license,project:re};let ie=C.maintainer??formatAuthor(S.author)??formatDeveloper(I);if(!ie)throw Error('gjsify ship: no maintainer — set `author` in package.json ("Name <you@example.com>"), `gjsify.ship.maintainer`, or `gjsify.ship.developer`. dpkg refuses a package without one.');let ae=I.summary??S.description??Y,oe=descriptionParagraphs(I.description)??[ae],Q=sectionsFor(I.categories);X===`app`&&F.iconFiles.length===0&&n.push("gjsify ship: no icon found — the installed app will show a placeholder in menus on Linux, the Flatpak will carry no catalogue icon for an app store to show, and the darwin and windows layouts refuse to stage without one. Point `gjsify.ship.icon` at an SVG (or a directory of sized PNGs).");let se=resolveShipFlatpakSettings({ship:C,flatpak:N,kind:X});return n.push(...se.warnings),{settings:{projectDir:t.projectDir,appId:q,name:Y,binaryName:W,version:ne.version,release:assertRelease(C.release??`1`),maintainer:ie,summary:ae,description:oe,license:re,licenseFile:F.licenseFile,changelogFile:F.changelogFile,homepage:I.homepageUrl??S.homepage,section:C.section??Q.section,group:C.group??Q.group,kind:X,mimeTypes:H,extraDepends:{deb:C.depends?.deb??[],rpm:C.depends?.rpm??[]},typelibPackages:C.typelibPackages??{},bundlePath:F.bundlePath,bundleDir:F.bundleDir,iconFiles:F.iconFiles,schemaFiles:F.schemaFiles,typelibFiles:F.typelibFiles,formatFiles:F.formatFiles,localeFiles:F.localeFiles,fontFiles:F.fontFiles,extraFiles:C.extraFiles??{},execArgs:C.execArgs??[],outDir:t.cli.outDir??C.outDir??`ship`,arch:t.cli.arch??process.arch,app:Z,layoutOs:t.cli.layoutOs,minGjsVersion:C.minGjsVersion??`1.86`,minNodeVersion:C.minNodeVersion??`24`,flatpak:se.settings},metadata:I,warnings:n}}function resolveShipBundle(t){let n=t.ship.bundle,S=typeof n==`object`&&n?n:{};for(let t of Object.keys(S))if(!Object.hasOwn(RV,t))throw Error(`gjsify ship: \`gjsify.ship.bundle.${t}\` is not an OS this command assembles for. Known: ${Object.keys(RV).join(`, `)} — the \`process.platform\` spelling, not the \`gjsify ship <os>\` positional's. An entry under a key nothing reads leaves that target on \`gjsify.main\` with nothing to say so.`);let C=typeof n==`string`?n:void 0,N=t.pkg.gjsify?.main??t.pkg.main,entryFor=t=>S[t]??C??N,F=S[t.layoutOs],I=entryFor(t.layoutOs),H=F===void 0?C===void 0?t.pkg.gjsify?.main===void 0?`main`:`gjsify.main`:`gjsify.ship.bundle`:`gjsify.ship.bundle.${t.layoutOs}`,W=[...new Set(Object.keys(RV).filter(n=>n!==t.layoutOs).map(entryFor).filter(t=>t!==void 0&&t!==I))];return{declared:I,key:H,overridden:F!==void 0,foreign:W}}function deriveBinaryName(t){if(!t)throw Error("gjsify ship: no package name — set `name` in package.json or `gjsify.ship.binaryName`.");let n=(t.includes(`/`)?t.split(`/`).pop():t).toLowerCase().replace(/[^a-z\d+.-]+/g,`-`).replace(/^-+|-+$/g,``);if(!/^[a-z\d][a-z\d+.-]+$/.test(n))throw Error(`gjsify ship: cannot derive a package name from "${t}" (got "${n}"). Set \`gjsify.ship.binaryName\` to something matching \`[a-z0-9][a-z0-9+.-]+\`.`);return n}function reverseDnsOrThrow(t,n){if(t&&/^[A-Za-z][\w-]*(\.[A-Za-z][\w-]*){2,}$/.test(t))return t;throw Error(`gjsify ship: no application id. Set \`gjsify.ship.appId\` (or \`gjsify.flatpak.appId\`) to a reverse-DNS id such as "io.github.you.${titleCase(n).replace(/\s+/g,``)}". It names the desktop entry, the AppStream component and the installed icon, so it cannot be guessed.`)}function definedOnly(t){return Object.fromEntries(Object.entries(t).filter(([,t])=>t!==void 0))}function titleCase(t){return t.split(/[-_.]+/).filter(t=>t.length>0).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(` `)}function sectionsFor(t){for(let[n,S]of zV)if(t?.includes(n))return S;return{section:`misc`,group:`Applications/System`}}function formatAuthor(t){if(typeof t==`string`)return t.replace(/\s*\([^)]*\)\s*$/,``).trim()||void 0;if(t?.name)return t.email?`${t.name} <${t.email}>`:t.name}function formatDeveloper(t){let n=t.developer;if(n?.name)return n.email?`${n.name} <${n.email}>`:n.name}function descriptionParagraphs(t){if(t===void 0)return;if(typeof t==`string`){let n=t.trim().split(/\n\n+/).map(t=>t.trim().replace(/\s+/g,` `)).filter(t=>t.length>0);return n.length>0?n:void 0}let n=[];for(let S of t)if(typeof S==`string`){let t=S.trim().replace(/\s+/g,` `);t&&n.push(t)}else if(`p`in S)n.push(S.p.trim().replace(/\s+/g,` `));else for(let t of S.ul)n.push(`* ${(typeof t==`string`?t:t.item).trim().replace(/\s+/g,` `)}`);return n.length>0?n:void 0}var RV,zV,BV,VV,HV=__esmMin(()=>{PV(),Pn(),TB(),Dz(),LV(),RV={linux:!0,darwin:!0,win32:!0},zV=[[`Development`,{section:`devel`,group:`Development/Tools`}],[`Education`,{section:`education`,group:`Applications/Education`}],[`Game`,{section:`games`,group:`Amusements/Games`}],[`Graphics`,{section:`graphics`,group:`Applications/Multimedia`}],[`AudioVideo`,{section:`sound`,group:`Applications/Multimedia`}],[`Network`,{section:`net`,group:`Applications/Internet`}],[`Office`,{section:`text`,group:`Applications/Productivity`}],[`Science`,{section:`science`,group:`Applications/Engineering`}],[`System`,{section:`admin`,group:`Applications/System`}],[`Utility`,{section:`utils`,group:`Applications/System`}]],BV=[`LICENSE`,`LICENSE.md`,`LICENSE.txt`,`COPYING`,`COPYING.md`],VV=[`CHANGELOG.md`,`CHANGELOG`,`CHANGELOG.txt`,`NEWS.md`,`NEWS`]});function discoverPayload(t){let{projectDir:n,ship:S}=t,C=resolveBundle(t),N=xn(C,`..`),F=discoverLocales(n,S.localeDir);return{bundlePath:C,bundleDir:N,bundleFiles:withoutForeignEntries(withoutLocaleTree(listFilesRecursive(N),N,n,S.localeDir),N,n,t.foreignBundles??[],C),iconFiles:discoverIcons(n,S.icon??t.flatpakIcon),schemaFiles:discoverSchemas(n,S.schemas),typelibFiles:discoverTypelibs(n,resolveBundledTypelibs(S.bundledTypelibs,t.layoutOs)),formatFiles:discoverFormatFiles(n,S,t.layoutOs),localeFiles:F,fontFiles:discoverFonts(n,S.fonts),licenseFile:discoverLicense(n,S.licenseFile),changelogFile:discoverChangelog(n,S.changelogFile)}}function discoverFormatFiles(t,n,S){let C={};if(S!==void 0&&S!==`linux`)return C;for(let[S,N]of Object.entries(n.formats??{})){if(S!==`deb`&&S!==`rpm`)throw Error(`gjsify ship: \`gjsify.ship.formats.${S}\` is not a format that carries its own files. Known: deb, rpm.`);C[S]={typelibFiles:discoverTypelibs(t,N?.bundledTypelibs),extraFiles:Object.fromEntries(Object.entries(N?.extraFiles??{}).map(([n,S])=>[n,xn(t,S)]))}}return C}function resolveBundledTypelibs(t,n){if(t===void 0||Array.isArray(t))return t??[];let S=[`linux`,`darwin`,`win32`];for(let n of Object.keys(t))if(!S.includes(n))throw Error(`gjsify ship: \`gjsify.ship.bundledTypelibs.${n}\` is not an OS this command assembles for. Known: ${S.join(`, `)} — the \`process.platform\` spelling, not the \`gjsify ship <os>\` positional's.`);if(n===void 0)throw Error("gjsify ship: `gjsify.ship.bundledTypelibs` is a per-OS table but no layout OS was given.");return t[n]??[]}function discoverTypelibs(t,n){let S=[];for(let C of n??[]){let n=xn(t,C);if(!existsSync(n))throw Error(`gjsify ship: \`gjsify.ship.bundledTypelibs\` names ${C}, which does not exist. A missing directory here means the package would install without the typelib it promises.`);for(let t of listFilesRecursive(n))(/\.(typelib|dylib|dll)$/i.test(t)||/\.so(\.\d+)*$/.test(t))&&S.push(wn(n,t))}return S}function withoutLocaleTree(t,n,S,C){if(C===void 0)return t;let N=Tn(n,xn(S,C));if(N===``||N.startsWith(`..`)||Cn(N))return t;let F=`${N.split(jn).join(pn.sep)}${pn.sep}`;return t.filter(t=>!`${t}${pn.sep}`.startsWith(F))}function discoverLocales(t,n){if(n===void 0)return[];let S=xn(t,n);if(!existsSync(S))throw Error(`gjsify ship: \`gjsify.ship.localeDir\` names ${n}, which does not exist. Compile the catalogues first (msgfmt, or @gjsify/vite-plugin-gettext) — a missing directory here means the package would install without the translations it promises.`);let C=[],N=[];for(let t of listFilesRecursive(S)){if(t.endsWith(`.po`)||t.endsWith(`.pot`)){N.push(`${t} (a .po source; bindtextdomain reads .mo only)`);continue}if(!t.endsWith(`.mo`))continue;let n=t.split(pn.sep);if(n.length!==3||n[1]!==`LC_MESSAGES`){N.push(`${t} (expected <lang>/LC_MESSAGES/<domain>.mo)`);continue}C.push({rel:n.join(`/`),abs:wn(S,t)})}if(N.length>0)throw Error(`gjsify ship: \`gjsify.ship.localeDir\` (${n}) holds files no catalogue lookup will find:\n`+N.map(t=>` ${t}`).join(`
1145
1145
  `)+`
1146
- A misplaced catalogue installs and then shows nothing, which reads exactly like having no translation at all. Lay them out as <lang>/LC_MESSAGES/<domain>.mo.`);if(C.length===0)throw Error(`gjsify ship: \`gjsify.ship.localeDir\` (${n}) contains no \`.mo\` catalogue. Declaring a locale directory that ships nothing is a promise the package does not keep.`);return C}function withoutForeignEntries(t,n,S,C,N){if(C.length===0)return t;let F=new Set;for(let t of C){let C=Cn(t)?t:xn(S,t);if(C===N)continue;let I=Tn(n,C);I===``||I.startsWith(`..`)||Cn(I)||F.add(I.split(jn).join(pn.sep))}return t.filter(t=>!F.has(t))}function resolveBundle(t){let n=t.declaredBundle;if(n===void 0)throw Error("gjsify ship: no bundle to ship. Set `gjsify.main` (or `main`) in package.json to the built bundle, or `gjsify.ship.bundle` to override it.");let S=Cn(n)?n:xn(t.projectDir,n);if(!existsSync(S))throw Error(`gjsify ship: the bundle ${n} does not exist. Build it first (\`gjsify run build\`), or drop \`--skip-build\`.`);return S}function discoverIcons(t,n){if(n!==void 0){let S=xn(t,n);if(!existsSync(S))throw Error(`gjsify ship: the configured icon path ${n} does not exist.`);return statSync(S).isDirectory()?listIcons(S):[S]}for(let n of[`data/icons`,`data/icons/hicolor`]){let S=wn(t,n);if(existsSync(S)&&statSync(S).isDirectory()){let t=listIcons(S);if(t.length>0)return t}}return[]}function listIcons(t){return listFilesRecursive(t).filter(t=>RV.some(n=>t.toLowerCase().endsWith(n))).map(n=>wn(t,n.split(`/`).join(jn))).sort()}function discoverFonts(t,n){let S=n??`data/fonts`,C=n===void 0?wn(t,`data`,`fonts`):xn(t,n);if(!existsSync(C)){if(n===void 0)return[];throw Error(`gjsify ship: the configured font path ${n} does not exist.`)}if(!statSync(C).isDirectory()){if(assertNotWebFont(C,S),!zV.some(t=>C.toLowerCase().endsWith(t)))throw Error(`gjsify ship: \`gjsify.ship.fonts\` names ${n}, which is not a font face fontconfig will open (${zV.join(`, `)}). A file it cannot read installs and is never found, and Pango substitutes a fallback family rather than reporting anything.`);return[C]}let N=[];for(let t of listFilesRecursive(C))assertNotWebFont(t,S),zV.some(n=>t.toLowerCase().endsWith(n))&&N.push(wn(C,t.split(`/`).join(jn)));if(N.length===0&&n!==void 0)throw Error(`gjsify ship: \`gjsify.ship.fonts\` (${n}) holds no font face (${zV.join(`, `)}). Declaring fonts that ship nothing is a promise the package does not keep — and its symptom is a substituted family, not an error.`);return N.sort()}function assertNotWebFont(t,n){let S=t.toLowerCase(),C=BV.find(t=>S.endsWith(t));if(C!==void 0)throw Error(`gjsify ship: \`gjsify.ship.fonts\` (${n}) carries ${t}, and \`${C}\` is a web-font wrapper whose support is a FreeType BUILD option — brotli for woff2, zlib for woff. Whether it opens is therefore a property of the FreeType the SHIPPED artifact loads (inside \`@gjsify/gtk-runtime-<target>\` for a \`.app\` or a Windows program directory), not of the machine that packaged it. Ship the desktop face instead (${zV.join(`, `)}); a font that fails to open is not an error, it is Pango quietly substituting a different typeface.`)}function discoverSchemas(t,n){let S=n===void 0?[wn(t,`data`)]:[xn(t,n)];for(let t of S){if(!existsSync(t)){if(n!==void 0)throw Error(`gjsify ship: the configured schema path ${n} does not exist.`);continue}if(!statSync(t).isDirectory())return[t];let S=listFilesRecursive(t).filter(t=>t.endsWith(`.gschema.xml`)).map(n=>wn(t,n.split(`/`).join(jn))).sort();if(S.length>0)return S}return[]}function discoverLicense(t,n){if(n!==void 0){let S=xn(t,n);if(!existsSync(S))throw Error(`gjsify ship: the configured licence file ${n} does not exist.`);return S}for(let n of licenseSearchDirs(t))for(let t of FV){let S=wn(n,t);if(existsSync(S))return S}}function discoverChangelog(t,n){if(n!==void 0){let S=xn(t,n);if(!existsSync(S))throw Error(`gjsify ship: the configured changelog file ${n} does not exist.`);return S}for(let n of licenseSearchDirs(t))for(let t of IV){let S=wn(n,t);if(existsSync(S))return S}}function licenseSearchDirs(t){let n=[];for(let S=t;;){if(n.push(S),isProjectRoot(S))return n;let C=En(S);if(C===S)return[t];S=C}}function isProjectRoot(t){if(existsSync(wn(t,`.git`)))return!0;let n=wn(t,`package.json`);if(!existsSync(n))return!1;try{return JSON.parse(readFileSync(n,`utf-8`)).workspaces!==void 0}catch{return!1}}function listFilesRecursive(t){let n=[],walk=S=>{for(let C of readdirSync(S,{withFileTypes:!0}).sort((t,n)=>t.name<n.name?-1:1)){let N=wn(S,C.name);if(C.isDirectory())walk(N);else if(C.isSymbolicLink())throw Error(`gjsify ship: ${N} is a symlink. The payload has to be self-contained — replace it with the file it points at, or exclude it from the bundle directory.`);else C.isFile()&&n.push(pn.join(...Tn(t,N).split(jn)))}};return walk(t),n.sort()}var RV,zV,BV,VV=__esmMin(()=>{Rd(),Pn(),LV(),RV=[`.svg`,`.png`],zV=[`.ttf`,`.otf`,`.ttc`,`.otc`],BV=[`.woff`,`.woff2`,`.eot`]});function isNodeRuntimeTarget(t){return HV.includes(t)}function nodeRuntimePackageName(t){return`@gjsify/node-runtime-${t}`}function nodeRuntimeBinaryName(t){return t.startsWith(`win32-`)?`node.exe`:`node`}function resolveNodeRuntime(t,n={}){let S=n.env??process.env,C=nodeRuntimeBinaryName(t),N=S.GJSIFY_NODE_RUNTIME;if(N){let t=complete(`GJSIFY_NODE_RUNTIME`,N,C);if(t)return t}let F=nodeRuntimePackageName(t),I=resolveInstalledPackage(F,{cwd:n.cwd,bundleUrl:import.meta.url});return I===null?null:complete(F,wn(En(I),`bin`),C)}function complete(t,n,S){let C=wn(n,S),N=wn(n,`LICENSE`);return!existsSync(C)||!existsSync(N)?null:{source:t,binDir:n,nodePath:C,licensePath:N}}var HV,UV=__esmMin(()=>{Rd(),Pn(),nF(),HV=[`darwin-arm64`,`darwin-x64`,`win32-x64`]});function rfc822(t){let n=new Date(t*1e3),pad=t=>String(t).padStart(2,`0`);return`${WV[n.getUTCDay()]}, ${pad(n.getUTCDate())} ${GV[n.getUTCMonth()]} ${n.getUTCFullYear()} ${pad(n.getUTCHours())}:${pad(n.getUTCMinutes())}:${pad(n.getUTCSeconds())} +0000`}function changelogEntriesFor(t,n){let S=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),C=RegExp(`^##+[ \\t]+\\[?${S}\\]?[^\\n]*$`,`m`).exec(n);if(C===null)return[];let N=n.slice(C.index+C[0].length),F=/^##[ \t]+\[?\d/m.exec(N),I=F===null?N:N.slice(0,F.index),H=[];for(let t of I.split(`
1147
- `)){let n=/^[*-][ \t]+(.*\S)\s*$/.exec(t);n!==null&&H.push(n[1].replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\*\*([^*]+)\*\*/g,`$1`).replace(/\s+/g,` `).trim())}return H}function wrapEntry(t){let n=[],S=` *`;for(let C of t.split(/\s+/))C!==``&&(S.length+1+C.length>KV&&S!==` *`&&S!==` `&&(n.push(S),S=` `),S+=` ${C}`);return n.push(S),n}function renderDebianChangelog(t,n,S){let C=n===void 0?[]:changelogEntriesFor(t.version,n),N=t.homepage?`Release ${t.version}. See ${t.homepage} for the upstream changes.`:`Release ${t.version}.`,F=(C.length>0?C:[N]).flatMap(wrapEntry);return[`${t.binaryName} (${t.version}-${t.release}) unstable; urgency=medium`,``,...F,``,` -- ${t.maintainer} ${rfc822(S)}`,``].join(`
1148
- `)}var WV,GV,KV,qV=__esmMin(()=>{WV=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],GV=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],KV=80});function planStage(t,n){let S=[],C=`lib/${t.binaryName}`;S.push({path:`bin/${t.binaryName}`,mode:493,source:{kind:`text`,text:n.launcher}});for(let N of n.bundleFiles)S.push({path:pn.join(C,N),mode:isExecutableAsset(N)?493:420,source:{kind:`file`,path:pn.join(t.bundleDir,N)}});if(S.push({path:`${SB.metainfo}/${t.appId}.metainfo.xml`,mode:420,source:{kind:`text`,text:n.metainfo}}),t.kind===`app`){if(n.desktopEntry===void 0)throw Error('gjsify ship: internal error — a desktop entry is required for `kind: "app"`.');S.push({path:`${SB.applications}/${t.appId}.desktop`,mode:420,source:{kind:`text`,text:n.desktopEntry}});for(let n of planIcons(t))S.push(n)}for(let n of t.schemaFiles){let C=Dn(n);if(!C.startsWith(t.appId))throw Error(`gjsify ship: the GSettings schema ${C} must be named \`${t.appId}[.…].gschema.xml\`. Every installed schema shares one system directory, so the app id is what keeps it unique.`);S.push({path:`${SB.schemas}/${C}`,mode:420,source:{kind:`file`,path:n}})}for(let n of t.typelibFiles)S.push({path:pn.join(C,`gi`,Dn(n)),mode:493,source:{kind:`file`,path:n}});t.mimeTypes.length>0&&S.push({path:`${SB.mime}/${t.appId}.xml`,mode:420,source:{kind:`text`,text:renderMimePackage(t.mimeTypes)}});for(let n of t.localeFiles)S.push({path:pn.join(SB.locale,n.rel),mode:420,source:{kind:`file`,path:n.abs}});for(let n of planFonts(t))S.push(n);for(let[n,C]of Object.entries(t.extraFiles))S.push({path:assertInsidePrefix(n),mode:420,source:{kind:`file`,path:C}});return normalise(S)}function planFonts(t){let n=[],S=new Map;for(let C of t.fontFiles){let N=`${SB.fonts}/${t.appId}/${Dn(C)}`,F=S.get(N);if(F!==void 0)throw Error(`gjsify ship: ${C} and ${F} both install as ${N}. Two faces cannot share one filename — one would silently not ship, and a missing face is a substituted typeface rather than an error. Rename one, or point \`gjsify.ship.fonts\` at a directory holding only the faces you mean to ship.`);S.set(N,C),n.push({path:N,mode:420,source:{kind:`file`,path:C}})}return n}async function planOverlay(t,n,S){if(S.licenseText===void 0)throw Error(`gjsify ship: no licence file found, so the ${n.id} package would ship no ${n.licenseDest(t.binaryName)}. Debian Policy § 12.5 requires it and lintian errors without it, and neither dpkg nor rpm will tell you it is missing. Add a LICENSE file to ${t.projectDir} or to the root of its repository, or point \`gjsify.ship.licenseFile\` at the one this package ships under.`);let C=n.licenseKind===`debian-copyright`?renderDebianCopyright(t,S.licenseText):S.licenseText,N=[{path:n.licenseDest(t.binaryName),mode:420,source:{kind:`text`,text:C}}];if(n.changelogDest!==void 0){let C=renderDebianChangelog(t,S.changelogText,S.mtime);N.push({path:n.changelogDest(t.binaryName),mode:420,source:{kind:`bytes`,data:await gzipDeterministic(new TextEncoder().encode(C),9)}})}let F=t.formatFiles[n.id];for(let n of F?.typelibFiles??[])N.push({path:pn.join(`lib`,t.binaryName,`gi`,Dn(n)),mode:493,source:{kind:`bytes`,data:new Uint8Array(await readFile$1(n))}});for(let[t,n]of Object.entries(F?.extraFiles??{}))N.push({path:assertInsidePrefix(t),mode:t.endsWith(`.so`)?493:420,source:{kind:`bytes`,data:new Uint8Array(await readFile$1(n))}});return N}function assertOverlayIsLicensed(t,n,S){if(!(S.length>0))throw Error(`gjsify ship: this stage carries no ${t} licence overlay, so the package would ship no licence file for ${n} — Debian Policy § 12.5 requires one and lintian errors without it. The fix is on the assembling host, not this one: give that project a LICENSE (or set \`gjsify.ship.licenseFile\`) and re-run the \`--stage\` phase.`)}function renderDebianCopyright(t,n){let S=n.trimEnd().split(`
1146
+ A misplaced catalogue installs and then shows nothing, which reads exactly like having no translation at all. Lay them out as <lang>/LC_MESSAGES/<domain>.mo.`);if(C.length===0)throw Error(`gjsify ship: \`gjsify.ship.localeDir\` (${n}) contains no \`.mo\` catalogue. Declaring a locale directory that ships nothing is a promise the package does not keep.`);return C}function withoutForeignEntries(t,n,S,C,N){if(C.length===0)return t;let F=new Set;for(let t of C){let C=Cn(t)?t:xn(S,t);if(C===N)continue;let I=Tn(n,C);I===``||I.startsWith(`..`)||Cn(I)||F.add(I.split(jn).join(pn.sep))}return t.filter(t=>!F.has(t))}function resolveBundle(t){let n=t.declaredBundle;if(n===void 0)throw Error("gjsify ship: no bundle to ship. Set `gjsify.main` (or `main`) in package.json to the built bundle, or `gjsify.ship.bundle` to override it.");let S=Cn(n)?n:xn(t.projectDir,n);if(!existsSync(S))throw Error(`gjsify ship: the bundle ${n} does not exist. Build it first (\`gjsify run build\`), or drop \`--skip-build\`.`);return S}function discoverIcons(t,n){if(n!==void 0){let S=xn(t,n);if(!existsSync(S))throw Error(`gjsify ship: the configured icon path ${n} does not exist.`);return statSync(S).isDirectory()?listIcons(S):[S]}for(let n of[`data/icons`,`data/icons/hicolor`]){let S=wn(t,n);if(existsSync(S)&&statSync(S).isDirectory()){let t=listIcons(S);if(t.length>0)return t}}return[]}function listIcons(t){return listFilesRecursive(t).filter(t=>UV.some(n=>t.toLowerCase().endsWith(n))).map(n=>wn(t,n.split(`/`).join(jn))).sort()}function discoverFonts(t,n){let S=n??`data/fonts`,C=n===void 0?wn(t,`data`,`fonts`):xn(t,n);if(!existsSync(C)){if(n===void 0)return[];throw Error(`gjsify ship: the configured font path ${n} does not exist.`)}if(!statSync(C).isDirectory()){if(assertNotWebFont(C,S),!WV.some(t=>C.toLowerCase().endsWith(t)))throw Error(`gjsify ship: \`gjsify.ship.fonts\` names ${n}, which is not a font face fontconfig will open (${WV.join(`, `)}). A file it cannot read installs and is never found, and Pango substitutes a fallback family rather than reporting anything.`);return[C]}let N=[];for(let t of listFilesRecursive(C))assertNotWebFont(t,S),WV.some(n=>t.toLowerCase().endsWith(n))&&N.push(wn(C,t.split(`/`).join(jn)));if(N.length===0&&n!==void 0)throw Error(`gjsify ship: \`gjsify.ship.fonts\` (${n}) holds no font face (${WV.join(`, `)}). Declaring fonts that ship nothing is a promise the package does not keep — and its symptom is a substituted family, not an error.`);return N.sort()}function assertNotWebFont(t,n){let S=t.toLowerCase(),C=GV.find(t=>S.endsWith(t));if(C!==void 0)throw Error(`gjsify ship: \`gjsify.ship.fonts\` (${n}) carries ${t}, and \`${C}\` is a web-font wrapper whose support is a FreeType BUILD option — brotli for woff2, zlib for woff. Whether it opens is therefore a property of the FreeType the SHIPPED artifact loads (inside \`@gjsify/gtk-runtime-<target>\` for a \`.app\` or a Windows program directory), not of the machine that packaged it. Ship the desktop face instead (${WV.join(`, `)}); a font that fails to open is not an error, it is Pango quietly substituting a different typeface.`)}function discoverSchemas(t,n){let S=n===void 0?[wn(t,`data`)]:[xn(t,n)];for(let t of S){if(!existsSync(t)){if(n!==void 0)throw Error(`gjsify ship: the configured schema path ${n} does not exist.`);continue}if(!statSync(t).isDirectory())return[t];let S=listFilesRecursive(t).filter(t=>t.endsWith(`.gschema.xml`)).map(n=>wn(t,n.split(`/`).join(jn))).sort();if(S.length>0)return S}return[]}function discoverLicense(t,n){if(n!==void 0){let S=xn(t,n);if(!existsSync(S))throw Error(`gjsify ship: the configured licence file ${n} does not exist.`);return S}for(let n of licenseSearchDirs(t))for(let t of BV){let S=wn(n,t);if(existsSync(S))return S}}function discoverChangelog(t,n){if(n!==void 0){let S=xn(t,n);if(!existsSync(S))throw Error(`gjsify ship: the configured changelog file ${n} does not exist.`);return S}for(let n of licenseSearchDirs(t))for(let t of VV){let S=wn(n,t);if(existsSync(S))return S}}function licenseSearchDirs(t){let n=[];for(let S=t;;){if(n.push(S),isProjectRoot(S))return n;let C=En(S);if(C===S)return[t];S=C}}function isProjectRoot(t){if(existsSync(wn(t,`.git`)))return!0;let n=wn(t,`package.json`);if(!existsSync(n))return!1;try{return JSON.parse(readFileSync(n,`utf-8`)).workspaces!==void 0}catch{return!1}}function listFilesRecursive(t){let n=[],walk=S=>{for(let C of readdirSync(S,{withFileTypes:!0}).sort((t,n)=>t.name<n.name?-1:1)){let N=wn(S,C.name);if(C.isDirectory())walk(N);else if(C.isSymbolicLink())throw Error(`gjsify ship: ${N} is a symlink. The payload has to be self-contained — replace it with the file it points at, or exclude it from the bundle directory.`);else C.isFile()&&n.push(pn.join(...Tn(t,N).split(jn)))}};return walk(t),n.sort()}var UV,WV,GV,KV=__esmMin(()=>{Rd(),Pn(),HV(),UV=[`.svg`,`.png`],WV=[`.ttf`,`.otf`,`.ttc`,`.otc`],GV=[`.woff`,`.woff2`,`.eot`]});function isNodeRuntimeTarget(t){return qV.includes(t)}function nodeRuntimePackageName(t){return`@gjsify/node-runtime-${t}`}function nodeRuntimeBinaryName(t){return t.startsWith(`win32-`)?`node.exe`:`node`}function resolveNodeRuntime(t,n={}){let S=n.env??process.env,C=nodeRuntimeBinaryName(t),N=S.GJSIFY_NODE_RUNTIME;if(N){let t=complete(`GJSIFY_NODE_RUNTIME`,N,C);if(t)return t}let F=nodeRuntimePackageName(t),I=resolveInstalledPackage(F,{cwd:n.cwd,bundleUrl:import.meta.url});return I===null?null:complete(F,wn(En(I),`bin`),C)}function complete(t,n,S){let C=wn(n,S),N=wn(n,`LICENSE`);return!existsSync(C)||!existsSync(N)?null:{source:t,binDir:n,nodePath:C,licensePath:N}}var qV,JV=__esmMin(()=>{Rd(),Pn(),nF(),qV=[`darwin-arm64`,`darwin-x64`,`win32-x64`]});function rfc822(t){let n=new Date(t*1e3),pad=t=>String(t).padStart(2,`0`);return`${YV[n.getUTCDay()]}, ${pad(n.getUTCDate())} ${XV[n.getUTCMonth()]} ${n.getUTCFullYear()} ${pad(n.getUTCHours())}:${pad(n.getUTCMinutes())}:${pad(n.getUTCSeconds())} +0000`}function changelogEntriesFor(t,n){let S=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),C=RegExp(`^##+[ \\t]+\\[?${S}\\]?[^\\n]*$`,`m`).exec(n);if(C===null)return[];let N=n.slice(C.index+C[0].length),F=/^##[ \t]+\[?\d/m.exec(N),I=F===null?N:N.slice(0,F.index),H=[];for(let t of I.split(`
1147
+ `)){let n=/^[*-][ \t]+(.*\S)\s*$/.exec(t);n!==null&&H.push(n[1].replace(/\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\*\*([^*]+)\*\*/g,`$1`).replace(/\s+/g,` `).trim())}return H}function wrapEntry(t){let n=[],S=` *`;for(let C of t.split(/\s+/))C!==``&&(S.length+1+C.length>ZV&&S!==` *`&&S!==` `&&(n.push(S),S=` `),S+=` ${C}`);return n.push(S),n}function renderDebianChangelog(t,n,S){let C=n===void 0?[]:changelogEntriesFor(t.version,n),N=t.homepage?`Release ${t.version}. See ${t.homepage} for the upstream changes.`:`Release ${t.version}.`,F=(C.length>0?C:[N]).flatMap(wrapEntry);return[`${t.binaryName} (${t.version}-${t.release}) unstable; urgency=medium`,``,...F,``,` -- ${t.maintainer} ${rfc822(S)}`,``].join(`
1148
+ `)}var YV,XV,ZV,QV=__esmMin(()=>{YV=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],XV=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ZV=80});function planStage(t,n){let S=[],C=`lib/${t.binaryName}`;S.push({path:`bin/${t.binaryName}`,mode:493,source:{kind:`text`,text:n.launcher}});for(let N of n.bundleFiles)S.push({path:pn.join(C,N),mode:isExecutableAsset(N)?493:420,source:{kind:`file`,path:pn.join(t.bundleDir,N)}});if(S.push({path:`${DB.metainfo}/${t.appId}.metainfo.xml`,mode:420,source:{kind:`text`,text:n.metainfo}}),t.kind===`app`){if(n.desktopEntry===void 0)throw Error('gjsify ship: internal error — a desktop entry is required for `kind: "app"`.');S.push({path:`${DB.applications}/${t.appId}.desktop`,mode:420,source:{kind:`text`,text:n.desktopEntry}});for(let n of planIcons(t))S.push(n)}for(let n of t.schemaFiles){let C=Dn(n);if(!C.startsWith(t.appId))throw Error(`gjsify ship: the GSettings schema ${C} must be named \`${t.appId}[.…].gschema.xml\`. Every installed schema shares one system directory, so the app id is what keeps it unique.`);S.push({path:`${DB.schemas}/${C}`,mode:420,source:{kind:`file`,path:n}})}for(let n of t.typelibFiles)S.push({path:pn.join(C,`gi`,Dn(n)),mode:493,source:{kind:`file`,path:n}});t.mimeTypes.length>0&&S.push({path:`${DB.mime}/${t.appId}.xml`,mode:420,source:{kind:`text`,text:renderMimePackage(t.mimeTypes)}});for(let n of t.localeFiles)S.push({path:pn.join(DB.locale,n.rel),mode:420,source:{kind:`file`,path:n.abs}});for(let n of planFonts(t))S.push(n);for(let[n,C]of Object.entries(t.extraFiles))S.push({path:assertInsidePrefix(n),mode:420,source:{kind:`file`,path:C}});return normalise(S)}function planFonts(t){let n=[],S=new Map;for(let C of t.fontFiles){let N=`${DB.fonts}/${t.appId}/${Dn(C)}`,F=S.get(N);if(F!==void 0)throw Error(`gjsify ship: ${C} and ${F} both install as ${N}. Two faces cannot share one filename — one would silently not ship, and a missing face is a substituted typeface rather than an error. Rename one, or point \`gjsify.ship.fonts\` at a directory holding only the faces you mean to ship.`);S.set(N,C),n.push({path:N,mode:420,source:{kind:`file`,path:C}})}return n}async function planOverlay(t,n,S){if(S.licenseText===void 0)throw Error(`gjsify ship: no licence file found, so the ${n.id} package would ship no ${n.licenseDest(t.binaryName)}. Debian Policy § 12.5 requires it and lintian errors without it, and neither dpkg nor rpm will tell you it is missing. Add a LICENSE file to ${t.projectDir} or to the root of its repository, or point \`gjsify.ship.licenseFile\` at the one this package ships under.`);let C=n.licenseKind===`debian-copyright`?renderDebianCopyright(t,S.licenseText):S.licenseText,N=[{path:n.licenseDest(t.binaryName),mode:420,source:{kind:`text`,text:C}}];if(n.changelogDest!==void 0){let C=renderDebianChangelog(t,S.changelogText,S.mtime);N.push({path:n.changelogDest(t.binaryName),mode:420,source:{kind:`bytes`,data:await gzipDeterministic(new TextEncoder().encode(C),9)}})}let F=t.formatFiles[n.id];for(let n of F?.typelibFiles??[])N.push({path:pn.join(`lib`,t.binaryName,`gi`,Dn(n)),mode:493,source:{kind:`bytes`,data:new Uint8Array(await readFile$1(n))}});for(let[t,n]of Object.entries(F?.extraFiles??{}))N.push({path:assertInsidePrefix(t),mode:t.endsWith(`.so`)?493:420,source:{kind:`bytes`,data:new Uint8Array(await readFile$1(n))}});return N}function assertOverlayIsLicensed(t,n,S){if(!(S.length>0))throw Error(`gjsify ship: this stage carries no ${t} licence overlay, so the package would ship no licence file for ${n} — Debian Policy § 12.5 requires one and lintian errors without it. The fix is on the assembling host, not this one: give that project a LICENSE (or set \`gjsify.ship.licenseFile\`) and re-run the \`--stage\` phase.`)}function renderDebianCopyright(t,n){let S=n.trimEnd().split(`
1149
1149
  `).map(t=>t.trim()===``?` .`:` ${t}`).join(`
1150
1150
  `);return[`Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/`,`Upstream-Name: ${t.name}`,...t.homepage?[`Source: ${t.homepage}`]:[],``,`Files: *`,`Copyright: ${t.maintainer}`,`License: ${t.license}`,S,``].join(`
1151
- `)}function planIcons(t){let n=[],S=new Map;for(let C of t.iconFiles){let N=On(C),F=iconThemeDir(C),I=isSymbolicIcon(C)?`${t.appId}-symbolic`:t.appId,H=`${SB.icons}/${F}/apps/${I}${N}`,W=S.get(H);if(W!==void 0)throw Error(`gjsify ship: ${C} and ${W} both install as ${H}. An icon is keyed on its context and its size: \`symbolic\` is read from a \`symbolic/\` path component or a \`-symbolic\` filename, the size from the path (\`.../128x128/...\`) or the filename (\`icon-128.png\`). Give them distinguishable sizes, or point \`gjsify.ship.icon\` at a single file.`);S.set(H,C),n.push({path:H,mode:420,source:{kind:`file`,path:C}})}return n}function assertInsidePrefix(t){let n=pn.normalize(t);if(pn.isAbsolute(n)||n===`..`||n.startsWith(`../`))throw Error(`gjsify ship: \`gjsify.ship.extraFiles\` destination "${t}" escapes the install prefix. Destinations are relative to the prefix, e.g. \`share/applications/extra.desktop\`.`);return n}function isExecutableAsset(t){return/\.(so|node|dylib)(\.\d+)*$/.test(t)}function normalise(t){let n=new Map;for(let S of t)n.set(S.path,S);return[...n.values()].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}var JV=__esmMin(()=>{qV(),xB(),kB(),kV(),CB(),xd(),Pn()});function isGtkRuntimeTarget(t){return YV.includes(t)}function gtkRuntimePackageName(t){return`@gjsify/gtk-runtime-${t}`}function resolveGtkRuntime(t,n={}){let S=n.env??process.env,C=t.startsWith(`win32-`)?`bin`:`lib`,N=[],F=S.GJSIFY_GTK_RUNTIME;F&&N.push({source:`GJSIFY_GTK_RUNTIME`,dir:F});let I=resolveNodeGiRoot(n);I!==null&&(N.push({source:`${ZV}/prebuilds/${t}`,dir:wn(I,`prebuilds`,t,`gtk`)}),N.push({source:`${ZV} sibling`,dir:wn(I,`..`,`gtk-runtime-${t}`,`gtk`)}));let H=gtkRuntimePackageName(t),W=resolveStagedPackage(H,n);W!==null&&N.push({source:H,dir:wn(En(W),`gtk`)});for(let t of N){let n=wn(t.dir,C),S=wn(t.dir,`girepository-1.0`);if(!(!existsSync(n)||!existsSync(S)))return{source:t.source,dir:t.dir,libDir:n,typelibDir:S}}return null}function resolveNodeGiAddon(t,n={}){let S=resolveNodeGiRoot(n);if(S===null)return null;let C=wn(S,`prebuilds`,t,XV);return existsSync(C)?{source:ZV,addonPath:C}:null}function resolveNodeGiRoot(t){let n=resolveStagedPackage(ZV,t);return n===null?null:En(n)}function resolveStagedPackage(t,n){let S={bundleUrl:import.meta.url};return n.cwd!==void 0&&(S.cwd=n.cwd),n.resolve!==void 0&&(S.resolve=n.resolve),resolveInstalledPackage(t,S)}function resolveNodeGiPackage(t={}){let n=resolveNodeGiRoot(t);if(n===null)return null;let S=[`package.json`];for(let t of readdirSync(n,{withFileTypes:!0}).sort((t,n)=>t.name<n.name?-1:1))t.isFile()&&t.name.endsWith(`.js`)&&S.push(t.name);let C=wn(n,`overrides`);if(existsSync(C))for(let t of listFilesRecursive(C))S.push(pn.join(`overrides`,t));return S.length>1?{source:ZV,root:n,files:S.sort()}:null}function appRuntimePaths(t,n,S){let C=t.dirs(n),N=pn.join(C.native,`node-gi`),F=pn.join(N,`prebuilds`,S);return{nodeGiRoot:N,nodeGiPackageDir:pn.join(C.bundle,`node_modules`,ZV),prebuildDir:F,gtkDir:pn.join(F,`gtk`),addonPath:pn.join(F,XV),interpreterPath:pn.join(C.launcher,nodeRuntimeBinaryName(S)),interpreterLicensePath:pn.join(C.data,`licenses`,`node`,`LICENSE`)}}function stageAppRuntime(t){let n=appRuntimePaths(t.layout,t.identity,t.target),S=[],C={},N=[],F=[];t.interpreter===null?F.push(`no bundled interpreter — install \`@gjsify/node-runtime-${t.target}\` (or point \`GJSIFY_NODE_RUNTIME\` at a \`bin/\` directory holding \`node\` and its \`LICENSE\`)`):(S.push({path:n.interpreterPath,mode:493,source:{kind:`file`,path:t.interpreter.nodePath}}),S.push({path:n.interpreterLicensePath,mode:420,source:{kind:`file`,path:t.interpreter.licensePath}}),C.interpreter=n.interpreterPath,N.push(`interpreter from ${t.interpreter.source}`));let I=resolveGtkRuntime(t.target,discoveryOptions(t));if(I!==null){for(let t of listFilesRecursive(I.dir)){let C=wn(I.dir,t.split(`/`).join(jn));S.push({path:pn.join(n.gtkDir,t),mode:stagedMode(t,C),source:{kind:`file`,path:C}})}C.gtkRuntimeDir=n.gtkDir,N.push(`GTK closure from ${I.source}`)}else{let n=t.target.startsWith(`win32-`)?`bin`:`lib`;F.push(`no GTK closure — install \`${gtkRuntimePackageName(t.target)}\` (or point \`GJSIFY_GTK_RUNTIME\` at a bundle directory holding \`${n}/\` and \`girepository-1.0/\`)`)}let H=resolveNodeGiPackage(discoveryOptions(t));if(H!==null){for(let t of H.files)S.push({path:pn.join(n.nodeGiPackageDir,t),mode:420,source:{kind:`file`,path:wn(H.root,t.split(`/`).join(jn))}});N.push(`node-gi runtime (${H.files.length} file(s)) from ${H.source}`)}else F.push(`no node-gi JavaScript — install \`${ZV}\`; a \`--app node\` bundle keeps \`@gjsify/node-gi/*\` external, so the staged bundle would \`require\` a package the artifact does not carry`);let W=resolveNodeGiAddon(t.target,discoveryOptions(t));return W===null?F.push(`no node-gi addon — install \`${ZV}\`, whose \`prebuilds/${t.target}/${XV}\` is the binary built against that closure`):(S.push({path:n.addonPath,mode:493,source:{kind:`file`,path:W.addonPath}}),C.nodeGiAddon=n.addonPath,N.push(`node-gi addon from ${W.source}`)),{files:S,launcher:C,found:N,missing:F}}function discoveryOptions(t){let n={};return t.cwd!==void 0&&(n.cwd=t.cwd),t.env!==void 0&&(n.env=t.env),t.resolve!==void 0&&(n.resolve=t.resolve),n}function stagedMode(t,n){if(isExecutableAsset(t)||t.startsWith(`libexec/`)||t.startsWith(`bin/`))return 493;try{if(statSync(n).mode&73)return 493}catch{}return 420}var YV,XV,ZV,QV=__esmMin(()=>{Rd(),Pn(),VV(),UV(),JV(),nF(),YV=[`darwin-arm64`,`darwin-x64`,`win32-x64`],XV=`node_gi.node`,ZV=`@gjsify/node-gi`});function appDirFor(t){return wn(t,`appimage`,rH)}function appImageHostRequirements(t){let n=interpreterFloor(t),S=new Set(t.optionalNamespaces??[]);return[`${t.app} (>= ${n})`,...hostProvidedNamespaces(t.namespaces,t.bundledTypelibs).map(t=>S.has(t)?`the ${t} typelib (optional)`:`the ${t} typelib`)]}function interpreterFloor(t){return t.app===`node`?t.minNodeVersion??`24`:t.minGjsVersion??`1.86`}function renderAppRun(t,n){let S=sV.linux.dirs(t).launcher,C=interpreterFloor(t),[N=`0`,F=`0`]=C.split(`.`);return[`#!/bin/sh`,"# Generated by `gjsify ship` — do not edit.",`set -e`,`here=$(dirname "$(readlink -f "$0")")`,`if ! command -v ${t.app} >/dev/null 2>&1; then`,` echo "${shellSafe(t.name)} needs ${t.app}, and this system has none." >&2`,` echo "This AppImage carries the application, not its runtime. It needs:" >&2`,...n.map(t=>` echo " - ${shellSafe(t)}" >&2`),` exit 127`,`fi`,`found=$(${t.app} --version 2>/dev/null | sed -n 's/[^0-9]*\\([0-9][0-9]*\\)\\.\\([0-9][0-9]*\\).*/\\1 \\2/p' | head -n 1 || true)`,"major=${found% *}","minor=${found#* }",`if [ -n "$major" ]; then`,` if [ "$major" -lt ${N} ] || { [ "$major" -eq ${N} ] && [ "$minor" -lt ${F} ]; }; then`,` echo "${shellSafe(t.name)} needs ${t.app} ${C} or newer, and this system has $major.$minor." >&2`,` echo "This AppImage carries the application, not its runtime. It needs:" >&2`,...n.map(t=>` echo " - ${shellSafe(t)}" >&2`),` exit 126`,` fi`,`fi`,`exec "$here/usr/${S}/${t.binaryName}" "$@"`,``].join(`
1152
- `)}function shellSafe(t){return t.replace(/(["$`\\])/g,`\\$1`)}function findPinnedRuntime(t,n=process.env,S=existsSync){let C=n.GJSIFY_APPIMAGE_RUNTIME_DIR||`/usr/local/share/gjsify/appimage-runtime`,N=pn.join(C,`runtime-${t}`);return S(N)?N:void 0}function appImageRuntimeNotice(t,n){return n===void 0?`NO pinned AppImage runtime for ${t}: appimagetool will fetch runtime-${t} from type2-runtime's rolling \`continuous\` tag, so this pack NEEDS A NETWORK and the ~940 KB of runtime it embeds carries no digest from this tree. Pin one at ${nH}/runtime-${t} (or point ${tH} at a directory holding it).`:`the AppImage runtime is pinned: ${n} — this pack needs no network`}function selectAppDirIcon(t,n){let S;for(let C of t){let t=rootIconRank(C.path,n);t!==void 0&&(S===void 0||t>S.rank)&&(S={entry:C,rank:t})}return S?.entry}function rootIconRank(t,n){if(oH.find(S=>t.endsWith(`${n}${S}`))===void 0||!t.startsWith(`${SB.icons}/`)||t.includes(`/symbolic/`))return;if(t.includes(`/scalable/`))return 2**53-1;let S=/\/(\d+)x\1\//.exec(t);return S===null?1:Number(S[1])}function assertAppImageIsPackable(t,n,S){let C=`${SB.applications}/${n.appId}.desktop`;if(!t.some(t=>t.path===C))throw Error(`gjsify ship: an AppImage needs a desktop entry and this payload has no ${C}. appimagetool refuses an AppDir without one, and the AppImage runtime has nothing to tell a desktop about the application it just mounted. A \`kind: "cli"\` project stages no entry by design — set \`gjsify.ship.kind\` to "app" if this is a GUI application, or ship it as a \`.deb\`, an \`.rpm\` or a Flatpak, none of which need one.`);if(selectAppDirIcon(t,n.appId)===void 0)throw Error(`gjsify ship: an AppImage needs an icon called ${n.appId} beside its desktop entry, and this payload stages none under ${SB.icons}/. The entry's \`Icon=\` names the app id, so a file keeping its own basename is an icon nothing looks up — point \`gjsify.ship.icon\` at a PNG or an SVG and it is renamed into the theme for you.`);if(S===void 0&&t.some(t=>isSchemaSource(t.path)))throw Error(`gjsify ship: this payload stages GSettings schema sources under ${SB.schemas}/ and no ${mV} was compiled for it. An AppImage has NO INSTALL STEP — that is the whole point of the format — so the \`.deb\`/\`.rpm\` postinst that compiles the system schema directory never runs, and GSettings aborts on a directory holding only sources. The AppDir must carry ${mV}; \`compileSchemasForPayload\` produces it from this payload.`)}function appDirPayload(t,n,S,C){assertAppImageIsPackable(n,t,C);let N=selectAppDirIcon(n,t.appId),F=`${SB.applications}/${t.appId}.desktop`,I=n.find(t=>t.path===F);return[...[...n,...C===void 0?[]:[C]].map(t=>({...t,path:`usr/${t.path}`})),{path:iH,mode:493,data:encodeUtf8(renderAppRun(t,S))},{path:`${t.appId}.desktop`,mode:420,data:I.data},{path:N.path.slice(N.path.lastIndexOf(`/`)+1),mode:420,data:N.data},{path:aH,mode:420,data:N.data}]}function appImageToolArgs(t){return[`--no-appstream`,`--comp`,`zstd`,...t.runtimeFile===void 0?[]:[`--runtime-file`,t.runtimeFile],t.appDir,t.target]}function appImageToolEnv(t){return{ARCH:t,[eH]:`1`}}function appImageToolFailureMessage(t,n){let S=n===void 0?`the AppImage RUNTIME could not be downloaded — ${$V} fetches it from github.com/AppImage/type2-runtime when no runtime is pinned, so this pack needs a network and an offline host fails here having written nothing; or `:`the pinned runtime at ${n} is not an AppImage runtime — it is passed through to \`--runtime-file\` unread, so a truncated or wrong-architecture file fails here; or `;return`gjsify ship: ${$V} failed with ${t}. Four causes, measured in this order: ${S}\`file\` is not installed — ${$V} requires file(1) and says so, even though this pack already tells it the architecture; or FUSE is unavailable and the tool on PATH is a wrapper that dropped ${eH}=1, which this pack sets so the extract path is taken instead of a mount; or the work directory is full — the AppDir is copied into a squashfs image beside it.`}async function buildAppImage(t){let n=appImageToolArgs(t),S=appImageToolEnv(t.archLabel);t.verbose&&ge.log(`[gjsify ship] ${Object.entries(S).map(([t,n])=>`${t}=${n}`).join(` `)} ${$V} ${n.join(` `)}`);let C=await spawnToCompletion($V,n,{completion:`return`,cwd:t.workDir,stdio:`inherit`,env:{...process.env,...S},notFound:()=>Error(`gjsify ship: ${$V} is not on PATH. Unlike flatpak-builder and msitools it is not packaged by Fedora or Debian: take the release from https://github.com/AppImage/appimagetool/releases, \`chmod +x\` it and put it on PATH as \`${$V}\`. \`gjsify ship linux --stage\` needs none of this — the payload is assembled by this CLI and only the container needs the tool.`)});if(C.code!==0)throw Error(appImageToolFailureMessage(describeExit(C),t.runtimeFile));if(!existsSync(t.target))throw Error(`gjsify ship: ${$V} exited 0 and wrote no file at ${t.target}. An exit code is not an artifact — re-run with \`--verbose\` to see what it was told.`)}function appDirPaths(t){let n=new Set;for(let S of t){let t=S.path.split(`/`);for(let S=1;S<t.length;S++)n.add(t.slice(0,S).join(`/`))}return[...[...n].sort(),...t.map(t=>t.path)]}function stampAppDirTimes(t,n,S){for(let C of appDirPaths(n))utimesSync(wn(t,C.split(`/`).join(jn)),S,S);utimesSync(t,S,S)}var $V,eH,tH,nH,rH,iH,aH,oH,sH=__esmMin(()=>{_e(),Rd(),Pn(),V_(),cB(),bB(),uV(),hV(),CB(),$V=`appimagetool`,eH=`APPIMAGE_EXTRACT_AND_RUN`,tH=`GJSIFY_APPIMAGE_RUNTIME_DIR`,nH=`/usr/local/share/gjsify/appimage-runtime`,rH=`AppDir`,iH=`AppRun`,aH=`.DirIcon`,oH=[`.png`,`.svg`]});function dmgVolumeName(t){let n=t.name;if(n.trim()===``)throw Error("gjsify ship: the macOS image has no name to call its volume — `gjsify.ship.name` (or the package name it is derived from) is empty. `hdiutil` would accept that and mount the image as `untitled`, which is the name every nameless disk image on the machine has.");if(lH.test(n))throw Error(`gjsify ship: the macOS image would mount a volume called "${n}", and HFS+ cannot hold it: the Finder shows a stored ":" as a "/" and a stored "/" as a ":", so the volume would not be the one this project named. Set \`gjsify.ship.name\` to the display name you want.`);return n}function hdiutilCreateArgs(t){return[`create`,`-format`,`UDZO`,`-fs`,`HFS+J`,`-volname`,t.volumeName,`-srcfolder`,t.sourceDir,`-ov`,`-quiet`,t.target]}async function buildDmgImage(t){let n=hdiutilCreateArgs(t);t.verbose&&ge.log(`[gjsify ship] ${cH} ${n.join(` `)}`);let S=await spawnToCompletion(cH,n,{completion:`return`,cwd:t.workDir,stdio:`inherit`,notFound:()=>Error(`gjsify ship: ${cH} is not on PATH. It ships with macOS and cannot be installed anywhere else, so this is either a broken macOS installation or a host that is not macOS at all. A \`.dmg\` is packed on darwin (ADR 0024 § A1); from anywhere else the route is \`gjsify ship darwin --stage\` here and \`gjsify ship --from-stage <dir> --target macos-app-dmg\` there.`)});if(S.code!==0)throw Error(`gjsify ship: ${cH} failed with ${describeExit(S)}.`)}function dmgVolumeDir(t){return wn(t,`dmg`,`volume`)}var cH,lH,uH=__esmMin(()=>{_e(),Pn(),V_(),cH=`hdiutil`,lH=/[/:]/});function renderShipFlatpakManifest(t){let{settings:n,stageDir:S,overlayDir:C}=t,N=n.flatpak,F={id:n.appId,runtime:N.runtime,"runtime-version":N.runtimeVersion,sdk:N.sdk,branch:N.branch,command:n.binaryName,"finish-args":N.finishArgs};return N.sdkExtensions.length>0&&(F[`sdk-extensions`]=N.sdkExtensions),N.appendPath.length>0&&(F[`build-options`]={"append-path":N.appendPath.join(`:`)}),N.cleanup.length>0&&(F.cleanup=N.cleanup),F.modules=[{name:n.binaryName,buildsystem:`simple`,"build-commands":[`mkdir -p /app`,`cp -a stage/. /app/`,`cp -a overlay/. /app/`],sources:[{type:`dir`,path:S,dest:`stage`,skip:[t.stageManifestFile]},{type:`dir`,path:C,dest:`overlay`}]}],F}async function buildFlatpakBundle(t){let{settings:n,workDir:S,archLabel:C}=t,N=wn(S,`${n.appId}.json`),F=wn(S,`build`),I=wn(S,`repo`),H=wn(S,`state`);mkdirSync(S,{recursive:!0}),rmSync(I,{recursive:!0,force:!0,maxRetries:5}),writeFileSync(N,`${JSON.stringify(renderShipFlatpakManifest(t),null,2)}\n`),await run$1(`flatpak-builder`,[`--force-clean`,`--disable-rofiles-fuse`,`--delete-build-dirs`,`--state-dir=${H}`,`--arch=${C}`,`--repo=${I}`,F,N],t,"flatpak-builder not found. Install it (Fedora: `sudo dnf install flatpak-builder`)."),await run$1(`flatpak`,[`build-bundle`,`--arch=${C}`,I,t.target,n.appId,n.flatpak.branch],t,`flatpak not found. Install it via your distro: see https://flathub.org/setup.`)}async function run$1(t,n,S,C){S.verbose&&ge.log(`[gjsify ship] ${t} ${n.join(` `)}`);let N=await spawnToCompletion(t,n,{completion:`return`,cwd:S.workDir,stdio:`inherit`,notFound:()=>Error(`gjsify ship: ${C}`)});if(N.code!==0)throw Error(`gjsify ship: ${t} failed with ${describeExit(N)}.`)}var dH=__esmMin(()=>{_e(),Rd(),Pn(),V_(),__name$1(run$1,`run`)});function localeOf(t){return t.split(`/`)[0]??``}function fold(t,n,S,C,N){let F=wn(N,`source${S}`);return writeFileSync(F,n),readFileSync(mergeCatalogues({mode:t,template:F,extension:S,catalogues:C,workDir:N}),`utf-8`)}function localizeMetadata(t,n){if(n.length===0)return t;let S=mkdtempSync(wn(tmpdir(),`gjsify-ship-l10n-`));try{let C=[...n].sort((t,n)=>t.rel<n.rel?-1:+(t.rel>n.rel)),N=new Map;for(let[t,n]of C.entries()){let C=wn(S,`${t}.po`);execFileSync(`msgunfmt`,[n.abs,`--output-file`,C],{stdio:`pipe`});let F=localeOf(n.rel);N.set(F,[...N.get(F)??[],C])}let F=[...N].map(([t,n])=>({locale:t,po:n.length===1?n[0]:msgcat(n,wn(S,`${t}.merged.po`))}));return{metainfo:fold(`--xml`,t.metainfo,`.metainfo.xml`,F,S),desktopEntry:t.desktopEntry===void 0?void 0:fold(`--desktop`,t.desktopEntry,`.desktop`,F,S)}}catch(t){throw Error(describeFailure(t,n.length))}finally{rmSync(S,{recursive:!0,force:!0})}}function msgcat(t,n){return execFileSync(`msgcat`,[`--use-first`,`--output-file`,n,...t],{stdio:`pipe`}),n}function describeFailure(t,n){let S=t;return S?.code===`ENOENT`?`gjsify ship: \`msgfmt\`/\`msgunfmt\`/\`msgcat\` are not on PATH, but the package stages ${n} gettext catalogue(s). Install them (package: gettext) — shipping the metadata untranslated would install an English app menu entry for a translated app, which nothing downstream can detect.`:`gjsify ship: could not fold the gettext catalogues into the freedesktop metadata.${S?.stderr===void 0?``:`\n${String(S.stderr).trim()}`}`}var fH=__esmMin(()=>{P_(),Rd(),Lg(),Pn(),sz()});function lookupArch(t,n,S){let C=t[n];if(!C)throw Error(`gjsify ship: no ${S} architecture is known for \`process.arch\` "${n}". Known: ${Object.keys(t).join(`, `)}.`);return C}function debArch(t,n){return n?`all`:lookupArch(pH,t,`Debian`)}function rpmArch(t,n){return n?`noarch`:lookupArch(mH,t,`RPM`)}function flatpakArch(t,n){return lookupArch(hH,t,`Flatpak`)}function appImageArch(t,n){return lookupArch(gH,t,`AppImage`)}function macosArch(t,n){return lookupArch(_H,t,`macOS`)}function windowsArch(t,n){return lookupArch(vH,t,`Windows`)}function windowsNameIsUnusable(t){return yH.test(t)||bH.test(t)||/[. ]$/.test(t)?!0:[...t].some(t=>(t.codePointAt(0)??0)<32)}function windowsProgramDirName(t){let n=t.name;if(n.trim()===``)throw Error("gjsify ship: the windows layout has no name to call the program directory — `gjsify.ship.name` (or the package name it is derived from) is empty. The artifact IS a directory and its zip expands into one, so an empty name would unpack `app\\`, `share\\` and the launcher loose into whatever folder the user was in.");if(windowsNameIsUnusable(n))throw Error(`gjsify ship: the windows layout would put this app in a directory called "${n}", and Windows cannot hold it: it reserves < > : " / \\ | ? * and the control characters, reserves CON, PRN, AUX, NUL, COM1-9 and LPT1-9 as device names at every path, and silently strips a trailing dot or space.
1151
+ `)}function planIcons(t){let n=[],S=new Map;for(let C of t.iconFiles){let N=On(C),F=iconThemeDir(C),I=isSymbolicIcon(C)?`${t.appId}-symbolic`:t.appId,H=`${DB.icons}/${F}/apps/${I}${N}`,W=S.get(H);if(W!==void 0)throw Error(`gjsify ship: ${C} and ${W} both install as ${H}. An icon is keyed on its context and its size: \`symbolic\` is read from a \`symbolic/\` path component or a \`-symbolic\` filename, the size from the path (\`.../128x128/...\`) or the filename (\`icon-128.png\`). Give them distinguishable sizes, or point \`gjsify.ship.icon\` at a single file.`);S.set(H,C),n.push({path:H,mode:420,source:{kind:`file`,path:C}})}return n}function assertInsidePrefix(t){let n=pn.normalize(t);if(pn.isAbsolute(n)||n===`..`||n.startsWith(`../`))throw Error(`gjsify ship: \`gjsify.ship.extraFiles\` destination "${t}" escapes the install prefix. Destinations are relative to the prefix, e.g. \`share/applications/extra.desktop\`.`);return n}function isExecutableAsset(t){return/\.(so|node|dylib)(\.\d+)*$/.test(t)}function normalise(t){let n=new Map;for(let S of t)n.set(S.path,S);return[...n.values()].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}var $V=__esmMin(()=>{QV(),EB(),PB(),PV(),OB(),xd(),Pn()});function isGtkRuntimeTarget(t){return eH.includes(t)}function gtkRuntimePackageName(t){return`@gjsify/gtk-runtime-${t}`}function resolveGtkRuntime(t,n={}){let S=n.env??process.env,C=t.startsWith(`win32-`)?`bin`:`lib`,N=[],F=S.GJSIFY_GTK_RUNTIME;F&&N.push({source:`GJSIFY_GTK_RUNTIME`,dir:F});let I=resolveNodeGiRoot(n);I!==null&&(N.push({source:`${nH}/prebuilds/${t}`,dir:wn(I,`prebuilds`,t,`gtk`)}),N.push({source:`${nH} sibling`,dir:wn(I,`..`,`gtk-runtime-${t}`,`gtk`)}));let H=gtkRuntimePackageName(t),W=resolveStagedPackage(H,n);W!==null&&N.push({source:H,dir:wn(En(W),`gtk`)});for(let t of N){let n=wn(t.dir,C),S=wn(t.dir,`girepository-1.0`);if(!(!existsSync(n)||!existsSync(S)))return{source:t.source,dir:t.dir,libDir:n,typelibDir:S}}return null}function resolveNodeGiAddon(t,n={}){let S=resolveNodeGiRoot(n);if(S===null)return null;let C=wn(S,`prebuilds`,t,tH);return existsSync(C)?{source:nH,addonPath:C}:null}function resolveNodeGiRoot(t){let n=resolveStagedPackage(nH,t);return n===null?null:En(n)}function resolveStagedPackage(t,n){let S={bundleUrl:import.meta.url};return n.cwd!==void 0&&(S.cwd=n.cwd),n.resolve!==void 0&&(S.resolve=n.resolve),resolveInstalledPackage(t,S)}function resolveNodeGiPackage(t={}){let n=resolveNodeGiRoot(t);if(n===null)return null;let S=[`package.json`];for(let t of readdirSync(n,{withFileTypes:!0}).sort((t,n)=>t.name<n.name?-1:1))t.isFile()&&t.name.endsWith(`.js`)&&S.push(t.name);let C=wn(n,`overrides`);if(existsSync(C))for(let t of listFilesRecursive(C))S.push(pn.join(`overrides`,t));return S.length>1?{source:nH,root:n,files:S.sort()}:null}function appRuntimePaths(t,n,S){let C=t.dirs(n),N=pn.join(C.native,`node-gi`),F=pn.join(N,`prebuilds`,S);return{nodeGiRoot:N,nodeGiPackageDir:pn.join(C.bundle,`node_modules`,nH),prebuildDir:F,gtkDir:pn.join(F,`gtk`),addonPath:pn.join(F,tH),interpreterPath:pn.join(C.launcher,nodeRuntimeBinaryName(S)),interpreterLicensePath:pn.join(C.data,`licenses`,`node`,`LICENSE`)}}function stageAppRuntime(t){let n=appRuntimePaths(t.layout,t.identity,t.target),S=[],C={},N=[],F=[];t.interpreter===null?F.push(`no bundled interpreter — install \`@gjsify/node-runtime-${t.target}\` (or point \`GJSIFY_NODE_RUNTIME\` at a \`bin/\` directory holding \`node\` and its \`LICENSE\`)`):(S.push({path:n.interpreterPath,mode:493,source:{kind:`file`,path:t.interpreter.nodePath}}),S.push({path:n.interpreterLicensePath,mode:420,source:{kind:`file`,path:t.interpreter.licensePath}}),C.interpreter=n.interpreterPath,N.push(`interpreter from ${t.interpreter.source}`));let I=resolveGtkRuntime(t.target,discoveryOptions(t));if(I!==null){for(let t of listFilesRecursive(I.dir)){let C=wn(I.dir,t.split(`/`).join(jn));S.push({path:pn.join(n.gtkDir,t),mode:stagedMode(t,C),source:{kind:`file`,path:C}})}C.gtkRuntimeDir=n.gtkDir,N.push(`GTK closure from ${I.source}`)}else{let n=t.target.startsWith(`win32-`)?`bin`:`lib`;F.push(`no GTK closure — install \`${gtkRuntimePackageName(t.target)}\` (or point \`GJSIFY_GTK_RUNTIME\` at a bundle directory holding \`${n}/\` and \`girepository-1.0/\`)`)}let H=resolveNodeGiPackage(discoveryOptions(t));if(H!==null){for(let t of H.files)S.push({path:pn.join(n.nodeGiPackageDir,t),mode:420,source:{kind:`file`,path:wn(H.root,t.split(`/`).join(jn))}});N.push(`node-gi runtime (${H.files.length} file(s)) from ${H.source}`)}else F.push(`no node-gi JavaScript — install \`${nH}\`; a \`--app node\` bundle keeps \`@gjsify/node-gi/*\` external, so the staged bundle would \`require\` a package the artifact does not carry`);let W=resolveNodeGiAddon(t.target,discoveryOptions(t));return W===null?F.push(`no node-gi addon — install \`${nH}\`, whose \`prebuilds/${t.target}/${tH}\` is the binary built against that closure`):(S.push({path:n.addonPath,mode:493,source:{kind:`file`,path:W.addonPath}}),C.nodeGiAddon=n.addonPath,N.push(`node-gi addon from ${W.source}`)),{files:S,launcher:C,found:N,missing:F}}function discoveryOptions(t){let n={};return t.cwd!==void 0&&(n.cwd=t.cwd),t.env!==void 0&&(n.env=t.env),t.resolve!==void 0&&(n.resolve=t.resolve),n}function stagedMode(t,n){if(isExecutableAsset(t)||t.startsWith(`libexec/`)||t.startsWith(`bin/`))return 493;try{if(statSync(n).mode&73)return 493}catch{}return 420}var eH,tH,nH,rH=__esmMin(()=>{Rd(),Pn(),KV(),JV(),$V(),nF(),eH=[`darwin-arm64`,`darwin-x64`,`win32-x64`],tH=`node_gi.node`,nH=`@gjsify/node-gi`});function appDirFor(t){return wn(t,`appimage`,cH)}function appImageHostRequirements(t){let n=interpreterFloor(t),S=new Set(t.optionalNamespaces??[]);return[`${t.app} (>= ${n})`,...hostProvidedNamespaces(t.namespaces,t.bundledTypelibs).map(t=>S.has(t)?`the ${t} typelib (optional)`:`the ${t} typelib`)]}function interpreterFloor(t){return t.app===`node`?t.minNodeVersion??`24`:t.minGjsVersion??`1.86`}function renderAppRun(t,n){let S=fV.linux.dirs(t).launcher,C=interpreterFloor(t),[N=`0`,F=`0`]=C.split(`.`);return[`#!/bin/sh`,"# Generated by `gjsify ship` — do not edit.",`set -e`,`here=$(dirname "$(readlink -f "$0")")`,`if ! command -v ${t.app} >/dev/null 2>&1; then`,` echo "${shellSafe(t.name)} needs ${t.app}, and this system has none." >&2`,` echo "This AppImage carries the application, not its runtime. It needs:" >&2`,...n.map(t=>` echo " - ${shellSafe(t)}" >&2`),` exit 127`,`fi`,`found=$(${t.app} --version 2>/dev/null | sed -n 's/[^0-9]*\\([0-9][0-9]*\\)\\.\\([0-9][0-9]*\\).*/\\1 \\2/p' | head -n 1 || true)`,"major=${found% *}","minor=${found#* }",`if [ -n "$major" ]; then`,` if [ "$major" -lt ${N} ] || { [ "$major" -eq ${N} ] && [ "$minor" -lt ${F} ]; }; then`,` echo "${shellSafe(t.name)} needs ${t.app} ${C} or newer, and this system has $major.$minor." >&2`,` echo "This AppImage carries the application, not its runtime. It needs:" >&2`,...n.map(t=>` echo " - ${shellSafe(t)}" >&2`),` exit 126`,` fi`,`fi`,`exec "$here/usr/${S}/${t.binaryName}" "$@"`,``].join(`
1152
+ `)}function shellSafe(t){return t.replace(/(["$`\\])/g,`\\$1`)}function findPinnedRuntime(t,n=process.env,S=existsSync){let C=n.GJSIFY_APPIMAGE_RUNTIME_DIR||`/usr/local/share/gjsify/appimage-runtime`,N=pn.join(C,`runtime-${t}`);return S(N)?N:void 0}function appImageRuntimeNotice(t,n){return n===void 0?`NO pinned AppImage runtime for ${t}: appimagetool will fetch runtime-${t} from type2-runtime's rolling \`continuous\` tag, so this pack NEEDS A NETWORK and the ~940 KB of runtime it embeds carries no digest from this tree. Pin one at ${sH}/runtime-${t} (or point ${oH} at a directory holding it).`:`the AppImage runtime is pinned: ${n} — this pack needs no network`}function selectAppDirIcon(t,n){let S;for(let C of t){let t=rootIconRank(C.path,n);t!==void 0&&(S===void 0||t>S.rank)&&(S={entry:C,rank:t})}return S?.entry}function rootIconRank(t,n){if(dH.find(S=>t.endsWith(`${n}${S}`))===void 0||!t.startsWith(`${DB.icons}/`)||t.includes(`/symbolic/`))return;if(t.includes(`/scalable/`))return 2**53-1;let S=/\/(\d+)x\1\//.exec(t);return S===null?1:Number(S[1])}function assertAppImageIsPackable(t,n,S){let C=`${DB.applications}/${n.appId}.desktop`;if(!t.some(t=>t.path===C))throw Error(`gjsify ship: an AppImage needs a desktop entry and this payload has no ${C}. appimagetool refuses an AppDir without one, and the AppImage runtime has nothing to tell a desktop about the application it just mounted. A \`kind: "cli"\` project stages no entry by design — set \`gjsify.ship.kind\` to "app" if this is a GUI application, or ship it as a \`.deb\`, an \`.rpm\` or a Flatpak, none of which need one.`);if(selectAppDirIcon(t,n.appId)===void 0)throw Error(`gjsify ship: an AppImage needs an icon called ${n.appId} beside its desktop entry, and this payload stages none under ${DB.icons}/. The entry's \`Icon=\` names the app id, so a file keeping its own basename is an icon nothing looks up — point \`gjsify.ship.icon\` at a PNG or an SVG and it is renamed into the theme for you.`);if(S===void 0&&t.some(t=>isSchemaSource(t.path)))throw Error(`gjsify ship: this payload stages GSettings schema sources under ${DB.schemas}/ and no ${yV} was compiled for it. An AppImage has NO INSTALL STEP — that is the whole point of the format — so the \`.deb\`/\`.rpm\` postinst that compiles the system schema directory never runs, and GSettings aborts on a directory holding only sources. The AppDir must carry ${yV}; \`compileSchemasForPayload\` produces it from this payload.`)}function appDirPayload(t,n,S,C){assertAppImageIsPackable(n,t,C);let N=selectAppDirIcon(n,t.appId),F=`${DB.applications}/${t.appId}.desktop`,I=n.find(t=>t.path===F);return[...[...n,...C===void 0?[]:[C]].map(t=>({...t,path:`usr/${t.path}`})),{path:lH,mode:493,data:encodeUtf8(renderAppRun(t,S))},{path:`${t.appId}.desktop`,mode:420,data:I.data},{path:N.path.slice(N.path.lastIndexOf(`/`)+1),mode:420,data:N.data},{path:uH,mode:420,data:N.data}]}function appImageToolArgs(t){return[`--no-appstream`,`--comp`,`zstd`,...t.runtimeFile===void 0?[]:[`--runtime-file`,t.runtimeFile],t.appDir,t.target]}function appImageToolEnv(t){return{ARCH:t,[aH]:`1`}}function appImageToolFailureMessage(t,n){let S=n===void 0?`the AppImage RUNTIME could not be downloaded — ${iH} fetches it from github.com/AppImage/type2-runtime when no runtime is pinned, so this pack needs a network and an offline host fails here having written nothing; or `:`the pinned runtime at ${n} is not an AppImage runtime — it is passed through to \`--runtime-file\` unread, so a truncated or wrong-architecture file fails here; or `;return`gjsify ship: ${iH} failed with ${t}. Four causes, measured in this order: ${S}\`file\` is not installed — ${iH} requires file(1) and says so, even though this pack already tells it the architecture; or FUSE is unavailable and the tool on PATH is a wrapper that dropped ${aH}=1, which this pack sets so the extract path is taken instead of a mount; or the work directory is full — the AppDir is copied into a squashfs image beside it.`}async function buildAppImage(t){let n=appImageToolArgs(t),S=appImageToolEnv(t.archLabel);t.verbose&&ge.log(`[gjsify ship] ${Object.entries(S).map(([t,n])=>`${t}=${n}`).join(` `)} ${iH} ${n.join(` `)}`);let C=await spawnToCompletion(iH,n,{completion:`return`,cwd:t.workDir,stdio:`inherit`,env:{...process.env,...S},notFound:()=>Error(`gjsify ship: ${iH} is not on PATH. Unlike flatpak-builder and msitools it is not packaged by Fedora or Debian: take the release from https://github.com/AppImage/appimagetool/releases, \`chmod +x\` it and put it on PATH as \`${iH}\`. \`gjsify ship linux --stage\` needs none of this — the payload is assembled by this CLI and only the container needs the tool.`)});if(C.code!==0)throw Error(appImageToolFailureMessage(describeExit(C),t.runtimeFile));if(!existsSync(t.target))throw Error(`gjsify ship: ${iH} exited 0 and wrote no file at ${t.target}. An exit code is not an artifact — re-run with \`--verbose\` to see what it was told.`)}function appDirPaths(t){let n=new Set;for(let S of t){let t=S.path.split(`/`);for(let S=1;S<t.length;S++)n.add(t.slice(0,S).join(`/`))}return[...[...n].sort(),...t.map(t=>t.path)]}function stampAppDirTimes(t,n,S){for(let C of appDirPaths(n))utimesSync(wn(t,C.split(`/`).join(jn)),S,S);utimesSync(t,S,S)}var iH,aH,oH,sH,cH,lH,uH,dH,fH=__esmMin(()=>{_e(),Rd(),Pn(),V_(),pB(),TB(),hV(),bV(),OB(),iH=`appimagetool`,aH=`APPIMAGE_EXTRACT_AND_RUN`,oH=`GJSIFY_APPIMAGE_RUNTIME_DIR`,sH=`/usr/local/share/gjsify/appimage-runtime`,cH=`AppDir`,lH=`AppRun`,uH=`.DirIcon`,dH=[`.png`,`.svg`]});function dmgVolumeName(t){let n=t.name;if(n.trim()===``)throw Error("gjsify ship: the macOS image has no name to call its volume — `gjsify.ship.name` (or the package name it is derived from) is empty. `hdiutil` would accept that and mount the image as `untitled`, which is the name every nameless disk image on the machine has.");if(mH.test(n))throw Error(`gjsify ship: the macOS image would mount a volume called "${n}", and HFS+ cannot hold it: the Finder shows a stored ":" as a "/" and a stored "/" as a ":", so the volume would not be the one this project named. Set \`gjsify.ship.name\` to the display name you want.`);return n}function hdiutilCreateArgs(t){return[`create`,`-format`,`UDZO`,`-fs`,`HFS+J`,`-volname`,t.volumeName,`-srcfolder`,t.sourceDir,`-ov`,`-quiet`,t.target]}async function buildDmgImage(t){let n=hdiutilCreateArgs(t);t.verbose&&ge.log(`[gjsify ship] ${pH} ${n.join(` `)}`);let S=await spawnToCompletion(pH,n,{completion:`return`,cwd:t.workDir,stdio:`inherit`,notFound:()=>Error(`gjsify ship: ${pH} is not on PATH. It ships with macOS and cannot be installed anywhere else, so this is either a broken macOS installation or a host that is not macOS at all. A \`.dmg\` is packed on darwin (ADR 0024 § A1); from anywhere else the route is \`gjsify ship darwin --stage\` here and \`gjsify ship --from-stage <dir> --target macos-app-dmg\` there.`)});if(S.code!==0)throw Error(`gjsify ship: ${pH} failed with ${describeExit(S)}.`)}function dmgVolumeDir(t){return wn(t,`dmg`,`volume`)}var pH,mH,hH=__esmMin(()=>{_e(),Pn(),V_(),pH=`hdiutil`,mH=/[/:]/});function renderShipFlatpakManifest(t){let{settings:n,stageDir:S,overlayDir:C}=t,N=n.flatpak,F={id:n.appId,runtime:N.runtime,"runtime-version":N.runtimeVersion,sdk:N.sdk,branch:N.branch,command:n.binaryName,"finish-args":N.finishArgs};return N.sdkExtensions.length>0&&(F[`sdk-extensions`]=N.sdkExtensions),N.appendPath.length>0&&(F[`build-options`]={"append-path":N.appendPath.join(`:`)}),N.cleanup.length>0&&(F.cleanup=N.cleanup),F.modules=[{name:n.binaryName,buildsystem:`simple`,"build-commands":[`mkdir -p /app`,`cp -a stage/. /app/`,`cp -a overlay/. /app/`],sources:[{type:`dir`,path:S,dest:`stage`,skip:[t.stageManifestFile]},{type:`dir`,path:C,dest:`overlay`}]}],F}async function buildFlatpakBundle(t){let{settings:n,workDir:S,archLabel:C}=t,N=wn(S,`${n.appId}.json`),F=wn(S,`build`),I=wn(S,`repo`),H=wn(S,`state`);mkdirSync(S,{recursive:!0}),rmSync(I,{recursive:!0,force:!0,maxRetries:5}),writeFileSync(N,`${JSON.stringify(renderShipFlatpakManifest(t),null,2)}\n`),await run$1(`flatpak-builder`,[`--force-clean`,`--disable-rofiles-fuse`,`--delete-build-dirs`,`--state-dir=${H}`,`--arch=${C}`,`--repo=${I}`,F,N],t,"flatpak-builder not found. Install it (Fedora: `sudo dnf install flatpak-builder`)."),await run$1(`flatpak`,[`build-bundle`,`--arch=${C}`,I,t.target,n.appId,n.flatpak.branch],t,`flatpak not found. Install it via your distro: see https://flathub.org/setup.`)}async function run$1(t,n,S,C){S.verbose&&ge.log(`[gjsify ship] ${t} ${n.join(` `)}`);let N=await spawnToCompletion(t,n,{completion:`return`,cwd:S.workDir,stdio:`inherit`,notFound:()=>Error(`gjsify ship: ${C}`)});if(N.code!==0)throw Error(`gjsify ship: ${t} failed with ${describeExit(N)}.`)}var gH=__esmMin(()=>{_e(),Rd(),Pn(),V_(),__name$1(run$1,`run`)});function localeOf(t){return t.split(`/`)[0]??``}function fold(t,n,S,C,N){let F=wn(N,`source${S}`);return writeFileSync(F,n),readFileSync(mergeCatalogues({mode:t,template:F,extension:S,catalogues:C,workDir:N}),`utf-8`)}function localizeMetadata(t,n){if(n.length===0)return t;let S=mkdtempSync(wn(tmpdir(),`gjsify-ship-l10n-`));try{let C=[...n].sort((t,n)=>t.rel<n.rel?-1:+(t.rel>n.rel)),N=new Map;for(let[t,n]of C.entries()){let C=wn(S,`${t}.po`);execFileSync(`msgunfmt`,[n.abs,`--output-file`,C],{stdio:`pipe`});let F=localeOf(n.rel);N.set(F,[...N.get(F)??[],C])}let F=[...N].map(([t,n])=>({locale:t,po:n.length===1?n[0]:msgcat(n,wn(S,`${t}.merged.po`))}));return{metainfo:fold(`--xml`,t.metainfo,`.metainfo.xml`,F,S),desktopEntry:t.desktopEntry===void 0?void 0:fold(`--desktop`,t.desktopEntry,`.desktop`,F,S)}}catch(t){throw Error(describeFailure(t,n.length))}finally{rmSync(S,{recursive:!0,force:!0})}}function msgcat(t,n){return execFileSync(`msgcat`,[`--use-first`,`--output-file`,n,...t],{stdio:`pipe`}),n}function describeFailure(t,n){let S=t;return S?.code===`ENOENT`?`gjsify ship: \`msgfmt\`/\`msgunfmt\`/\`msgcat\` are not on PATH, but the package stages ${n} gettext catalogue(s). Install them (package: gettext) — shipping the metadata untranslated would install an English app menu entry for a translated app, which nothing downstream can detect.`:`gjsify ship: could not fold the gettext catalogues into the freedesktop metadata.${S?.stderr===void 0?``:`\n${String(S.stderr).trim()}`}`}var _H=__esmMin(()=>{P_(),Rd(),Lg(),Pn(),fz()});function lookupArch(t,n,S){let C=t[n];if(!C)throw Error(`gjsify ship: no ${S} architecture is known for \`process.arch\` "${n}". Known: ${Object.keys(t).join(`, `)}.`);return C}function debArch(t,n){return n?`all`:lookupArch(vH,t,`Debian`)}function rpmArch(t,n){return n?`noarch`:lookupArch(yH,t,`RPM`)}function flatpakArch(t,n){return lookupArch(bH,t,`Flatpak`)}function appImageArch(t,n){return lookupArch(xH,t,`AppImage`)}function macosArch(t,n){return lookupArch(SH,t,`macOS`)}function windowsArch(t,n){return lookupArch(CH,t,`Windows`)}function windowsNameIsUnusable(t){return wH.test(t)||TH.test(t)||/[. ]$/.test(t)?!0:[...t].some(t=>(t.codePointAt(0)??0)<32)}function windowsProgramDirName(t){let n=t.name;if(n.trim()===``)throw Error("gjsify ship: the windows layout has no name to call the program directory — `gjsify.ship.name` (or the package name it is derived from) is empty. The artifact IS a directory and its zip expands into one, so an empty name would unpack `app\\`, `share\\` and the launcher loose into whatever folder the user was in.");if(windowsNameIsUnusable(n))throw Error(`gjsify ship: the windows layout would put this app in a directory called "${n}", and Windows cannot hold it: it reserves < > : " / \\ | ? * and the control characters, reserves CON, PRN, AUX, NUL, COM1-9 and LPT1-9 as device names at every path, and silently strips a trailing dot or space.
1153
1153
  The artifact would assemble here and be unextractable — or extract under a different name than
1154
- the launcher resolves against. Set \`gjsify.ship.name\` to the display name you want on disk.`);return n}function requiredToolsOn(t,n){return Array.isArray(t)?t:t[n]??[]}function defaultFormatIds(t){return TH.filter(n=>wH[n].layoutOs===t&&wH[n].host.finishOn===`any`)}function formatIdsFor(t){return TH.filter(n=>wH[n].layoutOs===t)}function assertHostCanFinish(t,n=process.platform){let{finishOn:S}=t.host;if(!(S===`any`||S.includes(n)))throw Error(`gjsify ship: a ${t.id} artifact is packed on ${S.join(` or `)} and this host is ${n} (ADR 0024 § A1: a container is produced where its format's tool lives). Assembly is not host-bound, so the way across is the two-phase split: run \`gjsify ship --stage\` here, move \`ship/stage/\` to a ${S.join(`/`)} runner, and finish with \`gjsify ship --from-stage <dir> --target ${t.id}\`.`)}function assertToolsInstalled(t,n=isOnPath,S=process.platform){let C=requiredToolsOn(t.host.requiredTools,S),N=C.filter(t=>!n(t));if(N.length===0)return;let F=t.host.installHint;throw Error(`gjsify ship: packing a ${t.id} on ${S} needs ${C.join(` and `)}, and ${N.join(`, `)} ${N.length>1?`are`:`is`} not on PATH. ${F===void 0?`Install it`:`Install it (${F})`}, or drop this target — the other formats need no tools at all. \`gjsify ship --stage\` also works without ${N.join(`/`)}: the payload is assembled by this CLI and only the container needs them.`)}function parseFormatNames(t,n){let S=t.flatMap(t=>t.split(`,`)).map(t=>t.trim()).filter(t=>t.length>0),C=S.filter(t=>!Object.hasOwn(wH,t));if(C.length>0)throw Error(`gjsify ship: unknown target${C.length>1?`s`:``} ${C.join(`, `)} in ${n}. Known targets: ${TH.join(`, `)}.`);let N=[...new Set(S)].sort();if(N.length===0)throw Error(`gjsify ship: ${n} named no format. Known targets: ${TH.join(`, `)}.`);return N}function resolveFormats(t,n){let S=parseFormatNames(t,`--target`),C=S.filter(t=>wH[t].layoutOs!==n.os);if(C.length>0){let t=formatIdsFor(n.os),S=[...new Set(C.map(t=>wH[t].layoutOs))];throw Error(`gjsify ship: ${C.join(`, `)} ${C.length>1?`wrap`:`wraps`} the ${S.join(`/`)} layout and this run assembles the ${n.name} one. `+(t.length===0?`No format wraps the ${n.name} layout — \`gjsify ship ${n.name} --stage\` assembles it and stops.`:`Formats for this layout: ${t.join(`, `)}.`)+` To build ${C.join(`, `)}, name the layout each wraps: ${S.map(t=>`\`gjsify ship ${EH[t]??t} --target ${C.filter(n=>wH[n].layoutOs===t).join(`,`)}\``).join(`, `)}.`)}return S.map(t=>wH[t])}function configuredFormats(t,n){let S=parseFormatNames(t,"`gjsify.ship.targets`");return{formats:S.filter(t=>wH[t].layoutOs===n.os).map(t=>wH[t]),dropped:S.filter(t=>wH[t].layoutOs!==n.os)}}function assertKindCanPack(t,n){if(n===`app`)return;let S=t.filter(t=>t.requiresDesktopEntry);if(S.length!==0)throw Error(`gjsify ship: ${S.map(t=>t.id).join(`, `)} cannot package a \`kind: "cli"\` project — the container needs a desktop entry at its root and a CLI stages none by design. Set \`gjsify.ship.kind\` to "app" if this is a GUI application, or ship it as a \`.deb\`, an \`.rpm\` or a Flatpak, none of which need one.`)}function canCarryTicket(t){switch(t){case`macos-app`:case`macos-app-dmg`:return!0;case`macos-app-zip`:case`deb`:case`rpm`:case`flatpak`:case`appimage`:case`windows-dir`:case`windows-dir-zip`:case`msi`:return!1;default:throw Error(`gjsify ship: no ticket answer for format "${String(t)}".`)}}var pH,mH,hH,gH,_H,vH,yH,bH,xH,SH,CH,SHARE_LICENSE_DEST,WRITTEN_HERE,wH,TH,EH,DH=__esmMin(()=>{vF(),sH(),uH(),uV(),hV(),pH={x64:`amd64`,arm64:`arm64`,ia32:`i386`,arm:`armhf`,riscv64:`riscv64`,ppc64:`ppc64el`,s390x:`s390x`},mH={x64:`x86_64`,arm64:`aarch64`,ia32:`i686`,arm:`armv7hl`,riscv64:`riscv64`,ppc64:`ppc64le`,s390x:`s390x`},hH={x64:`x86_64`,arm64:`aarch64`,ia32:`i386`,arm:`arm`},gH={x64:`x86_64`,arm64:`aarch64`,ia32:`i686`,arm:`armhf`},_H={x64:`x86_64`,arm64:`arm64`},vH={x64:`x64`},yH=/[<>:"/\\|?*]/,bH=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\.|$)/i,xH=`a distro package declares its interpreter as a dependency instead of carrying one, and every distribution ships both`,SH='a `.app` a stranger downloads has to CARRY its interpreter, and there is no relocatable GJS to put in one — `packages/node-gi/scripts/build-gtk-runtime-darwin.mjs` records "GJS ships no relocation", which is why ADR 0024 § 4 derives Node on macOS and stage 7 is what would change it',CH="there is no GJS host on Windows at all (ADR 0024 § 4) — not a system one to depend on and not a relocatable one to carry — so a `--app gjs` payload cannot be shipped this way. That is why § 4 derives Node here, and why `@gjsify/node-runtime-win32-x64` exists",SHARE_LICENSE_DEST=t=>`share/licenses/${t}/LICENSE`,WRITTEN_HERE=t=>({finishOn:`any`,requiredTools:[],oracle:{readWith:t,readOn:[`linux`],selfReading:!1}}),wH={deb:{id:`deb`,layoutOs:`linux`,prefix:`/usr`,host:WRITTEN_HERE([`ar`,`tar`,`dpkg-deb`,`lintian`]),depends:`deb`,interpreters:[`gjs`,`node`],interpreterGap:xH,licenseDest:t=>`share/doc/${t}/copyright`,licenseKind:`debian-copyright`,changelogDest:t=>`share/doc/${t}/changelog.Debian.gz`,archName:debArch,fileName:(t,n)=>`${t.binaryName}_${t.version}-${t.release}_${n}.deb`,artifactKind:`file`},rpm:{id:`rpm`,layoutOs:`linux`,prefix:`/usr`,host:WRITTEN_HERE([`rpm`,`rpm2cpio`,`cpio`]),depends:`rpm`,interpreters:[`gjs`,`node`],interpreterGap:xH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:rpmArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.${n}.rpm`,artifactKind:`file`},flatpak:{id:`flatpak`,layoutOs:`linux`,prefix:`/app`,host:{finishOn:[`linux`],requiredTools:[`flatpak-builder`,`flatpak`],installHint:"Fedora: `sudo dnf install flatpak flatpak-builder`, Debian/Ubuntu: `sudo apt install flatpak flatpak-builder`",oracle:{readWith:[`flatpak`,`ostree`],readOn:[`linux`],selfReading:!1}},depends:null,interpreters:[`gjs`],interpreterGap:"a Flatpak runs against `org.gnome.Platform`, which ships `gjs` and no `node`. Node exists only as `org.freedesktop.Sdk.Extension.node2x`, and that extension puts node on the BUILD path, not in the runtime — so the artifact would install and then fail at `exec node`",licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:flatpakArch,fileName:(t,n)=>`${t.appId}-${t.version}-${t.release}.${n}.flatpak`,artifactKind:`file`},appimage:{id:`appimage`,layoutOs:`linux`,prefix:`/usr`,host:{finishOn:[`linux`],requiredTools:[$V,fV],installHint:`no distribution packages appimagetool — take the release from https://github.com/AppImage/appimagetool/releases, \`chmod +x\` it and put it on PATH as \`appimagetool\`; or assemble here with \`gjsify ship linux --stage\` and pack where it is. The schema compiler is packaged: ${pV}`,oracle:{readWith:[`python3`,`unsquashfs`],readOn:[`linux`],selfReading:!1}},depends:null,interpreters:[`gjs`,`node`],interpreterGap:"an AppImage carries the application and takes its interpreter from the host, exactly as a distro package does — but with no dependency field to declare it in, so the requirement is printed at pack time and checked by `AppRun` at launch instead",licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:appImageArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.${n}.AppImage`,artifactKind:`file`,requiresDesktopEntry:!0},"macos-app":{id:`macos-app`,layoutOs:`darwin`,prefix:``,host:{finishOn:`any`,requiredTools:[fV],installHint:pV,oracle:{readWith:[`python3`],readOn:[`linux`,`darwin`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:SH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:macosArch,fileName:t=>`${t.name}.app`,artifactKind:`directory`},"macos-app-zip":{id:`macos-app-zip`,layoutOs:`darwin`,prefix:``,host:{finishOn:`any`,requiredTools:[fV],installHint:pV,oracle:{readWith:[`zipinfo`],readOn:[`linux`,`darwin`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:SH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:macosArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.macos.${n}.zip`,artifactKind:`file`},"macos-app-dmg":{id:`macos-app-dmg`,layoutOs:`darwin`,prefix:``,host:{finishOn:[`darwin`],requiredTools:[cH],installHint:"`hdiutil` is part of macOS and cannot be installed elsewhere — on a Mac it is /usr/bin/hdiutil, so an absent one means a broken installation rather than a missing package",oracle:{readWith:[`7z`,`dmg2img`,`fsck.hfsplus`],readOn:[`linux`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:SH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:macosArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.${n}.dmg`,artifactKind:`file`},"windows-dir":{id:`windows-dir`,layoutOs:`win32`,prefix:``,host:{finishOn:`any`,requiredTools:[fV],installHint:pV,oracle:{readWith:[`cmd`,`python3`],readOn:[`linux`,`win32`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:CH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:windowsArch,fileName:t=>windowsProgramDirName(t),artifactKind:`directory`},"windows-dir-zip":{id:`windows-dir-zip`,layoutOs:`win32`,prefix:``,host:{finishOn:`any`,requiredTools:[fV],installHint:pV,oracle:{readWith:[`zipinfo`],readOn:[`linux`,`darwin`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:CH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:windowsArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.windows.${n}.zip`,artifactKind:`file`},msi:{id:`msi`,layoutOs:`win32`,prefix:``,host:{finishOn:[`linux`,`win32`],requiredTools:{linux:[fV,`wixl`],win32:[fV,`candle.exe`,`light.exe`]},installHint:`${pV}; the MSI compiler is Fedora: \`sudo dnf install msitools\`, Debian/Ubuntu: \`sudo apt install msitools\`, Windows: WiX Toolset v3.14 (https://github.com/wixtoolset/wix3/releases) with its \`bin\` directory on PATH`,oracle:{readWith:[`msiexec`,`msiinfo`],readOn:[`win32`,`linux`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:CH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:windowsArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.${n}.msi`,artifactKind:`file`}},TH=Object.keys(wH),EH=Object.fromEntries(cV.map(t=>[sV[t].os,t]))});function uuid5(t,n){let S=t.replace(/-/g,``),C=new Uint8Array(16);for(let t=0;t<16;t+=1)C[t]=Number.parseInt(S.slice(t*2,t*2+2),16);let N=createHash(`sha1`).update(C).update(new TextEncoder().encode(n)).digest(),F=Uint8Array.from(N.subarray(0,16));F[6]=(F[6]??0)&15|80,F[8]=(F[8]??0)&63|128;let I=[...F].map(t=>t.toString(16).padStart(2,`0`)).join(``);return[I.slice(0,8),I.slice(8,12),I.slice(12,16),I.slice(16,20),I.slice(20)].join(`-`)}function msiUpgradeCode(t){return uuid5(OH,`upgrade\n${t.appId}`).toUpperCase()}function msiProductCode(t,n){let S=`product\n${t.appId}\n${t.version}\n${t.release}\n${n}`;return uuid5(OH,S).toUpperCase()}function msiComponentGuid(t,n){return uuid5(OH,`component\n${t.appId}\n${n}`).toUpperCase()}function msiProductVersion(t){let n=/^(\d+)\.(\d+)(?:\.(\d+))?$/.exec(t);if(n===null)throw Error(`gjsify ship: "${t}" is not a version an \`.msi\` can carry. Windows Installer's \`ProductVersion\` is \`major.minor.build\` and nothing else — no prerelease suffix, no build metadata.
1154
+ the launcher resolves against. Set \`gjsify.ship.name\` to the display name you want on disk.`);return n}function requiredToolsOn(t,n){return Array.isArray(t)?t:t[n]??[]}function defaultFormatIds(t){return AH.filter(n=>kH[n].layoutOs===t&&kH[n].host.finishOn===`any`)}function formatIdsFor(t){return AH.filter(n=>kH[n].layoutOs===t)}function assertHostCanFinish(t,n=process.platform){let{finishOn:S}=t.host;if(!(S===`any`||S.includes(n)))throw Error(`gjsify ship: a ${t.id} artifact is packed on ${S.join(` or `)} and this host is ${n} (ADR 0024 § A1: a container is produced where its format's tool lives). Assembly is not host-bound, so the way across is the two-phase split: run \`gjsify ship --stage\` here, move \`ship/stage/\` to a ${S.join(`/`)} runner, and finish with \`gjsify ship --from-stage <dir> --target ${t.id}\`.`)}function assertToolsInstalled(t,n=isOnPath,S=process.platform){let C=requiredToolsOn(t.host.requiredTools,S),N=C.filter(t=>!n(t));if(N.length===0)return;let F=t.host.installHint;throw Error(`gjsify ship: packing a ${t.id} on ${S} needs ${C.join(` and `)}, and ${N.join(`, `)} ${N.length>1?`are`:`is`} not on PATH. ${F===void 0?`Install it`:`Install it (${F})`}, or drop this target — the other formats need no tools at all. \`gjsify ship --stage\` also works without ${N.join(`/`)}: the payload is assembled by this CLI and only the container needs them.`)}function parseFormatNames(t,n){let S=t.flatMap(t=>t.split(`,`)).map(t=>t.trim()).filter(t=>t.length>0),C=S.filter(t=>!Object.hasOwn(kH,t));if(C.length>0)throw Error(`gjsify ship: unknown target${C.length>1?`s`:``} ${C.join(`, `)} in ${n}. Known targets: ${AH.join(`, `)}.`);let N=[...new Set(S)].sort();if(N.length===0)throw Error(`gjsify ship: ${n} named no format. Known targets: ${AH.join(`, `)}.`);return N}function resolveFormats(t,n){let S=parseFormatNames(t,`--target`),C=S.filter(t=>kH[t].layoutOs!==n.os);if(C.length>0){let t=formatIdsFor(n.os),S=[...new Set(C.map(t=>kH[t].layoutOs))];throw Error(`gjsify ship: ${C.join(`, `)} ${C.length>1?`wrap`:`wraps`} the ${S.join(`/`)} layout and this run assembles the ${n.name} one. `+(t.length===0?`No format wraps the ${n.name} layout — \`gjsify ship ${n.name} --stage\` assembles it and stops.`:`Formats for this layout: ${t.join(`, `)}.`)+` To build ${C.join(`, `)}, name the layout each wraps: ${S.map(t=>`\`gjsify ship ${jH[t]??t} --target ${C.filter(n=>kH[n].layoutOs===t).join(`,`)}\``).join(`, `)}.`)}return S.map(t=>kH[t])}function configuredFormats(t,n){let S=parseFormatNames(t,"`gjsify.ship.targets`");return{formats:S.filter(t=>kH[t].layoutOs===n.os).map(t=>kH[t]),dropped:S.filter(t=>kH[t].layoutOs!==n.os)}}function assertKindCanPack(t,n){if(n===`app`)return;let S=t.filter(t=>t.requiresDesktopEntry);if(S.length!==0)throw Error(`gjsify ship: ${S.map(t=>t.id).join(`, `)} cannot package a \`kind: "cli"\` project — the container needs a desktop entry at its root and a CLI stages none by design. Set \`gjsify.ship.kind\` to "app" if this is a GUI application, or ship it as a \`.deb\`, an \`.rpm\` or a Flatpak, none of which need one.`)}function canCarryTicket(t){switch(t){case`macos-app`:case`macos-app-dmg`:return!0;case`macos-app-zip`:case`deb`:case`rpm`:case`flatpak`:case`appimage`:case`windows-dir`:case`windows-dir-zip`:case`msi`:return!1;default:throw Error(`gjsify ship: no ticket answer for format "${String(t)}".`)}}var vH,yH,bH,xH,SH,CH,wH,TH,EH,DH,OH,SHARE_LICENSE_DEST,WRITTEN_HERE,kH,AH,jH,MH=__esmMin(()=>{vF(),fH(),hH(),hV(),bV(),vH={x64:`amd64`,arm64:`arm64`,ia32:`i386`,arm:`armhf`,riscv64:`riscv64`,ppc64:`ppc64el`,s390x:`s390x`},yH={x64:`x86_64`,arm64:`aarch64`,ia32:`i686`,arm:`armv7hl`,riscv64:`riscv64`,ppc64:`ppc64le`,s390x:`s390x`},bH={x64:`x86_64`,arm64:`aarch64`,ia32:`i386`,arm:`arm`},xH={x64:`x86_64`,arm64:`aarch64`,ia32:`i686`,arm:`armhf`},SH={x64:`x86_64`,arm64:`arm64`},CH={x64:`x64`},wH=/[<>:"/\\|?*]/,TH=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\.|$)/i,EH=`a distro package declares its interpreter as a dependency instead of carrying one, and every distribution ships both`,DH='a `.app` a stranger downloads has to CARRY its interpreter, and there is no relocatable GJS to put in one — `packages/node-gi/scripts/build-gtk-runtime-darwin.mjs` records "GJS ships no relocation", which is why ADR 0024 § 4 derives Node on macOS and stage 7 is what would change it',OH="there is no GJS host on Windows at all (ADR 0024 § 4) — not a system one to depend on and not a relocatable one to carry — so a `--app gjs` payload cannot be shipped this way. That is why § 4 derives Node here, and why `@gjsify/node-runtime-win32-x64` exists",SHARE_LICENSE_DEST=t=>`share/licenses/${t}/LICENSE`,WRITTEN_HERE=t=>({finishOn:`any`,requiredTools:[],oracle:{readWith:t,readOn:[`linux`],selfReading:!1}}),kH={deb:{id:`deb`,layoutOs:`linux`,prefix:`/usr`,host:WRITTEN_HERE([`ar`,`tar`,`dpkg-deb`,`lintian`]),depends:`deb`,interpreters:[`gjs`,`node`],interpreterGap:EH,licenseDest:t=>`share/doc/${t}/copyright`,licenseKind:`debian-copyright`,changelogDest:t=>`share/doc/${t}/changelog.Debian.gz`,archName:debArch,fileName:(t,n)=>`${t.binaryName}_${t.version}-${t.release}_${n}.deb`,artifactKind:`file`},rpm:{id:`rpm`,layoutOs:`linux`,prefix:`/usr`,host:WRITTEN_HERE([`rpm`,`rpm2cpio`,`cpio`]),depends:`rpm`,interpreters:[`gjs`,`node`],interpreterGap:EH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:rpmArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.${n}.rpm`,artifactKind:`file`},flatpak:{id:`flatpak`,layoutOs:`linux`,prefix:`/app`,host:{finishOn:[`linux`],requiredTools:[`flatpak-builder`,`flatpak`],installHint:"Fedora: `sudo dnf install flatpak flatpak-builder`, Debian/Ubuntu: `sudo apt install flatpak flatpak-builder`",oracle:{readWith:[`flatpak`,`ostree`],readOn:[`linux`],selfReading:!1}},depends:null,interpreters:[`gjs`],interpreterGap:"a Flatpak runs against `org.gnome.Platform`, which ships `gjs` and no `node`. Node exists only as `org.freedesktop.Sdk.Extension.node2x`, and that extension puts node on the BUILD path, not in the runtime — so the artifact would install and then fail at `exec node`",licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:flatpakArch,fileName:(t,n)=>`${t.appId}-${t.version}-${t.release}.${n}.flatpak`,artifactKind:`file`},appimage:{id:`appimage`,layoutOs:`linux`,prefix:`/usr`,host:{finishOn:[`linux`],requiredTools:[iH,_V],installHint:`no distribution packages appimagetool — take the release from https://github.com/AppImage/appimagetool/releases, \`chmod +x\` it and put it on PATH as \`appimagetool\`; or assemble here with \`gjsify ship linux --stage\` and pack where it is. The schema compiler is packaged: ${vV}`,oracle:{readWith:[`python3`,`unsquashfs`],readOn:[`linux`],selfReading:!1}},depends:null,interpreters:[`gjs`,`node`],interpreterGap:"an AppImage carries the application and takes its interpreter from the host, exactly as a distro package does — but with no dependency field to declare it in, so the requirement is printed at pack time and checked by `AppRun` at launch instead",licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:appImageArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.${n}.AppImage`,artifactKind:`file`,requiresDesktopEntry:!0},"macos-app":{id:`macos-app`,layoutOs:`darwin`,prefix:``,host:{finishOn:`any`,requiredTools:[_V],installHint:vV,oracle:{readWith:[`python3`],readOn:[`linux`,`darwin`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:DH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:macosArch,fileName:t=>`${t.name}.app`,artifactKind:`directory`},"macos-app-zip":{id:`macos-app-zip`,layoutOs:`darwin`,prefix:``,host:{finishOn:`any`,requiredTools:[_V],installHint:vV,oracle:{readWith:[`zipinfo`],readOn:[`linux`,`darwin`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:DH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:macosArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.macos.${n}.zip`,artifactKind:`file`},"macos-app-dmg":{id:`macos-app-dmg`,layoutOs:`darwin`,prefix:``,host:{finishOn:[`darwin`],requiredTools:[pH],installHint:"`hdiutil` is part of macOS and cannot be installed elsewhere — on a Mac it is /usr/bin/hdiutil, so an absent one means a broken installation rather than a missing package",oracle:{readWith:[`7z`,`dmg2img`,`fsck.hfsplus`],readOn:[`linux`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:DH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:macosArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.${n}.dmg`,artifactKind:`file`},"windows-dir":{id:`windows-dir`,layoutOs:`win32`,prefix:``,host:{finishOn:`any`,requiredTools:[_V],installHint:vV,oracle:{readWith:[`cmd`,`python3`],readOn:[`linux`,`win32`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:OH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:windowsArch,fileName:t=>windowsProgramDirName(t),artifactKind:`directory`},"windows-dir-zip":{id:`windows-dir-zip`,layoutOs:`win32`,prefix:``,host:{finishOn:`any`,requiredTools:[_V],installHint:vV,oracle:{readWith:[`zipinfo`],readOn:[`linux`,`darwin`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:OH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:windowsArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.windows.${n}.zip`,artifactKind:`file`},msi:{id:`msi`,layoutOs:`win32`,prefix:``,host:{finishOn:[`linux`,`win32`],requiredTools:{linux:[_V,`wixl`],win32:[_V,`candle.exe`,`light.exe`]},installHint:`${vV}; the MSI compiler is Fedora: \`sudo dnf install msitools\`, Debian/Ubuntu: \`sudo apt install msitools\`, Windows: WiX Toolset v3.14 (https://github.com/wixtoolset/wix3/releases) with its \`bin\` directory on PATH`,oracle:{readWith:[`msiexec`,`msiinfo`],readOn:[`win32`,`linux`],selfReading:!1}},depends:null,interpreters:[`node`],interpreterGap:OH,licenseDest:SHARE_LICENSE_DEST,licenseKind:`plain`,archName:windowsArch,fileName:(t,n)=>`${t.binaryName}-${t.version}-${t.release}.${n}.msi`,artifactKind:`file`}},AH=Object.keys(kH),jH=Object.fromEntries(pV.map(t=>[fV[t].os,t]))});function uuid5(t,n){let S=t.replace(/-/g,``),C=new Uint8Array(16);for(let t=0;t<16;t+=1)C[t]=Number.parseInt(S.slice(t*2,t*2+2),16);let N=createHash(`sha1`).update(C).update(new TextEncoder().encode(n)).digest(),F=Uint8Array.from(N.subarray(0,16));F[6]=(F[6]??0)&15|80,F[8]=(F[8]??0)&63|128;let I=[...F].map(t=>t.toString(16).padStart(2,`0`)).join(``);return[I.slice(0,8),I.slice(8,12),I.slice(12,16),I.slice(16,20),I.slice(20)].join(`-`)}function msiUpgradeCode(t){return uuid5(NH,`upgrade\n${t.appId}`).toUpperCase()}function msiProductCode(t,n){let S=`product\n${t.appId}\n${t.version}\n${t.release}\n${n}`;return uuid5(NH,S).toUpperCase()}function msiComponentGuid(t,n){return uuid5(NH,`component\n${t.appId}\n${n}`).toUpperCase()}function msiProductVersion(t){let n=/^(\d+)\.(\d+)(?:\.(\d+))?$/.exec(t);if(n===null)throw Error(`gjsify ship: "${t}" is not a version an \`.msi\` can carry. Windows Installer's \`ProductVersion\` is \`major.minor.build\` and nothing else — no prerelease suffix, no build metadata.
1155
1155
  Dropping the suffix is not an option this command will take silently: \`1.2.0~rc.1\` and \`1.2.0\` would
1156
1156
  become the same version, \`MajorUpgrade\` could not tell them apart, and installing one over the other
1157
1157
  would leave both on the machine. Set \`gjsify.ship.version\` to a plain \`x.y.z\`, or drop \`msi\` from the targets.`);let[S,C,N]=[Number(n[1]),Number(n[2]),Number(n[3]??`0`)];if(S>255||C>255||N>65535)throw Error(`gjsify ship: version "${t}" is outside what Windows Installer compares — \`major\` and \`minor\` are at most 255 and \`build\` at most 65535. A field over the limit is not rejected by the installer, it is
1158
- TRUNCATED, so the artifact would carry a version that is not the one it was built from. Set \`gjsify.ship.version\`.`);return`${S}.${C}.${N}`}function msiIdentifier(t,n,S=``){let C=createHash(`sha1`).update(new TextEncoder().encode(n)).digest(`hex`).slice(0,12),N=n.replace(/[^A-Za-z0-9_.]/g,`_`),F=72-t.length-2-C.length-S.length;return`${t}_${N.length>F?N.slice(N.length-F):N}_${C}${S}`}function assertNameIsAddressable(t,n){if(t===`.`||t===`..`||t.length===0||kH.test(t))throw Error(`gjsify ship: the payload holds "${n}", and Windows Installer cannot address the path segment "${t}". A \`FileName\` or \`DefaultDir\` cell reserves < > : " / \\ | ? * and ; (its own list separator), and
1158
+ TRUNCATED, so the artifact would carry a version that is not the one it was built from. Set \`gjsify.ship.version\`.`);return`${S}.${C}.${N}`}function msiIdentifier(t,n,S=``){let C=createHash(`sha1`).update(new TextEncoder().encode(n)).digest(`hex`).slice(0,12),N=n.replace(/[^A-Za-z0-9_.]/g,`_`),F=72-t.length-2-C.length-S.length;return`${t}_${N.length>F?N.slice(N.length-F):N}_${C}${S}`}function assertNameIsAddressable(t,n){if(t===`.`||t===`..`||t.length===0||PH.test(t))throw Error(`gjsify ship: the payload holds "${n}", and Windows Installer cannot address the path segment "${t}". A \`FileName\` or \`DefaultDir\` cell reserves < > : " / \\ | ? * and ; (its own list separator), and
1159
1159
  \`.\` and \`..\` are not names. The \`.msi\` would build and install the file somewhere else, or not at all.`);if(t.length>255)throw Error(`gjsify ship: the payload holds "${n}", whose segment "${t.slice(0,40)}…" is ${t.length} characters. Windows Installer's \`FileName\` column is 255.`)}function directoryTree(t){let n={path:``,name:``,children:new Map,files:[]};for(let S of[...t].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))){let t=S.path.split(`/`),C=t.pop();if(C===void 0)throw Error(`gjsify ship: the payload holds an empty path.`);let N=n;for(let n of t){assertNameIsAddressable(n,S.path);let t=N.children.get(n)??{path:N.path===``?n:`${N.path}/${n}`,name:n,children:new Map,files:[]};N.children.set(n,t),N=t}assertNameIsAddressable(C,S.path),N.files.push(S)}return n}function renderWxs(t){let{settings:n,programDirName:S,archLabel:C}=t,N=msiProductVersion(n.version),F=n.maintainer.replace(/\s*<[^>]*>\s*$/,``).trim()||n.maintainer,I=windowsGuiLauncherPath(n),H=new Map,claim=(t,n)=>{let S=H.get(t);if(S!==void 0)throw Error(`gjsify ship: the MSI identifier "${t}" would be shared by ${S} and ${n}. Two rows cannot carry one id — one would silently replace the other.`);return H.set(t,n),t},W=claim(msiIdentifier(`i`,I,`.exe`),`the launcher icon`),q=[],Y=[],X=!1,Z,emitDir=(t,S)=>{for(let C of t.files){let t=claim(msiIdentifier(`c`,C.path),C.path),N=claim(msiIdentifier(`f`,C.path),C.path);Y.push(t);let F=msiComponentGuid(n,C.path),H=xmlEscape(pn.basename(C.path));q.push(`${S}<Component Id="${t}" Guid="${F}">`),C.path===I?(X=!0,Z=C.source,q.push(`${S} <File Id="${N}" Name="${H}" Source="${xmlEscape(C.source)}" KeyPath="yes">`),q.push(`${S} <Shortcut Id="${claim(`s_startmenu`,`the Start-Menu shortcut`)}" Directory="ProgramMenuFolder" Name="${xmlEscape(n.name)}" WorkingDirectory="INSTALLDIR" Description="${xmlEscape(n.summary)}" Icon="${W}" IconIndex="0" Advertise="yes" />`),q.push(`${S} </File>`)):q.push(`${S} <File Id="${N}" Name="${H}" Source="${xmlEscape(C.source)}" KeyPath="yes" />`),q.push(`${S}</Component>`)}for(let n of[...t.children.values()].sort((t,n)=>t.name<n.name?-1:1)){let t=claim(msiIdentifier(`d`,n.path),`the directory ${n.path}`);q.push(`${S}<Directory Id="${t}" Name="${xmlEscape(n.name)}">`),emitDir(n,`${S} `),q.push(`${S}</Directory>`)}};if(emitDir(directoryTree(t.files),` `),Y.length===0)throw Error("gjsify ship: the windows payload is empty, so there is nothing for an `.msi` to install.");if(!X||Z===void 0)throw Error(`gjsify ship: the windows payload carries no "${I}" at the root of the program directory, so the installer would have nothing to point a Start-Menu shortcut at — an application a user installs and
1160
1160
  cannot start. \`windows-dir\` puts the launcher there; a payload without one is a stage assembled for another layout.`);let te=n.homepage===void 0?[]:[` <Property Id="ARPURLINFOABOUT" Value="${xmlEscape(n.homepage)}" />`];return[`<?xml version="1.0" encoding="utf-8"?>`,"<!-- Generated by `gjsify ship` (ADR 0024 stage 5). Do not edit; edit utils/ship/msi.ts. -->",`<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">`,` <Product Id="${msiProductCode(n,C)}" Name="${xmlEscape(n.name)}" Language="1033" Version="${N}" Manufacturer="${xmlEscape(F)}" UpgradeCode="${msiUpgradeCode(n)}">`,` <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Manufacturer="${xmlEscape(F)}" Description="${xmlEscape(n.summary)}" />`,` <MajorUpgrade DowngradeErrorMessage="A newer version of ${xmlEscape(n.name)} is already installed." />`,` <Media Id="1" Cabinet="app.cab" EmbedCab="yes" />`,` <Icon Id="${W}" SourceFile="${xmlEscape(Z)}" />`,` <Property Id="ARPPRODUCTICON" Value="${W}" />`,...te,` <Directory Id="TARGETDIR" Name="SourceDir">`,` <Directory Id="ProgramFiles64Folder">`,` <Directory Id="INSTALLDIR" Name="${xmlEscape(S)}">`,...q,` </Directory>`,` </Directory>`,` <Directory Id="ProgramMenuFolder" />`,` </Directory>`,` <Feature Id="Main" Title="${xmlEscape(n.name)}" Level="1">`,...Y.map(t=>` <ComponentRef Id="${t}" />`),` </Feature>`,` </Product>`,`</Wix>`,``].join(`
1161
- `)}function msiBackendFor(t){if(t===`linux`)return`wixl`;if(t===`win32`)return`wix3`;throw Error(`gjsify ship: no MSI compiler is wired for ${t}. \`wixl\` (msitools) is used on linux and WiX v3 on win32; assembly is not host-bound, so \`gjsify ship windows --stage\` here and \`gjsify ship --from-stage <dir> --target msi\` there is the way across.`)}async function buildMsi(t){let n=msiBackendFor(t.host??process.platform);mkdirSync(t.workDir,{recursive:!0});let S=wn(t.workDir,`${t.settings.binaryName}.wxs`);if(writeFileSync(S,renderWxs(t)),n===`wixl`)return await run(`wixl`,[`-a`,t.archLabel,`-o`,t.target,S],t),S;let C=wn(t.workDir,`obj`);return rmSync(C,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(C,{recursive:!0}),await run(`candle.exe`,[`-nologo`,`-arch`,t.archLabel,`-out`,`${C}\\`,S],t),await run(`light.exe`,[`-nologo`,`-out`,t.target,wn(C,`${t.settings.binaryName}.wixobj`)],t),S}async function run(t,n,S){S.verbose&&ge.log(`[gjsify ship] ${t} ${n.join(` `)}`);let C=await spawnToCompletion(t,[...n],{completion:`return`,cwd:S.workDir,stdio:`inherit`,notFound:()=>Error(`gjsify ship: ${t} not found. It is the MSI compiler for this host — Fedora: \`sudo dnf install msitools\`, Debian/Ubuntu: \`sudo apt install msitools\`, Windows: WiX Toolset v3.14 with its \`bin\` directory on PATH.`)});if(C.code!==0)throw Error(`gjsify ship: ${t} failed with ${describeExit(C)}.`)}var OH,kH,AH,jH=__esmMin(()=>{_e(),Qc(),Rd(),Pn(),V_(),uV(),DV(),OH=`7b3a1f6e-0c4d-4a2b-9e51-3d8c6f2a0b14`,kH=/[<>:"/\\|?*;]/,AH=`root`});function getCrcTable(){if(RH!==null)return RH;let t=new Uint32Array(256);for(let n=0;n<256;n++){let S=n;for(let t=0;t<8;t++)S=S&1?3988292384^S>>>1:S>>>1;t[n]=S>>>0}return RH=t,t}function crc32(t){let n=getCrcTable(),S=4294967295;for(let C=0;C<t.length;C++)S=n[(S^t[C])&255]^S>>>8;return(S^4294967295)>>>0}function dosDateTime(t){let n=new Date(Math.max(t,315532800)*1e3);return{date:(n.getUTCFullYear()-1980&127)<<9|n.getUTCMonth()+1<<5|n.getUTCDate(),time:n.getUTCHours()<<11|n.getUTCMinutes()<<5|Math.floor(n.getUTCSeconds()/2)}}function buildZip(t,n){let S=[...t].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path)),{date:C,time:N}=dosDateTime(n),F=new TextEncoder;if(S.length>65535)throw Error(`gjsify ship: this archive would hold ${S.length} entries and a non-ZIP64 central directory records the count in 16 bits, so it would silently wrap. Nothing here writes ZIP64 yet; the payload has to shrink, or this writer has to grow the ZIP64 records.`);let I=new Writer,H=new Writer,W=0;for(let t of S){let n=F.encode(t.path),S=crc32(t.data),q=t.data.byteLength,Y=I.offset;if(Y>4294967295||q>4294967295)throw Error(`gjsify ship: ${t.path} would push this archive past 4 GiB, which a non-ZIP64 header records in 32 bits and therefore truncates. Nothing here writes ZIP64 yet.`);I.u32(MH),I.u16(LH),I.u16(2048),I.u16(FH),I.u16(N),I.u16(C),I.u32(S),I.u32(q),I.u32(q),I.u16(n.byteLength),I.u16(0),I.bytes(n),I.bytes(t.data),H.u32(NH),H.u16(IH),H.u16(LH),H.u16(2048),H.u16(FH),H.u16(N),H.u16(C),H.u32(S),H.u32(q),H.u32(q),H.u16(n.byteLength),H.u16(0),H.u16(0),H.u16(0),H.u16(0),H.u32(((32768|t.mode&4095)>>>0)*65536),H.u32(Y),H.bytes(n),W+=1}let q=H.finish(),Y=new Writer;Y.bytes(I.finish());let X=Y.offset;return Y.bytes(q),Y.u32(PH),Y.u16(0),Y.u16(0),Y.u16(W),Y.u16(W),Y.u32(q.byteLength),Y.u32(X),Y.u16(0),Y.finish()}function zipEntriesFromPayload(t,n=``){let S=n===``?``:`${n}/`;return t.map(t=>({path:`${S}${t.path}`,mode:t.mode,data:t.data}))}var MH,NH,PH,FH,IH,LH,RH,Writer,zH=__esmMin(()=>{MH=67324752,NH=33639248,PH=101010256,FH=0,IH=788,LH=20,RH=null,Writer=class{parts=[];length=0;get offset(){return this.length}u16(t){this.push(new Uint8Array([t&255,t>>>8&255]))}u32(t){this.push(new Uint8Array([t&255,t>>>8&255,t>>>16&255,t>>>24&255]))}bytes(t){this.push(t)}push(t){this.parts.push(t),this.length+=t.byteLength}finish(){let t=new Uint8Array(this.length),n=0;for(let S of this.parts)t.set(S,n),n+=S.byteLength;return t}}});function entryEvidence(t){let n=new Set,S=new Set;return walkModuleAst(t,t=>{let C=importedSpecifier(t);C!==null&&(C.startsWith(`gi://`)||BH.has(C)?n.add(C):C.startsWith(`node:`)&&S.add(C))}),{gi:[...n].sort(),node:[...S].sort()}}function assertEntryRunsUnder(t){let n=entryEvidence(t.source),S=t.interpreter===`node`?n.gi:n.node;if(S.length===0)return;let C=t.interpreter===`node`?`gjs`:`node`,N=t.interpreter===`gjs`?`GJS's loader refuses it: ImportError, "Unsupported URI scheme for importing: node"`:S.some(t=>t.startsWith(`gi://`))?`node's ESM loader refuses it: ERR_UNSUPPORTED_ESM_URL_SCHEME, "Only URLs with a scheme in: file, data, and node are supported by the default ESM loader"`:`node's ESM loader refuses it: ERR_MODULE_NOT_FOUND — a GJS built-in is not a package`,F=S.slice(0,3).join(`, `),I=S.length>3?`, and ${S.length-3} more`:``;throw Error(`gjsify ship: this target execs \`${t.interpreter}\` (\`${t.appKey}\`), and the entry it would ship — ${t.entry} (\`${t.bundleKey}\`) — imports ${F}${I}.\n ${N}, before a line of application code runs.\n The artifact would be built, reported as built, and fail at launch on every machine.
1162
- Either ship this target the \`--app ${t.interpreter}\` build of the app — \`gjsify.ship.bundle.${t.layoutOs}\` selects the entry per target, the way \`gjsify.ship.app.${t.layoutOs}\` selects the runtime —\n or set \`gjsify.ship.app.${t.layoutOs}\` to "${C}" if this bundle is the one that should ship.`)}var BH,VH=__esmMin(()=>{oI(),BH=new Set([`system`,`gettext`])});function base64Encode(t){let n=``,S=32768;for(let C=0;C<t.length;C+=S)n+=String.fromCharCode(...t.subarray(C,C+S));return btoa(n)}function base64Decode(t){let n=atob(t),S=new Uint8Array(n.length);for(let t=0;t<n.length;t++)S[t]=n.charCodeAt(t);return S}var HH=__esmMin(()=>{});function toPackSettings(t){return{binaryName:t.binaryName,appId:t.appId,name:t.name,version:t.version,release:t.release,maintainer:t.maintainer,summary:t.summary,description:t.description,license:t.license,...t.homepage===void 0?{}:{homepage:t.homepage},section:t.section,group:t.group,extraDepends:t.extraDepends,typelibPackages:t.typelibPackages,app:t.app,minGjsVersion:t.minGjsVersion,minNodeVersion:t.minNodeVersion,flatpak:t.flatpak}}function stageManifestPath(t){return wn(t,UH)}function formatTarget(t){return`${t.os}-${t.arch}`}function writeStageManifest(t){let n={};for(let S of t.formats)n[S.id]=(t.overlay.get(S.id)??[]).map(t=>{if(t.source.kind===`text`)return{path:t.path,mode:t.mode,text:t.source.text};if(t.source.kind===`bytes`)return{path:t.path,mode:t.mode,base64:base64Encode(t.source.data)};throw Error(`gjsify ship: internal error — the ${S.id} overlay entry ${t.path} is a file reference, and a stage manifest may only carry rendered bytes. Render it in \`planOverlay\` instead.`)});let S={schema:6,tool:{name:`@gjsify/cli`,version:cliVersion()},target:{os:t.settings.layoutOs,arch:t.settings.arch},formats:t.formats.map(t=>t.id),mtime:t.mtime,namespaces:[...t.namespaces],optionalNamespaces:[...t.optionalNamespaces??[]],settings:toPackSettings(t.settings),staged:t.staged.map(n=>({path:n.path,mode:n.mode,bytes:statSync(wn(t.stageDir,n.path.split(`/`).join(jn))).size})),overlay:n};return writeFileSync(stageManifestPath(t.stageDir),`${JSON.stringify(S,null,2)}\n`),S}function readStageManifest(t){let n=stageManifestPath(t);if(!existsSync(n))throw Error(`gjsify ship: ${t} has no ${UH}, so it is not a stage this command can pack. A stage is produced by \`gjsify ship --stage\`, which writes that file at the stage root beside the payload. If you pointed --from-stage at a project's \`ship/\` directory, point it at \`ship/stage/\` instead.`);let S;try{S=JSON.parse(readFileSync(n,`utf-8`))}catch(t){throw Error(`gjsify ship: ${n} is not readable JSON (${t.message}). Re-run the \`--stage\` phase; a truncated manifest means the stage transfer was truncated too.`)}if(typeof S!=`object`||!S||Array.isArray(S))throw Error(`gjsify ship: ${n} is not a JSON object. Re-run the \`--stage\` phase.`);let C=S,N=C.schema;if(typeof N!=`number`||!Number.isInteger(N))throw Error(`gjsify ship: ${n} has no integer \`schema\` field, so it was not written by \`gjsify ship --stage\`. Re-run the \`--stage\` phase.`);if(N>6)throw Error(`gjsify ship: ${n} declares schema ${N} and this gjsify understands 6. The stage was assembled by a newer gjsify: upgrade this one (\`gjsify self-update\`), or re-run the \`--stage\` phase with this version. A manifest from the future is refused rather than partially read, because an unknown field could be the one that decides a file's mode.`);if(N<6)throw Error(`gjsify ship: ${n} declares schema ${N} and this gjsify understands 6. Re-run the \`--stage\` phase with this gjsify. A stage is a short-lived intermediate between two jobs of one run, not an archive, so no migration is kept for it.`);let at=t=>`${n} → ${t}`,F=record(C.tool,at(`tool`)),I=record(C.target,at(`target`)),H={schema:N,tool:{name:expectString(F.name,at(`tool.name`)),version:expectString(F.version,at(`tool.version`))},target:{os:expectLayoutOs(expectString(I.os,at(`target.os`)),at(`target.os`)),arch:expectString(I.arch,at(`target.arch`))},formats:expectArray(C.formats,at(`formats`)).map((t,n)=>{let S=expectString(t,at(`formats[${n}]`));if(!TH.includes(S))throw Error(`gjsify ship: ${at(`formats[${n}]`)} is "${S}", which this gjsify does not know. Known formats: ${TH.join(`, `)}.`);return S}),mtime:expectInteger(C.mtime,at(`mtime`)),namespaces:expectArray(C.namespaces,at(`namespaces`)).map((t,n)=>expectString(t,at(`namespaces[${n}]`))),...C.optionalNamespaces===void 0?{}:{optionalNamespaces:expectArray(C.optionalNamespaces,at(`optionalNamespaces`)).map((t,n)=>expectString(t,at(`optionalNamespaces[${n}]`)))},settings:readPackSettings(record(C.settings,at(`settings`)),at(`settings`)),staged:expectArray(C.staged,at(`staged`)).map((t,n)=>{let S=record(t,at(`staged[${n}]`));return{path:expectString(S.path,at(`staged[${n}].path`)),mode:expectInteger(S.mode,at(`staged[${n}].mode`)),bytes:expectInteger(S.bytes,at(`staged[${n}].bytes`))}}),overlay:{}};if(H.staged.length===0)throw Error(`gjsify ship: ${at(`staged`)} is empty, so this stage describes no payload. A stage always carries at least the launcher its plan named. Re-run the \`--stage\` phase; a stage that lost its plan cannot be packed into anything but an empty package.`);let W=record(C.overlay,at(`overlay`));for(let t of H.formats)H.overlay[t]=expectArray(W[t],at(`overlay.${t}`)).map((n,S)=>{let C=record(n,at(`overlay.${t}[${S}]`)),N=at(`overlay.${t}[${S}]`);if(C.text===void 0==(C.base64===void 0))throw Error(`gjsify ship: ${N} must carry exactly one of \`text\` and \`base64\`. An overlay entry is either rendered text or rendered bytes; an entry with neither would pack an empty file at a path the format requires content at.`);return{path:expectString(C.path,at(`overlay.${t}[${S}].path`)),mode:expectInteger(C.mode,at(`overlay.${t}[${S}].mode`)),...C.text===void 0?{base64:expectString(C.base64,at(`overlay.${t}[${S}].base64`))}:{text:expectString(C.text,at(`overlay.${t}[${S}].text`))}}});return H}function expectLayoutOs(t,n){try{return layoutForOs(t).os}catch{let S=cV.map(t=>sV[t].os).join(`, `);throw Error(`gjsify ship: ${n} is "${t}", which is not a layout this gjsify can pack. It carries the \`process.platform\` spelling and only that — ${S}, so \`win32\` and never \`windows\`. A stage holds exactly one OS's layout and every path in it has that OS's shape, so there is nothing to pack here. Re-run the \`--stage\` phase.`)}}function overlayFiles(t,n){return(t.overlay[n]??[]).map(t=>({path:t.path,mode:t.mode,source:t.base64===void 0?{kind:`text`,text:t.text??``}:{kind:`bytes`,data:base64Decode(t.base64)}}))}function assertExpectedTarget(t,n){if(n===void 0)return;let S=formatTarget(t.target);if(n!==S)throw Error(`gjsify ship: --expect-target ${n} but this stage was assembled for ${S}. The stage records the target its \`--arch\` resolved to at stage time, so this is a stage from another matrix leg: download the artifact belonging to ${n}, or drop --expect-target if packing this one is what you meant.`)}function assertFormatsStaged(t,n){let S=n.filter(n=>!t.formats.includes(n.id)).map(t=>t.id);if(S.length!==0)throw Error(`gjsify ship: this stage was assembled for ${t.formats.length===0?`no format at all`:t.formats.join(`, `)}, and --target names ${S.join(`, `)}. Phase one renders each format's overlay — rpm wants the licence at \`share/licenses/<pkg>/LICENSE\`, deb wants a machine-readable copyright at \`share/doc/<pkg>/copyright\` — so a format the stage never saw would pack without it, and Debian Policy § 12.5 makes that a broken package. Re-run \`gjsify ship --stage --target ${[...t.formats,...S].join(`,`)}\` on the assembling host.`)}function resolveStageMtime(t,n=process.env){let S=n.SOURCE_DATE_EPOCH;return S===void 0||Number(S)===t.mtime?{mtime:t.mtime,warnings:[]}:{mtime:t.mtime,warnings:[`SOURCE_DATE_EPOCH is ${S} here and this stage was stamped ${t.mtime}. The stage's stamp wins, because changing it would make this artifact differ from the same stage packed on the assembling host. Set the same value in both jobs, or set it in neither.`]}}function warnOnToolSkew(t){let n=cliVersion();return t.tool.version===n?[]:[`this stage was assembled by ${t.tool.name} ${t.tool.version} and is being packed by ${n}. Both phases run the same packer, so a version difference can change the artifact's bytes. Pin both jobs to one gjsify version.`]}function readPackSettings(t,n){let field=t=>`${n}.${t}`,S=record(t.extraDepends,field(`extraDepends`)),C=record(t.typelibPackages,field(`typelibPackages`));return{binaryName:expectString(t.binaryName,field(`binaryName`)),appId:expectString(t.appId,field(`appId`)),name:expectString(t.name,field(`name`)),version:expectString(t.version,field(`version`)),release:expectString(t.release,field(`release`)),maintainer:expectString(t.maintainer,field(`maintainer`)),summary:expectString(t.summary,field(`summary`)),description:expectArray(t.description,field(`description`)).map((t,n)=>expectString(t,field(`description[${n}]`))),license:expectString(t.license,field(`license`)),...t.homepage===void 0?{}:{homepage:expectString(t.homepage,field(`homepage`))},section:expectString(t.section,field(`section`)),group:expectString(t.group,field(`group`)),extraDepends:{deb:expectArray(S.deb??[],field(`extraDepends.deb`)).map((t,n)=>expectString(t,field(`extraDepends.deb[${n}]`))),rpm:expectArray(S.rpm??[],field(`extraDepends.rpm`)).map((t,n)=>expectString(t,field(`extraDepends.rpm[${n}]`)))},typelibPackages:Object.fromEntries(Object.entries(C).map(([t,n])=>{let S=record(n,field(`typelibPackages.${t}`));return[t,{deb:expectString(S.deb,field(`typelibPackages.${t}.deb`)),rpm:expectString(S.rpm,field(`typelibPackages.${t}.rpm`))}]})),app:expectApp(t.app,field(`app`)),minGjsVersion:expectString(t.minGjsVersion,field(`minGjsVersion`)),minNodeVersion:expectString(t.minNodeVersion,field(`minNodeVersion`)),flatpak:readFlatpakSettings(record(t.flatpak,field(`flatpak`)),field(`flatpak`))}}function readFlatpakSettings(t,n){let field=t=>`${n}.${t}`,strings=(t,n)=>expectArray(t,field(n)).map((t,S)=>expectString(t,field(`${n}[${S}]`)));return{runtime:expectString(t.runtime,field(`runtime`)),runtimeVersion:expectString(t.runtimeVersion,field(`runtimeVersion`)),sdk:expectString(t.sdk,field(`sdk`)),branch:expectString(t.branch,field(`branch`)),sdkExtensions:strings(t.sdkExtensions,`sdkExtensions`),appendPath:strings(t.appendPath,`appendPath`),finishArgs:strings(t.finishArgs,`finishArgs`),cleanup:strings(t.cleanup,`cleanup`)}}function record(t,n){if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`gjsify ship: ${n} must be an object. Re-run the \`--stage\` phase.`);return t}function expectArray(t,n){if(!Array.isArray(t))throw Error(`gjsify ship: ${n} must be an array. Re-run the \`--stage\` phase.`);return t}function expectApp(t,n){if(t===`gjs`||t===`node`)return t;throw Error(`gjsify ship: ${n} must be "gjs" or "node", got ${JSON.stringify(t)}.`)}function expectString(t,n){if(typeof t!=`string`)throw Error(`gjsify ship: ${n} must be a string. Re-run the \`--stage\` phase.`);return t}function expectInteger(t,n){if(typeof t!=`number`||!Number.isInteger(t)||t<0)throw Error(`gjsify ship: ${n} must be a non-negative integer. Re-run the \`--stage\` phase. (Modes are decimal here — JSON has no octal literal, so 0o755 is written 493.)`);return t}var UH,WH=__esmMin(()=>{Rd(),Pn(),HH(),nh(),DH(),uV(),UH=`.gjsify-ship-stage.json`});function writeStage(t,n){for(let t of n)if(t.path===`.gjsify-ship-stage.json`)throw Error(`gjsify ship: a payload file may not be called \`${UH}\` — that name belongs to the stage manifest, which sits at the stage root beside the payload and carries what the packing host needs (ADR 0024 § A2). Rename the \`gjsify.ship.extraFiles\` destination.`);rmSync(t,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(t,{recursive:!0});for(let S of n){let n=wn(t,S.path.split(`/`).join(jn));mkdirSync(En(n),{recursive:!0});let C;switch(S.source.kind){case`text`:C=new TextEncoder().encode(S.source.text);break;case`file`:C=new Uint8Array(readFileSync(S.source.path));break;case`bytes`:C=S.source.data;break;default:{let t=S.source;throw Error(`gjsify ship: no writer for the "${JSON.stringify(t)}" source kind.`)}}writeFileSync(n,C),chmodSync(n,S.mode)}}function readStage(t,n){let S=new Map(n.map(t=>[t.path,t])),C=new Map;for(let n of t)for(let t of listFilesRecursive(n)){if(t===`.gjsify-ship-stage.json`)continue;let N=S.get(t);if(N===void 0)throw Error(`gjsify ship: ${wn(n,t.split(`/`).join(jn))} is in the stage and not in its manifest, so nothing knows what mode to give it. Every payload file takes its mode from the plan, never from the filesystem, so a file that arrived some other way would be packed 0644 — unrunnable if it is a program. Remove it, or add it through \`gjsify.ship.extraFiles\` and re-run the \`--stage\` phase.`);let F=new Uint8Array(readFileSync(wn(n,t.split(`/`).join(jn))));if(N.bytes!==void 0&&N.bytes!==F.byteLength)throw Error(`gjsify ship: ${t} is ${F.byteLength} bytes in the stage and ${N.bytes} in its manifest. The stage arrived truncated or was edited after it was assembled. Re-upload it, or re-run the \`--stage\` phase.`);C.set(t,{path:t,mode:N.mode,data:F})}let N=n.filter(t=>!C.has(t.path)).map(t=>t.path);if(N.length>0)throw Error(`gjsify ship: the stage manifest lists ${N.length} file(s) the stage does not contain: ${N.slice(0,5).join(`, `)}${N.length>5?`, …`:``}. A payload has to be complete before it is packed — both formats would pack the rest without complaint and install a package that cannot start. Re-run the \`--stage\` phase, and check that whatever moved the stage between hosts copied every file (an artifact upload that drops empty files or dotfiles is the usual cause).`);return[...C.values()].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}function writePayload(t,n,S){let C=S===``?``:`${S}/`;rmSync(t,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(t,{recursive:!0});for(let N of n){if(!N.path.startsWith(C))throw Error(`gjsify ship: ${N.path} is outside ${S||`the artifact`}, which this artifact IS — so there is nowhere inside it for the file to go. A payload file that escaped the bundle would ship beside it, unsigned and unfound.`);let n=wn(t,N.path.slice(C.length).split(`/`).join(jn));mkdirSync(En(n),{recursive:!0}),writeFileSync(n,N.data),chmodSync(n,N.mode)}}function directorySize(t){let n=0;for(let S of listFilesRecursive(t))n+=statSync(wn(t,S.split(`/`).join(jn))).size;return n}var GH=__esmMin(()=>{Rd(),Pn(),VV(),WH()});function resolveSignPlan(t){let n=KH[t.layoutOs];if(n===void 0){if(t.flag!==void 0)throw Error(`gjsify ship: --sign has nothing to sign in the ${t.layoutOs} layout. A .deb and an .rpm carry no per-file signature — the artifact is signed as a whole by the repository that serves it (\`debsigs\`, \`rpmsign\`), with that repository's key and not with a build-time identity. Drop --sign, or assemble the darwin or windows layout.`);return{kind:`unsupported`}}let S=t.config?.[t.layoutOs]?.identity,[C,N]=t.flag===void 0?[S,`config`]:[t.flag,`flag`];return C===void 0||C===``?{kind:`skip`,message:`${C===``?`an empty identity was ${N===`flag`?`passed to --sign`:`set in \`${n.configKey}\``}`:`no identity was given`} — skipping ${n.tool}. An unsigned artifact is the default path and a legitimate deliverable (ADR 0024 § A13). Pass \`--sign <identity>\` or set \`${n.configKey}\` to sign; \`--sign -\` signs ad-hoc and needs no developer identity.`}:{kind:`sign`,identity:C,signer:n,source:N}}function assertHostCanSign(t){let n=process.platform;if(!t.signOn.includes(n))throw Error(`gjsify ship: signing the ${t.layoutOs} layout needs ${t.tool}, which runs on ${t.signOn.join(`, `)} and this host is ${n}. Assembly is not host-bound — \`gjsify ship <os> --stage\` here, then \`gjsify ship --from-stage <dir> --sign <identity>\` on a host that has both the tool and the identity (ADR 0024 § A1, § A14).`);if(!isOnPath(t.tool))throw Error(`gjsify ship: --sign was given and \`${t.tool}\` is not on PATH, so nothing can make the signature — ${t.installHint}. Dropping --sign produces an unsigned artifact, which is a legitimate output (ADR 0024 § A13); silently producing one while --sign was asked for is not.`)}function partitionSignedFileSet(t){let n=new Set(t.planned),S=new Set(t.arrived),C=[...S].filter(t=>!n.has(t)).sort(),N=t.sealPrefix;return{sealed:N===void 0?[]:C.filter(t=>t.startsWith(N)),unexpected:N===void 0?C:C.filter(t=>!t.startsWith(N)),removed:[...n].filter(t=>!S.has(t)).sort()}}async function signPayload(t){let{payload:n,signer:S,workDir:C}=t;writePayload(C,n,``);let N=t.identity===`-`,F,I=S.entitlements(N);I.length>0&&(mkdirSync(En(t.entitlementsPath),{recursive:!0}),writeFileSync(t.entitlementsPath,renderEntitlements(I)),F=t.entitlementsPath);let run=async(n,I)=>{let H=S.args({identity:t.identity,file:n,adhoc:N,...F?{entitlements:F}:{}});t.verbose&&t.log(`${S.tool} ${H.join(` `)}`);let W=await spawnToCompletion(S.tool,H,{completion:`return`,cwd:C,stdio:`inherit`,notFound:()=>Error(`gjsify ship: \`${S.tool}\` is not on PATH — ${S.installHint}.`)});if(W.code!==0)throw Error(`gjsify ship: ${S.tool} failed on ${I} with ${describeExit(W)}. Nothing is packed from a payload whose signature failed: an artifact that is half signed installs and is refused at first launch, which is worse than not shipping.`)},H=n.filter(t=>classifyBinary(t.data)===S.signs);if(H.length===0&&!S.sealsBundle)return t.log(`nothing in this payload is a ${S.signs===`macho`?`Mach-O`:`PE`} image, so ${S.tool} signed 0 file(s). The artifact carries no signature.`),[...n];for(let t of H)await run(wn(C,t.path.split(`/`).join(jn)),t.path);let W;if(S.sealsBundle){if(t.bundleRoot===``)throw Error(`gjsify ship: the ${S.layoutOs} signer seals a bundle and this layout has no root to seal. \`Layout.root\` is what names the artifact directory; a signer that sealed the whole stage would sign the payload of every other format beside it.`);W=S.sealAddPrefix(t.bundleRoot),await run(wn(C,t.bundleRoot.split(`/`).join(jn)),`${t.bundleRoot} (bundle seal)`)}let q=partitionSignedFileSet({arrived:listFilesRecursive(C),planned:n.map(t=>t.path),...W===void 0?{}:{sealPrefix:W}});if(q.unexpected.length>0||q.removed.length>0)throw Error(`gjsify ship: ${S.tool} changed the payload's file set — ${q.unexpected.length} added (${q.unexpected.slice(0,3).join(`, `)||`—`}), ${q.removed.length} removed (${q.removed.slice(0,3).join(`, `)||`—`}). Signing is a mutation of the files that are already in the payload (ADR 0024 § A4), plus exactly the seal's own directory${W===void 0?``:` (\`${W}\`)`}.`);let Y=q.sealed;t.log(`${S.tool} signed ${H.length} of ${n.length} payload file(s) as ${N?"ad-hoc (`-`)":`\`${t.identity}\``}${W===void 0?``:` and sealed ${t.bundleRoot} (${Y.length} seal file(s))`} — ${S.gap}.`);let read=t=>new Uint8Array(readFileSync(wn(C,t.split(`/`).join(jn))));return[...n.map(t=>({path:t.path,mode:t.mode,data:read(t.path)})),...Y.map(t=>({path:t,mode:420,data:read(t)}))].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}function resolveNotaryPlan(t){let n=qH[t.layoutOs];if(n===void 0){if(t.flag!==void 0)throw Error(`gjsify ship: --notarize has no meaning in the ${t.layoutOs} layout. Notarisation is Apple's pre-clearance of a signed artifact and nothing else asks for it — Windows SmartScreen accrues reputation per file hash instead (ADR 0024 § A5).`);return{kind:`unsupported`}}if(t.flag===void 0||t.flag===``)return{kind:`skip`,message:`no notarisation credential was given — skipping ${n.tool} notarytool. Pass \`--notarize <keychain-profile>\`, naming a profile a prior \`notarytool store-credentials\` put in this host's keychain.`};if(t.sign.kind!==`sign`)throw Error("gjsify ship: --notarize was given without an identity to sign with. Notarisation is a check ON a signature, so submitting an unsigned artifact has nothing to clear. Pass `--sign <identity>` as well, or drop --notarize.");return{kind:`notarize`,credential:t.flag,notary:n}}async function notarizeArtifact(t){let{notary:n,credential:S}=t.plan,C=process.platform;if(!n.notarizeOn.includes(C))throw Error(`gjsify ship: notarising the ${n.layoutOs} layout needs ${n.tool}, which runs on ${n.notarizeOn.join(`, `)} and this host is ${C}.`);let N=n.args(S,t.artifact);t.verbose&&t.log(`${n.tool} ${N.join(` `)}`);let F=await spawnToCompletion(n.tool,N,{completion:`return`,stdio:`inherit`,notFound:()=>Error(`gjsify ship: \`${n.tool}\` is not on PATH — ${n.installHint}.`)});if(F.code!==0)throw Error(`gjsify ship: ${n.tool} notarytool failed with ${describeExit(F)}.`);t.log(`${n.tool} notarytool accepted ${t.artifact}.`)}async function stapleArtifact(t){let n=[`stapler`,`staple`,t.artifact];t.verbose&&t.log(`${t.notary.tool} ${n.join(` `)}`);let S=await spawnToCompletion(t.notary.tool,n,{completion:`return`,stdio:`inherit`,notFound:()=>Error(`gjsify ship: \`${t.notary.tool}\` is not on PATH — ${t.notary.installHint}.`)});if(S.code!==0)throw Error(`gjsify ship: ${t.notary.tool} stapler failed with ${describeExit(S)}. The artifact is notarised and NOT stapled, which means every launch asks Gatekeeper to check online — and fails closed on a machine with no network. Re-run the finish phase; \`stapler\` requires internet access and the ticket may not have propagated yet.`);t.log(`${t.notary.tool} stapler attached the ticket to ${t.artifact}.`)}var KH,qH,JH=__esmMin(()=>{Rd(),Pn(),vF(),V_(),VV(),TV(),iV(),GH(),KH={darwin:{layoutOs:`darwin`,tool:`codesign`,signOn:[`darwin`],installHint:"install the Xcode Command Line Tools (`xcode-select --install`) on a macOS host",signs:`macho`,args:({identity:t,file:n,entitlements:S,adhoc:C})=>[`--force`,`--sign`,t,`--options`,`runtime`,...S===void 0?[]:[`--entitlements`,S],...C?[]:[`--timestamp`],n],entitlements:t=>[`com.apple.security.cs.allow-jit`,`com.apple.security.cs.allow-unsigned-executable-memory`,`com.apple.security.cs.disable-executable-page-protection`,`com.apple.security.cs.allow-dyld-environment-variables`,...t?[`com.apple.security.cs.disable-library-validation`]:[]],sealsBundle:!0,sealAddPrefix:t=>`${t}/Contents/_CodeSignature/`,configKey:`gjsify.ship.sign.darwin.identity`,gap:"the images are signed and the bundle is sealed, and the seal survives both the `.zip` and the `.dmg` round trip; § A16 stands measured in ONE direction only — library validation refuses an ad-hoc-signed dylib, so the ad-hoc identity grants `disable-library-validation` while a named one does not, and no run in this repository has ever held the named one"},win32:{layoutOs:`win32`,tool:`signtool`,signOn:[`win32`],installHint:"install the Windows SDK (signtool.exe ships in its `bin/<version>/x64` directory)",signs:`pe`,args:({identity:t,file:n})=>[`sign`,`/n`,t,`/fd`,`sha256`,n],entitlements:()=>[],sealsBundle:!1,sealAddPrefix:()=>``,configKey:`gjsify.ship.sign.win32.identity`,gap:`no timestamp countersignature is requested, so the signature expires with the certificate (UNVERIFIED: no run in this repository has ever invoked signtool)`}},qH={darwin:{layoutOs:`darwin`,tool:`xcrun`,notarizeOn:[`darwin`],installHint:"install the Xcode Command Line Tools (`xcode-select --install`) on a macOS host",args:(t,n)=>[`notarytool`,`submit`,`--keychain-profile`,t,`--wait`,n]}}});function stagedFontDir(t,n){return`${t}/${pn.basename(SB.fonts)}/${n}`}function shellQuote(t){return`'${t.replace(/'/g,`'\\''`)}'`}function cmdQuote(t){let n=/["%!\r\n]/.exec(t);if(n!==null)throw Error(`gjsify ship: \`gjsify.ship.execArgs\` contains ${JSON.stringify(t)}, and cmd.exe has no way to pass ${JSON.stringify(n[0])} through a Windows launcher literally — \`%\` expands at parse time and \`"\` ends the quoted run. Move the value into the app (it can read it from its own config) or drop the character.`);return`"${t}"`}function renderLauncher(t,n,S,C={}){switch(S.name){case`linux`:return renderPrefixLauncher(t,n,S);case`darwin`:return renderAppBundleLauncher(t,n,S,C);case`windows`:return renderWindowsLauncher(t,n,S,C);default:{let t=S.name;throw Error(`gjsify ship: no launcher is wired for the "${String(t)}" layout.`)}}}function renderPrefixLauncher(t,n,S){let C=S.dirs(t),N=[`#!/bin/sh`,"# Generated by `gjsify ship` — do not edit.",`set -e`,`self=$(readlink -f "$0")`,`prefix=$(dirname "$(dirname "$self")")`,`XDG_DATA_DIRS="$prefix/${C.data}:\${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"`,`export XDG_DATA_DIRS`];if(t.typelibFiles.length>0){let t=`"$prefix"/${C.native}`;for(let n of[`GI_TYPELIB_PATH`,`LD_LIBRARY_PATH`])N.push(`${n}=${t}\${${n}:+:$${n}}`,`export ${n}`)}else if(Object.values(t.formatFiles).some(t=>t.typelibFiles.length>0)){let t=`"$prefix"/${C.native}`;N.push(`if [ -d ${t} ]; then`);for(let n of[`GI_TYPELIB_PATH`,`LD_LIBRARY_PATH`])N.push(` ${n}=${t}\${${n}:+:$${n}}`,` export ${n}`);N.push(`fi`)}return t.localeFiles.length>0&&N.push(`GJSIFY_LOCALE_DIR="$prefix"/${C.data}/locale`,`export GJSIFY_LOCALE_DIR`),t.fontFiles.length>0&&N.push(`GJSIFY_FONT_DIR="$prefix"/${stagedFontDir(C.data,t.appId)}`,`export GJSIFY_FONT_DIR`),N.push(`exec ${execLine(S,`"$prefix"/${C.bundle}/${n}`,t)} "$@"`,``),N.join(`
1161
+ `)}function msiBackendFor(t){if(t===`linux`)return`wixl`;if(t===`win32`)return`wix3`;throw Error(`gjsify ship: no MSI compiler is wired for ${t}. \`wixl\` (msitools) is used on linux and WiX v3 on win32; assembly is not host-bound, so \`gjsify ship windows --stage\` here and \`gjsify ship --from-stage <dir> --target msi\` there is the way across.`)}async function buildMsi(t){let n=msiBackendFor(t.host??process.platform);mkdirSync(t.workDir,{recursive:!0});let S=wn(t.workDir,`${t.settings.binaryName}.wxs`);if(writeFileSync(S,renderWxs(t)),n===`wixl`)return await run(`wixl`,[`-a`,t.archLabel,`-o`,t.target,S],t),S;let C=wn(t.workDir,`obj`);return rmSync(C,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(C,{recursive:!0}),await run(`candle.exe`,[`-nologo`,`-arch`,t.archLabel,`-out`,`${C}\\`,S],t),await run(`light.exe`,[`-nologo`,`-out`,t.target,wn(C,`${t.settings.binaryName}.wixobj`)],t),S}async function run(t,n,S){S.verbose&&ge.log(`[gjsify ship] ${t} ${n.join(` `)}`);let C=await spawnToCompletion(t,[...n],{completion:`return`,cwd:S.workDir,stdio:`inherit`,notFound:()=>Error(`gjsify ship: ${t} not found. It is the MSI compiler for this host — Fedora: \`sudo dnf install msitools\`, Debian/Ubuntu: \`sudo apt install msitools\`, Windows: WiX Toolset v3.14 with its \`bin\` directory on PATH.`)});if(C.code!==0)throw Error(`gjsify ship: ${t} failed with ${describeExit(C)}.`)}var NH,PH,FH,IH=__esmMin(()=>{_e(),Qc(),Rd(),Pn(),V_(),hV(),MV(),NH=`7b3a1f6e-0c4d-4a2b-9e51-3d8c6f2a0b14`,PH=/[<>:"/\\|?*;]/,FH=`root`});function getCrcTable(){if(UH!==null)return UH;let t=new Uint32Array(256);for(let n=0;n<256;n++){let S=n;for(let t=0;t<8;t++)S=S&1?3988292384^S>>>1:S>>>1;t[n]=S>>>0}return UH=t,t}function crc32(t){let n=getCrcTable(),S=4294967295;for(let C=0;C<t.length;C++)S=n[(S^t[C])&255]^S>>>8;return(S^4294967295)>>>0}function dosDateTime(t){let n=new Date(Math.max(t,315532800)*1e3);return{date:(n.getUTCFullYear()-1980&127)<<9|n.getUTCMonth()+1<<5|n.getUTCDate(),time:n.getUTCHours()<<11|n.getUTCMinutes()<<5|Math.floor(n.getUTCSeconds()/2)}}function buildZip(t,n){let S=[...t].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path)),{date:C,time:N}=dosDateTime(n),F=new TextEncoder;if(S.length>65535)throw Error(`gjsify ship: this archive would hold ${S.length} entries and a non-ZIP64 central directory records the count in 16 bits, so it would silently wrap. Nothing here writes ZIP64 yet; the payload has to shrink, or this writer has to grow the ZIP64 records.`);let I=new Writer,H=new Writer,W=0;for(let t of S){let n=F.encode(t.path),S=crc32(t.data),q=t.data.byteLength,Y=I.offset;if(Y>4294967295||q>4294967295)throw Error(`gjsify ship: ${t.path} would push this archive past 4 GiB, which a non-ZIP64 header records in 32 bits and therefore truncates. Nothing here writes ZIP64 yet.`);I.u32(LH),I.u16(HH),I.u16(2048),I.u16(BH),I.u16(N),I.u16(C),I.u32(S),I.u32(q),I.u32(q),I.u16(n.byteLength),I.u16(0),I.bytes(n),I.bytes(t.data),H.u32(RH),H.u16(VH),H.u16(HH),H.u16(2048),H.u16(BH),H.u16(N),H.u16(C),H.u32(S),H.u32(q),H.u32(q),H.u16(n.byteLength),H.u16(0),H.u16(0),H.u16(0),H.u16(0),H.u32(((32768|t.mode&4095)>>>0)*65536),H.u32(Y),H.bytes(n),W+=1}let q=H.finish(),Y=new Writer;Y.bytes(I.finish());let X=Y.offset;return Y.bytes(q),Y.u32(zH),Y.u16(0),Y.u16(0),Y.u16(W),Y.u16(W),Y.u32(q.byteLength),Y.u32(X),Y.u16(0),Y.finish()}function zipEntriesFromPayload(t,n=``){let S=n===``?``:`${n}/`;return t.map(t=>({path:`${S}${t.path}`,mode:t.mode,data:t.data}))}var LH,RH,zH,BH,VH,HH,UH,Writer,WH=__esmMin(()=>{LH=67324752,RH=33639248,zH=101010256,BH=0,VH=788,HH=20,UH=null,Writer=class{parts=[];length=0;get offset(){return this.length}u16(t){this.push(new Uint8Array([t&255,t>>>8&255]))}u32(t){this.push(new Uint8Array([t&255,t>>>8&255,t>>>16&255,t>>>24&255]))}bytes(t){this.push(t)}push(t){this.parts.push(t),this.length+=t.byteLength}finish(){let t=new Uint8Array(this.length),n=0;for(let S of this.parts)t.set(S,n),n+=S.byteLength;return t}}});function entryEvidence(t){let n=new Set,S=new Set;return walkModuleAst(t,t=>{let C=importedSpecifier(t);C!==null&&(C.startsWith(`gi://`)||GH.has(C)?n.add(C):C.startsWith(`node:`)&&S.add(C))}),{gi:[...n].sort(),node:[...S].sort()}}function assertEntryRunsUnder(t){let n=entryEvidence(t.source),S=t.interpreter===`node`?n.gi:n.node;if(S.length===0)return;let C=t.interpreter===`node`?`gjs`:`node`,N=t.interpreter===`gjs`?`GJS's loader refuses it: ImportError, "Unsupported URI scheme for importing: node"`:S.some(t=>t.startsWith(`gi://`))?`node's ESM loader refuses it: ERR_UNSUPPORTED_ESM_URL_SCHEME, "Only URLs with a scheme in: file, data, and node are supported by the default ESM loader"`:`node's ESM loader refuses it: ERR_MODULE_NOT_FOUND — a GJS built-in is not a package`,F=S.slice(0,3).join(`, `),I=S.length>3?`, and ${S.length-3} more`:``;throw Error(`gjsify ship: this target execs \`${t.interpreter}\` (\`${t.appKey}\`), and the entry it would ship — ${t.entry} (\`${t.bundleKey}\`) — imports ${F}${I}.\n ${N}, before a line of application code runs.\n The artifact would be built, reported as built, and fail at launch on every machine.
1162
+ Either ship this target the \`--app ${t.interpreter}\` build of the app — \`gjsify.ship.bundle.${t.layoutOs}\` selects the entry per target, the way \`gjsify.ship.app.${t.layoutOs}\` selects the runtime —\n or set \`gjsify.ship.app.${t.layoutOs}\` to "${C}" if this bundle is the one that should ship.`)}var GH,KH=__esmMin(()=>{dI(),GH=new Set([`system`,`gettext`])});function base64Encode(t){let n=``,S=32768;for(let C=0;C<t.length;C+=S)n+=String.fromCharCode(...t.subarray(C,C+S));return btoa(n)}function base64Decode(t){let n=atob(t),S=new Uint8Array(n.length);for(let t=0;t<n.length;t++)S[t]=n.charCodeAt(t);return S}var qH=__esmMin(()=>{});function toPackSettings(t){return{binaryName:t.binaryName,appId:t.appId,name:t.name,version:t.version,release:t.release,maintainer:t.maintainer,summary:t.summary,description:t.description,license:t.license,...t.homepage===void 0?{}:{homepage:t.homepage},section:t.section,group:t.group,extraDepends:t.extraDepends,typelibPackages:t.typelibPackages,app:t.app,minGjsVersion:t.minGjsVersion,minNodeVersion:t.minNodeVersion,flatpak:t.flatpak}}function stageManifestPath(t){return wn(t,JH)}function formatTarget(t){return`${t.os}-${t.arch}`}function writeStageManifest(t){let n={};for(let S of t.formats)n[S.id]=(t.overlay.get(S.id)??[]).map(t=>{if(t.source.kind===`text`)return{path:t.path,mode:t.mode,text:t.source.text};if(t.source.kind===`bytes`)return{path:t.path,mode:t.mode,base64:base64Encode(t.source.data)};throw Error(`gjsify ship: internal error — the ${S.id} overlay entry ${t.path} is a file reference, and a stage manifest may only carry rendered bytes. Render it in \`planOverlay\` instead.`)});let S={schema:6,tool:{name:`@gjsify/cli`,version:cliVersion()},target:{os:t.settings.layoutOs,arch:t.settings.arch},formats:t.formats.map(t=>t.id),mtime:t.mtime,namespaces:[...t.namespaces],optionalNamespaces:[...t.optionalNamespaces??[]],settings:toPackSettings(t.settings),staged:t.staged.map(n=>({path:n.path,mode:n.mode,bytes:statSync(wn(t.stageDir,n.path.split(`/`).join(jn))).size})),overlay:n};return writeFileSync(stageManifestPath(t.stageDir),`${JSON.stringify(S,null,2)}\n`),S}function readStageManifest(t){let n=stageManifestPath(t);if(!existsSync(n))throw Error(`gjsify ship: ${t} has no ${JH}, so it is not a stage this command can pack. A stage is produced by \`gjsify ship --stage\`, which writes that file at the stage root beside the payload. If you pointed --from-stage at a project's \`ship/\` directory, point it at \`ship/stage/\` instead.`);let S;try{S=JSON.parse(readFileSync(n,`utf-8`))}catch(t){throw Error(`gjsify ship: ${n} is not readable JSON (${t.message}). Re-run the \`--stage\` phase; a truncated manifest means the stage transfer was truncated too.`)}if(typeof S!=`object`||!S||Array.isArray(S))throw Error(`gjsify ship: ${n} is not a JSON object. Re-run the \`--stage\` phase.`);let C=S,N=C.schema;if(typeof N!=`number`||!Number.isInteger(N))throw Error(`gjsify ship: ${n} has no integer \`schema\` field, so it was not written by \`gjsify ship --stage\`. Re-run the \`--stage\` phase.`);if(N>6)throw Error(`gjsify ship: ${n} declares schema ${N} and this gjsify understands 6. The stage was assembled by a newer gjsify: upgrade this one (\`gjsify self-update\`), or re-run the \`--stage\` phase with this version. A manifest from the future is refused rather than partially read, because an unknown field could be the one that decides a file's mode.`);if(N<6)throw Error(`gjsify ship: ${n} declares schema ${N} and this gjsify understands 6. Re-run the \`--stage\` phase with this gjsify. A stage is a short-lived intermediate between two jobs of one run, not an archive, so no migration is kept for it.`);let at=t=>`${n} → ${t}`,F=record(C.tool,at(`tool`)),I=record(C.target,at(`target`)),H={schema:N,tool:{name:expectString(F.name,at(`tool.name`)),version:expectString(F.version,at(`tool.version`))},target:{os:expectLayoutOs(expectString(I.os,at(`target.os`)),at(`target.os`)),arch:expectString(I.arch,at(`target.arch`))},formats:expectArray(C.formats,at(`formats`)).map((t,n)=>{let S=expectString(t,at(`formats[${n}]`));if(!AH.includes(S))throw Error(`gjsify ship: ${at(`formats[${n}]`)} is "${S}", which this gjsify does not know. Known formats: ${AH.join(`, `)}.`);return S}),mtime:expectInteger(C.mtime,at(`mtime`)),namespaces:expectArray(C.namespaces,at(`namespaces`)).map((t,n)=>expectString(t,at(`namespaces[${n}]`))),...C.optionalNamespaces===void 0?{}:{optionalNamespaces:expectArray(C.optionalNamespaces,at(`optionalNamespaces`)).map((t,n)=>expectString(t,at(`optionalNamespaces[${n}]`)))},settings:readPackSettings(record(C.settings,at(`settings`)),at(`settings`)),staged:expectArray(C.staged,at(`staged`)).map((t,n)=>{let S=record(t,at(`staged[${n}]`));return{path:expectString(S.path,at(`staged[${n}].path`)),mode:expectInteger(S.mode,at(`staged[${n}].mode`)),bytes:expectInteger(S.bytes,at(`staged[${n}].bytes`))}}),overlay:{}};if(H.staged.length===0)throw Error(`gjsify ship: ${at(`staged`)} is empty, so this stage describes no payload. A stage always carries at least the launcher its plan named. Re-run the \`--stage\` phase; a stage that lost its plan cannot be packed into anything but an empty package.`);let W=record(C.overlay,at(`overlay`));for(let t of H.formats)H.overlay[t]=expectArray(W[t],at(`overlay.${t}`)).map((n,S)=>{let C=record(n,at(`overlay.${t}[${S}]`)),N=at(`overlay.${t}[${S}]`);if(C.text===void 0==(C.base64===void 0))throw Error(`gjsify ship: ${N} must carry exactly one of \`text\` and \`base64\`. An overlay entry is either rendered text or rendered bytes; an entry with neither would pack an empty file at a path the format requires content at.`);return{path:expectString(C.path,at(`overlay.${t}[${S}].path`)),mode:expectInteger(C.mode,at(`overlay.${t}[${S}].mode`)),...C.text===void 0?{base64:expectString(C.base64,at(`overlay.${t}[${S}].base64`))}:{text:expectString(C.text,at(`overlay.${t}[${S}].text`))}}});return H}function expectLayoutOs(t,n){try{return layoutForOs(t).os}catch{let S=pV.map(t=>fV[t].os).join(`, `);throw Error(`gjsify ship: ${n} is "${t}", which is not a layout this gjsify can pack. It carries the \`process.platform\` spelling and only that — ${S}, so \`win32\` and never \`windows\`. A stage holds exactly one OS's layout and every path in it has that OS's shape, so there is nothing to pack here. Re-run the \`--stage\` phase.`)}}function overlayFiles(t,n){return(t.overlay[n]??[]).map(t=>({path:t.path,mode:t.mode,source:t.base64===void 0?{kind:`text`,text:t.text??``}:{kind:`bytes`,data:base64Decode(t.base64)}}))}function assertExpectedTarget(t,n){if(n===void 0)return;let S=formatTarget(t.target);if(n!==S)throw Error(`gjsify ship: --expect-target ${n} but this stage was assembled for ${S}. The stage records the target its \`--arch\` resolved to at stage time, so this is a stage from another matrix leg: download the artifact belonging to ${n}, or drop --expect-target if packing this one is what you meant.`)}function assertFormatsStaged(t,n){let S=n.filter(n=>!t.formats.includes(n.id)).map(t=>t.id);if(S.length!==0)throw Error(`gjsify ship: this stage was assembled for ${t.formats.length===0?`no format at all`:t.formats.join(`, `)}, and --target names ${S.join(`, `)}. Phase one renders each format's overlay — rpm wants the licence at \`share/licenses/<pkg>/LICENSE\`, deb wants a machine-readable copyright at \`share/doc/<pkg>/copyright\` — so a format the stage never saw would pack without it, and Debian Policy § 12.5 makes that a broken package. Re-run \`gjsify ship --stage --target ${[...t.formats,...S].join(`,`)}\` on the assembling host.`)}function resolveStageMtime(t,n=process.env){let S=n.SOURCE_DATE_EPOCH;return S===void 0||Number(S)===t.mtime?{mtime:t.mtime,warnings:[]}:{mtime:t.mtime,warnings:[`SOURCE_DATE_EPOCH is ${S} here and this stage was stamped ${t.mtime}. The stage's stamp wins, because changing it would make this artifact differ from the same stage packed on the assembling host. Set the same value in both jobs, or set it in neither.`]}}function warnOnToolSkew(t){let n=cliVersion();return t.tool.version===n?[]:[`this stage was assembled by ${t.tool.name} ${t.tool.version} and is being packed by ${n}. Both phases run the same packer, so a version difference can change the artifact's bytes. Pin both jobs to one gjsify version.`]}function readPackSettings(t,n){let field=t=>`${n}.${t}`,S=record(t.extraDepends,field(`extraDepends`)),C=record(t.typelibPackages,field(`typelibPackages`));return{binaryName:expectString(t.binaryName,field(`binaryName`)),appId:expectString(t.appId,field(`appId`)),name:expectString(t.name,field(`name`)),version:expectString(t.version,field(`version`)),release:expectString(t.release,field(`release`)),maintainer:expectString(t.maintainer,field(`maintainer`)),summary:expectString(t.summary,field(`summary`)),description:expectArray(t.description,field(`description`)).map((t,n)=>expectString(t,field(`description[${n}]`))),license:expectString(t.license,field(`license`)),...t.homepage===void 0?{}:{homepage:expectString(t.homepage,field(`homepage`))},section:expectString(t.section,field(`section`)),group:expectString(t.group,field(`group`)),extraDepends:{deb:expectArray(S.deb??[],field(`extraDepends.deb`)).map((t,n)=>expectString(t,field(`extraDepends.deb[${n}]`))),rpm:expectArray(S.rpm??[],field(`extraDepends.rpm`)).map((t,n)=>expectString(t,field(`extraDepends.rpm[${n}]`)))},typelibPackages:Object.fromEntries(Object.entries(C).map(([t,n])=>{let S=record(n,field(`typelibPackages.${t}`));return[t,{deb:expectString(S.deb,field(`typelibPackages.${t}.deb`)),rpm:expectString(S.rpm,field(`typelibPackages.${t}.rpm`))}]})),app:expectApp(t.app,field(`app`)),minGjsVersion:expectString(t.minGjsVersion,field(`minGjsVersion`)),minNodeVersion:expectString(t.minNodeVersion,field(`minNodeVersion`)),flatpak:readFlatpakSettings(record(t.flatpak,field(`flatpak`)),field(`flatpak`))}}function readFlatpakSettings(t,n){let field=t=>`${n}.${t}`,strings=(t,n)=>expectArray(t,field(n)).map((t,S)=>expectString(t,field(`${n}[${S}]`)));return{runtime:expectString(t.runtime,field(`runtime`)),runtimeVersion:expectString(t.runtimeVersion,field(`runtimeVersion`)),sdk:expectString(t.sdk,field(`sdk`)),branch:expectString(t.branch,field(`branch`)),sdkExtensions:strings(t.sdkExtensions,`sdkExtensions`),appendPath:strings(t.appendPath,`appendPath`),finishArgs:strings(t.finishArgs,`finishArgs`),cleanup:strings(t.cleanup,`cleanup`)}}function record(t,n){if(typeof t!=`object`||!t||Array.isArray(t))throw Error(`gjsify ship: ${n} must be an object. Re-run the \`--stage\` phase.`);return t}function expectArray(t,n){if(!Array.isArray(t))throw Error(`gjsify ship: ${n} must be an array. Re-run the \`--stage\` phase.`);return t}function expectApp(t,n){if(t===`gjs`||t===`node`)return t;throw Error(`gjsify ship: ${n} must be "gjs" or "node", got ${JSON.stringify(t)}.`)}function expectString(t,n){if(typeof t!=`string`)throw Error(`gjsify ship: ${n} must be a string. Re-run the \`--stage\` phase.`);return t}function expectInteger(t,n){if(typeof t!=`number`||!Number.isInteger(t)||t<0)throw Error(`gjsify ship: ${n} must be a non-negative integer. Re-run the \`--stage\` phase. (Modes are decimal here — JSON has no octal literal, so 0o755 is written 493.)`);return t}var JH,YH=__esmMin(()=>{Rd(),Pn(),qH(),nh(),MH(),hV(),JH=`.gjsify-ship-stage.json`});function writeStage(t,n){for(let t of n)if(t.path===`.gjsify-ship-stage.json`)throw Error(`gjsify ship: a payload file may not be called \`${JH}\` — that name belongs to the stage manifest, which sits at the stage root beside the payload and carries what the packing host needs (ADR 0024 § A2). Rename the \`gjsify.ship.extraFiles\` destination.`);rmSync(t,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(t,{recursive:!0});for(let S of n){let n=wn(t,S.path.split(`/`).join(jn));mkdirSync(En(n),{recursive:!0});let C;switch(S.source.kind){case`text`:C=new TextEncoder().encode(S.source.text);break;case`file`:C=new Uint8Array(readFileSync(S.source.path));break;case`bytes`:C=S.source.data;break;default:{let t=S.source;throw Error(`gjsify ship: no writer for the "${JSON.stringify(t)}" source kind.`)}}writeFileSync(n,C),chmodSync(n,S.mode)}}function readStage(t,n){let S=new Map(n.map(t=>[t.path,t])),C=new Map;for(let n of t)for(let t of listFilesRecursive(n)){if(t===`.gjsify-ship-stage.json`)continue;let N=S.get(t);if(N===void 0)throw Error(`gjsify ship: ${wn(n,t.split(`/`).join(jn))} is in the stage and not in its manifest, so nothing knows what mode to give it. Every payload file takes its mode from the plan, never from the filesystem, so a file that arrived some other way would be packed 0644 — unrunnable if it is a program. Remove it, or add it through \`gjsify.ship.extraFiles\` and re-run the \`--stage\` phase.`);let F=new Uint8Array(readFileSync(wn(n,t.split(`/`).join(jn))));if(N.bytes!==void 0&&N.bytes!==F.byteLength)throw Error(`gjsify ship: ${t} is ${F.byteLength} bytes in the stage and ${N.bytes} in its manifest. The stage arrived truncated or was edited after it was assembled. Re-upload it, or re-run the \`--stage\` phase.`);C.set(t,{path:t,mode:N.mode,data:F})}let N=n.filter(t=>!C.has(t.path)).map(t=>t.path);if(N.length>0)throw Error(`gjsify ship: the stage manifest lists ${N.length} file(s) the stage does not contain: ${N.slice(0,5).join(`, `)}${N.length>5?`, …`:``}. A payload has to be complete before it is packed — both formats would pack the rest without complaint and install a package that cannot start. Re-run the \`--stage\` phase, and check that whatever moved the stage between hosts copied every file (an artifact upload that drops empty files or dotfiles is the usual cause).`);return[...C.values()].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}function writePayload(t,n,S){let C=S===``?``:`${S}/`;rmSync(t,{recursive:!0,force:!0,maxRetries:5}),mkdirSync(t,{recursive:!0});for(let N of n){if(!N.path.startsWith(C))throw Error(`gjsify ship: ${N.path} is outside ${S||`the artifact`}, which this artifact IS — so there is nowhere inside it for the file to go. A payload file that escaped the bundle would ship beside it, unsigned and unfound.`);let n=wn(t,N.path.slice(C.length).split(`/`).join(jn));mkdirSync(En(n),{recursive:!0}),writeFileSync(n,N.data),chmodSync(n,N.mode)}}function directorySize(t){let n=0;for(let S of listFilesRecursive(t))n+=statSync(wn(t,S.split(`/`).join(jn))).size;return n}var XH=__esmMin(()=>{Rd(),Pn(),KV(),YH()});function resolveSignPlan(t){let n=ZH[t.layoutOs];if(n===void 0){if(t.flag!==void 0)throw Error(`gjsify ship: --sign has nothing to sign in the ${t.layoutOs} layout. A .deb and an .rpm carry no per-file signature — the artifact is signed as a whole by the repository that serves it (\`debsigs\`, \`rpmsign\`), with that repository's key and not with a build-time identity. Drop --sign, or assemble the darwin or windows layout.`);return{kind:`unsupported`}}let S=t.config?.[t.layoutOs]?.identity,[C,N]=t.flag===void 0?[S,`config`]:[t.flag,`flag`];return C===void 0||C===``?{kind:`skip`,message:`${C===``?`an empty identity was ${N===`flag`?`passed to --sign`:`set in \`${n.configKey}\``}`:`no identity was given`} — skipping ${n.tool}. An unsigned artifact is the default path and a legitimate deliverable (ADR 0024 § A13). Pass \`--sign <identity>\` or set \`${n.configKey}\` to sign; \`--sign -\` signs ad-hoc and needs no developer identity.`}:{kind:`sign`,identity:C,signer:n,source:N}}function assertHostCanSign(t){let n=process.platform;if(!t.signOn.includes(n))throw Error(`gjsify ship: signing the ${t.layoutOs} layout needs ${t.tool}, which runs on ${t.signOn.join(`, `)} and this host is ${n}. Assembly is not host-bound — \`gjsify ship <os> --stage\` here, then \`gjsify ship --from-stage <dir> --sign <identity>\` on a host that has both the tool and the identity (ADR 0024 § A1, § A14).`);if(!isOnPath(t.tool))throw Error(`gjsify ship: --sign was given and \`${t.tool}\` is not on PATH, so nothing can make the signature — ${t.installHint}. Dropping --sign produces an unsigned artifact, which is a legitimate output (ADR 0024 § A13); silently producing one while --sign was asked for is not.`)}function partitionSignedFileSet(t){let n=new Set(t.planned),S=new Set(t.arrived),C=[...S].filter(t=>!n.has(t)).sort(),N=t.sealPrefix;return{sealed:N===void 0?[]:C.filter(t=>t.startsWith(N)),unexpected:N===void 0?C:C.filter(t=>!t.startsWith(N)),removed:[...n].filter(t=>!S.has(t)).sort()}}async function signPayload(t){let{payload:n,signer:S,workDir:C}=t;writePayload(C,n,``);let N=t.identity===`-`,F,I=S.entitlements(N);I.length>0&&(mkdirSync(En(t.entitlementsPath),{recursive:!0}),writeFileSync(t.entitlementsPath,renderEntitlements(I)),F=t.entitlementsPath);let run=async(n,I)=>{let H=S.args({identity:t.identity,file:n,adhoc:N,...F?{entitlements:F}:{}});t.verbose&&t.log(`${S.tool} ${H.join(` `)}`);let W=await spawnToCompletion(S.tool,H,{completion:`return`,cwd:C,stdio:`inherit`,notFound:()=>Error(`gjsify ship: \`${S.tool}\` is not on PATH — ${S.installHint}.`)});if(W.code!==0)throw Error(`gjsify ship: ${S.tool} failed on ${I} with ${describeExit(W)}. Nothing is packed from a payload whose signature failed: an artifact that is half signed installs and is refused at first launch, which is worse than not shipping.`)},H=n.filter(t=>classifyBinary(t.data)===S.signs);if(H.length===0&&!S.sealsBundle)return t.log(`nothing in this payload is a ${S.signs===`macho`?`Mach-O`:`PE`} image, so ${S.tool} signed 0 file(s). The artifact carries no signature.`),[...n];for(let t of H)await run(wn(C,t.path.split(`/`).join(jn)),t.path);let W;if(S.sealsBundle){if(t.bundleRoot===``)throw Error(`gjsify ship: the ${S.layoutOs} signer seals a bundle and this layout has no root to seal. \`Layout.root\` is what names the artifact directory; a signer that sealed the whole stage would sign the payload of every other format beside it.`);W=S.sealAddPrefix(t.bundleRoot),await run(wn(C,t.bundleRoot.split(`/`).join(jn)),`${t.bundleRoot} (bundle seal)`)}let q=partitionSignedFileSet({arrived:listFilesRecursive(C),planned:n.map(t=>t.path),...W===void 0?{}:{sealPrefix:W}});if(q.unexpected.length>0||q.removed.length>0)throw Error(`gjsify ship: ${S.tool} changed the payload's file set — ${q.unexpected.length} added (${q.unexpected.slice(0,3).join(`, `)||`—`}), ${q.removed.length} removed (${q.removed.slice(0,3).join(`, `)||`—`}). Signing is a mutation of the files that are already in the payload (ADR 0024 § A4), plus exactly the seal's own directory${W===void 0?``:` (\`${W}\`)`}.`);let Y=q.sealed;t.log(`${S.tool} signed ${H.length} of ${n.length} payload file(s) as ${N?"ad-hoc (`-`)":`\`${t.identity}\``}${W===void 0?``:` and sealed ${t.bundleRoot} (${Y.length} seal file(s))`} — ${S.gap}.`);let read=t=>new Uint8Array(readFileSync(wn(C,t.split(`/`).join(jn))));return[...n.map(t=>({path:t.path,mode:t.mode,data:read(t.path)})),...Y.map(t=>({path:t,mode:420,data:read(t)}))].sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}function resolveNotaryPlan(t){let n=QH[t.layoutOs];if(n===void 0){if(t.flag!==void 0)throw Error(`gjsify ship: --notarize has no meaning in the ${t.layoutOs} layout. Notarisation is Apple's pre-clearance of a signed artifact and nothing else asks for it — Windows SmartScreen accrues reputation per file hash instead (ADR 0024 § A5).`);return{kind:`unsupported`}}if(t.flag===void 0||t.flag===``)return{kind:`skip`,message:`no notarisation credential was given — skipping ${n.tool} notarytool. Pass \`--notarize <keychain-profile>\`, naming a profile a prior \`notarytool store-credentials\` put in this host's keychain.`};if(t.sign.kind!==`sign`)throw Error("gjsify ship: --notarize was given without an identity to sign with. Notarisation is a check ON a signature, so submitting an unsigned artifact has nothing to clear. Pass `--sign <identity>` as well, or drop --notarize.");return{kind:`notarize`,credential:t.flag,notary:n}}async function notarizeArtifact(t){let{notary:n,credential:S}=t.plan,C=process.platform;if(!n.notarizeOn.includes(C))throw Error(`gjsify ship: notarising the ${n.layoutOs} layout needs ${n.tool}, which runs on ${n.notarizeOn.join(`, `)} and this host is ${C}.`);let N=n.args(S,t.artifact);t.verbose&&t.log(`${n.tool} ${N.join(` `)}`);let F=await spawnToCompletion(n.tool,N,{completion:`return`,stdio:`inherit`,notFound:()=>Error(`gjsify ship: \`${n.tool}\` is not on PATH — ${n.installHint}.`)});if(F.code!==0)throw Error(`gjsify ship: ${n.tool} notarytool failed with ${describeExit(F)}.`);t.log(`${n.tool} notarytool accepted ${t.artifact}.`)}async function stapleArtifact(t){let n=[`stapler`,`staple`,t.artifact];t.verbose&&t.log(`${t.notary.tool} ${n.join(` `)}`);let S=await spawnToCompletion(t.notary.tool,n,{completion:`return`,stdio:`inherit`,notFound:()=>Error(`gjsify ship: \`${t.notary.tool}\` is not on PATH — ${t.notary.installHint}.`)});if(S.code!==0)throw Error(`gjsify ship: ${t.notary.tool} stapler failed with ${describeExit(S)}. The artifact is notarised and NOT stapled, which means every launch asks Gatekeeper to check online — and fails closed on a machine with no network. Re-run the finish phase; \`stapler\` requires internet access and the ticket may not have propagated yet.`);t.log(`${t.notary.tool} stapler attached the ticket to ${t.artifact}.`)}var ZH,QH,$H=__esmMin(()=>{Rd(),Pn(),vF(),V_(),KV(),AV(),lV(),XH(),ZH={darwin:{layoutOs:`darwin`,tool:`codesign`,signOn:[`darwin`],installHint:"install the Xcode Command Line Tools (`xcode-select --install`) on a macOS host",signs:`macho`,args:({identity:t,file:n,entitlements:S,adhoc:C})=>[`--force`,`--sign`,t,`--options`,`runtime`,...S===void 0?[]:[`--entitlements`,S],...C?[]:[`--timestamp`],n],entitlements:t=>[`com.apple.security.cs.allow-jit`,`com.apple.security.cs.allow-unsigned-executable-memory`,`com.apple.security.cs.disable-executable-page-protection`,`com.apple.security.cs.allow-dyld-environment-variables`,...t?[`com.apple.security.cs.disable-library-validation`]:[]],sealsBundle:!0,sealAddPrefix:t=>`${t}/Contents/_CodeSignature/`,configKey:`gjsify.ship.sign.darwin.identity`,gap:"the images are signed and the bundle is sealed, and the seal survives both the `.zip` and the `.dmg` round trip; § A16 stands measured in ONE direction only — library validation refuses an ad-hoc-signed dylib, so the ad-hoc identity grants `disable-library-validation` while a named one does not, and no run in this repository has ever held the named one"},win32:{layoutOs:`win32`,tool:`signtool`,signOn:[`win32`],installHint:"install the Windows SDK (signtool.exe ships in its `bin/<version>/x64` directory)",signs:`pe`,args:({identity:t,file:n})=>[`sign`,`/n`,t,`/fd`,`sha256`,n],entitlements:()=>[],sealsBundle:!1,sealAddPrefix:()=>``,configKey:`gjsify.ship.sign.win32.identity`,gap:`no timestamp countersignature is requested, so the signature expires with the certificate (UNVERIFIED: no run in this repository has ever invoked signtool)`}},QH={darwin:{layoutOs:`darwin`,tool:`xcrun`,notarizeOn:[`darwin`],installHint:"install the Xcode Command Line Tools (`xcode-select --install`) on a macOS host",args:(t,n)=>[`notarytool`,`submit`,`--keychain-profile`,t,`--wait`,n]}}});function stagedFontDir(t,n){return`${t}/${pn.basename(DB.fonts)}/${n}`}function shellQuote(t){return`'${t.replace(/'/g,`'\\''`)}'`}function cmdQuote(t){let n=/["%!\r\n]/.exec(t);if(n!==null)throw Error(`gjsify ship: \`gjsify.ship.execArgs\` contains ${JSON.stringify(t)}, and cmd.exe has no way to pass ${JSON.stringify(n[0])} through a Windows launcher literally — \`%\` expands at parse time and \`"\` ends the quoted run. Move the value into the app (it can read it from its own config) or drop the character.`);return`"${t}"`}function renderLauncher(t,n,S,C={}){switch(S.name){case`linux`:return renderPrefixLauncher(t,n,S);case`darwin`:return renderAppBundleLauncher(t,n,S,C);case`windows`:return renderWindowsLauncher(t,n,S,C);default:{let t=S.name;throw Error(`gjsify ship: no launcher is wired for the "${String(t)}" layout.`)}}}function renderPrefixLauncher(t,n,S){let C=S.dirs(t),N=[`#!/bin/sh`,"# Generated by `gjsify ship` — do not edit.",`set -e`,`self=$(readlink -f "$0")`,`prefix=$(dirname "$(dirname "$self")")`,`XDG_DATA_DIRS="$prefix/${C.data}:\${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"`,`export XDG_DATA_DIRS`];if(t.typelibFiles.length>0){let t=`"$prefix"/${C.native}`;for(let n of[`GI_TYPELIB_PATH`,`LD_LIBRARY_PATH`])N.push(`${n}=${t}\${${n}:+:$${n}}`,`export ${n}`)}else if(Object.values(t.formatFiles).some(t=>t.typelibFiles.length>0)){let t=`"$prefix"/${C.native}`;N.push(`if [ -d ${t} ]; then`);for(let n of[`GI_TYPELIB_PATH`,`LD_LIBRARY_PATH`])N.push(` ${n}=${t}\${${n}:+:$${n}}`,` export ${n}`);N.push(`fi`)}return t.localeFiles.length>0&&N.push(`GJSIFY_LOCALE_DIR="$prefix"/${C.data}/locale`,`export GJSIFY_LOCALE_DIR`),t.fontFiles.length>0&&N.push(`GJSIFY_FONT_DIR="$prefix"/${stagedFontDir(C.data,t.appId)}`,`export GJSIFY_FONT_DIR`),N.push(`exec ${execLine(S,`"$prefix"/${C.bundle}/${n}`,t)} "$@"`,``),N.join(`
1163
1163
  `)}function renderAppBundleLauncher(t,n,S,C){let N=`${S.root(t)}/Contents`,F=S.dirs(t),under=t=>pn.relative(N,t),beside=t=>pn.relative(F.launcher,t),I=[`#!/bin/sh`,"# Generated by `gjsify ship` — do not edit.",`set -e`,`here=$(cd -- "$(dirname -- "$0")" && pwd)`,`contents=$(dirname -- "$here")`,`XDG_DATA_DIRS="$contents/${under(F.data)}"\${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}`,`export XDG_DATA_DIRS`];C.gtkRuntimeDir!==void 0&&I.push(`GJSIFY_GTK_RUNTIME="$contents/${under(C.gtkRuntimeDir)}"`,`export GJSIFY_GTK_RUNTIME`),C.nodeGiAddon!==void 0&&I.push(`NODE_GI_NATIVE="$contents/${under(C.nodeGiAddon)}"`,`export NODE_GI_NATIVE`),t.typelibFiles.length>0&&(I.push(`GI_TYPELIB_PATH="$contents/${under(F.native)}"\${GI_TYPELIB_PATH:+:$GI_TYPELIB_PATH}`,`export GI_TYPELIB_PATH`),I.push(`GJSIFY_GI_LIBRARY_PATH="$contents/${under(F.native)}"\${GJSIFY_GI_LIBRARY_PATH:+:$GJSIFY_GI_LIBRARY_PATH}`,`export GJSIFY_GI_LIBRARY_PATH`)),t.localeFiles.length>0&&I.push(`GJSIFY_LOCALE_DIR="$contents/${under(F.data)}/locale"`,`export GJSIFY_LOCALE_DIR`),t.fontFiles.length>0&&I.push(`GJSIFY_FONT_DIR="$contents/${stagedFontDir(under(F.data),t.appId)}"`,`export GJSIFY_FONT_DIR`);let H=C.interpreter===void 0?void 0:`"$here/${beside(C.interpreter)}"`;return I.push(`exec ${execLine(S,`"$contents/${under(F.bundle)}/${n}"`,t,H)} "$@"`,``),I.join(`
1164
1164
  `)}function renderWindowsLauncher(t,n,S,C){let N=S.dirs(t),at=t=>`%HERE%${windowsPath(t)}`,F=[`@echo off`,`rem Generated by "gjsify ship" - do not edit.`,`setlocal`,`set "HERE=%~dp0"`,prependVar(`XDG_DATA_DIRS`,at(N.data))];C.gtkRuntimeDir!==void 0&&F.push(`set "GJSIFY_GTK_RUNTIME=${at(C.gtkRuntimeDir)}"`),C.nodeGiAddon!==void 0&&F.push(`set "NODE_GI_NATIVE=${at(C.nodeGiAddon)}"`),t.typelibFiles.length>0&&F.push(prependVar(`GI_TYPELIB_PATH`,at(N.native)),prependVar(`PATH`,at(N.native))),t.localeFiles.length>0&&F.push(`set "GJSIFY_LOCALE_DIR=${at(N.data)}\\locale"`),t.fontFiles.length>0&&F.push(`set "GJSIFY_FONT_DIR=${at(stagedFontDir(N.data,t.appId))}"`);let I=C.interpreter===void 0?void 0:`"${at(C.interpreter)}"`;return F.push(`${execLine(S,`"${at(N.bundle)}\\${windowsPath(n)}"`,t,I)} %*`,``),F.join(`\r
1165
- `)}function prependVar(t,n){return`if defined ${t} (set "${t}=${n};%${t}%") else (set "${t}=${n}")`}function windowsPath(t){return t.split(`/`).filter(t=>t.length>0).join(`\\`)}function execLine(t,n,S,C){let N=t.name===`windows`?cmdQuote:shellQuote,F=S.execArgs.map(N).join(` `),I=C??(S.app===`node`?`node`:`gjs`);return`${S.app===`node`?I:`${I} -m`} ${n}${F?` ${F}`:``}`}var YH=__esmMin(()=>{Pn(),CB()});function createCpioArchive(t){let n=[],S=0;t.forEach((t,C)=>{let N=t.linkTarget===void 0?t.data??new Uint8Array:encodeUtf8(t.linkTarget),F=encodeUtf8(`${t.name}\0`),I=buildHeader({ino:t.ino??C+1,mode:t.mode,nlink:t.nlink??1,mtime:t.mtime??0,filesize:N.byteLength,namesize:F.byteLength});S=push(n,I,S),S=push(n,F,S),S=padTo4(n,S),S=push(n,N,S),S=padTo4(n,S)});let C=encodeUtf8(`TRAILER!!!\0`);return S=push(n,buildHeader({ino:0,mode:0,nlink:1,mtime:0,filesize:0,namesize:C.byteLength}),S),S=push(n,C,S),padTo4(n,S),concatBytes(n)}function buildHeader(t){let n=XH+hex8(t.ino)+hex8(t.mode)+hex8(0)+hex8(0)+hex8(t.nlink)+hex8(t.mtime)+hex8(t.filesize)+hex8(0)+hex8(0)+hex8(0)+hex8(0)+hex8(t.namesize)+hex8(0);if(n.length!==ZH)throw Error(`gjsify ship: internal error — cpio header is ${n.length} bytes, expected ${ZH}.`);return encodeUtf8(n)}function hex8(t){if(t<0||!Number.isInteger(t))throw Error(`gjsify ship: cpio header field must be a non-negative integer, got ${t}.`);let n=t.toString(16).toUpperCase();if(n.length>8)throw Error(`gjsify ship: cpio header field ${t} does not fit in 8 hex digits.`);return n.padStart(8,`0`)}function push(t,n,S){return n.byteLength>0&&t.push(n),S+n.byteLength}function padTo4(t,n){let S=n%4;if(S===0)return n;let C=4-S;return t.push(new Uint8Array(C)),n+C}var XH,ZH,QH,$H,eU=__esmMin(()=>{cB(),XH=`070701`,ZH=110,QH=32768,$H=16384});function buildRpmHeader(t,n){let S=[...t].sort((t,n)=>t.tag-n.tag),C=[],N=[],F=0;for(let t of S){if(t.tag<100)throw Error(`gjsify ship: rpm tag ${t.tag} is below 100 and would be rejected by hdrchkTag.`);let{data:n,count:S}=encodeValue(t.type,t.value,t.tag),I=iU[t.type],H=(I-F%I)%I;H>0&&(N.push(new Uint8Array(H)),F+=H),C.push({tag:t.tag,type:t.type,offset:F,count:S}),N.push(n),F+=n.byteLength}let I=F,H=C.length+1;N.push(indexEntry(n,7,-(nU*H),rU)),F+=nU;let W=new Uint8Array(tU.byteLength+8+H*nU+F),q=new DataView(W.buffer);W.set(tU,0),q.setUint32(8,H),q.setUint32(12,F);let Y=16;W.set(indexEntry(n,7,I,rU),Y),Y+=nU;for(let t of C)W.set(indexEntry(t.tag,t.type,t.offset,t.count),Y),Y+=nU;for(let t of N)W.set(t,Y),Y+=t.byteLength;return W}function indexEntry(t,n,S,C){let N=new Uint8Array(nU),F=new DataView(N.buffer);return F.setInt32(0,t),F.setInt32(4,n),F.setInt32(8,S),F.setInt32(12,C),N}function encodeValue(t,n,S){let C=new TextEncoder;switch(t){case 6:if(typeof n!=`string`)throw typeMismatch(S,`a string`);return{data:C.encode(`${n}\0`),count:1};case 8:case 9:{let t=typeof n==`string`?[n]:n;if(!Array.isArray(t))throw typeMismatch(S,`a string array`);if(t.length===0)throw Error(`gjsify ship: rpm tag ${S} has an empty array; omit it instead.`);return{data:C.encode(t.map(t=>`${t}\0`).join(``)),count:t.length}}case 7:if(!(n instanceof Uint8Array))throw typeMismatch(S,`binary data`);return{data:n,count:n.byteLength};case 3:case 4:{let C=typeof n==`number`?[n]:n;if(!Array.isArray(C))throw typeMismatch(S,`a number array`);if(C.length===0)throw Error(`gjsify ship: rpm tag ${S} has an empty array; omit it instead.`);let N=t===3?2:4,F=new Uint8Array(C.length*N),I=new DataView(F.buffer);return C.forEach((n,S)=>{t===3?I.setUint16(S*N,n&65535):I.setUint32(S*N,n>>>0)}),{data:F,count:C.length}}}}function typeMismatch(t,n){return Error(`gjsify ship: internal error — rpm tag ${t} expects ${n}.`)}function buildRpmLead(t){let n=new Uint8Array(96),S=new DataView(n.buffer);n.set([237,171,238,219],0),n[4]=3,n[5]=0,S.setInt16(6,0),S.setInt16(8,0);let C=new TextEncoder().encode(t).slice(0,65);return n.set(C,10),S.setInt16(76,0),S.setInt16(78,5),n}function padToEight(t){let n=(8-t.byteLength%8)%8;if(n===0)return t;let S=new Uint8Array(t.byteLength+n);return S.set(t,0),S}var tU,nU,rU,iU,aU=__esmMin(()=>{tU=Uint8Array.from([142,173,232,1,0,0,0,0]),nU=16,rU=16,iU={3:2,4:4,6:1,7:1,8:1,9:1}});async function buildRpm(t){let{settings:n,mtime:S}=t,C=collectFiles(t,`/${t.prefix.replace(/^\/+|\/+$/g,``)}`),N=createCpioArchive(C.map((t,n)=>({name:`.${t.path}`,mode:t.mode,data:t.data,mtime:S,ino:n+1}))),F=await gzipDeterministic(N),I=buildRpmHeader(mainHeaderEntries(t,C,N,F),63),H=concatBytes([I,F]),W=padToEight(buildRpmHeader([{tag:sU.SHA1HEADER,type:6,value:hashHex(`sha1`,I)},{tag:sU.SHA256HEADER,type:6,value:hashHex(`sha256`,I)},{tag:sU.SIZE,type:4,value:[H.byteLength]},{tag:sU.MD5,type:7,value:hashBytes(`md5`,H)},{tag:sU.PAYLOADSIZE,type:4,value:[N.byteLength]}],62));return concatBytes([buildRpmLead(`${n.binaryName}-${n.version}-${n.release}`),W,H])}function collectFiles(t,n){let S=t.payload.map(t=>{if(t.data.byteLength>4294967295)throw Error(`gjsify ship: ${t.path} is larger than 4 GiB, which needs rpm's LONGFILESIZES tag. That is not implemented — split the payload.`);return{path:`${n}/${t.path}`,mode:QH|t.mode&4095,data:t.data,isDirectory:!1}}),C=new Set;for(let t of S){let n=t.path.split(`/`).slice(1);n.pop();let S=``;for(let t of n)S=`${S}/${t}`,dU.has(S)||C.add(S)}for(let t of C)S.push({path:t,mode:$H|493,data:new Uint8Array,isDirectory:!0});return S.sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}function mainHeaderEntries(t,n,S,C){let{settings:N}=t,F=`${N.version}-${N.release}`,I=[],H=[],W=[];for(let t of n){let n=t.path.lastIndexOf(`/`),S=`${t.path.slice(0,n)}/`,C=I.indexOf(S);C===-1&&(C=I.push(S)-1),H.push(C),W.push(t.path.slice(n+1))}let q=renderRpmScriptlets(readPayloadFacts(t.payload),t.prefix),Y=buildRequires(t.depends,q,readShebangInterpreters(t.payload)),X=buildRecommends(t.recommends??[]),Z=[{tag:oU.HEADERI18NTABLE,type:8,value:[`C`]},{tag:oU.NAME,type:6,value:N.binaryName},{tag:oU.VERSION,type:6,value:N.version},{tag:oU.RELEASE,type:6,value:N.release},{tag:oU.SUMMARY,type:9,value:[N.summary]},{tag:oU.DESCRIPTION,type:9,value:[N.description.join(`
1165
+ `)}function prependVar(t,n){return`if defined ${t} (set "${t}=${n};%${t}%") else (set "${t}=${n}")`}function windowsPath(t){return t.split(`/`).filter(t=>t.length>0).join(`\\`)}function execLine(t,n,S,C){let N=t.name===`windows`?cmdQuote:shellQuote,F=S.execArgs.map(N).join(` `),I=C??(S.app===`node`?`node`:`gjs`);return`${S.app===`node`?I:`${I} -m`} ${n}${F?` ${F}`:``}`}var eU=__esmMin(()=>{Pn(),OB()});function createCpioArchive(t){let n=[],S=0;t.forEach((t,C)=>{let N=t.linkTarget===void 0?t.data??new Uint8Array:encodeUtf8(t.linkTarget),F=encodeUtf8(`${t.name}\0`),I=buildHeader({ino:t.ino??C+1,mode:t.mode,nlink:t.nlink??1,mtime:t.mtime??0,filesize:N.byteLength,namesize:F.byteLength});S=push(n,I,S),S=push(n,F,S),S=padTo4(n,S),S=push(n,N,S),S=padTo4(n,S)});let C=encodeUtf8(`TRAILER!!!\0`);return S=push(n,buildHeader({ino:0,mode:0,nlink:1,mtime:0,filesize:0,namesize:C.byteLength}),S),S=push(n,C,S),padTo4(n,S),concatBytes(n)}function buildHeader(t){let n=tU+hex8(t.ino)+hex8(t.mode)+hex8(0)+hex8(0)+hex8(t.nlink)+hex8(t.mtime)+hex8(t.filesize)+hex8(0)+hex8(0)+hex8(0)+hex8(0)+hex8(t.namesize)+hex8(0);if(n.length!==nU)throw Error(`gjsify ship: internal error — cpio header is ${n.length} bytes, expected ${nU}.`);return encodeUtf8(n)}function hex8(t){if(t<0||!Number.isInteger(t))throw Error(`gjsify ship: cpio header field must be a non-negative integer, got ${t}.`);let n=t.toString(16).toUpperCase();if(n.length>8)throw Error(`gjsify ship: cpio header field ${t} does not fit in 8 hex digits.`);return n.padStart(8,`0`)}function push(t,n,S){return n.byteLength>0&&t.push(n),S+n.byteLength}function padTo4(t,n){let S=n%4;if(S===0)return n;let C=4-S;return t.push(new Uint8Array(C)),n+C}var tU,nU,rU,iU,aU=__esmMin(()=>{pB(),tU=`070701`,nU=110,rU=32768,iU=16384});function buildRpmHeader(t,n){let S=[...t].sort((t,n)=>t.tag-n.tag),C=[],N=[],F=0;for(let t of S){if(t.tag<100)throw Error(`gjsify ship: rpm tag ${t.tag} is below 100 and would be rejected by hdrchkTag.`);let{data:n,count:S}=encodeValue(t.type,t.value,t.tag),I=lU[t.type],H=(I-F%I)%I;H>0&&(N.push(new Uint8Array(H)),F+=H),C.push({tag:t.tag,type:t.type,offset:F,count:S}),N.push(n),F+=n.byteLength}let I=F,H=C.length+1;N.push(indexEntry(n,7,-(sU*H),cU)),F+=sU;let W=new Uint8Array(oU.byteLength+8+H*sU+F),q=new DataView(W.buffer);W.set(oU,0),q.setUint32(8,H),q.setUint32(12,F);let Y=16;W.set(indexEntry(n,7,I,cU),Y),Y+=sU;for(let t of C)W.set(indexEntry(t.tag,t.type,t.offset,t.count),Y),Y+=sU;for(let t of N)W.set(t,Y),Y+=t.byteLength;return W}function indexEntry(t,n,S,C){let N=new Uint8Array(sU),F=new DataView(N.buffer);return F.setInt32(0,t),F.setInt32(4,n),F.setInt32(8,S),F.setInt32(12,C),N}function encodeValue(t,n,S){let C=new TextEncoder;switch(t){case 6:if(typeof n!=`string`)throw typeMismatch(S,`a string`);return{data:C.encode(`${n}\0`),count:1};case 8:case 9:{let t=typeof n==`string`?[n]:n;if(!Array.isArray(t))throw typeMismatch(S,`a string array`);if(t.length===0)throw Error(`gjsify ship: rpm tag ${S} has an empty array; omit it instead.`);return{data:C.encode(t.map(t=>`${t}\0`).join(``)),count:t.length}}case 7:if(!(n instanceof Uint8Array))throw typeMismatch(S,`binary data`);return{data:n,count:n.byteLength};case 3:case 4:{let C=typeof n==`number`?[n]:n;if(!Array.isArray(C))throw typeMismatch(S,`a number array`);if(C.length===0)throw Error(`gjsify ship: rpm tag ${S} has an empty array; omit it instead.`);let N=t===3?2:4,F=new Uint8Array(C.length*N),I=new DataView(F.buffer);return C.forEach((n,S)=>{t===3?I.setUint16(S*N,n&65535):I.setUint32(S*N,n>>>0)}),{data:F,count:C.length}}}}function typeMismatch(t,n){return Error(`gjsify ship: internal error — rpm tag ${t} expects ${n}.`)}function buildRpmLead(t){let n=new Uint8Array(96),S=new DataView(n.buffer);n.set([237,171,238,219],0),n[4]=3,n[5]=0,S.setInt16(6,0),S.setInt16(8,0);let C=new TextEncoder().encode(t).slice(0,65);return n.set(C,10),S.setInt16(76,0),S.setInt16(78,5),n}function padToEight(t){let n=(8-t.byteLength%8)%8;if(n===0)return t;let S=new Uint8Array(t.byteLength+n);return S.set(t,0),S}var oU,sU,cU,lU,uU=__esmMin(()=>{oU=Uint8Array.from([142,173,232,1,0,0,0,0]),sU=16,cU=16,lU={3:2,4:4,6:1,7:1,8:1,9:1}});async function buildRpm(t){let{settings:n,mtime:S}=t,C=collectFiles(t,`/${t.prefix.replace(/^\/+|\/+$/g,``)}`),N=createCpioArchive(C.map((t,n)=>({name:`.${t.path}`,mode:t.mode,data:t.data,mtime:S,ino:n+1}))),F=await gzipDeterministic(N),I=buildRpmHeader(mainHeaderEntries(t,C,N,F),63),H=concatBytes([I,F]),W=padToEight(buildRpmHeader([{tag:fU.SHA1HEADER,type:6,value:hashHex(`sha1`,I)},{tag:fU.SHA256HEADER,type:6,value:hashHex(`sha256`,I)},{tag:fU.SIZE,type:4,value:[H.byteLength]},{tag:fU.MD5,type:7,value:hashBytes(`md5`,H)},{tag:fU.PAYLOADSIZE,type:4,value:[N.byteLength]}],62));return concatBytes([buildRpmLead(`${n.binaryName}-${n.version}-${n.release}`),W,H])}function collectFiles(t,n){let S=t.payload.map(t=>{if(t.data.byteLength>4294967295)throw Error(`gjsify ship: ${t.path} is larger than 4 GiB, which needs rpm's LONGFILESIZES tag. That is not implemented — split the payload.`);return{path:`${n}/${t.path}`,mode:rU|t.mode&4095,data:t.data,isDirectory:!1}}),C=new Set;for(let t of S){let n=t.path.split(`/`).slice(1);n.pop();let S=``;for(let t of n)S=`${S}/${t}`,gU.has(S)||C.add(S)}for(let t of C)S.push({path:t,mode:iU|493,data:new Uint8Array,isDirectory:!0});return S.sort((t,n)=>t.path<n.path?-1:+(t.path>n.path))}function mainHeaderEntries(t,n,S,C){let{settings:N}=t,F=`${N.version}-${N.release}`,I=[],H=[],W=[];for(let t of n){let n=t.path.lastIndexOf(`/`),S=`${t.path.slice(0,n)}/`,C=I.indexOf(S);C===-1&&(C=I.push(S)-1),H.push(C),W.push(t.path.slice(n+1))}let q=renderRpmScriptlets(readPayloadFacts(t.payload),t.prefix),Y=buildRequires(t.depends,q,readShebangInterpreters(t.payload)),X=buildRecommends(t.recommends??[]),Z=[{tag:dU.HEADERI18NTABLE,type:8,value:[`C`]},{tag:dU.NAME,type:6,value:N.binaryName},{tag:dU.VERSION,type:6,value:N.version},{tag:dU.RELEASE,type:6,value:N.release},{tag:dU.SUMMARY,type:9,value:[N.summary]},{tag:dU.DESCRIPTION,type:9,value:[N.description.join(`
1166
1166
 
1167
- `)]},{tag:oU.BUILDTIME,type:4,value:[t.mtime]},{tag:oU.BUILDHOST,type:6,value:`localhost`},{tag:oU.SIZE,type:4,value:[n.reduce((t,n)=>t+n.data.byteLength,0)]},{tag:oU.LICENSE,type:6,value:N.license},{tag:oU.GROUP,type:9,value:[N.group]},{tag:oU.OS,type:6,value:`linux`},{tag:oU.ARCH,type:6,value:t.archLabel},{tag:oU.SOURCERPM,type:6,value:`${N.binaryName}-${F}.src.rpm`},{tag:oU.RPMVERSION,type:6,value:`4.20.0`},{tag:oU.ENCODING,type:6,value:`utf-8`},{tag:oU.FILESIZES,type:4,value:n.map(t=>t.data.byteLength)},{tag:oU.FILEMODES,type:3,value:n.map(t=>t.mode)},{tag:oU.FILERDEVS,type:3,value:n.map(()=>0)},{tag:oU.FILEMTIMES,type:4,value:n.map(()=>t.mtime)},{tag:oU.FILEDIGESTS,type:8,value:n.map(t=>t.isDirectory?``:hashHex(`sha256`,t.data))},{tag:oU.FILELINKTOS,type:8,value:n.map(()=>``)},{tag:oU.FILEFLAGS,type:4,value:n.map(()=>0)},{tag:oU.FILEUSERNAME,type:8,value:n.map(()=>`root`)},{tag:oU.FILEGROUPNAME,type:8,value:n.map(()=>`root`)},{tag:oU.FILEVERIFYFLAGS,type:4,value:n.map(()=>4294967295)},{tag:oU.FILEDEVICES,type:4,value:n.map(()=>1)},{tag:oU.FILEINODES,type:4,value:n.map((t,n)=>n+1)},{tag:oU.FILELANGS,type:8,value:n.map(()=>``)},{tag:oU.FILEDIGESTALGO,type:4,value:[lU]},{tag:oU.DIRINDEXES,type:4,value:H},{tag:oU.BASENAMES,type:8,value:W},{tag:oU.DIRNAMES,type:8,value:I},{tag:oU.PROVIDENAME,type:8,value:[N.binaryName]},{tag:oU.PROVIDEFLAGS,type:4,value:[cU.EQUAL]},{tag:oU.PROVIDEVERSION,type:8,value:[F]},{tag:oU.REQUIRENAME,type:8,value:Y.names},{tag:oU.REQUIREFLAGS,type:4,value:Y.flags},{tag:oU.REQUIREVERSION,type:8,value:Y.versions},...X.names.length>0?[{tag:oU.RECOMMENDNAME,type:8,value:X.names},{tag:oU.RECOMMENDFLAGS,type:4,value:X.flags},{tag:oU.RECOMMENDVERSION,type:8,value:X.versions}]:[],{tag:oU.PAYLOADFORMAT,type:6,value:`cpio`},{tag:oU.PAYLOADCOMPRESSOR,type:6,value:`gzip`},{tag:oU.PAYLOADFLAGS,type:6,value:`9`},{tag:oU.PAYLOADDIGEST,type:8,value:[hashHex(`sha256`,C)]},{tag:oU.PAYLOADDIGESTALGO,type:4,value:[lU]},{tag:oU.PAYLOADDIGESTALT,type:8,value:[hashHex(`sha256`,S)]}];return assertParallelFileArrays(Z,n.length),N.homepage&&Z.push({tag:oU.URL,type:6,value:N.homepage}),q.post!==void 0&&(Z.push({tag:oU.POSTIN,type:6,value:q.post}),Z.push({tag:oU.POSTINPROG,type:6,value:`/bin/sh`})),q.postun!==void 0&&(Z.push({tag:oU.POSTUN,type:6,value:q.postun}),Z.push({tag:oU.POSTUNPROG,type:6,value:`/bin/sh`})),Z}function assertParallelFileArrays(t,n){let S=new Set([oU.FILESIZES,oU.FILEMODES,oU.FILERDEVS,oU.FILEMTIMES,oU.FILEDIGESTS,oU.FILELINKTOS,oU.FILEFLAGS,oU.FILEUSERNAME,oU.FILEGROUPNAME,oU.FILEVERIFYFLAGS,oU.FILEDEVICES,oU.FILEINODES,oU.FILELANGS,oU.DIRINDEXES,oU.BASENAMES]);for(let C of t){if(!S.has(C.tag))continue;let t=Array.isArray(C.value)?C.value.length:1;if(t!==n)throw Error(`gjsify ship: internal error — rpm tag ${C.tag} has ${t} values for ${n} files.`)}}function buildRequires(t,n,S){let C=[],N=[],F=[];for(let n of t){let t=parseDepend(n);C.push(t.name),N.push(senseFor(t.relation)),F.push(t.version??``)}n.post!==void 0&&(C.push(`/bin/sh`),N.push(cU.INTERP|cU.SCRIPT_POST),F.push(``)),n.postun!==void 0&&(C.push(`/bin/sh`),N.push(cU.INTERP|cU.SCRIPT_POSTUN),F.push(``));for(let t of S)C.push(t),N.push(cU.FIND_REQUIRES),F.push(``);for(let[t,n]of uU)C.push(t),N.push(cU.RPMLIB|cU.LESS|cU.EQUAL),F.push(n);return{names:C,flags:N,versions:F}}function buildRecommends(t){let n=[],S=[],C=[];for(let N of t){let t=parseDepend(N);n.push(t.name),S.push(senseFor(t.relation)),C.push(t.version??``)}return{names:n,flags:S,versions:C}}function senseFor(t){switch(t){case`>=`:return cU.GREATER|cU.EQUAL;case`>`:return cU.GREATER;case`<=`:return cU.LESS|cU.EQUAL;case`<`:return cU.LESS;case`=`:return cU.EQUAL;default:return 0}}function hashHex(t,n){return createHash(t).update(n).digest(`hex`)}function hashBytes(t,n){return new Uint8Array(createHash(t).update(n).digest())}var oU,sU,cU,lU,uU,dU,fU=__esmMin(()=>{Qc(),cB(),eU(),bB(),TV(),aU(),xB(),wB(),CB(),oU={HEADERI18NTABLE:100,NAME:1e3,VERSION:1001,RELEASE:1002,SUMMARY:1004,DESCRIPTION:1005,BUILDTIME:1006,BUILDHOST:1007,SIZE:1009,LICENSE:1014,GROUP:1016,URL:1020,OS:1021,ARCH:1022,POSTIN:1024,POSTUN:1026,FILESIZES:1028,FILEMODES:1030,FILERDEVS:1033,FILEMTIMES:1034,FILEDIGESTS:1035,FILELINKTOS:1036,FILEFLAGS:1037,FILEUSERNAME:1039,FILEGROUPNAME:1040,SOURCERPM:1044,FILEVERIFYFLAGS:1045,PROVIDENAME:1047,REQUIREFLAGS:1048,REQUIRENAME:1049,REQUIREVERSION:1050,RECOMMENDNAME:5046,RECOMMENDVERSION:5047,RECOMMENDFLAGS:5048,RPMVERSION:1064,POSTINPROG:1086,POSTUNPROG:1088,FILEDEVICES:1095,FILEINODES:1096,FILELANGS:1097,PROVIDEFLAGS:1112,PROVIDEVERSION:1113,DIRINDEXES:1116,BASENAMES:1117,DIRNAMES:1118,PAYLOADFORMAT:1124,PAYLOADCOMPRESSOR:1125,PAYLOADFLAGS:1126,FILEDIGESTALGO:5011,ENCODING:5062,PAYLOADDIGEST:5092,PAYLOADDIGESTALGO:5093,PAYLOADDIGESTALT:5097},sU={SIZE:1e3,MD5:1004,PAYLOADSIZE:1007,SHA1HEADER:269,SHA256HEADER:273},cU={LESS:2,GREATER:4,EQUAL:8,INTERP:256,SCRIPT_POST:1024,SCRIPT_POSTUN:4096,FIND_REQUIRES:16384,RPMLIB:1<<24},lU=8,uU=[[`rpmlib(CompressedFileNames)`,`3.0.4-1`],[`rpmlib(FileDigests)`,`4.6.0-1`],[`rpmlib(PayloadFilesHavePrefix)`,`4.0-1`]],dU=new Set([`/usr`,`/usr/bin`,`/usr/lib`,`/usr/lib64`,`/usr/libexec`,`/usr/sbin`,`/usr/share`,`/usr/${SB.applications}`,`/usr/share/doc`,`/usr/share/icons`,`/usr/share/licenses`,`/usr/share/man`,`/usr/${SB.metainfo}`,`/usr/share/glib-2.0`,`/usr/${SB.schemas}`,`/usr/${SB.fonts}`,`/etc`,`/opt`,`/var`])});async function assemble(t){let n=process.cwd(),S=t.os===void 0?hostLayout():resolveLayout(t.os),C=await new Config().forCommand(n),N=C.ship??{},F=C.flatpak??{},I=resolveShipApp({project:C.app,perTarget:N.app,layoutOs:S.os}),H=I.app;I.overridden&&ge.log(`${pU} runtime for ${S.name}: ${H} — \`${I.key}\` overrides \`gjsify.app${C.app===void 0?``:`: "${C.app}"`}\`.`);let W=readPackageJson$2(wn(n,`package.json`))??{},q,Y=[];if(t.target!==void 0)q=resolveFormats(t.target,S);else if(N.targets!==void 0){let t=configuredFormats(N.targets,S);q=t.formats,t.dropped.length>0&&ge.log(`${pU} \`gjsify.ship.targets\` names ${t.dropped.join(`, `)}, which wrap another layout — not built for ${S.name}. Pass --target to ask for one explicitly.`)}else{let t=defaultFormatIds(S.os).map(t=>wH[t]);q=t.filter(t=>t.interpreters.includes(H)),Y=t.filter(t=>!t.interpreters.includes(H)),Y.length>0&&ge.log(`${pU} ${Y.map(t=>t.id).join(`, `)} wrap the ${S.name} layout but cannot run \`${H}\`, which \`${I.key}\` resolves to — ${Y[0]?.interpreterGap??``}. Set \`gjsify.ship.app.${S.os}\` to "${Y[0]?.interpreters.join(`" / "`)}" to ship this OS on that runtime; it leaves every other target on \`gjsify.app\`. Assembling the layout only; pass --target to be told the same thing as an error.`)}q.some(t=>t.id===`flatpak`)&&assertNoDroppedFlatpakModules(F),t.stage||assertPackable(q,S,t.os===void 0?`host`:`positional`,Y);let X=resolveSignPlan({flag:t.sign,config:N.sign,layoutOs:S.os}),Z=resolveNotaryPlan({flag:t.notarize,layoutOs:S.os,sign:X});if(t.stage&&assertNothingToSignYet(t),t.stage||(announceSigning(X,Z),X.kind===`sign`&&assertHostCanSign(X.signer)),t.stage||assertKindCanPack(q,resolveShipKind(N,F)),!t.stage)for(let t of q)assertCanPack(t);let te=parseDeclaredChannel(t.channel,`--channel`)??parseDeclaredChannel(N.channel,`gjsify.ship.channel`)??(q.some(t=>t.id===`flatpak`)?`flathub`:void 0);t[`skip-build`]||await runProjectBuild(n,te);let ne=resolveShipBundle({pkg:W,ship:N,layoutOs:S.os});ne.overridden&&ge.log(`${pU} entry for ${S.name}: ${ne.declared} — \`${ne.key}\` overrides \`gjsify.main\`.`);let re=discoverPayload({projectDir:n,pkg:W,ship:N,flatpakIcon:F.icon,declaredBundle:ne.declared,layoutOs:S.os,foreignBundles:ne.foreign}),{settings:ie,metadata:ae,warnings:oe}=resolveShipSettings({projectDir:n,pkg:W,ship:N,flatpak:F,cli:{outDir:t.out,arch:t.arch,layoutOs:S.os},discovered:re,app:H});for(let t of oe)ge.warn(`${pU} ${t}`);for(let t of q)assertFormatCanRunInterpreter(t,ie.app);let Q=readFileSync(ie.bundlePath,`utf-8`);assertEntryRunsUnder({interpreter:ie.app,source:Q,entry:Tn(n,ie.bundlePath)||ie.bundlePath,appKey:I.key,bundleKey:ne.key,layoutOs:S.os});let se=buildTimestamp(ie.bundlePath),ce={appId:ie.appId,name:ie.name,command:ie.binaryName,kind:ie.kind,metadata:ae,channel:te,configKey:`gjsify.ship`,copyrightYear:new Date(se*1e3).getUTCFullYear()};for(let t of validateAppMetadata(ce))ge.warn(`${pU} ${t.field} is not set — ${t.hint}`);ie.licenseFile!==void 0&&En(ie.licenseFile)!==n&&ge.log(`${pU} licence text from ${Tn(n,ie.licenseFile)} (this package carries none of its own)`);let le=localizeMetadata({metainfo:ie.kind===`app`?renderMetainfoApp$1(ce):renderMetainfoCli$1(ce),desktopEntry:ie.kind===`app`?renderDesktopEntry(ce):void 0},ie.localeFiles),ue=resolveCarriedRuntime(S,ie,n),de={bundleFiles:re.bundleFiles,launcher:renderLauncher(ie,Dn(ie.bundlePath),S,ue.launcher),metainfo:le.metainfo,desktopEntry:le.desktopEntry,licenseText:ie.licenseFile===void 0?void 0:readFileSync(ie.licenseFile,`utf-8`),changelogText:ie.changelogFile===void 0?void 0:readFileSync(ie.changelogFile,`utf-8`),mtime:se},fe=xn(n,ie.outDir),pe=wn(fe,`stage`),me=[...planStage(ie,de),...S.os===`linux`?[]:await compileSchemasForStage({schemaFiles:ie.schemaFiles,workDir:wn(fe,`schemas`)})],he=ie.kind===`app`&&S.icon!==void 0&&(S.icon.required||ie.iconFiles.length>0)?await resolveAppIcon({iconFiles:ie.iconFiles,appId:ie.appId,sizes:S.icon.sizes,target:S.icon.writes}):void 0;he!==void 0&&ge.log(`${pU} icon: ${iconSizes(he).join(`/`)} px, ${he.source}`);let _e=placeStage(S,{...ie,icon:he},me,ue.files);if(writeStage(pe,_e),ge.log(`${pU} staged ${_e.length} file(s) for ${S.name} in ${Tn(n,pe)}/`),t.verbose)for(let t of _e)ge.log(`${pU} ${t.path}`);if(assertPayloadMatchesArch(readStage([pe],_e),ie.arch),S.os!==`linux`){let t=linuxInstallDependent(me);if(t.length>0){ge.warn(`${pU} the ${S.name} layout carries ${t.length} file(s) whose Linux correctness comes from a package install step it has no equivalent for:`);let n={aborts:`ABORTS: `,unknown:`UNCLASSIFIED: `,inert:``};for(let{path:S,verdict:C,why:N}of t)ge.warn(`${pU} ${n[C]??``}${S} — ${N}`)}for(let t of ue.found)ge.log(`${pU} carries its own ${t}`);for(let t of ue.missing)ge.warn(`${pU} ${t}`);ue.launcher.interpreter===void 0&&S.runtimeGap!==void 0&&ge.warn(`${pU} ${S.runtimeGap}`),S.fontGap!==void 0&&me.some(t=>isUnder(t.path,SB.fonts))&&ge.warn(`${pU} ${S.fontGap}`),S.arches!==null&&!S.arches.only.includes(ie.arch)&&ge.warn(`${pU} this stage is labelled ${ie.arch} and the ${S.name} layout has no runtime for it — ${S.arches.why}. Nothing can pack this stage; \`--arch ${S.arches.only.join(`|`)}\` is what produces an artifact.`)}let ve=scanGiRequirements(Q),ye=ve.namespaces,be=ve.optional;if(t.verbose){let t=ye.filter(t=>!be.includes(t));ge.log(`${pU} gi namespaces: ${ye.join(`, `)||`(none)`}`),be.length>0&&(ge.log(`${pU} gi optional namespaces: ${be.join(`, `)}`),ge.log(`${pU} gi required namespaces: ${t.join(`, `)||`(none)`}`))}let xe=new Map;for(let t of q)xe.set(t.id,(await planOverlay(ie,t,de)).map(t=>({...t,path:place(S,ie,t.path)})));let Se=readPayloadFacts(me);for(let t of q){if(t.depends===null)continue;let n=deriveDepends(t.depends,{namespaces:ye,optionalNamespaces:be,hasIcons:Se.hasIcons,hasSchemas:Se.hasSchemas,interpreter:ie.app,extra:ie.extraDepends[t.depends],typelibPackages:ie.typelibPackages,bundledTypelibs:Se.bundledTypelibs,minGjsVersion:ie.minGjsVersion,minNodeVersion:ie.minNodeVersion});for(let S of n.unmappedOptional)ge.warn(`${pU} gi://${S} is imported optionally, but no ${t.depends} package is known to ship its typelib, so no Recommends entry names it. The package builds and runs without it. Add the row if the namespace should be recommended: \`gjsify.ship.typelibPackages.${S} = { "${t.depends}": "…" }\`.`);let S=ie.app===`node`?warnAboutNodeFloor(t.depends,ie.minNodeVersion):warnAboutGjsFloor(t.depends,ie.minGjsVersion);for(let t of S)ge.warn(`${pU} ${t}`)}let Ce=writeStageManifest({stageDir:pe,settings:ie,formats:q,mtime:se,namespaces:ye,optionalNamespaces:be,staged:_e,overlay:xe});if(t.stage){let t=Y.length>0?`(none — ${Y.map(t=>t.id).join(` and `)} need \`gjsify.ship.app.${S.os}: "node"\`)`:formatIdsFor(S.os).length===0?`(none — no format wraps the ${S.name} layout)`:`(none asked for)`,n=Ce.formats.join(`, `)||t;ge.log(`${pU} stage manifest: ${formatTarget(Ce.target)}, formats ${n}`);return}let we=[];for(let n of q)we.push(await packOne({format:n,settings:ie,arch:ie.arch,staged:_e,overlay:xe.get(n.id)??[],stageDir:pe,outRoot:fe,namespaces:ye,optionalNamespaces:be,mtime:se,sign:X,notarize:Z,verbose:t.verbose}));printArtifacts(n,we)}function assertNothingToSignYet(t){let n=t.sign===void 0?t.notarize===void 0?void 0:`--notarize`:`--sign`;if(n!==void 0)throw Error(`gjsify ship: ${n} belongs to the finish phase, and --stage produces no artifact to sign — it writes the tree a packing host reads back. Assemble here, then run \`gjsify ship --from-stage <dir> --sign <identity>\` on the host that holds the identity (ADR 0024 § A2, § A14).`)}function announceSigning(t,n){t.kind===`skip`&&ge.warn(`${pU} ${t.message}`),n.kind===`skip`&&t.kind===`sign`&&ge.warn(`${pU} ${n.message}`)}function resolveCarriedRuntime(t,n,S){let C={files:[],launcher:{},found:[],missing:[]};if(t.os===`linux`||n.app!==`node`)return C;let N=`${t.os}-${n.arch}`;return isGtkRuntimeTarget(N)?stageAppRuntime({layout:t,identity:n,target:N,cwd:S,interpreter:isNodeRuntimeTarget(N)?resolveNodeRuntime(N,{cwd:S}):null}):C}async function finishFromStage(t,n){if(t.stage)throw Error("gjsify ship: --stage and --from-stage are the two halves of one split and cannot run together. `--stage` assembles a payload and stops; `--from-stage <dir>` packs one that is already assembled. Run them as two commands, on the host each belongs on (ADR 0024 § A2).");if(t[`skip-build`])throw Error(`gjsify ship: --from-stage never runs a build — the payload it packs was built and staged by an earlier run — so --skip-build has nothing to skip. Drop it.`);if(t.arch!==void 0)throw Error("gjsify ship: --arch is decided when the stage is assembled, not when it is packed: the launcher, the payload and the recorded target were all fixed then. Pass --arch to `gjsify ship --stage`, and use `--expect-target <os>-<arch>` here to assert which leg you are packing.");if(t.os!==void 0)throw Error(`gjsify ship: the layout is decided when the stage is assembled, so "${t.os}" has nothing to change here — the staged tree already IS one OS's layout. Use \`--expect-target <os>-<arch>\` to assert which one you are packing.`);let S=process.cwd(),C=xn(S,n),N=readStageManifest(C);assertExpectedTarget(N,t[`expect-target`]);let F=layoutForOs(N.target.os);t.target===void 0&&assertPackable(N.formats.map(t=>wH[t]),F,`stage`,defaultFormatIds(F.os).map(t=>wH[t]).filter(t=>!t.interpreters.includes(N.settings.app)));let I=resolveFormats(t.target??N.formats,F);assertFormatsStaged(N,I);for(let t of I)assertCanPack(t);let H=resolveSignPlan({flag:t.sign,layoutOs:F.os}),W=resolveNotaryPlan({flag:t.notarize,layoutOs:F.os,sign:H});announceSigning(H,W),H.kind===`sign`&&assertHostCanSign(H.signer);for(let t of warnOnToolSkew(N))ge.warn(`${pU} ${t}`);let{mtime:q,warnings:Y}=resolveStageMtime(N);for(let t of Y)ge.warn(`${pU} ${t}`);if(ge.log(`${pU} packing ${N.settings.binaryName} ${N.settings.version}-${N.settings.release} for ${formatTarget(N.target)} from ${Tn(S,C)||`.`}/`),t.verbose){for(let t of N.staged)ge.log(`${pU} ${t.path}`);ge.log(`${pU} gi namespaces: ${N.namespaces.join(`, `)||`(none)`}`),(N.optionalNamespaces??[]).length>0&&ge.log(`${pU} gi optional namespaces: ${N.optionalNamespaces?.join(`, `)}`)}let X=t.out===void 0?En(C):xn(S,t.out),Z=[];for(let n of I){if(assertFormatCanRunInterpreter(n,N.settings.app),n.depends!==null){let t=N.settings.app===`node`?warnAboutNodeFloor(n.depends,N.settings.minNodeVersion):warnAboutGjsFloor(n.depends,N.settings.minGjsVersion);for(let n of t)ge.warn(`${pU} ${n}`)}Z.push(await packOne({format:n,settings:N.settings,arch:N.target.arch,staged:N.staged,overlay:overlayFiles(N,n.id),stageDir:C,outRoot:X,namespaces:N.namespaces,optionalNamespaces:N.optionalNamespaces??[],mtime:q,sign:H,notarize:W,verbose:t.verbose}))}printArtifacts(S,Z)}async function packOne(t){let{format:n,settings:S,stageDir:C,outRoot:N,mtime:F}=t;assertOverlayIsLicensed(n.id,S.binaryName,t.overlay);let I=wn(N,`overlay`,n.id);writeStage(I,t.overlay);let H=readStage([C,I],[...t.staged,...t.overlay]),W=readPayloadFacts(H),q=n.depends===null?{requires:[],recommends:[],unmappedOptional:[]}:deriveDepends(n.depends,{namespaces:t.namespaces,optionalNamespaces:t.optionalNamespaces,hasIcons:W.hasIcons,hasSchemas:W.hasSchemas,interpreter:S.app,extra:S.extraDepends[n.depends],typelibPackages:S.typelibPackages,bundledTypelibs:W.bundledTypelibs,minGjsVersion:S.minGjsVersion,minNodeVersion:S.minNodeVersion}),Y=q.requires,X=q.recommends;assertPayloadMatchesArch(H,t.arch);let Z=layoutForOs(n.layoutOs);assertLauncherMatchesInterpreter(H,Z,S,S.app),assertLayoutSupportsArch(Z,t.arch);let te=t.sign.kind===`sign`?await signPayload({payload:H,identity:t.sign.identity,signer:t.sign.signer,workDir:wn(N,`signed`,n.id),bundleRoot:Z.root(S),entitlementsPath:wn(N,`signed`,`${n.id}.entitlements.plist`),verbose:t.verbose,log:t=>ge.log(`${pU} ${t}`)}):H,ne=n.archName(t.arch,isArchIndependent(te)),re={settings:S,payload:te,prefix:n.prefix,depends:Y,recommends:X,archLabel:ne,mtime:F},ie=wn(N,`out`);mkdirSync(ie,{recursive:!0});let ae=wn(ie,n.fileName(S,ne));switch(n.id){case`deb`:writeFileSync(ae,await buildDeb(re));break;case`rpm`:writeFileSync(ae,await buildRpm(re));break;case`flatpak`:await buildFlatpakBundle({settings:S,stageDir:C,overlayDir:I,stageManifestFile:UH,workDir:wn(N,`flatpak`),target:ae,archLabel:ne,verbose:t.verbose});break;case`appimage`:{let n=appImageHostRequirements({app:S.app,minGjsVersion:S.minGjsVersion,minNodeVersion:S.minNodeVersion,namespaces:t.namespaces,optionalNamespaces:t.optionalNamespaces,bundledTypelibs:W.bundledTypelibs}),C=appDirFor(N),I=appDirPayload(S,te,n,await compileSchemasForPayload({payload:te,workDir:wn(N,`appimage-schemas`)}));writePayload(C,I,``),stampAppDirTimes(C,I,F),ge.log(`${pU} the AppImage takes these from the host: ${n.join(`, `)}`);let H=findPinnedRuntime(ne);ge.log(`${pU} ${appImageRuntimeNotice(ne,H)}`),await buildAppImage({appDir:C,target:ae,archLabel:ne,runtimeFile:H,workDir:En(C),verbose:t.verbose});break}case`macos-app`:case`windows-dir`:writePayload(ae,te,Z.root(S));break;case`macos-app-dmg`:{let n=dmgVolumeDir(N);writePayload(n,te,``),await buildDmgImage({volumeName:dmgVolumeName(S),sourceDir:n,target:ae,workDir:En(n),verbose:t.verbose});break}case`macos-app-zip`:writeFileSync(ae,buildZip(zipEntriesFromPayload(te),F));break;case`windows-dir-zip`:writeFileSync(ae,buildZip(zipEntriesFromPayload(te,windowsProgramDirName(S)),F));break;case`msi`:{let n=wn(N,`msi`);writePayload(wn(n,AH),te,Z.root(S)),await buildMsi({settings:S,files:te.map(t=>({path:t.path,source:`${AH}/${t.path}`})),programDirName:windowsProgramDirName(S),archLabel:ne,workDir:n,target:ae,verbose:t.verbose});break}default:{let t=n.id;throw Error(`gjsify ship: no packer is wired for format "${String(t)}".`)}}let oe=n.artifactKind===`directory`?directorySize(ae):statSync(ae).size;return t.notarize.kind===`notarize`&&(n.artifactKind===`directory`?ge.warn(`${pU} ${n.id} is a directory, and notarytool submits an archive or an installer — not notarised. The container format beside it is what carries the ticket.`):(await notarizeArtifact({plan:t.notarize,artifact:ae,verbose:t.verbose,log:t=>ge.log(`${pU} ${t}`)}),canCarryTicket(n.id)?await stapleArtifact({notary:t.notarize.notary,artifact:ae,verbose:t.verbose,log:t=>ge.log(`${pU} ${t}`)}):ge.warn(`${pU} ${n.id} is notarised and NOT stapled: \`stapler\` takes a UDIF image, a signed flat package or a code-signed bundle, and an archive is none of them. Apple's remedy is to staple each item that went INTO the archive and re-create it — for this artifact that is the \`.app\`, which \`--target macos-app\` writes beside it.`))),{format:n.id,path:ae,size:oe}}function printArtifacts(t,n){for(let S of n)ge.log(`${pU} ${S.format}: ${Tn(t,S.path)} (${S.size} bytes)`)}function assertCanPack(t){assertHostCanFinish(t),assertToolsInstalled(t)}function assertPackable(t,n,S,C=[]){if(t.length>0)return;if(C.length>0)throw Error(`gjsify ship: ${C.map(t=>t.id).join(` and `)} wrap the ${n.name} layout, and neither can run this project — ${C[0]?.interpreterGap??``}.\n Set \`gjsify.ship.app.${n.os}\` to "${C[0]?.interpreters.join(`" / "`)}" — it overrides \`gjsify.app\` for THIS target and\n leaves every other one alone, which is what lets one project be GJS on Linux and Node here.
1167
+ `)]},{tag:dU.BUILDTIME,type:4,value:[t.mtime]},{tag:dU.BUILDHOST,type:6,value:`localhost`},{tag:dU.SIZE,type:4,value:[n.reduce((t,n)=>t+n.data.byteLength,0)]},{tag:dU.LICENSE,type:6,value:N.license},{tag:dU.GROUP,type:9,value:[N.group]},{tag:dU.OS,type:6,value:`linux`},{tag:dU.ARCH,type:6,value:t.archLabel},{tag:dU.SOURCERPM,type:6,value:`${N.binaryName}-${F}.src.rpm`},{tag:dU.RPMVERSION,type:6,value:`4.20.0`},{tag:dU.ENCODING,type:6,value:`utf-8`},{tag:dU.FILESIZES,type:4,value:n.map(t=>t.data.byteLength)},{tag:dU.FILEMODES,type:3,value:n.map(t=>t.mode)},{tag:dU.FILERDEVS,type:3,value:n.map(()=>0)},{tag:dU.FILEMTIMES,type:4,value:n.map(()=>t.mtime)},{tag:dU.FILEDIGESTS,type:8,value:n.map(t=>t.isDirectory?``:hashHex(`sha256`,t.data))},{tag:dU.FILELINKTOS,type:8,value:n.map(()=>``)},{tag:dU.FILEFLAGS,type:4,value:n.map(()=>0)},{tag:dU.FILEUSERNAME,type:8,value:n.map(()=>`root`)},{tag:dU.FILEGROUPNAME,type:8,value:n.map(()=>`root`)},{tag:dU.FILEVERIFYFLAGS,type:4,value:n.map(()=>4294967295)},{tag:dU.FILEDEVICES,type:4,value:n.map(()=>1)},{tag:dU.FILEINODES,type:4,value:n.map((t,n)=>n+1)},{tag:dU.FILELANGS,type:8,value:n.map(()=>``)},{tag:dU.FILEDIGESTALGO,type:4,value:[mU]},{tag:dU.DIRINDEXES,type:4,value:H},{tag:dU.BASENAMES,type:8,value:W},{tag:dU.DIRNAMES,type:8,value:I},{tag:dU.PROVIDENAME,type:8,value:[N.binaryName]},{tag:dU.PROVIDEFLAGS,type:4,value:[pU.EQUAL]},{tag:dU.PROVIDEVERSION,type:8,value:[F]},{tag:dU.REQUIRENAME,type:8,value:Y.names},{tag:dU.REQUIREFLAGS,type:4,value:Y.flags},{tag:dU.REQUIREVERSION,type:8,value:Y.versions},...X.names.length>0?[{tag:dU.RECOMMENDNAME,type:8,value:X.names},{tag:dU.RECOMMENDFLAGS,type:4,value:X.flags},{tag:dU.RECOMMENDVERSION,type:8,value:X.versions}]:[],{tag:dU.PAYLOADFORMAT,type:6,value:`cpio`},{tag:dU.PAYLOADCOMPRESSOR,type:6,value:`gzip`},{tag:dU.PAYLOADFLAGS,type:6,value:`9`},{tag:dU.PAYLOADDIGEST,type:8,value:[hashHex(`sha256`,C)]},{tag:dU.PAYLOADDIGESTALGO,type:4,value:[mU]},{tag:dU.PAYLOADDIGESTALT,type:8,value:[hashHex(`sha256`,S)]}];return assertParallelFileArrays(Z,n.length),N.homepage&&Z.push({tag:dU.URL,type:6,value:N.homepage}),q.post!==void 0&&(Z.push({tag:dU.POSTIN,type:6,value:q.post}),Z.push({tag:dU.POSTINPROG,type:6,value:`/bin/sh`})),q.postun!==void 0&&(Z.push({tag:dU.POSTUN,type:6,value:q.postun}),Z.push({tag:dU.POSTUNPROG,type:6,value:`/bin/sh`})),Z}function assertParallelFileArrays(t,n){let S=new Set([dU.FILESIZES,dU.FILEMODES,dU.FILERDEVS,dU.FILEMTIMES,dU.FILEDIGESTS,dU.FILELINKTOS,dU.FILEFLAGS,dU.FILEUSERNAME,dU.FILEGROUPNAME,dU.FILEVERIFYFLAGS,dU.FILEDEVICES,dU.FILEINODES,dU.FILELANGS,dU.DIRINDEXES,dU.BASENAMES]);for(let C of t){if(!S.has(C.tag))continue;let t=Array.isArray(C.value)?C.value.length:1;if(t!==n)throw Error(`gjsify ship: internal error — rpm tag ${C.tag} has ${t} values for ${n} files.`)}}function buildRequires(t,n,S){let C=[],N=[],F=[];for(let n of t){let t=parseDepend(n);C.push(t.name),N.push(senseFor(t.relation)),F.push(t.version??``)}n.post!==void 0&&(C.push(`/bin/sh`),N.push(pU.INTERP|pU.SCRIPT_POST),F.push(``)),n.postun!==void 0&&(C.push(`/bin/sh`),N.push(pU.INTERP|pU.SCRIPT_POSTUN),F.push(``));for(let t of S)C.push(t),N.push(pU.FIND_REQUIRES),F.push(``);for(let[t,n]of hU)C.push(t),N.push(pU.RPMLIB|pU.LESS|pU.EQUAL),F.push(n);return{names:C,flags:N,versions:F}}function buildRecommends(t){let n=[],S=[],C=[];for(let N of t){let t=parseDepend(N);n.push(t.name),S.push(senseFor(t.relation)),C.push(t.version??``)}return{names:n,flags:S,versions:C}}function senseFor(t){switch(t){case`>=`:return pU.GREATER|pU.EQUAL;case`>`:return pU.GREATER;case`<=`:return pU.LESS|pU.EQUAL;case`<`:return pU.LESS;case`=`:return pU.EQUAL;default:return 0}}function hashHex(t,n){return createHash(t).update(n).digest(`hex`)}function hashBytes(t,n){return new Uint8Array(createHash(t).update(n).digest())}var dU,fU,pU,mU,hU,gU,_U=__esmMin(()=>{Qc(),pB(),aU(),TB(),AV(),uU(),EB(),kB(),OB(),dU={HEADERI18NTABLE:100,NAME:1e3,VERSION:1001,RELEASE:1002,SUMMARY:1004,DESCRIPTION:1005,BUILDTIME:1006,BUILDHOST:1007,SIZE:1009,LICENSE:1014,GROUP:1016,URL:1020,OS:1021,ARCH:1022,POSTIN:1024,POSTUN:1026,FILESIZES:1028,FILEMODES:1030,FILERDEVS:1033,FILEMTIMES:1034,FILEDIGESTS:1035,FILELINKTOS:1036,FILEFLAGS:1037,FILEUSERNAME:1039,FILEGROUPNAME:1040,SOURCERPM:1044,FILEVERIFYFLAGS:1045,PROVIDENAME:1047,REQUIREFLAGS:1048,REQUIRENAME:1049,REQUIREVERSION:1050,RECOMMENDNAME:5046,RECOMMENDVERSION:5047,RECOMMENDFLAGS:5048,RPMVERSION:1064,POSTINPROG:1086,POSTUNPROG:1088,FILEDEVICES:1095,FILEINODES:1096,FILELANGS:1097,PROVIDEFLAGS:1112,PROVIDEVERSION:1113,DIRINDEXES:1116,BASENAMES:1117,DIRNAMES:1118,PAYLOADFORMAT:1124,PAYLOADCOMPRESSOR:1125,PAYLOADFLAGS:1126,FILEDIGESTALGO:5011,ENCODING:5062,PAYLOADDIGEST:5092,PAYLOADDIGESTALGO:5093,PAYLOADDIGESTALT:5097},fU={SIZE:1e3,MD5:1004,PAYLOADSIZE:1007,SHA1HEADER:269,SHA256HEADER:273},pU={LESS:2,GREATER:4,EQUAL:8,INTERP:256,SCRIPT_POST:1024,SCRIPT_POSTUN:4096,FIND_REQUIRES:16384,RPMLIB:1<<24},mU=8,hU=[[`rpmlib(CompressedFileNames)`,`3.0.4-1`],[`rpmlib(FileDigests)`,`4.6.0-1`],[`rpmlib(PayloadFilesHavePrefix)`,`4.0-1`]],gU=new Set([`/usr`,`/usr/bin`,`/usr/lib`,`/usr/lib64`,`/usr/libexec`,`/usr/sbin`,`/usr/share`,`/usr/${DB.applications}`,`/usr/share/doc`,`/usr/share/icons`,`/usr/share/licenses`,`/usr/share/man`,`/usr/${DB.metainfo}`,`/usr/share/glib-2.0`,`/usr/${DB.schemas}`,`/usr/${DB.fonts}`,`/etc`,`/opt`,`/var`])});async function assemble(t){let n=process.cwd(),S=t.os===void 0?hostLayout():resolveLayout(t.os),C=await new Config().forCommand(n),N=C.ship??{},F=C.flatpak??{},I=resolveShipApp({project:C.app,perTarget:N.app,layoutOs:S.os}),H=I.app;I.overridden&&ge.log(`${vU} runtime for ${S.name}: ${H} — \`${I.key}\` overrides \`gjsify.app${C.app===void 0?``:`: "${C.app}"`}\`.`);let W=readPackageJson$2(wn(n,`package.json`))??{},q,Y=[];if(t.target!==void 0)q=resolveFormats(t.target,S);else if(N.targets!==void 0){let t=configuredFormats(N.targets,S);q=t.formats,t.dropped.length>0&&ge.log(`${vU} \`gjsify.ship.targets\` names ${t.dropped.join(`, `)}, which wrap another layout — not built for ${S.name}. Pass --target to ask for one explicitly.`)}else{let t=defaultFormatIds(S.os).map(t=>kH[t]);q=t.filter(t=>t.interpreters.includes(H)),Y=t.filter(t=>!t.interpreters.includes(H)),Y.length>0&&ge.log(`${vU} ${Y.map(t=>t.id).join(`, `)} wrap the ${S.name} layout but cannot run \`${H}\`, which \`${I.key}\` resolves to — ${Y[0]?.interpreterGap??``}. Set \`gjsify.ship.app.${S.os}\` to "${Y[0]?.interpreters.join(`" / "`)}" to ship this OS on that runtime; it leaves every other target on \`gjsify.app\`. Assembling the layout only; pass --target to be told the same thing as an error.`)}q.some(t=>t.id===`flatpak`)&&assertNoDroppedFlatpakModules(F),t.stage||assertPackable(q,S,t.os===void 0?`host`:`positional`,Y);let X=resolveSignPlan({flag:t.sign,config:N.sign,layoutOs:S.os}),Z=resolveNotaryPlan({flag:t.notarize,layoutOs:S.os,sign:X});if(t.stage&&assertNothingToSignYet(t),t.stage||(announceSigning(X,Z),X.kind===`sign`&&assertHostCanSign(X.signer)),t.stage||assertKindCanPack(q,resolveShipKind(N,F)),!t.stage)for(let t of q)assertCanPack(t);let te=parseDeclaredChannel(t.channel,`--channel`)??parseDeclaredChannel(N.channel,`gjsify.ship.channel`)??(q.some(t=>t.id===`flatpak`)?`flathub`:void 0);t[`skip-build`]||await runProjectBuild(n,te);let ne=resolveShipBundle({pkg:W,ship:N,layoutOs:S.os});ne.overridden&&ge.log(`${vU} entry for ${S.name}: ${ne.declared} — \`${ne.key}\` overrides \`gjsify.main\`.`);let re=discoverPayload({projectDir:n,pkg:W,ship:N,flatpakIcon:F.icon,declaredBundle:ne.declared,layoutOs:S.os,foreignBundles:ne.foreign}),{settings:ie,metadata:ae,warnings:oe}=resolveShipSettings({projectDir:n,pkg:W,ship:N,flatpak:F,cli:{outDir:t.out,arch:t.arch,layoutOs:S.os},discovered:re,app:H});for(let t of oe)ge.warn(`${vU} ${t}`);for(let t of q)assertFormatCanRunInterpreter(t,ie.app);let Q=readFileSync(ie.bundlePath,`utf-8`);assertEntryRunsUnder({interpreter:ie.app,source:Q,entry:Tn(n,ie.bundlePath)||ie.bundlePath,appKey:I.key,bundleKey:ne.key,layoutOs:S.os});let se=buildTimestamp(ie.bundlePath),ce={appId:ie.appId,name:ie.name,command:ie.binaryName,kind:ie.kind,metadata:ae,channel:te,configKey:`gjsify.ship`,copyrightYear:new Date(se*1e3).getUTCFullYear()};for(let t of validateAppMetadata(ce))ge.warn(`${vU} ${t.field} is not set — ${t.hint}`);ie.licenseFile!==void 0&&En(ie.licenseFile)!==n&&ge.log(`${vU} licence text from ${Tn(n,ie.licenseFile)} (this package carries none of its own)`);let le=localizeMetadata({metainfo:ie.kind===`app`?renderMetainfoApp$1(ce):renderMetainfoCli$1(ce),desktopEntry:ie.kind===`app`?renderDesktopEntry(ce):void 0},ie.localeFiles),ue=resolveCarriedRuntime(S,ie,n),de={bundleFiles:re.bundleFiles,launcher:renderLauncher(ie,Dn(ie.bundlePath),S,ue.launcher),metainfo:le.metainfo,desktopEntry:le.desktopEntry,licenseText:ie.licenseFile===void 0?void 0:readFileSync(ie.licenseFile,`utf-8`),changelogText:ie.changelogFile===void 0?void 0:readFileSync(ie.changelogFile,`utf-8`),mtime:se},fe=xn(n,ie.outDir),pe=wn(fe,`stage`),me=[...planStage(ie,de),...S.os===`linux`?[]:await compileSchemasForStage({schemaFiles:ie.schemaFiles,workDir:wn(fe,`schemas`)})],he=ie.kind===`app`&&S.icon!==void 0&&(S.icon.required||ie.iconFiles.length>0)?await resolveAppIcon({iconFiles:ie.iconFiles,appId:ie.appId,sizes:S.icon.sizes,target:S.icon.writes}):void 0;he!==void 0&&ge.log(`${vU} icon: ${iconSizes(he).join(`/`)} px, ${he.source}`);let _e=placeStage(S,{...ie,icon:he},me,ue.files);if(writeStage(pe,_e),ge.log(`${vU} staged ${_e.length} file(s) for ${S.name} in ${Tn(n,pe)}/`),t.verbose)for(let t of _e)ge.log(`${vU} ${t.path}`);if(assertPayloadMatchesArch(readStage([pe],_e),ie.arch),S.os!==`linux`){let t=linuxInstallDependent(me);if(t.length>0){ge.warn(`${vU} the ${S.name} layout carries ${t.length} file(s) whose Linux correctness comes from a package install step it has no equivalent for:`);let n={aborts:`ABORTS: `,unknown:`UNCLASSIFIED: `,inert:``};for(let{path:S,verdict:C,why:N}of t)ge.warn(`${vU} ${n[C]??``}${S} — ${N}`)}for(let t of ue.found)ge.log(`${vU} carries its own ${t}`);for(let t of ue.missing)ge.warn(`${vU} ${t}`);ue.launcher.interpreter===void 0&&S.runtimeGap!==void 0&&ge.warn(`${vU} ${S.runtimeGap}`),S.fontGap!==void 0&&me.some(t=>isUnder(t.path,DB.fonts))&&ge.warn(`${vU} ${S.fontGap}`),S.arches!==null&&!S.arches.only.includes(ie.arch)&&ge.warn(`${vU} this stage is labelled ${ie.arch} and the ${S.name} layout has no runtime for it — ${S.arches.why}. Nothing can pack this stage; \`--arch ${S.arches.only.join(`|`)}\` is what produces an artifact.`)}let ve=scanGiRequirements(Q),ye=ve.namespaces,be=ve.optional;if(t.verbose){let t=ye.filter(t=>!be.includes(t));ge.log(`${vU} gi namespaces: ${ye.join(`, `)||`(none)`}`),be.length>0&&(ge.log(`${vU} gi optional namespaces: ${be.join(`, `)}`),ge.log(`${vU} gi required namespaces: ${t.join(`, `)||`(none)`}`))}let xe=new Map;for(let t of q)xe.set(t.id,(await planOverlay(ie,t,de)).map(t=>({...t,path:place(S,ie,t.path)})));let Se=readPayloadFacts(me);for(let t of q){if(t.depends===null)continue;let n=deriveDepends(t.depends,{namespaces:ye,optionalNamespaces:be,hasIcons:Se.hasIcons,hasSchemas:Se.hasSchemas,interpreter:ie.app,extra:ie.extraDepends[t.depends],typelibPackages:ie.typelibPackages,bundledTypelibs:Se.bundledTypelibs,minGjsVersion:ie.minGjsVersion,minNodeVersion:ie.minNodeVersion});for(let S of n.unmappedOptional)ge.warn(`${vU} gi://${S} is imported optionally, but no ${t.depends} package is known to ship its typelib, so no Recommends entry names it. The package builds and runs without it. Add the row if the namespace should be recommended: \`gjsify.ship.typelibPackages.${S} = { "${t.depends}": "…" }\`.`);let S=ie.app===`node`?warnAboutNodeFloor(t.depends,ie.minNodeVersion):warnAboutGjsFloor(t.depends,ie.minGjsVersion);for(let t of S)ge.warn(`${vU} ${t}`)}let Ce=writeStageManifest({stageDir:pe,settings:ie,formats:q,mtime:se,namespaces:ye,optionalNamespaces:be,staged:_e,overlay:xe});if(t.stage){let t=Y.length>0?`(none — ${Y.map(t=>t.id).join(` and `)} need \`gjsify.ship.app.${S.os}: "node"\`)`:formatIdsFor(S.os).length===0?`(none — no format wraps the ${S.name} layout)`:`(none asked for)`,n=Ce.formats.join(`, `)||t;ge.log(`${vU} stage manifest: ${formatTarget(Ce.target)}, formats ${n}`);return}let we=[];for(let n of q)we.push(await packOne({format:n,settings:ie,arch:ie.arch,staged:_e,overlay:xe.get(n.id)??[],stageDir:pe,outRoot:fe,namespaces:ye,optionalNamespaces:be,mtime:se,sign:X,notarize:Z,verbose:t.verbose}));printArtifacts(n,we)}function assertNothingToSignYet(t){let n=t.sign===void 0?t.notarize===void 0?void 0:`--notarize`:`--sign`;if(n!==void 0)throw Error(`gjsify ship: ${n} belongs to the finish phase, and --stage produces no artifact to sign — it writes the tree a packing host reads back. Assemble here, then run \`gjsify ship --from-stage <dir> --sign <identity>\` on the host that holds the identity (ADR 0024 § A2, § A14).`)}function announceSigning(t,n){t.kind===`skip`&&ge.warn(`${vU} ${t.message}`),n.kind===`skip`&&t.kind===`sign`&&ge.warn(`${vU} ${n.message}`)}function resolveCarriedRuntime(t,n,S){let C={files:[],launcher:{},found:[],missing:[]};if(t.os===`linux`||n.app!==`node`)return C;let N=`${t.os}-${n.arch}`;return isGtkRuntimeTarget(N)?stageAppRuntime({layout:t,identity:n,target:N,cwd:S,interpreter:isNodeRuntimeTarget(N)?resolveNodeRuntime(N,{cwd:S}):null}):C}async function finishFromStage(t,n){if(t.stage)throw Error("gjsify ship: --stage and --from-stage are the two halves of one split and cannot run together. `--stage` assembles a payload and stops; `--from-stage <dir>` packs one that is already assembled. Run them as two commands, on the host each belongs on (ADR 0024 § A2).");if(t[`skip-build`])throw Error(`gjsify ship: --from-stage never runs a build — the payload it packs was built and staged by an earlier run — so --skip-build has nothing to skip. Drop it.`);if(t.arch!==void 0)throw Error("gjsify ship: --arch is decided when the stage is assembled, not when it is packed: the launcher, the payload and the recorded target were all fixed then. Pass --arch to `gjsify ship --stage`, and use `--expect-target <os>-<arch>` here to assert which leg you are packing.");if(t.os!==void 0)throw Error(`gjsify ship: the layout is decided when the stage is assembled, so "${t.os}" has nothing to change here — the staged tree already IS one OS's layout. Use \`--expect-target <os>-<arch>\` to assert which one you are packing.`);let S=process.cwd(),C=xn(S,n),N=readStageManifest(C);assertExpectedTarget(N,t[`expect-target`]);let F=layoutForOs(N.target.os);t.target===void 0&&assertPackable(N.formats.map(t=>kH[t]),F,`stage`,defaultFormatIds(F.os).map(t=>kH[t]).filter(t=>!t.interpreters.includes(N.settings.app)));let I=resolveFormats(t.target??N.formats,F);assertFormatsStaged(N,I);for(let t of I)assertCanPack(t);let H=resolveSignPlan({flag:t.sign,layoutOs:F.os}),W=resolveNotaryPlan({flag:t.notarize,layoutOs:F.os,sign:H});announceSigning(H,W),H.kind===`sign`&&assertHostCanSign(H.signer);for(let t of warnOnToolSkew(N))ge.warn(`${vU} ${t}`);let{mtime:q,warnings:Y}=resolveStageMtime(N);for(let t of Y)ge.warn(`${vU} ${t}`);if(ge.log(`${vU} packing ${N.settings.binaryName} ${N.settings.version}-${N.settings.release} for ${formatTarget(N.target)} from ${Tn(S,C)||`.`}/`),t.verbose){for(let t of N.staged)ge.log(`${vU} ${t.path}`);ge.log(`${vU} gi namespaces: ${N.namespaces.join(`, `)||`(none)`}`),(N.optionalNamespaces??[]).length>0&&ge.log(`${vU} gi optional namespaces: ${N.optionalNamespaces?.join(`, `)}`)}let X=t.out===void 0?En(C):xn(S,t.out),Z=[];for(let n of I){if(assertFormatCanRunInterpreter(n,N.settings.app),n.depends!==null){let t=N.settings.app===`node`?warnAboutNodeFloor(n.depends,N.settings.minNodeVersion):warnAboutGjsFloor(n.depends,N.settings.minGjsVersion);for(let n of t)ge.warn(`${vU} ${n}`)}Z.push(await packOne({format:n,settings:N.settings,arch:N.target.arch,staged:N.staged,overlay:overlayFiles(N,n.id),stageDir:C,outRoot:X,namespaces:N.namespaces,optionalNamespaces:N.optionalNamespaces??[],mtime:q,sign:H,notarize:W,verbose:t.verbose}))}printArtifacts(S,Z)}async function packOne(t){let{format:n,settings:S,stageDir:C,outRoot:N,mtime:F}=t;assertOverlayIsLicensed(n.id,S.binaryName,t.overlay);let I=wn(N,`overlay`,n.id);writeStage(I,t.overlay);let H=readStage([C,I],[...t.staged,...t.overlay]),W=readPayloadFacts(H),q=n.depends===null?{requires:[],recommends:[],unmappedOptional:[]}:deriveDepends(n.depends,{namespaces:t.namespaces,optionalNamespaces:t.optionalNamespaces,hasIcons:W.hasIcons,hasSchemas:W.hasSchemas,interpreter:S.app,extra:S.extraDepends[n.depends],typelibPackages:S.typelibPackages,bundledTypelibs:W.bundledTypelibs,minGjsVersion:S.minGjsVersion,minNodeVersion:S.minNodeVersion}),Y=q.requires,X=q.recommends;assertPayloadMatchesArch(H,t.arch);let Z=layoutForOs(n.layoutOs);assertLauncherMatchesInterpreter(H,Z,S,S.app),assertLayoutSupportsArch(Z,t.arch);let te=t.sign.kind===`sign`?await signPayload({payload:H,identity:t.sign.identity,signer:t.sign.signer,workDir:wn(N,`signed`,n.id),bundleRoot:Z.root(S),entitlementsPath:wn(N,`signed`,`${n.id}.entitlements.plist`),verbose:t.verbose,log:t=>ge.log(`${vU} ${t}`)}):H,ne=n.archName(t.arch,isArchIndependent(te)),re={settings:S,payload:te,prefix:n.prefix,depends:Y,recommends:X,archLabel:ne,mtime:F},ie=wn(N,`out`);mkdirSync(ie,{recursive:!0});let ae=wn(ie,n.fileName(S,ne));switch(n.id){case`deb`:writeFileSync(ae,await buildDeb(re));break;case`rpm`:writeFileSync(ae,await buildRpm(re));break;case`flatpak`:await buildFlatpakBundle({settings:S,stageDir:C,overlayDir:I,stageManifestFile:JH,workDir:wn(N,`flatpak`),target:ae,archLabel:ne,verbose:t.verbose});break;case`appimage`:{let n=appImageHostRequirements({app:S.app,minGjsVersion:S.minGjsVersion,minNodeVersion:S.minNodeVersion,namespaces:t.namespaces,optionalNamespaces:t.optionalNamespaces,bundledTypelibs:W.bundledTypelibs}),C=appDirFor(N),I=appDirPayload(S,te,n,await compileSchemasForPayload({payload:te,workDir:wn(N,`appimage-schemas`)}));writePayload(C,I,``),stampAppDirTimes(C,I,F),ge.log(`${vU} the AppImage takes these from the host: ${n.join(`, `)}`);let H=findPinnedRuntime(ne);ge.log(`${vU} ${appImageRuntimeNotice(ne,H)}`),await buildAppImage({appDir:C,target:ae,archLabel:ne,runtimeFile:H,workDir:En(C),verbose:t.verbose});break}case`macos-app`:case`windows-dir`:writePayload(ae,te,Z.root(S));break;case`macos-app-dmg`:{let n=dmgVolumeDir(N);writePayload(n,te,``),await buildDmgImage({volumeName:dmgVolumeName(S),sourceDir:n,target:ae,workDir:En(n),verbose:t.verbose});break}case`macos-app-zip`:writeFileSync(ae,buildZip(zipEntriesFromPayload(te),F));break;case`windows-dir-zip`:writeFileSync(ae,buildZip(zipEntriesFromPayload(te,windowsProgramDirName(S)),F));break;case`msi`:{let n=wn(N,`msi`);writePayload(wn(n,FH),te,Z.root(S)),await buildMsi({settings:S,files:te.map(t=>({path:t.path,source:`${FH}/${t.path}`})),programDirName:windowsProgramDirName(S),archLabel:ne,workDir:n,target:ae,verbose:t.verbose});break}default:{let t=n.id;throw Error(`gjsify ship: no packer is wired for format "${String(t)}".`)}}let oe=n.artifactKind===`directory`?directorySize(ae):statSync(ae).size;return t.notarize.kind===`notarize`&&(n.artifactKind===`directory`?ge.warn(`${vU} ${n.id} is a directory, and notarytool submits an archive or an installer — not notarised. The container format beside it is what carries the ticket.`):(await notarizeArtifact({plan:t.notarize,artifact:ae,verbose:t.verbose,log:t=>ge.log(`${vU} ${t}`)}),canCarryTicket(n.id)?await stapleArtifact({notary:t.notarize.notary,artifact:ae,verbose:t.verbose,log:t=>ge.log(`${vU} ${t}`)}):ge.warn(`${vU} ${n.id} is notarised and NOT stapled: \`stapler\` takes a UDIF image, a signed flat package or a code-signed bundle, and an archive is none of them. Apple's remedy is to staple each item that went INTO the archive and re-create it — for this artifact that is the \`.app\`, which \`--target macos-app\` writes beside it.`))),{format:n.id,path:ae,size:oe}}function printArtifacts(t,n){for(let S of n)ge.log(`${vU} ${S.format}: ${Tn(t,S.path)} (${S.size} bytes)`)}function assertCanPack(t){assertHostCanFinish(t),assertToolsInstalled(t)}function assertPackable(t,n,S,C=[]){if(t.length>0)return;if(C.length>0)throw Error(`gjsify ship: ${C.map(t=>t.id).join(` and `)} wrap the ${n.name} layout, and neither can run this project — ${C[0]?.interpreterGap??``}.\n Set \`gjsify.ship.app.${n.os}\` to "${C[0]?.interpreters.join(`" / "`)}" — it overrides \`gjsify.app\` for THIS target and\n leaves every other one alone, which is what lets one project be GJS on Linux and Node here.
1168
1168
  \`gjsify ship ${n.name} --stage\` assembles the tree either way.`);let N=formatIdsFor(n.os).sort();if(N.length>0){let t=S===`stage`?`${n.name} --stage --target`:`${n.name} --target`;throw Error(`gjsify ship: this run records no formats for the ${n.name} layout, so there is nothing to pack — and it is not that none exist: ${N.join(`, `)} wrap it.\n An empty list means none were SELECTED. \`gjsify.ship.targets\` is filtered to the layout being assembled,
1169
1169
  so a configured list naming only another OS's formats leaves this one empty and says so at stage time.
1170
- Name one where the payload is assembled: \`gjsify ship ${t} ${N[0]}\`.`)}let F=defaultFormatIds(`linux`).join(`,`),I={host:`This host is ${process.platform}, so \`gjsify ship\` assembled the ${n.name} layout. Assembly is not host-bound (ADR 0024 § A1), so the Linux packages are still one word away: \`gjsify ship linux\` builds ${F} from right here.`,positional:`\`gjsify ship ${n.name} --stage\` assembles the payload and stops, which is the whole of what this command does for that OS today.`,stage:`This stage carries the ${n.name} layout and nothing here can wrap it — a stage is a build intermediate, not an artifact. Keep it for the milestone that packs it, or re-assemble with \`gjsify ship linux --stage\` if a Linux package is what you wanted.`}[S];throw Error(`gjsify ship: no format wraps the ${n.name} layout, so there is nothing to pack. ${I} Every layout this gjsify knows has one (ADR 0024 stages 2-5), so this is a layout added without a \`FORMATS\` row.`)}function assertFormatCanRunInterpreter(t,n){if(!t.interpreters.includes(n))throw Error(`gjsify ship: this ${t.layoutOs} target runs \`${n}\`, and the ${t.id} runtime cannot run it — it provides ${t.interpreters.join(`, `)}.\n ${t.interpreterGap}.\n Build the formats that wrap this layout and can run it, or set \`gjsify.ship.app.${t.layoutOs}: "${t.interpreters.join(`" / "`)}"\` (which overrides \`gjsify.app\` for this target alone).`)}async function runProjectBuild(t,n){if(typeof readPackageJson$2(wn(t,`package.json`))?.scripts?.build!=`string`)throw Error("gjsify ship: this project has no `build` script to run. Add one, or pass --skip-build to package what is already built.");ge.log(`${pU} running the project's build script`);let S=await spawnToCompletion(`gjsify`,[`run`,`build`],{completion:`return`,cwd:t,stdio:`inherit`,env:n===void 0?void 0:{...process.env,[sh]:n},notFound:()=>Error("gjsify ship: `gjsify` is not on PATH, so the project build cannot be run. Build the project yourself and pass --skip-build.")});if(S.code!==0)throw Error(`gjsify ship: the project's build script failed with ${describeExit(S)}.`)}var pU,mU,hU=__esmMin(()=>{_e(),ch(),Rd(),Pn(),TI(),wz(),$P(),V_(),EV(),bB(),QV(),VV(),sH(),uH(),Sz(),dH(),kB(),fH(),DH(),uV(),UV(),CB(),hV(),jH(),zH(),VH(),lI(),TV(),JV(),JH(),YH(),fU(),LV(),WH(),GH(),pU=`[gjsify ship]`,mU={command:`ship [os]`,description:`Build installable artifacts (${TH.join(`, `)}) from the current project.`,builder:t=>t.positional(`os`,{type:`string`,description:`Operating system whose LAYOUT to assemble (${cV.join(`|`)}, ADR 0024 § A2). Default: this host. Assembly is not host-bound, so any of them can be staged anywhere.`}).option(`target`,{type:`string`,array:!0,description:`Formats to build, comma-separated or repeated. Default: every format wrapping the target OS's layout that needs no extra tooling — on linux, ${defaultFormatIds(`linux`).join(`,`)}. Also available for linux, and opt-in because it needs tooling this CLI does not carry: ${formatIdsFor(`linux`).filter(t=>!defaultFormatIds(`linux`).includes(t)).join(`, `)}.`}).option(`out`,{type:`string`,normalize:!0,description:"Output root, relative to the project. Default: `gjsify.ship.outDir`, else `ship`."}).option(`stage`,{type:`boolean`,default:!1,description:`Produce the staged payload and stop, without packing anything.`}).option(`from-stage`,{type:`string`,normalize:!0,description:"Pack a staged payload written by an earlier `--stage` run. Needs no project: the stage carries its own closure."}).option(`expect-target`,{type:`string`,description:"With --from-stage: refuse unless the stage was assembled for this `<os>-<arch>`, e.g. `linux-arm64`."}).option(`channel`,{type:`string`,choices:[...ah],description:"Distribution channel (ADR 0113). Overrides gjsify.ship.channel; `--target flatpak` implies flathub. Passed to the project build, and gates the metainfo donation URL."}).option(`skip-build`,{type:`boolean`,default:!1,description:"Package what is already built instead of running the project's `build` script."}).option(`arch`,{type:`string`,description:"Target architecture in `process.arch` spelling. Default: this host."}).option(`sign`,{type:`string`,requiresArg:!0,description:"Sign the payload with this identity, e.g. a Developer ID name or SHA-1 fingerprint. `-` signs ad-hoc and needs no developer identity. Default: `gjsify.ship.sign.<darwin|win32>.identity`; absent means unsigned, which is a legitimate output."}).option(`notarize`,{type:`string`,requiresArg:!0,description:"Submit the signed artifact to Apple with this `notarytool` keychain profile. Needs --sign; darwin only."}).option(`verbose`,{type:`boolean`,default:!1,description:`Print each staged file, the GI namespaces the bundle imports, and every tool a host-bound packer invokes.`}),handler:async t=>{if(t[`from-stage`]!==void 0)return await finishFromStage(t,t[`from-stage`]);await assemble(t)}}});function forceExit(t){if(process.exitCode=t,!gjsExit(t))return process.exit(t)}var gU=__esmMin(()=>{d_()});function workspaceLinkTarget(t,n){return _U===`junction`?xn(n):Tn(En(t),n)}function applyPlatformConfigFromFlags(t){for(let[n,S]of[[`os`,`npm_config_os`],[`cpu`,`npm_config_cpu`],[`libc`,`npm_config_libc`]]){let C=t[n];if(typeof C!=`string`)continue;let N=C.trim();N!==``&&(process.env[S]=N)}t.force&&(process.env.npm_config_force=`true`)}function isAbortedFromOverallTimeout(t){if(!t||typeof t!=`object`)return!1;let n=t.name;if(n===`AbortError`)return!0;let S=t.message;return!!(typeof S==`string`&&S.includes(`install-overall-timeout`)||n===`RegistryTimeoutError`)}function readCliVersionFrom(t){try{if(!existsSync(t))return null;let n=JSON.parse(readFileSync(t,`utf-8`));if(n.name===bU&&typeof n.version==`string`)return n.version}catch{}return null}function readRunningCliVersion(){try{let t=En(xn(fileURLToPath(import.meta.url)));for(let n=0;n<8&&t!==En(t);n++){let n=readCliVersionFrom(wn(t,`package.json`));if(n)return n;t=En(t)}}catch{}return null}function readWorkspaceCliVersion(t){let n=readPackageJson$1(wn(t,`package.json`)),S=!1;for(let t of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n?.[t]?.[bU];typeof C==`string`&&(S=!0);let N=typeof C==`string`?/^[\^~=v]*(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(C.trim()):null;if(N)return N[1]}if(!S){let n=readCliVersionFrom(wn(t,`node_modules`,bU,`package.json`));if(n)return n}return readCliVersionFrom(wn(t,`packages`,`infra`,`cli`,`package.json`))}function warnOnCliVersionSkew(t){if(process.env.GJSIFY_NO_VERSION_SKEW_WARNING===`1`)return;let n=readRunningCliVersion(),S=readWorkspaceCliVersion(t);!n||!S||n===S||ge.warn(`gjsify install: version skew — you are running @gjsify/cli v${n}, but this workspace pins v${S}.\n A mismatched CLI can stall the install (lock discarded → full re-resolve) or silently produce a wrong build.\n Align them: run \`gjsify self-update\` (global CLI) or use the workspace-local \`node_modules/.bin/gjsify\`.\n Suppress this with GJSIFY_NO_VERSION_SKEW_WARNING=1.`)}function isWorkspaceRoot(t){let n=readPackageJson$1(wn(t,`package.json`));return n?n.workspaces!==void 0:!1}function optionalDependencyNames(t){let n=new Set,S=new Set;for(let C of t){let t=new Set(Object.keys(C.optionalDependencies??{}));for(let S of t)n.add(S);for(let n of[`dependencies`,`devDependencies`])for(let N of Object.keys(C[n]??{}))t.has(N)||S.add(N)}for(let t of S)n.delete(t);return n}function depKindFromArgs(t){return t[`save-dev`]?`devDependencies`:t[`save-peer`]?`peerDependencies`:t[`save-optional`]?`optionalDependencies`:`dependencies`}function activateDevLinks(t,n){let S=prepareDevLinks(devLinkRoot(t));if(!S)return null;let C=applyDevLinks(S.links);if(!n)return S;ge.log(`gjsify install: development link ACTIVE (${S.overridePath}) — ${S.links.length} package(s) come from ${S.checkout}, linked rather than fetched (${C.length} (re)written, ${S.links.length-C.length} already current):`);let N=S.links.map(t=>t.name),F=N.slice(0,12);return ge.log(` ${F.join(`, `)}${N.length>F.length?`, +${N.length-F.length} more`:``}`),ge.log(" `gjsify unlink` restores the registry copies; `gjsify install --immutable` refuses while it exists."),S}function reportRewiredDevLinks(t){if(!t)return;let n=applyDevLinks(t.links);n.length!==0&&ge.log(`gjsify install: re-applied ${n.length} development link(s) the install had replaced: ${n.map(t=>t.name).join(`, `)}`)}async function projectInstallNative(t,n){let S=process.cwd(),C=wn(S,`package.json`),N=[`.pnp.cjs`,`.pnp.loader.mjs`].filter(t=>existsSync(wn(S,t)));if(N.length>0)throw Error(`gjsify install uses the node_modules linker and cannot run in a Yarn PnP project (found ${N.join(`, `)} in ${S}).\n\n• If this project uses \`gjsify install\` to manage dependencies, these PnP files are stale residue from an earlier \`yarn install\` — remove them and re-run:\n rm -f .pnp.cjs .pnp.loader.mjs && rm -rf .yarn/cache .yarn/unplugged\n gjsify install\n\n• If instead you want Yarn to manage dependencies, set \`nodeLinker: node-modules\` in .yarnrc.yml and run \`yarn install\` (not \`gjsify install\`).`);if(!t.packages||t.packages.length===0){let C=isWorkspaceRoot(S)?S:findWorkspaceRoot(S);if(C){C!==S&&ge.log(`gjsify install: resolved workspace root ${C} (from ${S}); installing the workspace.`),await workspaceInstall(C,t,n);return}}let F,I=readPackageJson$1(C),H=I?projectSpecsFromPackageJson(I):[];if(t.packages&&t.packages.length>0){let n=new Set(t.packages.map(t=>parseSpec$2(t).name));F=[...H.filter(t=>!n.has(parseSpec$2(t).name)),...t.packages]}else{if(!I)throw Error(`gjsify install: no package.json in ${S}`);if(F=H,F.length===0){ge.log(`gjsify install: no dependencies declared in package.json — nothing to do.`);return}}mkdirSync(S,{recursive:!0});let W=makeProgressReporter({enabled:!t.verbose&&!t.quiet&&t.progress!==!1}),q=await acquireInstallLock(S,{signal:n});try{let N=activateDevLinks(S,!0),H=await installPackages({prefix:S,specs:F,verbose:t.verbose,lockfile:!t.immutable,frozen:t.immutable,refreshLockfile:t[`refresh-lockfile`],signal:n,progress:W,optionalSpecs:new Set([...optionalDependencyNames(I?[I]:[]),...t[`save-optional`]?(t.packages??[]).map(t=>parseSpec$2(t).name):[]]),linkedNames:N?.names});if(reportRewiredDevLinks(N),t.packages&&t.packages.length>0&&I){let n=depKindFromArgs(t);for(let S of t.packages){let{name:t,range:C}=parseSpec$2(S),N=H.installed.find(n=>n.name===t);addDependencyEntry(I,t,C??(N?defaultRangeFromVersion(N.version):`latest`),n)}writePackageJson(C,I),t.immutable||syncLockfileRequested(S,projectSpecsFromPackageJson(I))}}finally{q.release()}}function syncLockfileRequested(t,n){let S=wn(t,`gjsify-lock.json`);if(existsSync(S))try{let t=JSON.parse(readFileSync(S,`utf-8`)),C=[...n].sort(),N=[...t.requested??[]].sort();if(C.length===N.length&&C.every((t,n)=>t===N[n]))return;t.requested=n,atomicWriteStrict(S,JSON.stringify(t,null,2)+`
1171
- `)}catch{}}async function workspaceInstall(t,n,S){let C=await acquireInstallLock(t,{signal:S});try{await workspaceInstallLocked(t,n,S)}finally{C.release()}}async function workspaceInstallLocked(t,n,S){let C=discoverWorkspaces(t,{includeRoot:!0});if(C.length===0)throw Error(`gjsify install: ${t} has a "workspaces" field but no workspaces were discovered`);let N=new Map(C.map(t=>[t.name,t])),F=n.focus&&n.focus.length>0?planFocus(C,n.focus,`gjsify install`):void 0,I=F?new Set(F.workspaces):void 0,H=new Set,W=new Map,q=[];for(let t of C){let n=t.manifest;for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n[S];if(C)for(let[n,S]of Object.entries(C)){if(typeof S!=`string`)continue;let C=N.get(n);if(C&&!/^(link|file|portal|git\+|https?):/.test(S)){if(I&&!I.has(t))continue;q.push({fromWorkspaceName:t.name,depName:n,targetLocation:C.location});continue}if(S.startsWith(`workspace:`))throw Error(`gjsify install: ${t.name} declares "${n}: ${S}" but no workspace with that name exists`);if(/^(link|file|portal|git\+|https?):/.test(S))continue;let F=`${n}@${S}`;H.add(F);let Y=W.get(F);Y||(Y=new Set,W.set(F,Y)),Y.add(t.name)}}}ge.log(`gjsify install: ${C.length} workspace(s), ${H.size} external dep spec(s), ${q.length} workspace symlink(s)`);let Y=activateDevLinks(t,!0);writeWorkspaceBinShims(t,F?.workspaces??C);let wireWorkspaceSymlinks=async()=>{if(q.length>0){let t=await Promise.resolve().then(()=>(xd(),vd)),n=new Set,S=[];for(let t of q){let C=N.get(t.fromWorkspaceName);if(!C)continue;let F=wn(C.location,`node_modules`,t.depName);n.add(En(F));let I=workspaceLinkTarget(F,t.targetLocation);S.push({linkPath:F,relTarget:I})}await Promise.all([...n].map(n=>t.mkdir(n,{recursive:!0})));let C=0,F=[],wireOne=async(n,S)=>{try{await t.rm(n,{recursive:!0,force:!0,maxRetries:10,retryDelay:100})}catch{}await t.symlink(S,n,_U)};for(let t=0;t<Math.min(32,S.length);t++)F.push((async()=>{for(;;){let t=C++;if(t>=S.length)return;let n=S[t];if(!n)return;await wireOne(n.linkPath,n.relTarget)}})());await Promise.all(F),ge.log(`gjsify install: wired ${q.length} workspace symlink(s)`)}let n=wn(t,`node_modules`),S=0;for(let N of F?.workspaces??C){if(N.location===t||!N.name)continue;let C=wn(n,N.name),F=!1;try{lstatSync(C),F=!0}catch{}F||(mkdirSync(En(C),{recursive:!0}),symlinkSync(workspaceLinkTarget(C,N.location),C,_U),S++)}S>0&&ge.log(`gjsify install: hoisted ${S} workspace(s) to root node_modules/`)};await wireWorkspaceSymlinks();let X=C.find(n=>n.location===t)?.manifest,Z=extractOverrides(X),te=Z?.global,ne=new Map,re=new Set;if(Z&&Z.scoped.size>0){for(let t of F?.workspaces??C){let n=t.manifest;for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n[S];if(C)for(let[n,S]of Object.entries(C)){let C=scopedOverrideFor(t,n,Z);if(!C)continue;let N=C,F=t.location,I=ne.get(F);I||(I=new Set,ne.set(F,I)),I.add(`${n}@${N}`),re.add(`${n}@${S}`)}}}let t=new Set;for(let n of C)for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n.manifest[S];if(C)for(let[S,N]of Object.entries(C))scopedOverrideFor(n,S,Z)||t.add(`${S}@${N}`)}for(let n of re)t.has(n)||H.delete(n);ne.size>0&&ge.log(`gjsify install: ${ne.size} workspace(s) have scoped overrides — they will install their overridden deps locally after the root install`)}if(H.size>0){let I=makeProgressReporter({enabled:!n.verbose&&!n.quiet&&n.progress!==!1});await installPackages({prefix:t,specs:[...H],verbose:n.verbose,lockfile:!n.immutable,frozen:n.immutable,refreshLockfile:n[`refresh-lockfile`],overrides:te,signal:S,progress:I,workspaceNames:new Set(N.keys()),linkedNames:Y?.names,specOrigins:new Map([...W].map(([t,n])=>[t,[...n]])),optionalSpecs:optionalDependencyNames(C.map(t=>t.manifest)),focusSpecs:F?.specs})}else n.verbose&&ge.log(`gjsify install: no external deps to fetch`);for(let[t,F]of ne){if(F.size===0)continue;let I=C.find(n=>n.location===t)?.name??t;n.verbose&&ge.log(`gjsify install: ${I} — installing ${F.size} scoped-override spec(s) into ${t}/node_modules/`),await installPackages({prefix:t,specs:[...F],verbose:n.verbose,lockfile:!n.immutable,frozen:n.immutable,signal:S,workspaceNames:new Set(N.keys()),linkedNames:Y?.names,optionalSpecs:optionalDependencyNames(C.map(t=>t.manifest))})}await wireWorkspaceSymlinks(),reportRewiredDevLinks(Y);let ie=writeWorkspaceBinShims(t,F?.workspaces??C);ie>0&&ge.log(`gjsify install: linked ${ie} workspace bin(s) into node_modules/.bin/`)}function writeWorkspaceBinShims(t,n){let S=wn(t,`node_modules`,`.bin`),C=detectNativePackages(t).map(t=>t.prebuildsDir),N=0;for(let F of n){let n=F.manifest,I=n.gjsify?.bin,H=n.bin,W=mergeWorkspaceBins(F.name,I,H);if(W.size!==0){mkdirSync(S,{recursive:!0});for(let[n,{nodeTarget:I,gjsTarget:H}]of W){let W=wn(S,n);for(let t of[W,`${W}.cmd`,`${W}.ps1`])try{rmSync(t,{force:!0,maxRetries:10,retryDelay:100})}catch{}if(writeFileSync(W,buildBinShim(F.location,I,H,C,process.platform,t),{mode:493}),chmodSync(W,493),process.platform===`win32`)for(let[t,n]of Object.entries(buildWorkspaceBinShimsForWindows(F.location,I,H,C)))writeFileSync(`${W}.${t}`,n,{mode:493});N++}}}return N}function extractOverrides(t){if(!t)return;let n={},S=new Map,merge=(t,C)=>{if(t){for(let[N,F]of Object.entries(t))if(!N.startsWith(`_`)){if(typeof F==`string`){let t=N,S=N.startsWith(`@`)?N.indexOf(`@`,1):N.indexOf(`@`);S>0&&(t=N.slice(0,S)),n[t]=F;continue}if(F&&typeof F==`object`&&!Array.isArray(F)){let t={};for(let[n,S]of Object.entries(F)){if(n.startsWith(`_`))continue;if(typeof S!=`string`){ge.warn(`gjsify install: ${C}["${N}"]["${n}"] is not a string — only one level of nesting is supported, skipping`);continue}let F=n,I=n.startsWith(`@`)?n.indexOf(`@`,1):n.indexOf(`@`);I>0&&(F=n.slice(0,I)),t[F]=S}if(Object.keys(t).length>0){let n=S.get(N)??{};S.set(N,{...n,...t})}continue}ge.warn(`gjsify install: ${C}["${N}"] is not a string or object — skipping`)}}};if(merge(t.overrides,`overrides`),merge(t.resolutions,`resolutions`),!(Object.keys(n).length===0&&S.size===0))return{global:n,scoped:S}}function scopedOverrideFor(t,n,S){if(!S||S.scoped.size===0)return;let C=[t.name,t.relativeLocation];for(let t of C){let C=S.scoped.get(t);if(C?.[n])return C[n]}}function buildBinShim(t,n,S,C=[],N=process.platform,F=t){let I=n?wn(t,n):null,H=S?wn(t,S):null,W=buildNativeEnvPreamble(F,C,{platform:N});if(I&&H){let t=N===`darwin`||N===`win32`,n=`if command -v gjs >/dev/null 2>&1 && [ -f "${H}" ]; then\n${W}exec gjs -m "${H}" "$@"\nfi\nexec node "${I}" "$@"\n`,S=`if command -v node >/dev/null 2>&1 && [ -f "${I}" ]; then\nexec node "${I}" "$@"\nfi\n${W}exec gjs -m "${H}" "$@"\n`;return`#!/bin/sh
1172
- `+(t?S:n)}if(I)return`#!/bin/sh\nexec node "${I}" "$@"\n`;if(H)return`#!/bin/sh\n${W}exec gjs -m "${H}" "$@"\n`;throw Error(`buildBinShim: either nodeTarget or gjsTarget must be provided`)}function buildWorkspaceBinShimsForWindows(t,n,S,C=[]){let N=n?wn(t,n):null,F=S?wn(t,S):null;if(N)return buildLauncherShims({interpreter:`node`,target:N});if(F){let t=C.join(`;`);return buildLauncherShims({interpreter:`gjs`,interpreterArgs:[`-m`],target:F,prependEnv:C.length===0?{}:{GI_TYPELIB_PATH:t,PATH:t}})}throw Error(`buildWorkspaceBinShimsForWindows: either nodeTarget or gjsTarget must be provided`)}function mergeWorkspaceBins(t,n,S){let C=new Map,N=t.startsWith(`@`)?t.slice(t.indexOf(`/`)+1):t,get=t=>{let n=C.get(t);return n||(n={},C.set(t,n)),n};if(typeof S==`string`)get(N).nodeTarget=S;else if(S&&typeof S==`object`)for(let[t,n]of Object.entries(S))typeof n==`string`&&n.length>0&&(get(t).nodeTarget=n);if(typeof n==`string`)get(N).gjsTarget=n;else if(n&&typeof n==`object`)for(let[t,S]of Object.entries(n))typeof S==`string`&&S.length>0&&(get(t).gjsTarget=S);return C}async function projectInstallViaNpm(t){let n=[`install`];t[`save-dev`]&&n.push(`--save-dev`),t[`save-peer`]&&n.push(`--save-peer`),t[`save-optional`]&&n.push(`--save-optional`),t.verbose&&n.push(`--loglevel`,`verbose`),t.packages&&t.packages.length>0&&n.push(...t.packages),await spawnNpm(n)}async function spawnNpm(t){return spawnToCompletion(`npm`,t,{completion:`return`,notFound:()=>Error(`npm not found on PATH — install Node.js first.`)}).then(({code:t})=>{if(t!==0)throw Error(`npm install exited with code ${t}`)}).catch(t=>{let n=t.code;ge.error(n===void 0?t.message:`npm install failed: ${t.message}`),process.exit(1)})}async function installGlobalAndLink(t,n){let S=defaultGlobalLayout();mkdirSync(S.prefix,{recursive:!0}),ge.log(`gjsify install --global → ${S.prefix}`),ge.log(` bins → ${S.binDir}`);let C=await acquireInstallLock(S.prefix,{});try{let C=await installPackages({prefix:S.prefix,specs:t,verbose:n.verbose}),N=t.map(specToPackageName);if(N.includes(`@gjsify/cli`)){let t=C.installed.find(t=>t.name===`@gjsify/cli`)?.version??`latest`;await installGjsEnginePackages(S.prefix,t,{verbose:n.verbose})}n.prune!==!1&&pruneAfterInstall(S.prefix,resolveHostPlatform({env:{}}),{hint:`gjsify prune -g --dry-run`}),reportLinkedBins(linkGlobalBins(N,S),S.binDir)}finally{C.release()}}function pruneProjectPrefix(t){t.prune!==!1&&pruneAfterInstall(process.cwd(),resolveHostPlatform({env:{}}),{immutable:t.immutable===!0,hint:`gjsify prune --dry-run`})}function reportLinkedBins(t,n){if(t.length===0)ge.warn("\nNo bins declared (neither `gjsify.bin` nor `bin` in package.json) — nothing was symlinked.");else{ge.log(`\nLinked ${t.length} bin(s):`);for(let n of t)ge.log(` • ${n.link} → ${n.target}`)}t.length>0&&!binDirOnPath(n)&&ge.warn(`\nNote: ${n} is not on your PATH.\nAdd it to your shell rc file:\n export PATH="${n}:$PATH"`)}async function ensureProjectGjsEngine(t,n,S={}){let C=S.cwd??process.cwd(),N=S.hasEngineFn??hasBundlerEngineInstalled;if(!existsSync(wn(C,`node_modules`,`@gjsify`,`cli`,`package.json`))||!n||N(C))return;if(t.immutable){ge.warn(`\nWarning: \`gjsify build\` will fail under GJS — ${nR} is not installed, and\n --immutable cannot add it (the lockfile does not name it). Declare it so the lockfile carries it:
1173
- gjsify install ${nR}\n Under Node the npm \`rolldown\` engine is used instead and this does not apply.`);return}let F=readCliVersionFrom(wn(C,`node_modules`,`@gjsify`,`cli`,`package.json`))??`latest`;ge.log(`\n${nR} is missing and this host can run gjs, so \`gjsify build\` would have no\n bundler engine (there is no npm \`rolldown\` fallback under GJS). Installing the GJS engine set at\n ${F}, in lockstep with the CLI.`),await(S.installFn??installGjsEnginePackages)(C,F,{verbose:t.verbose})}async function runPostInstallChecks(t){ge.log(`
1170
+ Name one where the payload is assembled: \`gjsify ship ${t} ${N[0]}\`.`)}let F=defaultFormatIds(`linux`).join(`,`),I={host:`This host is ${process.platform}, so \`gjsify ship\` assembled the ${n.name} layout. Assembly is not host-bound (ADR 0024 § A1), so the Linux packages are still one word away: \`gjsify ship linux\` builds ${F} from right here.`,positional:`\`gjsify ship ${n.name} --stage\` assembles the payload and stops, which is the whole of what this command does for that OS today.`,stage:`This stage carries the ${n.name} layout and nothing here can wrap it — a stage is a build intermediate, not an artifact. Keep it for the milestone that packs it, or re-assemble with \`gjsify ship linux --stage\` if a Linux package is what you wanted.`}[S];throw Error(`gjsify ship: no format wraps the ${n.name} layout, so there is nothing to pack. ${I} Every layout this gjsify knows has one (ADR 0024 stages 2-5), so this is a layout added without a \`FORMATS\` row.`)}function assertFormatCanRunInterpreter(t,n){if(!t.interpreters.includes(n))throw Error(`gjsify ship: this ${t.layoutOs} target runs \`${n}\`, and the ${t.id} runtime cannot run it — it provides ${t.interpreters.join(`, `)}.\n ${t.interpreterGap}.\n Build the formats that wrap this layout and can run it, or set \`gjsify.ship.app.${t.layoutOs}: "${t.interpreters.join(`" / "`)}"\` (which overrides \`gjsify.app\` for this target alone).`)}async function runProjectBuild(t,n){if(typeof readPackageJson$2(wn(t,`package.json`))?.scripts?.build!=`string`)throw Error("gjsify ship: this project has no `build` script to run. Add one, or pass --skip-build to package what is already built.");ge.log(`${vU} running the project's build script`);let S=await spawnToCompletion(`gjsify`,[`run`,`build`],{completion:`return`,cwd:t,stdio:`inherit`,env:n===void 0?void 0:{...process.env,[sh]:n},notFound:()=>Error("gjsify ship: `gjsify` is not on PATH, so the project build cannot be run. Build the project yourself and pass --skip-build.")});if(S.code!==0)throw Error(`gjsify ship: the project's build script failed with ${describeExit(S)}.`)}var vU,yU,bU=__esmMin(()=>{_e(),ch(),Rd(),Pn(),AI(),kz(),$P(),V_(),jV(),TB(),rH(),KV(),fH(),hH(),Dz(),gH(),PB(),_H(),MH(),hV(),JV(),OB(),bV(),IH(),WH(),KH(),mI(),AV(),$V(),$H(),eU(),_U(),HV(),YH(),XH(),vU=`[gjsify ship]`,yU={command:`ship [os]`,description:`Build installable artifacts (${AH.join(`, `)}) from the current project.`,builder:t=>t.positional(`os`,{type:`string`,description:`Operating system whose LAYOUT to assemble (${pV.join(`|`)}, ADR 0024 § A2). Default: this host. Assembly is not host-bound, so any of them can be staged anywhere.`}).option(`target`,{type:`string`,array:!0,description:`Formats to build, comma-separated or repeated. Default: every format wrapping the target OS's layout that needs no extra tooling — on linux, ${defaultFormatIds(`linux`).join(`,`)}. Also available for linux, and opt-in because it needs tooling this CLI does not carry: ${formatIdsFor(`linux`).filter(t=>!defaultFormatIds(`linux`).includes(t)).join(`, `)}.`}).option(`out`,{type:`string`,normalize:!0,description:"Output root, relative to the project. Default: `gjsify.ship.outDir`, else `ship`."}).option(`stage`,{type:`boolean`,default:!1,description:`Produce the staged payload and stop, without packing anything.`}).option(`from-stage`,{type:`string`,normalize:!0,description:"Pack a staged payload written by an earlier `--stage` run. Needs no project: the stage carries its own closure."}).option(`expect-target`,{type:`string`,description:"With --from-stage: refuse unless the stage was assembled for this `<os>-<arch>`, e.g. `linux-arm64`."}).option(`channel`,{type:`string`,choices:[...ah],description:"Distribution channel (ADR 0113). Overrides gjsify.ship.channel; `--target flatpak` implies flathub. Passed to the project build, and gates the metainfo donation URL."}).option(`skip-build`,{type:`boolean`,default:!1,description:"Package what is already built instead of running the project's `build` script."}).option(`arch`,{type:`string`,description:"Target architecture in `process.arch` spelling. Default: this host."}).option(`sign`,{type:`string`,requiresArg:!0,description:"Sign the payload with this identity, e.g. a Developer ID name or SHA-1 fingerprint. `-` signs ad-hoc and needs no developer identity. Default: `gjsify.ship.sign.<darwin|win32>.identity`; absent means unsigned, which is a legitimate output."}).option(`notarize`,{type:`string`,requiresArg:!0,description:"Submit the signed artifact to Apple with this `notarytool` keychain profile. Needs --sign; darwin only."}).option(`verbose`,{type:`boolean`,default:!1,description:`Print each staged file, the GI namespaces the bundle imports, and every tool a host-bound packer invokes.`}),handler:async t=>{if(t[`from-stage`]!==void 0)return await finishFromStage(t,t[`from-stage`]);await assemble(t)}}});function forceExit(t){if(process.exitCode=t,!gjsExit(t))return process.exit(t)}var xU=__esmMin(()=>{d_()});function workspaceLinkTarget(t,n){return SU===`junction`?xn(n):Tn(En(t),n)}function applyPlatformConfigFromFlags(t){for(let[n,S]of[[`os`,`npm_config_os`],[`cpu`,`npm_config_cpu`],[`libc`,`npm_config_libc`]]){let C=t[n];if(typeof C!=`string`)continue;let N=C.trim();N!==``&&(process.env[S]=N)}t.force&&(process.env.npm_config_force=`true`)}function isAbortedFromOverallTimeout(t){if(!t||typeof t!=`object`)return!1;let n=t.name;if(n===`AbortError`)return!0;let S=t.message;return!!(typeof S==`string`&&S.includes(`install-overall-timeout`)||n===`RegistryTimeoutError`)}function readCliVersionFrom(t){try{if(!existsSync(t))return null;let n=JSON.parse(readFileSync(t,`utf-8`));if(n.name===TU&&typeof n.version==`string`)return n.version}catch{}return null}function readRunningCliVersion(){try{let t=En(xn(fileURLToPath(import.meta.url)));for(let n=0;n<8&&t!==En(t);n++){let n=readCliVersionFrom(wn(t,`package.json`));if(n)return n;t=En(t)}}catch{}return null}function readWorkspaceCliVersion(t){let n=readPackageJson$1(wn(t,`package.json`)),S=!1;for(let t of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n?.[t]?.[TU];typeof C==`string`&&(S=!0);let N=typeof C==`string`?/^[\^~=v]*(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/.exec(C.trim()):null;if(N)return N[1]}if(!S){let n=readCliVersionFrom(wn(t,`node_modules`,TU,`package.json`));if(n)return n}return readCliVersionFrom(wn(t,`packages`,`infra`,`cli`,`package.json`))}function warnOnCliVersionSkew(t){if(process.env.GJSIFY_NO_VERSION_SKEW_WARNING===`1`)return;let n=readRunningCliVersion(),S=readWorkspaceCliVersion(t);!n||!S||n===S||ge.warn(`gjsify install: version skew — you are running @gjsify/cli v${n}, but this workspace pins v${S}.\n A mismatched CLI can stall the install (lock discarded → full re-resolve) or silently produce a wrong build.\n Align them: run \`gjsify self-update\` (global CLI) or use the workspace-local \`node_modules/.bin/gjsify\`.\n Suppress this with GJSIFY_NO_VERSION_SKEW_WARNING=1.`)}function isWorkspaceRoot(t){let n=readPackageJson$1(wn(t,`package.json`));return n?n.workspaces!==void 0:!1}function optionalDependencyNames(t){let n=new Set,S=new Set;for(let C of t){let t=new Set(Object.keys(C.optionalDependencies??{}));for(let S of t)n.add(S);for(let n of[`dependencies`,`devDependencies`])for(let N of Object.keys(C[n]??{}))t.has(N)||S.add(N)}for(let t of S)n.delete(t);return n}function depKindFromArgs(t){return t[`save-dev`]?`devDependencies`:t[`save-peer`]?`peerDependencies`:t[`save-optional`]?`optionalDependencies`:`dependencies`}function activateDevLinks(t,n){let S=prepareDevLinks(devLinkRoot(t));if(!S)return null;let C=applyDevLinks(S.links);if(!n)return S;ge.log(`gjsify install: development link ACTIVE (${S.overridePath}) — ${S.links.length} package(s) come from ${S.checkout}, linked rather than fetched (${C.length} (re)written, ${S.links.length-C.length} already current):`);let N=S.links.map(t=>t.name),F=N.slice(0,12);return ge.log(` ${F.join(`, `)}${N.length>F.length?`, +${N.length-F.length} more`:``}`),ge.log(" `gjsify unlink` restores the registry copies; `gjsify install --immutable` refuses while it exists."),S}function reportRewiredDevLinks(t){if(!t)return;let n=applyDevLinks(t.links);n.length!==0&&ge.log(`gjsify install: re-applied ${n.length} development link(s) the install had replaced: ${n.map(t=>t.name).join(`, `)}`)}async function projectInstallNative(t,n){let S=process.cwd(),C=wn(S,`package.json`),N=[`.pnp.cjs`,`.pnp.loader.mjs`].filter(t=>existsSync(wn(S,t)));if(N.length>0)throw Error(`gjsify install uses the node_modules linker and cannot run in a Yarn PnP project (found ${N.join(`, `)} in ${S}).\n\n• If this project uses \`gjsify install\` to manage dependencies, these PnP files are stale residue from an earlier \`yarn install\` — remove them and re-run:\n rm -f .pnp.cjs .pnp.loader.mjs && rm -rf .yarn/cache .yarn/unplugged\n gjsify install\n\n• If instead you want Yarn to manage dependencies, set \`nodeLinker: node-modules\` in .yarnrc.yml and run \`yarn install\` (not \`gjsify install\`).`);if(!t.packages||t.packages.length===0){let C=isWorkspaceRoot(S)?S:findWorkspaceRoot(S);if(C){C!==S&&ge.log(`gjsify install: resolved workspace root ${C} (from ${S}); installing the workspace.`),await workspaceInstall(C,t,n);return}}let F,I=readPackageJson$1(C),H=I?projectSpecsFromPackageJson(I):[];if(t.packages&&t.packages.length>0){let n=new Set(t.packages.map(t=>parseSpec$2(t).name));F=[...H.filter(t=>!n.has(parseSpec$2(t).name)),...t.packages]}else{if(!I)throw Error(`gjsify install: no package.json in ${S}`);if(F=H,F.length===0){ge.log(`gjsify install: no dependencies declared in package.json — nothing to do.`);return}}mkdirSync(S,{recursive:!0});let W=makeProgressReporter({enabled:!t.verbose&&!t.quiet&&t.progress!==!1}),q=await acquireInstallLock(S,{signal:n});try{let N=activateDevLinks(S,!0),H=await installPackages({prefix:S,specs:F,verbose:t.verbose,lockfile:!t.immutable,frozen:t.immutable,refreshLockfile:t[`refresh-lockfile`],signal:n,progress:W,optionalSpecs:new Set([...optionalDependencyNames(I?[I]:[]),...t[`save-optional`]?(t.packages??[]).map(t=>parseSpec$2(t).name):[]]),linkedNames:N?.names});if(reportRewiredDevLinks(N),t.packages&&t.packages.length>0&&I){let n=depKindFromArgs(t);for(let S of t.packages){let{name:t,range:C}=parseSpec$2(S),N=H.installed.find(n=>n.name===t);addDependencyEntry(I,t,C??(N?defaultRangeFromVersion(N.version):`latest`),n)}writePackageJson(C,I),t.immutable||syncLockfileRequested(S,projectSpecsFromPackageJson(I))}}finally{q.release()}}function syncLockfileRequested(t,n){let S=wn(t,`gjsify-lock.json`);if(existsSync(S))try{let t=JSON.parse(readFileSync(S,`utf-8`)),C=[...n].sort(),N=[...t.requested??[]].sort();if(C.length===N.length&&C.every((t,n)=>t===N[n]))return;t.requested=n,atomicWriteStrict(S,JSON.stringify(t,null,2)+`
1171
+ `)}catch{}}async function workspaceInstall(t,n,S){let C=await acquireInstallLock(t,{signal:S});try{await workspaceInstallLocked(t,n,S)}finally{C.release()}}async function workspaceInstallLocked(t,n,S){let C=discoverWorkspaces(t,{includeRoot:!0});if(C.length===0)throw Error(`gjsify install: ${t} has a "workspaces" field but no workspaces were discovered`);let N=new Map(C.map(t=>[t.name,t])),F=n.focus&&n.focus.length>0?planFocus(C,n.focus,`gjsify install`):void 0,I=F?new Set(F.workspaces):void 0,H=new Set,W=new Map,q=[];for(let t of C){let n=t.manifest;for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n[S];if(C)for(let[n,S]of Object.entries(C)){if(typeof S!=`string`)continue;let C=N.get(n);if(C&&!/^(link|file|portal|git\+|https?):/.test(S)){if(I&&!I.has(t))continue;q.push({fromWorkspaceName:t.name,depName:n,targetLocation:C.location});continue}if(S.startsWith(`workspace:`))throw Error(`gjsify install: ${t.name} declares "${n}: ${S}" but no workspace with that name exists`);if(/^(link|file|portal|git\+|https?):/.test(S))continue;let F=`${n}@${S}`;H.add(F);let Y=W.get(F);Y||(Y=new Set,W.set(F,Y)),Y.add(t.name)}}}ge.log(`gjsify install: ${C.length} workspace(s), ${H.size} external dep spec(s), ${q.length} workspace symlink(s)`);let Y=activateDevLinks(t,!0);writeWorkspaceBinShims(t,F?.workspaces??C);let wireWorkspaceSymlinks=async()=>{if(q.length>0){let t=await Promise.resolve().then(()=>(xd(),vd)),n=new Set,S=[];for(let t of q){let C=N.get(t.fromWorkspaceName);if(!C)continue;let F=wn(C.location,`node_modules`,t.depName);n.add(En(F));let I=workspaceLinkTarget(F,t.targetLocation);S.push({linkPath:F,relTarget:I})}await Promise.all([...n].map(n=>t.mkdir(n,{recursive:!0})));let C=0,F=[],wireOne=async(n,S)=>{try{await t.rm(n,{recursive:!0,force:!0,maxRetries:10,retryDelay:100})}catch{}await t.symlink(S,n,SU)};for(let t=0;t<Math.min(32,S.length);t++)F.push((async()=>{for(;;){let t=C++;if(t>=S.length)return;let n=S[t];if(!n)return;await wireOne(n.linkPath,n.relTarget)}})());await Promise.all(F),ge.log(`gjsify install: wired ${q.length} workspace symlink(s)`)}let n=wn(t,`node_modules`),S=0;for(let N of F?.workspaces??C){if(N.location===t||!N.name)continue;let C=wn(n,N.name),F=!1;try{lstatSync(C),F=!0}catch{}F||(mkdirSync(En(C),{recursive:!0}),symlinkSync(workspaceLinkTarget(C,N.location),C,SU),S++)}S>0&&ge.log(`gjsify install: hoisted ${S} workspace(s) to root node_modules/`)};await wireWorkspaceSymlinks();let X=C.find(n=>n.location===t)?.manifest,Z=extractOverrides(X),te=Z?.global,ne=new Map,re=new Set;if(Z&&Z.scoped.size>0){for(let t of F?.workspaces??C){let n=t.manifest;for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n[S];if(C)for(let[n,S]of Object.entries(C)){let C=scopedOverrideFor(t,n,Z);if(!C)continue;let N=C,F=t.location,I=ne.get(F);I||(I=new Set,ne.set(F,I)),I.add(`${n}@${N}`),re.add(`${n}@${S}`)}}}let t=new Set;for(let n of C)for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n.manifest[S];if(C)for(let[S,N]of Object.entries(C))scopedOverrideFor(n,S,Z)||t.add(`${S}@${N}`)}for(let n of re)t.has(n)||H.delete(n);ne.size>0&&ge.log(`gjsify install: ${ne.size} workspace(s) have scoped overrides — they will install their overridden deps locally after the root install`)}if(H.size>0){let I=makeProgressReporter({enabled:!n.verbose&&!n.quiet&&n.progress!==!1});await installPackages({prefix:t,specs:[...H],verbose:n.verbose,lockfile:!n.immutable,frozen:n.immutable,refreshLockfile:n[`refresh-lockfile`],overrides:te,signal:S,progress:I,workspaceNames:new Set(N.keys()),linkedNames:Y?.names,specOrigins:new Map([...W].map(([t,n])=>[t,[...n]])),optionalSpecs:optionalDependencyNames(C.map(t=>t.manifest)),focusSpecs:F?.specs})}else n.verbose&&ge.log(`gjsify install: no external deps to fetch`);for(let[t,F]of ne){if(F.size===0)continue;let I=C.find(n=>n.location===t)?.name??t;n.verbose&&ge.log(`gjsify install: ${I} — installing ${F.size} scoped-override spec(s) into ${t}/node_modules/`),await installPackages({prefix:t,specs:[...F],verbose:n.verbose,lockfile:!n.immutable,frozen:n.immutable,signal:S,workspaceNames:new Set(N.keys()),linkedNames:Y?.names,optionalSpecs:optionalDependencyNames(C.map(t=>t.manifest))})}await wireWorkspaceSymlinks(),reportRewiredDevLinks(Y);let ie=writeWorkspaceBinShims(t,F?.workspaces??C);ie>0&&ge.log(`gjsify install: linked ${ie} workspace bin(s) into node_modules/.bin/`)}function writeWorkspaceBinShims(t,n){let S=wn(t,`node_modules`,`.bin`),C=detectNativePackages(t).map(t=>t.prebuildsDir),N=0;for(let F of n){let n=F.manifest,I=n.gjsify?.bin,H=n.bin,W=mergeWorkspaceBins(F.name,I,H);if(W.size!==0){mkdirSync(S,{recursive:!0});for(let[n,{nodeTarget:I,gjsTarget:H}]of W){let W=wn(S,n);for(let t of[W,`${W}.cmd`,`${W}.ps1`])try{rmSync(t,{force:!0,maxRetries:10,retryDelay:100})}catch{}if(writeFileSync(W,buildBinShim(F.location,I,H,C,process.platform,t),{mode:493}),chmodSync(W,493),process.platform===`win32`)for(let[t,n]of Object.entries(buildWorkspaceBinShimsForWindows(F.location,I,H,C)))writeFileSync(`${W}.${t}`,n,{mode:493});N++}}}return N}function extractOverrides(t){if(!t)return;let n={},S=new Map,merge=(t,C)=>{if(t){for(let[N,F]of Object.entries(t))if(!N.startsWith(`_`)){if(typeof F==`string`){let t=N,S=N.startsWith(`@`)?N.indexOf(`@`,1):N.indexOf(`@`);S>0&&(t=N.slice(0,S)),n[t]=F;continue}if(F&&typeof F==`object`&&!Array.isArray(F)){let t={};for(let[n,S]of Object.entries(F)){if(n.startsWith(`_`))continue;if(typeof S!=`string`){ge.warn(`gjsify install: ${C}["${N}"]["${n}"] is not a string — only one level of nesting is supported, skipping`);continue}let F=n,I=n.startsWith(`@`)?n.indexOf(`@`,1):n.indexOf(`@`);I>0&&(F=n.slice(0,I)),t[F]=S}if(Object.keys(t).length>0){let n=S.get(N)??{};S.set(N,{...n,...t})}continue}ge.warn(`gjsify install: ${C}["${N}"] is not a string or object — skipping`)}}};if(merge(t.overrides,`overrides`),merge(t.resolutions,`resolutions`),!(Object.keys(n).length===0&&S.size===0))return{global:n,scoped:S}}function scopedOverrideFor(t,n,S){if(!S||S.scoped.size===0)return;let C=[t.name,t.relativeLocation];for(let t of C){let C=S.scoped.get(t);if(C?.[n])return C[n]}}function buildBinShim(t,n,S,C=[],N=process.platform,F=t){let I=n?wn(t,n):null,H=S?wn(t,S):null,W=buildNativeEnvPreamble(F,C,{platform:N});if(I&&H){let t=N===`darwin`||N===`win32`,n=`if command -v gjs >/dev/null 2>&1 && [ -f "${H}" ]; then\n${W}exec gjs -m "${H}" "$@"\nfi\nexec node "${I}" "$@"\n`,S=`if command -v node >/dev/null 2>&1 && [ -f "${I}" ]; then\nexec node "${I}" "$@"\nfi\n${W}exec gjs -m "${H}" "$@"\n`;return`#!/bin/sh
1172
+ `+(t?S:n)}if(I)return`#!/bin/sh\nexec node "${I}" "$@"\n`;if(H)return`#!/bin/sh\n${W}exec gjs -m "${H}" "$@"\n`;throw Error(`buildBinShim: either nodeTarget or gjsTarget must be provided`)}function buildWorkspaceBinShimsForWindows(t,n,S,C=[]){let N=n?wn(t,n):null,F=S?wn(t,S):null;if(N)return buildLauncherShims({interpreter:`node`,target:N});if(F){let t=C.join(`;`);return buildLauncherShims({interpreter:`gjs`,interpreterArgs:[`-m`],target:F,prependEnv:C.length===0?{}:{GI_TYPELIB_PATH:t,PATH:t}})}throw Error(`buildWorkspaceBinShimsForWindows: either nodeTarget or gjsTarget must be provided`)}function mergeWorkspaceBins(t,n,S){let C=new Map,N=t.startsWith(`@`)?t.slice(t.indexOf(`/`)+1):t,get=t=>{let n=C.get(t);return n||(n={},C.set(t,n)),n};if(typeof S==`string`)get(N).nodeTarget=S;else if(S&&typeof S==`object`)for(let[t,n]of Object.entries(S))typeof n==`string`&&n.length>0&&(get(t).nodeTarget=n);if(typeof n==`string`)get(N).gjsTarget=n;else if(n&&typeof n==`object`)for(let[t,S]of Object.entries(n))typeof S==`string`&&S.length>0&&(get(t).gjsTarget=S);return C}async function projectInstallViaNpm(t){let n=[`install`];t[`save-dev`]&&n.push(`--save-dev`),t[`save-peer`]&&n.push(`--save-peer`),t[`save-optional`]&&n.push(`--save-optional`),t.verbose&&n.push(`--loglevel`,`verbose`),t.packages&&t.packages.length>0&&n.push(...t.packages),await spawnNpm(n)}async function spawnNpm(t){return spawnToCompletion(`npm`,t,{completion:`return`,notFound:()=>Error(`npm not found on PATH — install Node.js first.`)}).then(({code:t})=>{if(t!==0)throw Error(`npm install exited with code ${t}`)}).catch(t=>{let n=t.code;ge.error(n===void 0?t.message:`npm install failed: ${t.message}`),process.exit(1)})}async function installGlobalAndLink(t,n){let S=defaultGlobalLayout();mkdirSync(S.prefix,{recursive:!0}),ge.log(`gjsify install --global → ${S.prefix}`),ge.log(` bins → ${S.binDir}`);let C=await acquireInstallLock(S.prefix,{});try{let C=await installPackages({prefix:S.prefix,specs:t,verbose:n.verbose}),N=t.map(specToPackageName);if(N.includes(`@gjsify/cli`)){let t=C.installed.find(t=>t.name===`@gjsify/cli`)?.version??`latest`;await installGjsEnginePackages(S.prefix,t,{verbose:n.verbose})}n.prune!==!1&&pruneAfterInstall(S.prefix,resolveHostPlatform({env:{}}),{hint:`gjsify prune -g --dry-run`}),reportLinkedBins(linkGlobalBins(N,S),S.binDir)}finally{C.release()}}function pruneProjectPrefix(t){t.prune!==!1&&pruneAfterInstall(process.cwd(),resolveHostPlatform({env:{}}),{immutable:t.immutable===!0,hint:`gjsify prune --dry-run`})}function reportLinkedBins(t,n){if(t.length===0)ge.warn("\nNo bins declared (neither `gjsify.bin` nor `bin` in package.json) — nothing was symlinked.");else{ge.log(`\nLinked ${t.length} bin(s):`);for(let n of t)ge.log(` • ${n.link} → ${n.target}`)}t.length>0&&!binDirOnPath(n)&&ge.warn(`\nNote: ${n} is not on your PATH.\nAdd it to your shell rc file:\n export PATH="${n}:$PATH"`)}async function ensureProjectGjsEngine(t,n,S={}){let C=S.cwd??process.cwd(),N=S.hasEngineFn??hasBundlerEngineInstalled;if(!existsSync(wn(C,`node_modules`,`@gjsify`,`cli`,`package.json`))||!n||N(C))return;if(t.immutable){ge.warn(`\nWarning: \`gjsify build\` will fail under GJS — ${sR} is not installed, and\n --immutable cannot add it (the lockfile does not name it). Declare it so the lockfile carries it:
1173
+ gjsify install ${sR}\n Under Node the npm \`rolldown\` engine is used instead and this does not apply.`);return}let F=readCliVersionFrom(wn(C,`node_modules`,`@gjsify`,`cli`,`package.json`))??`latest`;ge.log(`\n${sR} is missing and this host can run gjs, so \`gjsify build\` would have no\n bundler engine (there is no npm \`rolldown\` fallback under GJS). Installing the GJS engine set at\n ${F}, in lockstep with the CLI.`),await(S.installFn??installGjsEnginePackages)(C,F,{verbose:t.verbose})}async function runPostInstallChecks(t){ge.log(`
1174
1174
  --- gjsify post-install checks ---`);let n=runMinimalChecks(),S=n.filter(t=>!t.found&&t.severity===`required`);if(S.length>0){ge.warn(`Missing required system dependencies:
1175
1175
  `);for(let t of S)ge.warn(` ✗ ${t.name}`);let t=buildInstallCommand(detectPackageManager$1(),S);t&&ge.warn(`\nInstall with:\n ${t}`)}else ge.log(`System dependencies OK.`);await ensureProjectGjsEngine(t,n.find(t=>t.id===`gjs`)?.found??!1);let C=detectNativePackages(process.cwd());if(C.length>0){ge.log(`\nDetected ${C.length} @gjsify/* package(s) with native prebuilds:`);for(let t of C)ge.log(` • ${t.name}`);ge.log("\nUse `gjsify run <bundle>` to launch with LD_LIBRARY_PATH/GI_TYPELIB_PATH set.");let t=muslPrebuildFallbacks(detectHostLibc(process.platform),C);if(t.length>0){ge.warn(`\nWarning: musl host — ${t.length} of ${C.length} package(s) ship no \`-musl\` prebuild, so the
1176
1176
  default (glibc) build was used:`);for(let n of t)ge.warn(` ${n}`);ge.warn(` Most of these run anyway: a bridge that links only GLib records no libc at all.
@@ -1180,24 +1180,24 @@ A misplaced catalogue installs and then shows nothing, which reads exactly like
1180
1180
  A bridge lost that way is silently absent from the next build rather than
1181
1181
  reported, so the first symptom can be an unrelated-looking bundler error
1182
1182
  (\`Could not load <file>\` from rolldown, for the CSS bridge). Nothing to
1183
- install: no \`-musl\` package is published for any target yet.`)}}maybeInstallGitHooks()}function maybeInstallGitHooks(){let t=process.cwd(),n=wn(t,`scripts`,`install-git-hooks.mjs`);if(existsSync(n)&&existsSync(wn(t,`.git`)))try{let S=spawnSync(nodeBinary(),[n,`--quiet`],{cwd:t,stdio:`inherit`,env:process.env});S.status!==0&&ge.warn(`[gjsify install] scripts/install-git-hooks.mjs exited ${S.status} — git hooks may not be active.`)}catch(t){ge.warn(`[gjsify install] git hook installation skipped: ${t instanceof Error?t.message:String(t)}`)}}var _U,vU,yU,bU,xU=__esmMin(()=>{_e(),Rd(),Pn(),Gn(),P_(),gU(),QP(),vF(),CF(),VI(),eR(),oL(),TL(),QI(),V_(),eF(),Rz(),iR(),zL(),VL(),iL(),WL(),_U=process.platform===`win32`?`junction`:void 0,vU=18e5,yU={command:`install [packages..]`,description:`Install npm dependencies in the current project (or globally with -g), then run gjsify-aware post-checks.`,builder:t=>t.positional(`packages`,{description:`Optional package specs. With none, runs a full project install.`,type:`string`,array:!0}).option(`global`,{description:`Install into the user-global XDG location and symlink bins into ~/.local/bin.`,type:`boolean`,alias:`g`,default:!1}).option(`save-dev`,{type:`boolean`,alias:`D`}).option(`save-peer`,{type:`boolean`}).option(`save-optional`,{type:`boolean`,alias:`O`}).option(`immutable`,{description:`CI mode: install strictly from gjsify-lock.json, fail if the lockfile is missing or stale. Equivalent to yarn --immutable / npm ci --frozen-lockfile.`,type:`boolean`,default:!1}).option(`refresh-lockfile`,{description:`Re-resolve every dependency to the newest version satisfying its range and rewrite the lockfile (bumps in-range transitive deps). Without it, a resolve preserves versions already pinned in the lockfile and only resolves new/changed deps — the npm/yarn/pnpm default. Mirrors yarn install --mode=update-lockfile.`,type:`boolean`,default:!1}).option(`focus`,{description:`Install only the named workspaces (package names), the workspaces they depend on, and their external dependencies, as if they were the only members of the monorepo (yarn workspaces focus). Reads gjsify-lock.json and never rewrites it; fails if it is missing or stale. Workspace projects only.`,type:`string`,array:!0}).option(`verbose`,{description:`Verbose install logging.`,type:`boolean`,default:!1}).option(`quiet`,{description:`Silence the progress bar.`,type:`boolean`,default:!1}).option(`progress`,{description:`Show a TTY-aware progress bar for resolve / download / extract phases. Auto-enabled when stderr is a TTY (override with --no-progress). Implicitly off under --verbose (per-package log lines replace the bar) or --quiet.`,type:`boolean`,default:!0}).option(`backend`,{description:"Install backend. `native` (default) routes through `@gjsify/{semver,npm-registry,tar}` — no Node/npm at runtime. `npm` shells out to `npm install` as an escape hatch for cases the native backend does not yet model (Yarn PnP repos, lifecycle scripts). Overrides `GJSIFY_INSTALL_BACKEND` if both are set.",type:`string`,choices:[`native`,`npm`]}).option(`timeout`,{description:`Overall install wall-clock timeout in ms (default 1800000 = 30 min). On timeout, all in-flight registry fetches are aborted and the install exits non-zero with a clear "install timed out — likely a registry slowdown" message. Per-request timeouts in @gjsify/npm-registry (default 30s) still apply within this budget. Set to 0 to disable the overall budget.`,type:`number`,default:vU}).option(`os`,{description:"Resolve/install for this OS instead of the running one (npm config key `os`, e.g. darwin, win32, linux). Affects which packages pass the os/cpu/libc compatibility check; the lockfile stays platform-independent either way.",type:`string`}).option(`cpu`,{description:"Resolve/install for this CPU architecture instead of the running one (npm config key `cpu`, e.g. x64, arm64).",type:`string`}).option(`libc`,{description:"Resolve/install for this libc family instead of probing the host (npm config key `libc`: glibc or musl). Only meaningful with --os=linux. A package declaring a libc is incompatible when the target libc is unknown.",type:`string`}).option(`force`,{description:"Install a REQUIRED dependency even when its os/cpu/libc excludes the target, instead of failing with EBADPLATFORM (npm config key `force`). Incompatible OPTIONAL dependencies stay skipped — npm ignores --force for those too, and a binary that cannot load is not worth downloading.",type:`boolean`,default:!1}).option(`prune`,{description:`After installing, remove packages an earlier install left behind that this host cannot use (foreign os/cpu/libc). Use --no-prune to disable. Skipped automatically under --immutable, and whenever --os/--cpu/--libc is given: an install must never delete against a target the user typed.`,type:`boolean`,default:!0}),handler:async t=>{if(applyPlatformConfigFromFlags(t),t.immutable){if(t.packages&&t.packages.length>0)return ge.error(`gjsify install --immutable does not accept package arguments. Remove the package names or drop --immutable.`),process.exit(1);if(t.global)return ge.error(`gjsify install --immutable is incompatible with --global.`),process.exit(1);if(t[`refresh-lockfile`])return ge.error(`gjsify install --immutable is incompatible with --refresh-lockfile (--immutable forbids rewriting the lockfile). Drop one.`),process.exit(1);assertNoDevLinkUnderImmutable(process.cwd())}if(t.global){if(!t.packages||t.packages.length===0)return ge.error(`gjsify install --global requires at least one <pkg> argument.`),process.exit(1);for(let n of[`save-dev`,`save-peer`,`save-optional`])t[n]&&ge.warn(`gjsify install --global ignores --${n}: global installs do not modify a project package.json.`);await installGlobalAndLink(t.packages,{verbose:t.verbose,prune:t.prune});return}if(warnOnCliVersionSkew(process.cwd()),(t.backend??process.env.GJSIFY_INSTALL_BACKEND??`native`)===`npm`){await projectInstallViaNpm(t),pruneProjectPrefix(t),await runPostInstallChecks(t);return}let n=t.timeout>0?t.timeout:0,S=n>0?new AbortController:null,C=S===null?null:setTimeout(()=>S.abort(Error(`install-overall-timeout`)),n),N=n>0?setTimeout(()=>{let t=Math.round(n/100)/10;ge.error(`gjsify install: the ${t}s budget elapsed and the abort did not unwind within 10s — forcing exit. That means one of two things, and this timer cannot distinguish them: the install was still WORKING (a cold tree here extracts several GB, and extraction blocks the loop in multi-second synchronous stretches), or a step genuinely wedged. Re-running tells you which, and is safe: extraction is idempotent, every package already on disk is skipped, so a second run finishes the remainder in a fraction of the time. A re-run that makes NO further progress is a real wedge — file an issue.`),forceExit(1)},n+1e4):null;N?.unref?.();try{await projectInstallNative(t,S?.signal),pruneProjectPrefix(t),await runPostInstallChecks(t)}catch(t){if(S!==null&&S.signal.aborted&&isAbortedFromOverallTimeout(t)){let t=Math.round(n/100)/10;return ge.error(`gjsify install: timed out after ${t}s — likely a registry slowdown or a wedged extract.\nRe-run, or override with --timeout <ms> (set --timeout 0 to disable the overall budget).`),process.exit(1)}throw t}finally{C!==null&&clearTimeout(C),N!==null&&clearTimeout(N)}}},bU=`@gjsify/cli`});function sweepCheckouts(t,n){let S=null;try{S=readDevLinkOverride(t)?.checkout??null}catch{S=null}return S&&S!==n?[S,n]:[n]}var SU,CU,wU=__esmMin(()=>{_e(),Rd(),Pn(),WL(),SU={command:`link <checkout>`,description:"Link this project against a local gjsify checkout for development: its workspace packages replace the installed registry copies, recorded in a git-ignored .gjsify-link.json that every later `gjsify install` re-applies. Undo with `gjsify unlink`.",builder:t=>t.positional(`checkout`,{description:`Path to the gjsify checkout to link from (a repo whose package.json declares "workspaces").`,type:`string`,demandOption:!0}).option(`packages`,{description:"Name glob selecting which of the checkout's workspace packages take part (repeatable; default: all of them). Matched against the package NAME with the same single-segment dialect as `gjsify foreach --include`, so a whole scope is `@gjsify/*` — a bare `*` matches no scoped name. Only packages this project actually depends on are ever linked.",type:`string`,array:!0}).option(`dry-run`,{description:`Print the links that would be made and write nothing.`,type:`boolean`,default:!1}),handler:t=>{let n=process.cwd(),S=t[`dry-run`]??!1,C=xn(n,t.checkout),N=devLinkPath(n),F=resolveCheckoutWorkspaces(C,N),I=t.packages??[],H=planDevLinks({consumerRoot:n,workspaces:F,patterns:I,knownNames:consumerKnownNames(n)});if(H.length===0)return ge.error(`gjsify link: nothing to link — ${C} has ${F.length} workspace package(s), none of which ${n} depends on${I.length===0?``:` and matches ${I.join(`, `)}`}.\nA link that links nothing is a silent no-op, so this is an error. Check the --packages pattern, or run \`gjsify install\` first so the dependency tree exists.`),process.exit(1);let W=`gjsify link${S?` (dry-run)`:``}`;ge.log(`${W} → ${C}`),ge.log(`${` `.repeat(W.length)} in ${n}`);for(let t of H)ge.log(` ${t.name} → ${Tn(C,t.target)||`.`}`);let q=unbuiltDevLinks(H);if(q.length>0)return ge.error(`\n${formatUnbuiltDevLinks(q)}`),process.exit(1);let Y=sweepCheckouts(n,C),X=new Set(H.map(t=>t.name)),Z=scanDevLinks(n,Y).filter(t=>!X.has(t.name));for(let t of Z)ge.log(` retire ${t.name} (no longer selected)`);if(S){ge.log(`\n${W}: nothing written. Drop --dry-run to apply.`);return}let te=retireDevLinks(n,Y,X),ne=applyDevLinks(H);writeDevLinkOverride(n,{version:1,checkout:C,packages:I});let re=ensureLocallyIgnored(n);ge.log(`\n ${ne.length} link(s) written, ${H.length-ne.length} already current.`),Z.length>0&&ge.log(` ${te.length} of ${Z.length} retired link(s) removed.`),ge.log(` override: ${N}`),re===`added`&&ge.log(` git: ${HL} added to .git/info/exclude (local, never committed)`),re===`no-git`&&ge.log(` git: ${n} is not a git repository — nothing to ignore`),re===`unreadable-git`&&ge.warn(` ! git: ${n} has a .git POINTER that does not parse, so ${HL} is NOT ignored. Add it to .gitignore by hand, or the next \`git add -A\` commits your local override.`),ge.log("\nEvery `gjsify install` here now re-applies these links and says so.\n`gjsify install --immutable` refuses while the override exists. Undo: `gjsify unlink`.")}},CU={command:`unlink`,description:"Undo `gjsify link`: remove the development links and the .gjsify-link.json override, then reinstall the registry copies.",builder:t=>t.option(`dry-run`,{description:`Print what would be removed and change nothing.`,type:`boolean`,default:!1}).option(`install`,{description:"Reinstall after unlinking, to put the registry copies back where the links were. On by default; --no-install leaves the holes for a later `gjsify install`.",type:`boolean`,default:!0}),handler:async t=>{let n=process.cwd(),S=t[`dry-run`]??!1,C=devLinkPath(n);if(!existsSync(C)){ge.log(`gjsify unlink: no development link in ${n} (no ${HL}).`);return}let N=[];try{let t=readDevLinkOverride(n)?.checkout;t&&N.push(t)}catch{}let F=[];try{F=prepareDevLinks(n)?.links??[]}catch(t){ge.warn(`gjsify unlink: ${t instanceof Error?t.message:String(t)}\n Removing the override anyway; any dangling links are cleaned by the reinstall.`)}let I=`gjsify unlink${S?` (dry-run)`:``}`;if(ge.log(`${I} in ${n}`),S){let t=new Set(F.map(t=>t.name));for(let S of scanDevLinks(n,N))t.add(S.name);for(let n of[...t].sort())ge.log(` would remove link ${n}`);ge.log(` would remove ${C}`),ge.log(` would remove ${HL} entry from .git/info/exclude (if this module wrote it)`),ge.log(`\n${I}: nothing changed. Drop --dry-run to apply.`);return}let H=removeDevLinks(F),W=new Set(H.map(t=>t.name));for(let t of retireDevLinks(n,N,new Set))W.has(t.name)||H.push(t);for(let t of H)ge.log(` unlinked ${t.name}`);let q=scanDevLinks(n,N);if(q.length>0)return ge.error(`gjsify unlink: ${q.length} link(s) still point into a checkout and could not be removed:\n`+q.map(t=>` ${t.name} ${t.linkPath} → ${t.target}`).join(`
1184
- `)+`\n ${C} is kept so this stays undoable. Remove the paths above and re-run.`),process.exit(1);if(removeDevLinkOverride(n),ge.log(` removed ${C}`),removeLocalIgnore(n)===`removed`&&ge.log(` removed ${HL} entry from .git/info/exclude`),t.install===!1){ge.log(`\n ${H.length} link(s) removed. Run \`gjsify install\` to restore the registry copies.`);return}ge.log(`\n ${H.length} link(s) removed — reinstalling to restore the registry copies.\n`);let{runCli:Y}=await Promise.resolve().then(()=>(IK(),FK));await Y([`install`])}}});function signalTree(t,n,S){for(let t=n.length-1;t>=0;t--)try{process.kill(n[t],S)}catch{}try{t.kill(S)}catch{}}function killActiveChildren(){let t=new Map;for(let n of TU){let S=n.pid?collectDescendants(n.pid):[];t.set(n,S),signalTree(n,S,`SIGTERM`)}setTimeout(()=>{for(let n of TU){let S=new Set(n.pid?collectDescendants(n.pid):[]);for(let C of t.get(n)??[])S.add(C);signalTree(n,[...S],`SIGKILL`)}},EU).unref?.()}function assertEveryIncludeMatches(t,n){if(!n||n.length===0)return;let S=n.filter(n=>filterWorkspaces(t,{include:[n]}).length===0);if(S.length===0)return;let C=[`gjsify foreach: --include matched no workspace (${S.length} of ${n.length} pattern(s)):`];for(let n of S){C.push(` ${JSON.stringify(n)}`);let S=stripSurroundingQuotes(n);if(S!==n&&filterWorkspaces(t,{include:[S]}).length>0){C.push(` → matches as ${JSON.stringify(S)}: the QUOTES are part of the value. A shell expansion`," is not re-scanned for quoting, so a pre-quoted filter spliced through `sh -c` arrives with",` the quotes attached. Pass the bare name and let word splitting do the work.`);continue}let N=t.map(t=>t.name).filter(t=>t.toLowerCase().includes(S.replace(/\*/g,``).toLowerCase())).slice(0,3);N.length>0&&C.push(` → did you mean: ${N.join(`, `)}?`)}throw C.push(` ${t.length} workspace(s) discovered. Refusing to run: a filter that selects nothing would`,` otherwise exit 0 and look exactly like a successful run over the whole set.`),ge.error(C.join(`
1185
- `)),process.exit(1),Error(`gjsify foreach: --include matched no workspace`)}function stripSurroundingQuotes(t){return t.length>=2&&(t[0]===`'`||t[0]===`"`)&&t[t.length-1]===t[0]?t.slice(1,-1):t}async function runSequential(t,n,S,C,N,F){for(let I of t)await runOne(I,n,S,!1,C,N,F)}async function runParallel(t,n,S,C,N,F,I){let H=0,W=[];for(let q=0;q<C;q++)W.push((async()=>{for(;H<t.length;)await runOne(t[H++],n,S,!0,N,F,I)})());await Promise.all(W)}async function runTopologicalParallel(t,n,S,C,N,F,I,H){let W=new Map([...buildDependencyGraph(t,{includeDev:F}).edges].map(([t,n])=>[t,new Set(n)])),q=new Map(t.map(t=>[t.name,t])),Y=t.length,X=new Set,Z=0,te=!process.stdout.isTTY||N,ne=new Map,re=Number(process.env.GJSIFY_FOREACH_STALL_MINUTES??`20`),ie=(Number.isFinite(re)&&re>0?re:20)*6e4;return new Promise((t,F)=>{let re=null,ae=Date.now(),describeInflight=()=>[...ne.entries()].map(([t,n])=>`${t} (${Math.round((Date.now()-n)/1e3)}s)`).join(`, `),failFast=t=>{re||(re=t,killActiveChildren(),setTimeout(()=>settle(),DU).unref?.())},oe=setInterval(()=>{let t=Date.now()-ae;t<3e5||ne.size===0||(ge.error(`[gjsify foreach] WARNING: no workspace completed for ${Math.round(t/6e4)}min — in-flight: ${describeInflight()}`),t>=ie&&failFast(Error(`gjsify foreach: stalled — no workspace completed for ${Math.round(t/6e4)}min (override via GJSIFY_FOREACH_STALL_MINUTES); killed in-flight: ${describeInflight()}`)))},6e4);oe.unref?.();let settle=()=>{clearInterval(oe),re?F(re):t()},pump=()=>{if(!re){for(;Z<C;){let t=[...W.entries()].filter(([,t])=>[...t].every(t=>X.has(t))).map(([t])=>t);if(t.length===0)break;let C=t.sort()[0];W.delete(C),Z++,ne.set(C,Date.now()),te&&ge.error(`[gjsify foreach] start ${C} (${X.size}/${Y} done, ${Z} in flight)`),runOne(q.get(C),n,S,!0,N,I,H).then(()=>{X.add(C)}).catch(t=>{failFast(t instanceof Error?t:Error(String(t)))}).finally(()=>{Z--,ne.delete(C),ae=Date.now(),re?Z===0&&settle():W.size===0&&Z===0?settle():pump()})}W.size>0&&Z===0&&!re&&(clearInterval(oe),F(Error(`gjsify foreach --topological: stuck — workspaces ${[...W.keys()].join(`, `)} have unsatisfied deps in the selected set`)))}};pump()})}async function runOne(t,n,S,C,N,F,I){if(F){N&&ge.error(`[${t.name}] $ ${n} ${S.join(` `)}`),await spawnPrefixed(n,S,t.location,C?`[${t.name}] `:null);return}if(I&&I.tryRestore(t))return;let H=I?.snapshotOutputs(t),W=detectPackageManager(),q=W===`gjsify`?[`run`,n,...S]:[`run`,n,...S.length>0?[`--`,...S]:[]];N&&ge.error(`[${t.name}] $ ${W} ${q.join(` `)}`),await spawnPrefixed(W,q,t.location,C?`[${t.name}] `:null),I&&H&&I.storeAfterSuccess(t,H)}async function spawnPrefixed(t,n,S,C){let N=null,F=[];try{let I=await spawnToCompletion(t,n,{completion:`exit`,cwd:S,stdio:C?`pipe`:`inherit`,color:!0,onSpawn:t=>{N=t,TU.add(t);let n=!process.stdout.isTTY;C&&t.stdout&&t.stderr&&(F.push(prefixLines(t.stdout,process.stdout,C,n)),F.push(prefixLines(t.stderr,process.stderr,C,n)))}});for(let t of F)t();if(I.code!==0)throw Error(`${t} ${n.join(` `)} exited with code ${I.code}`)}finally{N&&TU.delete(N)}}var TU,EU,DU,OU,kU=__esmMin(()=>{_e(),V_(),gL(),Lg(),QP(),eF(),oI(),_R(),NI(),xR(),wR(),TU=new Set,EU=5e3,DU=15e3,OU={command:`foreach [script] [args..]`,description:"Run a workspace script across all (or filtered) workspaces. Drop-in for `yarn workspaces foreach`: -A/--all, -p/--parallel, -t/--topological, --include, --exclude, --no-private. Pass --exec to run an arbitrary command instead of a script.",builder:t=>t.positional(`script`,{description:"Script name to run in each workspace (`run <name>`-equivalent). With --exec, the command to run instead.",type:`string`}).positional(`args`,{description:`Extra arguments forwarded to each child invocation.`,type:`string`,array:!0}).option(`all`,{description:"Include workspaces declared as `private: true`.",type:`boolean`,alias:`A`,default:!1}).option(`parallel`,{description:`Run workspaces in parallel (capped by --jobs).`,type:`boolean`,alias:`p`,default:!1}).option(`topological`,{description:`Wait for each workspace's deps to finish before starting it (production deps only).`,type:`boolean`,alias:`t`,default:!1}).option(`topological-dev`,{description:`Like --topological but also respects devDependencies (often cyclic — use sparingly).`,type:`boolean`,default:!1}).option(`include`,{description:`Glob pattern to include workspaces by name (repeatable). A pattern that matches NO discovered workspace is a hard error — a filter selecting nothing is a typo or a caller-side quoting bug, never an intent.`,type:`string`,array:!0}).option(`exclude`,{description:`Glob pattern to exclude workspaces by name (repeatable).`,type:`string`,array:!0}).option(`with-dependencies`,{description:`Also select everything the filtered set DEPENDS ON (production deps; add --topological-dev for devDependencies). --include only filters and --topological only orders, so neither can say 'and the packages these need'. Excludes are re-applied afterwards.`,type:`boolean`,alias:`d`,default:!1}).option(`private`,{description:`Include private workspaces (default true). Pass --no-private to skip them.`,type:`boolean`,default:!0}).option(`verbose`,{description:`Echo every spawned command before running it.`,type:`boolean`,alias:`v`,default:!1}).option(`jobs`,{description:`Maximum concurrent workspaces in --parallel mode (default: cpu count).`,type:`number`,alias:`j`}).option(`exec`,{description:"Treat <script> [args..] as an arbitrary command (yarn `workspaces foreach exec`-equivalent) instead of a package.json script lookup. Workspace filtering by script presence is skipped. Use `-- <cmd> <args...>` to pass flags to the command without yargs intercepting them.",type:`boolean`,default:!1}).option(`cached`,{description:`Content-hash build cache (ADR 0006): skip a workspace whose inputs (src/**, package.json, tsconfig*.json, transitive workspace deps, toolchain versions) are unchanged and restore its stored outputs instead; on miss run the script and store the output dirs it modified. Script mode only. Default from GJSIFY_BUILD_CACHE=1.`,type:`boolean`}).option(`shard`,{description:`Run only a deterministic slice "<index>/<total>" (1-based) of the matched workspaces, e.g. --shard 2/4. For fanning a long run across parallel CI jobs. Partitions by sorted name (round-robin) so the shards are disjoint and their union is the full set; order-independent, so safe for tests but NOT for ordered builds.`,type:`string`}).parserConfiguration({"populate--":!0,"parse-positional-numbers":!1}),handler:async t=>{let n=findWorkspaceRoot(process.cwd())??process.cwd(),S=discoverWorkspaces(n),C=t.exec===!0,N=t.script,F=t.args??[];if(!C){let n=doubleDashArgs(t);n.length>0&&(F=[...F,...n])}if(C){let n=doubleDashArgs(t);if(n.length>0&&(N?F=[...F,...n]:(N=n[0],F=[...F,...n.slice(1)])),!N)return ge.error("gjsify foreach --exec: missing command. Pass it after `--`, e.g. `gjsify foreach --exec -- npm publish --tag latest`."),process.exit(1)}assertEveryIncludeMatches(S,t.include);let I=filterWorkspaces(S,{include:t.include,exclude:t.exclude,noPrivate:t.private===!1});if(t[`with-dependencies`]===!0){let n=affectedClosure(buildDependencyGraph(S,{includeDev:t[`topological-dev`]===!0}),I.map(t=>t.name));I=filterWorkspaces(S.filter(t=>n.has(t.name)),{exclude:t.exclude,noPrivate:t.private===!1})}if(!C){if(!N)return ge.error(`gjsify foreach: missing <script> positional. Pass --exec to run an arbitrary command instead.`),process.exit(1);let t=N;I=I.filter(n=>typeof(n.manifest.scripts??{})[t]==`string`)}if(typeof t.shard==`string`&&t.shard.length>0){let n=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t.shard);if(!n)return ge.error(`gjsify foreach: invalid --shard "${t.shard}" — expected "<index>/<total>" (1-based), e.g. 2/4.`),process.exit(1);let S=Number(n[1]),C=Number(n[2]);if(C<1||S<1||S>C)return ge.error(`gjsify foreach: invalid --shard "${t.shard}" — need 1 <= index <= total and total >= 1.`),process.exit(1);if(C>1){let t=[...I].sort((t,n)=>t.name<n.name?-1:+(t.name>n.name));I=t.filter((t,n)=>n%C===S-1),ge.log(`gjsify foreach: shard ${S}/${C} → ${I.length} of ${t.length} workspace(s)`)}}if(I.length===0){ge.log(`gjsify foreach: no workspaces match (${C?`exec`:`script`}="${N}", include=${JSON.stringify(t.include??[])}, exclude=${JSON.stringify(t.exclude??[])})`);return}(t.topological||t[`topological-dev`])&&(I=topologicalSort(buildDependencyGraph(I,{includeDev:t[`topological-dev`]===!0})));let H=t.verbose===!0,W=N,q=t.cached??buildCacheEnabledByEnv();if(t.cached===!0&&C)return ge.error(`gjsify foreach: --cached only applies to script mode, not --exec.`),process.exit(1);let Y=q&&!C?new BuildCacheRunner({root:n,workspaces:S,script:W,args:F,targets:I.map(t=>t.name)}):void 0,X=t.parallel===!0?cliRuntimeClosure(S):new Set,Z=X.size>0?I.filter(t=>X.has(t.name)):[],te=Z.length>0?I.filter(t=>!X.has(t.name)):I;try{if(Z.length>0){ge.error(`[gjsify foreach] serial prefix: ${Z.length} package(s) the running CLI imports — ${Z.map(t=>t.name).join(`, `)}`);for(let t of Z)ge.error(`[gjsify foreach] start ${t.name} (serial prefix)`),await runOne(t,W,F,!0,H,C,Y)}if(t.parallel&&!t.topological&&!t[`topological-dev`]){let n=t.jobs&&t.jobs>0?t.jobs:cpus().length;await runParallel(te,W,F,n,H,C,Y)}else if(t.parallel){let n=t.jobs&&t.jobs>0?t.jobs:cpus().length;await runTopologicalParallel(te,W,F,n,H,t[`topological-dev`]===!0,C,Y)}else await runSequential(te,W,F,H,C,Y)}catch(t){return killActiveChildren(),ge.error(t.message),process.exit(1)}process.exit(0)}}});async function runLifecycleScript(t,n,S,C={}){let N=(n.scripts??{})[S];if(typeof N!=`string`){if(C.optional!==!1)return!1;throw Error(`gjsify lifecycle-script: no "${S}" in ${t}/package.json`)}let F=findWorkspaceRoot(t),I=[wn(t,`node_modules`,`.bin`)];F&&F!==t&&I.push(wn(F,`node_modules`,`.bin`));let H=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`},W={...process.env,...H,PATH:[...I,process.env.PATH??``].filter(Boolean).join(Mn),npm_lifecycle_event:S,npm_package_name:n.name??``,npm_package_version:n.version??``,...C.env};if(C.stdio===`ignore`)throw Error(`gjsify lifecycle-script: stdio "ignore" is not supported — see utils/spawn.ts`);let q=await spawnToCompletion(N,[],{completion:`return`,cwd:t,env:W,shell:!0,stdio:C.stdio===`inherit-stderr`?`inherit-stderr`:C.stdio===`pipe`?`pipe`:`inherit`});if(q.code!==0)throw Error(`gjsify lifecycle-script: "${S}" in ${t} exited with ${describeExit(q)}`);return!0}var AU=__esmMin(()=>{Pn(),V_(),eF()});async function packWorkspace(t,n={}){let S=wn(t,`package.json`);if(!existsSync(S))throw Error(`gjsify pack: no package.json at ${t}`);let C=readFileSync(S,`utf-8`),N=JSON.parse(C),F=typeof N.name==`string`?N.name:``,I=typeof N.version==`string`?N.version:`0.0.0`;if(!F)throw Error(`gjsify pack: package.json at ${t} has no "name"`);let H=n.lifecycleScripts??[`prepack`];for(let S of H)await runLifecycleScript(t,N,S,{optional:!0,stdio:n.lifecycleStdio});let W=readFileSync(S,`utf-8`),q=W===C?N:JSON.parse(W),Y=n.skipWorkspaceRewrite?q:rewriteWorkspaceDeps(q,t),X=JSON.stringify(Y,null,indentOf(W))+`
1183
+ install: no \`-musl\` package is published for any target yet.`)}}maybeInstallGitHooks()}function maybeInstallGitHooks(){let t=process.cwd(),n=wn(t,`scripts`,`install-git-hooks.mjs`);if(existsSync(n)&&existsSync(wn(t,`.git`)))try{let S=spawnSync(nodeBinary(),[n,`--quiet`],{cwd:t,stdio:`inherit`,env:process.env});S.status!==0&&ge.warn(`[gjsify install] scripts/install-git-hooks.mjs exited ${S.status} — git hooks may not be active.`)}catch(t){ge.warn(`[gjsify install] git hook installation skipped: ${t instanceof Error?t.message:String(t)}`)}}var SU,CU,wU,TU,EU=__esmMin(()=>{_e(),Rd(),Pn(),Gn(),P_(),xU(),QP(),vF(),CF(),qI(),aR(),dL(),AL(),rL(),V_(),eF(),Uz(),lR(),WL(),KL(),lL(),YL(),SU=process.platform===`win32`?`junction`:void 0,CU=18e5,wU={command:`install [packages..]`,description:`Install npm dependencies in the current project (or globally with -g), then run gjsify-aware post-checks.`,builder:t=>t.positional(`packages`,{description:`Optional package specs. With none, runs a full project install.`,type:`string`,array:!0}).option(`global`,{description:`Install into the user-global XDG location and symlink bins into ~/.local/bin.`,type:`boolean`,alias:`g`,default:!1}).option(`save-dev`,{type:`boolean`,alias:`D`}).option(`save-peer`,{type:`boolean`}).option(`save-optional`,{type:`boolean`,alias:`O`}).option(`immutable`,{description:`CI mode: install strictly from gjsify-lock.json, fail if the lockfile is missing or stale. Equivalent to yarn --immutable / npm ci --frozen-lockfile.`,type:`boolean`,default:!1}).option(`refresh-lockfile`,{description:`Re-resolve every dependency to the newest version satisfying its range and rewrite the lockfile (bumps in-range transitive deps). Without it, a resolve preserves versions already pinned in the lockfile and only resolves new/changed deps — the npm/yarn/pnpm default. Mirrors yarn install --mode=update-lockfile.`,type:`boolean`,default:!1}).option(`focus`,{description:`Install only the named workspaces (package names), the workspaces they depend on, and their external dependencies, as if they were the only members of the monorepo (yarn workspaces focus). Reads gjsify-lock.json and never rewrites it; fails if it is missing or stale. Workspace projects only.`,type:`string`,array:!0}).option(`verbose`,{description:`Verbose install logging.`,type:`boolean`,default:!1}).option(`quiet`,{description:`Silence the progress bar.`,type:`boolean`,default:!1}).option(`progress`,{description:`Show a TTY-aware progress bar for resolve / download / extract phases. Auto-enabled when stderr is a TTY (override with --no-progress). Implicitly off under --verbose (per-package log lines replace the bar) or --quiet.`,type:`boolean`,default:!0}).option(`backend`,{description:"Install backend. `native` (default) routes through `@gjsify/{semver,npm-registry,tar}` — no Node/npm at runtime. `npm` shells out to `npm install` as an escape hatch for cases the native backend does not yet model (Yarn PnP repos, lifecycle scripts). Overrides `GJSIFY_INSTALL_BACKEND` if both are set.",type:`string`,choices:[`native`,`npm`]}).option(`timeout`,{description:`Overall install wall-clock timeout in ms (default 1800000 = 30 min). On timeout, all in-flight registry fetches are aborted and the install exits non-zero with a clear "install timed out — likely a registry slowdown" message. Per-request timeouts in @gjsify/npm-registry (default 30s) still apply within this budget. Set to 0 to disable the overall budget.`,type:`number`,default:CU}).option(`os`,{description:"Resolve/install for this OS instead of the running one (npm config key `os`, e.g. darwin, win32, linux). Affects which packages pass the os/cpu/libc compatibility check; the lockfile stays platform-independent either way.",type:`string`}).option(`cpu`,{description:"Resolve/install for this CPU architecture instead of the running one (npm config key `cpu`, e.g. x64, arm64).",type:`string`}).option(`libc`,{description:"Resolve/install for this libc family instead of probing the host (npm config key `libc`: glibc or musl). Only meaningful with --os=linux. A package declaring a libc is incompatible when the target libc is unknown.",type:`string`}).option(`force`,{description:"Install a REQUIRED dependency even when its os/cpu/libc excludes the target, instead of failing with EBADPLATFORM (npm config key `force`). Incompatible OPTIONAL dependencies stay skipped — npm ignores --force for those too, and a binary that cannot load is not worth downloading.",type:`boolean`,default:!1}).option(`prune`,{description:`After installing, remove packages an earlier install left behind that this host cannot use (foreign os/cpu/libc). Use --no-prune to disable. Skipped automatically under --immutable, and whenever --os/--cpu/--libc is given: an install must never delete against a target the user typed.`,type:`boolean`,default:!0}),handler:async t=>{if(applyPlatformConfigFromFlags(t),t.immutable){if(t.packages&&t.packages.length>0)return ge.error(`gjsify install --immutable does not accept package arguments. Remove the package names or drop --immutable.`),process.exit(1);if(t.global)return ge.error(`gjsify install --immutable is incompatible with --global.`),process.exit(1);if(t[`refresh-lockfile`])return ge.error(`gjsify install --immutable is incompatible with --refresh-lockfile (--immutable forbids rewriting the lockfile). Drop one.`),process.exit(1);assertNoDevLinkUnderImmutable(process.cwd())}if(t.global){if(!t.packages||t.packages.length===0)return ge.error(`gjsify install --global requires at least one <pkg> argument.`),process.exit(1);for(let n of[`save-dev`,`save-peer`,`save-optional`])t[n]&&ge.warn(`gjsify install --global ignores --${n}: global installs do not modify a project package.json.`);await installGlobalAndLink(t.packages,{verbose:t.verbose,prune:t.prune});return}if(warnOnCliVersionSkew(process.cwd()),(t.backend??process.env.GJSIFY_INSTALL_BACKEND??`native`)===`npm`){await projectInstallViaNpm(t),pruneProjectPrefix(t),await runPostInstallChecks(t);return}let n=t.timeout>0?t.timeout:0,S=n>0?new AbortController:null,C=S===null?null:setTimeout(()=>S.abort(Error(`install-overall-timeout`)),n),N=n>0?setTimeout(()=>{let t=Math.round(n/100)/10;ge.error(`gjsify install: the ${t}s budget elapsed and the abort did not unwind within 10s — forcing exit. That means one of two things, and this timer cannot distinguish them: the install was still WORKING (a cold tree here extracts several GB, and extraction blocks the loop in multi-second synchronous stretches), or a step genuinely wedged. Re-running tells you which, and is safe: extraction is idempotent, every package already on disk is skipped, so a second run finishes the remainder in a fraction of the time. A re-run that makes NO further progress is a real wedge — file an issue.`),forceExit(1)},n+1e4):null;N?.unref?.();try{await projectInstallNative(t,S?.signal),pruneProjectPrefix(t),await runPostInstallChecks(t)}catch(t){if(S!==null&&S.signal.aborted&&isAbortedFromOverallTimeout(t)){let t=Math.round(n/100)/10;return ge.error(`gjsify install: timed out after ${t}s — likely a registry slowdown or a wedged extract.\nRe-run, or override with --timeout <ms> (set --timeout 0 to disable the overall budget).`),process.exit(1)}throw t}finally{C!==null&&clearTimeout(C),N!==null&&clearTimeout(N)}}},TU=`@gjsify/cli`});function sweepCheckouts(t,n){let S=null;try{S=readDevLinkOverride(t)?.checkout??null}catch{S=null}return S&&S!==n?[S,n]:[n]}var DU,OU,kU=__esmMin(()=>{_e(),Rd(),Pn(),YL(),DU={command:`link <checkout>`,description:"Link this project against a local gjsify checkout for development: its workspace packages replace the installed registry copies, recorded in a git-ignored .gjsify-link.json that every later `gjsify install` re-applies. Undo with `gjsify unlink`.",builder:t=>t.positional(`checkout`,{description:`Path to the gjsify checkout to link from (a repo whose package.json declares "workspaces").`,type:`string`,demandOption:!0}).option(`packages`,{description:"Name glob selecting which of the checkout's workspace packages take part (repeatable; default: all of them). Matched against the package NAME with the same single-segment dialect as `gjsify foreach --include`, so a whole scope is `@gjsify/*` — a bare `*` matches no scoped name. Only packages this project actually depends on are ever linked.",type:`string`,array:!0}).option(`dry-run`,{description:`Print the links that would be made and write nothing.`,type:`boolean`,default:!1}),handler:t=>{let n=process.cwd(),S=t[`dry-run`]??!1,C=xn(n,t.checkout),N=devLinkPath(n),F=resolveCheckoutWorkspaces(C,N),I=t.packages??[],H=planDevLinks({consumerRoot:n,workspaces:F,patterns:I,knownNames:consumerKnownNames(n)});if(H.length===0)return ge.error(`gjsify link: nothing to link — ${C} has ${F.length} workspace package(s), none of which ${n} depends on${I.length===0?``:` and matches ${I.join(`, `)}`}.\nA link that links nothing is a silent no-op, so this is an error. Check the --packages pattern, or run \`gjsify install\` first so the dependency tree exists.`),process.exit(1);let W=`gjsify link${S?` (dry-run)`:``}`;ge.log(`${W} → ${C}`),ge.log(`${` `.repeat(W.length)} in ${n}`);for(let t of H)ge.log(` ${t.name} → ${Tn(C,t.target)||`.`}`);let q=unbuiltDevLinks(H);if(q.length>0)return ge.error(`\n${formatUnbuiltDevLinks(q)}`),process.exit(1);let Y=sweepCheckouts(n,C),X=new Set(H.map(t=>t.name)),Z=scanDevLinks(n,Y).filter(t=>!X.has(t.name));for(let t of Z)ge.log(` retire ${t.name} (no longer selected)`);if(S){ge.log(`\n${W}: nothing written. Drop --dry-run to apply.`);return}let te=retireDevLinks(n,Y,X),ne=applyDevLinks(H);writeDevLinkOverride(n,{version:1,checkout:C,packages:I});let re=ensureLocallyIgnored(n);ge.log(`\n ${ne.length} link(s) written, ${H.length-ne.length} already current.`),Z.length>0&&ge.log(` ${te.length} of ${Z.length} retired link(s) removed.`),ge.log(` override: ${N}`),re===`added`&&ge.log(` git: ${qL} added to .git/info/exclude (local, never committed)`),re===`no-git`&&ge.log(` git: ${n} is not a git repository — nothing to ignore`),re===`unreadable-git`&&ge.warn(` ! git: ${n} has a .git POINTER that does not parse, so ${qL} is NOT ignored. Add it to .gitignore by hand, or the next \`git add -A\` commits your local override.`),ge.log("\nEvery `gjsify install` here now re-applies these links and says so.\n`gjsify install --immutable` refuses while the override exists. Undo: `gjsify unlink`.")}},OU={command:`unlink`,description:"Undo `gjsify link`: remove the development links and the .gjsify-link.json override, then reinstall the registry copies.",builder:t=>t.option(`dry-run`,{description:`Print what would be removed and change nothing.`,type:`boolean`,default:!1}).option(`install`,{description:"Reinstall after unlinking, to put the registry copies back where the links were. On by default; --no-install leaves the holes for a later `gjsify install`.",type:`boolean`,default:!0}),handler:async t=>{let n=process.cwd(),S=t[`dry-run`]??!1,C=devLinkPath(n);if(!existsSync(C)){ge.log(`gjsify unlink: no development link in ${n} (no ${qL}).`);return}let N=[];try{let t=readDevLinkOverride(n)?.checkout;t&&N.push(t)}catch{}let F=[];try{F=prepareDevLinks(n)?.links??[]}catch(t){ge.warn(`gjsify unlink: ${t instanceof Error?t.message:String(t)}\n Removing the override anyway; any dangling links are cleaned by the reinstall.`)}let I=`gjsify unlink${S?` (dry-run)`:``}`;if(ge.log(`${I} in ${n}`),S){let t=new Set(F.map(t=>t.name));for(let S of scanDevLinks(n,N))t.add(S.name);for(let n of[...t].sort())ge.log(` would remove link ${n}`);ge.log(` would remove ${C}`),ge.log(` would remove ${qL} entry from .git/info/exclude (if this module wrote it)`),ge.log(`\n${I}: nothing changed. Drop --dry-run to apply.`);return}let H=removeDevLinks(F),W=new Set(H.map(t=>t.name));for(let t of retireDevLinks(n,N,new Set))W.has(t.name)||H.push(t);for(let t of H)ge.log(` unlinked ${t.name}`);let q=scanDevLinks(n,N);if(q.length>0)return ge.error(`gjsify unlink: ${q.length} link(s) still point into a checkout and could not be removed:\n`+q.map(t=>` ${t.name} ${t.linkPath} → ${t.target}`).join(`
1184
+ `)+`\n ${C} is kept so this stays undoable. Remove the paths above and re-run.`),process.exit(1);if(removeDevLinkOverride(n),ge.log(` removed ${C}`),removeLocalIgnore(n)===`removed`&&ge.log(` removed ${qL} entry from .git/info/exclude`),t.install===!1){ge.log(`\n ${H.length} link(s) removed. Run \`gjsify install\` to restore the registry copies.`);return}ge.log(`\n ${H.length} link(s) removed — reinstalling to restore the registry copies.\n`);let{runCli:Y}=await Promise.resolve().then(()=>(UK(),HK));await Y([`install`])}}});function signalTree(t,n,S){for(let t=n.length-1;t>=0;t--)try{process.kill(n[t],S)}catch{}try{t.kill(S)}catch{}}function killActiveChildren(){let t=new Map;for(let n of AU){let S=n.pid?collectDescendants(n.pid):[];t.set(n,S),signalTree(n,S,`SIGTERM`)}setTimeout(()=>{for(let n of AU){let S=new Set(n.pid?collectDescendants(n.pid):[]);for(let C of t.get(n)??[])S.add(C);signalTree(n,[...S],`SIGKILL`)}},jU).unref?.()}function assertEveryIncludeMatches(t,n){if(!n||n.length===0)return;let S=n.filter(n=>filterWorkspaces(t,{include:[n]}).length===0);if(S.length===0)return;let C=[`gjsify foreach: --include matched no workspace (${S.length} of ${n.length} pattern(s)):`];for(let n of S){C.push(` ${JSON.stringify(n)}`);let S=stripSurroundingQuotes(n);if(S!==n&&filterWorkspaces(t,{include:[S]}).length>0){C.push(` → matches as ${JSON.stringify(S)}: the QUOTES are part of the value. A shell expansion`," is not re-scanned for quoting, so a pre-quoted filter spliced through `sh -c` arrives with",` the quotes attached. Pass the bare name and let word splitting do the work.`);continue}let N=t.map(t=>t.name).filter(t=>t.toLowerCase().includes(S.replace(/\*/g,``).toLowerCase())).slice(0,3);N.length>0&&C.push(` → did you mean: ${N.join(`, `)}?`)}throw C.push(` ${t.length} workspace(s) discovered. Refusing to run: a filter that selects nothing would`,` otherwise exit 0 and look exactly like a successful run over the whole set.`),ge.error(C.join(`
1185
+ `)),process.exit(1),Error(`gjsify foreach: --include matched no workspace`)}function stripSurroundingQuotes(t){return t.length>=2&&(t[0]===`'`||t[0]===`"`)&&t[t.length-1]===t[0]?t.slice(1,-1):t}async function runSequential(t,n,S,C,N,F){for(let I of t)await runOne(I,n,S,!1,C,N,F)}async function runParallel(t,n,S,C,N,F,I){let H=0,W=[];for(let q=0;q<C;q++)W.push((async()=>{for(;H<t.length;)await runOne(t[H++],n,S,!0,N,F,I)})());await Promise.all(W)}async function runTopologicalParallel(t,n,S,C,N,F,I,H){let W=new Map([...buildDependencyGraph(t,{includeDev:F}).edges].map(([t,n])=>[t,new Set(n)])),q=new Map(t.map(t=>[t.name,t])),Y=t.length,X=new Set,Z=0,te=!process.stdout.isTTY||N,ne=new Map,re=Number(process.env.GJSIFY_FOREACH_STALL_MINUTES??`20`),ie=(Number.isFinite(re)&&re>0?re:20)*6e4;return new Promise((t,F)=>{let re=null,ae=Date.now(),describeInflight=()=>[...ne.entries()].map(([t,n])=>`${t} (${Math.round((Date.now()-n)/1e3)}s)`).join(`, `),failFast=t=>{re||(re=t,killActiveChildren(),setTimeout(()=>settle(),MU).unref?.())},oe=setInterval(()=>{let t=Date.now()-ae;t<3e5||ne.size===0||(ge.error(`[gjsify foreach] WARNING: no workspace completed for ${Math.round(t/6e4)}min — in-flight: ${describeInflight()}`),t>=ie&&failFast(Error(`gjsify foreach: stalled — no workspace completed for ${Math.round(t/6e4)}min (override via GJSIFY_FOREACH_STALL_MINUTES); killed in-flight: ${describeInflight()}`)))},6e4);oe.unref?.();let settle=()=>{clearInterval(oe),re?F(re):t()},pump=()=>{if(!re){for(;Z<C;){let t=[...W.entries()].filter(([,t])=>[...t].every(t=>X.has(t))).map(([t])=>t);if(t.length===0)break;let C=t.sort()[0];W.delete(C),Z++,ne.set(C,Date.now()),te&&ge.error(`[gjsify foreach] start ${C} (${X.size}/${Y} done, ${Z} in flight)`),runOne(q.get(C),n,S,!0,N,I,H).then(()=>{X.add(C)}).catch(t=>{failFast(t instanceof Error?t:Error(String(t)))}).finally(()=>{Z--,ne.delete(C),ae=Date.now(),re?Z===0&&settle():W.size===0&&Z===0?settle():pump()})}W.size>0&&Z===0&&!re&&(clearInterval(oe),F(Error(`gjsify foreach --topological: stuck — workspaces ${[...W.keys()].join(`, `)} have unsatisfied deps in the selected set`)))}};pump()})}async function runOne(t,n,S,C,N,F,I){if(F){N&&ge.error(`[${t.name}] $ ${n} ${S.join(` `)}`),await spawnPrefixed(n,S,t.location,C?`[${t.name}] `:null);return}if(I&&I.tryRestore(t))return;let H=I?.snapshotOutputs(t),W=detectPackageManager(),q=W===`gjsify`?[`run`,n,...S]:[`run`,n,...S.length>0?[`--`,...S]:[]];N&&ge.error(`[${t.name}] $ ${W} ${q.join(` `)}`),await spawnPrefixed(W,q,t.location,C?`[${t.name}] `:null),I&&H&&I.storeAfterSuccess(t,H)}async function spawnPrefixed(t,n,S,C){let N=null,F=[];try{let I=await spawnToCompletion(t,n,{completion:`exit`,cwd:S,stdio:C?`pipe`:`inherit`,color:!0,onSpawn:t=>{N=t,AU.add(t);let n=!process.stdout.isTTY;C&&t.stdout&&t.stderr&&(F.push(prefixLines(t.stdout,process.stdout,C,n)),F.push(prefixLines(t.stderr,process.stderr,C,n)))}});for(let t of F)t();if(I.code!==0)throw Error(`${t} ${n.join(` `)} exited with code ${I.code}`)}finally{N&&AU.delete(N)}}var AU,jU,MU,NU,PU=__esmMin(()=>{_e(),V_(),xL(),Lg(),QP(),eF(),dI(),SR(),RI(),ER(),kR(),AU=new Set,jU=5e3,MU=15e3,NU={command:`foreach [script] [args..]`,description:"Run a workspace script across all (or filtered) workspaces. Drop-in for `yarn workspaces foreach`: -A/--all, -p/--parallel, -t/--topological, --include, --exclude, --no-private. Pass --exec to run an arbitrary command instead of a script.",builder:t=>t.positional(`script`,{description:"Script name to run in each workspace (`run <name>`-equivalent). With --exec, the command to run instead.",type:`string`}).positional(`args`,{description:`Extra arguments forwarded to each child invocation.`,type:`string`,array:!0}).option(`all`,{description:"Include workspaces declared as `private: true`.",type:`boolean`,alias:`A`,default:!1}).option(`parallel`,{description:`Run workspaces in parallel (capped by --jobs).`,type:`boolean`,alias:`p`,default:!1}).option(`topological`,{description:`Wait for each workspace's deps to finish before starting it (production deps only).`,type:`boolean`,alias:`t`,default:!1}).option(`topological-dev`,{description:`Like --topological but also respects devDependencies (often cyclic — use sparingly).`,type:`boolean`,default:!1}).option(`include`,{description:`Glob pattern to include workspaces by name (repeatable). A pattern that matches NO discovered workspace is a hard error — a filter selecting nothing is a typo or a caller-side quoting bug, never an intent.`,type:`string`,array:!0}).option(`exclude`,{description:`Glob pattern to exclude workspaces by name (repeatable).`,type:`string`,array:!0}).option(`with-dependencies`,{description:`Also select everything the filtered set DEPENDS ON (production deps; add --topological-dev for devDependencies). --include only filters and --topological only orders, so neither can say 'and the packages these need'. Excludes are re-applied afterwards.`,type:`boolean`,alias:`d`,default:!1}).option(`private`,{description:`Include private workspaces (default true). Pass --no-private to skip them.`,type:`boolean`,default:!0}).option(`verbose`,{description:`Echo every spawned command before running it.`,type:`boolean`,alias:`v`,default:!1}).option(`jobs`,{description:`Maximum concurrent workspaces in --parallel mode (default: cpu count).`,type:`number`,alias:`j`}).option(`exec`,{description:"Treat <script> [args..] as an arbitrary command (yarn `workspaces foreach exec`-equivalent) instead of a package.json script lookup. Workspace filtering by script presence is skipped. Use `-- <cmd> <args...>` to pass flags to the command without yargs intercepting them.",type:`boolean`,default:!1}).option(`cached`,{description:`Content-hash build cache (ADR 0006): skip a workspace whose inputs (src/**, package.json, tsconfig*.json, transitive workspace deps, toolchain versions) are unchanged and restore its stored outputs instead; on miss run the script and store the output dirs it modified. Script mode only. Default from GJSIFY_BUILD_CACHE=1.`,type:`boolean`}).option(`shard`,{description:`Run only a deterministic slice "<index>/<total>" (1-based) of the matched workspaces, e.g. --shard 2/4. For fanning a long run across parallel CI jobs. Partitions by sorted name (round-robin) so the shards are disjoint and their union is the full set; order-independent, so safe for tests but NOT for ordered builds.`,type:`string`}).parserConfiguration({"populate--":!0,"parse-positional-numbers":!1}),handler:async t=>{let n=findWorkspaceRoot(process.cwd())??process.cwd(),S=discoverWorkspaces(n),C=t.exec===!0,N=t.script,F=t.args??[];if(!C){let n=doubleDashArgs(t);n.length>0&&(F=[...F,...n])}if(C){let n=doubleDashArgs(t);if(n.length>0&&(N?F=[...F,...n]:(N=n[0],F=[...F,...n.slice(1)])),!N)return ge.error("gjsify foreach --exec: missing command. Pass it after `--`, e.g. `gjsify foreach --exec -- npm publish --tag latest`."),process.exit(1)}assertEveryIncludeMatches(S,t.include);let I=filterWorkspaces(S,{include:t.include,exclude:t.exclude,noPrivate:t.private===!1});if(t[`with-dependencies`]===!0){let n=affectedClosure(buildDependencyGraph(S,{includeDev:t[`topological-dev`]===!0}),I.map(t=>t.name));I=filterWorkspaces(S.filter(t=>n.has(t.name)),{exclude:t.exclude,noPrivate:t.private===!1})}if(!C){if(!N)return ge.error(`gjsify foreach: missing <script> positional. Pass --exec to run an arbitrary command instead.`),process.exit(1);let t=N;I=I.filter(n=>typeof(n.manifest.scripts??{})[t]==`string`)}if(typeof t.shard==`string`&&t.shard.length>0){let n=/^\s*(\d+)\s*\/\s*(\d+)\s*$/.exec(t.shard);if(!n)return ge.error(`gjsify foreach: invalid --shard "${t.shard}" — expected "<index>/<total>" (1-based), e.g. 2/4.`),process.exit(1);let S=Number(n[1]),C=Number(n[2]);if(C<1||S<1||S>C)return ge.error(`gjsify foreach: invalid --shard "${t.shard}" — need 1 <= index <= total and total >= 1.`),process.exit(1);if(C>1){let t=[...I].sort((t,n)=>t.name<n.name?-1:+(t.name>n.name));I=t.filter((t,n)=>n%C===S-1),ge.log(`gjsify foreach: shard ${S}/${C} → ${I.length} of ${t.length} workspace(s)`)}}if(I.length===0){ge.log(`gjsify foreach: no workspaces match (${C?`exec`:`script`}="${N}", include=${JSON.stringify(t.include??[])}, exclude=${JSON.stringify(t.exclude??[])})`);return}(t.topological||t[`topological-dev`])&&(I=topologicalSort(buildDependencyGraph(I,{includeDev:t[`topological-dev`]===!0})));let H=t.verbose===!0,W=N,q=t.cached??buildCacheEnabledByEnv();if(t.cached===!0&&C)return ge.error(`gjsify foreach: --cached only applies to script mode, not --exec.`),process.exit(1);let Y=q&&!C?new BuildCacheRunner({root:n,workspaces:S,script:W,args:F,targets:I.map(t=>t.name)}):void 0,X=t.parallel===!0?cliRuntimeClosure(S):new Set,Z=X.size>0?I.filter(t=>X.has(t.name)):[],te=Z.length>0?I.filter(t=>!X.has(t.name)):I;try{if(Z.length>0){ge.error(`[gjsify foreach] serial prefix: ${Z.length} package(s) the running CLI imports — ${Z.map(t=>t.name).join(`, `)}`);for(let t of Z)ge.error(`[gjsify foreach] start ${t.name} (serial prefix)`),await runOne(t,W,F,!0,H,C,Y)}if(t.parallel&&!t.topological&&!t[`topological-dev`]){let n=t.jobs&&t.jobs>0?t.jobs:cpus().length;await runParallel(te,W,F,n,H,C,Y)}else if(t.parallel){let n=t.jobs&&t.jobs>0?t.jobs:cpus().length;await runTopologicalParallel(te,W,F,n,H,t[`topological-dev`]===!0,C,Y)}else await runSequential(te,W,F,H,C,Y)}catch(t){return killActiveChildren(),ge.error(t.message),process.exit(1)}process.exit(0)}}});async function runLifecycleScript(t,n,S,C={}){let N=(n.scripts??{})[S];if(typeof N!=`string`){if(C.optional!==!1)return!1;throw Error(`gjsify lifecycle-script: no "${S}" in ${t}/package.json`)}let F=findWorkspaceRoot(t),I=[wn(t,`node_modules`,`.bin`)];F&&F!==t&&I.push(wn(F,`node_modules`,`.bin`));let H=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`},W={...process.env,...H,PATH:[...I,process.env.PATH??``].filter(Boolean).join(Mn),npm_lifecycle_event:S,npm_package_name:n.name??``,npm_package_version:n.version??``,...C.env};if(C.stdio===`ignore`)throw Error(`gjsify lifecycle-script: stdio "ignore" is not supported — see utils/spawn.ts`);let q=await spawnToCompletion(N,[],{completion:`return`,cwd:t,env:W,shell:!0,stdio:C.stdio===`inherit-stderr`?`inherit-stderr`:C.stdio===`pipe`?`pipe`:`inherit`});if(q.code!==0)throw Error(`gjsify lifecycle-script: "${S}" in ${t} exited with ${describeExit(q)}`);return!0}var FU=__esmMin(()=>{Pn(),V_(),eF()});async function packWorkspace(t,n={}){let S=wn(t,`package.json`);if(!existsSync(S))throw Error(`gjsify pack: no package.json at ${t}`);let C=readFileSync(S,`utf-8`),N=JSON.parse(C),F=typeof N.name==`string`?N.name:``,I=typeof N.version==`string`?N.version:`0.0.0`;if(!F)throw Error(`gjsify pack: package.json at ${t} has no "name"`);let H=n.lifecycleScripts??[`prepack`];for(let S of H)await runLifecycleScript(t,N,S,{optional:!0,stdio:n.lifecycleStdio});let W=readFileSync(S,`utf-8`),q=W===C?N:JSON.parse(W),Y=n.skipWorkspaceRewrite?q:rewriteWorkspaceDeps(q,t),X=JSON.stringify(Y,null,indentOf(W))+`
1186
1186
  `,Z=collectPackedFiles(t,q);assertTypeDeclarationsShipped(t,q,Z);let te=[{name:`package/`,directory:!0,mode:493}],ne=[],re=0;for(let n of Z){let S;S=n===`package.json`?new TextEncoder().encode(X):new Uint8Array(readFileSync(wn(t,n)));let C=statSync(wn(t,n)).mode&511;te.push({name:`package/${n}`,body:S,mode:C,mtime:0}),ne.push({path:n,size:S.byteLength,mode:C}),re+=S.byteLength}let ie=await gzip(createTarball(te)),ae=`${F.startsWith(`@`)?F.slice(1).replace(`/`,`-`):F}-${I}.tgz`,oe=createHash(`sha1`).update(ie).digest(`hex`),Q=`sha512-${createHash(`sha512`).update(ie).digest(`base64`)}`,se=n.destination?xn(n.destination):t,ce=wn(se,ae);return n.dryRun||(mkdirSync(se,{recursive:!0}),writeFileSync(ce,ie)),{filename:ae,name:F,version:I,size:ie.byteLength,unpackedSize:re,shasum:oe,integrity:Q,entryCount:ne.length,files:ne,absolutePath:n.dryRun?null:ce}}function collectPackedFiles(t,n){let S=forceIncluded(n),C=Array.isArray(n.files)?n.files.filter(t=>typeof t==`string`):null,N=new Set;if(C)for(let n of expandFilesPatterns(t,C))N.add(n);else{let n=loadIgnore(t);for(let S of walkAll(t))n(S)||N.add(S)}for(let n of S)existsSync(wn(t,n))&&N.add(n);return[...N].sort()}function collectTypeDeclarationRefs(t){let n=new Set,add=t=>{if(typeof t!=`string`)return;let S=t.replace(/^\.\//,``);S.includes(`*`)||n.add(S)};for(let n of[`types`,`typings`])add(t[n]);let walk=t=>{if(!(!t||typeof t!=`object`)){if(Array.isArray(t)){for(let n of t)walk(n);return}for(let[n,S]of Object.entries(t))n===`types`||n===`typings`?add(S):walk(S)}};return walk(t.exports),[...n]}function assertTypeDeclarationsShipped(t,n,S){let C=new Set(S),N=collectTypeDeclarationRefs(n).filter(n=>{let S=wn(t,n);return existsSync(S)&&statSync(S).isFile()&&!C.has(n)});if(N.length===0)return;let F=typeof n.name==`string`?n.name:`(unnamed)`,I=Array.isArray(n.files)?JSON.stringify(n.files):`(none)`;throw Error(`gjsify pack: ${F} references TypeScript declaration file(s) via "exports"/"types" that exist on disk but are excluded from the tarball by the "files" allowlist (${I}):\n`+N.map(t=>` - ${t}`).join(`
1187
1187
  `)+`
1188
- Add the missing path(s) to package.json "files" so type resolution isn't silently broken for consumers.`)}function forceIncluded(t){let n=new Set;n.add(`package.json`);for(let t of[`README`,`README.md`,`LICENSE`,`LICENSE.md`,`NOTICE`,`NOTICE.md`])n.add(t);let S=typeof t.main==`string`?t.main:null;S&&n.add(S.replace(/^\.\//,``));let C=t.bin;if(typeof C==`string`)n.add(C.replace(/^\.\//,``));else if(C&&typeof C==`object`)for(let t of Object.values(C))typeof t==`string`&&n.add(t.replace(/^\.\//,``));return[...n]}function walkAll(t,n=``){let S=[],C=n?wn(t,n):t,N;try{N=readdirSync(C,{withFileTypes:!0})}catch{return S}for(let C of N){if(MU.has(C.name)||C.name.startsWith(`.tsbuildinfo`))continue;let N=n?`${n}/${C.name}`:C.name;C.isDirectory()?S.push(...walkAll(t,N)):C.isFile()&&S.push(N)}return S}function expandFilesPatterns(t,n){let S=new Set,C=null;for(let N of n){let n=N.replace(/^\.\//,``).replace(/\/$/,``);if(!n)continue;if(!/[*?[\]]/.test(n)){let C=wn(t,n);if(!existsSync(C))continue;let N=statSync(C);if(N.isDirectory())for(let C of walkAll(t,n))S.add(C);else N.isFile()&&S.add(n);continue}C??=walkAll(t);let F=filesGlobToRegExp(n),I=filesGlobToRegExp(`${n}/**`);for(let t of C)(F.test(t)||I.test(t))&&S.add(t)}return[...S]}function filesGlobToRegExp(t){let n=`^`;for(let S=0;S<t.length;S++){let C=t[S];if(C===`*`)t[S+1]===`*`?(n+=`.*`,S++,t[S+1]===`/`&&S++):n+=`[^/]*`;else if(C===`?`)n+=`[^/]`;else if(C===`[`){let C=S+1,N=`[`;for(t[C]===`!`&&(N+=`^`,C++);C<t.length&&t[C]!==`]`;C++)N+=t[C];C<t.length?(n+=`${N}]`,S=C):n+=`\\[`}else".+^${}()|\\]".includes(C)?n+=`\\${C}`:n+=C}return RegExp(`${n}$`)}function loadIgnore(t){let n=wn(t,`.npmignore`),S=wn(t,`.gitignore`),C=[],N=existsSync(n)?n:existsSync(S)?S:null;if(N){let t=readFileSync(N,`utf-8`).split(`
1189
- `);for(let n of t){let t=n.trim();!t||t.startsWith(`#`)||t.startsWith(`!`)||C.push(globToRegex(t))}}return t=>{for(let n of C)if(n.test(t))return!0;return!1}}function globToRegex(t){let n=t.replace(/^\//,``);return n=n.replace(/[.+^${}()|[\]\\]/g,`\\$&`),n=n.replace(/\*\*/g,`__DOUBLESTAR__`).replace(/\*/g,`[^/]*`).replace(/__DOUBLESTAR__/g,`.*`),n=n.replace(/\?/g,`[^/]`),RegExp(`^${n}($|/)`)}function collectWorkspaceProtocolDeps(t){let n=[];for(let S of NU){let C=t[S];if(C)for(let[t,N]of Object.entries(C))typeof N==`string`&&N.startsWith(`workspace:`)&&n.push(`${S}.${t}`)}return n}function findPackWorkspaceRoot(t){let n=findWorkspaceRoot(t);if(n)return n;let S=t;for(let t=0;t<12;t++){let t=wn(S,`package.json`);if(existsSync(t)&&readPackageJson$2(t)?.workspaces!==void 0)return S;let n=xn(S,`..`);if(n===S)break;S=n}return null}function rewriteWorkspaceDeps(t,n){let S=findPackWorkspaceRoot(n);if(!S){let S=collectWorkspaceProtocolDeps(t);if(S.length>0)throw Error(`gjsify pack: ${String(t.name)} declares workspace: ranges (${S.join(`, `)}) but ${n} is not inside a monorepo (no ancestor package.json declares "workspaces"). A workspace: range cannot be published — replace it with a real npm range, or pack from within the monorepo.`);return t}let C=new Map;for(let t of discoverWorkspaces(S))t.name&&t.version&&C.set(t.name,t.version);let N=JSON.parse(JSON.stringify(t));for(let t of NU){let n=N[t];if(n)for(let[F,I]of Object.entries(n)){if(typeof I!=`string`||!I.startsWith(`workspace:`))continue;let H=C.get(F);if(!H)throw Error(`gjsify pack: ${N.name} declares ${I} on ${F} (${t}) but no sibling workspace with that name exists in the monorepo at ${S}`);let W=I.slice(10);W===`*`||W===``?n[F]=H:W===`^`||W===`~`?n[F]=`${W}${H}`:n[F]=W}}return N}function indentOf(t){let n=t.match(/\n([ \t]+)"/);return n?n[1]:` `}var jU,MU,NU,PU=__esmMin(()=>{Rd(),Qc(),Pn(),hL(),QP(),eF(),$P(),AU(),jU={command:`pack [path]`,description:`Produce an npm-compatible .tgz tarball for the workspace at <path> (default: cwd). Rewrites workspace:^/~/* deps to resolved versions.`,builder:t=>t.positional(`path`,{description:`Workspace path (default: cwd).`,type:`string`}).option(`pack-destination`,{description:`Directory to write the tarball into. Default: workspace cwd.`,type:`string`}).option(`json`,{description:"Emit pack metadata as JSON on stdout (mirrors `npm pack --json`).",type:`boolean`,default:!1}).option(`dry-run`,{description:`Compute everything but do not write the .tgz.`,type:`boolean`,default:!1}).option(`ignore-scripts`,{description:"Skip the `prepack` lifecycle script before packing. Mirrors `npm pack --ignore-scripts`. Use when scripts are already run by the outer workflow.",type:`boolean`,default:!1}),handler:async t=>{let n=await packWorkspace(xn(t.path??process.cwd()),{destination:t[`pack-destination`],dryRun:t[`dry-run`]===!0,lifecycleScripts:t[`ignore-scripts`]?[]:[`prepack`],lifecycleStdio:t.json?`inherit-stderr`:`inherit`});t.json?process.stdout.write(`${JSON.stringify([n],null,2)}\n`):process.stdout.write(`${n.filename}\n`)}},MU=new Set([`.git`,`.svn`,`.hg`,`.gitignore`,`.gitattributes`,`.npmrc`,`CVS`,`.DS_Store`,`node_modules`,`.npmignore`,`package-lock.json`,`gjsify-lock.json`,`yarn.lock`,`yarn-error.log`,`.yarn`,`.pnp.cjs`,`.pnp.loader.mjs`,`tsconfig.tsbuildinfo`]),NU=[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]});function decodeJwtPayload(t){let n=t.split(`.`);if(n.length!==3)return null;try{let t=n[1].replace(/-/g,`+`).replace(/_/g,`/`),S=typeof atob==`function`?atob(t):Buffer.from(t,`base64`).toString(`binary`);return JSON.parse(S)}catch{return null}}function hasGithubOidcEnv(){return!!(process.env.ACTIONS_ID_TOKEN_REQUEST_URL&&process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN)}async function fetchGithubOidcToken(t,n){let S=process.env.ACTIONS_ID_TOKEN_REQUEST_URL,C=process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;if(!S||!C)throw new OidcUnavailableError("GitHub Actions OIDC env vars (ACTIONS_ID_TOKEN_REQUEST_{URL,TOKEN}) not set. The calling workflow needs `permissions: id-token: write`.",`no-env`);let N=`${S}${S.includes(`?`)?`&`:`?`}audience=${encodeURIComponent(t)}`;n?.(`gjsify oidc: GET ${N.replace(C,`<bearer>`)}`);let F=await fetch(N,{method:`GET`,headers:{Accept:`application/json`,Authorization:`Bearer ${C}`}});if(!F.ok){let t=await F.text().catch(()=>`<no body>`);throw new OidcUnavailableError(`Failed to fetch GitHub OIDC id_token: ${F.status} ${F.statusText} — ${t.slice(0,200)}`,`fetch-id-token`)}let I=await F.json().catch(()=>({}));if(!I.value)throw new OidcUnavailableError("GitHub OIDC response missing `value` field",`no-id-token`);return I.value}async function exchangeOidcForNpmToken(t){let{packageName:n,registry:S,idToken:C,log:N}=t,F=`${S.endsWith(`/`)?S.slice(0,-1):S}/-/npm/v1/oidc/token/exchange/package/${n.startsWith(`@`)?(()=>{let t=n.indexOf(`/`),S=n.slice(1,t),C=n.slice(t+1);return`@${encodeURIComponent(S)}%2f${encodeURIComponent(C)}`})():encodeURIComponent(n)}`;N?.(`gjsify oidc: POST ${F}`);let I=t.maxRetries??3,H=t.retryBaseMs??1e3;for(let t=0;;t++){let S;try{S=await fetch(F,{method:`POST`,headers:{Authorization:`Bearer ${C}`,"Content-Type":`application/json`,Accept:`application/json`},body:`{}`})}catch(S){if(t<I){let S=Math.min(H*2**t,8e3);N?.(`gjsify oidc: network error for ${n} (attempt ${t+1}/${I+1}), retrying in ${S}ms`),await sleep(S);continue}throw new OidcExchangeError(`npm OIDC token exchange network error for ${n} after ${t+1} attempt(s): ${S instanceof Error?S.message:String(S)}`,0,``,n,decodeJwtPayload(C)??void 0)}let W=await S.text().catch(()=>``);if(!S.ok){if(FU.has(S.status)&&t<I){let C=Math.min(H*2**t,8e3);N?.(`gjsify oidc: transient ${S.status} ${S.statusText} for ${n} (attempt ${t+1}/${I+1}), retrying in ${C}ms`),await sleep(C);continue}throw new OidcExchangeError(`npm OIDC token exchange failed for ${n}: ${S.status} ${S.statusText} — ${W.slice(0,300)}`,S.status,W,n,decodeJwtPayload(C)??void 0)}let q;try{q=JSON.parse(W)}catch{throw new OidcExchangeError(`npm OIDC token exchange returned non-JSON body for ${n}: ${W.slice(0,200)}`,S.status,W,n)}if(!q.token)throw new OidcExchangeError(`npm OIDC token exchange returned no \`token\` field for ${n}`,S.status,W,n);return q.token}}async function getNpmTrustedToken(t){let n=`npm:${new URL(t.registry).hostname}`,S=await fetchGithubOidcToken(n,t.log);return{token:await exchangeOidcForNpmToken({...t,idToken:S}),audience:n}}var FU,sleep,OidcUnavailableError,OidcExchangeError,IU=__esmMin(()=>{FU=new Set([408,425,429,500,502,503,504]),sleep=t=>new Promise(n=>setTimeout(n,t)),OidcUnavailableError=class extends Error{reason;constructor(t,n){super(t),this.reason=n,this.name=`OidcUnavailableError`}},OidcExchangeError=class extends Error{status;body;packageName;claims;constructor(t,n,S,C,N){super(t),this.status=n,this.body=S,this.packageName=C,this.claims=N,this.name=`OidcExchangeError`}}});async function diagnose404(t){let{packageName:n,version:S,registry:C,npmrc:N}=t,F={};try{F=await whoami(C,N)}catch{return{reason:`unknown`,message:formatUnknown(n,S)}}return F.username&&F.username.length>0?{reason:`live-token-404`,username:F.username,message:formatLiveToken404(n,S,F.username)}:{reason:`dead-token`,message:formatDeadToken(n,S)}}function formatDeadToken(t,n){return[`gjsify publish: ${t}@${n} — 404 Not Found`,``,`The npm token in ~/.npmrc appears to be revoked or expired (the /-/whoami probe`,`returned {} instead of {"username": "..."}). The 404 is npm's response to a PUT`,`authenticated with an invalid bearer token.`,``,`To refresh:`,` npm login`,` # or, future: gjsify login (tracked as project_gjsify_login_goal)`,``,`Then verify before publishing:`,` curl -s -H "Authorization: Bearer $(grep registry.npmjs.org ~/.npmrc | sed 's|.*=||')" \\`,` https://registry.npmjs.org/-/whoami`,` # Healthy: {"username":"<you>"}`,` # Dead: {}`].join(`
1188
+ Add the missing path(s) to package.json "files" so type resolution isn't silently broken for consumers.`)}function forceIncluded(t){let n=new Set;n.add(`package.json`);for(let t of[`README`,`README.md`,`LICENSE`,`LICENSE.md`,`NOTICE`,`NOTICE.md`])n.add(t);let S=typeof t.main==`string`?t.main:null;S&&n.add(S.replace(/^\.\//,``));let C=t.bin;if(typeof C==`string`)n.add(C.replace(/^\.\//,``));else if(C&&typeof C==`object`)for(let t of Object.values(C))typeof t==`string`&&n.add(t.replace(/^\.\//,``));return[...n]}function walkAll(t,n=``){let S=[],C=n?wn(t,n):t,N;try{N=readdirSync(C,{withFileTypes:!0})}catch{return S}for(let C of N){if(LU.has(C.name)||C.name.startsWith(`.tsbuildinfo`))continue;let N=n?`${n}/${C.name}`:C.name;C.isDirectory()?S.push(...walkAll(t,N)):C.isFile()&&S.push(N)}return S}function expandFilesPatterns(t,n){let S=new Set,C=null;for(let N of n){let n=N.replace(/^\.\//,``).replace(/\/$/,``);if(!n)continue;if(!/[*?[\]]/.test(n)){let C=wn(t,n);if(!existsSync(C))continue;let N=statSync(C);if(N.isDirectory())for(let C of walkAll(t,n))S.add(C);else N.isFile()&&S.add(n);continue}C??=walkAll(t);let F=filesGlobToRegExp(n),I=filesGlobToRegExp(`${n}/**`);for(let t of C)(F.test(t)||I.test(t))&&S.add(t)}return[...S]}function filesGlobToRegExp(t){let n=`^`;for(let S=0;S<t.length;S++){let C=t[S];if(C===`*`)t[S+1]===`*`?(n+=`.*`,S++,t[S+1]===`/`&&S++):n+=`[^/]*`;else if(C===`?`)n+=`[^/]`;else if(C===`[`){let C=S+1,N=`[`;for(t[C]===`!`&&(N+=`^`,C++);C<t.length&&t[C]!==`]`;C++)N+=t[C];C<t.length?(n+=`${N}]`,S=C):n+=`\\[`}else".+^${}()|\\]".includes(C)?n+=`\\${C}`:n+=C}return RegExp(`${n}$`)}function loadIgnore(t){let n=wn(t,`.npmignore`),S=wn(t,`.gitignore`),C=[],N=existsSync(n)?n:existsSync(S)?S:null;if(N){let t=readFileSync(N,`utf-8`).split(`
1189
+ `);for(let n of t){let t=n.trim();!t||t.startsWith(`#`)||t.startsWith(`!`)||C.push(globToRegex(t))}}return t=>{for(let n of C)if(n.test(t))return!0;return!1}}function globToRegex(t){let n=t.replace(/^\//,``);return n=n.replace(/[.+^${}()|[\]\\]/g,`\\$&`),n=n.replace(/\*\*/g,`__DOUBLESTAR__`).replace(/\*/g,`[^/]*`).replace(/__DOUBLESTAR__/g,`.*`),n=n.replace(/\?/g,`[^/]`),RegExp(`^${n}($|/)`)}function collectWorkspaceProtocolDeps(t){let n=[];for(let S of RU){let C=t[S];if(C)for(let[t,N]of Object.entries(C))typeof N==`string`&&N.startsWith(`workspace:`)&&n.push(`${S}.${t}`)}return n}function findPackWorkspaceRoot(t){let n=findWorkspaceRoot(t);if(n)return n;let S=t;for(let t=0;t<12;t++){let t=wn(S,`package.json`);if(existsSync(t)&&readPackageJson$2(t)?.workspaces!==void 0)return S;let n=xn(S,`..`);if(n===S)break;S=n}return null}function rewriteWorkspaceDeps(t,n){let S=findPackWorkspaceRoot(n);if(!S){let S=collectWorkspaceProtocolDeps(t);if(S.length>0)throw Error(`gjsify pack: ${String(t.name)} declares workspace: ranges (${S.join(`, `)}) but ${n} is not inside a monorepo (no ancestor package.json declares "workspaces"). A workspace: range cannot be published — replace it with a real npm range, or pack from within the monorepo.`);return t}let C=new Map;for(let t of discoverWorkspaces(S))t.name&&t.version&&C.set(t.name,t.version);let N=JSON.parse(JSON.stringify(t));for(let t of RU){let n=N[t];if(n)for(let[F,I]of Object.entries(n)){if(typeof I!=`string`||!I.startsWith(`workspace:`))continue;let H=C.get(F);if(!H)throw Error(`gjsify pack: ${N.name} declares ${I} on ${F} (${t}) but no sibling workspace with that name exists in the monorepo at ${S}`);let W=I.slice(10);W===`*`||W===``?n[F]=H:W===`^`||W===`~`?n[F]=`${W}${H}`:n[F]=W}}return N}function indentOf(t){let n=t.match(/\n([ \t]+)"/);return n?n[1]:` `}var IU,LU,RU,zU=__esmMin(()=>{Rd(),Qc(),Pn(),bL(),QP(),eF(),$P(),FU(),IU={command:`pack [path]`,description:`Produce an npm-compatible .tgz tarball for the workspace at <path> (default: cwd). Rewrites workspace:^/~/* deps to resolved versions.`,builder:t=>t.positional(`path`,{description:`Workspace path (default: cwd).`,type:`string`}).option(`pack-destination`,{description:`Directory to write the tarball into. Default: workspace cwd.`,type:`string`}).option(`json`,{description:"Emit pack metadata as JSON on stdout (mirrors `npm pack --json`).",type:`boolean`,default:!1}).option(`dry-run`,{description:`Compute everything but do not write the .tgz.`,type:`boolean`,default:!1}).option(`ignore-scripts`,{description:"Skip the `prepack` lifecycle script before packing. Mirrors `npm pack --ignore-scripts`. Use when scripts are already run by the outer workflow.",type:`boolean`,default:!1}),handler:async t=>{let n=await packWorkspace(xn(t.path??process.cwd()),{destination:t[`pack-destination`],dryRun:t[`dry-run`]===!0,lifecycleScripts:t[`ignore-scripts`]?[]:[`prepack`],lifecycleStdio:t.json?`inherit-stderr`:`inherit`});t.json?process.stdout.write(`${JSON.stringify([n],null,2)}\n`):process.stdout.write(`${n.filename}\n`)}},LU=new Set([`.git`,`.svn`,`.hg`,`.gitignore`,`.gitattributes`,`.npmrc`,`CVS`,`.DS_Store`,`node_modules`,`.npmignore`,`package-lock.json`,`gjsify-lock.json`,`yarn.lock`,`yarn-error.log`,`.yarn`,`.pnp.cjs`,`.pnp.loader.mjs`,`tsconfig.tsbuildinfo`]),RU=[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]});function parseRetryAfter(t,n=Date.now()){if(!t)return;let S=t.trim();if(/^\d+(?:\.\d+)?$/.test(S))return Math.round(Number(S)*1e3);let C=Date.parse(S);return Number.isNaN(C)?void 0:Math.max(0,C-n)}function retryDelayMs(t,n,S){let C=parseRetryAfter(S);return Math.min(C??n*2**t,VU)}async function fetchWithTransientRetry(t,n={}){let S=n.retries??5,C=n.baseMs??2e3,N=n.sleep??(t=>new Promise(n=>setTimeout(n,t)));for(let F=0;;F++){let I,H;try{I=await t()}catch(t){H=t}if(I&&!isTransientStatus(I.status))return{response:I,retried:F};if(F>=S){if(I)return{response:I,retried:F};throw H}let W=retryDelayMs(F,C,I?.headers.get(`retry-after`)),q=I?`${I.status} ${I.statusText}`:`network error: ${H instanceof Error?H.message:String(H)}`;n.log?.(`transient ${q} (attempt ${F+1}/${S+1}), retrying in ${W}ms`),await N(W)}}var BU,isTransientStatus,VU,HU=__esmMin(()=>{BU=new Set([408,425,429,500,502,503,504]),isTransientStatus=t=>BU.has(t),VU=3e4});function decodeJwtPayload(t){let n=t.split(`.`);if(n.length!==3)return null;try{let t=n[1].replace(/-/g,`+`).replace(/_/g,`/`),S=typeof atob==`function`?atob(t):Buffer.from(t,`base64`).toString(`binary`);return JSON.parse(S)}catch{return null}}function hasGithubOidcEnv(){return!!(process.env.ACTIONS_ID_TOKEN_REQUEST_URL&&process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN)}async function fetchGithubOidcToken(t,n){let S=process.env.ACTIONS_ID_TOKEN_REQUEST_URL,C=process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;if(!S||!C)throw new OidcUnavailableError("GitHub Actions OIDC env vars (ACTIONS_ID_TOKEN_REQUEST_{URL,TOKEN}) not set. The calling workflow needs `permissions: id-token: write`.",`no-env`);let N=`${S}${S.includes(`?`)?`&`:`?`}audience=${encodeURIComponent(t)}`;n?.(`gjsify oidc: GET ${N.replace(C,`<bearer>`)}`);let F=await fetch(N,{method:`GET`,headers:{Accept:`application/json`,Authorization:`Bearer ${C}`}});if(!F.ok){let t=await F.text().catch(()=>`<no body>`);throw new OidcUnavailableError(`Failed to fetch GitHub OIDC id_token: ${F.status} ${F.statusText} — ${t.slice(0,200)}`,`fetch-id-token`)}let I=await F.json().catch(()=>({}));if(!I.value)throw new OidcUnavailableError("GitHub OIDC response missing `value` field",`no-id-token`);return I.value}async function exchangeOidcForNpmToken(t){let{packageName:n,registry:S,idToken:C,log:N}=t,F=`${S.endsWith(`/`)?S.slice(0,-1):S}/-/npm/v1/oidc/token/exchange/package/${n.startsWith(`@`)?(()=>{let t=n.indexOf(`/`),S=n.slice(1,t),C=n.slice(t+1);return`@${encodeURIComponent(S)}%2f${encodeURIComponent(C)}`})():encodeURIComponent(n)}`;N?.(`gjsify oidc: POST ${F}`);let I=t.maxRetries??3,H=t.retryBaseMs??1e3;for(let t=0;;t++){let S;try{S=await fetch(F,{method:`POST`,headers:{Authorization:`Bearer ${C}`,"Content-Type":`application/json`,Accept:`application/json`},body:`{}`})}catch(S){if(t<I){let S=retryDelayMs(t,H);N?.(`gjsify oidc: network error for ${n} (attempt ${t+1}/${I+1}), retrying in ${S}ms`),await sleep(S);continue}throw new OidcExchangeError(`npm OIDC token exchange network error for ${n} after ${t+1} attempt(s): ${S instanceof Error?S.message:String(S)}`,0,``,n,decodeJwtPayload(C)??void 0)}let W=await S.text().catch(()=>``);if(!S.ok){if(isTransientStatus(S.status)&&t<I){let C=retryDelayMs(t,H,S.headers.get(`retry-after`));N?.(`gjsify oidc: transient ${S.status} ${S.statusText} for ${n} (attempt ${t+1}/${I+1}), retrying in ${C}ms`),await sleep(C);continue}throw new OidcExchangeError(`npm OIDC token exchange failed for ${n}: ${S.status} ${S.statusText} — ${W.slice(0,300)}`,S.status,W,n,decodeJwtPayload(C)??void 0)}let q;try{q=JSON.parse(W)}catch{throw new OidcExchangeError(`npm OIDC token exchange returned non-JSON body for ${n}: ${W.slice(0,200)}`,S.status,W,n)}if(!q.token)throw new OidcExchangeError(`npm OIDC token exchange returned no \`token\` field for ${n}`,S.status,W,n);return q.token}}async function getNpmTrustedToken(t){let n=`npm:${new URL(t.registry).hostname}`,S=await fetchGithubOidcToken(n,t.log);return{token:await exchangeOidcForNpmToken({...t,idToken:S}),audience:n}}var sleep,OidcUnavailableError,OidcExchangeError,UU=__esmMin(()=>{HU(),sleep=t=>new Promise(n=>setTimeout(n,t)),OidcUnavailableError=class extends Error{reason;constructor(t,n){super(t),this.reason=n,this.name=`OidcUnavailableError`}},OidcExchangeError=class extends Error{status;body;packageName;claims;constructor(t,n,S,C,N){super(t),this.status=n,this.body=S,this.packageName=C,this.claims=N,this.name=`OidcExchangeError`}}});async function diagnose404(t){let{packageName:n,version:S,registry:C,npmrc:N}=t,F={};try{F=await whoami(C,N)}catch{return{reason:`unknown`,message:formatUnknown(n,S)}}return F.username&&F.username.length>0?{reason:`live-token-404`,username:F.username,message:formatLiveToken404(n,S,F.username)}:{reason:`dead-token`,message:formatDeadToken(n,S)}}function formatDeadToken(t,n){return[`gjsify publish: ${t}@${n} — 404 Not Found`,``,`The npm token in ~/.npmrc appears to be revoked or expired (the /-/whoami probe`,`returned {} instead of {"username": "..."}). The 404 is npm's response to a PUT`,`authenticated with an invalid bearer token.`,``,`To refresh:`,` npm login`,` # or, future: gjsify login (tracked as project_gjsify_login_goal)`,``,`Then verify before publishing:`,` curl -s -H "Authorization: Bearer $(grep registry.npmjs.org ~/.npmrc | sed 's|.*=||')" \\`,` https://registry.npmjs.org/-/whoami`,` # Healthy: {"username":"<you>"}`,` # Dead: {}`].join(`
1190
1190
  `)}function formatLiveToken404(t,n,S){return[`gjsify publish: ${t}@${n} — 404 Not Found`,``,`Authenticated as: ${S}`,``,`Your token authenticates, so this is NOT a dead-token problem. The package`,`${t} is not (yet) on npmjs.com. Two cases:`,``,` 1. First publish of a brand-new scoped package — do the one-time bootstrap`,` (see AGENTS.md > "New @gjsify/* package: first-publish + Trusted`,` Publisher bootstrap"). The npm registry can also 404 *transiently*`,` while provisioning a brand-new package: simply re-run, or do the very`," first publish with `npm publish` (then configure the Trusted Publisher)."," 2. You lack publish access to the scope — verify with `npm access ls-packages`."].join(`
1191
- `)}function formatUnknown(t,n){return`gjsify publish: ${t}@${n} — 404 Not Found`}function is404DiagnosticCandidate(t){let n=t.trim();return!!(n.length===0||/^not found$/i.test(n)||/"error"\s*:\s*"Not Found"/i.test(n))}var LU=__esmMin(()=>{eh()});function backoffFor(t){return RU[Math.min(Math.max(t,0),RU.length-1)]??3e4}function probeTimeoutFor(t,n){return Math.min(t,Math.max(n,zU))}function cacheBustedUrl(t,n){return`${t}${t.includes(`?`)?`&`:`?`}__gjsify_readback=${encodeURIComponent(n)}`}async function verifyPublishedVersion(t){let{registry:n,name:S,version:C,budgetMs:N}=t,F=t.fetchImpl??((...t)=>globalThis.fetch(...t)),I=t.sleep??(t=>new Promise(n=>setTimeout(n,t))),H=t.now??(()=>Date.now()),W=t.probeTimeoutMs??3e4,q=`${n.endsWith(`/`)?n.slice(0,-1):n}/${escapePackageName(S)}`,Y=H(),X=0,Z={state:`error`,detail:`no probe was sent`};for(let n=0;X++,Z=await probeOnce({url:q,version:C,doFetch:F,probeTimeoutMs:probeTimeoutFor(W,N-(H()-Y)),authorization:t.authorization,nonce:`${Y}-${X}`}),t.log?.(`gjsify publish: read-back probe ${X} of ${S}@${C} → ${Z.state}`+(Z.state===`present`?``:` (${Z.detail})`)),Z.state!==`present`;n++){let t=N-(H()-Y);if(t<=0)break;await I(Math.min(backoffFor(n),t))}let te={attempts:X,elapsedMs:H()-Y,url:q,last:Z};if(Z.state===`present`)return{...te,confirmed:!0,verdict:`confirmed`,verdictDetail:`${q} serves ${C} with a tarball`};if(Z.state===`error`)return{...te,confirmed:!1,verdict:`unknown`,verdictDetail:`the read-back could not reach a verdict — ${Z.detail}`};let ne=await probeRegistryRecord({url:q,version:C,doFetch:F,probeTimeoutMs:W,authorization:t.authorization,nonce:`${Y}-record`});return t.log?.(`gjsify publish: read-back record probe of ${S}@${C} → ${ne.state} (${ne.detail})`),ne.state===`recorded`?{...te,confirmed:!1,verdict:`recorded-not-served`,verdictDetail:ne.detail,recordedAt:ne.recordedAt}:ne.state===`no-record`?{...te,confirmed:!1,verdict:`not-published`,verdictDetail:ne.detail}:{...te,confirmed:!1,verdict:`unknown`,verdictDetail:ne.detail}}async function probeRegistryRecord(t){let{url:n,version:S,doFetch:C,probeTimeoutMs:N}=t,F=new AbortController,I=setTimeout(()=>F.abort(),N),H;try{H=await C(cacheBustedUrl(n,t.nonce),{headers:{"cache-control":`no-cache`,...t.authorization?{authorization:t.authorization}:{}},signal:F.signal})}catch(t){return{state:`unknown`,detail:`the registry serves no ${S} and its own record was unreadable (${t instanceof Error?t.message:String(t)})`}}finally{clearTimeout(I)}if(H.status===404)return{state:`no-record`,detail:`the registry has no packument for this name at all (404)`};if(!H.ok)return{state:`unknown`,detail:`the registry serves no ${S} and its own record answered ${H.status} ${H.statusText}`};let W;try{W=await H.json()}catch(t){return{state:`unknown`,detail:`the registry serves no ${S} and its own record is not JSON (${t instanceof Error?t.message:String(t)})`}}let q=W?.time,Y=q&&typeof q==`object`?q[S]:void 0;return typeof Y==`string`&&Y.length>0?{state:`recorded`,recordedAt:Y,detail:`the registry RECORDS ${S} at ${Y} and its install document does not serve it`}:{state:`no-record`,detail:`the registry has no record of ${S} — neither in its install document nor in its own \`time\` map`}}async function sendPackumentRequest(t){let{url:n,doFetch:S,probeTimeoutMs:C}=t,N={accept:`application/vnd.npm.install-v1+json`,"cache-control":`no-cache`,...t.authorization?{authorization:t.authorization}:{}},send=async t=>{let n=new AbortController,F=setTimeout(()=>n.abort(),C);try{return await S(t,{headers:N,signal:n.signal})}finally{clearTimeout(F)}},F;try{F=await send(cacheBustedUrl(n,t.nonce)),!F.ok&&F.status!==404&&F.status>=400&&F.status<500&&(F=await send(n))}catch(t){return{error:`request failed (${t instanceof Error?t.message:String(t)})`}}return F}async function probeOnce(t){let{version:n}=t,S=await sendPackumentRequest(t);if(`error`in S)return{state:`error`,detail:S.error};let C=S;if(C.status===404)return{state:`absent`,status:404,detail:`404 — the registry serves no packument for this name`};if(!C.ok)return{state:`error`,status:C.status,detail:`${C.status} ${C.statusText}`};let N;try{N=await C.json()}catch(t){let n=t instanceof Error?t.message:String(t);return{state:`error`,status:C.status,detail:`packument is not JSON (${n})`}}let F=N?.versions,I=F&&typeof F==`object`?Object.keys(F):[],H=F&&typeof F==`object`&&Object.hasOwn(F,n)?F[n]:void 0;if(!H){let t=I.length>0?I[I.length-1]:`(none)`;return{state:`absent`,status:C.status,detail:`packument carries ${I.length} version(s), newest ${t} — ${n} is not among them`}}let W=H.dist?.tarball;return typeof W!=`string`||W.length===0?{state:`absent`,status:C.status,detail:`packument has ${n} but its \`dist.tarball\` is missing`}:{state:`present`,status:C.status,tarball:W}}function formatUnconfirmedPublish(t){let{name:n,version:S,putUrl:C,putStatus:N,putStatusText:F,payloadBytes:I,readback:H}=t,W=t.claim??`accepted`,q=(H.elapsedMs/1e3).toFixed(1),Y=H.last.state===`present`?`served`:H.last.detail,X=W===`already-published`?`npm says ${S} is ALREADY PUBLISHED`:`npm ACCEPTED the upload`,Z=H.verdict===`unknown`?H.last.state===`absent`?`${X}; its install document does not serve ${S} and the registry's own record could NOT be read.`:`${X} and the read-back could NOT establish whether the registry serves it.`:H.verdict===`recorded-not-served`?`${X}; the registry RECORDS ${S} and its install document does not serve it.`:`${X} and the registry has no record of ${S}.`,te=H.verdict===`unknown`?[` This is NOT a report that the publish failed, and it is not one that it worked. The read-back`,` reached no answer it could act on, so the version may or may not be installable — confirm it`," before releasing anything that depends on it (`npm view <name>@<version> dist.tarball`)."]:H.verdict===`recorded-not-served`?[` Do NOT re-publish: the registry holds the write, so a re-run is answered 409 and changes`,` nothing. The document npm installs from is behind the registry's own record — measured on`,` the ts-for-gir v5.1.0 release, @ts-for-gir/reporter was recorded at 21:43:00.983Z and a`,` cache-busted read of its install document still did not carry 5.1.0 ~40 min later. Wait and`,` re-read; if it persists, check https://status.npmjs.org/.`]:W===`already-published`?[` A 409 is npm refusing to overwrite a version it holds, which is not the same as serving it:`,` in the v0.46.0 recovery @gjsify/node-runtime-darwin-arm64 was answered 409 at 09:48:49 and`,` the registry recorded 0.46.0 at 09:49:07, 18s later. Re-running answers the same 409, so it`," cannot fix this — wait and re-read (`npm view <name>@<version>`), or check",` https://status.npmjs.org/.`]:[` A 2xx from npm is an ACCEPTED write, not a durable one. In the v0.46.0 release 19 of 199`,` packages were recorded by the registry 56-252s after their 2xx, and ONE was never recorded`,` at all while its job stayed green — that is the failure this check exists to name.`," Re-run this publish (`--tolerate-republish` no-ops if it landed meanwhile). If it keeps",` failing, the write was rejected downstream of the 2xx: check https://status.npmjs.org/.`];return[`gjsify publish: ${n}@${S} — ${Z}`,` PUT ${C} (${I} bytes) → ${N} ${F}`,` read-back GET ${H.url} (accept: application/vnd.npm.install-v1+json, per-probe cache buster)`,` answered ${H.last.state}: ${Y}`,` after ${H.attempts} probe(s) over ${q}s`,` verdict ${H.verdict} — ${H.verdictDetail}`,...te].join(`
1192
- `)}async function probePackageName(t){let n=t.fetchImpl??((...t)=>globalThis.fetch(...t)),S=await sendPackumentRequest({url:`${t.registry.endsWith(`/`)?t.registry.slice(0,-1):t.registry}/${escapePackageName(t.name)}`,doFetch:n,probeTimeoutMs:t.probeTimeoutMs??3e4,authorization:t.authorization,nonce:`name-${Date.now()}-${++VU}`});if(`error`in S)return{state:`unknown`,detail:S.error};if(S.status===404)return{state:`absent`,status:404,detail:`404 — the registry serves no packument for this name`};if(!S.ok)return{state:`unknown`,status:S.status,detail:`${S.status} ${S.statusText}`};let C;try{C=await S.json()}catch(t){let n=t instanceof Error?t.message:String(t);return{state:`unknown`,status:S.status,detail:`packument is not JSON (${n})`}}let N=C?.versions,F=N&&typeof N==`object`?Object.keys(N).length:0;return F===0?{state:`unknown`,status:S.status,detail:`a 200 carrying no versions establishes nothing`}:{state:`present`,status:S.status,versions:F}}var RU,zU,BU,VU,HU=__esmMin(()=>{nh(),RU=[2e3,4e3,8e3,15e3,3e4],zU=2e3,BU=6e5,VU=0});function collectWorkspacePins(t,n){let S=[];for(let C of UU){let N=depsOf(t,C),F=depsOf(n,C);for(let[t,n]of Object.entries(N))typeof n!=`string`||!n.startsWith(`workspace:`)||S.push({name:t,spec:F[t]??n,block:C})}return S}var UU,WU,depsOf,GU=__esmMin(()=>{UU=[`dependencies`,`optionalDependencies`,`peerDependencies`],WU=`dependencies`,depsOf=(t,n)=>{let S=t[n];return S&&typeof S==`object`?S:{}}});function statusTokenFromEnv(t){for(let n of[t.NPM_STATUS_TOKEN,t.NODE_AUTH_TOKEN]){let t=n?.trim();if(t&&!/^X+(-X+)+$/.test(t))return t}}async function fetchVersionStatus(t){if(!t.token)return{state:`unavailable`,reason:`no-credential`,detail:`the status endpoint needs an npm access token (set NPM_STATUS_TOKEN); OIDC publish tokens are not accepted`};let n=t.fetchImpl??((...t)=>globalThis.fetch(...t)),S=`${t.registry.endsWith(`/`)?t.registry.slice(0,-1):t.registry}/-/package/${escapePackageName(t.name)}/version/${encodeURIComponent(t.version)}/status`,C;try{C=await n(S,{headers:{accept:`application/json`,authorization:`Bearer ${t.token}`},signal:AbortSignal.timeout(t.probeTimeoutMs??3e4)})}catch(t){return{state:`unavailable`,reason:`error`,detail:t instanceof Error?t.message:String(t)}}if(C.status===401)return{state:`unavailable`,reason:`rejected`,detail:`401 — the token is missing, invalid or expired`};if(C.status===403)return{state:`unavailable`,reason:`not-enabled`,detail:`403 — package version status is not enabled for this package`};if(C.status===404)return{state:`unavailable`,reason:`not-found`,detail:`404 — no such version, or the token cannot see this package`};if(!C.ok)return{state:`unavailable`,reason:`error`,detail:`${C.status} ${C.statusText}`};let N;try{N=await C.json()}catch(t){return{state:`unavailable`,reason:`error`,detail:`status body is not JSON (${t instanceof Error?t.message:String(t)})`}}let F=N?.status;return typeof F!=`string`||!KU.includes(F)?{state:`unavailable`,reason:`error`,detail:`unrecognised status ${JSON.stringify(F)}`}:{state:`known`,status:F}}function isTerminalClass(t){return t!==`validating`&&t!==`published-lagging`&&t!==`unchecked`}function whyUnchecked(t){return t.reason===`no-credential`?`status endpoint not asked: no NPM_STATUS_TOKEN`:t.detail}function classifyUnserved(t,n){if(n.state===`known`)switch(n.status){case`validating`:return{cls:`validating`,detail:`npm accepted the upload and its automated review has not finished`,terminal:!1};case`staged`:return{cls:`staged`,detail:`awaiting maintainer approval on npm`,terminal:!0};case`blocked`:return{cls:`blocked`,detail:`failed npm automated validation`,terminal:!0};case`deleted`:return{cls:`deleted`,detail:`deleted on npm`,terminal:!0};case`published`:return{cls:`published-lagging`,detail:`npm reports it published; the install document does not serve it yet`,terminal:!1}}return n.reason===`not-found`?{cls:`missing`,detail:`the registry has no such version (${n.detail}); the PUT did not land`,terminal:!0}:{cls:`unchecked`,detail:`not served (read-back: ${t}); ${whyUnchecked(n)}`,terminal:!1}}function describeClass(t){switch(t){case`validating`:return`validating (npm automated review pending)`;case`staged`:return`staged (needs maintainer approval)`;case`blocked`:return`blocked (failed automated validation)`;case`deleted`:return`deleted`;case`published-lagging`:return`published, not yet served`;case`missing`:return`missing (never recorded)`;case`unchecked`:return`not served (status not checked)`}}var KU,qU=__esmMin(()=>{nh(),KU=[`published`,`validating`,`staged`,`blocked`,`deleted`]});function appendLedger(t,n){t&&appendFileSync(t,`${JSON.stringify(n)}\n`)}function readLedger(t){if(!t||!existsSync(t))return[];let n=[];for(let S of readFileSync(t,`utf-8`).split(`
1193
- `))if(S.trim())try{let t=JSON.parse(S);(t.ev===`unserved`||t.ev===`held`||t.ev===`served`)&&n.push(t)}catch{}return n}function pinVersion(t){return/^[\^~]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/.exec(t.trim())?.[1]}async function findUnavailablePins(t){let n=[],S=new Map;for(let C of t.pins){let N=pinVersion(C.spec);if(!N){t.log?.(`gjsify publish: ${C.name}@${C.spec} names no single version — not checked for hold`);continue}let F=`${C.name}@${N}`,I=C.block===`dependencies`?F:`${F}#nowait`;if(!S.has(I)){let n=C.block===`dependencies`?t:{...t,waitBudgetMs:0};S.set(I,await judgePin(n,C.name,N))}let H=S.get(I);H&&n.push({...H,block:C.block})}return n}async function judgePin(t,n,S){let C={name:n,version:S,block:`dependencies`},N=[...t.ledger].reverse().find(t=>t.name===n&&t.version===S);if(N?.ev===`served`)return null;if(N?.ev===`unserved`&&isTerminalClass(N.cls))return{...C,cls:N.cls,detail:N.detail};if(N?.ev===`held`)return{...C,cls:`held`,detail:`was itself held — ${summariseReasons(N.reasons)}`};let F={registry:t.registry,name:n,version:S,authorization:t.authorization,fetchImpl:t.fetchImpl,sleep:t.sleep,now:t.now,log:t.log},I=await verifyPublishedVersion({...F,budgetMs:YU});if(I.confirmed)return confirmedServed(t,N,n,S);let ask=()=>fetchVersionStatus({registry:t.registry,name:n,version:S,token:t.statusToken,fetchImpl:t.fetchImpl}),H=classifyUnserved(I.verdict,await ask());if(!H.terminal&&t.waitBudgetMs>0){if(I=await verifyPublishedVersion({...F,budgetMs:t.waitBudgetMs}),I.confirmed)return confirmedServed(t,N,n,S);H=classifyUnserved(I.verdict,await ask())}return{...C,cls:H.cls,detail:H.detail}}function confirmedServed(t,n,S,C){return n?.ev===`unserved`&&appendLedger(t.ledgerPath,{ev:`served`,name:S,version:C}),null}function summariseReasons(t){return t.map(t=>`${t.name}@${t.version} is ${t.cls===`held`?`held`:describeClass(t.cls)}`).join(`; `)}async function recordUnserved(t){let n=await fetchVersionStatus({registry:t.registry,name:t.name,version:t.version,token:t.statusToken,fetchImpl:t.fetchImpl}),S=classifyUnserved(t.verdict,n);return appendLedger(t.ledgerPath,{ev:`unserved`,name:t.name,version:t.version,cls:S.cls,detail:S.detail}),S}function renderLedgerSummary(t,n){let S=new Set(t.filter(t=>t.ev===`served`).map(t=>`${t.name}@${t.version}`)),C=t.filter(t=>t.ev===`unserved`&&!S.has(`${t.name}@${t.version}`)),N=t.filter(t=>t.ev===`held`);if(C.length===0&&N.length===0)return;let F=[`### npm versions that were accepted but are not installable`,``];if(C.length>0){F.push(`| Package | Version | State | Detail |`,`| --- | --- | --- | --- |`);for(let t of C)F.push(`| \`${t.name}\` | ${t.version} | ${describeClass(t.cls)} | ${t.detail} |`);F.push(``)}if(N.length>0){F.push(`### Held — NOT published in this run`,``,`Each package below depends on a version npm does not serve, so publishing it would have shipped a package that cannot be installed.`,``,`| Package | Version | Because |`,`| --- | --- | --- |`);for(let t of N)F.push(`| \`${t.name}\` | ${t.version} | ${summariseReasons(t.reasons)} |`);F.push(``,"Once the dependencies above are served by npm (a `validating` version appears on its own, or is approved/released by a maintainer), publish the held set with:",``,"```sh",`gh workflow run release.yml --ref ${n} -f skip_publish=false -f only='${[...new Set(N.map(t=>t.name))].join(` `)}'`,"```"),t.some(t=>t.ev===`unserved`&&(t.cls===`blocked`||t.cls===`deleted`))&&F.push(``,"A `blocked` or `deleted` version is a spent number: re-running the release cannot serve it, the package needs a version bump.")}return F.join(`
1194
- `)}var JU,YU,holdsPublish,XU=__esmMin(()=>{Rd(),GU(),HU(),qU(),JU=3e5,YU=1,holdsPublish=t=>t.block===WU});function beginPrompt(){ZU++}function endPrompt(t=defaultWrite){if(ZU=Math.max(0,ZU-1),ZU>0||QU.length===0)return;let n=QU.splice(0,QU.length);for(let S of n)t(S)}function writeAroundPrompt(t,n=defaultWrite){if(ZU>0){QU.push(t);return}n(t)}function defaultWrite(t){process.stdout.write(t)}var ZU,QU,$U=__esmMin(()=>{ZU=0,QU=[]});function isTtyStdin(){let t=process.stdin;return!!t.isTTY&&typeof t.setRawMode==`function`}function applyKey(t,n,S){return n===`\r`||n===`
1191
+ `)}function formatUnknown(t,n){return`gjsify publish: ${t}@${n} — 404 Not Found`}function is404DiagnosticCandidate(t){let n=t.trim();return!!(n.length===0||/^not found$/i.test(n)||/"error"\s*:\s*"Not Found"/i.test(n))}var WU=__esmMin(()=>{eh()});function backoffFor(t){return GU[Math.min(Math.max(t,0),GU.length-1)]??3e4}function probeTimeoutFor(t,n){return Math.min(t,Math.max(n,KU))}function cacheBustedUrl(t,n){return`${t}${t.includes(`?`)?`&`:`?`}__gjsify_readback=${encodeURIComponent(n)}`}async function verifyPublishedVersion(t){let{registry:n,name:S,version:C,budgetMs:N}=t,F=t.fetchImpl??((...t)=>globalThis.fetch(...t)),I=t.sleep??(t=>new Promise(n=>setTimeout(n,t))),H=t.now??(()=>Date.now()),W=t.probeTimeoutMs??3e4,q=`${n.endsWith(`/`)?n.slice(0,-1):n}/${escapePackageName(S)}`,Y=H(),X=0,Z={state:`error`,detail:`no probe was sent`};for(let n=0;X++,Z=await probeOnce({url:q,version:C,doFetch:F,probeTimeoutMs:probeTimeoutFor(W,N-(H()-Y)),authorization:t.authorization,nonce:`${Y}-${X}`}),t.log?.(`gjsify publish: read-back probe ${X} of ${S}@${C} → ${Z.state}`+(Z.state===`present`?``:` (${Z.detail})`)),Z.state!==`present`;n++){let t=N-(H()-Y);if(t<=0)break;await I(Math.min(backoffFor(n),t))}let te={attempts:X,elapsedMs:H()-Y,url:q,last:Z};if(Z.state===`present`)return{...te,confirmed:!0,verdict:`confirmed`,verdictDetail:`${q} serves ${C} with a tarball`};if(Z.state===`error`)return{...te,confirmed:!1,verdict:`unknown`,verdictDetail:`the read-back could not reach a verdict — ${Z.detail}`};let ne=await probeRegistryRecord({url:q,version:C,doFetch:F,probeTimeoutMs:W,authorization:t.authorization,nonce:`${Y}-record`});return t.log?.(`gjsify publish: read-back record probe of ${S}@${C} → ${ne.state} (${ne.detail})`),ne.state===`recorded`?{...te,confirmed:!1,verdict:`recorded-not-served`,verdictDetail:ne.detail,recordedAt:ne.recordedAt}:ne.state===`no-record`?{...te,confirmed:!1,verdict:`not-published`,verdictDetail:ne.detail}:{...te,confirmed:!1,verdict:`unknown`,verdictDetail:ne.detail}}async function probeRegistryRecord(t){let{url:n,version:S,doFetch:C,probeTimeoutMs:N}=t,F=new AbortController,I=setTimeout(()=>F.abort(),N),H;try{H=await C(cacheBustedUrl(n,t.nonce),{headers:{"cache-control":`no-cache`,...t.authorization?{authorization:t.authorization}:{}},signal:F.signal})}catch(t){return{state:`unknown`,detail:`the registry serves no ${S} and its own record was unreadable (${t instanceof Error?t.message:String(t)})`}}finally{clearTimeout(I)}if(H.status===404)return{state:`no-record`,detail:`the registry has no packument for this name at all (404)`};if(!H.ok)return{state:`unknown`,detail:`the registry serves no ${S} and its own record answered ${H.status} ${H.statusText}`};let W;try{W=await H.json()}catch(t){return{state:`unknown`,detail:`the registry serves no ${S} and its own record is not JSON (${t instanceof Error?t.message:String(t)})`}}let q=W?.time,Y=q&&typeof q==`object`?q[S]:void 0;return typeof Y==`string`&&Y.length>0?{state:`recorded`,recordedAt:Y,detail:`the registry RECORDS ${S} at ${Y} and its install document does not serve it`}:{state:`no-record`,detail:`the registry has no record of ${S} — neither in its install document nor in its own \`time\` map`}}async function sendPackumentRequest(t){let{url:n,doFetch:S,probeTimeoutMs:C}=t,N={accept:`application/vnd.npm.install-v1+json`,"cache-control":`no-cache`,...t.authorization?{authorization:t.authorization}:{}},send=async t=>{let n=new AbortController,F=setTimeout(()=>n.abort(),C);try{return await S(t,{headers:N,signal:n.signal})}finally{clearTimeout(F)}},F;try{F=await send(cacheBustedUrl(n,t.nonce)),!F.ok&&F.status!==404&&F.status>=400&&F.status<500&&(F=await send(n))}catch(t){return{error:`request failed (${t instanceof Error?t.message:String(t)})`}}return F}async function probeOnce(t){let{version:n}=t,S=await sendPackumentRequest(t);if(`error`in S)return{state:`error`,detail:S.error};let C=S;if(C.status===404)return{state:`absent`,status:404,detail:`404 — the registry serves no packument for this name`};if(!C.ok)return{state:`error`,status:C.status,detail:`${C.status} ${C.statusText}`};let N;try{N=await C.json()}catch(t){let n=t instanceof Error?t.message:String(t);return{state:`error`,status:C.status,detail:`packument is not JSON (${n})`}}let F=N?.versions,I=F&&typeof F==`object`?Object.keys(F):[],H=F&&typeof F==`object`&&Object.hasOwn(F,n)?F[n]:void 0;if(!H){let t=I.length>0?I[I.length-1]:`(none)`;return{state:`absent`,status:C.status,detail:`packument carries ${I.length} version(s), newest ${t} — ${n} is not among them`}}let W=H.dist?.tarball;return typeof W!=`string`||W.length===0?{state:`absent`,status:C.status,detail:`packument has ${n} but its \`dist.tarball\` is missing`}:{state:`present`,status:C.status,tarball:W}}function formatUnconfirmedPublish(t){let{name:n,version:S,putUrl:C,putStatus:N,putStatusText:F,payloadBytes:I,readback:H}=t,W=t.claim??`accepted`,q=(H.elapsedMs/1e3).toFixed(1),Y=H.last.state===`present`?`served`:H.last.detail,X=W===`already-published`?`npm says ${S} is ALREADY PUBLISHED`:`npm ACCEPTED the upload`,Z=H.verdict===`unknown`?H.last.state===`absent`?`${X}; its install document does not serve ${S} and the registry's own record could NOT be read.`:`${X} and the read-back could NOT establish whether the registry serves it.`:H.verdict===`recorded-not-served`?`${X}; the registry RECORDS ${S} and its install document does not serve it.`:`${X} and the registry has no record of ${S}.`,te=H.verdict===`unknown`?[` This is NOT a report that the publish failed, and it is not one that it worked. The read-back`,` reached no answer it could act on, so the version may or may not be installable — confirm it`," before releasing anything that depends on it (`npm view <name>@<version> dist.tarball`)."]:H.verdict===`recorded-not-served`?[` Do NOT re-publish: the registry holds the write, so a re-run is answered 409 and changes`,` nothing. The document npm installs from is behind the registry's own record — measured on`,` the ts-for-gir v5.1.0 release, @ts-for-gir/reporter was recorded at 21:43:00.983Z and a`,` cache-busted read of its install document still did not carry 5.1.0 ~40 min later. Wait and`,` re-read; if it persists, check https://status.npmjs.org/.`]:W===`already-published`?[` A 409 is npm refusing to overwrite a version it holds, which is not the same as serving it:`,` in the v0.46.0 recovery @gjsify/node-runtime-darwin-arm64 was answered 409 at 09:48:49 and`,` the registry recorded 0.46.0 at 09:49:07, 18s later. Re-running answers the same 409, so it`," cannot fix this — wait and re-read (`npm view <name>@<version>`), or check",` https://status.npmjs.org/.`]:[` A 2xx from npm is an ACCEPTED write, not a durable one. In the v0.46.0 release 19 of 199`,` packages were recorded by the registry 56-252s after their 2xx, and ONE was never recorded`,` at all while its job stayed green — that is the failure this check exists to name.`," Re-run this publish (`--tolerate-republish` no-ops if it landed meanwhile). If it keeps",` failing, the write was rejected downstream of the 2xx: check https://status.npmjs.org/.`];return[`gjsify publish: ${n}@${S} — ${Z}`,` PUT ${C} (${I} bytes) → ${N} ${F}`,` read-back GET ${H.url} (accept: application/vnd.npm.install-v1+json, per-probe cache buster)`,` answered ${H.last.state}: ${Y}`,` after ${H.attempts} probe(s) over ${q}s`,` verdict ${H.verdict} — ${H.verdictDetail}`,...te].join(`
1192
+ `)}async function probePackageName(t){let n=t.fetchImpl??((...t)=>globalThis.fetch(...t)),S=await sendPackumentRequest({url:`${t.registry.endsWith(`/`)?t.registry.slice(0,-1):t.registry}/${escapePackageName(t.name)}`,doFetch:n,probeTimeoutMs:t.probeTimeoutMs??3e4,authorization:t.authorization,nonce:`name-${Date.now()}-${++JU}`});if(`error`in S)return{state:`unknown`,detail:S.error};if(S.status===404)return{state:`absent`,status:404,detail:`404 — the registry serves no packument for this name`};if(!S.ok)return{state:`unknown`,status:S.status,detail:`${S.status} ${S.statusText}`};let C;try{C=await S.json()}catch(t){let n=t instanceof Error?t.message:String(t);return{state:`unknown`,status:S.status,detail:`packument is not JSON (${n})`}}let N=C?.versions,F=N&&typeof N==`object`?Object.keys(N).length:0;return F===0?{state:`unknown`,status:S.status,detail:`a 200 carrying no versions establishes nothing`}:{state:`present`,status:S.status,versions:F}}var GU,KU,qU,JU,YU=__esmMin(()=>{nh(),GU=[2e3,4e3,8e3,15e3,3e4],KU=2e3,qU=6e5,JU=0});function collectWorkspacePins(t,n){let S=[];for(let C of XU){let N=depsOf(t,C),F=depsOf(n,C);for(let[t,n]of Object.entries(N))typeof n!=`string`||!n.startsWith(`workspace:`)||S.push({name:t,spec:F[t]??n,block:C})}return S}var XU,ZU,depsOf,QU=__esmMin(()=>{XU=[`dependencies`,`optionalDependencies`,`peerDependencies`],ZU=`dependencies`,depsOf=(t,n)=>{let S=t[n];return S&&typeof S==`object`?S:{}}});function statusTokenFromEnv(t){for(let n of[t.NPM_STATUS_TOKEN,t.NODE_AUTH_TOKEN]){let t=n?.trim();if(t&&!/^X+(-X+)+$/.test(t))return t}}async function fetchVersionStatus(t){if(!t.token)return{state:`unavailable`,reason:`no-credential`,detail:`the status endpoint needs an npm access token (set NPM_STATUS_TOKEN); OIDC publish tokens are not accepted`};let n=t.fetchImpl??((...t)=>globalThis.fetch(...t)),S=`${t.registry.endsWith(`/`)?t.registry.slice(0,-1):t.registry}/-/package/${escapePackageName(t.name)}/version/${encodeURIComponent(t.version)}/status`,C;try{C=await n(S,{headers:{accept:`application/json`,authorization:`Bearer ${t.token}`},signal:AbortSignal.timeout(t.probeTimeoutMs??3e4)})}catch(t){return{state:`unavailable`,reason:`error`,detail:t instanceof Error?t.message:String(t)}}if(C.status===401)return{state:`unavailable`,reason:`rejected`,detail:`401 — the token is missing, invalid or expired`};if(C.status===403)return{state:`unavailable`,reason:`not-enabled`,detail:`403 — package version status is not enabled for this package`};if(C.status===404)return{state:`unavailable`,reason:`not-found`,detail:`404 — no such version, or the token cannot see this package`};if(!C.ok)return{state:`unavailable`,reason:`error`,detail:`${C.status} ${C.statusText}`};let N;try{N=await C.json()}catch(t){return{state:`unavailable`,reason:`error`,detail:`status body is not JSON (${t instanceof Error?t.message:String(t)})`}}let F=N?.status;return typeof F!=`string`||!$U.includes(F)?{state:`unavailable`,reason:`error`,detail:`unrecognised status ${JSON.stringify(F)}`}:{state:`known`,status:F}}function isTerminalClass(t){return t!==`validating`&&t!==`published-lagging`&&t!==`unchecked`}function whyUnchecked(t){return t.reason===`no-credential`?`status endpoint not asked: no NPM_STATUS_TOKEN`:t.detail}function classifyUnserved(t,n){if(n.state===`known`)switch(n.status){case`validating`:return{cls:`validating`,detail:`npm accepted the upload and its automated review has not finished`,terminal:!1};case`staged`:return{cls:`staged`,detail:`awaiting maintainer approval on npm`,terminal:!0};case`blocked`:return{cls:`blocked`,detail:`failed npm automated validation`,terminal:!0};case`deleted`:return{cls:`deleted`,detail:`deleted on npm`,terminal:!0};case`published`:return{cls:`published-lagging`,detail:`npm reports it published; the install document does not serve it yet`,terminal:!1}}return n.reason===`not-found`?{cls:`missing`,detail:`the registry has no such version (${n.detail}); the PUT did not land`,terminal:!0}:{cls:`unchecked`,detail:`not served (read-back: ${t}); ${whyUnchecked(n)}`,terminal:!1}}function describeClass(t){switch(t){case`validating`:return`validating (npm automated review pending)`;case`staged`:return`staged (needs maintainer approval)`;case`blocked`:return`blocked (failed automated validation)`;case`deleted`:return`deleted`;case`published-lagging`:return`published, not yet served`;case`missing`:return`missing (never recorded)`;case`unchecked`:return`not served (status not checked)`}}var $U,eW=__esmMin(()=>{nh(),$U=[`published`,`validating`,`staged`,`blocked`,`deleted`]});function appendLedger(t,n){t&&appendFileSync(t,`${JSON.stringify(n)}\n`)}function readLedger(t){if(!t||!existsSync(t))return[];let n=[];for(let S of readFileSync(t,`utf-8`).split(`
1193
+ `))if(S.trim())try{let t=JSON.parse(S);(t.ev===`unserved`||t.ev===`held`||t.ev===`served`)&&n.push(t)}catch{}return n}function pinVersion(t){return/^[\^~]?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?)$/.exec(t.trim())?.[1]}async function findUnavailablePins(t){let n=[],S=new Map;for(let C of t.pins){let N=pinVersion(C.spec);if(!N){t.log?.(`gjsify publish: ${C.name}@${C.spec} names no single version — not checked for hold`);continue}let F=`${C.name}@${N}`,I=C.block===`dependencies`?F:`${F}#nowait`;if(!S.has(I)){let n=C.block===`dependencies`?t:{...t,waitBudgetMs:0};S.set(I,await judgePin(n,C.name,N))}let H=S.get(I);H&&n.push({...H,block:C.block})}return n}async function judgePin(t,n,S){let C={name:n,version:S,block:`dependencies`},N=[...t.ledger].reverse().find(t=>t.name===n&&t.version===S);if(N?.ev===`served`)return null;if(N?.ev===`unserved`&&isTerminalClass(N.cls))return{...C,cls:N.cls,detail:N.detail};if(N?.ev===`held`)return{...C,cls:`held`,detail:`was itself held — ${summariseReasons(N.reasons)}`};let F={registry:t.registry,name:n,version:S,authorization:t.authorization,fetchImpl:t.fetchImpl,sleep:t.sleep,now:t.now,log:t.log},I=await verifyPublishedVersion({...F,budgetMs:nW});if(I.confirmed)return confirmedServed(t,N,n,S);let ask=()=>fetchVersionStatus({registry:t.registry,name:n,version:S,token:t.statusToken,fetchImpl:t.fetchImpl}),H=classifyUnserved(I.verdict,await ask());if(!H.terminal&&t.waitBudgetMs>0){if(I=await verifyPublishedVersion({...F,budgetMs:t.waitBudgetMs}),I.confirmed)return confirmedServed(t,N,n,S);H=classifyUnserved(I.verdict,await ask())}return{...C,cls:H.cls,detail:H.detail}}function confirmedServed(t,n,S,C){return n?.ev===`unserved`&&appendLedger(t.ledgerPath,{ev:`served`,name:S,version:C}),null}function summariseReasons(t){return t.map(t=>`${t.name}@${t.version} is ${t.cls===`held`?`held`:describeClass(t.cls)}`).join(`; `)}async function recordUnserved(t){let n=await fetchVersionStatus({registry:t.registry,name:t.name,version:t.version,token:t.statusToken,fetchImpl:t.fetchImpl}),S=classifyUnserved(t.verdict,n);return appendLedger(t.ledgerPath,{ev:`unserved`,name:t.name,version:t.version,cls:S.cls,detail:S.detail}),S}function pendingEntries(t){let n=new Map;for(let S of t)n.set(`${S.name}@${S.version}`,S);let S=[...n.values()];return{unserved:S.filter(t=>t.ev===`unserved`),held:S.filter(t=>t.ev===`held`)}}function markHeldPublished(t,n,S){[...readLedger(t)].reverse().find(t=>t.name===n&&t.version===S)?.ev===`held`&&appendLedger(t,{ev:`served`,name:n,version:S})}async function settleUnserved(t){let n=pendingEntries(t.entries).unserved.filter(t=>!isTerminalClass(t.cls));return(await Promise.all(n.map(async n=>{if((await verifyPublishedVersion({registry:t.registryFor(n.name),name:n.name,version:n.version,budgetMs:t.budgetMs,authorization:t.authorization,fetchImpl:t.fetchImpl,sleep:t.sleep,now:t.now,log:t.log})).confirmed)return appendLedger(t.ledgerPath,{ev:`served`,name:n.name,version:n.version}),`${n.name}@${n.version}`}))).filter(t=>t!==void 0)}function renderLedgerSummary(t,n){let{unserved:S,held:C}=pendingEntries(t);if(S.length===0&&C.length===0)return;let N=[`### npm versions that were accepted but are not installable`,``];if(S.length>0){N.push(`| Package | Version | State | Detail |`,`| --- | --- | --- | --- |`);for(let t of S)N.push(`| \`${t.name}\` | ${t.version} | ${describeClass(t.cls)} | ${t.detail} |`);N.push(``)}if(C.length>0){N.push(`### Held — NOT published in this run`,``,`Each package below depends on a version npm does not serve, so publishing it would have shipped a package that cannot be installed.`,``,`| Package | Version | Because |`,`| --- | --- | --- |`);for(let t of C)N.push(`| \`${t.name}\` | ${t.version} | ${summariseReasons(t.reasons)} |`);N.push(``,"Once the dependencies above are served by npm (a `validating` version appears on its own, or is approved/released by a maintainer), publish the held set with:",``,"```sh",`gh workflow run release.yml --ref ${n} -f skip_publish=false -f only='${[...new Set(C.map(t=>t.name))].join(` `)}'`,"```"),S.some(t=>t.cls===`blocked`||t.cls===`deleted`)&&N.push(``,"A `blocked` or `deleted` version is a spent number: re-running the release cannot serve it, the package needs a version bump.")}return N.join(`
1194
+ `)}var tW,nW,holdsPublish,rW=__esmMin(()=>{Rd(),QU(),YU(),eW(),tW=3e5,nW=1,holdsPublish=t=>t.block===ZU});function beginPrompt(){iW++}function endPrompt(t=defaultWrite){if(iW=Math.max(0,iW-1),iW>0||aW.length===0)return;let n=aW.splice(0,aW.length);for(let S of n)t(S)}function writeAroundPrompt(t,n=defaultWrite){if(iW>0){aW.push(t);return}n(t)}function defaultWrite(t){process.stdout.write(t)}var iW,aW,oW=__esmMin(()=>{iW=0,aW=[]});function isTtyStdin(){let t=process.stdin;return!!t.isTTY&&typeof t.setRawMode==`function`}function applyKey(t,n,S){return n===`\r`||n===`
1195
1195
  `?{buf:t,echo:`
1196
- `,done:!0,interrupt:!1}:n===eW?{buf:t,echo:`
1197
- `,done:!1,interrupt:!0}:n===tW||n===nW?t.length>0?{buf:t.slice(0,-1),echo:`\b \b`,done:!1,interrupt:!1}:{buf:t,echo:``,done:!1,interrupt:!1}:n>=` `?{buf:t+n,echo:S?`*`:n,done:!1,interrupt:!1}:{buf:t,echo:``,done:!1,interrupt:!1}}async function runRawSession(t){let n=process.stdin,S=process.stdout,C=null,cleanup=()=>{n.removeListener(`data`,onData);try{n.setRawMode(!1)}catch{}typeof n.pause==`function`&&n.pause()},onData=t=>{let n=typeof t==`string`?t:t.toString(`utf-8`);for(let t of n){if(!C)continue;let n=applyKey(C.buf,t,C.mask);if(C.buf=n.buf,n.echo&&S.write(n.echo),n.interrupt)return cleanup(),process.exit(130);if(n.done){let{resolve:t}=C;C=null,t(n.buf)}}};n.setRawMode(!0),typeof n.resume==`function`&&n.resume(),n.setEncoding(`utf-8`),n.on(`data`,onData);let read=(t,n)=>new Promise(N=>{beginPrompt(),S.write(t),C={mask:n,buf:``,resolve:t=>{endPrompt(),N(t)}}});try{return await t(read)}finally{cleanup()}}function readLine(){return new Promise(t=>{let n=``,onData=S=>{n+=typeof S==`string`?S:S.toString(`utf-8`);let C=n.search(/[\r\n]/);C>=0&&(cleanup(),t(n.slice(0,C)))},onEnd=()=>{cleanup(),t(n.replace(/\r$/,``).trim())},cleanup=()=>{process.stdin.removeListener(`data`,onData),process.stdin.removeListener(`end`,onEnd)};process.stdin.setEncoding(`utf-8`),typeof process.stdin.isPaused==`function`&&process.stdin.isPaused()&&process.stdin.resume(),process.stdin.on(`data`,onData),process.stdin.once(`end`,onEnd)})}async function promptLine(t){if(!isTtyStdin()){beginPrompt(),process.stdout.write(t);try{return await readLine()}finally{endPrompt()}}return runRawSession(n=>n(t,!1))}async function promptCredentials(t){if(!isTtyStdin()){let n=t;n||=(process.stdout.write(`Username: `),await readLine()),process.stdout.write(`Password: `);let S=await readLine();return{username:n,password:S}}return runRawSession(async n=>({username:t??await n(`Username: `,!1),password:await n(`Password: `,!0)}))}var eW,tW,nW,rW=__esmMin(()=>{$U(),eW=``,tW=``,nW=`\b`});function isOtpCacheEnabled(){let t=process.env[iW];return!(t===`1`||t===`true`||t===`yes`)}function normalizeRegistry(t){return t.endsWith(`/`)?t.slice(0,-1):t}function cacheBaseDir(t){if(t?.dir)return t.dir;let n=process.env.XDG_RUNTIME_DIR;return wn(n&&n.length>0?n:tmpdir(),aW)}function cacheFileFor(t,n){let S=normalizeRegistry(t).replace(/[^a-zA-Z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,120);return wn(cacheBaseDir(n),`otp-${S||`default`}.json`)}function readCachedOtp(t,n){if(!isOtpCacheEnabled())return;let S=n?.now??Date.now(),C=cacheFileFor(t,n);try{if(!existsSync(C))return;let n=JSON.parse(readFileSync(C,`utf8`));if(!n||typeof n.otp!=`string`||typeof n.expiresAt!=`number`){deleteCacheFile(C);return}if(n.registry!==normalizeRegistry(t))return;if(S>=n.expiresAt){deleteCacheFile(C);return}return n.otp.length>0?n.otp:void 0}catch{deleteCacheFile(C);return}}function writeCachedOtp(t,n,S){if(!isOtpCacheEnabled()||!n||n.length===0)return;let C=S?.now??Date.now(),N=S?.ttlMs??3e4;try{mkdirSync(cacheBaseDir(S),{recursive:!0,mode:448});let F=cacheFileFor(t,S),I={otp:n,expiresAt:C+N,registry:normalizeRegistry(t)};writeFileSync(F,JSON.stringify(I),{mode:384}),chmodSync(F,384)}catch{}}function clearCachedOtp(t,n){deleteCacheFile(cacheFileFor(t,n))}function deleteCacheFile(t){try{existsSync(t)&&rmSync(t,{force:!0})}catch{}}var iW,aW,oW=__esmMin(()=>{Rd(),Lg(),Pn(),iW=`GJSIFY_NO_OTP_CACHE`,aW=`gjsify-otp`});async function isOtpChallenge(t){if(t.status!==401)return!1;if((t.headers.get(`www-authenticate`)??``).toLowerCase().includes(`otp`))return!0;let n=await t.clone().text().catch(()=>``);return/one-time pass/i.test(n)||/\bEOTP\b/.test(n)}async function withOtpRetry(t,n,S={}){let C=S.maxPrompts??2,N=S.question,F=n.current(),I=S.seedFirstAttempt===!0&&F!==void 0,H=n.epoch(),W=await t(I?F:void 0);if(!await isOtpChallenge(W))return W;if(I&&n.invalidate(H),!I&&n.current()!==void 0){if(H=n.epoch(),W=await t(n.current()),!await isOtpChallenge(W))return W;n.invalidate(H)}for(let S=0;S<C;S++){let S=await n.refresh(N,H);if(!S||(H=n.epoch(),W=await t(S),!await isOtpChallenge(W)))return W;n.invalidate(H)}return W}var sW,cW,OtpProvider,lW=__esmMin(()=>{rW(),oW(),sW=`This operation requires a one-time password.
1198
- Enter OTP: `,cW=`The previous one-time password is no longer valid (npm codes last about 30 seconds).
1199
- Enter a NEW OTP: `,OtpProvider=class{cached;promptFn;registry;generation=0;pending;constructor(t,n=promptLine,S={}){this.promptFn=n,this.registry=S.registry;let C=t&&t.length>0?t:void 0;C?(this.cached=C,this.registry&&writeCachedOtp(this.registry,C)):this.cached=this.registry?readCachedOtp(this.registry):void 0}current(){return this.cached}epoch(){return this.generation}async refresh(t,n){if(n!==void 0&&this.generation>n&&this.cached)return this.cached;if(this.pending)return this.pending;this.pending=this.promptOnce(t??(this.generation>0?cW:sW));try{return await this.pending}finally{this.pending=void 0}}async promptOnce(t){let n=(await this.promptFn(t)).trim();return n&&(this.cached=n,this.generation++,this.registry&&writeCachedOtp(this.registry,n)),n}invalidate(t){t!==void 0&&this.generation!==t||(this.cached=void 0,this.registry&&clearCachedOtp(this.registry))}}});async function publishWorkspace(t){let{wsDir:n,tag:S,access:C,provenance:N,tolerate:F,tolerateUntrustedNew:I,trustedFlag:H,verbose:W,json:q,otpProvider:Y}=t,X=await packWorkspace(n,{dryRun:!0,lifecycleScripts:[`prepublishOnly`,`prepack`],lifecycleStdio:q?`inherit-stderr`:`inherit`}),Z=await packWorkspaceToBytes(n),te=readFileSync(wn(n,`package.json`),`utf-8`),ne=JSON.parse(te),re=await loadRewrittenManifest(n,ne),ie=await loadNpmrc(n),ae=t.registry??process.env.npm_config_registry??registryFor(X.name,ie)??qm,oe=ae.endsWith(`/`)?ae.slice(0,-1):ae,Q=`${oe}/${escapePackageName(X.name)}`,se=`${X.name.includes(`/`)?X.name.slice(X.name.indexOf(`/`)+1):X.name}-${X.version}.tgz`,ce=buildPublishPayload({pkg:re,tag:S,access:C,tarballBytes:Z,tarballUrl:`${oe}/${X.name}/-/${se}`,packed:{...X,wireFilename:se},provenance:N}),le=buildPublishHeaders(Q,{npmrc:ie}),ue=new Set(t.assumePresent??[]),de=collectWorkspacePins(ne,re).filter(t=>!ue.has(t.name));if(de.length>0){let t=await Promise.all(de.map(async t=>({pin:t,presence:await probePackageName({registry:ae,name:t.name,authorization:le.authorization})}))),n=[];for(let{pin:S,presence:C}of t){if(C.state===`present`)continue;let t=`${S.block}.${S.name}@${S.spec}`;if(C.state===`unknown`){ge.error(`gjsify publish: could not establish whether ${S.name} exists (${C.detail}) — not blocking on ${t}`);continue}if(S.block!==`dependencies`){ge.error(`gjsify publish: ${t} names a package ${ae} does not have — npm installs around it, Yarn (\`YN0035\`) does not`);continue}n.push(S)}if(n.length>0)return{ok:I,action:`blocked-missing-dependency`,name:X.name,version:X.version,registry:ae,tolerated:I,missing:n}}let fe=process.env.GJSIFY_PUBLISH_LEDGER;if(de.length>0){let n=await findUnavailablePins({registry:oe,pins:de,ledger:readLedger(fe),ledgerPath:fe,authorization:le.authorization,statusToken:statusTokenFromEnv(process.env),waitBudgetMs:t.holdWaitMs??3e5,log:W?t=>ge.error(t):void 0});for(let t of n.filter(t=>!holdsPublish(t)))ge.error(`gjsify publish: ${t.block}.${t.name}@${t.version} is not served (${t.detail}) — optional edge, publishing anyway`);let S=n.filter(holdsPublish);if(S.length>0)return appendLedger(fe,{ev:`held`,name:X.name,version:X.version,reasons:S}),{ok:!1,action:`held-unpublished-dependency`,name:X.name,version:X.version,registry:oe,reasons:S}}let pe=H===!0||H===void 0&&hasGithubOidcEnv()&&!process.env.NODE_AUTH_TOKEN,me=`token`;if(pe)try{let{token:t,audience:n}=await getNpmTrustedToken({packageName:X.name,registry:ae,log:W?t=>ge.error(t):void 0});le.authorization=`Bearer ${t}`,me=`oidc`,W&&ge.error(`gjsify publish: OIDC token obtained (audience=${n})`)}catch(t){if(t instanceof OidcExchangeError&&t.status===404&&/package not found/i.test(t.body)&&I)return{ok:!0,action:`skipped-untrusted-new`,name:X.name,version:X.version};if(H===!0)return{ok:!1,action:`oidc-failed`,name:X.name,version:X.version,error:t};if(!le.authorization)return{ok:!1,action:`oidc-no-token`,name:X.name,version:X.version,error:t};if(W){let n=t instanceof Error?t.message:String(t);ge.error(`gjsify publish: OIDC auto-detect failed (${n}) — falling back to token auth`)}}W&&(ge.error(`gjsify publish: PUT ${Q} (${X.name}@${X.version})`),ge.error(` auth-mode: ${me}`),ge.error(` authorization: ${le.authorization?`(set)`:`(none)`}`),ge.error(` payload size: ${JSON.stringify(ce).length} bytes`));let he=JSON.stringify(ce),doPut=t=>{let n={...le};return t&&(n[`npm-otp`]=t,n[`npm-auth-type`]=`legacy`),fetch(Q,{method:`PUT`,headers:n,body:he})},_e=await withOtpRetry(doPut,Y,{seedFirstAttempt:t.seedOtpFirst});if(W){ge.error(` response: ${_e.status} ${_e.statusText}`);let t=await _e.clone().text().catch(()=>``);t&&ge.error(` body: ${t.slice(0,300)}`)}let readBack=async()=>{let n=t.verifyBudgetMs??6e5;if(!(n<=0))return verifyPublishedVersion({registry:oe,name:X.name,version:X.version,budgetMs:n,authorization:le.authorization,log:W?t=>ge.error(t):void 0})};if(await isOtpChallenge(_e))return{ok:!1,action:`otp-required`,name:X.name,version:X.version,status:_e.status};if(_e.ok){let t=await readBack();return t?.confirmed&&W&&ge.error(` read-back: confirmed after ${t.attempts} probe(s) in ${t.elapsedMs} ms`),t&&!t.confirmed?{ok:!1,action:`publish-unconfirmed`,claim:`accepted`,name:X.name,version:X.version,registry:oe,putStatus:_e.status,putStatusText:_e.statusText,putUrl:Q,payloadBytes:he.length,readback:t,classification:await recordUnserved({ledgerPath:fe,registry:oe,name:X.name,version:X.version,verdict:t.verdict,statusToken:statusTokenFromEnv(process.env)})}:{ok:!0,action:`published`,name:X.name,version:X.version,filename:X.filename,size:X.size,integrity:X.integrity,tag:S,registry:oe,readback:t}}let ve=await _e.text().catch(()=>`<no body>`);if((_e.status===409||_e.status===403&&/previously published/i.test(ve))&&F){let t=await readBack();return t&&!t.confirmed?{ok:!1,action:`publish-unconfirmed`,claim:`already-published`,name:X.name,version:X.version,registry:oe,putStatus:_e.status,putStatusText:_e.statusText,putUrl:Q,payloadBytes:he.length,readback:t,classification:await recordUnserved({ledgerPath:fe,registry:oe,name:X.name,version:X.version,verdict:t.verdict,statusToken:statusTokenFromEnv(process.env)})}:{ok:!0,action:`republish-tolerated`,name:X.name,version:X.version,status:_e.status,registry:oe,readback:t}}if(_e.status===404&&me===`token`&&is404DiagnosticCandidate(ve)){let t=await diagnose404({packageName:X.name,version:X.version,registry:oe,npmrc:ie});if(t.reason!==`unknown`)return{ok:!1,action:`diagnostic`,name:X.name,version:X.version,status:404,diag:t}}return{ok:!1,action:`error`,name:X.name,version:X.version,status:_e.status,statusText:_e.statusText,text:ve}}function describeVerification(t,n){if(!t?.confirmed)return{verified:!1,clause:`(UNVERIFIED — read-back disabled by --verify-timeout 0)`,json:null};let S=(t.elapsedMs/1e3).toFixed(1);return{verified:!0,clause:`(verified on ${n} — ${t.attempts} probe(s), ${S}s)`,json:{registry:n,verdict:t.verdict,probes:t.attempts,elapsedMs:t.elapsedMs,tarball:t.last.state===`present`?t.last.tarball:null}}}function warnUnverified(t,n,S){process.env.GITHUB_ACTIONS&&process.stderr.write(`::warning title=Publish unverified::${t}@${n} was published with the read-back disabled (--verify-timeout 0) — nothing confirmed that ${S} serves it\n`)}function reportPublishOutcome(t,n,S=!1){switch(t.action){case`published`:{let S=describeVerification(t.readback,t.registry),C={ok:!0,name:t.name,version:t.version,filename:t.filename,size:t.size,integrity:t.integrity,tag:t.tag,registry:t.registry,verified:S.verified,verification:S.json};n?process.stdout.write(`${JSON.stringify(C,null,2)}\n`):process.stdout.write(`+ ${t.name}@${t.version} ${S.clause}\n`),S.verified||warnUnverified(t.name,t.version,t.registry);return}case`held-unpublished-dependency`:{let C=summariseReasons(t.reasons);return n?process.stdout.write(`${JSON.stringify({ok:!1,action:`held-unpublished-dependency`,name:t.name,version:t.version,registry:t.registry,reasons:t.reasons,deferred:S},null,2)}\n`):process.stderr.write(`~ ${t.name}@${t.version} (HELD — not published: ${C})\n`),process.env.GITHUB_ACTIONS&&process.stderr.write(`::warning title=Package held::${t.name}@${t.version} was NOT published: ${C}\n`),S?void 0:process.exit(1)}case`publish-unconfirmed`:{let C=`${formatUnconfirmedPublish(t)}\n state: ${describeClass(t.classification.cls)} — ${t.classification.detail}`;if(n?process.stdout.write(`${JSON.stringify({ok:!1,action:`publish-unconfirmed`,name:t.name,version:t.version,registry:t.registry,claim:t.claim,putStatus:t.putStatus,probes:t.readback.attempts,elapsedMs:t.readback.elapsedMs,readbackUrl:t.readback.url,readbackState:t.readback.last.state,verdict:t.readback.verdict,verdictDetail:t.readback.verdictDetail,recordedAt:t.readback.recordedAt??null,deferred:S,class:t.classification.cls,classDetail:t.classification.detail},null,2)}\n`):process.stderr.write(`${C}\n`),S){if(process.env.GITHUB_ACTIONS){let n=t.claim===`already-published`?`was reported already published`:`was accepted`;process.stderr.write(`::warning title=Publish unconfirmed::${t.name}@${t.version} ${n} (HTTP ${t.putStatus}) but did not resolve on ${t.registry} within ${(t.readback.elapsedMs/1e3).toFixed(1)}s [${t.readback.verdict}; ${describeClass(t.classification.cls)}] — the release-closure job must confirm it
1200
- `)}return}return process.exit(1)}case`republish-tolerated`:{let S=describeVerification(t.readback,t.registry),C={ok:!0,action:`republish-tolerated`,name:t.name,version:t.version,status:t.status,registry:t.registry,verified:S.verified,verification:S.json};n?process.stdout.write(`${JSON.stringify(C,null,2)}\n`):process.stdout.write(`= ${t.name}@${t.version} (already published, tolerated) ${S.clause}\n`),S.verified||warnUnverified(t.name,t.version,t.registry);return}case`skipped-untrusted-new`:n?process.stdout.write(`${JSON.stringify({ok:!0,action:`skipped-untrusted-new`,name:t.name,version:t.version,reason:`no-trusted-publisher`},null,2)}\n`):process.stdout.write(`~ ${t.name}@${t.version} (skipped — no Trusted Publisher on npm, see AGENTS.md "New @gjsify/* package: first-publish + Trusted Publisher bootstrap")\n`);return;case`blocked-missing-dependency`:{let S=t.missing.map(t=>`${t.block}.${t.name}@${t.spec}`).join(`, `);return n?process.stdout.write(`${JSON.stringify({ok:t.ok,action:`blocked-missing-dependency`,name:t.name,version:t.version,registry:t.registry,tolerated:t.tolerated,missing:t.missing},null,2)}\n`):process.stdout.write(`~ ${t.name}@${t.version} (NOT published — ${t.missing.length} required pin(s) name a package ${t.registry} does not have: ${S})\n`),ge.error(`gjsify publish: every consumer install of ${t.name} would fail with \`npm error 404\`, on every package manager — a required edge is not skippable. Bootstrap the target first (docs/publishing.md § New \`@gjsify/*\` package), then re-run. See #1713.`),t.tolerated?void 0:process.exit(1)}case`otp-required`:return ge.error("gjsify publish: npm requires a 2FA one-time code — re-run with `--otp <code>`"),process.exit(1);case`oidc-failed`:return handleOidcFailure(t.error,t.name,n),process.exit(1);case`oidc-no-token`:{let S=t.error instanceof Error?t.error.message:String(t.error);return ge.error(`gjsify publish: OIDC token exchange failed for ${t.name} (${S}) and no fallback npm token is configured — refusing to publish without credentials.`),n&&process.stdout.write(`${JSON.stringify({ok:!1,name:t.name,version:t.version,error:`oidc-failed-no-token`},null,2)}\n`),process.exit(1)}case`diagnostic`:return n?process.stdout.write(`${JSON.stringify({ok:!1,name:t.name,version:t.version,status:404,diagnostic:t.diag.reason,username:t.diag.username},null,2)}\n`):process.stderr.write(`${t.diag.message}\n`),process.exit(1);case`error`:return ge.error(`gjsify publish: ${t.name}@${t.version} — ${t.status} ${t.statusText}`),ge.error(t.text),process.exit(1)}}async function packWorkspaceToBytes(t){let n=wn(tmpdir(),`gjsify-publish-${process.pid}-${Date.now()}`),S=await packWorkspace(t,{destination:n,dryRun:!1,lifecycleScripts:[]});if(!S.absolutePath)throw Error(`gjsify publish: pack did not produce a file`);let C=new Uint8Array(readFileSync(S.absolutePath));try{(await Promise.resolve().then(()=>(Rd(),Id))).rmSync(S.absolutePath)}catch{}try{(await Promise.resolve().then(()=>(Rd(),Id))).rmdirSync(n)}catch{}return C}async function loadRewrittenManifest(t,n){let S=wn(tmpdir(),`gjsify-publish-manifest-${process.pid}-${Date.now()}`),C=await packWorkspace(t,{destination:S,dryRun:!1}),{rmSync:N}=await Promise.resolve().then(()=>(Rd(),Id));if(!C.absolutePath)throw Error(`gjsify publish: pack did not produce a file`);let{gunzip:F,parseTar:I}=await Promise.resolve().then(()=>(hL(),mL)),H=new Uint8Array(readFileSync(C.absolutePath));N(S,{recursive:!0,force:!0,maxRetries:3,retryDelay:100});let W=await F(H);for(let t of I(W))if(t.name===`package/package.json`&&t.body)return JSON.parse(new TextDecoder().decode(t.body));return n}function buildPublishPayload(t){let{pkg:n,tag:S,access:C,tarballBytes:N,tarballUrl:F,packed:I,provenance:H}=t,W={...n,_id:`${I.name}@${I.version}`,dist:{integrity:I.integrity,shasum:I.shasum,tarball:F}};H&&(W._hasShrinkwrap=!1);let q={_id:I.name,name:I.name,description:typeof n.description==`string`?n.description:``,"dist-tags":{[S]:I.version},versions:{[I.version]:W},readme:``,_attachments:{[I.wireFilename]:{content_type:`application/octet-stream`,data:base64Encode(N),length:N.byteLength}}};return C&&(q.access=C),q}function handleOidcFailure(t,n,S){if(t instanceof OidcUnavailableError){let C=`gjsify publish: OIDC not available — ${t.message}`;S?process.stdout.write(`${JSON.stringify({ok:!1,name:n,error:`oidc-unavailable`,reason:t.reason,message:t.message})}\n`):process.stderr.write(`${C}\n`);return}if(t instanceof OidcExchangeError){let C=t.status===401||t.status===403?`npm rejected the OIDC exchange (${t.status}) — check that ${n} has a Trusted Publisher configured at https://www.npmjs.com/package/${encodeURIComponent(n)}/access pointing at this workflow.`:t.message;if(S)process.stdout.write(`${JSON.stringify({ok:!1,name:n,error:`oidc-exchange`,status:t.status,body:t.body,claims:t.claims,message:t.message})}\n`);else if(process.stderr.write(`✗ ${n}: ${C}\n`),t.body&&process.stderr.write(` ↳ npm said: ${t.body.slice(0,300)}\n`),t.claims){let n=t.claims,S=[`aud`,`iss`,`repository`,`repository_owner`,`workflow_ref`,`job_workflow_ref`,`ref`,`environment`,`sub`].filter(t=>n[t]!==void 0).map(t=>`${t}=${JSON.stringify(n[t])}`).join(`, `);S&&process.stderr.write(` ↳ JWT claims npm received: ${S}\n`)}return}let C=t instanceof Error?t.message:String(t);S?process.stdout.write(`${JSON.stringify({ok:!1,name:n,error:`unknown`,message:C})}\n`):process.stderr.write(`✗ ${n}: ${C}\n`)}var uW,dW=__esmMin(()=>{_e(),Rd(),Lg(),Pn(),HH(),eh(),nh(),PU(),IU(),LU(),HU(),GU(),XU(),qU(),IR(),lW(),rW(),uW={command:`publish [path]`,description:"Pack + upload the workspace at <path> (default: cwd) to its npm registry. Drop-in for `npm publish` with workspace:^ rewrite handled automatically.",builder:t=>t.positional(`path`,{description:`Workspace path (default: cwd).`,type:`string`}).option(`tag`,{description:`Dist-tag to publish under. Default: latest.`,type:`string`,default:`latest`}).option(`access`,{description:"Package access — `public` or `restricted` (required for first publish of scoped packages on the public registry).",type:`string`}).option(`otp`,{description:"npm 2FA one-time code; sent as the `npm-otp` header. Required for manual publishes from a 2FA-enabled account.",type:`string`}).option(`tolerate-republish`,{description:'Treat "version already published" as success — covers both classic 409 Conflict and the npm OIDC-path 403 Forbidden + `"previously published"` body shape. Matches yarn `--tolerate-republish`.',type:`boolean`,default:!1}).option(`tolerate-untrusted-new`,{description:'Skip (exit 0) when OIDC token exchange returns `package not found` AND no fallback token is configured — i.e. a never-before-published `@scope/<name>` whose Trusted Publisher entry hasn\'t been set up on npmjs.com yet. Without this flag, one un-bootstrapped new package breaks the entire serialized `gjsify foreach publish` loop. Pair with `--tolerate-republish` in CI release workflows so a fresh-merged package gracefully skips its first CI publish, leaving the manual-bootstrap step to a maintainer (see AGENTS.md "New @gjsify/* package: first-publish + Trusted Publisher bootstrap").',type:`boolean`,default:!1}).option(`verify-timeout`,{description:"Seconds to keep asking the registry for the just-published version before giving up. npm answers 2xx to a write it has only ACCEPTED: in the v0.46.0 release 19 of 199 packages were recorded 56-252s after their 2xx and one was never recorded at all, so a shorter window turns normal queueing into a false red. `0` disables the read-back — for a registry with no packument read path; the success line then reads `UNVERIFIED` and says so, because a publish nothing checked must never look like one that was checked.",type:`number`,default:BU/1e3}).option(`verify-defer`,{description:"Report an unconfirmed read-back and exit 0 instead of 1. ONLY for a caller that re-checks the same set afterwards — `gjsify run npm:publish` passes it because `scripts/verify-published-closure.mjs` sweeps the whole roster at the end of release.yml. Everywhere else an unconfirmed publish must fail the job that made it.",type:`boolean`,default:!1}).option(`hold-timeout`,{description:'Seconds to wait for an intra-repo dependency pin whose exact version the registry does not serve (yet) before HOLDING this package instead of publishing it. A version npm accepted but never serves (status "validating") would make every dependent uninstallable; the write lag measured on v0.46.0 reaches 252s, hence the default. `0` probes once and holds without waiting. A hold exits 1, or 0 under `--verify-defer`.',type:`number`,default:JU/1e3}).option(`report-ledger`,{description:"Print the job-summary markdown for the publish ledger named by $GJSIFY_PUBLISH_LEDGER (versions npm accepted but does not serve, packages held because of them, the recovery command) and exit. Pair with `--ref <tag>`.",type:`boolean`,default:!1}).option(`ref`,{description:`With --report-ledger: the git ref to put in the printed recovery command.`,type:`string`}).option(`provenance`,{description:`Pass-through flag — recorded in the payload but no signing happens (gjsify doesn't ship a sigstore signer yet).`,type:`boolean`,default:!1}).option(`dry-run`,{description:`Pack only, do not PUT.`,type:`boolean`,default:!1}).option(`json`,{description:`Emit publish metadata as JSON on stdout.`,type:`boolean`,default:!1}).option(`trusted`,{description:"Authenticate via npm Trusted Publishing (OIDC): exchange the GitHub Actions id-token for a short-lived npm token. Pass `--trusted` to force this mode (errors if env vars missing). Omit to auto-detect: OIDC is used iff `ACTIONS_ID_TOKEN_REQUEST_URL`+`_TOKEN` are set AND no `_authToken` is present in the resolved npmrc; otherwise the long-lived token path is used. Requires the calling workflow to declare `permissions: id-token: write` AND the target package to have a Trusted Publisher configured on npmjs.com.",type:`boolean`,default:void 0}).option(`check-trusted`,{description:"Diagnostic mode: perform the OIDC id-token request + npm token exchange, report success/failure, then exit WITHOUT publishing. Useful as a bulk-verifier (e.g. via `gjsify foreach publish --check-trusted`) to confirm Trusted Publisher config across many packages.",type:`boolean`,default:!1}),handler:async t=>{let n=xn(t.path??process.cwd()),S=t.tag??`latest`,C=t.access,N=t.otp,F=t[`tolerate-republish`]===!0,I=t[`tolerate-untrusted-new`]===!0,H=t[`verify-timeout`]??6e5/1e3;if(!Number.isFinite(H)||H<0)return ge.error(`gjsify publish: --verify-timeout must be a non-negative number of seconds, got ${JSON.stringify(t[`verify-timeout`])}`),process.exit(2);let W=Math.round(H*1e3),q=t[`verify-defer`]===!0,Y=t.provenance===!0,X=t[`dry-run`]===!0,Z=t[`check-trusted`]===!0,te=t.trusted,ne=!!process.env.GJSIFY_PUBLISH_DEBUG;if(t[`report-ledger`]===!0){let n=renderLedgerSummary(readLedger(process.env.GJSIFY_PUBLISH_LEDGER),t.ref??`<tag>`);n&&process.stdout.write(`${n}\n`);return}let re=t[`hold-timeout`]??3e5/1e3;if(!Number.isFinite(re)||re<0)return ge.error(`gjsify publish: --hold-timeout must be a non-negative number of seconds, got ${JSON.stringify(t[`hold-timeout`])}`),process.exit(2);if(Y&&ge.warn(`gjsify publish: --provenance recorded but not signed (no sigstore integration yet).`),Z){let S=wn(n,`package.json`),C=JSON.parse(readFileSync(S,`utf-8`));if(typeof C.name!=`string`)return process.stderr.write(`gjsify publish --check-trusted: ${S} has no \`name\` field\n`),process.exit(2);if(C.private===!0){let n={ok:!0,action:`check-trusted`,name:C.name,skipped:`private`};t.json?process.stdout.write(`${JSON.stringify(n)}\n`):process.stdout.write(`- ${C.name}: skipped (private package)\n`);return}let N=await loadNpmrc(n),F=process.env.npm_config_registry??registryFor(C.name,N)??qm;try{await getNpmTrustedToken({packageName:C.name,registry:F,log:ne?t=>ge.error(t):void 0});let n={ok:!0,action:`check-trusted`,name:C.name,registry:F};t.json?process.stdout.write(`${JSON.stringify(n)}\n`):process.stdout.write(`✓ ${C.name}: trusted publisher OK\n`);return}catch(n){handleOidcFailure(n,C.name,t.json===!0);return}}if(X){let S=await packWorkspace(n,{dryRun:!0,lifecycleScripts:[`prepublishOnly`,`prepack`],lifecycleStdio:t.json?`inherit-stderr`:`inherit`}),C={ok:!0,action:`dry-run`,name:S.name,version:S.version,filename:S.filename,size:S.size,shasum:S.shasum,integrity:S.integrity};t.json?process.stdout.write(`${JSON.stringify(C,null,2)}\n`):process.stdout.write(`+ ${S.name}@${S.version} (dry-run, ${S.size} bytes, ${S.entryCount} files)\n`);return}let ie=!!(process.stdin.isTTY&&process.stdout.isTTY),ae=await loadNpmrc(n),oe;try{oe=JSON.parse(readFileSync(wn(n,`package.json`),`utf-8`)).name}catch{}let Q=process.env.npm_config_registry??(oe?registryFor(oe,ae):void 0)??ae.registry??qm,se=new OtpProvider(N,ie?promptLine:async()=>``,{registry:Q});reportPublishOutcome(await publishWorkspace({wsDir:n,tag:S,access:C,provenance:Y,tolerate:F,tolerateUntrustedNew:I,trustedFlag:te,verbose:ne,json:t.json===!0,otpProvider:se,seedOtpFirst:N!==void 0,verifyBudgetMs:W,holdWaitMs:Math.round(re*1e3)}),t.json===!0,q)}}}),fW,pW=__esmMin(()=>{eh(),IR(),fW={command:`whoami`,description:`Print the npm-registry username for the current ~/.npmrc token. Clear failure message when the token is dead, missing, or the registry is unreachable.`,builder:t=>t.option(`registry`,{description:`Registry URL to probe. Default: scope-aware lookup from .npmrc (falls back to ${qm}).`,type:`string`}).option(`json`,{description:"Emit `{username, registry}` (or `{error, registry}`) as a single-line JSON object.",type:`boolean`,default:!1}),handler:async t=>{let n=await loadNpmrc(process.cwd()),S=t.registry??process.env.npm_config_registry??n.registry??qm,C=S.endsWith(`/`)?S.slice(0,-1):S,N=t.json===!0;if(!hasAnyCredential(n))return N?process.stdout.write(`${JSON.stringify({error:`no-token-configured`,registry:C})}\n`):process.stderr.write([`gjsify whoami: no npm token configured.`,``,`No \`_authToken\` found in ~/.npmrc / $NPM_CONFIG_USERCONFIG / .npmrc for ${C}.`,``,`Add one via: npm login`,`Then verify: gjsify whoami`].join(`
1196
+ `,done:!0,interrupt:!1}:n===sW?{buf:t,echo:`
1197
+ `,done:!1,interrupt:!0}:n===cW||n===lW?t.length>0?{buf:t.slice(0,-1),echo:`\b \b`,done:!1,interrupt:!1}:{buf:t,echo:``,done:!1,interrupt:!1}:n>=` `?{buf:t+n,echo:S?`*`:n,done:!1,interrupt:!1}:{buf:t,echo:``,done:!1,interrupt:!1}}async function runRawSession(t){let n=process.stdin,S=process.stdout,C=null,cleanup=()=>{n.removeListener(`data`,onData);try{n.setRawMode(!1)}catch{}typeof n.pause==`function`&&n.pause()},onData=t=>{let n=typeof t==`string`?t:t.toString(`utf-8`);for(let t of n){if(!C)continue;let n=applyKey(C.buf,t,C.mask);if(C.buf=n.buf,n.echo&&S.write(n.echo),n.interrupt)return cleanup(),process.exit(130);if(n.done){let{resolve:t}=C;C=null,t(n.buf)}}};n.setRawMode(!0),typeof n.resume==`function`&&n.resume(),n.setEncoding(`utf-8`),n.on(`data`,onData);let read=(t,n)=>new Promise(N=>{beginPrompt(),S.write(t),C={mask:n,buf:``,resolve:t=>{endPrompt(),N(t)}}});try{return await t(read)}finally{cleanup()}}function readLine(){return new Promise(t=>{let n=``,onData=S=>{n+=typeof S==`string`?S:S.toString(`utf-8`);let C=n.search(/[\r\n]/);C>=0&&(cleanup(),t(n.slice(0,C)))},onEnd=()=>{cleanup(),t(n.replace(/\r$/,``).trim())},cleanup=()=>{process.stdin.removeListener(`data`,onData),process.stdin.removeListener(`end`,onEnd)};process.stdin.setEncoding(`utf-8`),typeof process.stdin.isPaused==`function`&&process.stdin.isPaused()&&process.stdin.resume(),process.stdin.on(`data`,onData),process.stdin.once(`end`,onEnd)})}async function promptLine(t){if(!isTtyStdin()){beginPrompt(),process.stdout.write(t);try{return await readLine()}finally{endPrompt()}}return runRawSession(n=>n(t,!1))}async function promptCredentials(t){if(!isTtyStdin()){let n=t;n||=(process.stdout.write(`Username: `),await readLine()),process.stdout.write(`Password: `);let S=await readLine();return{username:n,password:S}}return runRawSession(async n=>({username:t??await n(`Username: `,!1),password:await n(`Password: `,!0)}))}var sW,cW,lW,uW=__esmMin(()=>{oW(),sW=``,cW=``,lW=`\b`});function isOtpCacheEnabled(){let t=process.env[dW];return!(t===`1`||t===`true`||t===`yes`)}function normalizeRegistry(t){return t.endsWith(`/`)?t.slice(0,-1):t}function cacheBaseDir(t){if(t?.dir)return t.dir;let n=process.env.XDG_RUNTIME_DIR;return wn(n&&n.length>0?n:tmpdir(),fW)}function cacheFileFor(t,n){let S=normalizeRegistry(t).replace(/[^a-zA-Z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,120);return wn(cacheBaseDir(n),`otp-${S||`default`}.json`)}function readCachedOtp(t,n){if(!isOtpCacheEnabled())return;let S=n?.now??Date.now(),C=cacheFileFor(t,n);try{if(!existsSync(C))return;let n=JSON.parse(readFileSync(C,`utf8`));if(!n||typeof n.otp!=`string`||typeof n.expiresAt!=`number`){deleteCacheFile(C);return}if(n.registry!==normalizeRegistry(t))return;if(S>=n.expiresAt){deleteCacheFile(C);return}return n.otp.length>0?n.otp:void 0}catch{deleteCacheFile(C);return}}function writeCachedOtp(t,n,S){if(!isOtpCacheEnabled()||!n||n.length===0)return;let C=S?.now??Date.now(),N=S?.ttlMs??3e4;try{mkdirSync(cacheBaseDir(S),{recursive:!0,mode:448});let F=cacheFileFor(t,S),I={otp:n,expiresAt:C+N,registry:normalizeRegistry(t)};writeFileSync(F,JSON.stringify(I),{mode:384}),chmodSync(F,384)}catch{}}function clearCachedOtp(t,n){deleteCacheFile(cacheFileFor(t,n))}function deleteCacheFile(t){try{existsSync(t)&&rmSync(t,{force:!0})}catch{}}var dW,fW,pW=__esmMin(()=>{Rd(),Lg(),Pn(),dW=`GJSIFY_NO_OTP_CACHE`,fW=`gjsify-otp`});async function isOtpChallenge(t){if(t.status!==401)return!1;if((t.headers.get(`www-authenticate`)??``).toLowerCase().includes(`otp`))return!0;let n=await t.clone().text().catch(()=>``);return/one-time pass/i.test(n)||/\bEOTP\b/.test(n)}async function withOtpRetry(t,n,S={}){let C=S.maxPrompts??2,N=S.question,F=n.current(),I=S.seedFirstAttempt===!0&&F!==void 0,H=n.epoch(),W=await t(I?F:void 0);if(!await isOtpChallenge(W))return W;if(I&&n.invalidate(H),!I&&n.current()!==void 0){if(H=n.epoch(),W=await t(n.current()),!await isOtpChallenge(W))return W;n.invalidate(H)}for(let S=0;S<C;S++){let S=await n.refresh(N,H);if(!S||(H=n.epoch(),W=await t(S),!await isOtpChallenge(W)))return W;n.invalidate(H)}return W}var mW,hW,OtpProvider,gW=__esmMin(()=>{uW(),pW(),mW=`This operation requires a one-time password.
1198
+ Enter OTP: `,hW=`The previous one-time password is no longer valid (npm codes last about 30 seconds).
1199
+ Enter a NEW OTP: `,OtpProvider=class{cached;promptFn;registry;generation=0;pending;constructor(t,n=promptLine,S={}){this.promptFn=n,this.registry=S.registry;let C=t&&t.length>0?t:void 0;C?(this.cached=C,this.registry&&writeCachedOtp(this.registry,C)):this.cached=this.registry?readCachedOtp(this.registry):void 0}current(){return this.cached}epoch(){return this.generation}async refresh(t,n){if(n!==void 0&&this.generation>n&&this.cached)return this.cached;if(this.pending)return this.pending;this.pending=this.promptOnce(t??(this.generation>0?hW:mW));try{return await this.pending}finally{this.pending=void 0}}async promptOnce(t){let n=(await this.promptFn(t)).trim();return n&&(this.cached=n,this.generation++,this.registry&&writeCachedOtp(this.registry,n)),n}invalidate(t){t!==void 0&&this.generation!==t||(this.cached=void 0,this.registry&&clearCachedOtp(this.registry))}}});function remainingHoldDeadlineMs(){let t=Number(process.env.GJSIFY_HOLD_DEADLINE);return Number.isFinite(t)&&t>0?Math.max(0,t-Date.now()):1/0}function acceptsRepublish(t,n,S,C){return(t===409||t===403&&/previously published/i.test(n))&&(S||C)}async function publishWorkspace(t){let{wsDir:n,tag:S,access:C,provenance:N,tolerate:F,tolerateUntrustedNew:I,trustedFlag:H,verbose:W,json:q,otpProvider:Y}=t,X=await packWorkspace(n,{dryRun:!0,lifecycleScripts:[`prepublishOnly`,`prepack`],lifecycleStdio:q?`inherit-stderr`:`inherit`}),Z=await packWorkspaceToBytes(n),te=readFileSync(wn(n,`package.json`),`utf-8`),ne=JSON.parse(te),re=await loadRewrittenManifest(n,ne),ie=await loadNpmrc(n),ae=t.registry??process.env.npm_config_registry??registryFor(X.name,ie)??qm,oe=ae.endsWith(`/`)?ae.slice(0,-1):ae,Q=`${oe}/${escapePackageName(X.name)}`,se=`${X.name.includes(`/`)?X.name.slice(X.name.indexOf(`/`)+1):X.name}-${X.version}.tgz`,ce=buildPublishPayload({pkg:re,tag:S,access:C,tarballBytes:Z,tarballUrl:`${oe}/${X.name}/-/${se}`,packed:{...X,wireFilename:se},provenance:N}),le=buildPublishHeaders(Q,{npmrc:ie}),ue=new Set(t.assumePresent??[]),de=collectWorkspacePins(ne,re).filter(t=>!ue.has(t.name));if(de.length>0){let t=await Promise.all(de.map(async t=>({pin:t,presence:await probePackageName({registry:ae,name:t.name,authorization:le.authorization})}))),n=[];for(let{pin:S,presence:C}of t){if(C.state===`present`)continue;let t=`${S.block}.${S.name}@${S.spec}`;if(C.state===`unknown`){ge.error(`gjsify publish: could not establish whether ${S.name} exists (${C.detail}) — not blocking on ${t}`);continue}if(S.block!==`dependencies`){ge.error(`gjsify publish: ${t} names a package ${ae} does not have — npm installs around it, Yarn (\`YN0035\`) does not`);continue}n.push(S)}if(n.length>0)return{ok:I,action:`blocked-missing-dependency`,name:X.name,version:X.version,registry:ae,tolerated:I,missing:n}}let fe=process.env.GJSIFY_PUBLISH_LEDGER;if(de.length>0){let n=await findUnavailablePins({registry:oe,pins:de,ledger:readLedger(fe),ledgerPath:fe,authorization:le.authorization,statusToken:statusTokenFromEnv(process.env),waitBudgetMs:t.holdWaitMs??3e5,log:W?t=>ge.error(t):void 0});for(let t of n.filter(t=>!holdsPublish(t)))ge.error(`gjsify publish: ${t.block}.${t.name}@${t.version} is not served (${t.detail}) — optional edge, publishing anyway`);let S=n.filter(holdsPublish);if(S.length>0)return appendLedger(fe,{ev:`held`,name:X.name,version:X.version,reasons:S}),{ok:!1,action:`held-unpublished-dependency`,name:X.name,version:X.version,registry:oe,reasons:S}}let pe=H===!0||H===void 0&&hasGithubOidcEnv()&&!process.env.NODE_AUTH_TOKEN,me=`token`;if(pe)try{let{token:t,audience:n}=await getNpmTrustedToken({packageName:X.name,registry:ae,log:W?t=>ge.error(t):void 0});le.authorization=`Bearer ${t}`,me=`oidc`,W&&ge.error(`gjsify publish: OIDC token obtained (audience=${n})`)}catch(t){if(t instanceof OidcExchangeError&&t.status===404&&/package not found/i.test(t.body)&&I)return{ok:!0,action:`skipped-untrusted-new`,name:X.name,version:X.version};if(H===!0)return{ok:!1,action:`oidc-failed`,name:X.name,version:X.version,error:t};if(!le.authorization)return{ok:!1,action:`oidc-no-token`,name:X.name,version:X.version,error:t};if(W){let n=t instanceof Error?t.message:String(t);ge.error(`gjsify publish: OIDC auto-detect failed (${n}) — falling back to token auth`)}}W&&(ge.error(`gjsify publish: PUT ${Q} (${X.name}@${X.version})`),ge.error(` auth-mode: ${me}`),ge.error(` authorization: ${le.authorization?`(set)`:`(none)`}`),ge.error(` payload size: ${JSON.stringify(ce).length} bytes`));let he=JSON.stringify(ce),_e=!1,doPut=async n=>{let S={...le};n&&(S[`npm-otp`]=n,S[`npm-auth-type`]=`legacy`);let{response:C,retried:N}=await fetchWithTransientRetry(()=>fetch(Q,{method:`PUT`,headers:S,body:he}),{log:t=>ge.error(`gjsify publish: PUT ${X.name}@${X.version}: ${t}`),...t.putRetry});return N>0&&(_e=!0),C},ve=await withOtpRetry(doPut,Y,{seedFirstAttempt:t.seedOtpFirst});if(W){ge.error(` response: ${ve.status} ${ve.statusText}`);let t=await ve.clone().text().catch(()=>``);t&&ge.error(` body: ${t.slice(0,300)}`)}let readBack=async()=>{let n=t.verifyBudgetMs??6e5;if(!(n<=0))return verifyPublishedVersion({registry:oe,name:X.name,version:X.version,budgetMs:n,authorization:le.authorization,log:W?t=>ge.error(t):void 0})};if(await isOtpChallenge(ve))return{ok:!1,action:`otp-required`,name:X.name,version:X.version,status:ve.status};if(ve.ok){let t=await readBack();return t?.confirmed&&W&&ge.error(` read-back: confirmed after ${t.attempts} probe(s) in ${t.elapsedMs} ms`),t&&!t.confirmed?{ok:!1,action:`publish-unconfirmed`,claim:`accepted`,name:X.name,version:X.version,registry:oe,putStatus:ve.status,putStatusText:ve.statusText,putUrl:Q,payloadBytes:he.length,readback:t,classification:await recordUnserved({ledgerPath:fe,registry:oe,name:X.name,version:X.version,verdict:t.verdict,statusToken:statusTokenFromEnv(process.env)})}:(markHeldPublished(fe,X.name,X.version),{ok:!0,action:`published`,name:X.name,version:X.version,filename:X.filename,size:X.size,integrity:X.integrity,tag:S,registry:oe,readback:t})}let ye=await ve.text().catch(()=>`<no body>`);if(acceptsRepublish(ve.status,ye,F,_e)){let t=await readBack();return t&&!t.confirmed?{ok:!1,action:`publish-unconfirmed`,claim:`already-published`,name:X.name,version:X.version,registry:oe,putStatus:ve.status,putStatusText:ve.statusText,putUrl:Q,payloadBytes:he.length,readback:t,classification:await recordUnserved({ledgerPath:fe,registry:oe,name:X.name,version:X.version,verdict:t.verdict,statusToken:statusTokenFromEnv(process.env)})}:(markHeldPublished(fe,X.name,X.version),{ok:!0,action:`republish-tolerated`,name:X.name,version:X.version,status:ve.status,registry:oe,readback:t})}if(ve.status===404&&me===`token`&&is404DiagnosticCandidate(ye)){let t=await diagnose404({packageName:X.name,version:X.version,registry:oe,npmrc:ie});if(t.reason!==`unknown`)return{ok:!1,action:`diagnostic`,name:X.name,version:X.version,status:404,diag:t}}return{ok:!1,action:`error`,name:X.name,version:X.version,status:ve.status,statusText:ve.statusText,text:ye}}function describeVerification(t,n){if(!t?.confirmed)return{verified:!1,clause:`(UNVERIFIED — read-back disabled by --verify-timeout 0)`,json:null};let S=(t.elapsedMs/1e3).toFixed(1);return{verified:!0,clause:`(verified on ${n} — ${t.attempts} probe(s), ${S}s)`,json:{registry:n,verdict:t.verdict,probes:t.attempts,elapsedMs:t.elapsedMs,tarball:t.last.state===`present`?t.last.tarball:null}}}function warnUnverified(t,n,S){process.env.GITHUB_ACTIONS&&process.stderr.write(`::warning title=Publish unverified::${t}@${n} was published with the read-back disabled (--verify-timeout 0) — nothing confirmed that ${S} serves it\n`)}function reportPublishOutcome(t,n,S=!1){switch(t.action){case`published`:{let S=describeVerification(t.readback,t.registry),C={ok:!0,name:t.name,version:t.version,filename:t.filename,size:t.size,integrity:t.integrity,tag:t.tag,registry:t.registry,verified:S.verified,verification:S.json};n?process.stdout.write(`${JSON.stringify(C,null,2)}\n`):process.stdout.write(`+ ${t.name}@${t.version} ${S.clause}\n`),S.verified||warnUnverified(t.name,t.version,t.registry);return}case`held-unpublished-dependency`:{let C=summariseReasons(t.reasons);return n?process.stdout.write(`${JSON.stringify({ok:!1,action:`held-unpublished-dependency`,name:t.name,version:t.version,registry:t.registry,reasons:t.reasons,deferred:S},null,2)}\n`):process.stderr.write(`~ ${t.name}@${t.version} (HELD — not published: ${C})\n`),process.env.GITHUB_ACTIONS&&process.stderr.write(`::warning title=Package held::${t.name}@${t.version} was NOT published: ${C}\n`),S?void 0:process.exit(1)}case`publish-unconfirmed`:{let C=`${formatUnconfirmedPublish(t)}\n state: ${describeClass(t.classification.cls)} — ${t.classification.detail}`;if(n?process.stdout.write(`${JSON.stringify({ok:!1,action:`publish-unconfirmed`,name:t.name,version:t.version,registry:t.registry,claim:t.claim,putStatus:t.putStatus,probes:t.readback.attempts,elapsedMs:t.readback.elapsedMs,readbackUrl:t.readback.url,readbackState:t.readback.last.state,verdict:t.readback.verdict,verdictDetail:t.readback.verdictDetail,recordedAt:t.readback.recordedAt??null,deferred:S,class:t.classification.cls,classDetail:t.classification.detail},null,2)}\n`):process.stderr.write(`${C}\n`),S){if(process.env.GITHUB_ACTIONS){let n=t.claim===`already-published`?`was reported already published`:`was accepted`;process.stderr.write(`::warning title=Publish unconfirmed::${t.name}@${t.version} ${n} (HTTP ${t.putStatus}) but did not resolve on ${t.registry} within ${(t.readback.elapsedMs/1e3).toFixed(1)}s [${t.readback.verdict}; ${describeClass(t.classification.cls)}] — the release-closure job must confirm it
1200
+ `)}return}return process.exit(1)}case`republish-tolerated`:{let S=describeVerification(t.readback,t.registry),C={ok:!0,action:`republish-tolerated`,name:t.name,version:t.version,status:t.status,registry:t.registry,verified:S.verified,verification:S.json};n?process.stdout.write(`${JSON.stringify(C,null,2)}\n`):process.stdout.write(`= ${t.name}@${t.version} (already published, tolerated) ${S.clause}\n`),S.verified||warnUnverified(t.name,t.version,t.registry);return}case`skipped-untrusted-new`:n?process.stdout.write(`${JSON.stringify({ok:!0,action:`skipped-untrusted-new`,name:t.name,version:t.version,reason:`no-trusted-publisher`},null,2)}\n`):process.stdout.write(`~ ${t.name}@${t.version} (skipped — no Trusted Publisher on npm, see AGENTS.md "New @gjsify/* package: first-publish + Trusted Publisher bootstrap")\n`);return;case`blocked-missing-dependency`:{let S=t.missing.map(t=>`${t.block}.${t.name}@${t.spec}`).join(`, `);return n?process.stdout.write(`${JSON.stringify({ok:t.ok,action:`blocked-missing-dependency`,name:t.name,version:t.version,registry:t.registry,tolerated:t.tolerated,missing:t.missing},null,2)}\n`):process.stdout.write(`~ ${t.name}@${t.version} (NOT published — ${t.missing.length} required pin(s) name a package ${t.registry} does not have: ${S})\n`),ge.error(`gjsify publish: every consumer install of ${t.name} would fail with \`npm error 404\`, on every package manager — a required edge is not skippable. Bootstrap the target first (docs/publishing.md § New \`@gjsify/*\` package), then re-run. See #1713.`),t.tolerated?void 0:process.exit(1)}case`otp-required`:return ge.error("gjsify publish: npm requires a 2FA one-time code — re-run with `--otp <code>`"),process.exit(1);case`oidc-failed`:return handleOidcFailure(t.error,t.name,n),process.exit(1);case`oidc-no-token`:{let S=t.error instanceof Error?t.error.message:String(t.error);return ge.error(`gjsify publish: OIDC token exchange failed for ${t.name} (${S}) and no fallback npm token is configured — refusing to publish without credentials.`),n&&process.stdout.write(`${JSON.stringify({ok:!1,name:t.name,version:t.version,error:`oidc-failed-no-token`},null,2)}\n`),process.exit(1)}case`diagnostic`:return n?process.stdout.write(`${JSON.stringify({ok:!1,name:t.name,version:t.version,status:404,diagnostic:t.diag.reason,username:t.diag.username},null,2)}\n`):process.stderr.write(`${t.diag.message}\n`),process.exit(1);case`error`:return ge.error(`gjsify publish: ${t.name}@${t.version} — ${t.status} ${t.statusText}`),ge.error(t.text),process.exit(1)}}async function packWorkspaceToBytes(t){let n=wn(tmpdir(),`gjsify-publish-${process.pid}-${Date.now()}`),S=await packWorkspace(t,{destination:n,dryRun:!1,lifecycleScripts:[]});if(!S.absolutePath)throw Error(`gjsify publish: pack did not produce a file`);let C=new Uint8Array(readFileSync(S.absolutePath));try{(await Promise.resolve().then(()=>(Rd(),Id))).rmSync(S.absolutePath)}catch{}try{(await Promise.resolve().then(()=>(Rd(),Id))).rmdirSync(n)}catch{}return C}async function loadRewrittenManifest(t,n){let S=wn(tmpdir(),`gjsify-publish-manifest-${process.pid}-${Date.now()}`),C=await packWorkspace(t,{destination:S,dryRun:!1}),{rmSync:N}=await Promise.resolve().then(()=>(Rd(),Id));if(!C.absolutePath)throw Error(`gjsify publish: pack did not produce a file`);let{gunzip:F,parseTar:I}=await Promise.resolve().then(()=>(bL(),yL)),H=new Uint8Array(readFileSync(C.absolutePath));N(S,{recursive:!0,force:!0,maxRetries:3,retryDelay:100});let W=await F(H);for(let t of I(W))if(t.name===`package/package.json`&&t.body)return JSON.parse(new TextDecoder().decode(t.body));return n}function buildPublishPayload(t){let{pkg:n,tag:S,access:C,tarballBytes:N,tarballUrl:F,packed:I,provenance:H}=t,W={...n,_id:`${I.name}@${I.version}`,dist:{integrity:I.integrity,shasum:I.shasum,tarball:F}};H&&(W._hasShrinkwrap=!1);let q={_id:I.name,name:I.name,description:typeof n.description==`string`?n.description:``,"dist-tags":{[S]:I.version},versions:{[I.version]:W},readme:``,_attachments:{[I.wireFilename]:{content_type:`application/octet-stream`,data:base64Encode(N),length:N.byteLength}}};return C&&(q.access=C),q}function handleOidcFailure(t,n,S){if(t instanceof OidcUnavailableError){let C=`gjsify publish: OIDC not available — ${t.message}`;S?process.stdout.write(`${JSON.stringify({ok:!1,name:n,error:`oidc-unavailable`,reason:t.reason,message:t.message})}\n`):process.stderr.write(`${C}\n`);return}if(t instanceof OidcExchangeError){let C=t.status===401||t.status===403?`npm rejected the OIDC exchange (${t.status}) — check that ${n} has a Trusted Publisher configured at https://www.npmjs.com/package/${encodeURIComponent(n)}/access pointing at this workflow.`:t.message;if(S)process.stdout.write(`${JSON.stringify({ok:!1,name:n,error:`oidc-exchange`,status:t.status,body:t.body,claims:t.claims,message:t.message})}\n`);else if(process.stderr.write(`✗ ${n}: ${C}\n`),t.body&&process.stderr.write(` ↳ npm said: ${t.body.slice(0,300)}\n`),t.claims){let n=t.claims,S=[`aud`,`iss`,`repository`,`repository_owner`,`workflow_ref`,`job_workflow_ref`,`ref`,`environment`,`sub`].filter(t=>n[t]!==void 0).map(t=>`${t}=${JSON.stringify(n[t])}`).join(`, `);S&&process.stderr.write(` ↳ JWT claims npm received: ${S}\n`)}return}let C=t instanceof Error?t.message:String(t);S?process.stdout.write(`${JSON.stringify({ok:!1,name:n,error:`unknown`,message:C})}\n`):process.stderr.write(`✗ ${n}: ${C}\n`)}var _W,vW=__esmMin(()=>{_e(),Rd(),Lg(),Pn(),qH(),eh(),nh(),zU(),UU(),WU(),YU(),QU(),rW(),eW(),VR(),gW(),uW(),HU(),_W={command:`publish [path]`,description:"Pack + upload the workspace at <path> (default: cwd) to its npm registry. Drop-in for `npm publish` with workspace:^ rewrite handled automatically.",builder:t=>t.positional(`path`,{description:`Workspace path (default: cwd).`,type:`string`}).option(`tag`,{description:`Dist-tag to publish under. Default: latest.`,type:`string`,default:`latest`}).option(`access`,{description:"Package access — `public` or `restricted` (required for first publish of scoped packages on the public registry).",type:`string`}).option(`otp`,{description:"npm 2FA one-time code; sent as the `npm-otp` header. Required for manual publishes from a 2FA-enabled account.",type:`string`}).option(`tolerate-republish`,{description:'Treat "version already published" as success — covers both classic 409 Conflict and the npm OIDC-path 403 Forbidden + `"previously published"` body shape. Matches yarn `--tolerate-republish`.',type:`boolean`,default:!1}).option(`tolerate-untrusted-new`,{description:'Skip (exit 0) when OIDC token exchange returns `package not found` AND no fallback token is configured — i.e. a never-before-published `@scope/<name>` whose Trusted Publisher entry hasn\'t been set up on npmjs.com yet. Without this flag, one un-bootstrapped new package breaks the entire serialized `gjsify foreach publish` loop. Pair with `--tolerate-republish` in CI release workflows so a fresh-merged package gracefully skips its first CI publish, leaving the manual-bootstrap step to a maintainer (see AGENTS.md "New @gjsify/* package: first-publish + Trusted Publisher bootstrap").',type:`boolean`,default:!1}).option(`verify-timeout`,{description:"Seconds to keep asking the registry for the just-published version before giving up. npm answers 2xx to a write it has only ACCEPTED: in the v0.46.0 release 19 of 199 packages were recorded 56-252s after their 2xx and one was never recorded at all, so a shorter window turns normal queueing into a false red. `0` disables the read-back — for a registry with no packument read path; the success line then reads `UNVERIFIED` and says so, because a publish nothing checked must never look like one that was checked.",type:`number`,default:qU/1e3}).option(`verify-defer`,{description:"Report an unconfirmed read-back and exit 0 instead of 1. ONLY for a caller that re-checks the same set afterwards — `gjsify run npm:publish` passes it because `scripts/verify-published-closure.mjs` sweeps the whole roster at the end of release.yml. Everywhere else an unconfirmed publish must fail the job that made it.",type:`boolean`,default:!1}).option(`hold-timeout`,{description:'Seconds to wait for an intra-repo dependency pin whose exact version the registry does not serve (yet) before HOLDING this package instead of publishing it. A version npm accepted but never serves (status "validating") would make every dependent uninstallable; the write lag measured on v0.46.0 reaches 252s, hence the default. `0` probes once and holds without waiting. A hold exits 1, or 0 under `--verify-defer`.',type:`number`,default:tW/1e3}).option(`report-ledger`,{description:"Print the job-summary markdown for the publish ledger named by $GJSIFY_PUBLISH_LEDGER (versions npm accepted but does not serve, packages held because of them, the recovery command) and exit. Pair with `--ref <tag>`.",type:`boolean`,default:!1}).option(`fail-on-unsettled`,{description:`With --report-ledger: exit 1 when any package is still HELD or any accepted version is still unserved, naming them and the recovery command. The end-of-sweep gate: a sweep that left something behind must be red, not a warning.`,type:`boolean`,default:!1}).option(`held-names`,{description:`Print, one per line, the packages the ledger shows HELD and not yet published, and exit. Feeds the held-package second pass (.github/scripts/retry-held-publish.sh).`,type:`boolean`,default:!1}).option(`settle-ledger`,{description:`Wait up to --settle-timeout for every version the ledger records as accepted-but-unserved to be served (the longer read-back the sweep defers), record each as served, and exit.`,type:`boolean`,default:!1}).option(`settle-timeout`,{description:`With --settle-ledger: seconds to wait. Versions poll concurrently, so this is the longest lag tolerated, not a sum. Default 600 (the fatal read-back default; measured lags reach 368 s).`,type:`number`,default:qU/1e3}).option(`ref`,{description:`With --report-ledger: the git ref to put in the printed recovery command.`,type:`string`}).option(`provenance`,{description:`Pass-through flag — recorded in the payload but no signing happens (gjsify doesn't ship a sigstore signer yet).`,type:`boolean`,default:!1}).option(`dry-run`,{description:`Pack only, do not PUT.`,type:`boolean`,default:!1}).option(`json`,{description:`Emit publish metadata as JSON on stdout.`,type:`boolean`,default:!1}).option(`trusted`,{description:"Authenticate via npm Trusted Publishing (OIDC): exchange the GitHub Actions id-token for a short-lived npm token. Pass `--trusted` to force this mode (errors if env vars missing). Omit to auto-detect: OIDC is used iff `ACTIONS_ID_TOKEN_REQUEST_URL`+`_TOKEN` are set AND no `_authToken` is present in the resolved npmrc; otherwise the long-lived token path is used. Requires the calling workflow to declare `permissions: id-token: write` AND the target package to have a Trusted Publisher configured on npmjs.com.",type:`boolean`,default:void 0}).option(`check-trusted`,{description:"Diagnostic mode: perform the OIDC id-token request + npm token exchange, report success/failure, then exit WITHOUT publishing. Useful as a bulk-verifier (e.g. via `gjsify foreach publish --check-trusted`) to confirm Trusted Publisher config across many packages.",type:`boolean`,default:!1}),handler:async t=>{let n=xn(t.path??process.cwd()),S=t.tag??`latest`,C=t.access,N=t.otp,F=t[`tolerate-republish`]===!0,I=t[`tolerate-untrusted-new`]===!0,H=t[`verify-timeout`]??6e5/1e3;if(!Number.isFinite(H)||H<0)return ge.error(`gjsify publish: --verify-timeout must be a non-negative number of seconds, got ${JSON.stringify(t[`verify-timeout`])}`),process.exit(2);let W=Math.round(H*1e3),q=t[`verify-defer`]===!0,Y=t.provenance===!0,X=t[`dry-run`]===!0,Z=t[`check-trusted`]===!0,te=t.trusted,ne=!!process.env.GJSIFY_PUBLISH_DEBUG,re=process.env.GJSIFY_PUBLISH_LEDGER;if(t[`held-names`]===!0){for(let t of pendingEntries(readLedger(re)).held)process.stdout.write(`${t.name}\n`);return}if(t[`settle-ledger`]===!0){let n=t[`settle-timeout`]??6e5/1e3;if(!Number.isFinite(n)||n<0)return ge.error(`gjsify publish: --settle-timeout must be a non-negative number of seconds, got ${JSON.stringify(t[`settle-timeout`])}`),process.exit(2);let S=await loadNpmrc(process.cwd()),C=await settleUnserved({entries:readLedger(re),ledgerPath:re,registryFor:t=>(process.env.npm_config_registry??registryFor(t,S)??qm).replace(/\/$/,``),budgetMs:Math.max(1,Math.round(n*1e3)),log:ne?t=>ge.error(t):void 0});for(let t of C)process.stdout.write(`served after settling: ${t}\n`);return}if(t[`report-ledger`]===!0){let n=readLedger(re),S=renderLedgerSummary(n,t.ref??`<tag>`);if(S&&process.stdout.write(`${S}\n`),t[`fail-on-unsettled`]===!0){let{unserved:S,held:C}=pendingEntries(n),N=[...new Set([...C,...S].map(t=>t.name))];if(N.length>0){let n=t.ref??`<tag>`;return ge.error(`gjsify publish: ${C.length} package(s) still HELD and ${S.length} version(s) still unserved after the second pass: ${N.join(` `)}\n recover: re-run THIS run (\`gh run rerun <run-id>\` — keeps the version; never a new dispatch on the next channel, which mints a new one), or for a release: gh workflow run release.yml --ref ${n} -f skip_publish=false -f only='${N.join(` `)}'`),process.exit(1)}}return}let ie=t[`hold-timeout`]??3e5/1e3;if(!Number.isFinite(ie)||ie<0)return ge.error(`gjsify publish: --hold-timeout must be a non-negative number of seconds, got ${JSON.stringify(t[`hold-timeout`])}`),process.exit(2);if(Y&&ge.warn(`gjsify publish: --provenance recorded but not signed (no sigstore integration yet).`),Z){let S=wn(n,`package.json`),C=JSON.parse(readFileSync(S,`utf-8`));if(typeof C.name!=`string`)return process.stderr.write(`gjsify publish --check-trusted: ${S} has no \`name\` field\n`),process.exit(2);if(C.private===!0){let n={ok:!0,action:`check-trusted`,name:C.name,skipped:`private`};t.json?process.stdout.write(`${JSON.stringify(n)}\n`):process.stdout.write(`- ${C.name}: skipped (private package)\n`);return}let N=await loadNpmrc(n),F=process.env.npm_config_registry??registryFor(C.name,N)??qm;try{await getNpmTrustedToken({packageName:C.name,registry:F,log:ne?t=>ge.error(t):void 0});let n={ok:!0,action:`check-trusted`,name:C.name,registry:F};t.json?process.stdout.write(`${JSON.stringify(n)}\n`):process.stdout.write(`✓ ${C.name}: trusted publisher OK\n`);return}catch(n){handleOidcFailure(n,C.name,t.json===!0);return}}if(X){let S=await packWorkspace(n,{dryRun:!0,lifecycleScripts:[`prepublishOnly`,`prepack`],lifecycleStdio:t.json?`inherit-stderr`:`inherit`}),C={ok:!0,action:`dry-run`,name:S.name,version:S.version,filename:S.filename,size:S.size,shasum:S.shasum,integrity:S.integrity};t.json?process.stdout.write(`${JSON.stringify(C,null,2)}\n`):process.stdout.write(`+ ${S.name}@${S.version} (dry-run, ${S.size} bytes, ${S.entryCount} files)\n`);return}let ae=!!(process.stdin.isTTY&&process.stdout.isTTY),oe=await loadNpmrc(n),Q;try{Q=JSON.parse(readFileSync(wn(n,`package.json`),`utf-8`)).name}catch{}let se=process.env.npm_config_registry??(Q?registryFor(Q,oe):void 0)??oe.registry??qm,ce=new OtpProvider(N,ae?promptLine:async()=>``,{registry:se});reportPublishOutcome(await publishWorkspace({wsDir:n,tag:S,access:C,provenance:Y,tolerate:F,tolerateUntrustedNew:I,trustedFlag:te,verbose:ne,json:t.json===!0,otpProvider:ce,seedOtpFirst:N!==void 0,verifyBudgetMs:W,holdWaitMs:Math.min(Math.round(ie*1e3),remainingHoldDeadlineMs())}),t.json===!0,q)}}}),yW,bW=__esmMin(()=>{eh(),VR(),yW={command:`whoami`,description:`Print the npm-registry username for the current ~/.npmrc token. Clear failure message when the token is dead, missing, or the registry is unreachable.`,builder:t=>t.option(`registry`,{description:`Registry URL to probe. Default: scope-aware lookup from .npmrc (falls back to ${qm}).`,type:`string`}).option(`json`,{description:"Emit `{username, registry}` (or `{error, registry}`) as a single-line JSON object.",type:`boolean`,default:!1}),handler:async t=>{let n=await loadNpmrc(process.cwd()),S=t.registry??process.env.npm_config_registry??n.registry??qm,C=S.endsWith(`/`)?S.slice(0,-1):S,N=t.json===!0;if(!hasAnyCredential(n))return N?process.stdout.write(`${JSON.stringify({error:`no-token-configured`,registry:C})}\n`):process.stderr.write([`gjsify whoami: no npm token configured.`,``,`No \`_authToken\` found in ~/.npmrc / $NPM_CONFIG_USERCONFIG / .npmrc for ${C}.`,``,`Add one via: npm login`,`Then verify: gjsify whoami`].join(`
1201
1201
  `)+`
1202
1202
  `),process.exit(1);let F;try{F=await whoami(S,n)}catch(t){let n=t instanceof Error?t.message:String(t);return N?process.stdout.write(`${JSON.stringify({error:n,registry:C})}\n`):(process.stderr.write(`gjsify whoami: ${n}\n`),process.stderr.write(`Registry: ${C}\n`)),process.exit(1)}if(F.username&&F.username.length>0){N?process.stdout.write(`${JSON.stringify({username:F.username,registry:C})}\n`):(process.stdout.write(`Logged in as: ${F.username}\n`),process.stdout.write(`Registry: ${C}\n`));return}N?process.stdout.write(`${JSON.stringify({error:`dead-token`,registry:C})}\n`):process.stderr.write([`gjsify whoami: token appears dead or revoked (registry returned an empty whoami response).`,``,`Refresh via: npm login`,`Then verify: gjsify whoami`,``,`For the @gjsify scope, see AGENTS.md > "New @gjsify/* package: first-publish + Trusted Publisher bootstrap".`].join(`
1203
1203
  `)+`
@@ -1206,12 +1206,12 @@ Enter a NEW OTP: `,OtpProvider=class{cached;promptFn;registry;generation=0;pendi
1206
1206
  `)+`
1207
1207
  `),S}function removeAuthToken(t){let n=userconfigNpmrcPath(),S=authTokenKey(t),C=readUserconfig(n);if(!C)return{path:n,removed:!1};let N=C.split(`
1208
1208
  `),F=N.filter(t=>!t.replace(/\s+/g,``).startsWith(`${S}=`)),I=F.length!==N.length;return I&&writeUserconfig(n,F.join(`
1209
- `)),{path:n,removed:I}}var mW=__esmMin(()=>{Rd(),Lg(),Pn()});async function runLogin(t){let n=await loadNpmrc(t.cwd??process.cwd()),S=t.registry??process.env.npm_config_registry??(t.scope?registryFor(t.scope.startsWith(`@`)?`${t.scope}/_`:`@${t.scope}/_`,n):void 0)??qm,C=S.endsWith(`/`)?S:`${S}/`,{username:N,password:F}=await promptCredentials(t.username);if(!N)throw new LoginError(`gjsify login: a username is required.`);if(!F)throw new LoginError(`gjsify login: a password is required.`);let I=`Basic ${btoa(`${N}:${F}`)}`,H=`${C}-/user/org.couchdb.user:${encodeURIComponent(N)}`,W={_id:`org.couchdb.user:${N}`,name:N,password:F,type:`user`,roles:[],date:void 0};function authHeaders(t){let n={authorization:I,"content-type":`application/json`,accept:`*/*`};return t&&(n[`npm-otp`]=t),n}async function putUser(t,n){return fetch(`${H}${t}`,{method:`PUT`,headers:authHeaders(n),body:JSON.stringify(W)})}let q=typeof t.otp==`string`&&t.otp.length>0,Y=t.otp??readCachedOtp(C),X=await putUser(``,Y);if(X.status===401&&!q){let t=(X.headers.get(`www-authenticate`)??``).toLowerCase(),n=await X.clone().text().catch(()=>``);if(t.includes(`otp`)||/one-time pass/i.test(n)){if(clearCachedOtp(C),Y=await promptLine(`This operation requires a one-time password.
1210
- Enter OTP: `),!Y)throw new LoginError(`gjsify login: no OTP entered.`);writeCachedOtp(C,Y),X=await putUser(``,Y)}}if(X.status===409){let t=await fetch(`${H}?write=true`,{headers:authHeaders(Y)});if(t.ok){let n=await t.json().catch(()=>({}));for(let t of Object.keys(n))(!W[t]||t===`roles`)&&(W[t]=n[t]);W._rev&&(X=await putUser(`/-rev/${W._rev}`,Y))}}if(X.status===400)throw new LoginError(`gjsify login: there is no user with the username "${N}" on ${C}.`);if(!X.ok){let t=await X.text().catch(()=>`<no body>`);throw new LoginError(`gjsify login: ${X.status} ${X.statusText} from ${C}\n${t.slice(0,400)}`)}let Z=await X.json().catch(()=>({}));if(!Z.token)throw new LoginError("gjsify login: the registry accepted the login but returned no token (unexpected response shape). Your registry may require the web-OAuth flow — use `npm login`.");let te=writeAuthToken(C,Z.token);return Y&&writeCachedOtp(C,Y),{username:(await whoami(C,await loadNpmrc(t.cwd??process.cwd()))).username??N,registry:C,npmrcPath:te}}var LoginError,hW,gW=__esmMin(()=>{_e(),eh(),IR(),mW(),rW(),oW(),LoginError=class extends Error{constructor(t){super(t),this.name=`LoginError`}},hW={command:`login`,description:"Log in to an npm registry (Node-free `npm login`). Prompts for username + password (hidden) and writes the token to ~/.npmrc. Use --otp for 2FA. Web-OAuth flow is not supported — this is npm's legacy credentials flow.",builder:t=>t.option(`registry`,{description:`Registry URL to log in to. Default: ${qm} (or a --scope's registry).`,type:`string`}).option(`scope`,{description:`Associate the login with a scope (e.g. @gjsify) — resolves that scope's registry from .npmrc.`,type:`string`}).option(`username`,{description:`Username (prompted if omitted).`,type:`string`}).option(`otp`,{description:`npm 2FA one-time code (prompted on demand if omitted).`,type:`string`}).option(`json`,{description:"Emit `{username, registry}` JSON on success.",type:`boolean`}),handler:async t=>{try{let{username:n,registry:S,npmrcPath:C}=await runLogin({registry:t.registry,scope:t.scope,username:t.username,otp:t.otp});t.json?process.stdout.write(`${JSON.stringify({username:n,registry:S})}\n`):process.stdout.write(`Logged in as ${n} on ${S}\n(token written to ${C})\n`)}catch(t){if(t instanceof LoginError)return ge.error(t.message),process.exit(1);throw t}}}}),_W,vW=__esmMin(()=>{eh(),IR(),mW(),oW(),_W={command:`logout`,description:"Log out of an npm registry (Node-free `npm logout`). Revokes the token on the registry (best-effort) and removes it from ~/.npmrc.",builder:t=>t.option(`registry`,{description:`Registry URL to log out of. Default: ${qm} (or a --scope's registry).`,type:`string`}).option(`scope`,{description:`Log out of a scope's registry (e.g. @gjsify) — resolved from .npmrc.`,type:`string`}).option(`json`,{description:"Emit `{registry, revoked, removed}` JSON.",type:`boolean`}),handler:async t=>{let n=await loadNpmrc(process.cwd()),S=t.registry??process.env.npm_config_registry??(t.scope?registryFor(t.scope.startsWith(`@`)?`${t.scope}/_`:`@${t.scope}/_`,n):void 0)??qm,C=S.endsWith(`/`)?S:`${S}/`,N=resolveAuthForUrl(`${C}-/whoami`,n),F=!1;if(N?.startsWith(`Bearer `)){let t=N.slice(7);try{F=(await fetch(`${C}-/user/token/${encodeURIComponent(t)}`,{method:`DELETE`,headers:{authorization:N,accept:`*/*`}})).ok}catch{}}clearCachedOtp(C);let{path:I,removed:H}=removeAuthToken(C);t.json?process.stdout.write(`${JSON.stringify({registry:C,revoked:F,removed:H})}\n`):H?process.stdout.write(`Logged out of ${C}${F?` (token revoked)`:``}\n(removed from ${I})\n`):process.stdout.write(`No token for ${C} found in ${I} — nothing to remove.\n`)}}});function discoverNonWorkspacePublishables(t){let n=t,S=yW[0];for(let t=0;t<8&&!existsSync(wn(n,...S));t++){let t=En(n);if(t===n)return[];n=t}let C=[];for(let t of yW){let S=wn(n,...t);if(!existsSync(S))continue;let N;try{N=readdirSync(S,{withFileTypes:!0})}catch{continue}for(let n of N){if(!n.isDirectory())continue;let N=wn(S,n.name),F=wn(N,`package.json`);if(existsSync(F))try{let S=JSON.parse(readFileSync(F,`utf8`));if(!S||typeof S.name!=`string`||S.name.length===0)continue;C.push({location:N,relativeLocation:wn(...t,n.name),name:S.name,version:typeof S.version==`string`?S.version:`0.0.0`,manifest:S,private:S.private===!0})}catch{}}}return C}function mergePublishables(t,n){let S=new Set(t.map(t=>t.name));return[...t,...discoverNonWorkspacePublishables(n).filter(t=>!S.has(t.name))]}var yW,bW=__esmMin(()=>{Rd(),Pn(),yW=[[`packages`,`node-gi`],[`packages`,`napi`],[`packages`,`node-runtime`]]});function trustUrl(t,n){return`${t.endsWith(`/`)?t.slice(0,-1):t}/-/package/${escapePackageName(n)}/trust`}function githubTrustBody(t){let n={repository:t.repository,workflow_ref:{file:normalizeWorkflowFile(t.workflow)}};return t.environment&&(n.environment=t.environment),[{type:`github`,claims:n,permissions:t.permissions&&t.permissions.length>0?t.permissions:[xW]}]}function normalizeWorkflowFile(t){return t.split(`/`).pop()??t}function validateRepository(t){let n=t.split(`/`);return n.length===2&&n[0].length>0&&n[1].length>0}function matchesGithubTrust(t,n){if(t.type!==`github`)return!1;let S=t.claims?.repository,C=t.claims?.workflow_ref?.file;return S===n.repository&&C===normalizeWorkflowFile(n.workflow)}function classifyTrustList(t,n,S){return t===404?`unpublished`:t===401?`auth-required`:t>=200&&t<300?(Array.isArray(n)?n:[]).some(t=>matchesGithubTrust(t,S))?`trusted`:`untrusted`:`error`}function parseRepoFromGitRemote(t){let n=t.trim();if(!n)return null;n=n.replace(/^git\+/,``),n=n.replace(/\.git$/,``);let S=n.match(/^[^/@]+@[^:]+:(.+)$/);if(S)return twoSegments(S[1]);let C=n.match(/^[a-z]+:\/\/[^/]+\/(.+)$/i);return C?twoSegments(C[1]):null}function twoSegments(t){let n=t.split(`/`).filter(t=>t.length>0);return n.length<2?null:`${n[n.length-2]}/${n[n.length-1]}`}var xW,SW=__esmMin(()=>{nh(),xW=`createPackage`});function createTrustRequester(t){return async(n,S,C)=>{let doFetch=N=>{let F=buildHeaders(S,{npmrc:t.npmrc});F.accept=`application/json`,C!==void 0&&(F[`content-type`]=`application/json`),N&&(F[`npm-otp`]=N);let I={method:n,headers:F};return C!==void 0&&(I.body=JSON.stringify(C)),fetch(S,I)},N=await withOtpRetry(doFetch,t.otpProvider),F=await N.text().catch(()=>``),I;try{I=F?JSON.parse(F):void 0}catch{}return{status:N.status,json:I,text:F,headers:N.headers}}}function firstLine(t){return t.split(`
1211
- `)[0].slice(0,200)}var CW,wW=__esmMin(()=>{_e(),P_(),Rd(),Pn(),eh(),QP(),bW(),IR(),lW(),SW(),CW={command:`trust [packages..]`,description:"Configure npm Trusted Publishers (OIDC/GitHub Actions) for publishable workspace packages so release.yml can publish without a token. Native — no `npm` needed. Incremental: skips already-configured packages.",builder:t=>t.positional(`packages`,{description:`Optional package-name globs to limit the sweep (default: all publishable workspaces).`,type:`string`,array:!0}).option(`repository`,{description:"GitHub repo as `owner/repo`. Default: inferred from the `origin` git remote.",type:`string`}).option(`workflow`,{description:`Workflow filename allowed to publish (basename only).`,type:`string`,default:`release.yml`}).option(`environment`,{description:`Optional GitHub Actions environment the workflow must run in.`,type:`string`}).option(`registry`,{description:`Registry override. Default: scope-aware lookup from .npmrc (falls back to ${qm}).`,type:`string`}).option(`otp`,{description:"npm 2FA one-time code; sent as `npm-otp`. Prompted on demand if omitted.",type:`string`}).option(`dry-run`,{description:`List what would be configured without writing anything.`,type:`boolean`,default:!1}).option(`force`,{description:`Re-POST the config even for packages already trusted for this repo+workflow.`,type:`boolean`,default:!1}).option(`list`,{description:`Only report each package’s current trust state; configure nothing.`,type:`boolean`,default:!1}).option(`private`,{description:`Include private workspaces (default false — private packages are not publishable).`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=await loadNpmrc(n);if(!hasAnyCredential(S))return ge.error("gjsify trust: no npm token configured. Run `gjsify login` first."),process.exit(1);let C=t.registry??process.env.npm_config_registry??S.registry??qm;if(t[`dry-run`]!==!0){let t;try{t=await whoami(C,S)}catch(t){let n=t instanceof Error?t.message:String(t);return ge.error(`gjsify trust: npm auth check failed (${n}).\nYour ~/.npmrc token is dead or revoked — refresh it with \`npm login\`, then re-run.
1209
+ `)),{path:n,removed:I}}var xW=__esmMin(()=>{Rd(),Lg(),Pn()});async function runLogin(t){let n=await loadNpmrc(t.cwd??process.cwd()),S=t.registry??process.env.npm_config_registry??(t.scope?registryFor(t.scope.startsWith(`@`)?`${t.scope}/_`:`@${t.scope}/_`,n):void 0)??qm,C=S.endsWith(`/`)?S:`${S}/`,{username:N,password:F}=await promptCredentials(t.username);if(!N)throw new LoginError(`gjsify login: a username is required.`);if(!F)throw new LoginError(`gjsify login: a password is required.`);let I=`Basic ${btoa(`${N}:${F}`)}`,H=`${C}-/user/org.couchdb.user:${encodeURIComponent(N)}`,W={_id:`org.couchdb.user:${N}`,name:N,password:F,type:`user`,roles:[],date:void 0};function authHeaders(t){let n={authorization:I,"content-type":`application/json`,accept:`*/*`};return t&&(n[`npm-otp`]=t),n}async function putUser(t,n){return fetch(`${H}${t}`,{method:`PUT`,headers:authHeaders(n),body:JSON.stringify(W)})}let q=typeof t.otp==`string`&&t.otp.length>0,Y=t.otp??readCachedOtp(C),X=await putUser(``,Y);if(X.status===401&&!q){let t=(X.headers.get(`www-authenticate`)??``).toLowerCase(),n=await X.clone().text().catch(()=>``);if(t.includes(`otp`)||/one-time pass/i.test(n)){if(clearCachedOtp(C),Y=await promptLine(`This operation requires a one-time password.
1210
+ Enter OTP: `),!Y)throw new LoginError(`gjsify login: no OTP entered.`);writeCachedOtp(C,Y),X=await putUser(``,Y)}}if(X.status===409){let t=await fetch(`${H}?write=true`,{headers:authHeaders(Y)});if(t.ok){let n=await t.json().catch(()=>({}));for(let t of Object.keys(n))(!W[t]||t===`roles`)&&(W[t]=n[t]);W._rev&&(X=await putUser(`/-rev/${W._rev}`,Y))}}if(X.status===400)throw new LoginError(`gjsify login: there is no user with the username "${N}" on ${C}.`);if(!X.ok){let t=await X.text().catch(()=>`<no body>`);throw new LoginError(`gjsify login: ${X.status} ${X.statusText} from ${C}\n${t.slice(0,400)}`)}let Z=await X.json().catch(()=>({}));if(!Z.token)throw new LoginError("gjsify login: the registry accepted the login but returned no token (unexpected response shape). Your registry may require the web-OAuth flow — use `npm login`.");let te=writeAuthToken(C,Z.token);return Y&&writeCachedOtp(C,Y),{username:(await whoami(C,await loadNpmrc(t.cwd??process.cwd()))).username??N,registry:C,npmrcPath:te}}var LoginError,SW,CW=__esmMin(()=>{_e(),eh(),VR(),xW(),uW(),pW(),LoginError=class extends Error{constructor(t){super(t),this.name=`LoginError`}},SW={command:`login`,description:"Log in to an npm registry (Node-free `npm login`). Prompts for username + password (hidden) and writes the token to ~/.npmrc. Use --otp for 2FA. Web-OAuth flow is not supported — this is npm's legacy credentials flow.",builder:t=>t.option(`registry`,{description:`Registry URL to log in to. Default: ${qm} (or a --scope's registry).`,type:`string`}).option(`scope`,{description:`Associate the login with a scope (e.g. @gjsify) — resolves that scope's registry from .npmrc.`,type:`string`}).option(`username`,{description:`Username (prompted if omitted).`,type:`string`}).option(`otp`,{description:`npm 2FA one-time code (prompted on demand if omitted).`,type:`string`}).option(`json`,{description:"Emit `{username, registry}` JSON on success.",type:`boolean`}),handler:async t=>{try{let{username:n,registry:S,npmrcPath:C}=await runLogin({registry:t.registry,scope:t.scope,username:t.username,otp:t.otp});t.json?process.stdout.write(`${JSON.stringify({username:n,registry:S})}\n`):process.stdout.write(`Logged in as ${n} on ${S}\n(token written to ${C})\n`)}catch(t){if(t instanceof LoginError)return ge.error(t.message),process.exit(1);throw t}}}}),wW,TW=__esmMin(()=>{eh(),VR(),xW(),pW(),wW={command:`logout`,description:"Log out of an npm registry (Node-free `npm logout`). Revokes the token on the registry (best-effort) and removes it from ~/.npmrc.",builder:t=>t.option(`registry`,{description:`Registry URL to log out of. Default: ${qm} (or a --scope's registry).`,type:`string`}).option(`scope`,{description:`Log out of a scope's registry (e.g. @gjsify) — resolved from .npmrc.`,type:`string`}).option(`json`,{description:"Emit `{registry, revoked, removed}` JSON.",type:`boolean`}),handler:async t=>{let n=await loadNpmrc(process.cwd()),S=t.registry??process.env.npm_config_registry??(t.scope?registryFor(t.scope.startsWith(`@`)?`${t.scope}/_`:`@${t.scope}/_`,n):void 0)??qm,C=S.endsWith(`/`)?S:`${S}/`,N=resolveAuthForUrl(`${C}-/whoami`,n),F=!1;if(N?.startsWith(`Bearer `)){let t=N.slice(7);try{F=(await fetch(`${C}-/user/token/${encodeURIComponent(t)}`,{method:`DELETE`,headers:{authorization:N,accept:`*/*`}})).ok}catch{}}clearCachedOtp(C);let{path:I,removed:H}=removeAuthToken(C);t.json?process.stdout.write(`${JSON.stringify({registry:C,revoked:F,removed:H})}\n`):H?process.stdout.write(`Logged out of ${C}${F?` (token revoked)`:``}\n(removed from ${I})\n`):process.stdout.write(`No token for ${C} found in ${I} — nothing to remove.\n`)}}});function discoverNonWorkspacePublishables(t){let n=t,S=EW[0];for(let t=0;t<8&&!existsSync(wn(n,...S));t++){let t=En(n);if(t===n)return[];n=t}let C=[];for(let t of EW){let S=wn(n,...t);if(!existsSync(S))continue;let N;try{N=readdirSync(S,{withFileTypes:!0})}catch{continue}for(let n of N){if(!n.isDirectory())continue;let N=wn(S,n.name),F=wn(N,`package.json`);if(existsSync(F))try{let S=JSON.parse(readFileSync(F,`utf8`));if(!S||typeof S.name!=`string`||S.name.length===0)continue;C.push({location:N,relativeLocation:wn(...t,n.name),name:S.name,version:typeof S.version==`string`?S.version:`0.0.0`,manifest:S,private:S.private===!0})}catch{}}}return C}function mergePublishables(t,n){let S=new Set(t.map(t=>t.name));return[...t,...discoverNonWorkspacePublishables(n).filter(t=>!S.has(t.name))]}var EW,DW=__esmMin(()=>{Rd(),Pn(),EW=[[`packages`,`node-gi`],[`packages`,`napi`],[`packages`,`node-runtime`]]});function trustUrl(t,n){return`${t.endsWith(`/`)?t.slice(0,-1):t}/-/package/${escapePackageName(n)}/trust`}function githubTrustBody(t){let n={repository:t.repository,workflow_ref:{file:normalizeWorkflowFile(t.workflow)}};return t.environment&&(n.environment=t.environment),[{type:`github`,claims:n,permissions:t.permissions&&t.permissions.length>0?t.permissions:[OW]}]}function normalizeWorkflowFile(t){return t.split(`/`).pop()??t}function validateRepository(t){let n=t.split(`/`);return n.length===2&&n[0].length>0&&n[1].length>0}function matchesGithubTrust(t,n){if(t.type!==`github`)return!1;let S=t.claims?.repository,C=t.claims?.workflow_ref?.file;return S===n.repository&&C===normalizeWorkflowFile(n.workflow)}function classifyTrustList(t,n,S){return t===404?`unpublished`:t===401?`auth-required`:t>=200&&t<300?(Array.isArray(n)?n:[]).some(t=>matchesGithubTrust(t,S))?`trusted`:`untrusted`:`error`}function parseRepoFromGitRemote(t){let n=t.trim();if(!n)return null;n=n.replace(/^git\+/,``),n=n.replace(/\.git$/,``);let S=n.match(/^[^/@]+@[^:]+:(.+)$/);if(S)return twoSegments(S[1]);let C=n.match(/^[a-z]+:\/\/[^/]+\/(.+)$/i);return C?twoSegments(C[1]):null}function twoSegments(t){let n=t.split(`/`).filter(t=>t.length>0);return n.length<2?null:`${n[n.length-2]}/${n[n.length-1]}`}var OW,kW=__esmMin(()=>{nh(),OW=`createPackage`});function createTrustRequester(t){return async(n,S,C)=>{let doFetch=N=>{let F=buildHeaders(S,{npmrc:t.npmrc});F.accept=`application/json`,C!==void 0&&(F[`content-type`]=`application/json`),N&&(F[`npm-otp`]=N);let I={method:n,headers:F};return C!==void 0&&(I.body=JSON.stringify(C)),fetch(S,I)},N=await withOtpRetry(doFetch,t.otpProvider),F=await N.text().catch(()=>``),I;try{I=F?JSON.parse(F):void 0}catch{}return{status:N.status,json:I,text:F,headers:N.headers}}}function firstLine(t){return t.split(`
1211
+ `)[0].slice(0,200)}var AW,jW=__esmMin(()=>{_e(),P_(),Rd(),Pn(),eh(),QP(),DW(),VR(),gW(),kW(),AW={command:`trust [packages..]`,description:"Configure npm Trusted Publishers (OIDC/GitHub Actions) for publishable workspace packages so release.yml can publish without a token. Native — no `npm` needed. Incremental: skips already-configured packages.",builder:t=>t.positional(`packages`,{description:`Optional package-name globs to limit the sweep (default: all publishable workspaces).`,type:`string`,array:!0}).option(`repository`,{description:"GitHub repo as `owner/repo`. Default: inferred from the `origin` git remote.",type:`string`}).option(`workflow`,{description:`Workflow filename allowed to publish (basename only).`,type:`string`,default:`release.yml`}).option(`environment`,{description:`Optional GitHub Actions environment the workflow must run in.`,type:`string`}).option(`registry`,{description:`Registry override. Default: scope-aware lookup from .npmrc (falls back to ${qm}).`,type:`string`}).option(`otp`,{description:"npm 2FA one-time code; sent as `npm-otp`. Prompted on demand if omitted.",type:`string`}).option(`dry-run`,{description:`List what would be configured without writing anything.`,type:`boolean`,default:!1}).option(`force`,{description:`Re-POST the config even for packages already trusted for this repo+workflow.`,type:`boolean`,default:!1}).option(`list`,{description:`Only report each package’s current trust state; configure nothing.`,type:`boolean`,default:!1}).option(`private`,{description:`Include private workspaces (default false — private packages are not publishable).`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=await loadNpmrc(n);if(!hasAnyCredential(S))return ge.error("gjsify trust: no npm token configured. Run `gjsify login` first."),process.exit(1);let C=t.registry??process.env.npm_config_registry??S.registry??qm;if(t[`dry-run`]!==!0){let t;try{t=await whoami(C,S)}catch(t){let n=t instanceof Error?t.message:String(t);return ge.error(`gjsify trust: npm auth check failed (${n}).\nYour ~/.npmrc token is dead or revoked — refresh it with \`npm login\`, then re-run.
1212
1212
  (\`gjsify trust\` uses the ~/.npmrc bearer token directly — unlike \`npm trust\`, which logs in via the browser.)`),process.exit(1)}if(!t.username)return ge.error("gjsify trust: your npm token appears dead or revoked (registry returned an empty whoami).\nRefresh it with `npm login`, then re-run."),process.exit(1);ge.log(`gjsify trust: authenticated as ${t.username}`)}let N=t.repository;if(!N){let t=spawnSync(`git`,[`remote`,`get-url`,`origin`],{cwd:n,encoding:`utf8`});t.status===0&&(N=parseRepoFromGitRemote(t.stdout)??void 0)}if(!N)return ge.error("gjsify trust: could not determine the GitHub repository.\nPass --repository owner/repo (no `origin` remote to infer from)."),process.exit(1);if(!validateRepository(N))return ge.error(`gjsify trust: --repository must be "owner/repo", got "${N}".`),process.exit(1);let F=normalizeWorkflowFile(t.workflow),I=t.environment,H=t.list===!0,W=t[`dry-run`]===!0,q=t.force===!0,Y=wn(n,`.github`,`workflows`,F);existsSync(Y)||ge.warn(`gjsify trust: note — ${Y} not found; configuring trust for "${F}" anyway.`);let X=filterWorkspaces(mergePublishables(discoverWorkspaces(n,{includeRoot:!0}),n),{noPrivate:t.private!==!0,include:t.packages&&t.packages.length>0?t.packages:void 0}).filter(t=>t.name);if(X.length===0)return ge.error(`gjsify trust: no publishable packages matched.`),process.exit(1);ge.log(`gjsify trust: ${X.length} package(s) | repo=${N} workflow=${F}`),W&&ge.log(`(dry-run — nothing will be written)`),ge.log();let Z=createTrustRequester({npmrc:S,otpProvider:new OtpProvider(t.otp)}),te=0,ne=0,re=0,ie=0,ae=[],oe=[];for(let n of X){let C=n.name,Y=trustUrl(t.registry??registryFor(C,S)??qm,C);process.stdout.write(`→ ${C.padEnd(42)} `);let X=await Z(`GET`,Y),Q=classifyTrustList(X.status,X.json,{repository:N,workflow:F});if(H){Q===`trusted`?ge.log(`trusted`):Q===`unpublished`?ge.log(`unpublished`):Q===`auth-required`?ge.log(`auth-required (could not read)`):Q===`untrusted`?ge.log(`not trusted`):ge.log(`error (HTTP ${X.status})`);continue}if(Q===`trusted`&&!q){ge.log(`already configured — skip`),ne++;continue}if(Q===`unpublished`){ge.log(`not on npm yet — needs first-publish, skip`),re++,ae.push(C);continue}if(W){ge.log(`would configure`),te++;continue}let se=await Z(`POST`,Y,githubTrustBody({repository:N,workflow:F,environment:I}));se.status>=200&&se.status<300?(ge.log(`configured`),te++):se.status===409?(ge.log(`already configured (409) — done`),ne++):se.status===404?(ge.log(`not on npm yet — needs first-publish, skip`),re++,ae.push(C)):(ge.log(`FAILED (HTTP ${se.status})`),ie++,oe.push(`${C} — HTTP ${se.status}${se.text?`: ${firstLine(se.text)}`:``}`))}if(!H){if(ge.log(),ge.log(`Done: ${te} ${W?`would-configure`:`configured`}, ${ne} already-configured, ${re} unpublished, ${ie} failed.`),ae.length>0){ge.log("Need a first publish before they can be trust-configured (then re-run `gjsify trust`):");for(let t of ae)ge.log(` ${t}`)}if(oe.length>0){ge.log("Failed (re-run `gjsify trust` — it is incremental; usually a lapsed 2FA window or rate-limit):");for(let t of oe)ge.log(` ${t}`);process.exit(1)}}}}});function resolveRepoRoot(t){let n=findWorkspaceRoot(t);if(n)return n;let S=spawnSync(`git`,[`rev-parse`,`--show-toplevel`],{cwd:t,encoding:`utf8`});if(S.status===0){let t=S.stdout.trim();if(t&&existsSync(t))return t}return t}function assertEveryPatternMatches(t,n){let S=n.filter(n=>{try{return discoverWorkspaces(t,{patterns:[n]}).length===0}catch{return!0}});if(S.length===0)return;let C=[`gjsify onboard: --packages matched no package directory (${S.length} of ${n.length} pattern(s)) under ${t}:`];for(let t of S)C.push(` ${JSON.stringify(t)}`);throw C.push(" Patterns are DIRECTORY globs resolved against the repo root, and only `*` is supported",` (one path segment). A matched directory needs a package.json with a "name".`),Error(C.join(`
1213
1213
  `))}function collectOnboardPackages(t,n,S={}){let C=[],N=[],F=new Set,take=(t,n,S)=>{let I=0;for(let t of n)!t.name||F.has(t.name)||(F.add(t.name),N.push(t),I++);C.push({kind:t,patterns:S,count:I})};if(existsSync(wn(t,`package.json`)))try{take(`workspaces`,discoverWorkspaces(t,{includeRoot:!0}))}catch{}return S.patterns&&S.patterns.length>0&&take(`packages`,discoverWorkspaces(t,{patterns:[...S.patterns]}),S.patterns),take(`scanned-dirs`,mergePublishables([],n)),{packages:N,sources:C}}function describeSources(t){return t.filter(t=>t.count>0).map(t=>t.patterns?`${t.kind}(${t.patterns.join(`,`)})=${t.count}`:`${t.kind}=${t.count}`).join(` + `)}function declaredRepository(t){let n=t.manifest.repository,S=typeof n==`string`?n:n?.url;return typeof S!=`string`||S.length===0?null:parseRepoFromGitRemote(S)}function assertRepositoryAgreement(t,n){let S=n.toLowerCase(),C=t.map(t=>({ws:t,declared:declaredRepository(t)})).filter(t=>t.declared!==null&&t.declared.toLowerCase()!==S);if(C.length===0)return;let N=new Map;for(let{ws:t,declared:n}of C){let S=N.get(n)??[];S.push(t.name),N.set(n,S)}let F=[`gjsify onboard: ${C.length} selected package(s) declare a DIFFERENT repository than ${n}:`];for(let[t,n]of N){let S=n.slice(0,5).join(`, `),C=n.length>5?`, … (+${n.length-5} more)`:``;F.push(` ${t}: ${n.length} package(s) — ${S}${C}`)}throw F.push(` A Trusted Publisher scoped to the wrong repository points that package's OIDC exchange`,` at a workflow that does not publish it, which breaks the release this sweep protects.`,` Either exclude them (--exclude), select only what belongs here (--include), or point`,` --repository at the repo that actually publishes them.`),Error(F.join(`
1214
- `))}var TW=__esmMin(()=>{Rd(),P_(),QP(),Pn(),bW(),SW(),eF()});function describeRateLimitHeaders(t){if(!t)return`no headers captured`;let n=[];return t.forEach((t,S)=>{(/^retry-after$/i.test(S)||/ratelimit/i.test(S))&&n.push(`${S}: ${t}`)}),n.length>0?n.join(`, `):`npm sent no Retry-After and no rate-limit headers`}function retryAfterMs(t){let n=t?.get(`retry-after`);if(!n)return null;let S=Number.parseInt(n.trim(),10);return!Number.isFinite(S)||S<0?null:S*1e3}async function packumentExists(t,n){let S=t.endsWith(`/`)?t.slice(0,-1):t;try{let t=await fetch(`${S}/${n.replace(`/`,`%2f`)}`,{method:`GET`,headers:{accept:`application/vnd.npm.install-v1+json`}});return t.status===404?!1:t.ok?!0:null}catch{return null}}function actionForState(t){switch(t){case`trusted`:return`skip`;case`untrusted`:return`trust`;case`unpublished`:return`publish-and-trust`;default:return`blocked`}}function defaultSleep(t){return new Promise(n=>setTimeout(n,t))}async function requestWaitingOutRateLimit(t,n,S,C,N={}){let F=N.sleep??defaultSleep,I=N.maxRateLimitWaitMs??3e5,H=N.rateLimitBaseDelayMs??2e3,W=N.gate;W&&await W.wait();let q=await t(n,S,C),Y=0;for(let X=0;q.status===429&&Y<I;X++){let Z=retryAfterMs(q.headers),te=Math.min(Z??H*2**X,EW),ne=Math.min(te,I-Y);N.onRateLimit?.({url:S,headers:describeRateLimitHeaders(q.headers),waitMs:ne,fromRetryAfter:Z!==null}),W?.penalize(ne),await(W?W.wait():F(ne)),Y+=ne,q=await t(n,S,C)}return q}async function probeTrustState(t,n,S,C={}){let N=S.registryOverride??registryFor(n.name,S.npmrc)??qm,F=trustUrl(N,n.name),I={repository:S.repository,workflow:S.workflow},H=C.sleep??defaultSleep,W=await requestWaitingOutRateLimit(t,`GET`,F,void 0,C),q=classifyTrustList(W.status,W.json,I);return q===`auth-required`&&C.retryOn401!==!1&&(await H(C.retryDelayMs??400),W=await t(`GET`,F),q=classifyTrustList(W.status,W.json,I)),(q===`untrusted`||q===`auth-required`)&&await(C.exists??packumentExists)(N,n.name)===!1&&(q=`unpublished`),{ws:n,registry:N,url:F,state:q,httpStatus:W.status,action:actionForState(q)}}async function probeAllTrustStates(t,n,S,C,N={}){if(n.length===0)return[];let F=n.length,I=0,report=t=>(I++,N.onProgress?.(I,F,t),t);return[report(await probeTrustState(t,n[0],C,N)),...await mapWithConcurrency(n.slice(1),Math.max(1,S),async n=>report(await probeTrustState(t,n,C,N)))]}async function mapWithConcurrency(t,n,S){let C=Array.from({length:t.length}),N=0,F=Array.from({length:Math.min(Math.max(1,n),t.length)},async()=>{for(;;){let n=N++;if(n>=t.length)return;C[n]=await S(t[n])}});return await Promise.all(F),C}var EW,RateLimitGate,DW=__esmMin(()=>{eh(),SW(),EW=6e4,RateLimitGate=class{until=0;now;sleeper;constructor(t={}){this.now=t.now??(()=>Date.now()),this.sleeper=t.sleep??defaultSleep}async wait(){let t=this.until-this.now();t>0&&await this.sleeper(t)}penalize(t){this.until=Math.max(this.until,this.now()+t)}remainingMs(){return Math.max(0,this.until-this.now())}}});function finish(t,n,S){let C=S.failed??0;if(S.asJson)process.stdout.write(`${JSON.stringify({ok:C===0,dryRun:S.dryRun,root:S.root,sources:S.sources,discovered:S.discovered,total:n.length,published:t.filter(t=>t.result===`published`||t.result===`published+trusted`).length,trusted:t.filter(t=>t.result===`trusted`||t.result===`published+trusted`).length,alreadyDone:t.filter(t=>t.result===`already-done`).length,failed:C,results:t},null,2)}\n`);else{let n=S.dryRun?C>0?`Dry-run INCOMPLETE — nothing changed, but ${C} package(s) had an unreadable state, so the plan above does not cover them. Authenticate (\`gjsify login\`) and re-run.`:`Dry-run complete — nothing changed.`:`Done: ${t.filter(t=>t.result.includes(`published`)).length} published, ${t.filter(t=>t.result===`trusted`||t.result===`published+trusted`).length} trusted, ${t.filter(t=>t.result===`already-done`).length} already done, ${C} failed.`;process.stdout.write(`\n${n}\n`)}process.exit(+(C>0))}function statusCell(t){switch(t.action){case`skip`:return`published✓ trusted✓`;case`trust`:return`published✓ trust… `;case`publish-and-trust`:return`publish… trust… `;case`blocked`:return`unreadable (${t.httpStatus})`}}async function ensureAuthenticated(t){let{npmrc:n,registry:S,cwd:C,nonInteractive:N,dryRun:F,otp:I,log:H}=t;if(hasAnyCredential(n))try{let t=await whoami(S,n);if(t.username)return t.username}catch{}if(F){H(`gjsify onboard: no live npm token — dry-run continues (state reads may be limited).`);return}if(N)throw Error("gjsify onboard: not authenticated and --yes was passed — run `gjsify login` first (or omit --yes to log in interactively).");H(`gjsify onboard: no live npm token — logging in…`);try{return(await runLogin({registry:S,otp:I,cwd:C})).username}catch(t){throw t instanceof LoginError?Error(t.message):t}}async function buildIfPresent(t,n){if(typeof(t.manifest.scripts??{}).build!=`string`)return;let S=detectPackageManager(),C=[`run`,`build`];n(` $ ${S} ${C.join(` `)}`);let{code:N}=await spawnToCompletion(S,C,{completion:`return`,cwd:t.location,env:{...process.env}});if(N!==0)throw Error(`build exited with code ${N}`)}function describePublishFailure(t){switch(t.action){case`otp-required`:return`npm required a 2FA code (re-run with --otp, or on a TTY)`;case`oidc-failed`:case`oidc-no-token`:return`OIDC/token auth failed`;case`diagnostic`:return`HTTP 404 (${t.diag.reason})`;case`publish-unconfirmed`:return`npm ${t.claim===`already-published`?`reported it already published`:`accepted the upload`} (HTTP ${t.putStatus}) but ${t.name}@${t.version} did not resolve on ${t.registry} after ${t.readback.attempts} probe(s) over ${(t.readback.elapsedMs/1e3).toFixed(1)}s [${t.readback.verdict}: ${t.readback.verdictDetail}]`;case`blocked-missing-dependency`:return`not published — ${t.missing.length} required pin(s) name a package ${t.registry} does not have: ${t.missing.map(t=>`${t.block}.${t.name}@${t.spec}`).join(`, `)}. Bootstrap the target BEFORE its dependent; that order is a correctness property`;case`error`:return`HTTP ${t.status} ${t.statusText}`;default:return`unknown`}}var OW,kW,AW=__esmMin(()=>{_e(),P_(),eh(),QP(),IR(),lW(),$U(),dW(),wW(),gW(),wR(),V_(),TW(),SW(),DW(),OW=4,kW={command:`onboard`,description:`Ensure every publishable package in a monorepo is both published on npm and has a Trusted Publisher configured for its release workflow — publishing/trusting only what is missing, one shared OTP across the whole sweep. Works on npm/yarn workspaces and, via --packages, on a monorepo with no workspace manifest at all. Idempotent.`,builder:t=>t.option(`repository`,{description:"GitHub repo as `owner/repo`. Default: inferred from the `origin` git remote.",type:`string`}).option(`workflow`,{description:`Workflow filename allowed to publish via OIDC (basename only).`,type:`string`,default:`release.yml`}).option(`environment`,{description:`Optional GitHub Actions environment the workflow must run in.`,type:`string`}).option(`registry`,{description:`Registry override. Default: scope-aware lookup from .npmrc (falls back to ${qm}).`,type:`string`}).option(`otp`,{description:`npm 2FA one-time code, used as the initial shared code. Prompted on demand (once) if omitted and a challenge occurs.`,type:`string`}).option(`packages`,{description:'Directory glob naming package folders, resolved against the repo root (repeatable). For a monorepo that is not an npm/yarn workspace — `--packages "*"` in a repo whose 703 package directories sit at the top level. Merged with the root manifest\'s own `workspaces` globs when it has any. A pattern matching NO directory is a hard error.',type:`string`,array:!0}).option(`include`,{description:`Glob pattern to include packages by NAME (repeatable). Applied after discovery.`,type:`string`,array:!0}).option(`exclude`,{description:`Glob pattern to exclude packages by NAME (repeatable). Applied after discovery.`,type:`string`,array:!0}).option(`access`,{description:"npm access for a FIRST publish — `public` or `restricted`. Only ever applied to a package this sweep publishes; an already-published package keeps whatever access it has.",type:`string`,choices:[`public`,`restricted`],default:`public`}).option(`build`,{description:"Run each to-be-published package's `build` script first. `--no-build` skips it, for a repo whose packages are generated artifacts with nothing to build.",type:`boolean`,default:!0}).option(`verbose`,{description:`List every package in the plan table, including the ones already published + trusted (by default only the rows needing work are listed; the counts always cover all of them).`,type:`boolean`,alias:`v`,default:!1}).option(`concurrency`,{description:`How many packages to probe (read state) in parallel (kept small so a single token does not burst npm; the first read is always serial to prompt for the shared OTP once).`,type:`number`,default:4}).option(`write-concurrency`,{description:`How many Trusted-Publisher writes to issue in parallel. It buys FEWER 2FA PROMPTS more than it buys speed: an npm code lives about 30 seconds, so a serial sweep crosses a code boundary every ~38 packages. Raising it does not beat npm's rate limit — a 429 anywhere now pauses the whole sweep, so it self-paces down to whatever the registry will serve. Publishes are unaffected: they stay serial, because publish ORDER is a correctness property.`,type:`number`,default:OW}).option(`dry-run`,{description:`Report the plan (what would be published / trusted) without changing anything.`,type:`boolean`,default:!1}).option(`json`,{description:`Emit a machine-readable summary object as the final line of stdout.`,type:`boolean`,default:!1}).option(`yes`,{description:`Non-interactive: never prompt. Fail clearly if a login or an OTP is required and not supplied via flags.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t[`dry-run`]===!0,C=t.json===!0,N=t.yes===!0,log=(t=``)=>{C?process.stderr.write(`${t}\n`):writeAroundPrompt(`${t}\n`)},F=await loadNpmrc(n),I=t.registry??process.env.npm_config_registry??F.registry??qm,H;try{H=await ensureAuthenticated({npmrc:F,registry:I,cwd:n,nonInteractive:N,dryRun:S,otp:t.otp,log})}catch(t){let n=t instanceof Error?t.message:String(t);return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`auth`,message:n})}\n`):ge.error(n),process.exit(1)}F=await loadNpmrc(n),H&&log(`gjsify onboard: authenticated as ${H}`);let W=t.repository;if(!W){let t=spawnSync(`git`,[`remote`,`get-url`,`origin`],{cwd:n,encoding:`utf8`});t.status===0&&(W=parseRepoFromGitRemote(t.stdout)??void 0)}if(!W||!validateRepository(W)){let t=`gjsify onboard: could not determine the GitHub repository — pass --repository owner/repo.`;return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`repository`,message:t})}\n`):ge.error(t),process.exit(1)}let q=normalizeWorkflowFile(t.workflow),Y=t.environment,X=resolveRepoRoot(n),Z,te;try{t.packages&&t.packages.length>0&&assertEveryPatternMatches(X,t.packages);let S=collectOnboardPackages(X,n,{patterns:t.packages});Z=S.packages,te=describeSources(S.sources)}catch(t){let n=t instanceof Error?t.message:String(t);return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`discovery`,message:n})}\n`):ge.error(n),process.exit(1)}let ne=filterWorkspaces(Z,{noPrivate:!0,include:t.include,exclude:t.exclude}).filter(t=>t.name);if(ne.length===0){let t=`gjsify onboard: no publishable packages found under ${X} (discovered ${Z.length}${te?` — ${te}`:``}). `+(Z.length>0?`Every discovered package is private or was filtered out by --include/--exclude.`:`Pass --packages with a directory glob if this repo has no workspace manifest.`);return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`no-packages`,message:t})}\n`):ge.error(t),process.exit(1)}try{assertRepositoryAgreement(ne,W)}catch(t){let n=t instanceof Error?t.message:String(t);return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`foreign-repository`,message:n})}\n`):ge.error(n),process.exit(1)}log(`gjsify onboard: root=${X} | ${te}`),log(`gjsify onboard: ${ne.length} of ${Z.length} package(s) selected | repo=${W} workflow=${q}`),S&&log(`(dry-run — nothing will be published or configured)`),log();let re=new OtpProvider(t.otp,N?async()=>``:void 0,{registry:I}),ie=createTrustRequester({npmrc:F,otpProvider:re}),ae=new RateLimitGate,oe=!1,onRateLimit=t=>{oe||(oe=!0,log(` npm rate limit hit. ${t.headers}. Waiting ${Math.round(t.waitMs/1e3)}s (${t.fromRetryAfter?`npm's Retry-After`:`our backoff — npm advised nothing`}), and holding the whole sweep back while it lasts.`))},Q={gate:ae,onRateLimit},se=Math.max(1,Math.min(50,Math.ceil(ne.length/10))),ce=0,le=0,ue=0;ne.length>se&&log(`Reading trust state for ${ne.length} package(s)…`);let de=await probeAllTrustStates(ie,ne,Math.max(1,t.concurrency),{registryOverride:t.registry,npmrc:F,repository:W,workflow:q},{...Q,onProgress:(t,n,S)=>{if(S.action===`trust`||S.action===`publish-and-trust`?ce++:S.action===`skip`?le++:ue++,t%se!==0&&t!==n||n<=se)return;let C=[`${ce} to do`,`${le} already done`];ue>0&&C.push(`${ue} unreadable`),log(` read ${t}/${n} — ${C.join(`, `)}`)}}),fe=de.filter(t=>t.action===`publish-and-trust`),pe=de.filter(t=>t.action===`trust`),me=de.filter(t=>t.action===`skip`),he=de.filter(t=>t.action===`blocked`);for(let n of de)n.action===`skip`&&t.verbose!==!0||log(` ${statusCell(n)} ${n.ws.name}`);!t.verbose&&me.length>0&&log(` (${me.length} already published + trusted — pass -v to list)`),log(),log(`Plan: ${me.length} already done, ${fe.length} to publish+trust, ${pe.length} to trust, ${he.length} unreadable.`);let _e=he.filter(t=>t.httpStatus===429).length;_e>0&&log(` ${_e} of those are npm rate limits (HTTP 429) that outlasted the backoff — lower --concurrency and re-run; the sweep is idempotent and picks up where it left off.`);let ve=[];if(S){for(let t of de)ve.push({name:t.ws.name,result:t.action===`skip`?`already-done`:t.action===`blocked`?`failed`:`skipped-dry-run`,detail:t.action===`publish-and-trust`?`would publish + trust`:t.action===`trust`?`would trust`:t.action===`blocked`?`state HTTP ${t.httpStatus}`:void 0});finish(ve,de,{asJson:C,dryRun:S,failed:he.length,root:X,sources:te,discovered:Z.length});return}let ye=githubTrustBody({repository:W,workflow:q,environment:Y}),be=Math.max(1,t[`write-concurrency`]),xe=fe.length+pe.length,Se=Array.from({length:de.length}),Ce=0,we=0,Te=0,configureTrust=async(t,n,S)=>{let C=await requestWaitingOutRateLimit(ie,`POST`,t.url,ye,Q),N=`${++we}/${xe}`;C.status>=200&&C.status<300?(log(` [${N}] trusted ${t.ws.name}`),Se[n]={name:t.ws.name,result:S?`published+trusted`:`trusted`}):C.status===409?Se[n]={name:t.ws.name,result:S?`published+trusted`:`trusted`}:C.status===404?(log(` [${N}] ${t.ws.name}: published but not yet trust-configurable (re-run onboard)`),Se[n]={name:t.ws.name,result:S?`published`:`failed`,detail:`trust config deferred (404)`},S||Ce++):(log(` [${N}] trust failed (HTTP ${C.status}) — ${t.ws.name}`),Se[n]={name:t.ws.name,result:`failed`,detail:`trust HTTP ${C.status}`},C.status===429&&Te++,Ce++)},Ee=[],De=new Set;for(let n=0;n<de.length;n++){let S=de[n];if(S.action===`skip`){Se[n]={name:S.ws.name,result:`already-done`};continue}if(S.action===`blocked`){log(`→ ${S.ws.name}: cannot read trust state (HTTP ${S.httpStatus}) — skipped`),Se[n]={name:S.ws.name,result:`failed`,detail:`state HTTP ${S.httpStatus}`},Ce++;continue}if(S.action===`trust`){Ee.push({p:S,i:n});continue}log(`→ ${S.ws.name}: building + publishing…`);try{t.build!==!1&&await buildIfPresent(S.ws,log)}catch(t){let C=t instanceof Error?t.message:String(t);log(` build failed: ${C}`),Se[n]={name:S.ws.name,result:`failed`,detail:`build: ${C}`},Ce++;continue}let C=await publishWorkspace({assumePresent:[...De],wsDir:S.ws.location,tag:`latest`,access:t.access,provenance:!1,tolerate:!0,tolerateUntrustedNew:!1,trustedFlag:void 0,registry:S.registry,verbose:!1,json:!1,otpProvider:re,seedOtpFirst:!1});if(!C.ok){let t=describePublishFailure(C);log(` publish failed: ${t}`),Se[n]={name:S.ws.name,result:`failed`,detail:`publish: ${t}`},Ce++;continue}log(` published ${C.name}@${`version`in C?C.version:``}`+(`readback`in C&&C.readback?.confirmed?` (verified on ${C.registry} — ${C.readback.attempts} probe(s))`:C.action===`skipped-untrusted-new`?``:` (UNVERIFIED)`)),De.add(C.name),await configureTrust(S,n,C.action!==`skipped-untrusted-new`)}Ee.length>0&&(Ee.length>1&&log(`→ configuring ${Ee.length} Trusted Publisher(s), ${be} at a time…`),await mapWithConcurrency(Ee,be,async({p:t,i:n})=>configureTrust(t,n,!1)));for(let t of Se)t&&ve.push(t);Te>0&&(log(),log(`${Te} of the failures are npm rate limits (HTTP 429) that outlasted the wait, not a problem with those packages.`),log(` Re-run to pick them up — the sweep is idempotent and skips everything already configured. A lower --write-concurrency (currently ${be}) provokes the limit less.`)),finish(ve,de,{asJson:C,dryRun:S,failed:Ce,root:X,sources:te,discovered:Z.length})}}});function pathFor(t){return t===`win32`?hn:pn}function isInside$1(t,n,S){let C=pathFor(S);if(!C.isAbsolute(t)||!C.isAbsolute(n))return!1;let N=n.endsWith(C.sep)?n:n+C.sep;return t===n||t.startsWith(N)}function classifyInstall(t){let n=t.env??process.env,S=t.platform??process.platform,C=pathFor(S),N=C.resolve(t.selfDir);if(n.FLATPAK_ID||isInside$1(N,MW,S)){let t=n.FLATPAK_ID??`io.github.gjsify.Cli`;return{kind:`flatpak`,evidence:n.FLATPAK_ID?`FLATPAK_ID=${n.FLATPAK_ID}`:`running from ${MW}`,updateWith:`flatpak update ${t}`,managedElsewhere:!0}}return isInside$1(N,C.resolve(t.xdgPrefix),S)?{kind:`xdg-global`,evidence:`running from the user-global prefix ${t.xdgPrefix}`,managedElsewhere:!1}:S!==`win32`&&jW.some(t=>isInside$1(N,t,S))?{kind:`system-package`,evidence:`running from the system prefix ${N}`,updateWith:"your distribution package manager (`apt upgrade` / `dnf upgrade` / …), or install the newer package from https://github.com/gjsify/gjsify/releases/latest",managedElsewhere:!0}:N.split(C.sep).includes(`node_modules`)?{kind:`npm-global`,evidence:`running from a node_modules tree at ${N}`,updateWith:`npm install -g @gjsify/cli@latest (or switch to the Node-free bootstrap)`,managedElsewhere:!0}:{kind:`unknown`,evidence:`running from ${N}, which matches no known install layout`,managedElsewhere:!1}}var jW,MW,NW=__esmMin(()=>{Pn(),jW=[`/usr/`,`/opt/`,`/snap/`],MW=`/app/`,__name$1(isInside$1,`isInside`)});function verifyPathResolution(t){let n=t.platform??process.platform,S=n===`win32`?hn:pn,norm=t=>n===`win32`?S.resolve(t).toLowerCase():S.resolve(t);if(t.resolvedBin===null)return{ok:!1,message:`BUT nothing named \`${t.binName}\` is on PATH, so the update cannot take effect.\n\n Add the bin dir to PATH:\n ${t.binDir}`};if(norm(S.dirname(t.resolvedBin))===norm(t.binDir))return{ok:!0};let C=t.runningVersion?` (v${t.runningVersion})`:``;return{ok:!1,message:`BUT \`${t.binName}\` on PATH resolves to\n ${t.resolvedBin}${C}\nwhich is NOT the install that was just updated, so the next \`${t.binName}\`\nyou run will not be v${t.targetVersion}.\n\n If that is another install, remove it (e.g. \`npm uninstall -g ${PW}\`)\n or put ${t.binDir} ahead of it on PATH.\n If you ran this through npx/dlx, that temporary copy owns the name only for\n this run — open a new shell and check \`${t.binName} --version\`.`}}function isNextChannelVersion(t){return t?(parse(t)?.prerelease??[]).some(t=>t===`next`):!1}function nextChannelNotice(t){return t.requestedTag!==void 0||!isNextChannelVersion(t.currentVersion)?null:`Note: v${t.currentVersion} is a \`next\` prerelease; updating without --tag moves you to \`${FW}\`. Use \`--tag next\` to stay on the next channel.`}function readSelfDir(){let t=process.env.GJSIFY_CLI_PACKAGE_JSON;if(t)return En(xn(t));let n=fileURLToPath(import.meta.url),S=En(xn(n));for(let t=0;t<8&&S!==En(S);t++){if(existsSync(wn(S,`package.json`)))return S;S=En(S)}return En(xn(n))}function readCurrentVersion(){try{let t=process.env.GJSIFY_CLI_PACKAGE_JSON;if(t){let n=JSON.parse(readFileSync(t,`utf-8`));return n.name===PW&&typeof n.version==`string`?n.version:null}let n=En(xn(fileURLToPath(import.meta.url)));for(let t=0;t<8&&n!==En(n);t++){let t=wn(n,`package.json`);if(existsSync(t)){let n=JSON.parse(readFileSync(t,`utf-8`));if(n.name===PW&&typeof n.version==`string`)return n.version}n=En(n)}}catch{}return null}function resolveTag(t,n){let S=t[`dist-tags`]??{};return S[n]?S[n]:t.versions&&typeof t.versions==`object`&&t.versions[n]?n:null}var PW,FW,IW,LW,RW=__esmMin(()=>{_e(),Rd(),Pn(),Gn(),eh(),XP(),eR(),NW(),iR(),cR(),zL(),VL(),PW=`@gjsify/cli`,FW=`latest`,IW={command:`self-update`,description:`Update the installed ${PW} to the latest release (or pinned --tag).`,builder:t=>t.option(`check`,{description:`Only check whether a newer version is available; do not install.`,type:`boolean`,default:!1}).option(`force`,{description:`Reinstall even when the current version already matches the target tag.`,type:`boolean`,default:!1}).option(`tag`,{description:"npm dist-tag or pinned version to install (e.g. `latest`, `next`, `0.5.0`).",type:`string`}).option(`prune`,{description:`After updating, remove packages an earlier install left behind that this host cannot use (foreign os/cpu/libc). Use --no-prune to disable.`,type:`boolean`,default:!0}).option(`skip-deps`,{description:`Update only the @gjsify/cli bundle itself; do not pull its runtime dependencies (rolldown, lightningcss, @gjsify/tsc, the native gi:// bridges, …). Faster, but can leave the on-disk runtime deps stale relative to the new bundle.`,type:`boolean`,default:!1}),handler:async t=>{let n=defaultGlobalLayout(),S=wn(wn(n.prefix,`node_modules`,PW),`package.json`),C=readCurrentVersion(),N=existsSync(S);ge.log(`Current ${PW}: v${C??`(unknown)`}`);let F=classifyInstall({selfDir:readSelfDir(),xdgPrefix:n.prefix});if(F.managedElsewhere)return ge.error(`\ngjsify self-update: this gjsify is managed by something else — ${F.evidence}.\nUpdating it from here would write ${n.prefix} and leave you running two installs.\n\nUpdate with: ${F.updateWith}\n`),process.exit(1);N||ge.warn(`\nWarning: no @gjsify/cli install found under ${n.prefix}.\nself-update only manages installs created by install.mjs or \`gjsify install -g\`.\nIf you installed via \`npm install -g\`, remove that and use:\n curl -fsSL https://github.com/gjsify/gjsify/releases/latest/download/install.mjs -o /tmp/g.mjs && gjs -m /tmp/g.mjs && rm /tmp/g.mjs`);let I=t.tag??FW,H=nextChannelNotice({currentVersion:C,requestedTag:t.tag});H&&ge.log(H),ge.log(`Fetching dist-tags for ${PW}@${I} ...`);let W;try{W=await fetchPackument(PW)}catch(t){let n=t instanceof Error?t.message:String(t);return ge.error(`Failed to fetch packument: ${n}`),process.exit(1)}let q=resolveTag(W,I);if(!q)return ge.error(`Unknown dist-tag '${I}' on ${PW}. Known tags: ${Object.keys(W[`dist-tags`]??{}).join(`, `)||`(none)`}`),process.exit(1);ge.log(`Latest matching --tag ${I}: v${q}`);let Y=N&&!hasBundlerEngineInstalled(n.prefix),X=Y&&!t.skipDeps&&!t.check;if(C===q&&!t.force&&!X){ge.log(`Already up to date (v${q}).`),Y&&t.skipDeps&&ge.log("Note: the GJS bundler engine @gjsify/rolldown-native is not installed — re-run without --skip-deps to repair it (`gjsify build` needs it under GJS)."),t.check||ge.log(`Run with --force to reinstall anyway.`);return}if(X&&C===q&&!t.force&&ge.log(`@gjsify/cli is at v${q} but the GJS bundler engine @gjsify/rolldown-native is missing — repairing.`),t.check)return ge.log(C?`Update available: v${C} → v${q}`:`Install required: → v${q}`),process.exit(1);let Z=!t.skipDeps,te=Z?` + runtime dependencies`:` (bundle only)`;ge.log(`Installing ${PW}@${q}${te} ...`);let ne=makeProgressReporter();try{await installPackages({prefix:n.prefix,specs:[`${PW}@${q}`],verbose:!1,skipDeps:!Z,progress:ne})}catch(t){let n=t instanceof Error?t.message:String(t);return ge.error(`self-update: install failed — ${n}`),ge.error("Re-run `gjsify self-update` to retry."),process.exit(1)}Z&&await installGjsEnginePackages(n.prefix,q,{verbose:!1}),t.prune!==!1&&pruneAfterInstall(n.prefix,resolveHostPlatform({env:{}}),{hint:`gjsify prune -g --dry-run`});let re=linkGlobalBins([PW],n);if(re.length===0)ge.warn("self-update: install completed but no bins were linked — package.json may be missing a `bin` field.");else for(let t of re)ge.log(` • ${t.link} → ${t.target}`);if(globalLayoutIsDefault()){let t=verifyPathResolution({binName:LW,binDir:n.binDir,resolvedBin:resolveBinOnPath(LW,{pathValue:pathWithoutSelfShim()}),runningVersion:C,targetVersion:q});if(!t.ok)return ge.error(`\nInstalled ${PW} v${q} at ${n.prefix}`),ge.error(t.message),process.exit(1)}ge.log(`\nUpdated ${PW} to v${q}.`),Z?ge.log(`Runtime dependencies were resolved alongside the bundle.`):ge.log(`Bundle-only update (--skip-deps): on-disk runtime dependencies were left unchanged.`)}},LW=`gjsify`});function loadInstallerTemplate(){return`#!/usr/bin/env -S gjs -m
1214
+ `))}var MW=__esmMin(()=>{Rd(),P_(),QP(),Pn(),DW(),kW(),eF()});function describeRateLimitHeaders(t){if(!t)return`no headers captured`;let n=[];return t.forEach((t,S)=>{(/^retry-after$/i.test(S)||/ratelimit/i.test(S))&&n.push(`${S}: ${t}`)}),n.length>0?n.join(`, `):`npm sent no Retry-After and no rate-limit headers`}function retryAfterMs(t){let n=t?.get(`retry-after`);if(!n)return null;let S=Number.parseInt(n.trim(),10);return!Number.isFinite(S)||S<0?null:S*1e3}async function packumentExists(t,n){let S=t.endsWith(`/`)?t.slice(0,-1):t;try{let t=await fetch(`${S}/${n.replace(`/`,`%2f`)}`,{method:`GET`,headers:{accept:`application/vnd.npm.install-v1+json`}});return t.status===404?!1:t.ok?!0:null}catch{return null}}function actionForState(t){switch(t){case`trusted`:return`skip`;case`untrusted`:return`trust`;case`unpublished`:return`publish-and-trust`;default:return`blocked`}}function defaultSleep(t){return new Promise(n=>setTimeout(n,t))}async function requestWaitingOutRateLimit(t,n,S,C,N={}){let F=N.sleep??defaultSleep,I=N.maxRateLimitWaitMs??3e5,H=N.rateLimitBaseDelayMs??2e3,W=N.gate;W&&await W.wait();let q=await t(n,S,C),Y=0;for(let X=0;q.status===429&&Y<I;X++){let Z=retryAfterMs(q.headers),te=Math.min(Z??H*2**X,NW),ne=Math.min(te,I-Y);N.onRateLimit?.({url:S,headers:describeRateLimitHeaders(q.headers),waitMs:ne,fromRetryAfter:Z!==null}),W?.penalize(ne),await(W?W.wait():F(ne)),Y+=ne,q=await t(n,S,C)}return q}async function probeTrustState(t,n,S,C={}){let N=S.registryOverride??registryFor(n.name,S.npmrc)??qm,F=trustUrl(N,n.name),I={repository:S.repository,workflow:S.workflow},H=C.sleep??defaultSleep,W=await requestWaitingOutRateLimit(t,`GET`,F,void 0,C),q=classifyTrustList(W.status,W.json,I);return q===`auth-required`&&C.retryOn401!==!1&&(await H(C.retryDelayMs??400),W=await t(`GET`,F),q=classifyTrustList(W.status,W.json,I)),(q===`untrusted`||q===`auth-required`)&&await(C.exists??packumentExists)(N,n.name)===!1&&(q=`unpublished`),{ws:n,registry:N,url:F,state:q,httpStatus:W.status,action:actionForState(q)}}async function probeAllTrustStates(t,n,S,C,N={}){if(n.length===0)return[];let F=n.length,I=0,report=t=>(I++,N.onProgress?.(I,F,t),t);return[report(await probeTrustState(t,n[0],C,N)),...await mapWithConcurrency(n.slice(1),Math.max(1,S),async n=>report(await probeTrustState(t,n,C,N)))]}async function mapWithConcurrency(t,n,S){let C=Array.from({length:t.length}),N=0,F=Array.from({length:Math.min(Math.max(1,n),t.length)},async()=>{for(;;){let n=N++;if(n>=t.length)return;C[n]=await S(t[n])}});return await Promise.all(F),C}var NW,RateLimitGate,PW=__esmMin(()=>{eh(),kW(),NW=6e4,RateLimitGate=class{until=0;now;sleeper;constructor(t={}){this.now=t.now??(()=>Date.now()),this.sleeper=t.sleep??defaultSleep}async wait(){let t=this.until-this.now();t>0&&await this.sleeper(t)}penalize(t){this.until=Math.max(this.until,this.now()+t)}remainingMs(){return Math.max(0,this.until-this.now())}}});function finish(t,n,S){let C=S.failed??0;if(S.asJson)process.stdout.write(`${JSON.stringify({ok:C===0,dryRun:S.dryRun,root:S.root,sources:S.sources,discovered:S.discovered,total:n.length,published:t.filter(t=>t.result===`published`||t.result===`published+trusted`).length,trusted:t.filter(t=>t.result===`trusted`||t.result===`published+trusted`).length,alreadyDone:t.filter(t=>t.result===`already-done`).length,failed:C,results:t},null,2)}\n`);else{let n=S.dryRun?C>0?`Dry-run INCOMPLETE — nothing changed, but ${C} package(s) had an unreadable state, so the plan above does not cover them. Authenticate (\`gjsify login\`) and re-run.`:`Dry-run complete — nothing changed.`:`Done: ${t.filter(t=>t.result.includes(`published`)).length} published, ${t.filter(t=>t.result===`trusted`||t.result===`published+trusted`).length} trusted, ${t.filter(t=>t.result===`already-done`).length} already done, ${C} failed.`;process.stdout.write(`\n${n}\n`)}process.exit(+(C>0))}function statusCell(t){switch(t.action){case`skip`:return`published✓ trusted✓`;case`trust`:return`published✓ trust… `;case`publish-and-trust`:return`publish… trust… `;case`blocked`:return`unreadable (${t.httpStatus})`}}async function ensureAuthenticated(t){let{npmrc:n,registry:S,cwd:C,nonInteractive:N,dryRun:F,otp:I,log:H}=t;if(hasAnyCredential(n))try{let t=await whoami(S,n);if(t.username)return t.username}catch{}if(F){H(`gjsify onboard: no live npm token — dry-run continues (state reads may be limited).`);return}if(N)throw Error("gjsify onboard: not authenticated and --yes was passed — run `gjsify login` first (or omit --yes to log in interactively).");H(`gjsify onboard: no live npm token — logging in…`);try{return(await runLogin({registry:S,otp:I,cwd:C})).username}catch(t){throw t instanceof LoginError?Error(t.message):t}}async function buildIfPresent(t,n){if(typeof(t.manifest.scripts??{}).build!=`string`)return;let S=detectPackageManager(),C=[`run`,`build`];n(` $ ${S} ${C.join(` `)}`);let{code:N}=await spawnToCompletion(S,C,{completion:`return`,cwd:t.location,env:{...process.env}});if(N!==0)throw Error(`build exited with code ${N}`)}function describePublishFailure(t){switch(t.action){case`otp-required`:return`npm required a 2FA code (re-run with --otp, or on a TTY)`;case`oidc-failed`:case`oidc-no-token`:return`OIDC/token auth failed`;case`diagnostic`:return`HTTP 404 (${t.diag.reason})`;case`publish-unconfirmed`:return`npm ${t.claim===`already-published`?`reported it already published`:`accepted the upload`} (HTTP ${t.putStatus}) but ${t.name}@${t.version} did not resolve on ${t.registry} after ${t.readback.attempts} probe(s) over ${(t.readback.elapsedMs/1e3).toFixed(1)}s [${t.readback.verdict}: ${t.readback.verdictDetail}]`;case`blocked-missing-dependency`:return`not published — ${t.missing.length} required pin(s) name a package ${t.registry} does not have: ${t.missing.map(t=>`${t.block}.${t.name}@${t.spec}`).join(`, `)}. Bootstrap the target BEFORE its dependent; that order is a correctness property`;case`error`:return`HTTP ${t.status} ${t.statusText}`;default:return`unknown`}}var FW,IW,LW=__esmMin(()=>{_e(),P_(),eh(),QP(),VR(),gW(),oW(),vW(),jW(),CW(),kR(),V_(),MW(),kW(),PW(),FW=4,IW={command:`onboard`,description:`Ensure every publishable package in a monorepo is both published on npm and has a Trusted Publisher configured for its release workflow — publishing/trusting only what is missing, one shared OTP across the whole sweep. Works on npm/yarn workspaces and, via --packages, on a monorepo with no workspace manifest at all. Idempotent.`,builder:t=>t.option(`repository`,{description:"GitHub repo as `owner/repo`. Default: inferred from the `origin` git remote.",type:`string`}).option(`workflow`,{description:`Workflow filename allowed to publish via OIDC (basename only).`,type:`string`,default:`release.yml`}).option(`environment`,{description:`Optional GitHub Actions environment the workflow must run in.`,type:`string`}).option(`registry`,{description:`Registry override. Default: scope-aware lookup from .npmrc (falls back to ${qm}).`,type:`string`}).option(`otp`,{description:`npm 2FA one-time code, used as the initial shared code. Prompted on demand (once) if omitted and a challenge occurs.`,type:`string`}).option(`packages`,{description:'Directory glob naming package folders, resolved against the repo root (repeatable). For a monorepo that is not an npm/yarn workspace — `--packages "*"` in a repo whose 703 package directories sit at the top level. Merged with the root manifest\'s own `workspaces` globs when it has any. A pattern matching NO directory is a hard error.',type:`string`,array:!0}).option(`include`,{description:`Glob pattern to include packages by NAME (repeatable). Applied after discovery.`,type:`string`,array:!0}).option(`exclude`,{description:`Glob pattern to exclude packages by NAME (repeatable). Applied after discovery.`,type:`string`,array:!0}).option(`access`,{description:"npm access for a FIRST publish — `public` or `restricted`. Only ever applied to a package this sweep publishes; an already-published package keeps whatever access it has.",type:`string`,choices:[`public`,`restricted`],default:`public`}).option(`build`,{description:"Run each to-be-published package's `build` script first. `--no-build` skips it, for a repo whose packages are generated artifacts with nothing to build.",type:`boolean`,default:!0}).option(`verbose`,{description:`List every package in the plan table, including the ones already published + trusted (by default only the rows needing work are listed; the counts always cover all of them).`,type:`boolean`,alias:`v`,default:!1}).option(`concurrency`,{description:`How many packages to probe (read state) in parallel (kept small so a single token does not burst npm; the first read is always serial to prompt for the shared OTP once).`,type:`number`,default:4}).option(`write-concurrency`,{description:`How many Trusted-Publisher writes to issue in parallel. It buys FEWER 2FA PROMPTS more than it buys speed: an npm code lives about 30 seconds, so a serial sweep crosses a code boundary every ~38 packages. Raising it does not beat npm's rate limit — a 429 anywhere now pauses the whole sweep, so it self-paces down to whatever the registry will serve. Publishes are unaffected: they stay serial, because publish ORDER is a correctness property.`,type:`number`,default:FW}).option(`dry-run`,{description:`Report the plan (what would be published / trusted) without changing anything.`,type:`boolean`,default:!1}).option(`json`,{description:`Emit a machine-readable summary object as the final line of stdout.`,type:`boolean`,default:!1}).option(`yes`,{description:`Non-interactive: never prompt. Fail clearly if a login or an OTP is required and not supplied via flags.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t[`dry-run`]===!0,C=t.json===!0,N=t.yes===!0,log=(t=``)=>{C?process.stderr.write(`${t}\n`):writeAroundPrompt(`${t}\n`)},F=await loadNpmrc(n),I=t.registry??process.env.npm_config_registry??F.registry??qm,H;try{H=await ensureAuthenticated({npmrc:F,registry:I,cwd:n,nonInteractive:N,dryRun:S,otp:t.otp,log})}catch(t){let n=t instanceof Error?t.message:String(t);return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`auth`,message:n})}\n`):ge.error(n),process.exit(1)}F=await loadNpmrc(n),H&&log(`gjsify onboard: authenticated as ${H}`);let W=t.repository;if(!W){let t=spawnSync(`git`,[`remote`,`get-url`,`origin`],{cwd:n,encoding:`utf8`});t.status===0&&(W=parseRepoFromGitRemote(t.stdout)??void 0)}if(!W||!validateRepository(W)){let t=`gjsify onboard: could not determine the GitHub repository — pass --repository owner/repo.`;return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`repository`,message:t})}\n`):ge.error(t),process.exit(1)}let q=normalizeWorkflowFile(t.workflow),Y=t.environment,X=resolveRepoRoot(n),Z,te;try{t.packages&&t.packages.length>0&&assertEveryPatternMatches(X,t.packages);let S=collectOnboardPackages(X,n,{patterns:t.packages});Z=S.packages,te=describeSources(S.sources)}catch(t){let n=t instanceof Error?t.message:String(t);return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`discovery`,message:n})}\n`):ge.error(n),process.exit(1)}let ne=filterWorkspaces(Z,{noPrivate:!0,include:t.include,exclude:t.exclude}).filter(t=>t.name);if(ne.length===0){let t=`gjsify onboard: no publishable packages found under ${X} (discovered ${Z.length}${te?` — ${te}`:``}). `+(Z.length>0?`Every discovered package is private or was filtered out by --include/--exclude.`:`Pass --packages with a directory glob if this repo has no workspace manifest.`);return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`no-packages`,message:t})}\n`):ge.error(t),process.exit(1)}try{assertRepositoryAgreement(ne,W)}catch(t){let n=t instanceof Error?t.message:String(t);return C?process.stdout.write(`${JSON.stringify({ok:!1,error:`foreign-repository`,message:n})}\n`):ge.error(n),process.exit(1)}log(`gjsify onboard: root=${X} | ${te}`),log(`gjsify onboard: ${ne.length} of ${Z.length} package(s) selected | repo=${W} workflow=${q}`),S&&log(`(dry-run — nothing will be published or configured)`),log();let re=new OtpProvider(t.otp,N?async()=>``:void 0,{registry:I}),ie=createTrustRequester({npmrc:F,otpProvider:re}),ae=new RateLimitGate,oe=!1,onRateLimit=t=>{oe||(oe=!0,log(` npm rate limit hit. ${t.headers}. Waiting ${Math.round(t.waitMs/1e3)}s (${t.fromRetryAfter?`npm's Retry-After`:`our backoff — npm advised nothing`}), and holding the whole sweep back while it lasts.`))},Q={gate:ae,onRateLimit},se=Math.max(1,Math.min(50,Math.ceil(ne.length/10))),ce=0,le=0,ue=0;ne.length>se&&log(`Reading trust state for ${ne.length} package(s)…`);let de=await probeAllTrustStates(ie,ne,Math.max(1,t.concurrency),{registryOverride:t.registry,npmrc:F,repository:W,workflow:q},{...Q,onProgress:(t,n,S)=>{if(S.action===`trust`||S.action===`publish-and-trust`?ce++:S.action===`skip`?le++:ue++,t%se!==0&&t!==n||n<=se)return;let C=[`${ce} to do`,`${le} already done`];ue>0&&C.push(`${ue} unreadable`),log(` read ${t}/${n} — ${C.join(`, `)}`)}}),fe=de.filter(t=>t.action===`publish-and-trust`),pe=de.filter(t=>t.action===`trust`),me=de.filter(t=>t.action===`skip`),he=de.filter(t=>t.action===`blocked`);for(let n of de)n.action===`skip`&&t.verbose!==!0||log(` ${statusCell(n)} ${n.ws.name}`);!t.verbose&&me.length>0&&log(` (${me.length} already published + trusted — pass -v to list)`),log(),log(`Plan: ${me.length} already done, ${fe.length} to publish+trust, ${pe.length} to trust, ${he.length} unreadable.`);let _e=he.filter(t=>t.httpStatus===429).length;_e>0&&log(` ${_e} of those are npm rate limits (HTTP 429) that outlasted the backoff — lower --concurrency and re-run; the sweep is idempotent and picks up where it left off.`);let ve=[];if(S){for(let t of de)ve.push({name:t.ws.name,result:t.action===`skip`?`already-done`:t.action===`blocked`?`failed`:`skipped-dry-run`,detail:t.action===`publish-and-trust`?`would publish + trust`:t.action===`trust`?`would trust`:t.action===`blocked`?`state HTTP ${t.httpStatus}`:void 0});finish(ve,de,{asJson:C,dryRun:S,failed:he.length,root:X,sources:te,discovered:Z.length});return}let ye=githubTrustBody({repository:W,workflow:q,environment:Y}),be=Math.max(1,t[`write-concurrency`]),xe=fe.length+pe.length,Se=Array.from({length:de.length}),Ce=0,we=0,Te=0,configureTrust=async(t,n,S)=>{let C=await requestWaitingOutRateLimit(ie,`POST`,t.url,ye,Q),N=`${++we}/${xe}`;C.status>=200&&C.status<300?(log(` [${N}] trusted ${t.ws.name}`),Se[n]={name:t.ws.name,result:S?`published+trusted`:`trusted`}):C.status===409?Se[n]={name:t.ws.name,result:S?`published+trusted`:`trusted`}:C.status===404?(log(` [${N}] ${t.ws.name}: published but not yet trust-configurable (re-run onboard)`),Se[n]={name:t.ws.name,result:S?`published`:`failed`,detail:`trust config deferred (404)`},S||Ce++):(log(` [${N}] trust failed (HTTP ${C.status}) — ${t.ws.name}`),Se[n]={name:t.ws.name,result:`failed`,detail:`trust HTTP ${C.status}`},C.status===429&&Te++,Ce++)},Ee=[],De=new Set;for(let n=0;n<de.length;n++){let S=de[n];if(S.action===`skip`){Se[n]={name:S.ws.name,result:`already-done`};continue}if(S.action===`blocked`){log(`→ ${S.ws.name}: cannot read trust state (HTTP ${S.httpStatus}) — skipped`),Se[n]={name:S.ws.name,result:`failed`,detail:`state HTTP ${S.httpStatus}`},Ce++;continue}if(S.action===`trust`){Ee.push({p:S,i:n});continue}log(`→ ${S.ws.name}: building + publishing…`);try{t.build!==!1&&await buildIfPresent(S.ws,log)}catch(t){let C=t instanceof Error?t.message:String(t);log(` build failed: ${C}`),Se[n]={name:S.ws.name,result:`failed`,detail:`build: ${C}`},Ce++;continue}let C=await publishWorkspace({assumePresent:[...De],wsDir:S.ws.location,tag:`latest`,access:t.access,provenance:!1,tolerate:!0,tolerateUntrustedNew:!1,trustedFlag:void 0,registry:S.registry,verbose:!1,json:!1,otpProvider:re,seedOtpFirst:!1});if(!C.ok){let t=describePublishFailure(C);log(` publish failed: ${t}`),Se[n]={name:S.ws.name,result:`failed`,detail:`publish: ${t}`},Ce++;continue}log(` published ${C.name}@${`version`in C?C.version:``}`+(`readback`in C&&C.readback?.confirmed?` (verified on ${C.registry} — ${C.readback.attempts} probe(s))`:C.action===`skipped-untrusted-new`?``:` (UNVERIFIED)`)),De.add(C.name),await configureTrust(S,n,C.action!==`skipped-untrusted-new`)}Ee.length>0&&(Ee.length>1&&log(`→ configuring ${Ee.length} Trusted Publisher(s), ${be} at a time…`),await mapWithConcurrency(Ee,be,async({p:t,i:n})=>configureTrust(t,n,!1)));for(let t of Se)t&&ve.push(t);Te>0&&(log(),log(`${Te} of the failures are npm rate limits (HTTP 429) that outlasted the wait, not a problem with those packages.`),log(` Re-run to pick them up — the sweep is idempotent and skips everything already configured. A lower --write-concurrency (currently ${be}) provokes the limit less.`)),finish(ve,de,{asJson:C,dryRun:S,failed:Ce,root:X,sources:te,discovered:Z.length})}}});function pathFor(t){return t===`win32`?hn:pn}function isInside$1(t,n,S){let C=pathFor(S);if(!C.isAbsolute(t)||!C.isAbsolute(n))return!1;let N=n.endsWith(C.sep)?n:n+C.sep;return t===n||t.startsWith(N)}function classifyInstall(t){let n=t.env??process.env,S=t.platform??process.platform,C=pathFor(S),N=C.resolve(t.selfDir);if(n.FLATPAK_ID||isInside$1(N,zW,S)){let t=n.FLATPAK_ID??`io.github.gjsify.Cli`;return{kind:`flatpak`,evidence:n.FLATPAK_ID?`FLATPAK_ID=${n.FLATPAK_ID}`:`running from ${zW}`,updateWith:`flatpak update ${t}`,managedElsewhere:!0}}return isInside$1(N,C.resolve(t.xdgPrefix),S)?{kind:`xdg-global`,evidence:`running from the user-global prefix ${t.xdgPrefix}`,managedElsewhere:!1}:S!==`win32`&&RW.some(t=>isInside$1(N,t,S))?{kind:`system-package`,evidence:`running from the system prefix ${N}`,updateWith:"your distribution package manager (`apt upgrade` / `dnf upgrade` / …), or install the newer package from https://github.com/gjsify/gjsify/releases/latest",managedElsewhere:!0}:N.split(C.sep).includes(`node_modules`)?{kind:`npm-global`,evidence:`running from a node_modules tree at ${N}`,updateWith:`npm install -g @gjsify/cli@latest (or switch to the Node-free bootstrap)`,managedElsewhere:!0}:{kind:`unknown`,evidence:`running from ${N}, which matches no known install layout`,managedElsewhere:!1}}var RW,zW,BW=__esmMin(()=>{Pn(),RW=[`/usr/`,`/opt/`,`/snap/`],zW=`/app/`,__name$1(isInside$1,`isInside`)});function verifyPathResolution(t){let n=t.platform??process.platform,S=n===`win32`?hn:pn,norm=t=>n===`win32`?S.resolve(t).toLowerCase():S.resolve(t);if(t.resolvedBin===null)return{ok:!1,message:`BUT nothing named \`${t.binName}\` is on PATH, so the update cannot take effect.\n\n Add the bin dir to PATH:\n ${t.binDir}`};if(norm(S.dirname(t.resolvedBin))===norm(t.binDir))return{ok:!0};let C=t.runningVersion?` (v${t.runningVersion})`:``;return{ok:!1,message:`BUT \`${t.binName}\` on PATH resolves to\n ${t.resolvedBin}${C}\nwhich is NOT the install that was just updated, so the next \`${t.binName}\`\nyou run will not be v${t.targetVersion}.\n\n If that is another install, remove it (e.g. \`npm uninstall -g ${VW}\`)\n or put ${t.binDir} ahead of it on PATH.\n If you ran this through npx/dlx, that temporary copy owns the name only for\n this run — open a new shell and check \`${t.binName} --version\`.`}}function isNextChannelVersion(t){return t?(parse(t)?.prerelease??[]).some(t=>t===`next`):!1}function nextChannelNotice(t){return t.requestedTag!==void 0||!isNextChannelVersion(t.currentVersion)?null:`Note: v${t.currentVersion} is a \`next\` prerelease; updating without --tag moves you to \`${HW}\`. Use \`--tag next\` to stay on the next channel.`}function readSelfDir(){let t=process.env.GJSIFY_CLI_PACKAGE_JSON;if(t)return En(xn(t));let n=fileURLToPath(import.meta.url),S=En(xn(n));for(let t=0;t<8&&S!==En(S);t++){if(existsSync(wn(S,`package.json`)))return S;S=En(S)}return En(xn(n))}function readCurrentVersion(){try{let t=process.env.GJSIFY_CLI_PACKAGE_JSON;if(t){let n=JSON.parse(readFileSync(t,`utf-8`));return n.name===VW&&typeof n.version==`string`?n.version:null}let n=En(xn(fileURLToPath(import.meta.url)));for(let t=0;t<8&&n!==En(n);t++){let t=wn(n,`package.json`);if(existsSync(t)){let n=JSON.parse(readFileSync(t,`utf-8`));if(n.name===VW&&typeof n.version==`string`)return n.version}n=En(n)}}catch{}return null}function resolveTag(t,n){let S=t[`dist-tags`]??{};return S[n]?S[n]:t.versions&&typeof t.versions==`object`&&t.versions[n]?n:null}var VW,HW,UW,WW,GW=__esmMin(()=>{_e(),Rd(),Pn(),Gn(),eh(),XP(),aR(),BW(),lR(),pR(),WL(),KL(),VW=`@gjsify/cli`,HW=`latest`,UW={command:`self-update`,description:`Update the installed ${VW} to the latest release (or pinned --tag).`,builder:t=>t.option(`check`,{description:`Only check whether a newer version is available; do not install.`,type:`boolean`,default:!1}).option(`force`,{description:`Reinstall even when the current version already matches the target tag.`,type:`boolean`,default:!1}).option(`tag`,{description:"npm dist-tag or pinned version to install (e.g. `latest`, `next`, `0.5.0`).",type:`string`}).option(`prune`,{description:`After updating, remove packages an earlier install left behind that this host cannot use (foreign os/cpu/libc). Use --no-prune to disable.`,type:`boolean`,default:!0}).option(`skip-deps`,{description:`Update only the @gjsify/cli bundle itself; do not pull its runtime dependencies (rolldown, lightningcss, @gjsify/tsc, the native gi:// bridges, …). Faster, but can leave the on-disk runtime deps stale relative to the new bundle.`,type:`boolean`,default:!1}),handler:async t=>{let n=defaultGlobalLayout(),S=wn(wn(n.prefix,`node_modules`,VW),`package.json`),C=readCurrentVersion(),N=existsSync(S);ge.log(`Current ${VW}: v${C??`(unknown)`}`);let F=classifyInstall({selfDir:readSelfDir(),xdgPrefix:n.prefix});if(F.managedElsewhere)return ge.error(`\ngjsify self-update: this gjsify is managed by something else — ${F.evidence}.\nUpdating it from here would write ${n.prefix} and leave you running two installs.\n\nUpdate with: ${F.updateWith}\n`),process.exit(1);N||ge.warn(`\nWarning: no @gjsify/cli install found under ${n.prefix}.\nself-update only manages installs created by install.mjs or \`gjsify install -g\`.\nIf you installed via \`npm install -g\`, remove that and use:\n curl -fsSL https://github.com/gjsify/gjsify/releases/latest/download/install.mjs -o /tmp/g.mjs && gjs -m /tmp/g.mjs && rm /tmp/g.mjs`);let I=t.tag??HW,H=nextChannelNotice({currentVersion:C,requestedTag:t.tag});H&&ge.log(H),ge.log(`Fetching dist-tags for ${VW}@${I} ...`);let W;try{W=await fetchPackument(VW)}catch(t){let n=t instanceof Error?t.message:String(t);return ge.error(`Failed to fetch packument: ${n}`),process.exit(1)}let q=resolveTag(W,I);if(!q)return ge.error(`Unknown dist-tag '${I}' on ${VW}. Known tags: ${Object.keys(W[`dist-tags`]??{}).join(`, `)||`(none)`}`),process.exit(1);ge.log(`Latest matching --tag ${I}: v${q}`);let Y=N&&!hasBundlerEngineInstalled(n.prefix),X=Y&&!t.skipDeps&&!t.check;if(C===q&&!t.force&&!X){ge.log(`Already up to date (v${q}).`),Y&&t.skipDeps&&ge.log("Note: the GJS bundler engine @gjsify/rolldown-native is not installed — re-run without --skip-deps to repair it (`gjsify build` needs it under GJS)."),t.check||ge.log(`Run with --force to reinstall anyway.`);return}if(X&&C===q&&!t.force&&ge.log(`@gjsify/cli is at v${q} but the GJS bundler engine @gjsify/rolldown-native is missing — repairing.`),t.check)return ge.log(C?`Update available: v${C} → v${q}`:`Install required: → v${q}`),process.exit(1);let Z=!t.skipDeps,te=Z?` + runtime dependencies`:` (bundle only)`;ge.log(`Installing ${VW}@${q}${te} ...`);let ne=makeProgressReporter();try{await installPackages({prefix:n.prefix,specs:[`${VW}@${q}`],verbose:!1,skipDeps:!Z,progress:ne})}catch(t){let n=t instanceof Error?t.message:String(t);return ge.error(`self-update: install failed — ${n}`),ge.error("Re-run `gjsify self-update` to retry."),process.exit(1)}Z&&await installGjsEnginePackages(n.prefix,q,{verbose:!1}),t.prune!==!1&&pruneAfterInstall(n.prefix,resolveHostPlatform({env:{}}),{hint:`gjsify prune -g --dry-run`});let re=linkGlobalBins([VW],n);if(re.length===0)ge.warn("self-update: install completed but no bins were linked — package.json may be missing a `bin` field.");else for(let t of re)ge.log(` • ${t.link} → ${t.target}`);if(globalLayoutIsDefault()){let t=verifyPathResolution({binName:WW,binDir:n.binDir,resolvedBin:resolveBinOnPath(WW,{pathValue:pathWithoutSelfShim()}),runningVersion:C,targetVersion:q});if(!t.ok)return ge.error(`\nInstalled ${VW} v${q} at ${n.prefix}`),ge.error(t.message),process.exit(1)}ge.log(`\nUpdated ${VW} to v${q}.`),Z?ge.log(`Runtime dependencies were resolved alongside the bundle.`):ge.log(`Bundle-only update (--skip-deps): on-disk runtime dependencies were left unchanged.`)}},WW=`gjsify`});function loadInstallerTemplate(){return`#!/usr/bin/env -S gjs -m
1215
1215
  /**
1216
1216
  * gjsify universal installer — bootstraps \`@gjsify/cli\` (or any GJS app on npm)
1217
1217
  * on a system that has only \`gjs\` and libsoup: no Node, no npm. Decision and
@@ -1736,28 +1736,28 @@ async function main() {
1736
1736
  }
1737
1737
 
1738
1738
  await main();
1739
- `}function pickDefaultBinName(t,n){let S=t?.gjsify?.bin;if(S&&typeof S==`object`){let t=Object.keys(S)[0];if(t)return t}let C=t?.bin;if(C&&typeof C==`object`){let t=Object.keys(C)[0];if(t)return t}return n.startsWith(`@`)?n.slice(n.indexOf(`/`)+1):n}var zW,BW,VW=__esmMin(()=>{_e(),Rd(),Pn(),zW=`https://github.com/gjsify/gjsify/releases/latest/download/cli.gjs.mjs`,BW={command:`generate-installer [target]`,description:`Scaffold an install.mjs in the current directory for a GJS-runnable npm package.`,builder:t=>t.positional(`target`,{description:`Npm package name to install (default: current package.json name).`,type:`string`}).option(`bin-name`,{description:"Bin name produced by the installer (default: first key of `gjsify.bin` or `bin`).",type:`string`}).option(`bootstrap-url`,{description:`Override the cli.gjs.mjs bootstrap bundle URL (default: gjsify GitHub releases/latest).`,type:`string`}).option(`output`,{description:`Where to write the generated installer.`,type:`string`,default:`install.mjs`}).option(`force`,{description:`Overwrite an existing output file.`,type:`boolean`,default:!1}),handler:t=>{let n=xn(process.cwd(),t.output);if(existsSync(n)&&!t.force)return ge.error(`${t.output} already exists. Re-run with --force to overwrite.`),process.exit(1);let S=xn(process.cwd(),`package.json`),C=null;if(existsSync(S))try{C=JSON.parse(readFileSync(S,`utf-8`))}catch{}let N=t.target??C?.name;if(!N)return ge.error("No target package: pass `gjsify generate-installer <pkg>` or run inside a directory with a package.json."),process.exit(1);let F=t[`bin-name`]??pickDefaultBinName(C,N),I=t[`bootstrap-url`]??zW;writeFileSync(n,loadInstallerTemplate().replace(/const DEFAULT_TARGET = '[^']+';/,`const DEFAULT_TARGET = ${JSON.stringify(N)};`).replace(/const DEFAULT_BIN_NAME = '[^']+';/,`const DEFAULT_BIN_NAME = ${JSON.stringify(F)};`).replace(/const DEFAULT_BOOTSTRAP_URL =\s*'[^']+';/,`const DEFAULT_BOOTSTRAP_URL = ${JSON.stringify(I)};`),{mode:493}),ge.log(`Wrote ${t.output} (target=${N}, bin=${F}).`),ge.log(``),ge.log(`Install one-liner for your README:`),ge.log(` curl -fsSL https://github.com/<you>/<repo>/raw/main/${t.output} -o /tmp/i.mjs \\`),ge.log(` && gjs -m /tmp/i.mjs && rm /tmp/i.mjs`)}}}),HW,UW=__esmMin(()=>{_e(),Rd(),TL(),iR(),zL(),VL(),HW={command:`prune`,description:`Remove installed packages this host cannot use (foreign os/cpu/libc). Reads each package manifest — a package that declares no platform is never touched.`,builder:t=>t.option(`global`,{description:"Prune the user-global XDG prefix (the `install -g` target) instead of the project.",type:`boolean`,alias:`g`,default:!1}).option(`dry-run`,{description:`Report what would be removed without touching the filesystem.`,type:`boolean`,default:!1}).option(`verbose`,{description:`List every package rather than the first few.`,type:`boolean`,default:!1}).option(`os`,{description:`Prune AS IF the host were this OS (linux, darwin, win32). Defaults to this host.`,type:`string`}).option(`cpu`,{description:`Prune AS IF the host were this architecture (x64, arm64, …). Defaults to this host.`,type:`string`}).option(`libc`,{description:`Prune AS IF the host used this libc (glibc, musl). Defaults to this host.`,type:`string`}),handler:async t=>{let n=t.global?defaultGlobalLayout():null,S=n?n.prefix:process.cwd();if(!existsSync(`${S}/node_modules`)){ge.log(`gjsify prune: nothing installed at ${S}`);return}let C=resolveHostPlatform({env:{...t.os?{npm_config_os:t.os}:{},...t.cpu?{npm_config_cpu:t.cpu}:{},...t.libc?{npm_config_libc:t.libc}:{}}}),N=await acquireInstallLock(S,{}),F;try{F=executePrune(planPrune({prefix:S,target:C}),{dryRun:t.dryRun})}finally{N.release()}if(ge.log(formatPruneReport(F,{dryRun:t.dryRun,verbose:t.verbose})),F.failed.length>0)return process.exit(1)}}});function isInside(t,n){let S=Tn(t,n);return S===``?!0:S!==`..`&&!S.startsWith(`..${jn}`)&&!Cn(S)}function findBinShimsForPackage(t,n,S){if(!existsSync(t))return[];let C=[],N;try{N=readdirSync(t)}catch{return[]}for(let F of N){let N=wn(t,F);try{if(!statSync(N).isFile())continue;let t=readFileSync(N,`utf-8`);if(!t.startsWith(`#!/bin/sh`))continue;let S=t.split(`
1740
- `).find(t=>/^exec (?:gjs -m )?'/.test(t));if(!S)continue;let F=S.match(/'([^']+)'/);if(!F)continue;let I=F[1];if(isInside(n,I)){C.push(N);for(let t of[`.cmd`,`.ps1`])existsSync(N+t)&&C.push(N+t)}}catch(t){S&&ge.warn(` ? could not inspect ${N}: ${t.message}`)}}return C}var WW,GW=__esmMin(()=>{_e(),Rd(),Pn(),iR(),WW={command:`uninstall <packages..>`,description:"Uninstall a previously installed package. Currently only `--global` mode is supported.",builder:t=>t.positional(`packages`,{description:`Package(s) to uninstall (npm names, optionally with version).`,type:`string`,array:!0,demandOption:!0}).option(`global`,{description:`Uninstall from the user-global XDG location (the install -g target).`,type:`boolean`,alias:`g`,default:!1}).option(`dry-run`,{description:`Show what would be removed without touching the filesystem.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Verbose logging.`,type:`boolean`,default:!1}),handler:t=>{if(!t.global)return ge.error("gjsify uninstall currently only supports --global. For project-local removal, edit package.json + re-run `gjsify install`."),process.exit(1);let n=defaultGlobalLayout(),S=t[`dry-run`]??!1,C=t.verbose??!1,N=`gjsify uninstall${S?` (dry-run)`:``} --global`;ge.log(`${N} ← ${n.prefix}`),ge.log(`${` `.repeat(N.length)} bins ← ${n.binDir}`);let F=!1;for(let N of t.packages){let t=specToPackageName(N),I=wn(n.prefix,`node_modules`,t);if(!existsSync(I)){ge.warn(` ✗ ${t} — not installed at ${I}`);continue}let H=findBinShimsForPackage(n.binDir,I,C);if(S){ge.log(` • would remove ${I}`);for(let t of H)ge.log(` • would remove ${t}`)}else{rmSync(I,{recursive:!0,force:!0}),ge.log(` • removed ${I}`);for(let t of H)unlinkSync(t),ge.log(` • removed ${t}`)}F=!0}F||(ge.error(`
1739
+ `}function pickDefaultBinName(t,n){let S=t?.gjsify?.bin;if(S&&typeof S==`object`){let t=Object.keys(S)[0];if(t)return t}let C=t?.bin;if(C&&typeof C==`object`){let t=Object.keys(C)[0];if(t)return t}return n.startsWith(`@`)?n.slice(n.indexOf(`/`)+1):n}var KW,qW,JW=__esmMin(()=>{_e(),Rd(),Pn(),KW=`https://github.com/gjsify/gjsify/releases/latest/download/cli.gjs.mjs`,qW={command:`generate-installer [target]`,description:`Scaffold an install.mjs in the current directory for a GJS-runnable npm package.`,builder:t=>t.positional(`target`,{description:`Npm package name to install (default: current package.json name).`,type:`string`}).option(`bin-name`,{description:"Bin name produced by the installer (default: first key of `gjsify.bin` or `bin`).",type:`string`}).option(`bootstrap-url`,{description:`Override the cli.gjs.mjs bootstrap bundle URL (default: gjsify GitHub releases/latest).`,type:`string`}).option(`output`,{description:`Where to write the generated installer.`,type:`string`,default:`install.mjs`}).option(`force`,{description:`Overwrite an existing output file.`,type:`boolean`,default:!1}),handler:t=>{let n=xn(process.cwd(),t.output);if(existsSync(n)&&!t.force)return ge.error(`${t.output} already exists. Re-run with --force to overwrite.`),process.exit(1);let S=xn(process.cwd(),`package.json`),C=null;if(existsSync(S))try{C=JSON.parse(readFileSync(S,`utf-8`))}catch{}let N=t.target??C?.name;if(!N)return ge.error("No target package: pass `gjsify generate-installer <pkg>` or run inside a directory with a package.json."),process.exit(1);let F=t[`bin-name`]??pickDefaultBinName(C,N),I=t[`bootstrap-url`]??KW;writeFileSync(n,loadInstallerTemplate().replace(/const DEFAULT_TARGET = '[^']+';/,`const DEFAULT_TARGET = ${JSON.stringify(N)};`).replace(/const DEFAULT_BIN_NAME = '[^']+';/,`const DEFAULT_BIN_NAME = ${JSON.stringify(F)};`).replace(/const DEFAULT_BOOTSTRAP_URL =\s*'[^']+';/,`const DEFAULT_BOOTSTRAP_URL = ${JSON.stringify(I)};`),{mode:493}),ge.log(`Wrote ${t.output} (target=${N}, bin=${F}).`),ge.log(``),ge.log(`Install one-liner for your README:`),ge.log(` curl -fsSL https://github.com/<you>/<repo>/raw/main/${t.output} -o /tmp/i.mjs \\`),ge.log(` && gjs -m /tmp/i.mjs && rm /tmp/i.mjs`)}}}),YW,XW=__esmMin(()=>{_e(),Rd(),AL(),lR(),WL(),KL(),YW={command:`prune`,description:`Remove installed packages this host cannot use (foreign os/cpu/libc). Reads each package manifest — a package that declares no platform is never touched.`,builder:t=>t.option(`global`,{description:"Prune the user-global XDG prefix (the `install -g` target) instead of the project.",type:`boolean`,alias:`g`,default:!1}).option(`dry-run`,{description:`Report what would be removed without touching the filesystem.`,type:`boolean`,default:!1}).option(`verbose`,{description:`List every package rather than the first few.`,type:`boolean`,default:!1}).option(`os`,{description:`Prune AS IF the host were this OS (linux, darwin, win32). Defaults to this host.`,type:`string`}).option(`cpu`,{description:`Prune AS IF the host were this architecture (x64, arm64, …). Defaults to this host.`,type:`string`}).option(`libc`,{description:`Prune AS IF the host used this libc (glibc, musl). Defaults to this host.`,type:`string`}),handler:async t=>{let n=t.global?defaultGlobalLayout():null,S=n?n.prefix:process.cwd();if(!existsSync(`${S}/node_modules`)){ge.log(`gjsify prune: nothing installed at ${S}`);return}let C=resolveHostPlatform({env:{...t.os?{npm_config_os:t.os}:{},...t.cpu?{npm_config_cpu:t.cpu}:{},...t.libc?{npm_config_libc:t.libc}:{}}}),N=await acquireInstallLock(S,{}),F;try{F=executePrune(planPrune({prefix:S,target:C}),{dryRun:t.dryRun})}finally{N.release()}if(ge.log(formatPruneReport(F,{dryRun:t.dryRun,verbose:t.verbose})),F.failed.length>0)return process.exit(1)}}});function isInside(t,n){let S=Tn(t,n);return S===``?!0:S!==`..`&&!S.startsWith(`..${jn}`)&&!Cn(S)}function findBinShimsForPackage(t,n,S){if(!existsSync(t))return[];let C=[],N;try{N=readdirSync(t)}catch{return[]}for(let F of N){let N=wn(t,F);try{if(!statSync(N).isFile())continue;let t=readFileSync(N,`utf-8`);if(!t.startsWith(`#!/bin/sh`))continue;let S=t.split(`
1740
+ `).find(t=>/^exec (?:gjs -m )?'/.test(t));if(!S)continue;let F=S.match(/'([^']+)'/);if(!F)continue;let I=F[1];if(isInside(n,I)){C.push(N);for(let t of[`.cmd`,`.ps1`])existsSync(N+t)&&C.push(N+t)}}catch(t){S&&ge.warn(` ? could not inspect ${N}: ${t.message}`)}}return C}var ZW,QW=__esmMin(()=>{_e(),Rd(),Pn(),lR(),ZW={command:`uninstall <packages..>`,description:"Uninstall a previously installed package. Currently only `--global` mode is supported.",builder:t=>t.positional(`packages`,{description:`Package(s) to uninstall (npm names, optionally with version).`,type:`string`,array:!0,demandOption:!0}).option(`global`,{description:`Uninstall from the user-global XDG location (the install -g target).`,type:`boolean`,alias:`g`,default:!1}).option(`dry-run`,{description:`Show what would be removed without touching the filesystem.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Verbose logging.`,type:`boolean`,default:!1}),handler:t=>{if(!t.global)return ge.error("gjsify uninstall currently only supports --global. For project-local removal, edit package.json + re-run `gjsify install`."),process.exit(1);let n=defaultGlobalLayout(),S=t[`dry-run`]??!1,C=t.verbose??!1,N=`gjsify uninstall${S?` (dry-run)`:``} --global`;ge.log(`${N} ← ${n.prefix}`),ge.log(`${` `.repeat(N.length)} bins ← ${n.binDir}`);let F=!1;for(let N of t.packages){let t=specToPackageName(N),I=wn(n.prefix,`node_modules`,t);if(!existsSync(I)){ge.warn(` ✗ ${t} — not installed at ${I}`);continue}let H=findBinShimsForPackage(n.binDir,I,C);if(S){ge.log(` • would remove ${I}`);for(let t of H)ge.log(` • would remove ${t}`)}else{rmSync(I,{recursive:!0,force:!0}),ge.log(` • removed ${I}`);for(let t of H)unlinkSync(t),ge.log(` • removed ${t}`)}F=!0}F||(ge.error(`
1741
1741
  No packages removed.`),process.exit(1))}}});function globToRegexSource(t){let n=``,S=0;for(;S<t.length;){let C=t[S];if(C===`*`&&t[S+1]===`*`&&(S===0||t[S-1]===`/`)){if(S+2===t.length){n+=`.*`,S+=2;continue}if(t[S+2]===`/`){n+=`(?:.*/)?`,S+=3;continue}}if(C===`*`)for(n+=`[^/]*`;t[S+1]===`*`;)S++;else if(C===`?`)n+=`[^/]`;else if(C===`[`){let C=findClassEnd(t,S);if(C===-1)n+=`\\[`;else{let N=t.slice(S+1,C),F=!1;(N.startsWith(`!`)||N.startsWith(`^`))&&(F=!0,N=N.slice(1)),N=N.replace(/\]/g,`\\]`),n+=`[${F?`^/`:``}${N}]`,S=C}}else C===`\\`&&S+1<t.length?(S++,n+=escapeRegex(t[S])):n+=escapeRegex(C);S++}return n}function findClassEnd(t,n){let S=n+1;for((t[S]===`!`||t[S]===`^`)&&S++,t[S]===`]`&&S++;S<t.length;S++)if(t[S]===`]`)return S;return-1}function escapeRegex(t){return/[.+^${}()|[\]\\*?]/.test(t)?`\\${t}`:t}function parseLine(t){let n=t.replace(/\r$/,``);if(n=n.replace(/(?<!\\)\s+$/,``),n===``||n.startsWith(`#`))return null;let S=!1;n.startsWith(`!`)?(S=!0,n=n.slice(1)):(n.startsWith(`\\!`)||n.startsWith(`\\#`))&&(n=n.slice(1));let C=!1;if(n.endsWith(`/`)&&!n.endsWith(`\\/`)&&(C=!0,n=n.slice(0,-1)),n===``)return null;let N=n.includes(`/`);n.startsWith(`/`)&&(n=n.slice(1));let F=globToRegexSource(n);return{re:RegExp(`^${N?``:`(?:.*/)?`}${F}$`),negate:S,dirOnly:C}}function compileGitignore(t,n){let S=[];for(let n of t){let t=parseLine(n);t&&S.push(t)}let relOf=t=>{let S=Tn(n,t);return S===``||S===`..`||S.startsWith(`..${jn}`)||Cn(S)?null:jn===`/`?S:S.split(jn).join(`/`)},decide=(t,n)=>{for(let C=S.length-1;C>=0;C--){let N=S[C];if(!(N.dirOnly&&!n)&&N.re.test(t))return N.negate?`whitelist`:`ignore`}return null};return{base:n,matched(t,n){if(S.length===0)return null;let C=relOf(t);return C===null?null:decide(C,n)},matchedPathOrAnyParents(t,n){if(S.length===0)return null;let C=relOf(t);if(C===null)return null;let N=n;for(;;){let t=decide(C,N);if(t!==null)return t;let n=C.lastIndexOf(`/`);if(n===-1)return null;C=C.slice(0,n),N=!0}}}}function readGitignoreFile(t,n=En(t)){let S;try{S=readFileSync(t,`utf-8`)}catch{return null}return compileGitignore(S.split(`
1742
- `),n)}var KW=__esmMin(()=>{Rd(),Pn()});function externalParserFor(t,n=!1){if(YW.has(t))return null;let S=On(t).slice(1),C=JW[t]??(S?qW[S]:void 0)??null;return C===`svelte`&&!n?null:C}function scanForNativeSkips(t,n=process.cwd(),S={}){let C=[],N=0,F=t.filter(t=>t.startsWith(`!`)).map(t=>t.slice(1)),I=[],H=readGitignoreFile(wn(n,`.prettierignore`));H&&I.push(H),F.length&&I.push(compileGitignore(F,n));let globallyIgnored=(t,n,S)=>I.some(C=>(S?C.matchedPathOrAnyParents(t,n):C.matched(t,n))===`ignore`),W=S.configPath?xn(n,S.configPath):null,q=loadScope(W??discoverConfig(n)),Y=W===null,scopeFor=t=>Y?nearestScope(t,q):q,expandBraces=t=>{let n=/\{([^{}]*)\}/.exec(t);return n?n[1].split(`,`).flatMap(S=>expandBraces(t.slice(0,n.index)+S+t.slice(n.index+n[0].length))):[t]},X=[],Z=new Set;for(let S of t){if(S.startsWith(`!`))continue;let t=xn(n,S);if(/[*?[{]/.test(S)&&!existsSync(t))for(let t of expandBraces(S))X.push(RegExp(`^${globToRegexSource(t.includes(`/`)?t:`**/${t}`)}$`));else Z.add(t)}(X.length||Z.size===0)&&Z.add(xn(n));let record=(t,n)=>{n?.ignore?.matchedPathOrAnyParents(t,!1)!==`ignore`&&(N++,externalParserFor(Dn(t),n?.svelte)&&C.push(t))},te=[];for(let t of Z){let n;try{n=statSync(t)}catch{continue}globallyIgnored(t,n.isDirectory(),!0)||(n.isDirectory()?te.push(t):n.isFile()&&record(t,scopeFor(En(t))))}let matchesGlob=t=>{if(!X.length||Z.has(t))return!0;let S=Tn(n,t).split(jn).join(`/`);return X.some(t=>t.test(S))},ne=new Set,walk=(t,n,S)=>{if(ne.has(t))return;ne.add(t);let C=readGitignoreFile(wn(t,`.gitignore`)),N=C?[C,...n]:n;Y&&t!==S?.dir&&(S=scopeAt(t)??S);let F;try{F=readdirSync(t,{withFileTypes:!0})}catch{return}for(let n of F){let C=wn(t,n.name),F=n.isDirectory();!F&&!n.isFile()||F&&(XW.has(n.name)||n.name===`node_modules`)||globallyIgnored(C,F,!1)||gitIgnored(N,C,F)||(F?walk(C,N,S):matchesGlob(C)&&record(C,S))}},re=te.every(t=>repoRootOf(t)!==null);for(let t of te)walk(t,parentGitignores(t,re?repoRootOf(t):null,re),scopeFor(t));return{skipped:C,total:N}}function gitIgnored(t,n,S){for(let C of t){let t=C.matched(n,S);if(t!==null)return t===`ignore`}return!1}function parentGitignores(t,n,S){if(S&&n===null)return[];let C=[];for(let S=t;S!==n;){let t=En(S);if(t===S)break;S=t;let n=readGitignoreFile(wn(S,`.gitignore`));n&&C.push(n)}let N=n?readGitignoreFile(wn(n,`.git`,`info`,`exclude`),n):null;return N&&C.push(N),C}function repoRootOf(t){for(let n=t;;n=En(n)){if(existsSync(wn(n,`.git`))||existsSync(wn(n,`.jj`)))return n;if(En(n)===n)return null}}function configIn(t){for(let n of ZW){let S=wn(t,n);if(existsSync(S))return S}return null}function discoverConfig(t){for(let n=xn(t);;n=En(n)){let t=configIn(n);if(t)return t;if(En(n)===n)return null}}function scopeAt(t){let n=configIn(t);return n?loadScope(n):null}function nearestScope(t,n){for(;;t=En(t)){if(n&&t===n.dir)return n;let S=scopeAt(t);if(S)return S;if(En(t)===t)return n}}function loadScope(t){if(!t)return null;let n=En(t),S={};try{S=parseJsonc(readFileSync(t,`utf-8`))}catch{S={}}let C=Array.isArray(S.ignorePatterns)?S.ignorePatterns.filter(t=>typeof t==`string`):[];return{dir:n,ignore:C.length?compileGitignore(C,n):null,svelte:S.svelte!==void 0&&S.svelte!==null&&S.svelte!==!1}}function parseJsonc(t){let pass=(t,n)=>{let S=``;for(let C=0;C<t.length;){if(t[C]===`"`){let n=C+1;for(;n<t.length&&t[n]!==`"`;)n+=t[n]===`\\`?2:1;S+=t.slice(C,n+1),C=n+1;continue}let N=n(t,C);N>0?C+=N:S+=t[C++]}return S},n=pass(t,(t,n)=>{if(t.startsWith(`//`,n)){let S=t.indexOf(`
1743
- `,n);return(S===-1?t.length:S)-n}if(t.startsWith(`/*`,n)){let S=t.indexOf(`*/`,n+2);return(S===-1?t.length:S+2)-n}return 0});return JSON.parse(pass(n,(t,n)=>t[n]===`,`&&/^\s*[}\]]/.test(t.slice(n+1))?1:0))}var parsers,qW,JW,YW,XW,ZW,QW=__esmMin(()=>{Rd(),Pn(),KW(),parsers=(t,n)=>Object.fromEntries(n.map(n=>[n,t])),qW={...parsers(`yaml`,[`yml`,`mir`,`reek`,`rviz`,`sublime-syntax`,`syntax`,`yaml`,`yaml-tmlanguage`]),...parsers(`markdown`,[`md`,`livemd`,`markdown`,`mdown`,`mdwn`,`mkd`,`mkdn`,`mkdown`,`ronn`,`scd`,`workbook`]),...parsers(`html`,[`html`,`hta`,`htm`,`inc`,`xht`,`xhtml`]),...parsers(`glimmer`,[`handlebars`,`hbs`]),mdx:`mdx`,vue:`vue`,svelte:`svelte`,mjml:`mjml`},JW={...parsers(`yaml`,[`.clang-format`,`.clang-tidy`,`.clangd`,`.gemrc`,`CITATION.cff`,`glide.lock`]),...parsers(`yaml`,[`pixi.lock`,`.prettierrc`,`.stylelintrc`,`.lintstagedrc`]),...parsers(`markdown`,[`contents.lr`,`README`])},YW=new Set([`package-lock.json`,`pnpm-lock.yaml`,`yarn.lock`,`MODULE.bazel.lock`,`bun.lock`,`deno.lock`,`composer.lock`,`Package.resolved`,`Pipfile.lock`,`flake.lock`,`mcmod.info`,`Cargo.lock`,`Gopkg.lock`,`pdm.lock`,`poetry.lock`,`uv.lock`]),XW=new Set([`.git`,`.jj`,`.sl`,`.svn`,`.hg`]),ZW=[`.oxfmtrc.json`,`.oxfmtrc.jsonc`]});function handleInit({cwd:t,force:n}){let writeOne=(S,C)=>{let N=xn(t,S);if(existsSync(N)&&!n){ge.log(`[gjsify format] ${S} exists at ${N} — pass --force to overwrite.`);return}writeFileSync(N,C,`utf-8`),ge.log(`[gjsify format] wrote ${N}`)};writeOne(`.oxlintrc.json`,loadOxlintTemplate()),writeOne(`.oxfmtrc.json`,loadOxfmtTemplate()),ge.log("[gjsify format] Run `gjsify format` to apply the formatter to the project.")}var $W,eG=__esmMin(()=>{_e(),Rd(),Pn(),Oz(),QW(),$W={command:`format [paths..]`,description:`Format source files via oxfmt (Markdown/YAML/HTML/Vue need the napi build).`,builder:t=>t.positional(`paths`,{description:"Files or directories to format. Default: `.`",type:`string`,array:!0}).option(`write`,{description:`Modify files in place (default: true). Pass --no-write to report drift instead.`,type:`boolean`,default:!0}).option(`check`,{description:`Report formatting drift without modifying files; exit non-zero if any file is unformatted. Useful for CI.`,type:`boolean`,default:!1}).option(`config-path`,{description:`Path to an .oxfmtrc.json. Default: walks up from cwd to find one.`,type:`string`,normalize:!0}).option(`init`,{description:`Write recommended .oxlintrc.json + .oxfmtrc.json into cwd (skips existing files unless --force).`,type:`boolean`,default:!1}).option(`force`,{description:`Overwrite existing .oxlintrc.json / .oxfmtrc.json with --init.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo the resolved oxfmt launcher + args before spawning.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd();if(t.init){handleInit({cwd:n,force:t.force??!1});return}let S=t.paths?.length?t.paths:[`.`],C=[];t.check?C.push(`--check`):t.write===!1?C.push(`--list-different`):C.push(`--write`);let N=t.configPath??findOxfmtConfig(n)??void 0;if(N&&C.push(`--config`,xn(N)),C.push(...S),t.check&&await shouldUseNativeOxfmt()){let t=scanForNativeSkips(S,n,{configPath:N});if(t.skipped.length>0){let S=t.skipped.map(t=>` ${Tn(n,t)||t}`).join(`
1744
- `);ge.error(`[gjsify format] ERROR: ${t.skipped.length} file(s) skipped — the native oxfmt (GJS) has no Prettier host for them (Markdown/HTML/Vue/YAML/…):\n${S}\n The format check is INCOMPLETE. Run \`gjsify format --check\` under Node to check these files, or add them to \`ignorePatterns\`.`),setOxcExitCode(1);return}}try{setOxcExitCode(await runOxfmt(C,{cwd:n,verbose:t.verbose}))}catch(t){if(t instanceof OxcNotFoundError){printOxcNotFound(t),setOxcExitCode(1);return}throw t}}}}),tG,nG=__esmMin(()=>{Pn(),Oz(),tG={command:`lint [paths..]`,description:`Run oxlint diagnostics (spawned via its Node launcher to support JS plugins).`,builder:t=>t.positional(`paths`,{description:"Files or directories to lint. Default: `.`",type:`string`,array:!0}).option(`fix`,{description:`Apply safe lint fixes in place.`,type:`boolean`,default:!1}).option(`config-path`,{description:`Path to an .oxlintrc.json. Default: walks up from cwd to find one.`,type:`string`,normalize:!0}).option(`verbose`,{description:`Echo the resolved oxlint launcher + args before spawning.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.paths?.length?t.paths:[`.`],C=[];t.fix&&C.push(`--fix`);let N=t.configPath??findOxlintConfig(n)??void 0;N&&C.push(`--config`,xn(N)),C.push(...S);try{setOxcExitCode(await runOxlint(C,{cwd:n,verbose:t.verbose}))}catch(t){if(t instanceof OxcNotFoundError){printOxcNotFound(t),setOxcExitCode(1);return}throw t}}}}),rG,iG=__esmMin(()=>{Pn(),Oz(),rG={command:`fix [paths..]`,description:`Run oxfmt --write then oxlint --fix — format + safe lint fixes in one pass.`,builder:t=>t.positional(`paths`,{description:"Files or directories to fix. Default: `.`",type:`string`,array:!0}).option(`write`,{description:`Apply fixes in place (default: true). Pass --no-write to report only.`,type:`boolean`,default:!0}).option(`config-path`,{description:`Path to an .oxlintrc.json. Default: walks up from cwd to find one.`,type:`string`,normalize:!0}).option(`verbose`,{description:`Echo the resolved oxc launchers + args before spawning.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.paths?.length?t.paths:[`.`],C=t.verbose??!1,N=t.write!==!1;try{let F=[N?`--write`:`--list-different`],I=t.configPath??findOxfmtConfig(n)??void 0;I&&F.push(`--config`,xn(I)),F.push(...S);let H=await runOxfmt(F,{cwd:n,verbose:C}),W=[];N&&W.push(`--fix`);let q=t.configPath??findOxlintConfig(n)??void 0;q&&W.push(`--config`,xn(q)),W.push(...S);let Y=await runOxlint(W,{cwd:n,verbose:C});setOxcExitCode(H||Y)}catch(t){if(t instanceof OxcNotFoundError){printOxcNotFound(t),setOxcExitCode(1);return}throw t}}}});function createInterface(t,n){return typeof t==`object`&&t&&!(`read`in t&&typeof t.read==`function`)?new Interface(t):new Interface({input:t,output:n})}var Interface,aG=__esmMin(()=>{Ad(),Interface=class extends Interface$1{question(t,n){return new Promise(n=>{super.question(t,n)})}}});function semverGt(t,n){try{return compare(t,n)===1}catch{return!1}}function groupByDependency(t){let n=new Map;for(let S of t){let t=n.get(S.name);t||(t={name:S.name,occurrences:[],declaredRanges:new Set,dominantRange:S.currentRange,highestVersion:S.currentVersion},n.set(S.name,t)),t.occurrences.push(S),t.declaredRanges.add(S.currentRange),S.currentVersion&&(!t.highestVersion||semverGt(S.currentVersion,t.highestVersion))&&(t.highestVersion=S.currentVersion)}for(let t of n.values()){let n=new Map;for(let S of t.occurrences)n.set(S.currentRange,(n.get(S.currentRange)??0)+1);let S=t.occurrences[0].currentRange,C=-1,N=null;for(let[t,F]of n.entries()){let n=parse(t.replace(/^[\^~>=<]+/,``))?.version??null;(F>C||F===C&&n&&N&&semverGt(n,N)||F===C&&t<S)&&(S=t,C=F,N=n)}t.dominantRange=S}return[...n.values()].sort((t,n)=>t.name.localeCompare(n.name))}function isInconsistent(t){return t.declaredRanges.size>1}function findInconsistencies(t){return t.filter(isInconsistent)}var oG=__esmMin(()=>{XP()});function discoverContext(t){let n=findWorkspaceRoot(t);if(n)return{root:n,workspaces:discoverWorkspaces(n,{includeRoot:!0}),isMonorepo:!0};let S=wn(t,`package.json`);if(!existsSync(S))throw Error(`[gjsify upgrade] no package.json at ${S}`);let C=JSON.parse(readFileSync(S,`utf-8`));return{root:t,workspaces:[{name:C.name??`<root>`,location:t,relativeLocation:`.`,version:C.version??`0.0.0`,manifest:C,private:C.private===!0}],isMonorepo:!1}}function applyWorkspaceFilter(t,n,S){let C=n?.split(`,`).map(t=>t.trim()).filter(Boolean),N=S?.split(`,`).map(t=>t.trim()).filter(Boolean);return(!C||C.length===0)&&(!N||N.length===0)?t:filterWorkspaces(t,{include:C,exclude:N})}function parseFilterList(t){return t?t.split(`,`).map(t=>t.trim().toLowerCase()).filter(Boolean):[]}function collectAllDeclarations(t,n){let S=[];for(let C of t)for(let t of collectFromWorkspace(C,n))S.push(t);return S}function collectFromWorkspace(t,n){let S=[],C=t.manifest;for(let N of cG){let F=C[N];if(!(!F||typeof F!=`object`))for(let[C,I]of Object.entries(F)){if(typeof I!=`string`||n.length&&!n.some(t=>C.toLowerCase().includes(t))||isDistTagSpec(I)||I.startsWith(`workspace:`)||I.startsWith(`file:`)||I.startsWith(`link:`)||I.startsWith(`git+`)||I.startsWith(`git:`)||I.startsWith(`http:`)||I.startsWith(`https:`)||I.startsWith(`npm:`)||I.startsWith(`portal:`))continue;let{prefix:F,version:H}=splitRange(I);S.push({workspace:t.name,workspaceLocation:t.location,name:C,field:N,currentRange:I,currentVersion:H,prefix:F})}}return S}function isDistTagSpec(t){let n=t.trim();return lG.has(n)||!/^[A-Za-z]/.test(n)||/^v\d/.test(n)||/^v[xX*]/.test(n)?!1:/^[A-Za-z][\w.-]*$/.test(n)}function splitRange(t){let n=t.match(/^(\^|~|>=|<=|>|<|=)?\s*([0-9].*)$/);if(!n)return{prefix:``,version:null};let S=n[1]??``,C=n[2]?.split(/\s|[|&,]/)[0]??null;return{prefix:S,version:(C?parse(C):null)?.version??null}}function reportInexactRanges(t){let n=t.map(t=>({name:t.name,loose:t.occurrences.filter(t=>t.prefix!==``)})).filter(t=>t.loose.length>0);if(n.length===0)return 0;let S=n.reduce((t,n)=>t+n.loose.length,0);ge.error(`gjsify upgrade --check --exact: FAIL. ${S} declaration(s) across ${n.length} dep(s) carry a range operator:\n`);for(let t of n){let n=new Map;for(let S of t.loose){let t=n.get(S.currentRange)??[];t.push(S.workspace),n.set(S.currentRange,t)}ge.error(` ${uG.bold}${t.name}${uG.reset}`);for(let[t,S]of n.entries()){let n=S.length>6?`${S.slice(0,6).join(`, `)} … +${S.length-6}`:S.join(`, `);ge.error(` ${t.padEnd(16)} — ${n}`)}}return S}function checkLockfileRangeViolations(t,n){let S=wn(n,`gjsify-lock.json`);if(!existsSync(S))return 0;let C;try{C=JSON.parse(readFileSync(S,`utf-8`))}catch{return 0}if(!C.packages)return 0;let N=new Map;for(let n of t){let t=N.get(n.name)??new Set;for(let S of n.occurrences)t.add(S.currentRange);N.set(n.name,t)}let F=0;for(let[t,n]of Object.entries(C.packages)){if(!n.version)continue;let S=t.split(`node_modules/`);if(S.length!==2)continue;let C=S[1],I=N.get(C);if(!I||I.size===0)continue;let H=!1;for(let t of I)try{if(n.version&&satisfies(n.version,t)){H=!0;break}}catch{}H||(ge.error(` ${C}: lockfile has ${n.version}, but declared ranges are ${[...I].join(`, `)}`),F++)}return F>0&&ge.error(`gjsify upgrade --check: FAIL. ${F} lockfile entr${F===1?`y`:`ies`} violate declared ranges:\n`),F}function runCheckMode(t,n=!1,S=process.cwd()){checkLockfileRangeViolations(t,S);let C=n?reportInexactRanges(t):0,N=findInconsistencies(t);if(N.length===0&&C>0)return ge.error("\nFix: run `gjsify upgrade --align --exact` (offline; drops the operator and keeps the version)."),process.exit(1);if(N.length===0){ge.log(`gjsify upgrade --check: OK. ${t.length} dep(s) consistently declared across workspaces`+(n?`, every declaration pinned exactly.`:`.`));return}ge.error(`gjsify upgrade --check: FAIL. ${N.length} dep(s) declared at inconsistent ranges:\n`);for(let t of N){let n=new Map;for(let S of t.occurrences){let t=n.get(S.currentRange)??[];t.push(S.workspace),n.set(S.currentRange,t)}ge.error(` ${uG.bold}${t.name}${uG.reset}`);for(let[t,S]of n.entries())ge.error(` ${t.padEnd(16)} — ${S.join(`, `)}`)}ge.error(n?"\nFix: run `gjsify upgrade --align --exact` (offline; aligns each dep to its highest declared version and drops the operator).":"\nFix: run `gjsify upgrade --align` (offline; aligns each dep to its highest declared range)."),process.exit(1)}function alignTargets(t,n){return n?t.filter(t=>isInconsistent(t)||t.occurrences.some(t=>t.prefix!==``)):findInconsistencies(t)}function reportUnrepairable(t){ge.error(`\ngjsify upgrade --align: ${t.length} dep(s) left unrepaired — no version to align on:\n`);for(let n of t)ge.error(` ${uG.bold}${n.name}${uG.reset} ${[...n.declaredRanges].join(`, `)}`);return ge.error("\nThose ranges name no single version. Edit them by hand, or resolve one with `--latest`."),process.exit(1)}function runAlignMode(t,n){let S=n.exact??!1,C=alignTargets(t,S);if(C.length===0){ge.log(`gjsify upgrade --align: nothing to do. ${t.length} dep(s) already consistent`+(S?`, every declaration pinned exactly.`:`.`));return}let N=[],F=[];for(let t of C){if(!t.highestVersion){F.push(t);continue}let n=t.occurrences.find(n=>n.currentRange===t.dominantRange)?.prefix||`^`;N.push({...t,latestVersion:t.highestVersion,diff:`none`,occurrences:t.occurrences.map(t=>({...t,prefix:n}))})}if(N.length>0){ge.log(S?`gjsify upgrade --align --exact: pinning ${N.length} dep(s) to their highest declared version, without a range operator:\n`:`gjsify upgrade --align: aligning ${N.length} inconsistent dep(s) to their highest declared version:\n`);for(let t of N){let n=t.occurrences[0]?.prefix??`^`;ge.log(` ${t.name.padEnd(28)} ranges: ${[...t.declaredRanges].join(`, `)} → ${targetRange(n,t.latestVersion,S)}`)}if(n.dryRun)ge.log(`
1745
- [gjsify upgrade --align] --dry-run: no files changed.`);else{let t=applyToFiles(N,S);ge.log(`\n✏️ updated ${N.length} dep(s) across ${t} package.json file(s).`)}}if(F.length>0)return reportUnrepairable(F)}async function resolveCandidateGroups(t,n,S,C){let N=[],F=0;async function worker(){for(;;){let I=F++;if(I>=t.length)return;let H=t[I];try{let t=(await fetchPackument(H.name,{npmrc:n}))[`dist-tags`]?.latest;if(!t){S&&ge.warn(` ${H.name}: no dist-tags.latest, skipping`);continue}let F=H.highestVersion;if(!F){S&&ge.warn(` ${H.name}: unable to parse any current range`);continue}let I=classifyDiff(F,t);if(I===`none`||C===`minor`&&I===`major`||C===`patch`&&(I===`major`||I===`minor`))continue;N.push({...H,latestVersion:t,diff:I})}catch(t){S&&ge.warn(` ${H.name}: fetch failed (${t.message})`)}}}return await Promise.all(Array.from({length:8},()=>worker())),N.sort((t,n)=>t.name.localeCompare(n.name)),N}function classifyDiff(t,n){let S=parse(t),C=parse(n);return!S||!C?`none`:S.major===C.major?S.minor===C.minor?S.patch===C.patch?(S.prerelease??[]).join(`.`)===(C.prerelease??[]).join(`.`)?`none`:`prerelease`:C.patch>S.patch?`patch`:`none`:C.minor>S.minor?`minor`:`none`:C.major>S.major?`major`:`none`}function colorForDiff(t){switch(t){case`major`:return uG.red;case`minor`:return uG.yellow;case`patch`:return uG.green;case`prerelease`:return uG.cyan;default:return``}}function printTable(t){let n=Math.max(...t.map(t=>t.name.length),4),S=Math.max(...t.map(t=>`${t.occurrences.length}`.length+2),3),C=Math.max(...t.map(t=>declaredCellWidth(t)),7),N=Math.max(...t.map(t=>t.latestVersion.length),6),F=String(t.length).length+2,I=` `.repeat(F+2)+uG.bold+`name`.padEnd(n)+` `+`fan`.padEnd(S)+` `+`declared`.padEnd(C)+` `+`latest`.padEnd(N)+` kind`+uG.reset;ge.log(I),ge.log(` `.repeat(F+2)+uG.dim+`─`.repeat(n+S+C+N+16)+uG.reset);for(let I=0;I<t.length;I++){let H=t[I],W=`${I+1}.`.padEnd(F),q=H.declaredRanges.size>1?`${uG.magenta}⚠ ${uG.reset}`:` `,Y=colorForDiff(H.diff);ge.log(W+q+H.name.padEnd(n)+` `+uG.dim+`${H.occurrences.length}`.padEnd(S)+uG.reset+` `+uG.dim+renderDeclaredCell(H).padEnd(C)+uG.reset+` `+Y+H.latestVersion.padEnd(N)+uG.reset+` `+Y+H.diff+uG.reset)}let H=t.filter(t=>t.declaredRanges.size>1).length;H>0&&ge.log(`\n${uG.magenta}⚠${uG.reset} ${H} dep(s) declared at inconsistent ranges across workspaces.`)}function declaredCellWidth(t){return renderDeclaredCell(t).length}function renderDeclaredCell(t){if(t.declaredRanges.size===1)return[...t.declaredRanges][0];let n=[...t.declaredRanges].sort().join(`, `);return n.length<=32?n:n.slice(0,29)+`…`}function printChangePlan(t,n=!1){for(let S of t)for(let t of S.occurrences)ge.log(` ${t.workspace.padEnd(38)} ${S.name.padEnd(28)} ${t.currentRange.padEnd(12)} → ${targetRange(t.prefix,S.latestVersion,n)}`)}async function promptSelection(t){if(!process.stdin.isTTY)return ge.log(`[gjsify upgrade] non-TTY stdin: pass --latest / --minor / --patch (or --yes for interactive-all) to upgrade non-interactively.`),[];let n=createInterface({input:process.stdin,output:process.stdout});try{ge.log(`
1746
- Select upgrades: comma- or space-separated indices, `+uG.bold+`a`+uG.reset+` for all, ranges like `+uG.bold+`1-3`+uG.reset+`, or `+uG.bold+`ENTER`+uG.reset+` to skip:`);let S=(await n.question(`> `)).trim();if(!S)return[];if(S.toLowerCase()===`a`||S.toLowerCase()===`all`)return[...t];let C=new Set;for(let t of S.split(/[\s,]+/).filter(Boolean)){let n=t.match(/^(\d+)-(\d+)$/);if(n){let t=Number(n[1]),S=Number(n[2]);for(let n=Math.min(t,S);n<=Math.max(t,S);n++)C.add(n-1)}else/^\d+$/.test(t)&&C.add(Number(t)-1)}return[...C].filter(n=>n>=0&&n<t.length).map(n=>t[n])}finally{n.close()}}function targetRange(t,n,S){return S?n:`${t}${n}`}function applyToFiles(t,n=!1){let S=new Map;for(let n of t)for(let t of n.occurrences){let C=S.get(t.workspaceLocation)??[];C.push({...n,occurrences:[t]}),S.set(t.workspaceLocation,C)}let C=0;for(let[t,N]of S.entries()){let S=wn(t,`package.json`),F=readFileSync(S,`utf-8`),I=JSON.parse(F),H=!1,W=[];for(let t of N){let S=t.occurrences[0],C=I[S.field];if(!C)continue;let N=targetRange(S.prefix,t.latestVersion,n);C[t.name]!==N&&(C[t.name]=N,H=!0,W.push(t.name))}if(H){let t=detectIndent(F);writeFileSync(S,keepUntouchedLines(F,JSON.stringify(I,null,t)+(F.endsWith(`
1742
+ `),n)}var $W=__esmMin(()=>{Rd(),Pn()});function externalParserFor(t,n=!1){if(nG.has(t))return null;let S=On(t).slice(1),C=tG[t]??(S?eG[S]:void 0)??null;return C===`svelte`&&!n?null:C}function scanForNativeSkips(t,n=process.cwd(),S={}){let C=[],N=0,F=t.filter(t=>t.startsWith(`!`)).map(t=>t.slice(1)),I=[],H=readGitignoreFile(wn(n,`.prettierignore`));H&&I.push(H),F.length&&I.push(compileGitignore(F,n));let globallyIgnored=(t,n,S)=>I.some(C=>(S?C.matchedPathOrAnyParents(t,n):C.matched(t,n))===`ignore`),W=S.configPath?xn(n,S.configPath):null,q=loadScope(W??discoverConfig(n)),Y=W===null,scopeFor=t=>Y?nearestScope(t,q):q,expandBraces=t=>{let n=/\{([^{}]*)\}/.exec(t);return n?n[1].split(`,`).flatMap(S=>expandBraces(t.slice(0,n.index)+S+t.slice(n.index+n[0].length))):[t]},X=[],Z=new Set;for(let S of t){if(S.startsWith(`!`))continue;let t=xn(n,S);if(/[*?[{]/.test(S)&&!existsSync(t))for(let t of expandBraces(S))X.push(RegExp(`^${globToRegexSource(t.includes(`/`)?t:`**/${t}`)}$`));else Z.add(t)}(X.length||Z.size===0)&&Z.add(xn(n));let record=(t,n)=>{n?.ignore?.matchedPathOrAnyParents(t,!1)!==`ignore`&&(N++,externalParserFor(Dn(t),n?.svelte)&&C.push(t))},te=[];for(let t of Z){let n;try{n=statSync(t)}catch{continue}globallyIgnored(t,n.isDirectory(),!0)||(n.isDirectory()?te.push(t):n.isFile()&&record(t,scopeFor(En(t))))}let matchesGlob=t=>{if(!X.length||Z.has(t))return!0;let S=Tn(n,t).split(jn).join(`/`);return X.some(t=>t.test(S))},ne=new Set,walk=(t,n,S)=>{if(ne.has(t))return;ne.add(t);let C=readGitignoreFile(wn(t,`.gitignore`)),N=C?[C,...n]:n;Y&&t!==S?.dir&&(S=scopeAt(t)??S);let F;try{F=readdirSync(t,{withFileTypes:!0})}catch{return}for(let n of F){let C=wn(t,n.name),F=n.isDirectory();!F&&!n.isFile()||F&&(rG.has(n.name)||n.name===`node_modules`)||globallyIgnored(C,F,!1)||gitIgnored(N,C,F)||(F?walk(C,N,S):matchesGlob(C)&&record(C,S))}},re=te.every(t=>repoRootOf(t)!==null);for(let t of te)walk(t,parentGitignores(t,re?repoRootOf(t):null,re),scopeFor(t));return{skipped:C,total:N}}function gitIgnored(t,n,S){for(let C of t){let t=C.matched(n,S);if(t!==null)return t===`ignore`}return!1}function parentGitignores(t,n,S){if(S&&n===null)return[];let C=[];for(let S=t;S!==n;){let t=En(S);if(t===S)break;S=t;let n=readGitignoreFile(wn(S,`.gitignore`));n&&C.push(n)}let N=n?readGitignoreFile(wn(n,`.git`,`info`,`exclude`),n):null;return N&&C.push(N),C}function repoRootOf(t){for(let n=t;;n=En(n)){if(existsSync(wn(n,`.git`))||existsSync(wn(n,`.jj`)))return n;if(En(n)===n)return null}}function configIn(t){for(let n of iG){let S=wn(t,n);if(existsSync(S))return S}return null}function discoverConfig(t){for(let n=xn(t);;n=En(n)){let t=configIn(n);if(t)return t;if(En(n)===n)return null}}function scopeAt(t){let n=configIn(t);return n?loadScope(n):null}function nearestScope(t,n){for(;;t=En(t)){if(n&&t===n.dir)return n;let S=scopeAt(t);if(S)return S;if(En(t)===t)return n}}function loadScope(t){if(!t)return null;let n=En(t),S={};try{S=parseJsonc(readFileSync(t,`utf-8`))}catch{S={}}let C=Array.isArray(S.ignorePatterns)?S.ignorePatterns.filter(t=>typeof t==`string`):[];return{dir:n,ignore:C.length?compileGitignore(C,n):null,svelte:S.svelte!==void 0&&S.svelte!==null&&S.svelte!==!1}}function parseJsonc(t){let pass=(t,n)=>{let S=``;for(let C=0;C<t.length;){if(t[C]===`"`){let n=C+1;for(;n<t.length&&t[n]!==`"`;)n+=t[n]===`\\`?2:1;S+=t.slice(C,n+1),C=n+1;continue}let N=n(t,C);N>0?C+=N:S+=t[C++]}return S},n=pass(t,(t,n)=>{if(t.startsWith(`//`,n)){let S=t.indexOf(`
1743
+ `,n);return(S===-1?t.length:S)-n}if(t.startsWith(`/*`,n)){let S=t.indexOf(`*/`,n+2);return(S===-1?t.length:S+2)-n}return 0});return JSON.parse(pass(n,(t,n)=>t[n]===`,`&&/^\s*[}\]]/.test(t.slice(n+1))?1:0))}var parsers,eG,tG,nG,rG,iG,aG=__esmMin(()=>{Rd(),Pn(),$W(),parsers=(t,n)=>Object.fromEntries(n.map(n=>[n,t])),eG={...parsers(`yaml`,[`yml`,`mir`,`reek`,`rviz`,`sublime-syntax`,`syntax`,`yaml`,`yaml-tmlanguage`]),...parsers(`markdown`,[`md`,`livemd`,`markdown`,`mdown`,`mdwn`,`mkd`,`mkdn`,`mkdown`,`ronn`,`scd`,`workbook`]),...parsers(`html`,[`html`,`hta`,`htm`,`inc`,`xht`,`xhtml`]),...parsers(`glimmer`,[`handlebars`,`hbs`]),mdx:`mdx`,vue:`vue`,svelte:`svelte`,mjml:`mjml`},tG={...parsers(`yaml`,[`.clang-format`,`.clang-tidy`,`.clangd`,`.gemrc`,`CITATION.cff`,`glide.lock`]),...parsers(`yaml`,[`pixi.lock`,`.prettierrc`,`.stylelintrc`,`.lintstagedrc`]),...parsers(`markdown`,[`contents.lr`,`README`])},nG=new Set([`package-lock.json`,`pnpm-lock.yaml`,`yarn.lock`,`MODULE.bazel.lock`,`bun.lock`,`deno.lock`,`composer.lock`,`Package.resolved`,`Pipfile.lock`,`flake.lock`,`mcmod.info`,`Cargo.lock`,`Gopkg.lock`,`pdm.lock`,`poetry.lock`,`uv.lock`]),rG=new Set([`.git`,`.jj`,`.sl`,`.svn`,`.hg`]),iG=[`.oxfmtrc.json`,`.oxfmtrc.jsonc`]});function handleInit({cwd:t,force:n}){let writeOne=(S,C)=>{let N=xn(t,S);if(existsSync(N)&&!n){ge.log(`[gjsify format] ${S} exists at ${N} — pass --force to overwrite.`);return}writeFileSync(N,C,`utf-8`),ge.log(`[gjsify format] wrote ${N}`)};writeOne(`.oxlintrc.json`,loadOxlintTemplate()),writeOne(`.oxfmtrc.json`,loadOxfmtTemplate()),ge.log("[gjsify format] Run `gjsify format` to apply the formatter to the project.")}var oG,sG=__esmMin(()=>{_e(),Rd(),Pn(),Nz(),aG(),oG={command:`format [paths..]`,description:`Format source files via oxfmt (Markdown/YAML/HTML/Vue need the napi build).`,builder:t=>t.positional(`paths`,{description:"Files or directories to format. Default: `.`",type:`string`,array:!0}).option(`write`,{description:`Modify files in place (default: true). Pass --no-write to report drift instead.`,type:`boolean`,default:!0}).option(`check`,{description:`Report formatting drift without modifying files; exit non-zero if any file is unformatted. Useful for CI.`,type:`boolean`,default:!1}).option(`config-path`,{description:`Path to an .oxfmtrc.json. Default: walks up from cwd to find one.`,type:`string`,normalize:!0}).option(`init`,{description:`Write recommended .oxlintrc.json + .oxfmtrc.json into cwd (skips existing files unless --force).`,type:`boolean`,default:!1}).option(`force`,{description:`Overwrite existing .oxlintrc.json / .oxfmtrc.json with --init.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo the resolved oxfmt launcher + args before spawning.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd();if(t.init){handleInit({cwd:n,force:t.force??!1});return}let S=t.paths?.length?t.paths:[`.`],C=[];t.check?C.push(`--check`):t.write===!1?C.push(`--list-different`):C.push(`--write`);let N=t.configPath??findOxfmtConfig(n)??void 0;if(N&&C.push(`--config`,xn(N)),C.push(...S),t.check&&await shouldUseNativeOxfmt()){let t=scanForNativeSkips(S,n,{configPath:N});if(t.skipped.length>0){let S=t.skipped.map(t=>` ${Tn(n,t)||t}`).join(`
1744
+ `);ge.error(`[gjsify format] ERROR: ${t.skipped.length} file(s) skipped — the native oxfmt (GJS) has no Prettier host for them (Markdown/HTML/Vue/YAML/…):\n${S}\n The format check is INCOMPLETE. Run \`gjsify format --check\` under Node to check these files, or add them to \`ignorePatterns\`.`),setOxcExitCode(1);return}}try{setOxcExitCode(await runOxfmt(C,{cwd:n,verbose:t.verbose}))}catch(t){if(t instanceof OxcNotFoundError){printOxcNotFound(t),setOxcExitCode(1);return}throw t}}}}),cG,lG=__esmMin(()=>{Pn(),Nz(),cG={command:`lint [paths..]`,description:`Run oxlint diagnostics (spawned via its Node launcher to support JS plugins).`,builder:t=>t.positional(`paths`,{description:"Files or directories to lint. Default: `.`",type:`string`,array:!0}).option(`fix`,{description:`Apply safe lint fixes in place.`,type:`boolean`,default:!1}).option(`config-path`,{description:`Path to an .oxlintrc.json. Default: walks up from cwd to find one.`,type:`string`,normalize:!0}).option(`verbose`,{description:`Echo the resolved oxlint launcher + args before spawning.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.paths?.length?t.paths:[`.`],C=[];t.fix&&C.push(`--fix`);let N=t.configPath??findOxlintConfig(n)??void 0;N&&C.push(`--config`,xn(N)),C.push(...S);try{setOxcExitCode(await runOxlint(C,{cwd:n,verbose:t.verbose}))}catch(t){if(t instanceof OxcNotFoundError){printOxcNotFound(t),setOxcExitCode(1);return}throw t}}}}),uG,dG=__esmMin(()=>{Pn(),Nz(),uG={command:`fix [paths..]`,description:`Run oxfmt --write then oxlint --fix — format + safe lint fixes in one pass.`,builder:t=>t.positional(`paths`,{description:"Files or directories to fix. Default: `.`",type:`string`,array:!0}).option(`write`,{description:`Apply fixes in place (default: true). Pass --no-write to report only.`,type:`boolean`,default:!0}).option(`config-path`,{description:`Path to an .oxlintrc.json. Default: walks up from cwd to find one.`,type:`string`,normalize:!0}).option(`verbose`,{description:`Echo the resolved oxc launchers + args before spawning.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=t.paths?.length?t.paths:[`.`],C=t.verbose??!1,N=t.write!==!1;try{let F=[N?`--write`:`--list-different`],I=t.configPath??findOxfmtConfig(n)??void 0;I&&F.push(`--config`,xn(I)),F.push(...S);let H=await runOxfmt(F,{cwd:n,verbose:C}),W=[];N&&W.push(`--fix`);let q=t.configPath??findOxlintConfig(n)??void 0;q&&W.push(`--config`,xn(q)),W.push(...S);let Y=await runOxlint(W,{cwd:n,verbose:C});setOxcExitCode(H||Y)}catch(t){if(t instanceof OxcNotFoundError){printOxcNotFound(t),setOxcExitCode(1);return}throw t}}}});function createInterface(t,n){return typeof t==`object`&&t&&!(`read`in t&&typeof t.read==`function`)?new Interface(t):new Interface({input:t,output:n})}var Interface,fG=__esmMin(()=>{Ad(),Interface=class extends Interface$1{question(t,n){return new Promise(n=>{super.question(t,n)})}}});function semverGt(t,n){try{return compare(t,n)===1}catch{return!1}}function groupByDependency(t){let n=new Map;for(let S of t){let t=n.get(S.name);t||(t={name:S.name,occurrences:[],declaredRanges:new Set,dominantRange:S.currentRange,highestVersion:S.currentVersion},n.set(S.name,t)),t.occurrences.push(S),t.declaredRanges.add(S.currentRange),S.currentVersion&&(!t.highestVersion||semverGt(S.currentVersion,t.highestVersion))&&(t.highestVersion=S.currentVersion)}for(let t of n.values()){let n=new Map;for(let S of t.occurrences)n.set(S.currentRange,(n.get(S.currentRange)??0)+1);let S=t.occurrences[0].currentRange,C=-1,N=null;for(let[t,F]of n.entries()){let n=parse(t.replace(/^[\^~>=<]+/,``))?.version??null;(F>C||F===C&&n&&N&&semverGt(n,N)||F===C&&t<S)&&(S=t,C=F,N=n)}t.dominantRange=S}return[...n.values()].sort((t,n)=>t.name.localeCompare(n.name))}function isInconsistent(t){return t.declaredRanges.size>1}function findInconsistencies(t){return t.filter(isInconsistent)}var pG=__esmMin(()=>{XP()});function discoverContext(t){let n=findWorkspaceRoot(t);if(n)return{root:n,workspaces:discoverWorkspaces(n,{includeRoot:!0}),isMonorepo:!0};let S=wn(t,`package.json`);if(!existsSync(S))throw Error(`[gjsify upgrade] no package.json at ${S}`);let C=JSON.parse(readFileSync(S,`utf-8`));return{root:t,workspaces:[{name:C.name??`<root>`,location:t,relativeLocation:`.`,version:C.version??`0.0.0`,manifest:C,private:C.private===!0}],isMonorepo:!1}}function applyWorkspaceFilter(t,n,S){let C=n?.split(`,`).map(t=>t.trim()).filter(Boolean),N=S?.split(`,`).map(t=>t.trim()).filter(Boolean);return(!C||C.length===0)&&(!N||N.length===0)?t:filterWorkspaces(t,{include:C,exclude:N})}function parseFilterList(t){return t?t.split(`,`).map(t=>t.trim().toLowerCase()).filter(Boolean):[]}function collectAllDeclarations(t,n){let S=[];for(let C of t)for(let t of collectFromWorkspace(C,n))S.push(t);return S}function collectFromWorkspace(t,n){let S=[],C=t.manifest;for(let N of hG){let F=C[N];if(!(!F||typeof F!=`object`))for(let[C,I]of Object.entries(F)){if(typeof I!=`string`||n.length&&!n.some(t=>C.toLowerCase().includes(t))||isDistTagSpec(I)||I.startsWith(`workspace:`)||I.startsWith(`file:`)||I.startsWith(`link:`)||I.startsWith(`git+`)||I.startsWith(`git:`)||I.startsWith(`http:`)||I.startsWith(`https:`)||I.startsWith(`npm:`)||I.startsWith(`portal:`))continue;let{prefix:F,version:H}=splitRange(I);S.push({workspace:t.name,workspaceLocation:t.location,name:C,field:N,currentRange:I,currentVersion:H,prefix:F})}}return S}function isDistTagSpec(t){let n=t.trim();return gG.has(n)||!/^[A-Za-z]/.test(n)||/^v\d/.test(n)||/^v[xX*]/.test(n)?!1:/^[A-Za-z][\w.-]*$/.test(n)}function splitRange(t){let n=t.match(/^(\^|~|>=|<=|>|<|=)?\s*([0-9].*)$/);if(!n)return{prefix:``,version:null};let S=n[1]??``,C=n[2]?.split(/\s|[|&,]/)[0]??null;return{prefix:S,version:(C?parse(C):null)?.version??null}}function reportInexactRanges(t){let n=t.map(t=>({name:t.name,loose:t.occurrences.filter(t=>t.prefix!==``)})).filter(t=>t.loose.length>0);if(n.length===0)return 0;let S=n.reduce((t,n)=>t+n.loose.length,0);ge.error(`gjsify upgrade --check --exact: FAIL. ${S} declaration(s) across ${n.length} dep(s) carry a range operator:\n`);for(let t of n){let n=new Map;for(let S of t.loose){let t=n.get(S.currentRange)??[];t.push(S.workspace),n.set(S.currentRange,t)}ge.error(` ${_G.bold}${t.name}${_G.reset}`);for(let[t,S]of n.entries()){let n=S.length>6?`${S.slice(0,6).join(`, `)} … +${S.length-6}`:S.join(`, `);ge.error(` ${t.padEnd(16)} — ${n}`)}}return S}function checkLockfileRangeViolations(t,n){let S=wn(n,`gjsify-lock.json`);if(!existsSync(S))return 0;let C;try{C=JSON.parse(readFileSync(S,`utf-8`))}catch{return 0}if(!C.packages)return 0;let N=new Map;for(let n of t){let t=N.get(n.name)??new Set;for(let S of n.occurrences)t.add(S.currentRange);N.set(n.name,t)}let F=0;for(let[t,n]of Object.entries(C.packages)){if(!n.version)continue;let S=t.split(`node_modules/`);if(S.length!==2)continue;let C=S[1],I=N.get(C);if(!I||I.size===0)continue;let H=!1;for(let t of I)try{if(n.version&&satisfies(n.version,t)){H=!0;break}}catch{}H||(ge.error(` ${C}: lockfile has ${n.version}, but declared ranges are ${[...I].join(`, `)}`),F++)}return F>0&&ge.error(`gjsify upgrade --check: FAIL. ${F} lockfile entr${F===1?`y`:`ies`} violate declared ranges:\n`),F}function runCheckMode(t,n=!1,S=process.cwd()){checkLockfileRangeViolations(t,S);let C=n?reportInexactRanges(t):0,N=findInconsistencies(t);if(N.length===0&&C>0)return ge.error("\nFix: run `gjsify upgrade --align --exact` (offline; drops the operator and keeps the version)."),process.exit(1);if(N.length===0){ge.log(`gjsify upgrade --check: OK. ${t.length} dep(s) consistently declared across workspaces`+(n?`, every declaration pinned exactly.`:`.`));return}ge.error(`gjsify upgrade --check: FAIL. ${N.length} dep(s) declared at inconsistent ranges:\n`);for(let t of N){let n=new Map;for(let S of t.occurrences){let t=n.get(S.currentRange)??[];t.push(S.workspace),n.set(S.currentRange,t)}ge.error(` ${_G.bold}${t.name}${_G.reset}`);for(let[t,S]of n.entries())ge.error(` ${t.padEnd(16)} — ${S.join(`, `)}`)}ge.error(n?"\nFix: run `gjsify upgrade --align --exact` (offline; aligns each dep to its highest declared version and drops the operator).":"\nFix: run `gjsify upgrade --align` (offline; aligns each dep to its highest declared range)."),process.exit(1)}function alignTargets(t,n){return n?t.filter(t=>isInconsistent(t)||t.occurrences.some(t=>t.prefix!==``)):findInconsistencies(t)}function reportUnrepairable(t){ge.error(`\ngjsify upgrade --align: ${t.length} dep(s) left unrepaired — no version to align on:\n`);for(let n of t)ge.error(` ${_G.bold}${n.name}${_G.reset} ${[...n.declaredRanges].join(`, `)}`);return ge.error("\nThose ranges name no single version. Edit them by hand, or resolve one with `--latest`."),process.exit(1)}function runAlignMode(t,n){let S=n.exact??!1,C=alignTargets(t,S);if(C.length===0){ge.log(`gjsify upgrade --align: nothing to do. ${t.length} dep(s) already consistent`+(S?`, every declaration pinned exactly.`:`.`));return}let N=[],F=[];for(let t of C){if(!t.highestVersion){F.push(t);continue}let n=t.occurrences.find(n=>n.currentRange===t.dominantRange)?.prefix||`^`;N.push({...t,latestVersion:t.highestVersion,diff:`none`,occurrences:t.occurrences.map(t=>({...t,prefix:n}))})}if(N.length>0){ge.log(S?`gjsify upgrade --align --exact: pinning ${N.length} dep(s) to their highest declared version, without a range operator:\n`:`gjsify upgrade --align: aligning ${N.length} inconsistent dep(s) to their highest declared version:\n`);for(let t of N){let n=t.occurrences[0]?.prefix??`^`;ge.log(` ${t.name.padEnd(28)} ranges: ${[...t.declaredRanges].join(`, `)} → ${targetRange(n,t.latestVersion,S)}`)}if(n.dryRun)ge.log(`
1745
+ [gjsify upgrade --align] --dry-run: no files changed.`);else{let t=applyToFiles(N,S);ge.log(`\n✏️ updated ${N.length} dep(s) across ${t} package.json file(s).`)}}if(F.length>0)return reportUnrepairable(F)}async function resolveCandidateGroups(t,n,S,C){let N=[],F=0;async function worker(){for(;;){let I=F++;if(I>=t.length)return;let H=t[I];try{let t=(await fetchPackument(H.name,{npmrc:n}))[`dist-tags`]?.latest;if(!t){S&&ge.warn(` ${H.name}: no dist-tags.latest, skipping`);continue}let F=H.highestVersion;if(!F){S&&ge.warn(` ${H.name}: unable to parse any current range`);continue}let I=classifyDiff(F,t);if(I===`none`||C===`minor`&&I===`major`||C===`patch`&&(I===`major`||I===`minor`))continue;N.push({...H,latestVersion:t,diff:I})}catch(t){S&&ge.warn(` ${H.name}: fetch failed (${t.message})`)}}}return await Promise.all(Array.from({length:8},()=>worker())),N.sort((t,n)=>t.name.localeCompare(n.name)),N}function classifyDiff(t,n){let S=parse(t),C=parse(n);return!S||!C?`none`:S.major===C.major?S.minor===C.minor?S.patch===C.patch?(S.prerelease??[]).join(`.`)===(C.prerelease??[]).join(`.`)?`none`:`prerelease`:C.patch>S.patch?`patch`:`none`:C.minor>S.minor?`minor`:`none`:C.major>S.major?`major`:`none`}function colorForDiff(t){switch(t){case`major`:return _G.red;case`minor`:return _G.yellow;case`patch`:return _G.green;case`prerelease`:return _G.cyan;default:return``}}function printTable(t){let n=Math.max(...t.map(t=>t.name.length),4),S=Math.max(...t.map(t=>`${t.occurrences.length}`.length+2),3),C=Math.max(...t.map(t=>declaredCellWidth(t)),7),N=Math.max(...t.map(t=>t.latestVersion.length),6),F=String(t.length).length+2,I=` `.repeat(F+2)+_G.bold+`name`.padEnd(n)+` `+`fan`.padEnd(S)+` `+`declared`.padEnd(C)+` `+`latest`.padEnd(N)+` kind`+_G.reset;ge.log(I),ge.log(` `.repeat(F+2)+_G.dim+`─`.repeat(n+S+C+N+16)+_G.reset);for(let I=0;I<t.length;I++){let H=t[I],W=`${I+1}.`.padEnd(F),q=H.declaredRanges.size>1?`${_G.magenta}⚠ ${_G.reset}`:` `,Y=colorForDiff(H.diff);ge.log(W+q+H.name.padEnd(n)+` `+_G.dim+`${H.occurrences.length}`.padEnd(S)+_G.reset+` `+_G.dim+renderDeclaredCell(H).padEnd(C)+_G.reset+` `+Y+H.latestVersion.padEnd(N)+_G.reset+` `+Y+H.diff+_G.reset)}let H=t.filter(t=>t.declaredRanges.size>1).length;H>0&&ge.log(`\n${_G.magenta}⚠${_G.reset} ${H} dep(s) declared at inconsistent ranges across workspaces.`)}function declaredCellWidth(t){return renderDeclaredCell(t).length}function renderDeclaredCell(t){if(t.declaredRanges.size===1)return[...t.declaredRanges][0];let n=[...t.declaredRanges].sort().join(`, `);return n.length<=32?n:n.slice(0,29)+`…`}function printChangePlan(t,n=!1){for(let S of t)for(let t of S.occurrences)ge.log(` ${t.workspace.padEnd(38)} ${S.name.padEnd(28)} ${t.currentRange.padEnd(12)} → ${targetRange(t.prefix,S.latestVersion,n)}`)}async function promptSelection(t){if(!process.stdin.isTTY)return ge.log(`[gjsify upgrade] non-TTY stdin: pass --latest / --minor / --patch (or --yes for interactive-all) to upgrade non-interactively.`),[];let n=createInterface({input:process.stdin,output:process.stdout});try{ge.log(`
1746
+ Select upgrades: comma- or space-separated indices, `+_G.bold+`a`+_G.reset+` for all, ranges like `+_G.bold+`1-3`+_G.reset+`, or `+_G.bold+`ENTER`+_G.reset+` to skip:`);let S=(await n.question(`> `)).trim();if(!S)return[];if(S.toLowerCase()===`a`||S.toLowerCase()===`all`)return[...t];let C=new Set;for(let t of S.split(/[\s,]+/).filter(Boolean)){let n=t.match(/^(\d+)-(\d+)$/);if(n){let t=Number(n[1]),S=Number(n[2]);for(let n=Math.min(t,S);n<=Math.max(t,S);n++)C.add(n-1)}else/^\d+$/.test(t)&&C.add(Number(t)-1)}return[...C].filter(n=>n>=0&&n<t.length).map(n=>t[n])}finally{n.close()}}function targetRange(t,n,S){return S?n:`${t}${n}`}function applyToFiles(t,n=!1){let S=new Map;for(let n of t)for(let t of n.occurrences){let C=S.get(t.workspaceLocation)??[];C.push({...n,occurrences:[t]}),S.set(t.workspaceLocation,C)}let C=0;for(let[t,N]of S.entries()){let S=wn(t,`package.json`),F=readFileSync(S,`utf-8`),I=JSON.parse(F),H=!1,W=[];for(let t of N){let S=t.occurrences[0],C=I[S.field];if(!C)continue;let N=targetRange(S.prefix,t.latestVersion,n);C[t.name]!==N&&(C[t.name]=N,H=!0,W.push(t.name))}if(H){let t=detectIndent(F);writeFileSync(S,keepUntouchedLines(F,JSON.stringify(I,null,t)+(F.endsWith(`
1747
1747
  `)?`
1748
1748
  `:``),W),`utf-8`),C++}}return C}function keepUntouchedLines(t,n,S){let C=t.split(`
1749
1749
  `),N=n.split(`
1750
1750
  `);return C.length===N.length?N.map((t,n)=>S.some(n=>t.includes(`"${n}"`))?t:C[n]).join(`
1751
- `):n}function uniqueLocations(t){let n=new Set;for(let S of t)for(let t of S.occurrences)n.add(t.workspaceLocation);return[...n]}function detectIndent(t){let n=t.match(/^\{\n( +)/);return n?n[1].length:2}async function loadNpmrcLight(t){let n={registry:qm,scopes:{},authTokens:{},basicAuth:{}};for(let S of[wn(homedir(),`.npmrc`),wn(t,`.npmrc`)])if(existsSync(S))try{let t=parseNpmrc(readFileSync(S,`utf-8`));n={...n,...t,scopes:{...n.scopes,...t.scopes}}}catch{}return process.env.npm_config_registry&&(n.registry=process.env.npm_config_registry),n}var sG,cG,lG,uG,dG=__esmMin(()=>{_e(),Rd(),Pn(),Lg(),aG(),XP(),eh(),QP(),eF(),oG(),sG={command:`upgrade`,description:"Workspace-aware dependency upgrades. Walks every package.json in the monorepo, groups by dep, flags inconsistencies. `--latest` / `--minor` / `--patch` for bulk-mode, `--align` for offline consistency-only mode, `--check` for CI drift detection.",builder:t=>t.option(`latest`,{description:`Non-interactive: bump every dependency to its latest version (allows major).`,type:`boolean`,default:!1}).option(`minor`,{description:`Non-interactive: bump every dependency to the latest within the same major (semver-minor + semver-patch).`,type:`boolean`,default:!1}).option(`patch`,{description:`Non-interactive: bump every dependency to the latest within the same minor (semver-patch only).`,type:`boolean`,default:!1}).option(`filter`,{description:`Only consider deps whose name matches this substring (case-insensitive). Repeatable; comma-separated values are split.`,type:`string`}).option(`workspace`,{alias:`p`,description:`Restrict to a subset of workspaces. Patterns are matched against the workspace package name AND its directory path (substring + glob). Repeatable; comma-separated values are split.`,type:`string`}).option(`exclude-workspace`,{description:`Skip workspaces matching this pattern (glob-shaped; matched against workspace package name AND directory path). Repeatable; comma-separated values are split. Use for workspaces with intentional dependency drift — e.g. integration tests pinned to specific upstream versions.`,type:`string`}).option(`align`,{description:"Offline repair mode: find deps declared at multiple ranges across the workspace and align them to the highest. With `--exact`, also drop the range operator from declarations that already agree. No registry calls.",type:`boolean`,default:!1}).option(`check`,{description:"CI gate: exit non-zero when any dep is declared inconsistently across workspaces. Implies offline (no registry calls). Pairs with `--align` as the fix.",type:`boolean`,default:!1}).option(`exact`,{description:"Pin without a range operator. When writing, emits `1.2.3` instead of `^1.2.3`; with `--check`, fails on any matched dep that carries one; with `--align`, repairs exactly that. Pair with `--filter` — a repository-wide exactness run touches every ordinary caret dep by design.",type:`boolean`,default:!1}).option(`dry-run`,{description:`Print the upgrade plan without writing package.json files.`,type:`boolean`,default:!1}).option(`cwd`,{description:`Project directory. Default: process.cwd(). When inside a workspace, walks up to the monorepo root.`,type:`string`}).option(`yes`,{alias:`y`,description:`Interactive mode: select all without prompting.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print extra resolution details.`,type:`boolean`,default:!1}),handler:async t=>{let n=discoverContext(xn(t.cwd??process.cwd())),S=applyWorkspaceFilter(n.workspaces,t.workspace,t.excludeWorkspace);if(S.length===0){ge.log(`[gjsify upgrade] no matching workspaces.`);return}let C=collectAllDeclarations(S,parseFilterList(t.filter));if(C.length===0){ge.log(`[gjsify upgrade] no external npm dependencies to check.`);return}let N=groupByDependency(C);if(t.check)return runCheckMode(N,t.exact);if(t.align)return runAlignMode(N,t);let F=await loadNpmrcLight(n.root),I=t.latest?`latest`:t.minor?`minor`:t.patch?`patch`:`interactive`;ge.log(`[gjsify upgrade] checking ${N.length} unique deps across ${S.length} workspace(s) against ${F.registry}…`);let H=await resolveCandidateGroups(N,F,t.verbose??!1,I);if(H.length===0){ge.log(`✅ all dependencies are up to date`);let t=findInconsistencies(N);t.length>0&&ge.log(`\n⚠ ${t.length} dep(s) declared at inconsistent ranges across workspaces. Run \`gjsify upgrade --align\` to fix.`);return}printTable(H);let W;if(I===`interactive`&&!t.yes?W=await promptSelection(H):(t.yes&&I===`interactive`&&ge.log(`[gjsify upgrade] -y / --yes: selecting all`),W=H),W.length===0){ge.log(`[gjsify upgrade] nothing selected; no files changed.`);return}if(t.dryRun){let n=uniqueLocations(W).length;ge.log(`[gjsify upgrade] --dry-run: would update ${W.length} deps across ${n} package.json file(s).`),printChangePlan(W,t.exact);return}let q=applyToFiles(W,t.exact);ge.log(`✏️ updated ${W.length} dep(s) across ${q} package.json file(s). Run \`gjsify install\` to apply.`)}},cG=[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`],lG=new Set([`x`,`X`,`*`,``]),uG={reset:`\x1B[0m`,bold:`\x1B[1m`,dim:`\x1B[2m`,red:`\x1B[31m`,yellow:`\x1B[33m`,green:`\x1B[32m`,cyan:`\x1B[36m`,magenta:`\x1B[35m`}});async function unscannableBarrelPaths(t,n){let S=[];for(let C of n){let n=xn(t,C);try{(await stat$1(n)).isDirectory()||S.push(`${n} is not a directory`)}catch(t){S.push(`${n}: ${t.message}`)}}return S}async function generateBarrels(t){let n=t.singleQuotes?`'`:`"`,S=t.noSemicolon?``:`;`,C=t.extension===`none`?``:`.${t.extension}`,N=0;for(let F of t.paths){let I=xn(t.baseDir,F),H=Dn(I)===`types`,W;try{W=(await readdir$1(I,{withFileTypes:!0})).filter(t=>t.isFile()).filter(t=>pG.test(t.name)).filter(t=>t.name!==`index.ts`).filter(n=>!t.exclude.some(t=>t.test(n.name))).sort((t,n)=>t.name.localeCompare(n.name))}catch(n){t.verbose&&ge.error(`[gjsify barrels] skip ${I}: ${n.message}`);continue}let q=W.map(t=>{let N=Dn(t.name,On(t.name));return`${H?`export type *`:`export *`} from ${n}./${N}${C}${n}${S}`}),Y=q.length?`${q.join(`
1751
+ `):n}function uniqueLocations(t){let n=new Set;for(let S of t)for(let t of S.occurrences)n.add(t.workspaceLocation);return[...n]}function detectIndent(t){let n=t.match(/^\{\n( +)/);return n?n[1].length:2}async function loadNpmrcLight(t){let n={registry:qm,scopes:{},authTokens:{},basicAuth:{}};for(let S of[wn(homedir(),`.npmrc`),wn(t,`.npmrc`)])if(existsSync(S))try{let t=parseNpmrc(readFileSync(S,`utf-8`));n={...n,...t,scopes:{...n.scopes,...t.scopes}}}catch{}return process.env.npm_config_registry&&(n.registry=process.env.npm_config_registry),n}var mG,hG,gG,_G,vG=__esmMin(()=>{_e(),Rd(),Pn(),Lg(),fG(),XP(),eh(),QP(),eF(),pG(),mG={command:`upgrade`,description:"Workspace-aware dependency upgrades. Walks every package.json in the monorepo, groups by dep, flags inconsistencies. `--latest` / `--minor` / `--patch` for bulk-mode, `--align` for offline consistency-only mode, `--check` for CI drift detection.",builder:t=>t.option(`latest`,{description:`Non-interactive: bump every dependency to its latest version (allows major).`,type:`boolean`,default:!1}).option(`minor`,{description:`Non-interactive: bump every dependency to the latest within the same major (semver-minor + semver-patch).`,type:`boolean`,default:!1}).option(`patch`,{description:`Non-interactive: bump every dependency to the latest within the same minor (semver-patch only).`,type:`boolean`,default:!1}).option(`filter`,{description:`Only consider deps whose name matches this substring (case-insensitive). Repeatable; comma-separated values are split.`,type:`string`}).option(`workspace`,{alias:`p`,description:`Restrict to a subset of workspaces. Patterns are matched against the workspace package name AND its directory path (substring + glob). Repeatable; comma-separated values are split.`,type:`string`}).option(`exclude-workspace`,{description:`Skip workspaces matching this pattern (glob-shaped; matched against workspace package name AND directory path). Repeatable; comma-separated values are split. Use for workspaces with intentional dependency drift — e.g. integration tests pinned to specific upstream versions.`,type:`string`}).option(`align`,{description:"Offline repair mode: find deps declared at multiple ranges across the workspace and align them to the highest. With `--exact`, also drop the range operator from declarations that already agree. No registry calls.",type:`boolean`,default:!1}).option(`check`,{description:"CI gate: exit non-zero when any dep is declared inconsistently across workspaces. Implies offline (no registry calls). Pairs with `--align` as the fix.",type:`boolean`,default:!1}).option(`exact`,{description:"Pin without a range operator. When writing, emits `1.2.3` instead of `^1.2.3`; with `--check`, fails on any matched dep that carries one; with `--align`, repairs exactly that. Pair with `--filter` — a repository-wide exactness run touches every ordinary caret dep by design.",type:`boolean`,default:!1}).option(`dry-run`,{description:`Print the upgrade plan without writing package.json files.`,type:`boolean`,default:!1}).option(`cwd`,{description:`Project directory. Default: process.cwd(). When inside a workspace, walks up to the monorepo root.`,type:`string`}).option(`yes`,{alias:`y`,description:`Interactive mode: select all without prompting.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print extra resolution details.`,type:`boolean`,default:!1}),handler:async t=>{let n=discoverContext(xn(t.cwd??process.cwd())),S=applyWorkspaceFilter(n.workspaces,t.workspace,t.excludeWorkspace);if(S.length===0){ge.log(`[gjsify upgrade] no matching workspaces.`);return}let C=collectAllDeclarations(S,parseFilterList(t.filter));if(C.length===0){ge.log(`[gjsify upgrade] no external npm dependencies to check.`);return}let N=groupByDependency(C);if(t.check)return runCheckMode(N,t.exact);if(t.align)return runAlignMode(N,t);let F=await loadNpmrcLight(n.root),I=t.latest?`latest`:t.minor?`minor`:t.patch?`patch`:`interactive`;ge.log(`[gjsify upgrade] checking ${N.length} unique deps across ${S.length} workspace(s) against ${F.registry}…`);let H=await resolveCandidateGroups(N,F,t.verbose??!1,I);if(H.length===0){ge.log(`✅ all dependencies are up to date`);let t=findInconsistencies(N);t.length>0&&ge.log(`\n⚠ ${t.length} dep(s) declared at inconsistent ranges across workspaces. Run \`gjsify upgrade --align\` to fix.`);return}printTable(H);let W;if(I===`interactive`&&!t.yes?W=await promptSelection(H):(t.yes&&I===`interactive`&&ge.log(`[gjsify upgrade] -y / --yes: selecting all`),W=H),W.length===0){ge.log(`[gjsify upgrade] nothing selected; no files changed.`);return}if(t.dryRun){let n=uniqueLocations(W).length;ge.log(`[gjsify upgrade] --dry-run: would update ${W.length} deps across ${n} package.json file(s).`),printChangePlan(W,t.exact);return}let q=applyToFiles(W,t.exact);ge.log(`✏️ updated ${W.length} dep(s) across ${q} package.json file(s). Run \`gjsify install\` to apply.`)}},hG=[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`],gG=new Set([`x`,`X`,`*`,``]),_G={reset:`\x1B[0m`,bold:`\x1B[1m`,dim:`\x1B[2m`,red:`\x1B[31m`,yellow:`\x1B[33m`,green:`\x1B[32m`,cyan:`\x1B[36m`,magenta:`\x1B[35m`}});async function unscannableBarrelPaths(t,n){let S=[];for(let C of n){let n=xn(t,C);try{(await stat$1(n)).isDirectory()||S.push(`${n} is not a directory`)}catch(t){S.push(`${n}: ${t.message}`)}}return S}async function generateBarrels(t){let n=t.singleQuotes?`'`:`"`,S=t.noSemicolon?``:`;`,C=t.extension===`none`?``:`.${t.extension}`,N=0;for(let F of t.paths){let I=xn(t.baseDir,F),H=Dn(I)===`types`,W;try{W=(await readdir$1(I,{withFileTypes:!0})).filter(t=>t.isFile()).filter(t=>bG.test(t.name)).filter(t=>t.name!==`index.ts`).filter(n=>!t.exclude.some(t=>t.test(n.name))).sort((t,n)=>t.name.localeCompare(n.name))}catch(n){t.verbose&&ge.error(`[gjsify barrels] skip ${I}: ${n.message}`);continue}let q=W.map(t=>{let N=Dn(t.name,On(t.name));return`${H?`export type *`:`export *`} from ${n}./${N}${C}${n}${S}`}),Y=q.length?`${q.join(`
1752
1752
  `)}\n`:`export {};
1753
- `,X=`${t.header}\n\n${Y}`,Z=wn(I,`index.ts`);if(await readFile$1(Z,`utf-8`).catch(()=>``)===X){t.verbose&&ge.log(`[gjsify barrels] up-to-date: ${Z}`);continue}t.check?(ge.error(`[gjsify barrels] drift: ${Z}`),N++):(await writeFile$1(Z,X,`utf-8`),t.verbose&&ge.log(`[gjsify barrels] wrote: ${Z}`))}return N}var fG,pG,mG=__esmMin(()=>{_e(),xd(),Pn(),fG=[`\\.test\\.`,`\\.spec\\.`,`\\.test-data\\.`],pG=/\.(ts|tsx|mts|cts)$/}),hG,gG=__esmMin(()=>{_e(),mG(),hG={command:`barrels [paths..]`,description:"Regenerate `index.ts` barrel files for the given directories. Drop-in replacement for `barrelsby`.",builder:t=>t.positional(`paths`,{description:"Directories whose `index.ts` to (re)generate. May also be passed via `--paths`.",type:`string`,array:!0}).option(`paths`,{alias:`p`,description:`Alternative to positional — repeatable list of directories.`,type:`string`,array:!0}).option(`ext`,{description:"Import-specifier extension. Default: `none` (bundler-mode resolution).",type:`string`,choices:[`js`,`ts`,`none`],default:`none`}).option(`base-dir`,{alias:`b`,description:"Resolve `paths` against this directory. Default: cwd.",type:`string`}).option(`exclude`,{description:"Regex(es) of file names to skip. Repeatable. Defaults: `\\.test\\.`, `\\.spec\\.`, `\\.test-data\\.`.",type:`string`,array:!0}).option(`header`,{description:`Header comment prepended to every generated file.`,type:`string`}).option(`semicolon`,{description:"Emit trailing `;` on each export line. Negate with `--no-semicolon`. Default: omitted.",type:`boolean`,default:!1}).option(`single-quotes`,{description:"Use `'` for import specifiers. Default: true. Pass `--no-single-quotes` for `\"`.",type:`boolean`,default:!0}).option(`check`,{description:`Report drift without modifying files; exit non-zero if any barrel is stale.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Log each file scanned + written.`,type:`boolean`,default:!1}),handler:async t=>{let n=Array.from(new Set((t.paths??[]).filter(Boolean)));if(n.length===0){ge.error(`[gjsify barrels] no paths provided. Pass directories as positional arguments or via --paths.`),process.exitCode=1;return}let S=t.baseDir??process.cwd(),C=await unscannableBarrelPaths(S,n);if(C.length>0){for(let t of C)ge.error(`[gjsify barrels] cannot scan ${t}`);ge.error(`[gjsify barrels] ${C.length} of ${n.length} path(s) could not be scanned — refusing to report on the rest as if that were the whole set.`),process.exitCode=1;return}let N=t.exclude?.length?t.exclude:[...fG],F=await generateBarrels({paths:n,extension:t.ext??`none`,baseDir:S,exclude:N.map(t=>new RegExp(t)),header:t.header??"// Auto-generated by `gjsify barrels` — do not edit by hand.",noSemicolon:t.semicolon===!1||t.semicolon===void 0,singleQuotes:t.singleQuotes!==!1,check:t.check??!1,verbose:t.verbose??!1});t.check&&F>0&&(ge.error(`[gjsify barrels] ${F} barrel file(s) drifted. Run without --check to fix.`),process.exitCode=1)}}}),_G,vG=__esmMin(()=>{_e(),Il(),Pn(),Gn(),CF(),vF(),Rd(),gU(),QI(),eF(),V_(),_G={command:`tsc [tscArgs..]`,description:"Run TypeScript compiler (tsc) under GJS via the @gjsify/tsc bundle. All arguments are passed through to tsc. Equivalent to `gjsify-tsc <args>` from the @gjsify/tsc bin.",builder:t=>t.parserConfiguration({"unknown-options-as-args":!0}).version(!1).help(!1).positional(`tscArgs`,{description:"Arguments forwarded verbatim to tsc (e.g. `--version`, `-p tsconfig.json`).",type:`string`,array:!0,default:[]}),handler:async t=>{let n=(t._??[]).slice(1).map(String),S=t.tscArgs??[],C=n.length>0?n:S,N=process.cwd(),F=[pathToFileURL(`${findWorkspaceRoot(N)??N}/__gjsify_tsc__.js`).href,import.meta.url],I;for(let t of F)try{I=createRequire(t).resolve(`@gjsify/tsc/bundle`);break}catch{}let H;for(let t of F)try{H=wn(En(createRequire(t).resolve(`typescript/package.json`)),`lib`,`tsc.js`);break}catch{}if(!I&&!H)return ge.error("gjsify tsc: neither @gjsify/tsc (GJS bundle) nor npm `typescript` (Node) is installed."),ge.error(" Install with: gjsify install --save-dev @gjsify/tsc (or add `typescript`)."),forceExit(1);let W=buildNativeEnv(detectNativePackages(N)),q={...process.env,...W},runNodeTsc=async()=>{let t=nodeBinary();if(!(t.includes(`/`)||t.includes(`\\`)?existsSync(t):isOnPath(t)))return ge.error(`gjsify tsc: the @gjsify/tsc GJS bundle is unavailable and \`${t}\` cannot be run, so upstream \`typescript\` cannot run either.`),ge.error(` Build the bundle with: gjsify workspace @gjsify/tsc build`),ge.error(" …or install Node.js so the upstream `typescript` fallback can be spawned."),forceExit(1);try{await new Promise((n,S)=>{spawnToCompletion(t,[H,...C],{completion:`exit`,env:q,onSpawn:t=>{let n=!1;t.on(`error`,()=>{n=!0}),t.on(`close`,t=>{n||forceExit(t??1)})}}).catch(S)})}catch(t){let n=t;return n.code===`ENOENT`?(ge.error("gjsify tsc: the @gjsify/tsc GJS bundle is unavailable and `node` is not on PATH, so upstream `typescript` cannot run either."),ge.error(` Build the bundle with: gjsify workspace @gjsify/tsc build`)):ge.error(`gjsify tsc (node typescript): ${n.message}`),forceExit(1)}};if(I)try{await new Promise((t,n)=>{spawnToCompletion(`gjs`,[`-m`,I,...C],{completion:`exit`,env:q,onSpawn:t=>{let n=!1;t.on(`error`,()=>{n=!0}),t.on(`close`,t=>{n||forceExit(t??1)})}}).catch(n)})}catch(t){let n=t;return n.code===`ENOENT`&&H?await runNodeTsc():(n.code===`ENOENT`?(ge.error("gjsify tsc: `gjs` not found on PATH and no npm `typescript` fallback."),ge.error(" Install GJS (e.g. `dnf install gjs`), or add `typescript` to the project.")):ge.error(`gjsify tsc: ${n.message}`),forceExit(1))}else await runNodeTsc()}}});function readStdinText(){return readFileSync(0,`utf-8`)}function readStdinLines(){return splitStdinLines(readStdinText())}function splitStdinLines(t){return t.split(`
1754
- `).map(t=>t.trim()).filter(Boolean)}var yG=__esmMin(()=>{Rd()});function isResolvableScript(t){return wG.test(t)&&!bG.some(n=>n.test(t))&&!CG.some(n=>n.match.test(t))}function resolveRootScripts(t,n){let S=new Set,C=[];for(let n of t)isResolvableScript(n)?C.push(n):S.add(n);let N=new Set;for(;C.length>0;){let t=C.shift();if(!N.has(t)){N.add(t);for(let N of n(t))xG.some(t=>t.test(N))||(isResolvableScript(N)?C.push(N):S.add(N))}}return{files:[...S],scripts:N.size}}function classifyAndExpand(t,n,S){let C=n.map(t=>t.replace(/\\/g,`/`)).filter(t=>t.length>0);if(C.length===0)return{global:!1,reason:`empty-diff`,workspaces:[],runE2E:!1,runIntegration:!1,skipAll:!0};let N=[];for(let t of C)xG.some(n=>n.test(t))||N.push(t);let F=``;if(S){let t=resolveRootScripts(N,S);t.scripts>0&&(N=t.files,F=`; ${t.scripts} root script(s) resolved to their readers`)}if(N.length===0)return{global:!1,reason:`ignored-only`+F,workspaces:[],runE2E:!1,runIntegration:!1,skipAll:!0};for(let n of N)for(let S of bG)if(S.test(n))return{global:!0,reason:`global-trigger ${S.source} matched ${n}${F}`,workspaces:t.map(t=>t.name),runE2E:!0,runIntegration:!0,skipAll:!1};let{matched:I,unmatched:H}=workspacesForChangedFiles(t,N),W=new Set(t.map(t=>t.name)),q=new Set,Y=new Set,X=!1;for(let n of CG){let S=N.filter(t=>n.match.test(t));if(S.length!==0){for(let t of S)Y.add(t);for(let S of n.seeds){if(!W.has(S))return{global:!0,reason:`script-coupling seed ${S} is not a workspace (${n.match.source} → ${n.why}); SCRIPT_COUPLINGS in commands/affected.ts is stale`,workspaces:t.map(t=>t.name),runE2E:!0,runIntegration:!0,skipAll:!1};q.add(S)}n.runE2E&&(X=!0)}}let Z=H.filter(t=>!Y.has(t));if(Z.length>0)return{global:!0,reason:`unmatched files (${Z.length}): ${Z.slice(0,3).join(`, `)}${Z.length>3?`…`:``}${F}`,workspaces:t.map(t=>t.name),runE2E:!0,runIntegration:!0,skipAll:!1};for(let t of q)I.add(t);if(q.size===0&&N.every(t=>SG.some(n=>n.test(t)))&&I.size===1){let t=[...I][0],n=N.some(t=>t.startsWith(`tests/e2e/`)),S=N.some(t=>t.startsWith(`tests/integration/`));return{global:!1,reason:`test-only (${N.length} file(s) in ${t})${F}`,workspaces:[t],runE2E:n||X,runIntegration:S||isIntegrationWorkspace(t),skipAll:!1}}let te=affectedClosure(buildReverseDependencyGraph(t,{includeDev:!1}),[...I]),ne=buildDependencyGraph(t,{includeDev:!0}),re=!1;for(let[t,n]of ne.edges)if(isIntegrationWorkspace(t)){for(let S of n)if(te.has(S)){te.add(t),re=!0;break}}let ie=N.some(t=>t.startsWith(`tests/e2e/`))||X;return{global:!1,reason:`closure (${te.size} ws from ${I.size} seed(s))`+(q.size>0?`, ${q.size} via script-coupling`:``)+F,workspaces:[...te].sort(),runE2E:ie,runIntegration:re,skipAll:!1}}function isIntegrationWorkspace(t){return t.startsWith(`@gjsify/integration-`)}var bG,xG,SG,CG,wG,TG=__esmMin(()=>{QP(),bG=[/^packages\/infra\/workspace\//,/^packages\/infra\/cli\//,/^packages\/infra\/rolldown-plugin-gjsify\//,/^packages\/infra\/resolve-npm\//,/^packages\/gjs\/unit\//,/^\.github\/actions\//,/^gjsify-lock\.json$/,/^package\.json$/,/^tsconfig[^/]*\.json$/,/^\.github\/workflows\/main\.yml$/,/^scripts\/audit-runtimes\.mjs$/],xG=[/\.md$/i,/^refs\//,/^website\//,/^docs\//,/^\.github\/workflows\/(deploy-docs|commitlint|release|release-cut|audit-runtimes|prebuilds|node-gi|napi|cli-cross-platform|build-ci-image|cancel-pr-runs|macos-suites|windows-suites|gtk-os-suites)\.yml$/,/^\.github\/prebuild-toolchain\//,/^scripts\/manifest-conformance\//,/^status\//,/^scripts\/generate-status\.mjs$/,/^packages\/node-gi\//,/^packages\/napi\//,/^flatpak\//,/^LICENSE/,/^\.gitignore$/,/^\.gjsify-[^/]*\.md$/,/^STATUS\.md$/,/^CHANGELOG\.md$/,/^AGENTS\.md$/,/^CLAUDE\.md$/,/^README\.md$/],SG=[/\.spec\.[mc]?[tj]sx?$/,/^tests\/(e2e|integration)\//],CG=[{match:/^\.githooks\//,seeds:[],runE2E:!0,why:`tests/e2e/git-hooks-cli-bundle-staleness drives .githooks/pre-commit`},{match:/^templates\//,seeds:[`@gjsify/create-app`],runE2E:!0,why:`@gjsify/create-app build → node scripts/process-template.mjs reads templates/`},{match:/^packages\/framework\/react-native\//,seeds:[],runE2E:!0,why:`tests/e2e/react-native-devtools is the only external observer of AppRegistry.runApplication`}],wG=/^scripts\/[^/]+$/});function stripCommentLines(t,n){let S=/\.(ya?ml|sh|bash|py|toml)$|(^|\/)\.git[a-z]*$|Dockerfile$/.test(t)?/^\s*#/:/^\s*(\/\/|\/\*|\*)/;return n.split(`
1753
+ `,X=`${t.header}\n\n${Y}`,Z=wn(I,`index.ts`);if(await readFile$1(Z,`utf-8`).catch(()=>``)===X){t.verbose&&ge.log(`[gjsify barrels] up-to-date: ${Z}`);continue}t.check?(ge.error(`[gjsify barrels] drift: ${Z}`),N++):(await writeFile$1(Z,X,`utf-8`),t.verbose&&ge.log(`[gjsify barrels] wrote: ${Z}`))}return N}var yG,bG,xG=__esmMin(()=>{_e(),xd(),Pn(),yG=[`\\.test\\.`,`\\.spec\\.`,`\\.test-data\\.`],bG=/\.(ts|tsx|mts|cts)$/}),SG,CG=__esmMin(()=>{_e(),xG(),SG={command:`barrels [paths..]`,description:"Regenerate `index.ts` barrel files for the given directories. Drop-in replacement for `barrelsby`.",builder:t=>t.positional(`paths`,{description:"Directories whose `index.ts` to (re)generate. May also be passed via `--paths`.",type:`string`,array:!0}).option(`paths`,{alias:`p`,description:`Alternative to positional — repeatable list of directories.`,type:`string`,array:!0}).option(`ext`,{description:"Import-specifier extension. Default: `none` (bundler-mode resolution).",type:`string`,choices:[`js`,`ts`,`none`],default:`none`}).option(`base-dir`,{alias:`b`,description:"Resolve `paths` against this directory. Default: cwd.",type:`string`}).option(`exclude`,{description:"Regex(es) of file names to skip. Repeatable. Defaults: `\\.test\\.`, `\\.spec\\.`, `\\.test-data\\.`.",type:`string`,array:!0}).option(`header`,{description:`Header comment prepended to every generated file.`,type:`string`}).option(`semicolon`,{description:"Emit trailing `;` on each export line. Negate with `--no-semicolon`. Default: omitted.",type:`boolean`,default:!1}).option(`single-quotes`,{description:"Use `'` for import specifiers. Default: true. Pass `--no-single-quotes` for `\"`.",type:`boolean`,default:!0}).option(`check`,{description:`Report drift without modifying files; exit non-zero if any barrel is stale.`,type:`boolean`,default:!1}).option(`verbose`,{description:`Log each file scanned + written.`,type:`boolean`,default:!1}),handler:async t=>{let n=Array.from(new Set((t.paths??[]).filter(Boolean)));if(n.length===0){ge.error(`[gjsify barrels] no paths provided. Pass directories as positional arguments or via --paths.`),process.exitCode=1;return}let S=t.baseDir??process.cwd(),C=await unscannableBarrelPaths(S,n);if(C.length>0){for(let t of C)ge.error(`[gjsify barrels] cannot scan ${t}`);ge.error(`[gjsify barrels] ${C.length} of ${n.length} path(s) could not be scanned — refusing to report on the rest as if that were the whole set.`),process.exitCode=1;return}let N=t.exclude?.length?t.exclude:[...yG],F=await generateBarrels({paths:n,extension:t.ext??`none`,baseDir:S,exclude:N.map(t=>new RegExp(t)),header:t.header??"// Auto-generated by `gjsify barrels` — do not edit by hand.",noSemicolon:t.semicolon===!1||t.semicolon===void 0,singleQuotes:t.singleQuotes!==!1,check:t.check??!1,verbose:t.verbose??!1});t.check&&F>0&&(ge.error(`[gjsify barrels] ${F} barrel file(s) drifted. Run without --check to fix.`),process.exitCode=1)}}}),wG,TG=__esmMin(()=>{_e(),Il(),Pn(),Gn(),CF(),vF(),Rd(),xU(),rL(),eF(),V_(),wG={command:`tsc [tscArgs..]`,description:"Run TypeScript compiler (tsc) under GJS via the @gjsify/tsc bundle. All arguments are passed through to tsc. Equivalent to `gjsify-tsc <args>` from the @gjsify/tsc bin.",builder:t=>t.parserConfiguration({"unknown-options-as-args":!0}).version(!1).help(!1).positional(`tscArgs`,{description:"Arguments forwarded verbatim to tsc (e.g. `--version`, `-p tsconfig.json`).",type:`string`,array:!0,default:[]}),handler:async t=>{let n=(t._??[]).slice(1).map(String),S=t.tscArgs??[],C=n.length>0?n:S,N=process.cwd(),F=[pathToFileURL(`${findWorkspaceRoot(N)??N}/__gjsify_tsc__.js`).href,import.meta.url],I;for(let t of F)try{I=createRequire(t).resolve(`@gjsify/tsc/bundle`);break}catch{}let H;for(let t of F)try{H=wn(En(createRequire(t).resolve(`typescript/package.json`)),`lib`,`tsc.js`);break}catch{}if(!I&&!H)return ge.error("gjsify tsc: neither @gjsify/tsc (GJS bundle) nor npm `typescript` (Node) is installed."),ge.error(" Install with: gjsify install --save-dev @gjsify/tsc (or add `typescript`)."),forceExit(1);let W=buildNativeEnv(detectNativePackages(N)),q={...process.env,...W},runNodeTsc=async()=>{let t=nodeBinary();if(!(t.includes(`/`)||t.includes(`\\`)?existsSync(t):isOnPath(t)))return ge.error(`gjsify tsc: the @gjsify/tsc GJS bundle is unavailable and \`${t}\` cannot be run, so upstream \`typescript\` cannot run either.`),ge.error(` Build the bundle with: gjsify workspace @gjsify/tsc build`),ge.error(" …or install Node.js so the upstream `typescript` fallback can be spawned."),forceExit(1);try{await new Promise((n,S)=>{spawnToCompletion(t,[H,...C],{completion:`exit`,env:q,onSpawn:t=>{let n=!1;t.on(`error`,()=>{n=!0}),t.on(`close`,t=>{n||forceExit(t??1)})}}).catch(S)})}catch(t){let n=t;return n.code===`ENOENT`?(ge.error("gjsify tsc: the @gjsify/tsc GJS bundle is unavailable and `node` is not on PATH, so upstream `typescript` cannot run either."),ge.error(` Build the bundle with: gjsify workspace @gjsify/tsc build`)):ge.error(`gjsify tsc (node typescript): ${n.message}`),forceExit(1)}};if(I)try{await new Promise((t,n)=>{spawnToCompletion(`gjs`,[`-m`,I,...C],{completion:`exit`,env:q,onSpawn:t=>{let n=!1;t.on(`error`,()=>{n=!0}),t.on(`close`,t=>{n||forceExit(t??1)})}}).catch(n)})}catch(t){let n=t;return n.code===`ENOENT`&&H?await runNodeTsc():(n.code===`ENOENT`?(ge.error("gjsify tsc: `gjs` not found on PATH and no npm `typescript` fallback."),ge.error(" Install GJS (e.g. `dnf install gjs`), or add `typescript` to the project.")):ge.error(`gjsify tsc: ${n.message}`),forceExit(1))}else await runNodeTsc()}}});function readStdinText(){return readFileSync(0,`utf-8`)}function readStdinLines(){return splitStdinLines(readStdinText())}function splitStdinLines(t){return t.split(`
1754
+ `).map(t=>t.trim()).filter(Boolean)}var EG=__esmMin(()=>{Rd()});function isResolvableScript(t){return jG.test(t)&&!DG.some(n=>n.test(t))&&!AG.some(n=>n.match.test(t))}function resolveRootScripts(t,n){let S=new Set,C=[];for(let n of t)isResolvableScript(n)?C.push(n):S.add(n);let N=new Set;for(;C.length>0;){let t=C.shift();if(!N.has(t)){N.add(t);for(let N of n(t))OG.some(t=>t.test(N))||(isResolvableScript(N)?C.push(N):S.add(N))}}return{files:[...S],scripts:N.size}}function classifyAndExpand(t,n,S){let C=n.map(t=>t.replace(/\\/g,`/`)).filter(t=>t.length>0);if(C.length===0)return{global:!1,reason:`empty-diff`,workspaces:[],runE2E:!1,runIntegration:!1,skipAll:!0};let N=[];for(let t of C)OG.some(n=>n.test(t))||N.push(t);let F=``;if(S){let t=resolveRootScripts(N,S);t.scripts>0&&(N=t.files,F=`; ${t.scripts} root script(s) resolved to their readers`)}if(N.length===0)return{global:!1,reason:`ignored-only`+F,workspaces:[],runE2E:!1,runIntegration:!1,skipAll:!0};for(let n of N)for(let S of DG)if(S.test(n))return{global:!0,reason:`global-trigger ${S.source} matched ${n}${F}`,workspaces:t.map(t=>t.name),runE2E:!0,runIntegration:!0,skipAll:!1};let{matched:I,unmatched:H}=workspacesForChangedFiles(t,N),W=new Set(t.map(t=>t.name)),q=new Set,Y=new Set,X=!1;for(let n of AG){let S=N.filter(t=>n.match.test(t));if(S.length!==0){for(let t of S)Y.add(t);for(let S of n.seeds){if(!W.has(S))return{global:!0,reason:`script-coupling seed ${S} is not a workspace (${n.match.source} → ${n.why}); SCRIPT_COUPLINGS in commands/affected.ts is stale`,workspaces:t.map(t=>t.name),runE2E:!0,runIntegration:!0,skipAll:!1};q.add(S)}n.runE2E&&(X=!0)}}let Z=H.filter(t=>!Y.has(t));if(Z.length>0)return{global:!0,reason:`unmatched files (${Z.length}): ${Z.slice(0,3).join(`, `)}${Z.length>3?`…`:``}${F}`,workspaces:t.map(t=>t.name),runE2E:!0,runIntegration:!0,skipAll:!1};for(let t of q)I.add(t);if(q.size===0&&N.every(t=>kG.some(n=>n.test(t)))&&I.size===1){let t=[...I][0],n=N.some(t=>t.startsWith(`tests/e2e/`)),S=N.some(t=>t.startsWith(`tests/integration/`));return{global:!1,reason:`test-only (${N.length} file(s) in ${t})${F}`,workspaces:[t],runE2E:n||X,runIntegration:S||isIntegrationWorkspace(t),skipAll:!1}}let te=affectedClosure(buildReverseDependencyGraph(t,{includeDev:!1}),[...I]),ne=buildDependencyGraph(t,{includeDev:!0}),re=!1;for(let[t,n]of ne.edges)if(isIntegrationWorkspace(t)){for(let S of n)if(te.has(S)){te.add(t),re=!0;break}}let ie=N.some(t=>t.startsWith(`tests/e2e/`))||X;return{global:!1,reason:`closure (${te.size} ws from ${I.size} seed(s))`+(q.size>0?`, ${q.size} via script-coupling`:``)+F,workspaces:[...te].sort(),runE2E:ie,runIntegration:re,skipAll:!1}}function isIntegrationWorkspace(t){return t.startsWith(`@gjsify/integration-`)}var DG,OG,kG,AG,jG,MG=__esmMin(()=>{QP(),DG=[/^packages\/infra\/workspace\//,/^packages\/infra\/cli\//,/^packages\/infra\/rolldown-plugin-gjsify\//,/^packages\/infra\/resolve-npm\//,/^packages\/gjs\/unit\//,/^\.github\/actions\//,/^gjsify-lock\.json$/,/^package\.json$/,/^tsconfig[^/]*\.json$/,/^\.github\/workflows\/main\.yml$/,/^scripts\/audit-runtimes\.mjs$/],OG=[/\.md$/i,/^refs\//,/^website\//,/^docs\//,/^\.github\/workflows\/(deploy-docs|commitlint|release|release-cut|audit-runtimes|prebuilds|node-gi|napi|cli-cross-platform|build-ci-image|cancel-pr-runs|macos-suites|windows-suites|gtk-os-suites)\.yml$/,/^\.github\/prebuild-toolchain\//,/^scripts\/manifest-conformance\//,/^status\//,/^scripts\/generate-status\.mjs$/,/^packages\/node-gi\//,/^packages\/napi\//,/^flatpak\//,/^LICENSE/,/^\.gitignore$/,/^\.gjsify-[^/]*\.md$/,/^STATUS\.md$/,/^CHANGELOG\.md$/,/^AGENTS\.md$/,/^CLAUDE\.md$/,/^README\.md$/],kG=[/\.spec\.[mc]?[tj]sx?$/,/^tests\/(e2e|integration)\//],AG=[{match:/^\.githooks\//,seeds:[],runE2E:!0,why:`tests/e2e/git-hooks-cli-bundle-staleness drives .githooks/pre-commit`},{match:/^templates\//,seeds:[`@gjsify/create-app`],runE2E:!0,why:`@gjsify/create-app build → node scripts/process-template.mjs reads templates/`},{match:/^packages\/framework\/react-native\//,seeds:[],runE2E:!0,why:`tests/e2e/react-native-devtools is the only external observer of AppRegistry.runApplication`}],jG=/^scripts\/[^/]+$/});function stripCommentLines(t,n){let S=/\.(ya?ml|sh|bash|py|toml)$|(^|\/)\.git[a-z]*$|Dockerfile$/.test(t)?/^\s*#/:/^\s*(\/\/|\/\*|\*)/;return n.split(`
1755
1755
  `).filter(t=>!S.test(t)).join(`
1756
1756
  `)}function scriptNamePattern(t){let n=pn.basename(t),S=/^(.*?)(\.d)?\.[mc]?[jt]sx?$/.exec(n),C=S?`${escapeRe(S[1])}(\\.d)?\\.[mc]?[jt]sx?\\b`:`${escapeRe(n)}\\b`;return RegExp(`(^|[^\\w.-])${C}`)}function gatedJobs(t){let n=new Map,S=new Set;for(let{job:C,text:N}of t){if(!C)continue;n.has(C)||n.set(C,[]);let t=/^ {4}needs:\s*\[(.*)\]/.exec(N)??/^ {4}needs:\s*([A-Za-z0-9_-]+)\s*$/.exec(N);t&&n.set(C,t[1].split(`,`).map(t=>t.trim()).filter(Boolean)),(/needs\.changes\b/.test(N)||/^ {4}needs:\s*$/.test(N))&&S.add(C)}let C=new Set([`changes`,...S]),N=!0;for(;N;){N=!1;for(let[t,S]of n)!C.has(t)&&S.some(t=>C.has(t))&&(C.add(t),N=!0)}return C.delete(`changes`),C}function workflowLines(t){let n=t.split(`
1757
- `),S=[],C,N=!1;for(let t of n){/^jobs:\s*$/.test(t)?N=!0:/^\S/.test(t)&&(N=!1);let n=N?/^ {2}([A-Za-z0-9_-]+):\s*$/.exec(t):null;n&&(C=n[1]),!/^\s*#/.test(t)&&S.push({job:N?C:void 0,text:t})}return S}function buildScriptReferrers(t){let n=new Map;for(let[S,C]of t)S===EG||S===DG||n.set(S,stripCommentLines(S,C));let S=t.get(EG),C=S===void 0?[]:workflowLines(S),N=gatedJobs(C),gatedWorkflowNames=t=>C.some(n=>t.test(n.text)&&(n.job===void 0||N.has(n.job))),F,I=t.get(DG);I!==void 0&&(F=JSON.parse(I));let manifestReads=t=>{if(!F)return!1;for(let[n,S]of Object.entries(F))if(n!==`scripts`&&t.test(JSON.stringify(S)))return!0;let n=F.scripts??{};for(let[S,C]of Object.entries(n)){if(!t.test(C))continue;if(kG.test(S))return!0;let N=RegExp(`(^|[\\s"'])${escapeRe(S)}($|[\\s"'&;|])`);if(Object.entries(n).some(([t,n])=>t!==S&&N.test(n))||gatedWorkflowNames(N))return!0}return!1};return t=>{let S=scriptNamePattern(t),C=[];for(let[N,F]of n)N!==t&&S.test(F)&&C.push(N);return gatedWorkflowNames(S)&&C.push(EG),manifestReads(S)&&C.push(DG),C.sort()}}function readTrackedTexts(t){let n=spawnSync(`git`,[`ls-files`,`-z`],{cwd:t,encoding:`utf8`});if(n.status!==0)throw Error(`git ls-files failed (${n.status}): ${String(n.stderr).trim()}`);let S=new Map;for(let C of n.stdout.split(`\0`)){if(!C||C.startsWith(`refs/`))continue;let n=wn(t,C),N=statSync(n,{throwIfNoEntry:!1});if(!N?.isFile()||N.size>OG)continue;let F=readFileSync(n,`utf8`);F.includes(`\0`)||S.set(C,F)}return S}var EG,DG,OG,kG,escapeRe,AG=__esmMin(()=>{P_(),Rd(),Pn(),EG=`.github/workflows/main.yml`,DG=`package.json`,OG=2*1024*1024,kG=/^(pre|post)?(install|prepare|build|test)(:|$)/,escapeRe=t=>t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)});function scriptReadersFor(t,n){if(n.some(t=>/^scripts\/[^/]+$/.test(t.replace(/\\/g,`/`))))try{return buildScriptReferrers(readTrackedTexts(t))}catch(t){process.stderr.write(`gjsify affected: cannot index the tree for script readers (${String(t)}); root scripts stay unmatched\n`);return}}function runGitDiff(t,n,S){let C=spawnSync(`git`,[`diff`,`--no-renames`,`--name-only`,`${n}...${S}`],{cwd:t,encoding:`utf8`});if(C.status!==0)throw process.stderr.write(`gjsify affected: git diff failed (${C.status}): ${C.stderr.trim()}\n`),process.exit(2),Error(`gjsify affected: git diff failed (${C.status})`);return C.stdout.split(`
1757
+ `),S=[],C,N=!1;for(let t of n){/^jobs:\s*$/.test(t)?N=!0:/^\S/.test(t)&&(N=!1);let n=N?/^ {2}([A-Za-z0-9_-]+):\s*$/.exec(t):null;n&&(C=n[1]),!/^\s*#/.test(t)&&S.push({job:N?C:void 0,text:t})}return S}function buildScriptReferrers(t){let n=new Map;for(let[S,C]of t)S===NG||S===PG||n.set(S,stripCommentLines(S,C));let S=t.get(NG),C=S===void 0?[]:workflowLines(S),N=gatedJobs(C),gatedWorkflowNames=t=>C.some(n=>t.test(n.text)&&(n.job===void 0||N.has(n.job))),F,I=t.get(PG);I!==void 0&&(F=JSON.parse(I));let manifestReads=t=>{if(!F)return!1;for(let[n,S]of Object.entries(F))if(n!==`scripts`&&t.test(JSON.stringify(S)))return!0;let n=F.scripts??{};for(let[S,C]of Object.entries(n)){if(!t.test(C))continue;if(IG.test(S))return!0;let N=RegExp(`(^|[\\s"'])${escapeRe(S)}($|[\\s"'&;|])`);if(Object.entries(n).some(([t,n])=>t!==S&&N.test(n))||gatedWorkflowNames(N))return!0}return!1};return t=>{let S=scriptNamePattern(t),C=[];for(let[N,F]of n)N!==t&&S.test(F)&&C.push(N);return gatedWorkflowNames(S)&&C.push(NG),manifestReads(S)&&C.push(PG),C.sort()}}function readTrackedTexts(t){let n=spawnSync(`git`,[`ls-files`,`-z`],{cwd:t,encoding:`utf8`});if(n.status!==0)throw Error(`git ls-files failed (${n.status}): ${String(n.stderr).trim()}`);let S=new Map;for(let C of n.stdout.split(`\0`)){if(!C||C.startsWith(`refs/`))continue;let n=wn(t,C),N=statSync(n,{throwIfNoEntry:!1});if(!N?.isFile()||N.size>FG)continue;let F=readFileSync(n,`utf8`);F.includes(`\0`)||S.set(C,F)}return S}var NG,PG,FG,IG,escapeRe,LG=__esmMin(()=>{P_(),Rd(),Pn(),NG=`.github/workflows/main.yml`,PG=`package.json`,FG=2*1024*1024,IG=/^(pre|post)?(install|prepare|build|test)(:|$)/,escapeRe=t=>t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)});function scriptReadersFor(t,n){if(n.some(t=>/^scripts\/[^/]+$/.test(t.replace(/\\/g,`/`))))try{return buildScriptReferrers(readTrackedTexts(t))}catch(t){process.stderr.write(`gjsify affected: cannot index the tree for script readers (${String(t)}); root scripts stay unmatched\n`);return}}function runGitDiff(t,n,S){let C=spawnSync(`git`,[`diff`,`--no-renames`,`--name-only`,`${n}...${S}`],{cwd:t,encoding:`utf8`});if(C.status!==0)throw process.stderr.write(`gjsify affected: git diff failed (${C.status}): ${C.stderr.trim()}\n`),process.exit(2),Error(`gjsify affected: git diff failed (${C.status})`);return C.stdout.split(`
1758
1758
  `).filter(Boolean)}function emit(t,n){if(t===`json`){process.stdout.write(JSON.stringify(n)+`
1759
1759
  `);return}if(t===`globs`){for(let t of n.workspaces)process.stdout.write(`${t}\n`);return}if(t===`github-actions`){let t=n.global?``:n.workspaces.map(t=>`--include ${assertShellSafeWorkspaceName(t)}`).join(` `),S=process.env.GITHUB_OUTPUT,C=[`skip-all=${n.skipAll}`,`global=${n.global}`,`include-args=${t}`,`run-integration=${n.runIntegration}`,`run-e2e=${n.runE2E}`,`reason=${n.reason}`];if(S)for(let t of C)appendFileSync(S,`${t}\n`);else for(let t of C)process.stdout.write(`${t}\n`);return}process.stdout.write(`affected:
1760
- `),process.stdout.write(` reason: ${n.reason}\n`),process.stdout.write(` global: ${n.global}\n`),process.stdout.write(` skip-all: ${n.skipAll}\n`),process.stdout.write(` run-integration: ${n.runIntegration}\n`),process.stdout.write(` run-e2e: ${n.runE2E}\n`),process.stdout.write(` workspaces (${n.workspaces.length}):\n`);for(let t of n.workspaces)process.stdout.write(` - ${t}\n`)}function assertShellSafeWorkspaceName(t){if(MG.test(t))return t;throw process.stderr.write(`gjsify affected: workspace name ${JSON.stringify(t)} is not shell-safe, so it cannot be emitted as an\n \`include-args\` token (the value is consumed by an UNQUOTED $INCLUDE_ARGS expansion — see the\n contract at the top of commands/affected.ts). Rename the workspace, or teach this command a\n transport the consumers can unquote. Refusing to emit a filter that would silently mis-match.\n`),process.exit(2),Error(`gjsify affected: unsafe workspace name ${t}`)}var jG,MG,NG=__esmMin(()=>{P_(),Rd(),yG(),QP(),TG(),AG(),eF(),jG={command:`affected`,description:"Classify changed files against the workspace tree and print the set of workspaces affected (seeds + transitive dependents). Designed for CI to gate `gjsify foreach test --include …` so unrelated workspaces are not re-tested on every PR.",builder:t=>t.option(`base`,{description:"Diff base. Default: `origin/main`. Resolved via `git rev-parse`. On a PR set this to `${{ github.event.pull_request.base.sha }}`.",type:`string`}).option(`head`,{description:"Diff head. Default: `HEAD`.",type:`string`,default:`HEAD`}).option(`format`,{description:`Output shape.`,choices:[`text`,`json`,`globs`,`github-actions`],default:`text`}).option(`changed-from-stdin`,{description:"Skip `git diff`. Read a newline-separated list of repo-relative paths from stdin instead. Lets callers — tests, ad-hoc scripts — control the input exactly.",type:`boolean`,default:!1}).option(`cwd`,{description:"Workspace root. Default: discovered from `process.cwd()`.",type:`string`}),handler:async t=>{let n=t.cwd??findWorkspaceRoot(process.cwd())??process.cwd(),S=discoverWorkspaces(n,{includeRoot:!0}),C=t[`changed-from-stdin`]?readStdinLines():runGitDiff(n,t.base??`origin/main`,t.head??`HEAD`),N=classifyAndExpand(S,C,scriptReadersFor(n,C));emit(t.format,N)}},MG=/^[A-Za-z0-9@][A-Za-z0-9@._/-]*$/}),PG=__exportAll$5({isSelfWrite:()=>isSelfWrite,runWatchLoop:()=>runWatchLoop,spawnBundleSupervised:()=>spawnBundleSupervised,spawnSupervised:()=>spawnSupervised});function spawnSupervised(t,n,S){return new Promise((C,N)=>{spawnToCompletion(t,n,{completion:`daemon`,env:S,onSpawn:C}).catch(N)})}async function spawnBundleSupervised(t,n,S,C){if(t!==`gjs`){let{bundleRequiresNodeGi:N,resolveNodeGiForBundle:F}=await Promise.resolve().then(()=>(QI(),ZI));if(N(n)&&!F(n,S))throw Error(`Cannot run ${C} on ${t}: \`@gjsify/node-gi\` is not installed. Add @gjsify/node-gi as a dependency to run ${C} on ${t}.`)}let{computeNativeEnvForBundle:N}=await Promise.resolve().then(()=>(XI(),YI)),{env:F}=N(n,S),I={...process.env,...F};if(t===`gjs`)return spawnSupervised(`gjs`,[`-m`,n],I);if(t===`node`){let{nodeBinary:t}=await Promise.resolve().then(()=>(QI(),ZI));return spawnSupervised(t(),[n],I)}let[H,W]=U_[t].launch(n);return spawnSupervised(H,W,I)}function isSelfWrite(t,n,S){if(n===void 0||S===null)return!1;let C=xn(t,S),N=xn(t,n);if(C===N||C.startsWith(`${N}.`))return!0;let F=En(N);return F===xn(t)?!1:C===F||C.startsWith(`${F}${jn}`)}async function runWatchLoop(t){let{dir:n,label:S,prepare:C,build:N,spawnChild:F,output:I,ignore:H,debounceMs:W=200}=t;markDaemonCommand();let q=null,Y=!1,X=!1,rebuild=async()=>{if(Y){X=!0;return}Y=!0;try{C&&await C(),q&&=(q.kill(),null),await N(),F&&(q=await F())}catch(t){ge.error(`[${S}] rebuild failed: ${t.message}`)}finally{Y=!1,X&&(X=!1,rebuild())}};await rebuild();let Z=null,te=(t.watch??[{path:n,recursive:!0}]).map(t=>watch(t.path,{recursive:t.recursive},(n,S)=>{let C=typeof S==`string`?S:null;isSelfWrite(t.path,I,C)||H&&C!==null&&H(xn(t.path,C))||(Z&&clearTimeout(Z),Z=setTimeout(()=>void rebuild(),W))}));holdMainLoop();let ne=!1,shutdown=()=>{if(!ne){ne=!0,Z&&clearTimeout(Z),q?.kill();for(let t of te)t.close();process.exit(0)}};process.on(`SIGINT`,shutdown),process.on(`SIGTERM`,shutdown),ge.log(`[${S}] watching ${t.dirLabel??n} — press Ctrl+C to stop`)}var FG=__esmMin(()=>{_e(),Rd(),Pn(),Le(),uR(),V_(),W_()});function readPackage$4(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}function deriveAppId(t){return t?`org.gjsify.storybook.${t.replace(/^@/,``).replace(/[^a-zA-Z0-9]+/g,`.`).replace(/^\.+|\.+$/g,``)}`:`org.gjsify.Storybook`}function findStoryFiles(t){let n=[];if(!existsSync(t))return n;for(let S of readdirSync(t,{withFileTypes:!0})){if(S.name===`node_modules`||S.name.startsWith(`.`))continue;let C=wn(t,S.name);S.isDirectory()?n.push(...findStoryFiles(C)):/\.story\.(ts|js|mts|mjs)$/.test(S.name)&&n.push(C)}return n}function generateEntry$4(t,n,S){let C=t.map((t,n)=>`import * as m${n} from ${JSON.stringify(t)};`).join(`
1760
+ `),process.stdout.write(` reason: ${n.reason}\n`),process.stdout.write(` global: ${n.global}\n`),process.stdout.write(` skip-all: ${n.skipAll}\n`),process.stdout.write(` run-integration: ${n.runIntegration}\n`),process.stdout.write(` run-e2e: ${n.runE2E}\n`),process.stdout.write(` workspaces (${n.workspaces.length}):\n`);for(let t of n.workspaces)process.stdout.write(` - ${t}\n`)}function assertShellSafeWorkspaceName(t){if(zG.test(t))return t;throw process.stderr.write(`gjsify affected: workspace name ${JSON.stringify(t)} is not shell-safe, so it cannot be emitted as an\n \`include-args\` token (the value is consumed by an UNQUOTED $INCLUDE_ARGS expansion — see the\n contract at the top of commands/affected.ts). Rename the workspace, or teach this command a\n transport the consumers can unquote. Refusing to emit a filter that would silently mis-match.\n`),process.exit(2),Error(`gjsify affected: unsafe workspace name ${t}`)}var RG,zG,BG=__esmMin(()=>{P_(),Rd(),EG(),QP(),MG(),LG(),eF(),RG={command:`affected`,description:"Classify changed files against the workspace tree and print the set of workspaces affected (seeds + transitive dependents). Designed for CI to gate `gjsify foreach test --include …` so unrelated workspaces are not re-tested on every PR.",builder:t=>t.option(`base`,{description:"Diff base. Default: `origin/main`. Resolved via `git rev-parse`. On a PR set this to `${{ github.event.pull_request.base.sha }}`.",type:`string`}).option(`head`,{description:"Diff head. Default: `HEAD`.",type:`string`,default:`HEAD`}).option(`format`,{description:`Output shape.`,choices:[`text`,`json`,`globs`,`github-actions`],default:`text`}).option(`changed-from-stdin`,{description:"Skip `git diff`. Read a newline-separated list of repo-relative paths from stdin instead. Lets callers — tests, ad-hoc scripts — control the input exactly.",type:`boolean`,default:!1}).option(`cwd`,{description:"Workspace root. Default: discovered from `process.cwd()`.",type:`string`}),handler:async t=>{let n=t.cwd??findWorkspaceRoot(process.cwd())??process.cwd(),S=discoverWorkspaces(n,{includeRoot:!0}),C=t[`changed-from-stdin`]?readStdinLines():runGitDiff(n,t.base??`origin/main`,t.head??`HEAD`),N=classifyAndExpand(S,C,scriptReadersFor(n,C));emit(t.format,N)}},zG=/^[A-Za-z0-9@][A-Za-z0-9@._/-]*$/}),VG=__exportAll$5({isSelfWrite:()=>isSelfWrite,runWatchLoop:()=>runWatchLoop,spawnBundleSupervised:()=>spawnBundleSupervised,spawnSupervised:()=>spawnSupervised});function spawnSupervised(t,n,S){return new Promise((C,N)=>{spawnToCompletion(t,n,{completion:`daemon`,env:S,onSpawn:C}).catch(N)})}async function spawnBundleSupervised(t,n,S,C){if(t!==`gjs`){let{bundleRequiresNodeGi:N,resolveNodeGiForBundle:F}=await Promise.resolve().then(()=>(rL(),nL));if(N(n)&&!F(n,S))throw Error(`Cannot run ${C} on ${t}: \`@gjsify/node-gi\` is not installed. Add @gjsify/node-gi as a dependency to run ${C} on ${t}.`)}let{computeNativeEnvForBundle:N}=await Promise.resolve().then(()=>(tL(),eL)),{env:F}=N(n,S),I={...process.env,...F};if(t===`gjs`)return spawnSupervised(`gjs`,[`-m`,n],I);if(t===`node`){let{nodeBinary:t}=await Promise.resolve().then(()=>(rL(),nL));return spawnSupervised(t(),[n],I)}let[H,W]=U_[t].launch(n);return spawnSupervised(H,W,I)}function isSelfWrite(t,n,S){if(n===void 0||S===null)return!1;let C=xn(t,S),N=xn(t,n);if(C===N||C.startsWith(`${N}.`))return!0;let F=En(N);return F===xn(t)?!1:C===F||C.startsWith(`${F}${jn}`)}async function runWatchLoop(t){let{dir:n,label:S,prepare:C,build:N,spawnChild:F,output:I,ignore:H,debounceMs:W=200}=t;markDaemonCommand();let q=null,Y=!1,X=!1,rebuild=async()=>{if(Y){X=!0;return}Y=!0;try{C&&await C(),q&&=(q.kill(),null),await N(),F&&(q=await F())}catch(t){ge.error(`[${S}] rebuild failed: ${t.message}`)}finally{Y=!1,X&&(X=!1,rebuild())}};await rebuild();let Z=null,te=(t.watch??[{path:n,recursive:!0}]).map(t=>watch(t.path,{recursive:t.recursive},(n,S)=>{let C=typeof S==`string`?S:null;isSelfWrite(t.path,I,C)||H&&C!==null&&H(xn(t.path,C))||(Z&&clearTimeout(Z),Z=setTimeout(()=>void rebuild(),W))}));holdMainLoop();let ne=!1,shutdown=()=>{if(!ne){ne=!0,Z&&clearTimeout(Z),q?.kill();for(let t of te)t.close();process.exit(0)}};process.on(`SIGINT`,shutdown),process.on(`SIGTERM`,shutdown),ge.log(`[${S}] watching ${t.dirLabel??n} — press Ctrl+C to stop`)}var HG=__esmMin(()=>{_e(),Rd(),Pn(),Le(),hR(),V_(),W_()});function readPackage$4(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}function deriveAppId(t){return t?`org.gjsify.storybook.${t.replace(/^@/,``).replace(/[^a-zA-Z0-9]+/g,`.`).replace(/^\.+|\.+$/g,``)}`:`org.gjsify.Storybook`}function findStoryFiles(t){let n=[];if(!existsSync(t))return n;for(let S of readdirSync(t,{withFileTypes:!0})){if(S.name===`node_modules`||S.name.startsWith(`.`))continue;let C=wn(t,S.name);S.isDirectory()?n.push(...findStoryFiles(C)):/\.story\.(ts|js|mts|mjs)$/.test(S.name)&&n.push(C)}return n}function generateEntry$4(t,n,S){let C=t.map((t,n)=>`import * as m${n} from ${JSON.stringify(t)};`).join(`
1761
1761
  `),N=t.map((t,n)=>`m${n}`).join(`, `),F=S?`\n title: ${JSON.stringify(S)},`:``;return`// Auto-generated by \`gjsify storybook\` — do not edit by hand.
1762
1762
  import { collectStoryModules, runStorybook } from '@gjsify/storybook';
1763
1763
  ${C}
@@ -1766,14 +1766,14 @@ await runStorybook({
1766
1766
  applicationId: ${JSON.stringify(n)},${F}
1767
1767
  stories: collectStoryModules([${N}]),
1768
1768
  });
1769
- `}var IG,LG=__esmMin(()=>{_e(),Rd(),Pn(),d_(),__name$1(readPackage$4,`readPackage`),__name$1(generateEntry$4,`generateEntry`),IG={command:`storybook`,description:`Discover *.story.ts in this project and launch the GTK storybook browser.`,builder:t=>t.option(`stories`,{description:`Directory scanned recursively for *.story.ts (default: src, or gjsify.storybook.stories)`,type:`string`}).option(`app-id`,{description:`GApplication id (default: gjsify.storybook.applicationId or derived from the package name)`,type:`string`}).option(`title`,{description:`Window title`,type:`string`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto; use auto,dom for canvas/DOM stories)",type:`string`}).option(`out`,{description:`Output bundle path (default: node_modules/.cache/gjsify-storybook)`,type:`string`}).option(`runtime`,{description:"Runtime to build for and launch on: gjs | node | bun | deno (default: the host runtime). node/bun/deno build the same `--app node` bundle (gi:// → @gjsify/node-gi) and require @gjsify/node-gi installed in the project.",type:`string`,choices:[`gjs`,`node`,`bun`,`deno`],defaultDescription:`host runtime (gjs on gjs, else node/bun/deno)`}).option(`watch`,{description:`Rebuild and relaunch when a story file changes`,type:`boolean`,default:!1}).option(`build-only`,{description:`Build the bundle but do not launch it`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=readPackage$4(n),C=S.gjsify?.storybook??{},N=xn(n,t.stories??C.stories??`src`),F=t.appId??C.applicationId??deriveAppId(S.name),I=t.title??C.title,H=t.globals??C.globals??`auto`,W=t.runtime??C.runtime??hostRuntime$1(),q=W===`gjs`?`gjs`:`node`,Y=wn(n,`node_modules`,`.cache`,`gjsify-storybook`);mkdirSync(Y,{recursive:!0});let X=wn(Y,`entry.ts`),Z=t.out?xn(n,t.out):wn(Y,`storybook.${q}.mjs`),writeEntry=()=>{let t=findStoryFiles(N).sort();return writeFileSync(X,generateEntry$4(t,F,I)),t.length},te=writeEntry();if(te===0)return ge.error(`No *.story.ts files found under ${Tn(n,N)||N}\n\n \`gjsify storybook\` renders the stories of the CURRENT project: it discovers\n \`*.story.ts\` files and launches a component browser over them. Point it at a\n different directory with --stories <dir> (or \`gjsify.storybook.stories\` in\n package.json) if yours live elsewhere.\n\n To SEE a storybook without authoring one first, run the curated Libadwaita\n component browser — it is a showcase, so it needs no project at all:\n\n gjsify showcase adwaita-storybook`),process.exit(1);ge.log(`Found ${te} story file(s) under ${Tn(n,N)||`.`} (runtime: ${W})`);let{runCli:ne}=await Promise.resolve().then(()=>(IK(),FK)),buildBundle=()=>ne([`build`,X,`--app`,q,`--globals`,H,`--outfile`,Z]),launch=async()=>{if(W===`gjs`){let{runGjsBundle:t}=await Promise.resolve().then(()=>(XI(),YI));await t(Z,[],{completion:`exit`,exitOnSuccess:!0})}else if(W===`node`){let{runNodeBundle:t}=await Promise.resolve().then(()=>(QI(),ZI));await t(Z,[],{completion:`exit`,exitOnSuccess:!0})}else{let{runRuntimeBundle:t}=await Promise.resolve().then(()=>(QI(),ZI));await t(W,Z,[],{completion:`exit`,exitOnSuccess:!0})}};if(!t.watch){if(await buildBundle(),t.buildOnly)return;await launch();return}let{runWatchLoop:re,spawnBundleSupervised:ie}=await Promise.resolve().then(()=>(FG(),PG));await re({dir:N,dirLabel:Tn(n,N)||`.`,label:`storybook`,prepare:()=>{writeEntry()},build:buildBundle,spawnChild:t.buildOnly?null:()=>ie(W,Z,n,`the storybook`),output:Z})}}});function resolveSitePackage(t){let n=xn(t);for(;;){let t=wn(n,`node_modules`,`@gjsify`,`site`);if(existsSync(wn(t,`package.json`)))return t;let S=En(n);if(S===n)return;n=S}}function gjsOnPath(){return spawnSync(`gjs`,[`--version`],{stdio:`ignore`}).status===0}function pickRuntime(t,n){if(t)return t;let S=hostRuntime$1();return S===`gjs`||resolveNodeGi(n)?S:gjsOnPath()?`gjs`:S}function generateEntry$3(t){let n=`// Auto-generated by \`gjsify site\` — do not edit by hand.
1769
+ `}var UG,WG=__esmMin(()=>{_e(),Rd(),Pn(),d_(),__name$1(readPackage$4,`readPackage`),__name$1(generateEntry$4,`generateEntry`),UG={command:`storybook`,description:`Discover *.story.ts in this project and launch the GTK storybook browser.`,builder:t=>t.option(`stories`,{description:`Directory scanned recursively for *.story.ts (default: src, or gjsify.storybook.stories)`,type:`string`}).option(`app-id`,{description:`GApplication id (default: gjsify.storybook.applicationId or derived from the package name)`,type:`string`}).option(`title`,{description:`Window title`,type:`string`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto; use auto,dom for canvas/DOM stories)",type:`string`}).option(`out`,{description:`Output bundle path (default: node_modules/.cache/gjsify-storybook)`,type:`string`}).option(`runtime`,{description:"Runtime to build for and launch on: gjs | node | bun | deno (default: the host runtime). node/bun/deno build the same `--app node` bundle (gi:// → @gjsify/node-gi) and require @gjsify/node-gi installed in the project.",type:`string`,choices:[`gjs`,`node`,`bun`,`deno`],defaultDescription:`host runtime (gjs on gjs, else node/bun/deno)`}).option(`watch`,{description:`Rebuild and relaunch when a story file changes`,type:`boolean`,default:!1}).option(`build-only`,{description:`Build the bundle but do not launch it`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=readPackage$4(n),C=S.gjsify?.storybook??{},N=xn(n,t.stories??C.stories??`src`),F=t.appId??C.applicationId??deriveAppId(S.name),I=t.title??C.title,H=t.globals??C.globals??`auto`,W=t.runtime??C.runtime??hostRuntime$1(),q=W===`gjs`?`gjs`:`node`,Y=wn(n,`node_modules`,`.cache`,`gjsify-storybook`);mkdirSync(Y,{recursive:!0});let X=wn(Y,`entry.ts`),Z=t.out?xn(n,t.out):wn(Y,`storybook.${q}.mjs`),writeEntry=()=>{let t=findStoryFiles(N).sort();return writeFileSync(X,generateEntry$4(t,F,I)),t.length},te=writeEntry();if(te===0)return ge.error(`No *.story.ts files found under ${Tn(n,N)||N}\n\n \`gjsify storybook\` renders the stories of the CURRENT project: it discovers\n \`*.story.ts\` files and launches a component browser over them. Point it at a\n different directory with --stories <dir> (or \`gjsify.storybook.stories\` in\n package.json) if yours live elsewhere.\n\n To SEE a storybook without authoring one first, run the curated Libadwaita\n component browser — it is a showcase, so it needs no project at all:\n\n gjsify showcase adwaita-storybook`),process.exit(1);ge.log(`Found ${te} story file(s) under ${Tn(n,N)||`.`} (runtime: ${W})`);let{runCli:ne}=await Promise.resolve().then(()=>(UK(),HK)),buildBundle=()=>ne([`build`,X,`--app`,q,`--globals`,H,`--outfile`,Z]),launch=async()=>{if(W===`gjs`){let{runGjsBundle:t}=await Promise.resolve().then(()=>(tL(),eL));await t(Z,[],{completion:`exit`,exitOnSuccess:!0})}else if(W===`node`){let{runNodeBundle:t}=await Promise.resolve().then(()=>(rL(),nL));await t(Z,[],{completion:`exit`,exitOnSuccess:!0})}else{let{runRuntimeBundle:t}=await Promise.resolve().then(()=>(rL(),nL));await t(W,Z,[],{completion:`exit`,exitOnSuccess:!0})}};if(!t.watch){if(await buildBundle(),t.buildOnly)return;await launch();return}let{runWatchLoop:re,spawnBundleSupervised:ie}=await Promise.resolve().then(()=>(HG(),VG));await re({dir:N,dirLabel:Tn(n,N)||`.`,label:`storybook`,prepare:()=>{writeEntry()},build:buildBundle,spawnChild:t.buildOnly?null:()=>ie(W,Z,n,`the storybook`),output:Z})}}});function resolveSitePackage(t){let n=xn(t);for(;;){let t=wn(n,`node_modules`,`@gjsify`,`site`);if(existsSync(wn(t,`package.json`)))return t;let S=En(n);if(S===n)return;n=S}}function gjsOnPath(){return spawnSync(`gjs`,[`--version`],{stdio:`ignore`}).status===0}function pickRuntime(t,n){if(t)return t;let S=hostRuntime$1();return S===`gjs`||resolveNodeGi(n)?S:gjsOnPath()?`gjs`:S}function generateEntry$3(t){let n=`// Auto-generated by \`gjsify site\` — do not edit by hand.
1770
1770
  import { runSiteCli } from '@gjsify/site';
1771
- `;return t===`gjs`?`${n}import system from 'system';\n\nsystem.exit(await runSiteCli(system.programArgs));\n`:`${n}\nprocess.exit(await runSiteCli(process.argv.slice(2)));\n`}var RG,zG=__esmMin(()=>{_e(),P_(),Rd(),Pn(),d_(),QI(),__name$1(generateEntry$3,`generateEntry`),RG={command:`site <operation>`,description:`Render this project's static landing page from its AppStream metainfo (downloads, screenshots, release notes, support links), or sync the page catalogues.`,builder:t=>t.positional(`operation`,{description:`build — render the pages; i18n — update the page catalogues`,type:`string`,choices:[`build`,`i18n`],demandOption:!0}).option(`root`,{description:`Repository to read from (default: the working directory)`,type:`string`}).option(`overview`,{description:`build: render the support overview listed in this JSON file instead of one app`,type:`string`}).option(`out`,{description:`Output directory, emptied first (default: <root>/dist)`,type:`string`}).option(`offline`,{description:`Skip every network call`,type:`boolean`,default:!1}).option(`cache`,{description:`Use the one-hour HTTP response cache (--no-cache to ignore it)`,type:`boolean`,default:!0}).option(`cache-dir`,{description:`Where the response cache and the image renditions live`,defaultDescription:`<root>/node_modules/.cache/gjsify-site`,type:`string`}).option(`check`,{description:`i18n: report what is out of date instead of writing it`,type:`boolean`,default:!1}).option(`package`,{description:`i18n: sync @gjsify/site's own catalogues instead of this project's`,type:`boolean`,default:!1}).option(`runtime`,{description:"Runtime to build for and run on: gjs | node | bun | deno (default: the host runtime). node/bun/deno build the same `--app node` bundle and require @gjsify/node-gi in the project; without it the default falls back to gjs.",type:`string`,choices:[`gjs`,`node`,`bun`,`deno`],defaultDescription:`host runtime (gjs on gjs, else node/bun/deno)`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto)",type:`string`}),handler:async t=>{let n=process.cwd(),S=resolveSitePackage(n);if(!S)return ge.error(`gjsify site: @gjsify/site is not installed in this project.
1771
+ `;return t===`gjs`?`${n}import system from 'system';\n\nsystem.exit(await runSiteCli(system.programArgs));\n`:`${n}\nprocess.exit(await runSiteCli(process.argv.slice(2)));\n`}var GG,KG=__esmMin(()=>{_e(),P_(),Rd(),Pn(),d_(),rL(),__name$1(generateEntry$3,`generateEntry`),GG={command:`site <operation>`,description:`Render this project's static landing page from its AppStream metainfo (downloads, screenshots, release notes, support links), or sync the page catalogues.`,builder:t=>t.positional(`operation`,{description:`build — render the pages; i18n — update the page catalogues`,type:`string`,choices:[`build`,`i18n`],demandOption:!0}).option(`root`,{description:`Repository to read from (default: the working directory)`,type:`string`}).option(`overview`,{description:`build: render the support overview listed in this JSON file instead of one app`,type:`string`}).option(`out`,{description:`Output directory, emptied first (default: <root>/dist)`,type:`string`}).option(`offline`,{description:`Skip every network call`,type:`boolean`,default:!1}).option(`cache`,{description:`Use the one-hour HTTP response cache (--no-cache to ignore it)`,type:`boolean`,default:!0}).option(`cache-dir`,{description:`Where the response cache and the image renditions live`,defaultDescription:`<root>/node_modules/.cache/gjsify-site`,type:`string`}).option(`check`,{description:`i18n: report what is out of date instead of writing it`,type:`boolean`,default:!1}).option(`package`,{description:`i18n: sync @gjsify/site's own catalogues instead of this project's`,type:`boolean`,default:!1}).option(`runtime`,{description:"Runtime to build for and run on: gjs | node | bun | deno (default: the host runtime). node/bun/deno build the same `--app node` bundle and require @gjsify/node-gi in the project; without it the default falls back to gjs.",type:`string`,choices:[`gjs`,`node`,`bun`,`deno`],defaultDescription:`host runtime (gjs on gjs, else node/bun/deno)`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto)",type:`string`}),handler:async t=>{let n=process.cwd(),S=resolveSitePackage(n);if(!S)return ge.error(`gjsify site: @gjsify/site is not installed in this project.
1772
1772
 
1773
1773
  The generator ships as its own package so a project only pays for it when it
1774
1774
  publishes a page. Add it, then run this again:
1775
1775
 
1776
- npm install --save-dev @gjsify/site`),process.exit(1);if(!existsSync(wn(S,`lib`,`client`,`site.js`)))return ge.error(`gjsify site: ${S} has no built client bundle (lib/client/site.js).\n In a source checkout, build the package first: \`gjsify workspace site build\`.`),process.exit(1);let C=pickRuntime(t.runtime,n),N=C===`gjs`?`gjs`:`node`,F=wn(n,`node_modules`,`.cache`,`gjsify-site`);mkdirSync(F,{recursive:!0});let I=wn(F,`entry.${N}.ts`),H=wn(F,`site.${N}.mjs`);writeFileSync(I,generateEntry$3(N));let W=t.globals??`auto`;if(N===`gjs`){let{BuildAction:t}=await Promise.resolve().then(()=>(SI(),yI));await t.bundleFileForGjs(I,H,{globals:W,preserveDefaultExport:!1,toolchainAnchor:t.runningCliFile(),logLevel:`silent`})}else{let{runCli:t}=await Promise.resolve().then(()=>(IK(),FK));await t([`build`,I,`--app`,N,`--globals`,W,`--outfile`,H])}let q=[t.operation,`--package-dir`,S];if(t.root&&q.push(`--root`,xn(n,t.root)),t.out&&q.push(`--out`,xn(n,t.out)),t.overview&&q.push(`--overview`,xn(n,t.overview)),t.offline&&q.push(`--offline`),t.cache?t.cacheDir&&q.push(`--cache-dir`,xn(n,t.cacheDir)):q.push(`--no-cache`),t.check&&q.push(`--check`),t.package&&q.push(`--package`),C===`gjs`){let{runGjsBundle:t}=await Promise.resolve().then(()=>(XI(),YI));await t(H,q,{completion:`exit`,exitOnSuccess:!0});return}if(C===`node`){let{runNodeBundle:t}=await Promise.resolve().then(()=>(QI(),ZI));await t(H,q,{completion:`exit`,exitOnSuccess:!0});return}let{runRuntimeBundle:Y}=await Promise.resolve().then(()=>(QI(),ZI));await Y(C,H,q,{completion:`exit`,exitOnSuccess:!0})}}});function readFlag(t,n){let S=`--${n}`;for(let n=0;n<t.length;n++){let C=t[n];if(C===S)return t[n+1];if(C.startsWith(`${S}=`))return C.slice(S.length+1)}}function withFlag(t,n,S){let C=`--${n}`,N=[...t];for(let t=0;t<N.length;t++){let n=N[t];if(n===C)return N[t+1]=S,N;if(n.startsWith(`${C}=`))return N[t]=`${C}=${S}`,N}return N.push(C,S),N}function buildEntryPoint(t){let n=t[1];if(!(n===void 0||n.startsWith(`-`)))return n}function noEntryError(t,n){let S=n?`\`${t}\` is not a plain \`gjsify build <entry> …\` command, so its entry point cannot be read`:`this package declares no \`${t}\` script`;return Error(`gjsify dev: nothing to build — ${S}.\n Name the entry point directly: gjsify dev src/index.ts\n or point at another script: gjsify dev --script <name>`)}function planDev(t){let n=t.scripts[t.scriptName],S=typeof n==`string`?gjsifyCommandArgv(n):null,C=S&&S[0]===`build`?S:null,N=t.entry??(C?buildEntryPoint(C):void 0);if(N===void 0)throw noEntryError(t.scriptName,typeof n==`string`);let F;return C?(F=[...C],buildEntryPoint(C)===void 0?F.splice(1,0,N):F[1]=N):F=[`build`,N],F=withFlag(F,`app`,t.app),t.globals!==void 0&&(F=withFlag(F,`globals`,t.globals)),t.outfile!==void 0&&(F=withFlag(F,`outfile`,t.outfile)),{buildArgv:F,bundle:readFlag(F,`outfile`)??t.declaredBundle,watchDir:t.watchDir??En(N)}}function noBundleError(t,n){return Error(`gjsify dev: nothing to launch — neither \`${t}\` nor --outfile names an output file, and this package declares no ${n===`gjs`?"`gjsify.main`":"`gjsify.example.node`"}.\n Pass one: gjsify dev --outfile dist/index.${n}.mjs\n or rebuild without launching: gjsify dev --build-only`)}var BG=__esmMin(()=>{Pn(),hI()});function readPackage$3(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}var VG,HG=__esmMin(()=>{_e(),Rd(),Pn(),BG(),W_(),d_(),__name$1(readPackage$3,`readPackage`),VG={command:`dev [entry]`,description:`Watch this project, rebuild on change and relaunch the app.`,builder:t=>t.positional(`entry`,{description:"Entry point to build (default: the one the build script names, e.g. src/index.ts from `build:gjs`).",type:`string`}).option(`runtime`,{description:"Runtime to build for and launch on: gjs | node | bun | deno (default: the host runtime). node/bun/deno build the same `--app node` bundle.",type:`string`,choices:H_,defaultDescription:`host runtime (gjs on gjs, else node/bun/deno)`}).option(`script`,{description:`package.json script the build flags are read from (default: build:gjs, or build:node for node/bun/deno).`,type:`string`}).option(`globals`,{description:"Override the build script `--globals` value.",type:`string`}).option(`outfile`,{description:"Override the build script `--outfile` path.",type:`string`}).option(`watch-dir`,{description:`Directory watched recursively (default: the directory of the entry point).`,type:`string`}).option(`debounce`,{description:`Quiet window in ms after a change before rebuilding.`,type:`number`,default:200}).option(`build-only`,{description:`Rebuild on every change but never launch the app.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=readPackage$3(n),C=t.runtime??hostRuntime$1(),N=buildAppForRuntime(C),F=t.script??(N===`gjs`?`build:gjs`:`build:node`),I;try{I=planDev({scripts:S.scripts??{},scriptName:F,app:N,declaredBundle:N===`gjs`?S.gjsify?.main:S.gjsify?.example?.node,entry:t.entry,globals:t.globals,outfile:t.outfile,watchDir:t.watchDir})}catch(t){return ge.error(t.message),process.exit(1)}let H=I.bundle===void 0?void 0:xn(n,I.bundle);if(H===void 0&&!t.buildOnly)return ge.error(noBundleError(F,N).message),process.exit(1);let W=xn(n,I.watchDir);if(!existsSync(W))return ge.error(`gjsify dev: nothing to watch — ${Tn(n,W)||W} does not exist.\n Point the loop at your sources: gjsify dev --watch-dir <dir>`),process.exit(1);let q=H===void 0?`\`${F}\` output`:Tn(n,H);ge.log(`Watching ${Tn(n,W)||`.`} → ${q} (runtime: ${C})`);let{runCli:Y}=await Promise.resolve().then(()=>(IK(),FK)),{runWatchLoop:X,spawnBundleSupervised:Z}=await Promise.resolve().then(()=>(FG(),PG));await X({dir:W,dirLabel:Tn(n,W)||`.`,label:`dev`,build:()=>Y(I.buildArgv),spawnChild:t.buildOnly||H===void 0?null:()=>Z(C,H,n,`this project`),output:H,debounceMs:t.debounce})}}});function readPackage$2(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}function deriveStorybookAppId(t){return t?`org.gjsify.storybook.${t.replace(/^@/,``).replace(/[^a-zA-Z0-9]+/g,`.`).replace(/^\.+|\.+$/g,``)}`:`org.gjsify.Storybook`}function deriveBrowserAppId$1(t){return t?`org.gjsify.browser.${t.replace(/^@/,``).replace(/[^a-zA-Z0-9]+/g,`.`).replace(/^\.+|\.+$/g,``)}`:`org.gjsify.Browser`}function hasDep(t,n){return!!(t.dependencies?.[n]||t.devDependencies?.[n])}function generateEntry$2(t,n,S,C,N){let F=JSON.stringify(n),I=N?`, { address: ${JSON.stringify(N)} }`:``;return t===`storybook`?`// Auto-generated by \`gjsify debug\` — do not edit by hand.
1776
+ npm install --save-dev @gjsify/site`),process.exit(1);if(!existsSync(wn(S,`lib`,`client`,`site.js`)))return ge.error(`gjsify site: ${S} has no built client bundle (lib/client/site.js).\n In a source checkout, build the package first: \`gjsify workspace site build\`.`),process.exit(1);let C=pickRuntime(t.runtime,n),N=C===`gjs`?`gjs`:`node`,F=wn(n,`node_modules`,`.cache`,`gjsify-site`);mkdirSync(F,{recursive:!0});let I=wn(F,`entry.${N}.ts`),H=wn(F,`site.${N}.mjs`);writeFileSync(I,generateEntry$3(N));let W=t.globals??`auto`;if(N===`gjs`){let{BuildAction:t}=await Promise.resolve().then(()=>(DI(),wI));await t.bundleFileForGjs(I,H,{globals:W,preserveDefaultExport:!1,toolchainAnchor:t.runningCliFile(),logLevel:`silent`})}else{let{runCli:t}=await Promise.resolve().then(()=>(UK(),HK));await t([`build`,I,`--app`,N,`--globals`,W,`--outfile`,H])}let q=[t.operation,`--package-dir`,S];if(t.root&&q.push(`--root`,xn(n,t.root)),t.out&&q.push(`--out`,xn(n,t.out)),t.overview&&q.push(`--overview`,xn(n,t.overview)),t.offline&&q.push(`--offline`),t.cache?t.cacheDir&&q.push(`--cache-dir`,xn(n,t.cacheDir)):q.push(`--no-cache`),t.check&&q.push(`--check`),t.package&&q.push(`--package`),C===`gjs`){let{runGjsBundle:t}=await Promise.resolve().then(()=>(tL(),eL));await t(H,q,{completion:`exit`,exitOnSuccess:!0});return}if(C===`node`){let{runNodeBundle:t}=await Promise.resolve().then(()=>(rL(),nL));await t(H,q,{completion:`exit`,exitOnSuccess:!0});return}let{runRuntimeBundle:Y}=await Promise.resolve().then(()=>(rL(),nL));await Y(C,H,q,{completion:`exit`,exitOnSuccess:!0})}}});function readFlag(t,n){let S=`--${n}`;for(let n=0;n<t.length;n++){let C=t[n];if(C===S)return t[n+1];if(C.startsWith(`${S}=`))return C.slice(S.length+1)}}function withFlag(t,n,S){let C=`--${n}`,N=[...t];for(let t=0;t<N.length;t++){let n=N[t];if(n===C)return N[t+1]=S,N;if(n.startsWith(`${C}=`))return N[t]=`${C}=${S}`,N}return N.push(C,S),N}function buildEntryPoint(t){let n=t[1];if(!(n===void 0||n.startsWith(`-`)))return n}function noEntryError(t,n){let S=n?`\`${t}\` is not a plain \`gjsify build <entry> …\` command, so its entry point cannot be read`:`this package declares no \`${t}\` script`;return Error(`gjsify dev: nothing to build — ${S}.\n Name the entry point directly: gjsify dev src/index.ts\n or point at another script: gjsify dev --script <name>`)}function planDev(t){let n=t.scripts[t.scriptName],S=typeof n==`string`?gjsifyCommandArgv(n):null,C=S&&S[0]===`build`?S:null,N=t.entry??(C?buildEntryPoint(C):void 0);if(N===void 0)throw noEntryError(t.scriptName,typeof n==`string`);let F;return C?(F=[...C],buildEntryPoint(C)===void 0?F.splice(1,0,N):F[1]=N):F=[`build`,N],F=withFlag(F,`app`,t.app),t.globals!==void 0&&(F=withFlag(F,`globals`,t.globals)),t.outfile!==void 0&&(F=withFlag(F,`outfile`,t.outfile)),{buildArgv:F,bundle:readFlag(F,`outfile`)??t.declaredBundle,watchDir:t.watchDir??En(N)}}function noBundleError(t,n){return Error(`gjsify dev: nothing to launch — neither \`${t}\` nor --outfile names an output file, and this package declares no ${n===`gjs`?"`gjsify.main`":"`gjsify.example.node`"}.\n Pass one: gjsify dev --outfile dist/index.${n}.mjs\n or rebuild without launching: gjsify dev --build-only`)}var qG=__esmMin(()=>{Pn(),bI()});function readPackage$3(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}var JG,YG=__esmMin(()=>{_e(),Rd(),Pn(),qG(),W_(),d_(),__name$1(readPackage$3,`readPackage`),JG={command:`dev [entry]`,description:`Watch this project, rebuild on change and relaunch the app.`,builder:t=>t.positional(`entry`,{description:"Entry point to build (default: the one the build script names, e.g. src/index.ts from `build:gjs`).",type:`string`}).option(`runtime`,{description:"Runtime to build for and launch on: gjs | node | bun | deno (default: the host runtime). node/bun/deno build the same `--app node` bundle.",type:`string`,choices:H_,defaultDescription:`host runtime (gjs on gjs, else node/bun/deno)`}).option(`script`,{description:`package.json script the build flags are read from (default: build:gjs, or build:node for node/bun/deno).`,type:`string`}).option(`globals`,{description:"Override the build script `--globals` value.",type:`string`}).option(`outfile`,{description:"Override the build script `--outfile` path.",type:`string`}).option(`watch-dir`,{description:`Directory watched recursively (default: the directory of the entry point).`,type:`string`}).option(`debounce`,{description:`Quiet window in ms after a change before rebuilding.`,type:`number`,default:200}).option(`build-only`,{description:`Rebuild on every change but never launch the app.`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=readPackage$3(n),C=t.runtime??hostRuntime$1(),N=buildAppForRuntime(C),F=t.script??(N===`gjs`?`build:gjs`:`build:node`),I;try{I=planDev({scripts:S.scripts??{},scriptName:F,app:N,declaredBundle:N===`gjs`?S.gjsify?.main:S.gjsify?.example?.node,entry:t.entry,globals:t.globals,outfile:t.outfile,watchDir:t.watchDir})}catch(t){return ge.error(t.message),process.exit(1)}let H=I.bundle===void 0?void 0:xn(n,I.bundle);if(H===void 0&&!t.buildOnly)return ge.error(noBundleError(F,N).message),process.exit(1);let W=xn(n,I.watchDir);if(!existsSync(W))return ge.error(`gjsify dev: nothing to watch — ${Tn(n,W)||W} does not exist.\n Point the loop at your sources: gjsify dev --watch-dir <dir>`),process.exit(1);let q=H===void 0?`\`${F}\` output`:Tn(n,H);ge.log(`Watching ${Tn(n,W)||`.`} → ${q} (runtime: ${C})`);let{runCli:Y}=await Promise.resolve().then(()=>(UK(),HK)),{runWatchLoop:X,spawnBundleSupervised:Z}=await Promise.resolve().then(()=>(HG(),VG));await X({dir:W,dirLabel:Tn(n,W)||`.`,label:`dev`,build:()=>Y(I.buildArgv),spawnChild:t.buildOnly||H===void 0?null:()=>Z(C,H,n,`this project`),output:H,debounceMs:t.debounce})}}});function readPackage$2(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}function deriveStorybookAppId(t){return t?`org.gjsify.storybook.${t.replace(/^@/,``).replace(/[^a-zA-Z0-9]+/g,`.`).replace(/^\.+|\.+$/g,``)}`:`org.gjsify.Storybook`}function deriveBrowserAppId$1(t){return t?`org.gjsify.browser.${t.replace(/^@/,``).replace(/[^a-zA-Z0-9]+/g,`.`).replace(/^\.+|\.+$/g,``)}`:`org.gjsify.Browser`}function hasDep(t,n){return!!(t.dependencies?.[n]||t.devDependencies?.[n])}function generateEntry$2(t,n,S,C,N){let F=JSON.stringify(n),I=N?`, { address: ${JSON.stringify(N)} }`:``;return t===`storybook`?`// Auto-generated by \`gjsify debug\` — do not edit by hand.
1777
1777
  import { runDevtoolsMcp, storybookProfile } from '@gjsify/devtools-mcp';
1778
1778
 
1779
1779
  await runDevtoolsMcp(storybookProfile(${F}${I}));
@@ -1793,18 +1793,18 @@ await runDevtoolsMcp({
1793
1793
  version: ${JSON.stringify(C)},
1794
1794
  busNameBase: ${F},${N?`\n address: ${JSON.stringify(N)},`:``}
1795
1795
  });
1796
- `}var UG,WG=__esmMin(()=>{_e(),Rd(),Pn(),__name$1(readPackage$2,`readPackage`),__name$1(deriveBrowserAppId$1,`deriveBrowserAppId`),__name$1(generateEntry$2,`generateEntry`),UG={command:`debug`,description:`Launch an MCP bridge for a devtools-enabled gjsify app (org.gjsify.Devtools).`,builder:t=>t.option(`bus-name`,{description:`App DBus base name (default: gjsify.devtools.busNameBase, or the storybook app-id)`,type:`string`}).option(`address`,{description:`Peer D-Bus address of the app (unix:path=… / nonce-tcp:…) instead of the session bus — for macOS/Windows, which have no session bus. Default: GJSIFY_DEVTOOLS_ADDRESS, then the address file the app publishes, then the session bus`,type:`string`}).option(`profile`,{description:`Tool profile: generic | storybook | browser | cdp (default: auto — storybook if @gjsify/storybook is a dep, browser if @gjsify/devtools-browser is, cdp if @gjsify/devtools-cdp is, else generic)`,type:`string`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto)",type:`string`}).option(`out`,{description:`Output bundle path (default: node_modules/.cache/gjsify-debug)`,type:`string`}).option(`build-only`,{description:`Build the bridge bundle but do not launch it (for a .mcp.json command pointing at the bundle)`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=readPackage$2(n),C=S.gjsify?.devtools??{},N=t.profile??C.profile??(hasDep(S,`@gjsify/storybook`)?`storybook`:hasDep(S,`@gjsify/devtools-browser`)?`browser`:hasDep(S,`@gjsify/devtools-cdp`)?`cdp`:`generic`),F=t.busName??C.busNameBase??(N===`storybook`?S.gjsify?.storybook?.applicationId??deriveStorybookAppId(S.name):N===`browser`||N===`cdp`?S.gjsify?.browse?.applicationId??deriveBrowserAppId$1(S.name):void 0);if(!F)return ge.error(`gjsify debug: no bus name — set package.json#gjsify.devtools.busNameBase or pass --bus-name <org.example.App>`),process.exit(1);let I=t.globals??C.globals??`auto`,H=S.name?`${S.name}-devtools`:`gjsify-devtools`,W=wn(n,`node_modules`,`.cache`,`gjsify-debug`);mkdirSync(W,{recursive:!0});let q=wn(W,`entry.ts`),Y=t.out?xn(n,t.out):wn(W,`bridge.gjs.mjs`),X=t.address??C.address;writeFileSync(q,generateEntry$2(N,F,H,`0.8.0`,X)),ge.error(`[gjsify debug] profile=${N} bus=${F}${X?` address=${X}`:``}`);let{runCli:Z}=await Promise.resolve().then(()=>(IK(),FK));if(await Z([`build`,q,`--app`,`gjs`,`--shebang`,`--globals`,I,`--outfile`,Y]),t.buildOnly){ge.error(`[gjsify debug] built ${Y}`);return}let{runGjsBundle:te}=await Promise.resolve().then(()=>(XI(),YI));await te(Y,[],{completion:`exit`,exitOnSuccess:!0})}}});function readPackage$1(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}function generateEntry$1(){return`// Auto-generated by \`gjsify devtools\` — do not edit by hand.
1796
+ `}var XG,ZG=__esmMin(()=>{_e(),Rd(),Pn(),__name$1(readPackage$2,`readPackage`),__name$1(deriveBrowserAppId$1,`deriveBrowserAppId`),__name$1(generateEntry$2,`generateEntry`),XG={command:`debug`,description:`Launch an MCP bridge for a devtools-enabled gjsify app (org.gjsify.Devtools).`,builder:t=>t.option(`bus-name`,{description:`App DBus base name (default: gjsify.devtools.busNameBase, or the storybook app-id)`,type:`string`}).option(`address`,{description:`Peer D-Bus address of the app (unix:path=… / nonce-tcp:…) instead of the session bus — for macOS/Windows, which have no session bus. Default: GJSIFY_DEVTOOLS_ADDRESS, then the address file the app publishes, then the session bus`,type:`string`}).option(`profile`,{description:`Tool profile: generic | storybook | browser | cdp (default: auto — storybook if @gjsify/storybook is a dep, browser if @gjsify/devtools-browser is, cdp if @gjsify/devtools-cdp is, else generic)`,type:`string`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto)",type:`string`}).option(`out`,{description:`Output bundle path (default: node_modules/.cache/gjsify-debug)`,type:`string`}).option(`build-only`,{description:`Build the bridge bundle but do not launch it (for a .mcp.json command pointing at the bundle)`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=readPackage$2(n),C=S.gjsify?.devtools??{},N=t.profile??C.profile??(hasDep(S,`@gjsify/storybook`)?`storybook`:hasDep(S,`@gjsify/devtools-browser`)?`browser`:hasDep(S,`@gjsify/devtools-cdp`)?`cdp`:`generic`),F=t.busName??C.busNameBase??(N===`storybook`?S.gjsify?.storybook?.applicationId??deriveStorybookAppId(S.name):N===`browser`||N===`cdp`?S.gjsify?.browse?.applicationId??deriveBrowserAppId$1(S.name):void 0);if(!F)return ge.error(`gjsify debug: no bus name — set package.json#gjsify.devtools.busNameBase or pass --bus-name <org.example.App>`),process.exit(1);let I=t.globals??C.globals??`auto`,H=S.name?`${S.name}-devtools`:`gjsify-devtools`,W=wn(n,`node_modules`,`.cache`,`gjsify-debug`);mkdirSync(W,{recursive:!0});let q=wn(W,`entry.ts`),Y=t.out?xn(n,t.out):wn(W,`bridge.gjs.mjs`),X=t.address??C.address;writeFileSync(q,generateEntry$2(N,F,H,`0.8.0`,X)),ge.error(`[gjsify debug] profile=${N} bus=${F}${X?` address=${X}`:``}`);let{runCli:Z}=await Promise.resolve().then(()=>(UK(),HK));if(await Z([`build`,q,`--app`,`gjs`,`--shebang`,`--globals`,I,`--outfile`,Y]),t.buildOnly){ge.error(`[gjsify debug] built ${Y}`);return}let{runGjsBundle:te}=await Promise.resolve().then(()=>(tL(),eL));await te(Y,[],{completion:`exit`,exitOnSuccess:!0})}}});function readPackage$1(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}function generateEntry$1(){return`// Auto-generated by \`gjsify devtools\` — do not edit by hand.
1797
1797
  import system from 'system';
1798
1798
 
1799
1799
  import { runDevtoolsCli } from '@gjsify/devtools-mcp';
1800
1800
 
1801
1801
  system.exit(await runDevtoolsCli(system.programArgs));
1802
- `}var GG,KG=__esmMin(()=>{_e(),Rd(),Pn(),__name$1(readPackage$1,`readPackage`),__name$1(generateEntry$1,`generateEntry`),GG={command:`devtools`,description:"Drive a running devtools-enabled app from a script: capture a screenshot to a file, find a widget, activate it, send a key. Peer of `gjsify debug`, which speaks MCP for an AI agent.",builder:t=>t.positional(`operation`,{description:`Control-plane operation: shot | find | activate | key | tree | property | …`,type:`string`,demandOption:!0}).positional(`operands`,{description:"Subcommand arguments — e.g. the output path for `shot`, the selector for `find`.",type:`string`,array:!0}).option(`bus-name`,{description:"App DBus base name — the app's Gtk application id (default: gjsify.devtools.busNameBase, then the storybook app-id). Unlike `gjsify debug` there is no derived fallback: the bus name IS the application id, and guessing it produces a name nothing answers to",type:`string`}).option(`address`,{description:`Peer D-Bus address of the app (unix:path=… / nonce-tcp:…) instead of the session bus — for macOS/Windows, which have no session bus. Default: GJSIFY_DEVTOOLS_ADDRESS, then the address file the app publishes, then the session bus`,type:`string`}).option(`instance`,{description:`App instance label for a multi-instance app (default: GJSIFY_DEVTOOLS_INSTANCE)`,type:`string`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto)",type:`string`}).option(`out`,{description:`Output bundle path (default: node_modules/.cache/gjsify-devtools)`,type:`string`}).option(`timeout`,{description:`Seconds to keep polling GetStatus for the control plane to answer (default: 30). 0 = do not wait`,type:`number`,default:30}),handler:async t=>{let n=process.cwd(),S=readPackage$1(n),C=S.gjsify?.devtools??{},N=t.busName??C.busNameBase??S.gjsify?.storybook?.applicationId??S.gjsify?.browse?.applicationId;if(!N)return ge.error(`gjsify devtools: no bus name — the bus name IS the app's Gtk application id, so it cannot be derived from the package name. Pass --bus-name <org.example.App> (the app prints it when it exports the control plane) or set package.json#gjsify.devtools.busNameBase.`),process.exit(1);let F=wn(n,`node_modules`,`.cache`,`gjsify-devtools`);mkdirSync(F,{recursive:!0});let I=wn(F,`entry.ts`),H=t.out?xn(n,t.out):wn(F,`cli.gjs.mjs`),W=t.globals??`auto`;writeFileSync(I,generateEntry$1()),ge.error(`[gjsify devtools] bus=${N}${t.address?` address=${t.address}`:``}${t.instance?` instance=${t.instance}`:``}`);let{runCli:q}=await Promise.resolve().then(()=>(IK(),FK));await q([`build`,I,`--app`,`gjs`,`--globals`,W,`--outfile`,H]);let Y=[t.operation,...t.operands??[],`--bus-name`,N];t.address&&Y.push(`--address`,t.address),t.instance&&Y.push(`--instance`,t.instance),Y.push(`--timeout`,String(t.timeout));let{runGjsBundle:X}=await Promise.resolve().then(()=>(XI(),YI));await X(H,Y,{completion:`exit`,exitOnSuccess:!0})}}});function readPackage(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}function deriveBrowserAppId(t){return t?`org.gjsify.browser.${t.replace(/^@/,``).replace(/[^a-zA-Z0-9]+/g,`.`).replace(/^\.+|\.+$/g,``)}`:`org.gjsify.Browser`}function generateEntry(t,n,S,C,N){let F=S?`\n title: ${JSON.stringify(S)},`:``,I=n?`\n homeUrl: ${JSON.stringify(n)},`:``,H=C===void 0?``:`\n inspectorPort: ${C},`,W=N?`\n screenshot: ${JSON.stringify(N)},`:``;return`// Auto-generated by \`gjsify browse\` — do not edit by hand.
1802
+ `}var QG,$G=__esmMin(()=>{_e(),Rd(),Pn(),__name$1(readPackage$1,`readPackage`),__name$1(generateEntry$1,`generateEntry`),QG={command:`devtools`,description:"Drive a running devtools-enabled app from a script: capture a screenshot to a file, find a widget, activate it, send a key. Peer of `gjsify debug`, which speaks MCP for an AI agent.",builder:t=>t.positional(`operation`,{description:`Control-plane operation: shot | find | activate | key | tree | property | …`,type:`string`,demandOption:!0}).positional(`operands`,{description:"Subcommand arguments — e.g. the output path for `shot`, the selector for `find`.",type:`string`,array:!0}).option(`bus-name`,{description:"App DBus base name — the app's Gtk application id (default: gjsify.devtools.busNameBase, then the storybook app-id). Unlike `gjsify debug` there is no derived fallback: the bus name IS the application id, and guessing it produces a name nothing answers to",type:`string`}).option(`address`,{description:`Peer D-Bus address of the app (unix:path=… / nonce-tcp:…) instead of the session bus — for macOS/Windows, which have no session bus. Default: GJSIFY_DEVTOOLS_ADDRESS, then the address file the app publishes, then the session bus`,type:`string`}).option(`instance`,{description:`App instance label for a multi-instance app (default: GJSIFY_DEVTOOLS_INSTANCE)`,type:`string`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto)",type:`string`}).option(`out`,{description:`Output bundle path (default: node_modules/.cache/gjsify-devtools)`,type:`string`}).option(`timeout`,{description:`Seconds to keep polling GetStatus for the control plane to answer (default: 30). 0 = do not wait`,type:`number`,default:30}),handler:async t=>{let n=process.cwd(),S=readPackage$1(n),C=S.gjsify?.devtools??{},N=t.busName??C.busNameBase??S.gjsify?.storybook?.applicationId??S.gjsify?.browse?.applicationId;if(!N)return ge.error(`gjsify devtools: no bus name — the bus name IS the app's Gtk application id, so it cannot be derived from the package name. Pass --bus-name <org.example.App> (the app prints it when it exports the control plane) or set package.json#gjsify.devtools.busNameBase.`),process.exit(1);let F=wn(n,`node_modules`,`.cache`,`gjsify-devtools`);mkdirSync(F,{recursive:!0});let I=wn(F,`entry.ts`),H=t.out?xn(n,t.out):wn(F,`cli.gjs.mjs`),W=t.globals??`auto`;writeFileSync(I,generateEntry$1()),ge.error(`[gjsify devtools] bus=${N}${t.address?` address=${t.address}`:``}${t.instance?` instance=${t.instance}`:``}`);let{runCli:q}=await Promise.resolve().then(()=>(UK(),HK));await q([`build`,I,`--app`,`gjs`,`--globals`,W,`--outfile`,H]);let Y=[t.operation,...t.operands??[],`--bus-name`,N];t.address&&Y.push(`--address`,t.address),t.instance&&Y.push(`--instance`,t.instance),Y.push(`--timeout`,String(t.timeout));let{runGjsBundle:X}=await Promise.resolve().then(()=>(tL(),eL));await X(H,Y,{completion:`exit`,exitOnSuccess:!0})}}});function readPackage(t){try{return JSON.parse(readFileSync(wn(t,`package.json`),`utf8`))}catch{return{}}}function deriveBrowserAppId(t){return t?`org.gjsify.browser.${t.replace(/^@/,``).replace(/[^a-zA-Z0-9]+/g,`.`).replace(/^\.+|\.+$/g,``)}`:`org.gjsify.Browser`}function generateEntry(t,n,S,C,N){let F=S?`\n title: ${JSON.stringify(S)},`:``,I=n?`\n homeUrl: ${JSON.stringify(n)},`:``,H=C===void 0?``:`\n inspectorPort: ${C},`,W=N?`\n screenshot: ${JSON.stringify(N)},`:``;return`// Auto-generated by \`gjsify browse\` — do not edit by hand.
1803
1803
  import { runBrowserDevtools } from '@gjsify/devtools-browser';
1804
1804
 
1805
1805
  await runBrowserDevtools({
1806
1806
  applicationId: ${JSON.stringify(t)},${F}${I}${H}${W}
1807
1807
  });
1808
- `}var qG,JG=__esmMin(()=>{_e(),Rd(),Pn(),qG={command:`browse [url]`,description:`Launch the Adwaita web browser, optionally pointed at a URL.`,builder:t=>t.positional(`url`,{description:`Initial URL to load (default: page:welcome)`,type:`string`}).option(`app-id`,{description:`GApplication id (default: gjsify.browse.applicationId or derived from the package name)`,type:`string`}).option(`title`,{description:`Window title`,type:`string`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto,dom — WebKit/iframe need DOM globals)",type:`string`}).option(`out`,{description:`Output bundle path (default: node_modules/.cache/gjsify-browse)`,type:`string`}).option(`devtools`,{description:`Enable the MCP devtools control plane (sets GJSIFY_DEVTOOLS=1)`,type:`boolean`,default:!1}).option(`inspector-port`,{description:`Enable WebKit's remote inspector protocol on this port + the Cdp* methods (implies --devtools)`,type:`number`}).option(`screenshot`,{description:`One-shot: load the URL, capture a WebKit screenshot to this path, and exit (CI / quick captures).`,type:`string`}).option(`build-only`,{description:`Build the bundle but do not launch it`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=readPackage(n),C=S.gjsify?.browse??{},N=t.appId??C.applicationId??deriveBrowserAppId(S.name),F=t.title??C.title,I=t.globals??C.globals??`auto,dom`,H=t.url,W=t.inspectorPort??C.inspectorPort,q=t.devtools||W!==void 0,Y=wn(n,`node_modules`,`.cache`,`gjsify-browse`);mkdirSync(Y,{recursive:!0});let X=wn(Y,`entry.ts`),Z=t.out?xn(n,t.out):wn(Y,`browse.gjs.mjs`);writeFileSync(X,generateEntry(N,H,F,W,t.screenshot?xn(n,t.screenshot):void 0)),ge.log(`[gjsify browse] app=${N}${H?` url=${H}`:``}${q?` devtools=1`:``}${W===void 0?``:` inspector-port=${W}`}`);let{runCli:te}=await Promise.resolve().then(()=>(IK(),FK));if(await te([`build`,X,`--app`,`gjs`,`--globals`,I,`--outfile`,Z]),t.buildOnly){ge.log(`[gjsify browse] built ${Z}`);return}q&&(process.env.GJSIFY_DEVTOOLS=`1`),W!==void 0&&(process.env.WEBKIT_INSPECTOR_HTTP_SERVER=`127.0.0.1:${W}`);let{runGjsBundle:ne}=await Promise.resolve().then(()=>(XI(),YI));await ne(Z,[],{completion:`exit`,exitOnSuccess:!0})}}});function webextIconPaths(t,n,S){let C=t.sources.get(n);if(C===void 0)throw Error(`gjsify webext: the manifest asks for icon "${n}", and \`gjsify.webext.icons.sources\` declares ${[...t.sources.keys()].map(t=>`"${t}"`).join(`, `)||`none`}.`);let N=t.svgTargets.has(S.id),F={};for(let S of t.sizes)F[String(S)]=N?`icons/${Dn(C.get(S))}`:`icons/${n}-${S}.png`;return F}function svgIconFiles(t){let n=new Map;for(let[S,C]of t.sources)for(let t of C.values()){let C=`icons/${Dn(t)}`,N=n.get(C);if(N!==void 0&&N!==t)throw Error(`gjsify webext: icon "${S}" uses ${t}, and ${N} has the same file name; an SVG target would receive only one of them as `+C+`. Rename one.`);n.set(C,t)}return n}async function renderWebextIcons(t,n,S=rasterizeSvg){let C=n.some(n=>!t.svgTargets.has(n.id)),N=n.some(n=>t.svgTargets.has(n.id)),F=new Map;if(C){let n=new Map;for(let[S,C]of t.sources)for(let[t,N]of C)n.set(N,[...n.get(N)??[],{size:t,name:S}]);for(let[t,C]of n){let n=await S({svg:t,sizes:[...new Set(C.map(t=>t.size))],command:`gjsify webext`});for(let{size:t,name:S}of C)F.set(`icons/${S}-${t}.png`,n.get(t))}}return{png:F,svg:N?svgIconFiles(t):new Map}}function writeWebextIcons(t,n,S,C){if(mkdirSync(wn(C,`icons`),{recursive:!0}),n.svgTargets.has(S.id))for(let[n,S]of t.svg)copyFileSync(S,wn(C,n));else for(let[n,S]of t.png)writeFileSync(wn(C,n),S)}var YG=__esmMin(()=>{Rd(),Pn(),kB()});function isRecord$1(t){return typeof t==`object`&&!!t&&!Array.isArray(t)}function mergeManifest(t,n){let S={...t};for(let[t,C]of Object.entries(n))C===null?delete S[t]:isRecord$1(C)&&isRecord$1(S[t])?S[t]=mergeManifest(S[t],C):S[t]=C;return S}function applyTargetOverrides(t,n){let{$targets:S,...C}=t;if(S===void 0)return C;if(!isRecord$1(S))throw Error("gjsify webext: the manifest's `$targets` must be an object.");let N=S[n];if(N===void 0)return C;if(!isRecord$1(N))throw Error(`gjsify webext: \`$targets["${n}"]\` in the manifest must be an object.`);return mergeManifest(C,N)}async function composeManifest(t,n){let S=typeof t==`function`?await t(n):applyTargetOverrides(t,n.target);if(!isRecord$1(S))throw Error(`gjsify webext: the manifest for ${n.target} is not an object (got ${typeof S}).`);if(S.version!==void 0)return S;let C={};for(let[t,N]of Object.entries(S))C[t]=N,t===`name`&&(C.version=n.version);return C.version===void 0&&(C.version=n.version),C}async function loadManifestTemplate(t){if(/\.json$/i.test(t))try{return JSON.parse(readFileSync(t,`utf8`))}catch(n){throw Error(`gjsify webext: ${t} is not valid JSON: ${n.message}`)}let n,cleanup=null;if(isGjs()){let{BuildAction:S}=await Promise.resolve().then(()=>(SI(),yI)),C=await S.bundleFileForGjsCached(t,{cacheSubdir:`webext`,label:Dn(t),cache:!1,define:{"import.meta.url":JSON.stringify(pathToFileURL(t).href)}}),N=wn(En(C),`manifest-${process.pid}-${++XG}.mjs`);copyFileSync(C,N),n=pathToFileURL(N).href,cleanup=()=>rmSync(N,{force:!0})}else n=`${pathToFileURL(t).href}?t=${statSync(t).mtimeMs}-${++XG}`;try{let S=(await import(n)).default;if(typeof S!=`function`&&!isRecord$1(S))throw Error(`gjsify webext: ${t} has no default export. Export the manifest object, or a function \`(ctx) => manifest\` that receives the target.`);return S}finally{cleanup?.()}}function addPath(t,n){typeof n!=`string`||n===``||/^[a-z][a-z0-9+.-]*:/i.test(n)||n.includes(`*`)||t.add(n.replace(/^\//,``).replace(/[?#].*$/,``))}function addIconValue(t,n){if(typeof n==`string`)addPath(t,n);else if(isRecord$1(n))for(let S of Object.values(n))addPath(t,S)}function manifestFileReferences(t){let n=new Set,S=t.background;if(isRecord$1(S)&&(addPath(n,S.service_worker),addPath(n,S.page),Array.isArray(S.scripts)))for(let t of S.scripts)addPath(n,t);if(Array.isArray(t.content_scripts)){for(let S of t.content_scripts)if(isRecord$1(S)){for(let t of[`js`,`css`])if(Array.isArray(S[t]))for(let C of S[t])addPath(n,C)}}for(let S of[`action`,`browser_action`,`page_action`,`sidebar_action`]){let C=t[S];isRecord$1(C)&&(addPath(n,C.default_popup),addPath(n,C.default_panel),addIconValue(n,C.default_icon))}if(isRecord$1(t.options_ui)&&addPath(n,t.options_ui.page),addPath(n,t.options_page),addPath(n,t.devtools_page),isRecord$1(t.side_panel)&&addPath(n,t.side_panel.default_path),addIconValue(n,t.icons),isRecord$1(t.chrome_url_overrides))for(let S of Object.values(t.chrome_url_overrides))addPath(n,S);if(Array.isArray(t.web_accessible_resources)){for(let S of t.web_accessible_resources)if(typeof S==`string`)addPath(n,S);else if(isRecord$1(S)&&Array.isArray(S.resources))for(let t of S.resources)addPath(n,t)}return[...n].sort()}function checkManifest(t,n,S){let C=[];t.manifest_version!==n.manifestVersion&&C.push(`manifest_version is ${JSON.stringify(t.manifest_version)}, and target ${n.id} is Manifest V${n.manifestVersion}. gjsify does not convert keys between versions — branch on \`ctx.manifestVersion\` in the manifest.`);for(let N of manifestFileReferences(t))existsSync(wn(S,N))||C.push(`the manifest names "${N}", which the build did not write into ${n.id}/.`);let N=existsSync(wn(S,`_locales`)),F=t.default_locale;return N&&typeof F!=`string`?C.push(`_locales/ exists but the manifest sets no default_locale; the browser refuses to load it.`):!N&&F!==void 0?C.push(`the manifest sets default_locale "${String(F)}" but there is no _locales/ directory.`):typeof F==`string`&&!existsSync(wn(S,`_locales`,F,`messages.json`))&&C.push(`default_locale is "${F}" but _locales/${F}/messages.json does not exist.`),C}var XG,ZG=__esmMin(()=>{Rd(),Pn(),Gn(),d_(),__name$1(isRecord$1,`isRecord`),XG=0});function planPage(t,n,S){let C=En(n),N=[],F=[],local=t=>{if(iK.test(t)||t.startsWith(`/`))return null;let n=t.replace(/[?#].*$/,``);return Cn(n)?n:xn(C,n)},I=S.replace(QG,n=>{let S=eK.exec(n);if(!S)return n;let C=local(S[2]);if(C===null||!aK.test(C))return n;let F=N.length===0?`${t}.js`:`${t}-${N.length+1}.js`;return N.push({entry:C,format:nK.test(n)?`esm`:`iife`,output:F}),n.replace(eK,(t,n)=>`src=${n}${F}${n}`)});return I=I.replace($G,t=>{if(!rK.test(t))return t;let n=tK.exec(t);if(!n)return t;let S=local(n[2]);if(S===null)return t;let C=Dn(S);return F.push({source:S,output:C}),t.replace(tK,(t,n)=>`href=${n}${C}${n}`)}),{html:I,scripts:N,stylesheets:F}}var QG,$G,eK,tK,nK,rK,iK,aK,oK=__esmMin(()=>{Pn(),QG=/<script\b[^>]*\bsrc\s*=\s*["'][^"']+["'][^>]*>/gi,$G=/<link\b[^>]*>/gi,eK=/\bsrc\s*=\s*(["'])([^"']+)\1/i,tK=/\bhref\s*=\s*(["'])([^"']+)\1/i,nK=/\btype\s*=\s*["']module["']/i,rK=/\brel\s*=\s*["'][^"']*\bstylesheet\b[^"']*["']/i,iK=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,aK=/\.(?:[cm]?[jt]sx?)$/i});function zipTimestamp(t=process.env){let n=Number(t.SOURCE_DATE_EPOCH);return Number.isFinite(n)&&n>=sK?n:sK}function zipEntriesOf(t){let n=[],walk=S=>{for(let C of readdirSync(S,{withFileTypes:!0})){let N=wn(S,C.name);C.isDirectory()?walk(N):n.push({path:Tn(t,N).split(/[\\/]/).join(`/`),mode:420,data:readFileSync(N)})}};return walk(t),n}async function buildWebext(t){let{config:n,targets:S,outDir:C,define:N}=t,F=t.log??(t=>ge.log(t)),I=t.mode===`production`&&n.minify,H=wn(C,`.stage`);rmSync(H,{recursive:!0,force:!0}),mkdirSync(H,{recursive:!0});try{for(let[S,C]of n.scripts)await t.bundle({entry:C,outfile:wn(H,`${S}.js`),format:`iife`,define:N,minify:I});let W=new Map;for(let[S,C]of n.pages){let n=planPage(S,C,readFileSync(C,`utf8`));for(let S of n.scripts)await t.bundle({entry:S.entry,outfile:wn(H,S.output),format:S.format,define:N,minify:I});for(let t of n.stylesheets){let n=W.get(t.output);if(n!==void 0&&n!==t.source)throw Error(`gjsify webext: pages link ${n} and ${t.source}, which would both be written as ${t.output}. Rename one.`);W.set(t.output,t.source),cpSync(t.source,wn(H,t.output))}writeFileSync(wn(H,`${S}.html`),n.html)}let q=n.icons,Y=q?await renderWebextIcons(q,S,t.rasterize):null,X=await loadManifestTemplate(n.manifest),Z={folders:new Map,zips:new Map};for(let I of S){let S=wn(C,I.id);t.inPlace||rmSync(S,{recursive:!0,force:!0}),mkdirSync(S,{recursive:!0}),n.publicDir&&cpSync(n.publicDir,S,{recursive:!0}),n.localesDir&&cpSync(n.localesDir,wn(S,`_locales`),{recursive:!0}),cpSync(H,S,{recursive:!0}),q&&Y&&writeWebextIcons(Y,q,I,S);let W=await composeManifest(X,{target:I.id,browser:I.browser,manifestVersion:I.manifestVersion,mode:t.mode,version:n.version,define:N,icons:t=>{if(!q)throw Error(`gjsify webext: the manifest asks for icon "${t}" and \`gjsify.webext.icons\` is not declared.`);return webextIconPaths(q,t,I)}});writeFileSync(wn(S,`manifest.json`),`${JSON.stringify(W,null,2)}\n`);let te=checkManifest(W,I,S);if(te.length>0)throw Error(`gjsify webext: ${I.id} would not load:\n - ${te.join(`
1809
- - `)}`);if(Z.folders.set(I.id,S),F(`built ${Tn(process.cwd(),S)||S}`),t.zip){let t=wn(C,`${n.name}-${n.version}-${I.id}.zip`);writeFileSync(t,buildZip(zipEntriesOf(S),zipTimestamp())),Z.zips.set(I.id,t),F(`zipped ${Tn(process.cwd(),t)||t} (${Math.round(statSync(t).size/1024)} KiB)`)}}return Z}finally{rmSync(H,{recursive:!0,force:!0})}}var sK,cK=__esmMin(()=>{_e(),Rd(),Pn(),zH(),YG(),ZG(),oK(),sK=315532800});function parseWebextTarget(t){let n=/^([a-z]+)-mv([23])$/.exec(t),S=n?.[1];if(!n||S===void 0||!lK.includes(S))throw Error(`gjsify webext: unknown target "${t}". A target is <browser>-mv<2|3> with browser one of ${lK.join(`, `)} (e.g. chrome-mv3, firefox-mv2).`);let C=n[2]===`2`?2:3,N=C===2?dK.get(S):void 0;if(N!==void 0)throw Error(`gjsify webext: target "${t}" does not exist any more: ${N}. Use ${S}-mv3.`);return{id:t,browser:S,manifestVersion:C}}function webExtRunTarget(t){return t.browser===`firefox`?`firefox-desktop`:t.browser===`chrome`||t.browser===`edge`||t.browser===`opera`?`chromium`:null}var lK,uK,dK,fK=__esmMin(()=>{lK=[`chrome`,`edge`,`firefox`,`opera`,`safari`],uK=[`chrome-mv3`,`firefox-mv3`],dK=new Map([[`chrome`,`chrome has removed Manifest V2`],[`edge`,`edge has removed Manifest V2`],[`opera`,`opera's extension store accepts Manifest V3 only`]])});function isRecord(t){return typeof t==`object`&&!!t&&!Array.isArray(t)}function defaultArtifactName(t){let n=(t??`extension`).replace(/^@[^/]+\//,``);return n===``?`extension`:n}function iconSourceForSize(t,n){if(typeof t==`string`)return t;let S=Object.keys(t).filter(t=>/^\d+$/.test(t)).map(Number).sort((t,n)=>t-n).find(t=>n<=t);return S===void 0?t.default:t[String(S)]}function resolveWebextConfig(t,n,S=defaultExists){let C=[],N=t.gjsify?.webext;if(N===void 0)throw Error("gjsify webext: this package declares no `gjsify.webext` block in package.json. Add one naming at least the manifest and one script or page — see `gjsify webext build --help`.");if(!isRecord(N))throw Error("gjsify webext: `gjsify.webext` must be an object.");let F=N,abs=t=>Cn(t)?t:xn(n,t),need=(t,n,N)=>{let F=abs(n);return S(F,N)||C.push(`${t} "${n}" is not a ${N===`dir`?`directory`:`file`}.`),F},I=[],H=F.targets??[...uK];if(!Array.isArray(H)||H.length===0)C.push("`targets` must be a non-empty array of target names.");else for(let t of H)try{I.some(n=>n.id===t)?C.push(`target "${t}" is listed twice.`):I.push(parseWebextTarget(String(t)))}catch(t){C.push(t.message.replace(/^gjsify webext: /,``))}let W=``;if(F.manifest!==void 0)W=need("`manifest`",F.manifest,`file`);else{let t=mK.find(t=>S(wn(n,t),`file`));t===void 0?C.push(`no \`manifest\` declared and none of ${mK.join(`, `)} exists.`):W=wn(n,t)}let q=new Map,claim=(t,n)=>{let S=q.get(t);S===void 0?q.set(t,n):C.push(`${n} and ${S} both write ${t}.`)},readEntries=t=>{let n=new Map,S=F[t];if(S===void 0)return n;if(!isRecord(S))return C.push(`\`${t}\` must map an output name to a source file.`),n;for(let[N,F]of Object.entries(S)){if(!hK.test(N)){C.push(`\`${t}.${N}\`: an output name is a plain file name (letters, digits, . _ -).`);continue}if(typeof F!=`string`){C.push(`\`${t}.${N}\` must be a path.`);continue}n.set(N,need(`\`${t}.${N}\``,F,`file`)),t===`scripts`?claim(`${N}.js`,`\`scripts.${N}\``):claim(`${N}.html`,`\`pages.${N}\``)}return n},Y=readEntries(`scripts`),X=readEntries(`pages`);Y.size===0&&X.size===0&&C.push("declare at least one entry under `scripts` or `pages`; there is nothing to build.");for(let t of X.keys())Y.has(t)&&C.push(`\`scripts.${t}\` and the script of \`pages.${t}\` both write ${t}.js.`);let Z=null;if(F.icons!==void 0)if(!isRecord(F.icons)||!isRecord(F.icons.sources))C.push("`icons` must be an object with a `sources` map (icon name → SVG).");else{let t=F.icons.sizes??pK;(!Array.isArray(t)||t.length===0||t.some(t=>!Number.isInteger(t)||t<=0))&&C.push("`icons.sizes` must be a non-empty list of positive integers.");let n=new Set(F.icons.svg??[]);for(let t of n)I.some(n=>n.id===t)||C.push(`\`icons.svg\` names "${t}", which is not one of this package's targets.`);let N=new Map;for(let[n,I]of Object.entries(F.icons.sources)){if(!hK.test(n)){C.push(`\`icons.sources.${n}\`: an icon name is a plain file name.`);continue}if(typeof I!=`string`&&!isRecord(I)){C.push(`\`icons.sources.${n}\` must be an SVG path or a map of size ceilings to SVGs.`);continue}let F=new Map;for(let S of t){let t=iconSourceForSize(I,S);if(t===void 0){C.push(`\`icons.sources.${n}\` has no SVG for ${S} px — add a "default".`);continue}/\.svg$/i.test(t)||C.push(`\`icons.sources.${n}\`: "${t}" is not an .svg file.`),F.set(S,abs(t))}for(let t of new Set(F.values()))S(t,`file`)||C.push(`\`icons.sources.${n}\`: "${t}" does not exist.`);N.set(n,F)}Z={sizes:t,sources:N,svgTargets:n}}let optionalDir=(t,C)=>{let N=F[t];if(N!==void 0)return need(`\`${t}\``,N,`dir`);let I=wn(n,C);return S(I,`dir`)?I:null},te=optionalDir(`public`,`public`),ne=optionalDir(`locales`,`_locales`),re=F.define??{};(!isRecord(re)||Object.values(re).some(t=>typeof t!=`string`))&&C.push("`define` must map identifiers to JS expressions given as strings.");let ie=F.watch??[];if((!Array.isArray(ie)||ie.some(t=>typeof t!=`string`))&&C.push("`watch` must be a list of directories."),C.length>0)throw Error(`gjsify webext: \`gjsify.webext\` in ${wn(n,`package.json`)}:\n - ${C.join(`
1810
- - `)}`);return{root:n,name:F.name??defaultArtifactName(t.name),version:t.version??`0.0.0`,targets:I,manifest:W,scripts:Y,pages:X,icons:Z,publicDir:te,localesDir:ne,outDir:abs(F.outDir??`.output`),define:re,watch:ie.map(abs),minify:F.minify??!0}}function defaultExists(t,n){if(!existsSync(t))return!1;let S=statSync(t);return n===`dir`?S.isDirectory():S.isFile()}function selectTargets(t,n){return n===void 0||n.length===0?t.targets:n.map(n=>{let S=t.targets.find(t=>t.id===n);if(S)return S;throw parseWebextTarget(n),Error(`gjsify webext: target "${n}" is not in \`gjsify.webext.targets\` (${t.targets.map(t=>t.id).join(`, `)}).`)})}var pK,mK,hK,gK=__esmMin(()=>{Rd(),Pn(),fK(),pK=[16,32,48,128],mK=[`manifest.ts`,`manifest.mts`,`manifest.js`,`manifest.mjs`,`manifest.json`],hK=/^[A-Za-z0-9][A-Za-z0-9._-]*$/});function webExtRunArgs(t){let n=webExtRunTarget(t.target);if(n===null)throw Error(`gjsify webext dev: web-ext cannot launch ${t.target.browser}. Build with \`gjsify webext build --target ${t.target.id}\` and load the folder by hand, or pass \`--no-launch\`.`);let S=[`run`,`--source-dir`,t.sourceDir,`--target`,n,`--no-input`,`--profile-create-if-missing`];return n===`firefox-desktop`?(S.push(`--firefox-profile`,t.profile,`--keep-profile-changes`),t.browserBinary&&S.push(`--firefox`,t.browserBinary),t.headless&&S.push(`--arg=-headless`)):(S.push(`--chromium-profile`,t.profile),t.browserBinary&&S.push(`--chromium-binary`,t.browserBinary),t.headless&&S.push(`--arg=--headless=new`)),S}function defaultDevProfile(t,n,S=process.env){return wn(S.XDG_CACHE_HOME||wn(homedir(),`.cache`),`gjsify`,`webext`,t,n.id)}function resolveWebExt(t,n=process.platform,S=process.env){let C=n===`win32`?`web-ext.cmd`:`web-ext`;for(let n=t;;n=En(n)){let t=wn(n,`node_modules`,`.bin`);if(existsSync(wn(t,C)))return{cmd:`web-ext`,env:{...S,PATH:[t,S.PATH].filter(Boolean).join(Mn)}};if(En(n)===n)break}return isOnPath(`web-ext`)?{cmd:`web-ext`,env:S}:null}var _K,vK=__esmMin(()=>{Rd(),Lg(),Pn(),vF(),fK(),_K="gjsify webext dev: `web-ext` is not installed. Add it to the project (`gjsify install --save-dev web-ext`) or install it globally, or pass `--no-launch` to rebuild without a browser."});function loadConfig(t){let n=wn(t,`package.json`);if(!existsSync(n))throw Error(`gjsify webext: no package.json in ${t}.`);return resolveWebextConfig(JSON.parse(readFileSync(n,`utf8`)),t)}function effectiveDefines(t,n){let S={...t.define};for(let t of n){let n=t.indexOf(`=`);if(n<=0)throw Error(`gjsify webext: --define "${t}" is not KEY=VALUE.`);S[t.slice(0,n)]=t.slice(n+1)}return S}async function bundleInProcess(t){let{runCli:n}=await Promise.resolve().then(()=>(IK(),FK)),S=[`build`,t.entry,`--app`,`browser`,`--format`,t.format,`--outfile`,t.outfile];for(let[n,C]of Object.entries(t.define))S.push(`--define`,`${n}=${C}`);t.minify||S.push(`--no-minify`),await n(S)}async function runBuild(t,n){let S=process.cwd(),C=loadConfig(S),N=t.mode===`development`?`development`:`production`;await buildWebext({config:C,targets:selectTargets(C,t.target),outDir:t.outDir?xn(S,t.outDir):C.outDir,mode:N,define:effectiveDefines(C,t.define),inPlace:!1,zip:n,bundle:bundleInProcess})}function devTarget(t,n){if(n&&n.length>1)throw Error(`gjsify webext dev: pass one --target.`);let[S]=selectTargets(t,n);return n&&n.length===1?S:t.targets.find(t=>t.browser===`firefox`)??S}function devWatchTargets(t,n){let skip=t=>t===`node_modules`||t.startsWith(`.`),S=[{path:t.root,recursive:!1}];for(let C of readdirSync(t.root,{withFileTypes:!0})){let N=wn(t.root,C.name);!C.isDirectory()||skip(C.name)||N===n||n.startsWith(N+jn)||S.push({path:N,recursive:!0})}for(let n of t.watch)S.push({path:n,recursive:!0});return S}var yK,bK,xK,SK,CK,wK,TK=__esmMin(()=>{_e(),Rd(),Pn(),cK(),gK(),vK(),yK={description:`Build only these targets (default: every target in gjsify.webext.targets).`,type:`string`,array:!0},bK={description:`Output directory (default: gjsify.webext.outDir, else .output).`,type:`string`},xK={description:`Compile-time constant for every bundle, KEY=VALUE (repeatable); wins over gjsify.webext.define.`,type:`string`,array:!0,default:[]},SK={command:`build`,description:`Build one extension folder per target: bundles, pages, icons, locales and the manifest.`,builder:t=>t.option(`target`,yK).option(`out-dir`,bK).option(`define`,xK).option(`mode`,{description:`Passed to the manifest as ctx.mode; development also skips minification.`,type:`string`,choices:[`production`,`development`],default:`production`}),handler:t=>runBuild(t,!1)},CK={command:`zip`,description:`Production build, then one store-ready <name>-<version>-<target>.zip per target.`,builder:t=>t.option(`target`,yK).option(`out-dir`,bK).option(`define`,xK),handler:t=>runBuild(t,!0)},wK={command:`dev`,description:`Build one target in development mode, launch it in a browser via web-ext, and rebuild in place on change.`,builder:t=>t.option(`target`,{...yK,description:`The target to run (default: the first Firefox target).`}).option(`out-dir`,{description:`Output directory (default: <outDir>-dev).`,type:`string`}).option(`define`,xK).option(`launch`,{description:`Start a browser with the extension (--no-launch only rebuilds).`,type:`boolean`,default:!0}).option(`browser-binary`,{description:`Browser executable web-ext should start.`,type:`string`}).option(`profile`,{description:`Browser profile directory (default: $XDG_CACHE_HOME/gjsify/webext/<name>/<target>).`,type:`string`}).option(`headless`,{description:`Start the browser without a window.`,type:`boolean`,default:!1}).option(`debounce`,{description:`Quiet window in ms before a rebuild.`,type:`number`,default:200}),handler:async t=>{let n=process.cwd(),S=loadConfig(n),C=devTarget(S,t.target),N=t.outDir?xn(n,t.outDir):`${S.outDir}-dev`,F=effectiveDefines(S,t.define),I=wn(N,C.id),H=null;if(t.launch&&(H=resolveWebExt(n),H===null))throw Error(_K);let W=null,stopBrowser=()=>{W?.kill()};process.on(`SIGINT`,stopBrowser),process.on(`SIGTERM`,stopBrowser);let launch=async()=>{if(H===null||W!==null)return;let N=t.profile?xn(n,t.profile):defaultDevProfile(S.name,C);mkdirSync(En(N),{recursive:!0});let F=webExtRunArgs({sourceDir:I,target:C,profile:N,browserBinary:t.browserBinary,headless:t.headless});ge.log(`[webext] launching ${C.id} with profile ${N}`);let{spawnSupervised:q}=await Promise.resolve().then(()=>(FG(),PG));W=await q(H.cmd,F,H.env),W.on(`exit`,t=>{ge.log(`[webext] browser closed (${t??0}) — stopping`),process.exit(0)})},{runWatchLoop:q}=await Promise.resolve().then(()=>(FG(),PG));await q({dir:n,dirLabel:`.`,label:`webext`,watch:devWatchTargets(S,N),ignore:t=>t===N||t.startsWith(N+jn),build:async()=>{await buildWebext({config:S,targets:[C],outDir:N,mode:`development`,define:F,inPlace:!0,zip:!1,bundle:bundleInProcess}),await launch()},spawnChild:null,debounceMs:t.debounce})}}}),EK,DK=__esmMin(()=>{TK(),EK={command:`webext <subcommand>`,description:`Browser extensions: build, zip and develop one WebExtension for Chrome, Edge, Firefox, Opera and Safari.`,builder:t=>t.command(SK.command,SK.description,SK.builder,SK.handler).command(CK.command,CK.description,CK.builder,CK.handler).command(wK.command,wK.description,wK.builder,wK.handler).demandCommand(1).strict()}});function blueprintsUnder(t,n){let S;try{S=statSync(t)}catch{return n}if(!S.isDirectory())return t.endsWith(`.blp`)&&n.push(t),n;for(let S of readdirSync(t).sort())OK.has(S)||S.startsWith(`.`)||blueprintsUnder(wn(t,S),n);return n}var OK,kK,formatFor,AK,jK=__esmMin(()=>{_e(),Rd(),Pn(),Mk(),zk(),OK=new Set([`node_modules`,`dist`,`lib`,`.git`]),kK=new Map,formatFor=t=>{let n=kK.get(t);if(n!==void 0)return n;let S=emitFormatForTree(t);return kK.set(t,S),S},AK={command:`types [paths..]`,description:"Generate the `<name>.d.blp.ts` type sidecar for each .blp (ADR 0088), so `import { build }` / `import { GTypeName }` type-check before anything is built. Defaults to the current directory.",builder:t=>t.positional(`paths`,{description:`Files or directories to scan for .blp (default: the current directory)`,type:`string`,array:!0,normalize:!0,default:[]}).option(`check`,{description:`Write nothing; exit non-zero when a sidecar is missing or stale`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print every file considered, not only the ones that changed`,type:`boolean`,default:!1}),handler:async t=>{let n=t.paths??[],S=(n.length>0?n:[`.`]).map(t=>Cn(t)?t:xn(process.cwd(),t)),C=[];for(let t of S)blueprintsUnder(t,C);let N=[],F=0;for(let n of C){let S=sidecarPathFor(n),C=emitTypedSidecar(parseBlueprint(readFileSync(n,`utf8`),n),Dn(n),formatFor(En(n))),I;try{I=readFileSync(S,`utf8`)}catch{I=void 0}if(I===C){t.verbose&&ge.log(`[gjsify blueprint types] current: ${S}`);continue}if(t.check){N.push(S);continue}writeFileSync(S,C,`utf8`),F+=1,ge.log(`[gjsify blueprint types] wrote ${S}`)}if(t.check){if(N.length===0){ge.log(`[gjsify blueprint types] ${C.length} .blp checked, every sidecar current.`);return}for(let t of N)ge.error(`[gjsify blueprint types] missing or stale: ${t}`);ge.error(`[gjsify blueprint types] run without --check to regenerate.`),process.exitCode=1;return}ge.log(`[gjsify blueprint types] ${C.length} .blp scanned, ${F} sidecar(s) written, ${C.length-F} already current.`)}}}),MK,NK=__esmMin(()=>{jK(),MK={command:`blueprint <subcommand>`,description:`Blueprint (.blp) tooling: generate the TypeScript type sidecars a .blp exports (ADR 0088).`,builder:t=>t.command(AK.command,AK.description,AK.builder,AK.handler).demandCommand(1).strict()}}),PK=__esmMin(()=>{DI(),kI(),MI(),II(),eL(),rL(),fR(),mR(),gR(),ER(),zR(),rz(),oz(),uz(),pz(),sB(),hU(),FR(),xU(),wU(),kU(),wR(),PU(),dW(),pW(),gW(),vW(),wW(),AW(),RW(),VW(),UW(),GW(),eG(),nG(),iG(),dG(),gG(),vG(),NG(),LG(),zG(),HG(),WG(),KG(),JG(),DK(),NK()}),FK=__exportAll$5({runCli:()=>runCli});function runtimeLabel(){let t=gjsSystemVersion();if(t!==void 0){let n=Number(t);return`GJS ${Math.floor(n/1e4)}.${Math.floor(n%1e4/100)}.${n%100} (SpiderMonkey)`}return isBun()?`Bun ${globalThis.Bun?.version??process.versions.bun??``}`.trim():isDeno()?`Deno ${globalThis.Deno?.version?.deno??``}`.trim():isNode()?`Node.js ${process.version}`:`unknown runtime`}async function runCli(t){ensureGjsifyShimOnPath();let n=Hm(t);await n.scriptName(rh).version(cliVersion()).strict().fail((t,S)=>{let C=classifyCliFailure(t,S);if(C.kind===`usage`)throw n.showHelp(`error`),Error(C.message,{cause:S})}).wrap(n.terminalWidth()).command(nz.command,nz.description,nz.builder,nz.handler).command(yU.command,yU.description,yU.builder,yU.handler).command(SU.command,SU.description,SU.builder,SU.handler).command(CU.command,CU.description,CU.builder,CU.handler).command(EI.command,EI.description,EI.builder,EI.handler).command(OI.command,OI.description,OI.builder,OI.handler).command(jI.command,jI.description,jI.builder,jI.handler).command(FI.command,FI.description,FI.builder,FI.handler).command($I.command,$I.description,$I.builder,$I.handler).command(nL.command,nL.description,nL.builder,nL.handler).command(dR.command,dR.description,dR.builder,dR.handler).command(PR.command,PR.description,PR.builder,PR.handler).command(pR.command,pR.description,pR.builder,pR.handler).command(hR.command,hR.description,hR.builder,hR.handler).command(TR.command,TR.description,TR.builder,TR.handler).command(RR.command,RR.description,RR.builder,RR.handler).command(az.command,az.description,az.builder,az.handler).command(lz.command,lz.description,lz.builder,lz.handler).command(fz.command,fz.description,fz.builder,fz.handler).command(oB.command,oB.description,oB.builder,oB.handler).command(mU.command,mU.description,mU.builder,mU.handler).command(OU.command,OU.description,OU.builder,OU.handler).command(CR.command,CR.description,CR.builder,CR.handler).command(jU.command,jU.description,jU.builder,jU.handler).command(uW.command,uW.description,uW.builder,uW.handler).command(fW.command,fW.description,fW.builder,fW.handler).command(hW.command,hW.description,hW.builder,hW.handler).command(_W.command,_W.description,_W.builder,_W.handler).command(CW.command,CW.description,CW.builder,CW.handler).command(kW.command,kW.description,kW.builder,kW.handler).command(IW.command,IW.description,IW.builder,IW.handler).command(BW.command,BW.description,BW.builder,BW.handler).command(WW.command,WW.description,WW.builder,WW.handler).command(HW.command,HW.description,HW.builder,HW.handler).command(sG.command,sG.description,sG.builder,sG.handler).command($W.command,$W.description,$W.builder,$W.handler).command(tG.command,tG.description,tG.builder,tG.handler).command(rG.command,rG.description,rG.builder,rG.handler).command(hG.command,hG.description,hG.builder,hG.handler).command(_G.command,_G.description,_G.builder,_G.handler).command(jG.command,jG.description,jG.builder,jG.handler).command(IG.command,IG.description,IG.builder,IG.handler).command(RG.command,RG.description,RG.builder,RG.handler).command(VG.command,VG.description,VG.builder,VG.handler).command(UG.command,UG.description,UG.builder,UG.handler).command(GG.command,GG.description,GG.builder,GG.handler).command(qG.command,qG.description,qG.builder,qG.handler).command(EK.command,EK.description,EK.builder,EK.handler).command(MK.command,MK.description,MK.builder,MK.handler).demandCommand(1).epilogue(`Running on ${runtimeLabel()}`).help().parseAsync()}var IK=__esmMin(()=>{Um(),Wm(),nh(),PK(),ih(),d_(),cR()});IK(),d_(),uR();function pendingFailureCode(t,n){if(n||t==null)return null;let S=Number(t);return Number.isFinite(S)&&S!==0?S:null}function exitOnReportedFailure(){let t=pendingFailureCode(process.exitCode,isDaemonCommand());t!==null&&gjsExit(t)}_e(),d_();try{await runCli(hideBin(process.argv))}catch(t){let n=typeof t==`object`&&t&&typeof t.code==`string`?t.code:``,S=t instanceof Error?t.message:String(t);ge.error(n&&!S.includes(n)?`${n}: ${S}`:S),process.env.GJSIFY_DEBUG&&t instanceof Error&&t.stack&&ge.error(t.stack),process.exitCode=1,gjsExit(1)}exitOnReportedFailure();const LK=globalThis.process,RK=Number(LK?.exitCode);Number.isInteger(RK)&&RK!==0&&LK.exit(RK);
1808
+ `}var eK,tK=__esmMin(()=>{_e(),Rd(),Pn(),eK={command:`browse [url]`,description:`Launch the Adwaita web browser, optionally pointed at a URL.`,builder:t=>t.positional(`url`,{description:`Initial URL to load (default: page:welcome)`,type:`string`}).option(`app-id`,{description:`GApplication id (default: gjsify.browse.applicationId or derived from the package name)`,type:`string`}).option(`title`,{description:`Window title`,type:`string`}).option(`globals`,{description:"Value for `gjsify build --globals` (default: auto,dom — WebKit/iframe need DOM globals)",type:`string`}).option(`out`,{description:`Output bundle path (default: node_modules/.cache/gjsify-browse)`,type:`string`}).option(`devtools`,{description:`Enable the MCP devtools control plane (sets GJSIFY_DEVTOOLS=1)`,type:`boolean`,default:!1}).option(`inspector-port`,{description:`Enable WebKit's remote inspector protocol on this port + the Cdp* methods (implies --devtools)`,type:`number`}).option(`screenshot`,{description:`One-shot: load the URL, capture a WebKit screenshot to this path, and exit (CI / quick captures).`,type:`string`}).option(`build-only`,{description:`Build the bundle but do not launch it`,type:`boolean`,default:!1}),handler:async t=>{let n=process.cwd(),S=readPackage(n),C=S.gjsify?.browse??{},N=t.appId??C.applicationId??deriveBrowserAppId(S.name),F=t.title??C.title,I=t.globals??C.globals??`auto,dom`,H=t.url,W=t.inspectorPort??C.inspectorPort,q=t.devtools||W!==void 0,Y=wn(n,`node_modules`,`.cache`,`gjsify-browse`);mkdirSync(Y,{recursive:!0});let X=wn(Y,`entry.ts`),Z=t.out?xn(n,t.out):wn(Y,`browse.gjs.mjs`);writeFileSync(X,generateEntry(N,H,F,W,t.screenshot?xn(n,t.screenshot):void 0)),ge.log(`[gjsify browse] app=${N}${H?` url=${H}`:``}${q?` devtools=1`:``}${W===void 0?``:` inspector-port=${W}`}`);let{runCli:te}=await Promise.resolve().then(()=>(UK(),HK));if(await te([`build`,X,`--app`,`gjs`,`--globals`,I,`--outfile`,Z]),t.buildOnly){ge.log(`[gjsify browse] built ${Z}`);return}q&&(process.env.GJSIFY_DEVTOOLS=`1`),W!==void 0&&(process.env.WEBKIT_INSPECTOR_HTTP_SERVER=`127.0.0.1:${W}`);let{runGjsBundle:ne}=await Promise.resolve().then(()=>(tL(),eL));await ne(Z,[],{completion:`exit`,exitOnSuccess:!0})}}});function webextIconPaths(t,n,S){let C=t.sources.get(n);if(C===void 0)throw Error(`gjsify webext: the manifest asks for icon "${n}", and \`gjsify.webext.icons.sources\` declares ${[...t.sources.keys()].map(t=>`"${t}"`).join(`, `)||`none`}.`);let N=t.svgTargets.has(S.id),F={};for(let S of t.sizes)F[String(S)]=N?`icons/${Dn(C.get(S))}`:`icons/${n}-${S}.png`;return F}function svgIconFiles(t){let n=new Map;for(let[S,C]of t.sources)for(let t of C.values()){let C=`icons/${Dn(t)}`,N=n.get(C);if(N!==void 0&&N!==t)throw Error(`gjsify webext: icon "${S}" uses ${t}, and ${N} has the same file name; an SVG target would receive only one of them as `+C+`. Rename one.`);n.set(C,t)}return n}async function renderWebextIcons(t,n,S=rasterizeSvg){let C=n.some(n=>!t.svgTargets.has(n.id)),N=n.some(n=>t.svgTargets.has(n.id)),F=new Map;if(C){let n=new Map;for(let[S,C]of t.sources)for(let[t,N]of C)n.set(N,[...n.get(N)??[],{size:t,name:S}]);for(let[t,C]of n){let n=await S({svg:t,sizes:[...new Set(C.map(t=>t.size))],command:`gjsify webext`});for(let{size:t,name:S}of C)F.set(`icons/${S}-${t}.png`,n.get(t))}}return{png:F,svg:N?svgIconFiles(t):new Map}}function writeWebextIcons(t,n,S,C){if(mkdirSync(wn(C,`icons`),{recursive:!0}),n.svgTargets.has(S.id))for(let[n,S]of t.svg)copyFileSync(S,wn(C,n));else for(let[n,S]of t.png)writeFileSync(wn(C,n),S)}var nK=__esmMin(()=>{Rd(),Pn(),PB()});function isRecord$1(t){return typeof t==`object`&&!!t&&!Array.isArray(t)}function mergeManifest(t,n){let S={...t};for(let[t,C]of Object.entries(n))C===null?delete S[t]:isRecord$1(C)&&isRecord$1(S[t])?S[t]=mergeManifest(S[t],C):S[t]=C;return S}function applyTargetOverrides(t,n){let{$targets:S,...C}=t;if(S===void 0)return C;if(!isRecord$1(S))throw Error("gjsify webext: the manifest's `$targets` must be an object.");let N=S[n];if(N===void 0)return C;if(!isRecord$1(N))throw Error(`gjsify webext: \`$targets["${n}"]\` in the manifest must be an object.`);return mergeManifest(C,N)}async function composeManifest(t,n){let S=typeof t==`function`?await t(n):applyTargetOverrides(t,n.target);if(!isRecord$1(S))throw Error(`gjsify webext: the manifest for ${n.target} is not an object (got ${typeof S}).`);if(S.version!==void 0)return S;let C={};for(let[t,N]of Object.entries(S))C[t]=N,t===`name`&&(C.version=n.version);return C.version===void 0&&(C.version=n.version),C}async function loadManifestTemplate(t){if(/\.json$/i.test(t))try{return JSON.parse(readFileSync(t,`utf8`))}catch(n){throw Error(`gjsify webext: ${t} is not valid JSON: ${n.message}`)}let n,cleanup=null;if(isGjs()){let{BuildAction:S}=await Promise.resolve().then(()=>(DI(),wI)),C=await S.bundleFileForGjsCached(t,{cacheSubdir:`webext`,label:Dn(t),cache:!1,define:{"import.meta.url":JSON.stringify(pathToFileURL(t).href)}}),N=wn(En(C),`manifest-${process.pid}-${++rK}.mjs`);copyFileSync(C,N),n=pathToFileURL(N).href,cleanup=()=>rmSync(N,{force:!0})}else n=`${pathToFileURL(t).href}?t=${statSync(t).mtimeMs}-${++rK}`;try{let S=(await import(n)).default;if(typeof S!=`function`&&!isRecord$1(S))throw Error(`gjsify webext: ${t} has no default export. Export the manifest object, or a function \`(ctx) => manifest\` that receives the target.`);return S}finally{cleanup?.()}}function addPath(t,n){typeof n!=`string`||n===``||/^[a-z][a-z0-9+.-]*:/i.test(n)||n.includes(`*`)||t.add(n.replace(/^\//,``).replace(/[?#].*$/,``))}function addIconValue(t,n){if(typeof n==`string`)addPath(t,n);else if(isRecord$1(n))for(let S of Object.values(n))addPath(t,S)}function manifestFileReferences(t){let n=new Set,S=t.background;if(isRecord$1(S)&&(addPath(n,S.service_worker),addPath(n,S.page),Array.isArray(S.scripts)))for(let t of S.scripts)addPath(n,t);if(Array.isArray(t.content_scripts)){for(let S of t.content_scripts)if(isRecord$1(S)){for(let t of[`js`,`css`])if(Array.isArray(S[t]))for(let C of S[t])addPath(n,C)}}for(let S of[`action`,`browser_action`,`page_action`,`sidebar_action`]){let C=t[S];isRecord$1(C)&&(addPath(n,C.default_popup),addPath(n,C.default_panel),addIconValue(n,C.default_icon))}if(isRecord$1(t.options_ui)&&addPath(n,t.options_ui.page),addPath(n,t.options_page),addPath(n,t.devtools_page),isRecord$1(t.side_panel)&&addPath(n,t.side_panel.default_path),addIconValue(n,t.icons),isRecord$1(t.chrome_url_overrides))for(let S of Object.values(t.chrome_url_overrides))addPath(n,S);if(Array.isArray(t.web_accessible_resources)){for(let S of t.web_accessible_resources)if(typeof S==`string`)addPath(n,S);else if(isRecord$1(S)&&Array.isArray(S.resources))for(let t of S.resources)addPath(n,t)}return[...n].sort()}function checkManifest(t,n,S){let C=[];t.manifest_version!==n.manifestVersion&&C.push(`manifest_version is ${JSON.stringify(t.manifest_version)}, and target ${n.id} is Manifest V${n.manifestVersion}. gjsify does not convert keys between versions — branch on \`ctx.manifestVersion\` in the manifest.`);for(let N of manifestFileReferences(t))existsSync(wn(S,N))||C.push(`the manifest names "${N}", which the build did not write into ${n.id}/.`);let N=existsSync(wn(S,`_locales`)),F=t.default_locale;return N&&typeof F!=`string`?C.push(`_locales/ exists but the manifest sets no default_locale; the browser refuses to load it.`):!N&&F!==void 0?C.push(`the manifest sets default_locale "${String(F)}" but there is no _locales/ directory.`):typeof F==`string`&&!existsSync(wn(S,`_locales`,F,`messages.json`))&&C.push(`default_locale is "${F}" but _locales/${F}/messages.json does not exist.`),C}var rK,iK=__esmMin(()=>{Rd(),Pn(),Gn(),d_(),__name$1(isRecord$1,`isRecord`),rK=0});function planPage(t,n,S){let C=En(n),N=[],F=[],local=t=>{if(dK.test(t)||t.startsWith(`/`))return null;let n=t.replace(/[?#].*$/,``);return Cn(n)?n:xn(C,n)},I=S.replace(aK,n=>{let S=sK.exec(n);if(!S)return n;let C=local(S[2]);if(C===null||!fK.test(C))return n;let F=N.length===0?`${t}.js`:`${t}-${N.length+1}.js`;return N.push({entry:C,format:lK.test(n)?`esm`:`iife`,output:F}),n.replace(sK,(t,n)=>`src=${n}${F}${n}`)});return I=I.replace(oK,t=>{if(!uK.test(t))return t;let n=cK.exec(t);if(!n)return t;let S=local(n[2]);if(S===null)return t;let C=Dn(S);return F.push({source:S,output:C}),t.replace(cK,(t,n)=>`href=${n}${C}${n}`)}),{html:I,scripts:N,stylesheets:F}}var aK,oK,sK,cK,lK,uK,dK,fK,pK=__esmMin(()=>{Pn(),aK=/<script\b[^>]*\bsrc\s*=\s*["'][^"']+["'][^>]*>/gi,oK=/<link\b[^>]*>/gi,sK=/\bsrc\s*=\s*(["'])([^"']+)\1/i,cK=/\bhref\s*=\s*(["'])([^"']+)\1/i,lK=/\btype\s*=\s*["']module["']/i,uK=/\brel\s*=\s*["'][^"']*\bstylesheet\b[^"']*["']/i,dK=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,fK=/\.(?:[cm]?[jt]sx?)$/i});function zipTimestamp(t=process.env){let n=Number(t.SOURCE_DATE_EPOCH);return Number.isFinite(n)&&n>=mK?n:mK}function zipEntriesOf(t){let n=[],walk=S=>{for(let C of readdirSync(S,{withFileTypes:!0})){let N=wn(S,C.name);C.isDirectory()?walk(N):n.push({path:Tn(t,N).split(/[\\/]/).join(`/`),mode:420,data:readFileSync(N)})}};return walk(t),n}async function buildWebext(t){let{config:n,targets:S,outDir:C,define:N}=t,F=t.log??(t=>ge.log(t)),I=t.mode===`production`&&n.minify,H=wn(C,`.stage`);rmSync(H,{recursive:!0,force:!0}),mkdirSync(H,{recursive:!0});try{for(let[S,C]of n.scripts)await t.bundle({entry:C,outfile:wn(H,`${S}.js`),format:`iife`,define:N,minify:I});let W=new Map;for(let[S,C]of n.pages){let n=planPage(S,C,readFileSync(C,`utf8`));for(let S of n.scripts)await t.bundle({entry:S.entry,outfile:wn(H,S.output),format:S.format,define:N,minify:I});for(let t of n.stylesheets){let n=W.get(t.output);if(n!==void 0&&n!==t.source)throw Error(`gjsify webext: pages link ${n} and ${t.source}, which would both be written as ${t.output}. Rename one.`);W.set(t.output,t.source),cpSync(t.source,wn(H,t.output))}writeFileSync(wn(H,`${S}.html`),n.html)}let q=n.icons,Y=q?await renderWebextIcons(q,S,t.rasterize):null,X=await loadManifestTemplate(n.manifest),Z={folders:new Map,zips:new Map};for(let I of S){let S=wn(C,I.id);t.inPlace||rmSync(S,{recursive:!0,force:!0}),mkdirSync(S,{recursive:!0}),n.publicDir&&cpSync(n.publicDir,S,{recursive:!0}),n.localesDir&&cpSync(n.localesDir,wn(S,`_locales`),{recursive:!0}),cpSync(H,S,{recursive:!0}),q&&Y&&writeWebextIcons(Y,q,I,S);let W=await composeManifest(X,{target:I.id,browser:I.browser,manifestVersion:I.manifestVersion,mode:t.mode,version:n.version,define:N,icons:t=>{if(!q)throw Error(`gjsify webext: the manifest asks for icon "${t}" and \`gjsify.webext.icons\` is not declared.`);return webextIconPaths(q,t,I)}});writeFileSync(wn(S,`manifest.json`),`${JSON.stringify(W,null,2)}\n`);let te=checkManifest(W,I,S);if(te.length>0)throw Error(`gjsify webext: ${I.id} would not load:\n - ${te.join(`
1809
+ - `)}`);if(Z.folders.set(I.id,S),F(`built ${Tn(process.cwd(),S)||S}`),t.zip){let t=wn(C,`${n.name}-${n.version}-${I.id}.zip`);writeFileSync(t,buildZip(zipEntriesOf(S),zipTimestamp())),Z.zips.set(I.id,t),F(`zipped ${Tn(process.cwd(),t)||t} (${Math.round(statSync(t).size/1024)} KiB)`)}}return Z}finally{rmSync(H,{recursive:!0,force:!0})}}var mK,hK=__esmMin(()=>{_e(),Rd(),Pn(),WH(),nK(),iK(),pK(),mK=315532800});function parseWebextTarget(t){let n=/^([a-z]+)-mv([23])$/.exec(t),S=n?.[1];if(!n||S===void 0||!gK.includes(S))throw Error(`gjsify webext: unknown target "${t}". A target is <browser>-mv<2|3> with browser one of ${gK.join(`, `)} (e.g. chrome-mv3, firefox-mv2).`);let C=n[2]===`2`?2:3,N=C===2?vK.get(S):void 0;if(N!==void 0)throw Error(`gjsify webext: target "${t}" does not exist any more: ${N}. Use ${S}-mv3.`);return{id:t,browser:S,manifestVersion:C}}function webExtRunTarget(t){return t.browser===`firefox`?`firefox-desktop`:t.browser===`chrome`||t.browser===`edge`||t.browser===`opera`?`chromium`:null}var gK,_K,vK,yK=__esmMin(()=>{gK=[`chrome`,`edge`,`firefox`,`opera`,`safari`],_K=[`chrome-mv3`,`firefox-mv3`],vK=new Map([[`chrome`,`chrome has removed Manifest V2`],[`edge`,`edge has removed Manifest V2`],[`opera`,`opera's extension store accepts Manifest V3 only`]])});function isRecord(t){return typeof t==`object`&&!!t&&!Array.isArray(t)}function defaultArtifactName(t){let n=(t??`extension`).replace(/^@[^/]+\//,``);return n===``?`extension`:n}function iconSourceForSize(t,n){if(typeof t==`string`)return t;let S=Object.keys(t).filter(t=>/^\d+$/.test(t)).map(Number).sort((t,n)=>t-n).find(t=>n<=t);return S===void 0?t.default:t[String(S)]}function resolveWebextConfig(t,n,S=defaultExists){let C=[],N=t.gjsify?.webext;if(N===void 0)throw Error("gjsify webext: this package declares no `gjsify.webext` block in package.json. Add one naming at least the manifest and one script or page — see `gjsify webext build --help`.");if(!isRecord(N))throw Error("gjsify webext: `gjsify.webext` must be an object.");let F=N,abs=t=>Cn(t)?t:xn(n,t),need=(t,n,N)=>{let F=abs(n);return S(F,N)||C.push(`${t} "${n}" is not a ${N===`dir`?`directory`:`file`}.`),F},I=[],H=F.targets??[..._K];if(!Array.isArray(H)||H.length===0)C.push("`targets` must be a non-empty array of target names.");else for(let t of H)try{I.some(n=>n.id===t)?C.push(`target "${t}" is listed twice.`):I.push(parseWebextTarget(String(t)))}catch(t){C.push(t.message.replace(/^gjsify webext: /,``))}let W=``;if(F.manifest!==void 0)W=need("`manifest`",F.manifest,`file`);else{let t=xK.find(t=>S(wn(n,t),`file`));t===void 0?C.push(`no \`manifest\` declared and none of ${xK.join(`, `)} exists.`):W=wn(n,t)}let q=new Map,claim=(t,n)=>{let S=q.get(t);S===void 0?q.set(t,n):C.push(`${n} and ${S} both write ${t}.`)},readEntries=t=>{let n=new Map,S=F[t];if(S===void 0)return n;if(!isRecord(S))return C.push(`\`${t}\` must map an output name to a source file.`),n;for(let[N,F]of Object.entries(S)){if(!SK.test(N)){C.push(`\`${t}.${N}\`: an output name is a plain file name (letters, digits, . _ -).`);continue}if(typeof F!=`string`){C.push(`\`${t}.${N}\` must be a path.`);continue}n.set(N,need(`\`${t}.${N}\``,F,`file`)),t===`scripts`?claim(`${N}.js`,`\`scripts.${N}\``):claim(`${N}.html`,`\`pages.${N}\``)}return n},Y=readEntries(`scripts`),X=readEntries(`pages`);Y.size===0&&X.size===0&&C.push("declare at least one entry under `scripts` or `pages`; there is nothing to build.");for(let t of X.keys())Y.has(t)&&C.push(`\`scripts.${t}\` and the script of \`pages.${t}\` both write ${t}.js.`);let Z=null;if(F.icons!==void 0)if(!isRecord(F.icons)||!isRecord(F.icons.sources))C.push("`icons` must be an object with a `sources` map (icon name → SVG).");else{let t=F.icons.sizes??bK;(!Array.isArray(t)||t.length===0||t.some(t=>!Number.isInteger(t)||t<=0))&&C.push("`icons.sizes` must be a non-empty list of positive integers.");let n=new Set(F.icons.svg??[]);for(let t of n)I.some(n=>n.id===t)||C.push(`\`icons.svg\` names "${t}", which is not one of this package's targets.`);let N=new Map;for(let[n,I]of Object.entries(F.icons.sources)){if(!SK.test(n)){C.push(`\`icons.sources.${n}\`: an icon name is a plain file name.`);continue}if(typeof I!=`string`&&!isRecord(I)){C.push(`\`icons.sources.${n}\` must be an SVG path or a map of size ceilings to SVGs.`);continue}let F=new Map;for(let S of t){let t=iconSourceForSize(I,S);if(t===void 0){C.push(`\`icons.sources.${n}\` has no SVG for ${S} px — add a "default".`);continue}/\.svg$/i.test(t)||C.push(`\`icons.sources.${n}\`: "${t}" is not an .svg file.`),F.set(S,abs(t))}for(let t of new Set(F.values()))S(t,`file`)||C.push(`\`icons.sources.${n}\`: "${t}" does not exist.`);N.set(n,F)}Z={sizes:t,sources:N,svgTargets:n}}let optionalDir=(t,C)=>{let N=F[t];if(N!==void 0)return need(`\`${t}\``,N,`dir`);let I=wn(n,C);return S(I,`dir`)?I:null},te=optionalDir(`public`,`public`),ne=optionalDir(`locales`,`_locales`),re=F.define??{};(!isRecord(re)||Object.values(re).some(t=>typeof t!=`string`))&&C.push("`define` must map identifiers to JS expressions given as strings.");let ie=F.watch??[];if((!Array.isArray(ie)||ie.some(t=>typeof t!=`string`))&&C.push("`watch` must be a list of directories."),C.length>0)throw Error(`gjsify webext: \`gjsify.webext\` in ${wn(n,`package.json`)}:\n - ${C.join(`
1810
+ - `)}`);return{root:n,name:F.name??defaultArtifactName(t.name),version:t.version??`0.0.0`,targets:I,manifest:W,scripts:Y,pages:X,icons:Z,publicDir:te,localesDir:ne,outDir:abs(F.outDir??`.output`),define:re,watch:ie.map(abs),minify:F.minify??!0}}function defaultExists(t,n){if(!existsSync(t))return!1;let S=statSync(t);return n===`dir`?S.isDirectory():S.isFile()}function selectTargets(t,n){return n===void 0||n.length===0?t.targets:n.map(n=>{let S=t.targets.find(t=>t.id===n);if(S)return S;throw parseWebextTarget(n),Error(`gjsify webext: target "${n}" is not in \`gjsify.webext.targets\` (${t.targets.map(t=>t.id).join(`, `)}).`)})}var bK,xK,SK,CK=__esmMin(()=>{Rd(),Pn(),yK(),bK=[16,32,48,128],xK=[`manifest.ts`,`manifest.mts`,`manifest.js`,`manifest.mjs`,`manifest.json`],SK=/^[A-Za-z0-9][A-Za-z0-9._-]*$/});function webExtRunArgs(t){let n=webExtRunTarget(t.target);if(n===null)throw Error(`gjsify webext dev: web-ext cannot launch ${t.target.browser}. Build with \`gjsify webext build --target ${t.target.id}\` and load the folder by hand, or pass \`--no-launch\`.`);let S=[`run`,`--source-dir`,t.sourceDir,`--target`,n,`--no-input`,`--profile-create-if-missing`];return n===`firefox-desktop`?(S.push(`--firefox-profile`,t.profile,`--keep-profile-changes`),t.browserBinary&&S.push(`--firefox`,t.browserBinary),t.headless&&S.push(`--arg=-headless`)):(S.push(`--chromium-profile`,t.profile),t.browserBinary&&S.push(`--chromium-binary`,t.browserBinary),t.headless&&S.push(`--arg=--headless=new`)),S}function defaultDevProfile(t,n,S=process.env){return wn(S.XDG_CACHE_HOME||wn(homedir(),`.cache`),`gjsify`,`webext`,t,n.id)}function resolveWebExt(t,n=process.platform,S=process.env){let C=n===`win32`?`web-ext.cmd`:`web-ext`;for(let n=t;;n=En(n)){let t=wn(n,`node_modules`,`.bin`);if(existsSync(wn(t,C)))return{cmd:`web-ext`,env:{...S,PATH:[t,S.PATH].filter(Boolean).join(Mn)}};if(En(n)===n)break}return isOnPath(`web-ext`)?{cmd:`web-ext`,env:S}:null}var wK,TK=__esmMin(()=>{Rd(),Lg(),Pn(),vF(),yK(),wK="gjsify webext dev: `web-ext` is not installed. Add it to the project (`gjsify install --save-dev web-ext`) or install it globally, or pass `--no-launch` to rebuild without a browser."});function loadConfig(t){let n=wn(t,`package.json`);if(!existsSync(n))throw Error(`gjsify webext: no package.json in ${t}.`);return resolveWebextConfig(JSON.parse(readFileSync(n,`utf8`)),t)}function effectiveDefines(t,n){let S={...t.define};for(let t of n){let n=t.indexOf(`=`);if(n<=0)throw Error(`gjsify webext: --define "${t}" is not KEY=VALUE.`);S[t.slice(0,n)]=t.slice(n+1)}return S}async function bundleInProcess(t){let{runCli:n}=await Promise.resolve().then(()=>(UK(),HK)),S=[`build`,t.entry,`--app`,`browser`,`--format`,t.format,`--outfile`,t.outfile];for(let[n,C]of Object.entries(t.define))S.push(`--define`,`${n}=${C}`);t.minify||S.push(`--no-minify`),await n(S)}async function runBuild(t,n){let S=process.cwd(),C=loadConfig(S),N=t.mode===`development`?`development`:`production`;await buildWebext({config:C,targets:selectTargets(C,t.target),outDir:t.outDir?xn(S,t.outDir):C.outDir,mode:N,define:effectiveDefines(C,t.define),inPlace:!1,zip:n,bundle:bundleInProcess})}function devTarget(t,n){if(n&&n.length>1)throw Error(`gjsify webext dev: pass one --target.`);let[S]=selectTargets(t,n);return n&&n.length===1?S:t.targets.find(t=>t.browser===`firefox`)??S}function devWatchTargets(t,n){let skip=t=>t===`node_modules`||t.startsWith(`.`),S=[{path:t.root,recursive:!1}];for(let C of readdirSync(t.root,{withFileTypes:!0})){let N=wn(t.root,C.name);!C.isDirectory()||skip(C.name)||N===n||n.startsWith(N+jn)||S.push({path:N,recursive:!0})}for(let n of t.watch)S.push({path:n,recursive:!0});return S}var EK,DK,OK,kK,AK,jK,MK=__esmMin(()=>{_e(),Rd(),Pn(),hK(),CK(),TK(),EK={description:`Build only these targets (default: every target in gjsify.webext.targets).`,type:`string`,array:!0},DK={description:`Output directory (default: gjsify.webext.outDir, else .output).`,type:`string`},OK={description:`Compile-time constant for every bundle, KEY=VALUE (repeatable); wins over gjsify.webext.define.`,type:`string`,array:!0,default:[]},kK={command:`build`,description:`Build one extension folder per target: bundles, pages, icons, locales and the manifest.`,builder:t=>t.option(`target`,EK).option(`out-dir`,DK).option(`define`,OK).option(`mode`,{description:`Passed to the manifest as ctx.mode; development also skips minification.`,type:`string`,choices:[`production`,`development`],default:`production`}),handler:t=>runBuild(t,!1)},AK={command:`zip`,description:`Production build, then one store-ready <name>-<version>-<target>.zip per target.`,builder:t=>t.option(`target`,EK).option(`out-dir`,DK).option(`define`,OK),handler:t=>runBuild(t,!0)},jK={command:`dev`,description:`Build one target in development mode, launch it in a browser via web-ext, and rebuild in place on change.`,builder:t=>t.option(`target`,{...EK,description:`The target to run (default: the first Firefox target).`}).option(`out-dir`,{description:`Output directory (default: <outDir>-dev).`,type:`string`}).option(`define`,OK).option(`launch`,{description:`Start a browser with the extension (--no-launch only rebuilds).`,type:`boolean`,default:!0}).option(`browser-binary`,{description:`Browser executable web-ext should start.`,type:`string`}).option(`profile`,{description:`Browser profile directory (default: $XDG_CACHE_HOME/gjsify/webext/<name>/<target>).`,type:`string`}).option(`headless`,{description:`Start the browser without a window.`,type:`boolean`,default:!1}).option(`debounce`,{description:`Quiet window in ms before a rebuild.`,type:`number`,default:200}),handler:async t=>{let n=process.cwd(),S=loadConfig(n),C=devTarget(S,t.target),N=t.outDir?xn(n,t.outDir):`${S.outDir}-dev`,F=effectiveDefines(S,t.define),I=wn(N,C.id),H=null;if(t.launch&&(H=resolveWebExt(n),H===null))throw Error(wK);let W=null,stopBrowser=()=>{W?.kill()};process.on(`SIGINT`,stopBrowser),process.on(`SIGTERM`,stopBrowser);let launch=async()=>{if(H===null||W!==null)return;let N=t.profile?xn(n,t.profile):defaultDevProfile(S.name,C);mkdirSync(En(N),{recursive:!0});let F=webExtRunArgs({sourceDir:I,target:C,profile:N,browserBinary:t.browserBinary,headless:t.headless});ge.log(`[webext] launching ${C.id} with profile ${N}`);let{spawnSupervised:q}=await Promise.resolve().then(()=>(HG(),VG));W=await q(H.cmd,F,H.env),W.on(`exit`,t=>{ge.log(`[webext] browser closed (${t??0}) — stopping`),process.exit(0)})},{runWatchLoop:q}=await Promise.resolve().then(()=>(HG(),VG));await q({dir:n,dirLabel:`.`,label:`webext`,watch:devWatchTargets(S,N),ignore:t=>t===N||t.startsWith(N+jn),build:async()=>{await buildWebext({config:S,targets:[C],outDir:N,mode:`development`,define:F,inPlace:!0,zip:!1,bundle:bundleInProcess}),await launch()},spawnChild:null,debounceMs:t.debounce})}}}),NK,PK=__esmMin(()=>{MK(),NK={command:`webext <subcommand>`,description:`Browser extensions: build, zip and develop one WebExtension for Chrome, Edge, Firefox, Opera and Safari.`,builder:t=>t.command(kK.command,kK.description,kK.builder,kK.handler).command(AK.command,AK.description,AK.builder,AK.handler).command(jK.command,jK.description,jK.builder,jK.handler).demandCommand(1).strict()}});function blueprintsUnder(t,n){let S;try{S=statSync(t)}catch{return n}if(!S.isDirectory())return t.endsWith(`.blp`)&&n.push(t),n;for(let S of readdirSync(t).sort())FK.has(S)||S.startsWith(`.`)||blueprintsUnder(wn(t,S),n);return n}var FK,IK,formatFor,LK,RK=__esmMin(()=>{_e(),Rd(),Pn(),Mk(),zk(),FK=new Set([`node_modules`,`dist`,`lib`,`.git`]),IK=new Map,formatFor=t=>{let n=IK.get(t);if(n!==void 0)return n;let S=emitFormatForTree(t);return IK.set(t,S),S},LK={command:`types [paths..]`,description:"Generate the `<name>.d.blp.ts` type sidecar for each .blp (ADR 0088), so `import { build }` / `import { GTypeName }` type-check before anything is built. Defaults to the current directory.",builder:t=>t.positional(`paths`,{description:`Files or directories to scan for .blp (default: the current directory)`,type:`string`,array:!0,normalize:!0,default:[]}).option(`check`,{description:`Write nothing; exit non-zero when a sidecar is missing or stale`,type:`boolean`,default:!1}).option(`verbose`,{description:`Print every file considered, not only the ones that changed`,type:`boolean`,default:!1}),handler:async t=>{let n=t.paths??[],S=(n.length>0?n:[`.`]).map(t=>Cn(t)?t:xn(process.cwd(),t)),C=[];for(let t of S)blueprintsUnder(t,C);let N=[],F=0;for(let n of C){let S=sidecarPathFor(n),C=emitTypedSidecar(parseBlueprint(readFileSync(n,`utf8`),n),Dn(n),formatFor(En(n))),I;try{I=readFileSync(S,`utf8`)}catch{I=void 0}if(I===C){t.verbose&&ge.log(`[gjsify blueprint types] current: ${S}`);continue}if(t.check){N.push(S);continue}writeFileSync(S,C,`utf8`),F+=1,ge.log(`[gjsify blueprint types] wrote ${S}`)}if(t.check){if(N.length===0){ge.log(`[gjsify blueprint types] ${C.length} .blp checked, every sidecar current.`);return}for(let t of N)ge.error(`[gjsify blueprint types] missing or stale: ${t}`);ge.error(`[gjsify blueprint types] run without --check to regenerate.`),process.exitCode=1;return}ge.log(`[gjsify blueprint types] ${C.length} .blp scanned, ${F} sidecar(s) written, ${C.length-F} already current.`)}}}),zK,BK=__esmMin(()=>{RK(),zK={command:`blueprint <subcommand>`,description:`Blueprint (.blp) tooling: generate the TypeScript type sidecars a .blp exports (ADR 0088).`,builder:t=>t.command(LK.command,LK.description,LK.builder,LK.handler).demandCommand(1).strict()}}),VK=__esmMin(()=>{MI(),PI(),LI(),VI(),aL(),cL(),_R(),yR(),xR(),jR(),WR(),cz(),dz(),hz(),vz(),fB(),bU(),BR(),EU(),kU(),PU(),kR(),zU(),vW(),bW(),CW(),TW(),jW(),LW(),GW(),JW(),XW(),QW(),sG(),lG(),dG(),vG(),CG(),TG(),BG(),WG(),KG(),YG(),ZG(),$G(),tK(),PK(),BK()}),HK=__exportAll$5({runCli:()=>runCli});function runtimeLabel(){let t=gjsSystemVersion();if(t!==void 0){let n=Number(t);return`GJS ${Math.floor(n/1e4)}.${Math.floor(n%1e4/100)}.${n%100} (SpiderMonkey)`}return isBun()?`Bun ${globalThis.Bun?.version??process.versions.bun??``}`.trim():isDeno()?`Deno ${globalThis.Deno?.version?.deno??``}`.trim():isNode()?`Node.js ${process.version}`:`unknown runtime`}async function runCli(t){ensureGjsifyShimOnPath();let n=Hm(t);await n.scriptName(rh).version(cliVersion()).strict().fail((t,S)=>{let C=classifyCliFailure(t,S);if(C.kind===`usage`)throw n.showHelp(`error`),Error(C.message,{cause:S})}).wrap(n.terminalWidth()).command(sz.command,sz.description,sz.builder,sz.handler).command(wU.command,wU.description,wU.builder,wU.handler).command(DU.command,DU.description,DU.builder,DU.handler).command(OU.command,OU.description,OU.builder,OU.handler).command(jI.command,jI.description,jI.builder,jI.handler).command(NI.command,NI.description,NI.builder,NI.handler).command(II.command,II.description,II.builder,II.handler).command(BI.command,BI.description,BI.builder,BI.handler).command(iL.command,iL.description,iL.builder,iL.handler).command(sL.command,sL.description,sL.builder,sL.handler).command(gR.command,gR.description,gR.builder,gR.handler).command(zR.command,zR.description,zR.builder,zR.handler).command(vR.command,vR.description,vR.builder,vR.handler).command(bR.command,bR.description,bR.builder,bR.handler).command(AR.command,AR.description,AR.builder,AR.handler).command(UR.command,UR.description,UR.builder,UR.handler).command(uz.command,uz.description,uz.builder,uz.handler).command(mz.command,mz.description,mz.builder,mz.handler).command(_z.command,_z.description,_z.builder,_z.handler).command(dB.command,dB.description,dB.builder,dB.handler).command(yU.command,yU.description,yU.builder,yU.handler).command(NU.command,NU.description,NU.builder,NU.handler).command(OR.command,OR.description,OR.builder,OR.handler).command(IU.command,IU.description,IU.builder,IU.handler).command(_W.command,_W.description,_W.builder,_W.handler).command(yW.command,yW.description,yW.builder,yW.handler).command(SW.command,SW.description,SW.builder,SW.handler).command(wW.command,wW.description,wW.builder,wW.handler).command(AW.command,AW.description,AW.builder,AW.handler).command(IW.command,IW.description,IW.builder,IW.handler).command(UW.command,UW.description,UW.builder,UW.handler).command(qW.command,qW.description,qW.builder,qW.handler).command(ZW.command,ZW.description,ZW.builder,ZW.handler).command(YW.command,YW.description,YW.builder,YW.handler).command(mG.command,mG.description,mG.builder,mG.handler).command(oG.command,oG.description,oG.builder,oG.handler).command(cG.command,cG.description,cG.builder,cG.handler).command(uG.command,uG.description,uG.builder,uG.handler).command(SG.command,SG.description,SG.builder,SG.handler).command(wG.command,wG.description,wG.builder,wG.handler).command(RG.command,RG.description,RG.builder,RG.handler).command(UG.command,UG.description,UG.builder,UG.handler).command(GG.command,GG.description,GG.builder,GG.handler).command(JG.command,JG.description,JG.builder,JG.handler).command(XG.command,XG.description,XG.builder,XG.handler).command(QG.command,QG.description,QG.builder,QG.handler).command(eK.command,eK.description,eK.builder,eK.handler).command(NK.command,NK.description,NK.builder,NK.handler).command(zK.command,zK.description,zK.builder,zK.handler).demandCommand(1).epilogue(`Running on ${runtimeLabel()}`).help().parseAsync()}var UK=__esmMin(()=>{Um(),Wm(),nh(),VK(),ih(),d_(),pR()});UK(),d_(),hR();function pendingFailureCode(t,n){if(n||t==null)return null;let S=Number(t);return Number.isFinite(S)&&S!==0?S:null}function exitOnReportedFailure(){let t=pendingFailureCode(process.exitCode,isDaemonCommand());t!==null&&gjsExit(t)}_e(),d_();try{await runCli(hideBin(process.argv))}catch(t){let n=typeof t==`object`&&t&&typeof t.code==`string`?t.code:``,S=t instanceof Error?t.message:String(t);ge.error(n&&!S.includes(n)?`${n}: ${S}`:S),process.env.GJSIFY_DEBUG&&t instanceof Error&&t.stack&&ge.error(t.stack),process.exitCode=1,gjsExit(1)}exitOnReportedFailure();const WK=globalThis.process,GK=Number(WK?.exitCode);Number.isInteger(GK)&&GK!==0&&WK.exit(GK);