@multiplatform.one/config 7.84.4 → 7.84.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/config",
3
- "version": "7.84.4",
3
+ "version": "7.84.6",
4
4
  "description": "Shared build and test configuration presets for multiplatform.one",
5
5
  "keywords": [
6
6
  "config",
@@ -114,7 +114,7 @@
114
114
  "access": "public"
115
115
  },
116
116
  "dependencies": {
117
- "@multiplatform.one/utils": "^7.84.4",
117
+ "@multiplatform.one/utils": "^7.84.6",
118
118
  "@tamagui/vite-plugin": "2.7.6",
119
119
  "@vitejs/plugin-react": "^6.1.2",
120
120
  "dotenv": "^17.4.2",
package/press-lint.mjs CHANGED
@@ -254,6 +254,125 @@ export function findNestedPressClaimants(source, filename, imported = new Set())
254
254
  return found;
255
255
  }
256
256
 
257
+ const equalityKinds = new Set([
258
+ ts.SyntaxKind.EqualsEqualsEqualsToken,
259
+ ts.SyntaxKind.EqualsEqualsToken,
260
+ ]);
261
+ const inequalityKinds = new Set([
262
+ ts.SyntaxKind.ExclamationEqualsEqualsToken,
263
+ ts.SyntaxKind.ExclamationEqualsToken,
264
+ ]);
265
+
266
+ /**
267
+ * @param {string} name
268
+ * @returns {true | undefined}
269
+ */
270
+ function isWebName(name) {
271
+ return name === "isWeb" ? true : undefined;
272
+ }
273
+
274
+ /**
275
+ * @param {ts.BinaryExpression} e
276
+ * @param {ts.SourceFile} file
277
+ * @returns {boolean | undefined}
278
+ */
279
+ function webComparison(e, file) {
280
+ const op = e.operatorToken.kind;
281
+ const eq = equalityKinds.has(op);
282
+ if (!eq && !inequalityKinds.has(op)) return undefined;
283
+ const sides = [unwrap(e.left), unwrap(e.right)];
284
+ const web = sides.some((side) => ts.isStringLiteral(side) && side.text === "web");
285
+ const target = sides.some((side) => /(?:Platform\.OS|TAMAGUI_TARGET)$/.test(side.getText(file)));
286
+ return web && target ? eq : undefined;
287
+ }
288
+
289
+ /**
290
+ * @param {ts.BinaryExpression} e
291
+ * @param {ts.SourceFile} file
292
+ * @returns {boolean | undefined}
293
+ */
294
+ function webBinaryCondition(e, file) {
295
+ const comparison = webComparison(e, file);
296
+ if (comparison !== undefined) return comparison;
297
+ if (e.operatorToken.kind !== ts.SyntaxKind.AmpersandAmpersandToken) return undefined;
298
+ const either = webCondition(e.left, file) === true || webCondition(e.right, file) === true;
299
+ return either ? true : undefined;
300
+ }
301
+
302
+ /**
303
+ * true: the condition holds only on web; false: only off web; undefined: neither.
304
+ * @param {ts.Expression} expr
305
+ * @param {ts.SourceFile} file
306
+ * @returns {boolean | undefined}
307
+ */
308
+ function webCondition(expr, file) {
309
+ const e = unwrap(expr);
310
+ if (ts.isPrefixUnaryExpression(e) && e.operator === ts.SyntaxKind.ExclamationToken) {
311
+ const inner = webCondition(e.operand, file);
312
+ return inner === undefined ? undefined : !inner;
313
+ }
314
+ if (ts.isIdentifier(e)) return isWebName(e.text);
315
+ if (ts.isPropertyAccessExpression(e)) return isWebName(e.name.text);
316
+ if (ts.isBinaryExpression(e)) return webBinaryCondition(e, file);
317
+ return undefined;
318
+ }
319
+
320
+ /**
321
+ * @param {ts.Expression} condition
322
+ * @param {boolean} inThen
323
+ * @param {ts.SourceFile} file
324
+ */
325
+ function branchIsWeb(condition, inThen, file) {
326
+ const web = webCondition(condition, file);
327
+ return web !== undefined && web === inThen;
328
+ }
329
+
330
+ /**
331
+ * @param {ts.Node} parent
332
+ * @param {ts.Node} child
333
+ * @param {ts.SourceFile} file
334
+ */
335
+ function gatesChild(parent, child, file) {
336
+ if (ts.isConditionalExpression(parent)) {
337
+ return (
338
+ child !== parent.condition && branchIsWeb(parent.condition, child === parent.whenTrue, file)
339
+ );
340
+ }
341
+ if (ts.isIfStatement(parent)) {
342
+ return (
343
+ child !== parent.expression &&
344
+ branchIsWeb(parent.expression, child === parent.thenStatement, file)
345
+ );
346
+ }
347
+ return (
348
+ ts.isBinaryExpression(parent) &&
349
+ parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken &&
350
+ child === parent.right &&
351
+ webCondition(parent.left, file) === true
352
+ );
353
+ }
354
+
355
+ /**
356
+ * @param {ts.Node} node
357
+ * @param {ts.SourceFile} file
358
+ */
359
+ function webGated(node, file) {
360
+ for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent) {
361
+ if (gatesChild(parent, child, file)) return true;
362
+ }
363
+ return false;
364
+ }
365
+
366
+ /**
367
+ * @param {ts.Node} node
368
+ * @param {ts.SourceFile} file
369
+ */
370
+ function isFocusWithinKey(node, file) {
371
+ if (ts.isJsxAttribute(node)) return node.name.getText(file) === "focusWithinStyle";
372
+ const property = ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node);
373
+ return property && keyName(node.name) === "focusWithinStyle";
374
+ }
375
+
257
376
  /**
258
377
  * NATIVE-FOCUS-WITHIN (FZ-8991): no `focusWithinStyle` that renders on native.
259
378
  *
@@ -283,71 +402,11 @@ export function findNativeFocusWithin(source, filename) {
283
402
  ts.ScriptKind.TSX,
284
403
  );
285
404
 
286
- /**
287
- * true: the condition holds only on web; false: only off web; undefined: neither.
288
- * @param {ts.Expression} expr
289
- * @returns {boolean | undefined}
290
- */
291
- function webCondition(expr) {
292
- const e = unwrap(expr);
293
- if (ts.isPrefixUnaryExpression(e) && e.operator === ts.SyntaxKind.ExclamationToken) {
294
- const inner = webCondition(e.operand);
295
- return inner === undefined ? undefined : !inner;
296
- }
297
- if (ts.isIdentifier(e)) return e.text === "isWeb" ? true : undefined;
298
- if (ts.isPropertyAccessExpression(e)) return e.name.text === "isWeb" ? true : undefined;
299
- if (ts.isBinaryExpression(e)) {
300
- const op = e.operatorToken.kind;
301
- const eq =
302
- op === ts.SyntaxKind.EqualsEqualsEqualsToken || op === ts.SyntaxKind.EqualsEqualsToken;
303
- const ne =
304
- op === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
305
- op === ts.SyntaxKind.ExclamationEqualsToken;
306
- if (eq || ne) {
307
- const sides = [unwrap(e.left), unwrap(e.right)];
308
- const web = sides.some((side) => ts.isStringLiteral(side) && side.text === "web");
309
- const target = sides.some((side) =>
310
- /(?:Platform\.OS|TAMAGUI_TARGET)$/.test(side.getText(file)),
311
- );
312
- if (web && target) return eq;
313
- }
314
- if (op === ts.SyntaxKind.AmpersandAmpersandToken)
315
- return webCondition(e.left) === true || webCondition(e.right) === true ? true : undefined;
316
- }
317
- return undefined;
318
- }
319
-
320
- /** @param {ts.Node} node */
321
- function webGated(node) {
322
- for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent) {
323
- if (ts.isConditionalExpression(parent) && child !== parent.condition) {
324
- const web = webCondition(parent.condition);
325
- if (web !== undefined && web === (child === parent.whenTrue)) return true;
326
- }
327
- if (
328
- ts.isBinaryExpression(parent) &&
329
- parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken &&
330
- child === parent.right &&
331
- webCondition(parent.left) === true
332
- )
333
- return true;
334
- if (ts.isIfStatement(parent) && child !== parent.expression) {
335
- const web = webCondition(parent.expression);
336
- if (web !== undefined && web === (child === parent.thenStatement)) return true;
337
- }
338
- }
339
- return false;
340
- }
341
-
342
405
  /** @type {{ line: number }[]} */
343
406
  const found = [];
344
407
  /** @param {ts.Node} node */
345
408
  function visit(node) {
346
- const named =
347
- (ts.isJsxAttribute(node) && node.name.getText(file) === "focusWithinStyle") ||
348
- ((ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node)) &&
349
- keyName(node.name) === "focusWithinStyle");
350
- if (named && !webGated(node)) {
409
+ if (isFocusWithinKey(node, file) && !webGated(node, file)) {
351
410
  const { line } = file.getLineAndCharacterOfPosition(node.getStart(file));
352
411
  found.push({ line: line + 1 });
353
412
  }
@@ -169,6 +169,127 @@ describe("findNativeFocusWithin (FZ-8991 NATIVE-FOCUS-WITHIN)", () => {
169
169
  expect(lines(source)).toEqual([]);
170
170
  });
171
171
 
172
+ it.each([
173
+ ["isWeb ?", "const a = <View {...(isWeb ? { focusWithinStyle: ring } : undefined)} />;", []],
174
+ [
175
+ "isWeb else",
176
+ "const a = <View {...(isWeb ? undefined : { focusWithinStyle: ring })} />;",
177
+ [1],
178
+ ],
179
+ [
180
+ "!isWeb else",
181
+ "const a = <View {...(!isWeb ? undefined : { focusWithinStyle: ring })} />;",
182
+ [],
183
+ ],
184
+ [
185
+ "!isWeb then",
186
+ "const a = <View {...(!isWeb ? { focusWithinStyle: ring } : undefined)} />;",
187
+ [1],
188
+ ],
189
+ ["!!isWeb", "const a = <View {...(!!isWeb ? { focusWithinStyle: ring } : {})} />;", []],
190
+ ["!native", "const a = <View {...(!isNative ? { focusWithinStyle: ring } : {})} />;", [1]],
191
+ ["member isWeb", "const a = <View {...(env.isWeb ? { focusWithinStyle: ring } : {})} />;", []],
192
+ [
193
+ "member other",
194
+ "const a = <View {...(env.isNative ? { focusWithinStyle: ring } : {})} />;",
195
+ [1],
196
+ ],
197
+ ["cast", "const a = <View {...((isWeb as boolean) ? { focusWithinStyle: ring } : {})} />;", []],
198
+ [
199
+ "reversed ===",
200
+ 'const a = <View {...("web" === Platform.OS ? { focusWithinStyle: ring } : {})} />;',
201
+ [],
202
+ ],
203
+ ["==", 'const a = <View {...(Platform.OS == "web" ? { focusWithinStyle: ring } : {})} />;', []],
204
+ [
205
+ "!== then",
206
+ 'const a = <View {...(Platform.OS !== "web" ? { focusWithinStyle: ring } : {})} />;',
207
+ [1],
208
+ ],
209
+ [
210
+ "!== else",
211
+ 'const a = <View {...(Platform.OS !== "web" ? {} : { focusWithinStyle: ring })} />;',
212
+ [],
213
+ ],
214
+ [
215
+ "!= else",
216
+ 'const a = <View {...(Platform.OS != "web" ? {} : { focusWithinStyle: ring })} />;',
217
+ [],
218
+ ],
219
+ [
220
+ "=== other target",
221
+ 'const a = <View {...(os === "web" ? { focusWithinStyle: ring } : {})} />;',
222
+ [1],
223
+ ],
224
+ [
225
+ "=== ios",
226
+ 'const a = <View {...(Platform.OS === "ios" ? { focusWithinStyle: ring } : {})} />;',
227
+ [1],
228
+ ],
229
+ [
230
+ "!(=== web)",
231
+ 'const a = <View {...(!(Platform.OS === "web") ? {} : { focusWithinStyle: ring })} />;',
232
+ [],
233
+ ],
234
+ [
235
+ "x && isWeb",
236
+ "const a = <View {...(ready && isWeb ? { focusWithinStyle: ring } : {})} />;",
237
+ [],
238
+ ],
239
+ [
240
+ "!isWeb && x else",
241
+ "const a = <View {...(!isWeb && ready ? {} : { focusWithinStyle: ring })} />;",
242
+ [1],
243
+ ],
244
+ [
245
+ "|| isWeb",
246
+ "const a = <View {...(ready || isWeb ? { focusWithinStyle: ring } : {})} />;",
247
+ [1],
248
+ ],
249
+ ["unknown ?", "const a = <View {...(ready ? { focusWithinStyle: ring } : {})} />;", [1]],
250
+ ["x && obj", "const a = <View {...(ready && { focusWithinStyle: ring })} />;", [1]],
251
+ ["obj && isWeb", "const a = <View {...({ focusWithinStyle: ring } && isWeb)} />;", [1]],
252
+ [
253
+ "condition position",
254
+ "const a = <View {...({ focusWithinStyle: ring } ? isWeb : {})} />;",
255
+ [1],
256
+ ],
257
+ [
258
+ "deep under gate",
259
+ "const a = <View {...(isWeb ? { nested: { deeper: { focusWithinStyle: ring } } } : {})} />;",
260
+ [],
261
+ ],
262
+ [
263
+ "inner unknown, outer web",
264
+ "const a = <View {...(isWeb ? (ready ? { focusWithinStyle: ring } : {}) : {})} />;",
265
+ [],
266
+ ],
267
+ ["if else", "if (isWeb) {} else { props.x = { focusWithinStyle: ring }; }", [1]],
268
+ ["if !isWeb else", "if (!isWeb) {} else { props.x = { focusWithinStyle: ring }; }", []],
269
+ ["if unknown", "if (ready) { props.x = { focusWithinStyle: ring }; }", [1]],
270
+ ["shorthand", "const a = { focusWithinStyle };", [1]],
271
+ ["string key", 'const a = { "focusWithinStyle": ring };', [1]],
272
+ ["other attr", 'const a = <View focusStyle={ring} data-x="focusWithinStyle" />;', []],
273
+ ])("pins the web gate for %s", (_label, source, expected) => {
274
+ expect(lines(source)).toEqual(expected);
275
+ });
276
+
277
+ it("skips sources without the key and every *.web.* extension", () => {
278
+ expect(lines("const a = <View focusStyle={ring} />;")).toEqual([]);
279
+ const source = `const a = <View focusWithinStyle={ring} />;`;
280
+ for (const name of [
281
+ "a.web.ts",
282
+ "a.web.tsx",
283
+ "a.web.js",
284
+ "a.web.jsx",
285
+ "a.web.mts",
286
+ "a.web.cjs",
287
+ ]) {
288
+ expect(lines(source, name)).toEqual([]);
289
+ }
290
+ expect(lines(source, "a.web.css.tsx")).toEqual([1]);
291
+ });
292
+
172
293
  it("skips files that only render on web", () => {
173
294
  const source = `const a = <View focusWithinStyle={ring} />;`;
174
295
  expect(lines(source, "Frame.web.tsx")).toEqual([]);