Skip to content

Instantly share code, notes, and snippets.

@thewhodidthis
Last active August 8, 2021 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewhodidthis/ace928743f1632d5085d040c64d16749 to your computer and use it in GitHub Desktop.
Save thewhodidthis/ace928743f1632d5085d040c64d16749 to your computer and use it in GitHub Desktop.
Super basic text diff probe via terser
'use strict'
const { exec } = require('child_process')
const assert = require('assert')
const fs = require('fs')
const path = require('path')
const util = require('util')
const { minify } = require('terser')
const readFile = util.promisify(fs.readFile)
const minifyOptions = { format: { comments: false } }
// Read target file paths in `argv` array
const [,, prevMaybe, nextMaybe] = process.argv
// Run command
differ(prevMaybe, nextMaybe)
async function differ(next = '', prev = '') {
try {
const nextInput = await readFile(next, 'utf8')
const nextInputMinified = await minify(nextInput, minifyOptions)
const prevInput = await readFile(prev, 'utf8')
const prevInputMinified = await minify(prevInput, minifyOptions)
assert.equal(prevInputMinified.code, nextInputMinified.code)
} catch (e) {
console.log(e)
}
}
{
"name": "tersimonious-differ",
"version": "0.0.0",
"description": "Throws if terser output for a couple of files is different",
"main": "index.js",
"scripts": {
"test": "node index.js index.js index.js"
},
"license": "ISC",
"dependencies": {
"terser": "^5.5.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment