@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.js CHANGED
@@ -6,6 +6,7 @@ var path$1 = require('path');
6
6
  var vite = require('vite');
7
7
  var viteReactPlugin = require('@vitejs/plugin-react');
8
8
  var fs = require('node:fs/promises');
9
+ var url = require('node:url');
9
10
  var parser = require('@babel/parser');
10
11
  var generator = require('@babel/generator');
11
12
  var traverse = require('@babel/traverse');
@@ -36,6 +37,7 @@ var fs__namespace$2 = /*#__PURE__*/_interopNamespaceDefault(fs$2);
36
37
  var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
37
38
  var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
38
39
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
40
+ var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
39
41
  var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
40
42
 
41
43
  var createContext = (pluginRoot, coreCtx) => {
@@ -76,8 +78,7 @@ const loadComponentMeta = async (moduleId, code) => {
76
78
  .replace(".emb.", ".emb-temp.")
77
79
  .replace(/\.ts$/, ".js");
78
80
  await fs__namespace.writeFile(tempFilePath, babelGenerate(ast).code);
79
- const importFile = `${tempFilePath}?${Date.now()}`;
80
- const module = await import(importFile);
81
+ const module = await import(url__namespace.pathToFileURL(tempFilePath).href + `?${Date.now()}`);
81
82
  await fs__namespace.rm(tempFilePath);
82
83
  return module.meta;
83
84
  };
@@ -558,7 +559,7 @@ const validateComponentProps = (metaInfo) => {
558
559
  const errors = [];
559
560
  parseAndTraverse(metaInfo.moduleInfo.code, {
560
561
  ExportDefaultDeclaration: (path) => {
561
- var _a, _b, _c;
562
+ var _a, _b, _c, _d;
562
563
  const componentConfig = path.node.declaration
563
564
  .arguments[2];
564
565
  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"; });
@@ -586,12 +587,12 @@ const validateComponentProps = (metaInfo) => {
586
587
  functionBody = propsNode.value.body.body;
587
588
  }
588
589
  const propsReturnStatement = functionBody === null || functionBody === void 0 ? void 0 : functionBody.find((x) => x.type === "ReturnStatement");
589
- 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"; });
590
+ 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"; });
590
591
  // There is no results defined inside props
591
592
  if (results === undefined) {
592
593
  return;
593
594
  }
594
- const loadDataProperties = (_c = results === null || results === void 0 ? void 0 : results.value) === null || _c === void 0 ? void 0 : _c.arguments[0].properties;
595
+ const loadDataProperties = (_d = results === null || results === void 0 ? void 0 : results.value) === null || _d === void 0 ? void 0 : _d.arguments[0].properties;
595
596
  const dimensions = loadDataProperties === null || loadDataProperties === void 0 ? void 0 : loadDataProperties.find((prop) => prop.key.name === "dimensions");
596
597
  const timeDimensions = loadDataProperties === null || loadDataProperties === void 0 ? void 0 : loadDataProperties.find((prop) => prop.key.name === "timeDimensions");
597
598
  // There is no missuse of dimensions and timeDimensions
@@ -947,14 +948,21 @@ const ERROR_FALLBACK_COMPONENT_DEFAULT_NAME = "ErrorFallbackComponent";
947
948
  const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
948
949
  const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
949
950
  const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
951
+ function getRelativeFileNameForImport(ctx, fileName) {
952
+ return `./${path__namespace
953
+ .relative(ctx.client.rootDir, fileName)
954
+ // it is a bit of a hack. On windows the path will look like '.src\something\something'
955
+ // but for imports it must be '.src/something/something'
956
+ .replaceAll("\\", "/")}`;
957
+ }
950
958
  async function prepareEntrypoint(ctx, filesList) {
951
959
  const imports = filesList
952
- .map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('./${path__namespace.relative(ctx.client.rootDir, filePath)}'))`)
960
+ .map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('${getRelativeFileNameForImport(ctx, filePath)}'))`)
953
961
  .join(",\n");
954
962
  let errorBoundaryImport = "";
955
963
  let errorFallbackComponent = "null";
956
964
  if (ctx.client.errorFallbackComponent) {
957
- errorBoundaryImport = `import ${ERROR_FALLBACK_COMPONENT_DEFAULT_NAME} from './${path__namespace.relative(ctx.client.rootDir, ctx.client.errorFallbackComponent)}';`;
965
+ errorBoundaryImport = `import ${ERROR_FALLBACK_COMPONENT_DEFAULT_NAME} from '${getRelativeFileNameForImport(ctx, ctx.client.errorFallbackComponent)}';`;
958
966
  errorFallbackComponent = ERROR_FALLBACK_COMPONENT_DEFAULT_NAME;
959
967
  }
960
968
  const additionalContentImport = [];