Skip to content

Commit 7edace4

Browse files
committed
fix: for bash non-login shell sourcing and added npm min-release age
1 parent 84b1051 commit 7edace4

4 files changed

Lines changed: 60 additions & 5 deletions

File tree

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
min-release-age=10080

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codifycli/plugin-core",
3-
"version": "1.2.7",
3+
"version": "1.2.8",
44
"description": "TypeScript library for building Codify plugins to manage system resources (applications, CLI tools, settings) through infrastructure-as-code",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",

src/utils/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,17 @@ export const Utils = {
172172
const homeDir = os.homedir();
173173

174174
if (shell.endsWith('bash')) {
175-
// Linux typically uses .bashrc, macOS uses .bash_profile
176-
if (Utils.isLinux()) {
175+
if (Utils.needsLoginShell()) {
177176
return [
178-
path.join(homeDir, '.bashrc'),
179177
path.join(homeDir, '.bash_profile'),
178+
path.join(homeDir, '.bashrc'),
180179
path.join(homeDir, '.profile'),
181180
];
182181
}
183182

184183
return [
185-
path.join(homeDir, '.bash_profile'),
186184
path.join(homeDir, '.bashrc'),
185+
path.join(homeDir, '.bash_profile'),
187186
path.join(homeDir, '.profile'),
188187
];
189188
}

src/utils/shell-rc.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os from 'node:os';
2+
import path from 'node:path';
3+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4+
5+
import { Utils } from './index.js';
6+
7+
describe('getShellRcFiles / spawn-flag agreement', () => {
8+
const homeDir = os.homedir();
9+
const originalShell = process.env.SHELL;
10+
11+
beforeEach(() => {
12+
vi.restoreAllMocks();
13+
});
14+
15+
afterEach(() => {
16+
if (originalShell === undefined) {
17+
delete process.env.SHELL;
18+
} else {
19+
process.env.SHELL = originalShell;
20+
}
21+
vi.restoreAllMocks();
22+
});
23+
24+
it('prefers .bashrc for non-login bash on macOS (the CI runner case)', () => {
25+
process.env.SHELL = '/bin/bash';
26+
vi.spyOn(Utils, 'isLinux').mockReturnValue(false);
27+
vi.spyOn(Utils, 'isMacOS').mockReturnValue(true);
28+
29+
expect(Utils.needsLoginShell()).toBe(false);
30+
expect(Utils.getPrimaryShellRc()).toBe(path.join(homeDir, '.bashrc'));
31+
});
32+
33+
it('prefers .bashrc for non-login bash on Linux', () => {
34+
process.env.SHELL = '/bin/bash';
35+
vi.spyOn(Utils, 'isLinux').mockReturnValue(true);
36+
vi.spyOn(Utils, 'isMacOS').mockReturnValue(false);
37+
38+
expect(Utils.needsLoginShell()).toBe(false);
39+
expect(Utils.getPrimaryShellRc()).toBe(path.join(homeDir, '.bashrc'));
40+
});
41+
42+
it('prefers .bash_profile when a login shell is used (SHELL unset)', () => {
43+
delete process.env.SHELL;
44+
vi.spyOn(os, 'userInfo').mockReturnValue({ shell: '/bin/bash' } as ReturnType<typeof os.userInfo>);
45+
46+
expect(Utils.needsLoginShell()).toBe(true);
47+
expect(Utils.getPrimaryShellRc()).toBe(path.join(homeDir, '.bash_profile'));
48+
});
49+
50+
it('prefers .zshrc for zsh, which both login and non-login zsh source', () => {
51+
process.env.SHELL = '/bin/zsh';
52+
53+
expect(Utils.getPrimaryShellRc()).toBe(path.join(homeDir, '.zshrc'));
54+
});
55+
});

0 commit comments

Comments
 (0)