@modern-js/utils 2.27.0 → 2.29.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 +32 -0
- package/dist/cjs/cli/alias.js +3 -3
- package/dist/cjs/cli/constants/chainId.js +10 -0
- package/dist/cjs/cli/constants/index.js +1 -2
- package/dist/cjs/cli/index.js +0 -1
- package/dist/cjs/cli/is/config.js +13 -9
- package/dist/cjs/cli/logger.js +9 -0
- package/dist/cjs/cli/path.js +0 -23
- package/dist/cjs/cli/prettyInstructions.js +6 -5
- 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 -8
- package/dist/cjs/universal/time.js +38 -0
- package/dist/esm/cli/alias.js +3 -3
- package/dist/esm/cli/constants/chainId.js +10 -0
- package/dist/esm/cli/constants/index.js +1 -2
- package/dist/esm/cli/get/data.js +12 -3
- package/dist/esm/cli/index.js +0 -1
- package/dist/esm/cli/is/config.js +14 -9
- package/dist/esm/cli/logger.js +10 -0
- package/dist/esm/cli/path.js +2 -22
- package/dist/esm/cli/prettyInstructions.js +6 -5
- package/dist/esm/cli/require.js +2 -1
- package/dist/esm/runtime/nestedRoutes.js +9 -5
- package/dist/esm/runtime-browser/parsed.js +2 -1
- package/dist/esm/universal/formatWebpack.js +36 -4
- package/dist/esm/universal/time.js +29 -0
- package/dist/esm-node/cli/alias.js +3 -3
- package/dist/esm-node/cli/constants/chainId.js +10 -0
- package/dist/esm-node/cli/constants/index.js +1 -2
- package/dist/esm-node/cli/index.js +0 -1
- package/dist/esm-node/cli/is/config.js +13 -9
- package/dist/esm-node/cli/logger.js +6 -0
- package/dist/esm-node/cli/path.js +2 -16
- package/dist/esm-node/cli/prettyInstructions.js +6 -5
- package/dist/esm-node/cli/require.js +2 -1
- package/dist/esm-node/runtime/nestedRoutes.js +9 -5
- package/dist/esm-node/runtime-browser/parsed.js +2 -1
- package/dist/esm-node/universal/formatWebpack.js +43 -5
- package/dist/esm-node/universal/time.js +28 -0
- package/dist/types/cli/constants/chainId.d.ts +10 -0
- package/dist/types/cli/constants/index.d.ts +1 -1
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/is/config.d.ts +1 -1
- package/dist/types/cli/logger.d.ts +1 -0
- package/dist/types/cli/path.d.ts +0 -9
- package/dist/types/universal/formatWebpack.d.ts +14 -1
- package/dist/types/universal/time.d.ts +1 -0
- package/package.json +12 -4
- package/dist/cjs/cli/pathSerializer.js +0 -72
- package/dist/esm/cli/pathSerializer.js +0 -60
- package/dist/esm-node/cli/pathSerializer.js +0 -46
- package/dist/types/cli/pathSerializer.d.ts +0 -16
@@ -6,7 +6,8 @@ export const parsedJSONFromElement = (id) => {
|
|
6
6
|
const element = elements[elements.length - 1];
|
7
7
|
if (element) {
|
8
8
|
try {
|
9
|
-
|
9
|
+
var _element;
|
10
|
+
const parsed = JSON.parse(((_element = element) === null || _element === void 0 ? void 0 : _element.textContent) || "");
|
10
11
|
return parsed;
|
11
12
|
} catch (e) {
|
12
13
|
console.error(`parse ${id} error`, e);
|
@@ -42,13 +42,50 @@ ${stats.stack}` : "";
|
|
42
42
|
message = lines.join("\n");
|
43
43
|
return message.trim();
|
44
44
|
}
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
const noop = (message) => message;
|
46
|
+
const defaultColor = {
|
47
|
+
gray: noop,
|
48
|
+
cyan: noop,
|
49
|
+
green: noop,
|
50
|
+
yellow: noop,
|
51
|
+
underline: noop
|
52
|
+
};
|
53
|
+
export function addErrorTips(errors, color = defaultColor) {
|
54
|
+
const errorHelpers = [
|
55
|
+
{
|
56
|
+
validator(message) {
|
57
|
+
return (message.includes("You may need an appropriate loader") || message.includes("You may need an additional loader")) && message.includes(".ts");
|
58
|
+
},
|
59
|
+
formatter(message) {
|
60
|
+
return `${message}
|
61
|
+
|
62
|
+
${color.yellow(`If it is a TypeScript file, you can use "source.include" config to compile it. see ${color.underline("https://modernjs.dev/builder/en/api/config-source.html#sourceinclude")}`)}
|
63
|
+
|
64
|
+
${color.green(`${color.gray("// config file")}
|
65
|
+
export default {
|
66
|
+
source: {
|
67
|
+
include: [
|
68
|
+
${color.gray("// add some include rules")}
|
69
|
+
]
|
70
|
+
}
|
71
|
+
}`)}
|
72
|
+
`;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
];
|
76
|
+
return errors.map((error) => {
|
77
|
+
const helper = errorHelpers.find((item) => item.validator(error));
|
78
|
+
return helper ? helper.formatter(error) : error;
|
79
|
+
});
|
80
|
+
}
|
81
|
+
function formatWebpackMessages(json, color = defaultColor) {
|
82
|
+
var _json_errors, _json, _json_warnings, _json1, _result_errors;
|
83
|
+
const formattedErrors = (_json = json) === null || _json === void 0 ? void 0 : (_json_errors = _json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
|
84
|
+
const formattedWarnings = (_json1 = json) === null || _json1 === void 0 ? void 0 : (_json_warnings = _json1.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
|
49
85
|
const result = {
|
50
86
|
errors: formattedErrors || [],
|
51
|
-
warnings: formattedWarnings || []
|
87
|
+
warnings: formattedWarnings || [],
|
88
|
+
errorTips: []
|
52
89
|
};
|
53
90
|
if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
|
54
91
|
result.errors = result.errors.filter(isLikelyASyntaxError);
|
@@ -56,6 +93,7 @@ function formatWebpackMessages(json) {
|
|
56
93
|
if (result.errors.length > 1) {
|
57
94
|
result.errors.length = 1;
|
58
95
|
}
|
96
|
+
result.errors = addErrorTips(result.errors, color);
|
59
97
|
return result;
|
60
98
|
}
|
61
99
|
export { formatWebpackMessages };
|
@@ -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
|
+
};
|
@@ -37,6 +37,8 @@ export declare const CHAIN_ID: {
|
|
37
37
|
readonly YAML: "yaml";
|
38
38
|
/** Rule for wasm */
|
39
39
|
readonly WASM: "wasm";
|
40
|
+
/** Rule for node */
|
41
|
+
readonly NODE: "node";
|
40
42
|
/** Rule for bff */
|
41
43
|
readonly JS_BFF_API: "js-bff-api";
|
42
44
|
};
|
@@ -75,6 +77,8 @@ export declare const CHAIN_ID: {
|
|
75
77
|
readonly TOML: "toml";
|
76
78
|
/** html-loader */
|
77
79
|
readonly HTML: "html";
|
80
|
+
/** node-loader */
|
81
|
+
readonly NODE: "html";
|
78
82
|
/** babel-loader */
|
79
83
|
readonly BABEL: "babel";
|
80
84
|
/** esbuild-loader */
|
@@ -93,6 +97,8 @@ export declare const CHAIN_ID: {
|
|
93
97
|
readonly CSS_MODULES_TS: "css-modules-typescript";
|
94
98
|
/** mini-css-extract-plugin.loader */
|
95
99
|
readonly MINI_CSS_EXTRACT: "mini-css-extract";
|
100
|
+
/** resolve-url-loader */
|
101
|
+
readonly RESOLVE_URL_LOADER_FOR_SASS: "resolve-url-loader";
|
96
102
|
/** builder-plugin-image-compress.loader */
|
97
103
|
readonly IMAGE_COMPRESS: "image-compress";
|
98
104
|
/** builder-plugin-image-compress svgo-loader */
|
@@ -140,6 +146,10 @@ export declare const CHAIN_ID: {
|
|
140
146
|
readonly HTML_NONCE: "html-nonce";
|
141
147
|
/** HtmlCrossOriginPlugin */
|
142
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";
|
143
153
|
/** MiniCssExtractPlugin */
|
144
154
|
readonly MINI_CSS_EXTRACT: "mini-css-extract";
|
145
155
|
/** 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/
|
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
|
@@ -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 {};
|
package/dist/types/cli/path.d.ts
CHANGED
@@ -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;
|
@@ -6,7 +6,20 @@
|
|
6
6
|
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
7
7
|
*/
|
8
8
|
import type { StatsCompilation } from 'webpack';
|
9
|
-
declare function
|
9
|
+
export declare function addErrorTips(errors: string[], color?: {
|
10
|
+
gray: (message: string) => string;
|
11
|
+
cyan: (message: string) => string;
|
12
|
+
green: (message: string) => string;
|
13
|
+
yellow: (message: string) => string;
|
14
|
+
underline: (message: string) => string;
|
15
|
+
}): string[];
|
16
|
+
declare function formatWebpackMessages(json?: Pick<StatsCompilation, 'errors' | 'warnings'>, color?: {
|
17
|
+
gray: (message: string) => string;
|
18
|
+
cyan: (message: string) => string;
|
19
|
+
green: (message: string) => string;
|
20
|
+
yellow: (message: string) => string;
|
21
|
+
underline: (message: string) => string;
|
22
|
+
}): {
|
10
23
|
errors: string[];
|
11
24
|
warnings: string[];
|
12
25
|
};
|
@@ -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.
|
18
|
+
"version": "2.29.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.
|
239
|
-
"@scripts/
|
240
|
-
"@scripts/
|
246
|
+
"@modern-js/types": "2.29.0",
|
247
|
+
"@scripts/build": "2.29.0",
|
248
|
+
"@scripts/jest-config": "2.29.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[];
|