-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathremove-socket-wrapper.mts
More file actions
40 lines (36 loc) · 1.09 KB
/
remove-socket-wrapper.mts
File metadata and controls
40 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fs from 'node:fs'
import { getDefaultLogger } from '@socketsecurity/lib/logger'
const logger = getDefaultLogger()
export function removeSocketWrapper(filepath: string): void {
let content: string | undefined
try {
content = fs.readFileSync(filepath, 'utf8')
} catch (e) {
logger.fail(`There was an error removing the alias${e ? ':' : '.'}`)
if (e) {
logger.error(e)
}
return
}
const linesWithoutSocketAlias = content
.split('\n')
.filter(
l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"',
)
const updatedContent = linesWithoutSocketAlias.join('\n')
try {
fs.writeFileSync(filepath, updatedContent, 'utf8')
} catch (e) {
if (e) {
logger.error(e)
}
return
}
logger.success(
`The alias was removed from ${filepath}. Running 'npm install' will now run the standard npm command in new terminals going forward.`,
)
logger.log('')
logger.info(
'Note: We cannot deactivate the alias from current terminal sessions. You have to restart existing terminal sessions to finalize this step.',
)
}