Skip to content

Commit 41894e2

Browse files
authored
Rewrite (#35)
* rewrote extension to use modern apis for socket and cache better to avoid high memory and cpu usage
1 parent 69592ce commit 41894e2

33 files changed

+4282
-5133
lines changed

package-lock.json

Lines changed: 2078 additions & 1878 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
},
3434
"icon": "socket-square.png",
3535
"activationEvents": [
36-
"workspaceContains:**/[pP][aA][cC][kK][aA][gG][eE].[jJ][sS][oO][nN]",
37-
"workspaceContains:**/[sS][oO][cC][kK][eE][tT].[yY][mM][lL]",
36+
"workspaceConatains:**/[pP][aA][cC][kK][aA][gG][eE].[jJ][sS][oO][nN]",
3837
"workspaceContains:**/[rR][eE][qQ][uU][iI][rR][eE][mM][eE][nN][tT][sS].[tT][xX][tT]",
3938
"workspaceContains:**/[pP][yY][pP][rR][oO][jJ][eE][cC][tT].[tT][oO][mM][lL]",
4039
"workspaceContains:**/[pP][iI][pP][fF][iI][lL][eE]",
@@ -48,83 +47,41 @@
4847
"main": "./out/main.js",
4948
"homepage": "https://socket.dev",
5049
"contributes": {
51-
"commands": [
52-
{
53-
"command": "socket-security.runReport",
54-
"category": "Socket Security",
55-
"title": "Run Report",
56-
"enablement": "workspaceFolderCount >= 1"
57-
}
58-
],
5950
"configuration": {
6051
"title": "Socket Security",
6152
"properties": {
62-
"socket-security.minIssueLevel": {
63-
"order": 1,
64-
"type": "string",
65-
"default": "low",
66-
"enum": [
67-
"critical",
68-
"high",
69-
"middle",
70-
"low"
71-
],
72-
"description": "Hide all issues that are less important than this level. Note some issues are hidden by default so you may also wish to enable showing all issue types still."
73-
},
74-
"socket-security.errorOverlayThreshold": {
75-
"order": 2,
76-
"type": "number",
77-
"default": 50,
78-
"minimum": 0,
79-
"maximum": 100,
80-
"description": "Show error overlay for any import of a package with a summary score less than this value.",
81-
"examples": [
82-
50
83-
]
84-
},
85-
"socket-security.warnOverlayThreshold": {
86-
"order": 3,
87-
"type": "number",
88-
"default": 80,
89-
"minimum": 0,
90-
"maximum": 100,
91-
"description": "Show overlay for any import of a package with a summary score less than this value.",
92-
"examples": [
93-
80
94-
]
95-
},
96-
"socket-security.reportsEnabled": {
97-
"order": 4,
98-
"type": "boolean",
99-
"default": true,
100-
"description": "Create reports from package manifest files (package.json / package-lock.json) that require sending data remotely. Disabling this will disable all issues but keep scores listed."
101-
},
10253
"socket-security.pythonInterpreter": {
103-
"order": 5,
54+
"order": 1,
10455
"type": "string",
10556
"description": "Path to a Python interpreter to use for Socket dependency analysis.",
10657
"examples": [
10758
"/usr/bin/python"
10859
]
10960
},
11061
"socket-security.goExecutable": {
111-
"order": 6,
62+
"order": 2,
11263
"type": "string",
11364
"description": "Path to a Go executable to use for Socket dependency analysis.",
11465
"examples": [
11566
"/usr/bin/go"
11667
]
11768
}
11869
}
119-
}
70+
},
71+
"commands": [{
72+
"title": "Login",
73+
"category": "Socket Security",
74+
"command": "socket-security.login"
75+
}]
12076
},
12177
"bugs": {
12278
"email": "[email protected]"
12379
},
12480
"publisher": "SocketSecurity",
12581
"scripts": {
12682
"vscode:prepublish": "npm run esbuild -- --minify",
127-
"esbuild-base": "esbuild --bundle --external:vscode --loader:.wasm=binary --loader:.go=file --outdir=out/ --platform=node --sourcemap",
83+
"vscode:uninstall": "node ./src/lifecycle/uninstall.mjs",
84+
"esbuild-base": "esbuild --bundle --external:tree-sitter-java --external:vscode --loader:.wasm=binary --loader:.go=file --loader:.py=text --outdir=out/ --platform=node --sourcemap",
12885
"esbuild": "npm run esbuild-base -- --format=cjs main=src/extension.ts",
12986
"test-compile": "tsc -p ./",
13087
"lint": "eslint \"src/**/*.ts\"",
@@ -133,27 +90,21 @@
13390
},
13491
"dependencies": {
13592
"@babel/parser": "^7.20.7",
93+
"@babel/traverse": "^7.20.7",
94+
"@babel/types": "^7.20.7",
13695
"@socketsecurity/config": "^2.0.0",
13796
"@socketsecurity/registry": "^1.0.66",
138-
"@vscode/vsce": "^2.20.1",
139-
"acorn-walk": "^8.2.0",
140-
"antlr4": "^4.13.0",
141-
"ast-types": "^0.14.2",
142-
"form-data-encoder": "^3.0.0",
143-
"formdata-node": "^5.0.1",
144-
"ini": "^3.0.1",
145-
"json-to-ast": "^2.1.0",
146-
"micromatch": "^4.0.8",
147-
"octokit": "^3.1.2",
148-
"safe-stable-stringify": "^2.4.1",
149-
"semver": "^7.5.2",
150-
"yaml": "^2.2.2"
97+
"@vscode/python-extension": "^1.0.5",
98+
"@vscode/vsce": "^3.6.0",
99+
"ini": "^5.0.0",
100+
"json-to-ast": "^2.1.0"
151101
},
152102
"devDependencies": {
103+
"@types/babel__traverse": "^7.20.7",
153104
"@types/ini": "^1.3.31",
154105
"@types/json-to-ast": "^2.1.2",
155106
"@types/micromatch": "^4.0.2",
156-
"@types/node": "^16.11.7",
107+
"@types/node": "^24.0.15",
157108
"@types/vscode": "^1.26.0",
158109
"@typescript-eslint/eslint-plugin": "^5.42.0",
159110
"@typescript-eslint/parser": "^5.42.0",

src/api.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/////////
2+
// DESIGN NOTES
3+
/////////
4+
//
5+
// We pass apiKeys rather than shared state to avoid certain races, so if a
6+
// workflow starts with 1 API key it is inconvenient to grab an implicitly
7+
// new api key in the middle of the workflow
8+
//
9+
function toAuthHeader(apiKey: string) {
10+
return `Basic ${Buffer.from(`${apiKey}:`).toString('base64url')}`
11+
}
12+
export async function getQuota(apiKey: string) {
13+
const res = await fetch('https://api.socket.dev/v0/settings', {
14+
method: 'POST',
15+
headers: {
16+
Authorization: toAuthHeader(apiKey),
17+
'Content-Type': 'application/json'
18+
}
19+
})
20+
if (res.ok) {
21+
return res.json()
22+
} else {
23+
throw new Error(await res.text())
24+
}
25+
}

0 commit comments

Comments
 (0)