Skip to content

Commit 99174cc

Browse files
committed
wp-now: avoid exposing emscriptenOptions and just onStdout
1 parent da7699d commit 99174cc

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

packages/wp-now/src/execute-wp-cli.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import startWPNow from './wp-now';
1+
import startWPNow, { WPNowOutputOptions } from './wp-now';
22
import { downloadWPCLI } from './download';
33
import { disableOutput } from './output';
44
import getWpCliPath from './get-wp-cli-path';
55
import getWpNowConfig from './config';
66
import { DEFAULT_PHP_VERSION, DEFAULT_WORDPRESS_VERSION } from './constants';
77

8-
export async function executeWPCli(args: string[], emscriptenOptions = {}) {
8+
export async function executeWPCli(
9+
args: string[],
10+
outputOptions?: WPNowOutputOptions
11+
) {
912
await downloadWPCLI();
1013
disableOutput();
1114
const options = await getWpNowConfig({
@@ -18,7 +21,7 @@ export async function executeWPCli(args: string[], emscriptenOptions = {}) {
1821
...options,
1922
numberOfPhpInstances: 2,
2023
},
21-
emscriptenOptions
24+
outputOptions
2225
);
2326
const [, php] = phpInstances;
2427

packages/wp-now/src/tests/wp-now.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,11 @@ describe('wp-cli command', () => {
529529
*/
530530
test('wp-cli displays the version', async () => {
531531
let output = '';
532-
function collectOutput(outputLine: string) {
532+
function onStdout(outputLine: string) {
533533
output += outputLine;
534534
}
535535
await executeWPCli(['cli', 'version'], {
536-
print: collectOutput,
536+
onStdout,
537537
});
538538
expect(output).toMatch(/WP-CLI (\d\.?)+/i);
539539
});

packages/wp-now/src/wp-now.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs-extra';
2-
import { NodePHP } from '@php-wasm/node';
2+
import { NodePHP, PHPLoaderOptions } from '@php-wasm/node';
33
import path from 'path';
44
import { SQLITE_FILENAME } from './constants';
55
import {
@@ -27,6 +27,10 @@ import getWpNowPath from './get-wp-now-path';
2727
import getWordpressVersionsPath from './get-wordpress-versions-path';
2828
import getSqlitePath from './get-sqlite-path';
2929

30+
export interface WPNowOutputOptions {
31+
onStdout?: (data: string) => void;
32+
}
33+
3034
function seemsLikeAPHPFile(path) {
3135
return path.endsWith('.php') || path.includes('.php/');
3236
}
@@ -39,10 +43,11 @@ async function applyToInstances(phpInstances: NodePHP[], callback: Function) {
3943

4044
export default async function startWPNow(
4145
options: Partial<WPNowOptions> = {},
42-
emscriptenOptions = {}
46+
outputOptions: WPNowOutputOptions = {}
4347
): Promise<{ php: NodePHP; phpInstances: NodePHP[]; options: WPNowOptions }> {
4448
const { documentRoot } = options;
45-
const nodePHPOptions = {
49+
const print = outputOptions.onStdout;
50+
const nodePHPOptions: PHPLoaderOptions = {
4651
requestHandler: {
4752
documentRoot,
4853
absoluteUrl: options.absoluteUrl,
@@ -60,7 +65,7 @@ export default async function startWPNow(
6065
}
6166
},
6267
},
63-
emscriptenOptions,
68+
emscriptenOptions: print ? { print } : {},
6469
};
6570

6671
const phpInstances = [];

0 commit comments

Comments
 (0)