@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.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,14 +27,21 @@ var createContext = (pluginRoot, coreCtx) => {
|
|
|
26
27
|
};
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
const loadComponentMeta = async (moduleId, ast) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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);
|
|
35
|
+
try {
|
|
36
|
+
await fs.writeFile(tempFilePath, generate$1(ast));
|
|
37
|
+
const module = await import(url.pathToFileURL(tempFilePath).href + `?${Date.now()}`);
|
|
38
|
+
return module.meta;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.error(e);
|
|
42
|
+
await fs.unlink(tempFilePath);
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
37
45
|
};
|
|
38
46
|
|
|
39
47
|
/**
|
|
@@ -48,7 +56,10 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
|
|
|
48
56
|
var _a;
|
|
49
57
|
if (componentFileRegex.test(moduleInfo.id) &&
|
|
50
58
|
((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
|
|
51
|
-
const meta = await loadComponentMeta(
|
|
59
|
+
const meta = await loadComponentMeta({
|
|
60
|
+
moduleId: moduleInfo.id,
|
|
61
|
+
ast: moduleInfo.ast,
|
|
62
|
+
});
|
|
52
63
|
const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
|
|
53
64
|
value !== null &&
|
|
54
65
|
"__embeddableType" in value
|
|
@@ -732,7 +743,7 @@ const validateComponentEvents = (metaInfo) => {
|
|
|
732
743
|
return errors;
|
|
733
744
|
};
|
|
734
745
|
const validateModuleName = (metaInfo) => {
|
|
735
|
-
const basename = path.basename(metaInfo.moduleId);
|
|
746
|
+
const basename = path$1.basename(metaInfo.moduleId);
|
|
736
747
|
const fileName = basename.split(".")[0];
|
|
737
748
|
if (fileName !== metaInfo.meta.name) {
|
|
738
749
|
return [
|
|
@@ -848,7 +859,10 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
848
859
|
? getModuleType(moduleInfo)
|
|
849
860
|
: null;
|
|
850
861
|
if (moduleType) {
|
|
851
|
-
const meta = await loadComponentMeta(
|
|
862
|
+
const meta = await loadComponentMeta({
|
|
863
|
+
moduleId: moduleInfo.id,
|
|
864
|
+
ast: moduleInfo.ast,
|
|
865
|
+
});
|
|
852
866
|
metaConfigs.push({
|
|
853
867
|
moduleId: moduleInfo.id,
|
|
854
868
|
meta,
|
|
@@ -893,7 +907,7 @@ const styledComponentsEntrypointModifier = {
|
|
|
893
907
|
},
|
|
894
908
|
needToModify(ctx) {
|
|
895
909
|
var _a;
|
|
896
|
-
const packageJsonFilePath = path.resolve(ctx.client.rootDir, "package.json");
|
|
910
|
+
const packageJsonFilePath = path$1.resolve(ctx.client.rootDir, "package.json");
|
|
897
911
|
const packageJson = require(packageJsonFilePath);
|
|
898
912
|
return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
|
|
899
913
|
},
|
|
@@ -908,7 +922,7 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
|
|
|
908
922
|
const files = fs$1.readdirSync(directory);
|
|
909
923
|
const result = [];
|
|
910
924
|
files.forEach((file) => {
|
|
911
|
-
const filePath = path.join(directory, file);
|
|
925
|
+
const filePath = path$1.join(directory, file);
|
|
912
926
|
if (fs$1.statSync(filePath).isDirectory()) {
|
|
913
927
|
// Recursively check files in subdirectories
|
|
914
928
|
result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
|
|
@@ -926,7 +940,7 @@ function findTypeNames(directory) {
|
|
|
926
940
|
const files = fs$1.readdirSync(directory);
|
|
927
941
|
const typeNames = [];
|
|
928
942
|
files.forEach((file) => {
|
|
929
|
-
const filePath = path.join(directory, file);
|
|
943
|
+
const filePath = path$1.join(directory, file);
|
|
930
944
|
if (fs$1.statSync(filePath).isDirectory()) {
|
|
931
945
|
// Recursively check files in subdirectories
|
|
932
946
|
typeNames.push(...findTypeNames(filePath));
|
|
@@ -1063,11 +1077,11 @@ async function runViteBuild(ctx, watch = null) {
|
|
|
1063
1077
|
watch,
|
|
1064
1078
|
minify: !watch,
|
|
1065
1079
|
lib: {
|
|
1066
|
-
entry: path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
|
|
1080
|
+
entry: path$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
|
|
1067
1081
|
formats: ["es"],
|
|
1068
1082
|
fileName: ctx["sdk-react"].outputOptions.fileName,
|
|
1069
1083
|
},
|
|
1070
|
-
outDir: path.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
|
|
1084
|
+
outDir: path$1.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
|
|
1071
1085
|
},
|
|
1072
1086
|
define: { "process.env.NODE_ENV": '"production"' },
|
|
1073
1087
|
});
|
|
@@ -1088,7 +1102,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
|
|
|
1088
1102
|
const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
|
|
1089
1103
|
const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
|
|
1090
1104
|
function getRelativeFileNameForImport(ctx, fileName) {
|
|
1091
|
-
return `./${path
|
|
1105
|
+
return `./${path$1
|
|
1092
1106
|
.relative(ctx.client.rootDir, fileName)
|
|
1093
1107
|
// it is a bit of a hack. On windows the path will look like '.src\something\something'
|
|
1094
1108
|
// but for imports it must be '.src/something/something'
|
|
@@ -1114,8 +1128,8 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
1114
1128
|
additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
|
|
1115
1129
|
}
|
|
1116
1130
|
}
|
|
1117
|
-
const content = await fs$2.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
1118
|
-
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
|
|
1119
1133
|
.replace(IMPORT_REPLACE_TOKEN, imports)
|
|
1120
1134
|
.replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
|
|
1121
1135
|
.replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
|
|
@@ -1125,11 +1139,20 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
1125
1139
|
}
|
|
1126
1140
|
|
|
1127
1141
|
var build = async (ctx) => {
|
|
1128
|
-
createContext(path
|
|
1142
|
+
createContext(path.resolve(__dirname, ".."), ctx);
|
|
1129
1143
|
return await generate(ctx);
|
|
1130
1144
|
};
|
|
1131
1145
|
|
|
1132
|
-
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
|
+
};
|
|
1133
1156
|
|
|
1134
1157
|
var index = () => {
|
|
1135
1158
|
return {
|