@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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/universal/formatWebpack.js +0 -4
- package/dist/esm/cli/alias.js +26 -22
- package/dist/esm/cli/applyOptionsChain.js +8 -6
- package/dist/esm/cli/babel.js +50 -35
- package/dist/esm/cli/commands.js +7 -7
- package/dist/esm/cli/common.js +10 -5
- package/dist/esm/cli/constants/chainId.js +1 -1
- package/dist/esm/cli/constants/index.js +33 -37
- package/dist/esm/cli/ensure.js +4 -2
- package/dist/esm/cli/fs.js +56 -9
- package/dist/esm/cli/get/config.js +7 -7
- package/dist/esm/cli/get/data.js +93 -55
- package/dist/esm/cli/get/index.js +21 -6
- package/dist/esm/cli/is/config.js +33 -14
- package/dist/esm/cli/is/env.js +18 -6
- package/dist/esm/cli/is/platform.js +6 -2
- package/dist/esm/cli/is/project.js +73 -36
- package/dist/esm/cli/is/type.js +3 -1
- package/dist/esm/cli/logger.js +49 -38
- package/dist/esm/cli/monorepo.js +49 -36
- package/dist/esm/cli/package.js +156 -38
- package/dist/esm/cli/path.js +44 -20
- package/dist/esm/cli/pathSerializer.js +29 -15
- package/dist/esm/cli/port.js +89 -40
- package/dist/esm/cli/prettyInstructions.js +42 -31
- package/dist/esm/cli/require.js +21 -16
- package/dist/esm/cli/runtimeExports.js +21 -15
- package/dist/esm/cli/watch.js +94 -27
- package/dist/esm/compiled.js +3 -3
- package/dist/esm/import.js +4 -4
- package/dist/esm/runtime/nestedRoutes.js +42 -29
- package/dist/esm/runtime-browser/parsed.js +5 -5
- package/dist/esm/runtime-node/index.js +1 -1
- package/dist/esm/runtime-node/nestedRoutes.js +6 -4
- package/dist/esm/runtime-node/serialize.js +1 -1
- package/dist/esm/runtime-node/storage.js +12 -14
- package/dist/esm/universal/constants.js +3 -3
- package/dist/esm/universal/formatWebpack.js +20 -26
- package/dist/esm/universal/pluginDagSort.js +49 -26
- package/dist/esm-node/cli/alias.js +51 -0
- package/dist/esm-node/cli/applyOptionsChain.js +24 -0
- package/dist/esm-node/cli/babel.js +103 -0
- package/dist/esm-node/cli/commands.js +16 -0
- package/dist/esm-node/cli/common.js +10 -0
- package/dist/esm-node/cli/constants/chainId.js +180 -0
- package/dist/esm-node/cli/constants/index.js +103 -0
- package/dist/esm-node/cli/ensure.js +10 -0
- package/dist/esm-node/cli/fs.js +14 -0
- package/dist/esm-node/cli/get/config.js +16 -0
- package/dist/esm-node/cli/get/data.js +86 -0
- package/dist/esm-node/cli/get/index.js +13 -0
- package/dist/esm-node/cli/index.js +20 -0
- package/dist/esm-node/cli/is/config.js +40 -0
- package/dist/esm-node/cli/is/env.js +6 -0
- package/dist/esm-node/cli/is/index.js +5 -0
- package/dist/esm-node/cli/is/platform.js +2 -0
- package/dist/esm-node/cli/is/project.js +73 -0
- package/dist/esm-node/cli/is/type.js +25 -0
- package/dist/esm-node/cli/logger.js +103 -0
- package/dist/esm-node/cli/monorepo.js +70 -0
- package/dist/esm-node/cli/package.js +43 -0
- package/dist/esm-node/cli/path.js +49 -0
- package/dist/esm-node/cli/pathSerializer.js +46 -0
- package/dist/esm-node/cli/port.js +44 -0
- package/dist/esm-node/cli/prettyInstructions.js +77 -0
- package/dist/esm-node/cli/require.js +52 -0
- package/dist/esm-node/cli/runtimeExports.js +35 -0
- package/dist/esm-node/cli/watch.js +41 -0
- package/dist/esm-node/compiled.js +33 -0
- package/dist/esm-node/import.js +8 -0
- package/dist/esm-node/index.js +3 -0
- package/dist/esm-node/runtime/nestedRoutes.js +112 -0
- package/dist/esm-node/runtime/remixRouter.js +1 -0
- package/dist/esm-node/runtime/router.js +1 -0
- package/dist/esm-node/runtime-browser/index.js +1 -0
- package/dist/esm-node/runtime-browser/parsed.js +17 -0
- package/dist/esm-node/runtime-node/index.js +5 -0
- package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
- package/dist/esm-node/runtime-node/router.js +1 -0
- package/dist/esm-node/runtime-node/serialize.js +6 -0
- package/dist/esm-node/runtime-node/storage.js +38 -0
- package/dist/esm-node/universal/constants.js +3 -0
- package/dist/esm-node/universal/formatWebpack.js +61 -0
- package/dist/esm-node/universal/pluginDagSort.js +50 -0
- package/package.json +6 -6
package/dist/esm/cli/get/data.js
CHANGED
@@ -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
|
-
|
8
|
-
export
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
69
|
+
export var getCoreJsVersion = function(corejsPkgPath) {
|
33
70
|
try {
|
34
|
-
|
35
|
-
|
36
|
-
return
|
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
|
78
|
+
export var getAntdMajorVersion = function(appDirectory) {
|
42
79
|
try {
|
43
|
-
|
80
|
+
var pkgJsonPath = require.resolve("antd/package.json", {
|
44
81
|
paths: [
|
45
82
|
appDirectory
|
46
83
|
]
|
47
84
|
});
|
48
|
-
|
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
|
91
|
+
export var defaults = [
|
55
92
|
"> 0.01%",
|
56
93
|
"not dead",
|
57
94
|
"not op_mini all"
|
58
95
|
];
|
59
|
-
export
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
return
|
70
|
-
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
118
|
+
export var readTsConfig = function(root) {
|
81
119
|
return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
|
82
120
|
};
|
83
|
-
export
|
84
|
-
|
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
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
3
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
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
|
17
|
-
|
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
|
40
|
+
export var isServiceWorker = function(config) {
|
24
41
|
var _deploy_worker;
|
25
|
-
|
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
|
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
|
36
|
-
|
37
|
-
|
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
|
57
|
+
export var isSingleEntry = function(entrypoints) {
|
58
|
+
return entrypoints.length === 1 && entrypoints[0].entryName === "main";
|
59
|
+
};
|
package/dist/esm/cli/is/env.js
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
export
|
2
|
-
|
3
|
-
|
4
|
-
export
|
5
|
-
|
6
|
-
|
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
|
2
|
-
|
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
|
-
|
8
|
-
export
|
9
|
-
|
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(
|
14
|
+
debug("can't find package.json under: %s", appDirectory);
|
12
15
|
return false;
|
13
16
|
}
|
14
|
-
|
15
|
-
|
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
|
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
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
49
|
-
|
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
|
59
|
-
|
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
|
-
|
64
|
-
|
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
|
108
|
+
export var isTypescript = function(root) {
|
109
|
+
return fs.existsSync(path.resolve(root, "./tsconfig.json"));
|
110
|
+
};
|
package/dist/esm/cli/is/type.js
CHANGED
@@ -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
|
25
|
+
export var isEmpty = function(o) {
|
26
|
+
return Object.entries(o).length === 0 && o.constructor === Object;
|
27
|
+
};
|
package/dist/esm/cli/logger.js
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
44
|
+
var DEFAULT_CONFIG = {
|
40
45
|
displayLabel: true,
|
41
46
|
uppercaseLabel: false
|
42
47
|
};
|
43
|
-
|
44
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
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
|
83
|
+
if (_instanceof(message, Error)) {
|
61
84
|
if (message.stack) {
|
62
|
-
|
63
|
-
text =
|
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 =
|
91
|
+
text = "".concat(message);
|
70
92
|
}
|
71
|
-
|
72
|
-
console.log(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
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 };
|