1
1
import * as babel from '@babel/core' ;
2
- // @ts -ignore
3
2
import solid from 'babel-preset-solid' ;
4
3
import { readFileSync } from 'fs' ;
5
4
import { mergeAndConcat } from 'merge-anything' ;
6
5
import { createRequire } from 'module' ;
7
6
import solidRefresh from 'solid-refresh/babel' ;
8
- // TODO use proper path
9
- import type { Options as RefreshOptions } from 'solid-refresh/babel' ;
10
- import type { Alias , AliasOptions , FilterPattern , Plugin } from 'vite' ;
11
7
import { createFilter } from 'vite' ;
8
+ import type { Alias , AliasOptions , Plugin , FilterPattern } from 'vite' ;
12
9
import { crawlFrameworkPkgs } from 'vitefu' ;
13
10
14
11
const require = createRequire ( import . meta. url ) ;
@@ -54,7 +51,6 @@ export interface Options {
54
51
* This will inject HMR runtime in dev mode. Has no effect in prod. If
55
52
* set to `false`, it won't inject the runtime in dev.
56
53
*
57
- * @deprecated use `refresh` instead
58
54
* @default true
59
55
*/
60
56
hot : boolean ;
@@ -146,8 +142,6 @@ export interface Options {
146
142
*/
147
143
builtIns ?: string [ ] ;
148
144
} ;
149
-
150
- refresh : Omit < RefreshOptions & { disabled : boolean } , 'bundler' | 'fixRender' > ;
151
145
}
152
146
153
147
function getExtension ( filename : string ) : string {
@@ -194,7 +188,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
194
188
async config ( userConfig , { command } ) {
195
189
// We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
196
190
replaceDev = options . dev === true || ( options . dev !== false && command === 'serve' ) ;
197
- projectRoot = userConfig . root || projectRoot ;
191
+ projectRoot = userConfig . root ;
198
192
199
193
if ( ! userConfig . resolve ) userConfig . resolve = { } ;
200
194
userConfig . resolve . alias = normalizeAliases ( userConfig . resolve && userConfig . resolve . alias ) ;
@@ -261,7 +255,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
261
255
} ,
262
256
263
257
configResolved ( config ) {
264
- needHmr = config . command === 'serve' && config . mode !== 'production' && ( options . hot !== false && ! options . refresh ?. disabled ) ;
258
+ needHmr = config . command === 'serve' && config . mode !== 'production' && options . hot !== false ;
265
259
} ,
266
260
267
261
resolveId ( id ) {
@@ -313,19 +307,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
313
307
314
308
return extensionOptions . typescript ;
315
309
} ) ;
316
- const plugins : NonNullable < NonNullable < babel . TransformOptions [ 'parserOpts' ] > [ 'plugins' ] > = [
317
- 'jsx' ,
318
- // import { example } from 'example' with { example: true };
319
- 'importAttributes' ,
320
- // () => throw example
321
- 'throwExpressions' ,
322
- // You know what this is
323
- 'decorators' ,
324
- // const { #example: example } = this;
325
- 'destructuringPrivate' ,
326
- // using example = myExample()
327
- 'explicitResourceManagement' ,
328
- ] ;
310
+ const plugins : NonNullable < NonNullable < babel . TransformOptions [ 'parserOpts' ] > [ 'plugins' ] > = [ 'jsx' ]
329
311
330
312
if ( shouldBeProcessedWithTypescript ) {
331
313
plugins . push ( 'typescript' ) ;
@@ -336,12 +318,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
336
318
filename : id ,
337
319
sourceFileName : id ,
338
320
presets : [ [ solid , { ...solidOptions , ...( options . solid || { } ) } ] ] ,
339
- plugins : needHmr && ! isSsr && ! inNodeModules ? [ [ solidRefresh , {
340
- bundler : 'vite' ,
341
- fixRender : true ,
342
- imports : options . refresh ?. imports ,
343
- granular : options . refresh ?. granular ,
344
- } ] ] : [ ] ,
321
+ plugins : needHmr && ! isSsr && ! inNodeModules ? [ [ solidRefresh , { bundler : 'vite' } ] ] : [ ] ,
345
322
ast : false ,
346
323
sourceMaps : true ,
347
324
configFile : false ,
@@ -356,7 +333,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
356
333
357
334
if ( options . babel ) {
358
335
if ( typeof options . babel === 'function' ) {
359
- const babelOptions = options . babel ( source , id , ! ! isSsr ) ;
336
+ const babelOptions = options . babel ( source , id , isSsr ) ;
360
337
babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions ;
361
338
} else {
362
339
babelUserOptions = options . babel ;
@@ -365,11 +342,9 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
365
342
366
343
const babelOptions = mergeAndConcat ( babelUserOptions , opts ) as babel . TransformOptions ;
367
344
368
- const result = await babel . transformAsync ( source , babelOptions ) ;
369
- if ( ! result ) {
370
- return undefined ;
371
- }
372
- return { code : result . code || '' , map : result . map } ;
345
+ const { code, map } = await babel . transformAsync ( source , babelOptions ) ;
346
+
347
+ return { code, map } ;
373
348
} ,
374
349
} ;
375
350
}
0 commit comments