tmux-team 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/config.test.ts +45 -0
- package/src/config.ts +26 -1
package/package.json
CHANGED
package/src/config.test.ts
CHANGED
|
@@ -135,6 +135,51 @@ describe('resolvePaths', () => {
|
|
|
135
135
|
expect(paths.globalConfig).toBe('/custom/path/config.json');
|
|
136
136
|
expect(paths.stateFile).toBe('/custom/path/state.json');
|
|
137
137
|
});
|
|
138
|
+
|
|
139
|
+
it('searches up parent directories to find tmux-team.json', () => {
|
|
140
|
+
// Simulating: cwd is /projects/myapp/src/components
|
|
141
|
+
// tmux-team.json exists at /projects/myapp/tmux-team.json
|
|
142
|
+
const nestedCwd = '/projects/myapp/src/components';
|
|
143
|
+
const rootConfig = '/projects/myapp/tmux-team.json';
|
|
144
|
+
|
|
145
|
+
vi.mocked(fs.existsSync).mockImplementation((p) => {
|
|
146
|
+
return p === rootConfig;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const paths = resolvePaths(nestedCwd);
|
|
150
|
+
|
|
151
|
+
// Should find the config in parent directory, not assume it's in cwd
|
|
152
|
+
expect(paths.localConfig).toBe(rootConfig);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('nearest tmux-team.json wins when multiple exist', () => {
|
|
156
|
+
// Simulating: cwd is /projects/myapp/packages/frontend
|
|
157
|
+
// tmux-team.json exists at both:
|
|
158
|
+
// /projects/myapp/tmux-team.json (monorepo root)
|
|
159
|
+
// /projects/myapp/packages/frontend/tmux-team.json (package-specific)
|
|
160
|
+
const nestedCwd = '/projects/myapp/packages/frontend';
|
|
161
|
+
const packageConfig = '/projects/myapp/packages/frontend/tmux-team.json';
|
|
162
|
+
const monorepoConfig = '/projects/myapp/tmux-team.json';
|
|
163
|
+
|
|
164
|
+
vi.mocked(fs.existsSync).mockImplementation((p) => {
|
|
165
|
+
return p === packageConfig || p === monorepoConfig;
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const paths = resolvePaths(nestedCwd);
|
|
169
|
+
|
|
170
|
+
// Nearest config should win (package-specific, not monorepo root)
|
|
171
|
+
expect(paths.localConfig).toBe(packageConfig);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('falls back to cwd when no tmux-team.json found in parents', () => {
|
|
175
|
+
// No tmux-team.json exists anywhere
|
|
176
|
+
vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
177
|
+
|
|
178
|
+
const paths = resolvePaths(mockCwd);
|
|
179
|
+
|
|
180
|
+
// Should fall back to cwd/tmux-team.json (default behavior for init)
|
|
181
|
+
expect(paths.localConfig).toBe(path.join(mockCwd, 'tmux-team.json'));
|
|
182
|
+
});
|
|
138
183
|
});
|
|
139
184
|
|
|
140
185
|
describe('loadConfig', () => {
|
package/src/config.ts
CHANGED
|
@@ -80,12 +80,37 @@ export function resolveGlobalDir(): string {
|
|
|
80
80
|
return xdgPath;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Search up parent directories for a file (like how git finds .git/).
|
|
85
|
+
* Returns the path to the file if found, or null if not found.
|
|
86
|
+
*/
|
|
87
|
+
function findUpward(filename: string, startDir: string): string | null {
|
|
88
|
+
let dir = startDir;
|
|
89
|
+
while (true) {
|
|
90
|
+
const candidate = path.join(dir, filename);
|
|
91
|
+
if (fs.existsSync(candidate)) {
|
|
92
|
+
return candidate;
|
|
93
|
+
}
|
|
94
|
+
const parent = path.dirname(dir);
|
|
95
|
+
if (parent === dir) {
|
|
96
|
+
// Reached filesystem root
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
dir = parent;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
83
103
|
export function resolvePaths(cwd: string = process.cwd()): Paths {
|
|
84
104
|
const globalDir = resolveGlobalDir();
|
|
105
|
+
|
|
106
|
+
// Search up for local config (like .git discovery)
|
|
107
|
+
const localConfigPath =
|
|
108
|
+
findUpward(LOCAL_CONFIG_FILENAME, cwd) ?? path.join(cwd, LOCAL_CONFIG_FILENAME);
|
|
109
|
+
|
|
85
110
|
return {
|
|
86
111
|
globalDir,
|
|
87
112
|
globalConfig: path.join(globalDir, CONFIG_FILENAME),
|
|
88
|
-
localConfig:
|
|
113
|
+
localConfig: localConfigPath,
|
|
89
114
|
stateFile: path.join(globalDir, STATE_FILENAME),
|
|
90
115
|
};
|
|
91
116
|
}
|