jest-pegjs-transform.js 472 B

12345678910111213141516171819
  1. /* eslint-env node */
  2. // eslint-disable-next-line import/no-nodejs-modules
  3. const crypto = require('crypto');
  4. const peg = require('pegjs');
  5. function getCacheKey(fileData, _filePath, config, _options) {
  6. return crypto
  7. .createHash('md5')
  8. .update(fileData)
  9. .update(config.configString)
  10. .digest('hex');
  11. }
  12. function process(sourceText) {
  13. return `module.exports = ${peg.generate(sourceText, {output: 'source'})}`;
  14. }
  15. module.exports = {getCacheKey, process};