@modern-js/utils 2.69.7 → 3.0.0-alpha.1

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,50 +0,0 @@
1
- import { MAIN_ENTRY_NAME } from "../constants";
2
- import { isEmpty } from "./type";
3
- const isSSR = (config) => {
4
- const { server } = config;
5
- if (server === null || server === void 0 ? void 0 : server.ssr) {
6
- return true;
7
- }
8
- if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
9
- for (const name of Object.keys(server.ssrByEntries)) {
10
- if (server.ssrByEntries[name]) {
11
- return true;
12
- }
13
- }
14
- }
15
- return false;
16
- };
17
- const isUseSSRBundle = (config) => {
18
- const { output } = config;
19
- if (output === null || output === void 0 ? void 0 : output.ssg) {
20
- return true;
21
- }
22
- return isSSR(config);
23
- };
24
- const isUseRsc = (config) => {
25
- var _config_server;
26
- return config === null || config === void 0 ? void 0 : (_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.rsc;
27
- };
28
- const isServiceWorker = (config) => {
29
- var _deploy_worker;
30
- const { output, deploy } = config;
31
- 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))) {
32
- return true;
33
- }
34
- return false;
35
- };
36
- const isSSGEntry = (config, entryName, entrypoints) => {
37
- var _config_source;
38
- const ssgConfig = config.output.ssg;
39
- const useSSG = isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[0]) === "function" || Boolean(ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[entryName]);
40
- return useSSG;
41
- };
42
- const isSingleEntry = (entrypoints, mainEntryName = MAIN_ENTRY_NAME) => entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
43
- export {
44
- isSSGEntry,
45
- isSSR,
46
- isServiceWorker,
47
- isSingleEntry,
48
- isUseRsc,
49
- isUseSSRBundle
50
- };
@@ -1,12 +0,0 @@
1
- const getNodeEnv = () => process.env.NODE_ENV || "development";
2
- const isDev = () => getNodeEnv() === "development";
3
- const isProd = () => getNodeEnv() === "production";
4
- const isTest = () => getNodeEnv() === "test";
5
- const isBrowser = () => typeof window !== "undefined";
6
- export {
7
- getNodeEnv,
8
- isBrowser,
9
- isDev,
10
- isProd,
11
- isTest
12
- };
@@ -1,105 +0,0 @@
1
- import path from "path";
2
- import pkgUp from "../../../compiled/pkg-up";
3
- import { fs, minimist, semver } from "../../compiled";
4
- import { getArgv } from "../commands";
5
- import { createDebugger } from "../common";
6
- import { ensureArray } from "../ensure";
7
- const debug = createDebugger("judge-depExists");
8
- const isDepExists = (appDirectory, name) => {
9
- const pkgPath = path.resolve(appDirectory, "./package.json");
10
- if (!fs.existsSync(pkgPath)) {
11
- debug(`can't find package.json under: %s`, appDirectory);
12
- return false;
13
- }
14
- const json = require(pkgPath);
15
- const { dependencies = {}, devDependencies = {} } = json;
16
- return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
17
- };
18
- const isPackageInstalled = (name, resolvePaths) => {
19
- try {
20
- require.resolve(name, {
21
- paths: ensureArray(resolvePaths)
22
- });
23
- return true;
24
- } catch (err) {
25
- return false;
26
- }
27
- };
28
- const isApiOnly = async (appDirectory, entryDir, apiDir) => {
29
- const existApi = await fs.pathExists(apiDir !== null && apiDir !== void 0 ? apiDir : path.join(appDirectory, "api"));
30
- const existSrc = await fs.pathExists(path.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src"));
31
- const options = minimist(getArgv());
32
- if (options["api-only"]) {
33
- return true;
34
- }
35
- return existApi && !existSrc;
36
- };
37
- const isWebOnly = async () => {
38
- const options = minimist(getArgv());
39
- return Boolean(options["web-only"]);
40
- };
41
- const isVersionBeyond17 = (version) => {
42
- return semver.gte(semver.minVersion(version), "17.0.0");
43
- };
44
- const getReactVersion = (cwd) => {
45
- const pkgPath = pkgUp.sync({
46
- cwd
47
- });
48
- if (!pkgPath) {
49
- return false;
50
- }
51
- const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
52
- const deps = {
53
- ...pkgInfo.devDependencies,
54
- ...pkgInfo.dependencies
55
- };
56
- if (typeof deps.react !== "string") {
57
- return false;
58
- }
59
- try {
60
- const reactPath = require.resolve("react/package.json", {
61
- paths: [
62
- cwd
63
- ]
64
- });
65
- const reactVersion = JSON.parse(fs.readFileSync(reactPath, "utf8")).version;
66
- return reactVersion;
67
- } catch (error) {
68
- console.error("Failed to resolve React version:", error);
69
- return false;
70
- }
71
- };
72
- const isBeyondReact17 = (cwd) => {
73
- const reactVersion = getReactVersion(cwd);
74
- if (!reactVersion) {
75
- return false;
76
- }
77
- return isVersionBeyond17(reactVersion);
78
- };
79
- const isSupportAutomaticJsx = (cwd) => {
80
- const reactVersion = getReactVersion(cwd);
81
- if (!reactVersion) {
82
- return false;
83
- }
84
- return semver.satisfies(semver.minVersion(reactVersion), ">=16.14.0");
85
- };
86
- const isReact18 = (cwd = process.cwd()) => {
87
- const reactVersion = getReactVersion(cwd);
88
- if (!reactVersion) {
89
- return false;
90
- }
91
- return semver.gte(semver.minVersion(reactVersion), "18.0.0");
92
- };
93
- const isTypescript = (root) => fs.existsSync(path.resolve(root, "./tsconfig.json"));
94
- export {
95
- getReactVersion,
96
- isApiOnly,
97
- isBeyondReact17,
98
- isDepExists,
99
- isPackageInstalled,
100
- isReact18,
101
- isSupportAutomaticJsx,
102
- isTypescript,
103
- isVersionBeyond17,
104
- isWebOnly
105
- };
@@ -1,36 +0,0 @@
1
- function isString(str) {
2
- return typeof str === "string";
3
- }
4
- function isUndefined(obj) {
5
- return typeof obj === "undefined";
6
- }
7
- function isArray(obj) {
8
- return Array.isArray(obj);
9
- }
10
- function isFunction(func) {
11
- return typeof func === "function";
12
- }
13
- function isObject(obj) {
14
- return obj !== null && typeof obj === "object";
15
- }
16
- function isPlainObject(obj) {
17
- return isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]";
18
- }
19
- function isPromise(obj) {
20
- return Boolean(obj) && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
21
- }
22
- function isRegExp(obj) {
23
- return Object.prototype.toString.call(obj) === "[object RegExp]";
24
- }
25
- const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
26
- export {
27
- isArray,
28
- isEmpty,
29
- isFunction,
30
- isObject,
31
- isPlainObject,
32
- isPromise,
33
- isRegExp,
34
- isString,
35
- isUndefined
36
- };
@@ -1,5 +0,0 @@
1
- import { logger, createLogger } from "rslog";
2
- export {
3
- createLogger,
4
- logger
5
- };
@@ -1,67 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { glob, yaml } from "../compiled";
4
- const PACKAGE_MAX_DEPTH = 5;
5
- const WORKSPACE_FILES = {
6
- YARN: "package.json",
7
- PNPM: "pnpm-workspace.yaml",
8
- LERNA: "lerna.json"
9
- };
10
- const isLerna = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.LERNA));
11
- const isYarnWorkspaces = (root) => {
12
- var _json_workspaces;
13
- const pkg = path.join(root, WORKSPACE_FILES.YARN);
14
- if (!fs.existsSync(pkg)) {
15
- return false;
16
- }
17
- const json = JSON.parse(fs.readFileSync(pkg, "utf8"));
18
- return Boolean((_json_workspaces = json.workspaces) === null || _json_workspaces === void 0 ? void 0 : _json_workspaces.packages);
19
- };
20
- const isPnpmWorkspaces = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.PNPM));
21
- const isMonorepo = (root) => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
22
- const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
23
- let inMonorepo = false;
24
- let monorepoRoot = appDirectory;
25
- for (let depth = 0; depth < maxDepth; depth++) {
26
- if (isMonorepo(appDirectory)) {
27
- inMonorepo = true;
28
- break;
29
- }
30
- monorepoRoot = path.dirname(appDirectory);
31
- }
32
- return inMonorepo ? monorepoRoot : void 0;
33
- };
34
- const getMonorepoPackages = (root) => {
35
- let packages = [];
36
- if (isYarnWorkspaces(root)) {
37
- const json = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
38
- ({ packages } = json.workspaces);
39
- } else if (isLerna(root)) {
40
- const json = JSON.parse(fs.readFileSync(path.resolve(root, "lerna.json"), "utf8"));
41
- ({ packages } = json);
42
- } else {
43
- ({ packages } = yaml.load(fs.readFileSync(path.join(root, WORKSPACE_FILES.PNPM), "utf8")));
44
- }
45
- if (packages) {
46
- return packages.map((name) => (
47
- // The trailing / ensures only dirs are picked up
48
- glob.sync(path.join(root, `${name}/`), {
49
- ignore: [
50
- "**/node_modules/**"
51
- ]
52
- })
53
- )).reduce((acc, val) => acc.concat(val), []).filter((filepath) => fs.existsSync(path.resolve(filepath, "package.json"))).map((filepath) => ({
54
- path: filepath,
55
- name: JSON.parse(fs.readFileSync(path.resolve(filepath, "package.json"), "utf8")).name
56
- }));
57
- }
58
- return [];
59
- };
60
- export {
61
- findMonorepoRoot,
62
- getMonorepoPackages,
63
- isLerna,
64
- isMonorepo,
65
- isPnpmWorkspaces,
66
- isYarnWorkspaces
67
- };
@@ -1,66 +0,0 @@
1
- import { execa } from "../compiled";
2
- async function getPnpmVersion() {
3
- const { stdout } = await execa("pnpm", [
4
- "--version"
5
- ]);
6
- return stdout;
7
- }
8
- async function canUseNpm() {
9
- try {
10
- await execa("npm", [
11
- "--version"
12
- ], {
13
- env: process.env
14
- });
15
- return true;
16
- } catch (e) {
17
- return false;
18
- }
19
- }
20
- async function canUseYarn() {
21
- try {
22
- await execa("yarn", [
23
- "--version"
24
- ], {
25
- env: process.env
26
- });
27
- return true;
28
- } catch (e) {
29
- return false;
30
- }
31
- }
32
- async function canUsePnpm() {
33
- try {
34
- await execa("pnpm", [
35
- "--version"
36
- ], {
37
- env: process.env
38
- });
39
- return true;
40
- } catch (e) {
41
- return false;
42
- }
43
- }
44
- function removeModuleSyncFromExports(exports) {
45
- if (typeof exports !== "object" || exports === null) {
46
- return exports;
47
- }
48
- if (Array.isArray(exports)) {
49
- return exports.map(removeModuleSyncFromExports);
50
- }
51
- const result = {};
52
- for (const [key, value] of Object.entries(exports)) {
53
- if (key === "module-sync") {
54
- continue;
55
- }
56
- result[key] = removeModuleSyncFromExports(value);
57
- }
58
- return result;
59
- }
60
- export {
61
- canUseNpm,
62
- canUsePnpm,
63
- canUseYarn,
64
- getPnpmVersion,
65
- removeModuleSyncFromExports
66
- };
@@ -1,48 +0,0 @@
1
- import fs from "fs";
2
- import os from "os";
3
- import path from "path";
4
- import { nanoid, upath } from "../compiled";
5
- const isPathString = (test) => path.posix.basename(test) !== test || path.win32.basename(test) !== test;
6
- const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
7
- const normalizeOutputPath = (s) => s.replace(/\\/g, "\\\\");
8
- const normalizeToPosixPath = (p) => upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
9
- const getTemplatePath = (prefix) => {
10
- const tmpRoot = fs.realpathSync(os.tmpdir());
11
- const parts = [
12
- tmpRoot
13
- ];
14
- prefix && parts.push(prefix);
15
- parts.push(nanoid());
16
- return path.resolve(...parts);
17
- };
18
- function getRealTemporaryDirectory() {
19
- let ret = null;
20
- try {
21
- ret = os.tmpdir();
22
- ret = fs.realpathSync(ret);
23
- } catch {
24
- }
25
- return ret;
26
- }
27
- function splitPathString(str) {
28
- return str.split(/[\\/]/);
29
- }
30
- const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
31
- const removeTailSlash = (s) => s.replace(/\/+$/, "");
32
- const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
33
- function formatImportPath(str) {
34
- return str.replace(/\\/g, "/");
35
- }
36
- export {
37
- formatImportPath,
38
- getRealTemporaryDirectory,
39
- getTemplatePath,
40
- isPathString,
41
- isRelativePath,
42
- normalizeOutputPath,
43
- normalizeToPosixPath,
44
- removeLeadingSlash,
45
- removeSlash,
46
- removeTailSlash,
47
- splitPathString
48
- };
@@ -1,48 +0,0 @@
1
- import net from "net";
2
- import { chalk } from "../compiled";
3
- import { logger } from "./logger";
4
- const getPort = async (expectPort, { tryLimits = 20, strictPort = false, slient = false } = {}) => {
5
- let port = expectPort;
6
- if (typeof port === "string") {
7
- port = parseInt(port, 10);
8
- }
9
- if (strictPort) {
10
- tryLimits = 1;
11
- }
12
- const original = port;
13
- let found = false;
14
- let attempts = 0;
15
- while (!found && attempts <= tryLimits) {
16
- try {
17
- await new Promise((resolve, reject) => {
18
- const server = net.createServer();
19
- server.unref();
20
- server.on("error", reject);
21
- server.listen({
22
- port,
23
- host: "0.0.0.0"
24
- }, () => {
25
- found = true;
26
- server.close(resolve);
27
- });
28
- });
29
- } catch (e) {
30
- if (e.code !== "EADDRINUSE") {
31
- throw e;
32
- }
33
- port++;
34
- attempts++;
35
- }
36
- }
37
- if (port !== original) {
38
- if (strictPort) {
39
- throw new Error(`Port "${original}" is occupied, please choose another one.`);
40
- } else if (!slient) {
41
- logger.info(`Port ${original} is in use. ${chalk.yellow(`using port ${port}.`)}`);
42
- }
43
- }
44
- return port;
45
- };
46
- export {
47
- getPort
48
- };
@@ -1,90 +0,0 @@
1
- import { isIPv6 } from "net";
2
- import os from "os";
3
- import { chalk } from "../compiled";
4
- import { DEFAULT_DEV_HOST } from "./constants";
5
- import { isDev, isSingleEntry } from "./is";
6
- const normalizeUrl = (url) => url.replace(/([^:]\/)\/+/g, "$1");
7
- const getIpv4Interfaces = () => {
8
- const interfaces = os.networkInterfaces();
9
- const ipv4Interfaces = [];
10
- Object.keys(interfaces).forEach((key) => {
11
- interfaces[key].forEach((detail) => {
12
- const familyV4Value = typeof detail.family === "string" ? "IPv4" : 4;
13
- if (detail.family === familyV4Value) {
14
- ipv4Interfaces.push(detail);
15
- }
16
- });
17
- });
18
- return ipv4Interfaces;
19
- };
20
- const getHostInUrl = (host) => {
21
- if (isIPv6(host)) {
22
- return host === "::" ? "[::1]" : `[${host}]`;
23
- }
24
- return host;
25
- };
26
- const getAddressUrls = (protocol = "http", port, host) => {
27
- const LOCAL_LABEL = "Local: ";
28
- const NETWORK_LABEL = "Network: ";
29
- const isLocalhost = (url) => url === null || url === void 0 ? void 0 : url.includes("localhost");
30
- if (host && host !== DEFAULT_DEV_HOST) {
31
- return [
32
- {
33
- label: isLocalhost(host) ? LOCAL_LABEL : NETWORK_LABEL,
34
- url: `${protocol}://${getHostInUrl(host)}:${port}`
35
- }
36
- ];
37
- }
38
- const ipv4Interfaces = getIpv4Interfaces();
39
- return ipv4Interfaces.reduce((memo, detail) => {
40
- if (isLocalhost(detail.address) || detail.internal) {
41
- memo.push({
42
- label: LOCAL_LABEL,
43
- url: `${protocol}://localhost:${port}`
44
- });
45
- } else {
46
- memo.push({
47
- label: NETWORK_LABEL,
48
- url: `${protocol}://${detail.address}:${port}`
49
- });
50
- }
51
- return memo;
52
- }, []);
53
- };
54
- const prettyInstructions = (appContext, config) => {
55
- var _config_dev, _config_tools_devServer, _config_tools, _config_dev1, _config_source, _config_dev2;
56
- const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
57
- const isHttps = isDev() && ((config === null || config === void 0 ? void 0 : (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.https) || (config === null || config === void 0 ? void 0 : (_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : (_config_tools_devServer = _config_tools.devServer) === null || _config_tools_devServer === void 0 ? void 0 : _config_tools_devServer.https));
58
- const urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev1 = config.dev) === null || _config_dev1 === void 0 ? void 0 : _config_dev1.host);
59
- const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
60
- let message = "\n";
61
- if (isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) || apiOnly) {
62
- message += urls.map(({ label, url }) => ` ${chalk.bold(`> ${label.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}
63
- `).join("");
64
- } else {
65
- const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
66
- urls.forEach(({ label, url }) => {
67
- message += ` ${chalk.bold(`> ${label}`)}${routes.length === 0 ? chalk.cyanBright(url) : ""}
68
- `;
69
- routes.forEach(({ entryName, urlPath, isSSR }) => {
70
- if (!checkedEntries.includes(entryName)) {
71
- return;
72
- }
73
- message += ` ${chalk.yellowBright(isSSR ? "λ" : "○")} ${chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}
74
- `;
75
- });
76
- });
77
- message += "\n";
78
- message += chalk.cyanBright(" λ (Server) server-side renders at runtime\n");
79
- message += chalk.cyanBright(" ○ (Static) client-side renders as static HTML\n");
80
- }
81
- if ((_config_dev2 = config.dev) === null || _config_dev2 === void 0 ? void 0 : _config_dev2.cliShortcuts) {
82
- message += ` ${chalk.dim("> press")} ${chalk.bold("h + enter")} ${chalk.dim("to show shortcuts")}
83
- `;
84
- }
85
- return message;
86
- };
87
- export {
88
- getAddressUrls,
89
- prettyInstructions
90
- };
@@ -1,111 +0,0 @@
1
- const import_meta = {};
2
- import { isAbsolute } from "node:path";
3
- import { pathToFileURL } from "node:url";
4
- import { findExists } from "./fs";
5
- async function compatibleRequire(path, interop = true) {
6
- if (path.endsWith(".json")) {
7
- return require(path);
8
- }
9
- let requiredModule;
10
- try {
11
- requiredModule = require(path);
12
- } catch (err) {
13
- if (err.code === "ERR_REQUIRE_ESM") {
14
- const modulePath = isAbsolute(path) ? pathToFileURL(path).href : path;
15
- if (process.env.NODE_ENV === "development") {
16
- const timestamp = Date.now();
17
- requiredModule = await import(`${modulePath}?t=${timestamp}`);
18
- } else {
19
- requiredModule = await import(modulePath);
20
- }
21
- return interop ? requiredModule.default : requiredModule;
22
- } else {
23
- throw err;
24
- }
25
- }
26
- return interop && (requiredModule === null || requiredModule === void 0 ? void 0 : requiredModule.__esModule) ? requiredModule.default : requiredModule;
27
- }
28
- async function loadFromProject(moduleName, appDir) {
29
- let requiredModule;
30
- const paths = [
31
- appDir,
32
- process.cwd()
33
- ];
34
- try {
35
- if (typeof require !== "undefined") {
36
- const modulePath = require.resolve(moduleName, {
37
- paths
38
- });
39
- requiredModule = require(modulePath);
40
- } else {
41
- const { createRequire } = await import("node:module");
42
- const require1 = createRequire(import_meta.url);
43
- const modulePath = require1.resolve(moduleName, {
44
- paths
45
- });
46
- const moduleUrl = pathToFileURL(modulePath).href;
47
- requiredModule = await import(moduleUrl);
48
- }
49
- return requiredModule.default || requiredModule;
50
- } catch (error) {
51
- if (error.code === "MODULE_NOT_FOUND") {
52
- throw new Error(`Cannot find module ${moduleName}.`);
53
- }
54
- throw error;
55
- }
56
- }
57
- const dynamicImport = new Function("modulePath", "return import(modulePath)");
58
- const requireExistModule = async (filename, opt) => {
59
- const final = {
60
- extensions: [
61
- ".ts",
62
- ".js"
63
- ],
64
- interop: true,
65
- ...opt
66
- };
67
- const exist = findExists(final.extensions.map((ext) => `${filename}${ext}`));
68
- if (!exist) {
69
- return null;
70
- }
71
- return compatibleRequire(exist, final.interop);
72
- };
73
- const cleanRequireCache = (filelist) => {
74
- filelist.forEach((filepath) => {
75
- delete require.cache[filepath];
76
- });
77
- };
78
- function deleteRequireCache(path) {
79
- if (require.cache[path]) {
80
- delete require.cache[path];
81
- }
82
- if (module.children) {
83
- module.children = module.children.filter((item) => item.filename !== path);
84
- }
85
- }
86
- const tryResolve = (name, resolvePath) => {
87
- let filePath = "";
88
- try {
89
- filePath = require.resolve(name, {
90
- paths: [
91
- resolvePath
92
- ]
93
- });
94
- delete require.cache[filePath];
95
- } catch (err) {
96
- if (err.code === "MODULE_NOT_FOUND") {
97
- throw new Error(`Can not find module ${name}.`);
98
- }
99
- throw err;
100
- }
101
- return filePath;
102
- };
103
- export {
104
- cleanRequireCache,
105
- compatibleRequire,
106
- deleteRequireCache,
107
- dynamicImport,
108
- loadFromProject,
109
- requireExistModule,
110
- tryResolve
111
- };