js-dev-tool 1.0.18 → 1.0.19
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/package.json +2 -2
- package/regex.d.ts +9 -13
- package/scripts/publish-version.json +1 -1
- package/tool-lib/cjbm.js +9 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-dev-tool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"bin": {
|
|
5
5
|
"jstool": "tools.js"
|
|
6
6
|
},
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"fflate": "^0.8.2",
|
|
51
51
|
"mini-semaphore": "^1.4.4",
|
|
52
52
|
"replace": "^1.2.2",
|
|
53
|
-
"rm-cstyle-cmts": "^3.3.
|
|
53
|
+
"rm-cstyle-cmts": "^3.3.26",
|
|
54
54
|
"terser": "^5.44.1",
|
|
55
55
|
"tin-args": "^0.1.1"
|
|
56
56
|
}
|
package/regex.d.ts
CHANGED
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* @file js-dev-scripts/regex.d.ts
|
|
10
|
+
* @desc It is recommended to add `"skipLibCheck": true` to your tsconfig.
|
|
11
|
+
* @todo publish as "annotate-regex"
|
|
10
12
|
*/
|
|
11
13
|
declare global {
|
|
12
|
-
interface RegExp
|
|
14
|
+
interface RegExp {
|
|
13
15
|
/**
|
|
14
16
|
* Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search.
|
|
15
17
|
* @template {string} P
|
|
@@ -38,10 +40,7 @@ declare global {
|
|
|
38
40
|
* @param {F} [flags] The flags for the regular expression.
|
|
39
41
|
* @returns {RegExp & { readonly source: P; readonly flags: F }} A typed RegExp object.
|
|
40
42
|
*/
|
|
41
|
-
new <const P extends string, const F extends string = "">(pattern: P, flags?: F):
|
|
42
|
-
readonly source: P;
|
|
43
|
-
readonly flags: F;
|
|
44
|
-
};
|
|
43
|
+
new <const P extends string, const F extends string = "">(pattern: P, flags?: F): TypedRegExp<P, F>;
|
|
45
44
|
/**
|
|
46
45
|
* Creates a typed RegExp object with literal types for the pattern and flags.
|
|
47
46
|
* @template {string} P
|
|
@@ -50,10 +49,7 @@ declare global {
|
|
|
50
49
|
* @param {F} [flags] The flags for the regular expression.
|
|
51
50
|
* @returns {RegExp & { readonly source: P; readonly flags: F }} A typed RegExp object.
|
|
52
51
|
*/
|
|
53
|
-
<const P extends string, const F extends string = "">(pattern: P, flags?: F):
|
|
54
|
-
readonly source: P;
|
|
55
|
-
readonly flags: F;
|
|
56
|
-
};
|
|
52
|
+
<const P extends string, const F extends string = "">(pattern: P, flags?: F): TypedRegExp<P, F>;
|
|
57
53
|
readonly "prototype": RegExp;
|
|
58
54
|
}
|
|
59
55
|
}
|
|
@@ -66,7 +62,7 @@ export type Brand<Tag extends string> = {
|
|
|
66
62
|
[k in Tag]: true;
|
|
67
63
|
};
|
|
68
64
|
export type TypedRegExpBrand = Brand<"__TypedRegExp">;
|
|
69
|
-
export type TypedRegExp<
|
|
65
|
+
export type TypedRegExp<P extends string, F extends string = ""> = RegExp & {
|
|
70
66
|
readonly source: P;
|
|
71
67
|
readonly flags: F;
|
|
72
68
|
} & TypedRegExpBrand;
|
|
@@ -90,7 +86,7 @@ type FirstChar<S extends string> = S extends `${infer F}${infer _}` ? F : never;
|
|
|
90
86
|
* without considering nesting, and unions them.
|
|
91
87
|
* @template S - A string pattern.
|
|
92
88
|
*/
|
|
93
|
-
export type ExtractGroupNames<S extends
|
|
89
|
+
export type ExtractGroupNames<S extends unknown> =
|
|
94
90
|
S extends `${infer _Before}(?<${infer Rest}`
|
|
95
91
|
? FirstChar<Rest> extends "=" | "!"
|
|
96
92
|
? ExtractGroupNames<Rest>
|
|
@@ -197,11 +193,11 @@ export type ReplaceCallbackParams<
|
|
|
197
193
|
input: string,
|
|
198
194
|
groups: RegExpNamedGroups<R>
|
|
199
195
|
];
|
|
200
|
-
export type ReplacerFunctionSignature<R extends
|
|
196
|
+
export type ReplacerFunctionSignature<R extends unknown> =
|
|
201
197
|
R extends (
|
|
202
198
|
RegExp & { readonly source: infer T }
|
|
203
199
|
) ? R extends TypedRegExpBrand
|
|
204
|
-
? (...args: ReplaceCallbackParams<R, T
|
|
200
|
+
? (...args: ReplaceCallbackParams<R/* , T */>) => string
|
|
205
201
|
: (match: string, ...rest: any[]) => string
|
|
206
202
|
: string;
|
|
207
203
|
export as namespace XRegex;
|
package/tool-lib/cjbm.js
CHANGED
|
@@ -13,21 +13,15 @@
|
|
|
13
13
|
const fs = require("fs");
|
|
14
14
|
const path = require("path");
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @
|
|
18
|
-
* @template {string} F
|
|
19
|
-
* @param {P} pattern The regular expression pattern.
|
|
20
|
-
* @param {F} [flags] The flags for the regular expression.
|
|
21
|
-
* @returns {XRegex.TypedRegExp<P, F>} A typed RegExp object.
|
|
16
|
+
* DEVNOTE: Improved `RegExpConstructor` interface makes `createRegExp` unnecessary
|
|
17
|
+
* @date 2025/12/25 22:10:17
|
|
22
18
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(
|
|
29
|
-
(?:\\.(?<dynamicExt>(?:c|m)?jsx?))?\\k<qcDynamic>\\s*\\)|(?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+\\})\\s*from)\\s*(?<qcEsm>["'])(?!https?:)(?=[.\\/]+)\
|
|
30
|
-
(?:(?<moduleName>(?:[.\\/]+)?[^'"]+?)(?:\\.(?<moduleExt>(?:c|m)?jsx?))?)\\k<qcEsm>)(?=\\s*;)?`, "g"
|
|
19
|
+
const reImportExportDetection = new RegExp(
|
|
20
|
+
`(?:(?:^\\s*?\\/\\*+?[\\s\\S]*?\\*\\/)|(?<!\\s*\\/\\/+.*?)(?:(?<!@)import|export)\\s*\
|
|
21
|
+
(?:(?<qcGlobal>["'])(?!https?:)(?=(?:\\.\\.?\\/)+)(?:(?<globalName>(?:(?:\\.\\.?\\/)+)?[^'"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?)\\k<qcGlobal>|\
|
|
22
|
+
\\(\\s*(?<qcDynamic>["'])(?!https?:)(?=(?:\\.\\.?\\/)+)(?<dynamicName>(?:(?:\\.\\.?\\/)+)?[^'"]+?)(?:\\.(?<dynamicExt>(?:c|m)?jsx?))?\\k<qcDynamic>\\s*\\)|\
|
|
23
|
+
(?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+})\\s*from)\\s*(?<qcEsm>["'])(?!https?:)(?=(?:\\.\\.?\\/)+)(?:(?<moduleName>(?:(?:\\.\\.?\\/)+)?[^'"]+?)(?:\\.(?<moduleExt>(?:c|m)?jsx?))?)\\k<qcEsm>)\
|
|
24
|
+
(?=\\s*;)?)`, "gm"
|
|
31
25
|
);
|
|
32
26
|
/**
|
|
33
27
|
* @typedef {XRegex.ReplacerFunctionSignature<typeof reImportExportDetection>} TImportExportDetectRegexReplacer
|
|
@@ -49,6 +43,7 @@ function getReplacer(ext) {
|
|
|
49
43
|
return (
|
|
50
44
|
match, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _offset, _input, groups
|
|
51
45
|
) => {
|
|
46
|
+
if (/\s*?\/\*/.test(match)) return match;
|
|
52
47
|
const {
|
|
53
48
|
clause,
|
|
54
49
|
dynamicName,
|