-
Couldn't load subscription status.
- Fork 349
Feat: Automatically Discover StyleX Aliases from Configuration Files (Rebased PR of #810) #856
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
base: main
Are you sure you want to change the base?
Conversation
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
a4654f6 to
105df51
Compare
105df51 to
639a876
Compare
| const [_packageName, projectDir] = pkgInfo; | ||
|
|
||
| const resolveAliasPaths = (value: string | $ReadOnlyArray<string>) => | ||
| (Array.isArray(value) ? value : [value]).map((p) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should consider moving some of this logic to a separate files utils, there's some path functions in the cache.js utils that I also want to extract
| ...denoAliases, | ||
| ...tsconfigAliases, | ||
| ...packageAliases, | ||
| ...(manualAliases || {}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need manualAliases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to remove it in the same commit, but we could probably remove them in the future once we are sure this feature is working for the wide variety of project types.
We could deprecate it in the next release and delete it entirely after.
0430e86 to
0de16c3
Compare
| import os from 'os'; | ||
| import StateManager from '../src/utils/state-manager'; | ||
|
|
||
| describe('StyleX Alias Configuration', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write tests against the public API. If we refactor the internals, tests like this would likely need to be rewritten. And this test doesn't actually validate that real code is correctly processed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. Will need to simulate a filesystem or similar to make this happen, but should be doable.
…/babel-preset Until facebook/stylex#856 is merged and released, this is kind of the only option to be able to write imports like defined in a tsconfig file.
|
Are you still working on this @nmn ? |
|
I will rebase this PR and rewrite the tests soon. I was travelling for a while and had little time. |
Fixed flow and prettier tests failing Correct install of json5 dependency fix: Resolve alias paths to absolute paths
workflow: benchmarks/perfComparison of performance test results, measured in operations per second. Larger is better.
|
| try { | ||
| const filePath = path.join(projectDir, fileName); | ||
| if (fs.existsSync(filePath)) { | ||
| const rawConfig: mixed = JSON5.parse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the JSON5 dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just to allow the config file to have comments, trailing commas etc.
It's like JSONC, but a more permissive superset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okk
|
any update on this? |
What changed / motivation ?
This a rebased implementation of #810 with bug fixes.
[Feature] Automatically Discover StyleX Aliases from Configuration Files
Linked Issues
Fixes #765
Overview
This PR enhances the StyleX Babel plugin to automatically discover alias configurations from Node.js native imports (
package.json),tsconfig.json, anddeno.json. It ensures normalized paths for cross-platform compatibility and maintains backward compatibility with existing manual configurations.Implementation Details
package.jsonfor Node.js native subpath imports (aliases with#prefix).tsconfig.jsonforcompilerOptions.pathsand resolves paths relative tobaseUrl.deno.jsonfor theimportsfield.Manual >
package.json>tsconfig.json>deno.json.findProjectRootwithgetPackageNameAndPathfor project root discovery.Test Coverage
The following scenarios are tested:
1. Alias Discovery:
package.json(subpath imports).tsconfig.jsonpaths.deno.jsonimports.2. Configuration Merging:
3. Manual Overrides:
4. Error Handling:
Code Changes
1.
state-manager.js(Alias Discovery)loadAliases:stylex.aliasessupport.getPackageNameAndPath.deno.jsonimports.2.
stylex-transform-alias-config-test.jsdeno.jsonimports.Potential Future Improvements
Enhanced Test Cases:
Additional Features:
Performance Optimizations:
Pre-flight Checklist
Feedback
Feedback is welcome, particularly for: