@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.
Files changed (54) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/cjs/cli/alias.js +3 -3
  3. package/dist/cjs/cli/constants/chainId.js +10 -0
  4. package/dist/cjs/cli/constants/index.js +1 -2
  5. package/dist/cjs/cli/index.js +0 -1
  6. package/dist/cjs/cli/is/config.js +13 -9
  7. package/dist/cjs/cli/logger.js +9 -0
  8. package/dist/cjs/cli/path.js +0 -23
  9. package/dist/cjs/cli/prettyInstructions.js +6 -5
  10. package/dist/cjs/cli/require.js +2 -1
  11. package/dist/cjs/runtime/nestedRoutes.js +9 -5
  12. package/dist/cjs/runtime-browser/parsed.js +2 -1
  13. package/dist/cjs/universal/formatWebpack.js +55 -8
  14. package/dist/cjs/universal/time.js +38 -0
  15. package/dist/esm/cli/alias.js +3 -3
  16. package/dist/esm/cli/constants/chainId.js +10 -0
  17. package/dist/esm/cli/constants/index.js +1 -2
  18. package/dist/esm/cli/get/data.js +12 -3
  19. package/dist/esm/cli/index.js +0 -1
  20. package/dist/esm/cli/is/config.js +14 -9
  21. package/dist/esm/cli/logger.js +10 -0
  22. package/dist/esm/cli/path.js +2 -22
  23. package/dist/esm/cli/prettyInstructions.js +6 -5
  24. package/dist/esm/cli/require.js +2 -1
  25. package/dist/esm/runtime/nestedRoutes.js +9 -5
  26. package/dist/esm/runtime-browser/parsed.js +2 -1
  27. package/dist/esm/universal/formatWebpack.js +36 -4
  28. package/dist/esm/universal/time.js +29 -0
  29. package/dist/esm-node/cli/alias.js +3 -3
  30. package/dist/esm-node/cli/constants/chainId.js +10 -0
  31. package/dist/esm-node/cli/constants/index.js +1 -2
  32. package/dist/esm-node/cli/index.js +0 -1
  33. package/dist/esm-node/cli/is/config.js +13 -9
  34. package/dist/esm-node/cli/logger.js +6 -0
  35. package/dist/esm-node/cli/path.js +2 -16
  36. package/dist/esm-node/cli/prettyInstructions.js +6 -5
  37. package/dist/esm-node/cli/require.js +2 -1
  38. package/dist/esm-node/runtime/nestedRoutes.js +9 -5
  39. package/dist/esm-node/runtime-browser/parsed.js +2 -1
  40. package/dist/esm-node/universal/formatWebpack.js +43 -5
  41. package/dist/esm-node/universal/time.js +28 -0
  42. package/dist/types/cli/constants/chainId.d.ts +10 -0
  43. package/dist/types/cli/constants/index.d.ts +1 -1
  44. package/dist/types/cli/index.d.ts +0 -1
  45. package/dist/types/cli/is/config.d.ts +1 -1
  46. package/dist/types/cli/logger.d.ts +1 -0
  47. package/dist/types/cli/path.d.ts +0 -9
  48. package/dist/types/universal/formatWebpack.d.ts +14 -1
  49. package/dist/types/universal/time.d.ts +1 -0
  50. package/package.json +12 -4
  51. package/dist/cjs/cli/pathSerializer.js +0 -72
  52. package/dist/esm/cli/pathSerializer.js +0 -60
  53. package/dist/esm-node/cli/pathSerializer.js +0 -46
  54. package/dist/types/cli/pathSerializer.d.ts +0 -16
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 2.29.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cba7675: feat: add a server reporter that report server cost, logger about error, info etc.
8
+ feat: 添加一个 server 端 reporter,来报告 server 端耗时,报错等
9
+
10
+ ### Patch Changes
11
+
12
+ - e6b5355: feat(utils): change the color of error stacks to gray
13
+
14
+ feat(utils): 将 error stack 的颜色改为灰色
15
+
16
+ - 93db783: fix(utils): remove hard code 'main'
17
+
18
+ fix(utils): 移除 'main' 硬编码
19
+
20
+ - 99052ea: feat(builder): improve error stacks if dev compilation failed
21
+
22
+ feat(builder): 优化 dev 编译失败时的错误堆栈格式
23
+
24
+ - 1d71d2e: fix(@modern-js/utils): add missing url in devServer console
25
+ fix(@modern-js/utils): 修复 devServer console 中丢失的 url
26
+
27
+ ## 2.28.0
28
+
29
+ ### Patch Changes
30
+
31
+ - 00b58a7: feat(builder): add an error tip for source.include
32
+
33
+ feat(builder): 增加 source.include 常见问题的提示日志
34
+
3
35
  ## 2.27.0
4
36
 
5
37
  ### Patch Changes
@@ -46,7 +46,7 @@ const validAlias = (modernConfig, { tsconfigPath }) => {
46
46
  };
47
47
  const mergeAlias = (alias) => (0, _applyOptionsChain.applyOptionsChain)({}, alias);
48
48
  const getAliasConfig = (aliasOption, option) => {
49
- var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
49
+ var _tsconfig_compilerOptions, _tsconfig, _tsconfig_compilerOptions1, _tsconfig1;
50
50
  const isTsProject = _fs.default.existsSync(option.tsconfigPath);
51
51
  const alias = mergeAlias(aliasOption);
52
52
  if (!isTsProject) {
@@ -58,12 +58,12 @@ const getAliasConfig = (aliasOption, option) => {
58
58
  };
59
59
  }
60
60
  const tsconfig = (0, _get.readTsConfigByFile)(option.tsconfigPath);
61
- const baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
61
+ const baseUrl = (_tsconfig = tsconfig) === null || _tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = _tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
62
62
  return {
63
63
  absoluteBaseUrl: baseUrl ? _path.default.join(option.appDirectory, baseUrl) : option.appDirectory,
64
64
  paths: {
65
65
  ...alias,
66
- ...tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions1 = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths
66
+ ...(_tsconfig1 = tsconfig) === null || _tsconfig1 === void 0 ? void 0 : (_tsconfig_compilerOptions1 = _tsconfig1.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths
67
67
  },
68
68
  isTsPath: true,
69
69
  isTsProject
@@ -47,6 +47,8 @@ const CHAIN_ID = {
47
47
  YAML: "yaml",
48
48
  /** Rule for wasm */
49
49
  WASM: "wasm",
50
+ /** Rule for node */
51
+ NODE: "node",
50
52
  /** Rule for bff */
51
53
  JS_BFF_API: "js-bff-api"
52
54
  },
@@ -85,6 +87,8 @@ const CHAIN_ID = {
85
87
  TOML: "toml",
86
88
  /** html-loader */
87
89
  HTML: "html",
90
+ /** node-loader */
91
+ NODE: "html",
88
92
  /** babel-loader */
89
93
  BABEL: "babel",
90
94
  /** esbuild-loader */
@@ -103,6 +107,8 @@ const CHAIN_ID = {
103
107
  CSS_MODULES_TS: "css-modules-typescript",
104
108
  /** mini-css-extract-plugin.loader */
105
109
  MINI_CSS_EXTRACT: "mini-css-extract",
110
+ /** resolve-url-loader */
111
+ RESOLVE_URL_LOADER_FOR_SASS: "resolve-url-loader",
106
112
  /** builder-plugin-image-compress.loader */
107
113
  IMAGE_COMPRESS: "image-compress",
108
114
  /** builder-plugin-image-compress svgo-loader */
@@ -150,6 +156,10 @@ const CHAIN_ID = {
150
156
  HTML_NONCE: "html-nonce",
151
157
  /** HtmlCrossOriginPlugin */
152
158
  HTML_CROSS_ORIGIN: "html-cross-origin",
159
+ /** htmlPreconnectPlugin */
160
+ HTML_PRECONNECT: "html-preconnect-plugin",
161
+ /** htmlDnsPrefetchPlugin */
162
+ HTML_DNS_PREFETCH: "html-dns-prefetch-plugin",
153
163
  /** MiniCssExtractPlugin */
154
164
  MINI_CSS_EXTRACT: "mini-css-extract",
155
165
  /** VueLoaderPlugin */
@@ -117,7 +117,7 @@ const LOADABLE_STATS_FILE = "loadable-stats.json";
117
117
  const API_DIR = "api";
118
118
  const SERVER_DIR = "server";
119
119
  const SHARED_DIR = "shared";
120
- const CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
120
+ const CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
121
121
  const CONFIG_FILE_EXTENSIONS = [
122
122
  ".js",
123
123
  ".ts",
@@ -149,7 +149,6 @@ const INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
149
149
  };
150
150
  const INTERNAL_MODULE_TOOLS_PLUGINS = {
151
151
  "@modern-js/module-tools": "@modern-js/module-tools",
152
- "@modern-js/doc-tools": "@modern-js/doc-tools",
153
152
  "@modern-js/runtime": "@modern-js/runtime/cli",
154
153
  "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
155
154
  "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
@@ -17,7 +17,6 @@ _export_star._(require("./logger"), exports);
17
17
  _export_star._(require("./monorepo"), exports);
18
18
  _export_star._(require("./package"), exports);
19
19
  _export_star._(require("./path"), exports);
20
- _export_star._(require("./pathSerializer"), exports);
21
20
  _export_star._(require("./port"), exports);
22
21
  _export_star._(require("./prettyInstructions"), exports);
23
22
  _export_star._(require("./require"), exports);
@@ -29,13 +29,15 @@ _export(exports, {
29
29
  return isSingleEntry;
30
30
  }
31
31
  });
32
+ const _constants = require("../constants");
32
33
  const _type = require("./type");
33
34
  const isSSR = (config) => {
35
+ var _server, _server1;
34
36
  const { server } = config;
35
- if (server === null || server === void 0 ? void 0 : server.ssr) {
37
+ if ((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) {
36
38
  return true;
37
39
  }
38
- if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !(0, _type.isEmpty)(server.ssrByEntries)) {
40
+ if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && !(0, _type.isEmpty)(server.ssrByEntries)) {
39
41
  for (const name of Object.keys(server.ssrByEntries)) {
40
42
  if (server.ssrByEntries[name]) {
41
43
  return true;
@@ -45,27 +47,29 @@ const isSSR = (config) => {
45
47
  return false;
46
48
  };
47
49
  const isUseSSRBundle = (config) => {
50
+ var _output;
48
51
  const { output } = config;
49
- if (output === null || output === void 0 ? void 0 : output.ssg) {
52
+ if ((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) {
50
53
  return true;
51
54
  }
52
55
  return isSSR(config);
53
56
  };
54
57
  const isServiceWorker = (config) => {
55
- var _deploy_worker;
58
+ var _deploy_worker, _deploy, _output;
56
59
  const { output, deploy } = config;
57
- if ((deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr) && ((output === null || output === void 0 ? void 0 : output.ssg) || isSSR(config))) {
60
+ 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))) {
58
61
  return true;
59
62
  }
60
63
  return false;
61
64
  };
62
65
  const isRouterV5 = (config) => {
63
- var _config_runtime, _config_runtime1, _config_runtime_router;
64
- return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (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";
66
+ var _config_runtime, _config_runtime_router, _config_runtime1, _config;
67
+ 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";
65
68
  };
66
69
  const isSSGEntry = (config, entryName, entrypoints) => {
70
+ var _config_source, _ssgConfig, _ssgConfig1;
67
71
  const ssgConfig = config.output.ssg;
68
- const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[0]) === "function" || Boolean(ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[entryName]);
72
+ 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]);
69
73
  return useSSG;
70
74
  };
71
- const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
75
+ const isSingleEntry = (entrypoints, mainEntryName = _constants.MAIN_ENTRY_NAME) => entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
@@ -10,6 +10,9 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
+ isErrorStackMessage: function() {
14
+ return isErrorStackMessage;
15
+ },
13
16
  Logger: function() {
14
17
  return Logger;
15
18
  },
@@ -60,6 +63,9 @@ const DEFAULT_CONFIG = {
60
63
  displayLabel: true,
61
64
  uppercaseLabel: false
62
65
  };
66
+ const errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
67
+ const anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
68
+ const isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
63
69
  class Logger {
64
70
  _log(type, message, ...args) {
65
71
  if (message === void 0 || message === null) {
@@ -85,6 +91,9 @@ ${_chalk.default.grey(rest.join("\n"))}`;
85
91
  } else {
86
92
  text = message.message;
87
93
  }
94
+ } else if (logType.level === "error" && typeof message === "string") {
95
+ const lines = message.split("\n");
96
+ text = lines.map((line) => isErrorStackMessage(line) ? _chalk.default.gray(line) : line).join("\n");
88
97
  } else {
89
98
  text = `${message}`;
90
99
  }
@@ -25,15 +25,6 @@ _export(exports, {
25
25
  getTemplatePath: function() {
26
26
  return getTemplatePath;
27
27
  },
28
- compilePathMatcherRegExp: function() {
29
- return compilePathMatcherRegExp;
30
- },
31
- _joinPathParts: function() {
32
- return _joinPathParts;
33
- },
34
- upwardPaths: function() {
35
- return upwardPaths;
36
- },
37
28
  getRealTemporaryDirectory: function() {
38
29
  return getRealTemporaryDirectory;
39
30
  },
@@ -71,20 +62,6 @@ const getTemplatePath = (prefix) => {
71
62
  parts.push((0, _compiled.nanoid)());
72
63
  return _path.default.resolve(...parts);
73
64
  };
74
- function compilePathMatcherRegExp(match) {
75
- if (typeof match !== "string") {
76
- return match;
77
- }
78
- const escaped = _compiled.lodash.escapeRegExp(match);
79
- return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
80
- }
81
- const _joinPathParts = (_part, i, parts) => (0, _compiled.lodash)(parts).filter((part) => ![
82
- "/",
83
- "\\"
84
- ].includes(part)).tap((parts2) => parts2.unshift("")).slice(0, i + 2).join("/");
85
- function upwardPaths(start) {
86
- return (0, _compiled.lodash)(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
87
- }
88
65
  function getRealTemporaryDirectory() {
89
66
  let ret = null;
90
67
  try {
@@ -40,7 +40,8 @@ const getAddressUrls = (protocol = "http", port, host) => {
40
40
  const LOCAL_LABEL = "Local: ";
41
41
  const NETWORK_LABEL = "Network: ";
42
42
  const isLocalhost = (url) => {
43
- return url === null || url === void 0 ? void 0 : url.includes("localhost");
43
+ var _url;
44
+ return (_url = url) === null || _url === void 0 ? void 0 : _url.includes("localhost");
44
45
  };
45
46
  if (host && host !== _constants.DEFAULT_DEV_HOST) {
46
47
  return [
@@ -67,19 +68,19 @@ const getAddressUrls = (protocol = "http", port, host) => {
67
68
  }, []);
68
69
  };
69
70
  const prettyInstructions = (appContext, config) => {
70
- var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
71
+ var _appContext_builder_context_devServer, _appContext_builder, _config_dev, _config_source;
71
72
  const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
72
- const isHttps = (0, _is.isDev)() && ((_appContext_builder_context_devServer = (_appContext_builder = appContext.builder) === null || _appContext_builder === void 0 ? void 0 : _appContext_builder.context.devServer) === null || _appContext_builder_context_devServer === void 0 ? void 0 : _appContext_builder_context_devServer.https);
73
+ const isHttps = (0, _is.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);
73
74
  const urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
74
75
  const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
75
76
  let message = "App running at:\n\n";
76
- if ((0, _is.isSingleEntry)(entrypoints) || apiOnly) {
77
+ if ((0, _is.isSingleEntry)(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) || apiOnly) {
77
78
  message += urls.map(({ label, url }) => ` ${_compiled.chalk.bold(`> ${label.padEnd(10)}`)}${_compiled.chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}
78
79
  `).join("");
79
80
  } else {
80
81
  const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
81
82
  urls.forEach(({ label, url }) => {
82
- message += ` ${_compiled.chalk.bold(`> ${label}`)}
83
+ message += ` ${_compiled.chalk.bold(`> ${label}`)}${routes.length === 0 ? _compiled.chalk.cyanBright(url) : ""}
83
84
  `;
84
85
  routes.forEach(({ entryName, urlPath, isSSR }) => {
85
86
  if (!checkedEntries.includes(entryName)) {
@@ -31,8 +31,9 @@ _export(exports, {
31
31
  });
32
32
  const _fs = require("./fs");
33
33
  const compatRequire = (filePath, interop = true) => {
34
+ var _mod;
34
35
  const mod = require(filePath);
35
- const rtnESMDefault = interop && (mod === null || mod === void 0 ? void 0 : mod.__esModule);
36
+ const rtnESMDefault = interop && ((_mod = mod) === null || _mod === void 0 ? void 0 : _mod.__esModule);
36
37
  return rtnESMDefault ? mod.default : mod;
37
38
  };
38
39
  const dynamicImport = new Function("modulePath", "return import(modulePath)");
@@ -30,6 +30,7 @@ const transformNestedRoutes = (routes) => {
30
30
  return (0, _reactrouterdom.createRoutesFromElements)(routeElements);
31
31
  };
32
32
  const renderNestedRoute = (nestedRoute, options = {}) => {
33
+ var _config, _children;
33
34
  const { children, index, id, component, isRoot, lazyImport, config, handle } = nestedRoute;
34
35
  const Component = component;
35
36
  const { parent, DeferredDataComponent, props = {} } = options;
@@ -43,7 +44,7 @@ const renderNestedRoute = (nestedRoute, options = {}) => {
43
44
  shouldRevalidate: nestedRoute.shouldRevalidate,
44
45
  handle: {
45
46
  ...handle,
46
- ...typeof config === "object" ? config === null || config === void 0 ? void 0 : config.handle : {}
47
+ ...typeof config === "object" ? (_config = config) === null || _config === void 0 ? void 0 : _config.handle : {}
47
48
  },
48
49
  index: nestedRoute.index,
49
50
  element: nestedRoute.element,
@@ -55,7 +56,8 @@ const renderNestedRoute = (nestedRoute, options = {}) => {
55
56
  }
56
57
  let element;
57
58
  if (Component) {
58
- if ((parent === null || parent === void 0 ? void 0 : parent.loading) && lazyImport) {
59
+ var _parent;
60
+ if (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.loading) && lazyImport) {
59
61
  const Loading = parent.loading;
60
62
  if (isLoadableComponent(Component)) {
61
63
  element = /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
@@ -70,13 +72,14 @@ const renderNestedRoute = (nestedRoute, options = {}) => {
70
72
  } else if (isLoadableComponent(Component) && lazyImport) {
71
73
  element = /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {});
72
74
  } else if (isRoot) {
75
+ var _props;
73
76
  element = /* @__PURE__ */ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
74
77
  children: [
75
78
  /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {
76
79
  ...props
77
80
  }),
78
81
  typeof document === "undefined" && DeferredDataComponent && /* @__PURE__ */ (0, _jsxruntime.jsx)(DeferredDataComponent, {
79
- nonce: props === null || props === void 0 ? void 0 : props.nonce
82
+ nonce: (_props = props) === null || _props === void 0 ? void 0 : _props.nonce
80
83
  })
81
84
  ]
82
85
  });
@@ -89,12 +92,13 @@ const renderNestedRoute = (nestedRoute, options = {}) => {
89
92
  element = /* @__PURE__ */ (0, _jsxruntime.jsx)(Component, {});
90
93
  }
91
94
  } else {
92
- nestedRoute.loading = parent === null || parent === void 0 ? void 0 : parent.loading;
95
+ var _parent1;
96
+ nestedRoute.loading = (_parent1 = parent) === null || _parent1 === void 0 ? void 0 : _parent1.loading;
93
97
  }
94
98
  if (element) {
95
99
  routeProps.element = element;
96
100
  }
97
- const childElements = children === null || children === void 0 ? void 0 : children.map((childRoute) => {
101
+ const childElements = (_children = children) === null || _children === void 0 ? void 0 : _children.map((childRoute) => {
98
102
  return renderNestedRoute(childRoute, {
99
103
  parent: nestedRoute
100
104
  });
@@ -16,7 +16,8 @@ const parsedJSONFromElement = (id) => {
16
16
  const element = elements[elements.length - 1];
17
17
  if (element) {
18
18
  try {
19
- const parsed = JSON.parse((element === null || element === void 0 ? void 0 : element.textContent) || "");
19
+ var _element;
20
+ const parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
20
21
  return parsed;
21
22
  } catch (e) {
22
23
  console.error(`parse ${id} error`, e);
@@ -2,9 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "formatWebpackMessages", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ addErrorTips: function() {
14
+ return addErrorTips;
15
+ },
16
+ formatWebpackMessages: function() {
8
17
  return formatWebpackMessages;
9
18
  }
10
19
  });
@@ -52,13 +61,50 @@ ${stats.stack}` : "";
52
61
  message = lines.join("\n");
53
62
  return message.trim();
54
63
  }
55
- function formatWebpackMessages(json) {
56
- var _json_errors, _json_warnings, _result_errors;
57
- const formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
58
- const formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
64
+ const noop = (message) => message;
65
+ const defaultColor = {
66
+ gray: noop,
67
+ cyan: noop,
68
+ green: noop,
69
+ yellow: noop,
70
+ underline: noop
71
+ };
72
+ function addErrorTips(errors, color = defaultColor) {
73
+ const errorHelpers = [
74
+ {
75
+ validator(message) {
76
+ return (message.includes("You may need an appropriate loader") || message.includes("You may need an additional loader")) && message.includes(".ts");
77
+ },
78
+ formatter(message) {
79
+ return `${message}
80
+
81
+ ${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")}`)}
82
+
83
+ ${color.green(`${color.gray("// config file")}
84
+ export default {
85
+ source: {
86
+ include: [
87
+ ${color.gray("// add some include rules")}
88
+ ]
89
+ }
90
+ }`)}
91
+ `;
92
+ }
93
+ }
94
+ ];
95
+ return errors.map((error) => {
96
+ const helper = errorHelpers.find((item) => item.validator(error));
97
+ return helper ? helper.formatter(error) : error;
98
+ });
99
+ }
100
+ function formatWebpackMessages(json, color = defaultColor) {
101
+ var _json_errors, _json, _json_warnings, _json1, _result_errors;
102
+ 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);
103
+ 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);
59
104
  const result = {
60
105
  errors: formattedErrors || [],
61
- warnings: formattedWarnings || []
106
+ warnings: formattedWarnings || [],
107
+ errorTips: []
62
108
  };
63
109
  if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
64
110
  result.errors = result.errors.filter(isLikelyASyntaxError);
@@ -66,5 +112,6 @@ function formatWebpackMessages(json) {
66
112
  if (result.errors.length > 1) {
67
113
  result.errors.length = 1;
68
114
  }
115
+ result.errors = addErrorTips(result.errors, color);
69
116
  return result;
70
117
  }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "time", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return time;
9
+ }
10
+ });
11
+ function processHrtime(previousTimestamp) {
12
+ const now = (/* @__PURE__ */ new Date()).getTime();
13
+ const clocktime = now * 1e-3;
14
+ let seconds = Math.floor(clocktime);
15
+ let nanoseconds = Math.floor(clocktime % 1 * 1e9);
16
+ if (previousTimestamp) {
17
+ seconds -= previousTimestamp[0];
18
+ nanoseconds -= previousTimestamp[1];
19
+ if (nanoseconds < 0) {
20
+ seconds--;
21
+ nanoseconds += 1e9;
22
+ }
23
+ }
24
+ return [
25
+ seconds,
26
+ nanoseconds
27
+ ];
28
+ }
29
+ const getLatency = (hrtime) => {
30
+ const [s, ns] = processHrtime(hrtime);
31
+ return s * 1e3 + ns / 1e6;
32
+ };
33
+ const time = () => {
34
+ const hrtime = processHrtime();
35
+ return () => {
36
+ return getLatency(hrtime);
37
+ };
38
+ };
@@ -24,7 +24,7 @@ export var mergeAlias = function(alias) {
24
24
  return applyOptionsChain({}, alias);
25
25
  };
26
26
  export var getAliasConfig = function(aliasOption, option) {
27
- var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
27
+ var _tsconfig_compilerOptions, _tsconfig, _tsconfig_compilerOptions1, _tsconfig1;
28
28
  var isTsProject = fs.existsSync(option.tsconfigPath);
29
29
  var alias = mergeAlias(aliasOption);
30
30
  if (!isTsProject) {
@@ -36,10 +36,10 @@ export var getAliasConfig = function(aliasOption, option) {
36
36
  };
37
37
  }
38
38
  var tsconfig = readTsConfigByFile(option.tsconfigPath);
39
- var baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
39
+ var baseUrl = (_tsconfig = tsconfig) === null || _tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = _tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
40
40
  return {
41
41
  absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
42
- paths: _object_spread({}, alias, tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions1 = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths),
42
+ paths: _object_spread({}, alias, (_tsconfig1 = tsconfig) === null || _tsconfig1 === void 0 ? void 0 : (_tsconfig_compilerOptions1 = _tsconfig1.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths),
43
43
  isTsPath: true,
44
44
  isTsProject: isTsProject
45
45
  };
@@ -37,6 +37,8 @@ export var 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 var 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 var 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 var 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 */
@@ -10,7 +10,7 @@ export var LOADABLE_STATS_FILE = "loadable-stats.json";
10
10
  export var API_DIR = "api";
11
11
  export var SERVER_DIR = "server";
12
12
  export var SHARED_DIR = "shared";
13
- export var CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
13
+ export var CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
14
14
  export var CONFIG_FILE_EXTENSIONS = [
15
15
  ".js",
16
16
  ".ts",
@@ -42,7 +42,6 @@ export var INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
42
42
  };
43
43
  export var INTERNAL_MODULE_TOOLS_PLUGINS = {
44
44
  "@modern-js/module-tools": "@modern-js/module-tools",
45
- "@modern-js/doc-tools": "@modern-js/doc-tools",
46
45
  "@modern-js/runtime": "@modern-js/runtime/cli",
47
46
  "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
48
47
  "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
@@ -25,13 +25,22 @@ function _getPackageManager() {
25
25
  while (os.homedir() !== appDirectory && times < MAX_TIMES) {
26
26
  times++;
27
27
  if (fs.existsSync(path.resolve(appDirectory, "pnpm-lock.yaml"))) {
28
- return "pnpm";
28
+ return [
29
+ 2,
30
+ "pnpm"
31
+ ];
29
32
  }
30
33
  if (fs.existsSync(path.resolve(appDirectory, "yarn.lock"))) {
31
- return "yarn";
34
+ return [
35
+ 2,
36
+ "yarn"
37
+ ];
32
38
  }
33
39
  if (fs.existsSync(path.resolve(appDirectory, "package-lock.json"))) {
34
- return "npm";
40
+ return [
41
+ 2,
42
+ "npm"
43
+ ];
35
44
  }
36
45
  appDirectory = path.join(appDirectory, "..");
37
46
  }
@@ -12,7 +12,6 @@ export * from "./logger";
12
12
  export * from "./monorepo";
13
13
  export * from "./package";
14
14
  export * from "./path";
15
- export * from "./pathSerializer";
16
15
  export * from "./port";
17
16
  export * from "./prettyInstructions";
18
17
  export * from "./require";