js-dev-tool 1.2.25 → 1.2.26

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-dev-tool",
3
- "version": "1.2.25",
3
+ "version": "1.2.26",
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
- const index = /** @type {webpack.EntryObject} */(entry).index || /** @type {webpack.EntryObject} */(entry).main;
58
- if (typeof index === "string") {
59
- return path.basename(index);
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 Object.keys(entry)[0];
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).type;
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 = {
@@ -0,0 +1,3 @@
1
+ export type TWebpackProgressHandler = (percentage: number, message: string, ...args: string[]) => void;
2
+ declare const getWebpackProgressPluginHandler: (bunner: string) => TWebpackProgressHandler;
3
+ export { getWebpackProgressPluginHandler };
@@ -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;