rnwind 0.0.1 → 0.0.3
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/lib/cjs/core/parser/animation.cjs +427 -0
- package/lib/cjs/core/parser/animation.cjs.map +1 -0
- package/lib/cjs/core/parser/animation.d.ts +126 -0
- package/lib/cjs/core/parser/border-dispatcher.cjs +180 -0
- package/lib/cjs/core/parser/border-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/border-dispatcher.d.ts +15 -0
- package/lib/cjs/core/parser/case-convert.cjs +15 -0
- package/lib/cjs/core/parser/case-convert.cjs.map +1 -0
- package/lib/cjs/core/parser/case-convert.d.ts +6 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs +84 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.d.ts +19 -0
- package/lib/cjs/core/parser/color.cjs +193 -0
- package/lib/cjs/core/parser/color.cjs.map +1 -0
- package/lib/cjs/core/parser/color.d.ts +12 -0
- package/lib/cjs/core/parser/constants.cjs +21 -0
- package/lib/cjs/core/parser/constants.cjs.map +1 -0
- package/lib/cjs/core/parser/constants.d.ts +8 -0
- package/lib/cjs/core/parser/declaration.cjs +347 -0
- package/lib/cjs/core/parser/declaration.cjs.map +1 -0
- package/lib/cjs/core/parser/declaration.d.ts +15 -0
- package/lib/cjs/core/parser/gradient.cjs +132 -0
- package/lib/cjs/core/parser/gradient.cjs.map +1 -0
- package/lib/cjs/core/parser/gradient.d.ts +59 -0
- package/lib/cjs/core/parser/haptics.cjs +73 -0
- package/lib/cjs/core/parser/haptics.cjs.map +1 -0
- package/lib/cjs/core/parser/haptics.d.ts +47 -0
- package/lib/cjs/core/parser/index.d.ts +8 -0
- package/lib/cjs/core/parser/keyframes.cjs +95 -0
- package/lib/cjs/core/parser/keyframes.cjs.map +1 -0
- package/lib/cjs/core/parser/keyframes.d.ts +26 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs +120 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/layout-dispatcher.d.ts +14 -0
- package/lib/cjs/core/parser/length.cjs +110 -0
- package/lib/cjs/core/parser/length.cjs.map +1 -0
- package/lib/cjs/core/parser/length.d.ts +51 -0
- package/lib/cjs/core/parser/motion-dispatcher.cjs +77 -0
- package/lib/cjs/core/parser/motion-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/motion-dispatcher.d.ts +11 -0
- package/lib/cjs/core/parser/property.cjs +22 -0
- package/lib/cjs/core/parser/property.cjs.map +1 -0
- package/lib/cjs/core/parser/property.d.ts +8 -0
- package/lib/cjs/core/parser/safe-area.cjs +404 -0
- package/lib/cjs/core/parser/safe-area.cjs.map +1 -0
- package/lib/cjs/core/parser/safe-area.d.ts +39 -0
- package/lib/cjs/core/parser/selector.cjs +22 -0
- package/lib/cjs/core/parser/selector.cjs.map +1 -0
- package/lib/cjs/core/parser/selector.d.ts +11 -0
- package/lib/cjs/core/parser/shorthand.cjs +188 -0
- package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
- package/lib/cjs/core/parser/shorthand.d.ts +67 -0
- package/lib/cjs/core/parser/text-truncate.cjs +78 -0
- package/lib/cjs/core/parser/text-truncate.cjs.map +1 -0
- package/lib/cjs/core/parser/text-truncate.d.ts +44 -0
- package/lib/cjs/core/parser/theme-vars.cjs +467 -0
- package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
- package/lib/cjs/core/parser/theme-vars.d.ts +82 -0
- package/lib/cjs/core/parser/tokens.cjs +486 -0
- package/lib/cjs/core/parser/tokens.cjs.map +1 -0
- package/lib/cjs/core/parser/tokens.d.ts +45 -0
- package/lib/cjs/core/parser/transform.cjs +198 -0
- package/lib/cjs/core/parser/transform.cjs.map +1 -0
- package/lib/cjs/core/parser/transform.d.ts +36 -0
- package/lib/cjs/core/parser/tw-parser.cjs +1680 -0
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
- package/lib/cjs/core/parser/tw-parser.d.ts +210 -0
- package/lib/cjs/core/parser/types.d.ts +37 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs +108 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/typography-dispatcher.d.ts +11 -0
- package/lib/cjs/core/parser/typography.cjs +97 -0
- package/lib/cjs/core/parser/typography.cjs.map +1 -0
- package/lib/cjs/core/parser/typography.d.ts +43 -0
- package/lib/cjs/core/style-builder/build-style.cjs +444 -0
- package/lib/cjs/core/style-builder/build-style.cjs.map +1 -0
- package/lib/cjs/core/style-builder/build-style.d.ts +54 -0
- package/lib/cjs/core/style-builder/index.d.ts +3 -0
- package/lib/cjs/core/style-builder/union-builder.cjs +326 -0
- package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -0
- package/lib/cjs/core/style-builder/union-builder.d.ts +128 -0
- package/lib/cjs/core/types.d.ts +14 -0
- package/lib/cjs/metro/dts.cjs +127 -0
- package/lib/cjs/metro/dts.cjs.map +1 -0
- package/lib/cjs/metro/dts.d.ts +16 -0
- package/lib/cjs/metro/index.cjs +19 -0
- package/lib/cjs/metro/index.cjs.map +1 -0
- package/lib/cjs/metro/index.d.ts +9 -0
- package/lib/cjs/metro/resolver.cjs +47 -0
- package/lib/cjs/metro/resolver.cjs.map +1 -0
- package/lib/cjs/metro/resolver.d.ts +22 -0
- package/lib/cjs/metro/state.cjs +301 -0
- package/lib/cjs/metro/state.cjs.map +1 -0
- package/lib/cjs/metro/state.d.ts +88 -0
- package/lib/cjs/metro/transform-ast.cjs +1472 -0
- package/lib/cjs/metro/transform-ast.cjs.map +1 -0
- package/lib/cjs/metro/transform-ast.d.ts +88 -0
- package/lib/cjs/metro/transformer.cjs +372 -0
- package/lib/cjs/metro/transformer.cjs.map +1 -0
- package/lib/cjs/metro/transformer.d.ts +47 -0
- package/lib/cjs/metro/warn-unknown-classes.cjs +86 -0
- package/lib/cjs/metro/warn-unknown-classes.cjs.map +1 -0
- package/lib/cjs/metro/warn-unknown-classes.d.ts +21 -0
- package/lib/cjs/metro/with-config.cjs +196 -0
- package/lib/cjs/metro/with-config.cjs.map +1 -0
- package/lib/cjs/metro/with-config.d.ts +79 -0
- package/lib/cjs/runtime/chain-handlers.cjs +37 -0
- package/lib/cjs/runtime/chain-handlers.cjs.map +1 -0
- package/lib/cjs/runtime/chain-handlers.d.ts +33 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs +98 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs.map +1 -0
- package/lib/cjs/runtime/components/rnwind-provider.d.ts +84 -0
- package/lib/cjs/runtime/gradient-types.d.ts +58 -0
- package/lib/cjs/runtime/haptics.cjs +113 -0
- package/lib/cjs/runtime/haptics.cjs.map +1 -0
- package/lib/cjs/runtime/haptics.d.ts +48 -0
- package/lib/cjs/runtime/hooks/use-css.cjs +21 -0
- package/lib/cjs/runtime/hooks/use-css.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-css.d.ts +11 -0
- package/lib/cjs/runtime/hooks/use-interact.cjs +46 -0
- package/lib/cjs/runtime/hooks/use-interact.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-interact.d.ts +42 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs +68 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-scheme.d.ts +34 -0
- package/lib/cjs/runtime/index.cjs +45 -0
- package/lib/cjs/runtime/index.cjs.map +1 -0
- package/lib/cjs/runtime/index.d.ts +27 -0
- package/lib/cjs/runtime/interactive-box.cjs +35 -0
- package/lib/cjs/runtime/interactive-box.cjs.map +1 -0
- package/lib/cjs/runtime/interactive-box.d.ts +40 -0
- package/lib/cjs/runtime/lookup-css.cjs +542 -0
- package/lib/cjs/runtime/lookup-css.cjs.map +1 -0
- package/lib/cjs/runtime/lookup-css.d.ts +164 -0
- package/lib/cjs/runtime/types.d.ts +29 -0
- package/lib/cjs/testing/index.cjs +367 -0
- package/lib/cjs/testing/index.cjs.map +1 -0
- package/lib/cjs/testing/index.d.ts +145 -0
- package/lib/esm/core/parser/animation.d.ts +126 -0
- package/lib/esm/core/parser/animation.mjs +408 -0
- package/lib/esm/core/parser/animation.mjs.map +1 -0
- package/lib/esm/core/parser/border-dispatcher.d.ts +15 -0
- package/lib/esm/core/parser/border-dispatcher.mjs +178 -0
- package/lib/esm/core/parser/border-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/case-convert.d.ts +6 -0
- package/lib/esm/core/parser/case-convert.mjs +13 -0
- package/lib/esm/core/parser/case-convert.mjs.map +1 -0
- package/lib/esm/core/parser/color-properties-dispatcher.d.ts +19 -0
- package/lib/esm/core/parser/color-properties-dispatcher.mjs +82 -0
- package/lib/esm/core/parser/color-properties-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/color.d.ts +12 -0
- package/lib/esm/core/parser/color.mjs +191 -0
- package/lib/esm/core/parser/color.mjs.map +1 -0
- package/lib/esm/core/parser/constants.d.ts +8 -0
- package/lib/esm/core/parser/constants.mjs +13 -0
- package/lib/esm/core/parser/constants.mjs.map +1 -0
- package/lib/esm/core/parser/declaration.d.ts +15 -0
- package/lib/esm/core/parser/declaration.mjs +345 -0
- package/lib/esm/core/parser/declaration.mjs.map +1 -0
- package/lib/esm/core/parser/gradient.d.ts +59 -0
- package/lib/esm/core/parser/gradient.mjs +130 -0
- package/lib/esm/core/parser/gradient.mjs.map +1 -0
- package/lib/esm/core/parser/haptics.d.ts +47 -0
- package/lib/esm/core/parser/haptics.mjs +71 -0
- package/lib/esm/core/parser/haptics.mjs.map +1 -0
- package/lib/esm/core/parser/index.d.ts +8 -0
- package/lib/esm/core/parser/keyframes.d.ts +26 -0
- package/lib/esm/core/parser/keyframes.mjs +91 -0
- package/lib/esm/core/parser/keyframes.mjs.map +1 -0
- package/lib/esm/core/parser/layout-dispatcher.d.ts +14 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs +118 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/length.d.ts +51 -0
- package/lib/esm/core/parser/length.mjs +104 -0
- package/lib/esm/core/parser/length.mjs.map +1 -0
- package/lib/esm/core/parser/motion-dispatcher.d.ts +11 -0
- package/lib/esm/core/parser/motion-dispatcher.mjs +75 -0
- package/lib/esm/core/parser/motion-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/property.d.ts +8 -0
- package/lib/esm/core/parser/property.mjs +20 -0
- package/lib/esm/core/parser/property.mjs.map +1 -0
- package/lib/esm/core/parser/safe-area.d.ts +39 -0
- package/lib/esm/core/parser/safe-area.mjs +402 -0
- package/lib/esm/core/parser/safe-area.mjs.map +1 -0
- package/lib/esm/core/parser/selector.d.ts +11 -0
- package/lib/esm/core/parser/selector.mjs +20 -0
- package/lib/esm/core/parser/selector.mjs.map +1 -0
- package/lib/esm/core/parser/shorthand.d.ts +67 -0
- package/lib/esm/core/parser/shorthand.mjs +180 -0
- package/lib/esm/core/parser/shorthand.mjs.map +1 -0
- package/lib/esm/core/parser/text-truncate.d.ts +44 -0
- package/lib/esm/core/parser/text-truncate.mjs +75 -0
- package/lib/esm/core/parser/text-truncate.mjs.map +1 -0
- package/lib/esm/core/parser/theme-vars.d.ts +82 -0
- package/lib/esm/core/parser/theme-vars.mjs +461 -0
- package/lib/esm/core/parser/theme-vars.mjs.map +1 -0
- package/lib/esm/core/parser/tokens.d.ts +45 -0
- package/lib/esm/core/parser/tokens.mjs +480 -0
- package/lib/esm/core/parser/tokens.mjs.map +1 -0
- package/lib/esm/core/parser/transform.d.ts +36 -0
- package/lib/esm/core/parser/transform.mjs +193 -0
- package/lib/esm/core/parser/transform.mjs.map +1 -0
- package/lib/esm/core/parser/tw-parser.d.ts +210 -0
- package/lib/esm/core/parser/tw-parser.mjs +1678 -0
- package/lib/esm/core/parser/tw-parser.mjs.map +1 -0
- package/lib/esm/core/parser/types.d.ts +37 -0
- package/lib/esm/core/parser/typography-dispatcher.d.ts +11 -0
- package/lib/esm/core/parser/typography-dispatcher.mjs +106 -0
- package/lib/esm/core/parser/typography-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/typography.d.ts +43 -0
- package/lib/esm/core/parser/typography.mjs +91 -0
- package/lib/esm/core/parser/typography.mjs.map +1 -0
- package/lib/esm/core/style-builder/build-style.d.ts +54 -0
- package/lib/esm/core/style-builder/build-style.mjs +442 -0
- package/lib/esm/core/style-builder/build-style.mjs.map +1 -0
- package/lib/esm/core/style-builder/index.d.ts +3 -0
- package/lib/esm/core/style-builder/union-builder.d.ts +128 -0
- package/lib/esm/core/style-builder/union-builder.mjs +324 -0
- package/lib/esm/core/style-builder/union-builder.mjs.map +1 -0
- package/lib/esm/core/types.d.ts +14 -0
- package/lib/esm/metro/dts.d.ts +16 -0
- package/lib/esm/metro/dts.mjs +125 -0
- package/lib/esm/metro/dts.mjs.map +1 -0
- package/lib/esm/metro/index.d.ts +9 -0
- package/lib/esm/metro/index.mjs +6 -0
- package/lib/esm/metro/index.mjs.map +1 -0
- package/lib/esm/metro/resolver.d.ts +22 -0
- package/lib/esm/metro/resolver.mjs +43 -0
- package/lib/esm/metro/resolver.mjs.map +1 -0
- package/lib/esm/metro/state.d.ts +88 -0
- package/lib/esm/metro/state.mjs +291 -0
- package/lib/esm/metro/state.mjs.map +1 -0
- package/lib/esm/metro/transform-ast.d.ts +88 -0
- package/lib/esm/metro/transform-ast.mjs +1451 -0
- package/lib/esm/metro/transform-ast.mjs.map +1 -0
- package/lib/esm/metro/transformer.d.ts +47 -0
- package/lib/esm/metro/transformer.mjs +349 -0
- package/lib/esm/metro/transformer.mjs.map +1 -0
- package/lib/esm/metro/warn-unknown-classes.d.ts +21 -0
- package/lib/esm/metro/warn-unknown-classes.mjs +84 -0
- package/lib/esm/metro/warn-unknown-classes.mjs.map +1 -0
- package/lib/esm/metro/with-config.d.ts +79 -0
- package/lib/esm/metro/with-config.mjs +194 -0
- package/lib/esm/metro/with-config.mjs.map +1 -0
- package/lib/esm/runtime/chain-handlers.d.ts +33 -0
- package/lib/esm/runtime/chain-handlers.mjs +34 -0
- package/lib/esm/runtime/chain-handlers.mjs.map +1 -0
- package/lib/esm/runtime/components/rnwind-provider.d.ts +84 -0
- package/lib/esm/runtime/components/rnwind-provider.mjs +94 -0
- package/lib/esm/runtime/components/rnwind-provider.mjs.map +1 -0
- package/lib/esm/runtime/gradient-types.d.ts +58 -0
- package/lib/esm/runtime/haptics.d.ts +48 -0
- package/lib/esm/runtime/haptics.mjs +110 -0
- package/lib/esm/runtime/haptics.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-css.d.ts +11 -0
- package/lib/esm/runtime/hooks/use-css.mjs +19 -0
- package/lib/esm/runtime/hooks/use-css.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-interact.d.ts +42 -0
- package/lib/esm/runtime/hooks/use-interact.mjs +44 -0
- package/lib/esm/runtime/hooks/use-interact.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-scheme.d.ts +34 -0
- package/lib/esm/runtime/hooks/use-scheme.mjs +63 -0
- package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -0
- package/lib/esm/runtime/index.d.ts +27 -0
- package/lib/esm/runtime/index.mjs +18 -0
- package/lib/esm/runtime/index.mjs.map +1 -0
- package/lib/esm/runtime/interactive-box.d.ts +40 -0
- package/lib/esm/runtime/interactive-box.mjs +33 -0
- package/lib/esm/runtime/interactive-box.mjs.map +1 -0
- package/lib/esm/runtime/lookup-css.d.ts +164 -0
- package/lib/esm/runtime/lookup-css.mjs +531 -0
- package/lib/esm/runtime/lookup-css.mjs.map +1 -0
- package/lib/esm/runtime/types.d.ts +29 -0
- package/lib/esm/testing/index.d.ts +145 -0
- package/lib/esm/testing/index.mjs +344 -0
- package/lib/esm/testing/index.mjs.map +1 -0
- package/package.json +80 -13
- package/preset.css +1171 -0
- package/src/core/parser/animation.ts +404 -0
- package/src/core/parser/border-dispatcher.ts +176 -0
- package/src/core/parser/case-convert.ts +10 -0
- package/src/core/parser/color-properties-dispatcher.ts +78 -0
- package/src/core/parser/color.ts +191 -0
- package/src/core/parser/constants.ts +11 -0
- package/src/core/parser/declaration.ts +340 -0
- package/src/core/parser/gradient.ts +148 -0
- package/src/core/parser/haptics.ts +88 -0
- package/src/core/parser/index.ts +8 -0
- package/src/core/parser/keyframes.ts +84 -0
- package/src/core/parser/layout-dispatcher.ts +111 -0
- package/src/core/parser/length.ts +114 -0
- package/src/core/parser/motion-dispatcher.ts +89 -0
- package/src/core/parser/property.ts +15 -0
- package/src/core/parser/safe-area.ts +404 -0
- package/src/core/parser/selector.ts +17 -0
- package/src/core/parser/shorthand.ts +182 -0
- package/src/core/parser/text-truncate.ts +79 -0
- package/src/core/parser/theme-vars.ts +465 -0
- package/src/core/parser/tokens.ts +456 -0
- package/src/core/parser/transform.ts +195 -0
- package/src/core/parser/tw-parser.ts +1828 -0
- package/src/core/parser/types.ts +45 -0
- package/src/core/parser/typography-dispatcher.ts +97 -0
- package/src/core/parser/typography.ts +83 -0
- package/src/core/style-builder/build-style.ts +500 -0
- package/src/core/style-builder/index.ts +3 -0
- package/src/core/style-builder/union-builder.ts +328 -0
- package/src/core/types.ts +15 -0
- package/src/metro/dts.ts +128 -0
- package/src/metro/index.ts +9 -0
- package/src/metro/resolver.ts +42 -0
- package/src/metro/state.ts +305 -0
- package/src/metro/transform-ast.ts +1729 -0
- package/src/metro/transformer.ts +372 -0
- package/src/metro/warn-unknown-classes.ts +79 -0
- package/src/metro/with-config.ts +251 -0
- package/src/runtime/chain-handlers.ts +47 -0
- package/src/runtime/components/rnwind-provider.tsx +144 -0
- package/src/runtime/gradient-types.ts +60 -0
- package/src/runtime/haptics.ts +120 -0
- package/src/runtime/hooks/use-css.ts +16 -0
- package/src/runtime/hooks/use-interact.ts +65 -0
- package/src/runtime/hooks/use-scheme.ts +63 -0
- package/src/runtime/index.ts +54 -0
- package/src/runtime/interactive-box.tsx +57 -0
- package/src/runtime/lookup-css.ts +628 -0
- package/src/runtime/types.ts +32 -0
- package/src/testing/index.ts +507 -0
- package/src/types/tailwindcss-node.d.ts +33 -0
- package/src/index.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dts.mjs","sources":["../../../../src/metro/dts.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs'\nimport path from 'node:path'\n\n/**\n * React Native component-props interfaces rnwind augments. Adding an\n * optional `className?: string` to each lets TypeScript accept\n * `<View className=\"…\" />` without the user touching types by hand.\n * The generic ones are written with a placeholder so the output type\n * stays parameterised.\n */\nconst INTERFACES: ReadonlyArray<string | { name: string; generic: string }> = [\n 'ViewProps',\n 'TextProps',\n 'ImageProps',\n 'ImageBackgroundProps',\n 'ScrollViewProps',\n 'PressableProps',\n 'ModalProps',\n 'TextInputProps',\n 'TouchableOpacityProps',\n 'TouchableHighlightProps',\n 'TouchableNativeFeedbackProps',\n 'TouchableWithoutFeedbackProps',\n 'SafeAreaViewProps',\n 'KeyboardAvoidingViewProps',\n 'RefreshControlProps',\n 'StatusBarProps',\n 'SwitchProps',\n 'ActivityIndicatorProps',\n 'SectionListProps',\n { name: 'FlatListProps', generic: 'ItemT' },\n { name: 'VirtualizedListProps', generic: 'ItemT' },\n]\n\n/**\n * Built-in prefix wired into every install. Restricted to the interfaces\n * that natively expose `contentContainerStyle` so TypeScript doesn't\n * start accepting `<View contentContainerClassName=\"…\" />` — RN would\n * silently ignore it at runtime and a typed lint is more useful than a\n * permissive one. User prefixes don't come with this restriction; rnwind\n * can't know which component props they target.\n */\nconst BUILTIN_PREFIX = 'contentContainer'\n\n/**\n * Interfaces that expose `contentContainerStyle` in React Native's own\n * types — the set the built-in prefix's `.d.ts` augmentation targets.\n * Everything else stays `className`-only by default.\n */\nconst CONTENT_CONTAINER_INTERFACES: ReadonlySet<string> = new Set([\n 'ScrollViewProps',\n 'FlatListProps',\n 'SectionListProps',\n 'VirtualizedListProps',\n])\n\n/**\n * Build the body of one interface augmentation: `className?: string`\n * plus `<prefix>ClassName?: string` for every prefix that applies to\n * THIS interface. Emits a single-line body so the file stays easy to\n * scan and diff.\n * @param interfaceName Bare interface name (generic parameters stripped).\n * @param userPrefixes Extra prefixes from the Metro config — applied to\n * every interface the same way `className` is.\n * @returns Space-separated property declarations.\n */\nfunction buildInterfaceBody(interfaceName: string, userPrefixes: readonly string[]): string {\n const props = ['className?: string']\n if (CONTENT_CONTAINER_INTERFACES.has(interfaceName)) props.push(`${BUILTIN_PREFIX}ClassName?: string`)\n for (const prefix of userPrefixes) {\n if (prefix === BUILTIN_PREFIX) continue\n props.push(`${prefix}ClassName?: string`)\n }\n return props.join('; ')\n}\n\n/**\n * Write the rnwind TypeScript declaration file. The generated `.d.ts`\n * declares a `rnwind` module augmentation for `react-native`'s\n * component props — every interface gets an optional `className?:\n * string` plus `<prefix>ClassName?: string` for each active prefix.\n * Runtime-rendered schemes (`@variant` blocks) are reflected in the\n * `Scheme` union so `useScheme()` returns the actual names.\n *\n * Called once at Metro-config time — overwrite-on-rewrite so the file\n * stays in sync with the user's current theme CSS + prefix config.\n * @param targetPath Absolute path to write (typically `rnwind-types.d.ts` at project root).\n * @param schemes Scheme names from the user's `@variant` blocks (empty when none declared).\n * @param classNamePrefixes Extra prefixes from the Metro config — merged\n * on top of the built-in `'contentContainer'`. Defaults to empty.\n */\nexport function writeDtsFile(\n targetPath: string,\n schemes: readonly string[],\n classNamePrefixes: readonly string[] = [],\n): void {\n const lines: string[] = [\n '// Auto-generated by rnwind — do not edit by hand.',\n '// Overwritten on Metro start / theme CSS change.',\n '',\n `declare module 'react-native' {`,\n ]\n for (const entry of INTERFACES) {\n const name = typeof entry === 'string' ? entry : entry.name\n const body = buildInterfaceBody(name, classNamePrefixes)\n if (typeof entry === 'string') {\n lines.push(` interface ${entry} { ${body} }`)\n continue\n }\n lines.push(` interface ${entry.name}<${entry.generic}> { ${body} }`)\n }\n lines.push('}', '')\n if (schemes.length > 0) {\n lines.push(`declare module 'rnwind' {`, ` export interface RnwindConfig {`)\n const schemeLiterals = schemes.map((s) => `'${s}'`).join(', ')\n lines.push(` themes: readonly [${schemeLiterals}]`, ` }`, '}', '')\n }\n // The `export {}` is mandatory — without at least one top-level\n // import/export, TypeScript treats this file as a SCRIPT and the\n // `declare module 'react-native'` block above becomes a complete\n // *replacement* declaration (hiding the real RN exports like\n // `Pressable`, `useColorScheme`, etc.). With `export {}` the file\n // becomes a module and the `declare module` blocks are interpreted as\n // *augmentations* — which is what we want.\n lines.push('export {}', '')\n mkdirSync(path.dirname(targetPath), { recursive: true })\n writeFileSync(targetPath, lines.join('\\n'), 'utf8')\n}\n"],"names":[],"mappings":";;;AAGA;;;;;;AAMG;AACH,MAAM,UAAU,GAA8D;IAC5E,WAAW;IACX,WAAW;IACX,YAAY;IACZ,sBAAsB;IACtB,iBAAiB;IACjB,gBAAgB;IAChB,YAAY;IACZ,gBAAgB;IAChB,uBAAuB;IACvB,yBAAyB;IACzB,8BAA8B;IAC9B,+BAA+B;IAC/B,mBAAmB;IACnB,2BAA2B;IAC3B,qBAAqB;IACrB,gBAAgB;IAChB,aAAa;IACb,wBAAwB;IACxB,kBAAkB;AAClB,IAAA,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE;AAC3C,IAAA,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO,EAAE;CACnD;AAED;;;;;;;AAOG;AACH,MAAM,cAAc,GAAG,kBAAkB;AAEzC;;;;AAIG;AACH,MAAM,4BAA4B,GAAwB,IAAI,GAAG,CAAC;IAChE,iBAAiB;IACjB,eAAe;IACf,kBAAkB;IAClB,sBAAsB;AACvB,CAAA,CAAC;AAEF;;;;;;;;;AASG;AACH,SAAS,kBAAkB,CAAC,aAAqB,EAAE,YAA+B,EAAA;AAChF,IAAA,MAAM,KAAK,GAAG,CAAC,oBAAoB,CAAC;AACpC,IAAA,IAAI,4BAA4B,CAAC,GAAG,CAAC,aAAa,CAAC;AA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AAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAA,CAAA,EAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;AAC9D,QAAA,KAAK,CAAC,IAAI,CAAC,CAAA,sBAAA,EAAyB,cAAc,CAAA,CAAA,CAAG,EAAE,CAAA,GAAA,CAAK,EAAE,GAAG,EAAE,EAAE,CAAC;IACxE;;;;;;;;AAQA,IAAA,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;AAC3B,IAAA,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACxD,IAAA,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;AACrD;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { withRnwindConfig } from './with-config';
|
|
2
|
+
export type { RnwindMetroOptions, MetroConfigLike } from './with-config';
|
|
3
|
+
export { createRnwindResolver } from './resolver';
|
|
4
|
+
export type { ResolveRequestFn } from './resolver';
|
|
5
|
+
export { writeDtsFile } from './dts';
|
|
6
|
+
export { transform } from './transformer';
|
|
7
|
+
export type { BabelTransformerArgs, BabelTransformerResult } from './transformer';
|
|
8
|
+
export { getRnwindState, configureRnwindState, resetRnwindState, manifestPathFor } from './state';
|
|
9
|
+
export type { RnwindState } from './state';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { withRnwindConfig } from './with-config.mjs';
|
|
2
|
+
export { createRnwindResolver } from './resolver.mjs';
|
|
3
|
+
export { writeDtsFile } from './dts.mjs';
|
|
4
|
+
export { transform } from './transformer.mjs';
|
|
5
|
+
export { configureRnwindState, getRnwindState, manifestPathFor, resetRnwindState } from './state.mjs';
|
|
6
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Metro `resolveRequest` callable shape. Loose so we don't bind to Metro's internal types. */
|
|
2
|
+
export type ResolveRequestFn = (context: unknown, moduleName: string, platform: string | null) => unknown;
|
|
3
|
+
/**
|
|
4
|
+
* Sentinel module specifier the transformer prepends to every rewritten
|
|
5
|
+
* file. The resolver maps it to the user's theme CSS so Metro watches
|
|
6
|
+
* that file as a real node in the dependency graph — when the user
|
|
7
|
+
* edits `global.css`, the CSS file's SHA1 changes, and Metro
|
|
8
|
+
* invalidates every JS file that imports the sentinel. The transformer
|
|
9
|
+
* recognises `.css` filenames and returns an empty `export {}` AST so
|
|
10
|
+
* Metro can still bundle it.
|
|
11
|
+
*/
|
|
12
|
+
export declare const THEME_SIGNATURE_MODULE = "rnwind/__generated/theme-signature";
|
|
13
|
+
/**
|
|
14
|
+
* Build a Metro `resolveRequest` hook that maps the scheme manifest
|
|
15
|
+
* specifier (and the theme-signature sentinel) to its on-disk path.
|
|
16
|
+
* Delegates every other request to the upstream resolver.
|
|
17
|
+
* @param upstream Previously-registered `resolveRequest` (kept in the chain).
|
|
18
|
+
* @returns Metro-compatible resolver.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createRnwindResolver(upstream: ResolveRequestFn | null | undefined): ResolveRequestFn;
|
|
21
|
+
/** Side-effect import specifier(s) the transformer injects on every rewritten file. */
|
|
22
|
+
export declare const STYLE_SPECIFIERS: readonly ["rnwind/__generated/schemes"];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { manifestPathFor } from './state.mjs';
|
|
2
|
+
|
|
3
|
+
/** Specifier the transformer prepends — resolves to the scheme manifest. */
|
|
4
|
+
const SCHEMES_MODULE = 'rnwind/__generated/schemes';
|
|
5
|
+
/**
|
|
6
|
+
* Sentinel module specifier the transformer prepends to every rewritten
|
|
7
|
+
* file. The resolver maps it to the user's theme CSS so Metro watches
|
|
8
|
+
* that file as a real node in the dependency graph — when the user
|
|
9
|
+
* edits `global.css`, the CSS file's SHA1 changes, and Metro
|
|
10
|
+
* invalidates every JS file that imports the sentinel. The transformer
|
|
11
|
+
* recognises `.css` filenames and returns an empty `export {}` AST so
|
|
12
|
+
* Metro can still bundle it.
|
|
13
|
+
*/
|
|
14
|
+
const THEME_SIGNATURE_MODULE = 'rnwind/__generated/theme-signature';
|
|
15
|
+
/**
|
|
16
|
+
* Build a Metro `resolveRequest` hook that maps the scheme manifest
|
|
17
|
+
* specifier (and the theme-signature sentinel) to its on-disk path.
|
|
18
|
+
* Delegates every other request to the upstream resolver.
|
|
19
|
+
* @param upstream Previously-registered `resolveRequest` (kept in the chain).
|
|
20
|
+
* @returns Metro-compatible resolver.
|
|
21
|
+
*/
|
|
22
|
+
function createRnwindResolver(upstream) {
|
|
23
|
+
return (context, moduleName, platform) => {
|
|
24
|
+
if (moduleName === SCHEMES_MODULE)
|
|
25
|
+
return { type: 'sourceFile', filePath: manifestPathFor() };
|
|
26
|
+
if (moduleName === THEME_SIGNATURE_MODULE) {
|
|
27
|
+
const cssPath = process.env.RNWIND_CSS_ENTRY_FILE;
|
|
28
|
+
if (cssPath)
|
|
29
|
+
return { type: 'sourceFile', filePath: cssPath };
|
|
30
|
+
}
|
|
31
|
+
if (upstream)
|
|
32
|
+
return upstream(context, moduleName, platform);
|
|
33
|
+
const { resolveRequest } = context;
|
|
34
|
+
if (resolveRequest)
|
|
35
|
+
return resolveRequest(context, moduleName, platform);
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Side-effect import specifier(s) the transformer injects on every rewritten file. */
|
|
40
|
+
const STYLE_SPECIFIERS = [SCHEMES_MODULE];
|
|
41
|
+
|
|
42
|
+
export { STYLE_SPECIFIERS, THEME_SIGNATURE_MODULE, createRnwindResolver };
|
|
43
|
+
//# sourceMappingURL=resolver.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.mjs","sources":["../../../../src/metro/resolver.ts"],"sourcesContent":["import { manifestPathFor } from './state'\n\n/** Specifier the transformer prepends — resolves to the scheme manifest. */\nconst SCHEMES_MODULE = 'rnwind/__generated/schemes'\n\n/** Metro `resolveRequest` callable shape. Loose so we don't bind to Metro's internal types. */\nexport type ResolveRequestFn = (context: unknown, moduleName: string, platform: string | null) => unknown\n\n/**\n * Sentinel module specifier the transformer prepends to every rewritten\n * file. The resolver maps it to the user's theme CSS so Metro watches\n * that file as a real node in the dependency graph — when the user\n * edits `global.css`, the CSS file's SHA1 changes, and Metro\n * invalidates every JS file that imports the sentinel. The transformer\n * recognises `.css` filenames and returns an empty `export {}` AST so\n * Metro can still bundle it.\n */\nexport const THEME_SIGNATURE_MODULE = 'rnwind/__generated/theme-signature'\n\n/**\n * Build a Metro `resolveRequest` hook that maps the scheme manifest\n * specifier (and the theme-signature sentinel) to its on-disk path.\n * Delegates every other request to the upstream resolver.\n * @param upstream Previously-registered `resolveRequest` (kept in the chain).\n * @returns Metro-compatible resolver.\n */\nexport function createRnwindResolver(upstream: ResolveRequestFn | null | undefined): ResolveRequestFn {\n return (context, moduleName, platform) => {\n if (moduleName === SCHEMES_MODULE) return { type: 'sourceFile', filePath: manifestPathFor() }\n if (moduleName === THEME_SIGNATURE_MODULE) {\n const cssPath = process.env.RNWIND_CSS_ENTRY_FILE\n if (cssPath) return { type: 'sourceFile', filePath: cssPath }\n }\n if (upstream) return upstream(context, moduleName, platform)\n const { resolveRequest } = context as { resolveRequest?: ResolveRequestFn }\n if (resolveRequest) return resolveRequest(context, moduleName, platform)\n return null as unknown\n }\n}\n\n/** Side-effect import specifier(s) the transformer injects on every rewritten file. */\nexport const STYLE_SPECIFIERS = [SCHEMES_MODULE] as const\n"],"names":[],"mappings":";;AAEA;AACA,MAAM,cAAc,GAAG,4BAA4B;AAKnD;;;;;;;;AAQG;AACI,MAAM,sBAAsB,GAAG;AAEtC;;;;;;AAMG;AACG,SAAU,oBAAoB,CAAC,QAA6C,EAAA;AAChF,IAAA,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,KAAI;QACvC,IAAI,UAAU,KAAK,cAAc;YAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE;AAC7F,QAAA,IAAI,UAAU,KAAK,sBAAsB,EAAE;AACzC,YAAA,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB;AACjD,YAAA,IAAI,OAAO;gBAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE;QAC/D;AACA,QAAA,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC;AAC5D,QAAA,MAAM,EAAE,cAAc,EAAE,GAAG,OAAgD;AAC3E,QAAA,IAAI,cAAc;YAAE,OAAO,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC;AACxE,QAAA,OAAO,IAAe;AACxB,IAAA,CAAC;AACH;AAEA;AACO,MAAM,gBAAgB,GAAG,CAAC,cAAc;;;;"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { UnionBuilder } from '../core/style-builder';
|
|
2
|
+
import { TailwindParser } from '../core/parser';
|
|
3
|
+
/**
|
|
4
|
+
* Worker-local state. Lazy-initialised on first access so files that
|
|
5
|
+
* bypass the transform don't pay for construction.
|
|
6
|
+
*/
|
|
7
|
+
export interface RnwindState {
|
|
8
|
+
parser: TailwindParser;
|
|
9
|
+
builder: UnionBuilder;
|
|
10
|
+
themeCss: string;
|
|
11
|
+
themeHash: string;
|
|
12
|
+
projectRoot: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Publish the theme CSS path + cache dir to the environment so worker
|
|
16
|
+
* subprocesses (spawned by Metro once `babelTransformerPath` is set)
|
|
17
|
+
* can rebuild the same state without re-reading the Metro config.
|
|
18
|
+
* @param cssEntryFile Absolute path to the user's theme CSS.
|
|
19
|
+
* @param cacheDir Absolute path to the cache dir (`.rnwind`).
|
|
20
|
+
* @param watchFolders
|
|
21
|
+
* @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
|
|
22
|
+
* @param hostSources
|
|
23
|
+
* @param hostComponents
|
|
24
|
+
*/
|
|
25
|
+
export declare function configureRnwindState(cssEntryFile: string, cacheDir: string, watchFolders?: readonly string[], classNamePrefixes?: readonly string[], hostSources?: readonly string[], hostComponents?: readonly string[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Read the caller-configured extra className prefixes out of the
|
|
28
|
+
* worker environment. Returns an empty array when unset — the
|
|
29
|
+
* transformer applies the built-in `contentContainer` default on top
|
|
30
|
+
* either way.
|
|
31
|
+
* @returns User-supplied extra prefixes.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getClassNamePrefixes(): readonly string[];
|
|
34
|
+
/**
|
|
35
|
+
* Read the caller-configured extra host module sources out of the
|
|
36
|
+
* worker environment. Empty array when unset — the transformer applies
|
|
37
|
+
* its built-in default list on top either way.
|
|
38
|
+
* @returns User-supplied extra host sources.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getHostSources(): readonly string[];
|
|
41
|
+
/**
|
|
42
|
+
* Read the caller-configured extra host JSX tag names out of the worker
|
|
43
|
+
* environment. Verbatim names — may include `.` for member expressions
|
|
44
|
+
* like `'Animated.View'`.
|
|
45
|
+
* @returns User-supplied extra host component names.
|
|
46
|
+
*/
|
|
47
|
+
export declare function getHostComponents(): readonly string[];
|
|
48
|
+
/**
|
|
49
|
+
* Fetch (or build) the worker-local rnwind state. Re-reads the theme
|
|
50
|
+
* CSS hash on every call: if the user edited `global.css` while Metro
|
|
51
|
+
* is running, the cached state is dropped and a fresh parser + ledger
|
|
52
|
+
* is built. Combined with the `getCacheKey()` export on the
|
|
53
|
+
* transformer (which folds the same hash into Metro's per-file cache
|
|
54
|
+
* key) every CSS edit produces a full, correct re-bundle.
|
|
55
|
+
* @param projectRoot
|
|
56
|
+
* @returns The live rnwind state.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getRnwindState(projectRoot: string): RnwindState;
|
|
59
|
+
/**
|
|
60
|
+
* Compute the rnwind cache-key suffix Metro mixes into every per-file
|
|
61
|
+
* transform cache entry via the transformer's `getCacheKey()` export.
|
|
62
|
+
* Includes the CSS path + its current content hash + the rnwind
|
|
63
|
+
* library fingerprint, so any edit to `global.css` OR a library
|
|
64
|
+
* upgrade flips the cache key and forces Metro to re-run the
|
|
65
|
+
* transformer.
|
|
66
|
+
* @returns Deterministic string suitable for appending to Metro's cache key.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getRnwindCacheKey(): string;
|
|
69
|
+
/** Drop the cached state — call after editing the theme CSS. */
|
|
70
|
+
export declare function resetRnwindState(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Drop cached state, rebuild parser/builder with the fresh CSS, rescan
|
|
73
|
+
* the project, and rewrite every scheme file on disk. This is what
|
|
74
|
+
* `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits
|
|
75
|
+
* propagate to the app via Metro's HMR — without this, the CSS-as-JS
|
|
76
|
+
* module would re-emit `export {}` whose bytes never change, so Metro
|
|
77
|
+
* would never invalidate downstream modules.
|
|
78
|
+
* @param projectRoot Absolute project root (from `metroConfig.projectRoot`).
|
|
79
|
+
*/
|
|
80
|
+
export declare function onThemeChange(projectRoot: string): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Resolve the on-disk path of the scheme manifest module for the
|
|
83
|
+
* resolver. The manifest eager-imports `common.style.js` and
|
|
84
|
+
* lazy-requires each variant scheme; SchemeProvider calls its
|
|
85
|
+
* `ensureSchemeLoaded` export to trigger per-scheme requires.
|
|
86
|
+
* @returns Absolute path to `<cacheDir>/schemes.js`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function manifestPathFor(): string;
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { UnionBuilder } from '../core/style-builder/union-builder.mjs';
|
|
5
|
+
import { TailwindParser } from '../core/parser/tw-parser.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Default oxide Scanner globs — walk every JS/TS source under the
|
|
9
|
+
* project root AND every monorepo watch folder, excluding
|
|
10
|
+
* `node_modules` and rnwind's own cache dir so we don't rescan
|
|
11
|
+
* generated scheme files.
|
|
12
|
+
*
|
|
13
|
+
* Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface
|
|
14
|
+
* sibling package roots as `metroConfig.watchFolders`. Every folder
|
|
15
|
+
* Metro watches must also be scanned so atoms declared in shared UI
|
|
16
|
+
* packages make it into the union — without this, only the app's
|
|
17
|
+
* own files would be scanned and every UI-package atom would resolve
|
|
18
|
+
* to `undefined` at runtime.
|
|
19
|
+
* @param projectRoot Absolute project root.
|
|
20
|
+
* @param cacheDir Absolute rnwind cache dir (to exclude).
|
|
21
|
+
* @param watchFolders Extra monorepo roots Metro is watching.
|
|
22
|
+
* @returns Scanner sources suitable for `parser.parseProject()`.
|
|
23
|
+
*/
|
|
24
|
+
function defaultSources(projectRoot, cacheDir, watchFolders) {
|
|
25
|
+
const cacheBaseName = path.basename(cacheDir);
|
|
26
|
+
const roots = new Set([projectRoot, ...watchFolders]);
|
|
27
|
+
const sources = [];
|
|
28
|
+
for (const root of roots) {
|
|
29
|
+
sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true });
|
|
30
|
+
}
|
|
31
|
+
return sources;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read monorepo watch-folder paths out of the worker environment.
|
|
35
|
+
* Empty array when the host isn't a monorepo.
|
|
36
|
+
* @returns Absolute paths Metro also watches (sibling packages).
|
|
37
|
+
*/
|
|
38
|
+
function readWatchFolders() {
|
|
39
|
+
const raw = process.env[WATCH_FOLDERS_ENV];
|
|
40
|
+
if (!raw || raw.length === 0)
|
|
41
|
+
return [];
|
|
42
|
+
return raw.split('\0').filter((entry) => entry.length > 0);
|
|
43
|
+
}
|
|
44
|
+
/** Env var Metro workers read to locate the theme CSS on disk. */
|
|
45
|
+
const CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE';
|
|
46
|
+
/** Env var Metro workers read to locate the cache directory (`.rnwind`). */
|
|
47
|
+
const CACHE_DIR_ENV = 'RNWIND_CACHE_DIR';
|
|
48
|
+
/** Env var carrying `watchFolders` from Metro config (NUL-separated). */
|
|
49
|
+
const WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS';
|
|
50
|
+
/** Env var carrying extra className prefixes the Metro config supplied. */
|
|
51
|
+
const CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES';
|
|
52
|
+
/** Env var carrying extra import sources whose JSX exports get className→style rewrites. Comma-separated. */
|
|
53
|
+
const HOST_SOURCES_ENV = 'RNWIND_HOST_SOURCES';
|
|
54
|
+
/** Env var carrying extra JSX tag names (verbatim, may contain `.`) treated as hosts. Comma-separated. */
|
|
55
|
+
const HOST_COMPONENTS_ENV = 'RNWIND_HOST_COMPONENTS';
|
|
56
|
+
/** Memoised library fingerprint — read once per worker process. */
|
|
57
|
+
let libraryFingerprint;
|
|
58
|
+
/** Live state shared across one Metro transform worker. */
|
|
59
|
+
let cached = null;
|
|
60
|
+
/**
|
|
61
|
+
* Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the
|
|
62
|
+
* file's mtime nanoseconds (so identical content with different mtime
|
|
63
|
+
* — atomic rewrites — still picks up the change). Returns `'missing'`
|
|
64
|
+
* when the file can't be read so the cache key is still deterministic.
|
|
65
|
+
* @param cssPath Absolute CSS path.
|
|
66
|
+
* @returns 16-char hex content hash.
|
|
67
|
+
*/
|
|
68
|
+
function readThemeHashFor(cssPath) {
|
|
69
|
+
if (!existsSync(cssPath))
|
|
70
|
+
return 'missing';
|
|
71
|
+
try {
|
|
72
|
+
const bytes = readFileSync(cssPath);
|
|
73
|
+
const mtime = statSync(cssPath).mtimeMs.toString();
|
|
74
|
+
return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return 'missing';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Hash a small set of rnwind library files whose changes affect the
|
|
82
|
+
* generated transform output. When the library is rebuilt (workspace
|
|
83
|
+
* dev OR npm install of a new version) the file bytes change, the
|
|
84
|
+
* fingerprint rotates, and Metro's transform cache invalidates.
|
|
85
|
+
*
|
|
86
|
+
* Includes the JSX rewriter (`transform-ast`) alongside the parser /
|
|
87
|
+
* style-builder so a change to the transformer — e.g. renaming the
|
|
88
|
+
* injected context hook — invalidates every stale per-file cache entry
|
|
89
|
+
* on the next dev run. Without this, a user upgrading rnwind in-place
|
|
90
|
+
* would keep loading the old transformed bytes; React-refresh would
|
|
91
|
+
* then preserve fiber state across the version bump and the rendered
|
|
92
|
+
* hook list could shift, surfacing as "change in the order of Hooks"
|
|
93
|
+
* runtime errors.
|
|
94
|
+
* Memoised — read once per worker process.
|
|
95
|
+
* @returns 16-char hex fingerprint.
|
|
96
|
+
*/
|
|
97
|
+
function getLibraryFingerprint() {
|
|
98
|
+
if (libraryFingerprint !== undefined)
|
|
99
|
+
return libraryFingerprint;
|
|
100
|
+
const here = path.dirname(__filename);
|
|
101
|
+
const candidates = [
|
|
102
|
+
path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),
|
|
103
|
+
path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),
|
|
104
|
+
path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),
|
|
105
|
+
path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),
|
|
106
|
+
path.resolve(here, 'transform-ast.mjs'),
|
|
107
|
+
path.resolve(here, 'transform-ast.cjs'),
|
|
108
|
+
path.resolve(here, 'transformer.mjs'),
|
|
109
|
+
path.resolve(here, 'transformer.cjs'),
|
|
110
|
+
// Source-tree fallback for tests + workspace dev (no built lib yet).
|
|
111
|
+
path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),
|
|
112
|
+
path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),
|
|
113
|
+
path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),
|
|
114
|
+
path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),
|
|
115
|
+
];
|
|
116
|
+
const hash = createHash('sha256');
|
|
117
|
+
let included = 0;
|
|
118
|
+
for (const file of candidates) {
|
|
119
|
+
if (!existsSync(file))
|
|
120
|
+
continue;
|
|
121
|
+
try {
|
|
122
|
+
hash.update(readFileSync(file));
|
|
123
|
+
included += 1;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Unreadable file — skip; fingerprint still derives from whatever WE could read.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16);
|
|
130
|
+
return libraryFingerprint;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Publish the theme CSS path + cache dir to the environment so worker
|
|
134
|
+
* subprocesses (spawned by Metro once `babelTransformerPath` is set)
|
|
135
|
+
* can rebuild the same state without re-reading the Metro config.
|
|
136
|
+
* @param cssEntryFile Absolute path to the user's theme CSS.
|
|
137
|
+
* @param cacheDir Absolute path to the cache dir (`.rnwind`).
|
|
138
|
+
* @param watchFolders
|
|
139
|
+
* @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
|
|
140
|
+
* @param hostSources
|
|
141
|
+
* @param hostComponents
|
|
142
|
+
*/
|
|
143
|
+
function configureRnwindState(cssEntryFile, cacheDir, watchFolders = [], classNamePrefixes, hostSources, hostComponents) {
|
|
144
|
+
process.env[CSS_ENTRY_ENV] = cssEntryFile;
|
|
145
|
+
process.env[CACHE_DIR_ENV] = cacheDir;
|
|
146
|
+
if (watchFolders.length === 0) {
|
|
147
|
+
delete process.env[WATCH_FOLDERS_ENV];
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\0');
|
|
151
|
+
}
|
|
152
|
+
if (!classNamePrefixes || classNamePrefixes.length === 0) {
|
|
153
|
+
delete process.env[CLASSNAME_PREFIXES_ENV];
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',');
|
|
157
|
+
}
|
|
158
|
+
if (!hostSources || hostSources.length === 0) {
|
|
159
|
+
delete process.env[HOST_SOURCES_ENV];
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
process.env[HOST_SOURCES_ENV] = hostSources.join(',');
|
|
163
|
+
}
|
|
164
|
+
if (!hostComponents || hostComponents.length === 0) {
|
|
165
|
+
delete process.env[HOST_COMPONENTS_ENV];
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
process.env[HOST_COMPONENTS_ENV] = hostComponents.join(',');
|
|
169
|
+
}
|
|
170
|
+
cached = null;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Read the caller-configured extra className prefixes out of the
|
|
174
|
+
* worker environment. Returns an empty array when unset — the
|
|
175
|
+
* transformer applies the built-in `contentContainer` default on top
|
|
176
|
+
* either way.
|
|
177
|
+
* @returns User-supplied extra prefixes.
|
|
178
|
+
*/
|
|
179
|
+
function getClassNamePrefixes() {
|
|
180
|
+
const raw = process.env[CLASSNAME_PREFIXES_ENV];
|
|
181
|
+
if (!raw || raw.length === 0)
|
|
182
|
+
return [];
|
|
183
|
+
return raw.split(',').filter((entry) => entry.length > 0);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Read the caller-configured extra host module sources out of the
|
|
187
|
+
* worker environment. Empty array when unset — the transformer applies
|
|
188
|
+
* its built-in default list on top either way.
|
|
189
|
+
* @returns User-supplied extra host sources.
|
|
190
|
+
*/
|
|
191
|
+
function getHostSources() {
|
|
192
|
+
const raw = process.env[HOST_SOURCES_ENV];
|
|
193
|
+
if (!raw || raw.length === 0)
|
|
194
|
+
return [];
|
|
195
|
+
return raw.split(',').filter((entry) => entry.length > 0);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Read the caller-configured extra host JSX tag names out of the worker
|
|
199
|
+
* environment. Verbatim names — may include `.` for member expressions
|
|
200
|
+
* like `'Animated.View'`.
|
|
201
|
+
* @returns User-supplied extra host component names.
|
|
202
|
+
*/
|
|
203
|
+
function getHostComponents() {
|
|
204
|
+
const raw = process.env[HOST_COMPONENTS_ENV];
|
|
205
|
+
if (!raw || raw.length === 0)
|
|
206
|
+
return [];
|
|
207
|
+
return raw.split(',').filter((entry) => entry.length > 0);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Fetch (or build) the worker-local rnwind state. Re-reads the theme
|
|
211
|
+
* CSS hash on every call: if the user edited `global.css` while Metro
|
|
212
|
+
* is running, the cached state is dropped and a fresh parser + ledger
|
|
213
|
+
* is built. Combined with the `getCacheKey()` export on the
|
|
214
|
+
* transformer (which folds the same hash into Metro's per-file cache
|
|
215
|
+
* key) every CSS edit produces a full, correct re-bundle.
|
|
216
|
+
* @param projectRoot
|
|
217
|
+
* @returns The live rnwind state.
|
|
218
|
+
*/
|
|
219
|
+
function getRnwindState(projectRoot) {
|
|
220
|
+
const cssEntry = process.env[CSS_ENTRY_ENV];
|
|
221
|
+
const cacheDir = process.env[CACHE_DIR_ENV];
|
|
222
|
+
if (!cssEntry)
|
|
223
|
+
throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?');
|
|
224
|
+
if (!cacheDir)
|
|
225
|
+
throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?');
|
|
226
|
+
const currentHash = readThemeHashFor(cssEntry);
|
|
227
|
+
if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot)
|
|
228
|
+
return cached;
|
|
229
|
+
const themeCss = readFileSync(cssEntry, 'utf8');
|
|
230
|
+
const parser = new TailwindParser({
|
|
231
|
+
themeCss,
|
|
232
|
+
sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),
|
|
233
|
+
});
|
|
234
|
+
const builder = new UnionBuilder(cacheDir, parser);
|
|
235
|
+
cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot };
|
|
236
|
+
return cached;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Compute the rnwind cache-key suffix Metro mixes into every per-file
|
|
240
|
+
* transform cache entry via the transformer's `getCacheKey()` export.
|
|
241
|
+
* Includes the CSS path + its current content hash + the rnwind
|
|
242
|
+
* library fingerprint, so any edit to `global.css` OR a library
|
|
243
|
+
* upgrade flips the cache key and forces Metro to re-run the
|
|
244
|
+
* transformer.
|
|
245
|
+
* @returns Deterministic string suitable for appending to Metro's cache key.
|
|
246
|
+
*/
|
|
247
|
+
function getRnwindCacheKey() {
|
|
248
|
+
const cssEntry = process.env[CSS_ENTRY_ENV] ?? '';
|
|
249
|
+
const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? '';
|
|
250
|
+
// Host source / component config changes which JSX tags get rewritten,
|
|
251
|
+
// so it MUST flip the cache key — otherwise Metro replays stale
|
|
252
|
+
// transforms (a newly-opted-in host keeps its raw className, a removed
|
|
253
|
+
// one keeps the rewrite).
|
|
254
|
+
const hostSources = process.env[HOST_SOURCES_ENV] ?? '';
|
|
255
|
+
const hostComponents = process.env[HOST_COMPONENTS_ENV] ?? '';
|
|
256
|
+
return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}|hs:${hostSources}|hc:${hostComponents}`;
|
|
257
|
+
}
|
|
258
|
+
/** Drop the cached state — call after editing the theme CSS. */
|
|
259
|
+
function resetRnwindState() {
|
|
260
|
+
cached = null;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Drop cached state, rebuild parser/builder with the fresh CSS, rescan
|
|
264
|
+
* the project, and rewrite every scheme file on disk. This is what
|
|
265
|
+
* `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits
|
|
266
|
+
* propagate to the app via Metro's HMR — without this, the CSS-as-JS
|
|
267
|
+
* module would re-emit `export {}` whose bytes never change, so Metro
|
|
268
|
+
* would never invalidate downstream modules.
|
|
269
|
+
* @param projectRoot Absolute project root (from `metroConfig.projectRoot`).
|
|
270
|
+
*/
|
|
271
|
+
async function onThemeChange(projectRoot) {
|
|
272
|
+
resetRnwindState();
|
|
273
|
+
const state = getRnwindState(projectRoot);
|
|
274
|
+
await state.builder.writeSchemes();
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Resolve the on-disk path of the scheme manifest module for the
|
|
278
|
+
* resolver. The manifest eager-imports `common.style.js` and
|
|
279
|
+
* lazy-requires each variant scheme; SchemeProvider calls its
|
|
280
|
+
* `ensureSchemeLoaded` export to trigger per-scheme requires.
|
|
281
|
+
* @returns Absolute path to `<cacheDir>/schemes.js`.
|
|
282
|
+
*/
|
|
283
|
+
function manifestPathFor() {
|
|
284
|
+
const cacheDir = process.env[CACHE_DIR_ENV];
|
|
285
|
+
if (!cacheDir)
|
|
286
|
+
throw new Error('rnwind: RNWIND_CACHE_DIR is not set');
|
|
287
|
+
return path.join(cacheDir, 'schemes.js');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { configureRnwindState, getClassNamePrefixes, getHostComponents, getHostSources, getRnwindCacheKey, getRnwindState, manifestPathFor, onThemeChange, resetRnwindState };
|
|
291
|
+
//# sourceMappingURL=state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.mjs","sources":["../../../../src/metro/state.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs'\nimport path from 'node:path'\nimport { createHash } from 'node:crypto'\nimport { UnionBuilder } from '../core/style-builder'\nimport { TailwindParser, type SourceEntry } from '../core/parser'\n\n/**\n * Default oxide Scanner globs — walk every JS/TS source under the\n * project root AND every monorepo watch folder, excluding\n * `node_modules` and rnwind's own cache dir so we don't rescan\n * generated scheme files.\n *\n * Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface\n * sibling package roots as `metroConfig.watchFolders`. Every folder\n * Metro watches must also be scanned so atoms declared in shared UI\n * packages make it into the union — without this, only the app's\n * own files would be scanned and every UI-package atom would resolve\n * to `undefined` at runtime.\n * @param projectRoot Absolute project root.\n * @param cacheDir Absolute rnwind cache dir (to exclude).\n * @param watchFolders Extra monorepo roots Metro is watching.\n * @returns Scanner sources suitable for `parser.parseProject()`.\n */\nfunction defaultSources(projectRoot: string, cacheDir: string, watchFolders: readonly string[]): readonly SourceEntry[] {\n const cacheBaseName = path.basename(cacheDir)\n const roots = new Set<string>([projectRoot, ...watchFolders])\n const sources: SourceEntry[] = []\n for (const root of roots) {\n sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true })\n }\n return sources\n}\n\n/**\n * Read monorepo watch-folder paths out of the worker environment.\n * Empty array when the host isn't a monorepo.\n * @returns Absolute paths Metro also watches (sibling packages).\n */\nfunction readWatchFolders(): readonly string[] {\n const raw = process.env[WATCH_FOLDERS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split('\\0').filter((entry) => entry.length > 0)\n}\n\n/** Env var Metro workers read to locate the theme CSS on disk. */\nconst CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE'\n/** Env var Metro workers read to locate the cache directory (`.rnwind`). */\nconst CACHE_DIR_ENV = 'RNWIND_CACHE_DIR'\n/** Env var carrying `watchFolders` from Metro config (NUL-separated). */\nconst WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS'\n/** Env var carrying extra className prefixes the Metro config supplied. */\nconst CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES'\n/** Env var carrying extra import sources whose JSX exports get className→style rewrites. Comma-separated. */\nconst HOST_SOURCES_ENV = 'RNWIND_HOST_SOURCES'\n/** Env var carrying extra JSX tag names (verbatim, may contain `.`) treated as hosts. Comma-separated. */\nconst HOST_COMPONENTS_ENV = 'RNWIND_HOST_COMPONENTS'\n\n/** Memoised library fingerprint — read once per worker process. */\nlet libraryFingerprint: string | undefined\n\n/** Live state shared across one Metro transform worker. */\nlet cached: RnwindState | null = null\n\n/**\n * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the\n * file's mtime nanoseconds (so identical content with different mtime\n * — atomic rewrites — still picks up the change). Returns `'missing'`\n * when the file can't be read so the cache key is still deterministic.\n * @param cssPath Absolute CSS path.\n * @returns 16-char hex content hash.\n */\nfunction readThemeHashFor(cssPath: string): string {\n if (!existsSync(cssPath)) return 'missing'\n try {\n const bytes = readFileSync(cssPath)\n const mtime = statSync(cssPath).mtimeMs.toString()\n return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16)\n } catch {\n return 'missing'\n }\n}\n\n/**\n * Hash a small set of rnwind library files whose changes affect the\n * generated transform output. When the library is rebuilt (workspace\n * dev OR npm install of a new version) the file bytes change, the\n * fingerprint rotates, and Metro's transform cache invalidates.\n *\n * Includes the JSX rewriter (`transform-ast`) alongside the parser /\n * style-builder so a change to the transformer — e.g. renaming the\n * injected context hook — invalidates every stale per-file cache entry\n * on the next dev run. Without this, a user upgrading rnwind in-place\n * would keep loading the old transformed bytes; React-refresh would\n * then preserve fiber state across the version bump and the rendered\n * hook list could shift, surfacing as \"change in the order of Hooks\"\n * runtime errors.\n * Memoised — read once per worker process.\n * @returns 16-char hex fingerprint.\n */\nfunction getLibraryFingerprint(): string {\n if (libraryFingerprint !== undefined) return libraryFingerprint\n const here = path.dirname(__filename)\n const candidates = [\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),\n path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),\n path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),\n path.resolve(here, 'transform-ast.mjs'),\n path.resolve(here, 'transform-ast.cjs'),\n path.resolve(here, 'transformer.mjs'),\n path.resolve(here, 'transformer.cjs'),\n // Source-tree fallback for tests + workspace dev (no built lib yet).\n path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),\n path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),\n path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),\n ]\n const hash = createHash('sha256')\n let included = 0\n for (const file of candidates) {\n if (!existsSync(file)) continue\n try {\n hash.update(readFileSync(file))\n included += 1\n } catch {\n // Unreadable file — skip; fingerprint still derives from whatever WE could read.\n }\n }\n libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)\n return libraryFingerprint\n}\n\n/**\n * Worker-local state. Lazy-initialised on first access so files that\n * bypass the transform don't pay for construction.\n */\nexport interface RnwindState {\n parser: TailwindParser\n builder: UnionBuilder\n themeCss: string\n themeHash: string\n projectRoot: string\n}\n\n/**\n * Publish the theme CSS path + cache dir to the environment so worker\n * subprocesses (spawned by Metro once `babelTransformerPath` is set)\n * can rebuild the same state without re-reading the Metro config.\n * @param cssEntryFile Absolute path to the user's theme CSS.\n * @param cacheDir Absolute path to the cache dir (`.rnwind`).\n * @param watchFolders\n * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.\n * @param hostSources\n * @param hostComponents\n */\nexport function configureRnwindState(\n cssEntryFile: string,\n cacheDir: string,\n watchFolders: readonly string[] = [],\n classNamePrefixes?: readonly string[],\n hostSources?: readonly string[],\n hostComponents?: readonly string[],\n): void {\n process.env[CSS_ENTRY_ENV] = cssEntryFile\n process.env[CACHE_DIR_ENV] = cacheDir\n if (watchFolders.length === 0) {\n delete process.env[WATCH_FOLDERS_ENV]\n } else {\n process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\\0')\n }\n if (!classNamePrefixes || classNamePrefixes.length === 0) {\n delete process.env[CLASSNAME_PREFIXES_ENV]\n } else {\n process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')\n }\n if (!hostSources || hostSources.length === 0) {\n delete process.env[HOST_SOURCES_ENV]\n } else {\n process.env[HOST_SOURCES_ENV] = hostSources.join(',')\n }\n if (!hostComponents || hostComponents.length === 0) {\n delete process.env[HOST_COMPONENTS_ENV]\n } else {\n process.env[HOST_COMPONENTS_ENV] = hostComponents.join(',')\n }\n cached = null\n}\n\n/**\n * Read the caller-configured extra className prefixes out of the\n * worker environment. Returns an empty array when unset — the\n * transformer applies the built-in `contentContainer` default on top\n * either way.\n * @returns User-supplied extra prefixes.\n */\nexport function getClassNamePrefixes(): readonly string[] {\n const raw = process.env[CLASSNAME_PREFIXES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host module sources out of the\n * worker environment. Empty array when unset — the transformer applies\n * its built-in default list on top either way.\n * @returns User-supplied extra host sources.\n */\nexport function getHostSources(): readonly string[] {\n const raw = process.env[HOST_SOURCES_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Read the caller-configured extra host JSX tag names out of the worker\n * environment. Verbatim names — may include `.` for member expressions\n * like `'Animated.View'`.\n * @returns User-supplied extra host component names.\n */\nexport function getHostComponents(): readonly string[] {\n const raw = process.env[HOST_COMPONENTS_ENV]\n if (!raw || raw.length === 0) return []\n return raw.split(',').filter((entry) => entry.length > 0)\n}\n\n/**\n * Fetch (or build) the worker-local rnwind state. Re-reads the theme\n * CSS hash on every call: if the user edited `global.css` while Metro\n * is running, the cached state is dropped and a fresh parser + ledger\n * is built. Combined with the `getCacheKey()` export on the\n * transformer (which folds the same hash into Metro's per-file cache\n * key) every CSS edit produces a full, correct re-bundle.\n * @param projectRoot\n * @returns The live rnwind state.\n */\nexport function getRnwindState(projectRoot: string): RnwindState {\n const cssEntry = process.env[CSS_ENTRY_ENV]\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')\n const currentHash = readThemeHashFor(cssEntry)\n if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached\n const themeCss = readFileSync(cssEntry, 'utf8')\n const parser = new TailwindParser({\n themeCss,\n sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),\n })\n const builder = new UnionBuilder(cacheDir, parser)\n cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }\n return cached\n}\n\n/**\n * Compute the rnwind cache-key suffix Metro mixes into every per-file\n * transform cache entry via the transformer's `getCacheKey()` export.\n * Includes the CSS path + its current content hash + the rnwind\n * library fingerprint, so any edit to `global.css` OR a library\n * upgrade flips the cache key and forces Metro to re-run the\n * transformer.\n * @returns Deterministic string suitable for appending to Metro's cache key.\n */\nexport function getRnwindCacheKey(): string {\n const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''\n const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''\n // Host source / component config changes which JSX tags get rewritten,\n // so it MUST flip the cache key — otherwise Metro replays stale\n // transforms (a newly-opted-in host keeps its raw className, a removed\n // one keeps the rewrite).\n const hostSources = process.env[HOST_SOURCES_ENV] ?? ''\n const hostComponents = process.env[HOST_COMPONENTS_ENV] ?? ''\n return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}|hs:${hostSources}|hc:${hostComponents}`\n}\n\n/** Drop the cached state — call after editing the theme CSS. */\nexport function resetRnwindState(): void {\n cached = null\n}\n\n/**\n * Drop cached state, rebuild parser/builder with the fresh CSS, rescan\n * the project, and rewrite every scheme file on disk. This is what\n * `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits\n * propagate to the app via Metro's HMR — without this, the CSS-as-JS\n * module would re-emit `export {}` whose bytes never change, so Metro\n * would never invalidate downstream modules.\n * @param projectRoot Absolute project root (from `metroConfig.projectRoot`).\n */\nexport async function onThemeChange(projectRoot: string): Promise<void> {\n resetRnwindState()\n const state = getRnwindState(projectRoot)\n await state.builder.writeSchemes()\n}\n\n/**\n * Resolve the on-disk path of the scheme manifest module for the\n * resolver. The manifest eager-imports `common.style.js` and\n * lazy-requires each variant scheme; SchemeProvider calls its\n * `ensureSchemeLoaded` export to trigger per-scheme requires.\n * @returns Absolute path to `<cacheDir>/schemes.js`.\n */\nexport function manifestPathFor(): string {\n const cacheDir = process.env[CACHE_DIR_ENV]\n if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')\n return path.join(cacheDir, 'schemes.js')\n}\n"],"names":[],"mappings":";;;;;;AAMA;;;;;;;;;;;;;;;;AAgBG;AACH,SAAS,cAAc,CAAC,WAAmB,EAAE,QAAgB,EAAE,YAA+B,EAAA;IAC5F,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAC7C,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,CAAS,CAAC,WAAW,EAAE,GAAG,YAAY,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAkB,EAAE;AACjC,IAAA,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAA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ime atom-registration entry point imported by the union style file. */
|
|
4
|
+
export declare const REGISTER_ATOMS = "registerAtoms";
|
|
5
|
+
/** Per-file state returned by the transformer, for the caller to integrate with the atom ledger. */
|
|
6
|
+
export interface TransformAstResult {
|
|
7
|
+
/** `true` when the AST was mutated (any `className=` rewrite landed). */
|
|
8
|
+
touched: boolean;
|
|
9
|
+
/** Atom-name arrays the transformer hoisted — one entry per unique atom set. */
|
|
10
|
+
hoistedArrays: ReadonlyMap<string, readonly string[]>;
|
|
11
|
+
/** Candidate literal texts collected from every rewritten `className`. */
|
|
12
|
+
literals: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/** Inputs to {@link transformAst}. */
|
|
15
|
+
export interface TransformAstOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Module specifiers the transformer side-effect-imports at the top
|
|
18
|
+
* of each rewritten file. Today: the union `style.js` and
|
|
19
|
+
* `keyframes.js` (always two entries — see `STYLE_SPECIFIERS` in
|
|
20
|
+
* resolver.ts). Empty when the file has no atoms to register.
|
|
21
|
+
*/
|
|
22
|
+
styleSpecifiers: readonly string[];
|
|
23
|
+
/**
|
|
24
|
+
* Parser-surfaced gradient metadata per atom. The transformer reads
|
|
25
|
+
* this map when rewriting literal `className="..."` sites so it can
|
|
26
|
+
* strip gradient atoms out of the atom array fed to `lookupCss` and
|
|
27
|
+
* emit `colors={...} start={...} end={...}` JSX attributes consumed
|
|
28
|
+
* by `<LinearGradient>` (or any component with the expo prop shape).
|
|
29
|
+
*/
|
|
30
|
+
gradientAtoms?: ReadonlyMap<string, GradientAtomInfo>;
|
|
31
|
+
/**
|
|
32
|
+
* Parser-surfaced haptic metadata per atom. Keys are the full class
|
|
33
|
+
* name (including any variant prefix — `haptic-light`,
|
|
34
|
+
* `active:haptic-medium`). Values are the structured
|
|
35
|
+
* {@link HapticRequest}. The transformer strips matched atoms from
|
|
36
|
+
* the className, aggregates mount requests per enclosing component,
|
|
37
|
+
* and wires press-in chains directly on the element.
|
|
38
|
+
*/
|
|
39
|
+
hapticAtoms?: ReadonlyMap<string, HapticRequest>;
|
|
40
|
+
/**
|
|
41
|
+
* Extra prop-name prefixes that turn `<prefix>ClassName="…"` into
|
|
42
|
+
* `<prefix>Style={lookupCss(…)}` with the same plumbing as the plain
|
|
43
|
+
* `className` path. The built-in `'contentContainer'` prefix is always
|
|
44
|
+
* enabled (covers ScrollView / FlatList / SectionList) — entries here
|
|
45
|
+
* are additive, not a replacement. A user-supplied `['myFunny']` yields
|
|
46
|
+
* the effective set `['contentContainer', 'myFunny']`.
|
|
47
|
+
*
|
|
48
|
+
* Prefixed rewrites never go through `<InteractiveBox>`: the targeted
|
|
49
|
+
* sub-surfaces (scroll content containers, column wrappers, etc.)
|
|
50
|
+
* can't fire press / focus events, so we always emit the inline
|
|
51
|
+
* `lookupCss(…)` call regardless of whether the expression is static
|
|
52
|
+
* or dynamic.
|
|
53
|
+
*/
|
|
54
|
+
classNamePrefixes?: readonly string[];
|
|
55
|
+
/**
|
|
56
|
+
* Extra module specifiers whose JSX exports the transformer should
|
|
57
|
+
* treat as hosts (rewrite `className` → `style` at compile time).
|
|
58
|
+
* Merged with the built-in {@link DEFAULT_HOST_SOURCES} list. Use
|
|
59
|
+
* this for design-system packages whose primitives wrap RN hosts and
|
|
60
|
+
* accept `style` directly.
|
|
61
|
+
*/
|
|
62
|
+
hostSources?: readonly string[];
|
|
63
|
+
/**
|
|
64
|
+
* Extra component names (verbatim, including dotted member access
|
|
65
|
+
* like `'Animated.View'`) the transformer should treat as hosts. Use
|
|
66
|
+
* this for one-off escape-hatches that aren't matchable by source —
|
|
67
|
+
* e.g. you alias `View as MyBox` and want the compile-time path.
|
|
68
|
+
*/
|
|
69
|
+
hostComponents?: readonly string[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Mutate an already-parsed Babel AST in place:
|
|
73
|
+
* - Rewrite every JSX `className="…"` / `className={expr}` attribute to
|
|
74
|
+
* `style={lookupCss(<ref|expr>, _s, <existingStyle>)}`. Static string
|
|
75
|
+
* literals get a module-scope `const _c_<hash> = Object.freeze(['a',
|
|
76
|
+
* 'b'])` hoist so React sees an identity-stable array across renders.
|
|
77
|
+
* - Preserve any adjacent `style={…}` prop — it becomes the third
|
|
78
|
+
* argument so user inline styles keep working (and trump atoms).
|
|
79
|
+
* - Inject `const _s = useScheme()` at the top of the enclosing
|
|
80
|
+
* function component (idempotent — one injection per component).
|
|
81
|
+
* - Prepend `import { lookupCss, useScheme } from 'rnwind'`.
|
|
82
|
+
* - Prepend a side-effect `import 'rnwind/__generated/style'` so the
|
|
83
|
+
* union registry is loaded before any hoist runs.
|
|
84
|
+
* @param ast Babel File AST (usually handed to us by Metro).
|
|
85
|
+
* @param options Extra inputs — side-effect import specifiers + parser metadata.
|
|
86
|
+
* @returns Transform outcome flags + the hoist table.
|
|
87
|
+
*/
|
|
88
|
+
export declare function transformAst(ast: File, options: TransformAstOptions): TransformAstResult;
|