Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 10 additions & 10 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,54 @@ Fork, then clone the repo:
git clone https://github.com/your-username/stylex.git
```

Make sure you have npm@>=7 and node@>=16 installed. Then install the package
Make sure you have [email protected] and node@>=16 installed. Then install the package
dependencies:

```
npm install
yarn install
```

## Automated tests

To run the linter:

```
npm run lint
yarn lint
```

To run flow:

```
npm run flow
yarn flow
```

## Compile and build

To compile the source code:

```
npm run build
yarn build
```

To run all the tests (will build automatically):

```
npm run test
yarn test
```

…in watch mode (will build only once):

```
npm run test -- --watch
yarn test --watch
```

## Documentation

If necessary, first build the StyleX packages (`npm run build`), then start the
If necessary, first build the StyleX packages (`yarn build`), then start the
docs locally:

```
npm run start -w docs
yarn workspace docs start
```

### New Features
Expand All @@ -81,7 +81,7 @@ want to accept.
1. Fork the repository and create your branch from `main`.
2. If you've added code that should be tested, add tests!
3. If you've changed APIs, update the documentation.
4. Ensure the tests pass (`npm run test`).
4. Ensure the tests pass (`yarn test`).

You can now submit a pull request, referencing any issues it addresses.

Expand Down
26 changes: 16 additions & 10 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'yarn'
cache-dependency-path: yarn.lock
- run: corepack prepare [email protected] --activate
- name: 'Setup temporary files'
run: |
echo "BASE_JSON=$(mktemp)" >> $GITHUB_ENV
Expand All @@ -20,8 +23,8 @@ jobs:
run: |
git checkout -f ${{ github.event.pull_request.base.sha }}
git clean -fdx
npm install --loglevel error
if npm run perf -w benchmarks -- -o ${{ env.BASE_JSON }}; then
yarn install --frozen-lockfile --silent
if yarn workspace benchmarks run perf -- -o ${{ env.BASE_JSON }}; then
echo "Ran successfully on base branch"
else
echo "{}" > ${{ env.BASE_JSON }} # Empty JSON as default
Expand All @@ -31,14 +34,14 @@ jobs:
run: |
git checkout -f ${{ github.event.pull_request.head.sha }}
git clean -fdx
npm install --loglevel error
npm run perf -w benchmarks -- -o ${{ env.PATCH_JSON }}
yarn install --frozen-lockfile --silent
yarn workspace benchmarks run perf -- -o ${{ env.PATCH_JSON }}
echo "Ran successfully on patch branch"
- name: 'Collect results'
id: collect
run: |
echo "table<<EOF" >> $GITHUB_OUTPUT
npm run compare -w benchmarks -- ${{ env.BASE_JSON }} ${{ env.PATCH_JSON }} >> markdown
yarn workspace benchmarks run compare -- ${{ env.BASE_JSON }} ${{ env.PATCH_JSON }} >> markdown
cat markdown >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: 'Post comment'
Expand All @@ -63,6 +66,9 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'yarn'
cache-dependency-path: yarn.lock
- run: corepack prepare [email protected] --activate
- name: 'Setup temporary files'
run: |
echo "BASE_JSON=$(mktemp)" >> $GITHUB_ENV
Expand All @@ -71,8 +77,8 @@ jobs:
run: |
git checkout -f ${{ github.event.pull_request.base.sha }}
git clean -fdx
npm install --loglevel error
if npm run size -w benchmarks -- -o ${{ env.BASE_JSON }}; then
yarn install --frozen-lockfile --silent
if yarn workspace benchmarks run size -- -o ${{ env.BASE_JSON }}; then
echo "Ran successfully on base branch"
else
echo "{}" > ${{ env.BASE_JSON }} # Empty JSON as default
Expand All @@ -82,14 +88,14 @@ jobs:
run: |
git checkout -f ${{ github.event.pull_request.head.sha }}
git clean -fdx
npm install --loglevel error
npm run size -w benchmarks -- -o ${{ env.PATCH_JSON }}
yarn install --frozen-lockfile --silent
yarn workspace benchmarks run size -- -o ${{ env.PATCH_JSON }}
echo "Ran successfully on patch branch"
- name: 'Collect results'
id: collect
run: |
echo "table<<EOF" >> $GITHUB_OUTPUT
npm run compare -w benchmarks -- ${{ env.BASE_JSON }} ${{ env.PATCH_JSON }} >> markdown
yarn workspace benchmarks run compare -- ${{ env.BASE_JSON }} ${{ env.PATCH_JSON }} >> markdown
cat markdown >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: 'Post comment'
Expand Down
28 changes: 20 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22.x'
- run: npm install
- run: npm run flow
cache: 'yarn'
cache-dependency-path: yarn.lock
- run: corepack prepare [email protected] --activate
- run: yarn install --frozen-lockfile
- run: yarn flow

packages:
runs-on: ubuntu-latest
Expand All @@ -25,8 +28,11 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22.x'
- run: npm install
- run: npm run test:packages
cache: 'yarn'
cache-dependency-path: yarn.lock
- run: corepack prepare [email protected] --activate
- run: yarn install --frozen-lockfile
- run: yarn test:packages

prettier:
runs-on: ubuntu-latest
Expand All @@ -35,8 +41,11 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22.x'
- run: npm install
- run: npm run prettier:report
cache: 'yarn'
cache-dependency-path: yarn.lock
- run: corepack prepare [email protected] --activate
- run: yarn install --frozen-lockfile
- run: yarn prettier:report

lint:
runs-on: ubuntu-latest
Expand All @@ -45,8 +54,11 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: '22.x'
- run: npm install
- run: npm run lint:report
cache: 'yarn'
cache-dependency-path: yarn.lock
- run: corepack prepare [email protected] --activate
- run: yarn install --frozen-lockfile
- run: yarn lint:report

spelling:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ extend-exclude = [
[default.extend-words]
# Ignore false-positives
stylex = "stylex"
nd = "nd"
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ coverage
lib
flow_modules
node_modules
*.mdx
**/__mocks__/snapshot*
packages/benchmarks/size/fixtures/lotsOfStyles.js
flow-typed
examples/example-storybook/storybook-static
examples/example-cli/src
examples/example-cli/src
packages/docs/.source
7 changes: 6 additions & 1 deletion examples/example-cli/source/app/Counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
'use client';

import * as stylex from '@stylexjs/stylex';
import { spacing, text, globalTokens as $, colors } from '@/app/globalTokens.stylex';
import {
spacing,
text,
globalTokens as $,
colors,
} from '@/app/globalTokens.stylex';
import { useState } from 'react';

export default function Counter() {
Expand Down
4 changes: 2 additions & 2 deletions examples/example-cli/source/app/globalTokens.stylex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,5 @@ export const colors = stylex.defineVars({
gray4: '#ced4da',
gray8: '#343a40',
gray9: '#212529',
lime7: '#74b816'
})
lime7: '#74b816',
});
7 changes: 6 additions & 1 deletion examples/example-cli/source/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
*/

import * as stylex from '@stylexjs/stylex';
import { globalTokens as $, spacing, text, colors } from '../app/globalTokens.stylex';
import {
globalTokens as $,
spacing,
text,
colors,
} from '../app/globalTokens.stylex';
import { tokens } from '../app/CardTokens.stylex';

type Props = Readonly<{
Expand Down
7 changes: 6 additions & 1 deletion examples/example-nextjs/app/Counter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
'use client';

import * as stylex from '@stylexjs/stylex';
import { spacing, text, globalTokens as $, colors } from './globalTokens.stylex';
import {
spacing,
text,
globalTokens as $,
colors,
} from './globalTokens.stylex';
import { useState } from 'react';

export default function Counter() {
Expand Down
4 changes: 2 additions & 2 deletions examples/example-nextjs/app/globalTokens.stylex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,5 @@ export const colors = stylex.defineVars({
gray4: '#ced4da',
gray8: '#343a40',
gray9: '#212529',
lime7: '#74b816'
})
lime7: '#74b816',
});
10 changes: 5 additions & 5 deletions examples/example-react-router/src/entry.rsc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
decodeReply,
loadServerAction,
renderToReadableStream,
} from "@vitejs/plugin-rsc/rsc";
import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
} from '@vitejs/plugin-rsc/rsc';
import { unstable_matchRSCServerRequest as matchRSCServerRequest } from 'react-router';

import { routes } from "./routes/config";
import { routes } from './routes/config';

function fetchServer(request: Request) {
return matchRSCServerRequest({
Expand All @@ -35,8 +35,8 @@ function fetchServer(request: Request) {
export default async function handler(request: Request) {
// Import the generateHTML function from the client environment
const ssr = await import.meta.viteRsc.loadModule<
typeof import("./entry.ssr")
>("ssr", "index");
typeof import('./entry.ssr')
>('ssr', 'index');

return ssr.generateHTML(request, fetchServer);
}
Expand Down
10 changes: 5 additions & 5 deletions examples/example-react-router/src/entry.ssr.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
import { renderToReadableStream as renderHTMLToReadableStream } from "react-dom/server.edge";
import { createFromReadableStream } from '@vitejs/plugin-rsc/ssr';
import { renderToReadableStream as renderHTMLToReadableStream } from 'react-dom/server.edge';
import {
unstable_routeRSCServerRequest as routeRSCServerRequest,
unstable_RSCStaticRouter as RSCStaticRouter,
} from "react-router";
} from 'react-router';

export async function generateHTML(
request: Request,
Expand All @@ -20,10 +20,10 @@ export async function generateHTML(
async renderHTML(getPayload) {
const payload = await getPayload();
const formState =
payload.type === "render" ? await payload.formState : undefined;
payload.type === 'render' ? await payload.formState : undefined;

const bootstrapScriptContent =
await import.meta.viteRsc.loadBootstrapScriptContent("index");
await import.meta.viteRsc.loadBootstrapScriptContent('index');

return await renderHTMLToReadableStream(
<RSCStaticRouter getPayload={getPayload} />,
Expand Down
18 changes: 9 additions & 9 deletions examples/example-react-router/src/routes/config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import type { unstable_RSCRouteConfig as RSCRouteConfig } from "react-router";
import type { unstable_RSCRouteConfig as RSCRouteConfig } from 'react-router';

export function routes() {
return [
{
id: "root",
path: "",
lazy: () => import("./root/route"),
id: 'root',
path: '',
lazy: () => import('./root/route'),
children: [
{
id: "home",
id: 'home',
index: true,
lazy: () => import("./home/route"),
lazy: () => import('./home/route'),
},
{
id: "about",
path: "about",
lazy: () => import("./about/route"),
id: 'about',
path: 'about',
lazy: () => import('./about/route'),
},
],
},
Expand Down
8 changes: 4 additions & 4 deletions examples/example-react-router/src/routes/root/route.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Outlet } from "react-router";
import "../../stylex.css";
import { Outlet } from 'react-router';
import '../../stylex.css';

import { Layout as ClientLayout } from "./client";
import { Layout as ClientLayout } from './client';

export { ErrorBoundary } from "./client";
export { ErrorBoundary } from './client';

export function Layout({ children }: { children: React.ReactNode }) {
// This is necessary for the bundler to inject the needed CSS assets.
Expand Down
2 changes: 1 addition & 1 deletion examples/example-redwoodsdk/src/app/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Welcome } from "./Welcome.js";
import { Welcome } from './Welcome.js';

export const Home = () => {
// _Feel free to delete this element and its import_
Expand Down
4 changes: 2 additions & 2 deletions examples/example-redwoodsdk/src/app/shared/links.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { defineLinks } from "rwsdk/router";
import { defineLinks } from 'rwsdk/router';

export const link = defineLinks(["/"]);
export const link = defineLinks(['/']);
2 changes: 1 addition & 1 deletion examples/example-redwoodsdk/src/client.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { initClient } from "rwsdk/client";
import { initClient } from 'rwsdk/client';

initClient();
Loading