@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 +1 -1
- package/lib/generate.d.ts +2 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +44 -15
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +44 -15
- package/lib/index.js.map +1 -1
- package/lib/validate/schema/componentMetaSchema.d.ts +38 -2
- package/package.json +1 -1
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
704
|
-
|
|
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
|
-
|
|
708
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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));
|