@@ -4,9 +4,11 @@ import { join, resolve } from 'node:path'
44import { DevupUIWebpackPlugin } from '@devup-ui/webpack-plugin'
55
66import { DevupUI } from '../plugin'
7+ import { preload } from '../preload'
78
89vi . mock ( '@devup-ui/webpack-plugin' )
910vi . mock ( 'node:fs' )
11+ vi . mock ( '../preload' )
1012
1113describe ( 'DevupUINextPlugin' , ( ) => {
1214 describe ( 'webpack' , ( ) => {
@@ -85,20 +87,42 @@ describe('DevupUINextPlugin', () => {
8587 loader : '@devup-ui/webpack-plugin/css-loader' ,
8688 } ,
8789 ] ,
88- '*.{tsx,ts,js,mjs}' : [
89- {
90- loader : '@devup-ui/webpack-plugin/loader' ,
91- options : {
92- package : '@devup-ui/react' ,
93- cssDir : resolve ( 'df' , 'devup-ui' ) ,
94- sheetFile : join ( 'df' , 'sheet.json' ) ,
95- classMapFile : join ( 'df' , 'classMap.json' ) ,
96- fileMapFile : join ( 'df' , 'fileMap.json' ) ,
97- watch : false ,
98- singleCss : false ,
90+ '*.{tsx,ts,js,mjs}' : {
91+ loaders : [
92+ {
93+ loader : '@devup-ui/webpack-plugin/loader' ,
94+ options : {
95+ package : '@devup-ui/react' ,
96+ cssDir : resolve ( 'df' , 'devup-ui' ) ,
97+ sheetFile : join ( 'df' , 'sheet.json' ) ,
98+ classMapFile : join ( 'df' , 'classMap.json' ) ,
99+ fileMapFile : join ( 'df' , 'fileMap.json' ) ,
100+ watch : false ,
101+ singleCss : false ,
102+ theme : { } ,
103+ defaultClassMap : { } ,
104+ defaultFileMap : { } ,
105+ defaultSheet : {
106+ css : { } ,
107+ font_faces : { } ,
108+ global_css_files : [ ] ,
109+ imports : { } ,
110+ keyframes : { } ,
111+ properties : { } ,
112+ } ,
113+ } ,
114+ } ,
115+ ] ,
116+ condition : {
117+ not : {
118+ path : new RegExp (
119+ `node_modules(?!.*(${ [ '@devup-ui' ]
120+ . join ( '|' )
121+ . replaceAll ( '/' , '[\\/\\\\_]' ) } )([\\/\\\\.]|$))`,
122+ ) ,
99123 } ,
100124 } ,
101- ] ,
125+ } ,
102126 } ,
103127 } ,
104128 } )
@@ -118,20 +142,42 @@ describe('DevupUINextPlugin', () => {
118142 loader : '@devup-ui/webpack-plugin/css-loader' ,
119143 } ,
120144 ] ,
121- '*.{tsx,ts,js,mjs}' : [
122- {
123- loader : '@devup-ui/webpack-plugin/loader' ,
124- options : {
125- package : '@devup-ui/react' ,
126- cssDir : resolve ( 'df' , 'devup-ui' ) ,
127- sheetFile : join ( 'df' , 'sheet.json' ) ,
128- classMapFile : join ( 'df' , 'classMap.json' ) ,
129- fileMapFile : join ( 'df' , 'fileMap.json' ) ,
130- watch : false ,
131- singleCss : false ,
145+ '*.{tsx,ts,js,mjs}' : {
146+ condition : {
147+ not : {
148+ path : new RegExp (
149+ `node_modules(?!.*(${ [ '@devup-ui' ]
150+ . join ( '|' )
151+ . replaceAll ( '/' , '[\\/\\\\_]' ) } )([\\/\\\\.]|$))`,
152+ ) ,
132153 } ,
133154 } ,
134- ] ,
155+ loaders : [
156+ {
157+ loader : '@devup-ui/webpack-plugin/loader' ,
158+ options : {
159+ package : '@devup-ui/react' ,
160+ cssDir : resolve ( 'df' , 'devup-ui' ) ,
161+ sheetFile : join ( 'df' , 'sheet.json' ) ,
162+ classMapFile : join ( 'df' , 'classMap.json' ) ,
163+ fileMapFile : join ( 'df' , 'fileMap.json' ) ,
164+ watch : false ,
165+ singleCss : false ,
166+ theme : { } ,
167+ defaultClassMap : { } ,
168+ defaultFileMap : { } ,
169+ defaultSheet : {
170+ css : { } ,
171+ font_faces : { } ,
172+ global_css_files : [ ] ,
173+ imports : { } ,
174+ keyframes : { } ,
175+ properties : { } ,
176+ } ,
177+ } ,
178+ } ,
179+ ] ,
180+ } ,
135181 } ,
136182 } ,
137183 } )
@@ -158,21 +204,42 @@ describe('DevupUINextPlugin', () => {
158204 loader : '@devup-ui/webpack-plugin/css-loader' ,
159205 } ,
160206 ] ,
161- '*.{tsx,ts,js,mjs}' : [
162- {
163- loader : '@devup-ui/webpack-plugin/loader' ,
164- options : {
165- package : '@devup-ui/react' ,
166- cssDir : resolve ( 'df' , 'devup-ui' ) ,
167- sheetFile : join ( 'df' , 'sheet.json' ) ,
168- classMapFile : join ( 'df' , 'classMap.json' ) ,
169- fileMapFile : join ( 'df' , 'fileMap.json' ) ,
170- watch : false ,
171- singleCss : false ,
172- theme : 'theme' ,
207+ '*.{tsx,ts,js,mjs}' : {
208+ condition : {
209+ not : {
210+ path : new RegExp (
211+ `node_modules(?!.*(${ [ '@devup-ui' ]
212+ . join ( '|' )
213+ . replaceAll ( '/' , '[\\/\\\\_]' ) } )([\\/\\\\.]|$))`,
214+ ) ,
173215 } ,
174216 } ,
175- ] ,
217+ loaders : [
218+ {
219+ loader : '@devup-ui/webpack-plugin/loader' ,
220+ options : {
221+ package : '@devup-ui/react' ,
222+ cssDir : resolve ( 'df' , 'devup-ui' ) ,
223+ sheetFile : join ( 'df' , 'sheet.json' ) ,
224+ classMapFile : join ( 'df' , 'classMap.json' ) ,
225+ fileMapFile : join ( 'df' , 'fileMap.json' ) ,
226+ watch : false ,
227+ singleCss : false ,
228+ theme : 'theme' ,
229+ defaultClassMap : { } ,
230+ defaultFileMap : { } ,
231+ defaultSheet : {
232+ css : { } ,
233+ font_faces : { } ,
234+ global_css_files : [ ] ,
235+ imports : { } ,
236+ keyframes : { } ,
237+ properties : { } ,
238+ } ,
239+ } ,
240+ } ,
241+ ] ,
242+ } ,
176243 } ,
177244 } ,
178245 } )
@@ -184,9 +251,23 @@ describe('DevupUINextPlugin', () => {
184251 it ( 'should throw error if NODE_ENV is production' , ( ) => {
185252 vi . stubEnv ( 'NODE_ENV' , 'production' )
186253 vi . stubEnv ( 'TURBOPACK' , '1' )
187- const ret = ( ) => DevupUI ( { } )
188- expect ( ret ) . toThrow (
189- 'Devup UI is not supported in production with turbopack' ,
254+ vi . mocked ( preload ) . mockReturnValue ( )
255+ const ret = DevupUI ( { } )
256+ expect ( ret ) . toEqual ( {
257+ turbopack : {
258+ rules : expect . any ( Object ) ,
259+ } ,
260+ } )
261+ expect ( preload ) . toHaveBeenCalledWith (
262+ new RegExp (
263+ `node_modules(?!.*(${ [ '@devup-ui' ]
264+ . join ( '|' )
265+ . replaceAll ( '/' , '[\\/\\\\_]' ) } )([\\/\\\\.]|$))`,
266+ ) ,
267+ '@devup-ui/react' ,
268+ false ,
269+ 'theme' ,
270+ expect . any ( String ) ,
190271 )
191272 } )
192273 } )
0 commit comments