forked from sbull/sbull-bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-npm-pack
executable file
·92 lines (61 loc) · 2 KB
/
test-npm-pack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# NOTE 2014-12-01:
# There are sometimes problems with npm-publish (missing files etc.),
# so be sure to test the build!
# https://github.com/npm/npm/issues/5082
# Change the package version before running this script,
# e.g., `npm version patch`.
GIT_DIR=`pwd`
# 0. Require a clean repository.
if [[ -n `git status -s -uno` ]]; then
echo "Please stash your changes before running."
exit 1
fi
function make_build {
# 1. Make a temporary directory for doing our work.
REV=`git rev-list master -1`
BUILD_DIR=`mktemp -d --tmpdir npm-publish-safely.$REV.XXXXXX`
echo "Building in directory: $BUILD_DIR"
# 2. Create a list of build files from the repository.
GIT_LS=$BUILD_DIR/git-ls.txt
NPM_IGNORE=$BUILD_DIR/npmignore.txt
GIT_LIST=$BUILD_DIR/git-files.txt
git ls-files | sort > $GIT_LS
if [[ -f .npmignore ]]; then
# .npmignore info: https://docs.npmjs.com/misc/developers (2015-01-01)
git ls-files -i -X .npmignore | sort > $NPM_IGNORE
diff $NPM_IGNORE $GIT_LS | awk '$1 == ">" && $2 !~ /^(node_modules\/|.gitignore$)/ { print $2 }' > $GIT_LIST
else
mv $GIT_LS $GIT_LIST
fi
# 3.pre. Clean the npm cache.
# PKG_MOD_NAME=`awk '/^[ \t]*"name":/ { FS="\""; $0=$0; print $4; exit }' $GIT_DIR/package.json`
# npm cache clean $PKG_MOD_NAME
# 3. Build the package with npm.
cd $BUILD_DIR
PKG_FILENAME=`npm pack $GIT_DIR`
# 4. Get the list of files that got packaged by npm.
PKG_FILE=$BUILD_DIR/$PKG_FILENAME
PKG_LIST=$PKG_FILE.list
tar tf $PKG_FILE | sed -e 's/^[^/]\+\///' | sort > $PKG_LIST
# 5. Compare the file lists.
DIFF=`diff $PKG_LIST $GIT_LIST | grep -e '^>'`
if [[ -n "$DIFF" ]]; then
echo "ERRORS IN npm pack:"
echo "$DIFF"
exit 1
fi
cd $GIT_DIR
rm -r $BUILD_DIR
}
NUM_ITERS=10
if [[ -n $1 ]]; then
NUM_ITERS=$1
fi
echo "Number of iterations being attempted: $NUM_ITERS"
ITERATION=0
while [ $ITERATION -lt $NUM_ITERS ]; do
let ITERATION=ITERATION+1
echo "Starting iteration $ITERATION..."
make_build
done