@modern-js/utils 2.27.0 → 2.28.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 2.28.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 00b58a7: feat(builder): add an error tip for source.include
8
+
9
+ feat(builder): 增加 source.include 常见问题的提示日志
10
+
3
11
  ## 2.27.0
4
12
 
5
13
  ### 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 */
@@ -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",
@@ -31,11 +31,12 @@ _export(exports, {
31
31
  });
32
32
  const _type = require("./type");
33
33
  const isSSR = (config) => {
34
+ var _server, _server1;
34
35
  const { server } = config;
35
- if (server === null || server === void 0 ? void 0 : server.ssr) {
36
+ if ((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) {
36
37
  return true;
37
38
  }
38
- if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !(0, _type.isEmpty)(server.ssrByEntries)) {
39
+ if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && !(0, _type.isEmpty)(server.ssrByEntries)) {
39
40
  for (const name of Object.keys(server.ssrByEntries)) {
40
41
  if (server.ssrByEntries[name]) {
41
42
  return true;
@@ -45,27 +46,29 @@ const isSSR = (config) => {
45
46
  return false;
46
47
  };
47
48
  const isUseSSRBundle = (config) => {
49
+ var _output;
48
50
  const { output } = config;
49
- if (output === null || output === void 0 ? void 0 : output.ssg) {
51
+ if ((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) {
50
52
  return true;
51
53
  }
52
54
  return isSSR(config);
53
55
  };
54
56
  const isServiceWorker = (config) => {
55
- var _deploy_worker;
57
+ var _deploy_worker, _deploy, _output;
56
58
  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))) {
59
+ 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
60
  return true;
59
61
  }
60
62
  return false;
61
63
  };
62
64
  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";
65
+ var _config_runtime, _config_runtime_router, _config_runtime1, _config;
66
+ 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
67
  };
66
68
  const isSSGEntry = (config, entryName, entrypoints) => {
69
+ var _ssgConfig, _ssgConfig1;
67
70
  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]);
71
+ const useSSG = isSingleEntry(entrypoints) ? 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
72
  return useSSG;
70
73
  };
71
74
  const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
@@ -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 [
@@ -69,7 +70,7 @@ const getAddressUrls = (protocol = "http", port, host) => {
69
70
  const prettyInstructions = (appContext, config) => {
70
71
  var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
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";
@@ -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
  }
@@ -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 */
@@ -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
  }
@@ -1,10 +1,11 @@
1
1
  import { isEmpty } from "./type";
2
2
  export var isSSR = function(config) {
3
+ var _server, _server1;
3
4
  var server = config.server;
4
- if (server === null || server === void 0 ? void 0 : server.ssr) {
5
+ if ((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) {
5
6
  return true;
6
7
  }
7
- if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
8
+ if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
8
9
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
9
10
  try {
10
11
  for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
@@ -31,27 +32,29 @@ export var isSSR = function(config) {
31
32
  return false;
32
33
  };
33
34
  export var isUseSSRBundle = function(config) {
35
+ var _output;
34
36
  var output = config.output;
35
- if (output === null || output === void 0 ? void 0 : output.ssg) {
37
+ if ((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) {
36
38
  return true;
37
39
  }
38
40
  return isSSR(config);
39
41
  };
40
42
  export var isServiceWorker = function(config) {
41
- var _deploy_worker;
43
+ var _deploy_worker, _deploy, _output;
42
44
  var output = config.output, deploy = config.deploy;
43
- 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))) {
45
+ 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
46
  return true;
45
47
  }
46
48
  return false;
47
49
  };
48
50
  export var isRouterV5 = function(config) {
49
- var _config_runtime, _config_runtime1, _config_runtime_router;
50
- 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";
51
+ var _config_runtime, _config_runtime_router, _config_runtime1, _config;
52
+ 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
53
  };
52
54
  export var isSSGEntry = function(config, entryName, entrypoints) {
55
+ var _ssgConfig, _ssgConfig1;
53
56
  var ssgConfig = config.output.ssg;
54
- var 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]);
57
+ var useSSG = isSingleEntry(entrypoints) ? 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
58
  return useSSG;
56
59
  };
57
60
  export var isSingleEntry = function(entrypoints) {
@@ -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
- return url === null || url === void 0 ? void 0 : url.includes("localhost");
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 [
@@ -53,7 +54,7 @@ export var getAddressUrls = function() {
53
54
  export var prettyInstructions = function(appContext, config) {
54
55
  var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
55
56
  var entrypoints = appContext.entrypoints, serverRoutes = appContext.serverRoutes, port = appContext.port, apiOnly = appContext.apiOnly, checkedEntries = appContext.checkedEntries;
56
- var isHttps = 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);
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;
@@ -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 || mod === void 0 ? void 0 : mod.__esModule);
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 || config === void 0 ? void 0 : config.handle : {}),
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
- if ((parent === null || parent === void 0 ? void 0 : parent.loading) && lazyImport) {
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 || props === void 0 ? void 0 : props.nonce
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
- nestedRoute.loading = parent === null || parent === void 0 ? void 0 : parent.loading;
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 || children === void 0 ? void 0 : children.map(function(childRoute) {
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 parsed = JSON.parse((element === null || element === void 0 ? void 0 : element.textContent) || "");
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 _json_errors, _json_warnings, _result_errors;
45
- var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
46
- var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
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 };
@@ -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 || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
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 || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions1 = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths
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 */
@@ -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,11 @@
1
1
  import { isEmpty } from "./type";
2
2
  export const isSSR = (config) => {
3
+ var _server, _server1;
3
4
  const { server } = config;
4
- if (server === null || server === void 0 ? void 0 : server.ssr) {
5
+ if ((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) {
5
6
  return true;
6
7
  }
7
- if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
8
+ if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
8
9
  for (const name of Object.keys(server.ssrByEntries)) {
9
10
  if (server.ssrByEntries[name]) {
10
11
  return true;
@@ -14,27 +15,29 @@ export const isSSR = (config) => {
14
15
  return false;
15
16
  };
16
17
  export const isUseSSRBundle = (config) => {
18
+ var _output;
17
19
  const { output } = config;
18
- if (output === null || output === void 0 ? void 0 : output.ssg) {
20
+ if ((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) {
19
21
  return true;
20
22
  }
21
23
  return isSSR(config);
22
24
  };
23
25
  export const isServiceWorker = (config) => {
24
- var _deploy_worker;
26
+ var _deploy_worker, _deploy, _output;
25
27
  const { output, deploy } = config;
26
- 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))) {
28
+ 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
29
  return true;
28
30
  }
29
31
  return false;
30
32
  };
31
33
  export const isRouterV5 = (config) => {
32
- var _config_runtime, _config_runtime1, _config_runtime_router;
33
- 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";
34
+ var _config_runtime, _config_runtime_router, _config_runtime1, _config;
35
+ 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
36
  };
35
37
  export const isSSGEntry = (config, entryName, entrypoints) => {
38
+ var _ssgConfig, _ssgConfig1;
36
39
  const ssgConfig = config.output.ssg;
37
- 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]);
40
+ const useSSG = isSingleEntry(entrypoints) ? 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
41
  return useSSG;
39
42
  };
40
43
  export const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
@@ -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
- return url === null || url === void 0 ? void 0 : url.includes("localhost");
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 [
@@ -49,7 +50,7 @@ export const getAddressUrls = (protocol = "http", port, host) => {
49
50
  export const prettyInstructions = (appContext, config) => {
50
51
  var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
51
52
  const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
52
- const isHttps = 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);
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";
@@ -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 || mod === void 0 ? void 0 : mod.__esModule);
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 || config === void 0 ? void 0 : config.handle : {}
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
- if ((parent === null || parent === void 0 ? void 0 : parent.loading) && lazyImport) {
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 || props === void 0 ? void 0 : props.nonce
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
- nestedRoute.loading = parent === null || parent === void 0 ? void 0 : parent.loading;
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 || children === void 0 ? void 0 : children.map((childRoute) => {
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
  });
@@ -6,7 +6,8 @@ export const parsedJSONFromElement = (id) => {
6
6
  const element = elements[elements.length - 1];
7
7
  if (element) {
8
8
  try {
9
- const parsed = JSON.parse((element === null || element === void 0 ? void 0 : element.textContent) || "");
9
+ var _element;
10
+ const 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 ${id} error`, e);
@@ -42,13 +42,50 @@ ${stats.stack}` : "";
42
42
  message = lines.join("\n");
43
43
  return message.trim();
44
44
  }
45
- function formatWebpackMessages(json) {
46
- var _json_errors, _json_warnings, _result_errors;
47
- const formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
48
- const formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
45
+ const noop = (message) => message;
46
+ const defaultColor = {
47
+ gray: noop,
48
+ cyan: noop,
49
+ green: noop,
50
+ yellow: noop,
51
+ underline: noop
52
+ };
53
+ export function addErrorTips(errors, color = defaultColor) {
54
+ const errorHelpers = [
55
+ {
56
+ validator(message) {
57
+ return (message.includes("You may need an appropriate loader") || message.includes("You may need an additional loader")) && message.includes(".ts");
58
+ },
59
+ formatter(message) {
60
+ return `${message}
61
+
62
+ ${color.yellow(`If it is a TypeScript file, you can use "source.include" config to compile it. see ${color.underline("https://modernjs.dev/builder/en/api/config-source.html#sourceinclude")}`)}
63
+
64
+ ${color.green(`${color.gray("// config file")}
65
+ export default {
66
+ source: {
67
+ include: [
68
+ ${color.gray("// add some include rules")}
69
+ ]
70
+ }
71
+ }`)}
72
+ `;
73
+ }
74
+ }
75
+ ];
76
+ return errors.map((error) => {
77
+ const helper = errorHelpers.find((item) => item.validator(error));
78
+ return helper ? helper.formatter(error) : error;
79
+ });
80
+ }
81
+ function formatWebpackMessages(json, color = defaultColor) {
82
+ var _json_errors, _json, _json_warnings, _json1, _result_errors;
83
+ const formattedErrors = (_json = json) === null || _json === void 0 ? void 0 : (_json_errors = _json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
84
+ const formattedWarnings = (_json1 = json) === null || _json1 === void 0 ? void 0 : (_json_warnings = _json1.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
49
85
  const result = {
50
86
  errors: formattedErrors || [],
51
- warnings: formattedWarnings || []
87
+ warnings: formattedWarnings || [],
88
+ errorTips: []
52
89
  };
53
90
  if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
54
91
  result.errors = result.errors.filter(isLikelyASyntaxError);
@@ -56,6 +93,7 @@ function formatWebpackMessages(json) {
56
93
  if (result.errors.length > 1) {
57
94
  result.errors.length = 1;
58
95
  }
96
+ result.errors = addErrorTips(result.errors, color);
59
97
  return result;
60
98
  }
61
99
  export { formatWebpackMessages };
@@ -37,6 +37,8 @@ export declare const CHAIN_ID: {
37
37
  readonly YAML: "yaml";
38
38
  /** Rule for wasm */
39
39
  readonly WASM: "wasm";
40
+ /** Rule for node */
41
+ readonly NODE: "node";
40
42
  /** Rule for bff */
41
43
  readonly JS_BFF_API: "js-bff-api";
42
44
  };
@@ -75,6 +77,8 @@ export declare const CHAIN_ID: {
75
77
  readonly TOML: "toml";
76
78
  /** html-loader */
77
79
  readonly HTML: "html";
80
+ /** node-loader */
81
+ readonly NODE: "html";
78
82
  /** babel-loader */
79
83
  readonly BABEL: "babel";
80
84
  /** esbuild-loader */
@@ -6,7 +6,20 @@
6
6
  * https://github.com/facebook/create-react-app/blob/master/LICENSE
7
7
  */
8
8
  import type { StatsCompilation } from 'webpack';
9
- declare function formatWebpackMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>): {
9
+ export declare function addErrorTips(errors: string[], color?: {
10
+ gray: (message: string) => string;
11
+ cyan: (message: string) => string;
12
+ green: (message: string) => string;
13
+ yellow: (message: string) => string;
14
+ underline: (message: string) => string;
15
+ }): string[];
16
+ declare function formatWebpackMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>, color?: {
17
+ gray: (message: string) => string;
18
+ cyan: (message: string) => string;
19
+ green: (message: string) => string;
20
+ yellow: (message: string) => string;
21
+ underline: (message: string) => string;
22
+ }): {
10
23
  errors: string[];
11
24
  warnings: string[];
12
25
  };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.27.0",
18
+ "version": "2.28.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -235,9 +235,9 @@
235
235
  "typescript": "^5",
236
236
  "webpack": "^5.88.1",
237
237
  "@types/serialize-javascript": "^5.0.1",
238
- "@modern-js/types": "2.27.0",
239
- "@scripts/jest-config": "2.27.0",
240
- "@scripts/build": "2.27.0"
238
+ "@modern-js/types": "2.28.0",
239
+ "@scripts/build": "2.28.0",
240
+ "@scripts/jest-config": "2.28.0"
241
241
  },
242
242
  "sideEffects": false,
243
243
  "scripts": {