@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.
Files changed (44) hide show
  1. package/design-lint.mjs +29 -6
  2. package/lib/index.js +4 -4
  3. package/lib/{storybook-BpaziEtP.js → storybook-LYamvanr.js} +13 -9
  4. package/lib/storybook.js +1 -1
  5. package/lib/{tamaguiWorkspacePaths-DR3dud79.js → tamaguiWorkspacePaths-7eT9XxzE.js} +9 -6
  6. package/lib/{vite-CgiDLR6V.js → vite-BtlhFd_U.js} +40 -52
  7. package/lib/vite.js +4 -4
  8. package/lib/{vitest-B2vcGrZM.js → vitest-B8Z8ZZQR.js} +97 -10
  9. package/lib/vitest.js +2 -2
  10. package/lib/{workspacePublicPackages-DN-1LPcH.js → workspacePublicPackages-B_kw7fuc.js} +379 -129
  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 +24 -0
  18. package/src/nativeBlockScoping.spec.ts +12 -14
  19. package/src/noVoicelessText.rule.spec.ts +1 -1
  20. package/src/noVoicelessText.spec.ts +1 -1
  21. package/src/oxlint.spec.ts +5 -5
  22. package/src/phosphorNativeInk.spec.ts +17 -18
  23. package/src/phosphorTokenColor.spec.ts +35 -0
  24. package/src/phosphorTokenColor.ts +8 -5
  25. package/src/press-lint.spec.ts +64 -3
  26. package/src/react-native.config.cjs +9 -0
  27. package/src/shims/phosphorThemeInk.js +6 -1
  28. package/src/singletonDepAliases.spec.ts +99 -14
  29. package/src/singletonDepAliases.ts +102 -7
  30. package/src/storybook.spec.ts +0 -3
  31. package/src/storybook.ts +20 -6
  32. package/src/vite.nativeEntries.spec.ts +21 -20
  33. package/src/vite.spec.ts +11 -20
  34. package/src/vite.ts +44 -69
  35. package/src/vitest.spec.ts +142 -4
  36. package/src/vitest.ts +106 -8
  37. package/types/phosphorTokenColor.d.ts.map +1 -1
  38. package/types/singletonDepAliases.d.ts +55 -3
  39. package/types/singletonDepAliases.d.ts.map +1 -1
  40. package/types/storybook.d.ts.map +1 -1
  41. package/types/vite.d.ts +10 -1
  42. package/types/vite.d.ts.map +1 -1
  43. package/types/vitest.d.ts +46 -1
  44. package/types/vitest.d.ts.map +1 -1
package/design-lint.mjs CHANGED
@@ -61,6 +61,8 @@ const middotJoin = /(^|[^\p{L}\p{N}])·([^\p{L}\p{N}]|$)|\s•\s/u;
61
61
  const focusPaint =
62
62
  /^(?:outline(?:Width|Color|Offset)?|boxShadow|shadow(?:Color|Opacity|Radius|Offset)|elevation)$/;
63
63
  const focusStates = new Set(["focusStyle", "focusVisibleStyle", "focusWithinStyle"]);
64
+ const focusClausePaint =
65
+ /(?<![\w/-])(?:[@A-Za-z][\w/@-]*:)*focus(?:-visible|-within)?:(?!(?:0(?:px)?|none|transparent)(?:\s+[@A-Za-z][\w/@-]*:|\s*$))\S/;
64
66
  // LC-149 FIELD-TRAILING-ACTION: a field's own action (reveal, clear, copy,
65
67
  // eyedropper) is Input.Action inside the field, never an icon button beside it.
66
68
  const fieldTag =
@@ -72,6 +74,11 @@ const rowTag = /^(?:XStack|XGroup)$|\.XGroup$/;
72
74
  // copy inside its top-trailing corner), never mono text with a copy beside it.
73
75
  const copyGlyph = /(?:Copy|Clipboard)\w*Icon\b/;
74
76
  const copyTag = /^Copy\w*Button$/;
77
+ // Tamagui 3 replaced `Component.styleable(fn)` with `createStyledHOC(Component,
78
+ // fn)`, so a wrapped component spells its render function as the second
79
+ // argument. Both shapes are unwrapped while the tree is half converted.
80
+ const styleableWrap = /\.styleable$/;
81
+ const styledHocWrap = /(?:^|\.)createStyledHOC$/;
75
82
  // LC-176 ICON-BUTTON: an icon-only button paints its recipe's plate. A prop that
76
83
  // paints its own plate, ring or corners around the glyph needs a named plate.
77
84
  const buttonTag = /^(?:Button|IconButton|TamaguiButton|PageBarButton)$|\.Button$/;
@@ -296,6 +303,7 @@ const labelKey =
296
303
  // not seen, unless it doubles as the control's tooltip (LC-260), so syntax
297
304
  // can't tell which case it takes.
298
305
  const spokenKey = /^(?:aria-label|accessibilityLabel)$/;
306
+ const spokenCall = /^a11yProps$/;
299
307
  const pluralHedge = /[a-z]{2,}\(s\)(?=[\s"'`?.,;:!)]|$)/;
300
308
  const errorLead =
301
309
  /^(?:\d|\{x\}\s*:|[A-Z][A-Z0-9]*_[A-Z0-9_]*\b|[A-Z]{2,}[A-Z0-9]*(?::|\s+\d)|[a-z][a-z0-9]*(?:[A-Z_.][A-Za-z0-9_]*)+\b)/;
@@ -804,7 +812,8 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
804
812
  function numeric(node) {
805
813
  const value = resolve(node);
806
814
  if (ts.isNumericLiteral(value)) return true;
807
- if (ts.isStringLiteral(value)) return /^-?\d+(?:\.\d+)?(?:px|rem|em)?$/.test(value.text);
815
+ if (ts.isStringLiteral(value))
816
+ return /^-?\d+(?:\.\d+)?(?:px|rem|em)$|^-?\d+\.\d+$/.test(value.text);
808
817
  if (ts.isPrefixUnaryExpression(value)) return numeric(value.operand);
809
818
  if (ts.isBinaryExpression(value)) {
810
819
  if (
@@ -874,6 +883,15 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
874
883
  return undefined;
875
884
  }
876
885
  function checkFocus(key, value, node) {
886
+ const flat = resolve(value);
887
+ if (focusPaint.test(key) && ts.isStringLiteralLike(flat) && focusClausePaint.test(flat.text)) {
888
+ report(
889
+ node,
890
+ "field-focus",
891
+ `${key} paints its own focus clause; focus comes from MPO (FIELD_FOCUS_STYLE).`,
892
+ );
893
+ return;
894
+ }
877
895
  if (!focusStates.has(key)) return;
878
896
  const painted = paintsFocus(value);
879
897
  if (painted)
@@ -951,7 +969,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
951
969
  if (!children.some(copiesBeside)) return;
952
970
  for (const child of children) {
953
971
  const font = attribute(child, "fontFamily");
954
- if (font?.initializer && /\$mono/.test(font.initializer.getText(file)))
972
+ if (font?.initializer && /(?<![\w-])\$?mono(?![\w-])/.test(font.initializer.getText(file)))
955
973
  report(
956
974
  child,
957
975
  "code-block",
@@ -1120,6 +1138,8 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
1120
1138
  return "data";
1121
1139
  if (ts.isCallExpression(host) && /toast|notif|snack/i.test(host.expression.getText(file)))
1122
1140
  return "text";
1141
+ if (ts.isCallExpression(host) && spokenCall.test(host.expression.getText(file)))
1142
+ return undefined;
1123
1143
  if (
1124
1144
  /^(?:label|title|heading)$/.test(key) &&
1125
1145
  parent.parent.properties.some((prop) => prop.name && runningSibling.test(name(prop.name)))
@@ -1924,7 +1944,8 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
1924
1944
  const callee = current.expression.getText(file);
1925
1945
  if (/^(?:(?:React\.)?(?:memo|forwardRef)|observer|withStaticProperties)$/.test(callee))
1926
1946
  current = current.arguments[0];
1927
- else if (/\.styleable$/.test(callee)) current = current.arguments[0];
1947
+ else if (styleableWrap.test(callee)) current = current.arguments[0];
1948
+ else if (styledHocWrap.test(callee) && current.arguments[1]) current = current.arguments[1];
1928
1949
  else return current;
1929
1950
  }
1930
1951
  }
@@ -1934,8 +1955,10 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
1934
1955
  if (ts.isArrowFunction(value) || ts.isFunctionExpression(value))
1935
1956
  return paintsOwnSurface(value.body);
1936
1957
  if (styledPrimitive(value)?.paints) return true;
1937
- if (ts.isCallExpression(value) && /\.styleable$/.test(value.expression.getText(file)))
1938
- return false;
1958
+ if (ts.isCallExpression(value)) {
1959
+ const callee = value.expression.getText(file);
1960
+ if (styleableWrap.test(callee) || styledHocWrap.test(callee)) return false;
1961
+ }
1939
1962
  return false;
1940
1963
  }
1941
1964
  function checkMpoRoles() {
@@ -2011,7 +2034,7 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
2011
2034
  /^(?:bg|backgroundColor|background)$/.test(key) &&
2012
2035
  value &&
2013
2036
  !inert(value) &&
2014
- !/^["'`]?\$(?:background|backgroundTransparent)["'`]?$/.test(value.getText(file)),
2037
+ !/^["'`]?\$?(?:background|background-transparent)["'`]?$/.test(value.getText(file)),
2015
2038
  );
2016
2039
  const shape = [...keys].some(
2017
2040
  ([key, value]) =>
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { i as phosphorTokenColorPlugin, n as tamaguiWorkspacePathsFile, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-DR3dud79.js";
2
- import { t as createStorybookViteConfig } from "./storybook-BpaziEtP.js";
3
- import { t as createViteConfig } from "./vite-CgiDLR6V.js";
4
- import { t as createVitestConfig } from "./vitest-B2vcGrZM.js";
1
+ import { i as phosphorTokenColorPlugin, n as tamaguiWorkspacePathsFile, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-7eT9XxzE.js";
2
+ import { t as createStorybookViteConfig } from "./storybook-LYamvanr.js";
3
+ import { t as createViteConfig } from "./vite-BtlhFd_U.js";
4
+ import { t as createVitestConfig } from "./vitest-B8Z8ZZQR.js";
5
5
 
6
6
  export { createStorybookViteConfig, createViteConfig, createVitestConfig, ensureTamaguiWorkspacePaths, phosphorTokenColorPlugin, tamaguiWorkspacePathsFile };
@@ -1,5 +1,5 @@
1
- import { c as withSingletonDepAliases, r as resolvePackageMainSource, t as discoverPublicPackageRoots } from "./workspacePublicPackages-DN-1LPcH.js";
2
- import { i as phosphorTokenColorPlugin, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-DR3dud79.js";
1
+ import { d as nativeOnlyDepStubPlugin, f as movedDepAliases, o as singletonResolvePlugin, r as resolvePackageMainSource, s as withSingletonDepAliases, t as discoverPublicPackageRoots, u as nativeOnlyDepStubOptimizerPlugin } from "./workspacePublicPackages-B_kw7fuc.js";
2
+ import { i as phosphorTokenColorPlugin, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-7eT9XxzE.js";
3
3
  import { createRequire } from "node:module";
4
4
  import fs from "node:fs";
5
5
  import path from "node:path";
@@ -92,10 +92,14 @@ function resolvePackageDir(pkgName, root, requireFrom) {
92
92
  function createStorybookViteConfig(options = {}) {
93
93
  ensureTamaguiWorkspacePaths();
94
94
  const workspaceRoot = options.workspaceRoot || findWorkspaceRoot();
95
+ const packagesDir = path.join(workspaceRoot, "packages");
96
+ const nativeOnlyStub = nativeOnlyDepStubPlugin(workspaceRoot);
97
+ const nativeOnlyStubForOptimizer = nativeOnlyDepStubOptimizerPlugin(workspaceRoot);
95
98
  const sortedAliases = withSingletonDepAliases({
96
- ...discoverPackageAliases(path.join(workspaceRoot, "packages")),
99
+ ...discoverPackageAliases(packagesDir),
97
100
  ...discoverPublicPackageViteAliases(workspaceRoot),
98
- ...unexportedDepAliases(workspaceRoot)
101
+ ...unexportedDepAliases(workspaceRoot),
102
+ ...movedDepAliases(workspaceRoot)
99
103
  }, workspaceRoot, options.aliases);
100
104
  return {
101
105
  define: {
@@ -129,12 +133,10 @@ function createStorybookViteConfig(options = {}) {
129
133
  "react-native-web",
130
134
  "@tamagui/core",
131
135
  "@tamagui/web",
132
- "@tamagui/helpers-icon",
133
136
  "tamagui",
134
137
  "@tamagui/animations-css",
135
138
  "@tamagui/react-native-svg",
136
139
  "@tamagui/colors",
137
- "@tamagui/config",
138
140
  "@tamagui/config/v5",
139
141
  "@tamagui/constants",
140
142
  "@tamagui/font-inter",
@@ -143,7 +145,6 @@ function createStorybookViteConfig(options = {}) {
143
145
  "@tamagui/input",
144
146
  "@tamagui/label",
145
147
  "@tamagui/linear-gradient",
146
- "@tamagui/lucide-icons-2",
147
148
  "@tamagui/popover",
148
149
  "@tamagui/portal",
149
150
  "@tamagui/roving-focus",
@@ -152,7 +153,6 @@ function createStorybookViteConfig(options = {}) {
152
153
  "@tamagui/shorthands",
153
154
  "@tamagui/stacks",
154
155
  "@tamagui/text",
155
- "@tamagui/theme-builder",
156
156
  "@tamagui/themes",
157
157
  "@tamagui/toast",
158
158
  "@tamagui/use-presence",
@@ -170,6 +170,7 @@ function createStorybookViteConfig(options = {}) {
170
170
  "use-sync-external-store/with-selector",
171
171
  "fast-deep-equal",
172
172
  "color",
173
+ "warn-once",
173
174
  "query-string",
174
175
  "react-is"
175
176
  ],
@@ -183,11 +184,14 @@ function createStorybookViteConfig(options = {}) {
183
184
  "@react-navigation/elements",
184
185
  "@react-navigation/bottom-tabs",
185
186
  "@react-navigation/native-stack"
186
- ]
187
+ ],
188
+ rolldownOptions: nativeOnlyStubForOptimizer ? { plugins: [nativeOnlyStubForOptimizer] } : void 0
187
189
  },
188
190
  plugins: [
191
+ singletonResolvePlugin(workspaceRoot),
189
192
  nodeAsyncHooksStub(),
190
193
  phosphorTokenColorPlugin(),
194
+ ...nativeOnlyStub ? [nativeOnlyStub] : [],
191
195
  ...options.plugins || []
192
196
  ]
193
197
  };
package/lib/storybook.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as createStorybookViteConfig } from "./storybook-BpaziEtP.js";
1
+ import { t as createStorybookViteConfig } from "./storybook-LYamvanr.js";
2
2
 
3
3
  export { createStorybookViteConfig };
@@ -1,8 +1,8 @@
1
1
  import Module from "node:module";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
- import { fileURLToPath, pathToFileURL } from "node:url";
5
4
  import { execFileSync } from "node:child_process";
5
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
6
 
7
7
  //#region src/phosphorTokenColor.ts
8
8
  const virtualPrefix = "\0mpo-phosphor-token-icon-base:";
@@ -27,6 +27,8 @@ import { useTheme } from "@tamagui/core";
27
27
  import IconBase from ${JSON.stringify(originalIconBase)};
28
28
 
29
29
  const isToken = (color) => typeof color === "string" && color.charAt(0) === "$";
30
+ const isNamed = (color) =>
31
+ typeof color === "string" && color.length > 0 && color !== "currentColor";
30
32
 
31
33
  const paintOf = (entry) => {
32
34
  const value = entry != null && typeof entry === "object" ? entry.val : entry;
@@ -35,16 +37,17 @@ const paintOf = (entry) => {
35
37
 
36
38
  const ThemeColorIconBase = forwardRef(function ThemeColorIconBase(props, ref) {
37
39
  const theme = useTheme() || {};
40
+ const name = isToken(props.color) ? props.color.slice(1) : props.color;
38
41
  const color =
39
- paintOf(theme[props.color.slice(1)]) ??
40
- paintOf(theme.color) ??
41
- paintOf(theme.color12) ??
42
- paintOf(theme.color11);
42
+ paintOf(theme[name]) ??
43
+ (isToken(props.color)
44
+ ? paintOf(theme.color) ?? paintOf(theme["color-12"]) ?? paintOf(theme["color-11"])
45
+ : props.color);
43
46
  return createElement(IconBase, { ...props, ref, color });
44
47
  });
45
48
 
46
49
  const TokenColorIconBase = forwardRef(function TokenColorIconBase(props, ref) {
47
- return createElement(isToken(props.color) ? ThemeColorIconBase : IconBase, { ...props, ref });
50
+ return createElement(isNamed(props.color) ? ThemeColorIconBase : IconBase, { ...props, ref });
48
51
  });
49
52
  TokenColorIconBase.displayName = "IconBase";
50
53
 
@@ -1,5 +1,5 @@
1
- import { c as withSingletonDepAliases, i as resolveWorkspaceNativeEntry, l as __require, o as lookupTamaguiModules, s as resolveConfig, t as discoverPublicPackageRoots } from "./workspacePublicPackages-DN-1LPcH.js";
2
- import { i as phosphorTokenColorPlugin, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-DR3dud79.js";
1
+ import { c as lookupTamaguiModules, f as movedDepAliases, i as resolveWorkspaceNativeEntry, l as resolveConfig, o as singletonResolvePlugin, p as __require, s as withSingletonDepAliases, t as discoverPublicPackageRoots } from "./workspacePublicPackages-B_kw7fuc.js";
2
+ import { i as phosphorTokenColorPlugin, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-7eT9XxzE.js";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import dotenv from "dotenv";
@@ -225,6 +225,7 @@ function createViteConfig(options = {}) {
225
225
  dotenv.config({ path: path.resolve(projectRoot, ".env") });
226
226
  if (publicConfigKeys.length > 0) bakePublicConfig(publicConfigKeys);
227
227
  const vitePlugins = [];
228
+ vitePlugins.push(singletonResolvePlugin(projectRoot));
228
229
  vitePlugins.push(preferBuiltWorkspaceEntryPlugin());
229
230
  vitePlugins.push(phosphorTokenColorPlugin());
230
231
  if (publicConfigFile) vitePlugins.push(publicConfigPlugin({
@@ -235,14 +236,14 @@ function createViteConfig(options = {}) {
235
236
  if (one) {
236
237
  vitePlugins.push(ssrReactNativeAliasPlugin());
237
238
  vitePlugins.push(clientBrokenEsmPlugin());
238
- registerNativeEngineIoBrowserTransports();
239
- registerNativeSinglePackageInstances();
240
- registerNativeWorkspaceEntries();
241
- registerNativePhosphorIcons();
242
- if (nativeFixes?.protoShadow !== false) registerNativeProtoShadowFix();
243
- if (nativeFixes?.web3Stub !== false) registerNativeWeb3Stub();
244
- if (nativeFixes?.blockScoping !== false) registerNativeBlockScoping();
245
- registerNativeCommunityFlowStrip();
239
+ vitePlugins.push(registerNativeEngineIoBrowserTransports());
240
+ vitePlugins.push(registerNativeSinglePackageInstances());
241
+ vitePlugins.push(registerNativeWorkspaceEntries());
242
+ vitePlugins.push(registerNativePhosphorIcons());
243
+ if (nativeFixes?.protoShadow !== false) vitePlugins.push(registerNativeProtoShadowFix());
244
+ if (nativeFixes?.web3Stub !== false) vitePlugins.push(registerNativeWeb3Stub());
245
+ if (nativeFixes?.blockScoping !== false) vitePlugins.push(registerNativeBlockScoping());
246
+ vitePlugins.push(registerNativeCommunityFlowStrip());
246
247
  if (ssrCjsExternal !== false) vitePlugins.push(ssrCjsExternalFixPlugin([...DEFAULT_SSR_CJS_EXTERNAL, ...ssrCjsExternal ?? []]));
247
248
  }
248
249
  if (tamagui) {
@@ -250,8 +251,7 @@ function createViteConfig(options = {}) {
250
251
  vitePlugins.push(tamaguiPlugin({
251
252
  components: tamaguiOpts.components || lookupTamaguiModules([process.cwd()]),
252
253
  config: tamaguiOpts.config || "./config/tamagui.config.ts",
253
- outputCSS: tamaguiOpts.outputCSS || "./public/tamagui.css",
254
- disableWatchTamaguiConfig: true
254
+ outputCSS: tamaguiOpts.outputCSS || "./public/tamagui.css"
255
255
  }));
256
256
  }
257
257
  if (i18n) {
@@ -347,7 +347,8 @@ function createViteConfig(options = {}) {
347
347
  resolve: {
348
348
  alias: withSingletonDepAliases({
349
349
  "react.mjs": "react",
350
- "react-compiler-runtime": "react/compiler-runtime"
350
+ "react-compiler-runtime": "react/compiler-runtime",
351
+ ...movedDepAliases(projectRoot)
351
352
  }, projectRoot),
352
353
  dedupe: ["react-is"]
353
354
  },
@@ -415,8 +416,20 @@ function clientBrokenEsmPlugin() {
415
416
  };
416
417
  }
417
418
  /**
419
+ * A rolldown plugin for the native bundle only. one 2.x hands every vite
420
+ * plugin that carries `api.vxrnNative` to vxrn's native rolldown pipeline, in
421
+ * dev and in the native export; the vite plugin is a hookless shell under its
422
+ * own name, so web and SSR never run or list the native plugin.
423
+ */
424
+ function nativeOnlyPlugin(plugin) {
425
+ return {
426
+ name: `mpo-native:${plugin.name}`,
427
+ api: { vxrnNative: () => plugin }
428
+ };
429
+ }
430
+ /**
418
431
  * Adds engine.io-client's `browser`-field transport redirect to vxrn's NATIVE
419
- * rolldown pipeline via its `globalThis.__vxrnAddNativePlugins` hook.
432
+ * rolldown pipeline via one's `api.vxrnNative` hook.
420
433
  *
421
434
  * socket.io-client -> engine.io-client/index.js statically imports its Node
422
435
  * transports (`./globals.node.js`, `./transports/{websocket,polling-xhr}.node.js`),
@@ -427,7 +440,7 @@ function clientBrokenEsmPlugin() {
427
440
  * `WebSocket` / `XMLHttpRequest` React Native provides — but vxrn's native
428
441
  * resolver omits the `browser` aliasField (and its rolldown binding doesn't even
429
442
  * support `aliasFields`). vxrn's native dev engine ignores the Vite config's
430
- * `resolve.alias`/`resolveId` too — BUT it DOES read `globalThis.__vxrnAddNativePlugins`
443
+ * `resolve.alias`/`resolveId` too — BUT it DOES take one's `api.vxrnNative` plugins
431
444
  * inside `getNativePlugins`, so a `resolveId` registered there runs on native.
432
445
  * This re-asserts the browser redirect with no node_modules patch. Web is
433
446
  * unaffected (engine.io is SSR-externalized and the web client already maps `browser`).
@@ -472,10 +485,7 @@ function clientBrokenEsmPlugin() {
472
485
  * relative imports resolve inside the canonical copy for free.
473
486
  */
474
487
  function registerNativeSinglePackageInstances() {
475
- const g = globalThis;
476
488
  const name = "vxrn-single-package-instances";
477
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
478
- if (g.__vxrnAddNativePlugins.some((p) => p?.name === name)) return;
479
489
  const rootModules = path.join(findProjectRoot(), "node_modules");
480
490
  const storePath = /[\\/]node_modules[\\/]\.pnpm[\\/][^\\/]+[\\/]node_modules[\\/]((?:@[^\\/]+[\\/])?[^\\/]+)(?:[\\/](.*))?$/;
481
491
  function versionOf(dir) {
@@ -505,7 +515,7 @@ function registerNativeSinglePackageInstances() {
505
515
  return hoisted.get(pkg) ?? null;
506
516
  }
507
517
  const seen = /* @__PURE__ */ new Map();
508
- g.__vxrnAddNativePlugins.push({
518
+ return nativeOnlyPlugin({
509
519
  name,
510
520
  async resolveId(id, importer) {
511
521
  if (!id || id.startsWith(".") || id.startsWith("/") || id.startsWith("\0")) return null;
@@ -534,12 +544,8 @@ function registerNativeSinglePackageInstances() {
534
544
  });
535
545
  }
536
546
  function registerNativeEngineIoBrowserTransports() {
537
- const g = globalThis;
538
- const name = "vxrn-engineio-browser-transports";
539
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
540
- if (g.__vxrnAddNativePlugins.some((p) => p?.name === name)) return;
541
- g.__vxrnAddNativePlugins.push({
542
- name,
547
+ return nativeOnlyPlugin({
548
+ name: "vxrn-engineio-browser-transports",
543
549
  async resolveId(id, importer) {
544
550
  if (importer && /engine\.io-client[\\/]build[\\/]/.test(importer) && id.endsWith(".node.js")) return this.resolve(`${id.slice(0, -8)}.js`, importer, { skipSelf: true });
545
551
  return null;
@@ -548,7 +554,7 @@ function registerNativeEngineIoBrowserTransports() {
548
554
  }
549
555
  /**
550
556
  * Routes workspace (`@multiplatform.one/*`) packages to their native entry on
551
- * NATIVE, via vxrn's `globalThis.__vxrnAddNativePlugins` hook.
557
+ * NATIVE, via one's `api.vxrnNative` hook.
552
558
  *
553
559
  * Why this is needed: `preferBuiltWorkspaceEntryPlugin` (a Vite plugin, web/SSR only)
554
560
  * hard-resolves every workspace bare specifier to `<root>/dist/esm/index.mjs` — the WEB
@@ -565,10 +571,7 @@ function registerNativeEngineIoBrowserTransports() {
565
571
  * Web/SSR are unaffected (this plugin runs ONLY on native).
566
572
  */
567
573
  function registerNativeWorkspaceEntries() {
568
- const g = globalThis;
569
574
  const name = "vxrn-workspace-native-entries";
570
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
571
- if (g.__vxrnAddNativePlugins.some((p) => p?.name === name)) return;
572
575
  let roots;
573
576
  try {
574
577
  roots = discoverPublicPackageRoots(findProjectRoot());
@@ -596,7 +599,7 @@ function registerNativeWorkspaceEntries() {
596
599
  if (!entries.has(root)) entries.set(root, resolveWorkspaceNativeEntry(root) ?? null);
597
600
  return entries.get(root);
598
601
  };
599
- g.__vxrnAddNativePlugins.push({
602
+ return nativeOnlyPlugin({
600
603
  name,
601
604
  resolveId(id) {
602
605
  const root = roots.get(id);
@@ -669,23 +672,17 @@ function requiresReact(id) {
669
672
  * Object.prototype method back over an undefined shadowing own-property
670
673
  * before any module code runs — the shadowed vars are reassigned by their
671
674
  * own modules on init, so this only bridges the parse-to-init window.
672
- * Registered through globalThis.__vxrnAddNativePlugins (vxrn's native engine
675
+ * Registered through one's api.vxrnNative hook (vxrn's native engine
673
676
  * ignores vite resolve/config). Web/SSR bundles are ESM (module-scoped vars)
674
677
  * and unaffected.
675
678
  */
676
679
  function registerNativeBlockScoping() {
677
- const g = globalThis;
678
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
679
- if (g.__vxrnAddNativePlugins.some((p) => p?.name === "vxrn-native-block-scoping")) return;
680
- g.__vxrnAddNativePlugins.push(nativeBlockScopingPlugin());
680
+ return nativeOnlyPlugin(nativeBlockScopingPlugin());
681
681
  }
682
682
  function registerNativeProtoShadowFix() {
683
- const g = globalThis;
684
683
  const name = "vxrn-proto-shadow-fix";
685
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
686
- if (g.__vxrnAddNativePlugins.some((p) => p?.name === name)) return;
687
684
  const snippet = "(function(){var p=Object.prototype,h=p.hasOwnProperty,ns=Object.getOwnPropertyNames(p);for(var i=0;i<ns.length;i++){var k=ns[i];if(typeof p[k]===\"function\"&&globalThis[k]===void 0&&h.call(globalThis,k)){try{globalThis[k]=p[k]}catch(e){}}}})();";
688
- g.__vxrnAddNativePlugins.push({
685
+ return nativeOnlyPlugin({
689
686
  name,
690
687
  renderChunk(code) {
691
688
  return {
@@ -709,11 +706,8 @@ function registerNativeProtoShadowFix() {
709
706
  * packages, so a consumer app needs no plugin of its own (FZ-7357).
710
707
  */
711
708
  function registerNativeCommunityFlowStrip() {
712
- const g = globalThis;
713
709
  const name = "vxrn-community-flow-strip";
714
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
715
- if (g.__vxrnAddNativePlugins.some((p) => p?.name === name)) return;
716
- g.__vxrnAddNativePlugins.push({
710
+ return nativeOnlyPlugin({
717
711
  name,
718
712
  async transform(code, id) {
719
713
  if (!/node_modules[\\/]@react-native-(community|segmented-control)[\\/].*\.jsx?$/.test(id)) return null;
@@ -747,10 +741,7 @@ function registerNativeCommunityFlowStrip() {
747
741
  * normal pipeline and are unaffected.
748
742
  */
749
743
  function registerNativeWeb3Stub() {
750
- const g = globalThis;
751
744
  const name = "vxrn-web3-stub";
752
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
753
- if (g.__vxrnAddNativePlugins.some((p) => p?.name === name)) return;
754
745
  try {
755
746
  __require.resolve("@multiplatform.one/web3", { paths: [findProjectRoot(), process.cwd()] });
756
747
  return;
@@ -758,7 +749,7 @@ function registerNativeWeb3Stub() {
758
749
  const here = path.dirname(new URL(import.meta.url).pathname);
759
750
  const shim = [path.resolve(here, "shims/web3Stub.native.js"), path.resolve(here, "../src/shims/web3Stub.native.js")].find((candidate) => fs.existsSync(candidate));
760
751
  if (!shim) return;
761
- g.__vxrnAddNativePlugins.push({
752
+ return nativeOnlyPlugin({
762
753
  name,
763
754
  resolveId(id) {
764
755
  if (id === "@multiplatform.one/web3/native" || id === "@multiplatform.one/web3") return shim;
@@ -789,10 +780,7 @@ function findProjectRoot() {
789
780
  * when phosphor-react-native isn't installed in the consuming project.
790
781
  */
791
782
  function registerNativePhosphorIcons() {
792
- const g = globalThis;
793
783
  const name = "vxrn-phosphor-native-icons";
794
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
795
- if (g.__vxrnAddNativePlugins.some((p) => p?.name === name)) return;
796
784
  let nativeEntry = null;
797
785
  try {
798
786
  const cjsEntry = __require.resolve("phosphor-react-native", { paths: [findProjectRoot(), process.cwd()] });
@@ -802,7 +790,7 @@ function registerNativePhosphorIcons() {
802
790
  nativeEntry = null;
803
791
  }
804
792
  const iconBase = nativeEntry ? phosphorNativeIconBase(nativeEntry) : null;
805
- g.__vxrnAddNativePlugins.push({
793
+ return nativeOnlyPlugin({
806
794
  name,
807
795
  resolveId(id, importer) {
808
796
  if (iconBase) {
@@ -879,4 +867,4 @@ function preferBuiltWorkspaceEntryPlugin() {
879
867
  }
880
868
 
881
869
  //#endregion
882
- export { publicConfigPlugin as a, phosphorNativeIconLibId as i, phosphorNativeIconBase as n, readPublicConfigKeys as o, phosphorNativeIconBaseId as r, createViteConfig as t };
870
+ export { phosphorNativeIconLibId as a, phosphorNativeIconBaseId as i, nativeOnlyPlugin as n, publicConfigPlugin as o, phosphorNativeIconBase as r, readPublicConfigKeys as s, createViteConfig as t };
package/lib/vite.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as staleNativeDistSource, i as resolveWorkspaceNativeEntry, n as publicPackageViteSourceAliases, t as discoverPublicPackageRoots } from "./workspacePublicPackages-DN-1LPcH.js";
2
- import { i as phosphorTokenColorPlugin } from "./tamaguiWorkspacePaths-DR3dud79.js";
3
- import { a as publicConfigPlugin, i as phosphorNativeIconLibId, n as phosphorNativeIconBase, o as readPublicConfigKeys, r as phosphorNativeIconBaseId, t as createViteConfig } from "./vite-CgiDLR6V.js";
1
+ import { a as staleNativeDistSource, i as resolveWorkspaceNativeEntry, n as publicPackageViteSourceAliases, t as discoverPublicPackageRoots } from "./workspacePublicPackages-B_kw7fuc.js";
2
+ import { i as phosphorTokenColorPlugin } from "./tamaguiWorkspacePaths-7eT9XxzE.js";
3
+ import { a as phosphorNativeIconLibId, i as phosphorNativeIconBaseId, n as nativeOnlyPlugin, o as publicConfigPlugin, r as phosphorNativeIconBase, s as readPublicConfigKeys, t as createViteConfig } from "./vite-BtlhFd_U.js";
4
4
 
5
- export { createViteConfig, discoverPublicPackageRoots, phosphorNativeIconBase, phosphorNativeIconBaseId, phosphorNativeIconLibId, phosphorTokenColorPlugin, publicConfigPlugin, publicPackageViteSourceAliases, readPublicConfigKeys, resolveWorkspaceNativeEntry, staleNativeDistSource };
5
+ export { createViteConfig, discoverPublicPackageRoots, nativeOnlyPlugin, phosphorNativeIconBase, phosphorNativeIconBaseId, phosphorNativeIconLibId, phosphorTokenColorPlugin, publicConfigPlugin, publicPackageViteSourceAliases, readPublicConfigKeys, resolveWorkspaceNativeEntry, staleNativeDistSource };
@@ -1,4 +1,4 @@
1
- import { i as phosphorTokenColorPlugin, r as phosphorBarrelBundlePlugin, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-DR3dud79.js";
1
+ import { i as phosphorTokenColorPlugin, r as phosphorBarrelBundlePlugin, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-7eT9XxzE.js";
2
2
  import Module from "node:module";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
@@ -85,6 +85,89 @@ function pinNodeReactRequire(reactDir, reactDomDir, schedulerDir) {
85
85
  };
86
86
  }
87
87
  /**
88
+ * The Vite environment Tamagui 3's vite plugin evaluates the tamagui config in
89
+ * (`TAMAGUI_EVALUATION_ENVIRONMENT` in @tamagui/vite-plugin's loadTamagui.ts,
90
+ * not exported). It inlines only the Tamagui packages it has to and hands every
91
+ * other bare import, react above all, to node.
92
+ */
93
+ const tamaguiEvaluationEnvironment = "tamagui";
94
+ /**
95
+ * Vitest 4 sets `resolve.noExternal = true` on every Vite environment but its
96
+ * own runner's, Tamagui's evaluation environment included, so react's CJS
97
+ * entry gets inlined there and the run dies before collecting a spec with
98
+ * `module is not defined`. Put the plugin's own list back once vitest has had
99
+ * its say. The client and ssr environments vitest runs specs in keep vitest's.
100
+ */
101
+ function tamaguiEvaluationExternals() {
102
+ let noExternal;
103
+ return {
104
+ name: "mpo:tamagui-evaluation-externals",
105
+ configEnvironment(name, config) {
106
+ if (name === tamaguiEvaluationEnvironment) noExternal = config.resolve?.noExternal;
107
+ },
108
+ configResolved(config) {
109
+ const environment = config.environments[tamaguiEvaluationEnvironment];
110
+ if (!environment || noExternal === void 0) return;
111
+ environment.resolve.noExternal = noExternal;
112
+ }
113
+ };
114
+ }
115
+ /**
116
+ * Tamagui 3 evaluates a package's tamagui config in its own environment, which
117
+ * resolves with Vite's default client conditions plus `tamagui-compiler` and
118
+ * none of MPO's. A config that imports a workspace package
119
+ * (`createDefaultThemeConfig` from @multiplatform.one/theme) then reaches for
120
+ * that package's unbuilt `dist/` and the run dies at startup with
121
+ * `Failed to resolve entry for package`. The plugin merges a user's
122
+ * `environments.tamagui` over its own, so this hands that environment the
123
+ * conditions the specs resolve with, `source` first among them.
124
+ */
125
+ function tamaguiEvaluationConditions(conditions) {
126
+ return {
127
+ name: "mpo:tamagui-evaluation-conditions",
128
+ config() {
129
+ return { environments: { [tamaguiEvaluationEnvironment]: { resolve: { conditions } } } };
130
+ }
131
+ };
132
+ }
133
+ /**
134
+ * The virtual stylesheet Tamagui 3's compiler writes each module's extracted
135
+ * atomic rules to (`virtualExt` in @tamagui/vite-plugin's plugin.ts). Vitest
136
+ * drops every CSS module its `css.include` doesn't name, so without this an
137
+ * element the compiler flattened carries hashed classes with no rule behind
138
+ * them, while a runtime-styled sibling's rules sit in `#_tamagui-styles`.
139
+ * Naming it puts both kinds of rule in `document.styleSheets`, where
140
+ * `atomicStyle()` in @multiplatform.one/test-utils reads them.
141
+ */
142
+ const tamaguiExtractedCss = /\.tamagui\.css(?:\?|$)/;
143
+ /**
144
+ * MPO-37's one-physical-copy pins as a resolver rather than `resolve.alias`.
145
+ * An alias applies in every environment, and in Tamagui's evaluation
146
+ * environment it turns `react` into a file path, which that environment
147
+ * inlines instead of handing to node. The pins only matter where specs render,
148
+ * so that environment resolves react the way node does.
149
+ *
150
+ * Matching is the alias's: a pin applies to its name and to any subpath under
151
+ * it, so `react/jsx-runtime` lands in the pinned react.
152
+ */
153
+ function pinnedPackages(pins) {
154
+ const names = Object.keys(pins).sort((a, b) => b.length - a.length);
155
+ return {
156
+ name: "mpo:pinned-packages",
157
+ enforce: "pre",
158
+ api: { pins },
159
+ async resolveId(source, importer, options) {
160
+ if (this.environment?.name === tamaguiEvaluationEnvironment) return null;
161
+ const name = names.find((pin) => source === pin || source.startsWith(`${pin}/`));
162
+ if (!name) return null;
163
+ return this.resolve(pins[name] + source.slice(name.length), importer, {
164
+ ...options,
165
+ skipSelf: true
166
+ });
167
+ }
168
+ };
169
+ }
170
+ /**
88
171
  * Creates a shared Vitest configuration for multiplatform.one packages.
89
172
  *
90
173
  * This eliminates the ~100 lines of duplicated vitest config across 13+ packages,
@@ -132,7 +215,7 @@ function createVitestConfig(options = {}) {
132
215
  if (tamaguiConfig !== false) plugins.push(tamaguiPlugin({
133
216
  components: ["tamagui"],
134
217
  config: tamaguiConfig
135
- }));
218
+ }), tamaguiEvaluationExternals(), tamaguiEvaluationConditions(conditions));
136
219
  const resolveAliases = {};
137
220
  if (replaceReactNative) {
138
221
  resolveAliases["react-native"] = "react-native-web";
@@ -147,14 +230,16 @@ function createVitestConfig(options = {}) {
147
230
  };
148
231
  const reactDir = onePhysicalCopy("react");
149
232
  const reactDomDir = onePhysicalCopy("react-dom");
150
- resolveAliases.react = reactDir;
151
- resolveAliases["react-dom"] = reactDomDir;
152
- resolveAliases["react-dom/client"] = path.join(reactDomDir, "client");
153
- resolveAliases["react-dom/server"] = path.join(reactDomDir, "server");
154
- resolveAliases["react/jsx-runtime"] = path.join(reactDir, "jsx-runtime");
155
- resolveAliases["react/jsx-dev-runtime"] = path.join(reactDir, "jsx-dev-runtime");
156
233
  const schedulerDir = onePhysicalCopy("scheduler");
157
- resolveAliases.scheduler = schedulerDir;
234
+ plugins.push(pinnedPackages({
235
+ react: reactDir,
236
+ "react-dom": reactDomDir,
237
+ "react-dom/client": path.join(reactDomDir, "client"),
238
+ "react-dom/server": path.join(reactDomDir, "server"),
239
+ "react/jsx-runtime": path.join(reactDir, "jsx-runtime"),
240
+ "react/jsx-dev-runtime": path.join(reactDir, "jsx-dev-runtime"),
241
+ scheduler: schedulerDir
242
+ }));
158
243
  process.env.MPO_VITEST_REACT = reactDir;
159
244
  process.env.MPO_VITEST_REACT_DOM = reactDomDir;
160
245
  process.env.MPO_VITEST_SCHEDULER = schedulerDir;
@@ -164,6 +249,7 @@ function createVitestConfig(options = {}) {
164
249
  const testConfig = {
165
250
  environment,
166
251
  globals: true,
252
+ env: { IS_STATIC: "" },
167
253
  setupFiles: dedupeReact ? [pinReactRequireSetup, ...resolvedSetupFiles] : resolvedSetupFiles,
168
254
  testTimeout: positiveIntEnv("VITEST_TEST_TIMEOUT") ?? testTimeout,
169
255
  ...positiveIntEnv("VITEST_MAX_WORKERS") ? { maxWorkers: positiveIntEnv("VITEST_MAX_WORKERS") } : null,
@@ -207,6 +293,7 @@ function createVitestConfig(options = {}) {
207
293
  if (include) testConfig.include = include;
208
294
  testConfig.exclude = [...exclude ?? configDefaults.exclude, ...integrationSpecs];
209
295
  if (passWithNoTests) testConfig.passWithNoTests = true;
296
+ if (tamaguiConfig !== false) testConfig.css = { include: [tamaguiExtractedCss] };
210
297
  return {
211
298
  plugins,
212
299
  test: testConfig,
@@ -256,4 +343,4 @@ function createVitestConfig(options = {}) {
256
343
  }
257
344
 
258
345
  //#endregion
259
- export { createVitestConfig as t };
346
+ export { tamaguiExtractedCss as a, tamaguiEvaluationExternals as i, pinnedPackages as n, tamaguiEvaluationConditions as r, createVitestConfig as t };
package/lib/vitest.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as createVitestConfig } from "./vitest-B2vcGrZM.js";
1
+ import { a as tamaguiExtractedCss, i as tamaguiEvaluationExternals, n as pinnedPackages, r as tamaguiEvaluationConditions, t as createVitestConfig } from "./vitest-B8Z8ZZQR.js";
2
2
 
3
- export { createVitestConfig };
3
+ export { createVitestConfig, pinnedPackages, tamaguiEvaluationConditions, tamaguiEvaluationExternals, tamaguiExtractedCss };