@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.esm.js CHANGED
@@ -1,19 +1,16 @@
1
- import * as path from 'node:path';
1
+ import * as path$1 from 'node:path';
2
2
  import { resolve, join } from 'node:path';
3
3
  import * as fs$2 from 'fs/promises';
4
- import * as path$1 from 'path';
4
+ import * as path 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';
8
8
  import { readdir, lstat, rm } from 'node:fs/promises';
9
- import * as url from 'node:url';
10
- import { generate as generate$1 } from 'astring';
11
9
  import 'node:child_process';
12
10
  import { z } from 'zod';
13
11
  import { parse } from '@babel/parser';
14
12
  import traverse from '@babel/traverse';
15
13
  import * as fs$1 from 'fs';
16
- import { glob } from 'glob';
17
14
 
18
15
  var createContext = (pluginRoot, coreCtx) => {
19
16
  coreCtx["sdk-react"] = {
@@ -28,20 +25,8 @@ var createContext = (pluginRoot, coreCtx) => {
28
25
  };
29
26
 
30
27
  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
- }
28
+ const module = await import(moduleId);
29
+ return module.meta;
45
30
  };
46
31
 
47
32
  /**
@@ -743,7 +728,7 @@ const validateComponentEvents = (metaInfo) => {
743
728
  return errors;
744
729
  };
745
730
  const validateModuleName = (metaInfo) => {
746
- const basename = path$1.basename(metaInfo.moduleId);
731
+ const basename = path.basename(metaInfo.moduleId);
747
732
  const fileName = basename.split(".")[0];
748
733
  if (fileName !== metaInfo.meta.name) {
749
734
  return [
@@ -907,7 +892,7 @@ const styledComponentsEntrypointModifier = {
907
892
  },
908
893
  needToModify(ctx) {
909
894
  var _a;
910
- const packageJsonFilePath = path$1.resolve(ctx.client.rootDir, "package.json");
895
+ const packageJsonFilePath = path.resolve(ctx.client.rootDir, "package.json");
911
896
  const packageJson = require(packageJsonFilePath);
912
897
  return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
913
898
  },
@@ -922,7 +907,7 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
922
907
  const files = fs$1.readdirSync(directory);
923
908
  const result = [];
924
909
  files.forEach((file) => {
925
- const filePath = path$1.join(directory, file);
910
+ const filePath = path.join(directory, file);
926
911
  if (fs$1.statSync(filePath).isDirectory()) {
927
912
  // Recursively check files in subdirectories
928
913
  result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
@@ -940,7 +925,7 @@ function findTypeNames(directory) {
940
925
  const files = fs$1.readdirSync(directory);
941
926
  const typeNames = [];
942
927
  files.forEach((file) => {
943
- const filePath = path$1.join(directory, file);
928
+ const filePath = path.join(directory, file);
944
929
  if (fs$1.statSync(filePath).isDirectory()) {
945
930
  // Recursively check files in subdirectories
946
931
  typeNames.push(...findTypeNames(filePath));
@@ -1077,11 +1062,11 @@ async function runViteBuild(ctx, watch = null) {
1077
1062
  watch,
1078
1063
  minify: !watch,
1079
1064
  lib: {
1080
- entry: path$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
1065
+ entry: path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
1081
1066
  formats: ["es"],
1082
1067
  fileName: ctx["sdk-react"].outputOptions.fileName,
1083
1068
  },
1084
- outDir: path$1.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
1069
+ outDir: path.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
1085
1070
  },
1086
1071
  define: { "process.env.NODE_ENV": '"production"' },
1087
1072
  });
@@ -1102,7 +1087,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
1102
1087
  const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
1103
1088
  const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
1104
1089
  function getRelativeFileNameForImport(ctx, fileName) {
1105
- return `./${path$1
1090
+ return `./${path
1106
1091
  .relative(ctx.client.rootDir, fileName)
1107
1092
  // it is a bit of a hack. On windows the path will look like '.src\something\something'
1108
1093
  // but for imports it must be '.src/something/something'
@@ -1128,8 +1113,8 @@ async function prepareEntrypoint(ctx, filesList) {
1128
1113
  additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
1129
1114
  }
1130
1115
  }
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
1116
+ const content = await fs$2.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
1117
+ await fs$2.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
1133
1118
  .replace(IMPORT_REPLACE_TOKEN, imports)
1134
1119
  .replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
1135
1120
  .replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
@@ -1139,19 +1124,12 @@ async function prepareEntrypoint(ctx, filesList) {
1139
1124
  }
1140
1125
 
1141
1126
  var build = async (ctx) => {
1142
- createContext(path.resolve(__dirname, ".."), ctx);
1127
+ createContext(path$1.resolve(__dirname, ".."), ctx);
1143
1128
  return await generate(ctx);
1144
1129
  };
1145
1130
 
1146
1131
  var cleanup = async (ctx) => {
1147
1132
  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
1135
  var index = () => {