@modern-js/utils 2.69.5 → 3.0.0-alpha.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 (233) hide show
  1. package/dist/cjs/cli/alias.js +76 -70
  2. package/dist/cjs/cli/applyOptionsChain.js +44 -45
  3. package/dist/cjs/cli/babel.js +100 -119
  4. package/dist/cjs/cli/commands.js +61 -59
  5. package/dist/cjs/cli/common.js +45 -37
  6. package/dist/cjs/cli/config.js +36 -30
  7. package/dist/cjs/cli/constants.js +124 -161
  8. package/dist/cjs/cli/ensure.js +52 -45
  9. package/dist/cjs/cli/fs.js +41 -38
  10. package/dist/cjs/cli/get/config.js +43 -38
  11. package/dist/cjs/cli/get/data.js +108 -125
  12. package/dist/cjs/cli/get/index.js +109 -58
  13. package/dist/cjs/cli/index.js +202 -63
  14. package/dist/cjs/cli/is/config.js +75 -71
  15. package/dist/cjs/cli/is/env.js +49 -37
  16. package/dist/cjs/cli/is/index.js +76 -25
  17. package/dist/cjs/cli/is/project.js +139 -135
  18. package/dist/cjs/cli/is/type.js +65 -49
  19. package/dist/cjs/cli/logger.js +36 -27
  20. package/dist/cjs/cli/monorepo.js +100 -96
  21. package/dist/cjs/cli/package.js +85 -82
  22. package/dist/cjs/cli/path.js +101 -82
  23. package/dist/cjs/cli/port.js +71 -74
  24. package/dist/cjs/cli/prettyInstructions.js +106 -116
  25. package/dist/cjs/cli/require.js +116 -136
  26. package/dist/cjs/cli/route.js +67 -77
  27. package/dist/cjs/cli/runtimeExports.js +16 -70
  28. package/dist/cjs/cli/version.js +53 -42
  29. package/dist/cjs/cli/watch.js +79 -72
  30. package/dist/cjs/compiled.js +199 -128
  31. package/dist/cjs/import.js +58 -33
  32. package/dist/cjs/index.js +69 -23
  33. package/dist/cjs/universal/constants.js +77 -67
  34. package/dist/cjs/universal/index.js +33 -25
  35. package/dist/cjs/universal/path.js +33 -27
  36. package/dist/cjs/universal/pluginDagSort.js +69 -68
  37. package/dist/compiled/address/index.js +171 -1
  38. package/dist/compiled/browserslist/index.js +1329 -1
  39. package/dist/compiled/chalk/index.js +2368 -1
  40. package/dist/compiled/chokidar/index.js +4138 -16
  41. package/dist/compiled/chokidar/index.js.LICENSE.txt +41 -0
  42. package/dist/compiled/commander/index.js +1540 -1
  43. package/dist/compiled/debug/index.js +621 -1
  44. package/dist/compiled/dotenv/index.js +101 -1
  45. package/dist/compiled/dotenv-expand/index.js +54 -1
  46. package/dist/compiled/execa/index.js +1738 -1
  47. package/dist/compiled/fast-glob/index.js +4645 -17
  48. package/dist/compiled/fast-glob/index.js.LICENSE.txt +38 -0
  49. package/dist/compiled/filesize/index.js +193 -4
  50. package/dist/compiled/filesize/index.js.LICENSE.txt +7 -0
  51. package/dist/compiled/fs-extra/index.js +2222 -1
  52. package/dist/compiled/glob/index.js +2011 -1
  53. package/dist/compiled/globby/index.js +690 -1
  54. package/dist/compiled/gzip-size/index.js +157 -1
  55. package/dist/compiled/import-lazy/index.js +45 -1
  56. package/dist/compiled/inquirer/index.js +20162 -4
  57. package/dist/compiled/inquirer/index.js.LICENSE.txt +7 -0
  58. package/dist/compiled/js-yaml/index.js +2188 -1
  59. package/dist/compiled/json5/index.js +983 -1
  60. package/dist/compiled/lodash/index.js +0 -4
  61. package/dist/compiled/mime-types/index.js +108 -6
  62. package/dist/compiled/mime-types/index.js.LICENSE.txt +13 -0
  63. package/dist/compiled/minimist/index.js +202 -1
  64. package/dist/compiled/nanoid/index.js +83 -1
  65. package/dist/compiled/ora/index.js +3936 -3
  66. package/dist/compiled/ora/index.js.LICENSE.txt +1 -0
  67. package/dist/compiled/pkg-up/index.js +177 -1
  68. package/dist/compiled/semver/index.js +1779 -1
  69. package/dist/compiled/signale/index.js +1704 -1
  70. package/dist/compiled/slash/index.js +32 -1
  71. package/dist/compiled/strip-ansi/index.js +34 -1
  72. package/dist/compiled/tsconfig-paths/index.js +629 -1
  73. package/dist/compiled/upath/index.js +135 -1
  74. package/dist/compiled/url-join/index.js +61 -1
  75. package/dist/compiled/webpack-chain/index.js +1475 -1
  76. package/dist/esm/cli/alias.mjs +31 -0
  77. package/dist/esm/cli/applyOptionsChain.mjs +16 -0
  78. package/dist/esm/cli/babel.mjs +76 -0
  79. package/dist/esm/cli/commands.mjs +23 -0
  80. package/dist/esm/cli/common.mjs +11 -0
  81. package/dist/esm/cli/config.mjs +5 -0
  82. package/dist/esm/cli/constants.mjs +29 -0
  83. package/dist/esm/cli/ensure.mjs +9 -0
  84. package/dist/esm/cli/fs.mjs +9 -0
  85. package/dist/esm/cli/get/config.mjs +14 -0
  86. package/dist/esm/cli/get/data.mjs +57 -0
  87. package/dist/esm/cli/get/index.mjs +18 -0
  88. package/dist/{esm-node/cli/index.js → esm/cli/index.mjs} +0 -1
  89. package/dist/esm/cli/is/config.mjs +34 -0
  90. package/dist/esm/cli/is/env.mjs +6 -0
  91. package/dist/esm/cli/is/project.mjs +104 -0
  92. package/dist/esm/cli/is/type.mjs +26 -0
  93. package/dist/esm/cli/logger.mjs +2 -0
  94. package/dist/esm/cli/monorepo.mjs +50 -0
  95. package/dist/esm/cli/package.mjs +51 -0
  96. package/dist/esm/cli/path.mjs +35 -0
  97. package/dist/esm/cli/port.mjs +35 -0
  98. package/dist/esm/cli/prettyInstructions.mjs +68 -0
  99. package/dist/esm/cli/require.mjs +79 -0
  100. package/dist/esm/cli/route.mjs +36 -0
  101. package/dist/esm/cli/runtimeExports.mjs +0 -0
  102. package/dist/esm/cli/version.mjs +21 -0
  103. package/dist/esm/cli/watch.mjs +40 -0
  104. package/dist/esm/compiled.mjs +115 -0
  105. package/dist/esm/import.mjs +25 -0
  106. package/dist/esm/universal/constants.mjs +13 -0
  107. package/dist/{esm-node/universal/index.js → esm/universal/index.mjs} +1 -3
  108. package/dist/esm/universal/path.mjs +2 -0
  109. package/dist/esm/universal/pluginDagSort.mjs +41 -0
  110. package/dist/esm-node/cli/alias.mjs +31 -0
  111. package/dist/esm-node/cli/applyOptionsChain.mjs +16 -0
  112. package/dist/esm-node/cli/babel.mjs +76 -0
  113. package/dist/esm-node/cli/commands.mjs +23 -0
  114. package/dist/esm-node/cli/common.mjs +11 -0
  115. package/dist/esm-node/cli/config.mjs +5 -0
  116. package/dist/esm-node/cli/constants.mjs +29 -0
  117. package/dist/esm-node/cli/ensure.mjs +9 -0
  118. package/dist/esm-node/cli/fs.mjs +9 -0
  119. package/dist/esm-node/cli/get/config.mjs +14 -0
  120. package/dist/esm-node/cli/get/data.mjs +57 -0
  121. package/dist/esm-node/cli/get/index.mjs +18 -0
  122. package/dist/esm-node/cli/index.mjs +22 -0
  123. package/dist/esm-node/cli/is/config.mjs +34 -0
  124. package/dist/esm-node/cli/is/env.mjs +6 -0
  125. package/dist/esm-node/cli/is/index.mjs +4 -0
  126. package/dist/esm-node/cli/is/project.mjs +104 -0
  127. package/dist/esm-node/cli/is/type.mjs +26 -0
  128. package/dist/esm-node/cli/logger.mjs +2 -0
  129. package/dist/esm-node/cli/monorepo.mjs +50 -0
  130. package/dist/esm-node/cli/package.mjs +51 -0
  131. package/dist/esm-node/cli/path.mjs +35 -0
  132. package/dist/esm-node/cli/port.mjs +35 -0
  133. package/dist/esm-node/cli/prettyInstructions.mjs +68 -0
  134. package/dist/esm-node/cli/require.mjs +79 -0
  135. package/dist/esm-node/cli/route.mjs +36 -0
  136. package/dist/esm-node/cli/runtimeExports.mjs +0 -0
  137. package/dist/esm-node/cli/version.mjs +21 -0
  138. package/dist/esm-node/cli/watch.mjs +40 -0
  139. package/dist/esm-node/compiled.mjs +115 -0
  140. package/dist/esm-node/import.mjs +25 -0
  141. package/dist/esm-node/index.mjs +3 -0
  142. package/dist/esm-node/universal/constants.mjs +13 -0
  143. package/dist/esm-node/universal/index.mjs +2 -0
  144. package/dist/esm-node/universal/path.mjs +2 -0
  145. package/dist/esm-node/universal/pluginDagSort.mjs +41 -0
  146. package/dist/types/cli/constants.d.ts +2 -26
  147. package/dist/types/cli/get/data.d.ts +0 -1
  148. package/dist/types/cli/index.d.ts +0 -1
  149. package/dist/types/cli/is/config.d.ts +1 -1
  150. package/dist/types/cli/runtimeExports.d.ts +1 -4
  151. package/dist/types/cli/watch.d.ts +1 -1
  152. package/dist/types/compiled.d.ts +0 -5
  153. package/dist/types/universal/constants.d.ts +4 -7
  154. package/package.json +27 -27
  155. package/rslib.config.mts +140 -0
  156. package/dist/cjs/cli/action.js +0 -55
  157. package/dist/cjs/universal/formatWebpack.js +0 -127
  158. package/dist/esm/cli/action.js +0 -68
  159. package/dist/esm/cli/alias.js +0 -43
  160. package/dist/esm/cli/applyOptionsChain.js +0 -29
  161. package/dist/esm/cli/babel.js +0 -122
  162. package/dist/esm/cli/commands.js +0 -39
  163. package/dist/esm/cli/common.js +0 -20
  164. package/dist/esm/cli/config.js +0 -11
  165. package/dist/esm/cli/constants.js +0 -114
  166. package/dist/esm/cli/ensure.js +0 -16
  167. package/dist/esm/cli/fs.js +0 -65
  168. package/dist/esm/cli/get/config.js +0 -19
  169. package/dist/esm/cli/get/data.js +0 -143
  170. package/dist/esm/cli/get/index.js +0 -38
  171. package/dist/esm/cli/index.js +0 -23
  172. package/dist/esm/cli/is/config.js +0 -70
  173. package/dist/esm/cli/is/env.js +0 -22
  174. package/dist/esm/cli/is/index.js +0 -4
  175. package/dist/esm/cli/is/project.js +0 -146
  176. package/dist/esm/cli/is/type.js +0 -39
  177. package/dist/esm/cli/logger.js +0 -5
  178. package/dist/esm/cli/monorepo.js +0 -82
  179. package/dist/esm/cli/package.js +0 -203
  180. package/dist/esm/cli/path.js +0 -66
  181. package/dist/esm/cli/port.js +0 -97
  182. package/dist/esm/cli/prettyInstructions.js +0 -102
  183. package/dist/esm/cli/require.js +0 -235
  184. package/dist/esm/cli/route.js +0 -64
  185. package/dist/esm/cli/runtimeExports.js +0 -44
  186. package/dist/esm/cli/version.js +0 -26
  187. package/dist/esm/cli/watch.js +0 -112
  188. package/dist/esm/compiled.js +0 -66
  189. package/dist/esm/import.js +0 -11
  190. package/dist/esm/index.js +0 -3
  191. package/dist/esm/universal/constants.js +0 -32
  192. package/dist/esm/universal/formatWebpack.js +0 -95
  193. package/dist/esm/universal/index.js +0 -4
  194. package/dist/esm/universal/path.js +0 -6
  195. package/dist/esm/universal/pluginDagSort.js +0 -73
  196. package/dist/esm-node/cli/action.js +0 -30
  197. package/dist/esm-node/cli/alias.js +0 -40
  198. package/dist/esm-node/cli/applyOptionsChain.js +0 -27
  199. package/dist/esm-node/cli/babel.js +0 -107
  200. package/dist/esm-node/cli/commands.js +0 -39
  201. package/dist/esm-node/cli/common.js +0 -15
  202. package/dist/esm-node/cli/config.js +0 -9
  203. package/dist/esm-node/cli/constants.js +0 -114
  204. package/dist/esm-node/cli/ensure.js +0 -14
  205. package/dist/esm-node/cli/fs.js +0 -18
  206. package/dist/esm-node/cli/get/config.js +0 -19
  207. package/dist/esm-node/cli/get/data.js +0 -96
  208. package/dist/esm-node/cli/get/index.js +0 -22
  209. package/dist/esm-node/cli/is/config.js +0 -50
  210. package/dist/esm-node/cli/is/env.js +0 -12
  211. package/dist/esm-node/cli/is/project.js +0 -105
  212. package/dist/esm-node/cli/is/type.js +0 -36
  213. package/dist/esm-node/cli/logger.js +0 -5
  214. package/dist/esm-node/cli/monorepo.js +0 -67
  215. package/dist/esm-node/cli/package.js +0 -66
  216. package/dist/esm-node/cli/path.js +0 -48
  217. package/dist/esm-node/cli/port.js +0 -48
  218. package/dist/esm-node/cli/prettyInstructions.js +0 -90
  219. package/dist/esm-node/cli/require.js +0 -111
  220. package/dist/esm-node/cli/route.js +0 -60
  221. package/dist/esm-node/cli/runtimeExports.js +0 -38
  222. package/dist/esm-node/cli/version.js +0 -26
  223. package/dist/esm-node/cli/watch.js +0 -45
  224. package/dist/esm-node/compiled.js +0 -66
  225. package/dist/esm-node/import.js +0 -11
  226. package/dist/esm-node/universal/constants.js +0 -32
  227. package/dist/esm-node/universal/formatWebpack.js +0 -102
  228. package/dist/esm-node/universal/path.js +0 -6
  229. package/dist/esm-node/universal/pluginDagSort.js +0 -50
  230. package/dist/types/cli/action.d.ts +0 -2
  231. package/dist/types/universal/formatWebpack.d.ts +0 -26
  232. /package/dist/{esm-node/cli/is/index.js → esm/cli/is/index.mjs} +0 -0
  233. /package/dist/{esm-node/index.js → esm/index.mjs} +0 -0
@@ -0,0 +1,140 @@
1
+ import { rslibConfig } from '@modern-js/rslib';
2
+ import { type RslibConfig, type Rspack, defineConfig } from '@rslib/core';
3
+
4
+ const dependencies = [
5
+ // zero dependency
6
+ 'address',
7
+ 'filesize',
8
+ 'minimist',
9
+ 'commander',
10
+ 'import-lazy',
11
+ 'dotenv',
12
+ 'dotenv-expand',
13
+ 'url-join',
14
+ 'slash',
15
+ 'nanoid',
16
+ 'lodash',
17
+ {
18
+ name: 'upath',
19
+ },
20
+ // a few dependencies
21
+ 'debug',
22
+ 'semver',
23
+ 'js-yaml',
24
+ 'mime-types',
25
+ 'strip-ansi',
26
+ 'gzip-size',
27
+ 'pkg-up',
28
+ {
29
+ name: 'json5',
30
+ externals: {
31
+ minimist: '../minimist',
32
+ },
33
+ },
34
+ // some dependencies
35
+ 'glob',
36
+ 'chalk',
37
+ 'webpack-chain',
38
+ {
39
+ name: 'signale',
40
+ externals: {
41
+ chalk: '../chalk',
42
+ },
43
+ packageJsonField: ['options'],
44
+ },
45
+ 'execa',
46
+ 'fs-extra',
47
+ 'browserslist',
48
+ 'chokidar',
49
+ 'fast-glob',
50
+ {
51
+ name: 'globby',
52
+ externals: {
53
+ 'fast-glob': '../fast-glob',
54
+ },
55
+ },
56
+ {
57
+ name: 'ora',
58
+ externals: {
59
+ chalk: '../chalk',
60
+ 'strip-ansi': '../strip-ansi',
61
+ },
62
+ },
63
+ {
64
+ name: 'inquirer',
65
+ externals: {
66
+ ora: '../ora',
67
+ chalk: '../chalk',
68
+ 'strip-ansi': '../strip-ansi',
69
+ },
70
+ },
71
+ {
72
+ name: 'tsconfig-paths',
73
+ externals: {
74
+ json5: '../json5',
75
+ minimist: '../minimist',
76
+ },
77
+ },
78
+ ];
79
+
80
+ const regexpMap: Record<string, RegExp> = {};
81
+
82
+ for (const item of dependencies) {
83
+ const depName = typeof item === 'string' ? item : item.name;
84
+
85
+ // Skip dtsOnly dependencies
86
+ if (typeof item !== 'string' && 'dtsOnly' in item) {
87
+ continue;
88
+ }
89
+
90
+ regexpMap[depName] = new RegExp(`compiled[\\/]${depName}(?:[\\/]|$)`);
91
+ }
92
+
93
+ const externals: Rspack.Configuration['externals'] = [
94
+ // externalize pre-bundled dependencies
95
+ ({ request }, callback) => {
96
+ const entries = Object.entries(regexpMap);
97
+ if (request) {
98
+ for (const [name, test] of entries) {
99
+ if (request === name) {
100
+ throw new Error(
101
+ `"${name}" is not allowed to be imported, use "../compiled/${name}/index.js" instead.`,
102
+ );
103
+ }
104
+ if (test.test(request)) {
105
+ return callback(undefined, `node-commonjs ${request}/index.js`);
106
+ }
107
+ }
108
+ }
109
+ callback();
110
+ },
111
+ ];
112
+
113
+ const lib: RslibConfig['lib'] = rslibConfig.lib.map((config, index) => {
114
+ if (config.format === 'esm') {
115
+ return {
116
+ ...config,
117
+ output: {
118
+ ...config.output,
119
+ externals,
120
+ },
121
+ };
122
+ }
123
+ return {
124
+ ...config,
125
+ output: {
126
+ ...config.output,
127
+ copy: [
128
+ {
129
+ from: './compiled',
130
+ to: '../compiled',
131
+ },
132
+ ],
133
+ },
134
+ };
135
+ });
136
+
137
+ export default defineConfig({
138
+ ...rslibConfig,
139
+ lib,
140
+ });
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var action_exports = {};
20
- __export(action_exports, {
21
- newAction: () => newAction,
22
- upgradeAction: () => upgradeAction
23
- });
24
- module.exports = __toCommonJS(action_exports);
25
- var import_compiled = require("../compiled");
26
- const newAction = async (config, solution) => {
27
- var _process_env_MODERN_JS_VERSION;
28
- await (0, import_compiled.execa)("npx", [
29
- "--yes",
30
- `@modern-js/new-action@${(_process_env_MODERN_JS_VERSION = process.env.MODERN_JS_VERSION) !== null && _process_env_MODERN_JS_VERSION !== void 0 ? _process_env_MODERN_JS_VERSION : "latest"}`,
31
- `--config=${JSON.stringify(config)}`,
32
- `--solution=${solution}`
33
- ], {
34
- stderr: "inherit",
35
- stdout: "inherit",
36
- stdin: "inherit"
37
- });
38
- };
39
- const upgradeAction = async () => {
40
- var _process_env_MODERN_JS_VERSION;
41
- await (0, import_compiled.execa)("npx", [
42
- "--yes",
43
- `@modern-js/upgrade@${(_process_env_MODERN_JS_VERSION = process.env.MODERN_JS_VERSION) !== null && _process_env_MODERN_JS_VERSION !== void 0 ? _process_env_MODERN_JS_VERSION : "latest"}`,
44
- ...process.argv.slice(2)
45
- ], {
46
- stdin: "inherit",
47
- stdout: "inherit",
48
- stderr: "inherit"
49
- });
50
- };
51
- // Annotate the CommonJS export names for ESM import in node:
52
- 0 && (module.exports = {
53
- newAction,
54
- upgradeAction
55
- });
@@ -1,127 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var formatWebpack_exports = {};
20
- __export(formatWebpack_exports, {
21
- addErrorTips: () => addErrorTips,
22
- formatWebpackMessages: () => formatWebpackMessages
23
- });
24
- module.exports = __toCommonJS(formatWebpack_exports);
25
- const friendlySyntaxErrorLabel = "SyntaxError:";
26
- function isLikelyASyntaxError(message) {
27
- return message.includes(friendlySyntaxErrorLabel);
28
- }
29
- function formatMessage(stats) {
30
- let lines = [];
31
- let message;
32
- if (typeof stats === "object") {
33
- const fileName = stats.moduleName ? `File: ${stats.moduleName}
34
- ` : "";
35
- const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
36
- const details = stats.details ? `
37
- Details: ${stats.details}
38
- ` : "";
39
- const stack = stats.stack ? `
40
- ${stats.stack}` : "";
41
- message = `${fileName}${mainMessage}${details}${stack}`;
42
- } else {
43
- message = stats;
44
- }
45
- lines = message.split("\n");
46
- lines = lines.map((line) => {
47
- const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
48
- if (!parsingError) {
49
- return line;
50
- }
51
- const [, errorLine, errorColumn, errorMessage] = parsingError;
52
- return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
53
- });
54
- message = lines.join("\n");
55
- message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)
56
- `);
57
- lines = message.split("\n");
58
- if (lines.length > 2 && lines[1].trim() === "") {
59
- lines.splice(1, 1);
60
- }
61
- lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
62
- if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
63
- lines[1] = lines[1].replace("Error: ", "");
64
- }
65
- lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim());
66
- message = lines.join("\n");
67
- return message.trim();
68
- }
69
- const noop = (message) => message;
70
- const defaultColor = {
71
- gray: noop,
72
- cyan: noop,
73
- green: noop,
74
- yellow: noop,
75
- underline: noop
76
- };
77
- function addErrorTips(errors, color = defaultColor) {
78
- const errorHelpers = [
79
- {
80
- validator(message) {
81
- return (message.includes("You may need an appropriate loader") || message.includes("You may need an additional loader")) && message.includes(".ts");
82
- },
83
- formatter(message) {
84
- return `${message}
85
-
86
- ${color.yellow(`If it is a TypeScript file, you can use "source.include" config to compile it. see ${color.underline("https://modernjs.dev/en/configure/app/source/include.html")}`)}
87
-
88
- ${color.green(`${color.gray("// config file")}
89
- export default {
90
- source: {
91
- include: [
92
- ${color.gray("// add some include rules")}
93
- ]
94
- }
95
- }`)}
96
- `;
97
- }
98
- }
99
- ];
100
- return errors.map((error) => {
101
- const helper = errorHelpers.find((item) => item.validator(error));
102
- return helper ? helper.formatter(error) : error;
103
- });
104
- }
105
- function formatWebpackMessages(json, color = defaultColor) {
106
- var _json_errors, _json_warnings, _result_errors;
107
- const formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
108
- const formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
109
- const result = {
110
- errors: formattedErrors || [],
111
- warnings: formattedWarnings || [],
112
- errorTips: []
113
- };
114
- if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
115
- result.errors = result.errors.filter(isLikelyASyntaxError);
116
- }
117
- if (result.errors.length > 1) {
118
- result.errors.length = 1;
119
- }
120
- result.errors = addErrorTips(result.errors, color);
121
- return result;
122
- }
123
- // Annotate the CommonJS export names for ESM import in node:
124
- 0 && (module.exports = {
125
- addErrorTips,
126
- formatWebpackMessages
127
- });
@@ -1,68 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import { execa } from "../compiled";
5
- var newAction = function() {
6
- var _ref = _async_to_generator(function(config, solution) {
7
- var _process_env_MODERN_JS_VERSION;
8
- return _ts_generator(this, function(_state) {
9
- switch (_state.label) {
10
- case 0:
11
- return [
12
- 4,
13
- execa("npx", [
14
- "--yes",
15
- "@modern-js/new-action@".concat((_process_env_MODERN_JS_VERSION = process.env.MODERN_JS_VERSION) !== null && _process_env_MODERN_JS_VERSION !== void 0 ? _process_env_MODERN_JS_VERSION : "latest"),
16
- "--config=".concat(JSON.stringify(config)),
17
- "--solution=".concat(solution)
18
- ], {
19
- stderr: "inherit",
20
- stdout: "inherit",
21
- stdin: "inherit"
22
- })
23
- ];
24
- case 1:
25
- _state.sent();
26
- return [
27
- 2
28
- ];
29
- }
30
- });
31
- });
32
- return function newAction2(config, solution) {
33
- return _ref.apply(this, arguments);
34
- };
35
- }();
36
- var upgradeAction = function() {
37
- var _ref = _async_to_generator(function() {
38
- var _process_env_MODERN_JS_VERSION;
39
- return _ts_generator(this, function(_state) {
40
- switch (_state.label) {
41
- case 0:
42
- return [
43
- 4,
44
- execa("npx", [
45
- "--yes",
46
- "@modern-js/upgrade@".concat((_process_env_MODERN_JS_VERSION = process.env.MODERN_JS_VERSION) !== null && _process_env_MODERN_JS_VERSION !== void 0 ? _process_env_MODERN_JS_VERSION : "latest")
47
- ].concat(_to_consumable_array(process.argv.slice(2))), {
48
- stdin: "inherit",
49
- stdout: "inherit",
50
- stderr: "inherit"
51
- })
52
- ];
53
- case 1:
54
- _state.sent();
55
- return [
56
- 2
57
- ];
58
- }
59
- });
60
- });
61
- return function upgradeAction2() {
62
- return _ref.apply(this, arguments);
63
- };
64
- }();
65
- export {
66
- newAction,
67
- upgradeAction
68
- };
@@ -1,43 +0,0 @@
1
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
- import fs from "fs";
3
- import path from "path";
4
- import { applyOptionsChain } from "./applyOptionsChain";
5
- import { readTsConfigByFile } from "./get";
6
- var mergeAlias = function(alias) {
7
- return applyOptionsChain({}, alias);
8
- };
9
- var getAliasConfig = function(aliasOption, option) {
10
- var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
11
- var isTsProject = fs.existsSync(option.tsconfigPath);
12
- var alias = mergeAlias(aliasOption);
13
- if (!isTsProject) {
14
- return {
15
- absoluteBaseUrl: option.appDirectory,
16
- paths: alias,
17
- isTsPath: false,
18
- isTsProject
19
- };
20
- }
21
- var tsconfig = readTsConfigByFile(option.tsconfigPath);
22
- var baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
23
- return {
24
- absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
25
- 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),
26
- isTsPath: true,
27
- isTsProject
28
- };
29
- };
30
- var getUserAlias = function() {
31
- var alias = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
32
- return Object.keys(alias).reduce(function(o, k) {
33
- if (Array.isArray(alias[k])) {
34
- o[k] = alias[k];
35
- }
36
- return o;
37
- }, {});
38
- };
39
- export {
40
- getAliasConfig,
41
- getUserAlias,
42
- mergeAlias
43
- };
@@ -1,29 +0,0 @@
1
- import { isFunction, isPlainObject } from "./is";
2
- import { logger } from "./logger";
3
- function applyOptionsChain(defaults, options, utils) {
4
- var mergeFn = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : Object.assign;
5
- if (!options) {
6
- return defaults;
7
- }
8
- if (isPlainObject(options)) {
9
- return mergeFn(defaults, options);
10
- } else if (isFunction(options)) {
11
- var ret = options(defaults, utils);
12
- if (ret) {
13
- if (!isPlainObject(ret)) {
14
- logger.warn("".concat(options.name, ": Function should mutate the config and return nothing, Or return a cloned or merged version of config object."));
15
- }
16
- return ret;
17
- }
18
- } else if (Array.isArray(options)) {
19
- return options.reduce(function(memo, cur) {
20
- return applyOptionsChain(memo, cur, utils, mergeFn);
21
- }, defaults);
22
- } else {
23
- throw new Error("applyOptionsChain error:\ndefault options is: ".concat(JSON.stringify(defaults)));
24
- }
25
- return defaults;
26
- }
27
- export {
28
- applyOptionsChain
29
- };
@@ -1,122 +0,0 @@
1
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { isAbsolute, sep } from "path";
4
- import { applyOptionsChain } from "./applyOptionsChain";
5
- import { ensureArray } from "./ensure";
6
- import { normalizeToPosixPath } from "./path";
7
- var formatPath = function(originPath) {
8
- if (isAbsolute(originPath)) {
9
- return originPath.split(sep).join("/");
10
- }
11
- return originPath;
12
- };
13
- var getPluginItemName = function(item) {
14
- if (typeof item === "string") {
15
- return formatPath(item);
16
- }
17
- if (Array.isArray(item) && typeof item[0] === "string") {
18
- return formatPath(item[0]);
19
- }
20
- return null;
21
- };
22
- var addPlugins = function(plugins, config) {
23
- if (config.plugins) {
24
- var _config_plugins;
25
- (_config_plugins = config.plugins).push.apply(_config_plugins, _to_consumable_array(plugins));
26
- } else {
27
- config.plugins = plugins;
28
- }
29
- };
30
- var addPresets = function(presets, config) {
31
- if (config.presets) {
32
- var _config_presets;
33
- (_config_presets = config.presets).push.apply(_config_presets, _to_consumable_array(presets));
34
- } else {
35
- config.presets = presets;
36
- }
37
- };
38
- var removePlugins = function(plugins, config) {
39
- if (!config.plugins) {
40
- return;
41
- }
42
- var removeList = ensureArray(plugins);
43
- config.plugins = config.plugins.filter(function(item) {
44
- var name = getPluginItemName(item);
45
- if (name) {
46
- return !removeList.find(function(removeItem) {
47
- return name.includes(removeItem);
48
- });
49
- }
50
- return true;
51
- });
52
- };
53
- var removePresets = function(presets, config) {
54
- if (!config.presets) {
55
- return;
56
- }
57
- var removeList = ensureArray(presets);
58
- config.presets = config.presets.filter(function(item) {
59
- var name = getPluginItemName(item);
60
- if (name) {
61
- return !removeList.find(function(removeItem) {
62
- return name.includes(removeItem);
63
- });
64
- }
65
- return true;
66
- });
67
- };
68
- var modifyPresetOptions = function(presetName, options) {
69
- var presets = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
70
- presets.forEach(function(preset, index) {
71
- if (Array.isArray(preset)) {
72
- if (typeof preset[0] === "string" && normalizeToPosixPath(preset[0]).includes(presetName)) {
73
- preset[1] = _object_spread({}, preset[1] || {}, options);
74
- }
75
- } else if (typeof preset === "string" && normalizeToPosixPath(preset).includes(presetName)) {
76
- presets[index] = [
77
- preset,
78
- options
79
- ];
80
- }
81
- });
82
- };
83
- var getBabelUtils = function(config) {
84
- var noop = function() {
85
- };
86
- return {
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
- },
99
- // `addIncludes` and `addExcludes` are noop functions by default,
100
- // It can be overridden by `extraBabelUtils`.
101
- addIncludes: noop,
102
- addExcludes: noop,
103
- // Compat `presetEnvOptions` and `presetReactOptions` in Eden.
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
- }
110
- };
111
- };
112
- var applyUserBabelConfig = function(defaultOptions, userBabelConfig, extraBabelUtils) {
113
- if (userBabelConfig) {
114
- var babelUtils = _object_spread({}, getBabelUtils(defaultOptions), extraBabelUtils);
115
- return applyOptionsChain(defaultOptions, userBabelConfig || {}, babelUtils);
116
- }
117
- return defaultOptions;
118
- };
119
- export {
120
- applyUserBabelConfig,
121
- getBabelUtils
122
- };
@@ -1,39 +0,0 @@
1
- import { logger } from "./logger";
2
- var getFullArgv = function() {
3
- var _process_env_MODERN_ARGV;
4
- 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;
5
- };
6
- var getArgv = function() {
7
- return getFullArgv().slice(2);
8
- };
9
- var getCommand = function() {
10
- var args = getArgv();
11
- var command = args[0];
12
- return command;
13
- };
14
- var isDevCommand = function() {
15
- var command = getCommand();
16
- return command === "dev" || command === "start";
17
- };
18
- var deprecatedCommands = function(program) {
19
- var _program_commandsMap, _program_commandsMap1;
20
- var lintCommand = (_program_commandsMap = program.commandsMap) === null || _program_commandsMap === void 0 ? void 0 : _program_commandsMap.get("lint");
21
- if (!lintCommand) {
22
- program.command("lint [...files]").allowUnknownOption().description("Deprecated").action(function() {
23
- logger.warn('The "modern lint" command is deprecated, please use "eslint" or "biome" instead.');
24
- });
25
- }
26
- var preCommitCommand = (_program_commandsMap1 = program.commandsMap) === null || _program_commandsMap1 === void 0 ? void 0 : _program_commandsMap1.get("pre-commit");
27
- if (!preCommitCommand) {
28
- program.command("pre-commit").description("Deprecated").action(function() {
29
- logger.warn('The "modern pre-commit" command is deprecated, please use "lint-staged" instead.');
30
- });
31
- }
32
- };
33
- export {
34
- deprecatedCommands,
35
- getArgv,
36
- getCommand,
37
- getFullArgv,
38
- isDevCommand
39
- };
@@ -1,20 +0,0 @@
1
- import { debug } from "../../compiled/debug";
2
- var createDebugger = function(scope) {
3
- return debug("modern-js:".concat(scope));
4
- };
5
- var clearConsole = function() {
6
- if (process.stdout.isTTY && !process.env.DEBUG) {
7
- process.stdout.write("\x1B[H\x1B[2J");
8
- }
9
- };
10
- 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
- };
16
- export {
17
- clearConsole,
18
- createDebugger,
19
- wait
20
- };
@@ -1,11 +0,0 @@
1
- var isOverriddenConfigKey = function(key) {
2
- return [
3
- "removeConsole",
4
- "enableInlineScripts",
5
- "enableInlineStyles",
6
- "baseUrl"
7
- ].includes(key);
8
- };
9
- export {
10
- isOverriddenConfigKey
11
- };