@modern-js/utils 2.26.0 → 2.28.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/cli/alias.js +3 -3
- package/dist/cjs/cli/constants/chainId.js +4 -0
- package/dist/cjs/cli/constants/index.js +0 -1
- package/dist/cjs/cli/is/config.js +11 -8
- package/dist/cjs/cli/prettyInstructions.js +3 -2
- package/dist/cjs/cli/require.js +2 -1
- package/dist/cjs/runtime/nestedRoutes.js +9 -5
- package/dist/cjs/runtime-browser/parsed.js +2 -1
- package/dist/cjs/universal/formatWebpack.js +55 -12
- package/dist/esm/cli/alias.js +27 -23
- package/dist/esm/cli/applyOptionsChain.js +8 -6
- package/dist/esm/cli/babel.js +50 -35
- package/dist/esm/cli/commands.js +7 -7
- package/dist/esm/cli/common.js +10 -5
- package/dist/esm/cli/constants/chainId.js +5 -1
- package/dist/esm/cli/constants/index.js +33 -38
- package/dist/esm/cli/ensure.js +4 -2
- package/dist/esm/cli/fs.js +56 -9
- package/dist/esm/cli/get/config.js +7 -7
- package/dist/esm/cli/get/data.js +102 -55
- package/dist/esm/cli/get/index.js +21 -6
- package/dist/esm/cli/is/config.js +43 -21
- package/dist/esm/cli/is/env.js +18 -6
- package/dist/esm/cli/is/platform.js +6 -2
- package/dist/esm/cli/is/project.js +73 -36
- package/dist/esm/cli/is/type.js +3 -1
- package/dist/esm/cli/logger.js +49 -38
- package/dist/esm/cli/monorepo.js +49 -36
- package/dist/esm/cli/package.js +156 -38
- package/dist/esm/cli/path.js +44 -20
- package/dist/esm/cli/pathSerializer.js +29 -15
- package/dist/esm/cli/port.js +89 -40
- package/dist/esm/cli/prettyInstructions.js +44 -32
- package/dist/esm/cli/require.js +22 -16
- package/dist/esm/cli/runtimeExports.js +21 -15
- package/dist/esm/cli/watch.js +94 -27
- package/dist/esm/compiled.js +3 -3
- package/dist/esm/import.js +4 -4
- package/dist/esm/runtime/nestedRoutes.js +49 -32
- package/dist/esm/runtime-browser/parsed.js +6 -5
- package/dist/esm/runtime-node/index.js +1 -1
- package/dist/esm/runtime-node/nestedRoutes.js +6 -4
- package/dist/esm/runtime-node/serialize.js +1 -1
- package/dist/esm/runtime-node/storage.js +12 -14
- package/dist/esm/universal/constants.js +3 -3
- package/dist/esm/universal/formatWebpack.js +54 -28
- package/dist/esm/universal/pluginDagSort.js +49 -26
- package/dist/esm-node/cli/alias.js +51 -0
- package/dist/esm-node/cli/applyOptionsChain.js +24 -0
- package/dist/esm-node/cli/babel.js +103 -0
- package/dist/esm-node/cli/commands.js +16 -0
- package/dist/esm-node/cli/common.js +10 -0
- package/dist/esm-node/cli/constants/chainId.js +184 -0
- package/dist/esm-node/cli/constants/index.js +102 -0
- package/dist/esm-node/cli/ensure.js +10 -0
- package/dist/esm-node/cli/fs.js +14 -0
- package/dist/esm-node/cli/get/config.js +16 -0
- package/dist/esm-node/cli/get/data.js +86 -0
- package/dist/esm-node/cli/get/index.js +13 -0
- package/dist/esm-node/cli/index.js +20 -0
- package/dist/esm-node/cli/is/config.js +43 -0
- package/dist/esm-node/cli/is/env.js +6 -0
- package/dist/esm-node/cli/is/index.js +5 -0
- package/dist/esm-node/cli/is/platform.js +2 -0
- package/dist/esm-node/cli/is/project.js +73 -0
- package/dist/esm-node/cli/is/type.js +25 -0
- package/dist/esm-node/cli/logger.js +103 -0
- package/dist/esm-node/cli/monorepo.js +70 -0
- package/dist/esm-node/cli/package.js +43 -0
- package/dist/esm-node/cli/path.js +49 -0
- package/dist/esm-node/cli/pathSerializer.js +46 -0
- package/dist/esm-node/cli/port.js +44 -0
- package/dist/esm-node/cli/prettyInstructions.js +78 -0
- package/dist/esm-node/cli/require.js +53 -0
- package/dist/esm-node/cli/runtimeExports.js +35 -0
- package/dist/esm-node/cli/watch.js +41 -0
- package/dist/esm-node/compiled.js +33 -0
- package/dist/esm-node/import.js +8 -0
- package/dist/esm-node/index.js +3 -0
- package/dist/esm-node/runtime/nestedRoutes.js +116 -0
- package/dist/esm-node/runtime/remixRouter.js +1 -0
- package/dist/esm-node/runtime/router.js +1 -0
- package/dist/esm-node/runtime-browser/index.js +1 -0
- package/dist/esm-node/runtime-browser/parsed.js +18 -0
- package/dist/esm-node/runtime-node/index.js +5 -0
- package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
- package/dist/esm-node/runtime-node/router.js +1 -0
- package/dist/esm-node/runtime-node/serialize.js +6 -0
- package/dist/esm-node/runtime-node/storage.js +38 -0
- package/dist/esm-node/universal/constants.js +3 -0
- package/dist/esm-node/universal/formatWebpack.js +99 -0
- package/dist/esm-node/universal/pluginDagSort.js +50 -0
- package/dist/types/cli/constants/chainId.d.ts +4 -0
- package/dist/types/universal/formatWebpack.d.ts +14 -1
- package/package.json +4 -4
@@ -1,4 +1,4 @@
|
|
1
|
-
export
|
1
|
+
export var CHAIN_ID = {
|
2
2
|
/** Predefined rules */
|
3
3
|
RULE: {
|
4
4
|
/** Rule for .mjs */
|
@@ -37,6 +37,8 @@ export const CHAIN_ID = {
|
|
37
37
|
YAML: "yaml",
|
38
38
|
/** Rule for wasm */
|
39
39
|
WASM: "wasm",
|
40
|
+
/** Rule for node */
|
41
|
+
NODE: "node",
|
40
42
|
/** Rule for bff */
|
41
43
|
JS_BFF_API: "js-bff-api"
|
42
44
|
},
|
@@ -75,6 +77,8 @@ export const CHAIN_ID = {
|
|
75
77
|
TOML: "toml",
|
76
78
|
/** html-loader */
|
77
79
|
HTML: "html",
|
80
|
+
/** node-loader */
|
81
|
+
NODE: "html",
|
78
82
|
/** babel-loader */
|
79
83
|
BABEL: "babel",
|
80
84
|
/** esbuild-loader */
|
@@ -1,26 +1,27 @@
|
|
1
|
-
|
2
|
-
export
|
3
|
-
export
|
4
|
-
export
|
5
|
-
export
|
6
|
-
export
|
7
|
-
export
|
8
|
-
export
|
9
|
-
export
|
10
|
-
export
|
11
|
-
export
|
12
|
-
export
|
13
|
-
export
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
2
|
+
export var ROUTE_SPEC_FILE = "route.json";
|
3
|
+
export var NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
|
4
|
+
export var MAIN_ENTRY_NAME = "main";
|
5
|
+
export var SERVER_BUNDLE_DIRECTORY = "bundles";
|
6
|
+
export var SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
|
7
|
+
export var ENTRY_NAME_PATTERN = "^[a-zA-Z0-9_-]+$";
|
8
|
+
export var SERVER_RENDER_FUNCTION_NAME = "serverRender";
|
9
|
+
export var LOADABLE_STATS_FILE = "loadable-stats.json";
|
10
|
+
export var API_DIR = "api";
|
11
|
+
export var SERVER_DIR = "server";
|
12
|
+
export var SHARED_DIR = "shared";
|
13
|
+
export var CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
|
14
|
+
export var CONFIG_FILE_EXTENSIONS = [
|
14
15
|
".js",
|
15
16
|
".ts",
|
16
17
|
".mjs"
|
17
18
|
];
|
18
|
-
export
|
19
|
-
export
|
20
|
-
export
|
21
|
-
export
|
22
|
-
export
|
23
|
-
export
|
19
|
+
export var OUTPUT_CONFIG_FILE = "modern.config.json";
|
20
|
+
export var DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
|
21
|
+
export var ROUTE_MANIFEST_FILE = "routes-manifest.json";
|
22
|
+
export var LOADER_ROUTES_DIR = "loader-routes";
|
23
|
+
export var DEFAULT_DEV_HOST = "0.0.0.0";
|
24
|
+
export var INTERNAL_APP_TOOLS_PLUGINS = {
|
24
25
|
"@modern-js/app-tools": "@modern-js/app-tools/cli",
|
25
26
|
"@modern-js/plugin-proxy": "@modern-js/plugin-proxy/cli",
|
26
27
|
"@modern-js/plugin-ssg": "@modern-js/plugin-ssg/cli",
|
@@ -36,12 +37,11 @@ export const INTERNAL_APP_TOOLS_PLUGINS = {
|
|
36
37
|
// legacy router (inner react-router-dom v5)
|
37
38
|
"@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
|
38
39
|
};
|
39
|
-
export
|
40
|
+
export var INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
|
40
41
|
"@modern-js/runtime": "@modern-js/runtime/cli"
|
41
42
|
};
|
42
|
-
export
|
43
|
+
export var INTERNAL_MODULE_TOOLS_PLUGINS = {
|
43
44
|
"@modern-js/module-tools": "@modern-js/module-tools",
|
44
|
-
"@modern-js/doc-tools": "@modern-js/doc-tools",
|
45
45
|
"@modern-js/runtime": "@modern-js/runtime/cli",
|
46
46
|
"@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
|
47
47
|
"@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
|
@@ -49,16 +49,16 @@ export const INTERNAL_MODULE_TOOLS_PLUGINS = {
|
|
49
49
|
// legacy router (inner react-router-dom v5)
|
50
50
|
"@modern-js/plugin-router-legacy": "@modern-js/plugin-router-legacy/cli"
|
51
51
|
};
|
52
|
-
export
|
52
|
+
export var INTERNAL_MONOREPO_TOOLS_PLUGINS = {
|
53
53
|
"@modern-js/monorepo-tools": "@modern-js/monorepo-tools/cli",
|
54
54
|
"@modern-js/plugin-testing": "@modern-js/plugin-testing/cli"
|
55
55
|
};
|
56
|
-
export
|
56
|
+
export var INTERNAL_DOC_TOOLS_PLUGINS = {
|
57
57
|
"@modern-js/doc-tools": "@modern-js/doc-tools",
|
58
58
|
"@modern-js/runtime": "@modern-js/runtime/cli",
|
59
59
|
"@modern-js/plugin-testing": "@modern-js/plugin-testing/cli"
|
60
60
|
};
|
61
|
-
export
|
61
|
+
export var INTERNAL_CLI_PLUGINS = {
|
62
62
|
"@modern-js/app-tools": "@modern-js/app-tools/cli",
|
63
63
|
"@modern-js/monorepo-tools": "@modern-js/monorepo-tools/cli",
|
64
64
|
"@modern-js/module-tools": "@modern-js/module-tools",
|
@@ -79,19 +79,14 @@ export const INTERNAL_CLI_PLUGINS = {
|
|
79
79
|
// legacy router (inner react-router-dom v5)
|
80
80
|
"@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
|
81
81
|
};
|
82
|
-
export
|
83
|
-
export
|
84
|
-
export
|
85
|
-
export
|
86
|
-
export
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
[SERVER_PLUGIN_KOA]: "@modern-js/plugin-koa/server",
|
91
|
-
[SERVER_PLUGIN_SERVER]: "@modern-js/plugin-server/server",
|
92
|
-
[SERVER_PLUGIN_POLYFILL]: "@modern-js/plugin-polyfill/server"
|
93
|
-
};
|
94
|
-
export const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
|
82
|
+
export var SERVER_PLUGIN_BFF = "@modern-js/plugin-bff";
|
83
|
+
export var SERVER_PLUGIN_EXPRESS = "@modern-js/plugin-express";
|
84
|
+
export var SERVER_PLUGIN_KOA = "@modern-js/plugin-koa";
|
85
|
+
export var SERVER_PLUGIN_SERVER = "@modern-js/plugin-server";
|
86
|
+
export var SERVER_PLUGIN_POLYFILL = "@modern-js/plugin-polyfill";
|
87
|
+
var _obj;
|
88
|
+
export var INTERNAL_SERVER_PLUGINS = (_obj = {}, _define_property(_obj, SERVER_PLUGIN_BFF, "@modern-js/plugin-bff/server"), _define_property(_obj, SERVER_PLUGIN_EXPRESS, "@modern-js/plugin-express/server"), _define_property(_obj, SERVER_PLUGIN_KOA, "@modern-js/plugin-koa/server"), _define_property(_obj, SERVER_PLUGIN_SERVER, "@modern-js/plugin-server/server"), _define_property(_obj, SERVER_PLUGIN_POLYFILL, "@modern-js/plugin-polyfill/server"), _obj);
|
89
|
+
export var DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
|
95
90
|
allowNamespaces: true,
|
96
91
|
allExtensions: true,
|
97
92
|
allowDeclareFields: true,
|
package/dist/esm/cli/ensure.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import path from "path";
|
2
|
-
export
|
3
|
-
|
2
|
+
export var ensureAbsolutePath = function(base, filePath) {
|
3
|
+
return path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath);
|
4
|
+
};
|
5
|
+
export var ensureArray = function(params) {
|
4
6
|
if (Array.isArray(params)) {
|
5
7
|
return params;
|
6
8
|
}
|
package/dist/esm/cli/fs.js
CHANGED
@@ -1,14 +1,61 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
1
3
|
import { fs } from "../compiled";
|
2
|
-
export
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
export var findExists = function(files) {
|
5
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
6
|
+
try {
|
7
|
+
for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
8
|
+
var file = _step.value;
|
9
|
+
if (fs.existsSync(file) && fs.statSync(file).isFile()) {
|
10
|
+
return file;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
} catch (err) {
|
14
|
+
_didIteratorError = true;
|
15
|
+
_iteratorError = err;
|
16
|
+
} finally {
|
17
|
+
try {
|
18
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
19
|
+
_iterator.return();
|
20
|
+
}
|
21
|
+
} finally {
|
22
|
+
if (_didIteratorError) {
|
23
|
+
throw _iteratorError;
|
24
|
+
}
|
6
25
|
}
|
7
26
|
}
|
8
27
|
return false;
|
9
28
|
};
|
10
|
-
export
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
29
|
+
export var emptyDir = function() {
|
30
|
+
var _ref = _async_to_generator(function(dir) {
|
31
|
+
return _ts_generator(this, function(_state) {
|
32
|
+
switch (_state.label) {
|
33
|
+
case 0:
|
34
|
+
return [
|
35
|
+
4,
|
36
|
+
fs.pathExists(dir)
|
37
|
+
];
|
38
|
+
case 1:
|
39
|
+
if (!_state.sent())
|
40
|
+
return [
|
41
|
+
3,
|
42
|
+
3
|
43
|
+
];
|
44
|
+
return [
|
45
|
+
4,
|
46
|
+
fs.emptyDir(dir)
|
47
|
+
];
|
48
|
+
case 2:
|
49
|
+
_state.sent();
|
50
|
+
_state.label = 3;
|
51
|
+
case 3:
|
52
|
+
return [
|
53
|
+
2
|
54
|
+
];
|
55
|
+
}
|
56
|
+
});
|
57
|
+
});
|
58
|
+
return function emptyDir2(dir) {
|
59
|
+
return _ref.apply(this, arguments);
|
60
|
+
};
|
61
|
+
}();
|
@@ -1,16 +1,16 @@
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
1
2
|
import { isPlainObject } from "../is";
|
2
|
-
export
|
3
|
+
export var getEntryOptions = function(name, isMainEntry, baseOptions, optionsByEntries, packageName) {
|
3
4
|
if (optionsByEntries) {
|
4
|
-
|
5
|
+
var optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
|
5
6
|
if (optionsByEntry === void 0 && isMainEntry && packageName) {
|
6
7
|
optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
|
7
8
|
}
|
8
|
-
return optionsByEntry !== void 0 ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? {
|
9
|
-
...baseOptions,
|
10
|
-
...optionsByEntry
|
11
|
-
} : optionsByEntry : baseOptions;
|
9
|
+
return optionsByEntry !== void 0 ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? _object_spread({}, baseOptions, optionsByEntry) : optionsByEntry : baseOptions;
|
12
10
|
} else {
|
13
11
|
return baseOptions;
|
14
12
|
}
|
15
13
|
};
|
16
|
-
|
14
|
+
var getOptionsByEntryName = function(name, optionsByEntries) {
|
15
|
+
return optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : void 0;
|
16
|
+
};
|
package/dist/esm/cli/get/data.js
CHANGED
@@ -1,86 +1,133 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
3
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
1
5
|
import os from "os";
|
2
6
|
import path from "path";
|
3
7
|
import { browserslist, fs, json5 } from "../../compiled";
|
4
8
|
import { INTERNAL_CLI_PLUGINS } from "../constants";
|
5
9
|
import { isDepExists } from "../is";
|
6
10
|
import { canUsePnpm, canUseYarn } from "../package";
|
7
|
-
|
8
|
-
export
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
11
|
+
var MAX_TIMES = 5;
|
12
|
+
export function getPackageManager() {
|
13
|
+
return _getPackageManager.apply(this, arguments);
|
14
|
+
}
|
15
|
+
function _getPackageManager() {
|
16
|
+
_getPackageManager = _async_to_generator(function() {
|
17
|
+
var cwd, appDirectory, times;
|
18
|
+
var _arguments = arguments;
|
19
|
+
return _ts_generator(this, function(_state) {
|
20
|
+
switch (_state.label) {
|
21
|
+
case 0:
|
22
|
+
cwd = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : process.cwd();
|
23
|
+
appDirectory = cwd;
|
24
|
+
times = 0;
|
25
|
+
while (os.homedir() !== appDirectory && times < MAX_TIMES) {
|
26
|
+
times++;
|
27
|
+
if (fs.existsSync(path.resolve(appDirectory, "pnpm-lock.yaml"))) {
|
28
|
+
return [
|
29
|
+
2,
|
30
|
+
"pnpm"
|
31
|
+
];
|
32
|
+
}
|
33
|
+
if (fs.existsSync(path.resolve(appDirectory, "yarn.lock"))) {
|
34
|
+
return [
|
35
|
+
2,
|
36
|
+
"yarn"
|
37
|
+
];
|
38
|
+
}
|
39
|
+
if (fs.existsSync(path.resolve(appDirectory, "package-lock.json"))) {
|
40
|
+
return [
|
41
|
+
2,
|
42
|
+
"npm"
|
43
|
+
];
|
44
|
+
}
|
45
|
+
appDirectory = path.join(appDirectory, "..");
|
46
|
+
}
|
47
|
+
return [
|
48
|
+
4,
|
49
|
+
canUsePnpm()
|
50
|
+
];
|
51
|
+
case 1:
|
52
|
+
if (_state.sent()) {
|
53
|
+
return [
|
54
|
+
2,
|
55
|
+
"pnpm"
|
56
|
+
];
|
57
|
+
}
|
58
|
+
return [
|
59
|
+
4,
|
60
|
+
canUseYarn()
|
61
|
+
];
|
62
|
+
case 2:
|
63
|
+
if (_state.sent()) {
|
64
|
+
return [
|
65
|
+
2,
|
66
|
+
"yarn"
|
67
|
+
];
|
68
|
+
}
|
69
|
+
return [
|
70
|
+
2,
|
71
|
+
"npm"
|
72
|
+
];
|
73
|
+
}
|
74
|
+
});
|
75
|
+
});
|
76
|
+
return _getPackageManager.apply(this, arguments);
|
31
77
|
}
|
32
|
-
export
|
78
|
+
export var getCoreJsVersion = function(corejsPkgPath) {
|
33
79
|
try {
|
34
|
-
|
35
|
-
|
36
|
-
return
|
80
|
+
var version = fs.readJSONSync(corejsPkgPath).version;
|
81
|
+
var _version_split = _sliced_to_array(version.split("."), 2), major = _version_split[0], minor = _version_split[1];
|
82
|
+
return "".concat(major, ".").concat(minor);
|
37
83
|
} catch (err) {
|
38
84
|
return "3";
|
39
85
|
}
|
40
86
|
};
|
41
|
-
export
|
87
|
+
export var getAntdMajorVersion = function(appDirectory) {
|
42
88
|
try {
|
43
|
-
|
89
|
+
var pkgJsonPath = require.resolve("antd/package.json", {
|
44
90
|
paths: [
|
45
91
|
appDirectory
|
46
92
|
]
|
47
93
|
});
|
48
|
-
|
94
|
+
var version = require(pkgJsonPath).version;
|
49
95
|
return Number(version.split(".")[0]);
|
50
96
|
} catch (err) {
|
51
97
|
return null;
|
52
98
|
}
|
53
99
|
};
|
54
|
-
export
|
100
|
+
export var defaults = [
|
55
101
|
"> 0.01%",
|
56
102
|
"not dead",
|
57
103
|
"not op_mini all"
|
58
104
|
];
|
59
|
-
export
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
return
|
70
|
-
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
105
|
+
export var getBrowserslist = function(appDirectory) {
|
106
|
+
return browserslist.loadConfig({
|
107
|
+
path: appDirectory
|
108
|
+
}) || defaults;
|
109
|
+
};
|
110
|
+
export function getInternalPlugins(appDirectory) {
|
111
|
+
var internalPlugins = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : INTERNAL_CLI_PLUGINS;
|
112
|
+
return _to_consumable_array(Object.keys(internalPlugins).filter(function(name) {
|
113
|
+
var config = internalPlugins[name];
|
114
|
+
if (typeof config !== "string" && config.forced === true) {
|
115
|
+
return true;
|
116
|
+
}
|
117
|
+
return isDepExists(appDirectory, name);
|
118
|
+
}).map(function(name) {
|
119
|
+
var config = internalPlugins[name];
|
120
|
+
if (typeof config !== "string") {
|
121
|
+
return config.path;
|
122
|
+
} else {
|
123
|
+
return config;
|
124
|
+
}
|
125
|
+
}));
|
79
126
|
}
|
80
|
-
export
|
127
|
+
export var readTsConfig = function(root) {
|
81
128
|
return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
|
82
129
|
};
|
83
|
-
export
|
84
|
-
|
130
|
+
export var readTsConfigByFile = function(filename) {
|
131
|
+
var content = fs.readFileSync(path.resolve(filename), "utf-8");
|
85
132
|
return json5.parse(content);
|
86
133
|
};
|
@@ -1,12 +1,27 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
1
3
|
import path from "path";
|
2
4
|
import { CONFIG_FILE_EXTENSIONS } from "../constants";
|
3
5
|
import { findExists } from "../fs";
|
4
|
-
export
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
export var getServerConfig = function() {
|
7
|
+
var _ref = _async_to_generator(function(appDirectory, configFile) {
|
8
|
+
var configFilePath;
|
9
|
+
return _ts_generator(this, function(_state) {
|
10
|
+
configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map(function(extension) {
|
11
|
+
return path.resolve(appDirectory, "".concat(configFile).concat(extension));
|
12
|
+
}));
|
13
|
+
return [
|
14
|
+
2,
|
15
|
+
configFilePath
|
16
|
+
];
|
17
|
+
});
|
18
|
+
});
|
19
|
+
return function getServerConfig2(appDirectory, configFile) {
|
20
|
+
return _ref.apply(this, arguments);
|
21
|
+
};
|
22
|
+
}();
|
23
|
+
export var getTargetDir = function(from, baseDir, targetBaseDir) {
|
24
|
+
var relativePath = path.relative(baseDir, from);
|
10
25
|
return path.resolve(targetBaseDir, relativePath);
|
11
26
|
};
|
12
27
|
export * from "./data";
|
@@ -1,40 +1,62 @@
|
|
1
1
|
import { isEmpty } from "./type";
|
2
|
-
export
|
3
|
-
|
4
|
-
|
2
|
+
export var isSSR = function(config) {
|
3
|
+
var _server, _server1;
|
4
|
+
var server = config.server;
|
5
|
+
if ((_server = server) === null || _server === void 0 ? void 0 : _server.ssr) {
|
5
6
|
return true;
|
6
7
|
}
|
7
|
-
if ((server === null ||
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
if (((_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
|
9
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
10
|
+
try {
|
11
|
+
for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
12
|
+
var name = _step.value;
|
13
|
+
if (server.ssrByEntries[name]) {
|
14
|
+
return true;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
} catch (err) {
|
18
|
+
_didIteratorError = true;
|
19
|
+
_iteratorError = err;
|
20
|
+
} finally {
|
21
|
+
try {
|
22
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
23
|
+
_iterator.return();
|
24
|
+
}
|
25
|
+
} finally {
|
26
|
+
if (_didIteratorError) {
|
27
|
+
throw _iteratorError;
|
28
|
+
}
|
11
29
|
}
|
12
30
|
}
|
13
31
|
}
|
14
32
|
return false;
|
15
33
|
};
|
16
|
-
export
|
17
|
-
|
18
|
-
|
34
|
+
export var isUseSSRBundle = function(config) {
|
35
|
+
var _output;
|
36
|
+
var output = config.output;
|
37
|
+
if ((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) {
|
19
38
|
return true;
|
20
39
|
}
|
21
40
|
return isSSR(config);
|
22
41
|
};
|
23
|
-
export
|
24
|
-
var _deploy_worker;
|
25
|
-
|
26
|
-
if ((deploy === null ||
|
42
|
+
export var isServiceWorker = function(config) {
|
43
|
+
var _deploy_worker, _deploy, _output;
|
44
|
+
var output = config.output, deploy = config.deploy;
|
45
|
+
if (((_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr) && (((_output = output) === null || _output === void 0 ? void 0 : _output.ssg) || isSSR(config))) {
|
27
46
|
return true;
|
28
47
|
}
|
29
48
|
return false;
|
30
49
|
};
|
31
|
-
export
|
32
|
-
var _config_runtime, _config_runtime1,
|
33
|
-
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null ||
|
50
|
+
export var isRouterV5 = function(config) {
|
51
|
+
var _config_runtime, _config_runtime_router, _config_runtime1, _config;
|
52
|
+
return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && ((_config = config) === null || _config === void 0 ? void 0 : (_config_runtime1 = _config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
|
34
53
|
};
|
35
|
-
export
|
36
|
-
|
37
|
-
|
54
|
+
export var isSSGEntry = function(config, entryName, entrypoints) {
|
55
|
+
var _ssgConfig, _ssgConfig1;
|
56
|
+
var ssgConfig = config.output.ssg;
|
57
|
+
var useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
|
38
58
|
return useSSG;
|
39
59
|
};
|
40
|
-
export
|
60
|
+
export var isSingleEntry = function(entrypoints) {
|
61
|
+
return entrypoints.length === 1 && entrypoints[0].entryName === "main";
|
62
|
+
};
|
package/dist/esm/cli/is/env.js
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
export
|
2
|
-
|
3
|
-
|
4
|
-
export
|
5
|
-
|
6
|
-
|
1
|
+
export var getNodeEnv = function() {
|
2
|
+
return process.env.NODE_ENV || "development";
|
3
|
+
};
|
4
|
+
export var isDev = function() {
|
5
|
+
return getNodeEnv() === "development";
|
6
|
+
};
|
7
|
+
export var isProd = function() {
|
8
|
+
return getNodeEnv() === "production";
|
9
|
+
};
|
10
|
+
export var isTest = function() {
|
11
|
+
return getNodeEnv() === "test";
|
12
|
+
};
|
13
|
+
export var isProdProfile = function() {
|
14
|
+
return isProd() && process.argv.includes("--profile");
|
15
|
+
};
|
16
|
+
export var isFastRefresh = function() {
|
17
|
+
return isDev() && process.env.FAST_REFRESH !== "false";
|
18
|
+
};
|
@@ -1,2 +1,6 @@
|
|
1
|
-
export
|
2
|
-
|
1
|
+
export var isNodeJS = function() {
|
2
|
+
return typeof process !== "undefined" && process.versions != null && process.versions.node != null && process.versions.electron == null;
|
3
|
+
};
|
4
|
+
export var isBrowser = function() {
|
5
|
+
return typeof window !== "undefined";
|
6
|
+
};
|