@flareapp/js 2.0.1 → 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/index.cjs CHANGED
@@ -73,7 +73,7 @@ function hasStack$1(value) {
73
73
 
74
74
  //#endregion
75
75
  //#region src/env/index.ts
76
- const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.0.1" : "?";
76
+ const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.1.0" : "?";
77
77
  const KEY = typeof FLARE_JS_KEY === "undefined" ? "" : FLARE_JS_KEY;
78
78
  const SOURCEMAP_VERSION = typeof FLARE_SOURCEMAP_VERSION === "undefined" ? "" : FLARE_SOURCEMAP_VERSION;
79
79
 
@@ -282,6 +282,14 @@ function collectAttributes(urlDenylist) {
282
282
  };
283
283
  }
284
284
 
285
+ //#endregion
286
+ //#region src/stacktrace/nativeImport.ts
287
+ let cached = null;
288
+ function nativeImport(specifier) {
289
+ if (!cached) cached = new Function("specifier", "return import(specifier)");
290
+ return cached(specifier);
291
+ }
292
+
285
293
  //#endregion
286
294
  //#region src/stacktrace/fileReader.ts
287
295
  const cachedFiles = {};
@@ -291,7 +299,7 @@ function getCodeSnippet(url, lineNumber, columnNumber) {
291
299
  codeSnippet: { 0: `Could not read from file: missing file URL or line number. URL: ${url} lineNumber: ${lineNumber}` },
292
300
  trimmedColumnNumber: null
293
301
  });
294
- if (!isFetchableUrl(url)) return resolve({
302
+ if (!isFetchableUrl(url) && !(isNode() && isLocalFileUrl(url))) return resolve({
295
303
  codeSnippet: { 0: `Could not read from file: unsupported URL scheme. URL: ${url}` },
296
304
  trimmedColumnNumber: null
297
305
  });
@@ -307,14 +315,29 @@ function getCodeSnippet(url, lineNumber, columnNumber) {
307
315
  function isFetchableUrl(url) {
308
316
  return /^https?:\/\//i.test(url);
309
317
  }
318
+ function isNode() {
319
+ return typeof process !== "undefined" && process.release?.name === "node";
320
+ }
321
+ function isLocalFileUrl(url) {
322
+ return /^file:\/\//i.test(url) || url.startsWith("/") || /^[a-z]:[\\/]/i.test(url) || url.startsWith("\\\\");
323
+ }
310
324
  function readFile(url) {
311
325
  if (cachedFiles[url] !== void 0) return Promise.resolve(cachedFiles[url]);
326
+ return (isNode() && isLocalFileUrl(url) ? readFileFromDisk(url) : readFileWithFetch(url)).then((text) => {
327
+ if (text !== null) cachedFiles[url] = text;
328
+ return text;
329
+ });
330
+ }
331
+ function readFileWithFetch(url) {
312
332
  return fetch(url).then((response) => {
313
333
  if (response.status !== 200) return null;
314
334
  return response.text();
315
- }).then((text) => {
316
- if (text !== null) cachedFiles[url] = text;
317
- return text;
335
+ }).catch(() => null);
336
+ }
337
+ function readFileFromDisk(url) {
338
+ return nativeImport("node:url").then(({ fileURLToPath }) => {
339
+ const path = /^file:\/\//i.test(url) ? fileURLToPath(url) : url;
340
+ return nativeImport("node:fs/promises").then(({ readFile: readFileAsync }) => readFileAsync(path, "utf-8"));
318
341
  }).catch(() => null);
319
342
  }
320
343
  function readLinesFromFile(fileText, lineNumber, columnNumber, maxSnippetLineLength = 1e3, maxSnippetLines = 40) {
package/dist/index.mjs CHANGED
@@ -44,7 +44,7 @@ function hasStack$1(value) {
44
44
 
45
45
  //#endregion
46
46
  //#region src/env/index.ts
47
- const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.0.1" : "?";
47
+ const CLIENT_VERSION = typeof process !== "undefined" && true ? "2.1.0" : "?";
48
48
  const KEY = typeof FLARE_JS_KEY === "undefined" ? "" : FLARE_JS_KEY;
49
49
  const SOURCEMAP_VERSION = typeof FLARE_SOURCEMAP_VERSION === "undefined" ? "" : FLARE_SOURCEMAP_VERSION;
50
50
 
@@ -253,6 +253,14 @@ function collectAttributes(urlDenylist) {
253
253
  };
254
254
  }
255
255
 
256
+ //#endregion
257
+ //#region src/stacktrace/nativeImport.ts
258
+ let cached = null;
259
+ function nativeImport(specifier) {
260
+ if (!cached) cached = new Function("specifier", "return import(specifier)");
261
+ return cached(specifier);
262
+ }
263
+
256
264
  //#endregion
257
265
  //#region src/stacktrace/fileReader.ts
258
266
  const cachedFiles = {};
@@ -262,7 +270,7 @@ function getCodeSnippet(url, lineNumber, columnNumber) {
262
270
  codeSnippet: { 0: `Could not read from file: missing file URL or line number. URL: ${url} lineNumber: ${lineNumber}` },
263
271
  trimmedColumnNumber: null
264
272
  });
265
- if (!isFetchableUrl(url)) return resolve({
273
+ if (!isFetchableUrl(url) && !(isNode() && isLocalFileUrl(url))) return resolve({
266
274
  codeSnippet: { 0: `Could not read from file: unsupported URL scheme. URL: ${url}` },
267
275
  trimmedColumnNumber: null
268
276
  });
@@ -278,14 +286,29 @@ function getCodeSnippet(url, lineNumber, columnNumber) {
278
286
  function isFetchableUrl(url) {
279
287
  return /^https?:\/\//i.test(url);
280
288
  }
289
+ function isNode() {
290
+ return typeof process !== "undefined" && process.release?.name === "node";
291
+ }
292
+ function isLocalFileUrl(url) {
293
+ return /^file:\/\//i.test(url) || url.startsWith("/") || /^[a-z]:[\\/]/i.test(url) || url.startsWith("\\\\");
294
+ }
281
295
  function readFile(url) {
282
296
  if (cachedFiles[url] !== void 0) return Promise.resolve(cachedFiles[url]);
297
+ return (isNode() && isLocalFileUrl(url) ? readFileFromDisk(url) : readFileWithFetch(url)).then((text) => {
298
+ if (text !== null) cachedFiles[url] = text;
299
+ return text;
300
+ });
301
+ }
302
+ function readFileWithFetch(url) {
283
303
  return fetch(url).then((response) => {
284
304
  if (response.status !== 200) return null;
285
305
  return response.text();
286
- }).then((text) => {
287
- if (text !== null) cachedFiles[url] = text;
288
- return text;
306
+ }).catch(() => null);
307
+ }
308
+ function readFileFromDisk(url) {
309
+ return nativeImport("node:url").then(({ fileURLToPath }) => {
310
+ const path = /^file:\/\//i.test(url) ? fileURLToPath(url) : url;
311
+ return nativeImport("node:fs/promises").then(({ readFile: readFileAsync }) => readFileAsync(path, "utf-8"));
289
312
  }).catch(() => null);
290
313
  }
291
314
  function readLinesFromFile(fileText, lineNumber, columnNumber, maxSnippetLineLength = 1e3, maxSnippetLines = 40) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flareapp/js",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "JavaScript client for flareapp.io",
5
5
  "homepage": "https://flareapp.io",
6
6
  "bugs": {