@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
package/src/vite.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { lookupTamaguiModules } from "@multiplatform.one/utils/dev";
|
|
3
|
+
import { lookupTamaguiModules, movedDepAliases } from "@multiplatform.one/utils/dev";
|
|
4
4
|
import {
|
|
5
5
|
discoverPublicPackageRoots,
|
|
6
6
|
resolveWorkspaceNativeEntry,
|
|
7
7
|
} from "./workspacePublicPackages.js";
|
|
8
|
-
import { nativeBlockScopingPlugin
|
|
8
|
+
import { nativeBlockScopingPlugin } from "./nativeBlockScoping.js";
|
|
9
9
|
import { phosphorTokenColorPlugin } from "./phosphorTokenColor.js";
|
|
10
|
-
import { withSingletonDepAliases } from "./singletonDepAliases.js";
|
|
10
|
+
import { singletonResolvePlugin, withSingletonDepAliases } from "./singletonDepAliases.js";
|
|
11
11
|
import { ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths.js";
|
|
12
12
|
import {
|
|
13
13
|
bakePublicConfig,
|
|
@@ -239,6 +239,7 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
const vitePlugins: UserConfig["plugins"] = [];
|
|
242
|
+
vitePlugins.push(singletonResolvePlugin(projectRoot) as Plugin);
|
|
242
243
|
vitePlugins.push(preferBuiltWorkspaceEntryPlugin());
|
|
243
244
|
vitePlugins.push(phosphorTokenColorPlugin());
|
|
244
245
|
if (publicConfigFile) {
|
|
@@ -253,13 +254,13 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
|
|
|
253
254
|
// react-native/index.js (which contains Flow-only syntax).
|
|
254
255
|
vitePlugins.push(ssrReactNativeAliasPlugin());
|
|
255
256
|
vitePlugins.push(clientBrokenEsmPlugin());
|
|
256
|
-
// Register a native-only resolveId plugin through
|
|
257
|
+
// Register a native-only resolveId plugin through one's api.vxrnNative
|
|
257
258
|
// hook (consumed in vxrn's getNativePlugins). vxrn's native rolldown resolver
|
|
258
259
|
// does NOT honor engine.io-client's `browser` field, so its Node `.node`
|
|
259
260
|
// transports (ws + xmlhttprequest-ssl) leak into Hermes and won't even compile.
|
|
260
261
|
// This re-asserts the package's own browser redirect (-> browser transports that
|
|
261
262
|
// use RN's global WebSocket/XMLHttpRequest) with NO node_modules patch.
|
|
262
|
-
registerNativeEngineIoBrowserTransports();
|
|
263
|
+
vitePlugins.push(registerNativeEngineIoBrowserTransports());
|
|
263
264
|
// A mixed pnpm install (hoisted root dirs + a leftover .pnpm store) puts
|
|
264
265
|
// two byte-identical copies of react, react-native and 62 other packages
|
|
265
266
|
// on disk, and which one an importer reaches depends only on where that
|
|
@@ -268,29 +269,29 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
|
|
|
268
269
|
// other — "Cannot read property 'useContext' of null" on first render.
|
|
269
270
|
// It delegates through `this.resolve`, so it canonicalizes whatever the
|
|
270
271
|
// rest of the chain produces, wherever it sits in the plugin order.
|
|
271
|
-
registerNativeSinglePackageInstances();
|
|
272
|
+
vitePlugins.push(registerNativeSinglePackageInstances());
|
|
272
273
|
// preferBuiltWorkspaceEntryPlugin (web-only) hard-resolves every workspace
|
|
273
274
|
// package to its `dist/esm/index.mjs` (WEB build), and that resolution reaches
|
|
274
275
|
// the native graph too. This native-only resolveId sends each workspace
|
|
275
276
|
// package to its `dist/esm/index.native.js` when that build is current, to
|
|
276
277
|
// source when it was never built, and REFUSES a stale one (FZ-7844).
|
|
277
|
-
registerNativeWorkspaceEntries();
|
|
278
|
+
vitePlugins.push(registerNativeWorkspaceEntries());
|
|
278
279
|
// @phosphor-icons/react renders DOM <svg>/<path>, which redboxes Hermes
|
|
279
280
|
// ("View config getter callback for component `path` must be a function").
|
|
280
281
|
// phosphor-react-native@3 ships the SAME *Icon-suffixed export names on
|
|
281
282
|
// react-native-svg, so source keeps importing @phosphor-icons/react and
|
|
282
283
|
// native transparently gets the RN implementation.
|
|
283
|
-
registerNativePhosphorIcons();
|
|
284
|
+
vitePlugins.push(registerNativePhosphorIcons());
|
|
284
285
|
// Hermes V1 hoisted-var Object.prototype shadow fix (see the nativeFixes
|
|
285
286
|
// option docs). Every rolldown classic-script native bundle is exposed.
|
|
286
|
-
if (nativeFixes?.protoShadow !== false) registerNativeProtoShadowFix();
|
|
287
|
+
if (nativeFixes?.protoShadow !== false) vitePlugins.push(registerNativeProtoShadowFix());
|
|
287
288
|
// Optional-web3 stub for apps that don't install @multiplatform.one/web3
|
|
288
289
|
// (auto-skipped when the package resolves).
|
|
289
|
-
if (nativeFixes?.web3Stub !== false) registerNativeWeb3Stub();
|
|
290
|
-
if (nativeFixes?.blockScoping !== false) registerNativeBlockScoping();
|
|
290
|
+
if (nativeFixes?.web3Stub !== false) vitePlugins.push(registerNativeWeb3Stub());
|
|
291
|
+
if (nativeFixes?.blockScoping !== false) vitePlugins.push(registerNativeBlockScoping());
|
|
291
292
|
// @react-native-community/datetimepicker (an optional peer of forms and
|
|
292
293
|
// frappe-ui) ships Flow source vxrn never strips (FZ-7357).
|
|
293
|
-
registerNativeCommunityFlowStrip();
|
|
294
|
+
vitePlugins.push(registerNativeCommunityFlowStrip());
|
|
294
295
|
// CJS-only ids must land on ssr.external AFTER the one() plugin replaces
|
|
295
296
|
// the list during config — configResolved runs last, so the appends stick.
|
|
296
297
|
if (ssrCjsExternal !== false) {
|
|
@@ -308,14 +309,6 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
|
|
|
308
309
|
components: tamaguiOpts.components || lookupTamaguiModules([process.cwd()]),
|
|
309
310
|
config: tamaguiOpts.config || "./config/tamagui.config.ts",
|
|
310
311
|
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
312
|
}),
|
|
320
313
|
);
|
|
321
314
|
}
|
|
@@ -521,6 +514,7 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
|
|
|
521
514
|
// Do NOT alias it here — Vite's prefix-match aliases catch subpaths
|
|
522
515
|
// like /shim/with-selector.js and /with-selector, rewriting them to
|
|
523
516
|
// react/with-selector which doesn't exist, crashing dep optimisation.
|
|
517
|
+
...movedDepAliases(projectRoot),
|
|
524
518
|
},
|
|
525
519
|
projectRoot,
|
|
526
520
|
),
|
|
@@ -633,9 +627,19 @@ function clientBrokenEsmPlugin(): Plugin {
|
|
|
633
627
|
};
|
|
634
628
|
}
|
|
635
629
|
|
|
630
|
+
/**
|
|
631
|
+
* A rolldown plugin for the native bundle only. one 2.x hands every vite
|
|
632
|
+
* plugin that carries `api.vxrnNative` to vxrn's native rolldown pipeline, in
|
|
633
|
+
* dev and in the native export; the vite plugin is a hookless shell under its
|
|
634
|
+
* own name, so web and SSR never run or list the native plugin.
|
|
635
|
+
*/
|
|
636
|
+
export function nativeOnlyPlugin<T extends { name: string }>(plugin: T): Plugin {
|
|
637
|
+
return { name: `mpo-native:${plugin.name}`, api: { vxrnNative: () => plugin } };
|
|
638
|
+
}
|
|
639
|
+
|
|
636
640
|
/**
|
|
637
641
|
* Adds engine.io-client's `browser`-field transport redirect to vxrn's NATIVE
|
|
638
|
-
* rolldown pipeline via
|
|
642
|
+
* rolldown pipeline via one's `api.vxrnNative` hook.
|
|
639
643
|
*
|
|
640
644
|
* socket.io-client -> engine.io-client/index.js statically imports its Node
|
|
641
645
|
* transports (`./globals.node.js`, `./transports/{websocket,polling-xhr}.node.js`),
|
|
@@ -646,7 +650,7 @@ function clientBrokenEsmPlugin(): Plugin {
|
|
|
646
650
|
* `WebSocket` / `XMLHttpRequest` React Native provides — but vxrn's native
|
|
647
651
|
* resolver omits the `browser` aliasField (and its rolldown binding doesn't even
|
|
648
652
|
* support `aliasFields`). vxrn's native dev engine ignores the Vite config's
|
|
649
|
-
* `resolve.alias`/`resolveId` too — BUT it DOES
|
|
653
|
+
* `resolve.alias`/`resolveId` too — BUT it DOES take one's `api.vxrnNative` plugins
|
|
650
654
|
* inside `getNativePlugins`, so a `resolveId` registered there runs on native.
|
|
651
655
|
* This re-asserts the browser redirect with no node_modules patch. Web is
|
|
652
656
|
* unaffected (engine.io is SSR-externalized and the web client already maps `browser`).
|
|
@@ -690,11 +694,8 @@ function clientBrokenEsmPlugin(): Plugin {
|
|
|
690
694
|
* BARE specifiers are inspected — once a package's entry is canonical, its own
|
|
691
695
|
* relative imports resolve inside the canonical copy for free.
|
|
692
696
|
*/
|
|
693
|
-
function registerNativeSinglePackageInstances():
|
|
694
|
-
const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
|
|
697
|
+
function registerNativeSinglePackageInstances(): Plugin {
|
|
695
698
|
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
699
|
|
|
699
700
|
const rootModules = path.join(findProjectRoot(), "node_modules");
|
|
700
701
|
// <...>/node_modules/.pnpm/<pkg>@<ver>_<peerhash>/node_modules/<name>[/<rest>]
|
|
@@ -736,7 +737,7 @@ function registerNativeSinglePackageInstances(): void {
|
|
|
736
737
|
|
|
737
738
|
const seen = new Map<string, string | null>();
|
|
738
739
|
|
|
739
|
-
|
|
740
|
+
return nativeOnlyPlugin({
|
|
740
741
|
name,
|
|
741
742
|
async resolveId(
|
|
742
743
|
this: {
|
|
@@ -779,12 +780,9 @@ function registerNativeSinglePackageInstances(): void {
|
|
|
779
780
|
});
|
|
780
781
|
}
|
|
781
782
|
|
|
782
|
-
function registerNativeEngineIoBrowserTransports():
|
|
783
|
-
const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
|
|
783
|
+
function registerNativeEngineIoBrowserTransports(): Plugin {
|
|
784
784
|
const name = "vxrn-engineio-browser-transports";
|
|
785
|
-
|
|
786
|
-
if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
|
|
787
|
-
g.__vxrnAddNativePlugins.push({
|
|
785
|
+
return nativeOnlyPlugin({
|
|
788
786
|
name,
|
|
789
787
|
async resolveId(
|
|
790
788
|
this: { resolve: (id: string, importer: string, opts: { skipSelf: boolean }) => unknown },
|
|
@@ -805,7 +803,7 @@ function registerNativeEngineIoBrowserTransports(): void {
|
|
|
805
803
|
|
|
806
804
|
/**
|
|
807
805
|
* Routes workspace (`@multiplatform.one/*`) packages to their native entry on
|
|
808
|
-
* NATIVE, via
|
|
806
|
+
* NATIVE, via one's `api.vxrnNative` hook.
|
|
809
807
|
*
|
|
810
808
|
* Why this is needed: `preferBuiltWorkspaceEntryPlugin` (a Vite plugin, web/SSR only)
|
|
811
809
|
* hard-resolves every workspace bare specifier to `<root>/dist/esm/index.mjs` — the WEB
|
|
@@ -821,11 +819,8 @@ function registerNativeEngineIoBrowserTransports(): void {
|
|
|
821
819
|
* dist is older than the source (FZ-7844: a stale components dist shipped `TabBar = void 0`).
|
|
822
820
|
* Web/SSR are unaffected (this plugin runs ONLY on native).
|
|
823
821
|
*/
|
|
824
|
-
function registerNativeWorkspaceEntries():
|
|
825
|
-
const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
|
|
822
|
+
function registerNativeWorkspaceEntries(): Plugin {
|
|
826
823
|
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
824
|
let roots: Map<string, string>;
|
|
830
825
|
try {
|
|
831
826
|
roots = discoverPublicPackageRoots(findProjectRoot());
|
|
@@ -856,7 +851,7 @@ function registerNativeWorkspaceEntries(): void {
|
|
|
856
851
|
if (!entries.has(root)) entries.set(root, resolveWorkspaceNativeEntry(root) ?? null);
|
|
857
852
|
return entries.get(root) as string | null;
|
|
858
853
|
};
|
|
859
|
-
|
|
854
|
+
return nativeOnlyPlugin({
|
|
860
855
|
name,
|
|
861
856
|
resolveId(id: string): string | null {
|
|
862
857
|
// (a) bare workspace specifier (e.g. "@multiplatform.one/rich-text")
|
|
@@ -938,33 +933,22 @@ function requiresReact(id: string): boolean {
|
|
|
938
933
|
* Object.prototype method back over an undefined shadowing own-property
|
|
939
934
|
* before any module code runs — the shadowed vars are reassigned by their
|
|
940
935
|
* own modules on init, so this only bridges the parse-to-init window.
|
|
941
|
-
* Registered through
|
|
936
|
+
* Registered through one's api.vxrnNative hook (vxrn's native engine
|
|
942
937
|
* ignores vite resolve/config). Web/SSR bundles are ESM (module-scoped vars)
|
|
943
938
|
* and unaffected.
|
|
944
939
|
*/
|
|
945
|
-
function registerNativeBlockScoping():
|
|
946
|
-
|
|
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());
|
|
940
|
+
function registerNativeBlockScoping(): Plugin {
|
|
941
|
+
return nativeOnlyPlugin(nativeBlockScopingPlugin());
|
|
955
942
|
}
|
|
956
943
|
|
|
957
|
-
function registerNativeProtoShadowFix():
|
|
958
|
-
const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
|
|
944
|
+
function registerNativeProtoShadowFix(): Plugin {
|
|
959
945
|
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
946
|
const snippet =
|
|
963
947
|
`(function(){var p=Object.prototype,h=p.hasOwnProperty,ns=Object.getOwnPropertyNames(p);` +
|
|
964
948
|
`for(var i=0;i<ns.length;i++){var k=ns[i];` +
|
|
965
949
|
`if(typeof p[k]==="function"&&globalThis[k]===void 0&&h.call(globalThis,k)){` +
|
|
966
950
|
`try{globalThis[k]=p[k]}catch(e){}}}})();`;
|
|
967
|
-
|
|
951
|
+
return nativeOnlyPlugin({
|
|
968
952
|
name,
|
|
969
953
|
renderChunk(code: string) {
|
|
970
954
|
return { code: `${snippet}\n${code}`, map: null };
|
|
@@ -985,12 +969,9 @@ function registerNativeProtoShadowFix(): void {
|
|
|
985
969
|
* mechanism as vxrn's own plugin (fast-flow-transform), scoped to those
|
|
986
970
|
* packages, so a consumer app needs no plugin of its own (FZ-7357).
|
|
987
971
|
*/
|
|
988
|
-
function registerNativeCommunityFlowStrip():
|
|
989
|
-
const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
|
|
972
|
+
function registerNativeCommunityFlowStrip(): Plugin {
|
|
990
973
|
const name = "vxrn-community-flow-strip";
|
|
991
|
-
|
|
992
|
-
if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
|
|
993
|
-
g.__vxrnAddNativePlugins.push({
|
|
974
|
+
return nativeOnlyPlugin({
|
|
994
975
|
name,
|
|
995
976
|
async transform(code: string, id: string) {
|
|
996
977
|
if (!/node_modules[\\/]@react-native-(community|segmented-control)[\\/].*\.jsx?$/.test(id))
|
|
@@ -1022,11 +1003,8 @@ function registerNativeCommunityFlowStrip(): void {
|
|
|
1022
1003
|
* the root _layout route. Web/SSR resolve the same specifier through vite's
|
|
1023
1004
|
* normal pipeline and are unaffected.
|
|
1024
1005
|
*/
|
|
1025
|
-
function registerNativeWeb3Stub():
|
|
1026
|
-
const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
|
|
1006
|
+
function registerNativeWeb3Stub(): Plugin | undefined {
|
|
1027
1007
|
const name = "vxrn-web3-stub";
|
|
1028
|
-
g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
|
|
1029
|
-
if (g.__vxrnAddNativePlugins.some((p) => (p as { name?: string })?.name === name)) return;
|
|
1030
1008
|
try {
|
|
1031
1009
|
// web3 installed — its real native entry resolves; no stub needed.
|
|
1032
1010
|
require.resolve("@multiplatform.one/web3", { paths: [findProjectRoot(), process.cwd()] });
|
|
@@ -1044,7 +1022,7 @@ function registerNativeWeb3Stub(): void {
|
|
|
1044
1022
|
path.resolve(here, "../src/shims/web3Stub.native.js"),
|
|
1045
1023
|
].find((candidate) => fs.existsSync(candidate));
|
|
1046
1024
|
if (!shim) return;
|
|
1047
|
-
|
|
1025
|
+
return nativeOnlyPlugin({
|
|
1048
1026
|
name,
|
|
1049
1027
|
resolveId(id: string) {
|
|
1050
1028
|
if (id === "@multiplatform.one/web3/native" || id === "@multiplatform.one/web3") {
|
|
@@ -1078,11 +1056,8 @@ function findProjectRoot(): string {
|
|
|
1078
1056
|
* so app/library source needs no platform splits. Skipped (with a warning)
|
|
1079
1057
|
* when phosphor-react-native isn't installed in the consuming project.
|
|
1080
1058
|
*/
|
|
1081
|
-
function registerNativePhosphorIcons():
|
|
1082
|
-
const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
|
|
1059
|
+
function registerNativePhosphorIcons(): Plugin {
|
|
1083
1060
|
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
1061
|
let nativeEntry: string | null = null;
|
|
1087
1062
|
try {
|
|
1088
1063
|
// The package's exports map doesn't expose "./package.json", so resolve
|
|
@@ -1100,7 +1075,7 @@ function registerNativePhosphorIcons(): void {
|
|
|
1100
1075
|
nativeEntry = null;
|
|
1101
1076
|
}
|
|
1102
1077
|
const iconBase = nativeEntry ? phosphorNativeIconBase(nativeEntry) : null;
|
|
1103
|
-
|
|
1078
|
+
return nativeOnlyPlugin({
|
|
1104
1079
|
name,
|
|
1105
1080
|
resolveId(id: string, importer?: string): string | null {
|
|
1106
1081
|
if (iconBase) {
|
package/src/vitest.spec.ts
CHANGED
|
@@ -20,9 +20,16 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
20
20
|
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
21
21
|
import type { ViteUserConfig } from "vitest/config";
|
|
22
22
|
import { createVitest, resolveConfig } from "vitest/node";
|
|
23
|
-
import { createServer, type ViteDevServer } from "vite";
|
|
23
|
+
import { createServer, resolveConfig as resolveViteConfig, type ViteDevServer } from "vite";
|
|
24
24
|
import { integrationConfig, integrationSpecs } from "./testTiers.js";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
createVitestConfig,
|
|
27
|
+
pinnedPackages,
|
|
28
|
+
tamaguiEvaluationConditions,
|
|
29
|
+
tamaguiEvaluationExternals,
|
|
30
|
+
tamaguiExtractedCss,
|
|
31
|
+
type PinnedPackagesPlugin,
|
|
32
|
+
} from "./vitest.js";
|
|
26
33
|
|
|
27
34
|
const fixtureDir = path.resolve(
|
|
28
35
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
@@ -92,7 +99,11 @@ describe("dedupeReact aliases", () => {
|
|
|
92
99
|
const componentsReactDom = path.join(componentsDir, "node_modules/react-dom");
|
|
93
100
|
|
|
94
101
|
function aliasMap() {
|
|
95
|
-
|
|
102
|
+
const plugins = (createVitestConfig({ tamaguiConfig: false }).plugins ?? []).flat() as Array<
|
|
103
|
+
PinnedPackagesPlugin | undefined
|
|
104
|
+
>;
|
|
105
|
+
const pinned = plugins.find((plugin) => plugin?.name === "mpo:pinned-packages");
|
|
106
|
+
return pinned?.api.pins ?? {};
|
|
96
107
|
}
|
|
97
108
|
|
|
98
109
|
it("binds react-dom/client and jsx-runtime to the same physical copies as the packages", () => {
|
|
@@ -155,6 +166,133 @@ describe("dedupeReact aliases", () => {
|
|
|
155
166
|
});
|
|
156
167
|
});
|
|
157
168
|
|
|
169
|
+
describe("Tamagui 3's config evaluation environment (FZ-10849)", () => {
|
|
170
|
+
let root: string;
|
|
171
|
+
|
|
172
|
+
beforeEach(() => {
|
|
173
|
+
root = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), "mpo-pins-"));
|
|
174
|
+
const pinnedReact = path.join(root, "pinned/react");
|
|
175
|
+
fs.mkdirSync(pinnedReact, { recursive: true });
|
|
176
|
+
fs.writeFileSync(
|
|
177
|
+
path.join(pinnedReact, "package.json"),
|
|
178
|
+
JSON.stringify({ name: "react", main: "index.js" }),
|
|
179
|
+
);
|
|
180
|
+
fs.writeFileSync(path.join(pinnedReact, "index.js"), "module.exports = {};\n");
|
|
181
|
+
fs.writeFileSync(path.join(pinnedReact, "jsx-runtime.js"), "module.exports = {};\n");
|
|
182
|
+
fs.writeFileSync(path.join(root, "entry.ts"), "");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
afterEach(() => {
|
|
186
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("pins react where specs render and leaves the evaluation environment to node", async () => {
|
|
190
|
+
const pinnedReact = path.join(root, "pinned/react");
|
|
191
|
+
const server = await createServer({
|
|
192
|
+
configFile: false,
|
|
193
|
+
logLevel: "silent",
|
|
194
|
+
root,
|
|
195
|
+
server: { middlewareMode: true },
|
|
196
|
+
plugins: [pinnedPackages({ react: pinnedReact })],
|
|
197
|
+
environments: { tamagui: { consumer: "server" } },
|
|
198
|
+
});
|
|
199
|
+
servers.push(server);
|
|
200
|
+
const importer = path.join(root, "entry.ts");
|
|
201
|
+
const inClient = await server.environments.client.pluginContainer.resolveId("react", importer);
|
|
202
|
+
const subpath = await server.environments.client.pluginContainer.resolveId(
|
|
203
|
+
"react/jsx-runtime",
|
|
204
|
+
importer,
|
|
205
|
+
);
|
|
206
|
+
const inEvaluation = await server.environments.tamagui.pluginContainer.resolveId(
|
|
207
|
+
"react",
|
|
208
|
+
importer,
|
|
209
|
+
);
|
|
210
|
+
expect(inClient?.id).toBe(path.join(pinnedReact, "index.js"));
|
|
211
|
+
expect(subpath?.id).toBe(path.join(pinnedReact, "jsx-runtime.js"));
|
|
212
|
+
expect(inEvaluation?.id ?? "").not.toContain(pinnedReact);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("gives the evaluation environment back the externals vitest takes from it", async () => {
|
|
216
|
+
const config = await resolveViteConfig(
|
|
217
|
+
{
|
|
218
|
+
configFile: false,
|
|
219
|
+
logLevel: "silent",
|
|
220
|
+
root,
|
|
221
|
+
plugins: [
|
|
222
|
+
{
|
|
223
|
+
name: "tamagui-like",
|
|
224
|
+
config: () => ({ environments: { tamagui: { resolve: { noExternal: ["tamagui"] } } } }),
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "vitest-like",
|
|
228
|
+
configEnvironment: {
|
|
229
|
+
order: "post",
|
|
230
|
+
handler(_name, environment) {
|
|
231
|
+
environment.resolve ??= {};
|
|
232
|
+
environment.resolve.noExternal = true;
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
tamaguiEvaluationExternals(),
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
"serve",
|
|
240
|
+
);
|
|
241
|
+
expect(config.environments.tamagui.resolve.noExternal).toEqual(["tamagui"]);
|
|
242
|
+
expect(config.environments.client.resolve.noExternal).toBe(true);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("resolves the evaluation environment with the specs' conditions beside the plugin's", async () => {
|
|
246
|
+
const config = await resolveViteConfig(
|
|
247
|
+
{
|
|
248
|
+
configFile: false,
|
|
249
|
+
logLevel: "silent",
|
|
250
|
+
root,
|
|
251
|
+
plugins: [
|
|
252
|
+
{
|
|
253
|
+
name: "tamagui-like",
|
|
254
|
+
config: () => ({
|
|
255
|
+
environments: { tamagui: { resolve: { conditions: ["tamagui-compiler"] } } },
|
|
256
|
+
}),
|
|
257
|
+
},
|
|
258
|
+
tamaguiEvaluationConditions(["source", "test"]),
|
|
259
|
+
],
|
|
260
|
+
},
|
|
261
|
+
"serve",
|
|
262
|
+
);
|
|
263
|
+
expect(config.environments.tamagui.resolve.conditions).toEqual(
|
|
264
|
+
expect.arrayContaining(["tamagui-compiler", "source", "test"]),
|
|
265
|
+
);
|
|
266
|
+
expect(config.environments.client.resolve.conditions).not.toContain("source");
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("puts the restore beside the tamagui plugin and the pins beside the aliases", () => {
|
|
270
|
+
const names = (
|
|
271
|
+
(
|
|
272
|
+
(createVitestConfig({ tamaguiConfig: "./tests/tamagui.config.ts" }).plugins ??
|
|
273
|
+
[]) as unknown[]
|
|
274
|
+
).flat(Infinity) as Array<{ name?: string } | undefined>
|
|
275
|
+
).map((plugin) => plugin?.name);
|
|
276
|
+
expect(names).toContain("mpo:tamagui-evaluation-externals");
|
|
277
|
+
expect(names).toContain("mpo:pinned-packages");
|
|
278
|
+
const aliases = createVitestConfig({ tamaguiConfig: false }).resolve?.alias as Record<
|
|
279
|
+
string,
|
|
280
|
+
string
|
|
281
|
+
>;
|
|
282
|
+
expect(Object.keys(aliases)).not.toContain("react");
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("loads the compiler's extracted stylesheets only where the compiler runs", () => {
|
|
286
|
+
const cssOf = (tamaguiConfig: string | false) =>
|
|
287
|
+
(createVitestConfig({ tamaguiConfig, dedupeReact: false }) as ViteUserConfig).test?.css;
|
|
288
|
+
expect(cssOf("./tests/tamagui.config.ts")).toEqual({ include: [tamaguiExtractedCss] });
|
|
289
|
+
expect(cssOf(false)).toBeUndefined();
|
|
290
|
+
expect(tamaguiExtractedCss.test("/repo/src/Button.tsx.tamagui.css")).toBe(true);
|
|
291
|
+
expect(tamaguiExtractedCss.test("/repo/src/Button.tsx.tamagui.css?direct")).toBe(true);
|
|
292
|
+
expect(tamaguiExtractedCss.test("/repo/src/theme.css")).toBe(false);
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
158
296
|
describe("coverage for SonarQube (FZ-8866)", () => {
|
|
159
297
|
const coverageOf = () =>
|
|
160
298
|
(createVitestConfig({ tamaguiConfig: false, dedupeReact: false }) as ViteUserConfig).test
|
|
@@ -336,7 +474,7 @@ describe("test tiers by file name (FZ-10556)", () => {
|
|
|
336
474
|
let root: string;
|
|
337
475
|
|
|
338
476
|
beforeEach(() => {
|
|
339
|
-
root = fs.mkdtempSync(path.join(os.tmpdir(), "mpo-test-tiers-"));
|
|
477
|
+
root = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), "mpo-test-tiers-"));
|
|
340
478
|
for (const file of files) {
|
|
341
479
|
fs.mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
|
342
480
|
fs.writeFileSync(path.join(root, file), "");
|
package/src/vitest.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
5
5
|
import { resolvePathSync } from "mlly";
|
|
6
6
|
import { tamaguiPlugin } from "@tamagui/vite-plugin";
|
|
7
7
|
import react from "@vitejs/plugin-react";
|
|
8
|
-
import type { UserConfig } from "vite";
|
|
8
|
+
import type { Plugin, UserConfig } from "vite";
|
|
9
9
|
import { configDefaults } from "vitest/config";
|
|
10
10
|
import { phosphorBarrelBundlePlugin, phosphorTokenColorPlugin } from "./phosphorTokenColor.js";
|
|
11
11
|
import { ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths.js";
|
|
@@ -104,6 +104,96 @@ function pinNodeReactRequire(reactDir: string, reactDomDir: string, schedulerDir
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The Vite environment Tamagui 3's vite plugin evaluates the tamagui config in
|
|
109
|
+
* (`TAMAGUI_EVALUATION_ENVIRONMENT` in @tamagui/vite-plugin's loadTamagui.ts,
|
|
110
|
+
* not exported). It inlines only the Tamagui packages it has to and hands every
|
|
111
|
+
* other bare import, react above all, to node.
|
|
112
|
+
*/
|
|
113
|
+
const tamaguiEvaluationEnvironment = "tamagui";
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Vitest 4 sets `resolve.noExternal = true` on every Vite environment but its
|
|
117
|
+
* own runner's, Tamagui's evaluation environment included, so react's CJS
|
|
118
|
+
* entry gets inlined there and the run dies before collecting a spec with
|
|
119
|
+
* `module is not defined`. Put the plugin's own list back once vitest has had
|
|
120
|
+
* its say. The client and ssr environments vitest runs specs in keep vitest's.
|
|
121
|
+
*/
|
|
122
|
+
export function tamaguiEvaluationExternals(): Plugin {
|
|
123
|
+
let noExternal: unknown;
|
|
124
|
+
return {
|
|
125
|
+
name: "mpo:tamagui-evaluation-externals",
|
|
126
|
+
configEnvironment(name, config) {
|
|
127
|
+
if (name === tamaguiEvaluationEnvironment) noExternal = config.resolve?.noExternal;
|
|
128
|
+
},
|
|
129
|
+
configResolved(config) {
|
|
130
|
+
const environment = config.environments[tamaguiEvaluationEnvironment];
|
|
131
|
+
if (!environment || noExternal === undefined) return;
|
|
132
|
+
environment.resolve.noExternal = noExternal as typeof environment.resolve.noExternal;
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Tamagui 3 evaluates a package's tamagui config in its own environment, which
|
|
139
|
+
* resolves with Vite's default client conditions plus `tamagui-compiler` and
|
|
140
|
+
* none of MPO's. A config that imports a workspace package
|
|
141
|
+
* (`createDefaultThemeConfig` from @multiplatform.one/theme) then reaches for
|
|
142
|
+
* that package's unbuilt `dist/` and the run dies at startup with
|
|
143
|
+
* `Failed to resolve entry for package`. The plugin merges a user's
|
|
144
|
+
* `environments.tamagui` over its own, so this hands that environment the
|
|
145
|
+
* conditions the specs resolve with, `source` first among them.
|
|
146
|
+
*/
|
|
147
|
+
export function tamaguiEvaluationConditions(conditions: string[]): Plugin {
|
|
148
|
+
return {
|
|
149
|
+
name: "mpo:tamagui-evaluation-conditions",
|
|
150
|
+
config() {
|
|
151
|
+
return { environments: { [tamaguiEvaluationEnvironment]: { resolve: { conditions } } } };
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The virtual stylesheet Tamagui 3's compiler writes each module's extracted
|
|
158
|
+
* atomic rules to (`virtualExt` in @tamagui/vite-plugin's plugin.ts). Vitest
|
|
159
|
+
* drops every CSS module its `css.include` doesn't name, so without this an
|
|
160
|
+
* element the compiler flattened carries hashed classes with no rule behind
|
|
161
|
+
* them, while a runtime-styled sibling's rules sit in `#_tamagui-styles`.
|
|
162
|
+
* Naming it puts both kinds of rule in `document.styleSheets`, where
|
|
163
|
+
* `atomicStyle()` in @multiplatform.one/test-utils reads them.
|
|
164
|
+
*/
|
|
165
|
+
export const tamaguiExtractedCss = /\.tamagui\.css(?:\?|$)/;
|
|
166
|
+
|
|
167
|
+
export type PinnedPackagesPlugin = Plugin & { api: { pins: Record<string, string> } };
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* MPO-37's one-physical-copy pins as a resolver rather than `resolve.alias`.
|
|
171
|
+
* An alias applies in every environment, and in Tamagui's evaluation
|
|
172
|
+
* environment it turns `react` into a file path, which that environment
|
|
173
|
+
* inlines instead of handing to node. The pins only matter where specs render,
|
|
174
|
+
* so that environment resolves react the way node does.
|
|
175
|
+
*
|
|
176
|
+
* Matching is the alias's: a pin applies to its name and to any subpath under
|
|
177
|
+
* it, so `react/jsx-runtime` lands in the pinned react.
|
|
178
|
+
*/
|
|
179
|
+
export function pinnedPackages(pins: Record<string, string>): PinnedPackagesPlugin {
|
|
180
|
+
const names = Object.keys(pins).sort((a, b) => b.length - a.length);
|
|
181
|
+
return {
|
|
182
|
+
name: "mpo:pinned-packages",
|
|
183
|
+
enforce: "pre",
|
|
184
|
+
api: { pins },
|
|
185
|
+
async resolveId(source, importer, options) {
|
|
186
|
+
if (this.environment?.name === tamaguiEvaluationEnvironment) return null;
|
|
187
|
+
const name = names.find((pin) => source === pin || source.startsWith(`${pin}/`));
|
|
188
|
+
if (!name) return null;
|
|
189
|
+
return this.resolve(pins[name] + source.slice(name.length), importer, {
|
|
190
|
+
...options,
|
|
191
|
+
skipSelf: true,
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
107
197
|
export interface CreateVitestConfigOptions {
|
|
108
198
|
/**
|
|
109
199
|
* Path to the Tamagui config file for test environments.
|
|
@@ -263,6 +353,8 @@ export function createVitestConfig(options: CreateVitestConfigOptions = {}): Use
|
|
|
263
353
|
components: ["tamagui"],
|
|
264
354
|
config: tamaguiConfig,
|
|
265
355
|
} as any),
|
|
356
|
+
tamaguiEvaluationExternals(),
|
|
357
|
+
tamaguiEvaluationConditions(conditions),
|
|
266
358
|
);
|
|
267
359
|
}
|
|
268
360
|
|
|
@@ -308,14 +400,18 @@ export function createVitestConfig(options: CreateVitestConfigOptions = {}): Use
|
|
|
308
400
|
};
|
|
309
401
|
const reactDir = onePhysicalCopy("react");
|
|
310
402
|
const reactDomDir = onePhysicalCopy("react-dom");
|
|
311
|
-
resolveAliases.react = reactDir;
|
|
312
|
-
resolveAliases["react-dom"] = reactDomDir;
|
|
313
|
-
resolveAliases["react-dom/client"] = path.join(reactDomDir, "client");
|
|
314
|
-
resolveAliases["react-dom/server"] = path.join(reactDomDir, "server");
|
|
315
|
-
resolveAliases["react/jsx-runtime"] = path.join(reactDir, "jsx-runtime");
|
|
316
|
-
resolveAliases["react/jsx-dev-runtime"] = path.join(reactDir, "jsx-dev-runtime");
|
|
317
403
|
const schedulerDir = onePhysicalCopy("scheduler");
|
|
318
|
-
|
|
404
|
+
plugins.push(
|
|
405
|
+
pinnedPackages({
|
|
406
|
+
react: reactDir,
|
|
407
|
+
"react-dom": reactDomDir,
|
|
408
|
+
"react-dom/client": path.join(reactDomDir, "client"),
|
|
409
|
+
"react-dom/server": path.join(reactDomDir, "server"),
|
|
410
|
+
"react/jsx-runtime": path.join(reactDir, "jsx-runtime"),
|
|
411
|
+
"react/jsx-dev-runtime": path.join(reactDir, "jsx-dev-runtime"),
|
|
412
|
+
scheduler: schedulerDir,
|
|
413
|
+
}),
|
|
414
|
+
);
|
|
319
415
|
process.env.MPO_VITEST_REACT = reactDir;
|
|
320
416
|
process.env.MPO_VITEST_REACT_DOM = reactDomDir;
|
|
321
417
|
process.env.MPO_VITEST_SCHEDULER = schedulerDir;
|
|
@@ -326,6 +422,7 @@ export function createVitestConfig(options: CreateVitestConfigOptions = {}): Use
|
|
|
326
422
|
const testConfig: Record<string, unknown> = {
|
|
327
423
|
environment,
|
|
328
424
|
globals: true,
|
|
425
|
+
env: { IS_STATIC: "" },
|
|
329
426
|
setupFiles: dedupeReact ? [pinReactRequireSetup, ...resolvedSetupFiles] : resolvedSetupFiles,
|
|
330
427
|
testTimeout: positiveIntEnv("VITEST_TEST_TIMEOUT") ?? testTimeout,
|
|
331
428
|
...(positiveIntEnv("VITEST_MAX_WORKERS")
|
|
@@ -383,6 +480,7 @@ export function createVitestConfig(options: CreateVitestConfigOptions = {}): Use
|
|
|
383
480
|
if (include) testConfig.include = include;
|
|
384
481
|
testConfig.exclude = [...(exclude ?? configDefaults.exclude), ...integrationSpecs];
|
|
385
482
|
if (passWithNoTests) testConfig.passWithNoTests = true;
|
|
483
|
+
if (tamaguiConfig !== false) testConfig.css = { include: [tamaguiExtractedCss] };
|
|
386
484
|
|
|
387
485
|
return {
|
|
388
486
|
plugins,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phosphorTokenColor.d.ts","sourceRoot":"","sources":["../src/phosphorTokenColor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"phosphorTokenColor.d.ts","sourceRoot":"","sources":["../src/phosphorTokenColor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAqFnC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAgBjD;AAkDD;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,CAkBnD"}
|