@embeddable.com/sdk-react 2.2.14 → 2.2.16
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 +34 -15
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +34 -15
- package/lib/index.js.map +1 -1
- 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
|
};
|
|
@@ -642,7 +644,7 @@ const getModuleType = (moduleInfo) => {
|
|
|
642
644
|
}
|
|
643
645
|
};
|
|
644
646
|
var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
645
|
-
|
|
647
|
+
let metaConfigs = [];
|
|
646
648
|
return {
|
|
647
649
|
name: "validate-component-meta",
|
|
648
650
|
moduleParsed: async (moduleInfo) => {
|
|
@@ -667,6 +669,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
667
669
|
errors.push(`\nComponent meta is not valid ${metaConfig.moduleId}:\n${validationResult.join("\n")}`);
|
|
668
670
|
}
|
|
669
671
|
}
|
|
672
|
+
metaConfigs = [];
|
|
670
673
|
if (errors.length) {
|
|
671
674
|
// @ts-ignore
|
|
672
675
|
this.error(errors.join("\n"));
|
|
@@ -706,30 +709,37 @@ const entrypointModifiers = [
|
|
|
706
709
|
const oraP = import('ora');
|
|
707
710
|
const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
|
|
708
711
|
var generate = async (ctx) => {
|
|
712
|
+
var _a;
|
|
709
713
|
const ora = (await oraP).default;
|
|
710
|
-
const progress = ora("React: building components...").start();
|
|
711
714
|
const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
712
715
|
await prepareEntrypoint(ctx, filesList);
|
|
713
|
-
|
|
714
|
-
|
|
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;
|
|
715
726
|
};
|
|
716
|
-
async function runViteBuild(ctx) {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
logLevel: "error",
|
|
727
|
+
async function runViteBuild(ctx, watch = null) {
|
|
728
|
+
return await vite__namespace.build({
|
|
729
|
+
logLevel: !!watch ? "info" : "error",
|
|
720
730
|
plugins: [
|
|
721
731
|
viteReactPlugin(),
|
|
722
732
|
extractComponentsConfigPlugin({
|
|
723
733
|
globalKey: "componentsMeta",
|
|
724
734
|
fileName: "embeddable-components-meta.js",
|
|
725
|
-
outputDir:
|
|
735
|
+
outputDir: ctx.client.buildDir,
|
|
726
736
|
componentFileRegex: EMB_FILE_REGEX,
|
|
727
737
|
searchEntry: "defineComponent",
|
|
728
738
|
}),
|
|
729
739
|
extractComponentsConfigPlugin({
|
|
730
740
|
globalKey: "editorsMeta",
|
|
731
741
|
fileName: "embeddable-editors-meta.js",
|
|
732
|
-
outputDir:
|
|
742
|
+
outputDir: ctx.client.buildDir,
|
|
733
743
|
componentFileRegex: EMB_FILE_REGEX,
|
|
734
744
|
searchEntry: "defineEditor",
|
|
735
745
|
}),
|
|
@@ -737,16 +747,25 @@ async function runViteBuild(ctx) {
|
|
|
737
747
|
],
|
|
738
748
|
build: {
|
|
739
749
|
sourcemap: true,
|
|
750
|
+
watch,
|
|
740
751
|
lib: {
|
|
741
|
-
entry:
|
|
752
|
+
entry: path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
|
|
742
753
|
formats: ["es"],
|
|
743
754
|
fileName: ctx["sdk-react"].outputOptions.fileName,
|
|
744
755
|
},
|
|
745
|
-
outDir:
|
|
756
|
+
outDir: path__namespace.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
|
|
746
757
|
},
|
|
747
758
|
define: { "process.env.NODE_ENV": '"production"' },
|
|
748
759
|
});
|
|
749
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
|
+
}
|
|
750
769
|
const IMPORT_REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
|
|
751
770
|
const ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN = "{{ERROR_FALLBACK_COMPONENT_IMPORT}}";
|
|
752
771
|
const ERROR_FALLBACK_COMPONENT_TOKEN = "{{ERROR_FALLBACK_COMPONENT}}";
|
|
@@ -786,7 +805,7 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
786
805
|
|
|
787
806
|
var build = async (ctx) => {
|
|
788
807
|
createContext(path__namespace$1.resolve(__dirname, ".."), ctx);
|
|
789
|
-
await generate(ctx);
|
|
808
|
+
return await generate(ctx);
|
|
790
809
|
};
|
|
791
810
|
|
|
792
811
|
var cleanup = async (ctx) => await fs.rm(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename));
|