@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
@@ -0,0 +1,5 @@
1
+ const isOverriddenConfigKey = (key)=>[
2
+ 'removeConsole',
3
+ 'baseUrl'
4
+ ].includes(key);
5
+ export { isOverriddenConfigKey };
@@ -0,0 +1,29 @@
1
+ import { DEFAULT_ENTRY_NAME, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_PLUGIN_BFF, SERVER_PLUGIN_POLYFILL, SERVER_RENDER_FUNCTION_NAME } from "../universal/constants.mjs";
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 ROUTE_MANIFEST_FILE = 'routes-manifest.json';
24
+ const LOADER_ROUTES_DIR = "loader-routes";
25
+ const DEFAULT_DEV_HOST = '0.0.0.0';
26
+ const INTERNAL_RUNTIME_PLUGINS = {
27
+ '@modern-js/runtime': '@modern-js/runtime/cli'
28
+ };
29
+ export { API_DIR, CONFIG_CACHE_DIR, CONFIG_FILE_EXTENSIONS, DEFAULT_API_PREFIX, DEFAULT_DEV_HOST, DEFAULT_ENTRY_NAME, DEFAULT_RUNTIME_CONFIG, ENTRY_NAME_PATTERN, INTERNAL_RUNTIME_PLUGINS, JS_EXTENSIONS, LOADABLE_STATS_FILE, LOADER_ROUTES_DIR, MAIN_ENTRY_NAME, NESTED_ROUTE_SPEC_FILE, OUTPUT_CONFIG_FILE, ROUTE_MANIFEST_FILE, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_DIR, SERVER_PLUGIN_BFF, SERVER_PLUGIN_POLYFILL, SERVER_RENDER_FUNCTION_NAME, SERVER_WORKER_BUNDLE_DIRECTORY, SHARED_DIR };
@@ -0,0 +1,9 @@
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)) return params;
5
+ return [
6
+ params
7
+ ];
8
+ };
9
+ export { ensureAbsolutePath, ensureArray };
@@ -0,0 +1,9 @@
1
+ import { fs } from "../compiled.mjs";
2
+ const findExists = (files)=>{
3
+ for (const file of files)if (fs.existsSync(file) && fs.statSync(file).isFile()) return file;
4
+ return false;
5
+ };
6
+ const emptyDir = async (dir)=>{
7
+ if (await fs.pathExists(dir)) await fs.emptyDir(dir);
8
+ };
9
+ export { emptyDir, findExists };
@@ -0,0 +1,14 @@
1
+ import { isPlainObject } from "../is/index.mjs";
2
+ const getEntryOptions = (name, isMainEntry, baseOptions, optionsByEntries, packageName)=>{
3
+ if (!optionsByEntries) return baseOptions;
4
+ {
5
+ let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
6
+ if (void 0 === optionsByEntry && isMainEntry && packageName) optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
7
+ return void 0 !== optionsByEntry ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? {
8
+ ...baseOptions,
9
+ ...optionsByEntry
10
+ } : optionsByEntry : baseOptions;
11
+ }
12
+ };
13
+ const getOptionsByEntryName = (name, optionsByEntries)=>optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : void 0;
14
+ export { getEntryOptions };
@@ -0,0 +1,57 @@
1
+ import os from "os";
2
+ import path from "path";
3
+ import { browserslist, fs, json5 } from "../../compiled.mjs";
4
+ import { isDepExists } from "../is/index.mjs";
5
+ import { canUsePnpm, canUseYarn } from "../package.mjs";
6
+ const MAX_TIMES = 5;
7
+ async function getPackageManager(cwd = process.cwd()) {
8
+ let appDirectory = cwd;
9
+ let times = 0;
10
+ while(os.homedir() !== appDirectory && times < MAX_TIMES){
11
+ times++;
12
+ if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) return 'pnpm';
13
+ if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) return 'yarn';
14
+ if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) return 'npm';
15
+ appDirectory = path.join(appDirectory, '..');
16
+ }
17
+ if (await canUsePnpm()) return 'pnpm';
18
+ if (await canUseYarn()) return 'yarn';
19
+ return 'npm';
20
+ }
21
+ const getCoreJsVersion = (corejsPkgPath)=>{
22
+ try {
23
+ const { version } = fs.readJSONSync(corejsPkgPath);
24
+ const [major, minor] = version.split('.');
25
+ return `${major}.${minor}`;
26
+ } catch (err) {
27
+ return '3';
28
+ }
29
+ };
30
+ const defaults = [
31
+ 'chrome >= 87',
32
+ 'edge >= 88',
33
+ 'firefox >= 78',
34
+ 'safari >= 14'
35
+ ];
36
+ const getBrowserslist = (appDirectory)=>browserslist.loadConfig({
37
+ path: appDirectory
38
+ }) || defaults;
39
+ function getInternalPlugins(appDirectory, internalPlugins = {}) {
40
+ return [
41
+ ...Object.keys(internalPlugins).filter((name)=>{
42
+ const config = internalPlugins[name];
43
+ if ('string' != typeof config && true === config.forced) return true;
44
+ return isDepExists(appDirectory, name);
45
+ }).map((name)=>{
46
+ const config = internalPlugins[name];
47
+ if ('string' != typeof config) return config.path;
48
+ return config;
49
+ })
50
+ ];
51
+ }
52
+ const readTsConfig = (root)=>readTsConfigByFile(path.resolve(root, './tsconfig.json'));
53
+ const readTsConfigByFile = (filename)=>{
54
+ const content = fs.readFileSync(path.resolve(filename), 'utf-8');
55
+ return json5.parse(content);
56
+ };
57
+ export { defaults, getBrowserslist, getCoreJsVersion, getInternalPlugins, getPackageManager, readTsConfig, readTsConfigByFile };
@@ -0,0 +1,18 @@
1
+ import path from "path";
2
+ import { CONFIG_FILE_EXTENSIONS } from "../constants.mjs";
3
+ import { findExists } from "../fs.mjs";
4
+ export * from "./data.mjs";
5
+ export * from "./config.mjs";
6
+ const getServerConfig = async (appDirectory, configFile)=>{
7
+ const configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map((extension)=>path.resolve(appDirectory, `${configFile}${extension}`)));
8
+ return configFilePath;
9
+ };
10
+ const getMeta = (metaName = 'modern-js')=>{
11
+ const meta = metaName.toLowerCase().split('-')[0];
12
+ return meta;
13
+ };
14
+ const getTargetDir = (from, baseDir, targetBaseDir)=>{
15
+ const relativePath = path.relative(baseDir, from);
16
+ return path.resolve(targetBaseDir, relativePath);
17
+ };
18
+ export { getMeta, getServerConfig, getTargetDir };
@@ -0,0 +1,22 @@
1
+ export * from "./constants.mjs";
2
+ export * from "./get/index.mjs";
3
+ export * from "./is/index.mjs";
4
+ export * from "./alias.mjs";
5
+ export * from "./applyOptionsChain.mjs";
6
+ export * from "./babel.mjs";
7
+ export * from "./commands.mjs";
8
+ export * from "./common.mjs";
9
+ export * from "./ensure.mjs";
10
+ export * from "./fs.mjs";
11
+ export * from "./logger.mjs";
12
+ export * from "./monorepo.mjs";
13
+ export * from "./package.mjs";
14
+ export * from "./path.mjs";
15
+ export * from "./port.mjs";
16
+ export * from "./prettyInstructions.mjs";
17
+ export * from "./require.mjs";
18
+ export * from "./runtimeExports.mjs";
19
+ export * from "./watch.mjs";
20
+ export * from "./config.mjs";
21
+ export * from "./version.mjs";
22
+ export * from "./route.mjs";
@@ -0,0 +1,34 @@
1
+ import { MAIN_ENTRY_NAME } from "../constants.mjs";
2
+ import { isEmpty } from "./type.mjs";
3
+ const isSSR = (config)=>{
4
+ const { server } = config;
5
+ if (server?.ssr) return true;
6
+ if (server?.ssrByEntries && !isEmpty(server.ssrByEntries)) {
7
+ for (const name of Object.keys(server.ssrByEntries))if (server.ssrByEntries[name]) return true;
8
+ }
9
+ return false;
10
+ };
11
+ const isUseSSRBundle = (config)=>{
12
+ const { output } = config;
13
+ if (output?.ssg || output?.ssgByEntries && Object.keys(output?.ssgByEntries).length > 0) return true;
14
+ return isSSR(config);
15
+ };
16
+ const isUseRsc = (config)=>config?.server?.rsc;
17
+ const isServiceWorker = (config)=>{
18
+ const { output, deploy } = config;
19
+ if (deploy?.worker?.ssr && (output?.ssg || isSSR(config))) return true;
20
+ return false;
21
+ };
22
+ const isSSGEntry = (config, entryName, entrypoints)=>{
23
+ const { output, source } = config;
24
+ const single = isSingleEntry(entrypoints, source?.mainEntryName);
25
+ if (single) {
26
+ const byEntries = output?.ssgByEntries;
27
+ return Boolean(output?.ssg) || byEntries && !isEmpty(byEntries);
28
+ }
29
+ const byEntries = output?.ssgByEntries;
30
+ if (!byEntries || isEmpty(byEntries)) return false;
31
+ return Boolean(byEntries[entryName]);
32
+ };
33
+ const isSingleEntry = (entrypoints, mainEntryName = MAIN_ENTRY_NAME)=>1 === entrypoints.length && entrypoints[0].entryName === mainEntryName;
34
+ export { isSSGEntry, isSSR, isServiceWorker, isSingleEntry, isUseRsc, isUseSSRBundle };
@@ -0,0 +1,6 @@
1
+ const getNodeEnv = ()=>process.env.NODE_ENV || 'development';
2
+ const isDev = ()=>'development' === getNodeEnv();
3
+ const isProd = ()=>'production' === getNodeEnv();
4
+ const isTest = ()=>'test' === getNodeEnv();
5
+ const isBrowser = ()=>"u" > typeof window;
6
+ export { getNodeEnv, isBrowser, isDev, isProd, isTest };
@@ -0,0 +1,4 @@
1
+ export * from "./env.mjs";
2
+ export * from "./type.mjs";
3
+ export * from "./config.mjs";
4
+ export * from "./project.mjs";
@@ -0,0 +1,104 @@
1
+ import path from "path";
2
+ import { fs, minimist, semver } from "../../compiled.mjs";
3
+ import { getArgv } from "../commands.mjs";
4
+ import { createDebugger } from "../common.mjs";
5
+ import { ensureArray } from "../ensure.mjs";
6
+ import { createRequire as __rspack_createRequire } from "node:module";
7
+ const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
8
+ var __webpack_require__ = {};
9
+ (()=>{
10
+ __webpack_require__.n = (module)=>{
11
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
12
+ __webpack_require__.d(getter, {
13
+ a: getter
14
+ });
15
+ return getter;
16
+ };
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.d = (exports, definition)=>{
20
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
21
+ enumerable: true,
22
+ get: definition[key]
23
+ });
24
+ };
25
+ })();
26
+ (()=>{
27
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
28
+ })();
29
+ const index_js_namespaceObject = __rspack_createRequire_require("../../../compiled/pkg-up/index.js");
30
+ var index_js_default = /*#__PURE__*/ __webpack_require__.n(index_js_namespaceObject);
31
+ const debug = createDebugger('judge-depExists');
32
+ const isDepExists = (appDirectory, name)=>{
33
+ const pkgPath = path.resolve(appDirectory, './package.json');
34
+ if (!fs.existsSync(pkgPath)) {
35
+ debug("can't find package.json under: %s", appDirectory);
36
+ return false;
37
+ }
38
+ const json = require(pkgPath);
39
+ const { dependencies = {}, devDependencies = {} } = json;
40
+ return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
41
+ };
42
+ const isPackageInstalled = (name, resolvePaths)=>{
43
+ try {
44
+ require.resolve(name, {
45
+ paths: ensureArray(resolvePaths)
46
+ });
47
+ return true;
48
+ } catch (err) {
49
+ return false;
50
+ }
51
+ };
52
+ const isApiOnly = async (appDirectory, entryDir, apiDir)=>{
53
+ const existApi = await fs.pathExists(apiDir ?? path.join(appDirectory, 'api'));
54
+ const existSrc = await fs.pathExists(path.join(appDirectory, entryDir ?? 'src'));
55
+ const options = minimist(getArgv());
56
+ if (options['api-only']) return true;
57
+ return existApi && !existSrc;
58
+ };
59
+ const isWebOnly = async ()=>{
60
+ const options = minimist(getArgv());
61
+ return Boolean(options['web-only']);
62
+ };
63
+ const isVersionBeyond17 = (version)=>semver.gte(semver.minVersion(version), '17.0.0');
64
+ const getReactVersion = (cwd)=>{
65
+ const pkgPath = index_js_default().sync({
66
+ cwd
67
+ });
68
+ if (!pkgPath) return false;
69
+ const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
70
+ const deps = {
71
+ ...pkgInfo.devDependencies,
72
+ ...pkgInfo.dependencies
73
+ };
74
+ if ('string' != typeof deps.react) return false;
75
+ try {
76
+ const reactPath = require.resolve('react/package.json', {
77
+ paths: [
78
+ cwd
79
+ ]
80
+ });
81
+ const reactVersion = JSON.parse(fs.readFileSync(reactPath, 'utf8')).version;
82
+ return reactVersion;
83
+ } catch (error) {
84
+ console.error('Failed to resolve React version:', error);
85
+ return false;
86
+ }
87
+ };
88
+ const isBeyondReact17 = (cwd)=>{
89
+ const reactVersion = getReactVersion(cwd);
90
+ if (!reactVersion) return false;
91
+ return isVersionBeyond17(reactVersion);
92
+ };
93
+ const isSupportAutomaticJsx = (cwd)=>{
94
+ const reactVersion = getReactVersion(cwd);
95
+ if (!reactVersion) return false;
96
+ return semver.satisfies(semver.minVersion(reactVersion), '>=16.14.0');
97
+ };
98
+ const isReact18 = (cwd = process.cwd())=>{
99
+ const reactVersion = getReactVersion(cwd);
100
+ if (!reactVersion) return false;
101
+ return semver.gte(semver.minVersion(reactVersion), '18.0.0');
102
+ };
103
+ const isTypescript = (root)=>fs.existsSync(path.resolve(root, './tsconfig.json'));
104
+ export { getReactVersion, isApiOnly, isBeyondReact17, isDepExists, isPackageInstalled, isReact18, isSupportAutomaticJsx, isTypescript, isVersionBeyond17, isWebOnly };
@@ -0,0 +1,26 @@
1
+ function isString(str) {
2
+ return 'string' == typeof str;
3
+ }
4
+ function isUndefined(obj) {
5
+ return void 0 === obj;
6
+ }
7
+ function isArray(obj) {
8
+ return Array.isArray(obj);
9
+ }
10
+ function isFunction(func) {
11
+ return 'function' == typeof func;
12
+ }
13
+ function isObject(obj) {
14
+ return null !== obj && 'object' == typeof obj;
15
+ }
16
+ function isPlainObject(obj) {
17
+ return isObject(obj) && '[object Object]' === Object.prototype.toString.call(obj);
18
+ }
19
+ function isPromise(obj) {
20
+ return Boolean(obj) && ('object' == typeof obj || 'function' == typeof obj) && 'function' == typeof obj.then;
21
+ }
22
+ function isRegExp(obj) {
23
+ return '[object RegExp]' === Object.prototype.toString.call(obj);
24
+ }
25
+ const isEmpty = (o)=>0 === Object.entries(o).length && o.constructor === Object;
26
+ export { isArray, isEmpty, isFunction, isObject, isPlainObject, isPromise, isRegExp, isString, isUndefined };
@@ -0,0 +1,2 @@
1
+ import { createLogger, logger } from "rslog";
2
+ export { createLogger, logger };
@@ -0,0 +1,50 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { glob, yaml } from "../compiled.mjs";
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
+ const pkg = path.join(root, WORKSPACE_FILES.YARN);
13
+ if (!fs.existsSync(pkg)) return false;
14
+ const json = JSON.parse(fs.readFileSync(pkg, 'utf8'));
15
+ return Boolean(json.workspaces?.packages);
16
+ };
17
+ const isPnpmWorkspaces = (root)=>fs.existsSync(path.join(root, WORKSPACE_FILES.PNPM));
18
+ const isMonorepo = (root)=>isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
19
+ const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH)=>{
20
+ let inMonorepo = false;
21
+ let monorepoRoot = appDirectory;
22
+ for(let depth = 0; depth < maxDepth; depth++){
23
+ if (isMonorepo(appDirectory)) {
24
+ inMonorepo = true;
25
+ break;
26
+ }
27
+ monorepoRoot = path.dirname(appDirectory);
28
+ }
29
+ return inMonorepo ? monorepoRoot : void 0;
30
+ };
31
+ const getMonorepoPackages = (root)=>{
32
+ let packages = [];
33
+ if (isYarnWorkspaces(root)) {
34
+ const json = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
35
+ ({ packages } = json.workspaces);
36
+ } else if (isLerna(root)) {
37
+ const json = JSON.parse(fs.readFileSync(path.resolve(root, 'lerna.json'), 'utf8'));
38
+ ({ packages } = json);
39
+ } else ({ packages } = yaml.load(fs.readFileSync(path.join(root, WORKSPACE_FILES.PNPM), 'utf8')));
40
+ if (packages) return packages.map((name)=>glob.sync(path.join(root, `${name}/`), {
41
+ ignore: [
42
+ '**/node_modules/**'
43
+ ]
44
+ })).reduce((acc, val)=>acc.concat(val), []).filter((filepath)=>fs.existsSync(path.resolve(filepath, 'package.json'))).map((filepath)=>({
45
+ path: filepath,
46
+ name: JSON.parse(fs.readFileSync(path.resolve(filepath, 'package.json'), 'utf8')).name
47
+ }));
48
+ return [];
49
+ };
50
+ export { findMonorepoRoot, getMonorepoPackages, isLerna, isMonorepo, isPnpmWorkspaces, isYarnWorkspaces };
@@ -0,0 +1,51 @@
1
+ import { execa } from "../compiled.mjs";
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 ('object' != typeof exports || null === exports) return exports;
46
+ if (Array.isArray(exports)) return exports.map(removeModuleSyncFromExports);
47
+ const result = {};
48
+ for (const [key, value] of Object.entries(exports))if ('module-sync' !== key) result[key] = removeModuleSyncFromExports(value);
49
+ return result;
50
+ }
51
+ export { canUseNpm, canUsePnpm, canUseYarn, getPnpmVersion, removeModuleSyncFromExports };
@@ -0,0 +1,35 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+ import { nanoid, upath } from "../compiled.mjs";
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
+ return ret;
25
+ }
26
+ function splitPathString(str) {
27
+ return str.split(/[\\/]/);
28
+ }
29
+ const removeLeadingSlash = (s)=>s.replace(/^\/+/, '');
30
+ const removeTailSlash = (s)=>s.replace(/\/+$/, '');
31
+ const removeSlash = (s)=>removeLeadingSlash(removeTailSlash(s));
32
+ function formatImportPath(str) {
33
+ return str.replace(/\\/g, '/');
34
+ }
35
+ export { formatImportPath, getRealTemporaryDirectory, getTemplatePath, isPathString, isRelativePath, normalizeOutputPath, normalizeToPosixPath, removeLeadingSlash, removeSlash, removeTailSlash, splitPathString };
@@ -0,0 +1,35 @@
1
+ import net from "net";
2
+ import { chalk } from "../compiled.mjs";
3
+ import { logger } from "./logger.mjs";
4
+ const getPort = async (expectPort, { tryLimits = 20, strictPort = false, slient = false } = {})=>{
5
+ let port = expectPort;
6
+ if ('string' == typeof port) port = parseInt(port, 10);
7
+ if (strictPort) tryLimits = 1;
8
+ const original = port;
9
+ let found = false;
10
+ let attempts = 0;
11
+ while(!found && attempts <= tryLimits)try {
12
+ await new Promise((resolve, reject)=>{
13
+ const server = net.createServer();
14
+ server.unref();
15
+ server.on('error', reject);
16
+ server.listen({
17
+ port,
18
+ host: '0.0.0.0'
19
+ }, ()=>{
20
+ found = true;
21
+ server.close(resolve);
22
+ });
23
+ });
24
+ } catch (e) {
25
+ if ('EADDRINUSE' !== e.code) throw e;
26
+ port++;
27
+ attempts++;
28
+ }
29
+ if (port !== original) {
30
+ if (strictPort) throw new Error(`Port "${original}" is occupied, please choose another one.`);
31
+ else if (!slient) logger.info(`Port ${original} is in use. ${chalk.yellow(`using port ${port}.`)}`);
32
+ }
33
+ return port;
34
+ };
35
+ export { getPort };
@@ -0,0 +1,68 @@
1
+ import { isIPv6 } from "net";
2
+ import os from "os";
3
+ import { chalk } from "../compiled.mjs";
4
+ import { DEFAULT_DEV_HOST } from "./constants.mjs";
5
+ import { isDev, isSingleEntry } from "./is/index.mjs";
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 = 'string' == typeof detail.family ? 'IPv4' : 4;
13
+ if (detail.family === familyV4Value) ipv4Interfaces.push(detail);
14
+ });
15
+ });
16
+ return ipv4Interfaces;
17
+ };
18
+ const getHostInUrl = (host)=>{
19
+ if (isIPv6(host)) return '::' === host ? '[::1]' : `[${host}]`;
20
+ return host;
21
+ };
22
+ const getAddressUrls = (protocol = 'http', port, host)=>{
23
+ const LOCAL_LABEL = 'Local: ';
24
+ const NETWORK_LABEL = 'Network: ';
25
+ const isLocalhost = (url)=>url?.includes('localhost');
26
+ if (host && host !== DEFAULT_DEV_HOST) return [
27
+ {
28
+ label: isLocalhost(host) ? LOCAL_LABEL : NETWORK_LABEL,
29
+ url: `${protocol}://${getHostInUrl(host)}:${port}`
30
+ }
31
+ ];
32
+ const ipv4Interfaces = getIpv4Interfaces();
33
+ return ipv4Interfaces.reduce((memo, detail)=>{
34
+ if (isLocalhost(detail.address) || detail.internal) memo.push({
35
+ label: LOCAL_LABEL,
36
+ url: `${protocol}://localhost:${port}`
37
+ });
38
+ else memo.push({
39
+ label: NETWORK_LABEL,
40
+ url: `${protocol}://${detail.address}:${port}`
41
+ });
42
+ return memo;
43
+ }, []);
44
+ };
45
+ const prettyInstructions = (appContext, config)=>{
46
+ const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
47
+ const isHttps = isDev() && (config?.dev?.https || config?.tools?.devServer?.https);
48
+ const urls = getAddressUrls(isHttps ? 'https' : 'http', port, config.dev?.host);
49
+ const routes = apiOnly ? serverRoutes : serverRoutes.filter((route)=>route.entryName);
50
+ let message = '\n';
51
+ if (isSingleEntry(entrypoints, config.source?.mainEntryName) || apiOnly) message += urls.map(({ label, url })=>` ${chalk.bold(`> ${label.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}\n`).join('');
52
+ else {
53
+ const maxNameLength = Math.max(...routes.map((r)=>r.entryName.length));
54
+ urls.forEach(({ label, url })=>{
55
+ message += ` ${chalk.bold(`> ${label}`)}${0 === routes.length ? chalk.cyanBright(url) : ''}\n`;
56
+ routes.forEach(({ entryName, urlPath, isSSR })=>{
57
+ if (!checkedEntries.includes(entryName)) return;
58
+ message += ` ${chalk.yellowBright(isSSR ? 'λ' : '○')} ${chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}\n`;
59
+ });
60
+ });
61
+ message += '\n';
62
+ message += chalk.cyanBright(' λ (Server) server-side renders at runtime\n');
63
+ message += chalk.cyanBright(' ○ (Static) client-side renders as static HTML\n');
64
+ }
65
+ if (config.dev?.cliShortcuts) message += ` ${chalk.dim('> press')} ${chalk.bold('h + enter')} ${chalk.dim('to show shortcuts')}\n`;
66
+ return message;
67
+ };
68
+ export { getAddressUrls, prettyInstructions };