@chatcode/chatcode-cli-test 1.0.11 → 1.0.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatcode/chatcode-cli-test",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "ChatCode CLI command-line coding assistant.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "type": "module",
@@ -20,20 +20,11 @@
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",
30
23
  "prepublishOnly": "bun run build"
31
24
  },
32
25
  "files": [
33
- "bin/",
34
26
  "dist/cli.js",
35
27
  "dist/vendor/",
36
- "scripts/npm-preinstall.mjs",
37
28
  "README.md"
38
29
  ],
39
30
  "publishConfig": {
@@ -117,11 +108,8 @@
117
108
  "modifiers-napi": "file:./shims/modifiers-napi",
118
109
  "url-handler-napi": "file:./shims/url-handler-napi"
119
110
  },
120
- "optionalDependencies": {
121
- "@chatcode/chatcode-cli-test-darwin-arm64": "1.0.11",
122
- "@chatcode/chatcode-cli-test-darwin-x64": "1.0.11",
123
- "@chatcode/chatcode-cli-test-linux-x64": "1.0.11",
124
- "@chatcode/chatcode-cli-test-linux-arm64": "1.0.11",
125
- "@chatcode/chatcode-cli-test-win32-x64": "1.0.11"
111
+ "bin": {
112
+ "chatcode-cli": "./dist/cli.js",
113
+ "cco": "./dist/cli.js"
126
114
  }
127
115
  }
package/bin/cli.js DELETED
@@ -1,70 +0,0 @@
1
- #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process'
3
- import { existsSync, readFileSync } from 'node:fs'
4
- import { createRequire } from 'node:module'
5
- import { dirname, join } from 'node:path'
6
- import { fileURLToPath } from 'node:url'
7
-
8
- const require = createRequire(import.meta.url)
9
- const here = dirname(fileURLToPath(import.meta.url))
10
- const root = join(here, '..')
11
- const args = process.argv.slice(2)
12
- const platformKey = `${process.platform}-${process.arch}`
13
- const executableName = process.platform === 'win32' ? 'chatcode-cli.exe' : 'chatcode-cli'
14
- const mainPackageName = JSON.parse(
15
- readFileSync(join(root, 'package.json'), 'utf8'),
16
- ).name
17
-
18
- function resolveOptionalBinary() {
19
- if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return null
20
-
21
- try {
22
- return require.resolve(`${mainPackageName}-${platformKey}/${executableName}`)
23
- } catch (_) {
24
- return null
25
- }
26
- }
27
-
28
- function resolveLocalBinary() {
29
- if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return null
30
-
31
- const localBinary = join(root, 'dist', 'native', platformKey, executableName)
32
- return existsSync(localBinary) ? localBinary : null
33
- }
34
-
35
- function run(command, commandArgs) {
36
- const result = spawnSync(command, commandArgs, {
37
- stdio: 'inherit',
38
- windowsHide: false,
39
- })
40
-
41
- if (result.error) return result.error
42
- if (result.signal) {
43
- process.kill(process.pid, result.signal)
44
- process.exit(1)
45
- }
46
- process.exit(result.status ?? 1)
47
- }
48
-
49
- const nativeBinary = resolveLocalBinary() ?? resolveOptionalBinary()
50
- if (nativeBinary) {
51
- const error = run(nativeBinary, args)
52
- if (error && error.code !== 'ENOENT') {
53
- console.error(`Failed to run native ChatCode CLI binary: ${error.message}`)
54
- process.exit(1)
55
- }
56
- }
57
-
58
- const fallbackCli = join(root, 'dist', 'cli.js')
59
- if (!existsSync(fallbackCli)) {
60
- console.error(
61
- `ChatCode CLI is not installed correctly: missing ${fallbackCli}`,
62
- )
63
- process.exit(1)
64
- }
65
-
66
- const error = run(process.execPath, [fallbackCli, ...args])
67
- if (error) {
68
- console.error(`Failed to run ChatCode CLI: ${error.message}`)
69
- process.exit(1)
70
- }
@@ -1,219 +0,0 @@
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
- }