@modern-js/utils 2.26.0 → 2.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +12 -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 +4 -4
@@ -1,39 +1,44 @@
1
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
1
2
  import fs from "fs";
2
3
  import path from "path";
3
4
  import { glob, yaml } from "../compiled";
4
- const PACKAGE_MAX_DEPTH = 5;
5
- const WORKSPACE_FILES = {
5
+ var PACKAGE_MAX_DEPTH = 5;
6
+ var WORKSPACE_FILES = {
6
7
  YARN: "package.json",
7
8
  PNPM: "pnpm-workspace.yaml",
8
9
  LERNA: "lerna.json"
9
10
  };
10
- export const isLerna = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.LERNA));
11
- export const isYarnWorkspaces = (root) => {
11
+ export var isLerna = function(root) {
12
+ return fs.existsSync(path.join(root, WORKSPACE_FILES.LERNA));
13
+ };
14
+ export var isYarnWorkspaces = function(root) {
12
15
  var _json_workspaces;
13
- const pkg = path.join(root, WORKSPACE_FILES.YARN);
16
+ var pkg = path.join(root, WORKSPACE_FILES.YARN);
14
17
  if (!fs.existsSync(pkg)) {
15
18
  return false;
16
19
  }
17
- const json = JSON.parse(fs.readFileSync(pkg, "utf8"));
20
+ var json = JSON.parse(fs.readFileSync(pkg, "utf8"));
18
21
  return Boolean((_json_workspaces = json.workspaces) === null || _json_workspaces === void 0 ? void 0 : _json_workspaces.packages);
19
22
  };
20
- export const isPnpmWorkspaces = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES.PNPM));
21
- export const isMonorepo = (root) => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
22
- export const isModernjsMonorepo = (root) => {
23
- const pkgJsonPath = path.join(root, "package.json");
23
+ export var isPnpmWorkspaces = function(root) {
24
+ return fs.existsSync(path.join(root, WORKSPACE_FILES.PNPM));
25
+ };
26
+ export var isMonorepo = function(root) {
27
+ return isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
28
+ };
29
+ export var isModernjsMonorepo = function(root) {
30
+ var pkgJsonPath = path.join(root, "package.json");
24
31
  if (!fs.existsSync(pkgJsonPath)) {
25
32
  return false;
26
33
  }
27
- const json = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
28
- const deps = {
29
- ...json.dependencies || {},
30
- ...json.devDependencies || {}
31
- };
34
+ var json = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
35
+ var deps = _object_spread({}, json.dependencies || {}, json.devDependencies || {});
32
36
  return Boolean(deps["@modern-js/monorepo-tools"]);
33
37
  };
34
- export const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
35
- let inMonorepo = false;
36
- for (let depth = 0; depth < maxDepth; depth++) {
38
+ export var findMonorepoRoot = function(appDirectory) {
39
+ var maxDepth = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : PACKAGE_MAX_DEPTH;
40
+ var inMonorepo = false;
41
+ for (var depth = 0; depth < maxDepth; depth++) {
37
42
  if (isMonorepo(appDirectory)) {
38
43
  inMonorepo = true;
39
44
  break;
@@ -42,29 +47,37 @@ export const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) =>
42
47
  }
43
48
  return inMonorepo ? appDirectory : void 0;
44
49
  };
45
- export const getMonorepoPackages = (root) => {
46
- let packages = [];
50
+ export var getMonorepoPackages = function(root) {
51
+ var packages = [];
47
52
  if (isYarnWorkspaces(root)) {
48
- const json = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
49
- ({ packages } = json.workspaces);
53
+ var json = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
54
+ packages = json.workspaces.packages;
50
55
  } else if (isLerna(root)) {
51
- const json = JSON.parse(fs.readFileSync(path.resolve(root, "lerna.json"), "utf8"));
52
- ({ packages } = json);
56
+ var json1 = JSON.parse(fs.readFileSync(path.resolve(root, "lerna.json"), "utf8"));
57
+ packages = json1.packages;
53
58
  } else {
54
- ({ packages } = yaml.load(fs.readFileSync(path.join(root, WORKSPACE_FILES.PNPM), "utf8")));
59
+ packages = yaml.load(fs.readFileSync(path.join(root, WORKSPACE_FILES.PNPM), "utf8")).packages;
55
60
  }
56
61
  if (packages) {
57
- return packages.map((name) => (
58
- // The trailing / ensures only dirs are picked up
59
- glob.sync(path.join(root, `${name}/`), {
60
- ignore: [
61
- "**/node_modules/**"
62
- ]
63
- })
64
- )).reduce((acc, val) => acc.concat(val), []).filter((filepath) => fs.existsSync(path.resolve(filepath, "package.json"))).map((filepath) => ({
65
- path: filepath,
66
- name: JSON.parse(fs.readFileSync(path.resolve(filepath, "package.json"), "utf8")).name
67
- }));
62
+ return packages.map(function(name) {
63
+ return (
64
+ // The trailing / ensures only dirs are picked up
65
+ glob.sync(path.join(root, "".concat(name, "/")), {
66
+ ignore: [
67
+ "**/node_modules/**"
68
+ ]
69
+ })
70
+ );
71
+ }).reduce(function(acc, val) {
72
+ return acc.concat(val);
73
+ }, []).filter(function(filepath) {
74
+ return fs.existsSync(path.resolve(filepath, "package.json"));
75
+ }).map(function(filepath) {
76
+ return {
77
+ path: filepath,
78
+ name: JSON.parse(fs.readFileSync(path.resolve(filepath, "package.json"), "utf8")).name
79
+ };
80
+ });
68
81
  }
69
82
  return [];
70
83
  };
@@ -1,43 +1,161 @@
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 { execa } from "../compiled";
2
- export async function getPnpmVersion() {
3
- const { stdout } = await execa("pnpm", [
4
- "--version"
5
- ]);
6
- return stdout;
7
- }
8
- export async function canUseNpm() {
9
- try {
10
- await execa("npm", [
11
- "--version"
12
- ], {
13
- env: process.env
4
+ export function getPnpmVersion() {
5
+ return _getPnpmVersion.apply(this, arguments);
6
+ }
7
+ function _getPnpmVersion() {
8
+ _getPnpmVersion = _async_to_generator(function() {
9
+ var stdout;
10
+ return _ts_generator(this, function(_state) {
11
+ switch (_state.label) {
12
+ case 0:
13
+ return [
14
+ 4,
15
+ execa("pnpm", [
16
+ "--version"
17
+ ])
18
+ ];
19
+ case 1:
20
+ stdout = _state.sent().stdout;
21
+ return [
22
+ 2,
23
+ stdout
24
+ ];
25
+ }
26
+ });
27
+ });
28
+ return _getPnpmVersion.apply(this, arguments);
29
+ }
30
+ export function canUseNpm() {
31
+ return _canUseNpm.apply(this, arguments);
32
+ }
33
+ function _canUseNpm() {
34
+ _canUseNpm = _async_to_generator(function() {
35
+ var e;
36
+ return _ts_generator(this, function(_state) {
37
+ switch (_state.label) {
38
+ case 0:
39
+ _state.trys.push([
40
+ 0,
41
+ 2,
42
+ ,
43
+ 3
44
+ ]);
45
+ return [
46
+ 4,
47
+ execa("npm", [
48
+ "--version"
49
+ ], {
50
+ env: process.env
51
+ })
52
+ ];
53
+ case 1:
54
+ _state.sent();
55
+ return [
56
+ 2,
57
+ true
58
+ ];
59
+ case 2:
60
+ e = _state.sent();
61
+ return [
62
+ 2,
63
+ false
64
+ ];
65
+ case 3:
66
+ return [
67
+ 2
68
+ ];
69
+ }
14
70
  });
15
- return true;
16
- } catch (e) {
17
- return false;
18
- }
19
- }
20
- export async function canUseYarn() {
21
- try {
22
- await execa("yarn", [
23
- "--version"
24
- ], {
25
- env: process.env
71
+ });
72
+ return _canUseNpm.apply(this, arguments);
73
+ }
74
+ export function canUseYarn() {
75
+ return _canUseYarn.apply(this, arguments);
76
+ }
77
+ function _canUseYarn() {
78
+ _canUseYarn = _async_to_generator(function() {
79
+ var e;
80
+ return _ts_generator(this, function(_state) {
81
+ switch (_state.label) {
82
+ case 0:
83
+ _state.trys.push([
84
+ 0,
85
+ 2,
86
+ ,
87
+ 3
88
+ ]);
89
+ return [
90
+ 4,
91
+ execa("yarn", [
92
+ "--version"
93
+ ], {
94
+ env: process.env
95
+ })
96
+ ];
97
+ case 1:
98
+ _state.sent();
99
+ return [
100
+ 2,
101
+ true
102
+ ];
103
+ case 2:
104
+ e = _state.sent();
105
+ return [
106
+ 2,
107
+ false
108
+ ];
109
+ case 3:
110
+ return [
111
+ 2
112
+ ];
113
+ }
26
114
  });
27
- return true;
28
- } catch (e) {
29
- return false;
30
- }
31
- }
32
- export async function canUsePnpm() {
33
- try {
34
- await execa("pnpm", [
35
- "--version"
36
- ], {
37
- env: process.env
115
+ });
116
+ return _canUseYarn.apply(this, arguments);
117
+ }
118
+ export function canUsePnpm() {
119
+ return _canUsePnpm.apply(this, arguments);
120
+ }
121
+ function _canUsePnpm() {
122
+ _canUsePnpm = _async_to_generator(function() {
123
+ var e;
124
+ return _ts_generator(this, function(_state) {
125
+ switch (_state.label) {
126
+ case 0:
127
+ _state.trys.push([
128
+ 0,
129
+ 2,
130
+ ,
131
+ 3
132
+ ]);
133
+ return [
134
+ 4,
135
+ execa("pnpm", [
136
+ "--version"
137
+ ], {
138
+ env: process.env
139
+ })
140
+ ];
141
+ case 1:
142
+ _state.sent();
143
+ return [
144
+ 2,
145
+ true
146
+ ];
147
+ case 2:
148
+ e = _state.sent();
149
+ return [
150
+ 2,
151
+ false
152
+ ];
153
+ case 3:
154
+ return [
155
+ 2
156
+ ];
157
+ }
38
158
  });
39
- return true;
40
- } catch (e) {
41
- return false;
42
- }
159
+ });
160
+ return _canUsePnpm.apply(this, arguments);
43
161
  }
@@ -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
+ }();