@modern-js/utils 2.35.1 → 2.37.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/cli/alias.js +45 -46
- package/dist/cjs/cli/applyOptionsChain.js +30 -13
- package/dist/cjs/cli/babel.js +36 -26
- package/dist/cjs/cli/commands.js +29 -21
- package/dist/cjs/cli/common.js +29 -20
- package/dist/cjs/cli/config.js +24 -7
- package/dist/cjs/cli/constants/chainId.js +24 -7
- package/dist/cjs/cli/constants/index.js +84 -113
- package/dist/cjs/cli/ensure.js +37 -18
- package/dist/cjs/cli/fs.js +29 -19
- package/dist/cjs/cli/get/config.js +26 -9
- package/dist/cjs/cli/get/data.js +67 -54
- package/dist/cjs/cli/get/index.js +46 -25
- package/dist/cjs/cli/index.js +58 -23
- package/dist/cjs/cli/is/config.js +37 -31
- package/dist/cjs/cli/is/env.js +32 -29
- package/dist/cjs/cli/is/index.js +26 -8
- package/dist/cjs/cli/is/project.js +67 -53
- package/dist/cjs/cli/is/type.js +39 -36
- package/dist/cjs/cli/logger.js +25 -130
- package/dist/cjs/cli/monorepo.js +58 -58
- package/dist/cjs/cli/package.js +34 -26
- package/dist/cjs/cli/path.js +64 -54
- package/dist/cjs/cli/port.js +39 -13
- package/dist/cjs/cli/prettyInstructions.js +48 -29
- package/dist/cjs/cli/require.js +35 -29
- package/dist/cjs/cli/runtimeExports.js +42 -16
- package/dist/cjs/cli/watch.js +41 -22
- package/dist/cjs/compiled.js +127 -138
- package/dist/cjs/import.js +25 -15
- package/dist/cjs/index.js +24 -6
- package/dist/cjs/universal/constants.js +32 -21
- package/dist/cjs/universal/formatWebpack.js +25 -15
- package/dist/cjs/universal/pluginDagSort.js +25 -8
- package/dist/esm/cli/alias.js +10 -22
- package/dist/esm/cli/applyOptionsChain.js +4 -1
- package/dist/esm/cli/babel.js +6 -2
- package/dist/esm/cli/commands.js +10 -4
- package/dist/esm/cli/common.js +8 -3
- package/dist/esm/cli/config.js +4 -1
- package/dist/esm/cli/constants/chainId.js +4 -1
- package/dist/esm/cli/constants/index.js +62 -39
- package/dist/esm/cli/ensure.js +6 -2
- package/dist/esm/cli/fs.js +6 -2
- package/dist/esm/cli/get/config.js +4 -1
- package/dist/esm/cli/get/data.js +18 -8
- package/dist/esm/cli/get/index.js +6 -2
- package/dist/esm/cli/is/config.js +14 -6
- package/dist/esm/cli/is/env.js +12 -8
- package/dist/esm/cli/is/index.js +0 -1
- package/dist/esm/cli/is/project.js +17 -8
- package/dist/esm/cli/is/type.js +20 -9
- package/dist/esm/cli/logger.js +4 -128
- package/dist/esm/cli/monorepo.js +14 -16
- package/dist/esm/cli/package.js +10 -4
- package/dist/esm/cli/path.js +24 -11
- package/dist/esm/cli/port.js +5 -2
- package/dist/esm/cli/prettyInstructions.js +6 -2
- package/dist/esm/cli/require.js +14 -6
- package/dist/esm/cli/runtimeExports.js +6 -3
- package/dist/esm/cli/watch.js +10 -6
- package/dist/esm/compiled.js +65 -31
- package/dist/esm/import.js +6 -3
- package/dist/esm/universal/constants.js +12 -4
- package/dist/esm/universal/formatWebpack.js +5 -2
- package/dist/esm/universal/pluginDagSort.js +5 -2
- package/dist/esm-node/cli/alias.js +8 -19
- package/dist/esm-node/cli/applyOptionsChain.js +4 -1
- package/dist/esm-node/cli/babel.js +6 -2
- package/dist/esm-node/cli/commands.js +10 -4
- package/dist/esm-node/cli/common.js +8 -3
- package/dist/esm-node/cli/config.js +4 -1
- package/dist/esm-node/cli/constants/chainId.js +4 -1
- package/dist/esm-node/cli/constants/index.js +62 -39
- package/dist/esm-node/cli/ensure.js +6 -2
- package/dist/esm-node/cli/fs.js +6 -2
- package/dist/esm-node/cli/get/config.js +4 -1
- package/dist/esm-node/cli/get/data.js +18 -8
- package/dist/esm-node/cli/get/index.js +6 -2
- package/dist/esm-node/cli/is/config.js +14 -6
- package/dist/esm-node/cli/is/env.js +12 -6
- package/dist/esm-node/cli/is/index.js +0 -1
- package/dist/esm-node/cli/is/project.js +16 -7
- package/dist/esm-node/cli/is/type.js +20 -9
- package/dist/esm-node/cli/logger.js +4 -113
- package/dist/esm-node/cli/monorepo.js +14 -18
- package/dist/esm-node/cli/package.js +10 -4
- package/dist/esm-node/cli/path.js +24 -11
- package/dist/esm-node/cli/port.js +4 -1
- package/dist/esm-node/cli/prettyInstructions.js +6 -2
- package/dist/esm-node/cli/require.js +14 -6
- package/dist/esm-node/cli/runtimeExports.js +4 -1
- package/dist/esm-node/cli/watch.js +6 -2
- package/dist/esm-node/compiled.js +65 -31
- package/dist/esm-node/import.js +5 -2
- package/dist/esm-node/universal/constants.js +12 -4
- package/dist/esm-node/universal/formatWebpack.js +5 -2
- package/dist/esm-node/universal/pluginDagSort.js +5 -2
- package/dist/types/cli/alias.d.ts +0 -5
- package/dist/types/cli/constants/index.d.ts +0 -14
- package/dist/types/cli/is/env.d.ts +1 -2
- package/dist/types/cli/is/index.d.ts +0 -1
- package/dist/types/cli/logger.d.ts +1 -69
- package/dist/types/cli/monorepo.d.ts +0 -1
- package/dist/types/universal/constants.d.ts +4 -0
- package/package.json +6 -13
- package/dist/cjs/cli/is/platform.js +0 -21
- package/dist/compiled/gradient-string/index.d.ts +0 -1
- package/dist/compiled/gradient-string/index.js +0 -1
- package/dist/compiled/gradient-string/license +0 -21
- package/dist/compiled/gradient-string/package.json +0 -1
- package/dist/compiled/webpack-dev-middleware/index.js +0 -7
- package/dist/compiled/webpack-dev-middleware/license +0 -20
- package/dist/compiled/webpack-dev-middleware/package.json +0 -1
- package/dist/compiled/webpack-dev-middleware/types/index.d.ts +0 -262
- package/dist/esm/cli/is/platform.js +0 -6
- package/dist/esm-node/cli/is/platform.js +0 -2
- package/dist/types/cli/is/platform.d.ts +0 -2
package/dist/esm/cli/get/data.js
CHANGED
@@ -9,7 +9,7 @@ import { INTERNAL_CLI_PLUGINS } from "../constants";
|
|
9
9
|
import { isDepExists } from "../is";
|
10
10
|
import { canUsePnpm, canUseYarn } from "../package";
|
11
11
|
var MAX_TIMES = 5;
|
12
|
-
|
12
|
+
function getPackageManager() {
|
13
13
|
return _getPackageManager.apply(this, arguments);
|
14
14
|
}
|
15
15
|
function _getPackageManager() {
|
@@ -75,7 +75,7 @@ function _getPackageManager() {
|
|
75
75
|
});
|
76
76
|
return _getPackageManager.apply(this, arguments);
|
77
77
|
}
|
78
|
-
|
78
|
+
var getCoreJsVersion = function(corejsPkgPath) {
|
79
79
|
try {
|
80
80
|
var version = fs.readJSONSync(corejsPkgPath).version;
|
81
81
|
var _version_split = _sliced_to_array(version.split("."), 2), major = _version_split[0], minor = _version_split[1];
|
@@ -84,7 +84,7 @@ export var getCoreJsVersion = function(corejsPkgPath) {
|
|
84
84
|
return "3";
|
85
85
|
}
|
86
86
|
};
|
87
|
-
|
87
|
+
var getAntdMajorVersion = function(appDirectory) {
|
88
88
|
try {
|
89
89
|
var pkgJsonPath = require.resolve("antd/package.json", {
|
90
90
|
paths: [
|
@@ -97,17 +97,17 @@ export var getAntdMajorVersion = function(appDirectory) {
|
|
97
97
|
return null;
|
98
98
|
}
|
99
99
|
};
|
100
|
-
|
100
|
+
var defaults = [
|
101
101
|
"> 0.01%",
|
102
102
|
"not dead",
|
103
103
|
"not op_mini all"
|
104
104
|
];
|
105
|
-
|
105
|
+
var getBrowserslist = function(appDirectory) {
|
106
106
|
return browserslist.loadConfig({
|
107
107
|
path: appDirectory
|
108
108
|
}) || defaults;
|
109
109
|
};
|
110
|
-
|
110
|
+
function getInternalPlugins(appDirectory) {
|
111
111
|
var internalPlugins = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : INTERNAL_CLI_PLUGINS;
|
112
112
|
return _to_consumable_array(Object.keys(internalPlugins).filter(function(name) {
|
113
113
|
var config = internalPlugins[name];
|
@@ -124,10 +124,20 @@ export function getInternalPlugins(appDirectory) {
|
|
124
124
|
}
|
125
125
|
}));
|
126
126
|
}
|
127
|
-
|
127
|
+
var readTsConfig = function(root) {
|
128
128
|
return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
|
129
129
|
};
|
130
|
-
|
130
|
+
var readTsConfigByFile = function(filename) {
|
131
131
|
var content = fs.readFileSync(path.resolve(filename), "utf-8");
|
132
132
|
return json5.parse(content);
|
133
133
|
};
|
134
|
+
export {
|
135
|
+
defaults,
|
136
|
+
getAntdMajorVersion,
|
137
|
+
getBrowserslist,
|
138
|
+
getCoreJsVersion,
|
139
|
+
getInternalPlugins,
|
140
|
+
getPackageManager,
|
141
|
+
readTsConfig,
|
142
|
+
readTsConfigByFile
|
143
|
+
};
|
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import path from "path";
|
4
4
|
import { CONFIG_FILE_EXTENSIONS } from "../constants";
|
5
5
|
import { findExists } from "../fs";
|
6
|
-
|
6
|
+
var getServerConfig = function() {
|
7
7
|
var _ref = _async_to_generator(function(appDirectory, configFile) {
|
8
8
|
var configFilePath;
|
9
9
|
return _ts_generator(this, function(_state) {
|
@@ -20,9 +20,13 @@ export var getServerConfig = function() {
|
|
20
20
|
return _ref.apply(this, arguments);
|
21
21
|
};
|
22
22
|
}();
|
23
|
-
|
23
|
+
var getTargetDir = function(from, baseDir, targetBaseDir) {
|
24
24
|
var relativePath = path.relative(baseDir, from);
|
25
25
|
return path.resolve(targetBaseDir, relativePath);
|
26
26
|
};
|
27
27
|
export * from "./data";
|
28
28
|
export * from "./config";
|
29
|
+
export {
|
30
|
+
getServerConfig,
|
31
|
+
getTargetDir
|
32
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { MAIN_ENTRY_NAME } from "../constants";
|
2
2
|
import { isEmpty } from "./type";
|
3
|
-
|
3
|
+
var isSSR = function(config) {
|
4
4
|
var server = config.server;
|
5
5
|
if (server === null || server === void 0 ? void 0 : server.ssr) {
|
6
6
|
return true;
|
@@ -31,14 +31,14 @@ export var isSSR = function(config) {
|
|
31
31
|
}
|
32
32
|
return false;
|
33
33
|
};
|
34
|
-
|
34
|
+
var isUseSSRBundle = function(config) {
|
35
35
|
var output = config.output;
|
36
36
|
if (output === null || output === void 0 ? void 0 : output.ssg) {
|
37
37
|
return true;
|
38
38
|
}
|
39
39
|
return isSSR(config);
|
40
40
|
};
|
41
|
-
|
41
|
+
var isServiceWorker = function(config) {
|
42
42
|
var _deploy_worker;
|
43
43
|
var output = config.output, deploy = config.deploy;
|
44
44
|
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))) {
|
@@ -46,17 +46,25 @@ export var isServiceWorker = function(config) {
|
|
46
46
|
}
|
47
47
|
return false;
|
48
48
|
};
|
49
|
-
|
49
|
+
var isRouterV5 = function(config) {
|
50
50
|
var _config_runtime, _config_runtime_router, _config_runtime1;
|
51
51
|
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";
|
52
52
|
};
|
53
|
-
|
53
|
+
var isSSGEntry = function(config, entryName, entrypoints) {
|
54
54
|
var _config_source;
|
55
55
|
var ssgConfig = config.output.ssg;
|
56
56
|
var useSSG = isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[0]) === "function" || Boolean(ssgConfig === null || ssgConfig === void 0 ? void 0 : ssgConfig[entryName]);
|
57
57
|
return useSSG;
|
58
58
|
};
|
59
|
-
|
59
|
+
var isSingleEntry = function(entrypoints) {
|
60
60
|
var mainEntryName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : MAIN_ENTRY_NAME;
|
61
61
|
return entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
|
62
62
|
};
|
63
|
+
export {
|
64
|
+
isRouterV5,
|
65
|
+
isSSGEntry,
|
66
|
+
isSSR,
|
67
|
+
isServiceWorker,
|
68
|
+
isSingleEntry,
|
69
|
+
isUseSSRBundle
|
70
|
+
};
|
package/dist/esm/cli/is/env.js
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
-
|
1
|
+
var getNodeEnv = function() {
|
2
2
|
return process.env.NODE_ENV || "development";
|
3
3
|
};
|
4
|
-
|
4
|
+
var isDev = function() {
|
5
5
|
return getNodeEnv() === "development";
|
6
6
|
};
|
7
|
-
|
7
|
+
var isProd = function() {
|
8
8
|
return getNodeEnv() === "production";
|
9
9
|
};
|
10
|
-
|
10
|
+
var isTest = function() {
|
11
11
|
return getNodeEnv() === "test";
|
12
12
|
};
|
13
|
-
|
14
|
-
return
|
13
|
+
var isBrowser = function() {
|
14
|
+
return typeof window !== "undefined";
|
15
15
|
};
|
16
|
-
export
|
17
|
-
|
16
|
+
export {
|
17
|
+
getNodeEnv,
|
18
|
+
isBrowser,
|
19
|
+
isDev,
|
20
|
+
isProd,
|
21
|
+
isTest
|
18
22
|
};
|
package/dist/esm/cli/is/index.js
CHANGED
@@ -8,7 +8,7 @@ import { fs, minimist, semver } from "../../compiled";
|
|
8
8
|
import { createDebugger } from "../common";
|
9
9
|
import { ensureArray } from "../ensure";
|
10
10
|
var debug = createDebugger("judge-depExists");
|
11
|
-
|
11
|
+
var isDepExists = function(appDirectory, name) {
|
12
12
|
var pkgPath = path.resolve(appDirectory, "./package.json");
|
13
13
|
if (!fs.existsSync(pkgPath)) {
|
14
14
|
debug("can't find package.json under: %s", appDirectory);
|
@@ -18,7 +18,7 @@ export var isDepExists = function(appDirectory, name) {
|
|
18
18
|
var _json_dependencies = json.dependencies, dependencies = _json_dependencies === void 0 ? {} : _json_dependencies, _json_devDependencies = json.devDependencies, devDependencies = _json_devDependencies === void 0 ? {} : _json_devDependencies;
|
19
19
|
return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
|
20
20
|
};
|
21
|
-
|
21
|
+
var isPackageInstalled = function(name, resolvePaths) {
|
22
22
|
try {
|
23
23
|
require.resolve(name, {
|
24
24
|
paths: ensureArray(resolvePaths)
|
@@ -28,7 +28,7 @@ export var isPackageInstalled = function(name, resolvePaths) {
|
|
28
28
|
return false;
|
29
29
|
}
|
30
30
|
};
|
31
|
-
|
31
|
+
var isApiOnly = function() {
|
32
32
|
var _ref = _async_to_generator(function(appDirectory, entryDir, apiDir) {
|
33
33
|
var existApi, existSrc, options;
|
34
34
|
return _ts_generator(this, function(_state) {
|
@@ -64,7 +64,7 @@ export var isApiOnly = function() {
|
|
64
64
|
return _ref.apply(this, arguments);
|
65
65
|
};
|
66
66
|
}();
|
67
|
-
|
67
|
+
var isWebOnly = function() {
|
68
68
|
var _ref = _async_to_generator(function() {
|
69
69
|
var options;
|
70
70
|
return _ts_generator(this, function(_state) {
|
@@ -79,9 +79,9 @@ export var isWebOnly = function() {
|
|
79
79
|
return _ref.apply(this, arguments);
|
80
80
|
};
|
81
81
|
}();
|
82
|
-
|
82
|
+
var isBeyondReact17 = function(cwd) {
|
83
83
|
var pkgPath = pkgUp.sync({
|
84
|
-
cwd
|
84
|
+
cwd
|
85
85
|
});
|
86
86
|
if (!pkgPath) {
|
87
87
|
return false;
|
@@ -93,7 +93,7 @@ export var isBeyondReact17 = function(cwd) {
|
|
93
93
|
}
|
94
94
|
return semver.satisfies(semver.minVersion(deps.react), ">=17.0.0");
|
95
95
|
};
|
96
|
-
|
96
|
+
var isReact18 = function(cwd) {
|
97
97
|
var pkgPath = path.join(cwd, "package.json");
|
98
98
|
if (!fs.existsSync(pkgPath)) {
|
99
99
|
return false;
|
@@ -105,6 +105,15 @@ export var isReact18 = function(cwd) {
|
|
105
105
|
}
|
106
106
|
return semver.satisfies(semver.minVersion(deps.react), ">=18.0.0");
|
107
107
|
};
|
108
|
-
|
108
|
+
var isTypescript = function(root) {
|
109
109
|
return fs.existsSync(path.resolve(root, "./tsconfig.json"));
|
110
110
|
};
|
111
|
+
export {
|
112
|
+
isApiOnly,
|
113
|
+
isBeyondReact17,
|
114
|
+
isDepExists,
|
115
|
+
isPackageInstalled,
|
116
|
+
isReact18,
|
117
|
+
isTypescript,
|
118
|
+
isWebOnly
|
119
|
+
};
|
package/dist/esm/cli/is/type.js
CHANGED
@@ -1,27 +1,38 @@
|
|
1
|
-
|
1
|
+
function isString(str) {
|
2
2
|
return typeof str === "string";
|
3
3
|
}
|
4
|
-
|
4
|
+
function isUndefined(obj) {
|
5
5
|
return typeof obj === "undefined";
|
6
6
|
}
|
7
|
-
|
7
|
+
function isArray(obj) {
|
8
8
|
return Array.isArray(obj);
|
9
9
|
}
|
10
|
-
|
10
|
+
function isFunction(func) {
|
11
11
|
return typeof func === "function";
|
12
12
|
}
|
13
|
-
|
13
|
+
function isObject(obj) {
|
14
14
|
return obj !== null && typeof obj === "object";
|
15
15
|
}
|
16
|
-
|
16
|
+
function isPlainObject(obj) {
|
17
17
|
return isObject(obj) && Object.prototype.toString.call(obj) === "[object Object]";
|
18
18
|
}
|
19
|
-
|
19
|
+
function isPromise(obj) {
|
20
20
|
return Boolean(obj) && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
21
21
|
}
|
22
|
-
|
22
|
+
function isRegExp(obj) {
|
23
23
|
return Object.prototype.toString.call(obj) === "[object RegExp]";
|
24
24
|
}
|
25
|
-
|
25
|
+
var isEmpty = function(o) {
|
26
26
|
return Object.entries(o).length === 0 && o.constructor === Object;
|
27
27
|
};
|
28
|
+
export {
|
29
|
+
isArray,
|
30
|
+
isEmpty,
|
31
|
+
isFunction,
|
32
|
+
isObject,
|
33
|
+
isPlainObject,
|
34
|
+
isPromise,
|
35
|
+
isRegExp,
|
36
|
+
isString,
|
37
|
+
isUndefined
|
38
|
+
};
|
package/dist/esm/cli/logger.js
CHANGED
@@ -1,129 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
6
|
-
import chalk from "../../compiled/chalk";
|
7
|
-
var LOG_LEVEL = {
|
8
|
-
error: 0,
|
9
|
-
warn: 1,
|
10
|
-
info: 2,
|
11
|
-
debug: 3,
|
12
|
-
log: 4
|
1
|
+
import { logger, createLogger } from "rslog";
|
2
|
+
export {
|
3
|
+
createLogger,
|
4
|
+
logger
|
13
5
|
};
|
14
|
-
var LOG_TYPES = {
|
15
|
-
error: {
|
16
|
-
color: "red",
|
17
|
-
label: "error",
|
18
|
-
level: "error"
|
19
|
-
},
|
20
|
-
info: {
|
21
|
-
color: "cyan",
|
22
|
-
label: "info",
|
23
|
-
level: "info"
|
24
|
-
},
|
25
|
-
ready: {
|
26
|
-
color: "green",
|
27
|
-
label: "ready",
|
28
|
-
level: "info"
|
29
|
-
},
|
30
|
-
success: {
|
31
|
-
color: "green",
|
32
|
-
label: "success",
|
33
|
-
level: "info"
|
34
|
-
},
|
35
|
-
warn: {
|
36
|
-
color: "yellow",
|
37
|
-
label: "warn",
|
38
|
-
level: "warn"
|
39
|
-
},
|
40
|
-
debug: {
|
41
|
-
color: "red",
|
42
|
-
label: "debug",
|
43
|
-
level: "debug"
|
44
|
-
},
|
45
|
-
log: {
|
46
|
-
level: "log"
|
47
|
-
}
|
48
|
-
};
|
49
|
-
var DEFAULT_CONFIG = {
|
50
|
-
displayLabel: true,
|
51
|
-
uppercaseLabel: false
|
52
|
-
};
|
53
|
-
var errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
|
54
|
-
var anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
|
55
|
-
export var isErrorStackMessage = function(message) {
|
56
|
-
return errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
|
57
|
-
};
|
58
|
-
var Logger = /* @__PURE__ */ function() {
|
59
|
-
"use strict";
|
60
|
-
function Logger2() {
|
61
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
62
|
-
var _this = this;
|
63
|
-
_class_call_check(this, Logger2);
|
64
|
-
this.level = options.level || LOG_TYPES.log.level;
|
65
|
-
this.config = _object_spread({}, DEFAULT_CONFIG, options.config || {});
|
66
|
-
this.types = _object_spread({}, LOG_TYPES, options.types || {});
|
67
|
-
this.longestLabel = this.getLongestLabel();
|
68
|
-
Object.keys(this.types).forEach(function(type) {
|
69
|
-
_this[type] = _this._log.bind(_this, type);
|
70
|
-
});
|
71
|
-
}
|
72
|
-
var _proto = Logger2.prototype;
|
73
|
-
_proto._log = function _log(type, message) {
|
74
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
75
|
-
args[_key - 2] = arguments[_key];
|
76
|
-
}
|
77
|
-
var _console;
|
78
|
-
if (message === void 0 || message === null) {
|
79
|
-
console.log();
|
80
|
-
return;
|
81
|
-
}
|
82
|
-
if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
var label = "";
|
86
|
-
var text = "";
|
87
|
-
var logType = this.types[type];
|
88
|
-
if (this.config.displayLabel && logType.label) {
|
89
|
-
label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
|
90
|
-
label = label.padEnd(this.longestLabel.length);
|
91
|
-
label = chalk.bold(logType.color ? chalk[logType.color](label) : label);
|
92
|
-
}
|
93
|
-
if (_instanceof(message, Error)) {
|
94
|
-
if (message.stack) {
|
95
|
-
var _message_stack_split = _to_array(message.stack.split("\n")), name = _message_stack_split[0], rest = _message_stack_split.slice(1);
|
96
|
-
text = "".concat(name, "\n").concat(chalk.grey(rest.join("\n")));
|
97
|
-
} else {
|
98
|
-
text = message.message;
|
99
|
-
}
|
100
|
-
} else if (logType.level === "error" && typeof message === "string") {
|
101
|
-
var lines = message.split("\n");
|
102
|
-
text = lines.map(function(line) {
|
103
|
-
return isErrorStackMessage(line) ? chalk.gray(line) : line;
|
104
|
-
}).join("\n");
|
105
|
-
} else {
|
106
|
-
text = "".concat(message);
|
107
|
-
}
|
108
|
-
var log = label.length > 0 ? "".concat(label, " ").concat(text) : text;
|
109
|
-
(_console = console).log.apply(_console, [
|
110
|
-
log
|
111
|
-
].concat(_to_consumable_array(args)));
|
112
|
-
};
|
113
|
-
_proto.getLongestLabel = function getLongestLabel() {
|
114
|
-
var _this = this;
|
115
|
-
var longestLabel = "";
|
116
|
-
Object.keys(this.types).forEach(function(type) {
|
117
|
-
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;
|
118
|
-
if (label.length > longestLabel.length) {
|
119
|
-
longestLabel = label;
|
120
|
-
}
|
121
|
-
});
|
122
|
-
return longestLabel;
|
123
|
-
};
|
124
|
-
return Logger2;
|
125
|
-
}();
|
126
|
-
var logger = new Logger();
|
127
|
-
logger.Logger = Logger;
|
128
|
-
export { Logger };
|
129
|
-
export { logger };
|
package/dist/esm/cli/monorepo.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
2
1
|
import fs from "fs";
|
3
2
|
import path from "path";
|
4
3
|
import { glob, yaml } from "../compiled";
|
@@ -8,10 +7,10 @@ var WORKSPACE_FILES = {
|
|
8
7
|
PNPM: "pnpm-workspace.yaml",
|
9
8
|
LERNA: "lerna.json"
|
10
9
|
};
|
11
|
-
|
10
|
+
var isLerna = function(root) {
|
12
11
|
return fs.existsSync(path.join(root, WORKSPACE_FILES.LERNA));
|
13
12
|
};
|
14
|
-
|
13
|
+
var isYarnWorkspaces = function(root) {
|
15
14
|
var _json_workspaces;
|
16
15
|
var pkg = path.join(root, WORKSPACE_FILES.YARN);
|
17
16
|
if (!fs.existsSync(pkg)) {
|
@@ -20,22 +19,13 @@ export var isYarnWorkspaces = function(root) {
|
|
20
19
|
var json = JSON.parse(fs.readFileSync(pkg, "utf8"));
|
21
20
|
return Boolean((_json_workspaces = json.workspaces) === null || _json_workspaces === void 0 ? void 0 : _json_workspaces.packages);
|
22
21
|
};
|
23
|
-
|
22
|
+
var isPnpmWorkspaces = function(root) {
|
24
23
|
return fs.existsSync(path.join(root, WORKSPACE_FILES.PNPM));
|
25
24
|
};
|
26
|
-
|
25
|
+
var isMonorepo = function(root) {
|
27
26
|
return isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
|
28
27
|
};
|
29
|
-
|
30
|
-
var pkgJsonPath = path.join(root, "package.json");
|
31
|
-
if (!fs.existsSync(pkgJsonPath)) {
|
32
|
-
return false;
|
33
|
-
}
|
34
|
-
var json = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
35
|
-
var deps = _object_spread({}, json.dependencies || {}, json.devDependencies || {});
|
36
|
-
return Boolean(deps["@modern-js/monorepo-tools"]);
|
37
|
-
};
|
38
|
-
export var findMonorepoRoot = function(appDirectory) {
|
28
|
+
var findMonorepoRoot = function(appDirectory) {
|
39
29
|
var maxDepth = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : PACKAGE_MAX_DEPTH;
|
40
30
|
var inMonorepo = false;
|
41
31
|
for (var depth = 0; depth < maxDepth; depth++) {
|
@@ -47,7 +37,7 @@ export var findMonorepoRoot = function(appDirectory) {
|
|
47
37
|
}
|
48
38
|
return inMonorepo ? appDirectory : void 0;
|
49
39
|
};
|
50
|
-
|
40
|
+
var getMonorepoPackages = function(root) {
|
51
41
|
var packages = [];
|
52
42
|
if (isYarnWorkspaces(root)) {
|
53
43
|
var json = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
@@ -81,3 +71,11 @@ export var getMonorepoPackages = function(root) {
|
|
81
71
|
}
|
82
72
|
return [];
|
83
73
|
};
|
74
|
+
export {
|
75
|
+
findMonorepoRoot,
|
76
|
+
getMonorepoPackages,
|
77
|
+
isLerna,
|
78
|
+
isMonorepo,
|
79
|
+
isPnpmWorkspaces,
|
80
|
+
isYarnWorkspaces
|
81
|
+
};
|
package/dist/esm/cli/package.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import { execa } from "../compiled";
|
4
|
-
|
4
|
+
function getPnpmVersion() {
|
5
5
|
return _getPnpmVersion.apply(this, arguments);
|
6
6
|
}
|
7
7
|
function _getPnpmVersion() {
|
@@ -27,7 +27,7 @@ function _getPnpmVersion() {
|
|
27
27
|
});
|
28
28
|
return _getPnpmVersion.apply(this, arguments);
|
29
29
|
}
|
30
|
-
|
30
|
+
function canUseNpm() {
|
31
31
|
return _canUseNpm.apply(this, arguments);
|
32
32
|
}
|
33
33
|
function _canUseNpm() {
|
@@ -71,7 +71,7 @@ function _canUseNpm() {
|
|
71
71
|
});
|
72
72
|
return _canUseNpm.apply(this, arguments);
|
73
73
|
}
|
74
|
-
|
74
|
+
function canUseYarn() {
|
75
75
|
return _canUseYarn.apply(this, arguments);
|
76
76
|
}
|
77
77
|
function _canUseYarn() {
|
@@ -115,7 +115,7 @@ function _canUseYarn() {
|
|
115
115
|
});
|
116
116
|
return _canUseYarn.apply(this, arguments);
|
117
117
|
}
|
118
|
-
|
118
|
+
function canUsePnpm() {
|
119
119
|
return _canUsePnpm.apply(this, arguments);
|
120
120
|
}
|
121
121
|
function _canUsePnpm() {
|
@@ -159,3 +159,9 @@ function _canUsePnpm() {
|
|
159
159
|
});
|
160
160
|
return _canUsePnpm.apply(this, arguments);
|
161
161
|
}
|
162
|
+
export {
|
163
|
+
canUseNpm,
|
164
|
+
canUsePnpm,
|
165
|
+
canUseYarn,
|
166
|
+
getPnpmVersion
|
167
|
+
};
|
package/dist/esm/cli/path.js
CHANGED
@@ -3,21 +3,21 @@ import path from "path";
|
|
3
3
|
import os from "os";
|
4
4
|
import fs from "fs";
|
5
5
|
import { nanoid, upath } from "../compiled";
|
6
|
-
|
6
|
+
var isPathString = function(test) {
|
7
7
|
return path.posix.basename(test) !== test || path.win32.basename(test) !== test;
|
8
8
|
};
|
9
|
-
|
9
|
+
var isRelativePath = function(test) {
|
10
10
|
return /^\.\.?($|[\\/])/.test(test);
|
11
11
|
};
|
12
|
-
|
12
|
+
var normalizeOutputPath = function(s) {
|
13
13
|
return s.replace(/\\/g, "\\\\");
|
14
14
|
};
|
15
|
-
|
15
|
+
var normalizeToPosixPath = function(p) {
|
16
16
|
return upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, function(_, m) {
|
17
17
|
return "/".concat(m.toLowerCase());
|
18
18
|
});
|
19
19
|
};
|
20
|
-
|
20
|
+
var getTemplatePath = function(prefix) {
|
21
21
|
var _path;
|
22
22
|
var tmpRoot = fs.realpathSync(os.tmpdir());
|
23
23
|
var parts = [
|
@@ -27,7 +27,7 @@ export var getTemplatePath = function(prefix) {
|
|
27
27
|
parts.push(nanoid());
|
28
28
|
return (_path = path).resolve.apply(_path, _to_consumable_array(parts));
|
29
29
|
};
|
30
|
-
|
30
|
+
function getRealTemporaryDirectory() {
|
31
31
|
var ret = null;
|
32
32
|
try {
|
33
33
|
ret = os.tmpdir();
|
@@ -36,18 +36,31 @@ export function getRealTemporaryDirectory() {
|
|
36
36
|
}
|
37
37
|
return ret;
|
38
38
|
}
|
39
|
-
|
39
|
+
function splitPathString(str) {
|
40
40
|
return str.split(/[\\/]/);
|
41
41
|
}
|
42
|
-
|
42
|
+
var removeLeadingSlash = function(s) {
|
43
43
|
return s.replace(/^\/+/, "");
|
44
44
|
};
|
45
|
-
|
45
|
+
var removeTailSlash = function(s) {
|
46
46
|
return s.replace(/\/+$/, "");
|
47
47
|
};
|
48
|
-
|
48
|
+
var removeSlash = function(s) {
|
49
49
|
return removeLeadingSlash(removeTailSlash(s));
|
50
50
|
};
|
51
|
-
|
51
|
+
var cutNameByHyphen = function(s) {
|
52
52
|
return s.split(/[-_]/)[0];
|
53
53
|
};
|
54
|
+
export {
|
55
|
+
cutNameByHyphen,
|
56
|
+
getRealTemporaryDirectory,
|
57
|
+
getTemplatePath,
|
58
|
+
isPathString,
|
59
|
+
isRelativePath,
|
60
|
+
normalizeOutputPath,
|
61
|
+
normalizeToPosixPath,
|
62
|
+
removeLeadingSlash,
|
63
|
+
removeSlash,
|
64
|
+
removeTailSlash,
|
65
|
+
splitPathString
|
66
|
+
};
|
package/dist/esm/cli/port.js
CHANGED
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import net from "net";
|
4
4
|
import { chalk } from "../compiled";
|
5
5
|
import { logger } from "./logger";
|
6
|
-
|
6
|
+
var getPort = function() {
|
7
7
|
var _ref = _async_to_generator(function(port) {
|
8
8
|
var _ref2, _ref_tryLimits, tryLimits, _ref_strictPort, strictPort, _ref_slient, slient, original, found, attempts, e;
|
9
9
|
var _arguments = arguments;
|
@@ -42,7 +42,7 @@ export var getPort = function() {
|
|
42
42
|
server.unref();
|
43
43
|
server.on("error", reject);
|
44
44
|
server.listen({
|
45
|
-
port
|
45
|
+
port,
|
46
46
|
host: "0.0.0.0"
|
47
47
|
}, function() {
|
48
48
|
found = true;
|
@@ -91,3 +91,6 @@ export var getPort = function() {
|
|
91
91
|
return _ref.apply(this, arguments);
|
92
92
|
};
|
93
93
|
}();
|
94
|
+
export {
|
95
|
+
getPort
|
96
|
+
};
|
@@ -19,7 +19,7 @@ var getIpv4Interfaces = function() {
|
|
19
19
|
});
|
20
20
|
return ipv4Interfaces;
|
21
21
|
};
|
22
|
-
|
22
|
+
var getAddressUrls = function() {
|
23
23
|
var protocol = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "http", port = arguments.length > 1 ? arguments[1] : void 0, host = arguments.length > 2 ? arguments[2] : void 0;
|
24
24
|
var LOCAL_LABEL = "Local: ";
|
25
25
|
var NETWORK_LABEL = "Network: ";
|
@@ -50,7 +50,7 @@ export var getAddressUrls = function() {
|
|
50
50
|
return memo;
|
51
51
|
}, []);
|
52
52
|
};
|
53
|
-
|
53
|
+
var prettyInstructions = function(appContext, config) {
|
54
54
|
var _appContext_builder_context_devServer, _appContext_builder, _config_dev, _config_source;
|
55
55
|
var entrypoints = appContext.entrypoints, serverRoutes = appContext.serverRoutes, port = appContext.port, apiOnly = appContext.apiOnly, checkedEntries = appContext.checkedEntries;
|
56
56
|
var isHttps = isDev() && ((_appContext_builder = appContext.builder) === null || _appContext_builder === void 0 ? void 0 : (_appContext_builder_context_devServer = _appContext_builder.context.devServer) === null || _appContext_builder_context_devServer === void 0 ? void 0 : _appContext_builder_context_devServer.https);
|
@@ -86,3 +86,7 @@ export var prettyInstructions = function(appContext, config) {
|
|
86
86
|
}
|
87
87
|
return message;
|
88
88
|
};
|
89
|
+
export {
|
90
|
+
getAddressUrls,
|
91
|
+
prettyInstructions
|
92
|
+
};
|