Skip to content

Commit 0c3ca9c

Browse files
committed
Refactor php-wasm-cli xdebug-bridge-cli and playground-cli
1 parent 5eb3f16 commit 0c3ca9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+67
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ jobs:
321321
with:
322322
submodules: true
323323
- uses: ./.github/actions/prepare-playground
324-
- run: packages/playground/cli/tests/test-running-unbuilt-cli.sh
324+
- run: packages/playground/cli/src/tests/test-running-unbuilt-cli.sh
325325

326326
build:
327327
runs-on: ubuntu-latest

packages/php-wasm/cli/src/lib/run-cli.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import { PHP } from '@php-wasm/universal';
1313
import { loadNodeRuntime, useHostFilesystem } from '@php-wasm/node';
1414
import { startBridge } from '@php-wasm/xdebug-bridge';
1515
import path from 'path';
16+
import { logger, LogSeverity } from '@php-wasm/logger';
17+
18+
const LogVerbosity = {
19+
Quiet: { name: 'quiet', severity: LogSeverity.Fatal },
20+
Normal: { name: 'normal', severity: LogSeverity.Info },
21+
Debug: { name: 'debug', severity: LogSeverity.Debug },
22+
} as const;
23+
24+
type LogVerbosity = (typeof LogVerbosity)[keyof typeof LogVerbosity]['name'];
1625

1726
interface CLIDefaults {
1827
directive: string[];
@@ -25,6 +34,8 @@ interface CLIArgs {
2534
directive: string[];
2635
xdebug?: boolean;
2736
experimentalDevtools?: boolean;
37+
verbosity?: LogVerbosity;
38+
help?: boolean;
2839
}
2940

3041
function parseCliArgs(defaults: CLIDefaults) {
@@ -58,6 +69,14 @@ Usage: php-wasm-cli <command> [options]
5869
describe: 'Enable experimental browser development tools.',
5970
default: false,
6071
})
72+
.option('verbosity', {
73+
type: 'string',
74+
describe: 'Output logs',
75+
choices: Object.values(LogVerbosity).map(
76+
(verbosity) => verbosity.name
77+
),
78+
default: 'normal',
79+
})
6180
.strictCommands()
6281
.help()
6382
.epilog(
@@ -112,6 +131,17 @@ export async function parseOptionsAndRunCLI(): Promise<void> {
112131
config: defaultPhpIniPath,
113132
});
114133

134+
if (args.help) {
135+
return;
136+
}
137+
138+
if (args.verbosity) {
139+
const severity = Object.values(LogVerbosity).find(
140+
(v) => v.name === args.verbosity
141+
)!.severity;
142+
logger.setSeverityFilterLevel(severity);
143+
}
144+
115145
// npm scripts set the TMPDIR env variable
116146
// PHP accepts a TMPDIR env variable and expects it to
117147
// be a writable directory within the PHP filesystem.

packages/php-wasm/xdebug-bridge/src/tests/run-cli.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import './mocker';
22
import { vi } from 'vitest';
3-
import { main } from '../lib/run-cli';
3+
import { parseOptionsAndRunCLI } from '../lib/run-cli';
44
import { logger, LogSeverity } from '@php-wasm/logger';
55
import { startBridge } from '../lib/start-bridge';
66
import type { XdebugCDPBridge } from '../lib/xdebug-cdp-bridge';
@@ -26,7 +26,7 @@ describe('CLI', () => {
2626
});
2727

2828
it('calls startBridge with default arguments', async () => {
29-
await main();
29+
await parseOptionsAndRunCLI();
3030

3131
expect(startBridge).toHaveBeenCalledWith({
3232
cdpPort: 9229,
@@ -48,7 +48,7 @@ describe('CLI', () => {
4848
'/var/www'
4949
);
5050

51-
await main();
51+
await parseOptionsAndRunCLI();
5252

5353
expect(startBridge).toHaveBeenCalledWith({
5454
cdpPort: 9229,
@@ -62,7 +62,7 @@ describe('CLI', () => {
6262
process.argv.push('--help');
6363

6464
try {
65-
await main();
65+
await parseOptionsAndRunCLI();
6666
} catch (e: any) {
6767
expect(e.message).toBe('process.exit unexpectedly called with "0"');
6868
}
@@ -73,7 +73,7 @@ describe('CLI', () => {
7373
it('runs cli with verbosity option set to quiet', async () => {
7474
process.argv.push('--verbosity', 'quiet');
7575

76-
await main();
76+
await parseOptionsAndRunCLI();
7777

7878
expect(logger.setSeverityFilterLevel).toHaveBeenCalledWith(
7979
LogSeverity.Fatal
@@ -83,7 +83,7 @@ describe('CLI', () => {
8383
it('runs cli with verbosity option set to normal', async () => {
8484
process.argv.push('--verbosity', 'normal');
8585

86-
await main();
86+
await parseOptionsAndRunCLI();
8787

8888
expect(logger.setSeverityFilterLevel).toHaveBeenCalledWith(
8989
LogSeverity.Info
@@ -93,7 +93,7 @@ describe('CLI', () => {
9393
it('runs cli with verbosity option set to debug', async () => {
9494
process.argv.push('--verbosity', 'debug');
9595

96-
await main();
96+
await parseOptionsAndRunCLI();
9797

9898
expect(logger.setSeverityFilterLevel).toHaveBeenCalledWith(
9999
LogSeverity.Debug

packages/playground/cli/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136
"executor": "@nx/vite:test",
137137
"outputs": ["{workspaceRoot}/coverage/packages/playground/cli"],
138138
"options": {
139-
"passWithNoTests": true,
140139
"reportsDirectory": "../../../coverage/packages/playground/cli"
141140
}
142141
},

packages/playground/cli/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { parseOptionsAndRunCLI } from './run-cli';
1+
import { parseOptionsAndRunCLI } from './lib/run-cli';
22

33
// Do not await this as top-level await is not supported in all environments.
44
parseOptionsAndRunCLI();

packages/playground/cli/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './run-cli';
1+
export * from './lib/run-cli';

packages/playground/cli/src/blueprints-v1/blueprints-v1-handler.ts renamed to packages/playground/cli/src/lib/blueprints-v1/blueprints-v1-handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class BlueprintsV1Handler {
5959
import.meta.dirname,
6060
'..',
6161
'..',
62+
'..',
6263
importedWorkerV1UrlString
6364
);
6465
}

0 commit comments

Comments
 (0)