@teambit/snapping 1.0.443 → 1.0.444
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/__bit_junit.xml +6 -6
- package/artifacts/schema.json +807 -419
- package/dist/snapping.main.runtime.d.ts +6 -0
- package/dist/snapping.main.runtime.js +147 -40
- package/dist/snapping.main.runtime.js.map +1 -1
- package/package.json +28 -28
- /package/dist/{preview-1729740041534.js → preview-1729785193922.js} +0 -0
|
@@ -115,6 +115,12 @@ export declare class SnappingMain {
|
|
|
115
115
|
rebuildArtifacts?: boolean;
|
|
116
116
|
ignoreLastPkgJson?: boolean;
|
|
117
117
|
} & Partial<BasicTagParams>): Promise<TagResults | null>;
|
|
118
|
+
forkAndSnap(snapDataPerCompRaw: SnapDataPerCompRaw[], params: {
|
|
119
|
+
push?: boolean;
|
|
120
|
+
ignoreIssues?: string;
|
|
121
|
+
lane?: string;
|
|
122
|
+
updateDependents?: boolean;
|
|
123
|
+
} & Partial<BasicTagParams>): Promise<SnapFromScopeResults>;
|
|
118
124
|
snapFromScope(snapDataPerCompRaw: SnapDataPerCompRaw[], params: {
|
|
119
125
|
push?: boolean;
|
|
120
126
|
ignoreIssues?: string;
|
|
@@ -578,10 +578,10 @@ if you're willing to lose the history from the head to the specified version, us
|
|
|
578
578
|
newComponents: new (_componentId().ComponentIdList)()
|
|
579
579
|
};
|
|
580
580
|
}
|
|
581
|
-
async
|
|
582
|
-
const
|
|
583
|
-
if (
|
|
584
|
-
throw new (_bitError().BitError)(`
|
|
581
|
+
async forkAndSnap(snapDataPerCompRaw, params) {
|
|
582
|
+
const allAreForkedFrom = snapDataPerCompRaw.every(s => s.forkFrom);
|
|
583
|
+
if (!allAreForkedFrom) {
|
|
584
|
+
throw new (_bitError().BitError)(`when forkedFrom prop is used, all components must have the forkedFrom prop`);
|
|
585
585
|
}
|
|
586
586
|
let lane;
|
|
587
587
|
const laneIdStr = params.lane;
|
|
@@ -592,18 +592,9 @@ if you're willing to lose the history from the head to the specified version, us
|
|
|
592
592
|
} catch (err) {
|
|
593
593
|
if (err.constructor.name !== _legacy2().LaneNotFound.name) throw err;
|
|
594
594
|
// if the lane is not found, it's probably because it's new. create a new lane.
|
|
595
|
-
lane = await (0, _lanesModules().
|
|
596
|
-
// it's important to set the lane as new in scope.json. otherwise, later, when importing and the lane is loaded
|
|
597
|
-
// from the filesystem, it looses the "isNew: true", and then it tries to fetch the lane from the remote scope.
|
|
598
|
-
// which fails with the importer.
|
|
599
|
-
this.scope.legacyScope.scopeJson.setLaneAsNew(laneId.name);
|
|
595
|
+
lane = await (0, _lanesModules().createLane)(this.workspace, laneId.name, laneId.scope);
|
|
600
596
|
}
|
|
601
|
-
// this is critical. otherwise, later on, when loading aspects and isolating capsules, we'll try to fetch dists
|
|
602
|
-
// from the original scope instead of the lane-scope.
|
|
603
|
-
this.scope.legacyScope.setCurrentLaneId(laneId);
|
|
604
|
-
this.scope.legacyScope.scopeImporter.shouldOnlyFetchFromCurrentLane = true;
|
|
605
597
|
}
|
|
606
|
-
const laneCompIds = lane?.toComponentIdsIncludeUpdateDependents();
|
|
607
598
|
const snapDataPerComp = snapDataPerCompRaw.map(snapData => {
|
|
608
599
|
return {
|
|
609
600
|
componentId: _componentId().ComponentID.fromString(snapData.componentId),
|
|
@@ -620,18 +611,14 @@ if you're willing to lose the history from the head to the specified version, us
|
|
|
620
611
|
type: dep.type ?? 'runtime'
|
|
621
612
|
})),
|
|
622
613
|
removeDependencies: snapData.removeDependencies,
|
|
623
|
-
forkFrom:
|
|
614
|
+
forkFrom: _componentId().ComponentID.fromString(snapData.forkFrom)
|
|
624
615
|
};
|
|
625
616
|
});
|
|
626
617
|
|
|
627
618
|
// console.log('snapDataPerComp', JSON.stringify(snapDataPerComp, undefined, 2));
|
|
628
619
|
|
|
629
|
-
const componentIds = (0, _lodash().compact)(snapDataPerComp.map(t => t.isNew || t.forkFrom ? null : t.componentId));
|
|
630
620
|
const allCompIds = snapDataPerComp.map(s => s.componentId);
|
|
631
|
-
const componentIdsLatest = componentIds.map(id => id.changeVersion(_constants().LATEST));
|
|
632
|
-
const newCompsData = (0, _lodash().compact)(snapDataPerComp.map(t => t.isNew && !t.forkFrom ? t : null));
|
|
633
621
|
const forkedFromData = (0, _lodash().compact)(snapDataPerComp.map(t => t.forkFrom ? t : null));
|
|
634
|
-
const newComponents = await Promise.all(newCompsData.map(newComp => (0, _generateCompFromScope().generateCompFromScope)(this.scope, newComp, this)));
|
|
635
622
|
const forkMultipleData = forkedFromData.map(f => ({
|
|
636
623
|
sourceId: f.forkFrom.toString(),
|
|
637
624
|
targetId: f.componentId.fullName,
|
|
@@ -655,7 +642,138 @@ if you're willing to lose the history from the head to the specified version, us
|
|
|
655
642
|
await (0, _pMapSeries().default)(Object.entries(newEnvData), async ([env, compIds]) => {
|
|
656
643
|
await this.workspace.setEnvToComponents(_componentId().ComponentID.fromString(env), compIds, false);
|
|
657
644
|
});
|
|
645
|
+
// @todo: merge current config in .bitmap with "aspect" prop of forkedFromData.
|
|
646
|
+
const getSnapData = id => {
|
|
647
|
+
const snapData = snapDataPerComp.find(t => {
|
|
648
|
+
return t.componentId.isEqual(id, {
|
|
649
|
+
ignoreVersion: true
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
if (!snapData) throw new Error(`unable to find ${id.toString()} in snapDataPerComp`);
|
|
653
|
+
return snapData;
|
|
654
|
+
};
|
|
658
655
|
const newForkedComponents = forkResults.length ? await this.workspace.getMany(forkResults.map(f => f.targetCompId)) : [];
|
|
656
|
+
await Promise.all(newForkedComponents.map(async comp => {
|
|
657
|
+
const snapData = getSnapData(comp.id);
|
|
658
|
+
// if (snapData.aspects) await this.scope.addAspectsFromConfigObject(comp, snapData.aspects);
|
|
659
|
+
if (snapData.files?.length) {
|
|
660
|
+
await this.updateSourceFiles(comp, snapData.files);
|
|
661
|
+
await this.workspace.write(comp);
|
|
662
|
+
}
|
|
663
|
+
}));
|
|
664
|
+
// if you don't clear the cache here, the installation assumes all components have the old env.
|
|
665
|
+
await this.workspace.clearCache();
|
|
666
|
+
await this.install.install(undefined, {
|
|
667
|
+
dedupe: true,
|
|
668
|
+
import: false,
|
|
669
|
+
copyPeerToRuntimeOnRoot: true,
|
|
670
|
+
copyPeerToRuntimeOnComponents: false,
|
|
671
|
+
updateExisting: false
|
|
672
|
+
});
|
|
673
|
+
// if we don't clear the cache here, the "build" process during tag doesn't install the necessary packages
|
|
674
|
+
// on the capsules.
|
|
675
|
+
await this.workspace.clearCache();
|
|
676
|
+
const components = await this.workspace.getMany(forkedFromData.map(f => f.componentId));
|
|
677
|
+
const consumerComponents = components.map(c => c.state._consumer);
|
|
678
|
+
const ids = _componentId().ComponentIdList.fromArray(allCompIds);
|
|
679
|
+
const results = await (0, _tagModelComponent().tagModelComponent)(_objectSpread(_objectSpread({}, params), {}, {
|
|
680
|
+
scope: this.scope,
|
|
681
|
+
consumerComponents,
|
|
682
|
+
tagDataPerComp: snapDataPerComp.map(s => ({
|
|
683
|
+
componentId: s.componentId,
|
|
684
|
+
message: s.message,
|
|
685
|
+
dependencies: []
|
|
686
|
+
})),
|
|
687
|
+
snapping: this,
|
|
688
|
+
builder: this.builder,
|
|
689
|
+
dependencyResolver: this.dependencyResolver,
|
|
690
|
+
skipAutoTag: true,
|
|
691
|
+
persist: true,
|
|
692
|
+
isSnap: true,
|
|
693
|
+
ids,
|
|
694
|
+
message: params.message,
|
|
695
|
+
updateDependentsOnLane: params.updateDependents
|
|
696
|
+
}));
|
|
697
|
+
const {
|
|
698
|
+
taggedComponents
|
|
699
|
+
} = results;
|
|
700
|
+
let exportedIds;
|
|
701
|
+
if (params.push) {
|
|
702
|
+
const updatedLane = lane ? await this.scope.legacyScope.loadLane(lane.toLaneId()) : undefined;
|
|
703
|
+
const {
|
|
704
|
+
exported
|
|
705
|
+
} = await this.exporter.exportMany({
|
|
706
|
+
scope: this.scope.legacyScope,
|
|
707
|
+
ids,
|
|
708
|
+
idsWithFutureScope: ids,
|
|
709
|
+
allVersions: false,
|
|
710
|
+
laneObject: updatedLane,
|
|
711
|
+
// no need other snaps. only the latest one. without this option, when snapping on lane from another-scope, it
|
|
712
|
+
// may throw an error saying the previous snaps don't exist on the filesystem.
|
|
713
|
+
// (see the e2e - "snap on a lane when the component is new to the lane and the scope")
|
|
714
|
+
exportHeadsOnly: true
|
|
715
|
+
});
|
|
716
|
+
exportedIds = exported;
|
|
717
|
+
}
|
|
718
|
+
return {
|
|
719
|
+
snappedComponents: taggedComponents,
|
|
720
|
+
snappedIds: taggedComponents.map(comp => comp.id),
|
|
721
|
+
exportedIds
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
async snapFromScope(snapDataPerCompRaw, params) {
|
|
725
|
+
const hasForkedFrom = snapDataPerCompRaw.some(s => s.forkFrom);
|
|
726
|
+
if (hasForkedFrom) return this.forkAndSnap(snapDataPerCompRaw, params);
|
|
727
|
+
if (this.workspace) {
|
|
728
|
+
throw new (_bitError().BitError)(`unable to run this command from a workspace, please create a new bare-scope and run it from there`);
|
|
729
|
+
}
|
|
730
|
+
let lane;
|
|
731
|
+
const laneIdStr = params.lane;
|
|
732
|
+
if (laneIdStr) {
|
|
733
|
+
const laneId = _laneId().LaneId.parse(laneIdStr);
|
|
734
|
+
try {
|
|
735
|
+
lane = await this.importer.importLaneObject(laneId);
|
|
736
|
+
} catch (err) {
|
|
737
|
+
if (err.constructor.name !== _legacy2().LaneNotFound.name) throw err;
|
|
738
|
+
// if the lane is not found, it's probably because it's new. create a new lane.
|
|
739
|
+
lane = await (0, _lanesModules().createLaneInScope)(laneId.name, this.scope, laneId.scope);
|
|
740
|
+
// it's important to set the lane as new in scope.json. otherwise, later, when importing and the lane is loaded
|
|
741
|
+
// from the filesystem, it looses the "isNew: true", and then it tries to fetch the lane from the remote scope.
|
|
742
|
+
// which fails with the importer.
|
|
743
|
+
this.scope.legacyScope.scopeJson.setLaneAsNew(laneId.name);
|
|
744
|
+
}
|
|
745
|
+
// this is critical. otherwise, later on, when loading aspects and isolating capsules, we'll try to fetch dists
|
|
746
|
+
// from the original scope instead of the lane-scope.
|
|
747
|
+
this.scope.legacyScope.setCurrentLaneId(laneId);
|
|
748
|
+
this.scope.legacyScope.scopeImporter.shouldOnlyFetchFromCurrentLane = true;
|
|
749
|
+
}
|
|
750
|
+
const laneCompIds = lane?.toComponentIdsIncludeUpdateDependents();
|
|
751
|
+
const snapDataPerComp = snapDataPerCompRaw.map(snapData => {
|
|
752
|
+
return {
|
|
753
|
+
componentId: _componentId().ComponentID.fromString(snapData.componentId),
|
|
754
|
+
dependencies: snapData.dependencies || [],
|
|
755
|
+
aspects: snapData.aspects,
|
|
756
|
+
message: snapData.message,
|
|
757
|
+
files: snapData.files,
|
|
758
|
+
isNew: snapData.isNew,
|
|
759
|
+
mainFile: snapData.mainFile,
|
|
760
|
+
newDependencies: (snapData.newDependencies || []).map(dep => ({
|
|
761
|
+
id: dep.id,
|
|
762
|
+
version: dep.version,
|
|
763
|
+
isComponent: dep.isComponent ?? true,
|
|
764
|
+
type: dep.type ?? 'runtime'
|
|
765
|
+
})),
|
|
766
|
+
removeDependencies: snapData.removeDependencies
|
|
767
|
+
};
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
// console.log('snapDataPerComp', JSON.stringify(snapDataPerComp, undefined, 2));
|
|
771
|
+
|
|
772
|
+
const componentIds = (0, _lodash().compact)(snapDataPerComp.map(t => t.isNew ? null : t.componentId));
|
|
773
|
+
const allCompIds = snapDataPerComp.map(s => s.componentId);
|
|
774
|
+
const componentIdsLatest = componentIds.map(id => id.changeVersion(_constants().LATEST));
|
|
775
|
+
const newCompsData = (0, _lodash().compact)(snapDataPerComp.map(t => t.isNew ? t : null));
|
|
776
|
+
const newComponents = await Promise.all(newCompsData.map(newComp => (0, _generateCompFromScope().generateCompFromScope)(this.scope, newComp, this)));
|
|
659
777
|
await this.scope.import(componentIdsLatest, {
|
|
660
778
|
preferDependencyGraph: false,
|
|
661
779
|
lane,
|
|
@@ -685,7 +803,7 @@ if you're willing to lose the history from the head to the specified version, us
|
|
|
685
803
|
});
|
|
686
804
|
});
|
|
687
805
|
}
|
|
688
|
-
const components = [...existingComponents, ...newComponents
|
|
806
|
+
const components = [...existingComponents, ...newComponents];
|
|
689
807
|
|
|
690
808
|
// this must be done before we load component aspects later on, because this updated deps may update aspects.
|
|
691
809
|
await (0, _pMapSeries().default)(components, async component => {
|
|
@@ -695,33 +813,22 @@ if you're willing to lose the history from the head to the specified version, us
|
|
|
695
813
|
});
|
|
696
814
|
|
|
697
815
|
// for new components these are not needed. coz when generating them we already add the aspects and the files.
|
|
698
|
-
await Promise.all(
|
|
816
|
+
await Promise.all(existingComponents.map(async comp => {
|
|
699
817
|
const snapData = getSnapData(comp.id);
|
|
700
818
|
if (snapData.aspects) await this.scope.addAspectsFromConfigObject(comp, snapData.aspects);
|
|
701
819
|
if (snapData.files?.length) {
|
|
702
820
|
await this.updateSourceFiles(comp, snapData.files);
|
|
703
821
|
}
|
|
704
822
|
}));
|
|
705
|
-
if (!this.workspace) {
|
|
706
|
-
// load the aspects user configured to set on the components. it creates capsules if needed.
|
|
707
|
-
// otherwise, when a user set a custom-env, it won't be loaded and the Version object will leave the
|
|
708
|
-
// teambit.envs/envs in a weird state. the config will be set correctly but the data will be set to the default
|
|
709
|
-
// node env.
|
|
710
|
-
await this.scope.loadManyCompsAspects(components);
|
|
711
823
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
copyPeerToRuntimeOnRoot: true,
|
|
721
|
-
copyPeerToRuntimeOnComponents: false,
|
|
722
|
-
updateExisting: false
|
|
723
|
-
});
|
|
724
|
-
}
|
|
824
|
+
// load the aspects user configured to set on the components. it creates capsules if needed.
|
|
825
|
+
// otherwise, when a user set a custom-env, it won't be loaded and the Version object will leave the
|
|
826
|
+
// teambit.envs/envs in a weird state. the config will be set correctly but the data will be set to the default
|
|
827
|
+
// node env.
|
|
828
|
+
await this.scope.loadManyCompsAspects(components);
|
|
829
|
+
|
|
830
|
+
// this is similar to what happens in the workspace. the "onLoad" is running and populating the "data" of the aspects.
|
|
831
|
+
await (0, _pMapSeries().default)(components, async comp => this.scope.executeOnCompAspectReCalcSlot(comp));
|
|
725
832
|
const consumerComponents = components.map(c => c.state._consumer);
|
|
726
833
|
const ids = _componentId().ComponentIdList.fromArray(allCompIds);
|
|
727
834
|
const results = await (0, _tagModelComponent().tagModelComponent)(_objectSpread(_objectSpread({}, params), {}, {
|