Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor, remove shouldIgnoreComponent, use shouldIgnorePackage instead #8204

Merged
merged 1 commit into from
Nov 28, 2023
Merged
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 @@ -9,7 +9,6 @@ import { IssuesList, IssuesClasses } from '@teambit/component-issues';
import { Dependency } from '..';
import { DEFAULT_DIST_DIRNAME, DEPENDENCIES_FIELDS, MANUALLY_REMOVE_DEPENDENCY } from '../../../../constants';
import Consumer from '../../../../consumer/consumer';
import GeneralError from '../../../../error/general-error';
import logger from '../../../../logger/logger';
import { getExt, pathNormalizeToLinux, pathRelativeLinux } from '../../../../utils';
import { PathLinux, PathLinuxRelative, PathOsBased, removeFileExtension } from '../../../../utils/path';
Expand Down Expand Up @@ -446,12 +445,6 @@ export default class DependencyResolver {
this._pushToUntrackDependenciesIssues(originFile, depFileRelative, nested);
return true;
}
if (this.overridesDependencies.shouldIgnoreComponent(componentId, fileType)) {
// we can't support it because on the imported side, we don't know to convert the relative path
// to the component name, as it won't have the component installed
throw new GeneralError(`unable to ignore "${componentId.toString()}" dependency of "${this.componentId.toString()}" by using ignore components syntax because the component is required with relative path.
either, use the ignore file syntax or change the require statement to have a module path`);
}
// happens when in the same component one file requires another one. In this case, there is
// noting to do regarding the dependencies
if (componentId.isEqual(this.componentId, { ignoreVersion: true })) {
Expand Down Expand Up @@ -561,7 +554,7 @@ either, use the ignore file syntax or change the require statement to have a mod
if (version) {
componentId = componentId.changeVersion(version);
}
if (this.overridesDependencies.shouldIgnoreComponent(componentId, fileType)) {
if (this.overridesDependencies.shouldIgnorePackage(compDep.name, fileType)) {
return;
}
const getExistingIdFromBitmap = (): ComponentID | undefined => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import _ from 'lodash';
import { ComponentID } from '@teambit/component-id';
import { DEPENDENCIES_FIELDS, MANUALLY_ADD_DEPENDENCY, MANUALLY_REMOVE_DEPENDENCY } from '../../../../constants';
import Consumer from '../../../../consumer/consumer';
Expand Down Expand Up @@ -65,22 +64,6 @@ export default class OverridesDependencies {
return ignore;
}

shouldIgnoreComponent(componentId: ComponentID, fileType: FileType): boolean {
const componentIdStr = componentId.toStringWithoutVersion();
const shouldIgnore = (ids: ComponentID[]) => {
return ids.some((id) => {
return componentId.isEqual(id, { ignoreVersion: true });
});
};
const field = fileType.isTestFile ? 'devDependencies' : 'dependencies';
const ignoredComponents = this._getIgnoredComponentsByField(field);
const ignore = shouldIgnore(ignoredComponents);
if (ignore) {
this._addManuallyRemovedDep(field, componentIdStr);
}
return ignore;
}

getDependenciesToAddManually(
packageJson: Record<string, any> | null | undefined,
existingDependencies: AllDependencies
Expand Down Expand Up @@ -117,12 +100,6 @@ export default class OverridesDependencies {
return { components, packages };
}

_getIgnoredComponentsByField(field: 'devDependencies' | 'dependencies' | 'peerDependencies'): ComponentID[] {
const ignoredPackages = this.component.overrides.getIgnoredPackages(field);
const ignoredComponents = ignoredPackages.map((packageName) => this._getComponentIdFromPackage(packageName));
return _.compact(ignoredComponents);
}

_getComponentIdToAdd(
field: string,
dependency: string
Expand All @@ -132,11 +109,6 @@ export default class OverridesDependencies {
return { componentId: packageData?.componentId, packageName: packageData?.name };
}

_getComponentIdFromPackage(packageName: string): ComponentID | undefined {
const packageData = this._resolvePackageData(packageName);
return packageData?.componentId;
}

_manuallyAddPackage(
field: string,
dependency: string,
Expand Down