@modern-js/utils 2.18.0 → 2.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/{alias.js → cli/alias.js} +3 -3
  3. package/dist/cjs/{applyOptionsChain.js → cli/applyOptionsChain.js} +6 -5
  4. package/dist/cjs/{babel.js → cli/babel.js} +3 -3
  5. package/dist/cjs/cli/common.js +26 -0
  6. package/dist/cjs/{constants.js → cli/constants/index.js} +14 -2
  7. package/dist/cjs/{readTsConfig.js → cli/ensure.js} +10 -9
  8. package/dist/cjs/cli/fs.js +29 -0
  9. package/dist/cjs/{getEntryOptions.js → cli/get/config.js} +2 -2
  10. package/dist/cjs/cli/get/data.js +112 -0
  11. package/dist/cjs/cli/get/index.js +46 -0
  12. package/dist/cjs/cli/index.js +41 -0
  13. package/dist/cjs/{is/index.js → cli/is/config.js} +2 -43
  14. package/dist/cjs/{is/nodeEnv.js → cli/is/env.js} +3 -1
  15. package/dist/cjs/cli/is/index.js +22 -0
  16. package/dist/cjs/cli/is/project.js +92 -0
  17. package/dist/cjs/{is → cli/is}/type.js +3 -1
  18. package/dist/cjs/{logger.js → cli/logger.js} +1 -1
  19. package/dist/cjs/{monorepo.js → cli/monorepo.js} +1 -1
  20. package/dist/cjs/{nodeEnv.js → cli/package.js} +8 -1
  21. package/dist/cjs/{path.js → cli/path.js} +8 -2
  22. package/dist/cjs/{pathSerializer.js → cli/pathSerializer.js} +1 -1
  23. package/dist/cjs/{getPort.js → cli/port.js} +1 -1
  24. package/dist/cjs/{prettyInstructions.js → cli/prettyInstructions.js} +1 -2
  25. package/dist/cjs/{printBuildError.js → cli/print.js} +1 -1
  26. package/dist/cjs/{compatRequire.js → cli/require.js} +21 -3
  27. package/dist/cjs/{routes.js → cli/routes.js} +4 -11
  28. package/dist/cjs/{runtimeExports.js → cli/runtimeExports.js} +1 -1
  29. package/dist/cjs/cli/watch.js +61 -0
  30. package/dist/cjs/index.js +1 -42
  31. package/dist/cjs/runtime/router.js +19 -0
  32. package/dist/cjs/{ssr.js → runtime-node/index.js} +3 -1
  33. package/dist/esm/{alias.js → cli/alias.js} +2 -2
  34. package/dist/esm/{applyOptionsChain.js → cli/applyOptionsChain.js} +2 -1
  35. package/dist/esm/{babel.js → cli/babel.js} +1 -1
  36. package/dist/esm/cli/common.js +10 -0
  37. package/dist/esm/{constants.js → cli/constants/index.js} +1 -1
  38. package/dist/esm/{ensureAbsolutePath.js → cli/ensure.js} +8 -0
  39. package/dist/esm/{findExists.js → cli/fs.js} +6 -1
  40. package/dist/esm/{getEntryOptions.js → cli/get/config.js} +2 -2
  41. package/dist/esm/cli/get/data.js +86 -0
  42. package/dist/esm/cli/get/index.js +13 -0
  43. package/dist/esm/cli/index.js +24 -0
  44. package/dist/esm/{is/index.js → cli/is/config.js} +1 -21
  45. package/dist/esm/{is/nodeEnv.js → cli/is/env.js} +1 -0
  46. package/dist/esm/cli/is/index.js +5 -0
  47. package/dist/esm/cli/is/project.js +67 -0
  48. package/dist/esm/{is → cli/is}/type.js +1 -0
  49. package/dist/esm/{logger.js → cli/logger.js} +1 -1
  50. package/dist/esm/{monorepo.js → cli/monorepo.js} +1 -1
  51. package/dist/esm/{nodeEnv.js → cli/package.js} +7 -1
  52. package/dist/esm/{path.js → cli/path.js} +4 -1
  53. package/dist/esm/{pathSerializer.js → cli/pathSerializer.js} +1 -1
  54. package/dist/esm/{getPort.js → cli/port.js} +1 -1
  55. package/dist/esm/{prettyInstructions.js → cli/prettyInstructions.js} +2 -2
  56. package/dist/esm/{printBuildError.js → cli/print.js} +1 -1
  57. package/dist/esm/{compatRequire.js → cli/require.js} +18 -1
  58. package/dist/esm/{routes.js → cli/routes.js} +2 -2
  59. package/dist/esm/{runtimeExports.js → cli/runtimeExports.js} +1 -1
  60. package/dist/esm/{watch.js → cli/watch.js} +2 -2
  61. package/dist/esm/index.js +1 -42
  62. package/dist/esm/runtime/router.js +2 -0
  63. package/dist/esm/{ssr.js → runtime-node/index.js} +1 -0
  64. package/dist/types/{applyOptionsChain.d.ts → cli/applyOptionsChain.d.ts} +1 -1
  65. package/dist/types/{debug.d.ts → cli/common.d.ts} +3 -1
  66. package/dist/types/{constants.d.ts → cli/constants/index.d.ts} +2 -6
  67. package/dist/types/{ensureAbsolutePath.d.ts → cli/ensure.d.ts} +2 -1
  68. package/dist/types/{findExists.d.ts → cli/fs.d.ts} +2 -1
  69. package/dist/types/cli/get/data.d.ts +9 -0
  70. package/dist/types/cli/get/index.d.ts +4 -0
  71. package/dist/types/cli/index.d.ts +24 -0
  72. package/dist/types/cli/is/config.d.ts +30 -0
  73. package/dist/types/{is/nodeEnv.d.ts → cli/is/env.d.ts} +2 -1
  74. package/dist/types/cli/is/index.d.ts +5 -0
  75. package/dist/types/cli/is/project.d.ts +25 -0
  76. package/dist/types/{is → cli/is}/type.d.ts +9 -1
  77. package/dist/types/{logger.d.ts → cli/logger.d.ts} +1 -1
  78. package/dist/types/cli/package.d.ts +4 -0
  79. package/dist/types/{path.d.ts → cli/path.d.ts} +5 -2
  80. package/dist/types/{prettyInstructions.d.ts → cli/prettyInstructions.d.ts} +0 -3
  81. package/dist/types/{compatRequire.d.ts → cli/require.d.ts} +9 -1
  82. package/dist/types/cli/routes.d.ts +1 -0
  83. package/dist/types/{watch.d.ts → cli/watch.d.ts} +1 -1
  84. package/dist/types/index.d.ts +2 -43
  85. package/dist/types/runtime/router.d.ts +2 -0
  86. package/dist/types/{ssr.d.ts → runtime-node/index.d.ts} +2 -1
  87. package/package.json +56 -93
  88. package/dist/cjs/FileSizeReporter.js +0 -139
  89. package/dist/cjs/analyzeProject.js +0 -68
  90. package/dist/cjs/clearConsole.js +0 -13
  91. package/dist/cjs/debug.js +0 -10
  92. package/dist/cjs/emptyDir.js +0 -14
  93. package/dist/cjs/ensureAbsolutePath.js +0 -15
  94. package/dist/cjs/ensureArray.js +0 -16
  95. package/dist/cjs/findExists.js +0 -22
  96. package/dist/cjs/getBrowserslist.js +0 -24
  97. package/dist/cjs/getCoreJsVersion.js +0 -58
  98. package/dist/cjs/getPackageManager.js +0 -42
  99. package/dist/cjs/getServerConfig.js +0 -55
  100. package/dist/cjs/getTargetDir.js +0 -53
  101. package/dist/cjs/plugin.js +0 -28
  102. package/dist/cjs/react.js +0 -30
  103. package/dist/cjs/removeSlash.js +0 -19
  104. package/dist/cjs/resolve.js +0 -57
  105. package/dist/cjs/types.js +0 -4
  106. package/dist/cjs/version.js +0 -43
  107. package/dist/cjs/wait.js +0 -11
  108. package/dist/cjs/watch.js +0 -96
  109. package/dist/esm/FileSizeReporter.js +0 -121
  110. package/dist/esm/analyzeProject.js +0 -13
  111. package/dist/esm/clearConsole.js +0 -5
  112. package/dist/esm/debug.js +0 -2
  113. package/dist/esm/emptyDir.js +0 -6
  114. package/dist/esm/ensureArray.js +0 -8
  115. package/dist/esm/getBrowserslist.js +0 -9
  116. package/dist/esm/getCoreJsVersion.js +0 -10
  117. package/dist/esm/getPackageManager.js +0 -29
  118. package/dist/esm/getServerConfig.js +0 -7
  119. package/dist/esm/getTargetDir.js +0 -5
  120. package/dist/esm/plugin.js +0 -20
  121. package/dist/esm/react.js +0 -17
  122. package/dist/esm/readTsConfig.js +0 -9
  123. package/dist/esm/removeSlash.js +0 -3
  124. package/dist/esm/resolve.js +0 -41
  125. package/dist/esm/types.js +0 -1
  126. package/dist/esm/version.js +0 -23
  127. package/dist/esm/wait.js +0 -4
  128. package/dist/types/FileSizeReporter.d.ts +0 -16
  129. package/dist/types/analyzeProject.d.ts +0 -2
  130. package/dist/types/clearConsole.d.ts +0 -1
  131. package/dist/types/emptyDir.d.ts +0 -1
  132. package/dist/types/ensureArray.d.ts +0 -1
  133. package/dist/types/getBrowserslist.d.ts +0 -2
  134. package/dist/types/getCoreJsVersion.d.ts +0 -1
  135. package/dist/types/getPackageManager.d.ts +0 -1
  136. package/dist/types/getServerConfig.d.ts +0 -1
  137. package/dist/types/getTargetDir.d.ts +0 -1
  138. package/dist/types/is/index.d.ts +0 -58
  139. package/dist/types/nodeEnv.d.ts +0 -3
  140. package/dist/types/plugin.d.ts +0 -2
  141. package/dist/types/react.d.ts +0 -1
  142. package/dist/types/readTsConfig.d.ts +0 -2
  143. package/dist/types/removeSlash.d.ts +0 -3
  144. package/dist/types/resolve.d.ts +0 -13
  145. package/dist/types/routes.d.ts +0 -2
  146. package/dist/types/types.d.ts +0 -1
  147. package/dist/types/version.d.ts +0 -2
  148. package/dist/types/wait.d.ts +0 -2
  149. /package/dist/cjs/{commands.js → cli/commands.js} +0 -0
  150. /package/dist/cjs/{chainId.js → cli/constants/chainId.js} +0 -0
  151. /package/dist/cjs/{generateMetaTags.js → cli/generateMetaTags.js} +0 -0
  152. /package/dist/cjs/{is → cli/is}/platform.js +0 -0
  153. /package/dist/cjs/{testUtils.js → cli/test.js} +0 -0
  154. /package/dist/cjs/{universal → runtime}/nestedRoutes.js +0 -0
  155. /package/dist/cjs/{universal → runtime}/remixRouter.js +0 -0
  156. /package/dist/cjs/{runtime → runtime-browser}/index.js +0 -0
  157. /package/dist/cjs/{runtime → runtime-browser}/parsed.js +0 -0
  158. /package/dist/cjs/{universal → runtime-node}/serialize.js +0 -0
  159. /package/dist/cjs/{storage.js → runtime-node/storage.js} +0 -0
  160. /package/dist/esm/{commands.js → cli/commands.js} +0 -0
  161. /package/dist/esm/{chainId.js → cli/constants/chainId.js} +0 -0
  162. /package/dist/esm/{generateMetaTags.js → cli/generateMetaTags.js} +0 -0
  163. /package/dist/esm/{is → cli/is}/platform.js +0 -0
  164. /package/dist/esm/{testUtils.js → cli/test.js} +0 -0
  165. /package/dist/esm/{universal → runtime}/nestedRoutes.js +0 -0
  166. /package/dist/esm/{universal → runtime}/remixRouter.js +0 -0
  167. /package/dist/esm/{runtime → runtime-browser}/index.js +0 -0
  168. /package/dist/esm/{runtime → runtime-browser}/parsed.js +0 -0
  169. /package/dist/esm/{universal → runtime-node}/serialize.js +0 -0
  170. /package/dist/esm/{storage.js → runtime-node/storage.js} +0 -0
  171. /package/dist/types/{alias.d.ts → cli/alias.d.ts} +0 -0
  172. /package/dist/types/{babel.d.ts → cli/babel.d.ts} +0 -0
  173. /package/dist/types/{commands.d.ts → cli/commands.d.ts} +0 -0
  174. /package/dist/types/{chainId.d.ts → cli/constants/chainId.d.ts} +0 -0
  175. /package/dist/types/{generateMetaTags.d.ts → cli/generateMetaTags.d.ts} +0 -0
  176. /package/dist/types/{getEntryOptions.d.ts → cli/get/config.d.ts} +0 -0
  177. /package/dist/types/{is → cli/is}/platform.d.ts +0 -0
  178. /package/dist/types/{monorepo.d.ts → cli/monorepo.d.ts} +0 -0
  179. /package/dist/types/{pathSerializer.d.ts → cli/pathSerializer.d.ts} +0 -0
  180. /package/dist/types/{getPort.d.ts → cli/port.d.ts} +0 -0
  181. /package/dist/types/{printBuildError.d.ts → cli/print.d.ts} +0 -0
  182. /package/dist/types/{runtimeExports.d.ts → cli/runtimeExports.d.ts} +0 -0
  183. /package/dist/types/{testUtils.d.ts → cli/test.d.ts} +0 -0
  184. /package/dist/types/{universal → runtime}/nestedRoutes.d.ts +0 -0
  185. /package/dist/types/{universal → runtime}/remixRouter.d.ts +0 -0
  186. /package/dist/types/{runtime → runtime-browser}/index.d.ts +0 -0
  187. /package/dist/types/{runtime → runtime-browser}/parsed.d.ts +0 -0
  188. /package/dist/types/{universal → runtime-node}/serialize.d.ts +0 -0
  189. /package/dist/types/{storage.d.ts → runtime-node/storage.d.ts} +0 -0
@@ -10,11 +10,18 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
+ getPnpmVersion: () => getPnpmVersion,
13
14
  canUseNpm: () => canUseNpm,
14
15
  canUseYarn: () => canUseYarn,
15
16
  canUsePnpm: () => canUsePnpm
16
17
  });
17
- const _compiled = require("./compiled");
18
+ const _compiled = require("../compiled");
19
+ async function getPnpmVersion() {
20
+ const { stdout } = await (0, _compiled.execa)("pnpm", [
21
+ "--version"
22
+ ]);
23
+ return stdout;
24
+ }
18
25
  async function canUseNpm() {
19
26
  try {
20
27
  await (0, _compiled.execa)("npm", [
@@ -19,12 +19,15 @@ _export(exports, {
19
19
  _joinPathParts: () => _joinPathParts,
20
20
  upwardPaths: () => upwardPaths,
21
21
  getRealTemporaryDirectory: () => getRealTemporaryDirectory,
22
- splitPathString: () => splitPathString
22
+ splitPathString: () => splitPathString,
23
+ removeLeadingSlash: () => removeLeadingSlash,
24
+ removeTailSlash: () => removeTailSlash,
25
+ removeSlash: () => removeSlash
23
26
  });
24
27
  const _path = /* @__PURE__ */ _interop_require_default(require("path"));
25
28
  const _os = /* @__PURE__ */ _interop_require_default(require("os"));
26
29
  const _fs = /* @__PURE__ */ _interop_require_default(require("fs"));
27
- const _compiled = require("./compiled");
30
+ const _compiled = require("../compiled");
28
31
  function _interop_require_default(obj) {
29
32
  return obj && obj.__esModule ? obj : {
30
33
  default: obj
@@ -69,3 +72,6 @@ function getRealTemporaryDirectory() {
69
72
  function splitPathString(str) {
70
73
  return str.split(/[\\/]/);
71
74
  }
75
+ const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
76
+ const removeTailSlash = (s) => s.replace(/\/+$/, "");
77
+ const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
@@ -16,7 +16,7 @@ _export(exports, {
16
16
  createDefaultPathMatchers: () => createDefaultPathMatchers
17
17
  });
18
18
  const _os = /* @__PURE__ */ _interop_require_default(require("os"));
19
- const _lodash = /* @__PURE__ */ _interop_require_default(require("../compiled/lodash"));
19
+ const _lodash = /* @__PURE__ */ _interop_require_default(require("../../compiled/lodash"));
20
20
  const _path = require("./path");
21
21
  function _interop_require_default(obj) {
22
22
  return obj && obj.__esModule ? obj : {
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "getPort", {
7
7
  get: () => getPort
8
8
  });
9
9
  const _net = /* @__PURE__ */ _interop_require_default(require("net"));
10
- const _compiled = require("./compiled");
10
+ const _compiled = require("../compiled");
11
11
  const _logger = require("./logger");
12
12
  function _interop_require_default(obj) {
13
13
  return obj && obj.__esModule ? obj : {
@@ -10,12 +10,11 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- getIpv4Interfaces: () => getIpv4Interfaces,
14
13
  getAddressUrls: () => getAddressUrls,
15
14
  prettyInstructions: () => prettyInstructions
16
15
  });
17
16
  const _os = /* @__PURE__ */ _interop_require_default(require("os"));
18
- const _compiled = require("./compiled");
17
+ const _compiled = require("../compiled");
19
18
  const _is = require("./is");
20
19
  const _constants = require("./constants");
21
20
  function _interop_require_default(obj) {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "printBuildError", {
6
6
  enumerable: true,
7
7
  get: () => printBuildError
8
8
  });
9
- const _compiled = require("./compiled");
9
+ const _compiled = require("../compiled");
10
10
  const _logger = require("./logger");
11
11
  function printBuildError(err) {
12
12
  const message = err != null && err.message;
@@ -14,9 +14,10 @@ _export(exports, {
14
14
  dynamicImport: () => dynamicImport,
15
15
  requireExistModule: () => requireExistModule,
16
16
  cleanRequireCache: () => cleanRequireCache,
17
- deleteRequireCache: () => deleteRequireCache
17
+ deleteRequireCache: () => deleteRequireCache,
18
+ tryResolve: () => tryResolve
18
19
  });
19
- const _findExists = require("./findExists");
20
+ const _fs = require("./fs");
20
21
  const compatRequire = (filePath, interop = true) => {
21
22
  const mod = require(filePath);
22
23
  const rtnESMDefault = interop && (mod === null || mod === void 0 ? void 0 : mod.__esModule);
@@ -32,7 +33,7 @@ const requireExistModule = (filename, opt) => {
32
33
  interop: true,
33
34
  ...opt
34
35
  };
35
- const exist = (0, _findExists.findExists)(final.extensions.map((ext) => `${filename}${ext}`));
36
+ const exist = (0, _fs.findExists)(final.extensions.map((ext) => `${filename}${ext}`));
36
37
  if (!exist) {
37
38
  return null;
38
39
  }
@@ -51,3 +52,20 @@ function deleteRequireCache(path) {
51
52
  module.children = module.children.filter((item) => item.filename !== path);
52
53
  }
53
54
  }
55
+ const tryResolve = (name, resolvePath) => {
56
+ let filePath = "";
57
+ try {
58
+ filePath = require.resolve(name, {
59
+ paths: [
60
+ resolvePath
61
+ ]
62
+ });
63
+ delete require.cache[filePath];
64
+ } catch (err) {
65
+ if (err.code === "MODULE_NOT_FOUND") {
66
+ throw new Error(`Can not find module ${name}.`);
67
+ }
68
+ throw err;
69
+ }
70
+ return filePath;
71
+ };
@@ -2,20 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- function _export(target, all) {
6
- for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- getPathWithoutExt: () => getPathWithoutExt,
14
- getRouteId: () => getRouteId
5
+ Object.defineProperty(exports, "getRouteId", {
6
+ enumerable: true,
7
+ get: () => getRouteId
15
8
  });
16
9
  const _path = /* @__PURE__ */ _interop_require_default(require("path"));
17
- const _path1 = require("./path");
18
10
  const _constants = require("./constants");
11
+ const _path1 = require("./path");
19
12
  function _interop_require_default(obj) {
20
13
  return obj && obj.__esModule ? obj : {
21
14
  default: obj
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "createRuntimeExportsUtils", {
7
7
  get: () => createRuntimeExportsUtils
8
8
  });
9
9
  const _path = /* @__PURE__ */ _interop_require_default(require("path"));
10
- const _compiled = require("./compiled");
10
+ const _compiled = require("../compiled");
11
11
  const _path1 = require("./path");
12
12
  function _interop_require_default(obj) {
13
13
  return obj && obj.__esModule ? obj : {
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ WatchChangeType: () => WatchChangeType,
14
+ watch: () => watch
15
+ });
16
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
17
+ const _compiled = require("../compiled");
18
+ function _interop_require_default(obj) {
19
+ return obj && obj.__esModule ? obj : {
20
+ default: obj
21
+ };
22
+ }
23
+ const WatchChangeType = {
24
+ ADD: "add",
25
+ UNLINK: "unlink",
26
+ CHANGE: "change"
27
+ };
28
+ const watch = (watchDir, runTask, ignored = []) => {
29
+ let ready = false;
30
+ const watcher = _compiled.chokidar.watch(watchDir, {
31
+ ignored
32
+ });
33
+ watcher.on("ready", () => ready = true);
34
+ watcher.on("change", async (filePath) => {
35
+ const changedFilePath = _path.default.resolve(filePath);
36
+ await runTask({
37
+ changedFilePath,
38
+ changeType: WatchChangeType.CHANGE
39
+ });
40
+ });
41
+ watcher.on("add", async (filePath) => {
42
+ const changedFilePath = _path.default.resolve(filePath);
43
+ if (ready) {
44
+ await runTask({
45
+ changedFilePath,
46
+ changeType: WatchChangeType.ADD
47
+ });
48
+ }
49
+ });
50
+ watcher.on("unlink", async (filePath) => {
51
+ const changedFilePath = _path.default.resolve(filePath);
52
+ await runTask({
53
+ changedFilePath,
54
+ changeType: WatchChangeType.UNLINK
55
+ });
56
+ });
57
+ watcher.on("error", (err) => {
58
+ throw err;
59
+ });
60
+ return watcher;
61
+ };
package/dist/cjs/index.js CHANGED
@@ -3,49 +3,8 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  _export_star(require("./compiled"), exports);
6
- _export_star(require("./commands"), exports);
7
- _export_star(require("./FileSizeReporter"), exports);
8
- _export_star(require("./printBuildError"), exports);
9
- _export_star(require("./debug"), exports);
10
- _export_star(require("./findExists"), exports);
11
- _export_star(require("./is"), exports);
12
- _export_star(require("./compatRequire"), exports);
13
- _export_star(require("./logger"), exports);
14
- _export_star(require("./constants"), exports);
15
- _export_star(require("./ensureArray"), exports);
16
- _export_star(require("./ensureAbsolutePath"), exports);
17
- _export_star(require("./clearConsole"), exports);
18
- _export_star(require("./applyOptionsChain"), exports);
19
- _export_star(require("./getBrowserslist"), exports);
20
- _export_star(require("./removeSlash"), exports);
21
- _export_star(require("./getEntryOptions"), exports);
22
- _export_star(require("./getPort"), exports);
23
- _export_star(require("./monorepo"), exports);
24
- _export_star(require("./getPackageManager"), exports);
25
- _export_star(require("./runtimeExports"), exports);
26
- _export_star(require("./readTsConfig"), exports);
27
- _export_star(require("./path"), exports);
28
- _export_star(require("./pathSerializer"), exports);
29
- _export_star(require("./generateMetaTags"), exports);
30
- _export_star(require("./prettyInstructions"), exports);
31
- _export_star(require("./alias"), exports);
6
+ _export_star(require("./cli"), exports);
32
7
  _export_star(require("./import"), exports);
33
- _export_star(require("./watch"), exports);
34
- _export_star(require("./nodeEnv"), exports);
35
- _export_star(require("./wait"), exports);
36
- _export_star(require("./emptyDir"), exports);
37
- _export_star(require("./getServerConfig"), exports);
38
- _export_star(require("./resolve"), exports);
39
- _export_star(require("./analyzeProject"), exports);
40
- _export_star(require("./chainId"), exports);
41
- _export_star(require("./version"), exports);
42
- _export_star(require("./plugin"), exports);
43
- _export_star(require("./routes"), exports);
44
- _export_star(require("./testUtils"), exports);
45
- _export_star(require("./getCoreJsVersion"), exports);
46
- _export_star(require("./react"), exports);
47
- _export_star(require("./getTargetDir"), exports);
48
- _export_star(require("./babel"), exports);
49
8
  function _export_star(from, to) {
50
9
  Object.keys(from).forEach(function(k) {
51
10
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./nestedRoutes"), exports);
6
+ _export_star(require("./remixRouter"), exports);
7
+ function _export_star(from, to) {
8
+ Object.keys(from).forEach(function(k) {
9
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
10
+ Object.defineProperty(to, k, {
11
+ enumerable: true,
12
+ get: function() {
13
+ return from[k];
14
+ }
15
+ });
16
+ }
17
+ });
18
+ return from;
19
+ }
@@ -11,7 +11,9 @@ function _export(target, all) {
11
11
  }
12
12
  _export(exports, {
13
13
  run: () => run,
14
- useHeaders: () => useHeaders
14
+ useHeaders: () => useHeaders,
15
+ serializeJson: () => _serialize.serializeJson
15
16
  });
16
17
  const _storage = require("./storage");
18
+ const _serialize = require("./serialize");
17
19
  const { run, useContext: useHeaders } = (0, _storage.createStorage)();
@@ -1,7 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { chalk } from "./compiled";
4
- import { readTsConfigByFile } from "./readTsConfig";
3
+ import { chalk } from "../compiled";
4
+ import { readTsConfigByFile } from "./get";
5
5
  import { applyOptionsChain } from "./applyOptionsChain";
6
6
  export const validAlias = (modernConfig, { tsconfigPath }) => {
7
7
  const { source: { alias } } = modernConfig;
@@ -1,4 +1,5 @@
1
- import { isFunction, logger, isPlainObject } from "./index";
1
+ import { isFunction, isPlainObject } from "./is";
2
+ import { logger } from "./logger";
2
3
  export function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
3
4
  if (!options) {
4
5
  return defaults;
@@ -1,6 +1,6 @@
1
1
  import { isAbsolute, sep } from "path";
2
2
  import { applyOptionsChain } from "./applyOptionsChain";
3
- import { ensureArray } from "./ensureArray";
3
+ import { ensureArray } from "./ensure";
4
4
  import { normalizeToPosixPath } from "./path";
5
5
  const formatPath = (originPath) => {
6
6
  if (isAbsolute(originPath)) {
@@ -0,0 +1,10 @@
1
+ import { debug } from "../../compiled/debug";
2
+ export const createDebugger = (scope) => debug(`modern-js:${scope}`);
3
+ export const clearConsole = () => {
4
+ if (process.stdout.isTTY && !process.env.DEBUG) {
5
+ process.stdout.write("\x1B[H\x1B[2J");
6
+ }
7
+ };
8
+ export const wait = (time = 0) => new Promise((resolve) => {
9
+ setTimeout(resolve, time);
10
+ });
@@ -1,6 +1,5 @@
1
1
  export const ROUTE_SPEC_FILE = "route.json";
2
2
  export const MAIN_ENTRY_NAME = "main";
3
- export const LAUNCH_EDITOR_ENDPOINT = "/__open-stack-frame-in-editor";
4
3
  export const SERVER_BUNDLE_DIRECTORY = "bundles";
5
4
  export const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
6
5
  export const ENTRY_NAME_PATTERN = "^[a-zA-Z0-9_-]+$";
@@ -312,3 +311,4 @@ export const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
312
311
  optimizeConstEnums: true,
313
312
  isTSX: true
314
313
  };
314
+ export * from "./chainId";
@@ -1,2 +1,10 @@
1
1
  import path from "path";
2
2
  export const ensureAbsolutePath = (base, filePath) => path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath);
3
+ export const ensureArray = (params) => {
4
+ if (Array.isArray(params)) {
5
+ return params;
6
+ }
7
+ return [
8
+ params
9
+ ];
10
+ };
@@ -1,4 +1,4 @@
1
- import fs from "fs";
1
+ import { fs } from "../compiled";
2
2
  export const findExists = (files) => {
3
3
  for (const file of files) {
4
4
  if (fs.existsSync(file) && fs.statSync(file).isFile()) {
@@ -7,3 +7,8 @@ export const findExists = (files) => {
7
7
  }
8
8
  return false;
9
9
  };
10
+ export const emptyDir = async (dir) => {
11
+ if (await fs.pathExists(dir)) {
12
+ await fs.emptyDir(dir);
13
+ }
14
+ };
@@ -1,5 +1,5 @@
1
- import { isPlainObject } from "./is";
2
- import { MAIN_ENTRY_NAME } from "./constants";
1
+ import { isPlainObject } from "../is";
2
+ import { MAIN_ENTRY_NAME } from "../constants";
3
3
  export const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
4
4
  if (optionsByEntries) {
5
5
  let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
@@ -0,0 +1,86 @@
1
+ import os from "os";
2
+ import path from "path";
3
+ import { browserslist, fs, 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
+ export 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
+ export 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
+ export 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
+ export const defaults = [
55
+ "> 0.01%",
56
+ "not dead",
57
+ "not op_mini all"
58
+ ];
59
+ export const getBrowserslist = (appDirectory) => browserslist.loadConfig({
60
+ path: appDirectory
61
+ }) || defaults;
62
+ export 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
+ export const readTsConfig = (root) => {
81
+ return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
82
+ };
83
+ export const readTsConfigByFile = (filename) => {
84
+ const content = fs.readFileSync(path.resolve(filename), "utf-8");
85
+ return json5.parse(content);
86
+ };
@@ -0,0 +1,13 @@
1
+ import path from "path";
2
+ import { CONFIG_FILE_EXTENSIONS } from "../constants";
3
+ import { findExists } from "../fs";
4
+ export const getServerConfig = async (appDirectory, configFile) => {
5
+ const configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(appDirectory, `${configFile}${extension}`)));
6
+ return configFilePath;
7
+ };
8
+ export const getTargetDir = (from, baseDir, targetBaseDir) => {
9
+ const relativePath = path.relative(baseDir, from);
10
+ return path.resolve(targetBaseDir, relativePath);
11
+ };
12
+ export * from "./data";
13
+ export * from "./config";
@@ -0,0 +1,24 @@
1
+ export * from "./constants";
2
+ export * from "./get";
3
+ export * from "./is";
4
+ export * from "./alias";
5
+ export * from "./applyOptionsChain";
6
+ export * from "./babel";
7
+ export * from "./commands";
8
+ export * from "./common";
9
+ export * from "./ensure";
10
+ export * from "./fs";
11
+ export * from "./generateMetaTags";
12
+ export * from "./logger";
13
+ export * from "./monorepo";
14
+ export * from "./package";
15
+ export * from "./path";
16
+ export * from "./pathSerializer";
17
+ export * from "./port";
18
+ export * from "./prettyInstructions";
19
+ export * from "./print";
20
+ export * from "./require";
21
+ export * from "./routes";
22
+ export * from "./runtimeExports";
23
+ export * from "./test";
24
+ export * from "./watch";
@@ -1,20 +1,4 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { createDebugger } from "../debug";
4
- import { isDev } from "./nodeEnv";
5
- const debug = createDebugger("judge-depExists");
6
- export const isDepExists = (appDirectory, name) => {
7
- const pkgPath = path.resolve(appDirectory, "./package.json");
8
- if (!fs.existsSync(pkgPath)) {
9
- debug(`can't find package.json under: %s`, appDirectory);
10
- return false;
11
- }
12
- const json = require(pkgPath);
13
- const { dependencies = {}, devDependencies = {} } = json;
14
- return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
15
- };
16
- export const isTypescript = (root) => fs.existsSync(path.resolve(root, "./tsconfig.json"));
17
- export const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
1
+ import { isEmpty } from "./type";
18
2
  export const isSSR = (config) => {
19
3
  const { server } = config;
20
4
  if (server === null || server === void 0 ? void 0 : server.ssr) {
@@ -44,7 +28,6 @@ export const isServiceWorker = (config) => {
44
28
  }
45
29
  return false;
46
30
  };
47
- export const isFastRefresh = () => isDev() && process.env.FAST_REFRESH !== "false";
48
31
  export const isRouterV5 = (config) => {
49
32
  var _config_runtime, _config_runtime1, _config_runtime_router;
50
33
  return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
@@ -55,6 +38,3 @@ export const isSSGEntry = (config, entryName, entrypoints) => {
55
38
  return useSSG;
56
39
  };
57
40
  export const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
58
- export * from "./nodeEnv";
59
- export * from "./platform";
60
- export * from "./type";
@@ -3,3 +3,4 @@ export const isDev = () => getNodeEnv() === "development";
3
3
  export const isProd = () => getNodeEnv() === "production";
4
4
  export const isTest = () => getNodeEnv() === "test";
5
5
  export const isProdProfile = () => isProd() && process.argv.includes("--profile");
6
+ export const isFastRefresh = () => isDev() && process.env.FAST_REFRESH !== "false";
@@ -0,0 +1,5 @@
1
+ export * from "./env";
2
+ export * from "./platform";
3
+ export * from "./type";
4
+ export * from "./config";
5
+ export * from "./project";
@@ -0,0 +1,67 @@
1
+ import path from "path";
2
+ import { getArgv } from "../commands";
3
+ import { fs, minimist, semver } from "../../compiled";
4
+ import { createDebugger } from "../common";
5
+ import { ensureArray } from "../ensure";
6
+ const debug = createDebugger("judge-depExists");
7
+ export const isDepExists = (appDirectory, name) => {
8
+ const pkgPath = path.resolve(appDirectory, "./package.json");
9
+ if (!fs.existsSync(pkgPath)) {
10
+ debug(`can't find package.json under: %s`, appDirectory);
11
+ return false;
12
+ }
13
+ const json = require(pkgPath);
14
+ const { dependencies = {}, devDependencies = {} } = json;
15
+ return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
16
+ };
17
+ export const isPackageInstalled = (name, resolvePaths) => {
18
+ try {
19
+ require.resolve(name, {
20
+ paths: ensureArray(resolvePaths)
21
+ });
22
+ return true;
23
+ } catch (err) {
24
+ return false;
25
+ }
26
+ };
27
+ export const isApiOnly = async (appDirectory, entryDir) => {
28
+ const srcDir = path.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src");
29
+ const existSrc = await fs.pathExists(srcDir);
30
+ const options = minimist(getArgv());
31
+ return !existSrc || Boolean(options["api-only"]);
32
+ };
33
+ export const isWebOnly = async () => {
34
+ const options = minimist(getArgv());
35
+ return Boolean(options["web-only"]);
36
+ };
37
+ export const isBeyondReact17 = (cwd) => {
38
+ const pkgPath = path.join(cwd, "package.json");
39
+ if (!fs.existsSync(pkgPath)) {
40
+ return false;
41
+ }
42
+ const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
43
+ const deps = {
44
+ ...pkgInfo.devDependencies,
45
+ ...pkgInfo.dependencies
46
+ };
47
+ if (typeof deps.react !== "string") {
48
+ return false;
49
+ }
50
+ return semver.satisfies(semver.minVersion(deps.react), ">=17.0.0");
51
+ };
52
+ export const isReact18 = (cwd) => {
53
+ const pkgPath = path.join(cwd, "package.json");
54
+ if (!fs.existsSync(pkgPath)) {
55
+ return false;
56
+ }
57
+ const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
58
+ const deps = {
59
+ ...pkgInfo.devDependencies,
60
+ ...pkgInfo.dependencies
61
+ };
62
+ if (typeof deps.react !== "string") {
63
+ return false;
64
+ }
65
+ return semver.satisfies(semver.minVersion(deps.react), ">=18.0.0");
66
+ };
67
+ export const isTypescript = (root) => fs.existsSync(path.resolve(root, "./tsconfig.json"));
@@ -22,3 +22,4 @@ export function isPromise(obj) {
22
22
  export function isRegExp(obj) {
23
23
  return Object.prototype.toString.call(obj) === "[object RegExp]";
24
24
  }
25
+ export const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;