@modern-js/utils 2.26.0 → 2.28.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/cli/alias.js +3 -3
- package/dist/cjs/cli/constants/chainId.js +4 -0
- package/dist/cjs/cli/constants/index.js +0 -1
- package/dist/cjs/cli/is/config.js +11 -8
- package/dist/cjs/cli/prettyInstructions.js +3 -2
- package/dist/cjs/cli/require.js +2 -1
- package/dist/cjs/runtime/nestedRoutes.js +9 -5
- package/dist/cjs/runtime-browser/parsed.js +2 -1
- package/dist/cjs/universal/formatWebpack.js +55 -12
- package/dist/esm/cli/alias.js +27 -23
- package/dist/esm/cli/applyOptionsChain.js +8 -6
- package/dist/esm/cli/babel.js +50 -35
- package/dist/esm/cli/commands.js +7 -7
- package/dist/esm/cli/common.js +10 -5
- package/dist/esm/cli/constants/chainId.js +5 -1
- package/dist/esm/cli/constants/index.js +33 -38
- package/dist/esm/cli/ensure.js +4 -2
- package/dist/esm/cli/fs.js +56 -9
- package/dist/esm/cli/get/config.js +7 -7
- package/dist/esm/cli/get/data.js +102 -55
- package/dist/esm/cli/get/index.js +21 -6
- package/dist/esm/cli/is/config.js +43 -21
- package/dist/esm/cli/is/env.js +18 -6
- package/dist/esm/cli/is/platform.js +6 -2
- package/dist/esm/cli/is/project.js +73 -36
- package/dist/esm/cli/is/type.js +3 -1
- package/dist/esm/cli/logger.js +49 -38
- package/dist/esm/cli/monorepo.js +49 -36
- package/dist/esm/cli/package.js +156 -38
- package/dist/esm/cli/path.js +44 -20
- package/dist/esm/cli/pathSerializer.js +29 -15
- package/dist/esm/cli/port.js +89 -40
- package/dist/esm/cli/prettyInstructions.js +44 -32
- package/dist/esm/cli/require.js +22 -16
- package/dist/esm/cli/runtimeExports.js +21 -15
- package/dist/esm/cli/watch.js +94 -27
- package/dist/esm/compiled.js +3 -3
- package/dist/esm/import.js +4 -4
- package/dist/esm/runtime/nestedRoutes.js +49 -32
- package/dist/esm/runtime-browser/parsed.js +6 -5
- package/dist/esm/runtime-node/index.js +1 -1
- package/dist/esm/runtime-node/nestedRoutes.js +6 -4
- package/dist/esm/runtime-node/serialize.js +1 -1
- package/dist/esm/runtime-node/storage.js +12 -14
- package/dist/esm/universal/constants.js +3 -3
- package/dist/esm/universal/formatWebpack.js +54 -28
- package/dist/esm/universal/pluginDagSort.js +49 -26
- package/dist/esm-node/cli/alias.js +51 -0
- package/dist/esm-node/cli/applyOptionsChain.js +24 -0
- package/dist/esm-node/cli/babel.js +103 -0
- package/dist/esm-node/cli/commands.js +16 -0
- package/dist/esm-node/cli/common.js +10 -0
- package/dist/esm-node/cli/constants/chainId.js +184 -0
- package/dist/esm-node/cli/constants/index.js +102 -0
- package/dist/esm-node/cli/ensure.js +10 -0
- package/dist/esm-node/cli/fs.js +14 -0
- package/dist/esm-node/cli/get/config.js +16 -0
- package/dist/esm-node/cli/get/data.js +86 -0
- package/dist/esm-node/cli/get/index.js +13 -0
- package/dist/esm-node/cli/index.js +20 -0
- package/dist/esm-node/cli/is/config.js +43 -0
- package/dist/esm-node/cli/is/env.js +6 -0
- package/dist/esm-node/cli/is/index.js +5 -0
- package/dist/esm-node/cli/is/platform.js +2 -0
- package/dist/esm-node/cli/is/project.js +73 -0
- package/dist/esm-node/cli/is/type.js +25 -0
- package/dist/esm-node/cli/logger.js +103 -0
- package/dist/esm-node/cli/monorepo.js +70 -0
- package/dist/esm-node/cli/package.js +43 -0
- package/dist/esm-node/cli/path.js +49 -0
- package/dist/esm-node/cli/pathSerializer.js +46 -0
- package/dist/esm-node/cli/port.js +44 -0
- package/dist/esm-node/cli/prettyInstructions.js +78 -0
- package/dist/esm-node/cli/require.js +53 -0
- package/dist/esm-node/cli/runtimeExports.js +35 -0
- package/dist/esm-node/cli/watch.js +41 -0
- package/dist/esm-node/compiled.js +33 -0
- package/dist/esm-node/import.js +8 -0
- package/dist/esm-node/index.js +3 -0
- package/dist/esm-node/runtime/nestedRoutes.js +116 -0
- package/dist/esm-node/runtime/remixRouter.js +1 -0
- package/dist/esm-node/runtime/router.js +1 -0
- package/dist/esm-node/runtime-browser/index.js +1 -0
- package/dist/esm-node/runtime-browser/parsed.js +18 -0
- package/dist/esm-node/runtime-node/index.js +5 -0
- package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
- package/dist/esm-node/runtime-node/router.js +1 -0
- package/dist/esm-node/runtime-node/serialize.js +6 -0
- package/dist/esm-node/runtime-node/storage.js +38 -0
- package/dist/esm-node/universal/constants.js +3 -0
- package/dist/esm-node/universal/formatWebpack.js +99 -0
- package/dist/esm-node/universal/pluginDagSort.js +50 -0
- package/dist/types/cli/constants/chainId.d.ts +4 -0
- package/dist/types/universal/formatWebpack.d.ts +14 -1
- package/package.json +4 -4
@@ -0,0 +1,41 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { chokidar } from "../compiled";
|
3
|
+
export const WatchChangeType = {
|
4
|
+
ADD: "add",
|
5
|
+
UNLINK: "unlink",
|
6
|
+
CHANGE: "change"
|
7
|
+
};
|
8
|
+
export const watch = (watchDir, runTask, ignored = []) => {
|
9
|
+
let ready = false;
|
10
|
+
const watcher = chokidar.watch(watchDir, {
|
11
|
+
ignored
|
12
|
+
});
|
13
|
+
watcher.on("ready", () => ready = true);
|
14
|
+
watcher.on("change", async (filePath) => {
|
15
|
+
const changedFilePath = path.resolve(filePath);
|
16
|
+
await runTask({
|
17
|
+
changedFilePath,
|
18
|
+
changeType: WatchChangeType.CHANGE
|
19
|
+
});
|
20
|
+
});
|
21
|
+
watcher.on("add", async (filePath) => {
|
22
|
+
const changedFilePath = path.resolve(filePath);
|
23
|
+
if (ready) {
|
24
|
+
await runTask({
|
25
|
+
changedFilePath,
|
26
|
+
changeType: WatchChangeType.ADD
|
27
|
+
});
|
28
|
+
}
|
29
|
+
});
|
30
|
+
watcher.on("unlink", async (filePath) => {
|
31
|
+
const changedFilePath = path.resolve(filePath);
|
32
|
+
await runTask({
|
33
|
+
changedFilePath,
|
34
|
+
changeType: WatchChangeType.UNLINK
|
35
|
+
});
|
36
|
+
});
|
37
|
+
watcher.on("error", (err) => {
|
38
|
+
throw err;
|
39
|
+
});
|
40
|
+
return watcher;
|
41
|
+
};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { Import } from "./import";
|
2
|
+
export { default as fs } from "../compiled/fs-extra";
|
3
|
+
export { default as ora } from "../compiled/ora";
|
4
|
+
export { default as glob } from "../compiled/glob";
|
5
|
+
export { default as yaml } from "../compiled/js-yaml";
|
6
|
+
export { default as chalk } from "../compiled/chalk";
|
7
|
+
export { default as debug } from "../compiled/debug";
|
8
|
+
export { default as slash } from "../compiled/slash";
|
9
|
+
export { default as execa } from "../compiled/execa";
|
10
|
+
export { default as json5 } from "../compiled/json5";
|
11
|
+
export { default as upath } from "../compiled/upath";
|
12
|
+
export { default as pkgUp } from "../compiled/pkg-up";
|
13
|
+
export { nanoid } from "../compiled/nanoid";
|
14
|
+
export { default as semver } from "../compiled/semver";
|
15
|
+
export { default as dotenv } from "../compiled/dotenv";
|
16
|
+
export { default as lodash } from "../compiled/lodash";
|
17
|
+
export { default as globby } from "../compiled/globby";
|
18
|
+
export { default as address } from "../compiled/address";
|
19
|
+
export { default as signale } from "../compiled/signale";
|
20
|
+
export { default as urlJoin } from "../compiled/url-join";
|
21
|
+
export { default as minimist } from "../compiled/minimist";
|
22
|
+
export { default as fastGlob } from "../compiled/fast-glob";
|
23
|
+
export { default as filesize } from "../compiled/filesize";
|
24
|
+
export { default as gzipSize } from "../compiled/gzip-size";
|
25
|
+
export { default as stripAnsi } from "../compiled/strip-ansi";
|
26
|
+
export { default as dotenvExpand } from "../compiled/dotenv-expand";
|
27
|
+
export { default as browserslist } from "../compiled/browserslist";
|
28
|
+
export { default as recursiveReaddir } from "../compiled/recursive-readdir";
|
29
|
+
export { program, Command } from "../compiled/commander";
|
30
|
+
export { Signale } from "../compiled/signale";
|
31
|
+
export const mime = Import.lazy("../compiled/mime-types", require);
|
32
|
+
export const chokidar = Import.lazy("../compiled/chokidar", require);
|
33
|
+
export const inquirer = Import.lazy("../compiled/inquirer", require);
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
2
|
+
import { Suspense } from "react";
|
3
|
+
import { createRoutesFromElements, Route } from "react-router-dom";
|
4
|
+
export const transformNestedRoutes = (routes) => {
|
5
|
+
const routeElements = [];
|
6
|
+
for (const route of routes) {
|
7
|
+
const routeElement = renderNestedRoute(route);
|
8
|
+
routeElements.push(routeElement);
|
9
|
+
}
|
10
|
+
return createRoutesFromElements(routeElements);
|
11
|
+
};
|
12
|
+
export const renderNestedRoute = (nestedRoute, options = {}) => {
|
13
|
+
var _config, _children;
|
14
|
+
const { children, index, id, component, isRoot, lazyImport, config, handle } = nestedRoute;
|
15
|
+
const Component = component;
|
16
|
+
const { parent, DeferredDataComponent, props = {} } = options;
|
17
|
+
const routeProps = {
|
18
|
+
caseSensitive: nestedRoute.caseSensitive,
|
19
|
+
path: nestedRoute.path,
|
20
|
+
id: nestedRoute.id,
|
21
|
+
loader: createLoader(nestedRoute),
|
22
|
+
action: nestedRoute.action,
|
23
|
+
hasErrorBoundary: nestedRoute.hasErrorBoundary,
|
24
|
+
shouldRevalidate: nestedRoute.shouldRevalidate,
|
25
|
+
handle: {
|
26
|
+
...handle,
|
27
|
+
...typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _config.handle : {}
|
28
|
+
},
|
29
|
+
index: nestedRoute.index,
|
30
|
+
element: nestedRoute.element,
|
31
|
+
errorElement: nestedRoute.errorElement
|
32
|
+
};
|
33
|
+
if (nestedRoute.error) {
|
34
|
+
const errorElement = /* @__PURE__ */ _jsx(nestedRoute.error, {});
|
35
|
+
routeProps.errorElement = errorElement;
|
36
|
+
}
|
37
|
+
let element;
|
38
|
+
if (Component) {
|
39
|
+
var _parent;
|
40
|
+
if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
|
41
|
+
const Loading = parent.loading;
|
42
|
+
if (isLoadableComponent(Component)) {
|
43
|
+
element = /* @__PURE__ */ _jsx(Component, {
|
44
|
+
fallback: /* @__PURE__ */ _jsx(Loading, {})
|
45
|
+
});
|
46
|
+
} else {
|
47
|
+
element = /* @__PURE__ */ _jsx(Suspense, {
|
48
|
+
fallback: /* @__PURE__ */ _jsx(Loading, {}),
|
49
|
+
children: /* @__PURE__ */ _jsx(Component, {})
|
50
|
+
});
|
51
|
+
}
|
52
|
+
} else if (isLoadableComponent(Component) && lazyImport) {
|
53
|
+
element = /* @__PURE__ */ _jsx(Component, {});
|
54
|
+
} else if (isRoot) {
|
55
|
+
var _props;
|
56
|
+
element = /* @__PURE__ */ _jsxs(_Fragment, {
|
57
|
+
children: [
|
58
|
+
/* @__PURE__ */ _jsx(Component, {
|
59
|
+
...props
|
60
|
+
}),
|
61
|
+
typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
|
62
|
+
nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
|
63
|
+
})
|
64
|
+
]
|
65
|
+
});
|
66
|
+
} else if (lazyImport) {
|
67
|
+
element = /* @__PURE__ */ _jsx(Suspense, {
|
68
|
+
fallback: null,
|
69
|
+
children: /* @__PURE__ */ _jsx(Component, {})
|
70
|
+
});
|
71
|
+
} else {
|
72
|
+
element = /* @__PURE__ */ _jsx(Component, {});
|
73
|
+
}
|
74
|
+
} else {
|
75
|
+
var _parent1;
|
76
|
+
nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
|
77
|
+
}
|
78
|
+
if (element) {
|
79
|
+
routeProps.element = element;
|
80
|
+
}
|
81
|
+
const childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map((childRoute) => {
|
82
|
+
return renderNestedRoute(childRoute, {
|
83
|
+
parent: nestedRoute
|
84
|
+
});
|
85
|
+
});
|
86
|
+
const routeElement = index ? /* @__PURE__ */ _jsx(Route, {
|
87
|
+
...routeProps,
|
88
|
+
index: true
|
89
|
+
}, id) : /* @__PURE__ */ _jsx(Route, {
|
90
|
+
...routeProps,
|
91
|
+
index: false,
|
92
|
+
children: childElements
|
93
|
+
}, id);
|
94
|
+
return routeElement;
|
95
|
+
};
|
96
|
+
function createLoader(route) {
|
97
|
+
const { loader } = route;
|
98
|
+
if (loader) {
|
99
|
+
return (args) => {
|
100
|
+
if (typeof route.lazyImport === "function") {
|
101
|
+
route.lazyImport();
|
102
|
+
}
|
103
|
+
return loader(args);
|
104
|
+
};
|
105
|
+
} else {
|
106
|
+
return () => {
|
107
|
+
if (typeof route.lazyImport === "function") {
|
108
|
+
route.lazyImport();
|
109
|
+
}
|
110
|
+
return null;
|
111
|
+
};
|
112
|
+
}
|
113
|
+
}
|
114
|
+
function isLoadableComponent(component) {
|
115
|
+
return component && component.displayName === "Loadable" && component.preload && typeof component.preload === "function";
|
116
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "@remix-run/router";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "react-router-dom";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./parsed";
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export const parsedJSONFromElement = (id) => {
|
2
|
+
const elements = document.querySelectorAll(`#${id}`);
|
3
|
+
if (elements.length === 0) {
|
4
|
+
return void 0;
|
5
|
+
}
|
6
|
+
const element = elements[elements.length - 1];
|
7
|
+
if (element) {
|
8
|
+
try {
|
9
|
+
var _element;
|
10
|
+
const parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
|
11
|
+
return parsed;
|
12
|
+
} catch (e) {
|
13
|
+
console.error(`parse ${id} error`, e);
|
14
|
+
return void 0;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
return void 0;
|
18
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
function sortByUrlPath(entries) {
|
2
|
+
entries.sort(function(a, b) {
|
3
|
+
const length1 = a.urlPath.length;
|
4
|
+
const length2 = b.urlPath.length;
|
5
|
+
if (length1 < length2) {
|
6
|
+
return 1;
|
7
|
+
}
|
8
|
+
if (length1 > length2) {
|
9
|
+
return -1;
|
10
|
+
}
|
11
|
+
return 0;
|
12
|
+
});
|
13
|
+
return entries;
|
14
|
+
}
|
15
|
+
export const matchEntry = (pathname, entries) => {
|
16
|
+
sortByUrlPath(entries);
|
17
|
+
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
18
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "react-router-dom/server";
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as ah from "async_hooks";
|
2
|
+
const createStorage = () => {
|
3
|
+
let storage;
|
4
|
+
if (typeof ah.AsyncLocalStorage !== "undefined") {
|
5
|
+
storage = new ah.AsyncLocalStorage();
|
6
|
+
}
|
7
|
+
const run = (context, cb) => {
|
8
|
+
if (!storage) {
|
9
|
+
throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
|
10
|
+
`);
|
11
|
+
}
|
12
|
+
return new Promise((resolve, reject) => {
|
13
|
+
storage.run(context, () => {
|
14
|
+
try {
|
15
|
+
return resolve(cb());
|
16
|
+
} catch (error) {
|
17
|
+
return reject(error);
|
18
|
+
}
|
19
|
+
});
|
20
|
+
});
|
21
|
+
};
|
22
|
+
const useContext = () => {
|
23
|
+
if (!storage) {
|
24
|
+
throw new Error(`Unable to use async_hook, please confirm the node version >= 12.17
|
25
|
+
`);
|
26
|
+
}
|
27
|
+
const context = storage.getStore();
|
28
|
+
if (!context) {
|
29
|
+
throw new Error(`Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules`);
|
30
|
+
}
|
31
|
+
return context;
|
32
|
+
};
|
33
|
+
return {
|
34
|
+
run,
|
35
|
+
useContext
|
36
|
+
};
|
37
|
+
};
|
38
|
+
export { createStorage };
|
@@ -0,0 +1,99 @@
|
|
1
|
+
const friendlySyntaxErrorLabel = "SyntaxError:";
|
2
|
+
function isLikelyASyntaxError(message) {
|
3
|
+
return message.includes(friendlySyntaxErrorLabel);
|
4
|
+
}
|
5
|
+
function formatMessage(stats) {
|
6
|
+
let lines = [];
|
7
|
+
let message;
|
8
|
+
if (typeof stats === "object") {
|
9
|
+
const fileName = stats.moduleName ? `File: ${stats.moduleName}
|
10
|
+
` : "";
|
11
|
+
const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
|
12
|
+
const details = stats.details ? `
|
13
|
+
Details: ${stats.details}
|
14
|
+
` : "";
|
15
|
+
const stack = stats.stack ? `
|
16
|
+
${stats.stack}` : "";
|
17
|
+
message = `${fileName}${mainMessage}${details}${stack}`;
|
18
|
+
} else {
|
19
|
+
message = stats;
|
20
|
+
}
|
21
|
+
lines = message.split("\n");
|
22
|
+
lines = lines.map((line) => {
|
23
|
+
const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
|
24
|
+
if (!parsingError) {
|
25
|
+
return line;
|
26
|
+
}
|
27
|
+
const [, errorLine, errorColumn, errorMessage] = parsingError;
|
28
|
+
return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
|
29
|
+
});
|
30
|
+
message = lines.join("\n");
|
31
|
+
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)
|
32
|
+
`);
|
33
|
+
lines = message.split("\n");
|
34
|
+
if (lines.length > 2 && lines[1].trim() === "") {
|
35
|
+
lines.splice(1, 1);
|
36
|
+
}
|
37
|
+
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
|
38
|
+
if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
|
39
|
+
lines[1] = lines[1].replace("Error: ", "");
|
40
|
+
}
|
41
|
+
lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim());
|
42
|
+
message = lines.join("\n");
|
43
|
+
return message.trim();
|
44
|
+
}
|
45
|
+
const noop = (message) => message;
|
46
|
+
const defaultColor = {
|
47
|
+
gray: noop,
|
48
|
+
cyan: noop,
|
49
|
+
green: noop,
|
50
|
+
yellow: noop,
|
51
|
+
underline: noop
|
52
|
+
};
|
53
|
+
export function addErrorTips(errors, color = defaultColor) {
|
54
|
+
const errorHelpers = [
|
55
|
+
{
|
56
|
+
validator(message) {
|
57
|
+
return (message.includes("You may need an appropriate loader") || message.includes("You may need an additional loader")) && message.includes(".ts");
|
58
|
+
},
|
59
|
+
formatter(message) {
|
60
|
+
return `${message}
|
61
|
+
|
62
|
+
${color.yellow(`If it is a TypeScript file, you can use "source.include" config to compile it. see ${color.underline("https://modernjs.dev/builder/en/api/config-source.html#sourceinclude")}`)}
|
63
|
+
|
64
|
+
${color.green(`${color.gray("// config file")}
|
65
|
+
export default {
|
66
|
+
source: {
|
67
|
+
include: [
|
68
|
+
${color.gray("// add some include rules")}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
}`)}
|
72
|
+
`;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
];
|
76
|
+
return errors.map((error) => {
|
77
|
+
const helper = errorHelpers.find((item) => item.validator(error));
|
78
|
+
return helper ? helper.formatter(error) : error;
|
79
|
+
});
|
80
|
+
}
|
81
|
+
function formatWebpackMessages(json, color = defaultColor) {
|
82
|
+
var _json_errors, _json, _json_warnings, _json1, _result_errors;
|
83
|
+
const formattedErrors = (_json = json) === null || _json === void 0 ? void 0 : (_json_errors = _json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
|
84
|
+
const formattedWarnings = (_json1 = json) === null || _json1 === void 0 ? void 0 : (_json_warnings = _json1.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
|
85
|
+
const result = {
|
86
|
+
errors: formattedErrors || [],
|
87
|
+
warnings: formattedWarnings || [],
|
88
|
+
errorTips: []
|
89
|
+
};
|
90
|
+
if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
|
91
|
+
result.errors = result.errors.filter(isLikelyASyntaxError);
|
92
|
+
}
|
93
|
+
if (result.errors.length > 1) {
|
94
|
+
result.errors.length = 1;
|
95
|
+
}
|
96
|
+
result.errors = addErrorTips(result.errors, color);
|
97
|
+
return result;
|
98
|
+
}
|
99
|
+
export { formatWebpackMessages };
|
@@ -0,0 +1,50 @@
|
|
1
|
+
export const pluginDagSort = (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
|
+
var _item_preKey, _item_postKey;
|
12
|
+
(_item_preKey = item[preKey]) === null || _item_preKey === void 0 ? void 0 : _item_preKey.forEach((p) => {
|
13
|
+
if (plugins.find((ap) => ap.name === p)) {
|
14
|
+
allLines.push([
|
15
|
+
getPluginByAny(p)[key],
|
16
|
+
getPluginByAny(item)[key]
|
17
|
+
]);
|
18
|
+
}
|
19
|
+
});
|
20
|
+
(_item_postKey = item[postKey]) === null || _item_postKey === void 0 ? void 0 : _item_postKey.forEach((pt) => {
|
21
|
+
if (plugins.find((ap) => ap.name === pt)) {
|
22
|
+
allLines.push([
|
23
|
+
getPluginByAny(item)[key],
|
24
|
+
getPluginByAny(pt)[key]
|
25
|
+
]);
|
26
|
+
}
|
27
|
+
});
|
28
|
+
});
|
29
|
+
let zeroEndPoints = plugins.filter((item) => !allLines.find((l) => l[1] === item[key]));
|
30
|
+
const sortedPoint = [];
|
31
|
+
while (zeroEndPoints.length) {
|
32
|
+
const zep = zeroEndPoints.shift();
|
33
|
+
sortedPoint.push(getPluginByAny(zep));
|
34
|
+
allLines = allLines.filter((l) => l[0] !== getPluginByAny(zep)[key]);
|
35
|
+
const restPoints = plugins.filter((item) => !sortedPoint.find((sp) => sp[key] === item[key]));
|
36
|
+
zeroEndPoints = restPoints.filter(
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
38
|
+
(item) => !allLines.find((l) => l[1] === item[key])
|
39
|
+
);
|
40
|
+
}
|
41
|
+
if (allLines.length) {
|
42
|
+
const restInRingPoints = {};
|
43
|
+
allLines.forEach((l) => {
|
44
|
+
restInRingPoints[l[0]] = true;
|
45
|
+
restInRingPoints[l[1]] = true;
|
46
|
+
});
|
47
|
+
throw new Error(`plugins dependences has loop: ${Object.keys(restInRingPoints).join(",")}`);
|
48
|
+
}
|
49
|
+
return sortedPoint;
|
50
|
+
};
|
@@ -37,6 +37,8 @@ export declare const CHAIN_ID: {
|
|
37
37
|
readonly YAML: "yaml";
|
38
38
|
/** Rule for wasm */
|
39
39
|
readonly WASM: "wasm";
|
40
|
+
/** Rule for node */
|
41
|
+
readonly NODE: "node";
|
40
42
|
/** Rule for bff */
|
41
43
|
readonly JS_BFF_API: "js-bff-api";
|
42
44
|
};
|
@@ -75,6 +77,8 @@ export declare const CHAIN_ID: {
|
|
75
77
|
readonly TOML: "toml";
|
76
78
|
/** html-loader */
|
77
79
|
readonly HTML: "html";
|
80
|
+
/** node-loader */
|
81
|
+
readonly NODE: "html";
|
78
82
|
/** babel-loader */
|
79
83
|
readonly BABEL: "babel";
|
80
84
|
/** esbuild-loader */
|
@@ -6,7 +6,20 @@
|
|
6
6
|
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
7
7
|
*/
|
8
8
|
import type { StatsCompilation } from 'webpack';
|
9
|
-
declare function
|
9
|
+
export declare function addErrorTips(errors: string[], color?: {
|
10
|
+
gray: (message: string) => string;
|
11
|
+
cyan: (message: string) => string;
|
12
|
+
green: (message: string) => string;
|
13
|
+
yellow: (message: string) => string;
|
14
|
+
underline: (message: string) => string;
|
15
|
+
}): string[];
|
16
|
+
declare function formatWebpackMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>, color?: {
|
17
|
+
gray: (message: string) => string;
|
18
|
+
cyan: (message: string) => string;
|
19
|
+
green: (message: string) => string;
|
20
|
+
yellow: (message: string) => string;
|
21
|
+
underline: (message: string) => string;
|
22
|
+
}): {
|
10
23
|
errors: string[];
|
11
24
|
warnings: string[];
|
12
25
|
};
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.28.0",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -235,9 +235,9 @@
|
|
235
235
|
"typescript": "^5",
|
236
236
|
"webpack": "^5.88.1",
|
237
237
|
"@types/serialize-javascript": "^5.0.1",
|
238
|
-
"@modern-js/types": "2.
|
239
|
-
"@scripts/
|
240
|
-
"@scripts/
|
238
|
+
"@modern-js/types": "2.28.0",
|
239
|
+
"@scripts/build": "2.28.0",
|
240
|
+
"@scripts/jest-config": "2.28.0"
|
241
241
|
},
|
242
242
|
"sideEffects": false,
|
243
243
|
"scripts": {
|