@embeddable.com/sdk-react 2.2.14 → 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 +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/build.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (ctx: any) => Promise<
|
|
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
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<
|
|
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
|
|
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
|
-
|
|
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
|
};
|
|
@@ -619,7 +621,7 @@ const getModuleType = (moduleInfo) => {
|
|
|
619
621
|
}
|
|
620
622
|
};
|
|
621
623
|
var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
622
|
-
|
|
624
|
+
let metaConfigs = [];
|
|
623
625
|
return {
|
|
624
626
|
name: "validate-component-meta",
|
|
625
627
|
moduleParsed: async (moduleInfo) => {
|
|
@@ -644,6 +646,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
644
646
|
errors.push(`\nComponent meta is not valid ${metaConfig.moduleId}:\n${validationResult.join("\n")}`);
|
|
645
647
|
}
|
|
646
648
|
}
|
|
649
|
+
metaConfigs = [];
|
|
647
650
|
if (errors.length) {
|
|
648
651
|
// @ts-ignore
|
|
649
652
|
this.error(errors.join("\n"));
|
|
@@ -683,30 +686,37 @@ const entrypointModifiers = [
|
|
|
683
686
|
const oraP = import('ora');
|
|
684
687
|
const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
|
|
685
688
|
var generate = async (ctx) => {
|
|
689
|
+
var _a;
|
|
686
690
|
const ora = (await oraP).default;
|
|
687
|
-
const progress = ora("React: building components...").start();
|
|
688
691
|
const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
689
692
|
await prepareEntrypoint(ctx, filesList);
|
|
690
|
-
|
|
691
|
-
|
|
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;
|
|
692
703
|
};
|
|
693
|
-
async function runViteBuild(ctx) {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
logLevel: "error",
|
|
704
|
+
async function runViteBuild(ctx, watch = null) {
|
|
705
|
+
return await vite.build({
|
|
706
|
+
logLevel: !!watch ? "info" : "error",
|
|
697
707
|
plugins: [
|
|
698
708
|
viteReactPlugin(),
|
|
699
709
|
extractComponentsConfigPlugin({
|
|
700
710
|
globalKey: "componentsMeta",
|
|
701
711
|
fileName: "embeddable-components-meta.js",
|
|
702
|
-
outputDir:
|
|
712
|
+
outputDir: ctx.client.buildDir,
|
|
703
713
|
componentFileRegex: EMB_FILE_REGEX,
|
|
704
714
|
searchEntry: "defineComponent",
|
|
705
715
|
}),
|
|
706
716
|
extractComponentsConfigPlugin({
|
|
707
717
|
globalKey: "editorsMeta",
|
|
708
718
|
fileName: "embeddable-editors-meta.js",
|
|
709
|
-
outputDir:
|
|
719
|
+
outputDir: ctx.client.buildDir,
|
|
710
720
|
componentFileRegex: EMB_FILE_REGEX,
|
|
711
721
|
searchEntry: "defineEditor",
|
|
712
722
|
}),
|
|
@@ -714,16 +724,25 @@ async function runViteBuild(ctx) {
|
|
|
714
724
|
],
|
|
715
725
|
build: {
|
|
716
726
|
sourcemap: true,
|
|
727
|
+
watch,
|
|
717
728
|
lib: {
|
|
718
|
-
entry:
|
|
729
|
+
entry: path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
|
|
719
730
|
formats: ["es"],
|
|
720
731
|
fileName: ctx["sdk-react"].outputOptions.fileName,
|
|
721
732
|
},
|
|
722
|
-
outDir:
|
|
733
|
+
outDir: path.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
|
|
723
734
|
},
|
|
724
735
|
define: { "process.env.NODE_ENV": '"production"' },
|
|
725
736
|
});
|
|
726
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
|
+
}
|
|
727
746
|
const IMPORT_REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
|
|
728
747
|
const ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN = "{{ERROR_FALLBACK_COMPONENT_IMPORT}}";
|
|
729
748
|
const ERROR_FALLBACK_COMPONENT_TOKEN = "{{ERROR_FALLBACK_COMPONENT}}";
|
|
@@ -763,7 +782,7 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
763
782
|
|
|
764
783
|
var build = async (ctx) => {
|
|
765
784
|
createContext(path$1.resolve(__dirname, ".."), ctx);
|
|
766
|
-
await generate(ctx);
|
|
785
|
+
return await generate(ctx);
|
|
767
786
|
};
|
|
768
787
|
|
|
769
788
|
var cleanup = async (ctx) => await rm(resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename));
|