@modern-js/utils 2.26.0 → 2.28.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 +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
package/dist/esm/cli/watch.js
CHANGED
|
@@ -1,40 +1,107 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
1
3
|
import path from "path";
|
|
2
4
|
import { chokidar } from "../compiled";
|
|
3
|
-
export
|
|
5
|
+
export var WatchChangeType = {
|
|
4
6
|
ADD: "add",
|
|
5
7
|
UNLINK: "unlink",
|
|
6
8
|
CHANGE: "change"
|
|
7
9
|
};
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
export var watch = function(watchDir, runTask) {
|
|
11
|
+
var ignored = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
|
|
12
|
+
var ready = false;
|
|
13
|
+
var watcher = chokidar.watch(watchDir, {
|
|
14
|
+
ignored: ignored
|
|
12
15
|
});
|
|
13
|
-
watcher.on("ready", ()
|
|
14
|
-
|
|
15
|
-
const changedFilePath = path.resolve(filePath);
|
|
16
|
-
await runTask({
|
|
17
|
-
changedFilePath,
|
|
18
|
-
changeType: WatchChangeType.CHANGE
|
|
19
|
-
});
|
|
16
|
+
watcher.on("ready", function() {
|
|
17
|
+
return ready = true;
|
|
20
18
|
});
|
|
21
|
-
watcher.on("
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
watcher.on("change", function() {
|
|
20
|
+
var _ref = _async_to_generator(function(filePath) {
|
|
21
|
+
var changedFilePath;
|
|
22
|
+
return _ts_generator(this, function(_state) {
|
|
23
|
+
switch (_state.label) {
|
|
24
|
+
case 0:
|
|
25
|
+
changedFilePath = path.resolve(filePath);
|
|
26
|
+
return [
|
|
27
|
+
4,
|
|
28
|
+
runTask({
|
|
29
|
+
changedFilePath: changedFilePath,
|
|
30
|
+
changeType: WatchChangeType.CHANGE
|
|
31
|
+
})
|
|
32
|
+
];
|
|
33
|
+
case 1:
|
|
34
|
+
_state.sent();
|
|
35
|
+
return [
|
|
36
|
+
2
|
|
37
|
+
];
|
|
38
|
+
}
|
|
27
39
|
});
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
watcher.on("unlink", async (filePath) => {
|
|
31
|
-
const changedFilePath = path.resolve(filePath);
|
|
32
|
-
await runTask({
|
|
33
|
-
changedFilePath,
|
|
34
|
-
changeType: WatchChangeType.UNLINK
|
|
35
40
|
});
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
return function(filePath) {
|
|
42
|
+
return _ref.apply(this, arguments);
|
|
43
|
+
};
|
|
44
|
+
}());
|
|
45
|
+
watcher.on("add", function() {
|
|
46
|
+
var _ref = _async_to_generator(function(filePath) {
|
|
47
|
+
var changedFilePath;
|
|
48
|
+
return _ts_generator(this, function(_state) {
|
|
49
|
+
switch (_state.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
changedFilePath = path.resolve(filePath);
|
|
52
|
+
if (!ready)
|
|
53
|
+
return [
|
|
54
|
+
3,
|
|
55
|
+
2
|
|
56
|
+
];
|
|
57
|
+
return [
|
|
58
|
+
4,
|
|
59
|
+
runTask({
|
|
60
|
+
changedFilePath: changedFilePath,
|
|
61
|
+
changeType: WatchChangeType.ADD
|
|
62
|
+
})
|
|
63
|
+
];
|
|
64
|
+
case 1:
|
|
65
|
+
_state.sent();
|
|
66
|
+
_state.label = 2;
|
|
67
|
+
case 2:
|
|
68
|
+
return [
|
|
69
|
+
2
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return function(filePath) {
|
|
75
|
+
return _ref.apply(this, arguments);
|
|
76
|
+
};
|
|
77
|
+
}());
|
|
78
|
+
watcher.on("unlink", function() {
|
|
79
|
+
var _ref = _async_to_generator(function(filePath) {
|
|
80
|
+
var changedFilePath;
|
|
81
|
+
return _ts_generator(this, function(_state) {
|
|
82
|
+
switch (_state.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
changedFilePath = path.resolve(filePath);
|
|
85
|
+
return [
|
|
86
|
+
4,
|
|
87
|
+
runTask({
|
|
88
|
+
changedFilePath: changedFilePath,
|
|
89
|
+
changeType: WatchChangeType.UNLINK
|
|
90
|
+
})
|
|
91
|
+
];
|
|
92
|
+
case 1:
|
|
93
|
+
_state.sent();
|
|
94
|
+
return [
|
|
95
|
+
2
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return function(filePath) {
|
|
101
|
+
return _ref.apply(this, arguments);
|
|
102
|
+
};
|
|
103
|
+
}());
|
|
104
|
+
watcher.on("error", function(err) {
|
|
38
105
|
throw err;
|
|
39
106
|
});
|
|
40
107
|
return watcher;
|
package/dist/esm/compiled.js
CHANGED
|
@@ -28,6 +28,6 @@ export { default as browserslist } from "../compiled/browserslist";
|
|
|
28
28
|
export { default as recursiveReaddir } from "../compiled/recursive-readdir";
|
|
29
29
|
export { program, Command } from "../compiled/commander";
|
|
30
30
|
export { Signale } from "../compiled/signale";
|
|
31
|
-
export
|
|
32
|
-
export
|
|
33
|
-
export
|
|
31
|
+
export var mime = Import.lazy("../compiled/mime-types", require);
|
|
32
|
+
export var chokidar = Import.lazy("../compiled/chokidar", require);
|
|
33
|
+
export var inquirer = Import.lazy("../compiled/inquirer", require);
|
package/dist/esm/import.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var lazy = function(moduleName, requireFn) {
|
|
2
|
+
var importLazyLocal = require("../compiled/import-lazy")(requireFn);
|
|
3
3
|
return importLazyLocal(moduleName);
|
|
4
4
|
};
|
|
5
5
|
export { lazy as lazyImport };
|
|
6
|
-
export
|
|
7
|
-
lazy
|
|
6
|
+
export var Import = {
|
|
7
|
+
lazy: lazy
|
|
8
8
|
};
|
|
@@ -1,19 +1,40 @@
|
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
1
3
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
4
|
import { Suspense } from "react";
|
|
3
5
|
import { createRoutesFromElements, Route } from "react-router-dom";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export var transformNestedRoutes = function(routes) {
|
|
7
|
+
var routeElements = [];
|
|
8
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
9
|
+
try {
|
|
10
|
+
for (var _iterator = routes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
11
|
+
var route = _step.value;
|
|
12
|
+
var routeElement = renderNestedRoute(route);
|
|
13
|
+
routeElements.push(routeElement);
|
|
14
|
+
}
|
|
15
|
+
} catch (err) {
|
|
16
|
+
_didIteratorError = true;
|
|
17
|
+
_iteratorError = err;
|
|
18
|
+
} finally {
|
|
19
|
+
try {
|
|
20
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
21
|
+
_iterator.return();
|
|
22
|
+
}
|
|
23
|
+
} finally {
|
|
24
|
+
if (_didIteratorError) {
|
|
25
|
+
throw _iteratorError;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
9
28
|
}
|
|
10
29
|
return createRoutesFromElements(routeElements);
|
|
11
30
|
};
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
export var renderNestedRoute = function(nestedRoute) {
|
|
32
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
33
|
+
var _config, _children;
|
|
34
|
+
var children = nestedRoute.children, index = nestedRoute.index, id = nestedRoute.id, component = nestedRoute.component, isRoot = nestedRoute.isRoot, lazyImport = nestedRoute.lazyImport, config = nestedRoute.config, handle = nestedRoute.handle;
|
|
35
|
+
var Component = component;
|
|
36
|
+
var parent = options.parent, DeferredDataComponent = options.DeferredDataComponent, _options_props = options.props, props = _options_props === void 0 ? {} : _options_props;
|
|
37
|
+
var routeProps = {
|
|
17
38
|
caseSensitive: nestedRoute.caseSensitive,
|
|
18
39
|
path: nestedRoute.path,
|
|
19
40
|
id: nestedRoute.id,
|
|
@@ -21,22 +42,20 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
|
|
|
21
42
|
action: nestedRoute.action,
|
|
22
43
|
hasErrorBoundary: nestedRoute.hasErrorBoundary,
|
|
23
44
|
shouldRevalidate: nestedRoute.shouldRevalidate,
|
|
24
|
-
handle: {
|
|
25
|
-
...handle,
|
|
26
|
-
...typeof config === "object" ? config === null || config === void 0 ? void 0 : config.handle : {}
|
|
27
|
-
},
|
|
45
|
+
handle: _object_spread({}, handle, typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _config.handle : {}),
|
|
28
46
|
index: nestedRoute.index,
|
|
29
47
|
element: nestedRoute.element,
|
|
30
48
|
errorElement: nestedRoute.errorElement
|
|
31
49
|
};
|
|
32
50
|
if (nestedRoute.error) {
|
|
33
|
-
|
|
51
|
+
var errorElement = /* @__PURE__ */ _jsx(nestedRoute.error, {});
|
|
34
52
|
routeProps.errorElement = errorElement;
|
|
35
53
|
}
|
|
36
|
-
|
|
54
|
+
var element;
|
|
37
55
|
if (Component) {
|
|
38
|
-
|
|
39
|
-
|
|
56
|
+
var _parent;
|
|
57
|
+
if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
|
|
58
|
+
var Loading = parent.loading;
|
|
40
59
|
if (isLoadableComponent(Component)) {
|
|
41
60
|
element = /* @__PURE__ */ _jsx(Component, {
|
|
42
61
|
fallback: /* @__PURE__ */ _jsx(Loading, {})
|
|
@@ -50,13 +69,12 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
|
|
|
50
69
|
} else if (isLoadableComponent(Component) && lazyImport) {
|
|
51
70
|
element = /* @__PURE__ */ _jsx(Component, {});
|
|
52
71
|
} else if (isRoot) {
|
|
72
|
+
var _props;
|
|
53
73
|
element = /* @__PURE__ */ _jsxs(_Fragment, {
|
|
54
74
|
children: [
|
|
55
|
-
/* @__PURE__ */ _jsx(Component, {
|
|
56
|
-
...props
|
|
57
|
-
}),
|
|
75
|
+
/* @__PURE__ */ _jsx(Component, _object_spread({}, props)),
|
|
58
76
|
typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
|
|
59
|
-
nonce: props === null ||
|
|
77
|
+
nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
|
|
60
78
|
})
|
|
61
79
|
]
|
|
62
80
|
});
|
|
@@ -69,37 +87,36 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
|
|
|
69
87
|
element = /* @__PURE__ */ _jsx(Component, {});
|
|
70
88
|
}
|
|
71
89
|
} else {
|
|
72
|
-
|
|
90
|
+
var _parent1;
|
|
91
|
+
nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
|
|
73
92
|
}
|
|
74
93
|
if (element) {
|
|
75
94
|
routeProps.element = element;
|
|
76
95
|
}
|
|
77
|
-
|
|
96
|
+
var childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map(function(childRoute) {
|
|
78
97
|
return renderNestedRoute(childRoute, {
|
|
79
98
|
parent: nestedRoute
|
|
80
99
|
});
|
|
81
100
|
});
|
|
82
|
-
|
|
83
|
-
...routeProps,
|
|
101
|
+
var routeElement = index ? /* @__PURE__ */ _jsx(Route, _object_spread_props(_object_spread({}, routeProps), {
|
|
84
102
|
index: true
|
|
85
|
-
}, id) : /* @__PURE__ */ _jsx(Route, {
|
|
86
|
-
...routeProps,
|
|
103
|
+
}), id) : /* @__PURE__ */ _jsx(Route, _object_spread_props(_object_spread({}, routeProps), {
|
|
87
104
|
index: false,
|
|
88
105
|
children: childElements
|
|
89
|
-
}, id);
|
|
106
|
+
}), id);
|
|
90
107
|
return routeElement;
|
|
91
108
|
};
|
|
92
109
|
function createLoader(route) {
|
|
93
|
-
|
|
110
|
+
var loader = route.loader;
|
|
94
111
|
if (loader) {
|
|
95
|
-
return (args)
|
|
112
|
+
return function(args) {
|
|
96
113
|
if (typeof route.lazyImport === "function") {
|
|
97
114
|
route.lazyImport();
|
|
98
115
|
}
|
|
99
116
|
return loader(args);
|
|
100
117
|
};
|
|
101
118
|
} else {
|
|
102
|
-
return ()
|
|
119
|
+
return function() {
|
|
103
120
|
if (typeof route.lazyImport === "function") {
|
|
104
121
|
route.lazyImport();
|
|
105
122
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export var parsedJSONFromElement = function(id) {
|
|
2
|
+
var elements = document.querySelectorAll("#".concat(id));
|
|
3
3
|
if (elements.length === 0) {
|
|
4
4
|
return void 0;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
var element = elements[elements.length - 1];
|
|
7
7
|
if (element) {
|
|
8
8
|
try {
|
|
9
|
-
|
|
9
|
+
var _element;
|
|
10
|
+
var parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
|
|
10
11
|
return parsed;
|
|
11
12
|
} catch (e) {
|
|
12
|
-
console.error(
|
|
13
|
+
console.error("parse ".concat(id, " error"), e);
|
|
13
14
|
return void 0;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createStorage } from "./storage";
|
|
2
|
-
|
|
2
|
+
var _createStorage = createStorage(), run = _createStorage.run, useHeaders = _createStorage.useContext;
|
|
3
3
|
export { run, useHeaders };
|
|
4
4
|
export { serializeJson } from "./serialize";
|
|
5
5
|
export * from "./nestedRoutes";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function sortByUrlPath(entries) {
|
|
2
2
|
entries.sort(function(a, b) {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var length1 = a.urlPath.length;
|
|
4
|
+
var length2 = b.urlPath.length;
|
|
5
5
|
if (length1 < length2) {
|
|
6
6
|
return 1;
|
|
7
7
|
}
|
|
@@ -12,7 +12,9 @@ function sortByUrlPath(entries) {
|
|
|
12
12
|
});
|
|
13
13
|
return entries;
|
|
14
14
|
}
|
|
15
|
-
export
|
|
15
|
+
export var matchEntry = function(pathname, entries) {
|
|
16
16
|
sortByUrlPath(entries);
|
|
17
|
-
return entries.find((entry)
|
|
17
|
+
return entries.find(function(entry) {
|
|
18
|
+
return pathname.startsWith(entry.urlPath);
|
|
19
|
+
});
|
|
18
20
|
};
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import * as ah from "async_hooks";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
var createStorage = function() {
|
|
3
|
+
var storage;
|
|
4
4
|
if (typeof ah.AsyncLocalStorage !== "undefined") {
|
|
5
5
|
storage = new ah.AsyncLocalStorage();
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
var run = function(context, cb) {
|
|
8
8
|
if (!storage) {
|
|
9
|
-
throw new Error(
|
|
10
|
-
`);
|
|
9
|
+
throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
|
|
11
10
|
}
|
|
12
|
-
return new Promise((resolve, reject)
|
|
13
|
-
storage.run(context, ()
|
|
11
|
+
return new Promise(function(resolve, reject) {
|
|
12
|
+
storage.run(context, function() {
|
|
14
13
|
try {
|
|
15
14
|
return resolve(cb());
|
|
16
15
|
} catch (error) {
|
|
@@ -19,20 +18,19 @@ const createStorage = () => {
|
|
|
19
18
|
});
|
|
20
19
|
});
|
|
21
20
|
};
|
|
22
|
-
|
|
21
|
+
var useContext = function() {
|
|
23
22
|
if (!storage) {
|
|
24
|
-
throw new Error(
|
|
25
|
-
`);
|
|
23
|
+
throw new Error("Unable to use async_hook, please confirm the node version >= 12.17\n ");
|
|
26
24
|
}
|
|
27
|
-
|
|
25
|
+
var context = storage.getStore();
|
|
28
26
|
if (!context) {
|
|
29
|
-
throw new Error(
|
|
27
|
+
throw new Error("Can't call useContext out of scope, make sure @modern-js/utils is a single version in node_modules");
|
|
30
28
|
}
|
|
31
29
|
return context;
|
|
32
30
|
};
|
|
33
31
|
return {
|
|
34
|
-
run,
|
|
35
|
-
useContext
|
|
32
|
+
run: run,
|
|
33
|
+
useContext: useContext
|
|
36
34
|
};
|
|
37
35
|
};
|
|
38
36
|
export { createStorage };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export var ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
|
|
2
|
+
export var HMR_SOCK_PATH = "/webpack-hmr";
|
|
3
|
+
export var HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
|
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
2
|
+
var friendlySyntaxErrorLabel = "SyntaxError:";
|
|
2
3
|
function isLikelyASyntaxError(message) {
|
|
3
4
|
return message.includes(friendlySyntaxErrorLabel);
|
|
4
5
|
}
|
|
5
6
|
function formatMessage(stats) {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
var lines = [];
|
|
8
|
+
var message;
|
|
8
9
|
if (typeof stats === "object") {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
` : "";
|
|
15
|
-
const stack = stats.stack ? `
|
|
16
|
-
${stats.stack}` : "";
|
|
17
|
-
message = `${fileName}${mainMessage}${details}${stack}`;
|
|
10
|
+
var fileName = stats.moduleName ? "File: ".concat(stats.moduleName, "\n") : "";
|
|
11
|
+
var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
|
|
12
|
+
var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
|
|
13
|
+
var stack = stats.stack ? "\n".concat(stats.stack) : "";
|
|
14
|
+
message = "".concat(fileName).concat(mainMessage).concat(details).concat(stack);
|
|
18
15
|
} else {
|
|
19
16
|
message = stats;
|
|
20
17
|
}
|
|
21
18
|
lines = message.split("\n");
|
|
22
|
-
lines = lines.map((line)
|
|
23
|
-
|
|
19
|
+
lines = lines.map(function(line) {
|
|
20
|
+
var parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
|
|
24
21
|
if (!parsingError) {
|
|
25
22
|
return line;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
return
|
|
24
|
+
var _parsingError = _sliced_to_array(parsingError, 4), errorLine = _parsingError[1], errorColumn = _parsingError[2], errorMessage = _parsingError[3];
|
|
25
|
+
return "".concat(friendlySyntaxErrorLabel, " ").concat(errorMessage, " (").concat(errorLine, ":").concat(errorColumn, ")");
|
|
29
26
|
});
|
|
30
27
|
message = lines.join("\n");
|
|
31
|
-
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g,
|
|
32
|
-
`);
|
|
28
|
+
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "".concat(friendlySyntaxErrorLabel, " $3 ($1:$2)\n"));
|
|
33
29
|
lines = message.split("\n");
|
|
34
30
|
if (lines.length > 2 && lines[1].trim() === "") {
|
|
35
31
|
lines.splice(1, 1);
|
|
@@ -38,21 +34,50 @@ ${stats.stack}` : "";
|
|
|
38
34
|
if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
|
|
39
35
|
lines[1] = lines[1].replace("Error: ", "");
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
lines = message.split("\n");
|
|
45
|
-
lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim());
|
|
37
|
+
lines = lines.filter(function(line, index, arr) {
|
|
38
|
+
return index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim();
|
|
39
|
+
});
|
|
46
40
|
message = lines.join("\n");
|
|
47
41
|
return message.trim();
|
|
48
42
|
}
|
|
43
|
+
var noop = function(message) {
|
|
44
|
+
return message;
|
|
45
|
+
};
|
|
46
|
+
var defaultColor = {
|
|
47
|
+
gray: noop,
|
|
48
|
+
cyan: noop,
|
|
49
|
+
green: noop,
|
|
50
|
+
yellow: noop,
|
|
51
|
+
underline: noop
|
|
52
|
+
};
|
|
53
|
+
export function addErrorTips(errors) {
|
|
54
|
+
var color = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : defaultColor;
|
|
55
|
+
var errorHelpers = [
|
|
56
|
+
{
|
|
57
|
+
validator: function validator(message) {
|
|
58
|
+
return (message.includes("You may need an appropriate loader") || message.includes("You may need an additional loader")) && message.includes(".ts");
|
|
59
|
+
},
|
|
60
|
+
formatter: function formatter(message) {
|
|
61
|
+
return "".concat(message, "\n\n").concat(color.yellow('If it is a TypeScript file, you can use "source.include" config to compile it. see '.concat(color.underline("https://modernjs.dev/builder/en/api/config-source.html#sourceinclude"))), "\n\n").concat(color.green("".concat(color.gray("// config file"), "\nexport default {\n source: {\n include: [\n ").concat(color.gray("// add some include rules"), "\n ]\n }\n}")), "\n ");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
];
|
|
65
|
+
return errors.map(function(error) {
|
|
66
|
+
var helper = errorHelpers.find(function(item) {
|
|
67
|
+
return item.validator(error);
|
|
68
|
+
});
|
|
69
|
+
return helper ? helper.formatter(error) : error;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
49
72
|
function formatWebpackMessages(json) {
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
73
|
+
var color = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : defaultColor;
|
|
74
|
+
var _json_errors, _json, _json_warnings, _json1, _result_errors;
|
|
75
|
+
var formattedErrors = (_json = json) === null || _json === void 0 ? void 0 : (_json_errors = _json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
|
|
76
|
+
var formattedWarnings = (_json1 = json) === null || _json1 === void 0 ? void 0 : (_json_warnings = _json1.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
|
|
77
|
+
var result = {
|
|
54
78
|
errors: formattedErrors || [],
|
|
55
|
-
warnings: formattedWarnings || []
|
|
79
|
+
warnings: formattedWarnings || [],
|
|
80
|
+
errorTips: []
|
|
56
81
|
};
|
|
57
82
|
if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
|
|
58
83
|
result.errors = result.errors.filter(isLikelyASyntaxError);
|
|
@@ -60,6 +85,7 @@ function formatWebpackMessages(json) {
|
|
|
60
85
|
if (result.errors.length > 1) {
|
|
61
86
|
result.errors.length = 1;
|
|
62
87
|
}
|
|
88
|
+
result.errors = addErrorTips(result.errors, color);
|
|
63
89
|
return result;
|
|
64
90
|
}
|
|
65
91
|
export { formatWebpackMessages };
|
|
@@ -1,24 +1,51 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export var pluginDagSort = function(plugins) {
|
|
2
|
+
var _loop = function() {
|
|
3
|
+
var zep = zeroEndPoints.shift();
|
|
4
|
+
sortedPoint.push(getPluginByAny(zep));
|
|
5
|
+
allLines = allLines.filter(function(l) {
|
|
6
|
+
return l[0] !== getPluginByAny(zep)[key];
|
|
7
|
+
});
|
|
8
|
+
var restPoints = plugins.filter(function(item) {
|
|
9
|
+
return !sortedPoint.find(function(sp) {
|
|
10
|
+
return sp[key] === item[key];
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
zeroEndPoints = restPoints.filter(
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
15
|
+
function(item) {
|
|
16
|
+
return !allLines.find(function(l) {
|
|
17
|
+
return l[1] === item[key];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
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";
|
|
23
|
+
var getPluginByAny = function getPluginByAny2(q) {
|
|
24
|
+
var target = plugins.find(function(item) {
|
|
25
|
+
return typeof q === "string" ? item[key] === q : item[key] === q[key];
|
|
26
|
+
});
|
|
5
27
|
if (!target) {
|
|
6
|
-
throw new Error(
|
|
28
|
+
throw new Error("plugin ".concat(q, " not existed"));
|
|
7
29
|
}
|
|
8
30
|
return target;
|
|
9
|
-
}
|
|
10
|
-
|
|
31
|
+
};
|
|
32
|
+
var allLines = [];
|
|
33
|
+
plugins.forEach(function(item) {
|
|
11
34
|
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)
|
|
35
|
+
(_item_preKey = item[preKey]) === null || _item_preKey === void 0 ? void 0 : _item_preKey.forEach(function(p) {
|
|
36
|
+
if (plugins.find(function(ap) {
|
|
37
|
+
return ap.name === p;
|
|
38
|
+
})) {
|
|
14
39
|
allLines.push([
|
|
15
40
|
getPluginByAny(p)[key],
|
|
16
41
|
getPluginByAny(item)[key]
|
|
17
42
|
]);
|
|
18
43
|
}
|
|
19
44
|
});
|
|
20
|
-
(_item_postKey = item[postKey]) === null || _item_postKey === void 0 ? void 0 : _item_postKey.forEach((pt)
|
|
21
|
-
if (plugins.find((ap)
|
|
45
|
+
(_item_postKey = item[postKey]) === null || _item_postKey === void 0 ? void 0 : _item_postKey.forEach(function(pt) {
|
|
46
|
+
if (plugins.find(function(ap) {
|
|
47
|
+
return ap.name === pt;
|
|
48
|
+
})) {
|
|
22
49
|
allLines.push([
|
|
23
50
|
getPluginByAny(item)[key],
|
|
24
51
|
getPluginByAny(pt)[key]
|
|
@@ -26,25 +53,21 @@ export const pluginDagSort = (plugins, key = "name", preKey = "pre", postKey = "
|
|
|
26
53
|
}
|
|
27
54
|
});
|
|
28
55
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
|
38
|
-
(item) => !allLines.find((l) => l[1] === item[key])
|
|
39
|
-
);
|
|
40
|
-
}
|
|
56
|
+
var zeroEndPoints = plugins.filter(function(item) {
|
|
57
|
+
return !allLines.find(function(l) {
|
|
58
|
+
return l[1] === item[key];
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var sortedPoint = [];
|
|
62
|
+
while (zeroEndPoints.length)
|
|
63
|
+
_loop();
|
|
41
64
|
if (allLines.length) {
|
|
42
|
-
|
|
43
|
-
allLines.forEach((l)
|
|
65
|
+
var restInRingPoints = {};
|
|
66
|
+
allLines.forEach(function(l) {
|
|
44
67
|
restInRingPoints[l[0]] = true;
|
|
45
68
|
restInRingPoints[l[1]] = true;
|
|
46
69
|
});
|
|
47
|
-
throw new Error(
|
|
70
|
+
throw new Error("plugins dependences has loop: ".concat(Object.keys(restInRingPoints).join(",")));
|
|
48
71
|
}
|
|
49
72
|
return sortedPoint;
|
|
50
73
|
};
|