@modern-js/plugin 0.0.0-next-1682468392848 → 0.0.0-next-1682520086226
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 +13 -1
- package/dist/cjs/manager/shared.js +2 -2
- package/dist/esm/index.js +2 -75
- package/dist/esm-node/manager/shared.js +2 -2
- package/package.json +5 -4
- package/dist/cjs/utils/pluginDagSort.js +0 -57
- package/dist/esm-node/utils/pluginDagSort.js +0 -49
- package/dist/types/utils/pluginDagSort.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# @modern-js/plugin
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-1682520086226
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 759652038: feat(builder): builder plugin supports specifying relative order via the `pre` / `post` configuration items
|
|
8
|
+
|
|
9
|
+
feat(builder): builder 插件支持通过 `pre` / `post` 配置项指定相对顺序
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [5954330f9]
|
|
14
|
+
- Updated dependencies [759652038]
|
|
15
|
+
- @modern-js/utils@0.0.0-next-1682520086226
|
|
4
16
|
|
|
5
17
|
## 2.15.0
|
|
6
18
|
|
|
@@ -16,7 +16,7 @@ _export(exports, {
|
|
|
16
16
|
isObject: () => isObject,
|
|
17
17
|
hasOwnProperty: () => hasOwnProperty
|
|
18
18
|
});
|
|
19
|
-
const _pluginDagSort = require("
|
|
19
|
+
const _pluginDagSort = require("@modern-js/utils/universal/pluginDagSort");
|
|
20
20
|
const checkPlugins = (plugins) => {
|
|
21
21
|
if (process.env.NODE_ENV !== "production") {
|
|
22
22
|
plugins.forEach((origin) => {
|
|
@@ -36,7 +36,7 @@ const checkPlugins = (plugins) => {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
function sortPlugins(input) {
|
|
39
|
-
return (0, _pluginDagSort.
|
|
39
|
+
return (0, _pluginDagSort.pluginDagSort)(input.slice());
|
|
40
40
|
}
|
|
41
41
|
const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
|
|
42
42
|
const isObject = (obj) => obj !== null && typeof obj === "object";
|
package/dist/esm/index.js
CHANGED
|
@@ -815,81 +815,8 @@ function isPromise(obj) {
|
|
|
815
815
|
return obj && typeof obj.then === "function";
|
|
816
816
|
}
|
|
817
817
|
|
|
818
|
-
// src/utils/pluginDagSort.ts
|
|
819
|
-
var dagSort = function(plugins) {
|
|
820
|
-
var _loop = function() {
|
|
821
|
-
var zep = zeroEndPoints.shift();
|
|
822
|
-
sortedPoint.push(getPluginByAny(zep));
|
|
823
|
-
allLines = allLines.filter(function(l) {
|
|
824
|
-
return l[0] !== getPluginByAny(zep)[key];
|
|
825
|
-
});
|
|
826
|
-
var restPoints = plugins.filter(function(item) {
|
|
827
|
-
return !sortedPoint.find(function(sp) {
|
|
828
|
-
return sp[key] === item[key];
|
|
829
|
-
});
|
|
830
|
-
});
|
|
831
|
-
zeroEndPoints = restPoints.filter(
|
|
832
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
833
|
-
function(item) {
|
|
834
|
-
return !allLines.find(function(l) {
|
|
835
|
-
return l[1] === item[key];
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
);
|
|
839
|
-
};
|
|
840
|
-
var key = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "name", preKey = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "pre", postKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "post";
|
|
841
|
-
var getPluginByAny = function getPluginByAny2(q) {
|
|
842
|
-
var target = plugins.find(function(item) {
|
|
843
|
-
return typeof q === "string" ? item[key] === q : item[key] === q[key];
|
|
844
|
-
});
|
|
845
|
-
if (!target) {
|
|
846
|
-
throw new Error("plugin ".concat(q, " not existed"));
|
|
847
|
-
}
|
|
848
|
-
return target;
|
|
849
|
-
};
|
|
850
|
-
var allLines = [];
|
|
851
|
-
plugins.forEach(function(item) {
|
|
852
|
-
item[preKey].forEach(function(p) {
|
|
853
|
-
if (plugins.find(function(ap) {
|
|
854
|
-
return ap.name === p;
|
|
855
|
-
})) {
|
|
856
|
-
allLines.push([
|
|
857
|
-
getPluginByAny(p)[key],
|
|
858
|
-
getPluginByAny(item)[key]
|
|
859
|
-
]);
|
|
860
|
-
}
|
|
861
|
-
});
|
|
862
|
-
item[postKey].forEach(function(pt) {
|
|
863
|
-
if (plugins.find(function(ap) {
|
|
864
|
-
return ap.name === pt;
|
|
865
|
-
})) {
|
|
866
|
-
allLines.push([
|
|
867
|
-
getPluginByAny(item)[key],
|
|
868
|
-
getPluginByAny(pt)[key]
|
|
869
|
-
]);
|
|
870
|
-
}
|
|
871
|
-
});
|
|
872
|
-
});
|
|
873
|
-
var zeroEndPoints = plugins.filter(function(item) {
|
|
874
|
-
return !allLines.find(function(l) {
|
|
875
|
-
return l[1] === item[key];
|
|
876
|
-
});
|
|
877
|
-
});
|
|
878
|
-
var sortedPoint = [];
|
|
879
|
-
while (zeroEndPoints.length)
|
|
880
|
-
_loop();
|
|
881
|
-
if (allLines.length) {
|
|
882
|
-
var restInRingPoints = {};
|
|
883
|
-
allLines.forEach(function(l) {
|
|
884
|
-
restInRingPoints[l[0]] = true;
|
|
885
|
-
restInRingPoints[l[1]] = true;
|
|
886
|
-
});
|
|
887
|
-
throw new Error("plugins dependences has loop: ".concat(Object.keys(restInRingPoints).join(",")));
|
|
888
|
-
}
|
|
889
|
-
return sortedPoint;
|
|
890
|
-
};
|
|
891
|
-
|
|
892
818
|
// src/manager/shared.ts
|
|
819
|
+
import { pluginDagSort } from "@modern-js/utils/universal/pluginDagSort";
|
|
893
820
|
var checkPlugins = function(plugins) {
|
|
894
821
|
if (process.env.NODE_ENV !== "production") {
|
|
895
822
|
plugins.forEach(function(origin) {
|
|
@@ -911,7 +838,7 @@ var checkPlugins = function(plugins) {
|
|
|
911
838
|
}
|
|
912
839
|
};
|
|
913
840
|
function sortPlugins(input) {
|
|
914
|
-
return
|
|
841
|
+
return pluginDagSort(input.slice());
|
|
915
842
|
}
|
|
916
843
|
var includePlugin = function(plugins, input) {
|
|
917
844
|
return plugins.some(function(plugin) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { pluginDagSort } from "@modern-js/utils/universal/pluginDagSort";
|
|
2
2
|
export const checkPlugins = (plugins) => {
|
|
3
3
|
if (process.env.NODE_ENV !== "production") {
|
|
4
4
|
plugins.forEach((origin) => {
|
|
@@ -18,7 +18,7 @@ export const checkPlugins = (plugins) => {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
export function sortPlugins(input) {
|
|
21
|
-
return
|
|
21
|
+
return pluginDagSort(input.slice());
|
|
22
22
|
}
|
|
23
23
|
export const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
|
|
24
24
|
export const isObject = (obj) => obj !== null && typeof obj === "object";
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.0-next-
|
|
14
|
+
"version": "0.0.0-next-1682520086226",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/cjs/index.js",
|
|
@@ -28,15 +28,16 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@babel/runtime": "^7.18.0"
|
|
31
|
+
"@babel/runtime": "^7.18.0",
|
|
32
|
+
"@modern-js/utils": "0.0.0-next-1682520086226"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/jest": "^29",
|
|
35
36
|
"@types/node": "^14",
|
|
36
37
|
"typescript": "^4",
|
|
37
38
|
"jest": "^29",
|
|
38
|
-
"@scripts/
|
|
39
|
-
"@scripts/
|
|
39
|
+
"@scripts/build": "0.0.0-next-1682520086226",
|
|
40
|
+
"@scripts/jest-config": "0.0.0-next-1682520086226"
|
|
40
41
|
},
|
|
41
42
|
"sideEffects": false,
|
|
42
43
|
"publishConfig": {
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "dagSort", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: () => dagSort
|
|
8
|
-
});
|
|
9
|
-
const dagSort = (plugins, key = "name", preKey = "pre", postKey = "post") => {
|
|
10
|
-
let allLines = [];
|
|
11
|
-
function getPluginByAny(q) {
|
|
12
|
-
const target = plugins.find((item) => typeof q === "string" ? item[key] === q : item[key] === q[key]);
|
|
13
|
-
if (!target) {
|
|
14
|
-
throw new Error(`plugin ${q} not existed`);
|
|
15
|
-
}
|
|
16
|
-
return target;
|
|
17
|
-
}
|
|
18
|
-
plugins.forEach((item) => {
|
|
19
|
-
item[preKey].forEach((p) => {
|
|
20
|
-
if (plugins.find((ap) => ap.name === p)) {
|
|
21
|
-
allLines.push([
|
|
22
|
-
getPluginByAny(p)[key],
|
|
23
|
-
getPluginByAny(item)[key]
|
|
24
|
-
]);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
item[postKey].forEach((pt) => {
|
|
28
|
-
if (plugins.find((ap) => ap.name === pt)) {
|
|
29
|
-
allLines.push([
|
|
30
|
-
getPluginByAny(item)[key],
|
|
31
|
-
getPluginByAny(pt)[key]
|
|
32
|
-
]);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
let zeroEndPoints = plugins.filter((item) => !allLines.find((l) => l[1] === item[key]));
|
|
37
|
-
const sortedPoint = [];
|
|
38
|
-
while (zeroEndPoints.length) {
|
|
39
|
-
const zep = zeroEndPoints.shift();
|
|
40
|
-
sortedPoint.push(getPluginByAny(zep));
|
|
41
|
-
allLines = allLines.filter((l) => l[0] !== getPluginByAny(zep)[key]);
|
|
42
|
-
const restPoints = plugins.filter((item) => !sortedPoint.find((sp) => sp[key] === item[key]));
|
|
43
|
-
zeroEndPoints = restPoints.filter(
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
45
|
-
(item) => !allLines.find((l) => l[1] === item[key])
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
if (allLines.length) {
|
|
49
|
-
const restInRingPoints = {};
|
|
50
|
-
allLines.forEach((l) => {
|
|
51
|
-
restInRingPoints[l[0]] = true;
|
|
52
|
-
restInRingPoints[l[1]] = true;
|
|
53
|
-
});
|
|
54
|
-
throw new Error(`plugins dependences has loop: ${Object.keys(restInRingPoints).join(",")}`);
|
|
55
|
-
}
|
|
56
|
-
return sortedPoint;
|
|
57
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export const dagSort = (plugins, key = "name", preKey = "pre", postKey = "post") => {
|
|
2
|
-
let allLines = [];
|
|
3
|
-
function getPluginByAny(q) {
|
|
4
|
-
const target = plugins.find((item) => typeof q === "string" ? item[key] === q : item[key] === q[key]);
|
|
5
|
-
if (!target) {
|
|
6
|
-
throw new Error(`plugin ${q} not existed`);
|
|
7
|
-
}
|
|
8
|
-
return target;
|
|
9
|
-
}
|
|
10
|
-
plugins.forEach((item) => {
|
|
11
|
-
item[preKey].forEach((p) => {
|
|
12
|
-
if (plugins.find((ap) => ap.name === p)) {
|
|
13
|
-
allLines.push([
|
|
14
|
-
getPluginByAny(p)[key],
|
|
15
|
-
getPluginByAny(item)[key]
|
|
16
|
-
]);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
item[postKey].forEach((pt) => {
|
|
20
|
-
if (plugins.find((ap) => ap.name === pt)) {
|
|
21
|
-
allLines.push([
|
|
22
|
-
getPluginByAny(item)[key],
|
|
23
|
-
getPluginByAny(pt)[key]
|
|
24
|
-
]);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
let zeroEndPoints = plugins.filter((item) => !allLines.find((l) => l[1] === item[key]));
|
|
29
|
-
const sortedPoint = [];
|
|
30
|
-
while (zeroEndPoints.length) {
|
|
31
|
-
const zep = zeroEndPoints.shift();
|
|
32
|
-
sortedPoint.push(getPluginByAny(zep));
|
|
33
|
-
allLines = allLines.filter((l) => l[0] !== getPluginByAny(zep)[key]);
|
|
34
|
-
const restPoints = plugins.filter((item) => !sortedPoint.find((sp) => sp[key] === item[key]));
|
|
35
|
-
zeroEndPoints = restPoints.filter(
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
37
|
-
(item) => !allLines.find((l) => l[1] === item[key])
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
if (allLines.length) {
|
|
41
|
-
const restInRingPoints = {};
|
|
42
|
-
allLines.forEach((l) => {
|
|
43
|
-
restInRingPoints[l[0]] = true;
|
|
44
|
-
restInRingPoints[l[1]] = true;
|
|
45
|
-
});
|
|
46
|
-
throw new Error(`plugins dependences has loop: ${Object.keys(restInRingPoints).join(",")}`);
|
|
47
|
-
}
|
|
48
|
-
return sortedPoint;
|
|
49
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const dagSort: <P extends Record<string, any>>(plugins: P[], key?: string, preKey?: string, postKey?: string) => P[];
|