@embeddable.com/sdk-react 3.0.2 → 3.1.0-next.1
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 +46 -23
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +46 -23
- package/lib/index.js.map +1 -1
- package/lib/loadComponentMeta.d.ts +4 -1
- package/package.json +3 -2
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,14 +52,21 @@ var createContext = (pluginRoot, coreCtx) => {
|
|
|
51
52
|
};
|
|
52
53
|
};
|
|
53
54
|
|
|
54
|
-
const loadComponentMeta = async (moduleId, ast) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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);
|
|
60
|
+
try {
|
|
61
|
+
await fs__namespace.writeFile(tempFilePath, astring.generate(ast));
|
|
62
|
+
const module = await import(url__namespace.pathToFileURL(tempFilePath).href + `?${Date.now()}`);
|
|
63
|
+
return module.meta;
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.error(e);
|
|
67
|
+
await fs__namespace.unlink(tempFilePath);
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
62
70
|
};
|
|
63
71
|
|
|
64
72
|
/**
|
|
@@ -73,7 +81,10 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
|
|
|
73
81
|
var _a;
|
|
74
82
|
if (componentFileRegex.test(moduleInfo.id) &&
|
|
75
83
|
((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
|
|
76
|
-
const meta = await loadComponentMeta(
|
|
84
|
+
const meta = await loadComponentMeta({
|
|
85
|
+
moduleId: moduleInfo.id,
|
|
86
|
+
ast: moduleInfo.ast,
|
|
87
|
+
});
|
|
77
88
|
const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
|
|
78
89
|
value !== null &&
|
|
79
90
|
"__embeddableType" in value
|
|
@@ -757,7 +768,7 @@ const validateComponentEvents = (metaInfo) => {
|
|
|
757
768
|
return errors;
|
|
758
769
|
};
|
|
759
770
|
const validateModuleName = (metaInfo) => {
|
|
760
|
-
const basename = path__namespace.basename(metaInfo.moduleId);
|
|
771
|
+
const basename = path__namespace$1.basename(metaInfo.moduleId);
|
|
761
772
|
const fileName = basename.split(".")[0];
|
|
762
773
|
if (fileName !== metaInfo.meta.name) {
|
|
763
774
|
return [
|
|
@@ -873,7 +884,10 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
873
884
|
? getModuleType(moduleInfo)
|
|
874
885
|
: null;
|
|
875
886
|
if (moduleType) {
|
|
876
|
-
const meta = await loadComponentMeta(
|
|
887
|
+
const meta = await loadComponentMeta({
|
|
888
|
+
moduleId: moduleInfo.id,
|
|
889
|
+
ast: moduleInfo.ast,
|
|
890
|
+
});
|
|
877
891
|
metaConfigs.push({
|
|
878
892
|
moduleId: moduleInfo.id,
|
|
879
893
|
meta,
|
|
@@ -918,7 +932,7 @@ const styledComponentsEntrypointModifier = {
|
|
|
918
932
|
},
|
|
919
933
|
needToModify(ctx) {
|
|
920
934
|
var _a;
|
|
921
|
-
const packageJsonFilePath = path__namespace.resolve(ctx.client.rootDir, "package.json");
|
|
935
|
+
const packageJsonFilePath = path__namespace$1.resolve(ctx.client.rootDir, "package.json");
|
|
922
936
|
const packageJson = require(packageJsonFilePath);
|
|
923
937
|
return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
|
|
924
938
|
},
|
|
@@ -933,7 +947,7 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
|
|
|
933
947
|
const files = fs__namespace$1.readdirSync(directory);
|
|
934
948
|
const result = [];
|
|
935
949
|
files.forEach((file) => {
|
|
936
|
-
const filePath = path__namespace.join(directory, file);
|
|
950
|
+
const filePath = path__namespace$1.join(directory, file);
|
|
937
951
|
if (fs__namespace$1.statSync(filePath).isDirectory()) {
|
|
938
952
|
// Recursively check files in subdirectories
|
|
939
953
|
result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
|
|
@@ -951,7 +965,7 @@ function findTypeNames(directory) {
|
|
|
951
965
|
const files = fs__namespace$1.readdirSync(directory);
|
|
952
966
|
const typeNames = [];
|
|
953
967
|
files.forEach((file) => {
|
|
954
|
-
const filePath = path__namespace.join(directory, file);
|
|
968
|
+
const filePath = path__namespace$1.join(directory, file);
|
|
955
969
|
if (fs__namespace$1.statSync(filePath).isDirectory()) {
|
|
956
970
|
// Recursively check files in subdirectories
|
|
957
971
|
typeNames.push(...findTypeNames(filePath));
|
|
@@ -1088,11 +1102,11 @@ async function runViteBuild(ctx, watch = null) {
|
|
|
1088
1102
|
watch,
|
|
1089
1103
|
minify: !watch,
|
|
1090
1104
|
lib: {
|
|
1091
|
-
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),
|
|
1092
1106
|
formats: ["es"],
|
|
1093
1107
|
fileName: ctx["sdk-react"].outputOptions.fileName,
|
|
1094
1108
|
},
|
|
1095
|
-
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),
|
|
1096
1110
|
},
|
|
1097
1111
|
define: { "process.env.NODE_ENV": '"production"' },
|
|
1098
1112
|
});
|
|
@@ -1113,7 +1127,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
|
|
|
1113
1127
|
const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
|
|
1114
1128
|
const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
|
|
1115
1129
|
function getRelativeFileNameForImport(ctx, fileName) {
|
|
1116
|
-
return `./${path__namespace
|
|
1130
|
+
return `./${path__namespace$1
|
|
1117
1131
|
.relative(ctx.client.rootDir, fileName)
|
|
1118
1132
|
// it is a bit of a hack. On windows the path will look like '.src\something\something'
|
|
1119
1133
|
// but for imports it must be '.src/something/something'
|
|
@@ -1139,8 +1153,8 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
1139
1153
|
additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
|
|
1140
1154
|
}
|
|
1141
1155
|
}
|
|
1142
|
-
const content = await fs__namespace$2.readFile(path__namespace.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
1143
|
-
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
|
|
1144
1158
|
.replace(IMPORT_REPLACE_TOKEN, imports)
|
|
1145
1159
|
.replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
|
|
1146
1160
|
.replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
|
|
@@ -1150,11 +1164,20 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
1150
1164
|
}
|
|
1151
1165
|
|
|
1152
1166
|
var build = async (ctx) => {
|
|
1153
|
-
createContext(path__namespace
|
|
1167
|
+
createContext(path__namespace.resolve(__dirname, ".."), ctx);
|
|
1154
1168
|
return await generate(ctx);
|
|
1155
1169
|
};
|
|
1156
1170
|
|
|
1157
|
-
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
|
+
};
|
|
1158
1181
|
|
|
1159
1182
|
var index = () => {
|
|
1160
1183
|
return {
|