mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
fix: handle empty folders in non-bundle-compat (#7649)
This commit is contained in:

committed by
Svetoslav

parent
5f22594eb7
commit
5fd7913103
@ -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)) {
|
if (cache.has(path)) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
cache.add(path);
|
cache.add(path);
|
||||||
|
|
||||||
if (traceEnabled()) {
|
if (traceEnabled()) {
|
||||||
traceWrite(`[Compat] Processing folder: ${path}`, traceCategories.ModuleNameResolver);
|
traceWrite(`[Compat] Processing folder: ${path}`, traceCategories.ModuleNameResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let folderEmpty = true;
|
||||||
|
|
||||||
if (fs.Folder.exists(path)) {
|
if (fs.Folder.exists(path)) {
|
||||||
const folder = fs.Folder.fromPath(path);
|
const folder = fs.Folder.fromPath(path);
|
||||||
@ -72,11 +78,14 @@ function processFolder(path: string) {
|
|||||||
folder.eachEntity((file) => {
|
folder.eachEntity((file) => {
|
||||||
if (file instanceof fs.File) {
|
if (file instanceof fs.File) {
|
||||||
processFile(file);
|
processFile(file);
|
||||||
|
folderEmpty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return !folderEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,23 +96,25 @@ function processFolder(path: string) {
|
|||||||
export function registerModulesFromFileSystem(moduleName: string) {
|
export function registerModulesFromFileSystem(moduleName: string) {
|
||||||
initialize();
|
initialize();
|
||||||
|
|
||||||
let folderFound = false;
|
let folderProcessed = false;
|
||||||
|
let parentFolderProcessed = false;
|
||||||
// moduleName is a folder with package.json
|
// moduleName is a folder with package.json
|
||||||
const path = fs.path.join(fs.knownFolders.currentApp().path, moduleName);
|
const path = fs.path.join(fs.knownFolders.currentApp().path, moduleName);
|
||||||
if (fs.Folder.exists(path)) {
|
if (fs.Folder.exists(path)) {
|
||||||
processFolder(path);
|
folderProcessed = processFolder(path);
|
||||||
folderFound = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// moduleName is file - load all files in its parent folder
|
// moduleName is file - load all files in its parent folder
|
||||||
const parentName = moduleName.substr(0, moduleName.lastIndexOf(fs.path.separator));
|
const parentName = moduleName.substr(0, moduleName.lastIndexOf(fs.path.separator));
|
||||||
const parentFolderPath = fs.path.join(fs.knownFolders.currentApp().path, parentName);
|
const parentFolderPath = fs.path.join(fs.knownFolders.currentApp().path, parentName);
|
||||||
if (fs.Folder.exists(parentFolderPath)) {
|
if (fs.Folder.exists(parentFolderPath)) {
|
||||||
processFolder(parentFolderPath);
|
parentFolderProcessed = processFolder(parentFolderPath);
|
||||||
folderFound = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user