@modern-js/utils 2.27.0 → 2.29.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +32 -0
- package/dist/cjs/cli/alias.js +3 -3
- package/dist/cjs/cli/constants/chainId.js +10 -0
- package/dist/cjs/cli/constants/index.js +1 -2
- package/dist/cjs/cli/index.js +0 -1
- package/dist/cjs/cli/is/config.js +13 -9
- package/dist/cjs/cli/logger.js +9 -0
- package/dist/cjs/cli/path.js +0 -23
- package/dist/cjs/cli/prettyInstructions.js +6 -5
- 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 -8
- package/dist/cjs/universal/time.js +38 -0
- package/dist/esm/cli/alias.js +3 -3
- package/dist/esm/cli/constants/chainId.js +10 -0
- package/dist/esm/cli/constants/index.js +1 -2
- package/dist/esm/cli/get/data.js +12 -3
- package/dist/esm/cli/index.js +0 -1
- package/dist/esm/cli/is/config.js +14 -9
- package/dist/esm/cli/logger.js +10 -0
- package/dist/esm/cli/path.js +2 -22
- package/dist/esm/cli/prettyInstructions.js +6 -5
- package/dist/esm/cli/require.js +2 -1
- package/dist/esm/runtime/nestedRoutes.js +9 -5
- package/dist/esm/runtime-browser/parsed.js +2 -1
- package/dist/esm/universal/formatWebpack.js +36 -4
- package/dist/esm/universal/time.js +29 -0
- package/dist/esm-node/cli/alias.js +3 -3
- package/dist/esm-node/cli/constants/chainId.js +10 -0
- package/dist/esm-node/cli/constants/index.js +1 -2
- package/dist/esm-node/cli/index.js +0 -1
- package/dist/esm-node/cli/is/config.js +13 -9
- package/dist/esm-node/cli/logger.js +6 -0
- package/dist/esm-node/cli/path.js +2 -16
- package/dist/esm-node/cli/prettyInstructions.js +6 -5
- package/dist/esm-node/cli/require.js +2 -1
- package/dist/esm-node/runtime/nestedRoutes.js +9 -5
- package/dist/esm-node/runtime-browser/parsed.js +2 -1
- package/dist/esm-node/universal/formatWebpack.js +43 -5
- package/dist/esm-node/universal/time.js +28 -0
- package/dist/types/cli/constants/chainId.d.ts +10 -0
- package/dist/types/cli/constants/index.d.ts +1 -1
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/is/config.d.ts +1 -1
- package/dist/types/cli/logger.d.ts +1 -0
- package/dist/types/cli/path.d.ts +0 -9
- package/dist/types/universal/formatWebpack.d.ts +14 -1
- package/dist/types/universal/time.d.ts +1 -0
- package/package.json +12 -4
- package/dist/cjs/cli/pathSerializer.js +0 -72
- package/dist/esm/cli/pathSerializer.js +0 -60
- package/dist/esm-node/cli/pathSerializer.js +0 -46
- package/dist/types/cli/pathSerializer.d.ts +0 -16
@@ -1,10 +1,12 @@
|
|
1
|
+
import { MAIN_ENTRY_NAME } from "../constants";
|
1
2
|
import { isEmpty } from "./type";
|
2
3
|
export var isSSR = function(config) {
|
4
|
+
var _server, _server1;
|
3
5
|
var server = config.server;
|
4
|
-
if (server === null ||
|
6
|
+
if ((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) {
|
5
7
|
return true;
|
6
8
|
}
|
7
|
-
if ((server === null ||
|
9
|
+
if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
|
8
10
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
9
11
|
try {
|
10
12
|
for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
@@ -31,29 +33,32 @@ export var isSSR = function(config) {
|
|
31
33
|
return false;
|
32
34
|
};
|
33
35
|
export var isUseSSRBundle = function(config) {
|
36
|
+
var _output;
|
34
37
|
var output = config.output;
|
35
|
-
if (output === null ||
|
38
|
+
if ((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) {
|
36
39
|
return true;
|
37
40
|
}
|
38
41
|
return isSSR(config);
|
39
42
|
};
|
40
43
|
export var isServiceWorker = function(config) {
|
41
|
-
var _deploy_worker;
|
44
|
+
var _deploy_worker, _deploy, _output;
|
42
45
|
var output = config.output, deploy = config.deploy;
|
43
|
-
if ((deploy === null ||
|
46
|
+
if (((_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr) && (((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) || isSSR(config))) {
|
44
47
|
return true;
|
45
48
|
}
|
46
49
|
return false;
|
47
50
|
};
|
48
51
|
export var isRouterV5 = function(config) {
|
49
|
-
var _config_runtime, _config_runtime1,
|
50
|
-
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null ||
|
52
|
+
var _config_runtime, _config_runtime_router, _config_runtime1, _config;
|
53
|
+
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && ((_config = config) === null || _config === void 0 ? void 0 : (_config_runtime1 = _config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
|
51
54
|
};
|
52
55
|
export var isSSGEntry = function(config, entryName, entrypoints) {
|
56
|
+
var _config_source, _ssgConfig, _ssgConfig1;
|
53
57
|
var ssgConfig = config.output.ssg;
|
54
|
-
var useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig === null ||
|
58
|
+
var useSSG = isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
|
55
59
|
return useSSG;
|
56
60
|
};
|
57
61
|
export var isSingleEntry = function(entrypoints) {
|
58
|
-
|
62
|
+
var mainEntryName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : MAIN_ENTRY_NAME;
|
63
|
+
return entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
|
59
64
|
};
|
package/dist/esm/cli/logger.js
CHANGED
@@ -45,6 +45,11 @@ var DEFAULT_CONFIG = {
|
|
45
45
|
displayLabel: true,
|
46
46
|
uppercaseLabel: false
|
47
47
|
};
|
48
|
+
var errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
|
49
|
+
var anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
|
50
|
+
export var isErrorStackMessage = function(message) {
|
51
|
+
return errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
|
52
|
+
};
|
48
53
|
var Logger = /* @__PURE__ */ function() {
|
49
54
|
"use strict";
|
50
55
|
function Logger2() {
|
@@ -87,6 +92,11 @@ var Logger = /* @__PURE__ */ function() {
|
|
87
92
|
} else {
|
88
93
|
text = message.message;
|
89
94
|
}
|
95
|
+
} else if (logType.level === "error" && typeof message === "string") {
|
96
|
+
var lines = message.split("\n");
|
97
|
+
text = lines.map(function(line) {
|
98
|
+
return isErrorStackMessage(line) ? chalk.gray(line) : line;
|
99
|
+
}).join("\n");
|
90
100
|
} else {
|
91
101
|
text = "".concat(message);
|
92
102
|
}
|
package/dist/esm/cli/path.js
CHANGED
@@ -2,7 +2,7 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
2
|
import path from "path";
|
3
3
|
import os from "os";
|
4
4
|
import fs from "fs";
|
5
|
-
import { nanoid, upath
|
5
|
+
import { nanoid, upath } from "../compiled";
|
6
6
|
export var isPathString = function(test) {
|
7
7
|
return path.posix.basename(test) !== test || path.win32.basename(test) !== test;
|
8
8
|
};
|
@@ -13,7 +13,7 @@ export var normalizeOutputPath = function(s) {
|
|
13
13
|
return s.replace(/\\/g, "\\\\");
|
14
14
|
};
|
15
15
|
export var normalizeToPosixPath = function(p) {
|
16
|
-
return upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, function(
|
16
|
+
return upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, function(_, m) {
|
17
17
|
return "/".concat(m.toLowerCase());
|
18
18
|
});
|
19
19
|
};
|
@@ -27,26 +27,6 @@ export var getTemplatePath = function(prefix) {
|
|
27
27
|
parts.push(nanoid());
|
28
28
|
return (_path = path).resolve.apply(_path, _to_consumable_array(parts));
|
29
29
|
};
|
30
|
-
export function compilePathMatcherRegExp(match) {
|
31
|
-
if (typeof match !== "string") {
|
32
|
-
return match;
|
33
|
-
}
|
34
|
-
var escaped = _.escapeRegExp(match);
|
35
|
-
return new RegExp("(?<=\\W|^)".concat(escaped, "(?=\\W|$)"));
|
36
|
-
}
|
37
|
-
export var _joinPathParts = function(_part, i, parts) {
|
38
|
-
return _(parts).filter(function(part) {
|
39
|
-
return ![
|
40
|
-
"/",
|
41
|
-
"\\"
|
42
|
-
].includes(part);
|
43
|
-
}).tap(function(parts2) {
|
44
|
-
return parts2.unshift("");
|
45
|
-
}).slice(0, i + 2).join("/");
|
46
|
-
};
|
47
|
-
export function upwardPaths(start) {
|
48
|
-
return _(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
|
49
|
-
}
|
50
30
|
export function getRealTemporaryDirectory() {
|
51
31
|
var ret = null;
|
52
32
|
try {
|
@@ -24,7 +24,8 @@ export var getAddressUrls = function() {
|
|
24
24
|
var LOCAL_LABEL = "Local: ";
|
25
25
|
var NETWORK_LABEL = "Network: ";
|
26
26
|
var isLocalhost = function(url) {
|
27
|
-
|
27
|
+
var _url;
|
28
|
+
return (_url = url) === null || _url === void 0 ? void 0 : _url.includes("localhost");
|
28
29
|
};
|
29
30
|
if (host && host !== DEFAULT_DEV_HOST) {
|
30
31
|
return [
|
@@ -51,15 +52,15 @@ export var getAddressUrls = function() {
|
|
51
52
|
}, []);
|
52
53
|
};
|
53
54
|
export var prettyInstructions = function(appContext, config) {
|
54
|
-
var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
|
55
|
+
var _appContext_builder_context_devServer, _appContext_builder, _config_dev, _config_source;
|
55
56
|
var entrypoints = appContext.entrypoints, serverRoutes = appContext.serverRoutes, port = appContext.port, apiOnly = appContext.apiOnly, checkedEntries = appContext.checkedEntries;
|
56
|
-
var isHttps = isDev() && ((
|
57
|
+
var isHttps = isDev() && ((_appContext_builder = appContext.builder) === null || _appContext_builder === void 0 ? void 0 : (_appContext_builder_context_devServer = _appContext_builder.context.devServer) === null || _appContext_builder_context_devServer === void 0 ? void 0 : _appContext_builder_context_devServer.https);
|
57
58
|
var urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
|
58
59
|
var routes = !apiOnly ? serverRoutes.filter(function(route) {
|
59
60
|
return route.entryName;
|
60
61
|
}) : serverRoutes;
|
61
62
|
var message = "App running at:\n\n";
|
62
|
-
if (isSingleEntry(entrypoints) || apiOnly) {
|
63
|
+
if (isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) || apiOnly) {
|
63
64
|
message += urls.map(function(param) {
|
64
65
|
var label = param.label, url = param.url;
|
65
66
|
return " ".concat(chalk.bold("> ".concat(label.padEnd(10)))).concat(chalk.cyanBright(normalizeUrl("".concat(url, "/").concat(routes[0].urlPath))), "\n");
|
@@ -71,7 +72,7 @@ export var prettyInstructions = function(appContext, config) {
|
|
71
72
|
})));
|
72
73
|
urls.forEach(function(param) {
|
73
74
|
var label = param.label, url = param.url;
|
74
|
-
message += " ".concat(chalk.bold("> ".concat(label)), "\n");
|
75
|
+
message += " ".concat(chalk.bold("> ".concat(label))).concat(routes.length === 0 ? chalk.cyanBright(url) : "", "\n");
|
75
76
|
routes.forEach(function(param2) {
|
76
77
|
var entryName = param2.entryName, urlPath = param2.urlPath, isSSR = param2.isSSR;
|
77
78
|
if (!checkedEntries.includes(entryName)) {
|
package/dist/esm/cli/require.js
CHANGED
@@ -2,8 +2,9 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
2
|
import { findExists } from "./fs";
|
3
3
|
export var compatRequire = function(filePath) {
|
4
4
|
var interop = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
5
|
+
var _mod;
|
5
6
|
var mod = require(filePath);
|
6
|
-
var rtnESMDefault = interop && (mod === null ||
|
7
|
+
var rtnESMDefault = interop && ((_mod = mod) === null || _mod === void 0 ? void 0 : _mod.__esModule);
|
7
8
|
return rtnESMDefault ? mod.default : mod;
|
8
9
|
};
|
9
10
|
export var dynamicImport = new Function("modulePath", "return import(modulePath)");
|
@@ -30,6 +30,7 @@ export var transformNestedRoutes = function(routes) {
|
|
30
30
|
};
|
31
31
|
export var renderNestedRoute = function(nestedRoute) {
|
32
32
|
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
33
|
+
var _config, _children;
|
33
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;
|
34
35
|
var Component = component;
|
35
36
|
var parent = options.parent, DeferredDataComponent = options.DeferredDataComponent, _options_props = options.props, props = _options_props === void 0 ? {} : _options_props;
|
@@ -41,7 +42,7 @@ export var renderNestedRoute = function(nestedRoute) {
|
|
41
42
|
action: nestedRoute.action,
|
42
43
|
hasErrorBoundary: nestedRoute.hasErrorBoundary,
|
43
44
|
shouldRevalidate: nestedRoute.shouldRevalidate,
|
44
|
-
handle: _object_spread({}, handle, typeof config === "object" ? config === null ||
|
45
|
+
handle: _object_spread({}, handle, typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _config.handle : {}),
|
45
46
|
index: nestedRoute.index,
|
46
47
|
element: nestedRoute.element,
|
47
48
|
errorElement: nestedRoute.errorElement
|
@@ -52,7 +53,8 @@ export var renderNestedRoute = function(nestedRoute) {
|
|
52
53
|
}
|
53
54
|
var element;
|
54
55
|
if (Component) {
|
55
|
-
|
56
|
+
var _parent;
|
57
|
+
if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
|
56
58
|
var Loading = parent.loading;
|
57
59
|
if (isLoadableComponent(Component)) {
|
58
60
|
element = /* @__PURE__ */ _jsx(Component, {
|
@@ -67,11 +69,12 @@ export var renderNestedRoute = function(nestedRoute) {
|
|
67
69
|
} else if (isLoadableComponent(Component) && lazyImport) {
|
68
70
|
element = /* @__PURE__ */ _jsx(Component, {});
|
69
71
|
} else if (isRoot) {
|
72
|
+
var _props;
|
70
73
|
element = /* @__PURE__ */ _jsxs(_Fragment, {
|
71
74
|
children: [
|
72
75
|
/* @__PURE__ */ _jsx(Component, _object_spread({}, props)),
|
73
76
|
typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
|
74
|
-
nonce: props === null ||
|
77
|
+
nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
|
75
78
|
})
|
76
79
|
]
|
77
80
|
});
|
@@ -84,12 +87,13 @@ export var renderNestedRoute = function(nestedRoute) {
|
|
84
87
|
element = /* @__PURE__ */ _jsx(Component, {});
|
85
88
|
}
|
86
89
|
} else {
|
87
|
-
|
90
|
+
var _parent1;
|
91
|
+
nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
|
88
92
|
}
|
89
93
|
if (element) {
|
90
94
|
routeProps.element = element;
|
91
95
|
}
|
92
|
-
var childElements = children === null ||
|
96
|
+
var childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map(function(childRoute) {
|
93
97
|
return renderNestedRoute(childRoute, {
|
94
98
|
parent: nestedRoute
|
95
99
|
});
|
@@ -6,7 +6,8 @@ export var parsedJSONFromElement = function(id) {
|
|
6
6
|
var element = elements[elements.length - 1];
|
7
7
|
if (element) {
|
8
8
|
try {
|
9
|
-
var
|
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
13
|
console.error("parse ".concat(id, " error"), e);
|
@@ -40,13 +40,44 @@ function formatMessage(stats) {
|
|
40
40
|
message = lines.join("\n");
|
41
41
|
return message.trim();
|
42
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
|
+
}
|
43
72
|
function formatWebpackMessages(json) {
|
44
|
-
var
|
45
|
-
var
|
46
|
-
var
|
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);
|
47
77
|
var result = {
|
48
78
|
errors: formattedErrors || [],
|
49
|
-
warnings: formattedWarnings || []
|
79
|
+
warnings: formattedWarnings || [],
|
80
|
+
errorTips: []
|
50
81
|
};
|
51
82
|
if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
|
52
83
|
result.errors = result.errors.filter(isLikelyASyntaxError);
|
@@ -54,6 +85,7 @@ function formatWebpackMessages(json) {
|
|
54
85
|
if (result.errors.length > 1) {
|
55
86
|
result.errors.length = 1;
|
56
87
|
}
|
88
|
+
result.errors = addErrorTips(result.errors, color);
|
57
89
|
return result;
|
58
90
|
}
|
59
91
|
export { formatWebpackMessages };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
2
|
+
function processHrtime(previousTimestamp) {
|
3
|
+
var now = (/* @__PURE__ */ new Date()).getTime();
|
4
|
+
var clocktime = now * 1e-3;
|
5
|
+
var seconds = Math.floor(clocktime);
|
6
|
+
var nanoseconds = Math.floor(clocktime % 1 * 1e9);
|
7
|
+
if (previousTimestamp) {
|
8
|
+
seconds -= previousTimestamp[0];
|
9
|
+
nanoseconds -= previousTimestamp[1];
|
10
|
+
if (nanoseconds < 0) {
|
11
|
+
seconds--;
|
12
|
+
nanoseconds += 1e9;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
return [
|
16
|
+
seconds,
|
17
|
+
nanoseconds
|
18
|
+
];
|
19
|
+
}
|
20
|
+
var getLatency = function(hrtime) {
|
21
|
+
var _processHrtime = _sliced_to_array(processHrtime(hrtime), 2), s = _processHrtime[0], ns = _processHrtime[1];
|
22
|
+
return s * 1e3 + ns / 1e6;
|
23
|
+
};
|
24
|
+
export var time = function() {
|
25
|
+
var hrtime = processHrtime();
|
26
|
+
return function() {
|
27
|
+
return getLatency(hrtime);
|
28
|
+
};
|
29
|
+
};
|
@@ -20,7 +20,7 @@ export const validAlias = (modernConfig, { tsconfigPath }) => {
|
|
20
20
|
};
|
21
21
|
export const mergeAlias = (alias) => applyOptionsChain({}, alias);
|
22
22
|
export const getAliasConfig = (aliasOption, option) => {
|
23
|
-
var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
|
23
|
+
var _tsconfig_compilerOptions, _tsconfig, _tsconfig_compilerOptions1, _tsconfig1;
|
24
24
|
const isTsProject = fs.existsSync(option.tsconfigPath);
|
25
25
|
const alias = mergeAlias(aliasOption);
|
26
26
|
if (!isTsProject) {
|
@@ -32,12 +32,12 @@ export const getAliasConfig = (aliasOption, option) => {
|
|
32
32
|
};
|
33
33
|
}
|
34
34
|
const tsconfig = readTsConfigByFile(option.tsconfigPath);
|
35
|
-
const baseUrl = tsconfig === null ||
|
35
|
+
const baseUrl = (_tsconfig = tsconfig) === null || _tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = _tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
|
36
36
|
return {
|
37
37
|
absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
|
38
38
|
paths: {
|
39
39
|
...alias,
|
40
|
-
...tsconfig === null ||
|
40
|
+
...(_tsconfig1 = tsconfig) === null || _tsconfig1 === void 0 ? void 0 : (_tsconfig_compilerOptions1 = _tsconfig1.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths
|
41
41
|
},
|
42
42
|
isTsPath: true,
|
43
43
|
isTsProject
|
@@ -37,6 +37,8 @@ export const CHAIN_ID = {
|
|
37
37
|
YAML: "yaml",
|
38
38
|
/** Rule for wasm */
|
39
39
|
WASM: "wasm",
|
40
|
+
/** Rule for node */
|
41
|
+
NODE: "node",
|
40
42
|
/** Rule for bff */
|
41
43
|
JS_BFF_API: "js-bff-api"
|
42
44
|
},
|
@@ -75,6 +77,8 @@ export const CHAIN_ID = {
|
|
75
77
|
TOML: "toml",
|
76
78
|
/** html-loader */
|
77
79
|
HTML: "html",
|
80
|
+
/** node-loader */
|
81
|
+
NODE: "html",
|
78
82
|
/** babel-loader */
|
79
83
|
BABEL: "babel",
|
80
84
|
/** esbuild-loader */
|
@@ -93,6 +97,8 @@ export const CHAIN_ID = {
|
|
93
97
|
CSS_MODULES_TS: "css-modules-typescript",
|
94
98
|
/** mini-css-extract-plugin.loader */
|
95
99
|
MINI_CSS_EXTRACT: "mini-css-extract",
|
100
|
+
/** resolve-url-loader */
|
101
|
+
RESOLVE_URL_LOADER_FOR_SASS: "resolve-url-loader",
|
96
102
|
/** builder-plugin-image-compress.loader */
|
97
103
|
IMAGE_COMPRESS: "image-compress",
|
98
104
|
/** builder-plugin-image-compress svgo-loader */
|
@@ -140,6 +146,10 @@ export const CHAIN_ID = {
|
|
140
146
|
HTML_NONCE: "html-nonce",
|
141
147
|
/** HtmlCrossOriginPlugin */
|
142
148
|
HTML_CROSS_ORIGIN: "html-cross-origin",
|
149
|
+
/** htmlPreconnectPlugin */
|
150
|
+
HTML_PRECONNECT: "html-preconnect-plugin",
|
151
|
+
/** htmlDnsPrefetchPlugin */
|
152
|
+
HTML_DNS_PREFETCH: "html-dns-prefetch-plugin",
|
143
153
|
/** MiniCssExtractPlugin */
|
144
154
|
MINI_CSS_EXTRACT: "mini-css-extract",
|
145
155
|
/** VueLoaderPlugin */
|
@@ -9,7 +9,7 @@ export const LOADABLE_STATS_FILE = "loadable-stats.json";
|
|
9
9
|
export const API_DIR = "api";
|
10
10
|
export const SERVER_DIR = "server";
|
11
11
|
export const SHARED_DIR = "shared";
|
12
|
-
export const CONFIG_CACHE_DIR = "./node_modules/.cache/
|
12
|
+
export const CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
|
13
13
|
export const CONFIG_FILE_EXTENSIONS = [
|
14
14
|
".js",
|
15
15
|
".ts",
|
@@ -41,7 +41,6 @@ export const INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
|
|
41
41
|
};
|
42
42
|
export const INTERNAL_MODULE_TOOLS_PLUGINS = {
|
43
43
|
"@modern-js/module-tools": "@modern-js/module-tools",
|
44
|
-
"@modern-js/doc-tools": "@modern-js/doc-tools",
|
45
44
|
"@modern-js/runtime": "@modern-js/runtime/cli",
|
46
45
|
"@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
|
47
46
|
"@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
|
@@ -1,10 +1,12 @@
|
|
1
|
+
import { MAIN_ENTRY_NAME } from "../constants";
|
1
2
|
import { isEmpty } from "./type";
|
2
3
|
export const isSSR = (config) => {
|
4
|
+
var _server, _server1;
|
3
5
|
const { server } = config;
|
4
|
-
if (server === null ||
|
6
|
+
if ((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) {
|
5
7
|
return true;
|
6
8
|
}
|
7
|
-
if ((server === null ||
|
9
|
+
if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
|
8
10
|
for (const name of Object.keys(server.ssrByEntries)) {
|
9
11
|
if (server.ssrByEntries[name]) {
|
10
12
|
return true;
|
@@ -14,27 +16,29 @@ export const isSSR = (config) => {
|
|
14
16
|
return false;
|
15
17
|
};
|
16
18
|
export const isUseSSRBundle = (config) => {
|
19
|
+
var _output;
|
17
20
|
const { output } = config;
|
18
|
-
if (output === null ||
|
21
|
+
if ((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) {
|
19
22
|
return true;
|
20
23
|
}
|
21
24
|
return isSSR(config);
|
22
25
|
};
|
23
26
|
export const isServiceWorker = (config) => {
|
24
|
-
var _deploy_worker;
|
27
|
+
var _deploy_worker, _deploy, _output;
|
25
28
|
const { output, deploy } = config;
|
26
|
-
if ((deploy === null ||
|
29
|
+
if (((_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr) && (((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) || isSSR(config))) {
|
27
30
|
return true;
|
28
31
|
}
|
29
32
|
return false;
|
30
33
|
};
|
31
34
|
export const isRouterV5 = (config) => {
|
32
|
-
var _config_runtime, _config_runtime1,
|
33
|
-
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null ||
|
35
|
+
var _config_runtime, _config_runtime_router, _config_runtime1, _config;
|
36
|
+
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && ((_config = config) === null || _config === void 0 ? void 0 : (_config_runtime1 = _config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
|
34
37
|
};
|
35
38
|
export const isSSGEntry = (config, entryName, entrypoints) => {
|
39
|
+
var _config_source, _ssgConfig, _ssgConfig1;
|
36
40
|
const ssgConfig = config.output.ssg;
|
37
|
-
const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig === null ||
|
41
|
+
const useSSG = isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
|
38
42
|
return useSSG;
|
39
43
|
};
|
40
|
-
export const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName ===
|
44
|
+
export const isSingleEntry = (entrypoints, mainEntryName = MAIN_ENTRY_NAME) => entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
|
@@ -40,6 +40,9 @@ const DEFAULT_CONFIG = {
|
|
40
40
|
displayLabel: true,
|
41
41
|
uppercaseLabel: false
|
42
42
|
};
|
43
|
+
const errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
|
44
|
+
const anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
|
45
|
+
export const isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
|
43
46
|
class Logger {
|
44
47
|
_log(type, message, ...args) {
|
45
48
|
if (message === void 0 || message === null) {
|
@@ -65,6 +68,9 @@ ${chalk.grey(rest.join("\n"))}`;
|
|
65
68
|
} else {
|
66
69
|
text = message.message;
|
67
70
|
}
|
71
|
+
} else if (logType.level === "error" && typeof message === "string") {
|
72
|
+
const lines = message.split("\n");
|
73
|
+
text = lines.map((line) => isErrorStackMessage(line) ? chalk.gray(line) : line).join("\n");
|
68
74
|
} else {
|
69
75
|
text = `${message}`;
|
70
76
|
}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import os from "os";
|
3
3
|
import fs from "fs";
|
4
|
-
import { nanoid, upath
|
4
|
+
import { nanoid, upath } from "../compiled";
|
5
5
|
export const isPathString = (test) => path.posix.basename(test) !== test || path.win32.basename(test) !== test;
|
6
6
|
export const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
|
7
7
|
export const normalizeOutputPath = (s) => s.replace(/\\/g, "\\\\");
|
8
|
-
export const normalizeToPosixPath = (p) => upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, (
|
8
|
+
export const normalizeToPosixPath = (p) => upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
|
9
9
|
export const getTemplatePath = (prefix) => {
|
10
10
|
const tmpRoot = fs.realpathSync(os.tmpdir());
|
11
11
|
const parts = [
|
@@ -15,20 +15,6 @@ export const getTemplatePath = (prefix) => {
|
|
15
15
|
parts.push(nanoid());
|
16
16
|
return path.resolve(...parts);
|
17
17
|
};
|
18
|
-
export function compilePathMatcherRegExp(match) {
|
19
|
-
if (typeof match !== "string") {
|
20
|
-
return match;
|
21
|
-
}
|
22
|
-
const escaped = _.escapeRegExp(match);
|
23
|
-
return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
|
24
|
-
}
|
25
|
-
export const _joinPathParts = (_part, i, parts) => _(parts).filter((part) => ![
|
26
|
-
"/",
|
27
|
-
"\\"
|
28
|
-
].includes(part)).tap((parts2) => parts2.unshift("")).slice(0, i + 2).join("/");
|
29
|
-
export function upwardPaths(start) {
|
30
|
-
return _(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
|
31
|
-
}
|
32
18
|
export function getRealTemporaryDirectory() {
|
33
19
|
let ret = null;
|
34
20
|
try {
|
@@ -20,7 +20,8 @@ export const getAddressUrls = (protocol = "http", port, host) => {
|
|
20
20
|
const LOCAL_LABEL = "Local: ";
|
21
21
|
const NETWORK_LABEL = "Network: ";
|
22
22
|
const isLocalhost = (url) => {
|
23
|
-
|
23
|
+
var _url;
|
24
|
+
return (_url = url) === null || _url === void 0 ? void 0 : _url.includes("localhost");
|
24
25
|
};
|
25
26
|
if (host && host !== DEFAULT_DEV_HOST) {
|
26
27
|
return [
|
@@ -47,19 +48,19 @@ export const getAddressUrls = (protocol = "http", port, host) => {
|
|
47
48
|
}, []);
|
48
49
|
};
|
49
50
|
export const prettyInstructions = (appContext, config) => {
|
50
|
-
var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
|
51
|
+
var _appContext_builder_context_devServer, _appContext_builder, _config_dev, _config_source;
|
51
52
|
const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
|
52
|
-
const isHttps = isDev() && ((
|
53
|
+
const isHttps = isDev() && ((_appContext_builder = appContext.builder) === null || _appContext_builder === void 0 ? void 0 : (_appContext_builder_context_devServer = _appContext_builder.context.devServer) === null || _appContext_builder_context_devServer === void 0 ? void 0 : _appContext_builder_context_devServer.https);
|
53
54
|
const urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
|
54
55
|
const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
|
55
56
|
let message = "App running at:\n\n";
|
56
|
-
if (isSingleEntry(entrypoints) || apiOnly) {
|
57
|
+
if (isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) || apiOnly) {
|
57
58
|
message += urls.map(({ label, url }) => ` ${chalk.bold(`> ${label.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}
|
58
59
|
`).join("");
|
59
60
|
} else {
|
60
61
|
const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
|
61
62
|
urls.forEach(({ label, url }) => {
|
62
|
-
message += ` ${chalk.bold(`> ${label}`)}
|
63
|
+
message += ` ${chalk.bold(`> ${label}`)}${routes.length === 0 ? chalk.cyanBright(url) : ""}
|
63
64
|
`;
|
64
65
|
routes.forEach(({ entryName, urlPath, isSSR }) => {
|
65
66
|
if (!checkedEntries.includes(entryName)) {
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { findExists } from "./fs";
|
2
2
|
export const compatRequire = (filePath, interop = true) => {
|
3
|
+
var _mod;
|
3
4
|
const mod = require(filePath);
|
4
|
-
const rtnESMDefault = interop && (mod === null ||
|
5
|
+
const rtnESMDefault = interop && ((_mod = mod) === null || _mod === void 0 ? void 0 : _mod.__esModule);
|
5
6
|
return rtnESMDefault ? mod.default : mod;
|
6
7
|
};
|
7
8
|
export const dynamicImport = new Function("modulePath", "return import(modulePath)");
|
@@ -10,6 +10,7 @@ export const transformNestedRoutes = (routes) => {
|
|
10
10
|
return createRoutesFromElements(routeElements);
|
11
11
|
};
|
12
12
|
export const renderNestedRoute = (nestedRoute, options = {}) => {
|
13
|
+
var _config, _children;
|
13
14
|
const { children, index, id, component, isRoot, lazyImport, config, handle } = nestedRoute;
|
14
15
|
const Component = component;
|
15
16
|
const { parent, DeferredDataComponent, props = {} } = options;
|
@@ -23,7 +24,7 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
|
|
23
24
|
shouldRevalidate: nestedRoute.shouldRevalidate,
|
24
25
|
handle: {
|
25
26
|
...handle,
|
26
|
-
...typeof config === "object" ? config === null ||
|
27
|
+
...typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _config.handle : {}
|
27
28
|
},
|
28
29
|
index: nestedRoute.index,
|
29
30
|
element: nestedRoute.element,
|
@@ -35,7 +36,8 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
|
|
35
36
|
}
|
36
37
|
let element;
|
37
38
|
if (Component) {
|
38
|
-
|
39
|
+
var _parent;
|
40
|
+
if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
|
39
41
|
const Loading = parent.loading;
|
40
42
|
if (isLoadableComponent(Component)) {
|
41
43
|
element = /* @__PURE__ */ _jsx(Component, {
|
@@ -50,13 +52,14 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
|
|
50
52
|
} else if (isLoadableComponent(Component) && lazyImport) {
|
51
53
|
element = /* @__PURE__ */ _jsx(Component, {});
|
52
54
|
} else if (isRoot) {
|
55
|
+
var _props;
|
53
56
|
element = /* @__PURE__ */ _jsxs(_Fragment, {
|
54
57
|
children: [
|
55
58
|
/* @__PURE__ */ _jsx(Component, {
|
56
59
|
...props
|
57
60
|
}),
|
58
61
|
typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ _jsx(DeferredDataComponent, {
|
59
|
-
nonce: props === null ||
|
62
|
+
nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
|
60
63
|
})
|
61
64
|
]
|
62
65
|
});
|
@@ -69,12 +72,13 @@ export const renderNestedRoute = (nestedRoute, options = {}) => {
|
|
69
72
|
element = /* @__PURE__ */ _jsx(Component, {});
|
70
73
|
}
|
71
74
|
} else {
|
72
|
-
|
75
|
+
var _parent1;
|
76
|
+
nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
|
73
77
|
}
|
74
78
|
if (element) {
|
75
79
|
routeProps.element = element;
|
76
80
|
}
|
77
|
-
const childElements = children === null ||
|
81
|
+
const childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map((childRoute) => {
|
78
82
|
return renderNestedRoute(childRoute, {
|
79
83
|
parent: nestedRoute
|
80
84
|
});
|