@embeddable.com/sdk-react 3.1.0-next.1 → 3.1.1-next.0

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.js CHANGED
@@ -6,14 +6,11 @@ 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');
10
- var astring = require('astring');
11
9
  require('node:child_process');
12
10
  var zod = require('zod');
13
11
  var parser = require('@babel/parser');
14
12
  var traverse = require('@babel/traverse');
15
13
  var fs$1 = require('fs');
16
- var glob = require('glob');
17
14
 
18
15
  function _interopNamespaceDefault(e) {
19
16
  var n = Object.create(null);
@@ -32,12 +29,11 @@ function _interopNamespaceDefault(e) {
32
29
  return Object.freeze(n);
33
30
  }
34
31
 
35
- var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
32
+ var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path);
36
33
  var fs__namespace$2 = /*#__PURE__*/_interopNamespaceDefault(fs$2);
37
- var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$1);
34
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
38
35
  var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
39
36
  var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
40
- var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
41
37
  var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
42
38
 
43
39
  var createContext = (pluginRoot, coreCtx) => {
@@ -52,21 +48,9 @@ var createContext = (pluginRoot, coreCtx) => {
52
48
  };
53
49
  };
54
50
 
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
- }
51
+ const loadComponentMeta = async (moduleId) => {
52
+ const module = await import(moduleId);
53
+ return module.meta;
70
54
  };
71
55
 
72
56
  /**
@@ -81,10 +65,7 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
81
65
  var _a;
82
66
  if (componentFileRegex.test(moduleInfo.id) &&
83
67
  ((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
84
- const meta = await loadComponentMeta({
85
- moduleId: moduleInfo.id,
86
- ast: moduleInfo.ast,
87
- });
68
+ const meta = await loadComponentMeta(moduleInfo.id);
88
69
  const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
89
70
  value !== null &&
90
71
  "__embeddableType" in value
@@ -768,7 +749,7 @@ const validateComponentEvents = (metaInfo) => {
768
749
  return errors;
769
750
  };
770
751
  const validateModuleName = (metaInfo) => {
771
- const basename = path__namespace$1.basename(metaInfo.moduleId);
752
+ const basename = path__namespace.basename(metaInfo.moduleId);
772
753
  const fileName = basename.split(".")[0];
773
754
  if (fileName !== metaInfo.meta.name) {
774
755
  return [
@@ -884,10 +865,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
884
865
  ? getModuleType(moduleInfo)
885
866
  : null;
886
867
  if (moduleType) {
887
- const meta = await loadComponentMeta({
888
- moduleId: moduleInfo.id,
889
- ast: moduleInfo.ast,
890
- });
868
+ const meta = await loadComponentMeta(moduleInfo.id);
891
869
  metaConfigs.push({
892
870
  moduleId: moduleInfo.id,
893
871
  meta,
@@ -932,7 +910,7 @@ const styledComponentsEntrypointModifier = {
932
910
  },
933
911
  needToModify(ctx) {
934
912
  var _a;
935
- const packageJsonFilePath = path__namespace$1.resolve(ctx.client.rootDir, "package.json");
913
+ const packageJsonFilePath = path__namespace.resolve(ctx.client.rootDir, "package.json");
936
914
  const packageJson = require(packageJsonFilePath);
937
915
  return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
938
916
  },
@@ -947,7 +925,7 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
947
925
  const files = fs__namespace$1.readdirSync(directory);
948
926
  const result = [];
949
927
  files.forEach((file) => {
950
- const filePath = path__namespace$1.join(directory, file);
928
+ const filePath = path__namespace.join(directory, file);
951
929
  if (fs__namespace$1.statSync(filePath).isDirectory()) {
952
930
  // Recursively check files in subdirectories
953
931
  result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
@@ -965,7 +943,7 @@ function findTypeNames(directory) {
965
943
  const files = fs__namespace$1.readdirSync(directory);
966
944
  const typeNames = [];
967
945
  files.forEach((file) => {
968
- const filePath = path__namespace$1.join(directory, file);
946
+ const filePath = path__namespace.join(directory, file);
969
947
  if (fs__namespace$1.statSync(filePath).isDirectory()) {
970
948
  // Recursively check files in subdirectories
971
949
  typeNames.push(...findTypeNames(filePath));
@@ -1102,13 +1080,15 @@ async function runViteBuild(ctx, watch = null) {
1102
1080
  watch,
1103
1081
  minify: !watch,
1104
1082
  lib: {
1105
- entry: path__namespace$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
1083
+ entry: path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
1106
1084
  formats: ["es"],
1107
1085
  fileName: ctx["sdk-react"].outputOptions.fileName,
1108
1086
  },
1109
- outDir: path__namespace$1.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
1087
+ outDir: path__namespace.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
1088
+ },
1089
+ define: {
1090
+ "process.env.NODE_ENV": `${watch ? "development" : "production"}`,
1110
1091
  },
1111
- define: { "process.env.NODE_ENV": '"production"' },
1112
1092
  });
1113
1093
  }
1114
1094
  async function runViteWatch(ctx) {
@@ -1127,7 +1107,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
1127
1107
  const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
1128
1108
  const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
1129
1109
  function getRelativeFileNameForImport(ctx, fileName) {
1130
- return `./${path__namespace$1
1110
+ return `./${path__namespace
1131
1111
  .relative(ctx.client.rootDir, fileName)
1132
1112
  // it is a bit of a hack. On windows the path will look like '.src\something\something'
1133
1113
  // but for imports it must be '.src/something/something'
@@ -1153,8 +1133,8 @@ async function prepareEntrypoint(ctx, filesList) {
1153
1133
  additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
1154
1134
  }
1155
1135
  }
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
1136
+ const content = await fs__namespace$2.readFile(path__namespace.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
1137
+ await fs__namespace$2.writeFile(path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
1158
1138
  .replace(IMPORT_REPLACE_TOKEN, imports)
1159
1139
  .replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
1160
1140
  .replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
@@ -1164,19 +1144,12 @@ async function prepareEntrypoint(ctx, filesList) {
1164
1144
  }
1165
1145
 
1166
1146
  var build = async (ctx) => {
1167
- createContext(path__namespace.resolve(__dirname, ".."), ctx);
1147
+ createContext(path__namespace$1.resolve(__dirname, ".."), ctx);
1168
1148
  return await generate(ctx);
1169
1149
  };
1170
1150
 
1171
1151
  var cleanup = async (ctx) => {
1172
1152
  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
1153
  };
1181
1154
 
1182
1155
  var index = () => {