js-dev-tool 1.2.25 → 1.2.27
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 +3 -1
- package/scripts/vitest/ts-const-enum-transform.d.mts +17 -0
- package/scripts/wp/webpack.config.util.d.mts +52 -0
- package/scripts/wp/webpack.config.util.mjs +28 -7
- package/scripts/wp/wp-progress.d.mts +3 -0
- package/scripts/wp/wp-progress.mjs +1 -1
- package/utils.d.ts +17 -1
- package/utils.js +26 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js-dev-tool",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.27",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"bin": {
|
|
6
6
|
"jstool": "tools.js",
|
|
@@ -40,9 +40,11 @@
|
|
|
40
40
|
"require": "./progress/*.js"
|
|
41
41
|
},
|
|
42
42
|
"./scripts/wp/*": {
|
|
43
|
+
"types": "./scripts/wp/*.d.mts",
|
|
43
44
|
"import": "./scripts/wp/*.mjs"
|
|
44
45
|
},
|
|
45
46
|
"./scripts/vitest/*": {
|
|
47
|
+
"types": "./scripts/vitest/*.d.mts",
|
|
46
48
|
"import": "./scripts/vitest/*.mjs"
|
|
47
49
|
},
|
|
48
50
|
"./basic-types": {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type ts from "typescript";
|
|
2
|
+
/**
|
|
3
|
+
* + when could refers `vite` types
|
|
4
|
+
*
|
|
5
|
+
* @import * as NsVite from "vite";
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* import * as NsVite from "vite";
|
|
9
|
+
* // @ returns {NsVite.Plugin}
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @template {unknown} R
|
|
13
|
+
* @param {string=} cwd
|
|
14
|
+
* @param {ts.CompilerOptions=} compilerOpt
|
|
15
|
+
* @param {(tsEmitFileName: string) => boolean=} validateFileName
|
|
16
|
+
*/
|
|
17
|
+
export declare function tsConstEnumPlugin<R>(cwd?: string, compilerOpt?: ts.CompilerOptions, validateFileName?: (fileName: string) => boolean): R;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
// Copyright (C) 2020 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
+
// Released under the MIT license
|
|
5
|
+
// https://opensource.org/licenses/mit-license.php
|
|
6
|
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
+
*/
|
|
8
|
+
/// <reference path="../../basic-types.d.ts" preserve="true"/>
|
|
9
|
+
import type webpack from "webpack";
|
|
10
|
+
export type TWpConfigRequiredKeys = "name" | "mode" | "target" | "entry" | "output" | "module" | "externalsPresets" | "resolve" | "devtool" | "plugins" | "profile" | "cache" | "recordsPath" | "externals" | "experiments";
|
|
11
|
+
export type WpConfig = RequireKeys<webpack.Configuration, TWpConfigRequiredKeys>;
|
|
12
|
+
export type TExtraOptions = { beautify?: true; forceSourceMap?: true, altEntry?: WpConfig["entry"]; tsconfig?: string; logsSubDir?: string };
|
|
13
|
+
export type TModuleIdMaker = (originId: string, module: webpack.Module) => string | number;
|
|
14
|
+
export declare const CWD: string;
|
|
15
|
+
/**
|
|
16
|
+
* __reduce webpack size by shorten modId__
|
|
17
|
+
*
|
|
18
|
+
* @param {TModuleIdMaker} maker
|
|
19
|
+
*/
|
|
20
|
+
export declare const mapModuleIds: (maker: TModuleIdMaker) => (compiler: webpack.Compiler) => void;
|
|
21
|
+
export declare const numberMaker: TModuleIdMaker;
|
|
22
|
+
/**
|
|
23
|
+
* + About `entry` shape
|
|
24
|
+
*
|
|
25
|
+
* ```
|
|
26
|
+
* // "index.js"
|
|
27
|
+
* getIndexName("./src/index.js");
|
|
28
|
+
* getIndexName({ index: "./src/index.js" });
|
|
29
|
+
* getIndexName(["./src/index.js"]);
|
|
30
|
+
*
|
|
31
|
+
* // "hoge"
|
|
32
|
+
* getIndexName({ hoge: "./src/index.js" });
|
|
33
|
+
*
|
|
34
|
+
* // undefined
|
|
35
|
+
* getIndexName({});
|
|
36
|
+
* ```
|
|
37
|
+
* @param entry
|
|
38
|
+
*/
|
|
39
|
+
export declare function getIndexName(entry: NonNullable<WpConfig["entry"]>): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* CAVEAT: `resolve`, `entry`, `externals`, `module`, `optimization` property is __empty object__
|
|
42
|
+
*
|
|
43
|
+
* @param target
|
|
44
|
+
* @param output NOTE: On config name creation refers of `library.type`. if not specified use `commonjs2`
|
|
45
|
+
* @param [mode] default is __`"production"`__
|
|
46
|
+
* @param {TExtraOptions=} extraOpt see {@link TExtraOptions}
|
|
47
|
+
* @return {WpConfig}
|
|
48
|
+
* @version 2.0
|
|
49
|
+
*/
|
|
50
|
+
export declare const createWebpackConfig: (target: WpConfig["target"], output: WpConfig["output"], mode?: WpConfig["mode"], extraOpt?: TExtraOptions) => WpConfig;
|
|
51
|
+
export type TCreateWebpackConfigParameters = Parameters<typeof createWebpackConfig>;
|
|
52
|
+
export type TWebpackConfigParameters = [TCreateWebpackConfigParameters[0], TCreateWebpackConfigParameters[1], altEntry?: webpack.EntryObject, tsconfig?: string];
|
|
@@ -51,14 +51,35 @@ export const numberMaker = ((cache) => {
|
|
|
51
51
|
};
|
|
52
52
|
})(/** @type {Map<string, number>} */(new Map()));
|
|
53
53
|
/**
|
|
54
|
+
* + About `entry` shape
|
|
55
|
+
*
|
|
56
|
+
* ```
|
|
57
|
+
* // "index.js"
|
|
58
|
+
* getIndexName("./src/index.js");
|
|
59
|
+
* getIndexName({ index: "./src/index.js" });
|
|
60
|
+
* getIndexName(["./src/index.js"]);
|
|
61
|
+
*
|
|
62
|
+
* // "hoge"
|
|
63
|
+
* getIndexName({ hoge: "./src/index.js" });
|
|
64
|
+
*
|
|
65
|
+
* // undefined
|
|
66
|
+
* getIndexName({});
|
|
67
|
+
* ```
|
|
54
68
|
* @param {NonNullable<WpConfig["entry"]>} entry
|
|
55
69
|
*/
|
|
56
70
|
export function getIndexName(entry) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
/** @type {string=} */
|
|
72
|
+
let indexPath;
|
|
73
|
+
if (typeof entry === "string") indexPath = entry;
|
|
74
|
+
else {
|
|
75
|
+
const path = /** @type {webpack.EntryObject} */(entry).index || /** @type {webpack.EntryObject} */(entry).main;
|
|
76
|
+
if (typeof path === "string") indexPath = path;
|
|
77
|
+
else {
|
|
78
|
+
if (Array.isArray(entry)) indexPath = entry[0];
|
|
79
|
+
else if (typeof entry === "object") return Object.keys(entry)[0];
|
|
80
|
+
}
|
|
60
81
|
}
|
|
61
|
-
return
|
|
82
|
+
if (typeof indexPath === "string") return path.basename(indexPath);
|
|
62
83
|
}
|
|
63
84
|
/**
|
|
64
85
|
* @typedef {"name" | "mode" | "target" | "entry" | "output" | "module" | "externalsPresets" | "resolve" | "devtool" | "plugins" | "profile" | "cache" | "recordsPath" | "externals" | "experiments"} TWpConfigRequiredKeys
|
|
@@ -76,7 +97,7 @@ const wpProgressType = /** @type {TWPProgressType} */(process.env.WP_PROGRESS_TY
|
|
|
76
97
|
* CAVEAT: `resolve`, `entry`, `externals`, `module`, `optimization` property is __empty object__
|
|
77
98
|
*
|
|
78
99
|
* @param {WpConfig["target"]} target
|
|
79
|
-
* @param {WpConfig["output"]} output
|
|
100
|
+
* @param {WpConfig["output"]} output NOTE: On config name creation refers of `library.type`. if not specified use `commonjs2`
|
|
80
101
|
* @param {WpConfig["mode"]=} mode default is __`"production"`__
|
|
81
102
|
* @param {TExtraOptions=} extraOpt see {@link TExtraOptions}
|
|
82
103
|
* @return {WpConfig}
|
|
@@ -93,8 +114,8 @@ export const createWebpackConfig = (target, output, mode = "production", extraOp
|
|
|
93
114
|
* @type {WpConfig["entry"]}
|
|
94
115
|
*/
|
|
95
116
|
const entry = altEntry ?? {};
|
|
96
|
-
const mtype = /** @type {webpack.LibraryOptions} */(output.library)
|
|
97
|
-
const mainName = `${target}@${mtype}_${getIndexName(entry)}`;
|
|
117
|
+
const mtype = /** @type {webpack.LibraryOptions} */(output.library)?.type ?? "commonjs2";
|
|
118
|
+
const mainName = `${target}@${mtype}_${getIndexName(entry) ?? "anonymous"}`;
|
|
98
119
|
const outputModule = mtype === "module";
|
|
99
120
|
/** @type {WpConfig} */
|
|
100
121
|
const configObject = {
|
|
@@ -13,7 +13,7 @@ import * as extras from "../../progress/progress-extras.js";
|
|
|
13
13
|
import * as lib from "../../common/index.js";
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {(percentage: number, message: string, ...args: string[]) => void} TWebpackProgressHandler
|
|
16
|
-
* @typedef {(percentage: number, message: string, ...args: string[]) => Promise<void>} TWebpackProgressHandlerPromise
|
|
16
|
+
* @typedef {(percentage: number, message: string, ...args: string[]) => Promise<void>} TWebpackProgressHandlerPromise unused
|
|
17
17
|
*/
|
|
18
18
|
const PROGRESS_ROW_START = 4;
|
|
19
19
|
let rowStart = PROGRESS_ROW_START;
|
package/utils.d.ts
CHANGED
|
@@ -222,4 +222,20 @@ export declare function indexByCol<
|
|
|
222
222
|
Entry extends Partial<Record<TProp, string | number>>,
|
|
223
223
|
R extends Record<TKey, Entry>
|
|
224
224
|
>(tsvSource: string, opt?: TCSVParseOpt): R;
|
|
225
|
-
export const parseDelimitedToIndex: typeof indexByCol;
|
|
225
|
+
export const parseDelimitedToIndex: typeof indexByCol;
|
|
226
|
+
/**
|
|
227
|
+
* Type guard to check if a value is an object.
|
|
228
|
+
* @template {unknown} [T=Record<string, unknown>]
|
|
229
|
+
* @param {unknown} value Value to check.
|
|
230
|
+
* @returns {value is T} True if the value is an object.
|
|
231
|
+
* @date 2025/8/22 10:52:32 from `lmt`
|
|
232
|
+
*/
|
|
233
|
+
export declare const isObject: <T extends unknown = Record<string, unknown>>(value: unknown) => value is T;
|
|
234
|
+
export type TTypeOfToken = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
|
|
235
|
+
/**
|
|
236
|
+
* @template {unknown} T
|
|
237
|
+
* @param {unknown} data
|
|
238
|
+
* @param {Array<[property: string, type: TTypeOfToken]>} verifier
|
|
239
|
+
* @returns {data is T}
|
|
240
|
+
*/
|
|
241
|
+
export declare const isTypeOf: <T>(data: unknown, ...verifier: Array<[property: string, type: TTypeOfToken]>) => data is T;
|
package/utils.js
CHANGED
|
@@ -314,7 +314,7 @@ function execWithOutputResult(command, doneCallbackWithArgs, cwd) {
|
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
316
|
/**
|
|
317
|
-
* @import { TCSVParseOpt } from "./utils";
|
|
317
|
+
* @import { TCSVParseOpt, TTypeOfToken } from "./utils";
|
|
318
318
|
*/
|
|
319
319
|
/**
|
|
320
320
|
* Builds a key -> row index from a delimited text source (TSV by default).
|
|
@@ -473,6 +473,28 @@ function prependStringTo(str_array, content, suffix = "") {
|
|
|
473
473
|
str_array[i++] = `${content}${suffix}${target}`;
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* Type guard to check if a value is an object.
|
|
478
|
+
* @template {unknown} [T=Record<string, unknown>]
|
|
479
|
+
* @param {unknown} value Value to check.
|
|
480
|
+
* @returns {value is T} True if the value is an object.
|
|
481
|
+
* @date 2025/8/22 10:52:32 from `lmt`
|
|
482
|
+
*/
|
|
483
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
484
|
+
/**
|
|
485
|
+
* @template {unknown} T
|
|
486
|
+
* @param {unknown} data
|
|
487
|
+
* @param {Array<[property: string, type: TTypeOfToken]>} verifier
|
|
488
|
+
* @returns {data is T}
|
|
489
|
+
*/
|
|
490
|
+
const isTypeOf = (data, ...verifier) => {
|
|
491
|
+
if (!isObject(data)) return false;
|
|
492
|
+
for (const [prop, type] of verifier) {
|
|
493
|
+
if (!(prop in data && typeof data[prop] === type))
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
return true;
|
|
497
|
+
};
|
|
476
498
|
module.exports = {
|
|
477
499
|
prependStringTo,
|
|
478
500
|
extractVersion,
|
|
@@ -500,5 +522,7 @@ module.exports = {
|
|
|
500
522
|
log,
|
|
501
523
|
listDependenciesOf,
|
|
502
524
|
indexByCol,
|
|
503
|
-
parseDelimitedToIndex: indexByCol
|
|
525
|
+
parseDelimitedToIndex: indexByCol,
|
|
526
|
+
isObject,
|
|
527
|
+
isTypeOf,
|
|
504
528
|
};
|