|
| 1 | +#!/bin/sh |
| 2 | +set -o xtrace |
| 3 | +set -e |
| 4 | + |
| 5 | +# Performs a diff between current type definition files and the latest published on npm. |
| 6 | +# This is useful as a helper to detect interface and API changes, without having to look |
| 7 | +# at source files or performing git diffs. |
| 8 | +# |
| 9 | +# Note: this script assumes that the d.ts files live under ./dist directory. |
| 10 | +# |
| 11 | +# Usage: ./scripts/ts-interface-diff.sh ethereumjs-vm packages/vm/ |
| 12 | +# Run from repository root |
| 13 | +# |
| 14 | +# To send stdout to VS Code to leverage better tools to visualize diff, you can run: |
| 15 | +# ./scripts/ts-interface-diff.sh ethereumjs-blockchain packages/blockchain/ | code- |
| 16 | +# |
| 17 | + |
| 18 | +PACKAGE_NAME=$1 |
| 19 | +DIST_PATH=$2/dist |
| 20 | +CACHE_PATH=.tmp/$PACKAGE_NAME/cache |
| 21 | + |
| 22 | +# A and B are parts of the comparison |
| 23 | +A_PATH=.tmp/$PACKAGE_NAME/A # definition files from npm |
| 24 | +B_PATH=.tmp/$PACKAGE_NAME/B # definition files from repo |
| 25 | + |
| 26 | +# setting up dir tree |
| 27 | +rm -rf .tmp/$PACKAGE_NAME |
| 28 | +mkdir -p $CACHE_PATH $A_PATH $B_PATH |
| 29 | + |
| 30 | +A_FULL_PATH=`realpath $A_PATH` |
| 31 | +B_FULL_PATH=`realpath $B_PATH` |
| 32 | + |
| 33 | +# Downloads latest published pacakge from npm. Stores tarball file name in variable TGZ |
| 34 | +TGZ=`npm pack $PACKAGE_NAME` |
| 35 | + |
| 36 | +# unpacks to $CACHE_PATH |
| 37 | +tar -xzf $TGZ --strip-components=1 -C $CACHE_PATH |
| 38 | + |
| 39 | +# # copies definition files recursively from unpacked package |
| 40 | +cd $CACHE_PATH/dist |
| 41 | +pwd -L |
| 42 | +find . | grep -E "\.d\.ts$" | cpio -pvd $A_FULL_PATH |
| 43 | +cd - |
| 44 | + |
| 45 | +# copies definition files recursively to a tmp directory |
| 46 | +cd $DIST_PATH |
| 47 | +find . | grep -E "\.d\.ts$" | cpio -pvd $B_FULL_PATH |
| 48 | +cd - |
| 49 | + |
| 50 | +# cleanup |
| 51 | +rm -rf $TGZ $CACHE_PATH |
| 52 | + |
| 53 | +git diff --no-index -- $A_PATH $B_PATH |
| 54 | + |
| 55 | +# fin. |
| 56 | + |
| 57 | +### |
| 58 | +# After running this script, you can just run the standalone command: |
| 59 | +# git diff --no-index -- .tmp/ethereumjs-vm/A .tmp/ethereumjs-vm/B |
| 60 | +# |
| 61 | +# or variations of it: |
| 62 | +# git diff --word-diff=color --no-index -- .tmp/ethereumjs-vm/A .tmp/ethereumjs-vm/B |
| 63 | +### |
0 commit comments