@wp-playground/blueprints 0.6.1 → 0.6.2
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 +3 -3
- package/index.js +12 -5
- package/package.json +2 -2
- package/__vite-browser-external-2447137e.js +0 -4
- package/__vite-browser-external-b3701507.cjs +0 -1
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Nt=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var H=(e,t,r)=>(Nt(e,t,"read from private field"),r?r.call(e):t.get(e)),Z=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},te=(e,t,r,n)=>(Nt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var ce=(e,t,r)=>(Nt(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});if(typeof File>"u"){class e extends Blob{constructor(r,n,s){super(r);let i;s!=null&&s.lastModified&&(i=new Date),(!i||isNaN(i.getFullYear()))&&(i=new Date),this.lastModifiedDate=i,this.lastModified=i.getMilliseconds(),this.name=n||""}}global.File=e}function asPromise(e){return new Promise(function(t,r){e.onload=e.onerror=function(n){e.onload=e.onerror=null,n.type==="load"?t(e.result):r(new Error("Failed to read the blob/file"))}})}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const t=new FileReader;return t.readAsArrayBuffer(this),asPromise(t)});typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const t=new FileReader;return t.readAsText(this),asPromise(t)});function isByobSupported(){const e=new Uint8Array([1,2,3,4]),r=new File([e],"test").stream();try{return r.getReader({mode:"byob"}),!0}catch{return!1}}(typeof Blob.prototype.stream>"u"||!isByobSupported())&&(Blob.prototype.stream=function(){let e=0;const t=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(r){const n=r.byobRequest.view,i=await t.slice(e,e+n.byteLength).arrayBuffer(),a=new Uint8Array(i);new Uint8Array(n.buffer).set(a);const l=a.byteLength;r.byobRequest.respond(l),e+=l,e>=t.size&&r.close()}})});if(typeof CustomEvent>"u"){class e extends Event{constructor(r,n={}){super(r,n),this.detail=n.detail}initCustomEvent(){}}globalThis.CustomEvent=e}
|
|
1
|
+
"use strict";var Nt=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var H=(e,t,r)=>(Nt(e,t,"read from private field"),r?r.call(e):t.get(e)),Z=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},te=(e,t,r,n)=>(Nt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var ce=(e,t,r)=>(Nt(e,t,"access private method"),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});if(typeof File>"u"){class e extends Blob{constructor(r,n,s){super(r);let i;s!=null&&s.lastModified&&(i=new Date),(!i||isNaN(i.getFullYear()))&&(i=new Date),this.lastModifiedDate=i,this.lastModified=i.getMilliseconds(),this.name=n||""}}global.File=e}function asPromise(e){return new Promise(function(t,r){e.onload=e.onerror=function(n){e.onload=e.onerror=null,n.type==="load"?t(e.result):r(new Error("Failed to read the blob/file"))}})}typeof Blob.prototype.arrayBuffer>"u"&&(Blob.prototype.arrayBuffer=function(){const t=new FileReader;return t.readAsArrayBuffer(this),asPromise(t)});typeof Blob.prototype.text>"u"&&(Blob.prototype.text=function(){const t=new FileReader;return t.readAsText(this),asPromise(t)});function isByobSupported(){const e=new Uint8Array([1,2,3,4]),r=new File([e],"test").stream();try{return r.getReader({mode:"byob"}),!0}catch{return!1}}(typeof Blob.prototype.stream>"u"||!isByobSupported())&&(Blob.prototype.stream=function(){let e=0;const t=this;return new ReadableStream({type:"bytes",autoAllocateChunkSize:512*1024,async pull(r){const n=r.byobRequest.view,i=await t.slice(e,e+n.byteLength).arrayBuffer(),a=new Uint8Array(i);new Uint8Array(n.buffer).set(a);const l=a.byteLength;r.byobRequest.respond(l),e+=l,e>=t.size&&r.close()}})});if(typeof CustomEvent>"u"){class e extends Event{constructor(r,n={}){super(r,n),this.detail=n.detail}initCustomEvent(){}}globalThis.CustomEvent=e}const wpContentFilesExcludedFromExport=["db.php","plugins/akismet","plugins/hello.php","plugins/wordpress-importer","mu-plugins/sqlite-database-integration","mu-plugins/playground-includes","mu-plugins/export-wxz.php","mu-plugins/0-playground.php","themes/twentytwenty","themes/twentytwentyone","themes/twentytwentytwo","themes/twentytwentythree","themes/twentytwentyfour","themes/twentytwentyfive","themes/twentytwentysix"];class Semaphore{constructor({concurrency:t}){this._running=0,this.concurrency=t,this.queue=[]}get running(){return this._running}async acquire(){for(;;)if(this._running>=this.concurrency)await new Promise(t=>this.queue.push(t));else{this._running++;let t=!1;return()=>{t||(t=!0,this._running--,this.queue.length>0&&this.queue.shift()())}}}async run(t){const r=await this.acquire();try{return await t()}finally{r()}}}function joinPaths(...e){let t=e.join("/");const r=t[0]==="/",n=t.substring(t.length-1)==="/";return t=normalizePath(t),!t&&!r&&(t="."),t&&n&&(t+="/"),t}function dirname(e){if(e==="/")return"/";e=normalizePath(e);const t=e.lastIndexOf("/");return t===-1?"":t===0?"/":e.substr(0,t)}function normalizePath(e){const t=e[0]==="/";return e=normalizePathsArray(e.split("/").filter(r=>!!r),!t).join("/"),(t?"/":"")+e.replace(/\/$/,"")}function normalizePathsArray(e,t){let r=0;for(let n=e.length-1;n>=0;n--){const s=e[n];s==="."?e.splice(n,1):s===".."?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r;r--)e.unshift("..");return e}function createSpawnHandler(e){return function(t){const r=new ChildProcess,n=new ProcessApi(r);return setTimeout(async()=>{await e(t,n),r.emit("spawn",!0)}),r}}class EventEmitter{constructor(){this.listeners={}}emit(t,r){this.listeners[t]&&this.listeners[t].forEach(function(n){n(r)})}on(t,r){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(r)}}class ProcessApi extends EventEmitter{constructor(t){super(),this.childProcess=t,this.exited=!1,this.stdinData=[],t.on("stdin",r=>{this.stdinData?this.stdinData.push(r.slice()):this.emit("stdin",r)})}stdout(t){typeof t=="string"&&(t=new TextEncoder().encode(t)),this.childProcess.stdout.emit("data",t)}stderr(t){typeof t=="string"&&(t=new TextEncoder().encode(t)),this.childProcess.stderr.emit("data",t)}exit(t){this.exited||(this.exited=!0,this.childProcess.emit("exit",t))}flushStdin(){if(this.stdinData)for(let t=0;t<this.stdinData.length;t++)this.emit("stdin",this.stdinData[t]);this.stdinData=null}}let lastPid=9743;class ChildProcess extends EventEmitter{constructor(t=lastPid++){super(),this.pid=t,this.stdout=new EventEmitter,this.stderr=new EventEmitter;const r=this;this.stdin={write:n=>{r.emit("stdin",n)}}}}function randomString(e=36,t="!@#$%^&*()_+=-[]/.,<>?"){const r="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"+t;let n="";for(let s=e;s>0;--s)n+=r[Math.floor(Math.random()*r.length)];return n}function randomFilename(){return randomString(36,"-_")}function phpVar(e){return`json_decode(base64_decode('${stringToBase64(JSON.stringify(e))}'), true)`}function phpVars(e){const t={};for(const r in e)t[r]=phpVar(e[r]);return t}function stringToBase64(e){return bytesToBase64(new TextEncoder().encode(e))}function bytesToBase64(e){const t=String.fromCodePoint(...e);return btoa(t)}const activatePlugin=async(e,{pluginPath:t,pluginName:r},n)=>{n==null||n.tracker.setCaption(`Activating ${r||t}`);const s=await e.documentRoot;await e.run({throwOnError:!0,code:`<?php
|
|
2
2
|
define( 'WP_ADMIN', true );
|
|
3
3
|
require_once( ${phpVar(s)}. "/wp-load.php" );
|
|
4
4
|
require_once( ${phpVar(s)}. "/wp-admin/includes/plugin.php" );
|
|
@@ -31,7 +31,7 @@ require_once( ${phpVar(n)}. "/wp-load.php" );
|
|
|
31
31
|
set_current_user( get_users(array('role' => 'Administrator') )[0] );
|
|
32
32
|
|
|
33
33
|
switch_theme( ${phpVar(t)} );
|
|
34
|
-
`})},runPHP=async(e,{code:t})=>await e.run({code:t,throwOnError:!0}),runPHPWithOptions=async(e,{options:t})=>await e.run(t),rm=async(e,{path:t})=>{await e.unlink(t)},runSql=async(e,{sql:t},r)=>{r==null||r.tracker.setCaption("Executing SQL Queries");const n=`/tmp/${
|
|
34
|
+
`})},runPHP=async(e,{code:t})=>await e.run({code:t,throwOnError:!0}),runPHPWithOptions=async(e,{options:t})=>await e.run(t),rm=async(e,{path:t})=>{await e.unlink(t)},runSql=async(e,{sql:t},r)=>{r==null||r.tracker.setCaption("Executing SQL Queries");const n=`/tmp/${randomFilename()}.sql`;await e.writeFile(n,new Uint8Array(await t.arrayBuffer()));const s=await e.documentRoot,i=phpVars({docroot:s,sqlFilename:n}),a=await e.run({code:`<?php
|
|
35
35
|
require_once ${i.docroot} . '/wp-load.php';
|
|
36
36
|
|
|
37
37
|
$handle = fopen(${i.sqlFilename}, 'r');
|
|
@@ -522,7 +522,7 @@ function delTree($dir)
|
|
|
522
522
|
`;async function runPhpWithZipFunctions(e,t){return await e.run({throwOnError:!0,code:zipFunctions+t})}const tmpPath="/tmp/file.zip",unzip=async(e,{zipFile:t,zipPath:r,extractToPath:n})=>{if(r)await e.writeFile(tmpPath,await e.readFileAsBuffer(r)),console.warn('The "zipPath" option of the unzip() Blueprint step is deprecated and will be removed. Use "zipFile" instead.');else if(t)await e.writeFile(tmpPath,new Uint8Array(await t.arrayBuffer()));else throw new Error("Either zipPath or zipFile must be provided");const s=phpVars({zipPath:tmpPath,extractToPath:n});await runPhpWithZipFunctions(e,`unzip(${s.zipPath}, ${s.extractToPath});`),e.fileExists(tmpPath)&&await e.unlink(tmpPath)},importWordPressFiles=async(e,{wordPressFilesZip:t,pathInZip:r=""})=>{const n=await e.documentRoot;let s=joinPaths("/tmp","import");await e.mkdir(s),await unzip(e,{zipFile:t,extractToPath:s}),s=joinPaths(s,r);const i=joinPaths(s,"wp-content"),a=joinPaths(n,"wp-content");for(const d of wpContentFilesExcludedFromExport){const $=joinPaths(i,d);await removePath(e,$);const E=joinPaths(a,d);await e.fileExists(E)&&(await e.mkdir(dirname($)),await e.mv(E,$))}const l=joinPaths(s,"wp-content","database");await e.fileExists(l)||await e.mv(joinPaths(n,"wp-content","database"),l);const p=await e.listFiles(s);for(const d of p)await removePath(e,joinPaths(n,d)),await e.mv(joinPaths(s,d),joinPaths(n,d));await e.rmdir(s),await defineSiteUrl(e,{siteUrl:await e.absoluteUrl});const u=phpVar(joinPaths(n,"wp-admin","upgrade.php"));await e.run({throwOnError:!0,code:`<?php
|
|
523
523
|
$_GET['step'] = 'upgrade_db';
|
|
524
524
|
require ${u};
|
|
525
|
-
`})};async function removePath(e,t){await e.fileExists(t)&&(await e.isDir(t)?await e.rmdir(t):await e.unlink(t))}async function exportWXR(e){const t=await e.request({url:"/wp-admin/export.php?download=true&content=all"});return new File([t.bytes],"export.xml")}async function exportWXZ(e){const t=await e.request({url:"/wp-admin/export.php?download=true&content=all&export_wxz=1"});return new File([t.bytes],"export.wxz")}async function installAsset(e,{targetPath:t,zipFile:r}){const s=r.name.replace(/\.zip$/,""),i=joinPaths(await e.documentRoot,"wp-content"),a=joinPaths(i,
|
|
525
|
+
`})};async function removePath(e,t){await e.fileExists(t)&&(await e.isDir(t)?await e.rmdir(t):await e.unlink(t))}async function exportWXR(e){const t=await e.request({url:"/wp-admin/export.php?download=true&content=all"});return new File([t.bytes],"export.xml")}async function exportWXZ(e){const t=await e.request({url:"/wp-admin/export.php?download=true&content=all&export_wxz=1"});return new File([t.bytes],"export.wxz")}async function installAsset(e,{targetPath:t,zipFile:r}){const s=r.name.replace(/\.zip$/,""),i=joinPaths(await e.documentRoot,"wp-content"),a=joinPaths(i,randomString()),l=joinPaths(a,"assets",s);await e.fileExists(l)&&await e.rmdir(a,{recursive:!0}),await e.mkdir(a);try{await unzip(e,{zipFile:r,extractToPath:l});let p=await e.listFiles(l,{prependPath:!0});p=p.filter(R=>!R.endsWith("/__MACOSX"));const u=p.length===1&&await e.isDir(p[0]);let d,$="";u?($=p[0],d=p[0].split("/").pop()):($=l,d=s);const E=`${t}/${d}`;return await e.mv($,E),{assetFolderPath:E,assetFolderName:d}}finally{await e.rmdir(a,{recursive:!0})}}function zipNameToHumanName(e){const t=e.split(".").shift().replace(/-/g," ");return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}const installPlugin=async(e,{pluginZipFile:t,options:r={}},n)=>{const s=t.name.split("/").pop()||"plugin.zip",i=zipNameToHumanName(s);n==null||n.tracker.setCaption(`Installing the ${i} plugin`);const{assetFolderPath:a}=await installAsset(e,{zipFile:t,targetPath:`${await e.documentRoot}/wp-content/plugins`});("activate"in r?r.activate:!0)&&await activatePlugin(e,{pluginPath:a,pluginName:i},n)},installTheme=async(e,{themeZipFile:t,options:r={}},n)=>{const s=zipNameToHumanName(t.name);n==null||n.tracker.setCaption(`Installing the ${s} theme`);const{assetFolderName:i}=await installAsset(e,{zipFile:t,targetPath:`${await e.documentRoot}/wp-content/themes`});("activate"in r?r.activate:!0)&&await activateTheme(e,{themeFolderName:i},n)},runWpInstallationWizard=async(e,{options:t})=>{await e.request({url:"/wp-admin/install.php?step=2",method:"POST",formData:{language:"en",prefix:"wp_",weblog_title:"My WordPress Website",user_name:t.adminPassword||"admin",admin_password:t.adminPassword||"password",admin_password2:t.adminPassword||"password",Submit:"Install WordPress",pw_weak:"1",admin_email:"admin@localhost.com"}})},zipWpContent=async(e,{selfContained:t=!1}={})=>{const r="/tmp/wordpress-playground.zip",n=await e.documentRoot,s=joinPaths(n,"wp-content");let i=wpContentFilesExcludedFromExport;t&&(i=i.filter(p=>!p.startsWith("themes/twenty")).filter(p=>p!=="mu-plugins/sqlite-database-integration"));const a=phpVars({zipPath:r,wpContentPath:s,documentRoot:n,exceptPaths:i.map(p=>joinPaths(n,"wp-content",p)),additionalPaths:t?{[joinPaths(n,"wp-config.php")]:"wp-config.php"}:{}});await runPhpWithZipFunctions(e,`zipDir(${a.wpContentPath}, ${a.zipPath}, array(
|
|
526
526
|
'exclude_paths' => ${a.exceptPaths},
|
|
527
527
|
'zip_root' => ${a.documentRoot},
|
|
528
528
|
'additional_paths' => ${a.additionalPaths}
|
package/index.js
CHANGED
|
@@ -67,9 +67,6 @@ if (typeof CustomEvent > "u") {
|
|
|
67
67
|
}
|
|
68
68
|
globalThis.CustomEvent = e;
|
|
69
69
|
}
|
|
70
|
-
typeof crypto > "u" && import("./__vite-browser-external-2447137e.js").then((e) => {
|
|
71
|
-
global.crypto = e;
|
|
72
|
-
});
|
|
73
70
|
const wpContentFilesExcludedFromExport = [
|
|
74
71
|
"db.php",
|
|
75
72
|
"plugins/akismet",
|
|
@@ -205,6 +202,16 @@ class ChildProcess extends EventEmitter {
|
|
|
205
202
|
};
|
|
206
203
|
}
|
|
207
204
|
}
|
|
205
|
+
function randomString(e = 36, t = "!@#$%^&*()_+=-[]/.,<>?") {
|
|
206
|
+
const r = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + t;
|
|
207
|
+
let n = "";
|
|
208
|
+
for (let s = e; s > 0; --s)
|
|
209
|
+
n += r[Math.floor(Math.random() * r.length)];
|
|
210
|
+
return n;
|
|
211
|
+
}
|
|
212
|
+
function randomFilename() {
|
|
213
|
+
return randomString(36, "-_");
|
|
214
|
+
}
|
|
208
215
|
function phpVar(e) {
|
|
209
216
|
return `json_decode(base64_decode('${stringToBase64(
|
|
210
217
|
JSON.stringify(e)
|
|
@@ -274,7 +281,7 @@ switch_theme( ${phpVar(t)} );
|
|
|
274
281
|
await e.unlink(t);
|
|
275
282
|
}, runSql = async (e, { sql: t }, r) => {
|
|
276
283
|
r == null || r.tracker.setCaption("Executing SQL Queries");
|
|
277
|
-
const n = `/tmp/${
|
|
284
|
+
const n = `/tmp/${randomFilename()}.sql`;
|
|
278
285
|
await e.writeFile(
|
|
279
286
|
n,
|
|
280
287
|
new Uint8Array(await t.arrayBuffer())
|
|
@@ -1076,7 +1083,7 @@ async function exportWXZ(e) {
|
|
|
1076
1083
|
return new File([t.bytes], "export.wxz");
|
|
1077
1084
|
}
|
|
1078
1085
|
async function installAsset(e, { targetPath: t, zipFile: r }) {
|
|
1079
|
-
const s = r.name.replace(/\.zip$/, ""), i = joinPaths(await e.documentRoot, "wp-content"), a = joinPaths(i,
|
|
1086
|
+
const s = r.name.replace(/\.zip$/, ""), i = joinPaths(await e.documentRoot, "wp-content"), a = joinPaths(i, randomString()), l = joinPaths(a, "assets", s);
|
|
1080
1087
|
await e.fileExists(l) && await e.rmdir(a, {
|
|
1081
1088
|
recursive: !0
|
|
1082
1089
|
}), await e.mkdir(a);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wp-playground/blueprints",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"import": "./index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"access": "public",
|
|
22
22
|
"directory": "../../../dist/packages/playground/blueprints"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "3c0de0d0847c3550a75a026bef9724eac421afbf",
|
|
25
25
|
"engines": {
|
|
26
26
|
"node": ">=18.18.2",
|
|
27
27
|
"npm": ">=8.11.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={};exports.default=e;
|