@yarn-tool/pkg-entry-util 3.0.34 → 3.0.36
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/CHANGELOG.md +42 -0
- package/lib/field/scripts-auto.d.ts +175 -0
- package/lib/field/scripts-auto.js +172 -0
- package/lib/field/scripts-auto.js.map +1 -0
- package/lib/field/scripts.d.ts +23 -22
- package/lib/field/scripts.js +22 -21
- package/lib/field/scripts.js.map +1 -1
- package/lib/preset/scripts/dummy.d.ts +11 -36
- package/lib/preset/scripts/dummy.js +12 -40
- package/lib/preset/scripts/dummy.js.map +1 -1
- package/lib/preset/scripts/pkg-scripts.d.ts +4 -37
- package/lib/preset/scripts/pkg-scripts.js +4 -35
- package/lib/preset/scripts/pkg-scripts.js.map +1 -1
- package/lib/preset/scripts/root-scripts.d.ts +15 -33
- package/lib/preset/scripts/root-scripts.js +12 -30
- package/lib/preset/scripts/root-scripts.js.map +1 -1
- package/lib/preset/scripts/shared-root-scripts.d.ts +11 -32
- package/lib/preset/scripts/shared-root-scripts.js +11 -32
- package/lib/preset/scripts/shared-root-scripts.js.map +1 -1
- package/lib/preset/scripts/ws-root-scripts.d.ts +29 -71
- package/lib/preset/scripts/ws-root-scripts.js +38 -74
- package/lib/preset/scripts/ws-root-scripts.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,48 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.36](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/pkg-entry-util@3.0.35...@yarn-tool/pkg-entry-util@3.0.36) (2026-11-23)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @yarn-tool/pkg-entry-util
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [3.0.35](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/pkg-entry-util@3.0.34...@yarn-tool/pkg-entry-util@3.0.35) (2026-11-23)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### BREAKING CHANGES
|
|
18
|
+
|
|
19
|
+
* **@yarn-tool/pkg-entry-util:** 新增自動化腳本處理邏輯並整合至各工具模組
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### ✨ Features
|
|
24
|
+
|
|
25
|
+
* **@yarn-tool/pkg-entry-util:** 優化腳本自動補齊邏輯並整合 lerna 版本管理 ([b9c3a9a](https://github.com/bluelovers/ws-yarn-workspaces/commit/b9c3a9a96607c58c4dcb4a20c1888cfd3a43534e))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### 📦 Code Refactoring
|
|
29
|
+
|
|
30
|
+
* **@yarn-tool/fix-all:** 將 noScripts 選項更名為 noFillScripts 以符合命名規範 ([3d6805d](https://github.com/bluelovers/ws-yarn-workspaces/commit/3d6805d9c918b4b75ad92f09e16b19118493e1a2))
|
|
31
|
+
* **@yarn-tool/pkg-entry-util:** 重構腳本自動補齊邏輯並提取內部輔助函數 ([7763b0c](https://github.com/bluelovers/ws-yarn-workspaces/commit/7763b0cd794cc8c426a653cdfc41e09ddc6ce7f9))
|
|
32
|
+
* **@yarn-tool/pkg-entry-util:** 新增自動化腳本處理邏輯並整合至各工具模組 ([20a533e](https://github.com/bluelovers/ws-yarn-workspaces/commit/20a533e36b08d5a797dbdd6ee1df0f615af64ba9))
|
|
33
|
+
* **@yarn-tool/pkg-entry-util:** 統一管理腳本命令字串並新增常用指令 ([82d383f](https://github.com/bluelovers/ws-yarn-workspaces/commit/82d383fac06ef1c0a0f70b4e919774e496cc46a4))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### 🛠 Build System
|
|
37
|
+
|
|
38
|
+
* update build ([61f6ad4](https://github.com/bluelovers/ws-yarn-workspaces/commit/61f6ad4c5c5b5301b59f460ab3a8e2a93e1b5f2e))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### 🔖 Miscellaneous
|
|
42
|
+
|
|
43
|
+
* . ([9c9eaf5](https://github.com/bluelovers/ws-yarn-workspaces/commit/9c9eaf51d3f3e778b6a019f8c519043a09bf0e99))
|
|
44
|
+
* . ([eefdbb7](https://github.com/bluelovers/ws-yarn-workspaces/commit/eefdbb71c1306dbf29f92bd08ccbc1b7fe26a03a))
|
|
45
|
+
* . ([9ab838e](https://github.com/bluelovers/ws-yarn-workspaces/commit/9ab838e15e58abf3964e56d5f6e3f1a79fcd195e))
|
|
46
|
+
|
|
47
|
+
|
|
6
48
|
## [3.0.34](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/pkg-entry-util@3.0.33...@yarn-tool/pkg-entry-util@3.0.34) (2026-11-20)
|
|
7
49
|
|
|
8
50
|
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* package.json scripts 自動設定模組
|
|
3
|
+
*
|
|
4
|
+
* 依 rootData 表達的專案角色(根目錄 / workspace / 一般套件)套用對應的預設腳本與修復規則,
|
|
5
|
+
* 作為各初始化與修復流程取得 scripts 預設值的統一入口
|
|
6
|
+
*/
|
|
7
|
+
import { IPackageJson } from '@ts-type/package-dts/package-json';
|
|
8
|
+
import { IFindRootReturnType } from '@yarn-tool/find-root';
|
|
9
|
+
import { EnumScriptsEntry } from './scripts';
|
|
10
|
+
/** 已初始化的 scripts 物件型別 */
|
|
11
|
+
type IScripts = NonNullable<IPackageJson['scripts']>;
|
|
12
|
+
/** 預設腳本補齊的選項 */
|
|
13
|
+
export interface IFillScriptsOptions {
|
|
14
|
+
/** 跳過預設腳本補齊,僅確保 scripts 物件存在 */
|
|
15
|
+
noFillScripts?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 移除「未指定測試」的佔位 test 腳本
|
|
19
|
+
*
|
|
20
|
+
* 佔位訊息代表測試尚未設定,留著會掩蓋後續補上的真實測試腳本
|
|
21
|
+
*
|
|
22
|
+
* @param scripts - package.json 的 scripts 欄位
|
|
23
|
+
* @returns 原地修改後的 scripts
|
|
24
|
+
*/
|
|
25
|
+
export declare function removeNoTestSpecifiedScript(scripts: IPackageJson['scripts']): {
|
|
26
|
+
[k: string]: string;
|
|
27
|
+
lint?: string;
|
|
28
|
+
prepublish?: string;
|
|
29
|
+
prepare?: string;
|
|
30
|
+
prepublishOnly?: string;
|
|
31
|
+
prepack?: string;
|
|
32
|
+
postpack?: string;
|
|
33
|
+
publish?: string;
|
|
34
|
+
postpublish?: import("@ts-type/package-dts/types/package.json").ScriptsPublishAfter;
|
|
35
|
+
preinstall?: string;
|
|
36
|
+
install?: import("@ts-type/package-dts/types/package.json").ScriptsInstallAfter;
|
|
37
|
+
postinstall?: import("@ts-type/package-dts/types/package.json").ScriptsInstallAfter;
|
|
38
|
+
preuninstall?: import("@ts-type/package-dts/types/package.json").ScriptsUninstallBefore;
|
|
39
|
+
uninstall?: import("@ts-type/package-dts/types/package.json").ScriptsUninstallBefore;
|
|
40
|
+
postuninstall?: string;
|
|
41
|
+
preversion?: import("@ts-type/package-dts/types/package.json").ScriptsVersionBefore;
|
|
42
|
+
version?: import("@ts-type/package-dts/types/package.json").ScriptsVersionBefore;
|
|
43
|
+
postversion?: string;
|
|
44
|
+
pretest?: import("@ts-type/package-dts/types/package.json").ScriptsTest;
|
|
45
|
+
test?: import("@ts-type/package-dts/types/package.json").ScriptsTest;
|
|
46
|
+
posttest?: import("@ts-type/package-dts/types/package.json").ScriptsTest;
|
|
47
|
+
prestop?: import("@ts-type/package-dts/types/package.json").ScriptsStop;
|
|
48
|
+
stop?: import("@ts-type/package-dts/types/package.json").ScriptsStop;
|
|
49
|
+
poststop?: import("@ts-type/package-dts/types/package.json").ScriptsStop;
|
|
50
|
+
prestart?: import("@ts-type/package-dts/types/package.json").ScriptsStart;
|
|
51
|
+
start?: import("@ts-type/package-dts/types/package.json").ScriptsStart;
|
|
52
|
+
poststart?: import("@ts-type/package-dts/types/package.json").ScriptsStart;
|
|
53
|
+
prerestart?: import("@ts-type/package-dts/types/package.json").ScriptsRestart;
|
|
54
|
+
restart?: import("@ts-type/package-dts/types/package.json").ScriptsRestart;
|
|
55
|
+
postrestart?: import("@ts-type/package-dts/types/package.json").ScriptsRestart;
|
|
56
|
+
serve?: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* 依 rootData 補齊一般套件的預設腳本並修復 preversion
|
|
60
|
+
*
|
|
61
|
+
* @param scripts - package.json 的 scripts 欄位
|
|
62
|
+
* @param rootData - 根目錄資訊,用於判定是否為根套件
|
|
63
|
+
* @param options - 補齊選項
|
|
64
|
+
* @returns 補齊後的 scripts
|
|
65
|
+
*/
|
|
66
|
+
export declare function fixPkgScriptsAuto(scripts: IPackageJson['scripts'], rootData: IFindRootReturnType, options?: IFillScriptsOptions): IScripts;
|
|
67
|
+
/**
|
|
68
|
+
* 補齊 workspace 根目錄的預設腳本
|
|
69
|
+
*
|
|
70
|
+
* 只填補尚不存在的腳本,不覆寫使用者自訂的同名腳本
|
|
71
|
+
*
|
|
72
|
+
* @param scripts - package.json 的 scripts 欄位
|
|
73
|
+
* @param options - 補齊選項
|
|
74
|
+
* @returns 補齊後的 scripts
|
|
75
|
+
*/
|
|
76
|
+
export declare function fixWsRootScriptsAuto(scripts: IPackageJson['scripts'], options?: IFillScriptsOptions): IScripts;
|
|
77
|
+
/**
|
|
78
|
+
* 建立新 workspace 根目錄專用的預設 scripts
|
|
79
|
+
*
|
|
80
|
+
* 以 workspace 根目錄預設腳本為底,再補上 dummy 佔位的生命週期腳本,
|
|
81
|
+
* 已存在的腳本不會被覆蓋
|
|
82
|
+
*
|
|
83
|
+
* @returns 可直接寫入 package.json 的 scripts
|
|
84
|
+
*/
|
|
85
|
+
export declare function createWorkspaceRootScripts(): {
|
|
86
|
+
"prepublishOnly:root": string;
|
|
87
|
+
"prepublishOnly:lockfile": string;
|
|
88
|
+
"prepublishOnly:check-bin": EnumScriptsEntry;
|
|
89
|
+
"prepare:fix-ws-links": string;
|
|
90
|
+
"prepublishOnly:update": string;
|
|
91
|
+
ncu: string;
|
|
92
|
+
"ncu:root": EnumScriptsEntry;
|
|
93
|
+
"ncu:ws": string;
|
|
94
|
+
"sort-package-json": string;
|
|
95
|
+
"sort-package-json:root": EnumScriptsEntry;
|
|
96
|
+
"sort-package-json:ws": string;
|
|
97
|
+
postpublishOnly: string;
|
|
98
|
+
"postpublishOnly:ws-root-changelog": string;
|
|
99
|
+
preversion: EnumScriptsEntry;
|
|
100
|
+
postversion: string;
|
|
101
|
+
version: string;
|
|
102
|
+
"lerna:publish": string;
|
|
103
|
+
"build:all": string;
|
|
104
|
+
"build:since": string;
|
|
105
|
+
"test:snapshot:all": string;
|
|
106
|
+
"test:snapshot:since": string;
|
|
107
|
+
"test:all": string;
|
|
108
|
+
"test:since": string;
|
|
109
|
+
test: string;
|
|
110
|
+
"ci:install": string;
|
|
111
|
+
"ci:install:yarn": string;
|
|
112
|
+
"ci:install:pnpm": string;
|
|
113
|
+
"test:jest:clearCache": string;
|
|
114
|
+
"install:resetLockfile": string;
|
|
115
|
+
"install:frozenLockfile": string;
|
|
116
|
+
"ws:fix-all": string;
|
|
117
|
+
"ws:fix-all:addStaticFiles": string;
|
|
118
|
+
"ws:fix-all:resetStaticFiles": string;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* 建立專案初始化流程共用的 scripts 模板
|
|
122
|
+
*
|
|
123
|
+
* 依 rootData 的角色補上對應腳本:
|
|
124
|
+
*
|
|
125
|
+
* - 單一專案根目錄:合併根目錄專用的發布與版本腳本
|
|
126
|
+
* - workspaces 根目錄:腳本交由 workspaces 設定管理,不額外追加
|
|
127
|
+
* - 一般套件:維持共用模板
|
|
128
|
+
*
|
|
129
|
+
* @param rootData - 根目錄資訊
|
|
130
|
+
* @returns 共用 scripts 模板
|
|
131
|
+
*/
|
|
132
|
+
export declare function createSharedScriptsAuto(rootData: IFindRootReturnType): {
|
|
133
|
+
[k: string]: string;
|
|
134
|
+
lint?: string;
|
|
135
|
+
prepublish?: string;
|
|
136
|
+
prepare?: string;
|
|
137
|
+
prepublishOnly?: string;
|
|
138
|
+
prepack?: string;
|
|
139
|
+
postpack?: string;
|
|
140
|
+
publish?: string;
|
|
141
|
+
postpublish?: import("@ts-type/package-dts/types/package.json").ScriptsPublishAfter;
|
|
142
|
+
preinstall?: string;
|
|
143
|
+
install?: import("@ts-type/package-dts/types/package.json").ScriptsInstallAfter;
|
|
144
|
+
postinstall?: import("@ts-type/package-dts/types/package.json").ScriptsInstallAfter;
|
|
145
|
+
preuninstall?: import("@ts-type/package-dts/types/package.json").ScriptsUninstallBefore;
|
|
146
|
+
uninstall?: import("@ts-type/package-dts/types/package.json").ScriptsUninstallBefore;
|
|
147
|
+
postuninstall?: string;
|
|
148
|
+
preversion?: import("@ts-type/package-dts/types/package.json").ScriptsVersionBefore;
|
|
149
|
+
version?: import("@ts-type/package-dts/types/package.json").ScriptsVersionBefore;
|
|
150
|
+
postversion?: string;
|
|
151
|
+
pretest?: import("@ts-type/package-dts/types/package.json").ScriptsTest;
|
|
152
|
+
test?: import("@ts-type/package-dts/types/package.json").ScriptsTest;
|
|
153
|
+
posttest?: import("@ts-type/package-dts/types/package.json").ScriptsTest;
|
|
154
|
+
prestop?: import("@ts-type/package-dts/types/package.json").ScriptsStop;
|
|
155
|
+
stop?: import("@ts-type/package-dts/types/package.json").ScriptsStop;
|
|
156
|
+
poststop?: import("@ts-type/package-dts/types/package.json").ScriptsStop;
|
|
157
|
+
prestart?: import("@ts-type/package-dts/types/package.json").ScriptsStart;
|
|
158
|
+
start?: import("@ts-type/package-dts/types/package.json").ScriptsStart;
|
|
159
|
+
poststart?: import("@ts-type/package-dts/types/package.json").ScriptsStart;
|
|
160
|
+
prerestart?: import("@ts-type/package-dts/types/package.json").ScriptsRestart;
|
|
161
|
+
restart?: import("@ts-type/package-dts/types/package.json").ScriptsRestart;
|
|
162
|
+
postrestart?: import("@ts-type/package-dts/types/package.json").ScriptsRestart;
|
|
163
|
+
serve?: string;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* 為新建立的套件補上完整預設腳本
|
|
167
|
+
*
|
|
168
|
+
* 以新套件專用的完整預設腳本為底,套用共用模板,僅補上尚不存在的腳本
|
|
169
|
+
*
|
|
170
|
+
* @param scripts - package.json 的 scripts 欄位
|
|
171
|
+
* @param sharedScript - 共用 scripts 模板
|
|
172
|
+
* @returns 補齊後的 scripts
|
|
173
|
+
*/
|
|
174
|
+
export declare function fillNewPackageScriptsAuto(scripts: IPackageJson['scripts'], sharedScript: IPackageJson['scripts']): IScripts;
|
|
175
|
+
export {};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeNoTestSpecifiedScript = removeNoTestSpecifiedScript;
|
|
4
|
+
exports.fixPkgScriptsAuto = fixPkgScriptsAuto;
|
|
5
|
+
exports.fixWsRootScriptsAuto = fixWsRootScriptsAuto;
|
|
6
|
+
exports.createWorkspaceRootScripts = createWorkspaceRootScripts;
|
|
7
|
+
exports.createSharedScriptsAuto = createSharedScriptsAuto;
|
|
8
|
+
exports.fillNewPackageScriptsAuto = fillNewPackageScriptsAuto;
|
|
9
|
+
const scripts_1 = require("./scripts");
|
|
10
|
+
const dummy_1 = require("../util/scripts/dummy");
|
|
11
|
+
const pkg_scripts_1 = require("../preset/scripts/pkg-scripts");
|
|
12
|
+
const root_scripts_1 = require("../preset/scripts/root-scripts");
|
|
13
|
+
const ws_root_scripts_1 = require("../preset/scripts/ws-root-scripts");
|
|
14
|
+
const dummy_2 = require("../preset/scripts/dummy");
|
|
15
|
+
/**
|
|
16
|
+
* 統一處理 noFillScripts 與 scripts 初始化:
|
|
17
|
+
* noFillScripts 時略過補齊、僅確保 scripts 物件存在,
|
|
18
|
+
* 否則建立已初始化的 scripts 後交由 fill 補齊缺失腳本
|
|
19
|
+
*/
|
|
20
|
+
function _fixScriptsAuto(scripts, options, fill) {
|
|
21
|
+
if (options === null || options === void 0 ? void 0 : options.noFillScripts) {
|
|
22
|
+
return scripts !== null && scripts !== void 0 ? scripts : {};
|
|
23
|
+
}
|
|
24
|
+
const _scripts = scripts !== null && scripts !== void 0 ? scripts : {};
|
|
25
|
+
fill(_scripts);
|
|
26
|
+
return _scripts;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 以 source 補齊尚不存在的腳本鍵(??=),不覆寫既有值
|
|
30
|
+
*/
|
|
31
|
+
function _fillMissingScripts(scripts, source) {
|
|
32
|
+
Object
|
|
33
|
+
.entries(source)
|
|
34
|
+
.forEach(([key, value]) => {
|
|
35
|
+
var _a;
|
|
36
|
+
(_a = scripts[key]) !== null && _a !== void 0 ? _a : (scripts[key] = value);
|
|
37
|
+
});
|
|
38
|
+
return scripts;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 取得 workspace 根目錄的預設腳本並補上 dummy 佔位生命週期腳本,
|
|
42
|
+
* prefix 作為 echo 前綴,用於區分腳本的來源
|
|
43
|
+
*/
|
|
44
|
+
function _workspaceRootScripts(prefix) {
|
|
45
|
+
return (0, dummy_2.fillDummyScripts)((0, ws_root_scripts_1.defaultWorkspaceRootScripts)(), prefix);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 移除「未指定測試」的佔位 test 腳本
|
|
49
|
+
*
|
|
50
|
+
* 佔位訊息代表測試尚未設定,留著會掩蓋後續補上的真實測試腳本
|
|
51
|
+
*
|
|
52
|
+
* @param scripts - package.json 的 scripts 欄位
|
|
53
|
+
* @returns 原地修改後的 scripts
|
|
54
|
+
*/
|
|
55
|
+
function removeNoTestSpecifiedScript(scripts) {
|
|
56
|
+
if (scripts && (0, scripts_1.scriptsEntryIsNoTestSpecified)(scripts.test)) {
|
|
57
|
+
delete scripts.test;
|
|
58
|
+
}
|
|
59
|
+
return scripts;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 依 rootData 補齊一般套件的預設腳本並修復 preversion
|
|
63
|
+
*
|
|
64
|
+
* @param scripts - package.json 的 scripts 欄位
|
|
65
|
+
* @param rootData - 根目錄資訊,用於判定是否為根套件
|
|
66
|
+
* @param options - 補齊選項
|
|
67
|
+
* @returns 補齊後的 scripts
|
|
68
|
+
*/
|
|
69
|
+
function fixPkgScriptsAuto(scripts, rootData, options) {
|
|
70
|
+
return _fixScriptsAuto(scripts, options, (_scripts) => {
|
|
71
|
+
var _a;
|
|
72
|
+
/**
|
|
73
|
+
* 預設腳本僅補上尚不存在的鍵,
|
|
74
|
+
* 讓使用者自訂的同名腳本不被預設值覆蓋
|
|
75
|
+
*/
|
|
76
|
+
_fillMissingScripts(_scripts, (0, pkg_scripts_1.defaultPkgScripts)());
|
|
77
|
+
/**
|
|
78
|
+
* 非根套件:preversion 缺失或僅是 dummy echo 時,
|
|
79
|
+
* 補上會實際執行測試的 preversion,避免發布前未經驗證
|
|
80
|
+
*/
|
|
81
|
+
if (!rootData.isRoot && !((_a = _scripts['_preversion']) === null || _a === void 0 ? void 0 : _a.length) && (0, dummy_1.isDummyEchoMaybeOrEmpty)(_scripts.preversion)) {
|
|
82
|
+
_scripts.preversion = "pnpm run test" /* EnumScriptsEntry.preversion */;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 補齊 workspace 根目錄的預設腳本
|
|
88
|
+
*
|
|
89
|
+
* 只填補尚不存在的腳本,不覆寫使用者自訂的同名腳本
|
|
90
|
+
*
|
|
91
|
+
* @param scripts - package.json 的 scripts 欄位
|
|
92
|
+
* @param options - 補齊選項
|
|
93
|
+
* @returns 補齊後的 scripts
|
|
94
|
+
*/
|
|
95
|
+
function fixWsRootScriptsAuto(scripts, options) {
|
|
96
|
+
return _fixScriptsAuto(scripts, options, (_scripts) => {
|
|
97
|
+
_fillMissingScripts(_scripts, _workspaceRootScripts('workspaces'));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 建立新 workspace 根目錄專用的預設 scripts
|
|
102
|
+
*
|
|
103
|
+
* 以 workspace 根目錄預設腳本為底,再補上 dummy 佔位的生命週期腳本,
|
|
104
|
+
* 已存在的腳本不會被覆蓋
|
|
105
|
+
*
|
|
106
|
+
* @returns 可直接寫入 package.json 的 scripts
|
|
107
|
+
*/
|
|
108
|
+
function createWorkspaceRootScripts() {
|
|
109
|
+
return _workspaceRootScripts('workspaces');
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 建立專案初始化流程共用的 scripts 模板
|
|
113
|
+
*
|
|
114
|
+
* 依 rootData 的角色補上對應腳本:
|
|
115
|
+
*
|
|
116
|
+
* - 單一專案根目錄:合併根目錄專用的發布與版本腳本
|
|
117
|
+
* - workspaces 根目錄:腳本交由 workspaces 設定管理,不額外追加
|
|
118
|
+
* - 一般套件:維持共用模板
|
|
119
|
+
*
|
|
120
|
+
* @param rootData - 根目錄資訊
|
|
121
|
+
* @returns 共用 scripts 模板
|
|
122
|
+
*/
|
|
123
|
+
function createSharedScriptsAuto(rootData) {
|
|
124
|
+
/** 預設測試腳本:尚無測試時以佔位訊息提示 */
|
|
125
|
+
let sharedScript = {
|
|
126
|
+
"test": "echo \"Error: no test specified\"" /* EnumScriptsEntry.NO_TEST_SPECIFIED */,
|
|
127
|
+
};
|
|
128
|
+
/** 補上 dummy 佔位的生命週期腳本 */
|
|
129
|
+
(0, dummy_2.fillDummyScripts)(sharedScript);
|
|
130
|
+
/**
|
|
131
|
+
* 單一專案根目錄:prepublishOnly 接續 preversion,
|
|
132
|
+
* 讓發布前先跑一次版本遞增流程
|
|
133
|
+
*/
|
|
134
|
+
if (rootData.isRoot && !rootData.isWorkspace) {
|
|
135
|
+
sharedScript.prepublishOnly = "node --run preversion";
|
|
136
|
+
}
|
|
137
|
+
if (rootData.hasWorkspace) {
|
|
138
|
+
if (rootData.isPkg) {
|
|
139
|
+
sharedScript.version = 'node --run prepublishOnly:lerna';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (rootData.isRoot) {
|
|
143
|
+
sharedScript = {
|
|
144
|
+
...sharedScript,
|
|
145
|
+
...(0, root_scripts_1.defaultRootScripts)(),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* preversion 先保留 echo 提示,再接上會實際執行測試的指令
|
|
150
|
+
*/
|
|
151
|
+
sharedScript.preversion = [
|
|
152
|
+
"echo preversion",
|
|
153
|
+
"pnpm run test" /* EnumScriptsEntry.preversion */,
|
|
154
|
+
].join(' && ');
|
|
155
|
+
return sharedScript;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 為新建立的套件補上完整預設腳本
|
|
159
|
+
*
|
|
160
|
+
* 以新套件專用的完整預設腳本為底,套用共用模板,僅補上尚不存在的腳本
|
|
161
|
+
*
|
|
162
|
+
* @param scripts - package.json 的 scripts 欄位
|
|
163
|
+
* @param sharedScript - 共用 scripts 模板
|
|
164
|
+
* @returns 補齊後的 scripts
|
|
165
|
+
*/
|
|
166
|
+
function fillNewPackageScriptsAuto(scripts, sharedScript) {
|
|
167
|
+
return _fillMissingScripts(scripts !== null && scripts !== void 0 ? scripts : {}, {
|
|
168
|
+
...(0, pkg_scripts_1.defaultPkgNotOldExists)(),
|
|
169
|
+
...sharedScript,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=scripts-auto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts-auto.js","sourceRoot":"","sources":["scripts-auto.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * package.json scripts 自動設定模組\n *\n * 依 rootData 表達的專案角色(根目錄 / workspace / 一般套件)套用對應的預設腳本與修復規則,\n * 作為各初始化與修復流程取得 scripts 預設值的統一入口\n */\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { IFindRootReturnType } from '@yarn-tool/find-root';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from './scripts';\nimport { isDummyEchoMaybeOrEmpty } from '../util/scripts/dummy';\nimport { defaultPkgScripts, defaultPkgNotOldExists } from '../preset/scripts/pkg-scripts';\nimport { defaultRootScripts } from '../preset/scripts/root-scripts';\nimport { defaultWorkspaceRootScripts } from '../preset/scripts/ws-root-scripts';\nimport { fillDummyScripts } from '../preset/scripts/dummy';\n\n/** 已初始化的 scripts 物件型別 */\ntype IScripts = NonNullable<IPackageJson['scripts']>;\n\n/** 預設腳本補齊的選項 */\nexport interface IFillScriptsOptions\n{\n\t/** 跳過預設腳本補齊,僅確保 scripts 物件存在 */\n\tnoFillScripts?: boolean;\n}\n\n/**\n * 統一處理 noFillScripts 與 scripts 初始化:\n * noFillScripts 時略過補齊、僅確保 scripts 物件存在,\n * 否則建立已初始化的 scripts 後交由 fill 補齊缺失腳本\n */\nfunction _fixScriptsAuto(scripts: IPackageJson['scripts'], options: IFillScriptsOptions | undefined, fill: (scripts: IScripts) => void): IScripts\n{\n\tif (options?.noFillScripts)\n\t{\n\t\treturn scripts ?? {};\n\t}\n\n\tconst _scripts: IScripts = scripts ?? {};\n\n\tfill(_scripts);\n\n\treturn _scripts;\n}\n\n/**\n * 以 source 補齊尚不存在的腳本鍵(??=),不覆寫既有值\n */\nfunction _fillMissingScripts(scripts: IScripts, source: Record<string, string>): IScripts\n{\n\tObject\n\t\t.entries(source)\n\t\t.forEach(([key, value]) =>\n\t\t{\n\t\t\tscripts[key] ??= value;\n\t\t})\n\t;\n\n\treturn scripts;\n}\n\n/**\n * 取得 workspace 根目錄的預設腳本並補上 dummy 佔位生命週期腳本,\n * prefix 作為 echo 前綴,用於區分腳本的來源\n */\nfunction _workspaceRootScripts(prefix?: string)\n{\n\treturn fillDummyScripts(defaultWorkspaceRootScripts(), prefix);\n}\n\n/**\n * 移除「未指定測試」的佔位 test 腳本\n *\n * 佔位訊息代表測試尚未設定,留著會掩蓋後續補上的真實測試腳本\n *\n * @param scripts - package.json 的 scripts 欄位\n * @returns 原地修改後的 scripts\n */\nexport function removeNoTestSpecifiedScript(scripts: IPackageJson['scripts'])\n{\n\tif (scripts && scriptsEntryIsNoTestSpecified(scripts.test))\n\t{\n\t\tdelete scripts.test;\n\t}\n\n\treturn scripts;\n}\n\n/**\n * 依 rootData 補齊一般套件的預設腳本並修復 preversion\n *\n * @param scripts - package.json 的 scripts 欄位\n * @param rootData - 根目錄資訊,用於判定是否為根套件\n * @param options - 補齊選項\n * @returns 補齊後的 scripts\n */\nexport function fixPkgScriptsAuto(scripts: IPackageJson['scripts'], rootData: IFindRootReturnType, options?: IFillScriptsOptions): IScripts\n{\n\treturn _fixScriptsAuto(scripts, options, (_scripts) =>\n\t{\n\t\t/**\n\t\t * 預設腳本僅補上尚不存在的鍵,\n\t\t * 讓使用者自訂的同名腳本不被預設值覆蓋\n\t\t */\n\t\t_fillMissingScripts(_scripts, defaultPkgScripts());\n\n\t\t/**\n\t\t * 非根套件:preversion 缺失或僅是 dummy echo 時,\n\t\t * 補上會實際執行測試的 preversion,避免發布前未經驗證\n\t\t */\n\t\tif (!rootData.isRoot && !_scripts['_preversion']?.length && isDummyEchoMaybeOrEmpty(_scripts.preversion))\n\t\t{\n\t\t\t_scripts.preversion = EnumScriptsEntry.preversion;\n\t\t}\n\t});\n}\n\n/**\n * 補齊 workspace 根目錄的預設腳本\n *\n * 只填補尚不存在的腳本,不覆寫使用者自訂的同名腳本\n *\n * @param scripts - package.json 的 scripts 欄位\n * @param options - 補齊選項\n * @returns 補齊後的 scripts\n */\nexport function fixWsRootScriptsAuto(scripts: IPackageJson['scripts'], options?: IFillScriptsOptions): IScripts\n{\n\treturn _fixScriptsAuto(scripts, options, (_scripts) =>\n\t{\n\t\t_fillMissingScripts(_scripts, _workspaceRootScripts('workspaces'));\n\t});\n}\n\n/**\n * 建立新 workspace 根目錄專用的預設 scripts\n *\n * 以 workspace 根目錄預設腳本為底,再補上 dummy 佔位的生命週期腳本,\n * 已存在的腳本不會被覆蓋\n *\n * @returns 可直接寫入 package.json 的 scripts\n */\nexport function createWorkspaceRootScripts()\n{\n\treturn _workspaceRootScripts('workspaces');\n}\n\n/**\n * 建立專案初始化流程共用的 scripts 模板\n *\n * 依 rootData 的角色補上對應腳本:\n *\n * - 單一專案根目錄:合併根目錄專用的發布與版本腳本\n * - workspaces 根目錄:腳本交由 workspaces 設定管理,不額外追加\n * - 一般套件:維持共用模板\n *\n * @param rootData - 根目錄資訊\n * @returns 共用 scripts 模板\n */\nexport function createSharedScriptsAuto(rootData: IFindRootReturnType)\n{\n\t/** 預設測試腳本:尚無測試時以佔位訊息提示 */\n\tlet sharedScript: IScripts = {\n\t\t\"test\": EnumScriptsEntry.NO_TEST_SPECIFIED,\n\t};\n\n\t/** 補上 dummy 佔位的生命週期腳本 */\n\tfillDummyScripts(sharedScript);\n\n\t/**\n\t * 單一專案根目錄:prepublishOnly 接續 preversion,\n\t * 讓發布前先跑一次版本遞增流程\n\t */\n\tif (rootData.isRoot && !rootData.isWorkspace)\n\t{\n\t\tsharedScript.prepublishOnly = \"node --run preversion\";\n\t}\n\n\tif (rootData.hasWorkspace)\n\t{\n\t\tif (rootData.isPkg)\n\t\t{\n\t\t\tsharedScript.version = 'node --run prepublishOnly:lerna';\n\t\t}\n\t}\n\telse if (rootData.isRoot)\n\t{\n\t\tsharedScript = {\n\t\t\t...sharedScript,\n\t\t\t...defaultRootScripts(),\n\t\t};\n\t}\n\n\t/**\n\t * preversion 先保留 echo 提示,再接上會實際執行測試的指令\n\t */\n\tsharedScript.preversion = [\n\t\t\"echo preversion\",\n\t\tEnumScriptsEntry.preversion,\n\t].join(' && ');\n\n\treturn sharedScript;\n}\n\n/**\n * 為新建立的套件補上完整預設腳本\n *\n * 以新套件專用的完整預設腳本為底,套用共用模板,僅補上尚不存在的腳本\n *\n * @param scripts - package.json 的 scripts 欄位\n * @param sharedScript - 共用 scripts 模板\n * @returns 補齊後的 scripts\n */\nexport function fillNewPackageScriptsAuto(scripts: IPackageJson['scripts'], sharedScript: IPackageJson['scripts']): IScripts\n{\n\treturn _fillMissingScripts(scripts ?? {}, {\n\t\t...defaultPkgNotOldExists(),\n\t\t...sharedScript,\n\t});\n}\n"]}
|
package/lib/field/scripts.d.ts
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 常用腳本命令字串列舉
|
|
3
|
-
* Enum of common script command strings
|
|
4
3
|
*
|
|
5
4
|
* 集中管理預設腳本的命令內容,讓各預設腳本模組引用同一份字串,
|
|
6
5
|
* 避免命令在多處重複定義後逐漸不一致
|
|
7
|
-
* Centralizes the command strings so every preset script module shares a
|
|
8
|
-
* single source, preventing drift caused by duplicated definitions
|
|
9
6
|
*/
|
|
10
7
|
export declare const enum EnumScriptsEntry {
|
|
11
|
-
/** 以 Jest 執行測試,且在沒有測試檔時仍視為成功
|
|
8
|
+
/** 以 Jest 執行測試,且在沒有測試檔時仍視為成功 */
|
|
12
9
|
JEST_TEST = "jest --passWithNoTests",
|
|
13
|
-
/** 以 Node.js 原生 test runner(經 tsx)執行測試並更新快照
|
|
10
|
+
/** 以 Node.js 原生 test runner(經 tsx)執行測試並更新快照 */
|
|
14
11
|
NODE_TEST = "node --run test:node:bin -- **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
|
|
15
|
-
/** 預設測試命令
|
|
12
|
+
/** 預設測試命令 */
|
|
16
13
|
DEFAULT_TEST = "node --run test:node --",
|
|
17
14
|
/**
|
|
18
15
|
* TypeScript 型別檢查:以 `&` 連結 echo,讓檢查完成後仍有成功訊息
|
|
19
|
-
* Type check: chained with `&` so a completion message is printed afterward
|
|
20
16
|
*/
|
|
21
17
|
TSC_TEST = "tsc --noEmit & echo Type checking completed (main)",
|
|
22
18
|
TSC_TEST2 = "cd test && tsc --noEmit & echo Type checking completed (test)",
|
|
23
|
-
/**
|
|
19
|
+
/** 未指定測試的預設錯誤訊息(不中斷流程)*/
|
|
24
20
|
NO_TEST_SPECIFIED = "echo \"Error: no test specified\"",
|
|
25
|
-
/** 同上,但以 `exit 1` 讓腳本以失敗結束
|
|
21
|
+
/** 同上,但以 `exit 1` 讓腳本以失敗結束 */
|
|
26
22
|
NO_TEST_SPECIFIED_EXIT = "echo \"Error: no test specified\" && exit 1",
|
|
27
|
-
/** 以 dts-bundle-generator 產生打包型別檔
|
|
23
|
+
/** 以 dts-bundle-generator 產生打包型別檔 */
|
|
28
24
|
BUILD_DTS_BUNDLE = "ynpx @bluelovers/dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle",
|
|
29
|
-
/** 複製已存在的型別檔到 dist(Windows copy
|
|
25
|
+
/** 複製已存在的型別檔到 dist(Windows copy 指令) */
|
|
30
26
|
BUILD_DTS_COPY = "copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts",
|
|
31
|
-
/** 僅輸出型別宣告檔
|
|
27
|
+
/** 僅輸出型別宣告檔 */
|
|
32
28
|
BUILD_DTS_TSC_EMIT = "tsc --emitDeclarationOnly --declaration --noEmit false",
|
|
33
|
-
/** 完整型別建構:先 emit 再複製
|
|
29
|
+
/** 完整型別建構:先 emit 再複製 */
|
|
34
30
|
BUILD_DTS_TSC = "node --run build:dts:tsc:emit & node --run build:dts:copy",
|
|
35
|
-
/** 以 TSDX 建構 JS bundle
|
|
31
|
+
/** 以 TSDX 建構 JS bundle */
|
|
36
32
|
BUILD_TSDX = "ynpx @bluelovers/tsdx build --target node --name index",
|
|
37
|
-
/** 建構 JS
|
|
33
|
+
/** 建構 JS 與打包型別檔(兩者依序執行) */
|
|
38
34
|
BUILD_TSDX_AND_DTS = "node --run build:tsdx && node --run build:dts:bundle",
|
|
39
|
-
/** 版本遞增前先跑測試,避免發布未經驗證的版本
|
|
40
|
-
preversion = "pnpm run test"
|
|
35
|
+
/** 版本遞增前先跑測試,避免發布未經驗證的版本 */
|
|
36
|
+
preversion = "pnpm run test",
|
|
37
|
+
/** 發布前檢查套件二進位檔是否可執行 */
|
|
38
|
+
PREPUBLISH_ONLY_CHECK_BIN = "ynpx --quiet @yarn-tool/check-pkg-bin",
|
|
39
|
+
/** 顯示目前生效的 TypeScript 設定 */
|
|
40
|
+
TSC_SHOW_CONFIG = "ynpx get-current-tsconfig -p",
|
|
41
|
+
/** 更新所有依賴至最新版 */
|
|
42
|
+
NCU = "yarn-tool ncu -u",
|
|
43
|
+
/** 排序 package.json 欄位 */
|
|
44
|
+
SORT_PACKAGE_JSON = "yarn-tool sort"
|
|
41
45
|
}
|
|
42
46
|
/**
|
|
43
47
|
* 判斷腳本命令是否為「未指定測試」的佔位訊息
|
|
44
|
-
* Check whether a script command is the "no test specified" placeholder
|
|
45
48
|
*
|
|
46
49
|
* 同時涵蓋會中斷(`exit 1`)與不會中斷兩種變體,
|
|
47
50
|
* 讓呼叫端不必自行比較兩組字串
|
|
48
|
-
* Covers both the aborting (`exit 1`) and non-aborting variants so callers
|
|
49
|
-
* need not compare two literals themselves
|
|
50
51
|
*
|
|
51
|
-
* @param value - 要檢查的腳本命令
|
|
52
|
-
* @returns 是否為未指定測試的佔位訊息
|
|
52
|
+
* @param value - 要檢查的腳本命令
|
|
53
|
+
* @returns 是否為未指定測試的佔位訊息
|
|
53
54
|
*/
|
|
54
55
|
export declare function scriptsEntryIsNoTestSpecified(value: string): value is EnumScriptsEntry.NO_TEST_SPECIFIED_EXIT | EnumScriptsEntry.NO_TEST_SPECIFIED;
|
package/lib/field/scripts.js
CHANGED
|
@@ -4,57 +4,58 @@ exports.EnumScriptsEntry = void 0;
|
|
|
4
4
|
exports.scriptsEntryIsNoTestSpecified = scriptsEntryIsNoTestSpecified;
|
|
5
5
|
/**
|
|
6
6
|
* 常用腳本命令字串列舉
|
|
7
|
-
* Enum of common script command strings
|
|
8
7
|
*
|
|
9
8
|
* 集中管理預設腳本的命令內容,讓各預設腳本模組引用同一份字串,
|
|
10
9
|
* 避免命令在多處重複定義後逐漸不一致
|
|
11
|
-
* Centralizes the command strings so every preset script module shares a
|
|
12
|
-
* single source, preventing drift caused by duplicated definitions
|
|
13
10
|
*/
|
|
14
11
|
var EnumScriptsEntry;
|
|
15
12
|
(function (EnumScriptsEntry) {
|
|
16
|
-
/** 以 Jest 執行測試,且在沒有測試檔時仍視為成功
|
|
13
|
+
/** 以 Jest 執行測試,且在沒有測試檔時仍視為成功 */
|
|
17
14
|
EnumScriptsEntry["JEST_TEST"] = "jest --passWithNoTests";
|
|
18
|
-
/** 以 Node.js 原生 test runner(經 tsx)執行測試並更新快照
|
|
15
|
+
/** 以 Node.js 原生 test runner(經 tsx)執行測試並更新快照 */
|
|
19
16
|
EnumScriptsEntry["NODE_TEST"] = "node --run test:node:bin -- **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts";
|
|
20
|
-
/** 預設測試命令
|
|
17
|
+
/** 預設測試命令 */
|
|
21
18
|
EnumScriptsEntry["DEFAULT_TEST"] = "node --run test:node --";
|
|
22
19
|
/**
|
|
23
20
|
* TypeScript 型別檢查:以 `&` 連結 echo,讓檢查完成後仍有成功訊息
|
|
24
|
-
* Type check: chained with `&` so a completion message is printed afterward
|
|
25
21
|
*/
|
|
26
22
|
EnumScriptsEntry["TSC_TEST"] = "tsc --noEmit & echo Type checking completed (main)";
|
|
27
23
|
EnumScriptsEntry["TSC_TEST2"] = "cd test && tsc --noEmit & echo Type checking completed (test)";
|
|
28
|
-
/**
|
|
24
|
+
/** 未指定測試的預設錯誤訊息(不中斷流程)*/
|
|
29
25
|
EnumScriptsEntry["NO_TEST_SPECIFIED"] = "echo \"Error: no test specified\"";
|
|
30
|
-
/** 同上,但以 `exit 1` 讓腳本以失敗結束
|
|
26
|
+
/** 同上,但以 `exit 1` 讓腳本以失敗結束 */
|
|
31
27
|
EnumScriptsEntry["NO_TEST_SPECIFIED_EXIT"] = "echo \"Error: no test specified\" && exit 1";
|
|
32
|
-
/** 以 dts-bundle-generator 產生打包型別檔
|
|
28
|
+
/** 以 dts-bundle-generator 產生打包型別檔 */
|
|
33
29
|
EnumScriptsEntry["BUILD_DTS_BUNDLE"] = "ynpx @bluelovers/dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle";
|
|
34
|
-
/** 複製已存在的型別檔到 dist(Windows copy
|
|
30
|
+
/** 複製已存在的型別檔到 dist(Windows copy 指令) */
|
|
35
31
|
EnumScriptsEntry["BUILD_DTS_COPY"] = "copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts";
|
|
36
|
-
/** 僅輸出型別宣告檔
|
|
32
|
+
/** 僅輸出型別宣告檔 */
|
|
37
33
|
EnumScriptsEntry["BUILD_DTS_TSC_EMIT"] = "tsc --emitDeclarationOnly --declaration --noEmit false";
|
|
38
|
-
/** 完整型別建構:先 emit 再複製
|
|
34
|
+
/** 完整型別建構:先 emit 再複製 */
|
|
39
35
|
EnumScriptsEntry["BUILD_DTS_TSC"] = "node --run build:dts:tsc:emit & node --run build:dts:copy";
|
|
40
|
-
/** 以 TSDX 建構 JS bundle
|
|
36
|
+
/** 以 TSDX 建構 JS bundle */
|
|
41
37
|
EnumScriptsEntry["BUILD_TSDX"] = "ynpx @bluelovers/tsdx build --target node --name index";
|
|
42
|
-
/** 建構 JS
|
|
38
|
+
/** 建構 JS 與打包型別檔(兩者依序執行) */
|
|
43
39
|
EnumScriptsEntry["BUILD_TSDX_AND_DTS"] = "node --run build:tsdx && node --run build:dts:bundle";
|
|
44
|
-
/** 版本遞增前先跑測試,避免發布未經驗證的版本
|
|
40
|
+
/** 版本遞增前先跑測試,避免發布未經驗證的版本 */
|
|
45
41
|
EnumScriptsEntry["preversion"] = "pnpm run test";
|
|
42
|
+
/** 發布前檢查套件二進位檔是否可執行 */
|
|
43
|
+
EnumScriptsEntry["PREPUBLISH_ONLY_CHECK_BIN"] = "ynpx --quiet @yarn-tool/check-pkg-bin";
|
|
44
|
+
/** 顯示目前生效的 TypeScript 設定 */
|
|
45
|
+
EnumScriptsEntry["TSC_SHOW_CONFIG"] = "ynpx get-current-tsconfig -p";
|
|
46
|
+
/** 更新所有依賴至最新版 */
|
|
47
|
+
EnumScriptsEntry["NCU"] = "yarn-tool ncu -u";
|
|
48
|
+
/** 排序 package.json 欄位 */
|
|
49
|
+
EnumScriptsEntry["SORT_PACKAGE_JSON"] = "yarn-tool sort";
|
|
46
50
|
})(EnumScriptsEntry || (exports.EnumScriptsEntry = EnumScriptsEntry = {}));
|
|
47
51
|
/**
|
|
48
52
|
* 判斷腳本命令是否為「未指定測試」的佔位訊息
|
|
49
|
-
* Check whether a script command is the "no test specified" placeholder
|
|
50
53
|
*
|
|
51
54
|
* 同時涵蓋會中斷(`exit 1`)與不會中斷兩種變體,
|
|
52
55
|
* 讓呼叫端不必自行比較兩組字串
|
|
53
|
-
* Covers both the aborting (`exit 1`) and non-aborting variants so callers
|
|
54
|
-
* need not compare two literals themselves
|
|
55
56
|
*
|
|
56
|
-
* @param value - 要檢查的腳本命令
|
|
57
|
-
* @returns 是否為未指定測試的佔位訊息
|
|
57
|
+
* @param value - 要檢查的腳本命令
|
|
58
|
+
* @returns 是否為未指定測試的佔位訊息
|
|
58
59
|
*/
|
|
59
60
|
function scriptsEntryIsNoTestSpecified(value) {
|
|
60
61
|
return value === "echo \"Error: no test specified\" && exit 1" /* EnumScriptsEntry.NO_TEST_SPECIFIED_EXIT */ || value === "echo \"Error: no test specified\"" /* EnumScriptsEntry.NO_TEST_SPECIFIED */;
|
package/lib/field/scripts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["scripts.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["scripts.ts"],"names":[],"mappings":";;;AAgEA,sEAGC;AAlED;;;;;GAKG;AACH,IAAkB,gBA8CjB;AA9CD,WAAkB,gBAAgB;IAEjC,gCAAgC;IAChC,wDAAoC,CAAA;IACpC,+CAA+C;IAC/C,2HAAuG,CAAA;IAEvG,aAAa;IACb,4DAAwC,CAAA;IAExC;;OAEG;IACH,mFAA+D,CAAA;IAC/D,+FAA2E,CAAA;IAE3E,yBAAyB;IACzB,2EAAuD,CAAA;IACvD,8BAA8B;IAC9B,0FAAsE,CAAA;IAEtE,qCAAqC;IACrC,8KAA0J,CAAA;IAC1J,uCAAuC;IACvC,mGAA+E,CAAA;IAC/E,eAAe;IACf,iGAA6E,CAAA;IAC7E,wBAAwB;IACxB,+FAA2E,CAAA;IAE3E,0BAA0B;IAC1B,yFAAqE,CAAA;IACrE,2BAA2B;IAC3B,+FAA2E,CAAA;IAE3E,4BAA4B;IAC5B,gDAA4B,CAAA;IAE5B,uBAAuB;IACvB,uFAAmE,CAAA;IACnE,4BAA4B;IAC5B,oEAAgD,CAAA;IAChD,iBAAiB;IACjB,4CAAwB,CAAA;IACxB,yBAAyB;IACzB,wDAAoC,CAAA;AACrC,CAAC,EA9CiB,gBAAgB,gCAAhB,gBAAgB,QA8CjC;AAED;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CAAC,KAAa;IAE1D,OAAO,KAAK,gGAA4C,IAAI,KAAK,iFAAuC,CAAA;AACzG,CAAC","sourcesContent":["\n/**\n * 常用腳本命令字串列舉\n *\n * 集中管理預設腳本的命令內容,讓各預設腳本模組引用同一份字串,\n * 避免命令在多處重複定義後逐漸不一致\n */\nexport const enum EnumScriptsEntry\n{\n\t/** 以 Jest 執行測試,且在沒有測試檔時仍視為成功 */\n\tJEST_TEST = \"jest --passWithNoTests\",\n\t/** 以 Node.js 原生 test runner(經 tsx)執行測試並更新快照 */\n\tNODE_TEST = \"node --run test:node:bin -- **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts\",\n\n\t/** 預設測試命令 */\n\tDEFAULT_TEST = \"node --run test:node --\",\n\n\t/**\n\t * TypeScript 型別檢查:以 `&` 連結 echo,讓檢查完成後仍有成功訊息\n\t */\n\tTSC_TEST = \"tsc --noEmit & echo Type checking completed (main)\",\n\tTSC_TEST2 = \"cd test && tsc --noEmit & echo Type checking completed (test)\",\n\n\t/** 未指定測試的預設錯誤訊息(不中斷流程)*/\n\tNO_TEST_SPECIFIED = \"echo \\\"Error: no test specified\\\"\",\n\t/** 同上,但以 `exit 1` 讓腳本以失敗結束 */\n\tNO_TEST_SPECIFIED_EXIT = \"echo \\\"Error: no test specified\\\" && exit 1\",\n\n\t/** 以 dts-bundle-generator 產生打包型別檔 */\n\tBUILD_DTS_BUNDLE = \"ynpx @bluelovers/dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle\",\n\t/** 複製已存在的型別檔到 dist(Windows copy 指令) */\n\tBUILD_DTS_COPY = \"copy .\\\\src\\\\index.d.ts .\\\\dist\\\\index.d.ts & echo build:dts\",\n\t/** 僅輸出型別宣告檔 */\n\tBUILD_DTS_TSC_EMIT = \"tsc --emitDeclarationOnly --declaration --noEmit false\",\n\t/** 完整型別建構:先 emit 再複製 */\n\tBUILD_DTS_TSC = \"node --run build:dts:tsc:emit & node --run build:dts:copy\",\n\n\t/** 以 TSDX 建構 JS bundle */\n\tBUILD_TSDX = \"ynpx @bluelovers/tsdx build --target node --name index\",\n\t/** 建構 JS 與打包型別檔(兩者依序執行) */\n\tBUILD_TSDX_AND_DTS = \"node --run build:tsdx && node --run build:dts:bundle\",\n\n\t/** 版本遞增前先跑測試,避免發布未經驗證的版本 */\n\tpreversion = \"pnpm run test\",\n\n\t/** 發布前檢查套件二進位檔是否可執行 */\n\tPREPUBLISH_ONLY_CHECK_BIN = \"ynpx --quiet @yarn-tool/check-pkg-bin\",\n\t/** 顯示目前生效的 TypeScript 設定 */\n\tTSC_SHOW_CONFIG = \"ynpx get-current-tsconfig -p\",\n\t/** 更新所有依賴至最新版 */\n\tNCU = \"yarn-tool ncu -u\",\n\t/** 排序 package.json 欄位 */\n\tSORT_PACKAGE_JSON = \"yarn-tool sort\",\n}\n\n/**\n * 判斷腳本命令是否為「未指定測試」的佔位訊息\n *\n * 同時涵蓋會中斷(`exit 1`)與不會中斷兩種變體,\n * 讓呼叫端不必自行比較兩組字串\n *\n * @param value - 要檢查的腳本命令\n * @returns 是否為未指定測試的佔位訊息\n */\nexport function scriptsEntryIsNoTestSpecified(value: string): value is EnumScriptsEntry.NO_TEST_SPECIFIED_EXIT | EnumScriptsEntry.NO_TEST_SPECIFIED\n{\n\treturn value === EnumScriptsEntry.NO_TEST_SPECIFIED_EXIT || value === EnumScriptsEntry.NO_TEST_SPECIFIED\n}\n"]}
|