()
| 70 | * Creates the directory, package.json, and wrapper script |
| 71 | */ |
| 72 | export async function ensureLocalPackageEnvironment(): Promise<boolean> { |
| 73 | try { |
| 74 | const localInstallDir = getLocalInstallDir() |
| 75 | |
| 76 | // Create installation directory (recursive, idempotent) |
| 77 | await getFsImplementation().mkdir(localInstallDir) |
| 78 | |
| 79 | // Create package.json if it doesn't exist |
| 80 | await writeIfMissing( |
| 81 | join(localInstallDir, 'package.json'), |
| 82 | jsonStringify( |
| 83 | { name: 'claude-local', version: '0.0.1', private: true }, |
| 84 | null, |
| 85 | 2, |
| 86 | ), |
| 87 | ) |
| 88 | |
| 89 | // Create the wrapper script if it doesn't exist |
| 90 | const wrapperPath = join(localInstallDir, 'claude') |
| 91 | const created = await writeIfMissing( |
| 92 | wrapperPath, |
| 93 | `#!/bin/sh\nexec "${localInstallDir}/node_modules/.bin/claude" "$@"`, |
| 94 | 0o755, |
| 95 | ) |
| 96 | if (created) { |
| 97 | // Mode in writeFile is masked by umask; chmod to ensure executable bit. |
| 98 | await chmod(wrapperPath, 0o755) |
| 99 | } |
| 100 | |
| 101 | return true |
| 102 | } catch (error) { |
| 103 | logError(error) |
| 104 | return false |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Install or update NCode CLI package in the local directory |
no test coverage detected