forked from n1ru4l/envelop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-esm.mjs
51 lines (45 loc) · 1.3 KB
/
test-esm.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import globby from 'globby';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
process.env.NEW_RELIC_APP_NAME = 'TEST';
async function main() {
const mjsFiles = await globby(['../packages/*/dist/*.mjs', '../packages/plugins/*/dist/*.mjs'], {
cwd: dirname(fileURLToPath(import.meta.url)),
});
const ok = [];
const fail = [];
let i = 0;
await Promise.all(
mjsFiles.map(mjsFile => {
const mjsPath = `./${mjsFile}`;
return import(mjsPath)
.then(() => {
ok.push(mjsPath);
})
.catch(err => {
const color = i++ % 2 === 0 ? chalk.magenta : chalk.red;
console.error(color('\n\n-----\n' + i + '\n'));
console.error(mjsPath, err);
console.error(color('\n-----\n\n'));
fail.push(mjsPath);
});
})
);
ok.length && console.log(chalk.blue(`${ok.length} OK: ${ok.join(' | ')}`));
fail.length && console.error(chalk.red(`${fail.length} Fail: ${fail.join(' | ')}`));
if (fail.length) {
console.error('\nFAILED');
process.exit(1);
} else if (ok.length) {
console.error('\nOK');
process.exit(0);
} else {
console.error('No files analyzed!');
process.exit(1);
}
}
main().catch(err => {
console.error(err);
process.exit(1);
});