Prevent duplicate auto-discovery for nested packages
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0ed096c782
commit
b5eb407b55
@ -73,9 +73,10 @@ export class NodeModules {
|
|||||||
*
|
*
|
||||||
* @param root - the path to node_modules
|
* @param root - the path to node_modules
|
||||||
* @param module - the module whose children we are discovering
|
* @param module - the module whose children we are discovering
|
||||||
|
* @param seen - used to prevent duplicate packages when recursing
|
||||||
* @protected
|
* @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 ) {
|
for ( const key in module.dependencies ) {
|
||||||
if ( !Object.prototype.hasOwnProperty.call(module.dependencies, key) ) {
|
if ( !Object.prototype.hasOwnProperty.call(module.dependencies, key) ) {
|
||||||
continue
|
continue
|
||||||
@ -94,13 +95,19 @@ export class NodeModules {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( seen.includes(key) ) {
|
||||||
|
this.logging.debug(`Skipping already-discovered package: ${key}`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
this.logging.info(`Auto-discovering package: ${key}`)
|
this.logging.info(`Auto-discovering package: ${key}`)
|
||||||
|
seen.push(key)
|
||||||
await this.bus.dispatch(new PackageDiscovered(packageJsonData, packageJson.clone()))
|
await this.bus.dispatch(new PackageDiscovered(packageJsonData, packageJson.clone()))
|
||||||
|
|
||||||
const packageNodeModules = packageJson.concat('..', 'node_modules')
|
const packageNodeModules = packageJson.concat('..', 'node_modules')
|
||||||
if ( await packageNodeModules.exists() && packageJsonData?.extollo?.recursiveDependencies?.discover ) {
|
if ( await packageNodeModules.exists() && packageJsonData?.extollo?.recursiveDependencies?.discover ) {
|
||||||
this.logging.debug(`Recursing: ${packageNodeModules}`)
|
this.logging.debug(`Recursing: ${packageNodeModules}`)
|
||||||
await this.discoverRoot(packageNodeModules, packageJsonData)
|
await this.discoverRoot(packageNodeModules, packageJsonData, seen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
|
Loading…
Reference in New Issue
Block a user