MCPcopy Create free account
hub / github.com/arktypeio/arktype / nextConfigReadOf

Function nextConfigReadOf

ark/aot/nextProgram.ts:298–341  ·  view source on GitHub ↗
(
	config: NextConfigLike,
	isOwnLoader: (loader: string) => boolean
)

Source from the content-addressed store, hash-verified

296// sets of options, or pages of an extension it doesn't read. Else the options
297// its rules give this loader
298export const nextConfigReadOf = (
299 config: NextConfigLike,
300 isOwnLoader: (loader: string) => boolean
301): { problem: string } | { options: PrecompilePluginOptions } => {
302 if (
303 config.pageExtensions !== undefined &&
304 !(
305 Array.isArray(config.pageExtensions) &&
306 config.pageExtensions.every(extension =>
307 pageExtensions.includes(extension)
308 )
309 )
310 ) {
311 return {
312 problem: "next.config sets pageExtensions, whose pages it can't read"
313 }
314 }
315 const swcPlugins = config.experimental?.swcPlugins
316 if (Array.isArray(swcPlugins) && swcPlugins.length) {
317 return {
318 problem:
319 "next.config runs SWC plugins after this loader, which may add reads it can't see"
320 }
321 }
322 const options = new Map<string, PrecompilePluginOptions>()
323 for (const item of loadersIn(Object.values(config.turbopack?.rules ?? {}))) {
324 const loader = typeof item === "string" ? item : item.loader
325 if (typeof loader !== "string")
326 return { problem: "next.config runs a loader it can't name" }
327 if (!isOwnLoader(loader)) {
328 return {
329 problem: `next.config runs ${loader}, which may add imports it can't see`
330 }
331 }
332 const given = (typeof item === "string" ? undefined : item.options) ?? {}
333 options.set(JSON.stringify(given), given as PrecompilePluginOptions)
334 }
335 if (options.size > 1) {
336 return {
337 problem: `next.config runs the loader with ${options.size} sets of options`
338 }
339 }
340 return { options: [...options.values()][0] ?? {} }
341}
342
343type LoaderItem = string | { loader: string; options?: unknown }
344

Callers 2

readOfFunction · 0.90
readProjectWithFunction · 0.85

Calls 3

loadersInFunction · 0.85
isOwnLoaderFunction · 0.85
setMethod · 0.45

Tested by 1

readOfFunction · 0.72