Prevent duplicate auto-discovery for nested packages
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2021-11-27 00:12:51 -06:00
parent 0ed096c782
commit b5eb407b55

View File

@ -73,9 +73,10 @@ export class NodeModules {
*
* @param root - the path to node_modules
* @param module - the module whose children we are discovering
* @param seen - used to prevent duplicate packages when recursing
* @protected
*/
protected async discoverRoot(root: UniversalPath, module: NodeModule): Promise<void> {
protected async discoverRoot(root: UniversalPath, module: NodeModule, seen: string[] = []): Promise<void> {
for ( const key in module.dependencies ) {
if ( !Object.prototype.hasOwnProperty.call(module.dependencies, key) ) {
continue
@ -94,13 +95,19 @@ export class NodeModules {
continue
}
if ( seen.includes(key) ) {
this.logging.debug(`Skipping already-discovered package: ${key}`)
continue
}
this.logging.info(`Auto-discovering package: ${key}`)
seen.push(key)
await this.bus.dispatch(new PackageDiscovered(packageJsonData, packageJson.clone()))
const packageNodeModules = packageJson.concat('..', 'node_modules')
if ( await packageNodeModules.exists() && packageJsonData?.extollo?.recursiveDependencies?.discover ) {
this.logging.debug(`Recursing: ${packageNodeModules}`)
await this.discoverRoot(packageNodeModules, packageJsonData)
await this.discoverRoot(packageNodeModules, packageJsonData, seen)
}
}
} catch (e: unknown) {