@multiplatform.one/config 7.86.0 → 7.87.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 CHANGED
@@ -51,6 +51,7 @@ const svgPrimitives = new Set([
51
51
  "Use",
52
52
  ]);
53
53
  const svgRoots = new Set(["Svg", "Symbol"]);
54
+ const svgBridges = ["public/components/src/charts/svg"];
54
55
  // LC-261 NO-MIDDOT-JOIN: values strung together with a "·" (or a spaced "•")
55
56
  // instead of each value in its own element. A dot inside a word (Catalan
56
57
  // "l·l"), a list bullet and a masked "••••" are not joins.
@@ -451,8 +452,28 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
451
452
  importedFrom(node, (specifier) =>
452
453
  /^(?:@phosphor-icons\/react(?:\/.*)?|phosphor-react-native)$/.test(specifier),
453
454
  );
455
+ const svgBridge = (specifier) =>
456
+ specifier.startsWith(".") &&
457
+ svgBridges.some((bridge) =>
458
+ path.resolve(path.dirname(filename), specifier).endsWith(path.join(...bridge.split("/"))),
459
+ );
454
460
  const fromSvg = (node) =>
455
- importedFrom(node, (specifier) => /^(?:@tamagui\/)?react-native-svg$/.test(specifier));
461
+ importedFrom(
462
+ node,
463
+ (specifier) => /^(?:@tamagui\/)?react-native-svg$/.test(specifier) || svgBridge(specifier),
464
+ );
465
+ function forwardedProp(element, key) {
466
+ const attr = attribute(element, key);
467
+ const value =
468
+ attr?.initializer && ts.isJsxExpression(attr.initializer)
469
+ ? attr.initializer.expression
470
+ : undefined;
471
+ if (!value || !ts.isIdentifier(value)) return false;
472
+ const declaration = typeChecker().getSymbolAtLocation(value)?.valueDeclaration;
473
+ if (!declaration || !ts.isBindingElement(declaration)) return false;
474
+ if ((declaration.propertyName ?? declaration.name).getText(file) !== key) return false;
475
+ return ts.isParameter(declaration.parent.parent);
476
+ }
456
477
  function svgTag(tag, set) {
457
478
  if (ts.isIdentifier(tag) && /^[a-z]/.test(tag.text))
458
479
  return set.has(tag.text[0].toUpperCase() + tag.text.slice(1));
@@ -1028,7 +1049,12 @@ export function inspectDesign(source, filename, projectRoot = process.cwd(), opt
1028
1049
  `${tag} sets ${key}; a link's ink, weight and underline come from the theme (LC-181).`,
1029
1050
  );
1030
1051
  }
1031
- if (imageTag.test(tag) && !svgArtwork(element) && paintedBy(element, /^tintColor$/)) {
1052
+ if (
1053
+ imageTag.test(tag) &&
1054
+ !svgArtwork(element) &&
1055
+ paintedBy(element, /^tintColor$/) &&
1056
+ !forwardedProp(element, "tintColor")
1057
+ ) {
1032
1058
  const source = attribute(element, "source") ?? attribute(element, "src");
1033
1059
  if (!source?.initializer || !glyphSource.test(source.initializer.getText(file)))
1034
1060
  report(
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createViteConfig } from "./vite-W2LL_nGt.js";
1
+ import { t as createViteConfig } from "./vite-5O-fr2qj.js";
2
2
  import { i as phosphorTokenColorPlugin, n as tamaguiWorkspacePathsFile, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-DR3dud79.js";
3
3
  import { t as createStorybookViteConfig } from "./storybook-CfmAuOrU.js";
4
4
  import { createVitestConfig } from "./vitest.js";
@@ -12,6 +12,51 @@ import i18nextLoader from "vite-plugin-i18next-loader";
12
12
  //#region \0rolldown/runtime.js
13
13
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
14
14
 
15
+ //#endregion
16
+ //#region src/nativeBlockScoping.ts
17
+ /**
18
+ * Hermes compiles a loop's let/const into ONE binding unless it runs with
19
+ * -Xes6-block-scoping, so a closure created in a loop sees the last value
20
+ * (every DataTable filter chip removes the last filter, every FloatingPanel
21
+ * reference handler calls the last one). Metro avoids it by running
22
+ * @babel/plugin-transform-block-scoping over every module; vxrn's native
23
+ * build ships let/const as written. This lowers the whole production chunk
24
+ * once, after rolldown has flattened it (FZ-8895, from Pelt's FZ-8408 fix).
25
+ */
26
+ const nativeBlockScopingPluginName = "vxrn-native-block-scoping";
27
+ async function lowerBlockScoping(code, filename = "main.jsbundle") {
28
+ const [{ transformAsync }, { default: blockScoping }] = await Promise.all([import("@babel/core"), import("@babel/plugin-transform-block-scoping")]);
29
+ const result = await transformAsync(code, {
30
+ filename,
31
+ babelrc: false,
32
+ configFile: false,
33
+ sourceType: "unambiguous",
34
+ compact: false,
35
+ sourceMaps: true,
36
+ plugins: [blockScoping]
37
+ });
38
+ if (result?.code == null) throw new Error(`block scoping produced no code for ${filename}`);
39
+ return {
40
+ code: result.code,
41
+ map: result.map ?? null
42
+ };
43
+ }
44
+ /** vxrn's dev engine sets `experimental.devMode`; its production build does not. */
45
+ function nativeBlockScopingPlugin() {
46
+ let dev = false;
47
+ return {
48
+ name: nativeBlockScopingPluginName,
49
+ options(options) {
50
+ dev = Boolean(options?.experimental?.devMode);
51
+ return null;
52
+ },
53
+ async renderChunk(code, chunk) {
54
+ if (dev) return null;
55
+ return lowerBlockScoping(code, chunk.fileName);
56
+ }
57
+ };
58
+ }
59
+
15
60
  //#endregion
16
61
  //#region src/publicConfig.ts
17
62
  const bakedConfigEnvKey = "VITE_MP_CONFIG";
@@ -201,6 +246,7 @@ function createViteConfig(options = {}) {
201
246
  registerNativePhosphorIcons();
202
247
  if (nativeFixes?.protoShadow !== false) registerNativeProtoShadowFix();
203
248
  if (nativeFixes?.web3Stub !== false) registerNativeWeb3Stub();
249
+ if (nativeFixes?.blockScoping !== false) registerNativeBlockScoping();
204
250
  registerNativeCommunityFlowStrip();
205
251
  if (ssrCjsExternal !== false) vitePlugins.push(ssrCjsExternalFixPlugin([...DEFAULT_SSR_CJS_EXTERNAL, ...ssrCjsExternal ?? []]));
206
252
  }
@@ -632,6 +678,12 @@ function requiresReact(id) {
632
678
  * ignores vite resolve/config). Web/SSR bundles are ESM (module-scoped vars)
633
679
  * and unaffected.
634
680
  */
681
+ function registerNativeBlockScoping() {
682
+ const g = globalThis;
683
+ g.__vxrnAddNativePlugins = g.__vxrnAddNativePlugins ?? [];
684
+ if (g.__vxrnAddNativePlugins.some((p) => p?.name === "vxrn-native-block-scoping")) return;
685
+ g.__vxrnAddNativePlugins.push(nativeBlockScopingPlugin());
686
+ }
635
687
  function registerNativeProtoShadowFix() {
636
688
  const g = globalThis;
637
689
  const name = "vxrn-proto-shadow-fix";
package/lib/vite.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as readPublicConfigKeys, i as publicConfigPlugin, n as phosphorNativeIconBase, r as phosphorNativeIconBaseId, t as createViteConfig } from "./vite-W2LL_nGt.js";
1
+ import { a as readPublicConfigKeys, i as publicConfigPlugin, n as phosphorNativeIconBase, r as phosphorNativeIconBaseId, t as createViteConfig } from "./vite-5O-fr2qj.js";
2
2
  import { i as phosphorTokenColorPlugin } from "./tamaguiWorkspacePaths-DR3dud79.js";
3
3
  import { a as staleNativeDistSource, i as resolveWorkspaceNativeEntry, n as publicPackageViteSourceAliases, t as discoverPublicPackageRoots } from "./workspacePublicPackages-CodgZ6JU.js";
4
4
 
package/lib/vitest.js CHANGED
@@ -23,6 +23,16 @@ function resolveSetupFile(file, conditions) {
23
23
  }
24
24
  }
25
25
  /**
26
+ * A gate on a loaded box caps its workers and, only if specs still time out
27
+ * under that cap, lengthens the per-test timeout (FZ-7915). Unset, the package
28
+ * values stand, so CI keeps the defaults. Vitest 4.1 reads VITEST_MAX_WORKERS
29
+ * itself as well; naming it here keeps the cap if that ever moves.
30
+ */
31
+ function positiveIntEnv(name) {
32
+ const value = Number(process.env[name]);
33
+ return Number.isInteger(value) && value > 0 ? value : void 0;
34
+ }
35
+ /**
26
36
  * The coverage SonarQube reads (FZ-8866). With MPO_COVERAGE=1, CI's test-vitest
27
37
  * measures every run as lcov, even a failing one. Each vitest process writes
28
38
  * its own directory because a package can run twice, as components runs its
@@ -136,7 +146,8 @@ function createVitestConfig(options = {}) {
136
146
  environment,
137
147
  globals: true,
138
148
  setupFiles: dedupeReact ? [pinReactRequireSetup, ...resolvedSetupFiles] : resolvedSetupFiles,
139
- testTimeout,
149
+ testTimeout: positiveIntEnv("VITEST_TEST_TIMEOUT") ?? testTimeout,
150
+ ...positiveIntEnv("VITEST_MAX_WORKERS") ? { maxWorkers: positiveIntEnv("VITEST_MAX_WORKERS") } : null,
140
151
  coverage: {
141
152
  provider: "v8",
142
153
  reporter: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/config",
3
- "version": "7.86.0",
3
+ "version": "7.87.0",
4
4
  "description": "Shared build and test configuration presets for multiplatform.one",
5
5
  "keywords": [
6
6
  "config",
@@ -114,7 +114,11 @@
114
114
  "access": "public"
115
115
  },
116
116
  "dependencies": {
117
- "@multiplatform.one/utils": "^7.86.0",
117
+ "@babel/core": "^7.29.7",
118
+ "@babel/parser": "^7.29.9",
119
+ "@babel/plugin-transform-block-scoping": "^7.29.7",
120
+ "@babel/traverse": "^7.29.10",
121
+ "@multiplatform.one/utils": "^7.87.0",
118
122
  "@tamagui/vite-plugin": "2.7.6",
119
123
  "@vitejs/plugin-react": "^6.1.2",
120
124
  "dotenv": "^17.4.2",
@@ -127,6 +131,10 @@
127
131
  "vitest": "^4.1.12"
128
132
  },
129
133
  "devDependencies": {
134
+ "@babel/plugin-transform-react-jsx": "^7.29.7",
135
+ "@babel/plugin-transform-typescript": "^7.29.7",
136
+ "@babel/types": "^7.29.8",
137
+ "@types/babel__traverse": "^7.28.0",
130
138
  "tsdown": "^0.21.10"
131
139
  },
132
140
  "peerDependencies": {
@@ -0,0 +1,43 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ import { describe, expect, it } from "vitest";
4
+ import { findLoopClosures } from "./loopClosures";
5
+ import { lowerBlockScoping } from "./nativeBlockScoping";
6
+
7
+ const publicDir = fileURLToPath(new URL("../../", import.meta.url));
8
+
9
+ /** Sites FZ-8895 names, each a closure that escapes its loop iteration. */
10
+ const sites = [
11
+ { file: "table/src/components/DataTableFilterChips/index.tsx", binding: "filter" },
12
+ { file: "table/src/components/DataTableFilterChips/index.tsx", binding: "columnFilter" },
13
+ { file: "components/src/views/Kanban.native.tsx", binding: "handle" },
14
+ { file: "forms/src/FloatingPanel/index.tsx", binding: "handler" },
15
+ ];
16
+
17
+ /** The site as rolldown hands it to the native plugin: plain JS, then lowered. */
18
+ async function lowered(source: string, file: string): Promise<string> {
19
+ const { transformAsync } = await import("@babel/core");
20
+ const plain = await transformAsync(source, {
21
+ filename: file,
22
+ babelrc: false,
23
+ configFile: false,
24
+ plugins: [
25
+ ["@babel/plugin-transform-typescript", { isTSX: true }],
26
+ ["@babel/plugin-transform-react-jsx", { runtime: "automatic" }],
27
+ ],
28
+ });
29
+ return (await lowerBlockScoping(plain!.code!, file.replace(/\.tsx?$/, ".js"))).code;
30
+ }
31
+
32
+ describe("loop closures at the FZ-8895 sites", () => {
33
+ for (const { file, binding } of sites) {
34
+ it(`${file}: \`${binding}\` is shared under Hermes as written and per-iteration once lowered`, async () => {
35
+ const path = `${publicDir}${file}`;
36
+ const source = readFileSync(path, "utf8");
37
+ const asWritten = findLoopClosures(source, path).filter((hit) => hit.name === binding);
38
+ expect(asWritten.length).toBeGreaterThan(0);
39
+ const after = findLoopClosures(await lowered(source, path), "lowered.js");
40
+ expect(after.filter((hit) => hit.name === binding)).toEqual([]);
41
+ });
42
+ }
43
+ });
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Finds closures that capture a let/const binding declared inside a loop.
3
+ * Under Hermes without block scoping, each one sees only the last iteration's
4
+ * value (FZ-8895). Ported from Pelt's jsbundle gate (FZ-8408).
5
+ */
6
+ import { parse, type ParserPlugin } from "@babel/parser";
7
+ import traverseModule, { type Binding, type NodePath } from "@babel/traverse";
8
+ import type { Node } from "@babel/types";
9
+
10
+ const traverse = ((traverseModule as unknown as { default?: typeof traverseModule }).default ??
11
+ traverseModule) as typeof traverseModule;
12
+
13
+ export type LoopClosure = {
14
+ name: string;
15
+ kind: "let" | "const";
16
+ line: number;
17
+ column: number;
18
+ loopLine: number;
19
+ closureLine: number;
20
+ };
21
+
22
+ function enclosingLoop(path: NodePath): NodePath | null {
23
+ let current: NodePath | null = path;
24
+ while (current) {
25
+ if (current.isLoop()) return current;
26
+ if (current.isFunction() || current.isProgram() || current.isStaticBlock()) return null;
27
+ current = current.parentPath;
28
+ }
29
+ return null;
30
+ }
31
+
32
+ function closureBetween(use: NodePath, scopeBlock: Node): NodePath | null {
33
+ let closure: NodePath | null = null;
34
+ let current: NodePath | null = use.parentPath;
35
+ while (current && current.node !== scopeBlock) {
36
+ if (current.isFunction() || current.isClass()) closure = current;
37
+ current = current.parentPath;
38
+ }
39
+ return current ? closure : null;
40
+ }
41
+
42
+ function capturedInLoop(binding: Binding): LoopClosure | null {
43
+ if (binding.kind !== "let" && binding.kind !== "const") return null;
44
+ if (binding.path.isCatchClause()) return null;
45
+ const loop = enclosingLoop(binding.scope.path);
46
+ if (!loop) return null;
47
+ for (const use of [...binding.referencePaths, ...binding.constantViolations]) {
48
+ const closure = closureBetween(use, binding.scope.block);
49
+ if (!closure) continue;
50
+ const at = binding.identifier.loc?.start;
51
+ return {
52
+ name: binding.identifier.name,
53
+ kind: binding.kind,
54
+ line: at?.line ?? 0,
55
+ column: (at?.column ?? 0) + 1,
56
+ loopLine: loop.node.loc?.start.line ?? 0,
57
+ closureLine: closure.node.loc?.start.line ?? 0,
58
+ };
59
+ }
60
+ return null;
61
+ }
62
+
63
+ function parserPlugins(filename: string): ParserPlugin[] {
64
+ if (filename.endsWith(".tsx")) return ["typescript", "jsx"];
65
+ if (/\.[cm]?ts$/.test(filename)) return ["typescript"];
66
+ if (/\.[cm]?jsx?$/.test(filename)) return ["jsx", "flow"];
67
+ return [];
68
+ }
69
+
70
+ export function findLoopClosures(code: string, filename = "main.jsbundle"): LoopClosure[] {
71
+ const ast = parse(code, {
72
+ sourceType: "unambiguous",
73
+ sourceFilename: filename,
74
+ allowReturnOutsideFunction: true,
75
+ plugins: parserPlugins(filename),
76
+ });
77
+ const found: LoopClosure[] = [];
78
+ traverse(ast, {
79
+ Scopable(path) {
80
+ if (path.scope.block !== path.node) return;
81
+ for (const binding of Object.values(path.scope.bindings)) {
82
+ const hit = capturedInLoop(binding);
83
+ if (hit) found.push(hit);
84
+ }
85
+ },
86
+ });
87
+ return found.sort((a, b) => a.line - b.line || a.column - b.column);
88
+ }
@@ -0,0 +1,78 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+ import { createViteConfig } from "./vite";
3
+
4
+ interface NativePlugin {
5
+ name: string;
6
+ options?: (options: unknown) => unknown;
7
+ renderChunk?: (
8
+ code: string,
9
+ chunk: { fileName: string },
10
+ ) => Promise<{ code: string } | null> | { code: string } | null;
11
+ }
12
+
13
+ const nativeHook = globalThis as unknown as { __vxrnAddNativePlugins?: NativePlugin[] };
14
+
15
+ const fixture = `
16
+ function run() {
17
+ const fns = [];
18
+ for (const x of [1, 2, 3]) fns.push(() => x);
19
+ for (let i = 0; i < 3; i++) fns.push(() => i);
20
+ const handlers = {};
21
+ for (const key of ["a", "b"]) {
22
+ handlers[key] = () => key;
23
+ }
24
+ return fns.map((fn) => fn()).concat([handlers.a(), handlers.b()]);
25
+ }
26
+ `;
27
+
28
+ const perIteration = [1, 2, 3, 0, 1, 2, "a", "b"];
29
+
30
+ /** Hermes without -Xes6-block-scoping: every let/const binds once per function. */
31
+ function runFunctionScoped(code: string): unknown[] {
32
+ const functionScoped = code.replace(/\b(?:let|const)\s/g, "var ");
33
+ return new Function(`${functionScoped}\nreturn run();`)() as unknown[];
34
+ }
35
+
36
+ function blockScopingPlugin(): NativePlugin | undefined {
37
+ return nativeHook.__vxrnAddNativePlugins?.find((p) => p.name === "vxrn-native-block-scoping");
38
+ }
39
+
40
+ beforeEach(() => {
41
+ delete nativeHook.__vxrnAddNativePlugins;
42
+ });
43
+
44
+ describe("native block scoping (FZ-8895)", () => {
45
+ it("models the Hermes bug: a function-scoped run of the raw fixture sees only last values", () => {
46
+ expect(runFunctionScoped(fixture)).toEqual([3, 3, 3, 3, 3, 3, "b", "b"]);
47
+ });
48
+
49
+ it("lowers let/const in a production native chunk so loop closures keep per-iteration values", async () => {
50
+ createViteConfig({ one: true });
51
+ const plugin = blockScopingPlugin();
52
+ expect(plugin).toBeDefined();
53
+ plugin!.options?.({});
54
+ const result = await plugin!.renderChunk!(fixture, { fileName: "main.jsbundle" });
55
+ expect(result).not.toBeNull();
56
+ expect(runFunctionScoped(result!.code)).toEqual(perIteration);
57
+ });
58
+
59
+ it("leaves dev-engine chunks alone so Fast Refresh stays fast", async () => {
60
+ createViteConfig({ one: true });
61
+ const plugin = blockScopingPlugin()!;
62
+ plugin.options?.({ experimental: { devMode: { host: "localhost", port: 8081 } } });
63
+ expect(await plugin.renderChunk!(fixture, { fileName: "main.jsbundle" })).toBeNull();
64
+ });
65
+
66
+ it("never reaches the web or SSR plugin list", () => {
67
+ const config = createViteConfig({ one: true });
68
+ const names = (config.plugins as Array<{ name?: string } | undefined>)
69
+ .flat()
70
+ .map((p) => p?.name);
71
+ expect(names).not.toContain("vxrn-native-block-scoping");
72
+ });
73
+
74
+ it("can be turned off with nativeFixes.blockScoping: false", () => {
75
+ createViteConfig({ one: true, nativeFixes: { blockScoping: false } });
76
+ expect(blockScopingPlugin()).toBeUndefined();
77
+ });
78
+ });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Hermes compiles a loop's let/const into ONE binding unless it runs with
3
+ * -Xes6-block-scoping, so a closure created in a loop sees the last value
4
+ * (every DataTable filter chip removes the last filter, every FloatingPanel
5
+ * reference handler calls the last one). Metro avoids it by running
6
+ * @babel/plugin-transform-block-scoping over every module; vxrn's native
7
+ * build ships let/const as written. This lowers the whole production chunk
8
+ * once, after rolldown has flattened it (FZ-8895, from Pelt's FZ-8408 fix).
9
+ */
10
+ export const nativeBlockScopingPluginName = "vxrn-native-block-scoping";
11
+
12
+ export async function lowerBlockScoping(code: string, filename = "main.jsbundle") {
13
+ const [{ transformAsync }, { default: blockScoping }] = await Promise.all([
14
+ import("@babel/core"),
15
+ import("@babel/plugin-transform-block-scoping"),
16
+ ]);
17
+ const result = await transformAsync(code, {
18
+ filename,
19
+ babelrc: false,
20
+ configFile: false,
21
+ sourceType: "unambiguous",
22
+ compact: false,
23
+ sourceMaps: true,
24
+ plugins: [blockScoping],
25
+ });
26
+ if (result?.code == null) throw new Error(`block scoping produced no code for ${filename}`);
27
+ return { code: result.code, map: result.map ?? null };
28
+ }
29
+
30
+ interface NativeBuildOptions {
31
+ experimental?: { devMode?: unknown };
32
+ }
33
+
34
+ /** vxrn's dev engine sets `experimental.devMode`; its production build does not. */
35
+ export function nativeBlockScopingPlugin() {
36
+ let dev = false;
37
+ return {
38
+ name: nativeBlockScopingPluginName,
39
+ options(options: NativeBuildOptions) {
40
+ dev = Boolean(options?.experimental?.devMode);
41
+ return null;
42
+ },
43
+ async renderChunk(code: string, chunk: { fileName: string }) {
44
+ if (dev) return null;
45
+ return lowerBlockScoping(code, chunk.fileName);
46
+ },
47
+ };
48
+ }
package/src/vite.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  discoverPublicPackageRoots,
6
6
  resolveWorkspaceNativeEntry,
7
7
  } from "./workspacePublicPackages.js";
8
+ import { nativeBlockScopingPlugin, nativeBlockScopingPluginName } from "./nativeBlockScoping.js";
8
9
  import { phosphorTokenColorPlugin } from "./phosphorTokenColor.js";
9
10
  import { withSingletonDepAliases } from "./singletonDepAliases.js";
10
11
  import { ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths.js";
@@ -169,6 +170,12 @@ export interface CreateViteConfigOptions {
169
170
  * Auto-skipped when web3 is installed.
170
171
  */
171
172
  web3Stub?: boolean;
173
+ /**
174
+ * Lower let/const in the production native bundle with Babel's
175
+ * block-scoping transform. Hermes gives a loop's let/const one binding,
176
+ * so without it every closure made in a loop sees the last value.
177
+ */
178
+ blockScoping?: boolean;
172
179
  };
173
180
  }
174
181
 
@@ -280,6 +287,7 @@ export function createViteConfig(options: CreateViteConfigOptions = {}): UserCon
280
287
  // Optional-web3 stub for apps that don't install @multiplatform.one/web3
281
288
  // (auto-skipped when the package resolves).
282
289
  if (nativeFixes?.web3Stub !== false) registerNativeWeb3Stub();
290
+ if (nativeFixes?.blockScoping !== false) registerNativeBlockScoping();
283
291
  // @react-native-community/datetimepicker (an optional peer of forms and
284
292
  // frappe-ui) ships Flow source vxrn never strips (FZ-7357).
285
293
  registerNativeCommunityFlowStrip();
@@ -934,6 +942,18 @@ function requiresReact(id: string): boolean {
934
942
  * ignores vite resolve/config). Web/SSR bundles are ESM (module-scoped vars)
935
943
  * and unaffected.
936
944
  */
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());
955
+ }
956
+
937
957
  function registerNativeProtoShadowFix(): void {
938
958
  const g = globalThis as unknown as { __vxrnAddNativePlugins?: unknown[] };
939
959
  const name = "vxrn-proto-shadow-fix";
@@ -281,3 +281,41 @@ describe("setupFiles bare specifiers (FZ-8926)", () => {
281
281
  expect(() => configFor()).toThrow();
282
282
  });
283
283
  });
284
+
285
+ describe("gate load overrides (FZ-7915)", () => {
286
+ const testOf = (options: Parameters<typeof createVitestConfig>[0] = {}) =>
287
+ (createVitestConfig({ tamaguiConfig: false, dedupeReact: false, ...options }) as ViteUserConfig)
288
+ .test;
289
+
290
+ it("keeps the package's timeout and sets no worker cap when neither is set", () => {
291
+ vi.stubEnv("VITEST_TEST_TIMEOUT", "");
292
+ vi.stubEnv("VITEST_MAX_WORKERS", "");
293
+ expect(testOf()?.testTimeout).toBe(30000);
294
+ expect(testOf({ testTimeout: 60000 })?.testTimeout).toBe(60000);
295
+ expect(testOf()).not.toHaveProperty("maxWorkers");
296
+ vi.unstubAllEnvs();
297
+ });
298
+
299
+ it("takes a gate's longer timeout over the package's", () => {
300
+ vi.stubEnv("VITEST_TEST_TIMEOUT", "90000");
301
+ expect(testOf()?.testTimeout).toBe(90000);
302
+ expect(testOf({ testTimeout: 60000 })?.testTimeout).toBe(90000);
303
+ vi.unstubAllEnvs();
304
+ });
305
+
306
+ it("caps the workers a gate names", () => {
307
+ vi.stubEnv("VITEST_MAX_WORKERS", "2");
308
+ expect(testOf()?.maxWorkers).toBe(2);
309
+ vi.unstubAllEnvs();
310
+ });
311
+
312
+ it("ignores a value that is not a positive whole number", () => {
313
+ for (const bad of ["0", "-1", "1.5", "abc"]) {
314
+ vi.stubEnv("VITEST_TEST_TIMEOUT", bad);
315
+ vi.stubEnv("VITEST_MAX_WORKERS", bad);
316
+ expect(testOf()?.testTimeout).toBe(30000);
317
+ expect(testOf()).not.toHaveProperty("maxWorkers");
318
+ }
319
+ vi.unstubAllEnvs();
320
+ });
321
+ });
package/src/vitest.ts CHANGED
@@ -29,6 +29,17 @@ function resolveSetupFile(file: string, conditions: string[]): string {
29
29
  }
30
30
  }
31
31
 
32
+ /**
33
+ * A gate on a loaded box caps its workers and, only if specs still time out
34
+ * under that cap, lengthens the per-test timeout (FZ-7915). Unset, the package
35
+ * values stand, so CI keeps the defaults. Vitest 4.1 reads VITEST_MAX_WORKERS
36
+ * itself as well; naming it here keeps the cap if that ever moves.
37
+ */
38
+ function positiveIntEnv(name: string): number | undefined {
39
+ const value = Number(process.env[name]);
40
+ return Number.isInteger(value) && value > 0 ? value : undefined;
41
+ }
42
+
32
43
  /**
33
44
  * The coverage SonarQube reads (FZ-8866). With MPO_COVERAGE=1, CI's test-vitest
34
45
  * measures every run as lcov, even a failing one. Each vitest process writes
@@ -310,7 +321,10 @@ export function createVitestConfig(options: CreateVitestConfigOptions = {}): Use
310
321
  environment,
311
322
  globals: true,
312
323
  setupFiles: dedupeReact ? [pinReactRequireSetup, ...resolvedSetupFiles] : resolvedSetupFiles,
313
- testTimeout,
324
+ testTimeout: positiveIntEnv("VITEST_TEST_TIMEOUT") ?? testTimeout,
325
+ ...(positiveIntEnv("VITEST_MAX_WORKERS")
326
+ ? { maxWorkers: positiveIntEnv("VITEST_MAX_WORKERS") }
327
+ : null),
314
328
  coverage: {
315
329
  provider: "v8" as const,
316
330
  reporter: ["text", "lcov", "html"],
@@ -0,0 +1,10 @@
1
+ export type LoopClosure = {
2
+ name: string;
3
+ kind: "let" | "const";
4
+ line: number;
5
+ column: number;
6
+ loopLine: number;
7
+ closureLine: number;
8
+ };
9
+ export declare function findLoopClosures(code: string, filename?: string): LoopClosure[];
10
+ //# sourceMappingURL=loopClosures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loopClosures.d.ts","sourceRoot":"","sources":["../src/loopClosures.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAkDF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAkB,GAAG,WAAW,EAAE,CAkBxF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Hermes compiles a loop's let/const into ONE binding unless it runs with
3
+ * -Xes6-block-scoping, so a closure created in a loop sees the last value
4
+ * (every DataTable filter chip removes the last filter, every FloatingPanel
5
+ * reference handler calls the last one). Metro avoids it by running
6
+ * @babel/plugin-transform-block-scoping over every module; vxrn's native
7
+ * build ships let/const as written. This lowers the whole production chunk
8
+ * once, after rolldown has flattened it (FZ-8895, from Pelt's FZ-8408 fix).
9
+ */
10
+ export declare const nativeBlockScopingPluginName = "vxrn-native-block-scoping";
11
+ export declare function lowerBlockScoping(code: string, filename?: string): Promise<{
12
+ code: string;
13
+ map: {
14
+ version: number;
15
+ sources: string[];
16
+ names: string[];
17
+ sourceRoot?: string | undefined;
18
+ sourcesContent?: string[] | undefined;
19
+ mappings: string;
20
+ file: string;
21
+ } | null;
22
+ }>;
23
+ interface NativeBuildOptions {
24
+ experimental?: {
25
+ devMode?: unknown;
26
+ };
27
+ }
28
+ /** vxrn's dev engine sets `experimental.devMode`; its production build does not. */
29
+ export declare function nativeBlockScopingPlugin(): {
30
+ name: string;
31
+ options(options: NativeBuildOptions): null;
32
+ renderChunk(code: string, chunk: {
33
+ fileName: string;
34
+ }): Promise<{
35
+ code: string;
36
+ map: {
37
+ version: number;
38
+ sources: string[];
39
+ names: string[];
40
+ sourceRoot?: string | undefined;
41
+ sourcesContent?: string[] | undefined;
42
+ mappings: string;
43
+ file: string;
44
+ } | null;
45
+ } | null>;
46
+ };
47
+ export {};
48
+ //# sourceMappingURL=nativeBlockScoping.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nativeBlockScoping.d.ts","sourceRoot":"","sources":["../src/nativeBlockScoping.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,8BAA8B,CAAC;AAExE,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAkB;;;;;;;;;;;GAgB/E;AAED,UAAU,kBAAkB;IAC1B,YAAY,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACtC;AAED,oFAAoF;AACpF,wBAAgB,wBAAwB;;qBAInB,kBAAkB;sBAIX,MAAM,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;EAK9D"}
package/types/vite.d.ts CHANGED
@@ -135,6 +135,12 @@ export interface CreateViteConfigOptions {
135
135
  * Auto-skipped when web3 is installed.
136
136
  */
137
137
  web3Stub?: boolean;
138
+ /**
139
+ * Lower let/const in the production native bundle with Babel's
140
+ * block-scoping transform. Hermes gives a loop's let/const one binding,
141
+ * so without it every closure made in a loop sees the last value.
142
+ */
143
+ blockScoping?: boolean;
138
144
  };
139
145
  }
140
146
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAU,UAAU,EAAE,MAAM,MAAM,CAAC;AAI/C,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE5B;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,OAAO,CAAC,EACJ,OAAO,GACP;QACE;;;WAGG;QACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QAEtB;;;WAGG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAEhB;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IAEN;;OAEG;IACH,IAAI,CAAC,EACD,OAAO,GACP;QACE;;;WAGG;QACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QAEjB;;WAEG;QACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;IAEN;;;OAGG;IACH,GAAG,CAAC,EACA,OAAO,GACP;QACE,MAAM,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3B,GAAG,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE,MAAM,CAAC;YAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QACtD,KAAK,CAAC,EAAE;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC;QAC/B,MAAM,CAAC,EAAE;YAAE,GAAG,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAChC,CAAC;IAEN;;OA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