Files
klz-cables.com/.pnpm-store/v10/files/fb/01ce64c662151fc5b3cd5a0e33330f7c395bb93061066b3d9f469b2201feb3e4ec684c5ed568c34e89d082021bd4a19f722724d5ca4aa148fadc0309146384
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

45 lines
1.2 KiB
Plaintext

import path from 'path';
import { throwError } from '../../plugin/utils.js';
const formats = {
json: {
codec: () => import('./codecs/JSONCodec.js'),
extension: '.json'
},
po: {
codec: () => import('./codecs/POCodec.js'),
extension: '.po'
}
};
function isBuiltInFormat(format) {
return typeof format === 'string' && format in formats;
}
function getFormatExtension(format) {
if (isBuiltInFormat(format)) {
return formats[format].extension;
} else {
return format.extension;
}
}
async function resolveCodec(format, projectRoot) {
if (isBuiltInFormat(format)) {
const factory = (await formats[format].codec()).default;
return factory();
} else {
const resolvedPath = path.isAbsolute(format.codec) ? format.codec : path.resolve(projectRoot, format.codec);
let module;
try {
module = await import(resolvedPath);
} catch (error) {
throwError(`Could not load codec from "${resolvedPath}".\n${error}`);
}
const factory = module.default;
if (!factory || typeof factory !== 'function') {
throwError(`Codec at "${resolvedPath}" must have a default export returned from \`defineCodec\`.`);
}
return factory();
}
}
export { formats as default, getFormatExtension, resolveCodec };