vnu-jar.mjs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env node
  2. /*!
  3. * Script to run vnu-jar if Java is available.
  4. * Copyright 2017-2025 The Bootstrap Authors
  5. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  6. */
  7. import { execFile, spawn } from 'node:child_process'
  8. import vnu from 'vnu-jar'
  9. execFile('java', ['-version'], (error, stdout, stderr) => {
  10. if (error) {
  11. console.error('Skipping vnu-jar test; Java is probably missing.')
  12. console.error(error)
  13. return
  14. }
  15. console.log('Running vnu-jar validation...')
  16. const is32bitJava = !/64-Bit/.test(stderr)
  17. // vnu-jar accepts multiple ignores joined with a `|`.
  18. // Also note that the ignores are string regular expressions.
  19. const ignores = [
  20. // "autocomplete" is included in <button> and checkboxes and radio <input>s due to
  21. // Firefox's non-standard autocomplete behavior - see https://bugzilla.mozilla.org/show_bug.cgi?id=654072
  22. 'Attribute “autocomplete” is only allowed when the input type is.*',
  23. 'Attribute “autocomplete” not allowed on element “button” at this point.',
  24. // Per https://www.w3.org/TR/html-aria/#docconformance having "aria-disabled" on a link is
  25. // NOT RECOMMENDED, but it's still valid - we explain in the docs that it's not ideal,
  26. // and offer more robust alternatives, but also need to show a less-than-ideal example
  27. 'An “aria-disabled” attribute whose value is “true” should not be specified on an “a” element that has an “href” attribute.',
  28. // A `code` element with the `is:raw` attribute coming from remark-prismjs (Astro upstream possible bug)
  29. 'Attribute “is:raw” is not serializable as XML 1.0.',
  30. 'Attribute “is:raw” not allowed on element “code” at this point.',
  31. // Astro's expecting trailing slashes on HTML tags such as <br />
  32. 'Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.',
  33. // Allow `switch` attribute.
  34. 'Attribute “switch” not allowed on element “input” at this point.'
  35. ].join('|')
  36. const args = [
  37. '-jar',
  38. `"${vnu}"`,
  39. '--asciiquotes',
  40. '--skip-non-html',
  41. '--Werror',
  42. `--filterpattern "${ignores}"`,
  43. '_site/',
  44. 'js/tests/'
  45. ]
  46. // For the 32-bit Java we need to pass `-Xss512k`
  47. if (is32bitJava) {
  48. args.splice(0, 0, '-Xss512k')
  49. }
  50. console.log(`command used: java ${args.join(' ')}`)
  51. return spawn('java', args, {
  52. shell: true,
  53. stdio: 'inherit'
  54. })
  55. .on('exit', process.exit)
  56. })