@modern-js/plugin 1.3.8 → 1.4.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 +6 -0
- package/dist/js/modern/farrow-pipeline/context.js +14 -75
- package/dist/js/modern/farrow-pipeline/index.js +0 -14
- package/dist/js/modern/farrow-pipeline/pipeline.js +12 -29
- package/dist/js/modern/manager/async.js +8 -12
- package/dist/js/modern/manager/index.js +0 -1
- package/dist/js/modern/manager/sync.js +13 -19
- package/dist/js/modern/waterfall/async.js +1 -3
- package/dist/js/modern/waterfall/sync.js +1 -3
- package/dist/js/modern/workflow/async.js +3 -3
- package/dist/js/modern/workflow/parallel.js +2 -2
- package/dist/js/modern/workflow/sync.js +3 -3
- package/dist/js/node/farrow-pipeline/context.js +15 -88
- package/dist/js/node/farrow-pipeline/pipeline.js +10 -45
- package/dist/js/node/manager/async.js +10 -16
- package/dist/js/node/manager/index.js +0 -13
- package/dist/js/node/manager/sync.js +16 -23
- package/dist/js/node/waterfall/async.js +0 -2
- package/dist/js/node/waterfall/sync.js +0 -2
- package/dist/js/node/workflow/async.js +3 -3
- package/dist/js/node/workflow/parallel.js +2 -2
- package/dist/js/node/workflow/sync.js +3 -3
- package/dist/js/treeshaking/farrow-pipeline/context.js +14 -75
- package/dist/js/treeshaking/farrow-pipeline/index.js +0 -14
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +10 -29
- package/dist/js/treeshaking/manager/async.js +15 -17
- package/dist/js/treeshaking/manager/index.js +0 -1
- package/dist/js/treeshaking/manager/sync.js +16 -20
- package/dist/js/treeshaking/waterfall/async.js +1 -3
- package/dist/js/treeshaking/waterfall/sync.js +1 -3
- package/dist/js/treeshaking/workflow/async.js +6 -6
- package/dist/js/treeshaking/workflow/parallel.js +5 -5
- package/dist/js/treeshaking/workflow/sync.js +3 -3
- package/dist/types/farrow-pipeline/context.d.ts +5 -20
- package/dist/types/farrow-pipeline/index.d.ts +0 -14
- package/dist/types/farrow-pipeline/pipeline.d.ts +5 -14
- package/dist/types/manager/async.d.ts +4 -7
- package/dist/types/manager/index.d.ts +0 -1
- package/dist/types/manager/sync.d.ts +6 -10
- package/dist/types/manager/types.d.ts +1 -6
- package/dist/types/waterfall/async.d.ts +1 -7
- package/dist/types/waterfall/sync.d.ts +0 -7
- package/dist/types/workflow/async.d.ts +1 -7
- package/dist/types/workflow/parallel.d.ts +2 -9
- package/dist/types/workflow/sync.d.ts +1 -10
- package/package.json +1 -12
- package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +0 -80
- package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +0 -12
- package/dist/js/modern/farrow-pipeline/hook.js +0 -42
- package/dist/js/modern/manager/runner.js +0 -11
- package/dist/js/node/farrow-pipeline/asyncHooks.node.js +0 -100
- package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +0 -26
- package/dist/js/node/farrow-pipeline/hook.js +0 -52
- package/dist/js/node/manager/runner.js +0 -23
- package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +0 -80
- package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +0 -12
- package/dist/js/treeshaking/farrow-pipeline/hook.js +0 -46
- package/dist/js/treeshaking/manager/runner.js +0 -11
- package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +0 -2
- package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +0 -19
- package/dist/types/farrow-pipeline/hook.d.ts +0 -9
- package/dist/types/manager/runner.d.ts +0 -3
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.4.1",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -25,17 +25,6 @@
|
|
25
25
|
"require": "./dist/js/node/index.js"
|
26
26
|
},
|
27
27
|
"default": "./dist/js/treeshaking/index.js"
|
28
|
-
},
|
29
|
-
"./node": {
|
30
|
-
"jsnext:source": "./src/farrow-pipeline/asyncHooks.node.ts",
|
31
|
-
"default": "./dist/js/node/farrow-pipeline/asyncHooks.node.js"
|
32
|
-
}
|
33
|
-
},
|
34
|
-
"typesVersions": {
|
35
|
-
"*": {
|
36
|
-
"node": [
|
37
|
-
"./dist/types/farrow-pipeline/asyncHooks.node.d.ts"
|
38
|
-
]
|
39
28
|
}
|
40
29
|
},
|
41
30
|
"dependencies": {
|
@@ -1,80 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
import NodeAsyncHooks from 'async_hooks';
|
6
|
-
import * as asyncHooksInterface from "./asyncHooksInterface";
|
7
|
-
|
8
|
-
const createAsyncHooks = () => {
|
9
|
-
const store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
|
10
|
-
|
11
|
-
const hooks = NodeAsyncHooks.createHook({
|
12
|
-
init: (asyncId, _, triggerAsyncId) => {
|
13
|
-
if (store.has(triggerAsyncId)) {
|
14
|
-
const value = store.get(triggerAsyncId);
|
15
|
-
|
16
|
-
if (value) {
|
17
|
-
store.set(asyncId, value);
|
18
|
-
}
|
19
|
-
}
|
20
|
-
},
|
21
|
-
destroy: asyncId => {
|
22
|
-
if (store.has(asyncId)) {
|
23
|
-
store.delete(asyncId);
|
24
|
-
}
|
25
|
-
}
|
26
|
-
});
|
27
|
-
|
28
|
-
const set = value => {
|
29
|
-
store.set(NodeAsyncHooks.executionAsyncId(), value);
|
30
|
-
};
|
31
|
-
|
32
|
-
const get = () => {
|
33
|
-
return store.get(NodeAsyncHooks.executionAsyncId());
|
34
|
-
};
|
35
|
-
|
36
|
-
const clear = () => {
|
37
|
-
store.clear();
|
38
|
-
};
|
39
|
-
|
40
|
-
const enable = () => {
|
41
|
-
hooks.enable();
|
42
|
-
};
|
43
|
-
|
44
|
-
const disable = () => {
|
45
|
-
hooks.disable();
|
46
|
-
store.clear();
|
47
|
-
};
|
48
|
-
|
49
|
-
const entries = () => {
|
50
|
-
return store.entries();
|
51
|
-
};
|
52
|
-
|
53
|
-
return {
|
54
|
-
enable,
|
55
|
-
disable,
|
56
|
-
set,
|
57
|
-
get,
|
58
|
-
clear,
|
59
|
-
entries
|
60
|
-
};
|
61
|
-
};
|
62
|
-
|
63
|
-
let enabled = false;
|
64
|
-
export const enable = () => {
|
65
|
-
if (enabled) {
|
66
|
-
return;
|
67
|
-
}
|
68
|
-
|
69
|
-
enabled = true;
|
70
|
-
const hooks = createAsyncHooks();
|
71
|
-
asyncHooksInterface.impl(hooks);
|
72
|
-
hooks.enable();
|
73
|
-
};
|
74
|
-
export const disable = () => {
|
75
|
-
var _asyncHooksInterface$;
|
76
|
-
|
77
|
-
enabled = false;
|
78
|
-
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
79
|
-
asyncHooksInterface.reset();
|
80
|
-
};
|
@@ -1,12 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
// eslint-disable-next-line import/no-mutable-exports
|
6
|
-
export let asyncHooks;
|
7
|
-
export const impl = implimentations => {
|
8
|
-
asyncHooks = implimentations;
|
9
|
-
};
|
10
|
-
export const reset = () => {
|
11
|
-
asyncHooks = undefined;
|
12
|
-
};
|
@@ -1,42 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
import { asyncHooks } from "./asyncHooksInterface";
|
6
|
-
export const createHooks = defaultHooks => {
|
7
|
-
let currentHooks = {};
|
8
|
-
const hooks = {};
|
9
|
-
|
10
|
-
for (const key in defaultHooks) {
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
12
|
-
const f = (...args) => {
|
13
|
-
var _asyncHooks$get;
|
14
|
-
|
15
|
-
const hooks = currentHooks === defaultHooks ? (_asyncHooks$get = asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
|
16
|
-
let handler = hooks[key];
|
17
|
-
|
18
|
-
if (typeof handler !== 'function') {
|
19
|
-
handler = defaultHooks[key];
|
20
|
-
}
|
21
|
-
|
22
|
-
return handler(...args);
|
23
|
-
};
|
24
|
-
|
25
|
-
hooks[key] = f;
|
26
|
-
}
|
27
|
-
|
28
|
-
const run = (f, implementations) => {
|
29
|
-
try {
|
30
|
-
currentHooks = implementations || defaultHooks;
|
31
|
-
asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.set(currentHooks);
|
32
|
-
return f();
|
33
|
-
} finally {
|
34
|
-
currentHooks = defaultHooks;
|
35
|
-
}
|
36
|
-
};
|
37
|
-
|
38
|
-
return {
|
39
|
-
run,
|
40
|
-
hooks
|
41
|
-
};
|
42
|
-
};
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import { createContext } from "../farrow-pipeline";
|
2
|
-
export const RunnerContext = createContext(null);
|
3
|
-
export const useRunner = () => {
|
4
|
-
const runner = RunnerContext.use().value;
|
5
|
-
|
6
|
-
if (!runner) {
|
7
|
-
throw new Error(`Can't call useRunner out of scope, it should be placed in hooks of plugin`);
|
8
|
-
}
|
9
|
-
|
10
|
-
return runner;
|
11
|
-
};
|
@@ -1,100 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.enable = exports.disable = void 0;
|
7
|
-
|
8
|
-
var _async_hooks = _interopRequireDefault(require("async_hooks"));
|
9
|
-
|
10
|
-
var asyncHooksInterface = _interopRequireWildcard(require("./asyncHooksInterface"));
|
11
|
-
|
12
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
13
|
-
|
14
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15
|
-
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
-
|
18
|
-
/**
|
19
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
20
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
21
|
-
*/
|
22
|
-
const createAsyncHooks = () => {
|
23
|
-
const store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
|
24
|
-
|
25
|
-
const hooks = _async_hooks.default.createHook({
|
26
|
-
init: (asyncId, _, triggerAsyncId) => {
|
27
|
-
if (store.has(triggerAsyncId)) {
|
28
|
-
const value = store.get(triggerAsyncId);
|
29
|
-
|
30
|
-
if (value) {
|
31
|
-
store.set(asyncId, value);
|
32
|
-
}
|
33
|
-
}
|
34
|
-
},
|
35
|
-
destroy: asyncId => {
|
36
|
-
if (store.has(asyncId)) {
|
37
|
-
store.delete(asyncId);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
});
|
41
|
-
|
42
|
-
const set = value => {
|
43
|
-
store.set(_async_hooks.default.executionAsyncId(), value);
|
44
|
-
};
|
45
|
-
|
46
|
-
const get = () => {
|
47
|
-
return store.get(_async_hooks.default.executionAsyncId());
|
48
|
-
};
|
49
|
-
|
50
|
-
const clear = () => {
|
51
|
-
store.clear();
|
52
|
-
};
|
53
|
-
|
54
|
-
const enable = () => {
|
55
|
-
hooks.enable();
|
56
|
-
};
|
57
|
-
|
58
|
-
const disable = () => {
|
59
|
-
hooks.disable();
|
60
|
-
store.clear();
|
61
|
-
};
|
62
|
-
|
63
|
-
const entries = () => {
|
64
|
-
return store.entries();
|
65
|
-
};
|
66
|
-
|
67
|
-
return {
|
68
|
-
enable,
|
69
|
-
disable,
|
70
|
-
set,
|
71
|
-
get,
|
72
|
-
clear,
|
73
|
-
entries
|
74
|
-
};
|
75
|
-
};
|
76
|
-
|
77
|
-
let enabled = false;
|
78
|
-
|
79
|
-
const enable = () => {
|
80
|
-
if (enabled) {
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
|
84
|
-
enabled = true;
|
85
|
-
const hooks = createAsyncHooks();
|
86
|
-
asyncHooksInterface.impl(hooks);
|
87
|
-
hooks.enable();
|
88
|
-
};
|
89
|
-
|
90
|
-
exports.enable = enable;
|
91
|
-
|
92
|
-
const disable = () => {
|
93
|
-
var _asyncHooksInterface$;
|
94
|
-
|
95
|
-
enabled = false;
|
96
|
-
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
97
|
-
asyncHooksInterface.reset();
|
98
|
-
};
|
99
|
-
|
100
|
-
exports.disable = disable;
|
@@ -1,26 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.reset = exports.impl = exports.asyncHooks = void 0;
|
7
|
-
|
8
|
-
/**
|
9
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
10
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
11
|
-
*/
|
12
|
-
// eslint-disable-next-line import/no-mutable-exports
|
13
|
-
let asyncHooks;
|
14
|
-
exports.asyncHooks = asyncHooks;
|
15
|
-
|
16
|
-
const impl = implimentations => {
|
17
|
-
exports.asyncHooks = asyncHooks = implimentations;
|
18
|
-
};
|
19
|
-
|
20
|
-
exports.impl = impl;
|
21
|
-
|
22
|
-
const reset = () => {
|
23
|
-
exports.asyncHooks = asyncHooks = undefined;
|
24
|
-
};
|
25
|
-
|
26
|
-
exports.reset = reset;
|
@@ -1,52 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.createHooks = void 0;
|
7
|
-
|
8
|
-
var _asyncHooksInterface = require("./asyncHooksInterface");
|
9
|
-
|
10
|
-
/**
|
11
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
12
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
13
|
-
*/
|
14
|
-
const createHooks = defaultHooks => {
|
15
|
-
let currentHooks = {};
|
16
|
-
const hooks = {};
|
17
|
-
|
18
|
-
for (const key in defaultHooks) {
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
20
|
-
const f = (...args) => {
|
21
|
-
var _asyncHooks$get;
|
22
|
-
|
23
|
-
const hooks = currentHooks === defaultHooks ? (_asyncHooks$get = _asyncHooksInterface.asyncHooks === null || _asyncHooksInterface.asyncHooks === void 0 ? void 0 : _asyncHooksInterface.asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
|
24
|
-
let handler = hooks[key];
|
25
|
-
|
26
|
-
if (typeof handler !== 'function') {
|
27
|
-
handler = defaultHooks[key];
|
28
|
-
}
|
29
|
-
|
30
|
-
return handler(...args);
|
31
|
-
};
|
32
|
-
|
33
|
-
hooks[key] = f;
|
34
|
-
}
|
35
|
-
|
36
|
-
const run = (f, implementations) => {
|
37
|
-
try {
|
38
|
-
currentHooks = implementations || defaultHooks;
|
39
|
-
_asyncHooksInterface.asyncHooks === null || _asyncHooksInterface.asyncHooks === void 0 ? void 0 : _asyncHooksInterface.asyncHooks.set(currentHooks);
|
40
|
-
return f();
|
41
|
-
} finally {
|
42
|
-
currentHooks = defaultHooks;
|
43
|
-
}
|
44
|
-
};
|
45
|
-
|
46
|
-
return {
|
47
|
-
run,
|
48
|
-
hooks
|
49
|
-
};
|
50
|
-
};
|
51
|
-
|
52
|
-
exports.createHooks = createHooks;
|
@@ -1,23 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.useRunner = exports.RunnerContext = void 0;
|
7
|
-
|
8
|
-
var _farrowPipeline = require("../farrow-pipeline");
|
9
|
-
|
10
|
-
const RunnerContext = (0, _farrowPipeline.createContext)(null);
|
11
|
-
exports.RunnerContext = RunnerContext;
|
12
|
-
|
13
|
-
const useRunner = () => {
|
14
|
-
const runner = RunnerContext.use().value;
|
15
|
-
|
16
|
-
if (!runner) {
|
17
|
-
throw new Error(`Can't call useRunner out of scope, it should be placed in hooks of plugin`);
|
18
|
-
}
|
19
|
-
|
20
|
-
return runner;
|
21
|
-
};
|
22
|
-
|
23
|
-
exports.useRunner = useRunner;
|
@@ -1,80 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
import NodeAsyncHooks from 'async_hooks';
|
6
|
-
import * as asyncHooksInterface from "./asyncHooksInterface";
|
7
|
-
|
8
|
-
var createAsyncHooks = function createAsyncHooks() {
|
9
|
-
var store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
|
10
|
-
|
11
|
-
var hooks = NodeAsyncHooks.createHook({
|
12
|
-
init: function init(asyncId, _, triggerAsyncId) {
|
13
|
-
if (store.has(triggerAsyncId)) {
|
14
|
-
var value = store.get(triggerAsyncId);
|
15
|
-
|
16
|
-
if (value) {
|
17
|
-
store.set(asyncId, value);
|
18
|
-
}
|
19
|
-
}
|
20
|
-
},
|
21
|
-
destroy: function destroy(asyncId) {
|
22
|
-
if (store.has(asyncId)) {
|
23
|
-
store["delete"](asyncId);
|
24
|
-
}
|
25
|
-
}
|
26
|
-
});
|
27
|
-
|
28
|
-
var set = function set(value) {
|
29
|
-
store.set(NodeAsyncHooks.executionAsyncId(), value);
|
30
|
-
};
|
31
|
-
|
32
|
-
var get = function get() {
|
33
|
-
return store.get(NodeAsyncHooks.executionAsyncId());
|
34
|
-
};
|
35
|
-
|
36
|
-
var clear = function clear() {
|
37
|
-
store.clear();
|
38
|
-
};
|
39
|
-
|
40
|
-
var enable = function enable() {
|
41
|
-
hooks.enable();
|
42
|
-
};
|
43
|
-
|
44
|
-
var disable = function disable() {
|
45
|
-
hooks.disable();
|
46
|
-
store.clear();
|
47
|
-
};
|
48
|
-
|
49
|
-
var entries = function entries() {
|
50
|
-
return store.entries();
|
51
|
-
};
|
52
|
-
|
53
|
-
return {
|
54
|
-
enable: enable,
|
55
|
-
disable: disable,
|
56
|
-
set: set,
|
57
|
-
get: get,
|
58
|
-
clear: clear,
|
59
|
-
entries: entries
|
60
|
-
};
|
61
|
-
};
|
62
|
-
|
63
|
-
var enabled = false;
|
64
|
-
export var enable = function enable() {
|
65
|
-
if (enabled) {
|
66
|
-
return;
|
67
|
-
}
|
68
|
-
|
69
|
-
enabled = true;
|
70
|
-
var hooks = createAsyncHooks();
|
71
|
-
asyncHooksInterface.impl(hooks);
|
72
|
-
hooks.enable();
|
73
|
-
};
|
74
|
-
export var disable = function disable() {
|
75
|
-
var _asyncHooksInterface$;
|
76
|
-
|
77
|
-
enabled = false;
|
78
|
-
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
79
|
-
asyncHooksInterface.reset();
|
80
|
-
};
|
@@ -1,12 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
// eslint-disable-next-line import/no-mutable-exports
|
6
|
-
export var asyncHooks;
|
7
|
-
export var impl = function impl(implimentations) {
|
8
|
-
asyncHooks = implimentations;
|
9
|
-
};
|
10
|
-
export var reset = function reset() {
|
11
|
-
asyncHooks = undefined;
|
12
|
-
};
|
@@ -1,46 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
import { asyncHooks } from "./asyncHooksInterface";
|
6
|
-
export var createHooks = function createHooks(defaultHooks) {
|
7
|
-
var currentHooks = {};
|
8
|
-
var hooks = {};
|
9
|
-
|
10
|
-
var _loop = function _loop(key) {
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
12
|
-
var f = function f() {
|
13
|
-
var _asyncHooks$get;
|
14
|
-
|
15
|
-
var hooks = currentHooks === defaultHooks ? (_asyncHooks$get = asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
|
16
|
-
var handler = hooks[key];
|
17
|
-
|
18
|
-
if (typeof handler !== 'function') {
|
19
|
-
handler = defaultHooks[key];
|
20
|
-
}
|
21
|
-
|
22
|
-
return handler.apply(void 0, arguments);
|
23
|
-
};
|
24
|
-
|
25
|
-
hooks[key] = f;
|
26
|
-
};
|
27
|
-
|
28
|
-
for (var key in defaultHooks) {
|
29
|
-
_loop(key);
|
30
|
-
}
|
31
|
-
|
32
|
-
var run = function run(f, implementations) {
|
33
|
-
try {
|
34
|
-
currentHooks = implementations || defaultHooks;
|
35
|
-
asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.set(currentHooks);
|
36
|
-
return f();
|
37
|
-
} finally {
|
38
|
-
currentHooks = defaultHooks;
|
39
|
-
}
|
40
|
-
};
|
41
|
-
|
42
|
-
return {
|
43
|
-
run: run,
|
44
|
-
hooks: hooks
|
45
|
-
};
|
46
|
-
};
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import { createContext } from "../farrow-pipeline";
|
2
|
-
export var RunnerContext = createContext(null);
|
3
|
-
export var useRunner = function useRunner() {
|
4
|
-
var runner = RunnerContext.use().value;
|
5
|
-
|
6
|
-
if (!runner) {
|
7
|
-
throw new Error("Can't call useRunner out of scope, it should be placed in hooks of plugin");
|
8
|
-
}
|
9
|
-
|
10
|
-
return runner;
|
11
|
-
};
|
@@ -1,19 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
export declare type AnyFn = (...args: any) => any;
|
6
|
-
export declare type Hooks = {
|
7
|
-
[key: string]: AnyFn;
|
8
|
-
};
|
9
|
-
export declare type AsyncHooks = {
|
10
|
-
enable: () => void;
|
11
|
-
disable: () => void;
|
12
|
-
set: (value: Hooks) => void;
|
13
|
-
get: () => Hooks | undefined;
|
14
|
-
clear: () => void;
|
15
|
-
entries: () => IterableIterator<[number, Hooks]>;
|
16
|
-
} | undefined;
|
17
|
-
export declare let asyncHooks: AsyncHooks;
|
18
|
-
export declare const impl: (implimentations: AsyncHooks) => void;
|
19
|
-
export declare const reset: () => void;
|
@@ -1,9 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
import { Hooks, AnyFn } from './asyncHooksInterface';
|
6
|
-
export declare const createHooks: <HS extends Hooks>(defaultHooks: HS) => {
|
7
|
-
run: <F extends AnyFn>(f: F, implementations: HS) => ReturnType<F>;
|
8
|
-
hooks: HS;
|
9
|
-
};
|