@specific.dev/spectest 0.38.0 → 0.41.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/components/k3s.js +1 -24
- package/dist/components/supabase.d.ts +87 -27
- package/dist/components/supabase.js +352 -69
- package/dist/daemon.d.ts +38 -0
- package/dist/daemon.js +405 -946
- package/dist/harness/build-context.d.ts +82 -0
- package/dist/harness/build-context.js +113 -0
- package/dist/harness/buildkit-progress.d.ts +37 -0
- package/dist/harness/buildkit-progress.js +66 -0
- package/dist/harness/container-run.d.ts +89 -0
- package/dist/harness/container-run.js +118 -0
- package/dist/harness/file-mounts.d.ts +91 -0
- package/dist/harness/file-mounts.js +119 -0
- package/dist/harness/hostmatch.d.ts +65 -0
- package/dist/harness/hostmatch.js +108 -0
- package/dist/harness/http-proxy.d.ts +62 -0
- package/dist/harness/http-proxy.js +104 -0
- package/dist/harness/ingress-table.d.ts +148 -0
- package/dist/harness/ingress-table.js +129 -0
- package/dist/harness/log-delta.d.ts +54 -0
- package/dist/harness/log-delta.js +83 -0
- package/dist/harness/main.d.ts +47 -0
- package/dist/harness/main.js +164 -0
- package/dist/harness/methods.d.ts +54 -0
- package/dist/harness/methods.js +65 -0
- package/dist/harness/names-registry.d.ts +63 -0
- package/dist/harness/names-registry.js +90 -0
- package/dist/harness/protocol.d.ts +88 -0
- package/dist/harness/protocol.js +96 -0
- package/dist/harness/ready-poll.d.ts +47 -0
- package/dist/harness/ready-poll.js +67 -0
- package/dist/harness/service-graph.d.ts +29 -0
- package/dist/harness/service-graph.js +92 -0
- package/dist/harness/volume-paths.d.ts +70 -0
- package/dist/harness/volume-paths.js +81 -0
- package/dist/index.d.ts +3 -3
- package/dist/ingress.d.ts +1 -1
- package/dist/inspect.d.ts +23 -0
- package/dist/inspect.js +65 -0
- package/dist/resolver.js +5 -8
- package/dist/vendor/rrweb-plugin-console-record.umd.js +521 -0
- package/dist/vendor/rrweb-record.min.js +5061 -0
- package/package.json +7 -1
- package/src/aws-sigv4.ts +218 -0
- package/src/browser.ts +2040 -0
- package/src/components/aws.ts +554 -0
- package/src/components/email.ts +398 -0
- package/src/components/expo.ts +167 -0
- package/src/components/index.ts +81 -0
- package/src/components/k3s.ts +2061 -0
- package/src/components/postgres.ts +132 -0
- package/src/components/replayFake.ts +1015 -0
- package/src/components/s3.ts +132 -0
- package/src/components/supabase.ts +1699 -0
- package/src/daemon.ts +5489 -0
- package/src/harness/build-context.test.ts +0 -0
- package/src/harness/build-context.ts +146 -0
- package/src/harness/buildkit-progress.test.ts +98 -0
- package/src/harness/buildkit-progress.ts +74 -0
- package/src/harness/container-run.test.ts +209 -0
- package/src/harness/container-run.ts +158 -0
- package/src/harness/file-mounts.test.ts +185 -0
- package/src/harness/file-mounts.ts +145 -0
- package/src/harness/hostmatch.test.ts +148 -0
- package/src/harness/hostmatch.ts +109 -0
- package/src/harness/http-proxy.test.ts +156 -0
- package/src/harness/http-proxy.ts +119 -0
- package/src/harness/ingress-rebind.test.ts +125 -0
- package/src/harness/ingress-table.test.ts +172 -0
- package/src/harness/ingress-table.ts +186 -0
- package/src/harness/log-delta.test.ts +125 -0
- package/src/harness/log-delta.ts +100 -0
- package/src/harness/main.test.ts +211 -0
- package/src/harness/main.ts +196 -0
- package/src/harness/methods.test.ts +63 -0
- package/src/harness/methods.ts +92 -0
- package/src/harness/names-registry.test.ts +137 -0
- package/src/harness/names-registry.ts +108 -0
- package/src/harness/protocol.test.ts +148 -0
- package/src/harness/protocol.ts +163 -0
- package/src/harness/ready-poll.test.ts +172 -0
- package/src/harness/ready-poll.ts +93 -0
- package/src/harness/service-graph.test.ts +97 -0
- package/src/harness/service-graph.ts +97 -0
- package/src/harness/volume-paths.test.ts +102 -0
- package/src/harness/volume-paths.ts +112 -0
- package/src/ids.ts +89 -0
- package/src/index.ts +2725 -0
- package/src/ingress.ts +305 -0
- package/src/inspect.ts +739 -0
- package/src/locator.ts +716 -0
- package/src/mobile.ts +133 -0
- package/src/record-secrets.ts +41 -0
- package/src/recorder.ts +846 -0
- package/src/redis.ts +202 -0
- package/src/replay-bundle.ts +108 -0
- package/src/resolver.ts +348 -0
- package/src/s3.ts +333 -0
- package/src/sql.ts +243 -0
- package/src/terminal.ts +740 -0
- package/src/url-match.ts +67 -0
- package/src/vendor/rrweb-plugin-console-record.umd.js +521 -0
- package/src/vendor/rrweb-record.min.js +5061 -0
package/dist/index.d.ts
CHANGED
|
@@ -84,7 +84,7 @@ export interface ServiceConfig {
|
|
|
84
84
|
hostnames?: readonly string[];
|
|
85
85
|
/**
|
|
86
86
|
* Expose this service over HTTPS via a TLS-terminating reverse proxy
|
|
87
|
-
* hosted in the
|
|
87
|
+
* hosted in the harness. Each entry maps a fully-qualified
|
|
88
88
|
* hostname to the HTTP port the service listens on inside its
|
|
89
89
|
* container; the daemon binds the hostname on `:443` (SNI-multiplexed,
|
|
90
90
|
* with a leaf cert signed by the in-VM root CA) and on `:80`, and
|
|
@@ -1038,7 +1038,7 @@ export interface TestSuite<S extends ServicesMap = ServicesMap, F extends FakesM
|
|
|
1038
1038
|
tests: TestCase<unknown, S, F>[];
|
|
1039
1039
|
}
|
|
1040
1040
|
/**
|
|
1041
|
-
* A fake server hosted in the
|
|
1041
|
+
* A fake server hosted in the harness. Use this to stand in for
|
|
1042
1042
|
* external HTTP APIs (auth providers, payment gateways, …) that you can't
|
|
1043
1043
|
* call directly from the hermetic test VM.
|
|
1044
1044
|
*
|
|
@@ -1176,7 +1176,7 @@ export interface TypedTest<S extends ServicesMap, F extends FakesMap = FakesMap>
|
|
|
1176
1176
|
export interface Project<S extends ServicesMap = ServicesMap, F extends FakesMap = FakesMap> {
|
|
1177
1177
|
environment: EnvironmentConfig<S>;
|
|
1178
1178
|
/**
|
|
1179
|
-
* Fake servers hosted in the
|
|
1179
|
+
* Fake servers hosted in the harness (see {@link defineFake}).
|
|
1180
1180
|
* Keyed by stable fake name; the key becomes the slot in
|
|
1181
1181
|
* `ctx.fakes.<key>` from test code. Populated from the `fakes` declared
|
|
1182
1182
|
* in `defineEnvironment(...)`.
|
package/dist/ingress.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Project, ServiceConfig } from "./index.js";
|
|
2
|
-
/** Where a DNS name points. `ingress` = the
|
|
2
|
+
/** Where a DNS name points. `ingress` = the harness's listener on the
|
|
3
3
|
* bridge gateway (fakes, TLS-terminated proxies); `service` = a container's
|
|
4
4
|
* live IP on spectest-net (a plain peer alias, no daemon hop). */
|
|
5
5
|
export type DnsTarget = {
|
package/dist/inspect.d.ts
CHANGED
|
@@ -22,6 +22,29 @@ export declare function clearPendingNullish(): void;
|
|
|
22
22
|
export declare function adoptNullishTag<T>(value: T): T;
|
|
23
23
|
/** If x is wrapped, return the raw value; otherwise return x. */
|
|
24
24
|
export declare function readRaw<T>(x: T): T;
|
|
25
|
+
/**
|
|
26
|
+
* Strip provenance wrappers from a value AND from anything nested inside a
|
|
27
|
+
* plain object/array it holds. The inbound counterpart of {@link wrap}: for
|
|
28
|
+
* values crossing *back* into code that expects raw data — a fake's `helpers`,
|
|
29
|
+
* a k8s client method's arguments. Without it a helper that takes a value some
|
|
30
|
+
* earlier op produced gets a `Carrier`/proxy, and the first `.matchAll(...)` /
|
|
31
|
+
* typed-client call inside it throws a `TypeError` from deep in the callee,
|
|
32
|
+
* far from the call site that passed the wrapper. Coercion sinks
|
|
33
|
+
* ({@link makeCarrier}) rescue only the interpolation cases; a callee that
|
|
34
|
+
* calls a method on the value, or checks its `typeof`, still sees an object.
|
|
35
|
+
*
|
|
36
|
+
* One {@link readRaw} finishes a wrapped value: a wrapper's target is raw all
|
|
37
|
+
* the way down (the proxy wraps children lazily, on read), so there is nothing
|
|
38
|
+
* left to walk underneath it. The recursion is for the other shape — a
|
|
39
|
+
* container the *caller* built around wrapped leaves: `{ to: msg.to }`,
|
|
40
|
+
* `[row.id, row.email]`.
|
|
41
|
+
*
|
|
42
|
+
* Rebuilds only what changed, and only plain objects/arrays: a `Date`,
|
|
43
|
+
* `Buffer`, `Map`, `Response` or class instance is returned untouched rather
|
|
44
|
+
* than flattened into a plain object. Cyclic containers are left in place at
|
|
45
|
+
* the point the cycle closes.
|
|
46
|
+
*/
|
|
47
|
+
export declare function deepUnwrap<T>(value: T): T;
|
|
25
48
|
/** The raw type behind a wrapper: a `Carrier`/`WrappedObject`/`WrappedArray`/
|
|
26
49
|
* `WrappedResponse` resolves to its `unwrap()` return type; anything else is
|
|
27
50
|
* already raw and passes through unchanged. */
|
package/dist/inspect.js
CHANGED
|
@@ -136,6 +136,71 @@ export function readRaw(x) {
|
|
|
136
136
|
}
|
|
137
137
|
return cur;
|
|
138
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Strip provenance wrappers from a value AND from anything nested inside a
|
|
141
|
+
* plain object/array it holds. The inbound counterpart of {@link wrap}: for
|
|
142
|
+
* values crossing *back* into code that expects raw data — a fake's `helpers`,
|
|
143
|
+
* a k8s client method's arguments. Without it a helper that takes a value some
|
|
144
|
+
* earlier op produced gets a `Carrier`/proxy, and the first `.matchAll(...)` /
|
|
145
|
+
* typed-client call inside it throws a `TypeError` from deep in the callee,
|
|
146
|
+
* far from the call site that passed the wrapper. Coercion sinks
|
|
147
|
+
* ({@link makeCarrier}) rescue only the interpolation cases; a callee that
|
|
148
|
+
* calls a method on the value, or checks its `typeof`, still sees an object.
|
|
149
|
+
*
|
|
150
|
+
* One {@link readRaw} finishes a wrapped value: a wrapper's target is raw all
|
|
151
|
+
* the way down (the proxy wraps children lazily, on read), so there is nothing
|
|
152
|
+
* left to walk underneath it. The recursion is for the other shape — a
|
|
153
|
+
* container the *caller* built around wrapped leaves: `{ to: msg.to }`,
|
|
154
|
+
* `[row.id, row.email]`.
|
|
155
|
+
*
|
|
156
|
+
* Rebuilds only what changed, and only plain objects/arrays: a `Date`,
|
|
157
|
+
* `Buffer`, `Map`, `Response` or class instance is returned untouched rather
|
|
158
|
+
* than flattened into a plain object. Cyclic containers are left in place at
|
|
159
|
+
* the point the cycle closes.
|
|
160
|
+
*/
|
|
161
|
+
export function deepUnwrap(value) {
|
|
162
|
+
return deepUnwrapInner(value, new Set());
|
|
163
|
+
}
|
|
164
|
+
function deepUnwrapInner(value, seen) {
|
|
165
|
+
if (value === null || value === undefined)
|
|
166
|
+
return value;
|
|
167
|
+
const raw = readRaw(value);
|
|
168
|
+
// It was wrapped, so it's now fully raw — and recursing into it would be
|
|
169
|
+
// wrong anyway (the raw form may be an exotic object we must not rebuild).
|
|
170
|
+
if (raw !== value)
|
|
171
|
+
return raw;
|
|
172
|
+
if (typeof raw !== "object")
|
|
173
|
+
return raw;
|
|
174
|
+
const obj = raw;
|
|
175
|
+
if (seen.has(obj))
|
|
176
|
+
return obj;
|
|
177
|
+
if (Array.isArray(obj)) {
|
|
178
|
+
seen.add(obj);
|
|
179
|
+
let changed = false;
|
|
180
|
+
const out = obj.map((el) => {
|
|
181
|
+
const next = deepUnwrapInner(el, seen);
|
|
182
|
+
if (next !== el)
|
|
183
|
+
changed = true;
|
|
184
|
+
return next;
|
|
185
|
+
});
|
|
186
|
+
seen.delete(obj);
|
|
187
|
+
return changed ? out : obj;
|
|
188
|
+
}
|
|
189
|
+
const proto = Object.getPrototypeOf(obj);
|
|
190
|
+
if (proto !== Object.prototype && proto !== null)
|
|
191
|
+
return obj;
|
|
192
|
+
seen.add(obj);
|
|
193
|
+
let changed = false;
|
|
194
|
+
const out = {};
|
|
195
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
196
|
+
const next = deepUnwrapInner(v, seen);
|
|
197
|
+
if (next !== v)
|
|
198
|
+
changed = true;
|
|
199
|
+
out[k] = next;
|
|
200
|
+
}
|
|
201
|
+
seen.delete(obj);
|
|
202
|
+
return changed ? out : obj;
|
|
203
|
+
}
|
|
139
204
|
/**
|
|
140
205
|
* Wrap a value so reads through it carry an `OpTag`. Recursion is lazy:
|
|
141
206
|
* a property read on an object Proxy wraps its child on demand.
|
package/dist/resolver.js
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
import { createSocket } from "node:dgram";
|
|
28
28
|
import { request as httpRequest } from "node:http";
|
|
29
29
|
import { readFile, stat } from "node:fs/promises";
|
|
30
|
+
import { lookup } from "./harness/names-registry.js";
|
|
30
31
|
import * as dnsPacket from "dns-packet";
|
|
31
32
|
const NETWORK_NAME = process.env.SPECTEST_NETWORK ?? "spectest-net";
|
|
32
33
|
const DOCKER_SOCKET = process.env.DOCKER_SOCKET ?? "/var/run/docker.sock";
|
|
@@ -37,7 +38,7 @@ const UPSTREAM_PORT = Number(process.env.SPECTEST_UPSTREAM_PORT ?? "53");
|
|
|
37
38
|
const LISTEN_ADDR = process.env.SPECTEST_RESOLVER_ADDR ?? "127.0.0.53";
|
|
38
39
|
const LISTEN_PORT = Number(process.env.SPECTEST_RESOLVER_PORT ?? "53");
|
|
39
40
|
const TTL_SECONDS = Number(process.env.SPECTEST_RESOLVER_TTL ?? "5");
|
|
40
|
-
/** Path the
|
|
41
|
+
/** Path the harness writes when it brings fakes up. */
|
|
41
42
|
const FAKES_REGISTRY_PATH = process.env.SPECTEST_FAKES_REGISTRY ?? "/run/spectest-fakes.json";
|
|
42
43
|
function dockerGet(path) {
|
|
43
44
|
return new Promise((resolve) => {
|
|
@@ -129,13 +130,9 @@ async function lookupFake(name) {
|
|
|
129
130
|
* longest (most specific) matching suffix wins. */
|
|
130
131
|
async function lookupWildcard(name) {
|
|
131
132
|
await refreshRegistry();
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
best = w;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return best?.ip ?? null;
|
|
133
|
+
// Same module the harness writes with, so the two halves of this file
|
|
134
|
+
// format cannot drift apart.
|
|
135
|
+
return lookup({ hosts: {}, wildcards: registryCache.wildcards }, name);
|
|
139
136
|
}
|
|
140
137
|
async function forwardUpstream(query) {
|
|
141
138
|
return new Promise((resolve) => {
|
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
(function (g, f) {
|
|
2
|
+
if ("object" == typeof exports && "object" == typeof module) {
|
|
3
|
+
module.exports = f();
|
|
4
|
+
} else if ("function" == typeof define && define.amd) {
|
|
5
|
+
define("rrwebPluginConsoleRecord", [], f);
|
|
6
|
+
} else if ("object" == typeof exports) {
|
|
7
|
+
exports["rrwebPluginConsoleRecord"] = f();
|
|
8
|
+
} else {
|
|
9
|
+
g["rrwebPluginConsoleRecord"] = f();
|
|
10
|
+
}
|
|
11
|
+
}(this, () => {
|
|
12
|
+
var exports = {};
|
|
13
|
+
var module = { exports };
|
|
14
|
+
"use strict";
|
|
15
|
+
var __defProp = Object.defineProperty;
|
|
16
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
18
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
19
|
+
if (!/* @__PURE__ */ /[1-9][0-9]{12}/.test(Date.now().toString())) ;
|
|
20
|
+
function patch(source, name, replacement) {
|
|
21
|
+
try {
|
|
22
|
+
if (!(name in source)) {
|
|
23
|
+
return () => {
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const original = source[name];
|
|
27
|
+
const wrapped = replacement(original);
|
|
28
|
+
if (typeof wrapped === "function") {
|
|
29
|
+
wrapped.prototype = wrapped.prototype || {};
|
|
30
|
+
Object.defineProperties(wrapped, {
|
|
31
|
+
__rrweb_original__: {
|
|
32
|
+
enumerable: false,
|
|
33
|
+
value: original
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
source[name] = wrapped;
|
|
38
|
+
return () => {
|
|
39
|
+
source[name] = original;
|
|
40
|
+
};
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return () => {
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class StackFrame {
|
|
47
|
+
constructor(obj) {
|
|
48
|
+
__publicField(this, "fileName");
|
|
49
|
+
__publicField(this, "functionName");
|
|
50
|
+
__publicField(this, "lineNumber");
|
|
51
|
+
__publicField(this, "columnNumber");
|
|
52
|
+
this.fileName = obj.fileName || "";
|
|
53
|
+
this.functionName = obj.functionName || "";
|
|
54
|
+
this.lineNumber = obj.lineNumber;
|
|
55
|
+
this.columnNumber = obj.columnNumber;
|
|
56
|
+
}
|
|
57
|
+
toString() {
|
|
58
|
+
const lineNumber = this.lineNumber || "";
|
|
59
|
+
const columnNumber = this.columnNumber || "";
|
|
60
|
+
if (this.functionName)
|
|
61
|
+
return `${this.functionName} (${this.fileName}:${lineNumber}:${columnNumber})`;
|
|
62
|
+
return `${this.fileName}:${lineNumber}:${columnNumber}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+:\d+/;
|
|
66
|
+
const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
|
|
67
|
+
const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
|
|
68
|
+
const ErrorStackParser = {
|
|
69
|
+
/**
|
|
70
|
+
* Given an Error object, extract the most information from it.
|
|
71
|
+
*/
|
|
72
|
+
parse: function(error) {
|
|
73
|
+
if (!error) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
typeof error.stacktrace !== "undefined" || // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
typeof error["opera#sourceloc"] !== "undefined"
|
|
82
|
+
) {
|
|
83
|
+
return this.parseOpera(
|
|
84
|
+
error
|
|
85
|
+
);
|
|
86
|
+
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
|
|
87
|
+
return this.parseV8OrIE(error);
|
|
88
|
+
} else if (error.stack) {
|
|
89
|
+
return this.parseFFOrSafari(error);
|
|
90
|
+
} else {
|
|
91
|
+
console.warn(
|
|
92
|
+
"[console-record-plugin]: Failed to parse error object:",
|
|
93
|
+
error
|
|
94
|
+
);
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
// Separate line and column numbers from a string of the form: (URI:Line:Column)
|
|
99
|
+
extractLocation: function(urlLike) {
|
|
100
|
+
if (urlLike.indexOf(":") === -1) {
|
|
101
|
+
return [urlLike];
|
|
102
|
+
}
|
|
103
|
+
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
104
|
+
const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
|
|
105
|
+
if (!parts) throw new Error(`Cannot parse given url: ${urlLike}`);
|
|
106
|
+
return [parts[1], parts[2] || void 0, parts[3] || void 0];
|
|
107
|
+
},
|
|
108
|
+
parseV8OrIE: function(error) {
|
|
109
|
+
const filtered = error.stack.split("\n").filter(function(line) {
|
|
110
|
+
return !!line.match(CHROME_IE_STACK_REGEXP);
|
|
111
|
+
}, this);
|
|
112
|
+
return filtered.map(function(line) {
|
|
113
|
+
if (line.indexOf("(eval ") > -1) {
|
|
114
|
+
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(\),.*$)/g, "");
|
|
115
|
+
}
|
|
116
|
+
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(");
|
|
117
|
+
const location = sanitizedLine.match(/ (\((.+):(\d+):(\d+)\)$)/);
|
|
118
|
+
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
119
|
+
const tokens = sanitizedLine.split(/\s+/).slice(1);
|
|
120
|
+
const locationParts = this.extractLocation(
|
|
121
|
+
location ? location[1] : tokens.pop()
|
|
122
|
+
);
|
|
123
|
+
const functionName = tokens.join(" ") || void 0;
|
|
124
|
+
const fileName = ["eval", "<anonymous>"].indexOf(locationParts[0]) > -1 ? void 0 : locationParts[0];
|
|
125
|
+
return new StackFrame({
|
|
126
|
+
functionName,
|
|
127
|
+
fileName,
|
|
128
|
+
lineNumber: locationParts[1],
|
|
129
|
+
columnNumber: locationParts[2]
|
|
130
|
+
});
|
|
131
|
+
}, this);
|
|
132
|
+
},
|
|
133
|
+
parseFFOrSafari: function(error) {
|
|
134
|
+
const filtered = error.stack.split("\n").filter(function(line) {
|
|
135
|
+
return !line.match(SAFARI_NATIVE_CODE_REGEXP);
|
|
136
|
+
}, this);
|
|
137
|
+
return filtered.map(function(line) {
|
|
138
|
+
if (line.indexOf(" > eval") > -1) {
|
|
139
|
+
line = line.replace(
|
|
140
|
+
/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
|
|
141
|
+
":$1"
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
if (line.indexOf("@") === -1 && line.indexOf(":") === -1) {
|
|
145
|
+
return new StackFrame({
|
|
146
|
+
functionName: line
|
|
147
|
+
});
|
|
148
|
+
} else {
|
|
149
|
+
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
|
|
150
|
+
const matches = line.match(functionNameRegex);
|
|
151
|
+
const functionName = matches && matches[1] ? matches[1] : void 0;
|
|
152
|
+
const locationParts = this.extractLocation(
|
|
153
|
+
line.replace(functionNameRegex, "")
|
|
154
|
+
);
|
|
155
|
+
return new StackFrame({
|
|
156
|
+
functionName,
|
|
157
|
+
fileName: locationParts[0],
|
|
158
|
+
lineNumber: locationParts[1],
|
|
159
|
+
columnNumber: locationParts[2]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}, this);
|
|
163
|
+
},
|
|
164
|
+
parseOpera: function(e) {
|
|
165
|
+
if (!e.stacktrace || e.message.indexOf("\n") > -1 && e.message.split("\n").length > e.stacktrace.split("\n").length) {
|
|
166
|
+
return this.parseOpera9(e);
|
|
167
|
+
} else if (!e.stack) {
|
|
168
|
+
return this.parseOpera10(e);
|
|
169
|
+
} else {
|
|
170
|
+
return this.parseOpera11(e);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
parseOpera9: function(e) {
|
|
174
|
+
const lineRE = /Line (\d+).*script (?:in )?(\S+)/i;
|
|
175
|
+
const lines = e.message.split("\n");
|
|
176
|
+
const result = [];
|
|
177
|
+
for (let i = 2, len = lines.length; i < len; i += 2) {
|
|
178
|
+
const match = lineRE.exec(lines[i]);
|
|
179
|
+
if (match) {
|
|
180
|
+
result.push(
|
|
181
|
+
new StackFrame({
|
|
182
|
+
fileName: match[2],
|
|
183
|
+
lineNumber: parseFloat(match[1])
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
},
|
|
190
|
+
parseOpera10: function(e) {
|
|
191
|
+
const lineRE = /Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i;
|
|
192
|
+
const lines = e.stacktrace.split("\n");
|
|
193
|
+
const result = [];
|
|
194
|
+
for (let i = 0, len = lines.length; i < len; i += 2) {
|
|
195
|
+
const match = lineRE.exec(lines[i]);
|
|
196
|
+
if (match) {
|
|
197
|
+
result.push(
|
|
198
|
+
new StackFrame({
|
|
199
|
+
functionName: match[3] || void 0,
|
|
200
|
+
fileName: match[2],
|
|
201
|
+
lineNumber: parseFloat(match[1])
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
},
|
|
208
|
+
// Opera 10.65+ Error.stack very similar to FF/Safari
|
|
209
|
+
parseOpera11: function(error) {
|
|
210
|
+
const filtered = error.stack.split("\n").filter(function(line) {
|
|
211
|
+
return !!line.match(FIREFOX_SAFARI_STACK_REGEXP) && !line.match(/^Error created at/);
|
|
212
|
+
}, this);
|
|
213
|
+
return filtered.map(function(line) {
|
|
214
|
+
const tokens = line.split("@");
|
|
215
|
+
const locationParts = this.extractLocation(tokens.pop());
|
|
216
|
+
const functionCall = tokens.shift() || "";
|
|
217
|
+
const functionName = functionCall.replace(/<anonymous function(: (\w+))?>/, "$2").replace(/\([^)]*\)/g, "") || void 0;
|
|
218
|
+
return new StackFrame({
|
|
219
|
+
functionName,
|
|
220
|
+
fileName: locationParts[0],
|
|
221
|
+
lineNumber: locationParts[1],
|
|
222
|
+
columnNumber: locationParts[2]
|
|
223
|
+
});
|
|
224
|
+
}, this);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
function pathToSelector(node) {
|
|
228
|
+
if (!node || !node.outerHTML) {
|
|
229
|
+
return "";
|
|
230
|
+
}
|
|
231
|
+
let path = "";
|
|
232
|
+
while (node.parentElement) {
|
|
233
|
+
let name = node.localName;
|
|
234
|
+
if (!name) {
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
name = name.toLowerCase();
|
|
238
|
+
const parent = node.parentElement;
|
|
239
|
+
const domSiblings = [];
|
|
240
|
+
if (parent.children && parent.children.length > 0) {
|
|
241
|
+
for (let i = 0; i < parent.children.length; i++) {
|
|
242
|
+
const sibling = parent.children[i];
|
|
243
|
+
if (sibling.localName && sibling.localName.toLowerCase) {
|
|
244
|
+
if (sibling.localName.toLowerCase() === name) {
|
|
245
|
+
domSiblings.push(sibling);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (domSiblings.length > 1) {
|
|
251
|
+
name += `:eq(${domSiblings.indexOf(node)})`;
|
|
252
|
+
}
|
|
253
|
+
path = name + (path ? ">" + path : "");
|
|
254
|
+
node = parent;
|
|
255
|
+
}
|
|
256
|
+
return path;
|
|
257
|
+
}
|
|
258
|
+
function isObject(obj) {
|
|
259
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
260
|
+
}
|
|
261
|
+
function isObjTooDeep(obj, limit) {
|
|
262
|
+
if (limit === 0) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
const keys = Object.keys(obj);
|
|
266
|
+
for (const key of keys) {
|
|
267
|
+
if (isObject(obj[key]) && isObjTooDeep(obj[key], limit - 1)) {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
function stringify(obj, stringifyOptions) {
|
|
274
|
+
const options = {
|
|
275
|
+
numOfKeysLimit: 50,
|
|
276
|
+
depthOfLimit: 4
|
|
277
|
+
};
|
|
278
|
+
Object.assign(options, stringifyOptions);
|
|
279
|
+
const stack = [];
|
|
280
|
+
const keys = [];
|
|
281
|
+
return JSON.stringify(
|
|
282
|
+
obj,
|
|
283
|
+
function(key, value) {
|
|
284
|
+
if (stack.length > 0) {
|
|
285
|
+
const thisPos = stack.indexOf(this);
|
|
286
|
+
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
|
287
|
+
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
|
|
288
|
+
if (~stack.indexOf(value)) {
|
|
289
|
+
if (stack[0] === value) {
|
|
290
|
+
value = "[Circular ~]";
|
|
291
|
+
} else {
|
|
292
|
+
value = "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]";
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
stack.push(value);
|
|
297
|
+
}
|
|
298
|
+
if (value === null) return value;
|
|
299
|
+
if (value === void 0) return "undefined";
|
|
300
|
+
if (shouldIgnore(value)) {
|
|
301
|
+
return toString(value);
|
|
302
|
+
}
|
|
303
|
+
if (typeof value === "bigint") {
|
|
304
|
+
return value.toString() + "n";
|
|
305
|
+
}
|
|
306
|
+
if (value instanceof Event) {
|
|
307
|
+
const eventResult = {};
|
|
308
|
+
for (const eventKey in value) {
|
|
309
|
+
const eventValue = value[eventKey];
|
|
310
|
+
if (Array.isArray(eventValue)) {
|
|
311
|
+
eventResult[eventKey] = pathToSelector(
|
|
312
|
+
eventValue.length ? eventValue[0] : null
|
|
313
|
+
);
|
|
314
|
+
} else {
|
|
315
|
+
eventResult[eventKey] = eventValue;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return eventResult;
|
|
319
|
+
} else if (value instanceof Node) {
|
|
320
|
+
if (value instanceof HTMLElement) {
|
|
321
|
+
return value ? value.outerHTML : "";
|
|
322
|
+
}
|
|
323
|
+
return value.nodeName;
|
|
324
|
+
} else if (value instanceof Error) {
|
|
325
|
+
return value.stack ? value.stack + "\nEnd of stack for Error object" : value.name + ": " + value.message;
|
|
326
|
+
}
|
|
327
|
+
return value;
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
function shouldIgnore(_obj) {
|
|
331
|
+
if (isObject(_obj) && Object.keys(_obj).length > options.numOfKeysLimit) {
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
if (typeof _obj === "function") {
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
if (isObject(_obj) && isObjTooDeep(_obj, options.depthOfLimit)) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
function toString(_obj) {
|
|
343
|
+
let str = _obj.toString();
|
|
344
|
+
if (options.stringLengthLimit && str.length > options.stringLengthLimit) {
|
|
345
|
+
str = `${str.slice(0, options.stringLengthLimit)}...`;
|
|
346
|
+
}
|
|
347
|
+
return str;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
const defaultLogOptions = {
|
|
351
|
+
level: [
|
|
352
|
+
"assert",
|
|
353
|
+
"clear",
|
|
354
|
+
"count",
|
|
355
|
+
"countReset",
|
|
356
|
+
"debug",
|
|
357
|
+
"dir",
|
|
358
|
+
"dirxml",
|
|
359
|
+
"error",
|
|
360
|
+
"group",
|
|
361
|
+
"groupCollapsed",
|
|
362
|
+
"groupEnd",
|
|
363
|
+
"info",
|
|
364
|
+
"log",
|
|
365
|
+
"table",
|
|
366
|
+
"time",
|
|
367
|
+
"timeEnd",
|
|
368
|
+
"timeLog",
|
|
369
|
+
"trace",
|
|
370
|
+
"warn"
|
|
371
|
+
],
|
|
372
|
+
lengthThreshold: 1e3,
|
|
373
|
+
logger: "console"
|
|
374
|
+
};
|
|
375
|
+
function initLogObserver(cb, win, options) {
|
|
376
|
+
const logOptions = options ? Object.assign({}, defaultLogOptions, options) : defaultLogOptions;
|
|
377
|
+
const loggerType = logOptions.logger;
|
|
378
|
+
if (!loggerType) {
|
|
379
|
+
return () => {
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
let logger;
|
|
383
|
+
if (typeof loggerType === "string") {
|
|
384
|
+
logger = win[loggerType];
|
|
385
|
+
} else {
|
|
386
|
+
logger = loggerType;
|
|
387
|
+
}
|
|
388
|
+
let logCount = 0;
|
|
389
|
+
let inStack = false;
|
|
390
|
+
const cancelHandlers = [];
|
|
391
|
+
if (logOptions.level.includes("error")) {
|
|
392
|
+
const errorHandler = (event) => {
|
|
393
|
+
const message = event.message, error = event.error;
|
|
394
|
+
const trace = ErrorStackParser.parse(error).map(
|
|
395
|
+
(stackFrame) => stackFrame.toString()
|
|
396
|
+
);
|
|
397
|
+
const payload = [stringify(message, logOptions.stringifyOptions)];
|
|
398
|
+
cb({
|
|
399
|
+
level: "error",
|
|
400
|
+
trace,
|
|
401
|
+
payload
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
win.addEventListener("error", errorHandler);
|
|
405
|
+
cancelHandlers.push(() => {
|
|
406
|
+
win.removeEventListener("error", errorHandler);
|
|
407
|
+
});
|
|
408
|
+
const unhandledrejectionHandler = (event) => {
|
|
409
|
+
let error;
|
|
410
|
+
let payload;
|
|
411
|
+
if (event.reason instanceof Error) {
|
|
412
|
+
error = event.reason;
|
|
413
|
+
payload = [
|
|
414
|
+
stringify(
|
|
415
|
+
`Uncaught (in promise) ${error.name}: ${error.message}`,
|
|
416
|
+
logOptions.stringifyOptions
|
|
417
|
+
)
|
|
418
|
+
];
|
|
419
|
+
} else {
|
|
420
|
+
error = new Error();
|
|
421
|
+
payload = [
|
|
422
|
+
stringify("Uncaught (in promise)", logOptions.stringifyOptions),
|
|
423
|
+
stringify(event.reason, logOptions.stringifyOptions)
|
|
424
|
+
];
|
|
425
|
+
}
|
|
426
|
+
const trace = ErrorStackParser.parse(error).map(
|
|
427
|
+
(stackFrame) => stackFrame.toString()
|
|
428
|
+
);
|
|
429
|
+
cb({
|
|
430
|
+
level: "error",
|
|
431
|
+
trace,
|
|
432
|
+
payload
|
|
433
|
+
});
|
|
434
|
+
};
|
|
435
|
+
win.addEventListener("unhandledrejection", unhandledrejectionHandler);
|
|
436
|
+
cancelHandlers.push(() => {
|
|
437
|
+
win.removeEventListener("unhandledrejection", unhandledrejectionHandler);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
for (const levelType of logOptions.level) {
|
|
441
|
+
cancelHandlers.push(replace(logger, levelType));
|
|
442
|
+
}
|
|
443
|
+
return () => {
|
|
444
|
+
cancelHandlers.forEach((h) => h());
|
|
445
|
+
};
|
|
446
|
+
function replace(_logger, level) {
|
|
447
|
+
if (!_logger[level]) {
|
|
448
|
+
return () => {
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
return patch(
|
|
452
|
+
_logger,
|
|
453
|
+
level,
|
|
454
|
+
(original) => {
|
|
455
|
+
return (...args) => {
|
|
456
|
+
original.apply(this, args);
|
|
457
|
+
if (level === "assert" && !!args[0]) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
if (inStack) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
inStack = true;
|
|
464
|
+
try {
|
|
465
|
+
const trace = ErrorStackParser.parse(new Error()).map((stackFrame) => stackFrame.toString()).splice(1);
|
|
466
|
+
const argsForPayload = level === "assert" ? args.slice(1) : args;
|
|
467
|
+
const payload = argsForPayload.map(
|
|
468
|
+
(s) => stringify(s, logOptions.stringifyOptions)
|
|
469
|
+
);
|
|
470
|
+
logCount++;
|
|
471
|
+
if (logCount < logOptions.lengthThreshold) {
|
|
472
|
+
cb({
|
|
473
|
+
level,
|
|
474
|
+
trace,
|
|
475
|
+
payload
|
|
476
|
+
});
|
|
477
|
+
} else if (logCount === logOptions.lengthThreshold) {
|
|
478
|
+
cb({
|
|
479
|
+
level: "warn",
|
|
480
|
+
trace: [],
|
|
481
|
+
payload: [
|
|
482
|
+
stringify("The number of log records reached the threshold.")
|
|
483
|
+
]
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
} catch (error) {
|
|
487
|
+
original("rrweb logger error:", error, ...args);
|
|
488
|
+
} finally {
|
|
489
|
+
inStack = false;
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const PLUGIN_NAME = "rrweb/console@1";
|
|
497
|
+
const getRecordConsolePlugin = (options) => ({
|
|
498
|
+
name: PLUGIN_NAME,
|
|
499
|
+
observer: initLogObserver,
|
|
500
|
+
options
|
|
501
|
+
});
|
|
502
|
+
exports.PLUGIN_NAME = PLUGIN_NAME;
|
|
503
|
+
exports.getRecordConsolePlugin = getRecordConsolePlugin;
|
|
504
|
+
if (typeof module.exports == "object" && typeof exports == "object") {
|
|
505
|
+
var __cp = (to, from, except, desc) => {
|
|
506
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
507
|
+
for (let key of Object.getOwnPropertyNames(from)) {
|
|
508
|
+
if (!Object.prototype.hasOwnProperty.call(to, key) && key !== except)
|
|
509
|
+
Object.defineProperty(to, key, {
|
|
510
|
+
get: () => from[key],
|
|
511
|
+
enumerable: !(desc = Object.getOwnPropertyDescriptor(from, key)) || desc.enumerable,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return to;
|
|
516
|
+
};
|
|
517
|
+
module.exports = __cp(module.exports, exports);
|
|
518
|
+
}
|
|
519
|
+
return module.exports;
|
|
520
|
+
}))
|
|
521
|
+
//# sourceMappingURL=rrweb-plugin-console-record.umd.cjs.map
|