@embeddable.com/sdk-react 2.2.28 → 2.2.30
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.esm.js +14 -7
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +15 -7
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -6,6 +6,7 @@ import * as vite from 'vite';
|
|
|
6
6
|
import viteReactPlugin from '@vitejs/plugin-react';
|
|
7
7
|
import * as fs from 'node:fs/promises';
|
|
8
8
|
import { readdir, lstat, rm } from 'node:fs/promises';
|
|
9
|
+
import * as url from 'node:url';
|
|
9
10
|
import { parse } from '@babel/parser';
|
|
10
11
|
import generator from '@babel/generator';
|
|
11
12
|
import traverse from '@babel/traverse';
|
|
@@ -52,8 +53,7 @@ const loadComponentMeta = async (moduleId, code) => {
|
|
|
52
53
|
.replace(".emb.", ".emb-temp.")
|
|
53
54
|
.replace(/\.ts$/, ".js");
|
|
54
55
|
await fs.writeFile(tempFilePath, babelGenerate(ast).code);
|
|
55
|
-
const
|
|
56
|
-
const module = await import(importFile);
|
|
56
|
+
const module = await import(url.pathToFileURL(tempFilePath).href + `?${Date.now()}`);
|
|
57
57
|
await fs.rm(tempFilePath);
|
|
58
58
|
return module.meta;
|
|
59
59
|
};
|
|
@@ -534,7 +534,7 @@ const validateComponentProps = (metaInfo) => {
|
|
|
534
534
|
const errors = [];
|
|
535
535
|
parseAndTraverse(metaInfo.moduleInfo.code, {
|
|
536
536
|
ExportDefaultDeclaration: (path) => {
|
|
537
|
-
var _a, _b, _c;
|
|
537
|
+
var _a, _b, _c, _d;
|
|
538
538
|
const componentConfig = path.node.declaration
|
|
539
539
|
.arguments[2];
|
|
540
540
|
const propsNode = (_a = componentConfig.properties) === null || _a === void 0 ? void 0 : _a.find((x) => { var _a; return ((_a = x.key) === null || _a === void 0 ? void 0 : _a.name) === "props"; });
|
|
@@ -562,12 +562,12 @@ const validateComponentProps = (metaInfo) => {
|
|
|
562
562
|
functionBody = propsNode.value.body.body;
|
|
563
563
|
}
|
|
564
564
|
const propsReturnStatement = functionBody === null || functionBody === void 0 ? void 0 : functionBody.find((x) => x.type === "ReturnStatement");
|
|
565
|
-
const results = (_b = propsReturnStatement === null || propsReturnStatement === void 0 ? void 0 : propsReturnStatement.argument) === null || _b === void 0 ? void 0 : _b.properties.find((x) => { var _a; return ((_a = x === null || x === void 0 ? void 0 : x.key) === null || _a === void 0 ? void 0 : _a.name) === "results"; });
|
|
565
|
+
const results = (_c = (_b = propsReturnStatement === null || propsReturnStatement === void 0 ? void 0 : propsReturnStatement.argument) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.find((x) => { var _a; return ((_a = x === null || x === void 0 ? void 0 : x.key) === null || _a === void 0 ? void 0 : _a.name) === "results"; });
|
|
566
566
|
// There is no results defined inside props
|
|
567
567
|
if (results === undefined) {
|
|
568
568
|
return;
|
|
569
569
|
}
|
|
570
|
-
const loadDataProperties = (
|
|
570
|
+
const loadDataProperties = (_d = results === null || results === void 0 ? void 0 : results.value) === null || _d === void 0 ? void 0 : _d.arguments[0].properties;
|
|
571
571
|
const dimensions = loadDataProperties === null || loadDataProperties === void 0 ? void 0 : loadDataProperties.find((prop) => prop.key.name === "dimensions");
|
|
572
572
|
const timeDimensions = loadDataProperties === null || loadDataProperties === void 0 ? void 0 : loadDataProperties.find((prop) => prop.key.name === "timeDimensions");
|
|
573
573
|
// There is no missuse of dimensions and timeDimensions
|
|
@@ -923,14 +923,21 @@ const ERROR_FALLBACK_COMPONENT_DEFAULT_NAME = "ErrorFallbackComponent";
|
|
|
923
923
|
const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
|
|
924
924
|
const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
|
|
925
925
|
const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
|
|
926
|
+
function getRelativeFileNameForImport(ctx, fileName) {
|
|
927
|
+
return `./${path
|
|
928
|
+
.relative(ctx.client.rootDir, fileName)
|
|
929
|
+
// it is a bit of a hack. On windows the path will look like '.src\something\something'
|
|
930
|
+
// but for imports it must be '.src/something/something'
|
|
931
|
+
.replaceAll("\\", "/")}`;
|
|
932
|
+
}
|
|
926
933
|
async function prepareEntrypoint(ctx, filesList) {
|
|
927
934
|
const imports = filesList
|
|
928
|
-
.map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('
|
|
935
|
+
.map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('${getRelativeFileNameForImport(ctx, filePath)}'))`)
|
|
929
936
|
.join(",\n");
|
|
930
937
|
let errorBoundaryImport = "";
|
|
931
938
|
let errorFallbackComponent = "null";
|
|
932
939
|
if (ctx.client.errorFallbackComponent) {
|
|
933
|
-
errorBoundaryImport = `import ${ERROR_FALLBACK_COMPONENT_DEFAULT_NAME} from '
|
|
940
|
+
errorBoundaryImport = `import ${ERROR_FALLBACK_COMPONENT_DEFAULT_NAME} from '${getRelativeFileNameForImport(ctx, ctx.client.errorFallbackComponent)}';`;
|
|
934
941
|
errorFallbackComponent = ERROR_FALLBACK_COMPONENT_DEFAULT_NAME;
|
|
935
942
|
}
|
|
936
943
|
const additionalContentImport = [];
|