@embeddable.com/sdk-react 2.2.31 → 2.2.33

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/lib/index.esm.js CHANGED
@@ -806,6 +806,27 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
806
806
  });
807
807
  return result.filter((file) => !mustEndWith.some((ending) => file.endsWith(ending)));
808
808
  }
809
+ function findTypeNames(directory) {
810
+ const files = fs$1.readdirSync(directory);
811
+ const typeNames = [];
812
+ files.forEach((file) => {
813
+ const filePath = path.join(directory, file);
814
+ if (fs$1.statSync(filePath).isDirectory()) {
815
+ // Recursively check files in subdirectories
816
+ typeNames.push(...findTypeNames(filePath));
817
+ }
818
+ else {
819
+ const fileContent = fs$1.readFileSync(filePath, "utf8");
820
+ const regexDefineTypeFunctionTypeName = /defineType\(["'](.*?)["']\,/g;
821
+ const matches = fileContent.match(regexDefineTypeFunctionTypeName) || [];
822
+ const extractedContent = matches.map((match) => match.slice(12, -2))[0];
823
+ if (extractedContent) {
824
+ typeNames.push({ file: filePath, typeName: extractedContent });
825
+ }
826
+ }
827
+ });
828
+ return typeNames;
829
+ }
809
830
  const regexDefineComponentFunction = /defineComponent(<\w+>)?\(/;
810
831
  const regexDefineTypeFunction = /defineType\(/;
811
832
  const regexDefineOptionFunction = /defineOption\(/;
@@ -850,6 +871,32 @@ const usageValidator = async (directory) => {
850
871
  progress.fail("React: cubes: usage is only allowed inside files with the extension .cube.(yml|yaml) files.\nFix the following files:\n" +
851
872
  filesWithWrongCubeUsage.join("\n"));
852
873
  }
874
+ const typeNames = findTypeNames(directory);
875
+ // check for definedTypes using a native typeNames
876
+ const duplicatedNativeTypeNames = typeNames.filter((item) => ALL_NATIVE_TYPES.includes(item.typeName));
877
+ if (duplicatedNativeTypeNames.length) {
878
+ isValid = false;
879
+ progress.fail("React: defineType() can't be used with the same typeName as the nativeTypes. Fix the following files:\n" +
880
+ duplicatedNativeTypeNames
881
+ .map((dtn) => `${dtn.typeName} (file: ${dtn.file})`)
882
+ .join("\n"));
883
+ }
884
+ // check for duplicated typeNames
885
+ const duplicatedTypeNames = typeNames.filter((item, index) => {
886
+ return typeNames.some((otherItem, otherIndex) => {
887
+ if (index !== otherIndex) {
888
+ return item.typeName === otherItem.typeName;
889
+ }
890
+ return false;
891
+ });
892
+ });
893
+ if (duplicatedTypeNames.length) {
894
+ isValid = false;
895
+ progress.fail("React: defineType() must be used with a unique typeName. Fix the following files:\n" +
896
+ duplicatedTypeNames
897
+ .map((dtn) => `${dtn.typeName} (file: ${dtn.file})`)
898
+ .join("\n"));
899
+ }
853
900
  isValid
854
901
  ? progress.succeed("React: function usage validated")
855
902
  : process.exit(1);