@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
@@ -5,7 +5,7 @@ import { INTERNAL_CLI_PLUGINS } from "../constants";
|
|
5
5
|
import { isDepExists } from "../is";
|
6
6
|
import { canUsePnpm, canUseYarn } from "../package";
|
7
7
|
const MAX_TIMES = 5;
|
8
|
-
|
8
|
+
async function getPackageManager(cwd = process.cwd()) {
|
9
9
|
let appDirectory = cwd;
|
10
10
|
let times = 0;
|
11
11
|
while (os.homedir() !== appDirectory && times < MAX_TIMES) {
|
@@ -29,7 +29,7 @@ export async function getPackageManager(cwd = process.cwd()) {
|
|
29
29
|
}
|
30
30
|
return "npm";
|
31
31
|
}
|
32
|
-
|
32
|
+
const getCoreJsVersion = (corejsPkgPath) => {
|
33
33
|
try {
|
34
34
|
const { version } = fs.readJSONSync(corejsPkgPath);
|
35
35
|
const [major, minor] = version.split(".");
|
@@ -38,7 +38,7 @@ export const getCoreJsVersion = (corejsPkgPath) => {
|
|
38
38
|
return "3";
|
39
39
|
}
|
40
40
|
};
|
41
|
-
|
41
|
+
const getAntdMajorVersion = (appDirectory) => {
|
42
42
|
try {
|
43
43
|
const pkgJsonPath = require.resolve("antd/package.json", {
|
44
44
|
paths: [
|
@@ -51,15 +51,15 @@ export const getAntdMajorVersion = (appDirectory) => {
|
|
51
51
|
return null;
|
52
52
|
}
|
53
53
|
};
|
54
|
-
|
54
|
+
const defaults = [
|
55
55
|
"> 0.01%",
|
56
56
|
"not dead",
|
57
57
|
"not op_mini all"
|
58
58
|
];
|
59
|
-
|
59
|
+
const getBrowserslist = (appDirectory) => browserslist.loadConfig({
|
60
60
|
path: appDirectory
|
61
61
|
}) || defaults;
|
62
|
-
|
62
|
+
function getInternalPlugins(appDirectory, internalPlugins = INTERNAL_CLI_PLUGINS) {
|
63
63
|
return [
|
64
64
|
...Object.keys(internalPlugins).filter((name) => {
|
65
65
|
const config = internalPlugins[name];
|
@@ -77,10 +77,20 @@ export function getInternalPlugins(appDirectory, internalPlugins = INTERNAL_CLI_
|
|
77
77
|
})
|
78
78
|
];
|
79
79
|
}
|
80
|
-
|
80
|
+
const readTsConfig = (root) => {
|
81
81
|
return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
|
82
82
|
};
|
83
|
-
|
83
|
+
const readTsConfigByFile = (filename) => {
|
84
84
|
const content = fs.readFileSync(path.resolve(filename), "utf-8");
|
85
85
|
return json5.parse(content);
|
86
86
|
};
|
87
|
+
export {
|
88
|
+
defaults,
|
89
|
+
getAntdMajorVersion,
|
90
|
+
getBrowserslist,
|
91
|
+
getCoreJsVersion,
|
92
|
+
getInternalPlugins,
|
93
|
+
getPackageManager,
|
94
|
+
readTsConfig,
|
95
|
+
readTsConfigByFile
|
96
|
+
};
|
@@ -1,13 +1,17 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import { CONFIG_FILE_EXTENSIONS } from "../constants";
|
3
3
|
import { findExists } from "../fs";
|
4
|
-
|
4
|
+
const getServerConfig = async (appDirectory, configFile) => {
|
5
5
|
const configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(appDirectory, `${configFile}${extension}`)));
|
6
6
|
return configFilePath;
|
7
7
|
};
|
8
|
-
|
8
|
+
const getTargetDir = (from, baseDir, targetBaseDir) => {
|
9
9
|
const relativePath = path.relative(baseDir, from);
|
10
10
|
return path.resolve(targetBaseDir, relativePath);
|
11
11
|
};
|
12
12
|
export * from "./data";
|
13
13
|
export * from "./config";
|
14
|
+
export {
|
15
|
+
getServerConfig,
|
16
|
+
getTargetDir
|
17
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { MAIN_ENTRY_NAME } from "../constants";
|
2
2
|
import { isEmpty } from "./type";
|
3
|
-
|
3
|
+
const isSSR = (config) => {
|
4
4
|
const { server } = config;
|
5
5
|
if (server === null || server === void 0 ? void 0 : server.ssr) {
|
6
6
|
return true;
|
@@ -14,14 +14,14 @@ export const isSSR = (config) => {
|
|
14
14
|
}
|
15
15
|
return false;
|
16
16
|
};
|
17
|
-
|
17
|
+
const isUseSSRBundle = (config) => {
|
18
18
|
const { output } = config;
|
19
19
|
if (output === null || output === void 0 ? void 0 : output.ssg) {
|
20
20
|
return true;
|
21
21
|
}
|
22
22
|
return isSSR(config);
|
23
23
|
};
|
24
|
-
|
24
|
+
const isServiceWorker = (config) => {
|
25
25
|
var _deploy_worker;
|
26
26
|
const { output, deploy } = config;
|
27
27
|
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))) {
|
@@ -29,14 +29,22 @@ export const isServiceWorker = (config) => {
|
|
29
29
|
}
|
30
30
|
return false;
|
31
31
|
};
|
32
|
-
|
32
|
+
const isRouterV5 = (config) => {
|
33
33
|
var _config_runtime, _config_runtime_router, _config_runtime1;
|
34
34
|
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";
|
35
35
|
};
|
36
|
-
|
36
|
+
const isSSGEntry = (config, entryName, entrypoints) => {
|
37
37
|
var _config_source;
|
38
38
|
const ssgConfig = config.output.ssg;
|
39
39
|
const 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]);
|
40
40
|
return useSSG;
|
41
41
|
};
|
42
|
-
|
42
|
+
const isSingleEntry = (entrypoints, mainEntryName = MAIN_ENTRY_NAME) => entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
|
43
|
+
export {
|
44
|
+
isRouterV5,
|
45
|
+
isSSGEntry,
|
46
|
+
isSSR,
|
47
|
+
isServiceWorker,
|
48
|
+
isSingleEntry,
|
49
|
+
isUseSSRBundle
|
50
|
+
};
|
@@ -1,6 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
export
|
1
|
+
const getNodeEnv = () => process.env.NODE_ENV || "development";
|
2
|
+
const isDev = () => getNodeEnv() === "development";
|
3
|
+
const isProd = () => getNodeEnv() === "production";
|
4
|
+
const isTest = () => getNodeEnv() === "test";
|
5
|
+
const isBrowser = () => typeof window !== "undefined";
|
6
|
+
export {
|
7
|
+
getNodeEnv,
|
8
|
+
isBrowser,
|
9
|
+
isDev,
|
10
|
+
isProd,
|
11
|
+
isTest
|
12
|
+
};
|
@@ -5,7 +5,7 @@ import { fs, minimist, semver } from "../../compiled";
|
|
5
5
|
import { createDebugger } from "../common";
|
6
6
|
import { ensureArray } from "../ensure";
|
7
7
|
const debug = createDebugger("judge-depExists");
|
8
|
-
|
8
|
+
const isDepExists = (appDirectory, name) => {
|
9
9
|
const pkgPath = path.resolve(appDirectory, "./package.json");
|
10
10
|
if (!fs.existsSync(pkgPath)) {
|
11
11
|
debug(`can't find package.json under: %s`, appDirectory);
|
@@ -15,7 +15,7 @@ export const isDepExists = (appDirectory, name) => {
|
|
15
15
|
const { dependencies = {}, devDependencies = {} } = json;
|
16
16
|
return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
|
17
17
|
};
|
18
|
-
|
18
|
+
const isPackageInstalled = (name, resolvePaths) => {
|
19
19
|
try {
|
20
20
|
require.resolve(name, {
|
21
21
|
paths: ensureArray(resolvePaths)
|
@@ -25,7 +25,7 @@ export const isPackageInstalled = (name, resolvePaths) => {
|
|
25
25
|
return false;
|
26
26
|
}
|
27
27
|
};
|
28
|
-
|
28
|
+
const isApiOnly = async (appDirectory, entryDir, apiDir) => {
|
29
29
|
const existApi = await fs.pathExists(apiDir !== null && apiDir !== void 0 ? apiDir : path.join(appDirectory, "api"));
|
30
30
|
const existSrc = await fs.pathExists(path.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src"));
|
31
31
|
const options = minimist(getArgv());
|
@@ -34,11 +34,11 @@ export const isApiOnly = async (appDirectory, entryDir, apiDir) => {
|
|
34
34
|
}
|
35
35
|
return existApi && !existSrc;
|
36
36
|
};
|
37
|
-
|
37
|
+
const isWebOnly = async () => {
|
38
38
|
const options = minimist(getArgv());
|
39
39
|
return Boolean(options["web-only"]);
|
40
40
|
};
|
41
|
-
|
41
|
+
const isBeyondReact17 = (cwd) => {
|
42
42
|
const pkgPath = pkgUp.sync({
|
43
43
|
cwd
|
44
44
|
});
|
@@ -55,7 +55,7 @@ export const isBeyondReact17 = (cwd) => {
|
|
55
55
|
}
|
56
56
|
return semver.satisfies(semver.minVersion(deps.react), ">=17.0.0");
|
57
57
|
};
|
58
|
-
|
58
|
+
const isReact18 = (cwd) => {
|
59
59
|
const pkgPath = path.join(cwd, "package.json");
|
60
60
|
if (!fs.existsSync(pkgPath)) {
|
61
61
|
return false;
|
@@ -70,4 +70,13 @@ export const isReact18 = (cwd) => {
|
|
70
70
|
}
|
71
71
|
return semver.satisfies(semver.minVersion(deps.react), ">=18.0.0");
|
72
72
|
};
|
73
|
-
|
73
|
+
const isTypescript = (root) => fs.existsSync(path.resolve(root, "./tsconfig.json"));
|
74
|
+
export {
|
75
|
+
isApiOnly,
|
76
|
+
isBeyondReact17,
|
77
|
+
isDepExists,
|
78
|
+
isPackageInstalled,
|
79
|
+
isReact18,
|
80
|
+
isTypescript,
|
81
|
+
isWebOnly
|
82
|
+
};
|
@@ -1,25 +1,36 @@
|
|
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
|
+
const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
|
26
|
+
export {
|
27
|
+
isArray,
|
28
|
+
isEmpty,
|
29
|
+
isFunction,
|
30
|
+
isObject,
|
31
|
+
isPlainObject,
|
32
|
+
isPromise,
|
33
|
+
isRegExp,
|
34
|
+
isString,
|
35
|
+
isUndefined
|
36
|
+
};
|
@@ -1,114 +1,5 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
info: 2,
|
6
|
-
debug: 3,
|
7
|
-
log: 4
|
1
|
+
import { logger, createLogger } from "rslog";
|
2
|
+
export {
|
3
|
+
createLogger,
|
4
|
+
logger
|
8
5
|
};
|
9
|
-
const LOG_TYPES = {
|
10
|
-
error: {
|
11
|
-
color: "red",
|
12
|
-
label: "error",
|
13
|
-
level: "error"
|
14
|
-
},
|
15
|
-
info: {
|
16
|
-
color: "cyan",
|
17
|
-
label: "info",
|
18
|
-
level: "info"
|
19
|
-
},
|
20
|
-
ready: {
|
21
|
-
color: "green",
|
22
|
-
label: "ready",
|
23
|
-
level: "info"
|
24
|
-
},
|
25
|
-
success: {
|
26
|
-
color: "green",
|
27
|
-
label: "success",
|
28
|
-
level: "info"
|
29
|
-
},
|
30
|
-
warn: {
|
31
|
-
color: "yellow",
|
32
|
-
label: "warn",
|
33
|
-
level: "warn"
|
34
|
-
},
|
35
|
-
debug: {
|
36
|
-
color: "red",
|
37
|
-
label: "debug",
|
38
|
-
level: "debug"
|
39
|
-
},
|
40
|
-
log: {
|
41
|
-
level: "log"
|
42
|
-
}
|
43
|
-
};
|
44
|
-
const DEFAULT_CONFIG = {
|
45
|
-
displayLabel: true,
|
46
|
-
uppercaseLabel: false
|
47
|
-
};
|
48
|
-
const errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
|
49
|
-
const anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
|
50
|
-
export const isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
|
51
|
-
class Logger {
|
52
|
-
_log(type, message, ...args) {
|
53
|
-
if (message === void 0 || message === null) {
|
54
|
-
console.log();
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
|
58
|
-
return;
|
59
|
-
}
|
60
|
-
let label = "";
|
61
|
-
let text = "";
|
62
|
-
const logType = this.types[type];
|
63
|
-
if (this.config.displayLabel && logType.label) {
|
64
|
-
label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
|
65
|
-
label = label.padEnd(this.longestLabel.length);
|
66
|
-
label = chalk.bold(logType.color ? chalk[logType.color](label) : label);
|
67
|
-
}
|
68
|
-
if (message instanceof Error) {
|
69
|
-
if (message.stack) {
|
70
|
-
const [name, ...rest] = message.stack.split("\n");
|
71
|
-
text = `${name}
|
72
|
-
${chalk.grey(rest.join("\n"))}`;
|
73
|
-
} else {
|
74
|
-
text = message.message;
|
75
|
-
}
|
76
|
-
} else if (logType.level === "error" && typeof message === "string") {
|
77
|
-
const lines = message.split("\n");
|
78
|
-
text = lines.map((line) => isErrorStackMessage(line) ? chalk.gray(line) : line).join("\n");
|
79
|
-
} else {
|
80
|
-
text = `${message}`;
|
81
|
-
}
|
82
|
-
const log = label.length > 0 ? `${label} ${text}` : text;
|
83
|
-
console.log(log, ...args);
|
84
|
-
}
|
85
|
-
getLongestLabel() {
|
86
|
-
let longestLabel = "";
|
87
|
-
Object.keys(this.types).forEach((type) => {
|
88
|
-
const { label = "" } = this.types[type];
|
89
|
-
if (label.length > longestLabel.length) {
|
90
|
-
longestLabel = label;
|
91
|
-
}
|
92
|
-
});
|
93
|
-
return longestLabel;
|
94
|
-
}
|
95
|
-
constructor(options = {}) {
|
96
|
-
this.level = options.level || LOG_TYPES.log.level;
|
97
|
-
this.config = {
|
98
|
-
...DEFAULT_CONFIG,
|
99
|
-
...options.config || {}
|
100
|
-
};
|
101
|
-
this.types = {
|
102
|
-
...LOG_TYPES,
|
103
|
-
...options.types || {}
|
104
|
-
};
|
105
|
-
this.longestLabel = this.getLongestLabel();
|
106
|
-
Object.keys(this.types).forEach((type) => {
|
107
|
-
this[type] = this._log.bind(this, type);
|
108
|
-
});
|
109
|
-
}
|
110
|
-
}
|
111
|
-
const logger = new Logger();
|
112
|
-
logger.Logger = Logger;
|
113
|
-
export { Logger };
|
114
|
-
export { logger };
|
@@ -7,8 +7,8 @@ const WORKSPACE_FILES = {
|
|
7
7
|
PNPM: "pnpm-workspace.yaml",
|
8
8
|
LERNA: "lerna.json"
|
9
9
|
};
|
10
|
-
|
11
|
-
|
10
|
+
const isLerna = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.LERNA));
|
11
|
+
const isYarnWorkspaces = (root) => {
|
12
12
|
var _json_workspaces;
|
13
13
|
const pkg = path.join(root, WORKSPACE_FILES.YARN);
|
14
14
|
if (!fs.existsSync(pkg)) {
|
@@ -17,21 +17,9 @@ export const isYarnWorkspaces = (root) => {
|
|
17
17
|
const json = JSON.parse(fs.readFileSync(pkg, "utf8"));
|
18
18
|
return Boolean((_json_workspaces = json.workspaces) === null || _json_workspaces === void 0 ? void 0 : _json_workspaces.packages);
|
19
19
|
};
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
const pkgJsonPath = path.join(root, "package.json");
|
24
|
-
if (!fs.existsSync(pkgJsonPath)) {
|
25
|
-
return false;
|
26
|
-
}
|
27
|
-
const json = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
28
|
-
const deps = {
|
29
|
-
...json.dependencies || {},
|
30
|
-
...json.devDependencies || {}
|
31
|
-
};
|
32
|
-
return Boolean(deps["@modern-js/monorepo-tools"]);
|
33
|
-
};
|
34
|
-
export const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
|
20
|
+
const isPnpmWorkspaces = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.PNPM));
|
21
|
+
const isMonorepo = (root) => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
|
22
|
+
const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
|
35
23
|
let inMonorepo = false;
|
36
24
|
for (let depth = 0; depth < maxDepth; depth++) {
|
37
25
|
if (isMonorepo(appDirectory)) {
|
@@ -42,7 +30,7 @@ export const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) =>
|
|
42
30
|
}
|
43
31
|
return inMonorepo ? appDirectory : void 0;
|
44
32
|
};
|
45
|
-
|
33
|
+
const getMonorepoPackages = (root) => {
|
46
34
|
let packages = [];
|
47
35
|
if (isYarnWorkspaces(root)) {
|
48
36
|
const json = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
@@ -68,3 +56,11 @@ export const getMonorepoPackages = (root) => {
|
|
68
56
|
}
|
69
57
|
return [];
|
70
58
|
};
|
59
|
+
export {
|
60
|
+
findMonorepoRoot,
|
61
|
+
getMonorepoPackages,
|
62
|
+
isLerna,
|
63
|
+
isMonorepo,
|
64
|
+
isPnpmWorkspaces,
|
65
|
+
isYarnWorkspaces
|
66
|
+
};
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { execa } from "../compiled";
|
2
|
-
|
2
|
+
async function getPnpmVersion() {
|
3
3
|
const { stdout } = await execa("pnpm", [
|
4
4
|
"--version"
|
5
5
|
]);
|
6
6
|
return stdout;
|
7
7
|
}
|
8
|
-
|
8
|
+
async function canUseNpm() {
|
9
9
|
try {
|
10
10
|
await execa("npm", [
|
11
11
|
"--version"
|
@@ -17,7 +17,7 @@ export async function canUseNpm() {
|
|
17
17
|
return false;
|
18
18
|
}
|
19
19
|
}
|
20
|
-
|
20
|
+
async function canUseYarn() {
|
21
21
|
try {
|
22
22
|
await execa("yarn", [
|
23
23
|
"--version"
|
@@ -29,7 +29,7 @@ export async function canUseYarn() {
|
|
29
29
|
return false;
|
30
30
|
}
|
31
31
|
}
|
32
|
-
|
32
|
+
async function canUsePnpm() {
|
33
33
|
try {
|
34
34
|
await execa("pnpm", [
|
35
35
|
"--version"
|
@@ -41,3 +41,9 @@ export async function canUsePnpm() {
|
|
41
41
|
return false;
|
42
42
|
}
|
43
43
|
}
|
44
|
+
export {
|
45
|
+
canUseNpm,
|
46
|
+
canUsePnpm,
|
47
|
+
canUseYarn,
|
48
|
+
getPnpmVersion
|
49
|
+
};
|
@@ -2,11 +2,11 @@ import path from "path";
|
|
2
2
|
import os from "os";
|
3
3
|
import fs from "fs";
|
4
4
|
import { nanoid, upath } from "../compiled";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
const isPathString = (test) => path.posix.basename(test) !== test || path.win32.basename(test) !== test;
|
6
|
+
const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
|
7
|
+
const normalizeOutputPath = (s) => s.replace(/\\/g, "\\\\");
|
8
|
+
const normalizeToPosixPath = (p) => upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
|
9
|
+
const getTemplatePath = (prefix) => {
|
10
10
|
const tmpRoot = fs.realpathSync(os.tmpdir());
|
11
11
|
const parts = [
|
12
12
|
tmpRoot
|
@@ -15,7 +15,7 @@ export const getTemplatePath = (prefix) => {
|
|
15
15
|
parts.push(nanoid());
|
16
16
|
return path.resolve(...parts);
|
17
17
|
};
|
18
|
-
|
18
|
+
function getRealTemporaryDirectory() {
|
19
19
|
let ret = null;
|
20
20
|
try {
|
21
21
|
ret = os.tmpdir();
|
@@ -24,12 +24,25 @@ export function getRealTemporaryDirectory() {
|
|
24
24
|
}
|
25
25
|
return ret;
|
26
26
|
}
|
27
|
-
|
27
|
+
function splitPathString(str) {
|
28
28
|
return str.split(/[\\/]/);
|
29
29
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
|
31
|
+
const removeTailSlash = (s) => s.replace(/\/+$/, "");
|
32
|
+
const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
|
33
|
+
const cutNameByHyphen = (s) => {
|
34
34
|
return s.split(/[-_]/)[0];
|
35
35
|
};
|
36
|
+
export {
|
37
|
+
cutNameByHyphen,
|
38
|
+
getRealTemporaryDirectory,
|
39
|
+
getTemplatePath,
|
40
|
+
isPathString,
|
41
|
+
isRelativePath,
|
42
|
+
normalizeOutputPath,
|
43
|
+
normalizeToPosixPath,
|
44
|
+
removeLeadingSlash,
|
45
|
+
removeSlash,
|
46
|
+
removeTailSlash,
|
47
|
+
splitPathString
|
48
|
+
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import net from "net";
|
2
2
|
import { chalk } from "../compiled";
|
3
3
|
import { logger } from "./logger";
|
4
|
-
|
4
|
+
const getPort = async (port, { tryLimits = 20, strictPort = false, slient = false } = {}) => {
|
5
5
|
if (typeof port === "string") {
|
6
6
|
port = parseInt(port, 10);
|
7
7
|
}
|
@@ -42,3 +42,6 @@ export const getPort = async (port, { tryLimits = 20, strictPort = false, slient
|
|
42
42
|
}
|
43
43
|
return port;
|
44
44
|
};
|
45
|
+
export {
|
46
|
+
getPort
|
47
|
+
};
|
@@ -16,7 +16,7 @@ const getIpv4Interfaces = () => {
|
|
16
16
|
});
|
17
17
|
return ipv4Interfaces;
|
18
18
|
};
|
19
|
-
|
19
|
+
const getAddressUrls = (protocol = "http", port, host) => {
|
20
20
|
const LOCAL_LABEL = "Local: ";
|
21
21
|
const NETWORK_LABEL = "Network: ";
|
22
22
|
const isLocalhost = (url) => url === null || url === void 0 ? void 0 : url.includes("localhost");
|
@@ -44,7 +44,7 @@ export const getAddressUrls = (protocol = "http", port, host) => {
|
|
44
44
|
return memo;
|
45
45
|
}, []);
|
46
46
|
};
|
47
|
-
|
47
|
+
const prettyInstructions = (appContext, config) => {
|
48
48
|
var _appContext_builder_context_devServer, _appContext_builder, _config_dev, _config_source;
|
49
49
|
const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
|
50
50
|
const 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);
|
@@ -73,3 +73,7 @@ export const prettyInstructions = (appContext, config) => {
|
|
73
73
|
}
|
74
74
|
return message;
|
75
75
|
};
|
76
|
+
export {
|
77
|
+
getAddressUrls,
|
78
|
+
prettyInstructions
|
79
|
+
};
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { findExists } from "./fs";
|
2
|
-
|
2
|
+
const compatRequire = (filePath, interop = true) => {
|
3
3
|
const mod = require(filePath);
|
4
4
|
const rtnESMDefault = interop && (mod === null || mod === void 0 ? void 0 : mod.__esModule);
|
5
5
|
return rtnESMDefault ? mod.default : mod;
|
6
6
|
};
|
7
|
-
|
8
|
-
|
7
|
+
const dynamicImport = new Function("modulePath", "return import(modulePath)");
|
8
|
+
const requireExistModule = (filename, opt) => {
|
9
9
|
const final = {
|
10
10
|
extensions: [
|
11
11
|
".ts",
|
@@ -20,12 +20,12 @@ export const requireExistModule = (filename, opt) => {
|
|
20
20
|
}
|
21
21
|
return compatRequire(exist, final.interop);
|
22
22
|
};
|
23
|
-
|
23
|
+
const cleanRequireCache = (filelist) => {
|
24
24
|
filelist.forEach((filepath) => {
|
25
25
|
delete require.cache[filepath];
|
26
26
|
});
|
27
27
|
};
|
28
|
-
|
28
|
+
function deleteRequireCache(path) {
|
29
29
|
if (require.cache[path]) {
|
30
30
|
delete require.cache[path];
|
31
31
|
}
|
@@ -33,7 +33,7 @@ export function deleteRequireCache(path) {
|
|
33
33
|
module.children = module.children.filter((item) => item.filename !== path);
|
34
34
|
}
|
35
35
|
}
|
36
|
-
|
36
|
+
const tryResolve = (name, resolvePath) => {
|
37
37
|
let filePath = "";
|
38
38
|
try {
|
39
39
|
filePath = require.resolve(name, {
|
@@ -50,3 +50,11 @@ export const tryResolve = (name, resolvePath) => {
|
|
50
50
|
}
|
51
51
|
return filePath;
|
52
52
|
};
|
53
|
+
export {
|
54
|
+
cleanRequireCache,
|
55
|
+
compatRequire,
|
56
|
+
deleteRequireCache,
|
57
|
+
dynamicImport,
|
58
|
+
requireExistModule,
|
59
|
+
tryResolve
|
60
|
+
};
|
@@ -14,7 +14,7 @@ const memo = (fn) => {
|
|
14
14
|
return res;
|
15
15
|
};
|
16
16
|
};
|
17
|
-
|
17
|
+
const createRuntimeExportsUtils = memo((pwd = "", namespace = "index") => {
|
18
18
|
const entryExportFile = path.join(pwd, `.runtime-exports/${namespace}.js`);
|
19
19
|
const addExport = (statement) => {
|
20
20
|
statement = normalizeOutputPath(statement);
|
@@ -33,3 +33,6 @@ export const createRuntimeExportsUtils = memo((pwd = "", namespace = "index") =>
|
|
33
33
|
getPath
|
34
34
|
};
|
35
35
|
});
|
36
|
+
export {
|
37
|
+
createRuntimeExportsUtils
|
38
|
+
};
|