mirror of https://github.com/aminya/setup-cpp
fix: require ~ in untildifyUser
This commit is contained in:
parent
c85b694b1c
commit
1a3ed1a856
|
@ -30,6 +30,7 @@ words:
|
||||||
- dearmor
|
- dearmor
|
||||||
- CPPFLAGS
|
- CPPFLAGS
|
||||||
- cpprc
|
- cpprc
|
||||||
|
- untildified
|
||||||
- Cpython
|
- Cpython
|
||||||
- DCMAKE
|
- DCMAKE
|
||||||
- deps
|
- deps
|
||||||
|
|
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
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
|
@ -18,13 +18,23 @@ npm install --save untildify-user
|
||||||
|
|
||||||
<!-- INSERT GENERATED DOCS START -->
|
<!-- INSERT GENERATED DOCS START -->
|
||||||
|
|
||||||
|
### `userHomeDir` (function)
|
||||||
|
|
||||||
|
**returns:** string
|
||||||
|
|
||||||
### `untildifyUser` (function)
|
### `untildifyUser` (function)
|
||||||
|
|
||||||
|
Replaces a tilde with the user's home directory
|
||||||
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
|
|
||||||
- path (`string`)
|
- path (`string`) - The path to untildify
|
||||||
|
|
||||||
**returns:** any
|
**returns:** string
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
UntildifyUser("~/foo") // /home/user/foo
|
||||||
|
```
|
||||||
|
|
||||||
<!-- INSERT GENERATED DOCS END -->
|
<!-- INSERT GENERATED DOCS END -->
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,7 @@
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"admina": "1.0.1",
|
"admina": "1.0.1"
|
||||||
"untildify": "^5.0.0"
|
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"tilde",
|
"tilde",
|
||||||
|
|
|
@ -1,16 +1,39 @@
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import untildify from "untildify"
|
|
||||||
import { isSudo } from "admina"
|
import { isSudo } from "admina"
|
||||||
|
import { homedir } from "os"
|
||||||
|
|
||||||
export function untildifyUser(path: string) {
|
export function userHomeDir() {
|
||||||
if (isSudo() && typeof process.env.SUDO_USER === "string") {
|
if (isSudo() && typeof process.env.SUDO_USER === "string" && process.env.SUDO_USER !== "") {
|
||||||
// use the user profile even if root
|
// use the user profile even if root
|
||||||
if (process.platform === "darwin") {
|
if (process.platform === "darwin") {
|
||||||
return join("/Users/", process.env.SUDO_USER, path)
|
return join("/Users/", process.env.SUDO_USER)
|
||||||
} else {
|
} else {
|
||||||
return join("/home/", process.env.SUDO_USER, path)
|
return join("/home/", process.env.SUDO_USER)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return untildify(`~/${path}`)
|
const maybeHomeDir = homedir()
|
||||||
|
if (maybeHomeDir === "") {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
return maybeHomeDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tildeRegex = /^~(?=$|\/|\\)/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces a tilde with the user's home directory
|
||||||
|
*
|
||||||
|
* @example UntildifyUser("~/foo") // /home/user/foo
|
||||||
|
*
|
||||||
|
* @param path The path to untildify
|
||||||
|
* @returns The untildified path
|
||||||
|
*/
|
||||||
|
export function untildifyUser(path: string) {
|
||||||
|
const maybeHomeDir = userHomeDir()
|
||||||
|
if (maybeHomeDir === undefined) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.replace(tildeRegex, maybeHomeDir)
|
||||||
|
}
|
||||||
|
|
|
@ -81,14 +81,14 @@ async function getCmake() {
|
||||||
if (cmake === null) {
|
if (cmake === null) {
|
||||||
const { binDir } = await setupCmake(
|
const { binDir } = await setupCmake(
|
||||||
getVersion("cmake", undefined, await ubuntuVersion()),
|
getVersion("cmake", undefined, await ubuntuVersion()),
|
||||||
join(untildifyUser(""), "cmake"),
|
join(untildifyUser("~"), "cmake"),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
cmake = join(binDir, "cmake")
|
cmake = join(binDir, "cmake")
|
||||||
}
|
}
|
||||||
const ninja = which.sync("ninja", { nothrow: true })
|
const ninja = which.sync("ninja", { nothrow: true })
|
||||||
if (ninja === null) {
|
if (ninja === null) {
|
||||||
await setupNinja(getVersion("ninja", undefined, await ubuntuVersion()), join(untildifyUser(""), "ninja"), "")
|
await setupNinja(getVersion("ninja", undefined, await ubuntuVersion()), join(untildifyUser("~"), "ninja"), "")
|
||||||
}
|
}
|
||||||
return cmake
|
return cmake
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ async function main(args: string[]): Promise<number> {
|
||||||
const arch = opts.architecture ?? process.arch
|
const arch = opts.architecture ?? process.arch
|
||||||
|
|
||||||
// the installation dir for the tools that are downloaded directly
|
// the installation dir for the tools that are downloaded directly
|
||||||
const setupCppDir = process.env.SETUP_CPP_DIR ?? untildifyUser("")
|
const setupCppDir = process.env.SETUP_CPP_DIR ?? untildifyUser("~")
|
||||||
|
|
||||||
// report messages
|
// report messages
|
||||||
const successMessages: string[] = []
|
const successMessages: string[] = []
|
||||||
|
|
|
@ -100,7 +100,7 @@ export async function addPath(path: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const cpprc_path = untildifyUser(".cpprc")
|
export const cpprc_path = untildifyUser("~/.cpprc")
|
||||||
|
|
||||||
async function addEnvSystem(name: string, valGiven: string | undefined, options: AddEnvOptions) {
|
async function addEnvSystem(name: string, valGiven: string | undefined, options: AddEnvOptions) {
|
||||||
const val = valGiven ?? ""
|
const val = valGiven ?? ""
|
||||||
|
@ -188,12 +188,12 @@ export async function setupCppInProfile() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// source cpprc in .profile
|
// source cpprc in .profile
|
||||||
const profile_path = untildifyUser(".profile")
|
const profile_path = untildifyUser("~/.profile")
|
||||||
appendFileSync(profile_path, source_cpprc_string)
|
appendFileSync(profile_path, source_cpprc_string)
|
||||||
info(`${source_cpprc_string} was added to ${profile_path}`)
|
info(`${source_cpprc_string} was added to ${profile_path}`)
|
||||||
|
|
||||||
// source cpprc in .bashrc too
|
// source cpprc in .bashrc too
|
||||||
const bashrc_path = untildifyUser(".bashrc")
|
const bashrc_path = untildifyUser("~/.bashrc")
|
||||||
appendFileSync(bashrc_path, source_cpprc_string)
|
appendFileSync(bashrc_path, source_cpprc_string)
|
||||||
info(`${source_cpprc_string} was added to ${bashrc_path}`)
|
info(`${source_cpprc_string} was added to ${bashrc_path}`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in New Issue