@embeddable.com/sdk-react 3.0.2-next.0 → 3.0.3
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 +39 -24
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +39 -24
- package/lib/index.js.map +1 -1
- package/lib/loadComponentMeta.d.ts +4 -1
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var zod = require('zod');
|
|
|
13
13
|
var parser = require('@babel/parser');
|
|
14
14
|
var traverse = require('@babel/traverse');
|
|
15
15
|
var fs$1 = require('fs');
|
|
16
|
+
var glob = require('glob');
|
|
16
17
|
|
|
17
18
|
function _interopNamespaceDefault(e) {
|
|
18
19
|
var n = Object.create(null);
|
|
@@ -31,9 +32,9 @@ function _interopNamespaceDefault(e) {
|
|
|
31
32
|
return Object.freeze(n);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
var path__namespace
|
|
35
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
35
36
|
var fs__namespace$2 = /*#__PURE__*/_interopNamespaceDefault(fs$2);
|
|
36
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
37
|
+
var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
37
38
|
var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
|
|
38
39
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
39
40
|
var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
|
|
@@ -51,21 +52,20 @@ var createContext = (pluginRoot, coreCtx) => {
|
|
|
51
52
|
};
|
|
52
53
|
};
|
|
53
54
|
|
|
54
|
-
const loadComponentMeta = async (moduleId, ast) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const loadComponentMeta = async ({ moduleId, ast, }) => {
|
|
56
|
+
// make it dot file so it will be hidden
|
|
57
|
+
const fileName = `.${path__namespace.basename(moduleId)}`;
|
|
58
|
+
const tempFileName = fileName.replace(".emb.ts", ".emb-temp.js");
|
|
59
|
+
const tempFilePath = path__namespace.join(path__namespace.dirname(moduleId), tempFileName);
|
|
59
60
|
try {
|
|
61
|
+
await fs__namespace.writeFile(tempFilePath, astring.generate(ast));
|
|
60
62
|
const module = await import(url__namespace.pathToFileURL(tempFilePath).href + `?${Date.now()}`);
|
|
61
63
|
return module.meta;
|
|
62
64
|
}
|
|
63
65
|
catch (e) {
|
|
64
66
|
console.error(e);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
finally {
|
|
68
|
-
await fs__namespace.rm(tempFilePath);
|
|
67
|
+
await fs__namespace.unlink(tempFilePath);
|
|
68
|
+
throw e;
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
|
|
@@ -81,7 +81,10 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
|
|
|
81
81
|
var _a;
|
|
82
82
|
if (componentFileRegex.test(moduleInfo.id) &&
|
|
83
83
|
((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
|
|
84
|
-
const meta = await loadComponentMeta(
|
|
84
|
+
const meta = await loadComponentMeta({
|
|
85
|
+
moduleId: moduleInfo.id,
|
|
86
|
+
ast: moduleInfo.ast,
|
|
87
|
+
});
|
|
85
88
|
const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
|
|
86
89
|
value !== null &&
|
|
87
90
|
"__embeddableType" in value
|
|
@@ -765,7 +768,7 @@ const validateComponentEvents = (metaInfo) => {
|
|
|
765
768
|
return errors;
|
|
766
769
|
};
|
|
767
770
|
const validateModuleName = (metaInfo) => {
|
|
768
|
-
const basename = path__namespace.basename(metaInfo.moduleId);
|
|
771
|
+
const basename = path__namespace$1.basename(metaInfo.moduleId);
|
|
769
772
|
const fileName = basename.split(".")[0];
|
|
770
773
|
if (fileName !== metaInfo.meta.name) {
|
|
771
774
|
return [
|
|
@@ -881,7 +884,10 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
881
884
|
? getModuleType(moduleInfo)
|
|
882
885
|
: null;
|
|
883
886
|
if (moduleType) {
|
|
884
|
-
const meta = await loadComponentMeta(
|
|
887
|
+
const meta = await loadComponentMeta({
|
|
888
|
+
moduleId: moduleInfo.id,
|
|
889
|
+
ast: moduleInfo.ast,
|
|
890
|
+
});
|
|
885
891
|
metaConfigs.push({
|
|
886
892
|
moduleId: moduleInfo.id,
|
|
887
893
|
meta,
|
|
@@ -926,7 +932,7 @@ const styledComponentsEntrypointModifier = {
|
|
|
926
932
|
},
|
|
927
933
|
needToModify(ctx) {
|
|
928
934
|
var _a;
|
|
929
|
-
const packageJsonFilePath = path__namespace.resolve(ctx.client.rootDir, "package.json");
|
|
935
|
+
const packageJsonFilePath = path__namespace$1.resolve(ctx.client.rootDir, "package.json");
|
|
930
936
|
const packageJson = require(packageJsonFilePath);
|
|
931
937
|
return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
|
|
932
938
|
},
|
|
@@ -941,7 +947,7 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
|
|
|
941
947
|
const files = fs__namespace$1.readdirSync(directory);
|
|
942
948
|
const result = [];
|
|
943
949
|
files.forEach((file) => {
|
|
944
|
-
const filePath = path__namespace.join(directory, file);
|
|
950
|
+
const filePath = path__namespace$1.join(directory, file);
|
|
945
951
|
if (fs__namespace$1.statSync(filePath).isDirectory()) {
|
|
946
952
|
// Recursively check files in subdirectories
|
|
947
953
|
result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
|
|
@@ -959,7 +965,7 @@ function findTypeNames(directory) {
|
|
|
959
965
|
const files = fs__namespace$1.readdirSync(directory);
|
|
960
966
|
const typeNames = [];
|
|
961
967
|
files.forEach((file) => {
|
|
962
|
-
const filePath = path__namespace.join(directory, file);
|
|
968
|
+
const filePath = path__namespace$1.join(directory, file);
|
|
963
969
|
if (fs__namespace$1.statSync(filePath).isDirectory()) {
|
|
964
970
|
// Recursively check files in subdirectories
|
|
965
971
|
typeNames.push(...findTypeNames(filePath));
|
|
@@ -1096,11 +1102,11 @@ async function runViteBuild(ctx, watch = null) {
|
|
|
1096
1102
|
watch,
|
|
1097
1103
|
minify: !watch,
|
|
1098
1104
|
lib: {
|
|
1099
|
-
entry: path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
|
|
1105
|
+
entry: path__namespace$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
|
|
1100
1106
|
formats: ["es"],
|
|
1101
1107
|
fileName: ctx["sdk-react"].outputOptions.fileName,
|
|
1102
1108
|
},
|
|
1103
|
-
outDir: path__namespace.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
|
|
1109
|
+
outDir: path__namespace$1.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
|
|
1104
1110
|
},
|
|
1105
1111
|
define: { "process.env.NODE_ENV": '"production"' },
|
|
1106
1112
|
});
|
|
@@ -1121,7 +1127,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
|
|
|
1121
1127
|
const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
|
|
1122
1128
|
const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
|
|
1123
1129
|
function getRelativeFileNameForImport(ctx, fileName) {
|
|
1124
|
-
return `./${path__namespace
|
|
1130
|
+
return `./${path__namespace$1
|
|
1125
1131
|
.relative(ctx.client.rootDir, fileName)
|
|
1126
1132
|
// it is a bit of a hack. On windows the path will look like '.src\something\something'
|
|
1127
1133
|
// but for imports it must be '.src/something/something'
|
|
@@ -1147,8 +1153,8 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
1147
1153
|
additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
|
|
1148
1154
|
}
|
|
1149
1155
|
}
|
|
1150
|
-
const content = await fs__namespace$2.readFile(path__namespace.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
1151
|
-
await fs__namespace$2.writeFile(path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
|
|
1156
|
+
const content = await fs__namespace$2.readFile(path__namespace$1.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
1157
|
+
await fs__namespace$2.writeFile(path__namespace$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
|
|
1152
1158
|
.replace(IMPORT_REPLACE_TOKEN, imports)
|
|
1153
1159
|
.replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
|
|
1154
1160
|
.replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
|
|
@@ -1158,11 +1164,20 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
1158
1164
|
}
|
|
1159
1165
|
|
|
1160
1166
|
var build = async (ctx) => {
|
|
1161
|
-
createContext(path__namespace
|
|
1167
|
+
createContext(path__namespace.resolve(__dirname, ".."), ctx);
|
|
1162
1168
|
return await generate(ctx);
|
|
1163
1169
|
};
|
|
1164
1170
|
|
|
1165
|
-
var cleanup = async (ctx) =>
|
|
1171
|
+
var cleanup = async (ctx) => {
|
|
1172
|
+
await fs.rm(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename));
|
|
1173
|
+
const tempFiles = await glob.glob(`${ctx.client.rootDir}/**/*.emb-temp.js`, {
|
|
1174
|
+
ignore: "node_modules/**",
|
|
1175
|
+
dot: true,
|
|
1176
|
+
});
|
|
1177
|
+
for (const file of tempFiles) {
|
|
1178
|
+
await fs.rm(file);
|
|
1179
|
+
}
|
|
1180
|
+
};
|
|
1166
1181
|
|
|
1167
1182
|
var index = () => {
|
|
1168
1183
|
return {
|