2
2
3
3
export { serializePageConfigs }
4
4
5
- import { assert , assertUsage , objectEntries } from '../../../utils.js'
5
+ import { assert , assertUsage , getPropAccessNotation , hasProp , objectEntries } from '../../../utils.js'
6
6
import type {
7
7
ConfigValue ,
8
8
ConfigValueSource ,
@@ -15,6 +15,7 @@ import { debug } from './debug.js'
15
15
import { stringify } from '@brillout/json-serializer/stringify'
16
16
import { skipConfigValue } from './getVirtualFileImportCodeFiles.js'
17
17
import { getConfigEnv } from './helpers.js'
18
+ import pc from '@brillout/picocolors'
18
19
19
20
function serializePageConfigs (
20
21
pageConfigsData : PageConfigData [ ] ,
@@ -159,12 +160,19 @@ function serializeConfigValueSource(
159
160
}
160
161
function getConfigValueSerialized ( value : unknown , configName : string , configDefinedByFile : string ) : string {
161
162
let configValueSerialized : string
163
+ const valueName = `config${ getPropAccessNotation ( configName ) } `
162
164
try {
163
- configValueSerialized = stringify ( value )
164
- } catch {
165
+ configValueSerialized = stringify ( value , { valueName } )
166
+ } catch ( err ) {
167
+ assert ( hasProp ( err , 'messageCore' , 'string' ) )
168
+ const configPath = pc . bold ( configDefinedByFile )
165
169
assertUsage (
166
170
false ,
167
- `The value of the config '${ configName } ' cannot live inside ${ configDefinedByFile } , see https://vite-plugin-ssr.com/header-file`
171
+ [
172
+ `The value of the config ${ pc . cyan ( configName ) } cannot be defined inside the file ${ configPath } .` ,
173
+ `Its value must be defined in an another file and then imported by ${ configPath } (because it isn't serializable: ${ err . messageCore } ).` ,
174
+ `Only serializable config values can be defined inside ${ configPath } , see https://vite-plugin-ssr.com/header-file.`
175
+ ] . join ( ' ' )
168
176
)
169
177
}
170
178
configValueSerialized = JSON . stringify ( configValueSerialized )
0 commit comments