jest-pegjs-transform.js 441 B

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