@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.
Files changed (96) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/cli/alias.js +3 -3
  3. package/dist/cjs/cli/constants/chainId.js +4 -0
  4. package/dist/cjs/cli/constants/index.js +0 -1
  5. package/dist/cjs/cli/is/config.js +11 -8
  6. package/dist/cjs/cli/prettyInstructions.js +3 -2
  7. package/dist/cjs/cli/require.js +2 -1
  8. package/dist/cjs/runtime/nestedRoutes.js +9 -5
  9. package/dist/cjs/runtime-browser/parsed.js +2 -1
  10. package/dist/cjs/universal/formatWebpack.js +55 -12
  11. package/dist/esm/cli/alias.js +27 -23
  12. package/dist/esm/cli/applyOptionsChain.js +8 -6
  13. package/dist/esm/cli/babel.js +50 -35
  14. package/dist/esm/cli/commands.js +7 -7
  15. package/dist/esm/cli/common.js +10 -5
  16. package/dist/esm/cli/constants/chainId.js +5 -1
  17. package/dist/esm/cli/constants/index.js +33 -38
  18. package/dist/esm/cli/ensure.js +4 -2
  19. package/dist/esm/cli/fs.js +56 -9
  20. package/dist/esm/cli/get/config.js +7 -7
  21. package/dist/esm/cli/get/data.js +102 -55
  22. package/dist/esm/cli/get/index.js +21 -6
  23. package/dist/esm/cli/is/config.js +43 -21
  24. package/dist/esm/cli/is/env.js +18 -6
  25. package/dist/esm/cli/is/platform.js +6 -2
  26. package/dist/esm/cli/is/project.js +73 -36
  27. package/dist/esm/cli/is/type.js +3 -1
  28. package/dist/esm/cli/logger.js +49 -38
  29. package/dist/esm/cli/monorepo.js +49 -36
  30. package/dist/esm/cli/package.js +156 -38
  31. package/dist/esm/cli/path.js +44 -20
  32. package/dist/esm/cli/pathSerializer.js +29 -15
  33. package/dist/esm/cli/port.js +89 -40
  34. package/dist/esm/cli/prettyInstructions.js +44 -32
  35. package/dist/esm/cli/require.js +22 -16
  36. package/dist/esm/cli/runtimeExports.js +21 -15
  37. package/dist/esm/cli/watch.js +94 -27
  38. package/dist/esm/compiled.js +3 -3
  39. package/dist/esm/import.js +4 -4
  40. package/dist/esm/runtime/nestedRoutes.js +49 -32
  41. package/dist/esm/runtime-browser/parsed.js +6 -5
  42. package/dist/esm/runtime-node/index.js +1 -1
  43. package/dist/esm/runtime-node/nestedRoutes.js +6 -4
  44. package/dist/esm/runtime-node/serialize.js +1 -1
  45. package/dist/esm/runtime-node/storage.js +12 -14
  46. package/dist/esm/universal/constants.js +3 -3
  47. package/dist/esm/universal/formatWebpack.js +54 -28
  48. package/dist/esm/universal/pluginDagSort.js +49 -26
  49. package/dist/esm-node/cli/alias.js +51 -0
  50. package/dist/esm-node/cli/applyOptionsChain.js +24 -0
  51. package/dist/esm-node/cli/babel.js +103 -0
  52. package/dist/esm-node/cli/commands.js +16 -0
  53. package/dist/esm-node/cli/common.js +10 -0
  54. package/dist/esm-node/cli/constants/chainId.js +184 -0
  55. package/dist/esm-node/cli/constants/index.js +102 -0
  56. package/dist/esm-node/cli/ensure.js +10 -0
  57. package/dist/esm-node/cli/fs.js +14 -0
  58. package/dist/esm-node/cli/get/config.js +16 -0
  59. package/dist/esm-node/cli/get/data.js +86 -0
  60. package/dist/esm-node/cli/get/index.js +13 -0
  61. package/dist/esm-node/cli/index.js +20 -0
  62. package/dist/esm-node/cli/is/config.js +43 -0
  63. package/dist/esm-node/cli/is/env.js +6 -0
  64. package/dist/esm-node/cli/is/index.js +5 -0
  65. package/dist/esm-node/cli/is/platform.js +2 -0
  66. package/dist/esm-node/cli/is/project.js +73 -0
  67. package/dist/esm-node/cli/is/type.js +25 -0
  68. package/dist/esm-node/cli/logger.js +103 -0
  69. package/dist/esm-node/cli/monorepo.js +70 -0
  70. package/dist/esm-node/cli/package.js +43 -0
  71. package/dist/esm-node/cli/path.js +49 -0
  72. package/dist/esm-node/cli/pathSerializer.js +46 -0
  73. package/dist/esm-node/cli/port.js +44 -0
  74. package/dist/esm-node/cli/prettyInstructions.js +78 -0
  75. package/dist/esm-node/cli/require.js +53 -0
  76. package/dist/esm-node/cli/runtimeExports.js +35 -0
  77. package/dist/esm-node/cli/watch.js +41 -0
  78. package/dist/esm-node/compiled.js +33 -0
  79. package/dist/esm-node/import.js +8 -0
  80. package/dist/esm-node/index.js +3 -0
  81. package/dist/esm-node/runtime/nestedRoutes.js +116 -0
  82. package/dist/esm-node/runtime/remixRouter.js +1 -0
  83. package/dist/esm-node/runtime/router.js +1 -0
  84. package/dist/esm-node/runtime-browser/index.js +1 -0
  85. package/dist/esm-node/runtime-browser/parsed.js +18 -0
  86. package/dist/esm-node/runtime-node/index.js +5 -0
  87. package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
  88. package/dist/esm-node/runtime-node/router.js +1 -0
  89. package/dist/esm-node/runtime-node/serialize.js +6 -0
  90. package/dist/esm-node/runtime-node/storage.js +38 -0
  91. package/dist/esm-node/universal/constants.js +3 -0
  92. package/dist/esm-node/universal/formatWebpack.js +99 -0
  93. package/dist/esm-node/universal/pluginDagSort.js +50 -0
  94. package/dist/types/cli/constants/chainId.d.ts +4 -0
  95. package/dist/types/universal/formatWebpack.d.ts +14 -1
  96. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- export const CHAIN_ID = {
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
- export const ROUTE_SPEC_FILE = "route.json";
2
- export const NESTED_ROUTE_SPEC_FILE = "nestedRoutes.json";
3
- export const MAIN_ENTRY_NAME = "main";
4
- export const SERVER_BUNDLE_DIRECTORY = "bundles";
5
- export const SERVER_WORKER_BUNDLE_DIRECTORY = "worker";
6
- export const ENTRY_NAME_PATTERN = "^[a-zA-Z0-9_-]+$";
7
- export const SERVER_RENDER_FUNCTION_NAME = "serverRender";
8
- export const LOADABLE_STATS_FILE = "loadable-stats.json";
9
- export const API_DIR = "api";
10
- export const SERVER_DIR = "server";
11
- export const SHARED_DIR = "shared";
12
- export const CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
13
- export const CONFIG_FILE_EXTENSIONS = [
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 const OUTPUT_CONFIG_FILE = "modern.config.json";
19
- export const DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
20
- export const ROUTE_MANIFEST_FILE = "routes-manifest.json";
21
- export const LOADER_ROUTES_DIR = `loader-routes`;
22
- export const DEFAULT_DEV_HOST = "0.0.0.0";
23
- export const INTERNAL_APP_TOOLS_PLUGINS = {
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 const INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
40
+ export var INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
40
41
  "@modern-js/runtime": "@modern-js/runtime/cli"
41
42
  };
42
- export const INTERNAL_MODULE_TOOLS_PLUGINS = {
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 const INTERNAL_MONOREPO_TOOLS_PLUGINS = {
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 const INTERNAL_DOC_TOOLS_PLUGINS = {
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 const INTERNAL_CLI_PLUGINS = {
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 const SERVER_PLUGIN_BFF = "@modern-js/plugin-bff";
83
- export const SERVER_PLUGIN_EXPRESS = "@modern-js/plugin-express";
84
- export const SERVER_PLUGIN_KOA = "@modern-js/plugin-koa";
85
- export const SERVER_PLUGIN_SERVER = "@modern-js/plugin-server";
86
- export const SERVER_PLUGIN_POLYFILL = "@modern-js/plugin-polyfill";
87
- export const INTERNAL_SERVER_PLUGINS = {
88
- [SERVER_PLUGIN_BFF]: "@modern-js/plugin-bff/server",
89
- [SERVER_PLUGIN_EXPRESS]: "@modern-js/plugin-express/server",
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,
@@ -1,6 +1,8 @@
1
1
  import path from "path";
2
- export const ensureAbsolutePath = (base, filePath) => path.isAbsolute(filePath) ? filePath : path.resolve(base, filePath);
3
- export const ensureArray = (params) => {
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
  }
@@ -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 const findExists = (files) => {
3
- for (const file of files) {
4
- if (fs.existsSync(file) && fs.statSync(file).isFile()) {
5
- return file;
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 const emptyDir = async (dir) => {
11
- if (await fs.pathExists(dir)) {
12
- await fs.emptyDir(dir);
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 const getEntryOptions = (name, isMainEntry, baseOptions, optionsByEntries, packageName) => {
3
+ export var getEntryOptions = function(name, isMainEntry, baseOptions, optionsByEntries, packageName) {
3
4
  if (optionsByEntries) {
4
- let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
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
- const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : void 0;
14
+ var getOptionsByEntryName = function(name, optionsByEntries) {
15
+ return optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : void 0;
16
+ };
@@ -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
- const MAX_TIMES = 5;
8
- export async function getPackageManager(cwd = process.cwd()) {
9
- let appDirectory = cwd;
10
- let times = 0;
11
- while (os.homedir() !== appDirectory && times < MAX_TIMES) {
12
- times++;
13
- if (fs.existsSync(path.resolve(appDirectory, "pnpm-lock.yaml"))) {
14
- return "pnpm";
15
- }
16
- if (fs.existsSync(path.resolve(appDirectory, "yarn.lock"))) {
17
- return "yarn";
18
- }
19
- if (fs.existsSync(path.resolve(appDirectory, "package-lock.json"))) {
20
- return "npm";
21
- }
22
- appDirectory = path.join(appDirectory, "..");
23
- }
24
- if (await canUsePnpm()) {
25
- return "pnpm";
26
- }
27
- if (await canUseYarn()) {
28
- return "yarn";
29
- }
30
- return "npm";
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 const getCoreJsVersion = (corejsPkgPath) => {
78
+ export var getCoreJsVersion = function(corejsPkgPath) {
33
79
  try {
34
- const { version } = fs.readJSONSync(corejsPkgPath);
35
- const [major, minor] = version.split(".");
36
- return `${major}.${minor}`;
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 const getAntdMajorVersion = (appDirectory) => {
87
+ export var getAntdMajorVersion = function(appDirectory) {
42
88
  try {
43
- const pkgJsonPath = require.resolve("antd/package.json", {
89
+ var pkgJsonPath = require.resolve("antd/package.json", {
44
90
  paths: [
45
91
  appDirectory
46
92
  ]
47
93
  });
48
- const { version } = require(pkgJsonPath);
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 const defaults = [
100
+ export var defaults = [
55
101
  "> 0.01%",
56
102
  "not dead",
57
103
  "not op_mini all"
58
104
  ];
59
- export const getBrowserslist = (appDirectory) => browserslist.loadConfig({
60
- path: appDirectory
61
- }) || defaults;
62
- export function getInternalPlugins(appDirectory, internalPlugins = INTERNAL_CLI_PLUGINS) {
63
- return [
64
- ...Object.keys(internalPlugins).filter((name) => {
65
- const config = internalPlugins[name];
66
- if (typeof config !== "string" && config.forced === true) {
67
- return true;
68
- }
69
- return isDepExists(appDirectory, name);
70
- }).map((name) => {
71
- const config = internalPlugins[name];
72
- if (typeof config !== "string") {
73
- return config.path;
74
- } else {
75
- return config;
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 const readTsConfig = (root) => {
127
+ export var readTsConfig = function(root) {
81
128
  return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
82
129
  };
83
- export const readTsConfigByFile = (filename) => {
84
- const content = fs.readFileSync(path.resolve(filename), "utf-8");
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 const getServerConfig = async (appDirectory, configFile) => {
5
- const configFilePath = findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(appDirectory, `${configFile}${extension}`)));
6
- return configFilePath;
7
- };
8
- export const getTargetDir = (from, baseDir, targetBaseDir) => {
9
- const relativePath = path.relative(baseDir, from);
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 const isSSR = (config) => {
3
- const { server } = config;
4
- if (server === null || server === void 0 ? void 0 : server.ssr) {
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 || server === void 0 ? void 0 : server.ssrByEntries) && !isEmpty(server.ssrByEntries)) {
8
- for (const name of Object.keys(server.ssrByEntries)) {
9
- if (server.ssrByEntries[name]) {
10
- return true;
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 const isUseSSRBundle = (config) => {
17
- const { output } = config;
18
- if (output === null || output === void 0 ? void 0 : output.ssg) {
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 const isServiceWorker = (config) => {
24
- var _deploy_worker;
25
- const { output, deploy } = config;
26
- 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))) {
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 const isRouterV5 = (config) => {
32
- var _config_runtime, _config_runtime1, _config_runtime_router;
33
- 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";
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 const isSSGEntry = (config, entryName, entrypoints) => {
36
- const ssgConfig = config.output.ssg;
37
- const useSSG = isSingleEntry(entrypoints) ? 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]);
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 const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
60
+ export var isSingleEntry = function(entrypoints) {
61
+ return entrypoints.length === 1 && entrypoints[0].entryName === "main";
62
+ };
@@ -1,6 +1,18 @@
1
- export const getNodeEnv = () => process.env.NODE_ENV || "development";
2
- export const isDev = () => getNodeEnv() === "development";
3
- export const isProd = () => getNodeEnv() === "production";
4
- export const isTest = () => getNodeEnv() === "test";
5
- export const isProdProfile = () => isProd() && process.argv.includes("--profile");
6
- export const isFastRefresh = () => isDev() && process.env.FAST_REFRESH !== "false";
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 const isNodeJS = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null && process.versions.electron == null;
2
- export const isBrowser = () => typeof window !== "undefined";
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
+ };