@superblocksteam/sdk 2.0.41-next.9 → 2.0.41

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.
@@ -0,0 +1,96 @@
1
+ // Pre-compile regex for better performance
2
+ const LUCIDE_IMPORT_PATTERN = /([ \t]*)import\s+\{\s*([^}]+)\s*\}\s+from\s+['"]lucide-react['"]/g;
3
+ /**
4
+ * A Vite plugin that optimizes lucide-react imports by converting
5
+ * destructured imports to direct imports for better tree-shaking
6
+ */
7
+ function createLucideReactImportOptimizer() {
8
+ return {
9
+ name: "lucide-react-import-optimizer",
10
+ transform(sourceCode, filePath) {
11
+ if (!isValidInput(sourceCode, filePath))
12
+ return null;
13
+ try {
14
+ // Quick check if the file contains lucide-astro imports
15
+ if (!sourceCode.includes("lucide-react"))
16
+ return null;
17
+ const { transformedCode, hasChanges } = transformLucideImports(sourceCode);
18
+ if (hasChanges) {
19
+ return {
20
+ code: transformedCode,
21
+ map: null, // No source maps in this implementation
22
+ };
23
+ }
24
+ return null;
25
+ }
26
+ catch (error) {
27
+ handleTransformError(error);
28
+ return null;
29
+ }
30
+ },
31
+ };
32
+ }
33
+ /**
34
+ * Validates the input parameters for processing
35
+ */
36
+ function isValidInput(code, id) {
37
+ return Boolean(code && id);
38
+ }
39
+ /**
40
+ * Transforms lucide-react imports from destructured to individual imports
41
+ */
42
+ function transformLucideImports(sourceCode) {
43
+ let hasChanges = false;
44
+ const transformedCode = sourceCode.replace(LUCIDE_IMPORT_PATTERN, (match, indentation, importNames) => {
45
+ if (!importNames.trim())
46
+ return match;
47
+ const semicolonAtEnd = match.endsWith(";");
48
+ const individualImports = convertToIndividualImports(importNames, indentation, semicolonAtEnd);
49
+ if (individualImports) {
50
+ hasChanges = true;
51
+ return individualImports;
52
+ }
53
+ return match;
54
+ });
55
+ return { transformedCode, hasChanges };
56
+ }
57
+ /**
58
+ * Converts a comma-separated list of imports to individual import statements
59
+ */
60
+ function convertToIndividualImports(importNames, indentation, withSemicolon) {
61
+ return importNames
62
+ .split(",")
63
+ .map((name) => name.trim())
64
+ .filter(Boolean)
65
+ .map((name) => {
66
+ const kebabCasePath = convertToKebabCase(name);
67
+ const semicolon = withSemicolon ? ";" : "";
68
+ return `${indentation}import ${name} from "lucide-react/dist/esm/icons/${kebabCasePath}"${semicolon}`;
69
+ })
70
+ .join("\n");
71
+ }
72
+ /**
73
+ * Converts a camelCase or PascalCase string to kebab-case
74
+ * Should handle cases like:
75
+ * - CheckIcon -> check
76
+ * - BluetoothConnectedIcon -> bluetooth-connected
77
+ * - XIcon -> x
78
+ * - Loader2Icon -> loader-2
79
+ * - Grid2X2CheckIcon -> grid-2-x-2-check
80
+ */
81
+ function convertToKebabCase(str) {
82
+ return str
83
+ .replace("Icon", "")
84
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
85
+ .replace(/([a-zA-Z])([0-9])/g, "$1-$2")
86
+ .toLowerCase();
87
+ }
88
+ /**
89
+ * Handles and logs transformation errors
90
+ */
91
+ function handleTransformError(error) {
92
+ const typedError = error instanceof Error ? error : new Error(String(error));
93
+ console.error("Error in lucide-react-import-optimizer plugin:", typedError);
94
+ }
95
+ export default createLucideReactImportOptimizer;
96
+ //# sourceMappingURL=vite-plugin-optimize-lucide-imports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin-optimize-lucide-imports.js","sourceRoot":"","sources":["../src/vite-plugin-optimize-lucide-imports.ts"],"names":[],"mappings":"AAEA,2CAA2C;AAC3C,MAAM,qBAAqB,GACzB,mEAAmE,CAAC;AAEtE;;;GAGG;AACH,SAAS,gCAAgC;IACvC,OAAO;QACL,IAAI,EAAE,+BAA+B;QACrC,SAAS,CACP,UAAkB,EAClB,QAAgB;YAEhB,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC;gBAAE,OAAO,IAAI,CAAC;YAErD,IAAI,CAAC;gBACH,wDAAwD;gBACxD,IAAI,CAAC,UAAU,CAAC,QAAQ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,EACnB,aAAsB;IAEtB,OAAO,WAAW;SACf,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,MAAM,aAAa,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,SAAS,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,OAAO,GAAG,WAAW,UAAU,IAAI,sCAAsC,aAAa,IAAI,SAAS,EAAE,CAAC;IACxG,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,OAAO,GAAG;SACP,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;SACnB,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,WAAW,EAAE,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,KAAc;IAC1C,MAAM,UAAU,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7E,OAAO,CAAC,KAAK,CAAC,gDAAgD,EAAE,UAAU,CAAC,CAAC;AAC9E,CAAC;AAED,eAAe,gCAAgC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/sdk",
3
- "version": "2.0.41-next.9",
3
+ "version": "2.0.41",
4
4
  "type": "module",
5
5
  "description": "Superblocks JS SDK",
6
6
  "homepage": "https://www.superblocks.com",
@@ -34,11 +34,11 @@
34
34
  "@opentelemetry/semantic-conventions": "^1.28.0",
35
35
  "@rollup/wasm-node": "^4.35.0",
36
36
  "@superblocksteam/bucketeer-sdk": "0.5.0",
37
- "@superblocksteam/library": "2.0.41-next.9",
38
- "@superblocksteam/library-shared": "2.0.41-next.9",
39
- "@superblocksteam/shared": "0.9460.0",
40
- "@superblocksteam/util": "2.0.41-next.9",
41
- "@superblocksteam/vite-plugin-file-sync": "2.0.41-next.9",
37
+ "@superblocksteam/library": "2.0.41",
38
+ "@superblocksteam/library-shared": "2.0.41",
39
+ "@superblocksteam/shared": "0.9484.0",
40
+ "@superblocksteam/util": "2.0.41",
41
+ "@superblocksteam/vite-plugin-file-sync": "2.0.41",
42
42
  "@vitejs/plugin-react": "4.3.4",
43
43
  "axios": "^1.4.0",
44
44
  "chokidar": "^4.0.3",
@@ -10,6 +10,7 @@ import { ddRumPlugin } from "./dev-utils/vite-plugin-dd-rum.mjs";
10
10
  import { getLogger } from "./telemetry/logging.js";
11
11
  import { generateBuildManifestPlugin } from "./vite-plugin-generate-build-manifest.mjs";
12
12
  import { injectSuperblocksIdsPlugin } from "./vite-plugin-inject-sb-ids-transform.mjs";
13
+ import createLucideReactImportOptimizer from "./vite-plugin-optimize-lucide-imports.js";
13
14
 
14
15
  export async function buildApplication({
15
16
  root,
@@ -112,8 +113,8 @@ async function buildWithVite({
112
113
  customComponentsPlugin(),
113
114
  injectSuperblocksIdsPlugin(root),
114
115
  react(),
116
+ createLucideReactImportOptimizer(),
115
117
  generateBuildManifestPlugin(root),
116
-
117
118
  ddRumPlugin({
118
119
  clientToken: ddClientToken ?? "",
119
120
  applicationId: ddApplicationId ?? "",
package/src/client.ts CHANGED
@@ -28,6 +28,7 @@ import { AgentType } from "./types/index.js";
28
28
  import { getAgentUrl } from "./utils.js";
29
29
  import {
30
30
  DEFAULT_BRANCH,
31
+ findGitRepositoryRoot,
31
32
  getCurrentGitBranchIfGit,
32
33
  } from "./version-control.mjs";
33
34
  import type { StdISocketRPCClient } from "./socket/index.js";
@@ -327,9 +328,24 @@ export async function fetchApplication({
327
328
  return data;
328
329
  } catch (e) {
329
330
  if (axios.isAxiosError(e) && e.response?.status === 404) {
330
- throw new NotFoundError(
331
- `Application ${applicationId} was not found with branch ${branch}, are you sure you are on the correct application and branch?`,
332
- );
331
+ let errorMessage = `Application ${applicationId} was not found on branch '${branch}'. `;
332
+
333
+ // Try to get the actual current branch to provide more helpful context
334
+ try {
335
+ const [actualBranch, gitRoot] = await Promise.all([
336
+ getCurrentGitBranchIfGit(),
337
+ findGitRepositoryRoot(),
338
+ ]);
339
+ if (actualBranch && gitRoot) {
340
+ errorMessage += `You are currently on branch '${actualBranch}' in a git repository at '${gitRoot}'. `;
341
+ }
342
+ } catch {
343
+ // Ignore errors getting current branch
344
+ }
345
+
346
+ errorMessage +=
347
+ "Are you sure you are on the correct application and branch?";
348
+ throw new NotFoundError(errorMessage);
333
349
  }
334
350
  throw new Error(
335
351
  `Could not fetch application: ${
@@ -13,6 +13,7 @@ import pkg from "../../package.json" with { type: "json" };
13
13
  import { getTracer } from "../telemetry/index.js";
14
14
  import { getErrorMeta, getLogger } from "../telemetry/logging.js";
15
15
  import { getCurrentGitBranchIfGit } from "../version-control.mjs";
16
+ import createLucideReactImportOptimizer from "../vite-plugin-optimize-lucide-imports.js";
16
17
  import {
17
18
  customComponentsPlugin,
18
19
  isCustomComponentsEnabled,
@@ -211,11 +212,11 @@ export async function createDevServer({
211
212
  req.headers["x-superblocks-branch"] !== currentBranch
212
213
  ) {
213
214
  logger.error(
214
- `Branch header mismatch, expected ${currentBranch}, received ${req.headers["x-superblocks-branch"]}`,
215
+ `Dev server expects branch ${currentBranch}, but received ${req.headers["x-superblocks-branch"]}. Check your current branch with 'git branch' and try again.`,
215
216
  );
216
217
  res.status(401).send(
217
218
  JSON.stringify({
218
- error: `Branch header mismatch. Expected ${currentBranch}, received ${req.headers["x-superblocks-branch"]}`,
219
+ error: `Dev server expects branch ${currentBranch}, but received ${req.headers["x-superblocks-branch"]}. Check your current branch with 'git branch' and try again.`,
219
220
  }),
220
221
  );
221
222
  return;
@@ -481,7 +482,6 @@ async function startVite({
481
482
  fileSyncPluginCreator.plugin,
482
483
  // Add a virtual "stub" module for the build manifest
483
484
  buildManifestStubPlugin(),
484
-
485
485
  react({
486
486
  babel: {
487
487
  plugins: [
@@ -494,6 +494,7 @@ async function startVite({
494
494
  ],
495
495
  },
496
496
  }),
497
+ createLucideReactImportOptimizer(),
497
498
  ddRumPlugin({
498
499
  clientToken: env.SUPERBLOCKS_LIBRARY_DD_CLIENT_TOKEN ?? "",
499
500
  applicationId: env.SUPERBLOCKS_LIBRARY_DD_APPLICATION_ID ?? "",
@@ -1033,6 +1033,19 @@ export async function getLocalGitRepoState(
1033
1033
  };
1034
1034
  }
1035
1035
 
1036
+ /**
1037
+ * Returns the root directory of the git repository, or null if not in a git repo
1038
+ */
1039
+ export async function findGitRepositoryRoot(): Promise<string | null> {
1040
+ const git: SimpleGit = simpleGit();
1041
+ try {
1042
+ const rootDir = await git.revparse(["--show-toplevel"]);
1043
+ return rootDir.trim();
1044
+ } catch {
1045
+ return null;
1046
+ }
1047
+ }
1048
+
1036
1049
  /**
1037
1050
  * Returns the current git branch, or undefined if not in a git repo
1038
1051
  */
@@ -0,0 +1,128 @@
1
+ import type { TransformResult, Plugin } from "vite";
2
+
3
+ // Pre-compile regex for better performance
4
+ const LUCIDE_IMPORT_PATTERN =
5
+ /([ \t]*)import\s+\{\s*([^}]+)\s*\}\s+from\s+['"]lucide-react['"]/g;
6
+
7
+ /**
8
+ * A Vite plugin that optimizes lucide-react imports by converting
9
+ * destructured imports to direct imports for better tree-shaking
10
+ */
11
+ function createLucideReactImportOptimizer(): Plugin {
12
+ return {
13
+ name: "lucide-react-import-optimizer",
14
+ transform(
15
+ sourceCode: string,
16
+ filePath: string,
17
+ ): TransformResult | null | undefined {
18
+ if (!isValidInput(sourceCode, filePath)) return null;
19
+
20
+ try {
21
+ // Quick check if the file contains lucide-astro imports
22
+ if (!sourceCode.includes("lucide-react")) return null;
23
+
24
+ const { transformedCode, hasChanges } =
25
+ transformLucideImports(sourceCode);
26
+
27
+ if (hasChanges) {
28
+ return {
29
+ code: transformedCode,
30
+ map: null, // No source maps in this implementation
31
+ };
32
+ }
33
+
34
+ return null;
35
+ } catch (error) {
36
+ handleTransformError(error);
37
+ return null;
38
+ }
39
+ },
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Validates the input parameters for processing
45
+ */
46
+ function isValidInput(code: string, id: string): boolean {
47
+ return Boolean(code && id);
48
+ }
49
+
50
+ /**
51
+ * Transforms lucide-react imports from destructured to individual imports
52
+ */
53
+ function transformLucideImports(sourceCode: string): {
54
+ transformedCode: string;
55
+ hasChanges: boolean;
56
+ } {
57
+ let hasChanges = false;
58
+
59
+ const transformedCode = sourceCode.replace(
60
+ LUCIDE_IMPORT_PATTERN,
61
+ (match: string, indentation: string, importNames: string): string => {
62
+ if (!importNames.trim()) return match;
63
+
64
+ const semicolonAtEnd = match.endsWith(";");
65
+ const individualImports = convertToIndividualImports(
66
+ importNames,
67
+ indentation,
68
+ semicolonAtEnd,
69
+ );
70
+
71
+ if (individualImports) {
72
+ hasChanges = true;
73
+ return individualImports;
74
+ }
75
+
76
+ return match;
77
+ },
78
+ );
79
+
80
+ return { transformedCode, hasChanges };
81
+ }
82
+
83
+ /**
84
+ * Converts a comma-separated list of imports to individual import statements
85
+ */
86
+ function convertToIndividualImports(
87
+ importNames: string,
88
+ indentation: string,
89
+ withSemicolon: boolean,
90
+ ): string {
91
+ return importNames
92
+ .split(",")
93
+ .map((name) => name.trim())
94
+ .filter(Boolean)
95
+ .map((name) => {
96
+ const kebabCasePath = convertToKebabCase(name);
97
+ const semicolon = withSemicolon ? ";" : "";
98
+ return `${indentation}import ${name} from "lucide-react/dist/esm/icons/${kebabCasePath}"${semicolon}`;
99
+ })
100
+ .join("\n");
101
+ }
102
+
103
+ /**
104
+ * Converts a camelCase or PascalCase string to kebab-case
105
+ * Should handle cases like:
106
+ * - CheckIcon -> check
107
+ * - BluetoothConnectedIcon -> bluetooth-connected
108
+ * - XIcon -> x
109
+ * - Loader2Icon -> loader-2
110
+ * - Grid2X2CheckIcon -> grid-2-x-2-check
111
+ */
112
+ function convertToKebabCase(str: string): string {
113
+ return str
114
+ .replace("Icon", "")
115
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
116
+ .replace(/([a-zA-Z])([0-9])/g, "$1-$2")
117
+ .toLowerCase();
118
+ }
119
+
120
+ /**
121
+ * Handles and logs transformation errors
122
+ */
123
+ function handleTransformError(error: unknown): void {
124
+ const typedError = error instanceof Error ? error : new Error(String(error));
125
+ console.error("Error in lucide-react-import-optimizer plugin:", typedError);
126
+ }
127
+
128
+ export default createLucideReactImportOptimizer;