test.js 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import fs from 'fs'
  2. import path, { dirname } from 'path'
  3. import assert from 'assert'
  4. import { spawn } from 'child_process'
  5. import syntaxError from 'syntax-error'
  6. import { fileURLToPath } from 'url'
  7. import { createRequire } from 'module'
  8. const __filename = fileURLToPath(import.meta.url)
  9. const __dirname = dirname(__filename)
  10. const require = createRequire(__dirname)
  11. let folders = ['.', ...Object.keys(require(path.join(__dirname, './package.json')).directories)]
  12. let files = []
  13. for (let folder of folders)
  14. for (let file of fs.readdirSync(folder).filter(v => v.endsWith('.js')))
  15. files.push(path.resolve(path.join(folder, file)))
  16. for (let file of files) {
  17. if (file == __filename) continue
  18. console.error('Checking', file)
  19. const error = syntaxError(fs.readFileSync(file, 'utf8'), file, {
  20. sourceType: 'module',
  21. allowReturnOutsideFunction: true,
  22. allowAwaitOutsideFunction: true
  23. })
  24. if (error) assert.ok(error.length < 1, file + '\n\n' + error)
  25. assert.ok(file)
  26. console.log('Done', file)
  27. }