parseGlobOptions() — vite Function Reference
Architecture documentation for the parseGlobOptions() function in importMetaGlob.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 82795e66_8dfd_fa82_3c8a_e25c455f5e42["parseGlobOptions()"] b68d9c02_4026_8cfa_8eb1_35ec4a8f23cb["importMetaGlob.ts"] 82795e66_8dfd_fa82_3c8a_e25c455f5e42 -->|defined in| b68d9c02_4026_8cfa_8eb1_35ec4a8f23cb e4ded9fb_6262_73a6_ae73_068c08e2b994["parseImportGlob()"] e4ded9fb_6262_73a6_ae73_068c08e2b994 -->|calls| 82795e66_8dfd_fa82_3c8a_e25c455f5e42 59716ea1_465c_8cb5_daff_ba167d787a1e["evalValue()"] 82795e66_8dfd_fa82_3c8a_e25c455f5e42 -->|calls| 59716ea1_465c_8cb5_daff_ba167d787a1e 97ec4c6d_f8dd_eac0_9f3c_6fbc9c14481f["err()"] 82795e66_8dfd_fa82_3c8a_e25c455f5e42 -->|calls| 97ec4c6d_f8dd_eac0_9f3c_6fbc9c14481f style 82795e66_8dfd_fa82_3c8a_e25c455f5e42 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/importMetaGlob.ts lines 147–243
function parseGlobOptions(
rawOpts: string,
optsStartIndex: number,
logger?: Logger,
): ParsedGeneralImportGlobOptions {
let opts: GeneralImportGlobOptions = {}
try {
opts = evalValue(rawOpts)
} catch {
throw err(
'Vite is unable to parse the glob options as the value is not static',
optsStartIndex,
)
}
if (opts == null) {
return {}
}
for (const key in opts) {
if (!(key in knownOptions)) {
throw err(`Unknown glob option "${key}"`, optsStartIndex)
}
const allowedTypes = knownOptions[key as keyof typeof knownOptions]
const valueType = typeof opts[key as keyof GeneralImportGlobOptions]
if (!allowedTypes.includes(valueType)) {
throw err(
`Expected glob option "${key}" to be of type ${allowedTypes.join(
' or ',
)}, but got ${valueType}`,
optsStartIndex,
)
}
}
if (opts.base) {
if (opts.base[0] === '!') {
throw err('Option "base" cannot start with "!"', optsStartIndex)
} else if (
opts.base[0] !== '/' &&
!opts.base.startsWith('./') &&
!opts.base.startsWith('../')
) {
throw err(
`Option "base" must start with '/', './' or '../', but got "${opts.base}"`,
optsStartIndex,
)
}
}
if (typeof opts.query === 'object') {
for (const key in opts.query) {
const value = opts.query[key]
if (!['string', 'number', 'boolean'].includes(typeof value)) {
throw err(
`Expected glob option "query.${key}" to be of type string, number, or boolean, but got ${typeof value}`,
optsStartIndex,
)
}
}
// normalize query as string so it's easier to handle later
opts.query = stringifyQuery(opts.query)
}
if (opts.as && logger) {
const importSuggestion = forceDefaultAs.includes(opts.as)
? `, import: 'default'`
: ''
logger.warn(
colors.yellow(
`The glob option "as" has been deprecated in favour of "query". Please update \`as: '${opts.as}'\` to \`query: '?${opts.as}'${importSuggestion}\`.`,
),
)
}
// validate `import` option based on `as` option
if (opts.as && forceDefaultAs.includes(opts.as)) {
if (opts.import && opts.import !== 'default' && opts.import !== '*')
throw err(
`Option "import" can only be "default" or "*" when "as" is "${opts.as}", but got "${opts.import}"`,
optsStartIndex,
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does parseGlobOptions() do?
parseGlobOptions() is a function in the vite codebase, defined in packages/vite/src/node/plugins/importMetaGlob.ts.
Where is parseGlobOptions() defined?
parseGlobOptions() is defined in packages/vite/src/node/plugins/importMetaGlob.ts at line 147.
What does parseGlobOptions() call?
parseGlobOptions() calls 2 function(s): err, evalValue.
What calls parseGlobOptions()?
parseGlobOptions() is called by 1 function(s): parseImportGlob.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free