Last active
August 8, 2021 16:22
-
-
Save thewhodidthis/ace928743f1632d5085d040c64d16749 to your computer and use it in GitHub Desktop.
Super basic text diff probe via terser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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