* 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)
| 57 | * replaces internal compilation logic to use mdx-rs instead. |
| 58 | */ |
| 59 | function 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 | |
| 96 | function getOptionsHash(options) { |
| 97 | const hash = createHash('sha256') |
no test coverage detected