Suneha Bose 1f527c033f
Migrate to ESM with esbuild, vitest (#227)
* Migrate to ESM, esbuild, vitest, and update actions/* to latest

- Update @actions/core to 3.x, @actions/exec to 3.x, @actions/io to 3.x
- Replace @vercel/ncc + babel with esbuild (build.mjs) targeting Node 20 ESM
- Replace jest/babel-jest/ts-jest with vitest and @vitest/coverage-v8
- Update tsconfig to NodeNext module resolution with strict mode
- Add explicit .js extensions to all relative imports (NodeNext requirement)
- Fix implicit any index signatures in parseCluster and parseMethod
- Migrate all test files from jest to vi.mock/vi.mocked APIs
- Fix ESM module spying limitations using vi.mock() at module level
- Fix env var test pollution in default.test.ts with afterEach cleanup

* remove build.mjs and update build script

* update pkg lock

* update pkg lock
2026-03-26 17:25:46 -04:00

44 lines
1.2 KiB
TypeScript

import * as fs from 'fs'
import {ExecOptions, exec} from '@actions/exec'
import {spawn} from 'child_process'
const AZ_TIMEOUT_SECONDS: number = 120
/**
* Executes an az cli command
* @param azPath The path to the az tool
* @param args The arguments to be invoked
* @param options Optional options for the command execution
*/
export async function runAzCliCommand(
azPath: string,
args: string[],
options: ExecOptions = {}
) {
await exec(azPath, args, options)
}
/**
* Executes an az cli command that will set the kubeconfig
* @param azPath The path to the az tool
* @param args The arguments to be be invoked
* @param kubeconfigPath The path to the kubeconfig that is updated by the command
* @returns The contents of the kubeconfig
*/
export async function runAzKubeconfigCommandBlocking(
azPath: string,
args: string[],
kubeconfigPath: string
): Promise<string> {
const proc = spawn(azPath, args, {
detached: true,
stdio: 'ignore'
})
proc.unref()
await sleep(AZ_TIMEOUT_SECONDS)
return fs.readFileSync(kubeconfigPath).toString()
}
const sleep = (seconds: number) =>
new Promise((resolve) => setTimeout(resolve, seconds * 1000))