@oxy.so/app-preset 6.7.3 → 6.8.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/README.md +21 -0
- package/metro/base-font/Text.js +5 -0
- package/metro/base-font/TextInput.js +5 -0
- package/metro/base-font/base-font.native.js +48 -0
- package/metro/base-font/base-font.web.js +46 -0
- package/metro/base-font/mappings.js +9 -0
- package/metro/index.js +77 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -450,6 +450,27 @@ release bundle: Gradle can otherwise reuse its previous bundle despite a changed
|
|
|
450
450
|
package install. Inspect the regenerated source map for a single CSS runtime
|
|
451
451
|
before comparing device behavior.
|
|
452
452
|
|
|
453
|
+
#### A text that names no family draws Bloom's face (6.8.0+)
|
|
454
|
+
|
|
455
|
+
React Native draws a `Text` or `TextInput` that names no `fontFamily` in the
|
|
456
|
+
system face and has no setting for another default; react-native-web gives one
|
|
457
|
+
`font: 14px System`. Bloom's old default, `Text.defaultProps`, never reached a
|
|
458
|
+
text: React 19 applies `defaultProps` to class components only. So a raw
|
|
459
|
+
`<Text className="text-[15px]">` (Mention's feed rows, for one) drew Roboto, San
|
|
460
|
+
Francisco or Segoe UI next to Bloom's Inter.
|
|
461
|
+
|
|
462
|
+
`createOxyMetroConfig` bundles `metro/base-font/Text.js` and `TextInput.js`
|
|
463
|
+
wherever NativeWind's `Text` or `TextInput` would be bundled: the same
|
|
464
|
+
components (`styled(host, mapping)`, NativeWind's mappings) over a host that
|
|
465
|
+
puts the base face FIRST in its style. On native that is `Inter`, on a text with
|
|
466
|
+
no text ancestor (a nested text inherits its parent's family); on the web it is
|
|
467
|
+
`font-family: inherit` as an atomic class, so the text takes the document's
|
|
468
|
+
Inter (`--font-sans`). A `font-*` utility, an inline `fontFamily` and Bloom's
|
|
469
|
+
`Text` (which names its own family) still win. The match is on the resolved
|
|
470
|
+
file, so `import { Text } from 'react-native'`, deep `react-native/Libraries/…`
|
|
471
|
+
imports and the react-native-web path Expo's Babel preset rewrites to all reach
|
|
472
|
+
it; `withBaseFontText` is exported for an app that composes its own config.
|
|
473
|
+
|
|
453
474
|
#### `react-native` on native: the complete NativeWind shim (4.1.0+)
|
|
454
475
|
|
|
455
476
|
On native, NativeWind's resolver sends every `import … from 'react-native'`
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// What `react-native-css`'s `TextInput` resolves to under the preset (`../index.js`,
|
|
2
|
+
// `withBaseFontText`): NativeWind's component, drawing Bloom's base face.
|
|
3
|
+
const { TextInput } = require('./base-font');
|
|
4
|
+
|
|
5
|
+
module.exports = { __esModule: true, TextInput, default: TextInput };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeWind's `Text` and `TextInput` on Android and iOS, drawing Bloom's base
|
|
3
|
+
* face, Inter, when the text names no family.
|
|
4
|
+
*
|
|
5
|
+
* React Native draws such a text in the system face and has no setting for
|
|
6
|
+
* another default (Android falls back to `Typeface.DEFAULT`). The old way to set
|
|
7
|
+
* one, `Text.defaultProps`, is gone: React 19 applies `defaultProps` to class
|
|
8
|
+
* components only, and `Text` is a function component. So every text that
|
|
9
|
+
* named no family, a raw `<Text className="text-[15px]">` included, drew Roboto
|
|
10
|
+
* or San Francisco.
|
|
11
|
+
*
|
|
12
|
+
* Each component is `styled(host, mapping)`, as NativeWind builds its own, over
|
|
13
|
+
* a host that puts the base face FIRST in the style it is finally given. Under
|
|
14
|
+
* `styled()` that style is the className's utilities followed by the caller's
|
|
15
|
+
* inline style, so a `font-*` utility, an inline `fontFamily` and every Bloom
|
|
16
|
+
* `Text` (which names its own family) still win. A text nested in another text
|
|
17
|
+
* inherits its parent's family, as React Native does: the base face goes only on
|
|
18
|
+
* a text with no text ancestor.
|
|
19
|
+
*
|
|
20
|
+
* `Inter` mirrors `fontFamilies.sans` in `@oxy.so/bloom/fonts`, the family
|
|
21
|
+
* `BloomThemeProvider` loads on native, as `css/base.css` restates `--font-sans`.
|
|
22
|
+
*/
|
|
23
|
+
const { createElement, useContext } = require('react');
|
|
24
|
+
const { styled } = require('react-native-css');
|
|
25
|
+
const { copyComponentProperties } = require('react-native-css/components/copyComponentProperties');
|
|
26
|
+
const reactNative = require('react-native');
|
|
27
|
+
const MAPPINGS = require('./mappings');
|
|
28
|
+
|
|
29
|
+
const BASE_FONT = { fontFamily: 'Inter' };
|
|
30
|
+
|
|
31
|
+
function BaseFontText(props) {
|
|
32
|
+
if (useContext(reactNative.unstable_TextAncestorContext)) {
|
|
33
|
+
return createElement(reactNative.Text, props);
|
|
34
|
+
}
|
|
35
|
+
return createElement(reactNative.Text, { ...props, style: [BASE_FONT, props.style] });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function BaseFontTextInput(props) {
|
|
39
|
+
return createElement(reactNative.TextInput, { ...props, style: [BASE_FONT, props.style] });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
Text: copyComponentProperties(reactNative.Text, styled(BaseFontText, MAPPINGS.Text)),
|
|
44
|
+
TextInput: copyComponentProperties(
|
|
45
|
+
reactNative.TextInput,
|
|
46
|
+
styled(BaseFontTextInput, MAPPINGS.TextInput),
|
|
47
|
+
),
|
|
48
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeWind's `Text` and `TextInput` on the web, drawing the document's family
|
|
3
|
+
* (Inter: `--font-sans`, `css/base.css`) when the text names none.
|
|
4
|
+
*
|
|
5
|
+
* react-native-web gives a text with no text ancestor, and every TextInput,
|
|
6
|
+
* `font: 14px System`, so it drew the system stack (Segoe UI, Roboto, San
|
|
7
|
+
* Francisco) whatever the page's family. CSS alone cannot undo it: the rule sits
|
|
8
|
+
* in react-native-web's stylesheet at a class's specificity, and anything that
|
|
9
|
+
* beats it there also beats the atomic classes a `fontFamily` style compiles to.
|
|
10
|
+
*
|
|
11
|
+
* Each component is `styled(host, mapping)`, as NativeWind builds its own, over
|
|
12
|
+
* a host that puts `fontFamily: inherit` FIRST in its style, as an atomic class
|
|
13
|
+
* (`StyleSheet.create`): it beats react-native-web's default and loses to a
|
|
14
|
+
* `font-*` utility (the app's stylesheet follows react-native-web's), to a later
|
|
15
|
+
* `fontFamily` style (every Bloom `Text` names its own) and to an inline one. A
|
|
16
|
+
* nested text already inherits; inheriting again changes nothing.
|
|
17
|
+
*
|
|
18
|
+
* The hosts are react-native-web's own components, imported by the path that
|
|
19
|
+
* Expo's Babel preset rewrites `import { Text } from 'react-native'` to.
|
|
20
|
+
*/
|
|
21
|
+
const { createElement } = require('react');
|
|
22
|
+
const { styled } = require('react-native-css');
|
|
23
|
+
const { copyComponentProperties } = require('react-native-css/components/copyComponentProperties');
|
|
24
|
+
const StyleSheet = require('react-native-web/dist/exports/StyleSheet').default;
|
|
25
|
+
const MAPPINGS = require('./mappings');
|
|
26
|
+
|
|
27
|
+
const RNWText = require('react-native-web/dist/exports/Text').default;
|
|
28
|
+
const RNWTextInput = require('react-native-web/dist/exports/TextInput').default;
|
|
29
|
+
|
|
30
|
+
const styles = StyleSheet.create({ documentFont: { fontFamily: 'inherit' } });
|
|
31
|
+
|
|
32
|
+
function DocumentFontText(props) {
|
|
33
|
+
return createElement(RNWText, { ...props, style: [styles.documentFont, props.style] });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function DocumentFontTextInput(props) {
|
|
37
|
+
return createElement(RNWTextInput, { ...props, style: [styles.documentFont, props.style] });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
Text: copyComponentProperties(RNWText, styled(DocumentFontText, MAPPINGS.Text)),
|
|
42
|
+
TextInput: copyComponentProperties(
|
|
43
|
+
RNWTextInput,
|
|
44
|
+
styled(DocumentFontTextInput, MAPPINGS.TextInput),
|
|
45
|
+
),
|
|
46
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeWind's own mappings for its `Text` and `TextInput`
|
|
3
|
+
* (`react-native-css/components/Text` and `/TextInput`): a className becomes
|
|
4
|
+
* `style`, and on a TextInput `text-center` and friends also reach `textAlign`.
|
|
5
|
+
*/
|
|
6
|
+
module.exports = {
|
|
7
|
+
Text: { className: 'style' },
|
|
8
|
+
TextInput: { className: { target: 'style', nativeStyleMapping: { textAlign: true } } },
|
|
9
|
+
};
|
package/metro/index.js
CHANGED
|
@@ -385,6 +385,78 @@ function withCompleteReactNative(config, projectRoot = config.projectRoot) {
|
|
|
385
385
|
return config;
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
+
const BASE_FONT_DIR = path.join(__dirname, 'base-font');
|
|
389
|
+
/** The base-font modules, by both spellings (as for the completed module). */
|
|
390
|
+
const BASE_FONT_MODULES = new Set(
|
|
391
|
+
fs
|
|
392
|
+
.readdirSync(BASE_FONT_DIR)
|
|
393
|
+
.flatMap((file) => [
|
|
394
|
+
path.join(BASE_FONT_DIR, file),
|
|
395
|
+
fs.realpathSync(path.join(BASE_FONT_DIR, file)),
|
|
396
|
+
]),
|
|
397
|
+
);
|
|
398
|
+
/** NativeWind's `Text` and `TextInput` components, by any of the conditions Metro may pick. */
|
|
399
|
+
const CSS_TEXT_COMPONENT =
|
|
400
|
+
/[/\\]react-native-css[/\\](?:dist[/\\](?:commonjs|module)[/\\]components[/\\](Text|TextInput)\.js|src[/\\]components[/\\](Text|TextInput)\.tsx)$/;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Wraps a Metro config so that wherever NativeWind's `Text` or `TextInput`
|
|
404
|
+
* would be bundled, `./base-font/Text.js` or `./base-font/TextInput.js` is:
|
|
405
|
+
* the same component, drawing Bloom's base face when the text names no family
|
|
406
|
+
* (Inter on Android and iOS, the document's family on the web; see
|
|
407
|
+
* `./base-font/base-font.native.js` and `.web.js` for why each platform needs it).
|
|
408
|
+
*
|
|
409
|
+
* NativeWind is where every text of the app already passes: on native it sends
|
|
410
|
+
* `import { Text } from 'react-native'` (and deep `react-native/Libraries/…`
|
|
411
|
+
* imports) to its components, on the web the deep `react-native-web` import Expo's
|
|
412
|
+
* Babel preset rewrites it to. So the match is on the RESOLVED file, by every
|
|
413
|
+
* route that reaches it; nothing else changes.
|
|
414
|
+
*
|
|
415
|
+
* Apply it OUTERMOST. The base-font modules' own imports (React Native's hosts,
|
|
416
|
+
* NativeWind's runtime) go straight to Metro's resolver from the project, past
|
|
417
|
+
* every redirect: NativeWind's would send the hosts back to the components
|
|
418
|
+
* these modules replace.
|
|
419
|
+
*
|
|
420
|
+
* @param {import('metro-config').MetroConfig} config The finished config, NativeWind applied.
|
|
421
|
+
* @param {string} [projectRoot=config.projectRoot] The app package.
|
|
422
|
+
* @returns {import('metro-config').MetroConfig} `config`, its resolver wrapped.
|
|
423
|
+
*/
|
|
424
|
+
function withBaseFontText(config, projectRoot = config.projectRoot) {
|
|
425
|
+
const parentResolveRequest = config.resolver.resolveRequest;
|
|
426
|
+
const projectOrigin = path.join(projectRoot, 'package.json');
|
|
427
|
+
|
|
428
|
+
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
429
|
+
if (BASE_FONT_MODULES.has(context.originModulePath)) {
|
|
430
|
+
const own = moduleName.startsWith('.')
|
|
431
|
+
? context
|
|
432
|
+
: cssRuntimeContext(
|
|
433
|
+
{ ...context, originModulePath: projectOrigin },
|
|
434
|
+
moduleName,
|
|
435
|
+
platform,
|
|
436
|
+
projectRoot,
|
|
437
|
+
);
|
|
438
|
+
return context.resolveRequest(own, moduleName, platform);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const resolution = (parentResolveRequest ?? context.resolveRequest)(
|
|
442
|
+
context,
|
|
443
|
+
moduleName,
|
|
444
|
+
platform,
|
|
445
|
+
);
|
|
446
|
+
const component =
|
|
447
|
+
resolution?.type === 'sourceFile' && CSS_TEXT_COMPONENT.exec(resolution.filePath);
|
|
448
|
+
if (component) {
|
|
449
|
+
return {
|
|
450
|
+
type: 'sourceFile',
|
|
451
|
+
filePath: path.join(BASE_FONT_DIR, `${component[1] ?? component[2]}.js`),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
return resolution;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
return config;
|
|
458
|
+
}
|
|
459
|
+
|
|
388
460
|
/**
|
|
389
461
|
* Wraps a NativeWind Metro config with the Bloom single-instance rewrite and the
|
|
390
462
|
* web `ws` shim. In hoisted monorepos the same Bloom version is duplicated under
|
|
@@ -447,9 +519,10 @@ function createOxyMetroConfigWithBloom(projectRoot, options = {}) {
|
|
|
447
519
|
config,
|
|
448
520
|
options.workspaceRoot ? path.resolve(options.workspaceRoot) : findWorkspaceRoot(projectRoot),
|
|
449
521
|
);
|
|
450
|
-
// Outermost, so
|
|
451
|
-
// reach no redirect beneath
|
|
452
|
-
|
|
522
|
+
// Outermost, so they see the final resolution and their own modules'
|
|
523
|
+
// imports reach no redirect beneath them.
|
|
524
|
+
config = withCompleteReactNative(config, projectRoot);
|
|
525
|
+
return withBaseFontText(config, projectRoot);
|
|
453
526
|
}
|
|
454
527
|
|
|
455
528
|
module.exports = {
|
|
@@ -458,6 +531,7 @@ module.exports = {
|
|
|
458
531
|
withBloomSingleInstance,
|
|
459
532
|
withReactNativeCssSingleInstance,
|
|
460
533
|
withCompleteReactNative,
|
|
534
|
+
withBaseFontText,
|
|
461
535
|
withLinkedNativePackagesOnly,
|
|
462
536
|
withFreshWorkspaceBuilds,
|
|
463
537
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/app-preset",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0",
|
|
4
4
|
"description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
|
|
5
5
|
"main": "./app.plugin.js",
|
|
6
6
|
"publishConfig": {
|