From e0c21afe580170bc6e888a50006cfedd4223014f Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Thu, 22 Aug 2024 11:30:54 -0700 Subject: [PATCH 1/4] fix: Use @libs/xml over xml2js for tiff parsing --- bids-validator/deno.json | 2 +- bids-validator/src/files/tiff.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bids-validator/deno.json b/bids-validator/deno.json index 502b343b3..a5f7a209f 100644 --- a/bids-validator/deno.json +++ b/bids-validator/deno.json @@ -34,7 +34,7 @@ "@hed/validator": "npm:hed-validator@3.15.4", "@ignore": "npm:ignore@5.3.2", "@mango/nifti": "npm:nifti-reader-js@0.6.8", - "@xml2js": "npm:xml2js@0.6.2" + "@libs/xml": "jsr:@libs/xml@5.4.13" }, "tasks": { "test": "deno test -A src/tests/" diff --git a/bids-validator/src/files/tiff.ts b/bids-validator/src/files/tiff.ts index 01a0ec50c..ba828564a 100644 --- a/bids-validator/src/files/tiff.ts +++ b/bids-validator/src/files/tiff.ts @@ -3,7 +3,7 @@ * Module for extracting Tiff metadata */ import { Ome, Tiff } from '@bids/schema/context' -import * as xml2js from '@xml2js' +import * as XML from '@libs/xml' import { BIDSFile } from '../types/filetree.ts' function getImageDescription( @@ -57,19 +57,19 @@ export async function parseTIFF( } const imageDescription = getImageDescription(dataview, littleEndian, version === 42 ? 12 : 20) - const omexml = await xml2js.parseStringPromise(imageDescription || '') as { [key: string]: any } - const Pixels = omexml?.OME?.Image[0]?.Pixels[0]["$"] + const omexml = await XML.parse(imageDescription || '') as { [key: string]: any } + const Pixels = omexml?.OME?.Image?.Pixels if (!Pixels) return { tiff: { version } } return { tiff: { version }, ome: { - PhysicalSizeX: parseFloat(Pixels['PhysicalSizeX']), - PhysicalSizeY: parseFloat(Pixels['PhysicalSizeY']), - PhysicalSizeZ: parseFloat(Pixels['PhysicalSizeZ']), - PhysicalSizeXUnit: Pixels['PhysicalSizeXUnit'], - PhysicalSizeYUnit: Pixels['PhysicalSizeYUnit'], - PhysicalSizeZUnit: Pixels['PhysicalSizeZUnit'], + PhysicalSizeX: parseFloat(Pixels['@PhysicalSizeX']), + PhysicalSizeY: parseFloat(Pixels['@PhysicalSizeY']), + PhysicalSizeZ: parseFloat(Pixels['@PhysicalSizeZ']), + PhysicalSizeXUnit: Pixels['@PhysicalSizeXUnit'], + PhysicalSizeYUnit: Pixels['@PhysicalSizeYUnit'], + PhysicalSizeZUnit: Pixels['@PhysicalSizeZUnit'], }, } } From f4e5ed2df8f5cf826610e31d69c4c1c0b7a30275 Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Fri, 23 Aug 2024 14:29:38 -0700 Subject: [PATCH 2/4] fix(web): Workaround Vite bug with @libs/xml --- web/vite.config.mts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/web/vite.config.mts b/web/vite.config.mts index 14ca82ede..75dd3736d 100644 --- a/web/vite.config.mts +++ b/web/vite.config.mts @@ -6,10 +6,27 @@ import { nodePolyfills } from "npm:vite-plugin-node-polyfills@0.22.0" import "npm:react@^18.2.0" import "npm:react-dom@^18.2.0" +/** + * Vite plugin to hack a bug injected by the default assetImportMetaUrlPlugin + */ +function workaroundAssetImportMetaUrlPluginBug() { + return { + name: "vite-workaround-import-glob", + transform(src, id) { + if (id.includes('validator/main.js')) { + return src.replace(", import.meta.url", "") + } else { + return null + } + } + } +} + // https://vitejs.dev/config/ export default defineConfig({ base: '', plugins: [ + workaroundAssetImportMetaUrlPluginBug(), httpsImports.default(), react(), nodePolyfills({ From 5e74213dbc3756ee1076035d296d1b9e86b6e9c6 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Mon, 26 Aug 2024 11:14:12 -0500 Subject: [PATCH 3/4] check for blacklistModalities in validators/bids.ts, web validator does not initialize options with setup/options.ts function. --- bids-validator/src/validators/bids.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bids-validator/src/validators/bids.ts b/bids-validator/src/validators/bids.ts index 8f1fa12dd..408943e63 100644 --- a/bids-validator/src/validators/bids.ts +++ b/bids-validator/src/validators/bids.ts @@ -108,11 +108,13 @@ export async function validate( const modalitiesRule = schema.rules.modalities as Record const blacklistedDatatypes = new Map() - // Map blacklisted datatypes back to the modality that generated them - for (const modality of options.blacklistModalities) { - const datatypes = modalitiesRule[modality.toLowerCase()]?.datatypes as string[] - for (const datatype of datatypes) { - blacklistedDatatypes.set(datatype, modality) + if (options.blacklistModalities) { + // Map blacklisted datatypes back to the modality that generated them + for (const modality of options.blacklistModalities) { + const datatypes = modalitiesRule[modality.toLowerCase()]?.datatypes as string[] + for (const datatype of datatypes) { + blacklistedDatatypes.set(datatype, modality) + } } } From 786cc939740c27cda1d789c886041e16e76f3e75 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Thu, 22 Aug 2024 16:54:09 -0400 Subject: [PATCH 4/4] test(ci): Make sure JS build can be run --- .github/workflows/deno_tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deno_tests.yml b/.github/workflows/deno_tests.yml index 2e017d410..4f10a3314 100644 --- a/.github/workflows/deno_tests.yml +++ b/.github/workflows/deno_tests.yml @@ -27,6 +27,7 @@ jobs: deno-version: v1.x - run: ./build.ts working-directory: ./bids-validator + - run: deno run -A ./bids-validator/dist/validator/bids-validator.js --version - uses: actions/upload-artifact@v4 with: name: main