async-browser-context 0.2.4 → 0.3.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.
- package/CHANGELOG.md +94 -0
- package/README.md +45 -30
- package/dist/babel/async-generator-helpers.d.ts +6 -6
- package/dist/babel/async-generator-helpers.d.ts.map +1 -1
- package/dist/babel/async-generator-helpers.js +33 -22
- package/dist/babel/async-generator-helpers.js.map +1 -1
- package/dist/babel/async-generator-resources.d.ts +14 -0
- package/dist/babel/async-generator-resources.d.ts.map +1 -0
- package/dist/babel/async-generator-resources.js +38 -0
- package/dist/babel/async-generator-resources.js.map +1 -0
- package/dist/babel/bind-generators.d.ts +1 -1
- package/dist/babel/bind-generators.d.ts.map +1 -1
- package/dist/babel/bind-generators.js +88 -44
- package/dist/babel/bind-generators.js.map +1 -1
- package/dist/babel/name-coroutines.d.ts +14 -8
- package/dist/babel/name-coroutines.d.ts.map +1 -1
- package/dist/babel/name-coroutines.js +160 -39
- package/dist/babel/name-coroutines.js.map +1 -1
- package/dist/babel/preset.d.ts +24 -13
- package/dist/babel/preset.d.ts.map +1 -1
- package/dist/babel/preset.js +37 -9
- package/dist/babel/preset.js.map +1 -1
- package/dist/babel/runtime-calls.d.ts +22 -0
- package/dist/babel/runtime-calls.d.ts.map +1 -0
- package/dist/babel/runtime-calls.js +69 -0
- package/dist/babel/runtime-calls.js.map +1 -0
- package/dist/babel/skip-runtime.d.ts +18 -11
- package/dist/babel/skip-runtime.d.ts.map +1 -1
- package/dist/babel/skip-runtime.js +52 -16
- package/dist/babel/skip-runtime.js.map +1 -1
- package/dist/babel/static-members.d.ts +4 -0
- package/dist/babel/static-members.d.ts.map +1 -0
- package/dist/babel/static-members.js +112 -0
- package/dist/babel/static-members.js.map +1 -0
- package/dist/core/async-generator.d.ts +26 -8
- package/dist/core/async-generator.d.ts.map +1 -1
- package/dist/core/async-generator.js +162 -44
- package/dist/core/async-generator.js.map +1 -1
- package/dist/core/async-local-storage.d.ts +3 -0
- package/dist/core/async-local-storage.d.ts.map +1 -1
- package/dist/core/async-local-storage.js +3 -0
- package/dist/core/async-local-storage.js.map +1 -1
- package/dist/core/callback-hook.d.ts +3 -3
- package/dist/core/coroutine.d.ts +6 -2
- package/dist/core/coroutine.d.ts.map +1 -1
- package/dist/core/coroutine.js +35 -21
- package/dist/core/coroutine.js.map +1 -1
- package/dist/core/function-name.d.ts +9 -0
- package/dist/core/function-name.d.ts.map +1 -0
- package/dist/core/function-name.js +12 -0
- package/dist/core/function-name.js.map +1 -0
- package/dist/core/hooks.d.ts +2 -1
- package/dist/core/hooks.d.ts.map +1 -1
- package/dist/core/hooks.js +21 -6
- package/dist/core/hooks.js.map +1 -1
- package/dist/core/snapshot.d.ts +2 -1
- package/dist/core/snapshot.d.ts.map +1 -1
- package/dist/core/snapshot.js +7 -3
- package/dist/core/snapshot.js.map +1 -1
- package/dist/core/store.d.ts +28 -0
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/store.js +90 -20
- package/dist/core/store.js.map +1 -1
- package/dist/core/variable.d.ts +2 -1
- package/dist/core/variable.d.ts.map +1 -1
- package/dist/core/variable.js +5 -2
- package/dist/core/variable.js.map +1 -1
- package/dist/node/index.d.ts +10 -4
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +51 -16
- package/dist/node/index.js.map +1 -1
- package/dist/node/runtime.d.ts +7 -6
- package/dist/node/runtime.d.ts.map +1 -1
- package/dist/node/runtime.js +29 -16
- package/dist/node/runtime.js.map +1 -1
- package/dist/opentelemetry/context-manager.d.ts.map +1 -1
- package/dist/opentelemetry/context-manager.js +172 -13
- package/dist/opentelemetry/context-manager.js.map +1 -1
- package/dist/patches/callbacks.d.ts.map +1 -1
- package/dist/patches/callbacks.js +84 -29
- package/dist/patches/callbacks.js.map +1 -1
- package/dist/patches/events.d.ts.map +1 -1
- package/dist/patches/events.js +203 -91
- package/dist/patches/events.js.map +1 -1
- package/dist/patches/handler-interfaces.d.ts +4 -3
- package/dist/patches/handler-interfaces.d.ts.map +1 -1
- package/dist/patches/handler-interfaces.js +7 -5
- package/dist/patches/handler-interfaces.js.map +1 -1
- package/dist/patches/promise.d.ts +3 -0
- package/dist/patches/promise.d.ts.map +1 -1
- package/dist/patches/promise.js +13 -5
- package/dist/patches/promise.js.map +1 -1
- package/dist/patches/streams.d.ts.map +1 -1
- package/dist/patches/streams.js +36 -16
- package/dist/patches/streams.js.map +1 -1
- package/dist/patches/timers.d.ts.map +1 -1
- package/dist/patches/timers.js +17 -5
- package/dist/patches/timers.js.map +1 -1
- package/dist/patches/to-string.d.ts +4 -0
- package/dist/patches/to-string.d.ts.map +1 -1
- package/dist/patches/to-string.js +12 -6
- package/dist/patches/to-string.js.map +1 -1
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +3 -3
- package/dist/runtime.js.map +1 -1
- package/dist/vite/plugin.d.ts +7 -2
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/plugin.js +30 -6
- package/dist/vite/plugin.js.map +1 -1
- package/package.json +52 -25
- package/src/babel/async-generator-helpers.ts +34 -23
- package/src/babel/async-generator-resources.ts +40 -0
- package/src/babel/bind-generators.ts +91 -47
- package/src/babel/name-coroutines.ts +170 -41
- package/src/babel/preset.ts +47 -15
- package/src/babel/runtime-calls.ts +73 -0
- package/src/babel/skip-runtime.ts +58 -18
- package/src/babel/static-members.ts +117 -0
- package/src/core/async-generator.ts +169 -46
- package/src/core/async-local-storage.ts +3 -0
- package/src/core/callback-hook.ts +3 -3
- package/src/core/coroutine.ts +35 -21
- package/src/core/function-name.ts +11 -0
- package/src/core/hooks.ts +23 -6
- package/src/core/snapshot.ts +8 -3
- package/src/core/store.ts +107 -21
- package/src/core/variable.ts +6 -2
- package/src/node/index.ts +62 -19
- package/src/node/runtime.ts +33 -15
- package/src/opentelemetry/context-manager.ts +188 -13
- package/src/patches/callbacks.ts +87 -30
- package/src/patches/events.ts +249 -103
- package/src/patches/handler-interfaces.ts +7 -5
- package/src/patches/promise.ts +17 -13
- package/src/patches/streams.ts +36 -16
- package/src/patches/timers.ts +17 -5
- package/src/patches/to-string.ts +12 -6
- package/src/runtime.ts +3 -3
- package/src/vite/plugin.ts +38 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler-interfaces.js","sourceRoot":"","sources":["../../src/patches/handler-interfaces.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"handler-interfaces.js","sourceRoot":"","sources":["../../src/patches/handler-interfaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAuB;IAClD,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc;IAC7F,0BAA0B,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,6BAA6B;IAC/F,kBAAkB,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,mCAAmC;IACzG,4BAA4B,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa;IACjH,eAAe,EAAE,4BAA4B,EAAE,eAAe,EAAE,UAAU,EAAE,0BAA0B;IACtG,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW;IACrG,iBAAiB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,aAAa,EAAE,qBAAqB;IACjG,wBAAwB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,sBAAsB;IACnH,kBAAkB,EAAE,aAAa;IACjC,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,oBAAoB;IACzG,qBAAqB,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,eAAe;IAC5G,aAAa,EAAE,aAAa,EAAE,kBAAkB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|
+
* The patch starts the `then` that it replaces, as the other patches do. Thus a
|
|
13
|
+
* patch of `then` that another tool installed before stays in effect.
|
|
11
14
|
*/
|
|
12
15
|
export declare function installPromisePatch(): void;
|
|
13
16
|
//# sourceMappingURL=promise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../src/patches/promise.ts"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../src/patches/promise.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,IAAK,IAAI,CAkB3C"}
|
package/dist/patches/promise.js
CHANGED
|
@@ -10,15 +10,23 @@ import { claim, replaceFunction } from "./patch.js";
|
|
|
10
10
|
*
|
|
11
11
|
* `await` in native code does not use `then`. The Babel preset changes each
|
|
12
12
|
* `await` so that the coroutine sets the context (rule C3).
|
|
13
|
+
*
|
|
14
|
+
* The patch starts the `then` that it replaces, as the other patches do. Thus a
|
|
15
|
+
* patch of `then` that another tool installed before stays in effect.
|
|
13
16
|
*/
|
|
14
17
|
export function installPromisePatch() {
|
|
15
18
|
if (!claim("Promise.prototype.then")) {
|
|
16
19
|
return;
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
replaceFunction(Promise.prototype, "then", () =>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// Method syntax: a native method has no prototype property and is not a constructor
|
|
22
|
+
replaceFunction(Promise.prototype, "then", (original) => ({
|
|
23
|
+
then(onFulfilled, onRejected) {
|
|
24
|
+
const frame = store.current;
|
|
25
|
+
return Reflect.apply(original, this, [
|
|
26
|
+
typeof onFulfilled === "function" ? bindOneArgument(frame, onFulfilled, "Promise.then") : onFulfilled,
|
|
27
|
+
typeof onRejected === "function" ? bindOneArgument(frame, onRejected, "Promise.then") : onRejected,
|
|
28
|
+
]);
|
|
29
|
+
},
|
|
30
|
+
}).then);
|
|
23
31
|
}
|
|
24
32
|
//# sourceMappingURL=promise.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/patches/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpD
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/patches/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB;IAC/B,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,EAAE,CAAC;QACnC,OAAO;IACX,CAAC;IACD,oFAAoF;IACpF,eAAe,CAAO,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC5D,IAAI,CAEA,WAA2D,EAC3D,UAAiE;YAEjE,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;YAC5B,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE;gBACjC,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,WAAW;gBACrG,OAAO,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,UAAU;aACrG,CAAqB,CAAC;QAC3B,CAAC;KACJ,CAAC,CAAC,IAAY,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../../src/patches/streams.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../../src/patches/streams.ts"],"names":[],"mappings":"AAoEA,qDAAqD;AACrD,wBAAgB,oBAAoB,IAAK,IAAI,CA8B5C"}
|
package/dist/patches/streams.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyWithHooks, store } from "../core/store.js";
|
|
1
|
+
import { applyQuietly, applyWithHooks, store } from "../core/store.js";
|
|
2
2
|
import { claim, ownDataValue, rememberOriginal } from "./patch.js";
|
|
3
3
|
/**
|
|
4
4
|
* The stream constructors and the methods of the object that each constructor
|
|
@@ -11,36 +11,56 @@ const STREAMS = [
|
|
|
11
11
|
["TransformStream", ["start", "transform", "flush", "cancel"]],
|
|
12
12
|
];
|
|
13
13
|
/**
|
|
14
|
-
* This function gives
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* This function gives a view of `underlying` in which each method of `methods` is a wrapper.
|
|
15
|
+
* The view is a Proxy, so the other properties, for example `type`, come from `underlying`
|
|
16
|
+
* with their getters and private fields. The target of the Proxy is an empty object, so a
|
|
17
|
+
* frozen object also operates. The specification reads the members with [[Get]]. But the
|
|
18
|
+
* streams of WebKit first examine each member with the `in` operator, thus the `has` trap
|
|
19
|
+
* gives the answer of `underlying`. Each method gets `underlying` as its `this` value, as the
|
|
20
|
+
* specification tells.
|
|
18
21
|
*/
|
|
19
22
|
function wrapUnderlying(underlying, methods, frame, name) {
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// A method that a hook registers does not start the hooks
|
|
24
|
+
const quiet = store.inHook === true;
|
|
25
|
+
const wrappers = new Map();
|
|
26
|
+
const wrapperOf = (method, original) => {
|
|
27
|
+
let wrapper = wrappers.get(method);
|
|
28
|
+
if (wrapper !== undefined) {
|
|
29
|
+
return wrapper;
|
|
26
30
|
}
|
|
27
31
|
const source = `${name}.${method}`;
|
|
28
|
-
|
|
32
|
+
wrapper = function asyncBrowserContextWrapper() {
|
|
29
33
|
const previous = store.current;
|
|
30
34
|
store.current = frame;
|
|
31
35
|
try {
|
|
36
|
+
if (quiet) {
|
|
37
|
+
return applyQuietly(original, underlying, Array.prototype.slice.call(arguments));
|
|
38
|
+
}
|
|
32
39
|
const hooks = store.hooks;
|
|
33
40
|
if (hooks === undefined) {
|
|
34
|
-
return
|
|
41
|
+
return Reflect.apply(original, underlying, arguments);
|
|
35
42
|
}
|
|
36
|
-
return applyWithHooks(hooks, original, source, original, underlying,
|
|
43
|
+
return applyWithHooks(hooks, original, source, original, underlying, Array.prototype.slice.call(arguments));
|
|
37
44
|
}
|
|
38
45
|
finally {
|
|
39
46
|
store.current = previous;
|
|
40
47
|
}
|
|
41
48
|
};
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
wrappers.set(method, wrapper);
|
|
50
|
+
return wrapper;
|
|
51
|
+
};
|
|
52
|
+
return new Proxy({}, {
|
|
53
|
+
get(_target, property) {
|
|
54
|
+
const value = Reflect.get(underlying, property, underlying);
|
|
55
|
+
if (typeof property === "string" && typeof value === "function" && methods.includes(property)) {
|
|
56
|
+
return wrapperOf(property, value);
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
},
|
|
60
|
+
has(_target, property) {
|
|
61
|
+
return Reflect.has(underlying, property);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
44
64
|
}
|
|
45
65
|
/** This function patches the stream constructors. */
|
|
46
66
|
export function installStreamPatches() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streams.js","sourceRoot":"","sources":["../../src/patches/streams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAc,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"streams.js","sourceRoot":"","sources":["../../src/patches/streams.ts"],"names":[],"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,EAAG,KAAK,EAAE,CAAC,CAAC;YACjG,CAAC;QACL,CAAC;QACD,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,UAAU,EAAE,KAAK,EAAG,KAAK,EAAE,CAAC,CAAC;IAC9E,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timers.d.ts","sourceRoot":"","sources":["../../src/patches/timers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"timers.d.ts","sourceRoot":"","sources":["../../src/patches/timers.ts"],"names":[],"mappings":"AA+CA;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAK,IAAI,CAe3C"}
|
package/dist/patches/timers.js
CHANGED
|
@@ -20,12 +20,24 @@ const PROTOTYPE_SCHEDULERS = [
|
|
|
20
20
|
["XRSession", "requestAnimationFrame"],
|
|
21
21
|
];
|
|
22
22
|
// Stryker restore all
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* `source` is the name of the scheduler, for the callback hooks. The replacement is a method,
|
|
25
|
+
* so it has no prototype property and is not a constructor, as the native function. It gives
|
|
26
|
+
* the native function the same number of arguments, so `setTimeout()` without arguments
|
|
27
|
+
* throws as the native function does.
|
|
28
|
+
*/
|
|
24
29
|
function wrapFirstArgument(source) {
|
|
25
|
-
return (original) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
return (original) => ({
|
|
31
|
+
scheduler(callback) {
|
|
32
|
+
if (typeof callback !== "function") {
|
|
33
|
+
// A string callback of setTimeout, or no callback: the native function decides
|
|
34
|
+
return Reflect.apply(original, this, arguments);
|
|
35
|
+
}
|
|
36
|
+
const args = Array.prototype.slice.call(arguments);
|
|
37
|
+
args[0] = bindToFrame(store.current, callback, source);
|
|
38
|
+
return Reflect.apply(original, this, args);
|
|
39
|
+
},
|
|
40
|
+
}).scheduler;
|
|
29
41
|
}
|
|
30
42
|
/**
|
|
31
43
|
* This function patches the timers and the other schedulers. The callback
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timers.js","sourceRoot":"","sources":["../../src/patches/timers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIrE,yFAAyF;AACzF,MAAM,iBAAiB,GAAG;IACtB,YAAY;IACZ,aAAa;IACb,cAAc;IACd,gBAAgB;IAChB,uBAAuB;IACvB,qBAAqB;CACf,CAAC;AAEX;;;GAGG;AACH,6EAA6E;AAC7E,MAAM,oBAAoB,GAA4C;IAClE,CAAC,WAAW,EAAE,UAAU,CAAC;IACzB,CAAC,kBAAkB,EAAE,2BAA2B,CAAC;IACjD,CAAC,WAAW,EAAE,uBAAuB,CAAC;CACzC,CAAC;AACF,sBAAsB;AAEtB
|
|
1
|
+
{"version":3,"file":"timers.js","sourceRoot":"","sources":["../../src/patches/timers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIrE,yFAAyF;AACzF,MAAM,iBAAiB,GAAG;IACtB,YAAY;IACZ,aAAa;IACb,cAAc;IACd,gBAAgB;IAChB,uBAAuB;IACvB,qBAAqB;CACf,CAAC;AAEX;;;GAGG;AACH,6EAA6E;AAC7E,MAAM,oBAAoB,GAA4C;IAClE,CAAC,WAAW,EAAE,UAAU,CAAC;IACzB,CAAC,kBAAkB,EAAE,2BAA2B,CAAC;IACjD,CAAC,WAAW,EAAE,uBAAuB,CAAC;CACzC,CAAC;AACF,sBAAsB;AAEtB;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,MAAe;IACtC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAClB,SAAS,CAAiB,QAAkB;YACxC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;gBACjC,+EAA+E;gBAC/E,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAc,CAAC;YAChE,IAAI,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,QAA8C,EAAE,MAAM,CAAC,CAAC;YAC7F,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/C,CAAC;KACJ,CAAC,CAAC,SAAS,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IAC/B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnB,OAAO;IACX,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;QACnC,eAAe,CAAY,UAAU,EAAE,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;IACD,0FAA0F;IAC1F,KAAK,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,oBAAoB,EAAE,CAAC;QAC3D,MAAM,SAAS,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;QACnD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1B,eAAe,CAAY,SAAS,EAAE,MAAM,EAAE,iBAAiB,CAAC,GAAG,eAAe,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC;QACrG,CAAC;IACL,CAAC;IACD,sBAAsB;AAC1B,CAAC"}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* This function patches `Function.prototype.toString`. For a patched function, the patch gives
|
|
3
3
|
* the source text of the original function. Some libraries examine this text
|
|
4
4
|
* to find native functions, and a changed text can stop them.
|
|
5
|
+
*
|
|
6
|
+
* The patch starts the `toString` that it replaces, as the other patches do. Thus a patch of
|
|
7
|
+
* `toString` that another tool installed before, for example to show the source of its own
|
|
8
|
+
* wrappers, stays in effect.
|
|
5
9
|
*/
|
|
6
10
|
export declare function installToStringPatch(): void;
|
|
7
11
|
//# sourceMappingURL=to-string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-string.d.ts","sourceRoot":"","sources":["../../src/patches/to-string.ts"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"to-string.d.ts","sourceRoot":"","sources":["../../src/patches/to-string.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,IAAK,IAAI,CAY5C"}
|
|
@@ -4,16 +4,22 @@ import { claim, replaceFunction } from "./patch.js";
|
|
|
4
4
|
* This function patches `Function.prototype.toString`. For a patched function, the patch gives
|
|
5
5
|
* the source text of the original function. Some libraries examine this text
|
|
6
6
|
* to find native functions, and a changed text can stop them.
|
|
7
|
+
*
|
|
8
|
+
* The patch starts the `toString` that it replaces, as the other patches do. Thus a patch of
|
|
9
|
+
* `toString` that another tool installed before, for example to show the source of its own
|
|
10
|
+
* wrappers, stays in effect.
|
|
7
11
|
*/
|
|
8
12
|
export function installToStringPatch() {
|
|
9
13
|
if (!claim("Function.prototype.toString")) {
|
|
10
14
|
return;
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
replaceFunction(Function.prototype, "toString", () =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// Method syntax: a native method has no prototype property and is not a constructor
|
|
17
|
+
replaceFunction(Function.prototype, "toString", (replaced) => ({
|
|
18
|
+
toString() {
|
|
19
|
+
// WeakMap.get gives undefined for a primitive. The native function then throws its TypeError.
|
|
20
|
+
const original = store.originals.get(this);
|
|
21
|
+
return Reflect.apply(replaced, original ?? this, []);
|
|
22
|
+
},
|
|
23
|
+
}).toString);
|
|
18
24
|
}
|
|
19
25
|
//# sourceMappingURL=to-string.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-string.js","sourceRoot":"","sources":["../../src/patches/to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpD
|
|
1
|
+
{"version":3,"file":"to-string.js","sourceRoot":"","sources":["../../src/patches/to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpD;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB;IAChC,IAAI,CAAC,KAAK,CAAC,6BAA6B,CAAC,EAAE,CAAC;QACxC,OAAO;IACX,CAAC;IACD,oFAAoF;IACpF,eAAe,CAAW,QAAQ,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACrE,QAAQ;YACJ,8FAA8F;YAC9F,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAc,CAAC,CAAC;YACrD,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;QACzD,CAAC;KACJ,CAAC,CAAC,QAAQ,CAAC,CAAC;AACjB,CAAC"}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The runtime of the code that the Babel preset transforms. The transformed
|
|
3
|
-
* code imports `coroutine`, `bindGenerator`, `asyncGenerator`
|
|
4
|
-
* `
|
|
3
|
+
* code imports `coroutine`, `bindGenerator`, `asyncGenerator`, `OverloadYield`,
|
|
4
|
+
* `awaitAsyncGenerator` and `asyncGeneratorDelegate` from this module. When the
|
|
5
5
|
* module loads, it installs the patches of the runtime.
|
|
6
6
|
*
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
import "./install.js";
|
|
10
|
-
export { OverloadYield } from "./core/async-generator.js";
|
|
10
|
+
export { asyncGeneratorDelegate, awaitAsyncGenerator, OverloadYield } from "./core/async-generator.js";
|
|
11
11
|
export { asyncGenerator, bindGenerator, coroutine } from "./core/coroutine.js";
|
|
12
12
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The runtime of the code that the Babel preset transforms. The transformed
|
|
3
|
-
* code imports `coroutine`, `bindGenerator`, `asyncGenerator`
|
|
4
|
-
* `
|
|
3
|
+
* code imports `coroutine`, `bindGenerator`, `asyncGenerator`, `OverloadYield`,
|
|
4
|
+
* `awaitAsyncGenerator` and `asyncGeneratorDelegate` from this module. When the
|
|
5
5
|
* module loads, it installs the patches of the runtime.
|
|
6
6
|
*
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
9
|
import "./install.js";
|
|
10
|
-
export { OverloadYield } from "./core/async-generator.js";
|
|
10
|
+
export { asyncGeneratorDelegate, awaitAsyncGenerator, OverloadYield } from "./core/async-generator.js";
|
|
11
11
|
export { asyncGenerator, bindGenerator, coroutine } from "./core/coroutine.js";
|
|
12
12
|
//# sourceMappingURL=runtime.js.map
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACvG,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -5,12 +5,17 @@ export type ModuleFilter = RegExp | ((id: string) => boolean);
|
|
|
5
5
|
export interface AsyncContextPluginOptions {
|
|
6
6
|
/**
|
|
7
7
|
* The modules to transform. The default is all JavaScript and TypeScript
|
|
8
|
-
* modules, also the modules in `node_modules
|
|
8
|
+
* modules, also the modules in `node_modules`, and the JavaScript of Vue,
|
|
9
|
+
* Svelte, Astro and MDX components. This filter can only select from these
|
|
10
|
+
* modules: the plugin does not transform styles.
|
|
9
11
|
*/
|
|
10
12
|
readonly include?: ModuleFilter | undefined;
|
|
11
13
|
/** The modules not to transform. */
|
|
12
14
|
readonly exclude?: ModuleFilter | undefined;
|
|
13
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The runtime module. It must export the six names of `async-browser-context/runtime`.
|
|
17
|
+
* The default is `async-browser-context/runtime`.
|
|
18
|
+
*/
|
|
14
19
|
readonly runtime?: string | undefined;
|
|
15
20
|
/**
|
|
16
21
|
* Give the name of each async function to the callback hooks. The default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,mEAAmE;AACnE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,EAAG,MAAM,KAAK,OAAO,CAAC,CAAC;AAE/D,sCAAsC;AACtC,MAAM,WAAW,yBAAyB;IACtC
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,mEAAmE;AACnE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,EAAG,MAAM,KAAK,OAAO,CAAC,CAAC;AAE/D,sCAAsC;AACtC,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAG,YAAY,GAAG,SAAS,CAAC;IAC7C,oCAAoC;IACpC,QAAQ,CAAC,OAAO,CAAC,EAAG,YAAY,GAAG,SAAS,CAAC;IAC7C;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAG,MAAM,GAAG,SAAS,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAG,OAAO,GAAG,SAAS,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAG,OAAO,GAAG,SAAS,CAAC;CACvC;AA8BD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAG,yBAA8B,GAAI,MAAM,CAmD9E"}
|
package/dist/vite/plugin.js
CHANGED
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import { transformAsync } from "@babel/core";
|
|
2
2
|
import preset, { DEFAULT_RUNTIME, METADATA_KEY } from "../babel/preset.js";
|
|
3
3
|
const SCRIPT = /\.[cm]?[jt]sx?$/;
|
|
4
|
+
/** The component files that other Vite plugins compile to JavaScript before this plugin operates. */
|
|
5
|
+
const COMPONENT = /\.(?:vue|svelte|astro|mdx)$/;
|
|
6
|
+
/** The parts of a component that are styles, not JavaScript, for example `App.vue?vue&type=style&lang.css`. */
|
|
7
|
+
const STYLE_QUERY = /[?&](?:type=style|lang\.(?:css|scss|sass|less|styl|stylus|pcss|postcss|sss))(?:&|$)/;
|
|
4
8
|
/** A module without these words has no async function, generator or `for await`. */
|
|
5
9
|
const MIGHT_CHANGE = /\basync\b|\byield\b|function\s*\*/;
|
|
6
10
|
/** The runtime of this library. The plugin must not transform it. */
|
|
7
11
|
const OWN_RUNTIME = /[\\/]async-browser-context[\\/]dist[\\/]/;
|
|
12
|
+
/** The marks of a CommonJS module. */
|
|
13
|
+
const COMMONJS = /\brequire\s*\(|\bmodule\.exports\b|\bexports\.[A-Za-z_$]/;
|
|
8
14
|
function matches(filter, id) {
|
|
9
15
|
return filter instanceof RegExp ? filter.test(id) : filter(id);
|
|
10
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* This function gives the source type for Babel. Vite serves each module as an ES module, also
|
|
19
|
+
* a worker or a file with only a dynamic `import()`. With "unambiguous", Babel reads such a file
|
|
20
|
+
* as a script and adds a `require()` of the runtime, which a browser does not have. Thus only a
|
|
21
|
+
* `.cjs` or `.cts` file, or a file with CommonJS marks, gets "unambiguous". Babel then reads it
|
|
22
|
+
* as a script, unless it has a static import or export. A text of the code that looks like an
|
|
23
|
+
* import, for example in a string, does not change this.
|
|
24
|
+
*/
|
|
25
|
+
function sourceTypeOf(file, code) {
|
|
26
|
+
return /\.c[jt]s$/.test(file) || COMMONJS.test(code) ? "unambiguous" : "module";
|
|
27
|
+
}
|
|
11
28
|
/**
|
|
12
29
|
* The Vite plugin of `async-browser-context`. It applies the Babel preset to
|
|
13
30
|
* the modules of the application and of its dependencies. Thus, the context
|
|
@@ -27,6 +44,8 @@ function matches(filter, id) {
|
|
|
27
44
|
*/
|
|
28
45
|
export function asyncContext(options = {}) {
|
|
29
46
|
const runtime = options.runtime ?? DEFAULT_RUNTIME;
|
|
47
|
+
// One presets array for all modules, so the configuration cache of Babel operates
|
|
48
|
+
const presets = [[preset, { runtime, names: options.names }]];
|
|
30
49
|
return {
|
|
31
50
|
name: "async-browser-context",
|
|
32
51
|
enforce: "post",
|
|
@@ -40,7 +59,7 @@ export function asyncContext(options = {}) {
|
|
|
40
59
|
return null;
|
|
41
60
|
}
|
|
42
61
|
const file = id.split("?", 1)[0] ?? id;
|
|
43
|
-
if (!SCRIPT.test(file) || OWN_RUNTIME.test(file)) {
|
|
62
|
+
if (!(SCRIPT.test(file) || COMPONENT.test(file)) || STYLE_QUERY.test(id) || OWN_RUNTIME.test(file)) {
|
|
44
63
|
return null;
|
|
45
64
|
}
|
|
46
65
|
if (options.include !== undefined && !matches(options.include, file)) {
|
|
@@ -56,16 +75,21 @@ export function asyncContext(options = {}) {
|
|
|
56
75
|
filename: file,
|
|
57
76
|
babelrc: false,
|
|
58
77
|
configFile: false,
|
|
59
|
-
sourceType:
|
|
78
|
+
sourceType: sourceTypeOf(file, code),
|
|
60
79
|
sourceMaps: true,
|
|
61
|
-
|
|
80
|
+
// The map of Vite describes the code that this plugin gets, not a map file of the module
|
|
81
|
+
inputSourceMap: false,
|
|
82
|
+
// Large modules, for example the dependency bundles of Vite, keep their format
|
|
83
|
+
compact: false,
|
|
84
|
+
presets,
|
|
62
85
|
});
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
// Without the options ignore and only, Babel gives a result with code. With sourceMaps, it also gives a map.
|
|
87
|
+
const { code: output, map, metadata } = result;
|
|
88
|
+
if (metadata[METADATA_KEY] !== true) {
|
|
65
89
|
return null;
|
|
66
90
|
}
|
|
67
91
|
// A source map in JSON text satisfies both Rollup and Rolldown
|
|
68
|
-
return { code:
|
|
92
|
+
return { code: output, map: JSON.stringify(map) };
|
|
69
93
|
},
|
|
70
94
|
},
|
|
71
95
|
};
|
package/dist/vite/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,MAAM,EAAE,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,MAAM,EAAE,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAkC3E,MAAM,MAAM,GAAG,iBAAiB,CAAC;AACjC,qGAAqG;AACrG,MAAM,SAAS,GAAG,6BAA6B,CAAC;AAChD,+GAA+G;AAC/G,MAAM,WAAW,GAAG,qFAAqF,CAAC;AAC1G,oFAAoF;AACpF,MAAM,YAAY,GAAG,mCAAmC,CAAC;AACzD,qEAAqE;AACrE,MAAM,WAAW,GAAG,0CAA0C,CAAC;AAC/D,sCAAsC;AACtC,MAAM,QAAQ,GAAG,0DAA0D,CAAC;AAE5E,SAAS,OAAO,CAAC,MAAqB,EAAE,EAAW;IAC/C,OAAO,MAAM,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,IAAa,EAAE,IAAa;IAC9C,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,C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AAC;gBAChB,CAAC;gBACD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;oBAClE,OAAO,IAAI,CAAC;gBAChB,CAAC;gBACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC3B,OAAO,IAAI,CAAC;gBAChB,CAAC;gBACD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE;oBACtC,QAAQ,EAAG,IAAI;oBACf,OAAO,EAAG,KAAK;oBACf,UAAU,EAAG,KAAK;oBAClB,UAAU,EAAG,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC;oBACrC,UAAU,EAAG,IAAI;oBACjB,yFAAyF;oBACzF,cAAc,EAAG,KAAK;oBACtB,+EAA+E;oBAC/E,OAAO,EAAG,KAAK;oBACf,OAAO;iBACV,CAAC,CAAC;gBACH,6GAA6G;gBAC7G,MAAM,EAAE,IAAI,EAAG,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,MAA6E,CAAC;gBACvH,IAAI,QAAQ,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE,CAAC;oBAClC,OAAO,IAAI,CAAC;gBAChB,CAAC;gBACD,+DAA+D;gBAC/D,OAAO,EAAE,IAAI,EAAG,MAAM,EAAE,GAAG,EAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACxD,CAAC;SACJ;KACJ,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "async-browser-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "AsyncLocalStorage and the TC39 AsyncContext API (Variable, Snapshot) for browsers. The context stays through await, promises, timers, events and generators. A Babel preset and a Vite plugin transform async functions. On Node.js, the package uses the native AsyncLocalStorage.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Mark Russell",
|
|
@@ -54,6 +54,30 @@
|
|
|
54
54
|
"./src/install.ts",
|
|
55
55
|
"./src/patches/*.ts"
|
|
56
56
|
],
|
|
57
|
+
"main": "./dist/index.js",
|
|
58
|
+
"types": "./dist/index.d.ts",
|
|
59
|
+
"typesVersions": {
|
|
60
|
+
"*": {
|
|
61
|
+
"browser": [
|
|
62
|
+
"./dist/index.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"browser/runtime": [
|
|
65
|
+
"./dist/runtime.d.ts"
|
|
66
|
+
],
|
|
67
|
+
"runtime": [
|
|
68
|
+
"./dist/runtime.d.ts"
|
|
69
|
+
],
|
|
70
|
+
"opentelemetry": [
|
|
71
|
+
"./dist/opentelemetry.d.ts"
|
|
72
|
+
],
|
|
73
|
+
"babel-preset": [
|
|
74
|
+
"./dist/babel/preset.d.ts"
|
|
75
|
+
],
|
|
76
|
+
"vite": [
|
|
77
|
+
"./dist/vite/plugin.d.ts"
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
57
81
|
"exports": {
|
|
58
82
|
".": {
|
|
59
83
|
"types": "./dist/index.d.ts",
|
|
@@ -101,33 +125,12 @@
|
|
|
101
125
|
"engines": {
|
|
102
126
|
"node": "^22.18.0 || >=24.11.0"
|
|
103
127
|
},
|
|
104
|
-
"packageManager": "pnpm@10.26.0",
|
|
105
|
-
"scripts": {
|
|
106
|
-
"build": "tsc -p tsconfig.build.json",
|
|
107
|
-
"typecheck": "tsc -p tsconfig.json",
|
|
108
|
-
"test": "vitest run",
|
|
109
|
-
"test:node": "vitest run --project unit --project \"rules (browser runtime, Node.js)\" --project \"rules (browser runtime, SWC ES2016)\" --project \"rules (browser runtime, esbuild ES2016)\" --project \"rules (node runtime)\" --project \"rules (node runtime, no transform)\"",
|
|
110
|
-
"test:browser": "vitest run --project \"browser (chromium)\" --project \"browser (firefox)\" --project \"browser (webkit)\"",
|
|
111
|
-
"coverage": "vitest run --coverage --project unit --project \"rules (browser runtime, Node.js)\" --project \"rules (node runtime)\"",
|
|
112
|
-
"mutation": "stryker run",
|
|
113
|
-
"bench": "pnpm build && tsx bench/run.ts",
|
|
114
|
-
"smoke": "pnpm build && tsx test/smoke/run.ts",
|
|
115
|
-
"test:babel": "pnpm build && tsx test/babel/run.ts",
|
|
116
|
-
"lint:ste": "tsx tools/ste-lint/src/cli.ts",
|
|
117
|
-
"site:dev": "pnpm --filter ./site dev",
|
|
118
|
-
"site:build": "pnpm --filter ./site build",
|
|
119
|
-
"prepublishOnly": "pnpm build && pnpm test",
|
|
120
|
-
"site:data": "tsx scripts/site-data.ts",
|
|
121
|
-
"readme:media": "tsx scripts/readme-media.ts",
|
|
122
|
-
"test:bundlers": "pnpm build && tsx test/bundlers/run.ts",
|
|
123
|
-
"bench:size": "tsx bench/size.ts",
|
|
124
|
-
"bench:browsers": "tsx bench/browsers.ts"
|
|
125
|
-
},
|
|
126
128
|
"dependencies": {
|
|
127
129
|
"@babel/core": "^8.0.7",
|
|
128
130
|
"@babel/helper-module-imports": "^8.0.0",
|
|
129
131
|
"@babel/plugin-transform-async-generator-functions": "^8.0.6",
|
|
130
|
-
"@babel/plugin-transform-async-to-generator": "^8.0.1"
|
|
132
|
+
"@babel/plugin-transform-async-to-generator": "^8.0.1",
|
|
133
|
+
"@babel/plugin-transform-explicit-resource-management": "^8.0.5"
|
|
131
134
|
},
|
|
132
135
|
"peerDependencies": {
|
|
133
136
|
"@opentelemetry/api": "^1.0.0",
|
|
@@ -142,6 +145,7 @@
|
|
|
142
145
|
}
|
|
143
146
|
},
|
|
144
147
|
"devDependencies": {
|
|
148
|
+
"@mark1russell7/rigor-generators": "^0.1.8",
|
|
145
149
|
"@opentelemetry/api": "^1.9.1",
|
|
146
150
|
"@stryker-mutator/core": "^10.0.0",
|
|
147
151
|
"@swc/core": "^1.16.18",
|
|
@@ -156,5 +160,28 @@
|
|
|
156
160
|
"typescript": "^5.9.3",
|
|
157
161
|
"vite": "^8.3.4",
|
|
158
162
|
"vitest": "^5.0.3"
|
|
163
|
+
},
|
|
164
|
+
"scripts": {
|
|
165
|
+
"build": "tsc -p tsconfig.build.json",
|
|
166
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
167
|
+
"test": "vitest run",
|
|
168
|
+
"test:node": "vitest run --project unit --project \"rules (browser runtime, Node.js)\" --project \"rules (browser runtime, SWC ES2016)\" --project \"rules (browser runtime, esbuild ES2016)\" --project \"rules (node runtime)\" --project \"rules (node runtime, no transform)\"",
|
|
169
|
+
"test:browser": "vitest run --project \"browser (chromium)\" --project \"browser (firefox)\" --project \"browser (webkit)\"",
|
|
170
|
+
"coverage": "vitest run --coverage --project unit --project \"rules (browser runtime, Node.js)\" --project \"rules (node runtime)\"",
|
|
171
|
+
"mutation": "stryker run",
|
|
172
|
+
"bench": "tsx bench/run.ts",
|
|
173
|
+
"smoke": "pnpm build && tsx test/smoke/run.ts",
|
|
174
|
+
"test:babel": "pnpm build && tsx test/babel/run.ts",
|
|
175
|
+
"lint:ste": "tsx tools/ste-lint/src/cli.ts --max-warnings 0",
|
|
176
|
+
"test:ste-lint": "vitest run --config tools/ste-lint/vitest.config.ts",
|
|
177
|
+
"site:dev": "pnpm --filter ./site dev",
|
|
178
|
+
"site:build": "pnpm --filter ./site build",
|
|
179
|
+
"site:data": "tsx scripts/site-data.ts",
|
|
180
|
+
"site:stamps": "tsx scripts/data-stamps.ts",
|
|
181
|
+
"mutation:run": "tsx scripts/mutation-run.ts",
|
|
182
|
+
"readme:media": "tsx scripts/readme-media.ts",
|
|
183
|
+
"test:bundlers": "pnpm build && tsx test/bundlers/run.ts",
|
|
184
|
+
"bench:size": "tsx bench/size.ts",
|
|
185
|
+
"bench:browsers": "tsx bench/browsers.ts"
|
|
159
186
|
}
|
|
160
|
-
}
|
|
187
|
+
}
|