Skip to content

Commit f89fa04

Browse files
committed
refactor(bazel): replace yargs with node:util.parseArgs for CLI argument parsing
Use the node.js built-in args parser.
1 parent c23dd2d commit f89fa04

File tree

6 files changed

+47
-33
lines changed

6 files changed

+47
-33
lines changed

bazel/http-server/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ ts_project(
1818
"//bazel:node_modules/@types/browser-sync",
1919
"//bazel:node_modules/@types/node",
2020
"//bazel:node_modules/@types/send",
21-
"//bazel:node_modules/@types/yargs",
2221
"//bazel:node_modules/browser-sync",
2322
"//bazel:node_modules/send",
24-
"//bazel:node_modules/yargs",
2523
],
2624
)
2725

bazel/http-server/index.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ def _http_server_rule_impl(ctx):
4343
args += "--root-paths '%s' " % root
4444

4545
if ctx.attr.history_api_fallback:
46-
args += "--history-api-fallback=true "
46+
args += "--history-api-fallback "
4747

4848
if ctx.attr.enable_dev_ui:
49-
args += "--enable-dev-ui=true "
49+
args += "--enable-dev-ui "
5050

5151
if ctx.attr.relax_cors:
52-
args += "--relax-cors=true "
52+
args += "--relax-cors "
5353

5454
for variable_name in ctx.attr.environment_variables:
5555
args += "--environment-variables '%s' " % variable_name

bazel/http-server/main.mts

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,56 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import yargs from 'yargs';
9+
import {parseArgs} from 'node:util';
1010
import assert from 'node:assert';
1111

1212
import {HttpServer} from './server.mjs';
1313
import {setupBazelWatcherSupport} from './ibazel.mjs';
1414

15+
const {values} = parseArgs({
16+
args: process.argv.slice(2),
17+
strict: true,
18+
allowNegative: true,
19+
options: {
20+
port: {
21+
type: 'string',
22+
default: '4200',
23+
},
24+
'history-api-fallback': {
25+
type: 'boolean',
26+
default: false,
27+
},
28+
'root-paths': {
29+
type: 'string',
30+
multiple: true,
31+
default: ['./'],
32+
},
33+
'environment-variables': {
34+
type: 'string',
35+
multiple: true,
36+
default: [],
37+
},
38+
'enable-dev-ui': {
39+
type: 'boolean',
40+
default: false,
41+
},
42+
'relax-cors': {
43+
type: 'boolean',
44+
default: false,
45+
},
46+
},
47+
});
48+
1549
const {
16-
rootPaths,
17-
historyApiFallback,
18-
enableDevUi,
19-
environmentVariables,
50+
'root-paths': rootPaths,
51+
'history-api-fallback': historyApiFallback,
52+
'enable-dev-ui': enableDevUi,
53+
'environment-variables': environmentVariables,
2054
port: cliPort,
21-
relaxCors,
22-
} = yargs(process.argv.slice(2))
23-
.strict()
24-
.option('port', {
25-
type: 'number',
26-
default: 4200,
27-
})
28-
.option('historyApiFallback', {type: 'boolean', default: false})
29-
.option('rootPaths', {type: 'array', string: true, default: ['']})
30-
.option('environmentVariables', {type: 'array', string: true, default: []})
31-
.option('enableDevUi', {type: 'boolean', default: false})
32-
.option('relaxCors', {type: 'boolean', default: false})
33-
.parseSync();
34-
35-
let port = cliPort;
55+
'relax-cors': relaxCors,
56+
} = values;
57+
58+
let port = Number(cliPort);
3659
// Process environment port always overrides the CLI, or rule attribute-specified port.
3760
if (process.env.PORT !== undefined) {
3861
port = Number(process.env.PORT);

bazel/http-server/test/server-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async function runTest() {
5353
// Wait for server to be ready, regardless of status code (404/200 or else)
5454
await waitOn({
5555
resources: [`http-get://${serverHost}`],
56+
timeout: 20_000,
5657
headers: {
5758
'accept': 'text/html',
5859
},

bazel/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
"@types/send": "1.2.1",
1010
"@types/wait-on": "^5.3.4",
1111
"@types/source-map-support": "0.5.10",
12-
"@types/yargs": "17.0.35",
1312
"browser-sync": "3.0.4",
1413
"get-tsconfig": "4.13.0",
1514
"piscina": "^5.0.0",
1615
"send": "1.2.1",
1716
"true-case-path": "2.2.1",
1817
"typescript": "5.9.3",
1918
"wait-on": "^9.0.0",
20-
"yargs": "18.0.0",
2119
"protractor": "7.0.0",
2220
"semver": "7.7.3",
2321
"selenium-webdriver": "4.39.0",

pnpm-lock.yaml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)