"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("@php-wasm/node"),v=require("@php-wasm/progress"),r=require("@php-wasm/universal"),A=require("@php-wasm/util"),M=require("@wp-playground/common"),F=require("@wp-playground/wordpress"),D=require("tls"),E=require("wasm-feature-detect"),h=require("worker_threads"),P=require("./mounts-BJFrPHGW.cjs");function H(c,e,...s){console.log(performance.now().toFixed(6).padStart(15,"0"),c.toString().padStart(16,"0"),A.sprintf(e,...s))}class m extends r.PHPWorker{constructor(e){super(void 0,e),this.booted=!1}async useFileLockManager(e){await E.jspi()?this.fileLockManager=r.consumeAPI(e):this.fileLockManager=await r.consumeAPISync(e)}async bootAsPrimaryWorker({absoluteUrl:e,mountsBeforeWpInstall:s,mountsAfterWpInstall:w,phpVersion:y=M.RecommendedPHPVersion,wordPressZip:l,sqliteIntegrationPluginZip:d,firstProcessId:n,processIdSpaceLength:g,dataSqlPath:f,followSymlinks:b,trace:k,internalCookieStore:q,withXdebug:W}){if(this.booted)throw new Error("Playground already booted");this.booted=!0;let o=n;const _=n+g-1;try{const t={WP_DEBUG:!0,WP_DEBUG_LOG:!0,WP_DEBUG_DISPLAY:!1},u=await F.bootWordPress({siteUrl:e,createPhpRuntime:async()=>{const i=o;return o<_?o++:o=n,await S.loadNodeRuntime(y,{emscriptenOptions:{fileLockManager:this.fileLockManager,processId:i,trace:k?H:void 0},followSymlinks:b,withXdebug:W})},wordPressZip:l!==void 0?new File([l],"wordpress.zip"):void 0,sqliteIntegrationPluginZip:d!==void 0?new File([d],"sqlite-integration-plugin.zip"):void 0,sapiName:"cli",createFiles:{"/internal/shared/ca-bundle.crt":D.rootCertificates.join(`
`)},constants:t,phpIniEntries:{"openssl.cafile":"/internal/shared/ca-bundle.crt",allow_url_fopen:"1",disable_functions:""},hooks:{async beforeWordPressFiles(i){P.mountResources(i,s)}},cookieStore:q?void 0:!1,dataSqlPath:f,spawnHandler:r.sandboxedSpawnHandlerFactory});this.__internal_setRequestHandler(u);const p=await u.getPrimaryPhp();await this.setPrimaryPHP(p),P.mountResources(p,w),I()}catch(t){throw L(t),t}}async bootAsSecondaryWorker(e){return this.bootAsPrimaryWorker(e)}async dispose(){await this[Symbol.asyncDispose]()}}const a=new h.MessageChannel,[I,L]=r.exposeAPI(new m(new v.EmscriptenDownloadMonitor),void 0,a.port1);h.parentPort.postMessage({command:"worker-script-initialized",phpPort:a.port2},[a.port2]);exports.PlaygroundCliBlueprintV1Worker=m;
//# sourceMappingURL=worker-thread-v1.cjs.map
