facebook / stylex

StyleX is the styling system for ambitious user interfaces.
https://stylexjs.com
MIT License
8.44k stars 310 forks source link

feat: automatically resolve name from containing package.json #745

Closed nmn closed 1 month ago

nmn commented 1 month ago

Walk tree to find package name from package.json file

This PR adds a tree walker to walk up the tree and find the nearest package.json file and use the name from that file to generate the "canonical file path" for a file.

This canonical file path is used for generating the variable names for:

  1. defineVars calls within .stylex.js files
  2. The debug classNames

Benefits

This change removes the need for passing in rootDir for the theming APIs to work.

Possible concerns

Next Steps

github-actions[bot] commented 1 month ago

workflow: benchmarks/size

Comparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.

@stylexjs/scripts@0.8.0 size:compare ./size-compare.js /tmp/tmp.Fqm60yXUcS /tmp/tmp.IQRH59lFlu

Results Base Patch Ratio
stylex/lib/stylex.js
· compressed 729 729 1.00
· minified 2,541 2,541 1.00
stylex/lib/StyleXSheet.js
· compressed 1,266 1,266 1.00
· minified 3,776 3,776 1.00
rollup-example/.build/bundle.js
· compressed 563,025 563,025 1.00
· minified 10,185,368 10,185,368 1.00
rollup-example/.build/stylex.css
· compressed 99,154 99,154 1.00
· minified 745,649 745,649 1.00