@multiplatform.one/config 9.16.1 → 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
package/src/storybook.ts CHANGED
@@ -2,7 +2,9 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import type { Plugin, UserConfig } from "vite";
4
4
  import { phosphorTokenColorPlugin } from "./phosphorTokenColor.js";
5
- import { withSingletonDepAliases } from "./singletonDepAliases.js";
5
+ import { movedDepAliases } from "./movedDepAliases.js";
6
+ import { nativeOnlyDepStubOptimizerPlugin, nativeOnlyDepStubPlugin } from "./nativeOnlyDepStubs.js";
7
+ import { singletonResolvePlugin, withSingletonDepAliases } from "./singletonDepAliases.js";
6
8
  import { unexportedDepAliases } from "./unexportedDepAliases.js";
7
9
  import { discoverPublicPackageRoots, resolvePackageMainSource } from "./workspacePublicPackages.js";
8
10
  import { ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths.js";
@@ -56,12 +58,15 @@ export function createStorybookViteConfig(
56
58
  ensureTamaguiWorkspacePaths();
57
59
  const workspaceRoot = options.workspaceRoot || findWorkspaceRoot();
58
60
  const packagesDir = path.join(workspaceRoot, "packages");
61
+ const nativeOnlyStub = nativeOnlyDepStubPlugin(workspaceRoot);
62
+ const nativeOnlyStubForOptimizer = nativeOnlyDepStubOptimizerPlugin(workspaceRoot);
59
63
 
60
64
  const sortedAliases = withSingletonDepAliases(
61
65
  {
62
66
  ...discoverPackageAliases(packagesDir),
63
67
  ...discoverPublicPackageViteAliases(workspaceRoot),
64
68
  ...unexportedDepAliases(workspaceRoot),
69
+ ...movedDepAliases(workspaceRoot),
65
70
  },
66
71
  workspaceRoot,
67
72
  options.aliases,
@@ -121,7 +126,6 @@ export function createStorybookViteConfig(
121
126
  "react-native-web",
122
127
  "@tamagui/core",
123
128
  "@tamagui/web",
124
- "@tamagui/helpers-icon",
125
129
  "tamagui",
126
130
  // MPO-149: every @tamagui/* package the story graph can reach, so the
127
131
  // whole tamagui graph is pre-bundled in ONE optimizer generation.
@@ -152,7 +156,6 @@ export function createStorybookViteConfig(
152
156
  "@tamagui/animations-css",
153
157
  "@tamagui/react-native-svg",
154
158
  "@tamagui/colors",
155
- "@tamagui/config",
156
159
  "@tamagui/config/v5",
157
160
  "@tamagui/constants",
158
161
  "@tamagui/font-inter",
@@ -161,7 +164,6 @@ export function createStorybookViteConfig(
161
164
  "@tamagui/input",
162
165
  "@tamagui/label",
163
166
  "@tamagui/linear-gradient",
164
- "@tamagui/lucide-icons-2",
165
167
  "@tamagui/popover",
166
168
  "@tamagui/portal",
167
169
  "@tamagui/roving-focus",
@@ -170,7 +172,6 @@ export function createStorybookViteConfig(
170
172
  "@tamagui/shorthands",
171
173
  "@tamagui/stacks",
172
174
  "@tamagui/text",
173
- "@tamagui/theme-builder",
174
175
  "@tamagui/themes",
175
176
  "@tamagui/toast",
176
177
  "@tamagui/use-presence",
@@ -207,6 +208,7 @@ export function createStorybookViteConfig(
207
208
  "use-sync-external-store/with-selector",
208
209
  "fast-deep-equal",
209
210
  "color",
211
+ "warn-once",
210
212
  // query-string v7 is CJS-only (require/exports), pulled in by
211
213
  // @react-navigation/core for URL parsing. Unlike the One app which
212
214
  // aliases it to @vxrn/query-string (ESM), Storybook has no such alias.
@@ -229,8 +231,17 @@ export function createStorybookViteConfig(
229
231
  "@react-navigation/bottom-tabs",
230
232
  "@react-navigation/native-stack",
231
233
  ],
234
+ rolldownOptions: nativeOnlyStubForOptimizer
235
+ ? { plugins: [nativeOnlyStubForOptimizer] }
236
+ : undefined,
232
237
  },
233
- plugins: [nodeAsyncHooksStub(), phosphorTokenColorPlugin(), ...(options.plugins || [])],
238
+ plugins: [
239
+ singletonResolvePlugin(workspaceRoot) as Plugin,
240
+ nodeAsyncHooksStub(),
241
+ phosphorTokenColorPlugin(),
242
+ ...(nativeOnlyStub ? [nativeOnlyStub] : []),
243
+ ...(options.plugins || []),
244
+ ],
234
245
  };
235
246
  }
236
247
 
@@ -1,11 +1,15 @@
1
1
  import fs from "node:fs";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
- import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
4
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
5
5
  import { createViteConfig } from "./vite.js";
6
6
 
7
7
  type NativePlugin = { name?: string; resolveId?: (id: string) => string | null };
8
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: NativePlugin[] };
8
+ function nativePlugins<T>(config: ReturnType<typeof createViteConfig>): T[] {
9
+ return (config.plugins as Array<{ api?: { vxrnNative?: () => T } } | undefined>)
10
+ .flat()
11
+ .flatMap((plugin) => (plugin?.api?.vxrnNative ? [plugin.api.vxrnNative()] : []));
12
+ }
9
13
 
10
14
  const cwd = process.cwd();
11
15
  let workspace: string;
@@ -17,8 +21,8 @@ function write(file: string, body: string, mtime?: Date) {
17
21
  if (mtime) fs.utimesSync(at, mtime, mtime);
18
22
  }
19
23
 
20
- function nativeEntries() {
21
- const plugins = (g.__vxrnAddNativePlugins ?? []).filter(
24
+ function nativeEntries(config: ReturnType<typeof createViteConfig>) {
25
+ const plugins = nativePlugins<NativePlugin>(config).filter(
22
26
  (plugin) => plugin.name === "vxrn-workspace-native-entries",
23
27
  );
24
28
  expect(plugins).toHaveLength(1);
@@ -52,47 +56,44 @@ afterAll(() => {
52
56
  fs.rmSync(workspace, { recursive: true, force: true });
53
57
  });
54
58
 
55
- beforeEach(() => {
56
- delete g.__vxrnAddNativePlugins;
57
- });
58
-
59
59
  describe("native workspace entries outside a git checkout", () => {
60
60
  it("finds the workspace by its pnpm-workspace.yaml and registers the resolver once", () => {
61
61
  createViteConfig({ one: true });
62
- createViteConfig({ one: true });
63
- nativeEntries();
62
+ nativeEntries(createViteConfig({ one: true }));
64
63
  });
65
64
 
66
65
  it("sends a bare workspace name to source when the package has no native build", () => {
67
- createViteConfig({ one: true });
68
- expect(nativeEntries()("@fixture/alpha")).toBe(
66
+ const config = createViteConfig({ one: true });
67
+ expect(nativeEntries(config)("@fixture/alpha")).toBe(
69
68
  path.join(workspace, "public/alpha/src/index.ts"),
70
69
  );
71
70
  });
72
71
 
73
72
  it("sends a resolved web dist entry to its current native sibling", () => {
74
- createViteConfig({ one: true });
75
- const resolve = nativeEntries();
73
+ const config = createViteConfig({ one: true });
74
+ const resolve = nativeEntries(config);
76
75
  const native = path.join(workspace, "public/beta/dist/esm/index.native.js");
77
76
  expect(resolve(path.join(workspace, "public/beta/dist/esm/index.mjs"))).toBe(native);
78
77
  expect(resolve("@fixture/beta")).toBe(native);
79
78
  });
80
79
 
81
80
  it("leaves a web dist entry alone when there is no native build", () => {
82
- createViteConfig({ one: true });
83
- expect(nativeEntries()(path.join(workspace, "public/gamma/dist/esm/index.mjs"))).toBeNull();
81
+ const config = createViteConfig({ one: true });
82
+ expect(
83
+ nativeEntries(config)(path.join(workspace, "public/gamma/dist/esm/index.mjs")),
84
+ ).toBeNull();
84
85
  });
85
86
 
86
87
  it("ignores ids that are neither a workspace name nor a workspace dist entry", () => {
87
- createViteConfig({ one: true });
88
- const resolve = nativeEntries();
88
+ const config = createViteConfig({ one: true });
89
+ const resolve = nativeEntries(config);
89
90
  expect(resolve("react")).toBeNull();
90
91
  expect(resolve(path.join(workspace, "missing/dist/esm/index.mjs"))).toBeNull();
91
92
  expect(resolve(path.join(workspace, "public/alpha/src/index.ts"))).toBeNull();
92
93
  });
93
94
 
94
95
  it("refuses a native build older than its source", () => {
95
- createViteConfig({ one: true });
96
- expect(() => nativeEntries()("@fixture/stale")).toThrow(/older than src[\\/]index\.ts/);
96
+ const config = createViteConfig({ one: true });
97
+ expect(() => nativeEntries(config)("@fixture/stale")).toThrow(/older than src[\\/]index\.ts/);
97
98
  });
98
99
  });
package/src/vite.spec.ts CHANGED
@@ -17,9 +17,11 @@ type NativePlugin = {
17
17
  renderChunk?: (code: string) => { code: string; map: null };
18
18
  };
19
19
 
20
- const globalWithNativePlugins = globalThis as unknown as {
21
- __vxrnAddNativePlugins?: NativePlugin[];
22
- };
20
+ function nativePlugins<T>(config: ReturnType<typeof createViteConfig>): T[] {
21
+ return (config.plugins as Array<{ api?: { vxrnNative?: () => T } } | undefined>)
22
+ .flat()
23
+ .flatMap((plugin) => (plugin?.api?.vxrnNative ? [plugin.api.vxrnNative()] : []));
24
+ }
23
25
 
24
26
  function findPlugin(config: ReturnType<typeof createViteConfig>, name: string): Plugin | undefined {
25
27
  return (config.plugins as Plugin[]).flat().find((p) => p && (p as Plugin).name === name) as
@@ -37,11 +39,6 @@ function runConfigResolved(
37
39
  return fakeConfig.ssr.external;
38
40
  }
39
41
 
40
- beforeEach(() => {
41
- // Native fix registration is global and deduped — reset between tests.
42
- delete globalWithNativePlugins.__vxrnAddNativePlugins;
43
- });
44
-
45
42
  describe("ssrCjsExternal", () => {
46
43
  it("appends the default CJS-only ids to ssr.external after one() replaces the list", () => {
47
44
  const config = createViteConfig({ one: true });
@@ -101,8 +98,7 @@ describe("ssrCjsExternal", () => {
101
98
 
102
99
  describe("nativeFixes.protoShadow", () => {
103
100
  it("registers the Hermes proto-shadow renderChunk fix by default", () => {
104
- createViteConfig({ one: true });
105
- const plugin = globalWithNativePlugins.__vxrnAddNativePlugins?.find(
101
+ const plugin = nativePlugins<NativePlugin>(createViteConfig({ one: true })).find(
106
102
  (p) => p.name === "vxrn-proto-shadow-fix",
107
103
  );
108
104
  expect(plugin).toBeDefined();
@@ -114,20 +110,18 @@ describe("nativeFixes.protoShadow", () => {
114
110
  });
115
111
 
116
112
  it("can be disabled with nativeFixes.protoShadow: false", () => {
117
- createViteConfig({ one: true, nativeFixes: { protoShadow: false } });
113
+ const config = createViteConfig({ one: true, nativeFixes: { protoShadow: false } });
118
114
  expect(
119
- globalWithNativePlugins.__vxrnAddNativePlugins?.some(
120
- (p) => p.name === "vxrn-proto-shadow-fix",
121
- ),
115
+ nativePlugins<NativePlugin>(config).some((p) => p.name === "vxrn-proto-shadow-fix"),
122
116
  ).toBeFalsy();
123
117
  });
124
118
  });
125
119
 
126
120
  describe("nativeFixes.web3Stub", () => {
127
121
  it("auto-skips when @multiplatform.one/web3 is installed (monorepo has it)", () => {
128
- createViteConfig({ one: true });
122
+ const config = createViteConfig({ one: true });
129
123
  expect(
130
- globalWithNativePlugins.__vxrnAddNativePlugins?.some((p) => p.name === "vxrn-web3-stub"),
124
+ nativePlugins<NativePlugin>(config).some((p) => p.name === "vxrn-web3-stub"),
131
125
  ).toBeFalsy();
132
126
  });
133
127
  });
@@ -138,12 +132,11 @@ describe("community Flow strip (FZ-7357)", () => {
138
132
  transform: (code: string, id: string) => Promise<{ code: string } | null>;
139
133
  };
140
134
  const strip = () =>
141
- globalWithNativePlugins.__vxrnAddNativePlugins?.find(
135
+ nativePlugins<NativePlugin>(createViteConfig({ one: true })).find(
142
136
  (p) => p.name === "vxrn-community-flow-strip",
143
137
  ) as unknown as FlowStrip | undefined;
144
138
 
145
139
  it("strips Flow from @react-native-community sources on native", async () => {
146
- createViteConfig({ one: true });
147
140
  const result = await strip()!.transform(
148
141
  "// @flow\nconst x: number = 1;\nexport default x;\n",
149
142
  "/app/node_modules/@react-native-community/datetimepicker/src/index.js",
@@ -153,7 +146,6 @@ describe("community Flow strip (FZ-7357)", () => {
153
146
  });
154
147
 
155
148
  it("strips Flow from @react-native-segmented-control sources on native (FZ-8486)", async () => {
156
- createViteConfig({ one: true });
157
149
  const result = await strip()!.transform(
158
150
  "// @flow\nimport type {Node} from 'react';\nconst x: number = 1;\nexport default x;\n",
159
151
  "/app/node_modules/@react-native-segmented-control/segmented-control/js/SegmentedControl.ios.js",
@@ -164,7 +156,6 @@ describe("community Flow strip (FZ-7357)", () => {
164
156
  });
165
157
 
166
158
  it("leaves every other package to vxrn", async () => {
167
- createViteConfig({ one: true });
168
159
  expect(
169
160
  await strip()!.transform("const x = 1;", "/app/node_modules/react-native-webview/index.js"),
170
161
  ).toBeNull();
package/src/vite.ts CHANGED
@@ -5,9 +5,10 @@ import {
5
5
  discoverPublicPackageRoots,
6
6
  resolveWorkspaceNativeEntry,
7
7
  } from "./workspacePublicPackages.js";
8
- import { nativeBlockScopingPlugin, nativeBlockScopingPluginName } from "./nativeBlockScoping.js";
8
+ import { nativeBlockScopingPlugin } from "./nativeBlockScoping.js";
9
9
  import { phosphorTokenColorPlugin } from "./phosphorTokenColor.js";
10
- import { withSingletonDepAliases } from "./singletonDepAliases.js";
10
+ import { movedDepAliases } from "./movedDepAliases.js";
11
+ import { singletonResolvePlugin, withSingletonDepAliases } from "./singletonDepAliases.js";
11
12
  import { ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths.js";
12
13
  import {
13
14
  bakePublicConfig,
@@ -239,6 +240,7 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
239
240
  }
240
241
 
241
242
  const vitePlugins: UserConfig["plugins"] = [];
243
+ vitePlugins.push(singletonResolvePlugin(projectRoot) as Plugin);
242
244
  vitePlugins.push(preferBuiltWorkspaceEntryPlugin());
243
245
  vitePlugins.push(phosphorTokenColorPlugin());
244
246
  if (publicConfigFile) {
@@ -253,13 +255,13 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
253
255
  // react-native/index.js (which contains Flow-only syntax).
254
256
  vitePlugins.push(ssrReactNativeAliasPlugin());
255
257
  vitePlugins.push(clientBrokenEsmPlugin());
256
- // Register a native-only resolveId plugin through vxrn's __vxrnAddNativePlugins
258
+ // Register a native-only resolveId plugin through one's api.vxrnNative
257
259
  // hook (consumed in vxrn's getNativePlugins). vxrn's native rolldown resolver
258
260
  // does NOT honor engine.io-client's `browser` field, so its Node `.node`
259
261
  // transports (ws + xmlhttprequest-ssl) leak into Hermes and won't even compile.
260
262
  // This re-asserts the package's own browser redirect (-> browser transports that
261
263
  // use RN's global WebSocket/XMLHttpRequest) with NO node_modules patch.
262
- registerNativeEngineIoBrowserTransports();
264
+ vitePlugins.push(registerNativeEngineIoBrowserTransports());
263
265
  // A mixed pnpm install (hoisted root dirs + a leftover .pnpm store) puts
264
266
  // two byte-identical copies of react, react-native and 62 other packages
265
267
  // on disk, and which one an importer reaches depends only on where that
@@ -268,29 +270,29 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
268
270
  // other — "Cannot read property 'useContext' of null" on first render.
269
271
  // It delegates through `this.resolve`, so it canonicalizes whatever the
270
272
  // rest of the chain produces, wherever it sits in the plugin order.
271
- registerNativeSinglePackageInstances();
273
+ vitePlugins.push(registerNativeSinglePackageInstances());
272
274
  // preferBuiltWorkspaceEntryPlugin (web-only) hard-resolves every workspace
273
275
  // package to its `dist/esm/index.mjs` (WEB build), and that resolution reaches
274
276
  // the native graph too. This native-only resolveId sends each workspace
275
277
  // package to its `dist/esm/index.native.js` when that build is current, to
276
278
  // source when it was never built, and REFUSES a stale one (FZ-7844).
277
- registerNativeWorkspaceEntries();
279
+ vitePlugins.push(registerNativeWorkspaceEntries());
278
280
  // @phosphor-icons/react renders DOM <svg>/<path>, which redboxes Hermes
279
281
  // ("View config getter callback for component `path` must be a function").
280
282
  // phosphor-react-native@3 ships the SAME *Icon-suffixed export names on
281
283
  // react-native-svg, so source keeps importing @phosphor-icons/react and
282
284
  // native transparently gets the RN implementation.
283
- registerNativePhosphorIcons();
285
+ vitePlugins.push(registerNativePhosphorIcons());
284
286
  // Hermes V1 hoisted-var Object.prototype shadow fix (see the nativeFixes
285
287
  // option docs). Every rolldown classic-script native bundle is exposed.
286
- if (nativeFixes?.protoShadow !== false) registerNativeProtoShadowFix();
288
+ if (nativeFixes?.protoShadow !== false) vitePlugins.push(registerNativeProtoShadowFix());
287
289
  // Optional-web3 stub for apps that don't install @multiplatform.one/web3
288
290
  // (auto-skipped when the package resolves).
289
- if (nativeFixes?.web3Stub !== false) registerNativeWeb3Stub();
290
- if (nativeFixes?.blockScoping !== false) registerNativeBlockScoping();
291
+ if (nativeFixes?.web3Stub !== false) vitePlugins.push(registerNativeWeb3Stub());
292
+ if (nativeFixes?.blockScoping !== false) vitePlugins.push(registerNativeBlockScoping());
291
293
  // @react-native-community/datetimepicker (an optional peer of forms and
292
294
  // frappe-ui) ships Flow source vxrn never strips (FZ-7357).
293
- registerNativeCommunityFlowStrip();
295
+ vitePlugins.push(registerNativeCommunityFlowStrip());
294
296
  // CJS-only ids must land on ssr.external AFTER the one() plugin replaces
295
297
  // the list during config — configResolved runs last, so the appends stick.
296
298
  if (ssrCjsExternal !== false) {
@@ -308,14 +310,6 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
308
310
  components: tamaguiOpts.components || lookupTamaguiModules([process.cwd()]),
309
311
  config: tamaguiOpts.config || "./config/tamagui.config.ts",
310
312
  outputCSS: tamaguiOpts.outputCSS || "./public/tamagui.css",
311
- // Prevents the config file watcher from re-evaluating the Tamagui
312
- // config in the main process when the Piscina worker writes changes
313
- // to .tamagui/. Without this, the watcher triggers bundleConfig →
314
- // import() → createTamagui() on a raw @tamagui/web instance that
315
- // conflicts with the SSR module runner's pre-bundled instance.
316
- // See also: patches/@tamagui__static (forces CJS config bundles in
317
- // the worker to avoid ESM/CJS dual-instance globalThis conflicts).
318
- disableWatchTamaguiConfig: true,
319
313
  }),
320
314
  );
321
315
  }
@@ -521,6 +515,7 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
521
515
  // Do NOT alias it here — Vite's prefix-match aliases catch subpaths
522
516
  // like /shim/with-selector.js and /with-selector, rewriting them to
523
517
  // react/with-selector which doesn't exist, crashing dep optimisation.
518
+ ...movedDepAliases(projectRoot),
524
519
  },
525
520
  projectRoot,
526
521
  ),
@@ -633,9 +628,19 @@ function clientBrokenEsmPlugin(): Plugin {
633
628
  };
634
629
  }
635
630
 
631
+ /**
632
+ * A rolldown plugin for the native bundle only. one 2.x hands every vite
633
+ * plugin that carries `api.vxrnNative` to vxrn's native rolldown pipeline, in
634
+ * dev and in the native export; the vite plugin is a hookless shell under its
635
+ * own name, so web and SSR never run or list the native plugin.
636
+ */
637
+ export function nativeOnlyPlugin<T extends { name: string }>(plugin: T): Plugin {
638
+ return { name: `mpo-native:${plugin.name}`, api: { vxrnNative: () => plugin } };
639
+ }
640
+
636
641
  /**
637
642
  * Adds engine.io-client's `browser`-field transport redirect to vxrn's NATIVE
638
- * rolldown pipeline via its `globalThis.__vxrnAddNativePlugins` hook.
643
+ * rolldown pipeline via one's `api.vxrnNative` hook.
639
644
  *
640
645
  * socket.io-client -> engine.io-client/index.js statically imports its Node
641
646
  * transports (`./globals.node.js`, `./transports/{websocket,polling-xhr}.node.js`),
@@ -646,7 +651,7 @@ function clientBrokenEsmPlugin(): Plugin {
646
651
  * `WebSocket` / `XMLHttpRequest` React Native provides — but vxrn's native
647
652
  * resolver omits the `browser` aliasField (and its rolldown binding doesn't even
648
653
  * support `aliasFields`). vxrn's native dev engine ignores the Vite config's
649
- * `resolve.alias`/`resolveId` too — BUT it DOES read `globalThis.__vxrnAddNativePlugins`
654
+ * `resolve.alias`/`resolveId` too — BUT it DOES take one's `api.vxrnNative` plugins
650
655
  * inside `getNativePlugins`, so a `resolveId` registered there runs on native.
651
656
  * This re-asserts the browser redirect with no node_modules patch. Web is
652
657
  * unaffected (engine.io is SSR-externalized and the web client already maps `browser`).
@@ -690,11 +695,8 @@ function clientBrokenEsmPlugin(): Plugin {
690
695
  * BARE specifiers are inspected — once a package's entry is canonical, its own
691
696
  * relative imports resolve inside the canonical copy for free.
692
697
  */
693
- function registerNativeSinglePackageInstances(): void {
694
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
698
+ function registerNativeSinglePackageInstances(): Plugin {
695
699
  const name = "vxrn-single-package-instances";
696
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
697
- if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
698
700
 
699
701
  const rootModules = path.join(findProjectRoot(), "node_modules");
700
702
  // <...>/node_modules/.pnpm/<pkg>@<ver>_<peerhash>/node_modules/<name>[/<rest>]
@@ -736,7 +738,7 @@ function registerNativeSinglePackageInstances(): void {
736
738
 
737
739
  const seen = new Map<string, string | null>();
738
740
 
739
- g.__vxrnAddNativePlugins.push({
741
+ return nativeOnlyPlugin({
740
742
  name,
741
743
  async resolveId(
742
744
  this: {
@@ -779,12 +781,9 @@ function registerNativeSinglePackageInstances(): void {
779
781
  });
780
782
  }
781
783
 
782
- function registerNativeEngineIoBrowserTransports(): void {
783
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
784
+ function registerNativeEngineIoBrowserTransports(): Plugin {
784
785
  const name = "vxrn-engineio-browser-transports";
785
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
786
- if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
787
- g.__vxrnAddNativePlugins.push({
786
+ return nativeOnlyPlugin({
788
787
  name,
789
788
  async resolveId(
790
789
  this: { resolve: (id: string, importer: string, opts: { skipSelf: boolean }) => unknown },
@@ -805,7 +804,7 @@ function registerNativeEngineIoBrowserTransports(): void {
805
804
 
806
805
  /**
807
806
  * Routes workspace (`@multiplatform.one/*`) packages to their native entry on
808
- * NATIVE, via vxrn's `globalThis.__vxrnAddNativePlugins` hook.
807
+ * NATIVE, via one's `api.vxrnNative` hook.
809
808
  *
810
809
  * Why this is needed: `preferBuiltWorkspaceEntryPlugin` (a Vite plugin, web/SSR only)
811
810
  * hard-resolves every workspace bare specifier to `<root>/dist/esm/index.mjs` — the WEB
@@ -821,11 +820,8 @@ function registerNativeEngineIoBrowserTransports(): void {
821
820
  * dist is older than the source (FZ-7844: a stale components dist shipped `TabBar = void 0`).
822
821
  * Web/SSR are unaffected (this plugin runs ONLY on native).
823
822
  */
824
- function registerNativeWorkspaceEntries(): void {
825
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
823
+ function registerNativeWorkspaceEntries(): Plugin {
826
824
  const name = "vxrn-workspace-native-entries";
827
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
828
- if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
829
825
  let roots: Map<string, string>;
830
826
  try {
831
827
  roots = discoverPublicPackageRoots(findProjectRoot());
@@ -856,7 +852,7 @@ function registerNativeWorkspaceEntries(): void {
856
852
  if (!entries.has(root)) entries.set(root, resolveWorkspaceNativeEntry(root) ?? null);
857
853
  return entries.get(root) as string | null;
858
854
  };
859
- g.__vxrnAddNativePlugins.push({
855
+ return nativeOnlyPlugin({
860
856
  name,
861
857
  resolveId(id: string): string | null {
862
858
  // (a) bare workspace specifier (e.g. "@multiplatform.one/rich-text")
@@ -938,33 +934,22 @@ function requiresReact(id: string): boolean {
938
934
  * Object.prototype method back over an undefined shadowing own-property
939
935
  * before any module code runs — the shadowed vars are reassigned by their
940
936
  * own modules on init, so this only bridges the parse-to-init window.
941
- * Registered through globalThis.__vxrnAddNativePlugins (vxrn's native engine
937
+ * Registered through one's api.vxrnNative hook (vxrn's native engine
942
938
  * ignores vite resolve/config). Web/SSR bundles are ESM (module-scoped vars)
943
939
  * and unaffected.
944
940
  */
945
- function registerNativeBlockScoping(): void {
946
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
947
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
948
- if (
949
- g.__vxrnAddNativePlugins.some(
950
- (p) => (p as { name?: string })?.name === nativeBlockScopingPluginName,
951
- )
952
- )
953
- return;
954
- g.__vxrnAddNativePlugins.push(nativeBlockScopingPlugin());
941
+ function registerNativeBlockScoping(): Plugin {
942
+ return nativeOnlyPlugin(nativeBlockScopingPlugin());
955
943
  }
956
944
 
957
- function registerNativeProtoShadowFix(): void {
958
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
945
+ function registerNativeProtoShadowFix(): Plugin {
959
946
  const name = "vxrn-proto-shadow-fix";
960
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
961
- if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
962
947
  const snippet =
963
948
  `(function(){var p=Object.prototype,h=p.hasOwnProperty,ns=Object.getOwnPropertyNames(p);` +
964
949
  `for(var i=0;i<ns.length;i++){var k=ns[i];` +
965
950
  `if(typeof p[k]==="function"&&globalThis[k]===void 0&&h.call(globalThis,k)){` +
966
951
  `try{globalThis[k]=p[k]}catch(e){}}}})();`;
967
- g.__vxrnAddNativePlugins.push({
952
+ return nativeOnlyPlugin({
968
953
  name,
969
954
  renderChunk(code: string) {
970
955
  return { code: `${snippet}\n${code}`, map: null };
@@ -985,12 +970,9 @@ function registerNativeProtoShadowFix(): void {
985
970
  * mechanism as vxrn's own plugin (fast-flow-transform), scoped to those
986
971
  * packages, so a consumer app needs no plugin of its own (FZ-7357).
987
972
  */
988
- function registerNativeCommunityFlowStrip(): void {
989
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
973
+ function registerNativeCommunityFlowStrip(): Plugin {
990
974
  const name = "vxrn-community-flow-strip";
991
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
992
- if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
993
- g.__vxrnAddNativePlugins.push({
975
+ return nativeOnlyPlugin({
994
976
  name,
995
977
  async transform(code: string, id: string) {
996
978
  if (!/node_modules[\\/]@react-native-(community|segmented-control)[\\/].*\.jsx?$/.test(id))
@@ -1022,11 +1004,8 @@ function registerNativeCommunityFlowStrip(): void {
1022
1004
  * the root _layout route. Web/SSR resolve the same specifier through vite's
1023
1005
  * normal pipeline and are unaffected.
1024
1006
  */
1025
- function registerNativeWeb3Stub(): void {
1026
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
1007
+ function registerNativeWeb3Stub(): Plugin | undefined {
1027
1008
  const name = "vxrn-web3-stub";
1028
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
1029
- if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
1030
1009
  try {
1031
1010
  // web3 installed — its real native entry resolves; no stub needed.
1032
1011
  require.resolve("@multiplatform.one/web3", { paths: [findProjectRoot(), process.cwd()] });
@@ -1044,7 +1023,7 @@ function registerNativeWeb3Stub(): void {
1044
1023
  path.resolve(here, "../src/shims/web3Stub.native.js"),
1045
1024
  ].find((candidate) => fs.existsSync(candidate));
1046
1025
  if (!shim) return;
1047
- g.__vxrnAddNativePlugins.push({
1026
+ return nativeOnlyPlugin({
1048
1027
  name,
1049
1028
  resolveId(id: string) {
1050
1029
  if (id === "@multiplatform.one/web3/native" || id === "@multiplatform.one/web3") {
@@ -1078,11 +1057,8 @@ function findProjectRoot(): string {
1078
1057
  * so app/library source needs no platform splits. Skipped (with a warning)
1079
1058
  * when phosphor-react-native isn't installed in the consuming project.
1080
1059
  */
1081
- function registerNativePhosphorIcons(): void {
1082
- const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
1060
+ function registerNativePhosphorIcons(): Plugin {
1083
1061
  const name = "vxrn-phosphor-native-icons";
1084
- g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
1085
- if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
1086
1062
  let nativeEntry: string | null = null;
1087
1063
  try {
1088
1064
  // The package's exports map doesn't expose "./package.json", so resolve
@@ -1100,7 +1076,7 @@ function registerNativePhosphorIcons(): void {
1100
1076
  nativeEntry = null;
1101
1077
  }
1102
1078
  const iconBase = nativeEntry ? phosphorNativeIconBase(nativeEntry) : null;
1103
- g.__vxrnAddNativePlugins.push({
1079
+ return nativeOnlyPlugin({
1104
1080
  name,
1105
1081
  resolveId(id: string, importer?: string): string | null {
1106
1082
  if (iconBase) {