Skip to content

Commit 1e6f120

Browse files
authored
perf, reduce the usage of componentDefaultScopeFromComponentDirAndNameWithoutConfigFile (#9604)
1 parent 4585b00 commit 1e6f120

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

e2e/harmony/update-cmd.e2e.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ describe('update command', function () {
2626
});
2727
helper.command.ejectConf('comp2');
2828
componentJson = helper.componentJson.read('comp2');
29-
delete componentJson.componentId.scope;
3029
componentJson.extensions = {
3130
'teambit.dependencies/dependency-resolver': {
3231
policy: {

scopes/workspace/workspace/component-config-file/component-config-file.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class ComponentConfigFile {
4747
static async load(
4848
componentDir: PathOsBasedAbsolute,
4949
aspectListFactory: (extensionDataList: ExtensionDataList) => Promise<AspectList>,
50-
outsideDefaultScope?: string
5150
): Promise<ComponentConfigFile | undefined> {
5251
const filePath = ComponentConfigFile.composePath(componentDir);
5352
const isExist = await fs.pathExists(filePath);
@@ -58,7 +57,10 @@ export class ComponentConfigFile {
5857
const parsed: ComponentConfigFileJson = parseComponentJsonContent(content, componentDir);
5958
const indent = detectIndent(content).indent;
6059
const newLine = detectNewline(content);
61-
const componentId = ComponentID.fromObject(parsed.componentId, parsed.defaultScope || outsideDefaultScope);
60+
if (!parsed.componentId.scope) {
61+
throw new Error(`component.json file at ${componentDir} is invalid, it must contain 'scope' property in the componentId`);
62+
}
63+
const componentId = ComponentID.fromObject(parsed.componentId);
6264
const aspects = await aspectListFactory(ExtensionDataList.fromConfigObject(parsed.extensions));
6365

6466
return new ComponentConfigFile(

scopes/workspace/workspace/workspace.main.runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export class WorkspaceMain {
241241
// This component from scope here are only used for merging the extensions with the workspace components
242242
const componentFromScope = await workspace.scope.get(componentId);
243243
const { extensions } = await workspace.componentExtensions(componentId, componentFromScope, undefined, loadOpts);
244-
const defaultScope = await workspace.componentDefaultScope(componentId);
244+
const defaultScope = componentId.scope;
245245

246246
const extensionsWithLegacyIdsP = extensions.map(async (extension) => {
247247
if (extension.extensionId) {

scopes/workspace/workspace/workspace.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,9 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
12851285
return path.join(this.path, relativeComponentDir);
12861286
}
12871287

1288+
/**
1289+
* @deprecated long long ago we added it to the componentId object. use `componentId.scope` instead.
1290+
*/
12881291
async componentDefaultScope(componentId: ComponentID): Promise<string | undefined> {
12891292
const relativeComponentDir = this.componentDir(componentId, { ignoreVersion: true }, { relative: true });
12901293
return this.componentDefaultScopeFromComponentDirAndName(relativeComponentDir, componentId.fullName);
@@ -1294,10 +1297,6 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
12941297
relativeComponentDir: PathOsBasedRelative,
12951298
name: string
12961299
): Promise<string | undefined> {
1297-
const componentConfigFile = await this.componentConfigFileFromComponentDirAndName(relativeComponentDir, name);
1298-
if (componentConfigFile && componentConfigFile.defaultScope) {
1299-
return componentConfigFile.defaultScope;
1300-
}
13011300
const bitMapId = this.consumer.bitMap.getExistingBitId(name, false);
13021301
const bitMapEntry = bitMapId ? this.consumer.bitMap.getComponent(bitMapId) : undefined;
13031302
if (bitMapEntry && bitMapEntry.defaultScope) {
@@ -1590,7 +1589,7 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
15901589
*/
15911590
public async componentConfigFile(id: ComponentID): Promise<ComponentConfigFile | undefined> {
15921591
const relativeComponentDir = this.componentDir(id, { ignoreVersion: true }, { relative: true });
1593-
return this.componentConfigFileFromComponentDirAndName(relativeComponentDir, id.fullName);
1592+
return this.componentConfigFileFromComponentDirAndName(relativeComponentDir);
15941593
}
15951594

15961595
/**
@@ -1608,17 +1607,13 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
16081607

16091608
private async componentConfigFileFromComponentDirAndName(
16101609
relativeComponentDir: PathOsBasedRelative,
1611-
name: string
16121610
): Promise<ComponentConfigFile | undefined> {
16131611
let componentConfigFile;
16141612
if (relativeComponentDir) {
16151613
const absComponentDir = this.componentDirToAbsolute(relativeComponentDir);
1616-
const defaultScopeFromVariantsOrWs =
1617-
await this.componentDefaultScopeFromComponentDirAndNameWithoutConfigFile(relativeComponentDir, name);
16181614
componentConfigFile = await ComponentConfigFile.load(
16191615
absComponentDir,
16201616
this.createAspectList.bind(this),
1621-
defaultScopeFromVariantsOrWs
16221617
);
16231618
}
16241619

0 commit comments

Comments
 (0)