-
Notifications
You must be signed in to change notification settings - Fork 310
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
A CLI to compile an entire folder with StyleX #412
Conversation
Note that this is kind of how the RN ecosystem (Expo) handles compiling RN packages for web, and it's pretty fragile because someone has to know a list of all dependencies and sub-dependencies that might be need processing. Probably a bit of a challenge to reliably do that automatically. Do you know if the other CLI-based projects have any alternatives, or does everything expect the developer to list out the packages to be processed? |
I know that Next has a I understand that the |
compressed-size: runtime library Size change: 0.00 kB View unchanged
|
compressed-size: e2e bundles Size change: 0.00 kB View unchanged
|
Converting to draft while it's progress. Mark it as ready for review, when it's ... ready for review. |
This is ready for an initial review. I have no idea how to make eslint ignore my test files that are transfomed by babel. I tried adding to the |
I figured it out |
@nmn any word on when this will land? If this is close I don't mind using a beta version and testing it out if you push a release! |
packages/cli/README.md
Outdated
@@ -0,0 +1,257 @@ | |||
# @stylexjs/stylex |
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.
Don't forget to replace this README
var stylex = _interopRequireWildcard(require("@stylexjs/stylex")); | ||
var _otherStyles = _interopRequireDefault(require("./otherStyles")); | ||
var _npmStyles = _interopRequireDefault(require("./npmStyles")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
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 wonder if for the sake of making these snapshots more readable we can avoid the babel module interop code appearing here
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.
Is this an option that can be passed into babel? These files are supposed to be the expected output of the CLI, so I think adding a specific option for tests degrades the integrity of the tests a bit.
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.
Yes, this is an option that can be passed into Babel. We don't want any transform other than StyleX to run. So we probably just need to set babelrc: false
to ensure that is the case.
@@ -0,0 +1,40 @@ | |||
'use strict'; | |||
|
|||
Object.defineProperty(exports, "__esModule", { |
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.
Are these files mock snapshots? Or snapshots that accidentally got saved in the mocks directory? (File path is __mocks__/snapshot
)
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.
These are files I created by manually running mocks/source through the CLI in order to use in my tests to validate the output.
packages/cli/src/index.js
Outdated
chalk.green(`\n | ||
______ _ _ __ __ | ||
/ ____| | | | | \\ \\ / / | ||
| (___ | |_ _ _ | | ___ \\ V / | ||
\\___ \\ | __| | | | | | | / _ \\ > < | ||
____) | | |_ | |_| | | | | __/ / . \\ | ||
|_____/ \\__| \\__, | |_| \\___| /_/ \\_\\ | ||
__/ | | ||
|___/ | ||
`), |
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.
This doesn't looks particularly readable
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 some escaped characters. I'll attach a screenshot of what it looks like in the CLI.
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.
packages/cli/src/options.js
Outdated
export default { | ||
directory: { | ||
alias: 'd', | ||
describe: 'The directory to compile with Stylex', |
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.
describe: 'The directory to compile with Stylex', | |
describe: 'The directory to compile with StyleX', |
Looks like a few improvements still need to be made. I'll try to do this on my end shortly. |
…stable_moduleResolution
Use the `lib` folder, not the `src` folder for the output of the package.
Closing to open a new one because something is messed up with github |
What changed / motivation ?
StyleX needs a bundler integration to work correctly. It also depends on Babel. However, this can be burden when trying to integrate into various projects built with project starters like Next.js, Solid Start and create-react-app. These projects have a complex bundler setup and it can be hard to integrate into them correctly. In some cases, like Next, the tooling may be written in Rust where an integration of the Babel plugin is impossible.
In order to provide a clean and reliable escape hatch for these scenarios, we should have a CLI that transforms an entire folder of JS files and outputs the resulting CSS file. (Tools like Tailwind and PandaCSS similarly side-step the built-in bundler because of how hard it is to integrate)
Expected Behaviour
For this example, consider a Next.js app configured to use the
src/
folder with asrc/app/
within that contains actual routes. When using the CLI, you'd be able to make another folder called, say,source/
and gitignoresrc/
folder. Thesource/
folder would contain all the same files that would normally be defined within thesrc/
folder, but you'd be able to use StyleX.The CLI will then:
source/
folder with the StyleX Babel plugin and output it at the same relative path in thesrc/
folder.src/stylex-bundle.css
.stylex-bundle.css
file. (Configurable)With this process, the StyleX CLI would run first and generate an
src/
folder with your actual source code. After this, the usualnext dev
script will be able to take over and run as usual.Additionally, the CLI should also:
watch
mode so that only the files that are edited are recompiled, and the generated CSS file is updated accordingly.node_modules
packages and write the compiled files in some locations.Finally, there are a few requirements for the configuration (This is probably a lot of the work):
.babelrc
file at the project root. (Next goes into Babel mode if it detect a.babelrc
file)Stretch Goals
Possible tools that can be used:
fb-watchman
is a node client forwatchman
. A tool that tracks file changes within a folderchokidar
node-watch