@wp-playground/common 0.7.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.
- package/index.d.ts +13 -0
- package/index.js +18 -0
- package/package.json +31 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Avoid adding new code here. @wp-playground/common should remain
|
|
3
|
+
* as lean as possible.
|
|
4
|
+
*
|
|
5
|
+
* This package exists to avoid circular dependencies. Let's not
|
|
6
|
+
* use it as a default place to add code that doesn't seem to fit
|
|
7
|
+
* anywhere else. If there's no good place for your code, perhaps
|
|
8
|
+
* it needs to be restructured? Or maybe there's a need for a new package?
|
|
9
|
+
* Let's always consider these questions before adding new code here.
|
|
10
|
+
*/
|
|
11
|
+
import { UniversalPHP } from '../../../php-wasm/universal/src/index.ts';
|
|
12
|
+
export declare const RecommendedPHPVersion = "8.0";
|
|
13
|
+
export declare const unzipFile: (php: UniversalPHP, zipPath: string | File, extractToPath: string) => Promise<void>;
|
package/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function c(t){return`json_decode(base64_decode('${s(JSON.stringify(t))}'), true)`}function a(t){const e={};for(const n in t)e[n]=c(t[n]);return e}function s(t){return u(new TextEncoder().encode(t))}function u(t){const e=String.fromCodePoint(...t);return btoa(e)}const f="8.0",i="/tmp/file.zip",$=async(t,e,n)=>{if(e instanceof File){const r=e;e=i,await t.writeFile(e,new Uint8Array(await r.arrayBuffer()))}const o=a({zipPath:e,extractToPath:n});await t.run({code:`<?php
|
|
2
|
+
function unzip($zipPath, $extractTo, $overwrite = true)
|
|
3
|
+
{
|
|
4
|
+
if (!is_dir($extractTo)) {
|
|
5
|
+
mkdir($extractTo, 0777, true);
|
|
6
|
+
}
|
|
7
|
+
$zip = new ZipArchive;
|
|
8
|
+
$res = $zip->open($zipPath);
|
|
9
|
+
if ($res === TRUE) {
|
|
10
|
+
$zip->extractTo($extractTo);
|
|
11
|
+
$zip->close();
|
|
12
|
+
chmod($extractTo, 0777);
|
|
13
|
+
} else {
|
|
14
|
+
throw new Exception("Could not unzip file");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
unzip(${o.zipPath}, ${o.extractToPath});
|
|
18
|
+
`}),await t.fileExists(i)&&await t.unlink(i)};export{f as RecommendedPHPVersion,$ as unzipFile};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wp-playground/common",
|
|
3
|
+
"version": "0.7.20",
|
|
4
|
+
"description": "Common exports and utilities for WordPress Playground",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/common/common-playground"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://developer.wordpress.org/playground",
|
|
10
|
+
"author": "The WordPress contributors",
|
|
11
|
+
"contributors": [
|
|
12
|
+
{
|
|
13
|
+
"name": "Adam Zielinski",
|
|
14
|
+
"email": "adam@adamziel.com",
|
|
15
|
+
"url": "https://github.com/adamziel"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"main": "./index.js",
|
|
19
|
+
"typings": "./index.d.ts",
|
|
20
|
+
"license": "GPL-2.0-or-later",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18.18.0",
|
|
24
|
+
"npm": ">=8.11.0"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"directory": "../../../dist/packages/playground/common"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "5915ef756c88da8dcb665f9f0e49ddc0c0b10d50"
|
|
31
|
+
}
|