Skip to content
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

Feature/rust deployment #128

Closed
wants to merge 115 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
2dabecc
parse css in rust
jantimon Jun 24, 2024
31d7191
improve docs
jantimon Jun 30, 2024
0d2c7ed
rename snapshots
jantimon Jul 1, 2024
5206568
wip swc plugin
jantimon Jul 1, 2024
6642489
use variable name
jantimon Jul 1, 2024
d6ddbca
enums
jantimon Jul 2, 2024
27bfc5d
comments
jantimon Jul 2, 2024
a5c0ea3
Move to workspace
martindisch Jul 1, 2024
5f2948d
Create an SWC API example
martindisch Jul 1, 2024
dfe1c86
class name naming
jantimon Jul 2, 2024
f008e46
Apply clippy lints
martindisch Jul 2, 2024
1323aea
leap
jantimon Jul 3, 2024
c379cec
cleanup
jantimon Jul 3, 2024
f4a74e2
Use test modules
martindisch Jul 3, 2024
0cc0b8e
add naming convention
jantimon Jul 3, 2024
5966f03
selectors
jantimon Jul 4, 2024
aabf36f
Apply lints
martindisch Jul 4, 2024
9f2f55b
remove unused strip css comment logic (#106)
jantimon Jun 30, 2024
a70a9d8
add bundler integration tests for webpack (#105)
jantimon Jun 30, 2024
ac9f398
Feature/cross file selectors (#103)
jantimon Jun 30, 2024
2f45f96
release 0.2.3 with experimental cross file support
jantimon Jun 30, 2024
58ce2df
benchmark for soft navigation (#109)
jantimon Jul 4, 2024
42d1bdf
Merge remote-tracking branch 'origin/main' into feature/rust
jantimon Jul 4, 2024
e1ebe32
add fixture tests
jantimon Jul 5, 2024
7b08adc
Fix comments issue (#111)
kdy1 Jul 5, 2024
3c72100
tests with fixtures
jantimon Jul 5, 2024
0319b52
move transform into separate file
jantimon Jul 6, 2024
a3c8c30
move to helper
jantimon Jul 7, 2024
a19124d
transform into fn call
jantimon Jul 7, 2024
10b73cc
half baked broken css variable implementation
jantimon Jul 8, 2024
1b36549
change import
jantimon Jul 8, 2024
4094293
mixins
jantimon Jul 8, 2024
ebb7dbd
css-variables
jantimon Jul 8, 2024
6c92134
make tests deterministic by ordering keys
jantimon Jul 8, 2024
c55235d
comments
jantimon Jul 10, 2024
1c81896
Merge remote-tracking branch 'origin/main' into feature/rust
jantimon Jul 10, 2024
851b23d
apply clippy changes
Mad-Kat Jul 10, 2024
1e83a19
scoped inline mixins
jantimon Jul 10, 2024
3eacff9
move import detection to skip non-yak files
jantimon Jul 11, 2024
098e1c5
import css file
jantimon Jul 11, 2024
d84c9b7
fix typo
jantimon Jul 11, 2024
655ba62
Added tests for babel that read input and compare output from swc tests
Mad-Kat Jul 11, 2024
8f660e9
only add import if needed
jantimon Jul 11, 2024
20a792e
align module-selector with babel version
jantimon Jul 11, 2024
d8115fa
align css-variables with babel version
jantimon Jul 11, 2024
2a521bc
Format babel and swc output similar to see differences
Jul 12, 2024
fe1e57f
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 12, 2024
543d585
Change file input name to be the same in SWC and babel for tests
Jul 12, 2024
b37d908
change injection position of css module
jantimon Jul 12, 2024
24b710c
variable names similar to babel
jantimon Jul 12, 2024
5f8cab2
access styles similar to babel
jantimon Jul 12, 2024
1411f9a
variable names similar to babel
jantimon Jul 12, 2024
eecea2d
more prettification
jantimon Jul 12, 2024
9107b99
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 12, 2024
efac9f4
ts-ignore
jantimon Jul 12, 2024
33f86cb
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 12, 2024
6e13f2b
new lines after comments
jantimon Jul 12, 2024
11b5937
test-prettification
jantimon Jul 12, 2024
8e4789a
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 12, 2024
81f8cde
Merge branch 'main' into feature/rust
jantimon Jul 12, 2024
6ade250
add config options
jantimon Jul 12, 2024
3190ba3
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 12, 2024
4e96960
improve css variable names
jantimon Jul 12, 2024
f91fb76
remove log
jantimon Jul 12, 2024
c378eb3
css variable units
jantimon Jul 13, 2024
8752690
remove css unit from css
jantimon Jul 14, 2024
2f1c5c2
move path calculation to own crate to precompile regexp
jantimon Jul 14, 2024
6246607
adjust unwrap for murmur_hash
jantimon Jul 14, 2024
f32062b
align with babel plugin
jantimon Jul 14, 2024
1b37e9c
Merge branch 'main' into feature/rust
jantimon Jul 14, 2024
157785c
adjust test
jantimon Jul 14, 2024
99ebb21
adjust test
jantimon Jul 14, 2024
1a3f9ad
update main cargo.toml
jantimon Jul 14, 2024
b59b8a6
Merge branch 'main' into feature/rust
jantimon Jul 15, 2024
c617fef
adjust with-yak
jantimon Jul 15, 2024
b6781ab
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 15, 2024
8a39eb2
Throw the same error as Babel if nested mixins are encountered
Jul 15, 2024
bbcc79e
fix casing
jantimon Jul 15, 2024
936cc9c
identifiy invalid expressions in nested css
jantimon Jul 15, 2024
80c4898
add kudus
jantimon Jul 15, 2024
4e7f5e0
fix extending-styles test
jantimon Jul 15, 2024
470a909
add test for attrs
jantimon Jul 15, 2024
6682fa5
fix attrs
jantimon Jul 15, 2024
29f982f
Merge branch 'main' into feature/rust
jantimon Jul 16, 2024
8669c30
add yak-imports
jantimon Jul 16, 2024
83f72e1
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 16, 2024
dda9317
cleanup
jantimon Jul 16, 2024
46b26f0
cleanup
jantimon Jul 16, 2024
63b2503
try build swc
jantimon Jul 16, 2024
409095f
remove swc for now as vercel has no cargo installed
jantimon Jul 16, 2024
37735d3
cross-file-mixins
jantimon Jul 16, 2024
4bfee68
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 16, 2024
919f0da
format
jantimon Jul 16, 2024
1756df3
add rust build workflow
jantimon Jul 16, 2024
24b84e1
wasm build
jantimon Jul 16, 2024
79df873
upgrade node
jantimon Jul 16, 2024
039e30b
remove circular dependency
jantimon Jul 16, 2024
d231a2b
updade pnpm
jantimon Jul 16, 2024
7d12547
preview build
jantimon Jul 16, 2024
eae7e97
remove id
jantimon Jul 16, 2024
570b020
flip
jantimon Jul 16, 2024
2d6c539
fix build
jantimon Jul 16, 2024
e9afb2e
pull
jantimon Jul 17, 2024
fa46cda
switch back to inline
jantimon Jul 17, 2024
c1ac0ec
drop import type
jantimon Jul 17, 2024
b1c717f
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 17, 2024
ebf8597
pnpm install with action
jantimon Jul 17, 2024
15f7a70
define dest
jantimon Jul 17, 2024
e0be9fb
try cache dir
jantimon Jul 17, 2024
961a7b7
no double pull
jantimon Jul 17, 2024
9c8773b
pin vercel version
jantimon Jul 17, 2024
b42f959
without prebuild
jantimon Jul 17, 2024
2559176
try with org and projectid
jantimon Jul 17, 2024
880b892
stay in root
jantimon Jul 17, 2024
44b683e
no double pull
jantimon Jul 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build and Deploy packages/example
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}

on:
push:
branches-ignore:
- main

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- 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

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

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

- name: Install node_modules
run: pnpm install

- name: Install Vercel CLI
run: npm install -g vercel@35

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

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

- name: Link Vercel project
run: vercel link --yes --token ${{ secrets.VERCEL_TOKEN }}

- name: Pull Vercel environment information
run: vercel pull --yes --environment=preview --token ${{ secrets.VERCEL_TOKEN }}

- name: Build project artifacts
run: vercel build --yes --token ${{ secrets.VERCEL_TOKEN }}

- name: Deploy to Vercel
run: vercel deploy --prebuilt --token ${{ secrets.VERCEL_TOKEN }}
30 changes: 30 additions & 0 deletions .github/workflows/swc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: SWC validation

on:
push:
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
rust:
name: Rust tests & lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Enable caching
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/yak-swc
- name: Run cargo check
run: cargo check --manifest-path packages/yak-swc/Cargo.toml
- name: Run cargo test
run: cargo test --manifest-path packages/yak-swc/Cargo.toml
- name: Run cargo fmt
run: cargo fmt --manifest-path packages/yak-swc/Cargo.toml --all -- --check
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
node_modules
packages/docs/docs/dist
packages/next-yak/dist
packages/playground/dist
packages/playground/dist
target
.vercel
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const Container = styled.div`
## Yak shaving

While trying to get next-yak to work properly we stumbled accross several bugs.
Thanks for merging our prs fixes in next.js and postcss ❤️
Thanks for merging our prs fixes in next.js, webpack and postcss ❤️

<details>
<summary>PRS</summary>
Expand All @@ -296,14 +296,19 @@ Thanks for merging our prs fixes in next.js and postcss ❤️

## Acknowledgments

Massive kudos to:

- @sokra: For guiding us through the webpacks module and loader APIs
- @kdy1: For his support while rewriting our Babel plugin as a blazing fast SWC Rust WASM plugin

Special thanks to the contributors and the inspiring projects that influenced next-yak:

- Styled-Components 💅: For pioneering the styled syntax and redefining styling in the React ecosystem.
- Linaria: For its innovative approach to zero-runtime CSS in JS and efficient styling solutions.
- Emotion: For pushing the boundaries of CSS-in-JS and providing a high-performance styling experience.
- Vanilla Extract: For its focus on type-safe, zero-runtime CSS and contributing to the evolution of styling techniques.
- Tailwind CSS: For its exceptional atomic CSS approach, enabling efficient and customizable styling solutions.

## License

**next-yak** is licensed under the [MIT License](link/to/LICENSE).
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"scripts": {
"build": "pnpm run --filter=next-yak build",
"build:swc": "pnpm run --filter=yak-swc build",
"watch": "pnpm run --filter=next-yak watch",
"example": "pnpm --filter=next-yak-example run dev",
"test": "pnpm --filter=next-yak --filter=webpack-tests run \"/test($|:types)/\"",
Expand Down
6 changes: 2 additions & 4 deletions packages/example/app/mixins/constants.yak.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { mixin } from "next-yak/static";

export const typography = {
h1: mixin.css`
h1: `
font-family: "Roboto", sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 1.5;
${mixin.css`
letter-spacing: 0.00938em;
`}
letter-spacing: 0.00938em;
`,
};
12 changes: 2 additions & 10 deletions packages/example/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/** @jsxImportSource next-yak */

import { YakThemeProvider, css, styled } from "next-yak";
import styles from "./page.module.css";
import { queries, colors } from "@/theme/constants.yak";
Expand All @@ -9,8 +8,7 @@ import { HighContrastToggle } from "./HighContrastToggle";
import { typography } from "./mixins/constants.yak";

const headline = css<{ $primary?: boolean }>`
${typography.h1}

${typography.h1};
filter: drop-shadow(0px 0px 1px #fff);
${({ theme }) =>
theme.highContrast
Expand Down Expand Up @@ -129,13 +127,7 @@ export default function Home() {
<StyledLink href="https://github.com/jantimon/next-yak/tree/main/packages/example/app">
view code
</StyledLink>
<p
css={css`
color: green;
`}
>
CSS Prop works if this is green
</p>
<p>CSS Prop works if this is green</p>
<Inputs />
</main>
</YakThemeProvider>
Expand Down
1 change: 1 addition & 0 deletions packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "pnpm run build:yak && pnpm run build:next",
"build:next": "next build",
"build:yak": "pnpm run --filter next-yak build",
"build:swc": "pnpm run --filter yak-swc build",
"start": "next start",
"lint": "next lint",
"test": "jest",
Expand Down
9 changes: 7 additions & 2 deletions packages/next-yak/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const Container = styled.div`
## Yak shaving

While trying to get next-yak to work properly we stumbled accross several bugs.
Thanks for merging our prs fixes in next.js and postcss ❤️
Thanks for merging our prs fixes in next.js, webpack and postcss ❤️

<details>
<summary>PRS</summary>
Expand All @@ -296,14 +296,19 @@ Thanks for merging our prs fixes in next.js and postcss ❤️

## Acknowledgments

Massive kudos to:

- @sokra: For guiding us through webpacks module and loader APIs
- @kdy1: For his support while rewriting our Babel plugin as a blazing fast SWC Rust WASM plugin

Special thanks to the contributors and the inspiring projects that influenced next-yak:

- Styled-Components 💅: For pioneering the styled syntax and redefining styling in the React ecosystem.
- Linaria: For its innovative approach to zero-runtime CSS in JS and efficient styling solutions.
- Emotion: For pushing the boundaries of CSS-in-JS and providing a high-performance styling experience.
- Vanilla Extract: For its focus on type-safe, zero-runtime CSS and contributing to the evolution of styling techniques.
- Tailwind CSS: For its exceptional atomic CSS approach, enabling efficient and customizable styling solutions.

## License

**next-yak** is licensed under the [MIT License](link/to/LICENSE).
Expand Down
98 changes: 98 additions & 0 deletions packages/next-yak/loaders/__tests__/babel-swc-comparison.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { it, describe, expect } from "vitest";
import fs from "fs";
import path from "path";
import { glob } from "glob";
import tsloader from "../ts-loader";
import * as prettier from "prettier";

describe("should work", () => {
const inputFiles = glob.sync("../yak-swc/**/input.tsx", {
absolute: true,
ignore: "node_modules/**",
});
inputFiles.forEach((inputFile) => {
it(`processing ${inputFile
.split(path.sep)
.at(-2)} should match output`, async () => {
const input = fs.readFileSync(inputFile, "utf8");
const output = await tsloader
.call(
{
_compilation: {},
resourcePath: "/some/path/input.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",
experiments: {
crossFileSelectors: true,
},
}),
async: () => (err, result) => {
if (err) {
throw err;
}
return result;
},
},
input,
)
.then((result) => result)
.catch((err) => err.toString());

if (fs.existsSync(path.resolve(inputFile, "../output.stderr"))) {
const outputFile = path.join(path.dirname(inputFile), "output.stderr");
const expectedOutput = fs.readFileSync(outputFile, "utf8");
expect(prettifyBabelError(output)).toEqual(
prettifySWCError(expectedOutput),
);
} else {
const outputFile = path.join(path.dirname(inputFile), "output.tsx");
const expectedOutput = fs.readFileSync(outputFile, "utf8");
expect(await prettify(output)).toEqual(await prettify(expectedOutput));
}
});
});
});

/** Helper to format SWC and Babel compile outputs the same way */
const prettify = async (code: string) =>
await prettier.format(
code
// replace the newlines and spaces before comments
.replace(/\s*\/\*/g, "/*")
// replace the newlines and spaces after comments
.replace(/\s*\*\//g, "*/")
// replace the newlines after comments
.replace(/\*\/\s*/g, "*/\n")
// remove ts ignore comments
.replace(/\/\/\s*@ts-ignore/g, "")
// replace empty lines
.replace(/\n\n+/g, "\n")
.trim(),
{
parser: "typescript",
},
);

const prettifySWCError = (code: string) =>
code
.replace(/\n [^\|x][\s\S]+/, "")
.replace(/ [\|x] /g, "")
.trim();

const prettifyBabelError = (code: string) =>
code.replace(/.*line \d+: /, "").trim();
2 changes: 1 addition & 1 deletion packages/next-yak/loaders/lib/encodeModuleImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ export function encodeModuleImport(
.map((part) => encodeURIComponent(part))
.join(":");

return `:yak-css-import(${modulePath}:${kind}:${encodedChain})`;
return `--yak-css-import: url("${modulePath}:${encodedChain}")`;
}
Loading
Loading