@embeddable.com/sdk-react 2.2.17 → 2.2.19

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.js CHANGED
@@ -49,7 +49,7 @@ var createContext = (pluginRoot, coreCtx) => {
49
49
  };
50
50
 
51
51
  // @ts-ignore
52
- const babelTraverse = traverse.default;
52
+ const babelTraverse$1 = traverse.default;
53
53
  // @ts-ignore
54
54
  const babelGenerate = generator.default;
55
55
  const CORE_TYPES_IMPORT_REGEX = /@embeddable\.com\/core$/;
@@ -58,7 +58,7 @@ const loadComponentMeta = async (moduleId, code) => {
58
58
  const ast = parser.parse(code, {
59
59
  sourceType: "module",
60
60
  });
61
- babelTraverse(ast, {
61
+ babelTraverse$1(ast, {
62
62
  ImportDeclaration: (path) => {
63
63
  const isNativeTypesImport = CORE_TYPES_IMPORT_REGEX.test(path.node.source.value);
64
64
  const isCustomTypeImport = EMB_TYPE_FILE_REGEX.test(path.node.source.value);
@@ -528,12 +528,42 @@ const componentMetaSchema = zod.z
528
528
  }
529
529
  });
530
530
 
531
+ // @ts-ignore
532
+ const babelTraverse = traverse.default;
531
533
  const componentMetaValidator = (metaInfo) => {
532
534
  const result = componentMetaSchema.safeParse(metaInfo.meta);
533
535
  if (!result.success)
534
536
  return errorFormatter(result.error.issues);
535
- let errors = validateModuleName(metaInfo);
536
- errors = errors.concat(validateVariables(metaInfo.meta));
537
+ let moduleNameErrors = validateModuleName(metaInfo);
538
+ const variableErrors = validateVariables(metaInfo.meta);
539
+ const eventErrors = validateComponentEvents(metaInfo);
540
+ return [...moduleNameErrors, ...variableErrors, ...eventErrors];
541
+ };
542
+ const validateComponentEvents = (metaInfo) => {
543
+ var _a, _b;
544
+ const definedEvents = (_b = (_a = metaInfo.meta.events) === null || _a === void 0 ? void 0 : _a.map((e) => e.name)) !== null && _b !== void 0 ? _b : [];
545
+ let implementedEvents = [];
546
+ const errors = [];
547
+ babelTraverse(metaInfo.moduleInfo.ast, {
548
+ ExportDefaultDeclaration: (path) => {
549
+ var _a, _b, _c, _d;
550
+ const componentConfig = path.node.declaration
551
+ .arguments[2];
552
+ const eventsNode = (_a = componentConfig.properties) === null || _a === void 0 ? void 0 : _a.find((p) => { var _a; return ((_a = p.key) === null || _a === void 0 ? void 0 : _a.name) === "events"; });
553
+ implementedEvents =
554
+ (_d = (_c = (_b = eventsNode === null || eventsNode === void 0 ? void 0 : eventsNode.value) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.map((p) => p.key.name)) !== null && _d !== void 0 ? _d : [];
555
+ },
556
+ });
557
+ const definedEventsSet = new Set(definedEvents);
558
+ const implementedEventsSet = new Set(implementedEvents);
559
+ const notImplementedEvents = definedEvents.filter((e) => !implementedEventsSet.has(e));
560
+ const notDefinedEvents = implementedEvents.filter((e) => !definedEventsSet.has(e));
561
+ for (const notDefinedEvent of notDefinedEvents) {
562
+ errors.push(`event '${notDefinedEvent}' is not defined in the component's meta`);
563
+ }
564
+ for (const notImplementedEvent of notImplementedEvents) {
565
+ errors.push(`event '${notImplementedEvent}' is defined but not implemented`);
566
+ }
537
567
  return errors;
538
568
  };
539
569
  const validateModuleName = (metaInfo) => {
@@ -658,6 +688,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
658
688
  moduleId: moduleInfo.id,
659
689
  meta,
660
690
  moduleType,
691
+ moduleInfo,
661
692
  });
662
693
  }
663
694
  },
@@ -762,7 +793,7 @@ async function runViteBuild(ctx, watch = null) {
762
793
  async function runViteWatch(ctx) {
763
794
  const watch = {
764
795
  chokidar: {
765
- ignored: ["**/node_modules/**", /.*\.emb-temp.js$/],
796
+ ignored: ["**/node_modules/**", /.*\.emb-temp.js$/, /.*\.cube.js$/],
766
797
  },
767
798
  };
768
799
  return (await runViteBuild(ctx, watch));