@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.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/universal/formatWebpack.js +0 -4
- package/dist/esm/cli/alias.js +26 -22
- package/dist/esm/cli/applyOptionsChain.js +8 -6
- package/dist/esm/cli/babel.js +50 -35
- package/dist/esm/cli/commands.js +7 -7
- package/dist/esm/cli/common.js +10 -5
- package/dist/esm/cli/constants/chainId.js +1 -1
- package/dist/esm/cli/constants/index.js +33 -37
- package/dist/esm/cli/ensure.js +4 -2
- package/dist/esm/cli/fs.js +56 -9
- package/dist/esm/cli/get/config.js +7 -7
- package/dist/esm/cli/get/data.js +93 -55
- package/dist/esm/cli/get/index.js +21 -6
- package/dist/esm/cli/is/config.js +33 -14
- package/dist/esm/cli/is/env.js +18 -6
- package/dist/esm/cli/is/platform.js +6 -2
- package/dist/esm/cli/is/project.js +73 -36
- package/dist/esm/cli/is/type.js +3 -1
- package/dist/esm/cli/logger.js +49 -38
- package/dist/esm/cli/monorepo.js +49 -36
- package/dist/esm/cli/package.js +156 -38
- package/dist/esm/cli/path.js +44 -20
- package/dist/esm/cli/pathSerializer.js +29 -15
- package/dist/esm/cli/port.js +89 -40
- package/dist/esm/cli/prettyInstructions.js +42 -31
- package/dist/esm/cli/require.js +21 -16
- package/dist/esm/cli/runtimeExports.js +21 -15
- package/dist/esm/cli/watch.js +94 -27
- package/dist/esm/compiled.js +3 -3
- package/dist/esm/import.js +4 -4
- package/dist/esm/runtime/nestedRoutes.js +42 -29
- package/dist/esm/runtime-browser/parsed.js +5 -5
- package/dist/esm/runtime-node/index.js +1 -1
- package/dist/esm/runtime-node/nestedRoutes.js +6 -4
- package/dist/esm/runtime-node/serialize.js +1 -1
- package/dist/esm/runtime-node/storage.js +12 -14
- package/dist/esm/universal/constants.js +3 -3
- package/dist/esm/universal/formatWebpack.js +20 -26
- package/dist/esm/universal/pluginDagSort.js +49 -26
- package/dist/esm-node/cli/alias.js +51 -0
- package/dist/esm-node/cli/applyOptionsChain.js +24 -0
- package/dist/esm-node/cli/babel.js +103 -0
- package/dist/esm-node/cli/commands.js +16 -0
- package/dist/esm-node/cli/common.js +10 -0
- package/dist/esm-node/cli/constants/chainId.js +180 -0
- package/dist/esm-node/cli/constants/index.js +103 -0
- package/dist/esm-node/cli/ensure.js +10 -0
- package/dist/esm-node/cli/fs.js +14 -0
- package/dist/esm-node/cli/get/config.js +16 -0
- package/dist/esm-node/cli/get/data.js +86 -0
- package/dist/esm-node/cli/get/index.js +13 -0
- package/dist/esm-node/cli/index.js +20 -0
- package/dist/esm-node/cli/is/config.js +40 -0
- package/dist/esm-node/cli/is/env.js +6 -0
- package/dist/esm-node/cli/is/index.js +5 -0
- package/dist/esm-node/cli/is/platform.js +2 -0
- package/dist/esm-node/cli/is/project.js +73 -0
- package/dist/esm-node/cli/is/type.js +25 -0
- package/dist/esm-node/cli/logger.js +103 -0
- package/dist/esm-node/cli/monorepo.js +70 -0
- package/dist/esm-node/cli/package.js +43 -0
- package/dist/esm-node/cli/path.js +49 -0
- package/dist/esm-node/cli/pathSerializer.js +46 -0
- package/dist/esm-node/cli/port.js +44 -0
- package/dist/esm-node/cli/prettyInstructions.js +77 -0
- package/dist/esm-node/cli/require.js +52 -0
- package/dist/esm-node/cli/runtimeExports.js +35 -0
- package/dist/esm-node/cli/watch.js +41 -0
- package/dist/esm-node/compiled.js +33 -0
- package/dist/esm-node/import.js +8 -0
- package/dist/esm-node/index.js +3 -0
- package/dist/esm-node/runtime/nestedRoutes.js +112 -0
- package/dist/esm-node/runtime/remixRouter.js +1 -0
- package/dist/esm-node/runtime/router.js +1 -0
- package/dist/esm-node/runtime-browser/index.js +1 -0
- package/dist/esm-node/runtime-browser/parsed.js +17 -0
- package/dist/esm-node/runtime-node/index.js +5 -0
- package/dist/esm-node/runtime-node/nestedRoutes.js +18 -0
- package/dist/esm-node/runtime-node/router.js +1 -0
- package/dist/esm-node/runtime-node/serialize.js +6 -0
- package/dist/esm-node/runtime-node/storage.js +38 -0
- package/dist/esm-node/universal/constants.js +3 -0
- package/dist/esm-node/universal/formatWebpack.js +61 -0
- package/dist/esm-node/universal/pluginDagSort.js +50 -0
- package/package.json +4 -4
package/dist/esm/cli/monorepo.js
CHANGED
@@ -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
|
-
|
5
|
-
|
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
|
11
|
-
|
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
|
-
|
16
|
+
var pkg = path.join(root, WORKSPACE_FILES.YARN);
|
14
17
|
if (!fs.existsSync(pkg)) {
|
15
18
|
return false;
|
16
19
|
}
|
17
|
-
|
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
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
28
|
-
|
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
|
35
|
-
|
36
|
-
|
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
|
46
|
-
|
50
|
+
export var getMonorepoPackages = function(root) {
|
51
|
+
var packages = [];
|
47
52
|
if (isYarnWorkspaces(root)) {
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
56
|
+
var json1 = JSON.parse(fs.readFileSync(path.resolve(root, "lerna.json"), "utf8"));
|
57
|
+
packages = json1.packages;
|
53
58
|
} else {
|
54
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
};
|
package/dist/esm/cli/package.js
CHANGED
@@ -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
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
return false;
|
42
|
-
}
|
159
|
+
});
|
160
|
+
return _canUsePnpm.apply(this, arguments);
|
43
161
|
}
|
package/dist/esm/cli/path.js
CHANGED
@@ -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
|
6
|
-
|
7
|
-
|
8
|
-
export
|
9
|
-
|
10
|
-
|
11
|
-
|
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(
|
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
|
-
|
23
|
-
return new RegExp(
|
34
|
+
var escaped = _.escapeRegExp(match);
|
35
|
+
return new RegExp("(?<=\\W|^)".concat(escaped, "(?=\\W|$)"));
|
24
36
|
}
|
25
|
-
export
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
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
|
45
|
-
|
46
|
-
|
47
|
-
export
|
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
|
5
|
-
match
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
15
|
-
|
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
|
20
|
-
|
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
|
25
|
-
|
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
|
-
|
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(
|
58
|
+
(_ret = ret).push.apply(_ret, _to_consumable_array(matchUpwardPathsAsUnknown(root)));
|
45
59
|
return ret;
|
46
60
|
};
|
package/dist/esm/cli/port.js
CHANGED
@@ -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
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
+
}();
|