@yarn-tool/setup-module-env 3.0.16 → 3.0.17

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 CHANGED
@@ -3,6 +3,40 @@
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.17](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/setup-module-env@3.0.16...@yarn-tool/setup-module-env@3.0.17) (2026-10-12)
7
+
8
+
9
+
10
+ ### 📦 Code Refactoring
11
+
12
+ * **core:** 統一靜態檔案控制邏輯並更新 package.json 腳本規範 ([12f5a56](https://github.com/bluelovers/ws-yarn-workspaces/commit/12f5a5623a6f19e33616a326c86a094c548a0436))
13
+ * **pkg-entry-util:** 優化與更新預設 package.json 腳本內容 ([f9bcc9b](https://github.com/bluelovers/ws-yarn-workspaces/commit/f9bcc9b7d2ec3397bcbdb28939bcded09ad3acfd))
14
+ * **utils:** 重構測試腳本配置與路徑搜尋工具 ([aeb410e](https://github.com/bluelovers/ws-yarn-workspaces/commit/aeb410e2103f62ce8e012f96115f095a06107ddf))
15
+
16
+
17
+ ### 📚 Documentation
18
+
19
+ * add jsdoc ([9cb9b13](https://github.com/bluelovers/ws-yarn-workspaces/commit/9cb9b13eda8c357221ad1b754458aa9916eada22))
20
+
21
+
22
+ ### 🛠 Build System
23
+
24
+ * update build ([3186340](https://github.com/bluelovers/ws-yarn-workspaces/commit/3186340758172427cb1e9b8955f6fd677abac625))
25
+ * **deps:** 更新測試腳本與依賴以支援 node:test ([f9c71c7](https://github.com/bluelovers/ws-yarn-workspaces/commit/f9c71c795c792c5c7ed9d613ce7e9c3c726c39d5))
26
+
27
+
28
+ ### ♻️ Chores
29
+
30
+ * **deps:** 更新各套件依賴版本 ([569f075](https://github.com/bluelovers/ws-yarn-workspaces/commit/569f0756189cdadf69955d8e388ac0a6a8988056))
31
+ * **workspace:** 更新測試指令路徑與新增工作區搜尋選項 ([a80039d](https://github.com/bluelovers/ws-yarn-workspaces/commit/a80039dd8c691e047466966ffc8f8a4e2e31c03f))
32
+
33
+
34
+ ### 🔖 Miscellaneous
35
+
36
+ * . ([e5788f8](https://github.com/bluelovers/ws-yarn-workspaces/commit/e5788f84551b870490a96d0a5d67d8d542481373))
37
+
38
+
39
+
6
40
  ## [3.0.16](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/setup-module-env@3.0.15...@yarn-tool/setup-module-env@3.0.16) (2026-09-10)
7
41
 
8
42
  **Note:** Version bump only for package @yarn-tool/setup-module-env
package/README.md CHANGED
@@ -2,7 +2,16 @@
2
2
 
3
3
  用於設定 tsdx 專案環境的工具,自動配置 package.json 與靜態檔案 (Tool for setting up tsdx project environment, auto-configuring package.json and static files)
4
4
 
5
- ## install
5
+ ## Features
6
+
7
+ - 自動設定 `package.json` 的 scripts(`test`、`build`、`build:tsdx`、`build:dts` 等)
8
+ - 自動配置 `main` / `module` / `types` / `exports` 等模組入口欄位
9
+ - 自動添加 `create-by-tsdx` 關鍵字 (Keyword) 以標識 tsdx 專案
10
+ - 依工作區 (Workspace) 狀態調整 `tslib` 依賴位置(子套件移除、根目錄移至 devDependencies)
11
+ - 內建靜態檔案映射表 (Static File Map),複製 `tsconfig.json` 等範本至目標專案
12
+ - 提供 `isTsdxPackage` 判斷既有專案是否為 tsdx 專案
13
+
14
+ ## Installation
6
15
 
7
16
  ```bash
8
17
  yarn add @yarn-tool/setup-module-env
@@ -14,3 +23,61 @@ pnpm add @yarn-tool/setup-module-env
14
23
  npm install @yarn-tool/setup-module-env
15
24
  ```
16
25
 
26
+ ## Usage
27
+
28
+ ```ts
29
+ import { setupTsdx } from '@yarn-tool/setup-module-env';
30
+
31
+ const result = setupTsdx({
32
+ pkg,
33
+ targetDir,
34
+ rootData,
35
+ file_map: [],
36
+ mdFile: 'README.md',
37
+ existsReadme: true,
38
+ oldExists: false,
39
+ });
40
+
41
+ // 回傳更新後的 pkg 與合併後的 file_map
42
+ console.log(result.pkg.scripts);
43
+ console.log(result.file_map);
44
+ ```
45
+
46
+ ## API Documentation
47
+
48
+ ### `setupTsdx(config: ISetupTsdxOptions<P>): ISetupTsdxOptions<P> & { pkg, file_map }`
49
+
50
+ 套件的主要入口(Main Entry),執行以下步驟:
51
+
52
+ 1. 呼叫 `updatePackageJson` 更新 `package.json`
53
+ 2. 合併預設與自訂的靜態檔案映射表
54
+ 3. 確保目標專案的 `src` 目錄存在
55
+
56
+ 回傳的物件包含原始設定與更新後的 `pkg`、`file_map`。
57
+
58
+ ### `ISetupTsdxOptions<P>` 選項
59
+
60
+ | 欄位 | 型別 | 說明 |
61
+ | --- | --- | --- |
62
+ | `targetDir` | `string` | 目標目錄路徑 |
63
+ | `pkg` | `P` | 要更新的 `package.json` 物件 |
64
+ | `rootData` | `IFindRootReturnType` | 工作區根目錄資訊(由 `@yarn-tool/find-root` 回傳) |
65
+ | `file_map` | `IStaticFilesMapArray<string>` | 自訂靜態檔案映射表 |
66
+ | `mdFile` | `string` | README 檔案名稱 |
67
+ | `existsReadme` | `boolean` | 是否已存在 README 檔案 |
68
+ | `oldExists` | `boolean` | 是否為已存在的專案 |
69
+
70
+ ### 內部函式(`lib/preset/tsdx/`)
71
+
72
+ - `updatePackageJson(pkg, config?)` — 更新 `package.json` 的 scripts、入口欄位、exports 與 keywords
73
+ - `fixTsdxPackage(pkg, config)` — 依工作區狀態修復 `tslib` 依賴位置
74
+ - `isTsdxPackage(pkg, config?)` — 透過 keywords 是否含 `create-by-tsdx` 且 `exports['.']` 為物件來判斷是否為 tsdx 專案
75
+ - `defaultCopyStaticFilesTsdx` — 凍結 (Frozen) 的預設靜態檔案映射表,包含 `tsconfig.json`、`test/tsconfig.json`、`src/index.cts`、`src/tsconfig.json`
76
+
77
+ ## Configuration
78
+
79
+ 此套件無需設定檔,所有行為皆由 `ISetupTsdxOptions` 參數控制:
80
+
81
+ - **靜態檔案**:預設映射表會與傳入的 `file_map` 依序合併(預設項在前),可透過 `file_map` 新增或覆寫目標路徑
82
+ - **scripts**:僅在欄位缺失時填入預設值(使用 `??=`),已有自訂內容不會被覆寫;唯一的例外是 `build` 不含 `run build:tsdx` 時會被替換
83
+ - **依賴**:工作區子套件會移除 `tslib`(由根目錄統一管理),獨立專案或工作區根目錄則移至 `devDependencies`,根目錄另會確保 `@bluelovers/tsconfig` 存在
@@ -26,26 +26,39 @@ const dot_values2_1 = require("dot-values2");
26
26
  function fixTsdxPackage(pkg, config) {
27
27
  var _a, _b, _c, _d, _e;
28
28
  var _f, _g;
29
- // 檢查是否在工作區內但不是工作區本身(即子套件)
30
- // Check if inside a workspace but not the workspace itself (i.e., sub-package)
29
+ /**
30
+ * 檢查是否在工作區內但不是工作區本身(即子套件)
31
+ * Check if inside a workspace but not the workspace itself (i.e., sub-package)
32
+ */
31
33
  if (config.rootData.hasWorkspace && !config.rootData.isWorkspace) {
32
- // 在工作區子套件中,移除 tslib 依賴(由根目錄統一管理)
33
- // In workspace sub-packages, remove tslib dependency (managed by root)
34
+ /**
35
+ * 在工作區子套件中,移除 tslib 依賴(由根目錄統一管理)
36
+ * In workspace sub-packages, remove tslib dependency (managed by root)
37
+ */
34
38
  (0, dot_values2_1.deleteValue)(pkg, ['dependencies', 'tslib']);
35
39
  (0, dot_values2_1.deleteValue)(pkg, ['devDependencies', 'tslib']);
36
40
  }
37
41
  else {
38
- // 確保 devDependencies 存在
39
- // Ensure devDependencies exists
42
+ /**
43
+ * 確保 devDependencies 存在
44
+ * Ensure devDependencies exists
45
+ */
40
46
  (_a = pkg.devDependencies) !== null && _a !== void 0 ? _a : (pkg.devDependencies = {});
41
- // 如果 tslib 在 dependencies 中,將其移至 devDependencies
42
- // If tslib is in dependencies, move it to devDependencies
47
+ /**
48
+ * 如果 tslib 在 dependencies 中,將其移至 devDependencies
49
+ * If tslib is in dependencies, move it to devDependencies
50
+ *
51
+ * 以 length > 0 過濾空字串,避免把無效版本複製到 devDependencies
52
+ * The length > 0 check filters out empty strings so an invalid version is not copied
53
+ */
43
54
  if (((_c = (_b = pkg.dependencies) === null || _b === void 0 ? void 0 : _b['tslib']) === null || _c === void 0 ? void 0 : _c.length) > 0) {
44
55
  (_d = (_f = pkg.devDependencies)['tslib']) !== null && _d !== void 0 ? _d : (_f['tslib'] = pkg.dependencies['tslib']);
45
56
  (0, dot_values2_1.deleteValue)(pkg, ['dependencies', 'tslib']);
46
57
  }
47
- // 如果是根目錄,確保 @bluelovers/tsconfig 存在
48
- // If it's the root directory, ensure @bluelovers/tsconfig exists
58
+ /**
59
+ * 如果是根目錄,確保 @bluelovers/tsconfig 存在
60
+ * If it's the root directory, ensure @bluelovers/tsconfig exists
61
+ */
49
62
  if (config.rootData.isRoot) {
50
63
  (_e = (_g = pkg.devDependencies)['@bluelovers/tsconfig']) !== null && _e !== void 0 ? _e : (_g['@bluelovers/tsconfig'] = '*');
51
64
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fix.js","sourceRoot":"","sources":["fix.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAwBH,wCAkCC;AAtDD,6CAA0C;AAG1C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,cAAc,CAAyB,GAAM,EAAE,MAAsD;;;IAEpH,0BAA0B;IAC1B,+EAA+E;IAC/E,IAAI,MAAM,CAAC,QAAQ,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAChE,CAAC;QACA,iCAAiC;QACjC,uEAAuE;QACvE,IAAA,yBAAW,EAAC,GAAG,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;QAC5C,IAAA,yBAAW,EAAC,GAAG,EAAE,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC;IAChD,CAAC;SAED,CAAC;QACA,wBAAwB;QACxB,gCAAgC;QAChC,MAAA,GAAG,CAAC,eAAe,oCAAnB,GAAG,CAAC,eAAe,GAAK,EAAE,EAAC;QAE3B,iDAAiD;QACjD,0DAA0D;QAC1D,IAAI,CAAA,MAAA,MAAA,GAAG,CAAC,YAAY,0CAAG,OAAO,CAAC,0CAAE,MAAM,IAAG,CAAC,EAC3C,CAAC;YACA,YAAA,GAAG,CAAC,eAAe,EAAC,OAAO,wCAAP,OAAO,IAAM,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,EAAC;YAC3D,IAAA,yBAAW,EAAC,GAAG,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;QAC7C,CAAC;QAED,oCAAoC;QACpC,iEAAiE;QACjE,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,EAC1B,CAAC;YACA,YAAA,GAAG,CAAC,eAAe,EAAC,sBAAsB,wCAAtB,sBAAsB,IAAM,GAAG,EAAC;QACrD,CAAC;IACF,CAAC;IAED,OAAO,GAAG,CAAA;AACX,CAAC","sourcesContent":["/**\n * tsdx package.json 修復與調整工具函式\n * Utility functions for fixing and adjusting tsdx package.json\n */\n\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { ISetupTsdxOptions } from './index';\nimport { deleteValue } from 'dot-values2';\nimport { ITSPickExtra } from 'ts-type/lib/type/record';\n\n/**\n * 修復 tsdx 專案的 package.json 設定\n * Fix tsdx project's package.json configuration\n *\n * 根據工作區 (workspace) 的狀態調整 tslib 依賴的位置:\n * Adjusts tslib dependency location based on workspace status:\n *\n * - 如果位於工作區內但不是工作區根目錄:移除 tslib 依賴(由根目錄統一管理)\n * If inside a workspace but not the workspace root: removes tslib dependency (managed by root)\n *\n * - 如果是獨立專案或工作區根目錄:將 tslib 從 dependencies 移至 devDependencies\n * If standalone project or workspace root: moves tslib from dependencies to devDependencies\n *\n * @param pkg - package.json 物件 / package.json object\n * @param config - 包含 rootData 的設定選項 / configuration options containing rootData\n * @returns 修改後的 package.json 物件 / Modified package.json object\n */\nexport function fixTsdxPackage<P extends IPackageJson>(pkg: P, config: ITSPickExtra<ISetupTsdxOptions<P>, 'rootData'>)\n{\n\t// 檢查是否在工作區內但不是工作區本身(即子套件)\n\t// Check if inside a workspace but not the workspace itself (i.e., sub-package)\n\tif (config.rootData.hasWorkspace && !config.rootData.isWorkspace)\n\t{\n\t\t// 在工作區子套件中,移除 tslib 依賴(由根目錄統一管理)\n\t\t// In workspace sub-packages, remove tslib dependency (managed by root)\n\t\tdeleteValue(pkg, ['dependencies', 'tslib']);\n\t\tdeleteValue(pkg, ['devDependencies', 'tslib']);\n\t}\n\telse\n\t{\n\t\t// 確保 devDependencies 存在\n\t\t// Ensure devDependencies exists\n\t\tpkg.devDependencies ??= {};\n\n\t\t// 如果 tslib 在 dependencies 中,將其移至 devDependencies\n\t\t// If tslib is in dependencies, move it to devDependencies\n\t\tif (pkg.dependencies?.['tslib']?.length > 0)\n\t\t{\n\t\t\tpkg.devDependencies['tslib'] ??= pkg.dependencies['tslib'];\n\t\t\tdeleteValue(pkg, ['dependencies', 'tslib']);\n\t\t}\n\n\t\t// 如果是根目錄,確保 @bluelovers/tsconfig 存在\n\t\t// If it's the root directory, ensure @bluelovers/tsconfig exists\n\t\tif (config.rootData.isRoot)\n\t\t{\n\t\t\tpkg.devDependencies['@bluelovers/tsconfig'] ??= '*';\n\t\t}\n\t}\n\n\treturn pkg\n}\n"]}
1
+ {"version":3,"file":"fix.js","sourceRoot":"","sources":["fix.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAwBH,wCA+CC;AAnED,6CAA0C;AAG1C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,cAAc,CAAyB,GAAM,EAAE,MAAsD;;;IAEpH;;;OAGG;IACH,IAAI,MAAM,CAAC,QAAQ,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,EAChE,CAAC;QACA;;;WAGG;QACH,IAAA,yBAAW,EAAC,GAAG,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;QAC5C,IAAA,yBAAW,EAAC,GAAG,EAAE,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC;IAChD,CAAC;SAED,CAAC;QACA;;;WAGG;QACH,MAAA,GAAG,CAAC,eAAe,oCAAnB,GAAG,CAAC,eAAe,GAAK,EAAE,EAAC;QAE3B;;;;;;WAMG;QACH,IAAI,CAAA,MAAA,MAAA,GAAG,CAAC,YAAY,0CAAG,OAAO,CAAC,0CAAE,MAAM,IAAG,CAAC,EAC3C,CAAC;YACA,YAAA,GAAG,CAAC,eAAe,EAAC,OAAO,wCAAP,OAAO,IAAM,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,EAAC;YAC3D,IAAA,yBAAW,EAAC,GAAG,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;QAC7C,CAAC;QAED;;;WAGG;QACH,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,EAC1B,CAAC;YACA,YAAA,GAAG,CAAC,eAAe,EAAC,sBAAsB,wCAAtB,sBAAsB,IAAM,GAAG,EAAC;QACrD,CAAC;IACF,CAAC;IAED,OAAO,GAAG,CAAA;AACX,CAAC","sourcesContent":["/**\n * tsdx package.json 修復與調整工具函式\n * Utility functions for fixing and adjusting tsdx package.json\n */\n\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { ISetupTsdxOptions } from './index';\nimport { deleteValue } from 'dot-values2';\nimport { ITSPickExtra } from 'ts-type/lib/type/record';\n\n/**\n * 修復 tsdx 專案的 package.json 設定\n * Fix tsdx project's package.json configuration\n *\n * 根據工作區 (workspace) 的狀態調整 tslib 依賴的位置:\n * Adjusts tslib dependency location based on workspace status:\n *\n * - 如果位於工作區內但不是工作區根目錄:移除 tslib 依賴(由根目錄統一管理)\n * If inside a workspace but not the workspace root: removes tslib dependency (managed by root)\n *\n * - 如果是獨立專案或工作區根目錄:將 tslib 從 dependencies 移至 devDependencies\n * If standalone project or workspace root: moves tslib from dependencies to devDependencies\n *\n * @param pkg - package.json 物件 / package.json object\n * @param config - 包含 rootData 的設定選項 / configuration options containing rootData\n * @returns 修改後的 package.json 物件 / Modified package.json object\n */\nexport function fixTsdxPackage<P extends IPackageJson>(pkg: P, config: ITSPickExtra<ISetupTsdxOptions<P>, 'rootData'>)\n{\n\t/**\n\t * 檢查是否在工作區內但不是工作區本身(即子套件)\n\t * Check if inside a workspace but not the workspace itself (i.e., sub-package)\n\t */\n\tif (config.rootData.hasWorkspace && !config.rootData.isWorkspace)\n\t{\n\t\t/**\n\t\t * 在工作區子套件中,移除 tslib 依賴(由根目錄統一管理)\n\t\t * In workspace sub-packages, remove tslib dependency (managed by root)\n\t\t */\n\t\tdeleteValue(pkg, ['dependencies', 'tslib']);\n\t\tdeleteValue(pkg, ['devDependencies', 'tslib']);\n\t}\n\telse\n\t{\n\t\t/**\n\t\t * 確保 devDependencies 存在\n\t\t * Ensure devDependencies exists\n\t\t */\n\t\tpkg.devDependencies ??= {};\n\n\t\t/**\n\t\t * 如果 tslib 在 dependencies 中,將其移至 devDependencies\n\t\t * If tslib is in dependencies, move it to devDependencies\n\t\t *\n\t\t * 以 length > 0 過濾空字串,避免把無效版本複製到 devDependencies\n\t\t * The length > 0 check filters out empty strings so an invalid version is not copied\n\t\t */\n\t\tif (pkg.dependencies?.['tslib']?.length > 0)\n\t\t{\n\t\t\tpkg.devDependencies['tslib'] ??= pkg.dependencies['tslib'];\n\t\t\tdeleteValue(pkg, ['dependencies', 'tslib']);\n\t\t}\n\n\t\t/**\n\t\t * 如果是根目錄,確保 @bluelovers/tsconfig 存在\n\t\t * If it's the root directory, ensure @bluelovers/tsconfig exists\n\t\t */\n\t\tif (config.rootData.isRoot)\n\t\t{\n\t\t\tpkg.devDependencies['@bluelovers/tsconfig'] ??= '*';\n\t\t}\n\t}\n\n\treturn pkg\n}\n"]}
@@ -47,6 +47,9 @@ declare const _defaultCopyStaticFilesTsdx: readonly [readonly ["tsconfig.json",
47
47
  /**
48
48
  * 凍結的預設靜態檔案映射表
49
49
  * Frozen default static file mapping table
50
+ *
51
+ * 凍結是為了避免執行期意外改動全域預設值,影響其他套件的設定流程
52
+ * Frozen to prevent accidental mutation of the global default, which would affect setup runs in other packages
50
53
  */
51
54
  export declare const defaultCopyStaticFilesTsdx: IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFilesTsdx>>;
52
55
  /**
@@ -41,77 +41,128 @@ const path_1 = require("path");
41
41
  * @returns 更新後的 package.json 物件 / Updated package.json object
42
42
  */
43
43
  function updatePackageJson(pkg, config) {
44
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
45
- var _q, _r, _s, _t, _u, _v, _w, _x, _y;
46
- // 確保 scripts 欄位存在
47
- // Ensure scripts field exists
44
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
45
+ var _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
46
+ /**
47
+ * 確保 scripts 欄位存在
48
+ * Ensure scripts field exists
49
+ */
48
50
  (_a = pkg.scripts) !== null && _a !== void 0 ? _a : (pkg.scripts = {});
49
- // 如果 test 腳本未指定或為空,清除並設定預設值
50
- // If test script is not specified or empty, clear and set default
51
+ /**
52
+ * 如果 test 腳本未指定或為空,清除並設定預設值
53
+ * If test script is not specified or empty, clear and set default
54
+ *
55
+ * 先設為 undefined 才能讓下一行的 ??= 生效,
56
+ * 因為 "no test specified" 這類佔位字串並非 nullish
57
+ * Setting it to undefined first lets the following ??= take effect,
58
+ * because placeholder strings like "no test specified" are not nullish
59
+ */
51
60
  if ((0, scripts_1.scriptsEntryIsNoTestSpecified)(pkg.scripts["test"])) {
52
61
  pkg.scripts["test"] = void 0;
53
62
  }
54
- // 設定預設的 test 腳本為 jest
55
- // Set default test script to jest
56
- (_b = (_q = pkg.scripts)["test"]) !== null && _b !== void 0 ? _b : (_q["test"] = "jest --passWithNoTests" /* EnumScriptsEntry.JEST_TEST */);
57
- // 設定 posttest 腳本,在測試後執行 build
58
- // Set posttest script to run build after tests
59
- (_c = (_r = pkg.scripts)["posttest"]) !== null && _c !== void 0 ? _c : (_r["posttest"] = "yarn run build");
60
- // 如果 build 腳本不包含 tsdx build,則設定新的 build 腳本
61
- // If build script doesn't include tsdx build, set new build script
62
- if (!((_d = pkg.scripts["build"]) === null || _d === void 0 ? void 0 : _d.includes('run build:tsdx'))) {
63
- pkg.scripts["build"] = "node --run build:tsdx && node --run build:dts:bundle";
63
+ (_b = (_r = pkg.scripts)["test"]) !== null && _b !== void 0 ? _b : (_r["test"] = "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts" /* EnumScriptsEntry.NODE_TEST */);
64
+ (_c = (_s = pkg.scripts)["test:node"]) !== null && _c !== void 0 ? _c : (_s["test:node"] = "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts" /* EnumScriptsEntry.NODE_TEST */);
65
+ /**
66
+ * 設定 posttest 腳本,在測試後執行 build
67
+ * Set posttest script to run build after tests
68
+ */
69
+ (_d = (_t = pkg.scripts)["posttest"]) !== null && _d !== void 0 ? _d : (_t["posttest"] = "pnpm run build");
70
+ /**
71
+ * 如果 build 腳本不包含 tsdx build,則設定新的 build 腳本
72
+ * If build script doesn't include tsdx build, set new build script
73
+ *
74
+ * 以 includes 檢查而非直接覆寫,避免破壞已含 tsdx build 的自訂腳本
75
+ * Checks with includes instead of overwriting directly, so custom scripts already invoking tsdx build are preserved
76
+ */
77
+ if (!((_e = pkg.scripts["build"]) === null || _e === void 0 ? void 0 : _e.includes('run build:tsdx'))) {
78
+ pkg.scripts["build"] = "node --run build:tsdx && node --run build:dts:bundle" /* EnumScriptsEntry.BUILD_TSDX_AND_DTS */;
64
79
  }
65
- // 設定 TypeScript 宣告檔案打包腳本
66
- // Set TypeScript declaration file bundling script
67
- (_e = (_s = pkg.scripts)["build:dts:bundle"]) !== null && _e !== void 0 ? _e : (_s["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" /* EnumScriptsEntry.BUILD_DTS_BUNDLE */);
68
- // 設定 tsdx build 腳本,目標為 node 環境
69
- // Set tsdx build script targeting node environment
70
- (_f = (_t = pkg.scripts)["build:tsdx"]) !== null && _f !== void 0 ? _f : (_t["build:tsdx"] = "ynpx @bluelovers/tsdx build --target node");
71
- // 設定複製宣告檔案的腳本 (Windows 語法)
72
- // Set declaration file copy script (Windows syntax)
73
- (_g = (_u = pkg.scripts)["build:dts:copy"]) !== null && _g !== void 0 ? _g : (_u["build:dts:copy"] = "copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts");
74
- // 設定 TypeScript 宣告檔案輸出腳本
75
- // Set TypeScript declaration file emit script
76
- (_h = (_v = pkg.scripts)["build:dts:tsc:emit"]) !== null && _h !== void 0 ? _h : (_v["build:dts:tsc:emit"] = "tsc --emitDeclarationOnly --declaration --noEmit false");
77
- // 組合完整的 dts 建置腳本
78
- // Compose complete dts build script
79
- (_j = (_w = pkg.scripts)["build:dts:tsc"]) !== null && _j !== void 0 ? _j : (_w["build:dts:tsc"] = [
80
- 'node --run build:dts:copy',
81
- 'node --run build:dts:tsc:emit',
82
- 'node --run build:dts:copy',
83
- ].join(' && '));
84
- // 設定模組入口點
85
- // Set module entry points
80
+ /**
81
+ * 設定 TypeScript 宣告檔案打包腳本
82
+ * Set TypeScript declaration file bundling script
83
+ */
84
+ (_f = (_u = pkg.scripts)["build:dts:bundle"]) !== null && _f !== void 0 ? _f : (_u["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" /* EnumScriptsEntry.BUILD_DTS_BUNDLE */);
85
+ /**
86
+ * 設定 tsdx build 腳本,目標為 node 環境
87
+ * Set tsdx build script targeting node environment
88
+ */
89
+ (_g = (_v = pkg.scripts)["build:tsdx"]) !== null && _g !== void 0 ? _g : (_v["build:tsdx"] = "ynpx @bluelovers/tsdx build --target node --name index" /* EnumScriptsEntry.BUILD_TSDX */);
90
+ /**
91
+ * 設定複製宣告檔案的腳本 (Windows 語法)
92
+ * Set declaration file copy script (Windows syntax)
93
+ */
94
+ (_h = (_w = pkg.scripts)["build:dts:copy"]) !== null && _h !== void 0 ? _h : (_w["build:dts:copy"] = "copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts" /* EnumScriptsEntry.BUILD_DTS_COPY */);
95
+ /**
96
+ * 設定 TypeScript 宣告檔案輸出腳本
97
+ * Set TypeScript declaration file emit script
98
+ */
99
+ (_j = (_x = pkg.scripts)["build:dts:tsc:emit"]) !== null && _j !== void 0 ? _j : (_x["build:dts:tsc:emit"] = "tsc --emitDeclarationOnly --declaration --noEmit false" /* EnumScriptsEntry.BUILD_DTS_TSC_EMIT */);
100
+ /**
101
+ * 設定完整的 dts 建置腳本
102
+ * Set complete dts build script
103
+ */
104
+ (_k = (_y = pkg.scripts)["build:dts:tsc"]) !== null && _k !== void 0 ? _k : (_y["build:dts:tsc"] = "node --run build:dts:tsc:emit & node --run build:dts:copy" /* EnumScriptsEntry.BUILD_DTS_TSC */);
105
+ /**
106
+ * 設定模組入口點
107
+ * Set module entry points
108
+ *
109
+ * 這裡刻意直接賦值而非 ??=,確保與 tsdx 的實際輸出檔名保持一致
110
+ * Assigned directly instead of via ??= to stay in sync with tsdx's actual output file names
111
+ */
86
112
  pkg.main = "dist/index.cjs";
87
113
  pkg.module = "dist/index.esm.mjs";
88
114
  pkg.types = pkg.typings = "dist/index.d.ts";
89
- // 設定 unpkg CDN 入口點
90
- // Set unpkg CDN entry point
91
- (_k = pkg.unpkg) !== null && _k !== void 0 ? _k : (pkg.unpkg = "dist/index.umd.production.min.cjs");
92
- // 設定 exports 欄位,定義模組匯出映射
93
- // Set exports field, defining module export mappings
94
- (_l = pkg.exports) !== null && _l !== void 0 ? _l : (pkg.exports = {});
95
- (_m = (_x = pkg.exports)['.']) !== null && _m !== void 0 ? _m : (_x['.'] = {});
115
+ /**
116
+ * 設定 unpkg CDN 入口點
117
+ * Set unpkg CDN entry point
118
+ */
119
+ (_l = pkg.unpkg) !== null && _l !== void 0 ? _l : (pkg.unpkg = "dist/index.umd.production.min.cjs");
120
+ /**
121
+ * 設定 exports 欄位,定義模組匯出映射
122
+ * Set exports field, defining module export mappings
123
+ *
124
+ * types/import/require 一律覆寫,因為必須與 main/module/types 的輸出檔名完全對應,
125
+ * 否則 Node.js 的條件匯出會指向過期的舊檔
126
+ * types/import/require are always overwritten because they must match the output names of
127
+ * main/module/types exactly, otherwise Node.js conditional exports would point at stale files
128
+ */
129
+ (_m = pkg.exports) !== null && _m !== void 0 ? _m : (pkg.exports = {});
130
+ (_o = (_z = pkg.exports)['.']) !== null && _o !== void 0 ? _o : (_z['.'] = {});
96
131
  pkg.exports['.'].types = "./dist/index.d.ts";
97
132
  pkg.exports['.'].import = "./dist/index.esm.mjs";
98
133
  pkg.exports['.'].require = "./dist/index.cjs";
99
- // 允許直接存取 src 目錄下的檔案
100
- // Allow direct access to files under src directory
134
+ /**
135
+ * 允許直接存取 src 目錄下的檔案
136
+ * Allow direct access to files under src directory
137
+ *
138
+ * 直接覆寫而非 ??=,確保 wildcard 匯出格式始終一致
139
+ * Overwritten rather than via ??= so the wildcard export format always stays consistent
140
+ */
101
141
  pkg.exports['./src/*'] = './src/*';
102
- // 匯出 package.json 本身
103
- // Export package.json itself
104
- (_o = (_y = pkg.exports)['./package.json']) !== null && _o !== void 0 ? _o : (_y['./package.json'] = './package.json');
105
- // 確保 keywords 欄位存在
106
- // Ensure keywords field exists
107
- (_p = pkg.keywords) !== null && _p !== void 0 ? _p : (pkg.keywords = []);
108
- // 添加 tsdx 標識關鍵字(如果尚未存在)
109
- // Add tsdx identifier keyword if not already present
142
+ /**
143
+ * 匯出 package.json 本身
144
+ * Export package.json itself
145
+ */
146
+ (_p = (_0 = pkg.exports)['./package.json']) !== null && _p !== void 0 ? _p : (_0['./package.json'] = './package.json');
147
+ /**
148
+ * 確保 keywords 欄位存在
149
+ * Ensure keywords field exists
150
+ */
151
+ (_q = pkg.keywords) !== null && _q !== void 0 ? _q : (pkg.keywords = []);
152
+ /**
153
+ * 添加 tsdx 標識關鍵字(如果尚未存在)
154
+ * Add tsdx identifier keyword if not already present
155
+ *
156
+ * 重複的 keywords 會讓 isTsdxPackage 的判斷失去意義,故先檢查再加入
157
+ * Duplicate keywords would undermine the check in isTsdxPackage, so it is added only when absent
158
+ */
110
159
  if (!pkg.keywords.includes("create-by-tsdx" /* EnumTsdx.keyword */)) {
111
160
  pkg.keywords.push("create-by-tsdx" /* EnumTsdx.keyword */);
112
161
  }
113
- // 呼叫 fixTsdxPackage 進行額外的修復
114
- // Call fixTsdxPackage for additional fixes
162
+ /**
163
+ * 呼叫 fixTsdxPackage 進行額外的修復
164
+ * Call fixTsdxPackage for additional fixes
165
+ */
115
166
  (0, fix_1.fixTsdxPackage)(pkg, config);
116
167
  return pkg;
117
168
  }
@@ -124,22 +175,33 @@ function updatePackageJson(pkg, config) {
124
175
  * each entry follows [targetPath, sourcePath, ?sourceFileName] format.
125
176
  */
126
177
  const _defaultCopyStaticFilesTsdx = [
127
- // 根目錄的 tsconfig.json 設定檔
128
- // Root tsconfig.json configuration file
178
+ /**
179
+ * 根目錄的 tsconfig.json 設定檔
180
+ * Root tsconfig.json configuration file
181
+ */
129
182
  ['tsconfig.json', 'file/tsconfig.tsdx.json.tpl'],
130
- // 測試目錄的 tsconfig.json 設定檔
131
- // Test directory tsconfig.json configuration file
183
+ /**
184
+ * 測試目錄的 tsconfig.json 設定檔
185
+ * Test directory tsconfig.json configuration file
186
+ */
132
187
  ['test/tsconfig.json', 'file/test/tsconfig.json.tpl'],
133
- // src 目錄下的 index.cts 檔案
134
- // index.cts file under src directory
188
+ /**
189
+ * src 目錄下的 index.cts 檔案
190
+ * index.cts file under src directory
191
+ */
135
192
  ['src/index.cts', 'file/tsdx/index.cts'],
136
- // src 目錄的 tsconfig.json 設定檔
137
- // src directory tsconfig.json configuration file
193
+ /**
194
+ * src 目錄的 tsconfig.json 設定檔
195
+ * src directory tsconfig.json configuration file
196
+ */
138
197
  ['src/tsconfig.json', 'file/tsdx/tsconfig.json.tpl'],
139
198
  ];
140
199
  /**
141
200
  * 凍結的預設靜態檔案映射表
142
201
  * Frozen default static file mapping table
202
+ *
203
+ * 凍結是為了避免執行期意外改動全域預設值,影響其他套件的設定流程
204
+ * Frozen to prevent accidental mutation of the global default, which would affect setup runs in other packages
143
205
  */
144
206
  exports.defaultCopyStaticFilesTsdx = Object.freeze(_defaultCopyStaticFilesTsdx);
145
207
  /**
@@ -164,17 +226,29 @@ exports.defaultCopyStaticFilesTsdx = Object.freeze(_defaultCopyStaticFilesTsdx);
164
226
  */
165
227
  function setup(config) {
166
228
  let { pkg, file_map, targetDir, } = config;
167
- // 更新 package.json
168
- // Update package.json
229
+ /**
230
+ * 更新 package.json
231
+ * Update package.json
232
+ */
169
233
  pkg = updatePackageJson(pkg, config);
170
- // 合併預設與自訂的靜態檔案映射
171
- // Merge default and custom static file mappings
234
+ /**
235
+ * 合併預設與自訂的靜態檔案映射
236
+ * Merge default and custom static file mappings
237
+ *
238
+ * 預設項排在前方,自訂項排在後方,讓呼叫端可用相同目標路徑覆寫預設值
239
+ * Default entries come first and custom entries follow, so callers can override a default via the same target path
240
+ */
172
241
  file_map = [
173
242
  ...exports.defaultCopyStaticFilesTsdx,
174
243
  ...file_map,
175
244
  ];
176
- // 確保 src 目錄存在
177
- // Ensure src directory exists
245
+ /**
246
+ * 確保 src 目錄存在
247
+ * Ensure src directory exists
248
+ *
249
+ * tsdx 假定來源碼位於 src/,新專案若缺少此目錄會導致後續 build 失敗
250
+ * tsdx assumes sources live under src/; a new project missing this directory would fail the subsequent build
251
+ */
178
252
  (0, fs_extra_1.ensureDirSync)((0, path_1.resolve)(targetDir, 'src'));
179
253
  return {
180
254
  ...config,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAmCH,8CA8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QACH,QAAQ;KACR,CAAA;AACF,CAAC","sourcesContent":["/**\n * tsdx 專案設定模組\n * tsdx project setup module\n *\n * 此模組提供設定 tsdx 專案的核心功能,包括更新 package.json、\n * 設定靜態檔案映射以及主要設定函式。\n * This module provides core functionality for setting up tsdx projects,\n * including updating package.json, configuring static file mappings,\n * and the main setup function.\n */\n\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { IFindRootReturnType } from '@yarn-tool/find-root';\nimport { _Key, IStaticFilesMapArray } from '@yarn-tool/static-file/lib/types';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from '@yarn-tool/pkg-entry-util/lib/field/scripts';\nimport { deleteValue } from 'dot-values2';\nimport { EnumTsdx } from './const';\nimport { fixTsdxPackage } from './fix';\nimport { ensureDirSync } from 'fs-extra';\nimport { resolve } from 'path';\n\n/**\n * 更新 package.json 以符合 tsdx 專案標準\n * Update package.json to conform to tsdx project standards\n *\n * 此函式會設定以下內容:\n * This function configures the following:\n *\n * - scripts: test, posttest, build, build:dts:bundle, build:tsdx 等\n * scripts: test, posttest, build, build:dts:bundle, build:tsdx, etc.\n *\n * - main/module/types: 設定輸出檔案路徑\n * main/module/types: configure output file paths\n *\n * - exports: 設定模組匯出映射\n * exports: configure module export mappings\n *\n * - keywords: 添加 tsdx 標識關鍵字\n * keywords: add tsdx identifier keyword\n *\n * @param pkg - 要更新的 package.json 物件 / package.json object to update\n * @param config - 設定選項 (可選) / configuration options (optional)\n * @returns 更新後的 package.json 物件 / Updated package.json object\n */\nexport function updatePackageJson<P extends IPackageJson>(pkg: P, config?: ISetupTsdxOptions<P>)\n{\n\t// 確保 scripts 欄位存在\n\t// Ensure scripts field exists\n\tpkg.scripts ??= {};\n\n\t// 如果 test 腳本未指定或為空,清除並設定預設值\n\t// If test script is not specified or empty, clear and set default\n\tif (scriptsEntryIsNoTestSpecified(pkg.scripts[\"test\"]))\n\t{\n\t\tpkg.scripts[\"test\"] = void 0;\n\t}\n\n\t// 設定預設的 test 腳本為 jest\n\t// Set default test script to jest\n\tpkg.scripts[\"test\"] ??= EnumScriptsEntry.JEST_TEST;\n\n\t// 設定 posttest 腳本,在測試後執行 build\n\t// Set posttest script to run build after tests\n\tpkg.scripts[\"posttest\"] ??= \"yarn run build\";\n\n\t// 如果 build 腳本不包含 tsdx build,則設定新的 build 腳本\n\t// If build script doesn't include tsdx build, set new build script\n\tif (!pkg.scripts[\"build\"]?.includes('run build:tsdx'))\n\t{\n\t\tpkg.scripts[\"build\"] = \"node --run build:tsdx && node --run build:dts:bundle\";\n\t}\n\n\t// 設定 TypeScript 宣告檔案打包腳本\n\t// Set TypeScript declaration file bundling script\n\tpkg.scripts[\"build:dts:bundle\"] ??= EnumScriptsEntry.BUILD_DTS_BUNDLE;\n\n\t// 設定 tsdx build 腳本,目標為 node 環境\n\t// Set tsdx build script targeting node environment\n\tpkg.scripts[\"build:tsdx\"] ??= \"ynpx @bluelovers/tsdx build --target node\";\n\n\t// 設定複製宣告檔案的腳本 (Windows 語法)\n\t// Set declaration file copy script (Windows syntax)\n\tpkg.scripts[\"build:dts:copy\"] ??= \"copy .\\\\src\\\\index.d.ts .\\\\dist\\\\index.d.ts & echo build:dts\";\n\n\t// 設定 TypeScript 宣告檔案輸出腳本\n\t// Set TypeScript declaration file emit script\n\tpkg.scripts[\"build:dts:tsc:emit\"] ??= \"tsc --emitDeclarationOnly --declaration --noEmit false\";\n\n\t// 組合完整的 dts 建置腳本\n\t// Compose complete dts build script\n\tpkg.scripts[\"build:dts:tsc\"] ??= [\n 'node --run build:dts:copy',\n 'node --run build:dts:tsc:emit',\n 'node --run build:dts:copy',\n ].join(' && ');\n\n\t// 設定模組入口點\n\t// Set module entry points\n\tpkg.main = \"dist/index.cjs\";\n\tpkg.module = \"dist/index.esm.mjs\";\n\tpkg.types = pkg.typings = \"dist/index.d.ts\";\n\n\t// 設定 unpkg CDN 入口點\n\t// Set unpkg CDN entry point\n\tpkg.unpkg ??= \"dist/index.umd.production.min.cjs\";\n\n\t// 設定 exports 欄位,定義模組匯出映射\n\t// Set exports field, defining module export mappings\n\tpkg.exports ??= {};\n\tpkg.exports['.'] ??= {};\n\tpkg.exports['.'].types = \"./dist/index.d.ts\";\n\tpkg.exports['.'].import = \"./dist/index.esm.mjs\";\n\tpkg.exports['.'].require = \"./dist/index.cjs\";\n\n\t// 允許直接存取 src 目錄下的檔案\n\t// Allow direct access to files under src directory\n\tpkg.exports['./src/*'] = './src/*';\n\n\t// 匯出 package.json 本身\n\t// Export package.json itself\n\tpkg.exports['./package.json'] ??= './package.json';\n\n\t// 確保 keywords 欄位存在\n\t// Ensure keywords field exists\n\tpkg.keywords ??= [];\n\n\t// 添加 tsdx 標識關鍵字(如果尚未存在)\n\t// Add tsdx identifier keyword if not already present\n\tif (!pkg.keywords.includes(EnumTsdx.keyword))\n\t{\n\t\tpkg.keywords.push(EnumTsdx.keyword);\n\t}\n\n\t// 呼叫 fixTsdxPackage 進行額外的修復\n\t// Call fixTsdxPackage for additional fixes\n\tfixTsdxPackage(pkg, config);\n\n\treturn pkg\n}\n\n/**\n * 預設的靜態檔案複製映射表\n * Default static file copy mapping table\n *\n * 定義需要複製到目標專案的靜態檔案,每個項目為 [目標路徑, 來源路徑, ?來源檔名] 的格式。\n * Defines static files that need to be copied to the target project,\n * each entry follows [targetPath, sourcePath, ?sourceFileName] format.\n */\nconst _defaultCopyStaticFilesTsdx = [\n\n\t// 根目錄的 tsconfig.json 設定檔\n\t// Root tsconfig.json configuration file\n\t['tsconfig.json', 'file/tsconfig.tsdx.json.tpl'],\n\n\t// 測試目錄的 tsconfig.json 設定檔\n\t// Test directory tsconfig.json configuration file\n\t['test/tsconfig.json', 'file/test/tsconfig.json.tpl'],\n\n\t// src 目錄下的 index.cts 檔案\n\t// index.cts file under src directory\n\t['src/index.cts', 'file/tsdx/index.cts'],\n\n\t// src 目錄的 tsconfig.json 設定檔\n\t// src directory tsconfig.json configuration file\n\t['src/tsconfig.json', 'file/tsdx/tsconfig.json.tpl'],\n\n] as const;\n\n/**\n * 凍結的預設靜態檔案映射表\n * Frozen default static file mapping table\n */\nexport const defaultCopyStaticFilesTsdx = Object.freeze(_defaultCopyStaticFilesTsdx) as any as IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFilesTsdx>>;\n\n/**\n * tsdx 設定選項介面\n * tsdx setup options interface\n *\n * @template P - package.json 類型 / package.json type\n */\nexport interface ISetupTsdxOptions<P extends IPackageJson>\n{\n\t/** 目標目錄路徑 / Target directory path */\n\ttargetDir: string,\n\n\t/** package.json 物件 / package.json object */\n\tpkg: P,\n\n\t/** 工作區根目錄資訊 / Workspace root directory information */\n\trootData: IFindRootReturnType,\n\n\t/** 靜態檔案映射表 / Static file mapping table */\n\tfile_map: IStaticFilesMapArray<string>,\n\n\t/** README 檔案名稱 / README file name */\n\tmdFile: string,\n\n\t/** 是否存在 README 檔案 / Whether README file exists */\n\texistsReadme: boolean,\n\n\t/** 是否為已存在的專案 / Whether it's an existing project */\n\toldExists: boolean,\n}\n\n/**\n * 設定 tsdx 專案的主要函式\n * Main function for setting up tsdx project\n *\n * 此函式執行以下操作:\n * This function performs the following operations:\n *\n * 1. 更新 package.json 設定\n * Update package.json configuration\n *\n * 2. 合併預設與自訂的靜態檔案映射\n * Merge default and custom static file mappings\n *\n * 3. 確保 src 目錄存在\n * Ensure src directory exists\n *\n * @template P - package.json 類型 / package.json type\n * @param config - 設定選項 / Configuration options\n * @returns 包含更新後設定的物件 / Object containing updated configuration\n */\nexport function setup<P extends IPackageJson>(config: ISetupTsdxOptions<P>)\n{\n\tlet {\n\t\tpkg,\n\t\tfile_map,\n\t\ttargetDir,\n\t} = config;\n\n\t// 更新 package.json\n\t// Update package.json\n\tpkg = updatePackageJson(pkg, config);\n\n\t// 合併預設與自訂的靜態檔案映射\n\t// Merge default and custom static file mappings\n\tfile_map = [\n ...defaultCopyStaticFilesTsdx,\n\t\t...file_map,\n\t];\n\n\t// 確保 src 目錄存在\n\t// Ensure src directory exists\n\tensureDirSync(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AG,CAAC,QAAQ,CAAC,IAAI,yCAAkB,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,IAAA,oBAAc,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAE5B,OAAO,GAAG,CAAA;AACX,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,2BAA2B,GAAG;IAEnC;;;OAGG;IACH,CAAC,eAAe,EAAE,6BAA6B,CAAC;IAEhD;;;OAGG;IACH,CAAC,oBAAoB,EAAE,6BAA6B,CAAC;IAErD;;;OAGG;IACH,CAAC,eAAe,EAAE,qBAAqB,CAAC;IAExC;;;OAGG;IACH,CAAC,mBAAmB,EAAE,6BAA6B,CAAC;CAE3C,CAAC;AAEX;;;;;;GAMG;AACU,QAAA,0BAA0B,GAAG,MAAM,CAAC,MAAM,CAAC,2BAA2B,CAA0E,CAAC;AAgC9J;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,KAAK,CAAyB,MAA4B;IAEzE,IAAI,EACH,GAAG,EACH,QAAQ,EACR,SAAS,GACT,GAAG,MAAM,CAAC;IAEX;;;OAGG;IACH,GAAG,GAAG,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAErC;;;;;;OAMG;IACH,QAAQ,GAAG;QACR,GAAG,kCAA0B;QAC/B,GAAG,QAAQ;KACX,CAAC;IAEF;;;;;;OAMG;IACH,IAAA,wBAAa,EAAC,IAAA,cAAO,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAEzC,OAAO;QACN,GAAG,MAAM;QACT,GAAG;QACH,QAAQ;KACR,CAAA;AACF,CAAC","sourcesContent":["/**\n * tsdx 專案設定模組\n * tsdx project setup module\n *\n * 此模組提供設定 tsdx 專案的核心功能,包括更新 package.json、\n * 設定靜態檔案映射以及主要設定函式。\n * This module provides core functionality for setting up tsdx projects,\n * including updating package.json, configuring static file mappings,\n * and the main setup function.\n */\n\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { IFindRootReturnType } from '@yarn-tool/find-root';\nimport { _Key, IStaticFilesMapArray } from '@yarn-tool/static-file/lib/types';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from '@yarn-tool/pkg-entry-util/lib/field/scripts';\nimport { deleteValue } from 'dot-values2';\nimport { EnumTsdx } from './const';\nimport { fixTsdxPackage } from './fix';\nimport { ensureDirSync } from 'fs-extra';\nimport { resolve } from 'path';\n\n/**\n * 更新 package.json 以符合 tsdx 專案標準\n * Update package.json to conform to tsdx project standards\n *\n * 此函式會設定以下內容:\n * This function configures the following:\n *\n * - scripts: test, posttest, build, build:dts:bundle, build:tsdx 等\n * scripts: test, posttest, build, build:dts:bundle, build:tsdx, etc.\n *\n * - main/module/types: 設定輸出檔案路徑\n * main/module/types: configure output file paths\n *\n * - exports: 設定模組匯出映射\n * exports: configure module export mappings\n *\n * - keywords: 添加 tsdx 標識關鍵字\n * keywords: add tsdx identifier keyword\n *\n * @param pkg - 要更新的 package.json 物件 / package.json object to update\n * @param config - 設定選項 (可選) / configuration options (optional)\n * @returns 更新後的 package.json 物件 / Updated package.json object\n */\nexport function updatePackageJson<P extends IPackageJson>(pkg: P, config?: ISetupTsdxOptions<P>)\n{\n\t/**\n\t * 確保 scripts 欄位存在\n\t * Ensure scripts field exists\n\t */\n\tpkg.scripts ??= {};\n\n\t/**\n\t * 如果 test 腳本未指定或為空,清除並設定預設值\n\t * If test script is not specified or empty, clear and set default\n\t *\n\t * 先設為 undefined 才能讓下一行的 ??= 生效,\n\t * 因為 \"no test specified\" 這類佔位字串並非 nullish\n\t * Setting it to undefined first lets the following ??= take effect,\n\t * because placeholder strings like \"no test specified\" are not nullish\n\t */\n\tif (scriptsEntryIsNoTestSpecified(pkg.scripts[\"test\"]))\n\t{\n\t\tpkg.scripts[\"test\"] = void 0;\n\t}\n\n\tpkg.scripts[\"test\"] ??= EnumScriptsEntry.NODE_TEST;\n\n\tpkg.scripts[\"test:node\"] ??= EnumScriptsEntry.NODE_TEST;\n\n\t/**\n\t * 設定 posttest 腳本,在測試後執行 build\n\t * Set posttest script to run build after tests\n\t */\n\tpkg.scripts[\"posttest\"] ??= \"pnpm run build\";\n\n\t/**\n\t * 如果 build 腳本不包含 tsdx build,則設定新的 build 腳本\n\t * If build script doesn't include tsdx build, set new build script\n\t *\n\t * 以 includes 檢查而非直接覆寫,避免破壞已含 tsdx build 的自訂腳本\n\t * Checks with includes instead of overwriting directly, so custom scripts already invoking tsdx build are preserved\n\t */\n\tif (!pkg.scripts[\"build\"]?.includes('run build:tsdx'))\n\t{\n\t\tpkg.scripts[\"build\"] = EnumScriptsEntry.BUILD_TSDX_AND_DTS;\n\t}\n\n\t/**\n\t * 設定 TypeScript 宣告檔案打包腳本\n\t * Set TypeScript declaration file bundling script\n\t */\n\tpkg.scripts[\"build:dts:bundle\"] ??= EnumScriptsEntry.BUILD_DTS_BUNDLE;\n\n\t/**\n\t * 設定 tsdx build 腳本,目標為 node 環境\n\t * Set tsdx build script targeting node environment\n\t */\n\tpkg.scripts[\"build:tsdx\"] ??= EnumScriptsEntry.BUILD_TSDX;\n\n\t/**\n\t * 設定複製宣告檔案的腳本 (Windows 語法)\n\t * Set declaration file copy script (Windows syntax)\n\t */\n\tpkg.scripts[\"build:dts:copy\"] ??= EnumScriptsEntry.BUILD_DTS_COPY;\n\n\t/**\n\t * 設定 TypeScript 宣告檔案輸出腳本\n\t * Set TypeScript declaration file emit script\n\t */\n\tpkg.scripts[\"build:dts:tsc:emit\"] ??= EnumScriptsEntry.BUILD_DTS_TSC_EMIT;\n\n\t/**\n\t * 設定完整的 dts 建置腳本\n\t * Set complete dts build script\n\t */\n\tpkg.scripts[\"build:dts:tsc\"] ??= EnumScriptsEntry.BUILD_DTS_TSC;\n\n\t/**\n\t * 設定模組入口點\n\t * Set module entry points\n\t *\n\t * 這裡刻意直接賦值而非 ??=,確保與 tsdx 的實際輸出檔名保持一致\n\t * Assigned directly instead of via ??= to stay in sync with tsdx's actual output file names\n\t */\n\tpkg.main = \"dist/index.cjs\";\n\tpkg.module = \"dist/index.esm.mjs\";\n\tpkg.types = pkg.typings = \"dist/index.d.ts\";\n\n\t/**\n\t * 設定 unpkg CDN 入口點\n\t * Set unpkg CDN entry point\n\t */\n\tpkg.unpkg ??= \"dist/index.umd.production.min.cjs\";\n\n\t/**\n\t * 設定 exports 欄位,定義模組匯出映射\n\t * Set exports field, defining module export mappings\n\t *\n\t * types/import/require 一律覆寫,因為必須與 main/module/types 的輸出檔名完全對應,\n\t * 否則 Node.js 的條件匯出會指向過期的舊檔\n\t * types/import/require are always overwritten because they must match the output names of\n\t * main/module/types exactly, otherwise Node.js conditional exports would point at stale files\n\t */\n\tpkg.exports ??= {};\n\tpkg.exports['.'] ??= {};\n\tpkg.exports['.'].types = \"./dist/index.d.ts\";\n\tpkg.exports['.'].import = \"./dist/index.esm.mjs\";\n\tpkg.exports['.'].require = \"./dist/index.cjs\";\n\n\t/**\n\t * 允許直接存取 src 目錄下的檔案\n\t * Allow direct access to files under src directory\n\t *\n\t * 直接覆寫而非 ??=,確保 wildcard 匯出格式始終一致\n\t * Overwritten rather than via ??= so the wildcard export format always stays consistent\n\t */\n\tpkg.exports['./src/*'] = './src/*';\n\n\t/**\n\t * 匯出 package.json 本身\n\t * Export package.json itself\n\t */\n\tpkg.exports['./package.json'] ??= './package.json';\n\n\t/**\n\t * 確保 keywords 欄位存在\n\t * Ensure keywords field exists\n\t */\n\tpkg.keywords ??= [];\n\n\t/**\n\t * 添加 tsdx 標識關鍵字(如果尚未存在)\n\t * Add tsdx identifier keyword if not already present\n\t *\n\t * 重複的 keywords 會讓 isTsdxPackage 的判斷失去意義,故先檢查再加入\n\t * Duplicate keywords would undermine the check in isTsdxPackage, so it is added only when absent\n\t */\n\tif (!pkg.keywords.includes(EnumTsdx.keyword))\n\t{\n\t\tpkg.keywords.push(EnumTsdx.keyword);\n\t}\n\n\t/**\n\t * 呼叫 fixTsdxPackage 進行額外的修復\n\t * Call fixTsdxPackage for additional fixes\n\t */\n\tfixTsdxPackage(pkg, config);\n\n\treturn pkg\n}\n\n/**\n * 預設的靜態檔案複製映射表\n * Default static file copy mapping table\n *\n * 定義需要複製到目標專案的靜態檔案,每個項目為 [目標路徑, 來源路徑, ?來源檔名] 的格式。\n * Defines static files that need to be copied to the target project,\n * each entry follows [targetPath, sourcePath, ?sourceFileName] format.\n */\nconst _defaultCopyStaticFilesTsdx = [\n\n\t/**\n\t * 根目錄的 tsconfig.json 設定檔\n\t * Root tsconfig.json configuration file\n\t */\n\t['tsconfig.json', 'file/tsconfig.tsdx.json.tpl'],\n\n\t/**\n\t * 測試目錄的 tsconfig.json 設定檔\n\t * Test directory tsconfig.json configuration file\n\t */\n\t['test/tsconfig.json', 'file/test/tsconfig.json.tpl'],\n\n\t/**\n\t * src 目錄下的 index.cts 檔案\n\t * index.cts file under src directory\n\t */\n\t['src/index.cts', 'file/tsdx/index.cts'],\n\n\t/**\n\t * src 目錄的 tsconfig.json 設定檔\n\t * src directory tsconfig.json configuration file\n\t */\n\t['src/tsconfig.json', 'file/tsdx/tsconfig.json.tpl'],\n\n] as const;\n\n/**\n * 凍結的預設靜態檔案映射表\n * Frozen default static file mapping table\n *\n * 凍結是為了避免執行期意外改動全域預設值,影響其他套件的設定流程\n * Frozen to prevent accidental mutation of the global default, which would affect setup runs in other packages\n */\nexport const defaultCopyStaticFilesTsdx = Object.freeze(_defaultCopyStaticFilesTsdx) as any as IStaticFilesMapArray<_Key<typeof _defaultCopyStaticFilesTsdx>>;\n\n/**\n * tsdx 設定選項介面\n * tsdx setup options interface\n *\n * @template P - package.json 類型 / package.json type\n */\nexport interface ISetupTsdxOptions<P extends IPackageJson>\n{\n\t/** 目標目錄路徑 / Target directory path */\n\ttargetDir: string,\n\n\t/** package.json 物件 / package.json object */\n\tpkg: P,\n\n\t/** 工作區根目錄資訊 / Workspace root directory information */\n\trootData: IFindRootReturnType,\n\n\t/** 靜態檔案映射表 / Static file mapping table */\n\tfile_map: IStaticFilesMapArray<string>,\n\n\t/** README 檔案名稱 / README file name */\n\tmdFile: string,\n\n\t/** 是否存在 README 檔案 / Whether README file exists */\n\texistsReadme: boolean,\n\n\t/** 是否為已存在的專案 / Whether it's an existing project */\n\toldExists: boolean,\n}\n\n/**\n * 設定 tsdx 專案的主要函式\n * Main function for setting up tsdx project\n *\n * 此函式執行以下操作:\n * This function performs the following operations:\n *\n * 1. 更新 package.json 設定\n * Update package.json configuration\n *\n * 2. 合併預設與自訂的靜態檔案映射\n * Merge default and custom static file mappings\n *\n * 3. 確保 src 目錄存在\n * Ensure src directory exists\n *\n * @template P - package.json 類型 / package.json type\n * @param config - 設定選項 / Configuration options\n * @returns 包含更新後設定的物件 / Object containing updated configuration\n */\nexport function setup<P extends IPackageJson>(config: ISetupTsdxOptions<P>)\n{\n\tlet {\n\t\tpkg,\n\t\tfile_map,\n\t\ttargetDir,\n\t} = config;\n\n\t/**\n\t * 更新 package.json\n\t * Update package.json\n\t */\n\tpkg = updatePackageJson(pkg, config);\n\n\t/**\n\t * 合併預設與自訂的靜態檔案映射\n\t * Merge default and custom static file mappings\n\t *\n\t * 預設項排在前方,自訂項排在後方,讓呼叫端可用相同目標路徑覆寫預設值\n\t * Default entries come first and custom entries follow, so callers can override a default via the same target path\n\t */\n\tfile_map = [\n ...defaultCopyStaticFilesTsdx,\n\t\t...file_map,\n\t];\n\n\t/**\n\t * 確保 src 目錄存在\n\t * Ensure src directory exists\n\t *\n\t * tsdx 假定來源碼位於 src/,新專案若缺少此目錄會導致後續 build 失敗\n\t * tsdx assumes sources live under src/; a new project missing this directory would fail the subsequent build\n\t */\n\tensureDirSync(resolve(targetDir, 'src'));\n\n\treturn {\n\t\t...config,\n\t\tpkg,\n\t\tfile_map,\n\t}\n}\n"]}
@@ -18,8 +18,15 @@ exports.isTsdxPackage = isTsdxPackage;
18
18
  */
19
19
  function isTsdxPackage(pkg, config) {
20
20
  var _a, _b;
21
- // 檢查關鍵字是否包含 tsdx 標記,且 exports['.'] 為物件類型
22
- // Check if keywords include tsdx marker and exports['.'] is an object type
21
+ /**
22
+ * 檢查關鍵字是否包含 tsdx 標記,且 exports['.'] 為物件類型
23
+ * Check if keywords include tsdx marker and exports['.'] is an object type
24
+ *
25
+ * 兩個條件缺一不可:只有 keywords 可能是手動殘留,
26
+ * 只有 exports 則無法區分是否由 tsdx 建立
27
+ * Both conditions are required: keywords alone may be manually left over,
28
+ * and exports alone cannot tell whether the project was created by tsdx
29
+ */
23
30
  return ((_a = pkg.keywords) === null || _a === void 0 ? void 0 : _a.includes("create-by-tsdx" /* EnumTsdx.keyword */)) && typeof ((_b = pkg.exports) === null || _b === void 0 ? void 0 : _b['.']) === 'object';
24
31
  }
25
32
  //# sourceMappingURL=is-tsdx.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-tsdx.js","sourceRoot":"","sources":["is-tsdx.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAiBH,sCAKC;AAhBD;;;;;;;;;;GAUG;AACH,SAAgB,aAAa,CAAyB,GAAM,EAAE,MAA6B;;IAE1F,yCAAyC;IACzC,2EAA2E;IAC3E,OAAO,CAAA,MAAA,GAAG,CAAC,QAAQ,0CAAE,QAAQ,yCAAkB,KAAI,OAAO,CAAA,MAAA,GAAG,CAAC,OAAO,0CAAG,GAAG,CAAC,CAAA,KAAK,QAAQ,CAAA;AAC1F,CAAC","sourcesContent":["/**\n * tsdx 專案識別工具函式\n * Utility functions for identifying tsdx projects\n */\n\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { ISetupTsdxOptions } from './index';\nimport { EnumTsdx } from './const';\n\n/**\n * 檢查是否為 tsdx 專案\n * Check if the package is a tsdx project\n *\n * 透過檢查 package.json 中的 keywords 和 exports 欄位來判斷是否為 tsdx 專案。\n * Determines if a package is a tsdx project by checking the keywords and exports fields in package.json.\n *\n * @param pkg - package.json 物件 / package.json object\n * @param config - 設定選項 (可選) / configuration options (optional)\n * @returns 如果是 tsdx 專案則返回 true,否則返回 false / Returns true if it's a tsdx project, false otherwise\n */\nexport function isTsdxPackage<P extends IPackageJson>(pkg: P, config?: ISetupTsdxOptions<P>)\n{\n\t// 檢查關鍵字是否包含 tsdx 標記,且 exports['.'] 為物件類型\n\t// Check if keywords include tsdx marker and exports['.'] is an object type\n\treturn pkg.keywords?.includes(EnumTsdx.keyword) && typeof pkg.exports?.['.'] === 'object'\n}\n"]}
1
+ {"version":3,"file":"is-tsdx.js","sourceRoot":"","sources":["is-tsdx.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAiBH,sCAYC;AAvBD;;;;;;;;;;GAUG;AACH,SAAgB,aAAa,CAAyB,GAAM,EAAE,MAA6B;;IAE1F;;;;;;;;OAQG;IACH,OAAO,CAAA,MAAA,GAAG,CAAC,QAAQ,0CAAE,QAAQ,yCAAkB,KAAI,OAAO,CAAA,MAAA,GAAG,CAAC,OAAO,0CAAG,GAAG,CAAC,CAAA,KAAK,QAAQ,CAAA;AAC1F,CAAC","sourcesContent":["/**\n * tsdx 專案識別工具函式\n * Utility functions for identifying tsdx projects\n */\n\nimport { IPackageJson } from '@ts-type/package-dts/package-json';\nimport { ISetupTsdxOptions } from './index';\nimport { EnumTsdx } from './const';\n\n/**\n * 檢查是否為 tsdx 專案\n * Check if the package is a tsdx project\n *\n * 透過檢查 package.json 中的 keywords 和 exports 欄位來判斷是否為 tsdx 專案。\n * Determines if a package is a tsdx project by checking the keywords and exports fields in package.json.\n *\n * @param pkg - package.json 物件 / package.json object\n * @param config - 設定選項 (可選) / configuration options (optional)\n * @returns 如果是 tsdx 專案則返回 true,否則返回 false / Returns true if it's a tsdx project, false otherwise\n */\nexport function isTsdxPackage<P extends IPackageJson>(pkg: P, config?: ISetupTsdxOptions<P>)\n{\n\t/**\n\t * 檢查關鍵字是否包含 tsdx 標記,且 exports['.'] 為物件類型\n\t * Check if keywords include tsdx marker and exports['.'] is an object type\n\t *\n\t * 兩個條件缺一不可:只有 keywords 可能是手動殘留,\n\t * 只有 exports 則無法區分是否由 tsdx 建立\n\t * Both conditions are required: keywords alone may be manually left over,\n\t * and exports alone cannot tell whether the project was created by tsdx\n\t */\n\treturn pkg.keywords?.includes(EnumTsdx.keyword) && typeof pkg.exports?.['.'] === 'object'\n}\n"]}
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@yarn-tool/setup-module-env",
3
- "version": "3.0.16",
3
+ "version": "3.0.17",
4
4
  "description": "用於設定 tsdx 專案環境的工具,自動配置 package.json 與靜態檔案 (Tool for setting up tsdx project environment, auto-configuring package.json and static files)",
5
5
  "keywords": [
6
+ "tsdx",
7
+ "setup-module-env",
8
+ "project-setup",
9
+ "static-files",
6
10
  "yarn",
7
11
  "yarn-tool",
8
12
  "npm",
@@ -31,12 +35,14 @@
31
35
  "scripts": {
32
36
  "coverage": "pnpm run test -- --coverage",
33
37
  "lint": "ynpx --quiet eslint -- **/*.ts",
34
- "test": "jest --passWithNoTests",
38
+ "test": "node --run test:node",
35
39
  "test:jest": "jest --passWithNoTests",
36
40
  "test:jest:coverage": "pnpm run test:jest -- --coverage",
37
41
  "test:jest:snapshot": "pnpm run test:jest -- -u",
38
42
  "test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
43
+ "test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
39
44
  "test:snapshot": "pnpm run test -u",
45
+ "test:tsc": "tsc --noEmit & echo typescript check done",
40
46
  "test:tsd": "ynpx tsd",
41
47
  "test:tsdx": "ynpx @bluelovers/tsdx test --passWithNoTests",
42
48
  "build:dts": "ynpx @bluelovers/tsdx dts -o ./dist/index.d.ts ./src/index.ts --no-banner & echo build:dts",
@@ -55,15 +61,15 @@
55
61
  "tsc:showConfig": "ynpx get-current-tsconfig -p"
56
62
  },
57
63
  "dependencies": {
58
- "@ts-type/package-dts": "^3.0.9",
59
- "@yarn-tool/find-root": "^2.0.25",
60
- "@yarn-tool/pkg-entry-util": "^3.0.14",
61
- "@yarn-tool/static-file": "^3.0.19",
64
+ "@ts-type/package-dts": "^3.0.14",
65
+ "@yarn-tool/find-root": "^2.0.26",
66
+ "@yarn-tool/pkg-entry-util": "^3.0.15",
67
+ "@yarn-tool/static-file": "^3.0.20",
62
68
  "dot-values2": "^2.0.7",
63
69
  "tslib": ">=2.8.1"
64
70
  },
65
71
  "publishConfig": {
66
72
  "access": "public"
67
73
  },
68
- "gitHead": "74c07cfa7748b838e039b289590ba5d720fcef44"
74
+ "gitHead": "471c63ee11851f0ac3487f23d1c472936f99b460"
69
75
  }