Skip to content

Commit

Permalink
Merge branch 'main' into feature/tests-for-prod-environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon authored Nov 29, 2024
2 parents 8b5a8d8 + eabe5d8 commit ef37699
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 5,572 deletions.
2 changes: 2 additions & 0 deletions .changeset/honest-cameras-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
30 changes: 28 additions & 2 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,58 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 20

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9.12.3
run_install: false

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Add wasm32-wasi target
run: rustup target add wasm32-wasi

- name: Enable caching
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/yak-swc

- name: Build with SWC
run: pnpm run build:swc

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install

- name: Build Yak
run: pnpm run build

- name: Build benchmark suite
run: cd packages/benchmarks && pnpm run codspeed

- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
Expand Down
61 changes: 25 additions & 36 deletions packages/benchmarks/letters/gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as swc from "@swc/core";
import { writeFile } from "fs";
import tsLoader from "../../next-yak/loaders/ts-loader";

// Function to generate the content of JapaneseLetterComponent.tsx for Kanji characters
async function generateKanjiComponentFile() {
Expand All @@ -19,7 +19,7 @@ async function generateKanjiComponentFile() {
const styled = libs[lib];

const fileContent = `
"use client";
"use client";
import React, { type FunctionComponent } from 'react';
import ${
lib === "next-yak" ? `{ styled as ${styled}, css }` : `{ ${styled}, css }`
Expand Down Expand Up @@ -233,10 +233,10 @@ export const KanjiLetterComponent${
<LibHeader onClick={() => document.location.href = "${
lib === "next-yak" ? "/styled" : "/yak"
}"}>${lib}</LibHeader>
<Wrapper
style={{
<Wrapper
style={{
// @ts-ignore
"--count0": count0
"--count0": count0
}}
className={\`wrapper-\${count5}\`}
>
Expand Down Expand Up @@ -280,7 +280,7 @@ export const KanjiLetterComponent${
)
.join("\n ")}
</Wrapper>
<a href="https://github.com/jantimon/next-yak/">next-yak</a>
</>
);
Expand All @@ -300,38 +300,27 @@ export const KanjiLetterComponent${

// Precompile yak similar to how it would be compiled by our loader
if (lib === "next-yak") {
const loaderContext = {
resourcePath: "/some/special/path/page.tsx",
rootContext: "/some",
mode: "development",
importModule: () => {
return {
replaces: {
queries: {
sm: "@media (min-width: 640px)",
md: "@media (min-width: 768px)",
lg: "@media (min-width: 1024px)",
xl: "@media (min-width: 1280px)",
xxl: "@media (min-width: 1536px)",
},
},
};
},
getOptions: () => ({
configPath: "/some/special/path/config",
}),
async: () => (err, result) => {
if (err) {
throw err;
}
return result;
},
};
let i = 0;
const compiled =
"// @ts-nocheck\n" +
(await tsLoader.call(loaderContext, fileContent))
// Remove __styleYak import
swc
.transformSync(fileContent, {
filename: "/foo/index.tsx",
jsc: {
experimental: {
plugins: [[require.resolve("yak-swc"), { basePath: "/foo/" }]],
},
target: "es2022",
loose: false,
minify: {
compress: false,
mangle: false,
},
preserveAllComments: true,
},
minify: false,
isModule: true,
})
.code // Remove __styleYak import
.replace(/import[^;\n]+yak.module.css";/, "")
// Replace __styleYak usage to a string
.replace(/__styleYak.(\w+)/g, `"$1"`);
Expand Down
14 changes: 8 additions & 6 deletions packages/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
"codspeed:run": "NODE_ENV=production node ./codspeed/dist/index.bench.mjs"
},
"dependencies": {
"@swc/core": "1.7.42",
"next": "15.0.2",
"next-yak": "workspace:*",
"react": "18.3.1",
"react-dom": "18.3.1",
"next-yak": "workspace:*",
"styled-components": "6.1.1"
"styled-components": "6.1.1",
"yak-swc": "workspace:^"
},
"devDependencies": {
"@codspeed/benchmark.js-plugin": "3.1.0",
"@types/benchmark": "2.1.5",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@types/benchmark": "2.1.5",
"benchmark": "2.1.4",
"typescript": "5.5.2",
"tree-kill": "1.2.2",
"@codspeed/benchmark.js-plugin": "3.1.0",
"tsup": "7.2.0"
"tsup": "7.2.0",
"typescript": "5.5.2"
}
}
Loading

0 comments on commit ef37699

Please sign in to comment.