@modern-js/utils 2.28.0 → 2.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/cjs/cli/constants/chainId.js +10 -0
  3. package/dist/cjs/cli/constants/index.js +1 -1
  4. package/dist/cjs/cli/index.js +0 -1
  5. package/dist/cjs/cli/is/config.js +4 -3
  6. package/dist/cjs/cli/logger.js +9 -0
  7. package/dist/cjs/cli/path.js +0 -23
  8. package/dist/cjs/cli/prettyInstructions.js +3 -3
  9. package/dist/cjs/universal/time.js +38 -0
  10. package/dist/esm/cli/constants/chainId.js +10 -0
  11. package/dist/esm/cli/constants/index.js +1 -1
  12. package/dist/esm/cli/index.js +0 -1
  13. package/dist/esm/cli/is/config.js +5 -3
  14. package/dist/esm/cli/logger.js +10 -0
  15. package/dist/esm/cli/path.js +2 -22
  16. package/dist/esm/cli/prettyInstructions.js +3 -3
  17. package/dist/esm/universal/time.js +29 -0
  18. package/dist/esm-node/cli/constants/chainId.js +10 -0
  19. package/dist/esm-node/cli/constants/index.js +1 -1
  20. package/dist/esm-node/cli/index.js +0 -1
  21. package/dist/esm-node/cli/is/config.js +4 -3
  22. package/dist/esm-node/cli/logger.js +6 -0
  23. package/dist/esm-node/cli/path.js +2 -16
  24. package/dist/esm-node/cli/prettyInstructions.js +3 -3
  25. package/dist/esm-node/universal/time.js +28 -0
  26. package/dist/types/cli/constants/chainId.d.ts +10 -0
  27. package/dist/types/cli/constants/index.d.ts +1 -1
  28. package/dist/types/cli/index.d.ts +0 -1
  29. package/dist/types/cli/is/config.d.ts +1 -1
  30. package/dist/types/cli/logger.d.ts +1 -0
  31. package/dist/types/cli/path.d.ts +0 -9
  32. package/dist/types/universal/time.d.ts +1 -0
  33. package/package.json +12 -4
  34. package/dist/cjs/cli/pathSerializer.js +0 -72
  35. package/dist/esm/cli/pathSerializer.js +0 -60
  36. package/dist/esm-node/cli/pathSerializer.js +0 -46
  37. package/dist/types/cli/pathSerializer.d.ts +0 -16
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 2.30.0
4
+
5
+ ## 2.29.0
6
+
7
+ ### Minor Changes
8
+
9
+ - cba7675: feat: add a server reporter that report server cost, logger about error, info etc.
10
+ feat: 添加一个 server 端 reporter,来报告 server 端耗时,报错等
11
+
12
+ ### Patch Changes
13
+
14
+ - e6b5355: feat(utils): change the color of error stacks to gray
15
+
16
+ feat(utils): 将 error stack 的颜色改为灰色
17
+
18
+ - 93db783: fix(utils): remove hard code 'main'
19
+
20
+ fix(utils): 移除 'main' 硬编码
21
+
22
+ - 99052ea: feat(builder): improve error stacks if dev compilation failed
23
+
24
+ feat(builder): 优化 dev 编译失败时的错误堆栈格式
25
+
26
+ - 1d71d2e: fix(@modern-js/utils): add missing url in devServer console
27
+ fix(@modern-js/utils): 修复 devServer console 中丢失的 url
28
+
3
29
  ## 2.28.0
4
30
 
5
31
  ### Patch Changes
@@ -107,6 +107,8 @@ const CHAIN_ID = {
107
107
  CSS_MODULES_TS: "css-modules-typescript",
108
108
  /** mini-css-extract-plugin.loader */
109
109
  MINI_CSS_EXTRACT: "mini-css-extract",
110
+ /** resolve-url-loader */
111
+ RESOLVE_URL_LOADER_FOR_SASS: "resolve-url-loader",
110
112
  /** builder-plugin-image-compress.loader */
111
113
  IMAGE_COMPRESS: "image-compress",
112
114
  /** builder-plugin-image-compress svgo-loader */
@@ -154,6 +156,14 @@ const CHAIN_ID = {
154
156
  HTML_NONCE: "html-nonce",
155
157
  /** HtmlCrossOriginPlugin */
156
158
  HTML_CROSS_ORIGIN: "html-cross-origin",
159
+ /** htmlPreconnectPlugin */
160
+ HTML_PRECONNECT: "html-preconnect-plugin",
161
+ /** htmlDnsPrefetchPlugin */
162
+ HTML_DNS_PREFETCH: "html-dns-prefetch-plugin",
163
+ /** htmlPrefetchPlugin */
164
+ HTML_PREFETCH: "html-prefetch-plugin",
165
+ /** htmlPreloadPlugin */
166
+ HTML_PRELOAD: "html-preload-plugin",
157
167
  /** MiniCssExtractPlugin */
158
168
  MINI_CSS_EXTRACT: "mini-css-extract",
159
169
  /** VueLoaderPlugin */
@@ -117,7 +117,7 @@ const LOADABLE_STATS_FILE = "loadable-stats.json";
117
117
  const API_DIR = "api";
118
118
  const SERVER_DIR = "server";
119
119
  const SHARED_DIR = "shared";
120
- const CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
120
+ const CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
121
121
  const CONFIG_FILE_EXTENSIONS = [
122
122
  ".js",
123
123
  ".ts",
@@ -17,7 +17,6 @@ _export_star._(require("./logger"), exports);
17
17
  _export_star._(require("./monorepo"), exports);
18
18
  _export_star._(require("./package"), exports);
19
19
  _export_star._(require("./path"), exports);
20
- _export_star._(require("./pathSerializer"), exports);
21
20
  _export_star._(require("./port"), exports);
22
21
  _export_star._(require("./prettyInstructions"), exports);
23
22
  _export_star._(require("./require"), exports);
@@ -29,6 +29,7 @@ _export(exports, {
29
29
  return isSingleEntry;
30
30
  }
31
31
  });
32
+ const _constants = require("../constants");
32
33
  const _type = require("./type");
33
34
  const isSSR = (config) => {
34
35
  var _server, _server1;
@@ -66,9 +67,9 @@ const isRouterV5 = (config) => {
66
67
  return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && ((_config = config) === null || _config === void 0 ? void 0 : (_config_runtime1 = _config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
67
68
  };
68
69
  const isSSGEntry = (config, entryName, entrypoints) => {
69
- var _ssgConfig, _ssgConfig1;
70
+ var _config_source, _ssgConfig, _ssgConfig1;
70
71
  const ssgConfig = config.output.ssg;
71
- const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
72
+ const useSSG = isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
72
73
  return useSSG;
73
74
  };
74
- const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
75
+ const isSingleEntry = (entrypoints, mainEntryName = _constants.MAIN_ENTRY_NAME) => entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
@@ -10,6 +10,9 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
+ isErrorStackMessage: function() {
14
+ return isErrorStackMessage;
15
+ },
13
16
  Logger: function() {
14
17
  return Logger;
15
18
  },
@@ -60,6 +63,9 @@ const DEFAULT_CONFIG = {
60
63
  displayLabel: true,
61
64
  uppercaseLabel: false
62
65
  };
66
+ const errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
67
+ const anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
68
+ const isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
63
69
  class Logger {
64
70
  _log(type, message, ...args) {
65
71
  if (message === void 0 || message === null) {
@@ -85,6 +91,9 @@ ${_chalk.default.grey(rest.join("\n"))}`;
85
91
  } else {
86
92
  text = message.message;
87
93
  }
94
+ } else if (logType.level === "error" && typeof message === "string") {
95
+ const lines = message.split("\n");
96
+ text = lines.map((line) => isErrorStackMessage(line) ? _chalk.default.gray(line) : line).join("\n");
88
97
  } else {
89
98
  text = `${message}`;
90
99
  }
@@ -25,15 +25,6 @@ _export(exports, {
25
25
  getTemplatePath: function() {
26
26
  return getTemplatePath;
27
27
  },
28
- compilePathMatcherRegExp: function() {
29
- return compilePathMatcherRegExp;
30
- },
31
- _joinPathParts: function() {
32
- return _joinPathParts;
33
- },
34
- upwardPaths: function() {
35
- return upwardPaths;
36
- },
37
28
  getRealTemporaryDirectory: function() {
38
29
  return getRealTemporaryDirectory;
39
30
  },
@@ -71,20 +62,6 @@ const getTemplatePath = (prefix) => {
71
62
  parts.push((0, _compiled.nanoid)());
72
63
  return _path.default.resolve(...parts);
73
64
  };
74
- function compilePathMatcherRegExp(match) {
75
- if (typeof match !== "string") {
76
- return match;
77
- }
78
- const escaped = _compiled.lodash.escapeRegExp(match);
79
- return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
80
- }
81
- const _joinPathParts = (_part, i, parts) => (0, _compiled.lodash)(parts).filter((part) => ![
82
- "/",
83
- "\\"
84
- ].includes(part)).tap((parts2) => parts2.unshift("")).slice(0, i + 2).join("/");
85
- function upwardPaths(start) {
86
- return (0, _compiled.lodash)(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
87
- }
88
65
  function getRealTemporaryDirectory() {
89
66
  let ret = null;
90
67
  try {
@@ -68,19 +68,19 @@ const getAddressUrls = (protocol = "http", port, host) => {
68
68
  }, []);
69
69
  };
70
70
  const prettyInstructions = (appContext, config) => {
71
- var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
71
+ var _appContext_builder_context_devServer, _appContext_builder, _config_dev, _config_source;
72
72
  const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
73
73
  const isHttps = (0, _is.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);
74
74
  const urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
75
75
  const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
76
76
  let message = "App running at:\n\n";
77
- if ((0, _is.isSingleEntry)(entrypoints) || apiOnly) {
77
+ if ((0, _is.isSingleEntry)(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) || apiOnly) {
78
78
  message += urls.map(({ label, url }) => ` ${_compiled.chalk.bold(`> ${label.padEnd(10)}`)}${_compiled.chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}
79
79
  `).join("");
80
80
  } else {
81
81
  const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
82
82
  urls.forEach(({ label, url }) => {
83
- message += ` ${_compiled.chalk.bold(`> ${label}`)}
83
+ message += ` ${_compiled.chalk.bold(`> ${label}`)}${routes.length === 0 ? _compiled.chalk.cyanBright(url) : ""}
84
84
  `;
85
85
  routes.forEach(({ entryName, urlPath, isSSR }) => {
86
86
  if (!checkedEntries.includes(entryName)) {
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "time", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return time;
9
+ }
10
+ });
11
+ function processHrtime(previousTimestamp) {
12
+ const now = (/* @__PURE__ */ new Date()).getTime();
13
+ const clocktime = now * 1e-3;
14
+ let seconds = Math.floor(clocktime);
15
+ let nanoseconds = Math.floor(clocktime % 1 * 1e9);
16
+ if (previousTimestamp) {
17
+ seconds -= previousTimestamp[0];
18
+ nanoseconds -= previousTimestamp[1];
19
+ if (nanoseconds < 0) {
20
+ seconds--;
21
+ nanoseconds += 1e9;
22
+ }
23
+ }
24
+ return [
25
+ seconds,
26
+ nanoseconds
27
+ ];
28
+ }
29
+ const getLatency = (hrtime) => {
30
+ const [s, ns] = processHrtime(hrtime);
31
+ return s * 1e3 + ns / 1e6;
32
+ };
33
+ const time = () => {
34
+ const hrtime = processHrtime();
35
+ return () => {
36
+ return getLatency(hrtime);
37
+ };
38
+ };
@@ -97,6 +97,8 @@ export var CHAIN_ID = {
97
97
  CSS_MODULES_TS: "css-modules-typescript",
98
98
  /** mini-css-extract-plugin.loader */
99
99
  MINI_CSS_EXTRACT: "mini-css-extract",
100
+ /** resolve-url-loader */
101
+ RESOLVE_URL_LOADER_FOR_SASS: "resolve-url-loader",
100
102
  /** builder-plugin-image-compress.loader */
101
103
  IMAGE_COMPRESS: "image-compress",
102
104
  /** builder-plugin-image-compress svgo-loader */
@@ -144,6 +146,14 @@ export var CHAIN_ID = {
144
146
  HTML_NONCE: "html-nonce",
145
147
  /** HtmlCrossOriginPlugin */
146
148
  HTML_CROSS_ORIGIN: "html-cross-origin",
149
+ /** htmlPreconnectPlugin */
150
+ HTML_PRECONNECT: "html-preconnect-plugin",
151
+ /** htmlDnsPrefetchPlugin */
152
+ HTML_DNS_PREFETCH: "html-dns-prefetch-plugin",
153
+ /** htmlPrefetchPlugin */
154
+ HTML_PREFETCH: "html-prefetch-plugin",
155
+ /** htmlPreloadPlugin */
156
+ HTML_PRELOAD: "html-preload-plugin",
147
157
  /** MiniCssExtractPlugin */
148
158
  MINI_CSS_EXTRACT: "mini-css-extract",
149
159
  /** VueLoaderPlugin */
@@ -10,7 +10,7 @@ export var LOADABLE_STATS_FILE = "loadable-stats.json";
10
10
  export var API_DIR = "api";
11
11
  export var SERVER_DIR = "server";
12
12
  export var SHARED_DIR = "shared";
13
- export var CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
13
+ export var CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
14
14
  export var CONFIG_FILE_EXTENSIONS = [
15
15
  ".js",
16
16
  ".ts",
@@ -12,7 +12,6 @@ export * from "./logger";
12
12
  export * from "./monorepo";
13
13
  export * from "./package";
14
14
  export * from "./path";
15
- export * from "./pathSerializer";
16
15
  export * from "./port";
17
16
  export * from "./prettyInstructions";
18
17
  export * from "./require";
@@ -1,3 +1,4 @@
1
+ import { MAIN_ENTRY_NAME } from "../constants";
1
2
  import { isEmpty } from "./type";
2
3
  export var isSSR = function(config) {
3
4
  var _server, _server1;
@@ -52,11 +53,12 @@ export var isRouterV5 = function(config) {
52
53
  return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && ((_config = config) === null || _config === void 0 ? void 0 : (_config_runtime1 = _config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
53
54
  };
54
55
  export var isSSGEntry = function(config, entryName, entrypoints) {
55
- var _ssgConfig, _ssgConfig1;
56
+ var _config_source, _ssgConfig, _ssgConfig1;
56
57
  var ssgConfig = config.output.ssg;
57
- var useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
58
+ var useSSG = isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
58
59
  return useSSG;
59
60
  };
60
61
  export var isSingleEntry = function(entrypoints) {
61
- return entrypoints.length === 1 && entrypoints[0].entryName === "main";
62
+ var mainEntryName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : MAIN_ENTRY_NAME;
63
+ return entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
62
64
  };
@@ -45,6 +45,11 @@ var DEFAULT_CONFIG = {
45
45
  displayLabel: true,
46
46
  uppercaseLabel: false
47
47
  };
48
+ var errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
49
+ var anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
50
+ export var isErrorStackMessage = function(message) {
51
+ return errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
52
+ };
48
53
  var Logger = /* @__PURE__ */ function() {
49
54
  "use strict";
50
55
  function Logger2() {
@@ -87,6 +92,11 @@ var Logger = /* @__PURE__ */ function() {
87
92
  } else {
88
93
  text = message.message;
89
94
  }
95
+ } else if (logType.level === "error" && typeof message === "string") {
96
+ var lines = message.split("\n");
97
+ text = lines.map(function(line) {
98
+ return isErrorStackMessage(line) ? chalk.gray(line) : line;
99
+ }).join("\n");
90
100
  } else {
91
101
  text = "".concat(message);
92
102
  }
@@ -2,7 +2,7 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
2
2
  import path from "path";
3
3
  import os from "os";
4
4
  import fs from "fs";
5
- import { nanoid, upath, lodash as _ } from "../compiled";
5
+ import { nanoid, upath } from "../compiled";
6
6
  export var isPathString = function(test) {
7
7
  return path.posix.basename(test) !== test || path.win32.basename(test) !== test;
8
8
  };
@@ -13,7 +13,7 @@ export var normalizeOutputPath = function(s) {
13
13
  return s.replace(/\\/g, "\\\\");
14
14
  };
15
15
  export var normalizeToPosixPath = function(p) {
16
- return upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, function(_2, m) {
16
+ return upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, function(_, m) {
17
17
  return "/".concat(m.toLowerCase());
18
18
  });
19
19
  };
@@ -27,26 +27,6 @@ export var getTemplatePath = function(prefix) {
27
27
  parts.push(nanoid());
28
28
  return (_path = path).resolve.apply(_path, _to_consumable_array(parts));
29
29
  };
30
- export function compilePathMatcherRegExp(match) {
31
- if (typeof match !== "string") {
32
- return match;
33
- }
34
- var escaped = _.escapeRegExp(match);
35
- return new RegExp("(?<=\\W|^)".concat(escaped, "(?=\\W|$)"));
36
- }
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
- };
47
- export function upwardPaths(start) {
48
- return _(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
49
- }
50
30
  export function getRealTemporaryDirectory() {
51
31
  var ret = null;
52
32
  try {
@@ -52,7 +52,7 @@ export var getAddressUrls = function() {
52
52
  }, []);
53
53
  };
54
54
  export var prettyInstructions = function(appContext, config) {
55
- var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
55
+ var _appContext_builder_context_devServer, _appContext_builder, _config_dev, _config_source;
56
56
  var entrypoints = appContext.entrypoints, serverRoutes = appContext.serverRoutes, port = appContext.port, apiOnly = appContext.apiOnly, checkedEntries = appContext.checkedEntries;
57
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
58
  var urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
@@ -60,7 +60,7 @@ export var prettyInstructions = function(appContext, config) {
60
60
  return route.entryName;
61
61
  }) : serverRoutes;
62
62
  var message = "App running at:\n\n";
63
- if (isSingleEntry(entrypoints) || apiOnly) {
63
+ if (isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) || apiOnly) {
64
64
  message += urls.map(function(param) {
65
65
  var label = param.label, url = param.url;
66
66
  return " ".concat(chalk.bold("> ".concat(label.padEnd(10)))).concat(chalk.cyanBright(normalizeUrl("".concat(url, "/").concat(routes[0].urlPath))), "\n");
@@ -72,7 +72,7 @@ export var prettyInstructions = function(appContext, config) {
72
72
  })));
73
73
  urls.forEach(function(param) {
74
74
  var label = param.label, url = param.url;
75
- message += " ".concat(chalk.bold("> ".concat(label)), "\n");
75
+ message += " ".concat(chalk.bold("> ".concat(label))).concat(routes.length === 0 ? chalk.cyanBright(url) : "", "\n");
76
76
  routes.forEach(function(param2) {
77
77
  var entryName = param2.entryName, urlPath = param2.urlPath, isSSR = param2.isSSR;
78
78
  if (!checkedEntries.includes(entryName)) {
@@ -0,0 +1,29 @@
1
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
+ function processHrtime(previousTimestamp) {
3
+ var now = (/* @__PURE__ */ new Date()).getTime();
4
+ var clocktime = now * 1e-3;
5
+ var seconds = Math.floor(clocktime);
6
+ var nanoseconds = Math.floor(clocktime % 1 * 1e9);
7
+ if (previousTimestamp) {
8
+ seconds -= previousTimestamp[0];
9
+ nanoseconds -= previousTimestamp[1];
10
+ if (nanoseconds < 0) {
11
+ seconds--;
12
+ nanoseconds += 1e9;
13
+ }
14
+ }
15
+ return [
16
+ seconds,
17
+ nanoseconds
18
+ ];
19
+ }
20
+ var getLatency = function(hrtime) {
21
+ var _processHrtime = _sliced_to_array(processHrtime(hrtime), 2), s = _processHrtime[0], ns = _processHrtime[1];
22
+ return s * 1e3 + ns / 1e6;
23
+ };
24
+ export var time = function() {
25
+ var hrtime = processHrtime();
26
+ return function() {
27
+ return getLatency(hrtime);
28
+ };
29
+ };
@@ -97,6 +97,8 @@ export const CHAIN_ID = {
97
97
  CSS_MODULES_TS: "css-modules-typescript",
98
98
  /** mini-css-extract-plugin.loader */
99
99
  MINI_CSS_EXTRACT: "mini-css-extract",
100
+ /** resolve-url-loader */
101
+ RESOLVE_URL_LOADER_FOR_SASS: "resolve-url-loader",
100
102
  /** builder-plugin-image-compress.loader */
101
103
  IMAGE_COMPRESS: "image-compress",
102
104
  /** builder-plugin-image-compress svgo-loader */
@@ -144,6 +146,14 @@ export const CHAIN_ID = {
144
146
  HTML_NONCE: "html-nonce",
145
147
  /** HtmlCrossOriginPlugin */
146
148
  HTML_CROSS_ORIGIN: "html-cross-origin",
149
+ /** htmlPreconnectPlugin */
150
+ HTML_PRECONNECT: "html-preconnect-plugin",
151
+ /** htmlDnsPrefetchPlugin */
152
+ HTML_DNS_PREFETCH: "html-dns-prefetch-plugin",
153
+ /** htmlPrefetchPlugin */
154
+ HTML_PREFETCH: "html-prefetch-plugin",
155
+ /** htmlPreloadPlugin */
156
+ HTML_PRELOAD: "html-preload-plugin",
147
157
  /** MiniCssExtractPlugin */
148
158
  MINI_CSS_EXTRACT: "mini-css-extract",
149
159
  /** VueLoaderPlugin */
@@ -9,7 +9,7 @@ export const LOADABLE_STATS_FILE = "loadable-stats.json";
9
9
  export const API_DIR = "api";
10
10
  export const SERVER_DIR = "server";
11
11
  export const SHARED_DIR = "shared";
12
- export const CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
12
+ export const CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
13
13
  export const CONFIG_FILE_EXTENSIONS = [
14
14
  ".js",
15
15
  ".ts",
@@ -12,7 +12,6 @@ export * from "./logger";
12
12
  export * from "./monorepo";
13
13
  export * from "./package";
14
14
  export * from "./path";
15
- export * from "./pathSerializer";
16
15
  export * from "./port";
17
16
  export * from "./prettyInstructions";
18
17
  export * from "./require";
@@ -1,3 +1,4 @@
1
+ import { MAIN_ENTRY_NAME } from "../constants";
1
2
  import { isEmpty } from "./type";
2
3
  export const isSSR = (config) => {
3
4
  var _server, _server1;
@@ -35,9 +36,9 @@ export const isRouterV5 = (config) => {
35
36
  return typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && ((_config = config) === null || _config === void 0 ? void 0 : (_config_runtime1 = _config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
36
37
  };
37
38
  export const isSSGEntry = (config, entryName, entrypoints) => {
38
- var _ssgConfig, _ssgConfig1;
39
+ var _config_source, _ssgConfig, _ssgConfig1;
39
40
  const ssgConfig = config.output.ssg;
40
- const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
41
+ const useSSG = isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) ? Boolean(ssgConfig) : ssgConfig === true || typeof ((_ssgConfig = ssgConfig) === null || _ssgConfig === void 0 ? void 0 : _ssgConfig[0]) === "function" || Boolean((_ssgConfig1 = ssgConfig) === null || _ssgConfig1 === void 0 ? void 0 : _ssgConfig1[entryName]);
41
42
  return useSSG;
42
43
  };
43
- export const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
44
+ export const isSingleEntry = (entrypoints, mainEntryName = MAIN_ENTRY_NAME) => entrypoints.length === 1 && entrypoints[0].entryName === mainEntryName;
@@ -40,6 +40,9 @@ const DEFAULT_CONFIG = {
40
40
  displayLabel: true,
41
41
  uppercaseLabel: false
42
42
  };
43
+ const errorStackRegExp = /^\s*at\s.*:\d+:\d+[\s)]*$/;
44
+ const anonymousErrorStackRegExp = /^\s*at\s.*\(<anonymous>\)$/;
45
+ export const isErrorStackMessage = (message) => errorStackRegExp.test(message) || anonymousErrorStackRegExp.test(message);
43
46
  class Logger {
44
47
  _log(type, message, ...args) {
45
48
  if (message === void 0 || message === null) {
@@ -65,6 +68,9 @@ ${chalk.grey(rest.join("\n"))}`;
65
68
  } else {
66
69
  text = message.message;
67
70
  }
71
+ } else if (logType.level === "error" && typeof message === "string") {
72
+ const lines = message.split("\n");
73
+ text = lines.map((line) => isErrorStackMessage(line) ? chalk.gray(line) : line).join("\n");
68
74
  } else {
69
75
  text = `${message}`;
70
76
  }
@@ -1,11 +1,11 @@
1
1
  import path from "path";
2
2
  import os from "os";
3
3
  import fs from "fs";
4
- import { nanoid, upath, lodash as _ } from "../compiled";
4
+ import { nanoid, upath } from "../compiled";
5
5
  export const isPathString = (test) => path.posix.basename(test) !== test || path.win32.basename(test) !== test;
6
6
  export const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
7
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()}`);
8
+ export const normalizeToPosixPath = (p) => upath.normalizeSafe(path.normalize(p || "")).replace(/^([a-zA-Z]+):/, (_, m) => `/${m.toLowerCase()}`);
9
9
  export const getTemplatePath = (prefix) => {
10
10
  const tmpRoot = fs.realpathSync(os.tmpdir());
11
11
  const parts = [
@@ -15,20 +15,6 @@ export const getTemplatePath = (prefix) => {
15
15
  parts.push(nanoid());
16
16
  return path.resolve(...parts);
17
17
  };
18
- export function compilePathMatcherRegExp(match) {
19
- if (typeof match !== "string") {
20
- return match;
21
- }
22
- const escaped = _.escapeRegExp(match);
23
- return new RegExp(`(?<=\\W|^)${escaped}(?=\\W|$)`);
24
- }
25
- export const _joinPathParts = (_part, i, parts) => _(parts).filter((part) => ![
26
- "/",
27
- "\\"
28
- ].includes(part)).tap((parts2) => parts2.unshift("")).slice(0, i + 2).join("/");
29
- export function upwardPaths(start) {
30
- return _(start).split(/[/\\]/).filter(Boolean).map(_joinPathParts).reverse().push("/").value();
31
- }
32
18
  export function getRealTemporaryDirectory() {
33
19
  let ret = null;
34
20
  try {
@@ -48,19 +48,19 @@ export const getAddressUrls = (protocol = "http", port, host) => {
48
48
  }, []);
49
49
  };
50
50
  export const prettyInstructions = (appContext, config) => {
51
- var _appContext_builder_context_devServer, _appContext_builder, _config_dev;
51
+ var _appContext_builder_context_devServer, _appContext_builder, _config_dev, _config_source;
52
52
  const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
53
53
  const 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);
54
54
  const urls = getAddressUrls(isHttps ? "https" : "http", port, (_config_dev = config.dev) === null || _config_dev === void 0 ? void 0 : _config_dev.host);
55
55
  const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
56
56
  let message = "App running at:\n\n";
57
- if (isSingleEntry(entrypoints) || apiOnly) {
57
+ if (isSingleEntry(entrypoints, (_config_source = config.source) === null || _config_source === void 0 ? void 0 : _config_source.mainEntryName) || apiOnly) {
58
58
  message += urls.map(({ label, url }) => ` ${chalk.bold(`> ${label.padEnd(10)}`)}${chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}
59
59
  `).join("");
60
60
  } else {
61
61
  const maxNameLength = Math.max(...routes.map((r) => r.entryName.length));
62
62
  urls.forEach(({ label, url }) => {
63
- message += ` ${chalk.bold(`> ${label}`)}
63
+ message += ` ${chalk.bold(`> ${label}`)}${routes.length === 0 ? chalk.cyanBright(url) : ""}
64
64
  `;
65
65
  routes.forEach(({ entryName, urlPath, isSSR }) => {
66
66
  if (!checkedEntries.includes(entryName)) {
@@ -0,0 +1,28 @@
1
+ function processHrtime(previousTimestamp) {
2
+ const now = (/* @__PURE__ */ new Date()).getTime();
3
+ const clocktime = now * 1e-3;
4
+ let seconds = Math.floor(clocktime);
5
+ let nanoseconds = Math.floor(clocktime % 1 * 1e9);
6
+ if (previousTimestamp) {
7
+ seconds -= previousTimestamp[0];
8
+ nanoseconds -= previousTimestamp[1];
9
+ if (nanoseconds < 0) {
10
+ seconds--;
11
+ nanoseconds += 1e9;
12
+ }
13
+ }
14
+ return [
15
+ seconds,
16
+ nanoseconds
17
+ ];
18
+ }
19
+ const getLatency = (hrtime) => {
20
+ const [s, ns] = processHrtime(hrtime);
21
+ return s * 1e3 + ns / 1e6;
22
+ };
23
+ export const time = () => {
24
+ const hrtime = processHrtime();
25
+ return () => {
26
+ return getLatency(hrtime);
27
+ };
28
+ };
@@ -97,6 +97,8 @@ export declare const CHAIN_ID: {
97
97
  readonly CSS_MODULES_TS: "css-modules-typescript";
98
98
  /** mini-css-extract-plugin.loader */
99
99
  readonly MINI_CSS_EXTRACT: "mini-css-extract";
100
+ /** resolve-url-loader */
101
+ readonly RESOLVE_URL_LOADER_FOR_SASS: "resolve-url-loader";
100
102
  /** builder-plugin-image-compress.loader */
101
103
  readonly IMAGE_COMPRESS: "image-compress";
102
104
  /** builder-plugin-image-compress svgo-loader */
@@ -144,6 +146,14 @@ export declare const CHAIN_ID: {
144
146
  readonly HTML_NONCE: "html-nonce";
145
147
  /** HtmlCrossOriginPlugin */
146
148
  readonly HTML_CROSS_ORIGIN: "html-cross-origin";
149
+ /** htmlPreconnectPlugin */
150
+ readonly HTML_PRECONNECT: "html-preconnect-plugin";
151
+ /** htmlDnsPrefetchPlugin */
152
+ readonly HTML_DNS_PREFETCH: "html-dns-prefetch-plugin";
153
+ /** htmlPrefetchPlugin */
154
+ readonly HTML_PREFETCH: "html-prefetch-plugin";
155
+ /** htmlPreloadPlugin */
156
+ readonly HTML_PRELOAD: "html-preload-plugin";
147
157
  /** MiniCssExtractPlugin */
148
158
  readonly MINI_CSS_EXTRACT: "mini-css-extract";
149
159
  /** VueLoaderPlugin */
@@ -40,7 +40,7 @@ export declare const SHARED_DIR = "shared";
40
40
  /**
41
41
  * Modern.config.ts cached dir
42
42
  */
43
- export declare const CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
43
+ export declare const CONFIG_CACHE_DIR = "./node_modules/.cache/bundle-require";
44
44
  export declare const CONFIG_FILE_EXTENSIONS: string[];
45
45
  /**
46
46
  * Serialized config path
@@ -12,7 +12,6 @@ export * from './logger';
12
12
  export * from './monorepo';
13
13
  export * from './package';
14
14
  export * from './path';
15
- export * from './pathSerializer';
16
15
  export * from './port';
17
16
  export * from './prettyInstructions';
18
17
  export * from './require';
@@ -24,5 +24,5 @@ export declare const isRouterV5: (config: {
24
24
  };
25
25
  }) => boolean;
26
26
  export declare const isSSGEntry: (config: any, entryName: string, entrypoints: EntryPoint[]) => boolean;
27
- export declare const isSingleEntry: (entrypoints: EntryPoint[]) => boolean;
27
+ export declare const isSingleEntry: (entrypoints: EntryPoint[], mainEntryName?: string) => boolean;
28
28
  export {};
@@ -46,6 +46,7 @@ declare const LOG_TYPES: {
46
46
  level: string;
47
47
  };
48
48
  };
49
+ export declare const isErrorStackMessage: (message: string) => boolean;
49
50
  declare class Logger {
50
51
  private readonly level;
51
52
  private readonly config;
@@ -1,17 +1,8 @@
1
- import { lodash as _ } from '../compiled';
2
1
  export declare const isPathString: (test: string) => boolean;
3
2
  export declare const isRelativePath: (test: string) => boolean;
4
3
  export declare const normalizeOutputPath: (s: string) => string;
5
4
  export declare const normalizeToPosixPath: (p: string | undefined) => string;
6
5
  export declare const getTemplatePath: (prefix?: string) => string;
7
- /**
8
- * Compile path string to RegExp.
9
- * @note Only support posix path.
10
- */
11
- export declare function compilePathMatcherRegExp(match: string | RegExp): RegExp;
12
- /** @internal @see {@link upwardPaths} */
13
- export declare const _joinPathParts: (_part: unknown, i: number, parts: _.List<string>) => string;
14
- export declare function upwardPaths(start: string): string[];
15
6
  export declare function getRealTemporaryDirectory(): string | null;
16
7
  export declare function splitPathString(str: string): string[];
17
8
  export declare const removeLeadingSlash: (s: string) => string;
@@ -0,0 +1 @@
1
+ export declare const time: () => () => number;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.28.0",
18
+ "version": "2.30.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -76,6 +76,11 @@
76
76
  "import": "./dist/esm/universal/pluginDagSort.js",
77
77
  "default": "./dist/cjs/universal/pluginDagSort.js"
78
78
  },
79
+ "./universal/time": {
80
+ "types": "./dist/types/universal/time.d.ts",
81
+ "import": "./dist/esm/universal/time.js",
82
+ "default": "./dist/cjs/universal/time.js"
83
+ },
79
84
  "./ajv": "./dist/compiled/ajv/index.js",
80
85
  "./commander": "./dist/compiled/commander/index.js",
81
86
  "./ora": "./dist/compiled/ora/index.js",
@@ -138,6 +143,9 @@
138
143
  "universal/plugin-dag-sort": [
139
144
  "./dist/types/universal/pluginDagSort.d.ts"
140
145
  ],
146
+ "universal/time": [
147
+ "./dist/types/universal/time.d.ts"
148
+ ],
141
149
  "ajv": [
142
150
  "./dist/compiled/ajv/types/ajv.d.ts"
143
151
  ],
@@ -235,9 +243,9 @@
235
243
  "typescript": "^5",
236
244
  "webpack": "^5.88.1",
237
245
  "@types/serialize-javascript": "^5.0.1",
238
- "@modern-js/types": "2.28.0",
239
- "@scripts/build": "2.28.0",
240
- "@scripts/jest-config": "2.28.0"
246
+ "@scripts/build": "2.30.0",
247
+ "@scripts/jest-config": "2.30.0",
248
+ "@modern-js/types": "2.30.0"
241
249
  },
242
250
  "sideEffects": false,
243
251
  "scripts": {
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- matchUpwardPathsAsUnknown: function() {
14
- return matchUpwardPathsAsUnknown;
15
- },
16
- applyPathMatcher: function() {
17
- return applyPathMatcher;
18
- },
19
- applyMatcherReplacement: function() {
20
- return applyMatcherReplacement;
21
- },
22
- createDefaultPathMatchers: function() {
23
- return createDefaultPathMatchers;
24
- }
25
- });
26
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
27
- const _os = /* @__PURE__ */ _interop_require_default._(require("os"));
28
- const _lodash = /* @__PURE__ */ _interop_require_default._(require("../../compiled/lodash"));
29
- const _path = require("./path");
30
- const matchUpwardPathsAsUnknown = (p) => (0, _lodash.default)((0, _path.upwardPaths)((0, _path.normalizeToPosixPath)(p))).map((match) => ({
31
- match,
32
- mark: "unknown"
33
- })).slice(1, -1).value();
34
- function applyPathMatcher(matcher, str, options = {}) {
35
- const regex = (0, _path.compilePathMatcherRegExp)(matcher.match);
36
- const replacer = (substring, ...args) => {
37
- if (options.minPartials && (0, _path.splitPathString)(substring).length < options.minPartials) {
38
- return substring;
39
- }
40
- const ret = typeof matcher.mark === "string" ? matcher.mark : matcher.mark(substring, ...args);
41
- return `<${_lodash.default.snakeCase(ret).toUpperCase()}>`;
42
- };
43
- return str.replace(regex, replacer);
44
- }
45
- function applyMatcherReplacement(matchers, str, options = {}) {
46
- return matchers.reduce((ret, matcher) => {
47
- return applyPathMatcher(matcher, ret, options);
48
- }, str);
49
- }
50
- const createDefaultPathMatchers = (root) => {
51
- const ret = [
52
- {
53
- match: RegExp("(?<=\\/)(\\.pnpm\\/.+?\\/node_modules)(?=\\/)"),
54
- mark: "pnpmInner"
55
- }
56
- ];
57
- const tmpdir = (0, _path.getRealTemporaryDirectory)();
58
- tmpdir && ret.push({
59
- match: tmpdir,
60
- mark: "temp"
61
- });
62
- ret.push({
63
- match: _os.default.tmpdir(),
64
- mark: "temp"
65
- });
66
- ret.push({
67
- match: _os.default.homedir(),
68
- mark: "home"
69
- });
70
- ret.push(...matchUpwardPathsAsUnknown(root));
71
- return ret;
72
- };
@@ -1,60 +0,0 @@
1
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
2
- import os from "os";
3
- import _ from "../../compiled/lodash";
4
- import { compilePathMatcherRegExp, normalizeToPosixPath, getRealTemporaryDirectory, splitPathString, upwardPaths } from "./path";
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;
21
- if (options.minPartials && splitPathString(substring).length < options.minPartials) {
22
- return substring;
23
- }
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(), ">");
28
- };
29
- return str.replace(regex, replacer);
30
- }
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) {
34
- return applyPathMatcher(matcher, ret, options);
35
- }, str);
36
- }
37
- export var createDefaultPathMatchers = function(root) {
38
- var _ret;
39
- var ret = [
40
- {
41
- match: RegExp("(?<=\\/)(\\.pnpm\\/.+?\\/node_modules)(?=\\/)"),
42
- mark: "pnpmInner"
43
- }
44
- ];
45
- var tmpdir = getRealTemporaryDirectory();
46
- tmpdir && ret.push({
47
- match: tmpdir,
48
- mark: "temp"
49
- });
50
- ret.push({
51
- match: os.tmpdir(),
52
- mark: "temp"
53
- });
54
- ret.push({
55
- match: os.homedir(),
56
- mark: "home"
57
- });
58
- (_ret = ret).push.apply(_ret, _to_consumable_array(matchUpwardPathsAsUnknown(root)));
59
- return ret;
60
- };
@@ -1,46 +0,0 @@
1
- import os from "os";
2
- import _ from "../../compiled/lodash";
3
- 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) => {
11
- if (options.minPartials && splitPathString(substring).length < options.minPartials) {
12
- return substring;
13
- }
14
- const ret = typeof matcher.mark === "string" ? matcher.mark : matcher.mark(substring, ...args);
15
- return `<${_.snakeCase(ret).toUpperCase()}>`;
16
- };
17
- return str.replace(regex, replacer);
18
- }
19
- export function applyMatcherReplacement(matchers, str, options = {}) {
20
- return matchers.reduce((ret, matcher) => {
21
- return applyPathMatcher(matcher, ret, options);
22
- }, str);
23
- }
24
- export const createDefaultPathMatchers = (root) => {
25
- const ret = [
26
- {
27
- match: RegExp("(?<=\\/)(\\.pnpm\\/.+?\\/node_modules)(?=\\/)"),
28
- mark: "pnpmInner"
29
- }
30
- ];
31
- const tmpdir = getRealTemporaryDirectory();
32
- tmpdir && ret.push({
33
- match: tmpdir,
34
- mark: "temp"
35
- });
36
- ret.push({
37
- match: os.tmpdir(),
38
- mark: "temp"
39
- });
40
- ret.push({
41
- match: os.homedir(),
42
- mark: "home"
43
- });
44
- ret.push(...matchUpwardPathsAsUnknown(root));
45
- return ret;
46
- };
@@ -1,16 +0,0 @@
1
- /** Different from */
2
- export type PathMatchExpression = string | RegExp;
3
- export interface PathMatcher {
4
- match: PathMatchExpression;
5
- mark: string | ((substring: string, ...args: any[]) => string);
6
- }
7
- export declare const matchUpwardPathsAsUnknown: (p: string) => {
8
- match: string;
9
- mark: string;
10
- }[];
11
- export interface ApplyPathMatcherOptions {
12
- minPartials?: number;
13
- }
14
- export declare function applyPathMatcher(matcher: PathMatcher, str: string, options?: ApplyPathMatcherOptions): string;
15
- export declare function applyMatcherReplacement(matchers: PathMatcher[], str: string, options?: ApplyPathMatcherOptions): string;
16
- export declare const createDefaultPathMatchers: (root: string) => PathMatcher[];