rnwind 0.0.1 → 0.0.2
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 +164 -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 +100 -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 +96 -0
- package/lib/cjs/core/parser/length.cjs.map +1 -0
- package/lib/cjs/core/parser/length.d.ts +48 -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 +156 -0
- package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
- package/lib/cjs/core/parser/shorthand.d.ts +61 -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 +414 -0
- package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
- package/lib/cjs/core/parser/theme-vars.d.ts +61 -0
- package/lib/cjs/core/parser/tokens.cjs +304 -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 +1567 -0
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
- package/lib/cjs/core/parser/tw-parser.d.ts +194 -0
- package/lib/cjs/core/parser/types.d.ts +37 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs +93 -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 +397 -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 +251 -0
- package/lib/cjs/metro/state.cjs.map +1 -0
- package/lib/cjs/metro/state.d.ts +72 -0
- package/lib/cjs/metro/transform-ast.cjs +1255 -0
- package/lib/cjs/metro/transform-ast.cjs.map +1 -0
- package/lib/cjs/metro/transform-ast.d.ts +73 -0
- package/lib/cjs/metro/transformer.cjs +345 -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 +57 -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 +162 -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 +98 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/length.d.ts +48 -0
- package/lib/esm/core/parser/length.mjs +90 -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 +61 -0
- package/lib/esm/core/parser/shorthand.mjs +148 -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 +61 -0
- package/lib/esm/core/parser/theme-vars.mjs +409 -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 +298 -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 +194 -0
- package/lib/esm/core/parser/tw-parser.mjs +1565 -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 +91 -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 +395 -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 +72 -0
- package/lib/esm/metro/state.mjs +243 -0
- package/lib/esm/metro/state.mjs.map +1 -0
- package/lib/esm/metro/transform-ast.d.ts +73 -0
- package/lib/esm/metro/transform-ast.mjs +1234 -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 +322 -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 +57 -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 +79 -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 +157 -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 +92 -0
- package/src/core/parser/length.ts +100 -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 +152 -0
- package/src/core/parser/text-truncate.ts +79 -0
- package/src/core/parser/theme-vars.ts +412 -0
- package/src/core/parser/tokens.ts +286 -0
- package/src/core/parser/transform.ts +195 -0
- package/src/core/parser/tw-parser.ts +1709 -0
- package/src/core/parser/types.ts +45 -0
- package/src/core/parser/typography-dispatcher.ts +83 -0
- package/src/core/parser/typography.ts +83 -0
- package/src/core/style-builder/build-style.ts +442 -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 +257 -0
- package/src/metro/transform-ast.ts +1498 -0
- package/src/metro/transformer.ts +347 -0
- package/src/metro/warn-unknown-classes.ts +79 -0
- package/src/metro/with-config.ts +229 -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,257 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { UnionBuilder } from '../core/style-builder'
|
|
5
|
+
import { TailwindParser, type SourceEntry } from '../core/parser'
|
|
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: string, cacheDir: string, watchFolders: readonly string[]): readonly SourceEntry[] {
|
|
25
|
+
const cacheBaseName = path.basename(cacheDir)
|
|
26
|
+
const roots = new Set<string>([projectRoot, ...watchFolders])
|
|
27
|
+
const sources: SourceEntry[] = []
|
|
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
|
+
/**
|
|
35
|
+
* Read monorepo watch-folder paths out of the worker environment.
|
|
36
|
+
* Empty array when the host isn't a monorepo.
|
|
37
|
+
* @returns Absolute paths Metro also watches (sibling packages).
|
|
38
|
+
*/
|
|
39
|
+
function readWatchFolders(): readonly string[] {
|
|
40
|
+
const raw = process.env[WATCH_FOLDERS_ENV]
|
|
41
|
+
if (!raw || raw.length === 0) return []
|
|
42
|
+
return raw.split('\0').filter((entry) => entry.length > 0)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Env var Metro workers read to locate the theme CSS on disk. */
|
|
46
|
+
const CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE'
|
|
47
|
+
/** Env var Metro workers read to locate the cache directory (`.rnwind`). */
|
|
48
|
+
const CACHE_DIR_ENV = 'RNWIND_CACHE_DIR'
|
|
49
|
+
/** Env var carrying `watchFolders` from Metro config (NUL-separated). */
|
|
50
|
+
const WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS'
|
|
51
|
+
/** Env var carrying extra className prefixes the Metro config supplied. */
|
|
52
|
+
const CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES'
|
|
53
|
+
|
|
54
|
+
/** Memoised library fingerprint — read once per worker process. */
|
|
55
|
+
let libraryFingerprint: string | undefined
|
|
56
|
+
|
|
57
|
+
/** Live state shared across one Metro transform worker. */
|
|
58
|
+
let cached: RnwindState | null = null
|
|
59
|
+
|
|
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: string): string {
|
|
69
|
+
if (!existsSync(cssPath)) return 'missing'
|
|
70
|
+
try {
|
|
71
|
+
const bytes = readFileSync(cssPath)
|
|
72
|
+
const mtime = statSync(cssPath).mtimeMs.toString()
|
|
73
|
+
return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16)
|
|
74
|
+
} catch {
|
|
75
|
+
return 'missing'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Hash a small set of rnwind library files whose changes affect the
|
|
81
|
+
* generated transform output. When the library is rebuilt (workspace
|
|
82
|
+
* dev OR npm install of a new version) the file bytes change, the
|
|
83
|
+
* fingerprint rotates, and Metro's transform cache invalidates.
|
|
84
|
+
*
|
|
85
|
+
* Includes the JSX rewriter (`transform-ast`) alongside the parser /
|
|
86
|
+
* style-builder so a change to the transformer — e.g. renaming the
|
|
87
|
+
* injected context hook — invalidates every stale per-file cache entry
|
|
88
|
+
* on the next dev run. Without this, a user upgrading rnwind in-place
|
|
89
|
+
* would keep loading the old transformed bytes; React-refresh would
|
|
90
|
+
* then preserve fiber state across the version bump and the rendered
|
|
91
|
+
* hook list could shift, surfacing as "change in the order of Hooks"
|
|
92
|
+
* runtime errors.
|
|
93
|
+
* Memoised — read once per worker process.
|
|
94
|
+
* @returns 16-char hex fingerprint.
|
|
95
|
+
*/
|
|
96
|
+
function getLibraryFingerprint(): string {
|
|
97
|
+
if (libraryFingerprint !== undefined) return libraryFingerprint
|
|
98
|
+
const here = path.dirname(__filename)
|
|
99
|
+
const candidates = [
|
|
100
|
+
path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),
|
|
101
|
+
path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),
|
|
102
|
+
path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),
|
|
103
|
+
path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),
|
|
104
|
+
path.resolve(here, 'transform-ast.mjs'),
|
|
105
|
+
path.resolve(here, 'transform-ast.cjs'),
|
|
106
|
+
path.resolve(here, 'transformer.mjs'),
|
|
107
|
+
path.resolve(here, 'transformer.cjs'),
|
|
108
|
+
// Source-tree fallback for tests + workspace dev (no built lib yet).
|
|
109
|
+
path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),
|
|
110
|
+
path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),
|
|
111
|
+
path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),
|
|
112
|
+
path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),
|
|
113
|
+
]
|
|
114
|
+
const hash = createHash('sha256')
|
|
115
|
+
let included = 0
|
|
116
|
+
for (const file of candidates) {
|
|
117
|
+
if (!existsSync(file)) continue
|
|
118
|
+
try {
|
|
119
|
+
hash.update(readFileSync(file))
|
|
120
|
+
included += 1
|
|
121
|
+
} catch {
|
|
122
|
+
// Unreadable file — skip; fingerprint still derives from whatever WE could read.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)
|
|
126
|
+
return libraryFingerprint
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Worker-local state. Lazy-initialised on first access so files that
|
|
131
|
+
* bypass the transform don't pay for construction.
|
|
132
|
+
*/
|
|
133
|
+
export interface RnwindState {
|
|
134
|
+
parser: TailwindParser
|
|
135
|
+
builder: UnionBuilder
|
|
136
|
+
themeCss: string
|
|
137
|
+
themeHash: string
|
|
138
|
+
projectRoot: string
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Publish the theme CSS path + cache dir to the environment so worker
|
|
143
|
+
* subprocesses (spawned by Metro once `babelTransformerPath` is set)
|
|
144
|
+
* can rebuild the same state without re-reading the Metro config.
|
|
145
|
+
* @param cssEntryFile Absolute path to the user's theme CSS.
|
|
146
|
+
* @param cacheDir Absolute path to the cache dir (`.rnwind`).
|
|
147
|
+
* @param watchFolders
|
|
148
|
+
* @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
|
|
149
|
+
*/
|
|
150
|
+
export function configureRnwindState(
|
|
151
|
+
cssEntryFile: string,
|
|
152
|
+
cacheDir: string,
|
|
153
|
+
watchFolders: readonly string[] = [],
|
|
154
|
+
classNamePrefixes?: readonly string[],
|
|
155
|
+
): void {
|
|
156
|
+
process.env[CSS_ENTRY_ENV] = cssEntryFile
|
|
157
|
+
process.env[CACHE_DIR_ENV] = cacheDir
|
|
158
|
+
if (watchFolders.length === 0) {
|
|
159
|
+
delete process.env[WATCH_FOLDERS_ENV]
|
|
160
|
+
} else {
|
|
161
|
+
process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\0')
|
|
162
|
+
}
|
|
163
|
+
if (!classNamePrefixes || classNamePrefixes.length === 0) {
|
|
164
|
+
delete process.env[CLASSNAME_PREFIXES_ENV]
|
|
165
|
+
} else {
|
|
166
|
+
process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')
|
|
167
|
+
}
|
|
168
|
+
cached = null
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Read the caller-configured extra className prefixes out of the
|
|
173
|
+
* worker environment. Returns an empty array when unset — the
|
|
174
|
+
* transformer applies the built-in `contentContainer` default on top
|
|
175
|
+
* either way.
|
|
176
|
+
* @returns User-supplied extra prefixes.
|
|
177
|
+
*/
|
|
178
|
+
export function getClassNamePrefixes(): readonly string[] {
|
|
179
|
+
const raw = process.env[CLASSNAME_PREFIXES_ENV]
|
|
180
|
+
if (!raw || raw.length === 0) return []
|
|
181
|
+
return raw.split(',').filter((entry) => entry.length > 0)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Fetch (or build) the worker-local rnwind state. Re-reads the theme
|
|
186
|
+
* CSS hash on every call: if the user edited `global.css` while Metro
|
|
187
|
+
* is running, the cached state is dropped and a fresh parser + ledger
|
|
188
|
+
* is built. Combined with the `getCacheKey()` export on the
|
|
189
|
+
* transformer (which folds the same hash into Metro's per-file cache
|
|
190
|
+
* key) every CSS edit produces a full, correct re-bundle.
|
|
191
|
+
* @param projectRoot
|
|
192
|
+
* @returns The live rnwind state.
|
|
193
|
+
*/
|
|
194
|
+
export function getRnwindState(projectRoot: string): RnwindState {
|
|
195
|
+
const cssEntry = process.env[CSS_ENTRY_ENV]
|
|
196
|
+
const cacheDir = process.env[CACHE_DIR_ENV]
|
|
197
|
+
if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')
|
|
198
|
+
if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')
|
|
199
|
+
const currentHash = readThemeHashFor(cssEntry)
|
|
200
|
+
if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached
|
|
201
|
+
const themeCss = readFileSync(cssEntry, 'utf8')
|
|
202
|
+
const parser = new TailwindParser({
|
|
203
|
+
themeCss,
|
|
204
|
+
sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),
|
|
205
|
+
})
|
|
206
|
+
const builder = new UnionBuilder(cacheDir, parser)
|
|
207
|
+
cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }
|
|
208
|
+
return cached
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Compute the rnwind cache-key suffix Metro mixes into every per-file
|
|
213
|
+
* transform cache entry via the transformer's `getCacheKey()` export.
|
|
214
|
+
* Includes the CSS path + its current content hash + the rnwind
|
|
215
|
+
* library fingerprint, so any edit to `global.css` OR a library
|
|
216
|
+
* upgrade flips the cache key and forces Metro to re-run the
|
|
217
|
+
* transformer.
|
|
218
|
+
* @returns Deterministic string suitable for appending to Metro's cache key.
|
|
219
|
+
*/
|
|
220
|
+
export function getRnwindCacheKey(): string {
|
|
221
|
+
const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''
|
|
222
|
+
const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''
|
|
223
|
+
return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}`
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Drop the cached state — call after editing the theme CSS. */
|
|
227
|
+
export function resetRnwindState(): void {
|
|
228
|
+
cached = null
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Drop cached state, rebuild parser/builder with the fresh CSS, rescan
|
|
233
|
+
* the project, and rewrite every scheme file on disk. This is what
|
|
234
|
+
* `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits
|
|
235
|
+
* propagate to the app via Metro's HMR — without this, the CSS-as-JS
|
|
236
|
+
* module would re-emit `export {}` whose bytes never change, so Metro
|
|
237
|
+
* would never invalidate downstream modules.
|
|
238
|
+
* @param projectRoot Absolute project root (from `metroConfig.projectRoot`).
|
|
239
|
+
*/
|
|
240
|
+
export async function onThemeChange(projectRoot: string): Promise<void> {
|
|
241
|
+
resetRnwindState()
|
|
242
|
+
const state = getRnwindState(projectRoot)
|
|
243
|
+
await state.builder.writeSchemes()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Resolve the on-disk path of the scheme manifest module for the
|
|
248
|
+
* resolver. The manifest eager-imports `common.style.js` and
|
|
249
|
+
* lazy-requires each variant scheme; SchemeProvider calls its
|
|
250
|
+
* `ensureSchemeLoaded` export to trigger per-scheme requires.
|
|
251
|
+
* @returns Absolute path to `<cacheDir>/schemes.js`.
|
|
252
|
+
*/
|
|
253
|
+
export function manifestPathFor(): string {
|
|
254
|
+
const cacheDir = process.env[CACHE_DIR_ENV]
|
|
255
|
+
if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')
|
|
256
|
+
return path.join(cacheDir, 'schemes.js')
|
|
257
|
+
}
|