js-dev-tool 1.0.12 → 1.0.14
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 -1
- package/regex.d.ts +49 -12
- package/scripts/publish-version.json +1 -1
- package/tool-lib/cjbm.js +31 -18
- package/tool-lib/tools.d.ts +5 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-dev-tool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"bin": {
|
|
5
5
|
"jstool": "tools.js"
|
|
6
6
|
},
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"tools.js",
|
|
33
33
|
"utils.js",
|
|
34
34
|
"tsconfig.json",
|
|
35
|
+
"!tool-lib/cjbm-*",
|
|
35
36
|
"!scripts/unzip.ts",
|
|
36
37
|
"!scripts/bin",
|
|
37
38
|
"!extras/npm",
|
package/regex.d.ts
CHANGED
|
@@ -38,6 +38,14 @@ export type ExtractGroupNames<S extends string> =
|
|
|
38
38
|
export type ReGroups<R extends RegExp> = {
|
|
39
39
|
[K in ExtractGroupNames<ReSource<R>>]?: string;
|
|
40
40
|
};
|
|
41
|
+
export type PreprocessEscapes<S extends string, Result extends string = ""> =
|
|
42
|
+
S extends `\\\\${infer Rest}`
|
|
43
|
+
? PreprocessEscapes<Rest, `${Result}__`>
|
|
44
|
+
: S extends `\\${infer Next}${infer Rest}`
|
|
45
|
+
? PreprocessEscapes<Rest, `${Result}_`>
|
|
46
|
+
: S extends `${infer Char}${infer Rest}`
|
|
47
|
+
? PreprocessEscapes<Rest, `${Result}${Char}`>
|
|
48
|
+
: Result;
|
|
41
49
|
/**
|
|
42
50
|
* Counts the exact number of capture groups in a string pattern.
|
|
43
51
|
* @template S - A string pattern.
|
|
@@ -46,17 +54,21 @@ export type ReGroups<R extends RegExp> = {
|
|
|
46
54
|
* @todo FIXME: 多く count してしまう場合あり. 2025/3/18 15:47:57
|
|
47
55
|
* @deprecated text base の parse には限界があり cost が見合わないので、この type は将来削除予定!
|
|
48
56
|
*/
|
|
49
|
-
export type CountCaptureGroups<
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
export type CountCaptureGroups<
|
|
58
|
+
S extends string,
|
|
59
|
+
Counter extends unknown[] = []
|
|
60
|
+
> =
|
|
61
|
+
S extends `${infer _Before}(${infer Rest}`
|
|
62
|
+
? _Before extends "\\"
|
|
63
|
+
? never
|
|
64
|
+
: Rest extends `?:${infer After}`
|
|
65
|
+
| `?=${infer After}`
|
|
66
|
+
| `?!${infer After}`
|
|
67
|
+
| `?<=${infer After}`
|
|
68
|
+
| `?<!${infer After}`
|
|
52
69
|
? CountCaptureGroups<After, Counter>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
| `?<=${infer After}`
|
|
56
|
-
| `?<!${infer After}`
|
|
57
|
-
? CountCaptureGroups<After, Counter>
|
|
58
|
-
: CountCaptureGroups<Rest, [...Counter, unknown]>
|
|
59
|
-
: Counter['length'];
|
|
70
|
+
: CountCaptureGroups<Rest, [...Counter, unknown]>
|
|
71
|
+
: Counter['length'];
|
|
60
72
|
/**
|
|
61
73
|
* Represents a fixed version of RegExpExecArray that includes the matched string,
|
|
62
74
|
* captures, and optionally named groups.
|
|
@@ -67,7 +79,9 @@ export type CountCaptureGroups<S extends string, Counter extends unknown[] = []>
|
|
|
67
79
|
export type RegExpExecArrayFixed<
|
|
68
80
|
R extends RegExp,
|
|
69
81
|
S extends ReSource<R> = ReSource<R>,
|
|
70
|
-
GroupCount extends number = CountCaptureGroups<
|
|
82
|
+
GroupCount extends number = CountCaptureGroups<
|
|
83
|
+
PreprocessEscapes<S>
|
|
84
|
+
>
|
|
71
85
|
> = [match: string, ...ExtractCaptures<GroupCount>] & {
|
|
72
86
|
groups?: ReGroups<R>;
|
|
73
87
|
};
|
|
@@ -79,9 +93,32 @@ export type RegExpExecArrayFixed<
|
|
|
79
93
|
export type ExtractCaptures<Count extends number, Result extends unknown[] = []> =
|
|
80
94
|
Result['length'] extends Count
|
|
81
95
|
? Result : ExtractCaptures<Count, [...Result, string]>;
|
|
82
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Creates the parameter types for String.replace callback function.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* type Params = ReplaceCallbackParams<typeof myRegex>;
|
|
101
|
+
* // [match: string, ...captures: string[], offset: number, string: string, groups?: {...}]
|
|
102
|
+
*/
|
|
103
|
+
export type ReplaceCallbackParams<
|
|
104
|
+
R extends RegExp,
|
|
105
|
+
S extends ReSource<R> = ReSource<R>,
|
|
106
|
+
GroupCount extends number = CountCaptureGroups<
|
|
107
|
+
PreprocessEscapes<S>
|
|
108
|
+
>
|
|
109
|
+
> = [
|
|
110
|
+
match: string,
|
|
111
|
+
...captures: ExtractCaptures<GroupCount>,
|
|
112
|
+
offset: number,
|
|
113
|
+
input: string,
|
|
114
|
+
groups: ReGroups<R>
|
|
115
|
+
];
|
|
116
|
+
export type ReplacerFunctionSignature<R extends RegExp> = (...args: ReplaceCallbackParams<R>) => string;
|
|
117
|
+
const re1 = createRegExp("(test)(group)()()()()()()()(22)", "g");
|
|
118
|
+
type TRe1Replacer = ReplacerFunctionSignature<typeof re1>;
|
|
83
119
|
type ExecResult1 = RegExpExecArrayFixed<typeof re1>;
|
|
84
120
|
const re2 = createRegExp("(?<name1>test)(?<name2>group)", "g");
|
|
121
|
+
type TRe2Replacer = ReplacerFunctionSignature<typeof re2>;
|
|
85
122
|
type ExecResult2 = RegExpExecArrayFixed<typeof re2>;
|
|
86
123
|
const result = re2.exec("test group") as RegExpExecArrayFixed<typeof re2>;
|
|
87
124
|
if (result) {
|
package/tool-lib/cjbm.js
CHANGED
|
@@ -13,30 +13,33 @@
|
|
|
13
13
|
*/
|
|
14
14
|
const fs = require("fs");
|
|
15
15
|
const path = require("path");
|
|
16
|
-
/**
|
|
17
|
-
* @import * as Regex from "../regex.d.ts";
|
|
18
|
-
*/
|
|
19
16
|
const RE_TEXT = String.raw`
|
|
20
|
-
# NOTE:
|
|
21
|
-
(
|
|
17
|
+
# NOTE: PCRE での検証時は line comment assertion を (?<!\/\/|\/\/\s)(?:(?<!@)import|export) とすること (regex101.com)
|
|
18
|
+
# 正しくは: (?<!\s*\/\/+.*?)(?:(?<!@)import|export)
|
|
19
|
+
(?<!\s*\/\/+.*?)(?:(?<!@)import|export)
|
|
22
20
|
\s*
|
|
23
21
|
(?:
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
)
|
|
22
|
+
# 2025/12/22 14:57:44 - support quote character detection ["']
|
|
23
|
+
# global import, import "./"; import './global.mjs';
|
|
24
|
+
(?<qcGlobal>["'])(?!https?:)(?=[.\/]+)(?:
|
|
25
|
+
(?<globalName>(?:[.\/]+)?[^'"]+?)(?:\.(?<globalExt>(?:c|m)?jsx?))?
|
|
26
|
+
)\k<qcGlobal>|
|
|
27
|
+
# dynamic import, import("...") import('...')
|
|
27
28
|
\(\s*
|
|
28
|
-
"(?!https?:)(?=[.\/]+)(?<dynamicName>(?:[.\/]+)?[^"]+?)(?:\.(?<dynamicExt>(?:c|m)?jsx?))
|
|
29
|
+
(?<qcDynamic>["'])(?!https?:)(?=[.\/]+)(?<dynamicName>(?:[.\/]+)?[^'"]+?)(?:\.(?<dynamicExt>(?:c|m)?jsx?))?\k<qcDynamic>
|
|
29
30
|
\s*\)|
|
|
30
|
-
|
|
31
|
-
(?:
|
|
32
|
-
(?<
|
|
33
|
-
|
|
31
|
+
# esm import/export
|
|
32
|
+
(?:(?<clause>.+?|(?:\w+\s*,)?\s*\{[^}]+\})\s*from)\s*
|
|
33
|
+
(?<qcEsm>["'])(?!https?:)(?=[.\/]+)
|
|
34
|
+
(?:
|
|
35
|
+
(?<moduleName>(?:[.\/]+)?[^'"]+?)(?:\.(?<moduleExt>(?:c|m)?jsx?))?
|
|
36
|
+
)\k<qcEsm>
|
|
34
37
|
)
|
|
35
38
|
(?=\s*;)?
|
|
36
39
|
`;
|
|
37
40
|
/**
|
|
38
|
-
* @date 2025/
|
|
39
|
-
* @see https://regex101.com/r/uMMsD4/
|
|
41
|
+
* @date 2025/12/22 16:09:36
|
|
42
|
+
* @see https://regex101.com/r/uMMsD4/31
|
|
40
43
|
*/
|
|
41
44
|
const reImportExportDetection = new RegExp(
|
|
42
45
|
RE_TEXT.replace(/\s*\(\?\#.*\)\s*$|(?<!\\)\#\s*.*$|\s+/gm, ""), "g",
|
|
@@ -47,6 +50,7 @@ const reImportExportDetection = new RegExp(
|
|
|
47
50
|
* @param {string} ext - The new file extension to use.
|
|
48
51
|
* @returns {TRegexImportExportDetectorReplacer} A function to update import/export statements with the specified file extension.
|
|
49
52
|
* @date 2025/2/16 18:38:39
|
|
53
|
+
* @date 2025/12/22 16:05:13 - ./tool-lib/cjbm-resources/cjbm-browser-test.mjs を参照
|
|
50
54
|
*/
|
|
51
55
|
function getReplacer(ext) {
|
|
52
56
|
/**
|
|
@@ -55,16 +59,25 @@ function getReplacer(ext) {
|
|
|
55
59
|
*/
|
|
56
60
|
/** @type {TRegexImportExportDetectorReplacer} */
|
|
57
61
|
const replacer = (
|
|
58
|
-
$0, _1, _2, _3, _4, _5, _6, _7,
|
|
62
|
+
$0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _offset, _input, { clause, dynamicName, globalName, moduleName, qcDynamic, qcEsm, qcGlobal }
|
|
59
63
|
) => {
|
|
60
|
-
const
|
|
64
|
+
const kword = $0.startsWith("import") ? "import" : "export";
|
|
65
|
+
const qc = qcDynamic || qcEsm || qcGlobal;
|
|
61
66
|
let whichName = /** @type {string} */ (
|
|
62
67
|
globalName || moduleName || dynamicName
|
|
63
68
|
);
|
|
64
69
|
if (whichName[whichName.length - 1] === "/") {
|
|
65
70
|
whichName += "index";
|
|
66
71
|
}
|
|
67
|
-
|
|
72
|
+
const modId = `${qc}${whichName}.${ext}${qc}`;
|
|
73
|
+
return `${kword}${
|
|
74
|
+
|
|
75
|
+
globalName ? ` ${modId}` :
|
|
76
|
+
|
|
77
|
+
clause? ` ${clause} from ${modId}` :
|
|
78
|
+
|
|
79
|
+
`(${modId})`
|
|
80
|
+
}`;
|
|
68
81
|
};
|
|
69
82
|
return replacer;
|
|
70
83
|
}
|
package/tool-lib/tools.d.ts
CHANGED
|
@@ -6,21 +6,16 @@
|
|
|
6
6
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
8
|
/// <reference path="../regex.d.ts"/>
|
|
9
|
-
declare const ImportExportDetectRegex = `(
|
|
10
|
-
(?:(?<globalName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?)"
|
|
11
|
-
|
|
12
|
-
(?:(?<
|
|
13
|
-
(?:\\.(?<moduleExt>(?:c|m)?jsx?))?)")(?=\\s*;)?`;
|
|
9
|
+
declare const ImportExportDetectRegex = `(?<!\\s*\\/\\/+.*?)(?:(?<!@)import|export)\\s*(?:(?<qcGlobal>["'])(?!https?:)(?=[.\\/]+)\
|
|
10
|
+
(?:(?<globalName>(?:[.\\/]+)?[^'"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?)\\k<qcGlobal>|\\(\\s*(?<qcDynamic>["'])(?!https?:)(?=[.\\/]+)(?<dynamicName>(?:[.\\/]+)?[^'"]+?)\
|
|
11
|
+
(?:\\.(?<dynamicExt>(?:c|m)?jsx?))?\\k<qcDynamic>\\s*\\)|(?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+\\})\\s*from)\\s*(?<qcEsm>["'])(?!https?:)(?=[.\\/]+)\
|
|
12
|
+
(?:(?<moduleName>(?:[.\\/]+)?[^'"]+?)(?:\\.(?<moduleExt>(?:c|m)?jsx?))?)\\k<qcEsm>)(?=\\s*;)?`;
|
|
14
13
|
declare const reOk: ReturnType<typeof XRegex.createRegExp<typeof ImportExportDetectRegex>>;
|
|
15
|
-
type TRegexDetectRet = XRegex.ReGroups<typeof reOk>;
|
|
16
14
|
/**
|
|
17
15
|
* @date 2023-10-25
|
|
18
16
|
*/
|
|
19
17
|
declare global {
|
|
20
|
-
type TRegexImportExportDetectorReplacer =
|
|
21
|
-
string, string, string, string, string, string, string, string, number, string,
|
|
22
|
-
TRegexDetectRet
|
|
23
|
-
): string;
|
|
18
|
+
type TRegexImportExportDetectorReplacer = XRegex.ReplacerFunctionSignature<typeof reOk>;
|
|
24
19
|
declare function processSources(
|
|
25
20
|
taskName: string,
|
|
26
21
|
process: (source: string) => Promise<string> | string,
|