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

Add path logger #222

Merged
merged 4 commits into from
Jan 23, 2025
Merged

Add path logger #222

merged 4 commits into from
Jan 23, 2025

Conversation

mattstyles
Copy link
Contributor

@mattstyles mattstyles commented Jan 22, 2025

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Adds debug logging to rs-compiler based on the value of the environment variable STYLEX_DEBUG. If this env variable does not exist (or does not match the log levels below) then no log information will be output (same behaviour as now).

Log levels supported:

  • error
  • warn
  • info
  • debug

I have only added a few log instances to rs-compiler as I'm not sure on which areas are going to be most valuable.

Logs in this diff show which files are being traversed, and provides information on the resolved import path from the list of potential valid import paths.

Additional Info

I've added an info log and some debug logs regarding pathing of stylex imports.

$ STYLEX_DEBUG=debug pnpm run build

INFO stylex_compiler_rs                               > Transforming source file: /Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/app/Counter.tsx
INFO stylex_compiler_rs                               > Transforming source file: /Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/app/globalTokens.stylex.ts
INFO stylex_compiler_rs                               > Transforming source file: /Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/components/Card.tsx
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["app/globalTokens.stylex", "node_modules/@/app/globalTokens.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@/app/globalTokens.stylex"] for import `@/app/globalTokens.stylex`
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["app/globalTokens.stylex", "node_modules/@/app/globalTokens.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@/app/globalTokens.stylex"] for import `@/app/globalTokens.stylex`
DEBUG stylex_shared::shared::structures::state_manager > Resolved import path: app/globalTokens.stylex.ts
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["app/globalTokens.stylex", "node_modules/@/app/globalTokens.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@/app/globalTokens.stylex"] for import `@/app/globalTokens.stylex`
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["app/globalTokens.stylex", "node_modules/@/app/globalTokens.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@/app/globalTokens.stylex"] for import `@/app/globalTokens.stylex`
DEBUG stylex_shared::shared::structures::state_manager > Resolved import path: app/globalTokens.stylex.ts
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["app/CardTokens.stylex", "node_modules/@/app/CardTokens.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@/app/CardTokens.stylex"] for import `@/app/CardTokens.stylex`
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["app/CardTokens.stylex", "node_modules/@/app/CardTokens.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@/app/CardTokens.stylex"] for import `@/app/CardTokens.stylex`
DEBUG stylex_shared::shared::structures::state_manager > Resolved import path: app/CardTokens.stylex.ts
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["node_modules/@stylexjs/open-props/lib/colors.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@stylexjs/open-props/lib/colors.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@stylexjs/open-props/lib/colors.stylex.js", "node_modules/@stylexjs/open-props/lib/colors.stylex.js"] for import `@stylexjs/open-props/lib/colors.stylex`
DEBUG stylex_shared::shared::structures::state_manager > Resolved import path: /Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@stylexjs/open-props/lib/colors.stylex.js
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["app/globalTokens.stylex", "node_modules/@/app/globalTokens.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@/app/globalTokens.stylex"] for import `@/app/globalTokens.stylex`
DEBUG stylex_path_resolver::resolvers                  > Resolved potential paths: ["app/globalTokens.stylex", "node_modules/@/app/globalTokens.stylex", "/Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/apps/nextjs-postcss-example/node_modules/@/app/globalTokens.stylex"] for import `@/app/globalTokens.stylex`
DEBUG stylex_shared::shared::structures::state_manager > Resolved import path: app/globalTokens.stylex.ts
INFO stylex_compiler_rs                               > Transforming source file: /Users/mattstyles/projects/third-party/forks/stylex-swc-plugin/node_modules/.pnpm/@stylexjs+stylex@0.10.1/node_modules/@stylexjs/stylex/lib/es/stylex.mjs

Type of change

Please select options that are relevant.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • [-] I have made corresponding changes to the documentation
  • New and existing unit tests pass locally with my changes
  • I have read the CONTRIBUTING document

crates/stylex-rs-compiler/src/structs/mod.rs Outdated Show resolved Hide resolved
crates/stylex-shared/src/shared/utils/js/evaluate.rs Outdated Show resolved Hide resolved
crates/stylex-shared/src/shared/utils/log/logger.rs Outdated Show resolved Hide resolved
@Dwlad90
Copy link
Owner

Dwlad90 commented Jan 22, 2025

Hi @mattstyles, thanks for the PR, great job.

It really does look a bit noisy, but I think the debugging value outweighs that.

It's probably worth printing out potentially valid import paths for StyleX files in crates/stylex-path-resolver/src/resolvers/mod.rs:411 file. Bugs are mostly related to this. Usually the correct path is missing from the list.

Something like this:

debug!("Resolved file paths: {:?} for import `{}`", valid_file_paths, import_path_str);

@Dwlad90
Copy link
Owner

Dwlad90 commented Jan 23, 2025

/merge

@github-actions github-actions bot merged commit 77c00a3 into Dwlad90:develop Jan 23, 2025
3 checks passed
Copy link
Contributor

Success! Fast forwarded develop to add-path-logger!

@Dwlad90 Dwlad90 temporarily deployed to release-approval January 23, 2025 16:14 — with GitHub Actions Inactive
@Dwlad90 Dwlad90 temporarily deployed to changlog-approval January 23, 2025 16:16 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants