From 7c61f5153bd90f8b44a38cbef381f86288bd2a8b Mon Sep 17 00:00:00 2001 From: Axel Bocciarelli Date: Fri, 19 Apr 2024 11:17:45 +0200 Subject: [PATCH 1/2] Bump min pnpm version --- .github/workflows/lint-build.yml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint-build.yml b/.github/workflows/lint-build.yml index 19997f8..1d86f3c 100644 --- a/.github/workflows/lint-build.yml +++ b/.github/workflows/lint-build.yml @@ -22,7 +22,7 @@ jobs: - name: Install pnpm ⚙️ uses: pnpm/action-setup@v2 with: - version: 8.x + version: 9.x - name: Restore cache 📌 uses: actions/cache@v3 @@ -56,7 +56,7 @@ jobs: - name: Install pnpm ⚙️ uses: pnpm/action-setup@v2 with: - version: 8.x + version: 9.x - name: Restore cache 📌 uses: actions/cache@v3 diff --git a/package.json b/package.json index 5db3ecf..6b51614 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ ], "engines": { "node": "20.x", - "pnpm": "8.x", + "pnpm": "9.x", "vscode": ">=1.86.0" }, "contributes": { From d3721696a378d7830cc49029af66dae3a5d566a5 Mon Sep 17 00:00:00 2001 From: Axel Bocciarelli Date: Fri, 19 Apr 2024 11:18:34 +0200 Subject: [PATCH 2/2] Pass supported plugins through JSON script tag --- app/Viewer.tsx | 3 +-- app/utils.ts | 32 ++++++++++++++++++++------------ src/H5WebViewer.ts | 23 +++++++++++++---------- src/models.ts | 1 - 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/app/Viewer.tsx b/app/Viewer.tsx index 9e795fb..97e429d 100644 --- a/app/Viewer.tsx +++ b/app/Viewer.tsx @@ -10,7 +10,6 @@ interface Props { function Viewer(props: Props) { const { fileInfo } = props; - const { supportedPlugins } = fileInfo; const buffer = suspend(async () => { const res = await fetch(fileInfo.uri); @@ -22,7 +21,7 @@ function Viewer(props: Props) { filename={fileInfo.name} buffer={buffer} getExportURL={getExportURL} - getPlugin={async (name) => getPlugin(supportedPlugins[name])} + getPlugin={getPlugin} > diff --git a/app/utils.ts b/app/utils.ts index 70b2eb9..43b16ee 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -1,10 +1,29 @@ -import type { GetExportURL } from '@h5web/app'; +import { assertNonNull, type GetExportURL } from '@h5web/app'; import { MessageType } from '../src/models.js'; import { vscode } from './vscode-api.js'; +import type { Plugin } from '@h5web/h5wasm'; + +const pluginsScriptElem = document.getElementById('plugins'); +assertNonNull(pluginsScriptElem); + +const PLUGINS = JSON.parse(pluginsScriptElem.innerHTML); // 2 GB = 2 * 1024 * 1024 * 1024 B export const MAX_SIZE_IN_BYTES = 2147483648; +export async function getPlugin( + name: Plugin +): Promise { + const url = PLUGINS[name]; + + if (!url) { + return undefined; + } + + const response = await fetch(url); + return response.arrayBuffer(); +} + export const getExportURL: GetExportURL = ( format, dataset, @@ -56,14 +75,3 @@ export const getExportURL: GetExportURL = ( return undefined; }; - -export async function getPlugin( - url: string | undefined -): Promise { - if (!url) { - return undefined; - } - - const response = await fetch(url); - return response.arrayBuffer(); -} diff --git a/src/H5WebViewer.ts b/src/H5WebViewer.ts index e67a43c..41448d6 100644 --- a/src/H5WebViewer.ts +++ b/src/H5WebViewer.ts @@ -48,22 +48,15 @@ export default class H5WebViewer const name = basename(document.uri.fsPath); const { size } = await workspace.fs.stat(document.uri); - const supportedPlugins = Object.fromEntries( - Object.entries(PLUGINS).map(([name, relativePath]) => { - const pluginUri = Uri.joinPath(extensionUri, 'out', relativePath); - return [name, webview.asWebviewUri(pluginUri).toString()]; - }) - ); - webview.postMessage({ type: MessageType.FileInfo, - data: { uri, name, size, supportedPlugins }, + data: { uri, name, size }, }); function watcher() { webview.postMessage({ type: MessageType.FileInfo, - data: { uri, name, size, supportedPlugins }, + data: { uri, name, size }, }); } @@ -97,7 +90,7 @@ export default class H5WebViewer } private async getHtmlForWebview(webview: Webview): Promise { - const { extensionPath } = this.context; + const { extensionPath, extensionUri } = this.context; const { cspSource } = webview; const manifest = require(join(extensionPath, 'dist/manifest.json')); @@ -110,6 +103,15 @@ export default class H5WebViewer const jsUri = webview.asWebviewUri(jsPathOnDisk); const cssUri = webview.asWebviewUri(cssPathOnDisk); + const plugins = JSON.stringify( + Object.fromEntries( + Object.entries(PLUGINS).map(([name, relativePath]) => { + const pluginUri = Uri.joinPath(extensionUri, 'out', relativePath); + return [name, webview.asWebviewUri(pluginUri).toString()]; + }) + ) + ); + /* * CSP policy: * - `connect-src data:` allows download URLs generated by `getExportURL` when exporting datasets/slices @@ -126,6 +128,7 @@ export default class H5WebViewer > H5Web + diff --git a/src/models.ts b/src/models.ts index a94ce15..b3081d1 100644 --- a/src/models.ts +++ b/src/models.ts @@ -16,7 +16,6 @@ export interface FileInfo { uri: string; name: string; size: number; - supportedPlugins: Record; } export interface Export {