@curl-runner/cli 1.14.0 → 1.16.0

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.
@@ -0,0 +1,123 @@
1
+ // Installation source detection for curl-runner upgrade command
2
+
3
+ export type InstallationSource = 'bun' | 'npm' | 'curl' | 'standalone';
4
+
5
+ export interface DetectionResult {
6
+ source: InstallationSource;
7
+ path: string;
8
+ canAutoUpgrade: boolean;
9
+ }
10
+
11
+ const CURL_INSTALL_PATHS = [
12
+ `${process.env.HOME}/.local/bin/curl-runner`,
13
+ `${process.env.USERPROFILE}\\.local\\bin\\curl-runner.exe`,
14
+ ];
15
+
16
+ export function detectInstallationSource(): DetectionResult {
17
+ const execPath = process.execPath;
18
+ const argv0 = process.argv[0];
19
+
20
+ // Check for bun installation
21
+ if (isBunInstall(execPath)) {
22
+ return {
23
+ source: 'bun',
24
+ path: execPath,
25
+ canAutoUpgrade: true,
26
+ };
27
+ }
28
+
29
+ // Check for npm installation
30
+ if (isNpmInstall(execPath, argv0)) {
31
+ return {
32
+ source: 'npm',
33
+ path: execPath,
34
+ canAutoUpgrade: true,
35
+ };
36
+ }
37
+
38
+ // Check for curl installation (binary in ~/.local/bin)
39
+ if (isCurlInstall(execPath)) {
40
+ return {
41
+ source: 'curl',
42
+ path: execPath,
43
+ canAutoUpgrade: true,
44
+ };
45
+ }
46
+
47
+ // Standalone binary
48
+ return {
49
+ source: 'standalone',
50
+ path: execPath,
51
+ canAutoUpgrade: true,
52
+ };
53
+ }
54
+
55
+ function isBunInstall(execPath: string): boolean {
56
+ // Check if running from bun's global install directory
57
+ if (execPath.includes('.bun')) {
58
+ return true;
59
+ }
60
+ if (process.env.BUN_INSTALL && execPath.includes(process.env.BUN_INSTALL)) {
61
+ return true;
62
+ }
63
+
64
+ // Check for bun-specific paths
65
+ const bunPaths = ['/bun/install/', '/.bun/bin/', '/bun/bin/'];
66
+ return bunPaths.some((p) => execPath.includes(p));
67
+ }
68
+
69
+ function isNpmInstall(execPath: string, argv0: string): boolean {
70
+ // Check for npm global install indicators
71
+ if (execPath.includes('node_modules')) {
72
+ return true;
73
+ }
74
+ if (argv0.includes('node_modules')) {
75
+ return true;
76
+ }
77
+
78
+ // Check for npm config env vars (set when running via npm)
79
+ if (process.env.npm_config_prefix) {
80
+ return true;
81
+ }
82
+ if (process.env.npm_execpath) {
83
+ return true;
84
+ }
85
+
86
+ // Check common npm global paths
87
+ const npmPaths = ['/lib/node_modules/', '/node_modules/.bin/'];
88
+ return npmPaths.some((p) => execPath.includes(p) || argv0.includes(p));
89
+ }
90
+
91
+ function isCurlInstall(execPath: string): boolean {
92
+ // Check if binary is in curl installer's default location
93
+ return CURL_INSTALL_PATHS.some((p) => execPath === p || execPath.startsWith(p));
94
+ }
95
+
96
+ export function getUpgradeCommand(source: InstallationSource): string {
97
+ switch (source) {
98
+ case 'bun':
99
+ return 'bun install -g @curl-runner/cli@latest';
100
+ case 'npm':
101
+ return 'npm install -g @curl-runner/cli@latest';
102
+ case 'curl':
103
+ return 'curl -fsSL https://www.curl-runner.com/install.sh | bash';
104
+ case 'standalone':
105
+ return 'curl -fsSL https://www.curl-runner.com/install.sh | bash';
106
+ }
107
+ }
108
+
109
+ export function getUpgradeCommandWindows(source: InstallationSource): string {
110
+ switch (source) {
111
+ case 'bun':
112
+ return 'bun install -g @curl-runner/cli@latest';
113
+ case 'npm':
114
+ return 'npm install -g @curl-runner/cli@latest';
115
+ case 'curl':
116
+ case 'standalone':
117
+ return 'irm https://www.curl-runner.com/install.ps1 | iex';
118
+ }
119
+ }
120
+
121
+ export function isWindows(): boolean {
122
+ return process.platform === 'win32';
123
+ }
@@ -106,7 +106,7 @@ export class Logger {
106
106
  };
107
107
  }
108
108
 
109
- private color(text: string, color: keyof typeof this.colors): string {
109
+ color(text: string, color: keyof typeof this.colors): string {
110
110
  return `${this.colors[color]}${text}${this.colors.reset}`;
111
111
  }
112
112
 
@@ -69,45 +69,38 @@ export class VersionChecker {
69
69
  private compareVersions(current: string, latest: string): void {
70
70
  if (this.isNewerVersion(current, latest)) {
71
71
  console.log();
72
- console.log(color('╭────────────────────────────────────────────────────────╮', 'yellow'));
72
+ console.log(color('╭───────────────────────────────────────────────╮', 'yellow'));
73
73
  console.log(
74
74
  color('│', 'yellow') +
75
- ' ' +
75
+ ' ' +
76
76
  color('│', 'yellow'),
77
77
  );
78
78
  console.log(
79
79
  color('│', 'yellow') +
80
80
  ' ' +
81
- color('📦 New version available!', 'bright') +
81
+ color('Update available!', 'bright') +
82
82
  ` ${color(current, 'red')} → ${color(latest, 'green')}` +
83
- ' ' +
83
+ ' ' +
84
84
  color('│', 'yellow'),
85
85
  );
86
86
  console.log(
87
87
  color('│', 'yellow') +
88
- ' ' +
88
+ ' ' +
89
89
  color('│', 'yellow'),
90
90
  );
91
91
  console.log(
92
92
  color('│', 'yellow') +
93
- ' Update with: ' +
94
- color('npm install -g @curl-runner/cli', 'cyan') +
95
- ' ' +
93
+ ' Run ' +
94
+ color('curl-runner upgrade', 'cyan') +
95
+ ' to update ' +
96
96
  color('│', 'yellow'),
97
97
  );
98
98
  console.log(
99
99
  color('│', 'yellow') +
100
- ' or: ' +
101
- color('bun install -g @curl-runner/cli', 'cyan') +
102
- ' ' +
100
+ ' ' +
103
101
  color('│', 'yellow'),
104
102
  );
105
- console.log(
106
- color('│', 'yellow') +
107
- ' ' +
108
- color('│', 'yellow'),
109
- );
110
- console.log(color('╰────────────────────────────────────────────────────────╯', 'yellow'));
103
+ console.log(color('╰───────────────────────────────────────────────╯', 'yellow'));
111
104
  console.log();
112
105
  }
113
106
  }