@modern-js/utils 2.35.0 → 2.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/alias.js +48 -49
- 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 +27 -10
- package/dist/cjs/cli/constants/index.js +86 -104
- 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 +45 -41
- 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 -125
- 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 +50 -34
- package/dist/cjs/cli/require.js +36 -31
- 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 +29 -21
- package/dist/cjs/universal/formatWebpack.js +28 -18
- package/dist/cjs/universal/pluginDagSort.js +25 -8
- package/dist/esm/cli/alias.js +13 -25
- 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 +7 -4
- package/dist/esm/cli/constants/index.js +64 -31
- 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 +23 -17
- 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 -123
- 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 +6 -3
- package/dist/esm/cli/prettyInstructions.js +8 -5
- package/dist/esm/cli/require.js +15 -8
- 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 +10 -4
- package/dist/esm/universal/formatWebpack.js +8 -5
- package/dist/esm/universal/pluginDagSort.js +5 -2
- package/dist/esm-node/cli/alias.js +11 -22
- 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 +7 -4
- package/dist/esm-node/cli/constants/index.js +64 -31
- 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 +23 -17
- 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 -108
- 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 +5 -2
- package/dist/esm-node/cli/prettyInstructions.js +8 -7
- package/dist/esm-node/cli/require.js +15 -8
- 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 +10 -4
- package/dist/esm-node/universal/formatWebpack.js +8 -5
- package/dist/esm-node/universal/pluginDagSort.js +5 -2
- package/dist/types/cli/alias.d.ts +0 -5
- package/dist/types/cli/constants/chainId.d.ts +2 -2
- 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 -64
- package/dist/types/cli/monorepo.d.ts +0 -1
- package/package.json +6 -84
- package/dist/cjs/cli/is/platform.js +0 -21
- package/dist/cjs/runtime/nestedRoutes.js +0 -149
- package/dist/cjs/runtime/remixRouter.js +0 -6
- package/dist/cjs/runtime/router.js +0 -6
- package/dist/cjs/runtime-browser/index.js +0 -6
- package/dist/cjs/runtime-browser/parsed.js +0 -28
- package/dist/cjs/runtime-node/index.js +0 -28
- package/dist/cjs/runtime-node/loaderContext/createLoaderCtx.js +0 -34
- package/dist/cjs/runtime-node/loaderContext/createRequestCtx.js +0 -38
- package/dist/cjs/runtime-node/loaderContext/index.js +0 -22
- package/dist/cjs/runtime-node/nestedRoutes.js +0 -28
- package/dist/cjs/runtime-node/router.js +0 -6
- package/dist/cjs/runtime-node/serialize.js +0 -17
- package/dist/cjs/runtime-node/storage.js +0 -48
- package/dist/cjs/universal/time.js +0 -38
- 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/runtime/nestedRoutes.js +0 -163
- package/dist/esm/runtime/remixRouter.js +0 -1
- package/dist/esm/runtime/router.js +0 -1
- package/dist/esm/runtime-browser/index.js +0 -1
- package/dist/esm/runtime-browser/parsed.js +0 -18
- package/dist/esm/runtime-node/index.js +0 -6
- package/dist/esm/runtime-node/loaderContext/createLoaderCtx.js +0 -20
- package/dist/esm/runtime-node/loaderContext/createRequestCtx.js +0 -24
- package/dist/esm/runtime-node/loaderContext/index.js +0 -3
- package/dist/esm/runtime-node/nestedRoutes.js +0 -20
- package/dist/esm/runtime-node/router.js +0 -1
- package/dist/esm/runtime-node/serialize.js +0 -6
- package/dist/esm/runtime-node/storage.js +0 -36
- package/dist/esm/universal/time.js +0 -29
- package/dist/esm-node/cli/is/platform.js +0 -2
- package/dist/esm-node/runtime/nestedRoutes.js +0 -129
- package/dist/esm-node/runtime/remixRouter.js +0 -1
- package/dist/esm-node/runtime/router.js +0 -1
- package/dist/esm-node/runtime-browser/index.js +0 -1
- package/dist/esm-node/runtime-browser/parsed.js +0 -18
- package/dist/esm-node/runtime-node/index.js +0 -6
- package/dist/esm-node/runtime-node/loaderContext/createLoaderCtx.js +0 -15
- package/dist/esm-node/runtime-node/loaderContext/createRequestCtx.js +0 -19
- package/dist/esm-node/runtime-node/loaderContext/index.js +0 -3
- package/dist/esm-node/runtime-node/nestedRoutes.js +0 -18
- package/dist/esm-node/runtime-node/router.js +0 -1
- package/dist/esm-node/runtime-node/serialize.js +0 -6
- package/dist/esm-node/runtime-node/storage.js +0 -38
- package/dist/esm-node/universal/time.js +0 -28
- package/dist/types/cli/is/platform.d.ts +0 -2
- package/dist/types/runtime/nestedRoutes.d.ts +0 -13
- package/dist/types/runtime/remixRouter.d.ts +0 -1
- package/dist/types/runtime/router.d.ts +0 -1
- package/dist/types/runtime-browser/index.d.ts +0 -1
- package/dist/types/runtime-browser/parsed.d.ts +0 -1
- package/dist/types/runtime-node/index.d.ts +0 -10
- package/dist/types/runtime-node/loaderContext/createLoaderCtx.d.ts +0 -7
- package/dist/types/runtime-node/loaderContext/createRequestCtx.d.ts +0 -7
- package/dist/types/runtime-node/loaderContext/index.d.ts +0 -4
- package/dist/types/runtime-node/nestedRoutes.d.ts +0 -3
- package/dist/types/runtime-node/router.d.ts +0 -1
- package/dist/types/runtime-node/serialize.d.ts +0 -1
- package/dist/types/runtime-node/storage.d.ts +0 -5
- package/dist/types/universal/time.d.ts +0 -1
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
const ROUTE_SPEC_FILE = "route.json";
|
|
2
|
+
const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
|
|
3
|
+
const MAIN_ENTRY_NAME = "main";
|
|
4
|
+
const SERVER_BUNDLE_DIRECTORY = "bundles";
|
|
5
|
+
const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
|
|
6
|
+
const ENTRY_NAME_PATTERN = "^[a-zA-Z0-9_-]+$";
|
|
7
|
+
const SERVER_RENDER_FUNCTION_NAME = "serverRender";
|
|
8
|
+
const LOADABLE_STATS_FILE = "loadable-stats.json";
|
|
9
|
+
const API_DIR = "api";
|
|
10
|
+
const SERVER_DIR = "server";
|
|
11
|
+
const SHARED_DIR = "shared";
|
|
12
|
+
const CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
|
|
13
|
+
const CONFIG_FILE_EXTENSIONS = [
|
|
14
14
|
".js",
|
|
15
15
|
".ts",
|
|
16
16
|
".mjs"
|
|
17
17
|
];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const OUTPUT_CONFIG_FILE = "modern.config.json";
|
|
19
|
+
const DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
|
|
20
|
+
const ROUTE_MANIFEST_FILE = "routes-manifest.json";
|
|
21
|
+
const LOADER_ROUTES_DIR = `loader-routes`;
|
|
22
|
+
const DEFAULT_DEV_HOST = "0.0.0.0";
|
|
23
|
+
const INTERNAL_APP_TOOLS_PLUGINS = {
|
|
24
24
|
"@modern-js/app-tools": "@modern-js/app-tools/cli",
|
|
25
25
|
"@modern-js/plugin-proxy": "@modern-js/plugin-proxy/cli",
|
|
26
26
|
"@modern-js/plugin-ssg": "@modern-js/plugin-ssg/cli",
|
|
@@ -36,10 +36,10 @@ export const INTERNAL_APP_TOOLS_PLUGINS = {
|
|
|
36
36
|
// legacy router (inner react-router-dom v5)
|
|
37
37
|
"@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
|
|
38
38
|
};
|
|
39
|
-
|
|
39
|
+
const INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
|
|
40
40
|
"@modern-js/runtime": "@modern-js/runtime/cli"
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
const INTERNAL_MODULE_TOOLS_PLUGINS = {
|
|
43
43
|
"@modern-js/module-tools": "@modern-js/module-tools",
|
|
44
44
|
"@modern-js/runtime": "@modern-js/runtime/cli",
|
|
45
45
|
"@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
|
|
@@ -48,16 +48,16 @@ export const INTERNAL_MODULE_TOOLS_PLUGINS = {
|
|
|
48
48
|
// legacy router (inner react-router-dom v5)
|
|
49
49
|
"@modern-js/plugin-router-legacy": "@modern-js/plugin-router-legacy/cli"
|
|
50
50
|
};
|
|
51
|
-
|
|
51
|
+
const INTERNAL_MONOREPO_TOOLS_PLUGINS = {
|
|
52
52
|
"@modern-js/monorepo-tools": "@modern-js/monorepo-tools/cli",
|
|
53
53
|
"@modern-js/plugin-testing": "@modern-js/plugin-testing/cli"
|
|
54
54
|
};
|
|
55
|
-
|
|
55
|
+
const INTERNAL_DOC_TOOLS_PLUGINS = {
|
|
56
56
|
"@modern-js/doc-tools": "@modern-js/doc-tools",
|
|
57
57
|
"@modern-js/runtime": "@modern-js/runtime/cli",
|
|
58
58
|
"@modern-js/plugin-testing": "@modern-js/plugin-testing/cli"
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
const INTERNAL_CLI_PLUGINS = {
|
|
61
61
|
"@modern-js/app-tools": "@modern-js/app-tools/cli",
|
|
62
62
|
"@modern-js/monorepo-tools": "@modern-js/monorepo-tools/cli",
|
|
63
63
|
"@modern-js/module-tools": "@modern-js/module-tools",
|
|
@@ -78,19 +78,19 @@ export const INTERNAL_CLI_PLUGINS = {
|
|
|
78
78
|
// legacy router (inner react-router-dom v5)
|
|
79
79
|
"@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
|
|
80
80
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const SERVER_PLUGIN_BFF = "@modern-js/plugin-bff";
|
|
82
|
+
const SERVER_PLUGIN_EXPRESS = "@modern-js/plugin-express";
|
|
83
|
+
const SERVER_PLUGIN_KOA = "@modern-js/plugin-koa";
|
|
84
|
+
const SERVER_PLUGIN_SERVER = "@modern-js/plugin-server";
|
|
85
|
+
const SERVER_PLUGIN_POLYFILL = "@modern-js/plugin-polyfill";
|
|
86
|
+
const INTERNAL_SERVER_PLUGINS = {
|
|
87
87
|
[SERVER_PLUGIN_BFF]: "@modern-js/plugin-bff/server",
|
|
88
88
|
[SERVER_PLUGIN_EXPRESS]: "@modern-js/plugin-express/server",
|
|
89
89
|
[SERVER_PLUGIN_KOA]: "@modern-js/plugin-koa/server",
|
|
90
90
|
[SERVER_PLUGIN_SERVER]: "@modern-js/plugin-server/server",
|
|
91
91
|
[SERVER_PLUGIN_POLYFILL]: "@modern-js/plugin-polyfill/server"
|
|
92
92
|
};
|
|
93
|
-
|
|
93
|
+
const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
|
|
94
94
|
allowNamespaces: true,
|
|
95
95
|
allExtensions: true,
|
|
96
96
|
allowDeclareFields: true,
|
|
@@ -100,3 +100,36 @@ export const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
|
|
|
100
100
|
isTSX: true
|
|
101
101
|
};
|
|
102
102
|
export * from "./chainId";
|
|
103
|
+
export {
|
|
104
|
+
API_DIR,
|
|
105
|
+
CONFIG_CACHE_DIR,
|
|
106
|
+
CONFIG_FILE_EXTENSIONS,
|
|
107
|
+
DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS,
|
|
108
|
+
DEFAULT_DEV_HOST,
|
|
109
|
+
DEFAULT_SERVER_CONFIG,
|
|
110
|
+
ENTRY_NAME_PATTERN,
|
|
111
|
+
INTERNAL_APP_TOOLS_PLUGINS,
|
|
112
|
+
INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
|
|
113
|
+
INTERNAL_CLI_PLUGINS,
|
|
114
|
+
INTERNAL_DOC_TOOLS_PLUGINS,
|
|
115
|
+
INTERNAL_MODULE_TOOLS_PLUGINS,
|
|
116
|
+
INTERNAL_MONOREPO_TOOLS_PLUGINS,
|
|
117
|
+
INTERNAL_SERVER_PLUGINS,
|
|
118
|
+
LOADABLE_STATS_FILE,
|
|
119
|
+
LOADER_ROUTES_DIR,
|
|
120
|
+
MAIN_ENTRY_NAME,
|
|
121
|
+
NESTED_ROUTE_SPEC_FILE,
|
|
122
|
+
OUTPUT_CONFIG_FILE,
|
|
123
|
+
ROUTE_MANIFEST_FILE,
|
|
124
|
+
ROUTE_SPEC_FILE,
|
|
125
|
+
SERVER_BUNDLE_DIRECTORY,
|
|
126
|
+
SERVER_DIR,
|
|
127
|
+
SERVER_PLUGIN_BFF,
|
|
128
|
+
SERVER_PLUGIN_EXPRESS,
|
|
129
|
+
SERVER_PLUGIN_KOA,
|
|
130
|
+
SERVER_PLUGIN_POLYFILL,
|
|
131
|
+
SERVER_PLUGIN_SERVER,
|
|
132
|
+
SERVER_RENDER_FUNCTION_NAME,
|
|
133
|
+
SERVER_WORKER_BUNDLE_DIRECTORY,
|
|
134
|
+
SHARED_DIR
|
|
135
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const ensureAbsolutePath = (base, filePath) => path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath);
|
|
3
|
+
const ensureArray = (params) => {
|
|
4
4
|
if (Array.isArray(params)) {
|
|
5
5
|
return params;
|
|
6
6
|
}
|
|
@@ -8,3 +8,7 @@ export const ensureArray = (params) => {
|
|
|
8
8
|
params
|
|
9
9
|
];
|
|
10
10
|
};
|
|
11
|
+
export {
|
|
12
|
+
ensureAbsolutePath,
|
|
13
|
+
ensureArray
|
|
14
|
+
};
|
package/dist/esm-node/cli/fs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fs } from "../compiled";
|
|
2
|
-
|
|
2
|
+
const findExists = (files) => {
|
|
3
3
|
for (const file of files) {
|
|
4
4
|
if (fs.existsSync(file) && fs.statSync(file).isFile()) {
|
|
5
5
|
return file;
|
|
@@ -7,8 +7,12 @@ export const findExists = (files) => {
|
|
|
7
7
|
}
|
|
8
8
|
return false;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
const emptyDir = async (dir) => {
|
|
11
11
|
if (await fs.pathExists(dir)) {
|
|
12
12
|
await fs.emptyDir(dir);
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
+
export {
|
|
16
|
+
emptyDir,
|
|
17
|
+
findExists
|
|
18
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isPlainObject } from "../is";
|
|
2
|
-
|
|
2
|
+
const getEntryOptions = (name, isMainEntry, baseOptions, optionsByEntries, packageName) => {
|
|
3
3
|
if (optionsByEntries) {
|
|
4
4
|
let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
|
|
5
5
|
if (optionsByEntry === void 0 && isMainEntry && packageName) {
|
|
@@ -14,3 +14,6 @@ export const getEntryOptions = (name, isMainEntry, baseOptions, optionsByEntries
|
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : void 0;
|
|
17
|
+
export {
|
|
18
|
+
getEntryOptions
|
|
19
|
+
};
|
|
@@ -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,12 +1,11 @@
|
|
|
1
1
|
import { MAIN_ENTRY_NAME } from "../constants";
|
|
2
2
|
import { isEmpty } from "./type";
|
|
3
|
-
|
|
4
|
-
var _server, _server1;
|
|
3
|
+
const isSSR = (config) => {
|
|
5
4
|
const { server } = config;
|
|
6
|
-
if (
|
|
5
|
+
if (server === null || server === void 0 ? void 0 : server.ssr) {
|
|
7
6
|
return true;
|
|
8
7
|
}
|
|
9
|
-
if ((
|
|
8
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
|
|
10
9
|
for (const name of Object.keys(server.ssrByEntries)) {
|
|
11
10
|
if (server.ssrByEntries[name]) {
|
|
12
11
|
return true;
|
|
@@ -15,30 +14,37 @@ export const isSSR = (config) => {
|
|
|
15
14
|
}
|
|
16
15
|
return false;
|
|
17
16
|
};
|
|
18
|
-
|
|
19
|
-
var _output;
|
|
17
|
+
const isUseSSRBundle = (config) => {
|
|
20
18
|
const { output } = config;
|
|
21
|
-
if (
|
|
19
|
+
if (output === null || output === void 0 ? void 0 : output.ssg) {
|
|
22
20
|
return true;
|
|
23
21
|
}
|
|
24
22
|
return isSSR(config);
|
|
25
23
|
};
|
|
26
|
-
|
|
27
|
-
var _deploy_worker
|
|
24
|
+
const isServiceWorker = (config) => {
|
|
25
|
+
var _deploy_worker;
|
|
28
26
|
const { output, deploy } = config;
|
|
29
|
-
if ((
|
|
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))) {
|
|
30
28
|
return true;
|
|
31
29
|
}
|
|
32
30
|
return false;
|
|
33
31
|
};
|
|
34
|
-
|
|
35
|
-
var _config_runtime, _config_runtime_router, _config_runtime1
|
|
36
|
-
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (
|
|
32
|
+
const isRouterV5 = (config) => {
|
|
33
|
+
var _config_runtime, _config_runtime_router, _config_runtime1;
|
|
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";
|
|
37
35
|
};
|
|
38
|
-
|
|
39
|
-
var _config_source
|
|
36
|
+
const isSSGEntry = (config, entryName, entrypoints) => {
|
|
37
|
+
var _config_source;
|
|
40
38
|
const ssgConfig = config.output.ssg;
|
|
41
|
-
const useSSG = isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) ? Boolean(ssgConfig) : ssgConfig === true || typeof (
|
|
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]);
|
|
42
40
|
return useSSG;
|
|
43
41
|
};
|
|
44
|
-
|
|
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,109 +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
|
-
success: {
|
|
21
|
-
color: "green",
|
|
22
|
-
label: "Success",
|
|
23
|
-
level: "info"
|
|
24
|
-
},
|
|
25
|
-
warn: {
|
|
26
|
-
color: "yellow",
|
|
27
|
-
label: "warn",
|
|
28
|
-
level: "warn"
|
|
29
|
-
},
|
|
30
|
-
debug: {
|
|
31
|
-
color: "red",
|
|
32
|
-
label: "debug",
|
|
33
|
-
level: "debug"
|
|
34
|
-
},
|
|
35
|
-
log: {
|
|
36
|
-
level: "log"
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const DEFAULT_CONFIG = {
|
|
40
|
-
displayLabel: true,
|
|
41
|
-
uppercaseLabel: false
|
|
42
|
-
};
|
|
43
|
-
const errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
|
|
44
|
-
const anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
|
|
45
|
-
export const isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
|
|
46
|
-
class Logger {
|
|
47
|
-
_log(type, message, ...args) {
|
|
48
|
-
if (message === void 0 || message === null) {
|
|
49
|
-
console.log();
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
let label = "";
|
|
56
|
-
let text = "";
|
|
57
|
-
const logType = this.types[type];
|
|
58
|
-
if (this.config.displayLabel && logType.label) {
|
|
59
|
-
label = this.config.uppercaseLabel ? logType.label.toUpperCase() : logType.label;
|
|
60
|
-
label = label.padEnd(this.longestLabel.length);
|
|
61
|
-
label = chalk.bold(logType.color ? chalk[logType.color](label) : label);
|
|
62
|
-
}
|
|
63
|
-
if (message instanceof Error) {
|
|
64
|
-
if (message.stack) {
|
|
65
|
-
const [name, ...rest] = message.stack.split("\n");
|
|
66
|
-
text = `${name}
|
|
67
|
-
${chalk.grey(rest.join("\n"))}`;
|
|
68
|
-
} else {
|
|
69
|
-
text = message.message;
|
|
70
|
-
}
|
|
71
|
-
} else if (logType.level === "error" && typeof message === "string") {
|
|
72
|
-
const lines = message.split("\n");
|
|
73
|
-
text = lines.map((line) => isErrorStackMessage(line) ? chalk.gray(line) : line).join("\n");
|
|
74
|
-
} else {
|
|
75
|
-
text = `${message}`;
|
|
76
|
-
}
|
|
77
|
-
const log = label.length > 0 ? `${label} ${text}` : text;
|
|
78
|
-
console.log(log, ...args);
|
|
79
|
-
}
|
|
80
|
-
getLongestLabel() {
|
|
81
|
-
let longestLabel = "";
|
|
82
|
-
Object.keys(this.types).forEach((type) => {
|
|
83
|
-
const { label = "" } = this.types[type];
|
|
84
|
-
if (label.length > longestLabel.length) {
|
|
85
|
-
longestLabel = label;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
return longestLabel;
|
|
89
|
-
}
|
|
90
|
-
constructor(options = {}) {
|
|
91
|
-
this.level = options.level || LOG_TYPES.log.level;
|
|
92
|
-
this.config = {
|
|
93
|
-
...DEFAULT_CONFIG,
|
|
94
|
-
...options.config || {}
|
|
95
|
-
};
|
|
96
|
-
this.types = {
|
|
97
|
-
...LOG_TYPES,
|
|
98
|
-
...options.types || {}
|
|
99
|
-
};
|
|
100
|
-
this.longestLabel = this.getLongestLabel();
|
|
101
|
-
Object.keys(this.types).forEach((type) => {
|
|
102
|
-
this[type] = this._log.bind(this, type);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const logger = new Logger();
|
|
107
|
-
logger.Logger = Logger;
|
|
108
|
-
export { Logger };
|
|
109
|
-
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
|
+
};
|