posthog-node 5.47.6 → 5.47.8

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 +1 @@
1
- {"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../../src/entrypoints/index.node.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAM1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D,qBAAa,OAAQ,SAAQ,oBAAoB;IAC/C,YAAY,IAAI,MAAM;IAItB,SAAS,CAAC,iBAAiB,IAAI,cAAc;cAI1B,4BAA4B,IAAI,iBAAiB,CAAC,sBAAsB;CAa5F"}
1
+ {"version":3,"file":"index.node.d.ts","sourceRoot":"","sources":["../../src/entrypoints/index.node.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAM1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAChD,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAE9D,qBAAa,OAAQ,SAAQ,oBAAoB;IAC/C,YAAY,IAAI,MAAM;IAItB,SAAS,CAAC,iBAAiB,IAAI,cAAc;cAI1B,4BAA4B,IAAI,iBAAiB,CAAC,sBAAsB;CAiB5F"}
@@ -99,7 +99,7 @@ var __webpack_exports__ = {};
99
99
  new _posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.PrimitiveCoercer()
100
100
  ], _posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.createStackParser("node:javascript", _posthog_core__WEBPACK_IMPORTED_MODULE_5__.ErrorTracking.nodeStackLineParser), [
101
101
  (0, _extensions_error_tracking_modifiers_module_node__WEBPACK_IMPORTED_MODULE_1__.createModulerModifier)(),
102
- _extensions_error_tracking_modifiers_context_lines_node__WEBPACK_IMPORTED_MODULE_2__.addSourceContext,
102
+ (frames)=>(0, _extensions_error_tracking_modifiers_context_lines_node__WEBPACK_IMPORTED_MODULE_2__.addSourceContext)(frames, void 0, this._logger),
103
103
  (0, _extensions_error_tracking_modifiers_relative_path_node__WEBPACK_IMPORTED_MODULE_3__.createRelativePathModifier)()
104
104
  ]);
105
105
  }
@@ -21,7 +21,7 @@ class PostHog extends PostHogBackendClient {
21
21
  new ErrorTracking.PrimitiveCoercer()
22
22
  ], ErrorTracking.createStackParser("node:javascript", ErrorTracking.nodeStackLineParser), [
23
23
  createModulerModifier(),
24
- addSourceContext,
24
+ (frames)=>addSourceContext(frames, void 0, this._logger),
25
25
  createRelativePathModifier()
26
26
  ]);
27
27
  }
@@ -1,5 +1,9 @@
1
- import { ErrorTracking as CoreErrorTracking } from '@posthog/core';
1
+ import { ErrorTracking as CoreErrorTracking, type Logger } from '@posthog/core';
2
+ import { type FileHandle } from 'node:fs/promises';
2
3
  export declare const MAX_CONTEXTLINES_COLNO: number;
3
4
  export declare const MAX_CONTEXTLINES_LINENO: number;
4
- export declare function addSourceContext(frames: CoreErrorTracking.StackFrame[]): Promise<CoreErrorTracking.StackFrame[]>;
5
+ export declare const MAX_CONTEXTLINES_FILE_SIZE: number;
6
+ type OpenSourceFile = (path: string, flags: number) => Promise<FileHandle>;
7
+ export declare function addSourceContext(frames: CoreErrorTracking.StackFrame[], openSourceFile?: OpenSourceFile, logger?: Pick<Logger, 'debug'>): Promise<CoreErrorTracking.StackFrame[]>;
8
+ export {};
5
9
  //# sourceMappingURL=context-lines.node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context-lines.node.d.ts","sourceRoot":"","sources":["../../../../src/extensions/error-tracking/modifiers/context-lines.node.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAUlE,eAAO,MAAM,sBAAsB,EAAE,MAAa,CAAA;AAClD,eAAO,MAAM,uBAAuB,EAAE,MAAc,CAAA;AAIpD,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,iBAAiB,CAAC,UAAU,EAAE,GACrC,OAAO,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC,CAuEzC"}
1
+ {"version":3,"file":"context-lines.node.d.ts","sourceRoot":"","sources":["../../../../src/extensions/error-tracking/modifiers/context-lines.node.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAE/E,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAUxD,eAAO,MAAM,sBAAsB,EAAE,MAAa,CAAA;AAClD,eAAO,MAAM,uBAAuB,EAAE,MAAc,CAAA;AACpD,eAAO,MAAM,0BAA0B,EAAE,MAAyB,CAAA;AAGlE,KAAK,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;AAE1E,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,iBAAiB,CAAC,UAAU,EAAE,EACtC,cAAc,GAAE,cAAqB,EACrC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC,CAqFzC"}
@@ -24,24 +24,33 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- MAX_CONTEXTLINES_LINENO: ()=>MAX_CONTEXTLINES_LINENO,
27
+ MAX_CONTEXTLINES_FILE_SIZE: ()=>MAX_CONTEXTLINES_FILE_SIZE,
28
28
  MAX_CONTEXTLINES_COLNO: ()=>MAX_CONTEXTLINES_COLNO,
29
- addSourceContext: ()=>addSourceContext
29
+ addSourceContext: ()=>addSourceContext,
30
+ MAX_CONTEXTLINES_LINENO: ()=>MAX_CONTEXTLINES_LINENO
30
31
  });
31
32
  const core_namespaceObject = require("@posthog/core");
32
33
  const external_node_fs_namespaceObject = require("node:fs");
34
+ const promises_namespaceObject = require("node:fs/promises");
35
+ const external_node_path_namespaceObject = require("node:path");
33
36
  const external_node_readline_namespaceObject = require("node:readline");
34
37
  const LRU_FILE_CONTENTS_CACHE = new core_namespaceObject.ErrorTracking.ReduceableCache(25);
35
38
  const LRU_FILE_CONTENTS_FS_READ_FAILED = new core_namespaceObject.ErrorTracking.ReduceableCache(20);
36
39
  const DEFAULT_LINES_OF_CONTEXT = 7;
37
40
  const MAX_CONTEXTLINES_COLNO = 1000;
38
41
  const MAX_CONTEXTLINES_LINENO = 10000;
39
- async function addSourceContext(frames) {
42
+ const MAX_CONTEXTLINES_FILE_SIZE = 10485760;
43
+ async function addSourceContext(frames, openSourceFile = promises_namespaceObject.open, logger) {
40
44
  const filesToLines = {};
45
+ let basePath;
46
+ try {
47
+ basePath = process.cwd();
48
+ } catch {}
41
49
  for(let i = frames.length - 1; i >= 0; i--){
42
50
  const frame = frames[i];
43
51
  const filename = frame?.filename;
44
52
  if (!frame || 'string' != typeof filename || 'number' != typeof frame.lineno || shouldSkipContextLinesForFile(filename) || shouldSkipContextLinesForFrame(frame)) continue;
53
+ if (!(0, external_node_path_namespaceObject.isAbsolute)(filename) && void 0 === basePath) continue;
45
54
  const filesToLinesOutput = filesToLines[filename];
46
55
  if (!filesToLinesOutput) filesToLines[filename] = [];
47
56
  filesToLines[filename].push(frame.lineno);
@@ -50,45 +59,87 @@ async function addSourceContext(frames) {
50
59
  if (0 == files.length) return frames;
51
60
  const readlinePromises = [];
52
61
  for (const file of files){
53
- if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(file)) continue;
62
+ const cacheKey = makeSourceCacheKey(file, basePath);
63
+ if (void 0 === cacheKey) continue;
64
+ if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(cacheKey)) continue;
54
65
  const filesToLineRanges = filesToLines[file];
55
66
  if (!filesToLineRanges) continue;
56
67
  filesToLineRanges.sort((a, b)=>a - b);
57
68
  const ranges = makeLineReaderRanges(filesToLineRanges);
58
- if (ranges.every((r)=>rangeExistsInContentCache(file, r))) continue;
59
- const cache = emplace(LRU_FILE_CONTENTS_CACHE, file, {});
60
- readlinePromises.push(getContextLinesFromFile(file, ranges, cache));
69
+ if (ranges.every((r)=>rangeExistsInContentCache(cacheKey, r))) continue;
70
+ const cache = emplace(LRU_FILE_CONTENTS_CACHE, cacheKey, {});
71
+ readlinePromises.push(getContextLinesFromFile(file, ranges, cache, cacheKey, openSourceFile, logger));
61
72
  }
62
73
  await Promise.all(readlinePromises).catch(()=>{});
63
- if (frames && frames.length > 0) addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE);
74
+ if (frames && frames.length > 0) addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE, basePath);
64
75
  LRU_FILE_CONTENTS_CACHE.reduce();
65
76
  return frames;
66
77
  }
67
- function getContextLinesFromFile(path, ranges, output) {
78
+ async function openRegularSourceFile(path, openSourceFile, logger) {
79
+ let fileHandle;
80
+ let isValid = false;
81
+ try {
82
+ fileHandle = await openSourceFile(path, external_node_fs_namespaceObject.constants.O_RDONLY | external_node_fs_namespaceObject.constants.O_NONBLOCK);
83
+ const fileStat = await fileHandle.stat();
84
+ if (!fileStat.isFile()) return;
85
+ if (fileStat.size > MAX_CONTEXTLINES_FILE_SIZE) return void logger?.debug(`Skipping source context for oversized file ${path}: ${fileStat.size} bytes exceeds ${MAX_CONTEXTLINES_FILE_SIZE}`);
86
+ isValid = true;
87
+ return fileHandle;
88
+ } catch {
89
+ return;
90
+ } finally{
91
+ if (fileHandle && !isValid) await fileHandle.close().catch(()=>{});
92
+ }
93
+ }
94
+ async function getContextLinesFromFile(path, ranges, output, cacheKey, openSourceFile, logger) {
95
+ const fileHandle = await openRegularSourceFile(path, openSourceFile, logger);
96
+ if (void 0 === fileHandle) return void LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
97
+ const openedFileHandle = fileHandle;
68
98
  return new Promise((resolve)=>{
69
- const stream = (0, external_node_fs_namespaceObject.createReadStream)(path);
70
- const lineReaded = (0, external_node_readline_namespaceObject.createInterface)({
71
- input: stream
72
- });
73
- function destroyStreamAndResolve() {
74
- stream.destroy();
75
- resolve();
99
+ let finished = false;
100
+ function destroyStreamAndResolve(stream) {
101
+ if (finished) return;
102
+ finished = true;
103
+ stream?.destroy();
104
+ openedFileHandle.close().then(resolve, resolve);
105
+ }
106
+ let stream;
107
+ try {
108
+ stream = openedFileHandle.createReadStream({
109
+ autoClose: false,
110
+ start: 0,
111
+ end: MAX_CONTEXTLINES_FILE_SIZE - 1
112
+ });
113
+ } catch {
114
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
115
+ destroyStreamAndResolve();
116
+ return;
117
+ }
118
+ let lineReaded;
119
+ try {
120
+ lineReaded = (0, external_node_readline_namespaceObject.createInterface)({
121
+ input: stream
122
+ });
123
+ } catch {
124
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
125
+ destroyStreamAndResolve(stream);
126
+ return;
76
127
  }
77
128
  let lineNumber = 0;
78
129
  let currentRangeIndex = 0;
79
130
  const range = ranges[currentRangeIndex];
80
- if (void 0 === range) return void destroyStreamAndResolve();
131
+ if (void 0 === range) return void destroyStreamAndResolve(stream);
81
132
  let rangeStart = range[0];
82
133
  let rangeEnd = range[1];
83
134
  function onStreamError() {
84
- LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1);
135
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
85
136
  lineReaded.close();
86
137
  lineReaded.removeAllListeners();
87
- destroyStreamAndResolve();
138
+ destroyStreamAndResolve(stream);
88
139
  }
89
140
  stream.on('error', onStreamError);
90
141
  lineReaded.on('error', onStreamError);
91
- lineReaded.on('close', destroyStreamAndResolve);
142
+ lineReaded.on('close', ()=>destroyStreamAndResolve(stream));
92
143
  lineReaded.on('line', (line)=>{
93
144
  lineNumber++;
94
145
  if (lineNumber < rangeStart) return;
@@ -112,9 +163,10 @@ function getContextLinesFromFile(path, ranges, output) {
112
163
  });
113
164
  });
114
165
  }
115
- function addSourceContextToFrames(frames, cache) {
166
+ function addSourceContextToFrames(frames, cache, basePath) {
116
167
  for (const frame of frames)if (frame.filename && void 0 === frame.context_line && 'number' == typeof frame.lineno) {
117
- const contents = cache.get(frame.filename);
168
+ const cacheKey = makeSourceCacheKey(frame.filename, basePath);
169
+ const contents = void 0 === cacheKey ? void 0 : cache.get(cacheKey);
118
170
  if (void 0 === contents) continue;
119
171
  addContextToFrame(frame.lineno, frame, contents);
120
172
  }
@@ -150,8 +202,18 @@ function shouldSkipContextLinesForFrame(frame) {
150
202
  if (void 0 !== frame.colno && frame.colno > MAX_CONTEXTLINES_COLNO) return true;
151
203
  return false;
152
204
  }
153
- function rangeExistsInContentCache(file, range) {
154
- const contents = LRU_FILE_CONTENTS_CACHE.get(file);
205
+ function makeSourceCacheKey(path, basePath) {
206
+ if ((0, external_node_path_namespaceObject.isAbsolute)(path)) return JSON.stringify([
207
+ null,
208
+ path
209
+ ]);
210
+ return void 0 === basePath ? void 0 : JSON.stringify([
211
+ basePath,
212
+ path
213
+ ]);
214
+ }
215
+ function rangeExistsInContentCache(cacheKey, range) {
216
+ const contents = LRU_FILE_CONTENTS_CACHE.get(cacheKey);
155
217
  if (void 0 === contents) return false;
156
218
  for(let i = range[0]; i <= range[1]; i++)if (void 0 === contents[i]) return false;
157
219
  return true;
@@ -215,10 +277,12 @@ function snipLine(line, colno) {
215
277
  return newLine;
216
278
  }
217
279
  exports.MAX_CONTEXTLINES_COLNO = __webpack_exports__.MAX_CONTEXTLINES_COLNO;
280
+ exports.MAX_CONTEXTLINES_FILE_SIZE = __webpack_exports__.MAX_CONTEXTLINES_FILE_SIZE;
218
281
  exports.MAX_CONTEXTLINES_LINENO = __webpack_exports__.MAX_CONTEXTLINES_LINENO;
219
282
  exports.addSourceContext = __webpack_exports__.addSourceContext;
220
283
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
221
284
  "MAX_CONTEXTLINES_COLNO",
285
+ "MAX_CONTEXTLINES_FILE_SIZE",
222
286
  "MAX_CONTEXTLINES_LINENO",
223
287
  "addSourceContext"
224
288
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
@@ -1,17 +1,25 @@
1
1
  import { ErrorTracking } from "@posthog/core";
2
- import { createReadStream } from "node:fs";
2
+ import { constants } from "node:fs";
3
+ import { open as promises_open } from "node:fs/promises";
4
+ import { isAbsolute } from "node:path";
3
5
  import { createInterface } from "node:readline";
4
6
  const LRU_FILE_CONTENTS_CACHE = new ErrorTracking.ReduceableCache(25);
5
7
  const LRU_FILE_CONTENTS_FS_READ_FAILED = new ErrorTracking.ReduceableCache(20);
6
8
  const DEFAULT_LINES_OF_CONTEXT = 7;
7
9
  const MAX_CONTEXTLINES_COLNO = 1000;
8
10
  const MAX_CONTEXTLINES_LINENO = 10000;
9
- async function addSourceContext(frames) {
11
+ const MAX_CONTEXTLINES_FILE_SIZE = 10485760;
12
+ async function addSourceContext(frames, openSourceFile = promises_open, logger) {
10
13
  const filesToLines = {};
14
+ let basePath;
15
+ try {
16
+ basePath = process.cwd();
17
+ } catch {}
11
18
  for(let i = frames.length - 1; i >= 0; i--){
12
19
  const frame = frames[i];
13
20
  const filename = frame?.filename;
14
21
  if (!frame || 'string' != typeof filename || 'number' != typeof frame.lineno || shouldSkipContextLinesForFile(filename) || shouldSkipContextLinesForFrame(frame)) continue;
22
+ if (!isAbsolute(filename) && void 0 === basePath) continue;
15
23
  const filesToLinesOutput = filesToLines[filename];
16
24
  if (!filesToLinesOutput) filesToLines[filename] = [];
17
25
  filesToLines[filename].push(frame.lineno);
@@ -20,45 +28,87 @@ async function addSourceContext(frames) {
20
28
  if (0 == files.length) return frames;
21
29
  const readlinePromises = [];
22
30
  for (const file of files){
23
- if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(file)) continue;
31
+ const cacheKey = makeSourceCacheKey(file, basePath);
32
+ if (void 0 === cacheKey) continue;
33
+ if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(cacheKey)) continue;
24
34
  const filesToLineRanges = filesToLines[file];
25
35
  if (!filesToLineRanges) continue;
26
36
  filesToLineRanges.sort((a, b)=>a - b);
27
37
  const ranges = makeLineReaderRanges(filesToLineRanges);
28
- if (ranges.every((r)=>rangeExistsInContentCache(file, r))) continue;
29
- const cache = emplace(LRU_FILE_CONTENTS_CACHE, file, {});
30
- readlinePromises.push(getContextLinesFromFile(file, ranges, cache));
38
+ if (ranges.every((r)=>rangeExistsInContentCache(cacheKey, r))) continue;
39
+ const cache = emplace(LRU_FILE_CONTENTS_CACHE, cacheKey, {});
40
+ readlinePromises.push(getContextLinesFromFile(file, ranges, cache, cacheKey, openSourceFile, logger));
31
41
  }
32
42
  await Promise.all(readlinePromises).catch(()=>{});
33
- if (frames && frames.length > 0) addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE);
43
+ if (frames && frames.length > 0) addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE, basePath);
34
44
  LRU_FILE_CONTENTS_CACHE.reduce();
35
45
  return frames;
36
46
  }
37
- function getContextLinesFromFile(path, ranges, output) {
47
+ async function openRegularSourceFile(path, openSourceFile, logger) {
48
+ let fileHandle;
49
+ let isValid = false;
50
+ try {
51
+ fileHandle = await openSourceFile(path, constants.O_RDONLY | constants.O_NONBLOCK);
52
+ const fileStat = await fileHandle.stat();
53
+ if (!fileStat.isFile()) return;
54
+ if (fileStat.size > MAX_CONTEXTLINES_FILE_SIZE) return void logger?.debug(`Skipping source context for oversized file ${path}: ${fileStat.size} bytes exceeds ${MAX_CONTEXTLINES_FILE_SIZE}`);
55
+ isValid = true;
56
+ return fileHandle;
57
+ } catch {
58
+ return;
59
+ } finally{
60
+ if (fileHandle && !isValid) await fileHandle.close().catch(()=>{});
61
+ }
62
+ }
63
+ async function getContextLinesFromFile(path, ranges, output, cacheKey, openSourceFile, logger) {
64
+ const fileHandle = await openRegularSourceFile(path, openSourceFile, logger);
65
+ if (void 0 === fileHandle) return void LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
66
+ const openedFileHandle = fileHandle;
38
67
  return new Promise((resolve)=>{
39
- const stream = createReadStream(path);
40
- const lineReaded = createInterface({
41
- input: stream
42
- });
43
- function destroyStreamAndResolve() {
44
- stream.destroy();
45
- resolve();
68
+ let finished = false;
69
+ function destroyStreamAndResolve(stream) {
70
+ if (finished) return;
71
+ finished = true;
72
+ stream?.destroy();
73
+ openedFileHandle.close().then(resolve, resolve);
74
+ }
75
+ let stream;
76
+ try {
77
+ stream = openedFileHandle.createReadStream({
78
+ autoClose: false,
79
+ start: 0,
80
+ end: MAX_CONTEXTLINES_FILE_SIZE - 1
81
+ });
82
+ } catch {
83
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
84
+ destroyStreamAndResolve();
85
+ return;
86
+ }
87
+ let lineReaded;
88
+ try {
89
+ lineReaded = createInterface({
90
+ input: stream
91
+ });
92
+ } catch {
93
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
94
+ destroyStreamAndResolve(stream);
95
+ return;
46
96
  }
47
97
  let lineNumber = 0;
48
98
  let currentRangeIndex = 0;
49
99
  const range = ranges[currentRangeIndex];
50
- if (void 0 === range) return void destroyStreamAndResolve();
100
+ if (void 0 === range) return void destroyStreamAndResolve(stream);
51
101
  let rangeStart = range[0];
52
102
  let rangeEnd = range[1];
53
103
  function onStreamError() {
54
- LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1);
104
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
55
105
  lineReaded.close();
56
106
  lineReaded.removeAllListeners();
57
- destroyStreamAndResolve();
107
+ destroyStreamAndResolve(stream);
58
108
  }
59
109
  stream.on('error', onStreamError);
60
110
  lineReaded.on('error', onStreamError);
61
- lineReaded.on('close', destroyStreamAndResolve);
111
+ lineReaded.on('close', ()=>destroyStreamAndResolve(stream));
62
112
  lineReaded.on('line', (line)=>{
63
113
  lineNumber++;
64
114
  if (lineNumber < rangeStart) return;
@@ -82,9 +132,10 @@ function getContextLinesFromFile(path, ranges, output) {
82
132
  });
83
133
  });
84
134
  }
85
- function addSourceContextToFrames(frames, cache) {
135
+ function addSourceContextToFrames(frames, cache, basePath) {
86
136
  for (const frame of frames)if (frame.filename && void 0 === frame.context_line && 'number' == typeof frame.lineno) {
87
- const contents = cache.get(frame.filename);
137
+ const cacheKey = makeSourceCacheKey(frame.filename, basePath);
138
+ const contents = void 0 === cacheKey ? void 0 : cache.get(cacheKey);
88
139
  if (void 0 === contents) continue;
89
140
  addContextToFrame(frame.lineno, frame, contents);
90
141
  }
@@ -120,8 +171,18 @@ function shouldSkipContextLinesForFrame(frame) {
120
171
  if (void 0 !== frame.colno && frame.colno > MAX_CONTEXTLINES_COLNO) return true;
121
172
  return false;
122
173
  }
123
- function rangeExistsInContentCache(file, range) {
124
- const contents = LRU_FILE_CONTENTS_CACHE.get(file);
174
+ function makeSourceCacheKey(path, basePath) {
175
+ if (isAbsolute(path)) return JSON.stringify([
176
+ null,
177
+ path
178
+ ]);
179
+ return void 0 === basePath ? void 0 : JSON.stringify([
180
+ basePath,
181
+ path
182
+ ]);
183
+ }
184
+ function rangeExistsInContentCache(cacheKey, range) {
185
+ const contents = LRU_FILE_CONTENTS_CACHE.get(cacheKey);
125
186
  if (void 0 === contents) return false;
126
187
  for(let i = range[0]; i <= range[1]; i++)if (void 0 === contents[i]) return false;
127
188
  return true;
@@ -184,4 +245,4 @@ function snipLine(line, colno) {
184
245
  if (end < lineLength) newLine += '...';
185
246
  return newLine;
186
247
  }
187
- export { MAX_CONTEXTLINES_COLNO, MAX_CONTEXTLINES_LINENO, addSourceContext };
248
+ export { MAX_CONTEXTLINES_COLNO, MAX_CONTEXTLINES_FILE_SIZE, MAX_CONTEXTLINES_LINENO, addSourceContext };
@@ -67,6 +67,7 @@ declare class FeatureFlagsPoller {
67
67
  onLoad?: (count: number) => void;
68
68
  private cacheProvider?;
69
69
  private loadingPromise?;
70
+ private pollerStopped;
70
71
  private flagsEtag?;
71
72
  private nextFetchAllowedAt?;
72
73
  private strictLocalEvaluation;
@@ -1 +1 @@
1
- {"version":3,"file":"feature-flags.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAmC,kBAAkB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtH,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAG1G,OAAO,EAAE,2BAA2B,EAA2B,MAAM,SAAS,CAAA;AAe9E,KAAK,oBAAoB,GAAG,OAAO,GAAG,UAAU,GAAG,sBAAsB,CAAA;AAEzE,cAAM,WAAY,SAAQ,KAAK;gBACjB,OAAO,EAAE,MAAM;CAO5B;AAWD,cAAM,sBAAuB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,cAAM,wBAAyB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED,KAAK,yBAAyB,GAAG;IAC/B,cAAc,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACpF,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAChC,M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,IAAI,OAAO;IAIjC;;;OAGG;IACH,0BAA0B,IAAI,MAAM,GAAG,SAAS;IAIhD;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAQ1B;;;OAGG;IACH,OAAO,CAAC,YAAY;IAQpB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAMd,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmKxC,OAAO,CAAC,+BAA+B;IAoBjC,8BAA8B,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAqD/D,UAAU,CAAC,SAAS,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAsB3D;AAWD,iBAAS,aAAa,CACpB,QAAQ,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EACpD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GACnC,OAAO,CAqJT;AA6JD,KAAK,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAgB3C;;;;;;;;GAQG;AACH,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAwB/C;AAuGD,iBAAS,uCAAuC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAmC3E;AAED,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,uCAAuC,EACvC,WAAW,EACX,sBAAsB,EACtB,wBAAwB,EACxB,WAAW,GACZ,CAAA"}
@@ -71,6 +71,7 @@ class FeatureFlagsPoller {
71
71
  this.debugMode = false;
72
72
  this.shouldBeginExponentialBackoff = false;
73
73
  this.backOffCount = 0;
74
+ this.pollerStopped = false;
74
75
  this.pollingInterval = pollingInterval;
75
76
  this.personalApiKey = personalApiKey;
76
77
  this.featureFlags = [];
@@ -400,7 +401,6 @@ class FeatureFlagsPoller {
400
401
  clearTimeout(this.poller);
401
402
  this.poller = void 0;
402
403
  }
403
- this.poller = setTimeout(()=>this.loadFeatureFlags(true), this.getPollingInterval());
404
404
  try {
405
405
  let shouldFetch = true;
406
406
  if (this.cacheProvider) try {
@@ -467,6 +467,8 @@ class FeatureFlagsPoller {
467
467
  }
468
468
  } catch (err) {
469
469
  if (err instanceof ClientError) this.onError?.(err);
470
+ } finally{
471
+ if (!this.pollerStopped) this.poller = setTimeout(()=>this.loadFeatureFlags(true), this.getPollingInterval());
470
472
  }
471
473
  }
472
474
  getPersonalApiKeyRequestOptions(method = 'GET', etag) {
@@ -525,7 +527,9 @@ class FeatureFlagsPoller {
525
527
  }
526
528
  }
527
529
  async stopPoller(timeoutMs = 30000) {
530
+ this.pollerStopped = true;
528
531
  clearTimeout(this.poller);
532
+ this.poller = void 0;
529
533
  if (this.cacheProvider) try {
530
534
  const shutdownResult = this.cacheProvider.shutdown();
531
535
  if (shutdownResult instanceof Promise) await (0, core_namespaceObject.raceWithTimeout)(shutdownResult, timeoutMs, ()=>{
@@ -37,6 +37,7 @@ class FeatureFlagsPoller {
37
37
  this.debugMode = false;
38
38
  this.shouldBeginExponentialBackoff = false;
39
39
  this.backOffCount = 0;
40
+ this.pollerStopped = false;
40
41
  this.pollingInterval = pollingInterval;
41
42
  this.personalApiKey = personalApiKey;
42
43
  this.featureFlags = [];
@@ -366,7 +367,6 @@ class FeatureFlagsPoller {
366
367
  clearTimeout(this.poller);
367
368
  this.poller = void 0;
368
369
  }
369
- this.poller = setTimeout(()=>this.loadFeatureFlags(true), this.getPollingInterval());
370
370
  try {
371
371
  let shouldFetch = true;
372
372
  if (this.cacheProvider) try {
@@ -433,6 +433,8 @@ class FeatureFlagsPoller {
433
433
  }
434
434
  } catch (err) {
435
435
  if (err instanceof ClientError) this.onError?.(err);
436
+ } finally{
437
+ if (!this.pollerStopped) this.poller = setTimeout(()=>this.loadFeatureFlags(true), this.getPollingInterval());
436
438
  }
437
439
  }
438
440
  getPersonalApiKeyRequestOptions(method = 'GET', etag) {
@@ -491,7 +493,9 @@ class FeatureFlagsPoller {
491
493
  }
492
494
  }
493
495
  async stopPoller(timeoutMs = 30000) {
496
+ this.pollerStopped = true;
494
497
  clearTimeout(this.poller);
498
+ this.poller = void 0;
495
499
  if (this.cacheProvider) try {
496
500
  const shutdownResult = this.cacheProvider.shutdown();
497
501
  if (shutdownResult instanceof Promise) await raceWithTimeout(shutdownResult, timeoutMs, ()=>{
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const version = "5.47.6";
1
+ export declare const version = "5.47.8";
2
2
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  version: ()=>version
28
28
  });
29
- const version = '5.47.6';
29
+ const version = '5.47.8';
30
30
  exports.version = __webpack_exports__.version;
31
31
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
32
32
  "version"
package/dist/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- const version = '5.47.6';
1
+ const version = '5.47.8';
2
2
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-node",
3
- "version": "5.47.6",
3
+ "version": "5.47.8",
4
4
  "bugs": {
5
5
  "url": "https://github.com/PostHog/posthog-js/issues"
6
6
  },
@@ -28,7 +28,7 @@
28
28
  "module": "dist/entrypoints/index.node.mjs",
29
29
  "types": "dist/entrypoints/index.node.d.ts",
30
30
  "dependencies": {
31
- "@posthog/core": "^1.46.4"
31
+ "@posthog/core": "^1.46.6"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@edge-runtime/jest-environment": "^4.0.0",
@@ -27,7 +27,11 @@ export class PostHog extends PostHogBackendClient {
27
27
  new CoreErrorTracking.PrimitiveCoercer(),
28
28
  ],
29
29
  CoreErrorTracking.createStackParser('node:javascript', CoreErrorTracking.nodeStackLineParser),
30
- [createModulerModifier(), addSourceContext, createRelativePathModifier()]
30
+ [
31
+ createModulerModifier(),
32
+ (frames) => addSourceContext(frames, undefined, this._logger),
33
+ createRelativePathModifier(),
34
+ ]
31
35
  )
32
36
  }
33
37
  }
@@ -2,8 +2,10 @@
2
2
  // Copyright (c) 2012 Functional Software, Inc. dba Sentry
3
3
  // Licensed under the MIT License: https://github.com/getsentry/sentry-javascript/blob/develop/LICENSE
4
4
 
5
- import { ErrorTracking as CoreErrorTracking } from '@posthog/core'
6
- import { createReadStream } from 'node:fs'
5
+ import { ErrorTracking as CoreErrorTracking, type Logger } from '@posthog/core'
6
+ import { constants, type ReadStream } from 'node:fs'
7
+ import { open, type FileHandle } from 'node:fs/promises'
8
+ import { isAbsolute } from 'node:path'
7
9
  import { createInterface } from 'node:readline'
8
10
 
9
11
  const LRU_FILE_CONTENTS_CACHE = new CoreErrorTracking.ReduceableCache<string, Record<number, string>>(25)
@@ -14,15 +16,25 @@ const DEFAULT_LINES_OF_CONTEXT = 7
14
16
  // Exported for testing purposes.
15
17
  export const MAX_CONTEXTLINES_COLNO: number = 1000
16
18
  export const MAX_CONTEXTLINES_LINENO: number = 10000
19
+ export const MAX_CONTEXTLINES_FILE_SIZE: number = 10 * 1024 * 1024
17
20
 
18
21
  type ReadlineRange = [start: number, end: number]
22
+ type OpenSourceFile = (path: string, flags: number) => Promise<FileHandle>
19
23
 
20
24
  export async function addSourceContext(
21
- frames: CoreErrorTracking.StackFrame[]
25
+ frames: CoreErrorTracking.StackFrame[],
26
+ openSourceFile: OpenSourceFile = open,
27
+ logger?: Pick<Logger, 'debug'>
22
28
  ): Promise<CoreErrorTracking.StackFrame[]> {
23
29
  // keep a lookup map of which files we've already enqueued to read,
24
30
  // so we don't enqueue the same file multiple times which would cause multiple i/o reads
25
31
  const filesToLines: Record<string, number[]> = {}
32
+ let basePath: string | undefined
33
+ try {
34
+ basePath = process.cwd()
35
+ } catch {
36
+ // Absolute source paths can still be processed when the working directory was removed.
37
+ }
26
38
 
27
39
  // Maps preserve insertion order, so we iterate in reverse, starting at the
28
40
  // outermost frame and closer to where the exception has occurred (poor mans priority)
@@ -40,6 +52,9 @@ export async function addSourceContext(
40
52
  continue
41
53
  }
42
54
 
55
+ if (!isAbsolute(filename) && basePath === undefined) {
56
+ continue
57
+ }
43
58
  const filesToLinesOutput = filesToLines[filename]
44
59
  if (!filesToLinesOutput) {
45
60
  filesToLines[filename] = []
@@ -54,8 +69,13 @@ export async function addSourceContext(
54
69
 
55
70
  const readlinePromises: Promise<void>[] = []
56
71
  for (const file of files) {
72
+ const cacheKey = makeSourceCacheKey(file, basePath)
73
+ if (cacheKey === undefined) {
74
+ continue
75
+ }
76
+
57
77
  // If we failed to read this before, dont try reading it again.
58
- if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(file)) {
78
+ if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(cacheKey)) {
59
79
  continue
60
80
  }
61
81
 
@@ -68,12 +88,12 @@ export async function addSourceContext(
68
88
  filesToLineRanges.sort((a, b) => a - b)
69
89
  // Check if the contents are already in the cache and if we can avoid reading the file again.
70
90
  const ranges = makeLineReaderRanges(filesToLineRanges)
71
- if (ranges.every((r) => rangeExistsInContentCache(file, r))) {
91
+ if (ranges.every((r) => rangeExistsInContentCache(cacheKey, r))) {
72
92
  continue
73
93
  }
74
94
 
75
- const cache = emplace(LRU_FILE_CONTENTS_CACHE, file, {})
76
- readlinePromises.push(getContextLinesFromFile(file, ranges, cache))
95
+ const cache = emplace(LRU_FILE_CONTENTS_CACHE, cacheKey, {})
96
+ readlinePromises.push(getContextLinesFromFile(file, ranges, cache, cacheKey, openSourceFile, logger))
77
97
  }
78
98
 
79
99
  // The promise rejections are caught in order to prevent them from short circuiting Promise.all
@@ -82,7 +102,7 @@ export async function addSourceContext(
82
102
  // Perform the same loop as above, but this time we can assume all files are in the cache
83
103
  // and attempt to add source context to frames.
84
104
  if (frames && frames.length > 0) {
85
- addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE)
105
+ addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE, basePath)
86
106
  }
87
107
 
88
108
  // Once we're finished processing an exception reduce the files held in the cache
@@ -92,25 +112,99 @@ export async function addSourceContext(
92
112
  return frames
93
113
  }
94
114
 
115
+ /**
116
+ * Opens a bounded regular file without blocking on special files such as FIFOs.
117
+ * File validation and content reads use the same descriptor so path replacement cannot change what is read.
118
+ */
119
+ async function openRegularSourceFile(
120
+ path: string,
121
+ openSourceFile: OpenSourceFile,
122
+ logger?: Pick<Logger, 'debug'>
123
+ ): Promise<FileHandle | undefined> {
124
+ let fileHandle: FileHandle | undefined
125
+ let isValid = false
126
+ try {
127
+ fileHandle = await openSourceFile(path, constants.O_RDONLY | constants.O_NONBLOCK)
128
+ const fileStat = await fileHandle.stat()
129
+ if (!fileStat.isFile()) {
130
+ return undefined
131
+ }
132
+ if (fileStat.size > MAX_CONTEXTLINES_FILE_SIZE) {
133
+ logger?.debug(
134
+ `Skipping source context for oversized file ${path}: ${fileStat.size} bytes exceeds ${MAX_CONTEXTLINES_FILE_SIZE}`
135
+ )
136
+ return undefined
137
+ }
138
+
139
+ isValid = true
140
+ return fileHandle
141
+ } catch {
142
+ return undefined
143
+ } finally {
144
+ if (fileHandle && !isValid) {
145
+ await fileHandle.close().catch(() => {})
146
+ }
147
+ }
148
+ }
149
+
95
150
  /**
96
151
  * Extracts lines from a file and stores them in a cache.
97
152
  */
98
- function getContextLinesFromFile(path: string, ranges: ReadlineRange[], output: Record<number, string>): Promise<void> {
153
+ async function getContextLinesFromFile(
154
+ path: string,
155
+ ranges: ReadlineRange[],
156
+ output: Record<number, string>,
157
+ cacheKey: string,
158
+ openSourceFile: OpenSourceFile,
159
+ logger?: Pick<Logger, 'debug'>
160
+ ): Promise<void> {
161
+ const fileHandle = await openRegularSourceFile(path, openSourceFile, logger)
162
+ if (fileHandle === undefined) {
163
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1)
164
+ return
165
+ }
166
+ const openedFileHandle = fileHandle
167
+
99
168
  return new Promise((resolve) => {
169
+ let finished = false
170
+
171
+ // We need to explicitly destroy the stream and close its descriptor to prevent memory leaks,
172
+ // removing the listeners on the readline interface is not enough.
173
+ // Otherwise, repeated exception captures can keep opening the same files without closing them.
174
+ function destroyStreamAndResolve(stream?: ReadStream): void {
175
+ if (finished) {
176
+ return
177
+ }
178
+ finished = true
179
+ stream?.destroy()
180
+ void openedFileHandle.close().then(resolve, resolve)
181
+ }
182
+
100
183
  // It is important *not* to have any async code between createInterface and the 'line' event listener
101
184
  // as it will cause the 'line' event to
102
185
  // be emitted before the listener is attached.
103
- const stream = createReadStream(path)
104
- const lineReaded = createInterface({
105
- input: stream,
106
- })
186
+ let stream: ReadStream
187
+ try {
188
+ stream = openedFileHandle.createReadStream({
189
+ autoClose: false,
190
+ start: 0,
191
+ end: MAX_CONTEXTLINES_FILE_SIZE - 1,
192
+ })
193
+ } catch {
194
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1)
195
+ destroyStreamAndResolve()
196
+ return
197
+ }
107
198
 
108
- // We need to explicitly destroy the stream to prevent memory leaks,
109
- // removing the listeners on the readline interface is not enough.
110
- // Otherwise, repeated exception captures can keep opening the same files without closing them.
111
- function destroyStreamAndResolve(): void {
112
- stream.destroy()
113
- resolve()
199
+ let lineReaded: ReturnType<typeof createInterface>
200
+ try {
201
+ lineReaded = createInterface({
202
+ input: stream,
203
+ })
204
+ } catch {
205
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1)
206
+ destroyStreamAndResolve(stream)
207
+ return
114
208
  }
115
209
 
116
210
  // Init at zero and increment at the start of the loop because lines are 1 indexed.
@@ -119,7 +213,7 @@ function getContextLinesFromFile(path: string, ranges: ReadlineRange[], output:
119
213
  const range = ranges[currentRangeIndex]
120
214
  if (range === undefined) {
121
215
  // We should never reach this point, but if we do, we should resolve the promise to prevent it from hanging.
122
- destroyStreamAndResolve()
216
+ destroyStreamAndResolve(stream)
123
217
  return
124
218
  }
125
219
  let rangeStart = range[0]
@@ -128,18 +222,18 @@ function getContextLinesFromFile(path: string, ranges: ReadlineRange[], output:
128
222
  // We use this inside Promise.all, so we need to resolve the promise even if there is an error
129
223
  // to prevent Promise.all from short circuiting the rest.
130
224
  function onStreamError(): void {
131
- // Mark file path as failed to read and prevent multiple read attempts.
132
- LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1)
225
+ // Mark the file as failed to prevent repeated read attempts.
226
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1)
133
227
  lineReaded.close()
134
228
  lineReaded.removeAllListeners()
135
- destroyStreamAndResolve()
229
+ destroyStreamAndResolve(stream)
136
230
  }
137
231
 
138
232
  // We need to handle the error event to prevent the process from crashing in < Node 16
139
233
  // https://github.com/nodejs/node/pull/31603
140
234
  stream.on('error', onStreamError)
141
235
  lineReaded.on('error', onStreamError)
142
- lineReaded.on('close', destroyStreamAndResolve)
236
+ lineReaded.on('close', () => destroyStreamAndResolve(stream))
143
237
 
144
238
  lineReaded.on('line', (line) => {
145
239
  lineNumber++
@@ -175,12 +269,14 @@ function getContextLinesFromFile(path: string, ranges: ReadlineRange[], output:
175
269
  /** Adds context lines to frames */
176
270
  function addSourceContextToFrames(
177
271
  frames: CoreErrorTracking.StackFrame[],
178
- cache: CoreErrorTracking.ReduceableCache<string, Record<number, string>>
272
+ cache: CoreErrorTracking.ReduceableCache<string, Record<number, string>>,
273
+ basePath: string | undefined
179
274
  ): void {
180
275
  for (const frame of frames) {
181
276
  // Only add context if we have a filename and it hasn't already been added
182
277
  if (frame.filename && frame.context_line === undefined && typeof frame.lineno === 'number') {
183
- const contents = cache.get(frame.filename)
278
+ const cacheKey = makeSourceCacheKey(frame.filename, basePath)
279
+ const contents = cacheKey === undefined ? undefined : cache.get(cacheKey)
184
280
  if (contents === undefined) {
185
281
  continue
186
282
  }
@@ -280,11 +376,18 @@ function shouldSkipContextLinesForFrame(frame: CoreErrorTracking.StackFrame): bo
280
376
  return false
281
377
  }
282
378
 
379
+ function makeSourceCacheKey(path: string, basePath: string | undefined): string | undefined {
380
+ if (isAbsolute(path)) {
381
+ return JSON.stringify([null, path])
382
+ }
383
+ return basePath === undefined ? undefined : JSON.stringify([basePath, path])
384
+ }
385
+
283
386
  /**
284
387
  * Checks if we have all the contents that we need in the cache.
285
388
  */
286
- function rangeExistsInContentCache(file: string, range: ReadlineRange): boolean {
287
- const contents = LRU_FILE_CONTENTS_CACHE.get(file)
389
+ function rangeExistsInContentCache(cacheKey: string, range: ReadlineRange): boolean {
390
+ const contents = LRU_FILE_CONTENTS_CACHE.get(cacheKey)
288
391
  if (contents === undefined) {
289
392
  return false
290
393
  }
@@ -107,6 +107,7 @@ class FeatureFlagsPoller {
107
107
  onLoad?: (count: number) => void
108
108
  private cacheProvider?: FlagDefinitionCacheProvider
109
109
  private loadingPromise?: Promise<void>
110
+ private pollerStopped: boolean = false
110
111
  private flagsEtag?: string
111
112
  private nextFetchAllowedAt?: number
112
113
  private strictLocalEvaluation: boolean
@@ -823,8 +824,6 @@ class FeatureFlagsPoller {
823
824
  this.poller = undefined
824
825
  }
825
826
 
826
- this.poller = setTimeout(() => this.loadFeatureFlags(true), this.getPollingInterval())
827
-
828
827
  try {
829
828
  let shouldFetch = true
830
829
  if (this.cacheProvider) {
@@ -975,6 +974,10 @@ class FeatureFlagsPoller {
975
974
  if (err instanceof ClientError) {
976
975
  this.onError?.(err)
977
976
  }
977
+ } finally {
978
+ if (!this.pollerStopped) {
979
+ this.poller = setTimeout(() => this.loadFeatureFlags(true), this.getPollingInterval())
980
+ }
978
981
  }
979
982
  }
980
983
 
@@ -1052,7 +1055,9 @@ class FeatureFlagsPoller {
1052
1055
  }
1053
1056
 
1054
1057
  async stopPoller(timeoutMs: number = 30000): Promise<void> {
1058
+ this.pollerStopped = true
1055
1059
  clearTimeout(this.poller)
1060
+ this.poller = undefined
1056
1061
 
1057
1062
  if (this.cacheProvider) {
1058
1063
  try {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.47.6'
1
+ export const version = '5.47.8'