Skip to content

Commit c9007c8

Browse files
committed
fix: avoid rc sourcing loops
1 parent 05bd2b5 commit c9007c8

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

cspell.config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ words:
3030
- choco
3131
- clangd
3232
- cmake
33+
- cmakeformat
3334
- cmakelang
3435
- cmakelint
35-
- llvmorg
36-
- cmakeformat
3736
- cobertura
3837
- copr
3938
- CPATH
@@ -51,6 +50,7 @@ words:
5150
- dyld
5251
- eabi
5352
- envosman
53+
- envosmanrc
5454
- esac
5555
- esbuild
5656
- esmodule
@@ -75,6 +75,7 @@ words:
7575
- libstdc
7676
- libtinfo
7777
- liuli
78+
- llvmorg
7879
- mdimporterdir
7980
- memoizee
8081
- mkdirp

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/envosman/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "envosman",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Manage environment variables, PATH, and rc files",
55
"repository": "https://github.com/aminya/setup-cpp",
66
"homepage": "https://github.com/aminya/setup-cpp/tree/master/packages/envosman",

packages/envosman/src/rc-file.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { promises } from "fs"
2+
import { resolve } from "path"
23
import { grantUserWriteAccess } from "admina"
34
import { info, warning } from "ci-log"
45
import memoize from "memoizee"
56
import { pathExists } from "path-exists"
67
import { untildifyUser } from "untildify-user"
78
const { appendFile, readFile, writeFile } = promises
89

9-
export const defaultRcPath = untildifyUser("~/.bashrc")
10+
export const defaultRcPath = untildifyUser("~/.envosmanrc")
1011

1112
/**
1213
* Options for adding an rc file
@@ -20,15 +21,25 @@ export type RcOptions = {
2021
}
2122

2223
async function sourceRCInRc_(options: RcOptions) {
24+
const bashrc = untildifyUser("~/.bashrc")
25+
const profile = untildifyUser("~/.profile")
26+
27+
const rcPath = resolve(options.rcPath)
28+
29+
// avoid source loops
30+
if (rcPath === bashrc || rcPath === profile) {
31+
return
32+
}
33+
2334
const sourceRcString = options.guard === undefined
24-
? `\nsource "${options.rcPath}"\n`
25-
: `\n# ${options.guard}\nif [[ "$SOURCE_${options.guard.toUpperCase()}RC" != 0 && -f "${options.rcPath}" ]]; then source "${options.rcPath}"; fi\n`
35+
? `\nsource "${rcPath}"\n`
36+
: `\n# ${options.guard}\nif [[ "$SOURCE_${options.guard.toUpperCase()}RC" != 0 && -f "${rcPath}" ]]; then source "${rcPath}"; fi\n`
2637

2738
try {
2839
await Promise.all([
2940
addRCHeader(options),
30-
addSourceToTargetRc(sourceRcString, untildifyUser("~/.bashrc")),
31-
addSourceToTargetRc(sourceRcString, untildifyUser("~/.profile")),
41+
addSourceToTargetRc(sourceRcString, bashrc),
42+
addSourceToTargetRc(sourceRcString, profile),
3243
])
3344
} catch (err) {
3445
warning(`Failed to add ${sourceRcString} to .profile or .bashrc. You should add it manually: ${err}`)

0 commit comments

Comments
 (0)