@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.esm.js CHANGED
@@ -26,7 +26,7 @@ var createContext = (pluginRoot, coreCtx) => {
26
26
  };
27
27
 
28
28
  // @ts-ignore
29
- const babelTraverse = traverse.default;
29
+ const babelTraverse$1 = traverse.default;
30
30
  // @ts-ignore
31
31
  const babelGenerate = generator.default;
32
32
  const CORE_TYPES_IMPORT_REGEX = /@embeddable\.com\/core$/;
@@ -35,7 +35,7 @@ const loadComponentMeta = async (moduleId, code) => {
35
35
  const ast = parse(code, {
36
36
  sourceType: "module",
37
37
  });
38
- babelTraverse(ast, {
38
+ babelTraverse$1(ast, {
39
39
  ImportDeclaration: (path) => {
40
40
  const isNativeTypesImport = CORE_TYPES_IMPORT_REGEX.test(path.node.source.value);
41
41
  const isCustomTypeImport = EMB_TYPE_FILE_REGEX.test(path.node.source.value);
@@ -505,12 +505,42 @@ const componentMetaSchema = z
505
505
  }
506
506
  });
507
507
 
508
+ // @ts-ignore
509
+ const babelTraverse = traverse.default;
508
510
  const componentMetaValidator = (metaInfo) => {
509
511
  const result = componentMetaSchema.safeParse(metaInfo.meta);
510
512
  if (!result.success)
511
513
  return errorFormatter(result.error.issues);
512
- let errors = validateModuleName(metaInfo);
513
- errors = errors.concat(validateVariables(metaInfo.meta));
514
+ let moduleNameErrors = validateModuleName(metaInfo);
515
+ const variableErrors = validateVariables(metaInfo.meta);
516
+ const eventErrors = validateComponentEvents(metaInfo);
517
+ return [...moduleNameErrors, ...variableErrors, ...eventErrors];
518
+ };
519
+ const validateComponentEvents = (metaInfo) => {
520
+ var _a, _b;
521
+ const definedEvents = (_b = (_a = metaInfo.meta.events) === null || _a === void 0 ? void 0 : _a.map((e) => e.name)) !== null && _b !== void 0 ? _b : [];
522
+ let implementedEvents = [];
523
+ const errors = [];
524
+ babelTraverse(metaInfo.moduleInfo.ast, {
525
+ ExportDefaultDeclaration: (path) => {
526
+ var _a, _b, _c, _d;
527
+ const componentConfig = path.node.declaration
528
+ .arguments[2];
529
+ 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"; });
530
+ implementedEvents =
531
+ (_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 : [];
532
+ },
533
+ });
534
+ const definedEventsSet = new Set(definedEvents);
535
+ const implementedEventsSet = new Set(implementedEvents);
536
+ const notImplementedEvents = definedEvents.filter((e) => !implementedEventsSet.has(e));
537
+ const notDefinedEvents = implementedEvents.filter((e) => !definedEventsSet.has(e));
538
+ for (const notDefinedEvent of notDefinedEvents) {
539
+ errors.push(`event '${notDefinedEvent}' is not defined in the component's meta`);
540
+ }
541
+ for (const notImplementedEvent of notImplementedEvents) {
542
+ errors.push(`event '${notImplementedEvent}' is defined but not implemented`);
543
+ }
514
544
  return errors;
515
545
  };
516
546
  const validateModuleName = (metaInfo) => {
@@ -635,6 +665,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
635
665
  moduleId: moduleInfo.id,
636
666
  meta,
637
667
  moduleType,
668
+ moduleInfo,
638
669
  });
639
670
  }
640
671
  },
@@ -739,7 +770,7 @@ async function runViteBuild(ctx, watch = null) {
739
770
  async function runViteWatch(ctx) {
740
771
  const watch = {
741
772
  chokidar: {
742
- ignored: ["**/node_modules/**", /.*\.emb-temp.js$/],
773
+ ignored: ["**/node_modules/**", /.*\.emb-temp.js$/, /.*\.cube.js$/],
743
774
  },
744
775
  };
745
776
  return (await runViteBuild(ctx, watch));