diff --git a/mediapipe/tasks/web/core/fileset_resolver.ts b/mediapipe/tasks/web/core/fileset_resolver.ts index 289ee4d92..34df13999 100644 --- a/mediapipe/tasks/web/core/fileset_resolver.ts +++ b/mediapipe/tasks/web/core/fileset_resolver.ts @@ -47,10 +47,15 @@ async function isSimdSupported(): Promise { } async function createFileset( - taskName: MediapipeTaskCategory, basePath = ''): Promise { + taskName: MediapipeTaskCategory, basePath?: string): Promise { const suffix = await isSimdSupported() ? 'wasm_internal' : 'wasm_nosimd_internal'; + // For backwards compatiblity, we treat an unset `basePath` as a relative + // path. FilesetResolver provides an empty path as a default, which is not + // rewritten to '.'. + basePath = basePath ?? '.'; + return { wasmLoaderPath: `${basePath}/${taskName}_${suffix}.js`, wasmBinaryPath: `${basePath}/${taskName}_${suffix}.wasm`, @@ -93,7 +98,7 @@ export class FilesetResolver { * @return A `WasmFileset` that can be used to initialize MediaPipe Audio * tasks. */ - static forAudioTasks(basePath?: string): Promise { + static forAudioTasks(basePath = ''): Promise { return createFileset('audio', basePath); } @@ -107,7 +112,7 @@ export class FilesetResolver { * @return A `WasmFileset` that can be used to initialize MediaPipe Text * tasks. */ - static forTextTasks(basePath?: string): Promise { + static forTextTasks(basePath = ''): Promise { return createFileset('text', basePath); } @@ -121,7 +126,7 @@ export class FilesetResolver { * @return A `WasmFileset` that can be used to initialize MediaPipe Vision * tasks. */ - static forVisionTasks(basePath?: string): Promise { + static forVisionTasks(basePath = ''): Promise { return createFileset('vision', basePath); } }