diff --git a/bids-validator/deno.json b/bids-validator/deno.json index f02aa2149..7d82ab302 100644 --- a/bids-validator/deno.json +++ b/bids-validator/deno.json @@ -28,7 +28,7 @@ "@std/log": "jsr:@std/log@0.224.5", "@std/path": "jsr:@std/path@1.0.2", "@ajv": "npm:ajv@8.16.0", - "@bids/schema": "jsr:@bids/schema@0.0.202408141737", + "@bids/schema": "jsr:@bids/schema@0.11.1-dev.2+aa884b7e", "@cliffy/table": "jsr:@cliffy/table@1.0.0-rc.5", "@cliffy/command": "jsr:@cliffy/command@1.0.0-rc.5", "@hed/validator": "npm:hed-validator@3.15.4", diff --git a/bids-validator/src/setup/loadSchema.ts b/bids-validator/src/setup/loadSchema.ts index 3c8a5ba06..a659f8f46 100644 --- a/bids-validator/src/setup/loadSchema.ts +++ b/bids-validator/src/setup/loadSchema.ts @@ -8,34 +8,35 @@ import { setCustomMetadataFormats } from '../validators/json.ts' * * version is ignored when the network cannot be accessed */ -export async function loadSchema(version = 'latest'): Promise { - const versionRegex = /^v\d/ +export async function loadSchema(version?: string): Promise { let schemaUrl = version const bidsSchema = typeof Deno !== 'undefined' ? Deno.env.get('BIDS_SCHEMA') : undefined if (bidsSchema !== undefined) { schemaUrl = bidsSchema - } else if (version === 'latest' || versionRegex.test(version)) { + } else if (version?.match(/^(v\d+\.\d+\.\d+|stable|latest)$/)) { schemaUrl = `https://bids-specification.readthedocs.io/en/${version}/schema.json` } - let schema: Schema | undefined = undefined - try { - const schemaModule = await import(/* @vite-ignore */ schemaUrl, { - with: { type: 'json' }, - }) - schema = new Proxy( - schemaModule.default as object, - objectPathHandler, - ) as Schema - } catch (error) { - // No network access or other errors - console.error(error) - console.error( - `Warning, could not load schema from ${schemaUrl}, falling back to internal version`, - ) - schema = new Proxy( - schemaDefault as object, - objectPathHandler, - ) as Schema + + let schema: Schema = new Proxy( + schemaDefault as object, + objectPathHandler, + ) as Schema + + if (schemaUrl !== undefined) { + try { + const jsonResponse = await fetch(schemaUrl) + const jsonData = await jsonResponse.json() + schema = new Proxy( + jsonData as object, + objectPathHandler, + ) as Schema + } catch (error) { + // No network access or other errors + console.error(error) + console.error( + `Warning, could not load schema from ${schemaUrl}, falling back to internal version`, + ) + } } setCustomMetadataFormats(schema) return schema