From 2a8f5598c1985a226b71f055f3411b1be4594d00 Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Thu, 18 Dec 2025 13:35:23 +0000 Subject: [PATCH] refactor(bazel): replace yargs with node:util.parseArgs for CLI argument parsing Use the node.js built-in args parser. --- bazel/http-server/BUILD.bazel | 2 - bazel/http-server/index.bzl | 6 +-- bazel/http-server/main.mts | 63 ++++++++++++++++++--------- bazel/http-server/test/server-test.ts | 1 + bazel/package.json | 2 - pnpm-lock.yaml | 6 --- 6 files changed, 47 insertions(+), 33 deletions(-) diff --git a/bazel/http-server/BUILD.bazel b/bazel/http-server/BUILD.bazel index 7d0b29d85..1bea12abd 100644 --- a/bazel/http-server/BUILD.bazel +++ b/bazel/http-server/BUILD.bazel @@ -18,10 +18,8 @@ ts_project( "//bazel:node_modules/@types/browser-sync", "//bazel:node_modules/@types/node", "//bazel:node_modules/@types/send", - "//bazel:node_modules/@types/yargs", "//bazel:node_modules/browser-sync", "//bazel:node_modules/send", - "//bazel:node_modules/yargs", ], ) diff --git a/bazel/http-server/index.bzl b/bazel/http-server/index.bzl index 6de1ba653..20c1b737d 100644 --- a/bazel/http-server/index.bzl +++ b/bazel/http-server/index.bzl @@ -43,13 +43,13 @@ def _http_server_rule_impl(ctx): args += "--root-paths '%s' " % root if ctx.attr.history_api_fallback: - args += "--history-api-fallback=true " + args += "--history-api-fallback " if ctx.attr.enable_dev_ui: - args += "--enable-dev-ui=true " + args += "--enable-dev-ui " if ctx.attr.relax_cors: - args += "--relax-cors=true " + args += "--relax-cors " for variable_name in ctx.attr.environment_variables: args += "--environment-variables '%s' " % variable_name diff --git a/bazel/http-server/main.mts b/bazel/http-server/main.mts index a4eca7bfd..dd8921918 100644 --- a/bazel/http-server/main.mts +++ b/bazel/http-server/main.mts @@ -6,33 +6,56 @@ * found in the LICENSE file at https://angular.io/license */ -import yargs from 'yargs'; +import {parseArgs} from 'node:util'; import assert from 'node:assert'; import {HttpServer} from './server.mjs'; import {setupBazelWatcherSupport} from './ibazel.mjs'; +const {values} = parseArgs({ + args: process.argv.slice(2), + strict: true, + allowNegative: true, + options: { + port: { + type: 'string', + default: '4200', + }, + 'history-api-fallback': { + type: 'boolean', + default: false, + }, + 'root-paths': { + type: 'string', + multiple: true, + default: ['./'], + }, + 'environment-variables': { + type: 'string', + multiple: true, + default: [], + }, + 'enable-dev-ui': { + type: 'boolean', + default: false, + }, + 'relax-cors': { + type: 'boolean', + default: false, + }, + }, +}); + const { - rootPaths, - historyApiFallback, - enableDevUi, - environmentVariables, + 'root-paths': rootPaths, + 'history-api-fallback': historyApiFallback, + 'enable-dev-ui': enableDevUi, + 'environment-variables': environmentVariables, port: cliPort, - relaxCors, -} = yargs(process.argv.slice(2)) - .strict() - .option('port', { - type: 'number', - default: 4200, - }) - .option('historyApiFallback', {type: 'boolean', default: false}) - .option('rootPaths', {type: 'array', string: true, default: ['']}) - .option('environmentVariables', {type: 'array', string: true, default: []}) - .option('enableDevUi', {type: 'boolean', default: false}) - .option('relaxCors', {type: 'boolean', default: false}) - .parseSync(); - -let port = cliPort; + 'relax-cors': relaxCors, +} = values; + +let port = Number(cliPort); // Process environment port always overrides the CLI, or rule attribute-specified port. if (process.env.PORT !== undefined) { port = Number(process.env.PORT); diff --git a/bazel/http-server/test/server-test.ts b/bazel/http-server/test/server-test.ts index 6c06bfada..8ce5524bd 100644 --- a/bazel/http-server/test/server-test.ts +++ b/bazel/http-server/test/server-test.ts @@ -53,6 +53,7 @@ async function runTest() { // Wait for server to be ready, regardless of status code (404/200 or else) await waitOn({ resources: [`http-get://${serverHost}`], + timeout: 20_000, headers: { 'accept': 'text/html', }, diff --git a/bazel/package.json b/bazel/package.json index 0216e502b..070fcf2d9 100644 --- a/bazel/package.json +++ b/bazel/package.json @@ -9,7 +9,6 @@ "@types/send": "1.2.1", "@types/wait-on": "^5.3.4", "@types/source-map-support": "0.5.10", - "@types/yargs": "17.0.35", "browser-sync": "3.0.4", "get-tsconfig": "4.13.0", "piscina": "^5.0.0", @@ -17,7 +16,6 @@ "true-case-path": "2.2.1", "typescript": "5.9.3", "wait-on": "^9.0.0", - "yargs": "18.0.0", "protractor": "7.0.0", "semver": "7.7.3", "selenium-webdriver": "4.39.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 120aa8075..28e6ea409 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -214,9 +214,6 @@ importers: '@types/wait-on': specifier: ^5.3.4 version: 5.3.4 - '@types/yargs': - specifier: 17.0.35 - version: 17.0.35 browser-sync: specifier: 3.0.4 version: 3.0.4(bufferutil@4.0.9)(utf-8-validate@6.0.5) @@ -253,9 +250,6 @@ importers: wait-on: specifier: ^9.0.0 version: 9.0.3 - yargs: - specifier: 18.0.0 - version: 18.0.0 bazel/spec-bundling/test: dependencies: