@modern-js/utils 2.18.0 → 2.18.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +2 -0
- package/dist/cjs/{alias.js → cli/alias.js} +3 -3
- package/dist/cjs/{applyOptionsChain.js → cli/applyOptionsChain.js} +6 -5
- package/dist/cjs/{babel.js → cli/babel.js} +3 -3
- package/dist/cjs/cli/common.js +26 -0
- package/dist/cjs/{constants.js → cli/constants/index.js} +14 -2
- package/dist/cjs/{readTsConfig.js → cli/ensure.js} +10 -9
- package/dist/cjs/cli/fs.js +29 -0
- package/dist/cjs/{getEntryOptions.js → cli/get/config.js} +2 -2
- package/dist/cjs/cli/get/data.js +112 -0
- package/dist/cjs/cli/get/index.js +46 -0
- package/dist/cjs/cli/index.js +41 -0
- package/dist/cjs/{is/index.js → cli/is/config.js} +2 -43
- package/dist/cjs/{is/nodeEnv.js → cli/is/env.js} +3 -1
- package/dist/cjs/cli/is/index.js +22 -0
- package/dist/cjs/cli/is/project.js +92 -0
- package/dist/cjs/{is → cli/is}/type.js +3 -1
- package/dist/cjs/{logger.js → cli/logger.js} +1 -1
- package/dist/cjs/{monorepo.js → cli/monorepo.js} +1 -1
- package/dist/cjs/{nodeEnv.js → cli/package.js} +8 -1
- package/dist/cjs/{path.js → cli/path.js} +8 -2
- package/dist/cjs/{pathSerializer.js → cli/pathSerializer.js} +1 -1
- package/dist/cjs/{getPort.js → cli/port.js} +1 -1
- package/dist/cjs/{prettyInstructions.js → cli/prettyInstructions.js} +1 -2
- package/dist/cjs/{printBuildError.js → cli/print.js} +1 -1
- package/dist/cjs/{compatRequire.js → cli/require.js} +21 -3
- package/dist/cjs/{routes.js → cli/routes.js} +4 -11
- package/dist/cjs/{runtimeExports.js → cli/runtimeExports.js} +1 -1
- package/dist/cjs/cli/watch.js +61 -0
- package/dist/cjs/index.js +1 -42
- package/dist/cjs/runtime/router.js +19 -0
- package/dist/cjs/{ssr.js → runtime-node/index.js} +3 -1
- package/dist/esm/{alias.js → cli/alias.js} +2 -2
- package/dist/esm/{applyOptionsChain.js → cli/applyOptionsChain.js} +2 -1
- package/dist/esm/{babel.js → cli/babel.js} +1 -1
- package/dist/esm/cli/common.js +10 -0
- package/dist/esm/{constants.js → cli/constants/index.js} +1 -1
- package/dist/esm/{ensureAbsolutePath.js → cli/ensure.js} +8 -0
- package/dist/esm/{findExists.js → cli/fs.js} +6 -1
- package/dist/esm/{getEntryOptions.js → cli/get/config.js} +2 -2
- package/dist/esm/cli/get/data.js +86 -0
- package/dist/esm/cli/get/index.js +13 -0
- package/dist/esm/cli/index.js +24 -0
- package/dist/esm/{is/index.js → cli/is/config.js} +1 -21
- package/dist/esm/{is/nodeEnv.js → cli/is/env.js} +1 -0
- package/dist/esm/cli/is/index.js +5 -0
- package/dist/esm/cli/is/project.js +67 -0
- package/dist/esm/{is → cli/is}/type.js +1 -0
- package/dist/esm/{logger.js → cli/logger.js} +1 -1
- package/dist/esm/{monorepo.js → cli/monorepo.js} +1 -1
- package/dist/esm/{nodeEnv.js → cli/package.js} +7 -1
- package/dist/esm/{path.js → cli/path.js} +4 -1
- package/dist/esm/{pathSerializer.js → cli/pathSerializer.js} +1 -1
- package/dist/esm/{getPort.js → cli/port.js} +1 -1
- package/dist/esm/{prettyInstructions.js → cli/prettyInstructions.js} +2 -2
- package/dist/esm/{printBuildError.js → cli/print.js} +1 -1
- package/dist/esm/{compatRequire.js → cli/require.js} +18 -1
- package/dist/esm/{routes.js → cli/routes.js} +2 -2
- package/dist/esm/{runtimeExports.js → cli/runtimeExports.js} +1 -1
- package/dist/esm/{watch.js → cli/watch.js} +2 -2
- package/dist/esm/index.js +1 -42
- package/dist/esm/runtime/router.js +2 -0
- package/dist/esm/{ssr.js → runtime-node/index.js} +1 -0
- package/dist/types/{applyOptionsChain.d.ts → cli/applyOptionsChain.d.ts} +1 -1
- package/dist/types/{debug.d.ts → cli/common.d.ts} +3 -1
- package/dist/types/{constants.d.ts → cli/constants/index.d.ts} +2 -6
- package/dist/types/{ensureAbsolutePath.d.ts → cli/ensure.d.ts} +2 -1
- package/dist/types/{findExists.d.ts → cli/fs.d.ts} +2 -1
- package/dist/types/cli/get/data.d.ts +9 -0
- package/dist/types/cli/get/index.d.ts +4 -0
- package/dist/types/cli/index.d.ts +24 -0
- package/dist/types/cli/is/config.d.ts +30 -0
- package/dist/types/{is/nodeEnv.d.ts → cli/is/env.d.ts} +2 -1
- package/dist/types/cli/is/index.d.ts +5 -0
- package/dist/types/cli/is/project.d.ts +25 -0
- package/dist/types/{is → cli/is}/type.d.ts +9 -1
- package/dist/types/{logger.d.ts → cli/logger.d.ts} +1 -1
- package/dist/types/cli/package.d.ts +4 -0
- package/dist/types/{path.d.ts → cli/path.d.ts} +5 -2
- package/dist/types/{prettyInstructions.d.ts → cli/prettyInstructions.d.ts} +0 -3
- package/dist/types/{compatRequire.d.ts → cli/require.d.ts} +9 -1
- package/dist/types/cli/routes.d.ts +1 -0
- package/dist/types/{watch.d.ts → cli/watch.d.ts} +1 -1
- package/dist/types/index.d.ts +2 -43
- package/dist/types/runtime/router.d.ts +2 -0
- package/dist/types/{ssr.d.ts → runtime-node/index.d.ts} +2 -1
- package/package.json +55 -92
- package/dist/cjs/FileSizeReporter.js +0 -139
- package/dist/cjs/analyzeProject.js +0 -68
- package/dist/cjs/clearConsole.js +0 -13
- package/dist/cjs/debug.js +0 -10
- package/dist/cjs/emptyDir.js +0 -14
- package/dist/cjs/ensureAbsolutePath.js +0 -15
- package/dist/cjs/ensureArray.js +0 -16
- package/dist/cjs/findExists.js +0 -22
- package/dist/cjs/getBrowserslist.js +0 -24
- package/dist/cjs/getCoreJsVersion.js +0 -58
- package/dist/cjs/getPackageManager.js +0 -42
- package/dist/cjs/getServerConfig.js +0 -55
- package/dist/cjs/getTargetDir.js +0 -53
- package/dist/cjs/plugin.js +0 -28
- package/dist/cjs/react.js +0 -30
- package/dist/cjs/removeSlash.js +0 -19
- package/dist/cjs/resolve.js +0 -57
- package/dist/cjs/types.js +0 -4
- package/dist/cjs/version.js +0 -43
- package/dist/cjs/wait.js +0 -11
- package/dist/cjs/watch.js +0 -96
- package/dist/esm/FileSizeReporter.js +0 -121
- package/dist/esm/analyzeProject.js +0 -13
- package/dist/esm/clearConsole.js +0 -5
- package/dist/esm/debug.js +0 -2
- package/dist/esm/emptyDir.js +0 -6
- package/dist/esm/ensureArray.js +0 -8
- package/dist/esm/getBrowserslist.js +0 -9
- package/dist/esm/getCoreJsVersion.js +0 -10
- package/dist/esm/getPackageManager.js +0 -29
- package/dist/esm/getServerConfig.js +0 -7
- package/dist/esm/getTargetDir.js +0 -5
- package/dist/esm/plugin.js +0 -20
- package/dist/esm/react.js +0 -17
- package/dist/esm/readTsConfig.js +0 -9
- package/dist/esm/removeSlash.js +0 -3
- package/dist/esm/resolve.js +0 -41
- package/dist/esm/types.js +0 -1
- package/dist/esm/version.js +0 -23
- package/dist/esm/wait.js +0 -4
- package/dist/types/FileSizeReporter.d.ts +0 -16
- package/dist/types/analyzeProject.d.ts +0 -2
- package/dist/types/clearConsole.d.ts +0 -1
- package/dist/types/emptyDir.d.ts +0 -1
- package/dist/types/ensureArray.d.ts +0 -1
- package/dist/types/getBrowserslist.d.ts +0 -2
- package/dist/types/getCoreJsVersion.d.ts +0 -1
- package/dist/types/getPackageManager.d.ts +0 -1
- package/dist/types/getServerConfig.d.ts +0 -1
- package/dist/types/getTargetDir.d.ts +0 -1
- package/dist/types/is/index.d.ts +0 -58
- package/dist/types/nodeEnv.d.ts +0 -3
- package/dist/types/plugin.d.ts +0 -2
- package/dist/types/react.d.ts +0 -1
- package/dist/types/readTsConfig.d.ts +0 -2
- package/dist/types/removeSlash.d.ts +0 -3
- package/dist/types/resolve.d.ts +0 -13
- package/dist/types/routes.d.ts +0 -2
- package/dist/types/types.d.ts +0 -1
- package/dist/types/version.d.ts +0 -2
- package/dist/types/wait.d.ts +0 -2
- /package/dist/cjs/{commands.js → cli/commands.js} +0 -0
- /package/dist/cjs/{chainId.js → cli/constants/chainId.js} +0 -0
- /package/dist/cjs/{generateMetaTags.js → cli/generateMetaTags.js} +0 -0
- /package/dist/cjs/{is → cli/is}/platform.js +0 -0
- /package/dist/cjs/{testUtils.js → cli/test.js} +0 -0
- /package/dist/cjs/{universal → runtime}/nestedRoutes.js +0 -0
- /package/dist/cjs/{universal → runtime}/remixRouter.js +0 -0
- /package/dist/cjs/{runtime → runtime-browser}/index.js +0 -0
- /package/dist/cjs/{runtime → runtime-browser}/parsed.js +0 -0
- /package/dist/cjs/{universal → runtime-node}/serialize.js +0 -0
- /package/dist/cjs/{storage.js → runtime-node/storage.js} +0 -0
- /package/dist/esm/{commands.js → cli/commands.js} +0 -0
- /package/dist/esm/{chainId.js → cli/constants/chainId.js} +0 -0
- /package/dist/esm/{generateMetaTags.js → cli/generateMetaTags.js} +0 -0
- /package/dist/esm/{is → cli/is}/platform.js +0 -0
- /package/dist/esm/{testUtils.js → cli/test.js} +0 -0
- /package/dist/esm/{universal → runtime}/nestedRoutes.js +0 -0
- /package/dist/esm/{universal → runtime}/remixRouter.js +0 -0
- /package/dist/esm/{runtime → runtime-browser}/index.js +0 -0
- /package/dist/esm/{runtime → runtime-browser}/parsed.js +0 -0
- /package/dist/esm/{universal → runtime-node}/serialize.js +0 -0
- /package/dist/esm/{storage.js → runtime-node/storage.js} +0 -0
- /package/dist/types/{alias.d.ts → cli/alias.d.ts} +0 -0
- /package/dist/types/{babel.d.ts → cli/babel.d.ts} +0 -0
- /package/dist/types/{commands.d.ts → cli/commands.d.ts} +0 -0
- /package/dist/types/{chainId.d.ts → cli/constants/chainId.d.ts} +0 -0
- /package/dist/types/{generateMetaTags.d.ts → cli/generateMetaTags.d.ts} +0 -0
- /package/dist/types/{getEntryOptions.d.ts → cli/get/config.d.ts} +0 -0
- /package/dist/types/{is → cli/is}/platform.d.ts +0 -0
- /package/dist/types/{monorepo.d.ts → cli/monorepo.d.ts} +0 -0
- /package/dist/types/{pathSerializer.d.ts → cli/pathSerializer.d.ts} +0 -0
- /package/dist/types/{getPort.d.ts → cli/port.d.ts} +0 -0
- /package/dist/types/{printBuildError.d.ts → cli/print.d.ts} +0 -0
- /package/dist/types/{runtimeExports.d.ts → cli/runtimeExports.d.ts} +0 -0
- /package/dist/types/{testUtils.d.ts → cli/test.d.ts} +0 -0
- /package/dist/types/{universal → runtime}/nestedRoutes.d.ts +0 -0
- /package/dist/types/{universal → runtime}/remixRouter.d.ts +0 -0
- /package/dist/types/{runtime → runtime-browser}/index.d.ts +0 -0
- /package/dist/types/{runtime → runtime-browser}/parsed.d.ts +0 -0
- /package/dist/types/{universal → runtime-node}/serialize.d.ts +0 -0
- /package/dist/types/{storage.d.ts → runtime-node/storage.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
@@ -17,8 +17,8 @@ _export(exports, {
|
|
17
17
|
});
|
18
18
|
const _fs = /* @__PURE__ */ _interop_require_default(require("fs"));
|
19
19
|
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
20
|
-
const _compiled = require("
|
21
|
-
const
|
20
|
+
const _compiled = require("../compiled");
|
21
|
+
const _get = require("./get");
|
22
22
|
const _applyOptionsChain = require("./applyOptionsChain");
|
23
23
|
function _interop_require_default(obj) {
|
24
24
|
return obj && obj.__esModule ? obj : {
|
@@ -53,7 +53,7 @@ const getAliasConfig = (aliasOption, option) => {
|
|
53
53
|
isTsProject
|
54
54
|
};
|
55
55
|
}
|
56
|
-
const tsconfig = (0,
|
56
|
+
const tsconfig = (0, _get.readTsConfigByFile)(option.tsconfigPath);
|
57
57
|
const baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
|
58
58
|
return {
|
59
59
|
absoluteBaseUrl: baseUrl ? _path.default.join(option.appDirectory, baseUrl) : option.appDirectory,
|
@@ -6,18 +6,19 @@ Object.defineProperty(exports, "applyOptionsChain", {
|
|
6
6
|
enumerable: true,
|
7
7
|
get: () => applyOptionsChain
|
8
8
|
});
|
9
|
-
const
|
9
|
+
const _is = require("./is");
|
10
|
+
const _logger = require("./logger");
|
10
11
|
function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
|
11
12
|
if (!options) {
|
12
13
|
return defaults;
|
13
14
|
}
|
14
|
-
if ((0,
|
15
|
+
if ((0, _is.isPlainObject)(options)) {
|
15
16
|
return mergeFn(defaults, options);
|
16
|
-
} else if ((0,
|
17
|
+
} else if ((0, _is.isFunction)(options)) {
|
17
18
|
const ret = options(defaults, utils);
|
18
19
|
if (ret) {
|
19
|
-
if (!(0,
|
20
|
-
|
20
|
+
if (!(0, _is.isPlainObject)(ret)) {
|
21
|
+
_logger.logger.warn(`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`);
|
21
22
|
}
|
22
23
|
return ret;
|
23
24
|
}
|
@@ -15,7 +15,7 @@ _export(exports, {
|
|
15
15
|
});
|
16
16
|
const _path = require("path");
|
17
17
|
const _applyOptionsChain = require("./applyOptionsChain");
|
18
|
-
const
|
18
|
+
const _ensure = require("./ensure");
|
19
19
|
const _path1 = require("./path");
|
20
20
|
const formatPath = (originPath) => {
|
21
21
|
if ((0, _path.isAbsolute)(originPath)) {
|
@@ -50,7 +50,7 @@ const removePlugins = (plugins, config) => {
|
|
50
50
|
if (!config.plugins) {
|
51
51
|
return;
|
52
52
|
}
|
53
|
-
const removeList = (0,
|
53
|
+
const removeList = (0, _ensure.ensureArray)(plugins);
|
54
54
|
config.plugins = config.plugins.filter((item) => {
|
55
55
|
const name = getPluginItemName(item);
|
56
56
|
if (name) {
|
@@ -63,7 +63,7 @@ const removePresets = (presets, config) => {
|
|
63
63
|
if (!config.presets) {
|
64
64
|
return;
|
65
65
|
}
|
66
|
-
const removeList = (0,
|
66
|
+
const removeList = (0, _ensure.ensureArray)(presets);
|
67
67
|
config.presets = config.presets.filter((item) => {
|
68
68
|
const name = getPluginItemName(item);
|
69
69
|
if (name) {
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
createDebugger: () => createDebugger,
|
14
|
+
clearConsole: () => clearConsole,
|
15
|
+
wait: () => wait
|
16
|
+
});
|
17
|
+
const _debug = require("../../compiled/debug");
|
18
|
+
const createDebugger = (scope) => (0, _debug.debug)(`modern-js:${scope}`);
|
19
|
+
const clearConsole = () => {
|
20
|
+
if (process.stdout.isTTY && !process.env.DEBUG) {
|
21
|
+
process.stdout.write("\x1B[H\x1B[2J");
|
22
|
+
}
|
23
|
+
};
|
24
|
+
const wait = (time = 0) => new Promise((resolve) => {
|
25
|
+
setTimeout(resolve, time);
|
26
|
+
});
|
@@ -12,7 +12,6 @@ function _export(target, all) {
|
|
12
12
|
_export(exports, {
|
13
13
|
ROUTE_SPEC_FILE: () => ROUTE_SPEC_FILE,
|
14
14
|
MAIN_ENTRY_NAME: () => MAIN_ENTRY_NAME,
|
15
|
-
LAUNCH_EDITOR_ENDPOINT: () => LAUNCH_EDITOR_ENDPOINT,
|
16
15
|
SERVER_BUNDLE_DIRECTORY: () => SERVER_BUNDLE_DIRECTORY,
|
17
16
|
SERVER_WORKER_BUNDLE_DIRECTORY: () => SERVER_WORKER_BUNDLE_DIRECTORY,
|
18
17
|
ENTRY_NAME_PATTERN: () => ENTRY_NAME_PATTERN,
|
@@ -43,9 +42,22 @@ _export(exports, {
|
|
43
42
|
PLUGIN_SCHEMAS: () => PLUGIN_SCHEMAS,
|
44
43
|
DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS: () => DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS
|
45
44
|
});
|
45
|
+
_export_star(require("./chainId"), exports);
|
46
|
+
function _export_star(from, to) {
|
47
|
+
Object.keys(from).forEach(function(k) {
|
48
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
49
|
+
Object.defineProperty(to, k, {
|
50
|
+
enumerable: true,
|
51
|
+
get: function() {
|
52
|
+
return from[k];
|
53
|
+
}
|
54
|
+
});
|
55
|
+
}
|
56
|
+
});
|
57
|
+
return from;
|
58
|
+
}
|
46
59
|
const ROUTE_SPEC_FILE = "route.json";
|
47
60
|
const MAIN_ENTRY_NAME = "main";
|
48
|
-
const LAUNCH_EDITOR_ENDPOINT = "/__open-stack-frame-in-editor";
|
49
61
|
const SERVER_BUNDLE_DIRECTORY = "bundles";
|
50
62
|
const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
|
51
63
|
const ENTRY_NAME_PATTERN = "^[a-zA-Z0-9_-]+$";
|
@@ -10,20 +10,21 @@ function _export(target, all) {
|
|
10
10
|
});
|
11
11
|
}
|
12
12
|
_export(exports, {
|
13
|
-
|
14
|
-
|
13
|
+
ensureAbsolutePath: () => ensureAbsolutePath,
|
14
|
+
ensureArray: () => ensureArray
|
15
15
|
});
|
16
16
|
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
17
|
-
const _compiled = require("./compiled");
|
18
17
|
function _interop_require_default(obj) {
|
19
18
|
return obj && obj.__esModule ? obj : {
|
20
19
|
default: obj
|
21
20
|
};
|
22
21
|
}
|
23
|
-
const
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return
|
22
|
+
const ensureAbsolutePath = (base, filePath) => _path.default.isAbsolute(filePath) ? filePath : _path.default.resolve(base, filePath);
|
23
|
+
const ensureArray = (params) => {
|
24
|
+
if (Array.isArray(params)) {
|
25
|
+
return params;
|
26
|
+
}
|
27
|
+
return [
|
28
|
+
params
|
29
|
+
];
|
29
30
|
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
findExists: () => findExists,
|
14
|
+
emptyDir: () => emptyDir
|
15
|
+
});
|
16
|
+
const _compiled = require("../compiled");
|
17
|
+
const findExists = (files) => {
|
18
|
+
for (const file of files) {
|
19
|
+
if (_compiled.fs.existsSync(file) && _compiled.fs.statSync(file).isFile()) {
|
20
|
+
return file;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
return false;
|
24
|
+
};
|
25
|
+
const emptyDir = async (dir) => {
|
26
|
+
if (await _compiled.fs.pathExists(dir)) {
|
27
|
+
await _compiled.fs.emptyDir(dir);
|
28
|
+
}
|
29
|
+
};
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "getEntryOptions", {
|
|
6
6
|
enumerable: true,
|
7
7
|
get: () => getEntryOptions
|
8
8
|
});
|
9
|
-
const _is = require("
|
10
|
-
const _constants = require("
|
9
|
+
const _is = require("../is");
|
10
|
+
const _constants = require("../constants");
|
11
11
|
const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
|
12
12
|
if (optionsByEntries) {
|
13
13
|
let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
|
@@ -0,0 +1,112 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
getPackageManager: () => getPackageManager,
|
14
|
+
getCoreJsVersion: () => getCoreJsVersion,
|
15
|
+
getAntdMajorVersion: () => getAntdMajorVersion,
|
16
|
+
defaults: () => defaults,
|
17
|
+
getBrowserslist: () => getBrowserslist,
|
18
|
+
getInternalPlugins: () => getInternalPlugins,
|
19
|
+
readTsConfig: () => readTsConfig,
|
20
|
+
readTsConfigByFile: () => readTsConfigByFile
|
21
|
+
});
|
22
|
+
const _os = /* @__PURE__ */ _interop_require_default(require("os"));
|
23
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
24
|
+
const _compiled = require("../../compiled");
|
25
|
+
const _constants = require("../constants");
|
26
|
+
const _is = require("../is");
|
27
|
+
const _package = require("../package");
|
28
|
+
function _interop_require_default(obj) {
|
29
|
+
return obj && obj.__esModule ? obj : {
|
30
|
+
default: obj
|
31
|
+
};
|
32
|
+
}
|
33
|
+
const MAX_TIMES = 5;
|
34
|
+
async function getPackageManager(cwd = process.cwd()) {
|
35
|
+
let appDirectory = cwd;
|
36
|
+
let times = 0;
|
37
|
+
while (_os.default.homedir() !== appDirectory && times < MAX_TIMES) {
|
38
|
+
times++;
|
39
|
+
if (_compiled.fs.existsSync(_path.default.resolve(appDirectory, "pnpm-lock.yaml"))) {
|
40
|
+
return "pnpm";
|
41
|
+
}
|
42
|
+
if (_compiled.fs.existsSync(_path.default.resolve(appDirectory, "yarn.lock"))) {
|
43
|
+
return "yarn";
|
44
|
+
}
|
45
|
+
if (_compiled.fs.existsSync(_path.default.resolve(appDirectory, "package-lock.json"))) {
|
46
|
+
return "npm";
|
47
|
+
}
|
48
|
+
appDirectory = _path.default.join(appDirectory, "..");
|
49
|
+
}
|
50
|
+
if (await (0, _package.canUsePnpm)()) {
|
51
|
+
return "pnpm";
|
52
|
+
}
|
53
|
+
if (await (0, _package.canUseYarn)()) {
|
54
|
+
return "yarn";
|
55
|
+
}
|
56
|
+
return "npm";
|
57
|
+
}
|
58
|
+
const getCoreJsVersion = (corejsPkgPath) => {
|
59
|
+
try {
|
60
|
+
const { version } = _compiled.fs.readJSONSync(corejsPkgPath);
|
61
|
+
const [major, minor] = version.split(".");
|
62
|
+
return `${major}.${minor}`;
|
63
|
+
} catch (err) {
|
64
|
+
return "3";
|
65
|
+
}
|
66
|
+
};
|
67
|
+
const getAntdMajorVersion = (appDirectory) => {
|
68
|
+
try {
|
69
|
+
const pkgJsonPath = require.resolve("antd/package.json", {
|
70
|
+
paths: [
|
71
|
+
appDirectory
|
72
|
+
]
|
73
|
+
});
|
74
|
+
const { version } = require(pkgJsonPath);
|
75
|
+
return Number(version.split(".")[0]);
|
76
|
+
} catch (err) {
|
77
|
+
return null;
|
78
|
+
}
|
79
|
+
};
|
80
|
+
const defaults = [
|
81
|
+
"> 0.01%",
|
82
|
+
"not dead",
|
83
|
+
"not op_mini all"
|
84
|
+
];
|
85
|
+
const getBrowserslist = (appDirectory) => _compiled.browserslist.loadConfig({
|
86
|
+
path: appDirectory
|
87
|
+
}) || defaults;
|
88
|
+
function getInternalPlugins(appDirectory, internalPlugins = _constants.INTERNAL_CLI_PLUGINS) {
|
89
|
+
return [
|
90
|
+
...Object.keys(internalPlugins).filter((name) => {
|
91
|
+
const config = internalPlugins[name];
|
92
|
+
if (typeof config !== "string" && config.forced === true) {
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
return (0, _is.isDepExists)(appDirectory, name);
|
96
|
+
}).map((name) => {
|
97
|
+
const config = internalPlugins[name];
|
98
|
+
if (typeof config !== "string") {
|
99
|
+
return config.path;
|
100
|
+
} else {
|
101
|
+
return config;
|
102
|
+
}
|
103
|
+
})
|
104
|
+
];
|
105
|
+
}
|
106
|
+
const readTsConfig = (root) => {
|
107
|
+
return readTsConfigByFile(_path.default.resolve(root, "./tsconfig.json"));
|
108
|
+
};
|
109
|
+
const readTsConfigByFile = (filename) => {
|
110
|
+
const content = _compiled.fs.readFileSync(_path.default.resolve(filename), "utf-8");
|
111
|
+
return _compiled.json5.parse(content);
|
112
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
getServerConfig: () => getServerConfig,
|
14
|
+
getTargetDir: () => getTargetDir
|
15
|
+
});
|
16
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
17
|
+
const _constants = require("../constants");
|
18
|
+
const _fs = require("../fs");
|
19
|
+
_export_star(require("./data"), exports);
|
20
|
+
_export_star(require("./config"), exports);
|
21
|
+
function _export_star(from, to) {
|
22
|
+
Object.keys(from).forEach(function(k) {
|
23
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
24
|
+
Object.defineProperty(to, k, {
|
25
|
+
enumerable: true,
|
26
|
+
get: function() {
|
27
|
+
return from[k];
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
});
|
32
|
+
return from;
|
33
|
+
}
|
34
|
+
function _interop_require_default(obj) {
|
35
|
+
return obj && obj.__esModule ? obj : {
|
36
|
+
default: obj
|
37
|
+
};
|
38
|
+
}
|
39
|
+
const getServerConfig = async (appDirectory, configFile) => {
|
40
|
+
const configFilePath = (0, _fs.findExists)(_constants.CONFIG_FILE_EXTENSIONS.map((extension) => _path.default.resolve(appDirectory, `${configFile}${extension}`)));
|
41
|
+
return configFilePath;
|
42
|
+
};
|
43
|
+
const getTargetDir = (from, baseDir, targetBaseDir) => {
|
44
|
+
const relativePath = _path.default.relative(baseDir, from);
|
45
|
+
return _path.default.resolve(targetBaseDir, relativePath);
|
46
|
+
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
_export_star(require("./constants"), exports);
|
6
|
+
_export_star(require("./get"), exports);
|
7
|
+
_export_star(require("./is"), exports);
|
8
|
+
_export_star(require("./alias"), exports);
|
9
|
+
_export_star(require("./applyOptionsChain"), exports);
|
10
|
+
_export_star(require("./babel"), exports);
|
11
|
+
_export_star(require("./commands"), exports);
|
12
|
+
_export_star(require("./common"), exports);
|
13
|
+
_export_star(require("./ensure"), exports);
|
14
|
+
_export_star(require("./fs"), exports);
|
15
|
+
_export_star(require("./generateMetaTags"), exports);
|
16
|
+
_export_star(require("./logger"), exports);
|
17
|
+
_export_star(require("./monorepo"), exports);
|
18
|
+
_export_star(require("./package"), exports);
|
19
|
+
_export_star(require("./path"), exports);
|
20
|
+
_export_star(require("./pathSerializer"), exports);
|
21
|
+
_export_star(require("./port"), exports);
|
22
|
+
_export_star(require("./prettyInstructions"), exports);
|
23
|
+
_export_star(require("./print"), exports);
|
24
|
+
_export_star(require("./require"), exports);
|
25
|
+
_export_star(require("./routes"), exports);
|
26
|
+
_export_star(require("./runtimeExports"), exports);
|
27
|
+
_export_star(require("./test"), exports);
|
28
|
+
_export_star(require("./watch"), exports);
|
29
|
+
function _export_star(from, to) {
|
30
|
+
Object.keys(from).forEach(function(k) {
|
31
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
32
|
+
Object.defineProperty(to, k, {
|
33
|
+
enumerable: true,
|
34
|
+
get: function() {
|
35
|
+
return from[k];
|
36
|
+
}
|
37
|
+
});
|
38
|
+
}
|
39
|
+
});
|
40
|
+
return from;
|
41
|
+
}
|
@@ -10,60 +10,20 @@ function _export(target, all) {
|
|
10
10
|
});
|
11
11
|
}
|
12
12
|
_export(exports, {
|
13
|
-
isDepExists: () => isDepExists,
|
14
|
-
isTypescript: () => isTypescript,
|
15
|
-
isEmpty: () => isEmpty,
|
16
13
|
isSSR: () => isSSR,
|
17
14
|
isUseSSRBundle: () => isUseSSRBundle,
|
18
15
|
isServiceWorker: () => isServiceWorker,
|
19
|
-
isFastRefresh: () => isFastRefresh,
|
20
16
|
isRouterV5: () => isRouterV5,
|
21
17
|
isSSGEntry: () => isSSGEntry,
|
22
18
|
isSingleEntry: () => isSingleEntry
|
23
19
|
});
|
24
|
-
const
|
25
|
-
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
26
|
-
const _debug = require("../debug");
|
27
|
-
const _nodeEnv = _export_star(require("./nodeEnv"), exports);
|
28
|
-
_export_star(require("./platform"), exports);
|
29
|
-
_export_star(require("./type"), exports);
|
30
|
-
function _export_star(from, to) {
|
31
|
-
Object.keys(from).forEach(function(k) {
|
32
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
33
|
-
Object.defineProperty(to, k, {
|
34
|
-
enumerable: true,
|
35
|
-
get: function() {
|
36
|
-
return from[k];
|
37
|
-
}
|
38
|
-
});
|
39
|
-
}
|
40
|
-
});
|
41
|
-
return from;
|
42
|
-
}
|
43
|
-
function _interop_require_default(obj) {
|
44
|
-
return obj && obj.__esModule ? obj : {
|
45
|
-
default: obj
|
46
|
-
};
|
47
|
-
}
|
48
|
-
const debug = (0, _debug.createDebugger)("judge-depExists");
|
49
|
-
const isDepExists = (appDirectory, name) => {
|
50
|
-
const pkgPath = _path.default.resolve(appDirectory, "./package.json");
|
51
|
-
if (!_fs.default.existsSync(pkgPath)) {
|
52
|
-
debug(`can't find package.json under: %s`, appDirectory);
|
53
|
-
return false;
|
54
|
-
}
|
55
|
-
const json = require(pkgPath);
|
56
|
-
const { dependencies = {}, devDependencies = {} } = json;
|
57
|
-
return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
|
58
|
-
};
|
59
|
-
const isTypescript = (root) => _fs.default.existsSync(_path.default.resolve(root, "./tsconfig.json"));
|
60
|
-
const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
|
20
|
+
const _type = require("./type");
|
61
21
|
const isSSR = (config) => {
|
62
22
|
const { server } = config;
|
63
23
|
if (server === null || server === void 0 ? void 0 : server.ssr) {
|
64
24
|
return true;
|
65
25
|
}
|
66
|
-
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
|
26
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !(0, _type.isEmpty)(server.ssrByEntries)) {
|
67
27
|
for (const name of Object.keys(server.ssrByEntries)) {
|
68
28
|
if (server.ssrByEntries[name]) {
|
69
29
|
return true;
|
@@ -87,7 +47,6 @@ const isServiceWorker = (config) => {
|
|
87
47
|
}
|
88
48
|
return false;
|
89
49
|
};
|
90
|
-
const isFastRefresh = () => (0, _nodeEnv.isDev)() && process.env.FAST_REFRESH !== "false";
|
91
50
|
const isRouterV5 = (config) => {
|
92
51
|
var _config_runtime, _config_runtime1, _config_runtime_router;
|
93
52
|
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";
|
@@ -14,10 +14,12 @@ _export(exports, {
|
|
14
14
|
isDev: () => isDev,
|
15
15
|
isProd: () => isProd,
|
16
16
|
isTest: () => isTest,
|
17
|
-
isProdProfile: () => isProdProfile
|
17
|
+
isProdProfile: () => isProdProfile,
|
18
|
+
isFastRefresh: () => isFastRefresh
|
18
19
|
});
|
19
20
|
const getNodeEnv = () => process.env.NODE_ENV || "development";
|
20
21
|
const isDev = () => getNodeEnv() === "development";
|
21
22
|
const isProd = () => getNodeEnv() === "production";
|
22
23
|
const isTest = () => getNodeEnv() === "test";
|
23
24
|
const isProdProfile = () => isProd() && process.argv.includes("--profile");
|
25
|
+
const isFastRefresh = () => isDev() && process.env.FAST_REFRESH !== "false";
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
_export_star(require("./env"), exports);
|
6
|
+
_export_star(require("./platform"), exports);
|
7
|
+
_export_star(require("./type"), exports);
|
8
|
+
_export_star(require("./config"), exports);
|
9
|
+
_export_star(require("./project"), exports);
|
10
|
+
function _export_star(from, to) {
|
11
|
+
Object.keys(from).forEach(function(k) {
|
12
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
13
|
+
Object.defineProperty(to, k, {
|
14
|
+
enumerable: true,
|
15
|
+
get: function() {
|
16
|
+
return from[k];
|
17
|
+
}
|
18
|
+
});
|
19
|
+
}
|
20
|
+
});
|
21
|
+
return from;
|
22
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
|
+
for (var name in all)
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
isDepExists: () => isDepExists,
|
14
|
+
isPackageInstalled: () => isPackageInstalled,
|
15
|
+
isApiOnly: () => isApiOnly,
|
16
|
+
isWebOnly: () => isWebOnly,
|
17
|
+
isBeyondReact17: () => isBeyondReact17,
|
18
|
+
isReact18: () => isReact18,
|
19
|
+
isTypescript: () => isTypescript
|
20
|
+
});
|
21
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
22
|
+
const _commands = require("../commands");
|
23
|
+
const _compiled = require("../../compiled");
|
24
|
+
const _common = require("../common");
|
25
|
+
const _ensure = require("../ensure");
|
26
|
+
function _interop_require_default(obj) {
|
27
|
+
return obj && obj.__esModule ? obj : {
|
28
|
+
default: obj
|
29
|
+
};
|
30
|
+
}
|
31
|
+
const debug = (0, _common.createDebugger)("judge-depExists");
|
32
|
+
const isDepExists = (appDirectory, name) => {
|
33
|
+
const pkgPath = _path.default.resolve(appDirectory, "./package.json");
|
34
|
+
if (!_compiled.fs.existsSync(pkgPath)) {
|
35
|
+
debug(`can't find package.json under: %s`, appDirectory);
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
const json = require(pkgPath);
|
39
|
+
const { dependencies = {}, devDependencies = {} } = json;
|
40
|
+
return dependencies.hasOwnProperty(name) || devDependencies.hasOwnProperty(name);
|
41
|
+
};
|
42
|
+
const isPackageInstalled = (name, resolvePaths) => {
|
43
|
+
try {
|
44
|
+
require.resolve(name, {
|
45
|
+
paths: (0, _ensure.ensureArray)(resolvePaths)
|
46
|
+
});
|
47
|
+
return true;
|
48
|
+
} catch (err) {
|
49
|
+
return false;
|
50
|
+
}
|
51
|
+
};
|
52
|
+
const isApiOnly = async (appDirectory, entryDir) => {
|
53
|
+
const srcDir = _path.default.join(appDirectory, entryDir !== null && entryDir !== void 0 ? entryDir : "src");
|
54
|
+
const existSrc = await _compiled.fs.pathExists(srcDir);
|
55
|
+
const options = (0, _compiled.minimist)((0, _commands.getArgv)());
|
56
|
+
return !existSrc || Boolean(options["api-only"]);
|
57
|
+
};
|
58
|
+
const isWebOnly = async () => {
|
59
|
+
const options = (0, _compiled.minimist)((0, _commands.getArgv)());
|
60
|
+
return Boolean(options["web-only"]);
|
61
|
+
};
|
62
|
+
const isBeyondReact17 = (cwd) => {
|
63
|
+
const pkgPath = _path.default.join(cwd, "package.json");
|
64
|
+
if (!_compiled.fs.existsSync(pkgPath)) {
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
const pkgInfo = JSON.parse(_compiled.fs.readFileSync(pkgPath, "utf8"));
|
68
|
+
const deps = {
|
69
|
+
...pkgInfo.devDependencies,
|
70
|
+
...pkgInfo.dependencies
|
71
|
+
};
|
72
|
+
if (typeof deps.react !== "string") {
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
return _compiled.semver.satisfies(_compiled.semver.minVersion(deps.react), ">=17.0.0");
|
76
|
+
};
|
77
|
+
const isReact18 = (cwd) => {
|
78
|
+
const pkgPath = _path.default.join(cwd, "package.json");
|
79
|
+
if (!_compiled.fs.existsSync(pkgPath)) {
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
const pkgInfo = JSON.parse(_compiled.fs.readFileSync(pkgPath, "utf8"));
|
83
|
+
const deps = {
|
84
|
+
...pkgInfo.devDependencies,
|
85
|
+
...pkgInfo.dependencies
|
86
|
+
};
|
87
|
+
if (typeof deps.react !== "string") {
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
return _compiled.semver.satisfies(_compiled.semver.minVersion(deps.react), ">=18.0.0");
|
91
|
+
};
|
92
|
+
const isTypescript = (root) => _compiled.fs.existsSync(_path.default.resolve(root, "./tsconfig.json"));
|
@@ -17,7 +17,8 @@ _export(exports, {
|
|
17
17
|
isObject: () => isObject,
|
18
18
|
isPlainObject: () => isPlainObject,
|
19
19
|
isPromise: () => isPromise,
|
20
|
-
isRegExp: () => isRegExp
|
20
|
+
isRegExp: () => isRegExp,
|
21
|
+
isEmpty: () => isEmpty
|
21
22
|
});
|
22
23
|
function isString(str) {
|
23
24
|
return typeof str === "string";
|
@@ -43,3 +44,4 @@ function isPromise(obj) {
|
|
43
44
|
function isRegExp(obj) {
|
44
45
|
return Object.prototype.toString.call(obj) === "[object RegExp]";
|
45
46
|
}
|
47
|
+
const isEmpty = (o) => Object.entries(o).length === 0 && o.constructor === Object;
|
@@ -13,7 +13,7 @@ _export(exports, {
|
|
13
13
|
Logger: () => Logger,
|
14
14
|
logger: () => logger
|
15
15
|
});
|
16
|
-
const _chalk = /* @__PURE__ */ _interop_require_default(require("
|
16
|
+
const _chalk = /* @__PURE__ */ _interop_require_default(require("../../compiled/chalk"));
|
17
17
|
function _define_property(obj, key, value) {
|
18
18
|
if (key in obj) {
|
19
19
|
Object.defineProperty(obj, key, {
|
@@ -20,7 +20,7 @@ _export(exports, {
|
|
20
20
|
});
|
21
21
|
const _fs = /* @__PURE__ */ _interop_require_default(require("fs"));
|
22
22
|
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
23
|
-
const _compiled = require("
|
23
|
+
const _compiled = require("../compiled");
|
24
24
|
function _interop_require_default(obj) {
|
25
25
|
return obj && obj.__esModule ? obj : {
|
26
26
|
default: obj
|
@@ -10,11 +10,18 @@ function _export(target, all) {
|
|
10
10
|
});
|
11
11
|
}
|
12
12
|
_export(exports, {
|
13
|
+
getPnpmVersion: () => getPnpmVersion,
|
13
14
|
canUseNpm: () => canUseNpm,
|
14
15
|
canUseYarn: () => canUseYarn,
|
15
16
|
canUsePnpm: () => canUsePnpm
|
16
17
|
});
|
17
|
-
const _compiled = require("
|
18
|
+
const _compiled = require("../compiled");
|
19
|
+
async function getPnpmVersion() {
|
20
|
+
const { stdout } = await (0, _compiled.execa)("pnpm", [
|
21
|
+
"--version"
|
22
|
+
]);
|
23
|
+
return stdout;
|
24
|
+
}
|
18
25
|
async function canUseNpm() {
|
19
26
|
try {
|
20
27
|
await (0, _compiled.execa)("npm", [
|