From 654ce17286f7ac2e436e9bbbbedbd5e94db4ce22 Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Fri, 11 Apr 2025 16:36:46 +0300 Subject: [PATCH] fix(schema-compiler): Fix incorrect bulk transpilation if there are no JS files --- .../src/compiler/DataSchemaCompiler.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.js b/packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.js index eb0fee5e84523..732b08540182a 100644 --- a/packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.js +++ b/packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.js @@ -172,20 +172,24 @@ export class DataSchemaCompiler { .map(f => this.transpileFile(f, errorsReport, { transpilerNames, compilerId })); const jsFiles = toCompile.filter(file => file.fileName.endsWith('.js')); - let jsChunks; - if (jsFiles.length < transpilationNativeThreadsCount * transpilationNativeThreadsCount) { - jsChunks = [jsFiles]; - } else { - const baseSize = Math.floor(jsFiles.length / transpilationNativeThreadsCount); - jsChunks = []; - for (let i = 0; i < transpilationNativeThreadsCount; i++) { - // For the last part, we take the remaining files so we don't lose the extra ones. - const start = i * baseSize; - const end = (i === transpilationNativeThreadsCount - 1) ? jsFiles.length : start + baseSize; - jsChunks.push(jsFiles.slice(start, end)); + let JsFilesTasks = []; + + if (jsFiles.length > 0) { + let jsChunks; + if (jsFiles.length < transpilationNativeThreadsCount * transpilationNativeThreadsCount) { + jsChunks = [jsFiles]; + } else { + const baseSize = Math.floor(jsFiles.length / transpilationNativeThreadsCount); + jsChunks = []; + for (let i = 0; i < transpilationNativeThreadsCount; i++) { + // For the last part, we take the remaining files so we don't lose the extra ones. + const start = i * baseSize; + const end = (i === transpilationNativeThreadsCount - 1) ? jsFiles.length : start + baseSize; + jsChunks.push(jsFiles.slice(start, end)); + } } + JsFilesTasks = jsChunks.map(chunk => this.transpileJsFilesBulk(chunk, errorsReport, { transpilerNames, compilerId })); } - const JsFilesTasks = jsChunks.map(chunk => this.transpileJsFilesBulk(chunk, errorsReport, { transpilerNames, compilerId })); results = (await Promise.all([...nonJsFilesTasks, ...JsFilesTasks])).flat(); } else if (transpilationWorkerThreads) {