@nestjs/observe 0.1.0 → 0.1.1
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.
|
@@ -1,41 +1,20 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
|
-
import { dirname, resolve } from "node:path";
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
2
|
+
* `@jridgewell/trace-mapping` is imported statically rather than pulled in on
|
|
3
|
+
* first use through `createRequire(import.meta.url)`. The shim was valid only
|
|
4
|
+
* under ESM: consumers whose test runner transpiles this package down to
|
|
5
|
+
* CommonJS got `const require = ...` on top of the module-scope `require`,
|
|
6
|
+
* which is a redeclaration - the package failed to load at all under Jest.
|
|
7
|
+
* It is a hard dependency with no import-time side effects, so binding it
|
|
8
|
+
* eagerly costs one module parse and keeps this file loadable either way.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
import { originalPositionFor, sourceContentFor, TraceMap, } from "@jridgewell/trace-mapping";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import { dirname, resolve } from "node:path";
|
|
10
13
|
const SOURCE_MAPPING_URL_PATTERN = /\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/gm;
|
|
11
14
|
const INLINE_MAP_PREFIX = "data:application/json";
|
|
12
15
|
/** Parsed maps by compiled-file path; null marks "looked, found none". */
|
|
13
16
|
const mapCache = new Map();
|
|
14
|
-
let traceMappingModule = null;
|
|
15
|
-
let traceMappingLoadAttempted = false;
|
|
16
|
-
/**
|
|
17
|
-
* Loaded on first use rather than at import time, so a process that never enables
|
|
18
|
-
* source maps never pays for it - and a missing install degrades to raw frames
|
|
19
|
-
* instead of taking the app down.
|
|
20
|
-
*/
|
|
21
|
-
function loadTraceMapping() {
|
|
22
|
-
if (traceMappingLoadAttempted) {
|
|
23
|
-
return traceMappingModule;
|
|
24
|
-
}
|
|
25
|
-
traceMappingLoadAttempted = true;
|
|
26
|
-
try {
|
|
27
|
-
traceMappingModule = require("@jridgewell/trace-mapping");
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
traceMappingModule = null;
|
|
31
|
-
}
|
|
32
|
-
return traceMappingModule;
|
|
33
|
-
}
|
|
34
17
|
function readMapFor(file) {
|
|
35
|
-
const traceMapping = loadTraceMapping();
|
|
36
|
-
if (!traceMapping) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
18
|
let compiled;
|
|
40
19
|
try {
|
|
41
20
|
compiled = readFileSync(file, "utf8");
|
|
@@ -73,7 +52,7 @@ function readMapFor(file) {
|
|
|
73
52
|
}
|
|
74
53
|
try {
|
|
75
54
|
return {
|
|
76
|
-
tracer: new
|
|
55
|
+
tracer: new TraceMap(JSON.parse(rawMap)),
|
|
77
56
|
mapDir,
|
|
78
57
|
};
|
|
79
58
|
}
|
|
@@ -96,15 +75,11 @@ function getMap(file) {
|
|
|
96
75
|
* to the compiled file - a degraded but still truthful result.
|
|
97
76
|
*/
|
|
98
77
|
export function resolveOriginalPosition(file, line, column) {
|
|
99
|
-
const traceMapping = loadTraceMapping();
|
|
100
|
-
if (!traceMapping) {
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
78
|
const map = getMap(file);
|
|
104
79
|
if (!map) {
|
|
105
80
|
return undefined;
|
|
106
81
|
}
|
|
107
|
-
const position =
|
|
82
|
+
const position = originalPositionFor(map.tracer, {
|
|
108
83
|
line,
|
|
109
84
|
// Stack columns are 1-based, source map columns are 0-based.
|
|
110
85
|
column: Math.max(0, column - 1),
|
|
@@ -115,7 +90,7 @@ export function resolveOriginalPosition(file, line, column) {
|
|
|
115
90
|
// `sourcesContent` is the reliable path: the original text is embedded in the
|
|
116
91
|
// map, so it works even when the source tree is absent at runtime (a container
|
|
117
92
|
// shipping only dist, for instance).
|
|
118
|
-
const embedded =
|
|
93
|
+
const embedded = sourceContentFor(map.tracer, position.source);
|
|
119
94
|
return {
|
|
120
95
|
file: position.source.startsWith("/")
|
|
121
96
|
? position.source
|
package/package.json
CHANGED