Skip to content

Commit d5354ad

Browse files
committed
Create devup-ui css issue
2 parents 0cf0ca8 + 178bc1f commit d5354ad

File tree

4 files changed

+93
-2
lines changed

4 files changed

+93
-2
lines changed

packages/next-plugin/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @devup-ui/next-plugin
22

3+
## 1.0.50
4+
5+
### Patch Changes
6+
7+
- [#471](https://github.com/dev-five-git/devup-ui/pull/471) [`8a37e11`](https://github.com/dev-five-git/devup-ui/commit/8a37e119381fe4c4a4c11fbf793b0bdb72a32a19) Thanks [@owjs3901](https://github.com/owjs3901)! - Fix default theme issue
8+
39
## 1.0.49
410

511
### Patch Changes

packages/next-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"webpack"
2020
],
2121
"type": "module",
22-
"version": "1.0.49",
22+
"version": "1.0.50",
2323
"scripts": {
2424
"lint": "eslint",
2525
"build": "tsc && vite build"

packages/next-plugin/src/__tests__/plugin.test.ts

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
22
import { join, resolve } from 'node:path'
33

4-
import { getThemeInterface } from '@devup-ui/wasm'
4+
import { getDefaultTheme, getThemeInterface } from '@devup-ui/wasm'
55
import { DevupUIWebpackPlugin } from '@devup-ui/webpack-plugin'
66

77
import { DevupUI } from '../plugin'
@@ -14,6 +14,19 @@ vi.mock('@devup-ui/wasm', async (original) => ({
1414
...(await original()),
1515
registerTheme: vi.fn(),
1616
getThemeInterface: vi.fn(),
17+
getDefaultTheme: vi.fn(),
18+
exportSheet: vi.fn(() =>
19+
JSON.stringify({
20+
css: {},
21+
font_faces: {},
22+
global_css_files: [],
23+
imports: {},
24+
keyframes: {},
25+
properties: {},
26+
}),
27+
),
28+
exportClassMap: vi.fn(() => JSON.stringify({})),
29+
exportFileMap: vi.fn(() => JSON.stringify({})),
1730
}))
1831

1932
describe('DevupUINextPlugin', () => {
@@ -312,5 +325,67 @@ describe('DevupUINextPlugin', () => {
312325
})
313326
expect(writeFileSync).toHaveBeenCalledWith(join('df', '.gitignore'), '*')
314327
})
328+
it('should set DEVUP_UI_DEFAULT_THEME when getDefaultTheme returns a value', async () => {
329+
vi.stubEnv('TURBOPACK', '1')
330+
vi.stubEnv('DEVUP_UI_DEFAULT_THEME', '')
331+
vi.mocked(existsSync)
332+
.mockReturnValueOnce(true)
333+
.mockReturnValueOnce(true)
334+
.mockReturnValueOnce(true)
335+
.mockReturnValueOnce(false)
336+
vi.mocked(getDefaultTheme).mockReturnValue('dark')
337+
const config: any = {}
338+
const ret = DevupUI(config)
339+
340+
expect(process.env.DEVUP_UI_DEFAULT_THEME).toBe('dark')
341+
expect(ret.env).toEqual({
342+
DEVUP_UI_DEFAULT_THEME: 'dark',
343+
})
344+
expect(config.env).toEqual({
345+
DEVUP_UI_DEFAULT_THEME: 'dark',
346+
})
347+
})
348+
it('should not set DEVUP_UI_DEFAULT_THEME when getDefaultTheme returns undefined', async () => {
349+
vi.stubEnv('TURBOPACK', '1')
350+
vi.stubEnv('DEVUP_UI_DEFAULT_THEME', '')
351+
vi.mocked(existsSync)
352+
.mockReturnValueOnce(true)
353+
.mockReturnValueOnce(true)
354+
.mockReturnValueOnce(true)
355+
.mockReturnValueOnce(false)
356+
vi.mocked(getDefaultTheme).mockReturnValue(undefined)
357+
const config: any = {}
358+
const ret = DevupUI(config)
359+
360+
expect(process.env.DEVUP_UI_DEFAULT_THEME).toBe('')
361+
expect(ret.env).toBeUndefined()
362+
expect(config.env).toBeUndefined()
363+
})
364+
it('should set DEVUP_UI_DEFAULT_THEME and preserve existing env vars', async () => {
365+
vi.stubEnv('TURBOPACK', '1')
366+
vi.stubEnv('DEVUP_UI_DEFAULT_THEME', '')
367+
vi.mocked(existsSync)
368+
.mockReturnValueOnce(true)
369+
.mockReturnValueOnce(true)
370+
.mockReturnValueOnce(true)
371+
.mockReturnValueOnce(false)
372+
vi.mocked(getDefaultTheme).mockReturnValue('light')
373+
const config: any = {
374+
env: {
375+
CUSTOM_VAR: 'value',
376+
},
377+
}
378+
const ret = DevupUI(config)
379+
380+
expect(process.env.DEVUP_UI_DEFAULT_THEME).toBe('light')
381+
expect(ret.env).toEqual({
382+
CUSTOM_VAR: 'value',
383+
DEVUP_UI_DEFAULT_THEME: 'light',
384+
})
385+
expect(config.env).toEqual({
386+
CUSTOM_VAR: 'value',
387+
DEVUP_UI_DEFAULT_THEME: 'light',
388+
})
389+
})
315390
})
316391
})

packages/next-plugin/src/plugin.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
exportFileMap,
77
exportSheet,
88
getCss,
9+
getDefaultTheme,
910
getThemeInterface,
1011
registerTheme,
1112
} from '@devup-ui/wasm'
@@ -99,6 +100,15 @@ export function DevupUI(
99100
const defaultSheet = JSON.parse(exportSheet())
100101
const defaultClassMap = JSON.parse(exportClassMap())
101102
const defaultFileMap = JSON.parse(exportFileMap())
103+
// for theme script
104+
const defaultTheme = getDefaultTheme()
105+
if (defaultTheme) {
106+
process.env.DEVUP_UI_DEFAULT_THEME = defaultTheme
107+
config.env ??= {}
108+
Object.assign(config.env, {
109+
DEVUP_UI_DEFAULT_THEME: defaultTheme,
110+
})
111+
}
102112

103113
const rules: NonNullable<typeof config.turbopack.rules> = {
104114
[`./${relative(process.cwd(), cssDir).replaceAll('\\', '/')}/*.css`]: [

0 commit comments

Comments
 (0)