Skip to content

Commit feff4fd

Browse files
Copilotmikebarkmin
andcommitted
Address code review feedback
- Remove unused CSS options from build script - Add proper type definition for VS Code API instead of using 'any' - Use crypto.randomBytes() for secure nonce generation instead of Math.random() - Add example.learningmap file for testing Co-authored-by: mikebarkmin <[email protected]>
1 parent 1e8bd49 commit feff4fd

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-20
lines changed

platforms/vscode/.vscodeignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ src/**
66
tsconfig.json
77
node_modules/**
88
*.map
9+
example.learningmap
10+
DEVELOPMENT.md
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"nodes": [
3+
{
4+
"id": "1",
5+
"type": "topic",
6+
"position": {
7+
"x": 250,
8+
"y": 100
9+
},
10+
"data": {
11+
"state": "unlocked",
12+
"label": "Getting Started",
13+
"description": "Learn the basics of creating learningmaps"
14+
}
15+
},
16+
{
17+
"id": "2",
18+
"type": "topic",
19+
"position": {
20+
"x": 250,
21+
"y": 250
22+
},
23+
"data": {
24+
"state": "locked",
25+
"label": "Advanced Topics",
26+
"description": "Deep dive into advanced features"
27+
}
28+
}
29+
],
30+
"edges": [
31+
{
32+
"id": "e1-2",
33+
"source": "1",
34+
"target": "2"
35+
}
36+
],
37+
"settings": {
38+
"title": "Sample Learningmap",
39+
"background": {
40+
"color": "#ffffff"
41+
}
42+
},
43+
"version": 1,
44+
"type": "learningmap",
45+
"source": "vscode-extension"
46+
}

platforms/vscode/src/LearningmapEditorProvider.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import * as crypto from 'crypto';
23

34
/**
45
* Provider for learningmap custom editor.
@@ -138,10 +139,5 @@ export class LearningmapEditorProvider implements vscode.CustomTextEditorProvide
138139
}
139140

140141
function getNonce() {
141-
let text = '';
142-
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
143-
for (let i = 0; i < 32; i++) {
144-
text += possible.charAt(Math.floor(Math.random() * possible.length));
145-
}
146-
return text;
142+
return crypto.randomBytes(16).toString('hex');
147143
}

platforms/vscode/src/webview.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ import { createRoot } from 'react-dom/client';
33
import { LearningMapEditor, useEditorStore, RoadmapData } from '@learningmap/learningmap';
44
import '@learningmap/learningmap/index.css';
55

6-
// VS Code API
7-
declare const acquireVsCodeApi: any;
6+
// VS Code API type
7+
interface VSCodeApi {
8+
postMessage(message: any): void;
9+
setState(state: any): void;
10+
getState(): any;
11+
}
12+
13+
// VS Code API - this is provided by VS Code in webview context
14+
declare function acquireVsCodeApi(): VSCodeApi;
815
const vscode = acquireVsCodeApi();
916

1017
interface VSCodeMessage {

scripts/build-vscode.mjs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ const webviewOptions = {
5555
},
5656
};
5757

58-
// Build CSS separately
59-
const cssOptions = {
60-
...commonOptions,
61-
entryPoints: [
62-
path.join(__dirname, "../packages/learningmap/dist/index.css"),
63-
],
64-
outfile: path.join(__dirname, "../platforms/vscode/dist/webview.css"),
65-
loader: {
66-
".css": "copy",
67-
},
68-
};
69-
7058
async function build() {
7159
try {
7260
if (isWatch) {

0 commit comments

Comments
 (0)