|
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' |
| 1 | +import fs from 'fs'; |
| 2 | +import path, { dirname } from 'path'; |
| 3 | +import assert from 'assert'; |
| 4 | +import syntaxError from 'syntax-error'; |
| 5 | +import { fileURLToPath } from 'url'; |
| 6 | +import { createRequire } from 'module'; |
8 | 7 |
|
9 | | -const __filename = fileURLToPath(import.meta.url) |
10 | | -const __dirname = dirname(__filename) |
11 | | -const require = createRequire(__dirname) |
| 8 | +const __filename = fileURLToPath(import.meta.url); |
| 9 | +const __dirname = dirname(__filename); |
| 10 | +const require = createRequire(__dirname); |
| 11 | + |
| 12 | +let folders = ['.', ...Object.keys(require(path.join(__dirname, './package.json')).directories)]; |
| 13 | +let files = []; |
| 14 | + |
| 15 | +for (let folder of folders) { |
| 16 | + try { |
| 17 | + for (let file of fs.readdirSync(folder).filter(v => v.endsWith('.js'))) { |
| 18 | + files.push(path.resolve(path.join(folder, file))); |
| 19 | + } |
| 20 | + } catch (err) { |
| 21 | + console.error(`Error reading folder ${folder}:`, err); |
| 22 | + } |
| 23 | +} |
12 | 24 |
|
13 | | -let folders = ['.', ...Object.keys(require(path.join(__dirname, './package.json')).directories)] |
14 | | -let files = [] |
15 | | -for (let folder of folders) |
16 | | - for (let file of fs.readdirSync(folder).filter(v => v.endsWith('.js'))) |
17 | | - files.push(path.resolve(path.join(folder, file))) |
18 | 25 | for (let file of files) { |
19 | | - if (file == __filename) continue |
20 | | - console.error('Checking', file) |
| 26 | + if (file == __filename) continue; |
| 27 | + console.error('Checking', file); |
| 28 | + |
21 | 29 | const error = syntaxError(fs.readFileSync(file, 'utf8'), file, { |
22 | 30 | sourceType: 'module', |
23 | 31 | allowReturnOutsideFunction: true, |
24 | 32 | allowAwaitOutsideFunction: true |
25 | | - }) |
26 | | - if (error) assert.ok(error.length < 1, file + '\n\n' + error) |
27 | | - assert.ok(file) |
28 | | - console.log('Done ☑️', file) |
| 33 | + }); |
| 34 | + |
| 35 | + assert.ifError(error); |
| 36 | + console.log('Done ☑️', file); |
29 | 37 | } |
0 commit comments