UNPKG

1 kBPlain TextView Raw
1import {Promise} from 'bluebird';
2// 支持注解
3import 'reflect-metadata';
4
5/**
6 * 替换全局Promise
7 * 自动解析sourcemap
8 * 捕获全局错误
9 */
10export function preload() {
11 // 使用bluebird输出完整的promise调用链
12 global.Promise = Promise;
13 // 开启长堆栈
14 Promise.config({
15 // Enable warnings
16 warnings: true,
17 // Enable long stack traces
18 longStackTraces: true,
19 // Enable cancellation
20 cancellation: true,
21 // Enable monitoring
22 monitoring: true
23 });
24
25 // 自动解析ts的sourcemap
26 require('source-map-support').install({
27 handleUncaughtExceptions: false
28 });
29
30 // 捕获普通异常
31 process.on('uncaughtException', function (err) {
32 console.error('Caught exception: ' + err.stack);
33 });
34
35 // 捕获async异常
36 process.on('unhandledRejection', (reason, p) => {
37 console.error('Caught Unhandled Rejection at:' + p + 'reason:' + reason.stack);
38 });
39}
\No newline at end of file