@modern-js/utils 2.25.2 → 2.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/universal/formatWebpack.js +0 -4
  3. package/dist/esm/cli/alias.js +26 -22
  4. package/dist/esm/cli/applyOptionsChain.js +8 -6
  5. package/dist/esm/cli/babel.js +50 -35
  6. package/dist/esm/cli/commands.js +7 -7
  7. package/dist/esm/cli/common.js +10 -5
  8. package/dist/esm/cli/constants/chainId.js +1 -1
  9. package/dist/esm/cli/constants/index.js +33 -37
  10. package/dist/esm/cli/ensure.js +4 -2
  11. package/dist/esm/cli/fs.js +56 -9
  12. package/dist/esm/cli/get/config.js +7 -7
  13. package/dist/esm/cli/get/data.js +93 -55
  14. package/dist/esm/cli/get/index.js +21 -6
  15. package/dist/esm/cli/is/config.js +33 -14
  16. package/dist/esm/cli/is/env.js +18 -6
  17. package/dist/esm/cli/is/platform.js +6 -2
  18. package/dist/esm/cli/is/project.js +73 -36
  19. package/dist/esm/cli/is/type.js +3 -1
  20. package/dist/esm/cli/logger.js +49 -38
  21. package/dist/esm/cli/monorepo.js +49 -36
  22. package/dist/esm/cli/package.js +156 -38
  23. package/dist/esm/cli/path.js +44 -20
  24. package/dist/esm/cli/pathSerializer.js +29 -15
  25. package/dist/esm/cli/port.js +89 -40
  26. package/dist/esm/cli/prettyInstructions.js +42 -31
  27. package/dist/esm/cli/require.js +21 -16
  28. package/dist/esm/cli/runtimeExports.js +21 -15
  29. package/dist/esm/cli/watch.js +94 -27
  30. package/dist/esm/compiled.js +3 -3
  31. package/dist/esm/import.js +4 -4
  32. package/dist/esm/runtime/nestedRoutes.js +42 -29
  33. package/dist/esm/runtime-browser/parsed.js +5 -5
  34. package/dist/esm/runtime-node/index.js +1 -1
  35. package/dist/esm/runtime-node/nestedRoutes.js +6 -4
  36. package/dist/esm/runtime-node/serialize.js +1 -1
  37. package/dist/esm/runtime-node/storage.js +12 -14
  38. package/dist/esm/universal/constants.js +3 -3
  39. package/dist/esm/universal/formatWebpack.js +20 -26
  40. package/dist/esm/universal/pluginDagSort.js +49 -26
  41. package/dist/esm-node/cli/alias.js +51 -0
  42. package/dist/esm-node/cli/applyOptionsChain.js +24 -0
  43. package/dist/esm-node/cli/babel.js +103 -0
  44. package/dist/esm-node/cli/commands.js +16 -0
  45. package/dist/esm-node/cli/common.js +10 -0
  46. package/dist/esm-node/cli/constants/chainId.js +180 -0
  47. package/dist/esm-node/cli/constants/index.js +103 -0
  48. package/dist/esm-node/cli/ensure.js +10 -0
  49. package/dist/esm-node/cli/fs.js +14 -0
  50. package/dist/esm-node/cli/get/config.js +16 -0
  51. package/dist/esm-node/cli/get/data.js +86 -0
  52. package/dist/esm-node/cli/get/index.js +13 -0
  53. package/dist/esm-node/cli/index.js +20 -0
  54. package/dist/esm-node/cli/is/config.js +40 -0
  55. package/dist/esm-node/cli/is/env.js +6 -0
  56. package/dist/esm-node/cli/is/index.js +5 -0
  57. package/dist/esm-node/cli/is/platform.js +2 -0
  58. package/dist/esm-node/cli/is/project.js +73 -0
  59. package/dist/esm-node/cli/is/type.js +25 -0
  60. package/dist/esm-node/cli/logger.js +103 -0
  61. package/dist/esm-node/cli/monorepo.js +70 -0
  62. package/dist/esm-node/cli/package.js +43 -0
  63. package/dist/esm-node/cli/path.js +49 -0
  64. package/dist/esm-node/cli/pathSerializer.js +46 -0
  65. package/dist/esm-node/cli/port.js +44 -0
  66. package/dist/esm-node/cli/prettyInstructions.js +77 -0
  67. package/dist/esm-node/cli/require.js +52 -0
  68. package/dist/esm-node/cli/runtimeExports.js +35 -0
  69. package/dist/esm-node/cli/watch.js +41 -0
  70. package/dist/esm-node/compiled.js +33 -0
  71. package/dist/esm-node/import.js +8 -0
  72. package/dist/esm-node/index.js +3 -0
  73. package/dist/esm-node/runtime/nestedRoutes.js +112 -0
  74. package/dist/esm-node/runtime/remixRouter.js +1 -0
  75. package/dist/esm-node/runtime/router.js +1 -0
  76. package/dist/esm-node/runtime-browser/index.js +1 -0
  77. package/dist/esm-node/runtime-browser/parsed.js +17 -0
  78. package/dist/esm-node/runtime-node/index.js +5 -0
  79. package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
  80. package/dist/esm-node/runtime-node/router.js +1 -0
  81. package/dist/esm-node/runtime-node/serialize.js +6 -0
  82. package/dist/esm-node/runtime-node/storage.js +38 -0
  83. package/dist/esm-node/universal/constants.js +3 -0
  84. package/dist/esm-node/universal/formatWebpack.js +61 -0
  85. package/dist/esm-node/universal/pluginDagSort.js +50 -0
  86. package/package.json +6 -6
@@ -1,35 +1,31 @@
1
- const friendlySyntaxErrorLabel = "SyntaxError:";
1
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
+ var friendlySyntaxErrorLabel = "SyntaxError:";
2
3
  function isLikelyASyntaxError(message) {
3
4
  return message.includes(friendlySyntaxErrorLabel);
4
5
  }
5
6
  function formatMessage(stats) {
6
- let lines = [];
7
- let message;
7
+ var lines = [];
8
+ var message;
8
9
  if (typeof stats === "object") {
9
- const fileName = stats.moduleName ? `File: ${stats.moduleName}
10
- ` : "";
11
- const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
12
- const details = stats.details ? `
13
- Details: ${stats.details}
14
- ` : "";
15
- const stack = stats.stack ? `
16
- ${stats.stack}` : "";
17
- message = `${fileName}${mainMessage}${details}${stack}`;
10
+ var fileName = stats.moduleName ? "File: ".concat(stats.moduleName, "\n") : "";
11
+ var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
12
+ var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
13
+ var stack = stats.stack ? "\n".concat(stats.stack) : "";
14
+ message = "".concat(fileName).concat(mainMessage).concat(details).concat(stack);
18
15
  } else {
19
16
  message = stats;
20
17
  }
21
18
  lines = message.split("\n");
22
- lines = lines.map((line) => {
23
- const parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
19
+ lines = lines.map(function(line) {
20
+ var parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
24
21
  if (!parsingError) {
25
22
  return line;
26
23
  }
27
- const [, errorLine, errorColumn, errorMessage] = parsingError;
28
- return `${friendlySyntaxErrorLabel} ${errorMessage} (${errorLine}:${errorColumn})`;
24
+ var _parsingError = _sliced_to_array(parsingError, 4), errorLine = _parsingError[1], errorColumn = _parsingError[2], errorMessage = _parsingError[3];
25
+ return "".concat(friendlySyntaxErrorLabel, " ").concat(errorMessage, " (").concat(errorLine, ":").concat(errorColumn, ")");
29
26
  });
30
27
  message = lines.join("\n");
31
- message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, `${friendlySyntaxErrorLabel} $3 ($1:$2)
32
- `);
28
+ message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "".concat(friendlySyntaxErrorLabel, " $3 ($1:$2)\n"));
33
29
  lines = message.split("\n");
34
30
  if (lines.length > 2 && lines[1].trim() === "") {
35
31
  lines.splice(1, 1);
@@ -38,19 +34,17 @@ ${stats.stack}` : "";
38
34
  if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
39
35
  lines[1] = lines[1].replace("Error: ", "");
40
36
  }
41
- message = lines.join("\n");
42
- message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, "");
43
- message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, "");
44
- lines = message.split("\n");
45
- lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim());
37
+ lines = lines.filter(function(line, index, arr) {
38
+ return index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim();
39
+ });
46
40
  message = lines.join("\n");
47
41
  return message.trim();
48
42
  }
49
43
  function formatWebpackMessages(json) {
50
44
  var _json_errors, _json_warnings, _result_errors;
51
- const formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
52
- const formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
53
- const result = {
45
+ var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
46
+ var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
47
+ var result = {
54
48
  errors: formattedErrors || [],
55
49
  warnings: formattedWarnings || []
56
50
  };
@@ -1,24 +1,51 @@
1
- export const pluginDagSort = (plugins, key = "name", preKey = "pre", postKey = "post") => {
2
- let allLines = [];
3
- function getPluginByAny(q) {
4
- const target = plugins.find((item) => typeof q === "string" ? item[key] === q : item[key] === q[key]);
1
+ export var pluginDagSort = function(plugins) {
2
+ var _loop = function() {
3
+ var zep = zeroEndPoints.shift();
4
+ sortedPoint.push(getPluginByAny(zep));
5
+ allLines = allLines.filter(function(l) {
6
+ return l[0] !== getPluginByAny(zep)[key];
7
+ });
8
+ var restPoints = plugins.filter(function(item) {
9
+ return !sortedPoint.find(function(sp) {
10
+ return sp[key] === item[key];
11
+ });
12
+ });
13
+ zeroEndPoints = restPoints.filter(
14
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
15
+ function(item) {
16
+ return !allLines.find(function(l) {
17
+ return l[1] === item[key];
18
+ });
19
+ }
20
+ );
21
+ };
22
+ var key = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "name", preKey = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "pre", postKey = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "post";
23
+ var getPluginByAny = function getPluginByAny2(q) {
24
+ var target = plugins.find(function(item) {
25
+ return typeof q === "string" ? item[key] === q : item[key] === q[key];
26
+ });
5
27
  if (!target) {
6
- throw new Error(`plugin ${q} not existed`);
28
+ throw new Error("plugin ".concat(q, " not existed"));
7
29
  }
8
30
  return target;
9
- }
10
- plugins.forEach((item) => {
31
+ };
32
+ var allLines = [];
33
+ plugins.forEach(function(item) {
11
34
  var _item_preKey, _item_postKey;
12
- (_item_preKey = item[preKey]) === null || _item_preKey === void 0 ? void 0 : _item_preKey.forEach((p) => {
13
- if (plugins.find((ap) => ap.name === p)) {
35
+ (_item_preKey = item[preKey]) === null || _item_preKey === void 0 ? void 0 : _item_preKey.forEach(function(p) {
36
+ if (plugins.find(function(ap) {
37
+ return ap.name === p;
38
+ })) {
14
39
  allLines.push([
15
40
  getPluginByAny(p)[key],
16
41
  getPluginByAny(item)[key]
17
42
  ]);
18
43
  }
19
44
  });
20
- (_item_postKey = item[postKey]) === null || _item_postKey === void 0 ? void 0 : _item_postKey.forEach((pt) => {
21
- if (plugins.find((ap) => ap.name === pt)) {
45
+ (_item_postKey = item[postKey]) === null || _item_postKey === void 0 ? void 0 : _item_postKey.forEach(function(pt) {
46
+ if (plugins.find(function(ap) {
47
+ return ap.name === pt;
48
+ })) {
22
49
  allLines.push([
23
50
  getPluginByAny(item)[key],
24
51
  getPluginByAny(pt)[key]
@@ -26,25 +53,21 @@ export const pluginDagSort = (plugins, key = "name", preKey = "pre", postKey = "
26
53
  }
27
54
  });
28
55
  });
29
- let zeroEndPoints = plugins.filter((item) => !allLines.find((l) => l[1] === item[key]));
30
- const sortedPoint = [];
31
- while (zeroEndPoints.length) {
32
- const zep = zeroEndPoints.shift();
33
- sortedPoint.push(getPluginByAny(zep));
34
- allLines = allLines.filter((l) => l[0] !== getPluginByAny(zep)[key]);
35
- const restPoints = plugins.filter((item) => !sortedPoint.find((sp) => sp[key] === item[key]));
36
- zeroEndPoints = restPoints.filter(
37
- // eslint-disable-next-line @typescript-eslint/no-loop-func
38
- (item) => !allLines.find((l) => l[1] === item[key])
39
- );
40
- }
56
+ var zeroEndPoints = plugins.filter(function(item) {
57
+ return !allLines.find(function(l) {
58
+ return l[1] === item[key];
59
+ });
60
+ });
61
+ var sortedPoint = [];
62
+ while (zeroEndPoints.length)
63
+ _loop();
41
64
  if (allLines.length) {
42
- const restInRingPoints = {};
43
- allLines.forEach((l) => {
65
+ var restInRingPoints = {};
66
+ allLines.forEach(function(l) {
44
67
  restInRingPoints[l[0]] = true;
45
68
  restInRingPoints[l[1]] = true;
46
69
  });
47
- throw new Error(`plugins dependences has loop: ${Object.keys(restInRingPoints).join(",")}`);
70
+ throw new Error("plugins dependences has loop: ".concat(Object.keys(restInRingPoints).join(",")));
48
71
  }
49
72
  return sortedPoint;
50
73
  };
@@ -0,0 +1,51 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { chalk } from "../compiled";
4
+ import { readTsConfigByFile } from "./get";
5
+ 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) => {
23
+ var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
24
+ const isTsProject = fs.existsSync(option.tsconfigPath);
25
+ const alias = mergeAlias(aliasOption);
26
+ if (!isTsProject) {
27
+ return {
28
+ absoluteBaseUrl: option.appDirectory,
29
+ paths: alias,
30
+ isTsPath: false,
31
+ isTsProject
32
+ };
33
+ }
34
+ const tsconfig = readTsConfigByFile(option.tsconfigPath);
35
+ const baseUrl = tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions === void 0 ? void 0 : _tsconfig_compilerOptions.baseUrl;
36
+ return {
37
+ absoluteBaseUrl: baseUrl ? path.join(option.appDirectory, baseUrl) : option.appDirectory,
38
+ paths: {
39
+ ...alias,
40
+ ...tsconfig === null || tsconfig === void 0 ? void 0 : (_tsconfig_compilerOptions1 = tsconfig.compilerOptions) === null || _tsconfig_compilerOptions1 === void 0 ? void 0 : _tsconfig_compilerOptions1.paths
41
+ },
42
+ isTsPath: true,
43
+ isTsProject
44
+ };
45
+ };
46
+ export const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
47
+ if (Array.isArray(alias[k])) {
48
+ o[k] = alias[k];
49
+ }
50
+ return o;
51
+ }, {});
@@ -0,0 +1,24 @@
1
+ import { isFunction, isPlainObject } from "./is";
2
+ import { logger } from "./logger";
3
+ export function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
4
+ if (!options) {
5
+ return defaults;
6
+ }
7
+ if (isPlainObject(options)) {
8
+ return mergeFn(defaults, options);
9
+ } else if (isFunction(options)) {
10
+ const ret = options(defaults, utils);
11
+ if (ret) {
12
+ if (!isPlainObject(ret)) {
13
+ logger.warn(`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`);
14
+ }
15
+ return ret;
16
+ }
17
+ } else if (Array.isArray(options)) {
18
+ return options.reduce((memo, cur) => applyOptionsChain(memo, cur, utils, mergeFn), defaults);
19
+ } else {
20
+ throw new Error(`applyOptionsChain error:
21
+ default options is: ${JSON.stringify(defaults)}`);
22
+ }
23
+ return defaults;
24
+ }
@@ -0,0 +1,103 @@
1
+ import { isAbsolute, sep } from "path";
2
+ import { applyOptionsChain } from "./applyOptionsChain";
3
+ import { ensureArray } from "./ensure";
4
+ import { normalizeToPosixPath } from "./path";
5
+ const formatPath = (originPath) => {
6
+ if (isAbsolute(originPath)) {
7
+ return originPath.split(sep).join("/");
8
+ }
9
+ return originPath;
10
+ };
11
+ const getPluginItemName = (item) => {
12
+ if (typeof item === "string") {
13
+ return formatPath(item);
14
+ }
15
+ if (Array.isArray(item) && typeof item[0] === "string") {
16
+ return formatPath(item[0]);
17
+ }
18
+ return null;
19
+ };
20
+ const addPlugins = (plugins, config) => {
21
+ if (config.plugins) {
22
+ config.plugins.push(...plugins);
23
+ } else {
24
+ config.plugins = plugins;
25
+ }
26
+ };
27
+ const addPresets = (presets, config) => {
28
+ if (config.presets) {
29
+ config.presets.push(...presets);
30
+ } else {
31
+ config.presets = presets;
32
+ }
33
+ };
34
+ const removePlugins = (plugins, config) => {
35
+ if (!config.plugins) {
36
+ return;
37
+ }
38
+ const removeList = ensureArray(plugins);
39
+ config.plugins = config.plugins.filter((item) => {
40
+ const name = getPluginItemName(item);
41
+ if (name) {
42
+ return !removeList.find((removeItem) => name.includes(removeItem));
43
+ }
44
+ return true;
45
+ });
46
+ };
47
+ const removePresets = (presets, config) => {
48
+ if (!config.presets) {
49
+ return;
50
+ }
51
+ const removeList = ensureArray(presets);
52
+ config.presets = config.presets.filter((item) => {
53
+ const name = getPluginItemName(item);
54
+ if (name) {
55
+ return !removeList.find((removeItem) => name.includes(removeItem));
56
+ }
57
+ return true;
58
+ });
59
+ };
60
+ const modifyPresetOptions = (presetName, options, presets = []) => {
61
+ presets.forEach((preset, index) => {
62
+ if (Array.isArray(preset)) {
63
+ if (typeof preset[0] === "string" && normalizeToPosixPath(preset[0]).includes(presetName)) {
64
+ preset[1] = {
65
+ ...preset[1] || {},
66
+ ...options
67
+ };
68
+ }
69
+ } else if (typeof preset === "string" && normalizeToPosixPath(preset).includes(presetName)) {
70
+ presets[index] = [
71
+ preset,
72
+ options
73
+ ];
74
+ }
75
+ });
76
+ };
77
+ export const getBabelUtils = (config) => {
78
+ const noop = () => {
79
+ };
80
+ return {
81
+ addPlugins: (plugins) => addPlugins(plugins, config),
82
+ addPresets: (presets) => addPresets(presets, config),
83
+ removePlugins: (plugins) => removePlugins(plugins, config),
84
+ removePresets: (presets) => removePresets(presets, config),
85
+ // `addIncludes` and `addExcludes` are noop functions by default,
86
+ // It can be overridden by `extraBabelUtils`.
87
+ addIncludes: noop,
88
+ addExcludes: noop,
89
+ // Compat `presetEnvOptions` and `presetReactOptions` in Eden.
90
+ modifyPresetEnvOptions: (options) => modifyPresetOptions("@babel/preset-env", options, config.presets || []),
91
+ modifyPresetReactOptions: (options) => modifyPresetOptions("@babel/preset-react", options, config.presets || [])
92
+ };
93
+ };
94
+ export const applyUserBabelConfig = (defaultOptions, userBabelConfig, extraBabelUtils) => {
95
+ if (userBabelConfig) {
96
+ const babelUtils = {
97
+ ...getBabelUtils(defaultOptions),
98
+ ...extraBabelUtils
99
+ };
100
+ return applyOptionsChain(defaultOptions, userBabelConfig || {}, babelUtils);
101
+ }
102
+ return defaultOptions;
103
+ };
@@ -0,0 +1,16 @@
1
+ export const getFullArgv = () => {
2
+ var _process_env_MODERN_ARGV;
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
+ };
5
+ export const getArgv = () => {
6
+ return getFullArgv().slice(2);
7
+ };
8
+ export const getCommand = () => {
9
+ const args = getArgv();
10
+ const command = args[0];
11
+ return command;
12
+ };
13
+ export const isDevCommand = () => {
14
+ const command = getCommand();
15
+ return command === "dev" || command === "start";
16
+ };
@@ -0,0 +1,10 @@
1
+ import { debug } from "../../compiled/debug";
2
+ export const createDebugger = (scope) => debug(`modern-js:${scope}`);
3
+ export const clearConsole = () => {
4
+ if (process.stdout.isTTY && !process.env.DEBUG) {
5
+ process.stdout.write("\x1B[H\x1B[2J");
6
+ }
7
+ };
8
+ export const wait = (time = 0) => new Promise((resolve) => {
9
+ setTimeout(resolve, time);
10
+ });
@@ -0,0 +1,180 @@
1
+ export const CHAIN_ID = {
2
+ /** Predefined rules */
3
+ RULE: {
4
+ /** Rule for .mjs */
5
+ MJS: "mjs",
6
+ /** Rule for predefined loaders */
7
+ LOADERS: "loaders",
8
+ /** Rule for fonts */
9
+ FONT: "font",
10
+ /** Rule for images */
11
+ IMAGE: "image",
12
+ /** Rule for media */
13
+ MEDIA: "media",
14
+ /** Rule for js */
15
+ JS: "js",
16
+ /** Rule for data uri encoded javascript */
17
+ JS_DATA_URI: "js-data-uri",
18
+ /** Rule for ts */
19
+ TS: "ts",
20
+ /** Rule for css */
21
+ CSS: "css",
22
+ /** Rule for less */
23
+ LESS: "less",
24
+ /** Rule for sass */
25
+ SASS: "sass",
26
+ /** Rule for stylus */
27
+ STYLUS: "stylus",
28
+ /** Rule for svg */
29
+ SVG: "svg",
30
+ /** Rule for pug */
31
+ PUG: "pug",
32
+ /** Rule for Vue */
33
+ VUE: "vue",
34
+ /** Rule for toml */
35
+ TOML: "toml",
36
+ /** Rule for yaml */
37
+ YAML: "yaml",
38
+ /** Rule for wasm */
39
+ WASM: "wasm",
40
+ /** Rule for bff */
41
+ JS_BFF_API: "js-bff-api"
42
+ },
43
+ /** Predefined rule groups */
44
+ ONE_OF: {
45
+ SVG: "svg",
46
+ SVG_URL: "svg-url",
47
+ SVG_ASSET: "svg-asset",
48
+ SVG_INLINE: "svg-inline"
49
+ },
50
+ /** Predefined loaders */
51
+ USE: {
52
+ /** ts-loader */
53
+ TS: "ts",
54
+ /** css-loader */
55
+ CSS: "css",
56
+ /** sass-loader */
57
+ SASS: "sass",
58
+ /** less-loader */
59
+ LESS: "less",
60
+ /** stylus-loader */
61
+ STYLUS: "stylus",
62
+ /** url-loader */
63
+ URL: "url",
64
+ /** pug-loader */
65
+ PUG: "pug",
66
+ /** vue-loader */
67
+ VUE: "vue",
68
+ /** file-loader */
69
+ FILE: "file",
70
+ /** @svgr/webpack */
71
+ SVGR: "svgr",
72
+ /** yaml-loader */
73
+ YAML: "yaml",
74
+ /** toml-loader */
75
+ TOML: "toml",
76
+ /** html-loader */
77
+ HTML: "html",
78
+ /** babel-loader */
79
+ BABEL: "babel",
80
+ /** esbuild-loader */
81
+ ESBUILD: "esbuild",
82
+ /** swc-loader */
83
+ SWC: "swc",
84
+ /** style-loader */
85
+ STYLE: "style-loader",
86
+ /** postcss-loader */
87
+ POSTCSS: "postcss",
88
+ /** markdown-loader */
89
+ MARKDOWN: "markdown",
90
+ /** ignore-css-loader */
91
+ IGNORE_CSS: "ignore-css",
92
+ /** css-modules-typescript-loader */
93
+ CSS_MODULES_TS: "css-modules-typescript",
94
+ /** mini-css-extract-plugin.loader */
95
+ MINI_CSS_EXTRACT: "mini-css-extract",
96
+ /** builder-plugin-image-compress.loader */
97
+ IMAGE_COMPRESS: "image-compress",
98
+ /** builder-plugin-image-compress svgo-loader */
99
+ SVGO: "svgo",
100
+ /** builder-plugin-imagex */
101
+ IMAGEX: "imagex"
102
+ },
103
+ /** Predefined plugins */
104
+ PLUGIN: {
105
+ /** HotModuleReplacementPlugin */
106
+ HMR: "hmr",
107
+ /** CopyWebpackPlugin */
108
+ COPY: "copy",
109
+ /** HtmlWebpackPlugin */
110
+ HTML: "html",
111
+ /** DefinePlugin */
112
+ DEFINE: "define",
113
+ /** IgnorePlugin */
114
+ IGNORE: "ignore",
115
+ /** BannerPlugin */
116
+ BANNER: "banner",
117
+ /** Webpackbar */
118
+ PROGRESS: "progress",
119
+ /** Inspector */
120
+ INSPECTOR: "inspector",
121
+ /** AppIconPlugin */
122
+ APP_ICON: "app-icon",
123
+ /** FaviconUrlPlugin */
124
+ FAVICON_URL: "favicon-url",
125
+ /** LoadableWebpackPlugin */
126
+ LOADABLE: "loadable",
127
+ /** WebpackManifestPlugin */
128
+ MANIFEST: "webpack-manifest",
129
+ /** ForkTsCheckerWebpackPlugin */
130
+ TS_CHECKER: "ts-checker",
131
+ /** InlineChunkHtmlPlugin */
132
+ INLINE_HTML: "inline-html",
133
+ /** WebpackBundleAnalyzer */
134
+ BUNDLE_ANALYZER: "bundle-analyze",
135
+ /** BottomTemplatePlugin */
136
+ BOTTOM_TEMPLATE: "bottom-template",
137
+ /** HtmlTagsPlugin */
138
+ HTML_TAGS: "html-tags",
139
+ /** HtmlNoncePlugin */
140
+ HTML_NONCE: "html-nonce",
141
+ /** HtmlCrossOriginPlugin */
142
+ HTML_CROSS_ORIGIN: "html-cross-origin",
143
+ /** MiniCssExtractPlugin */
144
+ MINI_CSS_EXTRACT: "mini-css-extract",
145
+ /** VueLoaderPlugin */
146
+ VUE_LOADER_PLUGIN: "vue-loader-plugin",
147
+ /** ReactFastRefreshPlugin */
148
+ REACT_FAST_REFRESH: "react-fast-refresh",
149
+ /** ProvidePlugin for node polyfill */
150
+ NODE_POLYFILL_PROVIDE: "node-polyfill-provide",
151
+ /** WebpackSRIPlugin */
152
+ SUBRESOURCE_INTEGRITY: "subresource-integrity",
153
+ /** WebpackAssetsRetryPlugin */
154
+ ASSETS_RETRY: "ASSETS_RETRY",
155
+ /** AutoSetRootFontSizePlugin */
156
+ AUTO_SET_ROOT_SIZE: "auto-set-root-size",
157
+ /** HtmlAsyncChunkPlugin */
158
+ HTML_ASYNC_CHUNK: "html-async-chunk",
159
+ /** SWC_POLYFILL_CHECKER */
160
+ SWC_POLYFILL_CHECKER: "swc-polyfill-checker-plugin"
161
+ },
162
+ /** Predefined minimizers */
163
+ MINIMIZER: {
164
+ /** TerserWebpackPlugin */
165
+ JS: "js",
166
+ /** CssMinimizerWebpackPlugin */
167
+ CSS: "css",
168
+ /** ESBuildPlugin */
169
+ ESBUILD: "js-css",
170
+ /** SWCPlugin */
171
+ SWC: "swc"
172
+ },
173
+ /** Predefined resolve plugins */
174
+ RESOLVE_PLUGIN: {
175
+ /** ModuleScopePlugin */
176
+ MODULE_SCOPE: "module-scope",
177
+ /** TsConfigPathsPlugin */
178
+ TS_CONFIG_PATHS: "ts-config-paths"
179
+ }
180
+ };
@@ -0,0 +1,103 @@
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 = [
14
+ ".js",
15
+ ".ts",
16
+ ".mjs"
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 = {
24
+ "@modern-js/app-tools": "@modern-js/app-tools/cli",
25
+ "@modern-js/plugin-proxy": "@modern-js/plugin-proxy/cli",
26
+ "@modern-js/plugin-ssg": "@modern-js/plugin-ssg/cli",
27
+ "@modern-js/plugin-bff": "@modern-js/plugin-bff/cli",
28
+ "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
29
+ "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
30
+ "@modern-js/plugin-express": "@modern-js/plugin-express/cli",
31
+ "@modern-js/plugin-koa": "@modern-js/plugin-koa/cli",
32
+ "@modern-js/plugin-server": "@modern-js/plugin-server/cli",
33
+ "@modern-js/plugin-garfish": "@modern-js/plugin-garfish/cli",
34
+ "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
35
+ "@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/cli",
36
+ // legacy router (inner react-router-dom v5)
37
+ "@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
38
+ };
39
+ export const INTERNAL_APP_TOOLS_RUNTIME_PLUGINS = {
40
+ "@modern-js/runtime": "@modern-js/runtime/cli"
41
+ };
42
+ export const INTERNAL_MODULE_TOOLS_PLUGINS = {
43
+ "@modern-js/module-tools": "@modern-js/module-tools",
44
+ "@modern-js/doc-tools": "@modern-js/doc-tools",
45
+ "@modern-js/runtime": "@modern-js/runtime/cli",
46
+ "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
47
+ "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
48
+ "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
49
+ // legacy router (inner react-router-dom v5)
50
+ "@modern-js/plugin-router-legacy": "@modern-js/plugin-router-legacy/cli"
51
+ };
52
+ export const INTERNAL_MONOREPO_TOOLS_PLUGINS = {
53
+ "@modern-js/monorepo-tools": "@modern-js/monorepo-tools/cli",
54
+ "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli"
55
+ };
56
+ export const INTERNAL_DOC_TOOLS_PLUGINS = {
57
+ "@modern-js/doc-tools": "@modern-js/doc-tools",
58
+ "@modern-js/runtime": "@modern-js/runtime/cli",
59
+ "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli"
60
+ };
61
+ export const INTERNAL_CLI_PLUGINS = {
62
+ "@modern-js/app-tools": "@modern-js/app-tools/cli",
63
+ "@modern-js/monorepo-tools": "@modern-js/monorepo-tools/cli",
64
+ "@modern-js/module-tools": "@modern-js/module-tools",
65
+ "@modern-js/doc-tools": "@modern-js/doc-tools",
66
+ "@modern-js/runtime": "@modern-js/runtime/cli",
67
+ "@modern-js/plugin-proxy": "@modern-js/plugin-proxy/cli",
68
+ "@modern-js/plugin-ssg": "@modern-js/plugin-ssg/cli",
69
+ "@modern-js/plugin-bff": "@modern-js/plugin-bff/cli",
70
+ "@modern-js/plugin-testing": "@modern-js/plugin-testing/cli",
71
+ "@modern-js/plugin-storybook": "@modern-js/plugin-storybook/cli",
72
+ "@modern-js/plugin-express": "@modern-js/plugin-express/cli",
73
+ "@modern-js/plugin-koa": "@modern-js/plugin-koa/cli",
74
+ "@modern-js/plugin-server": "@modern-js/plugin-server/cli",
75
+ "@modern-js/plugin-swc": "@modern-js/plugin-swc",
76
+ "@modern-js/plugin-garfish": "@modern-js/plugin-garfish/cli",
77
+ "@modern-js/plugin-tailwindcss": "@modern-js/plugin-tailwindcss/cli",
78
+ "@modern-js/plugin-polyfill": "@modern-js/plugin-polyfill/cli",
79
+ // legacy router (inner react-router-dom v5)
80
+ "@modern-js/plugin-router-v5": "@modern-js/plugin-router-v5/cli"
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 = {
95
+ allowNamespaces: true,
96
+ allExtensions: true,
97
+ allowDeclareFields: true,
98
+ // aligns Babel's behavior with TypeScript's default behavior.
99
+ // https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
100
+ optimizeConstEnums: true,
101
+ isTSX: true
102
+ };
103
+ export * from "./chainId";