Skip to content

Commit 980bbb1

Browse files
authored
Revert "Add the launch browser flag to CLI" (#24)
Reverts Automattic/wordpress-playground-private#18 which adds a platform-level feature "open in the system browser". It is a useful feature; it just doesn't seem like a good fit at the platform level. There are too many OS and JS runtime combinations that we can reasonably test. It's easy to imagine reports saying it doesn't work on Node 18 on Linux Arch, and there's not much value in spending time solving this type of error. Case in point: the original PR already adds an exception for GitHub codespaces. We would inevitably see more exceptions and special rules for other online platforms. Let's not go there at all and leave it to the API consumers. Every CLI consumer is free to implement that feature on their own or use a ready package. Let's leave it to them. For the Playground platform, it's less about "what can we add" and more about "what can we leave out?" cc @bgrgicak @zaerl
1 parent 3a258e1 commit 980bbb1

File tree

2 files changed

+15
-77
lines changed

2 files changed

+15
-77
lines changed

packages/playground/cli/src/cli.ts

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { errorLogPath, logger } from '@php-wasm/logger';
2-
import { createNodeFsMountHandler, loadNodeRuntime } from '@php-wasm/node';
3-
import { EmscriptenDownloadMonitor, ProgressTracker } from '@php-wasm/progress';
1+
import fs from 'fs';
2+
import path from 'path';
3+
import yargs from 'yargs';
4+
import readline from 'readline';
5+
import { startServer } from './server';
46
import {
57
PHP,
68
PHPRequest,
@@ -9,31 +11,25 @@ import {
911
SupportedPHPVersion,
1012
SupportedPHPVersions,
1113
} from '@php-wasm/universal';
14+
import { logger, errorLogPath } from '@php-wasm/logger';
1215
import {
1316
Blueprint,
1417
compileBlueprint,
1518
runBlueprintSteps,
1619
} from '@wp-playground/blueprints';
20+
import { isValidWordPressSlug } from './is-valid-wordpress-slug';
21+
import { EmscriptenDownloadMonitor, ProgressTracker } from '@php-wasm/progress';
22+
import { createNodeFsMountHandler, loadNodeRuntime } from '@php-wasm/node';
1723
import { RecommendedPHPVersion, zipDirectory } from '@wp-playground/common';
18-
import {
19-
bootWordPress,
20-
resolveWordPressRelease,
21-
} from '@wp-playground/wordpress';
22-
import { spawn, SpawnOptionsWithoutStdio } from 'child_process';
23-
import fs from 'fs';
24-
import path from 'path';
25-
import readline from 'readline';
24+
import { bootWordPress } from '@wp-playground/wordpress';
2625
import { rootCertificates } from 'tls';
27-
import yargs from 'yargs';
2826
import {
2927
CACHE_FOLDER,
3028
cachedDownload,
3129
fetchSqliteIntegration,
3230
readAsFile,
3331
} from './download';
34-
import { isGitHubCodespace } from './github-codespaces';
35-
import { isValidWordPressSlug } from './is-valid-wordpress-slug';
36-
import { startServer } from './server';
32+
import { resolveWordPressRelease } from '@wp-playground/wordpress';
3733
export interface Mount {
3834
hostPath: string;
3935
vfsPath: string;
@@ -44,7 +40,7 @@ async function run() {
4440
* @TODO This looks similar to Query API args https://wordpress.github.io/wordpress-playground/developers/apis/query-api/
4541
* Perhaps the two could be handled by the same code?
4642
*/
47-
const yargsObject = yargs(process.argv.slice(2))
43+
const yargsObject = await yargs(process.argv.slice(2))
4844
.usage('Usage: wp-playground <command> [options]')
4945
.positional('command', {
5046
describe: 'Command to run',
@@ -80,7 +76,7 @@ async function run() {
8076
type: 'array',
8177
string: true,
8278
})
83-
.option('mount-before-install', {
79+
.option('mountBeforeInstall', {
8480
describe:
8581
'Mount a directory to the PHP runtime before installing WordPress. You can provide --mount-before-install multiple times. Format: /host/path:/vfs/path',
8682
type: 'array',
@@ -95,16 +91,12 @@ async function run() {
9591
describe: 'Blueprint to execute.',
9692
type: 'string',
9793
})
98-
.option('skip-wordpress-setup', {
94+
.option('skipWordPressSetup', {
9995
describe:
10096
'Do not download, unzip, and install WordPress. Useful for mounting a pre-configured WordPress directory at /wordpress.',
10197
type: 'boolean',
10298
default: false,
10399
})
104-
.deprecateOption(
105-
'skipWordPressSetup',
106-
'Use --skip-wordpress-setup instead.'
107-
)
108100
.option('quiet', {
109101
describe: 'Do not output logs and progress messages.',
110102
type: 'boolean',
@@ -116,11 +108,6 @@ async function run() {
116108
type: 'boolean',
117109
default: false,
118110
})
119-
.option('launch-browser', {
120-
describe: 'Launch the default browser after starting the server.',
121-
type: 'boolean',
122-
default: false,
123-
})
124111
.showHelpOnFail(false)
125112
.check((args) => {
126113
if (args.wp !== undefined && !isValidWordPressSlug(args.wp)) {
@@ -257,42 +244,6 @@ async function run() {
257244
});
258245
}
259246

260-
/**
261-
* Open the default browser at the end of the process.
262-
*
263-
* If the current environment is a GitHub Codespace, the browser is not opened.
264-
*
265-
* @param url
266-
*/
267-
function openInDefaultBrowser(url: string): void {
268-
if (isGitHubCodespace()) {
269-
return;
270-
}
271-
272-
let cmd: string, args: string[] | SpawnOptionsWithoutStdio;
273-
switch (process.platform) {
274-
case 'darwin':
275-
cmd = 'open';
276-
args = [url];
277-
break;
278-
case 'linux':
279-
cmd = 'xdg-open';
280-
args = [url];
281-
break;
282-
case 'win32':
283-
cmd = 'cmd';
284-
args = ['/c', `start ${url}`];
285-
break;
286-
default:
287-
logger.log(`Platform '${process.platform}' not supported`);
288-
return;
289-
}
290-
291-
spawn(cmd, args).on('error', function (err: any) {
292-
logger.error(err.message);
293-
});
294-
}
295-
296247
const command = args._[0] as string;
297248
if (!['run-blueprint', 'server', 'build-snapshot'].includes(command)) {
298249
yargsObject.showHelp();
@@ -314,7 +265,7 @@ async function run() {
314265
logger.log(`Setting up WordPress ${args.wp}`);
315266
let wpDetails: any = undefined;
316267
const monitor = new EmscriptenDownloadMonitor();
317-
if (!args.skipWordpressSetup && !args['skipWordPressSetup']) {
268+
if (!args.skipWordPressSetup) {
318269
// @TODO: Rename to FetchProgressMonitor. There's nothing Emscripten
319270
// about that class anymore.
320271
monitor.addEventListener('progress', ((
@@ -435,10 +386,6 @@ async function run() {
435386
process.exit(0);
436387
} else {
437388
logger.log(`WordPress is running on ${absoluteUrl}`);
438-
439-
if (args.launchBrowser) {
440-
openInDefaultBrowser(absoluteUrl);
441-
}
442389
}
443390
} catch (error) {
444391
if (!args.debug) {

packages/playground/cli/src/github-codespaces.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)