Bug 1380956 - Don't manually install our local eslint plugins as npm will do that for us. r?ahal
This works since we added the modules as local references in package.json.
MozReview-Commit-ID: 5e6EkcThJTX
--- a/tools/lint/eslint/eslint-plugin-mozilla/update.sh
+++ b/tools/lint/eslint/eslint-plugin-mozilla/update.sh
@@ -31,17 +31,17 @@ case "$choice" in
* )
echo ""
echo "Invalid input."
continue
;;
esac
echo ""
-echo "Removing node_modules and npm_shrinkwrap.json..."
+echo "Removing node_modules and package-lock.json..."
# Move to the top-level directory.
rm -rf node_modules
rm package-lock.json
echo "Installing modules for eslint-plugin-mozilla..."
npm install
echo "Creating eslint-plugin-mozilla.tar.gz..."
--- a/tools/lint/eslint/setup_helper.py
+++ b/tools/lint/eslint/setup_helper.py
@@ -58,18 +58,16 @@ def eslint_setup():
This command will inspect your eslint configuration and
guide you through an interactive wizard helping you configure
eslint for optimal use on Mozilla projects.
"""
orig_cwd = os.getcwd()
sys.path.append(os.path.dirname(__file__))
- module_path = get_eslint_module_path()
-
# npm sometimes fails to respect cwd when it is run using check_call so
# we manually switch folders here instead.
os.chdir(get_project_root())
npm_path = get_node_or_npm_path("npm")
if not npm_path:
return 1
@@ -77,32 +75,16 @@ def eslint_setup():
# Install ESLint and external plugins
cmd = [npm_path, "install"]
cmd.extend(extra_parameters)
print("Installing eslint for mach using \"%s\"..." % (" ".join(cmd)))
if not call_process("eslint", cmd):
return 1
- # Install in-tree ESLint plugin mozilla.
- cmd = [npm_path, "install",
- os.path.join(module_path, "eslint-plugin-mozilla")]
- cmd.extend(extra_parameters)
- print("Installing eslint-plugin-mozilla using \"%s\"..." % (" ".join(cmd)))
- if not call_process("eslint-plugin-mozilla", cmd):
- return 1
-
- # Install in-tree ESLint plugin spidermonkey.
- cmd = [npm_path, "install",
- os.path.join(module_path, "eslint-plugin-spidermonkey-js")]
- cmd.extend(extra_parameters)
- print("Installing eslint-plugin-spidermonkey-js using \"%s\"..." % (" ".join(cmd)))
- if not call_process("eslint-plugin-spidermonkey-js", cmd):
- return 1
-
eslint_path = os.path.join(get_project_root(), "node_modules", ".bin", "eslint")
print("\nESLint and approved plugins installed successfully!")
print("\nNOTE: Your local eslint binary is at %s\n" % eslint_path)
os.chdir(orig_cwd)
@@ -122,27 +104,29 @@ def call_process(name, cmd, cwd=None):
def expected_eslint_modules():
# Read the expected version of ESLint and external modules
expected_modules_path = os.path.join(get_project_root(), "package.json")
with open(expected_modules_path, "r") as f:
expected_modules = json.load(f)["dependencies"]
- # Also read the in-tree ESLint plugin mozilla information.
+ # Also read the in-tree ESLint plugin mozilla information, to ensure the
+ # dependencies are up to date.
mozilla_json_path = os.path.join(get_eslint_module_path(),
"eslint-plugin-mozilla", "package.json")
with open(mozilla_json_path, "r") as f:
- expected_modules["eslint-plugin-mozilla"] = json.load(f)
+ expected_modules.update(json.load(f)["dependencies"])
- # Also read the in-tree ESLint plugin spidermonkey information.
+ # Also read the in-tree ESLint plugin spidermonkey information, to ensure the
+ # dependencies are up to date.
mozilla_json_path = os.path.join(get_eslint_module_path(),
"eslint-plugin-spidermonkey-js", "package.json")
with open(mozilla_json_path, "r") as f:
- expected_modules["eslint-plugin-spidermonkey-js"] = json.load(f)
+ expected_modules.update(json.load(f)["dependencies"])
return expected_modules
def check_eslint_files(node_modules_path, name):
def check_file_diffs(dcmp):
# Diff files only looks at files that are different. Not for files
# that are only present on one side. This should be generally OK as
@@ -182,35 +166,26 @@ def eslint_module_needs_setup():
if not os.path.exists(path):
print("%s v%s needs to be installed locally." % (name, version_range))
has_issues = True
continue
data = json.load(open(path))
+ if version_range.startswith("file:"):
+ # We don't need to check local file installations for versions, as
+ # these are symlinked, so we'll always pick up the latest.
+ continue
+
if not version_in_range(data["version"], version_range):
print("%s v%s should be v%s." % (name, data["version"], version_range))
has_issues = True
continue
- if name == "eslint-plugin-mozilla" or name == "eslint-plugin-spidermonkey-js":
- # For our in-tree modules, check that package.json has the same dependencies.
- if (cmp(data["dependencies"], expected_data["dependencies"]) != 0 or
- cmp(data["devDependencies"], expected_data["devDependencies"]) != 0):
- print("Dependencies of %s differ." % (name))
- has_issues = True
- continue
-
- # We also need to check the files themselves in case one changed without
- # the version number being updated.
- if check_eslint_files(node_modules_path, name):
- print("%s has out of-date files." % (name))
- has_issues = True
-
return has_issues
def version_in_range(version, version_range):
"""
Check if a module version is inside a version range. Only supports explicit versions and
caret ranges for the moment, since that's all we've used so far.
"""