Allow manage_node_deps to run custom npm commands

This allows us to execute the following:

npm run install-deps -- outdated

Which is equivalent to `npm outdated`, although it will run on the
actual node_modules output (that we can verify is unchanged).

Most of the npm commands require the private information to exist.
Therefore, if we run a custom command we first have to install with
`npm ci` to get the private information. Then we have to execute
the command, perform the cleanup and only after that finisht the
script. If we would bail out right after executing the custom command,
the private information would remain in the repository.

R=jacktfranklin@chromium.org

Fixed: 1068132
Change-Id: I50d3538a7115783dea19e1899faf17b1622f22ff
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2137381
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
This commit is contained in:
Tim van der Lippe
2020-04-06 13:01:08 +00:00
committed by Commit Bot
parent 21ebdb46fc
commit 35cca41271
2 changed files with 28 additions and 18 deletions
+4 -4
View File
@@ -33,9 +33,9 @@
"debug-unittest": "DEBUG=1 npm run unittest",
"e2etest": "python scripts/test/run_test_suite.py --test-suite=e2e",
"eslint-test": "mocha \"./scripts/eslint_rules/tests/*_test.js\"",
"generate-bridge-file": "tsc -p scripts/component_bridges/tsconfig.json && node scripts/component_bridges/gen/cli.js",
"generate-bridges-test": "tsc -p test/unittests/scripts/component_bridges/tsconfig.json && mocha test/unittests/scripts/component_bridges/**/*_test.js",
"generate-protocol-resources": "python scripts/deps/generate_protocol_resources.py && git cl format --js",
"generate-bridge-file": "tsc -p scripts/component_bridges/tsconfig.json && node scripts/component_bridges/gen/cli.js",
"install-deps": "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true python scripts/deps/manage_node_deps.py",
"interactive-screenshottest": "INTERACTIVE=1 python scripts/test/run_test_suite.py --test-suite=screenshots",
"optimize-svg-images": "python scripts/optimize_svg_images.py",
@@ -47,7 +47,7 @@
"start": "node scripts/hosted_mode/start_chrome_and_server.js",
"test": "node scripts/npm_test.js",
"test-local": "node scripts/npm_test.js --layout-tests-directory=test/webtests/",
"unittest": "NO_TEXT_COVERAGE=1 python scripts/test/run_unittests.py",
"ts_library-test": "./third_party/typescript/tests/verify_ts_libary.sh"
"ts_library-test": "./third_party/typescript/tests/verify_ts_libary.sh",
"unittest": "NO_TEXT_COVERAGE=1 python scripts/test/run_unittests.py"
}
}
}
+24 -14
View File
@@ -65,8 +65,8 @@ DEPS = {
def exec_command(cmd):
try:
cmd_proc_result = subprocess.check_call(cmd, cwd=devtools_paths.root_path())
except Error as error:
print(error.output)
except Exception as error:
print(error)
return True
return False
@@ -93,7 +93,6 @@ def strip_private_fields():
for pkg in packages:
with open(pkg, 'r+') as pkg_file:
prop_removal_count = 0
try:
pkg_data = json.load(pkg_file)
@@ -102,12 +101,10 @@ def strip_private_fields():
for key in pkg_data.keys():
if key.find(u'_') == 0:
pkg_data.pop(key)
prop_removal_count = prop_removal_count + 1
pkg_file.truncate(0)
pkg_file.seek(0)
json.dump(pkg_data, pkg_file, indent=2, sort_keys=True, separators=(',', ': '))
print("(%s): %s" % (prop_removal_count, pkg))
except:
print('Unable to fix: %s' % pkg)
return True
@@ -115,6 +112,7 @@ def strip_private_fields():
return False
# Required to keep the package-lock.json in sync with the package.json dependencies
def install_missing_deps():
with open(devtools_paths.package_lock_json_path(), 'r+') as pkg_lock_file:
try:
@@ -188,37 +186,49 @@ def addClangFormat():
return False
def install_deps():
def run_npm_command(npm_command_args=None):
for (name, version) in DEPS.items():
if (version.find(u'^') == 0):
print('Versions must be locked to a specific version; remove ^ from the start of the version.')
return True
run_custom_command = npm_command_args is not None
if append_package_json_entries():
return True
if install_missing_deps():
return True
# Run the CI version of npm, which prevents updates to the versions of modules.
# By default, run the CI version of npm, which prevents updates to the versions of modules.
if exec_command(['npm', 'ci']):
return True
if run_custom_command:
custom_command_result = exec_command(['npm'] + npm_command_args)
if remove_package_json_entries():
return True
if strip_private_fields():
return True
if remove_package_json_entries():
return True
if addClangFormat():
return True
if run_custom_command:
return custom_command_result
return ensure_licenses()
npm_errors_found = install_deps()
npm_args = None
if (len(sys.argv[1:]) > 0):
npm_args = sys.argv[1:]
npm_errors_found = run_npm_command(npm_args)
if npm_errors_found:
print('npm installation failed')
else:
print('npm installation successful')
print('npm command failed')
exit(1)