@embeddable.com/sdk-react 3.0.3 → 3.1.0-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) => {
@@ -53,20 +49,8 @@ var createContext = (pluginRoot, coreCtx) => {
53
49
  };
54
50
 
55
51
  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
- }
52
+ const module = await import(moduleId);
53
+ return module.meta;
70
54
  };
71
55
 
72
56
  /**
@@ -768,7 +752,7 @@ const validateComponentEvents = (metaInfo) => {
768
752
  return errors;
769
753
  };
770
754
  const validateModuleName = (metaInfo) => {
771
- const basename = path__namespace$1.basename(metaInfo.moduleId);
755
+ const basename = path__namespace.basename(metaInfo.moduleId);
772
756
  const fileName = basename.split(".")[0];
773
757
  if (fileName !== metaInfo.meta.name) {
774
758
  return [
@@ -932,7 +916,7 @@ const styledComponentsEntrypointModifier = {
932
916
  },
933
917
  needToModify(ctx) {
934
918
  var _a;
935
- const packageJsonFilePath = path__namespace$1.resolve(ctx.client.rootDir, "package.json");
919
+ const packageJsonFilePath = path__namespace.resolve(ctx.client.rootDir, "package.json");
936
920
  const packageJson = require(packageJsonFilePath);
937
921
  return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
938
922
  },
@@ -947,7 +931,7 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
947
931
  const files = fs__namespace$1.readdirSync(directory);
948
932
  const result = [];
949
933
  files.forEach((file) => {
950
- const filePath = path__namespace$1.join(directory, file);
934
+ const filePath = path__namespace.join(directory, file);
951
935
  if (fs__namespace$1.statSync(filePath).isDirectory()) {
952
936
  // Recursively check files in subdirectories
953
937
  result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
@@ -965,7 +949,7 @@ function findTypeNames(directory) {
965
949
  const files = fs__namespace$1.readdirSync(directory);
966
950
  const typeNames = [];
967
951
  files.forEach((file) => {
968
- const filePath = path__namespace$1.join(directory, file);
952
+ const filePath = path__namespace.join(directory, file);
969
953
  if (fs__namespace$1.statSync(filePath).isDirectory()) {
970
954
  // Recursively check files in subdirectories
971
955
  typeNames.push(...findTypeNames(filePath));
@@ -1102,11 +1086,11 @@ async function runViteBuild(ctx, watch = null) {
1102
1086
  watch,
1103
1087
  minify: !watch,
1104
1088
  lib: {
1105
- entry: path__namespace$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
1089
+ entry: path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
1106
1090
  formats: ["es"],
1107
1091
  fileName: ctx["sdk-react"].outputOptions.fileName,
1108
1092
  },
1109
- outDir: path__namespace$1.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
1093
+ outDir: path__namespace.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
1110
1094
  },
1111
1095
  define: { "process.env.NODE_ENV": '"production"' },
1112
1096
  });
@@ -1127,7 +1111,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
1127
1111
  const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
1128
1112
  const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
1129
1113
  function getRelativeFileNameForImport(ctx, fileName) {
1130
- return `./${path__namespace$1
1114
+ return `./${path__namespace
1131
1115
  .relative(ctx.client.rootDir, fileName)
1132
1116
  // it is a bit of a hack. On windows the path will look like '.src\something\something'
1133
1117
  // but for imports it must be '.src/something/something'
@@ -1153,8 +1137,8 @@ async function prepareEntrypoint(ctx, filesList) {
1153
1137
  additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
1154
1138
  }
1155
1139
  }
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
1140
+ const content = await fs__namespace$2.readFile(path__namespace.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
1141
+ await fs__namespace$2.writeFile(path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
1158
1142
  .replace(IMPORT_REPLACE_TOKEN, imports)
1159
1143
  .replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
1160
1144
  .replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
@@ -1164,19 +1148,12 @@ async function prepareEntrypoint(ctx, filesList) {
1164
1148
  }
1165
1149
 
1166
1150
  var build = async (ctx) => {
1167
- createContext(path__namespace.resolve(__dirname, ".."), ctx);
1151
+ createContext(path__namespace$1.resolve(__dirname, ".."), ctx);
1168
1152
  return await generate(ctx);
1169
1153
  };
1170
1154
 
1171
1155
  var cleanup = async (ctx) => {
1172
1156
  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
1157
  };
1181
1158
 
1182
1159
  var index = () => {