MCPcopy Index your code
hub / github.com/codeaashu/claude-code / ensureLocalPackageEnvironment

Function ensureLocalPackageEnvironment

src/utils/localInstaller.ts:56–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54 * Creates the directory, package.json, and wrapper script
55 */
56export async function ensureLocalPackageEnvironment(): Promise<boolean> {
57 try {
58 const localInstallDir = getLocalInstallDir()
59
60 // Create installation directory (recursive, idempotent)
61 await getFsImplementation().mkdir(localInstallDir)
62
63 // Create package.json if it doesn't exist
64 await writeIfMissing(
65 join(localInstallDir, 'package.json'),
66 jsonStringify(
67 { name: 'claude-local', version: '0.0.1', private: true },
68 null,
69 2,
70 ),
71 )
72
73 // Create the wrapper script if it doesn't exist
74 const wrapperPath = join(localInstallDir, 'claude')
75 const created = await writeIfMissing(
76 wrapperPath,
77 `#!/bin/sh\nexec "${localInstallDir}/node_modules/.bin/claude" "$@"`,
78 0o755,
79 )
80 if (created) {
81 // Mode in writeFile is masked by umask; chmod to ensure executable bit.
82 await chmod(wrapperPath, 0o755)
83 }
84
85 return true
86 } catch (error) {
87 logError(error)
88 return false
89 }
90}
91
92/**
93 * Install or update Claude CLI package in the local directory

Callers 1

Calls 5

getLocalInstallDirFunction · 0.85
getFsImplementationFunction · 0.85
writeIfMissingFunction · 0.85
jsonStringifyFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected