@bluelibs/runner 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/define.js +6 -0
- package/dist/define.js.map +1 -1
- package/dist/defs.d.ts +2 -0
- package/dist/defs.js +3 -1
- package/dist/defs.js.map +1 -1
- package/dist/globalResources.js +5 -0
- package/dist/globalResources.js.map +1 -1
- package/dist/tools/getCallerFile.d.ts +1 -0
- package/dist/tools/getCallerFile.js +30 -0
- package/dist/tools/getCallerFile.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/index.ts +1 -0
- package/src/__tests__/tools/getCallerFile.test.ts +51 -0
- package/src/define.ts +7 -0
- package/src/defs.ts +3 -0
- package/src/globalResources.ts +6 -0
- package/src/tools/getCallerFile.ts +33 -0
package/dist/define.js
CHANGED
|
@@ -11,9 +11,12 @@ exports.isEvent = isEvent;
|
|
|
11
11
|
exports.isMiddleware = isMiddleware;
|
|
12
12
|
const defs_1 = require("./defs");
|
|
13
13
|
const errors_1 = require("./errors");
|
|
14
|
+
const getCallerFile_1 = require("./tools/getCallerFile");
|
|
15
|
+
// Helper function to get the caller file
|
|
14
16
|
function defineTask(taskConfig) {
|
|
15
17
|
return {
|
|
16
18
|
[defs_1.symbols.task]: true,
|
|
19
|
+
[defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
|
|
17
20
|
id: taskConfig.id,
|
|
18
21
|
dependencies: taskConfig.dependencies || {},
|
|
19
22
|
middleware: taskConfig.middleware || [],
|
|
@@ -37,6 +40,7 @@ function defineTask(taskConfig) {
|
|
|
37
40
|
function defineResource(constConfig) {
|
|
38
41
|
return {
|
|
39
42
|
[defs_1.symbols.resource]: true,
|
|
43
|
+
[defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
|
|
40
44
|
id: constConfig.id,
|
|
41
45
|
dependencies: constConfig.dependencies,
|
|
42
46
|
dispose: constConfig.dispose,
|
|
@@ -68,12 +72,14 @@ function defineResource(constConfig) {
|
|
|
68
72
|
}
|
|
69
73
|
function defineEvent(config) {
|
|
70
74
|
return {
|
|
75
|
+
[defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
|
|
71
76
|
[defs_1.symbolEvent]: true,
|
|
72
77
|
...config,
|
|
73
78
|
};
|
|
74
79
|
}
|
|
75
80
|
function defineMiddleware(config) {
|
|
76
81
|
const object = {
|
|
82
|
+
[defs_1.symbols.filePath]: (0, getCallerFile_1.getCallerFile)(),
|
|
77
83
|
[defs_1.symbols.middleware]: true,
|
|
78
84
|
...config,
|
|
79
85
|
dependencies: config.dependencies || {},
|
package/dist/define.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":";;AAsBA,gCA8BC;AAED,wCAwCC;AAED,kCAQC;AAED,4CAsBC;AAED,wBAEC;AAED,gCAEC;AAED,oDAIC;AAED,0BAEC;AAED,oCAEC;AAtJD,iCAgBgB;AAChB,qCAAkC;AAClC,yDAAsD;AAEtD,yCAAyC;AAEzC,SAAgB,UAAU,CAMxB,UAAqD;IAErD,OAAO;QACL,CAAC,cAAO,CAAC,IAAI,CAAC,EAAE,IAAI;QACpB,CAAC,cAAO,CAAC,QAAQ,CAAC,EAAE,IAAA,6BAAa,GAAE;QACnC,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,YAAY,EAAE,UAAU,CAAC,YAAY,IAAK,EAAW;QACrD,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,EAAE;QACvC,GAAG,EAAE,UAAU,CAAC,GAAG;QACnB,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,MAAM,EAAE;YACN,SAAS,EAAE,WAAW,CAAC;gBACrB,EAAE,EAAE,GAAG,UAAU,CAAC,EAAE,YAAY;aACjC,CAAC;YACF,QA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CAAC,cAAO,CAAC,UAAU,CAAC,CAAC;AACtD,CAAC"}
|
package/dist/defs.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const symbolResourceWithConfig: unique symbol;
|
|
|
4
4
|
export declare const symbolEvent: unique symbol;
|
|
5
5
|
export declare const symbolMiddleware: unique symbol;
|
|
6
6
|
export declare const symbolMiddlewareGlobal: unique symbol;
|
|
7
|
+
export declare const symbolFilePath: unique symbol;
|
|
7
8
|
export declare const symbols: {
|
|
8
9
|
task: symbol;
|
|
9
10
|
resource: symbol;
|
|
@@ -11,6 +12,7 @@ export declare const symbols: {
|
|
|
11
12
|
event: symbol;
|
|
12
13
|
middleware: symbol;
|
|
13
14
|
middlewareGlobal: symbol;
|
|
15
|
+
filePath: symbol;
|
|
14
16
|
};
|
|
15
17
|
export interface IMeta {
|
|
16
18
|
title?: string;
|
package/dist/defs.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.symbols = exports.symbolMiddlewareGlobal = exports.symbolMiddleware = exports.symbolEvent = exports.symbolResourceWithConfig = exports.symbolResource = exports.symbolTask = void 0;
|
|
3
|
+
exports.symbols = exports.symbolFilePath = exports.symbolMiddlewareGlobal = exports.symbolMiddleware = exports.symbolEvent = exports.symbolResourceWithConfig = exports.symbolResource = exports.symbolTask = void 0;
|
|
4
4
|
exports.symbolTask = Symbol("runner.task");
|
|
5
5
|
exports.symbolResource = Symbol("runner.resource");
|
|
6
6
|
exports.symbolResourceWithConfig = Symbol("runner.resourceWithConfig");
|
|
7
7
|
exports.symbolEvent = Symbol("runner.event");
|
|
8
8
|
exports.symbolMiddleware = Symbol("runner.middleware");
|
|
9
9
|
exports.symbolMiddlewareGlobal = Symbol("runner.middlewareGlobal");
|
|
10
|
+
exports.symbolFilePath = Symbol("runner.filePath");
|
|
10
11
|
exports.symbols = {
|
|
11
12
|
task: exports.symbolTask,
|
|
12
13
|
resource: exports.symbolResource,
|
|
@@ -14,5 +15,6 @@ exports.symbols = {
|
|
|
14
15
|
event: exports.symbolEvent,
|
|
15
16
|
middleware: exports.symbolMiddleware,
|
|
16
17
|
middlewareGlobal: exports.symbolMiddlewareGlobal,
|
|
18
|
+
filePath: exports.symbolFilePath,
|
|
17
19
|
};
|
|
18
20
|
//# sourceMappingURL=defs.js.map
|
package/dist/defs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.js","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAkB,MAAM,CAAC,aAAa,CAAC,CAAC;AAClD,QAAA,cAAc,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC1D,QAAA,wBAAwB,GAAkB,MAAM,CAC3D,2BAA2B,CAC5B,CAAC;AACW,QAAA,WAAW,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AACpD,QAAA,gBAAgB,GAAkB,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC9D,QAAA,sBAAsB,GAAkB,MAAM,CACzD,yBAAyB,CAC1B,CAAC;AAEW,QAAA,OAAO,GAAG;IACrB,IAAI,EAAE,kBAAU;IAChB,QAAQ,EAAE,sBAAc;IACxB,kBAAkB,EAAE,gCAAwB;IAC5C,KAAK,EAAE,mBAAW;IAClB,UAAU,EAAE,wBAAgB;IAC5B,gBAAgB,EAAE,8BAAsB;
|
|
1
|
+
{"version":3,"file":"defs.js","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAkB,MAAM,CAAC,aAAa,CAAC,CAAC;AAClD,QAAA,cAAc,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC1D,QAAA,wBAAwB,GAAkB,MAAM,CAC3D,2BAA2B,CAC5B,CAAC;AACW,QAAA,WAAW,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AACpD,QAAA,gBAAgB,GAAkB,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC9D,QAAA,sBAAsB,GAAkB,MAAM,CACzD,yBAAyB,CAC1B,CAAC;AAEW,QAAA,cAAc,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAE1D,QAAA,OAAO,GAAG;IACrB,IAAI,EAAE,kBAAU;IAChB,QAAQ,EAAE,sBAAc;IACxB,kBAAkB,EAAE,gCAAwB;IAC5C,KAAK,EAAE,mBAAW;IAClB,UAAU,EAAE,wBAAgB;IAC5B,gBAAgB,EAAE,8BAAsB;IACxC,QAAQ,EAAE,sBAAc;CACzB,CAAC"}
|
package/dist/globalResources.js
CHANGED
|
@@ -5,6 +5,11 @@ const define_1 = require("./define");
|
|
|
5
5
|
const store = (0, define_1.defineResource)({
|
|
6
6
|
id: "global.store",
|
|
7
7
|
init: async (store) => store,
|
|
8
|
+
meta: {
|
|
9
|
+
title: "Store",
|
|
10
|
+
description: "A global store that can be used to store and retrieve tasks, resources, events and middleware",
|
|
11
|
+
tags: ["internal"],
|
|
12
|
+
},
|
|
8
13
|
});
|
|
9
14
|
exports.globalResources = {
|
|
10
15
|
store,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalResources.js","sourceRoot":"","sources":["../src/globalResources.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAM1C,MAAM,KAAK,GAAG,IAAA,uBAAc,EAAC;IAC3B,EAAE,EAAE,cAAc;IAClB,IAAI,EAAE,KAAK,EAAE,KAAY,EAAE,EAAE,CAAC,KAAK;
|
|
1
|
+
{"version":3,"file":"globalResources.js","sourceRoot":"","sources":["../src/globalResources.ts"],"names":[],"mappings":";;;AAAA,qCAA0C;AAM1C,MAAM,KAAK,GAAG,IAAA,uBAAc,EAAC;IAC3B,EAAE,EAAE,cAAc;IAClB,IAAI,EAAE,KAAK,EAAE,KAAY,EAAE,EAAE,CAAC,KAAK;IACnC,IAAI,EAAE;QACJ,KAAK,EAAE,OAAO;QACd,WAAW,EACT,+FAA+F;QACjG,IAAI,EAAE,CAAC,UAAU,CAAC;KACnB;CACF,CAAC,CAAC;AAEU,QAAA,eAAe,GAAG;IAC7B,KAAK;IACL,YAAY,EAAE,IAAA,uBAAc,EAAC;QAC3B,EAAE,EAAE,qBAAqB;QACzB,IAAI,EAAE,KAAK,EAAE,EAAgB,EAAE,EAAE,CAAC,EAAE;QACpC,IAAI,EAAE;YACJ,KAAK,EAAE,eAAe;YACtB,WAAW,EACT,iGAAiG;YACnG,IAAI,EAAE,CAAC,UAAU,CAAC;SACnB;KACF,CAAC;IACF,UAAU,EAAE,IAAA,uBAAc,EAAC;QACzB,EAAE,EAAE,mBAAmB;QACvB,IAAI,EAAE,KAAK,EAAE,MAAkB,EAAE,EAAE,CAAC,MAAM;QAC1C,IAAI,EAAE;YACJ,KAAK,EAAE,aAAa;YACpB,WAAW,EACT,+GAA+G;YACjH,IAAI,EAAE,CAAC,UAAU,CAAC;SACnB;KACF,CAAC;IACF,MAAM,EAAE,IAAA,uBAAc,EAAC;QACrB,EAAE,EAAE,eAAe;QACnB,IAAI,EAAE,KAAK,EAAE,MAAc,EAAE,EAAE,CAAC,MAAM;QACtC,IAAI,EAAE;YACJ,KAAK,EAAE,QAAQ;YACf,WAAW,EACT,4HAA4H;SAC/H;KACF,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCallerFile(): string | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCallerFile = getCallerFile;
|
|
4
|
+
function getCallerFile() {
|
|
5
|
+
const originalFunc = Error.prepareStackTrace;
|
|
6
|
+
try {
|
|
7
|
+
const err = new Error();
|
|
8
|
+
let callerfile;
|
|
9
|
+
let currentfile;
|
|
10
|
+
// Safeguard prepareStackTrace
|
|
11
|
+
Error.prepareStackTrace = (err, stack) => stack;
|
|
12
|
+
const stack = err.stack;
|
|
13
|
+
// Don't know how to test this.
|
|
14
|
+
// if (stack.length < 3) {
|
|
15
|
+
// // We need at least 3 frames: current function, its caller, and one above
|
|
16
|
+
// return undefined;
|
|
17
|
+
// }
|
|
18
|
+
// Remove the first frame (getCallerFile itself)
|
|
19
|
+
stack.shift();
|
|
20
|
+
// Remove the second frame (the direct caller of getCallerFile)
|
|
21
|
+
currentfile = stack.shift()?.getFileName();
|
|
22
|
+
// The third frame (the caller above the immediate one)
|
|
23
|
+
callerfile = stack.shift()?.getFileName();
|
|
24
|
+
return callerfile; // Return the file name of the caller above
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
Error.prepareStackTrace = originalFunc;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=getCallerFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCallerFile.js","sourceRoot":"","sources":["../../src/tools/getCallerFile.ts"],"names":[],"mappings":";;AAAA,sCAgCC;AAhCD,SAAgB,aAAa;IAC3B,MAAM,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC;IAE7C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,UAAU,CAAC;QACf,IAAI,WAAW,CAAC;QAEhB,8BAA8B;QAC9B,KAAK,CAAC,iBAAiB,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;QAEhD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAqC,CAAC;QAExD,+BAA+B;QAC/B,0BAA0B;QAC1B,8EAA8E;QAC9E,sBAAsB;QACtB,IAAI;QAEJ,gDAAgD;QAChD,KAAK,CAAC,KAAK,EAAE,CAAC;QAEd,+DAA+D;QAC/D,WAAW,GAAG,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC;QAE3C,uDAAuD;QACvD,UAAU,GAAG,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,CAAC;QAE1C,OAAO,UAAU,CAAC,CAAC,2CAA2C;IAChE,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,iBAAiB,GAAG,YAAY,CAAC;IACzC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
package/src/__tests__/index.ts
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineTask,
|
|
3
|
+
defineResource,
|
|
4
|
+
defineMiddleware,
|
|
5
|
+
defineEvent,
|
|
6
|
+
} from "../../define";
|
|
7
|
+
import { symbols } from "../../defs";
|
|
8
|
+
import { getCallerFile } from "../../tools/getCallerFile";
|
|
9
|
+
|
|
10
|
+
describe("getCallerFile", () => {
|
|
11
|
+
it("should return the file name of the caller", () => {
|
|
12
|
+
function testFunction() {
|
|
13
|
+
return getCallerFile();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const callerFile = testFunction();
|
|
17
|
+
|
|
18
|
+
expect(callerFile).toBeDefined();
|
|
19
|
+
expect(callerFile).toContain("getCallerFile.test"); // we don't use .ts because for coverage it gets compiled to js
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("Should work with tasks, resources, middleware and events", () => {
|
|
23
|
+
const task = defineTask({
|
|
24
|
+
id: "task",
|
|
25
|
+
run: async () => {},
|
|
26
|
+
});
|
|
27
|
+
const resource = defineResource({
|
|
28
|
+
id: "resource",
|
|
29
|
+
init: async () => {},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const middleware = defineMiddleware({
|
|
33
|
+
id: "middleware",
|
|
34
|
+
run: async () => {},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const event = defineEvent({
|
|
38
|
+
id: "event",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(task[symbols.filePath]).toBeDefined();
|
|
42
|
+
expect(resource[symbols.filePath]).toBeDefined();
|
|
43
|
+
expect(middleware[symbols.filePath]).toBeDefined();
|
|
44
|
+
expect(event[symbols.filePath]).toBeDefined();
|
|
45
|
+
|
|
46
|
+
expect(task[symbols.filePath]).toContain("getCallerFile.test");
|
|
47
|
+
expect(resource[symbols.filePath]).toContain("getCallerFile.test");
|
|
48
|
+
expect(middleware[symbols.filePath]).toContain("getCallerFile.test");
|
|
49
|
+
expect(event[symbols.filePath]).toContain("getCallerFile.test");
|
|
50
|
+
});
|
|
51
|
+
});
|
package/src/define.ts
CHANGED
|
@@ -16,6 +16,9 @@ import {
|
|
|
16
16
|
symbolEvent,
|
|
17
17
|
} from "./defs";
|
|
18
18
|
import { Errors } from "./errors";
|
|
19
|
+
import { getCallerFile } from "./tools/getCallerFile";
|
|
20
|
+
|
|
21
|
+
// Helper function to get the caller file
|
|
19
22
|
|
|
20
23
|
export function defineTask<
|
|
21
24
|
Input = undefined,
|
|
@@ -27,6 +30,7 @@ export function defineTask<
|
|
|
27
30
|
): ITask<Input, Output, Deps, TOn> {
|
|
28
31
|
return {
|
|
29
32
|
[symbols.task]: true,
|
|
33
|
+
[symbols.filePath]: getCallerFile(),
|
|
30
34
|
id: taskConfig.id,
|
|
31
35
|
dependencies: taskConfig.dependencies || ({} as Deps),
|
|
32
36
|
middleware: taskConfig.middleware || [],
|
|
@@ -58,6 +62,7 @@ export function defineResource<
|
|
|
58
62
|
): IResource<TConfig, TValue, TDeps> {
|
|
59
63
|
return {
|
|
60
64
|
[symbols.resource]: true,
|
|
65
|
+
[symbols.filePath]: getCallerFile(),
|
|
61
66
|
id: constConfig.id,
|
|
62
67
|
dependencies: constConfig.dependencies,
|
|
63
68
|
dispose: constConfig.dispose,
|
|
@@ -93,6 +98,7 @@ export function defineEvent<TPayload = any>(
|
|
|
93
98
|
config: IEventDefinitionConfig<TPayload>
|
|
94
99
|
): IEventDefinition<TPayload> {
|
|
95
100
|
return {
|
|
101
|
+
[symbols.filePath]: getCallerFile(),
|
|
96
102
|
[symbolEvent]: true,
|
|
97
103
|
...config,
|
|
98
104
|
};
|
|
@@ -102,6 +108,7 @@ export function defineMiddleware<TDeps extends DependencyMapType = {}>(
|
|
|
102
108
|
config: IMiddlewareDefinition<TDeps>
|
|
103
109
|
): IMiddleware<TDeps> {
|
|
104
110
|
const object = {
|
|
111
|
+
[symbols.filePath]: getCallerFile(),
|
|
105
112
|
[symbols.middleware]: true,
|
|
106
113
|
...config,
|
|
107
114
|
dependencies: config.dependencies || ({} as TDeps),
|
package/src/defs.ts
CHANGED
|
@@ -9,6 +9,8 @@ export const symbolMiddlewareGlobal: unique symbol = Symbol(
|
|
|
9
9
|
"runner.middlewareGlobal"
|
|
10
10
|
);
|
|
11
11
|
|
|
12
|
+
export const symbolFilePath: unique symbol = Symbol("runner.filePath");
|
|
13
|
+
|
|
12
14
|
export const symbols = {
|
|
13
15
|
task: symbolTask,
|
|
14
16
|
resource: symbolResource,
|
|
@@ -16,6 +18,7 @@ export const symbols = {
|
|
|
16
18
|
event: symbolEvent,
|
|
17
19
|
middleware: symbolMiddleware,
|
|
18
20
|
middlewareGlobal: symbolMiddlewareGlobal,
|
|
21
|
+
filePath: symbolFilePath,
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export interface IMeta {
|
package/src/globalResources.ts
CHANGED
|
@@ -7,6 +7,12 @@ import { TaskRunner } from "./models/TaskRunner";
|
|
|
7
7
|
const store = defineResource({
|
|
8
8
|
id: "global.store",
|
|
9
9
|
init: async (store: Store) => store,
|
|
10
|
+
meta: {
|
|
11
|
+
title: "Store",
|
|
12
|
+
description:
|
|
13
|
+
"A global store that can be used to store and retrieve tasks, resources, events and middleware",
|
|
14
|
+
tags: ["internal"],
|
|
15
|
+
},
|
|
10
16
|
});
|
|
11
17
|
|
|
12
18
|
export const globalResources = {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function getCallerFile(): string | undefined {
|
|
2
|
+
const originalFunc = Error.prepareStackTrace;
|
|
3
|
+
|
|
4
|
+
try {
|
|
5
|
+
const err = new Error();
|
|
6
|
+
let callerfile;
|
|
7
|
+
let currentfile;
|
|
8
|
+
|
|
9
|
+
// Safeguard prepareStackTrace
|
|
10
|
+
Error.prepareStackTrace = (err, stack) => stack;
|
|
11
|
+
|
|
12
|
+
const stack = err.stack as unknown as NodeJS.CallSite[];
|
|
13
|
+
|
|
14
|
+
// Don't know how to test this.
|
|
15
|
+
// if (stack.length < 3) {
|
|
16
|
+
// // We need at least 3 frames: current function, its caller, and one above
|
|
17
|
+
// return undefined;
|
|
18
|
+
// }
|
|
19
|
+
|
|
20
|
+
// Remove the first frame (getCallerFile itself)
|
|
21
|
+
stack.shift();
|
|
22
|
+
|
|
23
|
+
// Remove the second frame (the direct caller of getCallerFile)
|
|
24
|
+
currentfile = stack.shift()?.getFileName();
|
|
25
|
+
|
|
26
|
+
// The third frame (the caller above the immediate one)
|
|
27
|
+
callerfile = stack.shift()?.getFileName();
|
|
28
|
+
|
|
29
|
+
return callerfile; // Return the file name of the caller above
|
|
30
|
+
} finally {
|
|
31
|
+
Error.prepareStackTrace = originalFunc;
|
|
32
|
+
}
|
|
33
|
+
}
|