@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,49 +1,73 @@
1
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
2
  import path from "path";
2
3
  import os from "os";
3
4
  import fs from "fs";
4
5
  import { nanoid, upath, lodash as _ } from "../compiled";
5
- export const isPathString = (test) => path.posix.basename(test) !== test || path.win32.basename(test) !== test;
6
- export const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
7
- export const normalizeOutputPath = (s) => s.replace(/\\/g, "\\\\");
8
- export const normalizeToPosixPath = (p) => upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_2, m) => `/${m.toLowerCase()}`);
9
- export const getTemplatePath = (prefix) => {
10
- const tmpRoot = fs.realpathSync(os.tmpdir());
11
- const parts = [
6
+ export var isPathString = function(test) {
7
+ return path.posix.basename(test) !== test || path.win32.basename(test) !== test;
8
+ };
9
+ export var isRelativePath = function(test) {
10
+ return /^\.\.?($|[\\/])/.test(test);
11
+ };
12
+ export var normalizeOutputPath = function(s) {
13
+ return s.replace(/\\/g, "\\\\");
14
+ };
15
+ export var normalizeToPosixPath = function(p) {
16
+ return upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, function(_2, m) {
17
+ return "/".concat(m.toLowerCase());
18
+ });
19
+ };
20
+ export var getTemplatePath = function(prefix) {
21
+ var _path;
22
+ var tmpRoot = fs.realpathSync(os.tmpdir());
23
+ var parts = [
12
24
  tmpRoot
13
25
  ];
14
26
  prefix && parts.push(prefix);
15
27
  parts.push(nanoid());
16
- return path.resolve(...parts);
28
+ return (_path = path).resolve.apply(_path, _to_consumable_array(parts));
17
29
  };
18
30
  export function compilePathMatcherRegExp(match) {
19
31
  if (typeof match !== "string") {
20
32
  return match;
21
33
  }
22
- const escaped = _.escapeRegExp(match);
23
- return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
34
+ var escaped = _.escapeRegExp(match);
35
+ return new RegExp("(?<=\\W|^)".concat(escaped, "(?=\\W|$)"));
24
36
  }
25
- export const _joinPathParts = (_part, i, parts) => _(parts).filter((part) => ![
26
- "/",
27
- "\\"
28
- ].includes(part)).tap((parts2) => parts2.unshift("")).slice(0, i + 2).join("/");
37
+ export var _joinPathParts = function(_part, i, parts) {
38
+ return _(parts).filter(function(part) {
39
+ return ![
40
+ "/",
41
+ "\\"
42
+ ].includes(part);
43
+ }).tap(function(parts2) {
44
+ return parts2.unshift("");
45
+ }).slice(0, i + 2).join("/");
46
+ };
29
47
  export function upwardPaths(start) {
30
48
  return _(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
31
49
  }
32
50
  export function getRealTemporaryDirectory() {
33
- let ret = null;
51
+ var ret = null;
34
52
  try {
35
53
  ret = os.tmpdir();
36
54
  ret = fs.realpathSync(ret);
37
- } catch {
55
+ } catch (e) {
38
56
  }
39
57
  return ret;
40
58
  }
41
59
  export function splitPathString(str) {
42
60
  return str.split(/[\\/]/);
43
61
  }
44
- export const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
45
- export const removeTailSlash = (s) => s.replace(/\/+$/, "");
46
- export const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
47
- export const cutNameByHyphen = (s) => {
62
+ export var removeLeadingSlash = function(s) {
63
+ return s.replace(/^\/+/, "");
64
+ };
65
+ export var removeTailSlash = function(s) {
66
+ return s.replace(/\/+$/, "");
67
+ };
68
+ export var removeSlash = function(s) {
69
+ return removeLeadingSlash(removeTailSlash(s));
70
+ };
71
+ export var cutNameByHyphen = function(s) {
48
72
  return s.split(/[-_]/)[0];
49
73
  };
@@ -1,34 +1,48 @@
1
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
2
  import os from "os";
2
3
  import _ from "../../compiled/lodash";
3
4
  import { compilePathMatcherRegExp, normalizeToPosixPath, getRealTemporaryDirectory, splitPathString, upwardPaths } from "./path";
4
- export const matchUpwardPathsAsUnknown = (p) => _(upwardPaths(normalizeToPosixPath(p))).map((match) => ({
5
- match,
6
- mark: "unknown"
7
- })).slice(1, -1).value();
8
- export function applyPathMatcher(matcher, str, options = {}) {
9
- const regex = compilePathMatcherRegExp(matcher.match);
10
- const replacer = (substring, ...args) => {
5
+ export var matchUpwardPathsAsUnknown = function(p) {
6
+ return _(upwardPaths(normalizeToPosixPath(p))).map(function(match) {
7
+ return {
8
+ match: match,
9
+ mark: "unknown"
10
+ };
11
+ }).slice(1, -1).value();
12
+ };
13
+ export function applyPathMatcher(matcher, str) {
14
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
15
+ var regex = compilePathMatcherRegExp(matcher.match);
16
+ var replacer = function(substring) {
17
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
18
+ args[_key - 1] = arguments[_key];
19
+ }
20
+ var _matcher;
11
21
  if (options.minPartials && splitPathString(substring).length < options.minPartials) {
12
22
  return substring;
13
23
  }
14
- const ret = typeof matcher.mark === "string" ? matcher.mark : matcher.mark(substring, ...args);
15
- return `<${_.snakeCase(ret).toUpperCase()}>`;
24
+ var ret = typeof matcher.mark === "string" ? matcher.mark : (_matcher = matcher).mark.apply(_matcher, [
25
+ substring
26
+ ].concat(_to_consumable_array(args)));
27
+ return "<".concat(_.snakeCase(ret).toUpperCase(), ">");
16
28
  };
17
29
  return str.replace(regex, replacer);
18
30
  }
19
- export function applyMatcherReplacement(matchers, str, options = {}) {
20
- return matchers.reduce((ret, matcher) => {
31
+ export function applyMatcherReplacement(matchers, str) {
32
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
33
+ return matchers.reduce(function(ret, matcher) {
21
34
  return applyPathMatcher(matcher, ret, options);
22
35
  }, str);
23
36
  }
24
- export const createDefaultPathMatchers = (root) => {
25
- const ret = [
37
+ export var createDefaultPathMatchers = function(root) {
38
+ var _ret;
39
+ var ret = [
26
40
  {
27
41
  match: RegExp("(?<=\\/)(\\.pnpm\\/.+?\\/node_modules)(?=\\/)"),
28
42
  mark: "pnpmInner"
29
43
  }
30
44
  ];
31
- const tmpdir = getRealTemporaryDirectory();
45
+ var tmpdir = getRealTemporaryDirectory();
32
46
  tmpdir && ret.push({
33
47
  match: tmpdir,
34
48
  mark: "temp"
@@ -41,6 +55,6 @@ export const createDefaultPathMatchers = (root) => {
41
55
  match: os.homedir(),
42
56
  mark: "home"
43
57
  });
44
- ret.push(...matchUpwardPathsAsUnknown(root));
58
+ (_ret = ret).push.apply(_ret, _to_consumable_array(matchUpwardPathsAsUnknown(root)));
45
59
  return ret;
46
60
  };
@@ -1,44 +1,93 @@
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 net from "net";
2
4
  import { chalk } from "../compiled";
3
5
  import { logger } from "./logger";
4
- export const getPort = async (port, { tryLimits = 20, strictPort = false } = {}) => {
5
- if (typeof port === "string") {
6
- port = parseInt(port, 10);
7
- }
8
- if (strictPort) {
9
- tryLimits = 1;
10
- }
11
- const original = port;
12
- let found = false;
13
- let attempts = 0;
14
- while (!found && attempts <= tryLimits) {
15
- try {
16
- await new Promise((resolve, reject) => {
17
- const server = net.createServer();
18
- server.unref();
19
- server.on("error", reject);
20
- server.listen({
21
- port,
22
- host: "0.0.0.0"
23
- }, () => {
24
- found = true;
25
- server.close(resolve);
26
- });
27
- });
28
- } catch (e) {
29
- if (e.code !== "EADDRINUSE") {
30
- throw e;
6
+ export var getPort = function() {
7
+ var _ref = _async_to_generator(function(port) {
8
+ var _ref2, _ref_tryLimits, tryLimits, _ref_strictPort, strictPort, original, found, attempts, e;
9
+ var _arguments = arguments;
10
+ return _ts_generator(this, function(_state) {
11
+ switch (_state.label) {
12
+ case 0:
13
+ _ref2 = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, _ref_tryLimits = _ref2.tryLimits, tryLimits = _ref_tryLimits === void 0 ? 20 : _ref_tryLimits, _ref_strictPort = _ref2.strictPort, strictPort = _ref_strictPort === void 0 ? false : _ref_strictPort;
14
+ if (typeof port === "string") {
15
+ port = parseInt(port, 10);
16
+ }
17
+ if (strictPort) {
18
+ tryLimits = 1;
19
+ }
20
+ original = port;
21
+ found = false;
22
+ attempts = 0;
23
+ _state.label = 1;
24
+ case 1:
25
+ if (!(!found && attempts <= tryLimits))
26
+ return [
27
+ 3,
28
+ 6
29
+ ];
30
+ _state.label = 2;
31
+ case 2:
32
+ _state.trys.push([
33
+ 2,
34
+ 4,
35
+ ,
36
+ 5
37
+ ]);
38
+ return [
39
+ 4,
40
+ new Promise(function(resolve, reject) {
41
+ var server = net.createServer();
42
+ server.unref();
43
+ server.on("error", reject);
44
+ server.listen({
45
+ port: port,
46
+ host: "0.0.0.0"
47
+ }, function() {
48
+ found = true;
49
+ server.close(resolve);
50
+ });
51
+ })
52
+ ];
53
+ case 3:
54
+ _state.sent();
55
+ return [
56
+ 3,
57
+ 5
58
+ ];
59
+ case 4:
60
+ e = _state.sent();
61
+ if (e.code !== "EADDRINUSE") {
62
+ throw e;
63
+ }
64
+ port++;
65
+ attempts++;
66
+ return [
67
+ 3,
68
+ 5
69
+ ];
70
+ case 5:
71
+ return [
72
+ 3,
73
+ 1
74
+ ];
75
+ case 6:
76
+ if (port !== original) {
77
+ if (strictPort) {
78
+ throw new Error('Port "'.concat(original, '" is occupied, please choose another one.'));
79
+ } else {
80
+ logger.info("Something is already running on port ".concat(original, ". ").concat(chalk.yellow("Use port ".concat(port, " instead."))));
81
+ }
82
+ }
83
+ return [
84
+ 2,
85
+ port
86
+ ];
31
87
  }
32
- port++;
33
- attempts++;
34
- }
35
- }
36
- if (port !== original) {
37
- if (strictPort) {
38
- throw new Error(`Port "${original}" is occupied, please choose another one.`);
39
- } else {
40
- logger.info(`Something is already running on port ${original}. ${chalk.yellow(`Use port ${port} instead.`)}`);
41
- }
42
- }
43
- return port;
44
- };
88
+ });
89
+ });
90
+ return function getPort2(port) {
91
+ return _ref.apply(this, arguments);
92
+ };
93
+ }();
@@ -1,14 +1,17 @@
1
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
2
  import os from "os";
2
3
  import { chalk } from "../compiled";
3
4
  import { isDev, isSingleEntry } from "./is";
4
5
  import { DEFAULT_DEV_HOST } from "./constants";
5
- const normalizeUrl = (url) => url.replace(/([^:]\/)\/+/g, "$1");
6
- const getIpv4Interfaces = () => {
7
- const interfaces = os.networkInterfaces();
8
- const ipv4Interfaces = [];
9
- Object.keys(interfaces).forEach((key) => {
10
- interfaces[key].forEach((detail) => {
11
- const familyV4Value = typeof detail.family === "string" ? "IPv4" : 4;
6
+ var normalizeUrl = function(url) {
7
+ return url.replace(/([^:]\/)\/+/g, "$1");
8
+ };
9
+ var getIpv4Interfaces = function() {
10
+ var interfaces = os.networkInterfaces();
11
+ var ipv4Interfaces = [];
12
+ Object.keys(interfaces).forEach(function(key) {
13
+ interfaces[key].forEach(function(detail) {
14
+ var familyV4Value = typeof detail.family === "string" ? "IPv4" : 4;
12
15
  if (detail.family === familyV4Value) {
13
16
  ipv4Interfaces.push(detail);
14
17
  }
@@ -16,57 +19,66 @@ const getIpv4Interfaces = () => {
16
19
  });
17
20
  return ipv4Interfaces;
18
21
  };
19
- export const getAddressUrls = (protocol = "http", port, host) => {
20
- const LOCAL_LABEL = "Local: ";
21
- const NETWORK_LABEL = "Network: ";
22
- const isLocalhost = (url) => {
23
- return url === null || url === void 0 ? void 0 : url.includes("localhost");
22
+ export var getAddressUrls = function() {
23
+ var protocol = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "http", port = arguments.length > 1 ? arguments[1] : void 0, host = arguments.length > 2 ? arguments[2] : void 0;
24
+ var LOCAL_LABEL = "Local: ";
25
+ var NETWORK_LABEL = "Network: ";
26
+ var isLocalhost = function(url) {
27
+ var _url;
28
+ return (_url = url) === null || _url === void 0 ? void 0 : _url.includes("localhost");
24
29
  };
25
30
  if (host && host !== DEFAULT_DEV_HOST) {
26
31
  return [
27
32
  {
28
33
  label: isLocalhost(host) ? LOCAL_LABEL : NETWORK_LABEL,
29
- url: `${protocol}://${host}:${port}`
34
+ url: "".concat(protocol, "://").concat(host, ":").concat(port)
30
35
  }
31
36
  ];
32
37
  }
33
- const ipv4Interfaces = getIpv4Interfaces();
34
- return ipv4Interfaces.reduce((memo, detail) => {
38
+ var ipv4Interfaces = getIpv4Interfaces();
39
+ return ipv4Interfaces.reduce(function(memo, detail) {
35
40
  if (isLocalhost(detail.address) || detail.internal) {
36
41
  memo.push({
37
42
  label: LOCAL_LABEL,
38
- url: `${protocol}://localhost:${port}`
43
+ url: "".concat(protocol, "://localhost:").concat(port)
39
44
  });
40
45
  } else {
41
46
  memo.push({
42
47
  label: NETWORK_LABEL,
43
- url: `${protocol}://${detail.address}:${port}`
48
+ url: "".concat(protocol, "://").concat(detail.address, ":").concat(port)
44
49
  });
45
50
  }
46
51
  return memo;
47
52
  }, []);
48
53
  };
49
- export const prettyInstructions = (appContext, config) => {
54
+ export var prettyInstructions = function(appContext, config) {
50
55
  var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
51
- const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
52
- const isHttps = isDev() && ((_appContext_builder_context_devServer = (_appContext_builder = appContext.builder) === null || _appContext_builder === void 0 ? void 0 : _appContext_builder.context.devServer) === null || _appContext_builder_context_devServer === void 0 ? void 0 : _appContext_builder_context_devServer.https);
53
- const urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
54
- const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
55
- let message = "App running at:\n\n";
56
+ var entrypoints = appContext.entrypoints, serverRoutes = appContext.serverRoutes, port = appContext.port, apiOnly = appContext.apiOnly, checkedEntries = appContext.checkedEntries;
57
+ var isHttps = isDev() && ((_appContext_builder = appContext.builder) === null || _appContext_builder === void 0 ? void 0 : (_appContext_builder_context_devServer = _appContext_builder.context.devServer) === null || _appContext_builder_context_devServer === void 0 ? void 0 : _appContext_builder_context_devServer.https);
58
+ var urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
59
+ var routes = !apiOnly ? serverRoutes.filter(function(route) {
60
+ return route.entryName;
61
+ }) : serverRoutes;
62
+ var message = "App running at:\n\n";
56
63
  if (isSingleEntry(entrypoints) || apiOnly) {
57
- message += urls.map(({ label, url }) => ` ${chalk.bold(`> ${label.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}
58
- `).join("");
64
+ message += urls.map(function(param) {
65
+ var label = param.label, url = param.url;
66
+ return " ".concat(chalk.bold("> ".concat(label.padEnd(10)))).concat(chalk.cyanBright(normalizeUrl("".concat(url, "/").concat(routes[0].urlPath))), "\n");
67
+ }).join("");
59
68
  } else {
60
- const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
61
- urls.forEach(({ label, url }) => {
62
- message += ` ${chalk.bold(`> ${label}`)}
63
- `;
64
- routes.forEach(({ entryName, urlPath, isSSR }) => {
69
+ var _Math;
70
+ var maxNameLength = (_Math = Math).max.apply(_Math, _to_consumable_array(routes.map(function(r) {
71
+ return r.entryName.length;
72
+ })));
73
+ urls.forEach(function(param) {
74
+ var label = param.label, url = param.url;
75
+ message += " ".concat(chalk.bold("> ".concat(label)), "\n");
76
+ routes.forEach(function(param2) {
77
+ var entryName = param2.entryName, urlPath = param2.urlPath, isSSR = param2.isSSR;
65
78
  if (!checkedEntries.includes(entryName)) {
66
79
  return;
67
80
  }
68
- message += ` ${chalk.yellowBright(isSSR ? "λ" : "○")} ${chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}
69
- `;
81
+ message += " ".concat(chalk.yellowBright(isSSR ? "λ" : "○"), " ").concat(chalk.yellowBright(entryName.padEnd(maxNameLength + 8))).concat(chalk.cyanBright(normalizeUrl("".concat(url, "/").concat(urlPath))), "\n");
70
82
  });
71
83
  });
72
84
  message += "\n";
@@ -1,27 +1,31 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
1
2
  import { findExists } from "./fs";
2
- export const compatRequire = (filePath, interop = true) => {
3
- const mod = require(filePath);
4
- const rtnESMDefault = interop && (mod === null || mod === void 0 ? void 0 : mod.__esModule);
3
+ export var compatRequire = function(filePath) {
4
+ var interop = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
5
+ var _mod;
6
+ var mod = require(filePath);
7
+ var rtnESMDefault = interop && ((_mod = mod) === null || _mod === void 0 ? void 0 : _mod.__esModule);
5
8
  return rtnESMDefault ? mod.default : mod;
6
9
  };
7
- export const dynamicImport = new Function("modulePath", "return import(modulePath)");
8
- export const requireExistModule = (filename, opt) => {
9
- const final = {
10
+ export var dynamicImport = new Function("modulePath", "return import(modulePath)");
11
+ export var requireExistModule = function(filename, opt) {
12
+ var final = _object_spread({
10
13
  extensions: [
11
14
  ".ts",
12
15
  ".js"
13
16
  ],
14
- interop: true,
15
- ...opt
16
- };
17
- const exist = findExists(final.extensions.map((ext) => `${filename}${ext}`));
17
+ interop: true
18
+ }, opt);
19
+ var exist = findExists(final.extensions.map(function(ext) {
20
+ return "".concat(filename).concat(ext);
21
+ }));
18
22
  if (!exist) {
19
23
  return null;
20
24
  }
21
25
  return compatRequire(exist, final.interop);
22
26
  };
23
- export const cleanRequireCache = (filelist) => {
24
- filelist.forEach((filepath) => {
27
+ export var cleanRequireCache = function(filelist) {
28
+ filelist.forEach(function(filepath) {
25
29
  delete require.cache[filepath];
26
30
  });
27
31
  };
@@ -30,11 +34,13 @@ export function deleteRequireCache(path) {
30
34
  delete require.cache[path];
31
35
  }
32
36
  if (module.children) {
33
- module.children = module.children.filter((item) => item.filename !== path);
37
+ module.children = module.children.filter(function(item) {
38
+ return item.filename !== path;
39
+ });
34
40
  }
35
41
  }
36
- export const tryResolve = (name, resolvePath) => {
37
- let filePath = "";
42
+ export var tryResolve = function(name, resolvePath) {
43
+ var filePath = "";
38
44
  try {
39
45
  filePath = require.resolve(name, {
40
46
  paths: [
@@ -44,7 +50,7 @@ export const tryResolve = (name, resolvePath) => {
44
50
  delete require.cache[filePath];
45
51
  } catch (err) {
46
52
  if (err.code === "MODULE_NOT_FOUND") {
47
- throw new Error(`Can not find module ${name}.`);
53
+ throw new Error("Can not find module ".concat(name, "."));
48
54
  }
49
55
  throw err;
50
56
  }
@@ -1,35 +1,41 @@
1
+ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
1
2
  import path from "path";
2
3
  import { fs } from "../compiled";
3
4
  import { normalizeOutputPath } from "./path";
4
- const memo = (fn) => {
5
- const cache = /* @__PURE__ */ new Map();
6
- return (...params) => {
7
- const stringifiedParams = JSON.stringify(params);
8
- const cachedResult = cache.get(stringifiedParams);
5
+ var memo = function(fn) {
6
+ var cache = /* @__PURE__ */ new Map();
7
+ return function() {
8
+ for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ params[_key] = arguments[_key];
10
+ }
11
+ var stringifiedParams = JSON.stringify(params);
12
+ var cachedResult = cache.get(stringifiedParams);
9
13
  if (cachedResult) {
10
14
  return cachedResult;
11
15
  }
12
- const res = fn(...params);
16
+ var res = fn.apply(void 0, _to_consumable_array(params));
13
17
  cache.set(stringifiedParams, res);
14
18
  return res;
15
19
  };
16
20
  };
17
- export const createRuntimeExportsUtils = memo((pwd = "", namespace = "index") => {
18
- const entryExportFile = path.join(pwd, `.runtime-exports/${namespace}.js`);
19
- const addExport = (statement) => {
21
+ export var createRuntimeExportsUtils = memo(function() {
22
+ var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", namespace = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "index";
23
+ var entryExportFile = path.join(pwd, ".runtime-exports/".concat(namespace, ".js"));
24
+ var addExport = function(statement) {
20
25
  statement = normalizeOutputPath(statement);
21
26
  try {
22
27
  fs.ensureFileSync(entryExportFile);
23
28
  if (!fs.readFileSync(entryExportFile, "utf8").includes(statement)) {
24
- fs.appendFileSync(entryExportFile, `${statement}
25
- `);
29
+ fs.appendFileSync(entryExportFile, "".concat(statement, "\n"));
26
30
  }
27
- } catch {
31
+ } catch (e) {
28
32
  }
29
33
  };
30
- const getPath = () => entryExportFile;
34
+ var getPath = function() {
35
+ return entryExportFile;
36
+ };
31
37
  return {
32
- addExport,
33
- getPath
38
+ addExport: addExport,
39
+ getPath: getPath
34
40
  };
35
41
  });