Skip to content

Commit 0b4870c

Browse files
authored
fix(cli): correct tab completion script path resolution (#879)
Fixes incorrect path to socket-completion.bash when running from built CLI. The rootPath calculation was not accounting for code running from the `build/` directory, causing it to resolve one level too high (`/packages/` instead of `/packages/cli/`). Now checks if __dirname ends with 'dist' or 'build' to correctly determine the root path in all execution contexts. Also fixes import extensions from .mjs to .mts for consistency.
1 parent bb3e6ec commit 0b4870c

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

packages/cli/src/commands/install/setup-tab-completion.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { safeMkdirSync } from '@socketsecurity/lib/fs'
88

99
import ENV from '../../constants/env.mts'
1010
import { homePath } from '../../constants/paths.mts'
11-
import { getBashrcDetails } from '../../utils/cli/completion.mjs'
11+
import { getBashrcDetails } from '../../utils/cli/completion.mts'
1212

1313
const __filename = fileURLToPath(import.meta.url)
1414
const __dirname = path.dirname(__filename)

packages/cli/src/commands/uninstall/teardown-tab-completion.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { homePath } from '../../constants/paths.mts'
55
import {
66
COMPLETION_CMD_PREFIX,
77
getBashrcDetails,
8-
} from '../../utils/cli/completion.mjs'
8+
} from '../../utils/cli/completion.mts'
99

1010
import type { CResult } from '../../types.mts'
1111

packages/cli/src/commands/wrapper/postinstall-wrapper.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { confirm } from '@socketsecurity/lib/stdio/prompts'
77
import { addSocketWrapper } from './add-socket-wrapper.mts'
88
import { checkSocketWrapperSetup } from './check-socket-wrapper-setup.mts'
99
import { getBashRcPath, getZshRcPath } from '../../constants/paths.mts'
10-
import { getBashrcDetails } from '../../utils/cli/completion.mjs'
10+
import { getBashrcDetails } from '../../utils/cli/completion.mts'
1111
import { getErrorCause } from '../../utils/error/errors.mjs'
1212
import { updateInstalledTabCompletionScript } from '../install/setup-tab-completion.mts'
1313
const logger = getDefaultLogger()

packages/cli/src/constants/paths.mts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ const __filename = fileURLToPath(import.meta.url)
3838
const __dirname = path.dirname(__filename)
3939

4040
// Static Base Paths (eagerly computed)
41-
// In unified build, this file is bundled into dist/cli.js, so __dirname will be the dist directory.
41+
// In unified build, this file is bundled into dist/cli.js or build/cli.js, so __dirname will be the dist or build directory.
4242
// In normal build, this file stays in src/constants, so __dirname is src/constants.
4343
export const srcPath = path.resolve(__dirname, '..')
44-
// If srcPath ends with 'dist', we're in the bundled CLI, so rootPath is one level up from dist.
44+
// If __dirname ends with 'dist' or 'build', we're in the bundled CLI, so rootPath is srcPath (one level up from dist/build).
4545
// Otherwise, we're in source code where srcPath is 'src', so rootPath is one level up from src.
46-
export const rootPath = path.resolve(srcPath, '..')
46+
export const rootPath =
47+
__dirname.endsWith('dist') || __dirname.endsWith('build')
48+
? srcPath
49+
: path.resolve(srcPath, '..')
4750
export const distPath = path.join(rootPath, 'dist')
4851
export const configPath = path.join(rootPath, '.config')
4952
export const externalPath = path.join(rootPath, 'external')

0 commit comments

Comments
 (0)