1#!/bin/sh 2 3# Shell script to update ESLint in the source tree to the latest release. 4 5# This script must be in the tools directory when it runs because it uses the 6# script source file path to determine directories to work in. 7 8set -ex 9 10ROOT=$(cd "$(dirname "$0")/../.." && pwd) 11 12[ -z "$NODE" ] && NODE="$ROOT/out/Release/node" 13[ -x "$NODE" ] || NODE=$(command -v node) 14NPM="$ROOT/deps/npm/bin/npm-cli.js" 15 16NEW_VERSION=$("$NODE" "$NPM" view eslint dist-tags.latest) 17CURRENT_VERSION=$("$NODE" -p "require('./tools/node_modules/eslint/package.json').version") 18 19echo "Comparing $NEW_VERSION with $CURRENT_VERSION" 20 21if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then 22 echo "Skipped because ESlint is on the latest version." 23 exit 0 24fi 25 26cd "$( dirname "$0" )" || exit 27rm -rf ../node_modules/eslint 28( 29 rm -rf eslint-tmp 30 mkdir eslint-tmp 31 cd eslint-tmp || exit 32 33 "$NODE" "$NPM" init --yes 34 35 "$NODE" "$NPM" install \ 36 --ignore-scripts \ 37 --install-strategy=shallow \ 38 --no-bin-links \ 39 "eslint@$NEW_VERSION" 40 # Uninstall plugins that we want to install so that they are removed from 41 # devDependencies. Otherwise --omit=dev will cause them to be skipped. 42 ( 43 cd node_modules/eslint 44 "$NODE" "$NPM" uninstall \ 45 --install-links=false \ 46 --ignore-scripts \ 47 eslint-plugin-jsdoc \ 48 eslint-plugin-markdown \ 49 @babel/core \ 50 @babel/eslint-parser \ 51 @babel/plugin-syntax-import-assertions 52 ) 53 ( 54 cd node_modules/eslint 55 "$NODE" "$NPM" install \ 56 --ignore-scripts \ 57 --install-links=false \ 58 --no-bin-links \ 59 --no-save \ 60 --omit=dev \ 61 --omit=peer \ 62 eslint-plugin-jsdoc \ 63 eslint-plugin-markdown \ 64 @babel/core \ 65 @babel/eslint-parser \ 66 @babel/plugin-syntax-import-assertions 67 ) 68 # Use dmn to remove some unneeded files. 69 "$NODE" "$NPM" exec --package=dmn@2.2.2 --yes -- dmn -f clean 70 # TODO: Get this into dmn. 71 find node_modules -name .package-lock.json -exec rm {} \; 72 find node_modules -name 'README*' -exec rm {} \; 73) 74 75mv eslint-tmp/node_modules/eslint ../node_modules/eslint 76rm -rf eslint-tmp/ 77 78# The last line of the script should always print the new version, 79# as we need to add it to $GITHUB_ENV variable. 80echo "NEW_VERSION=$NEW_VERSION" 81