sync-lockfile 3.0.11 → 3.0.13
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 +37 -0
- package/README.md +84 -28
- package/bin/sync-lockfile.js +21 -0
- package/bin/sync-lockfile.js.map +1 -1
- package/index.d.ts +22 -1
- package/index.js +80 -3
- package/index.js.map +1 -1
- package/package.json +16 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,43 @@
|
|
|
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.13](https://github.com/bluelovers/ws-yarn-workspaces/compare/sync-lockfile@3.0.12...sync-lockfile@3.0.13) (2026-10-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 🔖 Miscellaneous
|
|
11
|
+
|
|
12
|
+
* . ([2ce14fc](https://github.com/bluelovers/ws-yarn-workspaces/commit/2ce14fcf8272584c51c4ba43b87a488f105c2f63))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## [3.0.12](https://github.com/bluelovers/ws-yarn-workspaces/compare/sync-lockfile@3.0.11...sync-lockfile@3.0.12) (2026-10-12)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### 📚 Documentation
|
|
21
|
+
|
|
22
|
+
* add jsdoc ([9cb9b13](https://github.com/bluelovers/ws-yarn-workspaces/commit/9cb9b13eda8c357221ad1b754458aa9916eada22))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### 🛠 Build System
|
|
26
|
+
|
|
27
|
+
* update build ([3186340](https://github.com/bluelovers/ws-yarn-workspaces/commit/3186340758172427cb1e9b8955f6fd677abac625))
|
|
28
|
+
* **deps:** 更新測試腳本與依賴以支援 node:test ([f9c71c7](https://github.com/bluelovers/ws-yarn-workspaces/commit/f9c71c795c792c5c7ed9d613ce7e9c3c726c39d5))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### ♻️ Chores
|
|
32
|
+
|
|
33
|
+
* **deps:** 更新各套件依賴版本 ([569f075](https://github.com/bluelovers/ws-yarn-workspaces/commit/569f0756189cdadf69955d8e388ac0a6a8988056))
|
|
34
|
+
* **workspace:** 更新測試指令路徑與新增工作區搜尋選項 ([a80039d](https://github.com/bluelovers/ws-yarn-workspaces/commit/a80039dd8c691e047466966ffc8f8a4e2e31c03f))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### 🔖 Miscellaneous
|
|
38
|
+
|
|
39
|
+
* . ([e5788f8](https://github.com/bluelovers/ws-yarn-workspaces/commit/e5788f84551b870490a96d0a5d67d8d542481373))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
6
43
|
## [3.0.11](https://github.com/bluelovers/ws-yarn-workspaces/compare/sync-lockfile@3.0.10...sync-lockfile@3.0.11) (2026-09-06)
|
|
7
44
|
|
|
8
45
|
|
package/README.md
CHANGED
|
@@ -1,40 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# sync-lockfile
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
同步 (sync) yarn.lock 到 yarn workspaces 中各個套件的工具:把 workspace 根目錄的 yarn.lock 複製 (copy) 到每個子套件目錄,讓各子套件被單獨安裝時也能取得一致的依賴鎖定結果。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 簡介 (Introduction)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`sync-lockfile` 會從指定的目錄 (cwd) 向上尋找 workspace 根目錄 (workspace root),確認根目錄存在 `yarn.lock` 後,將它逐一複製到所有 workspace 套件,並印出每個複製目標與總耗時。
|
|
8
|
+
|
|
9
|
+
同一個功能可以兩種方式使用:命令列工具 (CLI) `sync-lockfile` 與 Node.js API `syncLockfile()`;兩者共用同一份實作,行為完全一致。
|
|
10
|
+
|
|
11
|
+
## 特色 (Features)
|
|
12
|
+
|
|
13
|
+
- 自動向上尋找 workspace 根目錄,不必自行計算路徑。
|
|
14
|
+
- 一次將根目錄的 `yarn.lock` 複製到所有 workspace 套件。
|
|
15
|
+
- 複製時保留時間戳記 (timestamps)、覆寫 (overwrite) 舊檔,並解引用 (dereference) 符號連結。
|
|
16
|
+
- 提供 CLI 與 API 兩種入口,CLI 可用 `--silent` 靜默輸出。
|
|
17
|
+
- 目標不是 workspace 或缺少 `yarn.lock` 時,可選擇丟出錯誤或回傳 `null` 靜默結束。
|
|
18
|
+
|
|
19
|
+
## 安裝 (Installation)
|
|
20
|
+
|
|
21
|
+
```bash
|
|
8
22
|
yarn add sync-lockfile
|
|
9
23
|
```
|
|
10
24
|
|
|
11
|
-
|
|
25
|
+
以命令列方式執行時可直接使用 `npx`,不必先行安裝:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
12
28
|
npx sync-lockfile
|
|
13
29
|
```
|
|
14
30
|
|
|
31
|
+
## 用法 (Usage)
|
|
32
|
+
|
|
33
|
+
命令列:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# 以目前目錄為起點尋找 workspace 並同步 yarn.lock
|
|
37
|
+
npx sync-lockfile
|
|
38
|
+
|
|
39
|
+
# 指定目標目錄、靜默輸出
|
|
40
|
+
npx sync-lockfile --cwd packages/example --silent
|
|
15
41
|
```
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
copy to... packages
|
|
23
|
-
copy to... packages
|
|
24
|
-
copy to... packages\@yarn-tool\update-notifier
|
|
25
|
-
copy to... packages\cli-table3
|
|
26
|
-
copy to... packages\create-yarn-workspaces
|
|
27
|
-
copy to... packages\cross-spawn-extra
|
|
28
|
-
copy to... packages\find-pkg-ws
|
|
29
|
-
copy to... packages\find-yarn-workspace-root
|
|
30
|
-
copy to... packages\node-callable-instance
|
|
31
|
-
copy to... packages\node-lang-info
|
|
32
|
-
copy to... packages\npm-init2
|
|
33
|
-
copy to... packages\synp
|
|
34
|
-
copy to... packages\workspaces-config
|
|
35
|
-
copy to... packages\ws-pkg-list
|
|
36
|
-
copy to... packages\yarn-cmd-module
|
|
37
|
-
copy to... packages\yarn-list-link
|
|
38
|
-
copy to... packages\yarn-tool
|
|
42
|
+
|
|
43
|
+
輸出範例:
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
workspaces: D:/path/to/ws-yarn-workspaces
|
|
47
|
+
|
|
48
|
+
copy to... packages/@yarn-tool/find-root
|
|
49
|
+
copy to... packages/ws-pkg-list
|
|
39
50
|
copy done: 620.652ms
|
|
40
51
|
```
|
|
52
|
+
|
|
53
|
+
Node.js API:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import syncLockfile from 'sync-lockfile';
|
|
57
|
+
|
|
58
|
+
// 同步成功回傳 true;失敗時依 noThrowError 決定丟錯或回傳 null
|
|
59
|
+
const ok = syncLockfile(process.cwd(), {
|
|
60
|
+
print: true,
|
|
61
|
+
noThrowError: true,
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API 文件 (API Documentation)
|
|
66
|
+
|
|
67
|
+
### `syncLockfile(cwd: string, options?): true | null`
|
|
68
|
+
|
|
69
|
+
由根目錄 (package root) 匯出,同時也是預設匯出 (default export)。以 `cwd` 為起點尋找 workspace 根目錄並複製 `yarn.lock`:
|
|
70
|
+
|
|
71
|
+
| 回傳值 | 情況 |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `true` | 已將 `yarn.lock` 複製到所有 workspace 套件 |
|
|
74
|
+
| `null` | 目標不是 workspace、根目錄缺少 `yarn.lock`,且 `noThrowError` 為 `true` |
|
|
75
|
+
| (丟出 `Error`) | 同上情況但 `noThrowError` 未啟用 |
|
|
76
|
+
|
|
77
|
+
內部相依 `@yarn-tool/find-root`(尋找根目錄)與 `ws-pkg-list`(列出 workspace 套件),因此不需要額外傳入套件清單。
|
|
78
|
+
|
|
79
|
+
## 設定 (Configuration)
|
|
80
|
+
|
|
81
|
+
### API 選項 (`options`)
|
|
82
|
+
|
|
83
|
+
`options` 為第二個引數,型別為 `{ print?: boolean, noThrowError?: boolean }`:
|
|
84
|
+
|
|
85
|
+
| 選項 | 型別 | 預設值 | 說明 |
|
|
86
|
+
| --- | --- | --- | --- |
|
|
87
|
+
| `print` | `boolean` | `undefined`(不列印) | 是否印出 workspace 根目錄、每個複製目標與 `console.time` 計時 |
|
|
88
|
+
| `noThrowError` | `boolean` | `undefined`(會丟錯) | 失敗時改回傳 `null` 而非丟出 `Error` |
|
|
89
|
+
|
|
90
|
+
### CLI 選項
|
|
91
|
+
|
|
92
|
+
| 選項 | 簡寫 | 型別 | 說明 |
|
|
93
|
+
| --- | --- | --- | --- |
|
|
94
|
+
| `--cwd` | `-c` | `string` | 起始目錄,預設為 `process.cwd()`(會正規化 (normalize) 路徑) |
|
|
95
|
+
| `--silent` | — | `boolean` | 不印出複製過程,等同 API 的 `print: false` |
|
|
96
|
+
| `--help` | — | — | 顯示說明;參數失敗時也會自動顯示 |
|
package/bin/sync-lockfile.js
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
/**
|
|
4
|
+
* `sync-lockfile` 命令列入口 (CLI entry):解析參數後呼叫 index 的 syncLockfile。
|
|
5
|
+
*
|
|
6
|
+
* Command-line entry of `sync-lockfile`: parses the arguments and then calls
|
|
7
|
+
* syncLockfile from the package root.
|
|
8
|
+
*
|
|
4
9
|
* Created by user on 2020/1/8.
|
|
5
10
|
*/
|
|
6
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
12
|
const tslib_1 = require("tslib");
|
|
8
13
|
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
9
14
|
const index_1 = tslib_1.__importDefault(require("../index"));
|
|
15
|
+
/**
|
|
16
|
+
* 以 yargs 定義 CLI 介面:`--cwd` 決定起始目錄、`--silent` 關閉列印,
|
|
17
|
+
* 失敗時自動顯示說明 (help) 讓使用者立刻看到可用選項。
|
|
18
|
+
*
|
|
19
|
+
* Defines the CLI surface with yargs: `--cwd` picks the start directory and
|
|
20
|
+
* `--silent` turns off output, while failures auto-show help so users see
|
|
21
|
+
* the available options right away.
|
|
22
|
+
*/
|
|
10
23
|
let argv = yargs_1.default
|
|
11
24
|
.option('cwd', {
|
|
12
25
|
alias: ['c'],
|
|
@@ -20,6 +33,14 @@ let argv = yargs_1.default
|
|
|
20
33
|
.help(true)
|
|
21
34
|
.showHelpOnFail(true)
|
|
22
35
|
.parseSync();
|
|
36
|
+
/**
|
|
37
|
+
* CLI 預設保持輸出(`print: true`),僅在明確指定 `--silent` 時靜默,
|
|
38
|
+
* 讓一般使用者總能看到複製了哪些目標。
|
|
39
|
+
*
|
|
40
|
+
* The CLI prints by default (`print: true`) and stays quiet only when
|
|
41
|
+
* `--silent` is passed, so regular users always see which targets were
|
|
42
|
+
* copied.
|
|
43
|
+
*/
|
|
23
44
|
(0, index_1.default)(argv.cwd, {
|
|
24
45
|
print: !argv.silent,
|
|
25
46
|
});
|
package/bin/sync-lockfile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-lockfile.js","sourceRoot":"","sources":["sync-lockfile.ts"],"names":[],"mappings":";;AAEA
|
|
1
|
+
{"version":3,"file":"sync-lockfile.js","sourceRoot":"","sources":["sync-lockfile.ts"],"names":[],"mappings":";;AAEA;;;;;;;GAOG;;;AAEH,0DAA0B;AAC1B,6DAAoC;AAEpC;;;;;;;GAOG;AACH,IAAI,IAAI,GAAG,eAAK;KACd,MAAM,CAAC,KAAK,EAAE;IACd,KAAK,EAAE,CAAC,GAAG,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;IACtB,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,IAAI;CACZ,CAAC;KACD,MAAM,CAAC,QAAQ,EAAE;IACjB,OAAO,EAAE,IAAI;CACb,CAAC;KACD,IAAI,CAAC,IAAI,CAAC;KACV,cAAc,CAAC,IAAI,CAAC;KACpB,SAAS,EAAE,CACZ;AAED;;;;;;;GAOG;AACH,IAAA,eAAY,EAAC,IAAI,CAAC,GAAG,EAAE;IACtB,KAAK,EAAE,CAAC,IAAI,CAAC,MAAM;CACnB,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n/**\n * `sync-lockfile` 命令列入口 (CLI entry):解析參數後呼叫 index 的 syncLockfile。\n *\n * Command-line entry of `sync-lockfile`: parses the arguments and then calls\n * syncLockfile from the package root.\n *\n * Created by user on 2020/1/8.\n */\n\nimport yargs from 'yargs';\nimport syncLockfile from '../index';\n\n/**\n * 以 yargs 定義 CLI 介面:`--cwd` 決定起始目錄、`--silent` 關閉列印,\n * 失敗時自動顯示說明 (help) 讓使用者立刻看到可用選項。\n *\n * Defines the CLI surface with yargs: `--cwd` picks the start directory and\n * `--silent` turns off output, while failures auto-show help so users see\n * the available options right away.\n */\nlet argv = yargs\n\t.option('cwd', {\n\t\talias: ['c'],\n\t\tdefault: process.cwd(),\n\t\tnormalize: true,\n\t\tstring: true,\n\t})\n\t.option('silent', {\n\t\tboolean: true,\n\t})\n\t.help(true)\n\t.showHelpOnFail(true)\n\t.parseSync()\n;\n\n/**\n * CLI 預設保持輸出(`print: true`),僅在明確指定 `--silent` 時靜默,\n * 讓一般使用者總能看到複製了哪些目標。\n *\n * The CLI prints by default (`print: true`) and stays quiet only when\n * `--silent` is passed, so regular users always see which targets were\n * copied.\n */\nsyncLockfile(argv.cwd, {\n\tprint: !argv.silent,\n});\n"]}
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 以 `cwd` 為起點尋找 workspace 根目錄,並將根目錄的 `yarn.lock` 複製到
|
|
3
|
+
* 每一個 workspace 套件。
|
|
4
|
+
*
|
|
5
|
+
* Locates the workspace root from `cwd` and copies the root `yarn.lock` into
|
|
6
|
+
* every workspace package.
|
|
7
|
+
*
|
|
8
|
+
* @param cwd 起始目錄,向上尋找 workspace 根目錄 / start directory used to
|
|
9
|
+
* search upward for the workspace root
|
|
10
|
+
* @param options 列印與錯誤處理選項 / printing and error handling options
|
|
11
|
+
* @returns 成功同步回傳 `true`;失敗時依 `noThrowError` 回傳 `null` 或丟出
|
|
12
|
+
* `Error` /
|
|
13
|
+
* `true` on success; on failure either `null` or a thrown `Error`,
|
|
14
|
+
* depending on `noThrowError`
|
|
3
15
|
*/
|
|
4
16
|
export declare function syncLockfile(cwd: string, options?: {
|
|
17
|
+
/** 是否印出處理過程與計時 / whether to print progress and timing */
|
|
5
18
|
print?: boolean;
|
|
19
|
+
/** 失敗時回傳 null 而非丟錯 / return null instead of throwing on failure */
|
|
6
20
|
noThrowError?: boolean;
|
|
7
21
|
}): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 預設匯出 (Default export) 指向 syncLockfile,
|
|
24
|
+
* 讓 `import syncLockfile from 'sync-lockfile'` 成為最短的使用方式。
|
|
25
|
+
*
|
|
26
|
+
* The default export points to syncLockfile so the shortest import form
|
|
27
|
+
* remains the primary usage.
|
|
28
|
+
*/
|
|
8
29
|
export default syncLockfile;
|
package/index.js
CHANGED
|
@@ -1,35 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Created by user on 2020/1/8.
|
|
4
|
-
*/
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.syncLockfile = syncLockfile;
|
|
7
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* 套件進入點 (Entrypoint):提供將根目錄 yarn.lock 同步到各 workspace 套件的函式。
|
|
7
|
+
*
|
|
8
|
+
* Package entry point: provides the function that syncs the root yarn.lock
|
|
9
|
+
* into every workspace package.
|
|
10
|
+
*
|
|
11
|
+
* Created by user on 2020/1/8.
|
|
12
|
+
*/
|
|
8
13
|
const ws_pkg_list_1 = require("ws-pkg-list");
|
|
9
14
|
const find_root_1 = tslib_1.__importDefault(require("@yarn-tool/find-root"));
|
|
10
15
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
16
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
17
|
+
/**
|
|
18
|
+
* 以 `cwd` 為起點尋找 workspace 根目錄,並將根目錄的 `yarn.lock` 複製到
|
|
19
|
+
* 每一個 workspace 套件。
|
|
20
|
+
*
|
|
21
|
+
* Locates the workspace root from `cwd` and copies the root `yarn.lock` into
|
|
22
|
+
* every workspace package.
|
|
23
|
+
*
|
|
24
|
+
* @param cwd 起始目錄,向上尋找 workspace 根目錄 / start directory used to
|
|
25
|
+
* search upward for the workspace root
|
|
26
|
+
* @param options 列印與錯誤處理選項 / printing and error handling options
|
|
27
|
+
* @returns 成功同步回傳 `true`;失敗時依 `noThrowError` 回傳 `null` 或丟出
|
|
28
|
+
* `Error` /
|
|
29
|
+
* `true` on success; on failure either `null` or a thrown `Error`,
|
|
30
|
+
* depending on `noThrowError`
|
|
31
|
+
*/
|
|
12
32
|
function syncLockfile(cwd, options = {}) {
|
|
13
33
|
const { print, noThrowError } = options;
|
|
34
|
+
/**
|
|
35
|
+
* 從 cwd 向上尋找 workspace 根目錄,讓 CLI 與 API 都能以任意子目錄呼叫。
|
|
36
|
+
*
|
|
37
|
+
* Searches upward from cwd so both the CLI and the API can be invoked
|
|
38
|
+
* from any subdirectory.
|
|
39
|
+
*/
|
|
14
40
|
const ws = (0, find_root_1.default)({
|
|
15
41
|
cwd
|
|
16
42
|
});
|
|
43
|
+
/**
|
|
44
|
+
* 目標不是 workspace 時無法決定要複製到哪裡,
|
|
45
|
+
* 依 `noThrowError` 決定丟錯或以 null 表示「未執行」。
|
|
46
|
+
*
|
|
47
|
+
* Without a workspace there is nowhere to copy to, so `noThrowError`
|
|
48
|
+
* decides between throwing and returning null ("not executed").
|
|
49
|
+
*/
|
|
17
50
|
if (!ws.hasWorkspace) {
|
|
18
51
|
noThrowError || throwError(`target dir not a yarn workspaces, ${ws.root}`);
|
|
19
52
|
return null;
|
|
20
53
|
}
|
|
21
54
|
const lockfile = `yarn.lock`;
|
|
22
55
|
const lockfile_root = path_1.default.join(ws.root, lockfile);
|
|
56
|
+
/**
|
|
57
|
+
* 根目錄沒有 yarn.lock 時無從複製,同樣交由 `noThrowError` 決定處理方式,
|
|
58
|
+
* 以維持與上一個失敗分支一致的回傳契約 (contract)。
|
|
59
|
+
*
|
|
60
|
+
* With no root yarn.lock there is nothing to copy; this branch follows the
|
|
61
|
+
* same `noThrowError` handling to keep one consistent failure contract.
|
|
62
|
+
*/
|
|
23
63
|
if (!fs_extra_1.default.pathExistsSync(lockfile_root)) {
|
|
24
64
|
noThrowError || throwError(`yarn.lock not exists`);
|
|
25
65
|
return null;
|
|
26
66
|
}
|
|
27
67
|
print && console.log(`workspaces:`, ws.root, '\n');
|
|
28
68
|
const label = `copy done`;
|
|
69
|
+
/**
|
|
70
|
+
* 以 console.time 包住整批複製,讓 print 模式可同時看到每個目標與總耗時。
|
|
71
|
+
*
|
|
72
|
+
* Wraps the whole copy loop in console.time so print mode reports both
|
|
73
|
+
* each target and the total elapsed time.
|
|
74
|
+
*/
|
|
29
75
|
print && console.time(label);
|
|
76
|
+
/**
|
|
77
|
+
* 逐一複製到所有 workspace 套件;每個套件都覆寫成根目錄的同一份內容,
|
|
78
|
+
* 這正是本工具的目的——讓子套件的 lockfile 與根目錄保持一致。
|
|
79
|
+
*
|
|
80
|
+
* Copies into every workspace package, overwriting each one with the same
|
|
81
|
+
* root content; that is precisely the point of this tool — keeping
|
|
82
|
+
* sub-package lockfiles identical to the root.
|
|
83
|
+
*/
|
|
30
84
|
(0, ws_pkg_list_1.workspacesPackagesList)(ws.root, true)
|
|
31
85
|
.forEach(pkg_dir => {
|
|
32
86
|
print && console.log(`copy to... ${path_1.default.relative(ws.root, pkg_dir)}`);
|
|
87
|
+
/**
|
|
88
|
+
* 覆寫舊檔並保留時間戳記 (timestamps)、解引用 (dereference)
|
|
89
|
+
* 符號連結,確保子套件拿到的是實體檔案而非連結本體。
|
|
90
|
+
*
|
|
91
|
+
* Overwrites the old file while preserving timestamps and
|
|
92
|
+
* dereferencing symlinks, so sub-packages receive a real file
|
|
93
|
+
* rather than the link itself.
|
|
94
|
+
*/
|
|
33
95
|
fs_extra_1.default.copySync(lockfile_root, path_1.default.join(pkg_dir, lockfile), {
|
|
34
96
|
overwrite: true,
|
|
35
97
|
preserveTimestamps: true,
|
|
@@ -39,8 +101,23 @@ function syncLockfile(cwd, options = {}) {
|
|
|
39
101
|
print && console.timeEnd(label);
|
|
40
102
|
return true;
|
|
41
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* 統一錯誤出口 (error exit):讓失敗訊息集中在一處,方便日後調整錯誤格式。
|
|
106
|
+
*
|
|
107
|
+
* Single error exit point: keeps failure messages in one place so the error
|
|
108
|
+
* format can be adjusted centrally later.
|
|
109
|
+
*
|
|
110
|
+
* @param message 丟出的錯誤訊息 / the error message to throw
|
|
111
|
+
*/
|
|
42
112
|
function throwError(message) {
|
|
43
113
|
throw new Error(message);
|
|
44
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* 預設匯出 (Default export) 指向 syncLockfile,
|
|
117
|
+
* 讓 `import syncLockfile from 'sync-lockfile'` 成為最短的使用方式。
|
|
118
|
+
*
|
|
119
|
+
* The default export points to syncLockfile so the shortest import form
|
|
120
|
+
* remains the primary usage.
|
|
121
|
+
*/
|
|
45
122
|
exports.default = syncLockfile;
|
|
46
123
|
//# 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":";;AA4BA,oCA6FC;;AAzHD;;;;;;;GAOG;AACH,6CAAqD;AACrD,6EAA4C;AAC5C,gEAA0B;AAC1B,wDAAwB;AAExB;;;;;;;;;;;;;;GAcG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,UAKtC,EAAE;IAEL,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAExC;;;;;OAKG;IACH,MAAM,EAAE,GAAG,IAAA,mBAAQ,EAAC;QACnB,GAAG;KACH,CAAC,CAAC;IAEH;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,CAAC,YAAY,EACpB,CAAC;QACA,YAAY,IAAI,UAAU,CAAC,qCAAqC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,QAAQ,GAAG,WAAW,CAAC;IAC7B,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEnD;;;;;;OAMG;IACH,IAAI,CAAC,kBAAE,CAAC,cAAc,CAAC,aAAa,CAAC,EACrC,CAAC;QACA,YAAY,IAAI,UAAU,CAAC,sBAAsB,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAEnD,MAAM,KAAK,GAAG,WAAW,CAAC;IAE1B;;;;;OAKG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAE7B;;;;;;;OAOG;IACH,IAAA,oCAAsB,EAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;SACnC,OAAO,CAAC,OAAO,CAAC,EAAE;QAElB,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,cAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAEtE;;;;;;;WAOG;QACH,kBAAE,CAAC,QAAQ,CAAC,aAAa,EAAE,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE;YACxD,SAAS,EAAE,IAAI;YACf,kBAAkB,EAAE,IAAI;YACxB,WAAW,EAAE,IAAI;SACjB,CAAC,CAAA;IAEH,CAAC,CAAC,CACF;IAED,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEhC,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,UAAU,CAAC,OAAe;IAElC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;AACzB,CAAC;AAED;;;;;;GAMG;AACH,kBAAe,YAAY,CAAA","sourcesContent":["/**\n * 套件進入點 (Entrypoint):提供將根目錄 yarn.lock 同步到各 workspace 套件的函式。\n *\n * Package entry point: provides the function that syncs the root yarn.lock\n * into every workspace package.\n *\n * Created by user on 2020/1/8.\n */\nimport { workspacesPackagesList } from 'ws-pkg-list';\nimport findRoot from '@yarn-tool/find-root';\nimport fs from 'fs-extra';\nimport path from 'path';\n\n/**\n * 以 `cwd` 為起點尋找 workspace 根目錄,並將根目錄的 `yarn.lock` 複製到\n * 每一個 workspace 套件。\n *\n * Locates the workspace root from `cwd` and copies the root `yarn.lock` into\n * every workspace package.\n *\n * @param cwd 起始目錄,向上尋找 workspace 根目錄 / start directory used to\n * search upward for the workspace root\n * @param options 列印與錯誤處理選項 / printing and error handling options\n * @returns 成功同步回傳 `true`;失敗時依 `noThrowError` 回傳 `null` 或丟出\n * `Error` /\n * `true` on success; on failure either `null` or a thrown `Error`,\n * depending on `noThrowError`\n */\nexport function syncLockfile(cwd: string, options: {\n\t/** 是否印出處理過程與計時 / whether to print progress and timing */\n\tprint?: boolean,\n\t/** 失敗時回傳 null 而非丟錯 / return null instead of throwing on failure */\n\tnoThrowError?: boolean,\n} = {})\n{\n\tconst { print, noThrowError } = options;\n\n\t/**\n\t * 從 cwd 向上尋找 workspace 根目錄,讓 CLI 與 API 都能以任意子目錄呼叫。\n\t *\n\t * Searches upward from cwd so both the CLI and the API can be invoked\n\t * from any subdirectory.\n\t */\n\tconst ws = findRoot({\n\t\tcwd\n\t});\n\n\t/**\n\t * 目標不是 workspace 時無法決定要複製到哪裡,\n\t * 依 `noThrowError` 決定丟錯或以 null 表示「未執行」。\n\t *\n\t * Without a workspace there is nowhere to copy to, so `noThrowError`\n\t * decides between throwing and returning null (\"not executed\").\n\t */\n\tif (!ws.hasWorkspace)\n\t{\n\t\tnoThrowError || throwError(`target dir not a yarn workspaces, ${ws.root}`);\n\t\treturn null;\n\t}\n\n\tconst lockfile = `yarn.lock`;\n\tconst lockfile_root = path.join(ws.root, lockfile);\n\n\t/**\n\t * 根目錄沒有 yarn.lock 時無從複製,同樣交由 `noThrowError` 決定處理方式,\n\t * 以維持與上一個失敗分支一致的回傳契約 (contract)。\n\t *\n\t * With no root yarn.lock there is nothing to copy; this branch follows the\n\t * same `noThrowError` handling to keep one consistent failure contract.\n\t */\n\tif (!fs.pathExistsSync(lockfile_root))\n\t{\n\t\tnoThrowError || throwError(`yarn.lock not exists`);\n\t\treturn null;\n\t}\n\n\tprint && console.log(`workspaces:`, ws.root, '\\n');\n\n\tconst label = `copy done`;\n\n\t/**\n\t * 以 console.time 包住整批複製,讓 print 模式可同時看到每個目標與總耗時。\n\t *\n\t * Wraps the whole copy loop in console.time so print mode reports both\n\t * each target and the total elapsed time.\n\t */\n\tprint && console.time(label);\n\n\t/**\n\t * 逐一複製到所有 workspace 套件;每個套件都覆寫成根目錄的同一份內容,\n\t * 這正是本工具的目的——讓子套件的 lockfile 與根目錄保持一致。\n\t *\n\t * Copies into every workspace package, overwriting each one with the same\n\t * root content; that is precisely the point of this tool — keeping\n\t * sub-package lockfiles identical to the root.\n\t */\n\tworkspacesPackagesList(ws.root, true)\n\t\t.forEach(pkg_dir => {\n\n\t\t\tprint && console.log(`copy to... ${path.relative(ws.root, pkg_dir)}`);\n\n\t\t\t/**\n\t\t\t * 覆寫舊檔並保留時間戳記 (timestamps)、解引用 (dereference)\n\t\t\t * 符號連結,確保子套件拿到的是實體檔案而非連結本體。\n\t\t\t *\n\t\t\t * Overwrites the old file while preserving timestamps and\n\t\t\t * dereferencing symlinks, so sub-packages receive a real file\n\t\t\t * rather than the link itself.\n\t\t\t */\n\t\t\tfs.copySync(lockfile_root, path.join(pkg_dir, lockfile), {\n\t\t\t\toverwrite: true,\n\t\t\t\tpreserveTimestamps: true,\n\t\t\t\tdereference: true,\n\t\t\t})\n\n\t\t})\n\t;\n\n\tprint && console.timeEnd(label);\n\n\treturn true;\n}\n\n/**\n * 統一錯誤出口 (error exit):讓失敗訊息集中在一處,方便日後調整錯誤格式。\n *\n * Single error exit point: keeps failure messages in one place so the error\n * format can be adjusted centrally later.\n *\n * @param message 丟出的錯誤訊息 / the error message to throw\n */\nfunction throwError(message: string)\n{\n\tthrow new Error(message)\n}\n\n/**\n * 預設匯出 (Default export) 指向 syncLockfile,\n * 讓 `import syncLockfile from 'sync-lockfile'` 成為最短的使用方式。\n *\n * The default export points to syncLockfile so the shortest import form\n * remains the primary usage.\n */\nexport default syncLockfile\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sync-lockfile",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13",
|
|
4
4
|
"description": "sync yarn.lock to each packages in yarn workspaces",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sync",
|
|
7
|
+
"yarn.lock",
|
|
8
|
+
"lockfile",
|
|
9
|
+
"workspaces",
|
|
10
|
+
"yarn",
|
|
11
|
+
"monorepo"
|
|
12
|
+
],
|
|
6
13
|
"homepage": "https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/sync-lockfile#readme",
|
|
7
14
|
"bugs": {
|
|
8
15
|
"url": "https://github.com/bluelovers/ws-yarn-workspaces/issues"
|
|
@@ -21,11 +28,13 @@
|
|
|
21
28
|
"scripts": {
|
|
22
29
|
"coverage": "npx nyc pnpm run test",
|
|
23
30
|
"lint": "npx eslint **/*.ts",
|
|
24
|
-
"test": "node --run test:
|
|
31
|
+
"test": "node --run test:node",
|
|
25
32
|
"test:jest": "jest --passWithNoTests",
|
|
26
33
|
"test:jest:coverage": "pnpm run test:jest -- --coverage",
|
|
27
34
|
"test:jest:snapshot": "pnpm run test:jest -- -u",
|
|
35
|
+
"test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
|
|
28
36
|
"test:snapshot": "pnpm run test -u",
|
|
37
|
+
"test:tsc": "tsc --noEmit & echo typescript check done",
|
|
29
38
|
"test:tsd": "ynpx tsd",
|
|
30
39
|
"npm:publish": "npm publish",
|
|
31
40
|
"npm:publish:lerna": "npx lerna publish --yes --bump patch",
|
|
@@ -41,11 +50,11 @@
|
|
|
41
50
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
42
51
|
},
|
|
43
52
|
"dependencies": {
|
|
44
|
-
"@yarn-tool/find-root": "^2.0.
|
|
45
|
-
"fs-extra": "^11.4.
|
|
53
|
+
"@yarn-tool/find-root": "^2.0.27",
|
|
54
|
+
"fs-extra": "^11.4.1",
|
|
46
55
|
"tslib": ">=2.8.1",
|
|
47
|
-
"ws-pkg-list": "^3.0.
|
|
56
|
+
"ws-pkg-list": "^3.0.13",
|
|
48
57
|
"yargs": "<18 >=17.7.2"
|
|
49
58
|
},
|
|
50
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "cf2f309300d7e01680c5b8bd91114fe16dbadb24"
|
|
51
60
|
}
|