@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.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/cli/alias.js +3 -3
- package/dist/cjs/cli/constants/chainId.js +4 -0
- package/dist/cjs/cli/constants/index.js +0 -1
- package/dist/cjs/cli/is/config.js +11 -8
- package/dist/cjs/cli/prettyInstructions.js +3 -2
- package/dist/cjs/cli/require.js +2 -1
- package/dist/cjs/runtime/nestedRoutes.js +9 -5
- package/dist/cjs/runtime-browser/parsed.js +2 -1
- package/dist/cjs/universal/formatWebpack.js +55 -12
- package/dist/esm/cli/alias.js +27 -23
- 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 +5 -1
- package/dist/esm/cli/constants/index.js +33 -38
- 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 +102 -55
- package/dist/esm/cli/get/index.js +21 -6
- package/dist/esm/cli/is/config.js +43 -21
- 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 +44 -32
- package/dist/esm/cli/require.js +22 -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 +49 -32
- package/dist/esm/runtime-browser/parsed.js +6 -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 +54 -28
- 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 +184 -0
- package/dist/esm-node/cli/constants/index.js +102 -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 +43 -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 +78 -0
- package/dist/esm-node/cli/require.js +53 -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 +116 -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 +18 -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 +99 -0
- package/dist/esm-node/universal/pluginDagSort.js +50 -0
- package/dist/types/cli/constants/chainId.d.ts +4 -0
- package/dist/types/universal/formatWebpack.d.ts +14 -1
- package/package.json +4 -4
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
|
+
}();
|
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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:
|
34
|
+
url: "".concat(protocol, "://").concat(host, ":").concat(port)
|
30
35
|
}
|
31
36
|
];
|
32
37
|
}
|
33
|
-
|
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:
|
43
|
+
url: "".concat(protocol, "://localhost:").concat(port)
|
39
44
|
});
|
40
45
|
} else {
|
41
46
|
memo.push({
|
42
47
|
label: NETWORK_LABEL,
|
43
|
-
url:
|
48
|
+
url: "".concat(protocol, "://").concat(detail.address, ":").concat(port)
|
44
49
|
});
|
45
50
|
}
|
46
51
|
return memo;
|
47
52
|
}, []);
|
48
53
|
};
|
49
|
-
export
|
54
|
+
export var prettyInstructions = function(appContext, config) {
|
50
55
|
var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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((
|
58
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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 +=
|
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";
|
package/dist/esm/cli/require.js
CHANGED
@@ -1,27 +1,31 @@
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
1
2
|
import { findExists } from "./fs";
|
2
|
-
export
|
3
|
-
|
4
|
-
|
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
|
8
|
-
export
|
9
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
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
|
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)
|
37
|
+
module.children = module.children.filter(function(item) {
|
38
|
+
return item.filename !== path;
|
39
|
+
});
|
34
40
|
}
|
35
41
|
}
|
36
|
-
export
|
37
|
-
|
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(
|
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
|
-
|
5
|
-
|
6
|
-
return (
|
7
|
-
|
8
|
-
|
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
|
-
|
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
|
18
|
-
|
19
|
-
|
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,
|
25
|
-
`);
|
29
|
+
fs.appendFileSync(entryExportFile, "".concat(statement, "\n"));
|
26
30
|
}
|
27
|
-
} catch {
|
31
|
+
} catch (e) {
|
28
32
|
}
|
29
33
|
};
|
30
|
-
|
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
|
});
|