js-dev-tool 1.0.11 → 1.0.13
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/common/index.js +3 -2
- package/package.json +2 -1
- package/scripts/publish-version.json +1 -1
- package/tool-lib/cjbm.js +22 -14
- package/tool-lib/tools.d.ts +6 -6
package/common/index.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// @ts-check
|
|
12
12
|
const fs = require("fs");
|
|
13
13
|
const path = require("path");
|
|
14
|
+
const rl = require("readline");
|
|
14
15
|
/**
|
|
15
16
|
* @param {string} dest
|
|
16
17
|
*/
|
|
@@ -35,10 +36,10 @@ function createLogStreamAndResolvePath(logPath) {
|
|
|
35
36
|
*/
|
|
36
37
|
function renderLine(msg, row) {
|
|
37
38
|
const output = process.stderr || process.stdout;
|
|
38
|
-
|
|
39
|
+
rl.cursorTo(output, 0, row);
|
|
39
40
|
msg && (
|
|
40
41
|
output.write(msg),
|
|
41
|
-
|
|
42
|
+
rl.clearLine(output, 1)
|
|
42
43
|
);
|
|
43
44
|
}
|
|
44
45
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-dev-tool",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
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/tool-lib/cjbm.js
CHANGED
|
@@ -17,26 +17,32 @@ const path = require("path");
|
|
|
17
17
|
* @import * as Regex from "../regex.d.ts";
|
|
18
18
|
*/
|
|
19
19
|
const RE_TEXT = String.raw`
|
|
20
|
-
# NOTE:
|
|
21
|
-
(
|
|
20
|
+
# NOTE: PCRE での検証時は line comment assertion を (?<!\/\/|\/\/\s)(?:(?<!@)import|export) とすること (regex101.com)
|
|
21
|
+
# 正しくは: (?<!\s*\/\/+.*?)(?:(?<!@)import|export)
|
|
22
|
+
(?<!\s*\/\/+.*?)(?:(?<!@)import|export)
|
|
22
23
|
\s*
|
|
23
24
|
(?:
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
)
|
|
25
|
+
# 2025/12/22 14:57:44 - support quote character detection ["']
|
|
26
|
+
# global import, import "./"; import './global.mjs';
|
|
27
|
+
(?<qcGlobal>["'])(?!https?:)(?=[.\/]+)(?:
|
|
28
|
+
(?<globalName>(?:[.\/]+)?[^'"]+?)(?:\.(?<globalExt>(?:c|m)?jsx?))?
|
|
29
|
+
)\k<qcGlobal>|
|
|
30
|
+
# dynamic import, import("...") import('...')
|
|
27
31
|
\(\s*
|
|
28
|
-
"(?!https?:)(?=[.\/]+)(?<dynamicName>(?:[.\/]+)?[^"]+?)(?:\.(?<dynamicExt>(?:c|m)?jsx?))
|
|
32
|
+
(?<qcDynamic>["'])(?!https?:)(?=[.\/]+)(?<dynamicName>(?:[.\/]+)?[^'"]+?)(?:\.(?<dynamicExt>(?:c|m)?jsx?))?\k<qcDynamic>
|
|
29
33
|
\s*\)|
|
|
30
|
-
|
|
31
|
-
(?:
|
|
32
|
-
(?<
|
|
33
|
-
|
|
34
|
+
# esm import/export
|
|
35
|
+
(?:(?<clause>.+?|(?:\w+\s*,)?\s*\{[^}]+\})\s*from)\s*
|
|
36
|
+
(?<qcEsm>["'])(?!https?:)(?=[.\/]+)
|
|
37
|
+
(?:
|
|
38
|
+
(?<moduleName>(?:[.\/]+)?[^'"]+?)(?:\.(?<moduleExt>(?:c|m)?jsx?))?
|
|
39
|
+
)\k<qcEsm>
|
|
34
40
|
)
|
|
35
41
|
(?=\s*;)?
|
|
36
42
|
`;
|
|
37
43
|
/**
|
|
38
|
-
* @date 2025/
|
|
39
|
-
* @see https://regex101.com/r/uMMsD4/
|
|
44
|
+
* @date 2025/12/22 16:09:36
|
|
45
|
+
* @see https://regex101.com/r/uMMsD4/31
|
|
40
46
|
*/
|
|
41
47
|
const reImportExportDetection = new RegExp(
|
|
42
48
|
RE_TEXT.replace(/\s*\(\?\#.*\)\s*$|(?<!\\)\#\s*.*$|\s+/gm, ""), "g",
|
|
@@ -47,6 +53,7 @@ const reImportExportDetection = new RegExp(
|
|
|
47
53
|
* @param {string} ext - The new file extension to use.
|
|
48
54
|
* @returns {TRegexImportExportDetectorReplacer} A function to update import/export statements with the specified file extension.
|
|
49
55
|
* @date 2025/2/16 18:38:39
|
|
56
|
+
* @date 2025/12/22 16:05:13 - ./tool-lib/cjbm-resources/cjbm-browser-test.mjs を参照
|
|
50
57
|
*/
|
|
51
58
|
function getReplacer(ext) {
|
|
52
59
|
/**
|
|
@@ -55,16 +62,17 @@ function getReplacer(ext) {
|
|
|
55
62
|
*/
|
|
56
63
|
/** @type {TRegexImportExportDetectorReplacer} */
|
|
57
64
|
const replacer = (
|
|
58
|
-
$0, _1, _2, _3, _4, _5, _6, _7, _o, _s, { clause, dynamicName, globalName, moduleName }
|
|
65
|
+
$0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _o, _s, { clause, dynamicName, globalName, moduleName, qcDynamic, qcEsm, qcGlobal }
|
|
59
66
|
) => {
|
|
60
67
|
const kw = $0.startsWith("import") ? "import" : "export";
|
|
68
|
+
const qc = qcDynamic || qcEsm || qcGlobal;
|
|
61
69
|
let whichName = /** @type {string} */ (
|
|
62
70
|
globalName || moduleName || dynamicName
|
|
63
71
|
);
|
|
64
72
|
if (whichName[whichName.length - 1] === "/") {
|
|
65
73
|
whichName += "index";
|
|
66
74
|
}
|
|
67
|
-
return `${kw}${globalName
|
|
75
|
+
return `${kw}${globalName? ` ${qc}${whichName}.${ext}${qc}`: clause? ` ${clause} from ${qc}${whichName}.${ext}${qc}`: `(${qc}${whichName}.${ext}${qc})`}`;
|
|
68
76
|
};
|
|
69
77
|
return replacer;
|
|
70
78
|
}
|
package/tool-lib/tools.d.ts
CHANGED
|
@@ -6,11 +6,10 @@
|
|
|
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
14
|
type TRegexDetectRet = XRegex.ReGroups<typeof reOk>;
|
|
16
15
|
/**
|
|
@@ -18,7 +17,8 @@ type TRegexDetectRet = XRegex.ReGroups<typeof reOk>;
|
|
|
18
17
|
*/
|
|
19
18
|
declare global {
|
|
20
19
|
type TRegexImportExportDetectorReplacer = function(
|
|
21
|
-
string, string, string, string, string, string, string, string,
|
|
20
|
+
string, string, string, string, string, string, string, string, string, string, string,
|
|
21
|
+
number, string,
|
|
22
22
|
TRegexDetectRet
|
|
23
23
|
): string;
|
|
24
24
|
declare function processSources(
|