@wp-playground/cli 1.2.1 → 1.2.3

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/worker-thread.js CHANGED
@@ -1,91 +1,105 @@
1
- import { exposeAPI as g, PHPWorker as v, consumeAPI as W } from "@php-wasm/universal";
2
- import { loadNodeRuntime as k, createNodeFsMountHandler as E } from "@php-wasm/node";
3
- import { EmscriptenDownloadMonitor as D } from "@php-wasm/progress";
4
- import { bootWordPress as F } from "@wp-playground/wordpress";
5
- import { sprintf as I } from "@php-wasm/util";
6
- import { parentPort as a } from "worker_threads";
7
- import { rootCertificates as S } from "tls";
8
- function u(t, e) {
9
- for (const o of e)
10
- t.mkdir(o.vfsPath), t.mount(o.vfsPath, E(o.hostPath));
11
- }
12
- function x(t, e, ...o) {
1
+ import { loadNodeRuntime as k } from "@php-wasm/node";
2
+ import { EmscriptenDownloadMonitor as v } from "@php-wasm/progress";
3
+ import { exposeAPI as M, PHPWorker as S, consumeAPI as W, consumeAPISync as E, sandboxedSpawnHandlerFactory as F } from "@php-wasm/universal";
4
+ import { sprintf as H } from "@php-wasm/util";
5
+ import { RecommendedPHPVersion as I } from "@wp-playground/common";
6
+ import { bootWordPress as L } from "@wp-playground/wordpress";
7
+ import { rootCertificates as x } from "tls";
8
+ import { jspi as A } from "wasm-feature-detect";
9
+ import { MessageChannel as D, parentPort as R } from "worker_threads";
10
+ import { m } from "./mounts-B-Qdcyyt.js";
11
+ function C(n, e, ...t) {
13
12
  console.log(
14
13
  performance.now().toFixed(6).padStart(15, "0"),
15
- t.toString().padStart(16, "0"),
16
- I(e, ...o)
14
+ n.toString().padStart(16, "0"),
15
+ H(e, ...t)
17
16
  );
18
17
  }
19
- class A extends v {
18
+ class G extends S {
20
19
  constructor(e) {
21
20
  super(void 0, e), this.booted = !1;
22
21
  }
22
+ /**
23
+ * Call this method before boot() to use file locking.
24
+ *
25
+ * This method is separate from boot() to simplify the related Comlink.transferHandlers
26
+ * setup – if an argument is a MessagePort, we're transferring it, not copying it.
27
+ *
28
+ * @see comlink-sync.ts
29
+ * @see phpwasm-emscripten-library-file-locking-for-node.js
30
+ */
31
+ async useFileLockManager(e) {
32
+ await A() ? this.fileLockManager = W(e) : this.fileLockManager = await E(e);
33
+ }
23
34
  async boot({
24
35
  absoluteUrl: e,
25
- mountsBeforeWpInstall: o,
26
- mountsAfterWpInstall: P,
27
- phpVersion: f = "8.0",
36
+ mountsBeforeWpInstall: t,
37
+ mountsAfterWpInstall: f,
38
+ phpVersion: P = I,
28
39
  wordPressZip: c,
29
- sqliteIntegrationPluginZip: l,
40
+ sqliteIntegrationPluginZip: p,
30
41
  firstProcessId: i,
31
42
  processIdSpaceLength: h,
32
- dataSqlPath: w,
33
- followSymlinks: y,
34
- trace: b
43
+ dataSqlPath: u,
44
+ followSymlinks: w,
45
+ trace: y,
46
+ internalCookieStore: g,
47
+ withXdebug: b
35
48
  }) {
36
49
  if (this.booted)
37
50
  throw new Error("Playground already booted");
38
51
  this.booted = !0;
39
- let r = i;
40
- const _ = i + h - 1, d = W(a);
41
- await d.isConnected();
52
+ let o = i;
53
+ const _ = i + h - 1;
42
54
  try {
43
- const s = {
55
+ const r = {
44
56
  WP_DEBUG: !0,
45
57
  WP_DEBUG_LOG: !0,
46
58
  WP_DEBUG_DISPLAY: !1
47
- }, p = await F({
59
+ }, l = await L({
48
60
  siteUrl: e,
49
61
  createPhpRuntime: async () => {
50
- const n = r;
51
- return r < _ ? r++ : r = i, await k(f, {
62
+ const s = o;
63
+ return o < _ ? o++ : o = i, await k(P, {
52
64
  emscriptenOptions: {
53
- fileLockManager: d,
54
- processId: n,
55
- trace: b ? x : void 0
65
+ fileLockManager: this.fileLockManager,
66
+ processId: s,
67
+ trace: y ? C : void 0
56
68
  },
57
- followSymlinks: y
69
+ followSymlinks: w,
70
+ withXdebug: b
58
71
  });
59
72
  },
60
73
  wordPressZip: c !== void 0 ? new File([c], "wordpress.zip") : void 0,
61
- sqliteIntegrationPluginZip: l !== void 0 ? new File(
62
- [l],
74
+ sqliteIntegrationPluginZip: p !== void 0 ? new File(
75
+ [p],
63
76
  "sqlite-integration-plugin.zip"
64
77
  ) : void 0,
65
78
  sapiName: "cli",
66
79
  createFiles: {
67
- "/internal/shared/ca-bundle.crt": S.join(`
80
+ "/internal/shared/ca-bundle.crt": x.join(`
68
81
  `)
69
82
  },
70
- constants: s,
83
+ constants: r,
71
84
  phpIniEntries: {
72
85
  "openssl.cafile": "/internal/shared/ca-bundle.crt",
73
86
  allow_url_fopen: "1",
74
87
  disable_functions: ""
75
88
  },
76
89
  hooks: {
77
- async beforeWordPressFiles(n) {
78
- u(n, o);
90
+ async beforeWordPressFiles(s) {
91
+ m(s, t);
79
92
  }
80
93
  },
81
- cookieStore: !1,
82
- dataSqlPath: w
94
+ cookieStore: g ? void 0 : !1,
95
+ dataSqlPath: u,
96
+ spawnHandler: F
83
97
  });
84
- this.__internal_setRequestHandler(p);
85
- const m = await p.getPrimaryPhp();
86
- await this.setPrimaryPHP(m), u(m, P), H();
87
- } catch (s) {
88
- throw R(s), s;
98
+ this.__internal_setRequestHandler(l);
99
+ const d = await l.getPrimaryPhp();
100
+ await this.setPrimaryPHP(d), m(d, f), U();
101
+ } catch (r) {
102
+ throw q(r), r;
89
103
  }
90
104
  }
91
105
  // Provide a named disposal method that can be invoked via comlink.
@@ -93,13 +107,19 @@ class A extends v {
93
107
  await this[Symbol.asyncDispose]();
94
108
  }
95
109
  }
96
- const [H, R] = g(
97
- new A(new D()),
110
+ const a = new D(), [U, q] = M(
111
+ new G(new v()),
98
112
  void 0,
99
- a
113
+ a.port1
114
+ );
115
+ R.postMessage(
116
+ {
117
+ command: "worker-script-initialized",
118
+ phpPort: a.port2
119
+ },
120
+ [a.port2]
100
121
  );
101
- a.postMessage("worker-script-initialized");
102
122
  export {
103
- A as PlaygroundCliWorker
123
+ G as PlaygroundCliWorker
104
124
  };
105
125
  //# sourceMappingURL=worker-thread.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-thread.js","sources":["../../../../packages/playground/cli/src/worker-thread.ts"],"sourcesContent":["import type { PHP, SupportedPHPVersion } from '@php-wasm/universal';\nimport { PHPWorker, consumeAPI, exposeAPI } from '@php-wasm/universal';\nimport type { FileLockManager } from '@php-wasm/node';\nimport { createNodeFsMountHandler, loadNodeRuntime } from '@php-wasm/node';\nimport { EmscriptenDownloadMonitor } from '@php-wasm/progress';\nimport { bootWordPress } from '@wp-playground/wordpress';\nimport { sprintf } from '@php-wasm/util';\nimport { parentPort } from 'worker_threads';\nimport { rootCertificates } from 'tls';\n\nexport interface Mount {\n\thostPath: string;\n\tvfsPath: string;\n}\n\nexport type PrimaryWorkerBootOptions = {\n\twpVersion?: string;\n\tphpVersion?: SupportedPHPVersion;\n\tabsoluteUrl: string;\n\tmountsBeforeWpInstall: Array<Mount>;\n\tmountsAfterWpInstall: Array<Mount>;\n\twordPressZip?: ArrayBuffer;\n\tsqliteIntegrationPluginZip?: ArrayBuffer;\n\tfirstProcessId: number;\n\tprocessIdSpaceLength: number;\n\tdataSqlPath?: string;\n\tfollowSymlinks: boolean;\n\ttrace: boolean;\n};\n\nfunction mountResources(php: PHP, mounts: Mount[]) {\n\tfor (const mount of mounts) {\n\t\tphp.mkdir(mount.vfsPath);\n\t\tphp.mount(mount.vfsPath, createNodeFsMountHandler(mount.hostPath));\n\t}\n}\n\n/**\n * Print trace messages from PHP-WASM.\n *\n * @param {number} processId - The process ID.\n * @param {string} format - The format string.\n * @param {...any} args - The arguments.\n */\nfunction tracePhpWasm(processId: number, format: string, ...args: any[]) {\n\t// eslint-disable-next-line no-console\n\tconsole.log(\n\t\tperformance.now().toFixed(6).padStart(15, '0'),\n\t\tprocessId.toString().padStart(16, '0'),\n\t\tsprintf(format, ...args)\n\t);\n}\n\nexport class PlaygroundCliWorker extends PHPWorker {\n\tbooted = false;\n\n\tconstructor(monitor: EmscriptenDownloadMonitor) {\n\t\tsuper(undefined, monitor);\n\t}\n\n\tasync boot({\n\t\tabsoluteUrl,\n\t\tmountsBeforeWpInstall,\n\t\tmountsAfterWpInstall,\n\t\tphpVersion = '8.0',\n\t\twordPressZip,\n\t\tsqliteIntegrationPluginZip,\n\t\tfirstProcessId,\n\t\tprocessIdSpaceLength,\n\t\tdataSqlPath,\n\t\tfollowSymlinks,\n\t\ttrace,\n\t}: PrimaryWorkerBootOptions) {\n\t\tif (this.booted) {\n\t\t\tthrow new Error('Playground already booted');\n\t\t}\n\t\tthis.booted = true;\n\n\t\tlet nextProcessId = firstProcessId;\n\t\tconst lastProcessId = firstProcessId + processIdSpaceLength - 1;\n\t\tconst fileLockManager = consumeAPI<FileLockManager>(parentPort!);\n\t\tawait fileLockManager.isConnected();\n\n\t\ttry {\n\t\t\tconst constants: Record<string, string | number | boolean | null> =\n\t\t\t\t{\n\t\t\t\t\tWP_DEBUG: true,\n\t\t\t\t\tWP_DEBUG_LOG: true,\n\t\t\t\t\tWP_DEBUG_DISPLAY: false,\n\t\t\t\t};\n\n\t\t\tconst requestHandler = await bootWordPress({\n\t\t\t\tsiteUrl: absoluteUrl,\n\t\t\t\tcreatePhpRuntime: async () => {\n\t\t\t\t\tconst processId = nextProcessId;\n\n\t\t\t\t\tif (nextProcessId < lastProcessId) {\n\t\t\t\t\t\tnextProcessId++;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// We've reached the end of the process ID space. Start over.\n\t\t\t\t\t\tnextProcessId = firstProcessId;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn await loadNodeRuntime(phpVersion, {\n\t\t\t\t\t\temscriptenOptions: {\n\t\t\t\t\t\t\tfileLockManager,\n\t\t\t\t\t\t\tprocessId,\n\t\t\t\t\t\t\ttrace: trace ? tracePhpWasm : undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tfollowSymlinks,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\twordPressZip:\n\t\t\t\t\twordPressZip !== undefined\n\t\t\t\t\t\t? new File([wordPressZip], 'wordpress.zip')\n\t\t\t\t\t\t: undefined,\n\t\t\t\tsqliteIntegrationPluginZip:\n\t\t\t\t\tsqliteIntegrationPluginZip !== undefined\n\t\t\t\t\t\t? new File(\n\t\t\t\t\t\t\t\t[sqliteIntegrationPluginZip],\n\t\t\t\t\t\t\t\t'sqlite-integration-plugin.zip'\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: undefined,\n\t\t\t\tsapiName: 'cli',\n\t\t\t\tcreateFiles: {\n\t\t\t\t\t'/internal/shared/ca-bundle.crt':\n\t\t\t\t\t\trootCertificates.join('\\n'),\n\t\t\t\t},\n\t\t\t\tconstants,\n\t\t\t\tphpIniEntries: {\n\t\t\t\t\t'openssl.cafile': '/internal/shared/ca-bundle.crt',\n\t\t\t\t\tallow_url_fopen: '1',\n\t\t\t\t\tdisable_functions: '',\n\t\t\t\t},\n\t\t\t\thooks: {\n\t\t\t\t\tasync beforeWordPressFiles(php) {\n\t\t\t\t\t\tmountResources(php, mountsBeforeWpInstall);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tcookieStore: false,\n\t\t\t\tdataSqlPath,\n\t\t\t});\n\t\t\tthis.__internal_setRequestHandler(requestHandler);\n\n\t\t\tconst primaryPhp = await requestHandler.getPrimaryPhp();\n\t\t\tawait this.setPrimaryPHP(primaryPhp);\n\n\t\t\tmountResources(primaryPhp, mountsAfterWpInstall);\n\n\t\t\tsetApiReady();\n\t\t} catch (e) {\n\t\t\tsetAPIError(e as Error);\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\t// Provide a named disposal method that can be invoked via comlink.\n\tasync dispose() {\n\t\tawait this[Symbol.asyncDispose]();\n\t}\n}\n\nconst [setApiReady, setAPIError] = exposeAPI(\n\tnew PlaygroundCliWorker(new EmscriptenDownloadMonitor()),\n\tundefined,\n\tparentPort!\n);\n\n// Confirm that the worker script has initialized.\nparentPort!.postMessage('worker-script-initialized');\n"],"names":["mountResources","php","mounts","mount","createNodeFsMountHandler","tracePhpWasm","processId","format","args","sprintf","PlaygroundCliWorker","PHPWorker","monitor","absoluteUrl","mountsBeforeWpInstall","mountsAfterWpInstall","phpVersion","wordPressZip","sqliteIntegrationPluginZip","firstProcessId","processIdSpaceLength","dataSqlPath","followSymlinks","trace","nextProcessId","lastProcessId","fileLockManager","consumeAPI","parentPort","constants","requestHandler","bootWordPress","loadNodeRuntime","rootCertificates","primaryPhp","setApiReady","e","setAPIError","exposeAPI","EmscriptenDownloadMonitor"],"mappings":";;;;;;;AA8BA,SAASA,EAAeC,GAAUC,GAAiB;AAClD,aAAWC,KAASD;AACf,IAAAD,EAAA,MAAME,EAAM,OAAO,GACvBF,EAAI,MAAME,EAAM,SAASC,EAAyBD,EAAM,QAAQ,CAAC;AAEnE;AASA,SAASE,EAAaC,GAAmBC,MAAmBC,GAAa;AAEhE,UAAA;AAAA,IACP,YAAY,MAAM,QAAQ,CAAC,EAAE,SAAS,IAAI,GAAG;AAAA,IAC7CF,EAAU,SAAW,EAAA,SAAS,IAAI,GAAG;AAAA,IACrCG,EAAQF,GAAQ,GAAGC,CAAI;AAAA,EACxB;AACD;AAEO,MAAME,UAA4BC,EAAU;AAAA,EAGlD,YAAYC,GAAoC;AAC/C,UAAM,QAAWA,CAAO,GAHhB,KAAA,SAAA;AAAA,EAAA;AAAA,EAMT,MAAM,KAAK;AAAA,IACV,aAAAC;AAAA,IACA,uBAAAC;AAAA,IACA,sBAAAC;AAAA,IACA,YAAAC,IAAa;AAAA,IACb,cAAAC;AAAA,IACA,4BAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,sBAAAC;AAAA,IACA,aAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,OAAAC;AAAA,EAAA,GAC4B;AAC5B,QAAI,KAAK;AACF,YAAA,IAAI,MAAM,2BAA2B;AAE5C,SAAK,SAAS;AAEd,QAAIC,IAAgBL;AACd,UAAAM,IAAgBN,IAAiBC,IAAuB,GACxDM,IAAkBC,EAA4BC,CAAW;AAC/D,UAAMF,EAAgB,YAAY;AAE9B,QA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EAAA;AAElC;AAEA,MAAM,CAACD,GAAaE,CAAW,IAAIC;AAAA,EAClC,IAAI5B,EAAoB,IAAI6B,GAA2B;AAAA,EACvD;AAAA,EACAX;AACD;AAGAA,EAAY,YAAY,2BAA2B;"}
1
+ {"version":3,"file":"worker-thread.js","sources":["../../../../packages/playground/cli/src/worker-thread.ts"],"sourcesContent":["import type { FileLockManager } from '@php-wasm/node';\nimport { loadNodeRuntime } from '@php-wasm/node';\nimport { EmscriptenDownloadMonitor } from '@php-wasm/progress';\nimport type { RemoteAPI, SupportedPHPVersion } from '@php-wasm/universal';\nimport {\n\tPHPWorker,\n\tconsumeAPI,\n\tconsumeAPISync,\n\texposeAPI,\n\tsandboxedSpawnHandlerFactory,\n} from '@php-wasm/universal';\nimport { sprintf } from '@php-wasm/util';\nimport { RecommendedPHPVersion } from '@wp-playground/common';\nimport { bootWordPress } from '@wp-playground/wordpress';\nimport { rootCertificates } from 'tls';\nimport { jspi } from 'wasm-feature-detect';\nimport { MessageChannel, type MessagePort, parentPort } from 'worker_threads';\nimport { mountResources } from './mounts';\n\nexport interface Mount {\n\thostPath: string;\n\tvfsPath: string;\n}\n\nexport type PrimaryWorkerBootOptions = {\n\twpVersion?: string;\n\tphpVersion?: SupportedPHPVersion;\n\tabsoluteUrl: string;\n\tmountsBeforeWpInstall: Array<Mount>;\n\tmountsAfterWpInstall: Array<Mount>;\n\twordPressZip?: ArrayBuffer;\n\tsqliteIntegrationPluginZip?: ArrayBuffer;\n\tfirstProcessId: number;\n\tprocessIdSpaceLength: number;\n\tdataSqlPath?: string;\n\tfollowSymlinks: boolean;\n\ttrace: boolean;\n\t/**\n\t * When true, Playground will not send cookies to the client but will manage\n\t * them internally. This can be useful in environments that can't store cookies,\n\t * e.g. VS Code WebView.\n\t *\n\t * Default: false.\n\t */\n\tinternalCookieStore?: boolean;\n\twithXdebug?: boolean;\n};\n\n/**\n * Print trace messages from PHP-WASM.\n *\n * @param {number} processId - The process ID.\n * @param {string} format - The format string.\n * @param {...any} args - The arguments.\n */\nfunction tracePhpWasm(processId: number, format: string, ...args: any[]) {\n\t// eslint-disable-next-line no-console\n\tconsole.log(\n\t\tperformance.now().toFixed(6).padStart(15, '0'),\n\t\tprocessId.toString().padStart(16, '0'),\n\t\tsprintf(format, ...args)\n\t);\n}\n\nexport class PlaygroundCliWorker extends PHPWorker {\n\tbooted = false;\n\tfileLockManager: RemoteAPI<FileLockManager> | FileLockManager | undefined;\n\n\tconstructor(monitor: EmscriptenDownloadMonitor) {\n\t\tsuper(undefined, monitor);\n\t}\n\n\t/**\n\t * Call this method before boot() to use file locking.\n\t *\n\t * This method is separate from boot() to simplify the related Comlink.transferHandlers\n\t * setup – if an argument is a MessagePort, we're transferring it, not copying it.\n\t *\n\t * @see comlink-sync.ts\n\t * @see phpwasm-emscripten-library-file-locking-for-node.js\n\t */\n\tasync useFileLockManager(port: MessagePort) {\n\t\tif (await jspi()) {\n\t\t\t/**\n\t\t\t * If JSPI is available, php.js supports both synchronous and asynchronous locking syscalls.\n\t\t\t * Web browsers, however, only support asynchronous message passing so let's use the\n\t\t\t * asynchronous API. Every method call will return a promise.\n\t\t\t *\n\t\t\t * @see comlink-sync.ts\n\t\t\t * @see phpwasm-emscripten-library-file-locking-for-node.js\n\t\t\t */\n\t\t\tthis.fileLockManager = consumeAPI<FileLockManager>(port);\n\t\t} else {\n\t\t\t/**\n\t\t\t * If JSPI is not available, php.js only supports synchronous locking syscalls.\n\t\t\t * Let's use the synchronous API. Every method call will block this thread\n\t\t\t * until the result is available.\n\t\t\t *\n\t\t\t * @see comlink-sync.ts\n\t\t\t * @see phpwasm-emscripten-library-file-locking-for-node.js\n\t\t\t */\n\t\t\tthis.fileLockManager = await consumeAPISync<FileLockManager>(port);\n\t\t}\n\t}\n\n\tasync boot({\n\t\tabsoluteUrl,\n\t\tmountsBeforeWpInstall,\n\t\tmountsAfterWpInstall,\n\t\tphpVersion = RecommendedPHPVersion,\n\t\twordPressZip,\n\t\tsqliteIntegrationPluginZip,\n\t\tfirstProcessId,\n\t\tprocessIdSpaceLength,\n\t\tdataSqlPath,\n\t\tfollowSymlinks,\n\t\ttrace,\n\t\tinternalCookieStore,\n\t\twithXdebug,\n\t}: PrimaryWorkerBootOptions) {\n\t\tif (this.booted) {\n\t\t\tthrow new Error('Playground already booted');\n\t\t}\n\t\tthis.booted = true;\n\n\t\tlet nextProcessId = firstProcessId;\n\t\tconst lastProcessId = firstProcessId + processIdSpaceLength - 1;\n\n\t\ttry {\n\t\t\tconst constants: Record<string, string | number | boolean | null> =\n\t\t\t\t{\n\t\t\t\t\tWP_DEBUG: true,\n\t\t\t\t\tWP_DEBUG_LOG: true,\n\t\t\t\t\tWP_DEBUG_DISPLAY: false,\n\t\t\t\t};\n\n\t\t\tconst requestHandler = await bootWordPress({\n\t\t\t\tsiteUrl: absoluteUrl,\n\t\t\t\tcreatePhpRuntime: async () => {\n\t\t\t\t\tconst processId = nextProcessId;\n\n\t\t\t\t\tif (nextProcessId < lastProcessId) {\n\t\t\t\t\t\tnextProcessId++;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// We've reached the end of the process ID space. Start over.\n\t\t\t\t\t\tnextProcessId = firstProcessId;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn await loadNodeRuntime(phpVersion, {\n\t\t\t\t\t\temscriptenOptions: {\n\t\t\t\t\t\t\tfileLockManager: this.fileLockManager!,\n\t\t\t\t\t\t\tprocessId,\n\t\t\t\t\t\t\ttrace: trace ? tracePhpWasm : undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tfollowSymlinks,\n\t\t\t\t\t\twithXdebug,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\twordPressZip:\n\t\t\t\t\twordPressZip !== undefined\n\t\t\t\t\t\t? new File([wordPressZip], 'wordpress.zip')\n\t\t\t\t\t\t: undefined,\n\t\t\t\tsqliteIntegrationPluginZip:\n\t\t\t\t\tsqliteIntegrationPluginZip !== undefined\n\t\t\t\t\t\t? new File(\n\t\t\t\t\t\t\t\t[sqliteIntegrationPluginZip],\n\t\t\t\t\t\t\t\t'sqlite-integration-plugin.zip'\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: undefined,\n\t\t\t\tsapiName: 'cli',\n\t\t\t\tcreateFiles: {\n\t\t\t\t\t'/internal/shared/ca-bundle.crt':\n\t\t\t\t\t\trootCertificates.join('\\n'),\n\t\t\t\t},\n\t\t\t\tconstants,\n\t\t\t\tphpIniEntries: {\n\t\t\t\t\t'openssl.cafile': '/internal/shared/ca-bundle.crt',\n\t\t\t\t\tallow_url_fopen: '1',\n\t\t\t\t\tdisable_functions: '',\n\t\t\t\t},\n\t\t\t\thooks: {\n\t\t\t\t\tasync beforeWordPressFiles(php) {\n\t\t\t\t\t\tmountResources(php, mountsBeforeWpInstall);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tcookieStore: internalCookieStore ? undefined : false,\n\t\t\t\tdataSqlPath,\n\t\t\t\tspawnHandler: sandboxedSpawnHandlerFactory,\n\t\t\t});\n\t\t\tthis.__internal_setRequestHandler(requestHandler);\n\n\t\t\tconst primaryPhp = await requestHandler.getPrimaryPhp();\n\t\t\tawait this.setPrimaryPHP(primaryPhp);\n\n\t\t\tmountResources(primaryPhp, mountsAfterWpInstall);\n\n\t\t\tsetApiReady();\n\t\t} catch (e) {\n\t\t\tsetAPIError(e as Error);\n\t\t\tthrow e;\n\t\t}\n\t}\n\n\t// Provide a named disposal method that can be invoked via comlink.\n\tasync dispose() {\n\t\tawait this[Symbol.asyncDispose]();\n\t}\n}\n\nconst phpChannel = new MessageChannel();\n\nconst [setApiReady, setAPIError] = exposeAPI(\n\tnew PlaygroundCliWorker(new EmscriptenDownloadMonitor()),\n\tundefined,\n\tphpChannel.port1\n);\n\nparentPort!.postMessage(\n\t{\n\t\tcommand: 'worker-script-initialized',\n\t\tphpPort: phpChannel.port2,\n\t},\n\t[phpChannel.port2 as any]\n);\n"],"names":["tracePhpWasm","processId","format","args","sprintf","PlaygroundCliWorker","PHPWorker","monitor","port","jspi","consumeAPI","consumeAPISync","absoluteUrl","mountsBeforeWpInstall","mountsAfterWpInstall","phpVersion","RecommendedPHPVersion","wordPressZip","sqliteIntegrationPluginZip","firstProcessId","processIdSpaceLength","dataSqlPath","followSymlinks","trace","internalCookieStore","withXdebug","nextProcessId","lastProcessId","constants","requestHandler","bootWordPress","loadNodeRuntime","rootCertificates","php","mountResources","sandboxedSpawnHandlerFactory","primaryPhp","setApiReady","e","setAPIError","phpChannel","MessageChannel","exposeAPI","EmscriptenDownloadMonitor","parentPort"],"mappings":";;;;;;;;;;AAuDA,SAASA,EAAaC,GAAmBC,MAAmBC,GAAa;AAEhE,UAAA;AAAA,IACP,YAAY,MAAM,QAAQ,CAAC,EAAE,SAAS,IAAI,GAAG;AAAA,IAC7CF,EAAU,SAAW,EAAA,SAAS,IAAI,GAAG;AAAA,IACrCG,EAAQF,GAAQ,GAAGC,CAAI;AAAA,EACxB;AACD;AAEO,MAAME,UAA4BC,EAAU;AAAA,EAIlD,YAAYC,GAAoC;AAC/C,UAAM,QAAWA,CAAO,GAJhB,KAAA,SAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBT,MAAM,mBAAmBC,GAAmB;AACvC,IAAA,MAAMC,MASJ,KAAA,kBAAkBC,EAA4BF,CAAI,IAUlD,KAAA,kBAAkB,MAAMG,EAAgCH,CAAI;AAAA,EAClE;AAAA,EAGD,MAAM,KAAK;AAAA,IACV,aAAAI;AAAA,IACA,uBAAAC;AAAA,IACA,sBAAAC;AAAA,IACA,YAAAC,IAAaC;AAAA,IACb,cAAAC;AAAA,IACA,4BAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,sBAAAC;AAAA,IACA,aAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,OAAAC;AAAA,IACA,qBAAAC;AAAA,IACA,YAAAC;AAAA,EAAA,GAC4B;AAC5B,QAAI,KAAK;AACF,YAAA,IAA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AAoB,GAEnCuB,EAAA;AAAA,aACJC,GAAG;AACX,YAAAC,EAAYD,CAAU,GAChBA;AAAA,IAAA;AAAA,EACP;AAAA;AAAA,EAID,MAAM,UAAU;AACT,UAAA,KAAK,OAAO,YAAY,EAAE;AAAA,EAAA;AAElC;AAEA,MAAME,IAAa,IAAIC,EAAe,GAEhC,CAACJ,GAAaE,CAAW,IAAIG;AAAA,EAClC,IAAIrC,EAAoB,IAAIsC,GAA2B;AAAA,EACvD;AAAA,EACAH,EAAW;AACZ;AAEAI,EAAY;AAAA,EACX;AAAA,IACC,SAAS;AAAA,IACT,SAASJ,EAAW;AAAA,EACrB;AAAA,EACA,CAACA,EAAW,KAAY;AACzB;"}
@@ -1,19 +0,0 @@
1
- import type { StepDefinition } from '@wp-playground/blueprints';
2
- import type { RunCLIArgs } from './run-cli';
3
- import type { Mount } from './mount';
4
- export declare function expandAutoMounts(args: RunCLIArgs): RunCLIArgs;
5
- export declare function containsFullWordPressInstallation(path: string): boolean;
6
- export declare function containsWpContentDirectories(path: string): boolean;
7
- export declare function isThemeDirectory(path: string): boolean;
8
- export declare function isPluginDirectory(path: string): boolean;
9
- /**
10
- * Returns a list of files and directories in the wp-content directory
11
- * to be mounted individually.
12
- *
13
- * This is needed because WordPress needs to be able to write to the
14
- * wp-content directory without Playground modifying the OS filesystem.
15
- *
16
- * See expandAutoMounts for more details.
17
- */
18
- export declare function wpContentMounts(wpContentDir: string): Mount[];
19
- export declare function getSteps(path: string): StepDefinition[];