@wp-playground/blueprints 3.1.5 → 3.1.9

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/index.cjs CHANGED
@@ -12,7 +12,7 @@ To fix this:
12
12
 
13
13
  Learn more about Blueprint resources: https://wordpress.github.io/wordpress-playground/blueprints/data-format#resources`;class Dr extends Error{constructor(t=kt){super(t),this.name="BlueprintFilesystemRequiredError"}}class or extends Error{constructor(t,n,f){super(t,f),this.name="ResourceDownloadError",this.url=n}}const Ot=["vfs","literal","wordpress.org/themes","wordpress.org/plugins","url","git:directory","bundled","zip"];function Et(r){return r&&typeof r=="object"&&typeof r.resource=="string"&&Ot.includes(r.resource)}function Tt(r){try{return new URL(r).hostname==="github-proxy.com"}catch{return!1}}function $t(r){let t;try{t=new URL(r)}catch{return null}if(t.hostname!=="github-proxy.com")return null;const n=t.pathname.slice(1);if(n.startsWith("https://github.com/")||n.startsWith("http://github.com/"))return{resource:"url",url:n};const f=t.searchParams,d=f.get("repo");if(!d)return null;const s=f.get("release"),e=f.get("asset");if(s&&e){const $=s==="latest"?"releases/latest/download":`releases/download/${s}`;return{resource:"url",url:`https://github.com/${d}/${$}/${e}`}}let p,u;const y=f.get("pr"),_=f.get("commit"),h=f.get("branch");y?p=`refs/pull/${y}/head`:_?(p=_,u="commit"):s?(p=s,u="tag"):p=h||"HEAD";const k=f.get("directory");return{resource:"zip",inner:{resource:"git:directory",url:`https://github.com/${d}`,ref:p,...u&&{refType:u},...k&&{path:k}}}}class be{get progress(){return this._progress}set progress(t){this._progress=t}setPlayground(t){this.playground=t}get isAsync(){return!1}static create(t,{semaphore:n,progress:f,corsProxy:d,streamBundledFile:s,gitAdditionalHeadersCallback:e}){if(t.resource==="url"&&Tt(t.url)){const u=$t(t.url);u&&(console.warn(`[Blueprints] github-proxy.com is deprecated and will stop working soon. The URL "${t.url}" has been automatically converted to a ${u.resource} resource. Please update your Blueprint to use native resource types. See: https://wordpress.github.io/wordpress-playground/blueprints/steps/resources`),t=u)}let p;switch(t.resource){case"vfs":p=new jt(t,f);break;case"literal":p=new qt(t,f);break;case"wordpress.org/themes":p=new xt(t,f);break;case"wordpress.org/plugins":p=new Ct(t,f);break;case"url":p=new St(t,f,{corsProxy:d});break;case"git:directory":p=new Lt(t,f,{corsProxy:d,additionalHeaders:e});break;case"literal:directory":p=new Nt(t,f);break;case"bundled":if(!s)throw new Dr;p=new It(t,s,f);break;case"zip":{const u=be.create(t.inner,{semaphore:n,progress:f,corsProxy:d,streamBundledFile:s,gitAdditionalHeadersCallback:e});p=new Wt(t,u,f);break}default:throw new Error(`Unknown resource type: ${t.resource}`)}return n&&(p=new Ut(p,n)),new Dt(p)}}class Ur extends be{constructor(t){super(),this.resource=t}get progress(){return this.resource.progress}set progress(t){this.resource.progress=t}get name(){return this.resource.name}get isAsync(){return this.resource.isAsync}setPlayground(t){this.resource.setPlayground(t)}}class jt extends be{constructor(t,n){super(),this.resource=t,this._progress=n}async resolve(){var n;const t=await this.playground.readFileAsBuffer(this.resource.path);return(n=this.progress)==null||n.set(100),new File([t],this.name)}get name(){return this.resource.path.split("/").pop()||""}}class qt extends be{constructor(t,n){super(),this.resource=t,this._progress=n}async resolve(){var t;return(t=this.progress)==null||t.set(100),new File([this.resource.contents],this.resource.name)}get name(){return this.resource.name}}class vr extends be{constructor(t,n){super(),this._progress=t,this.corsProxy=n}async resolve(){var n,f,d;(n=this.progress)==null||n.setCaption(this.caption);const t=this.getURL();try{let s=await Pt.fetchWithCorsProxy(t,void 0,this.corsProxy,await((f=this.playground)==null?void 0:f.absoluteUrl));if(!s.ok)throw new or(`Could not download "${t}"`,t);if(s=await br.cloneResponseMonitorProgress(s,((d=this.progress)==null?void 0:d.loadingListener)??Rt),s.status!==200)throw new or(`Could not download "${t}"`,t);const e=this.name||At(s.headers.get("content-disposition")||"")||encodeURIComponent(t);return new File([await s.arrayBuffer()],e)}catch(s){throw new or(`Could not download "${t}".
14
14
 
15
- Confirm that the URL is correct, the server is reachable, and the file isactually served at that URL. Original error:
15
+ Confirm that the URL is correct, the server is reachable, and the file is actually served at that URL. Original error:
16
16
  ${s}`,t,{cause:s})}}get caption(){return`Downloading ${this.name}`}get name(){try{return new URL(this.getURL(),"http://example.com").pathname.split("/").pop()}catch{return this.getURL()}}get isAsync(){return!0}}function At(r){if(!r)return null;const t=r.match(/filename\*?=([^;]+)/i);if(!t)return null;let n=t[1].trim();if((n.startsWith('"')&&n.endsWith('"')||n.startsWith("'")&&n.endsWith("'"))&&(n=n.slice(1,-1)),t[0].includes("filename*")){const f=n.match(/^[^']*'[^']*'(.+)$/);if(f)try{n=decodeURIComponent(f[1])}catch{}}return n}const Rt=()=>{};class St extends vr{constructor(t,n,f){if(super(n,f==null?void 0:f.corsProxy),this.resource=t,this.options=f,this.resource.url.startsWith("https://github.com/")){const d=this.resource.url.match(/^https:\/\/github\.com\/(?<owner>[^/]+)\/(?<repo>[^/]+)\/(?:blob|raw)\/(?<branch>[^/]+)\/(?<path>.+[^/])$/);d!=null&&d.groups&&(this.resource={...this.resource,url:`https://raw.githubusercontent.com/${d.groups.owner}/${d.groups.repo}/${d.groups.branch}/${d.groups.path}`})}}getURL(){return this.resource.url}get caption(){return this.resource.caption??super.caption}}class Lt extends be{constructor(t,n,f){super(),this.reference=t,this._progress=n,this.options=f}async resolve(){var f,d,s;const t=((d=(f=this.options)==null?void 0:f.additionalHeaders)==null?void 0:d.call(f,this.reference.url))??{},n=(s=this.options)!=null&&s.corsProxy?`${this.options.corsProxy}${this.reference.url}`:this.reference.url;try{const e=await ve.resolveCommitHash(n,{value:this.reference.ref,type:this.reference.refType??"infer"},t),p=await ve.listGitFiles(n,e,t),u=(this.reference.path??"").replace(/^\/+/,""),y=ve.listDescendantFiles(p,u),_=await ve.sparseCheckout(n,e,y,{withObjects:this.reference[".git"],additionalHeaders:t});let h=_.files;return h=Ft(h,k=>k.substring(u.length).replace(/^\/+/,"")),this.reference[".git"]&&(h={...await ve.createDotGitDirectory({repoUrl:this.reference.url,commitHash:e,ref:this.reference.ref,refType:this.reference.refType,objects:_.objects??[],fileOids:_.fileOids??{},pathPrefix:u}),...h}),{name:this.filename,files:h}}catch(e){throw e instanceof ve.GitAuthenticationError?new ve.GitAuthenticationError(this.reference.url,e.status):e}}get filename(){return this.name.replaceAll(/[^a-zA-Z0-9-.]/g,"-").replaceAll(/-+/g,"-").replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g,"")||I.randomFilename()}get name(){var t;return[this.reference.url,this.reference.ref?`(${this.reference.ref})`:"",(t=this.reference.path)!=null&&t.replace(/^\/+/,"")?`at ${this.reference.path}`:""].filter(n=>n.length>0).join(" ")}}function Ft(r,t){return Object.fromEntries(Object.entries(r).map(([n,f])=>[t(n),f]))}class Nt extends be{constructor(t,n){super(),this.reference=t,this._progress=n}async resolve(){return this.reference}get name(){return this.reference.name}}class xt extends vr{constructor(t,n){super(n),this.resource=t}get name(){return pr(this.resource.slug)}getURL(){return`https://downloads.wordpress.org/theme/${Ir(this.resource.slug)}`}}class Ct extends vr{constructor(t,n){super(n),this.resource=t}get name(){return pr(this.resource.slug)}getURL(){return`https://downloads.wordpress.org/plugin/${Ir(this.resource.slug)}`}}function Ir(r){return!r||r.endsWith(".zip")?r:r+".latest-stable.zip"}class Dt extends Ur{async resolve(){return this.promise||(this.promise=this.resource.resolve()),this.promise}}class Ut extends Ur{constructor(t,n){super(t),this.semaphore=n}async resolve(){return this.isAsync?this.semaphore.run(()=>this.resource.resolve()):this.resource.resolve()}}class It extends be{constructor(t,n,f){if(!n)throw new Error(`You are trying to run a Blueprint that refers to a bundled file ("blueprint" resource type), but you did not provide the rest of the bundle. This Blueprint won't work as a standalone JSON file. You'll need to load the entire bundle, e.g. a blueprint.zip file. Alternatively, you may try loading it directly from a URL or a local directory and Playground will try (with your permission) to source the missing files from paths relative to the blueprint file.`);super(),this.resource=t,this.streamBundledFile=n,this._progress=f}async resolve(){var t,n,f;(t=this.progress)==null||t.set(0);try{const d=await this.streamBundledFile(this.resource.path),s=d.filesize;if(!s)return(n=this.progress)==null||n.set(100),d;const e=br.cloneStreamMonitorProgress(d.stream(),s,p=>{var u;(u=this.progress)==null||u.set(p.detail.loaded/p.detail.total*100)});return new gr.StreamedFile(e,this.name,{filesize:s})}catch(d){throw(f=this.progress)==null||f.set(100),new Error(`Failed to read file from blueprint. This Blueprint refers to a resource of type "bundled" with path "${this.resource.path}" that was not available. Please ensure that the entire bundle, such as a blueprint.zip file, is loaded. If you are trying to load the Blueprint directly from a URL or a local directory, make sure that all the necessary files are accessible and located relative to the blueprint file.
17
17
 
18
18
  Error details: ${d instanceof Error?d.message:String(d)}`,{cause:d})}}get name(){return this.resource.path.split("/").pop()||""}get isAsync(){return!0}}class Wt extends be{constructor(t,n,f){super(),this.reference=t,this.innerResource=n,this._progress=f}async resolve(){var s,e;(s=this.progress)==null||s.setCaption(`Creating ZIP: ${this.name}`);const t=await this.innerResource.resolve();let n;t instanceof File?n=[t]:n=Bt(t.files,t.name);const f=gr.encodeZip(n),d=await gr.collectFile(this.name,f);return(e=this.progress)==null||e.set(100),d}get name(){if(this.reference.name)return this.reference.name;const t=this.innerResource.name;return t.endsWith(".zip")?t:`${t}.zip`}get isAsync(){return!0}}function Bt(r,t){const n=[];function f(d,s){for(const[e,p]of Object.entries(d)){const u=s?`${s}/${e}`:e;p instanceof Uint8Array?n.push(new File([p],`${t}/${u}`)):typeof p=="string"?n.push(new File([new TextEncoder().encode(p)],`${t}/${u}`)):f(p,u)}}return f(r,""),n}const Pr=async(r,{pluginPath:t,pluginName:n},f)=>{f==null||f.tracker.setCaption(`Activating ${n||t}`);const d=await r.documentRoot,s=await r.run({code:`<?php