@embeddable.com/sdk-react 2.2.13 → 2.2.15

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
@@ -74,7 +74,8 @@ const loadComponentMeta = async (moduleId, code) => {
74
74
  .replace(".emb.", ".emb-temp.")
75
75
  .replace(/\.ts$/, ".js");
76
76
  await fs__namespace.writeFile(tempFilePath, babelGenerate(ast).code);
77
- const module = await import(tempFilePath);
77
+ const importFile = `${tempFilePath}?${Date.now()}`;
78
+ const module = await import(importFile);
78
79
  await fs__namespace.rm(tempFilePath);
79
80
  return module.meta;
80
81
  };
@@ -84,7 +85,7 @@ const loadComponentMeta = async (moduleId, code) => {
84
85
  * is being cached. Thus we use this code duplication in place. Please investigate and fix.
85
86
  */
86
87
  var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, componentFileRegex, searchEntry = "", }) => {
87
- const configs = [];
88
+ let configs = [];
88
89
  return {
89
90
  name: "extract-components-config",
90
91
  moduleParsed: async (moduleInfo) => {
@@ -108,6 +109,7 @@ globalThis.__EMBEDDABLE__.${globalKey} = globalThis.__EMBEDDABLE__.${globalKey}
108
109
  ];
109
110
  `;
110
111
  await fs__namespace.writeFile(`${outputDir}/${fileName}`, template.replace("__PLACEHOLDER__", configs.filter(Boolean).join(",\n")));
112
+ configs = [];
111
113
  },
112
114
  };
113
115
  };
@@ -467,6 +469,16 @@ const componentMetaSchema = zod.z
467
469
  })
468
470
  .strict()
469
471
  .array()
472
+ .superRefine((inputs, refinementContext) => {
473
+ const inputNames = inputs.map((input) => input.name);
474
+ if (new Set(inputNames).size !== inputNames.length) {
475
+ const duplicateInputNames = inputNames.filter((name, index) => inputNames.indexOf(name) !== index);
476
+ return refinementContext.addIssue({
477
+ code: zod.z.ZodIssueCode.custom,
478
+ message: `Input names must be unique. Duplicate names: ${duplicateInputNames.join(", ")}`,
479
+ });
480
+ }
481
+ })
470
482
  .optional(),
471
483
  events: zod.z
472
484
  .object({
@@ -632,7 +644,7 @@ const getModuleType = (moduleInfo) => {
632
644
  }
633
645
  };
634
646
  var validateComponentMetaPlugin = (componentFileRegex) => {
635
- const metaConfigs = [];
647
+ let metaConfigs = [];
636
648
  return {
637
649
  name: "validate-component-meta",
638
650
  moduleParsed: async (moduleInfo) => {
@@ -657,6 +669,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
657
669
  errors.push(`\nComponent meta is not valid ${metaConfig.moduleId}:\n${validationResult.join("\n")}`);
658
670
  }
659
671
  }
672
+ metaConfigs = [];
660
673
  if (errors.length) {
661
674
  // @ts-ignore
662
675
  this.error(errors.join("\n"));
@@ -696,30 +709,37 @@ const entrypointModifiers = [
696
709
  const oraP = import('ora');
697
710
  const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
698
711
  var generate = async (ctx) => {
712
+ var _a;
699
713
  const ora = (await oraP).default;
700
- const progress = ora("React: building components...").start();
701
714
  const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
702
715
  await prepareEntrypoint(ctx, filesList);
703
- await runViteBuild(ctx);
704
- progress.succeed("React: components built completed");
716
+ let result;
717
+ if ((_a = ctx.dev) === null || _a === void 0 ? void 0 : _a.watch) {
718
+ result = await runViteWatch(ctx);
719
+ }
720
+ else {
721
+ const progress = ora("React: building components...").start();
722
+ result = await runViteBuild(ctx);
723
+ progress.succeed("React: components built completed");
724
+ }
725
+ return result;
705
726
  };
706
- async function runViteBuild(ctx) {
707
- process.chdir(ctx.client.rootDir);
708
- await vite__namespace.build({
709
- logLevel: "error",
727
+ async function runViteBuild(ctx, watch = null) {
728
+ return await vite__namespace.build({
729
+ logLevel: !!watch ? "info" : "error",
710
730
  plugins: [
711
731
  viteReactPlugin(),
712
732
  extractComponentsConfigPlugin({
713
733
  globalKey: "componentsMeta",
714
734
  fileName: "embeddable-components-meta.js",
715
- outputDir: ".embeddable-build",
735
+ outputDir: ctx.client.buildDir,
716
736
  componentFileRegex: EMB_FILE_REGEX,
717
737
  searchEntry: "defineComponent",
718
738
  }),
719
739
  extractComponentsConfigPlugin({
720
740
  globalKey: "editorsMeta",
721
741
  fileName: "embeddable-editors-meta.js",
722
- outputDir: ".embeddable-build",
742
+ outputDir: ctx.client.buildDir,
723
743
  componentFileRegex: EMB_FILE_REGEX,
724
744
  searchEntry: "defineEditor",
725
745
  }),
@@ -727,16 +747,25 @@ async function runViteBuild(ctx) {
727
747
  ],
728
748
  build: {
729
749
  sourcemap: true,
750
+ watch,
730
751
  lib: {
731
- entry: `./${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}`,
752
+ entry: path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
732
753
  formats: ["es"],
733
754
  fileName: ctx["sdk-react"].outputOptions.fileName,
734
755
  },
735
- outDir: `.embeddable-build/${ctx["sdk-react"].outputOptions.buildName}`,
756
+ outDir: path__namespace.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
736
757
  },
737
758
  define: { "process.env.NODE_ENV": '"production"' },
738
759
  });
739
760
  }
761
+ async function runViteWatch(ctx) {
762
+ const watch = {
763
+ chokidar: {
764
+ ignored: ["**/node_modules/**", /.*\.emb-temp.js$/],
765
+ },
766
+ };
767
+ return (await runViteBuild(ctx, watch));
768
+ }
740
769
  const IMPORT_REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
741
770
  const ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN = "{{ERROR_FALLBACK_COMPONENT_IMPORT}}";
742
771
  const ERROR_FALLBACK_COMPONENT_TOKEN = "{{ERROR_FALLBACK_COMPONENT}}";
@@ -776,7 +805,7 @@ async function prepareEntrypoint(ctx, filesList) {
776
805
 
777
806
  var build = async (ctx) => {
778
807
  createContext(path__namespace$1.resolve(__dirname, ".."), ctx);
779
- await generate(ctx);
808
+ return await generate(ctx);
780
809
  };
781
810
 
782
811
  var cleanup = async (ctx) => await fs.rm(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename));