@superblocksteam/sdk 2.0.138 → 2.0.139-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.
@@ -0,0 +1,50 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ import type { Alias } from "vite";
4
+
5
+ import { getLogger } from "./telemetry/logging.js";
6
+
7
+ // Module-scoped require for resolving sibling dependencies by absolute path.
8
+ // `createRequire` works under both the Node runtime and the Vitest module
9
+ // runner, unlike top-level `import.meta.resolve`.
10
+ const sdkRequire = createRequire(import.meta.url);
11
+ const logger = getLogger();
12
+
13
+ /**
14
+ * Vite alias mapping the React 19-only `react/compiler-runtime` specifier to
15
+ * the React-team `react-compiler-runtime` shim, which is API-compatible on
16
+ * React 17/18. Shared by the live-edit dev server and the production build so
17
+ * that user code (or a dependency) emitting `react/compiler-runtime` imports
18
+ * resolves against our React 18.3.1 runtime instead of crashing Vite
19
+ * resolution with `Missing "./compiler-runtime" specifier in "react" package`
20
+ * (APPS-2887).
21
+ *
22
+ * The exact-match string `find` fires only for `react/compiler-runtime`, never
23
+ * `react`, `react/jsx-runtime`, or `react-dom`.
24
+ *
25
+ * Returns `null` (and logs) if the shim package cannot be resolved — e.g. a
26
+ * corrupted or partial SDK install. Skipping the alias keeps the dev server /
27
+ * build starting for every other app instead of throwing synchronously inside
28
+ * `createServer()`/`build()` and permanently rejecting `vitePromise`, which
29
+ * would reproduce the very infinite-spinner symptom this fix removes. Only an
30
+ * app that actually imports `react/compiler-runtime` would then hit the
31
+ * original (now clearly-logged) resolution error.
32
+ */
33
+ export function reactCompilerRuntimeAlias(
34
+ // Resolver seam: defaults to the real module resolution; overridable in tests.
35
+ resolve: (id: string) => string = (id) => sdkRequire.resolve(id),
36
+ ): Alias | null {
37
+ let replacement: string;
38
+ try {
39
+ replacement = resolve("react-compiler-runtime");
40
+ } catch {
41
+ logger.warn(
42
+ "[APPS-2887] Could not resolve the 'react-compiler-runtime' shim; " +
43
+ "skipping the react/compiler-runtime alias. Reinstall the SDK " +
44
+ "dependencies if an app needs it (apps that do not import " +
45
+ "react/compiler-runtime are unaffected).",
46
+ );
47
+ return null;
48
+ }
49
+ return { find: "react/compiler-runtime", replacement };
50
+ }
@@ -0,0 +1,26 @@
1
+ import { existsSync } from "node:fs";
2
+ import { isAbsolute } from "node:path";
3
+
4
+ import { describe, expect, it } from "vitest";
5
+
6
+ import { reactCompilerRuntimeAlias } from "./react-compiler-runtime-shim.mjs";
7
+
8
+ describe("reactCompilerRuntimeAlias", () => {
9
+ it("maps react/compiler-runtime to an existing absolute shim path", () => {
10
+ const alias = reactCompilerRuntimeAlias();
11
+ expect(alias).not.toBeNull();
12
+ expect(alias!.find).toBe("react/compiler-runtime");
13
+ expect(typeof alias!.replacement).toBe("string");
14
+ expect(isAbsolute(alias!.replacement as string)).toBe(true);
15
+ expect(existsSync(alias!.replacement as string)).toBe(true);
16
+ });
17
+
18
+ it("returns null instead of throwing when the shim cannot be resolved", () => {
19
+ // Simulate a corrupted/partial install where the shim package is absent.
20
+ // The dev server must keep starting (no permanently-rejected vitePromise).
21
+ const alias = reactCompilerRuntimeAlias(() => {
22
+ throw new Error("Cannot find module 'react-compiler-runtime'");
23
+ });
24
+ expect(alias).toBeNull();
25
+ });
26
+ });