@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/build.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: (ctx: any) => Promise<void>;
1
+ declare const _default: (ctx: any) => Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
2
2
  export default _default;
package/lib/generate.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- declare const _default: (ctx: any) => Promise<void>;
1
+ import * as vite from "vite";
2
+ declare const _default: (ctx: any) => Promise<vite.Rollup.RollupOutput | vite.Rollup.RollupOutput[] | vite.Rollup.RollupWatcher>;
2
3
  export default _default;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare const _default: () => {
2
2
  pluginName: string;
3
3
  validate: () => Promise<void>;
4
- build: (ctx: any) => Promise<void>;
4
+ build: (ctx: any) => Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
5
5
  cleanup: (ctx: any) => Promise<void>;
6
6
  };
7
7
  export default _default;
package/lib/index.esm.js CHANGED
@@ -51,7 +51,8 @@ const loadComponentMeta = async (moduleId, code) => {
51
51
  .replace(".emb.", ".emb-temp.")
52
52
  .replace(/\.ts$/, ".js");
53
53
  await fs.writeFile(tempFilePath, babelGenerate(ast).code);
54
- const module = await import(tempFilePath);
54
+ const importFile = `${tempFilePath}?${Date.now()}`;
55
+ const module = await import(importFile);
55
56
  await fs.rm(tempFilePath);
56
57
  return module.meta;
57
58
  };
@@ -61,7 +62,7 @@ const loadComponentMeta = async (moduleId, code) => {
61
62
  * is being cached. Thus we use this code duplication in place. Please investigate and fix.
62
63
  */
63
64
  var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, componentFileRegex, searchEntry = "", }) => {
64
- const configs = [];
65
+ let configs = [];
65
66
  return {
66
67
  name: "extract-components-config",
67
68
  moduleParsed: async (moduleInfo) => {
@@ -85,6 +86,7 @@ globalThis.__EMBEDDABLE__.${globalKey} = globalThis.__EMBEDDABLE__.${globalKey}
85
86
  ];
86
87
  `;
87
88
  await fs.writeFile(`${outputDir}/${fileName}`, template.replace("__PLACEHOLDER__", configs.filter(Boolean).join(",\n")));
89
+ configs = [];
88
90
  },
89
91
  };
90
92
  };
@@ -444,6 +446,16 @@ const componentMetaSchema = z
444
446
  })
445
447
  .strict()
446
448
  .array()
449
+ .superRefine((inputs, refinementContext) => {
450
+ const inputNames = inputs.map((input) => input.name);
451
+ if (new Set(inputNames).size !== inputNames.length) {
452
+ const duplicateInputNames = inputNames.filter((name, index) => inputNames.indexOf(name) !== index);
453
+ return refinementContext.addIssue({
454
+ code: z.ZodIssueCode.custom,
455
+ message: `Input names must be unique. Duplicate names: ${duplicateInputNames.join(", ")}`,
456
+ });
457
+ }
458
+ })
447
459
  .optional(),
448
460
  events: z
449
461
  .object({
@@ -609,7 +621,7 @@ const getModuleType = (moduleInfo) => {
609
621
  }
610
622
  };
611
623
  var validateComponentMetaPlugin = (componentFileRegex) => {
612
- const metaConfigs = [];
624
+ let metaConfigs = [];
613
625
  return {
614
626
  name: "validate-component-meta",
615
627
  moduleParsed: async (moduleInfo) => {
@@ -634,6 +646,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
634
646
  errors.push(`\nComponent meta is not valid ${metaConfig.moduleId}:\n${validationResult.join("\n")}`);
635
647
  }
636
648
  }
649
+ metaConfigs = [];
637
650
  if (errors.length) {
638
651
  // @ts-ignore
639
652
  this.error(errors.join("\n"));
@@ -673,30 +686,37 @@ const entrypointModifiers = [
673
686
  const oraP = import('ora');
674
687
  const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
675
688
  var generate = async (ctx) => {
689
+ var _a;
676
690
  const ora = (await oraP).default;
677
- const progress = ora("React: building components...").start();
678
691
  const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
679
692
  await prepareEntrypoint(ctx, filesList);
680
- await runViteBuild(ctx);
681
- progress.succeed("React: components built completed");
693
+ let result;
694
+ if ((_a = ctx.dev) === null || _a === void 0 ? void 0 : _a.watch) {
695
+ result = await runViteWatch(ctx);
696
+ }
697
+ else {
698
+ const progress = ora("React: building components...").start();
699
+ result = await runViteBuild(ctx);
700
+ progress.succeed("React: components built completed");
701
+ }
702
+ return result;
682
703
  };
683
- async function runViteBuild(ctx) {
684
- process.chdir(ctx.client.rootDir);
685
- await vite.build({
686
- logLevel: "error",
704
+ async function runViteBuild(ctx, watch = null) {
705
+ return await vite.build({
706
+ logLevel: !!watch ? "info" : "error",
687
707
  plugins: [
688
708
  viteReactPlugin(),
689
709
  extractComponentsConfigPlugin({
690
710
  globalKey: "componentsMeta",
691
711
  fileName: "embeddable-components-meta.js",
692
- outputDir: ".embeddable-build",
712
+ outputDir: ctx.client.buildDir,
693
713
  componentFileRegex: EMB_FILE_REGEX,
694
714
  searchEntry: "defineComponent",
695
715
  }),
696
716
  extractComponentsConfigPlugin({
697
717
  globalKey: "editorsMeta",
698
718
  fileName: "embeddable-editors-meta.js",
699
- outputDir: ".embeddable-build",
719
+ outputDir: ctx.client.buildDir,
700
720
  componentFileRegex: EMB_FILE_REGEX,
701
721
  searchEntry: "defineEditor",
702
722
  }),
@@ -704,16 +724,25 @@ async function runViteBuild(ctx) {
704
724
  ],
705
725
  build: {
706
726
  sourcemap: true,
727
+ watch,
707
728
  lib: {
708
- entry: `./${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}`,
729
+ entry: path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
709
730
  formats: ["es"],
710
731
  fileName: ctx["sdk-react"].outputOptions.fileName,
711
732
  },
712
- outDir: `.embeddable-build/${ctx["sdk-react"].outputOptions.buildName}`,
733
+ outDir: path.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
713
734
  },
714
735
  define: { "process.env.NODE_ENV": '"production"' },
715
736
  });
716
737
  }
738
+ async function runViteWatch(ctx) {
739
+ const watch = {
740
+ chokidar: {
741
+ ignored: ["**/node_modules/**", /.*\.emb-temp.js$/],
742
+ },
743
+ };
744
+ return (await runViteBuild(ctx, watch));
745
+ }
717
746
  const IMPORT_REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
718
747
  const ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN = "{{ERROR_FALLBACK_COMPONENT_IMPORT}}";
719
748
  const ERROR_FALLBACK_COMPONENT_TOKEN = "{{ERROR_FALLBACK_COMPONENT}}";
@@ -753,7 +782,7 @@ async function prepareEntrypoint(ctx, filesList) {
753
782
 
754
783
  var build = async (ctx) => {
755
784
  createContext(path$1.resolve(__dirname, ".."), ctx);
756
- await generate(ctx);
785
+ return await generate(ctx);
757
786
  };
758
787
 
759
788
  var cleanup = async (ctx) => await rm(resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename));