@modern-js/utils 2.26.0 → 2.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/cli/alias.js +3 -3
  3. package/dist/cjs/cli/constants/chainId.js +4 -0
  4. package/dist/cjs/cli/constants/index.js +0 -1
  5. package/dist/cjs/cli/is/config.js +11 -8
  6. package/dist/cjs/cli/prettyInstructions.js +3 -2
  7. package/dist/cjs/cli/require.js +2 -1
  8. package/dist/cjs/runtime/nestedRoutes.js +9 -5
  9. package/dist/cjs/runtime-browser/parsed.js +2 -1
  10. package/dist/cjs/universal/formatWebpack.js +55 -12
  11. package/dist/esm/cli/alias.js +27 -23
  12. package/dist/esm/cli/applyOptionsChain.js +8 -6
  13. package/dist/esm/cli/babel.js +50 -35
  14. package/dist/esm/cli/commands.js +7 -7
  15. package/dist/esm/cli/common.js +10 -5
  16. package/dist/esm/cli/constants/chainId.js +5 -1
  17. package/dist/esm/cli/constants/index.js +33 -38
  18. package/dist/esm/cli/ensure.js +4 -2
  19. package/dist/esm/cli/fs.js +56 -9
  20. package/dist/esm/cli/get/config.js +7 -7
  21. package/dist/esm/cli/get/data.js +102 -55
  22. package/dist/esm/cli/get/index.js +21 -6
  23. package/dist/esm/cli/is/config.js +43 -21
  24. package/dist/esm/cli/is/env.js +18 -6
  25. package/dist/esm/cli/is/platform.js +6 -2
  26. package/dist/esm/cli/is/project.js +73 -36
  27. package/dist/esm/cli/is/type.js +3 -1
  28. package/dist/esm/cli/logger.js +49 -38
  29. package/dist/esm/cli/monorepo.js +49 -36
  30. package/dist/esm/cli/package.js +156 -38
  31. package/dist/esm/cli/path.js +44 -20
  32. package/dist/esm/cli/pathSerializer.js +29 -15
  33. package/dist/esm/cli/port.js +89 -40
  34. package/dist/esm/cli/prettyInstructions.js +44 -32
  35. package/dist/esm/cli/require.js +22 -16
  36. package/dist/esm/cli/runtimeExports.js +21 -15
  37. package/dist/esm/cli/watch.js +94 -27
  38. package/dist/esm/compiled.js +3 -3
  39. package/dist/esm/import.js +4 -4
  40. package/dist/esm/runtime/nestedRoutes.js +49 -32
  41. package/dist/esm/runtime-browser/parsed.js +6 -5
  42. package/dist/esm/runtime-node/index.js +1 -1
  43. package/dist/esm/runtime-node/nestedRoutes.js +6 -4
  44. package/dist/esm/runtime-node/serialize.js +1 -1
  45. package/dist/esm/runtime-node/storage.js +12 -14
  46. package/dist/esm/universal/constants.js +3 -3
  47. package/dist/esm/universal/formatWebpack.js +54 -28
  48. package/dist/esm/universal/pluginDagSort.js +49 -26
  49. package/dist/esm-node/cli/alias.js +51 -0
  50. package/dist/esm-node/cli/applyOptionsChain.js +24 -0
  51. package/dist/esm-node/cli/babel.js +103 -0
  52. package/dist/esm-node/cli/commands.js +16 -0
  53. package/dist/esm-node/cli/common.js +10 -0
  54. package/dist/esm-node/cli/constants/chainId.js +184 -0
  55. package/dist/esm-node/cli/constants/index.js +102 -0
  56. package/dist/esm-node/cli/ensure.js +10 -0
  57. package/dist/esm-node/cli/fs.js +14 -0
  58. package/dist/esm-node/cli/get/config.js +16 -0
  59. package/dist/esm-node/cli/get/data.js +86 -0
  60. package/dist/esm-node/cli/get/index.js +13 -0
  61. package/dist/esm-node/cli/index.js +20 -0
  62. package/dist/esm-node/cli/is/config.js +43 -0
  63. package/dist/esm-node/cli/is/env.js +6 -0
  64. package/dist/esm-node/cli/is/index.js +5 -0
  65. package/dist/esm-node/cli/is/platform.js +2 -0
  66. package/dist/esm-node/cli/is/project.js +73 -0
  67. package/dist/esm-node/cli/is/type.js +25 -0
  68. package/dist/esm-node/cli/logger.js +103 -0
  69. package/dist/esm-node/cli/monorepo.js +70 -0
  70. package/dist/esm-node/cli/package.js +43 -0
  71. package/dist/esm-node/cli/path.js +49 -0
  72. package/dist/esm-node/cli/pathSerializer.js +46 -0
  73. package/dist/esm-node/cli/port.js +44 -0
  74. package/dist/esm-node/cli/prettyInstructions.js +78 -0
  75. package/dist/esm-node/cli/require.js +53 -0
  76. package/dist/esm-node/cli/runtimeExports.js +35 -0
  77. package/dist/esm-node/cli/watch.js +41 -0
  78. package/dist/esm-node/compiled.js +33 -0
  79. package/dist/esm-node/import.js +8 -0
  80. package/dist/esm-node/index.js +3 -0
  81. package/dist/esm-node/runtime/nestedRoutes.js +116 -0
  82. package/dist/esm-node/runtime/remixRouter.js +1 -0
  83. package/dist/esm-node/runtime/router.js +1 -0
  84. package/dist/esm-node/runtime-browser/index.js +1 -0
  85. package/dist/esm-node/runtime-browser/parsed.js +18 -0
  86. package/dist/esm-node/runtime-node/index.js +5 -0
  87. package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
  88. package/dist/esm-node/runtime-node/router.js +1 -0
  89. package/dist/esm-node/runtime-node/serialize.js +6 -0
  90. package/dist/esm-node/runtime-node/storage.js +38 -0
  91. package/dist/esm-node/universal/constants.js +3 -0
  92. package/dist/esm-node/universal/formatWebpack.js +99 -0
  93. package/dist/esm-node/universal/pluginDagSort.js +50 -0
  94. package/dist/types/cli/constants/chainId.d.ts +4 -0
  95. package/dist/types/universal/formatWebpack.d.ts +14 -1
  96. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
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
+
11
+ ## 2.27.0
12
+
13
+ ### Patch Changes
14
+
15
+ - 91d14b8: fix(utils): using universal build config and fix compatibility issue
16
+
17
+ fix(utils): 使用 universal 构建配置,修复兼容性问题
18
+
19
+ - 6d7104d: fix(builder): should not strip error stacks
20
+
21
+ fix(builder): 不应该移除错误堆栈
22
+
3
23
  ## 2.26.0
4
24
 
5
25
  ## 2.25.2
@@ -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
  });
@@ -48,21 +57,54 @@ ${stats.stack}` : "";
48
57
  if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
49
58
  lines[1] = lines[1].replace("Error: ", "");
50
59
  }
51
- message = lines.join("\n");
52
- message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, "");
53
- message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, "");
54
- lines = message.split("\n");
55
60
  lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim());
56
61
  message = lines.join("\n");
57
62
  return message.trim();
58
63
  }
59
- function formatWebpackMessages(json) {
60
- var _json_errors, _json_warnings, _result_errors;
61
- const formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
62
- 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);
63
104
  const result = {
64
105
  errors: formattedErrors || [],
65
- warnings: formattedWarnings || []
106
+ warnings: formattedWarnings || [],
107
+ errorTips: []
66
108
  };
67
109
  if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
68
110
  result.errors = result.errors.filter(isLikelyASyntaxError);
@@ -70,5 +112,6 @@ function formatWebpackMessages(json) {
70
112
  if (result.errors.length > 1) {
71
113
  result.errors.length = 1;
72
114
  }
115
+ result.errors = addErrorTips(result.errors, color);
73
116
  return result;
74
117
  }
@@ -1,51 +1,55 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
1
2
  import fs from "fs";
2
3
  import path from "path";
3
4
  import { chalk } from "../compiled";
4
5
  import { readTsConfigByFile } from "./get";
5
6
  import { applyOptionsChain } from "./applyOptionsChain";
6
- export const validAlias = (modernConfig, { tsconfigPath }) => {
7
- const { source: { alias } } = modernConfig;
7
+ export var validAlias = function(modernConfig, param) {
8
+ var tsconfigPath = param.tsconfigPath;
9
+ var alias = modernConfig.source.alias;
8
10
  if (!alias) {
9
11
  return null;
10
12
  }
11
- const isTsProject = fs.existsSync(tsconfigPath);
13
+ var isTsProject = fs.existsSync(tsconfigPath);
12
14
  if (!isTsProject) {
13
15
  return null;
14
16
  }
15
- const userAlias = getUserAlias(alias);
17
+ var userAlias = getUserAlias(alias);
16
18
  if (Object.keys(userAlias).length > 0) {
17
19
  return chalk.red('Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript');
18
20
  }
19
21
  return null;
20
22
  };
21
- export const mergeAlias = (alias) => applyOptionsChain({}, alias);
22
- export const getAliasConfig = (aliasOption, option) => {
23
- var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
24
- const isTsProject = fs.existsSync(option.tsconfigPath);
25
- const alias = mergeAlias(aliasOption);
23
+ export var mergeAlias = function(alias) {
24
+ return applyOptionsChain({}, alias);
25
+ };
26
+ export var getAliasConfig = function(aliasOption, option) {
27
+ var _tsconfig_compilerOptions, _tsconfig, _tsconfig_compilerOptions1, _tsconfig1;
28
+ var isTsProject = fs.existsSync(option.tsconfigPath);
29
+ var alias = mergeAlias(aliasOption);
26
30
  if (!isTsProject) {
27
31
  return {
28
32
  absoluteBaseUrl: option.appDirectory,
29
33
  paths: alias,
30
34
  isTsPath: false,
31
- isTsProject
35
+ isTsProject: isTsProject
32
36
  };
33
37
  }
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;
38
+ var tsconfig = readTsConfigByFile(option.tsconfigPath);
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;
36
40
  return {
37
41
  absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
38
- paths: {
39
- ...alias,
40
- ...tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions1 = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths
41
- },
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),
42
43
  isTsPath: true,
43
- isTsProject
44
+ isTsProject: isTsProject
44
45
  };
45
46
  };
46
- export const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
47
- if (Array.isArray(alias[k])) {
48
- o[k] = alias[k];
49
- }
50
- return o;
51
- }, {});
47
+ export var getUserAlias = function() {
48
+ var alias = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
49
+ return Object.keys(alias).reduce(function(o, k) {
50
+ if (Array.isArray(alias[k])) {
51
+ o[k] = alias[k];
52
+ }
53
+ return o;
54
+ }, {});
55
+ };
@@ -1,24 +1,26 @@
1
1
  import { isFunction, isPlainObject } from "./is";
2
2
  import { logger } from "./logger";
3
- export function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
3
+ export function applyOptionsChain(defaults, options, utils) {
4
+ var mergeFn = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : Object.assign;
4
5
  if (!options) {
5
6
  return defaults;
6
7
  }
7
8
  if (isPlainObject(options)) {
8
9
  return mergeFn(defaults, options);
9
10
  } else if (isFunction(options)) {
10
- const ret = options(defaults, utils);
11
+ var ret = options(defaults, utils);
11
12
  if (ret) {
12
13
  if (!isPlainObject(ret)) {
13
- logger.warn(`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`);
14
+ logger.warn("".concat(options.name, ": Function should mutate the config and return nothing, Or return a cloned or merged version of config object."));
14
15
  }
15
16
  return ret;
16
17
  }
17
18
  } else if (Array.isArray(options)) {
18
- return options.reduce((memo, cur) => applyOptionsChain(memo, cur, utils, mergeFn), defaults);
19
+ return options.reduce(function(memo, cur) {
20
+ return applyOptionsChain(memo, cur, utils, mergeFn);
21
+ }, defaults);
19
22
  } else {
20
- throw new Error(`applyOptionsChain error:
21
- default options is: ${JSON.stringify(defaults)}`);
23
+ throw new Error("applyOptionsChain error:\ndefault options is: ".concat(JSON.stringify(defaults)));
22
24
  }
23
25
  return defaults;
24
26
  }
@@ -1,14 +1,16 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
3
  import { isAbsolute, sep } from "path";
2
4
  import { applyOptionsChain } from "./applyOptionsChain";
3
5
  import { ensureArray } from "./ensure";
4
6
  import { normalizeToPosixPath } from "./path";
5
- const formatPath = (originPath) => {
7
+ var formatPath = function(originPath) {
6
8
  if (isAbsolute(originPath)) {
7
9
  return originPath.split(sep).join("/");
8
10
  }
9
11
  return originPath;
10
12
  };
11
- const getPluginItemName = (item) => {
13
+ var getPluginItemName = function(item) {
12
14
  if (typeof item === "string") {
13
15
  return formatPath(item);
14
16
  }
@@ -17,54 +19,58 @@ const getPluginItemName = (item) => {
17
19
  }
18
20
  return null;
19
21
  };
20
- const addPlugins = (plugins, config) => {
22
+ var addPlugins = function(plugins, config) {
21
23
  if (config.plugins) {
22
- config.plugins.push(...plugins);
24
+ var _config_plugins;
25
+ (_config_plugins = config.plugins).push.apply(_config_plugins, _to_consumable_array(plugins));
23
26
  } else {
24
27
  config.plugins = plugins;
25
28
  }
26
29
  };
27
- const addPresets = (presets, config) => {
30
+ var addPresets = function(presets, config) {
28
31
  if (config.presets) {
29
- config.presets.push(...presets);
32
+ var _config_presets;
33
+ (_config_presets = config.presets).push.apply(_config_presets, _to_consumable_array(presets));
30
34
  } else {
31
35
  config.presets = presets;
32
36
  }
33
37
  };
34
- const removePlugins = (plugins, config) => {
38
+ var removePlugins = function(plugins, config) {
35
39
  if (!config.plugins) {
36
40
  return;
37
41
  }
38
- const removeList = ensureArray(plugins);
39
- config.plugins = config.plugins.filter((item) => {
40
- const name = getPluginItemName(item);
42
+ var removeList = ensureArray(plugins);
43
+ config.plugins = config.plugins.filter(function(item) {
44
+ var name = getPluginItemName(item);
41
45
  if (name) {
42
- return !removeList.find((removeItem) => name.includes(removeItem));
46
+ return !removeList.find(function(removeItem) {
47
+ return name.includes(removeItem);
48
+ });
43
49
  }
44
50
  return true;
45
51
  });
46
52
  };
47
- const removePresets = (presets, config) => {
53
+ var removePresets = function(presets, config) {
48
54
  if (!config.presets) {
49
55
  return;
50
56
  }
51
- const removeList = ensureArray(presets);
52
- config.presets = config.presets.filter((item) => {
53
- const name = getPluginItemName(item);
57
+ var removeList = ensureArray(presets);
58
+ config.presets = config.presets.filter(function(item) {
59
+ var name = getPluginItemName(item);
54
60
  if (name) {
55
- return !removeList.find((removeItem) => name.includes(removeItem));
61
+ return !removeList.find(function(removeItem) {
62
+ return name.includes(removeItem);
63
+ });
56
64
  }
57
65
  return true;
58
66
  });
59
67
  };
60
- const modifyPresetOptions = (presetName, options, presets = []) => {
61
- presets.forEach((preset, index) => {
68
+ var modifyPresetOptions = function(presetName, options) {
69
+ var presets = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
70
+ presets.forEach(function(preset, index) {
62
71
  if (Array.isArray(preset)) {
63
72
  if (typeof preset[0] === "string" && normalizeToPosixPath(preset[0]).includes(presetName)) {
64
- preset[1] = {
65
- ...preset[1] || {},
66
- ...options
67
- };
73
+ preset[1] = _object_spread({}, preset[1] || {}, options);
68
74
  }
69
75
  } else if (typeof preset === "string" && normalizeToPosixPath(preset).includes(presetName)) {
70
76
  presets[index] = [
@@ -74,29 +80,38 @@ const modifyPresetOptions = (presetName, options, presets = []) => {
74
80
  }
75
81
  });
76
82
  };
77
- export const getBabelUtils = (config) => {
78
- const noop = () => {
83
+ export var getBabelUtils = function(config) {
84
+ var noop = function() {
79
85
  };
80
86
  return {
81
- addPlugins: (plugins) => addPlugins(plugins, config),
82
- addPresets: (presets) => addPresets(presets, config),
83
- removePlugins: (plugins) => removePlugins(plugins, config),
84
- removePresets: (presets) => removePresets(presets, config),
87
+ addPlugins: function(plugins) {
88
+ return addPlugins(plugins, config);
89
+ },
90
+ addPresets: function(presets) {
91
+ return addPresets(presets, config);
92
+ },
93
+ removePlugins: function(plugins) {
94
+ return removePlugins(plugins, config);
95
+ },
96
+ removePresets: function(presets) {
97
+ return removePresets(presets, config);
98
+ },
85
99
  // `addIncludes` and `addExcludes` are noop functions by default,
86
100
  // It can be overridden by `extraBabelUtils`.
87
101
  addIncludes: noop,
88
102
  addExcludes: noop,
89
103
  // Compat `presetEnvOptions` and `presetReactOptions` in Eden.
90
- modifyPresetEnvOptions: (options) => modifyPresetOptions("@babel/preset-env", options, config.presets || []),
91
- modifyPresetReactOptions: (options) => modifyPresetOptions("@babel/preset-react", options, config.presets || [])
104
+ modifyPresetEnvOptions: function(options) {
105
+ return modifyPresetOptions("@babel/preset-env", options, config.presets || []);
106
+ },
107
+ modifyPresetReactOptions: function(options) {
108
+ return modifyPresetOptions("@babel/preset-react", options, config.presets || []);
109
+ }
92
110
  };
93
111
  };
94
- export const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils) => {
112
+ export var applyUserBabelConfig = function(defaultOptions, userBabelConfig, extraBabelUtils) {
95
113
  if (userBabelConfig) {
96
- const babelUtils = {
97
- ...getBabelUtils(defaultOptions),
98
- ...extraBabelUtils
99
- };
114
+ var babelUtils = _object_spread({}, getBabelUtils(defaultOptions), extraBabelUtils);
100
115
  return applyOptionsChain(defaultOptions, userBabelConfig || {}, babelUtils);
101
116
  }
102
117
  return defaultOptions;
@@ -1,16 +1,16 @@
1
- export const getFullArgv = () => {
1
+ export var getFullArgv = function() {
2
2
  var _process_env_MODERN_ARGV;
3
3
  return ((_process_env_MODERN_ARGV = process.env.MODERN_ARGV) === null || _process_env_MODERN_ARGV === void 0 ? void 0 : _process_env_MODERN_ARGV.split(" ")) || process.argv;
4
4
  };
5
- export const getArgv = () => {
5
+ export var getArgv = function() {
6
6
  return getFullArgv().slice(2);
7
7
  };
8
- export const getCommand = () => {
9
- const args = getArgv();
10
- const command = args[0];
8
+ export var getCommand = function() {
9
+ var args = getArgv();
10
+ var command = args[0];
11
11
  return command;
12
12
  };
13
- export const isDevCommand = () => {
14
- const command = getCommand();
13
+ export var isDevCommand = function() {
14
+ var command = getCommand();
15
15
  return command === "dev" || command === "start";
16
16
  };
@@ -1,10 +1,15 @@
1
1
  import { debug } from "../../compiled/debug";
2
- export const createDebugger = (scope) => debug(`modern-js:${scope}`);
3
- export const clearConsole = () => {
2
+ export var createDebugger = function(scope) {
3
+ return debug("modern-js:".concat(scope));
4
+ };
5
+ export var clearConsole = function() {
4
6
  if (process.stdout.isTTY && !process.env.DEBUG) {
5
7
  process.stdout.write("\x1B[H\x1B[2J");
6
8
  }
7
9
  };
8
- export const wait = (time = 0) => new Promise((resolve) => {
9
- setTimeout(resolve, time);
10
- });
10
+ export var wait = function() {
11
+ var time = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
12
+ return new Promise(function(resolve) {
13
+ setTimeout(resolve, time);
14
+ });
15
+ };