@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
@@ -1,6 +0,0 @@
1
- var cutNameByHyphen = function(s) {
2
- return s.split(/[-_]/)[0];
3
- };
4
- export {
5
- cutNameByHyphen
6
- };
@@ -1,73 +0,0 @@
1
- var pluginDagSort = function(plugins) {
2
- var _loop = function() {
3
- var zep = zeroEndPoints.shift();
4
- sortedPoint.push(getPluginByAny(zep));
5
- allLines = allLines.filter(function(l) {
6
- return l[0] !== getPluginByAny(zep)[key];
7
- });
8
- var restPoints = plugins.filter(function(item) {
9
- return !sortedPoint.find(function(sp) {
10
- return sp[key] === item[key];
11
- });
12
- });
13
- zeroEndPoints = restPoints.filter(function(item) {
14
- return !allLines.find(function(l) {
15
- return l[1] === item[key];
16
- });
17
- });
18
- };
19
- var key = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "name", preKey = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "pre", postKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "post";
20
- var getPluginByAny = function getPluginByAny2(q) {
21
- var target = plugins.find(function(item) {
22
- return typeof q === "string" ? item[key] === q : item[key] === q[key];
23
- });
24
- if (!target) {
25
- throw new Error("plugin ".concat(q, " not existed"));
26
- }
27
- return target;
28
- };
29
- var allLines = [];
30
- plugins.forEach(function(item) {
31
- var _item_preKey, _item_postKey;
32
- (_item_preKey = item[preKey]) === null || _item_preKey === void 0 ? void 0 : _item_preKey.forEach(function(p) {
33
- if (plugins.find(function(ap) {
34
- return ap.name === p;
35
- })) {
36
- allLines.push([
37
- getPluginByAny(p)[key],
38
- getPluginByAny(item)[key]
39
- ]);
40
- }
41
- });
42
- (_item_postKey = item[postKey]) === null || _item_postKey === void 0 ? void 0 : _item_postKey.forEach(function(pt) {
43
- if (plugins.find(function(ap) {
44
- return ap.name === pt;
45
- })) {
46
- allLines.push([
47
- getPluginByAny(item)[key],
48
- getPluginByAny(pt)[key]
49
- ]);
50
- }
51
- });
52
- });
53
- var zeroEndPoints = plugins.filter(function(item) {
54
- return !allLines.find(function(l) {
55
- return l[1] === item[key];
56
- });
57
- });
58
- var sortedPoint = [];
59
- while (zeroEndPoints.length)
60
- _loop();
61
- if (allLines.length) {
62
- var restInRingPoints = {};
63
- allLines.forEach(function(l) {
64
- restInRingPoints[l[0]] = true;
65
- restInRingPoints[l[1]] = true;
66
- });
67
- throw new Error("plugins dependencies has loop: ".concat(Object.keys(restInRingPoints).join(",")));
68
- }
69
- return sortedPoint;
70
- };
71
- export {
72
- pluginDagSort
73
- };
@@ -1,30 +0,0 @@
1
- import { execa } from "../compiled";
2
- const newAction = async (config, solution) => {
3
- var _process_env_MODERN_JS_VERSION;
4
- await execa("npx", [
5
- "--yes",
6
- `@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"}`,
7
- `--config=${JSON.stringify(config)}`,
8
- `--solution=${solution}`
9
- ], {
10
- stderr: "inherit",
11
- stdout: "inherit",
12
- stdin: "inherit"
13
- });
14
- };
15
- const upgradeAction = async () => {
16
- var _process_env_MODERN_JS_VERSION;
17
- await execa("npx", [
18
- "--yes",
19
- `@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"}`,
20
- ...process.argv.slice(2)
21
- ], {
22
- stdin: "inherit",
23
- stdout: "inherit",
24
- stderr: "inherit"
25
- });
26
- };
27
- export {
28
- newAction,
29
- upgradeAction
30
- };
@@ -1,40 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { applyOptionsChain } from "./applyOptionsChain";
4
- import { readTsConfigByFile } from "./get";
5
- const mergeAlias = (alias) => applyOptionsChain({}, alias);
6
- const getAliasConfig = (aliasOption, option) => {
7
- var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
8
- const isTsProject = fs.existsSync(option.tsconfigPath);
9
- const alias = mergeAlias(aliasOption);
10
- if (!isTsProject) {
11
- return {
12
- absoluteBaseUrl: option.appDirectory,
13
- paths: alias,
14
- isTsPath: false,
15
- isTsProject
16
- };
17
- }
18
- const tsconfig = readTsConfigByFile(option.tsconfigPath);
19
- const baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
20
- return {
21
- absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
22
- paths: {
23
- ...alias,
24
- ...tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions1 = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths
25
- },
26
- isTsPath: true,
27
- isTsProject
28
- };
29
- };
30
- const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
31
- if (Array.isArray(alias[k])) {
32
- o[k] = alias[k];
33
- }
34
- return o;
35
- }, {});
36
- export {
37
- getAliasConfig,
38
- getUserAlias,
39
- mergeAlias
40
- };
@@ -1,27 +0,0 @@
1
- import { isFunction, isPlainObject } from "./is";
2
- import { logger } from "./logger";
3
- function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
4
- if (!options) {
5
- return defaults;
6
- }
7
- if (isPlainObject(options)) {
8
- return mergeFn(defaults, options);
9
- } else if (isFunction(options)) {
10
- const ret = options(defaults, utils);
11
- if (ret) {
12
- 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
- }
15
- return ret;
16
- }
17
- } else if (Array.isArray(options)) {
18
- return options.reduce((memo, cur) => applyOptionsChain(memo, cur, utils, mergeFn), defaults);
19
- } else {
20
- throw new Error(`applyOptionsChain error:
21
- default options is: ${JSON.stringify(defaults)}`);
22
- }
23
- return defaults;
24
- }
25
- export {
26
- applyOptionsChain
27
- };
@@ -1,107 +0,0 @@
1
- import { isAbsolute, sep } from "path";
2
- import { applyOptionsChain } from "./applyOptionsChain";
3
- import { ensureArray } from "./ensure";
4
- import { normalizeToPosixPath } from "./path";
5
- const formatPath = (originPath) => {
6
- if (isAbsolute(originPath)) {
7
- return originPath.split(sep).join("/");
8
- }
9
- return originPath;
10
- };
11
- const getPluginItemName = (item) => {
12
- if (typeof item === "string") {
13
- return formatPath(item);
14
- }
15
- if (Array.isArray(item) && typeof item[0] === "string") {
16
- return formatPath(item[0]);
17
- }
18
- return null;
19
- };
20
- const addPlugins = (plugins, config) => {
21
- if (config.plugins) {
22
- config.plugins.push(...plugins);
23
- } else {
24
- config.plugins = plugins;
25
- }
26
- };
27
- const addPresets = (presets, config) => {
28
- if (config.presets) {
29
- config.presets.push(...presets);
30
- } else {
31
- config.presets = presets;
32
- }
33
- };
34
- const removePlugins = (plugins, config) => {
35
- if (!config.plugins) {
36
- return;
37
- }
38
- const removeList = ensureArray(plugins);
39
- config.plugins = config.plugins.filter((item) => {
40
- const name = getPluginItemName(item);
41
- if (name) {
42
- return !removeList.find((removeItem) => name.includes(removeItem));
43
- }
44
- return true;
45
- });
46
- };
47
- const removePresets = (presets, config) => {
48
- if (!config.presets) {
49
- return;
50
- }
51
- const removeList = ensureArray(presets);
52
- config.presets = config.presets.filter((item) => {
53
- const name = getPluginItemName(item);
54
- if (name) {
55
- return !removeList.find((removeItem) => name.includes(removeItem));
56
- }
57
- return true;
58
- });
59
- };
60
- const modifyPresetOptions = (presetName, options, presets = []) => {
61
- presets.forEach((preset, index) => {
62
- if (Array.isArray(preset)) {
63
- if (typeof preset[0] === "string" && normalizeToPosixPath(preset[0]).includes(presetName)) {
64
- preset[1] = {
65
- ...preset[1] || {},
66
- ...options
67
- };
68
- }
69
- } else if (typeof preset === "string" && normalizeToPosixPath(preset).includes(presetName)) {
70
- presets[index] = [
71
- preset,
72
- options
73
- ];
74
- }
75
- });
76
- };
77
- const getBabelUtils = (config) => {
78
- const noop = () => {
79
- };
80
- 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),
85
- // `addIncludes` and `addExcludes` are noop functions by default,
86
- // It can be overridden by `extraBabelUtils`.
87
- addIncludes: noop,
88
- addExcludes: noop,
89
- // 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 || [])
92
- };
93
- };
94
- const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils) => {
95
- if (userBabelConfig) {
96
- const babelUtils = {
97
- ...getBabelUtils(defaultOptions),
98
- ...extraBabelUtils
99
- };
100
- return applyOptionsChain(defaultOptions, userBabelConfig || {}, babelUtils);
101
- }
102
- return defaultOptions;
103
- };
104
- export {
105
- applyUserBabelConfig,
106
- getBabelUtils
107
- };
@@ -1,39 +0,0 @@
1
- import { logger } from "./logger";
2
- const getFullArgv = () => {
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
- const getArgv = () => {
7
- return getFullArgv().slice(2);
8
- };
9
- const getCommand = () => {
10
- const args = getArgv();
11
- const command = args[0];
12
- return command;
13
- };
14
- const isDevCommand = () => {
15
- const command = getCommand();
16
- return command === "dev" || command === "start";
17
- };
18
- const deprecatedCommands = (program) => {
19
- var _program_commandsMap, _program_commandsMap1;
20
- const 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(() => {
23
- logger.warn('The "modern lint" command is deprecated, please use "eslint" or "biome" instead.');
24
- });
25
- }
26
- const 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(() => {
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,15 +0,0 @@
1
- import { debug } from "../../compiled/debug";
2
- const createDebugger = (scope) => debug(`modern-js:${scope}`);
3
- const clearConsole = () => {
4
- if (process.stdout.isTTY && !process.env.DEBUG) {
5
- process.stdout.write("\x1B[H\x1B[2J");
6
- }
7
- };
8
- const wait = (time = 0) => new Promise((resolve) => {
9
- setTimeout(resolve, time);
10
- });
11
- export {
12
- clearConsole,
13
- createDebugger,
14
- wait
15
- };
@@ -1,9 +0,0 @@
1
- const isOverriddenConfigKey = (key) => [
2
- "removeConsole",
3
- "enableInlineScripts",
4
- "enableInlineStyles",
5
- "baseUrl"
6
- ].includes(key);
7
- export {
8
- isOverriddenConfigKey
9
- };
@@ -1,114 +0,0 @@
1
- import { NESTED_ROUTE_SPEC_FILE, MAIN_ENTRY_NAME, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_RENDER_FUNCTION_NAME, SERVER_PLUGIN_BFF, SERVER_PLUGIN_EXPRESS, SERVER_PLUGIN_KOA, SERVER_PLUGIN_SERVER, SERVER_PLUGIN_POLYFILL } from "../universal/constants";
2
- const JS_EXTENSIONS = [
3
- ".js",
4
- ".ts",
5
- ".jsx",
6
- ".tsx"
7
- ];
8
- const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
9
- const ENTRY_NAME_PATTERN = "^[a-zA-Z0-9_-]+$";
10
- const LOADABLE_STATS_FILE = "loadable-stats.json";
11
- const API_DIR = "api";
12
- const DEFAULT_API_PREFIX = "/api";
13
- const SERVER_DIR = "server";
14
- const SHARED_DIR = "shared";
15
- const CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
16
- const CONFIG_FILE_EXTENSIONS = [
17
- ".js",
18
- ".ts",
19
- ".mjs"
20
- ];
21
- const OUTPUT_CONFIG_FILE = "modern.config.json";
22
- const DEFAULT_RUNTIME_CONFIG = "modern.runtime";
23
- const DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
24
- const ROUTE_MANIFEST_FILE = "routes-manifest.json";
25
- const LOADER_ROUTES_DIR = `loader-routes`;
26
- const DEFAULT_DEV_HOST = "0.0.0.0";
27
- const INTERNAL_APP_TOOLS_PLUGINS = {
28
- "@modern-js/app-tools": "@modern-js/app-tools/cli",
29
- "@modern-js/plugin-proxy": "@modern-js/plugin-proxy/cli",
30
- "@modern-js/plugin-ssg": "@modern-js/plugin-ssg/cli",
31
- "@modern-js/plugin-bff": "@modern-js/plugin-bff/cli",
32
- "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
33
- "@modern-js/plugin-express": "@modern-js/plugin-express/cli",
34
- "@modern-js/plugin-koa": "@modern-js/plugin-koa/cli",
35
- "@modern-js/plugin-server": "@modern-js/plugin-server/cli",
36
- "@modern-js/plugin-garfish": "@modern-js/plugin-garfish/cli",
37
- "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
38
- "@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/cli",
39
- // legacy router (inner react-router-dom v5)
40
- "@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
41
- };
42
- const INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
43
- "@modern-js/runtime": "@modern-js/runtime/cli"
44
- };
45
- const INTERNAL_MODULE_TOOLS_PLUGINS = {
46
- "@modern-js/module-tools": "@modern-js/module-tools",
47
- "@modern-js/runtime": "@modern-js/runtime/cli",
48
- "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
49
- "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
50
- // legacy router (inner react-router-dom v5)
51
- "@modern-js/plugin-router-legacy": "@modern-js/plugin-router-legacy/cli"
52
- };
53
- const INTERNAL_MONOREPO_TOOLS_PLUGINS = {
54
- "@modern-js/monorepo-tools": "@modern-js/monorepo-tools/cli"
55
- };
56
- const INTERNAL_DOC_TOOLS_PLUGINS = {
57
- "@modern-js/doc-tools": "@modern-js/doc-tools",
58
- "@modern-js/runtime": "@modern-js/runtime/cli"
59
- };
60
- const INTERNAL_CLI_PLUGINS = {
61
- "@modern-js/app-tools": "@modern-js/app-tools/cli",
62
- "@modern-js/monorepo-tools": "@modern-js/monorepo-tools/cli",
63
- "@modern-js/module-tools": "@modern-js/module-tools",
64
- "@modern-js/doc-tools": "@modern-js/doc-tools",
65
- "@modern-js/runtime": "@modern-js/runtime/cli",
66
- "@modern-js/plugin-state": "@modern-js/plugin-state/cli",
67
- "@modern-js/plugin-proxy": "@modern-js/plugin-proxy/cli",
68
- "@modern-js/plugin-ssg": "@modern-js/plugin-ssg/cli",
69
- "@modern-js/plugin-bff": "@modern-js/plugin-bff/cli",
70
- "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
71
- "@modern-js/plugin-express": "@modern-js/plugin-express/cli",
72
- "@modern-js/plugin-koa": "@modern-js/plugin-koa/cli",
73
- "@modern-js/plugin-server": "@modern-js/plugin-server/cli",
74
- "@modern-js/plugin-swc": "@modern-js/plugin-swc",
75
- "@modern-js/plugin-garfish": "@modern-js/plugin-garfish/cli",
76
- "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
77
- "@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/cli",
78
- // legacy router (inner react-router-dom v5)
79
- "@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
80
- };
81
- export {
82
- API_DIR,
83
- CONFIG_CACHE_DIR,
84
- CONFIG_FILE_EXTENSIONS,
85
- DEFAULT_API_PREFIX,
86
- DEFAULT_DEV_HOST,
87
- DEFAULT_RUNTIME_CONFIG,
88
- DEFAULT_SERVER_CONFIG,
89
- ENTRY_NAME_PATTERN,
90
- INTERNAL_APP_TOOLS_PLUGINS,
91
- INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
92
- INTERNAL_CLI_PLUGINS,
93
- INTERNAL_DOC_TOOLS_PLUGINS,
94
- INTERNAL_MODULE_TOOLS_PLUGINS,
95
- INTERNAL_MONOREPO_TOOLS_PLUGINS,
96
- JS_EXTENSIONS,
97
- LOADABLE_STATS_FILE,
98
- LOADER_ROUTES_DIR,
99
- MAIN_ENTRY_NAME,
100
- NESTED_ROUTE_SPEC_FILE,
101
- OUTPUT_CONFIG_FILE,
102
- ROUTE_MANIFEST_FILE,
103
- ROUTE_SPEC_FILE,
104
- SERVER_BUNDLE_DIRECTORY,
105
- SERVER_DIR,
106
- SERVER_PLUGIN_BFF,
107
- SERVER_PLUGIN_EXPRESS,
108
- SERVER_PLUGIN_KOA,
109
- SERVER_PLUGIN_POLYFILL,
110
- SERVER_PLUGIN_SERVER,
111
- SERVER_RENDER_FUNCTION_NAME,
112
- SERVER_WORKER_BUNDLE_DIRECTORY,
113
- SHARED_DIR
114
- };
@@ -1,14 +0,0 @@
1
- import path from "path";
2
- const ensureAbsolutePath = (base, filePath) => path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath);
3
- const ensureArray = (params) => {
4
- if (Array.isArray(params)) {
5
- return params;
6
- }
7
- return [
8
- params
9
- ];
10
- };
11
- export {
12
- ensureAbsolutePath,
13
- ensureArray
14
- };
@@ -1,18 +0,0 @@
1
- import { fs } from "../compiled";
2
- const findExists = (files) => {
3
- for (const file of files) {
4
- if (fs.existsSync(file) && fs.statSync(file).isFile()) {
5
- return file;
6
- }
7
- }
8
- return false;
9
- };
10
- const emptyDir = async (dir) => {
11
- if (await fs.pathExists(dir)) {
12
- await fs.emptyDir(dir);
13
- }
14
- };
15
- export {
16
- emptyDir,
17
- findExists
18
- };
@@ -1,19 +0,0 @@
1
- import { isPlainObject } from "../is";
2
- const getEntryOptions = (name, isMainEntry, baseOptions, optionsByEntries, packageName) => {
3
- if (optionsByEntries) {
4
- let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
5
- if (optionsByEntry === void 0 && isMainEntry && packageName) {
6
- optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
7
- }
8
- return optionsByEntry !== void 0 ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? {
9
- ...baseOptions,
10
- ...optionsByEntry
11
- } : optionsByEntry : baseOptions;
12
- } else {
13
- return baseOptions;
14
- }
15
- };
16
- const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : void 0;
17
- export {
18
- getEntryOptions
19
- };
@@ -1,96 +0,0 @@
1
- import os from "os";
2
- import path from "path";
3
- import { fs, browserslist, json5 } from "../../compiled";
4
- import { INTERNAL_CLI_PLUGINS } from "../constants";
5
- import { isDepExists } from "../is";
6
- import { canUsePnpm, canUseYarn } from "../package";
7
- const MAX_TIMES = 5;
8
- async function getPackageManager(cwd = process.cwd()) {
9
- let appDirectory = cwd;
10
- let times = 0;
11
- while (os.homedir() !== appDirectory && times < MAX_TIMES) {
12
- times++;
13
- if (fs.existsSync(path.resolve(appDirectory, "pnpm-lock.yaml"))) {
14
- return "pnpm";
15
- }
16
- if (fs.existsSync(path.resolve(appDirectory, "yarn.lock"))) {
17
- return "yarn";
18
- }
19
- if (fs.existsSync(path.resolve(appDirectory, "package-lock.json"))) {
20
- return "npm";
21
- }
22
- appDirectory = path.join(appDirectory, "..");
23
- }
24
- if (await canUsePnpm()) {
25
- return "pnpm";
26
- }
27
- if (await canUseYarn()) {
28
- return "yarn";
29
- }
30
- return "npm";
31
- }
32
- const getCoreJsVersion = (corejsPkgPath) => {
33
- try {
34
- const { version } = fs.readJSONSync(corejsPkgPath);
35
- const [major, minor] = version.split(".");
36
- return `${major}.${minor}`;
37
- } catch (err) {
38
- return "3";
39
- }
40
- };
41
- const getAntdMajorVersion = (appDirectory) => {
42
- try {
43
- const pkgJsonPath = require.resolve("antd/package.json", {
44
- paths: [
45
- appDirectory
46
- ]
47
- });
48
- const { version } = require(pkgJsonPath);
49
- return Number(version.split(".")[0]);
50
- } catch (err) {
51
- return null;
52
- }
53
- };
54
- const defaults = [
55
- "> 0.01%",
56
- "not dead",
57
- "not op_mini all"
58
- ];
59
- const getBrowserslist = (appDirectory) => browserslist.loadConfig({
60
- path: appDirectory
61
- }) || defaults;
62
- function getInternalPlugins(appDirectory, internalPlugins = INTERNAL_CLI_PLUGINS) {
63
- return [
64
- ...Object.keys(internalPlugins).filter((name) => {
65
- const config = internalPlugins[name];
66
- if (typeof config !== "string" && config.forced === true) {
67
- return true;
68
- }
69
- return isDepExists(appDirectory, name);
70
- }).map((name) => {
71
- const config = internalPlugins[name];
72
- if (typeof config !== "string") {
73
- return config.path;
74
- } else {
75
- return config;
76
- }
77
- })
78
- ];
79
- }
80
- const readTsConfig = (root) => {
81
- return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
82
- };
83
- const readTsConfigByFile = (filename) => {
84
- const content = fs.readFileSync(path.resolve(filename), "utf-8");
85
- return json5.parse(content);
86
- };
87
- export {
88
- defaults,
89
- getAntdMajorVersion,
90
- getBrowserslist,
91
- getCoreJsVersion,
92
- getInternalPlugins,
93
- getPackageManager,
94
- readTsConfig,
95
- readTsConfigByFile
96
- };
@@ -1,22 +0,0 @@
1
- import path from "path";
2
- import { CONFIG_FILE_EXTENSIONS } from "../constants";
3
- import { findExists } from "../fs";
4
- const getServerConfig = async (appDirectory, configFile) => {
5
- const configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(appDirectory, `${configFile}${extension}`)));
6
- return configFilePath;
7
- };
8
- const getMeta = (metaName = "modern-js") => {
9
- const meta = metaName.toLowerCase().split("-")[0];
10
- return meta;
11
- };
12
- const getTargetDir = (from, baseDir, targetBaseDir) => {
13
- const relativePath = path.relative(baseDir, from);
14
- return path.resolve(targetBaseDir, relativePath);
15
- };
16
- export * from "./data";
17
- export * from "./config";
18
- export {
19
- getMeta,
20
- getServerConfig,
21
- getTargetDir
22
- };