js-dev-tool 1.0.1 → 1.0.3
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/basic-types.d.ts +36 -107
- package/common/index.d.ts +1 -1
- package/common/index.js +1 -41
- package/extras/tiny-progress.d.ts +1 -1
- package/extras/tiny-progress.js +1 -11
- package/index.d.ts +1 -6
- package/index.js +1 -1
- package/lib/unzip.min.js +1 -3
- package/lib/zip.min.js +1 -2
- package/lib/zlibjs.d.ts +1 -1
- package/package.json +2 -2
- package/progress/index.d.ts +1 -3
- package/progress/index.js +2 -38
- package/progress/progress-extras.d.ts +1 -1
- package/progress/progress-extras.js +1 -12
- package/progress/rnd-spinner.js +2 -6
- package/progress/spinners.d.ts +1 -3
- package/progress/test.js +1 -18
- package/regex.d.ts +3 -66
- package/scripts/publish-version.json +1 -1
- package/scripts/unzip.js +1 -2
- package/scripts/zip.js +6 -58
- package/tool-lib/cjbm.js +1 -117
- package/tool-lib/cmt-trick.js +1 -44
- package/tool-lib/ps.js +65 -72
- package/tool-lib/rws.js +13 -19
- package/tool-lib/tools.d.ts +3 -94
- package/tool-lib/zip-task.js +1 -2
- package/tools.d.ts +6 -6
- package/tools.js +8 -120
- package/tsconfig.json +1 -1
- package/utils.d.ts +23 -55
- package/utils.js +12 -245
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/// <reference path="./index.d.ts"/>
|
|
9
9
|
const lib = require("../common");
|
|
10
|
-
|
|
11
10
|
const checkENV = () => {
|
|
12
11
|
const env = process.env;
|
|
13
12
|
if (env.CI) return "ci";
|
|
@@ -19,18 +18,13 @@ const checkENV = () => {
|
|
|
19
18
|
/** @type {TWebpackProgressHandler} */
|
|
20
19
|
const wppHandlerV4 = ((renderer, cwd) => {
|
|
21
20
|
return (percentage, message, ...args) => {
|
|
22
|
-
// DEVNOTE: 2022/02/16 these values are webpack v4 (maybe
|
|
23
21
|
let [modules, actives, path = ""] = args;
|
|
24
|
-
// let [modules, actives, path = ""] = args;
|
|
25
22
|
if (message) {
|
|
26
23
|
const x = path.lastIndexOf(cwd) + 1;
|
|
27
24
|
x > 0 && (path = path.substring(x + cwd.length));
|
|
28
25
|
} else {
|
|
29
|
-
// which means all processing done
|
|
30
26
|
message = "- done -";
|
|
31
27
|
}
|
|
32
|
-
// TODO: 2022/2/16 webpack version 5 is different parameters
|
|
33
|
-
// so rewrite it.
|
|
34
28
|
renderer(
|
|
35
29
|
`processing ${(percentage * 100).toFixed(4)}% | ` +
|
|
36
30
|
message +
|
|
@@ -39,14 +33,12 @@ const wppHandlerV4 = ((renderer, cwd) => {
|
|
|
39
33
|
percentage === 1 && console.log();
|
|
40
34
|
};
|
|
41
35
|
})(lib.renderLine, process.cwd());
|
|
42
|
-
|
|
43
36
|
/** @type {TWebpackProgressHandler} */
|
|
44
37
|
const wppHandlerV5 = ((renderer, cwd) => {
|
|
45
38
|
return (percentage, message, ...args) => {
|
|
46
39
|
if (!message) {
|
|
47
40
|
message = "- done -";
|
|
48
41
|
}
|
|
49
|
-
// plugin name or source path
|
|
50
42
|
let str = args[1];
|
|
51
43
|
if (str) {
|
|
52
44
|
const x = str.lastIndexOf(cwd) + 1;
|
|
@@ -58,11 +50,9 @@ const wppHandlerV5 = ((renderer, cwd) => {
|
|
|
58
50
|
renderer(
|
|
59
51
|
`pct: ${(percentage * 100).toFixed(4)}%, process: [${message}]${str ? `, info: [${str}]` : ""}${args.length ? " - " : ""}${args.join(", ")}`,
|
|
60
52
|
);
|
|
61
|
-
// console.log(`pct: ${(percentage*100).toFixed(4)}%, process: [${message}]${ str? `, info: [${str}]`: "" }${ args.length? " -": "" }`, args.join(", "));
|
|
62
53
|
percentage === 1 && console.log();
|
|
63
54
|
};
|
|
64
55
|
})(lib.renderLine, process.cwd());
|
|
65
|
-
|
|
66
56
|
/** @type {boolean} */
|
|
67
57
|
let checkedCache;
|
|
68
58
|
/**
|
|
@@ -81,10 +71,9 @@ const isWebpackV5later = () => {
|
|
|
81
71
|
}
|
|
82
72
|
return checkedCache;
|
|
83
73
|
};
|
|
84
|
-
|
|
85
74
|
module.exports = {
|
|
86
75
|
checkENV,
|
|
87
76
|
wppHandlerV4,
|
|
88
77
|
wppHandlerV5,
|
|
89
78
|
isWebpackV5later,
|
|
90
|
-
};
|
|
79
|
+
};
|
package/progress/rnd-spinner.js
CHANGED
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
const randomIndex = (array) => {
|
|
18
18
|
return Math.floor(Math.random() * array.length);
|
|
19
19
|
};
|
|
20
|
-
|
|
21
20
|
/**
|
|
22
21
|
* @typedef {import("./spinners")} TSpinners
|
|
23
22
|
* @typedef {keyof TSpinners} TSpinnersName
|
|
@@ -31,25 +30,22 @@ const spinners = require("./spinners.json");
|
|
|
31
30
|
*/
|
|
32
31
|
// @ts-ignore
|
|
33
32
|
const frameNames = Object.keys(spinners);
|
|
34
|
-
|
|
35
33
|
const MAX_PAD = frameNames.reduce((acc, sn) => {
|
|
36
34
|
return Math.max(acc, sn.length);
|
|
37
35
|
}, 0);
|
|
38
36
|
const MIN_PAD = frameNames.reduce((acc, sn) => {
|
|
39
37
|
return Math.max(acc, sn.length);
|
|
40
38
|
}, MAX_PAD);
|
|
41
|
-
|
|
42
39
|
const getRandomFrame = () => {
|
|
43
40
|
/** @type {TSpinnersName} */
|
|
44
|
-
const name = frameNames[randomIndex(frameNames)];
|
|
41
|
+
const name = frameNames[randomIndex(frameNames)];
|
|
45
42
|
return {
|
|
46
43
|
name,
|
|
47
44
|
frames: spinners[name].frames,
|
|
48
45
|
};
|
|
49
46
|
};
|
|
50
|
-
|
|
51
47
|
module.exports = {
|
|
52
48
|
getRandomFrame,
|
|
53
49
|
MAX_PAD,
|
|
54
50
|
MIN_PAD,
|
|
55
|
-
};
|
|
51
|
+
};
|
package/progress/spinners.d.ts
CHANGED
package/progress/test.js
CHANGED
|
@@ -15,13 +15,10 @@ p = t.init();
|
|
|
15
15
|
p.run();
|
|
16
16
|
p.stop();
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
18
|
const p = require("./index.js");
|
|
20
19
|
const rndspinner = require("./rnd-spinner.js");
|
|
21
|
-
|
|
22
20
|
let fired = 0;
|
|
23
21
|
let pending = 0;
|
|
24
|
-
|
|
25
22
|
/** @type {() => { fired: number; pending: number; errors?: number; }} */
|
|
26
23
|
const cb = () => {
|
|
27
24
|
return {
|
|
@@ -29,9 +26,7 @@ const cb = () => {
|
|
|
29
26
|
pending: ++pending,
|
|
30
27
|
};
|
|
31
28
|
};
|
|
32
|
-
|
|
33
29
|
let tag = "progress test";
|
|
34
|
-
|
|
35
30
|
/**
|
|
36
31
|
* progress callback
|
|
37
32
|
* @type {() => string}
|
|
@@ -41,11 +36,9 @@ const pcb = () => {
|
|
|
41
36
|
const { fired, pending, errors } = cb();
|
|
42
37
|
return `${tag} | error: ${(errors + "").padEnd(3)} | send: ${(fired + "").padStart(3)}, pending: ${(pending + "").padEnd(5)}`;
|
|
43
38
|
} else {
|
|
44
|
-
// error
|
|
45
39
|
return "- - error - -";
|
|
46
40
|
}
|
|
47
41
|
};
|
|
48
|
-
|
|
49
42
|
/** @type {ReturnType<typeof p.createProgressObject>} */
|
|
50
43
|
let progress;
|
|
51
44
|
/**
|
|
@@ -74,21 +67,11 @@ const init = (fps = 30) => {
|
|
|
74
67
|
/**
|
|
75
68
|
* @typedef {ReturnType<typeof createRandomlyOptions>} TcreateRandomlyOptionsReturn
|
|
76
69
|
*/
|
|
77
|
-
// /** @type {string[]} */
|
|
78
|
-
// let frames;
|
|
79
|
-
// /** @type {TcreateRandomlyOptionsReturn["formatOpt"]} */
|
|
80
|
-
// let formatOpt;
|
|
81
|
-
// // TIP: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring
|
|
82
|
-
// (
|
|
83
|
-
// { frames, formatOpt } = createRandomlyOptions()
|
|
84
|
-
// );
|
|
85
70
|
const { frames, formatOpt } = createRandomlyOptions();
|
|
86
71
|
progress = p.createProgressObject(frames, formatOpt, pcb);
|
|
87
72
|
progress.setFPS(fps);
|
|
88
|
-
|
|
89
73
|
return progress;
|
|
90
74
|
};
|
|
91
|
-
|
|
92
75
|
module.exports = {
|
|
93
76
|
init,
|
|
94
|
-
};
|
|
77
|
+
};
|
package/regex.d.ts
CHANGED
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* @file js-dev-scripts/regex.d.ts
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
13
|
-
// Basics
|
|
14
|
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
15
11
|
/**
|
|
16
12
|
* Extracts the literal type from the source property of a RegExp.
|
|
17
13
|
* @template R - A RegExp type.
|
|
@@ -20,16 +16,7 @@ export type ReSource<R extends RegExp> = R extends RegExp & { readonly source: i
|
|
|
20
16
|
export declare function createRegExp<P extends string>(pattern: P, flags?: string): RegExp & {
|
|
21
17
|
readonly source: P;
|
|
22
18
|
};
|
|
23
|
-
|
|
24
|
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
25
|
-
// Named Capture Groups
|
|
26
|
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
27
19
|
type FirstChar<S extends string> = S extends `${infer F}${infer _}` ? F : never;
|
|
28
|
-
// Modified ExtractGroupNames:
|
|
29
|
-
// First, extract the part of S after "(?<" into Rest
|
|
30
|
-
// If the first character of Rest is "=" or "!", it is judged to be Lookbehind and recurses without treating it as a capture
|
|
31
|
-
// Otherwise, split Rest into the group name (GroupName) and the ">" separator and extract it,
|
|
32
|
-
// Apply the same process to the remaining After part
|
|
33
20
|
/**
|
|
34
21
|
* Recursively extracts parts that match the format (?<GroupName>...) from a string pattern,
|
|
35
22
|
* without considering nesting, and unions them.
|
|
@@ -51,11 +38,6 @@ export type ExtractGroupNames<S extends string> =
|
|
|
51
38
|
export type ReGroups<R extends RegExp> = {
|
|
52
39
|
[K in ExtractGroupNames<ReSource<R>>]?: string;
|
|
53
40
|
};
|
|
54
|
-
|
|
55
|
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
56
|
-
// Capture Groups
|
|
57
|
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
58
|
-
// CountCaptureGroups type: Get the exact number of capture groups
|
|
59
41
|
/**
|
|
60
42
|
* Counts the exact number of capture groups in a string pattern.
|
|
61
43
|
* @template S - A string pattern.
|
|
@@ -65,25 +47,16 @@ export type ReGroups<R extends RegExp> = {
|
|
|
65
47
|
* @deprecated text base の parse には限界があり cost が見合わないので、この type は将来削除予定!
|
|
66
48
|
*/
|
|
67
49
|
export type CountCaptureGroups<S extends string, Counter extends unknown[] = []> =
|
|
68
|
-
// // まず、エスケープされた左括弧 \(
|
|
69
|
-
// S extends `${infer _Before}\\(${infer Rest}`
|
|
70
|
-
// ? CountCaptureGroups<Rest, Counter> :
|
|
71
|
-
// 次に、通常の左括弧 ( を検出
|
|
72
50
|
S extends `${infer _Before}(${infer Rest}`
|
|
73
|
-
// 非キャプチャグループ (?:...) をスキップ
|
|
74
51
|
? Rest extends `?:${infer After}`
|
|
75
52
|
? CountCaptureGroups<After, Counter>
|
|
76
|
-
// Lookahead/Lookbehind (?=...), (?!...), (?<=...), (?<!...) をスキップ
|
|
77
53
|
: Rest extends `?=${infer After}`
|
|
78
54
|
| `?!${infer After}`
|
|
79
55
|
| `?<=${infer After}`
|
|
80
56
|
| `?<!${infer After}`
|
|
81
57
|
? CountCaptureGroups<After, Counter>
|
|
82
|
-
// それ以外は通常のキャプチャグループとしてカウント
|
|
83
58
|
: CountCaptureGroups<Rest, [...Counter, unknown]>
|
|
84
59
|
: Counter['length'];
|
|
85
|
-
|
|
86
|
-
// Fixed RegExpExecArray type
|
|
87
60
|
/**
|
|
88
61
|
* Represents a fixed version of RegExpExecArray that includes the matched string,
|
|
89
62
|
* captures, and optionally named groups.
|
|
@@ -98,8 +71,6 @@ export type RegExpExecArrayFixed<
|
|
|
98
71
|
> = [match: string, ...ExtractCaptures<GroupCount>] & {
|
|
99
72
|
groups?: ReGroups<R>;
|
|
100
73
|
};
|
|
101
|
-
|
|
102
|
-
// Helper type: Generates an array according to the number of capture groups
|
|
103
74
|
/**
|
|
104
75
|
* Generates an array type with a length corresponding to the number of capture groups.
|
|
105
76
|
* @template Count - The number of capture groups.
|
|
@@ -108,47 +79,13 @@ export type RegExpExecArrayFixed<
|
|
|
108
79
|
export type ExtractCaptures<Count extends number, Result extends unknown[] = []> =
|
|
109
80
|
Result['length'] extends Count
|
|
110
81
|
? Result : ExtractCaptures<Count, [...Result, string]>;
|
|
111
|
-
|
|
112
|
-
/* ctt
|
|
113
|
-
type Dummy = ExtractCaptures<4>;
|
|
114
|
-
// [string, string, string, string]
|
|
115
|
-
/*/
|
|
116
|
-
//*/
|
|
117
|
-
|
|
118
|
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
119
|
-
// The Examples
|
|
120
|
-
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
121
|
-
// Example 1: Anonymous capture groups
|
|
122
82
|
const re1 = createRegExp("(test)(group)", "g");
|
|
123
83
|
type ExecResult1 = RegExpExecArrayFixed<typeof re1>;
|
|
124
|
-
// ExecResult1 is [string, string, string] & { groups?: Record<string, string | undefined> };
|
|
125
|
-
|
|
126
|
-
// Example 2: Named capture groups
|
|
127
84
|
const re2 = createRegExp("(?<name1>test)(?<name2>group)", "g");
|
|
128
85
|
type ExecResult2 = RegExpExecArrayFixed<typeof re2>;
|
|
129
|
-
// ExecResult2 is [string, string, string] & { groups?: { name1: string; name2: string } };
|
|
130
|
-
|
|
131
|
-
// Verify that the exec result matches the type
|
|
132
86
|
const result = re2.exec("test group") as RegExpExecArrayFixed<typeof re2>;
|
|
133
87
|
if (result) {
|
|
134
|
-
console.log(result[1]);
|
|
135
|
-
console.log(result.groups?.name1);
|
|
88
|
+
console.log(result[1]);
|
|
89
|
+
console.log(result.groups?.name1);
|
|
136
90
|
}
|
|
137
|
-
|
|
138
|
-
export as namespace XRegex;
|
|
139
|
-
/* ctt sample code
|
|
140
|
-
// 補助関数 createRegExp を使って型レベルの情報を保持する RegExp を生成
|
|
141
|
-
function createRegExp<P extends string>(
|
|
142
|
-
pattern: P,
|
|
143
|
-
flags?: string
|
|
144
|
-
): RegExp & { readonly source: P } {
|
|
145
|
-
return new RegExp(pattern, flags) as RegExp & { readonly source: P };
|
|
146
|
-
}
|
|
147
|
-
const re = createRegExp("(?<token>test)", "ig");
|
|
148
|
-
// type a は "token" というグループ名から導出された型になりますが、
|
|
149
|
-
// groups オブジェクトとしては { token: string } になる
|
|
150
|
-
type Groups = ReGroups<typeof re>; // → { token: string }
|
|
151
|
-
const m = re.exec("this is test")!;
|
|
152
|
-
console.log(m, m.groups);
|
|
153
|
-
/*/
|
|
154
|
-
//*/
|
|
91
|
+
export as namespace XRegex;
|
package/scripts/unzip.js
CHANGED
|
@@ -12,7 +12,6 @@ const decompress = (fileName) => {
|
|
|
12
12
|
} else {
|
|
13
13
|
console.time(fileName);
|
|
14
14
|
unzip(data, (err, unzipped) => {
|
|
15
|
-
// [2022/5/10 3:05:43] webpack.zip: 159.833ms
|
|
16
15
|
console.timeEnd(fileName);
|
|
17
16
|
if (err) {
|
|
18
17
|
console.error(err);
|
|
@@ -27,4 +26,4 @@ const decompress = (fileName) => {
|
|
|
27
26
|
}
|
|
28
27
|
});
|
|
29
28
|
};
|
|
30
|
-
module.exports = decompress;
|
|
29
|
+
module.exports = decompress;
|
package/scripts/zip.js
CHANGED
|
@@ -2,38 +2,14 @@ const fs = require("fs");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fflate = require("fflate");
|
|
4
4
|
const { TextEncoder } = require("util");
|
|
5
|
-
// const b = require("node:buffer");
|
|
6
|
-
|
|
7
|
-
// fflate's ZIP API is asynchronous and parallelized (multithreaded)
|
|
8
5
|
const ALREADY_COMPRESSED = [
|
|
9
|
-
"
|
|
10
|
-
"gz",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"pdf",
|
|
15
|
-
"doc",
|
|
16
|
-
"docx",
|
|
17
|
-
"ppt",
|
|
18
|
-
"pptx",
|
|
19
|
-
"xls",
|
|
20
|
-
"xlsx",
|
|
21
|
-
"heic",
|
|
22
|
-
"heif",
|
|
23
|
-
"7z",
|
|
24
|
-
"bz2",
|
|
25
|
-
"rar",
|
|
26
|
-
"gif",
|
|
27
|
-
"webp",
|
|
28
|
-
"webm",
|
|
29
|
-
"mp4",
|
|
30
|
-
"mov",
|
|
31
|
-
"mp3",
|
|
32
|
-
"aifc",
|
|
6
|
+
"7z", "aifc", "bz2", "doc", "docx",
|
|
7
|
+
"gif", "gz", "heic", "heif", "jpeg",
|
|
8
|
+
"jpg", "mov", "mp3", "mp4", "pdf",
|
|
9
|
+
"png", "ppt", "pptx", "rar", "webm",
|
|
10
|
+
"webp", "xls", "xlsx", "zip"
|
|
33
11
|
];
|
|
34
|
-
|
|
35
12
|
/**
|
|
36
|
-
*
|
|
37
13
|
* @param {string} fileName
|
|
38
14
|
* @param {(out: Uint8Array | NodeJS.ErrnoException) => void} cb
|
|
39
15
|
*/
|
|
@@ -46,8 +22,6 @@ const fileToU8 = (fileName, cb /* : (out: Uint8Array) => void */) => {
|
|
|
46
22
|
}
|
|
47
23
|
});
|
|
48
24
|
};
|
|
49
|
-
|
|
50
|
-
// Yet again, this is necessary for parallelization.
|
|
51
25
|
/**
|
|
52
26
|
* @param {path.ParsedPath} parsedPath
|
|
53
27
|
* @param {(out: Uint8Array | null) => void} callback
|
|
@@ -61,22 +35,15 @@ const processFile = function (parsedPath, callback, comment) {
|
|
|
61
35
|
const zipObj = {
|
|
62
36
|
[parsedPath.base]: [
|
|
63
37
|
data, {
|
|
64
|
-
// With fflate, we can choose which files we want to compress
|
|
65
38
|
level: ALREADY_COMPRESSED.indexOf(parsedPath.ext) === -1 ? 6 : 0,
|
|
66
39
|
comment,
|
|
67
40
|
},
|
|
68
41
|
],
|
|
69
42
|
};
|
|
70
|
-
|
|
71
|
-
// If we didn't want to specify options:
|
|
72
|
-
// zipObj[fileName] = buf;
|
|
73
43
|
console.time(filePath);
|
|
74
44
|
fflate.zip(
|
|
75
45
|
zipObj,
|
|
76
46
|
{
|
|
77
|
-
// If you want to control options for every file, you can do so here
|
|
78
|
-
// They are merged with the per-file options (if they exist)
|
|
79
|
-
// mem: 9
|
|
80
47
|
},
|
|
81
48
|
function (err, out) {
|
|
82
49
|
if (err) {
|
|
@@ -84,10 +51,7 @@ const processFile = function (parsedPath, callback, comment) {
|
|
|
84
51
|
callback(null);
|
|
85
52
|
console.timeEnd(filePath);
|
|
86
53
|
} else {
|
|
87
|
-
// [2022/5/10 3:06:16] webpack.js: 399.832ms
|
|
88
54
|
console.timeEnd(filePath);
|
|
89
|
-
// You may want to try downloading to see that fflate actually works:
|
|
90
|
-
// download(out, 'fflate-demo.zip');
|
|
91
55
|
callback(out);
|
|
92
56
|
}
|
|
93
57
|
},
|
|
@@ -97,7 +61,6 @@ const processFile = function (parsedPath, callback, comment) {
|
|
|
97
61
|
}
|
|
98
62
|
});
|
|
99
63
|
};
|
|
100
|
-
|
|
101
64
|
/**
|
|
102
65
|
* @param {string} inputPath
|
|
103
66
|
* @param {string} [comment]
|
|
@@ -120,19 +83,4 @@ module.exports = function zip(inputPath, comment, dest) {
|
|
|
120
83
|
},
|
|
121
84
|
comment,
|
|
122
85
|
);
|
|
123
|
-
};
|
|
124
|
-
/*
|
|
125
|
-
node -i
|
|
126
|
-
const zip = require("js-dev-scripts/scripts/zip");
|
|
127
|
-
const comment = "sha384-XSSUboqeWltJhmqrtg5XP9Svrg5NFArrGX0Nm4+c6NUtaRXOiidVCaWFbSQXdVFC";
|
|
128
|
-
zip("./lib/webpack.js", comment);
|
|
129
|
-
const comment2 = "sha384-Y7FclS+/O1tb8AfLynrvaZRzlgEfzNlqOB2iX/tQ/BQBu6lK3MsxBlDDeqtFd+2X";
|
|
130
|
-
zip("./lib/typeid-map.js", comment2);
|
|
131
|
-
|
|
132
|
-
[2022/5/11 10:07:34]
|
|
133
|
-
b64=$(echo -n "sha384-XSSUboqeWltJhmqrtg5XP9Svrg5NFArrGX0Nm4+c6NUtaRXOiidVCaWFbSQXdVFC" | base64)
|
|
134
|
-
echo "$b64"
|
|
135
|
-
echo -n "$b64" | base64 -d # OK
|
|
136
|
-
|
|
137
|
-
echo -n "XSSUboqeWltJhmqrtg5XP9Svrg5NFArrGX0Nm4+c6NUtaRXOiidVCaWFbSQXdVFC" | base64 -d # binary data
|
|
138
|
-
*/
|
|
86
|
+
};
|
package/tool-lib/cjbm.js
CHANGED
|
@@ -11,49 +11,9 @@
|
|
|
11
11
|
/**
|
|
12
12
|
* @file (C)onvert (J)S to (B)rowser (M)odule
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
14
|
/**
|
|
16
15
|
* @import * as Regex from "../regex.d.ts";
|
|
17
16
|
*/
|
|
18
|
-
|
|
19
|
-
// [2023-10-30] from https://regex101.com/r/EpuQLT/37
|
|
20
|
-
// CAUTION: PCRE style では、js では使える assertion が使えない場合があるので、適宜書き換えないといけない.
|
|
21
|
-
// 詳細は、 https://regex101.com/r/EpuQLT/38 の regex string と以下を見比べて確認
|
|
22
|
-
// const RE_TEXT = `(?<!\\/\\/\\s*)(?:import|export) # comments
|
|
23
|
-
// \\s*
|
|
24
|
-
// (?:
|
|
25
|
-
// "(?=[.\\/]+)| # character ["] \\x22 e.g - import "../global/index"
|
|
26
|
-
// (?:
|
|
27
|
-
// [\\w_]+\\s+| # default import, e.g - import fs from "./file";
|
|
28
|
-
// (?:[\\w_]+\\s*,\\s*)?\\{[^}]+\\}\\s*| # e.g - import View, { TitiledSphereMesh } from "./view";
|
|
29
|
-
// \\*\\s*as\\s+[\\w_]+\\s+| # e.g - export * as OO from "./rateLimiter";
|
|
30
|
-
// \\*\\s* # e.g - export * from "./rateLimiter";
|
|
31
|
-
// )from\\s*"(?:[.\\/]+) # Positive Lookahead (./|../|../../) ...
|
|
32
|
-
// )
|
|
33
|
-
// (?:[^"]*?)(?:\\.((?:c|m)?js))? # extenstion replaceable
|
|
34
|
-
// (?="\\s*;?)`;
|
|
35
|
-
|
|
36
|
-
/* TODO: 2025/2/15 19:39:29 - regex group name を抽出する utility type
|
|
37
|
-
(?<!\\/\\/|\\/\\/\\s)(?:import|export)
|
|
38
|
-
\\s*
|
|
39
|
-
(?:
|
|
40
|
-
"(?!https?:)(?:
|
|
41
|
-
(?<globalName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?
|
|
42
|
-
)"|
|
|
43
|
-
\\(\\s*
|
|
44
|
-
"(?<dynamicName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<dynamicExt>(?:c|m)?jsx?))?"
|
|
45
|
-
\\s*\\)|
|
|
46
|
-
(?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+\\})\\s*from)\\s*"(?!https?:)
|
|
47
|
-
(?:
|
|
48
|
-
(?<moduleName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<moduleExt>(?:c|m)?jsx?))?
|
|
49
|
-
)"
|
|
50
|
-
)
|
|
51
|
-
\\s*;?
|
|
52
|
-
*/
|
|
53
|
-
// /**
|
|
54
|
-
// * @date 2025/2/15 20:11:22
|
|
55
|
-
// * @see https://regex101.com/r/uMMsD4/22
|
|
56
|
-
// */
|
|
57
17
|
const RE_TEXT = String.raw`
|
|
58
18
|
# NOTE: PCRE での検証時は line comment assertion を (?<!\/\/|\/\/\s) とすること (regex101.com)
|
|
59
19
|
(?<!\/\/+\s*)(?:import|export)
|
|
@@ -72,62 +32,13 @@ const RE_TEXT = String.raw`
|
|
|
72
32
|
)
|
|
73
33
|
(?=\s*;)?
|
|
74
34
|
`;
|
|
75
|
-
// const RE_TEXT = `
|
|
76
|
-
// # NOTE: PCRE での検証時は line comment assertion を (?<!\\/\\/|\\/\\/\\s) とすること
|
|
77
|
-
// (?<!\\/\\/+\\s*)(?:import|export) # line comment でない import/export statement
|
|
78
|
-
// \\s*
|
|
79
|
-
// (?:
|
|
80
|
-
// "(?!https?:)(?=[.\\/]+)(?:
|
|
81
|
-
// (?<globalName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?
|
|
82
|
-
// )"|
|
|
83
|
-
// \\(\\s*
|
|
84
|
-
// "(?!https?:)(?=[.\\/]+)(?<dynamicName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<dynamicExt>(?:c|m)?jsx?))?"
|
|
85
|
-
// \\s*\\)|
|
|
86
|
-
// (?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+\\})\\s*from)\\s*"(?!https?:)(?=[.\\/]+)
|
|
87
|
-
// (?:
|
|
88
|
-
// (?<moduleName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<moduleExt>(?:c|m)?jsx?))?
|
|
89
|
-
// )"
|
|
90
|
-
// )
|
|
91
|
-
// (?=\\s*;)?
|
|
92
|
-
// `;
|
|
93
|
-
|
|
94
35
|
/**
|
|
95
36
|
* @date 2025/2/15 20:11:22
|
|
96
37
|
* @see https://regex101.com/r/uMMsD4/22
|
|
97
38
|
*/
|
|
98
|
-
/* ctt
|
|
99
|
-
const reImportExportDetection = createRegExp(
|
|
100
|
-
`(?<!\\/\\/+\\s*)(?:import|export)\\s*(?:"(?!https?:)(?=[.\\/]+)\
|
|
101
|
-
(?:(?<globalName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<globalExt>(?:c|m)?jsx?))?)"|\
|
|
102
|
-
\\(\\s*"(?!https?:)(?=[.\\/]+)(?<dynamicName>(?:[.\\/]+)?[^"]+?)(?:\\.(?<dynamicExt>(?:c|m)?jsx?))?"\\s*\\)|\
|
|
103
|
-
(?:(?<clause>.+?|(?:\\w+\\s*,)?\\s*\\{[^}]+\\})\\s*from)\\s*"(?!https?:)(?=[.\\/]+)(?:(?<moduleName>(?:[.\\/]+)?[^"]+?)\
|
|
104
|
-
(?:\\.(?<moduleExt>(?:c|m)?jsx?))?)")(?=\\s*;)?`, "g"
|
|
105
|
-
);
|
|
106
|
-
/*/
|
|
107
39
|
const reImportExportDetection = new RegExp(
|
|
108
40
|
RE_TEXT.replace(/\s*\(\?\#.*\)\s*$|(?<!\\)\#\s*.*$|\s+/gm, ""), "g",
|
|
109
41
|
);
|
|
110
|
-
//*/
|
|
111
|
-
|
|
112
|
-
// /**
|
|
113
|
-
// * @type {typeof XRegex["createRegExp"]}
|
|
114
|
-
// */
|
|
115
|
-
// function createRegExp(pattern, flags) {
|
|
116
|
-
// return /** @type {RegExp & { readonly source: typeof pattern }} */(new RegExp(pattern, flags));
|
|
117
|
-
// }
|
|
118
|
-
/* ctt 2025/3/18 13:46:03 OK, works
|
|
119
|
-
// @ts-expect-error
|
|
120
|
-
let gg = /** @type {XRegex.RegExpExecArrayFixed<typeof reImportExportDetection>} * /(reImportExportDetection.exec("test"));
|
|
121
|
-
gg.groups?.dynamicExt
|
|
122
|
-
/*/
|
|
123
|
-
//*/
|
|
124
|
-
// function createRegExp<P extends string>(
|
|
125
|
-
// pattern: P,
|
|
126
|
-
// flags?: string
|
|
127
|
-
// ): RegExp & { readonly source: P } {
|
|
128
|
-
// return new RegExp(pattern, flags) as RegExp & { readonly source: P };
|
|
129
|
-
// }
|
|
130
|
-
|
|
131
42
|
/**
|
|
132
43
|
* Generates a replacer function to update import/export statements with a new file extension.
|
|
133
44
|
*
|
|
@@ -140,20 +51,10 @@ function getReplacer(ext) {
|
|
|
140
51
|
* NOTE: Replacement is only performed with the syntax "$` is $1".
|
|
141
52
|
* String concatenation is not allowed.
|
|
142
53
|
*/
|
|
143
|
-
// before match: $` NOTE: "$` is $1" のような使い方でないと置換されない (string concatnation is not allowed)
|
|
144
|
-
// after match: $'
|
|
145
|
-
// TIP: debug on chrome, snippet: detect-import-export-regex.js
|
|
146
54
|
/** @type {TRegexImportExportDetectorReplacer} */
|
|
147
55
|
const replacer = (
|
|
148
56
|
$0, _1, _2, _3, _4, _5, _6, _7, _o, _s, { clause, dynamicName, globalName, moduleName }
|
|
149
|
-
// $0, $1, $2, $3, $4, $5, $6, $7, offset, source, groups
|
|
150
57
|
) => {
|
|
151
|
-
// const {
|
|
152
|
-
// clause, // dynamicExt,
|
|
153
|
-
// dynamicName,// globalExt,
|
|
154
|
-
// globalName, // moduleExt,
|
|
155
|
-
// moduleName,
|
|
156
|
-
// } = groups;
|
|
157
58
|
const kw = $0.startsWith("import") ? "import" : "export";
|
|
158
59
|
let whichName = /** @type {string} */ (
|
|
159
60
|
globalName || moduleName || dynamicName
|
|
@@ -165,7 +66,6 @@ function getReplacer(ext) {
|
|
|
165
66
|
};
|
|
166
67
|
return replacer;
|
|
167
68
|
}
|
|
168
|
-
|
|
169
69
|
/**
|
|
170
70
|
* @returns {TJSToolEntry}
|
|
171
71
|
*/
|
|
@@ -176,14 +76,6 @@ module.exports = () => {
|
|
|
176
76
|
* about regex: see [[tools.js] regex - (C)onvert (J)S to (B)rowser (M)odule](https://regex101.com/r/EpuQLT/37)
|
|
177
77
|
*/
|
|
178
78
|
fn() {
|
|
179
|
-
// DEVNOTE: 2020/5/27 12:11:11 - https://regex101.com/r/EpuQLT/21
|
|
180
|
-
// DEVNOTE: 2022/4/19 7:28:28 - https://regex101.com/r/EpuQLT/23
|
|
181
|
-
// DEVNOTE: 2023/10/30 - https://regex101.com/r/EpuQLT/24
|
|
182
|
-
// -> supports [import*as e from"../"] etc
|
|
183
|
-
// DEVNOTE: 2023/11/06 - https://regex101.com/r/EpuQLT/32
|
|
184
|
-
// -> fix unstable detection
|
|
185
|
-
// const bp = params.basePath;
|
|
186
|
-
// const bases = Array.isArray(bp)? bp: typeof bp === "string" && bp.length ? [bp] : void 0;
|
|
187
79
|
const bases = getBasePaths();
|
|
188
80
|
const ext = params.ext || "js";
|
|
189
81
|
/** ### regex summary
|
|
@@ -205,20 +97,12 @@ module.exports = () => {
|
|
|
205
97
|
* ```
|
|
206
98
|
* @see regex details see {@link https://regex101.com/r/EpuQLT/32 regex101.com}
|
|
207
99
|
*/
|
|
208
|
-
// const replacer = (/** @type {string} */$0, /** @type {string} */$1) => {
|
|
209
|
-
// if ($0[$0.length - 1] === "/") {
|
|
210
|
-
// return `${$0}index.${ext}`;
|
|
211
|
-
// }
|
|
212
|
-
// return $1? $0.replace(`.${$1}`, `.${ext}`): `${$0}.${ext}`;
|
|
213
|
-
// };
|
|
214
|
-
// const bs = isArray(params.basePath)? params.basePath[0]: params.basePath;
|
|
215
100
|
processSources(
|
|
216
101
|
/** @type {string} */ (this.taskName), (data) => {
|
|
217
102
|
reImportExportDetection.lastIndex = 0;
|
|
218
103
|
return data.replace(reImportExportDetection, getReplacer(ext));
|
|
219
104
|
}, {
|
|
220
105
|
bases,
|
|
221
|
-
// base: bs || ""
|
|
222
106
|
},
|
|
223
107
|
);
|
|
224
108
|
},
|
|
@@ -236,4 +120,4 @@ module.exports = () => {
|
|
|
236
120
|
`;
|
|
237
121
|
},
|
|
238
122
|
};
|
|
239
|
-
};
|
|
123
|
+
};
|