@modern-js/utils 2.25.2 → 2.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/universal/formatWebpack.js +0 -4
  3. package/dist/esm/cli/alias.js +26 -22
  4. package/dist/esm/cli/applyOptionsChain.js +8 -6
  5. package/dist/esm/cli/babel.js +50 -35
  6. package/dist/esm/cli/commands.js +7 -7
  7. package/dist/esm/cli/common.js +10 -5
  8. package/dist/esm/cli/constants/chainId.js +1 -1
  9. package/dist/esm/cli/constants/index.js +33 -37
  10. package/dist/esm/cli/ensure.js +4 -2
  11. package/dist/esm/cli/fs.js +56 -9
  12. package/dist/esm/cli/get/config.js +7 -7
  13. package/dist/esm/cli/get/data.js +93 -55
  14. package/dist/esm/cli/get/index.js +21 -6
  15. package/dist/esm/cli/is/config.js +33 -14
  16. package/dist/esm/cli/is/env.js +18 -6
  17. package/dist/esm/cli/is/platform.js +6 -2
  18. package/dist/esm/cli/is/project.js +73 -36
  19. package/dist/esm/cli/is/type.js +3 -1
  20. package/dist/esm/cli/logger.js +49 -38
  21. package/dist/esm/cli/monorepo.js +49 -36
  22. package/dist/esm/cli/package.js +156 -38
  23. package/dist/esm/cli/path.js +44 -20
  24. package/dist/esm/cli/pathSerializer.js +29 -15
  25. package/dist/esm/cli/port.js +89 -40
  26. package/dist/esm/cli/prettyInstructions.js +42 -31
  27. package/dist/esm/cli/require.js +21 -16
  28. package/dist/esm/cli/runtimeExports.js +21 -15
  29. package/dist/esm/cli/watch.js +94 -27
  30. package/dist/esm/compiled.js +3 -3
  31. package/dist/esm/import.js +4 -4
  32. package/dist/esm/runtime/nestedRoutes.js +42 -29
  33. package/dist/esm/runtime-browser/parsed.js +5 -5
  34. package/dist/esm/runtime-node/index.js +1 -1
  35. package/dist/esm/runtime-node/nestedRoutes.js +6 -4
  36. package/dist/esm/runtime-node/serialize.js +1 -1
  37. package/dist/esm/runtime-node/storage.js +12 -14
  38. package/dist/esm/universal/constants.js +3 -3
  39. package/dist/esm/universal/formatWebpack.js +20 -26
  40. package/dist/esm/universal/pluginDagSort.js +49 -26
  41. package/dist/esm-node/cli/alias.js +51 -0
  42. package/dist/esm-node/cli/applyOptionsChain.js +24 -0
  43. package/dist/esm-node/cli/babel.js +103 -0
  44. package/dist/esm-node/cli/commands.js +16 -0
  45. package/dist/esm-node/cli/common.js +10 -0
  46. package/dist/esm-node/cli/constants/chainId.js +180 -0
  47. package/dist/esm-node/cli/constants/index.js +103 -0
  48. package/dist/esm-node/cli/ensure.js +10 -0
  49. package/dist/esm-node/cli/fs.js +14 -0
  50. package/dist/esm-node/cli/get/config.js +16 -0
  51. package/dist/esm-node/cli/get/data.js +86 -0
  52. package/dist/esm-node/cli/get/index.js +13 -0
  53. package/dist/esm-node/cli/index.js +20 -0
  54. package/dist/esm-node/cli/is/config.js +40 -0
  55. package/dist/esm-node/cli/is/env.js +6 -0
  56. package/dist/esm-node/cli/is/index.js +5 -0
  57. package/dist/esm-node/cli/is/platform.js +2 -0
  58. package/dist/esm-node/cli/is/project.js +73 -0
  59. package/dist/esm-node/cli/is/type.js +25 -0
  60. package/dist/esm-node/cli/logger.js +103 -0
  61. package/dist/esm-node/cli/monorepo.js +70 -0
  62. package/dist/esm-node/cli/package.js +43 -0
  63. package/dist/esm-node/cli/path.js +49 -0
  64. package/dist/esm-node/cli/pathSerializer.js +46 -0
  65. package/dist/esm-node/cli/port.js +44 -0
  66. package/dist/esm-node/cli/prettyInstructions.js +77 -0
  67. package/dist/esm-node/cli/require.js +52 -0
  68. package/dist/esm-node/cli/runtimeExports.js +35 -0
  69. package/dist/esm-node/cli/watch.js +41 -0
  70. package/dist/esm-node/compiled.js +33 -0
  71. package/dist/esm-node/import.js +8 -0
  72. package/dist/esm-node/index.js +3 -0
  73. package/dist/esm-node/runtime/nestedRoutes.js +112 -0
  74. package/dist/esm-node/runtime/remixRouter.js +1 -0
  75. package/dist/esm-node/runtime/router.js +1 -0
  76. package/dist/esm-node/runtime-browser/index.js +1 -0
  77. package/dist/esm-node/runtime-browser/parsed.js +17 -0
  78. package/dist/esm-node/runtime-node/index.js +5 -0
  79. package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
  80. package/dist/esm-node/runtime-node/router.js +1 -0
  81. package/dist/esm-node/runtime-node/serialize.js +6 -0
  82. package/dist/esm-node/runtime-node/storage.js +38 -0
  83. package/dist/esm-node/universal/constants.js +3 -0
  84. package/dist/esm-node/universal/formatWebpack.js +61 -0
  85. package/dist/esm-node/universal/pluginDagSort.js +50 -0
  86. package/package.json +6 -6
@@ -1,86 +1,124 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
3
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
1
5
  import os from "os";
2
6
  import path from "path";
3
7
  import { browserslist, fs, json5 } from "../../compiled";
4
8
  import { INTERNAL_CLI_PLUGINS } from "../constants";
5
9
  import { isDepExists } from "../is";
6
10
  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";
11
+ var MAX_TIMES = 5;
12
+ export function getPackageManager() {
13
+ return _getPackageManager.apply(this, arguments);
14
+ }
15
+ function _getPackageManager() {
16
+ _getPackageManager = _async_to_generator(function() {
17
+ var cwd, appDirectory, times;
18
+ var _arguments = arguments;
19
+ return _ts_generator(this, function(_state) {
20
+ switch (_state.label) {
21
+ case 0:
22
+ cwd = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : process.cwd();
23
+ appDirectory = cwd;
24
+ times = 0;
25
+ while (os.homedir() !== appDirectory && times < MAX_TIMES) {
26
+ times++;
27
+ if (fs.existsSync(path.resolve(appDirectory, "pnpm-lock.yaml"))) {
28
+ return "pnpm";
29
+ }
30
+ if (fs.existsSync(path.resolve(appDirectory, "yarn.lock"))) {
31
+ return "yarn";
32
+ }
33
+ if (fs.existsSync(path.resolve(appDirectory, "package-lock.json"))) {
34
+ return "npm";
35
+ }
36
+ appDirectory = path.join(appDirectory, "..");
37
+ }
38
+ return [
39
+ 4,
40
+ canUsePnpm()
41
+ ];
42
+ case 1:
43
+ if (_state.sent()) {
44
+ return [
45
+ 2,
46
+ "pnpm"
47
+ ];
48
+ }
49
+ return [
50
+ 4,
51
+ canUseYarn()
52
+ ];
53
+ case 2:
54
+ if (_state.sent()) {
55
+ return [
56
+ 2,
57
+ "yarn"
58
+ ];
59
+ }
60
+ return [
61
+ 2,
62
+ "npm"
63
+ ];
64
+ }
65
+ });
66
+ });
67
+ return _getPackageManager.apply(this, arguments);
31
68
  }
32
- export const getCoreJsVersion = (corejsPkgPath) => {
69
+ export var getCoreJsVersion = function(corejsPkgPath) {
33
70
  try {
34
- const { version } = fs.readJSONSync(corejsPkgPath);
35
- const [major, minor] = version.split(".");
36
- return `${major}.${minor}`;
71
+ var version = fs.readJSONSync(corejsPkgPath).version;
72
+ var _version_split = _sliced_to_array(version.split("."), 2), major = _version_split[0], minor = _version_split[1];
73
+ return "".concat(major, ".").concat(minor);
37
74
  } catch (err) {
38
75
  return "3";
39
76
  }
40
77
  };
41
- export const getAntdMajorVersion = (appDirectory) => {
78
+ export var getAntdMajorVersion = function(appDirectory) {
42
79
  try {
43
- const pkgJsonPath = require.resolve("antd/package.json", {
80
+ var pkgJsonPath = require.resolve("antd/package.json", {
44
81
  paths: [
45
82
  appDirectory
46
83
  ]
47
84
  });
48
- const { version } = require(pkgJsonPath);
85
+ var version = require(pkgJsonPath).version;
49
86
  return Number(version.split(".")[0]);
50
87
  } catch (err) {
51
88
  return null;
52
89
  }
53
90
  };
54
- export const defaults = [
91
+ export var defaults = [
55
92
  "> 0.01%",
56
93
  "not dead",
57
94
  "not op_mini all"
58
95
  ];
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
- ];
96
+ export var getBrowserslist = function(appDirectory) {
97
+ return browserslist.loadConfig({
98
+ path: appDirectory
99
+ }) || defaults;
100
+ };
101
+ export function getInternalPlugins(appDirectory) {
102
+ var internalPlugins = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : INTERNAL_CLI_PLUGINS;
103
+ return _to_consumable_array(Object.keys(internalPlugins).filter(function(name) {
104
+ var config = internalPlugins[name];
105
+ if (typeof config !== "string" && config.forced === true) {
106
+ return true;
107
+ }
108
+ return isDepExists(appDirectory, name);
109
+ }).map(function(name) {
110
+ var config = internalPlugins[name];
111
+ if (typeof config !== "string") {
112
+ return config.path;
113
+ } else {
114
+ return config;
115
+ }
116
+ }));
79
117
  }
80
- export const readTsConfig = (root) => {
118
+ export var readTsConfig = function(root) {
81
119
  return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
82
120
  };
83
- export const readTsConfigByFile = (filename) => {
84
- const content = fs.readFileSync(path.resolve(filename), "utf-8");
121
+ export var readTsConfigByFile = function(filename) {
122
+ var content = fs.readFileSync(path.resolve(filename), "utf-8");
85
123
  return json5.parse(content);
86
124
  };
@@ -1,12 +1,27 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
1
3
  import path from "path";
2
4
  import { CONFIG_FILE_EXTENSIONS } from "../constants";
3
5
  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);
6
+ export var getServerConfig = function() {
7
+ var _ref = _async_to_generator(function(appDirectory, configFile) {
8
+ var configFilePath;
9
+ return _ts_generator(this, function(_state) {
10
+ configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map(function(extension) {
11
+ return path.resolve(appDirectory, "".concat(configFile).concat(extension));
12
+ }));
13
+ return [
14
+ 2,
15
+ configFilePath
16
+ ];
17
+ });
18
+ });
19
+ return function getServerConfig2(appDirectory, configFile) {
20
+ return _ref.apply(this, arguments);
21
+ };
22
+ }();
23
+ export var getTargetDir = function(from, baseDir, targetBaseDir) {
24
+ var relativePath = path.relative(baseDir, from);
10
25
  return path.resolve(targetBaseDir, relativePath);
11
26
  };
12
27
  export * from "./data";
@@ -1,40 +1,59 @@
1
1
  import { isEmpty } from "./type";
2
- export const isSSR = (config) => {
3
- const { server } = config;
2
+ export var isSSR = function(config) {
3
+ var server = config.server;
4
4
  if (server === null || server === void 0 ? void 0 : server.ssr) {
5
5
  return true;
6
6
  }
7
7
  if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
8
- for (const name of Object.keys(server.ssrByEntries)) {
9
- if (server.ssrByEntries[name]) {
10
- return true;
8
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
9
+ try {
10
+ for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
11
+ var name = _step.value;
12
+ if (server.ssrByEntries[name]) {
13
+ return true;
14
+ }
15
+ }
16
+ } catch (err) {
17
+ _didIteratorError = true;
18
+ _iteratorError = err;
19
+ } finally {
20
+ try {
21
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
22
+ _iterator.return();
23
+ }
24
+ } finally {
25
+ if (_didIteratorError) {
26
+ throw _iteratorError;
27
+ }
11
28
  }
12
29
  }
13
30
  }
14
31
  return false;
15
32
  };
16
- export const isUseSSRBundle = (config) => {
17
- const { output } = config;
33
+ export var isUseSSRBundle = function(config) {
34
+ var output = config.output;
18
35
  if (output === null || output === void 0 ? void 0 : output.ssg) {
19
36
  return true;
20
37
  }
21
38
  return isSSR(config);
22
39
  };
23
- export const isServiceWorker = (config) => {
40
+ export var isServiceWorker = function(config) {
24
41
  var _deploy_worker;
25
- const { output, deploy } = config;
42
+ var output = config.output, deploy = config.deploy;
26
43
  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))) {
27
44
  return true;
28
45
  }
29
46
  return false;
30
47
  };
31
- export const isRouterV5 = (config) => {
48
+ export var isRouterV5 = function(config) {
32
49
  var _config_runtime, _config_runtime1, _config_runtime_router;
33
50
  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";
34
51
  };
35
- export const isSSGEntry = (config, entryName, entrypoints) => {
36
- const ssgConfig = config.output.ssg;
37
- const useSSG = isSingleEntry(entrypoints) ? 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]);
52
+ export var isSSGEntry = function(config, entryName, entrypoints) {
53
+ var ssgConfig = config.output.ssg;
54
+ var useSSG = isSingleEntry(entrypoints) ? 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]);
38
55
  return useSSG;
39
56
  };
40
- export const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
57
+ export var isSingleEntry = function(entrypoints) {
58
+ return entrypoints.length === 1 && entrypoints[0].entryName === "main";
59
+ };
@@ -1,6 +1,18 @@
1
- export const getNodeEnv = () => process.env.NODE_ENV || "development";
2
- export const isDev = () => getNodeEnv() === "development";
3
- export const isProd = () => getNodeEnv() === "production";
4
- export const isTest = () => getNodeEnv() === "test";
5
- export const isProdProfile = () => isProd() && process.argv.includes("--profile");
6
- export const isFastRefresh = () => isDev() && process.env.FAST_REFRESH !== "false";
1
+ export var getNodeEnv = function() {
2
+ return process.env.NODE_ENV || "development";
3
+ };
4
+ export var isDev = function() {
5
+ return getNodeEnv() === "development";
6
+ };
7
+ export var isProd = function() {
8
+ return getNodeEnv() === "production";
9
+ };
10
+ export var isTest = function() {
11
+ return getNodeEnv() === "test";
12
+ };
13
+ export var isProdProfile = function() {
14
+ return isProd() && process.argv.includes("--profile");
15
+ };
16
+ export var isFastRefresh = function() {
17
+ return isDev() && process.env.FAST_REFRESH !== "false";
18
+ };
@@ -1,2 +1,6 @@
1
- export const isNodeJS = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null && process.versions.electron == null;
2
- export const isBrowser = () => typeof window !== "undefined";
1
+ export var isNodeJS = function() {
2
+ return typeof process !== "undefined" && process.versions != null && process.versions.node != null && process.versions.electron == null;
3
+ };
4
+ export var isBrowser = function() {
5
+ return typeof window !== "undefined";
6
+ };
@@ -1,21 +1,24 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
1
4
  import path from "path";
2
5
  import pkgUp from "../../../compiled/pkg-up";
3
6
  import { getArgv } from "../commands";
4
7
  import { fs, minimist, semver } from "../../compiled";
5
8
  import { createDebugger } from "../common";
6
9
  import { ensureArray } from "../ensure";
7
- const debug = createDebugger("judge-depExists");
8
- export const isDepExists = (appDirectory, name) => {
9
- const pkgPath = path.resolve(appDirectory, "./package.json");
10
+ var debug = createDebugger("judge-depExists");
11
+ export var isDepExists = function(appDirectory, name) {
12
+ var pkgPath = path.resolve(appDirectory, "./package.json");
10
13
  if (!fs.existsSync(pkgPath)) {
11
- debug(`can't find package.json under: %s`, appDirectory);
14
+ debug("can't find package.json under: %s", appDirectory);
12
15
  return false;
13
16
  }
14
- const json = require(pkgPath);
15
- const { dependencies = {}, devDependencies = {} } = json;
17
+ var json = require(pkgPath);
18
+ var _json_dependencies = json.dependencies, dependencies = _json_dependencies === void 0 ? {} : _json_dependencies, _json_devDependencies = json.devDependencies, devDependencies = _json_devDependencies === void 0 ? {} : _json_devDependencies;
16
19
  return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
17
20
  };
18
- export const isPackageInstalled = (name, resolvePaths) => {
21
+ export var isPackageInstalled = function(name, resolvePaths) {
19
22
  try {
20
23
  require.resolve(name, {
21
24
  paths: ensureArray(resolvePaths)
@@ -25,49 +28,83 @@ export const isPackageInstalled = (name, resolvePaths) => {
25
28
  return false;
26
29
  }
27
30
  };
28
- export 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
- export const isWebOnly = async () => {
38
- const options = minimist(getArgv());
39
- return Boolean(options["web-only"]);
40
- };
41
- export const isBeyondReact17 = (cwd) => {
42
- const pkgPath = pkgUp.sync({
43
- cwd
31
+ export var isApiOnly = function() {
32
+ var _ref = _async_to_generator(function(appDirectory, entryDir, apiDir) {
33
+ var existApi, existSrc, options;
34
+ return _ts_generator(this, function(_state) {
35
+ switch (_state.label) {
36
+ case 0:
37
+ return [
38
+ 4,
39
+ fs.pathExists(apiDir !== null && apiDir !== void 0 ? apiDir : path.join(appDirectory, "api"))
40
+ ];
41
+ case 1:
42
+ existApi = _state.sent();
43
+ return [
44
+ 4,
45
+ fs.pathExists(path.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src"))
46
+ ];
47
+ case 2:
48
+ existSrc = _state.sent();
49
+ options = minimist(getArgv());
50
+ if (options["api-only"]) {
51
+ return [
52
+ 2,
53
+ true
54
+ ];
55
+ }
56
+ return [
57
+ 2,
58
+ existApi && !existSrc
59
+ ];
60
+ }
61
+ });
62
+ });
63
+ return function isApiOnly2(appDirectory, entryDir, apiDir) {
64
+ return _ref.apply(this, arguments);
65
+ };
66
+ }();
67
+ export var isWebOnly = function() {
68
+ var _ref = _async_to_generator(function() {
69
+ var options;
70
+ return _ts_generator(this, function(_state) {
71
+ options = minimist(getArgv());
72
+ return [
73
+ 2,
74
+ Boolean(options["web-only"])
75
+ ];
76
+ });
77
+ });
78
+ return function isWebOnly2() {
79
+ return _ref.apply(this, arguments);
80
+ };
81
+ }();
82
+ export var isBeyondReact17 = function(cwd) {
83
+ var pkgPath = pkgUp.sync({
84
+ cwd: cwd
44
85
  });
45
86
  if (!pkgPath) {
46
87
  return false;
47
88
  }
48
- const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
49
- const deps = {
50
- ...pkgInfo.devDependencies,
51
- ...pkgInfo.dependencies
52
- };
89
+ var pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
90
+ var deps = _object_spread({}, pkgInfo.devDependencies, pkgInfo.dependencies);
53
91
  if (typeof deps.react !== "string") {
54
92
  return false;
55
93
  }
56
94
  return semver.satisfies(semver.minVersion(deps.react), ">=17.0.0");
57
95
  };
58
- export const isReact18 = (cwd) => {
59
- const pkgPath = path.join(cwd, "package.json");
96
+ export var isReact18 = function(cwd) {
97
+ var pkgPath = path.join(cwd, "package.json");
60
98
  if (!fs.existsSync(pkgPath)) {
61
99
  return false;
62
100
  }
63
- const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
64
- const deps = {
65
- ...pkgInfo.devDependencies,
66
- ...pkgInfo.dependencies
67
- };
101
+ var pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
102
+ var deps = _object_spread({}, pkgInfo.devDependencies, pkgInfo.dependencies);
68
103
  if (typeof deps.react !== "string") {
69
104
  return false;
70
105
  }
71
106
  return semver.satisfies(semver.minVersion(deps.react), ">=18.0.0");
72
107
  };
73
- export const isTypescript = (root) => fs.existsSync(path.resolve(root, "./tsconfig.json"));
108
+ export var isTypescript = function(root) {
109
+ return fs.existsSync(path.resolve(root, "./tsconfig.json"));
110
+ };
@@ -22,4 +22,6 @@ 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;
25
+ export var isEmpty = function(o) {
26
+ return Object.entries(o).length === 0 && o.constructor === Object;
27
+ };
@@ -1,12 +1,17 @@
1
+ import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
+ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
4
+ import { _ as _to_array } from "@swc/helpers/_/_to_array";
5
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
6
  import chalk from "../../compiled/chalk";
2
- const LOG_LEVEL = {
7
+ var LOG_LEVEL = {
3
8
  error: 0,
4
9
  warn: 1,
5
10
  info: 2,
6
11
  debug: 3,
7
12
  log: 4
8
13
  };
9
- const LOG_TYPES = {
14
+ var LOG_TYPES = {
10
15
  error: {
11
16
  color: "red",
12
17
  label: "error",
@@ -36,12 +41,30 @@ const LOG_TYPES = {
36
41
  level: "log"
37
42
  }
38
43
  };
39
- const DEFAULT_CONFIG = {
44
+ var DEFAULT_CONFIG = {
40
45
  displayLabel: true,
41
46
  uppercaseLabel: false
42
47
  };
43
- class Logger {
44
- _log(type, message, ...args) {
48
+ var Logger = /* @__PURE__ */ function() {
49
+ "use strict";
50
+ function Logger2() {
51
+ var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
52
+ var _this = this;
53
+ _class_call_check(this, Logger2);
54
+ this.level = options.level || LOG_TYPES.log.level;
55
+ this.config = _object_spread({}, DEFAULT_CONFIG, options.config || {});
56
+ this.types = _object_spread({}, LOG_TYPES, options.types || {});
57
+ this.longestLabel = this.getLongestLabel();
58
+ Object.keys(this.types).forEach(function(type) {
59
+ _this[type] = _this._log.bind(_this, type);
60
+ });
61
+ }
62
+ var _proto = Logger2.prototype;
63
+ _proto._log = function _log(type, message) {
64
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
65
+ args[_key - 2] = arguments[_key];
66
+ }
67
+ var _console;
45
68
  if (message === void 0 || message === null) {
46
69
  console.log();
47
70
  return;
@@ -49,55 +72,43 @@ class Logger {
49
72
  if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
50
73
  return;
51
74
  }
52
- let label = "";
53
- let text = "";
54
- const logType = this.types[type];
75
+ var label = "";
76
+ var text = "";
77
+ var logType = this.types[type];
55
78
  if (this.config.displayLabel && logType.label) {
56
79
  label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
57
80
  label = label.padEnd(this.longestLabel.length);
58
81
  label = chalk.bold(logType.color ? chalk[logType.color](label) : label);
59
82
  }
60
- if (message instanceof Error) {
83
+ if (_instanceof(message, Error)) {
61
84
  if (message.stack) {
62
- const [name, ...rest] = message.stack.split("\n");
63
- text = `${name}
64
- ${chalk.grey(rest.join("\n"))}`;
85
+ var _message_stack_split = _to_array(message.stack.split("\n")), name = _message_stack_split[0], rest = _message_stack_split.slice(1);
86
+ text = "".concat(name, "\n").concat(chalk.grey(rest.join("\n")));
65
87
  } else {
66
88
  text = message.message;
67
89
  }
68
90
  } else {
69
- text = `${message}`;
91
+ text = "".concat(message);
70
92
  }
71
- const log = label.length > 0 ? `${label} ${text}` : text;
72
- console.log(log, ...args);
73
- }
74
- getLongestLabel() {
75
- let longestLabel = "";
76
- Object.keys(this.types).forEach((type) => {
77
- const { label = "" } = this.types[type];
93
+ var log = label.length > 0 ? "".concat(label, " ").concat(text) : text;
94
+ (_console = console).log.apply(_console, [
95
+ log
96
+ ].concat(_to_consumable_array(args)));
97
+ };
98
+ _proto.getLongestLabel = function getLongestLabel() {
99
+ var _this = this;
100
+ var longestLabel = "";
101
+ Object.keys(this.types).forEach(function(type) {
102
+ var _this_types_type = _this.types[type], _this_types_type_label = _this_types_type.label, label = _this_types_type_label === void 0 ? "" : _this_types_type_label;
78
103
  if (label.length > longestLabel.length) {
79
104
  longestLabel = label;
80
105
  }
81
106
  });
82
107
  return longestLabel;
83
- }
84
- constructor(options = {}) {
85
- this.level = options.level || LOG_TYPES.log.level;
86
- this.config = {
87
- ...DEFAULT_CONFIG,
88
- ...options.config || {}
89
- };
90
- this.types = {
91
- ...LOG_TYPES,
92
- ...options.types || {}
93
- };
94
- this.longestLabel = this.getLongestLabel();
95
- Object.keys(this.types).forEach((type) => {
96
- this[type] = this._log.bind(this, type);
97
- });
98
- }
99
- }
100
- const logger = new Logger();
108
+ };
109
+ return Logger2;
110
+ }();
111
+ var logger = new Logger();
101
112
  logger.Logger = Logger;
102
113
  export { Logger };
103
114
  export { logger };