@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.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"] = {
@@ -27,21 +24,9 @@ var createContext = (pluginRoot, coreCtx) => {
27
24
  };
28
25
  };
29
26
 
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
- }
27
+ const loadComponentMeta = async (moduleId) => {
28
+ const module = await import(moduleId);
29
+ return module.meta;
45
30
  };
46
31
 
47
32
  /**
@@ -56,10 +41,7 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
56
41
  var _a;
57
42
  if (componentFileRegex.test(moduleInfo.id) &&
58
43
  ((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
59
- const meta = await loadComponentMeta({
60
- moduleId: moduleInfo.id,
61
- ast: moduleInfo.ast,
62
- });
44
+ const meta = await loadComponentMeta(moduleInfo.id);
63
45
  const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
64
46
  value !== null &&
65
47
  "__embeddableType" in value
@@ -743,7 +725,7 @@ const validateComponentEvents = (metaInfo) => {
743
725
  return errors;
744
726
  };
745
727
  const validateModuleName = (metaInfo) => {
746
- const basename = path$1.basename(metaInfo.moduleId);
728
+ const basename = path.basename(metaInfo.moduleId);
747
729
  const fileName = basename.split(".")[0];
748
730
  if (fileName !== metaInfo.meta.name) {
749
731
  return [
@@ -859,10 +841,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
859
841
  ? getModuleType(moduleInfo)
860
842
  : null;
861
843
  if (moduleType) {
862
- const meta = await loadComponentMeta({
863
- moduleId: moduleInfo.id,
864
- ast: moduleInfo.ast,
865
- });
844
+ const meta = await loadComponentMeta(moduleInfo.id);
866
845
  metaConfigs.push({
867
846
  moduleId: moduleInfo.id,
868
847
  meta,
@@ -907,7 +886,7 @@ const styledComponentsEntrypointModifier = {
907
886
  },
908
887
  needToModify(ctx) {
909
888
  var _a;
910
- const packageJsonFilePath = path$1.resolve(ctx.client.rootDir, "package.json");
889
+ const packageJsonFilePath = path.resolve(ctx.client.rootDir, "package.json");
911
890
  const packageJson = require(packageJsonFilePath);
912
891
  return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
913
892
  },
@@ -922,7 +901,7 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
922
901
  const files = fs$1.readdirSync(directory);
923
902
  const result = [];
924
903
  files.forEach((file) => {
925
- const filePath = path$1.join(directory, file);
904
+ const filePath = path.join(directory, file);
926
905
  if (fs$1.statSync(filePath).isDirectory()) {
927
906
  // Recursively check files in subdirectories
928
907
  result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
@@ -940,7 +919,7 @@ function findTypeNames(directory) {
940
919
  const files = fs$1.readdirSync(directory);
941
920
  const typeNames = [];
942
921
  files.forEach((file) => {
943
- const filePath = path$1.join(directory, file);
922
+ const filePath = path.join(directory, file);
944
923
  if (fs$1.statSync(filePath).isDirectory()) {
945
924
  // Recursively check files in subdirectories
946
925
  typeNames.push(...findTypeNames(filePath));
@@ -1077,13 +1056,15 @@ async function runViteBuild(ctx, watch = null) {
1077
1056
  watch,
1078
1057
  minify: !watch,
1079
1058
  lib: {
1080
- entry: path$1.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
1059
+ entry: path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename),
1081
1060
  formats: ["es"],
1082
1061
  fileName: ctx["sdk-react"].outputOptions.fileName,
1083
1062
  },
1084
- outDir: path$1.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
1063
+ outDir: path.resolve(ctx.client.buildDir, ctx["sdk-react"].outputOptions.buildName),
1064
+ },
1065
+ define: {
1066
+ "process.env.NODE_ENV": `${watch ? "development" : "production"}`,
1085
1067
  },
1086
- define: { "process.env.NODE_ENV": '"production"' },
1087
1068
  });
1088
1069
  }
1089
1070
  async function runViteWatch(ctx) {
@@ -1102,7 +1083,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
1102
1083
  const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
1103
1084
  const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
1104
1085
  function getRelativeFileNameForImport(ctx, fileName) {
1105
- return `./${path$1
1086
+ return `./${path
1106
1087
  .relative(ctx.client.rootDir, fileName)
1107
1088
  // it is a bit of a hack. On windows the path will look like '.src\something\something'
1108
1089
  // but for imports it must be '.src/something/something'
@@ -1128,8 +1109,8 @@ async function prepareEntrypoint(ctx, filesList) {
1128
1109
  additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
1129
1110
  }
1130
1111
  }
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
1112
+ const content = await fs$2.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
1113
+ await fs$2.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
1133
1114
  .replace(IMPORT_REPLACE_TOKEN, imports)
1134
1115
  .replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
1135
1116
  .replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
@@ -1139,19 +1120,12 @@ async function prepareEntrypoint(ctx, filesList) {
1139
1120
  }
1140
1121
 
1141
1122
  var build = async (ctx) => {
1142
- createContext(path.resolve(__dirname, ".."), ctx);
1123
+ createContext(path$1.resolve(__dirname, ".."), ctx);
1143
1124
  return await generate(ctx);
1144
1125
  };
1145
1126
 
1146
1127
  var cleanup = async (ctx) => {
1147
1128
  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
1129
  };
1156
1130
 
1157
1131
  var index = () => {