@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.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as path
|
|
1
|
+
import * as path from 'node:path';
|
|
2
2
|
import { resolve, join } from 'node:path';
|
|
3
3
|
import * as fs$2 from 'fs/promises';
|
|
4
|
-
import * as path from 'path';
|
|
4
|
+
import * as path$1 from 'path';
|
|
5
5
|
import * as vite from 'vite';
|
|
6
6
|
import viteReactPlugin from '@vitejs/plugin-react';
|
|
7
7
|
import * as fs from 'node:fs/promises';
|
|
@@ -13,6 +13,7 @@ import { z } from 'zod';
|
|
|
13
13
|
import { parse } from '@babel/parser';
|
|
14
14
|
import traverse from '@babel/traverse';
|
|
15
15
|
import * as fs$1 from 'fs';
|
|
16
|
+
import { glob } from 'glob';
|
|
16
17
|
|
|
17
18
|
var createContext = (pluginRoot, coreCtx) => {
|
|
18
19
|
coreCtx["sdk-react"] = {
|
|
@@ -26,21 +27,20 @@ var createContext = (pluginRoot, coreCtx) => {
|
|
|
26
27
|
};
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
const loadComponentMeta = async (moduleId, ast) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const loadComponentMeta = async ({ moduleId, ast, }) => {
|
|
31
|
+
// make it dot file so it will be hidden
|
|
32
|
+
const fileName = `.${path.basename(moduleId)}`;
|
|
33
|
+
const tempFileName = fileName.replace(".emb.ts", ".emb-temp.js");
|
|
34
|
+
const tempFilePath = path.join(path.dirname(moduleId), tempFileName);
|
|
34
35
|
try {
|
|
36
|
+
await fs.writeFile(tempFilePath, generate$1(ast));
|
|
35
37
|
const module = await import(url.pathToFileURL(tempFilePath).href + `?${Date.now()}`);
|
|
36
38
|
return module.meta;
|
|
37
39
|
}
|
|
38
40
|
catch (e) {
|
|
39
41
|
console.error(e);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
finally {
|
|
43
|
-
await fs.rm(tempFilePath);
|
|
42
|
+
await fs.unlink(tempFilePath);
|
|
43
|
+
throw e;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
|
|
@@ -56,7 +56,10 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
|
|
|
56
56
|
var _a;
|
|
57
57
|
if (componentFileRegex.test(moduleInfo.id) &&
|
|
58
58
|
((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
|
|
59
|
-
const meta = await loadComponentMeta(
|
|
59
|
+
const meta = await loadComponentMeta({
|
|
60
|
+
moduleId: moduleInfo.id,
|
|
61
|
+
ast: moduleInfo.ast,
|
|
62
|
+
});
|
|
60
63
|
const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
|
|
61
64
|
value !== null &&
|
|
62
65
|
"__embeddableType" in value
|
|
@@ -740,7 +743,7 @@ const validateComponentEvents = (metaInfo) => {
|
|
|
740
743
|
return errors;
|
|
741
744
|
};
|
|
742
745
|
const validateModuleName = (metaInfo) => {
|
|
743
|
-
const basename = path.basename(metaInfo.moduleId);
|
|
746
|
+
const basename = path$1.basename(metaInfo.moduleId);
|
|
744
747
|
const fileName = basename.split(".")[0];
|
|
745
748
|
if (fileName !== metaInfo.meta.name) {
|
|
746
749
|
return [
|
|
@@ -856,7 +859,10 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
856
859
|
? getModuleType(moduleInfo)
|
|
857
860
|
: null;
|
|
858
861
|
if (moduleType) {
|
|
859
|
-
const meta = await loadComponentMeta(
|
|
862
|
+
const meta = await loadComponentMeta({
|
|
863
|
+
moduleId: moduleInfo.id,
|
|
864
|
+
ast: moduleInfo.ast,
|
|
865
|
+
});
|
|
860
866
|
metaConfigs.push({
|
|
861
867
|
moduleId: moduleInfo.id,
|
|
862
868
|
meta,
|
|
@@ -901,7 +907,7 @@ const styledComponentsEntrypointModifier = {
|
|
|
901
907
|
},
|
|
902
908
|
needToModify(ctx) {
|
|
903
909
|
var _a;
|
|
904
|
-
const packageJsonFilePath = path.resolve(ctx.client.rootDir, "package.json");
|
|
910
|
+
const packageJsonFilePath = path$1.resolve(ctx.client.rootDir, "package.json");
|
|
905
911
|
const packageJson = require(packageJsonFilePath);
|
|
906
912
|
return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
|
|
907
913
|
},
|
|
@@ -916,7 +922,7 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
|
|
|
916
922
|
const files = fs$1.readdirSync(directory);
|
|
917
923
|
const result = [];
|
|
918
924
|
files.forEach((file) => {
|
|
919
|
-
const filePath = path.join(directory, file);
|
|
925
|
+
const filePath = path$1.join(directory, file);
|
|
920
926
|
if (fs$1.statSync(filePath).isDirectory()) {
|
|
921
927
|
// Recursively check files in subdirectories
|
|
922
928
|
result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
|
|
@@ -934,7 +940,7 @@ function findTypeNames(directory) {
|
|
|
934
940
|
const files = fs$1.readdirSync(directory);
|
|
935
941
|
const typeNames = [];
|
|
936
942
|
files.forEach((file) => {
|
|
937
|
-
const filePath = path.join(directory, file);
|
|
943
|
+
const filePath = path$1.join(directory, file);
|
|
938
944
|
if (fs$1.statSync(filePath).isDirectory()) {
|
|
939
945
|
// Recursively check files in subdirectories
|
|
940
946
|
typeNames.push(...findTypeNames(filePath));
|
|
@@ -1071,11 +1077,11 @@ async function runViteBuild(ctx, watch = null) {
|
|
|
1071
1077
|
watch,
|
|
1072
1078
|
minify: !watch,
|
|
1073
1079
|
lib: {
|
|
1074
|
-
entry: path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
|
|
1080
|
+
entry: path$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
|
|
1075
1081
|
formats: ["es"],
|
|
1076
1082
|
fileName: ctx["sdk-react"].outputOptions.fileName,
|
|
1077
1083
|
},
|
|
1078
|
-
outDir: path.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
|
|
1084
|
+
outDir: path$1.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
|
|
1079
1085
|
},
|
|
1080
1086
|
define: { "process.env.NODE_ENV": '"production"' },
|
|
1081
1087
|
});
|
|
@@ -1096,7 +1102,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
|
|
|
1096
1102
|
const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
|
|
1097
1103
|
const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
|
|
1098
1104
|
function getRelativeFileNameForImport(ctx, fileName) {
|
|
1099
|
-
return `./${path
|
|
1105
|
+
return `./${path$1
|
|
1100
1106
|
.relative(ctx.client.rootDir, fileName)
|
|
1101
1107
|
// it is a bit of a hack. On windows the path will look like '.src\something\something'
|
|
1102
1108
|
// but for imports it must be '.src/something/something'
|
|
@@ -1122,8 +1128,8 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
1122
1128
|
additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
|
|
1123
1129
|
}
|
|
1124
1130
|
}
|
|
1125
|
-
const content = await fs$2.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
1126
|
-
await fs$2.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
|
|
1131
|
+
const content = await fs$2.readFile(path$1.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
1132
|
+
await fs$2.writeFile(path$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
|
|
1127
1133
|
.replace(IMPORT_REPLACE_TOKEN, imports)
|
|
1128
1134
|
.replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
|
|
1129
1135
|
.replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
|
|
@@ -1133,11 +1139,20 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
1133
1139
|
}
|
|
1134
1140
|
|
|
1135
1141
|
var build = async (ctx) => {
|
|
1136
|
-
createContext(path
|
|
1142
|
+
createContext(path.resolve(__dirname, ".."), ctx);
|
|
1137
1143
|
return await generate(ctx);
|
|
1138
1144
|
};
|
|
1139
1145
|
|
|
1140
|
-
var cleanup = async (ctx) =>
|
|
1146
|
+
var cleanup = async (ctx) => {
|
|
1147
|
+
await rm(resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename));
|
|
1148
|
+
const tempFiles = await glob(`${ctx.client.rootDir}/**/*.emb-temp.js`, {
|
|
1149
|
+
ignore: "node_modules/**",
|
|
1150
|
+
dot: true,
|
|
1151
|
+
});
|
|
1152
|
+
for (const file of tempFiles) {
|
|
1153
|
+
await rm(file);
|
|
1154
|
+
}
|
|
1155
|
+
};
|
|
1141
1156
|
|
|
1142
1157
|
var index = () => {
|
|
1143
1158
|
return {
|