@uniformdev/cli 20.61.2-alpha.3 → 20.61.2-alpha.4

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.
Files changed (2) hide show
  1. package/dist/index.mjs +90 -33
  2. package/package.json +9 -9
package/dist/index.mjs CHANGED
@@ -625,6 +625,9 @@ export default uniformConfig({
625
625
  `;
626
626
 
627
627
  // src/sync/fileSyncEngineDataSource.ts
628
+ function isErrorWithCode(error, code) {
629
+ return typeof error === "object" && error !== null && "code" in error && error.code === code;
630
+ }
628
631
  async function createFileSyncEngineDataSource({
629
632
  directory,
630
633
  format = "yaml",
@@ -685,7 +688,7 @@ ${e?.message}`));
685
688
  }
686
689
  await unlink(providerId);
687
690
  },
688
- writeObject: async (object4) => {
691
+ writeObject: async (object4, existingObject) => {
689
692
  const filename = selectFilename3 ? join(directory, `${selectFilename3(object4.object)}.${format}`) : getFullFilename(object4.id);
690
693
  let contents = object4.object;
691
694
  if (selectSchemaUrl2) {
@@ -698,6 +701,18 @@ ${e?.message}`));
698
701
  console.log(`Writing file ${filename}`);
699
702
  }
700
703
  emitWithFormat(contents, format, filename);
704
+ if (existingObject?.providerId && existingObject.providerId !== filename) {
705
+ if (verbose) {
706
+ console.log(`Deleting file ${existingObject.providerId}`);
707
+ }
708
+ try {
709
+ await unlink(existingObject.providerId);
710
+ } catch (error) {
711
+ if (!isErrorWithCode(error, "ENOENT")) {
712
+ throw error;
713
+ }
714
+ }
715
+ }
701
716
  }
702
717
  };
703
718
  }
@@ -836,43 +851,46 @@ async function syncEngine({
836
851
  const ids = Array.isArray(sourceObject.id) ? sourceObject.id : [sourceObject.id];
837
852
  const targetObject = targetItems.get(ids[0]);
838
853
  status.compared++;
839
- const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter((o) => o?.object !== targetObject?.object);
854
+ const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter(
855
+ (invalidTargetObject) => typeof invalidTargetObject !== "undefined" && invalidTargetObject.object !== targetObject?.object
856
+ );
857
+ const targetIds = Array.isArray(targetObject?.id) ? targetObject.id : [targetObject?.id];
858
+ const processedIds = new Set([...ids, ...targetIds].filter((id) => typeof id === "string"));
859
+ const processUpdate = async (sourceObject2, targetObject2) => {
860
+ try {
861
+ if (!whatIf) {
862
+ const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2, targetObject2) : sourceObject2;
863
+ await target.writeObject(finalSourceObject, targetObject2);
864
+ status.changesApplied++;
865
+ }
866
+ } catch (e) {
867
+ if (onError) {
868
+ onError(e, sourceObject2);
869
+ } else {
870
+ throw new SyncEngineError(e, sourceObject2);
871
+ }
872
+ } finally {
873
+ log2({
874
+ action: "update",
875
+ id: ids[0],
876
+ providerId: sourceObject2.providerId,
877
+ displayName: sourceObject2.displayName ?? sourceObject2.providerId,
878
+ whatIf,
879
+ diff: () => diffJson(targetObject2.object, sourceObject2.object)
880
+ });
881
+ }
882
+ };
840
883
  if (targetObject && invalidTargetObjects.length === 0) {
841
884
  sourceObject = onBeforeCompareObjects ? await onBeforeCompareObjects(sourceObject, targetObject) : sourceObject;
842
885
  const compareResult = compareContents(sourceObject, targetObject);
843
886
  if (!compareResult) {
844
887
  if (mode === "createOrUpdate" || mode === "mirror") {
845
888
  status.changeCount++;
846
- const process2 = async (sourceObject2, targetObject2) => {
847
- try {
848
- if (!whatIf) {
849
- const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2, targetObject2) : sourceObject2;
850
- await target.writeObject(finalSourceObject, targetObject2);
851
- status.changesApplied++;
852
- }
853
- } catch (e) {
854
- if (onError) {
855
- onError(e, sourceObject2);
856
- } else {
857
- throw new SyncEngineError(e, sourceObject2);
858
- }
859
- } finally {
860
- log2({
861
- action: "update",
862
- id: ids[0],
863
- providerId: sourceObject2.providerId,
864
- displayName: sourceObject2.displayName ?? sourceObject2.providerId,
865
- whatIf,
866
- diff: () => diffJson(targetObject2.object, sourceObject2.object)
867
- });
868
- }
869
- };
870
- actions.push(() => process2(sourceObject, targetObject));
889
+ actions.push(() => processUpdate(sourceObject, targetObject));
871
890
  }
872
891
  }
873
- ids.forEach((i) => targetItems.delete(i));
892
+ processedIds.forEach((i) => targetItems.delete(i));
874
893
  } else {
875
- status.changeCount++;
876
894
  const processUpsert = async (sourceObject2, id) => {
877
895
  try {
878
896
  if (!whatIf) {
@@ -898,6 +916,23 @@ async function syncEngine({
898
916
  }
899
917
  };
900
918
  if (invalidTargetObjects.length > 0) {
919
+ if (mode === "createOrUpdate" && !targetObject && invalidTargetObjects.length === 1) {
920
+ const matchedTargetObject = invalidTargetObjects[0];
921
+ sourceObject = onBeforeCompareObjects ? await onBeforeCompareObjects(sourceObject, matchedTargetObject) : sourceObject;
922
+ const compareResult = compareContents(sourceObject, matchedTargetObject);
923
+ if (!compareResult) {
924
+ status.changeCount++;
925
+ actions.push(() => processUpdate(sourceObject, matchedTargetObject));
926
+ }
927
+ (Array.isArray(matchedTargetObject.id) ? matchedTargetObject.id : [matchedTargetObject.id]).forEach(
928
+ (i) => targetItems.delete(i)
929
+ );
930
+ continue;
931
+ }
932
+ if (mode !== "mirror") {
933
+ continue;
934
+ }
935
+ status.changeCount++;
901
936
  [...invalidTargetObjects, targetObject].forEach((o) => {
902
937
  (Array.isArray(o?.id) ? o?.id : [o?.id])?.forEach((i) => i && targetItems.delete(i));
903
938
  });
@@ -909,20 +944,22 @@ async function syncEngine({
909
944
  () => Promise.all(deletes.map((deleteFn) => deleteFn())).then(() => processUpsert(sourceObject, ids[0]))
910
945
  );
911
946
  } else {
947
+ status.changeCount++;
912
948
  actions.push(() => processUpsert(sourceObject, ids[0]));
913
949
  }
914
950
  }
915
951
  }
916
- status.changeCount += targetItems.size;
917
- status.compared += targetItems.size;
952
+ const orphanTargetObjects = new Set(targetItems.values());
918
953
  if (mode === "mirror") {
919
- if (!sourceHasItems && !allowEmptySource && targetItems.size > 0) {
954
+ status.changeCount += orphanTargetObjects.size;
955
+ status.compared += orphanTargetObjects.size;
956
+ if (!sourceHasItems && !allowEmptySource && orphanTargetObjects.size > 0) {
920
957
  throw new Error(
921
958
  `Sync source (${source.name}) is empty and mode is mirror. This would cause deletion of everything in the target (${target.name}), and most likely indicates an error in source definition.`
922
959
  );
923
960
  }
924
961
  const deletes = [];
925
- targetItems.forEach((object4) => {
962
+ orphanTargetObjects.forEach((object4) => {
926
963
  deletes.push(() => processDelete(object4));
927
964
  });
928
965
  await Promise.all(deletes.map((d) => d()));
@@ -11957,6 +11994,20 @@ var selectIdentifier15 = (source, projectId) => [
11957
11994
  ];
11958
11995
  var selectFilename = (source) => cleanFileName(`${source.pathSegment}_${source.id}`);
11959
11996
  var selectDisplayName15 = (source) => `${source.name} (pid: ${source.id})`;
11997
+ function alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject) {
11998
+ if (!targetObject) {
11999
+ return sourceObject;
12000
+ }
12001
+ return {
12002
+ ...sourceObject,
12003
+ id: targetObject.id,
12004
+ providerId: targetObject.providerId,
12005
+ object: {
12006
+ ...sourceObject.object,
12007
+ id: targetObject.object.id
12008
+ }
12009
+ };
12010
+ }
11960
12011
 
11961
12012
  // src/commands/project-map/ProjectMapNodeEngineDataSource.ts
11962
12013
  function createProjectMapNodeEngineDataSource({
@@ -12173,6 +12224,12 @@ var ProjectMapNodePushModule = {
12173
12224
  whatIf,
12174
12225
  allowEmptySource,
12175
12226
  log: createSyncEngineConsoleLogger({ diffMode }),
12227
+ onBeforeCompareObjects: async (sourceObject, targetObject) => {
12228
+ return alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject);
12229
+ },
12230
+ onBeforeWriteObject: async (sourceObject, targetObject) => {
12231
+ return alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject);
12232
+ },
12176
12233
  onError: (error, object4) => {
12177
12234
  if (error.message.includes(__INTERNAL_MISSING_PARENT_NODE_ERROR)) {
12178
12235
  nodesFailedDueToMissingParent.add(object4.object);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "20.61.2-alpha.3+fc997c8a8e",
3
+ "version": "20.61.2-alpha.4+06664f4ab6",
4
4
  "description": "Uniform command line interface tool",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./cli.js",
@@ -27,13 +27,13 @@
27
27
  "dependencies": {
28
28
  "@inquirer/prompts": "^7.10.1",
29
29
  "@thi.ng/mime": "^2.2.23",
30
- "@uniformdev/assets": "20.61.2-alpha.3+fc997c8a8e",
31
- "@uniformdev/canvas": "20.61.2-alpha.3+fc997c8a8e",
32
- "@uniformdev/context": "20.61.2-alpha.3+fc997c8a8e",
33
- "@uniformdev/files": "20.61.2-alpha.3+fc997c8a8e",
34
- "@uniformdev/project-map": "20.61.2-alpha.3+fc997c8a8e",
35
- "@uniformdev/redirect": "20.61.2-alpha.3+fc997c8a8e",
36
- "@uniformdev/richtext": "20.61.2-alpha.3+fc997c8a8e",
30
+ "@uniformdev/assets": "20.61.2-alpha.4+06664f4ab6",
31
+ "@uniformdev/canvas": "20.61.2-alpha.4+06664f4ab6",
32
+ "@uniformdev/context": "20.61.2-alpha.4+06664f4ab6",
33
+ "@uniformdev/files": "20.61.2-alpha.4+06664f4ab6",
34
+ "@uniformdev/project-map": "20.61.2-alpha.4+06664f4ab6",
35
+ "@uniformdev/redirect": "20.61.2-alpha.4+06664f4ab6",
36
+ "@uniformdev/richtext": "20.61.2-alpha.4+06664f4ab6",
37
37
  "call-bind": "^1.0.2",
38
38
  "colorette": "2.0.20",
39
39
  "cosmiconfig": "9.0.0",
@@ -80,5 +80,5 @@
80
80
  "publishConfig": {
81
81
  "access": "public"
82
82
  },
83
- "gitHead": "fc997c8a8e1939d5050cde71204a9212ccf1705f"
83
+ "gitHead": "06664f4ab66e0ea0fcf234095dd2024c86739a83"
84
84
  }