@yarn-tool/publish-retry 2.0.10 → 2.0.11
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 +26 -0
- package/README.md +72 -3
- package/index.d.ts +11 -0
- package/index.js +53 -0
- package/index.js.map +1 -1
- package/package.json +12 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,32 @@
|
|
|
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
|
+
## [2.0.11](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/publish-retry@2.0.10...@yarn-tool/publish-retry@2.0.11) (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
|
+
* **workspace:** 更新測試指令路徑與新增工作區搜尋選項 ([a80039d](https://github.com/bluelovers/ws-yarn-workspaces/commit/a80039dd8c691e047466966ffc8f8a4e2e31c03f))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### 🔖 Miscellaneous
|
|
27
|
+
|
|
28
|
+
* . ([e5788f8](https://github.com/bluelovers/ws-yarn-workspaces/commit/e5788f84551b870490a96d0a5d67d8d542481373))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
6
32
|
## [2.0.10](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/publish-retry@2.0.9...@yarn-tool/publish-retry@2.0.10) (2026-09-06)
|
|
7
33
|
|
|
8
34
|
|
package/README.md
CHANGED
|
@@ -1,12 +1,81 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yarn-tool/publish-retry
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
publish un-published workspace packages, skipping versions already on the npm registry
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
依序發布 (Publish) monorepo 中尚未發布到 npm registry (倉庫) 的套件,已發布的版本會自動略過,適合中斷後重跑。
|
|
6
|
+
|
|
7
|
+
## 功能特色 (Features)
|
|
8
|
+
|
|
9
|
+
- **略過已發布**:透過 `@yarn-tool/is-published` 查詢 registry,`name@version` 已存在時不重複發布
|
|
10
|
+
- **依序執行 (Serial)**:以 `mapSeries` 逐一套件發布,避免 registry 速率限制 (Rate Limit)
|
|
11
|
+
- **沿用 npm CLI**:直接呼叫 `npm publish` 並繼承標準輸入輸出 (stdio),保留 npm 原本的認證與輸出
|
|
12
|
+
- **發布間隔**:每次發布後延遲 1 秒,降低觸發 registry 限流的風險
|
|
13
|
+
|
|
14
|
+
## 安裝 (Installation)
|
|
6
15
|
|
|
7
16
|
```bash
|
|
17
|
+
# 使用 yarn / Using yarn
|
|
8
18
|
yarn add @yarn-tool/publish-retry
|
|
19
|
+
|
|
20
|
+
# 使用 yarn-tool / Using yarn-tool
|
|
9
21
|
yarn-tool add @yarn-tool/publish-retry
|
|
22
|
+
# yt 是 yarn-tool 的別名 / yt is an alias for yarn-tool
|
|
10
23
|
yt add @yarn-tool/publish-retry
|
|
24
|
+
|
|
25
|
+
# 使用 pnpm / Using pnpm
|
|
26
|
+
pnpm add @yarn-tool/publish-retry
|
|
27
|
+
|
|
28
|
+
# 使用 npm / Using npm
|
|
29
|
+
npm install @yarn-tool/publish-retry
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 使用方式 (Usage)
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { publishRetry } from '@yarn-tool/publish-retry';
|
|
36
|
+
|
|
37
|
+
// 自動尋找 workspaces 並發布未發布的套件 / Find workspaces and publish unpublished packages
|
|
38
|
+
await publishRetry(process.cwd());
|
|
39
|
+
|
|
40
|
+
// 指定專案根目錄 / Specify the project root
|
|
41
|
+
await publishRetry('/path/to/monorepo');
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import publishRetry from '@yarn-tool/publish-retry';
|
|
46
|
+
|
|
47
|
+
// 預設匯出與具名匯出相同 / Default export is the same as the named export
|
|
48
|
+
await publishRetry();
|
|
11
49
|
```
|
|
12
50
|
|
|
51
|
+
## API 文件 (API Documentation)
|
|
52
|
+
|
|
53
|
+
### `publishRetry(cwd?: string): Promise<void>`
|
|
54
|
+
|
|
55
|
+
依序處理 `cwd` 底下所有 workspace 套件:
|
|
56
|
+
|
|
57
|
+
1. 以 `wsPkgListable(cwd)` 列出所有 workspace 套件
|
|
58
|
+
2. 以 `isPublishedByPackageJSON(row)` 查詢該 `name@version` 是否已發布
|
|
59
|
+
3. 未發布時執行 `npm publish`(於該套件目錄、`stdio: 'inherit'`)
|
|
60
|
+
4. 無論成功與否都延遲 1 秒後處理下一個套件
|
|
61
|
+
|
|
62
|
+
**參數:**
|
|
63
|
+
|
|
64
|
+
- `cwd` — 專案根目錄;省略時由 `wsPkgListable` 決定預設搜尋位置
|
|
65
|
+
|
|
66
|
+
**回傳:** `Promise<void>`,於所有套件處理完成後 resolve。
|
|
67
|
+
|
|
68
|
+
**注意:**
|
|
69
|
+
|
|
70
|
+
- 傳回值不含各套件的發布結果;發布狀態請以終端輸出(黃底紅字提示)判讀
|
|
71
|
+
- `npm publish` 的失敗(如權限不足)不會中斷後續套件的檢查
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
本套件無自有設定項;registry 網址、認證 (Auth) 等沿用 `npm` CLI 與專案 `.npmrc` 設定。
|
|
76
|
+
|
|
77
|
+
查詢已發布狀態的選項請見 [`@yarn-tool/is-published`](../is-published/README.md)。
|
|
78
|
+
|
|
79
|
+
## 版本 (Version)
|
|
80
|
+
|
|
81
|
+
當前版本:2.0.10
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 發布 cwd 底下所有尚未發布的 workspace 套件
|
|
3
|
+
* Publish all unpublished workspace packages under cwd
|
|
4
|
+
*
|
|
5
|
+
* @param cwd - 專案根目錄;省略時交由 wsPkgListable 決定 / Project root; omitted leaves it to wsPkgListable
|
|
6
|
+
* @returns 全部套件處理完成後 resolve / Resolves once every package has been processed
|
|
7
|
+
*/
|
|
1
8
|
export declare function publishRetry(cwd?: string): Promise<void[]>;
|
|
9
|
+
/**
|
|
10
|
+
* 預設匯出:此套件只有單一主要操作,具名與預設匯出等價
|
|
11
|
+
* Default export: the package has one main operation, so both exports are equivalent
|
|
12
|
+
*/
|
|
2
13
|
export default publishRetry;
|
package/index.js
CHANGED
|
@@ -2,28 +2,81 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.publishRetry = publishRetry;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* 依序發布尚未發布的 workspace 套件
|
|
7
|
+
* Serially publish workspace packages that are not yet published
|
|
8
|
+
*
|
|
9
|
+
* 此模組設計為「可安全重跑」:已發布的版本會被查出並略過,
|
|
10
|
+
* 因此中斷後再次執行即可續行,不需人工辨識失敗點。
|
|
11
|
+
*
|
|
12
|
+
* Designed to be safely re-runnable: already-published versions are detected
|
|
13
|
+
* and skipped, so rerunning after an interruption continues where it left off
|
|
14
|
+
* without manual triage.
|
|
15
|
+
*/
|
|
5
16
|
const ws_pkg_list_1 = require("ws-pkg-list");
|
|
6
17
|
const bluebird_1 = tslib_1.__importDefault(require("bluebird"));
|
|
7
18
|
const is_published_1 = require("@yarn-tool/is-published");
|
|
8
19
|
const cross_spawn_extra_1 = require("cross-spawn-extra");
|
|
9
20
|
const logger_1 = require("debug-color2/logger");
|
|
21
|
+
/**
|
|
22
|
+
* 發布 cwd 底下所有尚未發布的 workspace 套件
|
|
23
|
+
* Publish all unpublished workspace packages under cwd
|
|
24
|
+
*
|
|
25
|
+
* @param cwd - 專案根目錄;省略時交由 wsPkgListable 決定 / Project root; omitted leaves it to wsPkgListable
|
|
26
|
+
* @returns 全部套件處理完成後 resolve / Resolves once every package has been processed
|
|
27
|
+
*/
|
|
10
28
|
async function publishRetry(cwd) {
|
|
11
29
|
return bluebird_1.default.resolve((0, ws_pkg_list_1.wsPkgListable)(cwd))
|
|
30
|
+
/**
|
|
31
|
+
* mapSeries 而非 map:registry 對短時間大量請求會限流,
|
|
32
|
+
* 逐一發布可避免並行 publish 互相觸發 429
|
|
33
|
+
*
|
|
34
|
+
* mapSeries rather than map: the registry rate-limits bursts, and
|
|
35
|
+
* publishing one at a time avoids parallel publishes triggering 429s
|
|
36
|
+
*/
|
|
12
37
|
.mapSeries(async (row) => {
|
|
13
38
|
const { location: cwd } = row;
|
|
14
39
|
let bool = await (0, is_published_1.isPublishedByPackageJSON)(row);
|
|
40
|
+
/**
|
|
41
|
+
* bool 為 null(套件不存在)與 false(版本不存在)都視為需發布;
|
|
42
|
+
* 只有 true(完全已發布)才跳過
|
|
43
|
+
*
|
|
44
|
+
* Both null (package missing) and false (version missing) count as
|
|
45
|
+
* needing publish; only true (fully published) is skipped
|
|
46
|
+
*/
|
|
15
47
|
if (!bool) {
|
|
16
48
|
logger_1.consoleLogger.bgYellow.red.info(`try to publish ${row.name}@${row.version}`);
|
|
49
|
+
/**
|
|
50
|
+
* 呼叫 npm CLI 而非以程式發送 HTTP:
|
|
51
|
+
* 認證、OTP、.npmrc 解析皆沿用 npm 原生行為,不需重新實作
|
|
52
|
+
*
|
|
53
|
+
* Shell out to the npm CLI instead of sending HTTP directly:
|
|
54
|
+
* auth, OTP and .npmrc handling reuse npm's native behavior
|
|
55
|
+
* rather than being reimplemented
|
|
56
|
+
*/
|
|
17
57
|
const cp = await (0, cross_spawn_extra_1.async)('npm', [
|
|
18
58
|
'publish',
|
|
19
59
|
], {
|
|
20
60
|
cwd,
|
|
61
|
+
/** 繼承父程序輸出,讓使用者看到 npm 原本的進度與錯誤 / Inherit parent output so users see npm's own progress and errors */
|
|
21
62
|
stdio: 'inherit',
|
|
22
63
|
});
|
|
23
64
|
logger_1.consoleLogger.log(cp.status, cp.error);
|
|
65
|
+
/**
|
|
66
|
+
* 發布後固定延遲 1 秒:npm registry 對連續 publish 有速率限制,
|
|
67
|
+
* 等待可降低觸發 429 的機率
|
|
68
|
+
*
|
|
69
|
+
* Fixed 1-second delay after publishing: the npm registry
|
|
70
|
+
* rate-limits rapid publishes, and waiting lowers the chance
|
|
71
|
+
* of hitting a 429
|
|
72
|
+
*/
|
|
24
73
|
await bluebird_1.default.delay(1000);
|
|
25
74
|
}
|
|
26
75
|
});
|
|
27
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* 預設匯出:此套件只有單一主要操作,具名與預設匯出等價
|
|
79
|
+
* Default export: the package has one main operation, so both exports are equivalent
|
|
80
|
+
*/
|
|
28
81
|
exports.default = publishRetry;
|
|
29
82
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAwBA,oCAyDC;;AAjFD;;;;;;;;;;GAUG;AACH,6CAA4C;AAC5C,gEAAgC;AAChC,0DAAmE;AACnE,yDAAwD;AACxD,gDAA+D;AAE/D;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAAC,GAAY;IAE9C,OAAO,kBAAQ,CAAC,OAAO,CAAC,IAAA,2BAAa,EAAC,GAAG,CAAC,CAAC;QAC1C;;;;;;WAMG;SACF,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACxB,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;QAE9B,IAAI,IAAI,GAAG,MAAM,IAAA,uCAAwB,EAAC,GAAG,CAAC,CAAC;QAE/C;;;;;;WAMG;QACH,IAAI,CAAC,IAAI,EACT,CAAC;YACA,sBAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YAEvE;;;;;;;eAOG;YACH,MAAM,EAAE,GAAG,MAAM,IAAA,yBAAU,EAAC,KAAK,EAAE;gBAClC,SAAS;aACT,EAAE;gBACF,GAAG;gBACH,qGAAqG;gBACrG,KAAK,EAAE,SAAS;aAChB,CAAC,CAAC;YAEH,sBAAO,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;YAEjC;;;;;;;eAOG;YACH,MAAM,kBAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;IAEF,CAAC,CAAC,CACF;AACF,CAAC;AAED;;;GAGG;AACH,kBAAe,YAAY,CAAA","sourcesContent":["/**\n * 依序發布尚未發布的 workspace 套件\n * Serially publish workspace packages that are not yet published\n *\n * 此模組設計為「可安全重跑」:已發布的版本會被查出並略過,\n * 因此中斷後再次執行即可續行,不需人工辨識失敗點。\n *\n * Designed to be safely re-runnable: already-published versions are detected\n * and skipped, so rerunning after an interruption continues where it left off\n * without manual triage.\n */\nimport { wsPkgListable } from 'ws-pkg-list';\nimport Bluebird from 'bluebird';\nimport { isPublishedByPackageJSON } from '@yarn-tool/is-published';\nimport { async as crossSpawn } from 'cross-spawn-extra';\nimport { consoleLogger as console } from 'debug-color2/logger';\n\n/**\n * 發布 cwd 底下所有尚未發布的 workspace 套件\n * Publish all unpublished workspace packages under cwd\n *\n * @param cwd - 專案根目錄;省略時交由 wsPkgListable 決定 / Project root; omitted leaves it to wsPkgListable\n * @returns 全部套件處理完成後 resolve / Resolves once every package has been processed\n */\nexport async function publishRetry(cwd?: string)\n{\n\treturn Bluebird.resolve(wsPkgListable(cwd))\n\t\t/**\n\t\t * mapSeries 而非 map:registry 對短時間大量請求會限流,\n\t\t * 逐一發布可避免並行 publish 互相觸發 429\n\t\t *\n\t\t * mapSeries rather than map: the registry rate-limits bursts, and\n\t\t * publishing one at a time avoids parallel publishes triggering 429s\n\t\t */\n\t\t.mapSeries(async (row) => {\n\t\t\tconst { location: cwd } = row;\n\n\t\t\tlet bool = await isPublishedByPackageJSON(row);\n\n\t\t\t/**\n\t\t\t * bool 為 null(套件不存在)與 false(版本不存在)都視為需發布;\n\t\t\t * 只有 true(完全已發布)才跳過\n\t\t\t *\n\t\t\t * Both null (package missing) and false (version missing) count as\n\t\t\t * needing publish; only true (fully published) is skipped\n\t\t\t */\n\t\t\tif (!bool)\n\t\t\t{\n\t\t\t\tconsole.bgYellow.red.info(`try to publish ${row.name}@${row.version}`);\n\n\t\t\t\t/**\n\t\t\t\t * 呼叫 npm CLI 而非以程式發送 HTTP:\n\t\t\t\t * 認證、OTP、.npmrc 解析皆沿用 npm 原生行為,不需重新實作\n\t\t\t\t *\n\t\t\t\t * Shell out to the npm CLI instead of sending HTTP directly:\n\t\t\t\t * auth, OTP and .npmrc handling reuse npm's native behavior\n\t\t\t\t * rather than being reimplemented\n\t\t\t\t */\n\t\t\t\tconst cp = await crossSpawn('npm', [\n\t\t\t\t\t'publish',\n\t\t\t\t], {\n\t\t\t\t\tcwd,\n\t\t\t\t\t/** 繼承父程序輸出,讓使用者看到 npm 原本的進度與錯誤 / Inherit parent output so users see npm's own progress and errors */\n\t\t\t\t\tstdio: 'inherit',\n\t\t\t\t});\n\n\t\t\t\tconsole.log(cp.status, cp.error);\n\n\t\t\t\t/**\n\t\t\t\t * 發布後固定延遲 1 秒:npm registry 對連續 publish 有速率限制,\n\t\t\t\t * 等待可降低觸發 429 的機率\n\t\t\t\t *\n\t\t\t\t * Fixed 1-second delay after publishing: the npm registry\n\t\t\t\t * rate-limits rapid publishes, and waiting lowers the chance\n\t\t\t\t * of hitting a 429\n\t\t\t\t */\n\t\t\t\tawait Bluebird.delay(1000);\n\t\t\t}\n\n\t\t})\n\t;\n}\n\n/**\n * 預設匯出:此套件只有單一主要操作,具名與預設匯出等價\n * Default export: the package has one main operation, so both exports are equivalent\n */\nexport default publishRetry\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/publish-retry",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "2.0.11",
|
|
4
|
+
"description": "publish un-published workspace packages, skipping versions already on the npm registry",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"publish",
|
|
7
|
+
"publish-retry",
|
|
8
|
+
"npm-publish",
|
|
9
|
+
"skip-published",
|
|
6
10
|
"yarn",
|
|
7
11
|
"yarn-tool",
|
|
8
12
|
"npm",
|
|
@@ -38,12 +42,14 @@
|
|
|
38
42
|
"lint": "pnpm run lint:eslint",
|
|
39
43
|
"lint:eslint": "ynpx eslint --ext .ts,.tsx,.mts,.cts ./",
|
|
40
44
|
"pretest": "echo pretest",
|
|
41
|
-
"test": "
|
|
45
|
+
"test": "node --run test:node",
|
|
42
46
|
"test:jest": "jest --passWithNoTests",
|
|
43
47
|
"test:jest:coverage": "pnpm run test:jest -- --coverage",
|
|
44
48
|
"test:jest:snapshot": "pnpm run test:jest -- -u",
|
|
45
49
|
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
50
|
+
"test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
|
|
46
51
|
"test:snapshot": "pnpm run test -u",
|
|
52
|
+
"test:tsc": "tsc --noEmit & echo typescript check done",
|
|
47
53
|
"test:tsd": "ynpx tsd",
|
|
48
54
|
"test:tsdx": "ynpx @bluelovers/tsdx test --passWithNoTests",
|
|
49
55
|
"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",
|
|
@@ -58,7 +64,6 @@
|
|
|
58
64
|
"version": "echo version",
|
|
59
65
|
"postversion": "echo postversion",
|
|
60
66
|
"prepublish": "echo prepublish",
|
|
61
|
-
"prepare": "echo prepare",
|
|
62
67
|
"prepublishOnly": "echo prepublishOnly",
|
|
63
68
|
"prepublishOnly:update": "pnpm run ncu && pnpm run sort-package-json",
|
|
64
69
|
"prepack": "echo prepack",
|
|
@@ -72,14 +77,14 @@
|
|
|
72
77
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
73
78
|
},
|
|
74
79
|
"dependencies": {
|
|
75
|
-
"@yarn-tool/is-published": "^2.0.
|
|
80
|
+
"@yarn-tool/is-published": "^2.0.11",
|
|
76
81
|
"cross-spawn-extra": "^3.0.3",
|
|
77
82
|
"debug-color2": "^1.3.2",
|
|
78
83
|
"tslib": ">=2.8.1",
|
|
79
|
-
"ws-pkg-list": "^3.0.
|
|
84
|
+
"ws-pkg-list": "^3.0.12"
|
|
80
85
|
},
|
|
81
86
|
"publishConfig": {
|
|
82
87
|
"access": "public"
|
|
83
88
|
},
|
|
84
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "471c63ee11851f0ac3487f23d1c472936f99b460"
|
|
85
90
|
}
|