mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-16 17:00:35 +03:00
This allows us to load modules from scripts. This can be dangerous as it can load arbitrary files. Because of that it fails and throws by default. Currently, only js and JavaScriptTestRunner enable the default hook. This also adds tests to test-js which test module code. Because we form a spec perspective can't "enter" a module this is the easiest way to run tests without having to modify test-js to have special cases for modules. To specify modules in test-js we use the extension '.mjs' this is to ensure the files are not executed. We do still want to lint these files so the prettier scripts have changed to look for '.mjs' files as well.
39 lines
926 B
Bash
Executable File
39 lines
926 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
|
cd "${script_path}/.." || exit 1
|
|
|
|
if [ "$#" -eq "0" ]; then
|
|
mapfile -t files < <(
|
|
git ls-files \
|
|
--exclude-from .prettierignore \
|
|
-- \
|
|
'*.js' '*.mjs'
|
|
)
|
|
else
|
|
files=()
|
|
for file in "$@"; do
|
|
if [[ "${file}" == *".js" ]] || [[ "${file}" == *".mjs" ]]; then
|
|
files+=("${file}")
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if (( ${#files[@]} )); then
|
|
if ! command -v prettier >/dev/null 2>&1 ; then
|
|
echo "prettier is not available, but JS files need linting! Either skip this script, or install prettier."
|
|
exit 1
|
|
fi
|
|
|
|
if ! prettier --version | grep -qF '2.' ; then
|
|
echo "You are using '$(prettier --version)', which appears to not be prettier 2."
|
|
exit 1
|
|
fi
|
|
|
|
prettier --check "${files[@]}"
|
|
else
|
|
echo "No .js or .mjs files to check."
|
|
fi
|