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

feat: re design middleware #6

Merged
merged 6 commits into from
Jan 7, 2024
Merged
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ temp
types
.tmpl
coverage
.DS_Store

yarn-debug.log*
yarn-error.log*
8 changes: 4 additions & 4 deletions __tests__/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -55,8 +55,8 @@ async function mockBuild(taskName: string, opts: BuildOptions = {}) {
test('normal suit disable css minify', async (t) => {
const { css, js } = await mockBuild('normal', { vite: { build: { cssMinify: false } } })
await sleep()
t.is(css, `.xju2f9n:not(#\\#){color:blue}
.x1e2nbdu:not(#\\#){color:red}`)
t.is(css, `.xju2f9n{color:blue}
.x1e2nbdu{color:red}`)
t.is(js, `import * as s from "@stylexjs/stylex";
const e = {
blue: {
@@ -78,7 +78,7 @@ export {
test('normal suite enable css minify', async (t) => {
const { css } = await mockBuild('normal')
await sleep()
t.is(css, '.xju2f9n:not(#\\#){color:#00f}.x1e2nbdu:not(#\\#){color:red}\n')
t.is(css, '.xju2f9n{color:#00f}.x1e2nbdu{color:red}\n')
})

test('pxtorem suite should transform px to rem', async (t) => {
@@ -90,5 +90,5 @@ test('pxtorem suite should transform px to rem', async (t) => {
}
} })
await sleep()
t.is(css, '.x1j61zf2:not(#\\#){font-size:1rem}\n')
t.is(css, '.x1j61zf2{font-size:1rem}\n')
})
34 changes: 34 additions & 0 deletions e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -92,3 +92,37 @@ test('fixture open-props', async (t) => {
}, [windowHandle, elementHandle])
t.is(blue, 'rgb(231, 245, 255)', 'tap button and text color should be blue')
})

test('fixture tsconfig-paths', async (t) => {
const { page } = await createE2EServer('tsconfig-paths')
await page.waitForSelector('div[role="button"]')
const elementHandle = await page.$('div[role="button"]')
const windowHandle = await page.evaluateHandle(() => Promise.resolve(window))
const red = await page.evaluate(([window, el]) => {
return (window as Window).getComputedStyle(el as Element).color
}, [windowHandle, elementHandle])
t.is(red, 'rgb(255, 0, 0)', 'first load spa button text color should be red')
await elementHandle.click()
await new Promise((resolve) => setTimeout(resolve, 2000))
const blue = await page.evaluate(([window, el]) => {
return (window as Window).getComputedStyle(el as Element).color
}, [windowHandle, elementHandle])
t.is(blue, 'rgb(0, 0, 255)', 'tap button and text color should be blue')
})

test('fixture path-alias', async (t) => {
const { page } = await createE2EServer('path-alias')
await page.waitForSelector('div[role="button"]')
const elementHandle = await page.$('div[role="button"]')
const windowHandle = await page.evaluateHandle(() => Promise.resolve(window))
const red = await page.evaluate(([window, el]) => {
return (window as Window).getComputedStyle(el as Element).color
}, [windowHandle, elementHandle])
t.is(red, 'rgb(255, 0, 0)', 'first load spa button text color should be red')
await elementHandle.click()
await new Promise((resolve) => setTimeout(resolve, 2000))
const blue = await page.evaluate(([window, el]) => {
return (window as Window).getComputedStyle(el as Element).color
}, [windowHandle, elementHandle])
t.is(blue, 'rgb(0, 0, 255)', 'tap button and text color should be blue')
})
5 changes: 4 additions & 1 deletion e2e/fixtures/open-props/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "vite-plugin-stylex-e2e-open-props",
"scripts": {
"dev": "vite"
},
"devDependencies": {
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
@@ -10,6 +13,6 @@
"vite-plugin-stylex-dev": "workspace:*"
},
"dependencies": {
"@stylexjs/open-props": "^0.3.0"
"@stylexjs/open-props": "^0.4.1"
}
}
12 changes: 12 additions & 0 deletions e2e/fixtures/path-alias/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions e2e/fixtures/path-alias/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "vite-plugin-stylex-e2e-paths-alias",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react": "^4.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^5.0.10",
"vite-plugin-stylex-dev": "workspace:*"
}
}
28 changes: 28 additions & 0 deletions e2e/fixtures/path-alias/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable jsx-a11y/interactive-supports-focus */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import * as stylex from '@stylexjs/stylex'
import { useState } from 'react'

const styles = stylex.create({
text: { fontSize: '20px', cursor: 'pointer' },
blue: {
color: 'blue'
},
red: {
color: 'red'
}
})

export function App() {
const [color, setColor] = useState('red')

const handleClick = () => {
setColor(pre => pre === 'red' ? 'blue' : 'red')
}

return (
<div>
<div role="button" onClick={handleClick} className={stylex.props(styles.text, color === 'red' ? styles.red : styles.blue).className}>Action</div>
</div>
)
}
9 changes: 9 additions & 0 deletions e2e/fixtures/path-alias/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { App } from './app'

ReactDOM.createRoot(document.querySelector('#app')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
13 changes: 13 additions & 0 deletions e2e/fixtures/path-alias/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"baseUrl": ".",
"jsx": "react-jsx",
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"paths": {
"@/*": ["src/*"],
"~/*":["themes/*"]
}
}
}
13 changes: 13 additions & 0 deletions e2e/fixtures/path-alias/vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { stylexPlugin } from 'vite-plugin-stylex-dev'

export default defineConfig({
resolve: {
alias: {
'@': path.join(__dirname, 'src')
}
},
plugins: [react(), stylexPlugin()]
})
12 changes: 12 additions & 0 deletions e2e/fixtures/tsconfig-paths/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions e2e/fixtures/tsconfig-paths/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "vite-plugin-stylex-e2e-tsconfig-paths",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react": "^4.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^5.0.10",
"vite-plugin-stylex-dev": "workspace:*",
"vite-tsconfig-paths": "^4.2.3"
}
}
28 changes: 28 additions & 0 deletions e2e/fixtures/tsconfig-paths/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable jsx-a11y/interactive-supports-focus */
/* eslint-disable jsx-a11y/click-events-have-key-events */
import * as stylex from '@stylexjs/stylex'
import { useState } from 'react'

const styles = stylex.create({
text: { fontSize: '20px', cursor: 'pointer' },
blue: {
color: 'blue'
},
red: {
color: 'red'
}
})

export function App() {
const [color, setColor] = useState('red')

const handleClick = () => {
setColor(pre => pre === 'red' ? 'blue' : 'red')
}

return (
<div>
<div role="button" onClick={handleClick} className={stylex.props(styles.text, color === 'red' ? styles.red : styles.blue).className}>Action</div>
</div>
)
}
9 changes: 9 additions & 0 deletions e2e/fixtures/tsconfig-paths/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { App } from './app'

ReactDOM.createRoot(document.querySelector('#app')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
13 changes: 13 additions & 0 deletions e2e/fixtures/tsconfig-paths/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"baseUrl": ".",
"jsx": "react-jsx",
"esModuleInterop": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"paths": {
"@/*": ["src/*"],
"~/*":["themes/*"]
}
}
}
9 changes: 9 additions & 0 deletions e2e/fixtures/tsconfig-paths/vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// import path from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'
import { stylexPlugin } from 'vite-plugin-stylex-dev'

export default defineConfig({
plugins: [tsconfigPaths({ root: __dirname }), react(), stylexPlugin()]
})
4 changes: 2 additions & 2 deletions e2e/fixtures/vue-ssr/server.ts
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@ export async function createSSRServer(configFile = path.join(__dirname, 'vite.co
const port = genRandomPort()
app.listen(port)
const { page } = await createChromeBrowser(port)
return { app, page }
return { app, page, port }
}

if (require.main === module) {
createSSRServer()
createSSRServer().then(({ port }) => console.log(`server listen on: http://127.0.0.1:${port}`))
}
2 changes: 1 addition & 1 deletion examples/nuxt-demo/components/btn2.vue
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import stylex from '@stylexjs/stylex'
const btns = stylex.create({
button: {
transition: '.150s all',
border: '3px solid red',
border: '3px solid green',
backgroundColor: 'HotPink'

},
6 changes: 3 additions & 3 deletions examples/qwik-demo/src/components/starter/hero/hero.tsx
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ const s = stylex.create({

export default component$(() => {
return (
<div className={['container']}>
<h1 className={stylex(s.h1)}>
<div className="container">
<h1 className={stylex.props(s.h1).className}>
So
{' '}
<span className="highlight">fantastic</span>
@@ -23,7 +23,7 @@ export default component$(() => {
{' '}
here
</h1>
<p className={stylex(s.h1)}>Have fun building your App with Qwik.</p>
<p className={stylex.props(s.h1).className}>Have fun building your App with Qwik.</p>
</div>
)
})
2 changes: 1 addition & 1 deletion examples/qwik-demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import { stylexPlugin } from 'vite-plugin-stylex-dev'

export default defineConfig(() => {
return {
plugins: [qwikCity(), qwikVite(), tsconfigPaths(), stylexPlugin()],
plugins: [qwikCity(), qwikVite(), tsconfigPaths({ root: __dirname }), stylexPlugin()],
dev: {
headers: {
'Cache-Control': 'public, max-age=0'
3 changes: 2 additions & 1 deletion examples/vite-demo/src/card.vue
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ import * as stylex from '@stylexjs/stylex'
const styles = stylex.create({
card: {
border: '1px solid red',
color: 'red'
color: 'red',
fontSize: '30px'
}
})

3 changes: 2 additions & 1 deletion examples/vite-react-demo/package.json
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^5.0.10",
"vite-plugin-stylex-dev": "workspace:*"
"vite-plugin-stylex-dev": "workspace:*",
"vite-tsconfig-paths": "^4.2.3"
},
"dependencies": {
"@stylexjs/open-props": "^0.3.0"
13 changes: 2 additions & 11 deletions examples/vite-react-demo/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import * as stylex from '@stylexjs/stylex'

import { colors } from '@stylexjs/open-props/lib/colors.stylex'

const styles = stylex.create({
base: {
color: colors.gray0
}
})
import Button from './button'

function App() {
return <button type="button" {...stylex.props(styles.base)}>Click me!</button>
return <Button>123</Button>
}

export { App }
Loading