From 45f4caec52d9f14616be92c3c6cd9ed072bde6ed Mon Sep 17 00:00:00 2001 From: Sarthak Date: Sun, 22 Mar 2026 14:37:42 +0530 Subject: [PATCH 1/3] fix: resolve CLI freeze in large projects and fix discovery bugs --- src/modules/frontendlib.js | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/src/modules/frontendlib.js b/src/modules/frontendlib.js index 0a38bc1b..6a854b02 100644 --- a/src/modules/frontendlib.js +++ b/src/modules/frontendlib.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const path = require('path'); const process = require('process'); const spawnCommand = require('spawn-command'); const recursive = require('recursive-readdir'); @@ -14,9 +15,33 @@ let originalGlobals = null; async function makeClientLibUrl(port) { let configObj = config.get(); - let resourcesPath = configObj.cli.resourcesPath.replace(/^\//, ''); - let files = await recursive(resourcesPath); - let clientLib = files.find((file) => /neutralino\.js$/.test(file)); + let resourcesPath = (configObj.cli && configObj.cli.resourcesPath) ? configObj.cli.resourcesPath.replace(/^\//, '') : 'resources'; + let clientLib = null; + + // 1. Try to use path from config first (Fast Path) + if (configObj.cli && configObj.cli.clientLibrary) { + let configClientLib = configObj.cli.clientLibrary.replace(/^\//, ''); + if (fs.existsSync(configClientLib)) { + clientLib = configClientLib; + } + } + + // 2. Fallback to shallow search in resources root (Smart Path) + if (!clientLib && fs.existsSync(resourcesPath)) { + let topFiles = fs.readdirSync(resourcesPath); + if (topFiles.includes('neutralino.js')) { + clientLib = path.join(resourcesPath, 'neutralino.js'); + } + } + + // 3. Last resort: Recursive search with ignores (Safe Path) + if (!clientLib && fs.existsSync(resourcesPath)) { + utils.log('Searching for neutralino.js...'); + const skipFiles = ['node_modules', '.git', 'dist', 'build', 'bower_components']; + let files = await recursive(resourcesPath, skipFiles); + clientLib = files.find((file) => /neutralino\.js$/.test(file)); + } + if (clientLib) { clientLib = clientLib.replace(/\\/g, '/'); // Fix path on Windows } @@ -64,10 +89,9 @@ function getPortByProtocol(protocol) { module.exports.bootstrap = async (port) => { let configObj = config.get(); - if(configObj.cli.clientLibrary) { - let clientLibUrl = await makeClientLibUrl(port); - originalClientLib = patchHTMLFile(clientLibUrl, HOT_REL_LIB_PATCH_REGEX); - } + let clientLibUrl = await makeClientLibUrl(port); + originalClientLib = patchHTMLFile(clientLibUrl, HOT_REL_LIB_PATCH_REGEX); + let globalsUrl = await makeGlobalsUrl(port); originalGlobals = patchHTMLFile(globalsUrl, HOT_REL_GLOB_PATCH_REGEX); utils.warn('Global variables patch was applied successfully. ' + From 21eca1d85fe44e51ef9a17671d7fcfe124a7b41a Mon Sep 17 00:00:00 2001 From: Sarthak Date: Sun, 22 Mar 2026 15:05:51 +0530 Subject: [PATCH 2/3] refactor: improve discovery logic safety and robustness --- src/modules/frontendlib.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/frontendlib.js b/src/modules/frontendlib.js index 6a854b02..18db9d58 100644 --- a/src/modules/frontendlib.js +++ b/src/modules/frontendlib.js @@ -53,8 +53,9 @@ async function makeClientLibUrl(port) { clientLib = clientLib.replace(configObj.documentRoot, '/'); } url += clientLib; + return url; } - return url; + return null; } function makeGlobalsUrl(port) { @@ -90,7 +91,9 @@ function getPortByProtocol(protocol) { module.exports.bootstrap = async (port) => { let configObj = config.get(); let clientLibUrl = await makeClientLibUrl(port); - originalClientLib = patchHTMLFile(clientLibUrl, HOT_REL_LIB_PATCH_REGEX); + if (clientLibUrl) { + originalClientLib = patchHTMLFile(clientLibUrl, HOT_REL_LIB_PATCH_REGEX); + } let globalsUrl = await makeGlobalsUrl(port); originalGlobals = patchHTMLFile(globalsUrl, HOT_REL_GLOB_PATCH_REGEX); From 5400ec1701f2debf9fcdc26f974f91a455e1e1dd Mon Sep 17 00:00:00 2001 From: Sarthak Date: Sun, 22 Mar 2026 15:49:55 +0530 Subject: [PATCH 3/3] refactor: clean up comments and finalize freeze fix --- src/modules/frontendlib.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/frontendlib.js b/src/modules/frontendlib.js index 18db9d58..a728c3fa 100644 --- a/src/modules/frontendlib.js +++ b/src/modules/frontendlib.js @@ -18,7 +18,7 @@ async function makeClientLibUrl(port) { let resourcesPath = (configObj.cli && configObj.cli.resourcesPath) ? configObj.cli.resourcesPath.replace(/^\//, '') : 'resources'; let clientLib = null; - // 1. Try to use path from config first (Fast Path) + if (configObj.cli && configObj.cli.clientLibrary) { let configClientLib = configObj.cli.clientLibrary.replace(/^\//, ''); if (fs.existsSync(configClientLib)) { @@ -26,7 +26,7 @@ async function makeClientLibUrl(port) { } } - // 2. Fallback to shallow search in resources root (Smart Path) + if (!clientLib && fs.existsSync(resourcesPath)) { let topFiles = fs.readdirSync(resourcesPath); if (topFiles.includes('neutralino.js')) { @@ -34,7 +34,7 @@ async function makeClientLibUrl(port) { } } - // 3. Last resort: Recursive search with ignores (Safe Path) + if (!clientLib && fs.existsSync(resourcesPath)) { utils.log('Searching for neutralino.js...'); const skipFiles = ['node_modules', '.git', 'dist', 'build', 'bower_components']; @@ -43,7 +43,7 @@ async function makeClientLibUrl(port) { } if (clientLib) { - clientLib = clientLib.replace(/\\/g, '/'); // Fix path on Windows + clientLib = clientLib.replace(/\\/g, '/'); } let url = `http://localhost:${port}`;