Skip to content

Commit

Permalink
fix(deps-remove), in case a package is duplicate in runtime and dev a…
Browse files Browse the repository at this point in the history
…nd "bit deps remove --dev" was used, remove from dev (#9070)
  • Loading branch information
davidfirst authored Jul 26, 2024
1 parent 9fe8e69 commit b512aed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions scopes/component/checkout/checkout-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ when on a lane, "checkout head" only checks out components on this lane. to upda
forceOurs,
forceTheirs,
};
to = String(to); // it can be a number in case short-hash is used
if (to === HEAD) checkoutProps.head = true;
else if (to === LATEST) checkoutProps.latest = true;
else if (to === 'reset') checkoutProps.reset = true;
Expand Down
12 changes: 6 additions & 6 deletions scopes/dependencies/dependencies/dependencies.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export class DependenciesMain {
options: RemoveDependenciesFlags = {},
removeOnlyIfExists = false // unset
): Promise<RemoveDependencyResult[]> {
const getLifeCycle = () => {
if (options.dev) return 'dev';
if (options.peer) return 'peer';
return 'runtime';
};
const compIds = await this.workspace.idsByPattern(componentPattern);
const results = await pMapSeries(compIds, async (compId) => {
const component = await this.workspace.get(compId);
Expand All @@ -163,14 +168,9 @@ export class DependenciesMain {
const newDepResolverConfig = cloneDeep(currentDepResolverConfig || {});
const removedPackagesWithNulls = await pMapSeries(packages, async (pkg) => {
const [name, version] = this.splitPkgToNameAndVer(pkg);
const dependency = depList.findByPkgNameOrCompId(name, version);
const dependency = depList.findByPkgNameOrCompId(name, version, getLifeCycle());
if (!dependency) return null;
const depName = dependency.getPackageName?.() || dependency.id;
const getLifeCycle = () => {
if (options.dev) return 'dev';
if (options.peer) return 'peer';
return dependency.lifecycle;
};
const depField = KEY_NAME_BY_LIFECYCLE_TYPE[getLifeCycle()];
const existsInSpecificConfig = newDepResolverConfig.policy?.[depField]?.[depName];
if (existsInSpecificConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,22 @@ export class DependencyList {
return this.dependencies.find((dep) => removeVersion(dep.id) === componentIdStrWithoutVersion);
}

findByPkgNameOrCompId(id: string, version?: string): Dependency | undefined {
findByPkgNameOrCompId(
id: string,
version?: string,
lifecycle: DependencyLifecycleType = 'runtime'
): Dependency | undefined {
const findByVariousStrategies = () => {
// try by full-id or package-name
const found = this.dependencies.find(
const found = this.dependencies.filter(
(dep) => dep.id === id || dep.getPackageName?.() === id || dep.id.startsWith(`${id}@`)
);
if (found) return found;
if (found.length) {
if (found.length === 1) return found[0];
const foundByLifecycle = found.find((dep) => dep.lifecycle === lifecycle);
if (foundByLifecycle) return foundByLifecycle;
return found[0];
}
const compDeps = this.toTypeArray<ComponentDependency>('component');

// try by component-name
Expand Down

0 comments on commit b512aed

Please sign in to comment.