@yarn-tool/check-pkg-bin 4.0.11 → 4.0.12
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 +33 -0
- package/README.md +73 -3
- package/bin/check-pkg-bin.js +30 -0
- package/bin/check-pkg-bin.js.map +1 -1
- package/index.d.ts +9 -0
- package/index.js +9 -0
- package/index.js.map +1 -1
- package/lib/core.d.ts +29 -0
- package/lib/core.js +36 -0
- package/lib/core.js.map +1 -1
- package/lib/pkg.d.ts +10 -0
- package/lib/pkg.js +16 -0
- package/lib/pkg.js.map +1 -1
- package/lib/ws.d.ts +10 -0
- package/lib/ws.js +10 -0
- package/lib/ws.js.map +1 -1
- package/package.json +24 -23
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
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
|
+
## [4.0.12](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/check-pkg-bin@4.0.11...@yarn-tool/check-pkg-bin@4.0.12) (2026-10-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 📚 Documentation
|
|
11
|
+
|
|
12
|
+
* add jsdoc ([9cb9b13](https://github.com/bluelovers/ws-yarn-workspaces/commit/9cb9b13eda8c357221ad1b754458aa9916eada22))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### 🛠 Build System
|
|
16
|
+
|
|
17
|
+
* update build ([3186340](https://github.com/bluelovers/ws-yarn-workspaces/commit/3186340758172427cb1e9b8955f6fd677abac625))
|
|
18
|
+
* **deps:** 更新測試腳本與依賴以支援 node:test ([f9c71c7](https://github.com/bluelovers/ws-yarn-workspaces/commit/f9c71c795c792c5c7ed9d613ce7e9c3c726c39d5))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### ♻️ Chores
|
|
22
|
+
|
|
23
|
+
* **deps:** 更新依賴版本並清理 npm-init2 腳本 ([82bf1e5](https://github.com/bluelovers/ws-yarn-workspaces/commit/82bf1e5d229759aa285205d81cf0651e4d3d9792))
|
|
24
|
+
* **deps:** 更新各套件依賴版本 ([569f075](https://github.com/bluelovers/ws-yarn-workspaces/commit/569f0756189cdadf69955d8e388ac0a6a8988056))
|
|
25
|
+
* **workspace:** 更新測試指令路徑與新增工作區搜尋選項 ([a80039d](https://github.com/bluelovers/ws-yarn-workspaces/commit/a80039dd8c691e047466966ffc8f8a4e2e31c03f))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### 📌 Dependencies
|
|
29
|
+
|
|
30
|
+
* update deps ([a0c22fe](https://github.com/bluelovers/ws-yarn-workspaces/commit/a0c22feeb1703d1cc10d45ecbf6f2269e92f72da))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### 🔖 Miscellaneous
|
|
34
|
+
|
|
35
|
+
* . ([e5788f8](https://github.com/bluelovers/ws-yarn-workspaces/commit/e5788f84551b870490a96d0a5d67d8d542481373))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
6
39
|
## [4.0.11](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/check-pkg-bin@4.0.10...@yarn-tool/check-pkg-bin@4.0.11) (2026-09-06)
|
|
7
40
|
|
|
8
41
|
|
package/README.md
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yarn-tool/check-pkg-bin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
檢查套件的 `bin` 檔案是否帶有 shebang(check pkg bin has shebang)。可用於單一套件,也可一次檢查整個 Yarn workspace(Workspace)中的所有套件。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 檢查 `package.json` 中 `bin` 所指向的檔案是否含 shebang(`#!/usr/bin/env node`)
|
|
8
|
+
- 支援以 CLI 表格輸出檢查結果,並以 exit code 回報失敗
|
|
9
|
+
- 提供 `--workspaces` 模式,批次檢查 workspace 內所有套件
|
|
10
|
+
- 提供程式化 API:`checkPkgDir`、`checkPkgJson`、`checkWorkspaces`、`hasShebang`、`checkFile`
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
6
13
|
|
|
7
14
|
```bash
|
|
8
15
|
yarn add @yarn-tool/check-pkg-bin
|
|
@@ -10,3 +17,66 @@ yarn-tool add @yarn-tool/check-pkg-bin
|
|
|
10
17
|
yt add @yarn-tool/check-pkg-bin
|
|
11
18
|
```
|
|
12
19
|
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### CLI
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# 檢查當前套件
|
|
26
|
+
npx check-pkg-bin
|
|
27
|
+
|
|
28
|
+
# 檢查整個 workspace
|
|
29
|
+
npx check-pkg-bin --workspaces
|
|
30
|
+
|
|
31
|
+
# 指定工作目錄
|
|
32
|
+
npx check-pkg-bin --cwd ./packages/foo
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
輸出為表格,`validate` 欄位為 `true` / `false` / `none`(`none` 表示該套件沒有 `bin` 欄位);若有任何套件檢查失敗,程序將以狀態碼 `1` 結束。
|
|
36
|
+
|
|
37
|
+
### 程式化使用
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import checkPkgDir from '@yarn-tool/check-pkg-bin';
|
|
41
|
+
// 或
|
|
42
|
+
import { checkWorkspaces, checkPkgJson, hasShebang } from '@yarn-tool/check-pkg-bin';
|
|
43
|
+
|
|
44
|
+
const data = checkPkgDir(process.cwd());
|
|
45
|
+
|
|
46
|
+
console.log(data.valid); // 所有 bin 檔案是否皆含 shebang
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## API Documentation
|
|
50
|
+
|
|
51
|
+
### `checkPkgDir(pkgDir?: string): CheckPkgDirResult`
|
|
52
|
+
|
|
53
|
+
預設以 `process.cwd()` 為根目錄,讀取該目錄的 `package.json` 並檢查所有 `bin` 檔案。回傳:
|
|
54
|
+
|
|
55
|
+
- `name`:套件名稱
|
|
56
|
+
- `pkg`:解析後的 `package.json` 內容
|
|
57
|
+
- `pkgDir`:套件根目錄
|
|
58
|
+
- `result`:每個 bin 的檢查明細(`file`、`filename`、`hasShebang`)
|
|
59
|
+
- `valid`:所有 bin 是否皆通過檢查
|
|
60
|
+
|
|
61
|
+
### `checkPkgJson(pkg: IPackageJson, cwd: string): Array<{ file, filename, hasShebang }>`
|
|
62
|
+
|
|
63
|
+
對傳入的 `package.json` 物件執行 bin 檢查,不自行讀檔。
|
|
64
|
+
|
|
65
|
+
### `checkWorkspaces(cwd?: string): CheckPkgDirResult[]`
|
|
66
|
+
|
|
67
|
+
列出 workspace 內所有套件並逐一執行 `checkPkgDir`。
|
|
68
|
+
|
|
69
|
+
### `hasShebang(buf: Buffer | string): boolean`
|
|
70
|
+
|
|
71
|
+
判斷任意內容字串/緩衝區是否含 shebang。
|
|
72
|
+
|
|
73
|
+
### `checkFile(file: string): boolean | undefined`
|
|
74
|
+
|
|
75
|
+
檢查單一檔案是否存在且含 shebang;檔案不存在時回傳 `undefined`。
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
本套件無須額外設定,所有欄位皆來自各套件的 `package.json`:
|
|
80
|
+
|
|
81
|
+
- `bin`:欲檢查的可執行檔路徑(相對於套件根目錄)
|
|
82
|
+
- 工作目錄可透過 CLI 的 `--cwd` 或 API 的 `pkgDir` / `cwd` 參數指定
|
package/bin/check-pkg-bin.js
CHANGED
|
@@ -11,6 +11,14 @@ const pkg_dir_1 = tslib_1.__importDefault(require("pkg-dir"));
|
|
|
11
11
|
const string_natural_compare_1 = tslib_1.__importDefault(require("@bluelovers/string-natural-compare"));
|
|
12
12
|
const table_1 = require("@yarn-tool/table");
|
|
13
13
|
const find_root_1 = require("@yarn-tool/find-root");
|
|
14
|
+
/**
|
|
15
|
+
* CLI 參數定義:
|
|
16
|
+
* --workspaces(-w) 強制以 workspace 模式檢查;
|
|
17
|
+
* 未指定時交由 findRoot 的 isWorkspace 判斷,讓 monorepo 與單套件目錄皆可直接執行。
|
|
18
|
+
*
|
|
19
|
+
* CLI options: --workspaces(-w) forces workspace mode; when omitted, findRoot's
|
|
20
|
+
* isWorkspace decides, so both monorepo and single-package dirs can run as-is.
|
|
21
|
+
*/
|
|
14
22
|
const cli = yargs_1.default
|
|
15
23
|
.option('workspaces', {
|
|
16
24
|
alias: ['w'],
|
|
@@ -22,6 +30,8 @@ const cli = yargs_1.default
|
|
|
22
30
|
})
|
|
23
31
|
.help()
|
|
24
32
|
.parseSync();
|
|
33
|
+
// 以無邊框樣式輸出表格,避免在 CI / 純文字終機中出現雜亂的框線符號。
|
|
34
|
+
// Borderless table style avoids noisy box-drawing glyphs in CI / plain terminals.
|
|
25
35
|
const table = new cli_table3_1.default({
|
|
26
36
|
colAligns: ['left', 'right'],
|
|
27
37
|
});
|
|
@@ -31,15 +41,27 @@ table.options.head = [
|
|
|
31
41
|
chalk.bold.reset('package name'),
|
|
32
42
|
chalk.bold.reset('validate'),
|
|
33
43
|
];
|
|
44
|
+
// 整體驗證結果:只有「有 bin 且未通過」才會被設為 false;
|
|
45
|
+
// 初值 undefined 保留給「所有套件都沒有 bin」的情況,使其不觸發 exit 1。
|
|
46
|
+
// Overall result: only "has bins and failed" sets false; the initial undefined
|
|
47
|
+
// covers "no package has bins" so that case does not trigger exit 1.
|
|
34
48
|
let bool;
|
|
35
49
|
const rootData = (0, find_root_1.findRoot)(cli);
|
|
36
50
|
if ((_a = cli.workspaces) !== null && _a !== void 0 ? _a : rootData.isWorkspace) {
|
|
51
|
+
// workspace 模式:依套件名稱自然排序後逐一檢查,
|
|
52
|
+
// 並在表格中以顏色區分通過(綠)/ 失敗(紅)/ 無 bin(灰)。
|
|
53
|
+
// Workspace mode: check each package (naturally sorted by name) and color
|
|
54
|
+
// pass (green) / fail (red) / no bins (gray) in the table.
|
|
37
55
|
(0, __1.checkWorkspaces)(cli.cwd)
|
|
38
56
|
.sort((a, b) => (0, string_natural_compare_1.default)(a.name, b.name))
|
|
39
57
|
.forEach(data => {
|
|
40
58
|
let valid = data.valid.toString();
|
|
41
59
|
let color = 'gray';
|
|
42
60
|
if (data.result.length) {
|
|
61
|
+
// 僅有 bin 的套件才納入整體驗證;
|
|
62
|
+
// 空 result 以 none 呈現,不影響 exit code。
|
|
63
|
+
// Only packages with bins count toward the overall result; an
|
|
64
|
+
// empty result shows "none" without affecting the exit code.
|
|
43
65
|
bool = data.valid && (bool !== null && bool !== void 0 ? bool : true);
|
|
44
66
|
color = data.valid ? 'green' : 'red';
|
|
45
67
|
}
|
|
@@ -53,6 +75,10 @@ if ((_a = cli.workspaces) !== null && _a !== void 0 ? _a : rootData.isWorkspace)
|
|
|
53
75
|
});
|
|
54
76
|
}
|
|
55
77
|
else {
|
|
78
|
+
// 單套件模式:以 pkgDir.sync 向上尋找 package.json 所在目錄。
|
|
79
|
+
// 沒有 bin 或全部通過皆視為成功(true),僅「有 bin 且失敗」才會 exit 1。
|
|
80
|
+
// Single-package mode: pkgDir.sync walks up to the package.json directory.
|
|
81
|
+
// No bins or all passing counts as success; only "has bins and failed" exits 1.
|
|
56
82
|
let data = (0, __1.checkPkgDir)(pkg_dir_1.default.sync(cli.cwd));
|
|
57
83
|
bool = (!data.result.length || data.valid);
|
|
58
84
|
let valid = data.valid.toString();
|
|
@@ -69,6 +95,10 @@ else {
|
|
|
69
95
|
]);
|
|
70
96
|
}
|
|
71
97
|
debug_color2_1.console.log(table.toString());
|
|
98
|
+
// 僅在明確驗證失敗時以狀態碼 1 結束,
|
|
99
|
+
// 讓 CI 可據此攔截「bin 缺少 shebang」的套件。
|
|
100
|
+
// Exit with status 1 only on explicit failure so CI can block packages whose
|
|
101
|
+
// bins are missing a shebang.
|
|
72
102
|
if (bool === false) {
|
|
73
103
|
process.exit(1);
|
|
74
104
|
}
|
package/bin/check-pkg-bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
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ACnB,CAAC,CAAC;AACJ,CAAC;AAED,sBAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;AAE7B,IAAI,IAAI,KAAK,KAAK,EAClB,CAAC;IACA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAChB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport yargs from 'yargs';\nimport { checkWorkspaces, checkPkgJson, checkPkgDir } from '..';\nimport { console, chalkByConsoleMaybe } from 'debug-color2';\nimport Table from 'cli-table3';\nimport pkgDir from 'pkg-dir';\nimport stringNaturalCompare from '@bluelovers/string-natural-compare';\nimport { applyStyleBorderless } from '@yarn-tool/table';\nimport { findRoot } from '@yarn-tool/find-root';\n\nconst cli = yargs\n\t.option('workspaces', {\n\t\talias: ['w'],\n\t\tboolean: true,\n\t})\n\t.option('cwd', {\n\t\tnormalize: true,\n\t\tdefault: process.cwd(),\n\t})\n\t.help()\n\t.parseSync()\n;\n\nconst table = new Table({\n\tcolAligns: ['left', 'right'],\n});\n\napplyStyleBorderless(table);\n\nconst chalk = chalkByConsoleMaybe(console);\n\ntable.options.head = [\n\tchalk.bold.reset('package name'),\n\tchalk.bold.reset('validate'),\n];\n\nlet bool: boolean;\n\nconst rootData = findRoot(cli);\n\nif (cli.workspaces ?? rootData.isWorkspace)\n{\n\tcheckWorkspaces(cli.cwd)\n\t\t.sort((a, b) => stringNaturalCompare(a.name, b.name))\n\t\t.forEach(data =>\n\t\t{\n\t\t\tlet valid = data.valid.toString()\n\t\t\tlet color = 'gray';\n\n\t\t\tif (data.result.length)\n\t\t\t{\n\t\t\t\tbool = data.valid && (bool ?? true)\n\n\t\t\t\tcolor = data.valid ? 'green' : 'red';\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tvalid = 'none'\n\t\t\t}\n\n\t\t\ttable.push([\n\t\t\t\tdata.name,\n\t\t\t\tchalk[color](valid),\n\t\t\t]);\n\t\t})\n\t;\n}\nelse\n{\n\tlet data = checkPkgDir(pkgDir.sync(cli.cwd))\n\tbool = (!data.result.length || data.valid);\n\tlet valid = data.valid.toString()\n\tlet color = 'gray';\n\n\tif (!data.result.length)\n\t{\n\t\tvalid = 'none'\n\t}\n\telse\n\t{\n\t\tcolor = data.valid ? 'green' : 'red';\n\t}\n\n\ttable.push([\n\t\tchalk.blue(data.name),\n\t\tchalk[color](valid),\n\t]);\n}\n\nconsole.log(table.toString())\n\nif (bool === false)\n{\n\tprocess.exit(1)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"check-pkg-bin.js","sourceRoot":"","sources":["check-pkg-bin.ts"],"names":[],"mappings":";;;;;AAEA,0DAA0B;AAC1B,0BAAgE;AAChE,+CAA4D;AAC5D,oEAA+B;AAC/B,8DAA6B;AAC7B,wGAAsE;AACtE,4CAAwD;AACxD,oDAAgD;AAEhD;;;;;;;GAOG;AACH,MAAM,GAAG,GAAG,eAAK;KACf,MAAM,CAAC,YAAY,EAAE;IACrB,KAAK,EAAE,CAAC,GAAG,CAAC;IACZ,OAAO,EAAE,IAAI;CACb,CAAC;KACD,MAAM,CAAC,KAAK,EAAE;IACd,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;CACtB,CAAC;KACD,IAAI,EAAE;KACN,SAAS,EAAE,CACZ;AAED,uCAAuC;AACvC,kFAAkF;AAClF,MAAM,KAAK,GAAG,IAAI,oBAAK,CAAC;IACvB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;CAC5B,CAAC,CAAC;AAEH,IAAA,4BAAoB,EAAC,KAAK,CAAC,CAAC;AAE5B,MAAM,KAAK,GAAG,IAAA,kCAAmB,EAAC,sBAAO,CAAC,CAAC;AAE3C,KAAK,CAAC,OAAO,CAAC,IAAI,GAAG;IACpB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;IAChC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;CAC5B,CAAC;AAEF,o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AC,iBAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IAC5C,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAA;IACjC,IAAI,KAAK,GAAG,MAAM,CAAC;IAEnB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EACvB,CAAC;QACA,KAAK,GAAG,MAAM,CAAA;IACf,CAAC;SAED,CAAC;QACA,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC;QACV,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QACrB,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;KACnB,CAAC,CAAC;AACJ,CAAC;AAED,sBAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;AAE7B,sBAAsB;AACtB,iCAAiC;AACjC,6EAA6E;AAC7E,8BAA8B;AAC9B,IAAI,IAAI,KAAK,KAAK,EAClB,CAAC;IACA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAChB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport yargs from 'yargs';\nimport { checkWorkspaces, checkPkgJson, checkPkgDir } from '..';\nimport { console, chalkByConsoleMaybe } from 'debug-color2';\nimport Table from 'cli-table3';\nimport pkgDir from 'pkg-dir';\nimport stringNaturalCompare from '@bluelovers/string-natural-compare';\nimport { applyStyleBorderless } from '@yarn-tool/table';\nimport { findRoot } from '@yarn-tool/find-root';\n\n/**\n * CLI 參數定義:\n * --workspaces(-w) 強制以 workspace 模式檢查;\n * 未指定時交由 findRoot 的 isWorkspace 判斷,讓 monorepo 與單套件目錄皆可直接執行。\n *\n * CLI options: --workspaces(-w) forces workspace mode; when omitted, findRoot's\n * isWorkspace decides, so both monorepo and single-package dirs can run as-is.\n */\nconst cli = yargs\n\t.option('workspaces', {\n\t\talias: ['w'],\n\t\tboolean: true,\n\t})\n\t.option('cwd', {\n\t\tnormalize: true,\n\t\tdefault: process.cwd(),\n\t})\n\t.help()\n\t.parseSync()\n;\n\n// 以無邊框樣式輸出表格,避免在 CI / 純文字終機中出現雜亂的框線符號。\n// Borderless table style avoids noisy box-drawing glyphs in CI / plain terminals.\nconst table = new Table({\n\tcolAligns: ['left', 'right'],\n});\n\napplyStyleBorderless(table);\n\nconst chalk = chalkByConsoleMaybe(console);\n\ntable.options.head = [\n\tchalk.bold.reset('package name'),\n\tchalk.bold.reset('validate'),\n];\n\n// 整體驗證結果:只有「有 bin 且未通過」才會被設為 false;\n// 初值 undefined 保留給「所有套件都沒有 bin」的情況,使其不觸發 exit 1。\n// Overall result: only \"has bins and failed\" sets false; the initial undefined\n// covers \"no package has bins\" so that case does not trigger exit 1.\nlet bool: boolean;\n\nconst rootData = findRoot(cli);\n\nif (cli.workspaces ?? rootData.isWorkspace)\n{\n\t// workspace 模式:依套件名稱自然排序後逐一檢查,\n\t// 並在表格中以顏色區分通過(綠)/ 失敗(紅)/ 無 bin(灰)。\n\t// Workspace mode: check each package (naturally sorted by name) and color\n\t// pass (green) / fail (red) / no bins (gray) in the table.\n\tcheckWorkspaces(cli.cwd)\n\t\t.sort((a, b) => stringNaturalCompare(a.name, b.name))\n\t\t.forEach(data =>\n\t\t{\n\t\t\tlet valid = data.valid.toString()\n\t\t\tlet color = 'gray';\n\n\t\t\tif (data.result.length)\n\t\t\t{\n\t\t\t\t// 僅有 bin 的套件才納入整體驗證;\n\t\t\t\t// 空 result 以 none 呈現,不影響 exit code。\n\t\t\t\t// Only packages with bins count toward the overall result; an\n\t\t\t\t// empty result shows \"none\" without affecting the exit code.\n\t\t\t\tbool = data.valid && (bool ?? true)\n\n\t\t\t\tcolor = data.valid ? 'green' : 'red';\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tvalid = 'none'\n\t\t\t}\n\n\t\t\ttable.push([\n\t\t\t\tdata.name,\n\t\t\t\tchalk[color](valid),\n\t\t\t]);\n\t\t})\n\t;\n}\nelse\n{\n\t// 單套件模式:以 pkgDir.sync 向上尋找 package.json 所在目錄。\n\t// 沒有 bin 或全部通過皆視為成功(true),僅「有 bin 且失敗」才會 exit 1。\n\t// Single-package mode: pkgDir.sync walks up to the package.json directory.\n\t// No bins or all passing counts as success; only \"has bins and failed\" exits 1.\n\tlet data = checkPkgDir(pkgDir.sync(cli.cwd))\n\tbool = (!data.result.length || data.valid);\n\tlet valid = data.valid.toString()\n\tlet color = 'gray';\n\n\tif (!data.result.length)\n\t{\n\t\tvalid = 'none'\n\t}\n\telse\n\t{\n\t\tcolor = data.valid ? 'green' : 'red';\n\t}\n\n\ttable.push([\n\t\tchalk.blue(data.name),\n\t\tchalk[color](valid),\n\t]);\n}\n\nconsole.log(table.toString())\n\n// 僅在明確驗證失敗時以狀態碼 1 結束,\n// 讓 CI 可據此攔截「bin 缺少 shebang」的套件。\n// Exit with status 1 only on explicit failure so CI can block packages whose\n// bins are missing a shebang.\nif (bool === false)\n{\n\tprocess.exit(1)\n}\n"]}
|
package/index.d.ts
CHANGED
|
@@ -2,4 +2,13 @@ import { checkPkgDir } from './lib/pkg';
|
|
|
2
2
|
export * from './lib/core';
|
|
3
3
|
export * from './lib/ws';
|
|
4
4
|
export * from './lib/pkg';
|
|
5
|
+
/**
|
|
6
|
+
* 預設匯出單一套件檢查入口,
|
|
7
|
+
* 讓使用者可直接以 `import checkPkgDir from '@yarn-tool/check-pkg-bin'` 使用,
|
|
8
|
+
* 與 CLI 的單套件模式行為一致(Why:降低只做單套件檢查時的匯入成本)。
|
|
9
|
+
*
|
|
10
|
+
* Default export of the single-package check entry, so consumers can use
|
|
11
|
+
* `import checkPkgDir from '@yarn-tool/check-pkg-bin'` directly, matching the
|
|
12
|
+
* CLI's single-package mode (Why: lower the import cost for the common case).
|
|
13
|
+
*/
|
|
5
14
|
export default checkPkgDir;
|
package/index.js
CHANGED
|
@@ -5,5 +5,14 @@ const pkg_1 = require("./lib/pkg");
|
|
|
5
5
|
tslib_1.__exportStar(require("./lib/core"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./lib/ws"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./lib/pkg"), exports);
|
|
8
|
+
/**
|
|
9
|
+
* 預設匯出單一套件檢查入口,
|
|
10
|
+
* 讓使用者可直接以 `import checkPkgDir from '@yarn-tool/check-pkg-bin'` 使用,
|
|
11
|
+
* 與 CLI 的單套件模式行為一致(Why:降低只做單套件檢查時的匯入成本)。
|
|
12
|
+
*
|
|
13
|
+
* Default export of the single-package check entry, so consumers can use
|
|
14
|
+
* `import checkPkgDir from '@yarn-tool/check-pkg-bin'` directly, matching the
|
|
15
|
+
* CLI's single-package mode (Why: lower the import cost for the common case).
|
|
16
|
+
*/
|
|
8
17
|
exports.default = pkg_1.checkPkgDir;
|
|
9
18
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAExC,qDAA2B;AAC3B,mDAAyB;AACzB,oDAA0B;AAE1B,kBAAe,iBAAW,CAAA","sourcesContent":["import { checkPkgDir } from './lib/pkg';\n\nexport * from './lib/core';\nexport * from './lib/ws';\nexport * from './lib/pkg';\n\nexport default checkPkgDir\n
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAExC,qDAA2B;AAC3B,mDAAyB;AACzB,oDAA0B;AAE1B;;;;;;;;GAQG;AACH,kBAAe,iBAAW,CAAA","sourcesContent":["import { checkPkgDir } from './lib/pkg';\n\nexport * from './lib/core';\nexport * from './lib/ws';\nexport * from './lib/pkg';\n\n/**\n * 預設匯出單一套件檢查入口,\n * 讓使用者可直接以 `import checkPkgDir from '@yarn-tool/check-pkg-bin'` 使用,\n * 與 CLI 的單套件模式行為一致(Why:降低只做單套件檢查時的匯入成本)。\n *\n * Default export of the single-package check entry, so consumers can use\n * `import checkPkgDir from '@yarn-tool/check-pkg-bin'` directly, matching the\n * CLI's single-package mode (Why: lower the import cost for the common case).\n */\nexport default checkPkgDir\n"]}
|
package/lib/core.d.ts
CHANGED
|
@@ -2,8 +2,37 @@
|
|
|
2
2
|
* Created by user on 2020/6/13.
|
|
3
3
|
*/
|
|
4
4
|
import { IPackageJson } from '@ts-type/package-dts';
|
|
5
|
+
/**
|
|
6
|
+
* 判斷任意內容是否含 shebang(`#!`)開頭。
|
|
7
|
+
* 回傳布林值而非直接依賴 truthy,是為了讓「無 shebang」與「比對失敗」都明確視為 false。
|
|
8
|
+
*
|
|
9
|
+
* Detect whether arbitrary content starts with a shebang (`#!`).
|
|
10
|
+
* Returning an explicit boolean keeps "no shebang" and "match failure" both false.
|
|
11
|
+
*/
|
|
5
12
|
export declare function hasShebang(buf: Buffer | string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 檢查單一檔案是否存在且含 shebang。
|
|
15
|
+
* 檔案不存在時回傳 undefined(而非 false),讓呼叫方得以區分
|
|
16
|
+
* 「檔案缺少」與「檔案存在但沒有 shebang」兩種不同的失敗原因。
|
|
17
|
+
*
|
|
18
|
+
* Check whether a single file exists and contains a shebang.
|
|
19
|
+
* Returns undefined (not false) when missing, so callers can distinguish
|
|
20
|
+
* "file missing" from "file exists but lacks a shebang".
|
|
21
|
+
*/
|
|
6
22
|
export declare function checkFile(file: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 依 package.json 的 bin 欄位逐檔檢查 shebang,
|
|
25
|
+
* 並以 reduce 累積成固定的明細結構(而非僅回傳布林),
|
|
26
|
+
* 以便 CLI 能對每一支可執行檔顯示檔案路徑與檢查結果。
|
|
27
|
+
*
|
|
28
|
+
* Check every bin entry from package.json for a shebang, accumulating a fixed
|
|
29
|
+
* detail structure via reduce (instead of a bare boolean) so the CLI can show
|
|
30
|
+
* the path and result for each executable.
|
|
31
|
+
*
|
|
32
|
+
* @param pkg 已解析的 package.json 物件 / parsed package.json object
|
|
33
|
+
* @param cwd 套件根目錄,用於將 bin 的相對路徑解析為絕對路徑 /
|
|
34
|
+
* package root used to resolve relative bin paths to absolute ones
|
|
35
|
+
*/
|
|
7
36
|
export declare function checkPkgJson(pkg: IPackageJson, cwd: string): {
|
|
8
37
|
file: string;
|
|
9
38
|
filename: string;
|
package/lib/core.js
CHANGED
|
@@ -10,17 +10,53 @@ const fs_extra_1 = require("fs-extra");
|
|
|
10
10
|
const shebang_1 = require("@yarn-tool/shebang");
|
|
11
11
|
const get_pkg_bin_1 = require("@yarn-tool/get-pkg-bin");
|
|
12
12
|
const upath2_1 = require("upath2");
|
|
13
|
+
/**
|
|
14
|
+
* 判斷任意內容是否含 shebang(`#!`)開頭。
|
|
15
|
+
* 回傳布林值而非直接依賴 truthy,是為了讓「無 shebang」與「比對失敗」都明確視為 false。
|
|
16
|
+
*
|
|
17
|
+
* Detect whether arbitrary content starts with a shebang (`#!`).
|
|
18
|
+
* Returning an explicit boolean keeps "no shebang" and "match failure" both false.
|
|
19
|
+
*/
|
|
13
20
|
function hasShebang(buf) {
|
|
14
21
|
var _a, _b;
|
|
15
22
|
return ((_b = (_a = (0, shebang_1.matchShebang)(buf.toString())) === null || _a === void 0 ? void 0 : _a.script) === null || _b === void 0 ? void 0 : _b.length) > 0;
|
|
16
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* 檢查單一檔案是否存在且含 shebang。
|
|
26
|
+
* 檔案不存在時回傳 undefined(而非 false),讓呼叫方得以區分
|
|
27
|
+
* 「檔案缺少」與「檔案存在但沒有 shebang」兩種不同的失敗原因。
|
|
28
|
+
*
|
|
29
|
+
* Check whether a single file exists and contains a shebang.
|
|
30
|
+
* Returns undefined (not false) when missing, so callers can distinguish
|
|
31
|
+
* "file missing" from "file exists but lacks a shebang".
|
|
32
|
+
*/
|
|
17
33
|
function checkFile(file) {
|
|
18
34
|
if ((0, fs_extra_1.existsSync)(file)) {
|
|
19
35
|
return hasShebang((0, fs_extra_1.readFileSync)(file));
|
|
20
36
|
}
|
|
21
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* 依 package.json 的 bin 欄位逐檔檢查 shebang,
|
|
40
|
+
* 並以 reduce 累積成固定的明細結構(而非僅回傳布林),
|
|
41
|
+
* 以便 CLI 能對每一支可執行檔顯示檔案路徑與檢查結果。
|
|
42
|
+
*
|
|
43
|
+
* Check every bin entry from package.json for a shebang, accumulating a fixed
|
|
44
|
+
* detail structure via reduce (instead of a bare boolean) so the CLI can show
|
|
45
|
+
* the path and result for each executable.
|
|
46
|
+
*
|
|
47
|
+
* @param pkg 已解析的 package.json 物件 / parsed package.json object
|
|
48
|
+
* @param cwd 套件根目錄,用於將 bin 的相對路徑解析為絕對路徑 /
|
|
49
|
+
* package root used to resolve relative bin paths to absolute ones
|
|
50
|
+
*/
|
|
22
51
|
function checkPkgJson(pkg, cwd) {
|
|
23
52
|
var _a;
|
|
53
|
+
/**
|
|
54
|
+
* getPackageBins 可能回傳 undefined(無 bin 欄位),
|
|
55
|
+
* 以 ?? [] 落成空陣列,讓 result 為空即可判定「無 bin 需檢查」。
|
|
56
|
+
*
|
|
57
|
+
* getPackageBins may return undefined (no bin field); coalesce with ?? []
|
|
58
|
+
* so an empty result signals "no bins to check" to the caller.
|
|
59
|
+
*/
|
|
24
60
|
return Object.entries((_a = (0, get_pkg_bin_1.getPackageBins)(pkg)) !== null && _a !== void 0 ? _a : [])
|
|
25
61
|
.reduce((a, row) => {
|
|
26
62
|
let filename = row[1];
|
package/lib/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["core.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["core.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAeH,gCAGC;AAWD,8BAMC;AAeD,oCA6BC;AA7ED,uCAAoD;AACpD,gDAAkD;AAElD,wDAAwD;AACxD,mCAA8B;AAE9B;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,GAAoB;;IAE9C,OAAO,CAAA,MAAA,MAAA,IAAA,sBAAY,EAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,0CAAE,MAAM,0CAAE,MAAM,IAAG,CAAC,CAAA;AACxD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAC,IAAY;IAErC,IAAI,IAAA,qBAAU,EAAC,IAAI,CAAC,EACpB,CAAC;QACA,OAAO,UAAU,CAAC,IAAA,uBAAY,EAAC,IAAI,CAAC,CAAC,CAAA;IACtC,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,YAAY,CAAC,GAAiB,EAAE,GAAW;;IAE1D;;;;;;OAMG;IACH,OAAO,MAAM,CAAC,OAAO,CAAC,MAAA,IAAA,4BAAc,EAAC,GAAG,CAAC,mCAAI,EAAE,CAAC;SAC9C,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QAGlB,IAAI,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,IAAI,GAAG,IAAA,aAAI,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC/B,IAAI,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;QAE1B,CAAC,CAAC,IAAI,CAAC;YACN,IAAI;YACJ,QAAQ;YACR,UAAU,EAAE,IAAI;SAChB,CAAC,CAAA;QAEF,OAAO,CAAC,CAAA;IACT,CAAC,EAAE,EAIA,CAAC,CAAA;AACN,CAAC","sourcesContent":["/**\n * Created by user on 2020/6/13.\n */\n\nimport { existsSync, readFileSync } from 'fs-extra';\nimport { matchShebang } from '@yarn-tool/shebang';\nimport { IPackageJson } from '@ts-type/package-dts';\nimport { getPackageBins } from '@yarn-tool/get-pkg-bin';\nimport { join } from 'upath2';\n\n/**\n * 判斷任意內容是否含 shebang(`#!`)開頭。\n * 回傳布林值而非直接依賴 truthy,是為了讓「無 shebang」與「比對失敗」都明確視為 false。\n *\n * Detect whether arbitrary content starts with a shebang (`#!`).\n * Returning an explicit boolean keeps \"no shebang\" and \"match failure\" both false.\n */\nexport function hasShebang(buf: Buffer | string)\n{\n\treturn matchShebang(buf.toString())?.script?.length > 0\n}\n\n/**\n * 檢查單一檔案是否存在且含 shebang。\n * 檔案不存在時回傳 undefined(而非 false),讓呼叫方得以區分\n * 「檔案缺少」與「檔案存在但沒有 shebang」兩種不同的失敗原因。\n *\n * Check whether a single file exists and contains a shebang.\n * Returns undefined (not false) when missing, so callers can distinguish\n * \"file missing\" from \"file exists but lacks a shebang\".\n */\nexport function checkFile(file: string)\n{\n\tif (existsSync(file))\n\t{\n\t\treturn hasShebang(readFileSync(file))\n\t}\n}\n\n/**\n * 依 package.json 的 bin 欄位逐檔檢查 shebang,\n * 並以 reduce 累積成固定的明細結構(而非僅回傳布林),\n * 以便 CLI 能對每一支可執行檔顯示檔案路徑與檢查結果。\n *\n * Check every bin entry from package.json for a shebang, accumulating a fixed\n * detail structure via reduce (instead of a bare boolean) so the CLI can show\n * the path and result for each executable.\n *\n * @param pkg 已解析的 package.json 物件 / parsed package.json object\n * @param cwd 套件根目錄,用於將 bin 的相對路徑解析為絕對路徑 /\n * package root used to resolve relative bin paths to absolute ones\n */\nexport function checkPkgJson(pkg: IPackageJson, cwd: string)\n{\n\t/**\n\t * getPackageBins 可能回傳 undefined(無 bin 欄位),\n\t * 以 ?? [] 落成空陣列,讓 result 為空即可判定「無 bin 需檢查」。\n\t *\n\t * getPackageBins may return undefined (no bin field); coalesce with ?? []\n\t * so an empty result signals \"no bins to check\" to the caller.\n\t */\n\treturn Object.entries(getPackageBins(pkg) ?? [])\n\t\t.reduce((a, row) =>\n\t\t{\n\n\t\t\tlet filename = row[1];\n\t\t\tlet file = join(cwd, filename);\n\t\t\tlet bool = checkFile(file)\n\n\t\t\ta.push({\n\t\t\t\tfile,\n\t\t\t\tfilename,\n\t\t\t\thasShebang: bool,\n\t\t\t})\n\n\t\t\treturn a\n\t\t}, [] as {\n\t\t\tfile: string,\n\t\t\tfilename: string,\n\t\t\thasShebang: boolean,\n\t\t}[])\n}\n\n"]}
|
package/lib/pkg.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by user on 2020/6/13.
|
|
3
3
|
*/
|
|
4
|
+
/**
|
|
5
|
+
* 讀取指定目錄的 package.json,並檢查其所有 bin 檔案是否含 shebang。
|
|
6
|
+
* 預設使用 process.cwd(),讓 CLI 與 API 在未指定路徑時行為一致。
|
|
7
|
+
*
|
|
8
|
+
* Read the package.json of a directory and check whether all of its bin files
|
|
9
|
+
* contain a shebang. Defaults to process.cwd() so CLI and API behave the same
|
|
10
|
+
* when no path is given.
|
|
11
|
+
*
|
|
12
|
+
* @param pkgDir 套件根目錄 / package root directory
|
|
13
|
+
*/
|
|
4
14
|
export declare function checkPkgDir(pkgDir?: string): {
|
|
5
15
|
name: string;
|
|
6
16
|
pkg: import("@ts-type/package-dts").IPackageJson<unknown>;
|
package/lib/pkg.js
CHANGED
|
@@ -7,6 +7,16 @@ exports.checkPkgDir = checkPkgDir;
|
|
|
7
7
|
const package_dts_1 = require("@ts-type/package-dts");
|
|
8
8
|
const upath2_1 = require("upath2");
|
|
9
9
|
const core_1 = require("./core");
|
|
10
|
+
/**
|
|
11
|
+
* 讀取指定目錄的 package.json,並檢查其所有 bin 檔案是否含 shebang。
|
|
12
|
+
* 預設使用 process.cwd(),讓 CLI 與 API 在未指定路徑時行為一致。
|
|
13
|
+
*
|
|
14
|
+
* Read the package.json of a directory and check whether all of its bin files
|
|
15
|
+
* contain a shebang. Defaults to process.cwd() so CLI and API behave the same
|
|
16
|
+
* when no path is given.
|
|
17
|
+
*
|
|
18
|
+
* @param pkgDir 套件根目錄 / package root directory
|
|
19
|
+
*/
|
|
10
20
|
function checkPkgDir(pkgDir = process.cwd()) {
|
|
11
21
|
const pkg = (0, package_dts_1.readPackageJson)((0, upath2_1.join)(pkgDir, 'package.json'));
|
|
12
22
|
const result = (0, core_1.checkPkgJson)(pkg, pkgDir);
|
|
@@ -15,6 +25,12 @@ function checkPkgDir(pkgDir = process.cwd()) {
|
|
|
15
25
|
pkg,
|
|
16
26
|
pkgDir,
|
|
17
27
|
result,
|
|
28
|
+
// valid 只描述「已存在的 bin 是否皆通過」;
|
|
29
|
+
// 沒有任何 bin 時 result 為空、every 回傳 true,
|
|
30
|
+
// 由呼叫方以 result.length 決定是否顯示為 none。
|
|
31
|
+
// valid only describes whether existing bins all pass; with no bins the
|
|
32
|
+
// result is empty and every() is true, so callers show "none" based on
|
|
33
|
+
// result.length instead.
|
|
18
34
|
valid: result.every(r => r.hasShebang),
|
|
19
35
|
};
|
|
20
36
|
}
|
package/lib/pkg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkg.js","sourceRoot":"","sources":["pkg.ts"],"names":[],"mappings":";AAAA;;GAEG;;
|
|
1
|
+
{"version":3,"file":"pkg.js","sourceRoot":"","sources":["pkg.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAgBH,kCAmBC;AAjCD,sDAAuD;AACvD,mCAA8B;AAC9B,iCAAsC;AAEtC;;;;;;;;;GASG;AACH,SAAgB,WAAW,CAAC,SAAiB,OAAO,CAAC,GAAG,EAAE;IAEzD,MAAM,GAAG,GAAG,IAAA,6BAAe,EAAC,IAAA,aAAI,EAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IAE1D,MAAM,MAAM,GAAG,IAAA,mBAAY,EAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAExC,OAAO;QACN,IAAI,EAAE,GAAG,CAAC,IAAc;QACxB,GAAG;QACH,MAAM;QACN,MAAM;QACN,6BAA6B;QAC7B,sCAAsC;QACtC,oCAAoC;QACpC,wEAAwE;QACxE,uEAAuE;QACvE,yBAAyB;QACzB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;KACtC,CAAA;AACF,CAAC","sourcesContent":["/**\n * Created by user on 2020/6/13.\n */\n\nimport { readPackageJson } from '@ts-type/package-dts';\nimport { join } from 'upath2';\nimport { checkPkgJson } from './core';\n\n/**\n * 讀取指定目錄的 package.json,並檢查其所有 bin 檔案是否含 shebang。\n * 預設使用 process.cwd(),讓 CLI 與 API 在未指定路徑時行為一致。\n *\n * Read the package.json of a directory and check whether all of its bin files\n * contain a shebang. Defaults to process.cwd() so CLI and API behave the same\n * when no path is given.\n *\n * @param pkgDir 套件根目錄 / package root directory\n */\nexport function checkPkgDir(pkgDir: string = process.cwd())\n{\n\tconst pkg = readPackageJson(join(pkgDir, 'package.json'));\n\n\tconst result = checkPkgJson(pkg, pkgDir)\n\n\treturn {\n\t\tname: pkg.name as string,\n\t\tpkg,\n\t\tpkgDir,\n\t\tresult,\n\t\t// valid 只描述「已存在的 bin 是否皆通過」;\n\t\t// 沒有任何 bin 時 result 為空、every 回傳 true,\n\t\t// 由呼叫方以 result.length 決定是否顯示為 none。\n\t\t// valid only describes whether existing bins all pass; with no bins the\n\t\t// result is empty and every() is true, so callers show \"none\" based on\n\t\t// result.length instead.\n\t\tvalid: result.every(r => r.hasShebang),\n\t}\n}\n"]}
|
package/lib/ws.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { IPackageJson } from '@ts-type/package-dts';
|
|
2
|
+
/**
|
|
3
|
+
* 列出 workspace 內所有套件並逐一執行單套件檢查。
|
|
4
|
+
* 回傳完整陣列而非只回傳失敗者,讓 CLI 能同時呈現通過與失敗的套件。
|
|
5
|
+
*
|
|
6
|
+
* List every package in the workspace and run the single-package check on each.
|
|
7
|
+
* Returns the full array (not only failures) so the CLI can render both passing
|
|
8
|
+
* and failing packages.
|
|
9
|
+
*
|
|
10
|
+
* @param cwd workspace 根目錄 / workspace root directory
|
|
11
|
+
*/
|
|
2
12
|
export declare function checkWorkspaces(cwd?: string): {
|
|
3
13
|
name: string;
|
|
4
14
|
pkg: IPackageJson<unknown>;
|
package/lib/ws.js
CHANGED
|
@@ -3,6 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.checkWorkspaces = checkWorkspaces;
|
|
4
4
|
const listpkg_1 = require("ws-pkg-list/lib/listpkg");
|
|
5
5
|
const pkg_1 = require("./pkg");
|
|
6
|
+
/**
|
|
7
|
+
* 列出 workspace 內所有套件並逐一執行單套件檢查。
|
|
8
|
+
* 回傳完整陣列而非只回傳失敗者,讓 CLI 能同時呈現通過與失敗的套件。
|
|
9
|
+
*
|
|
10
|
+
* List every package in the workspace and run the single-package check on each.
|
|
11
|
+
* Returns the full array (not only failures) so the CLI can render both passing
|
|
12
|
+
* and failing packages.
|
|
13
|
+
*
|
|
14
|
+
* @param cwd workspace 根目錄 / workspace root directory
|
|
15
|
+
*/
|
|
6
16
|
function checkWorkspaces(cwd = process.cwd()) {
|
|
7
17
|
return (0, listpkg_1.workspacesPackagesList)(cwd)
|
|
8
18
|
.map(cwd => (0, pkg_1.checkPkgDir)(cwd));
|
package/lib/ws.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.js","sourceRoot":"","sources":["ws.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"ws.js","sourceRoot":"","sources":["ws.ts"],"names":[],"mappings":";;AAcA,0CAKC;AAnBD,qDAAiE;AACjE,+BAAoC;AAGpC;;;;;;;;;GASG;AACH,SAAgB,eAAe,CAAC,MAAc,OAAO,CAAC,GAAG,EAAE;IAE1D,OAAO,IAAA,gCAAsB,EAAC,GAAG,CAAC;SAChC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAA,iBAAW,EAAC,GAAG,CAAC,CAAC,CAC7B;AACF,CAAC","sourcesContent":["import { workspacesPackagesList } from 'ws-pkg-list/lib/listpkg';\nimport { checkPkgDir } from './pkg';\nimport { IPackageJson } from '@ts-type/package-dts';\n\n/**\n * 列出 workspace 內所有套件並逐一執行單套件檢查。\n * 回傳完整陣列而非只回傳失敗者,讓 CLI 能同時呈現通過與失敗的套件。\n *\n * List every package in the workspace and run the single-package check on each.\n * Returns the full array (not only failures) so the CLI can render both passing\n * and failing packages.\n *\n * @param cwd workspace 根目錄 / workspace root directory\n */\nexport function checkWorkspaces(cwd: string = process.cwd())\n{\n\treturn workspacesPackagesList(cwd)\n\t\t.map(cwd => checkPkgDir(cwd))\n\t;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/check-pkg-bin",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.12",
|
|
4
4
|
"description": "check pkg bin has shebang",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"shebang",
|
|
7
|
+
"bin",
|
|
8
|
+
"check",
|
|
9
|
+
"package.json",
|
|
10
|
+
"workspaces"
|
|
11
|
+
],
|
|
6
12
|
"homepage": "https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/@yarn-tool/check-pkg-bin#readme",
|
|
7
13
|
"bugs": {
|
|
8
14
|
"url": "https://github.com/bluelovers/ws-yarn-workspaces/issues"
|
|
@@ -23,45 +29,40 @@
|
|
|
23
29
|
"test": "test"
|
|
24
30
|
},
|
|
25
31
|
"scripts": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"test": "node --run test:jest --",
|
|
32
|
+
"bin:self": "tsx bin/check-pkg-bin.ts --workspaces",
|
|
33
|
+
"test": "node --run test:node",
|
|
29
34
|
"test:jest": "jest --coverage",
|
|
30
35
|
"test:jest:coverage": "pnpm run test:jest -- --coverage",
|
|
31
36
|
"test:jest:snapshot": "pnpm run test:jest -- -u",
|
|
32
|
-
"test:mocha": "
|
|
37
|
+
"test:mocha": "ynpx mocha --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
38
|
+
"test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
|
|
33
39
|
"test:snapshot": "pnpm run test -u",
|
|
40
|
+
"test:tsc": "tsc --noEmit & echo typescript check done",
|
|
34
41
|
"test:tsd": "ynpx tsd",
|
|
35
42
|
"npm:publish": "npm publish",
|
|
36
43
|
"npm:publish:lerna": "lerna publish --yes --bump patch",
|
|
37
44
|
"preversion": "pnpm run test",
|
|
38
|
-
"
|
|
39
|
-
"prepublishOnly_": "pnpm run ncu && pnpm run sort-package-json && pnpm run test",
|
|
40
|
-
"postpublish_": "git commit -m \"chore(release): publish & git push & echo postpublish\" .",
|
|
41
|
-
"ncu": "npx yarn-tool ncu -u",
|
|
42
|
-
"sort-package-json": "npx yarn-tool sort",
|
|
43
|
-
"tsc:default": "tsc -p tsconfig.json",
|
|
44
|
-
"tsc:esm": "tsc -p tsconfig.esm.json",
|
|
45
|
-
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
45
|
+
"sort-package-json": "npx yarn-tool sort"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@bluelovers/string-natural-compare": "^2.0.
|
|
49
|
-
"@ts-type/package-dts": "^3.0.
|
|
50
|
-
"@yarn-tool/find-root": "^2.0.
|
|
51
|
-
"@yarn-tool/get-pkg-bin": "^3.0.
|
|
52
|
-
"@yarn-tool/shebang": "^1.0.
|
|
53
|
-
"@yarn-tool/table": "^2.0.
|
|
48
|
+
"@bluelovers/string-natural-compare": "^2.0.17",
|
|
49
|
+
"@ts-type/package-dts": "^3.0.14",
|
|
50
|
+
"@yarn-tool/find-root": "^2.0.26",
|
|
51
|
+
"@yarn-tool/get-pkg-bin": "^3.0.12",
|
|
52
|
+
"@yarn-tool/shebang": "^1.0.25",
|
|
53
|
+
"@yarn-tool/table": "^2.0.23",
|
|
54
54
|
"cli-table3": "^0.6.5",
|
|
55
55
|
"debug-color2": "^1.3.2",
|
|
56
|
-
"fs-extra": "^11.4.
|
|
56
|
+
"fs-extra": "^11.4.1",
|
|
57
57
|
"pkg-dir": "<6 >=5",
|
|
58
|
+
"string-natural-compare2": "^3.0.1",
|
|
58
59
|
"tslib": ">=2.8.1",
|
|
59
60
|
"upath2": "^3.1.25",
|
|
60
|
-
"ws-pkg-list": "^3.0.
|
|
61
|
+
"ws-pkg-list": "^3.0.12",
|
|
61
62
|
"yargs": "<18 >=17.7.2"
|
|
62
63
|
},
|
|
63
64
|
"publishConfig": {
|
|
64
65
|
"access": "public"
|
|
65
66
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "471c63ee11851f0ac3487f23d1c472936f99b460"
|
|
67
68
|
}
|