Skip to content

Commit 7d83506

Browse files
authored
Merge pull request #3 from jiangxin/jx/minimatch
refactor: use minimatch for env var glob matching
2 parents b631287 + 39028b5 commit 7d83506

4 files changed

Lines changed: 90 additions & 19 deletions

File tree

package-lock.json

Lines changed: 44 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
},
4141
"dependencies": {
4242
"commander": "^13.1.0",
43+
"minimatch": "^10.0.3",
4344
"update-notifier": "^7.3.1"
4445
},
4546
"devDependencies": {

src/commands/exec.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import * as fs from 'fs';
66
import * as path from 'path';
77
import { spawnSync } from 'child_process';
8+
import { minimatch } from 'minimatch';
89

910
// Define environment variable configurations and their corresponding CoDevelopedBy values
1011
// Format: ["key=value", "co-developed-by-string"]
12+
// Use glob patterns for value matching with ** to match any characters including /
1113
const envConfigs: [string, string][] = [
1214
// We can run CLI in IDE (such as Cursor and Qoder), so check CLI env variables first
1315
['CLAUDECODE=1', 'Claude <noreply@anthropic.com>'],
@@ -19,6 +21,14 @@ const envConfigs: [string, string][] = [
1921
['__CFBundleIdentifier=dev.kiro.desktop', 'Kiro <noreply@kiro.dev>'],
2022
['VSCODE_BRAND=Qoder', 'Qoder <noreply@qoder.com>'],
2123
['__CFBundleIdentifier=com.qoder.ide', 'Qoder <noreply@qoder.com>'], // Use this unstable variable until Qoder has a better one
24+
// Check env variables for IDEs in remove development environments
25+
[
26+
'VSCODE_GIT_ASKPASS_MAIN=**/.cursor-server/**',
27+
'Cursor <noreply@cursor.com>',
28+
],
29+
['BROWSER=**/.cursor-server/**', 'Cursor <noreply@cursor.com>'],
30+
['VSCODE_GIT_ASKPASS_MAIN=**/.qoder-server/**', 'Qoder <noreply@qoder.com>'],
31+
['BROWSER=**/.qoder-server/**', 'Qoder <noreply@qoder.com>'],
2232
];
2333

2434
/**
@@ -278,30 +288,26 @@ function getCoDevelopedBy(): string {
278288
continue;
279289
}
280290

281-
// First check for exact match
282-
if (
283-
expectedValue !== null &&
284-
expectedValue !== '*' &&
285-
actualValue === expectedValue
286-
) {
287-
return coDevelopedBy;
288-
}
289-
290-
// For wildcard cases (*) or null for expectedValue, only return CoDevelopedBy
291-
// if the value is actually meaningful
292-
if (expectedValue === '*' || expectedValue === null) {
291+
// For null expectedValue (just check key existence)
292+
if (expectedValue === null) {
293293
// Only return CoDevelopedBy if the actual value is truthy (not empty, not '0', not 'false', etc.)
294294
if (
295295
actualValue &&
296296
actualValue !== '0' &&
297297
actualValue !== 'false' &&
298+
actualValue !== 'off' &&
298299
actualValue !== 'no'
299300
) {
300301
return coDevelopedBy;
301302
}
302303
// Continue to next configuration if value is falsy
303304
continue;
304305
}
306+
307+
// Use minimatch for glob pattern matching
308+
if (minimatch(actualValue, expectedValue, { dot: true })) {
309+
return coDevelopedBy;
310+
}
305311
}
306312

307313
// Return empty string if none of the environment configurations match

test/commands/exec.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,33 @@ describe('exec command utilities', () => {
737737
process.env.CLAUDECODE = '';
738738
expect(getCoDevelopedBy()).toBe('');
739739
});
740+
741+
// Enhanced tests for Cursor and Qoder detection
742+
it('should return Cursor CoDevelopedBy when VSCODE_GIT_ASKPASS_MAIN contains .cursor-server', () => {
743+
clearCoDevelopedByEnvVars();
744+
process.env.VSCODE_GIT_ASKPASS_MAIN =
745+
'/home/user/.cursor-server/bin/askpass-main.js';
746+
expect(getCoDevelopedBy()).toBe('Cursor <noreply@cursor.com>');
747+
});
748+
749+
it('should return Cursor CoDevelopedBy when BROWSER contains .cursor-server', () => {
750+
clearCoDevelopedByEnvVars();
751+
process.env.BROWSER = '/home/user/.cursor-server/bin/helpers/browser.sh';
752+
expect(getCoDevelopedBy()).toBe('Cursor <noreply@cursor.com>');
753+
});
754+
755+
it('should return Qoder CoDevelopedBy when VSCODE_GIT_ASKPASS_MAIN contains .qoder-server', () => {
756+
clearCoDevelopedByEnvVars();
757+
process.env.VSCODE_GIT_ASKPASS_MAIN =
758+
'/home/user/.qoder-server/bin/askpass-main.js';
759+
expect(getCoDevelopedBy()).toBe('Qoder <noreply@qoder.com>');
760+
});
761+
762+
it('should return Qoder CoDevelopedBy when BROWSER contains .qoder-server', () => {
763+
clearCoDevelopedByEnvVars();
764+
process.env.BROWSER = '/home/user/.qoder-server/bin/helpers/browser.sh';
765+
expect(getCoDevelopedBy()).toBe('Qoder <noreply@qoder.com>');
766+
});
740767
});
741768

742769
describe('hasCoDevelopedBy', () => {

0 commit comments

Comments
 (0)