Skip to content

Commit 99cd9f4

Browse files
committed
Make docs:check-links task Windows compatible.
`npx --call` uses the native shell. This means the shell code used by the task does not work on Windows. After quite a bit of unsuccessful efforts, I decided that it is simply too difficult to use npx for this application on Windows. So the Windows user is required to have markdown-link-check installed and in PATH. Because Task uses an integrated shell interpreter, shell code is usable as long as it is not wrapped in a `npx --call` command.
1 parent bee41c0 commit 99cd9f4

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

Taskfile.yml

+35-7
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,41 @@ tasks:
196196
desc: Check for dead links in documentation
197197
cmds:
198198
- |
199-
npx --package markdown-link-check --call '
200-
STATUS=0
201-
for file in $(find -name "*.md"); do
202-
markdown-link-check --quiet "$file"
203-
STATUS=$(( $STATUS + $? ))
204-
done
205-
exit $STATUS'
199+
if [[ "{{.OS}}" == "Windows_NT" ]]; then
200+
# npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
201+
# so the Windows user is required to have markdown-link-check installed and in PATH.
202+
if ! which markdown-link-check &>/dev/null; then
203+
echo "markdown-link-check not found or not in PATH. Please install: https://github.com/tcort/markdown-link-check#readme"
204+
exit 1
205+
fi
206+
# Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
207+
# exit status, but it's better to check all links before exiting.
208+
set +o errexit
209+
STATUS=0
210+
# Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
211+
# The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
212+
# \ characters special treatment on Windows in an attempt to support them as path separators.
213+
for file in $(find . -regex ".*[.]md"); do
214+
markdown-link-check \
215+
--quiet \
216+
--config "./.markdown-link-check.json" \
217+
"$file"
218+
STATUS=$(( $STATUS + $? ))
219+
done
220+
exit $STATUS
221+
else
222+
npx --package=markdown-link-check --call='
223+
STATUS=0
224+
for file in $(find . -regex ".*[.]md"); do
225+
markdown-link-check \
226+
--quiet \
227+
--config "./.markdown-link-check.json" \
228+
"$file"
229+
STATUS=$(( $STATUS + $? ))
230+
done
231+
exit $STATUS
232+
'
233+
fi
206234
207235
docs:check-formatting:
208236
desc: Check formatting of documentation files

0 commit comments

Comments
 (0)