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

fix(install): import objects according to the current lane/main #7081

Merged
merged 2 commits into from
Feb 23, 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
14 changes: 0 additions & 14 deletions scopes/scope/importer/import-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,6 @@ export default class ImportComponents {
lane,
});

// import lane components from their original scope, this way, it's possible to run diff/merge on them.
// don't use `scope.getDefaultLaneIdsFromLane()`. we need all components, because it's possible that a component
// does't have "head" locally although it exits in the origin-scope. it happens when the component was created on
// the origin-scope after a component with the same-name was created on the lane
// if (lane) {
// // @todo: optimize this maybe. currently, it imports twice.
// // try to make the previous `importComponentsObjectsHarmony` import the same component once from the original
// // scope and once from the lane-scope.
// const mainIdsLatest = BitIds.fromArray(lane.toBitIds().map((m) => m.changeVersion(undefined)));
// await this._importComponentsObjects(mainIdsLatest, {
// ignoreMissingHead: true,
// });
// }

// merge the lane objects
const mergeAllLanesResults = await pMapSeries(this.laneObjects, (laneObject) =>
this.scope.sources.mergeLane(laneObject, true)
Expand Down
31 changes: 24 additions & 7 deletions scopes/scope/importer/importer.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export class ImporterMain {
return results;
}

/**
* fetch objects according to the criteria set by `options` param.
* to fetch current objects according to the current lane or main, use `this.importCurrentObjects()`.
*/
async importObjects(options: Partial<ImportOptions> = {}): Promise<ImportResult> {
const importOptions: ImportOptions = {
...options,
Expand All @@ -76,6 +80,24 @@ export class ImporterMain {
return importComponents.importComponents();
}

/**
* if on main, fetch main objects, if on lane, fetch lane objects.
*/
async importCurrentObjects(): Promise<ImportResult> {
if (!this.workspace) throw new OutsideWorkspaceError();
const importOptions: ImportOptions = {
ids: [],
objectsOnly: true,
installNpmPackages: false,
};
const currentRemoteLane = await this.workspace.getCurrentRemoteLane();
if (currentRemoteLane) {
importOptions.lanes = { laneIds: [currentRemoteLane.toLaneId()], lanes: [currentRemoteLane] };
}
const importComponents = new ImportComponents(this.workspace, this.graph, this.componentWriter, importOptions);
return importComponents.importComponents();
}

async importObjectsFromMainIfExist(ids: BitId[]) {
await this.scope.legacyScope.scopeImporter.importWithoutDeps(BitIds.fromArray(ids), {
cache: false,
Expand Down Expand Up @@ -162,11 +184,6 @@ export class ImporterMain {
shouldFetchFromMain?: boolean,
options: Partial<ImportOptions> = {}
): Promise<ImportResult> {
// workaround for an issue where we have the current-lane object at hand but not its components, the sources.get
// throws an error about missing the Version object in the filesystem. to reproduce, comment the following line and
// run the e2e-test "import objects for multiple lanes".
await this.importObjects();

const resultFromMain = shouldFetchFromMain
? await this.importObjects(options)
: { importedIds: [], importDetails: [], importedDeps: [] };
Expand Down Expand Up @@ -247,11 +264,11 @@ export class ImporterMain {
install.registerPreInstall(async (opts) => {
if (!opts?.import) return;
logger.setStatusLine('importing missing objects');
await importerMain.importObjects();
await importerMain.importCurrentObjects();
logger.consoleSuccess();
});
install.registerPreLink(async (opts) => {
if (opts?.fetchObject) await importerMain.importObjects();
if (opts?.fetchObject) await importerMain.importCurrentObjects();
});
cli.register(new ImportCmd(importerMain, community.getDocsDomain()), new FetchCmd(importerMain));
return importerMain;
Expand Down