@embeddable.com/sdk-react 3.1.0-next.1 → 3.1.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,11 +1056,11 @@ 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),
1085
1064
  },
1086
1065
  define: { "process.env.NODE_ENV": '"production"' },
1087
1066
  });
@@ -1102,7 +1081,7 @@ const ADDITIONAL_CONTENT_IMPORT_TOKEN = "{{ADDITIONAL_CONTENT_IMPORT}}";
1102
1081
  const ADDITIONAL_CONTENT_BEGIN_TOKEN = "{{ADDITIONAL_CONTENT_BEGIN}}";
1103
1082
  const ADDITIONAL_CONTENT_END_TOKEN = "{{ADDITIONAL_CONTENT_END}}";
1104
1083
  function getRelativeFileNameForImport(ctx, fileName) {
1105
- return `./${path$1
1084
+ return `./${path
1106
1085
  .relative(ctx.client.rootDir, fileName)
1107
1086
  // it is a bit of a hack. On windows the path will look like '.src\something\something'
1108
1087
  // but for imports it must be '.src/something/something'
@@ -1128,8 +1107,8 @@ async function prepareEntrypoint(ctx, filesList) {
1128
1107
  additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
1129
1108
  }
1130
1109
  }
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
1110
+ const content = await fs$2.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
1111
+ await fs$2.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
1133
1112
  .replace(IMPORT_REPLACE_TOKEN, imports)
1134
1113
  .replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
1135
1114
  .replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
@@ -1139,19 +1118,12 @@ async function prepareEntrypoint(ctx, filesList) {
1139
1118
  }
1140
1119
 
1141
1120
  var build = async (ctx) => {
1142
- createContext(path.resolve(__dirname, ".."), ctx);
1121
+ createContext(path$1.resolve(__dirname, ".."), ctx);
1143
1122
  return await generate(ctx);
1144
1123
  };
1145
1124
 
1146
1125
  var cleanup = async (ctx) => {
1147
1126
  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
1127
  };
1156
1128
 
1157
1129
  var index = () => {