@modern-js/utils 2.35.1 → 2.37.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. package/dist/cjs/cli/alias.js +45 -46
  2. package/dist/cjs/cli/applyOptionsChain.js +30 -13
  3. package/dist/cjs/cli/babel.js +36 -26
  4. package/dist/cjs/cli/commands.js +29 -21
  5. package/dist/cjs/cli/common.js +29 -20
  6. package/dist/cjs/cli/config.js +24 -7
  7. package/dist/cjs/cli/constants/chainId.js +24 -7
  8. package/dist/cjs/cli/constants/index.js +84 -113
  9. package/dist/cjs/cli/ensure.js +37 -18
  10. package/dist/cjs/cli/fs.js +29 -19
  11. package/dist/cjs/cli/get/config.js +26 -9
  12. package/dist/cjs/cli/get/data.js +67 -54
  13. package/dist/cjs/cli/get/index.js +46 -25
  14. package/dist/cjs/cli/index.js +58 -23
  15. package/dist/cjs/cli/is/config.js +37 -31
  16. package/dist/cjs/cli/is/env.js +32 -29
  17. package/dist/cjs/cli/is/index.js +26 -8
  18. package/dist/cjs/cli/is/project.js +67 -53
  19. package/dist/cjs/cli/is/type.js +39 -36
  20. package/dist/cjs/cli/logger.js +25 -130
  21. package/dist/cjs/cli/monorepo.js +58 -58
  22. package/dist/cjs/cli/package.js +34 -26
  23. package/dist/cjs/cli/path.js +64 -54
  24. package/dist/cjs/cli/port.js +39 -13
  25. package/dist/cjs/cli/prettyInstructions.js +48 -29
  26. package/dist/cjs/cli/require.js +35 -29
  27. package/dist/cjs/cli/runtimeExports.js +42 -16
  28. package/dist/cjs/cli/watch.js +41 -22
  29. package/dist/cjs/compiled.js +127 -138
  30. package/dist/cjs/import.js +25 -15
  31. package/dist/cjs/index.js +24 -6
  32. package/dist/cjs/universal/constants.js +32 -21
  33. package/dist/cjs/universal/formatWebpack.js +25 -15
  34. package/dist/cjs/universal/pluginDagSort.js +25 -8
  35. package/dist/esm/cli/alias.js +10 -22
  36. package/dist/esm/cli/applyOptionsChain.js +4 -1
  37. package/dist/esm/cli/babel.js +6 -2
  38. package/dist/esm/cli/commands.js +10 -4
  39. package/dist/esm/cli/common.js +8 -3
  40. package/dist/esm/cli/config.js +4 -1
  41. package/dist/esm/cli/constants/chainId.js +4 -1
  42. package/dist/esm/cli/constants/index.js +62 -39
  43. package/dist/esm/cli/ensure.js +6 -2
  44. package/dist/esm/cli/fs.js +6 -2
  45. package/dist/esm/cli/get/config.js +4 -1
  46. package/dist/esm/cli/get/data.js +18 -8
  47. package/dist/esm/cli/get/index.js +6 -2
  48. package/dist/esm/cli/is/config.js +14 -6
  49. package/dist/esm/cli/is/env.js +12 -8
  50. package/dist/esm/cli/is/index.js +0 -1
  51. package/dist/esm/cli/is/project.js +17 -8
  52. package/dist/esm/cli/is/type.js +20 -9
  53. package/dist/esm/cli/logger.js +4 -128
  54. package/dist/esm/cli/monorepo.js +14 -16
  55. package/dist/esm/cli/package.js +10 -4
  56. package/dist/esm/cli/path.js +24 -11
  57. package/dist/esm/cli/port.js +5 -2
  58. package/dist/esm/cli/prettyInstructions.js +6 -2
  59. package/dist/esm/cli/require.js +14 -6
  60. package/dist/esm/cli/runtimeExports.js +6 -3
  61. package/dist/esm/cli/watch.js +10 -6
  62. package/dist/esm/compiled.js +65 -31
  63. package/dist/esm/import.js +6 -3
  64. package/dist/esm/universal/constants.js +12 -4
  65. package/dist/esm/universal/formatWebpack.js +5 -2
  66. package/dist/esm/universal/pluginDagSort.js +5 -2
  67. package/dist/esm-node/cli/alias.js +8 -19
  68. package/dist/esm-node/cli/applyOptionsChain.js +4 -1
  69. package/dist/esm-node/cli/babel.js +6 -2
  70. package/dist/esm-node/cli/commands.js +10 -4
  71. package/dist/esm-node/cli/common.js +8 -3
  72. package/dist/esm-node/cli/config.js +4 -1
  73. package/dist/esm-node/cli/constants/chainId.js +4 -1
  74. package/dist/esm-node/cli/constants/index.js +62 -39
  75. package/dist/esm-node/cli/ensure.js +6 -2
  76. package/dist/esm-node/cli/fs.js +6 -2
  77. package/dist/esm-node/cli/get/config.js +4 -1
  78. package/dist/esm-node/cli/get/data.js +18 -8
  79. package/dist/esm-node/cli/get/index.js +6 -2
  80. package/dist/esm-node/cli/is/config.js +14 -6
  81. package/dist/esm-node/cli/is/env.js +12 -6
  82. package/dist/esm-node/cli/is/index.js +0 -1
  83. package/dist/esm-node/cli/is/project.js +16 -7
  84. package/dist/esm-node/cli/is/type.js +20 -9
  85. package/dist/esm-node/cli/logger.js +4 -113
  86. package/dist/esm-node/cli/monorepo.js +14 -18
  87. package/dist/esm-node/cli/package.js +10 -4
  88. package/dist/esm-node/cli/path.js +24 -11
  89. package/dist/esm-node/cli/port.js +4 -1
  90. package/dist/esm-node/cli/prettyInstructions.js +6 -2
  91. package/dist/esm-node/cli/require.js +14 -6
  92. package/dist/esm-node/cli/runtimeExports.js +4 -1
  93. package/dist/esm-node/cli/watch.js +6 -2
  94. package/dist/esm-node/compiled.js +65 -31
  95. package/dist/esm-node/import.js +5 -2
  96. package/dist/esm-node/universal/constants.js +12 -4
  97. package/dist/esm-node/universal/formatWebpack.js +5 -2
  98. package/dist/esm-node/universal/pluginDagSort.js +5 -2
  99. package/dist/types/cli/alias.d.ts +0 -5
  100. package/dist/types/cli/constants/index.d.ts +0 -14
  101. package/dist/types/cli/is/env.d.ts +1 -2
  102. package/dist/types/cli/is/index.d.ts +0 -1
  103. package/dist/types/cli/logger.d.ts +1 -69
  104. package/dist/types/cli/monorepo.d.ts +0 -1
  105. package/dist/types/universal/constants.d.ts +4 -0
  106. package/package.json +6 -13
  107. package/dist/cjs/cli/is/platform.js +0 -21
  108. package/dist/compiled/gradient-string/index.d.ts +0 -1
  109. package/dist/compiled/gradient-string/index.js +0 -1
  110. package/dist/compiled/gradient-string/license +0 -21
  111. package/dist/compiled/gradient-string/package.json +0 -1
  112. package/dist/compiled/webpack-dev-middleware/index.js +0 -7
  113. package/dist/compiled/webpack-dev-middleware/license +0 -20
  114. package/dist/compiled/webpack-dev-middleware/package.json +0 -1
  115. package/dist/compiled/webpack-dev-middleware/types/index.d.ts +0 -262
  116. package/dist/esm/cli/is/platform.js +0 -6
  117. package/dist/esm-node/cli/is/platform.js +0 -2
  118. package/dist/types/cli/is/platform.d.ts +0 -2
@@ -1,13 +1,13 @@
1
1
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
2
  import { findExists } from "./fs";
3
- export var compatRequire = function(filePath) {
3
+ var compatRequire = function(filePath) {
4
4
  var interop = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
5
5
  var mod = require(filePath);
6
6
  var rtnESMDefault = interop && (mod === null || mod === void 0 ? void 0 : mod.__esModule);
7
7
  return rtnESMDefault ? mod.default : mod;
8
8
  };
9
- export var dynamicImport = new Function("modulePath", "return import(modulePath)");
10
- export var requireExistModule = function(filename, opt) {
9
+ var dynamicImport = new Function("modulePath", "return import(modulePath)");
10
+ var requireExistModule = function(filename, opt) {
11
11
  var final = _object_spread({
12
12
  extensions: [
13
13
  ".ts",
@@ -23,12 +23,12 @@ export var requireExistModule = function(filename, opt) {
23
23
  }
24
24
  return compatRequire(exist, final.interop);
25
25
  };
26
- export var cleanRequireCache = function(filelist) {
26
+ var cleanRequireCache = function(filelist) {
27
27
  filelist.forEach(function(filepath) {
28
28
  delete require.cache[filepath];
29
29
  });
30
30
  };
31
- export function deleteRequireCache(path) {
31
+ function deleteRequireCache(path) {
32
32
  if (require.cache[path]) {
33
33
  delete require.cache[path];
34
34
  }
@@ -38,7 +38,7 @@ export function deleteRequireCache(path) {
38
38
  });
39
39
  }
40
40
  }
41
- export var tryResolve = function(name, resolvePath) {
41
+ var tryResolve = function(name, resolvePath) {
42
42
  var filePath = "";
43
43
  try {
44
44
  filePath = require.resolve(name, {
@@ -55,3 +55,11 @@ export var tryResolve = function(name, resolvePath) {
55
55
  }
56
56
  return filePath;
57
57
  };
58
+ export {
59
+ cleanRequireCache,
60
+ compatRequire,
61
+ deleteRequireCache,
62
+ dynamicImport,
63
+ requireExistModule,
64
+ tryResolve
65
+ };
@@ -18,7 +18,7 @@ var memo = function(fn) {
18
18
  return res;
19
19
  };
20
20
  };
21
- export var createRuntimeExportsUtils = memo(function() {
21
+ var createRuntimeExportsUtils = memo(function() {
22
22
  var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", namespace = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "index";
23
23
  var entryExportFile = path.join(pwd, ".runtime-exports/".concat(namespace, ".js"));
24
24
  var addExport = function(statement) {
@@ -35,7 +35,10 @@ export var createRuntimeExportsUtils = memo(function() {
35
35
  return entryExportFile;
36
36
  };
37
37
  return {
38
- addExport: addExport,
39
- getPath: getPath
38
+ addExport,
39
+ getPath
40
40
  };
41
41
  });
42
+ export {
43
+ createRuntimeExportsUtils
44
+ };
@@ -2,16 +2,16 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
4
  import { chokidar } from "../compiled";
5
- export var WatchChangeType = {
5
+ var WatchChangeType = {
6
6
  ADD: "add",
7
7
  UNLINK: "unlink",
8
8
  CHANGE: "change"
9
9
  };
10
- export var watch = function(watchDir, runTask) {
10
+ var watch = function(watchDir, runTask) {
11
11
  var ignored = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
12
12
  var ready = false;
13
13
  var watcher = chokidar.watch(watchDir, {
14
- ignored: ignored
14
+ ignored
15
15
  });
16
16
  watcher.on("ready", function() {
17
17
  return ready = true;
@@ -26,7 +26,7 @@ export var watch = function(watchDir, runTask) {
26
26
  return [
27
27
  4,
28
28
  runTask({
29
- changedFilePath: changedFilePath,
29
+ changedFilePath,
30
30
  changeType: WatchChangeType.CHANGE
31
31
  })
32
32
  ];
@@ -57,7 +57,7 @@ export var watch = function(watchDir, runTask) {
57
57
  return [
58
58
  4,
59
59
  runTask({
60
- changedFilePath: changedFilePath,
60
+ changedFilePath,
61
61
  changeType: WatchChangeType.ADD
62
62
  })
63
63
  ];
@@ -85,7 +85,7 @@ export var watch = function(watchDir, runTask) {
85
85
  return [
86
86
  4,
87
87
  runTask({
88
- changedFilePath: changedFilePath,
88
+ changedFilePath,
89
89
  changeType: WatchChangeType.UNLINK
90
90
  })
91
91
  ];
@@ -106,3 +106,7 @@ export var watch = function(watchDir, runTask) {
106
106
  });
107
107
  return watcher;
108
108
  };
109
+ export {
110
+ WatchChangeType,
111
+ watch
112
+ };
@@ -1,32 +1,66 @@
1
1
  import { Import } from "./import";
2
- export { default as fs } from "../compiled/fs-extra";
3
- export { default as ora } from "../compiled/ora";
4
- export { default as glob } from "../compiled/glob";
5
- export { default as yaml } from "../compiled/js-yaml";
6
- export { default as chalk } from "../compiled/chalk";
7
- export { default as debug } from "../compiled/debug";
8
- export { default as slash } from "../compiled/slash";
9
- export { default as execa } from "../compiled/execa";
10
- export { default as json5 } from "../compiled/json5";
11
- export { default as upath } from "../compiled/upath";
12
- export { default as pkgUp } from "../compiled/pkg-up";
13
- export { nanoid } from "../compiled/nanoid";
14
- export { default as semver } from "../compiled/semver";
15
- export { default as dotenv } from "../compiled/dotenv";
16
- export { default as lodash } from "../compiled/lodash";
17
- export { default as globby } from "../compiled/globby";
18
- export { default as address } from "../compiled/address";
19
- export { default as signale } from "../compiled/signale";
20
- export { default as urlJoin } from "../compiled/url-join";
21
- export { default as minimist } from "../compiled/minimist";
22
- export { default as fastGlob } from "../compiled/fast-glob";
23
- export { default as filesize } from "../compiled/filesize";
24
- export { default as gzipSize } from "../compiled/gzip-size";
25
- export { default as stripAnsi } from "../compiled/strip-ansi";
26
- export { default as dotenvExpand } from "../compiled/dotenv-expand";
27
- export { default as browserslist } from "../compiled/browserslist";
28
- export { program, Command } from "../compiled/commander";
29
- export { Signale } from "../compiled/signale";
30
- export var mime = Import.lazy("../compiled/mime-types", require);
31
- export var chokidar = Import.lazy("../compiled/chokidar", require);
32
- export var inquirer = Import.lazy("../compiled/inquirer", require);
2
+ import { default as default2 } from "../compiled/fs-extra";
3
+ import { default as default3 } from "../compiled/ora";
4
+ import { default as default4 } from "../compiled/glob";
5
+ import { default as default5 } from "../compiled/js-yaml";
6
+ import { default as default6 } from "../compiled/chalk";
7
+ import { default as default7 } from "../compiled/debug";
8
+ import { default as default8 } from "../compiled/slash";
9
+ import { default as default9 } from "../compiled/execa";
10
+ import { default as default10 } from "../compiled/json5";
11
+ import { default as default11 } from "../compiled/upath";
12
+ import { default as default12 } from "../compiled/pkg-up";
13
+ import { nanoid } from "../compiled/nanoid";
14
+ import { default as default13 } from "../compiled/semver";
15
+ import { default as default14 } from "../compiled/dotenv";
16
+ import { default as default15 } from "../compiled/lodash";
17
+ import { default as default16 } from "../compiled/globby";
18
+ import { default as default17 } from "../compiled/address";
19
+ import { default as default18 } from "../compiled/signale";
20
+ import { default as default19 } from "../compiled/url-join";
21
+ import { default as default20 } from "../compiled/minimist";
22
+ import { default as default21 } from "../compiled/fast-glob";
23
+ import { default as default22 } from "../compiled/filesize";
24
+ import { default as default23 } from "../compiled/gzip-size";
25
+ import { default as default24 } from "../compiled/strip-ansi";
26
+ import { default as default25 } from "../compiled/dotenv-expand";
27
+ import { default as default26 } from "../compiled/browserslist";
28
+ import { program, Command } from "../compiled/commander";
29
+ import { Signale } from "../compiled/signale";
30
+ var mime = Import.lazy("../compiled/mime-types", require);
31
+ var chokidar = Import.lazy("../compiled/chokidar", require);
32
+ var inquirer = Import.lazy("../compiled/inquirer", require);
33
+ export {
34
+ Command,
35
+ Signale,
36
+ default17 as address,
37
+ default26 as browserslist,
38
+ default6 as chalk,
39
+ chokidar,
40
+ default7 as debug,
41
+ default14 as dotenv,
42
+ default25 as dotenvExpand,
43
+ default9 as execa,
44
+ default21 as fastGlob,
45
+ default22 as filesize,
46
+ default2 as fs,
47
+ default4 as glob,
48
+ default16 as globby,
49
+ default23 as gzipSize,
50
+ inquirer,
51
+ default10 as json5,
52
+ default15 as lodash,
53
+ mime,
54
+ default20 as minimist,
55
+ nanoid,
56
+ default3 as ora,
57
+ default12 as pkgUp,
58
+ program,
59
+ default13 as semver,
60
+ default18 as signale,
61
+ default8 as slash,
62
+ default24 as stripAnsi,
63
+ default11 as upath,
64
+ default19 as urlJoin,
65
+ default5 as yaml
66
+ };
@@ -2,7 +2,10 @@ var lazy = function(moduleName, requireFn) {
2
2
  var importLazyLocal = require("../compiled/import-lazy")(requireFn);
3
3
  return importLazyLocal(moduleName);
4
4
  };
5
- export { lazy as lazyImport };
6
- export var Import = {
7
- lazy: lazy
5
+ var Import = {
6
+ lazy
7
+ };
8
+ export {
9
+ Import,
10
+ lazy as lazyImport
8
11
  };
@@ -1,4 +1,12 @@
1
- export var ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
2
- export var HMR_SOCK_PATH = "/webpack-hmr";
3
- export var HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
4
- export var LOADER_REPORTER_NAME = "server-loader";
1
+ var ROUTE_MANIFEST = "_MODERNJS_ROUTE_MANIFEST";
2
+ var ROUTE_MODULES = "_routeModules";
3
+ var HMR_SOCK_PATH = "/webpack-hmr";
4
+ var HTML_CHUNKSMAP_SEPARATOR = "<!--<?- chunksMap.js ?>-->";
5
+ var LOADER_REPORTER_NAME = "server-loader";
6
+ export {
7
+ HMR_SOCK_PATH,
8
+ HTML_CHUNKSMAP_SEPARATOR,
9
+ LOADER_REPORTER_NAME,
10
+ ROUTE_MANIFEST,
11
+ ROUTE_MODULES
12
+ };
@@ -50,7 +50,7 @@ var defaultColor = {
50
50
  yellow: noop,
51
51
  underline: noop
52
52
  };
53
- export function addErrorTips(errors) {
53
+ function addErrorTips(errors) {
54
54
  var color = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : defaultColor;
55
55
  var errorHelpers = [
56
56
  {
@@ -88,4 +88,7 @@ function formatWebpackMessages(json) {
88
88
  result.errors = addErrorTips(result.errors, color);
89
89
  return result;
90
90
  }
91
- export { formatWebpackMessages };
91
+ export {
92
+ addErrorTips,
93
+ formatWebpackMessages
94
+ };
@@ -1,4 +1,4 @@
1
- export var pluginDagSort = function(plugins) {
1
+ var pluginDagSort = function(plugins) {
2
2
  var _loop = function() {
3
3
  var zep = zeroEndPoints.shift();
4
4
  sortedPoint.push(getPluginByAny(zep));
@@ -67,7 +67,10 @@ export var pluginDagSort = function(plugins) {
67
67
  restInRingPoints[l[0]] = true;
68
68
  restInRingPoints[l[1]] = true;
69
69
  });
70
- throw new Error("plugins dependences has loop: ".concat(Object.keys(restInRingPoints).join(",")));
70
+ throw new Error("plugins dependencies has loop: ".concat(Object.keys(restInRingPoints).join(",")));
71
71
  }
72
72
  return sortedPoint;
73
73
  };
74
+ export {
75
+ pluginDagSort
76
+ };
@@ -1,25 +1,9 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { chalk } from "../compiled";
4
3
  import { readTsConfigByFile } from "./get";
5
4
  import { applyOptionsChain } from "./applyOptionsChain";
6
- export const validAlias = (modernConfig, { tsconfigPath }) => {
7
- const { source: { alias } } = modernConfig;
8
- if (!alias) {
9
- return null;
10
- }
11
- const isTsProject = fs.existsSync(tsconfigPath);
12
- if (!isTsProject) {
13
- return null;
14
- }
15
- const userAlias = getUserAlias(alias);
16
- if (Object.keys(userAlias).length > 0) {
17
- return chalk.red('Note: Please use `compilerOptions.paths` in "tsconfig.json" file replace `source.alias` config in "modern.config.js/ts" when project is typescript');
18
- }
19
- return null;
20
- };
21
- export const mergeAlias = (alias) => applyOptionsChain({}, alias);
22
- export const getAliasConfig = (aliasOption, option) => {
5
+ const mergeAlias = (alias) => applyOptionsChain({}, alias);
6
+ const getAliasConfig = (aliasOption, option) => {
23
7
  var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
24
8
  const isTsProject = fs.existsSync(option.tsconfigPath);
25
9
  const alias = mergeAlias(aliasOption);
@@ -43,9 +27,14 @@ export const getAliasConfig = (aliasOption, option) => {
43
27
  isTsProject
44
28
  };
45
29
  };
46
- export const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
30
+ const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
47
31
  if (Array.isArray(alias[k])) {
48
32
  o[k] = alias[k];
49
33
  }
50
34
  return o;
51
35
  }, {});
36
+ export {
37
+ getAliasConfig,
38
+ getUserAlias,
39
+ mergeAlias
40
+ };
@@ -1,6 +1,6 @@
1
1
  import { isFunction, isPlainObject } from "./is";
2
2
  import { logger } from "./logger";
3
- export function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
3
+ function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
4
4
  if (!options) {
5
5
  return defaults;
6
6
  }
@@ -22,3 +22,6 @@ default options is: ${JSON.stringify(defaults)}`);
22
22
  }
23
23
  return defaults;
24
24
  }
25
+ export {
26
+ applyOptionsChain
27
+ };
@@ -74,7 +74,7 @@ const modifyPresetOptions = (presetName, options, presets = []) => {
74
74
  }
75
75
  });
76
76
  };
77
- export const getBabelUtils = (config) => {
77
+ const getBabelUtils = (config) => {
78
78
  const noop = () => {
79
79
  };
80
80
  return {
@@ -91,7 +91,7 @@ export const getBabelUtils = (config) => {
91
91
  modifyPresetReactOptions: (options) => modifyPresetOptions("@babel/preset-react", options, config.presets || [])
92
92
  };
93
93
  };
94
- export const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils) => {
94
+ const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils) => {
95
95
  if (userBabelConfig) {
96
96
  const babelUtils = {
97
97
  ...getBabelUtils(defaultOptions),
@@ -101,3 +101,7 @@ export const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabel
101
101
  }
102
102
  return defaultOptions;
103
103
  };
104
+ export {
105
+ applyUserBabelConfig,
106
+ getBabelUtils
107
+ };
@@ -1,16 +1,22 @@
1
- export const getFullArgv = () => {
1
+ const getFullArgv = () => {
2
2
  var _process_env_MODERN_ARGV;
3
3
  return ((_process_env_MODERN_ARGV = process.env.MODERN_ARGV) === null || _process_env_MODERN_ARGV === void 0 ? void 0 : _process_env_MODERN_ARGV.split(" ")) || process.argv;
4
4
  };
5
- export const getArgv = () => {
5
+ const getArgv = () => {
6
6
  return getFullArgv().slice(2);
7
7
  };
8
- export const getCommand = () => {
8
+ const getCommand = () => {
9
9
  const args = getArgv();
10
10
  const command = args[0];
11
11
  return command;
12
12
  };
13
- export const isDevCommand = () => {
13
+ const isDevCommand = () => {
14
14
  const command = getCommand();
15
15
  return command === "dev" || command === "start";
16
16
  };
17
+ export {
18
+ getArgv,
19
+ getCommand,
20
+ getFullArgv,
21
+ isDevCommand
22
+ };
@@ -1,10 +1,15 @@
1
1
  import { debug } from "../../compiled/debug";
2
- export const createDebugger = (scope) => debug(`modern-js:${scope}`);
3
- export const clearConsole = () => {
2
+ const createDebugger = (scope) => debug(`modern-js:${scope}`);
3
+ const clearConsole = () => {
4
4
  if (process.stdout.isTTY && !process.env.DEBUG) {
5
5
  process.stdout.write("\x1B[H\x1B[2J");
6
6
  }
7
7
  };
8
- export const wait = (time = 0) => new Promise((resolve) => {
8
+ const wait = (time = 0) => new Promise((resolve) => {
9
9
  setTimeout(resolve, time);
10
10
  });
11
+ export {
12
+ clearConsole,
13
+ createDebugger,
14
+ wait
15
+ };
@@ -1,5 +1,8 @@
1
- export const isOverriddenConfigKey = (key) => [
1
+ const isOverriddenConfigKey = (key) => [
2
2
  "removeConsole",
3
3
  "enableInlineScripts",
4
4
  "enableInlineStyles"
5
5
  ].includes(key);
6
+ export {
7
+ isOverriddenConfigKey
8
+ };
@@ -1,4 +1,4 @@
1
- export const CHAIN_ID = {
1
+ const CHAIN_ID = {
2
2
  /** Predefined rules */
3
3
  RULE: {
4
4
  /** Rule for .mjs */
@@ -192,3 +192,6 @@ export const CHAIN_ID = {
192
192
  TS_CONFIG_PATHS: "ts-config-paths"
193
193
  }
194
194
  };
195
+ export {
196
+ CHAIN_ID
197
+ };
@@ -1,26 +1,26 @@
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/bundle-require";
13
- export const CONFIG_FILE_EXTENSIONS = [
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
- 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 = {
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
- export const INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
39
+ const INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
40
40
  "@modern-js/runtime": "@modern-js/runtime/cli"
41
41
  };
42
- export const INTERNAL_MODULE_TOOLS_PLUGINS = {
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
- export const INTERNAL_MONOREPO_TOOLS_PLUGINS = {
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
- export const INTERNAL_DOC_TOOLS_PLUGINS = {
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
- export const INTERNAL_CLI_PLUGINS = {
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,25 +78,48 @@ 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
- export const SERVER_PLUGIN_BFF = "@modern-js/plugin-bff";
82
- export const SERVER_PLUGIN_EXPRESS = "@modern-js/plugin-express";
83
- export const SERVER_PLUGIN_KOA = "@modern-js/plugin-koa";
84
- export const SERVER_PLUGIN_SERVER = "@modern-js/plugin-server";
85
- export const SERVER_PLUGIN_POLYFILL = "@modern-js/plugin-polyfill";
86
- export const INTERNAL_SERVER_PLUGINS = {
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
- export const DEFAULT_BABEL_PRESET_TYPESCRIPT_OPTIONS = {
94
- allowNamespaces: true,
95
- allExtensions: true,
96
- allowDeclareFields: true,
97
- // aligns Babel's behavior with TypeScript's default behavior.
98
- // https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
99
- optimizeConstEnums: true,
100
- isTSX: true
101
- };
102
93
  export * from "./chainId";
94
+ export {
95
+ API_DIR,
96
+ CONFIG_CACHE_DIR,
97
+ CONFIG_FILE_EXTENSIONS,
98
+ DEFAULT_DEV_HOST,
99
+ DEFAULT_SERVER_CONFIG,
100
+ ENTRY_NAME_PATTERN,
101
+ INTERNAL_APP_TOOLS_PLUGINS,
102
+ INTERNAL_APP_TOOLS_RUNTIME_PLUGINS,
103
+ INTERNAL_CLI_PLUGINS,
104
+ INTERNAL_DOC_TOOLS_PLUGINS,
105
+ INTERNAL_MODULE_TOOLS_PLUGINS,
106
+ INTERNAL_MONOREPO_TOOLS_PLUGINS,
107
+ INTERNAL_SERVER_PLUGINS,
108
+ LOADABLE_STATS_FILE,
109
+ LOADER_ROUTES_DIR,
110
+ MAIN_ENTRY_NAME,
111
+ NESTED_ROUTE_SPEC_FILE,
112
+ OUTPUT_CONFIG_FILE,
113
+ ROUTE_MANIFEST_FILE,
114
+ ROUTE_SPEC_FILE,
115
+ SERVER_BUNDLE_DIRECTORY,
116
+ SERVER_DIR,
117
+ SERVER_PLUGIN_BFF,
118
+ SERVER_PLUGIN_EXPRESS,
119
+ SERVER_PLUGIN_KOA,
120
+ SERVER_PLUGIN_POLYFILL,
121
+ SERVER_PLUGIN_SERVER,
122
+ SERVER_RENDER_FUNCTION_NAME,
123
+ SERVER_WORKER_BUNDLE_DIRECTORY,
124
+ SHARED_DIR
125
+ };
@@ -1,6 +1,6 @@
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
+ 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
+ };
@@ -1,5 +1,5 @@
1
1
  import { fs } from "../compiled";
2
- export const findExists = (files) => {
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
- export const emptyDir = async (dir) => {
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
- export const getEntryOptions = (name, isMainEntry, baseOptions, optionsByEntries, packageName) => {
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
+ };