Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,26 @@ export class ComponentWriterMain {
skipWriteConfigFiles = false
): Promise<Error | undefined> {
this.logger.debug('installPackagesGracefully, start installing packages');
// Clear all components cache to ensure fresh dependency data is loaded.
// Without this, the install process might use stale cached components that don't have proper
// dependency information, resulting in missing package dependencies.
// Load the components to trigger full dependency detection before install.
// This ensures all dependencies from the source code are detected and added to the MissingPackagesDependenciesOnFs
// issue, which is used to merge dependencies from the model during manifest generation.
// We clear cache first to ensure components are loaded fresh from the filesystem.
this.workspace.clearAllComponentsCache();
this.logger.debug('installPackagesGracefully, loading components to detect dependencies');
await this.workspace.getMany(componentIds);
this.logger.debug('installPackagesGracefully, components loaded');
try {
const installOpts = {
dedupe: true,
updateExisting: false,
import: false,
writeConfigFiles: !skipWriteConfigFiles,
dependenciesGraph: await this.workspace.scope.getDependenciesGraphByComponentIds(componentIds),
// Don't pass dependenciesGraph during import-install to ensure all dependencies
// are resolved fresh from the component manifests. The pre-computed graph from the model
// may be incomplete for newly imported components whose dependencies aren't fully resolved yet.
};
await this.installer.install(undefined, installOpts);
this.logger.debug('installPackagesGracefully, completed installing packages successfully');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,22 @@ export class DependencyListFactory {
}
// All deps defined in model
const depListFromModel = await this.getDependenciesFromLegacyModelComponent(componentFromModel);
// Only deps from model which are also required in the current component on fs (currently missing)

// For component dependencies (bit components), always include them from the model if missingPackages has at least one entry.
// This is because component dependency detection may be incomplete during initial load (e.g., for Vue SFC files),
// but we still need to install these dependencies. Package dependencies are filtered by missingPackages to respect
// user changes in the source code.
const hasAnyMissingPackages = missingPackages.length > 0;
const filteredDepList = depListFromModel.filter((dep) => {
const packageName = dep.getPackageName?.();
if (!packageName) {
return false;
}
// For component dependencies, include them if we have any missing packages detected (indicating the component is being analyzed)
if (dep.constructor.name === 'ComponentDependency' && hasAnyMissingPackages) {
return true;
}
// For package dependencies, only include if they're in the missing packages list
return missingPackages.includes(packageName);
});
return filteredDepList;
Expand Down