MCPcopy
hub / github.com/vercel/next.js / loader

Function loader

packages/next-mdx/mdx-rs-loader.js:59–94  ·  view source on GitHub ↗

* A webpack loader for mdx-rs. This is largely based on existing @mdx-js/loader, * replaces internal compilation logic to use mdx-rs instead.

(value, bindings, callback)

Source from the content-addressed store, hash-verified

57 * replaces internal compilation logic to use mdx-rs instead.
58 */
59function loader(value, bindings, callback) {
60 const defaults = this.sourceMap ? { SourceMapGenerator } : {}
61 const options = this.getOptions()
62 const config = { ...defaults, ...options }
63 const hash = getOptionsHash(options)
64 const compiler = this._compiler || marker
65
66 let map = cache.get(compiler)
67
68 if (!map) {
69 map = new Map()
70 cache.set(compiler, map)
71 }
72
73 let process = map.get(hash)
74
75 if (!process) {
76 process = createFormatAwareProcessors(
77 bindings,
78 coereceMdxTransformOptions(config)
79 ).compile
80 map.set(hash, process)
81 }
82
83 process({ value, path: this.resourcePath }).then(
84 (code) => {
85 // TODO: no sourcemap
86 callback(null, code, null)
87 },
88 (error) => {
89 const fpath = path.relative(this.context, this.resourcePath)
90 error.message = `${fpath}:${error.name}: ${error.message}`
91 callback(error)
92 }
93 )
94}
95
96function getOptionsHash(options) {
97 const hash = createHash('sha256')

Callers 1

source.tsFile · 0.50

Calls 9

getOptionsHashFunction · 0.85
processFunction · 0.85
getOptionsMethod · 0.80
thenMethod · 0.80
getMethod · 0.65
setMethod · 0.65
callbackFunction · 0.50

Tested by

no test coverage detected