Skip to content

Commit 965739e

Browse files
authored
Merge pull request #260 from stronk7/node18_compatibility_and_more
Node18 compatibility and more
2 parents 33e6cd2 + 27846eb commit 965739e

File tree

8 files changed

+120
-106
lines changed

8 files changed

+120
-106
lines changed

grunt_process/grunt_process.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ if [[ -n ${npminstall} ]]; then
3838
source ${mydir}/../prepare_npm_stuff/prepare_npm_stuff.sh
3939
fi
4040

41-
# Ensure we have grunt cli available before continue.
42-
gruntcmd="$(${npmcmd} bin)"/grunt
43-
if [ ! -x $gruntcmd ]; then
41+
# Ensure we have grunt binary available before continue.
42+
#
43+
if [[ ! -x node_modules/.bin/grunt ]]; then
4444
echo "Error: grunt executable not found" | tee "${outputfile}"
4545
exitstatus=1
4646
else
@@ -63,7 +63,7 @@ else
6363
fi
6464

6565
set +e
66-
$gruntcmd $tasks --no-color > >(tee "${outputfile}") 2> >(tee "${outputfile}".stderr >&2)
66+
npx grunt $tasks --no-color > >(tee "${outputfile}") 2> >(tee "${outputfile}".stderr >&2)
6767
exitstatus=$?
6868
set -e
6969
fi

prepare_npm_stuff/prepare_npm_stuff.sh

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -90,72 +90,40 @@ if [[ -f ${gitdir}/package.json ]]; then
9090

9191
echo "INFO: Installing npm stuff following package/shrinkwrap details"
9292

93+
if ! hash ${npmcmd} 2>/dev/null; then
94+
echo "ERROR: npm not found in the system. Use .nvmrc OR install it in the PATH"
95+
exit 2
96+
fi
97+
9398
# Always run npm install to keep our npm packages correct
9499
${npmcmd} --no-color install
95100

96-
# Verify there is a grunt executable available, installing if missing
97-
gruntcmd="$(${npmcmd} bin)"/grunt
98-
if [[ ! -f ${gruntcmd} ]]; then
99-
echo "WARN: grunt-cli executable not found. Installing everything"
100-
${npmcmd} --no-color --no-save install grunt-cli
101-
fi
102-
else
103-
104-
# Install shifter version if there is not package.json
105-
# (this is required for branches < 29_STABLE)
106-
shifterinstall=""
107-
shiftercmd="$(${npmcmd} bin)"/shifter
108-
if [[ ! -f ${shiftercmd} ]]; then
109-
echo "WARN: shifter executable not found. Installing it"
110-
shifterinstall=1
111-
else
112-
# Have shifter, look its version matches expected one
113-
# Cannot use --version because it's varying (performing calls to verify latest). Use --help instead
114-
shiftercurrent=$(${shiftercmd} --no-color --help | head -1 | cut -d "@" -f2)
115-
if [[ "${shiftercurrent}" != "${shifterversion}" ]]; then
116-
echo "WARN: shifter executable "${shiftercurrent}" found, "${shifterversion}" expected. Installing it"
117-
shifterinstall=1
118-
else
119-
# All right, shifter found and version matches
120-
echo "INFO: shifter executable (${shifterversion}) found"
101+
# Verify that grunt-cli is available (locally), installing if missing
102+
if ! ${npmcmd} list --parseable | grep -q grunt-cli; then
103+
# Last chance, look for the binary itself.
104+
if [[ ! -x node_modules/.bin/grunt ]]; then
105+
echo "WARN: grunt binary not found. Installing it now"
106+
${npmcmd} --no-color --no-save install grunt-cli
121107
fi
122108
fi
123-
if [[ -n ${shifterinstall} ]]; then
124-
${npmcmd} --no-color install shifter@${shifterversion}
125-
echo "INFO: shifter executable (${shifterversion}) installed"
126-
fi
127109

128-
# Install recess version if there is not package.json
129-
# (this is required for branches < 29_STABLE)
130-
recessinstall=""
131-
recesscmd="$(${npmcmd} bin)"/recess
132-
if [[ ! -f ${recesscmd} ]]; then
133-
echo "WARN: recess executable not found. Installing it"
134-
recessinstall=1
135-
else
136-
# Have recess, look its version matches expected one
137-
recesscurrent=$(${recesscmd} --no-color --version)
138-
if [[ "${recesscurrent}" != "${recessversion}" ]]; then
139-
echo "WARN: recess executable "${recesscurrent}" found, "${recessversion}" expected. Installing it"
140-
recessinstall=1
141-
else
142-
# All right, recess found and version matches
143-
echo "INFO: recess executable (${recessversion}) found"
144-
fi
145-
fi
146-
if [[ -n ${recessinstall} ]]; then
147-
${npmcmd} --no-color install recess@${recessversion}
148-
echo "INFO: recess executable (${recessversion}) installed"
110+
# Verify that stylelint-checkstyle-formatter is available (locally), installing if missing
111+
if ! ${npmcmd} list --parseable | grep -q stylelint-checkstyle-formatter; then
112+
echo "WARN: stylelint-checkstyle-formatter package not found. Installing it now"
113+
${npmcmd} --no-color --no-save install stylelint-checkstyle-formatter
149114
fi
115+
else
116+
echo "ERROR: Something is wrong. Missing package.json"
150117
fi
151118

152119
# Move back to base directory.
153120
cd ${gitdir}
154121

155122
# Output information about installed binaries.
156123
echo "INFO: Installation ended"
157-
echo "INFO: Available binaries @ ${gitdir}"
158-
echo "INFO: (Contents of $(${npmcmd} bin))"
159-
for binary in $(ls $(${npmcmd} bin)); do
160-
echo "INFO: - Installed ${binary}"
124+
echo "INFO: Installed packages @ $(npm root)"
125+
echo "INFO: (Contents of ${npmcmd} list --depth=1)"
126+
for package in $(${npmcmd} list --depth=1 --parseable); do
127+
echo "INFO: - Installed $(basename ${package})"
161128
done
129+
echo "============== END OF LIST =============="

remote_branch_checker/remote_branch_checker.sh

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,14 @@ cat "${WORKSPACE}/work/mustachelint.txt" | ${phpcmd} ${mydir}/checkstyle_convert
370370

371371
if [ -f $WORKSPACE/.gherkin-lintrc ]; then
372372
echo "Info: Running gherkin-lint..."
373-
gherkinlintcmd="$(${npmcmd} bin)"/gherkin-lint
374-
if [ -x $gherkinlintcmd ]; then
375-
$gherkinlintcmd --format=json '**/tests/behat/*.feature' 2> "${WORKSPACE}/work/gherkin-lint.txt"
376-
cat "${WORKSPACE}/work/gherkin-lint.txt" | ${phpcmd} ${mydir}/checkstyle_converter.php --format=gherkinlint > "${WORKSPACE}/work/gherkin-lint.xml"
377-
else
378-
echo "Error: .gherkin-lintrc file found, but /gherkin-lint executable not found" | tee -a ${errorfile}
373+
if ! ${npmcmd} list --depth=1 --parseable | grep -q gherkin-lint; then
374+
echo "Error: .gherkin-lintrc file found, but gherkin-lint package not found" | tee -a ${errorfile}
379375
exit 1
380376
fi
377+
378+
# Run gherkin-lint
379+
npx gherkin-lint --format=json '**/tests/behat/*.feature' 2> "${WORKSPACE}/work/gherkin-lint.txt"
380+
cat "${WORKSPACE}/work/gherkin-lint.txt" | ${phpcmd} ${mydir}/checkstyle_converter.php --format=gherkinlint > "${WORKSPACE}/work/gherkin-lint.xml"
381381
fi
382382

383383
# Run the grunt checker if Gruntfile exists. node stuff has been already installed.
@@ -425,28 +425,27 @@ set +e
425425

426426
if [ -f $WORKSPACE/.eslintrc ]; then
427427
echo "Info: Running eslint..."
428-
eslintcmd="$(${npmcmd} bin)"/eslint
429-
if [ -x $eslintcmd ]; then
430-
# TODO: Remove this once everybody is using nodejs 14 or up.
431-
# We need to invoke eslint differently depending of the installed version.
432-
# (new versions v6.8 and up have this option to avoid exiting with error if there aren't JS files)
433-
eslintarg="--no-error-on-unmatched-pattern"
434-
# Old versions don't have this option, they exit without error if there aren't JS files, so don't use it.
435-
if ! $eslintcmd --help | grep -q -- $eslintarg; then
436-
eslintarg=""
437-
fi
438-
$eslintcmd -f checkstyle $eslintarg $WORKSPACE > "${WORKSPACE}/work/eslint.xml"
439-
else
440-
echo "Error: .eslintrc file found, but eslint executable not found" | tee -a ${errorfile}
428+
if ! ${npmcmd} list --depth=1 --parseable | grep -q eslint; then
429+
echo "Error: .eslintrc file found, but eslint package not found" | tee -a ${errorfile}
441430
exit 1
442431
fi
432+
433+
# Run eslint
434+
# TODO: Remove this once everybody is using nodejs 14 or up.
435+
# We need to invoke eslint differently depending of the installed version.
436+
# (new versions v6.8 and up have this option to avoid exiting with error if there aren't JS files)
437+
eslintarg="--no-error-on-unmatched-pattern"
438+
# Old versions don't have this option, they exit without error if there aren't JS files, so don't use it.
439+
if ! npx eslint --help | grep -q -- $eslintarg; then
440+
eslintarg=""
441+
fi
442+
npx eslint -f checkstyle $eslintarg $WORKSPACE > "${WORKSPACE}/work/eslint.xml"
443443
fi
444444

445445
if [ -f $WORKSPACE/.stylelintrc ]; then
446446
echo "Info: Running stylelint..."
447-
stylelintcmd="$(${npmcmd} bin)"/stylelint
448-
if [ ! -x $stylelintcmd ]; then
449-
echo "Error: .stylelintrc file found, but stylelint executable not found" | tee -a ${errorfile}
447+
if ! ${npmcmd} list --depth=1 --parseable | grep -q stylelint; then
448+
echo "Error: .stylelintrc file found, but stylelint package not found" | tee -a ${errorfile}
450449
exit 1
451450
fi
452451

@@ -456,10 +455,10 @@ if [ -f $WORKSPACE/.stylelintrc ]; then
456455
# (new versions 7.7.0 and up have this option to avoid exiting with error if there aren't CSS files)
457456
stylelintarg="--allow-empty-input"
458457
# Old versions don't have this option, they exit without error if there aren't CSS files, so don't use it.
459-
if ! $stylelintcmd --help | grep -q -- $stylelintarg; then
458+
if ! npx stylelint --help | grep -q -- $stylelintarg; then
460459
eslintarg=""
461460
fi
462-
if $stylelintcmd $stylelintarg --customFormatter 'node_modules/stylelint-checkstyle-formatter' "*/**/*.{css,less,scss}" > "${WORKSPACE}/work/stylelint.xml"
461+
if npx stylelint $stylelintarg --customFormatter 'node_modules/stylelint-checkstyle-formatter' "*/**/*.{css,less,scss}" > "${WORKSPACE}/work/stylelint.xml"
463462
then
464463
echo "Info: stylelint completed without errors."
465464
else

tests/1-grunt_process.bats

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ setup () {
4747
# When a third party library is added, developers need to commit
4848
# ignorefiles change since 3.2.
4949

50-
# Testing on in-dev 3.2dev
51-
create_git_branch 32-dev 5a1728df39116fc701cc907e85a638aa7674f416
52-
git_apply_fixture 32-thirdparty-lib-added.patch
50+
# Testing on v3.5.9
51+
create_git_branch 35-stable v3.5.9
52+
git_apply_fixture 35-thirdparty-lib-added.patch
5353

5454
# Run test
5555
ci_run grunt_process/grunt_process.sh
@@ -64,9 +64,9 @@ setup () {
6464
# When a 3rd party library is added, but we are checking a 3rd part plugin
6565
# we ignore any change in ignorefiles.
6666

67-
# Testing on in-dev 3.2dev
68-
create_git_branch 32-dev 5a1728df39116fc701cc907e85a638aa7674f416
69-
git_apply_fixture 32-thirdparty-lib-added.patch
67+
# Testing on v3.5.9
68+
create_git_branch 35-stable v3.5.9
69+
git_apply_fixture 35-thirdparty-lib-added.patch
7070

7171
# Run test
7272
export isplugin=1

tests/2-remote_branch_checker.bats

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ assert_prechecker () {
3131
assert_files_same $smurfxmlfixture $WORKSPACE/work/smurf.xml
3232
}
3333

34-
@test "remote_branch_checker/remote_branch_checker.sh: old branch failing" {
35-
# An extremely old branch running jshint..
36-
assert_prechecker local_ci_fixture_oldbranch MDLSITE-3899 v2.9.0-rc1
34+
@test "remote_branch_checker/remote_branch_checker.sh: old branch (38_STABLE) failing" {
35+
# An extremely old branch. MOODLE_38_STABLE (with node v14) is the oldest we support.
36+
# (note MOODLE_35_STABLE and up also is supported but not v3.5.0, v3.6.0... support came later and
37+
# we need to use always .0 versions in the tests as base, so 3.8.0 is the very first .0).
38+
assert_prechecker local_ci_fixture_oldbranch_38 MDLSITE-3899 v3.8.0
3739
}
3840

3941
@test "remote_branch_checker/remote_branch_checker.sh: all possible checks failing" {

tests/3-prepare_npm_stuff.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ setup () {
6363
# Assert result.
6464
# Cannot know if install will success or no (depends if npm/node binaries are elsewhere)
6565
# (hence, we are not asserting the result, just that the case is handled)
66+
67+
# Note this can end with some warnings if npm/node is not installed elsewhere and with
68+
# exit status = 2, but, as commented above, we are not asserting that here (success / failure...)
69+
# so that's ok.
6670
assert_output --partial "INFO: nvm not found, installing via git"
6771
assert_output --partial "INFO: nvm git installation found, updating to latest release"
6872
assert_output --partial "INFO: using nvm version:"
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
From 4600d7d6fd5d5bd4f5bae80c3e89b838d95f2b1d Mon Sep 17 00:00:00 2001
1+
From 96ec9462a7d7a05f39af044020b63e371831ab05 Mon Sep 17 00:00:00 2001
22
From: Dan Poltawski <[email protected]>
33
Date: Tue, 12 Jul 2016 11:23:56 +0100
4-
Subject: [PATCH 1/1] MDLSITE-4678 fixture: adding third party lib
4+
Subject: [PATCH] MDLSITE-4678 fixture: adding third party lib
55

66
---
77
lib/thirdpartylibs.xml | 6 ++++++
88
1 file changed, 6 insertions(+)
99

1010
diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml
11-
index 6440a73..3385d2f 100644
11+
index c14a3e01d4..ba719b5f84 100644
1212
--- a/lib/thirdpartylibs.xml
1313
+++ b/lib/thirdpartylibs.xml
14-
@@ -275,4 +275,10 @@
15-
<license>GPL</license>
16-
<version>2.3.0</version>
14+
@@ -323,4 +323,10 @@
15+
<license>MIT</license>
16+
<version>1.1.1</version>
1717
</library>
1818
+ <library>
1919
+ <location>integrationtest</location>
@@ -23,5 +23,5 @@ index 6440a73..3385d2f 100644
2323
+ </library>
2424
</libraries>
2525
--
26-
2.9.0
26+
2.39.1
2727

0 commit comments

Comments
 (0)