-
Notifications
You must be signed in to change notification settings - Fork 319
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
Fixed flow and prettier tests failing Correct install of json5 dependency fix: Resolve alias paths to absolute paths
105df51
to
639a876
Compare
|
||
// Load aliases from package.json imports field | ||
try { | ||
const packageJsonPath = path.join(projectDir, 'package.json'); |
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.
there's a lot of repeated code within these 3 try blocks - can we refactor to use a loop on ["package.json", "tsconfig.json", "deno.json"]
, will also make it more maintainable if we want to add support to other configs as follow ups
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
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: