@modern-js/plugin 2.15.0 → 2.17.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/CHANGELOG.md +25 -0
- package/dist/cjs/farrow-pipeline/context.js +9 -27
- package/dist/cjs/farrow-pipeline/counter.js +7 -25
- package/dist/cjs/farrow-pipeline/index.js +25 -38
- package/dist/cjs/index.js +21 -20
- package/dist/cjs/manager/async.js +25 -41
- package/dist/cjs/manager/index.js +20 -19
- package/dist/cjs/manager/shared.js +16 -34
- package/dist/cjs/manager/sync.js +48 -60
- package/dist/cjs/manager/types.js +4 -15
- package/dist/cjs/waterfall/async.js +25 -34
- package/dist/cjs/waterfall/index.js +19 -18
- package/dist/cjs/waterfall/sync.js +24 -31
- package/dist/cjs/workflow/async.js +25 -33
- package/dist/cjs/workflow/index.js +20 -19
- package/dist/cjs/workflow/parallel.js +25 -33
- package/dist/cjs/workflow/sync.js +23 -29
- package/dist/esm/index.js +1123 -637
- package/dist/esm-node/farrow-pipeline/context.js +3 -6
- package/dist/esm-node/farrow-pipeline/counter.js +1 -4
- package/dist/esm-node/farrow-pipeline/index.js +11 -14
- package/dist/esm-node/manager/async.js +11 -18
- package/dist/esm-node/manager/shared.js +8 -17
- package/dist/esm-node/manager/sync.js +21 -42
- package/dist/esm-node/manager/types.js +1 -0
- package/dist/esm-node/waterfall/async.js +14 -16
- package/dist/esm-node/waterfall/sync.js +12 -10
- package/dist/esm-node/workflow/async.js +12 -13
- package/dist/esm-node/workflow/parallel.js +11 -10
- package/dist/esm-node/workflow/sync.js +10 -7
- package/package.json +10 -5
- package/dist/cjs/utils/pluginDagSort.js +0 -79
- package/dist/esm-node/utils/pluginDagSort.js +0 -56
- package/dist/types/utils/pluginDagSort.d.ts +0 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# @modern-js/plugin
|
2
2
|
|
3
|
+
## 2.17.0
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- @modern-js/utils@2.17.0
|
8
|
+
|
9
|
+
## 2.16.0
|
10
|
+
|
11
|
+
### Minor Changes
|
12
|
+
|
13
|
+
- 7596520: feat(builder): builder plugin supports specifying relative order via the `pre` / `post` configuration items
|
14
|
+
|
15
|
+
feat(builder): builder 插件支持通过 `pre` / `post` 配置项指定相对顺序
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
20
|
+
|
21
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
22
|
+
|
23
|
+
- Updated dependencies [5954330]
|
24
|
+
- Updated dependencies [7596520]
|
25
|
+
- Updated dependencies [4e876ab]
|
26
|
+
- @modern-js/utils@2.16.0
|
27
|
+
|
3
28
|
## 2.15.0
|
4
29
|
|
5
30
|
## 2.14.0
|
@@ -1,25 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
};
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
-
for (let key of __getOwnPropNames(from))
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
-
}
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var context_exports = {};
|
19
|
-
__export(context_exports, {
|
20
|
-
createContext: () => createContext
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "createContext", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => createContext
|
21
8
|
});
|
22
|
-
module.exports = __toCommonJS(context_exports);
|
23
9
|
const createContext = (value) => {
|
24
10
|
let currentValue = value;
|
25
11
|
return {
|
@@ -32,12 +18,8 @@ const createContext = (value) => {
|
|
32
18
|
}
|
33
19
|
}),
|
34
20
|
get: () => currentValue,
|
35
|
-
set: (
|
36
|
-
currentValue =
|
21
|
+
set: (v1) => {
|
22
|
+
currentValue = v1;
|
37
23
|
}
|
38
24
|
};
|
39
25
|
};
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
41
|
-
0 && (module.exports = {
|
42
|
-
createContext
|
43
|
-
});
|
@@ -1,25 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
};
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
-
for (let key of __getOwnPropNames(from))
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
-
}
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var counter_exports = {};
|
19
|
-
__export(counter_exports, {
|
20
|
-
createCounter: () => createCounter
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "createCounter", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => createCounter
|
21
8
|
});
|
22
|
-
module.exports = __toCommonJS(counter_exports);
|
23
9
|
const createCounter = (callback) => {
|
24
10
|
const dispatch = (index, input) => {
|
25
11
|
const next = (nextInput = input) => dispatch(index + 1, nextInput);
|
@@ -30,7 +16,3 @@ const createCounter = (callback) => {
|
|
30
16
|
dispatch
|
31
17
|
};
|
32
18
|
};
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
34
|
-
0 && (module.exports = {
|
35
|
-
createCounter
|
36
|
-
});
|
@@ -1,31 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
6
|
for (var name in all)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var farrow_pipeline_exports = {};
|
19
|
-
__export(farrow_pipeline_exports, {
|
20
|
-
createAsyncPipeline: () => createAsyncPipeline,
|
21
|
-
createContext: () => import_context.createContext,
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
createContext: () => _context.createContext,
|
14
|
+
isPipeline: () => isPipeline,
|
22
15
|
createPipeline: () => createPipeline,
|
23
|
-
|
16
|
+
createAsyncPipeline: () => createAsyncPipeline
|
24
17
|
});
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
const _context = require("./context");
|
19
|
+
const _counter = require("./counter");
|
20
|
+
const isPipeline = (input) => {
|
21
|
+
return Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
22
|
+
};
|
29
23
|
const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
|
30
24
|
const getMiddleware = (input) => {
|
31
25
|
if (typeof input === "function") {
|
@@ -42,14 +36,12 @@ const createPipeline = () => {
|
|
42
36
|
return pipeline;
|
43
37
|
};
|
44
38
|
const createCurrentCounter = (onLast) => {
|
45
|
-
return (0,
|
39
|
+
return (0, _counter.createCounter)((index, input, next) => {
|
46
40
|
if (index >= middlewares.length) {
|
47
41
|
if (onLast) {
|
48
42
|
return onLast(input);
|
49
43
|
}
|
50
|
-
throw new Error(
|
51
|
-
`Expect returning a value, but all middlewares just calling next()`
|
52
|
-
);
|
44
|
+
throw new Error(`Expect returning a value, but all middlewares just calling next()`);
|
53
45
|
}
|
54
46
|
return middlewares[index](input, next);
|
55
47
|
});
|
@@ -59,7 +51,7 @@ const createPipeline = () => {
|
|
59
51
|
if (!options) {
|
60
52
|
return currentCounter;
|
61
53
|
}
|
62
|
-
return createCurrentCounter(options
|
54
|
+
return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
|
63
55
|
};
|
64
56
|
const run = (input, options) => getCounter(options).start(input);
|
65
57
|
const middleware = (input, next) => run(input, {
|
@@ -75,12 +67,7 @@ const createPipeline = () => {
|
|
75
67
|
};
|
76
68
|
const createAsyncPipeline = () => {
|
77
69
|
const pipeline = createPipeline();
|
78
|
-
return {
|
70
|
+
return {
|
71
|
+
...pipeline
|
72
|
+
};
|
79
73
|
};
|
80
|
-
// Annotate the CommonJS export names for ESM import in node:
|
81
|
-
0 && (module.exports = {
|
82
|
-
createAsyncPipeline,
|
83
|
-
createContext,
|
84
|
-
createPipeline,
|
85
|
-
isPipeline
|
86
|
-
});
|
package/dist/cjs/index.js
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
_export_star(require("./farrow-pipeline"), exports);
|
6
|
+
_export_star(require("./waterfall"), exports);
|
7
|
+
_export_star(require("./workflow"), exports);
|
8
|
+
_export_star(require("./manager"), exports);
|
9
|
+
function _export_star(from, to) {
|
10
|
+
Object.keys(from).forEach(function(k) {
|
11
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
12
|
+
Object.defineProperty(to, k, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function() {
|
15
|
+
return from[k];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
}
|
19
|
+
});
|
20
|
+
return from;
|
21
|
+
}
|
@@ -1,32 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
};
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
-
for (let key of __getOwnPropNames(from))
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
-
}
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var async_exports = {};
|
19
|
-
__export(async_exports, {
|
20
|
-
createAsyncManager: () => createAsyncManager
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "createAsyncManager", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => createAsyncManager
|
21
8
|
});
|
22
|
-
|
23
|
-
|
24
|
-
var import_shared = require("./shared");
|
9
|
+
const _sync = require("./sync");
|
10
|
+
const _shared = require("./shared");
|
25
11
|
const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
26
12
|
const createAsyncManager = (hooks, api) => {
|
27
13
|
let index = 0;
|
28
14
|
let runners;
|
29
|
-
let currentHooks = {
|
15
|
+
let currentHooks = {
|
16
|
+
...hooks
|
17
|
+
};
|
30
18
|
const useRunner = () => runners;
|
31
19
|
const registerHook = (extraHooks) => {
|
32
20
|
currentHooks = {
|
@@ -34,7 +22,7 @@ const createAsyncManager = (hooks, api) => {
|
|
34
22
|
...currentHooks
|
35
23
|
};
|
36
24
|
};
|
37
|
-
const isPlugin = (input) => (0,
|
25
|
+
const isPlugin = (input) => (0, _shared.isObject)(input) && (0, _shared.hasOwnProperty)(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
|
38
26
|
const pluginAPI = {
|
39
27
|
...api,
|
40
28
|
useHookRunners: useRunner
|
@@ -42,8 +30,10 @@ const createAsyncManager = (hooks, api) => {
|
|
42
30
|
const clone = (overrideAPI) => {
|
43
31
|
let plugins = [];
|
44
32
|
const addPlugin = (plugin) => {
|
45
|
-
if (!(0,
|
46
|
-
plugins.push({
|
33
|
+
if (!(0, _shared.includePlugin)(plugins, plugin)) {
|
34
|
+
plugins.push({
|
35
|
+
...plugin
|
36
|
+
});
|
47
37
|
}
|
48
38
|
};
|
49
39
|
const usePlugin = (...input) => {
|
@@ -53,7 +43,7 @@ const createAsyncManager = (hooks, api) => {
|
|
53
43
|
} else if (typeof plugin === "function") {
|
54
44
|
const options = plugin();
|
55
45
|
addPlugin(createPlugin(options.setup, options));
|
56
|
-
} else if ((0,
|
46
|
+
} else if ((0, _shared.isObject)(plugin)) {
|
57
47
|
addPlugin(createPlugin(plugin.setup, plugin));
|
58
48
|
} else if (process.env.NODE_ENV !== "production") {
|
59
49
|
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
@@ -63,8 +53,8 @@ const createAsyncManager = (hooks, api) => {
|
|
63
53
|
};
|
64
54
|
const createPlugin = (setup = () => {
|
65
55
|
}, options = {}) => {
|
66
|
-
var
|
67
|
-
if ((
|
56
|
+
var _options_usePlugins;
|
57
|
+
if ((_options_usePlugins = options.usePlugins) === null || _options_usePlugins === void 0 ? void 0 : _options_usePlugins.length) {
|
68
58
|
options.usePlugins.forEach((plugin) => {
|
69
59
|
usePlugin(createPlugin(plugin.setup, plugin));
|
70
60
|
});
|
@@ -73,7 +63,7 @@ const createAsyncManager = (hooks, api) => {
|
|
73
63
|
registerHook(options.registerHook);
|
74
64
|
}
|
75
65
|
return {
|
76
|
-
...
|
66
|
+
..._sync.DEFAULT_OPTIONS,
|
77
67
|
name: `No.${index++} plugin`,
|
78
68
|
...options,
|
79
69
|
ASYNC_PLUGIN_SYMBOL,
|
@@ -84,16 +74,14 @@ const createAsyncManager = (hooks, api) => {
|
|
84
74
|
plugins = [];
|
85
75
|
};
|
86
76
|
const init = () => {
|
87
|
-
const sortedPlugins = (0,
|
77
|
+
const sortedPlugins = (0, _shared.sortPlugins)(plugins);
|
88
78
|
const mergedPluginAPI = {
|
89
79
|
...pluginAPI,
|
90
80
|
...overrideAPI
|
91
81
|
};
|
92
|
-
(0,
|
93
|
-
return Promise.all(
|
94
|
-
|
95
|
-
).then((hooksList) => {
|
96
|
-
runners = (0, import_sync.generateRunner)(hooksList, currentHooks);
|
82
|
+
(0, _shared.checkPlugins)(sortedPlugins);
|
83
|
+
return Promise.all(sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI))).then((hooksList) => {
|
84
|
+
runners = (0, _sync.generateRunner)(hooksList, currentHooks);
|
97
85
|
return runners;
|
98
86
|
});
|
99
87
|
};
|
@@ -113,7 +101,3 @@ const createAsyncManager = (hooks, api) => {
|
|
113
101
|
};
|
114
102
|
return clone();
|
115
103
|
};
|
116
|
-
// Annotate the CommonJS export names for ESM import in node:
|
117
|
-
0 && (module.exports = {
|
118
|
-
createAsyncManager
|
119
|
-
});
|
@@ -1,19 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
_export_star(require("./sync"), exports);
|
6
|
+
_export_star(require("./async"), exports);
|
7
|
+
_export_star(require("./types"), exports);
|
8
|
+
function _export_star(from, to) {
|
9
|
+
Object.keys(from).forEach(function(k) {
|
10
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
11
|
+
Object.defineProperty(to, k, {
|
12
|
+
enumerable: true,
|
13
|
+
get: function() {
|
14
|
+
return from[k];
|
15
|
+
}
|
16
|
+
});
|
17
|
+
}
|
18
|
+
});
|
19
|
+
return from;
|
20
|
+
}
|
@@ -1,30 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
6
|
for (var name in all)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
-
}
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var shared_exports = {};
|
19
|
-
__export(shared_exports, {
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
20
13
|
checkPlugins: () => checkPlugins,
|
21
|
-
|
14
|
+
sortPlugins: () => sortPlugins,
|
22
15
|
includePlugin: () => includePlugin,
|
23
16
|
isObject: () => isObject,
|
24
|
-
|
17
|
+
hasOwnProperty: () => hasOwnProperty
|
25
18
|
});
|
26
|
-
|
27
|
-
var import_pluginDagSort = require("../utils/pluginDagSort");
|
19
|
+
const _pluginDagSort = require("@modern-js/utils/universal/pluginDagSort");
|
28
20
|
const checkPlugins = (plugins) => {
|
29
21
|
if (process.env.NODE_ENV !== "production") {
|
30
22
|
plugins.forEach((origin) => {
|
@@ -37,25 +29,15 @@ const checkPlugins = (plugins) => {
|
|
37
29
|
});
|
38
30
|
origin.required.forEach((required) => {
|
39
31
|
if (!plugins.some((plugin) => plugin.name === required)) {
|
40
|
-
throw new Error(
|
41
|
-
`The plugin: ${required} is required when plugin: ${origin.name} is exist.`
|
42
|
-
);
|
32
|
+
throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
|
43
33
|
}
|
44
34
|
});
|
45
35
|
});
|
46
36
|
}
|
47
37
|
};
|
48
38
|
function sortPlugins(input) {
|
49
|
-
return (0,
|
39
|
+
return (0, _pluginDagSort.pluginDagSort)(input.slice());
|
50
40
|
}
|
51
41
|
const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
|
52
42
|
const isObject = (obj) => obj !== null && typeof obj === "object";
|
53
43
|
const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
|
54
|
-
// Annotate the CommonJS export names for ESM import in node:
|
55
|
-
0 && (module.exports = {
|
56
|
-
checkPlugins,
|
57
|
-
hasOwnProperty,
|
58
|
-
includePlugin,
|
59
|
-
isObject,
|
60
|
-
sortPlugins
|
61
|
-
});
|