@gjsify/cli 0.16.2 → 0.16.3

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
@@ -743,7 +743,7 @@ function load() {
743
743
  cached = require('@gjsify/node-gi/gi').requireGi(${JSON.stringify(n)}${S});\n }\n return cached;\n}\nexport default new Proxy(Object.create(null), {\n get(_target, prop) { return load()[prop]; },\n has(_target, prop) { return prop in load(); },\n});\n`}function gjsGiNodePlugin(){return{name:`gjsify-gi-node`,resolveId:{order:`pre`,filter:{id:/^gi:\/\//},handler(n){let a=parseGiSpecifier(n);if(a===null)return null;let S=a.version?`@${a.version}`:``;return{id:`${bA}${a.namespace}${S}`}}},load(n){if(!n.startsWith(bA))return null;let a=n.slice(16),S=a.lastIndexOf(`@`);return{code:giNodeShimSource(S===-1?a:a.slice(0,S),S===-1?void 0:a.slice(S+1)),moduleSideEffects:!1}}}}function gjsBuiltinModulesNodePlugin(n){let a=Object.keys(n),S=a.length>0?{id:RegExp(`^(?:${a.map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)).join(`|`)})$`)}:void 0;return{name:`gjsify-builtin-modules-node`,resolveId:{order:`pre`,...S?{filter:S}:{},handler(a){let S=n[a];return S?{id:S,external:!0}:null}}}}var bA,xA=__esmMin(()=>{bA=`\0gjsify-gi-node:`});function flattenAliases$3(n){let a={};for(let[S,C]of Object.entries(n))C&&(a[S]=C);return a}var SA,CA,setupForNode,wA=__esmMin(()=>{Yb(),tC(),c_(),l_(),Nv(),Fk(),uA(),yA(),xA(),hA(),SA=`@gjsify/node-gi/globals`,CA=[`@gjsify/node-gi/system`,`@gjsify/node-gi/gettext`],setupForNode=async n=>{let a=n.userExternal??[],S=[...Qg,`node-datachannel`,`@gjsify/node-gi`,`@gjsify/node-gi/gi`,SA,...CA,...a],external=n=>!!(S.includes(n)||n===`@gjsify/node-gi`||n.startsWith(`@gjsify/node-gi/`)),C=n.pluginOptions.format??`esm`,N=n.pluginOptions.exclude??[],F=await globToEntryPoints(n.input,N),I=[];n.pluginOptions.nodeGiGlobalsInject&&I.push(SA);let H=wrapInputWithSideEffects(F,I),W=H.input,K={...getAliasesForNode({external}),...n.pluginOptions.aliases,...n.userAliases},q=getBundleDirFromOutput(n.output);return{options:{input:W,platform:`node`,external:S,resolve:{mainFields:C===`esm`?[`module`,`main`,`browser`]:[`main`,`module`,`browser`],conditionNames:C===`esm`?[`require`,`node`,`module`]:[`require`]},transform:{target:`node24`,define:{global:`globalThis`,window:`globalThis`}},output:{...n.output,format:C,sourcemap:!1,banner:void 0,codeSplitting:!1},treeshake:!0},plugins:[...H.plugin?[H.plugin]:[],gjsGiNodePlugin(),gjsBuiltinModulesNodePlugin(o_),gjsImportsEmptyPlugin({emptyGirs:!n.pluginOptions.nodeGiGlobalsInject}),aliasPlugin({entries:flattenAliases$3(K)}),deepkitPlugin({reflection:n.pluginOptions.reflection}),cssAsStringPlugin(),nodeModulesPathRewritePlugin({bundleDir:q})]}},__name$1(flattenAliases$3,`flattenAliases`)});function flattenAliases$2(n){let a={};for(let[S,C]of Object.entries(n))C&&(a[S]=C);return a}var setupForBrowser,TA=__esmMin(()=>{Yb(),tC(),kk(),c_(),Nv(),yA(),uA(),setupForBrowser=async n=>{let a=[...n.userExternal??[]],S=n.pluginOptions.exclude??[],C=await globToEntryPoints(n.input,S),N={};for(let[n,a]of Object.entries(n_))N[n]=a,N[`node:${n}`]=a;let F={},I={...getDerivedAliasesSync(`browser`),...N,...F,...n.pluginOptions.aliases,...n.userAliases};return{options:{input:C,platform:`browser`,external:a,resolve:{mainFields:[`browser`,`module`,`main`],conditionNames:[`import`,`browser`]},transform:{target:`esnext`,define:{global:`globalThis`,window:`globalThis`}},output:{...n.output,format:`esm`,sourcemap:!1,codeSplitting:!1},treeshake:!0},plugins:[gjsImportsEmptyPlugin(),aliasPlugin({entries:flattenAliases$2(I)}),blueprintPlugin(),deepkitPlugin({reflection:n.pluginOptions.reflection}),cssAsStringPlugin()]}},__name$1(flattenAliases$2,`flattenAliases`)});function isPlatform(n){return EA.includes(n)}function platformResolvePlugin(n={}){let a=n.platform,S=a?[a,`native`]:[`native`];return{name:`gjsify-nativescript-platform-resolve`,resolveId:{order:`pre`,async handler(n,a,C){if(!a||!n.startsWith(`./`)&&!n.startsWith(`../`))return null;let N=DA.exec(n),F=N?N[0]:``,I=F?n.slice(0,-F.length):n;for(let N of S){let S=F&&`${I}.${N}`!=`${I}.${N}${F}`?[`${I}.${N}`,`${I}.${N}${F}`]:[`${I}.${N}`];for(let N of S){if(N===n)continue;let S=await this.resolve(N,a,{skipSelf:!0,...C?.kind?{kind:C.kind}:{}});if(S&&!S.external)return S}}return null}}}}function detectNativescriptPlatform(n=process.env){let a=n.NATIVESCRIPT_PLATFORM??n.NS_PLATFORM;if(a&&isPlatform(a))return a;let S=n.NATIVESCRIPT_BUNDLER_ENV??n.NATIVESCRIPT_WEBPACK_ENV;if(S)try{let n=JSON.parse(S);if(n.android===!0)return`android`;if(n.ios===!0)return`ios`;if(n.visionos===!0)return`visionos`;if(typeof n.platform==`string`&&isPlatform(n.platform))return n.platform}catch{}}function nativescriptPlatformDefines(n,a={}){let S=n===`android`,C=n===`ios`,N=n===`visionos`;return{__ANDROID__:String(S),__IOS__:String(C),__VISIONOS__:String(N),__APPLE__:String(C||N),__DEV__:String(a.dev??!1)}}var EA,DA,OA=__esmMin(()=>{EA=[`android`,`ios`,`visionos`],DA=/\.(tsx?|jsx?|mts|cts|mjs|cjs)$/});function flattenAliases$1(n){let a={};for(let[S,C]of Object.entries(n))C&&(a[S]=C);return a}var setupForNativescript,kA=__esmMin(()=>{Yb(),tC(),c_(),Nv(),yA(),OA(),setupForNativescript=async n=>{let a=[...n.userExternal??[]],S=n.pluginOptions.exclude??[],C=await globToEntryPoints(n.input,S),N=detectNativescriptPlatform(),F={};for(let[n,a]of Object.entries(r_))F[n]=a,F[`node:${n}`]=a;let I={},H={...getDerivedAliasesSync(`nativescript`),...F,...I,...n.pluginOptions.aliases,...n.userAliases};return{options:{input:C,platform:`browser`,external:a,resolve:{mainFields:[`nativescript`,`module`,`main`],conditionNames:[`import`,`nativescript`]},transform:{target:`esnext`,define:{global:`globalThis`,...nativescriptPlatformDefines(N,{dev:!1})}},output:{...n.output,format:`esm`,sourcemap:!1,codeSplitting:!1},treeshake:!0},plugins:[gjsImportsEmptyPlugin(),platformResolvePlugin({platform:N}),aliasPlugin({entries:flattenAliases$1(H)}),deepkitPlugin({reflection:n.pluginOptions.reflection})]}},__name$1(flattenAliases$1,`flattenAliases`)}),AA=__esmMin(()=>{_A(),wA(),TA(),kA()});function isExternalSpecifier(n){return!(n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`/`)||n.startsWith(`\0`)||n.startsWith(`data:`))}function computeCommonRoot(n){let a=n===void 0?[]:typeof n==`string`?[n]:Array.isArray(n)?n:Object.values(n);if(a.length===0)return`src`;let S=a.map(n=>n.split(`/`).filter(Boolean)),C=S[0],N=0;for(;N<C.length;N++){let n=C[N];if(!S.every(a=>a[N]===n))break}if(N===0)return`src`;let F=C.slice(0,N);return S.some(n=>n.length>N)?F.join(`/`):F.slice(0,-1).join(`/`)||`src`}function flattenAliases(n){let a={};for(let[S,C]of Object.entries(n))C&&(a[S]=C);return a}var setupLib,jA=__esmMin(()=>{Yb(),uA(),Xb(),Nv(),setupLib=async n=>{let a=n.pluginOptions.format??n.pluginOptions.library??`esm`,S=n.pluginOptions.exclude??[],C=await globToEntryPoints(n.input,S),N=computeCommonRoot(C),F={...n.pluginOptions.aliases,...n.userAliases};return{options:{input:C,platform:`neutral`,resolve:{mainFields:a===`esm`?[`module`,`main`]:[`main`],conditionNames:a===`esm`?[`module`,`import`]:[`require`]},transform:{target:`esnext`},output:{...n.output,format:a,preserveModules:!0,preserveModulesRoot:N,sourcemap:!1},treeshake:!1},plugins:[aliasPlugin({entries:flattenAliases(F)}),externalsPlugin(isExternalSpecifier,{name:`gjsify-lib-externalize`}),cssAsStringPlugin()]}}}),MA=__esmMin(()=>{jA()});function mimeForExtension(n){return NA[n.toLowerCase()]??`application/octet-stream`}function textLoaderPlugin(n={}){let a=n.loaders??{},S=Object.entries(a),C=S.filter(([,n])=>n===`text`).map(([n])=>n),N=S.filter(([,n])=>n===`dataurl`).map(([n])=>n),F=[...C,...N];if(F.length===0)return null;let I=F.map(n=>n.replace(/^\./,``).replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)),H=RegExp(`\\.(?:${I.join(`|`)})$`),W=new Map(S.map(([n,a])=>[n.toLowerCase(),a]));return{name:`gjsify-asset-loader`,async load(n){if(!H.test(n))return null;let a=n.lastIndexOf(`.`),S=a>=0?n.slice(a).toLowerCase():``;if((W.get(S)??`text`)===`dataurl`){let a=await readFile$1(n),C=mimeForExtension(S),N=a.toString(`base64`);return{code:`export default ${JSON.stringify(`data:${C};base64,${N}`)};`,moduleType:`js`}}let C=await readFile$1(n,`utf8`);return{code:`export default ${JSON.stringify(C)};`,moduleType:`js`}}}}var NA,PA=__esmMin(()=>{kc(),NA={".png":`image/png`,".jpg":`image/jpeg`,".jpeg":`image/jpeg`,".gif":`image/gif`,".webp":`image/webp`,".svg":`image/svg+xml`,".ico":`image/x-icon`,".avif":`image/avif`,".bmp":`image/bmp`,".tiff":`image/tiff`,".tif":`image/tiff`,".wasm":`application/wasm`}}),gjsifyPlugin,FA=__esmMin(()=>{AA(),MA(),gjsifyPlugin=async(n,a={})=>{if(a.library)switch(a.library){case`esm`:case`cjs`:return await setupLib({input:n.input,output:n.output,userAliases:n.userAliases,pluginOptions:a});default:throw TypeError(`Unknown library type: `+a.library)}let S=a.app??`gjs`;switch(S){case`gjs`:return await setupForGjs({input:n.input,output:n.output,userExternal:n.userExternal,userBanner:n.userBanner,userAliases:n.userAliases,shebang:n.shebang,pluginOptions:a});case`node`:return await setupForNode({input:n.input,output:n.output,userExternal:n.userExternal,userAliases:n.userAliases,pluginOptions:a});case`browser`:return await setupForBrowser({input:n.input,output:n.output,userExternal:n.userExternal,userAliases:n.userAliases,pluginOptions:a});case`nativescript`:return await setupForNativescript({input:n.input,output:n.output,userExternal:n.userExternal,userAliases:n.userAliases,pluginOptions:a});default:throw TypeError(`Unknown app platform: `+S)}}}),IA=__esmMin(()=>{Kg(),Jb(),AA(),MA(),Fk(),Vk(),uA(),PA(),mA(),yA(),Xb(),OA(),FA(),FA(),c_()});function isPluginByName(n){return typeof n==`object`&&!!n&&typeof n.name==`string`&&!(`apply`in n)&&!(`resolveId`in n)&&!(`load`in n)&&!(`transform`in n)&&!(`renderChunk`in n)&&!(`generateBundle`in n)}async function resolveUserPlugins(n,a,S={}){let C=S.loadModule??defaultLoadModule,N=createRequire(ns(a,`package.json`)),F=[];for(let S of n){if(!isPluginByName(S)){F.push(S);continue}let n;try{n=N.resolve(S.name)}catch(n){throw Error(`gjsify config: failed to resolve plugin "${S.name}" from ${a}. Add it to your project's dependencies, or pass a Plugin object directly. (${n.message})`)}let I=await C(n,S.name),H=S.export??`default`,W=I[H];if(typeof W!=`function`){let n=Object.keys(I).filter(n=>typeof I[n]==`function`);throw Error(`gjsify config: plugin "${S.name}" has no function export "${H}". Available function exports: ${n.length?n.join(`, `):`(none)`}.`)}let K=await W(S.options);if(K==null)throw Error(`gjsify config: plugin "${S.name}" factory returned ${K}. Check the plugin's signature — it should return a Rolldown/Vite plugin object.`);F.push(K)}return F}var defaultLoadModule,LA=__esmMin(()=>{Uo(),ps(),mn(),defaultLoadModule=async n=>await import(pathToFileURL(n).href)}),RA,zA=__esmMin(()=>{RA={"@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/dom-elements/register/canvas":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`HTMLCanvasElement`,`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`,`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`,`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/navigator":[`AbortController`,`AbortSignal`,`Blob`,`Buffer`,`ByteLengthQueuingStrategy`,`CountQueuingStrategy`,`DOMException`,`File`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`navigator`,`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`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`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/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/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`,`ReadableStream`,`TextDecoderStream`,`TextEncoderStream`,`TransformStream`,`WritableStream`,`atob`,`btoa`,`performance`,`process`,`queueMicrotask`,`setTimeout`,`structuredClone`],"@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.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/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.Event.EventTarget.File.Headers.ProgressEvent.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(n,a){let S=new Set(n),C=[...n];for(;C.length>0;){let n=C.pop(),N=BA[n];if(!N)continue;let F=VA[N];if(F)for(let n of F)a.has(n)||BA[n]&&(S.has(n)||(S.add(n),C.push(n)))}return S}function isSubset(n,a){for(let S of n)if(!a.has(S))return!1;return!0}async function applyExcludeGlobals(n,a,S,C,N){if(C?.length)for(let a of C)n.delete(a);let F=detectedToRegisterPaths(n);for(let n of S)F.add(n);if(emitGiBackedDiagnostic(F,n,N),!C?.length)return{detected:n,injectPath:a};let I=N?filterResolvableRegisterPaths(F,N):F;return{detected:n,injectPath:I.size>0?await writeRegisterInjectFile(I,N)??void 0:void 0}}function detectedToRegisterPaths(n){let a=new Set;for(let S of n){let n=BA[S];n&&a.add(n)}return a}function giNamespacesForRegister(n){for(let a of Object.keys(HA))if(n===a||n.startsWith(a+`/`))return HA[a];return null}function describeGiBackedInjection(n,a){let S=new Set,C=new Set;for(let a of n){let n=giNamespacesForRegister(a);if(n){S.add(a);for(let a of n)C.add(a)}}if(S.size===0)return null;let N=[...a].filter(n=>{let a=BA[n];return!!a&&S.has(a)}).sort();return`[gjsify] note: --globals auto injected GTK/GNOME-backed register(s) — this bundle now requires ${[...C].sort().map(n=>`gi://${n}`).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(n,a,S){if(WA)return;let C=new Set;for(let a of n)giNamespacesForRegister(a)&&(S&&!isRegisterPathResolvable(a,S)||C.add(a));let N=describeGiBackedInjection(C,a);N&&(WA=!0,ke.warn(N))}function isFullConfig(n){return typeof n==`object`&&!!n&&!Array.isArray(n)&&`plugins`in n&&`options`in n}async function detectAutoGlobals(n,a,S,C,N={},F=defaultBundler){let I=N.extraGlobalsList?resolveGlobalsList(N.extraGlobalsList):new Set,H=new Set(N.excludeGlobals??[]),W=N.cwd,K=new Set,q;I.size>0&&(q=await writeRegisterInjectFile(W?filterResolvableRegisterPaths(I,W):I,W)??void 0);let Y=(n.plugins??[]).filter(n=>{let a=n&&typeof n==`object`&&`name`in n?n.name:void 0;return a!==`gjsify`&&a!==`gjsify-orchestrator`});for(let X=1;X<=UA;X++){let te=await S({...a,autoGlobalsInject:q}),ne,re;isFullConfig(te)?(re=te.options,ne=te.plugins):ne=te;let ie=q?appendInjectAsEntry(n.input,q):n.input,ae=n.resolve??re?.resolve,oe=n.external??re?.external,Z=n.transform??re?.transform,se=re?.treeshake,ce=Array.isArray(ne)?ne:[ne],le=await F({rolldownInput:{input:ie,external:oe,resolve:ae,transform:Z,plugins:[...Y,...ce],logLevel:`silent`,...se===void 0?{}:{treeshake:se}},format:n.format??`esm`});if(le.length===0)return{detected:new Set,injectPath:q};let ue=new Set;for(let n=0;n<le.length;n++){let a=le[n]??``;try{for(let n of detectFreeGlobals(a))ue.add(n)}catch(S){if(globalThis.process?.env?.GJSIFY_DEBUG_AUTO_GLOBALS){let S=`/tmp/gjsify-auto-globals-failed-chunk-${n}.mjs`;try{(await Promise.resolve().then(()=>(Zc(),Jc))).writeFileSync(S,a),ke.error(`[gjsify-auto-globals] parse failed on chunk #${n} — wrote ${S} for inspection`)}catch{}}throw S}}if(H.size>0)for(let n of H)ue.delete(n);if(isSubset(ue,K)){if(C){let n=[...K].sort(),a=I.size>0?` (+ ${I.size} extra register module(s))`:``;ke.debug(`[gjsify] --globals auto: converged after ${X-1} iteration(s), ${K.size} global(s)${n.length?`: `+n.join(`, `):``}${a}`)}return applyExcludeGlobals(K,q,I,N.excludeGlobals,W)}let de=N.disableClosureExpansion?ue:expandWithClosure(ue,H);C&&de.size>ue.size&&ke.debug(`[gjsify] --globals auto: closure map expanded ${ue.size} → ${de.size} global(s)`),X>1&&C&&ke.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`."),K=new Set([...K,...de]);let fe=detectedToRegisterPaths(K);for(let n of I)fe.add(n);if(W&&(fe=filterResolvableRegisterPaths(fe,W)),fe.size===0)return{detected:K,injectPath:void 0};if(q=await writeRegisterInjectFile(fe,W)??void 0,C){let n=[...K].sort();ke.debug(`[gjsify] --globals auto: iteration ${X}, ${K.size} global(s)${n.length?`: `+n.join(`, `):``}`)}}return C&&ke.debug(`[gjsify] --globals auto: hit max iterations (${UA}), using last detected set`),applyExcludeGlobals(K,q,I,N.excludeGlobals,W)}async function detectNodeGiGlobals(n,a,S,C=defaultBundler){let N=await S(a),F,I;isFullConfig(N)?(I=N.options,F=N.plugins):F=N;let H=(n.plugins??[]).filter(n=>{let a=n&&typeof n==`object`&&`name`in n?n.name:void 0;return a!==`gjsify`&&a!==`gjsify-orchestrator`}),W=Array.isArray(F)?F:[F],K=I?{...I}:{};delete K.output;let q;try{q=await C({rolldownInput:{...K,input:n.input,external:n.external??K.external,resolve:n.resolve??K.resolve,transform:n.transform??K.transform,plugins:[...H,...W],logLevel:`silent`},format:n.format??`esm`})}catch(n){return ke.warn(`[gjsify] --app node: could not analyse the bundle for GJS ambient globals (${n instanceof Error?n.message:String(n)}); 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 n of q)if(detectGjsAmbientGlobals(n).size>0)return!0;return!1}function appendInjectAsEntry(n,a){return n===void 0?[a]:typeof n==`string`?[n,a]:Array.isArray(n)?[...n,a]:{...n,__gjsify_inject:a}}var defaultBundler,BA,VA,HA,UA,WA,GA=__esmMin(()=>{Ae(),Vb(),Gb(),Fb(),zA(),defaultBundler=async({rolldownInput:n,format:a})=>{let S=await(await import(`rolldown`)).rolldown(n);try{let n=await S.generate({format:a,minify:!1,sourcemap:!1}),C=[];for(let a of n.output)a.type===`chunk`&&C.push(a.code);return C}finally{await S.close()}},BA=Nb,VA=RA,HA=Pb,UA=5,WA=!1}),KA=__esmMin(()=>{Gb(),Vb(),GA()});function findPnpRoot(n){let a=n;for(;;){if(existsSync(ns(a,`.pnp.cjs`)))return a;let n=as(a);if(n===a)return null;a=n}}async function loadPnpApi(){try{let n=await import(`pnpapi`);return n.default??n}catch{return null}}async function pnpPlugin(n={}){let a=n.issuerUrl??import.meta.url;if(!findPnpRoot(process.cwd()))return null;let S=await loadPnpApi();if(S===null)return null;let C=fileURLToPath(a),N=createRequire(C),F=n.relayPackages??[`@gjsify/node-polyfills`,`@gjsify/web-polyfills`],I=[];for(let n of F)try{I.push(N.resolve(`${n}/package.json`))}catch{}return{name:`gjsify-pnp`,resolveId:{order:`pre`,async handler(n,a){if(n.startsWith(`.`)||n.startsWith(`/`))return null;if(n.startsWith(`gi://`))return{id:n,external:!0};if(n.startsWith(`node:`))return await this.resolve(n,a,{skipSelf:!0});if(!a)return null;let N=a.startsWith(`file://`)?fileURLToPath(a):a;try{let a=S.resolveRequest(n,N);return a===null?null:{id:a}}catch(a){if(!isUndeclaredDependency(a))throw a;try{let a=S.resolveRequest(n,C);if(a!==null)return{id:a}}catch(n){if(!isUndeclaredDependency(n))throw n}for(let a of I)try{let C=S.resolveRequest(n,a);if(C!==null)return{id:C}}catch(n){if(!isUndeclaredDependency(n))throw n}return null}}},async load(n){if(!n.includes(`/.yarn/`)&&!n.includes(`.zip/`))return null;try{return{code:await readFile$1(n,`utf8`)}}catch(a){let S=a instanceof Error?a.message:String(a);this.error(`gjsify-pnp: failed to read ${n}: ${S}`)}}}}function isUndeclaredDependency(n){return typeof n==`object`&&!!n&&`pnpCode`in n&&n.pnpCode===`UNDECLARED_DEPENDENCY`}var qA=__esmMin(()=>{Uo(),mn(),ps(),Zc(),kc()});function normalizeBundlerOptions(n){let a=n.bundler??{},S=a;if(typeof a.define==`object`&&a.define!==null){YA||(YA=!0,ke.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:n,...C}=a;S={...C,transform:{...C.transform,define:{...n,...C.transform?.define}}}}if(!n.esbuild)return S;JA||(JA=!0,ke.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(n.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(n){let a={},S={},C={},N={};return n.outfile!==void 0&&(S.file=n.outfile),n.outdir!==void 0&&(S.dir=n.outdir),n.format!==void 0&&(S.format=n.format),n.minify!==void 0&&(S.minify=n.minify),n.sourcemap!==void 0&&(S.sourcemap=n.sourcemap===`inline`?`inline`:!!n.sourcemap),n.banner?.js!==void 0&&(S.banner=n.banner.js),n.target!==void 0&&(C.target=Array.isArray(n.target)?n.target.join(`,`):n.target),n.define!==void 0&&(C.define=n.define),n.mainFields!==void 0&&(N.mainFields=n.mainFields),n.conditions!==void 0&&(N.conditionNames=n.conditions),n.external!==void 0&&(a.external=n.external),n.platform!==void 0&&(a.platform=n.platform),Object.keys(S).length>0&&(a.output=S),Object.keys(C).length>0&&(a.transform=C),Object.keys(N).length>0&&(a.resolve=N),a}function mergeBundlerOptions(n,a){let{input:S,external:C,...N}=a,F={...n,...N};return(n.output||a.output)&&(F.output={...n.output,...a.output}),(n.transform||a.transform)&&(F.transform={...n.transform,...a.transform},(n.transform?.define||a.transform?.define)&&(F.transform.define={...n.transform?.define,...a.transform?.define})),(n.resolve||a.resolve)&&(F.resolve={...n.resolve,...a.resolve}),F}var JA,YA,XA=__esmMin(()=>{Ae(),JA=!1,YA=!1});function inputSourceDirs(n,a){let S=[],push=n=>{typeof n==`string`&&n.length>0&&S.push(n)};typeof n==`string`?push(n):Array.isArray(n)?n.forEach(push):n&&typeof n==`object`&&Object.values(n).forEach(push);let C=$o(a),N=new Set;for(let n of S){let a=n.replace(/\\/g,`/`),S=a.search(/[*?{}[\]()!+@]/),F=S===-1?a:a.slice(0,S);F=S===-1?ss(F)?as(F):F:F.replace(/\/[^/]*$/,``);let I=$o(C,F||`.`);I!==C&&N.add(I)}return[...N]}function isInsideOrEqual(n,a){let S=rs(a,n);return S===``||!S.startsWith(`..`)&&!ts(S)}function isOutdirInsideSource(n,a,S){let C=$o(S,n);return a.some(n=>isInsideOrEqual(C,n))}function libraryOutputLeakError(n){return Error(`gjsify build --library: refusing to write output into "${n}", 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 ZA=__esmMin(()=>{ps()});function detectHtmlEntry(n){if(!n)return null;let isHtml=n=>typeof n==`string`&&/\.html?$/i.test(n);if(typeof n==`string`)return isHtml(n)?n:null;if(Array.isArray(n))return n.length===1&&isHtml(n[0])?n[0]:null;if(typeof n==`object`){let a=Object.values(n);return a.length===1&&isHtml(a[0])?a[0]:null}return null}function parseHtmlEntry(n,a){for(let S of a.matchAll(QA)){let a=S[0],C=$A.exec(a);if(!C)continue;let N=C[1];if(!ej.test(N))return{moduleEntry:ts(N)?N:$o(as(n),N),scriptTag:a,scriptSrc:N}}throw Error(`gjsify build: ${n} 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(n){let{htmlSource:a,scriptTag:S,scriptSrc:C,jsOutPath:N,outHtmlPath:F}=n,I=rs(as(F),N).split(/[\\/]/).join(`/`);I.startsWith(`.`)||(I=`./${I}`);let H=S.replace($A,n=>n.replace(C,I));return a.replace(S,H)}function htmlOutPathFor(n){return $o(as(n),`index.html`)}var QA,$A,ej,tj=__esmMin(()=>{ps(),QA=/<script\b[^>]*\btype\s*=\s*["']module["'][^>]*>(?:<\/script>)?/gi,$A=/\bsrc\s*=\s*["']([^"']+)["']/i,ej=/^(?:https?:)?\/\//i});function isUnsafeDefaultOutput(n){if(/\.[cm]?tsx?$/i.test(n))return!0;let a=n.replace(/\\/g,`/`);return!!/(?:^|\/)src\//.test(a)}async function buildPnpPlugin(){return pnpPlugin({issuerUrl:import.meta.url})}function shortHash(n){let a=5381;for(let S=0;S<n.length;S++)a=(a<<5)+a+n.charCodeAt(S)>>>0;return a.toString(16).padStart(8,`0`)}function isTruthyEnv(n){return n===`1`||n===`true`||n===`yes`}async function newestLockfileMtime(n){let a=0;for(let S of rj)try{let C=await stat$1(ns(n,S));C.mtimeMs>a&&(a=C.mtimeMs)}catch{}return a}async function runOneLibraryBuild(n){let a=await gjsifyPlugin({input:n.userBundler.input,output:n.output,userAliases:n.userAliases},n.pluginOpts);return await runBundle({...mergeBundlerOptions(a.options,n.userBundler),plugins:[...n.pnpPlugins,...a.plugins]})}var nj,rj,ij,aj=__esmMin(()=>{Ae(),Hg(),IA(),zg(),LA(),KA(),qA(),ps(),mn(),kc(),XA(),ZA(),tj(),nj=`#!/usr/bin/env -S gjs -m`,rj=[`gjsify-lock.json`,`package-lock.json`,`yarn.lock`,`pnpm-lock.yaml`],ij=class BuildAction{configData;constructor(n={}){this.configData=n}async buildLibrary(){let{verbose:n,library:a,typescript:S,exclude:C,aliases:N}=this.configData,F=a??{},I=normalizeBundlerOptions(this.configData),H=process.cwd(),W=inputSourceDirs(I.input,H),assertDerivedOutdirSafe=n=>{if(n&&isOutdirInsideSource(n,W,H))throw libraryOutputLeakError(n)},K=F.module?as(F.module):void 0,q=F.main?as(F.main):void 0,Y=F.module?ss(F.module):`.js`,X=F.main?ss(F.main):`.js`,te=K&&q&&K!==q,ne=await buildPnpPlugin(),re=ne?[ne]:[],ie=[];if(te){assertDerivedOutdirSafe(K),assertDerivedOutdirSafe(q);let a=K.includes(`/cjs`)||Y===`.cjs`?`cjs`:`esm`;ie.push(await runOneLibraryBuild({pluginOpts:{debug:n,library:a,exclude:C,reflection:S?.reflection,jsExtension:Y},userBundler:I,output:{dir:K},userAliases:N,pnpPlugins:re}));let F=q.includes(`/cjs`)||X===`.cjs`?`cjs`:`esm`;ie.push(await runOneLibraryBuild({pluginOpts:{debug:n,library:F,exclude:C,reflection:S?.reflection,jsExtension:X},userBundler:I,output:{dir:q},userAliases:N,pnpPlugins:re}))}else{let a=I.output?.dir,H=I.output?.file??F.module??F.main,W=H?ss(H):`.js`,K=a??(H?as(H):void 0);a===void 0&&assertDerivedOutdirSafe(K);let q=I.output?.format??(K?.includes(`/cjs`)||W===`.cjs`?`cjs`:`esm`);ie.push(await runOneLibraryBuild({pluginOpts:{debug:n,library:q,exclude:C,reflection:S?.reflection,jsExtension:W},userBundler:I,output:{dir:K},userAliases:N,pnpPlugins:re}))}return ie}parseGlobalsValue(n){if(n===void 0)return{autoMode:!0,extras:``};if(n===`none`||n===``)return{autoMode:!1,extras:``};let a=n.split(`,`).map(n=>n.trim()).filter(Boolean);return{autoMode:a.includes(`auto`),extras:a.filter(n=>n!==`auto`).join(`,`)}}async resolveGlobalsInject(n,a,S){if(n!==`gjs`||!a)return;let C=resolveGlobalsList(a);if(C.size===0)return;let N=await writeRegisterInjectFile(C,process.cwd());return S&&N&&ke.debug(`[gjsify] globals: injected ${C.size} register module(s) from --globals ${a}`),N??void 0}async applyShebang(n,a,S){if(!a){S&&ke.warn(`[gjsify] --shebang skipped: no single outfile (use --outfile for executables)`);return}let C=n===`node`?fA:nj,N=resolveShebangLine(this.configData.shebang,C)??C,F=await readFile$1(a,`utf-8`);F.startsWith(`#!`)?S&&ke.debug(`[gjsify] --shebang skipped: ${a} already starts with a shebang`):await writeFile$1(a,N+`
744
744
  `+F),await chmod$1(a,493),S&&ke.debug(`[gjsify] --shebang: wrote ${N} + chmod 0o755 to ${a}`)}async applyBrowserHtml(n,a,S){let C=$o(a),N=htmlOutPathFor(C),F=emitBrowserHtml({htmlSource:n.htmlSource,scriptTag:n.scriptTag,scriptSrc:n.scriptSrc,jsOutPath:C,outHtmlPath:N});await mkdir$1(as(N),{recursive:!0}),await writeFile$1(N,F),S&&ke.debug(`[gjsify] --app browser: wrote ${N}`)}async loadPluginViaGjsBundle(n,a,S){let C=await this.bundlePluginForGjs(n,a,S);try{return await import(pathToFileURL(C).href)}catch(n){throw Error(`gjsify config: failed to import the GJS bundle for plugin "${a}" (bundled to ${C}). (${n.message})`)}}async bundlePluginForGjs(n,a,S){let C=process.cwd(),N=ns(C,`node_modules`,`.cache`,`gjsify`,`plugins`),F=ns(N,`${a.replace(/[^a-zA-Z0-9._-]/g,`_`)}-${shortHash(n)}.mjs`);if(!isTruthyEnv(process.env.GJSIFY_NO_PLUGIN_CACHE)&&await this.isPluginBundleFresh(F,n,C))return S&&ke.debug(`[gjsify] plugin "${a}": reusing cached GJS bundle ${F}`),F;S&&ke.debug(`[gjsify] plugin "${a}": bundling for GJS → ${F}`);try{await mkdir$1(N,{recursive:!0}),await new BuildAction({verbose:S,bundler:{input:n,output:{file:F}}}).buildApp(`gjs`,{preserveDefaultExport:!0})}catch(n){throw Error(`gjsify config: failed to bundle plugin "${a}" for GJS (needed because GJS can't import packages that use exports-map subpaths directly; cache dir ${N}). (${n.message})`)}return F}async isPluginBundleFresh(n,a,S){try{let C=await stat$1(n),N=await stat$1(a),F=await newestLockfileMtime(S);return C.mtimeMs>=Math.max(N.mtimeMs,F)}catch{return!1}}async buildApp(n=`gjs`,a={}){let{verbose:S,typescript:C,exclude:N,library:F,aliases:I,excludeGlobals:H}=this.configData,W=normalizeBundlerOptions(this.configData),K=null;if(n===`browser`){let n=detectHtmlEntry(W.input);if(n){let a=await readFile$1(n,`utf-8`),{moduleEntry:S,scriptTag:C,scriptSrc:N}=parseHtmlEntry(n,a);W.input=S,K={htmlSource:a,scriptTag:C,scriptSrc:N}}}let q=W.output?.format??(W.output?.file?.endsWith(`.cjs`)?`cjs`:`esm`),Y=q===`iife`?`esm`:q,X=W.output?.file,te=W.output?.dir;if(!X&&!te&&(F?.main||F?.module)){let n=Y===`cjs`?F.main??F.module:F.module??F.main;if(n&&isUnsafeDefaultOutput(n))throw Error(`gjsify build: refusing to default --outfile to ${n} (would overwrite a TypeScript source file). Pass --outfile/--outdir explicitly, or set "gjsify.bundler.output.file" in package.json.`);X=n}if(K&&!X)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:ne,globals:re}=this.configData,ie=Array.isArray(W.external)?W.external:void 0,ae=typeof W.output?.banner==`string`?W.output.banner:void 0,oe={debug:S,app:n,format:Y,exclude:N,reflection:C?.reflection,consoleShim:ne,...I?{aliases:I}:{},...a.preserveDefaultExport?{preserveDefaultExport:!0}:{}},{autoMode:Z,extras:se}=this.parseGlobalsValue(re),ce=await buildPnpPlugin(),le=ce?[ce]:[],ue=textLoaderPlugin({loaders:this.configData.loaders}),de=ue?[ue]:[];if(W.plugins?.length){let n=await resolveUserPlugins(W.plugins,process.cwd(),isGjs()?{loadModule:(n,a)=>this.loadPluginViaGjsBundle(n,a,S)}:{});de.push(...n)}if(n===`gjs`&&Z){let gjsifyPluginFactory=async n=>{let a=await gjsifyPlugin({input:W.input,output:{file:X,dir:te},userExternal:ie,userBanner:ae,userAliases:I,shebang:this.configData.shebang},n);return{options:a.options,plugins:a.plugins}},{injectPath:n}=await detectAutoGlobals({input:W.input,plugins:[...le,...de],external:W.external,transform:W.transform,format:Y},oe,gjsifyPluginFactory,S,{extraGlobalsList:se,excludeGlobals:H,cwd:process.cwd()},bundleToChunks);oe.autoGlobalsInject=n}else if(n===`node`&&Z){let gjsifyPluginFactory=async n=>{let a=await gjsifyPlugin({input:W.input,output:{file:X,dir:te},userExternal:ie,userBanner:ae,userAliases:I,shebang:this.configData.shebang},n);return{options:a.options,plugins:a.plugins}};await detectNodeGiGlobals({input:W.input,plugins:[...le,...de],external:W.external,transform:W.transform,format:Y},oe,gjsifyPluginFactory,bundleToChunks)&&(oe.nodeGiGlobalsInject=!0)}else se&&(oe.autoGlobalsInject=await this.resolveGlobalsInject(n,se,S));let fe=await gjsifyPlugin({input:W.input,output:{file:X,dir:te},userExternal:ie,userBanner:ae,userAliases:I,shebang:this.configData.shebang},oe),pe={...mergeBundlerOptions(fe.options,W),plugins:[...le,...de,...fe.plugins]};if(a.watch)return await this.runWatchLoop(pe,n,X,S),[];let me=await runBundle(pe);return(n===`gjs`||n===`node`)&&this.configData.shebang&&await this.applyShebang(n,X,S),n===`browser`&&K&&X&&await this.applyBrowserHtml(K,X,S),[me]}async runWatchLoop(n,a,S,C){let N=await runWatch(n),F=new Promise(n=>{N.on(`close`,()=>n())}),I=!1,shutdown=async()=>{if(!I){I=!0,ke.log(`
745
745
  [gjsify build --watch] stopping watcher…`);try{await N.close()}catch(n){ke.error(`[gjsify build --watch] watcher close error:`,n)}}};process.on(`SIGINT`,shutdown),process.on(`SIGTERM`,shutdown),N.on(`event`,async n=>{switch(n.code){case`START`:C&&ke.log(`[gjsify build --watch] rebuild start`);break;case`BUNDLE_START`:ke.log(`[gjsify build --watch] building…`);break;case`BUNDLE_END`:ke.log(`[gjsify build --watch] built in ${n.duration}ms`);try{(a===`gjs`||a===`node`)&&this.configData.shebang&&await this.applyShebang(a,S,C)}finally{await n.result.close()}break;case`END`:ke.log(`[gjsify build --watch] waiting for changes…`);break;case`ERROR`:ke.error(`[gjsify build --watch] build failed:`,n.error?.message??n.error),C&&n.error?.stack&&ke.error(n.error.stack);try{await n.result.close()}catch{}break}}),C&&N.on(`change`,(n,a)=>{ke.log(`[gjsify build --watch] ${a.event}: ${n}`)}),await F}async start(n={app:`gjs`}){if(n.library){if(n.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(n.app,{watch:n.watch})}}}),oj,sj=__esmMin(()=>{Fg(),aj(),oj={command:`build [entryPoints..]`,description:`Build and bundle your Gjs project`,builder:n=>n.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`,normalize:!0,defaultDescription:`src/index.ts (fallback)`,coerce:n=>[...new Set(n)]}).option(`exclude`,{description:`An array of glob patterns to exclude entry-points and aliases`,array:!0,type:`string`,normalize:!0,default:[]}).option(`verbose`,{description:`Switch on the verbose mode`,type:`boolean`,normalize:!0,default:!1}).option(`app`,{description:`Use this if you want to build an application, the platform node is usually only used for tests`,type:`string`,choices:[`gjs`,`node`,`browser`,`nativescript`],normalize:!0,default:`gjs`}).option(`format`,{description:`Override the default output format`,type:`string`,choices:[`iife`,`esm`,`cjs`],normalize:!0}).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`,normalize:!0,defaultDescription:`true`}).option(`library`,{description:`Use this if you want to build a library for Gjsify`,type:`boolean`,normalize:!0,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`,normalize:!0,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`],normalize:!0,default:`warning`}).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`,normalize:!0,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`,normalize:!0}).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`,normalize:!0}).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:n=>n.flatMap(n=>n.split(`,`).map(n=>n.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:n=>n.flatMap(n=>n.split(`,`).map(n=>n.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`,normalize:!0}).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`,normalize:!0,default:!1}),handler:async n=>{await new ij(await new Config().forBuild(n)).start({library:n.library,app:n.app,watch:n.watch})}}});function nodeArchToLinuxArch(n){return{x64:`x86_64`,arm64:`aarch64`,arm:`armv7`,ia32:`i686`}[n]??n}function readPackageJson$3(n){try{return JSON.parse(readFileSync(n,`utf-8`))}catch{return null}}function scanNodeModules(n,a){let S=[];if(!existsSync(n))return S;let C;try{C=readdirSync(n)}catch{return S}for(let N of C)if(!N.startsWith(`.`))if(N.startsWith(`@`)){let C=ns(n,N),F;try{F=readdirSync(C)}catch{continue}for(let n of F){let F=checkPackage(ns(C,n),`${N}/${n}`,a);F&&S.push(F)}}else{let C=checkPackage(ns(n,N),N,a);C&&S.push(C)}return S}function checkPackage(n,a,S){let C=readPackageJson$3(ns(n,`package.json`));if(!C)return null;let N=C.gjsify;if(!N||typeof N!=`object`)return null;let F=N.prebuilds;if(typeof F!=`string`)return null;let I=ns(n,F,`linux-${S}`);return existsSync(I)?{name:a,prebuildsDir:I}:null}function detectNativePackages(n){let a=nodeArchToLinuxArch(process.arch),S=[],C=new Set,N=$o(n);for(;;){let n=ns(N,`node_modules`);if(existsSync(n))for(let N of scanNodeModules(n,a))C.has(N.name)||(C.add(N.name),S.push(N));let F=$o(N,`..`);if(F===N)break;N=F}return S}function buildNativeEnv(n){let a=n.map(n=>n.prebuildsDir),S=process.env.LD_LIBRARY_PATH??``,C=process.env.GI_TYPELIB_PATH??``;return{LD_LIBRARY_PATH:[...a,...S?[S]:[]].join(`:`),GI_TYPELIB_PATH:[...a,...C?[C]:[]].join(`:`)}}var cj=__esmMin(()=>{Zc(),ps(),__name$1(readPackageJson$3,`readPackageJson`)}),lj=__exportAll$3({computeNativeEnvForBundle:()=>computeNativeEnvForBundle,runGjsBundle:()=>runGjsBundle});function computeNativeEnvForBundle(n,a=process.cwd()){let S=$o(n),C=detectNativePackages(a),N=detectNativePackages(as(S)),F=new Set(C.map(n=>n.name)),I=buildNativeEnv([...C,...N.filter(n=>!F.has(n.name))]);return{env:I,envPrefix:Object.entries(I).filter(([,n])=>n!==void 0&&n!==``).map(([n,a])=>`${n}=${a}`).join(` `)}}async function runGjsBundle(n,a=[],S={}){let{env:C,envPrefix:N}=computeNativeEnvForBundle(n),F={...process.env,...C},I=[`-m`,n,...a],H=[`gjs`,...I.map(n=>n.includes(` `)?`"${n}"`:n)].join(` `);ke.error(`$ ${N?`${N} `:``}${H}`);let W=spawn(`gjs`,I,{env:F,stdio:`inherit`});await new Promise((n,a)=>{W.on(`close`,S=>{S===0?n():a(Error(`gjs exited with code ${S}`))}),W.on(`error`,a)}).catch(n=>{ke.error(n.message),process.exit(1)}),S.exitOnSuccess&&process.exit(0)}var uj=__esmMin(()=>{Ae(),cC(),ps(),cj()});async function buildTestBundle(n,a,S,C){let N=await new Config().forBuild({entryPoints:[n],outfile:a,app:S,verbose:C??!1,logLevel:`warning`,exclude:[]});N.library={...N.library},N.bundler={...N.bundler,input:[n],output:{...N.bundler?.output,file:a}},await new ij(N).start({app:S,library:!1})}async function runTestBundle(n,a){if(a===`gjs`){await runGjsBundle(n);return}await new Promise((a,S)=>{let C=spawn(`node`,[n],{stdio:`inherit`});C.on(`error`,S),C.on(`exit`,n=>{n===0?a():S(Error(`node exited with code ${n}`))})})}function isFresh(n,a){if(!existsSync(n))return!1;let S=statSync(n).mtimeMs,C=as(a);try{return S>=newestMtimeUnder(existsSync(C)?C:a)}catch{return!1}}function newestMtimeUnder(n){let a=statSync(n);if(a.isFile())return a.mtimeMs;let S=a.mtimeMs;for(let a of readdirSync(n,{withFileTypes:!0})){if(a.name===`node_modules`||a.name===`dist`||a.name===`lib`||a.name.startsWith(`.`))continue;let C=newestMtimeUnder(ns(n,a.name));C>S&&(S=C)}return S}var dj,fj=__esmMin(()=>{Ae(),Zc(),ps(),cC(),Fg(),aj(),uj(),dj={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:n=>n.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 n=>{let a=process.cwd(),S=(await new Config().forBuild({}).catch(()=>({}))).test??{},C=$o(a,n.entry??S.entry??`src/test.mts`),N=$o(a,n.outdir??S.outdir??`dist`);existsSync(C)||(ke.error(`[gjsify test] no test entry at ${rs(a,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=n.runtime===`gjs`?[`gjs`]:n.runtime===`node`?[`node`]:S.runtimes&&S.runtimes.length>0?S.runtimes:[`gjs`,`node`],I=[];for(let S of F){let F=ns(N,`test.${S}.mjs`);if(n.build!==!1)if(n.rebuild||!isFresh(F,C)){let N=Date.now();n.verbose&&ke.log(`[gjsify test] building → ${rs(a,F)} (—app ${S})`);try{await buildTestBundle(C,F,S,n.verbose),n.verbose&&ke.log(`[gjsify test] built ${S} in ${Date.now()-N}ms`)}catch(n){ke.error(`[gjsify test] build failed for ${S}:`,n.message),I.push({runtime:S,ok:!1,durationMs:0,error:`build failed`});continue}}else n.verbose&&ke.log(`[gjsify test] ${S}: bundle is up-to-date — skipping build (use --rebuild to force)`);else if(!existsSync(F)){ke.error(`[gjsify test] --no-build but ${rs(a,F)} doesn't exist. Build first or drop --no-build.`),I.push({runtime:S,ok:!1,durationMs:0,error:`no bundle`});continue}let H=Date.now();try{await runTestBundle(F,S),I.push({runtime:S,ok:!0,durationMs:Date.now()-H})}catch(n){I.push({runtime:S,ok:!1,durationMs:Date.now()-H,error:n.message})}}let H=I.map(n=>`${n.ok?`✅`:`❌`} ${n.runtime} (${n.durationMs}ms)${n.error?` — ${n.error}`:``}`).join(` `);ke.log(`[gjsify test] ${H}`),I.some(n=>!n.ok)&&process.exit(1),process.exit(0)}}});function readPackageJson$2(n){if(!existsSync(n))return null;let a=readFileSync(n,`utf-8`);try{return JSON.parse(a)}catch(a){throw Error(`gjsify install: ${n} is not valid JSON: ${a.message}`)}}function writePackageJson(n,a){let S=sortKnownDepFields(a);writeFileSync(n,JSON.stringify(S,null,2)+`
746
- `,`utf-8`)}function parseSpec$2(n){if(n.startsWith(`@`)){let a=n.indexOf(`/`);if(a===-1)return{name:n};let S=n.indexOf(`@`,a+1);return S===-1?{name:n}:{name:n.slice(0,S),range:n.slice(S+1)}}let a=n.indexOf(`@`);return a===-1?{name:n}:{name:n.slice(0,a),range:n.slice(a+1)}}function projectSpecsFromPackageJson(n){let a=[];for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n[S];if(C)for(let[n,S]of Object.entries(C))typeof S==`string`&&(/^(workspace|link|file|portal|git\+|https?):/.test(S)||a.push(`${n}@${S}`))}return a}function addDependencyEntry(n,a,S,C){n[C]===void 0&&(n[C]={}),n[C][a]=S}function defaultRangeFromVersion(n){return`^${n}`}function sortKnownDepFields(n){let a={...n};for(let n of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let S=a[n];S&&(a[n]=Object.fromEntries(Object.entries(S).sort(([n],[a])=>n<a?-1:+(n>a))))}return a}var pj=__esmMin(()=>{Zc(),__name$1(readPackageJson$2,`readPackageJson`),__name$1(parseSpec$2,`parseSpec`)});function looksLikeFile(n){if(n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`/`)||n.includes(`/`)||n.includes(`\\`)||/\.(c?js|mjs|cjs|gjs)$/.test(n))return!0;try{return statSync(n).isFile()}catch{return!1}}async function runScript(n,a){let S=process.cwd(),C=ns(S,`package.json`),N=readPackageJson$2(C);N||(ke.error(`gjsify run: no package.json in ${S}`),process.exit(1));let F=N.scripts??{},I=F[n];if(typeof I!=`string`){let a=Object.keys(F).join(`, `)||`<none>`;ke.error(`gjsify run: no script "${n}" in ${C} (available: ${a})`),process.exit(1)}let H=findWorkspaceRoot(S),W=[ns(S,`node_modules`,`.bin`)];H&&H!==S&&W.push(ns(H,`node_modules`,`.bin`)),process.env.GJSIFY_SHIM_DIR&&W.unshift(process.env.GJSIFY_SHIM_DIR);let K=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`},q={...process.env,...K,PATH:[...W,process.env.PATH??``].filter(Boolean).join(ds),npm_lifecycle_event:n,npm_package_name:N.name??``,npm_package_version:N.version??``},Y=isGjs()?gjsifyInProcessArgv(I,a):null;if(Y){process.env.PATH=q.PATH,process.env.npm_lifecycle_event=q.npm_lifecycle_event,process.env.npm_package_name=q.npm_package_name,process.env.npm_package_version=q.npm_package_version,q.FORCE_COLOR!==void 0&&(process.env.FORCE_COLOR=q.FORCE_COLOR);try{let{runCli:n}=await Promise.resolve().then(()=>(eF(),$P));await n(Y)}catch(n){ke.error(n.message),process.exit(1)}process.exit(process.exitCode==null?0:Number(process.exitCode))}let X=a.length>0?`${I} ${a.map(shellEscape).join(` `)}`:I;await new Promise((a,C)=>{let N=spawn(X,[],{cwd:S,env:q,stdio:`inherit`,shell:!0});N.on(`close`,S=>{S===0?a():C(Error(`script "${n}" exited with code ${S}`))}),N.on(`error`,C)}).catch(n=>{ke.error(n.message),process.exit(1)}),process.exit(0)}function shellEscape(n){return/^[a-zA-Z0-9_\-./=:@,]+$/.test(n)?n:`'${n.replace(/'/g,`'\\''`)}'`}function gjsifyInProcessArgv(n,a){let S=tokenizeSimpleCommand(n);return!S||S.length<2||S[0]!==`gjsify`?null:[...S.slice(1),...a]}function tokenizeSimpleCommand(n){let a=[],S=``,C=!1,N=null;for(let F=0;F<n.length;F++){let I=n[F];if(N===`'`){I===`'`?N=null:S+=I;continue}if(N===`"`){if(I===`"`)N=null;else if(I===`\\`&&(n[F+1]===`"`||n[F+1]===`\\`))S+=n[++F];else if(I===`$`||I==="`")return null;else S+=I;continue}if(I===`'`||I===`"`){N=I,C=!0;continue}if(I===` `||I===` `){C&&=(a.push(S),S=``,!1);continue}if(`|&;<>\`$()\\
746
+ `,`utf-8`)}function parseSpec$2(n){if(n.startsWith(`@`)){let a=n.indexOf(`/`);if(a===-1)return{name:n};let S=n.indexOf(`@`,a+1);return S===-1?{name:n}:{name:n.slice(0,S),range:n.slice(S+1)}}let a=n.indexOf(`@`);return a===-1?{name:n}:{name:n.slice(0,a),range:n.slice(a+1)}}function projectSpecsFromPackageJson(n){let a=[];for(let S of[`dependencies`,`devDependencies`,`optionalDependencies`]){let C=n[S];if(C)for(let[n,S]of Object.entries(C))typeof S==`string`&&(/^(workspace|link|file|portal|git\+|https?):/.test(S)||a.push(`${n}@${S}`))}return a}function addDependencyEntry(n,a,S,C){n[C]===void 0&&(n[C]={}),n[C][a]=S}function defaultRangeFromVersion(n){return`^${n}`}function sortKnownDepFields(n){let a={...n};for(let n of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let S=a[n];S&&(a[n]=Object.fromEntries(Object.entries(S).sort(([n],[a])=>n<a?-1:+(n>a))))}return a}var pj=__esmMin(()=>{Zc(),__name$1(readPackageJson$2,`readPackageJson`),__name$1(parseSpec$2,`parseSpec`)});function looksLikeFile(n){if(n.startsWith(`./`)||n.startsWith(`../`)||n.startsWith(`/`)||n.includes(`/`)||n.includes(`\\`)||/\.(c?js|mjs|cjs|gjs)$/.test(n))return!0;try{return statSync(n).isFile()}catch{return!1}}async function runScript(n,a){let S=process.cwd(),C=ns(S,`package.json`),N=readPackageJson$2(C);N||(ke.error(`gjsify run: no package.json in ${S}`),process.exit(1));let F=N.scripts??{},I=F[n];if(typeof I!=`string`){let a=Object.keys(F).join(`, `)||`<none>`;ke.error(`gjsify run: no script "${n}" in ${C} (available: ${a})`),process.exit(1)}let H=findWorkspaceRoot(S),W=[ns(S,`node_modules`,`.bin`)];H&&H!==S&&W.push(ns(H,`node_modules`,`.bin`)),process.env.GJSIFY_SHIM_DIR&&W.unshift(process.env.GJSIFY_SHIM_DIR);let K=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`},q={...process.env,...K,PATH:[...W,process.env.PATH??``].filter(Boolean).join(ds),npm_lifecycle_event:n,npm_package_name:N.name??``,npm_package_version:N.version??``},Y=isGjs()?gjsifyInProcessArgv(I,a):null;if(Y){process.env.PATH=q.PATH,process.env.npm_lifecycle_event=q.npm_lifecycle_event,process.env.npm_package_name=q.npm_package_name,process.env.npm_package_version=q.npm_package_version,q.FORCE_COLOR!==void 0&&(process.env.FORCE_COLOR=q.FORCE_COLOR);try{let{runCli:n}=await Promise.resolve().then(()=>(eF(),$P));await n(Y)}catch(n){ke.error(n.message),process.exit(1)}process.exit(process.exitCode==null?0:Number(process.exitCode));return}let X=a.length>0?`${I} ${a.map(shellEscape).join(` `)}`:I;await new Promise((a,C)=>{let N=spawn(X,[],{cwd:S,env:q,stdio:`inherit`,shell:!0});N.on(`close`,S=>{S===0?a():C(Error(`script "${n}" exited with code ${S}`))}),N.on(`error`,C)}).catch(n=>{ke.error(n.message),process.exit(1)}),process.exit(0)}function shellEscape(n){return/^[a-zA-Z0-9_\-./=:@,]+$/.test(n)?n:`'${n.replace(/'/g,`'\\''`)}'`}function gjsifyInProcessArgv(n,a){let S=tokenizeSimpleCommand(n);return!S||S.length<2||S[0]!==`gjsify`?null:[...S.slice(1),...a]}function tokenizeSimpleCommand(n){let a=[],S=``,C=!1,N=null;for(let F=0;F<n.length;F++){let I=n[F];if(N===`'`){I===`'`?N=null:S+=I;continue}if(N===`"`){if(I===`"`)N=null;else if(I===`\\`&&(n[F+1]===`"`||n[F+1]===`\\`))S+=n[++F];else if(I===`$`||I==="`")return null;else S+=I;continue}if(I===`'`||I===`"`){N=I,C=!0;continue}if(I===` `||I===` `){C&&=(a.push(S),S=``,!1);continue}if(`|&;<>\`$()\\
747
747
  \r*?{}[]~#!`.includes(I))return null;S+=I,C=!0}return N?null:(C&&a.push(S),a)}var mj,hj=__esmMin(()=>{Ae(),Zc(),ps(),cC(),uj(),pj(),Lg(),zg(),mj={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:n=>n.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:[]}).parserConfiguration({"populate--":!0,"unknown-options-as-args":!0}),handler:async n=>{let a=n.target,S=n.args??[],C=(n[`--`]??[]).filter(n=>typeof n==`string`),N=[...S,...C],F=readPackageJson$2(ns(process.cwd(),`package.json`));if(!(F?.scripts&&typeof F.scripts[a]==`string`)&&looksLikeFile(a)){await runGjsBundle($o(a),N,{exitOnSuccess:!0});return}await runScript(a,N)}}}),gj,_j=__esmMin(()=>{Ae(),ps(),cj(),gj={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:n=>n.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 n=>{let a=process.cwd(),S=n.file?$o(n.file):null,C=detectNativePackages(a),{LD_LIBRARY_PATH:N,GI_TYPELIB_PATH:F}=buildNativeEnv(C);if(n.export){ke.log(`export LD_LIBRARY_PATH="${N}"`),ke.log(`export GI_TYPELIB_PATH="${F}"`);return}if(C.length===0){ke.log(`No native gjsify packages detected in node_modules.`),ke.log(`Native packages declare "gjsify": { "prebuilds": "<dir>" } in their package.json.`);return}ke.log(`Native packages detected:`);for(let n of C)ke.log(` ${n.name} → ${n.prebuildsDir}`);ke.log(``),ke.log(`To run your app directly with gjs, set:`),ke.log(` export LD_LIBRARY_PATH="${N}"`),ke.log(` export GI_TYPELIB_PATH="${F}"`),S?ke.log(` gjs -m ${S}`):ke.log(` gjs -m <your-bundle.js>`),ke.log(``),ke.log(`Or use gjsify run to handle this automatically:`),S?ke.log(` gjsify run ${n.file}`):ke.log(` gjsify run <your-bundle.js>`)}}});function tryExecFile(n,a){try{return execFileSync(n,a,{encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim()}catch{return null}}function checkBinary(n,a,S,C,N,F,I){let H=tryExecFile(S,C);return H===null?{id:n,name:a,found:!1,severity:N,requiredBy:I}:{id:n,name:a,found:!0,version:F?F(H):H.split(`
748
748
  `)[0]??H,severity:N,requiredBy:I}}function checkPkgConfig(n,a,S,C,N){let F=tryExecFile(`pkg-config`,[`--modversion`,S]);return F===null?{id:n,name:a,found:!1,severity:C,requiredBy:N}:{id:n,name:a,found:!0,version:F.split(`
749
749
  `)[0],severity:C,requiredBy:N}}function checkNpmPackage(n,a,S,C,N,F){try{return createRequire(pathToFileURL(ns(C,`_check_.js`)).href).resolve(S),{id:n,name:a,found:!0,severity:N,requiredBy:F}}catch{}try{return createRequire(import.meta.url).resolve(S),{id:n,name:a,found:!0,severity:N,requiredBy:F}}catch{return{id:n,name:a,found:!1,severity:N,requiredBy:F}}}function detectPackageManager$2(){for(let n of[`apt`,`dnf`,`pacman`,`zypper`,`apk`])if(tryExecFile(`which`,[n])!==null)return n;return`unknown`}function findProjectRoot(n){let a=$o(n);for(;;){if(existsSync(ns(a,`package.json`)))return a;let n=$o(a,`..`);if(n===a)return null;a=n}}function discoverGjsifyPackages(n){let a=findProjectRoot(n);if(!a)return null;let S=ns(a,`node_modules`,`@gjsify`);if(!existsSync(S))return new Set;let C=ns(a,`package.json`),N={};try{N=JSON.parse(readFileSync(C,`utf-8`))}catch{}let F={...N.dependencies,...N.devDependencies},I=new Set;try{for(let n of readdirSync(S,{withFileTypes:!0}))(n.isDirectory()||n.isSymbolicLink())&&I.add(`@gjsify/${n.name}`)}catch{}for(let n of Object.keys(F))n.startsWith(`@gjsify/`)&&I.add(n);return I}function computeNeededOptionalDeps(n){let a=discoverGjsifyPackages(n);if(a===null)return null;let S=new Set;for(let n of a){let a=yj[n];if(a)for(let n of a)S.add(n)}return S}function runAllChecks(n){let a=computeNeededOptionalDeps(n);return[...runMinimalChecks(),...runRequiredChecks(n),...runOptionalChecks(a,n)]}function runMinimalChecks(){let n=[];return n.push({id:`nodejs`,name:`Node.js`,found:!0,version:process.version,severity:`required`}),n.push(checkBinary(`gjs`,`GJS`,`gjs`,[`--version`],`required`,n=>n.replace(/^GJS\s+/i,``).split(`
@@ -188,6 +188,15 @@ async function runScript(script, extraArgs) {
188
188
  // (e.g. a failing check that sets the code instead of exiting) —
189
189
  // a bare exit(0) here masked such failures as success.
190
190
  process.exit(process.exitCode != null ? Number(process.exitCode) : 0);
191
+ // `process.exit()` under GJS is NOT synchronous — with the GLib main
192
+ // loop armed (`ensureMainLoop`, e.g. by a bundle the in-process dispatch
193
+ // just ran) it defers the actual teardown, so execution CONTINUES past
194
+ // the call. Without this `return` the function falls through to the
195
+ // shell-spawn fallback below and runs the SAME command a SECOND time
196
+ // (the double-execution bug). Mirrors the file-mode path's `return`
197
+ // after `runGjsBundle`. Keep both — the return is the real guard, the
198
+ // exit sets the status code for when the loop finally unwinds.
199
+ return;
191
200
  }
192
201
  const fullCmd = extraArgs.length > 0 ? `${literal} ${extraArgs.map(shellEscape).join(' ')}` : literal;
193
202
  // ensureMainLoop() (called inside spawn) keeps GJS alive after the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/cli",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "description": "CLI for Gjsify",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -122,19 +122,19 @@
122
122
  "cli"
123
123
  ],
124
124
  "dependencies": {
125
- "@gjsify/buffer": "^0.16.2",
126
- "@gjsify/create-app": "^0.16.2",
127
- "@gjsify/node-globals": "^0.16.2",
128
- "@gjsify/node-polyfills": "^0.16.2",
129
- "@gjsify/npm-registry": "^0.16.2",
130
- "@gjsify/resolve-npm": "^0.16.2",
131
- "@gjsify/rolldown-plugin-gjsify": "^0.16.2",
132
- "@gjsify/rolldown-plugin-pnp": "^0.16.2",
133
- "@gjsify/semver": "^0.16.2",
134
- "@gjsify/tar": "^0.16.2",
135
- "@gjsify/tsc": "^0.16.2",
136
- "@gjsify/web-polyfills": "^0.16.2",
137
- "@gjsify/workspace": "^0.16.2",
125
+ "@gjsify/buffer": "^0.16.3",
126
+ "@gjsify/create-app": "^0.16.3",
127
+ "@gjsify/node-globals": "^0.16.3",
128
+ "@gjsify/node-polyfills": "^0.16.3",
129
+ "@gjsify/npm-registry": "^0.16.3",
130
+ "@gjsify/resolve-npm": "^0.16.3",
131
+ "@gjsify/rolldown-plugin-gjsify": "^0.16.3",
132
+ "@gjsify/rolldown-plugin-pnp": "^0.16.3",
133
+ "@gjsify/semver": "^0.16.3",
134
+ "@gjsify/tar": "^0.16.3",
135
+ "@gjsify/tsc": "^0.16.3",
136
+ "@gjsify/web-polyfills": "^0.16.3",
137
+ "@gjsify/workspace": "^0.16.3",
138
138
  "cosmiconfig": "^9.0.2",
139
139
  "get-tsconfig": "^4.14.0",
140
140
  "pkg-types": "^2.3.1",
@@ -142,13 +142,13 @@
142
142
  "yargs": "^18.0.0"
143
143
  },
144
144
  "devDependencies": {
145
- "@gjsify/unit": "^0.16.2",
145
+ "@gjsify/unit": "^0.16.3",
146
146
  "@types/yargs": "^17.0.35",
147
147
  "typescript": "^6.0.3"
148
148
  },
149
149
  "peerDependencies": {
150
- "@gjsify/oxfmt-native": "^0.16.2",
151
- "@gjsify/rolldown-native": "^0.16.2"
150
+ "@gjsify/oxfmt-native": "^0.16.3",
151
+ "@gjsify/rolldown-native": "^0.16.3"
152
152
  },
153
153
  "peerDependenciesMeta": {
154
154
  "@gjsify/oxfmt-native": {