3 # look for old 0.x cruft, and get rid of it.
4 # Should already be sitting in the npm folder.
6 # This doesn't have to be quite as cross-platform as install.sh.
7 # There are some bash-isms, because maintaining *two*
8 # fully-portable posix/bourne sh scripts is too much for
9 # one project with a sane maintainer.
11 # If readlink isn't available, then this is just too tricky.
12 # However, greadlink is fine, so Solaris can join the party, too.
14 which $readlink >/dev/null 2>/dev/null
17 which $readlink >/dev/null 2>/dev/null
19 echo "Can't find the readlink or greadlink command. Aborting."
24 if [ "x$npm_config_prefix" != "x" ]; then
25 PREFIXES=$npm_config_prefix
28 if [ "x$node" = "x" ]; then
31 if [ "x$node" = "x" ]; then
32 echo "Can't find node to determine prefix. Aborting."
37 PREFIX=`dirname $node`
38 PREFIX=`dirname $PREFIX`
39 echo "cleanup prefix=$PREFIX"
42 altprefix=`"$node" -e process.installPrefix`
43 if [ "x$altprefix" != "x" ] && [ "x$altprefix" != "x$PREFIX" ]; then
44 echo "altprefix=$altprefix"
45 PREFIXES="$PREFIX $altprefix"
49 # now prefix is where npm would be rooted by default
53 for prefix in $PREFIXES; do
55 "`ls "$prefix"/lib/node/.npm 2>/dev/null | grep -v .cache`
58 packages=`echo $packages`
63 for prefix in $PREFIXES; do
64 # remove any links into the .npm dir, or links to
65 # version-named shims/symlinks.
66 for folder in share/man bin lib/node; do
67 find $prefix/$folder -type l | while read file; do
68 target=`$readlink $file | grep '/\.npm/'`
69 if [ "x$target" != "x" ]; then
71 filelist[$fid]="$file"
73 # also remove any symlinks to this file.
74 base=`basename "$file"`
75 base=`echo "$base" | awk -F@ '{print $1}'`
76 if [ "x$base" != "x" ]; then
77 find "`dirname $file`" -type l -name "$base"'*' \
79 target=`$readlink "$l" | grep "$base"`
80 if [ "x$target" != "x" ]; then
89 # Scour for shim files. These are relics of 0.2 npm installs.
90 # note: grep -r is not portable.
91 find $prefix/$folder -type f \
92 | xargs grep -sl '// generated by npm' \
94 filelist[$fid]="$file"
99 # now remove the package modules, and the .npm folder itself.
100 if [ "x$packages" != "x" ]; then
101 for pkg in $packages; do
102 filelist[$fid]="$prefix/lib/node/$pkg"
104 for i in $prefix/lib/node/$pkg\@*; do
111 for folder in lib/node/.npm lib/npm share/npm; do
112 if [ -d $prefix/$folder ]; then
113 filelist[$fid]="$prefix/$folder"
119 # now actually clean, but only if there's anything TO clean
120 if [ "${#filelist[@]}" -gt 0 ]; then
122 echo "This script will find and eliminate any shims, symbolic"
123 echo "links, and other cruft that was installed by npm 0.x."
126 if [ "x$packages" != "x" ]; then
127 echo "The following packages appear to have been installed with"
128 echo "an old version of npm, and will be removed forcibly:"
129 for pkg in $packages; do
132 echo "Make a note of these. You may want to install them"
133 echo "with npm 1.0 when this process is completed."
138 if [ "x$1" = "x-y" ]; then
142 while [ "$OK" != "y" ] && [ "$OK" != "yes" ] && [ "$OK" != "no" ]; do
144 echo " enter 'yes' or 'no'"
145 echo " or 'show' to see a list of files "
147 if [ "x$OK" = "xshow" ] || [ "x$OK" = "xs" ]; then
148 for i in "${filelist[@]}"; do
153 if [ "$OK" = "no" ]; then
157 for i in "${filelist[@]}"; do