Files
klz-cables.com/.pnpm-store/v10/files/2b/84672d1648be289605edbbee457683a5aa2101bc5656d53c2b149a4f55263219217cf896975cc1236ae62bbdfa02fd0688abc5f5927680077197ce7e1fff4b
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

42 lines
1.8 KiB
Plaintext

export const addSelectGenericsToGeneratedTypes = ({ compiledGeneratedTypes })=>{
const modifiedLines = [];
let isCollectionsSelectToken = false;
let isSelectTypeToken = false;
for (const line of compiledGeneratedTypes.split('\n')){
let newLine = line;
if (line === ` collectionsSelect: {` || line === ` globalsSelect: {`) {
isCollectionsSelectToken = true;
}
if (isCollectionsSelectToken) {
if (line === ' };') {
isCollectionsSelectToken = false;
} else {
// replace <posts: PostsSelect;> with <posts: PostsSelect<true> | PostsSelect<false;>
newLine = line.replace(/(['"]?\w+['"]?):\s*(\w+);/g, (_, variable, type)=>{
return `${variable}: ${type}<false> | ${type}<true>;`;
});
}
}
// eslint-disable-next-line regexp/no-unused-capturing-group
if (line.match(/via the `definition` "([\w-]+_select)"/g)) {
isSelectTypeToken = true;
}
if (isSelectTypeToken) {
if (line.startsWith('export interface')) {
// add generic to the interface
newLine = line.replace(/(export interface\s+\w+)(\s*\{)/g, '$1<T extends boolean = true>$2');
} else {
newLine = line// replace booleans with T on the line
.replace(/(?<!\?)\bboolean\b/g, 'T')// replace interface names like CtaBlock to CtaBlock<T>
.replace(/\b(\w+)\s*\|\s*(\w+)\b/g, (_match, left, right)=>`${left} | ${right}<${left}>`);
if (line === '}') {
isSelectTypeToken = false;
}
}
}
modifiedLines.push(newLine);
}
return modifiedLines.join('\n');
};
//# sourceMappingURL=addSelectGenericsToGeneretedTypes.js.map