node-web-mvc
Version:
node spring mvc
61 lines (60 loc) • 2.05 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const process_1 = __importDefault(require("process"));
const tracerSymbol = Symbol('tracer');
class Tracer {
constructor(error) {
if (error) {
const dependencies = error.stack.split('\n').slice(2, 10).map((m) => {
return m.split('(').pop().replace(/(:\d+)+/, '').replace(/\)$/, '');
});
this.id = dependencies[0];
}
}
static hasTracer(clazz) {
if (!clazz)
return false;
return !!clazz[tracerSymbol];
}
static setTracer(clazz, tracer) {
if (clazz) {
Object.defineProperty(clazz, tracerSymbol, {
configurable: true,
get() {
return tracer;
},
});
}
}
static getTracer(clazz) {
if (clazz) {
return clazz[tracerSymbol];
}
}
static getClassPath(id, suffix) {
const root = process_1.default.cwd();
const ext = path_1.default.extname(id);
const prefix = id.split(root).pop().replace(ext, '');
return suffix ? `${prefix}#${suffix}` : prefix;
}
static getFullName(clazz, suffix) {
var _a;
if (!clazz) {
return suffix;
}
const id = (_a = this.getTracer(clazz)) === null || _a === void 0 ? void 0 : _a.id;
return this.getClassPath(id || clazz.name, suffix).replace(/\//g, '.').replace(/^\./, '');
}
static isDependency(clazz, file) {
var _a, _b;
return ((_b = (_a = this.getTracer(clazz)) === null || _a === void 0 ? void 0 : _a.isDependency) === null || _b === void 0 ? void 0 : _b.call(_a, file)) === true;
}
isDependency(file) {
return this.id.indexOf(file) > -1;
}
}
exports.default = Tracer;