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

improvement(fork) - explicitly don't copy pkg config when forking component #7495

Merged
merged 3 commits into from
Jun 5, 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
2 changes: 1 addition & 1 deletion scopes/component/new-component-helper/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NewComponentHelperAspect } from './new-component-helper.aspect';

export type { NewComponentHelperMain, CloneConfig } from './new-component-helper.main.runtime';
export type { NewComponentHelperMain } from './new-component-helper.main.runtime';
export default NewComponentHelperAspect;
export { NewComponentHelperAspect };
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ComponentID } from '@teambit/component-id';
import { Harmony } from '@teambit/harmony';
import { PathLinuxRelative } from '@teambit/legacy/dist/utils/path';
import WorkspaceAspect, { Workspace } from '@teambit/workspace';
import { PkgAspect } from '@teambit/pkg';
import { NewComponentHelperAspect } from './new-component-helper.aspect';

export class NewComponentHelperMain {
Expand Down Expand Up @@ -86,20 +87,13 @@ export class NewComponentHelperMain {
}

async getConfigFromExistingToNewComponent(comp: Component) {
const aspectIds = comp.state.aspects.entries.map((e) => e.id.toString());
// the reason to load aspects is to be able to check later for the `shouldPreserveConfigForClonedComponent` prop.
// it's not saved in the model, it's available only on the aspect instance.
await this.workspace.loadAspects(aspectIds, undefined, 'new-component-helper.getConfigFromExistingToNewComponent');
const fromExisting = {};
comp.state.aspects.entries.forEach((entry) => {
if (!entry.config) return;
const aspectId = entry.id.toString();
const aspect = this.harmony.get<CloneConfig>(aspectId);
if (!aspect) throw new Error(`error: unable to get "${aspectId}" aspect from Harmony`);
if (
'shouldPreserveConfigForClonedComponent' in aspect &&
aspect.shouldPreserveConfigForClonedComponent === false
) {
// don't copy the pkg aspect, it's not relevant for the new component
// (it might contains values that are bounded to the other component name / id)
if (aspectId === PkgAspect.id) {
return;
}
fromExisting[aspectId] = entry.config;
Expand All @@ -116,7 +110,3 @@ export class NewComponentHelperMain {
}

NewComponentHelperAspect.addRuntime(NewComponentHelperMain);

export interface CloneConfig {
readonly shouldPreserveConfigForClonedComponent?: boolean; // default true
}
5 changes: 1 addition & 4 deletions scopes/pkg/pkg/pkg.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { ScopeAspect, ScopeMain } from '@teambit/scope';
import { Workspace, WorkspaceAspect } from '@teambit/workspace';
import { PackageJsonTransformer } from '@teambit/workspace.modules.node-modules-linker';
import { BuilderMain, BuilderAspect } from '@teambit/builder';
import { CloneConfig } from '@teambit/new-component-helper';
import { BitError } from '@teambit/bit-error';
import { snapToSemver } from '@teambit/component-package-version';
import { IssuesClasses } from '@teambit/component-issues';
Expand Down Expand Up @@ -96,7 +95,7 @@ export type VersionPackageManifest = {
};
};

export class PkgMain implements CloneConfig {
export class PkgMain {
static runtime = MainRuntime;
static dependencies = [
CLIAspect,
Expand Down Expand Up @@ -183,8 +182,6 @@ export class PkgMain implements CloneConfig {
return pkg;
}

readonly shouldPreserveConfigForClonedComponent = false;

/**
* get the package name of a component.
*/
Expand Down