@multiplatform.one/config 9.17.0 → 10.0.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.
Files changed (52) hide show
  1. package/design-lint.mjs +29 -6
  2. package/lib/index.js +4 -4
  3. package/lib/{storybook-BpaziEtP.js → storybook-BRZwQLAM.js} +150 -9
  4. package/lib/storybook.js +1 -1
  5. package/lib/{tamaguiWorkspacePaths-DR3dud79.js → tamaguiWorkspacePaths-BFMQNk1l.js} +8 -5
  6. package/lib/{vite-CgiDLR6V.js → vite-DaBjbGS0.js} +40 -52
  7. package/lib/vite.js +4 -4
  8. package/lib/{vitest-B2vcGrZM.js → vitest-NTT7k5jB.js} +97 -10
  9. package/lib/vitest.js +2 -2
  10. package/lib/{workspacePublicPackages-DN-1LPcH.js → workspacePublicPackages-z0fVhgGN.js} +121 -8
  11. package/lint.mjs +874 -52
  12. package/oxlint.mjs +26 -1
  13. package/package.json +6 -6
  14. package/press-lint.mjs +86 -5
  15. package/spec-registry.mjs +15 -0
  16. package/src/lint.spec.ts +696 -12
  17. package/src/movedDepAliases.spec.ts +73 -0
  18. package/src/movedDepAliases.ts +91 -0
  19. package/src/nativeBlockScoping.spec.ts +12 -14
  20. package/src/nativeOnlyDepStubs.spec.ts +178 -0
  21. package/src/nativeOnlyDepStubs.ts +215 -0
  22. package/src/noVoicelessText.rule.spec.ts +1 -1
  23. package/src/noVoicelessText.spec.ts +1 -1
  24. package/src/oxlint.spec.ts +5 -5
  25. package/src/phosphorNativeInk.spec.ts +17 -18
  26. package/src/phosphorTokenColor.spec.ts +35 -0
  27. package/src/phosphorTokenColor.ts +8 -5
  28. package/src/press-lint.spec.ts +64 -3
  29. package/src/react-native.config.cjs +9 -0
  30. package/src/shims/phosphorThemeInk.js +6 -1
  31. package/src/shims/svgTouchSound.web.js +23 -0
  32. package/src/singletonDepAliases.spec.ts +99 -14
  33. package/src/singletonDepAliases.ts +102 -7
  34. package/src/storybook.spec.ts +0 -3
  35. package/src/storybook.ts +17 -6
  36. package/src/vite.nativeEntries.spec.ts +21 -20
  37. package/src/vite.spec.ts +11 -20
  38. package/src/vite.ts +44 -68
  39. package/src/vitest.spec.ts +142 -4
  40. package/src/vitest.ts +106 -8
  41. package/types/movedDepAliases.d.ts +8 -0
  42. package/types/movedDepAliases.d.ts.map +1 -0
  43. package/types/nativeOnlyDepStubs.d.ts +41 -0
  44. package/types/nativeOnlyDepStubs.d.ts.map +1 -0
  45. package/types/phosphorTokenColor.d.ts.map +1 -1
  46. package/types/singletonDepAliases.d.ts +55 -3
  47. package/types/singletonDepAliases.d.ts.map +1 -1
  48. package/types/storybook.d.ts.map +1 -1
  49. package/types/vite.d.ts +10 -1
  50. package/types/vite.d.ts.map +1 -1
  51. package/types/vitest.d.ts +46 -1
  52. package/types/vitest.d.ts.map +1 -1
@@ -9,7 +9,7 @@ import fs from "node:fs";
9
9
  import Module from "node:module";
10
10
  import path from "node:path";
11
11
  import { fileURLToPath } from "node:url";
12
- import { beforeEach, describe, expect, it } from "vitest";
12
+ import { describe, expect, it } from "vitest";
13
13
  import { isBlackPaint, nativePaint } from "./shims/phosphorNativeProbe.js";
14
14
  import { contextOutline, resolveIconInk } from "./shims/phosphorThemeInk.js";
15
15
  import {
@@ -20,13 +20,17 @@ import {
20
20
  } from "./vite.js";
21
21
 
22
22
  type Resolver = { name?: string; resolveId?: (id: string, importer?: string) => unknown };
23
- const native = globalThis as unknown as { __vxrnAddNativePlugins?: Resolver[] };
23
+ function nativePlugins<T>(config: ReturnType<typeof createViteConfig>): T[] {
24
+ return (config.plugins as Array<{ api?: { vxrnNative?: () => T } } | undefined>)
25
+ .flat()
26
+ .flatMap((plugin) => (plugin?.api?.vxrnNative ? [plugin.api.vxrnNative()] : []));
27
+ }
24
28
 
25
29
  const dark = {
26
30
  color: { val: "#eeeeee" },
27
- color10: { val: "#7a7a7a" },
28
- color12: { val: "#ededed" },
29
- textMuted: { val: "#a0a0a0" },
31
+ "color-10": { val: "#7a7a7a" },
32
+ "color-12": { val: "#ededed" },
33
+ "text-muted": { val: "#a0a0a0" },
30
34
  };
31
35
 
32
36
  describe("resolveIconInk", () => {
@@ -35,9 +39,9 @@ describe("resolveIconInk", () => {
35
39
  [null, "#eeeeee"],
36
40
  ["", "#eeeeee"],
37
41
  ["currentColor", "#eeeeee"],
38
- ["$textMuted", "#a0a0a0"],
39
- ["textMuted", "#a0a0a0"],
40
- ["$color12", "#ededed"],
42
+ ["$text-muted", "#a0a0a0"],
43
+ ["text-muted", "#a0a0a0"],
44
+ ["$color-12", "#ededed"],
41
45
  ["$notInTheme", "#eeeeee"],
42
46
  ["#ff0000", "#ff0000"],
43
47
  ["rgb(1, 2, 3)", "rgb(1, 2, 3)"],
@@ -46,12 +50,12 @@ describe("resolveIconInk", () => {
46
50
  });
47
51
 
48
52
  it("falls back down the ink ramp when the theme carries no `color`", () => {
49
- expect(resolveIconInk({ color12: { val: "#ddd" } }, undefined)).toBe("#ddd");
50
- expect(resolveIconInk({ color11: { val: "#ccc" } }, "$missing")).toBe("#ccc");
53
+ expect(resolveIconInk({ "color-12": { val: "#ddd" } }, undefined)).toBe("#ddd");
54
+ expect(resolveIconInk({ "color-11": { val: "#ccc" } }, "$missing")).toBe("#ccc");
51
55
  });
52
56
 
53
57
  it("never hands back a token, so react-native-svg always gets a paint", () => {
54
- for (const color of [undefined, "$color10", "$missing", "currentColor"])
58
+ for (const color of [undefined, "$color-10", "$missing", "currentColor"])
55
59
  expect(resolveIconInk(dark, color).startsWith("$")).toBe(false);
56
60
  });
57
61
  });
@@ -75,7 +79,7 @@ describe("contextOutline (FZ-8996)", () => {
75
79
 
76
80
  describe("native paint probe", () => {
77
81
  it("paints what react-native-svg draws for a colour it cannot read: black", () => {
78
- for (const color of [undefined, "", "currentColor", "$color12"])
82
+ for (const color of [undefined, "", "currentColor", "$color-12"])
79
83
  expect(isBlackPaint(nativePaint(color))).toBe(true);
80
84
  expect(isBlackPaint(nativePaint("#eeeeee"))).toBe(false);
81
85
  });
@@ -125,13 +129,8 @@ describe("phosphorNativeIconBase", () => {
125
129
  });
126
130
 
127
131
  describe("createViteConfig({ one: true })", () => {
128
- beforeEach(() => {
129
- delete native.__vxrnAddNativePlugins;
130
- });
131
-
132
132
  it("registers the swap in the native graph", () => {
133
- createViteConfig({ one: true });
134
- const plugin = native.__vxrnAddNativePlugins?.find(
133
+ const plugin = nativePlugins<Resolver>(createViteConfig({ one: true })).find(
135
134
  (p) => p.name === "vxrn-phosphor-native-icons",
136
135
  );
137
136
  expect(plugin?.resolveId?.("@phosphor-icons/react")).toBe(entry);
@@ -63,6 +63,41 @@ describe("phosphorTokenColorPlugin", () => {
63
63
  expect(load("/repo/src/other.ts")).toBeNull();
64
64
  });
65
65
 
66
+ it("paints a bare Tamagui 3 theme key, a $ token and a literal through the theme", () => {
67
+ const wrapper = resolveId("../lib/IconBase.es.js", `${dist}/csr/Heart.es.js`) ?? "";
68
+ const body = (load(wrapper) ?? "")
69
+ .replace(/^import .*$/gm, "")
70
+ .replace("export default TokenColorIconBase;", "return TokenColorIconBase;");
71
+ type Element = { type: unknown; props: { color?: string } };
72
+ const paint = (theme: Record<string, { val: string }>, color?: string) => {
73
+ const make = new Function("createElement", "forwardRef", "useTheme", "IconBase", body);
74
+ const Wrapped = make(
75
+ (type: unknown, props: Element["props"]) => ({ type, props }),
76
+ (render: (props: unknown, ref: null) => Element) => (props: unknown) => render(props, null),
77
+ () => theme,
78
+ "IconBase",
79
+ ) as (props: Element["props"]) => Element;
80
+ let element = Wrapped({ color });
81
+ while (typeof element.type === "function")
82
+ element = (element.type as (props: Element["props"]) => Element)(element.props);
83
+ return element.props.color;
84
+ };
85
+ const dark = {
86
+ color: { val: "#eeeeee" },
87
+ "color-11": { val: "#bbbbbb" },
88
+ "text-muted": { val: "#a0a0a0" },
89
+ };
90
+ expect(paint(dark, "text-muted")).toBe("#a0a0a0");
91
+ expect(paint(dark, "$text-muted")).toBe("#a0a0a0");
92
+ expect(paint(dark, "color-11")).toBe("#bbbbbb");
93
+ expect(paint(dark, "$missing")).toBe("#eeeeee");
94
+ expect(paint(dark, "#ff0000")).toBe("#ff0000");
95
+ expect(paint(dark, "rebeccapurple")).toBe("rebeccapurple");
96
+ expect(paint(dark, "currentColor")).toBe("currentColor");
97
+ expect(paint(dark, undefined)).toBeUndefined();
98
+ expect(paint({ "color-12": { val: "#dddddd" } }, "$missing")).toBe("#dddddd");
99
+ });
100
+
66
101
  it("reaches the dev dep optimizer, which bundles phosphor without Vite plugins", () => {
67
102
  const configEnvironment = plugin.configEnvironment as unknown as () => {
68
103
  optimizeDeps: { rolldownOptions: { plugins: Array<Plugin> } };
@@ -26,6 +26,8 @@ import { useTheme } from "@tamagui/core";
26
26
  import IconBase from ${JSON.stringify(originalIconBase)};
27
27
 
28
28
  const isToken = (color) => typeof color === "string" && color.charAt(0) === "$";
29
+ const isNamed = (color) =>
30
+ typeof color === "string" && color.length > 0 && color !== "currentColor";
29
31
 
30
32
  const paintOf = (entry) => {
31
33
  const value = entry != null && typeof entry === "object" ? entry.val : entry;
@@ -34,16 +36,17 @@ const paintOf = (entry) => {
34
36
 
35
37
  const ThemeColorIconBase = forwardRef(function ThemeColorIconBase(props, ref) {
36
38
  const theme = useTheme() || {};
39
+ const name = isToken(props.color) ? props.color.slice(1) : props.color;
37
40
  const color =
38
- paintOf(theme[props.color.slice(1)]) ??
39
- paintOf(theme.color) ??
40
- paintOf(theme.color12) ??
41
- paintOf(theme.color11);
41
+ paintOf(theme[name]) ??
42
+ (isToken(props.color)
43
+ ? paintOf(theme.color) ?? paintOf(theme["color-12"]) ?? paintOf(theme["color-11"])
44
+ : props.color);
42
45
  return createElement(IconBase, { ...props, ref, color });
43
46
  });
44
47
 
45
48
  const TokenColorIconBase = forwardRef(function TokenColorIconBase(props, ref) {
46
- return createElement(isToken(props.color) ? ThemeColorIconBase : IconBase, { ...props, ref });
49
+ return createElement(isNamed(props.color) ? ThemeColorIconBase : IconBase, { ...props, ref });
47
50
  });
48
51
  TokenColorIconBase.displayName = "IconBase";
49
52
 
@@ -14,7 +14,7 @@ describe("findNestedPressClaimants (FZ-7792 NATIVE-PRESS-OWNER)", () => {
14
14
  it("flags a styled pressStyle pill inside its pressable target (Alert's action, before the fix)", () => {
15
15
  const source = `
16
16
  const Target = styled(View, { name: "T", pressStyle: { opacity: 0.9 } });
17
- const Pill = styled(View, { name: "P", pressStyle: { backgroundColor: "$color6" } });
17
+ const Pill = styled(View, { name: "P", pressStyle: { backgroundColor: "$color-6" } });
18
18
  export const A = ({ onPress }) => (
19
19
  <Target onPress={onPress}>
20
20
  <Pill><Text>Save</Text></Pill>
@@ -26,7 +26,7 @@ describe("findNestedPressClaimants (FZ-7792 NATIVE-PRESS-OWNER)", () => {
26
26
  it("passes the fix: the pill reads the owner's group press state", () => {
27
27
  const source = `
28
28
  const Target = styled(View, { name: "T", pressStyle: { opacity: 0.9 } });
29
- const Pill = styled(View, { name: "P", "$group-action-press": { backgroundColor: "$color6" } });
29
+ const Pill = styled(View, { name: "P", "$group-action-press": { backgroundColor: "$color-6" } });
30
30
  export const A = ({ onPress }) => (
31
31
  <Target group="action" onPress={onPress}>
32
32
  <Pill><Text>Save</Text></Pill>
@@ -48,6 +48,34 @@ describe("findNestedPressClaimants (FZ-7792 NATIVE-PRESS-OWNER)", () => {
48
48
  expect(find(source)).toEqual(["View<View", "View<View"]);
49
49
  });
50
50
 
51
+ it("flags a Tamagui 3 press, active or focus-visible clause, and a typed press object", () => {
52
+ const source = `
53
+ const Pill = styled(View, { backgroundColor: "color-2 press:color-6" });
54
+ export const A = () => (
55
+ <View onPress={go}>
56
+ <View opacity="1 press:0.5" />
57
+ <View bg={"background dark:active:color-4"} />
58
+ <View outlineColor="transparent focus-visible:accent-color" />
59
+ <View bg={{ default: "background", press: "color-5" }} />
60
+ <Pill />
61
+ </View>
62
+ );`;
63
+ expect(find(source)).toEqual(["View<View", "View<View", "View<View", "View<View", "Pill<View"]);
64
+ });
65
+
66
+ it("passes a Tamagui 3 group-press look, a hover clause and prose", () => {
67
+ const source = `
68
+ const Pill = styled(View, { variants: { active: { true: { bg: "color-4" } } } });
69
+ export const A = () => (
70
+ <View group="action" onPress={go}>
71
+ <View bg="color-2 group-press/action:color-6" />
72
+ <View opacity="1 hover:0.9" aria-label="press: to save" />
73
+ <Pill active />
74
+ </View>
75
+ );`;
76
+ expect(find(source)).toEqual([]);
77
+ });
78
+
51
79
  it("follows styled() of a claimant and a config object bound to a name", () => {
52
80
  const source = `
53
81
  const look = { variants: { on: { true: { pressStyle: { opacity: 0.5 } } } } };
@@ -57,6 +85,21 @@ describe("findNestedPressClaimants (FZ-7792 NATIVE-PRESS-OWNER)", () => {
57
85
  expect(find(source)).toEqual(["Ring<Pressable"]);
58
86
  });
59
87
 
88
+ it("follows createStyledHOC the way it followed .styleable", () => {
89
+ const render = "(props, ref) => <Inner {...props} ref={ref} />";
90
+ const claim = "styled(View, { pressStyle: { opacity: 0.5 } })";
91
+ for (const binding of [
92
+ `const Ring = ${claim}.styleable(${render});`,
93
+ `const Ring = createStyledHOC(${claim}, ${render});`,
94
+ `const Ring = createStyledHOC(${claim} as never, ${render});`,
95
+ ]) {
96
+ const source = `
97
+ ${binding}
98
+ export const A = () => <Pressable onPress={go}><Ring /></Pressable>;`;
99
+ expect(find(source), binding).toEqual(["Ring<Pressable"]);
100
+ }
101
+ });
102
+
60
103
  it("treats the child of an asChild element as the owner it slots a handler into", () => {
61
104
  const source = `
62
105
  const Ring = styled(View, { pressStyle: { opacity: 0.5 } });
@@ -119,6 +162,13 @@ describe("exportedPressClaimants", () => {
119
162
  expect(exportedPressClaimants(source, "Fixture.tsx").sort()).toEqual(["Pill", "Ring"]);
120
163
  });
121
164
 
165
+ it("lists a Tamagui 3 claimant written with a flat press clause", () => {
166
+ const source = `
167
+ export const Pill = styled(View, { bg: "color-2 press:color-6" });
168
+ export const Plain = styled(View, { bg: "color-2 hover:color-3" });`;
169
+ expect(exportedPressClaimants(source, "Fixture.tsx")).toEqual(["Pill"]);
170
+ });
171
+
122
172
  it("follows a named styled base under .styleable() and createStyledHOC (FZ-10909)", () => {
123
173
  const source = `
124
174
  const Frame = styled(View, { name: "F", pressStyle: { opacity: 0.5 } });
@@ -191,7 +241,7 @@ describe("findNativeFocusWithin (FZ-8991 NATIVE-FOCUS-WITHIN)", () => {
191
241
  new URL("../../components/src/layouts/ViewSwitcher.tsx", import.meta.url),
192
242
  );
193
243
  const source = readFileSync(viewSwitcher, "utf8");
194
- expect(source).toContain("focusWithinStyle");
244
+ expect(source).toContain('stateFragment("focus-within"');
195
245
  expect(findNativeFocusWithin(source, viewSwitcher)).toEqual([]);
196
246
  });
197
247
 
@@ -204,6 +254,17 @@ describe("findNativeFocusWithin (FZ-8991 NATIVE-FOCUS-WITHIN)", () => {
204
254
  expect(lines(source)).toEqual([2, 3, 4, 5]);
205
255
  });
206
256
 
257
+ it("flags a Tamagui 3 focus-within clause or key that renders on native", () => {
258
+ const source = `
259
+ const Frame = styled(View, { outlineColor: "transparent focus-within:accent-color" });
260
+ const a = <View borderColor="border-color focus-within:accent-color" />;
261
+ const b = <View borderColor={{ default: "border-color", "focus-within": "accent-color" }} />;
262
+ const c = <View borderColor="border-color web:focus-within:accent-color" />;
263
+ const d = <View {...(isWeb ? { borderColor: "focus-within:accent-color" } : undefined)} />;
264
+ const e = <View aria-label="focus-within: ring" />;`;
265
+ expect(lines(source)).toEqual([2, 3, 4, 5]);
266
+ });
267
+
207
268
  it("passes every web gate", () => {
208
269
  const source = `
209
270
  const a = <View {...(isWeb ? { focusWithinStyle: ring } : undefined)} />;
@@ -2,6 +2,14 @@
2
2
 
3
3
  const path = require("path");
4
4
 
5
+ const one = (() => {
6
+ try {
7
+ return require("one/react-native-config");
8
+ } catch {
9
+ return null;
10
+ }
11
+ })();
12
+
5
13
  module.exports = {
6
14
  // Pin react-native to its real, resolved location. This monorepo uses
7
15
  // pnpm `node-linker=hoisted`, so react-native lives in the repo-root
@@ -10,6 +18,7 @@ module.exports = {
10
18
  // which is empty here and breaks CocoaPods ("Couldn't find react-native
11
19
  // package.json"). Resolving it explicitly points the Podfile at the hoisted copy.
12
20
  reactNativePath: path.dirname(require.resolve("react-native/package.json")),
21
+ ...(one ? { dependencies: one.dependencies } : {}),
13
22
  commands: (() => {
14
23
  try {
15
24
  return [...require("vxrn/react-native-commands")];
@@ -29,7 +29,12 @@ export function resolveIconInk(theme, color) {
29
29
  if (fromTheme) return fromTheme;
30
30
  if (color.charAt(0) !== "$") return color;
31
31
  }
32
- return paintOf(scope.color) ?? paintOf(scope.color12) ?? paintOf(scope.color11) ?? "currentColor";
32
+ return (
33
+ paintOf(scope.color) ??
34
+ paintOf(scope["color-12"]) ??
35
+ paintOf(scope["color-11"]) ??
36
+ "currentColor"
37
+ );
33
38
  }
34
39
 
35
40
  const OUTLINE = ["stroke", "strokeWidth", "strokeLinejoin", "strokeLinecap"];
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Web replacement for react-native-svg's `fabric/NativeSvgSoundModule`.
3
+ *
4
+ * FZ-10849. The real module is one line — `TurboModuleRegistry.getEnforcing(
5
+ * "RNSVGSoundModule")` — and `react-native-svg` 15.16.0 added it for the
6
+ * Android touch sound. `SvgTouchableMixin` reaches it through a `require()`
7
+ * inside `if (Platform.OS === "android" && !touchSoundDisabled)`, so on web
8
+ * the branch is dead, but rolldown hoists the require into a static import
9
+ * and the web graph ends up importing `TurboModuleRegistry` from
10
+ * `react-native` — which aliases to `react-native-web`, where no such export
11
+ * exists. `storybook build` only warns (Rollup shims the export); the dev
12
+ * dep-optimizer treats it as fatal and no dev server starts at all.
13
+ *
14
+ * `playTouchSound` stays a no-op rather than throwing: a browser has no touch
15
+ * sound to play, and react-native-web's own Touchable ignores the same prop,
16
+ * so a platform mis-detection degrades to silence instead of a crash.
17
+ *
18
+ * Plain JS, like the other shims here: it is resolved by absolute path from
19
+ * build configs that never run the TypeScript pipeline over `src`.
20
+ */
21
+ export default {
22
+ playTouchSound() {},
23
+ };
@@ -3,7 +3,11 @@ import { createRequire } from "node:module";
3
3
  import path from "node:path";
4
4
  import { describe, expect, it } from "vitest";
5
5
  import { createStorybookViteConfig } from "./storybook";
6
- import { singletonDepAliases } from "./singletonDepAliases";
6
+ import {
7
+ resolveSingletons,
8
+ singletonDepAliases,
9
+ singletonResolvePlugin,
10
+ } from "./singletonDepAliases";
7
11
  import { createViteConfig } from "./vite";
8
12
 
9
13
  const workspaceRoot = path.resolve(__dirname, "../../..");
@@ -22,17 +26,80 @@ describe("singletonDepAliases", () => {
22
26
  expect(fs.existsSync(path.join(aliases["react-cookie"], "package.json"))).toBe(true);
23
27
  });
24
28
 
25
- it("pins the tamagui theme record to one package directory (MPO-217)", () => {
29
+ it("pins the tamagui theme record, by the plugin rather than an alias (MPO-217, FZ-10849)", () => {
26
30
  // @tamagui/web owns the theme context. Two realpaths for it means two
27
31
  // contexts: public/frappe's story files import "tamagui" from a package
28
32
  // with no copy of its own, so they reach the hoisted chain while every
29
33
  // other importer reaches the pnpm store chain, and their components read
30
34
  // a context no provider ever wrote to — tamagui's `Missing theme.`.
35
+ //
36
+ // Under Tamagui 3 both packages remap subpaths through their exports map,
37
+ // so the directory alias that pinned them in v2 rewrites
38
+ // `@tamagui/core/theme-update` to a path with no file behind it. The pin
39
+ // moved to singletonResolvePlugin and the alias record must stay clear of
40
+ // them, or the prefix match reaches the specifier first.
31
41
  const aliases = singletonDepAliases(workspaceRoot);
42
+ const pins = resolveSingletons(workspaceRoot);
32
43
  for (const pkg of ["@tamagui/core", "@tamagui/web"]) {
33
- expect(aliases[pkg], `${pkg} must be pinned`).toBeTruthy();
34
- expect(path.isAbsolute(aliases[pkg])).toBe(true);
35
- expect(fs.existsSync(path.join(aliases[pkg], "package.json"))).toBe(true);
44
+ const pin = pins.find((p) => p.name === pkg);
45
+ expect(pin, `${pkg} must be installed and classified`).toBeTruthy();
46
+ expect(pin?.exportsMapped, `${pkg} remaps a subpath`).toBe(true);
47
+ expect(path.isAbsolute(pin!.dir)).toBe(true);
48
+ expect(fs.existsSync(path.join(pin!.dir, "package.json"))).toBe(true);
49
+ expect(aliases[pkg], `${pkg} must not carry a directory alias`).toBeUndefined();
50
+ }
51
+ });
52
+
53
+ it("classifies a package by measuring its exports map, not by a list", () => {
54
+ // react-cookie and the tanstack packages expose their subpaths as real
55
+ // files, so a directory alias reaches them and they stay on the cheaper
56
+ // instrument. A tanstack upgrade that adds a remapped subpath moves itself
57
+ // to the plugin here instead of breaking a build.
58
+ const mapped = new Map(resolveSingletons(workspaceRoot).map((p) => [p.name, p.exportsMapped]));
59
+ for (const pkg of [
60
+ "react-cookie",
61
+ "@tanstack/db",
62
+ "@tanstack/react-db",
63
+ "@tanstack/react-store",
64
+ ]) {
65
+ expect(mapped.get(pkg), `${pkg} must be reachable by a directory alias`).toBe(false);
66
+ }
67
+ });
68
+
69
+ it("re-resolves a remapped subpath anchored at the pinned copy (FZ-10849)", async () => {
70
+ // The defect: `tamagui`'s index imports ./theme-update.mjs, which imports
71
+ // @tamagui/core/theme-update, which imports @tamagui/web/theme-update, so
72
+ // every import of tamagui walks that chain. A directory alias turned it
73
+ // into `<pkgDir>/theme-update` and apps/one's build died with
74
+ // [UNLOADABLE_DEPENDENCY]. Anchoring the re-resolution at the pinned
75
+ // package's own package.json runs the exports map and keeps the copy.
76
+ const plugin = singletonResolvePlugin(workspaceRoot);
77
+ const anchors: string[] = [];
78
+ const ctx = {
79
+ async resolve(source: string, importer?: string, options?: Record<string, unknown>) {
80
+ anchors.push(importer ?? "");
81
+ expect(options?.skipSelf).toBe(true);
82
+ return { id: createRequire(importer!).resolve(source) };
83
+ },
84
+ };
85
+ const core = resolveSingletons(workspaceRoot).find((p) => p.name === "@tamagui/core")!;
86
+ for (const spec of ["@tamagui/core/theme-update", "@tamagui/web/dom", "@tamagui/core"]) {
87
+ const id = await plugin.resolveId.call(ctx, spec, undefined, {});
88
+ expect(id, `${spec} must resolve to a file`).toBeTruthy();
89
+ expect(fs.existsSync(id!), `${spec} -> ${id}`).toBe(true);
90
+ }
91
+ expect(anchors[0]).toBe(path.join(core.dir, "package.json"));
92
+ });
93
+
94
+ it("leaves a specifier it does not pin to the rest of the pipeline", async () => {
95
+ const plugin = singletonResolvePlugin(workspaceRoot);
96
+ const ctx = {
97
+ async resolve() {
98
+ throw new Error("must not resolve an unpinned specifier");
99
+ },
100
+ };
101
+ for (const spec of ["react-cookie", "tamagui", "@tamagui/corelike", "lodash"]) {
102
+ expect(await plugin.resolveId.call(ctx, spec, undefined, {})).toBeNull();
36
103
  }
37
104
  });
38
105
 
@@ -102,13 +169,12 @@ describe("createStorybookViteConfig react-cookie singleton", () => {
102
169
  expect(path.isAbsolute(alias["react-cookie"])).toBe(true);
103
170
  });
104
171
 
105
- it("aliases the tamagui theme record so the build cannot split it (MPO-217)", () => {
172
+ it("pins the tamagui theme record through the plugin, not an alias (MPO-217, FZ-10849)", () => {
106
173
  const alias = (config.resolve?.alias ?? {}) as Record<string, string>;
107
- for (const pkg of ["@tamagui/core", "@tamagui/web"]) {
108
- expect(alias[pkg], `${pkg} must be aliased`).toBeTruthy();
109
- expect(path.isAbsolute(alias[pkg])).toBe(true);
174
+ for (const pkg of ["@tamagui/core", "@tamagui/web", "tamagui"]) {
175
+ expect(alias[pkg], `${pkg} must not be aliased`).toBeUndefined();
110
176
  }
111
- expect(alias.tamagui).toBeUndefined();
177
+ expect(pluginNames(config)).toContain("multiplatform-singleton-resolve");
112
178
  });
113
179
 
114
180
  it("pre-bundles react-cookie in dev so dev and build share one record", () => {
@@ -121,10 +187,15 @@ describe("createStorybookViteConfig react-cookie singleton", () => {
121
187
  });
122
188
 
123
189
  describe("createViteConfig context singletons (MPO-225)", () => {
124
- const alias = (createViteConfig({ projectRoot: workspaceRoot }).resolve?.alias ?? {}) as Record<
125
- string,
126
- string
127
- >;
190
+ const config = createViteConfig({ projectRoot: workspaceRoot });
191
+ const alias = (config.resolve?.alias ?? {}) as Record<string, string>;
192
+
193
+ it("carries the resolve plugin, which is the half an alias cannot do (FZ-10849)", () => {
194
+ // A generated project builds through createViteConfig and nothing else, so
195
+ // the plugin has to ride here as well as in storybook or apps/one's build
196
+ // dies on @tamagui/core/theme-update while every spec still passes.
197
+ expect(pluginNames(config)).toContain("multiplatform-singleton-resolve");
198
+ });
128
199
 
129
200
  it("applies every pin on the consumer path, not only in storybook", () => {
130
201
  // This is the defect the ticket names. The list existed and only
@@ -216,6 +287,20 @@ describe("CONTEXT_SINGLETONS membership, measured rather than recited (MPO-288)"
216
287
  });
217
288
  });
218
289
 
290
+ function pluginNames(config: { plugins?: unknown }): string[] {
291
+ const names: string[] = [];
292
+ const walk = (value: unknown) => {
293
+ if (Array.isArray(value)) {
294
+ for (const entry of value) walk(entry);
295
+ return;
296
+ }
297
+ const name = (value as { name?: unknown } | null)?.name;
298
+ if (typeof name === "string") names.push(name);
299
+ };
300
+ walk(config.plugins);
301
+ return names;
302
+ }
303
+
219
304
  function workspacePackageDirs(): string[] {
220
305
  const dirs = [path.join(workspaceRoot, "features")];
221
306
  for (const group of ["apps", "packages", "public"]) {
@@ -111,22 +111,117 @@ const CONTEXT_SINGLETONS: readonly string[] = [
111
111
  * Vite `resolve.alias` entries pinning each context singleton to one directory.
112
112
  *
113
113
  * Alias keys match the whole specifier or a `key + "/"` prefix, so subpath
114
- * imports follow the same copy instead of resolving independently. Entries are
115
- * omitted when the package is not installed, so a consumer that does not use
116
- * cookies is unaffected.
114
+ * imports follow the same copy instead of resolving independently. That holds
115
+ * only while every subpath is a real file under the package directory; a
116
+ * package whose `exports` map REMAPS one is pinned by
117
+ * `singletonResolvePlugin` instead, because the prefix would rewrite the
118
+ * specifier to a path that does not exist. Entries are omitted when the
119
+ * package is not installed, so a consumer that does not use cookies is
120
+ * unaffected.
117
121
  *
118
122
  * @param root Directory whose `node_modules` the packages resolve from.
119
123
  */
120
124
  export function singletonDepAliases(root: string = process.cwd()): Record<string, string> {
121
125
  const aliases: Record<string, string> = {};
126
+ for (const { name, dir, exportsMapped } of resolveSingletons(root)) {
127
+ if (!exportsMapped) aliases[name] = dir;
128
+ }
129
+ return aliases;
130
+ }
131
+
132
+ /** One installed context singleton, and how it has to be pinned. */
133
+ export interface SingletonPin {
134
+ name: string;
135
+ dir: string;
136
+ /** Its `exports` map remaps a subpath, so a directory alias cannot pin it. */
137
+ exportsMapped: boolean;
138
+ }
139
+
140
+ /**
141
+ * Every installed context singleton with its pinned directory.
142
+ *
143
+ * `exportsMapped` is measured rather than listed: a subpath key whose literal
144
+ * path does not exist under the package is one only the `exports` map can
145
+ * resolve. Measured on the installed tree at Tamagui 3.2.3, `@tamagui/core`
146
+ * and `@tamagui/web` each remap `./theme-update`, `./dom` and
147
+ * `./static-resolve`, and `react-cookie` and the three tanstack packages remap
148
+ * nothing. So a tanstack upgrade that adds a remapped subpath moves itself to
149
+ * the plugin instead of breaking a build.
150
+ */
151
+ export function resolveSingletons(root: string = process.cwd()): SingletonPin[] {
122
152
  const requireFrom = createRequire(path.join(root, "package.json"));
153
+ const pins: SingletonPin[] = [];
154
+ for (const name of CONTEXT_SINGLETONS) {
155
+ const dir = resolvePackageDir(name, root, requireFrom);
156
+ if (dir) pins.push({ name, dir, exportsMapped: remapsASubpath(dir) });
157
+ }
158
+ return pins;
159
+ }
123
160
 
124
- for (const pkgName of CONTEXT_SINGLETONS) {
125
- const pkgDir = resolvePackageDir(pkgName, root, requireFrom);
126
- if (pkgDir) aliases[pkgName] = pkgDir;
161
+ function remapsASubpath(pkgDir: string): boolean {
162
+ let exports: unknown;
163
+ try {
164
+ exports = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf8")).exports;
165
+ } catch {
166
+ return false;
167
+ }
168
+ if (typeof exports !== "object" || exports === null) return false;
169
+ for (const key of Object.keys(exports)) {
170
+ if (key === "." || key === "./package.json" || !key.startsWith("./")) continue;
171
+ if (key.includes("*")) return true;
172
+ if (!fs.existsSync(path.join(pkgDir, key.slice(2)))) return true;
127
173
  }
174
+ return false;
175
+ }
128
176
 
129
- return aliases;
177
+ /**
178
+ * Pins the singletons a directory alias cannot reach.
179
+ *
180
+ * `tamagui`'s own index imports `./theme-update.mjs`, which imports
181
+ * `@tamagui/core/theme-update`, which imports `@tamagui/web/theme-update`, so
182
+ * every import of `tamagui` anywhere walks that chain. Under a directory alias
183
+ * the prefix match rewrites it to `<pkgDir>/theme-update`, which is not a file,
184
+ * and `apps/one`'s production build dies with
185
+ * `[UNLOADABLE_DEPENDENCY] Could not load @tamagui/core/theme-update`. The dev
186
+ * server and vitest pre-bundle bare imports by package NAME and never see it,
187
+ * which is why 19,236 specs pass against a build that cannot be made.
188
+ *
189
+ * Re-resolving ANCHORED at the pinned package's own `package.json` is what
190
+ * keeps both halves: the exports map runs, so the environment's own conditions
191
+ * pick `.mjs` on web and `.native.js` on native, and the copy is the pinned one
192
+ * because that is where the resolution starts. A static target cannot do this,
193
+ * since the web and native files differ and this alias set is shared by both.
194
+ *
195
+ * @param root Directory whose `node_modules` the packages resolve from.
196
+ */
197
+ export function singletonResolvePlugin(root: string = process.cwd()): {
198
+ name: string;
199
+ enforce: "pre";
200
+ resolveId: (
201
+ this: {
202
+ resolve: (
203
+ source: string,
204
+ importer?: string,
205
+ options?: Record<string, unknown>,
206
+ ) => Promise<{ id: string } | null>;
207
+ },
208
+ source: string,
209
+ importer: string | undefined,
210
+ options: Record<string, unknown>,
211
+ ) => Promise<string | null>;
212
+ } {
213
+ const pinned = resolveSingletons(root).filter((pin) => pin.exportsMapped);
214
+ return {
215
+ name: "multiplatform-singleton-resolve",
216
+ enforce: "pre",
217
+ async resolveId(source, _importer, options) {
218
+ const pin = pinned.find((p) => source === p.name || source.startsWith(`${p.name}/`));
219
+ if (!pin) return null;
220
+ const anchor = path.join(pin.dir, "package.json");
221
+ const resolved = await this.resolve(source, anchor, { ...options, skipSelf: true });
222
+ return resolved?.id ?? null;
223
+ },
224
+ };
130
225
  }
131
226
 
132
227
  /**
@@ -54,17 +54,14 @@ describe("createStorybookViteConfig", () => {
54
54
  "@tamagui/animations-css",
55
55
  "@tamagui/react-native-svg",
56
56
  "@tamagui/colors",
57
- "@tamagui/config",
58
57
  "@tamagui/config/v5",
59
58
  "@tamagui/constants",
60
59
  "@tamagui/font-inter",
61
60
  "@tamagui/get-font-sized",
62
61
  "@tamagui/get-token",
63
62
  "@tamagui/linear-gradient",
64
- "@tamagui/lucide-icons-2",
65
63
  "@tamagui/roving-focus",
66
64
  "@tamagui/shorthands",
67
- "@tamagui/theme-builder",
68
65
  "@tamagui/themes",
69
66
  "@tamagui/toast",
70
67
  ]) {