UNPKG

389 BJavaScriptView Raw
1var crypto = require('crypto')
2var path = require('path')
3var cwd = process.cwd()
4
5module.exports = (code, fileName, compiledDir) => {
6 var hash = crypto
7 .createHash('sha256')
8 .update(fileName + code, 'utf8')
9 .digest('hex')
10 fileName = path.relative(cwd, fileName)
11 var hashed = fileName.replace(/[^\w]/g, '_') + '_' + hash + '.js'
12 return path.join(compiledDir, hashed)
13}