Skip to content

Commit e29cbb6

Browse files
deleonioCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Martin <6279703+deleonio@users.noreply.github.com>
1 parent 92eb422 commit e29cbb6

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

packages/tools/kolibri-cli/src/migrate/shares/reuse.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,32 @@ export function filterFilesByExt(dir: string, ext: FileExtension | FileExtension
6666
* @param {string} dir The directory to search in
6767
* @returns {boolean} True if at least one file contains KoliBri component tags (web or React)
6868
*/
69-
export function hasKolibriTags(dir: string): boolean {
69+
export async function hasKolibriTags(dir: string): Promise<boolean> {
7070
const regexes = [WEB_TAG_REGEX, REACT_TAG_REGEX];
71-
return filterFilesByExt(dir, MARKUP_EXTENSIONS).some((file) => {
71+
const files = filterFilesByExt(dir, MARKUP_EXTENSIONS);
72+
73+
for (const file of files) {
7274
const stream = fs.createReadStream(file, { encoding: 'utf8', highWaterMark: 1024 });
7375
let content = '';
74-
for await (const chunk of stream) {
76+
77+
let found = false;
78+
stream.on('data', (chunk) => {
7579
content += chunk;
7680
if (regexes.some((regex) => regex.test(content))) {
81+
found = true;
7782
stream.destroy(); // Stop reading further
78-
return true;
7983
}
80-
}
84+
});
85+
stream.on('end', () => {
86+
if (!found) {
87+
return false;
88+
}
89+
});
90+
stream.on('error', (err) => {
91+
console.error(`Error reading file ${file}:`, err);
92+
return false;
93+
});
94+
return found;
8195
return false;
8296
});
8397
}

packages/tools/kolibri-cli/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const CUSTOM_ELEMENT_FILE_EXTENSIONS: FileExtension[] = ['html', 'xhtml',
66
export const MARKUP_EXTENSIONS: FileExtension[] = COMPONENT_FILE_EXTENSIONS.concat(CUSTOM_ELEMENT_FILE_EXTENSIONS);
77

88
export const WEB_TAG_REGEX = /\b<kol-[a-z-]+/i;
9-
export const REACT_TAG_REGEX = /\b<Kol[A-Z][A-Za-z-]*/;
9+
export const REACT_TAG_REGEX = /\b<Kol[A-Z][A-Za-z]*/;
1010

1111
export type PackageJson = {
1212
name: string;

0 commit comments

Comments
 (0)