@multiplatform.one/config 9.17.0 → 10.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/design-lint.mjs +29 -6
- package/lib/index.js +4 -4
- package/lib/{storybook-BpaziEtP.js → storybook-LYamvanr.js} +13 -9
- package/lib/storybook.js +1 -1
- package/lib/{tamaguiWorkspacePaths-DR3dud79.js → tamaguiWorkspacePaths-7eT9XxzE.js} +9 -6
- package/lib/{vite-CgiDLR6V.js → vite-BtlhFd_U.js} +40 -52
- package/lib/vite.js +4 -4
- package/lib/{vitest-B2vcGrZM.js → vitest-B8Z8ZZQR.js} +97 -10
- package/lib/vitest.js +2 -2
- package/lib/{workspacePublicPackages-DN-1LPcH.js → workspacePublicPackages-B_kw7fuc.js} +379 -129
- package/lint.mjs +874 -52
- package/oxlint.mjs +26 -1
- package/package.json +6 -6
- package/press-lint.mjs +86 -5
- package/spec-registry.mjs +15 -0
- package/src/lint.spec.ts +696 -12
- package/src/movedDepAliases.spec.ts +24 -0
- package/src/nativeBlockScoping.spec.ts +12 -14
- package/src/noVoicelessText.rule.spec.ts +1 -1
- package/src/noVoicelessText.spec.ts +1 -1
- package/src/oxlint.spec.ts +5 -5
- package/src/phosphorNativeInk.spec.ts +17 -18
- package/src/phosphorTokenColor.spec.ts +35 -0
- package/src/phosphorTokenColor.ts +8 -5
- package/src/press-lint.spec.ts +64 -3
- package/src/react-native.config.cjs +9 -0
- package/src/shims/phosphorThemeInk.js +6 -1
- package/src/singletonDepAliases.spec.ts +99 -14
- package/src/singletonDepAliases.ts +102 -7
- package/src/storybook.spec.ts +0 -3
- package/src/storybook.ts +20 -6
- package/src/vite.nativeEntries.spec.ts +21 -20
- package/src/vite.spec.ts +11 -20
- package/src/vite.ts +44 -69
- package/src/vitest.spec.ts +142 -4
- package/src/vitest.ts +106 -8
- package/types/phosphorTokenColor.d.ts.map +1 -1
- package/types/singletonDepAliases.d.ts +55 -3
- package/types/singletonDepAliases.d.ts.map +1 -1
- package/types/storybook.d.ts.map +1 -1
- package/types/vite.d.ts +10 -1
- package/types/vite.d.ts.map +1 -1
- package/types/vitest.d.ts +46 -1
- package/types/vitest.d.ts.map +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { createStorybookViteConfig } from "./storybook";
|
|
4
|
+
import { createViteConfig } from "./vite";
|
|
5
|
+
|
|
6
|
+
const workspaceRoot = path.resolve(__dirname, "../../..");
|
|
7
|
+
|
|
8
|
+
describe("the factories that build a web bundle carry it", () => {
|
|
9
|
+
it("createStorybookViteConfig aliases it, which is where the build failed", () => {
|
|
10
|
+
const alias = (createStorybookViteConfig({ workspaceRoot }).resolve?.alias ?? {}) as Record<
|
|
11
|
+
string,
|
|
12
|
+
string
|
|
13
|
+
>;
|
|
14
|
+
expect(alias["@react-native/assets-registry/registry"]).toBeTruthy();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("createViteConfig aliases it too, so a generated project is not left with it", () => {
|
|
18
|
+
const alias = (createViteConfig({ projectRoot: workspaceRoot }).resolve?.alias ?? {}) as Record<
|
|
19
|
+
string,
|
|
20
|
+
string
|
|
21
|
+
>;
|
|
22
|
+
expect(alias["@react-native/assets-registry/registry"]).toBeTruthy();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { createViteConfig } from "./vite";
|
|
3
3
|
|
|
4
4
|
interface NativePlugin {
|
|
@@ -10,7 +10,11 @@ interface NativePlugin {
|
|
|
10
10
|
) => Promise<{ code: string } | null> | { code: string } | null;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
function nativePlugins<T>(config: ReturnType<typeof createViteConfig>): T[] {
|
|
14
|
+
return (config.plugins as Array<{ api?: { vxrnNative?: () => T } } | undefined>)
|
|
15
|
+
.flat()
|
|
16
|
+
.flatMap((plugin) => (plugin?.api?.vxrnNative ? [plugin.api.vxrnNative()] : []));
|
|
17
|
+
}
|
|
14
18
|
|
|
15
19
|
const fixture = `
|
|
16
20
|
function run() {
|
|
@@ -33,22 +37,17 @@ function runFunctionScoped(code: string): unknown[] {
|
|
|
33
37
|
return new Function(`${functionScoped}\nreturn run();`)() as unknown[];
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
function blockScopingPlugin(): NativePlugin | undefined {
|
|
37
|
-
return
|
|
40
|
+
function blockScopingPlugin(config: ReturnType<typeof createViteConfig>): NativePlugin | undefined {
|
|
41
|
+
return nativePlugins<NativePlugin>(config).find((p) => p.name === "vxrn-native-block-scoping");
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
delete nativeHook.__vxrnAddNativePlugins;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
44
|
describe("native block scoping (FZ-8895)", () => {
|
|
45
45
|
it("models the Hermes bug: a function-scoped run of the raw fixture sees only last values", () => {
|
|
46
46
|
expect(runFunctionScoped(fixture)).toEqual([3, 3, 3, 3, 3, 3, "b", "b"]);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
it("lowers let/const in a production native chunk so loop closures keep per-iteration values", async () => {
|
|
50
|
-
createViteConfig({ one: true });
|
|
51
|
-
const plugin = blockScopingPlugin();
|
|
50
|
+
const plugin = blockScopingPlugin(createViteConfig({ one: true }));
|
|
52
51
|
expect(plugin).toBeDefined();
|
|
53
52
|
plugin!.options?.({});
|
|
54
53
|
const result = await plugin!.renderChunk!(fixture, { fileName: "main.jsbundle" });
|
|
@@ -57,8 +56,7 @@ describe("native block scoping (FZ-8895)", () => {
|
|
|
57
56
|
});
|
|
58
57
|
|
|
59
58
|
it("leaves dev-engine chunks alone so Fast Refresh stays fast", async () => {
|
|
60
|
-
createViteConfig({ one: true })
|
|
61
|
-
const plugin = blockScopingPlugin()!;
|
|
59
|
+
const plugin = blockScopingPlugin(createViteConfig({ one: true }))!;
|
|
62
60
|
plugin.options?.({ experimental: { devMode: { host: "localhost", port: 8081 } } });
|
|
63
61
|
expect(await plugin.renderChunk!(fixture, { fileName: "main.jsbundle" })).toBeNull();
|
|
64
62
|
});
|
|
@@ -72,7 +70,7 @@ describe("native block scoping (FZ-8895)", () => {
|
|
|
72
70
|
});
|
|
73
71
|
|
|
74
72
|
it("can be turned off with nativeFixes.blockScoping: false", () => {
|
|
75
|
-
createViteConfig({ one: true, nativeFixes: { blockScoping: false } });
|
|
76
|
-
expect(blockScopingPlugin()).toBeUndefined();
|
|
73
|
+
const config = createViteConfig({ one: true, nativeFixes: { blockScoping: false } });
|
|
74
|
+
expect(blockScopingPlugin(config)).toBeUndefined();
|
|
77
75
|
});
|
|
78
76
|
});
|
|
@@ -184,7 +184,7 @@ describe("no-voiceless-text in process (LC-137)", () => {
|
|
|
184
184
|
const lines = lint(
|
|
185
185
|
[
|
|
186
186
|
styled("Shout", "Caption"),
|
|
187
|
-
styled("Caption", "Text", { color: "$
|
|
187
|
+
styled("Caption", "Text", { color: "$color-11" }),
|
|
188
188
|
styled("Mono", "Text", { fontFamily: "$mono" }),
|
|
189
189
|
styled("Plain", "Unknown"),
|
|
190
190
|
named("tamagui", [["Text"]]),
|
|
@@ -108,7 +108,7 @@ describe("mpo-conventions/no-voiceless-text (FZ-7739, LC-137)", () => {
|
|
|
108
108
|
" </>",
|
|
109
109
|
" );",
|
|
110
110
|
"}",
|
|
111
|
-
'const Caption = styled(Text, { color: "$
|
|
111
|
+
'const Caption = styled(Text, { color: "$color-11" });',
|
|
112
112
|
'const Mono = styled(Text, { fontFamily: "$mono" });',
|
|
113
113
|
"",
|
|
114
114
|
].join("\n"),
|
package/src/oxlint.spec.ts
CHANGED
|
@@ -37,7 +37,7 @@ describe("matchColorLiteral", () => {
|
|
|
37
37
|
expect(matchColorLiteral("#fff")).toBe("#fff");
|
|
38
38
|
expect(matchColorLiteral("rgba(0,0,0,0.35)")).toBe("rgba(0,0,0,0.35)");
|
|
39
39
|
expect(matchColorLiteral("hsl(0, 0%, 50%)")).toBe("hsl(0, 0%, 50%)");
|
|
40
|
-
expect(matchColorLiteral("$
|
|
40
|
+
expect(matchColorLiteral("$color-10")).toBeUndefined();
|
|
41
41
|
expect(matchColorLiteral("#025")).toBe("#025");
|
|
42
42
|
});
|
|
43
43
|
});
|
|
@@ -216,10 +216,10 @@ describe("mpo-conventions/no-chrome-props (MPO-17)", () => {
|
|
|
216
216
|
const filename = "features/lookout/src/WallScreen.tsx";
|
|
217
217
|
const importCard = houseImport("@multiplatform.one/components", ["Card"]);
|
|
218
218
|
|
|
219
|
-
it("errors on Card backgroundColor=$
|
|
219
|
+
it("errors on Card backgroundColor=$color-5 and stays silent on Card flex={1}", () => {
|
|
220
220
|
const chrome = driveHouseRule("no-chrome-props", filename, [
|
|
221
221
|
importCard,
|
|
222
|
-
jsxOpen("Card", [{ prop: "backgroundColor", value: token("$
|
|
222
|
+
jsxOpen("Card", [{ prop: "backgroundColor", value: token("$color-5") }]),
|
|
223
223
|
]);
|
|
224
224
|
expect(chrome.map((r) => r.data?.prop)).toEqual(["backgroundColor"]);
|
|
225
225
|
|
|
@@ -235,14 +235,14 @@ describe("mpo-conventions/no-chrome-props (MPO-17)", () => {
|
|
|
235
235
|
driveHouseRule(
|
|
236
236
|
"no-chrome-props",
|
|
237
237
|
filename,
|
|
238
|
-
[importCard, jsxOpen("Card", [{ prop: "bg", value: token("$
|
|
238
|
+
[importCard, jsxOpen("Card", [{ prop: "bg", value: token("$color-2") }])],
|
|
239
239
|
{ chromeAllow: ["Card"] },
|
|
240
240
|
),
|
|
241
241
|
).toEqual([]);
|
|
242
242
|
expect(
|
|
243
243
|
driveHouseRule("no-chrome-props", filename, [
|
|
244
244
|
houseImport("somewhere-else", ["Card"]),
|
|
245
|
-
jsxOpen("Card", [{ prop: "backgroundColor", value: token("$
|
|
245
|
+
jsxOpen("Card", [{ prop: "backgroundColor", value: token("$color-5") }]),
|
|
246
246
|
]),
|
|
247
247
|
).toEqual([]);
|
|
248
248
|
});
|
|
@@ -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 {
|
|
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
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
["$
|
|
39
|
-
["
|
|
40
|
-
["$
|
|
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({
|
|
50
|
-
expect(resolveIconInk({
|
|
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, "$
|
|
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", "$
|
|
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[
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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(
|
|
49
|
+
return createElement(isNamed(props.color) ? ThemeColorIconBase : IconBase, { ...props, ref });
|
|
47
50
|
});
|
|
48
51
|
TokenColorIconBase.displayName = "IconBase";
|
|
49
52
|
|
package/src/press-lint.spec.ts
CHANGED
|
@@ -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: "$
|
|
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: "$
|
|
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("
|
|
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
|
|
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"];
|
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
34
|
-
expect(
|
|
35
|
-
expect(
|
|
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("
|
|
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`).
|
|
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(
|
|
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
|
|
125
|
-
|
|
126
|
-
|
|
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"]) {
|