-
Notifications
You must be signed in to change notification settings - Fork 326
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 Discover StyleX Aliases from Configuration Files (Rebased PR of #810) #856
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.
Fixed flow and prettier tests failing Correct install of json5 dependency fix: Resolve alias paths to absolute paths
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.
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.json
for Node.js native subpath imports (aliases with#
prefix).tsconfig.json
forcompilerOptions.paths
and resolves paths relative tobaseUrl
.deno.json
for theimports
field.Manual >
package.json
>tsconfig.json
>deno.json
.findProjectRoot
withgetPackageNameAndPath
for project root discovery.Test Coverage
The following scenarios are tested:
1. Alias Discovery:
package.json
(subpath imports).tsconfig.json
paths.deno.json
imports.2. Configuration Merging:
3. Manual Overrides:
4. Error Handling:
Code Changes
1.
state-manager.js
(Alias Discovery)loadAliases
:stylex.aliases
support.getPackageNameAndPath
.deno.json
imports.2.
stylex-transform-alias-config-test.js
deno.json
imports.Potential Future Improvements
Enhanced Test Cases:
Additional Features:
Performance Optimizations:
Pre-flight Checklist
Feedback
Feedback is welcome, particularly for: