@chatcode/chatcode-cli 2.0.4 → 2.0.5
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/bin/cli.js +70 -0
- package/dist/cli.js +3200 -3200
- package/package.json +16 -4
- package/scripts/npm-preinstall.mjs +219 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatcode/chatcode-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "ChatCode CLI command-line coding assistant.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"type": "module",
|
|
@@ -20,11 +20,20 @@
|
|
|
20
20
|
"scan:public-surface": "bun run scripts/public-surface-scan.mjs --fail-on-match",
|
|
21
21
|
"verify:public-surface": "bun run scripts/verify-public-surface-release.mjs",
|
|
22
22
|
"build": "bun run scripts/build.mjs",
|
|
23
|
+
"build:native": "bun run scripts/build.mjs --compile",
|
|
24
|
+
"build:native:all": "bun run scripts/build.mjs --compile --all",
|
|
25
|
+
"build:native:win": "bun run scripts/build.mjs --compile --targets=win32-x64",
|
|
26
|
+
"build:native:pack": "node scripts/pack-native.mjs",
|
|
27
|
+
"preinstall": "node ./scripts/npm-preinstall.mjs",
|
|
28
|
+
"postinstall": "node ./scripts/npm-preinstall.mjs install-shims",
|
|
29
|
+
"preuninstall": "node ./scripts/npm-preinstall.mjs uninstall-shims",
|
|
23
30
|
"prepublishOnly": "bun run build"
|
|
24
31
|
},
|
|
25
32
|
"files": [
|
|
33
|
+
"bin/",
|
|
26
34
|
"dist/cli.js",
|
|
27
35
|
"dist/vendor/",
|
|
36
|
+
"scripts/npm-preinstall.mjs",
|
|
28
37
|
"README.md"
|
|
29
38
|
],
|
|
30
39
|
"publishConfig": {
|
|
@@ -108,8 +117,11 @@
|
|
|
108
117
|
"modifiers-napi": "file:./shims/modifiers-napi",
|
|
109
118
|
"url-handler-napi": "file:./shims/url-handler-napi"
|
|
110
119
|
},
|
|
111
|
-
"
|
|
112
|
-
"chatcode-cli": "
|
|
113
|
-
"
|
|
120
|
+
"optionalDependencies": {
|
|
121
|
+
"@chatcode/chatcode-cli-darwin-arm64": "2.0.5",
|
|
122
|
+
"@chatcode/chatcode-cli-darwin-x64": "2.0.5",
|
|
123
|
+
"@chatcode/chatcode-cli-linux-x64": "2.0.5",
|
|
124
|
+
"@chatcode/chatcode-cli-linux-arm64": "2.0.5",
|
|
125
|
+
"@chatcode/chatcode-cli-win32-x64": "2.0.5"
|
|
114
126
|
}
|
|
115
127
|
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
lstatSync,
|
|
5
|
+
chmodSync,
|
|
6
|
+
mkdirSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
readdirSync,
|
|
9
|
+
readlinkSync,
|
|
10
|
+
rmSync,
|
|
11
|
+
writeFileSync,
|
|
12
|
+
} from 'node:fs'
|
|
13
|
+
import { dirname, join } from 'node:path'
|
|
14
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
15
|
+
|
|
16
|
+
const COMMANDS = ['chatcode-cli', 'cco']
|
|
17
|
+
const WINDOWS_SHIM_SUFFIXES = ['', '.cmd', '.ps1']
|
|
18
|
+
const CHATCODE_PACKAGE_MARKERS = [
|
|
19
|
+
'@chatcode/chatcode-cli',
|
|
20
|
+
'@chatcode\\chatcode-cli',
|
|
21
|
+
'@chatcode/chatcode-cli-test',
|
|
22
|
+
'@chatcode\\chatcode-cli-test',
|
|
23
|
+
'node_modules/@chatcode/chatcode-cli',
|
|
24
|
+
'node_modules\\@chatcode\\chatcode-cli',
|
|
25
|
+
'node_modules/@chatcode/chatcode-cli-test',
|
|
26
|
+
'node_modules\\@chatcode\\chatcode-cli-test',
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
function isGlobalNpmInstall(env = process.env) {
|
|
30
|
+
return env.npm_config_global === 'true' || env.npm_config_global === '1'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function packageRoot() {
|
|
34
|
+
return join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function globalBinDir(prefix = process.env.npm_config_prefix) {
|
|
38
|
+
if (!prefix) return null
|
|
39
|
+
return process.platform === 'win32' ? prefix : join(prefix, 'bin')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function mentionsChatCodePackage(value) {
|
|
43
|
+
return CHATCODE_PACKAGE_MARKERS.some(marker => value.includes(marker))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function fileMentionsChatCodePackage(file) {
|
|
47
|
+
try {
|
|
48
|
+
return mentionsChatCodePackage(readFileSync(file, 'utf8'))
|
|
49
|
+
} catch (_) {
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function symlinkMentionsChatCodePackage(file) {
|
|
55
|
+
try {
|
|
56
|
+
return mentionsChatCodePackage(readlinkSync(file))
|
|
57
|
+
} catch (_) {
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function directoryLooksRemovable(dir) {
|
|
63
|
+
let entries
|
|
64
|
+
try {
|
|
65
|
+
entries = readdirSync(dir)
|
|
66
|
+
} catch (_) {
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
|
+
if (entries.length === 0) return true
|
|
70
|
+
|
|
71
|
+
const packageJson = join(dir, 'package.json')
|
|
72
|
+
if (!existsSync(packageJson)) return false
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const pkg = JSON.parse(readFileSync(packageJson, 'utf8'))
|
|
76
|
+
return (
|
|
77
|
+
pkg.name === '@chatcode/chatcode-cli' ||
|
|
78
|
+
pkg.name === '@chatcode/chatcode-cli-test'
|
|
79
|
+
)
|
|
80
|
+
} catch (_) {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function shouldRemoveCandidate(candidate) {
|
|
86
|
+
let stat
|
|
87
|
+
try {
|
|
88
|
+
stat = lstatSync(candidate)
|
|
89
|
+
} catch (_) {
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (stat.isSymbolicLink()) return symlinkMentionsChatCodePackage(candidate)
|
|
94
|
+
if (stat.isDirectory()) return directoryLooksRemovable(candidate)
|
|
95
|
+
if (!stat.isFile()) return false
|
|
96
|
+
return fileMentionsChatCodePackage(candidate)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function cleanLegacyGlobalShims({
|
|
100
|
+
prefix = globalBinDir(),
|
|
101
|
+
commands = COMMANDS,
|
|
102
|
+
log = () => {},
|
|
103
|
+
} = {}) {
|
|
104
|
+
if (!prefix) return []
|
|
105
|
+
|
|
106
|
+
const removed = []
|
|
107
|
+
for (const command of commands) {
|
|
108
|
+
for (const suffix of WINDOWS_SHIM_SUFFIXES) {
|
|
109
|
+
const candidate = join(prefix, `${command}${suffix}`)
|
|
110
|
+
if (!existsSync(candidate)) continue
|
|
111
|
+
if (!shouldRemoveCandidate(candidate)) continue
|
|
112
|
+
|
|
113
|
+
rmSync(candidate, { recursive: true, force: true })
|
|
114
|
+
removed.push(candidate)
|
|
115
|
+
log(`Removed stale ChatCode CLI npm shim: ${candidate}`)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return removed
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function shellQuote(value) {
|
|
122
|
+
return `'${value.replaceAll("'", "'\\''")}'`
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function powershellQuote(value) {
|
|
126
|
+
return `'${value.replaceAll("'", "''")}'`
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function writePosixShim(file, launcher) {
|
|
130
|
+
writeFileSync(
|
|
131
|
+
file,
|
|
132
|
+
`#!/bin/sh\nexec node ${shellQuote(launcher)} "$@"\n`,
|
|
133
|
+
{ mode: 0o755 },
|
|
134
|
+
)
|
|
135
|
+
try {
|
|
136
|
+
chmodSync(file, 0o755)
|
|
137
|
+
} catch (_) {}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function writeWindowsShims(binDir, command, launcher) {
|
|
141
|
+
const unixLauncher = launcher.replaceAll('\\', '/')
|
|
142
|
+
writeFileSync(
|
|
143
|
+
join(binDir, command),
|
|
144
|
+
`#!/bin/sh\nexec node ${shellQuote(unixLauncher)} "$@"\n`,
|
|
145
|
+
{ mode: 0o755 },
|
|
146
|
+
)
|
|
147
|
+
try {
|
|
148
|
+
chmodSync(join(binDir, command), 0o755)
|
|
149
|
+
} catch (_) {}
|
|
150
|
+
|
|
151
|
+
writeFileSync(
|
|
152
|
+
join(binDir, `${command}.cmd`),
|
|
153
|
+
`@ECHO off\r\nSETLOCAL\r\nnode "${launcher}" %*\r\n`,
|
|
154
|
+
)
|
|
155
|
+
writeFileSync(
|
|
156
|
+
join(binDir, `${command}.ps1`),
|
|
157
|
+
`#!/usr/bin/env pwsh\n& node ${powershellQuote(launcher)} @args\nexit $LASTEXITCODE\n`,
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function installGlobalShims({
|
|
162
|
+
prefix = process.env.npm_config_prefix,
|
|
163
|
+
root = packageRoot(),
|
|
164
|
+
commands = COMMANDS,
|
|
165
|
+
log = () => {},
|
|
166
|
+
} = {}) {
|
|
167
|
+
const binDir = globalBinDir(prefix)
|
|
168
|
+
if (!binDir) return []
|
|
169
|
+
|
|
170
|
+
mkdirSync(binDir, { recursive: true })
|
|
171
|
+
cleanLegacyGlobalShims({ prefix: binDir, commands, log })
|
|
172
|
+
|
|
173
|
+
const launcher = join(root, 'bin', 'cli.js')
|
|
174
|
+
const installed = []
|
|
175
|
+
for (const command of commands) {
|
|
176
|
+
const primary = join(binDir, process.platform === 'win32' ? `${command}.cmd` : command)
|
|
177
|
+
if (existsSync(primary) && !shouldRemoveCandidate(primary)) {
|
|
178
|
+
log(`Skipped existing non-ChatCode command shim: ${primary}`)
|
|
179
|
+
continue
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (process.platform === 'win32') {
|
|
183
|
+
writeWindowsShims(binDir, command, launcher)
|
|
184
|
+
installed.push(join(binDir, command), join(binDir, `${command}.cmd`), join(binDir, `${command}.ps1`))
|
|
185
|
+
} else {
|
|
186
|
+
writePosixShim(join(binDir, command), launcher)
|
|
187
|
+
installed.push(join(binDir, command))
|
|
188
|
+
}
|
|
189
|
+
log(`Installed ChatCode CLI npm shim: ${primary}`)
|
|
190
|
+
}
|
|
191
|
+
return installed
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function uninstallGlobalShims({
|
|
195
|
+
prefix = process.env.npm_config_prefix,
|
|
196
|
+
commands = COMMANDS,
|
|
197
|
+
log = () => {},
|
|
198
|
+
} = {}) {
|
|
199
|
+
return cleanLegacyGlobalShims({ prefix: globalBinDir(prefix), commands, log })
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function main() {
|
|
203
|
+
if (!isGlobalNpmInstall()) return
|
|
204
|
+
|
|
205
|
+
const action = process.argv[2] ?? 'clean'
|
|
206
|
+
if (action === 'install-shims') {
|
|
207
|
+
installGlobalShims({ log: message => console.log(message) })
|
|
208
|
+
return
|
|
209
|
+
}
|
|
210
|
+
if (action === 'uninstall-shims') {
|
|
211
|
+
uninstallGlobalShims({ log: message => console.log(message) })
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
cleanLegacyGlobalShims({ log: message => console.log(message) })
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
218
|
+
main()
|
|
219
|
+
}
|