@@ -16,7 +16,6 @@ import type {
16
16
} from '../types'
17
17
import type { JsPluginExtended , WatchChangeEvents } from './utils'
18
18
19
- import { existsSync } from 'node:fs'
20
19
import path from 'node:path'
21
20
22
21
import { toArray } from '../utils/general'
@@ -28,8 +27,8 @@ import {
28
27
customParseQueryString ,
29
28
decodeStr ,
30
29
encodeStr ,
30
+ formatTransformModuleType ,
31
31
getContentValue ,
32
- guessIdLoader ,
33
32
isObject ,
34
33
isStartsWithSlash ,
35
34
isString ,
@@ -88,13 +87,11 @@ export function toFarmPlugin(plugin: UnpluginOptions, options?: Record<string, a
88
87
filters = options ?. filters ?? [ ]
89
88
90
89
farmPlugin . resolve = {
91
- filters : { sources : [ '.*' , ... filters ] , importers : [ '.*' ] } ,
90
+ filters : { sources : filters . length ? filters : [ '.*' ] , importers : [ '.*' ] } ,
92
91
async executor ( params : PluginResolveHookParam , context : CompilationContext ) {
93
92
const resolvedIdPath = path . resolve (
94
- process . cwd ( ) ,
95
93
params . importer ?? '' ,
96
94
)
97
-
98
95
let isEntry = false
99
96
if ( isObject ( params . kind ) && 'entry' in params . kind ) {
100
97
const kindWithEntry = params . kind as { entry : string }
@@ -126,23 +123,9 @@ export function toFarmPlugin(plugin: UnpluginOptions, options?: Record<string, a
126
123
meta : { } ,
127
124
}
128
125
}
126
+
129
127
if ( ! isStartsWithSlash ( params . source ) )
130
128
return null
131
-
132
- const rootAbsolutePath = path . resolve (
133
- params . source ,
134
- )
135
- if (
136
- existsSync ( rootAbsolutePath )
137
- ) {
138
- return {
139
- resolvedPath : removeQuery ( encodeStr ( rootAbsolutePath ) ) ,
140
- query : customParseQueryString ( rootAbsolutePath ) ,
141
- sideEffects : false ,
142
- external : false ,
143
- meta : { } ,
144
- }
145
- }
146
129
} ,
147
130
} as unknown as JsPlugin [ 'resolve' ]
148
131
}
@@ -161,7 +144,7 @@ export function toFarmPlugin(plugin: UnpluginOptions, options?: Record<string, a
161
144
162
145
const id = appendQuery ( resolvedPath , params . query )
163
146
164
- const loader = guessIdLoader ( resolvedPath )
147
+ const loader = formatTransformModuleType ( id )
165
148
166
149
const shouldLoadInclude
167
150
= plugin . loadInclude ?.( id )
@@ -198,7 +181,7 @@ export function toFarmPlugin(plugin: UnpluginOptions, options?: Record<string, a
198
181
199
182
const id = appendQuery ( resolvedPath , params . query )
200
183
201
- const loader = params . moduleType ?? guessIdLoader ( params . resolvedPath )
184
+ const loader = formatTransformModuleType ( id )
202
185
203
186
const shouldTransformInclude
204
187
= plugin . transformInclude ?.( id )
@@ -216,7 +199,9 @@ export function toFarmPlugin(plugin: UnpluginOptions, options?: Record<string, a
216
199
const transformFarmResult : PluginTransformHookResult = {
217
200
content : getContentValue ( resource ) ,
218
201
moduleType : loader ,
219
- sourceMap : JSON . stringify ( resource . map ) ,
202
+ sourceMap : typeof resource . map === 'object' && resource . map !== null
203
+ ? JSON . stringify ( resource . map )
204
+ : undefined ,
220
205
}
221
206
222
207
return transformFarmResult
0 commit comments