Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nmn
Copy link
Contributor

@nmn nmn commented Oct 14, 2024

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

  • I'm not sure if the current logic is safe on Windows.

Next Steps

  • Add more tests
  • Update the config options to make theming APIs on by default.
  • Update the debug classNames to generate the data-style-src attribute instead.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 14, 2024
Copy link

github-actions bot commented Oct 14, 2024

workflow: benchmarks/size

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

@stylexjs/[email protected] 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

filepath: string,
): null | [+packageName: string, +packageDir: string] {
const folder = path.dirname(filepath);
if (folder === '/' || folder === '') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently the right way to do this for cross-platform support is

if (folder === path.parse(folder).root)

or

if (folder === path.sep || folder === '')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants