@wp-playground/client 2.0.18 → 2.0.20

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.
Files changed (4) hide show
  1. package/index.cjs +23 -20
  2. package/index.d.ts +1 -9
  3. package/index.js +45 -43
  4. package/package.json +2 -2
package/index.cjs CHANGED
@@ -778,25 +778,28 @@ This will ensure your code works reliably regardless of the current working dire
778
778
  add_action( 'wp_insert_post_data', function( $data ) {
779
779
  return wp_slash($data);
780
780
  });
781
-
782
- // Ensure that Site Editor templates are associated with the correct taxonomy.
783
- add_filter( 'wp_import_post_terms', function ( $terms, $post_id ) {
784
- foreach ( $terms as $post_term ) {
785
- if ( 'wp_theme' !== $term['taxonomy'] ) continue;
786
- $post_term = get_term_by('slug', $term['slug'], $term['taxonomy'] );
787
- if ( ! $post_term ) {
788
- $post_term = wp_insert_term(
789
- $term['slug'],
790
- $term['taxonomy']
791
- );
792
- $term_id = $post_term['term_id'];
793
- } else {
794
- $term_id = $post_term->term_id;
795
- }
796
- wp_set_object_terms( $post_id, $term_id, $term['taxonomy']) ;
797
- }
798
- return $terms;
799
- }, 10, 2 );
781
+
782
+ // Ensure that Site Editor templates are associated with the correct taxonomy.
783
+ function wp_playground_import_post_terms_handler( $terms, $post_id ) {
784
+ foreach ( $terms as $term ) {
785
+ if ( 'wp_theme' !== $term['taxonomy'] ) continue;
786
+ $post_term = get_term_by('slug', $term['slug'], $term['taxonomy'] );
787
+ if ( ! $post_term ) {
788
+ $post_term = wp_insert_term(
789
+ $term['slug'],
790
+ $term['taxonomy']
791
+ );
792
+ $term_id = $post_term['term_id'];
793
+ } else {
794
+ $term_id = $post_term->term_id;
795
+ }
796
+ wp_set_object_terms( $post_id, $term_id, $term['taxonomy']) ;
797
+ }
798
+ return $terms;
799
+ }
800
+
801
+ add_filter( 'wp_import_post_terms', 'wp_playground_import_post_terms_handler', 10, 2 );
802
+
800
803
  $result = $importer->import( '/tmp/import.wxr' );
801
804
  `})}const Da=async(e,{themeSlug:t=""},r)=>{var a;(a=r==null?void 0:r.tracker)==null||a.setCaption("Importing theme starter content");const i=await e.documentRoot;await e.run({code:`<?php
802
805
 
@@ -1052,6 +1055,6 @@ function playground_progress_reporter() {
1052
1055
  }
1053
1056
  playground_add_filter('blueprint.progress_reporter', 'playground_progress_reporter');
1054
1057
  require( "/tmp/blueprints.phar" );
1055
- `));const p=await i.cli(["/internal/shared/bin/php","/tmp/run-blueprints.php","exec",o,...t]);return p.finished.finally(f),p}async function ng(e){const t=await fetch(e,{credentials:"omit"});if(!t.ok)throw new Error(`Failed to fetch blueprint from ${e}`);const r=await t.arrayBuffer();try{const i=new TextDecoder().decode(r);return JSON.parse(i),new n_([new s_({"blueprint.json":i}),new i_({baseUrl:e})])}catch{if(await ig(r))return In.fromArrayBuffer(r);throw new Error(`Blueprint file at ${e} is neither a valid JSON nor a ZIP file.`)}}async function ig(e){if(e.byteLength<4)return!1;const t=new Uint8Array(e,0,4);return t[0]===80&&t[1]===75&&t[2]===3&&t[3]===4}function ag(){}const og=[],lg="127.0.0.1",fg=4400;async function pg({iframe:e,blueprint:t,remoteUrl:r,progressTracker:i=new Dn,disableProgressBar:a,onBlueprintStepCompleted:n,onClientConnected:s=()=>{},sapiName:o,onBeforeBlueprint:f,mounts:p,scope:c,corsProxy:y,shouldInstallWordPress:h,sqliteDriverVersion:_}){dg(r),cg(e),r=hg(r,{progressbar:!a}),i.setCaption("Preparing WordPress"),t||(t={});const O=await Ic(t,{progress:i.stage(.5),onStepCompleted:n,corsProxy:y});await new Promise(v=>{e.src=r,e.addEventListener("load",v,!1)});const m=Tu(e.contentWindow,e.ownerDocument.defaultView);await m.isConnected(),i.pipe(m);const g=i.stage();return await m.onDownloadProgress(g.loadingListener),await m.boot({mounts:p,sapiName:o,scope:c??Math.random().toFixed(16),shouldInstallWordPress:h,phpVersion:O.versions.php,wpVersion:O.versions.wp,withICU:O.features.intl,withNetworking:O.features.networking,corsProxyUrl:y,sqliteDriverVersion:_}),await m.isReady(),g.finish(),Mc(Te,m),s(m),f&&await f(),await $c(O,m),O.features.networking&&await m.prefetchUpdateChecks(),i.finish(),m}function cg(e){var t,r;(t=e.sandbox)!=null&&t.length&&!((r=e.sandbox)!=null&&r.contains("allow-storage-access-by-user-activation"))&&e.sandbox.add("allow-storage-access-by-user-activation")}const Fc="https://playground.wordpress.net",ug=`http://${lg}:${fg}`,Zl=[Fc,ug,"https://wasm.wordpress.net",location.origin,"http://localhost","https://localhost","http://127.0.0.1","https://127.0.0.1",...og],Nc=Fc;function dg(e){const t=new URL(e,Nc);if(!(Zl.includes(t.origin)&&t.pathname==="/remote.html"))throw new Error(`Invalid remote URL: ${t}. Expected remote URL to have a path of "/remote.html" based on one of the following origins:
1058
+ `));const p=await i.cli(["/internal/shared/bin/php","/tmp/run-blueprints.php","exec",o,...t]);return p.finished.finally(f),p}async function ng(e){const t=await fetch(e,{credentials:"omit"});if(!t.ok)throw new Error(`Failed to fetch blueprint from ${e}`);const r=await t.arrayBuffer();try{const i=new TextDecoder().decode(r);return JSON.parse(i),new n_([new s_({"blueprint.json":i}),new i_({baseUrl:e})])}catch{if(await ig(r))return In.fromArrayBuffer(r);throw new Error(`Blueprint file at ${e} is neither a valid JSON nor a ZIP file.`)}}async function ig(e){if(e.byteLength<4)return!1;const t=new Uint8Array(e,0,4);return t[0]===80&&t[1]===75&&t[2]===3&&t[3]===4}function ag(){}const og=[],lg="127.0.0.1",fg=4400;async function pg({iframe:e,blueprint:t,remoteUrl:r,progressTracker:i=new Dn,disableProgressBar:a,onBlueprintStepCompleted:n,onClientConnected:s=()=>{},sapiName:o,mounts:f,scope:p,corsProxy:c,shouldInstallWordPress:y,sqliteDriverVersion:h}){dg(r),cg(e),r=hg(r,{progressbar:!a}),i.setCaption("Preparing WordPress"),t||(t={});const _=await Ic(t,{progress:i.stage(.5),onStepCompleted:n,corsProxy:c});await new Promise(g=>{e.src=r,e.addEventListener("load",g,!1)});const O=Tu(e.contentWindow,e.ownerDocument.defaultView);await O.isConnected(),i.pipe(O);const m=i.stage();return await O.onDownloadProgress(m.loadingListener),await O.boot({mounts:f,sapiName:o,scope:p??Math.random().toFixed(16),shouldInstallWordPress:y,phpVersion:_.versions.php,wpVersion:_.versions.wp,withICU:_.features.intl,withNetworking:_.features.networking,corsProxyUrl:c,sqliteDriverVersion:h}),await O.isReady(),m.finish(),Mc(Te,O),s(O),await $c(_,O),_.features.networking&&await O.prefetchUpdateChecks(),i.finish(),O}function cg(e){var t,r;(t=e.sandbox)!=null&&t.length&&!((r=e.sandbox)!=null&&r.contains("allow-storage-access-by-user-activation"))&&e.sandbox.add("allow-storage-access-by-user-activation")}const Fc="https://playground.wordpress.net",ug=`http://${lg}:${fg}`,Zl=[Fc,ug,"https://wasm.wordpress.net",location.origin,"http://localhost","https://localhost","http://127.0.0.1","https://127.0.0.1",...og],Nc=Fc;function dg(e){const t=new URL(e,Nc);if(!(Zl.includes(t.origin)&&t.pathname==="/remote.html"))throw new Error(`Invalid remote URL: ${t}. Expected remote URL to have a path of "/remote.html" based on one of the following origins:
1056
1059
  ${Zl.join(`
1057
1060
  `)}`)}function hg(e,t){const r=new URL(e,Nc),i=new URLSearchParams(r.search);for(const[a,n]of Object.entries(t))if(n!=null&&n!==!1)if(Array.isArray(n))for(const s of n)i.append(a,s.toString());else i.set(a,n.toString());return r.search=i.toString(),r.toString()}exports.LatestSupportedPHPVersion=tf;exports.SupportedPHPVersions=Hn;exports.SupportedPHPVersionsList=ou;exports.activatePlugin=Aa;exports.activateTheme=Ta;exports.compileBlueprint=Ic;exports.cp=mc;exports.defineSiteUrl=Ia;exports.defineWpConfigConsts=Vn;exports.enableMultisite=hc;exports.exportWXR=xc;exports.getBlueprintDeclaration=Dc;exports.getV2Runner=Hc;exports.importThemeStarterContent=Da;exports.importWordPressFiles=vc;exports.importWxr=bc;exports.installPlugin=Sc;exports.installTheme=Ec;exports.isBlueprintBundle=Ha;exports.login=Pc;exports.mkdir=_c;exports.mv=yc;exports.phpVar=Qe;exports.phpVars=Is;exports.request=fc;exports.resetData=Ac;exports.resolveRemoteBlueprint=ng;exports.rm=Ca;exports.rmdir=gc;exports.runBlueprintSteps=$c;exports.runBlueprintV2=sg;exports.runPHP=ac;exports.runPHPWithOptions=oc;exports.runSql=lc;exports.runWpInstallationWizard=Tc;exports.setPhpIniEntries=su;exports.setPluginProxyURL=ag;exports.setSiteLanguage=Oc;exports.setSiteOptions=Oa;exports.startPlaygroundWeb=pg;exports.unzip=Xn;exports.updateUserMeta=uc;exports.wpCLI=Ra;exports.wpContentFilesExcludedFromExport=$a;exports.writeFile=Yn;exports.writeFiles=wc;exports.zipWpContent=Cc;
package/index.d.ts CHANGED
@@ -27,14 +27,6 @@ export interface StartPlaygroundOptions {
27
27
  * @private
28
28
  */
29
29
  sapiName?: string;
30
- /**
31
- * Called before the blueprint steps are run,
32
- * allows the caller to delay the Blueprint execution
33
- * once the Playground is booted.
34
- *
35
- * @returns
36
- */
37
- onBeforeBlueprint?: () => Promise<void>;
38
30
  mounts?: Array<MountDescriptor>;
39
31
  shouldInstallWordPress?: boolean;
40
32
  /**
@@ -69,4 +61,4 @@ export interface StartPlaygroundOptions {
69
61
  * @param options Options for loading the playground.
70
62
  * @returns A PlaygroundClient instance.
71
63
  */
72
- export declare function startPlaygroundWeb({ iframe, blueprint, remoteUrl, progressTracker, disableProgressBar, onBlueprintStepCompleted, onClientConnected, sapiName, onBeforeBlueprint, mounts, scope, corsProxy, shouldInstallWordPress, sqliteDriverVersion, }: StartPlaygroundOptions): Promise<PlaygroundClient>;
64
+ export declare function startPlaygroundWeb({ iframe, blueprint, remoteUrl, progressTracker, disableProgressBar, onBlueprintStepCompleted, onClientConnected, sapiName, mounts, scope, corsProxy, shouldInstallWordPress, sqliteDriverVersion, }: StartPlaygroundOptions): Promise<PlaygroundClient>;
package/index.js CHANGED
@@ -13999,25 +13999,28 @@ async function v_(e, t, r) {
13999
13999
  add_action( 'wp_insert_post_data', function( $data ) {
14000
14000
  return wp_slash($data);
14001
14001
  });
14002
-
14003
- // Ensure that Site Editor templates are associated with the correct taxonomy.
14004
- add_filter( 'wp_import_post_terms', function ( $terms, $post_id ) {
14005
- foreach ( $terms as $post_term ) {
14006
- if ( 'wp_theme' !== $term['taxonomy'] ) continue;
14007
- $post_term = get_term_by('slug', $term['slug'], $term['taxonomy'] );
14008
- if ( ! $post_term ) {
14009
- $post_term = wp_insert_term(
14010
- $term['slug'],
14011
- $term['taxonomy']
14012
- );
14013
- $term_id = $post_term['term_id'];
14014
- } else {
14015
- $term_id = $post_term->term_id;
14016
- }
14017
- wp_set_object_terms( $post_id, $term_id, $term['taxonomy']) ;
14018
- }
14019
- return $terms;
14020
- }, 10, 2 );
14002
+
14003
+ // Ensure that Site Editor templates are associated with the correct taxonomy.
14004
+ function wp_playground_import_post_terms_handler( $terms, $post_id ) {
14005
+ foreach ( $terms as $term ) {
14006
+ if ( 'wp_theme' !== $term['taxonomy'] ) continue;
14007
+ $post_term = get_term_by('slug', $term['slug'], $term['taxonomy'] );
14008
+ if ( ! $post_term ) {
14009
+ $post_term = wp_insert_term(
14010
+ $term['slug'],
14011
+ $term['taxonomy']
14012
+ );
14013
+ $term_id = $post_term['term_id'];
14014
+ } else {
14015
+ $term_id = $post_term->term_id;
14016
+ }
14017
+ wp_set_object_terms( $post_id, $term_id, $term['taxonomy']) ;
14018
+ }
14019
+ return $terms;
14020
+ }
14021
+
14022
+ add_filter( 'wp_import_post_terms', 'wp_playground_import_post_terms_handler', 10, 2 );
14023
+
14021
14024
  $result = $importer->import( '/tmp/import.wxr' );
14022
14025
  `
14023
14026
  });
@@ -25826,42 +25829,41 @@ async function hg({
25826
25829
  onClientConnected: s = () => {
25827
25830
  },
25828
25831
  sapiName: o,
25829
- onBeforeBlueprint: f,
25830
- mounts: p,
25831
- scope: c,
25832
- corsProxy: y,
25833
- shouldInstallWordPress: h,
25834
- sqliteDriverVersion: _
25832
+ mounts: f,
25833
+ scope: p,
25834
+ corsProxy: c,
25835
+ shouldInstallWordPress: y,
25836
+ sqliteDriverVersion: h
25835
25837
  }) {
25836
25838
  ag(r), ng(e), r = og(r, {
25837
25839
  progressbar: !a
25838
25840
  }), i.setCaption("Preparing WordPress"), t || (t = {});
25839
- const O = await U_(t, {
25841
+ const _ = await U_(t, {
25840
25842
  progress: i.stage(0.5),
25841
25843
  onStepCompleted: n,
25842
- corsProxy: y
25844
+ corsProxy: c
25843
25845
  });
25844
- await new Promise((v) => {
25845
- e.src = r, e.addEventListener("load", v, !1);
25846
+ await new Promise((g) => {
25847
+ e.src = r, e.addEventListener("load", g, !1);
25846
25848
  });
25847
- const m = eu(
25849
+ const O = eu(
25848
25850
  e.contentWindow,
25849
25851
  e.ownerDocument.defaultView
25850
25852
  );
25851
- await m.isConnected(), i.pipe(m);
25852
- const g = i.stage();
25853
- return await m.onDownloadProgress(g.loadingListener), await m.boot({
25854
- mounts: p,
25853
+ await O.isConnected(), i.pipe(O);
25854
+ const m = i.stage();
25855
+ return await O.onDownloadProgress(m.loadingListener), await O.boot({
25856
+ mounts: f,
25855
25857
  sapiName: o,
25856
- scope: c ?? Math.random().toFixed(16),
25857
- shouldInstallWordPress: h,
25858
- phpVersion: O.versions.php,
25859
- wpVersion: O.versions.wp,
25860
- withICU: O.features.intl,
25861
- withNetworking: O.features.networking,
25862
- corsProxyUrl: y,
25863
- sqliteDriverVersion: _
25864
- }), await m.isReady(), g.finish(), yc(Te, m), s(m), f && await f(), await X_(O, m), O.features.networking && await m.prefetchUpdateChecks(), i.finish(), m;
25858
+ scope: p ?? Math.random().toFixed(16),
25859
+ shouldInstallWordPress: y,
25860
+ phpVersion: _.versions.php,
25861
+ wpVersion: _.versions.wp,
25862
+ withICU: _.features.intl,
25863
+ withNetworking: _.features.networking,
25864
+ corsProxyUrl: c,
25865
+ sqliteDriverVersion: h
25866
+ }), await O.isReady(), m.finish(), yc(Te, O), s(O), await X_(_, O), _.features.networking && await O.prefetchUpdateChecks(), i.finish(), O;
25865
25867
  }
25866
25868
  function ng(e) {
25867
25869
  var t, r;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/client",
3
- "version": "2.0.18",
3
+ "version": "2.0.20",
4
4
  "description": "WordPress Playground client",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  "main": "./index.cjs",
38
38
  "module": "./index.js",
39
39
  "types": "index.d.ts",
40
- "gitHead": "1b63e0be1a05bdd244a5c29beff2ae2c228a003e",
40
+ "gitHead": "d48f477e13c90b08266735f015fb9581273d89f6",
41
41
  "engines": {
42
42
  "node": ">=20.18.3",
43
43
  "npm": ">=10.1.0"