Skip to content

Commit 126f995

Browse files
authored
Merge pull request #437 from nicolethoen/update_deps_dec2
fix(deps): bump various dependencies
2 parents 1b8d199 + 22b90d5 commit 126f995

File tree

10 files changed

+4594
-4281
lines changed

10 files changed

+4594
-4281
lines changed

packages/dev/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"tsconfig-paths-webpack-plugin": "^3.3.0",
4545
"webpack": "^5.95.0",
4646
"webpack-cli": "^5.1.1",
47-
"webpack-dev-server": "^5.2.1",
47+
"webpack-dev-server": "^5.2.2",
4848
"yaml": "^1.10.2",
4949
"yaml-loader": "^0.6.0"
5050
}

packages/vscode/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@
5656
"ts-loader": "^9.4.2",
5757
"tslint": "^6.1.3",
5858
"vscode": "^1.1.37",
59-
"webpack": "^5.83.0",
59+
"webpack": "^5.94.0",
6060
"webpack-cli": "^5.1.1"
6161
},
6262
"dependencies": {
63-
"@cloudmosaic/quickstarts": "^0.0.15",
6463
"@patternfly/patternfly": "^6.3.1",
64+
"@patternfly/quickstarts": "^6.0.0-prerelease.0",
6565
"i18next-parser": "^9.3.0",
66-
"js-base64": "^3.6.0",
66+
"js-base64": "3.7.8",
6767
"js-yaml": "^4.0.0",
68-
"react": "^18.2.0",
69-
"react-dom": "^18.2.0"
68+
"react": "18.3.1",
69+
"react-dom": "18.3.1"
7070
}
7171
}

packages/vscode/src/extension.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ export function activate(context: vscode.ExtensionContext) {
1919
const disposable = vscode.commands.registerCommand(
2020
"extension.qsPreview",
2121
() => {
22+
const activeEditor = vscode.window.activeTextEditor;
23+
if (!activeEditor) {
24+
vscode.window.showWarningMessage("Please open a file first to preview quick starts.");
25+
return;
26+
}
2227
view = new ViewLoader(
23-
vscode.window.activeTextEditor?.document.getText() as string,
24-
vscode.window.activeTextEditor?.document.fileName as string,
28+
activeEditor.document.getText(),
29+
activeEditor.document.fileName,
2530
context.extensionPath
2631
);
2732
}

packages/vscode/src/view/ViewLoader.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,18 @@ export default class ViewLoader {
5252
}
5353

5454
private getWebviewContent(config: string, filePath: string): string {
55+
if (!this._panel) {
56+
return "";
57+
}
5558
// Local path to main script run in the webview
5659
const reactAppPathOnDisk = vscode.Uri.file(
5760
path.join(this._extensionPath, "quickstartsPreview", "quickstartsPreview.js")
5861
);
62+
// Use vscode-resource scheme for older VS Code API compatibility
5963
const reactAppUri = reactAppPathOnDisk.with({ scheme: "vscode-resource" });
64+
// Escape the config and filePath for HTML to prevent XSS and syntax errors
65+
const escapedConfig = config.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r");
66+
const escapedFilePath = filePath.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
6067
const html = `<!DOCTYPE html>
6168
<html lang="en">
6269
<head>
@@ -72,8 +79,8 @@ export default class ViewLoader {
7279
7380
<script>
7481
window.acquireVsCodeApi = acquireVsCodeApi;
75-
window.initialData = "${config}";
76-
window.filePath = "${filePath}";
82+
window.initialData = "${escapedConfig}";
83+
window.filePath = "${escapedFilePath}";
7784
</script>
7885
</head>
7986
<body>
@@ -86,7 +93,7 @@ export default class ViewLoader {
8693
}
8794

8895
private encodeContent(text: string, fileName: string): any {
89-
if (fileName.endsWith(".yaml")) {
96+
if (fileName && fileName.endsWith(".yaml")) {
9097
return Base64.encode(JSON.stringify(yamlLoad(text)));
9198
}
9299
return Base64.encode(text);
Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as React from 'react';
12
import { createRoot } from 'react-dom/client';
23
import { QuickStartsPreview } from './quickstarts';
34

@@ -11,14 +12,27 @@ declare global {
1112
}
1213
}
1314

14-
const vscode = window.acquireVsCodeApi();
15-
16-
const root = createRoot(document.getElementById('root'));
17-
18-
root.render(
19-
<QuickStartsPreview
20-
vscode={vscode}
21-
initialData={window.initialData}
22-
filePath={window.filePath}
23-
/>,
24-
);
15+
try {
16+
const vscode = window.acquireVsCodeApi();
17+
const rootElement = document.getElementById('root');
18+
if (!rootElement) {
19+
console.error('Root element not found!');
20+
} else {
21+
const root = createRoot(rootElement);
22+
root.render(
23+
<QuickStartsPreview
24+
vscode={vscode}
25+
initialData={window.initialData}
26+
filePath={window.filePath}
27+
/>,
28+
);
29+
}
30+
} catch (error) {
31+
console.error('Error in webview:', error);
32+
document.body.innerHTML = `<div style="padding: 20px; color: red;">
33+
<h2>Error loading preview</h2>
34+
<pre>${error instanceof Error ? error.stack : String(error)}</pre>
35+
<p>initialData: ${window.initialData ? 'present (' + window.initialData.length + ' chars)' : 'missing'}</p>
36+
<p>filePath: ${window.filePath || 'missing'}</p>
37+
</div>`;
38+
}
Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import '@patternfly/patternfly/base/patternfly-shield-inheritable.css';
1+
import * as React from 'react';
22
import '@patternfly/patternfly/patternfly.min.css';
3-
import '@patternfly/patternfly/utilities/Accessibility/accessibility.css';
43
import '@patternfly/quickstarts/dist/quickstarts.css';
54
import {
6-
ProcedureAsciiDocParser,
5+
ProcQuickStartParser,
76
QuickStartCatalogPage,
87
QuickStartContext,
98
QuickStartDrawer,
@@ -13,27 +12,47 @@ import {
1312
import { Base64 } from 'js-base64';
1413

1514
export const QuickStartsPreview = ({ initialData: config, filePath, vscode }) => {
16-
const decodedConfig = Base64.decode(config);
17-
const allQuickStarts = [];
18-
if (filePath.endsWith('.adoc')) {
19-
allQuickStarts.push(ProcedureAsciiDocParser(decodedConfig));
20-
} else {
21-
allQuickStarts.push(JSON.parse(decodedConfig));
15+
if (!config) {
16+
console.error('No initialData provided!');
17+
return <div style={{ padding: '20px' }}>Error: No data provided to preview</div>;
18+
}
19+
20+
try {
21+
const decodedConfig = Base64.decode(config);
22+
const allQuickStarts = [];
23+
if (filePath && filePath.endsWith('.adoc')) {
24+
const parsedConfig = JSON.parse(decodedConfig);
25+
allQuickStarts.push(ProcQuickStartParser(parsedConfig));
26+
} else {
27+
const parsed = JSON.parse(decodedConfig);
28+
allQuickStarts.push(parsed);
29+
}
30+
31+
const [activeQuickStartID, setActiveQuickStartID] = useLocalStorage('quickstartId', '');
32+
const [allQuickStartStates, setAllQuickStartStates] = useLocalStorage('quickstarts', {});
33+
const valuesForQuickstartContext = useValuesForQuickStartContext({
34+
allQuickStarts,
35+
activeQuickStartID,
36+
setActiveQuickStartID,
37+
allQuickStartStates,
38+
setAllQuickStartStates,
39+
});
40+
return (
41+
<QuickStartContext.Provider value={valuesForQuickstartContext}>
42+
<QuickStartDrawer>
43+
<QuickStartCatalogPage />
44+
</QuickStartDrawer>
45+
</QuickStartContext.Provider>
46+
);
47+
} catch (error) {
48+
console.error('Error in QuickStartsPreview:', error);
49+
return (
50+
<div style={{ padding: '20px', color: 'red' }}>
51+
<h2>Error rendering Quick Start</h2>
52+
<pre>{error instanceof Error ? error.stack : String(error)}</pre>
53+
<p>Config length: {config?.length || 0}</p>
54+
<p>File path: {filePath || 'missing'}</p>
55+
</div>
56+
);
2257
}
23-
const [activeQuickStartID, setActiveQuickStartID] = useLocalStorage('quickstartId', '');
24-
const [allQuickStartStates, setAllQuickStartStates] = useLocalStorage('quickstarts', {});
25-
const valuesForQuickstartContext = useValuesForQuickStartContext({
26-
allQuickStarts,
27-
activeQuickStartID,
28-
setActiveQuickStartID,
29-
allQuickStartStates,
30-
setAllQuickStartStates,
31-
});
32-
return (
33-
<QuickStartContext.Provider value={valuesForQuickstartContext}>
34-
<QuickStartDrawer>
35-
<QuickStartCatalogPage />
36-
</QuickStartDrawer>
37-
</QuickStartContext.Provider>
38-
);
3958
};

packages/vscode/src/view/app/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"noUnusedLocals": true,
1515
"noImplicitReturns": true,
1616
"noFallthroughCasesInSwitch": true,
17-
"experimentalDecorators": true
17+
"experimentalDecorators": true,
18+
"allowSyntheticDefaultImports": true,
19+
"esModuleInterop": true
1820
},
1921
"exclude": [
2022
"node_modules"

packages/vscode/webpack.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ module.exports = {
1212
externals: {
1313
vscode: 'commonjs vscode',
1414
},
15+
optimization: {
16+
splitChunks: false,
17+
},
1518
resolve: {
1619
extensions: ['.js', '.ts', '.tsx'],
20+
alias: {
21+
'react': path.resolve(__dirname, 'node_modules/react'),
22+
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
23+
},
1724
},
1825
module: {
1926
rules: [

0 commit comments

Comments
 (0)