(()=>{"use strict";var e={417:e=>{e.exports=require("crypto")},669:e=>{e.exports=require("util")},549:e=>{e.exports=require("vscode")}},t={};function s(i){var r=t[i];if(void 0!==r)return r.exports;var n=t[i]={exports:{}};return e[i](n,n.exports,s),n.exports}var i={};(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.activate=void 0;const t=s(549),r=s(669),n=s(417);class o{constructor(){this.a=!1}get hasFired(){return this.a}fire(){this.a=!0}}class a extends t.Disposable{static start(e){if(e.configuration.serverReadyAction){let t=a.a.get(e);return t||(t=new a(e),a.a.set(e,t)),t}}static stop(e){const t=a.a.get(e);t&&(a.a.delete(e),t.dispose())}static rememberShellPid(e,t){const s=a.a.get(e);s&&(s.f=t)}static async startListeningTerminalData(){this.b||(this.b=t.window.onDidWriteTerminalData((async e=>{const t=await e.terminal.processId;for(const[,s]of this.a)if(s.f===t)return void s.detectPattern(e.data);for(const[,t]of this.a)if(t.detectPattern(e.data))return})))}constructor(e){super((()=>this.k())),this.j=e,this.h=[],this.i=new Set([]),e.parentSession?this.c=a.start(e.parentSession)?.c??new o:this.c=new o,this.g=new RegExp(e.configuration.serverReadyAction.pattern||"listening on.* (https?://\\S+|[0-9]+)","i")}k(){this.h.forEach((e=>e.dispose())),this.h=[]}dispose(){return this.i.forEach((e=>e.dispose())),super.dispose()}detectPattern(e){if(!this.c.hasFired){const t=this.g.exec(e);if(t&&t.length>=1)return this.l(this.j,t.length>1?t[1]:""),this.c.fire(),this.k(),!0}return!1}l(e,s){const i=e.configuration.serverReadyAction;let n;if(""===s){const e=i.uriFormat||"";if(e.indexOf("%s")>=0){const s=t.l10n.t("Format uri ('{0}') uses a substitution placeholder but pattern did not capture anything.",e);return void t.window.showErrorMessage(s,{modal:!0}).then((e=>{}))}n=e}else{const e=i.uriFormat||(/^[0-9]+$/.test(s)?"http://localhost:%s":"%s");if(2!==e.split("%s").length){const s=t.l10n.t("Format uri ('{0}') must contain exactly one substitution placeholder.",e);return void t.window.showErrorMessage(s,{modal:!0}).then((e=>{}))}n=r.format(e,s)}this.n(e,n)}async n(e,s){const i=e.configuration.serverReadyAction;switch(i.action||"openExternally"){case"openExternally":await t.env.openExternal(t.Uri.parse(s));break;case"debugWithChrome":await this.o("pwa-chrome",e,s);break;case"debugWithEdge":await this.o("pwa-msedge",e,s);break;case"startDebugging":await this.q(e,i.name||"unspecified")}}async o(e,s,i){if(!s.configuration.serverReadyAction.killOnServerStop)return void await this.p(e,s,i);const r=(0,n.randomUUID)(),o=new t.CancellationTokenSource,a=this.r((e=>e.configuration._debugServerReadySessionId===r),o.token);if(!await this.p(e,s,i,r))return o.cancel(),void o.dispose();const d=await a;if(o.dispose(),!d)return;const c=t.debug.onDidTerminateDebugSession((async e=>{e===s&&(c.dispose(),this.i.delete(c),await t.debug.stopDebugging(d))}));this.i.add(c)}p(e,s,i,r){return t.debug.startDebugging(s.workspaceFolder,{type:e,name:"Browser Debug",request:"launch",url:i,webRoot:s.configuration.serverReadyAction.webRoot||"${workspaceFolder}",_debugServerReadySessionId:r})}async q(e,s){if(!e.configuration.serverReadyAction.killOnServerStop)return void await t.debug.startDebugging(e.workspaceFolder,s);const i=new t.CancellationTokenSource,r=this.r((e=>e.name===s),i.token);if(!await t.debug.startDebugging(e.workspaceFolder,s))return i.cancel(),void i.dispose();const n=await r;if(i.dispose(),!n)return;const o=t.debug.onDidTerminateDebugSession((async s=>{s===e&&(o.dispose(),this.i.delete(o),await t.debug.stopDebugging(n))}));this.i.add(o)}r(e,s){return new Promise((i=>{const r=e=>{o.dispose(),n.dispose(),this.i.delete(o),this.i.delete(n),i(e)},n=s.onCancellationRequested(r),o=t.debug.onDidStartDebugSession((t=>{e(t)&&r(t)}));this.i.add(o),this.i.add(n)}))}}a.a=new Map,e.activate=function(e){e.subscriptions.push(t.debug.onDidChangeActiveDebugSession((e=>{e&&e.configuration.serverReadyAction&&a.start(e)&&a.startListeningTerminalData()}))),e.subscriptions.push(t.debug.onDidTerminateDebugSession((e=>{a.stop(e)})));const s=new Set;e.subscriptions.push(t.debug.registerDebugConfigurationProvider("*",{resolveDebugConfigurationWithSubstitutedVariables:(i,r)=>(r.type&&r.serverReadyAction&&(s.has(r.type)||(s.add(r.type),function(e,s){e.subscriptions.push(t.debug.registerDebugAdapterTrackerFactory(s,{createDebugAdapterTracker(e){const t=a.start(e);if(t){let s;return{onDidSendMessage:e=>{if("event"===e.type&&"output"===e.event&&e.body)switch(e.body.category){case"console":case"stderr":case"stdout":e.body.output&&t.detectPattern(e.body.output)}"request"===e.type&&"runInTerminal"===e.command&&e.arguments&&"integrated"===e.arguments.kind&&(s=e.seq)},onWillReceiveMessage:t=>{s&&"response"===t.type&&"runInTerminal"===t.command&&t.body&&s===t.request_seq&&(s=void 0,a.rememberShellPid(e,t.body.shellProcessId))}}}}}))}(e,r.type))),r)}))}})();var r=exports;for(var n in i)r[n]=i[n];i.__esModule&&Object.defineProperty(r,"__esModule",{value:!0})})();
//# sourceMappingURL=https://ticino.blob.core.windows.net/sourcemaps/97dec172d3256f8ca4bfb2143f3f76b503ca0534/extensions/debug-server-ready/dist/extension.js.map