mirror of https://github.com/aminya/setup-cpp
fix!: rename setup-apt functions to include the name apt
This commit is contained in:
parent
e881f4079c
commit
9d12380389
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -37,10 +37,12 @@ handles adding conditions to source rc file from .bashrc and .profile
|
|||
|
||||
### `escapeString` (function)
|
||||
|
||||
Escape a string for use in a shell command
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- valGiven (`string`)
|
||||
- shouldEscapeSpace (`boolean`)
|
||||
- valGiven (`string`) - The string to escape
|
||||
- shouldEscapeSpace (`boolean`) - Whether to escape spaces in the string
|
||||
|
||||
**returns:** any
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@ import { defaultRcPath, sourceRCInRc } from "./rc-file.js"
|
|||
import { escapeString } from "./utils.js"
|
||||
const { appendFile } = promises
|
||||
|
||||
/**
|
||||
* The options for adding an environment variable
|
||||
*/
|
||||
export type AddEnvOptions = {
|
||||
/** If true, the value will be escaped with quotes and spaces will be escaped with backslash */
|
||||
escapeSpace: boolean
|
||||
|
|
|
@ -7,6 +7,9 @@ import { execPowershell } from "exec-powershell"
|
|||
import { defaultRcPath, sourceRCInRc } from "./rc-file.js"
|
||||
const { appendFile } = promises
|
||||
|
||||
/**
|
||||
* The options for adding a PATH variable
|
||||
*/
|
||||
type AddPathOptions = {
|
||||
/**
|
||||
* The path to the RC file that the PATH variables should be added to.
|
||||
|
|
|
@ -8,6 +8,9 @@ const { appendFile, readFile, writeFile } = promises
|
|||
|
||||
export const defaultRcPath = untildifyUser("~/.bashrc")
|
||||
|
||||
/**
|
||||
* Options for adding an rc file
|
||||
*/
|
||||
export type RcOptions = {
|
||||
/** The path to the RC file that the env variables should be added to. */
|
||||
rcPath: string
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
import escapeSpace from "escape-path-with-spaces"
|
||||
import escapeQuote from "escape-quotes"
|
||||
|
||||
/**
|
||||
* Escape a string for use in a shell command
|
||||
* @param valGiven The string to escape
|
||||
* @param shouldEscapeSpace Whether to escape spaces in the string
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
export function escapeString(valGiven: string, shouldEscapeSpace: boolean = false) {
|
||||
const spaceEscaped = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
|
||||
return escapeQuote(spaceEscaped, "\"", "\\")
|
||||
|
|
|
@ -64,7 +64,7 @@ Check if a package matching a regexp is installed
|
|||
|
||||
**returns:** Promise<boolean>
|
||||
|
||||
### `updateRepos` (function)
|
||||
### `updateAptRepos` (function)
|
||||
|
||||
Update the apt repositories
|
||||
|
||||
|
@ -111,7 +111,7 @@ If nala is installed, use that, otherwise use apt-get
|
|||
|
||||
**returns:** string
|
||||
|
||||
### `getEnv` (function)
|
||||
### `getAptEnv` (function)
|
||||
|
||||
Get the environment variables to use for the apt command
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import { type ExecaError, execa } from "execa"
|
|||
import which from "which"
|
||||
import { addAptKeyViaServer } from "./apt-key.js"
|
||||
import { isAptPackInstalled } from "./is-installed.js"
|
||||
import { updateRepos } from "./update.js"
|
||||
import { updateAptRepos } from "./update.js"
|
||||
|
||||
/**
|
||||
* The information about an installation result
|
||||
|
@ -63,7 +63,7 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
|
|||
|
||||
// Update the repos if needed
|
||||
if (update) {
|
||||
updateRepos(apt)
|
||||
updateAptRepos(apt)
|
||||
didUpdate = true
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,10 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
|
|||
|
||||
// Install
|
||||
try {
|
||||
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall], { ...defaultExecOptions, env: getEnv(apt) })
|
||||
execRootSync(apt, ["install", "--fix-broken", "-y", ...needToInstall], {
|
||||
...defaultExecOptions,
|
||||
env: getAptEnv(apt),
|
||||
})
|
||||
} catch (err) {
|
||||
if (isExecaError(err)) {
|
||||
if (retryErrors.some((error) => err.stderr.includes(error))) {
|
||||
|
@ -93,7 +96,7 @@ export async function installAptPack(packages: AptPackage[], update = false): Pr
|
|||
execRootSync(
|
||||
apt,
|
||||
["install", "--fix-broken", "-y", "-o", aptTimeout, ...needToInstall],
|
||||
{ ...defaultExecOptions, env: getEnv(apt) },
|
||||
{ ...defaultExecOptions, env: getAptEnv(apt) },
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
@ -134,7 +137,7 @@ export function getApt() {
|
|||
* @param apt The apt command to use
|
||||
* @private Used internally
|
||||
*/
|
||||
export function getEnv(apt: string) {
|
||||
export function getAptEnv(apt: string) {
|
||||
const env: NodeJS.ProcessEnv = { ...process.env, DEBIAN_FRONTEND: "noninteractive" }
|
||||
|
||||
if (apt === "nala") {
|
||||
|
@ -185,9 +188,9 @@ async function addRepositories(apt: string, packages: AptPackage[]) {
|
|||
await installAddAptRepo(apt)
|
||||
for (const repo of allRepositories) {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
execRootSync("add-apt-repository", ["-y", "--no-update", repo], { ...defaultExecOptions, env: getEnv(apt) })
|
||||
execRootSync("add-apt-repository", ["-y", "--no-update", repo], { ...defaultExecOptions, env: getAptEnv(apt) })
|
||||
}
|
||||
updateRepos(apt)
|
||||
updateAptRepos(apt)
|
||||
didUpdate = true
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +201,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
|
|||
"search",
|
||||
"--names-only",
|
||||
`^${escapeRegex(name)}-${escapeRegex(version)}$`,
|
||||
], { env: getEnv(apt), stdio: "pipe" })
|
||||
], { env: getAptEnv(apt), stdio: "pipe" })
|
||||
if (stdout.trim() !== "") {
|
||||
return AptPackageType.NameDashVersion
|
||||
}
|
||||
|
@ -206,7 +209,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
|
|||
try {
|
||||
// check if apt-get show can find the version
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`], { env: getEnv(apt) })
|
||||
const { stdout } = await execa("apt-cache", ["show", `${name}=${version}`], { env: getAptEnv(apt) })
|
||||
if (stdout.trim() === "") {
|
||||
return AptPackageType.NameEqualsVersion
|
||||
}
|
||||
|
@ -216,7 +219,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
|
|||
}
|
||||
|
||||
try {
|
||||
const { stdout: showStdout } = await execa("apt-cache", ["show", name], { env: getEnv(apt), stdio: "pipe" })
|
||||
const { stdout: showStdout } = await execa("apt-cache", ["show", name], { env: getAptEnv(apt), stdio: "pipe" })
|
||||
if (showStdout.trim() !== "") {
|
||||
return AptPackageType.Name
|
||||
}
|
||||
|
@ -226,7 +229,7 @@ async function aptPackageType(apt: string, name: string, version: string | undef
|
|||
|
||||
// If apt-cache fails, update the repos and try again
|
||||
if (!didUpdate) {
|
||||
updateRepos(getApt())
|
||||
updateAptRepos(getApt())
|
||||
didUpdate = true
|
||||
return aptPackageType(apt, name, version)
|
||||
}
|
||||
|
@ -258,7 +261,7 @@ async function installAddAptRepo(apt: string) {
|
|||
execRootSync(
|
||||
apt,
|
||||
["install", "-y", "--fix-broken", "-o", aptTimeout, "software-properties-common"],
|
||||
{ ...defaultExecOptions, env: getEnv(apt) },
|
||||
{ ...defaultExecOptions, env: getAptEnv(apt) },
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -266,7 +269,7 @@ async function installAddAptRepo(apt: string) {
|
|||
async function initApt(apt: string) {
|
||||
// Update the repos if needed
|
||||
if (!didUpdate) {
|
||||
updateRepos(apt)
|
||||
updateAptRepos(apt)
|
||||
didUpdate = true
|
||||
}
|
||||
|
||||
|
@ -279,7 +282,7 @@ async function initApt(apt: string) {
|
|||
if (toInstall.length !== 0) {
|
||||
execRootSync(apt, ["install", "-y", "--fix-broken", "-o", aptTimeout, ...toInstall], {
|
||||
...defaultExecOptions,
|
||||
env: getEnv(apt),
|
||||
env: getAptEnv(apt),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { execa } from "execa"
|
||||
import { getEnv } from "./install.js"
|
||||
import { getAptEnv } from "./install.js"
|
||||
|
||||
/**
|
||||
* Check if a package is installed
|
||||
|
@ -9,7 +9,7 @@ import { getEnv } from "./install.js"
|
|||
export async function isAptPackInstalled(pack: string) {
|
||||
try {
|
||||
// check if a package is installed
|
||||
const { stdout } = await execa("dpkg", ["-s", pack], { env: getEnv("apt-get"), stdio: "pipe" })
|
||||
const { stdout } = await execa("dpkg", ["-s", pack], { env: getAptEnv("apt-get"), stdio: "pipe" })
|
||||
if (typeof stdout !== "string") {
|
||||
return false
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ export async function isAptPackInstalled(pack: string) {
|
|||
export async function isAptPackRegexInstalled(regexp: string) {
|
||||
try {
|
||||
// check if a package matching the regexp is installed
|
||||
const { stdout } = await execa("dpkg", ["-l", regexp], { env: getEnv("apt-get"), stdio: "pipe" })
|
||||
const { stdout } = await execa("dpkg", ["-l", regexp], { env: getAptEnv("apt-get"), stdio: "pipe" })
|
||||
if (typeof stdout !== "string") {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { defaultExecOptions, execRootSync } from "admina"
|
||||
import { aptTimeout, getApt, getEnv } from "./install.js"
|
||||
import { aptTimeout, getApt, getAptEnv } from "./install.js"
|
||||
|
||||
/**
|
||||
* Update the apt repositories
|
||||
* @param apt The apt command to use (optional)
|
||||
*/
|
||||
export function updateRepos(apt: string = getApt()) {
|
||||
export function updateAptRepos(apt: string = getApt()) {
|
||||
execRootSync(
|
||||
apt,
|
||||
apt !== "nala" ? ["update", "-y", "-o", aptTimeout] : ["update", "-o", aptTimeout],
|
||||
{ ...defaultExecOptions, env: getEnv(apt) },
|
||||
{ ...defaultExecOptions, env: getAptEnv(apt) },
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue