From 5fd7913103cb754c46b0f773f0eb8cf2e96d8ad2 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Wed, 7 Aug 2019 18:08:44 +0300 Subject: [PATCH] fix: handle empty folders in non-bundle-compat (#7649) --- .../non-bundle-workflow-compat.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tns-core-modules/module-name-resolver/non-bundle-workflow-compat.ts b/tns-core-modules/module-name-resolver/non-bundle-workflow-compat.ts index 9b2f4e7e0..90bbd7f18 100644 --- a/tns-core-modules/module-name-resolver/non-bundle-workflow-compat.ts +++ b/tns-core-modules/module-name-resolver/non-bundle-workflow-compat.ts @@ -56,15 +56,21 @@ function processFile(file: fs.File) { } } -function processFolder(path: string) { +/** + * Processes folder and returns true if folder was not empty. + * @param Folder path + */ +function processFolder(path: string): boolean { if (cache.has(path)) { - return; + return true; } cache.add(path); if (traceEnabled()) { traceWrite(`[Compat] Processing folder: ${path}`, traceCategories.ModuleNameResolver); } + + let folderEmpty = true; if (fs.Folder.exists(path)) { const folder = fs.Folder.fromPath(path); @@ -72,11 +78,14 @@ function processFolder(path: string) { folder.eachEntity((file) => { if (file instanceof fs.File) { processFile(file); + folderEmpty = false; } return true; }); } + + return !folderEmpty; } /** @@ -87,23 +96,25 @@ function processFolder(path: string) { export function registerModulesFromFileSystem(moduleName: string) { initialize(); - let folderFound = false; + let folderProcessed = false; + let parentFolderProcessed = false; // moduleName is a folder with package.json const path = fs.path.join(fs.knownFolders.currentApp().path, moduleName); if (fs.Folder.exists(path)) { - processFolder(path); - folderFound = true; + folderProcessed = processFolder(path); } // moduleName is file - load all files in its parent folder const parentName = moduleName.substr(0, moduleName.lastIndexOf(fs.path.separator)); const parentFolderPath = fs.path.join(fs.knownFolders.currentApp().path, parentName); if (fs.Folder.exists(parentFolderPath)) { - processFolder(parentFolderPath); - folderFound = true; + parentFolderProcessed = processFolder(parentFolderPath); } - if (folderFound) { + // Return only if we processed the actual folder or its parent folder. + // If the parent folder is empty we should still check tns_modules + // as this might be just a name of a plugin (ex. "nativescript-ui-autocomplete") + if (folderProcessed || (parentFolderProcessed && parentName)) { return; }