@embeddable.com/sdk-react 2.2.29 → 2.2.31
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 +11 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +12 -4
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
};
|
|
@@ -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('
|
|
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 '
|
|
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 = [];
|