Skip to content

Commit

Permalink
Use any for the loader type
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz committed Feb 27, 2022
1 parent 8884d0a commit efb78d1
Showing 1 changed file with 2 additions and 8 deletions.
@@ -1,27 +1,21 @@
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import crypto from 'crypto'

export type WasmBinding = {
filePath: string
name: string
}

const MiddlewareWasmLoader: webpack.loader.Loader = function (
source,
_sourceMap
) {
export default function MiddlewareWasmLoader(this: any, source: Buffer) {
const name = `wasm_${sha1(source)}`
const filePath = `server/middleware-chunks/${name}.wasm`
const binding: WasmBinding = { filePath, name }
this._module.buildInfo.nextWasmMiddlewareBinding = binding
this.emitFile(`/${filePath}`, source, null)
return `module.exports = globalThis[${JSON.stringify(name)}];`
return `module.exports = name;`
}

export const raw = true

export default MiddlewareWasmLoader

function sha1(source: string | Buffer) {
return crypto.createHash('sha1').update(source).digest('hex')
}

0 comments on commit efb78d1

Please sign in to comment.