@wp-playground/client 1.0.26 → 1.0.28

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/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Playground Client
2
+
3
+ Provides a [PlaygroundClient](https://wordpress.github.io/wordpress-playground/api/client/) that can be used to control a WordPress Playground iframe:
4
+
5
+ ```ts
6
+ import { startPlaygroundWeb } from '@wp-playground/client';
7
+
8
+ const client = await startPlaygroundWeb({
9
+ // An iframe pointing to https://playground.wordpress.net/remote.html:
10
+ iframe: document.getElementById('wp'),
11
+ remoteUrl: `https://playground.wordpress.net/remote.html`,
12
+ });
13
+
14
+ const response = await client.run({
15
+ // wp-load.php is only required if you want to interact with WordPress.
16
+ code: '<?php require_once "/wordpress/wp-load.php"; $posts = get_posts(); echo "Post Title: " . $posts[0]->post_title;',
17
+ });
18
+ console.log(response.text);
19
+ ```
20
+
21
+ Using TypeScript is highly recommended as this package ships with comprehensive types – hit ctrl+space in your IDE after `client.` and you'll see all the available methods.
22
+
23
+ Once you have a [PlaygroundClient](https://wordpress.github.io/wordpress-playground/api/client/) instance, you can use it to control the playground:
24
+
25
+ ```ts
26
+ await client.writeFile('/index.php', '<?php echo "Hi!"; ');
27
+ await client.run({
28
+ scriptPath: '/index.php',
29
+ });
30
+
31
+ console.log(await client.readFileAsText('/index.php'));
32
+
33
+ await client.request({
34
+ url: '/index.php',
35
+ method: 'POST',
36
+ body: {
37
+ foo: 'bar',
38
+ },
39
+ });
40
+ ```
41
+
42
+ To see all the available methods, check out the [PlaygroundClient](https://wordpress.github.io/wordpress-playground/api/client/) interface.
package/index.cjs CHANGED
@@ -744,7 +744,8 @@ function zipDir($root, $output, $options = array())
744
744
  $directory_path = $entry . '/';
745
745
  array_push($directories, $directory_path);
746
746
  } else if (is_file($entry)) {
747
- $zip->addFile($entry, substr($entry, strlen($zip_root)));
747
+ // ensure compliance with zip spec by only using relative paths for files
748
+ $zip->addFile($entry, ltrim(substr($entry, strlen($zip_root)), '/'));
748
749
  }
749
750
  }
750
751
  closedir($handle);
package/index.js CHANGED
@@ -2164,7 +2164,8 @@ function zipDir($root, $output, $options = array())
2164
2164
  $directory_path = $entry . '/';
2165
2165
  array_push($directories, $directory_path);
2166
2166
  } else if (is_file($entry)) {
2167
- $zip->addFile($entry, substr($entry, strlen($zip_root)));
2167
+ // ensure compliance with zip spec by only using relative paths for files
2168
+ $zip->addFile($entry, ltrim(substr($entry, strlen($zip_root)), '/'));
2168
2169
  }
2169
2170
  }
2170
2171
  closedir($handle);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/client",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
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": "f5b85399ff8dbabaf122bfa98347ce76d7f59910",
40
+ "gitHead": "ed7171a91717c70dd7162e3d93283f66d21c001d",
41
41
  "engines": {
42
42
  "node": ">=18.18.0",
43
43
  "npm": ">=8.11.0"
@@ -50,6 +50,8 @@
50
50
  "comlink": "^4.4.1",
51
51
  "crc-32": "1.2.2",
52
52
  "diff3": "0.0.4",
53
+ "events": "3.3.0",
54
+ "express": "4.19.2",
53
55
  "ignore": "5.2.4",
54
56
  "ini": "4.1.2",
55
57
  "minimisted": "2.0.1",
@@ -60,12 +62,14 @@
60
62
  "sha.js": "2.4.11",
61
63
  "simple-get": "4.0.1",
62
64
  "wasm-feature-detect": "1.8.0",
63
- "@wp-playground/blueprints": "1.0.26",
64
- "@php-wasm/universal": "1.0.26",
65
- "@php-wasm/util": "1.0.26",
66
- "@php-wasm/web": "1.0.26",
67
- "@php-wasm/progress": "1.0.26",
68
- "@wp-playground/remote": "1.0.26",
69
- "@php-wasm/logger": "1.0.26"
65
+ "ws": "8.18.0",
66
+ "yargs": "17.7.2",
67
+ "@wp-playground/blueprints": "1.0.28",
68
+ "@php-wasm/universal": "1.0.28",
69
+ "@php-wasm/util": "1.0.28",
70
+ "@php-wasm/web": "1.0.28",
71
+ "@php-wasm/progress": "1.0.28",
72
+ "@wp-playground/remote": "1.0.28",
73
+ "@php-wasm/logger": "1.0.28"
70
74
  }
71
75
  }